2 * OSS emulation layer for the mixer interface
3 * Copyright (c) by Jaroslav Kysela <perex@suse.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 <sound/driver.h>
23 #include <linux/init.h>
24 #include <linux/smp_lock.h>
25 #include <linux/slab.h>
26 #include <linux/time.h>
27 #include <linux/string.h>
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>
35 #define OSS_ALSAEMULVER _SIOR ('M', 249, int)
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
);
42 static int snd_mixer_oss_open(struct inode
*inode
, struct file
*file
)
44 struct snd_card
*card
;
45 struct snd_mixer_oss_file
*fmixer
;
48 card
= snd_lookup_oss_minor_data(iminor(inode
),
49 SNDRV_OSS_DEVICE_TYPE_MIXER
);
52 if (card
->mixer_oss
== NULL
)
54 err
= snd_card_file_add(card
, file
);
57 fmixer
= kzalloc(sizeof(*fmixer
), GFP_KERNEL
);
59 snd_card_file_remove(card
, file
);
63 fmixer
->mixer
= card
->mixer_oss
;
64 file
->private_data
= fmixer
;
65 if (!try_module_get(card
->module
)) {
67 snd_card_file_remove(card
, file
);
73 static int snd_mixer_oss_release(struct inode
*inode
, struct file
*file
)
75 struct snd_mixer_oss_file
*fmixer
;
77 if (file
->private_data
) {
78 fmixer
= (struct snd_mixer_oss_file
*) file
->private_data
;
79 module_put(fmixer
->card
->module
);
80 snd_card_file_remove(fmixer
->card
, file
);
86 static int snd_mixer_oss_info(struct snd_mixer_oss_file
*fmixer
,
87 mixer_info __user
*_info
)
89 struct snd_card
*card
= fmixer
->card
;
90 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
91 struct mixer_info info
;
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
)))
102 static int snd_mixer_oss_info_obsolete(struct snd_mixer_oss_file
*fmixer
,
103 _old_mixer_info __user
*_info
)
105 struct snd_card
*card
= fmixer
->card
;
106 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
107 _old_mixer_info info
;
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
)))
117 static int snd_mixer_oss_caps(struct snd_mixer_oss_file
*fmixer
)
119 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
124 if (mixer
->get_recsrc
&& mixer
->put_recsrc
)
125 result
|= SOUND_CAP_EXCL_INPUT
;
129 static int snd_mixer_oss_devmask(struct snd_mixer_oss_file
*fmixer
)
131 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
132 struct snd_mixer_oss_slot
*pslot
;
137 for (chn
= 0; chn
< 31; chn
++) {
138 pslot
= &mixer
->slots
[chn
];
139 if (pslot
->put_volume
|| pslot
->put_recsrc
)
145 static int snd_mixer_oss_stereodevs(struct snd_mixer_oss_file
*fmixer
)
147 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
148 struct snd_mixer_oss_slot
*pslot
;
153 for (chn
= 0; chn
< 31; chn
++) {
154 pslot
= &mixer
->slots
[chn
];
155 if (pslot
->put_volume
&& pslot
->stereo
)
161 static int snd_mixer_oss_recmask(struct snd_mixer_oss_file
*fmixer
)
163 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
168 if (mixer
->put_recsrc
&& mixer
->get_recsrc
) { /* exclusive */
169 result
= mixer
->mask_recsrc
;
171 struct snd_mixer_oss_slot
*pslot
;
173 for (chn
= 0; chn
< 31; chn
++) {
174 pslot
= &mixer
->slots
[chn
];
175 if (pslot
->put_recsrc
)
182 static int snd_mixer_oss_get_recsrc(struct snd_mixer_oss_file
*fmixer
)
184 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
189 if (mixer
->put_recsrc
&& mixer
->get_recsrc
) { /* exclusive */
191 if ((err
= mixer
->get_recsrc(fmixer
, &result
)) < 0)
193 result
= 1 << result
;
195 struct snd_mixer_oss_slot
*pslot
;
197 for (chn
= 0; chn
< 31; chn
++) {
198 pslot
= &mixer
->slots
[chn
];
199 if (pslot
->get_recsrc
) {
201 pslot
->get_recsrc(fmixer
, pslot
, &active
);
207 return mixer
->oss_recsrc
= result
;
210 static int snd_mixer_oss_set_recsrc(struct snd_mixer_oss_file
*fmixer
, int recsrc
)
212 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
213 struct snd_mixer_oss_slot
*pslot
;
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
;
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
);
234 for (chn
= 0; chn
< 31; chn
++) {
235 pslot
= &mixer
->slots
[chn
];
236 if (pslot
->get_recsrc
) {
238 pslot
->get_recsrc(fmixer
, pslot
, &active
);
247 static int snd_mixer_oss_get_volume(struct snd_mixer_oss_file
*fmixer
, int slot
)
249 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
250 struct snd_mixer_oss_slot
*pslot
;
251 int result
= 0, left
, right
;
253 if (mixer
== NULL
|| slot
> 30)
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
);
262 snd_assert(left
>= 0 && left
<= 100, return -EIO
);
263 snd_assert(right
>= 0 && right
<= 100, return -EIO
);
265 pslot
->volume
[0] = left
;
266 pslot
->volume
[1] = right
;
267 result
= (left
& 0xff) | ((right
& 0xff) << 8);
272 static int snd_mixer_oss_set_volume(struct snd_mixer_oss_file
*fmixer
,
273 int slot
, int volume
)
275 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
276 struct snd_mixer_oss_slot
*pslot
;
277 int result
= 0, left
= volume
& 0xff, right
= (volume
>> 8) & 0xff;
279 if (mixer
== NULL
|| slot
> 30)
281 pslot
= &mixer
->slots
[slot
];
288 if (pslot
->put_volume
)
289 result
= pslot
->put_volume(fmixer
, pslot
, left
, right
);
292 pslot
->volume
[0] = left
;
293 pslot
->volume
[1] = right
;
294 return (left
& 0xff) | ((right
& 0xff) << 8);
297 static int snd_mixer_oss_ioctl1(struct snd_mixer_oss_file
*fmixer
, unsigned int cmd
, unsigned long arg
)
299 void __user
*argp
= (void __user
*)arg
;
300 int __user
*p
= argp
;
303 snd_assert(fmixer
!= NULL
, return -ENXIO
);
304 if (((cmd
>> 8) & 0xff) == 'M') {
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
))
313 tmp
= snd_mixer_oss_set_recsrc(fmixer
, tmp
);
316 return put_user(tmp
, p
);
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
);
325 return put_user(tmp
, p
);
326 case SOUND_MIXER_READ_STEREODEVS
:
327 tmp
= snd_mixer_oss_stereodevs(fmixer
);
330 return put_user(tmp
, p
);
331 case SOUND_MIXER_READ_RECMASK
:
332 tmp
= snd_mixer_oss_recmask(fmixer
);
335 return put_user(tmp
, p
);
336 case SOUND_MIXER_READ_CAPS
:
337 tmp
= snd_mixer_oss_caps(fmixer
);
340 return put_user(tmp
, p
);
341 case SOUND_MIXER_READ_RECSRC
:
342 tmp
= snd_mixer_oss_get_recsrc(fmixer
);
345 return put_user(tmp
, p
);
349 if (get_user(tmp
, p
))
351 tmp
= snd_mixer_oss_set_volume(fmixer
, cmd
& 0xff, tmp
);
354 return put_user(tmp
, p
);
355 } else if (cmd
& SIOC_OUT
) {
356 tmp
= snd_mixer_oss_get_volume(fmixer
, cmd
& 0xff);
359 return put_user(tmp
, p
);
364 static long snd_mixer_oss_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
366 return snd_mixer_oss_ioctl1((struct snd_mixer_oss_file
*) file
->private_data
, cmd
, arg
);
369 int snd_mixer_oss_ioctl_card(struct snd_card
*card
, unsigned int cmd
, unsigned long arg
)
371 struct snd_mixer_oss_file fmixer
;
373 snd_assert(card
!= NULL
, return -ENXIO
);
374 if (card
->mixer_oss
== NULL
)
376 memset(&fmixer
, 0, sizeof(fmixer
));
378 fmixer
.mixer
= card
->mixer_oss
;
379 return snd_mixer_oss_ioctl1(&fmixer
, cmd
, arg
);
384 #define snd_mixer_oss_ioctl_compat snd_mixer_oss_ioctl
386 #define snd_mixer_oss_ioctl_compat NULL
393 static struct file_operations snd_mixer_oss_f_ops
=
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
,
406 static long snd_mixer_oss_conv(long val
, long omin
, long omax
, long nmin
, long nmax
)
408 long orange
= omax
- omin
, nrange
= nmax
- nmin
;
412 return ((nrange
* (val
- omin
)) + (orange
/ 2)) / orange
+ nmin
;
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
)
418 if (val
== snd_mixer_oss_conv(*old
, 0, 100, min
, max
))
420 return snd_mixer_oss_conv(val
, min
, max
, 0, 100);
423 /* convert from oss to alsa native values */
424 static long snd_mixer_oss_conv2(long val
, long min
, long max
)
426 return snd_mixer_oss_conv(val
, 0, 100, min
, max
);
430 static void snd_mixer_oss_recsrce_set(struct snd_card
*card
, int slot
)
432 struct snd_mixer_oss
*mixer
= card
->mixer_oss
;
434 mixer
->mask_recsrc
|= 1 << slot
;
437 static int snd_mixer_oss_recsrce_get(struct snd_card
*card
, int slot
)
439 struct snd_mixer_oss
*mixer
= card
->mixer_oss
;
440 if (mixer
&& (mixer
->mask_recsrc
& (1 << slot
)))
446 #define SNDRV_MIXER_OSS_SIGNATURE 0x65999250
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
460 #define SNDRV_MIXER_OSS_ITEM_COUNT 11
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)
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;
484 #define ID_UNKNOWN ((unsigned int)-1)
486 static struct snd_kcontrol
*snd_mixer_oss_test_id(struct snd_mixer_oss
*mixer
, const char *name
, int index
)
488 struct snd_card
*card
= mixer
->card
;
489 struct snd_ctl_elem_id id
;
491 memset(&id
, 0, sizeof(id
));
492 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
493 strcpy(id
.name
, name
);
495 return snd_ctl_find_id(card
, &id
);
498 static void snd_mixer_oss_get_volume1_vol(struct snd_mixer_oss_file
*fmixer
,
499 struct snd_mixer_oss_slot
*pslot
,
501 int *left
, int *right
)
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
;
508 if (numid
== ID_UNKNOWN
)
510 down_read(&card
->controls_rwsem
);
511 if ((kctl
= snd_ctl_find_numid(card
, numid
)) == NULL
) {
512 up_read(&card
->controls_rwsem
);
515 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
516 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
517 if (uinfo
== NULL
|| uctl
== NULL
)
519 if (kctl
->info(kctl
, uinfo
))
521 if (kctl
->get(kctl
, uctl
))
523 if (uinfo
->type
== SNDRV_CTL_ELEM_TYPE_BOOLEAN
&&
524 uinfo
->value
.integer
.min
== 0 && uinfo
->value
.integer
.max
== 1)
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]);
530 up_read(&card
->controls_rwsem
);
535 static void snd_mixer_oss_get_volume1_sw(struct snd_mixer_oss_file
*fmixer
,
536 struct snd_mixer_oss_slot
*pslot
,
538 int *left
, int *right
,
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
;
546 if (numid
== ID_UNKNOWN
)
548 down_read(&card
->controls_rwsem
);
549 if ((kctl
= snd_ctl_find_numid(card
, numid
)) == NULL
) {
550 up_read(&card
->controls_rwsem
);
553 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
554 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
555 if (uinfo
== NULL
|| uctl
== NULL
)
557 if (kctl
->info(kctl
, uinfo
))
559 if (kctl
->get(kctl
, uctl
))
561 if (!uctl
->value
.integer
.value
[0]) {
563 if (uinfo
->count
== 1)
566 if (uinfo
->count
> 1 && !uctl
->value
.integer
.value
[route
? 3 : 1])
569 up_read(&card
->controls_rwsem
);
574 static int snd_mixer_oss_get_volume1(struct snd_mixer_oss_file
*fmixer
,
575 struct snd_mixer_oss_slot
*pslot
,
576 int *left
, int *right
)
578 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
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
);
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);
600 static void snd_mixer_oss_put_volume1_vol(struct snd_mixer_oss_file
*fmixer
,
601 struct snd_mixer_oss_slot
*pslot
,
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
;
611 if (numid
== ID_UNKNOWN
)
613 down_read(&card
->controls_rwsem
);
614 if ((kctl
= snd_ctl_find_numid(card
, numid
)) == NULL
)
616 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
617 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
618 if (uinfo
== NULL
|| uctl
== NULL
)
620 if (kctl
->info(kctl
, uinfo
))
622 if (uinfo
->type
== SNDRV_CTL_ELEM_TYPE_BOOLEAN
&&
623 uinfo
->value
.integer
.min
== 0 && uinfo
->value
.integer
.max
== 1)
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
);
628 if ((res
= kctl
->put(kctl
, uctl
)) < 0)
631 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &kctl
->id
);
633 up_read(&card
->controls_rwsem
);
638 static void snd_mixer_oss_put_volume1_sw(struct snd_mixer_oss_file
*fmixer
,
639 struct snd_mixer_oss_slot
*pslot
,
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
;
650 if (numid
== ID_UNKNOWN
)
652 down_read(&card
->controls_rwsem
);
653 if ((kctl
= snd_ctl_find_numid(card
, numid
)) == NULL
) {
654 up_read(&fmixer
->card
->controls_rwsem
);
657 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
658 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
659 if (uinfo
== NULL
|| uctl
== NULL
)
661 if (kctl
->info(kctl
, uinfo
))
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;
667 uctl
->value
.integer
.value
[1] =
668 uctl
->value
.integer
.value
[2] = 0;
671 uctl
->value
.integer
.value
[0] = (left
> 0 || right
> 0) ? 1 : 0;
673 if ((res
= kctl
->put(kctl
, uctl
)) < 0)
676 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &kctl
->id
);
678 up_read(&card
->controls_rwsem
);
683 static int snd_mixer_oss_put_volume1(struct snd_mixer_oss_file
*fmixer
,
684 struct snd_mixer_oss_slot
*pslot
,
687 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
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
);
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);
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);
721 static int snd_mixer_oss_get_recsrc1_sw(struct snd_mixer_oss_file
*fmixer
,
722 struct snd_mixer_oss_slot
*pslot
,
725 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
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;
734 static int snd_mixer_oss_get_recsrc1_route(struct snd_mixer_oss_file
*fmixer
,
735 struct snd_mixer_oss_slot
*pslot
,
738 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
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;
747 static int snd_mixer_oss_put_recsrc1_sw(struct snd_mixer_oss_file
*fmixer
,
748 struct snd_mixer_oss_slot
*pslot
,
751 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
753 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CSWITCH
], active
, active
, 0);
757 static int snd_mixer_oss_put_recsrc1_route(struct snd_mixer_oss_file
*fmixer
,
758 struct snd_mixer_oss_slot
*pslot
,
761 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
763 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CROUTE
], active
, active
, 1);
767 static int snd_mixer_oss_get_recsrc2(struct snd_mixer_oss_file
*fmixer
, unsigned int *active_index
)
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
;
774 struct snd_ctl_elem_info
*uinfo
;
775 struct snd_ctl_elem_value
*uctl
;
778 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
779 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
780 if (uinfo
== NULL
|| uctl
== NULL
) {
784 down_read(&card
->controls_rwsem
);
785 kctl
= snd_mixer_oss_test_id(mixer
, "Capture Source", 0);
790 if ((err
= kctl
->info(kctl
, uinfo
)) < 0)
792 if ((err
= kctl
->get(kctl
, uctl
)) < 0)
794 for (idx
= 0; idx
< 32; idx
++) {
795 if (!(mixer
->mask_recsrc
& (1 << idx
)))
797 pslot
= &mixer
->slots
[idx
];
798 slot
= (struct slot
*)pslot
->private_data
;
799 if (slot
->signature
!= SNDRV_MIXER_OSS_SIGNATURE
)
801 if (!(slot
->present
& SNDRV_MIXER_OSS_PRESENT_CAPTURE
))
803 if (slot
->capture_item
== uctl
->value
.enumerated
.item
[0]) {
810 up_read(&card
->controls_rwsem
);
816 static int snd_mixer_oss_put_recsrc2(struct snd_mixer_oss_file
*fmixer
, unsigned int active_index
)
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
;
822 struct slot
*slot
= NULL
;
823 struct snd_ctl_elem_info
*uinfo
;
824 struct snd_ctl_elem_value
*uctl
;
828 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
829 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
830 if (uinfo
== NULL
|| uctl
== NULL
) {
834 down_read(&card
->controls_rwsem
);
835 kctl
= snd_mixer_oss_test_id(mixer
, "Capture Source", 0);
840 if ((err
= kctl
->info(kctl
, uinfo
)) < 0)
842 for (idx
= 0; idx
< 32; idx
++) {
843 if (!(mixer
->mask_recsrc
& (1 << idx
)))
845 pslot
= &mixer
->slots
[idx
];
846 slot
= (struct slot
*)pslot
->private_data
;
847 if (slot
->signature
!= SNDRV_MIXER_OSS_SIGNATURE
)
849 if (!(slot
->present
& SNDRV_MIXER_OSS_PRESENT_CAPTURE
))
851 if (idx
== active_index
)
857 for (idx
= 0; idx
< uinfo
->count
; idx
++)
858 uctl
->value
.enumerated
.item
[idx
] = slot
->capture_item
;
859 err
= kctl
->put(kctl
, uctl
);
861 snd_ctl_notify(fmixer
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &kctl
->id
);
864 up_read(&card
->controls_rwsem
);
870 struct snd_mixer_oss_assign_table
{
876 static int snd_mixer_oss_build_test(struct snd_mixer_oss
*mixer
, struct slot
*slot
, const char *name
, int index
, int item
)
878 struct snd_ctl_elem_info
*info
;
879 struct snd_kcontrol
*kcontrol
;
880 struct snd_card
*card
= mixer
->card
;
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
);
889 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
891 up_read(&card
->controls_rwsem
);
894 if ((err
= kcontrol
->info(kcontrol
, info
)) < 0) {
895 up_read(&card
->controls_rwsem
);
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
;
908 static void snd_mixer_oss_slot_free(struct snd_mixer_oss_slot
*chn
)
910 struct slot
*p
= (struct slot
*)chn
->private_data
;
912 if (p
->allocated
&& p
->assigned
) {
913 kfree(p
->assigned
->name
);
920 static void mixer_slot_clear(struct snd_mixer_oss_slot
*rslot
)
922 int idx
= rslot
->number
; /* remember this */
923 if (rslot
->private_free
)
924 rslot
->private_free(rslot
);
925 memset(rslot
, 0, sizeof(*rslot
));
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.
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
)
938 struct snd_kcontrol
*kctl
;
939 struct snd_mixer_oss_slot
*rslot
;
942 /* check if already assigned */
943 if (mixer
->slots
[ptr
->oss_id
].get_volume
&& ! replace_old
)
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
))
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
))
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
))
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
))
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
))
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
))
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
))
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
))
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
))
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
))
987 down_read(&mixer
->card
->controls_rwsem
);
988 if (ptr
->index
== 0 && (kctl
= snd_mixer_oss_test_id(mixer
, "Capture Source", 0)) != NULL
) {
989 struct snd_ctl_elem_info
*uinfo
;
991 uinfo
= kmalloc(sizeof(*uinfo
), GFP_KERNEL
);
993 up_read(&mixer
->card
->controls_rwsem
);
997 memset(uinfo
, 0, sizeof(*uinfo
));
998 if (kctl
->info(kctl
, uinfo
)) {
999 up_read(&mixer
->card
->controls_rwsem
);
1002 strcpy(str
, ptr
->name
);
1003 if (!strcmp(str
, "Master"))
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
;
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
);
1017 if (!strcmp(uinfo
->value
.enumerated
.name
, str
)) {
1018 slot
.present
|= SNDRV_MIXER_OSS_PRESENT_CAPTURE
;
1025 up_read(&mixer
->card
->controls_rwsem
);
1026 if (slot
.present
!= 0) {
1027 pslot
= (struct slot
*)kmalloc(sizeof(slot
), GFP_KERNEL
);
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
;
1049 rslot
->private_data
= pslot
;
1050 rslot
->private_free
= snd_mixer_oss_slot_free
;
1056 #ifdef CONFIG_PROC_FS
1059 #define MIXER_VOL(name) [SOUND_MIXER_##name] = #name
1060 static char *oss_mixer_names
[SNDRV_OSS_MAX_MIXERS
] = {
1078 MIXER_VOL(DIGITAL1
),
1079 MIXER_VOL(DIGITAL2
),
1080 MIXER_VOL(DIGITAL3
),
1082 MIXER_VOL(PHONEOUT
),
1092 static void snd_mixer_oss_proc_read(struct snd_info_entry
*entry
,
1093 struct snd_info_buffer
*buffer
)
1095 struct snd_mixer_oss
*mixer
= entry
->private_data
;
1098 mutex_lock(&mixer
->reg_mutex
);
1099 for (i
= 0; i
< SNDRV_OSS_MAX_MIXERS
; i
++) {
1102 if (! oss_mixer_names
[i
])
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",
1109 p
->assigned
->index
);
1111 snd_iprintf(buffer
, "\"\" 0\n");
1113 mutex_unlock(&mixer
->reg_mutex
);
1116 static void snd_mixer_oss_proc_write(struct snd_info_entry
*entry
,
1117 struct snd_info_buffer
*buffer
)
1119 struct snd_mixer_oss
*mixer
= entry
->private_data
;
1120 char line
[128], str
[32], idxstr
[16], *cptr
;
1122 struct snd_mixer_oss_assign_table
*tbl
;
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)
1130 if (ch
>= SNDRV_OSS_MAX_MIXERS
) {
1131 snd_printk(KERN_ERR
"mixer_oss: invalid OSS volume '%s'\n", str
);
1134 cptr
= snd_info_get_str(str
, cptr
, sizeof(str
));
1136 /* remove the entry */
1137 mutex_lock(&mixer
->reg_mutex
);
1138 mixer_slot_clear(&mixer
->slots
[ch
]);
1139 mutex_unlock(&mixer
->reg_mutex
);
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
);
1148 mutex_lock(&mixer
->reg_mutex
);
1149 slot
= (struct slot
*)mixer
->slots
[ch
].private_data
;
1150 if (slot
&& slot
->assigned
&&
1151 slot
->assigned
->index
== idx
&& ! strcmp(slot
->assigned
->name
, str
))
1154 tbl
= kmalloc(sizeof(*tbl
), GFP_KERNEL
);
1156 snd_printk(KERN_ERR
"mixer_oss: no memory\n");
1160 tbl
->name
= kstrdup(str
, GFP_KERNEL
);
1166 if (snd_mixer_oss_build_input(mixer
, tbl
, 1, 1) <= 0) {
1171 mutex_unlock(&mixer
->reg_mutex
);
1175 static void snd_mixer_oss_proc_init(struct snd_mixer_oss
*mixer
)
1177 struct snd_info_entry
*entry
;
1179 entry
= snd_info_create_card_entry(mixer
->card
, "oss_mixer",
1180 mixer
->card
->proc_root
);
1183 entry
->content
= SNDRV_INFO_CONTENT_TEXT
;
1184 entry
->mode
= S_IFREG
| S_IRUGO
| S_IWUSR
;
1185 entry
->c
.text
.read_size
= 8192;
1186 entry
->c
.text
.read
= snd_mixer_oss_proc_read
;
1187 entry
->c
.text
.write_size
= 8192;
1188 entry
->c
.text
.write
= snd_mixer_oss_proc_write
;
1189 entry
->private_data
= mixer
;
1190 if (snd_info_register(entry
) < 0) {
1191 snd_info_free_entry(entry
);
1194 mixer
->proc_entry
= entry
;
1197 static void snd_mixer_oss_proc_done(struct snd_mixer_oss
*mixer
)
1199 if (mixer
->proc_entry
) {
1200 snd_info_unregister(mixer
->proc_entry
);
1201 mixer
->proc_entry
= NULL
;
1204 #else /* !CONFIG_PROC_FS */
1205 #define snd_mixer_oss_proc_init(mix)
1206 #define snd_mixer_oss_proc_done(mix)
1207 #endif /* CONFIG_PROC_FS */
1209 static void snd_mixer_oss_build(struct snd_mixer_oss
*mixer
)
1211 static struct snd_mixer_oss_assign_table table
[] = {
1212 { SOUND_MIXER_VOLUME
, "Master", 0 },
1213 { SOUND_MIXER_VOLUME
, "Front", 0 }, /* fallback */
1214 { SOUND_MIXER_BASS
, "Tone Control - Bass", 0 },
1215 { SOUND_MIXER_TREBLE
, "Tone Control - Treble", 0 },
1216 { SOUND_MIXER_SYNTH
, "Synth", 0 },
1217 { SOUND_MIXER_SYNTH
, "FM", 0 }, /* fallback */
1218 { SOUND_MIXER_SYNTH
, "Music", 0 }, /* fallback */
1219 { SOUND_MIXER_PCM
, "PCM", 0 },
1220 { SOUND_MIXER_SPEAKER
, "PC Speaker", 0 },
1221 { SOUND_MIXER_LINE
, "Line", 0 },
1222 { SOUND_MIXER_MIC
, "Mic", 0 },
1223 { SOUND_MIXER_CD
, "CD", 0 },
1224 { SOUND_MIXER_IMIX
, "Monitor Mix", 0 },
1225 { SOUND_MIXER_ALTPCM
, "PCM", 1 },
1226 { SOUND_MIXER_ALTPCM
, "Headphone", 0 }, /* fallback */
1227 { SOUND_MIXER_ALTPCM
, "Wave", 0 }, /* fallback */
1228 { SOUND_MIXER_RECLEV
, "-- nothing --", 0 },
1229 { SOUND_MIXER_IGAIN
, "Capture", 0 },
1230 { SOUND_MIXER_OGAIN
, "Playback", 0 },
1231 { SOUND_MIXER_LINE1
, "Aux", 0 },
1232 { SOUND_MIXER_LINE2
, "Aux", 1 },
1233 { SOUND_MIXER_LINE3
, "Aux", 2 },
1234 { SOUND_MIXER_DIGITAL1
, "Digital", 0 },
1235 { SOUND_MIXER_DIGITAL1
, "IEC958", 0 }, /* fallback */
1236 { SOUND_MIXER_DIGITAL1
, "IEC958 Optical", 0 }, /* fallback */
1237 { SOUND_MIXER_DIGITAL1
, "IEC958 Coaxial", 0 }, /* fallback */
1238 { SOUND_MIXER_DIGITAL2
, "Digital", 1 },
1239 { SOUND_MIXER_DIGITAL3
, "Digital", 2 },
1240 { SOUND_MIXER_PHONEIN
, "Phone", 0 },
1241 { SOUND_MIXER_PHONEOUT
, "Master Mono", 0 },
1242 { SOUND_MIXER_PHONEOUT
, "Phone", 0 }, /* fallback */
1243 { SOUND_MIXER_VIDEO
, "Video", 0 },
1244 { SOUND_MIXER_RADIO
, "Radio", 0 },
1245 { SOUND_MIXER_MONITOR
, "Monitor", 0 }
1249 for (idx
= 0; idx
< ARRAY_SIZE(table
); idx
++)
1250 snd_mixer_oss_build_input(mixer
, &table
[idx
], 0, 0);
1251 if (mixer
->mask_recsrc
) {
1252 mixer
->get_recsrc
= snd_mixer_oss_get_recsrc2
;
1253 mixer
->put_recsrc
= snd_mixer_oss_put_recsrc2
;
1261 static int snd_mixer_oss_free1(void *private)
1263 struct snd_mixer_oss
*mixer
= private;
1264 struct snd_card
*card
;
1267 snd_assert(mixer
!= NULL
, return -ENXIO
);
1269 snd_assert(mixer
== card
->mixer_oss
, return -ENXIO
);
1270 card
->mixer_oss
= NULL
;
1271 for (idx
= 0; idx
< SNDRV_OSS_MAX_MIXERS
; idx
++) {
1272 struct snd_mixer_oss_slot
*chn
= &mixer
->slots
[idx
];
1273 if (chn
->private_free
)
1274 chn
->private_free(chn
);
1280 static int snd_mixer_oss_notify_handler(struct snd_card
*card
, int cmd
)
1282 struct snd_mixer_oss
*mixer
;
1284 if (cmd
== SND_MIXER_OSS_NOTIFY_REGISTER
) {
1288 mixer
= kcalloc(2, sizeof(*mixer
), GFP_KERNEL
);
1291 mutex_init(&mixer
->reg_mutex
);
1292 sprintf(name
, "mixer%i%i", card
->number
, 0);
1293 if ((err
= snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER
,
1295 &snd_mixer_oss_f_ops
, card
,
1297 snd_printk(KERN_ERR
"unable to register OSS mixer device %i:%i\n",
1302 mixer
->oss_dev_alloc
= 1;
1304 if (*card
->mixername
)
1305 strlcpy(mixer
->name
, card
->mixername
, sizeof(mixer
->name
));
1307 strlcpy(mixer
->name
, name
, sizeof(mixer
->name
));
1308 #ifdef SNDRV_OSS_INFO_DEV_MIXERS
1309 snd_oss_info_register(SNDRV_OSS_INFO_DEV_MIXERS
,
1313 for (idx
= 0; idx
< SNDRV_OSS_MAX_MIXERS
; idx
++)
1314 mixer
->slots
[idx
].number
= idx
;
1315 card
->mixer_oss
= mixer
;
1316 snd_mixer_oss_build(mixer
);
1317 snd_mixer_oss_proc_init(mixer
);
1318 } else if (cmd
== SND_MIXER_OSS_NOTIFY_DISCONNECT
) {
1319 mixer
= card
->mixer_oss
;
1320 if (mixer
== NULL
|| !mixer
->oss_dev_alloc
)
1322 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER
, mixer
->card
, 0);
1323 mixer
->oss_dev_alloc
= 0;
1325 mixer
= card
->mixer_oss
;
1328 #ifdef SNDRV_OSS_INFO_DEV_MIXERS
1329 snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_MIXERS
, mixer
->card
->number
);
1331 if (mixer
->oss_dev_alloc
)
1332 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER
, mixer
->card
, 0);
1333 snd_mixer_oss_proc_done(mixer
);
1334 return snd_mixer_oss_free1(mixer
);
1339 static int __init
alsa_mixer_oss_init(void)
1343 snd_mixer_oss_notify_callback
= snd_mixer_oss_notify_handler
;
1344 for (idx
= 0; idx
< SNDRV_CARDS
; idx
++) {
1346 snd_mixer_oss_notify_handler(snd_cards
[idx
], SND_MIXER_OSS_NOTIFY_REGISTER
);
1351 static void __exit
alsa_mixer_oss_exit(void)
1355 snd_mixer_oss_notify_callback
= NULL
;
1356 for (idx
= 0; idx
< SNDRV_CARDS
; idx
++) {
1358 snd_mixer_oss_notify_handler(snd_cards
[idx
], SND_MIXER_OSS_NOTIFY_FREE
);
1362 module_init(alsa_mixer_oss_init
)
1363 module_exit(alsa_mixer_oss_exit
)
1365 EXPORT_SYMBOL(snd_mixer_oss_ioctl_card
);