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 <linux/module.h>
27 #include <sound/core.h>
28 #include <sound/minors.h>
29 #include <sound/control.h>
30 #include <sound/info.h>
31 #include <sound/mixer_oss.h>
32 #include <linux/soundcard.h>
34 #define OSS_ALSAEMULVER _SIOR ('M', 249, int)
36 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
37 MODULE_DESCRIPTION("Mixer OSS emulation for ALSA.");
38 MODULE_LICENSE("GPL");
39 MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_MIXER);
41 static int snd_mixer_oss_open(struct inode *inode, struct file *file)
43 struct snd_card *card;
44 struct snd_mixer_oss_file *fmixer;
47 err = nonseekable_open(inode, file);
51 card = snd_lookup_oss_minor_data(iminor(inode),
52 SNDRV_OSS_DEVICE_TYPE_MIXER);
55 if (card->mixer_oss == NULL) {
59 err = snd_card_file_add(card, file);
64 fmixer = kzalloc(sizeof(*fmixer), GFP_KERNEL);
66 snd_card_file_remove(card, file);
71 fmixer->mixer = card->mixer_oss;
72 file->private_data = fmixer;
73 if (!try_module_get(card->module)) {
75 snd_card_file_remove(card, file);
83 static int snd_mixer_oss_release(struct inode *inode, struct file *file)
85 struct snd_mixer_oss_file *fmixer;
87 if (file->private_data) {
88 fmixer = file->private_data;
89 module_put(fmixer->card->module);
90 snd_card_file_remove(fmixer->card, file);
96 static int snd_mixer_oss_info(struct snd_mixer_oss_file *fmixer,
97 mixer_info __user *_info)
99 struct snd_card *card = fmixer->card;
100 struct snd_mixer_oss *mixer = fmixer->mixer;
101 struct mixer_info info;
103 memset(&info, 0, sizeof(info));
104 strlcpy(info.id, mixer && mixer->id[0] ? mixer->id : card->driver, sizeof(info.id));
105 strlcpy(info.name, mixer && mixer->name[0] ? mixer->name : card->mixername, sizeof(info.name));
106 info.modify_counter = card->mixer_oss_change_count;
107 if (copy_to_user(_info, &info, sizeof(info)))
112 static int snd_mixer_oss_info_obsolete(struct snd_mixer_oss_file *fmixer,
113 _old_mixer_info __user *_info)
115 struct snd_card *card = fmixer->card;
116 struct snd_mixer_oss *mixer = fmixer->mixer;
117 _old_mixer_info info;
119 memset(&info, 0, sizeof(info));
120 strlcpy(info.id, mixer && mixer->id[0] ? mixer->id : card->driver, sizeof(info.id));
121 strlcpy(info.name, mixer && mixer->name[0] ? mixer->name : card->mixername, sizeof(info.name));
122 if (copy_to_user(_info, &info, sizeof(info)))
127 static int snd_mixer_oss_caps(struct snd_mixer_oss_file *fmixer)
129 struct snd_mixer_oss *mixer = fmixer->mixer;
134 if (mixer->get_recsrc && mixer->put_recsrc)
135 result |= SOUND_CAP_EXCL_INPUT;
139 static int snd_mixer_oss_devmask(struct snd_mixer_oss_file *fmixer)
141 struct snd_mixer_oss *mixer = fmixer->mixer;
142 struct snd_mixer_oss_slot *pslot;
147 mutex_lock(&mixer->reg_mutex);
148 for (chn = 0; chn < 31; chn++) {
149 pslot = &mixer->slots[chn];
150 if (pslot->put_volume || pslot->put_recsrc)
153 mutex_unlock(&mixer->reg_mutex);
157 static int snd_mixer_oss_stereodevs(struct snd_mixer_oss_file *fmixer)
159 struct snd_mixer_oss *mixer = fmixer->mixer;
160 struct snd_mixer_oss_slot *pslot;
165 mutex_lock(&mixer->reg_mutex);
166 for (chn = 0; chn < 31; chn++) {
167 pslot = &mixer->slots[chn];
168 if (pslot->put_volume && pslot->stereo)
171 mutex_unlock(&mixer->reg_mutex);
175 static int snd_mixer_oss_recmask(struct snd_mixer_oss_file *fmixer)
177 struct snd_mixer_oss *mixer = fmixer->mixer;
182 mutex_lock(&mixer->reg_mutex);
183 if (mixer->put_recsrc && mixer->get_recsrc) { /* exclusive */
184 result = mixer->mask_recsrc;
186 struct snd_mixer_oss_slot *pslot;
188 for (chn = 0; chn < 31; chn++) {
189 pslot = &mixer->slots[chn];
190 if (pslot->put_recsrc)
194 mutex_unlock(&mixer->reg_mutex);
198 static int snd_mixer_oss_get_recsrc(struct snd_mixer_oss_file *fmixer)
200 struct snd_mixer_oss *mixer = fmixer->mixer;
205 mutex_lock(&mixer->reg_mutex);
206 if (mixer->put_recsrc && mixer->get_recsrc) { /* exclusive */
208 result = mixer->get_recsrc(fmixer, &index);
213 struct snd_mixer_oss_slot *pslot;
215 for (chn = 0; chn < 31; chn++) {
216 pslot = &mixer->slots[chn];
217 if (pslot->get_recsrc) {
219 pslot->get_recsrc(fmixer, pslot, &active);
225 mixer->oss_recsrc = result;
227 mutex_unlock(&mixer->reg_mutex);
231 static int snd_mixer_oss_set_recsrc(struct snd_mixer_oss_file *fmixer, int recsrc)
233 struct snd_mixer_oss *mixer = fmixer->mixer;
234 struct snd_mixer_oss_slot *pslot;
241 mutex_lock(&mixer->reg_mutex);
242 if (mixer->get_recsrc && mixer->put_recsrc) { /* exclusive input */
243 if (recsrc & ~mixer->oss_recsrc)
244 recsrc &= ~mixer->oss_recsrc;
245 mixer->put_recsrc(fmixer, ffz(~recsrc));
246 mixer->get_recsrc(fmixer, &index);
249 for (chn = 0; chn < 31; chn++) {
250 pslot = &mixer->slots[chn];
251 if (pslot->put_recsrc) {
252 active = (recsrc & (1 << chn)) ? 1 : 0;
253 pslot->put_recsrc(fmixer, pslot, active);
257 for (chn = 0; chn < 31; chn++) {
258 pslot = &mixer->slots[chn];
259 if (pslot->get_recsrc) {
261 pslot->get_recsrc(fmixer, pslot, &active);
267 mutex_unlock(&mixer->reg_mutex);
271 static int snd_mixer_oss_get_volume(struct snd_mixer_oss_file *fmixer, int slot)
273 struct snd_mixer_oss *mixer = fmixer->mixer;
274 struct snd_mixer_oss_slot *pslot;
275 int result = 0, left, right;
277 if (mixer == NULL || slot > 30)
279 mutex_lock(&mixer->reg_mutex);
280 pslot = &mixer->slots[slot];
281 left = pslot->volume[0];
282 right = pslot->volume[1];
283 if (pslot->get_volume)
284 result = pslot->get_volume(fmixer, pslot, &left, &right);
287 if (snd_BUG_ON(left < 0 || left > 100)) {
291 if (snd_BUG_ON(right < 0 || right > 100)) {
296 pslot->volume[0] = left;
297 pslot->volume[1] = right;
298 result = (left & 0xff) | ((right & 0xff) << 8);
301 mutex_unlock(&mixer->reg_mutex);
305 static int snd_mixer_oss_set_volume(struct snd_mixer_oss_file *fmixer,
306 int slot, int volume)
308 struct snd_mixer_oss *mixer = fmixer->mixer;
309 struct snd_mixer_oss_slot *pslot;
310 int result = 0, left = volume & 0xff, right = (volume >> 8) & 0xff;
312 if (mixer == NULL || slot > 30)
314 mutex_lock(&mixer->reg_mutex);
315 pslot = &mixer->slots[slot];
322 if (pslot->put_volume)
323 result = pslot->put_volume(fmixer, pslot, left, right);
326 pslot->volume[0] = left;
327 pslot->volume[1] = right;
328 result = (left & 0xff) | ((right & 0xff) << 8);
330 mutex_unlock(&mixer->reg_mutex);
334 static int snd_mixer_oss_ioctl1(struct snd_mixer_oss_file *fmixer, unsigned int cmd, unsigned long arg)
336 void __user *argp = (void __user *)arg;
337 int __user *p = argp;
340 if (snd_BUG_ON(!fmixer))
342 if (((cmd >> 8) & 0xff) == 'M') {
344 case SOUND_MIXER_INFO:
345 return snd_mixer_oss_info(fmixer, argp);
346 case SOUND_OLD_MIXER_INFO:
347 return snd_mixer_oss_info_obsolete(fmixer, argp);
348 case SOUND_MIXER_WRITE_RECSRC:
349 if (get_user(tmp, p))
351 tmp = snd_mixer_oss_set_recsrc(fmixer, tmp);
354 return put_user(tmp, p);
356 return put_user(SNDRV_OSS_VERSION, p);
357 case OSS_ALSAEMULVER:
358 return put_user(1, p);
359 case SOUND_MIXER_READ_DEVMASK:
360 tmp = snd_mixer_oss_devmask(fmixer);
363 return put_user(tmp, p);
364 case SOUND_MIXER_READ_STEREODEVS:
365 tmp = snd_mixer_oss_stereodevs(fmixer);
368 return put_user(tmp, p);
369 case SOUND_MIXER_READ_RECMASK:
370 tmp = snd_mixer_oss_recmask(fmixer);
373 return put_user(tmp, p);
374 case SOUND_MIXER_READ_CAPS:
375 tmp = snd_mixer_oss_caps(fmixer);
378 return put_user(tmp, p);
379 case SOUND_MIXER_READ_RECSRC:
380 tmp = snd_mixer_oss_get_recsrc(fmixer);
383 return put_user(tmp, p);
387 if (get_user(tmp, p))
389 tmp = snd_mixer_oss_set_volume(fmixer, cmd & 0xff, tmp);
392 return put_user(tmp, p);
393 } else if (cmd & SIOC_OUT) {
394 tmp = snd_mixer_oss_get_volume(fmixer, cmd & 0xff);
397 return put_user(tmp, p);
402 static long snd_mixer_oss_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
404 return snd_mixer_oss_ioctl1(file->private_data, cmd, arg);
407 int snd_mixer_oss_ioctl_card(struct snd_card *card, unsigned int cmd, unsigned long arg)
409 struct snd_mixer_oss_file fmixer;
411 if (snd_BUG_ON(!card))
413 if (card->mixer_oss == NULL)
415 memset(&fmixer, 0, sizeof(fmixer));
417 fmixer.mixer = card->mixer_oss;
418 return snd_mixer_oss_ioctl1(&fmixer, cmd, arg);
423 #define snd_mixer_oss_ioctl_compat snd_mixer_oss_ioctl
425 #define snd_mixer_oss_ioctl_compat NULL
432 static const struct file_operations snd_mixer_oss_f_ops =
434 .owner = THIS_MODULE,
435 .open = snd_mixer_oss_open,
436 .release = snd_mixer_oss_release,
438 .unlocked_ioctl = snd_mixer_oss_ioctl,
439 .compat_ioctl = snd_mixer_oss_ioctl_compat,
446 static long snd_mixer_oss_conv(long val, long omin, long omax, long nmin, long nmax)
448 long orange = omax - omin, nrange = nmax - nmin;
452 return ((nrange * (val - omin)) + (orange / 2)) / orange + nmin;
455 /* convert from alsa native to oss values (0-100) */
456 static long snd_mixer_oss_conv1(long val, long min, long max, int *old)
458 if (val == snd_mixer_oss_conv(*old, 0, 100, min, max))
460 return snd_mixer_oss_conv(val, min, max, 0, 100);
463 /* convert from oss to alsa native values */
464 static long snd_mixer_oss_conv2(long val, long min, long max)
466 return snd_mixer_oss_conv(val, 0, 100, min, max);
470 static void snd_mixer_oss_recsrce_set(struct snd_card *card, int slot)
472 struct snd_mixer_oss *mixer = card->mixer_oss;
474 mixer->mask_recsrc |= 1 << slot;
477 static int snd_mixer_oss_recsrce_get(struct snd_card *card, int slot)
479 struct snd_mixer_oss *mixer = card->mixer_oss;
480 if (mixer && (mixer->mask_recsrc & (1 << slot)))
486 #define SNDRV_MIXER_OSS_SIGNATURE 0x65999250
488 #define SNDRV_MIXER_OSS_ITEM_GLOBAL 0
489 #define SNDRV_MIXER_OSS_ITEM_GSWITCH 1
490 #define SNDRV_MIXER_OSS_ITEM_GROUTE 2
491 #define SNDRV_MIXER_OSS_ITEM_GVOLUME 3
492 #define SNDRV_MIXER_OSS_ITEM_PSWITCH 4
493 #define SNDRV_MIXER_OSS_ITEM_PROUTE 5
494 #define SNDRV_MIXER_OSS_ITEM_PVOLUME 6
495 #define SNDRV_MIXER_OSS_ITEM_CSWITCH 7
496 #define SNDRV_MIXER_OSS_ITEM_CROUTE 8
497 #define SNDRV_MIXER_OSS_ITEM_CVOLUME 9
498 #define SNDRV_MIXER_OSS_ITEM_CAPTURE 10
500 #define SNDRV_MIXER_OSS_ITEM_COUNT 11
502 #define SNDRV_MIXER_OSS_PRESENT_GLOBAL (1<<0)
503 #define SNDRV_MIXER_OSS_PRESENT_GSWITCH (1<<1)
504 #define SNDRV_MIXER_OSS_PRESENT_GROUTE (1<<2)
505 #define SNDRV_MIXER_OSS_PRESENT_GVOLUME (1<<3)
506 #define SNDRV_MIXER_OSS_PRESENT_PSWITCH (1<<4)
507 #define SNDRV_MIXER_OSS_PRESENT_PROUTE (1<<5)
508 #define SNDRV_MIXER_OSS_PRESENT_PVOLUME (1<<6)
509 #define SNDRV_MIXER_OSS_PRESENT_CSWITCH (1<<7)
510 #define SNDRV_MIXER_OSS_PRESENT_CROUTE (1<<8)
511 #define SNDRV_MIXER_OSS_PRESENT_CVOLUME (1<<9)
512 #define SNDRV_MIXER_OSS_PRESENT_CAPTURE (1<<10)
515 unsigned int signature;
516 unsigned int present;
517 unsigned int channels;
518 unsigned int numid[SNDRV_MIXER_OSS_ITEM_COUNT];
519 unsigned int capture_item;
520 struct snd_mixer_oss_assign_table *assigned;
521 unsigned int allocated: 1;
524 #define ID_UNKNOWN ((unsigned int)-1)
526 static struct snd_kcontrol *snd_mixer_oss_test_id(struct snd_mixer_oss *mixer, const char *name, int index)
528 struct snd_card *card = mixer->card;
529 struct snd_ctl_elem_id id;
531 memset(&id, 0, sizeof(id));
532 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
533 strlcpy(id.name, name, sizeof(id.name));
535 return snd_ctl_find_id(card, &id);
538 static void snd_mixer_oss_get_volume1_vol(struct snd_mixer_oss_file *fmixer,
539 struct snd_mixer_oss_slot *pslot,
541 int *left, int *right)
543 struct snd_ctl_elem_info *uinfo;
544 struct snd_ctl_elem_value *uctl;
545 struct snd_kcontrol *kctl;
546 struct snd_card *card = fmixer->card;
548 if (numid == ID_UNKNOWN)
550 down_read(&card->controls_rwsem);
551 if ((kctl = snd_ctl_find_numid(card, numid)) == NULL) {
552 up_read(&card->controls_rwsem);
555 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
556 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
557 if (uinfo == NULL || uctl == NULL)
559 if (kctl->info(kctl, uinfo))
561 if (kctl->get(kctl, uctl))
563 if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN &&
564 uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1)
566 *left = snd_mixer_oss_conv1(uctl->value.integer.value[0], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[0]);
567 if (uinfo->count > 1)
568 *right = snd_mixer_oss_conv1(uctl->value.integer.value[1], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1]);
570 up_read(&card->controls_rwsem);
575 static void snd_mixer_oss_get_volume1_sw(struct snd_mixer_oss_file *fmixer,
576 struct snd_mixer_oss_slot *pslot,
578 int *left, int *right,
581 struct snd_ctl_elem_info *uinfo;
582 struct snd_ctl_elem_value *uctl;
583 struct snd_kcontrol *kctl;
584 struct snd_card *card = fmixer->card;
586 if (numid == ID_UNKNOWN)
588 down_read(&card->controls_rwsem);
589 if ((kctl = snd_ctl_find_numid(card, numid)) == NULL) {
590 up_read(&card->controls_rwsem);
593 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
594 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
595 if (uinfo == NULL || uctl == NULL)
597 if (kctl->info(kctl, uinfo))
599 if (kctl->get(kctl, uctl))
601 if (!uctl->value.integer.value[0]) {
603 if (uinfo->count == 1)
606 if (uinfo->count > 1 && !uctl->value.integer.value[route ? 3 : 1])
609 up_read(&card->controls_rwsem);
614 static int snd_mixer_oss_get_volume1(struct snd_mixer_oss_file *fmixer,
615 struct snd_mixer_oss_slot *pslot,
616 int *left, int *right)
618 struct slot *slot = pslot->private_data;
620 *left = *right = 100;
621 if (slot->present & SNDRV_MIXER_OSS_PRESENT_PVOLUME) {
622 snd_mixer_oss_get_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PVOLUME], left, right);
623 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GVOLUME) {
624 snd_mixer_oss_get_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GVOLUME], left, right);
625 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GLOBAL) {
626 snd_mixer_oss_get_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GLOBAL], left, right);
628 if (slot->present & SNDRV_MIXER_OSS_PRESENT_PSWITCH) {
629 snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PSWITCH], left, right, 0);
630 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GSWITCH) {
631 snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GSWITCH], left, right, 0);
632 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_PROUTE) {
633 snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PROUTE], left, right, 1);
634 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GROUTE) {
635 snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GROUTE], left, right, 1);
640 static void snd_mixer_oss_put_volume1_vol(struct snd_mixer_oss_file *fmixer,
641 struct snd_mixer_oss_slot *pslot,
645 struct snd_ctl_elem_info *uinfo;
646 struct snd_ctl_elem_value *uctl;
647 struct snd_kcontrol *kctl;
648 struct snd_card *card = fmixer->card;
651 if (numid == ID_UNKNOWN)
653 down_read(&card->controls_rwsem);
654 if ((kctl = snd_ctl_find_numid(card, numid)) == NULL) {
655 up_read(&card->controls_rwsem);
658 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
659 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
660 if (uinfo == NULL || uctl == NULL)
662 if (kctl->info(kctl, uinfo))
664 if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN &&
665 uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1)
667 uctl->value.integer.value[0] = snd_mixer_oss_conv2(left, uinfo->value.integer.min, uinfo->value.integer.max);
668 if (uinfo->count > 1)
669 uctl->value.integer.value[1] = snd_mixer_oss_conv2(right, uinfo->value.integer.min, uinfo->value.integer.max);
670 if ((res = kctl->put(kctl, uctl)) < 0)
673 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
675 up_read(&card->controls_rwsem);
680 static void snd_mixer_oss_put_volume1_sw(struct snd_mixer_oss_file *fmixer,
681 struct snd_mixer_oss_slot *pslot,
686 struct snd_ctl_elem_info *uinfo;
687 struct snd_ctl_elem_value *uctl;
688 struct snd_kcontrol *kctl;
689 struct snd_card *card = fmixer->card;
692 if (numid == ID_UNKNOWN)
694 down_read(&card->controls_rwsem);
695 if ((kctl = snd_ctl_find_numid(card, numid)) == NULL) {
696 up_read(&card->controls_rwsem);
699 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
700 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
701 if (uinfo == NULL || uctl == NULL)
703 if (kctl->info(kctl, uinfo))
705 if (uinfo->count > 1) {
706 uctl->value.integer.value[0] = left > 0 ? 1 : 0;
707 uctl->value.integer.value[route ? 3 : 1] = right > 0 ? 1 : 0;
709 uctl->value.integer.value[1] =
710 uctl->value.integer.value[2] = 0;
713 uctl->value.integer.value[0] = (left > 0 || right > 0) ? 1 : 0;
715 if ((res = kctl->put(kctl, uctl)) < 0)
718 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
720 up_read(&card->controls_rwsem);
725 static int snd_mixer_oss_put_volume1(struct snd_mixer_oss_file *fmixer,
726 struct snd_mixer_oss_slot *pslot,
729 struct slot *slot = pslot->private_data;
731 if (slot->present & SNDRV_MIXER_OSS_PRESENT_PVOLUME) {
732 snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PVOLUME], left, right);
733 if (slot->present & SNDRV_MIXER_OSS_PRESENT_CVOLUME)
734 snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CVOLUME], left, right);
735 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_CVOLUME) {
736 snd_mixer_oss_put_volume1_vol(fmixer, pslot,
737 slot->numid[SNDRV_MIXER_OSS_ITEM_CVOLUME], left, right);
738 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GVOLUME) {
739 snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GVOLUME], left, right);
740 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GLOBAL) {
741 snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GLOBAL], left, right);
744 if (slot->present & SNDRV_MIXER_OSS_PRESENT_PSWITCH)
745 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PSWITCH], left, right, 0);
746 if (slot->present & SNDRV_MIXER_OSS_PRESENT_CSWITCH)
747 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CSWITCH], left, right, 0);
748 if (slot->present & SNDRV_MIXER_OSS_PRESENT_GSWITCH)
749 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GSWITCH], left, right, 0);
750 if (slot->present & SNDRV_MIXER_OSS_PRESENT_PROUTE)
751 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PROUTE], left, right, 1);
752 if (slot->present & SNDRV_MIXER_OSS_PRESENT_CROUTE)
753 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CROUTE], left, right, 1);
754 if (slot->present & SNDRV_MIXER_OSS_PRESENT_GROUTE)
755 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GROUTE], left, right, 1);
757 if (slot->present & SNDRV_MIXER_OSS_PRESENT_PSWITCH) {
758 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PSWITCH], left, right, 0);
759 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_CSWITCH) {
760 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CSWITCH], left, right, 0);
761 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GSWITCH) {
762 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GSWITCH], left, right, 0);
763 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_PROUTE) {
764 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PROUTE], left, right, 1);
765 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_CROUTE) {
766 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CROUTE], left, right, 1);
767 } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GROUTE) {
768 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GROUTE], left, right, 1);
774 static int snd_mixer_oss_get_recsrc1_sw(struct snd_mixer_oss_file *fmixer,
775 struct snd_mixer_oss_slot *pslot,
778 struct slot *slot = pslot->private_data;
782 snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CSWITCH], &left, &right, 0);
783 *active = (left || right) ? 1 : 0;
787 static int snd_mixer_oss_get_recsrc1_route(struct snd_mixer_oss_file *fmixer,
788 struct snd_mixer_oss_slot *pslot,
791 struct slot *slot = pslot->private_data;
795 snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CROUTE], &left, &right, 1);
796 *active = (left || right) ? 1 : 0;
800 static int snd_mixer_oss_put_recsrc1_sw(struct snd_mixer_oss_file *fmixer,
801 struct snd_mixer_oss_slot *pslot,
804 struct slot *slot = pslot->private_data;
806 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CSWITCH], active, active, 0);
810 static int snd_mixer_oss_put_recsrc1_route(struct snd_mixer_oss_file *fmixer,
811 struct snd_mixer_oss_slot *pslot,
814 struct slot *slot = pslot->private_data;
816 snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CROUTE], active, active, 1);
820 static int snd_mixer_oss_get_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned int *active_index)
822 struct snd_card *card = fmixer->card;
823 struct snd_mixer_oss *mixer = fmixer->mixer;
824 struct snd_kcontrol *kctl;
825 struct snd_mixer_oss_slot *pslot;
827 struct snd_ctl_elem_info *uinfo;
828 struct snd_ctl_elem_value *uctl;
831 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
832 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
833 if (uinfo == NULL || uctl == NULL) {
837 down_read(&card->controls_rwsem);
838 kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
843 if ((err = kctl->info(kctl, uinfo)) < 0)
845 if ((err = kctl->get(kctl, uctl)) < 0)
847 for (idx = 0; idx < 32; idx++) {
848 if (!(mixer->mask_recsrc & (1 << idx)))
850 pslot = &mixer->slots[idx];
851 slot = pslot->private_data;
852 if (slot->signature != SNDRV_MIXER_OSS_SIGNATURE)
854 if (!(slot->present & SNDRV_MIXER_OSS_PRESENT_CAPTURE))
856 if (slot->capture_item == uctl->value.enumerated.item[0]) {
863 up_read(&card->controls_rwsem);
870 static int snd_mixer_oss_put_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned int active_index)
872 struct snd_card *card = fmixer->card;
873 struct snd_mixer_oss *mixer = fmixer->mixer;
874 struct snd_kcontrol *kctl;
875 struct snd_mixer_oss_slot *pslot;
876 struct slot *slot = NULL;
877 struct snd_ctl_elem_info *uinfo;
878 struct snd_ctl_elem_value *uctl;
882 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
883 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
884 if (uinfo == NULL || uctl == NULL) {
888 down_read(&card->controls_rwsem);
889 kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
894 if ((err = kctl->info(kctl, uinfo)) < 0)
896 for (idx = 0; idx < 32; idx++) {
897 if (!(mixer->mask_recsrc & (1 << idx)))
899 pslot = &mixer->slots[idx];
900 slot = pslot->private_data;
901 if (slot->signature != SNDRV_MIXER_OSS_SIGNATURE)
903 if (!(slot->present & SNDRV_MIXER_OSS_PRESENT_CAPTURE))
905 if (idx == active_index)
911 for (idx = 0; idx < uinfo->count; idx++)
912 uctl->value.enumerated.item[idx] = slot->capture_item;
913 err = kctl->put(kctl, uctl);
915 snd_ctl_notify(fmixer->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
918 up_read(&card->controls_rwsem);
925 struct snd_mixer_oss_assign_table {
931 static int snd_mixer_oss_build_test(struct snd_mixer_oss *mixer, struct slot *slot, const char *name, int index, int item)
933 struct snd_ctl_elem_info *info;
934 struct snd_kcontrol *kcontrol;
935 struct snd_card *card = mixer->card;
938 down_read(&card->controls_rwsem);
939 kcontrol = snd_mixer_oss_test_id(mixer, name, index);
940 if (kcontrol == NULL) {
941 up_read(&card->controls_rwsem);
944 info = kmalloc(sizeof(*info), GFP_KERNEL);
946 up_read(&card->controls_rwsem);
949 if ((err = kcontrol->info(kcontrol, info)) < 0) {
950 up_read(&card->controls_rwsem);
954 slot->numid[item] = kcontrol->id.numid;
955 up_read(&card->controls_rwsem);
956 if (info->count > slot->channels)
957 slot->channels = info->count;
958 slot->present |= 1 << item;
963 static void snd_mixer_oss_slot_free(struct snd_mixer_oss_slot *chn)
965 struct slot *p = chn->private_data;
967 if (p->allocated && p->assigned) {
968 kfree(p->assigned->name);
975 static void mixer_slot_clear(struct snd_mixer_oss_slot *rslot)
977 int idx = rslot->number; /* remember this */
978 if (rslot->private_free)
979 rslot->private_free(rslot);
980 memset(rslot, 0, sizeof(*rslot));
984 /* In a separate function to keep gcc 3.2 happy - do NOT merge this in
985 snd_mixer_oss_build_input! */
986 static int snd_mixer_oss_build_test_all(struct snd_mixer_oss *mixer,
987 struct snd_mixer_oss_assign_table *ptr,
993 err = snd_mixer_oss_build_test(mixer, slot, ptr->name, ptr->index,
994 SNDRV_MIXER_OSS_ITEM_GLOBAL);
997 sprintf(str, "%s Switch", ptr->name);
998 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
999 SNDRV_MIXER_OSS_ITEM_GSWITCH);
1002 sprintf(str, "%s Route", ptr->name);
1003 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
1004 SNDRV_MIXER_OSS_ITEM_GROUTE);
1007 sprintf(str, "%s Volume", ptr->name);
1008 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
1009 SNDRV_MIXER_OSS_ITEM_GVOLUME);
1012 sprintf(str, "%s Playback Switch", ptr->name);
1013 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
1014 SNDRV_MIXER_OSS_ITEM_PSWITCH);
1017 sprintf(str, "%s Playback Route", ptr->name);
1018 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
1019 SNDRV_MIXER_OSS_ITEM_PROUTE);
1022 sprintf(str, "%s Playback Volume", ptr->name);
1023 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
1024 SNDRV_MIXER_OSS_ITEM_PVOLUME);
1027 sprintf(str, "%s Capture Switch", ptr->name);
1028 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
1029 SNDRV_MIXER_OSS_ITEM_CSWITCH);
1032 sprintf(str, "%s Capture Route", ptr->name);
1033 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
1034 SNDRV_MIXER_OSS_ITEM_CROUTE);
1037 sprintf(str, "%s Capture Volume", ptr->name);
1038 err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
1039 SNDRV_MIXER_OSS_ITEM_CVOLUME);
1047 * build an OSS mixer element.
1048 * ptr_allocated means the entry is dynamically allocated (change via proc file).
1049 * when replace_old = 1, the old entry is replaced with the new one.
1051 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)
1055 struct snd_kcontrol *kctl;
1056 struct snd_mixer_oss_slot *rslot;
1059 /* check if already assigned */
1060 if (mixer->slots[ptr->oss_id].get_volume && ! replace_old)
1063 memset(&slot, 0, sizeof(slot));
1064 memset(slot.numid, 0xff, sizeof(slot.numid)); /* ID_UNKNOWN */
1065 if (snd_mixer_oss_build_test_all(mixer, ptr, &slot))
1067 down_read(&mixer->card->controls_rwsem);
1068 if (ptr->index == 0 && (kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0)) != NULL) {
1069 struct snd_ctl_elem_info *uinfo;
1071 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
1073 up_read(&mixer->card->controls_rwsem);
1077 if (kctl->info(kctl, uinfo)) {
1078 up_read(&mixer->card->controls_rwsem);
1082 strcpy(str, ptr->name);
1083 if (!strcmp(str, "Master"))
1085 if (!strcmp(str, "Master Mono"))
1086 strcpy(str, "Mix Mono");
1087 slot.capture_item = 0;
1088 if (!strcmp(uinfo->value.enumerated.name, str)) {
1089 slot.present |= SNDRV_MIXER_OSS_PRESENT_CAPTURE;
1091 for (slot.capture_item = 1; slot.capture_item < uinfo->value.enumerated.items; slot.capture_item++) {
1092 uinfo->value.enumerated.item = slot.capture_item;
1093 if (kctl->info(kctl, uinfo)) {
1094 up_read(&mixer->card->controls_rwsem);
1098 if (!strcmp(uinfo->value.enumerated.name, str)) {
1099 slot.present |= SNDRV_MIXER_OSS_PRESENT_CAPTURE;
1106 up_read(&mixer->card->controls_rwsem);
1107 if (slot.present != 0) {
1108 pslot = kmalloc(sizeof(slot), GFP_KERNEL);
1112 pslot->signature = SNDRV_MIXER_OSS_SIGNATURE;
1113 pslot->assigned = ptr;
1114 pslot->allocated = ptr_allocated;
1115 rslot = &mixer->slots[ptr->oss_id];
1116 mixer_slot_clear(rslot);
1117 rslot->stereo = slot.channels > 1 ? 1 : 0;
1118 rslot->get_volume = snd_mixer_oss_get_volume1;
1119 rslot->put_volume = snd_mixer_oss_put_volume1;
1120 /* note: ES18xx have both Capture Source and XX Capture Volume !!! */
1121 if (slot.present & SNDRV_MIXER_OSS_PRESENT_CSWITCH) {
1122 rslot->get_recsrc = snd_mixer_oss_get_recsrc1_sw;
1123 rslot->put_recsrc = snd_mixer_oss_put_recsrc1_sw;
1124 } else if (slot.present & SNDRV_MIXER_OSS_PRESENT_CROUTE) {
1125 rslot->get_recsrc = snd_mixer_oss_get_recsrc1_route;
1126 rslot->put_recsrc = snd_mixer_oss_put_recsrc1_route;
1127 } else if (slot.present & SNDRV_MIXER_OSS_PRESENT_CAPTURE) {
1128 mixer->mask_recsrc |= 1 << ptr->oss_id;
1130 rslot->private_data = pslot;
1131 rslot->private_free = snd_mixer_oss_slot_free;
1137 #ifdef CONFIG_SND_PROC_FS
1140 #define MIXER_VOL(name) [SOUND_MIXER_##name] = #name
1141 static char *oss_mixer_names[SNDRV_OSS_MAX_MIXERS] = {
1159 MIXER_VOL(DIGITAL1),
1160 MIXER_VOL(DIGITAL2),
1161 MIXER_VOL(DIGITAL3),
1163 MIXER_VOL(PHONEOUT),
1173 static void snd_mixer_oss_proc_read(struct snd_info_entry *entry,
1174 struct snd_info_buffer *buffer)
1176 struct snd_mixer_oss *mixer = entry->private_data;
1179 mutex_lock(&mixer->reg_mutex);
1180 for (i = 0; i < SNDRV_OSS_MAX_MIXERS; i++) {
1183 if (! oss_mixer_names[i])
1185 p = (struct slot *)mixer->slots[i].private_data;
1186 snd_iprintf(buffer, "%s ", oss_mixer_names[i]);
1187 if (p && p->assigned)
1188 snd_iprintf(buffer, "\"%s\" %d\n",
1190 p->assigned->index);
1192 snd_iprintf(buffer, "\"\" 0\n");
1194 mutex_unlock(&mixer->reg_mutex);
1197 static void snd_mixer_oss_proc_write(struct snd_info_entry *entry,
1198 struct snd_info_buffer *buffer)
1200 struct snd_mixer_oss *mixer = entry->private_data;
1201 char line[128], str[32], idxstr[16];
1205 struct snd_mixer_oss_assign_table *tbl;
1208 while (!snd_info_get_line(buffer, line, sizeof(line))) {
1209 cptr = snd_info_get_str(str, line, sizeof(str));
1210 for (ch = 0; ch < SNDRV_OSS_MAX_MIXERS; ch++)
1211 if (oss_mixer_names[ch] && strcmp(oss_mixer_names[ch], str) == 0)
1213 if (ch >= SNDRV_OSS_MAX_MIXERS) {
1214 pr_err("ALSA: mixer_oss: invalid OSS volume '%s'\n",
1218 cptr = snd_info_get_str(str, cptr, sizeof(str));
1220 /* remove the entry */
1221 mutex_lock(&mixer->reg_mutex);
1222 mixer_slot_clear(&mixer->slots[ch]);
1223 mutex_unlock(&mixer->reg_mutex);
1226 snd_info_get_str(idxstr, cptr, sizeof(idxstr));
1227 idx = simple_strtoul(idxstr, NULL, 10);
1228 if (idx >= 0x4000) { /* too big */
1229 pr_err("ALSA: mixer_oss: invalid index %d\n", idx);
1232 mutex_lock(&mixer->reg_mutex);
1233 slot = (struct slot *)mixer->slots[ch].private_data;
1234 if (slot && slot->assigned &&
1235 slot->assigned->index == idx && ! strcmp(slot->assigned->name, str))
1238 tbl = kmalloc(sizeof(*tbl), GFP_KERNEL);
1242 tbl->name = kstrdup(str, GFP_KERNEL);
1248 if (snd_mixer_oss_build_input(mixer, tbl, 1, 1) <= 0) {
1253 mutex_unlock(&mixer->reg_mutex);
1257 static void snd_mixer_oss_proc_init(struct snd_mixer_oss *mixer)
1259 struct snd_info_entry *entry;
1261 entry = snd_info_create_card_entry(mixer->card, "oss_mixer",
1262 mixer->card->proc_root);
1265 entry->content = SNDRV_INFO_CONTENT_TEXT;
1266 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
1267 entry->c.text.read = snd_mixer_oss_proc_read;
1268 entry->c.text.write = snd_mixer_oss_proc_write;
1269 entry->private_data = mixer;
1270 if (snd_info_register(entry) < 0) {
1271 snd_info_free_entry(entry);
1274 mixer->proc_entry = entry;
1277 static void snd_mixer_oss_proc_done(struct snd_mixer_oss *mixer)
1279 snd_info_free_entry(mixer->proc_entry);
1280 mixer->proc_entry = NULL;
1282 #else /* !CONFIG_SND_PROC_FS */
1283 #define snd_mixer_oss_proc_init(mix)
1284 #define snd_mixer_oss_proc_done(mix)
1285 #endif /* CONFIG_SND_PROC_FS */
1287 static void snd_mixer_oss_build(struct snd_mixer_oss *mixer)
1289 static struct snd_mixer_oss_assign_table table[] = {
1290 { SOUND_MIXER_VOLUME, "Master", 0 },
1291 { SOUND_MIXER_VOLUME, "Front", 0 }, /* fallback */
1292 { SOUND_MIXER_BASS, "Tone Control - Bass", 0 },
1293 { SOUND_MIXER_TREBLE, "Tone Control - Treble", 0 },
1294 { SOUND_MIXER_SYNTH, "Synth", 0 },
1295 { SOUND_MIXER_SYNTH, "FM", 0 }, /* fallback */
1296 { SOUND_MIXER_SYNTH, "Music", 0 }, /* fallback */
1297 { SOUND_MIXER_PCM, "PCM", 0 },
1298 { SOUND_MIXER_SPEAKER, "Beep", 0 },
1299 { SOUND_MIXER_SPEAKER, "PC Speaker", 0 }, /* fallback */
1300 { SOUND_MIXER_SPEAKER, "Speaker", 0 }, /* fallback */
1301 { SOUND_MIXER_LINE, "Line", 0 },
1302 { SOUND_MIXER_MIC, "Mic", 0 },
1303 { SOUND_MIXER_CD, "CD", 0 },
1304 { SOUND_MIXER_IMIX, "Monitor Mix", 0 },
1305 { SOUND_MIXER_ALTPCM, "PCM", 1 },
1306 { SOUND_MIXER_ALTPCM, "Headphone", 0 }, /* fallback */
1307 { SOUND_MIXER_ALTPCM, "Wave", 0 }, /* fallback */
1308 { SOUND_MIXER_RECLEV, "-- nothing --", 0 },
1309 { SOUND_MIXER_IGAIN, "Capture", 0 },
1310 { SOUND_MIXER_OGAIN, "Playback", 0 },
1311 { SOUND_MIXER_LINE1, "Aux", 0 },
1312 { SOUND_MIXER_LINE2, "Aux", 1 },
1313 { SOUND_MIXER_LINE3, "Aux", 2 },
1314 { SOUND_MIXER_DIGITAL1, "Digital", 0 },
1315 { SOUND_MIXER_DIGITAL1, "IEC958", 0 }, /* fallback */
1316 { SOUND_MIXER_DIGITAL1, "IEC958 Optical", 0 }, /* fallback */
1317 { SOUND_MIXER_DIGITAL1, "IEC958 Coaxial", 0 }, /* fallback */
1318 { SOUND_MIXER_DIGITAL2, "Digital", 1 },
1319 { SOUND_MIXER_DIGITAL3, "Digital", 2 },
1320 { SOUND_MIXER_PHONEIN, "Phone", 0 },
1321 { SOUND_MIXER_PHONEOUT, "Master Mono", 0 },
1322 { SOUND_MIXER_PHONEOUT, "Speaker", 0 }, /*fallback*/
1323 { SOUND_MIXER_PHONEOUT, "Mono", 0 }, /*fallback*/
1324 { SOUND_MIXER_PHONEOUT, "Phone", 0 }, /* fallback */
1325 { SOUND_MIXER_VIDEO, "Video", 0 },
1326 { SOUND_MIXER_RADIO, "Radio", 0 },
1327 { SOUND_MIXER_MONITOR, "Monitor", 0 }
1331 for (idx = 0; idx < ARRAY_SIZE(table); idx++)
1332 snd_mixer_oss_build_input(mixer, &table[idx], 0, 0);
1333 if (mixer->mask_recsrc) {
1334 mixer->get_recsrc = snd_mixer_oss_get_recsrc2;
1335 mixer->put_recsrc = snd_mixer_oss_put_recsrc2;
1343 static int snd_mixer_oss_free1(void *private)
1345 struct snd_mixer_oss *mixer = private;
1346 struct snd_card *card;
1352 if (snd_BUG_ON(mixer != card->mixer_oss))
1354 card->mixer_oss = NULL;
1355 for (idx = 0; idx < SNDRV_OSS_MAX_MIXERS; idx++) {
1356 struct snd_mixer_oss_slot *chn = &mixer->slots[idx];
1357 if (chn->private_free)
1358 chn->private_free(chn);
1364 static int snd_mixer_oss_notify_handler(struct snd_card *card, int cmd)
1366 struct snd_mixer_oss *mixer;
1368 if (cmd == SND_MIXER_OSS_NOTIFY_REGISTER) {
1371 mixer = kcalloc(2, sizeof(*mixer), GFP_KERNEL);
1374 mutex_init(&mixer->reg_mutex);
1375 if ((err = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER,
1377 &snd_mixer_oss_f_ops, card)) < 0) {
1379 "unable to register OSS mixer device %i:%i\n",
1384 mixer->oss_dev_alloc = 1;
1386 if (*card->mixername)
1387 strlcpy(mixer->name, card->mixername, sizeof(mixer->name));
1389 snprintf(mixer->name, sizeof(mixer->name),
1390 "mixer%i", card->number);
1391 #ifdef SNDRV_OSS_INFO_DEV_MIXERS
1392 snd_oss_info_register(SNDRV_OSS_INFO_DEV_MIXERS,
1396 for (idx = 0; idx < SNDRV_OSS_MAX_MIXERS; idx++)
1397 mixer->slots[idx].number = idx;
1398 card->mixer_oss = mixer;
1399 snd_mixer_oss_build(mixer);
1400 snd_mixer_oss_proc_init(mixer);
1402 mixer = card->mixer_oss;
1405 if (mixer->oss_dev_alloc) {
1406 #ifdef SNDRV_OSS_INFO_DEV_MIXERS
1407 snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_MIXERS, mixer->card->number);
1409 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER, mixer->card, 0);
1410 mixer->oss_dev_alloc = 0;
1412 if (cmd == SND_MIXER_OSS_NOTIFY_DISCONNECT)
1414 snd_mixer_oss_proc_done(mixer);
1415 return snd_mixer_oss_free1(mixer);
1420 static int __init alsa_mixer_oss_init(void)
1424 snd_mixer_oss_notify_callback = snd_mixer_oss_notify_handler;
1425 for (idx = 0; idx < SNDRV_CARDS; idx++) {
1427 snd_mixer_oss_notify_handler(snd_cards[idx], SND_MIXER_OSS_NOTIFY_REGISTER);
1432 static void __exit alsa_mixer_oss_exit(void)
1436 snd_mixer_oss_notify_callback = NULL;
1437 for (idx = 0; idx < SNDRV_CARDS; idx++) {
1439 snd_mixer_oss_notify_handler(snd_cards[idx], SND_MIXER_OSS_NOTIFY_FREE);
1443 module_init(alsa_mixer_oss_init)
1444 module_exit(alsa_mixer_oss_exit)
1446 EXPORT_SYMBOL(snd_mixer_oss_ioctl_card);