ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / sound / control.h
1 #ifndef __SOUND_CONTROL_H
2 #define __SOUND_CONTROL_H
3
4 /*
5  *  Header file for control interface
6  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
7  *
8  *
9  *   This program is free software; you can redistribute it and/or modify
10  *   it under the terms of the GNU General Public License as published by
11  *   the Free Software Foundation; either version 2 of the License, or
12  *   (at your option) any later version.
13  *
14  *   This program is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with this program; if not, write to the Free Software
21  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22  *
23  */
24
25 #include <sound/asound.h>
26
27 typedef struct sndrv_aes_iec958 snd_aes_iec958_t;
28 typedef struct sndrv_ctl_card_info snd_ctl_card_info_t;
29 typedef enum sndrv_ctl_elem_type snd_ctl_elem_type_t;
30 typedef enum sndrv_ctl_elem_iface snd_ctl_elem_iface_t;
31 typedef struct sndrv_ctl_elem_id snd_ctl_elem_id_t;
32 typedef struct sndrv_ctl_elem_list snd_ctl_elem_list_t;
33 typedef struct sndrv_ctl_elem_info snd_ctl_elem_info_t;
34 typedef struct sndrv_ctl_elem_value snd_ctl_elem_value_t;
35 typedef enum sndrv_ctl_event_type snd_ctl_event_type_t;
36 typedef struct sndrv_ctl_event snd_ctl_event_t;
37
38 #define _snd_kcontrol_chip(kcontrol) ((kcontrol)->private_data)
39 #define snd_kcontrol_chip(kcontrol) snd_magic_cast1(chip_t, _snd_kcontrol_chip(kcontrol), return -ENXIO)
40
41 typedef int (snd_kcontrol_info_t) (snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo);
42 typedef int (snd_kcontrol_get_t) (snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol);
43 typedef int (snd_kcontrol_put_t) (snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol);
44
45 typedef struct _snd_kcontrol_new {
46         snd_ctl_elem_iface_t iface;     /* interface identifier */
47         unsigned int device;            /* device/client number */
48         unsigned int subdevice;         /* subdevice (substream) number */
49         unsigned char *name;            /* ASCII name of item */
50         unsigned int index;             /* index of item */
51         unsigned int access;            /* access rights */
52         unsigned int count;             /* count of same elements */
53         snd_kcontrol_info_t *info;
54         snd_kcontrol_get_t *get;
55         snd_kcontrol_put_t *put;
56         unsigned long private_value;
57 } snd_kcontrol_new_t;
58
59 typedef struct _snd_kcontrol_volatile {
60         snd_ctl_file_t *owner;  /* locked */
61         pid_t owner_pid;
62         unsigned int access;    /* access rights */
63 } snd_kcontrol_volatile_t;
64
65 struct _snd_kcontrol {
66         struct list_head list;          /* list of controls */
67         snd_ctl_elem_id_t id;
68         unsigned int count;             /* count of same elements */
69         snd_kcontrol_info_t *info;
70         snd_kcontrol_get_t *get;
71         snd_kcontrol_put_t *put;
72         unsigned long private_value;
73         void *private_data;
74         void (*private_free)(snd_kcontrol_t *kcontrol);
75         snd_kcontrol_volatile_t vd[0];  /* volatile data */
76 };
77
78 #define snd_kcontrol(n) list_entry(n, snd_kcontrol_t, list)
79
80 typedef struct _snd_kctl_event {
81         struct list_head list;  /* list of events */
82         snd_ctl_elem_id_t id;
83         unsigned int mask;
84 } snd_kctl_event_t;
85
86 #define snd_kctl_event(n) list_entry(n, snd_kctl_event_t, list)
87
88 struct _snd_ctl_file {
89         struct list_head list;          /* list of all control files */
90         snd_card_t *card;
91         pid_t pid;
92         int prefer_pcm_subdevice;
93         int prefer_rawmidi_subdevice;
94         wait_queue_head_t change_sleep;
95         spinlock_t read_lock;
96         struct fasync_struct *fasync;
97         int subscribed;                 /* read interface is activated */
98         struct list_head events;        /* waiting events for read */
99 };
100
101 #define snd_ctl_file(n) list_entry(n, snd_ctl_file_t, list)
102
103 typedef int (*snd_kctl_ioctl_func_t) (snd_card_t * card,
104                                  snd_ctl_file_t * control,
105                                  unsigned int cmd, unsigned long arg);
106
107 void snd_ctl_notify(snd_card_t * card, unsigned int mask, snd_ctl_elem_id_t * id);
108
109 snd_kcontrol_t *snd_ctl_new(snd_kcontrol_t * kcontrol, unsigned int access);
110 snd_kcontrol_t *snd_ctl_new1(snd_kcontrol_new_t * kcontrolnew, void * private_data);
111 void snd_ctl_free_one(snd_kcontrol_t * kcontrol);
112 int snd_ctl_add(snd_card_t * card, snd_kcontrol_t * kcontrol);
113 int snd_ctl_remove(snd_card_t * card, snd_kcontrol_t * kcontrol);
114 int snd_ctl_remove_id(snd_card_t * card, snd_ctl_elem_id_t *id);
115 int snd_ctl_rename_id(snd_card_t * card, snd_ctl_elem_id_t *src_id, snd_ctl_elem_id_t *dst_id);
116 snd_kcontrol_t *snd_ctl_find_numid(snd_card_t * card, unsigned int numid);
117 snd_kcontrol_t *snd_ctl_find_id(snd_card_t * card, snd_ctl_elem_id_t *id);
118
119 int snd_ctl_register(snd_card_t *card);
120 int snd_ctl_disconnect(snd_card_t *card);
121 int snd_ctl_can_unregister(snd_card_t *card);
122 int snd_ctl_unregister(snd_card_t *card);
123 int snd_ctl_register_ioctl(snd_kctl_ioctl_func_t fcn);
124 int snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn);
125
126 static inline unsigned int snd_ctl_get_ioffnum(snd_kcontrol_t *kctl, snd_ctl_elem_id_t *id)
127 {
128         return id->numid - kctl->id.numid;
129 }
130
131 static inline unsigned int snd_ctl_get_ioffidx(snd_kcontrol_t *kctl, snd_ctl_elem_id_t *id)
132 {
133         return id->index - kctl->id.index;
134 }
135
136 static inline unsigned int snd_ctl_get_ioff(snd_kcontrol_t *kctl, snd_ctl_elem_id_t *id)
137 {
138         if (id->numid) {
139                 return snd_ctl_get_ioffnum(kctl, id);
140         } else {
141                 return snd_ctl_get_ioffidx(kctl, id);
142         }
143 }
144
145 static inline snd_ctl_elem_id_t *snd_ctl_build_ioff(snd_ctl_elem_id_t *dst_id,
146                                                     snd_kcontrol_t *src_kctl,
147                                                     unsigned int offset)
148 {
149         *dst_id = src_kctl->id;
150         dst_id->index += offset;
151         dst_id->numid += offset;
152         return dst_id;
153 }
154
155 #endif  /* __SOUND_CONTROL_H */