Tidy up ASoC control get and put handlers
Subsystems (3)
cover Tidy up ASoC control get and put handlers
There is a lot of duplicated and occasionally slightly incorrect code around the ASoC control get and put handlers. This series add some kunit tests and then refactors the code to get all the tests passing and reduce some of the duplication. The focus here is on the volsw handlers, future work could still be done on some of the others but these were the ones that most required attention.
Hopefully the only slightly controversal change is the very last patch which changes platform_max to be applied after the control type is determined, more discussion in the commit message for that one.
Thanks,
Charles
Charles Keepax (15):
ASoC: ops-test: Add some basic kunit tests for soc-ops
ASoC: ops: Minor formatting fixups
ASoC: ops: Update comments for xr_sx control helpers
ASoC: ops: Update mask generation to use GENMASK
ASoC: ops: Factor out helper to check valid control values
ASoC: ops: Replace snd_soc_read_signed() with new helper
ASoC: ops: Add control to register value helper
ASoC: ops: Remove snd_soc_info_volsw_range()
ASoC: ops: Remove snd_soc_get_volsw_range()
ASoC: ops: Remove snd_soc_put_volsw_range()
ASoC: ops: Factor out common code from info callbacks
ASoC: ops: Factor out common code from put callbacks
ASoC: ops: Factor out common code from get callbacks
ASoC: ops: Remove some unnecessary local variables
ASoC: ops: Apply platform_max after deciding control type
include/sound/soc.h | 24 +- sound/pci/hda/tas2781_hda_i2c.c | 2 +- sound/pci/hda/tas2781_hda_spi.c | 2 +- sound/soc/Kconfig | 7 + sound/soc/Makefile | 4 + sound/soc/codecs/wm5110.c | 4 +- sound/soc/soc-ops-test.c | 541 ++++++++++++++++++++++++ sound/soc/soc-ops.c | 712 +++++++++++--------------------- sound/soc/soc-topology.c | 4 +- 9 files changed, 807 insertions(+), 493 deletions(-) create mode 100644 sound/soc/soc-ops-test.c
Signature · 1 line
2.39.5
PATCH 1/15 ASoC: ops-test: Add some basic kunit tests for soc-ops
Add some basic kunit tests for some of the ASoC control put and get helpers. This will assist in doing some refactoring. Note that presently some tests fail, but the rest of the series will fix these up.
--- sound/soc/Kconfig | 7 + sound/soc/Makefile | 4 + sound/soc/soc-ops-test.c | 541 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 552 insertions(+) create mode 100644 sound/soc/soc-ops-test.c
sound/soc/Kconfig +7 -0
@@ -81,6 +81,13 @@ config SND_SOC_UTILS_KUNIT_TEST help If you want to perform tests on ALSA SoC utils library say Y here. +config SND_SOC_OPS_KUNIT_TEST + tristate "KUnit tests for SoC ops" + depends on KUNIT + default KUNIT_ALL_TESTS + help + If you want to perform tests on ALSA SoC ops library say Y here. + config SND_SOC_ACPI tristate
sound/soc/Makefile +4 -0
@@ -21,6 +21,10 @@ ifneq ($(CONFIG_SND_SOC_UTILS_KUNIT_TEST),) obj-$(CONFIG_SND_SOC_UTILS_KUNIT_TEST) += soc-utils-test.o endif +ifneq ($(CONFIG_SND_SOC_OPS_KUNIT_TEST),) +obj-$(CONFIG_SND_SOC_OPS_KUNIT_TEST) += soc-ops-test.o +endif + ifneq ($(CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM),) snd-soc-core-y += soc-generic-dmaengine-pcm.o endif
sound/soc/soc-ops-test.c new file +541 -0
541 lines not on this page · raw message
Signature · 1 line
2.39.5
PATCH 2/15 ASoC: ops: Minor formatting fixups
In reply to Charles KeepaxNo functional changes just tidying up some tabbing etc.
--- sound/soc/soc-ops.c | 106 ++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 52 deletions(-)
sound/soc/soc-ops.c +54 -52
@@ -37,7 +37,7 @@* Returns 0 for success. */ int snd_soc_info_enum_double (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_info *uinfo) +struct snd_ctl_elem_info *uinfo) {struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
@@ -56,7 +56,7 @@ EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);* Returns 0 for success. */ int snd_soc_get_enum_double (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_value *ucontrol) +struct snd_ctl_elem_value *ucontrol) {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
@@ -87,7 +87,7 @@ EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);* Returns 0 for success. */ int snd_soc_put_enum_double (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_value *ucontrol) +struct snd_ctl_elem_value *ucontrol) {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
@@ -124,8 +124,9 @@ EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);* the given registervalue into a signed integer if sign_bit is non-zero. */ static void snd_soc_read_signed (struct snd_soc_component *component, -unsigned int reg,unsigned int mask,unsigned int shift, -unsigned int sign_bit,int *signed_val) +unsigned int reg,unsigned int mask, +unsigned int shift,unsigned int sign_bit, +int *signed_val) {int ret;unsigned int val;
@@ -168,7 +169,7 @@ static void snd_soc_read_signed(struct snd_soc_component *component,* Returns 0 for success. */ int snd_soc_info_volsw (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_info *uinfo) +struct snd_ctl_elem_info *uinfo) {struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
@@ -247,7 +248,7 @@ EXPORT_SYMBOL_GPL(snd_soc_info_volsw_sx);* Returns 0 for success. */ int snd_soc_get_volsw (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_value *ucontrol) +struct snd_ctl_elem_value *ucontrol) {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol); struct soc_mixer_control *mc =
@@ -300,7 +301,7 @@ EXPORT_SYMBOL_GPL(snd_soc_get_volsw);* Returns 0 for success. */ int snd_soc_put_volsw (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_value *ucontrol) +struct snd_ctl_elem_value *ucontrol) {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol); struct soc_mixer_control *mc =
@@ -362,9 +363,8 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, err =snd_soc_component_update_bits (component, reg2, val_mask, val2);/* Don't discard any error code or drop change flag */ -if (ret ==0 || err <0 ) { +if (ret ==0 || err <0 ) ret = err; - } }return ret;
@@ -382,11 +382,11 @@ EXPORT_SYMBOL_GPL(snd_soc_put_volsw);* Returns 0 for success. */ int snd_soc_get_volsw_sx (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_value *ucontrol) +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; + (struct soc_mixer_control *)kcontrol->private_value;unsigned int reg = mc->reg;unsigned int reg2 = mc->rreg;unsigned int shift = mc->shift;
@@ -423,18 +423,17 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);struct soc_mixer_control *mc = - (struct soc_mixer_control *)kcontrol->private_value; - + (struct soc_mixer_control *)kcontrol->private_value;unsigned int reg = mc->reg;unsigned int reg2 = mc->rreg;unsigned int shift = mc->shift;unsigned int rshift = mc->rshift; +unsigned int val, val_mask;int max = mc->max;int min = mc->min;unsigned int mask = (1U << (fls (min + max) -1 )) -1 ;int err =0 ;int ret; -unsigned int val, val_mask;if (ucontrol->value.integer.value[0 ] <0 )return -EINVAL ;
@@ -465,13 +464,13 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, val2 = val2 << rshift; err =snd_soc_component_update_bits (component, reg2, val_mask, - val2); + val2);/* Don't discard any error code or drop change flag */ -if (ret ==0 || err <0 ) { +if (ret ==0 || err <0 ) ret = err; - } } +return ret; }EXPORT_SYMBOL_GPL (snd_soc_put_volsw_sx);
@@ -487,7 +486,7 @@ EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);* returns 0 for success. */ int snd_soc_info_volsw_range (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_info *uinfo) +struct snd_ctl_elem_info *uinfo) {struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
@@ -516,7 +515,7 @@ EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range);* Returns 0 for success. */ int snd_soc_put_volsw_range (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_value *ucontrol) +struct snd_ctl_elem_value *ucontrol) {struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
@@ -568,11 +567,10 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, val = val << shift; err =snd_soc_component_update_bits (component, rreg, val_mask, - val); + val);/* Don't discard any error code or drop change flag */ -if (ret ==0 || err <0 ) { +if (ret ==0 || err <0 ) ret = err; - } }return ret;
@@ -589,7 +587,7 @@ EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range);* Returns 0 for success. */ int snd_soc_get_volsw_range (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_value *ucontrol) +struct snd_ctl_elem_value *ucontrol) {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol); struct soc_mixer_control *mc =
@@ -663,8 +661,7 @@ static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl)* * Return 0 for success, else error. */ -int snd_soc_limit_volume (struct snd_soc_card *card, -const char *name,int max) +int snd_soc_limit_volume (struct snd_soc_card *card,const char *name,int max) {struct snd_kcontrol *kctl;int ret = -EINVAL ;
@@ -675,12 +672,15 @@ int snd_soc_limit_volume(struct snd_soc_card *card, kctl =snd_soc_card_get_kcontrol (card, name);if (kctl) { -struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value; +struct soc_mixer_control *mc = + (struct soc_mixer_control *)kctl->private_value; +if (max <= mc->max - mc->min) { mc->platform_max = max; ret =snd_soc_clip_to_platform_max (kctl); } } +return ret; }EXPORT_SYMBOL_GPL (snd_soc_limit_volume);
@@ -740,8 +740,8 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);struct soc_bytes *params = (void *)kcontrol->private_value; -int ret, len;unsigned int val, mask; +int ret, len;if (!component->regmap || !params->num_regs)return -EINVAL ;
@@ -772,15 +772,13 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,break ;case 2 : mask = ~params->mask; - ret =regmap_parse_val (component->regmap, - &mask, &mask); + ret =regmap_parse_val (component->regmap, &mask, &mask);if (ret !=0 )return ret; ((u16 *)data)[0 ] &= mask; - ret =regmap_parse_val (component->regmap, - &val, &val); + ret =regmap_parse_val (component->regmap, &val, &val);if (ret !=0 )return ret;
@@ -788,15 +786,13 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,break ;case 4 : mask = ~params->mask; - ret =regmap_parse_val (component->regmap, - &mask, &mask); + ret =regmap_parse_val (component->regmap, &mask, &mask);if (ret !=0 )return ret; ((u32 *)data)[0 ] &= mask; - ret =regmap_parse_val (component->regmap, - &val, &val); + ret =regmap_parse_val (component->regmap, &val, &val);if (ret !=0 )return ret;
@@ -812,7 +808,7 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,EXPORT_SYMBOL_GPL (snd_soc_bytes_put);int snd_soc_bytes_info_ext (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_info *ucontrol) +struct snd_ctl_elem_info *ucontrol) {struct soc_bytes_ext *params = (void *)kcontrol->private_value;
@@ -824,7 +820,7 @@ int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol,EXPORT_SYMBOL_GPL (snd_soc_bytes_info_ext);int snd_soc_bytes_tlv_callback (struct snd_kcontrol *kcontrol,int op_flag, -unsigned int size,unsigned int __user *tlv) +unsigned int size,unsigned int __user *tlv) {struct soc_bytes_ext *params = (void *)kcontrol->private_value;unsigned int count = size < params->max ? size : params->max;
@@ -840,6 +836,7 @@ int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag, ret = params->put (kcontrol, tlv, count);break ; } +return ret; }EXPORT_SYMBOL_GPL (snd_soc_bytes_tlv_callback);
@@ -856,10 +853,11 @@ EXPORT_SYMBOL_GPL(snd_soc_bytes_tlv_callback);* Returns 0 for success. */ int snd_soc_info_xr_sx (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_info *uinfo) +struct snd_ctl_elem_info *uinfo) {struct soc_mreg_control *mc = (struct soc_mreg_control *)kcontrol->private_value; + uinfo->type =SNDRV_CTL_ELEM_TYPE_INTEGER ; uinfo->count =1 ; uinfo->value.integer.min = mc->min;
@@ -883,7 +881,7 @@ EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx);* Returns 0 for success. */ int snd_soc_get_xr_sx (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_value *ucontrol) +struct snd_ctl_elem_value *ucontrol) {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol); struct soc_mreg_control *mc =
@@ -891,17 +889,18 @@ int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,unsigned int regbase = mc->regbase;unsigned int regcount = mc->regcount;unsigned int regwshift = component->val_bytes *BITS_PER_BYTE ; -unsigned int regwmask = (1UL <<regwshift)-1 ; +unsigned int regwmask = (1UL << regwshift) -1 ;unsigned int invert = mc->invert; -unsigned long mask = (1UL <<mc->nbits)-1 ; +unsigned long mask = (1UL << mc->nbits) -1 ;long min = mc->min;long max = mc->max;long val =0 ;unsigned int i;for (i =0 ; i < regcount; i++) { -unsigned int regval =snd_soc_component_read (component, regbase+i); - val |= (regval & regwmask) << (regwshift*(regcount-i-1 )); +unsigned int regval =snd_soc_component_read (component, regbase + i); + + val |= (regval & regwmask) << (regwshift * (regcount - i -1 )); } val &= mask;if (min <0 && val > max)
@@ -928,7 +927,7 @@ EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx);* Returns 0 for success. */ int snd_soc_put_xr_sx (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_value *ucontrol) +struct snd_ctl_elem_value *ucontrol) {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol); struct soc_mreg_control *mc =
@@ -936,9 +935,9 @@ int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,unsigned int regbase = mc->regbase;unsigned int regcount = mc->regcount;unsigned int regwshift = component->val_bytes *BITS_PER_BYTE ; -unsigned int regwmask = (1UL <<regwshift)-1 ; +unsigned int regwmask = (1UL << regwshift) -1 ;unsigned int invert = mc->invert; -unsigned long mask = (1UL <<mc->nbits)-1 ; +unsigned long mask = (1UL << mc->nbits) -1 ;long max = mc->max;long val = ucontrol->value.integer.value[0 ];int ret =0 ;
@@ -950,10 +949,13 @@ int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol, val = max - val; val &= mask;for (i =0 ; i < regcount; i++) { -unsigned int regval = (val >> (regwshift*(regcount-i-1 ))) & regwmask; -unsigned int regmask = (mask >> (regwshift*(regcount-i-1 ))) & regwmask; -int err =snd_soc_component_update_bits (component, regbase+i, +unsigned int regval = (val >> (regwshift * (regcount - i -1 ))) & + regwmask; +unsigned int regmask = (mask >> (regwshift * (regcount - i -1 ))) & + regwmask; +int err =snd_soc_component_update_bits (component, regbase + i, regmask, regval); +if (err <0 )return err;if (err >0 )
@@ -974,7 +976,7 @@ EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx);* Returns 0 for success. */ int snd_soc_get_strobe (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_value *ucontrol) +struct snd_ctl_elem_value *ucontrol) {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol); struct soc_mixer_control *mc =
@@ -1007,7 +1009,7 @@ EXPORT_SYMBOL_GPL(snd_soc_get_strobe);* Returns 1 for success. */ int snd_soc_put_strobe (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_value *ucontrol) +struct snd_ctl_elem_value *ucontrol) {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol); struct soc_mixer_control *mc =
Signature · 1 line
2.39.5
PATCH 3/15 ASoC: ops: Update comments for xr_sx control helpers
In reply to Charles KeepaxUpdate the comments for the xr_sx control helper functions to better clarify the difference between these and the normal sx helpers.
--- sound/soc/soc-ops.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)
sound/soc/soc-ops.c +16 -13
@@ -846,9 +846,10 @@ EXPORT_SYMBOL_GPL(snd_soc_bytes_tlv_callback);* @kcontrol: mreg control * @uinfo: control element information * -* Callback to provide information of a control that can -* span multiple codec registers which together -* forms a single signed value in a MSB/LSB manner. +* Callback to provide information of a control that can span multiple +* codec registers which together forms a single signed value. Note +* that unlike the non-xr variant of sx controls these may or may not +* include the sign bit, depending on nbits, and there is no shift. * * Returns 0 for success. */
@@ -872,11 +873,12 @@ EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx);* @kcontrol: mreg control * @ucontrol: control element information * -* Callback to get the value of a control that can span -* multiple codec registers which together forms a single -* signed value in a MSB/LSB manner. The control supports -* specifying total no of bits used to allow for bitfields -* across the multiple codec registers. +* Callback to get the value of a control that can span multiple codec +* registers which together forms a single signed value. The control +* supports specifying total no of bits used to allow for bitfields +* across the multiple codec registers. Note that unlike the non-xr +* variant of sx controls these may or may not include the sign bit, +* depending on nbits, and there is no shift. * * Returns 0 for success. */
@@ -918,11 +920,12 @@ EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx);* @kcontrol: mreg control * @ucontrol: control element information * -* Callback to set the value of a control that can span -* multiple codec registers which together forms a single -* signed value in a MSB/LSB manner. The control supports -* specifying total no of bits used to allow for bitfields -* across the multiple codec registers. +* Callback to set the value of a control that can span multiple codec +* registers which together forms a single signed value. The control +* supports specifying total no of bits used to allow for bitfields +* across the multiple codec registers. Note that unlike the non-xr +* variant of sx controls these may or may not include the sign bit, +* depending on nbits, and there is no shift. * * Returns 0 for success. */
Signature · 1 line
2.39.5
PATCH 4/15 ASoC: ops: Update mask generation to use GENMASK
In reply to Charles KeepaxUse GENMASK to make the masks for the various control helper functions. Also factor out a shared helper function for the volsw and volsw_range controls since the same code is appropriate for each. Note this does add support for sign_bit into the volsw_range callbacks.
--- sound/soc/soc-ops.c | 46 +++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-)
sound/soc/soc-ops.c +26 -20
@@ -158,6 +158,20 @@ static void snd_soc_read_signed(struct snd_soc_component *component, *signed_val = ret; } +static int soc_mixer_mask (struct soc_mixer_control *mc) +{ +if (mc->sign_bit) +return GENMASK (mc->sign_bit,0 ); +else +return GENMASK (fls (mc->max) -1 ,0 ); +} + +static int soc_mixer_sx_mask (struct soc_mixer_control *mc) +{ +// min + max will take us 1-bit over the size of the mask +return GENMASK (fls (mc->min + mc->max) -2 ,0 ); +} +/** * snd_soc_info_volsw - single mixer info callback * @kcontrol: mixer control
@@ -260,13 +274,10 @@ int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,int max = mc->max;int min = mc->min;int sign_bit = mc->sign_bit; -unsigned int mask = (1ULL <<fls (max)) -1 ; +unsigned int mask =soc_mixer_mask (mc);unsigned int invert = mc->invert;int val; -if (sign_bit) - mask =BIT (sign_bit +1 ) -1 ; -snd_soc_read_signed (component, reg, mask, shift, sign_bit, &val); ucontrol->value.integer.value[0 ] = val - min;
@@ -312,17 +323,13 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,unsigned int rshift = mc->rshift;int max = mc->max;int min = mc->min; -unsigned int sign_bit = mc->sign_bit; -unsigned int mask = (1 <<fls (max)) -1 ; +unsigned int mask =soc_mixer_mask (mc);unsigned int invert = mc->invert;int err, ret;bool type_2r = false;unsigned int val2 =0 ;unsigned int val, val_mask; -if (sign_bit) - mask =BIT (sign_bit +1 ) -1 ; -if (ucontrol->value.integer.value[0 ] <0 )return -EINVAL ; val = ucontrol->value.integer.value[0 ];
@@ -391,9 +398,8 @@ int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,unsigned int reg2 = mc->rreg;unsigned int shift = mc->shift;unsigned int rshift = mc->rshift; -int max = mc->max;int min = mc->min; -unsigned int mask = (1U << (fls (min + max) -1 )) -1 ; +unsigned int mask =soc_mixer_sx_mask (mc);unsigned int val; val =snd_soc_component_read (component, reg);
@@ -431,7 +437,7 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,unsigned int val, val_mask;int max = mc->max;int min = mc->min; -unsigned int mask = (1U << (fls (min + max) -1 )) -1 ; +unsigned int mask =soc_mixer_sx_mask (mc);int err =0 ;int ret;
@@ -525,7 +531,7 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,unsigned int shift = mc->shift;int min = mc->min;int max = mc->max; -unsigned int mask = (1 <<fls (max)) -1 ; +unsigned int mask =soc_mixer_mask (mc);unsigned int invert = mc->invert;unsigned int val, val_mask;int err, ret, tmp;
@@ -597,7 +603,7 @@ int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,unsigned int shift = mc->shift;int min = mc->min;int max = mc->max; -unsigned int mask = (1 <<fls (max)) -1 ; +unsigned int mask =soc_mixer_mask (mc);unsigned int invert = mc->invert;unsigned int val;
@@ -891,9 +897,9 @@ int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,unsigned int regbase = mc->regbase;unsigned int regcount = mc->regcount;unsigned int regwshift = component->val_bytes *BITS_PER_BYTE ; -unsigned int regwmask = (1UL << regwshift) -1 ; +unsigned int regwmask =GENMASK (regwshift -1 ,0 ); +unsigned long mask =GENMASK (mc->nbits -1 ,0 );unsigned int invert = mc->invert; -unsigned long mask = (1UL << mc->nbits) -1 ;long min = mc->min;long max = mc->max;long val =0 ;
@@ -938,9 +944,9 @@ int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,unsigned int regbase = mc->regbase;unsigned int regcount = mc->regcount;unsigned int regwshift = component->val_bytes *BITS_PER_BYTE ; -unsigned int regwmask = (1UL << regwshift) -1 ; +unsigned int regwmask =GENMASK (regwshift -1 ,0 ); +unsigned long mask =GENMASK (mc->nbits -1 ,0 );unsigned int invert = mc->invert; -unsigned long mask = (1UL << mc->nbits) -1 ;long max = mc->max;long val = ucontrol->value.integer.value[0 ];int ret =0 ;
@@ -986,7 +992,7 @@ int snd_soc_get_strobe(struct snd_kcontrol *kcontrol, (struct soc_mixer_control *)kcontrol->private_value;unsigned int reg = mc->reg;unsigned int shift = mc->shift; -unsigned int mask =1 << shift; +unsigned int mask =BIT (shift);unsigned int invert = mc->invert !=0 ;unsigned int val;
@@ -1019,7 +1025,7 @@ int snd_soc_put_strobe(struct snd_kcontrol *kcontrol, (struct soc_mixer_control *)kcontrol->private_value;unsigned int reg = mc->reg;unsigned int shift = mc->shift; -unsigned int mask =1 << shift; +unsigned int mask =BIT (shift);unsigned int invert = mc->invert !=0 ;unsigned int strobe = ucontrol->value.enumerated.item[0 ] !=0 ;unsigned int val1 = (strobe ^ invert) ? mask :0 ;
Signature · 1 line
2.39.5
PATCH 5/15 ASoC: ops: Factor out helper to check valid control values
In reply to Charles KeepaxMost of the put handlers have identical code to verify the value passed in from user-space. Factor this out into a single helper function.
--- sound/soc/soc-ops.c | 82 ++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 39 deletions(-)
sound/soc/soc-ops.c +43 -39
@@ -158,6 +158,20 @@ static void snd_soc_read_signed(struct snd_soc_component *component, *signed_val = ret; } +static int soc_mixer_valid_ctl (struct soc_mixer_control *mc,long val,int max) +{ +if (val <0 ) +return -EINVAL ; + +if (mc->platform_max && val > mc->platform_max) +return -EINVAL ; + +if (val > max) +return -EINVAL ; + +return 0 ; +} +static int soc_mixer_mask (struct soc_mixer_control *mc) {if (mc->sign_bit)
@@ -330,26 +344,24 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,unsigned int val2 =0 ;unsigned int val, val_mask; -if (ucontrol->value.integer.value[0 ] <0 ) -return -EINVAL ; + ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[0 ], + mc->max - mc->min); +if (ret) +return ret; + val = ucontrol->value.integer.value[0 ]; -if (mc->platform_max && val > mc->platform_max) -return -EINVAL ; -if (val > max - min) -return -EINVAL ; val = (val + min) & mask;if (invert) val = max - val; val_mask = mask << shift; val = val << shift;if (snd_soc_volsw_is_stereo (mc)) { -if (ucontrol->value.integer.value[1 ] <0 ) -return -EINVAL ; + ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[1 ], + mc->max - mc->min); +if (ret) +return ret; + val2 = ucontrol->value.integer.value[1 ]; -if (mc->platform_max && val2 > mc->platform_max) -return -EINVAL ; -if (val2 > max - min) -return -EINVAL ; val2 = (val2 + min) & mask;if (invert) val2 = max - val2;
@@ -435,19 +447,16 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,unsigned int shift = mc->shift;unsigned int rshift = mc->rshift;unsigned int val, val_mask; -int max = mc->max;int min = mc->min;unsigned int mask =soc_mixer_sx_mask (mc);int err =0 ;int ret; -if (ucontrol->value.integer.value[0 ] <0 ) -return -EINVAL ; + ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[0 ], mc->max); +if (ret) +return ret; + val = ucontrol->value.integer.value[0 ]; -if (mc->platform_max && val > mc->platform_max) -return -EINVAL ; -if (val > max) -return -EINVAL ; val_mask = mask << shift; val = (val + min) & mask; val = val << shift;
@@ -458,13 +467,14 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, ret = err;if (snd_soc_volsw_is_stereo (mc)) { -unsigned int val2 = ucontrol->value.integer.value[1 ]; +unsigned int val2; -if (mc->platform_max && val2 > mc->platform_max) -return -EINVAL ; -if (val2 > max) -return -EINVAL ; + ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[1 ], + mc->max); +if (ret) +return ret; + val2 = ucontrol->value.integer.value[1 ]; val_mask = mask << rshift; val2 = (val2 + min) & mask; val2 = val2 << rshift;
@@ -534,15 +544,12 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,unsigned int mask =soc_mixer_mask (mc);unsigned int invert = mc->invert;unsigned int val, val_mask; -int err, ret, tmp; +int err, ret; - tmp = ucontrol->value.integer.value[0 ]; -if (tmp <0 ) -return -EINVAL ; -if (mc->platform_max && tmp > mc->platform_max) -return -EINVAL ; -if (tmp > mc->max - mc->min) -return -EINVAL ; + ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[0 ], + mc->max - mc->min); +if (ret) +return ret;if (invert) val = (max - ucontrol->value.integer.value[0 ]) & mask;
@@ -557,13 +564,10 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, ret = err;if (snd_soc_volsw_is_stereo (mc)) { - tmp = ucontrol->value.integer.value[1 ]; -if (tmp <0 ) -return -EINVAL ; -if (mc->platform_max && tmp > mc->platform_max) -return -EINVAL ; -if (tmp > mc->max - mc->min) -return -EINVAL ; + ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[1 ], + mc->max - mc->min); +if (ret) +return ret;if (invert) val = (max - ucontrol->value.integer.value[1 ]) & mask;
Signature · 1 line
2.39.5
PATCH 6/15 ASoC: ops: Replace snd_soc_read_signed() with new helper
In reply to Charles KeepaxThe current snd_soc_read_signed() helper is only used from snd_soc_get_volsw() and can be implemented more simply with sign_extend. Remove snd_soc_read_signed() and add a new soc_mixer_reg_to_ctl() helper. This new helper does not include the reading of the register, but does include min and max handling. This allows the helper to replace more of the duplicated code and makes it easier to process the differences between single, double register and double shift style controls.
It is worth noting this adds support for sign_bit into the _range and sx callbacks and the invert option to sx callbacks.
--- sound/soc/soc-ops.c | 134 ++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 93 deletions(-)
sound/soc/soc-ops.c +41 -93
@@ -110,52 +110,20 @@ int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, }EXPORT_SYMBOL_GPL (snd_soc_put_enum_double); -/** -* snd_soc_read_signed - Read a codec register and interpret as signed value -* @component: component -* @reg: Register to read -* @mask: Mask to use after shifting the register value -* @shift: Right shift of register value -* @sign_bit: Bit that describes if a number is negative or not. -* @signed_val: Pointer to where the read value should be stored -* -* This functions reads a codec register. The register value is shifted right -* by 'shift' bits and masked with the given 'mask'. Afterwards it translates -* the given registervalue into a signed integer if sign_bit is non-zero. -*/ -static void snd_soc_read_signed (struct snd_soc_component *component, -unsigned int reg,unsigned int mask, -unsigned int shift,unsigned int sign_bit, -int *signed_val) +static int soc_mixer_reg_to_ctl (struct soc_mixer_control *mc,unsigned int reg_val, +unsigned int mask,unsigned int shift,int max) { -int ret; -unsigned int val; - - val =snd_soc_component_read (component, reg); - val = (val >> shift) & mask; +int val = (reg_val >> shift) & mask; -if (!sign_bit) { - *signed_val = val; -return ; - } - -/* non-negative number */ -if (!(val &BIT (sign_bit))) { - *signed_val = val; -return ; - } +if (mc->sign_bit) + val =sign_extend32 (val, mc->sign_bit); - ret = val; + val -= mc->min; -/* -* The register most probably does not contain a full-sized int. -* Instead we have an arbitrary number of bits in a signed -* representation which has to be translated into a full-sized int. -* This is done by filling up all bits above the sign-bit. -*/ - ret |= ~((int )(BIT (sign_bit) -1 )); +if (mc->invert) + val = max - val; - *signed_val = ret; +return val & mask; }static int soc_mixer_valid_ctl (struct soc_mixer_control *mc,long val,int max)
@@ -281,34 +249,25 @@ int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,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 shift = mc->shift; -unsigned int rshift = mc->rshift; -int max = mc->max; -int min = mc->min; -int sign_bit = mc->sign_bit; +int max = mc->max - mc->min;unsigned int mask =soc_mixer_mask (mc); -unsigned int invert = mc->invert; +unsigned int reg_val;int val; -snd_soc_read_signed (component, reg, mask, shift, sign_bit, &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 - min; -if (invert) - ucontrol->value.integer.value[0 ] = - max - ucontrol->value.integer.value[0 ]; + ucontrol->value.integer.value[0 ] = val;if (snd_soc_volsw_is_stereo (mc)) { -if (reg == reg2) -snd_soc_read_signed (component, reg, mask, rshift, sign_bit, &val); -else -snd_soc_read_signed (component, reg2, mask, shift, sign_bit, &val); +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 - min; -if (invert) - ucontrol->value.integer.value[1 ] = - max - ucontrol->value.integer.value[1 ]; + ucontrol->value.integer.value[1 ] = val; }return 0 ;
@@ -408,18 +367,19 @@ int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol, (struct soc_mixer_control *)kcontrol->private_value;unsigned int reg = mc->reg;unsigned int reg2 = mc->rreg; -unsigned int shift = mc->shift; -unsigned int rshift = mc->rshift; -int min = mc->min;unsigned int mask =soc_mixer_sx_mask (mc); -unsigned int val; +unsigned int reg_val; +int val; - val =snd_soc_component_read (component, reg); - ucontrol->value.integer.value[0 ] = ((val >> shift) - min) & mask; + 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)) { - val =snd_soc_component_read (component, reg2); - val = ((val >> rshift) - min) & mask; + 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; }
@@ -602,33 +562,21 @@ int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,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 rreg = mc->rreg; -unsigned int shift = mc->shift; -int min = mc->min; -int max = mc->max; +int max = mc->max - mc->min;unsigned int mask =soc_mixer_mask (mc); -unsigned int invert = mc->invert; -unsigned int val; +unsigned int reg_val; +int val; - val =snd_soc_component_read (component, reg); - ucontrol->value.integer.value[0 ] = (val >> shift) & mask; -if (invert) - ucontrol->value.integer.value[0 ] = - max - ucontrol->value.integer.value[0 ]; -else - ucontrol->value.integer.value[0 ] = - ucontrol->value.integer.value[0 ] - min; + 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)) { - val =snd_soc_component_read (component, rreg); - ucontrol->value.integer.value[1 ] = (val >> shift) & mask; -if (invert) - ucontrol->value.integer.value[1 ] = - max - ucontrol->value.integer.value[1 ]; -else - ucontrol->value.integer.value[1 ] = - ucontrol->value.integer.value[1 ] - min; + 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 ;
Signature · 1 line
2.39.5
PATCH 7/15 ASoC: ops: Add control to register value helper
In reply to Charles KeepaxAdd a helper function to convert from control values to register values that can replace a lot of the duplicated code in the various put handlers.
This also fixes a small issue in snd_soc_put_volsw where the value is converted to a control value before doing the invert, but the invert is done against the register max which will result in incorrect values for inverted controls with a non-zero minimum.
--- sound/soc/soc-ops.c | 97 ++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 54 deletions(-)
sound/soc/soc-ops.c +43 -54
@@ -126,6 +126,20 @@ static int soc_mixer_reg_to_ctl(struct soc_mixer_control *mc, unsigned int reg_vreturn val & mask; } +static unsigned int soc_mixer_ctl_to_reg (struct soc_mixer_control *mc,int val, +unsigned int mask,unsigned int shift, +int max) +{ +unsigned int reg_val; + +if (mc->invert) + val = max - val; + + reg_val = val + mc->min; + +return (reg_val & mask) << shift; +} +static int soc_mixer_valid_ctl (struct soc_mixer_control *mc,long val,int max) {if (val <0 )
@@ -292,43 +306,35 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, (struct soc_mixer_control *)kcontrol->private_value;unsigned int reg = mc->reg;unsigned int reg2 = mc->rreg; -unsigned int shift = mc->shift; -unsigned int rshift = mc->rshift; -int max = mc->max; -int min = mc->min; +int max = mc->max - mc->min;unsigned int mask =soc_mixer_mask (mc); -unsigned int invert = mc->invert;int err, ret;bool type_2r = false;unsigned int val2 =0 ;unsigned int val, val_mask; - ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[0 ], - mc->max - mc->min); + ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[0 ], max);if (ret)return ret; - val = ucontrol->value.integer.value[0 ]; - val = (val + min) & mask; -if (invert) - val = max - val; - val_mask = mask << shift; - val = val << shift; + val =soc_mixer_ctl_to_reg (mc, ucontrol->value.integer.value[0 ], + mask, mc->shift, max); + val_mask = mask << mc->shift; +if (snd_soc_volsw_is_stereo (mc)) { - ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[1 ], - mc->max - mc->min); + ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[1 ], max);if (ret)return ret; - val2 = ucontrol->value.integer.value[1 ]; - val2 = (val2 + min) & mask; -if (invert) - val2 = max - val2;if (reg == reg2) { - val_mask |= mask << rshift; - val |= val2 << rshift; + val |=soc_mixer_ctl_to_reg (mc, + ucontrol->value.integer.value[1 ], + mask, mc->rshift, max); + val_mask |= mask << mc->rshift; }else { - val2 = val2 << shift; + val2 =soc_mixer_ctl_to_reg (mc, + ucontrol->value.integer.value[1 ], + mask, mc->shift, max); type_2r = true; } }
@@ -404,10 +410,7 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, (struct soc_mixer_control *)kcontrol->private_value;unsigned int reg = mc->reg;unsigned int reg2 = mc->rreg; -unsigned int shift = mc->shift; -unsigned int rshift = mc->rshift;unsigned int val, val_mask; -int min = mc->min;unsigned int mask =soc_mixer_sx_mask (mc);int err =0 ;int ret;
@@ -416,10 +419,9 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,if (ret)return ret; - val = ucontrol->value.integer.value[0 ]; - val_mask = mask << shift; - val = (val + min) & mask; - val = val << shift; + val =soc_mixer_ctl_to_reg (mc, ucontrol->value.integer.value[0 ], + mask, mc->shift, mc->max); + val_mask = mask << mc->shift; err =snd_soc_component_update_bits (component, reg, val_mask, val);if (err <0 )
@@ -427,20 +429,17 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, ret = err;if (snd_soc_volsw_is_stereo (mc)) { -unsigned int val2; - ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[1 ], mc->max);if (ret)return ret; - val2 = ucontrol->value.integer.value[1 ]; - val_mask = mask << rshift; - val2 = (val2 + min) & mask; - val2 = val2 << rshift; + val =soc_mixer_ctl_to_reg (mc, ucontrol->value.integer.value[1 ], + mask, mc->rshift, mc->max); + val_mask = mask << mc->rshift; err =snd_soc_component_update_bits (component, reg2, val_mask, - val2); + val);/* Don't discard any error code or drop change flag */ if (ret ==0 || err <0 )
@@ -498,12 +497,10 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);unsigned int reg = mc->reg;unsigned int rreg = mc->rreg; -unsigned int shift = mc->shift; -int min = mc->min; -int max = mc->max; +int max = mc->max - mc->min;unsigned int mask =soc_mixer_mask (mc); -unsigned int invert = mc->invert; -unsigned int val, val_mask; +unsigned int val_mask = mask << mc->shift; +unsigned int val;int err, ret; ret = soc_mixer_valid_ctl(mc, ucontrol->value.integer.value[0],
@@ -511,12 +508,8 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,if (ret)return ret; -if (invert) - val = (max - ucontrol->value.integer.value[0 ]) & mask; -else - val = ((ucontrol->value.integer.value[0 ] + min) & mask); - val_mask = mask << shift; - val = val << shift; + val =soc_mixer_ctl_to_reg (mc, ucontrol->value.integer.value[0 ], + mask, mc->shift, max); err =snd_soc_component_update_bits (component, reg, val_mask, val);if (err <0 )
@@ -525,16 +518,12 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,if (snd_soc_volsw_is_stereo (mc)) { ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[1 ], - mc->max - mc->min); + max);if (ret)return ret; -if (invert) - val = (max - ucontrol->value.integer.value[1 ]) & mask; -else - val = ((ucontrol->value.integer.value[1 ] + min) & mask); - val_mask = mask << shift; - val = val << shift; + val =soc_mixer_ctl_to_reg (mc, ucontrol->value.integer.value[1 ], + mask, mc->shift, max); err =snd_soc_component_update_bits (component, rreg, val_mask, val);
Signature · 1 line
2.39.5
PATCH 8/15 ASoC: ops: Remove snd_soc_info_volsw_range()
In reply to Charles KeepaxThe only difference between snd_soc_info_volsw() and snd_soc_info_volsw_range() is that the later will not force a 2 value control to be of type integer if the name ends in "Volume".
The kernel currently contains no users of snd_soc_info_volsw_range() that would return a boolean control with this code, so the risk is quite low and it seems appropriate that it should contain volume control detection. So remove snd_soc_info_volsw_range() and point its users at snd_soc_info_volsw().
--- include/sound/soc.h | 12 +++++------ sound/pci/hda/tas2781_hda_i2c.c | 2 +- sound/pci/hda/tas2781_hda_spi.c | 2 +- sound/soc/soc-ops.c | 36 +++------------------------------ sound/soc/soc-topology.c | 2 +- 5 files changed, 11 insertions(+), 43 deletions(-)
include/sound/soc.h +5 -7
@@ -65,7 +65,7 @@ struct platform_device; .private_value = SOC_SINGLE_VALUE(reg, shift, 0, max, invert, 0) }#define SOC_SINGLE_RANGE (xname, xreg, xshift, xmin, xmax, xinvert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ - .info = snd_soc_info_volsw_range, .get = snd_soc_get_volsw_range, \ + .info = snd_soc_info_volsw, .get = snd_soc_get_volsw_range, \ .put = snd_soc_put_volsw_range, \ .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, 0) }#define SOC_SINGLE_TLV (xname, reg, shift, max, invert, tlv_array) \
@@ -90,7 +90,7 @@ struct platform_device; .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ SNDRV_CTL_ELEM_ACCESS_READWRITE,\ .tlv.p = (tlv_array), \ - .info = snd_soc_info_volsw_range, \ + .info = snd_soc_info_volsw, \ .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \ .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, 0) }#define SOC_DOUBLE (xname, reg, shift_left, shift_right, max, invert) \
@@ -116,7 +116,7 @@ struct platform_device;#define SOC_DOUBLE_R_RANGE (xname, reg_left, reg_right, xshift, xmin, \ xmax, xinvert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ - .info = snd_soc_info_volsw_range, \ + .info = snd_soc_info_volsw, \ .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \ .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, \ xshift, xmin, xmax, xinvert) }
@@ -164,7 +164,7 @@ struct platform_device; .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ SNDRV_CTL_ELEM_ACCESS_READWRITE,\ .tlv.p = (tlv_array), \ - .info = snd_soc_info_volsw_range, \ + .info = snd_soc_info_volsw, \ .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \ .private_value =SOC_DOUBLE_R_VALUE (reg_left, reg_right, \ xshift, xmin, xmax, xinvert) }
@@ -266,7 +266,7 @@ struct platform_device; .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ SNDRV_CTL_ELEM_ACCESS_READWRITE,\ .tlv.p = (tlv_array), \ - .info = snd_soc_info_volsw_range, \ + .info = snd_soc_info_volsw, \ .get = xhandler_get, .put = xhandler_put, \ .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, 0) } #define SOC_DOUBLE_EXT_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert,\
@@ -569,8 +569,6 @@ int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);int snd_soc_put_volsw_sx (struct snd_kcontrol *kcontrol,struct snd_ctl_elem_value *ucontrol); -int snd_soc_info_volsw_range (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_info *uinfo);int snd_soc_put_volsw_range (struct snd_kcontrol *kcontrol,struct snd_ctl_elem_value *ucontrol); int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
sound/pci/hda/tas2781_hda_i2c.c +1 -1
@@ -45,7 +45,7 @@ .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ SNDRV_CTL_ELEM_ACCESS_READWRITE,\ .tlv.p = (tlv_array), \ - .info = snd_soc_info_volsw_range, \ + .info = snd_soc_info_volsw, \ .get = xhandler_get, .put = xhandler_put, \ .private_value = (unsigned long )&(struct soc_mixer_control ) \ {.reg = xreg, .rreg = xreg, .shift = xshift, \
sound/pci/hda/tas2781_hda_spi.c +1 -1
@@ -52,7 +52,7 @@ .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ SNDRV_CTL_ELEM_ACCESS_READWRITE, \ .tlv.p = (tlv_array), \ - .info = snd_soc_info_volsw_range, \ + .info = snd_soc_info_volsw, \ .get = xhandler_get, .put = xhandler_put, \ .private_value = (unsigned long )&(struct soc_mixer_control ) { \ .reg = xreg, .rreg = xreg, \
sound/soc/soc-ops.c +3 -33
@@ -169,12 +169,12 @@ static int soc_mixer_sx_mask(struct soc_mixer_control *mc) }/** -* snd_soc_info_volsw - single mixer info callback +* snd_soc_info_volsw - single mixer info callback with range. * @kcontrol: mixer control * @uinfo: control element information * -* Callback to provide information about a single mixer control, or a double -* mixer control that spans 2 registers. +* Callback to provide information, with a range, about a single mixer control, +* or a double mixer control that spans 2 registers. * * Returns 0 for success. */
@@ -450,36 +450,6 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, }EXPORT_SYMBOL_GPL (snd_soc_put_volsw_sx); -/** -* snd_soc_info_volsw_range - single mixer info callback with range. -* @kcontrol: mixer control -* @uinfo: control element information -* -* Callback to provide information, within a range, about a single -* mixer control. -* -* returns 0 for success. -*/ -int snd_soc_info_volsw_range (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_info *uinfo) -{ -struct soc_mixer_control *mc = - (struct soc_mixer_control *)kcontrol->private_value; -int max; - - max = mc->max - mc->min; -if (mc->platform_max && mc->platform_max < max) - max = mc->platform_max; - - uinfo->type =SNDRV_CTL_ELEM_TYPE_INTEGER ; - uinfo->count =snd_soc_volsw_is_stereo (mc) ?2 :1 ; - uinfo->value.integer.min =0 ; - uinfo->value.integer.max = max; - -return 0 ; -} -EXPORT_SYMBOL_GPL (snd_soc_info_volsw_range); -/** * snd_soc_put_volsw_range - single mixer put value callback with range. * @kcontrol: mixer control
sound/soc/soc-topology.c +1 -1
@@ -132,7 +132,7 @@ static const struct snd_soc_tplg_kcontrol_ops io_ops[] = { {SND_SOC_TPLG_CTL_BYTES , snd_soc_bytes_get, snd_soc_bytes_put, snd_soc_bytes_info}, {SND_SOC_TPLG_CTL_RANGE, snd_soc_get_volsw_range, - snd_soc_put_volsw_range, snd_soc_info_volsw_range}, + snd_soc_put_volsw_range, snd_soc_info_volsw}, {SND_SOC_TPLG_CTL_VOLSW_XR_SX, snd_soc_get_xr_sx, snd_soc_put_xr_sx, snd_soc_info_xr_sx}, {SND_SOC_TPLG_CTL_STROBE, snd_soc_get_strobe,
Signature · 1 line
2.39.5
PATCH 9/15 ASoC: ops: Remove snd_soc_get_volsw_range()
In reply to Charles KeepaxWith the addition of the soc_mixer_reg_to_ctl() helper it is now very clear that the only difference between snd_soc_get_volsw() and snd_soc_get_volsw_range() is that the former supports double controls with both values in the same register. As such we can combine both functions.
--- include/sound/soc.h | 10 ++++------ sound/soc/codecs/wm5110.c | 2 +- sound/soc/soc-ops.c | 42 +++------------------------------------ sound/soc/soc-topology.c | 2 +- 4 files changed, 9 insertions(+), 47 deletions(-)
include/sound/soc.h +4 -6
@@ -65,7 +65,7 @@ struct platform_device; .private_value = SOC_SINGLE_VALUE(reg, shift, 0, max, invert, 0) }#define SOC_SINGLE_RANGE (xname, xreg, xshift, xmin, xmax, xinvert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ - .info = snd_soc_info_volsw, .get = snd_soc_get_volsw_range, \ + .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \ .put = snd_soc_put_volsw_range, \ .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, 0) }#define SOC_SINGLE_TLV (xname, reg, shift, max, invert, tlv_array) \
@@ -91,7 +91,7 @@ struct platform_device; SNDRV_CTL_ELEM_ACCESS_READWRITE,\ .tlv.p = (tlv_array), \ .info = snd_soc_info_volsw, \ - .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \ + .get = snd_soc_get_volsw, .put = snd_soc_put_volsw_range, \ .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, 0) }#define SOC_DOUBLE (xname, reg, shift_left, shift_right, max, invert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
@@ -117,7 +117,7 @@ struct platform_device; xmax, xinvert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ .info = snd_soc_info_volsw, \ - .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \ + .get = snd_soc_get_volsw, .put = snd_soc_put_volsw_range, \ .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, \ xshift, xmin, xmax, xinvert) }#define SOC_DOUBLE_TLV (xname, reg, shift_left, shift_right, max, invert, tlv_array) \
@@ -165,7 +165,7 @@ struct platform_device; SNDRV_CTL_ELEM_ACCESS_READWRITE,\ .tlv.p = (tlv_array), \ .info = snd_soc_info_volsw, \ - .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \ + .get = snd_soc_get_volsw, .put = snd_soc_put_volsw_range, \ .private_value =SOC_DOUBLE_R_VALUE (reg_left, reg_right, \ xshift, xmin, xmax, xinvert) }#define SOC_DOUBLE_R_SX_TLV (xname, xreg, xrreg, xshift, xmin, xmax, tlv_array) \
@@ -571,8 +571,6 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);int snd_soc_put_volsw_range (struct snd_kcontrol *kcontrol,struct snd_ctl_elem_value *ucontrol); -int snd_soc_get_volsw_range (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_value *ucontrol);int snd_soc_limit_volume (struct snd_soc_card *card,const char *name,int max); int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
sound/soc/codecs/wm5110.c +1 -1
@@ -477,7 +477,7 @@ static int wm5110_in_pga_get(struct snd_kcontrol *kcontrol,*/ snd_soc_dapm_mutex_lock (dapm); - ret =snd_soc_get_volsw_range (kcontrol, ucontrol); + ret =snd_soc_get_volsw (kcontrol, ucontrol);snd_soc_dapm_mutex_unlock (dapm);
sound/soc/soc-ops.c +3 -39
57 lines not on this page · raw message
sound/soc/soc-topology.c +1 -1
@@ -131,7 +131,7 @@ static const struct snd_soc_tplg_kcontrol_ops io_ops[] = { snd_soc_put_enum_double, NULL}, {SND_SOC_TPLG_CTL_BYTES, snd_soc_bytes_get, snd_soc_bytes_put, snd_soc_bytes_info}, - {SND_SOC_TPLG_CTL_RANGE, snd_soc_get_volsw_range, + {SND_SOC_TPLG_CTL_RANGE, snd_soc_get_volsw, snd_soc_put_volsw_range, snd_soc_info_volsw}, {SND_SOC_TPLG_CTL_VOLSW_XR_SX, snd_soc_get_xr_sx, snd_soc_put_xr_sx, snd_soc_info_xr_sx},
Signature · 1 line
2.39.5
PATCH 10/15 ASoC: ops: Remove snd_soc_put_volsw_range()
In reply to Charles KeepaxWith the addition of the soc_mixer_ctl_to_reg() helper it is now very clear that the only difference between snd_soc_put_volsw() and snd_soc_put_volsw_range() is that the former supports double controls with both values in the same register. As such we can combine both functions.
--- include/sound/soc.h | 10 +++---- sound/soc/codecs/wm5110.c | 2 +- sound/soc/soc-ops.c | 62 ++------------------------------------- sound/soc/soc-topology.c | 2 +- 4 files changed, 9 insertions(+), 67 deletions(-)
include/sound/soc.h +4 -6
@@ -66,7 +66,7 @@ struct platform_device;#define SOC_SINGLE_RANGE (xname, xreg, xshift, xmin, xmax, xinvert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \ - .put = snd_soc_put_volsw_range, \ + .put = snd_soc_put_volsw, \ .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, 0) }#define SOC_SINGLE_TLV (xname, reg, shift, max, invert, tlv_array) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
@@ -91,7 +91,7 @@ struct platform_device; SNDRV_CTL_ELEM_ACCESS_READWRITE,\ .tlv.p = (tlv_array), \ .info = snd_soc_info_volsw, \ - .get = snd_soc_get_volsw, .put = snd_soc_put_volsw_range, \ + .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \ .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, 0) }#define SOC_DOUBLE (xname, reg, shift_left, shift_right, max, invert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
@@ -117,7 +117,7 @@ struct platform_device; xmax, xinvert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ .info = snd_soc_info_volsw, \ - .get = snd_soc_get_volsw, .put = snd_soc_put_volsw_range, \ + .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \ .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, \ xshift, xmin, xmax, xinvert) }#define SOC_DOUBLE_TLV (xname, reg, shift_left, shift_right, max, invert, tlv_array) \
@@ -165,7 +165,7 @@ struct platform_device; SNDRV_CTL_ELEM_ACCESS_READWRITE,\ .tlv.p = (tlv_array), \ .info = snd_soc_info_volsw, \ - .get = snd_soc_get_volsw, .put = snd_soc_put_volsw_range, \ + .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \ .private_value =SOC_DOUBLE_R_VALUE (reg_left, reg_right, \ xshift, xmin, xmax, xinvert) }#define SOC_DOUBLE_R_SX_TLV (xname, xreg, xrreg, xshift, xmin, xmax, tlv_array) \
@@ -569,8 +569,6 @@ int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);int snd_soc_put_volsw_sx (struct snd_kcontrol *kcontrol,struct snd_ctl_elem_value *ucontrol); -int snd_soc_put_volsw_range (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_value *ucontrol);int snd_soc_limit_volume (struct snd_soc_card *card,const char *name,int max); int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
sound/soc/codecs/wm5110.c +1 -1
@@ -497,7 +497,7 @@ static int wm5110_in_pga_put(struct snd_kcontrol *kcontrol,*/ snd_soc_dapm_mutex_lock (dapm); - ret =snd_soc_put_volsw_range (kcontrol, ucontrol); + ret =snd_soc_put_volsw (kcontrol, ucontrol);snd_soc_dapm_mutex_unlock (dapm);
sound/soc/soc-ops.c +3 -59
77 lines not on this page · raw message
sound/soc/soc-topology.c +1 -1
@@ -132,7 +132,7 @@ static const struct snd_soc_tplg_kcontrol_ops io_ops[] = { {SND_SOC_TPLG_CTL_BYTES , snd_soc_bytes_get, snd_soc_bytes_put, snd_soc_bytes_info}, {SND_SOC_TPLG_CTL_RANGE, snd_soc_get_volsw, - snd_soc_put_volsw_range, snd_soc_info_volsw}, + snd_soc_put_volsw, snd_soc_info_volsw}, {SND_SOC_TPLG_CTL_VOLSW_XR_SX, snd_soc_get_xr_sx, snd_soc_put_xr_sx, snd_soc_info_xr_sx}, {SND_SOC_TPLG_CTL_STROBE, snd_soc_get_strobe,
Signature · 1 line
2.39.5
PATCH 11/15 ASoC: ops: Factor out common code from info callbacks
In reply to Charles Keepaxsnd_soc_info_volsw() and snd_soc_info_volsw_sx() do very similar things, and have a lot of code in common. Already this is causing some issues as the detection of volume controls has been fixed in the normal callback but not the sx callback. Factor out a new helper containing the common code and leave the function specific bits behind in each callback.
--- sound/soc/soc-ops.c | 64 ++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 38 deletions(-)
sound/soc/soc-ops.c +26 -38
@@ -168,6 +168,30 @@ static int soc_mixer_sx_mask(struct soc_mixer_control *mc)return GENMASK (fls (mc->min + mc->max) -2 ,0 ); } +static int soc_info_volsw (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_info *uinfo, +struct soc_mixer_control *mc,int max) +{ +if (mc->platform_max && mc->platform_max < max) + max = mc->platform_max; + + uinfo->type =SNDRV_CTL_ELEM_TYPE_INTEGER ; + +if (max ==1 ) { +/* Even two value controls ending in Volume should be integer */ +const char *vol_string =strstr (kcontrol->id.name," Volume" ); + +if (!vol_string ||strcmp (vol_string," Volume" )) + uinfo->type =SNDRV_CTL_ELEM_TYPE_BOOLEAN ; + } + + uinfo->count =snd_soc_volsw_is_stereo (mc) ?2 :1 ; + uinfo->value.integer.min =0 ; + uinfo->value.integer.max = max; + +return 0 ; +} +/** * snd_soc_info_volsw - single mixer info callback with range. * @kcontrol: mixer control
@@ -183,29 +207,8 @@ int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, {struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; -const char *vol_string =NULL ; -int max; - - max = uinfo->value.integer.max = mc->max - mc->min; -if (mc->platform_max && mc->platform_max < max) - max = mc->platform_max; - -if (max ==1 ) { -/* Even two value controls ending in Volume should always be integer */ - vol_string =strstr (kcontrol->id.name," Volume" ); -if (vol_string && !strcmp (vol_string," Volume" )) - uinfo->type =SNDRV_CTL_ELEM_TYPE_INTEGER ; -else - uinfo->type =SNDRV_CTL_ELEM_TYPE_BOOLEAN ; - }else { - uinfo->type =SNDRV_CTL_ELEM_TYPE_INTEGER ; - } - uinfo->count =snd_soc_volsw_is_stereo (mc) ?2 :1 ; - uinfo->value.integer.min =0 ; - uinfo->value.integer.max = max; - -return 0 ; +return soc_info_volsw (kcontrol, uinfo, mc, mc->max - mc->min); }EXPORT_SYMBOL_GPL (snd_soc_info_volsw);
@@ -227,23 +230,8 @@ int snd_soc_info_volsw_sx(struct snd_kcontrol *kcontrol, {struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; -int max; -if (mc->platform_max) - max = mc->platform_max; -else - max = mc->max; - -if (max ==1 && !strstr (kcontrol->id.name," Volume" )) - uinfo->type =SNDRV_CTL_ELEM_TYPE_BOOLEAN ; -else - uinfo->type =SNDRV_CTL_ELEM_TYPE_INTEGER ; - - uinfo->count =snd_soc_volsw_is_stereo (mc) ?2 :1 ; - uinfo->value.integer.min =0 ; - uinfo->value.integer.max = max; - -return 0 ; +return soc_info_volsw (kcontrol, uinfo, mc, mc->max); }EXPORT_SYMBOL_GPL (snd_soc_info_volsw_sx);
Signature · 1 line
2.39.5
PATCH 12/15 ASoC: ops: Factor out common code from put callbacks
In reply to Charles KeepaxThere are only two differences between snd_soc_put_volsw() and snd_soc_put_volsw_sx(). The maximum field is handled differently, and snd_soc_put_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.
--- sound/soc/soc-ops.c | 138 +++++++++++++++++--------------------------- 1 file changed, 53 insertions(+), 85 deletions(-)
sound/soc/soc-ops.c +53 -85
@@ -192,6 +192,57 @@ static int soc_info_volsw(struct snd_kcontrol *kcontrol,return 0 ; } +static int soc_put_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 val1, val_mask; +unsigned int val2 =0 ; +bool double_r = false; +int ret; + + ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[0 ], max); +if (ret) +return ret; + + val1 =soc_mixer_ctl_to_reg (mc, ucontrol->value.integer.value[0 ], + mask, mc->shift, max); + val_mask = mask << mc->shift; + +if (snd_soc_volsw_is_stereo (mc)) { + ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[1 ], max); +if (ret) +return ret; + +if (mc->reg == mc->rreg) { + val1 |=soc_mixer_ctl_to_reg (mc, + ucontrol->value.integer.value[1 ], + mask, mc->rshift, max); + val_mask |= mask << mc->rshift; + }else { + val2 =soc_mixer_ctl_to_reg (mc, + ucontrol->value.integer.value[1 ], + mask, mc->shift, max); + double_r = true; + } + } + + ret =snd_soc_component_update_bits (component, mc->reg, val_mask, val1); +if (ret <0 ) +return ret; + +if (double_r) { +int err =snd_soc_component_update_bits (component, mc->rreg, + val_mask, val2); +/* Don't drop change flag */ +if (err) +return err; + } + +return ret; +} +/** * snd_soc_info_volsw - single mixer info callback with range. * @kcontrol: mixer control
@@ -289,57 +340,11 @@ EXPORT_SYMBOL_GPL(snd_soc_get_volsw);int snd_soc_put_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; -unsigned int reg = mc->reg; -unsigned int reg2 = mc->rreg; -int max = mc->max - mc->min;unsigned int mask =soc_mixer_mask (mc); -int err, ret; -bool type_2r = false; -unsigned int val2 =0 ; -unsigned int val, val_mask; - ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[0 ], max); -if (ret) -return ret; - - val =soc_mixer_ctl_to_reg (mc, ucontrol->value.integer.value[0 ], - mask, mc->shift, max); - val_mask = mask << mc->shift; - -if (snd_soc_volsw_is_stereo (mc)) { - ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[1 ], max); -if (ret) -return ret; - -if (reg == reg2) { - val |=soc_mixer_ctl_to_reg (mc, - ucontrol->value.integer.value[1 ], - mask, mc->rshift, max); - val_mask |= mask << mc->rshift; - }else { - val2 =soc_mixer_ctl_to_reg (mc, - ucontrol->value.integer.value[1 ], - mask, mc->shift, max); - type_2r = true; - } - } - err =snd_soc_component_update_bits (component, reg, val_mask, val); -if (err <0 ) -return err; - ret = err; - -if (type_2r) { - err =snd_soc_component_update_bits (component, reg2, val_mask, - val2); -/* Don't discard any error code or drop change flag */ -if (ret ==0 || err <0 ) - ret = err; - } - -return ret; +return soc_put_volsw (kcontrol, ucontrol, mc, mask, mc->max - mc->min); }EXPORT_SYMBOL_GPL (snd_soc_put_volsw);
@@ -393,48 +398,11 @@ EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx);int snd_soc_put_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 val, val_mask;unsigned int mask =soc_mixer_sx_mask (mc); -int err =0 ; -int ret; - - ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[0 ], mc->max); -if (ret) -return ret; - - val =soc_mixer_ctl_to_reg (mc, ucontrol->value.integer.value[0 ], - mask, mc->shift, mc->max); - val_mask = mask << mc->shift; - - err =snd_soc_component_update_bits (component, reg, val_mask, val); -if (err <0 ) -return err; - ret = err; -if (snd_soc_volsw_is_stereo (mc)) { - ret =soc_mixer_valid_ctl (mc, ucontrol->value.integer.value[1 ], - mc->max); -if (ret) -return ret; - - val =soc_mixer_ctl_to_reg (mc, ucontrol->value.integer.value[1 ], - mask, mc->rshift, mc->max); - val_mask = mask << mc->rshift; - - err =snd_soc_component_update_bits (component, reg2, val_mask, - val); - -/* Don't discard any error code or drop change flag */ -if (ret ==0 || err <0 ) - ret = err; - } - -return ret; +return soc_put_volsw (kcontrol, ucontrol, mc, mask, mc->max); }EXPORT_SYMBOL_GPL (snd_soc_put_volsw_sx);
Signature · 1 line
2.39.5
PATCH 13/15 ASoC: ops: Factor out common code from get callbacks
In reply to Charles KeepaxThere 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.
--- sound/soc/soc-ops.c | 66 ++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 37 deletions(-)
sound/soc/soc-ops.c +29 -37
@@ -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);
Signature · 1 line
2.39.5
Mark Brown
maintainerRe: [PATCH 13/15] ASoC: ops: Factor out common code from get callbacks
Quoted 4 lines · Charles Keepax
There are only two differences between
snd_soc_get_volsw()andsnd_soc_get_volsw_sx(). The maximum field is handled differently, andsnd_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.
Re: [PATCH 13/15] ASoC: ops: Factor out common code from get callbacks
Quoted 19 lines · Mark Brown
Quoted 4 lines · Charles Keepax
There are only two differences between
snd_soc_get_volsw()andsnd_soc_get_volsw_sx(). The maximum field is handled differently, andsnd_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
Quoted 1 line
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
maintainerRe: [PATCH 13/15] ASoC: ops: Factor out common code from get callbacks
Quoted 3 lines · Charles Keepax
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.
PATCH 14/15 ASoC: ops: Remove some unnecessary local variables
In reply to Charles KeepaxRemove some local variables that aren't adding much in terms of clarity or space saving.
--- sound/soc/soc-ops.c | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-)
sound/soc/soc-ops.c +17 -27
@@ -370,8 +370,6 @@ int snd_soc_get_volsw_sx(struct snd_kcontrol *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);return soc_get_volsw (kcontrol, ucontrol, mc, mask, mc->max);
@@ -666,9 +664,6 @@ int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,unsigned int regwshift = component->val_bytes *BITS_PER_BYTE ;unsigned int regwmask =GENMASK (regwshift -1 ,0 );unsigned long mask =GENMASK (mc->nbits -1 ,0 ); -unsigned int invert = mc->invert; -long min = mc->min; -long max = mc->max;long val =0 ;unsigned int i;
@@ -678,10 +673,10 @@ int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol, val |= (regval & regwmask) << (regwshift * (regcount - i -1 )); } val &= mask; -if (min <0 && val > max) +if (mc->min <0 && val > mc->max) val |= ~mask; -if (invert) - val = max - val; +if (mc->invert) + val = mc->max - val; ucontrol->value.integer.value[0 ] = val;return 0 ;
@@ -713,16 +708,14 @@ int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,unsigned int regwshift = component->val_bytes *BITS_PER_BYTE ;unsigned int regwmask =GENMASK (regwshift -1 ,0 );unsigned long mask =GENMASK (mc->nbits -1 ,0 ); -unsigned int invert = mc->invert; -long max = mc->max;long val = ucontrol->value.integer.value[0 ];int ret =0 ;unsigned int i;if (val < mc->min || val > mc->max)return -EINVAL ; -if (invert) - val = max - val; +if (mc->invert) + val = mc->max - val; val &= mask;for (i =0 ; i < regcount; i++) { unsigned int regval = (val >> (regwshift * (regcount - i - 1))) &
@@ -757,17 +750,16 @@ int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,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 shift = mc->shift; -unsigned int mask =BIT (shift);unsigned int invert = mc->invert !=0 ; +unsigned int mask =BIT (mc->shift);unsigned int val; - val =snd_soc_component_read (component, reg); + val =snd_soc_component_read (component, mc->reg); val &= mask; -if (shift !=0 && val !=0 ) - val = val >> shift; +if (mc->shift !=0 && val !=0 ) + val = val >> mc->shift; + ucontrol->value.enumerated.item[0 ] = val ^ invert;return 0 ;
@@ -790,19 +782,17 @@ int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,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 shift = mc->shift; -unsigned int mask =BIT (shift); -unsigned int invert = mc->invert !=0 ;unsigned int strobe = ucontrol->value.enumerated.item[0 ] !=0 ; +unsigned int invert = mc->invert !=0 ; +unsigned int mask =BIT (mc->shift);unsigned int val1 = (strobe ^ invert) ? mask :0 ;unsigned int val2 = (strobe ^ invert) ?0 : mask; -int err; +int ret; - err =snd_soc_component_update_bits (component, reg, mask, val1); -if (err <0 ) -return err; + ret =snd_soc_component_update_bits (component, mc->reg, mask, val1); +if (ret <0 ) +return ret; -return snd_soc_component_update_bits (component, reg, mask, val2); +return snd_soc_component_update_bits (component, mc->reg, mask, val2); }EXPORT_SYMBOL_GPL (snd_soc_put_strobe);
Signature · 1 line
2.39.5
PATCH 15/15 ASoC: ops: Apply platform_max after deciding control type
In reply to Charles KeepaxIt doesn't really make sense for the type of a control to change based on the platform_max field. platform_max allows a specific system to limit values of a control for safety but it seems reasonable the control type should remain the same between different systems, even if it is restricted down to just two values. Move the application of platform_max to after control type determination in soc_info_volsw().
--- sound/soc/soc-ops.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sound/soc/soc-ops.c +3 -3
@@ -172,9 +172,6 @@ static int soc_info_volsw(struct snd_kcontrol *kcontrol,struct snd_ctl_elem_info *uinfo, struct soc_mixer_control *mc, int max) { - if (mc->platform_max && mc->platform_max < max) - max = mc->platform_max; - uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;if (max ==1 ) {
@@ -185,6 +182,9 @@ static int soc_info_volsw(struct snd_kcontrol *kcontrol, uinfo->type =SNDRV_CTL_ELEM_TYPE_BOOLEAN ; } +if (mc->platform_max && mc->platform_max < max) + max = mc->platform_max; + uinfo->count =snd_soc_volsw_is_stereo (mc) ?2 :1 ; uinfo->value.integer.min =0 ; uinfo->value.integer.max = max;
Signature · 1 line
2.39.5
Mark Brown
maintainerQuoted 8 lines · Charles Keepax
There is a lot of duplicated and occasionally slightly incorrect code around the ASoC control get and put handlers. This series add some kunit tests and then refactors the code to get all the tests passing and reduce some of the duplication. The focus here is on the volsw handlers, future work could still be done on some of the others but these were the ones that most required attention.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[01/15] ASoC: ops-test: Add some basic kunit tests for soc-ops
commit: 7a24b876ad8cdd56457e881d384a038922b508c3
[02/15] ASoC: ops: Minor formatting fixups
commit: 534bfb330b2612199b2afaafc769ccb42bebb204
[03/15] ASoC: ops: Update comments for xr_sx control helpers
commit: 7f978180673b4f3b68fcc66fc1f1d74a1fc5a93a
[04/15] ASoC: ops: Update mask generation to use GENMASK
commit: c6002c1177cafb4462b6c188d2a62eb67f15165f
[05/15] ASoC: ops: Factor out helper to check valid control values
commit: eeb76cb1fa0dcccf33091b04ba150076dfbeb6fd
[06/15] ASoC: ops: Replace snd_soc_read_signed() with new helper
commit: 1522aacd0114069b7f01f047b9e5b159399af295
[07/15] ASoC: ops: Add control to register value helper
commit: ed336066202c02f0b0e47d0cf08fd8f40a42351f
[08/15] ASoC: ops: Remove snd_soc_info_volsw_range()
commit: 894a37c9de4b8a447ffa609d552e91ccb447c0a9
[09/15] ASoC: ops: Remove snd_soc_get_volsw_range()
commit: fd7442561cfe9516b37cdb1d229dc1f811dc86cc
[10/15] ASoC: ops: Remove snd_soc_put_volsw_range()
commit: 7d5df968f95cee274740d5fa42e0798ffb59bd38
[11/15] ASoC: ops: Factor out common code from info callbacks
commit: 9dfcafe2037acc14265cead8d8a937a8bc4e01d8
[12/15] ASoC: ops: Factor out common code from put callbacks
commit: 318e8794e05ca1879441a602e78c74f9d7e18309
[13/15] ASoC: ops: Factor out common code from get callbacks
commit: 1e3cd64a29baa874b89180ac0744178ecb00f3cd
[14/15] ASoC: ops: Remove some unnecessary local variables
commit: 94dfe71f0a4eb0d7df542560c22961dedf45141d
[15/15] ASoC: ops: Apply platform_max after deciding control type
commit: 502a668fad12b6ca10bcbb615d62e61d3b669c99All 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