2 * Routines for driver control interface
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/threads.h>
23 #include <linux/interrupt.h>
24 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <linux/vmalloc.h>
27 #include <linux/time.h>
28 #include <sound/core.h>
29 #include <sound/minors.h>
30 #include <sound/info.h>
31 #include <sound/control.h>
33 /* max number of user-defined controls */
34 #define MAX_USER_CONTROLS 32
35 #define MAX_CONTROL_COUNT 1028
37 struct snd_kctl_ioctl {
38 struct list_head list; /* list of all ioctls */
39 snd_kctl_ioctl_func_t fioctl;
42 static DECLARE_RWSEM(snd_ioctl_rwsem);
43 static LIST_HEAD(snd_control_ioctls);
45 static LIST_HEAD(snd_control_compat_ioctls);
48 static int snd_ctl_open(struct inode *inode, struct file *file)
51 struct snd_card *card;
52 struct snd_ctl_file *ctl;
55 err = nonseekable_open(inode, file);
59 card = snd_lookup_minor_data(iminor(inode), SNDRV_DEVICE_TYPE_CONTROL);
64 err = snd_card_file_add(card, file);
69 if (!try_module_get(card->module)) {
73 ctl = kzalloc(sizeof(*ctl), GFP_KERNEL);
78 INIT_LIST_HEAD(&ctl->events);
79 init_waitqueue_head(&ctl->change_sleep);
80 spin_lock_init(&ctl->read_lock);
82 ctl->prefer_pcm_subdevice = -1;
83 ctl->prefer_rawmidi_subdevice = -1;
84 ctl->pid = get_pid(task_pid(current));
85 file->private_data = ctl;
86 write_lock_irqsave(&card->ctl_files_rwlock, flags);
87 list_add_tail(&ctl->list, &card->ctl_files);
88 write_unlock_irqrestore(&card->ctl_files_rwlock, flags);
93 module_put(card->module);
95 snd_card_file_remove(card, file);
102 static void snd_ctl_empty_read_queue(struct snd_ctl_file * ctl)
105 struct snd_kctl_event *cread;
107 spin_lock_irqsave(&ctl->read_lock, flags);
108 while (!list_empty(&ctl->events)) {
109 cread = snd_kctl_event(ctl->events.next);
110 list_del(&cread->list);
113 spin_unlock_irqrestore(&ctl->read_lock, flags);
116 static int snd_ctl_release(struct inode *inode, struct file *file)
119 struct snd_card *card;
120 struct snd_ctl_file *ctl;
121 struct snd_kcontrol *control;
124 ctl = file->private_data;
125 file->private_data = NULL;
127 write_lock_irqsave(&card->ctl_files_rwlock, flags);
128 list_del(&ctl->list);
129 write_unlock_irqrestore(&card->ctl_files_rwlock, flags);
130 down_write(&card->controls_rwsem);
131 list_for_each_entry(control, &card->controls, list)
132 for (idx = 0; idx < control->count; idx++)
133 if (control->vd[idx].owner == ctl)
134 control->vd[idx].owner = NULL;
135 up_write(&card->controls_rwsem);
136 snd_ctl_empty_read_queue(ctl);
139 module_put(card->module);
140 snd_card_file_remove(card, file);
144 void snd_ctl_notify(struct snd_card *card, unsigned int mask,
145 struct snd_ctl_elem_id *id)
148 struct snd_ctl_file *ctl;
149 struct snd_kctl_event *ev;
151 if (snd_BUG_ON(!card || !id))
153 read_lock(&card->ctl_files_rwlock);
154 #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
155 card->mixer_oss_change_count++;
157 list_for_each_entry(ctl, &card->ctl_files, list) {
158 if (!ctl->subscribed)
160 spin_lock_irqsave(&ctl->read_lock, flags);
161 list_for_each_entry(ev, &ctl->events, list) {
162 if (ev->id.numid == id->numid) {
167 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
171 list_add_tail(&ev->list, &ctl->events);
173 snd_printk(KERN_ERR "No memory available to allocate event\n");
176 wake_up(&ctl->change_sleep);
177 spin_unlock_irqrestore(&ctl->read_lock, flags);
178 kill_fasync(&ctl->fasync, SIGIO, POLL_IN);
180 read_unlock(&card->ctl_files_rwlock);
183 EXPORT_SYMBOL(snd_ctl_notify);
186 * snd_ctl_new - create a control instance from the template
187 * @control: the control template
188 * @access: the default control access
190 * Allocates a new struct snd_kcontrol instance and copies the given template
191 * to the new instance. It does not copy volatile data (access).
193 * Return: The pointer of the new instance, or %NULL on failure.
195 static struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control,
198 struct snd_kcontrol *kctl;
201 if (snd_BUG_ON(!control || !control->count))
204 if (control->count > MAX_CONTROL_COUNT)
207 kctl = kzalloc(sizeof(*kctl) + sizeof(struct snd_kcontrol_volatile) * control->count, GFP_KERNEL);
209 snd_printk(KERN_ERR "Cannot allocate control instance\n");
213 for (idx = 0; idx < kctl->count; idx++)
214 kctl->vd[idx].access = access;
219 * snd_ctl_new1 - create a control instance from the template
220 * @ncontrol: the initialization record
221 * @private_data: the private data to set
223 * Allocates a new struct snd_kcontrol instance and initialize from the given
224 * template. When the access field of ncontrol is 0, it's assumed as
225 * READWRITE access. When the count field is 0, it's assumes as one.
227 * Return: The pointer of the newly generated instance, or %NULL on failure.
229 struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol,
232 struct snd_kcontrol kctl;
235 if (snd_BUG_ON(!ncontrol || !ncontrol->info))
237 memset(&kctl, 0, sizeof(kctl));
238 kctl.id.iface = ncontrol->iface;
239 kctl.id.device = ncontrol->device;
240 kctl.id.subdevice = ncontrol->subdevice;
241 if (ncontrol->name) {
242 strlcpy(kctl.id.name, ncontrol->name, sizeof(kctl.id.name));
243 if (strcmp(ncontrol->name, kctl.id.name) != 0)
244 snd_printk(KERN_WARNING
245 "Control name '%s' truncated to '%s'\n",
246 ncontrol->name, kctl.id.name);
248 kctl.id.index = ncontrol->index;
249 kctl.count = ncontrol->count ? ncontrol->count : 1;
250 access = ncontrol->access == 0 ? SNDRV_CTL_ELEM_ACCESS_READWRITE :
251 (ncontrol->access & (SNDRV_CTL_ELEM_ACCESS_READWRITE|
252 SNDRV_CTL_ELEM_ACCESS_VOLATILE|
253 SNDRV_CTL_ELEM_ACCESS_INACTIVE|
254 SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE|
255 SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND|
256 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK));
257 kctl.info = ncontrol->info;
258 kctl.get = ncontrol->get;
259 kctl.put = ncontrol->put;
260 kctl.tlv.p = ncontrol->tlv.p;
261 kctl.private_value = ncontrol->private_value;
262 kctl.private_data = private_data;
263 return snd_ctl_new(&kctl, access);
266 EXPORT_SYMBOL(snd_ctl_new1);
269 * snd_ctl_free_one - release the control instance
270 * @kcontrol: the control instance
272 * Releases the control instance created via snd_ctl_new()
274 * Don't call this after the control was added to the card.
276 void snd_ctl_free_one(struct snd_kcontrol *kcontrol)
279 if (kcontrol->private_free)
280 kcontrol->private_free(kcontrol);
285 EXPORT_SYMBOL(snd_ctl_free_one);
287 static bool snd_ctl_remove_numid_conflict(struct snd_card *card,
290 struct snd_kcontrol *kctl;
292 /* Make sure that the ids assigned to the control do not wrap around */
293 if (card->last_numid >= UINT_MAX - count)
294 card->last_numid = 0;
296 list_for_each_entry(kctl, &card->controls, list) {
297 if (kctl->id.numid < card->last_numid + 1 + count &&
298 kctl->id.numid + kctl->count > card->last_numid + 1) {
299 card->last_numid = kctl->id.numid + kctl->count - 1;
306 static int snd_ctl_find_hole(struct snd_card *card, unsigned int count)
308 unsigned int iter = 100000;
310 while (snd_ctl_remove_numid_conflict(card, count)) {
312 /* this situation is very unlikely */
313 snd_printk(KERN_ERR "unable to allocate new control numid\n");
321 * snd_ctl_add - add the control instance to the card
322 * @card: the card instance
323 * @kcontrol: the control instance to add
325 * Adds the control instance created via snd_ctl_new() or
326 * snd_ctl_new1() to the given card. Assigns also an unique
327 * numid used for fast search.
329 * It frees automatically the control which cannot be added.
331 * Return: Zero if successful, or a negative error code on failure.
334 int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
336 struct snd_ctl_elem_id id;
343 if (snd_BUG_ON(!card || !kcontrol->info))
346 down_write(&card->controls_rwsem);
347 if (snd_ctl_find_id(card, &id)) {
348 up_write(&card->controls_rwsem);
349 snd_printd(KERN_ERR "control %i:%i:%i:%s:%i is already present\n",
358 if (snd_ctl_find_hole(card, kcontrol->count) < 0) {
359 up_write(&card->controls_rwsem);
363 list_add_tail(&kcontrol->list, &card->controls);
364 card->controls_count += kcontrol->count;
365 kcontrol->id.numid = card->last_numid + 1;
366 card->last_numid += kcontrol->count;
367 count = kcontrol->count;
368 up_write(&card->controls_rwsem);
369 for (idx = 0; idx < count; idx++, id.index++, id.numid++)
370 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_ADD, &id);
374 snd_ctl_free_one(kcontrol);
378 EXPORT_SYMBOL(snd_ctl_add);
381 * snd_ctl_replace - replace the control instance of the card
382 * @card: the card instance
383 * @kcontrol: the control instance to replace
384 * @add_on_replace: add the control if not already added
386 * Replaces the given control. If the given control does not exist
387 * and the add_on_replace flag is set, the control is added. If the
388 * control exists, it is destroyed first.
390 * It frees automatically the control which cannot be added or replaced.
392 * Return: Zero if successful, or a negative error code on failure.
394 int snd_ctl_replace(struct snd_card *card, struct snd_kcontrol *kcontrol,
397 struct snd_ctl_elem_id id;
400 struct snd_kcontrol *old;
405 if (snd_BUG_ON(!card || !kcontrol->info)) {
410 down_write(&card->controls_rwsem);
411 old = snd_ctl_find_id(card, &id);
415 up_write(&card->controls_rwsem);
419 ret = snd_ctl_remove(card, old);
421 up_write(&card->controls_rwsem);
425 if (snd_ctl_find_hole(card, kcontrol->count) < 0) {
426 up_write(&card->controls_rwsem);
430 list_add_tail(&kcontrol->list, &card->controls);
431 card->controls_count += kcontrol->count;
432 kcontrol->id.numid = card->last_numid + 1;
433 card->last_numid += kcontrol->count;
434 count = kcontrol->count;
435 up_write(&card->controls_rwsem);
436 for (idx = 0; idx < count; idx++, id.index++, id.numid++)
437 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_ADD, &id);
441 snd_ctl_free_one(kcontrol);
444 EXPORT_SYMBOL(snd_ctl_replace);
447 * snd_ctl_remove - remove the control from the card and release it
448 * @card: the card instance
449 * @kcontrol: the control instance to remove
451 * Removes the control from the card and then releases the instance.
452 * You don't need to call snd_ctl_free_one(). You must be in
453 * the write lock - down_write(&card->controls_rwsem).
455 * Return: 0 if successful, or a negative error code on failure.
457 int snd_ctl_remove(struct snd_card *card, struct snd_kcontrol *kcontrol)
459 struct snd_ctl_elem_id id;
462 if (snd_BUG_ON(!card || !kcontrol))
464 list_del(&kcontrol->list);
465 card->controls_count -= kcontrol->count;
467 for (idx = 0; idx < kcontrol->count; idx++, id.index++, id.numid++)
468 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_REMOVE, &id);
469 snd_ctl_free_one(kcontrol);
473 EXPORT_SYMBOL(snd_ctl_remove);
476 * snd_ctl_remove_id - remove the control of the given id and release it
477 * @card: the card instance
478 * @id: the control id to remove
480 * Finds the control instance with the given id, removes it from the
481 * card list and releases it.
483 * Return: 0 if successful, or a negative error code on failure.
485 int snd_ctl_remove_id(struct snd_card *card, struct snd_ctl_elem_id *id)
487 struct snd_kcontrol *kctl;
490 down_write(&card->controls_rwsem);
491 kctl = snd_ctl_find_id(card, id);
493 up_write(&card->controls_rwsem);
496 ret = snd_ctl_remove(card, kctl);
497 up_write(&card->controls_rwsem);
501 EXPORT_SYMBOL(snd_ctl_remove_id);
504 * snd_ctl_remove_user_ctl - remove and release the unlocked user control
505 * @file: active control handle
506 * @id: the control id to remove
508 * Finds the control instance with the given id, removes it from the
509 * card list and releases it.
511 * Return: 0 if successful, or a negative error code on failure.
513 static int snd_ctl_remove_user_ctl(struct snd_ctl_file * file,
514 struct snd_ctl_elem_id *id)
516 struct snd_card *card = file->card;
517 struct snd_kcontrol *kctl;
520 down_write(&card->controls_rwsem);
521 kctl = snd_ctl_find_id(card, id);
526 if (!(kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_USER)) {
530 for (idx = 0; idx < kctl->count; idx++)
531 if (kctl->vd[idx].owner != NULL && kctl->vd[idx].owner != file) {
535 ret = snd_ctl_remove(card, kctl);
538 card->user_ctl_count--;
540 up_write(&card->controls_rwsem);
545 * snd_ctl_activate_id - activate/inactivate the control of the given id
546 * @card: the card instance
547 * @id: the control id to activate/inactivate
548 * @active: non-zero to activate
550 * Finds the control instance with the given id, and activate or
551 * inactivate the control together with notification, if changed.
553 * Return: 0 if unchanged, 1 if changed, or a negative error code on failure.
555 int snd_ctl_activate_id(struct snd_card *card, struct snd_ctl_elem_id *id,
558 struct snd_kcontrol *kctl;
559 struct snd_kcontrol_volatile *vd;
560 unsigned int index_offset;
563 down_write(&card->controls_rwsem);
564 kctl = snd_ctl_find_id(card, id);
569 index_offset = snd_ctl_get_ioff(kctl, &kctl->id);
570 vd = &kctl->vd[index_offset];
573 if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_INACTIVE))
575 vd->access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
577 if (vd->access & SNDRV_CTL_ELEM_ACCESS_INACTIVE)
579 vd->access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
583 up_write(&card->controls_rwsem);
585 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO, id);
588 EXPORT_SYMBOL_GPL(snd_ctl_activate_id);
591 * snd_ctl_rename_id - replace the id of a control on the card
592 * @card: the card instance
593 * @src_id: the old id
594 * @dst_id: the new id
596 * Finds the control with the old id from the card, and replaces the
597 * id with the new one.
599 * Return: Zero if successful, or a negative error code on failure.
601 int snd_ctl_rename_id(struct snd_card *card, struct snd_ctl_elem_id *src_id,
602 struct snd_ctl_elem_id *dst_id)
604 struct snd_kcontrol *kctl;
606 down_write(&card->controls_rwsem);
607 kctl = snd_ctl_find_id(card, src_id);
609 up_write(&card->controls_rwsem);
613 kctl->id.numid = card->last_numid + 1;
614 card->last_numid += kctl->count;
615 up_write(&card->controls_rwsem);
619 EXPORT_SYMBOL(snd_ctl_rename_id);
622 * snd_ctl_find_numid - find the control instance with the given number-id
623 * @card: the card instance
624 * @numid: the number-id to search
626 * Finds the control instance with the given number-id from the card.
628 * The caller must down card->controls_rwsem before calling this function
629 * (if the race condition can happen).
631 * Return: The pointer of the instance if found, or %NULL if not.
634 struct snd_kcontrol *snd_ctl_find_numid(struct snd_card *card, unsigned int numid)
636 struct snd_kcontrol *kctl;
638 if (snd_BUG_ON(!card || !numid))
640 list_for_each_entry(kctl, &card->controls, list) {
641 if (kctl->id.numid <= numid && kctl->id.numid + kctl->count > numid)
647 EXPORT_SYMBOL(snd_ctl_find_numid);
650 * snd_ctl_find_id - find the control instance with the given id
651 * @card: the card instance
652 * @id: the id to search
654 * Finds the control instance with the given id from the card.
656 * The caller must down card->controls_rwsem before calling this function
657 * (if the race condition can happen).
659 * Return: The pointer of the instance if found, or %NULL if not.
662 struct snd_kcontrol *snd_ctl_find_id(struct snd_card *card,
663 struct snd_ctl_elem_id *id)
665 struct snd_kcontrol *kctl;
667 if (snd_BUG_ON(!card || !id))
670 return snd_ctl_find_numid(card, id->numid);
671 list_for_each_entry(kctl, &card->controls, list) {
672 if (kctl->id.iface != id->iface)
674 if (kctl->id.device != id->device)
676 if (kctl->id.subdevice != id->subdevice)
678 if (strncmp(kctl->id.name, id->name, sizeof(kctl->id.name)))
680 if (kctl->id.index > id->index)
682 if (kctl->id.index + kctl->count <= id->index)
689 EXPORT_SYMBOL(snd_ctl_find_id);
691 static int snd_ctl_card_info(struct snd_card *card, struct snd_ctl_file * ctl,
692 unsigned int cmd, void __user *arg)
694 struct snd_ctl_card_info *info;
696 info = kzalloc(sizeof(*info), GFP_KERNEL);
699 down_read(&snd_ioctl_rwsem);
700 info->card = card->number;
701 strlcpy(info->id, card->id, sizeof(info->id));
702 strlcpy(info->driver, card->driver, sizeof(info->driver));
703 strlcpy(info->name, card->shortname, sizeof(info->name));
704 strlcpy(info->longname, card->longname, sizeof(info->longname));
705 strlcpy(info->mixername, card->mixername, sizeof(info->mixername));
706 strlcpy(info->components, card->components, sizeof(info->components));
707 up_read(&snd_ioctl_rwsem);
708 if (copy_to_user(arg, info, sizeof(struct snd_ctl_card_info))) {
716 static int snd_ctl_elem_list(struct snd_card *card,
717 struct snd_ctl_elem_list __user *_list)
719 struct list_head *plist;
720 struct snd_ctl_elem_list list;
721 struct snd_kcontrol *kctl;
722 struct snd_ctl_elem_id *dst, *id;
723 unsigned int offset, space, jidx;
725 if (copy_from_user(&list, _list, sizeof(list)))
727 offset = list.offset;
729 /* try limit maximum space */
733 /* allocate temporary buffer for atomic operation */
734 dst = vmalloc(space * sizeof(struct snd_ctl_elem_id));
737 down_read(&card->controls_rwsem);
738 list.count = card->controls_count;
739 plist = card->controls.next;
740 while (plist != &card->controls) {
743 kctl = snd_kcontrol(plist);
744 if (offset < kctl->count)
746 offset -= kctl->count;
751 while (space > 0 && plist != &card->controls) {
752 kctl = snd_kcontrol(plist);
753 for (jidx = offset; space > 0 && jidx < kctl->count; jidx++) {
754 snd_ctl_build_ioff(id, kctl, jidx);
762 up_read(&card->controls_rwsem);
764 copy_to_user(list.pids, dst,
765 list.used * sizeof(struct snd_ctl_elem_id))) {
771 down_read(&card->controls_rwsem);
772 list.count = card->controls_count;
773 up_read(&card->controls_rwsem);
775 if (copy_to_user(_list, &list, sizeof(list)))
780 static int snd_ctl_elem_info(struct snd_ctl_file *ctl,
781 struct snd_ctl_elem_info *info)
783 struct snd_card *card = ctl->card;
784 struct snd_kcontrol *kctl;
785 struct snd_kcontrol_volatile *vd;
786 unsigned int index_offset;
789 down_read(&card->controls_rwsem);
790 kctl = snd_ctl_find_id(card, &info->id);
792 up_read(&card->controls_rwsem);
795 #ifdef CONFIG_SND_DEBUG
798 result = kctl->info(kctl, info);
800 snd_BUG_ON(info->access);
801 index_offset = snd_ctl_get_ioff(kctl, &info->id);
802 vd = &kctl->vd[index_offset];
803 snd_ctl_build_ioff(&info->id, kctl, index_offset);
804 info->access = vd->access;
806 info->access |= SNDRV_CTL_ELEM_ACCESS_LOCK;
807 if (vd->owner == ctl)
808 info->access |= SNDRV_CTL_ELEM_ACCESS_OWNER;
809 info->owner = pid_vnr(vd->owner->pid);
814 up_read(&card->controls_rwsem);
818 static int snd_ctl_elem_info_user(struct snd_ctl_file *ctl,
819 struct snd_ctl_elem_info __user *_info)
821 struct snd_ctl_elem_info info;
824 if (copy_from_user(&info, _info, sizeof(info)))
826 snd_power_lock(ctl->card);
827 result = snd_power_wait(ctl->card, SNDRV_CTL_POWER_D0);
829 result = snd_ctl_elem_info(ctl, &info);
830 snd_power_unlock(ctl->card);
832 if (copy_to_user(_info, &info, sizeof(info)))
837 static int snd_ctl_elem_read(struct snd_card *card,
838 struct snd_ctl_elem_value *control)
840 struct snd_kcontrol *kctl;
841 struct snd_kcontrol_volatile *vd;
842 unsigned int index_offset;
845 down_read(&card->controls_rwsem);
846 kctl = snd_ctl_find_id(card, &control->id);
850 index_offset = snd_ctl_get_ioff(kctl, &control->id);
851 vd = &kctl->vd[index_offset];
852 if ((vd->access & SNDRV_CTL_ELEM_ACCESS_READ) &&
854 snd_ctl_build_ioff(&control->id, kctl, index_offset);
855 result = kctl->get(kctl, control);
859 up_read(&card->controls_rwsem);
863 static int snd_ctl_elem_read_user(struct snd_card *card,
864 struct snd_ctl_elem_value __user *_control)
866 struct snd_ctl_elem_value *control;
869 control = memdup_user(_control, sizeof(*control));
871 return PTR_ERR(control);
873 snd_power_lock(card);
874 result = snd_power_wait(card, SNDRV_CTL_POWER_D0);
876 result = snd_ctl_elem_read(card, control);
877 snd_power_unlock(card);
879 if (copy_to_user(_control, control, sizeof(*control)))
885 static int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file,
886 struct snd_ctl_elem_value *control)
888 struct snd_kcontrol *kctl;
889 struct snd_kcontrol_volatile *vd;
890 unsigned int index_offset;
893 down_read(&card->controls_rwsem);
894 kctl = snd_ctl_find_id(card, &control->id);
898 index_offset = snd_ctl_get_ioff(kctl, &control->id);
899 vd = &kctl->vd[index_offset];
900 if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_WRITE) ||
902 (file && vd->owner && vd->owner != file)) {
905 snd_ctl_build_ioff(&control->id, kctl, index_offset);
906 result = kctl->put(kctl, control);
909 struct snd_ctl_elem_id id = control->id;
910 up_read(&card->controls_rwsem);
911 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &id);
915 up_read(&card->controls_rwsem);
919 static int snd_ctl_elem_write_user(struct snd_ctl_file *file,
920 struct snd_ctl_elem_value __user *_control)
922 struct snd_ctl_elem_value *control;
923 struct snd_card *card;
926 control = memdup_user(_control, sizeof(*control));
928 return PTR_ERR(control);
931 snd_power_lock(card);
932 result = snd_power_wait(card, SNDRV_CTL_POWER_D0);
934 result = snd_ctl_elem_write(card, file, control);
935 snd_power_unlock(card);
937 if (copy_to_user(_control, control, sizeof(*control)))
943 static int snd_ctl_elem_lock(struct snd_ctl_file *file,
944 struct snd_ctl_elem_id __user *_id)
946 struct snd_card *card = file->card;
947 struct snd_ctl_elem_id id;
948 struct snd_kcontrol *kctl;
949 struct snd_kcontrol_volatile *vd;
952 if (copy_from_user(&id, _id, sizeof(id)))
954 down_write(&card->controls_rwsem);
955 kctl = snd_ctl_find_id(card, &id);
959 vd = &kctl->vd[snd_ctl_get_ioff(kctl, &id)];
960 if (vd->owner != NULL)
967 up_write(&card->controls_rwsem);
971 static int snd_ctl_elem_unlock(struct snd_ctl_file *file,
972 struct snd_ctl_elem_id __user *_id)
974 struct snd_card *card = file->card;
975 struct snd_ctl_elem_id id;
976 struct snd_kcontrol *kctl;
977 struct snd_kcontrol_volatile *vd;
980 if (copy_from_user(&id, _id, sizeof(id)))
982 down_write(&card->controls_rwsem);
983 kctl = snd_ctl_find_id(card, &id);
987 vd = &kctl->vd[snd_ctl_get_ioff(kctl, &id)];
988 if (vd->owner == NULL)
990 else if (vd->owner != file)
997 up_write(&card->controls_rwsem);
1001 struct user_element {
1002 struct snd_ctl_elem_info info;
1003 struct snd_card *card;
1004 void *elem_data; /* element data */
1005 unsigned long elem_data_size; /* size of element data in bytes */
1006 void *tlv_data; /* TLV data */
1007 unsigned long tlv_data_size; /* TLV data size */
1008 void *priv_data; /* private data (like strings for enumerated type) */
1011 static int snd_ctl_elem_user_info(struct snd_kcontrol *kcontrol,
1012 struct snd_ctl_elem_info *uinfo)
1014 struct user_element *ue = kcontrol->private_data;
1020 static int snd_ctl_elem_user_enum_info(struct snd_kcontrol *kcontrol,
1021 struct snd_ctl_elem_info *uinfo)
1023 struct user_element *ue = kcontrol->private_data;
1027 item = uinfo->value.enumerated.item;
1031 item = min(item, uinfo->value.enumerated.items - 1);
1032 uinfo->value.enumerated.item = item;
1034 names = ue->priv_data;
1035 for (; item > 0; --item)
1036 names += strlen(names) + 1;
1037 strcpy(uinfo->value.enumerated.name, names);
1042 static int snd_ctl_elem_user_get(struct snd_kcontrol *kcontrol,
1043 struct snd_ctl_elem_value *ucontrol)
1045 struct user_element *ue = kcontrol->private_data;
1047 mutex_lock(&ue->card->user_ctl_lock);
1048 memcpy(&ucontrol->value, ue->elem_data, ue->elem_data_size);
1049 mutex_unlock(&ue->card->user_ctl_lock);
1053 static int snd_ctl_elem_user_put(struct snd_kcontrol *kcontrol,
1054 struct snd_ctl_elem_value *ucontrol)
1057 struct user_element *ue = kcontrol->private_data;
1059 mutex_lock(&ue->card->user_ctl_lock);
1060 change = memcmp(&ucontrol->value, ue->elem_data, ue->elem_data_size) != 0;
1062 memcpy(ue->elem_data, &ucontrol->value, ue->elem_data_size);
1063 mutex_unlock(&ue->card->user_ctl_lock);
1067 static int snd_ctl_elem_user_tlv(struct snd_kcontrol *kcontrol,
1070 unsigned int __user *tlv)
1072 struct user_element *ue = kcontrol->private_data;
1077 if (size > 1024 * 128) /* sane value */
1080 new_data = memdup_user(tlv, size);
1081 if (IS_ERR(new_data))
1082 return PTR_ERR(new_data);
1083 mutex_lock(&ue->card->user_ctl_lock);
1084 change = ue->tlv_data_size != size;
1086 change = memcmp(ue->tlv_data, new_data, size);
1087 kfree(ue->tlv_data);
1088 ue->tlv_data = new_data;
1089 ue->tlv_data_size = size;
1090 mutex_unlock(&ue->card->user_ctl_lock);
1094 mutex_lock(&ue->card->user_ctl_lock);
1095 if (!ue->tlv_data_size || !ue->tlv_data) {
1099 if (size < ue->tlv_data_size) {
1103 if (copy_to_user(tlv, ue->tlv_data, ue->tlv_data_size))
1106 mutex_unlock(&ue->card->user_ctl_lock);
1113 static int snd_ctl_elem_init_enum_names(struct user_element *ue)
1116 size_t buf_len, name_len;
1118 const uintptr_t user_ptrval = ue->info.value.enumerated.names_ptr;
1120 if (ue->info.value.enumerated.names_length > 64 * 1024)
1123 names = memdup_user((const void __user *)user_ptrval,
1124 ue->info.value.enumerated.names_length);
1126 return PTR_ERR(names);
1128 /* check that there are enough valid names */
1129 buf_len = ue->info.value.enumerated.names_length;
1131 for (i = 0; i < ue->info.value.enumerated.items; ++i) {
1132 name_len = strnlen(p, buf_len);
1133 if (name_len == 0 || name_len >= 64 || name_len == buf_len) {
1138 buf_len -= name_len + 1;
1141 ue->priv_data = names;
1142 ue->info.value.enumerated.names_ptr = 0;
1147 static void snd_ctl_elem_user_free(struct snd_kcontrol *kcontrol)
1149 struct user_element *ue = kcontrol->private_data;
1151 kfree(ue->tlv_data);
1152 kfree(ue->priv_data);
1156 static int snd_ctl_elem_add(struct snd_ctl_file *file,
1157 struct snd_ctl_elem_info *info, int replace)
1159 struct snd_card *card = file->card;
1160 struct snd_kcontrol kctl, *_kctl;
1161 unsigned int access;
1163 struct user_element *ue;
1166 if (info->count < 1)
1168 access = info->access == 0 ? SNDRV_CTL_ELEM_ACCESS_READWRITE :
1169 (info->access & (SNDRV_CTL_ELEM_ACCESS_READWRITE|
1170 SNDRV_CTL_ELEM_ACCESS_INACTIVE|
1171 SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE));
1173 memset(&kctl, 0, sizeof(kctl));
1176 err = snd_ctl_remove_user_ctl(file, &info->id);
1181 if (card->user_ctl_count >= MAX_USER_CONTROLS)
1184 memcpy(&kctl.id, &info->id, sizeof(info->id));
1185 kctl.count = info->owner ? info->owner : 1;
1186 access |= SNDRV_CTL_ELEM_ACCESS_USER;
1187 if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED)
1188 kctl.info = snd_ctl_elem_user_enum_info;
1190 kctl.info = snd_ctl_elem_user_info;
1191 if (access & SNDRV_CTL_ELEM_ACCESS_READ)
1192 kctl.get = snd_ctl_elem_user_get;
1193 if (access & SNDRV_CTL_ELEM_ACCESS_WRITE)
1194 kctl.put = snd_ctl_elem_user_put;
1195 if (access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) {
1196 kctl.tlv.c = snd_ctl_elem_user_tlv;
1197 access |= SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
1199 switch (info->type) {
1200 case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
1201 case SNDRV_CTL_ELEM_TYPE_INTEGER:
1202 private_size = sizeof(long);
1203 if (info->count > 128)
1206 case SNDRV_CTL_ELEM_TYPE_INTEGER64:
1207 private_size = sizeof(long long);
1208 if (info->count > 64)
1211 case SNDRV_CTL_ELEM_TYPE_ENUMERATED:
1212 private_size = sizeof(unsigned int);
1213 if (info->count > 128 || info->value.enumerated.items == 0)
1216 case SNDRV_CTL_ELEM_TYPE_BYTES:
1217 private_size = sizeof(unsigned char);
1218 if (info->count > 512)
1221 case SNDRV_CTL_ELEM_TYPE_IEC958:
1222 private_size = sizeof(struct snd_aes_iec958);
1223 if (info->count != 1)
1229 private_size *= info->count;
1230 ue = kzalloc(sizeof(struct user_element) + private_size, GFP_KERNEL);
1235 ue->info.access = 0;
1236 ue->elem_data = (char *)ue + sizeof(*ue);
1237 ue->elem_data_size = private_size;
1238 if (ue->info.type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) {
1239 err = snd_ctl_elem_init_enum_names(ue);
1245 kctl.private_free = snd_ctl_elem_user_free;
1246 _kctl = snd_ctl_new(&kctl, access);
1247 if (_kctl == NULL) {
1248 kfree(ue->priv_data);
1252 _kctl->private_data = ue;
1253 for (idx = 0; idx < _kctl->count; idx++)
1254 _kctl->vd[idx].owner = file;
1255 err = snd_ctl_add(card, _kctl);
1259 down_write(&card->controls_rwsem);
1260 card->user_ctl_count++;
1261 up_write(&card->controls_rwsem);
1266 static int snd_ctl_elem_add_user(struct snd_ctl_file *file,
1267 struct snd_ctl_elem_info __user *_info, int replace)
1269 struct snd_ctl_elem_info info;
1270 if (copy_from_user(&info, _info, sizeof(info)))
1272 return snd_ctl_elem_add(file, &info, replace);
1275 static int snd_ctl_elem_remove(struct snd_ctl_file *file,
1276 struct snd_ctl_elem_id __user *_id)
1278 struct snd_ctl_elem_id id;
1280 if (copy_from_user(&id, _id, sizeof(id)))
1282 return snd_ctl_remove_user_ctl(file, &id);
1285 static int snd_ctl_subscribe_events(struct snd_ctl_file *file, int __user *ptr)
1288 if (get_user(subscribe, ptr))
1290 if (subscribe < 0) {
1291 subscribe = file->subscribed;
1292 if (put_user(subscribe, ptr))
1297 file->subscribed = 1;
1299 } else if (file->subscribed) {
1300 snd_ctl_empty_read_queue(file);
1301 file->subscribed = 0;
1306 static int snd_ctl_tlv_ioctl(struct snd_ctl_file *file,
1307 struct snd_ctl_tlv __user *_tlv,
1310 struct snd_card *card = file->card;
1311 struct snd_ctl_tlv tlv;
1312 struct snd_kcontrol *kctl;
1313 struct snd_kcontrol_volatile *vd;
1317 if (copy_from_user(&tlv, _tlv, sizeof(tlv)))
1319 if (tlv.length < sizeof(unsigned int) * 2)
1321 down_read(&card->controls_rwsem);
1322 kctl = snd_ctl_find_numid(card, tlv.numid);
1327 if (kctl->tlv.p == NULL) {
1331 vd = &kctl->vd[tlv.numid - kctl->id.numid];
1332 if ((op_flag == 0 && (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ) == 0) ||
1333 (op_flag > 0 && (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) == 0) ||
1334 (op_flag < 0 && (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND) == 0)) {
1338 if (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) {
1339 if (vd->owner != NULL && vd->owner != file) {
1343 err = kctl->tlv.c(kctl, op_flag, tlv.length, _tlv->tlv);
1345 struct snd_ctl_elem_id id = kctl->id;
1346 up_read(&card->controls_rwsem);
1347 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_TLV, &id);
1355 len = kctl->tlv.p[1] + 2 * sizeof(unsigned int);
1356 if (tlv.length < len) {
1360 if (copy_to_user(_tlv->tlv, kctl->tlv.p, len))
1364 up_read(&card->controls_rwsem);
1368 static long snd_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1370 struct snd_ctl_file *ctl;
1371 struct snd_card *card;
1372 struct snd_kctl_ioctl *p;
1373 void __user *argp = (void __user *)arg;
1374 int __user *ip = argp;
1377 ctl = file->private_data;
1379 if (snd_BUG_ON(!card))
1382 case SNDRV_CTL_IOCTL_PVERSION:
1383 return put_user(SNDRV_CTL_VERSION, ip) ? -EFAULT : 0;
1384 case SNDRV_CTL_IOCTL_CARD_INFO:
1385 return snd_ctl_card_info(card, ctl, cmd, argp);
1386 case SNDRV_CTL_IOCTL_ELEM_LIST:
1387 return snd_ctl_elem_list(card, argp);
1388 case SNDRV_CTL_IOCTL_ELEM_INFO:
1389 return snd_ctl_elem_info_user(ctl, argp);
1390 case SNDRV_CTL_IOCTL_ELEM_READ:
1391 return snd_ctl_elem_read_user(card, argp);
1392 case SNDRV_CTL_IOCTL_ELEM_WRITE:
1393 return snd_ctl_elem_write_user(ctl, argp);
1394 case SNDRV_CTL_IOCTL_ELEM_LOCK:
1395 return snd_ctl_elem_lock(ctl, argp);
1396 case SNDRV_CTL_IOCTL_ELEM_UNLOCK:
1397 return snd_ctl_elem_unlock(ctl, argp);
1398 case SNDRV_CTL_IOCTL_ELEM_ADD:
1399 return snd_ctl_elem_add_user(ctl, argp, 0);
1400 case SNDRV_CTL_IOCTL_ELEM_REPLACE:
1401 return snd_ctl_elem_add_user(ctl, argp, 1);
1402 case SNDRV_CTL_IOCTL_ELEM_REMOVE:
1403 return snd_ctl_elem_remove(ctl, argp);
1404 case SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS:
1405 return snd_ctl_subscribe_events(ctl, ip);
1406 case SNDRV_CTL_IOCTL_TLV_READ:
1407 return snd_ctl_tlv_ioctl(ctl, argp, 0);
1408 case SNDRV_CTL_IOCTL_TLV_WRITE:
1409 return snd_ctl_tlv_ioctl(ctl, argp, 1);
1410 case SNDRV_CTL_IOCTL_TLV_COMMAND:
1411 return snd_ctl_tlv_ioctl(ctl, argp, -1);
1412 case SNDRV_CTL_IOCTL_POWER:
1413 return -ENOPROTOOPT;
1414 case SNDRV_CTL_IOCTL_POWER_STATE:
1416 return put_user(card->power_state, ip) ? -EFAULT : 0;
1418 return put_user(SNDRV_CTL_POWER_D0, ip) ? -EFAULT : 0;
1421 down_read(&snd_ioctl_rwsem);
1422 list_for_each_entry(p, &snd_control_ioctls, list) {
1423 err = p->fioctl(card, ctl, cmd, arg);
1424 if (err != -ENOIOCTLCMD) {
1425 up_read(&snd_ioctl_rwsem);
1429 up_read(&snd_ioctl_rwsem);
1430 snd_printdd("unknown ioctl = 0x%x\n", cmd);
1434 static ssize_t snd_ctl_read(struct file *file, char __user *buffer,
1435 size_t count, loff_t * offset)
1437 struct snd_ctl_file *ctl;
1441 ctl = file->private_data;
1442 if (snd_BUG_ON(!ctl || !ctl->card))
1444 if (!ctl->subscribed)
1446 if (count < sizeof(struct snd_ctl_event))
1448 spin_lock_irq(&ctl->read_lock);
1449 while (count >= sizeof(struct snd_ctl_event)) {
1450 struct snd_ctl_event ev;
1451 struct snd_kctl_event *kev;
1452 while (list_empty(&ctl->events)) {
1454 if ((file->f_flags & O_NONBLOCK) != 0 || result > 0) {
1458 init_waitqueue_entry(&wait, current);
1459 add_wait_queue(&ctl->change_sleep, &wait);
1460 set_current_state(TASK_INTERRUPTIBLE);
1461 spin_unlock_irq(&ctl->read_lock);
1463 remove_wait_queue(&ctl->change_sleep, &wait);
1464 if (ctl->card->shutdown)
1466 if (signal_pending(current))
1467 return -ERESTARTSYS;
1468 spin_lock_irq(&ctl->read_lock);
1470 kev = snd_kctl_event(ctl->events.next);
1471 ev.type = SNDRV_CTL_EVENT_ELEM;
1472 ev.data.elem.mask = kev->mask;
1473 ev.data.elem.id = kev->id;
1474 list_del(&kev->list);
1475 spin_unlock_irq(&ctl->read_lock);
1477 if (copy_to_user(buffer, &ev, sizeof(struct snd_ctl_event))) {
1481 spin_lock_irq(&ctl->read_lock);
1482 buffer += sizeof(struct snd_ctl_event);
1483 count -= sizeof(struct snd_ctl_event);
1484 result += sizeof(struct snd_ctl_event);
1487 spin_unlock_irq(&ctl->read_lock);
1489 return result > 0 ? result : err;
1492 static unsigned int snd_ctl_poll(struct file *file, poll_table * wait)
1495 struct snd_ctl_file *ctl;
1497 ctl = file->private_data;
1498 if (!ctl->subscribed)
1500 poll_wait(file, &ctl->change_sleep, wait);
1503 if (!list_empty(&ctl->events))
1504 mask |= POLLIN | POLLRDNORM;
1510 * register the device-specific control-ioctls.
1511 * called from each device manager like pcm.c, hwdep.c, etc.
1513 static int _snd_ctl_register_ioctl(snd_kctl_ioctl_func_t fcn, struct list_head *lists)
1515 struct snd_kctl_ioctl *pn;
1517 pn = kzalloc(sizeof(struct snd_kctl_ioctl), GFP_KERNEL);
1521 down_write(&snd_ioctl_rwsem);
1522 list_add_tail(&pn->list, lists);
1523 up_write(&snd_ioctl_rwsem);
1527 int snd_ctl_register_ioctl(snd_kctl_ioctl_func_t fcn)
1529 return _snd_ctl_register_ioctl(fcn, &snd_control_ioctls);
1532 EXPORT_SYMBOL(snd_ctl_register_ioctl);
1534 #ifdef CONFIG_COMPAT
1535 int snd_ctl_register_ioctl_compat(snd_kctl_ioctl_func_t fcn)
1537 return _snd_ctl_register_ioctl(fcn, &snd_control_compat_ioctls);
1540 EXPORT_SYMBOL(snd_ctl_register_ioctl_compat);
1544 * de-register the device-specific control-ioctls.
1546 static int _snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn,
1547 struct list_head *lists)
1549 struct snd_kctl_ioctl *p;
1551 if (snd_BUG_ON(!fcn))
1553 down_write(&snd_ioctl_rwsem);
1554 list_for_each_entry(p, lists, list) {
1555 if (p->fioctl == fcn) {
1557 up_write(&snd_ioctl_rwsem);
1562 up_write(&snd_ioctl_rwsem);
1567 int snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn)
1569 return _snd_ctl_unregister_ioctl(fcn, &snd_control_ioctls);
1572 EXPORT_SYMBOL(snd_ctl_unregister_ioctl);
1574 #ifdef CONFIG_COMPAT
1575 int snd_ctl_unregister_ioctl_compat(snd_kctl_ioctl_func_t fcn)
1577 return _snd_ctl_unregister_ioctl(fcn, &snd_control_compat_ioctls);
1580 EXPORT_SYMBOL(snd_ctl_unregister_ioctl_compat);
1583 static int snd_ctl_fasync(int fd, struct file * file, int on)
1585 struct snd_ctl_file *ctl;
1587 ctl = file->private_data;
1588 return fasync_helper(fd, file, on, &ctl->fasync);
1594 #ifdef CONFIG_COMPAT
1595 #include "control_compat.c"
1597 #define snd_ctl_ioctl_compat NULL
1604 static const struct file_operations snd_ctl_f_ops =
1606 .owner = THIS_MODULE,
1607 .read = snd_ctl_read,
1608 .open = snd_ctl_open,
1609 .release = snd_ctl_release,
1610 .llseek = no_llseek,
1611 .poll = snd_ctl_poll,
1612 .unlocked_ioctl = snd_ctl_ioctl,
1613 .compat_ioctl = snd_ctl_ioctl_compat,
1614 .fasync = snd_ctl_fasync,
1618 * registration of the control device
1620 static int snd_ctl_dev_register(struct snd_device *device)
1622 struct snd_card *card = device->device_data;
1626 if (snd_BUG_ON(!card))
1628 cardnum = card->number;
1629 if (snd_BUG_ON(cardnum < 0 || cardnum >= SNDRV_CARDS))
1631 sprintf(name, "controlC%i", cardnum);
1632 if ((err = snd_register_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1,
1633 &snd_ctl_f_ops, card, name)) < 0)
1639 * disconnection of the control device
1641 static int snd_ctl_dev_disconnect(struct snd_device *device)
1643 struct snd_card *card = device->device_data;
1644 struct snd_ctl_file *ctl;
1647 if (snd_BUG_ON(!card))
1649 cardnum = card->number;
1650 if (snd_BUG_ON(cardnum < 0 || cardnum >= SNDRV_CARDS))
1653 read_lock(&card->ctl_files_rwlock);
1654 list_for_each_entry(ctl, &card->ctl_files, list) {
1655 wake_up(&ctl->change_sleep);
1656 kill_fasync(&ctl->fasync, SIGIO, POLL_ERR);
1658 read_unlock(&card->ctl_files_rwlock);
1660 if ((err = snd_unregister_device(SNDRV_DEVICE_TYPE_CONTROL,
1669 static int snd_ctl_dev_free(struct snd_device *device)
1671 struct snd_card *card = device->device_data;
1672 struct snd_kcontrol *control;
1674 down_write(&card->controls_rwsem);
1675 while (!list_empty(&card->controls)) {
1676 control = snd_kcontrol(card->controls.next);
1677 snd_ctl_remove(card, control);
1679 up_write(&card->controls_rwsem);
1684 * create control core:
1685 * called from init.c
1687 int snd_ctl_create(struct snd_card *card)
1689 static struct snd_device_ops ops = {
1690 .dev_free = snd_ctl_dev_free,
1691 .dev_register = snd_ctl_dev_register,
1692 .dev_disconnect = snd_ctl_dev_disconnect,
1695 if (snd_BUG_ON(!card))
1697 return snd_device_new(card, SNDRV_DEV_CONTROL, card, &ops);
1701 * Frequently used control callbacks/helpers
1703 int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol,
1704 struct snd_ctl_elem_info *uinfo)
1706 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1708 uinfo->value.integer.min = 0;
1709 uinfo->value.integer.max = 1;
1713 EXPORT_SYMBOL(snd_ctl_boolean_mono_info);
1715 int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol,
1716 struct snd_ctl_elem_info *uinfo)
1718 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1720 uinfo->value.integer.min = 0;
1721 uinfo->value.integer.max = 1;
1725 EXPORT_SYMBOL(snd_ctl_boolean_stereo_info);
1728 * snd_ctl_enum_info - fills the info structure for an enumerated control
1729 * @info: the structure to be filled
1730 * @channels: the number of the control's channels; often one
1731 * @items: the number of control values; also the size of @names
1732 * @names: an array containing the names of all control values
1734 * Sets all required fields in @info to their appropriate values.
1735 * If the control's accessibility is not the default (readable and writable),
1736 * the caller has to fill @info->access.
1740 int snd_ctl_enum_info(struct snd_ctl_elem_info *info, unsigned int channels,
1741 unsigned int items, const char *const names[])
1743 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1744 info->count = channels;
1745 info->value.enumerated.items = items;
1746 if (info->value.enumerated.item >= items)
1747 info->value.enumerated.item = items - 1;
1748 strlcpy(info->value.enumerated.name,
1749 names[info->value.enumerated.item],
1750 sizeof(info->value.enumerated.name));
1753 EXPORT_SYMBOL(snd_ctl_enum_info);