Lines Matching +full:calibration +full:- +full:data

1 // SPDX-License-Identifier: GPL-2.0-only
16 #include <sound/cs-amp-lib.h>
34 mutex_lock(&dsp->pwr_lock); in cs_amp_write_cal_coeff()
35 cs_ctl = cs_dsp_get_ctl(dsp, ctl_name, controls->mem_region, controls->alg_id); in cs_amp_write_cal_coeff()
37 mutex_unlock(&dsp->pwr_lock); in cs_amp_write_cal_coeff()
40 dev_err(dsp->dev, "Failed to write to '%s': %d\n", ctl_name, ret); in cs_amp_write_cal_coeff()
47 return -ENODEV; in cs_amp_write_cal_coeff()
52 const struct cirrus_amp_cal_data *data) in _cs_amp_write_cal_coeffs() argument
56 dev_dbg(dsp->dev, "Calibration: Ambient=%#x, Status=%#x, CalR=%d\n", in _cs_amp_write_cal_coeffs()
57 data->calAmbient, data->calStatus, data->calR); in _cs_amp_write_cal_coeffs()
59 if (list_empty(&dsp->ctl_list)) { in _cs_amp_write_cal_coeffs()
60 dev_info(dsp->dev, "Calibration disabled due to missing firmware controls\n"); in _cs_amp_write_cal_coeffs()
61 return -ENOENT; in _cs_amp_write_cal_coeffs()
64 ret = cs_amp_write_cal_coeff(dsp, controls, controls->ambient, data->calAmbient); in _cs_amp_write_cal_coeffs()
68 ret = cs_amp_write_cal_coeff(dsp, controls, controls->calr, data->calR); in _cs_amp_write_cal_coeffs()
72 ret = cs_amp_write_cal_coeff(dsp, controls, controls->status, data->calStatus); in _cs_amp_write_cal_coeffs()
76 ret = cs_amp_write_cal_coeff(dsp, controls, controls->checksum, data->calR + 1); in _cs_amp_write_cal_coeffs()
84 * cs_amp_write_cal_coeffs - Write calibration data to firmware controls.
87 * @data: Pointer to calibration data.
93 const struct cirrus_amp_cal_data *data) in cs_amp_write_cal_coeffs() argument
96 return _cs_amp_write_cal_coeffs(dsp, controls, data); in cs_amp_write_cal_coeffs()
98 return -ENODEV; in cs_amp_write_cal_coeffs()
121 u8 *data; in cs_amp_get_cal_efi_buffer() local
128 return ERR_PTR(-ENOENT); in cs_amp_get_cal_efi_buffer()
132 return ERR_PTR(-EOVERFLOW); in cs_amp_get_cal_efi_buffer()
136 data = kmalloc(data_size, GFP_KERNEL); in cs_amp_get_cal_efi_buffer()
137 if (!data) in cs_amp_get_cal_efi_buffer()
138 return ERR_PTR(-ENOMEM); in cs_amp_get_cal_efi_buffer()
140 status = cs_amp_get_efi_variable(CS_AMP_CAL_NAME, &CS_AMP_CAL_GUID, &data_size, data); in cs_amp_get_cal_efi_buffer()
142 ret = -EINVAL; in cs_amp_get_cal_efi_buffer()
146 efi_data = (struct cirrus_amp_efi_data *)data; in cs_amp_get_cal_efi_buffer()
147 dev_dbg(dev, "Calibration: Size=%d, Amp Count=%d\n", efi_data->size, efi_data->count); in cs_amp_get_cal_efi_buffer()
149 if ((efi_data->count > 128) || in cs_amp_get_cal_efi_buffer()
150 offsetof(struct cirrus_amp_efi_data, data[efi_data->count]) > data_size) { in cs_amp_get_cal_efi_buffer()
152 ret = -EOVERFLOW; in cs_amp_get_cal_efi_buffer()
159 kfree(data); in cs_amp_get_cal_efi_buffer()
160 dev_err(dev, "Failed to read calibration data from EFI: %d\n", ret); in cs_amp_get_cal_efi_buffer()
165 static u64 cs_amp_cal_target_u64(const struct cirrus_amp_cal_data *data) in cs_amp_cal_target_u64() argument
167 return ((u64)data->calTarget[1] << 32) | data->calTarget[0]; in cs_amp_cal_target_u64()
182 for (i = 0; i < efi_data->count; ++i) { in _cs_amp_get_efi_calibration_data()
183 u64 cal_target = cs_amp_cal_target_u64(&efi_data->data[i]); in _cs_amp_get_efi_calibration_data()
186 if (!efi_data->data[i].calTime[0] && !efi_data->data[i].calTime[1]) in _cs_amp_get_efi_calibration_data()
194 cal = &efi_data->data[i]; in _cs_amp_get_efi_calibration_data()
200 if (!cal && (amp_index >= 0) && (amp_index < efi_data->count) && in _cs_amp_get_efi_calibration_data()
201 (efi_data->data[amp_index].calTime[0] || efi_data->data[amp_index].calTime[1])) { in _cs_amp_get_efi_calibration_data()
202 u64 cal_target = cs_amp_cal_target_u64(&efi_data->data[amp_index]); in _cs_amp_get_efi_calibration_data()
211 cal = &efi_data->data[amp_index]; in _cs_amp_get_efi_calibration_data()
213 dev_warn(dev, "Calibration entry %d does not match silicon ID", amp_index); in _cs_amp_get_efi_calibration_data()
220 dev_warn(dev, "No calibration for silicon ID %#llx\n", target_uid); in _cs_amp_get_efi_calibration_data()
221 ret = -ENOENT; in _cs_amp_get_efi_calibration_data()
230 * cs_amp_get_efi_calibration_data - get an entry from calibration data in EFI.
233 * @amp_index: Entry index to use, or -1 to prevent lookup by index.
240 * Search the calibration data for a non-zero calTarget that matches
246 * Search the calibration data for a non-zero calTarget that matches
254 * entries in the calibration array, and in this case the return will
255 * be -ENOENT. An out-of-range amp_index does not prevent matching by
256 * target_uid - it has the same effect as passing amp_index < 0.
258 * If the EFI data is too short to be a valid entry, or the entry count
259 * in the EFI data overflows the actual length of the data, this function
260 * returns -EOVERFLOW.
262 * Return: 0 if the entry was found, -ENOENT if no entry was found,
263 * -EOVERFLOW if the EFI file is corrupt, else other error value.
271 return -ENOENT; in cs_amp_get_efi_calibration_data()