Skip to content

Commit 47c4f9b

Browse files
committed
Tidy up ASoC control get and put handlers
Merge series from Charles Keepax <ckeepax@opensource.cirrus.com>: 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.
2 parents 83eddf0 + 502a668 commit 47c4f9b

File tree

9 files changed

+807
-493
lines changed

9 files changed

+807
-493
lines changed

include/sound/soc.h

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ struct platform_device;
6565
.private_value = SOC_SINGLE_VALUE(reg, shift, 0, max, invert, 0) }
6666
#define SOC_SINGLE_RANGE(xname, xreg, xshift, xmin, xmax, xinvert) \
6767
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
68-
.info = snd_soc_info_volsw_range, .get = snd_soc_get_volsw_range, \
69-
.put = snd_soc_put_volsw_range, \
68+
.info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
69+
.put = snd_soc_put_volsw, \
7070
.private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, 0) }
7171
#define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
7272
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
@@ -90,8 +90,8 @@ struct platform_device;
9090
.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
9191
SNDRV_CTL_ELEM_ACCESS_READWRITE,\
9292
.tlv.p = (tlv_array), \
93-
.info = snd_soc_info_volsw_range, \
94-
.get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
93+
.info = snd_soc_info_volsw, \
94+
.get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
9595
.private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, 0) }
9696
#define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \
9797
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
@@ -116,8 +116,8 @@ struct platform_device;
116116
#define SOC_DOUBLE_R_RANGE(xname, reg_left, reg_right, xshift, xmin, \
117117
xmax, xinvert) \
118118
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
119-
.info = snd_soc_info_volsw_range, \
120-
.get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
119+
.info = snd_soc_info_volsw, \
120+
.get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
121121
.private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, \
122122
xshift, xmin, xmax, xinvert) }
123123
#define SOC_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, tlv_array) \
@@ -164,8 +164,8 @@ struct platform_device;
164164
.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
165165
SNDRV_CTL_ELEM_ACCESS_READWRITE,\
166166
.tlv.p = (tlv_array), \
167-
.info = snd_soc_info_volsw_range, \
168-
.get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
167+
.info = snd_soc_info_volsw, \
168+
.get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
169169
.private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, \
170170
xshift, xmin, xmax, xinvert) }
171171
#define SOC_DOUBLE_R_SX_TLV(xname, xreg, xrreg, xshift, xmin, xmax, tlv_array) \
@@ -266,7 +266,7 @@ struct platform_device;
266266
.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
267267
SNDRV_CTL_ELEM_ACCESS_READWRITE,\
268268
.tlv.p = (tlv_array), \
269-
.info = snd_soc_info_volsw_range, \
269+
.info = snd_soc_info_volsw, \
270270
.get = xhandler_get, .put = xhandler_put, \
271271
.private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, 0) }
272272
#define SOC_DOUBLE_EXT_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert,\
@@ -569,12 +569,6 @@ int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
569569
struct snd_ctl_elem_value *ucontrol);
570570
int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
571571
struct snd_ctl_elem_value *ucontrol);
572-
int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
573-
struct snd_ctl_elem_info *uinfo);
574-
int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
575-
struct snd_ctl_elem_value *ucontrol);
576-
int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
577-
struct snd_ctl_elem_value *ucontrol);
578572
int snd_soc_limit_volume(struct snd_soc_card *card,
579573
const char *name, int max);
580574
int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,

sound/pci/hda/tas2781_hda_i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
4646
SNDRV_CTL_ELEM_ACCESS_READWRITE,\
4747
.tlv.p = (tlv_array), \
48-
.info = snd_soc_info_volsw_range, \
48+
.info = snd_soc_info_volsw, \
4949
.get = xhandler_get, .put = xhandler_put, \
5050
.private_value = (unsigned long)&(struct soc_mixer_control) \
5151
{.reg = xreg, .rreg = xreg, .shift = xshift, \

sound/pci/hda/tas2781_hda_spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
5353
SNDRV_CTL_ELEM_ACCESS_READWRITE, \
5454
.tlv.p = (tlv_array), \
55-
.info = snd_soc_info_volsw_range, \
55+
.info = snd_soc_info_volsw, \
5656
.get = xhandler_get, .put = xhandler_put, \
5757
.private_value = (unsigned long)&(struct soc_mixer_control) { \
5858
.reg = xreg, .rreg = xreg, \

sound/soc/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ config SND_SOC_UTILS_KUNIT_TEST
8181
help
8282
If you want to perform tests on ALSA SoC utils library say Y here.
8383

84+
config SND_SOC_OPS_KUNIT_TEST
85+
tristate "KUnit tests for SoC ops"
86+
depends on KUNIT
87+
default KUNIT_ALL_TESTS
88+
help
89+
If you want to perform tests on ALSA SoC ops library say Y here.
90+
8491
config SND_SOC_ACPI
8592
tristate
8693

sound/soc/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ ifneq ($(CONFIG_SND_SOC_UTILS_KUNIT_TEST),)
2121
obj-$(CONFIG_SND_SOC_UTILS_KUNIT_TEST) += soc-utils-test.o
2222
endif
2323

24+
ifneq ($(CONFIG_SND_SOC_OPS_KUNIT_TEST),)
25+
obj-$(CONFIG_SND_SOC_OPS_KUNIT_TEST) += soc-ops-test.o
26+
endif
27+
2428
ifneq ($(CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM),)
2529
snd-soc-core-y += soc-generic-dmaengine-pcm.o
2630
endif

sound/soc/codecs/wm5110.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ static int wm5110_in_pga_get(struct snd_kcontrol *kcontrol,
477477
*/
478478
snd_soc_dapm_mutex_lock(dapm);
479479

480-
ret = snd_soc_get_volsw_range(kcontrol, ucontrol);
480+
ret = snd_soc_get_volsw(kcontrol, ucontrol);
481481

482482
snd_soc_dapm_mutex_unlock(dapm);
483483

@@ -497,7 +497,7 @@ static int wm5110_in_pga_put(struct snd_kcontrol *kcontrol,
497497
*/
498498
snd_soc_dapm_mutex_lock(dapm);
499499

500-
ret = snd_soc_put_volsw_range(kcontrol, ucontrol);
500+
ret = snd_soc_put_volsw(kcontrol, ucontrol);
501501

502502
snd_soc_dapm_mutex_unlock(dapm);
503503

0 commit comments

Comments
 (0)