Skip to contentSkip to conversation

ASoC: cs35l56: Allow factory calibration through ALSA controls

PATCH Superseded Richard Fitzgerald 2 participants 4 messages Mar 24

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Richard Fitzgerald

author maintainer
#0 lore raw

PATCH 1/1 ASoC: cs35l56: Allow factory calibration through ALSA controls

Add support for using ALSA controls to trigger a factory calibration. This is protected by a new Kconfig option so that it is only available if explicitly enabled in the kernel. By default it is not enabled.

Factory calibration is normally done through debugfs files. Google have requested that factory calibration can be performed by repair shops. These repair shops only have access to the standard "user" kernel, which does not include debugfs.

---
 include/sound/cs35l56.h           |  1 +
 sound/soc/codecs/Kconfig          | 13 +++++
 sound/soc/codecs/cs35l56-shared.c |  9 ++++
 sound/soc/codecs/cs35l56.c        | 89 +++++++++++++++++++++++++++++++
 4 files changed, 112 insertions(+)
include/sound/cs35l56.h +1 -0
index 7ca25487030a..c3b10587cb4c 100644
@@ -435,6 +435,7 @@ ssize_t cs35l56_cal_data_debugfs_read(struct cs35l56_base *cs35l56_base,
 ssize_t cs35l56_cal_data_debugfs_write(struct cs35l56_base *cs35l56_base,
 				       const char __user *from, size_t count,
 				       loff_t *ppos);
+int cs35l56_factory_calibrate(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);
sound/soc/codecs/Kconfig +13 -0
index d6104796db4f..ca3e47db126e 100644
@@ -921,6 +921,19 @@ config SND_SOC_CS35L56_CAL_SET_CTRL
 
 	  If unsure select "N".
 
+config SND_SOC_CS35L56_CAL_PERFORM_CTRL
+	bool "CS35L56 ALSA control to perform factory calibration"
+	default N
+	select SND_SOC_CS35L56_CAL_DEBUGFS_COMMON
+	help
+	  Allow performing factory calibration data through an ALSA
+	  control. It is recommended to use the debugfs method instead
+	  because debugfs has restricted access permissions.
+
+	  On most platforms this is not needed.
+
+	  If unsure select "N".
+
 config SND_SOC_CS35L56_TEST
 	tristate "KUnit test for Cirrus Logic cs35l56 driver" if !KUNIT_ALL_TESTS
 	depends on SND_SOC_CS35L56 && KUNIT
sound/soc/codecs/cs35l56-shared.c +9 -0
index af87ebae98cb..e05d975ba794 100644
@@ -1185,6 +1185,15 @@ ssize_t cs35l56_calibrate_debugfs_write(struct cs35l56_base *cs35l56_base,
 }
 EXPORT_SYMBOL_NS_GPL(cs35l56_calibrate_debugfs_write, "SND_SOC_CS35L56_SHARED");
 
+int cs35l56_factory_calibrate(struct cs35l56_base *cs35l56_base)
+{
+	if (!IS_ENABLED(CONFIG_SND_SOC_CS35L56_CAL_PERFORM_CTRL))
+		return -ENXIO;
+
+	return cs35l56_perform_calibration(cs35l56_base);
+}
+EXPORT_SYMBOL_NS_GPL(cs35l56_factory_calibrate, "SND_SOC_CS35L56_SHARED");
+
 ssize_t cs35l56_cal_ambient_debugfs_write(struct cs35l56_base *cs35l56_base,
 					  const char __user *from, size_t count,
 					  loff_t *ppos)
sound/soc/codecs/cs35l56.c +89 -0

107 lines not on this page · raw message

Signature · 1 line
2.47.3
maintainer
#1 lore raw

sound/soc/codecs/cs35l56.c static int cs35l56_cal_data_ctl_set(struct snd_kcontrol *kcontrol, · line 1133

Quoted 10 lines · Richard Fitzgerald
sound/soc/codecs/cs35l56.c +10 -0
+static int cs35l56_cal_ambient_ctl_set(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);
+	struct snd_soc_dapm_context *dapm;
+	int ret;
+
+	if (!in_range(ucontrol->value.integer.value[0], 5, 35))
+		return -EINVAL;

The values range from 5..35...

sound/soc/codecs/cs35l56.c static const struct snd_kcontrol_new cs35l56_cal_data_restore_controls[] = { · line 1198

Quoted 3 lines
sound/soc/codecs/cs35l56.c +3 -0
+static const struct snd_kcontrol_new cs35l56_cal_perform_controls[] = {
+	SOC_SINGLE_EXT("CAL_AMBIENT", SND_SOC_NOPM, 0, 40, 0,
+		       cs35l56_cal_ambient_ctl_get, cs35l56_cal_ambient_ctl_set),

...but the range is from 0..40? I'd expect mixer-test to complain about both these controls too, they're not flagged as volatile.

author maintainer
#2 lore raw
Quoted 15 lines · Mark Brown

sound/soc/codecs/cs35l56.c static int cs35l56_cal_data_ctl_set(struct snd_kcontrol *kcontrol, · line 1133

Quoted 10 lines · Richard Fitzgerald
sound/soc/codecs/cs35l56.c +10 -0
+static int cs35l56_cal_ambient_ctl_set(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);
+	struct snd_soc_dapm_context *dapm;
+	int ret;
+
+	if (!in_range(ucontrol->value.integer.value[0], 5, 35))
+		return -EINVAL;

The values range from 5..35...

The second argument to in_range() isn't a max.
But if I'm sending a new version to make them volatile I can also change it to not use the in_range() macro.

Quoted 6 lines

sound/soc/codecs/cs35l56.c static const struct snd_kcontrol_new cs35l56_cal_data_restore_controls[] = { · line 1198

Quoted 3 lines
sound/soc/codecs/cs35l56.c +3 -0
+static const struct snd_kcontrol_new cs35l56_cal_perform_controls[] = {
+	SOC_SINGLE_EXT("CAL_AMBIENT", SND_SOC_NOPM, 0, 40, 0,
+		       cs35l56_cal_ambient_ctl_get, cs35l56_cal_ambient_ctl_set),

...but the range is from 0..40? I'd expect mixer-test to complain about both these controls too, they're not flagged as volatile.

maintainer
#3 lore raw
Quoted 11 lines · Richard Fitzgerald
Quoted 6 lines · Mark Brown

Review

Quoted 2 lines · Richard Fitzgerald
(quoted diff) +2 -0
+	if (!in_range(ucontrol->value.integer.value[0], 5, 35))
+		return -EINVAL;

The values range from 5..35...

The second argument to in_range() isn't a max.
But if I'm sending a new version to make them volatile I can also change it to not use the in_range() macro.

Ah, indeed - that's a bit of a footgun! Still, there's also the 0..4 range that's advertised to userspace but not actually valid.