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 card
= snd_lookup_oss_minor_data(iminor(inode
),
47 SNDRV_OSS_DEVICE_TYPE_MIXER
);
50 if (card
->mixer_oss
== NULL
)
52 err
= snd_card_file_add(card
, file
);
55 fmixer
= kzalloc(sizeof(*fmixer
), GFP_KERNEL
);
57 snd_card_file_remove(card
, file
);
61 fmixer
->mixer
= card
->mixer_oss
;
62 file
->private_data
= fmixer
;
63 if (!try_module_get(card
->module
)) {
65 snd_card_file_remove(card
, file
);
71 static int snd_mixer_oss_release(struct inode
*inode
, struct file
*file
)
73 struct snd_mixer_oss_file
*fmixer
;
75 if (file
->private_data
) {
76 fmixer
= (struct snd_mixer_oss_file
*) file
->private_data
;
77 module_put(fmixer
->card
->module
);
78 snd_card_file_remove(fmixer
->card
, file
);
84 static int snd_mixer_oss_info(struct snd_mixer_oss_file
*fmixer
,
85 mixer_info __user
*_info
)
87 struct snd_card
*card
= fmixer
->card
;
88 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
89 struct mixer_info info
;
91 memset(&info
, 0, sizeof(info
));
92 strlcpy(info
.id
, mixer
&& mixer
->id
[0] ? mixer
->id
: card
->driver
, sizeof(info
.id
));
93 strlcpy(info
.name
, mixer
&& mixer
->name
[0] ? mixer
->name
: card
->mixername
, sizeof(info
.name
));
94 info
.modify_counter
= card
->mixer_oss_change_count
;
95 if (copy_to_user(_info
, &info
, sizeof(info
)))
100 static int snd_mixer_oss_info_obsolete(struct snd_mixer_oss_file
*fmixer
,
101 _old_mixer_info __user
*_info
)
103 struct snd_card
*card
= fmixer
->card
;
104 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
105 _old_mixer_info info
;
107 memset(&info
, 0, sizeof(info
));
108 strlcpy(info
.id
, mixer
&& mixer
->id
[0] ? mixer
->id
: card
->driver
, sizeof(info
.id
));
109 strlcpy(info
.name
, mixer
&& mixer
->name
[0] ? mixer
->name
: card
->mixername
, sizeof(info
.name
));
110 if (copy_to_user(_info
, &info
, sizeof(info
)))
115 static int snd_mixer_oss_caps(struct snd_mixer_oss_file
*fmixer
)
117 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
122 if (mixer
->get_recsrc
&& mixer
->put_recsrc
)
123 result
|= SOUND_CAP_EXCL_INPUT
;
127 static int snd_mixer_oss_devmask(struct snd_mixer_oss_file
*fmixer
)
129 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
130 struct snd_mixer_oss_slot
*pslot
;
135 for (chn
= 0; chn
< 31; chn
++) {
136 pslot
= &mixer
->slots
[chn
];
137 if (pslot
->put_volume
|| pslot
->put_recsrc
)
143 static int snd_mixer_oss_stereodevs(struct snd_mixer_oss_file
*fmixer
)
145 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
146 struct snd_mixer_oss_slot
*pslot
;
151 for (chn
= 0; chn
< 31; chn
++) {
152 pslot
= &mixer
->slots
[chn
];
153 if (pslot
->put_volume
&& pslot
->stereo
)
159 static int snd_mixer_oss_recmask(struct snd_mixer_oss_file
*fmixer
)
161 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
166 if (mixer
->put_recsrc
&& mixer
->get_recsrc
) { /* exclusive */
167 result
= mixer
->mask_recsrc
;
169 struct snd_mixer_oss_slot
*pslot
;
171 for (chn
= 0; chn
< 31; chn
++) {
172 pslot
= &mixer
->slots
[chn
];
173 if (pslot
->put_recsrc
)
180 static int snd_mixer_oss_get_recsrc(struct snd_mixer_oss_file
*fmixer
)
182 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
187 if (mixer
->put_recsrc
&& mixer
->get_recsrc
) { /* exclusive */
189 if ((err
= mixer
->get_recsrc(fmixer
, &result
)) < 0)
191 result
= 1 << result
;
193 struct snd_mixer_oss_slot
*pslot
;
195 for (chn
= 0; chn
< 31; chn
++) {
196 pslot
= &mixer
->slots
[chn
];
197 if (pslot
->get_recsrc
) {
199 pslot
->get_recsrc(fmixer
, pslot
, &active
);
205 return mixer
->oss_recsrc
= result
;
208 static int snd_mixer_oss_set_recsrc(struct snd_mixer_oss_file
*fmixer
, int recsrc
)
210 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
211 struct snd_mixer_oss_slot
*pslot
;
217 if (mixer
->get_recsrc
&& mixer
->put_recsrc
) { /* exclusive input */
218 if (recsrc
& ~mixer
->oss_recsrc
)
219 recsrc
&= ~mixer
->oss_recsrc
;
220 mixer
->put_recsrc(fmixer
, ffz(~recsrc
));
221 mixer
->get_recsrc(fmixer
, &result
);
222 result
= 1 << result
;
224 for (chn
= 0; chn
< 31; chn
++) {
225 pslot
= &mixer
->slots
[chn
];
226 if (pslot
->put_recsrc
) {
227 active
= (recsrc
& (1 << chn
)) ? 1 : 0;
228 pslot
->put_recsrc(fmixer
, pslot
, active
);
232 for (chn
= 0; chn
< 31; chn
++) {
233 pslot
= &mixer
->slots
[chn
];
234 if (pslot
->get_recsrc
) {
236 pslot
->get_recsrc(fmixer
, pslot
, &active
);
245 static int snd_mixer_oss_get_volume(struct snd_mixer_oss_file
*fmixer
, int slot
)
247 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
248 struct snd_mixer_oss_slot
*pslot
;
249 int result
= 0, left
, right
;
251 if (mixer
== NULL
|| slot
> 30)
253 pslot
= &mixer
->slots
[slot
];
254 left
= pslot
->volume
[0];
255 right
= pslot
->volume
[1];
256 if (pslot
->get_volume
)
257 result
= pslot
->get_volume(fmixer
, pslot
, &left
, &right
);
260 if (snd_BUG_ON(left
< 0 || left
> 100))
262 if (snd_BUG_ON(right
< 0 || right
> 100))
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 if (snd_BUG_ON(!fmixer
))
305 if (((cmd
>> 8) & 0xff) == 'M') {
307 case SOUND_MIXER_INFO
:
308 return snd_mixer_oss_info(fmixer
, argp
);
309 case SOUND_OLD_MIXER_INFO
:
310 return snd_mixer_oss_info_obsolete(fmixer
, argp
);
311 case SOUND_MIXER_WRITE_RECSRC
:
312 if (get_user(tmp
, p
))
314 tmp
= snd_mixer_oss_set_recsrc(fmixer
, tmp
);
317 return put_user(tmp
, p
);
319 return put_user(SNDRV_OSS_VERSION
, p
);
320 case OSS_ALSAEMULVER
:
321 return put_user(1, p
);
322 case SOUND_MIXER_READ_DEVMASK
:
323 tmp
= snd_mixer_oss_devmask(fmixer
);
326 return put_user(tmp
, p
);
327 case SOUND_MIXER_READ_STEREODEVS
:
328 tmp
= snd_mixer_oss_stereodevs(fmixer
);
331 return put_user(tmp
, p
);
332 case SOUND_MIXER_READ_RECMASK
:
333 tmp
= snd_mixer_oss_recmask(fmixer
);
336 return put_user(tmp
, p
);
337 case SOUND_MIXER_READ_CAPS
:
338 tmp
= snd_mixer_oss_caps(fmixer
);
341 return put_user(tmp
, p
);
342 case SOUND_MIXER_READ_RECSRC
:
343 tmp
= snd_mixer_oss_get_recsrc(fmixer
);
346 return put_user(tmp
, p
);
350 if (get_user(tmp
, p
))
352 tmp
= snd_mixer_oss_set_volume(fmixer
, cmd
& 0xff, tmp
);
355 return put_user(tmp
, p
);
356 } else if (cmd
& SIOC_OUT
) {
357 tmp
= snd_mixer_oss_get_volume(fmixer
, cmd
& 0xff);
360 return put_user(tmp
, p
);
365 static long snd_mixer_oss_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
367 return snd_mixer_oss_ioctl1((struct snd_mixer_oss_file
*) file
->private_data
, cmd
, arg
);
370 int snd_mixer_oss_ioctl_card(struct snd_card
*card
, unsigned int cmd
, unsigned long arg
)
372 struct snd_mixer_oss_file fmixer
;
374 if (snd_BUG_ON(!card
))
376 if (card
->mixer_oss
== NULL
)
378 memset(&fmixer
, 0, sizeof(fmixer
));
380 fmixer
.mixer
= card
->mixer_oss
;
381 return snd_mixer_oss_ioctl1(&fmixer
, cmd
, arg
);
386 #define snd_mixer_oss_ioctl_compat snd_mixer_oss_ioctl
388 #define snd_mixer_oss_ioctl_compat NULL
395 static const struct file_operations snd_mixer_oss_f_ops
=
397 .owner
= THIS_MODULE
,
398 .open
= snd_mixer_oss_open
,
399 .release
= snd_mixer_oss_release
,
400 .unlocked_ioctl
= snd_mixer_oss_ioctl
,
401 .compat_ioctl
= snd_mixer_oss_ioctl_compat
,
408 static long snd_mixer_oss_conv(long val
, long omin
, long omax
, long nmin
, long nmax
)
410 long orange
= omax
- omin
, nrange
= nmax
- nmin
;
414 return ((nrange
* (val
- omin
)) + (orange
/ 2)) / orange
+ nmin
;
417 /* convert from alsa native to oss values (0-100) */
418 static long snd_mixer_oss_conv1(long val
, long min
, long max
, int *old
)
420 if (val
== snd_mixer_oss_conv(*old
, 0, 100, min
, max
))
422 return snd_mixer_oss_conv(val
, min
, max
, 0, 100);
425 /* convert from oss to alsa native values */
426 static long snd_mixer_oss_conv2(long val
, long min
, long max
)
428 return snd_mixer_oss_conv(val
, 0, 100, min
, max
);
432 static void snd_mixer_oss_recsrce_set(struct snd_card
*card
, int slot
)
434 struct snd_mixer_oss
*mixer
= card
->mixer_oss
;
436 mixer
->mask_recsrc
|= 1 << slot
;
439 static int snd_mixer_oss_recsrce_get(struct snd_card
*card
, int slot
)
441 struct snd_mixer_oss
*mixer
= card
->mixer_oss
;
442 if (mixer
&& (mixer
->mask_recsrc
& (1 << slot
)))
448 #define SNDRV_MIXER_OSS_SIGNATURE 0x65999250
450 #define SNDRV_MIXER_OSS_ITEM_GLOBAL 0
451 #define SNDRV_MIXER_OSS_ITEM_GSWITCH 1
452 #define SNDRV_MIXER_OSS_ITEM_GROUTE 2
453 #define SNDRV_MIXER_OSS_ITEM_GVOLUME 3
454 #define SNDRV_MIXER_OSS_ITEM_PSWITCH 4
455 #define SNDRV_MIXER_OSS_ITEM_PROUTE 5
456 #define SNDRV_MIXER_OSS_ITEM_PVOLUME 6
457 #define SNDRV_MIXER_OSS_ITEM_CSWITCH 7
458 #define SNDRV_MIXER_OSS_ITEM_CROUTE 8
459 #define SNDRV_MIXER_OSS_ITEM_CVOLUME 9
460 #define SNDRV_MIXER_OSS_ITEM_CAPTURE 10
462 #define SNDRV_MIXER_OSS_ITEM_COUNT 11
464 #define SNDRV_MIXER_OSS_PRESENT_GLOBAL (1<<0)
465 #define SNDRV_MIXER_OSS_PRESENT_GSWITCH (1<<1)
466 #define SNDRV_MIXER_OSS_PRESENT_GROUTE (1<<2)
467 #define SNDRV_MIXER_OSS_PRESENT_GVOLUME (1<<3)
468 #define SNDRV_MIXER_OSS_PRESENT_PSWITCH (1<<4)
469 #define SNDRV_MIXER_OSS_PRESENT_PROUTE (1<<5)
470 #define SNDRV_MIXER_OSS_PRESENT_PVOLUME (1<<6)
471 #define SNDRV_MIXER_OSS_PRESENT_CSWITCH (1<<7)
472 #define SNDRV_MIXER_OSS_PRESENT_CROUTE (1<<8)
473 #define SNDRV_MIXER_OSS_PRESENT_CVOLUME (1<<9)
474 #define SNDRV_MIXER_OSS_PRESENT_CAPTURE (1<<10)
477 unsigned int signature
;
478 unsigned int present
;
479 unsigned int channels
;
480 unsigned int numid
[SNDRV_MIXER_OSS_ITEM_COUNT
];
481 unsigned int capture_item
;
482 struct snd_mixer_oss_assign_table
*assigned
;
483 unsigned int allocated
: 1;
486 #define ID_UNKNOWN ((unsigned int)-1)
488 static struct snd_kcontrol
*snd_mixer_oss_test_id(struct snd_mixer_oss
*mixer
, const char *name
, int index
)
490 struct snd_card
*card
= mixer
->card
;
491 struct snd_ctl_elem_id id
;
493 memset(&id
, 0, sizeof(id
));
494 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
495 strcpy(id
.name
, name
);
497 return snd_ctl_find_id(card
, &id
);
500 static void snd_mixer_oss_get_volume1_vol(struct snd_mixer_oss_file
*fmixer
,
501 struct snd_mixer_oss_slot
*pslot
,
503 int *left
, int *right
)
505 struct snd_ctl_elem_info
*uinfo
;
506 struct snd_ctl_elem_value
*uctl
;
507 struct snd_kcontrol
*kctl
;
508 struct snd_card
*card
= fmixer
->card
;
510 if (numid
== ID_UNKNOWN
)
512 down_read(&card
->controls_rwsem
);
513 if ((kctl
= snd_ctl_find_numid(card
, numid
)) == NULL
) {
514 up_read(&card
->controls_rwsem
);
517 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
518 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
519 if (uinfo
== NULL
|| uctl
== NULL
)
521 if (kctl
->info(kctl
, uinfo
))
523 if (kctl
->get(kctl
, uctl
))
525 if (uinfo
->type
== SNDRV_CTL_ELEM_TYPE_BOOLEAN
&&
526 uinfo
->value
.integer
.min
== 0 && uinfo
->value
.integer
.max
== 1)
528 *left
= snd_mixer_oss_conv1(uctl
->value
.integer
.value
[0], uinfo
->value
.integer
.min
, uinfo
->value
.integer
.max
, &pslot
->volume
[0]);
529 if (uinfo
->count
> 1)
530 *right
= snd_mixer_oss_conv1(uctl
->value
.integer
.value
[1], uinfo
->value
.integer
.min
, uinfo
->value
.integer
.max
, &pslot
->volume
[1]);
532 up_read(&card
->controls_rwsem
);
537 static void snd_mixer_oss_get_volume1_sw(struct snd_mixer_oss_file
*fmixer
,
538 struct snd_mixer_oss_slot
*pslot
,
540 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 (!uctl
->value
.integer
.value
[0]) {
565 if (uinfo
->count
== 1)
568 if (uinfo
->count
> 1 && !uctl
->value
.integer
.value
[route
? 3 : 1])
571 up_read(&card
->controls_rwsem
);
576 static int snd_mixer_oss_get_volume1(struct snd_mixer_oss_file
*fmixer
,
577 struct snd_mixer_oss_slot
*pslot
,
578 int *left
, int *right
)
580 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
582 *left
= *right
= 100;
583 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PVOLUME
) {
584 snd_mixer_oss_get_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PVOLUME
], left
, right
);
585 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GVOLUME
) {
586 snd_mixer_oss_get_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GVOLUME
], left
, right
);
587 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GLOBAL
) {
588 snd_mixer_oss_get_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GLOBAL
], left
, right
);
590 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PSWITCH
) {
591 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PSWITCH
], left
, right
, 0);
592 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GSWITCH
) {
593 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GSWITCH
], left
, right
, 0);
594 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PROUTE
) {
595 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PROUTE
], left
, right
, 1);
596 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GROUTE
) {
597 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GROUTE
], left
, right
, 1);
602 static void snd_mixer_oss_put_volume1_vol(struct snd_mixer_oss_file
*fmixer
,
603 struct snd_mixer_oss_slot
*pslot
,
607 struct snd_ctl_elem_info
*uinfo
;
608 struct snd_ctl_elem_value
*uctl
;
609 struct snd_kcontrol
*kctl
;
610 struct snd_card
*card
= fmixer
->card
;
613 if (numid
== ID_UNKNOWN
)
615 down_read(&card
->controls_rwsem
);
616 if ((kctl
= snd_ctl_find_numid(card
, numid
)) == NULL
)
618 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
619 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
620 if (uinfo
== NULL
|| uctl
== NULL
)
622 if (kctl
->info(kctl
, uinfo
))
624 if (uinfo
->type
== SNDRV_CTL_ELEM_TYPE_BOOLEAN
&&
625 uinfo
->value
.integer
.min
== 0 && uinfo
->value
.integer
.max
== 1)
627 uctl
->value
.integer
.value
[0] = snd_mixer_oss_conv2(left
, uinfo
->value
.integer
.min
, uinfo
->value
.integer
.max
);
628 if (uinfo
->count
> 1)
629 uctl
->value
.integer
.value
[1] = snd_mixer_oss_conv2(right
, uinfo
->value
.integer
.min
, uinfo
->value
.integer
.max
);
630 if ((res
= kctl
->put(kctl
, uctl
)) < 0)
633 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &kctl
->id
);
635 up_read(&card
->controls_rwsem
);
640 static void snd_mixer_oss_put_volume1_sw(struct snd_mixer_oss_file
*fmixer
,
641 struct snd_mixer_oss_slot
*pslot
,
646 struct snd_ctl_elem_info
*uinfo
;
647 struct snd_ctl_elem_value
*uctl
;
648 struct snd_kcontrol
*kctl
;
649 struct snd_card
*card
= fmixer
->card
;
652 if (numid
== ID_UNKNOWN
)
654 down_read(&card
->controls_rwsem
);
655 if ((kctl
= snd_ctl_find_numid(card
, numid
)) == NULL
) {
656 up_read(&fmixer
->card
->controls_rwsem
);
659 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
660 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
661 if (uinfo
== NULL
|| uctl
== NULL
)
663 if (kctl
->info(kctl
, uinfo
))
665 if (uinfo
->count
> 1) {
666 uctl
->value
.integer
.value
[0] = left
> 0 ? 1 : 0;
667 uctl
->value
.integer
.value
[route
? 3 : 1] = right
> 0 ? 1 : 0;
669 uctl
->value
.integer
.value
[1] =
670 uctl
->value
.integer
.value
[2] = 0;
673 uctl
->value
.integer
.value
[0] = (left
> 0 || right
> 0) ? 1 : 0;
675 if ((res
= kctl
->put(kctl
, uctl
)) < 0)
678 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &kctl
->id
);
680 up_read(&card
->controls_rwsem
);
685 static int snd_mixer_oss_put_volume1(struct snd_mixer_oss_file
*fmixer
,
686 struct snd_mixer_oss_slot
*pslot
,
689 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
691 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PVOLUME
) {
692 snd_mixer_oss_put_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PVOLUME
], left
, right
);
693 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_CVOLUME
)
694 snd_mixer_oss_put_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CVOLUME
], left
, right
);
695 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GVOLUME
) {
696 snd_mixer_oss_put_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GVOLUME
], left
, right
);
697 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GLOBAL
) {
698 snd_mixer_oss_put_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GLOBAL
], left
, right
);
701 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PSWITCH
)
702 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PSWITCH
], left
, right
, 0);
703 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GSWITCH
)
704 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GSWITCH
], left
, right
, 0);
705 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PROUTE
)
706 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PROUTE
], left
, right
, 1);
707 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GROUTE
)
708 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GROUTE
], left
, right
, 1);
710 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PSWITCH
) {
711 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PSWITCH
], left
, right
, 0);
712 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GSWITCH
) {
713 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GSWITCH
], left
, right
, 0);
714 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PROUTE
) {
715 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PROUTE
], left
, right
, 1);
716 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GROUTE
) {
717 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GROUTE
], left
, right
, 1);
723 static int snd_mixer_oss_get_recsrc1_sw(struct snd_mixer_oss_file
*fmixer
,
724 struct snd_mixer_oss_slot
*pslot
,
727 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
731 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CSWITCH
], &left
, &right
, 0);
732 *active
= (left
|| right
) ? 1 : 0;
736 static int snd_mixer_oss_get_recsrc1_route(struct snd_mixer_oss_file
*fmixer
,
737 struct snd_mixer_oss_slot
*pslot
,
740 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
744 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CROUTE
], &left
, &right
, 1);
745 *active
= (left
|| right
) ? 1 : 0;
749 static int snd_mixer_oss_put_recsrc1_sw(struct snd_mixer_oss_file
*fmixer
,
750 struct snd_mixer_oss_slot
*pslot
,
753 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
755 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CSWITCH
], active
, active
, 0);
759 static int snd_mixer_oss_put_recsrc1_route(struct snd_mixer_oss_file
*fmixer
,
760 struct snd_mixer_oss_slot
*pslot
,
763 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
765 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CROUTE
], active
, active
, 1);
769 static int snd_mixer_oss_get_recsrc2(struct snd_mixer_oss_file
*fmixer
, unsigned int *active_index
)
771 struct snd_card
*card
= fmixer
->card
;
772 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
773 struct snd_kcontrol
*kctl
;
774 struct snd_mixer_oss_slot
*pslot
;
776 struct snd_ctl_elem_info
*uinfo
;
777 struct snd_ctl_elem_value
*uctl
;
780 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
781 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
782 if (uinfo
== NULL
|| uctl
== NULL
) {
786 down_read(&card
->controls_rwsem
);
787 kctl
= snd_mixer_oss_test_id(mixer
, "Capture Source", 0);
792 if ((err
= kctl
->info(kctl
, uinfo
)) < 0)
794 if ((err
= kctl
->get(kctl
, uctl
)) < 0)
796 for (idx
= 0; idx
< 32; idx
++) {
797 if (!(mixer
->mask_recsrc
& (1 << idx
)))
799 pslot
= &mixer
->slots
[idx
];
800 slot
= (struct slot
*)pslot
->private_data
;
801 if (slot
->signature
!= SNDRV_MIXER_OSS_SIGNATURE
)
803 if (!(slot
->present
& SNDRV_MIXER_OSS_PRESENT_CAPTURE
))
805 if (slot
->capture_item
== uctl
->value
.enumerated
.item
[0]) {
812 up_read(&card
->controls_rwsem
);
818 static int snd_mixer_oss_put_recsrc2(struct snd_mixer_oss_file
*fmixer
, unsigned int active_index
)
820 struct snd_card
*card
= fmixer
->card
;
821 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
822 struct snd_kcontrol
*kctl
;
823 struct snd_mixer_oss_slot
*pslot
;
824 struct slot
*slot
= NULL
;
825 struct snd_ctl_elem_info
*uinfo
;
826 struct snd_ctl_elem_value
*uctl
;
830 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
831 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
832 if (uinfo
== NULL
|| uctl
== NULL
) {
836 down_read(&card
->controls_rwsem
);
837 kctl
= snd_mixer_oss_test_id(mixer
, "Capture Source", 0);
842 if ((err
= kctl
->info(kctl
, uinfo
)) < 0)
844 for (idx
= 0; idx
< 32; idx
++) {
845 if (!(mixer
->mask_recsrc
& (1 << idx
)))
847 pslot
= &mixer
->slots
[idx
];
848 slot
= (struct slot
*)pslot
->private_data
;
849 if (slot
->signature
!= SNDRV_MIXER_OSS_SIGNATURE
)
851 if (!(slot
->present
& SNDRV_MIXER_OSS_PRESENT_CAPTURE
))
853 if (idx
== active_index
)
859 for (idx
= 0; idx
< uinfo
->count
; idx
++)
860 uctl
->value
.enumerated
.item
[idx
] = slot
->capture_item
;
861 err
= kctl
->put(kctl
, uctl
);
863 snd_ctl_notify(fmixer
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &kctl
->id
);
866 up_read(&card
->controls_rwsem
);
872 struct snd_mixer_oss_assign_table
{
878 static int snd_mixer_oss_build_test(struct snd_mixer_oss
*mixer
, struct slot
*slot
, const char *name
, int index
, int item
)
880 struct snd_ctl_elem_info
*info
;
881 struct snd_kcontrol
*kcontrol
;
882 struct snd_card
*card
= mixer
->card
;
885 down_read(&card
->controls_rwsem
);
886 kcontrol
= snd_mixer_oss_test_id(mixer
, name
, index
);
887 if (kcontrol
== NULL
) {
888 up_read(&card
->controls_rwsem
);
891 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
893 up_read(&card
->controls_rwsem
);
896 if ((err
= kcontrol
->info(kcontrol
, info
)) < 0) {
897 up_read(&card
->controls_rwsem
);
901 slot
->numid
[item
] = kcontrol
->id
.numid
;
902 up_read(&card
->controls_rwsem
);
903 if (info
->count
> slot
->channels
)
904 slot
->channels
= info
->count
;
905 slot
->present
|= 1 << item
;
910 static void snd_mixer_oss_slot_free(struct snd_mixer_oss_slot
*chn
)
912 struct slot
*p
= (struct slot
*)chn
->private_data
;
914 if (p
->allocated
&& p
->assigned
) {
915 kfree(p
->assigned
->name
);
922 static void mixer_slot_clear(struct snd_mixer_oss_slot
*rslot
)
924 int idx
= rslot
->number
; /* remember this */
925 if (rslot
->private_free
)
926 rslot
->private_free(rslot
);
927 memset(rslot
, 0, sizeof(*rslot
));
931 /* In a separate function to keep gcc 3.2 happy - do NOT merge this in
932 snd_mixer_oss_build_input! */
933 static int snd_mixer_oss_build_test_all(struct snd_mixer_oss
*mixer
,
934 struct snd_mixer_oss_assign_table
*ptr
,
940 err
= snd_mixer_oss_build_test(mixer
, slot
, ptr
->name
, ptr
->index
,
941 SNDRV_MIXER_OSS_ITEM_GLOBAL
);
944 sprintf(str
, "%s Switch", ptr
->name
);
945 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
946 SNDRV_MIXER_OSS_ITEM_GSWITCH
);
949 sprintf(str
, "%s Route", ptr
->name
);
950 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
951 SNDRV_MIXER_OSS_ITEM_GROUTE
);
954 sprintf(str
, "%s Volume", ptr
->name
);
955 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
956 SNDRV_MIXER_OSS_ITEM_GVOLUME
);
959 sprintf(str
, "%s Playback Switch", ptr
->name
);
960 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
961 SNDRV_MIXER_OSS_ITEM_PSWITCH
);
964 sprintf(str
, "%s Playback Route", ptr
->name
);
965 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
966 SNDRV_MIXER_OSS_ITEM_PROUTE
);
969 sprintf(str
, "%s Playback Volume", ptr
->name
);
970 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
971 SNDRV_MIXER_OSS_ITEM_PVOLUME
);
974 sprintf(str
, "%s Capture Switch", ptr
->name
);
975 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
976 SNDRV_MIXER_OSS_ITEM_CSWITCH
);
979 sprintf(str
, "%s Capture Route", ptr
->name
);
980 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
981 SNDRV_MIXER_OSS_ITEM_CROUTE
);
984 sprintf(str
, "%s Capture Volume", ptr
->name
);
985 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
986 SNDRV_MIXER_OSS_ITEM_CVOLUME
);
994 * build an OSS mixer element.
995 * ptr_allocated means the entry is dynamically allocated (change via proc file).
996 * when replace_old = 1, the old entry is replaced with the new one.
998 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
)
1002 struct snd_kcontrol
*kctl
;
1003 struct snd_mixer_oss_slot
*rslot
;
1006 /* check if already assigned */
1007 if (mixer
->slots
[ptr
->oss_id
].get_volume
&& ! replace_old
)
1010 memset(&slot
, 0, sizeof(slot
));
1011 memset(slot
.numid
, 0xff, sizeof(slot
.numid
)); /* ID_UNKNOWN */
1012 if (snd_mixer_oss_build_test_all(mixer
, ptr
, &slot
))
1014 down_read(&mixer
->card
->controls_rwsem
);
1015 if (ptr
->index
== 0 && (kctl
= snd_mixer_oss_test_id(mixer
, "Capture Source", 0)) != NULL
) {
1016 struct snd_ctl_elem_info
*uinfo
;
1018 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
1020 up_read(&mixer
->card
->controls_rwsem
);
1024 if (kctl
->info(kctl
, uinfo
)) {
1025 up_read(&mixer
->card
->controls_rwsem
);
1028 strcpy(str
, ptr
->name
);
1029 if (!strcmp(str
, "Master"))
1031 if (!strcmp(str
, "Master Mono"))
1032 strcpy(str
, "Mix Mono");
1033 slot
.capture_item
= 0;
1034 if (!strcmp(uinfo
->value
.enumerated
.name
, str
)) {
1035 slot
.present
|= SNDRV_MIXER_OSS_PRESENT_CAPTURE
;
1037 for (slot
.capture_item
= 1; slot
.capture_item
< uinfo
->value
.enumerated
.items
; slot
.capture_item
++) {
1038 uinfo
->value
.enumerated
.item
= slot
.capture_item
;
1039 if (kctl
->info(kctl
, uinfo
)) {
1040 up_read(&mixer
->card
->controls_rwsem
);
1043 if (!strcmp(uinfo
->value
.enumerated
.name
, str
)) {
1044 slot
.present
|= SNDRV_MIXER_OSS_PRESENT_CAPTURE
;
1051 up_read(&mixer
->card
->controls_rwsem
);
1052 if (slot
.present
!= 0) {
1053 pslot
= kmalloc(sizeof(slot
), GFP_KERNEL
);
1057 pslot
->signature
= SNDRV_MIXER_OSS_SIGNATURE
;
1058 pslot
->assigned
= ptr
;
1059 pslot
->allocated
= ptr_allocated
;
1060 rslot
= &mixer
->slots
[ptr
->oss_id
];
1061 mixer_slot_clear(rslot
);
1062 rslot
->stereo
= slot
.channels
> 1 ? 1 : 0;
1063 rslot
->get_volume
= snd_mixer_oss_get_volume1
;
1064 rslot
->put_volume
= snd_mixer_oss_put_volume1
;
1065 /* note: ES18xx have both Capture Source and XX Capture Volume !!! */
1066 if (slot
.present
& SNDRV_MIXER_OSS_PRESENT_CSWITCH
) {
1067 rslot
->get_recsrc
= snd_mixer_oss_get_recsrc1_sw
;
1068 rslot
->put_recsrc
= snd_mixer_oss_put_recsrc1_sw
;
1069 } else if (slot
.present
& SNDRV_MIXER_OSS_PRESENT_CROUTE
) {
1070 rslot
->get_recsrc
= snd_mixer_oss_get_recsrc1_route
;
1071 rslot
->put_recsrc
= snd_mixer_oss_put_recsrc1_route
;
1072 } else if (slot
.present
& SNDRV_MIXER_OSS_PRESENT_CAPTURE
) {
1073 mixer
->mask_recsrc
|= 1 << ptr
->oss_id
;
1075 rslot
->private_data
= pslot
;
1076 rslot
->private_free
= snd_mixer_oss_slot_free
;
1082 #ifdef CONFIG_PROC_FS
1085 #define MIXER_VOL(name) [SOUND_MIXER_##name] = #name
1086 static char *oss_mixer_names
[SNDRV_OSS_MAX_MIXERS
] = {
1104 MIXER_VOL(DIGITAL1
),
1105 MIXER_VOL(DIGITAL2
),
1106 MIXER_VOL(DIGITAL3
),
1108 MIXER_VOL(PHONEOUT
),
1118 static void snd_mixer_oss_proc_read(struct snd_info_entry
*entry
,
1119 struct snd_info_buffer
*buffer
)
1121 struct snd_mixer_oss
*mixer
= entry
->private_data
;
1124 mutex_lock(&mixer
->reg_mutex
);
1125 for (i
= 0; i
< SNDRV_OSS_MAX_MIXERS
; i
++) {
1128 if (! oss_mixer_names
[i
])
1130 p
= (struct slot
*)mixer
->slots
[i
].private_data
;
1131 snd_iprintf(buffer
, "%s ", oss_mixer_names
[i
]);
1132 if (p
&& p
->assigned
)
1133 snd_iprintf(buffer
, "\"%s\" %d\n",
1135 p
->assigned
->index
);
1137 snd_iprintf(buffer
, "\"\" 0\n");
1139 mutex_unlock(&mixer
->reg_mutex
);
1142 static void snd_mixer_oss_proc_write(struct snd_info_entry
*entry
,
1143 struct snd_info_buffer
*buffer
)
1145 struct snd_mixer_oss
*mixer
= entry
->private_data
;
1146 char line
[128], str
[32], idxstr
[16], *cptr
;
1148 struct snd_mixer_oss_assign_table
*tbl
;
1151 while (!snd_info_get_line(buffer
, line
, sizeof(line
))) {
1152 cptr
= snd_info_get_str(str
, line
, sizeof(str
));
1153 for (ch
= 0; ch
< SNDRV_OSS_MAX_MIXERS
; ch
++)
1154 if (oss_mixer_names
[ch
] && strcmp(oss_mixer_names
[ch
], str
) == 0)
1156 if (ch
>= SNDRV_OSS_MAX_MIXERS
) {
1157 snd_printk(KERN_ERR
"mixer_oss: invalid OSS volume '%s'\n", str
);
1160 cptr
= snd_info_get_str(str
, cptr
, sizeof(str
));
1162 /* remove the entry */
1163 mutex_lock(&mixer
->reg_mutex
);
1164 mixer_slot_clear(&mixer
->slots
[ch
]);
1165 mutex_unlock(&mixer
->reg_mutex
);
1168 snd_info_get_str(idxstr
, cptr
, sizeof(idxstr
));
1169 idx
= simple_strtoul(idxstr
, NULL
, 10);
1170 if (idx
>= 0x4000) { /* too big */
1171 snd_printk(KERN_ERR
"mixer_oss: invalid index %d\n", idx
);
1174 mutex_lock(&mixer
->reg_mutex
);
1175 slot
= (struct slot
*)mixer
->slots
[ch
].private_data
;
1176 if (slot
&& slot
->assigned
&&
1177 slot
->assigned
->index
== idx
&& ! strcmp(slot
->assigned
->name
, str
))
1180 tbl
= kmalloc(sizeof(*tbl
), GFP_KERNEL
);
1182 snd_printk(KERN_ERR
"mixer_oss: no memory\n");
1186 tbl
->name
= kstrdup(str
, GFP_KERNEL
);
1192 if (snd_mixer_oss_build_input(mixer
, tbl
, 1, 1) <= 0) {
1197 mutex_unlock(&mixer
->reg_mutex
);
1201 static void snd_mixer_oss_proc_init(struct snd_mixer_oss
*mixer
)
1203 struct snd_info_entry
*entry
;
1205 entry
= snd_info_create_card_entry(mixer
->card
, "oss_mixer",
1206 mixer
->card
->proc_root
);
1209 entry
->content
= SNDRV_INFO_CONTENT_TEXT
;
1210 entry
->mode
= S_IFREG
| S_IRUGO
| S_IWUSR
;
1211 entry
->c
.text
.read
= snd_mixer_oss_proc_read
;
1212 entry
->c
.text
.write
= snd_mixer_oss_proc_write
;
1213 entry
->private_data
= mixer
;
1214 if (snd_info_register(entry
) < 0) {
1215 snd_info_free_entry(entry
);
1218 mixer
->proc_entry
= entry
;
1221 static void snd_mixer_oss_proc_done(struct snd_mixer_oss
*mixer
)
1223 snd_info_free_entry(mixer
->proc_entry
);
1224 mixer
->proc_entry
= NULL
;
1226 #else /* !CONFIG_PROC_FS */
1227 #define snd_mixer_oss_proc_init(mix)
1228 #define snd_mixer_oss_proc_done(mix)
1229 #endif /* CONFIG_PROC_FS */
1231 static void snd_mixer_oss_build(struct snd_mixer_oss
*mixer
)
1233 static struct snd_mixer_oss_assign_table table
[] = {
1234 { SOUND_MIXER_VOLUME
, "Master", 0 },
1235 { SOUND_MIXER_VOLUME
, "Front", 0 }, /* fallback */
1236 { SOUND_MIXER_BASS
, "Tone Control - Bass", 0 },
1237 { SOUND_MIXER_TREBLE
, "Tone Control - Treble", 0 },
1238 { SOUND_MIXER_SYNTH
, "Synth", 0 },
1239 { SOUND_MIXER_SYNTH
, "FM", 0 }, /* fallback */
1240 { SOUND_MIXER_SYNTH
, "Music", 0 }, /* fallback */
1241 { SOUND_MIXER_PCM
, "PCM", 0 },
1242 { SOUND_MIXER_SPEAKER
, "PC Speaker", 0 },
1243 { SOUND_MIXER_LINE
, "Line", 0 },
1244 { SOUND_MIXER_MIC
, "Mic", 0 },
1245 { SOUND_MIXER_CD
, "CD", 0 },
1246 { SOUND_MIXER_IMIX
, "Monitor Mix", 0 },
1247 { SOUND_MIXER_ALTPCM
, "PCM", 1 },
1248 { SOUND_MIXER_ALTPCM
, "Headphone", 0 }, /* fallback */
1249 { SOUND_MIXER_ALTPCM
, "Wave", 0 }, /* fallback */
1250 { SOUND_MIXER_RECLEV
, "-- nothing --", 0 },
1251 { SOUND_MIXER_IGAIN
, "Capture", 0 },
1252 { SOUND_MIXER_OGAIN
, "Playback", 0 },
1253 { SOUND_MIXER_LINE1
, "Aux", 0 },
1254 { SOUND_MIXER_LINE2
, "Aux", 1 },
1255 { SOUND_MIXER_LINE3
, "Aux", 2 },
1256 { SOUND_MIXER_DIGITAL1
, "Digital", 0 },
1257 { SOUND_MIXER_DIGITAL1
, "IEC958", 0 }, /* fallback */
1258 { SOUND_MIXER_DIGITAL1
, "IEC958 Optical", 0 }, /* fallback */
1259 { SOUND_MIXER_DIGITAL1
, "IEC958 Coaxial", 0 }, /* fallback */
1260 { SOUND_MIXER_DIGITAL2
, "Digital", 1 },
1261 { SOUND_MIXER_DIGITAL3
, "Digital", 2 },
1262 { SOUND_MIXER_PHONEIN
, "Phone", 0 },
1263 { SOUND_MIXER_PHONEOUT
, "Master Mono", 0 },
1264 { SOUND_MIXER_PHONEOUT
, "Speaker", 0 }, /*fallback*/
1265 { SOUND_MIXER_PHONEOUT
, "Mono", 0 }, /*fallback*/
1266 { SOUND_MIXER_PHONEOUT
, "Phone", 0 }, /* fallback */
1267 { SOUND_MIXER_VIDEO
, "Video", 0 },
1268 { SOUND_MIXER_RADIO
, "Radio", 0 },
1269 { SOUND_MIXER_MONITOR
, "Monitor", 0 }
1273 for (idx
= 0; idx
< ARRAY_SIZE(table
); idx
++)
1274 snd_mixer_oss_build_input(mixer
, &table
[idx
], 0, 0);
1275 if (mixer
->mask_recsrc
) {
1276 mixer
->get_recsrc
= snd_mixer_oss_get_recsrc2
;
1277 mixer
->put_recsrc
= snd_mixer_oss_put_recsrc2
;
1285 static int snd_mixer_oss_free1(void *private)
1287 struct snd_mixer_oss
*mixer
= private;
1288 struct snd_card
*card
;
1294 if (snd_BUG_ON(mixer
!= card
->mixer_oss
))
1296 card
->mixer_oss
= NULL
;
1297 for (idx
= 0; idx
< SNDRV_OSS_MAX_MIXERS
; idx
++) {
1298 struct snd_mixer_oss_slot
*chn
= &mixer
->slots
[idx
];
1299 if (chn
->private_free
)
1300 chn
->private_free(chn
);
1306 static int snd_mixer_oss_notify_handler(struct snd_card
*card
, int cmd
)
1308 struct snd_mixer_oss
*mixer
;
1310 if (cmd
== SND_MIXER_OSS_NOTIFY_REGISTER
) {
1314 mixer
= kcalloc(2, sizeof(*mixer
), GFP_KERNEL
);
1317 mutex_init(&mixer
->reg_mutex
);
1318 sprintf(name
, "mixer%i%i", card
->number
, 0);
1319 if ((err
= snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER
,
1321 &snd_mixer_oss_f_ops
, card
,
1323 snd_printk(KERN_ERR
"unable to register OSS mixer device %i:%i\n",
1328 mixer
->oss_dev_alloc
= 1;
1330 if (*card
->mixername
)
1331 strlcpy(mixer
->name
, card
->mixername
, sizeof(mixer
->name
));
1333 strlcpy(mixer
->name
, name
, sizeof(mixer
->name
));
1334 #ifdef SNDRV_OSS_INFO_DEV_MIXERS
1335 snd_oss_info_register(SNDRV_OSS_INFO_DEV_MIXERS
,
1339 for (idx
= 0; idx
< SNDRV_OSS_MAX_MIXERS
; idx
++)
1340 mixer
->slots
[idx
].number
= idx
;
1341 card
->mixer_oss
= mixer
;
1342 snd_mixer_oss_build(mixer
);
1343 snd_mixer_oss_proc_init(mixer
);
1345 mixer
= card
->mixer_oss
;
1348 if (mixer
->oss_dev_alloc
) {
1349 #ifdef SNDRV_OSS_INFO_DEV_MIXERS
1350 snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_MIXERS
, mixer
->card
->number
);
1352 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER
, mixer
->card
, 0);
1353 mixer
->oss_dev_alloc
= 0;
1355 if (cmd
== SND_MIXER_OSS_NOTIFY_DISCONNECT
)
1357 snd_mixer_oss_proc_done(mixer
);
1358 return snd_mixer_oss_free1(mixer
);
1363 static int __init
alsa_mixer_oss_init(void)
1367 snd_mixer_oss_notify_callback
= snd_mixer_oss_notify_handler
;
1368 for (idx
= 0; idx
< SNDRV_CARDS
; idx
++) {
1370 snd_mixer_oss_notify_handler(snd_cards
[idx
], SND_MIXER_OSS_NOTIFY_REGISTER
);
1375 static void __exit
alsa_mixer_oss_exit(void)
1379 snd_mixer_oss_notify_callback
= NULL
;
1380 for (idx
= 0; idx
< SNDRV_CARDS
; idx
++) {
1382 snd_mixer_oss_notify_handler(snd_cards
[idx
], SND_MIXER_OSS_NOTIFY_FREE
);
1386 module_init(alsa_mixer_oss_init
)
1387 module_exit(alsa_mixer_oss_exit
)
1389 EXPORT_SYMBOL(snd_mixer_oss_ioctl_card
);