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
);
82 static int snd_mixer_oss_release(struct inode
*inode
, struct file
*file
)
84 struct snd_mixer_oss_file
*fmixer
;
86 if (file
->private_data
) {
87 fmixer
= file
->private_data
;
88 module_put(fmixer
->card
->module
);
89 snd_card_file_remove(fmixer
->card
, file
);
95 static int snd_mixer_oss_info(struct snd_mixer_oss_file
*fmixer
,
96 mixer_info __user
*_info
)
98 struct snd_card
*card
= fmixer
->card
;
99 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
100 struct mixer_info info
;
102 memset(&info
, 0, sizeof(info
));
103 strlcpy(info
.id
, mixer
&& mixer
->id
[0] ? mixer
->id
: card
->driver
, sizeof(info
.id
));
104 strlcpy(info
.name
, mixer
&& mixer
->name
[0] ? mixer
->name
: card
->mixername
, sizeof(info
.name
));
105 info
.modify_counter
= card
->mixer_oss_change_count
;
106 if (copy_to_user(_info
, &info
, sizeof(info
)))
111 static int snd_mixer_oss_info_obsolete(struct snd_mixer_oss_file
*fmixer
,
112 _old_mixer_info __user
*_info
)
114 struct snd_card
*card
= fmixer
->card
;
115 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
116 _old_mixer_info info
;
118 memset(&info
, 0, sizeof(info
));
119 strlcpy(info
.id
, mixer
&& mixer
->id
[0] ? mixer
->id
: card
->driver
, sizeof(info
.id
));
120 strlcpy(info
.name
, mixer
&& mixer
->name
[0] ? mixer
->name
: card
->mixername
, sizeof(info
.name
));
121 if (copy_to_user(_info
, &info
, sizeof(info
)))
126 static int snd_mixer_oss_caps(struct snd_mixer_oss_file
*fmixer
)
128 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
133 if (mixer
->get_recsrc
&& mixer
->put_recsrc
)
134 result
|= SOUND_CAP_EXCL_INPUT
;
138 static int snd_mixer_oss_devmask(struct snd_mixer_oss_file
*fmixer
)
140 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
141 struct snd_mixer_oss_slot
*pslot
;
146 for (chn
= 0; chn
< 31; chn
++) {
147 pslot
= &mixer
->slots
[chn
];
148 if (pslot
->put_volume
|| pslot
->put_recsrc
)
154 static int snd_mixer_oss_stereodevs(struct snd_mixer_oss_file
*fmixer
)
156 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
157 struct snd_mixer_oss_slot
*pslot
;
162 for (chn
= 0; chn
< 31; chn
++) {
163 pslot
= &mixer
->slots
[chn
];
164 if (pslot
->put_volume
&& pslot
->stereo
)
170 static int snd_mixer_oss_recmask(struct snd_mixer_oss_file
*fmixer
)
172 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
177 if (mixer
->put_recsrc
&& mixer
->get_recsrc
) { /* exclusive */
178 result
= mixer
->mask_recsrc
;
180 struct snd_mixer_oss_slot
*pslot
;
182 for (chn
= 0; chn
< 31; chn
++) {
183 pslot
= &mixer
->slots
[chn
];
184 if (pslot
->put_recsrc
)
191 static int snd_mixer_oss_get_recsrc(struct snd_mixer_oss_file
*fmixer
)
193 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
198 if (mixer
->put_recsrc
&& mixer
->get_recsrc
) { /* exclusive */
201 if ((err
= mixer
->get_recsrc(fmixer
, &index
)) < 0)
205 struct snd_mixer_oss_slot
*pslot
;
207 for (chn
= 0; chn
< 31; chn
++) {
208 pslot
= &mixer
->slots
[chn
];
209 if (pslot
->get_recsrc
) {
211 pslot
->get_recsrc(fmixer
, pslot
, &active
);
217 return mixer
->oss_recsrc
= result
;
220 static int snd_mixer_oss_set_recsrc(struct snd_mixer_oss_file
*fmixer
, int recsrc
)
222 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
223 struct snd_mixer_oss_slot
*pslot
;
230 if (mixer
->get_recsrc
&& mixer
->put_recsrc
) { /* exclusive input */
231 if (recsrc
& ~mixer
->oss_recsrc
)
232 recsrc
&= ~mixer
->oss_recsrc
;
233 mixer
->put_recsrc(fmixer
, ffz(~recsrc
));
234 mixer
->get_recsrc(fmixer
, &index
);
237 for (chn
= 0; chn
< 31; chn
++) {
238 pslot
= &mixer
->slots
[chn
];
239 if (pslot
->put_recsrc
) {
240 active
= (recsrc
& (1 << chn
)) ? 1 : 0;
241 pslot
->put_recsrc(fmixer
, pslot
, active
);
245 for (chn
= 0; chn
< 31; chn
++) {
246 pslot
= &mixer
->slots
[chn
];
247 if (pslot
->get_recsrc
) {
249 pslot
->get_recsrc(fmixer
, pslot
, &active
);
258 static int snd_mixer_oss_get_volume(struct snd_mixer_oss_file
*fmixer
, int slot
)
260 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
261 struct snd_mixer_oss_slot
*pslot
;
262 int result
= 0, left
, right
;
264 if (mixer
== NULL
|| slot
> 30)
266 pslot
= &mixer
->slots
[slot
];
267 left
= pslot
->volume
[0];
268 right
= pslot
->volume
[1];
269 if (pslot
->get_volume
)
270 result
= pslot
->get_volume(fmixer
, pslot
, &left
, &right
);
273 if (snd_BUG_ON(left
< 0 || left
> 100))
275 if (snd_BUG_ON(right
< 0 || right
> 100))
278 pslot
->volume
[0] = left
;
279 pslot
->volume
[1] = right
;
280 result
= (left
& 0xff) | ((right
& 0xff) << 8);
285 static int snd_mixer_oss_set_volume(struct snd_mixer_oss_file
*fmixer
,
286 int slot
, int volume
)
288 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
289 struct snd_mixer_oss_slot
*pslot
;
290 int result
= 0, left
= volume
& 0xff, right
= (volume
>> 8) & 0xff;
292 if (mixer
== NULL
|| slot
> 30)
294 pslot
= &mixer
->slots
[slot
];
301 if (pslot
->put_volume
)
302 result
= pslot
->put_volume(fmixer
, pslot
, left
, right
);
305 pslot
->volume
[0] = left
;
306 pslot
->volume
[1] = right
;
307 return (left
& 0xff) | ((right
& 0xff) << 8);
310 static int snd_mixer_oss_ioctl1(struct snd_mixer_oss_file
*fmixer
, unsigned int cmd
, unsigned long arg
)
312 void __user
*argp
= (void __user
*)arg
;
313 int __user
*p
= argp
;
316 if (snd_BUG_ON(!fmixer
))
318 if (((cmd
>> 8) & 0xff) == 'M') {
320 case SOUND_MIXER_INFO
:
321 return snd_mixer_oss_info(fmixer
, argp
);
322 case SOUND_OLD_MIXER_INFO
:
323 return snd_mixer_oss_info_obsolete(fmixer
, argp
);
324 case SOUND_MIXER_WRITE_RECSRC
:
325 if (get_user(tmp
, p
))
327 tmp
= snd_mixer_oss_set_recsrc(fmixer
, tmp
);
330 return put_user(tmp
, p
);
332 return put_user(SNDRV_OSS_VERSION
, p
);
333 case OSS_ALSAEMULVER
:
334 return put_user(1, p
);
335 case SOUND_MIXER_READ_DEVMASK
:
336 tmp
= snd_mixer_oss_devmask(fmixer
);
339 return put_user(tmp
, p
);
340 case SOUND_MIXER_READ_STEREODEVS
:
341 tmp
= snd_mixer_oss_stereodevs(fmixer
);
344 return put_user(tmp
, p
);
345 case SOUND_MIXER_READ_RECMASK
:
346 tmp
= snd_mixer_oss_recmask(fmixer
);
349 return put_user(tmp
, p
);
350 case SOUND_MIXER_READ_CAPS
:
351 tmp
= snd_mixer_oss_caps(fmixer
);
354 return put_user(tmp
, p
);
355 case SOUND_MIXER_READ_RECSRC
:
356 tmp
= snd_mixer_oss_get_recsrc(fmixer
);
359 return put_user(tmp
, p
);
363 if (get_user(tmp
, p
))
365 tmp
= snd_mixer_oss_set_volume(fmixer
, cmd
& 0xff, tmp
);
368 return put_user(tmp
, p
);
369 } else if (cmd
& SIOC_OUT
) {
370 tmp
= snd_mixer_oss_get_volume(fmixer
, cmd
& 0xff);
373 return put_user(tmp
, p
);
378 static long snd_mixer_oss_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
380 return snd_mixer_oss_ioctl1(file
->private_data
, cmd
, arg
);
383 int snd_mixer_oss_ioctl_card(struct snd_card
*card
, unsigned int cmd
, unsigned long arg
)
385 struct snd_mixer_oss_file fmixer
;
387 if (snd_BUG_ON(!card
))
389 if (card
->mixer_oss
== NULL
)
391 memset(&fmixer
, 0, sizeof(fmixer
));
393 fmixer
.mixer
= card
->mixer_oss
;
394 return snd_mixer_oss_ioctl1(&fmixer
, cmd
, arg
);
399 #define snd_mixer_oss_ioctl_compat snd_mixer_oss_ioctl
401 #define snd_mixer_oss_ioctl_compat NULL
408 static const struct file_operations snd_mixer_oss_f_ops
=
410 .owner
= THIS_MODULE
,
411 .open
= snd_mixer_oss_open
,
412 .release
= snd_mixer_oss_release
,
414 .unlocked_ioctl
= snd_mixer_oss_ioctl
,
415 .compat_ioctl
= snd_mixer_oss_ioctl_compat
,
422 static long snd_mixer_oss_conv(long val
, long omin
, long omax
, long nmin
, long nmax
)
424 long orange
= omax
- omin
, nrange
= nmax
- nmin
;
428 return ((nrange
* (val
- omin
)) + (orange
/ 2)) / orange
+ nmin
;
431 /* convert from alsa native to oss values (0-100) */
432 static long snd_mixer_oss_conv1(long val
, long min
, long max
, int *old
)
434 if (val
== snd_mixer_oss_conv(*old
, 0, 100, min
, max
))
436 return snd_mixer_oss_conv(val
, min
, max
, 0, 100);
439 /* convert from oss to alsa native values */
440 static long snd_mixer_oss_conv2(long val
, long min
, long max
)
442 return snd_mixer_oss_conv(val
, 0, 100, min
, max
);
446 static void snd_mixer_oss_recsrce_set(struct snd_card
*card
, int slot
)
448 struct snd_mixer_oss
*mixer
= card
->mixer_oss
;
450 mixer
->mask_recsrc
|= 1 << slot
;
453 static int snd_mixer_oss_recsrce_get(struct snd_card
*card
, int slot
)
455 struct snd_mixer_oss
*mixer
= card
->mixer_oss
;
456 if (mixer
&& (mixer
->mask_recsrc
& (1 << slot
)))
462 #define SNDRV_MIXER_OSS_SIGNATURE 0x65999250
464 #define SNDRV_MIXER_OSS_ITEM_GLOBAL 0
465 #define SNDRV_MIXER_OSS_ITEM_GSWITCH 1
466 #define SNDRV_MIXER_OSS_ITEM_GROUTE 2
467 #define SNDRV_MIXER_OSS_ITEM_GVOLUME 3
468 #define SNDRV_MIXER_OSS_ITEM_PSWITCH 4
469 #define SNDRV_MIXER_OSS_ITEM_PROUTE 5
470 #define SNDRV_MIXER_OSS_ITEM_PVOLUME 6
471 #define SNDRV_MIXER_OSS_ITEM_CSWITCH 7
472 #define SNDRV_MIXER_OSS_ITEM_CROUTE 8
473 #define SNDRV_MIXER_OSS_ITEM_CVOLUME 9
474 #define SNDRV_MIXER_OSS_ITEM_CAPTURE 10
476 #define SNDRV_MIXER_OSS_ITEM_COUNT 11
478 #define SNDRV_MIXER_OSS_PRESENT_GLOBAL (1<<0)
479 #define SNDRV_MIXER_OSS_PRESENT_GSWITCH (1<<1)
480 #define SNDRV_MIXER_OSS_PRESENT_GROUTE (1<<2)
481 #define SNDRV_MIXER_OSS_PRESENT_GVOLUME (1<<3)
482 #define SNDRV_MIXER_OSS_PRESENT_PSWITCH (1<<4)
483 #define SNDRV_MIXER_OSS_PRESENT_PROUTE (1<<5)
484 #define SNDRV_MIXER_OSS_PRESENT_PVOLUME (1<<6)
485 #define SNDRV_MIXER_OSS_PRESENT_CSWITCH (1<<7)
486 #define SNDRV_MIXER_OSS_PRESENT_CROUTE (1<<8)
487 #define SNDRV_MIXER_OSS_PRESENT_CVOLUME (1<<9)
488 #define SNDRV_MIXER_OSS_PRESENT_CAPTURE (1<<10)
491 unsigned int signature
;
492 unsigned int present
;
493 unsigned int channels
;
494 unsigned int numid
[SNDRV_MIXER_OSS_ITEM_COUNT
];
495 unsigned int capture_item
;
496 struct snd_mixer_oss_assign_table
*assigned
;
497 unsigned int allocated
: 1;
500 #define ID_UNKNOWN ((unsigned int)-1)
502 static struct snd_kcontrol
*snd_mixer_oss_test_id(struct snd_mixer_oss
*mixer
, const char *name
, int index
)
504 struct snd_card
*card
= mixer
->card
;
505 struct snd_ctl_elem_id id
;
507 memset(&id
, 0, sizeof(id
));
508 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
509 strlcpy(id
.name
, name
, sizeof(id
.name
));
511 return snd_ctl_find_id(card
, &id
);
514 static void snd_mixer_oss_get_volume1_vol(struct snd_mixer_oss_file
*fmixer
,
515 struct snd_mixer_oss_slot
*pslot
,
517 int *left
, int *right
)
519 struct snd_ctl_elem_info
*uinfo
;
520 struct snd_ctl_elem_value
*uctl
;
521 struct snd_kcontrol
*kctl
;
522 struct snd_card
*card
= fmixer
->card
;
524 if (numid
== ID_UNKNOWN
)
526 down_read(&card
->controls_rwsem
);
527 if ((kctl
= snd_ctl_find_numid(card
, numid
)) == NULL
) {
528 up_read(&card
->controls_rwsem
);
531 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
532 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
533 if (uinfo
== NULL
|| uctl
== NULL
)
535 if (kctl
->info(kctl
, uinfo
))
537 if (kctl
->get(kctl
, uctl
))
539 if (uinfo
->type
== SNDRV_CTL_ELEM_TYPE_BOOLEAN
&&
540 uinfo
->value
.integer
.min
== 0 && uinfo
->value
.integer
.max
== 1)
542 *left
= snd_mixer_oss_conv1(uctl
->value
.integer
.value
[0], uinfo
->value
.integer
.min
, uinfo
->value
.integer
.max
, &pslot
->volume
[0]);
543 if (uinfo
->count
> 1)
544 *right
= snd_mixer_oss_conv1(uctl
->value
.integer
.value
[1], uinfo
->value
.integer
.min
, uinfo
->value
.integer
.max
, &pslot
->volume
[1]);
546 up_read(&card
->controls_rwsem
);
551 static void snd_mixer_oss_get_volume1_sw(struct snd_mixer_oss_file
*fmixer
,
552 struct snd_mixer_oss_slot
*pslot
,
554 int *left
, int *right
,
557 struct snd_ctl_elem_info
*uinfo
;
558 struct snd_ctl_elem_value
*uctl
;
559 struct snd_kcontrol
*kctl
;
560 struct snd_card
*card
= fmixer
->card
;
562 if (numid
== ID_UNKNOWN
)
564 down_read(&card
->controls_rwsem
);
565 if ((kctl
= snd_ctl_find_numid(card
, numid
)) == NULL
) {
566 up_read(&card
->controls_rwsem
);
569 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
570 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
571 if (uinfo
== NULL
|| uctl
== NULL
)
573 if (kctl
->info(kctl
, uinfo
))
575 if (kctl
->get(kctl
, uctl
))
577 if (!uctl
->value
.integer
.value
[0]) {
579 if (uinfo
->count
== 1)
582 if (uinfo
->count
> 1 && !uctl
->value
.integer
.value
[route
? 3 : 1])
585 up_read(&card
->controls_rwsem
);
590 static int snd_mixer_oss_get_volume1(struct snd_mixer_oss_file
*fmixer
,
591 struct snd_mixer_oss_slot
*pslot
,
592 int *left
, int *right
)
594 struct slot
*slot
= pslot
->private_data
;
596 *left
= *right
= 100;
597 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PVOLUME
) {
598 snd_mixer_oss_get_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PVOLUME
], left
, right
);
599 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GVOLUME
) {
600 snd_mixer_oss_get_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GVOLUME
], left
, right
);
601 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GLOBAL
) {
602 snd_mixer_oss_get_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GLOBAL
], left
, right
);
604 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PSWITCH
) {
605 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PSWITCH
], left
, right
, 0);
606 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GSWITCH
) {
607 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GSWITCH
], left
, right
, 0);
608 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PROUTE
) {
609 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PROUTE
], left
, right
, 1);
610 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GROUTE
) {
611 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GROUTE
], left
, right
, 1);
616 static void snd_mixer_oss_put_volume1_vol(struct snd_mixer_oss_file
*fmixer
,
617 struct snd_mixer_oss_slot
*pslot
,
621 struct snd_ctl_elem_info
*uinfo
;
622 struct snd_ctl_elem_value
*uctl
;
623 struct snd_kcontrol
*kctl
;
624 struct snd_card
*card
= fmixer
->card
;
627 if (numid
== ID_UNKNOWN
)
629 down_read(&card
->controls_rwsem
);
630 if ((kctl
= snd_ctl_find_numid(card
, numid
)) == NULL
) {
631 up_read(&card
->controls_rwsem
);
634 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
635 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
636 if (uinfo
== NULL
|| uctl
== NULL
)
638 if (kctl
->info(kctl
, uinfo
))
640 if (uinfo
->type
== SNDRV_CTL_ELEM_TYPE_BOOLEAN
&&
641 uinfo
->value
.integer
.min
== 0 && uinfo
->value
.integer
.max
== 1)
643 uctl
->value
.integer
.value
[0] = snd_mixer_oss_conv2(left
, uinfo
->value
.integer
.min
, uinfo
->value
.integer
.max
);
644 if (uinfo
->count
> 1)
645 uctl
->value
.integer
.value
[1] = snd_mixer_oss_conv2(right
, uinfo
->value
.integer
.min
, uinfo
->value
.integer
.max
);
646 if ((res
= kctl
->put(kctl
, uctl
)) < 0)
649 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &kctl
->id
);
651 up_read(&card
->controls_rwsem
);
656 static void snd_mixer_oss_put_volume1_sw(struct snd_mixer_oss_file
*fmixer
,
657 struct snd_mixer_oss_slot
*pslot
,
662 struct snd_ctl_elem_info
*uinfo
;
663 struct snd_ctl_elem_value
*uctl
;
664 struct snd_kcontrol
*kctl
;
665 struct snd_card
*card
= fmixer
->card
;
668 if (numid
== ID_UNKNOWN
)
670 down_read(&card
->controls_rwsem
);
671 if ((kctl
= snd_ctl_find_numid(card
, numid
)) == NULL
) {
672 up_read(&card
->controls_rwsem
);
675 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
676 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
677 if (uinfo
== NULL
|| uctl
== NULL
)
679 if (kctl
->info(kctl
, uinfo
))
681 if (uinfo
->count
> 1) {
682 uctl
->value
.integer
.value
[0] = left
> 0 ? 1 : 0;
683 uctl
->value
.integer
.value
[route
? 3 : 1] = right
> 0 ? 1 : 0;
685 uctl
->value
.integer
.value
[1] =
686 uctl
->value
.integer
.value
[2] = 0;
689 uctl
->value
.integer
.value
[0] = (left
> 0 || right
> 0) ? 1 : 0;
691 if ((res
= kctl
->put(kctl
, uctl
)) < 0)
694 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &kctl
->id
);
696 up_read(&card
->controls_rwsem
);
701 static int snd_mixer_oss_put_volume1(struct snd_mixer_oss_file
*fmixer
,
702 struct snd_mixer_oss_slot
*pslot
,
705 struct slot
*slot
= pslot
->private_data
;
707 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PVOLUME
) {
708 snd_mixer_oss_put_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PVOLUME
], left
, right
);
709 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_CVOLUME
)
710 snd_mixer_oss_put_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CVOLUME
], left
, right
);
711 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_CVOLUME
) {
712 snd_mixer_oss_put_volume1_vol(fmixer
, pslot
,
713 slot
->numid
[SNDRV_MIXER_OSS_ITEM_CVOLUME
], left
, right
);
714 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GVOLUME
) {
715 snd_mixer_oss_put_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GVOLUME
], left
, right
);
716 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GLOBAL
) {
717 snd_mixer_oss_put_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GLOBAL
], left
, right
);
720 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PSWITCH
)
721 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PSWITCH
], left
, right
, 0);
722 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_CSWITCH
)
723 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CSWITCH
], left
, right
, 0);
724 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GSWITCH
)
725 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GSWITCH
], left
, right
, 0);
726 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PROUTE
)
727 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PROUTE
], left
, right
, 1);
728 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_CROUTE
)
729 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CROUTE
], left
, right
, 1);
730 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GROUTE
)
731 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GROUTE
], left
, right
, 1);
733 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PSWITCH
) {
734 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PSWITCH
], left
, right
, 0);
735 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_CSWITCH
) {
736 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CSWITCH
], left
, right
, 0);
737 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GSWITCH
) {
738 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GSWITCH
], left
, right
, 0);
739 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PROUTE
) {
740 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PROUTE
], left
, right
, 1);
741 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_CROUTE
) {
742 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CROUTE
], left
, right
, 1);
743 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GROUTE
) {
744 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GROUTE
], left
, right
, 1);
750 static int snd_mixer_oss_get_recsrc1_sw(struct snd_mixer_oss_file
*fmixer
,
751 struct snd_mixer_oss_slot
*pslot
,
754 struct slot
*slot
= pslot
->private_data
;
758 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CSWITCH
], &left
, &right
, 0);
759 *active
= (left
|| right
) ? 1 : 0;
763 static int snd_mixer_oss_get_recsrc1_route(struct snd_mixer_oss_file
*fmixer
,
764 struct snd_mixer_oss_slot
*pslot
,
767 struct slot
*slot
= pslot
->private_data
;
771 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CROUTE
], &left
, &right
, 1);
772 *active
= (left
|| right
) ? 1 : 0;
776 static int snd_mixer_oss_put_recsrc1_sw(struct snd_mixer_oss_file
*fmixer
,
777 struct snd_mixer_oss_slot
*pslot
,
780 struct slot
*slot
= pslot
->private_data
;
782 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CSWITCH
], active
, active
, 0);
786 static int snd_mixer_oss_put_recsrc1_route(struct snd_mixer_oss_file
*fmixer
,
787 struct snd_mixer_oss_slot
*pslot
,
790 struct slot
*slot
= pslot
->private_data
;
792 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CROUTE
], active
, active
, 1);
796 static int snd_mixer_oss_get_recsrc2(struct snd_mixer_oss_file
*fmixer
, unsigned int *active_index
)
798 struct snd_card
*card
= fmixer
->card
;
799 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
800 struct snd_kcontrol
*kctl
;
801 struct snd_mixer_oss_slot
*pslot
;
803 struct snd_ctl_elem_info
*uinfo
;
804 struct snd_ctl_elem_value
*uctl
;
807 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
808 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
809 if (uinfo
== NULL
|| uctl
== NULL
) {
813 down_read(&card
->controls_rwsem
);
814 kctl
= snd_mixer_oss_test_id(mixer
, "Capture Source", 0);
819 if ((err
= kctl
->info(kctl
, uinfo
)) < 0)
821 if ((err
= kctl
->get(kctl
, uctl
)) < 0)
823 for (idx
= 0; idx
< 32; idx
++) {
824 if (!(mixer
->mask_recsrc
& (1 << idx
)))
826 pslot
= &mixer
->slots
[idx
];
827 slot
= pslot
->private_data
;
828 if (slot
->signature
!= SNDRV_MIXER_OSS_SIGNATURE
)
830 if (!(slot
->present
& SNDRV_MIXER_OSS_PRESENT_CAPTURE
))
832 if (slot
->capture_item
== uctl
->value
.enumerated
.item
[0]) {
839 up_read(&card
->controls_rwsem
);
846 static int snd_mixer_oss_put_recsrc2(struct snd_mixer_oss_file
*fmixer
, unsigned int active_index
)
848 struct snd_card
*card
= fmixer
->card
;
849 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
850 struct snd_kcontrol
*kctl
;
851 struct snd_mixer_oss_slot
*pslot
;
852 struct slot
*slot
= NULL
;
853 struct snd_ctl_elem_info
*uinfo
;
854 struct snd_ctl_elem_value
*uctl
;
858 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
859 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
860 if (uinfo
== NULL
|| uctl
== NULL
) {
864 down_read(&card
->controls_rwsem
);
865 kctl
= snd_mixer_oss_test_id(mixer
, "Capture Source", 0);
870 if ((err
= kctl
->info(kctl
, uinfo
)) < 0)
872 for (idx
= 0; idx
< 32; idx
++) {
873 if (!(mixer
->mask_recsrc
& (1 << idx
)))
875 pslot
= &mixer
->slots
[idx
];
876 slot
= pslot
->private_data
;
877 if (slot
->signature
!= SNDRV_MIXER_OSS_SIGNATURE
)
879 if (!(slot
->present
& SNDRV_MIXER_OSS_PRESENT_CAPTURE
))
881 if (idx
== active_index
)
887 for (idx
= 0; idx
< uinfo
->count
; idx
++)
888 uctl
->value
.enumerated
.item
[idx
] = slot
->capture_item
;
889 err
= kctl
->put(kctl
, uctl
);
891 snd_ctl_notify(fmixer
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &kctl
->id
);
894 up_read(&card
->controls_rwsem
);
901 struct snd_mixer_oss_assign_table
{
907 static int snd_mixer_oss_build_test(struct snd_mixer_oss
*mixer
, struct slot
*slot
, const char *name
, int index
, int item
)
909 struct snd_ctl_elem_info
*info
;
910 struct snd_kcontrol
*kcontrol
;
911 struct snd_card
*card
= mixer
->card
;
914 down_read(&card
->controls_rwsem
);
915 kcontrol
= snd_mixer_oss_test_id(mixer
, name
, index
);
916 if (kcontrol
== NULL
) {
917 up_read(&card
->controls_rwsem
);
920 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
922 up_read(&card
->controls_rwsem
);
925 if ((err
= kcontrol
->info(kcontrol
, info
)) < 0) {
926 up_read(&card
->controls_rwsem
);
930 slot
->numid
[item
] = kcontrol
->id
.numid
;
931 up_read(&card
->controls_rwsem
);
932 if (info
->count
> slot
->channels
)
933 slot
->channels
= info
->count
;
934 slot
->present
|= 1 << item
;
939 static void snd_mixer_oss_slot_free(struct snd_mixer_oss_slot
*chn
)
941 struct slot
*p
= chn
->private_data
;
943 if (p
->allocated
&& p
->assigned
) {
944 kfree(p
->assigned
->name
);
951 static void mixer_slot_clear(struct snd_mixer_oss_slot
*rslot
)
953 int idx
= rslot
->number
; /* remember this */
954 if (rslot
->private_free
)
955 rslot
->private_free(rslot
);
956 memset(rslot
, 0, sizeof(*rslot
));
960 /* In a separate function to keep gcc 3.2 happy - do NOT merge this in
961 snd_mixer_oss_build_input! */
962 static int snd_mixer_oss_build_test_all(struct snd_mixer_oss
*mixer
,
963 struct snd_mixer_oss_assign_table
*ptr
,
969 err
= snd_mixer_oss_build_test(mixer
, slot
, ptr
->name
, ptr
->index
,
970 SNDRV_MIXER_OSS_ITEM_GLOBAL
);
973 sprintf(str
, "%s Switch", ptr
->name
);
974 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
975 SNDRV_MIXER_OSS_ITEM_GSWITCH
);
978 sprintf(str
, "%s Route", ptr
->name
);
979 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
980 SNDRV_MIXER_OSS_ITEM_GROUTE
);
983 sprintf(str
, "%s Volume", ptr
->name
);
984 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
985 SNDRV_MIXER_OSS_ITEM_GVOLUME
);
988 sprintf(str
, "%s Playback Switch", ptr
->name
);
989 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
990 SNDRV_MIXER_OSS_ITEM_PSWITCH
);
993 sprintf(str
, "%s Playback Route", ptr
->name
);
994 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
995 SNDRV_MIXER_OSS_ITEM_PROUTE
);
998 sprintf(str
, "%s Playback Volume", ptr
->name
);
999 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
1000 SNDRV_MIXER_OSS_ITEM_PVOLUME
);
1003 sprintf(str
, "%s Capture Switch", ptr
->name
);
1004 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
1005 SNDRV_MIXER_OSS_ITEM_CSWITCH
);
1008 sprintf(str
, "%s Capture Route", ptr
->name
);
1009 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
1010 SNDRV_MIXER_OSS_ITEM_CROUTE
);
1013 sprintf(str
, "%s Capture Volume", ptr
->name
);
1014 err
= snd_mixer_oss_build_test(mixer
, slot
, str
, ptr
->index
,
1015 SNDRV_MIXER_OSS_ITEM_CVOLUME
);
1023 * build an OSS mixer element.
1024 * ptr_allocated means the entry is dynamically allocated (change via proc file).
1025 * when replace_old = 1, the old entry is replaced with the new one.
1027 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
)
1031 struct snd_kcontrol
*kctl
;
1032 struct snd_mixer_oss_slot
*rslot
;
1035 /* check if already assigned */
1036 if (mixer
->slots
[ptr
->oss_id
].get_volume
&& ! replace_old
)
1039 memset(&slot
, 0, sizeof(slot
));
1040 memset(slot
.numid
, 0xff, sizeof(slot
.numid
)); /* ID_UNKNOWN */
1041 if (snd_mixer_oss_build_test_all(mixer
, ptr
, &slot
))
1043 down_read(&mixer
->card
->controls_rwsem
);
1044 if (ptr
->index
== 0 && (kctl
= snd_mixer_oss_test_id(mixer
, "Capture Source", 0)) != NULL
) {
1045 struct snd_ctl_elem_info
*uinfo
;
1047 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
1049 up_read(&mixer
->card
->controls_rwsem
);
1053 if (kctl
->info(kctl
, uinfo
)) {
1054 up_read(&mixer
->card
->controls_rwsem
);
1058 strcpy(str
, ptr
->name
);
1059 if (!strcmp(str
, "Master"))
1061 if (!strcmp(str
, "Master Mono"))
1062 strcpy(str
, "Mix Mono");
1063 slot
.capture_item
= 0;
1064 if (!strcmp(uinfo
->value
.enumerated
.name
, str
)) {
1065 slot
.present
|= SNDRV_MIXER_OSS_PRESENT_CAPTURE
;
1067 for (slot
.capture_item
= 1; slot
.capture_item
< uinfo
->value
.enumerated
.items
; slot
.capture_item
++) {
1068 uinfo
->value
.enumerated
.item
= slot
.capture_item
;
1069 if (kctl
->info(kctl
, uinfo
)) {
1070 up_read(&mixer
->card
->controls_rwsem
);
1074 if (!strcmp(uinfo
->value
.enumerated
.name
, str
)) {
1075 slot
.present
|= SNDRV_MIXER_OSS_PRESENT_CAPTURE
;
1082 up_read(&mixer
->card
->controls_rwsem
);
1083 if (slot
.present
!= 0) {
1084 pslot
= kmalloc(sizeof(slot
), GFP_KERNEL
);
1088 pslot
->signature
= SNDRV_MIXER_OSS_SIGNATURE
;
1089 pslot
->assigned
= ptr
;
1090 pslot
->allocated
= ptr_allocated
;
1091 rslot
= &mixer
->slots
[ptr
->oss_id
];
1092 mixer_slot_clear(rslot
);
1093 rslot
->stereo
= slot
.channels
> 1 ? 1 : 0;
1094 rslot
->get_volume
= snd_mixer_oss_get_volume1
;
1095 rslot
->put_volume
= snd_mixer_oss_put_volume1
;
1096 /* note: ES18xx have both Capture Source and XX Capture Volume !!! */
1097 if (slot
.present
& SNDRV_MIXER_OSS_PRESENT_CSWITCH
) {
1098 rslot
->get_recsrc
= snd_mixer_oss_get_recsrc1_sw
;
1099 rslot
->put_recsrc
= snd_mixer_oss_put_recsrc1_sw
;
1100 } else if (slot
.present
& SNDRV_MIXER_OSS_PRESENT_CROUTE
) {
1101 rslot
->get_recsrc
= snd_mixer_oss_get_recsrc1_route
;
1102 rslot
->put_recsrc
= snd_mixer_oss_put_recsrc1_route
;
1103 } else if (slot
.present
& SNDRV_MIXER_OSS_PRESENT_CAPTURE
) {
1104 mixer
->mask_recsrc
|= 1 << ptr
->oss_id
;
1106 rslot
->private_data
= pslot
;
1107 rslot
->private_free
= snd_mixer_oss_slot_free
;
1113 #ifdef CONFIG_PROC_FS
1116 #define MIXER_VOL(name) [SOUND_MIXER_##name] = #name
1117 static char *oss_mixer_names
[SNDRV_OSS_MAX_MIXERS
] = {
1135 MIXER_VOL(DIGITAL1
),
1136 MIXER_VOL(DIGITAL2
),
1137 MIXER_VOL(DIGITAL3
),
1139 MIXER_VOL(PHONEOUT
),
1149 static void snd_mixer_oss_proc_read(struct snd_info_entry
*entry
,
1150 struct snd_info_buffer
*buffer
)
1152 struct snd_mixer_oss
*mixer
= entry
->private_data
;
1155 mutex_lock(&mixer
->reg_mutex
);
1156 for (i
= 0; i
< SNDRV_OSS_MAX_MIXERS
; i
++) {
1159 if (! oss_mixer_names
[i
])
1161 p
= (struct slot
*)mixer
->slots
[i
].private_data
;
1162 snd_iprintf(buffer
, "%s ", oss_mixer_names
[i
]);
1163 if (p
&& p
->assigned
)
1164 snd_iprintf(buffer
, "\"%s\" %d\n",
1166 p
->assigned
->index
);
1168 snd_iprintf(buffer
, "\"\" 0\n");
1170 mutex_unlock(&mixer
->reg_mutex
);
1173 static void snd_mixer_oss_proc_write(struct snd_info_entry
*entry
,
1174 struct snd_info_buffer
*buffer
)
1176 struct snd_mixer_oss
*mixer
= entry
->private_data
;
1177 char line
[128], str
[32], idxstr
[16];
1180 struct snd_mixer_oss_assign_table
*tbl
;
1183 while (!snd_info_get_line(buffer
, line
, sizeof(line
))) {
1184 cptr
= snd_info_get_str(str
, line
, sizeof(str
));
1185 for (ch
= 0; ch
< SNDRV_OSS_MAX_MIXERS
; ch
++)
1186 if (oss_mixer_names
[ch
] && strcmp(oss_mixer_names
[ch
], str
) == 0)
1188 if (ch
>= SNDRV_OSS_MAX_MIXERS
) {
1189 snd_printk(KERN_ERR
"mixer_oss: invalid OSS volume '%s'\n", str
);
1192 cptr
= snd_info_get_str(str
, cptr
, sizeof(str
));
1194 /* remove the entry */
1195 mutex_lock(&mixer
->reg_mutex
);
1196 mixer_slot_clear(&mixer
->slots
[ch
]);
1197 mutex_unlock(&mixer
->reg_mutex
);
1200 snd_info_get_str(idxstr
, cptr
, sizeof(idxstr
));
1201 idx
= simple_strtoul(idxstr
, NULL
, 10);
1202 if (idx
>= 0x4000) { /* too big */
1203 snd_printk(KERN_ERR
"mixer_oss: invalid index %d\n", idx
);
1206 mutex_lock(&mixer
->reg_mutex
);
1207 slot
= (struct slot
*)mixer
->slots
[ch
].private_data
;
1208 if (slot
&& slot
->assigned
&&
1209 slot
->assigned
->index
== idx
&& ! strcmp(slot
->assigned
->name
, str
))
1212 tbl
= kmalloc(sizeof(*tbl
), GFP_KERNEL
);
1214 snd_printk(KERN_ERR
"mixer_oss: no memory\n");
1218 tbl
->name
= kstrdup(str
, GFP_KERNEL
);
1224 if (snd_mixer_oss_build_input(mixer
, tbl
, 1, 1) <= 0) {
1229 mutex_unlock(&mixer
->reg_mutex
);
1233 static void snd_mixer_oss_proc_init(struct snd_mixer_oss
*mixer
)
1235 struct snd_info_entry
*entry
;
1237 entry
= snd_info_create_card_entry(mixer
->card
, "oss_mixer",
1238 mixer
->card
->proc_root
);
1241 entry
->content
= SNDRV_INFO_CONTENT_TEXT
;
1242 entry
->mode
= S_IFREG
| S_IRUGO
| S_IWUSR
;
1243 entry
->c
.text
.read
= snd_mixer_oss_proc_read
;
1244 entry
->c
.text
.write
= snd_mixer_oss_proc_write
;
1245 entry
->private_data
= mixer
;
1246 if (snd_info_register(entry
) < 0) {
1247 snd_info_free_entry(entry
);
1250 mixer
->proc_entry
= entry
;
1253 static void snd_mixer_oss_proc_done(struct snd_mixer_oss
*mixer
)
1255 snd_info_free_entry(mixer
->proc_entry
);
1256 mixer
->proc_entry
= NULL
;
1258 #else /* !CONFIG_PROC_FS */
1259 #define snd_mixer_oss_proc_init(mix)
1260 #define snd_mixer_oss_proc_done(mix)
1261 #endif /* CONFIG_PROC_FS */
1263 static void snd_mixer_oss_build(struct snd_mixer_oss
*mixer
)
1265 static struct snd_mixer_oss_assign_table table
[] = {
1266 { SOUND_MIXER_VOLUME
, "Master", 0 },
1267 { SOUND_MIXER_VOLUME
, "Front", 0 }, /* fallback */
1268 { SOUND_MIXER_BASS
, "Tone Control - Bass", 0 },
1269 { SOUND_MIXER_TREBLE
, "Tone Control - Treble", 0 },
1270 { SOUND_MIXER_SYNTH
, "Synth", 0 },
1271 { SOUND_MIXER_SYNTH
, "FM", 0 }, /* fallback */
1272 { SOUND_MIXER_SYNTH
, "Music", 0 }, /* fallback */
1273 { SOUND_MIXER_PCM
, "PCM", 0 },
1274 { SOUND_MIXER_SPEAKER
, "Beep", 0 },
1275 { SOUND_MIXER_SPEAKER
, "PC Speaker", 0 }, /* fallback */
1276 { SOUND_MIXER_SPEAKER
, "Speaker", 0 }, /* fallback */
1277 { SOUND_MIXER_LINE
, "Line", 0 },
1278 { SOUND_MIXER_MIC
, "Mic", 0 },
1279 { SOUND_MIXER_CD
, "CD", 0 },
1280 { SOUND_MIXER_IMIX
, "Monitor Mix", 0 },
1281 { SOUND_MIXER_ALTPCM
, "PCM", 1 },
1282 { SOUND_MIXER_ALTPCM
, "Headphone", 0 }, /* fallback */
1283 { SOUND_MIXER_ALTPCM
, "Wave", 0 }, /* fallback */
1284 { SOUND_MIXER_RECLEV
, "-- nothing --", 0 },
1285 { SOUND_MIXER_IGAIN
, "Capture", 0 },
1286 { SOUND_MIXER_OGAIN
, "Playback", 0 },
1287 { SOUND_MIXER_LINE1
, "Aux", 0 },
1288 { SOUND_MIXER_LINE2
, "Aux", 1 },
1289 { SOUND_MIXER_LINE3
, "Aux", 2 },
1290 { SOUND_MIXER_DIGITAL1
, "Digital", 0 },
1291 { SOUND_MIXER_DIGITAL1
, "IEC958", 0 }, /* fallback */
1292 { SOUND_MIXER_DIGITAL1
, "IEC958 Optical", 0 }, /* fallback */
1293 { SOUND_MIXER_DIGITAL1
, "IEC958 Coaxial", 0 }, /* fallback */
1294 { SOUND_MIXER_DIGITAL2
, "Digital", 1 },
1295 { SOUND_MIXER_DIGITAL3
, "Digital", 2 },
1296 { SOUND_MIXER_PHONEIN
, "Phone", 0 },
1297 { SOUND_MIXER_PHONEOUT
, "Master Mono", 0 },
1298 { SOUND_MIXER_PHONEOUT
, "Speaker", 0 }, /*fallback*/
1299 { SOUND_MIXER_PHONEOUT
, "Mono", 0 }, /*fallback*/
1300 { SOUND_MIXER_PHONEOUT
, "Phone", 0 }, /* fallback */
1301 { SOUND_MIXER_VIDEO
, "Video", 0 },
1302 { SOUND_MIXER_RADIO
, "Radio", 0 },
1303 { SOUND_MIXER_MONITOR
, "Monitor", 0 }
1307 for (idx
= 0; idx
< ARRAY_SIZE(table
); idx
++)
1308 snd_mixer_oss_build_input(mixer
, &table
[idx
], 0, 0);
1309 if (mixer
->mask_recsrc
) {
1310 mixer
->get_recsrc
= snd_mixer_oss_get_recsrc2
;
1311 mixer
->put_recsrc
= snd_mixer_oss_put_recsrc2
;
1319 static int snd_mixer_oss_free1(void *private)
1321 struct snd_mixer_oss
*mixer
= private;
1322 struct snd_card
*card
;
1328 if (snd_BUG_ON(mixer
!= card
->mixer_oss
))
1330 card
->mixer_oss
= NULL
;
1331 for (idx
= 0; idx
< SNDRV_OSS_MAX_MIXERS
; idx
++) {
1332 struct snd_mixer_oss_slot
*chn
= &mixer
->slots
[idx
];
1333 if (chn
->private_free
)
1334 chn
->private_free(chn
);
1340 static int snd_mixer_oss_notify_handler(struct snd_card
*card
, int cmd
)
1342 struct snd_mixer_oss
*mixer
;
1344 if (cmd
== SND_MIXER_OSS_NOTIFY_REGISTER
) {
1348 mixer
= kcalloc(2, sizeof(*mixer
), GFP_KERNEL
);
1351 mutex_init(&mixer
->reg_mutex
);
1352 sprintf(name
, "mixer%i%i", card
->number
, 0);
1353 if ((err
= snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER
,
1355 &snd_mixer_oss_f_ops
, card
,
1357 snd_printk(KERN_ERR
"unable to register OSS mixer device %i:%i\n",
1362 mixer
->oss_dev_alloc
= 1;
1364 if (*card
->mixername
)
1365 strlcpy(mixer
->name
, card
->mixername
, sizeof(mixer
->name
));
1367 strlcpy(mixer
->name
, name
, sizeof(mixer
->name
));
1368 #ifdef SNDRV_OSS_INFO_DEV_MIXERS
1369 snd_oss_info_register(SNDRV_OSS_INFO_DEV_MIXERS
,
1373 for (idx
= 0; idx
< SNDRV_OSS_MAX_MIXERS
; idx
++)
1374 mixer
->slots
[idx
].number
= idx
;
1375 card
->mixer_oss
= mixer
;
1376 snd_mixer_oss_build(mixer
);
1377 snd_mixer_oss_proc_init(mixer
);
1379 mixer
= card
->mixer_oss
;
1382 if (mixer
->oss_dev_alloc
) {
1383 #ifdef SNDRV_OSS_INFO_DEV_MIXERS
1384 snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_MIXERS
, mixer
->card
->number
);
1386 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER
, mixer
->card
, 0);
1387 mixer
->oss_dev_alloc
= 0;
1389 if (cmd
== SND_MIXER_OSS_NOTIFY_DISCONNECT
)
1391 snd_mixer_oss_proc_done(mixer
);
1392 return snd_mixer_oss_free1(mixer
);
1397 static int __init
alsa_mixer_oss_init(void)
1401 snd_mixer_oss_notify_callback
= snd_mixer_oss_notify_handler
;
1402 for (idx
= 0; idx
< SNDRV_CARDS
; idx
++) {
1404 snd_mixer_oss_notify_handler(snd_cards
[idx
], SND_MIXER_OSS_NOTIFY_REGISTER
);
1409 static void __exit
alsa_mixer_oss_exit(void)
1413 snd_mixer_oss_notify_callback
= NULL
;
1414 for (idx
= 0; idx
< SNDRV_CARDS
; idx
++) {
1416 snd_mixer_oss_notify_handler(snd_cards
[idx
], SND_MIXER_OSS_NOTIFY_FREE
);
1420 module_init(alsa_mixer_oss_init
)
1421 module_exit(alsa_mixer_oss_exit
)
1423 EXPORT_SYMBOL(snd_mixer_oss_ioctl_card
);