// SPDX-License-Identifier: GPL-2.0-only // // Common code for Cirrus Logic Smart Amplifiers // // Copyright (C) 2024 Cirrus Logic, Inc. and // Cirrus Logic International Semiconductor Ltd. #include <asm/byteorder.h> #include <kunit/static_stub.h> #include <linux/dev_printk.h> #include <linux/efi.h> #include <linux/firmware/cirrus/cs_dsp.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/types.h> #include <sound/cs-amp-lib.h> #define CS_AMP_CAL_GUID … #define CS_AMP_CAL_NAME … static int cs_amp_write_cal_coeff(struct cs_dsp *dsp, const struct cirrus_amp_cal_controls *controls, const char *ctl_name, u32 val) { … } static int _cs_amp_write_cal_coeffs(struct cs_dsp *dsp, const struct cirrus_amp_cal_controls *controls, const struct cirrus_amp_cal_data *data) { … } /** * cs_amp_write_cal_coeffs - Write calibration data to firmware controls. * @dsp: Pointer to struct cs_dsp. * @controls: Pointer to definition of firmware controls to be written. * @data: Pointer to calibration data. * * Returns: 0 on success, else negative error value. */ int cs_amp_write_cal_coeffs(struct cs_dsp *dsp, const struct cirrus_amp_cal_controls *controls, const struct cirrus_amp_cal_data *data) { … } EXPORT_SYMBOL_NS_GPL(…); static efi_status_t cs_amp_get_efi_variable(efi_char16_t *name, efi_guid_t *guid, unsigned long *size, void *buf) { … } static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev) { … } static u64 cs_amp_cal_target_u64(const struct cirrus_amp_cal_data *data) { … } static int _cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid, int amp_index, struct cirrus_amp_cal_data *out_data) { … } /** * cs_amp_get_efi_calibration_data - get an entry from calibration data in EFI. * @dev: struct device of the caller. * @target_uid: UID to match, or zero to ignore UID matching. * @amp_index: Entry index to use, or -1 to prevent lookup by index. * @out_data: struct cirrus_amp_cal_data where the entry will be copied. * * This function can perform 3 types of lookup: * * (target_uid > 0, amp_index >= 0) * UID search with fallback to using the array index. * Search the calibration data for a non-zero calTarget that matches * target_uid, and if found return that entry. Else, if the entry at * [amp_index] has calTarget == 0, return that entry. Else fail. * * (target_uid > 0, amp_index < 0) * UID search only. * Search the calibration data for a non-zero calTarget that matches * target_uid, and if found return that entry. Else fail. * * (target_uid == 0, amp_index >= 0) * Array index fetch only. * Return the entry at [amp_index]. * * An array lookup will be skipped if amp_index exceeds the number of * entries in the calibration array, and in this case the return will * be -ENOENT. An out-of-range amp_index does not prevent matching by * target_uid - it has the same effect as passing amp_index < 0. * * If the EFI data is too short to be a valid entry, or the entry count * in the EFI data overflows the actual length of the data, this function * returns -EOVERFLOW. * * Return: 0 if the entry was found, -ENOENT if no entry was found, * -EOVERFLOW if the EFI file is corrupt, else other error value. */ int cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid, int amp_index, struct cirrus_amp_cal_data *out_data) { … } EXPORT_SYMBOL_NS_GPL(…); static const struct cs_amp_test_hooks cs_amp_test_hook_ptrs = …; const struct cs_amp_test_hooks * const cs_amp_test_hooks = …; EXPORT_SYMBOL_NS_GPL(…); MODULE_DESCRIPTION(…) …; MODULE_AUTHOR(…) …; MODULE_LICENSE(…) …; MODULE_IMPORT_NS(…);