control.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #ifndef __SOUND_CONTROL_H
  2. #define __SOUND_CONTROL_H
  3. /*
  4. * Header file for control interface
  5. * Copyright (c) by Jaroslav Kysela <perex@suse.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. struct snd_kcontrol_new {
  30. snd_ctl_elem_iface_t iface; /* interface identifier */
  31. unsigned int device; /* device/client number */
  32. unsigned int subdevice; /* subdevice (substream) number */
  33. unsigned char *name; /* ASCII name of item */
  34. unsigned int index; /* index of item */
  35. unsigned int access; /* access rights */
  36. unsigned int count; /* count of same elements */
  37. snd_kcontrol_info_t *info;
  38. snd_kcontrol_get_t *get;
  39. snd_kcontrol_put_t *put;
  40. unsigned long private_value;
  41. };
  42. struct snd_kcontrol_volatile {
  43. struct snd_ctl_file *owner; /* locked */
  44. pid_t owner_pid;
  45. unsigned int access; /* access rights */
  46. };
  47. struct snd_kcontrol {
  48. struct list_head list; /* list of controls */
  49. struct snd_ctl_elem_id id;
  50. unsigned int count; /* count of same elements */
  51. snd_kcontrol_info_t *info;
  52. snd_kcontrol_get_t *get;
  53. snd_kcontrol_put_t *put;
  54. unsigned long private_value;
  55. void *private_data;
  56. void (*private_free)(struct snd_kcontrol *kcontrol);
  57. struct snd_kcontrol_volatile vd[0]; /* volatile data */
  58. };
  59. #define snd_kcontrol(n) list_entry(n, struct snd_kcontrol, list)
  60. struct snd_kctl_event {
  61. struct list_head list; /* list of events */
  62. struct snd_ctl_elem_id id;
  63. unsigned int mask;
  64. };
  65. #define snd_kctl_event(n) list_entry(n, struct snd_kctl_event, list)
  66. struct snd_ctl_file {
  67. struct list_head list; /* list of all control files */
  68. struct snd_card *card;
  69. pid_t pid;
  70. int prefer_pcm_subdevice;
  71. int prefer_rawmidi_subdevice;
  72. wait_queue_head_t change_sleep;
  73. spinlock_t read_lock;
  74. struct fasync_struct *fasync;
  75. int subscribed; /* read interface is activated */
  76. struct list_head events; /* waiting events for read */
  77. };
  78. #define snd_ctl_file(n) list_entry(n, struct snd_ctl_file, list)
  79. typedef int (*snd_kctl_ioctl_func_t) (struct snd_card * card,
  80. struct snd_ctl_file * control,
  81. unsigned int cmd, unsigned long arg);
  82. void snd_ctl_notify(struct snd_card * card, unsigned int mask, struct snd_ctl_elem_id * id);
  83. struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol * kcontrol, unsigned int access);
  84. struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new * kcontrolnew, void * private_data);
  85. void snd_ctl_free_one(struct snd_kcontrol * kcontrol);
  86. int snd_ctl_add(struct snd_card * card, struct snd_kcontrol * kcontrol);
  87. int snd_ctl_remove(struct snd_card * card, struct snd_kcontrol * kcontrol);
  88. int snd_ctl_remove_id(struct snd_card * card, struct snd_ctl_elem_id *id);
  89. int snd_ctl_rename_id(struct snd_card * card, struct snd_ctl_elem_id *src_id, struct snd_ctl_elem_id *dst_id);
  90. struct snd_kcontrol *snd_ctl_find_numid(struct snd_card * card, unsigned int numid);
  91. struct snd_kcontrol *snd_ctl_find_id(struct snd_card * card, struct snd_ctl_elem_id *id);
  92. int snd_ctl_create(struct snd_card *card);
  93. int snd_ctl_register_ioctl(snd_kctl_ioctl_func_t fcn);
  94. int snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn);
  95. #ifdef CONFIG_COMPAT
  96. int snd_ctl_register_ioctl_compat(snd_kctl_ioctl_func_t fcn);
  97. int snd_ctl_unregister_ioctl_compat(snd_kctl_ioctl_func_t fcn);
  98. #else
  99. #define snd_ctl_register_ioctl_compat(fcn)
  100. #define snd_ctl_unregister_ioctl_compat(fcn)
  101. #endif
  102. int snd_ctl_elem_read(struct snd_card *card, struct snd_ctl_elem_value *control);
  103. int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file, struct snd_ctl_elem_value *control);
  104. static inline unsigned int snd_ctl_get_ioffnum(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id)
  105. {
  106. return id->numid - kctl->id.numid;
  107. }
  108. static inline unsigned int snd_ctl_get_ioffidx(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id)
  109. {
  110. return id->index - kctl->id.index;
  111. }
  112. static inline unsigned int snd_ctl_get_ioff(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id)
  113. {
  114. if (id->numid) {
  115. return snd_ctl_get_ioffnum(kctl, id);
  116. } else {
  117. return snd_ctl_get_ioffidx(kctl, id);
  118. }
  119. }
  120. static inline struct snd_ctl_elem_id *snd_ctl_build_ioff(struct snd_ctl_elem_id *dst_id,
  121. struct snd_kcontrol *src_kctl,
  122. unsigned int offset)
  123. {
  124. *dst_id = src_kctl->id;
  125. dst_id->index += offset;
  126. dst_id->numid += offset;
  127. return dst_id;
  128. }
  129. #endif /* __SOUND_CONTROL_H */