Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * OSS emulation layer for the mixer interface | |
3 | * Copyright (c) by Jaroslav Kysela <perex@suse.cz> | |
4 | * | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
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 | |
19 | * | |
20 | */ | |
21 | ||
22 | #include <sound/driver.h> | |
23 | #include <linux/init.h> | |
24 | #include <linux/smp_lock.h> | |
25 | #include <linux/slab.h> | |
26 | #include <linux/time.h> | |
543537bd | 27 | #include <linux/string.h> |
1da177e4 LT |
28 | #include <sound/core.h> |
29 | #include <sound/minors.h> | |
30 | #include <sound/control.h> | |
31 | #include <sound/info.h> | |
32 | #include <sound/mixer_oss.h> | |
33 | #include <linux/soundcard.h> | |
34 | ||
35 | #define OSS_ALSAEMULVER _SIOR ('M', 249, int) | |
36 | ||
37 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); | |
38 | MODULE_DESCRIPTION("Mixer OSS emulation for ALSA."); | |
39 | MODULE_LICENSE("GPL"); | |
40 | MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_MIXER); | |
41 | ||
42 | static int snd_mixer_oss_open(struct inode *inode, struct file *file) | |
43 | { | |
f956b4a3 TI |
44 | struct snd_card *card; |
45 | struct snd_mixer_oss_file *fmixer; | |
1da177e4 LT |
46 | int err; |
47 | ||
f87135f5 CL |
48 | card = snd_lookup_oss_minor_data(iminor(inode), |
49 | SNDRV_OSS_DEVICE_TYPE_MIXER); | |
50 | if (card == NULL) | |
1da177e4 LT |
51 | return -ENODEV; |
52 | if (card->mixer_oss == NULL) | |
53 | return -ENODEV; | |
54 | err = snd_card_file_add(card, file); | |
55 | if (err < 0) | |
56 | return err; | |
ca2c0966 | 57 | fmixer = kzalloc(sizeof(*fmixer), GFP_KERNEL); |
1da177e4 LT |
58 | if (fmixer == NULL) { |
59 | snd_card_file_remove(card, file); | |
60 | return -ENOMEM; | |
61 | } | |
62 | fmixer->card = card; | |
63 | fmixer->mixer = card->mixer_oss; | |
64 | file->private_data = fmixer; | |
65 | if (!try_module_get(card->module)) { | |
66 | kfree(fmixer); | |
67 | snd_card_file_remove(card, file); | |
68 | return -EFAULT; | |
69 | } | |
70 | return 0; | |
71 | } | |
72 | ||
73 | static int snd_mixer_oss_release(struct inode *inode, struct file *file) | |
74 | { | |
f956b4a3 | 75 | struct snd_mixer_oss_file *fmixer; |
1da177e4 LT |
76 | |
77 | if (file->private_data) { | |
f956b4a3 | 78 | fmixer = (struct snd_mixer_oss_file *) file->private_data; |
1da177e4 LT |
79 | module_put(fmixer->card->module); |
80 | snd_card_file_remove(fmixer->card, file); | |
81 | kfree(fmixer); | |
82 | } | |
83 | return 0; | |
84 | } | |
85 | ||
f956b4a3 | 86 | static int snd_mixer_oss_info(struct snd_mixer_oss_file *fmixer, |
1da177e4 LT |
87 | mixer_info __user *_info) |
88 | { | |
f956b4a3 TI |
89 | struct snd_card *card = fmixer->card; |
90 | struct snd_mixer_oss *mixer = fmixer->mixer; | |
1da177e4 LT |
91 | struct mixer_info info; |
92 | ||
93 | memset(&info, 0, sizeof(info)); | |
94 | strlcpy(info.id, mixer && mixer->id[0] ? mixer->id : card->driver, sizeof(info.id)); | |
95 | strlcpy(info.name, mixer && mixer->name[0] ? mixer->name : card->mixername, sizeof(info.name)); | |
96 | info.modify_counter = card->mixer_oss_change_count; | |
97 | if (copy_to_user(_info, &info, sizeof(info))) | |
98 | return -EFAULT; | |
99 | return 0; | |
100 | } | |
101 | ||
f956b4a3 | 102 | static int snd_mixer_oss_info_obsolete(struct snd_mixer_oss_file *fmixer, |
1da177e4 LT |
103 | _old_mixer_info __user *_info) |
104 | { | |
f956b4a3 TI |
105 | struct snd_card *card = fmixer->card; |
106 | struct snd_mixer_oss *mixer = fmixer->mixer; | |
1da177e4 LT |
107 | _old_mixer_info info; |
108 | ||
109 | memset(&info, 0, sizeof(info)); | |
110 | strlcpy(info.id, mixer && mixer->id[0] ? mixer->id : card->driver, sizeof(info.id)); | |
111 | strlcpy(info.name, mixer && mixer->name[0] ? mixer->name : card->mixername, sizeof(info.name)); | |
112 | if (copy_to_user(_info, &info, sizeof(info))) | |
113 | return -EFAULT; | |
114 | return 0; | |
115 | } | |
116 | ||
f956b4a3 | 117 | static int snd_mixer_oss_caps(struct snd_mixer_oss_file *fmixer) |
1da177e4 | 118 | { |
f956b4a3 | 119 | struct snd_mixer_oss *mixer = fmixer->mixer; |
1da177e4 LT |
120 | int result = 0; |
121 | ||
122 | if (mixer == NULL) | |
123 | return -EIO; | |
124 | if (mixer->get_recsrc && mixer->put_recsrc) | |
125 | result |= SOUND_CAP_EXCL_INPUT; | |
126 | return result; | |
127 | } | |
128 | ||
f956b4a3 | 129 | static int snd_mixer_oss_devmask(struct snd_mixer_oss_file *fmixer) |
1da177e4 | 130 | { |
f956b4a3 TI |
131 | struct snd_mixer_oss *mixer = fmixer->mixer; |
132 | struct snd_mixer_oss_slot *pslot; | |
1da177e4 LT |
133 | int result = 0, chn; |
134 | ||
135 | if (mixer == NULL) | |
136 | return -EIO; | |
137 | for (chn = 0; chn < 31; chn++) { | |
138 | pslot = &mixer->slots[chn]; | |
139 | if (pslot->put_volume || pslot->put_recsrc) | |
140 | result |= 1 << chn; | |
141 | } | |
142 | return result; | |
143 | } | |
144 | ||
f956b4a3 | 145 | static int snd_mixer_oss_stereodevs(struct snd_mixer_oss_file *fmixer) |
1da177e4 | 146 | { |
f956b4a3 TI |
147 | struct snd_mixer_oss *mixer = fmixer->mixer; |
148 | struct snd_mixer_oss_slot *pslot; | |
1da177e4 LT |
149 | int result = 0, chn; |
150 | ||
151 | if (mixer == NULL) | |
152 | return -EIO; | |
153 | for (chn = 0; chn < 31; chn++) { | |
154 | pslot = &mixer->slots[chn]; | |
155 | if (pslot->put_volume && pslot->stereo) | |
156 | result |= 1 << chn; | |
157 | } | |
158 | return result; | |
159 | } | |
160 | ||
f956b4a3 | 161 | static int snd_mixer_oss_recmask(struct snd_mixer_oss_file *fmixer) |
1da177e4 | 162 | { |
f956b4a3 | 163 | struct snd_mixer_oss *mixer = fmixer->mixer; |
1da177e4 LT |
164 | int result = 0; |
165 | ||
166 | if (mixer == NULL) | |
167 | return -EIO; | |
168 | if (mixer->put_recsrc && mixer->get_recsrc) { /* exclusive */ | |
169 | result = mixer->mask_recsrc; | |
170 | } else { | |
f956b4a3 | 171 | struct snd_mixer_oss_slot *pslot; |
1da177e4 LT |
172 | int chn; |
173 | for (chn = 0; chn < 31; chn++) { | |
174 | pslot = &mixer->slots[chn]; | |
175 | if (pslot->put_recsrc) | |
176 | result |= 1 << chn; | |
177 | } | |
178 | } | |
179 | return result; | |
180 | } | |
181 | ||
f956b4a3 | 182 | static int snd_mixer_oss_get_recsrc(struct snd_mixer_oss_file *fmixer) |
1da177e4 | 183 | { |
f956b4a3 | 184 | struct snd_mixer_oss *mixer = fmixer->mixer; |
1da177e4 LT |
185 | int result = 0; |
186 | ||
187 | if (mixer == NULL) | |
188 | return -EIO; | |
189 | if (mixer->put_recsrc && mixer->get_recsrc) { /* exclusive */ | |
190 | int err; | |
191 | if ((err = mixer->get_recsrc(fmixer, &result)) < 0) | |
192 | return err; | |
193 | result = 1 << result; | |
194 | } else { | |
f956b4a3 | 195 | struct snd_mixer_oss_slot *pslot; |
1da177e4 LT |
196 | int chn; |
197 | for (chn = 0; chn < 31; chn++) { | |
198 | pslot = &mixer->slots[chn]; | |
199 | if (pslot->get_recsrc) { | |
200 | int active = 0; | |
201 | pslot->get_recsrc(fmixer, pslot, &active); | |
202 | if (active) | |
203 | result |= 1 << chn; | |
204 | } | |
205 | } | |
206 | } | |
207 | return mixer->oss_recsrc = result; | |
208 | } | |
209 | ||
f956b4a3 | 210 | static int snd_mixer_oss_set_recsrc(struct snd_mixer_oss_file *fmixer, int recsrc) |
1da177e4 | 211 | { |
f956b4a3 TI |
212 | struct snd_mixer_oss *mixer = fmixer->mixer; |
213 | struct snd_mixer_oss_slot *pslot; | |
1da177e4 LT |
214 | int chn, active; |
215 | int result = 0; | |
216 | ||
217 | if (mixer == NULL) | |
218 | return -EIO; | |
219 | if (mixer->get_recsrc && mixer->put_recsrc) { /* exclusive input */ | |
220 | if (recsrc & ~mixer->oss_recsrc) | |
221 | recsrc &= ~mixer->oss_recsrc; | |
222 | mixer->put_recsrc(fmixer, ffz(~recsrc)); | |
223 | mixer->get_recsrc(fmixer, &result); | |
224 | result = 1 << result; | |
225 | } | |
226 | for (chn = 0; chn < 31; chn++) { | |
227 | pslot = &mixer->slots[chn]; | |
228 | if (pslot->put_recsrc) { | |
229 | active = (recsrc & (1 << chn)) ? 1 : 0; | |
230 | pslot->put_recsrc(fmixer, pslot, active); | |
231 | } | |
232 | } | |
233 | if (! result) { | |
234 | for (chn = 0; chn < 31; chn++) { | |
235 | pslot = &mixer->slots[chn]; | |
236 | if (pslot->get_recsrc) { | |
237 | active = 0; | |
238 | pslot->get_recsrc(fmixer, pslot, &active); | |
239 | if (active) | |
240 | result |= 1 << chn; | |
241 | } | |
242 | } | |
243 | } | |
244 | return result; | |
245 | } | |
246 | ||
f956b4a3 | 247 | static int snd_mixer_oss_get_volume(struct snd_mixer_oss_file *fmixer, int slot) |
1da177e4 | 248 | { |
f956b4a3 TI |
249 | struct snd_mixer_oss *mixer = fmixer->mixer; |
250 | struct snd_mixer_oss_slot *pslot; | |
1da177e4 LT |
251 | int result = 0, left, right; |
252 | ||
253 | if (mixer == NULL || slot > 30) | |
254 | return -EIO; | |
255 | pslot = &mixer->slots[slot]; | |
256 | left = pslot->volume[0]; | |
257 | right = pslot->volume[1]; | |
258 | if (pslot->get_volume) | |
259 | result = pslot->get_volume(fmixer, pslot, &left, &right); | |
260 | if (!pslot->stereo) | |
261 | right = left; | |
262 | snd_assert(left >= 0 && left <= 100, return -EIO); | |
263 | snd_assert(right >= 0 && right <= 100, return -EIO); | |
264 | if (result >= 0) { | |
265 | pslot->volume[0] = left; | |
266 | pslot->volume[1] = right; | |
267 | result = (left & 0xff) | ((right & 0xff) << 8); | |
268 | } | |
269 | return result; | |
270 | } | |
271 | ||
f956b4a3 | 272 | static int snd_mixer_oss_set_volume(struct snd_mixer_oss_file *fmixer, |
1da177e4 LT |
273 | int slot, int volume) |
274 | { | |
f956b4a3 TI |
275 | struct snd_mixer_oss *mixer = fmixer->mixer; |
276 | struct snd_mixer_oss_slot *pslot; | |
1da177e4 LT |
277 | int result = 0, left = volume & 0xff, right = (volume >> 8) & 0xff; |
278 | ||
279 | if (mixer == NULL || slot > 30) | |
280 | return -EIO; | |
281 | pslot = &mixer->slots[slot]; | |
282 | if (left > 100) | |
283 | left = 100; | |
284 | if (right > 100) | |
285 | right = 100; | |
286 | if (!pslot->stereo) | |
287 | right = left; | |
288 | if (pslot->put_volume) | |
289 | result = pslot->put_volume(fmixer, pslot, left, right); | |
290 | if (result < 0) | |
291 | return result; | |
292 | pslot->volume[0] = left; | |
293 | pslot->volume[1] = right; | |
294 | return (left & 0xff) | ((right & 0xff) << 8); | |
295 | } | |
296 | ||
f956b4a3 | 297 | static int snd_mixer_oss_ioctl1(struct snd_mixer_oss_file *fmixer, unsigned int cmd, unsigned long arg) |
1da177e4 LT |
298 | { |
299 | void __user *argp = (void __user *)arg; | |
300 | int __user *p = argp; | |
301 | int tmp; | |
302 | ||
303 | snd_assert(fmixer != NULL, return -ENXIO); | |
304 | if (((cmd >> 8) & 0xff) == 'M') { | |
305 | switch (cmd) { | |
306 | case SOUND_MIXER_INFO: | |
307 | return snd_mixer_oss_info(fmixer, argp); | |
308 | case SOUND_OLD_MIXER_INFO: | |
309 | return snd_mixer_oss_info_obsolete(fmixer, argp); | |
310 | case SOUND_MIXER_WRITE_RECSRC: | |
311 | if (get_user(tmp, p)) | |
312 | return -EFAULT; | |
313 | tmp = snd_mixer_oss_set_recsrc(fmixer, tmp); | |
314 | if (tmp < 0) | |
315 | return tmp; | |
316 | return put_user(tmp, p); | |
317 | case OSS_GETVERSION: | |
318 | return put_user(SNDRV_OSS_VERSION, p); | |
319 | case OSS_ALSAEMULVER: | |
320 | return put_user(1, p); | |
321 | case SOUND_MIXER_READ_DEVMASK: | |
322 | tmp = snd_mixer_oss_devmask(fmixer); | |
323 | if (tmp < 0) | |
324 | return tmp; | |
325 | return put_user(tmp, p); | |
326 | case SOUND_MIXER_READ_STEREODEVS: | |
327 | tmp = snd_mixer_oss_stereodevs(fmixer); | |
328 | if (tmp < 0) | |
329 | return tmp; | |
330 | return put_user(tmp, p); | |
331 | case SOUND_MIXER_READ_RECMASK: | |
332 | tmp = snd_mixer_oss_recmask(fmixer); | |
333 | if (tmp < 0) | |
334 | return tmp; | |
335 | return put_user(tmp, p); | |
336 | case SOUND_MIXER_READ_CAPS: | |
337 | tmp = snd_mixer_oss_caps(fmixer); | |
338 | if (tmp < 0) | |
339 | return tmp; | |
340 | return put_user(tmp, p); | |
341 | case SOUND_MIXER_READ_RECSRC: | |
342 | tmp = snd_mixer_oss_get_recsrc(fmixer); | |
343 | if (tmp < 0) | |
344 | return tmp; | |
345 | return put_user(tmp, p); | |
346 | } | |
347 | } | |
348 | if (cmd & SIOC_IN) { | |
349 | if (get_user(tmp, p)) | |
350 | return -EFAULT; | |
351 | tmp = snd_mixer_oss_set_volume(fmixer, cmd & 0xff, tmp); | |
352 | if (tmp < 0) | |
353 | return tmp; | |
354 | return put_user(tmp, p); | |
355 | } else if (cmd & SIOC_OUT) { | |
356 | tmp = snd_mixer_oss_get_volume(fmixer, cmd & 0xff); | |
357 | if (tmp < 0) | |
358 | return tmp; | |
359 | return put_user(tmp, p); | |
360 | } | |
361 | return -ENXIO; | |
362 | } | |
363 | ||
364 | static long snd_mixer_oss_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
365 | { | |
f956b4a3 | 366 | return snd_mixer_oss_ioctl1((struct snd_mixer_oss_file *) file->private_data, cmd, arg); |
1da177e4 LT |
367 | } |
368 | ||
f956b4a3 | 369 | int snd_mixer_oss_ioctl_card(struct snd_card *card, unsigned int cmd, unsigned long arg) |
1da177e4 | 370 | { |
f956b4a3 | 371 | struct snd_mixer_oss_file fmixer; |
1da177e4 LT |
372 | |
373 | snd_assert(card != NULL, return -ENXIO); | |
374 | if (card->mixer_oss == NULL) | |
375 | return -ENXIO; | |
376 | memset(&fmixer, 0, sizeof(fmixer)); | |
377 | fmixer.card = card; | |
378 | fmixer.mixer = card->mixer_oss; | |
379 | return snd_mixer_oss_ioctl1(&fmixer, cmd, arg); | |
380 | } | |
381 | ||
382 | #ifdef CONFIG_COMPAT | |
383 | /* all compatible */ | |
384 | #define snd_mixer_oss_ioctl_compat snd_mixer_oss_ioctl | |
385 | #else | |
386 | #define snd_mixer_oss_ioctl_compat NULL | |
387 | #endif | |
388 | ||
389 | /* | |
390 | * REGISTRATION PART | |
391 | */ | |
392 | ||
393 | static struct file_operations snd_mixer_oss_f_ops = | |
394 | { | |
395 | .owner = THIS_MODULE, | |
396 | .open = snd_mixer_oss_open, | |
397 | .release = snd_mixer_oss_release, | |
398 | .unlocked_ioctl = snd_mixer_oss_ioctl, | |
399 | .compat_ioctl = snd_mixer_oss_ioctl_compat, | |
400 | }; | |
401 | ||
1da177e4 LT |
402 | /* |
403 | * utilities | |
404 | */ | |
405 | ||
406 | static long snd_mixer_oss_conv(long val, long omin, long omax, long nmin, long nmax) | |
407 | { | |
408 | long orange = omax - omin, nrange = nmax - nmin; | |
409 | ||
410 | if (orange == 0) | |
411 | return 0; | |
412 | return ((nrange * (val - omin)) + (orange / 2)) / orange + nmin; | |
413 | } | |
414 | ||
415 | /* convert from alsa native to oss values (0-100) */ | |
416 | static long snd_mixer_oss_conv1(long val, long min, long max, int *old) | |
417 | { | |
418 | if (val == snd_mixer_oss_conv(*old, 0, 100, min, max)) | |
419 | return *old; | |
420 | return snd_mixer_oss_conv(val, min, max, 0, 100); | |
421 | } | |
422 | ||
423 | /* convert from oss to alsa native values */ | |
424 | static long snd_mixer_oss_conv2(long val, long min, long max) | |
425 | { | |
426 | return snd_mixer_oss_conv(val, 0, 100, min, max); | |
427 | } | |
428 | ||
429 | #if 0 | |
f956b4a3 | 430 | static void snd_mixer_oss_recsrce_set(struct snd_card *card, int slot) |
1da177e4 | 431 | { |
f956b4a3 | 432 | struct snd_mixer_oss *mixer = card->mixer_oss; |
1da177e4 LT |
433 | if (mixer) |
434 | mixer->mask_recsrc |= 1 << slot; | |
435 | } | |
436 | ||
f956b4a3 | 437 | static int snd_mixer_oss_recsrce_get(struct snd_card *card, int slot) |
1da177e4 | 438 | { |
f956b4a3 | 439 | struct snd_mixer_oss *mixer = card->mixer_oss; |
1da177e4 LT |
440 | if (mixer && (mixer->mask_recsrc & (1 << slot))) |
441 | return 1; | |
442 | return 0; | |
443 | } | |
444 | #endif | |
445 | ||
446 | #define SNDRV_MIXER_OSS_SIGNATURE 0x65999250 | |
447 | ||
448 | #define SNDRV_MIXER_OSS_ITEM_GLOBAL 0 | |
449 | #define SNDRV_MIXER_OSS_ITEM_GSWITCH 1 | |
450 | #define SNDRV_MIXER_OSS_ITEM_GROUTE 2 | |
451 | #define SNDRV_MIXER_OSS_ITEM_GVOLUME 3 | |
452 | #define SNDRV_MIXER_OSS_ITEM_PSWITCH 4 | |
453 | #define SNDRV_MIXER_OSS_ITEM_PROUTE 5 | |
454 | #define SNDRV_MIXER_OSS_ITEM_PVOLUME 6 | |
455 | #define SNDRV_MIXER_OSS_ITEM_CSWITCH 7 | |
456 | #define SNDRV_MIXER_OSS_ITEM_CROUTE 8 | |
457 | #define SNDRV_MIXER_OSS_ITEM_CVOLUME 9 | |
458 | #define SNDRV_MIXER_OSS_ITEM_CAPTURE 10 | |
459 | ||
460 | #define SNDRV_MIXER_OSS_ITEM_COUNT 11 | |
461 | ||
462 | #define SNDRV_MIXER_OSS_PRESENT_GLOBAL (1<<0) | |
463 | #define SNDRV_MIXER_OSS_PRESENT_GSWITCH (1<<1) | |
464 | #define SNDRV_MIXER_OSS_PRESENT_GROUTE (1<<2) | |
465 | #define SNDRV_MIXER_OSS_PRESENT_GVOLUME (1<<3) | |
466 | #define SNDRV_MIXER_OSS_PRESENT_PSWITCH (1<<4) | |
467 | #define SNDRV_MIXER_OSS_PRESENT_PROUTE (1<<5) | |
468 | #define SNDRV_MIXER_OSS_PRESENT_PVOLUME (1<<6) | |
469 | #define SNDRV_MIXER_OSS_PRESENT_CSWITCH (1<<7) | |
470 | #define SNDRV_MIXER_OSS_PRESENT_CROUTE (1<<8) | |
471 | #define SNDRV_MIXER_OSS_PRESENT_CVOLUME (1<<9) | |
472 | #define SNDRV_MIXER_OSS_PRESENT_CAPTURE (1<<10) | |
473 | ||
474 | struct slot { | |
475 | unsigned int signature; | |
476 | unsigned int present; | |
477 | unsigned int channels; | |
478 | unsigned int numid[SNDRV_MIXER_OSS_ITEM_COUNT]; | |
479 | unsigned int capture_item; | |
480 | struct snd_mixer_oss_assign_table *assigned; | |
481 | unsigned int allocated: 1; | |
482 | }; | |
483 | ||
484 | #define ID_UNKNOWN ((unsigned int)-1) | |
485 | ||
f956b4a3 | 486 | static struct snd_kcontrol *snd_mixer_oss_test_id(struct snd_mixer_oss *mixer, const char *name, int index) |
1da177e4 | 487 | { |
f956b4a3 TI |
488 | struct snd_card *card = mixer->card; |
489 | struct snd_ctl_elem_id id; | |
1da177e4 LT |
490 | |
491 | memset(&id, 0, sizeof(id)); | |
492 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | |
493 | strcpy(id.name, name); | |
494 | id.index = index; | |
495 | return snd_ctl_find_id(card, &id); | |
496 | } | |
497 | ||
f956b4a3 TI |
498 | static void snd_mixer_oss_get_volume1_vol(struct snd_mixer_oss_file *fmixer, |
499 | struct snd_mixer_oss_slot *pslot, | |
1da177e4 LT |
500 | unsigned int numid, |
501 | int *left, int *right) | |
502 | { | |
f956b4a3 TI |
503 | struct snd_ctl_elem_info *uinfo; |
504 | struct snd_ctl_elem_value *uctl; | |
505 | struct snd_kcontrol *kctl; | |
506 | struct snd_card *card = fmixer->card; | |
1da177e4 LT |
507 | |
508 | if (numid == ID_UNKNOWN) | |
509 | return; | |
510 | down_read(&card->controls_rwsem); | |
511 | if ((kctl = snd_ctl_find_numid(card, numid)) == NULL) { | |
512 | up_read(&card->controls_rwsem); | |
513 | return; | |
514 | } | |
ca2c0966 TI |
515 | uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); |
516 | uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); | |
1da177e4 LT |
517 | if (uinfo == NULL || uctl == NULL) |
518 | goto __unalloc; | |
7c22f1aa TI |
519 | if (kctl->info(kctl, uinfo)) |
520 | goto __unalloc; | |
521 | if (kctl->get(kctl, uctl)) | |
522 | goto __unalloc; | |
523 | if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN && | |
524 | uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1) | |
525 | goto __unalloc; | |
1da177e4 LT |
526 | *left = snd_mixer_oss_conv1(uctl->value.integer.value[0], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[0]); |
527 | if (uinfo->count > 1) | |
528 | *right = snd_mixer_oss_conv1(uctl->value.integer.value[1], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1]); | |
529 | __unalloc: | |
530 | up_read(&card->controls_rwsem); | |
531 | kfree(uctl); | |
532 | kfree(uinfo); | |
533 | } | |
534 | ||
f956b4a3 TI |
535 | static void snd_mixer_oss_get_volume1_sw(struct snd_mixer_oss_file *fmixer, |
536 | struct snd_mixer_oss_slot *pslot, | |
1da177e4 LT |
537 | unsigned int numid, |
538 | int *left, int *right, | |
539 | int route) | |
540 | { | |
f956b4a3 TI |
541 | struct snd_ctl_elem_info *uinfo; |
542 | struct snd_ctl_elem_value *uctl; | |
543 | struct snd_kcontrol *kctl; | |
544 | struct snd_card *card = fmixer->card; | |
1da177e4 LT |
545 | |
546 | if (numid == ID_UNKNOWN) | |
547 | return; | |
548 | down_read(&card->controls_rwsem); | |
549 | if ((kctl = snd_ctl_find_numid(card, numid)) == NULL) { | |
550 | up_read(&card->controls_rwsem); | |
551 | return; | |
552 | } | |
ca2c0966 TI |
553 | uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); |
554 | uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); | |
1da177e4 LT |
555 | if (uinfo == NULL || uctl == NULL) |
556 | goto __unalloc; | |
7c22f1aa TI |
557 | if (kctl->info(kctl, uinfo)) |
558 | goto __unalloc; | |
559 | if (kctl->get(kctl, uctl)) | |
560 | goto __unalloc; | |
1da177e4 LT |
561 | if (!uctl->value.integer.value[0]) { |
562 | *left = 0; | |
563 | if (uinfo->count == 1) | |
564 | *right = 0; | |
565 | } | |
566 | if (uinfo->count > 1 && !uctl->value.integer.value[route ? 3 : 1]) | |
567 | *right = 0; | |
568 | __unalloc: | |
569 | up_read(&card->controls_rwsem); | |
570 | kfree(uctl); | |
571 | kfree(uinfo); | |
572 | } | |
573 | ||
f956b4a3 TI |
574 | static int snd_mixer_oss_get_volume1(struct snd_mixer_oss_file *fmixer, |
575 | struct snd_mixer_oss_slot *pslot, | |
1da177e4 LT |
576 | int *left, int *right) |
577 | { | |
578 | struct slot *slot = (struct slot *)pslot->private_data; | |
579 | ||
580 | *left = *right = 100; | |
581 | if (slot->present & SNDRV_MIXER_OSS_PRESENT_PVOLUME) { | |
582 | snd_mixer_oss_get_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PVOLUME], left, right); | |
583 | } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GVOLUME) { | |
584 | snd_mixer_oss_get_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GVOLUME], left, right); | |
585 | } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GLOBAL) { | |
586 | snd_mixer_oss_get_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GLOBAL], left, right); | |
587 | } | |
588 | if (slot->present & SNDRV_MIXER_OSS_PRESENT_PSWITCH) { | |
589 | snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PSWITCH], left, right, 0); | |
590 | } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GSWITCH) { | |
591 | snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GSWITCH], left, right, 0); | |
592 | } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_PROUTE) { | |
593 | snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PROUTE], left, right, 1); | |
594 | } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GROUTE) { | |
595 | snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GROUTE], left, right, 1); | |
596 | } | |
597 | return 0; | |
598 | } | |
599 | ||
f956b4a3 TI |
600 | static void snd_mixer_oss_put_volume1_vol(struct snd_mixer_oss_file *fmixer, |
601 | struct snd_mixer_oss_slot *pslot, | |
1da177e4 LT |
602 | unsigned int numid, |
603 | int left, int right) | |
604 | { | |
f956b4a3 TI |
605 | struct snd_ctl_elem_info *uinfo; |
606 | struct snd_ctl_elem_value *uctl; | |
607 | struct snd_kcontrol *kctl; | |
608 | struct snd_card *card = fmixer->card; | |
1da177e4 LT |
609 | int res; |
610 | ||
611 | if (numid == ID_UNKNOWN) | |
612 | return; | |
613 | down_read(&card->controls_rwsem); | |
614 | if ((kctl = snd_ctl_find_numid(card, numid)) == NULL) | |
615 | return; | |
ca2c0966 TI |
616 | uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); |
617 | uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); | |
1da177e4 LT |
618 | if (uinfo == NULL || uctl == NULL) |
619 | goto __unalloc; | |
7c22f1aa TI |
620 | if (kctl->info(kctl, uinfo)) |
621 | goto __unalloc; | |
622 | if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN && | |
623 | uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1) | |
624 | goto __unalloc; | |
1da177e4 LT |
625 | uctl->value.integer.value[0] = snd_mixer_oss_conv2(left, uinfo->value.integer.min, uinfo->value.integer.max); |
626 | if (uinfo->count > 1) | |
627 | uctl->value.integer.value[1] = snd_mixer_oss_conv2(right, uinfo->value.integer.min, uinfo->value.integer.max); | |
7c22f1aa TI |
628 | if ((res = kctl->put(kctl, uctl)) < 0) |
629 | goto __unalloc; | |
1da177e4 LT |
630 | if (res > 0) |
631 | snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); | |
632 | __unalloc: | |
633 | up_read(&card->controls_rwsem); | |
634 | kfree(uctl); | |
635 | kfree(uinfo); | |
636 | } | |
637 | ||
f956b4a3 TI |
638 | static void snd_mixer_oss_put_volume1_sw(struct snd_mixer_oss_file *fmixer, |
639 | struct snd_mixer_oss_slot *pslot, | |
1da177e4 LT |
640 | unsigned int numid, |
641 | int left, int right, | |
642 | int route) | |
643 | { | |
f956b4a3 TI |
644 | struct snd_ctl_elem_info *uinfo; |
645 | struct snd_ctl_elem_value *uctl; | |
646 | struct snd_kcontrol *kctl; | |
647 | struct snd_card *card = fmixer->card; | |
1da177e4 LT |
648 | int res; |
649 | ||
650 | if (numid == ID_UNKNOWN) | |
651 | return; | |
652 | down_read(&card->controls_rwsem); | |
653 | if ((kctl = snd_ctl_find_numid(card, numid)) == NULL) { | |
654 | up_read(&fmixer->card->controls_rwsem); | |
655 | return; | |
656 | } | |
ca2c0966 TI |
657 | uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); |
658 | uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); | |
1da177e4 LT |
659 | if (uinfo == NULL || uctl == NULL) |
660 | goto __unalloc; | |
7c22f1aa TI |
661 | if (kctl->info(kctl, uinfo)) |
662 | goto __unalloc; | |
1da177e4 LT |
663 | if (uinfo->count > 1) { |
664 | uctl->value.integer.value[0] = left > 0 ? 1 : 0; | |
665 | uctl->value.integer.value[route ? 3 : 1] = right > 0 ? 1 : 0; | |
666 | if (route) { | |
667 | uctl->value.integer.value[1] = | |
668 | uctl->value.integer.value[2] = 0; | |
669 | } | |
670 | } else { | |
671 | uctl->value.integer.value[0] = (left > 0 || right > 0) ? 1 : 0; | |
672 | } | |
7c22f1aa TI |
673 | if ((res = kctl->put(kctl, uctl)) < 0) |
674 | goto __unalloc; | |
1da177e4 LT |
675 | if (res > 0) |
676 | snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); | |
677 | __unalloc: | |
678 | up_read(&card->controls_rwsem); | |
679 | kfree(uctl); | |
680 | kfree(uinfo); | |
681 | } | |
682 | ||
f956b4a3 TI |
683 | static int snd_mixer_oss_put_volume1(struct snd_mixer_oss_file *fmixer, |
684 | struct snd_mixer_oss_slot *pslot, | |
1da177e4 LT |
685 | int left, int right) |
686 | { | |
687 | struct slot *slot = (struct slot *)pslot->private_data; | |
688 | ||
689 | if (slot->present & SNDRV_MIXER_OSS_PRESENT_PVOLUME) { | |
690 | snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PVOLUME], left, right); | |
691 | if (slot->present & SNDRV_MIXER_OSS_PRESENT_CVOLUME) | |
692 | snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CVOLUME], left, right); | |
693 | } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GVOLUME) { | |
694 | snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GVOLUME], left, right); | |
695 | } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GLOBAL) { | |
696 | snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GLOBAL], left, right); | |
697 | } | |
698 | if (left || right) { | |
699 | if (slot->present & SNDRV_MIXER_OSS_PRESENT_PSWITCH) | |
700 | snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PSWITCH], left, right, 0); | |
701 | if (slot->present & SNDRV_MIXER_OSS_PRESENT_GSWITCH) | |
702 | snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GSWITCH], left, right, 0); | |
703 | if (slot->present & SNDRV_MIXER_OSS_PRESENT_PROUTE) | |
704 | snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PROUTE], left, right, 1); | |
705 | if (slot->present & SNDRV_MIXER_OSS_PRESENT_GROUTE) | |
706 | snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GROUTE], left, right, 1); | |
707 | } else { | |
708 | if (slot->present & SNDRV_MIXER_OSS_PRESENT_PSWITCH) { | |
709 | snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PSWITCH], left, right, 0); | |
710 | } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GSWITCH) { | |
711 | snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GSWITCH], left, right, 0); | |
712 | } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_PROUTE) { | |
713 | snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PROUTE], left, right, 1); | |
714 | } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GROUTE) { | |
715 | snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GROUTE], left, right, 1); | |
716 | } | |
717 | } | |
718 | return 0; | |
719 | } | |
720 | ||
f956b4a3 TI |
721 | static int snd_mixer_oss_get_recsrc1_sw(struct snd_mixer_oss_file *fmixer, |
722 | struct snd_mixer_oss_slot *pslot, | |
1da177e4 LT |
723 | int *active) |
724 | { | |
725 | struct slot *slot = (struct slot *)pslot->private_data; | |
726 | int left, right; | |
727 | ||
728 | left = right = 1; | |
729 | snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CSWITCH], &left, &right, 0); | |
730 | *active = (left || right) ? 1 : 0; | |
731 | return 0; | |
732 | } | |
733 | ||
f956b4a3 TI |
734 | static int snd_mixer_oss_get_recsrc1_route(struct snd_mixer_oss_file *fmixer, |
735 | struct snd_mixer_oss_slot *pslot, | |
1da177e4 LT |
736 | int *active) |
737 | { | |
738 | struct slot *slot = (struct slot *)pslot->private_data; | |
739 | int left, right; | |
740 | ||
741 | left = right = 1; | |
742 | snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CROUTE], &left, &right, 1); | |
743 | *active = (left || right) ? 1 : 0; | |
744 | return 0; | |
745 | } | |
746 | ||
f956b4a3 TI |
747 | static int snd_mixer_oss_put_recsrc1_sw(struct snd_mixer_oss_file *fmixer, |
748 | struct snd_mixer_oss_slot *pslot, | |
1da177e4 LT |
749 | int active) |
750 | { | |
751 | struct slot *slot = (struct slot *)pslot->private_data; | |
752 | ||
753 | snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CSWITCH], active, active, 0); | |
754 | return 0; | |
755 | } | |
756 | ||
f956b4a3 TI |
757 | static int snd_mixer_oss_put_recsrc1_route(struct snd_mixer_oss_file *fmixer, |
758 | struct snd_mixer_oss_slot *pslot, | |
1da177e4 LT |
759 | int active) |
760 | { | |
761 | struct slot *slot = (struct slot *)pslot->private_data; | |
762 | ||
763 | snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CROUTE], active, active, 1); | |
764 | return 0; | |
765 | } | |
766 | ||
f956b4a3 | 767 | static int snd_mixer_oss_get_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned int *active_index) |
1da177e4 | 768 | { |
f956b4a3 TI |
769 | struct snd_card *card = fmixer->card; |
770 | struct snd_mixer_oss *mixer = fmixer->mixer; | |
771 | struct snd_kcontrol *kctl; | |
772 | struct snd_mixer_oss_slot *pslot; | |
1da177e4 | 773 | struct slot *slot; |
f956b4a3 TI |
774 | struct snd_ctl_elem_info *uinfo; |
775 | struct snd_ctl_elem_value *uctl; | |
1da177e4 LT |
776 | int err, idx; |
777 | ||
ca2c0966 TI |
778 | uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); |
779 | uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); | |
1da177e4 LT |
780 | if (uinfo == NULL || uctl == NULL) { |
781 | err = -ENOMEM; | |
782 | goto __unlock; | |
783 | } | |
784 | down_read(&card->controls_rwsem); | |
785 | kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0); | |
7c22f1aa TI |
786 | if (! kctl) { |
787 | err = -ENOENT; | |
788 | goto __unlock; | |
789 | } | |
790 | if ((err = kctl->info(kctl, uinfo)) < 0) | |
791 | goto __unlock; | |
792 | if ((err = kctl->get(kctl, uctl)) < 0) | |
793 | goto __unlock; | |
1da177e4 LT |
794 | for (idx = 0; idx < 32; idx++) { |
795 | if (!(mixer->mask_recsrc & (1 << idx))) | |
796 | continue; | |
797 | pslot = &mixer->slots[idx]; | |
798 | slot = (struct slot *)pslot->private_data; | |
799 | if (slot->signature != SNDRV_MIXER_OSS_SIGNATURE) | |
800 | continue; | |
801 | if (!(slot->present & SNDRV_MIXER_OSS_PRESENT_CAPTURE)) | |
802 | continue; | |
803 | if (slot->capture_item == uctl->value.enumerated.item[0]) { | |
804 | *active_index = idx; | |
805 | break; | |
806 | } | |
807 | } | |
808 | err = 0; | |
809 | __unlock: | |
810 | up_read(&card->controls_rwsem); | |
811 | kfree(uctl); | |
812 | kfree(uinfo); | |
813 | return err; | |
814 | } | |
815 | ||
f956b4a3 | 816 | static int snd_mixer_oss_put_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned int active_index) |
1da177e4 | 817 | { |
f956b4a3 TI |
818 | struct snd_card *card = fmixer->card; |
819 | struct snd_mixer_oss *mixer = fmixer->mixer; | |
820 | struct snd_kcontrol *kctl; | |
821 | struct snd_mixer_oss_slot *pslot; | |
1da177e4 | 822 | struct slot *slot = NULL; |
f956b4a3 TI |
823 | struct snd_ctl_elem_info *uinfo; |
824 | struct snd_ctl_elem_value *uctl; | |
1da177e4 LT |
825 | int err; |
826 | unsigned int idx; | |
827 | ||
ca2c0966 TI |
828 | uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); |
829 | uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); | |
1da177e4 LT |
830 | if (uinfo == NULL || uctl == NULL) { |
831 | err = -ENOMEM; | |
832 | goto __unlock; | |
833 | } | |
834 | down_read(&card->controls_rwsem); | |
835 | kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0); | |
7c22f1aa TI |
836 | if (! kctl) { |
837 | err = -ENOENT; | |
838 | goto __unlock; | |
839 | } | |
840 | if ((err = kctl->info(kctl, uinfo)) < 0) | |
841 | goto __unlock; | |
1da177e4 LT |
842 | for (idx = 0; idx < 32; idx++) { |
843 | if (!(mixer->mask_recsrc & (1 << idx))) | |
844 | continue; | |
845 | pslot = &mixer->slots[idx]; | |
846 | slot = (struct slot *)pslot->private_data; | |
847 | if (slot->signature != SNDRV_MIXER_OSS_SIGNATURE) | |
848 | continue; | |
849 | if (!(slot->present & SNDRV_MIXER_OSS_PRESENT_CAPTURE)) | |
850 | continue; | |
851 | if (idx == active_index) | |
852 | break; | |
853 | slot = NULL; | |
854 | } | |
7c22f1aa TI |
855 | if (! slot) |
856 | goto __unlock; | |
1da177e4 LT |
857 | for (idx = 0; idx < uinfo->count; idx++) |
858 | uctl->value.enumerated.item[idx] = slot->capture_item; | |
7c22f1aa | 859 | err = kctl->put(kctl, uctl); |
1da177e4 LT |
860 | if (err > 0) |
861 | snd_ctl_notify(fmixer->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); | |
862 | err = 0; | |
863 | __unlock: | |
864 | up_read(&card->controls_rwsem); | |
865 | kfree(uctl); | |
866 | kfree(uinfo); | |
867 | return err; | |
868 | } | |
869 | ||
870 | struct snd_mixer_oss_assign_table { | |
871 | int oss_id; | |
872 | const char *name; | |
873 | int index; | |
874 | }; | |
875 | ||
f956b4a3 | 876 | static int snd_mixer_oss_build_test(struct snd_mixer_oss *mixer, struct slot *slot, const char *name, int index, int item) |
1da177e4 | 877 | { |
f956b4a3 TI |
878 | struct snd_ctl_elem_info *info; |
879 | struct snd_kcontrol *kcontrol; | |
880 | struct snd_card *card = mixer->card; | |
1da177e4 LT |
881 | int err; |
882 | ||
883 | down_read(&card->controls_rwsem); | |
884 | kcontrol = snd_mixer_oss_test_id(mixer, name, index); | |
885 | if (kcontrol == NULL) { | |
886 | up_read(&card->controls_rwsem); | |
887 | return 0; | |
888 | } | |
889 | info = kmalloc(sizeof(*info), GFP_KERNEL); | |
890 | if (! info) { | |
891 | up_read(&card->controls_rwsem); | |
892 | return -ENOMEM; | |
893 | } | |
894 | if ((err = kcontrol->info(kcontrol, info)) < 0) { | |
895 | up_read(&card->controls_rwsem); | |
896 | kfree(info); | |
897 | return err; | |
898 | } | |
899 | slot->numid[item] = kcontrol->id.numid; | |
900 | up_read(&card->controls_rwsem); | |
901 | if (info->count > slot->channels) | |
902 | slot->channels = info->count; | |
903 | slot->present |= 1 << item; | |
904 | kfree(info); | |
905 | return 0; | |
906 | } | |
907 | ||
f956b4a3 | 908 | static void snd_mixer_oss_slot_free(struct snd_mixer_oss_slot *chn) |
1da177e4 LT |
909 | { |
910 | struct slot *p = (struct slot *)chn->private_data; | |
911 | if (p) { | |
912 | if (p->allocated && p->assigned) { | |
913 | kfree(p->assigned->name); | |
914 | kfree(p->assigned); | |
915 | } | |
916 | kfree(p); | |
917 | } | |
918 | } | |
919 | ||
f956b4a3 | 920 | static void mixer_slot_clear(struct snd_mixer_oss_slot *rslot) |
1da177e4 LT |
921 | { |
922 | int idx = rslot->number; /* remember this */ | |
923 | if (rslot->private_free) | |
924 | rslot->private_free(rslot); | |
925 | memset(rslot, 0, sizeof(*rslot)); | |
926 | rslot->number = idx; | |
927 | } | |
928 | ||
929 | /* | |
930 | * build an OSS mixer element. | |
931 | * ptr_allocated means the entry is dynamically allocated (change via proc file). | |
932 | * when replace_old = 1, the old entry is replaced with the new one. | |
933 | */ | |
f956b4a3 | 934 | static int snd_mixer_oss_build_input(struct snd_mixer_oss *mixer, struct snd_mixer_oss_assign_table *ptr, int ptr_allocated, int replace_old) |
1da177e4 LT |
935 | { |
936 | struct slot slot; | |
937 | struct slot *pslot; | |
f956b4a3 TI |
938 | struct snd_kcontrol *kctl; |
939 | struct snd_mixer_oss_slot *rslot; | |
1da177e4 LT |
940 | char str[64]; |
941 | ||
942 | /* check if already assigned */ | |
943 | if (mixer->slots[ptr->oss_id].get_volume && ! replace_old) | |
944 | return 0; | |
945 | ||
946 | memset(&slot, 0, sizeof(slot)); | |
947 | memset(slot.numid, 0xff, sizeof(slot.numid)); /* ID_UNKNOWN */ | |
948 | if (snd_mixer_oss_build_test(mixer, &slot, ptr->name, ptr->index, | |
949 | SNDRV_MIXER_OSS_ITEM_GLOBAL)) | |
950 | return 0; | |
951 | sprintf(str, "%s Switch", ptr->name); | |
952 | if (snd_mixer_oss_build_test(mixer, &slot, str, ptr->index, | |
953 | SNDRV_MIXER_OSS_ITEM_GSWITCH)) | |
954 | return 0; | |
955 | sprintf(str, "%s Route", ptr->name); | |
956 | if (snd_mixer_oss_build_test(mixer, &slot, str, ptr->index, | |
957 | SNDRV_MIXER_OSS_ITEM_GROUTE)) | |
958 | return 0; | |
959 | sprintf(str, "%s Volume", ptr->name); | |
960 | if (snd_mixer_oss_build_test(mixer, &slot, str, ptr->index, | |
961 | SNDRV_MIXER_OSS_ITEM_GVOLUME)) | |
962 | return 0; | |
963 | sprintf(str, "%s Playback Switch", ptr->name); | |
964 | if (snd_mixer_oss_build_test(mixer, &slot, str, ptr->index, | |
965 | SNDRV_MIXER_OSS_ITEM_PSWITCH)) | |
966 | return 0; | |
967 | sprintf(str, "%s Playback Route", ptr->name); | |
968 | if (snd_mixer_oss_build_test(mixer, &slot, str, ptr->index, | |
969 | SNDRV_MIXER_OSS_ITEM_PROUTE)) | |
970 | return 0; | |
971 | sprintf(str, "%s Playback Volume", ptr->name); | |
972 | if (snd_mixer_oss_build_test(mixer, &slot, str, ptr->index, | |
973 | SNDRV_MIXER_OSS_ITEM_PVOLUME)) | |
974 | return 0; | |
975 | sprintf(str, "%s Capture Switch", ptr->name); | |
976 | if (snd_mixer_oss_build_test(mixer, &slot, str, ptr->index, | |
977 | SNDRV_MIXER_OSS_ITEM_CSWITCH)) | |
978 | return 0; | |
979 | sprintf(str, "%s Capture Route", ptr->name); | |
980 | if (snd_mixer_oss_build_test(mixer, &slot, str, ptr->index, | |
981 | SNDRV_MIXER_OSS_ITEM_CROUTE)) | |
982 | return 0; | |
983 | sprintf(str, "%s Capture Volume", ptr->name); | |
984 | if (snd_mixer_oss_build_test(mixer, &slot, str, ptr->index, | |
985 | SNDRV_MIXER_OSS_ITEM_CVOLUME)) | |
986 | return 0; | |
987 | down_read(&mixer->card->controls_rwsem); | |
988 | if (ptr->index == 0 && (kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0)) != NULL) { | |
f956b4a3 | 989 | struct snd_ctl_elem_info *uinfo; |
1da177e4 LT |
990 | |
991 | uinfo = kmalloc(sizeof(*uinfo), GFP_KERNEL); | |
992 | if (! uinfo) { | |
993 | up_read(&mixer->card->controls_rwsem); | |
994 | return -ENOMEM; | |
995 | } | |
996 | ||
997 | memset(uinfo, 0, sizeof(*uinfo)); | |
998 | if (kctl->info(kctl, uinfo)) { | |
999 | up_read(&mixer->card->controls_rwsem); | |
1000 | return 0; | |
1001 | } | |
1002 | strcpy(str, ptr->name); | |
1003 | if (!strcmp(str, "Master")) | |
1004 | strcpy(str, "Mix"); | |
1005 | if (!strcmp(str, "Master Mono")) | |
1006 | strcpy(str, "Mix Mono"); | |
1007 | slot.capture_item = 0; | |
1008 | if (!strcmp(uinfo->value.enumerated.name, str)) { | |
1009 | slot.present |= SNDRV_MIXER_OSS_PRESENT_CAPTURE; | |
1010 | } else { | |
1011 | for (slot.capture_item = 1; slot.capture_item < uinfo->value.enumerated.items; slot.capture_item++) { | |
1012 | uinfo->value.enumerated.item = slot.capture_item; | |
1013 | if (kctl->info(kctl, uinfo)) { | |
1014 | up_read(&mixer->card->controls_rwsem); | |
1015 | return 0; | |
1016 | } | |
1017 | if (!strcmp(uinfo->value.enumerated.name, str)) { | |
1018 | slot.present |= SNDRV_MIXER_OSS_PRESENT_CAPTURE; | |
1019 | break; | |
1020 | } | |
1021 | } | |
1022 | } | |
1023 | kfree(uinfo); | |
1024 | } | |
1025 | up_read(&mixer->card->controls_rwsem); | |
1026 | if (slot.present != 0) { | |
1027 | pslot = (struct slot *)kmalloc(sizeof(slot), GFP_KERNEL); | |
7c22f1aa TI |
1028 | if (! pslot) |
1029 | return -ENOMEM; | |
1da177e4 LT |
1030 | *pslot = slot; |
1031 | pslot->signature = SNDRV_MIXER_OSS_SIGNATURE; | |
1032 | pslot->assigned = ptr; | |
1033 | pslot->allocated = ptr_allocated; | |
1034 | rslot = &mixer->slots[ptr->oss_id]; | |
1035 | mixer_slot_clear(rslot); | |
1036 | rslot->stereo = slot.channels > 1 ? 1 : 0; | |
1037 | rslot->get_volume = snd_mixer_oss_get_volume1; | |
1038 | rslot->put_volume = snd_mixer_oss_put_volume1; | |
1039 | /* note: ES18xx have both Capture Source and XX Capture Volume !!! */ | |
1040 | if (slot.present & SNDRV_MIXER_OSS_PRESENT_CSWITCH) { | |
1041 | rslot->get_recsrc = snd_mixer_oss_get_recsrc1_sw; | |
1042 | rslot->put_recsrc = snd_mixer_oss_put_recsrc1_sw; | |
1043 | } else if (slot.present & SNDRV_MIXER_OSS_PRESENT_CROUTE) { | |
1044 | rslot->get_recsrc = snd_mixer_oss_get_recsrc1_route; | |
1045 | rslot->put_recsrc = snd_mixer_oss_put_recsrc1_route; | |
1046 | } else if (slot.present & SNDRV_MIXER_OSS_PRESENT_CAPTURE) { | |
1047 | mixer->mask_recsrc |= 1 << ptr->oss_id; | |
1048 | } | |
1049 | rslot->private_data = pslot; | |
1050 | rslot->private_free = snd_mixer_oss_slot_free; | |
1051 | return 1; | |
1052 | } | |
1053 | return 0; | |
1054 | } | |
1055 | ||
04f141a8 | 1056 | #ifdef CONFIG_PROC_FS |
1da177e4 LT |
1057 | /* |
1058 | */ | |
1059 | #define MIXER_VOL(name) [SOUND_MIXER_##name] = #name | |
1060 | static char *oss_mixer_names[SNDRV_OSS_MAX_MIXERS] = { | |
1061 | MIXER_VOL(VOLUME), | |
1062 | MIXER_VOL(BASS), | |
1063 | MIXER_VOL(TREBLE), | |
1064 | MIXER_VOL(SYNTH), | |
1065 | MIXER_VOL(PCM), | |
1066 | MIXER_VOL(SPEAKER), | |
1067 | MIXER_VOL(LINE), | |
1068 | MIXER_VOL(MIC), | |
1069 | MIXER_VOL(CD), | |
1070 | MIXER_VOL(IMIX), | |
1071 | MIXER_VOL(ALTPCM), | |
1072 | MIXER_VOL(RECLEV), | |
1073 | MIXER_VOL(IGAIN), | |
1074 | MIXER_VOL(OGAIN), | |
1075 | MIXER_VOL(LINE1), | |
1076 | MIXER_VOL(LINE2), | |
1077 | MIXER_VOL(LINE3), | |
1078 | MIXER_VOL(DIGITAL1), | |
1079 | MIXER_VOL(DIGITAL2), | |
1080 | MIXER_VOL(DIGITAL3), | |
1081 | MIXER_VOL(PHONEIN), | |
1082 | MIXER_VOL(PHONEOUT), | |
1083 | MIXER_VOL(VIDEO), | |
1084 | MIXER_VOL(RADIO), | |
1085 | MIXER_VOL(MONITOR), | |
1086 | }; | |
1087 | ||
1088 | /* | |
1089 | * /proc interface | |
1090 | */ | |
1091 | ||
f956b4a3 TI |
1092 | static void snd_mixer_oss_proc_read(struct snd_info_entry *entry, |
1093 | struct snd_info_buffer *buffer) | |
1da177e4 | 1094 | { |
f956b4a3 | 1095 | struct snd_mixer_oss *mixer = entry->private_data; |
1da177e4 LT |
1096 | int i; |
1097 | ||
1a60d4c5 | 1098 | mutex_lock(&mixer->reg_mutex); |
1da177e4 LT |
1099 | for (i = 0; i < SNDRV_OSS_MAX_MIXERS; i++) { |
1100 | struct slot *p; | |
1101 | ||
1102 | if (! oss_mixer_names[i]) | |
1103 | continue; | |
1104 | p = (struct slot *)mixer->slots[i].private_data; | |
1105 | snd_iprintf(buffer, "%s ", oss_mixer_names[i]); | |
1106 | if (p && p->assigned) | |
1107 | snd_iprintf(buffer, "\"%s\" %d\n", | |
1108 | p->assigned->name, | |
1109 | p->assigned->index); | |
1110 | else | |
1111 | snd_iprintf(buffer, "\"\" 0\n"); | |
1112 | } | |
1a60d4c5 | 1113 | mutex_unlock(&mixer->reg_mutex); |
1da177e4 LT |
1114 | } |
1115 | ||
f956b4a3 TI |
1116 | static void snd_mixer_oss_proc_write(struct snd_info_entry *entry, |
1117 | struct snd_info_buffer *buffer) | |
1da177e4 | 1118 | { |
f956b4a3 | 1119 | struct snd_mixer_oss *mixer = entry->private_data; |
1da177e4 LT |
1120 | char line[128], str[32], idxstr[16], *cptr; |
1121 | int ch, idx; | |
1122 | struct snd_mixer_oss_assign_table *tbl; | |
1123 | struct slot *slot; | |
1124 | ||
1125 | while (!snd_info_get_line(buffer, line, sizeof(line))) { | |
1126 | cptr = snd_info_get_str(str, line, sizeof(str)); | |
1127 | for (ch = 0; ch < SNDRV_OSS_MAX_MIXERS; ch++) | |
1128 | if (oss_mixer_names[ch] && strcmp(oss_mixer_names[ch], str) == 0) | |
1129 | break; | |
1130 | if (ch >= SNDRV_OSS_MAX_MIXERS) { | |
1131 | snd_printk(KERN_ERR "mixer_oss: invalid OSS volume '%s'\n", str); | |
1132 | continue; | |
1133 | } | |
1134 | cptr = snd_info_get_str(str, cptr, sizeof(str)); | |
1135 | if (! *str) { | |
1136 | /* remove the entry */ | |
1a60d4c5 | 1137 | mutex_lock(&mixer->reg_mutex); |
1da177e4 | 1138 | mixer_slot_clear(&mixer->slots[ch]); |
1a60d4c5 | 1139 | mutex_unlock(&mixer->reg_mutex); |
1da177e4 LT |
1140 | continue; |
1141 | } | |
1142 | snd_info_get_str(idxstr, cptr, sizeof(idxstr)); | |
1143 | idx = simple_strtoul(idxstr, NULL, 10); | |
1144 | if (idx >= 0x4000) { /* too big */ | |
1145 | snd_printk(KERN_ERR "mixer_oss: invalid index %d\n", idx); | |
1146 | continue; | |
1147 | } | |
1a60d4c5 | 1148 | mutex_lock(&mixer->reg_mutex); |
1da177e4 LT |
1149 | slot = (struct slot *)mixer->slots[ch].private_data; |
1150 | if (slot && slot->assigned && | |
1151 | slot->assigned->index == idx && ! strcmp(slot->assigned->name, str)) | |
1152 | /* not changed */ | |
1153 | goto __unlock; | |
1154 | tbl = kmalloc(sizeof(*tbl), GFP_KERNEL); | |
1155 | if (! tbl) { | |
1156 | snd_printk(KERN_ERR "mixer_oss: no memory\n"); | |
1157 | goto __unlock; | |
1158 | } | |
1159 | tbl->oss_id = ch; | |
543537bd | 1160 | tbl->name = kstrdup(str, GFP_KERNEL); |
1da177e4 LT |
1161 | if (! tbl->name) { |
1162 | kfree(tbl); | |
1163 | goto __unlock; | |
1164 | } | |
1165 | tbl->index = idx; | |
1166 | if (snd_mixer_oss_build_input(mixer, tbl, 1, 1) <= 0) { | |
1167 | kfree(tbl->name); | |
1168 | kfree(tbl); | |
1169 | } | |
1170 | __unlock: | |
1a60d4c5 | 1171 | mutex_unlock(&mixer->reg_mutex); |
1da177e4 LT |
1172 | } |
1173 | } | |
1174 | ||
f956b4a3 | 1175 | static void snd_mixer_oss_proc_init(struct snd_mixer_oss *mixer) |
1da177e4 | 1176 | { |
f956b4a3 | 1177 | struct snd_info_entry *entry; |
1da177e4 LT |
1178 | |
1179 | entry = snd_info_create_card_entry(mixer->card, "oss_mixer", | |
1180 | mixer->card->proc_root); | |
1181 | if (! entry) | |
1182 | return; | |
1183 | entry->content = SNDRV_INFO_CONTENT_TEXT; | |
1184 | entry->mode = S_IFREG | S_IRUGO | S_IWUSR; | |
1da177e4 | 1185 | entry->c.text.read = snd_mixer_oss_proc_read; |
1da177e4 LT |
1186 | entry->c.text.write = snd_mixer_oss_proc_write; |
1187 | entry->private_data = mixer; | |
1188 | if (snd_info_register(entry) < 0) { | |
1189 | snd_info_free_entry(entry); | |
1190 | entry = NULL; | |
1191 | } | |
1192 | mixer->proc_entry = entry; | |
1193 | } | |
1194 | ||
f956b4a3 | 1195 | static void snd_mixer_oss_proc_done(struct snd_mixer_oss *mixer) |
1da177e4 LT |
1196 | { |
1197 | if (mixer->proc_entry) { | |
1198 | snd_info_unregister(mixer->proc_entry); | |
1199 | mixer->proc_entry = NULL; | |
1200 | } | |
1201 | } | |
04f141a8 TI |
1202 | #else /* !CONFIG_PROC_FS */ |
1203 | #define snd_mixer_oss_proc_init(mix) | |
1204 | #define snd_mixer_oss_proc_done(mix) | |
1205 | #endif /* CONFIG_PROC_FS */ | |
1da177e4 | 1206 | |
f956b4a3 | 1207 | static void snd_mixer_oss_build(struct snd_mixer_oss *mixer) |
1da177e4 LT |
1208 | { |
1209 | static struct snd_mixer_oss_assign_table table[] = { | |
1210 | { SOUND_MIXER_VOLUME, "Master", 0 }, | |
1211 | { SOUND_MIXER_VOLUME, "Front", 0 }, /* fallback */ | |
1212 | { SOUND_MIXER_BASS, "Tone Control - Bass", 0 }, | |
1213 | { SOUND_MIXER_TREBLE, "Tone Control - Treble", 0 }, | |
1214 | { SOUND_MIXER_SYNTH, "Synth", 0 }, | |
1215 | { SOUND_MIXER_SYNTH, "FM", 0 }, /* fallback */ | |
1216 | { SOUND_MIXER_SYNTH, "Music", 0 }, /* fallback */ | |
1217 | { SOUND_MIXER_PCM, "PCM", 0 }, | |
1218 | { SOUND_MIXER_SPEAKER, "PC Speaker", 0 }, | |
1219 | { SOUND_MIXER_LINE, "Line", 0 }, | |
1220 | { SOUND_MIXER_MIC, "Mic", 0 }, | |
1221 | { SOUND_MIXER_CD, "CD", 0 }, | |
1222 | { SOUND_MIXER_IMIX, "Monitor Mix", 0 }, | |
1223 | { SOUND_MIXER_ALTPCM, "PCM", 1 }, | |
1224 | { SOUND_MIXER_ALTPCM, "Headphone", 0 }, /* fallback */ | |
1225 | { SOUND_MIXER_ALTPCM, "Wave", 0 }, /* fallback */ | |
1226 | { SOUND_MIXER_RECLEV, "-- nothing --", 0 }, | |
1227 | { SOUND_MIXER_IGAIN, "Capture", 0 }, | |
1228 | { SOUND_MIXER_OGAIN, "Playback", 0 }, | |
1229 | { SOUND_MIXER_LINE1, "Aux", 0 }, | |
1230 | { SOUND_MIXER_LINE2, "Aux", 1 }, | |
1231 | { SOUND_MIXER_LINE3, "Aux", 2 }, | |
1232 | { SOUND_MIXER_DIGITAL1, "Digital", 0 }, | |
1233 | { SOUND_MIXER_DIGITAL1, "IEC958", 0 }, /* fallback */ | |
1234 | { SOUND_MIXER_DIGITAL1, "IEC958 Optical", 0 }, /* fallback */ | |
1235 | { SOUND_MIXER_DIGITAL1, "IEC958 Coaxial", 0 }, /* fallback */ | |
1236 | { SOUND_MIXER_DIGITAL2, "Digital", 1 }, | |
1237 | { SOUND_MIXER_DIGITAL3, "Digital", 2 }, | |
1238 | { SOUND_MIXER_PHONEIN, "Phone", 0 }, | |
1239 | { SOUND_MIXER_PHONEOUT, "Master Mono", 0 }, | |
1240 | { SOUND_MIXER_PHONEOUT, "Phone", 0 }, /* fallback */ | |
1241 | { SOUND_MIXER_VIDEO, "Video", 0 }, | |
1242 | { SOUND_MIXER_RADIO, "Radio", 0 }, | |
1243 | { SOUND_MIXER_MONITOR, "Monitor", 0 } | |
1244 | }; | |
1245 | unsigned int idx; | |
1246 | ||
1247 | for (idx = 0; idx < ARRAY_SIZE(table); idx++) | |
1248 | snd_mixer_oss_build_input(mixer, &table[idx], 0, 0); | |
1249 | if (mixer->mask_recsrc) { | |
1250 | mixer->get_recsrc = snd_mixer_oss_get_recsrc2; | |
1251 | mixer->put_recsrc = snd_mixer_oss_put_recsrc2; | |
1252 | } | |
1253 | } | |
1254 | ||
1255 | /* | |
1256 | * | |
1257 | */ | |
1258 | ||
1259 | static int snd_mixer_oss_free1(void *private) | |
1260 | { | |
f956b4a3 TI |
1261 | struct snd_mixer_oss *mixer = private; |
1262 | struct snd_card *card; | |
1da177e4 LT |
1263 | int idx; |
1264 | ||
1265 | snd_assert(mixer != NULL, return -ENXIO); | |
1266 | card = mixer->card; | |
1267 | snd_assert(mixer == card->mixer_oss, return -ENXIO); | |
1268 | card->mixer_oss = NULL; | |
1269 | for (idx = 0; idx < SNDRV_OSS_MAX_MIXERS; idx++) { | |
f956b4a3 | 1270 | struct snd_mixer_oss_slot *chn = &mixer->slots[idx]; |
1da177e4 LT |
1271 | if (chn->private_free) |
1272 | chn->private_free(chn); | |
1273 | } | |
1274 | kfree(mixer); | |
1275 | return 0; | |
1276 | } | |
1277 | ||
f956b4a3 | 1278 | static int snd_mixer_oss_notify_handler(struct snd_card *card, int cmd) |
1da177e4 | 1279 | { |
f956b4a3 | 1280 | struct snd_mixer_oss *mixer; |
1da177e4 LT |
1281 | |
1282 | if (cmd == SND_MIXER_OSS_NOTIFY_REGISTER) { | |
1283 | char name[128]; | |
1284 | int idx, err; | |
1285 | ||
1286 | mixer = kcalloc(2, sizeof(*mixer), GFP_KERNEL); | |
1287 | if (mixer == NULL) | |
1288 | return -ENOMEM; | |
1a60d4c5 | 1289 | mutex_init(&mixer->reg_mutex); |
1da177e4 LT |
1290 | sprintf(name, "mixer%i%i", card->number, 0); |
1291 | if ((err = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER, | |
1292 | card, 0, | |
f87135f5 | 1293 | &snd_mixer_oss_f_ops, card, |
1da177e4 | 1294 | name)) < 0) { |
d3d579f8 TI |
1295 | snd_printk(KERN_ERR "unable to register OSS mixer device %i:%i\n", |
1296 | card->number, 0); | |
1da177e4 LT |
1297 | kfree(mixer); |
1298 | return err; | |
1299 | } | |
1300 | mixer->oss_dev_alloc = 1; | |
1301 | mixer->card = card; | |
1302 | if (*card->mixername) | |
1303 | strlcpy(mixer->name, card->mixername, sizeof(mixer->name)); | |
1304 | else | |
1305 | strlcpy(mixer->name, name, sizeof(mixer->name)); | |
1306 | #ifdef SNDRV_OSS_INFO_DEV_MIXERS | |
1307 | snd_oss_info_register(SNDRV_OSS_INFO_DEV_MIXERS, | |
1308 | card->number, | |
1309 | mixer->name); | |
1310 | #endif | |
1311 | for (idx = 0; idx < SNDRV_OSS_MAX_MIXERS; idx++) | |
1312 | mixer->slots[idx].number = idx; | |
1313 | card->mixer_oss = mixer; | |
1314 | snd_mixer_oss_build(mixer); | |
1315 | snd_mixer_oss_proc_init(mixer); | |
1316 | } else if (cmd == SND_MIXER_OSS_NOTIFY_DISCONNECT) { | |
1317 | mixer = card->mixer_oss; | |
1318 | if (mixer == NULL || !mixer->oss_dev_alloc) | |
1319 | return 0; | |
1320 | snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER, mixer->card, 0); | |
1321 | mixer->oss_dev_alloc = 0; | |
1322 | } else { /* free */ | |
1323 | mixer = card->mixer_oss; | |
1324 | if (mixer == NULL) | |
1325 | return 0; | |
1326 | #ifdef SNDRV_OSS_INFO_DEV_MIXERS | |
1327 | snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_MIXERS, mixer->card->number); | |
1328 | #endif | |
1329 | if (mixer->oss_dev_alloc) | |
1330 | snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER, mixer->card, 0); | |
1331 | snd_mixer_oss_proc_done(mixer); | |
1332 | return snd_mixer_oss_free1(mixer); | |
1333 | } | |
1334 | return 0; | |
1335 | } | |
1336 | ||
1337 | static int __init alsa_mixer_oss_init(void) | |
1338 | { | |
1339 | int idx; | |
1340 | ||
1341 | snd_mixer_oss_notify_callback = snd_mixer_oss_notify_handler; | |
1342 | for (idx = 0; idx < SNDRV_CARDS; idx++) { | |
1343 | if (snd_cards[idx]) | |
1344 | snd_mixer_oss_notify_handler(snd_cards[idx], SND_MIXER_OSS_NOTIFY_REGISTER); | |
1345 | } | |
1346 | return 0; | |
1347 | } | |
1348 | ||
1349 | static void __exit alsa_mixer_oss_exit(void) | |
1350 | { | |
1351 | int idx; | |
1352 | ||
1353 | snd_mixer_oss_notify_callback = NULL; | |
1354 | for (idx = 0; idx < SNDRV_CARDS; idx++) { | |
1355 | if (snd_cards[idx]) | |
1356 | snd_mixer_oss_notify_handler(snd_cards[idx], SND_MIXER_OSS_NOTIFY_FREE); | |
1357 | } | |
1358 | } | |
1359 | ||
1360 | module_init(alsa_mixer_oss_init) | |
1361 | module_exit(alsa_mixer_oss_exit) | |
1362 | ||
1363 | EXPORT_SYMBOL(snd_mixer_oss_ioctl_card); |