2 * OSS emulation layer for the mixer interface
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
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.
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.
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
22 #include <linux/init.h>
23 #include <linux/slab.h>
24 #include <linux/time.h>
25 #include <linux/string.h>
26 #include <sound/core.h>
27 #include <sound/minors.h>
28 #include <sound/control.h>
29 #include <sound/info.h>
30 #include <sound/mixer_oss.h>
31 #include <linux/soundcard.h>
33 #define OSS_ALSAEMULVER _SIOR ('M', 249, int)
35 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
36 MODULE_DESCRIPTION("Mixer OSS emulation for ALSA.");
37 MODULE_LICENSE("GPL");
38 MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_MIXER);
40 static int snd_mixer_oss_open(struct inode *inode, struct file *file)
42 struct snd_card *card;
43 struct snd_mixer_oss_file *fmixer;
46 err = nonseekable_open(inode, file);
50 card = snd_lookup_oss_minor_data(iminor(inode),
51 SNDRV_OSS_DEVICE_TYPE_MIXER);
54 if (card->mixer_oss == NULL) {
58 err = snd_card_file_add(card, file);
63 fmixer = kzalloc(sizeof(*fmixer), GFP_KERNEL);
65 snd_card_file_remove(card, file);
70 fmixer->mixer = card->mixer_oss;
71 file->private_data = fmixer;
72 if (!try_module_get(card->module)) {
74 snd_card_file_remove(card, file);
81 static int snd_mixer_oss_release(struct inode *inode, struct file *file)
83 struct snd_mixer_oss_file *fmixer;
85 if (file->private_data) {
86 fmixer = file->private_data;
87 module_put(fmixer->card->module);
88 snd_card_file_remove(fmixer->card, file);
94 static int snd_mixer_oss_info(struct snd_mixer_oss_file *fmixer,
95 mixer_info __user *_info)
97 struct snd_card *card = fmixer->card;
98 struct snd_mixer_oss *mixer = fmixer->mixer;
99 struct mixer_info info;
101 memset(&info, 0, sizeof(info));
102 strlcpy(info.id, mixer && mixer->id[0] ? mixer->id : card->driver, sizeof(info.id));
103 strlcpy(info.name, mixer && mixer->name[0] ? mixer->name : card->mixername, sizeof(info.name));
104 info.modify_counter = card->mixer_oss_change_count;
105 if (copy_to_user(_info, &info, sizeof(info)))
110 static int snd_mixer_oss_info_obsolete(struct snd_mixer_oss_file *fmixer,
111 _old_mixer_info __user *_info)
113 struct snd_card *card = fmixer->card;
114 struct snd_mixer_oss *mixer = fmixer->mixer;
115 _old_mixer_info info;
117 memset(&info, 0, sizeof(info));
118 strlcpy(info.id, mixer && mixer->id[0] ? mixer->id : card->driver, sizeof(info.id));
119 strlcpy(info.name, mixer && mixer->name[0] ? mixer->name : card->mixername, sizeof(info.name));
120 if (copy_to_user(_info, &info, sizeof(info)))
125 static int snd_mixer_oss_caps(struct snd_mixer_oss_file *fmixer)
127 struct snd_mixer_oss *mixer = fmixer->mixer;
132 if (mixer->get_recsrc && mixer->put_recsrc)
133 result |= SOUND_CAP_EXCL_INPUT;
137 static int snd_mixer_oss_devmask(struct snd_mixer_oss_file *fmixer)
139 struct snd_mixer_oss *mixer = fmixer->mixer;
140 struct snd_mixer_oss_slot *pslot;
145 for (chn = 0; chn < 31; chn++) {
146 pslot = &mixer->slots[chn];
147 if (pslot->put_volume || pslot->put_recsrc)
153 static int snd_mixer_oss_stereodevs(struct snd_mixer_oss_file *fmixer)
155 struct snd_mixer_oss *mixer = fmixer->mixer;
156 struct snd_mixer_oss_slot *pslot;
161 for (chn = 0; chn < 31; chn++) {
162 pslot = &mixer->slots[chn];
163 if (pslot->put_volume && pslot->stereo)
169 static int snd_mixer_oss_recmask(struct snd_mixer_oss_file *fmixer)
171 struct snd_mixer_oss *mixer = fmixer->mixer;
176 if (mixer->put_recsrc && mixer->get_recsrc) { /* exclusive */
177 result = mixer->mask_recsrc;
179 struct snd_mixer_oss_slot *pslot;
181 for (chn = 0; chn < 31; chn++) {
182 pslot = &mixer->slots[chn];
183 if (pslot->put_recsrc)
190 static int snd_mixer_oss_get_recsrc(struct snd_mixer_oss_file *fmixer)
192 struct snd_mixer_oss *mixer = fmixer->mixer;
197 if (mixer->put_recsrc && mixer->get_recsrc) { /* exclusive */
200 if ((err = mixer->get_recsrc(fmixer, &index)) < 0)
204 struct snd_mixer_oss_slot *pslot;
206 for (chn = 0; chn < 31; chn++) {
207 pslot = &mixer->slots[chn];
208 if (pslot->get_recsrc) {
210 pslot->get_recsrc(fmixer, pslot, &active);
216 return mixer->oss_recsrc = result;
219 static int snd_mixer_oss_set_recsrc(struct snd_mixer_oss_file *fmixer, int recsrc)
221 struct snd_mixer_oss *mixer = fmixer->mixer;
222 struct snd_mixer_oss_slot *pslot;
229 if (mixer->get_recsrc && mixer->put_recsrc) { /* exclusive input */
230 if (recsrc & ~mixer->oss_recsrc)
231 recsrc &= ~mixer->oss_recsrc;
232 mixer->put_recsrc(fmixer, ffz(~recsrc));
233 mixer->get_recsrc(fmixer, &index);
236 for (chn = 0; chn < 31; chn++) {
237 pslot = &mixer->slots[chn];
238 if (pslot->put_recsrc) {
239 active = (recsrc & (1 << chn)) ? 1 : 0;
240 pslot->put_recsrc(fmixer, pslot, active);
244 for (chn = 0; chn < 31; chn++) {
245 pslot = &mixer->slots[chn];
246 if (pslot->get_recsrc) {
248 pslot->get_recsrc(fmixer, pslot, &active);
257 static int snd_mixer_oss_get_volume(struct snd_mixer_oss_file *fmixer, int slot)
259 struct snd_mixer_oss *mixer = fmixer->mixer;
260 struct snd_mixer_oss_slot *pslot;
261 int result = 0, left, right;
263 if (mixer == NULL || slot > 30)
265 pslot = &mixer->slots[slot];
266 left = pslot->volume[0];
267 right = pslot->volume[1];
268 if (pslot->get_volume)
269 result = pslot->get_volume(fmixer, pslot, &left, &right);
272 if (snd_BUG_ON(left < 0 || left > 100))
274 if (snd_BUG_ON(right < 0 || right > 100))
277 pslot->volume[0] = left;
278 pslot->volume[1] = right;
279 result = (left & 0xff) | ((right & 0xff) << 8);
284 static int snd_mixer_oss_set_volume(struct snd_mixer_oss_file *fmixer,
285 int slot, int volume)
287 struct snd_mixer_oss *mixer = fmixer->mixer;
288 struct snd_mixer_oss_slot *pslot;
289 int result = 0, left = volume & 0xff, right = (volume >> 8) & 0xff;
291 if (mixer == NULL || slot > 30)
293 pslot = &mixer->slots[slot];
300 if (pslot->put_volume)
301 result = pslot->put_volume(fmixer, pslot, left, right);
304 pslot->volume[0] = left;
305 pslot->volume[1] = right;
306 return (left & 0xff) | ((right & 0xff) << 8);
309 static int snd_mixer_oss_ioctl1(struct snd_mixer_oss_file *fmixer, unsigned int cmd, unsigned long arg)
311 void __user *argp = (void __user *)arg;
312 int __user *p = argp;
315 if (snd_BUG_ON(!fmixer))
317 if (((cmd >> 8) & 0xff) == 'M') {
319 case SOUND_MIXER_INFO:
320 return snd_mixer_oss_info(fmixer, argp);
321 case SOUND_OLD_MIXER_INFO:
322 return snd_mixer_oss_info_obsolete(fmixer, argp);
323 case SOUND_MIXER_WRITE_RECSRC:
324 if (get_user(tmp, p))
326 tmp = snd_mixer_oss_set_recsrc(fmixer, tmp);
329 return put_user(tmp, p);
331 return put_user(SNDRV_OSS_VERSION, p);
332 case OSS_ALSAEMULVER:
333 return put_user(1, p);
334 case SOUND_MIXER_READ_DEVMASK:
335 tmp = snd_mixer_oss_devmask(fmixer);
338 return put_user(tmp, p);
339 case SOUND_MIXER_READ_STEREODEVS:
340 tmp = snd_mixer_oss_stereodevs(fmixer);
343 return put_user(tmp, p);
344 case SOUND_MIXER_READ_RECMASK:
345 tmp = snd_mixer_oss_recmask(fmixer);
348 return put_user(tmp, p);
349 case SOUND_MIXER_READ_CAPS:
350 tmp = snd_mixer_oss_caps(fmixer);
353 return put_user(tmp, p);
354 case SOUND_MIXER_READ_RECSRC:
355 tmp = snd_mixer_oss_get_recsrc(fmixer);
358 return put_user(tmp, p);
362 if (get_user(tmp, p))
364 tmp = snd_mixer_oss_set_volume(fmixer, cmd & 0xff, tmp);
367 return put_user(tmp, p);
368 } else if (cmd & SIOC_OUT) {
369 tmp = snd_mixer_oss_get_volume(fmixer, cmd & 0xff);
372 return put_user(tmp, p);
377 static long snd_mixer_oss_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
379 return snd_mixer_oss_ioctl1(file->private_data, cmd, arg);
382 int snd_mixer_oss_ioctl_card(struct snd_card *card, unsigned int cmd, unsigned long arg)
384 struct snd_mixer_oss_file fmixer;
386 if (snd_BUG_ON(!card))
388 if (card->mixer_oss == NULL)
390 memset(&fmixer, 0, sizeof(fmixer));
392 fmixer.mixer = card->mixer_oss;
393 return snd_mixer_oss_ioctl1(&fmixer, cmd, arg);
398 #define snd_mixer_oss_ioctl_compat snd_mixer_oss_ioctl
400 #define snd_mixer_oss_ioctl_compat NULL
407 static const struct file_operations snd_mixer_oss_f_ops =
409 .owner = THIS_MODULE,
410 .open = snd_mixer_oss_open,
411 .release = snd_mixer_oss_release,
413 .unlocked_ioctl = snd_mixer_oss_ioctl,
414 .compat_ioctl = snd_mixer_oss_ioctl_compat,
421 static long snd_mixer_oss_conv(long val, long omin, long omax, long nmin, long nmax)
423 long orange = omax - omin, nrange = nmax - nmin;
427 return ((nrange * (val - omin)) + (orange / 2)) / orange + nmin;
430 /* convert from alsa native to oss values (0-100) */
431 static long snd_mixer_oss_conv1(long val, long min, long max, int *old)
433 if (val == snd_mixer_oss_conv(*old, 0, 100, min, max))
435 return snd_mixer_oss_conv(val, min, max, 0, 100);
438 /* convert from oss to alsa native values */
439 static long snd_mixer_oss_conv2(long val, long min, long max)
441 return snd_mixer_oss_conv(val, 0, 100, min, max);
445 static void snd_mixer_oss_recsrce_set(struct snd_card *card, int slot)
447 struct snd_mixer_oss *mixer = card->mixer_oss;
449 mixer->mask_recsrc |= 1 << slot;
452 static int snd_mixer_oss_recsrce_get(struct snd_card *card, int slot)
454 struct snd_mixer_oss *mixer = card->mixer_oss;
455 if (mixer && (mixer->mask_recsrc & (1 << slot)))
461 #define SNDRV_MIXER_OSS_SIGNATURE 0x65999250
463 #define SNDRV_MIXER_OSS_ITEM_GLOBAL 0
464 #define SNDRV_MIXER_OSS_ITEM_GSWITCH 1
465 #define SNDRV_MIXER_OSS_ITEM_GROUTE 2
466 #define SNDRV_MIXER_OSS_ITEM_GVOLUME 3
467 #define SNDRV_MIXER_OSS_ITEM_PSWITCH 4
468 #define SNDRV_MIXER_OSS_ITEM_PROUTE 5
469 #define SNDRV_MIXER_OSS_ITEM_PVOLUME 6
470 #define SNDRV_MIXER_OSS_ITEM_CSWITCH 7
471 #define SNDRV_MIXER_OSS_ITEM_CROUTE 8
472 #define SNDRV_MIXER_OSS_ITEM_CVOLUME 9
473 #define SNDRV_MIXER_OSS_ITEM_CAPTURE 10
475 #define SNDRV_MIXER_OSS_ITEM_COUNT 11
477 #define SNDRV_MIXER_OSS_PRESENT_GLOBAL (1<<0)
478 #define SNDRV_MIXER_OSS_PRESENT_GSWITCH (1<<1)
479 #define SNDRV_MIXER_OSS_PRESENT_GROUTE (1<<2)
480 #define SNDRV_MIXER_OSS_PRESENT_GVOLUME (1<<3)
481 #define SNDRV_MIXER_OSS_PRESENT_PSWITCH (1<<4)
482 #define SNDRV_MIXER_OSS_PRESENT_PROUTE (1<<5)
483 #define SNDRV_MIXER_OSS_PRESENT_PVOLUME (1<<6)
484 #define SNDRV_MIXER_OSS_PRESENT_CSWITCH (1<<7)
485 #define SNDRV_MIXER_OSS_PRESENT_CROUTE (1<<8)
486 #define SNDRV_MIXER_OSS_PRESENT_CVOLUME (1<<9)
487 #define SNDRV_MIXER_OSS_PRESENT_CAPTURE (1<<10)
490 unsigned int signature;
491 unsigned int present;
492 unsigned int channels;
493 unsigned int numid[SNDRV_MIXER_OSS_ITEM_COUNT];
494 unsigned int capture_item;
495 struct snd_mixer_oss_assign_table *assigned;
496 unsigned int allocated: 1;
499 #define ID_UNKNOWN ((unsigned int)-1)
501 static struct snd_kcontrol *snd_mixer_oss_test_id(struct snd_mixer_oss *mixer, const char *name, int index)
503 struct snd_card *card = mixer->card;
504 struct snd_ctl_elem_id id;
506 memset(&id, 0, sizeof(id));
507 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
508 strcpy(id.name, name);
510 return snd_ctl_find_id(card, &id);
513 static void snd_mixer_oss_get_volume1_vol(struct snd_mixer_oss_file *fmixer,
514 struct snd_mixer_oss_slot *pslot,
516 int *left, int *right)
518 struct snd_ctl_elem_info *uinfo;
519 struct snd_ctl_elem_value *uctl;
520 struct snd_kcontrol *kctl;
521 struct snd_card *card = fmixer->card;
523 if (numid == ID_UNKNOWN)
525 down_read(&card->controls_rwsem);
526 if ((kctl = snd_ctl_find_numid(card, numid)) == NULL) {
527 up_read(&card->controls_rwsem);
530 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
531 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
532 if (uinfo == NULL || uctl == NULL)
534 if (kctl->info(kctl, uinfo))
536 if (kctl->get(kctl, uctl))
538 if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN &&
539 uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1)
541 *left = snd_mixer_oss_conv1(uctl->value.integer.value[0], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[0]);
542 if (uinfo->count > 1)
543 *right = snd_mixer_oss_conv1(uctl->value.integer.value[1], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1]);
545 up_read(&card->controls_rwsem);
550 static void snd_mixer_oss_get_volume1_sw(struct snd_mixer_oss_file *fmixer,
551 struct snd_mixer_oss_slot *pslot,
553 int *left, int *right,
556 struct snd_ctl_elem_info *uinfo;
557 struct snd_ctl_elem_value *uctl;
558 struct snd_kcontrol *kctl;
559 struct snd_card *card = fmixer->card;
561 if (numid == ID_UNKNOWN)
563 down_read(&card->controls_rwsem);
564 if ((kctl = snd_ctl_find_numid(card, numid)) == NULL) {
565 up_read(&card->controls_rwsem);
568 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
569 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
570 if (uinfo == NULL || uctl == NULL)
572 if (kctl->info(kctl, uinfo))
574 if (kctl->get(kctl, uctl))
576 if (!uctl->value.integer.value[0]) {
578 if (uinfo->count == 1)
581 if (uinfo->count > 1 && !uctl->value.integer.value[route ? 3 : 1])
584 up_read(&card->controls_rwsem);
589 static int snd_mixer_oss_get_volume1(struct snd_mixer_oss_file *fmixer,
590 struct snd_mixer_oss_slot *pslot,
591 int *left, int *right)
593 struct slot *slot = pslot->private_data;
595 *left = *right = 100;
596 if (slot->present & SNDRV_MIXER_OSS_PRESENT_PVOLUME) {
597 snd_mixer_oss_get_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PVOLUME], left, right);
598 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GVOLUME) {
599 snd_mixer_oss_get_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GVOLUME], left, right);
600 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GLOBAL) {
601 snd_mixer_oss_get_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GLOBAL], left, right);
603 if (slot->present & SNDRV_MIXER_OSS_PRESENT_PSWITCH) {
604 snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PSWITCH], left, right, 0);
605 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GSWITCH) {
606 snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GSWITCH], left, right, 0);
607 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_PROUTE) {
608 snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PROUTE], left, right, 1);
609 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GROUTE) {
610 snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GROUTE], left, right, 1);
615 static void snd_mixer_oss_put_volume1_vol(struct snd_mixer_oss_file *fmixer,
616 struct snd_mixer_oss_slot *pslot,
620 struct snd_ctl_elem_info *uinfo;
621 struct snd_ctl_elem_value *uctl;
622 struct snd_kcontrol *kctl;
623 struct snd_card *card = fmixer->card;
626 if (numid == ID_UNKNOWN)
628 down_read(&card->controls_rwsem);
629 if ((kctl = snd_ctl_find_numid(card, numid)) == NULL) {
630 up_read(&card->controls_rwsem);
633 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
634 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
635 if (uinfo == NULL || uctl == NULL)
637 if (kctl->info(kctl, uinfo))
639 if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN &&
640 uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1)
642 uctl->value.integer.value[0] = snd_mixer_oss_conv2(left, uinfo->value.integer.min, uinfo->value.integer.max);
643 if (uinfo->count > 1)
644 uctl->value.integer.value[1] = snd_mixer_oss_conv2(right, uinfo->value.integer.min, uinfo->value.integer.max);
645 if ((res = kctl->put(kctl, uctl)) < 0)
648 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
650 up_read(&card->controls_rwsem);
655 static void snd_mixer_oss_put_volume1_sw(struct snd_mixer_oss_file *fmixer,
656 struct snd_mixer_oss_slot *pslot,
661 struct snd_ctl_elem_info *uinfo;
662 struct snd_ctl_elem_value *uctl;
663 struct snd_kcontrol *kctl;
664 struct snd_card *card = fmixer->card;
667 if (numid == ID_UNKNOWN)
669 down_read(&card->controls_rwsem);
670 if ((kctl = snd_ctl_find_numid(card, numid)) == NULL) {
671 up_read(&card->controls_rwsem);
674 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
675 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
676 if (uinfo == NULL || uctl == NULL)
678 if (kctl->info(kctl, uinfo))
680 if (uinfo->count > 1) {
681 uctl->value.integer.value[0] = left > 0 ? 1 : 0;
682 uctl->value.integer.value[route ? 3 : 1] = right > 0 ? 1 : 0;
684 uctl->value.integer.value[1] =
685 uctl->value.integer.value[2] = 0;
688 uctl->value.integer.value[0] = (left > 0 || right > 0) ? 1 : 0;
690 if ((res = kctl->put(kctl, uctl)) < 0)
693 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
695 up_read(&card->controls_rwsem);
700 static int snd_mixer_oss_put_volume1(struct snd_mixer_oss_file *fmixer,
701 struct snd_mixer_oss_slot *pslot,
704 struct slot *slot = pslot->private_data;
706 if (slot->present & SNDRV_MIXER_OSS_PRESENT_PVOLUME) {
707 snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PVOLUME], left, right);
708 if (slot->present & SNDRV_MIXER_OSS_PRESENT_CVOLUME)
709 snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CVOLUME], left, right);
710 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_CVOLUME) {
711 snd_mixer_oss_put_volume1_vol(fmixer, pslot,
712 slot->numid[SNDRV_MIXER_OSS_ITEM_CVOLUME], left, right);
713 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GVOLUME) {
714 snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GVOLUME], left, right);
715 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GLOBAL) {
716 snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GLOBAL], left, right);
719 if (slot->present & SNDRV_MIXER_OSS_PRESENT_PSWITCH)
720 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PSWITCH], left, right, 0);
721 if (slot->present & SNDRV_MIXER_OSS_PRESENT_CSWITCH)
722 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CSWITCH], left, right, 0);
723 if (slot->present & SNDRV_MIXER_OSS_PRESENT_GSWITCH)
724 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GSWITCH], left, right, 0);
725 if (slot->present & SNDRV_MIXER_OSS_PRESENT_PROUTE)
726 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PROUTE], left, right, 1);
727 if (slot->present & SNDRV_MIXER_OSS_PRESENT_CROUTE)
728 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CROUTE], left, right, 1);
729 if (slot->present & SNDRV_MIXER_OSS_PRESENT_GROUTE)
730 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GROUTE], left, right, 1);
732 if (slot->present & SNDRV_MIXER_OSS_PRESENT_PSWITCH) {
733 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PSWITCH], left, right, 0);
734 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_CSWITCH) {
735 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CSWITCH], left, right, 0);
736 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GSWITCH) {
737 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GSWITCH], left, right, 0);
738 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_PROUTE) {
739 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PROUTE], left, right, 1);
740 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_CROUTE) {
741 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CROUTE], left, right, 1);
742 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GROUTE) {
743 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GROUTE], left, right, 1);
749 static int snd_mixer_oss_get_recsrc1_sw(struct snd_mixer_oss_file *fmixer,
750 struct snd_mixer_oss_slot *pslot,
753 struct slot *slot = pslot->private_data;
757 snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CSWITCH], &left, &right, 0);
758 *active = (left || right) ? 1 : 0;
762 static int snd_mixer_oss_get_recsrc1_route(struct snd_mixer_oss_file *fmixer,
763 struct snd_mixer_oss_slot *pslot,
766 struct slot *slot = pslot->private_data;
770 snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CROUTE], &left, &right, 1);
771 *active = (left || right) ? 1 : 0;
775 static int snd_mixer_oss_put_recsrc1_sw(struct snd_mixer_oss_file *fmixer,
776 struct snd_mixer_oss_slot *pslot,
779 struct slot *slot = pslot->private_data;
781 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CSWITCH], active, active, 0);
785 static int snd_mixer_oss_put_recsrc1_route(struct snd_mixer_oss_file *fmixer,
786 struct snd_mixer_oss_slot *pslot,
789 struct slot *slot = pslot->private_data;
791 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CROUTE], active, active, 1);
795 static int snd_mixer_oss_get_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned int *active_index)
797 struct snd_card *card = fmixer->card;
798 struct snd_mixer_oss *mixer = fmixer->mixer;
799 struct snd_kcontrol *kctl;
800 struct snd_mixer_oss_slot *pslot;
802 struct snd_ctl_elem_info *uinfo;
803 struct snd_ctl_elem_value *uctl;
806 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
807 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
808 if (uinfo == NULL || uctl == NULL) {
812 down_read(&card->controls_rwsem);
813 kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
818 if ((err = kctl->info(kctl, uinfo)) < 0)
820 if ((err = kctl->get(kctl, uctl)) < 0)
822 for (idx = 0; idx < 32; idx++) {
823 if (!(mixer->mask_recsrc & (1 << idx)))
825 pslot = &mixer->slots[idx];
826 slot = pslot->private_data;
827 if (slot->signature != SNDRV_MIXER_OSS_SIGNATURE)
829 if (!(slot->present & SNDRV_MIXER_OSS_PRESENT_CAPTURE))
831 if (slot->capture_item == uctl->value.enumerated.item[0]) {
838 up_read(&card->controls_rwsem);
845 static int snd_mixer_oss_put_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned int active_index)
847 struct snd_card *card = fmixer->card;
848 struct snd_mixer_oss *mixer = fmixer->mixer;
849 struct snd_kcontrol *kctl;
850 struct snd_mixer_oss_slot *pslot;
851 struct slot *slot = NULL;
852 struct snd_ctl_elem_info *uinfo;
853 struct snd_ctl_elem_value *uctl;
857 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
858 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
859 if (uinfo == NULL || uctl == NULL) {
863 down_read(&card->controls_rwsem);
864 kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
869 if ((err = kctl->info(kctl, uinfo)) < 0)
871 for (idx = 0; idx < 32; idx++) {
872 if (!(mixer->mask_recsrc & (1 << idx)))
874 pslot = &mixer->slots[idx];
875 slot = pslot->private_data;
876 if (slot->signature != SNDRV_MIXER_OSS_SIGNATURE)
878 if (!(slot->present & SNDRV_MIXER_OSS_PRESENT_CAPTURE))
880 if (idx == active_index)
886 for (idx = 0; idx < uinfo->count; idx++)
887 uctl->value.enumerated.item[idx] = slot->capture_item;
888 err = kctl->put(kctl, uctl);
890 snd_ctl_notify(fmixer->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
893 up_read(&card->controls_rwsem);
900 struct snd_mixer_oss_assign_table {
906 static int snd_mixer_oss_build_test(struct snd_mixer_oss *mixer, struct slot *slot, const char *name, int index, int item)
908 struct snd_ctl_elem_info *info;
909 struct snd_kcontrol *kcontrol;
910 struct snd_card *card = mixer->card;
913 down_read(&card->controls_rwsem);
914 kcontrol = snd_mixer_oss_test_id(mixer, name, index);
915 if (kcontrol == NULL) {
916 up_read(&card->controls_rwsem);
919 info = kmalloc(sizeof(*info), GFP_KERNEL);
921 up_read(&card->controls_rwsem);
924 if ((err = kcontrol->info(kcontrol, info)) < 0) {
925 up_read(&card->controls_rwsem);
929 slot->numid[item] = kcontrol->id.numid;
930 up_read(&card->controls_rwsem);
931 if (info->count > slot->channels)
932 slot->channels = info->count;
933 slot->present |= 1 << item;
938 static void snd_mixer_oss_slot_free(struct snd_mixer_oss_slot *chn)
940 struct slot *p = chn->private_data;
942 if (p->allocated && p->assigned) {
943 kfree(p->assigned->name);
950 static void mixer_slot_clear(struct snd_mixer_oss_slot *rslot)
952 int idx = rslot->number; /* remember this */
953 if (rslot->private_free)
954 rslot->private_free(rslot);
955 memset(rslot, 0, sizeof(*rslot));
959 /* In a separate function to keep gcc 3.2 happy - do NOT merge this in
960 snd_mixer_oss_build_input! */
961 static int snd_mixer_oss_build_test_all(struct snd_mixer_oss *mixer,
962 struct snd_mixer_oss_assign_table *ptr,
968 err = snd_mixer_oss_build_test(mixer, slot, ptr->name, ptr->index,
969 SNDRV_MIXER_OSS_ITEM_GLOBAL);
972 sprintf(str, "%s Switch", ptr->name);
973 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
974 SNDRV_MIXER_OSS_ITEM_GSWITCH);
977 sprintf(str, "%s Route", ptr->name);
978 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
979 SNDRV_MIXER_OSS_ITEM_GROUTE);
982 sprintf(str, "%s Volume", ptr->name);
983 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
984 SNDRV_MIXER_OSS_ITEM_GVOLUME);
987 sprintf(str, "%s Playback Switch", ptr->name);
988 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
989 SNDRV_MIXER_OSS_ITEM_PSWITCH);
992 sprintf(str, "%s Playback Route", ptr->name);
993 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
994 SNDRV_MIXER_OSS_ITEM_PROUTE);
997 sprintf(str, "%s Playback Volume", ptr->name);
998 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
999 SNDRV_MIXER_OSS_ITEM_PVOLUME);
1002 sprintf(str, "%s Capture Switch", ptr->name);
1003 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
1004 SNDRV_MIXER_OSS_ITEM_CSWITCH);
1007 sprintf(str, "%s Capture Route", ptr->name);
1008 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
1009 SNDRV_MIXER_OSS_ITEM_CROUTE);
1012 sprintf(str, "%s Capture Volume", ptr->name);
1013 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
1014 SNDRV_MIXER_OSS_ITEM_CVOLUME);
1022 * build an OSS mixer element.
1023 * ptr_allocated means the entry is dynamically allocated (change via proc file).
1024 * when replace_old = 1, the old entry is replaced with the new one.
1026 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)
1030 struct snd_kcontrol *kctl;
1031 struct snd_mixer_oss_slot *rslot;
1034 /* check if already assigned */
1035 if (mixer->slots[ptr->oss_id].get_volume && ! replace_old)
1038 memset(&slot, 0, sizeof(slot));
1039 memset(slot.numid, 0xff, sizeof(slot.numid)); /* ID_UNKNOWN */
1040 if (snd_mixer_oss_build_test_all(mixer, ptr, &slot))
1042 down_read(&mixer->card->controls_rwsem);
1043 if (ptr->index == 0 && (kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0)) != NULL) {
1044 struct snd_ctl_elem_info *uinfo;
1046 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
1048 up_read(&mixer->card->controls_rwsem);
1052 if (kctl->info(kctl, uinfo)) {
1053 up_read(&mixer->card->controls_rwsem);
1056 strcpy(str, ptr->name);
1057 if (!strcmp(str, "Master"))
1059 if (!strcmp(str, "Master Mono"))
1060 strcpy(str, "Mix Mono");
1061 slot.capture_item = 0;
1062 if (!strcmp(uinfo->value.enumerated.name, str)) {
1063 slot.present |= SNDRV_MIXER_OSS_PRESENT_CAPTURE;
1065 for (slot.capture_item = 1; slot.capture_item < uinfo->value.enumerated.items; slot.capture_item++) {
1066 uinfo->value.enumerated.item = slot.capture_item;
1067 if (kctl->info(kctl, uinfo)) {
1068 up_read(&mixer->card->controls_rwsem);
1071 if (!strcmp(uinfo->value.enumerated.name, str)) {
1072 slot.present |= SNDRV_MIXER_OSS_PRESENT_CAPTURE;
1079 up_read(&mixer->card->controls_rwsem);
1080 if (slot.present != 0) {
1081 pslot = kmalloc(sizeof(slot), GFP_KERNEL);
1085 pslot->signature = SNDRV_MIXER_OSS_SIGNATURE;
1086 pslot->assigned = ptr;
1087 pslot->allocated = ptr_allocated;
1088 rslot = &mixer->slots[ptr->oss_id];
1089 mixer_slot_clear(rslot);
1090 rslot->stereo = slot.channels > 1 ? 1 : 0;
1091 rslot->get_volume = snd_mixer_oss_get_volume1;
1092 rslot->put_volume = snd_mixer_oss_put_volume1;
1093 /* note: ES18xx have both Capture Source and XX Capture Volume !!! */
1094 if (slot.present & SNDRV_MIXER_OSS_PRESENT_CSWITCH) {
1095 rslot->get_recsrc = snd_mixer_oss_get_recsrc1_sw;
1096 rslot->put_recsrc = snd_mixer_oss_put_recsrc1_sw;
1097 } else if (slot.present & SNDRV_MIXER_OSS_PRESENT_CROUTE) {
1098 rslot->get_recsrc = snd_mixer_oss_get_recsrc1_route;
1099 rslot->put_recsrc = snd_mixer_oss_put_recsrc1_route;
1100 } else if (slot.present & SNDRV_MIXER_OSS_PRESENT_CAPTURE) {
1101 mixer->mask_recsrc |= 1 << ptr->oss_id;
1103 rslot->private_data = pslot;
1104 rslot->private_free = snd_mixer_oss_slot_free;
1110 #ifdef CONFIG_PROC_FS
1113 #define MIXER_VOL(name) [SOUND_MIXER_##name] = #name
1114 static char *oss_mixer_names[SNDRV_OSS_MAX_MIXERS] = {
1132 MIXER_VOL(DIGITAL1),
1133 MIXER_VOL(DIGITAL2),
1134 MIXER_VOL(DIGITAL3),
1136 MIXER_VOL(PHONEOUT),
1146 static void snd_mixer_oss_proc_read(struct snd_info_entry *entry,
1147 struct snd_info_buffer *buffer)
1149 struct snd_mixer_oss *mixer = entry->private_data;
1152 mutex_lock(&mixer->reg_mutex);
1153 for (i = 0; i < SNDRV_OSS_MAX_MIXERS; i++) {
1156 if (! oss_mixer_names[i])
1158 p = (struct slot *)mixer->slots[i].private_data;
1159 snd_iprintf(buffer, "%s ", oss_mixer_names[i]);
1160 if (p && p->assigned)
1161 snd_iprintf(buffer, "\"%s\" %d\n",
1163 p->assigned->index);
1165 snd_iprintf(buffer, "\"\" 0\n");
1167 mutex_unlock(&mixer->reg_mutex);
1170 static void snd_mixer_oss_proc_write(struct snd_info_entry *entry,
1171 struct snd_info_buffer *buffer)
1173 struct snd_mixer_oss *mixer = entry->private_data;
1174 char line[128], str[32], idxstr[16];
1177 struct snd_mixer_oss_assign_table *tbl;
1180 while (!snd_info_get_line(buffer, line, sizeof(line))) {
1181 cptr = snd_info_get_str(str, line, sizeof(str));
1182 for (ch = 0; ch < SNDRV_OSS_MAX_MIXERS; ch++)
1183 if (oss_mixer_names[ch] && strcmp(oss_mixer_names[ch], str) == 0)
1185 if (ch >= SNDRV_OSS_MAX_MIXERS) {
1186 snd_printk(KERN_ERR "mixer_oss: invalid OSS volume '%s'\n", str);
1189 cptr = snd_info_get_str(str, cptr, sizeof(str));
1191 /* remove the entry */
1192 mutex_lock(&mixer->reg_mutex);
1193 mixer_slot_clear(&mixer->slots[ch]);
1194 mutex_unlock(&mixer->reg_mutex);
1197 snd_info_get_str(idxstr, cptr, sizeof(idxstr));
1198 idx = simple_strtoul(idxstr, NULL, 10);
1199 if (idx >= 0x4000) { /* too big */
1200 snd_printk(KERN_ERR "mixer_oss: invalid index %d\n", idx);
1203 mutex_lock(&mixer->reg_mutex);
1204 slot = (struct slot *)mixer->slots[ch].private_data;
1205 if (slot && slot->assigned &&
1206 slot->assigned->index == idx && ! strcmp(slot->assigned->name, str))
1209 tbl = kmalloc(sizeof(*tbl), GFP_KERNEL);
1211 snd_printk(KERN_ERR "mixer_oss: no memory\n");
1215 tbl->name = kstrdup(str, GFP_KERNEL);
1221 if (snd_mixer_oss_build_input(mixer, tbl, 1, 1) <= 0) {
1226 mutex_unlock(&mixer->reg_mutex);
1230 static void snd_mixer_oss_proc_init(struct snd_mixer_oss *mixer)
1232 struct snd_info_entry *entry;
1234 entry = snd_info_create_card_entry(mixer->card, "oss_mixer",
1235 mixer->card->proc_root);
1238 entry->content = SNDRV_INFO_CONTENT_TEXT;
1239 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
1240 entry->c.text.read = snd_mixer_oss_proc_read;
1241 entry->c.text.write = snd_mixer_oss_proc_write;
1242 entry->private_data = mixer;
1243 if (snd_info_register(entry) < 0) {
1244 snd_info_free_entry(entry);
1247 mixer->proc_entry = entry;
1250 static void snd_mixer_oss_proc_done(struct snd_mixer_oss *mixer)
1252 snd_info_free_entry(mixer->proc_entry);
1253 mixer->proc_entry = NULL;
1255 #else /* !CONFIG_PROC_FS */
1256 #define snd_mixer_oss_proc_init(mix)
1257 #define snd_mixer_oss_proc_done(mix)
1258 #endif /* CONFIG_PROC_FS */
1260 static void snd_mixer_oss_build(struct snd_mixer_oss *mixer)
1262 static struct snd_mixer_oss_assign_table table[] = {
1263 { SOUND_MIXER_VOLUME, "Master", 0 },
1264 { SOUND_MIXER_VOLUME, "Front", 0 }, /* fallback */
1265 { SOUND_MIXER_BASS, "Tone Control - Bass", 0 },
1266 { SOUND_MIXER_TREBLE, "Tone Control - Treble", 0 },
1267 { SOUND_MIXER_SYNTH, "Synth", 0 },
1268 { SOUND_MIXER_SYNTH, "FM", 0 }, /* fallback */
1269 { SOUND_MIXER_SYNTH, "Music", 0 }, /* fallback */
1270 { SOUND_MIXER_PCM, "PCM", 0 },
1271 { SOUND_MIXER_SPEAKER, "Beep", 0 },
1272 { SOUND_MIXER_SPEAKER, "PC Speaker", 0 }, /* fallback */
1273 { SOUND_MIXER_SPEAKER, "Speaker", 0 }, /* fallback */
1274 { SOUND_MIXER_LINE, "Line", 0 },
1275 { SOUND_MIXER_MIC, "Mic", 0 },
1276 { SOUND_MIXER_CD, "CD", 0 },
1277 { SOUND_MIXER_IMIX, "Monitor Mix", 0 },
1278 { SOUND_MIXER_ALTPCM, "PCM", 1 },
1279 { SOUND_MIXER_ALTPCM, "Headphone", 0 }, /* fallback */
1280 { SOUND_MIXER_ALTPCM, "Wave", 0 }, /* fallback */
1281 { SOUND_MIXER_RECLEV, "-- nothing --", 0 },
1282 { SOUND_MIXER_IGAIN, "Capture", 0 },
1283 { SOUND_MIXER_OGAIN, "Playback", 0 },
1284 { SOUND_MIXER_LINE1, "Aux", 0 },
1285 { SOUND_MIXER_LINE2, "Aux", 1 },
1286 { SOUND_MIXER_LINE3, "Aux", 2 },
1287 { SOUND_MIXER_DIGITAL1, "Digital", 0 },
1288 { SOUND_MIXER_DIGITAL1, "IEC958", 0 }, /* fallback */
1289 { SOUND_MIXER_DIGITAL1, "IEC958 Optical", 0 }, /* fallback */
1290 { SOUND_MIXER_DIGITAL1, "IEC958 Coaxial", 0 }, /* fallback */
1291 { SOUND_MIXER_DIGITAL2, "Digital", 1 },
1292 { SOUND_MIXER_DIGITAL3, "Digital", 2 },
1293 { SOUND_MIXER_PHONEIN, "Phone", 0 },
1294 { SOUND_MIXER_PHONEOUT, "Master Mono", 0 },
1295 { SOUND_MIXER_PHONEOUT, "Speaker", 0 }, /*fallback*/
1296 { SOUND_MIXER_PHONEOUT, "Mono", 0 }, /*fallback*/
1297 { SOUND_MIXER_PHONEOUT, "Phone", 0 }, /* fallback */
1298 { SOUND_MIXER_VIDEO, "Video", 0 },
1299 { SOUND_MIXER_RADIO, "Radio", 0 },
1300 { SOUND_MIXER_MONITOR, "Monitor", 0 }
1304 for (idx = 0; idx < ARRAY_SIZE(table); idx++)
1305 snd_mixer_oss_build_input(mixer, &table[idx], 0, 0);
1306 if (mixer->mask_recsrc) {
1307 mixer->get_recsrc = snd_mixer_oss_get_recsrc2;
1308 mixer->put_recsrc = snd_mixer_oss_put_recsrc2;
1316 static int snd_mixer_oss_free1(void *private)
1318 struct snd_mixer_oss *mixer = private;
1319 struct snd_card *card;
1325 if (snd_BUG_ON(mixer != card->mixer_oss))
1327 card->mixer_oss = NULL;
1328 for (idx = 0; idx < SNDRV_OSS_MAX_MIXERS; idx++) {
1329 struct snd_mixer_oss_slot *chn = &mixer->slots[idx];
1330 if (chn->private_free)
1331 chn->private_free(chn);
1337 static int snd_mixer_oss_notify_handler(struct snd_card *card, int cmd)
1339 struct snd_mixer_oss *mixer;
1341 if (cmd == SND_MIXER_OSS_NOTIFY_REGISTER) {
1345 mixer = kcalloc(2, sizeof(*mixer), GFP_KERNEL);
1348 mutex_init(&mixer->reg_mutex);
1349 sprintf(name, "mixer%i%i", card->number, 0);
1350 if ((err = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER,
1352 &snd_mixer_oss_f_ops, card,
1354 snd_printk(KERN_ERR "unable to register OSS mixer device %i:%i\n",
1359 mixer->oss_dev_alloc = 1;
1361 if (*card->mixername)
1362 strlcpy(mixer->name, card->mixername, sizeof(mixer->name));
1364 strlcpy(mixer->name, name, sizeof(mixer->name));
1365 #ifdef SNDRV_OSS_INFO_DEV_MIXERS
1366 snd_oss_info_register(SNDRV_OSS_INFO_DEV_MIXERS,
1370 for (idx = 0; idx < SNDRV_OSS_MAX_MIXERS; idx++)
1371 mixer->slots[idx].number = idx;
1372 card->mixer_oss = mixer;
1373 snd_mixer_oss_build(mixer);
1374 snd_mixer_oss_proc_init(mixer);
1376 mixer = card->mixer_oss;
1379 if (mixer->oss_dev_alloc) {
1380 #ifdef SNDRV_OSS_INFO_DEV_MIXERS
1381 snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_MIXERS, mixer->card->number);
1383 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER, mixer->card, 0);
1384 mixer->oss_dev_alloc = 0;
1386 if (cmd == SND_MIXER_OSS_NOTIFY_DISCONNECT)
1388 snd_mixer_oss_proc_done(mixer);
1389 return snd_mixer_oss_free1(mixer);
1394 static int __init alsa_mixer_oss_init(void)
1398 snd_mixer_oss_notify_callback = snd_mixer_oss_notify_handler;
1399 for (idx = 0; idx < SNDRV_CARDS; idx++) {
1401 snd_mixer_oss_notify_handler(snd_cards[idx], SND_MIXER_OSS_NOTIFY_REGISTER);
1406 static void __exit alsa_mixer_oss_exit(void)
1410 snd_mixer_oss_notify_callback = NULL;
1411 for (idx = 0; idx < SNDRV_CARDS; idx++) {
1413 snd_mixer_oss_notify_handler(snd_cards[idx], SND_MIXER_OSS_NOTIFY_FREE);
1417 module_init(alsa_mixer_oss_init)
1418 module_exit(alsa_mixer_oss_exit)
1420 EXPORT_SYMBOL(snd_mixer_oss_ioctl_card);