Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: cs35l56: Alter error codes for calibration routine

Adjust the error codes returned by the calibration debugfs files
to provide a wider range of errors and make them more consistent.

There is a limited number of standard errors and it's not always
easy to find an error code that accurately describes what happened.
Additionally, user code often uses strerror() or something similar
to report a generic error description. The original calibration
code used a limited set of errors to attempt to avoid user error
strings that would be confusing or unclear on a file read/write.
However, this restricts the ability to provide informative errors.

This limited error range didn't help very much with debugging so
it has been expanded, rather than worrying about what strerror()
would return.

The errors are now more consistent:

ENXIO Calibration is not supported by the driver.
EOPNOTSUPP The given calibration command is not supported.
EBUSY Cannot calibrate because the amp is playing audio.
ERANGE Calibration result was out-of-range.
ETIMEDOUT Calibration did not complete.
EMSGSIZE Blob written to cal_data is the wrong size.
ENODATA No calibration data available to read from cal_data,
or
Blob written to cal_data does not contain calibration,
or
No calibration data available to save to UEFI.
EIO General failure to communicate with the firmware, mainly
indicating that firmware controls are missing.
EINVAL Has its normal meaning that an invalid argument was passed.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20251110114327.84370-1-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Richard Fitzgerald and committed by
Mark Brown
772ada50 4acbfcf1

+25 -7
+3
include/sound/cs35l56.h
··· 265 265 #define CS35L56_PS3_POLL_US 500 266 266 #define CS35L56_PS3_TIMEOUT_US 300000 267 267 268 + #define CS35L56_CAL_STATUS_SUCCESS 1 269 + #define CS35L56_CAL_STATUS_OUT_OF_RANGE 3 270 + 268 271 #define CS35L56_CONTROL_PORT_READY_US 2200 269 272 #define CS35L56_HALO_STATE_POLL_US 1000 270 273 #define CS35L56_HALO_STATE_TIMEOUT_US 250000
+22 -7
sound/soc/codecs/cs35l56-shared.c
··· 1022 1022 return ret; 1023 1023 1024 1024 ret = cs35l56_wait_for_ps3(cs35l56_base); 1025 - if (ret) 1025 + if (ret) { 1026 + ret = -EBUSY; 1026 1027 goto err_pm_put; 1028 + } 1027 1029 1028 1030 regmap_update_bits_check(cs35l56_base->regmap, CS35L56_MIXER_NGATE_CH1_CFG, 1029 1031 CS35L56_AUX_NGATE_CHn_EN, 0, &ngate_ch1_was_enabled); ··· 1040 1038 if (!ctl) { 1041 1039 dev_err(cs35l56_base->dev, "Could not get %s control\n", 1042 1040 calibration_controls->status); 1043 - ret = -ENXIO; 1041 + ret = -EIO; 1044 1042 goto err; 1045 1043 } 1046 1044 ··· 1052 1050 0, &val, sizeof(val)); 1053 1051 if (ret < 0) { 1054 1052 dev_err(cs35l56_base->dev, "Could not write %s: %d\n", "CALI_NORM_EN", ret); 1053 + ret = -EIO; 1055 1054 goto err; 1056 1055 } 1057 1056 1058 1057 ret = cs35l56_mbox_send(cs35l56_base, CS35L56_MBOX_CMD_AUDIO_CALIBRATION); 1059 - if (ret) 1058 + if (ret) { 1059 + ret = -EIO; 1060 1060 goto err; 1061 + } 1061 1062 1062 1063 if (read_poll_timeout(cs_dsp_coeff_read_ctrl, ret, 1063 1064 (val == cpu_to_be32(1)), ··· 1070 1065 ctl, 0, &val, sizeof(val))) { 1071 1066 dev_err(cs35l56_base->dev, "Calibration timed out (CAL_STATUS: %u)\n", 1072 1067 be32_to_cpu(val)); 1073 - ret = -ETIMEDOUT; 1074 - goto err; 1068 + switch (be32_to_cpu(val)) { 1069 + case CS35L56_CAL_STATUS_OUT_OF_RANGE: 1070 + ret = -ERANGE; 1071 + goto err; 1072 + default: 1073 + ret = -ETIMEDOUT; 1074 + goto err; 1075 + } 1075 1076 } 1076 1077 } 1077 1078 1078 1079 cs35l56_base->cal_data_valid = false; 1079 1080 memset(&cal_data, 0, sizeof(cal_data)); 1080 1081 ret = cs_amp_read_cal_coeffs(dsp, calibration_controls, &cal_data); 1081 - if (ret) 1082 + if (ret) { 1083 + ret = -EIO; 1082 1084 goto err; 1085 + } 1083 1086 1084 1087 dev_info(cs35l56_base->dev, "Cal status:%d calR:%d ambient:%d\n", 1085 1088 cal_data.calStatus, cal_data.calR, cal_data.calAmbient); ··· 1154 1141 return ret; 1155 1142 break; 1156 1143 default: 1157 - return -ENXIO; 1144 + return -EOPNOTSUPP; 1158 1145 } 1159 1146 1160 1147 return count; ··· 1183 1170 goto out; 1184 1171 1185 1172 ret = cs_amp_write_ambient_temp(cs35l56_base->dsp, cs35l56_base->calibration_controls, val); 1173 + if (ret) 1174 + ret = -EIO; 1186 1175 out: 1187 1176 pm_runtime_put(cs35l56_base->dev); 1188 1177