hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/sound/core/vmaster.c
....@@ -1,12 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
2
- * Virtual master and slave controls
3
+ * Virtual master and follower controls
34 *
45 * Copyright (c) 2008 by Takashi Iwai <tiwai@suse.de>
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License as
8
- * published by the Free Software Foundation, version 2.
9
- *
106 */
117
128 #include <linux/slab.h>
....@@ -25,15 +21,15 @@
2521 };
2622
2723 /*
28
- * link master - this contains a list of slave controls that are
24
+ * link master - this contains a list of follower controls that are
2925 * identical types, i.e. info returns the same value type and value
3026 * ranges, but may have different number of counts.
3127 *
3228 * The master control is so far only mono volume/switch for simplicity.
33
- * The same value will be applied to all slaves.
29
+ * The same value will be applied to all followers.
3430 */
3531 struct link_master {
36
- struct list_head slaves;
32
+ struct list_head followers;
3733 struct link_ctl_info info;
3834 int val; /* the master value */
3935 unsigned int tlv[4];
....@@ -42,23 +38,23 @@
4238 };
4339
4440 /*
45
- * link slave - this contains a slave control element
41
+ * link follower - this contains a follower control element
4642 *
47
- * It fakes the control callbacsk with additional attenuation by the
48
- * master control. A slave may have either one or two channels.
43
+ * It fakes the control callbacks with additional attenuation by the
44
+ * master control. A follower may have either one or two channels.
4945 */
5046
51
-struct link_slave {
47
+struct link_follower {
5248 struct list_head list;
5349 struct link_master *master;
5450 struct link_ctl_info info;
5551 int vals[2]; /* current values */
5652 unsigned int flags;
5753 struct snd_kcontrol *kctl; /* original kcontrol pointer */
58
- struct snd_kcontrol slave; /* the copy of original control entry */
54
+ struct snd_kcontrol follower; /* the copy of original control entry */
5955 };
6056
61
-static int slave_update(struct link_slave *slave)
57
+static int follower_update(struct link_follower *follower)
6258 {
6359 struct snd_ctl_elem_value *uctl;
6460 int err, ch;
....@@ -66,68 +62,68 @@
6662 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
6763 if (!uctl)
6864 return -ENOMEM;
69
- uctl->id = slave->slave.id;
70
- err = slave->slave.get(&slave->slave, uctl);
65
+ uctl->id = follower->follower.id;
66
+ err = follower->follower.get(&follower->follower, uctl);
7167 if (err < 0)
7268 goto error;
73
- for (ch = 0; ch < slave->info.count; ch++)
74
- slave->vals[ch] = uctl->value.integer.value[ch];
69
+ for (ch = 0; ch < follower->info.count; ch++)
70
+ follower->vals[ch] = uctl->value.integer.value[ch];
7571 error:
7672 kfree(uctl);
7773 return err < 0 ? err : 0;
7874 }
7975
80
-/* get the slave ctl info and save the initial values */
81
-static int slave_init(struct link_slave *slave)
76
+/* get the follower ctl info and save the initial values */
77
+static int follower_init(struct link_follower *follower)
8278 {
8379 struct snd_ctl_elem_info *uinfo;
8480 int err;
8581
86
- if (slave->info.count) {
82
+ if (follower->info.count) {
8783 /* already initialized */
88
- if (slave->flags & SND_CTL_SLAVE_NEED_UPDATE)
89
- return slave_update(slave);
84
+ if (follower->flags & SND_CTL_FOLLOWER_NEED_UPDATE)
85
+ return follower_update(follower);
9086 return 0;
9187 }
9288
9389 uinfo = kmalloc(sizeof(*uinfo), GFP_KERNEL);
9490 if (!uinfo)
9591 return -ENOMEM;
96
- uinfo->id = slave->slave.id;
97
- err = slave->slave.info(&slave->slave, uinfo);
92
+ uinfo->id = follower->follower.id;
93
+ err = follower->follower.info(&follower->follower, uinfo);
9894 if (err < 0) {
9995 kfree(uinfo);
10096 return err;
10197 }
102
- slave->info.type = uinfo->type;
103
- slave->info.count = uinfo->count;
104
- if (slave->info.count > 2 ||
105
- (slave->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER &&
106
- slave->info.type != SNDRV_CTL_ELEM_TYPE_BOOLEAN)) {
107
- pr_err("ALSA: vmaster: invalid slave element\n");
98
+ follower->info.type = uinfo->type;
99
+ follower->info.count = uinfo->count;
100
+ if (follower->info.count > 2 ||
101
+ (follower->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER &&
102
+ follower->info.type != SNDRV_CTL_ELEM_TYPE_BOOLEAN)) {
103
+ pr_err("ALSA: vmaster: invalid follower element\n");
108104 kfree(uinfo);
109105 return -EINVAL;
110106 }
111
- slave->info.min_val = uinfo->value.integer.min;
112
- slave->info.max_val = uinfo->value.integer.max;
107
+ follower->info.min_val = uinfo->value.integer.min;
108
+ follower->info.max_val = uinfo->value.integer.max;
113109 kfree(uinfo);
114110
115
- return slave_update(slave);
111
+ return follower_update(follower);
116112 }
117113
118114 /* initialize master volume */
119115 static int master_init(struct link_master *master)
120116 {
121
- struct link_slave *slave;
117
+ struct link_follower *follower;
122118
123119 if (master->info.count)
124120 return 0; /* already initialized */
125121
126
- list_for_each_entry(slave, &master->slaves, list) {
127
- int err = slave_init(slave);
122
+ list_for_each_entry(follower, &master->followers, list) {
123
+ int err = follower_init(follower);
128124 if (err < 0)
129125 return err;
130
- master->info = slave->info;
126
+ master->info = follower->info;
131127 master->info.count = 1; /* always mono */
132128 /* set full volume as default (= no attenuation) */
133129 master->val = master->info.max_val;
....@@ -138,113 +134,113 @@
138134 return -ENOENT;
139135 }
140136
141
-static int slave_get_val(struct link_slave *slave,
142
- struct snd_ctl_elem_value *ucontrol)
137
+static int follower_get_val(struct link_follower *follower,
138
+ struct snd_ctl_elem_value *ucontrol)
143139 {
144140 int err, ch;
145141
146
- err = slave_init(slave);
142
+ err = follower_init(follower);
147143 if (err < 0)
148144 return err;
149
- for (ch = 0; ch < slave->info.count; ch++)
150
- ucontrol->value.integer.value[ch] = slave->vals[ch];
145
+ for (ch = 0; ch < follower->info.count; ch++)
146
+ ucontrol->value.integer.value[ch] = follower->vals[ch];
151147 return 0;
152148 }
153149
154
-static int slave_put_val(struct link_slave *slave,
155
- struct snd_ctl_elem_value *ucontrol)
150
+static int follower_put_val(struct link_follower *follower,
151
+ struct snd_ctl_elem_value *ucontrol)
156152 {
157153 int err, ch, vol;
158154
159
- err = master_init(slave->master);
155
+ err = master_init(follower->master);
160156 if (err < 0)
161157 return err;
162158
163
- switch (slave->info.type) {
159
+ switch (follower->info.type) {
164160 case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
165
- for (ch = 0; ch < slave->info.count; ch++)
161
+ for (ch = 0; ch < follower->info.count; ch++)
166162 ucontrol->value.integer.value[ch] &=
167
- !!slave->master->val;
163
+ !!follower->master->val;
168164 break;
169165 case SNDRV_CTL_ELEM_TYPE_INTEGER:
170
- for (ch = 0; ch < slave->info.count; ch++) {
166
+ for (ch = 0; ch < follower->info.count; ch++) {
171167 /* max master volume is supposed to be 0 dB */
172168 vol = ucontrol->value.integer.value[ch];
173
- vol += slave->master->val - slave->master->info.max_val;
174
- if (vol < slave->info.min_val)
175
- vol = slave->info.min_val;
176
- else if (vol > slave->info.max_val)
177
- vol = slave->info.max_val;
169
+ vol += follower->master->val - follower->master->info.max_val;
170
+ if (vol < follower->info.min_val)
171
+ vol = follower->info.min_val;
172
+ else if (vol > follower->info.max_val)
173
+ vol = follower->info.max_val;
178174 ucontrol->value.integer.value[ch] = vol;
179175 }
180176 break;
181177 }
182
- return slave->slave.put(&slave->slave, ucontrol);
178
+ return follower->follower.put(&follower->follower, ucontrol);
183179 }
184180
185181 /*
186
- * ctl callbacks for slaves
182
+ * ctl callbacks for followers
187183 */
188
-static int slave_info(struct snd_kcontrol *kcontrol,
189
- struct snd_ctl_elem_info *uinfo)
184
+static int follower_info(struct snd_kcontrol *kcontrol,
185
+ struct snd_ctl_elem_info *uinfo)
190186 {
191
- struct link_slave *slave = snd_kcontrol_chip(kcontrol);
192
- return slave->slave.info(&slave->slave, uinfo);
187
+ struct link_follower *follower = snd_kcontrol_chip(kcontrol);
188
+ return follower->follower.info(&follower->follower, uinfo);
193189 }
194190
195
-static int slave_get(struct snd_kcontrol *kcontrol,
196
- struct snd_ctl_elem_value *ucontrol)
191
+static int follower_get(struct snd_kcontrol *kcontrol,
192
+ struct snd_ctl_elem_value *ucontrol)
197193 {
198
- struct link_slave *slave = snd_kcontrol_chip(kcontrol);
199
- return slave_get_val(slave, ucontrol);
194
+ struct link_follower *follower = snd_kcontrol_chip(kcontrol);
195
+ return follower_get_val(follower, ucontrol);
200196 }
201197
202
-static int slave_put(struct snd_kcontrol *kcontrol,
203
- struct snd_ctl_elem_value *ucontrol)
198
+static int follower_put(struct snd_kcontrol *kcontrol,
199
+ struct snd_ctl_elem_value *ucontrol)
204200 {
205
- struct link_slave *slave = snd_kcontrol_chip(kcontrol);
201
+ struct link_follower *follower = snd_kcontrol_chip(kcontrol);
206202 int err, ch, changed = 0;
207203
208
- err = slave_init(slave);
204
+ err = follower_init(follower);
209205 if (err < 0)
210206 return err;
211
- for (ch = 0; ch < slave->info.count; ch++) {
212
- if (slave->vals[ch] != ucontrol->value.integer.value[ch]) {
207
+ for (ch = 0; ch < follower->info.count; ch++) {
208
+ if (follower->vals[ch] != ucontrol->value.integer.value[ch]) {
213209 changed = 1;
214
- slave->vals[ch] = ucontrol->value.integer.value[ch];
210
+ follower->vals[ch] = ucontrol->value.integer.value[ch];
215211 }
216212 }
217213 if (!changed)
218214 return 0;
219
- err = slave_put_val(slave, ucontrol);
215
+ err = follower_put_val(follower, ucontrol);
220216 if (err < 0)
221217 return err;
222218 return 1;
223219 }
224220
225
-static int slave_tlv_cmd(struct snd_kcontrol *kcontrol,
226
- int op_flag, unsigned int size,
227
- unsigned int __user *tlv)
221
+static int follower_tlv_cmd(struct snd_kcontrol *kcontrol,
222
+ int op_flag, unsigned int size,
223
+ unsigned int __user *tlv)
228224 {
229
- struct link_slave *slave = snd_kcontrol_chip(kcontrol);
225
+ struct link_follower *follower = snd_kcontrol_chip(kcontrol);
230226 /* FIXME: this assumes that the max volume is 0 dB */
231
- return slave->slave.tlv.c(&slave->slave, op_flag, size, tlv);
227
+ return follower->follower.tlv.c(&follower->follower, op_flag, size, tlv);
232228 }
233229
234
-static void slave_free(struct snd_kcontrol *kcontrol)
230
+static void follower_free(struct snd_kcontrol *kcontrol)
235231 {
236
- struct link_slave *slave = snd_kcontrol_chip(kcontrol);
237
- if (slave->slave.private_free)
238
- slave->slave.private_free(&slave->slave);
239
- if (slave->master)
240
- list_del(&slave->list);
241
- kfree(slave);
232
+ struct link_follower *follower = snd_kcontrol_chip(kcontrol);
233
+ if (follower->follower.private_free)
234
+ follower->follower.private_free(&follower->follower);
235
+ if (follower->master)
236
+ list_del(&follower->list);
237
+ kfree(follower);
242238 }
243239
244240 /*
245
- * Add a slave control to the group with the given master control
241
+ * Add a follower control to the group with the given master control
246242 *
247
- * All slaves must be the same type (returning the same information
243
+ * All followers must be the same type (returning the same information
248244 * via info callback). The function doesn't check it, so it's your
249245 * responsibility.
250246 *
....@@ -253,35 +249,36 @@
253249 * - logarithmic volume control (dB level), no linear volume
254250 * - master can only attenuate the volume, no gain
255251 */
256
-int _snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave,
257
- unsigned int flags)
252
+int _snd_ctl_add_follower(struct snd_kcontrol *master,
253
+ struct snd_kcontrol *follower,
254
+ unsigned int flags)
258255 {
259256 struct link_master *master_link = snd_kcontrol_chip(master);
260
- struct link_slave *srec;
257
+ struct link_follower *srec;
261258
262
- srec = kzalloc(struct_size(srec, slave.vd, slave->count),
259
+ srec = kzalloc(struct_size(srec, follower.vd, follower->count),
263260 GFP_KERNEL);
264261 if (!srec)
265262 return -ENOMEM;
266
- srec->kctl = slave;
267
- srec->slave = *slave;
268
- memcpy(srec->slave.vd, slave->vd, slave->count * sizeof(*slave->vd));
263
+ srec->kctl = follower;
264
+ srec->follower = *follower;
265
+ memcpy(srec->follower.vd, follower->vd, follower->count * sizeof(*follower->vd));
269266 srec->master = master_link;
270267 srec->flags = flags;
271268
272269 /* override callbacks */
273
- slave->info = slave_info;
274
- slave->get = slave_get;
275
- slave->put = slave_put;
276
- if (slave->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK)
277
- slave->tlv.c = slave_tlv_cmd;
278
- slave->private_data = srec;
279
- slave->private_free = slave_free;
270
+ follower->info = follower_info;
271
+ follower->get = follower_get;
272
+ follower->put = follower_put;
273
+ if (follower->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK)
274
+ follower->tlv.c = follower_tlv_cmd;
275
+ follower->private_data = srec;
276
+ follower->private_free = follower_free;
280277
281
- list_add_tail(&srec->list, &master_link->slaves);
278
+ list_add_tail(&srec->list, &master_link->followers);
282279 return 0;
283280 }
284
-EXPORT_SYMBOL(_snd_ctl_add_slave);
281
+EXPORT_SYMBOL(_snd_ctl_add_follower);
285282
286283 /*
287284 * ctl callbacks for master controls
....@@ -313,20 +310,20 @@
313310 return 0;
314311 }
315312
316
-static int sync_slaves(struct link_master *master, int old_val, int new_val)
313
+static int sync_followers(struct link_master *master, int old_val, int new_val)
317314 {
318
- struct link_slave *slave;
315
+ struct link_follower *follower;
319316 struct snd_ctl_elem_value *uval;
320317
321318 uval = kmalloc(sizeof(*uval), GFP_KERNEL);
322319 if (!uval)
323320 return -ENOMEM;
324
- list_for_each_entry(slave, &master->slaves, list) {
321
+ list_for_each_entry(follower, &master->followers, list) {
325322 master->val = old_val;
326
- uval->id = slave->slave.id;
327
- slave_get_val(slave, uval);
323
+ uval->id = follower->follower.id;
324
+ follower_get_val(follower, uval);
328325 master->val = new_val;
329
- slave_put_val(slave, uval);
326
+ follower_put_val(follower, uval);
330327 }
331328 kfree(uval);
332329 return 0;
....@@ -348,7 +345,7 @@
348345 if (new_val == old_val)
349346 return 0;
350347
351
- err = sync_slaves(master, old_val, new_val);
348
+ err = sync_followers(master, old_val, new_val);
352349 if (err < 0)
353350 return err;
354351 if (master->hook && !first_init)
....@@ -359,17 +356,17 @@
359356 static void master_free(struct snd_kcontrol *kcontrol)
360357 {
361358 struct link_master *master = snd_kcontrol_chip(kcontrol);
362
- struct link_slave *slave, *n;
359
+ struct link_follower *follower, *n;
363360
364
- /* free all slave links and retore the original slave kctls */
365
- list_for_each_entry_safe(slave, n, &master->slaves, list) {
366
- struct snd_kcontrol *sctl = slave->kctl;
361
+ /* free all follower links and retore the original follower kctls */
362
+ list_for_each_entry_safe(follower, n, &master->followers, list) {
363
+ struct snd_kcontrol *sctl = follower->kctl;
367364 struct list_head olist = sctl->list;
368
- memcpy(sctl, &slave->slave, sizeof(*sctl));
369
- memcpy(sctl->vd, slave->slave.vd,
365
+ memcpy(sctl, &follower->follower, sizeof(*sctl));
366
+ memcpy(sctl->vd, follower->follower.vd,
370367 sctl->count * sizeof(*sctl->vd));
371368 sctl->list = olist; /* keep the current linked-list */
372
- kfree(slave);
369
+ kfree(follower);
373370 }
374371 kfree(master);
375372 }
....@@ -382,8 +379,8 @@
382379 *
383380 * Creates a virtual master control with the given name string.
384381 *
385
- * After creating a vmaster element, you can add the slave controls
386
- * via snd_ctl_add_slave() or snd_ctl_add_slave_uncached().
382
+ * After creating a vmaster element, you can add the follower controls
383
+ * via snd_ctl_add_follower() or snd_ctl_add_follower_uncached().
387384 *
388385 * The optional argument @tlv can be used to specify the TLV information
389386 * for dB scale of the master control. It should be a single element
....@@ -407,7 +404,7 @@
407404 master = kzalloc(sizeof(*master), GFP_KERNEL);
408405 if (!master)
409406 return NULL;
410
- INIT_LIST_HEAD(&master->slaves);
407
+ INIT_LIST_HEAD(&master->followers);
411408
412409 kctl = snd_ctl_new1(&knew, master);
413410 if (!kctl) {
....@@ -459,11 +456,11 @@
459456 EXPORT_SYMBOL_GPL(snd_ctl_add_vmaster_hook);
460457
461458 /**
462
- * snd_ctl_sync_vmaster - Sync the vmaster slaves and hook
459
+ * snd_ctl_sync_vmaster - Sync the vmaster followers and hook
463460 * @kcontrol: vmaster kctl element
464461 * @hook_only: sync only the hook
465462 *
466
- * Forcibly call the put callback of each slave and call the hook function
463
+ * Forcibly call the put callback of each follower and call the hook function
467464 * to synchronize with the current value of the given vmaster element.
468465 * NOP when NULL is passed to @kcontrol.
469466 */
....@@ -480,7 +477,7 @@
480477 if (err < 0)
481478 return;
482479 first_init = err;
483
- err = sync_slaves(master, master->val, master->val);
480
+ err = sync_followers(master, master->val, master->val);
484481 if (err < 0)
485482 return;
486483 }
....@@ -491,34 +488,34 @@
491488 EXPORT_SYMBOL_GPL(snd_ctl_sync_vmaster);
492489
493490 /**
494
- * snd_ctl_apply_vmaster_slaves - Apply function to each vmaster slave
491
+ * snd_ctl_apply_vmaster_followers - Apply function to each vmaster follower
495492 * @kctl: vmaster kctl element
496493 * @func: function to apply
497494 * @arg: optional function argument
498495 *
499
- * Apply the function @func to each slave kctl of the given vmaster kctl.
496
+ * Apply the function @func to each follower kctl of the given vmaster kctl.
500497 * Returns 0 if successful, or a negative error code.
501498 */
502
-int snd_ctl_apply_vmaster_slaves(struct snd_kcontrol *kctl,
503
- int (*func)(struct snd_kcontrol *vslave,
504
- struct snd_kcontrol *slave,
505
- void *arg),
506
- void *arg)
499
+int snd_ctl_apply_vmaster_followers(struct snd_kcontrol *kctl,
500
+ int (*func)(struct snd_kcontrol *vfollower,
501
+ struct snd_kcontrol *follower,
502
+ void *arg),
503
+ void *arg)
507504 {
508505 struct link_master *master;
509
- struct link_slave *slave;
506
+ struct link_follower *follower;
510507 int err;
511508
512509 master = snd_kcontrol_chip(kctl);
513510 err = master_init(master);
514511 if (err < 0)
515512 return err;
516
- list_for_each_entry(slave, &master->slaves, list) {
517
- err = func(slave->kctl, &slave->slave, arg);
513
+ list_for_each_entry(follower, &master->followers, list) {
514
+ err = func(follower->kctl, &follower->follower, arg);
518515 if (err < 0)
519516 return err;
520517 }
521518
522519 return 0;
523520 }
524
-EXPORT_SYMBOL_GPL(snd_ctl_apply_vmaster_slaves);
521
+EXPORT_SYMBOL_GPL(snd_ctl_apply_vmaster_followers);