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/slab.h>
25 #include <linux/time.h>
26 #include <linux/string.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@suse.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 card
= snd_lookup_oss_minor_data(iminor(inode
),
48 SNDRV_OSS_DEVICE_TYPE_MIXER
);
51 if (card
->mixer_oss
== NULL
)
53 err
= snd_card_file_add(card
, file
);
56 fmixer
= kzalloc(sizeof(*fmixer
), GFP_KERNEL
);
58 snd_card_file_remove(card
, file
);
62 fmixer
->mixer
= card
->mixer_oss
;
63 file
->private_data
= fmixer
;
64 if (!try_module_get(card
->module
)) {
66 snd_card_file_remove(card
, file
);
72 static int snd_mixer_oss_release(struct inode
*inode
, struct file
*file
)
74 struct snd_mixer_oss_file
*fmixer
;
76 if (file
->private_data
) {
77 fmixer
= (struct snd_mixer_oss_file
*) file
->private_data
;
78 module_put(fmixer
->card
->module
);
79 snd_card_file_remove(fmixer
->card
, file
);
85 static int snd_mixer_oss_info(struct snd_mixer_oss_file
*fmixer
,
86 mixer_info __user
*_info
)
88 struct snd_card
*card
= fmixer
->card
;
89 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
90 struct mixer_info info
;
92 memset(&info
, 0, sizeof(info
));
93 strlcpy(info
.id
, mixer
&& mixer
->id
[0] ? mixer
->id
: card
->driver
, sizeof(info
.id
));
94 strlcpy(info
.name
, mixer
&& mixer
->name
[0] ? mixer
->name
: card
->mixername
, sizeof(info
.name
));
95 info
.modify_counter
= card
->mixer_oss_change_count
;
96 if (copy_to_user(_info
, &info
, sizeof(info
)))
101 static int snd_mixer_oss_info_obsolete(struct snd_mixer_oss_file
*fmixer
,
102 _old_mixer_info __user
*_info
)
104 struct snd_card
*card
= fmixer
->card
;
105 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
106 _old_mixer_info info
;
108 memset(&info
, 0, sizeof(info
));
109 strlcpy(info
.id
, mixer
&& mixer
->id
[0] ? mixer
->id
: card
->driver
, sizeof(info
.id
));
110 strlcpy(info
.name
, mixer
&& mixer
->name
[0] ? mixer
->name
: card
->mixername
, sizeof(info
.name
));
111 if (copy_to_user(_info
, &info
, sizeof(info
)))
116 static int snd_mixer_oss_caps(struct snd_mixer_oss_file
*fmixer
)
118 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
123 if (mixer
->get_recsrc
&& mixer
->put_recsrc
)
124 result
|= SOUND_CAP_EXCL_INPUT
;
128 static int snd_mixer_oss_devmask(struct snd_mixer_oss_file
*fmixer
)
130 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
131 struct snd_mixer_oss_slot
*pslot
;
136 for (chn
= 0; chn
< 31; chn
++) {
137 pslot
= &mixer
->slots
[chn
];
138 if (pslot
->put_volume
|| pslot
->put_recsrc
)
144 static int snd_mixer_oss_stereodevs(struct snd_mixer_oss_file
*fmixer
)
146 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
147 struct snd_mixer_oss_slot
*pslot
;
152 for (chn
= 0; chn
< 31; chn
++) {
153 pslot
= &mixer
->slots
[chn
];
154 if (pslot
->put_volume
&& pslot
->stereo
)
160 static int snd_mixer_oss_recmask(struct snd_mixer_oss_file
*fmixer
)
162 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
167 if (mixer
->put_recsrc
&& mixer
->get_recsrc
) { /* exclusive */
168 result
= mixer
->mask_recsrc
;
170 struct snd_mixer_oss_slot
*pslot
;
172 for (chn
= 0; chn
< 31; chn
++) {
173 pslot
= &mixer
->slots
[chn
];
174 if (pslot
->put_recsrc
)
181 static int snd_mixer_oss_get_recsrc(struct snd_mixer_oss_file
*fmixer
)
183 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
188 if (mixer
->put_recsrc
&& mixer
->get_recsrc
) { /* exclusive */
190 if ((err
= mixer
->get_recsrc(fmixer
, &result
)) < 0)
192 result
= 1 << result
;
194 struct snd_mixer_oss_slot
*pslot
;
196 for (chn
= 0; chn
< 31; chn
++) {
197 pslot
= &mixer
->slots
[chn
];
198 if (pslot
->get_recsrc
) {
200 pslot
->get_recsrc(fmixer
, pslot
, &active
);
206 return mixer
->oss_recsrc
= result
;
209 static int snd_mixer_oss_set_recsrc(struct snd_mixer_oss_file
*fmixer
, int recsrc
)
211 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
212 struct snd_mixer_oss_slot
*pslot
;
218 if (mixer
->get_recsrc
&& mixer
->put_recsrc
) { /* exclusive input */
219 if (recsrc
& ~mixer
->oss_recsrc
)
220 recsrc
&= ~mixer
->oss_recsrc
;
221 mixer
->put_recsrc(fmixer
, ffz(~recsrc
));
222 mixer
->get_recsrc(fmixer
, &result
);
223 result
= 1 << result
;
225 for (chn
= 0; chn
< 31; chn
++) {
226 pslot
= &mixer
->slots
[chn
];
227 if (pslot
->put_recsrc
) {
228 active
= (recsrc
& (1 << chn
)) ? 1 : 0;
229 pslot
->put_recsrc(fmixer
, pslot
, active
);
233 for (chn
= 0; chn
< 31; chn
++) {
234 pslot
= &mixer
->slots
[chn
];
235 if (pslot
->get_recsrc
) {
237 pslot
->get_recsrc(fmixer
, pslot
, &active
);
246 static int snd_mixer_oss_get_volume(struct snd_mixer_oss_file
*fmixer
, int slot
)
248 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
249 struct snd_mixer_oss_slot
*pslot
;
250 int result
= 0, left
, right
;
252 if (mixer
== NULL
|| slot
> 30)
254 pslot
= &mixer
->slots
[slot
];
255 left
= pslot
->volume
[0];
256 right
= pslot
->volume
[1];
257 if (pslot
->get_volume
)
258 result
= pslot
->get_volume(fmixer
, pslot
, &left
, &right
);
261 snd_assert(left
>= 0 && left
<= 100, return -EIO
);
262 snd_assert(right
>= 0 && right
<= 100, return -EIO
);
264 pslot
->volume
[0] = left
;
265 pslot
->volume
[1] = right
;
266 result
= (left
& 0xff) | ((right
& 0xff) << 8);
271 static int snd_mixer_oss_set_volume(struct snd_mixer_oss_file
*fmixer
,
272 int slot
, int volume
)
274 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
275 struct snd_mixer_oss_slot
*pslot
;
276 int result
= 0, left
= volume
& 0xff, right
= (volume
>> 8) & 0xff;
278 if (mixer
== NULL
|| slot
> 30)
280 pslot
= &mixer
->slots
[slot
];
287 if (pslot
->put_volume
)
288 result
= pslot
->put_volume(fmixer
, pslot
, left
, right
);
291 pslot
->volume
[0] = left
;
292 pslot
->volume
[1] = right
;
293 return (left
& 0xff) | ((right
& 0xff) << 8);
296 static int snd_mixer_oss_ioctl1(struct snd_mixer_oss_file
*fmixer
, unsigned int cmd
, unsigned long arg
)
298 void __user
*argp
= (void __user
*)arg
;
299 int __user
*p
= argp
;
302 snd_assert(fmixer
!= NULL
, return -ENXIO
);
303 if (((cmd
>> 8) & 0xff) == 'M') {
305 case SOUND_MIXER_INFO
:
306 return snd_mixer_oss_info(fmixer
, argp
);
307 case SOUND_OLD_MIXER_INFO
:
308 return snd_mixer_oss_info_obsolete(fmixer
, argp
);
309 case SOUND_MIXER_WRITE_RECSRC
:
310 if (get_user(tmp
, p
))
312 tmp
= snd_mixer_oss_set_recsrc(fmixer
, tmp
);
315 return put_user(tmp
, p
);
317 return put_user(SNDRV_OSS_VERSION
, p
);
318 case OSS_ALSAEMULVER
:
319 return put_user(1, p
);
320 case SOUND_MIXER_READ_DEVMASK
:
321 tmp
= snd_mixer_oss_devmask(fmixer
);
324 return put_user(tmp
, p
);
325 case SOUND_MIXER_READ_STEREODEVS
:
326 tmp
= snd_mixer_oss_stereodevs(fmixer
);
329 return put_user(tmp
, p
);
330 case SOUND_MIXER_READ_RECMASK
:
331 tmp
= snd_mixer_oss_recmask(fmixer
);
334 return put_user(tmp
, p
);
335 case SOUND_MIXER_READ_CAPS
:
336 tmp
= snd_mixer_oss_caps(fmixer
);
339 return put_user(tmp
, p
);
340 case SOUND_MIXER_READ_RECSRC
:
341 tmp
= snd_mixer_oss_get_recsrc(fmixer
);
344 return put_user(tmp
, p
);
348 if (get_user(tmp
, p
))
350 tmp
= snd_mixer_oss_set_volume(fmixer
, cmd
& 0xff, tmp
);
353 return put_user(tmp
, p
);
354 } else if (cmd
& SIOC_OUT
) {
355 tmp
= snd_mixer_oss_get_volume(fmixer
, cmd
& 0xff);
358 return put_user(tmp
, p
);
363 static long snd_mixer_oss_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
365 return snd_mixer_oss_ioctl1((struct snd_mixer_oss_file
*) file
->private_data
, cmd
, arg
);
368 int snd_mixer_oss_ioctl_card(struct snd_card
*card
, unsigned int cmd
, unsigned long arg
)
370 struct snd_mixer_oss_file fmixer
;
372 snd_assert(card
!= NULL
, return -ENXIO
);
373 if (card
->mixer_oss
== NULL
)
375 memset(&fmixer
, 0, sizeof(fmixer
));
377 fmixer
.mixer
= card
->mixer_oss
;
378 return snd_mixer_oss_ioctl1(&fmixer
, cmd
, arg
);
383 #define snd_mixer_oss_ioctl_compat snd_mixer_oss_ioctl
385 #define snd_mixer_oss_ioctl_compat NULL
392 static const struct file_operations snd_mixer_oss_f_ops
=
394 .owner
= THIS_MODULE
,
395 .open
= snd_mixer_oss_open
,
396 .release
= snd_mixer_oss_release
,
397 .unlocked_ioctl
= snd_mixer_oss_ioctl
,
398 .compat_ioctl
= snd_mixer_oss_ioctl_compat
,
405 static long snd_mixer_oss_conv(long val
, long omin
, long omax
, long nmin
, long nmax
)
407 long orange
= omax
- omin
, nrange
= nmax
- nmin
;
411 return ((nrange
* (val
- omin
)) + (orange
/ 2)) / orange
+ nmin
;
414 /* convert from alsa native to oss values (0-100) */
415 static long snd_mixer_oss_conv1(long val
, long min
, long max
, int *old
)
417 if (val
== snd_mixer_oss_conv(*old
, 0, 100, min
, max
))
419 return snd_mixer_oss_conv(val
, min
, max
, 0, 100);
422 /* convert from oss to alsa native values */
423 static long snd_mixer_oss_conv2(long val
, long min
, long max
)
425 return snd_mixer_oss_conv(val
, 0, 100, min
, max
);
429 static void snd_mixer_oss_recsrce_set(struct snd_card
*card
, int slot
)
431 struct snd_mixer_oss
*mixer
= card
->mixer_oss
;
433 mixer
->mask_recsrc
|= 1 << slot
;
436 static int snd_mixer_oss_recsrce_get(struct snd_card
*card
, int slot
)
438 struct snd_mixer_oss
*mixer
= card
->mixer_oss
;
439 if (mixer
&& (mixer
->mask_recsrc
& (1 << slot
)))
445 #define SNDRV_MIXER_OSS_SIGNATURE 0x65999250
447 #define SNDRV_MIXER_OSS_ITEM_GLOBAL 0
448 #define SNDRV_MIXER_OSS_ITEM_GSWITCH 1
449 #define SNDRV_MIXER_OSS_ITEM_GROUTE 2
450 #define SNDRV_MIXER_OSS_ITEM_GVOLUME 3
451 #define SNDRV_MIXER_OSS_ITEM_PSWITCH 4
452 #define SNDRV_MIXER_OSS_ITEM_PROUTE 5
453 #define SNDRV_MIXER_OSS_ITEM_PVOLUME 6
454 #define SNDRV_MIXER_OSS_ITEM_CSWITCH 7
455 #define SNDRV_MIXER_OSS_ITEM_CROUTE 8
456 #define SNDRV_MIXER_OSS_ITEM_CVOLUME 9
457 #define SNDRV_MIXER_OSS_ITEM_CAPTURE 10
459 #define SNDRV_MIXER_OSS_ITEM_COUNT 11
461 #define SNDRV_MIXER_OSS_PRESENT_GLOBAL (1<<0)
462 #define SNDRV_MIXER_OSS_PRESENT_GSWITCH (1<<1)
463 #define SNDRV_MIXER_OSS_PRESENT_GROUTE (1<<2)
464 #define SNDRV_MIXER_OSS_PRESENT_GVOLUME (1<<3)
465 #define SNDRV_MIXER_OSS_PRESENT_PSWITCH (1<<4)
466 #define SNDRV_MIXER_OSS_PRESENT_PROUTE (1<<5)
467 #define SNDRV_MIXER_OSS_PRESENT_PVOLUME (1<<6)
468 #define SNDRV_MIXER_OSS_PRESENT_CSWITCH (1<<7)
469 #define SNDRV_MIXER_OSS_PRESENT_CROUTE (1<<8)
470 #define SNDRV_MIXER_OSS_PRESENT_CVOLUME (1<<9)
471 #define SNDRV_MIXER_OSS_PRESENT_CAPTURE (1<<10)
474 unsigned int signature
;
475 unsigned int present
;
476 unsigned int channels
;
477 unsigned int numid
[SNDRV_MIXER_OSS_ITEM_COUNT
];
478 unsigned int capture_item
;
479 struct snd_mixer_oss_assign_table
*assigned
;
480 unsigned int allocated
: 1;
483 #define ID_UNKNOWN ((unsigned int)-1)
485 static struct snd_kcontrol
*snd_mixer_oss_test_id(struct snd_mixer_oss
*mixer
, const char *name
, int index
)
487 struct snd_card
*card
= mixer
->card
;
488 struct snd_ctl_elem_id id
;
490 memset(&id
, 0, sizeof(id
));
491 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
492 strcpy(id
.name
, name
);
494 return snd_ctl_find_id(card
, &id
);
497 static void snd_mixer_oss_get_volume1_vol(struct snd_mixer_oss_file
*fmixer
,
498 struct snd_mixer_oss_slot
*pslot
,
500 int *left
, int *right
)
502 struct snd_ctl_elem_info
*uinfo
;
503 struct snd_ctl_elem_value
*uctl
;
504 struct snd_kcontrol
*kctl
;
505 struct snd_card
*card
= fmixer
->card
;
507 if (numid
== ID_UNKNOWN
)
509 down_read(&card
->controls_rwsem
);
510 if ((kctl
= snd_ctl_find_numid(card
, numid
)) == NULL
) {
511 up_read(&card
->controls_rwsem
);
514 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
515 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
516 if (uinfo
== NULL
|| uctl
== NULL
)
518 if (kctl
->info(kctl
, uinfo
))
520 if (kctl
->get(kctl
, uctl
))
522 if (uinfo
->type
== SNDRV_CTL_ELEM_TYPE_BOOLEAN
&&
523 uinfo
->value
.integer
.min
== 0 && uinfo
->value
.integer
.max
== 1)
525 *left
= snd_mixer_oss_conv1(uctl
->value
.integer
.value
[0], uinfo
->value
.integer
.min
, uinfo
->value
.integer
.max
, &pslot
->volume
[0]);
526 if (uinfo
->count
> 1)
527 *right
= snd_mixer_oss_conv1(uctl
->value
.integer
.value
[1], uinfo
->value
.integer
.min
, uinfo
->value
.integer
.max
, &pslot
->volume
[1]);
529 up_read(&card
->controls_rwsem
);
534 static void snd_mixer_oss_get_volume1_sw(struct snd_mixer_oss_file
*fmixer
,
535 struct snd_mixer_oss_slot
*pslot
,
537 int *left
, int *right
,
540 struct snd_ctl_elem_info
*uinfo
;
541 struct snd_ctl_elem_value
*uctl
;
542 struct snd_kcontrol
*kctl
;
543 struct snd_card
*card
= fmixer
->card
;
545 if (numid
== ID_UNKNOWN
)
547 down_read(&card
->controls_rwsem
);
548 if ((kctl
= snd_ctl_find_numid(card
, numid
)) == NULL
) {
549 up_read(&card
->controls_rwsem
);
552 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
553 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
554 if (uinfo
== NULL
|| uctl
== NULL
)
556 if (kctl
->info(kctl
, uinfo
))
558 if (kctl
->get(kctl
, uctl
))
560 if (!uctl
->value
.integer
.value
[0]) {
562 if (uinfo
->count
== 1)
565 if (uinfo
->count
> 1 && !uctl
->value
.integer
.value
[route
? 3 : 1])
568 up_read(&card
->controls_rwsem
);
573 static int snd_mixer_oss_get_volume1(struct snd_mixer_oss_file
*fmixer
,
574 struct snd_mixer_oss_slot
*pslot
,
575 int *left
, int *right
)
577 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
579 *left
= *right
= 100;
580 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PVOLUME
) {
581 snd_mixer_oss_get_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PVOLUME
], left
, right
);
582 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GVOLUME
) {
583 snd_mixer_oss_get_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GVOLUME
], left
, right
);
584 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GLOBAL
) {
585 snd_mixer_oss_get_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GLOBAL
], left
, right
);
587 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PSWITCH
) {
588 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PSWITCH
], left
, right
, 0);
589 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GSWITCH
) {
590 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GSWITCH
], left
, right
, 0);
591 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PROUTE
) {
592 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PROUTE
], left
, right
, 1);
593 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GROUTE
) {
594 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GROUTE
], left
, right
, 1);
599 static void snd_mixer_oss_put_volume1_vol(struct snd_mixer_oss_file
*fmixer
,
600 struct snd_mixer_oss_slot
*pslot
,
604 struct snd_ctl_elem_info
*uinfo
;
605 struct snd_ctl_elem_value
*uctl
;
606 struct snd_kcontrol
*kctl
;
607 struct snd_card
*card
= fmixer
->card
;
610 if (numid
== ID_UNKNOWN
)
612 down_read(&card
->controls_rwsem
);
613 if ((kctl
= snd_ctl_find_numid(card
, numid
)) == NULL
) {
614 up_read(&card
->controls_rwsem
);
617 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
618 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
619 if (uinfo
== NULL
|| uctl
== NULL
)
621 if (kctl
->info(kctl
, uinfo
))
623 if (uinfo
->type
== SNDRV_CTL_ELEM_TYPE_BOOLEAN
&&
624 uinfo
->value
.integer
.min
== 0 && uinfo
->value
.integer
.max
== 1)
626 uctl
->value
.integer
.value
[0] = snd_mixer_oss_conv2(left
, uinfo
->value
.integer
.min
, uinfo
->value
.integer
.max
);
627 if (uinfo
->count
> 1)
628 uctl
->value
.integer
.value
[1] = snd_mixer_oss_conv2(right
, uinfo
->value
.integer
.min
, uinfo
->value
.integer
.max
);
629 if ((res
= kctl
->put(kctl
, uctl
)) < 0)
632 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &kctl
->id
);
634 up_read(&card
->controls_rwsem
);
639 static void snd_mixer_oss_put_volume1_sw(struct snd_mixer_oss_file
*fmixer
,
640 struct snd_mixer_oss_slot
*pslot
,
645 struct snd_ctl_elem_info
*uinfo
;
646 struct snd_ctl_elem_value
*uctl
;
647 struct snd_kcontrol
*kctl
;
648 struct snd_card
*card
= fmixer
->card
;
651 if (numid
== ID_UNKNOWN
)
653 down_read(&card
->controls_rwsem
);
654 if ((kctl
= snd_ctl_find_numid(card
, numid
)) == NULL
) {
655 up_read(&card
->controls_rwsem
);
658 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
659 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
660 if (uinfo
== NULL
|| uctl
== NULL
)
662 if (kctl
->info(kctl
, uinfo
))
664 if (uinfo
->count
> 1) {
665 uctl
->value
.integer
.value
[0] = left
> 0 ? 1 : 0;
666 uctl
->value
.integer
.value
[route
? 3 : 1] = right
> 0 ? 1 : 0;
668 uctl
->value
.integer
.value
[1] =
669 uctl
->value
.integer
.value
[2] = 0;
672 uctl
->value
.integer
.value
[0] = (left
> 0 || right
> 0) ? 1 : 0;
674 if ((res
= kctl
->put(kctl
, uctl
)) < 0)
677 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &kctl
->id
);
679 up_read(&card
->controls_rwsem
);
684 static int snd_mixer_oss_put_volume1(struct snd_mixer_oss_file
*fmixer
,
685 struct snd_mixer_oss_slot
*pslot
,
688 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
690 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PVOLUME
) {
691 snd_mixer_oss_put_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PVOLUME
], left
, right
);
692 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_CVOLUME
)
693 snd_mixer_oss_put_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CVOLUME
], left
, right
);
694 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GVOLUME
) {
695 snd_mixer_oss_put_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GVOLUME
], left
, right
);
696 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GLOBAL
) {
697 snd_mixer_oss_put_volume1_vol(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GLOBAL
], left
, right
);
700 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PSWITCH
)
701 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PSWITCH
], left
, right
, 0);
702 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GSWITCH
)
703 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GSWITCH
], left
, right
, 0);
704 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PROUTE
)
705 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PROUTE
], left
, right
, 1);
706 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GROUTE
)
707 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GROUTE
], left
, right
, 1);
709 if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PSWITCH
) {
710 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PSWITCH
], left
, right
, 0);
711 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GSWITCH
) {
712 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GSWITCH
], left
, right
, 0);
713 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_PROUTE
) {
714 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_PROUTE
], left
, right
, 1);
715 } else if (slot
->present
& SNDRV_MIXER_OSS_PRESENT_GROUTE
) {
716 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_GROUTE
], left
, right
, 1);
722 static int snd_mixer_oss_get_recsrc1_sw(struct snd_mixer_oss_file
*fmixer
,
723 struct snd_mixer_oss_slot
*pslot
,
726 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
730 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CSWITCH
], &left
, &right
, 0);
731 *active
= (left
|| right
) ? 1 : 0;
735 static int snd_mixer_oss_get_recsrc1_route(struct snd_mixer_oss_file
*fmixer
,
736 struct snd_mixer_oss_slot
*pslot
,
739 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
743 snd_mixer_oss_get_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CROUTE
], &left
, &right
, 1);
744 *active
= (left
|| right
) ? 1 : 0;
748 static int snd_mixer_oss_put_recsrc1_sw(struct snd_mixer_oss_file
*fmixer
,
749 struct snd_mixer_oss_slot
*pslot
,
752 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
754 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CSWITCH
], active
, active
, 0);
758 static int snd_mixer_oss_put_recsrc1_route(struct snd_mixer_oss_file
*fmixer
,
759 struct snd_mixer_oss_slot
*pslot
,
762 struct slot
*slot
= (struct slot
*)pslot
->private_data
;
764 snd_mixer_oss_put_volume1_sw(fmixer
, pslot
, slot
->numid
[SNDRV_MIXER_OSS_ITEM_CROUTE
], active
, active
, 1);
768 static int snd_mixer_oss_get_recsrc2(struct snd_mixer_oss_file
*fmixer
, unsigned int *active_index
)
770 struct snd_card
*card
= fmixer
->card
;
771 struct snd_mixer_oss
*mixer
= fmixer
->mixer
;
772 struct snd_kcontrol
*kctl
;
773 struct snd_mixer_oss_slot
*pslot
;
775 struct snd_ctl_elem_info
*uinfo
;
776 struct snd_ctl_elem_value
*uctl
;
779 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
780 uctl
= kzalloc(sizeof(*uctl
), GFP_KERNEL
);
781 if (uinfo
== NULL
|| uctl
== NULL
) {
785 down_read(&card
->controls_rwsem
);
786 kctl
= snd_mixer_oss_test_id(mixer
, "Capture Source", 0);
791 if ((err
= kctl
->info(kctl
, uinfo
)) < 0)
793 if ((err
= kctl
->get(kctl
, uctl
)) < 0)
795 for (idx
= 0; idx
< 32; idx
++) {
796 if (!(mixer
->mask_recsrc
& (1 << idx
)))
798 pslot
= &mixer
->slots
[idx
];
799 slot
= (struct slot
*)pslot
->private_data
;
800 if (slot
->signature
!= SNDRV_MIXER_OSS_SIGNATURE
)
802 if (!(slot
->present
& SNDRV_MIXER_OSS_PRESENT_CAPTURE
))
804 if (slot
->capture_item
== uctl
->value
.enumerated
.item
[0]) {
811 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
);
873 struct snd_mixer_oss_assign_table
{
879 static int snd_mixer_oss_build_test(struct snd_mixer_oss
*mixer
, struct slot
*slot
, const char *name
, int index
, int item
)
881 struct snd_ctl_elem_info
*info
;
882 struct snd_kcontrol
*kcontrol
;
883 struct snd_card
*card
= mixer
->card
;
886 down_read(&card
->controls_rwsem
);
887 kcontrol
= snd_mixer_oss_test_id(mixer
, name
, index
);
888 if (kcontrol
== NULL
) {
889 up_read(&card
->controls_rwsem
);
892 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
894 up_read(&card
->controls_rwsem
);
897 if ((err
= kcontrol
->info(kcontrol
, info
)) < 0) {
898 up_read(&card
->controls_rwsem
);
902 slot
->numid
[item
] = kcontrol
->id
.numid
;
903 up_read(&card
->controls_rwsem
);
904 if (info
->count
> slot
->channels
)
905 slot
->channels
= info
->count
;
906 slot
->present
|= 1 << item
;
911 static void snd_mixer_oss_slot_free(struct snd_mixer_oss_slot
*chn
)
913 struct slot
*p
= (struct slot
*)chn
->private_data
;
915 if (p
->allocated
&& p
->assigned
) {
916 kfree(p
->assigned
->name
);
923 static void mixer_slot_clear(struct snd_mixer_oss_slot
*rslot
)
925 int idx
= rslot
->number
; /* remember this */
926 if (rslot
->private_free
)
927 rslot
->private_free(rslot
);
928 memset(rslot
, 0, sizeof(*rslot
));
933 * build an OSS mixer element.
934 * ptr_allocated means the entry is dynamically allocated (change via proc file).
935 * when replace_old = 1, the old entry is replaced with the new one.
937 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
)
941 struct snd_kcontrol
*kctl
;
942 struct snd_mixer_oss_slot
*rslot
;
945 /* check if already assigned */
946 if (mixer
->slots
[ptr
->oss_id
].get_volume
&& ! replace_old
)
949 memset(&slot
, 0, sizeof(slot
));
950 memset(slot
.numid
, 0xff, sizeof(slot
.numid
)); /* ID_UNKNOWN */
951 if (snd_mixer_oss_build_test(mixer
, &slot
, ptr
->name
, ptr
->index
,
952 SNDRV_MIXER_OSS_ITEM_GLOBAL
))
954 sprintf(str
, "%s Switch", ptr
->name
);
955 if (snd_mixer_oss_build_test(mixer
, &slot
, str
, ptr
->index
,
956 SNDRV_MIXER_OSS_ITEM_GSWITCH
))
958 sprintf(str
, "%s Route", ptr
->name
);
959 if (snd_mixer_oss_build_test(mixer
, &slot
, str
, ptr
->index
,
960 SNDRV_MIXER_OSS_ITEM_GROUTE
))
962 sprintf(str
, "%s Volume", ptr
->name
);
963 if (snd_mixer_oss_build_test(mixer
, &slot
, str
, ptr
->index
,
964 SNDRV_MIXER_OSS_ITEM_GVOLUME
))
966 sprintf(str
, "%s Playback Switch", ptr
->name
);
967 if (snd_mixer_oss_build_test(mixer
, &slot
, str
, ptr
->index
,
968 SNDRV_MIXER_OSS_ITEM_PSWITCH
))
970 sprintf(str
, "%s Playback Route", ptr
->name
);
971 if (snd_mixer_oss_build_test(mixer
, &slot
, str
, ptr
->index
,
972 SNDRV_MIXER_OSS_ITEM_PROUTE
))
974 sprintf(str
, "%s Playback Volume", ptr
->name
);
975 if (snd_mixer_oss_build_test(mixer
, &slot
, str
, ptr
->index
,
976 SNDRV_MIXER_OSS_ITEM_PVOLUME
))
978 sprintf(str
, "%s Capture Switch", ptr
->name
);
979 if (snd_mixer_oss_build_test(mixer
, &slot
, str
, ptr
->index
,
980 SNDRV_MIXER_OSS_ITEM_CSWITCH
))
982 sprintf(str
, "%s Capture Route", ptr
->name
);
983 if (snd_mixer_oss_build_test(mixer
, &slot
, str
, ptr
->index
,
984 SNDRV_MIXER_OSS_ITEM_CROUTE
))
986 sprintf(str
, "%s Capture Volume", ptr
->name
);
987 if (snd_mixer_oss_build_test(mixer
, &slot
, str
, ptr
->index
,
988 SNDRV_MIXER_OSS_ITEM_CVOLUME
))
990 down_read(&mixer
->card
->controls_rwsem
);
991 if (ptr
->index
== 0 && (kctl
= snd_mixer_oss_test_id(mixer
, "Capture Source", 0)) != NULL
) {
992 struct snd_ctl_elem_info
*uinfo
;
994 uinfo
= kzalloc(sizeof(*uinfo
), GFP_KERNEL
);
996 up_read(&mixer
->card
->controls_rwsem
);
1000 if (kctl
->info(kctl
, uinfo
)) {
1001 up_read(&mixer
->card
->controls_rwsem
);
1004 strcpy(str
, ptr
->name
);
1005 if (!strcmp(str
, "Master"))
1007 if (!strcmp(str
, "Master Mono"))
1008 strcpy(str
, "Mix Mono");
1009 slot
.capture_item
= 0;
1010 if (!strcmp(uinfo
->value
.enumerated
.name
, str
)) {
1011 slot
.present
|= SNDRV_MIXER_OSS_PRESENT_CAPTURE
;
1013 for (slot
.capture_item
= 1; slot
.capture_item
< uinfo
->value
.enumerated
.items
; slot
.capture_item
++) {
1014 uinfo
->value
.enumerated
.item
= slot
.capture_item
;
1015 if (kctl
->info(kctl
, uinfo
)) {
1016 up_read(&mixer
->card
->controls_rwsem
);
1019 if (!strcmp(uinfo
->value
.enumerated
.name
, str
)) {
1020 slot
.present
|= SNDRV_MIXER_OSS_PRESENT_CAPTURE
;
1027 up_read(&mixer
->card
->controls_rwsem
);
1028 if (slot
.present
!= 0) {
1029 pslot
= kmalloc(sizeof(slot
), GFP_KERNEL
);
1033 pslot
->signature
= SNDRV_MIXER_OSS_SIGNATURE
;
1034 pslot
->assigned
= ptr
;
1035 pslot
->allocated
= ptr_allocated
;
1036 rslot
= &mixer
->slots
[ptr
->oss_id
];
1037 mixer_slot_clear(rslot
);
1038 rslot
->stereo
= slot
.channels
> 1 ? 1 : 0;
1039 rslot
->get_volume
= snd_mixer_oss_get_volume1
;
1040 rslot
->put_volume
= snd_mixer_oss_put_volume1
;
1041 /* note: ES18xx have both Capture Source and XX Capture Volume !!! */
1042 if (slot
.present
& SNDRV_MIXER_OSS_PRESENT_CSWITCH
) {
1043 rslot
->get_recsrc
= snd_mixer_oss_get_recsrc1_sw
;
1044 rslot
->put_recsrc
= snd_mixer_oss_put_recsrc1_sw
;
1045 } else if (slot
.present
& SNDRV_MIXER_OSS_PRESENT_CROUTE
) {
1046 rslot
->get_recsrc
= snd_mixer_oss_get_recsrc1_route
;
1047 rslot
->put_recsrc
= snd_mixer_oss_put_recsrc1_route
;
1048 } else if (slot
.present
& SNDRV_MIXER_OSS_PRESENT_CAPTURE
) {
1049 mixer
->mask_recsrc
|= 1 << ptr
->oss_id
;
1051 rslot
->private_data
= pslot
;
1052 rslot
->private_free
= snd_mixer_oss_slot_free
;
1058 #ifdef CONFIG_PROC_FS
1061 #define MIXER_VOL(name) [SOUND_MIXER_##name] = #name
1062 static char *oss_mixer_names
[SNDRV_OSS_MAX_MIXERS
] = {
1080 MIXER_VOL(DIGITAL1
),
1081 MIXER_VOL(DIGITAL2
),
1082 MIXER_VOL(DIGITAL3
),
1084 MIXER_VOL(PHONEOUT
),
1094 static void snd_mixer_oss_proc_read(struct snd_info_entry
*entry
,
1095 struct snd_info_buffer
*buffer
)
1097 struct snd_mixer_oss
*mixer
= entry
->private_data
;
1100 mutex_lock(&mixer
->reg_mutex
);
1101 for (i
= 0; i
< SNDRV_OSS_MAX_MIXERS
; i
++) {
1104 if (! oss_mixer_names
[i
])
1106 p
= (struct slot
*)mixer
->slots
[i
].private_data
;
1107 snd_iprintf(buffer
, "%s ", oss_mixer_names
[i
]);
1108 if (p
&& p
->assigned
)
1109 snd_iprintf(buffer
, "\"%s\" %d\n",
1111 p
->assigned
->index
);
1113 snd_iprintf(buffer
, "\"\" 0\n");
1115 mutex_unlock(&mixer
->reg_mutex
);
1118 static void snd_mixer_oss_proc_write(struct snd_info_entry
*entry
,
1119 struct snd_info_buffer
*buffer
)
1121 struct snd_mixer_oss
*mixer
= entry
->private_data
;
1122 char line
[128], str
[32], idxstr
[16], *cptr
;
1124 struct snd_mixer_oss_assign_table
*tbl
;
1127 while (!snd_info_get_line(buffer
, line
, sizeof(line
))) {
1128 cptr
= snd_info_get_str(str
, line
, sizeof(str
));
1129 for (ch
= 0; ch
< SNDRV_OSS_MAX_MIXERS
; ch
++)
1130 if (oss_mixer_names
[ch
] && strcmp(oss_mixer_names
[ch
], str
) == 0)
1132 if (ch
>= SNDRV_OSS_MAX_MIXERS
) {
1133 snd_printk(KERN_ERR
"mixer_oss: invalid OSS volume '%s'\n", str
);
1136 cptr
= snd_info_get_str(str
, cptr
, sizeof(str
));
1138 /* remove the entry */
1139 mutex_lock(&mixer
->reg_mutex
);
1140 mixer_slot_clear(&mixer
->slots
[ch
]);
1141 mutex_unlock(&mixer
->reg_mutex
);
1144 snd_info_get_str(idxstr
, cptr
, sizeof(idxstr
));
1145 idx
= simple_strtoul(idxstr
, NULL
, 10);
1146 if (idx
>= 0x4000) { /* too big */
1147 snd_printk(KERN_ERR
"mixer_oss: invalid index %d\n", idx
);
1150 mutex_lock(&mixer
->reg_mutex
);
1151 slot
= (struct slot
*)mixer
->slots
[ch
].private_data
;
1152 if (slot
&& slot
->assigned
&&
1153 slot
->assigned
->index
== idx
&& ! strcmp(slot
->assigned
->name
, str
))
1156 tbl
= kmalloc(sizeof(*tbl
), GFP_KERNEL
);
1158 snd_printk(KERN_ERR
"mixer_oss: no memory\n");
1162 tbl
->name
= kstrdup(str
, GFP_KERNEL
);
1168 if (snd_mixer_oss_build_input(mixer
, tbl
, 1, 1) <= 0) {
1173 mutex_unlock(&mixer
->reg_mutex
);
1177 static void snd_mixer_oss_proc_init(struct snd_mixer_oss
*mixer
)
1179 struct snd_info_entry
*entry
;
1181 entry
= snd_info_create_card_entry(mixer
->card
, "oss_mixer",
1182 mixer
->card
->proc_root
);
1185 entry
->content
= SNDRV_INFO_CONTENT_TEXT
;
1186 entry
->mode
= S_IFREG
| S_IRUGO
| S_IWUSR
;
1187 entry
->c
.text
.read
= snd_mixer_oss_proc_read
;
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 snd_info_free_entry(mixer
->proc_entry
);
1200 mixer
->proc_entry
= NULL
;
1202 #else /* !CONFIG_PROC_FS */
1203 #define snd_mixer_oss_proc_init(mix)
1204 #define snd_mixer_oss_proc_done(mix)
1205 #endif /* CONFIG_PROC_FS */
1207 static void snd_mixer_oss_build(struct snd_mixer_oss
*mixer
)
1209 static struct snd_mixer_oss_assign_table table
[] = {
1210 { SOUND_MIXER_VOLUME
, "Master", 0 },
1211 { SOUND_MIXER_VOLUME
, "Front", 0 }, /* fallback */
1212 { SOUND_MIXER_BASS
, "Tone Control - Bass", 0 },
1213 { SOUND_MIXER_TREBLE
, "Tone Control - Treble", 0 },
1214 { SOUND_MIXER_SYNTH
, "Synth", 0 },
1215 { SOUND_MIXER_SYNTH
, "FM", 0 }, /* fallback */
1216 { SOUND_MIXER_SYNTH
, "Music", 0 }, /* fallback */
1217 { SOUND_MIXER_PCM
, "PCM", 0 },
1218 { SOUND_MIXER_SPEAKER
, "PC Speaker", 0 },
1219 { SOUND_MIXER_LINE
, "Line", 0 },
1220 { SOUND_MIXER_MIC
, "Mic", 0 },
1221 { SOUND_MIXER_CD
, "CD", 0 },
1222 { SOUND_MIXER_IMIX
, "Monitor Mix", 0 },
1223 { SOUND_MIXER_ALTPCM
, "PCM", 1 },
1224 { SOUND_MIXER_ALTPCM
, "Headphone", 0 }, /* fallback */
1225 { SOUND_MIXER_ALTPCM
, "Wave", 0 }, /* fallback */
1226 { SOUND_MIXER_RECLEV
, "-- nothing --", 0 },
1227 { SOUND_MIXER_IGAIN
, "Capture", 0 },
1228 { SOUND_MIXER_OGAIN
, "Playback", 0 },
1229 { SOUND_MIXER_LINE1
, "Aux", 0 },
1230 { SOUND_MIXER_LINE2
, "Aux", 1 },
1231 { SOUND_MIXER_LINE3
, "Aux", 2 },
1232 { SOUND_MIXER_DIGITAL1
, "Digital", 0 },
1233 { SOUND_MIXER_DIGITAL1
, "IEC958", 0 }, /* fallback */
1234 { SOUND_MIXER_DIGITAL1
, "IEC958 Optical", 0 }, /* fallback */
1235 { SOUND_MIXER_DIGITAL1
, "IEC958 Coaxial", 0 }, /* fallback */
1236 { SOUND_MIXER_DIGITAL2
, "Digital", 1 },
1237 { SOUND_MIXER_DIGITAL3
, "Digital", 2 },
1238 { SOUND_MIXER_PHONEIN
, "Phone", 0 },
1239 { SOUND_MIXER_PHONEOUT
, "Master Mono", 0 },
1240 { SOUND_MIXER_PHONEOUT
, "Speaker", 0 }, /*fallback*/
1241 { SOUND_MIXER_PHONEOUT
, "Mono", 0 }, /*fallback*/
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
);
1319 mixer
= card
->mixer_oss
;
1322 if (mixer
->oss_dev_alloc
) {
1323 #ifdef SNDRV_OSS_INFO_DEV_MIXERS
1324 snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_MIXERS
, mixer
->card
->number
);
1326 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER
, mixer
->card
, 0);
1327 mixer
->oss_dev_alloc
= 0;
1329 if (cmd
== SND_MIXER_OSS_NOTIFY_DISCONNECT
)
1331 snd_mixer_oss_proc_done(mixer
);
1332 return snd_mixer_oss_free1(mixer
);
1337 static int __init
alsa_mixer_oss_init(void)
1341 snd_mixer_oss_notify_callback
= snd_mixer_oss_notify_handler
;
1342 for (idx
= 0; idx
< SNDRV_CARDS
; idx
++) {
1344 snd_mixer_oss_notify_handler(snd_cards
[idx
], SND_MIXER_OSS_NOTIFY_REGISTER
);
1349 static void __exit
alsa_mixer_oss_exit(void)
1353 snd_mixer_oss_notify_callback
= NULL
;
1354 for (idx
= 0; idx
< SNDRV_CARDS
; idx
++) {
1356 snd_mixer_oss_notify_handler(snd_cards
[idx
], SND_MIXER_OSS_NOTIFY_FREE
);
1360 module_init(alsa_mixer_oss_init
)
1361 module_exit(alsa_mixer_oss_exit
)
1363 EXPORT_SYMBOL(snd_mixer_oss_ioctl_card
);