11da177e4SLinus Torvalds #ifndef __SOUND_CONTROL_H 21da177e4SLinus Torvalds #define __SOUND_CONTROL_H 31da177e4SLinus Torvalds 41da177e4SLinus Torvalds /* 51da177e4SLinus Torvalds * Header file for control interface 6c1017a4cSJaroslav Kysela * Copyright (c) by Jaroslav Kysela <perex@perex.cz> 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 101da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 111da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 121da177e4SLinus Torvalds * (at your option) any later version. 131da177e4SLinus Torvalds * 141da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, 151da177e4SLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 161da177e4SLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 171da177e4SLinus Torvalds * GNU General Public License for more details. 181da177e4SLinus Torvalds * 191da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 201da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 211da177e4SLinus Torvalds * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 221da177e4SLinus Torvalds * 231da177e4SLinus Torvalds */ 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds #include <sound/asound.h> 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds #define snd_kcontrol_chip(kcontrol) ((kcontrol)->private_data) 281da177e4SLinus Torvalds 2982e9bae6STakashi Iwai struct snd_kcontrol; 3082e9bae6STakashi Iwai typedef int (snd_kcontrol_info_t) (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_info * uinfo); 3182e9bae6STakashi Iwai typedef int (snd_kcontrol_get_t) (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol); 3282e9bae6STakashi Iwai typedef int (snd_kcontrol_put_t) (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol); 338aa9b586SJaroslav Kysela typedef int (snd_kcontrol_tlv_rw_t)(struct snd_kcontrol *kcontrol, 348aa9b586SJaroslav Kysela int op_flag, /* 0=read,1=write,-1=command */ 358aa9b586SJaroslav Kysela unsigned int size, 368aa9b586SJaroslav Kysela unsigned int __user *tlv); 378aa9b586SJaroslav Kysela 381da177e4SLinus Torvalds 3982e9bae6STakashi Iwai struct snd_kcontrol_new { 401da177e4SLinus Torvalds snd_ctl_elem_iface_t iface; /* interface identifier */ 411da177e4SLinus Torvalds unsigned int device; /* device/client number */ 421da177e4SLinus Torvalds unsigned int subdevice; /* subdevice (substream) number */ 431da177e4SLinus Torvalds unsigned char *name; /* ASCII name of item */ 441da177e4SLinus Torvalds unsigned int index; /* index of item */ 451da177e4SLinus Torvalds unsigned int access; /* access rights */ 461da177e4SLinus Torvalds unsigned int count; /* count of same elements */ 471da177e4SLinus Torvalds snd_kcontrol_info_t *info; 481da177e4SLinus Torvalds snd_kcontrol_get_t *get; 491da177e4SLinus Torvalds snd_kcontrol_put_t *put; 508aa9b586SJaroslav Kysela union { 518aa9b586SJaroslav Kysela snd_kcontrol_tlv_rw_t *c; 520cb29ea0STakashi Iwai const unsigned int *p; 538aa9b586SJaroslav Kysela } tlv; 541da177e4SLinus Torvalds unsigned long private_value; 5582e9bae6STakashi Iwai }; 561da177e4SLinus Torvalds 5782e9bae6STakashi Iwai struct snd_kcontrol_volatile { 5882e9bae6STakashi Iwai struct snd_ctl_file *owner; /* locked */ 591da177e4SLinus Torvalds unsigned int access; /* access rights */ 6082e9bae6STakashi Iwai }; 611da177e4SLinus Torvalds 6282e9bae6STakashi Iwai struct snd_kcontrol { 631da177e4SLinus Torvalds struct list_head list; /* list of controls */ 6482e9bae6STakashi Iwai struct snd_ctl_elem_id id; 651da177e4SLinus Torvalds unsigned int count; /* count of same elements */ 661da177e4SLinus Torvalds snd_kcontrol_info_t *info; 671da177e4SLinus Torvalds snd_kcontrol_get_t *get; 681da177e4SLinus Torvalds snd_kcontrol_put_t *put; 698aa9b586SJaroslav Kysela union { 708aa9b586SJaroslav Kysela snd_kcontrol_tlv_rw_t *c; 710cb29ea0STakashi Iwai const unsigned int *p; 728aa9b586SJaroslav Kysela } tlv; 731da177e4SLinus Torvalds unsigned long private_value; 741da177e4SLinus Torvalds void *private_data; 7582e9bae6STakashi Iwai void (*private_free)(struct snd_kcontrol *kcontrol); 7682e9bae6STakashi Iwai struct snd_kcontrol_volatile vd[0]; /* volatile data */ 771da177e4SLinus Torvalds }; 781da177e4SLinus Torvalds 7982e9bae6STakashi Iwai #define snd_kcontrol(n) list_entry(n, struct snd_kcontrol, list) 801da177e4SLinus Torvalds 8182e9bae6STakashi Iwai struct snd_kctl_event { 821da177e4SLinus Torvalds struct list_head list; /* list of events */ 8382e9bae6STakashi Iwai struct snd_ctl_elem_id id; 841da177e4SLinus Torvalds unsigned int mask; 8582e9bae6STakashi Iwai }; 861da177e4SLinus Torvalds 8782e9bae6STakashi Iwai #define snd_kctl_event(n) list_entry(n, struct snd_kctl_event, list) 881da177e4SLinus Torvalds 8925d27edeSClemens Ladisch struct pid; 9025d27edeSClemens Ladisch 9182e9bae6STakashi Iwai struct snd_ctl_file { 921da177e4SLinus Torvalds struct list_head list; /* list of all control files */ 9382e9bae6STakashi Iwai struct snd_card *card; 9425d27edeSClemens Ladisch struct pid *pid; 951da177e4SLinus Torvalds int prefer_pcm_subdevice; 961da177e4SLinus Torvalds int prefer_rawmidi_subdevice; 971da177e4SLinus Torvalds wait_queue_head_t change_sleep; 981da177e4SLinus Torvalds spinlock_t read_lock; 991da177e4SLinus Torvalds struct fasync_struct *fasync; 1001da177e4SLinus Torvalds int subscribed; /* read interface is activated */ 1011da177e4SLinus Torvalds struct list_head events; /* waiting events for read */ 1021da177e4SLinus Torvalds }; 1031da177e4SLinus Torvalds 10482e9bae6STakashi Iwai #define snd_ctl_file(n) list_entry(n, struct snd_ctl_file, list) 1051da177e4SLinus Torvalds 10682e9bae6STakashi Iwai typedef int (*snd_kctl_ioctl_func_t) (struct snd_card * card, 10782e9bae6STakashi Iwai struct snd_ctl_file * control, 1081da177e4SLinus Torvalds unsigned int cmd, unsigned long arg); 1091da177e4SLinus Torvalds 11082e9bae6STakashi Iwai void snd_ctl_notify(struct snd_card * card, unsigned int mask, struct snd_ctl_elem_id * id); 1111da177e4SLinus Torvalds 11282e9bae6STakashi Iwai struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new * kcontrolnew, void * private_data); 11382e9bae6STakashi Iwai void snd_ctl_free_one(struct snd_kcontrol * kcontrol); 11482e9bae6STakashi Iwai int snd_ctl_add(struct snd_card * card, struct snd_kcontrol * kcontrol); 11582e9bae6STakashi Iwai int snd_ctl_remove(struct snd_card * card, struct snd_kcontrol * kcontrol); 11666b5b972SDimitris Papastamos int snd_ctl_replace(struct snd_card *card, struct snd_kcontrol *kcontrol, bool add_on_replace); 11782e9bae6STakashi Iwai int snd_ctl_remove_id(struct snd_card * card, struct snd_ctl_elem_id *id); 11882e9bae6STakashi Iwai int snd_ctl_rename_id(struct snd_card * card, struct snd_ctl_elem_id *src_id, struct snd_ctl_elem_id *dst_id); 1193cbdd753STakashi Iwai int snd_ctl_activate_id(struct snd_card *card, struct snd_ctl_elem_id *id, 1203cbdd753STakashi Iwai int active); 12182e9bae6STakashi Iwai struct snd_kcontrol *snd_ctl_find_numid(struct snd_card * card, unsigned int numid); 12282e9bae6STakashi Iwai struct snd_kcontrol *snd_ctl_find_id(struct snd_card * card, struct snd_ctl_elem_id *id); 1231da177e4SLinus Torvalds 12482e9bae6STakashi Iwai int snd_ctl_create(struct snd_card *card); 1251da177e4SLinus Torvalds 1261da177e4SLinus Torvalds int snd_ctl_register_ioctl(snd_kctl_ioctl_func_t fcn); 1271da177e4SLinus Torvalds int snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn); 1281da177e4SLinus Torvalds #ifdef CONFIG_COMPAT 1291da177e4SLinus Torvalds int snd_ctl_register_ioctl_compat(snd_kctl_ioctl_func_t fcn); 1301da177e4SLinus Torvalds int snd_ctl_unregister_ioctl_compat(snd_kctl_ioctl_func_t fcn); 1311da177e4SLinus Torvalds #else 1321da177e4SLinus Torvalds #define snd_ctl_register_ioctl_compat(fcn) 1331da177e4SLinus Torvalds #define snd_ctl_unregister_ioctl_compat(fcn) 1341da177e4SLinus Torvalds #endif 1351da177e4SLinus Torvalds 13682e9bae6STakashi Iwai static inline unsigned int snd_ctl_get_ioffnum(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id) 1371da177e4SLinus Torvalds { 1381da177e4SLinus Torvalds return id->numid - kctl->id.numid; 1391da177e4SLinus Torvalds } 1401da177e4SLinus Torvalds 14182e9bae6STakashi Iwai static inline unsigned int snd_ctl_get_ioffidx(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id) 1421da177e4SLinus Torvalds { 1431da177e4SLinus Torvalds return id->index - kctl->id.index; 1441da177e4SLinus Torvalds } 1451da177e4SLinus Torvalds 14682e9bae6STakashi Iwai static inline unsigned int snd_ctl_get_ioff(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id) 1471da177e4SLinus Torvalds { 1481da177e4SLinus Torvalds if (id->numid) { 1491da177e4SLinus Torvalds return snd_ctl_get_ioffnum(kctl, id); 1501da177e4SLinus Torvalds } else { 1511da177e4SLinus Torvalds return snd_ctl_get_ioffidx(kctl, id); 1521da177e4SLinus Torvalds } 1531da177e4SLinus Torvalds } 1541da177e4SLinus Torvalds 15582e9bae6STakashi Iwai static inline struct snd_ctl_elem_id *snd_ctl_build_ioff(struct snd_ctl_elem_id *dst_id, 15682e9bae6STakashi Iwai struct snd_kcontrol *src_kctl, 1571da177e4SLinus Torvalds unsigned int offset) 1581da177e4SLinus Torvalds { 1591da177e4SLinus Torvalds *dst_id = src_kctl->id; 1601da177e4SLinus Torvalds dst_id->index += offset; 1611da177e4SLinus Torvalds dst_id->numid += offset; 1621da177e4SLinus Torvalds return dst_id; 1631da177e4SLinus Torvalds } 1641da177e4SLinus Torvalds 165b9ed4f2bSTakashi Iwai /* 1669600732bSClemens Ladisch * Frequently used control callbacks/helpers 167b9ed4f2bSTakashi Iwai */ 168b9ed4f2bSTakashi Iwai int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol, 169b9ed4f2bSTakashi Iwai struct snd_ctl_elem_info *uinfo); 170b9ed4f2bSTakashi Iwai int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol, 171b9ed4f2bSTakashi Iwai struct snd_ctl_elem_info *uinfo); 1729600732bSClemens Ladisch int snd_ctl_enum_info(struct snd_ctl_elem_info *info, unsigned int channels, 1739600732bSClemens Ladisch unsigned int items, const char *const names[]); 174b9ed4f2bSTakashi Iwai 175e922b002STakashi Iwai /* 176e922b002STakashi Iwai * virtual master control 177e922b002STakashi Iwai */ 178e922b002STakashi Iwai struct snd_kcontrol *snd_ctl_make_virtual_master(char *name, 179e922b002STakashi Iwai const unsigned int *tlv); 180f5b1db63STakashi Iwai int _snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave, 181f5b1db63STakashi Iwai unsigned int flags); 182f5b1db63STakashi Iwai /* optional flags for slave */ 183f5b1db63STakashi Iwai #define SND_CTL_SLAVE_NEED_UPDATE (1 << 0) 184f5b1db63STakashi Iwai 18579c7cdd5STakashi Iwai /** 18679c7cdd5STakashi Iwai * snd_ctl_add_slave - Add a virtual slave control 18779c7cdd5STakashi Iwai * @master: vmaster element 18879c7cdd5STakashi Iwai * @slave: slave element to add 18979c7cdd5STakashi Iwai * 19079c7cdd5STakashi Iwai * Add a virtual slave control to the given master element created via 19179c7cdd5STakashi Iwai * snd_ctl_create_virtual_master() beforehand. 19279c7cdd5STakashi Iwai * Returns zero if successful or a negative error code. 19379c7cdd5STakashi Iwai * 19479c7cdd5STakashi Iwai * All slaves must be the same type (returning the same information 19525985edcSLucas De Marchi * via info callback). The function doesn't check it, so it's your 19679c7cdd5STakashi Iwai * responsibility. 19779c7cdd5STakashi Iwai * 19879c7cdd5STakashi Iwai * Also, some additional limitations: 19979c7cdd5STakashi Iwai * at most two channels, 20079c7cdd5STakashi Iwai * logarithmic volume control (dB level) thus no linear volume, 20179c7cdd5STakashi Iwai * master can only attenuate the volume without gain 20279c7cdd5STakashi Iwai */ 203f5b1db63STakashi Iwai static inline int 204f5b1db63STakashi Iwai snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave) 205f5b1db63STakashi Iwai { 206f5b1db63STakashi Iwai return _snd_ctl_add_slave(master, slave, 0); 207f5b1db63STakashi Iwai } 208f5b1db63STakashi Iwai 20979c7cdd5STakashi Iwai /** 21079c7cdd5STakashi Iwai * snd_ctl_add_slave_uncached - Add a virtual slave control 21179c7cdd5STakashi Iwai * @master: vmaster element 21279c7cdd5STakashi Iwai * @slave: slave element to add 21379c7cdd5STakashi Iwai * 21479c7cdd5STakashi Iwai * Add a virtual slave control to the given master. 21579c7cdd5STakashi Iwai * Unlike snd_ctl_add_slave(), the element added via this function 21679c7cdd5STakashi Iwai * is supposed to have volatile values, and get callback is called 21779c7cdd5STakashi Iwai * at each time quried from the master. 21879c7cdd5STakashi Iwai * 21979c7cdd5STakashi Iwai * When the control peeks the hardware values directly and the value 22079c7cdd5STakashi Iwai * can be changed by other means than the put callback of the element, 22179c7cdd5STakashi Iwai * this function should be used to keep the value always up-to-date. 22279c7cdd5STakashi Iwai */ 223f5b1db63STakashi Iwai static inline int 224f5b1db63STakashi Iwai snd_ctl_add_slave_uncached(struct snd_kcontrol *master, 225f5b1db63STakashi Iwai struct snd_kcontrol *slave) 226f5b1db63STakashi Iwai { 227f5b1db63STakashi Iwai return _snd_ctl_add_slave(master, slave, SND_CTL_SLAVE_NEED_UPDATE); 228f5b1db63STakashi Iwai } 229e922b002STakashi Iwai 23035be544aSTakashi Iwai /* 23135be544aSTakashi Iwai * Helper functions for jack-detection controls 23235be544aSTakashi Iwai */ 23335be544aSTakashi Iwai struct snd_kcontrol * 23435be544aSTakashi Iwai snd_kctl_jack_new(const char *name, int idx, void *private_data); 23535be544aSTakashi Iwai void snd_kctl_jack_report(struct snd_card *card, 23635be544aSTakashi Iwai struct snd_kcontrol *kctl, bool status); 23735be544aSTakashi Iwai 2381da177e4SLinus Torvalds #endif /* __SOUND_CONTROL_H */ 239