Skip to contentSkip to conversation

ASoC: cs35l56: Support for restoring calibration on ChromeOS

PATCH In review Richard Fitzgerald 2 participants 7 messages Nov 11, 2025

Subsystems (3)
lore
Share & tools
lore

Richard Fitzgerald

author maintainer
#0 lore raw

cover ASoC: cs35l56: Support for restoring calibration on ChromeOS

These two patches add ALSA controls to support restoring factory calibration during OS boot on ChromeOS.

ChromeOS applies calibration during boot using a process that has restricted access permissions. This process needs ALSA controls for all settings that it must restore.

Richard Fitzgerald (2):
ASoC: cs35l56: Add control to read CAL_SET_STATUS
ASoC: cs35l56: Allow restoring factory calibration through ALSA
control

 include/sound/cs35l56.h           | 11 ++++
 sound/soc/codecs/Kconfig          | 14 ++++++
 sound/soc/codecs/cs35l56-shared.c | 53 +++++++++++++++++++-
 sound/soc/codecs/cs35l56.c        | 83 +++++++++++++++++++++++++++++++
 4 files changed, 159 insertions(+), 2 deletions(-)
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH 1/2 ASoC: cs35l56: Add control to read CAL_SET_STATUS

Create an ALSA control to read the value of the firmware CAL_SET_STATUS control. This reports whether the firmware is using a calibration blob or the default calibration from the .bin file.

The firmware only reports a valid value in this register while audio is actually playing and the internal PLL is locked to the audio clock. Otherwise it returns a status of "unknown".

---
 include/sound/cs35l56.h           |  9 ++++++
 sound/soc/codecs/cs35l56-shared.c | 48 +++++++++++++++++++++++++++++++
 sound/soc/codecs/cs35l56.c        | 16 +++++++++++
 3 files changed, 73 insertions(+)
include/sound/cs35l56.h +9 -0
index 0a740a99ad31..bd13958bf19d 100644
@@ -16,6 +16,8 @@
 #include <linux/spi/spi.h>
 #include <sound/cs-amp-lib.h>
 
+struct snd_ctl_elem_value;
+
 #define CS35L56_DEVID					0x0000000
 #define CS35L56_REVID					0x0000004
 #define CS35L56_RELID					0x000000C
@@ -268,6 +270,10 @@
 #define CS35L56_CAL_STATUS_SUCCESS			1
 #define CS35L56_CAL_STATUS_OUT_OF_RANGE			3
 
+#define CS35L56_CAL_SET_STATUS_UNKNOWN			0
+#define CS35L56_CAL_SET_STATUS_DEFAULT			1
+#define CS35L56_CAL_SET_STATUS_SET			2
+
 #define CS35L56_CONTROL_PORT_READY_US			2200
 #define CS35L56_HALO_STATE_POLL_US			1000
 #define CS35L56_HALO_STATE_TIMEOUT_US			250000
@@ -363,6 +369,7 @@ extern const struct regmap_config cs35l63_regmap_i2c;
 extern const struct regmap_config cs35l63_regmap_sdw;
 
 extern const struct cirrus_amp_cal_controls cs35l56_calibration_controls;
+extern const char * const cs35l56_cal_set_status_text[3];
 
 extern const char * const cs35l56_tx_input_texts[CS35L56_NUM_INPUT_SRC];
 extern const unsigned int cs35l56_tx_input_values[CS35L56_NUM_INPUT_SRC];
@@ -396,6 +403,8 @@ ssize_t cs35l56_cal_data_debugfs_write(struct cs35l56_base *cs35l56_base,
 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_cal_set_status_get(struct cs35l56_base *cs35l56_base,
+			       struct snd_ctl_elem_value *uvalue);
 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/cs35l56-shared.c +48 -0

54 lines not on this page · raw message

sound/soc/codecs/cs35l56.c +16 -0
index 091a72325507..e1eb7360b058 100644
@@ -66,6 +66,18 @@ static int cs35l56_dspwait_put_volsw(struct snd_kcontrol *kcontrol,
 
 static DECLARE_TLV_DB_SCALE(vol_tlv, -10000, 25, 0);
 
+static SOC_ENUM_SINGLE_DECL(cs35l56_cal_set_status_enum, SND_SOC_NOPM, 0,
+			    cs35l56_cal_set_status_text);
+
+static int cs35l56_cal_set_status_ctl_get(struct snd_kcontrol *kcontrol,
+					  struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+	struct cs35l56_private *cs35l56 = snd_soc_component_get_drvdata(component);
+
+	return cs35l56_cal_set_status_get(&cs35l56->base, ucontrol);
+}
+
 static const struct snd_kcontrol_new cs35l56_controls[] = {
 	SOC_SINGLE_EXT("Speaker Switch",
 		       CS35L56_MAIN_RENDER_USER_MUTE, 0, 1, 1,
@@ -83,6 +95,8 @@ static const struct snd_kcontrol_new cs35l56_controls[] = {
 	SOC_SINGLE_EXT("Posture Number", CS35L56_MAIN_POSTURE_NUMBER,
 		       0, 255, 0,
 		       cs35l56_dspwait_get_volsw, cs35l56_dspwait_put_volsw),
+	SOC_ENUM_EXT("CAL_SET_STATUS", cs35l56_cal_set_status_enum,
+		     cs35l56_cal_set_status_ctl_get, NULL),
 };
 
 static const struct snd_kcontrol_new cs35l63_controls[] = {
@@ -102,6 +116,8 @@ static const struct snd_kcontrol_new cs35l63_controls[] = {
 	SOC_SINGLE_EXT("Posture Number", CS35L63_MAIN_POSTURE_NUMBER,
 		       0, 255, 0,
 		       cs35l56_dspwait_get_volsw, cs35l56_dspwait_put_volsw),
+	SOC_ENUM_EXT("CAL_SET_STATUS", cs35l56_cal_set_status_enum,
+		     cs35l56_cal_set_status_ctl_get, NULL),
 };
 
 static SOC_VALUE_ENUM_SINGLE_DECL(cs35l56_asp1tx1_enum,
Signature · 1 line
2.47.3
author maintainer
#2 lore raw

PATCH 2/2 ASoC: cs35l56: Allow restoring factory calibration through ALSA control

In reply to Richard Fitzgerald

Add an ALSA control (CAL_DATA) that can be used to restore amp calibration, instead of using debugfs. A readback control (CAL_DATA_RB) is also added for factory testing.

On ChromeOS the process that restores amp calibration from NVRAM has limited permissions and cannot access debugfs. It requires an ALSA control that it can write the calibration blob into. ChromeOS also restricts access to ALSA controls, which avoids the risk of accidental or malicious overwriting of good calibration data with bad data. As this control is not needed for normal Linux-based distros it is a Kconfig option.

A separate control, CAL_DATA_RB, provides a readback of the current calibration data, which could be either from a write to CAL_DATA or the result of factory production-line calibration.

The write and read are intentionally separate controls to defeat "dumb" save-and-restore tools like alsa-restore that assume it is safe to save all control values and write them back in any order at some undefined future time. Such behavior carries the risk of restoring stale or bad data over the top of good data.

---
 include/sound/cs35l56.h           |  2 +
 sound/soc/codecs/Kconfig          | 14 +++++++
 sound/soc/codecs/cs35l56-shared.c |  5 ++-
 sound/soc/codecs/cs35l56.c        | 67 +++++++++++++++++++++++++++++++
 4 files changed, 86 insertions(+), 2 deletions(-)
include/sound/cs35l56.h +2 -0
index bd13958bf19d..883f6a7e50aa 100644
@@ -388,6 +388,8 @@ 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);
+int cs35l56_stash_calibration(struct cs35l56_base *cs35l56_base,
+			      const struct cirrus_amp_cal_data *data);
 ssize_t cs35l56_calibrate_debugfs_write(struct cs35l56_base *cs35l56_base,
 					const char __user *from, size_t count,
 					loff_t *ppos);
sound/soc/codecs/Kconfig +14 -0
index 6da2fff9323c..433af9bc7564 100644
@@ -912,6 +912,20 @@ config SND_SOC_CS35L56_CAL_DEBUGFS
 	  Create debugfs entries used during factory-line manufacture
 	  for factory calibration.
 
+	  If unsure select "N".
+
+config SND_SOC_CS35L56_CAL_SET_CTRL
+	bool "CS35L56 ALSA control to restore factory calibration"
+	default N
+	select SND_SOC_CS35L56_CAL_SYSFS_COMMON
+	help
+	  Allow restoring factory calibration data through an ALSA
+	  control. This is only needed on platforms without UEFI or
+	  some other method of non-volatile storage that the driver
+	  can access directly.
+
+	  On most platforms this is not needed.
+
 	  If unsure select "N".
 endmenu
 
sound/soc/codecs/cs35l56-shared.c +3 -2
index 4fba4127c40c..7424e1353062 100644
@@ -962,8 +962,8 @@ int cs35l56_get_calibration(struct cs35l56_base *cs35l56_base)
 }
 EXPORT_SYMBOL_NS_GPL(cs35l56_get_calibration, "SND_SOC_CS35L56_SHARED");
 
-static int cs35l56_stash_calibration(struct cs35l56_base *cs35l56_base,
-				     const struct cirrus_amp_cal_data *data)
+int cs35l56_stash_calibration(struct cs35l56_base *cs35l56_base,
+			      const struct cirrus_amp_cal_data *data)
 {
 
 	/* Ignore if it is empty */
@@ -980,6 +980,7 @@ static int cs35l56_stash_calibration(struct cs35l56_base *cs35l56_base,
 
 	return 0;
 }
+EXPORT_SYMBOL_NS_GPL(cs35l56_stash_calibration, "SND_SOC_CS35L56_SHARED");
 
 static int cs35l56_perform_calibration(struct cs35l56_base *cs35l56_base)
 {
sound/soc/codecs/cs35l56.c +67 -0

79 lines not on this page · raw message

Signature · 1 line
2.47.3
maintainer
#3 lore raw

Re: [PATCH 2/2] ASoC: cs35l56: Allow restoring factory calibration through ALSA control

sound/soc/codecs/Kconfig config SND_SOC_CS35L56_CAL_DEBUGFS · line 920

Quoted 4 lines · Richard Fitzgerald
sound/soc/codecs/Kconfig +4 -0
+config SND_SOC_CS35L56_CAL_SET_CTRL
+	bool "CS35L56 ALSA control to restore factory calibration"
+	default N
+	select SND_SOC_CS35L56_CAL_SYSFS_COMMON

Not a big deal (don't bother with a new version) but N is the default default.

author maintainer
#4 lore raw

Re: [PATCH 2/2] ASoC: cs35l56: Allow restoring factory calibration through ALSA control

Quoted 9 lines · Mark Brown

sound/soc/codecs/Kconfig config SND_SOC_CS35L56_CAL_DEBUGFS · line 920

Quoted 4 lines · Richard Fitzgerald
sound/soc/codecs/Kconfig +4 -0
+config SND_SOC_CS35L56_CAL_SET_CTRL
+	bool "CS35L56 ALSA control to restore factory calibration"
+	default N
+	select SND_SOC_CS35L56_CAL_SYSFS_COMMON

Not a big deal (don't bother with a new version) but N is the default default.

Well, at least it self-documents that we _want_ N to be the default. But if that's considered bad grammar I don't mind if it's removed.

maintainer
#5 lore raw

Re: [PATCH 2/2] ASoC: cs35l56: Allow restoring factory calibration through ALSA control

Quoted 7 lines · Richard Fitzgerald
Quoted 2 lines · Mark Brown

Not a big deal (don't bother with a new version) but N is the default default.

Well, at least it self-documents that we _want_ N to be the default. But if that's considered bad grammar I don't mind if it's removed.

Yes, I can see why you did it. I don't super care either way, but I suspect someone will come along and clean it up.

maintainer
#6 lore raw
In reply to Richard Fitzgerald
Quoted 8 lines · Richard Fitzgerald

These two patches add ALSA controls to support restoring factory calibration during OS boot on ChromeOS.

ChromeOS applies calibration during boot using a process that has restricted access permissions. This process needs ALSA controls for all settings that it must restore.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/2] ASoC: cs35l56: Add control to read CAL_SET_STATUS

      commit: 69f3474a01e9867dd99fc4b703fa834ea1835c7d
[2/2] ASoC: cs35l56: Allow restoring factory calibration through ALSA control
      commit: 32172cf3cb543a04c41a1677c97a38e60cad05b6

All 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