1 From c4766c1589a25608ffe6848722632be2f65d0951 Mon Sep 17 00:00:00 2001
2 From: Takashi Iwai <tiwai@suse.de>
3 Date: Tue, 4 Sep 2018 17:58:57 +0200
4 Subject: [PATCH 461/806] staging: bcm2835-audio: Simplify kctl creation
7 commit dc5c0eb1e8601206dffbfc302cbd190f89dcd040 upstream.
9 Just a minor code refactoring and adding some const prefix.
11 Signed-off-by: Takashi Iwai <tiwai@suse.de>
12 Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
13 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
15 .../vc04_services/bcm2835-audio/bcm2835-ctl.c | 69 +++++++------------
16 1 file changed, 25 insertions(+), 44 deletions(-)
18 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c
19 +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c
20 @@ -97,40 +97,34 @@ static int snd_bcm2835_ctl_put(struct sn
22 static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
24 -static struct snd_kcontrol_new snd_bcm2835_ctl[] = {
25 +static const struct snd_kcontrol_new snd_bcm2835_ctl[] = {
27 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
28 .name = "PCM Playback Volume",
30 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
31 .private_value = PCM_PLAYBACK_VOLUME,
32 .info = snd_bcm2835_ctl_info,
33 .get = snd_bcm2835_ctl_get,
34 .put = snd_bcm2835_ctl_put,
36 .tlv = {.p = snd_bcm2835_db_scale}
39 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
40 .name = "PCM Playback Switch",
42 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
43 .private_value = PCM_PLAYBACK_MUTE,
44 .info = snd_bcm2835_ctl_info,
45 .get = snd_bcm2835_ctl_get,
46 .put = snd_bcm2835_ctl_put,
50 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
51 .name = "PCM Playback Route",
53 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
54 .private_value = PCM_PLAYBACK_DEVICE,
55 .info = snd_bcm2835_ctl_info,
56 .get = snd_bcm2835_ctl_get,
57 .put = snd_bcm2835_ctl_put,
62 @@ -196,7 +190,7 @@ static int snd_bcm2835_spdif_mask_get(st
66 -static struct snd_kcontrol_new snd_bcm2835_spdif[] = {
67 +static const struct snd_kcontrol_new snd_bcm2835_spdif[] = {
69 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
70 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
71 @@ -213,28 +207,32 @@ static struct snd_kcontrol_new snd_bcm28
75 -int snd_bcm2835_new_ctl(struct bcm2835_chip *chip)
76 +static int create_ctls(struct bcm2835_chip *chip, size_t size,
77 + const struct snd_kcontrol_new *kctls)
83 - strcpy(chip->card->mixername, "Broadcom Mixer");
84 - for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) {
85 - err = snd_ctl_add(chip->card,
86 - snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
90 - for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_spdif); idx++) {
91 - err = snd_ctl_add(chip->card,
92 - snd_ctl_new1(&snd_bcm2835_spdif[idx], chip));
93 + for (i = 0; i < size; i++) {
94 + err = snd_ctl_add(chip->card, snd_ctl_new1(&kctls[i], chip));
101 -static struct snd_kcontrol_new snd_bcm2835_headphones_ctl[] = {
102 +int snd_bcm2835_new_ctl(struct bcm2835_chip *chip)
106 + strcpy(chip->card->mixername, "Broadcom Mixer");
107 + err = create_ctls(chip, ARRAY_SIZE(snd_bcm2835_ctl), snd_bcm2835_ctl);
110 + return create_ctls(chip, ARRAY_SIZE(snd_bcm2835_spdif),
111 + snd_bcm2835_spdif);
114 +static const struct snd_kcontrol_new snd_bcm2835_headphones_ctl[] = {
116 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
117 .name = "Headphone Playback Volume",
118 @@ -263,21 +261,12 @@ static struct snd_kcontrol_new snd_bcm28
120 int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip)
125 strcpy(chip->card->mixername, "Broadcom Mixer");
126 - for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_headphones_ctl); idx++) {
127 - err = snd_ctl_add(chip->card,
128 - snd_ctl_new1(&snd_bcm2835_headphones_ctl[idx],
134 + return create_ctls(chip, ARRAY_SIZE(snd_bcm2835_headphones_ctl),
135 + snd_bcm2835_headphones_ctl);
138 -static struct snd_kcontrol_new snd_bcm2835_hdmi[] = {
139 +static const struct snd_kcontrol_new snd_bcm2835_hdmi[] = {
141 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
142 .name = "HDMI Playback Volume",
143 @@ -306,16 +295,8 @@ static struct snd_kcontrol_new snd_bcm28
145 int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip)
150 strcpy(chip->card->mixername, "Broadcom Mixer");
151 - for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_hdmi); idx++) {
152 - err = snd_ctl_add(chip->card,
153 - snd_ctl_new1(&snd_bcm2835_hdmi[idx], chip));
158 + return create_ctls(chip, ARRAY_SIZE(snd_bcm2835_hdmi),