control.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #ifndef __SOUND_CONTROL_H
  2. #define __SOUND_CONTROL_H
  3. /*
  4. * Header file for control interface
  5. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <sound/asound.h>
  24. #define snd_kcontrol_chip(kcontrol) ((kcontrol)->private_data)
  25. struct snd_kcontrol;
  26. typedef int (snd_kcontrol_info_t) (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_info * uinfo);
  27. typedef int (snd_kcontrol_get_t) (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol);
  28. typedef int (snd_kcontrol_put_t) (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol);
  29. typedef int (snd_kcontrol_tlv_rw_t)(struct snd_kcontrol *kcontrol,
  30. int op_flag, /* 0=read,1=write,-1=command */
  31. unsigned int size,
  32. unsigned int __user *tlv);
  33. struct snd_kcontrol_new {
  34. snd_ctl_elem_iface_t iface; /* interface identifier */
  35. unsigned int device; /* device/client number */
  36. unsigned int subdevice; /* subdevice (substream) number */
  37. unsigned char *name; /* ASCII name of item */
  38. unsigned int index; /* index of item */
  39. unsigned int access; /* access rights */
  40. unsigned int count; /* count of same elements */
  41. snd_kcontrol_info_t *info;
  42. snd_kcontrol_get_t *get;
  43. snd_kcontrol_put_t *put;
  44. union {
  45. snd_kcontrol_tlv_rw_t *c;
  46. const unsigned int *p;
  47. } tlv;
  48. unsigned long private_value;
  49. };
  50. struct snd_kcontrol_volatile {
  51. struct snd_ctl_file *owner; /* locked */
  52. unsigned int access; /* access rights */
  53. };
  54. struct snd_kcontrol {
  55. struct list_head list; /* list of controls */
  56. struct snd_ctl_elem_id id;
  57. unsigned int count; /* count of same elements */
  58. snd_kcontrol_info_t *info;
  59. snd_kcontrol_get_t *get;
  60. snd_kcontrol_put_t *put;
  61. union {
  62. snd_kcontrol_tlv_rw_t *c;
  63. const unsigned int *p;
  64. } tlv;
  65. unsigned long private_value;
  66. void *private_data;
  67. void (*private_free)(struct snd_kcontrol *kcontrol);
  68. struct snd_kcontrol_volatile vd[0]; /* volatile data */
  69. };
  70. #define snd_kcontrol(n) list_entry(n, struct snd_kcontrol, list)
  71. struct snd_kctl_event {
  72. struct list_head list; /* list of events */
  73. struct snd_ctl_elem_id id;
  74. unsigned int mask;
  75. };
  76. #define snd_kctl_event(n) list_entry(n, struct snd_kctl_event, list)
  77. struct snd_ctl_file {
  78. struct list_head list; /* list of all control files */
  79. struct snd_card *card;
  80. pid_t pid;
  81. int prefer_pcm_subdevice;
  82. int prefer_rawmidi_subdevice;
  83. wait_queue_head_t change_sleep;
  84. spinlock_t read_lock;
  85. struct fasync_struct *fasync;
  86. int subscribed; /* read interface is activated */
  87. struct list_head events; /* waiting events for read */
  88. };
  89. #define snd_ctl_file(n) list_entry(n, struct snd_ctl_file, list)
  90. typedef int (*snd_kctl_ioctl_func_t) (struct snd_card * card,
  91. struct snd_ctl_file * control,
  92. unsigned int cmd, unsigned long arg);
  93. void snd_ctl_notify(struct snd_card * card, unsigned int mask, struct snd_ctl_elem_id * id);
  94. struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new * kcontrolnew, void * private_data);
  95. void snd_ctl_free_one(struct snd_kcontrol * kcontrol);
  96. int snd_ctl_add(struct snd_card * card, struct snd_kcontrol * kcontrol);
  97. int snd_ctl_remove(struct snd_card * card, struct snd_kcontrol * kcontrol);
  98. int snd_ctl_remove_id(struct snd_card * card, struct snd_ctl_elem_id *id);
  99. int snd_ctl_rename_id(struct snd_card * card, struct snd_ctl_elem_id *src_id, struct snd_ctl_elem_id *dst_id);
  100. struct snd_kcontrol *snd_ctl_find_numid(struct snd_card * card, unsigned int numid);
  101. struct snd_kcontrol *snd_ctl_find_id(struct snd_card * card, struct snd_ctl_elem_id *id);
  102. int snd_ctl_create(struct snd_card *card);
  103. int snd_ctl_register_ioctl(snd_kctl_ioctl_func_t fcn);
  104. int snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn);
  105. #ifdef CONFIG_COMPAT
  106. int snd_ctl_register_ioctl_compat(snd_kctl_ioctl_func_t fcn);
  107. int snd_ctl_unregister_ioctl_compat(snd_kctl_ioctl_func_t fcn);
  108. #else
  109. #define snd_ctl_register_ioctl_compat(fcn)
  110. #define snd_ctl_unregister_ioctl_compat(fcn)
  111. #endif
  112. static inline unsigned int snd_ctl_get_ioffnum(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id)
  113. {
  114. return id->numid - kctl->id.numid;
  115. }
  116. static inline unsigned int snd_ctl_get_ioffidx(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id)
  117. {
  118. return id->index - kctl->id.index;
  119. }
  120. static inline unsigned int snd_ctl_get_ioff(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id)
  121. {
  122. if (id->numid) {
  123. return snd_ctl_get_ioffnum(kctl, id);
  124. } else {
  125. return snd_ctl_get_ioffidx(kctl, id);
  126. }
  127. }
  128. static inline struct snd_ctl_elem_id *snd_ctl_build_ioff(struct snd_ctl_elem_id *dst_id,
  129. struct snd_kcontrol *src_kctl,
  130. unsigned int offset)
  131. {
  132. *dst_id = src_kctl->id;
  133. dst_id->index += offset;
  134. dst_id->numid += offset;
  135. return dst_id;
  136. }
  137. /*
  138. * Frequently used control callbacks
  139. */
  140. int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol,
  141. struct snd_ctl_elem_info *uinfo);
  142. int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol,
  143. struct snd_ctl_elem_info *uinfo);
  144. /*
  145. * virtual master control
  146. */
  147. struct snd_kcontrol *snd_ctl_make_virtual_master(char *name,
  148. const unsigned int *tlv);
  149. int _snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave,
  150. unsigned int flags);
  151. /* optional flags for slave */
  152. #define SND_CTL_SLAVE_NEED_UPDATE (1 << 0)
  153. /**
  154. * snd_ctl_add_slave - Add a virtual slave control
  155. * @master: vmaster element
  156. * @slave: slave element to add
  157. *
  158. * Add a virtual slave control to the given master element created via
  159. * snd_ctl_create_virtual_master() beforehand.
  160. * Returns zero if successful or a negative error code.
  161. *
  162. * All slaves must be the same type (returning the same information
  163. * via info callback). The fucntion doesn't check it, so it's your
  164. * responsibility.
  165. *
  166. * Also, some additional limitations:
  167. * at most two channels,
  168. * logarithmic volume control (dB level) thus no linear volume,
  169. * master can only attenuate the volume without gain
  170. */
  171. static inline int
  172. snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave)
  173. {
  174. return _snd_ctl_add_slave(master, slave, 0);
  175. }
  176. /**
  177. * snd_ctl_add_slave_uncached - Add a virtual slave control
  178. * @master: vmaster element
  179. * @slave: slave element to add
  180. *
  181. * Add a virtual slave control to the given master.
  182. * Unlike snd_ctl_add_slave(), the element added via this function
  183. * is supposed to have volatile values, and get callback is called
  184. * at each time quried from the master.
  185. *
  186. * When the control peeks the hardware values directly and the value
  187. * can be changed by other means than the put callback of the element,
  188. * this function should be used to keep the value always up-to-date.
  189. */
  190. static inline int
  191. snd_ctl_add_slave_uncached(struct snd_kcontrol *master,
  192. struct snd_kcontrol *slave)
  193. {
  194. return _snd_ctl_add_slave(master, slave, SND_CTL_SLAVE_NEED_UPDATE);
  195. }
  196. #endif /* __SOUND_CONTROL_H */