aeb0c3f0d6e6ac367e2e619615809e464933ee95
[openwrt/staging/thess.git] /
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
5 helpers
6
7 commit dc5c0eb1e8601206dffbfc302cbd190f89dcd040 upstream.
8
9 Just a minor code refactoring and adding some const prefix.
10
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>
14 ---
15 .../vc04_services/bcm2835-audio/bcm2835-ctl.c | 69 +++++++------------
16 1 file changed, 25 insertions(+), 44 deletions(-)
17
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
21
22 static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
23
24 -static struct snd_kcontrol_new snd_bcm2835_ctl[] = {
25 +static const struct snd_kcontrol_new snd_bcm2835_ctl[] = {
26 {
27 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
28 .name = "PCM Playback Volume",
29 - .index = 0,
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,
35 - .count = 1,
36 .tlv = {.p = snd_bcm2835_db_scale}
37 },
38 {
39 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
40 .name = "PCM Playback Switch",
41 - .index = 0,
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,
47 - .count = 1,
48 },
49 {
50 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
51 .name = "PCM Playback Route",
52 - .index = 0,
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,
58 - .count = 1,
59 },
60 };
61
62 @@ -196,7 +190,7 @@ static int snd_bcm2835_spdif_mask_get(st
63 return 0;
64 }
65
66 -static struct snd_kcontrol_new snd_bcm2835_spdif[] = {
67 +static const struct snd_kcontrol_new snd_bcm2835_spdif[] = {
68 {
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
72 },
73 };
74
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)
78 {
79 - int err;
80 - unsigned int idx;
81 + int i, err;
82
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));
87 - if (err < 0)
88 - return err;
89 - }
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));
95 if (err < 0)
96 return err;
97 }
98 return 0;
99 }
100
101 -static struct snd_kcontrol_new snd_bcm2835_headphones_ctl[] = {
102 +int snd_bcm2835_new_ctl(struct bcm2835_chip *chip)
103 +{
104 + int err;
105 +
106 + strcpy(chip->card->mixername, "Broadcom Mixer");
107 + err = create_ctls(chip, ARRAY_SIZE(snd_bcm2835_ctl), snd_bcm2835_ctl);
108 + if (err < 0)
109 + return err;
110 + return create_ctls(chip, ARRAY_SIZE(snd_bcm2835_spdif),
111 + snd_bcm2835_spdif);
112 +}
113 +
114 +static const struct snd_kcontrol_new snd_bcm2835_headphones_ctl[] = {
115 {
116 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
117 .name = "Headphone Playback Volume",
118 @@ -263,21 +261,12 @@ static struct snd_kcontrol_new snd_bcm28
119
120 int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip)
121 {
122 - int err;
123 - unsigned int idx;
124 -
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],
129 - chip));
130 - if (err)
131 - return err;
132 - }
133 - return 0;
134 + return create_ctls(chip, ARRAY_SIZE(snd_bcm2835_headphones_ctl),
135 + snd_bcm2835_headphones_ctl);
136 }
137
138 -static struct snd_kcontrol_new snd_bcm2835_hdmi[] = {
139 +static const struct snd_kcontrol_new snd_bcm2835_hdmi[] = {
140 {
141 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
142 .name = "HDMI Playback Volume",
143 @@ -306,16 +295,8 @@ static struct snd_kcontrol_new snd_bcm28
144
145 int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip)
146 {
147 - int err;
148 - unsigned int idx;
149 -
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));
154 - if (err)
155 - return err;
156 - }
157 - return 0;
158 + return create_ctls(chip, ARRAY_SIZE(snd_bcm2835_hdmi),
159 + snd_bcm2835_hdmi);
160 }
161