ALSA: cs35l56: Add support for factory calibration
Subsystems (3)
Richard Fitzgerald
maintainerv2 cover ALSA: cs35l56: Add support for factory calibration
Until now, all products with an amplifier supported by the cs35l56 driver have shipped with Microsoft Windows pre-installed. The factory calibration of speaker protection has therefore been done using the Windows driver.
However, products that ship with a Linux-based distro must be able to perform the factory calibration procedure from within the Linux-based environment. This patch series adds that support.
NOTE: unfortunately this is yet another series that is mainly ASoC but also needs some changes to the HDA driver, and they have build dependencies on the ASoC code. I suggest taking this all through Mark's tree and we'll avoid sending any other commits to the HDA driver until it has all landed in Takashi's tree.
Changes since V1:
- Changed the file handlers to be debugfs files instead of sysfs files.
Richard Fitzgerald (11):
ASoC: cs35l56: Read silicon ID during initialization and save it
ASoC: cs-amp-lib: Add helpers for factory calibration
ASoC: cs35l56: Add common code for factory calibration
ASoC: cs35l56: Create debugfs files for factory calibration
ALSA: hda/cs35l56: Create debugfs files for factory calibration
ASoC: cs-amp-lib-test: Add cases for factory calibration helpers
ASoC: cs-amp-lib: Return attributes from cs_amp_get_efi_variable()
ASoC: cs-amp-lib: Add function to write calibration to UEFI
ASoC: cs35l56: Add calibration command to store into UEFI
ALSA: hda/cs35l56: Set cal_index to the amp index
ASoC: cs-amp-lib-test: Add test cases for
cs_amp_set_efi_calibration_data()
include/sound/cs-amp-lib.h | 25 +- include/sound/cs35l56.h | 35 + sound/hda/codecs/side-codecs/Kconfig | 15 + sound/hda/codecs/side-codecs/cs35l56_hda.c | 116 +- sound/hda/codecs/side-codecs/cs35l56_hda.h | 6 + sound/soc/codecs/Kconfig | 18 + sound/soc/codecs/cs-amp-lib-test.c | 1491 +++++++++++++++++++- sound/soc/codecs/cs-amp-lib.c | 345 ++++- sound/soc/codecs/cs35l56-shared.c | 368 ++++- sound/soc/codecs/cs35l56.c | 159 +++ sound/soc/codecs/cs35l56.h | 6 + 11 files changed, 2530 insertions(+), 54 deletions(-)
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH v2 1/11 ASoC: cs35l56: Read silicon ID during initialization and save it
Read the silicon ID from the amp during one-time cs35l56_hw_init() and store it in struct cs35l56_base, instead of reading it from registers every time it is needed.
Note that marking it non-volatile without a default in regmap isn't a suitable alternative because this causes regcache_sync() to always write the cached value out to the registers. This could trigger a bus fault interrupt inside the amp, which we want to avoid.
---
No changes since V1.
include/sound/cs35l56.h | 1 + sound/soc/codecs/cs35l56-shared.c | 53 +++++++++++++++---------------- 2 files changed, 27 insertions(+), 27 deletions(-)
include/sound/cs35l56.h +1 -0
@@ -309,6 +309,7 @@ struct cs35l56_base {struct cs35l56_spi_payload *spi_payload_buf;const struct cs35l56_fw_reg *fw_reg;const struct cirrus_amp_cal_controls *calibration_controls; +u64 silicon_uid; };static inline bool cs35l56_is_otp_register (unsigned int reg)
sound/soc/codecs/cs35l56-shared.c +26 -27
95 lines not on this page · raw message
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH v2 2/11 ASoC: cs-amp-lib: Add helpers for factory calibration
In reply to Richard FitzgeraldAdd helper functions for performing factory calibration.
cs_amp_read_cal_coeffs() reads the results of a calibration into a struct cirrus_amp_cal_data. The calTime member is also filled in with the current time (which is defined to be in Windows format).
cs_amp_write_ambient_temp() writes a given temperature value to the firmware control for ambient temperature.
The cs_amp_cal_target_u64() has been moved into the header file so that it can be used by the calling code and by KUnit tests.
cs_amp_create_debugfs() creates a debugfs directory to contain debugfs files related to calibration. This is placed in a directory in debugfs root, named "cirrus_logic". The purpose of this is to make it easier for tooling to find the files it needs by keeping control of the layout under this directory. By contrast the ASoC debugfs can vary between kernel releases and doesn't have a strictly stable naming convention. HDA does not have a debugfs directory at all and enabling the general ALSA debugfs (which is normally disabled) has other side-effects.
---
Changes in V2:
- Added cs_amp_create_debugfs()
include/sound/cs-amp-lib.h | 12 +++ sound/soc/codecs/cs-amp-lib.c | 148 ++++++++++++++++++++++++++++++++-- 2 files changed, 155 insertions(+), 5 deletions(-)
include/sound/cs-amp-lib.h +12 -0
@@ -47,9 +47,21 @@ struct cirrus_amp_cal_controls {int cs_amp_write_cal_coeffs (struct cs_dsp *dsp,const struct cirrus_amp_cal_controls *controls,const struct cirrus_amp_cal_data *data); +int cs_amp_read_cal_coeffs (struct cs_dsp *dsp, +const struct cirrus_amp_cal_controls *controls, +struct cirrus_amp_cal_data *data); +int cs_amp_write_ambient_temp (struct cs_dsp *dsp, +const struct cirrus_amp_cal_controls *controls, +u32 temp);int cs_amp_get_efi_calibration_data (struct device *dev,u64 target_uid,int amp_index,struct cirrus_amp_cal_data *out_data);int cs_amp_get_vendor_spkid (struct device *dev); +struct dentry *cs_amp_create_debugfs (struct device *dev); + +static inline u64 cs_amp_cal_target_u64 (const struct cirrus_amp_cal_data *data) +{ +return ((u64 )data->calTarget[1 ] <<32 ) | data->calTarget[0 ]; +}struct cs_amp_test_hooks { efi_status_t (*get_efi_variable)(efi_char16_t *name,
sound/soc/codecs/cs-amp-lib.c +143 -5
196 lines not on this page · raw message
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH v2 3/11 ASoC: cs35l56: Add common code for factory calibration
In reply to Richard FitzgeraldAdd core code to support factory calibration. This can be used by both the ASoC and HDA drivers.
This code consists of implementations of debugfs handlers for three debugfs files used to start factory calibration and read the results.
This is not a full implementation of debugfs files. There are some requirements to synchronize with the rest of the amp driver, and the way this is done is significantly different between ASoC and HDA. Therefore cs35l56-shared.c provides the main part of the file handlers, but the files themselves are defined in the ASoC and HDA drivers with suitable handling before calling into this shared code.
The cal_data file allows the calibration to be read and also for a previous calibration to be written (for systems where the storage is not something directly accessible to drivers, such as on filesystems). Code outside the kernel should treat the content of cal_data as an opaque blob, so the struct definition is not exported as a user API.
---
Changes in V2:
- File callbacks rewritten to be debugfs callbacks instead of sysfs callbacks.
- Added a function to create the debugfs files.
include/sound/cs35l56.h | 33 ++++ sound/soc/codecs/Kconfig | 3 + sound/soc/codecs/cs35l56-shared.c | 300 +++++++++++++++++++++++++++++- 3 files changed, 331 insertions(+), 5 deletions(-)
include/sound/cs35l56.h +33 -0
@@ -9,6 +9,7 @@#ifndef __CS35L56_H#define __CS35L56_H +#include <linux/debugfs.h> #include <linux/firmware/cirrus/cs_dsp.h> #include <linux/regulator/consumer.h> #include <linux/regmap.h>
@@ -62,6 +63,8 @@#define CS35L56_IRQ1_MASK_8 0x000E0AC#define CS35L56_IRQ1_MASK_18 0x000E0D4#define CS35L56_IRQ1_MASK_20 0x000E0DC +#define CS35L56_MIXER_NGATE_CH1_CFG 0x0010004 +#define CS35L56_MIXER_NGATE_CH2_CFG 0x0010008#define CS35L56_DSP_MBOX_1_RAW 0x0011000#define CS35L56_DSP_VIRTUAL1_MBOX_1 0x0011020#define CS35L56_DSP_VIRTUAL1_MBOX_2 0x0011024
@@ -177,6 +180,9 @@/* IRQ1_EINT_8 */ #define CS35L56_TEMP_ERR_EINT1_MASK 0x80000000 +/* MIXER_NGATE_CHn_CFG */ +#define CS35L56_AUX_NGATE_CHn_EN 0x00000001 +/* Mixer input sources */ #define CS35L56_INPUT_SRC_NONE 0x00#define CS35L56_INPUT_SRC_ASP1RX1 0x08
@@ -243,6 +249,7 @@#define CS35L56_MBOX_CMD_AUDIO_PLAY 0x0B000001#define CS35L56_MBOX_CMD_AUDIO_PAUSE 0x0B000002#define CS35L56_MBOX_CMD_AUDIO_REINIT 0x0B000003 +#define CS35L56_MBOX_CMD_AUDIO_CALIBRATION 0x0B000006#define CS35L56_MBOX_CMD_HIBERNATE_NOW 0x02000001#define CS35L56_MBOX_CMD_WAKEUP 0x02000002#define CS35L56_MBOX_CMD_PREVENT_AUTO_HIBERNATE 0x02000003
@@ -264,6 +271,9 @@#define CS35L56_RESET_PULSE_MIN_US 1100#define CS35L56_WAKE_HOLD_TIME_US 1000 +#define CS35L56_CALIBRATION_POLL_US (100 * USEC_PER_MSEC) +#define CS35L56_CALIBRATION_TIMEOUT_US (5 * USEC_PER_SEC) +#define CS35L56_SDW1_PLAYBACK_PORT 1#define CS35L56_SDW1_CAPTURE_PORT 3
@@ -291,9 +301,16 @@ struct cs35l56_fw_reg {unsigned int posture_number; }; +struct cs35l56_cal_debugfs_fops { +const struct debugfs_short_fops calibrate; +const struct debugfs_short_fops cal_temperature; +const struct debugfs_short_fops cal_data; +}; +struct cs35l56_base {struct device *dev;struct regmap *regmap; +struct cs_dsp *dsp;int irq;struct mutex irq_lock;u8 type;
@@ -309,6 +326,7 @@ struct cs35l56_base {struct cs35l56_spi_payload *spi_payload_buf;const struct cs35l56_fw_reg *fw_reg;const struct cirrus_amp_cal_controls *calibration_controls; +struct dentry *debugfs;u64 silicon_uid; };
@@ -359,6 +377,21 @@ int cs35l56_runtime_suspend_common(struct cs35l56_base *cs35l56_base);int cs35l56_runtime_resume_common (struct cs35l56_base *cs35l56_base,bool is_soundwire);void cs35l56_init_cs_dsp (struct cs35l56_base *cs35l56_base,struct cs_dsp *cs_dsp);int cs35l56_get_calibration (struct cs35l56_base *cs35l56_base); +ssize_t cs35l56_calibrate_debugfs_write (struct cs35l56_base *cs35l56_base, +const char __user *from,size_t count, +loff_t *ppos); +ssize_t cs35l56_cal_ambient_debugfs_write (struct cs35l56_base *cs35l56_base, +const char __user *from,size_t count, +loff_t *ppos); +ssize_t cs35l56_cal_data_debugfs_read (struct cs35l56_base *cs35l56_base, +char __user *to,size_t count, +loff_t *ppos); +ssize_t cs35l56_cal_data_debugfs_write (struct cs35l56_base *cs35l56_base, +const char __user *from,size_t count, +loff_t *ppos); +void cs35l56_create_cal_debugfs (struct cs35l56_base *cs35l56_base, +const struct cs35l56_cal_debugfs_fops *fops); +void cs35l56_remove_cal_debugfs (struct cs35l56_base *cs35l56_base);int cs35l56_read_prot_status (struct cs35l56_base *cs35l56_base,bool *fw_missing,unsigned int *fw_version);void cs35l56_log_tuning (struct cs35l56_base *cs35l56_base,struct cs_dsp *cs_dsp);
sound/soc/codecs/Kconfig +3 -0
@@ -896,6 +896,9 @@ config SND_SOC_CS35L56_SDW help Enable support for Cirrus Logic CS35L56 boosted amplifier with SoundWire control +config SND_SOC_CS35L56_CAL_DEBUGFS_COMMON + bool + config SND_SOC_CS40L50 tristate "Cirrus Logic CS40L50 CODEC" depends on MFD_CS40L50_CORE
sound/soc/codecs/cs35l56-shared.c +295 -5
351 lines not on this page · raw message
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH v2 4/11 ASoC: cs35l56: Create debugfs files for factory calibration
In reply to Richard FitzgeraldCreate debugfs files that can be used to perform factory calibration.
During manufacture, the production line must perform a factory calibration of the amps. This patch adds this functionality via debugfs files.
As this is only needed during manufacture, there is no need for this to be available in a normal system so a Kconfig item has been added to enable this. The new Kconfig option is inside a sub-menu because items do not group and indent if the parent is invisible or there are multiple parent dependencies. Anyway the sub-menu reduces the clutter.
---
Changes in V2:
- File callbacks rewritten to be debugfs callbacks instead of sysfs callbacks.
- Replace the sysfs file definition and creation with debugfs creation.
sound/soc/codecs/Kconfig | 15 ++++ sound/soc/codecs/cs35l56.c | 159 +++++++++++++++++++++++++++++++++++++ sound/soc/codecs/cs35l56.h | 6 ++ 3 files changed, 180 insertions(+)
sound/soc/codecs/Kconfig +15 -0
@@ -899,6 +899,21 @@ config SND_SOC_CS35L56_SDW config SND_SOC_CS35L56_CAL_DEBUGFS_COMMON bool +menu "CS35L56 driver options" + depends on SND_SOC_CS35L56 + +config SND_SOC_CS35L56_CAL_DEBUGFS + bool "CS35L56 create debugfs for factory calibration" + default N + depends on DEBUG_FS + select SND_SOC_CS35L56_CAL_DEBUGFS_COMMON + help + Create debugfs entries used during factory-line manufacture + for factory calibration. + + If unsure select "N". +endmenu + config SND_SOC_CS40L50 tristate "Cirrus Logic CS40L50 CODEC" depends on MFD_CS40L50_CORE
sound/soc/codecs/cs35l56.c +159 -0
195 lines not on this page · raw message
sound/soc/codecs/cs35l56.h +6 -0
@@ -10,6 +10,7 @@#define CS35L56_H #include <linux/completion.h> +#include <linux/container_of.h> #include <linux/regulator/consumer.h> #include <linux/pm_runtime.h> #include <linux/workqueue.h>
@@ -54,6 +55,11 @@ struct cs35l56_private {u8 sdw_unique_id; }; +static inline struct cs35l56_private *cs35l56_private_from_base (struct cs35l56_base *cs35l56_base) +{ + return container_of(cs35l56_base, struct cs35l56_private, base); +} +extern const struct dev_pm_ops cs35l56_pm_ops_i2c_spi;int cs35l56_system_suspend (struct device *dev);
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH v2 5/11 ALSA: hda/cs35l56: Create debugfs files for factory calibration
In reply to Richard FitzgeraldCreate debugfs files that can be used to perform factory calibration.
During manufacture, the production line must perform a factory calibration of the amps. This commit adds this functionality via debugfs files.
As this is only needed during manufacture, there is no need for this to be available in a normal system so a Kconfig item has been added to enable this. The new Kconfig option is inside a sub-menu because items do not group and indent if the parent is invisible or there are multiple parent dependencies. Anyway the sub-menu reduces the clutter.
cs35l56_hda_apply_calibration() has been changed to return an error code that can be reported back through the debugfs write. The original call to this function doesn't check the return code because in normal use it doesn't matter whether this fails - the firmware will default to a safe calibration for the platform. But tooling using the debugfs files might want to know if there was an error.
---
Changes in V2:
- File callbacks rewritten to be debugfs callbacks instead of sysfs callbacks.
- Replace the sysfs file definition and creation with debugfs creation.
sound/hda/codecs/side-codecs/Kconfig | 15 +++ sound/hda/codecs/side-codecs/cs35l56_hda.c | 114 ++++++++++++++++++++- sound/hda/codecs/side-codecs/cs35l56_hda.h | 6 ++ 3 files changed, 130 insertions(+), 5 deletions(-)
sound/hda/codecs/side-codecs/Kconfig +15 -0
@@ -88,6 +88,21 @@ config SND_HDA_SCODEC_CS35L56_SPI Say Y or M here to include CS35L56 amplifier support with SPI control. +menu "CS35L56 driver options" + depends on SND_HDA_SCODEC_CS35L56 + +config SND_HDA_SCODEC_CS35L56_CAL_DEBUGFS + bool "CS35L56 create debugfs for factory calibration" + default N + depends on DEBUG_FS + select SND_SOC_CS35L56_CAL_DEBUGFS_COMMON + help + Create debugfs entries used during factory-line manufacture + for factory calibration. + + If unsure select "N". +endmenu + config SND_HDA_SCODEC_TAS2781 tristate select SND_HDA_GENERIC
sound/hda/codecs/side-codecs/cs35l56_hda.c +109 -5
154 lines not on this page · raw message
sound/hda/codecs/side-codecs/cs35l56_hda.h +6 -0
@@ -9,6 +9,7 @@#ifndef __CS35L56_HDA_H__#define __CS35L56_HDA_H__ +#include <linux/container_of.h> #include <linux/device.h> #include <linux/gpio/consumer.h> #include <linux/firmware/cirrus/cs_dsp.h>
@@ -42,6 +43,11 @@ struct cs35l56_hda {#endif }; +static inline struct cs35l56_hda *cs35l56_hda_from_base (struct cs35l56_base *cs35l56_base) +{ + return container_of(cs35l56_base, struct cs35l56_hda, base); +} +extern const struct dev_pm_ops cs35l56_hda_pm_ops;int cs35l56_hda_common_probe (struct cs35l56_hda *cs35l56,int hid,int id);
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH v2 6/11 ASoC: cs-amp-lib-test: Add cases for factory calibration helpers
In reply to Richard FitzgeraldAdd test cases for the cs_amp_read_cal_coeffs() and cs_amp_write_ambient_temp() functions.
In both cases the test is simply to confirm that the correct data value(s) get passed back to the caller.
---
No changes since V1.
include/sound/cs-amp-lib.h | 5 +- sound/soc/codecs/cs-amp-lib-test.c | 75 +++++++++++++++++++++++++++++- sound/soc/codecs/cs-amp-lib.c | 1 + 3 files changed, 79 insertions(+), 2 deletions(-)
include/sound/cs-amp-lib.h +4 -1
@@ -72,8 +72,11 @@ struct cs_amp_test_hooks {int (*write_cal_coeff)(struct cs_dsp *dsp,const struct cirrus_amp_cal_controls *controls,const char *ctl_name,u32 val); -}; +int (*read_cal_coeff)(struct cs_dsp *dsp, +const struct cirrus_amp_cal_controls *controls, + const char *ctl_name, u32 *val); +};extern const struct cs_amp_test_hooks *const cs_amp_test_hooks;#endif /* CS_AMP_LIB_H */
sound/soc/codecs/cs-amp-lib-test.c +74 -1
88 lines not on this page · raw message
sound/soc/codecs/cs-amp-lib.c +1 -0
@@ -541,6 +541,7 @@ EXPORT_SYMBOL_NS_GPL(cs_amp_create_debugfs, "SND_SOC_CS_AMP_LIB");static const struct cs_amp_test_hooks cs_amp_test_hook_ptrs = { .get_efi_variable = cs_amp_get_efi_variable, .write_cal_coeff = cs_amp_write_cal_coeff, + .read_cal_coeff = cs_amp_read_cal_coeff, }; const struct cs_amp_test_hooks * const cs_amp_test_hooks =
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH v2 7/11 ASoC: cs-amp-lib: Return attributes from cs_amp_get_efi_variable()
In reply to Richard FitzgeraldAdd a pointer argument to cs_amp_get_efi_variable() to optionally return the EFI variable attributes.
Originally this function internally consumed the attributes from efi.get_variable(). The calling code did not use the attributes so this was a small simplification.
However, when writing to a pre-existing variable we would want to pass the existing attributes to efi.set_variable(). This patch deals with the change to return the attribute in preparation for adding code to update the variable.
---
No changes since V1.
include/sound/cs-amp-lib.h | 1 + sound/soc/codecs/cs-amp-lib-test.c | 23 +++++++++++++++++++++++ sound/soc/codecs/cs-amp-lib.c | 15 ++++++++++----- 3 files changed, 34 insertions(+), 5 deletions(-)
include/sound/cs-amp-lib.h +1 -0
@@ -66,6 +66,7 @@ static inline u64 cs_amp_cal_target_u64(const struct cirrus_amp_cal_data *data)struct cs_amp_test_hooks {efi_status_t (*get_efi_variable)(efi_char16_t *name,efi_guid_t *guid, +u32 *returned_attr,unsigned long *size,void *buf);
sound/soc/codecs/cs-amp-lib-test.c +23 -0
@@ -89,6 +89,7 @@ static u64 cs_amp_lib_test_get_target_uid(struct kunit *test)/* Redirected get_efi_variable to simulate that the file is too short */ static efi_status_t cs_amp_lib_test_get_efi_variable_nohead (efi_char16_t *name,efi_guid_t *guid, +u32 *returned_attr,unsigned long *size,void *buf) {
@@ -121,6 +122,7 @@ static void cs_amp_lib_test_cal_data_too_short_test(struct kunit *test)/* Redirected get_efi_variable to simulate that the count is larger than the file */ static efi_status_t cs_amp_lib_test_get_efi_variable_bad_count (efi_char16_t *name,efi_guid_t *guid, +u32 *returned_attr,unsigned long *size,void *buf) {
@@ -164,6 +166,7 @@ static void cs_amp_lib_test_cal_count_too_big_test(struct kunit *test)/* Redirected get_efi_variable to simulate that the variable not found */ static efi_status_t cs_amp_lib_test_get_efi_variable_none (efi_char16_t *name,efi_guid_t *guid, +u32 *returned_attr,unsigned long *size,void *buf) {
@@ -191,6 +194,7 @@ static void cs_amp_lib_test_no_cal_data_test(struct kunit *test)/* Redirected get_efi_variable to simulate reading a cal data blob */ static efi_status_t cs_amp_lib_test_get_efi_variable (efi_char16_t *name,efi_guid_t *guid, +u32 *returned_attr,unsigned long *size,void *buf) {
@@ -217,11 +221,18 @@ static efi_status_t cs_amp_lib_test_get_efi_variable(efi_char16_t *name,memcpy (buf, priv->cal_blob, priv->cal_blob->size); +if (returned_attr) { + *returned_attr =EFI_VARIABLE_NON_VOLATILE | +EFI_VARIABLE_BOOTSERVICE_ACCESS | +EFI_VARIABLE_RUNTIME_ACCESS ; + } +return EFI_SUCCESS ; }static efi_status_t cs_amp_lib_test_get_hp_cal_efi_variable (efi_char16_t *name,efi_guid_t *guid, +u32 *returned_attr,unsigned long *size,void *buf) {
@@ -248,6 +259,12 @@ static efi_status_t cs_amp_lib_test_get_hp_cal_efi_variable(efi_char16_t *name,memcpy (buf, priv->cal_blob, priv->cal_blob->size); +if (returned_attr) { + *returned_attr =EFI_VARIABLE_NON_VOLATILE | +EFI_VARIABLE_BOOTSERVICE_ACCESS | +EFI_VARIABLE_RUNTIME_ACCESS ; + } +return EFI_SUCCESS ; }
@@ -786,6 +803,7 @@ static void cs_amp_lib_test_spkid_lenovo_not_present(struct kunit *test)static efi_status_t cs_amp_lib_test_get_efi_variable_lenovo_d0 (efi_char16_t *name,efi_guid_t *guid, +u32 *returned_attr,unsigned long *size,void *buf) {
@@ -804,6 +822,7 @@ static efi_status_t cs_amp_lib_test_get_efi_variable_lenovo_d0(efi_char16_t *namstatic efi_status_t cs_amp_lib_test_get_efi_variable_lenovo_d1 (efi_char16_t *name,efi_guid_t *guid, +u32 *returned_attr,unsigned long *size,void *buf) {
@@ -822,6 +841,7 @@ static efi_status_t cs_amp_lib_test_get_efi_variable_lenovo_d1(efi_char16_t *namstatic efi_status_t cs_amp_lib_test_get_efi_variable_lenovo_00 (efi_char16_t *name,efi_guid_t *guid, +u32 *returned_attr,unsigned long *size,void *buf) {
@@ -873,6 +893,7 @@ static void cs_amp_lib_test_spkid_lenovo_illegal(struct kunit *test)static efi_status_t cs_amp_lib_test_get_efi_variable_buf_too_small (efi_char16_t *name,efi_guid_t *guid, +u32 *returned_attr,unsigned long *size,void *buf) {
@@ -893,6 +914,7 @@ static void cs_amp_lib_test_spkid_lenovo_oversize(struct kunit *test)static efi_status_t cs_amp_lib_test_get_efi_variable_hp_30 (efi_char16_t *name,efi_guid_t *guid, +u32 *returned_attr,unsigned long *size,void *buf) {
@@ -911,6 +933,7 @@ static efi_status_t cs_amp_lib_test_get_efi_variable_hp_30(efi_char16_t *name,static efi_status_t cs_amp_lib_test_get_efi_variable_hp_31 (efi_char16_t *name,efi_guid_t *guid, +u32 *returned_attr,unsigned long *size,void *buf) {
sound/soc/codecs/cs-amp-lib.c +10 -5
@@ -245,15 +245,20 @@ EXPORT_SYMBOL_NS_GPL(cs_amp_write_ambient_temp, "SND_SOC_CS_AMP_LIB");static efi_status_t cs_amp_get_efi_variable (efi_char16_t *name,efi_guid_t *guid, +u32 *returned_attr,unsigned long *size,void *buf) {u32 attr; -KUNIT_STATIC_STUB_REDIRECT (cs_amp_get_efi_variable, name, guid, size, buf); +if (!returned_attr) + returned_attr = &attr; + +KUNIT_STATIC_STUB_REDIRECT (cs_amp_get_efi_variable, name, guid, + returned_attr, size, buf);if (efi_rt_services_supported (EFI_RT_SUPPORTED_GET_VARIABLE )) -return efi.get_variable (name, guid, &attr, size, buf); +return efi.get_variable (name, guid, returned_attr, size, buf);return EFI_NOT_FOUND ; }
@@ -288,7 +293,7 @@ static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev)for (i =0 ; i <ARRAY_SIZE (cs_amp_lib_cal_efivars); i++) { status =cs_amp_get_efi_variable (cs_amp_lib_cal_efivars[i].name, cs_amp_lib_cal_efivars[i].guid, - &data_size,NULL ); +NULL , &data_size,NULL );if (status ==EFI_BUFFER_TOO_SMALL )break ; }
@@ -308,7 +313,7 @@ static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev) status =cs_amp_get_efi_variable (cs_amp_lib_cal_efivars[i].name, cs_amp_lib_cal_efivars[i].guid, - &data_size, data); +NULL , &data_size, data);if (status !=EFI_SUCCESS ) { ret = -EINVAL ; goto err;
@@ -452,7 +457,7 @@ static int cs_amp_get_efi_byte_spkid(struct device *dev, const struct cs_amp_spkint i, ret; size =sizeof (spkid); - status =cs_amp_get_efi_variable (info->name, info->guid, &size, &spkid); + status =cs_amp_get_efi_variable (info->name, info->guid,NULL , &size, &spkid); ret =cs_amp_convert_efi_status (status);if (ret <0 )return ret;
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH v2 8/11 ASoC: cs-amp-lib: Add function to write calibration to UEFI
In reply to Richard FitzgeraldAdd cs_amp_set_efi_calibration_data() to write an amp calibration blob to UEFI calibration variable.
The UEFI variable will be updated or created as necessary.
- If a Vendor-specific variable exists it will be updated, else if the Cirrus variable exists it will be update else the Cirrus variable will be created.
Some collateral changes are required:
- cs_amp_convert_efi_status() now specifically handles EFI_WRITE_PROTECTED error.
- cs_amp_get_cal_efi_buffer() can optionally return the name, guid and attr of the variable it found.
- cs_amp_get_cal_efi_buffer() will update the 'size' field of the returned data blob if it is zero. The BIOS could have pre-allocated the UEFI variable as zero-filled
---
No changes since V1.
include/sound/cs-amp-lib.h | 2 + sound/soc/codecs/cs-amp-lib.c | 190 +++++++++++++++++++++++++++++++++- 2 files changed, 188 insertions(+), 4 deletions(-)
include/sound/cs-amp-lib.h +2 -0
@@ -55,6 +55,8 @@ int cs_amp_write_ambient_temp(struct cs_dsp *dsp, u32 temp);int cs_amp_get_efi_calibration_data (struct device *dev,u64 target_uid,int amp_index,struct cirrus_amp_cal_data *out_data); +int cs_amp_set_efi_calibration_data (struct device *dev,int amp_index,int num_amps, +const struct cirrus_amp_cal_data *in_data);int cs_amp_get_vendor_spkid (struct device *dev);struct dentry *cs_amp_create_debugfs (struct device *dev);
sound/soc/codecs/cs-amp-lib.c +186 -4
271 lines not on this page · raw message
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH v2 9/11 ASoC: cs35l56: Add calibration command to store into UEFI
In reply to Richard FitzgeraldAdd a new command 'store_uefi' to the calibrate debugfs file. Writing this command will call cs_amp_set_efi_calibration_data() to save the new data into a UEFI variable. This is intended to be used after a successful factory calibration.
On systems without UEFI the write to the debugfs file will return an error.
---
Changes since V1:
- Rebased onto the new debugfs callback implementation
- Only code change since V1 is to increase the size of the local char array buf[].
include/sound/cs35l56.h | 1 + sound/soc/codecs/cs35l56-shared.c | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-)
include/sound/cs35l56.h +1 -0
@@ -321,6 +321,7 @@ struct cs35l56_base {bool can_hibernate;bool cal_data_valid;s8 cal_index; +u8 num_amps;struct cirrus_amp_cal_data cal_data;struct gpio_desc *reset_gpio;struct cs35l56_spi_payload *spi_payload_buf;
sound/soc/codecs/cs35l56-shared.c +18 -3
@@ -1105,9 +1105,9 @@ ssize_t cs35l56_calibrate_debugfs_write(struct cs35l56_base *cs35l56_base, const char __user *from, size_t count, loff_t *ppos) { - static const char * const options[] = { "factory" }; -char buf[8 ] = {0 }; -int ret; + static const char * const options[] = { "factory", "store_uefi" }; +char buf[11 ] = {0 }; +int num_amps, ret;if (!IS_ENABLED (CONFIG_SND_SOC_CS35L56_CAL_DEBUGFS_COMMON ))return -ENXIO ;
@@ -1125,6 +1125,21 @@ ssize_t cs35l56_calibrate_debugfs_write(struct cs35l56_base *cs35l56_base,if (ret <0 )return ret;break ; +case 1 : +if (!cs35l56_base->cal_data_valid) +return -ENODATA ; + + num_amps = cs35l56_base->num_amps; +if (num_amps ==0 ) + num_amps =-1 ; + + ret =cs_amp_set_efi_calibration_data (cs35l56_base->dev, + cs35l56_base->cal_index, + num_amps, + &cs35l56_base->cal_data); +if (ret <0 ) +return ret; +break ;default :return -ENXIO ; }
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH v2 10/11 ALSA: hda/cs35l56: Set cal_index to the amp index
In reply to Richard FitzgeraldSet cs35l56_base->cal_index to the (zero-based) amp index derived from cirrus,dev-index property.
This is so that factory calibration data will be written to the UEFI array in the slot equal to the amp index, for compatibility with the Windows driver.
---
No changes since V1.
sound/hda/codecs/side-codecs/cs35l56_hda.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/hda/codecs/side-codecs/cs35l56_hda.c +1 -1
@@ -1154,7 +1154,7 @@ int cs35l56_hda_common_probe(struct cs35l56_hda *cs35l56, int hid, int id) } cs35l56->base.type = hid &0xff ; - cs35l56->base.cal_index =-1 ; + cs35l56->base.cal_index = cs35l56->index;cs35l56_init_cs_dsp (&cs35l56->base, &cs35l56->cs_dsp); cs35l56->cs_dsp.client_ops = &cs35l56_hda_client_ops;
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH v2 11/11 ASoC: cs-amp-lib-test: Add test cases for cs_amp_set_efi_calibration_data()
In reply to Richard FitzgeraldAdd a set of test cases for cs_amp_set_efi_calibration_data().
Broadly there are two type of behavior being tested:
How the EFI is updated:
- Create a new EFI
- Overwrite part of existing content
- Overwrite part of zero-filled preallocated content
- Grow the file to append new content
And how the location within the content is chosen:
- Overwrite a specific array entry
- Overwrite an entry with the same calTarget (silicon ID)
- Overwrite a free entry
- Append after existing data
Plus some cases for error conditions.
---
No changes since V1.
include/sound/cs-amp-lib.h | 5 + sound/soc/codecs/cs-amp-lib-test.c | 1399 +++++++++++++++++++++++++++- sound/soc/codecs/cs-amp-lib.c | 1 + 3 files changed, 1397 insertions(+), 8 deletions(-)
include/sound/cs-amp-lib.h +5 -0
@@ -71,6 +71,11 @@ struct cs_amp_test_hooks {u32 *returned_attr, unsigned long *size, void *buf); +efi_status_t (*set_efi_variable)(efi_char16_t *name, +efi_guid_t *guid, +u32 attr, +unsigned long size, +void *buf); int (*write_cal_coeff)(struct cs_dsp *dsp, const struct cirrus_amp_cal_controls *controls,
sound/soc/codecs/cs-amp-lib-test.c +1391 -8
1,454 lines not on this page · raw message
sound/soc/codecs/cs-amp-lib.c +1 -0
@@ -727,6 +727,7 @@ EXPORT_SYMBOL_NS_GPL(cs_amp_create_debugfs, "SND_SOC_CS_AMP_LIB");static const struct cs_amp_test_hooks cs_amp_test_hook_ptrs = { .get_efi_variable = cs_amp_get_efi_variable, + .set_efi_variable = cs_amp_set_efi_variable, .write_cal_coeff = cs_amp_write_cal_coeff, .read_cal_coeff = cs_amp_read_cal_coeff, };
Signature · 1 line
2.47.3
Mark Brown
maintainerQuoted 5 lines · Richard Fitzgerald
NOTE: unfortunately this is yet another series that is mainly ASoC but also needs some changes to the HDA driver, and they have build dependencies on the ASoC code. I suggest taking this all through Mark's tree and we'll avoid sending any other commits to the HDA driver until it has all landed in Takashi's tree.
That seems like a reasonable plan to me, Takashi?
Takashi Iwai
Reviewed-byQuoted 10 lines · Mark Brown
Quoted 5 lines · Richard Fitzgerald
NOTE: unfortunately this is yet another series that is mainly ASoC but also needs some changes to the HDA driver, and they have build dependencies on the ASoC code. I suggest taking this all through Mark's tree and we'll avoid sending any other commits to the HDA driver until it has all landed in Takashi's tree.
That seems like a reasonable plan to me, Takashi?
Sorry for the late reaction, as I was off in the last week.
Let's get them through Mark's tree as suggested.
Feel free to take my ack:
thanks,
Takashi
Mark Brown
maintainerQuoted 9 lines · Richard Fitzgerald
Until now, all products with an amplifier supported by the cs35l56 driver have shipped with Microsoft Windows pre-installed. The factory calibration of speaker protection has therefore been done using the Windows driver.
However, products that ship with a Linux-based distro must be able to perform the factory calibration procedure from within the Linux-based environment. This patch series adds that support.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[01/11] ASoC: cs35l56: Read silicon ID during initialization and save it
commit: 1afc05996299b4546e8be9b13c89f78e19912c7d
[02/11] ASoC: cs-amp-lib: Add helpers for factory calibration
commit: cdd27fa3298ad2f39788804f7d09ab31af2b416c
[03/11] ASoC: cs35l56: Add common code for factory calibration
commit: f7097161e94cd39df7a8848ad0de5f394124ed69
[04/11] ASoC: cs35l56: Create debugfs files for factory calibration
commit: 191a27faf53edf9e9101901e402bfee49c44073c
[05/11] ALSA: hda/cs35l56: Create debugfs files for factory calibration
commit: 46a3df50b0cab466099515f2375b01c5be4fb95c
[06/11] ASoC: cs-amp-lib-test: Add cases for factory calibration helpers
commit: cf6290eebe3cc4eb677d11aa061d10cb1df12ab9
[07/11] ASoC: cs-amp-lib: Return attributes from cs_amp_get_efi_variable()
commit: 959400caf51eb31f95d1ab754a285b5546ebd3e4
[08/11] ASoC: cs-amp-lib: Add function to write calibration to UEFI
commit: 2b62e66626f05e277c8fdeb50d4c1e0cbab2fe0e
[09/11] ASoC: cs35l56: Add calibration command to store into UEFI
commit: ef24466ee1912997c2bd526194006bbca424c24f
[10/11] ALSA: hda/cs35l56: Set cal_index to the amp index
commit: 64670a6c062c4d183c366d46e71ee76395af6a15
[11/11] ASoC: cs-amp-lib-test: Add test cases for cs_amp_set_efi_calibration_data()
commit: 4795375d8aa072e9aacb0b278e6203c6ca41816aAll being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark