2 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
3 * Routines for Sound Blaster mixer control
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
23 #include <linux/delay.h>
24 #include <linux/time.h>
25 #include <sound/core.h>
27 #include <sound/control.h>
31 void snd_sbmixer_write(struct snd_sb
*chip
, unsigned char reg
, unsigned char data
)
33 outb(reg
, SBP(chip
, MIXER_ADDR
));
35 outb(data
, SBP(chip
, MIXER_DATA
));
38 snd_printk(KERN_DEBUG
"mixer_write 0x%x 0x%x\n", reg
, data
);
42 unsigned char snd_sbmixer_read(struct snd_sb
*chip
, unsigned char reg
)
46 outb(reg
, SBP(chip
, MIXER_ADDR
));
48 result
= inb(SBP(chip
, MIXER_DATA
));
51 snd_printk(KERN_DEBUG
"mixer_read 0x%x 0x%x\n", reg
, result
);
57 * Single channel mixer element
60 static int snd_sbmixer_info_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
62 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
64 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
66 uinfo
->value
.integer
.min
= 0;
67 uinfo
->value
.integer
.max
= mask
;
71 static int snd_sbmixer_get_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
73 struct snd_sb
*sb
= snd_kcontrol_chip(kcontrol
);
75 int reg
= kcontrol
->private_value
& 0xff;
76 int shift
= (kcontrol
->private_value
>> 16) & 0xff;
77 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
80 spin_lock_irqsave(&sb
->mixer_lock
, flags
);
81 val
= (snd_sbmixer_read(sb
, reg
) >> shift
) & mask
;
82 spin_unlock_irqrestore(&sb
->mixer_lock
, flags
);
83 ucontrol
->value
.integer
.value
[0] = val
;
87 static int snd_sbmixer_put_single(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
89 struct snd_sb
*sb
= snd_kcontrol_chip(kcontrol
);
91 int reg
= kcontrol
->private_value
& 0xff;
92 int shift
= (kcontrol
->private_value
>> 16) & 0x07;
93 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
95 unsigned char val
, oval
;
97 val
= (ucontrol
->value
.integer
.value
[0] & mask
) << shift
;
98 spin_lock_irqsave(&sb
->mixer_lock
, flags
);
99 oval
= snd_sbmixer_read(sb
, reg
);
100 val
= (oval
& ~(mask
<< shift
)) | val
;
101 change
= val
!= oval
;
103 snd_sbmixer_write(sb
, reg
, val
);
104 spin_unlock_irqrestore(&sb
->mixer_lock
, flags
);
109 * Double channel mixer element
112 static int snd_sbmixer_info_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
114 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
116 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
118 uinfo
->value
.integer
.min
= 0;
119 uinfo
->value
.integer
.max
= mask
;
123 static int snd_sbmixer_get_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
125 struct snd_sb
*sb
= snd_kcontrol_chip(kcontrol
);
127 int left_reg
= kcontrol
->private_value
& 0xff;
128 int right_reg
= (kcontrol
->private_value
>> 8) & 0xff;
129 int left_shift
= (kcontrol
->private_value
>> 16) & 0x07;
130 int right_shift
= (kcontrol
->private_value
>> 19) & 0x07;
131 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
132 unsigned char left
, right
;
134 spin_lock_irqsave(&sb
->mixer_lock
, flags
);
135 left
= (snd_sbmixer_read(sb
, left_reg
) >> left_shift
) & mask
;
136 right
= (snd_sbmixer_read(sb
, right_reg
) >> right_shift
) & mask
;
137 spin_unlock_irqrestore(&sb
->mixer_lock
, flags
);
138 ucontrol
->value
.integer
.value
[0] = left
;
139 ucontrol
->value
.integer
.value
[1] = right
;
143 static int snd_sbmixer_put_double(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
145 struct snd_sb
*sb
= snd_kcontrol_chip(kcontrol
);
147 int left_reg
= kcontrol
->private_value
& 0xff;
148 int right_reg
= (kcontrol
->private_value
>> 8) & 0xff;
149 int left_shift
= (kcontrol
->private_value
>> 16) & 0x07;
150 int right_shift
= (kcontrol
->private_value
>> 19) & 0x07;
151 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
153 unsigned char left
, right
, oleft
, oright
;
155 left
= (ucontrol
->value
.integer
.value
[0] & mask
) << left_shift
;
156 right
= (ucontrol
->value
.integer
.value
[1] & mask
) << right_shift
;
157 spin_lock_irqsave(&sb
->mixer_lock
, flags
);
158 if (left_reg
== right_reg
) {
159 oleft
= snd_sbmixer_read(sb
, left_reg
);
160 left
= (oleft
& ~((mask
<< left_shift
) | (mask
<< right_shift
))) | left
| right
;
161 change
= left
!= oleft
;
163 snd_sbmixer_write(sb
, left_reg
, left
);
165 oleft
= snd_sbmixer_read(sb
, left_reg
);
166 oright
= snd_sbmixer_read(sb
, right_reg
);
167 left
= (oleft
& ~(mask
<< left_shift
)) | left
;
168 right
= (oright
& ~(mask
<< right_shift
)) | right
;
169 change
= left
!= oleft
|| right
!= oright
;
171 snd_sbmixer_write(sb
, left_reg
, left
);
172 snd_sbmixer_write(sb
, right_reg
, right
);
175 spin_unlock_irqrestore(&sb
->mixer_lock
, flags
);
180 * DT-019x / ALS-007 capture/input switch
183 static int snd_dt019x_input_sw_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
185 static const char *texts
[5] = {
186 "CD", "Mic", "Line", "Synth", "Master"
189 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
191 uinfo
->value
.enumerated
.items
= 5;
192 if (uinfo
->value
.enumerated
.item
> 4)
193 uinfo
->value
.enumerated
.item
= 4;
194 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
198 static int snd_dt019x_input_sw_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
200 struct snd_sb
*sb
= snd_kcontrol_chip(kcontrol
);
204 spin_lock_irqsave(&sb
->mixer_lock
, flags
);
205 oval
= snd_sbmixer_read(sb
, SB_DT019X_CAPTURE_SW
);
206 spin_unlock_irqrestore(&sb
->mixer_lock
, flags
);
207 switch (oval
& 0x07) {
208 case SB_DT019X_CAP_CD
:
209 ucontrol
->value
.enumerated
.item
[0] = 0;
211 case SB_DT019X_CAP_MIC
:
212 ucontrol
->value
.enumerated
.item
[0] = 1;
214 case SB_DT019X_CAP_LINE
:
215 ucontrol
->value
.enumerated
.item
[0] = 2;
217 case SB_DT019X_CAP_MAIN
:
218 ucontrol
->value
.enumerated
.item
[0] = 4;
220 /* To record the synth on these cards you must record the main. */
221 /* Thus SB_DT019X_CAP_SYNTH == SB_DT019X_CAP_MAIN and would cause */
222 /* duplicate case labels if left uncommented. */
223 /* case SB_DT019X_CAP_SYNTH:
224 * ucontrol->value.enumerated.item[0] = 3;
228 ucontrol
->value
.enumerated
.item
[0] = 4;
234 static int snd_dt019x_input_sw_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
236 struct snd_sb
*sb
= snd_kcontrol_chip(kcontrol
);
239 unsigned char nval
, oval
;
241 if (ucontrol
->value
.enumerated
.item
[0] > 4)
243 switch (ucontrol
->value
.enumerated
.item
[0]) {
245 nval
= SB_DT019X_CAP_CD
;
248 nval
= SB_DT019X_CAP_MIC
;
251 nval
= SB_DT019X_CAP_LINE
;
254 nval
= SB_DT019X_CAP_SYNTH
;
257 nval
= SB_DT019X_CAP_MAIN
;
260 nval
= SB_DT019X_CAP_MAIN
;
262 spin_lock_irqsave(&sb
->mixer_lock
, flags
);
263 oval
= snd_sbmixer_read(sb
, SB_DT019X_CAPTURE_SW
);
264 change
= nval
!= oval
;
266 snd_sbmixer_write(sb
, SB_DT019X_CAPTURE_SW
, nval
);
267 spin_unlock_irqrestore(&sb
->mixer_lock
, flags
);
272 * ALS4000 mono recording control switch
275 static int snd_als4k_mono_capture_route_info(struct snd_kcontrol
*kcontrol
,
276 struct snd_ctl_elem_info
*uinfo
)
278 static const char *texts
[3] = {
279 "L chan only", "R chan only", "L ch/2 + R ch/2"
282 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
284 uinfo
->value
.enumerated
.items
= 3;
285 if (uinfo
->value
.enumerated
.item
> 2)
286 uinfo
->value
.enumerated
.item
= 2;
287 strcpy(uinfo
->value
.enumerated
.name
,
288 texts
[uinfo
->value
.enumerated
.item
]);
292 static int snd_als4k_mono_capture_route_get(struct snd_kcontrol
*kcontrol
,
293 struct snd_ctl_elem_value
*ucontrol
)
295 struct snd_sb
*sb
= snd_kcontrol_chip(kcontrol
);
299 spin_lock_irqsave(&sb
->mixer_lock
, flags
);
300 oval
= snd_sbmixer_read(sb
, SB_ALS4000_MONO_IO_CTRL
);
301 spin_unlock_irqrestore(&sb
->mixer_lock
, flags
);
306 ucontrol
->value
.enumerated
.item
[0] = oval
;
310 static int snd_als4k_mono_capture_route_put(struct snd_kcontrol
*kcontrol
,
311 struct snd_ctl_elem_value
*ucontrol
)
313 struct snd_sb
*sb
= snd_kcontrol_chip(kcontrol
);
316 unsigned char nval
, oval
;
318 if (ucontrol
->value
.enumerated
.item
[0] > 2)
320 spin_lock_irqsave(&sb
->mixer_lock
, flags
);
321 oval
= snd_sbmixer_read(sb
, SB_ALS4000_MONO_IO_CTRL
);
323 nval
= (oval
& ~(3 << 6))
324 | (ucontrol
->value
.enumerated
.item
[0] << 6);
325 change
= nval
!= oval
;
327 snd_sbmixer_write(sb
, SB_ALS4000_MONO_IO_CTRL
, nval
);
328 spin_unlock_irqrestore(&sb
->mixer_lock
, flags
);
333 * SBPRO input multiplexer
336 static int snd_sb8mixer_info_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
338 static const char *texts
[3] = {
342 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
344 uinfo
->value
.enumerated
.items
= 3;
345 if (uinfo
->value
.enumerated
.item
> 2)
346 uinfo
->value
.enumerated
.item
= 2;
347 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
352 static int snd_sb8mixer_get_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
354 struct snd_sb
*sb
= snd_kcontrol_chip(kcontrol
);
358 spin_lock_irqsave(&sb
->mixer_lock
, flags
);
359 oval
= snd_sbmixer_read(sb
, SB_DSP_CAPTURE_SOURCE
);
360 spin_unlock_irqrestore(&sb
->mixer_lock
, flags
);
361 switch ((oval
>> 0x01) & 0x03) {
363 ucontrol
->value
.enumerated
.item
[0] = 1;
365 case SB_DSP_MIXS_LINE
:
366 ucontrol
->value
.enumerated
.item
[0] = 2;
369 ucontrol
->value
.enumerated
.item
[0] = 0;
375 static int snd_sb8mixer_put_mux(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
377 struct snd_sb
*sb
= snd_kcontrol_chip(kcontrol
);
380 unsigned char nval
, oval
;
382 if (ucontrol
->value
.enumerated
.item
[0] > 2)
384 switch (ucontrol
->value
.enumerated
.item
[0]) {
386 nval
= SB_DSP_MIXS_CD
;
389 nval
= SB_DSP_MIXS_LINE
;
392 nval
= SB_DSP_MIXS_MIC
;
395 spin_lock_irqsave(&sb
->mixer_lock
, flags
);
396 oval
= snd_sbmixer_read(sb
, SB_DSP_CAPTURE_SOURCE
);
397 nval
|= oval
& ~0x06;
398 change
= nval
!= oval
;
400 snd_sbmixer_write(sb
, SB_DSP_CAPTURE_SOURCE
, nval
);
401 spin_unlock_irqrestore(&sb
->mixer_lock
, flags
);
409 static int snd_sb16mixer_info_input_sw(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
411 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
413 uinfo
->value
.integer
.min
= 0;
414 uinfo
->value
.integer
.max
= 1;
418 static int snd_sb16mixer_get_input_sw(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
420 struct snd_sb
*sb
= snd_kcontrol_chip(kcontrol
);
422 int reg1
= kcontrol
->private_value
& 0xff;
423 int reg2
= (kcontrol
->private_value
>> 8) & 0xff;
424 int left_shift
= (kcontrol
->private_value
>> 16) & 0x0f;
425 int right_shift
= (kcontrol
->private_value
>> 24) & 0x0f;
426 unsigned char val1
, val2
;
428 spin_lock_irqsave(&sb
->mixer_lock
, flags
);
429 val1
= snd_sbmixer_read(sb
, reg1
);
430 val2
= snd_sbmixer_read(sb
, reg2
);
431 spin_unlock_irqrestore(&sb
->mixer_lock
, flags
);
432 ucontrol
->value
.integer
.value
[0] = (val1
>> left_shift
) & 0x01;
433 ucontrol
->value
.integer
.value
[1] = (val2
>> left_shift
) & 0x01;
434 ucontrol
->value
.integer
.value
[2] = (val1
>> right_shift
) & 0x01;
435 ucontrol
->value
.integer
.value
[3] = (val2
>> right_shift
) & 0x01;
439 static int snd_sb16mixer_put_input_sw(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
441 struct snd_sb
*sb
= snd_kcontrol_chip(kcontrol
);
443 int reg1
= kcontrol
->private_value
& 0xff;
444 int reg2
= (kcontrol
->private_value
>> 8) & 0xff;
445 int left_shift
= (kcontrol
->private_value
>> 16) & 0x0f;
446 int right_shift
= (kcontrol
->private_value
>> 24) & 0x0f;
448 unsigned char val1
, val2
, oval1
, oval2
;
450 spin_lock_irqsave(&sb
->mixer_lock
, flags
);
451 oval1
= snd_sbmixer_read(sb
, reg1
);
452 oval2
= snd_sbmixer_read(sb
, reg2
);
453 val1
= oval1
& ~((1 << left_shift
) | (1 << right_shift
));
454 val2
= oval2
& ~((1 << left_shift
) | (1 << right_shift
));
455 val1
|= (ucontrol
->value
.integer
.value
[0] & 1) << left_shift
;
456 val2
|= (ucontrol
->value
.integer
.value
[1] & 1) << left_shift
;
457 val1
|= (ucontrol
->value
.integer
.value
[2] & 1) << right_shift
;
458 val2
|= (ucontrol
->value
.integer
.value
[3] & 1) << right_shift
;
459 change
= val1
!= oval1
|| val2
!= oval2
;
461 snd_sbmixer_write(sb
, reg1
, val1
);
462 snd_sbmixer_write(sb
, reg2
, val2
);
464 spin_unlock_irqrestore(&sb
->mixer_lock
, flags
);
473 int snd_sbmixer_add_ctl(struct snd_sb
*chip
, const char *name
, int index
, int type
, unsigned long value
)
475 static struct snd_kcontrol_new newctls
[] = {
477 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
478 .info
= snd_sbmixer_info_single
,
479 .get
= snd_sbmixer_get_single
,
480 .put
= snd_sbmixer_put_single
,
483 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
484 .info
= snd_sbmixer_info_double
,
485 .get
= snd_sbmixer_get_double
,
486 .put
= snd_sbmixer_put_double
,
488 [SB_MIX_INPUT_SW
] = {
489 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
490 .info
= snd_sb16mixer_info_input_sw
,
491 .get
= snd_sb16mixer_get_input_sw
,
492 .put
= snd_sb16mixer_put_input_sw
,
494 [SB_MIX_CAPTURE_PRO
] = {
495 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
496 .info
= snd_sb8mixer_info_mux
,
497 .get
= snd_sb8mixer_get_mux
,
498 .put
= snd_sb8mixer_put_mux
,
500 [SB_MIX_CAPTURE_DT019X
] = {
501 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
502 .info
= snd_dt019x_input_sw_info
,
503 .get
= snd_dt019x_input_sw_get
,
504 .put
= snd_dt019x_input_sw_put
,
506 [SB_MIX_MONO_CAPTURE_ALS4K
] = {
507 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
508 .info
= snd_als4k_mono_capture_route_info
,
509 .get
= snd_als4k_mono_capture_route_get
,
510 .put
= snd_als4k_mono_capture_route_put
,
513 struct snd_kcontrol
*ctl
;
516 ctl
= snd_ctl_new1(&newctls
[type
], chip
);
519 strlcpy(ctl
->id
.name
, name
, sizeof(ctl
->id
.name
));
520 ctl
->id
.index
= index
;
521 ctl
->private_value
= value
;
522 if ((err
= snd_ctl_add(chip
->card
, ctl
)) < 0)
528 * SB 2.0 specific mixer elements
531 static struct sbmix_elem snd_sb20_controls
[] = {
532 SB_SINGLE("Master Playback Volume", SB_DSP20_MASTER_DEV
, 1, 7),
533 SB_SINGLE("PCM Playback Volume", SB_DSP20_PCM_DEV
, 1, 3),
534 SB_SINGLE("Synth Playback Volume", SB_DSP20_FM_DEV
, 1, 7),
535 SB_SINGLE("CD Playback Volume", SB_DSP20_CD_DEV
, 1, 7)
538 static unsigned char snd_sb20_init_values
[][2] = {
539 { SB_DSP20_MASTER_DEV
, 0 },
540 { SB_DSP20_FM_DEV
, 0 },
544 * SB Pro specific mixer elements
546 static struct sbmix_elem snd_sbpro_controls
[] = {
547 SB_DOUBLE("Master Playback Volume",
548 SB_DSP_MASTER_DEV
, SB_DSP_MASTER_DEV
, 5, 1, 7),
549 SB_DOUBLE("PCM Playback Volume",
550 SB_DSP_PCM_DEV
, SB_DSP_PCM_DEV
, 5, 1, 7),
551 SB_SINGLE("PCM Playback Filter", SB_DSP_PLAYBACK_FILT
, 5, 1),
552 SB_DOUBLE("Synth Playback Volume",
553 SB_DSP_FM_DEV
, SB_DSP_FM_DEV
, 5, 1, 7),
554 SB_DOUBLE("CD Playback Volume", SB_DSP_CD_DEV
, SB_DSP_CD_DEV
, 5, 1, 7),
555 SB_DOUBLE("Line Playback Volume",
556 SB_DSP_LINE_DEV
, SB_DSP_LINE_DEV
, 5, 1, 7),
557 SB_SINGLE("Mic Playback Volume", SB_DSP_MIC_DEV
, 1, 3),
559 .name
= "Capture Source",
560 .type
= SB_MIX_CAPTURE_PRO
562 SB_SINGLE("Capture Filter", SB_DSP_CAPTURE_FILT
, 5, 1),
563 SB_SINGLE("Capture Low-Pass Filter", SB_DSP_CAPTURE_FILT
, 3, 1)
566 static unsigned char snd_sbpro_init_values
[][2] = {
567 { SB_DSP_MASTER_DEV
, 0 },
568 { SB_DSP_PCM_DEV
, 0 },
569 { SB_DSP_FM_DEV
, 0 },
573 * SB16 specific mixer elements
575 static struct sbmix_elem snd_sb16_controls
[] = {
576 SB_DOUBLE("Master Playback Volume",
577 SB_DSP4_MASTER_DEV
, (SB_DSP4_MASTER_DEV
+ 1), 3, 3, 31),
578 SB_DOUBLE("PCM Playback Volume",
579 SB_DSP4_PCM_DEV
, (SB_DSP4_PCM_DEV
+ 1), 3, 3, 31),
580 SB16_INPUT_SW("Synth Capture Route",
581 SB_DSP4_INPUT_LEFT
, SB_DSP4_INPUT_RIGHT
, 6, 5),
582 SB_DOUBLE("Synth Playback Volume",
583 SB_DSP4_SYNTH_DEV
, (SB_DSP4_SYNTH_DEV
+ 1), 3, 3, 31),
584 SB16_INPUT_SW("CD Capture Route",
585 SB_DSP4_INPUT_LEFT
, SB_DSP4_INPUT_RIGHT
, 2, 1),
586 SB_DOUBLE("CD Playback Switch",
587 SB_DSP4_OUTPUT_SW
, SB_DSP4_OUTPUT_SW
, 2, 1, 1),
588 SB_DOUBLE("CD Playback Volume",
589 SB_DSP4_CD_DEV
, (SB_DSP4_CD_DEV
+ 1), 3, 3, 31),
590 SB16_INPUT_SW("Mic Capture Route",
591 SB_DSP4_INPUT_LEFT
, SB_DSP4_INPUT_RIGHT
, 0, 0),
592 SB_SINGLE("Mic Playback Switch", SB_DSP4_OUTPUT_SW
, 0, 1),
593 SB_SINGLE("Mic Playback Volume", SB_DSP4_MIC_DEV
, 3, 31),
594 SB_SINGLE("Beep Volume", SB_DSP4_SPEAKER_DEV
, 6, 3),
595 SB_DOUBLE("Capture Volume",
596 SB_DSP4_IGAIN_DEV
, (SB_DSP4_IGAIN_DEV
+ 1), 6, 6, 3),
597 SB_DOUBLE("Playback Volume",
598 SB_DSP4_OGAIN_DEV
, (SB_DSP4_OGAIN_DEV
+ 1), 6, 6, 3),
599 SB16_INPUT_SW("Line Capture Route",
600 SB_DSP4_INPUT_LEFT
, SB_DSP4_INPUT_RIGHT
, 4, 3),
601 SB_DOUBLE("Line Playback Switch",
602 SB_DSP4_OUTPUT_SW
, SB_DSP4_OUTPUT_SW
, 4, 3, 1),
603 SB_DOUBLE("Line Playback Volume",
604 SB_DSP4_LINE_DEV
, (SB_DSP4_LINE_DEV
+ 1), 3, 3, 31),
605 SB_SINGLE("Mic Auto Gain", SB_DSP4_MIC_AGC
, 0, 1),
606 SB_SINGLE("3D Enhancement Switch", SB_DSP4_3DSE
, 0, 1),
607 SB_DOUBLE("Tone Control - Bass",
608 SB_DSP4_BASS_DEV
, (SB_DSP4_BASS_DEV
+ 1), 4, 4, 15),
609 SB_DOUBLE("Tone Control - Treble",
610 SB_DSP4_TREBLE_DEV
, (SB_DSP4_TREBLE_DEV
+ 1), 4, 4, 15)
613 static unsigned char snd_sb16_init_values
[][2] = {
614 { SB_DSP4_MASTER_DEV
+ 0, 0 },
615 { SB_DSP4_MASTER_DEV
+ 1, 0 },
616 { SB_DSP4_PCM_DEV
+ 0, 0 },
617 { SB_DSP4_PCM_DEV
+ 1, 0 },
618 { SB_DSP4_SYNTH_DEV
+ 0, 0 },
619 { SB_DSP4_SYNTH_DEV
+ 1, 0 },
620 { SB_DSP4_INPUT_LEFT
, 0 },
621 { SB_DSP4_INPUT_RIGHT
, 0 },
622 { SB_DSP4_OUTPUT_SW
, 0 },
623 { SB_DSP4_SPEAKER_DEV
, 0 },
627 * DT019x specific mixer elements
629 static struct sbmix_elem snd_dt019x_controls
[] = {
630 /* ALS4000 below has some parts which we might be lacking,
631 * e.g. snd_als4000_ctl_mono_playback_switch - check it! */
632 SB_DOUBLE("Master Playback Volume",
633 SB_DT019X_MASTER_DEV
, SB_DT019X_MASTER_DEV
, 4, 0, 15),
634 SB_DOUBLE("PCM Playback Switch",
635 SB_DT019X_OUTPUT_SW2
, SB_DT019X_OUTPUT_SW2
, 2, 1, 1),
636 SB_DOUBLE("PCM Playback Volume",
637 SB_DT019X_PCM_DEV
, SB_DT019X_PCM_DEV
, 4, 0, 15),
638 SB_DOUBLE("Synth Playback Switch",
639 SB_DT019X_OUTPUT_SW2
, SB_DT019X_OUTPUT_SW2
, 4, 3, 1),
640 SB_DOUBLE("Synth Playback Volume",
641 SB_DT019X_SYNTH_DEV
, SB_DT019X_SYNTH_DEV
, 4, 0, 15),
642 SB_DOUBLE("CD Playback Switch",
643 SB_DSP4_OUTPUT_SW
, SB_DSP4_OUTPUT_SW
, 2, 1, 1),
644 SB_DOUBLE("CD Playback Volume",
645 SB_DT019X_CD_DEV
, SB_DT019X_CD_DEV
, 4, 0, 15),
646 SB_SINGLE("Mic Playback Switch", SB_DSP4_OUTPUT_SW
, 0, 1),
647 SB_SINGLE("Mic Playback Volume", SB_DT019X_MIC_DEV
, 4, 7),
648 SB_SINGLE("Beep Volume", SB_DT019X_SPKR_DEV
, 0, 7),
649 SB_DOUBLE("Line Playback Switch",
650 SB_DSP4_OUTPUT_SW
, SB_DSP4_OUTPUT_SW
, 4, 3, 1),
651 SB_DOUBLE("Line Playback Volume",
652 SB_DT019X_LINE_DEV
, SB_DT019X_LINE_DEV
, 4, 0, 15),
654 .name
= "Capture Source",
655 .type
= SB_MIX_CAPTURE_DT019X
659 static unsigned char snd_dt019x_init_values
[][2] = {
660 { SB_DT019X_MASTER_DEV
, 0 },
661 { SB_DT019X_PCM_DEV
, 0 },
662 { SB_DT019X_SYNTH_DEV
, 0 },
663 { SB_DT019X_CD_DEV
, 0 },
664 { SB_DT019X_MIC_DEV
, 0 }, /* Includes PC-speaker in high nibble */
665 { SB_DT019X_LINE_DEV
, 0 },
666 { SB_DSP4_OUTPUT_SW
, 0 },
667 { SB_DT019X_OUTPUT_SW2
, 0 },
668 { SB_DT019X_CAPTURE_SW
, 0x06 },
672 * ALS4000 specific mixer elements
674 static struct sbmix_elem snd_als4000_controls
[] = {
675 SB_DOUBLE("PCM Playback Switch",
676 SB_DT019X_OUTPUT_SW2
, SB_DT019X_OUTPUT_SW2
, 2, 1, 1),
677 SB_DOUBLE("Synth Playback Switch",
678 SB_DT019X_OUTPUT_SW2
, SB_DT019X_OUTPUT_SW2
, 4, 3, 1),
679 SB_SINGLE("Mic Boost (+20dB)", SB_ALS4000_MIC_IN_GAIN
, 0, 0x03),
680 SB_SINGLE("Master Mono Playback Switch", SB_ALS4000_MONO_IO_CTRL
, 5, 1),
682 .name
= "Master Mono Capture Route",
683 .type
= SB_MIX_MONO_CAPTURE_ALS4K
685 SB_SINGLE("Mono Playback Switch", SB_DT019X_OUTPUT_SW2
, 0, 1),
686 SB_SINGLE("Analog Loopback Switch", SB_ALS4000_MIC_IN_GAIN
, 7, 0x01),
687 SB_SINGLE("3D Control - Switch", SB_ALS4000_3D_SND_FX
, 6, 0x01),
688 SB_SINGLE("Digital Loopback Switch",
689 SB_ALS4000_CR3_CONFIGURATION
, 7, 0x01),
690 /* FIXME: functionality of 3D controls might be swapped, I didn't find
691 * a description of how to identify what is supposed to be what */
692 SB_SINGLE("3D Control - Level", SB_ALS4000_3D_SND_FX
, 0, 0x07),
693 /* FIXME: maybe there's actually some standard 3D ctrl name for it?? */
694 SB_SINGLE("3D Control - Freq", SB_ALS4000_3D_SND_FX
, 4, 0x03),
695 /* FIXME: ALS4000a.pdf mentions BBD (Bucket Brigade Device) time delay,
696 * but what ALSA 3D attribute is that actually? "Center", "Depth",
697 * "Wide" or "Space" or even "Level"? Assuming "Wide" for now... */
698 SB_SINGLE("3D Control - Wide", SB_ALS4000_3D_TIME_DELAY
, 0, 0x0f),
699 SB_SINGLE("3D PowerOff Switch", SB_ALS4000_3D_TIME_DELAY
, 4, 0x01),
700 SB_SINGLE("Master Playback 8kHz / 20kHz LPF Switch",
701 SB_ALS4000_FMDAC
, 5, 0x01),
703 SB_SINGLE("FMDAC Switch (Option ?)", SB_ALS4000_FMDAC
, 0, 0x01),
704 SB_SINGLE("QSound Mode", SB_ALS4000_QSOUND
, 1, 0x1f),
708 static unsigned char snd_als4000_init_values
[][2] = {
709 { SB_DSP4_MASTER_DEV
+ 0, 0 },
710 { SB_DSP4_MASTER_DEV
+ 1, 0 },
711 { SB_DSP4_PCM_DEV
+ 0, 0 },
712 { SB_DSP4_PCM_DEV
+ 1, 0 },
713 { SB_DSP4_SYNTH_DEV
+ 0, 0 },
714 { SB_DSP4_SYNTH_DEV
+ 1, 0 },
715 { SB_DSP4_SPEAKER_DEV
, 0 },
716 { SB_DSP4_OUTPUT_SW
, 0 },
717 { SB_DSP4_INPUT_LEFT
, 0 },
718 { SB_DSP4_INPUT_RIGHT
, 0 },
719 { SB_DT019X_OUTPUT_SW2
, 0 },
720 { SB_ALS4000_MIC_IN_GAIN
, 0 },
725 static int snd_sbmixer_init(struct snd_sb
*chip
,
726 struct sbmix_elem
*controls
,
728 unsigned char map
[][2],
733 struct snd_card
*card
= chip
->card
;
737 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
738 snd_sbmixer_write(chip
, 0x00, 0x00);
739 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
741 /* mute and zero volume channels */
742 for (idx
= 0; idx
< map_count
; idx
++) {
743 spin_lock_irqsave(&chip
->mixer_lock
, flags
);
744 snd_sbmixer_write(chip
, map
[idx
][0], map
[idx
][1]);
745 spin_unlock_irqrestore(&chip
->mixer_lock
, flags
);
748 for (idx
= 0; idx
< controls_count
; idx
++) {
749 err
= snd_sbmixer_add_ctl_elem(chip
, &controls
[idx
]);
753 snd_component_add(card
, name
);
754 strcpy(card
->mixername
, name
);
758 int snd_sbmixer_new(struct snd_sb
*chip
)
760 struct snd_card
*card
;
763 if (snd_BUG_ON(!chip
|| !chip
->card
))
768 switch (chip
->hardware
) {
770 return 0; /* no mixer chip on SB1.x */
773 if ((err
= snd_sbmixer_init(chip
,
775 ARRAY_SIZE(snd_sb20_controls
),
776 snd_sb20_init_values
,
777 ARRAY_SIZE(snd_sb20_init_values
),
783 if ((err
= snd_sbmixer_init(chip
,
785 ARRAY_SIZE(snd_sbpro_controls
),
786 snd_sbpro_init_values
,
787 ARRAY_SIZE(snd_sbpro_init_values
),
794 if ((err
= snd_sbmixer_init(chip
,
796 ARRAY_SIZE(snd_sb16_controls
),
797 snd_sb16_init_values
,
798 ARRAY_SIZE(snd_sb16_init_values
),
803 /* use only the first 16 controls from SB16 */
804 err
= snd_sbmixer_init(chip
,
807 snd_sb16_init_values
,
808 ARRAY_SIZE(snd_sb16_init_values
),
812 if ((err
= snd_sbmixer_init(chip
,
813 snd_als4000_controls
,
814 ARRAY_SIZE(snd_als4000_controls
),
815 snd_als4000_init_values
,
816 ARRAY_SIZE(snd_als4000_init_values
),
821 err
= snd_sbmixer_init(chip
,
823 ARRAY_SIZE(snd_dt019x_controls
),
824 snd_dt019x_init_values
,
825 ARRAY_SIZE(snd_dt019x_init_values
),
831 strcpy(card
->mixername
, "???");
837 static unsigned char sb20_saved_regs
[] = {
844 static unsigned char sbpro_saved_regs
[] = {
847 SB_DSP_PLAYBACK_FILT
,
852 SB_DSP_CAPTURE_SOURCE
,
856 static unsigned char sb16_saved_regs
[] = {
857 SB_DSP4_MASTER_DEV
, SB_DSP4_MASTER_DEV
+ 1,
859 SB_DSP4_BASS_DEV
, SB_DSP4_BASS_DEV
+ 1,
860 SB_DSP4_TREBLE_DEV
, SB_DSP4_TREBLE_DEV
+ 1,
861 SB_DSP4_PCM_DEV
, SB_DSP4_PCM_DEV
+ 1,
862 SB_DSP4_INPUT_LEFT
, SB_DSP4_INPUT_RIGHT
,
863 SB_DSP4_SYNTH_DEV
, SB_DSP4_SYNTH_DEV
+ 1,
865 SB_DSP4_CD_DEV
, SB_DSP4_CD_DEV
+ 1,
866 SB_DSP4_LINE_DEV
, SB_DSP4_LINE_DEV
+ 1,
869 SB_DSP4_IGAIN_DEV
, SB_DSP4_IGAIN_DEV
+ 1,
870 SB_DSP4_OGAIN_DEV
, SB_DSP4_OGAIN_DEV
+ 1,
874 static unsigned char dt019x_saved_regs
[] = {
875 SB_DT019X_MASTER_DEV
,
883 SB_DT019X_OUTPUT_SW2
,
884 SB_DT019X_CAPTURE_SW
,
887 static unsigned char als4000_saved_regs
[] = {
888 /* please verify in dsheet whether regs to be added
889 are actually real H/W or just dummy */
890 SB_DSP4_MASTER_DEV
, SB_DSP4_MASTER_DEV
+ 1,
892 SB_DSP4_PCM_DEV
, SB_DSP4_PCM_DEV
+ 1,
893 SB_DSP4_INPUT_LEFT
, SB_DSP4_INPUT_RIGHT
,
894 SB_DSP4_SYNTH_DEV
, SB_DSP4_SYNTH_DEV
+ 1,
895 SB_DSP4_CD_DEV
, SB_DSP4_CD_DEV
+ 1,
898 SB_DSP4_IGAIN_DEV
, SB_DSP4_IGAIN_DEV
+ 1,
899 SB_DSP4_OGAIN_DEV
, SB_DSP4_OGAIN_DEV
+ 1,
900 SB_DT019X_OUTPUT_SW2
,
901 SB_ALS4000_MONO_IO_CTRL
,
902 SB_ALS4000_MIC_IN_GAIN
,
904 SB_ALS4000_3D_SND_FX
,
905 SB_ALS4000_3D_TIME_DELAY
,
906 SB_ALS4000_CR3_CONFIGURATION
,
909 static void save_mixer(struct snd_sb
*chip
, unsigned char *regs
, int num_regs
)
911 unsigned char *val
= chip
->saved_regs
;
912 if (snd_BUG_ON(num_regs
> ARRAY_SIZE(chip
->saved_regs
)))
914 for (; num_regs
; num_regs
--)
915 *val
++ = snd_sbmixer_read(chip
, *regs
++);
918 static void restore_mixer(struct snd_sb
*chip
, unsigned char *regs
, int num_regs
)
920 unsigned char *val
= chip
->saved_regs
;
921 if (snd_BUG_ON(num_regs
> ARRAY_SIZE(chip
->saved_regs
)))
923 for (; num_regs
; num_regs
--)
924 snd_sbmixer_write(chip
, *regs
++, *val
++);
927 void snd_sbmixer_suspend(struct snd_sb
*chip
)
929 switch (chip
->hardware
) {
932 save_mixer(chip
, sb20_saved_regs
, ARRAY_SIZE(sb20_saved_regs
));
936 save_mixer(chip
, sbpro_saved_regs
, ARRAY_SIZE(sbpro_saved_regs
));
941 save_mixer(chip
, sb16_saved_regs
, ARRAY_SIZE(sb16_saved_regs
));
944 save_mixer(chip
, als4000_saved_regs
, ARRAY_SIZE(als4000_saved_regs
));
947 save_mixer(chip
, dt019x_saved_regs
, ARRAY_SIZE(dt019x_saved_regs
));
954 void snd_sbmixer_resume(struct snd_sb
*chip
)
956 switch (chip
->hardware
) {
959 restore_mixer(chip
, sb20_saved_regs
, ARRAY_SIZE(sb20_saved_regs
));
963 restore_mixer(chip
, sbpro_saved_regs
, ARRAY_SIZE(sbpro_saved_regs
));
968 restore_mixer(chip
, sb16_saved_regs
, ARRAY_SIZE(sb16_saved_regs
));
971 restore_mixer(chip
, als4000_saved_regs
, ARRAY_SIZE(als4000_saved_regs
));
974 restore_mixer(chip
, dt019x_saved_regs
, ARRAY_SIZE(dt019x_saved_regs
));