diff mbox series

[13/15] ASoC: ops: Factor out common code from get callbacks

Message ID 20250318171459.3203730-14-ckeepax@opensource.cirrus.com (mailing list archive)
State Superseded
Headers show
Series Tidy up ASoC control get and put handlers | expand

Commit Message

Charles Keepax March 18, 2025, 5:14 p.m. UTC
There are only two differences between snd_soc_get_volsw() and
snd_soc_get_volsw_sx(). The maximum field is handled differently, and
snd_soc_get_volsw() supports double controls with both values in the
same register.

Factor out the common code into a new helper and pass in the
appropriate max value such that it is handled correctly for each
control.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
 sound/soc/soc-ops.c | 66 ++++++++++++++++++++-------------------------
 1 file changed, 29 insertions(+), 37 deletions(-)

Comments

Mark Brown March 19, 2025, 3:12 p.m. UTC | #1
On Tue, Mar 18, 2025 at 05:14:57PM +0000, Charles Keepax wrote:
> There are only two differences between snd_soc_get_volsw() and
> snd_soc_get_volsw_sx(). The maximum field is handled differently, and
> snd_soc_get_volsw() supports double controls with both values in the
> same register.

This breaks an x86 allmodconfig build:

/build/stage/linux/sound/soc/soc-ops.c: In function ‘snd_soc_get_volsw_sx’:
/build/stage/linux/sound/soc/soc-ops.c:374:22: error: unused variable ‘reg2’ [-W
error=unused-variable]
  374 |         unsigned int reg2 = mc->rreg;
      |                      ^~~~
/build/stage/linux/sound/soc/soc-ops.c:373:22: error: unused variable ‘reg’ [-We
rror=unused-variable]
  373 |         unsigned int reg = mc->reg;
      |                      ^~~
cc1: all warnings being treated as errors

Please ensure your serieses are bisectable.
Charles Keepax March 19, 2025, 4:04 p.m. UTC | #2
On Wed, Mar 19, 2025 at 03:12:56PM +0000, Mark Brown wrote:
> On Tue, Mar 18, 2025 at 05:14:57PM +0000, Charles Keepax wrote:
> > There are only two differences between snd_soc_get_volsw() and
> > snd_soc_get_volsw_sx(). The maximum field is handled differently, and
> > snd_soc_get_volsw() supports double controls with both values in the
> > same register.
> 
> This breaks an x86 allmodconfig build:
> 
> /build/stage/linux/sound/soc/soc-ops.c: In function ‘snd_soc_get_volsw_sx’:
> /build/stage/linux/sound/soc/soc-ops.c:374:22: error: unused variable ‘reg2’ [-W
> error=unused-variable]
>   374 |         unsigned int reg2 = mc->rreg;
>       |                      ^~~~
> /build/stage/linux/sound/soc/soc-ops.c:373:22: error: unused variable ‘reg’ [-We
> rror=unused-variable]
>   373 |         unsigned int reg = mc->reg;
>       |                      ^~~
> cc1: all warnings being treated as errors
> 
> Please ensure your serieses are bisectable.

Sorry those do get cleaned up in the next patch but will respin
to move them into this patch, must have got muddled in the rebase
at some point.

Thanks,
Charles
Mark Brown March 19, 2025, 4:08 p.m. UTC | #3
On Wed, Mar 19, 2025 at 04:04:57PM +0000, Charles Keepax wrote:

> Sorry those do get cleaned up in the next patch but will respin
> to move them into this patch, must have got muddled in the rebase
> at some point.

I've still got all the prior patches queued so only this and following
patches need a resend unless runtime testing turns something up.
diff mbox series

Patch

diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index 0b62ffb2e222f..3ec3242a2b114 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -243,6 +243,33 @@  static int soc_put_volsw(struct snd_kcontrol *kcontrol,
 	return ret;
 }
 
+static int soc_get_volsw(struct snd_kcontrol *kcontrol,
+			 struct snd_ctl_elem_value *ucontrol,
+			 struct soc_mixer_control *mc, int mask, int max)
+{
+	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+	unsigned int reg_val;
+	int val;
+
+	reg_val = snd_soc_component_read(component, mc->reg);
+	val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, max);
+
+	ucontrol->value.integer.value[0] = val;
+
+	if (snd_soc_volsw_is_stereo(mc)) {
+		if (mc->reg == mc->rreg) {
+			val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->rshift, max);
+		} else {
+			reg_val = snd_soc_component_read(component, mc->rreg);
+			val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, max);
+		}
+
+		ucontrol->value.integer.value[1] = val;
+	}
+
+	return 0;
+}
+
 /**
  * snd_soc_info_volsw - single mixer info callback with range.
  * @kcontrol: mixer control
@@ -299,31 +326,11 @@  EXPORT_SYMBOL_GPL(snd_soc_info_volsw_sx);
 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
 		      struct snd_ctl_elem_value *ucontrol)
 {
-	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
 	struct soc_mixer_control *mc =
 		(struct soc_mixer_control *)kcontrol->private_value;
-	int max = mc->max - mc->min;
 	unsigned int mask = soc_mixer_mask(mc);
-	unsigned int reg_val;
-	int val;
 
-	reg_val = snd_soc_component_read(component, mc->reg);
-	val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, max);
-
-	ucontrol->value.integer.value[0] = val;
-
-	if (snd_soc_volsw_is_stereo(mc)) {
-		if (mc->reg == mc->rreg) {
-			val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->rshift, max);
-		} else {
-			reg_val = snd_soc_component_read(component, mc->rreg);
-			val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, max);
-		}
-
-		ucontrol->value.integer.value[1] = val;
-	}
-
-	return 0;
+	return soc_get_volsw(kcontrol, ucontrol, mc, mask, mc->max - mc->min);
 }
 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
 
@@ -361,28 +368,13 @@  EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
 int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
 			 struct snd_ctl_elem_value *ucontrol)
 {
-	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
 	struct soc_mixer_control *mc =
 		(struct soc_mixer_control *)kcontrol->private_value;
 	unsigned int reg = mc->reg;
 	unsigned int reg2 = mc->rreg;
 	unsigned int mask = soc_mixer_sx_mask(mc);
-	unsigned int reg_val;
-	int val;
-
-	reg_val = snd_soc_component_read(component, reg);
-	val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, mc->max);
-
-	ucontrol->value.integer.value[0] = val;
-
-	if (snd_soc_volsw_is_stereo(mc)) {
-		reg_val = snd_soc_component_read(component, reg2);
-		val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->rshift, mc->max);
 
-		ucontrol->value.integer.value[1] = val;
-	}
-
-	return 0;
+	return soc_get_volsw(kcontrol, ucontrol, mc, mask, mc->max);
 }
 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx);