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_ctl_master_play_vol =
532 SB_SINGLE("Master Playback Volume", SB_DSP20_MASTER_DEV, 1, 7);
533 static struct sbmix_elem snd_sb20_ctl_pcm_play_vol =
534 SB_SINGLE("PCM Playback Volume", SB_DSP20_PCM_DEV, 1, 3);
535 static struct sbmix_elem snd_sb20_ctl_synth_play_vol =
536 SB_SINGLE("Synth Playback Volume", SB_DSP20_FM_DEV, 1, 7);
537 static struct sbmix_elem snd_sb20_ctl_cd_play_vol =
538 SB_SINGLE("CD Playback Volume", SB_DSP20_CD_DEV, 1, 7);
540 static struct sbmix_elem *snd_sb20_controls[] = {
541 &snd_sb20_ctl_master_play_vol,
542 &snd_sb20_ctl_pcm_play_vol,
543 &snd_sb20_ctl_synth_play_vol,
544 &snd_sb20_ctl_cd_play_vol
547 static unsigned char snd_sb20_init_values[][2] = {
548 { SB_DSP20_MASTER_DEV, 0 },
549 { SB_DSP20_FM_DEV, 0 },
553 * SB Pro specific mixer elements
555 static struct sbmix_elem snd_sbpro_ctl_master_play_vol =
556 SB_DOUBLE("Master Playback Volume", SB_DSP_MASTER_DEV, SB_DSP_MASTER_DEV, 5, 1, 7);
557 static struct sbmix_elem snd_sbpro_ctl_pcm_play_vol =
558 SB_DOUBLE("PCM Playback Volume", SB_DSP_PCM_DEV, SB_DSP_PCM_DEV, 5, 1, 7);
559 static struct sbmix_elem snd_sbpro_ctl_pcm_play_filter =
560 SB_SINGLE("PCM Playback Filter", SB_DSP_PLAYBACK_FILT, 5, 1);
561 static struct sbmix_elem snd_sbpro_ctl_synth_play_vol =
562 SB_DOUBLE("Synth Playback Volume", SB_DSP_FM_DEV, SB_DSP_FM_DEV, 5, 1, 7);
563 static struct sbmix_elem snd_sbpro_ctl_cd_play_vol =
564 SB_DOUBLE("CD Playback Volume", SB_DSP_CD_DEV, SB_DSP_CD_DEV, 5, 1, 7);
565 static struct sbmix_elem snd_sbpro_ctl_line_play_vol =
566 SB_DOUBLE("Line Playback Volume", SB_DSP_LINE_DEV, SB_DSP_LINE_DEV, 5, 1, 7);
567 static struct sbmix_elem snd_sbpro_ctl_mic_play_vol =
568 SB_SINGLE("Mic Playback Volume", SB_DSP_MIC_DEV, 1, 3);
569 static struct sbmix_elem snd_sbpro_ctl_capture_source =
571 .name = "Capture Source",
572 .type = SB_MIX_CAPTURE_PRO
574 static struct sbmix_elem snd_sbpro_ctl_capture_filter =
575 SB_SINGLE("Capture Filter", SB_DSP_CAPTURE_FILT, 5, 1);
576 static struct sbmix_elem snd_sbpro_ctl_capture_low_filter =
577 SB_SINGLE("Capture Low-Pass Filter", SB_DSP_CAPTURE_FILT, 3, 1);
579 static struct sbmix_elem *snd_sbpro_controls[] = {
580 &snd_sbpro_ctl_master_play_vol,
581 &snd_sbpro_ctl_pcm_play_vol,
582 &snd_sbpro_ctl_pcm_play_filter,
583 &snd_sbpro_ctl_synth_play_vol,
584 &snd_sbpro_ctl_cd_play_vol,
585 &snd_sbpro_ctl_line_play_vol,
586 &snd_sbpro_ctl_mic_play_vol,
587 &snd_sbpro_ctl_capture_source,
588 &snd_sbpro_ctl_capture_filter,
589 &snd_sbpro_ctl_capture_low_filter
592 static unsigned char snd_sbpro_init_values[][2] = {
593 { SB_DSP_MASTER_DEV, 0 },
594 { SB_DSP_PCM_DEV, 0 },
595 { SB_DSP_FM_DEV, 0 },
599 * SB16 specific mixer elements
601 static struct sbmix_elem snd_sb16_ctl_master_play_vol =
602 SB_DOUBLE("Master Playback Volume", SB_DSP4_MASTER_DEV, (SB_DSP4_MASTER_DEV + 1), 3, 3, 31);
603 static struct sbmix_elem snd_sb16_ctl_3d_enhance_switch =
604 SB_SINGLE("3D Enhancement Switch", SB_DSP4_3DSE, 0, 1);
605 static struct sbmix_elem snd_sb16_ctl_tone_bass =
606 SB_DOUBLE("Tone Control - Bass", SB_DSP4_BASS_DEV, (SB_DSP4_BASS_DEV + 1), 4, 4, 15);
607 static struct sbmix_elem snd_sb16_ctl_tone_treble =
608 SB_DOUBLE("Tone Control - Treble", SB_DSP4_TREBLE_DEV, (SB_DSP4_TREBLE_DEV + 1), 4, 4, 15);
609 static struct sbmix_elem snd_sb16_ctl_pcm_play_vol =
610 SB_DOUBLE("PCM Playback Volume", SB_DSP4_PCM_DEV, (SB_DSP4_PCM_DEV + 1), 3, 3, 31);
611 static struct sbmix_elem snd_sb16_ctl_synth_capture_route =
612 SB16_INPUT_SW("Synth Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 6, 5);
613 static struct sbmix_elem snd_sb16_ctl_synth_play_vol =
614 SB_DOUBLE("Synth Playback Volume", SB_DSP4_SYNTH_DEV, (SB_DSP4_SYNTH_DEV + 1), 3, 3, 31);
615 static struct sbmix_elem snd_sb16_ctl_cd_capture_route =
616 SB16_INPUT_SW("CD Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 2, 1);
617 static struct sbmix_elem snd_sb16_ctl_cd_play_switch =
618 SB_DOUBLE("CD Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1);
619 static struct sbmix_elem snd_sb16_ctl_cd_play_vol =
620 SB_DOUBLE("CD Playback Volume", SB_DSP4_CD_DEV, (SB_DSP4_CD_DEV + 1), 3, 3, 31);
621 static struct sbmix_elem snd_sb16_ctl_line_capture_route =
622 SB16_INPUT_SW("Line Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 4, 3);
623 static struct sbmix_elem snd_sb16_ctl_line_play_switch =
624 SB_DOUBLE("Line Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1);
625 static struct sbmix_elem snd_sb16_ctl_line_play_vol =
626 SB_DOUBLE("Line Playback Volume", SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31);
627 static struct sbmix_elem snd_sb16_ctl_mic_capture_route =
628 SB16_INPUT_SW("Mic Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0);
629 static struct sbmix_elem snd_sb16_ctl_mic_play_switch =
630 SB_SINGLE("Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1);
631 static struct sbmix_elem snd_sb16_ctl_mic_play_vol =
632 SB_SINGLE("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31);
633 static struct sbmix_elem snd_sb16_ctl_pc_speaker_vol =
634 SB_SINGLE("PC Speaker Volume", SB_DSP4_SPEAKER_DEV, 6, 3);
635 static struct sbmix_elem snd_sb16_ctl_capture_vol =
636 SB_DOUBLE("Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3);
637 static struct sbmix_elem snd_sb16_ctl_play_vol =
638 SB_DOUBLE("Playback Volume", SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3);
639 static struct sbmix_elem snd_sb16_ctl_auto_mic_gain =
640 SB_SINGLE("Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1);
642 static struct sbmix_elem *snd_sb16_controls[] = {
643 &snd_sb16_ctl_master_play_vol,
644 &snd_sb16_ctl_3d_enhance_switch,
645 &snd_sb16_ctl_tone_bass,
646 &snd_sb16_ctl_tone_treble,
647 &snd_sb16_ctl_pcm_play_vol,
648 &snd_sb16_ctl_synth_capture_route,
649 &snd_sb16_ctl_synth_play_vol,
650 &snd_sb16_ctl_cd_capture_route,
651 &snd_sb16_ctl_cd_play_switch,
652 &snd_sb16_ctl_cd_play_vol,
653 &snd_sb16_ctl_line_capture_route,
654 &snd_sb16_ctl_line_play_switch,
655 &snd_sb16_ctl_line_play_vol,
656 &snd_sb16_ctl_mic_capture_route,
657 &snd_sb16_ctl_mic_play_switch,
658 &snd_sb16_ctl_mic_play_vol,
659 &snd_sb16_ctl_pc_speaker_vol,
660 &snd_sb16_ctl_capture_vol,
661 &snd_sb16_ctl_play_vol,
662 &snd_sb16_ctl_auto_mic_gain
665 static unsigned char snd_sb16_init_values[][2] = {
666 { SB_DSP4_MASTER_DEV + 0, 0 },
667 { SB_DSP4_MASTER_DEV + 1, 0 },
668 { SB_DSP4_PCM_DEV + 0, 0 },
669 { SB_DSP4_PCM_DEV + 1, 0 },
670 { SB_DSP4_SYNTH_DEV + 0, 0 },
671 { SB_DSP4_SYNTH_DEV + 1, 0 },
672 { SB_DSP4_INPUT_LEFT, 0 },
673 { SB_DSP4_INPUT_RIGHT, 0 },
674 { SB_DSP4_OUTPUT_SW, 0 },
675 { SB_DSP4_SPEAKER_DEV, 0 },
679 * DT019x specific mixer elements
681 static struct sbmix_elem snd_dt019x_ctl_master_play_vol =
682 SB_DOUBLE("Master Playback Volume", SB_DT019X_MASTER_DEV, SB_DT019X_MASTER_DEV, 4,0, 15);
683 static struct sbmix_elem snd_dt019x_ctl_pcm_play_vol =
684 SB_DOUBLE("PCM Playback Volume", SB_DT019X_PCM_DEV, SB_DT019X_PCM_DEV, 4,0, 15);
685 static struct sbmix_elem snd_dt019x_ctl_synth_play_vol =
686 SB_DOUBLE("Synth Playback Volume", SB_DT019X_SYNTH_DEV, SB_DT019X_SYNTH_DEV, 4,0, 15);
687 static struct sbmix_elem snd_dt019x_ctl_cd_play_vol =
688 SB_DOUBLE("CD Playback Volume", SB_DT019X_CD_DEV, SB_DT019X_CD_DEV, 4,0, 15);
689 static struct sbmix_elem snd_dt019x_ctl_mic_play_vol =
690 SB_SINGLE("Mic Playback Volume", SB_DT019X_MIC_DEV, 4, 7);
691 static struct sbmix_elem snd_dt019x_ctl_pc_speaker_vol =
692 SB_SINGLE("PC Speaker Volume", SB_DT019X_SPKR_DEV, 0, 7);
693 static struct sbmix_elem snd_dt019x_ctl_line_play_vol =
694 SB_DOUBLE("Line Playback Volume", SB_DT019X_LINE_DEV, SB_DT019X_LINE_DEV, 4,0, 15);
695 static struct sbmix_elem snd_dt019x_ctl_pcm_play_switch =
696 SB_DOUBLE("PCM Playback Switch", SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 2,1, 1);
697 static struct sbmix_elem snd_dt019x_ctl_synth_play_switch =
698 SB_DOUBLE("Synth Playback Switch", SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 4,3, 1);
699 static struct sbmix_elem snd_dt019x_ctl_capture_source =
701 .name = "Capture Source",
702 .type = SB_MIX_CAPTURE_DT019X
705 static struct sbmix_elem *snd_dt019x_controls[] = {
706 /* ALS4000 below has some parts which we might be lacking,
707 * e.g. snd_als4000_ctl_mono_playback_switch - check it! */
708 &snd_dt019x_ctl_master_play_vol,
709 &snd_dt019x_ctl_pcm_play_vol,
710 &snd_dt019x_ctl_synth_play_vol,
711 &snd_dt019x_ctl_cd_play_vol,
712 &snd_dt019x_ctl_mic_play_vol,
713 &snd_dt019x_ctl_pc_speaker_vol,
714 &snd_dt019x_ctl_line_play_vol,
715 &snd_sb16_ctl_mic_play_switch,
716 &snd_sb16_ctl_cd_play_switch,
717 &snd_sb16_ctl_line_play_switch,
718 &snd_dt019x_ctl_pcm_play_switch,
719 &snd_dt019x_ctl_synth_play_switch,
720 &snd_dt019x_ctl_capture_source
723 static unsigned char snd_dt019x_init_values[][2] = {
724 { SB_DT019X_MASTER_DEV, 0 },
725 { SB_DT019X_PCM_DEV, 0 },
726 { SB_DT019X_SYNTH_DEV, 0 },
727 { SB_DT019X_CD_DEV, 0 },
728 { SB_DT019X_MIC_DEV, 0 }, /* Includes PC-speaker in high nibble */
729 { SB_DT019X_LINE_DEV, 0 },
730 { SB_DSP4_OUTPUT_SW, 0 },
731 { SB_DT019X_OUTPUT_SW2, 0 },
732 { SB_DT019X_CAPTURE_SW, 0x06 },
736 * ALS4000 specific mixer elements
738 static struct sbmix_elem snd_als4000_ctl_master_mono_playback_switch =
739 SB_SINGLE("Master Mono Playback Switch", SB_ALS4000_MONO_IO_CTRL, 5, 1);
740 static struct sbmix_elem snd_als4k_ctl_master_mono_capture_route = {
741 .name = "Master Mono Capture Route",
742 .type = SB_MIX_MONO_CAPTURE_ALS4K
744 static struct sbmix_elem snd_als4000_ctl_mono_playback_switch =
745 SB_SINGLE("Mono Playback Switch", SB_DT019X_OUTPUT_SW2, 0, 1);
746 static struct sbmix_elem snd_als4000_ctl_mic_20db_boost =
747 SB_SINGLE("Mic Boost (+20dB)", SB_ALS4000_MIC_IN_GAIN, 0, 0x03);
748 static struct sbmix_elem snd_als4000_ctl_mixer_analog_loopback =
749 SB_SINGLE("Analog Loopback Switch", SB_ALS4000_MIC_IN_GAIN, 7, 0x01);
750 static struct sbmix_elem snd_als4000_ctl_mixer_digital_loopback =
751 SB_SINGLE("Digital Loopback Switch",
752 SB_ALS4000_CR3_CONFIGURATION, 7, 0x01);
753 /* FIXME: functionality of 3D controls might be swapped, I didn't find
754 * a description of how to identify what is supposed to be what */
755 static struct sbmix_elem snd_als4000_3d_control_switch =
756 SB_SINGLE("3D Control - Switch", SB_ALS4000_3D_SND_FX, 6, 0x01);
757 static struct sbmix_elem snd_als4000_3d_control_ratio =
758 SB_SINGLE("3D Control - Level", SB_ALS4000_3D_SND_FX, 0, 0x07);
759 static struct sbmix_elem snd_als4000_3d_control_freq =
760 /* FIXME: maybe there's actually some standard 3D ctrl name for it?? */
761 SB_SINGLE("3D Control - Freq", SB_ALS4000_3D_SND_FX, 4, 0x03);
762 static struct sbmix_elem snd_als4000_3d_control_delay =
763 /* FIXME: ALS4000a.pdf mentions BBD (Bucket Brigade Device) time delay,
764 * but what ALSA 3D attribute is that actually? "Center", "Depth",
765 * "Wide" or "Space" or even "Level"? Assuming "Wide" for now... */
766 SB_SINGLE("3D Control - Wide", SB_ALS4000_3D_TIME_DELAY, 0, 0x0f);
767 static struct sbmix_elem snd_als4000_3d_control_poweroff_switch =
768 SB_SINGLE("3D PowerOff Switch", SB_ALS4000_3D_TIME_DELAY, 4, 0x01);
769 static struct sbmix_elem snd_als4000_ctl_3db_freq_control_switch =
770 SB_SINGLE("Master Playback 8kHz / 20kHz LPF Switch",
771 SB_ALS4000_FMDAC, 5, 0x01);
773 static struct sbmix_elem snd_als4000_ctl_fmdac =
774 SB_SINGLE("FMDAC Switch (Option ?)", SB_ALS4000_FMDAC, 0, 0x01);
775 static struct sbmix_elem snd_als4000_ctl_qsound =
776 SB_SINGLE("QSound Mode", SB_ALS4000_QSOUND, 1, 0x1f);
779 static struct sbmix_elem *snd_als4000_controls[] = {
780 /* ALS4000a.PDF regs page */
781 &snd_sb16_ctl_master_play_vol, /* MX30/31 12 */
782 &snd_dt019x_ctl_pcm_play_switch, /* MX4C 16 */
783 &snd_sb16_ctl_pcm_play_vol, /* MX32/33 12 */
784 &snd_sb16_ctl_synth_capture_route, /* MX3D/3E 14 */
785 &snd_dt019x_ctl_synth_play_switch, /* MX4C 16 */
786 &snd_sb16_ctl_synth_play_vol, /* MX34/35 12/13 */
787 &snd_sb16_ctl_cd_capture_route, /* MX3D/3E 14 */
788 &snd_sb16_ctl_cd_play_switch, /* MX3C 14 */
789 &snd_sb16_ctl_cd_play_vol, /* MX36/37 13 */
790 &snd_sb16_ctl_line_capture_route, /* MX3D/3E 14 */
791 &snd_sb16_ctl_line_play_switch, /* MX3C 14 */
792 &snd_sb16_ctl_line_play_vol, /* MX38/39 13 */
793 &snd_sb16_ctl_mic_capture_route, /* MX3D/3E 14 */
794 &snd_als4000_ctl_mic_20db_boost, /* MX4D 16 */
795 &snd_sb16_ctl_mic_play_switch, /* MX3C 14 */
796 &snd_sb16_ctl_mic_play_vol, /* MX3A 13 */
797 &snd_sb16_ctl_pc_speaker_vol, /* MX3B 14 */
798 &snd_sb16_ctl_capture_vol, /* MX3F/40 15 */
799 &snd_sb16_ctl_play_vol, /* MX41/42 15 */
800 &snd_als4000_ctl_master_mono_playback_switch, /* MX4C 16 */
801 &snd_als4k_ctl_master_mono_capture_route, /* MX4B 16 */
802 &snd_als4000_ctl_mono_playback_switch, /* MX4C 16 */
803 &snd_als4000_ctl_mixer_analog_loopback, /* MX4D 16 */
804 &snd_als4000_ctl_mixer_digital_loopback, /* CR3 21 */
805 &snd_als4000_3d_control_switch, /* MX50 17 */
806 &snd_als4000_3d_control_ratio, /* MX50 17 */
807 &snd_als4000_3d_control_freq, /* MX50 17 */
808 &snd_als4000_3d_control_delay, /* MX51 18 */
809 &snd_als4000_3d_control_poweroff_switch, /* MX51 18 */
810 &snd_als4000_ctl_3db_freq_control_switch, /* MX4F 17 */
812 &snd_als4000_ctl_fmdac,
813 &snd_als4000_ctl_qsound,
817 static unsigned char snd_als4000_init_values[][2] = {
818 { SB_DSP4_MASTER_DEV + 0, 0 },
819 { SB_DSP4_MASTER_DEV + 1, 0 },
820 { SB_DSP4_PCM_DEV + 0, 0 },
821 { SB_DSP4_PCM_DEV + 1, 0 },
822 { SB_DSP4_SYNTH_DEV + 0, 0 },
823 { SB_DSP4_SYNTH_DEV + 1, 0 },
824 { SB_DSP4_SPEAKER_DEV, 0 },
825 { SB_DSP4_OUTPUT_SW, 0 },
826 { SB_DSP4_INPUT_LEFT, 0 },
827 { SB_DSP4_INPUT_RIGHT, 0 },
828 { SB_DT019X_OUTPUT_SW2, 0 },
829 { SB_ALS4000_MIC_IN_GAIN, 0 },
835 static int snd_sbmixer_init(struct snd_sb *chip,
836 struct sbmix_elem **controls,
838 unsigned char map[][2],
843 struct snd_card *card = chip->card;
847 spin_lock_irqsave(&chip->mixer_lock, flags);
848 snd_sbmixer_write(chip, 0x00, 0x00);
849 spin_unlock_irqrestore(&chip->mixer_lock, flags);
851 /* mute and zero volume channels */
852 for (idx = 0; idx < map_count; idx++) {
853 spin_lock_irqsave(&chip->mixer_lock, flags);
854 snd_sbmixer_write(chip, map[idx][0], map[idx][1]);
855 spin_unlock_irqrestore(&chip->mixer_lock, flags);
858 for (idx = 0; idx < controls_count; idx++) {
859 if ((err = snd_sbmixer_add_ctl_elem(chip, controls[idx])) < 0)
862 snd_component_add(card, name);
863 strcpy(card->mixername, name);
867 int snd_sbmixer_new(struct snd_sb *chip)
869 struct snd_card *card;
872 if (snd_BUG_ON(!chip || !chip->card))
877 switch (chip->hardware) {
879 return 0; /* no mixer chip on SB1.x */
882 if ((err = snd_sbmixer_init(chip,
884 ARRAY_SIZE(snd_sb20_controls),
885 snd_sb20_init_values,
886 ARRAY_SIZE(snd_sb20_init_values),
891 if ((err = snd_sbmixer_init(chip,
893 ARRAY_SIZE(snd_sbpro_controls),
894 snd_sbpro_init_values,
895 ARRAY_SIZE(snd_sbpro_init_values),
902 if ((err = snd_sbmixer_init(chip,
904 ARRAY_SIZE(snd_sb16_controls),
905 snd_sb16_init_values,
906 ARRAY_SIZE(snd_sb16_init_values),
911 if ((err = snd_sbmixer_init(chip,
912 snd_als4000_controls,
913 ARRAY_SIZE(snd_als4000_controls),
914 snd_als4000_init_values,
915 ARRAY_SIZE(snd_als4000_init_values),
920 if ((err = snd_sbmixer_init(chip,
922 ARRAY_SIZE(snd_dt019x_controls),
923 snd_dt019x_init_values,
924 ARRAY_SIZE(snd_dt019x_init_values),
928 strcpy(card->mixername, "???");
934 static unsigned char sb20_saved_regs[] = {
941 static unsigned char sbpro_saved_regs[] = {
944 SB_DSP_PLAYBACK_FILT,
949 SB_DSP_CAPTURE_SOURCE,
953 static unsigned char sb16_saved_regs[] = {
954 SB_DSP4_MASTER_DEV, SB_DSP4_MASTER_DEV + 1,
956 SB_DSP4_BASS_DEV, SB_DSP4_BASS_DEV + 1,
957 SB_DSP4_TREBLE_DEV, SB_DSP4_TREBLE_DEV + 1,
958 SB_DSP4_PCM_DEV, SB_DSP4_PCM_DEV + 1,
959 SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT,
960 SB_DSP4_SYNTH_DEV, SB_DSP4_SYNTH_DEV + 1,
962 SB_DSP4_CD_DEV, SB_DSP4_CD_DEV + 1,
963 SB_DSP4_LINE_DEV, SB_DSP4_LINE_DEV + 1,
966 SB_DSP4_IGAIN_DEV, SB_DSP4_IGAIN_DEV + 1,
967 SB_DSP4_OGAIN_DEV, SB_DSP4_OGAIN_DEV + 1,
971 static unsigned char dt019x_saved_regs[] = {
972 SB_DT019X_MASTER_DEV,
980 SB_DT019X_OUTPUT_SW2,
981 SB_DT019X_CAPTURE_SW,
984 static unsigned char als4000_saved_regs[] = {
985 /* please verify in dsheet whether regs to be added
986 are actually real H/W or just dummy */
987 SB_DSP4_MASTER_DEV, SB_DSP4_MASTER_DEV + 1,
989 SB_DSP4_PCM_DEV, SB_DSP4_PCM_DEV + 1,
990 SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT,
991 SB_DSP4_SYNTH_DEV, SB_DSP4_SYNTH_DEV + 1,
992 SB_DSP4_CD_DEV, SB_DSP4_CD_DEV + 1,
995 SB_DSP4_IGAIN_DEV, SB_DSP4_IGAIN_DEV + 1,
996 SB_DSP4_OGAIN_DEV, SB_DSP4_OGAIN_DEV + 1,
997 SB_DT019X_OUTPUT_SW2,
998 SB_ALS4000_MONO_IO_CTRL,
999 SB_ALS4000_MIC_IN_GAIN,
1001 SB_ALS4000_3D_SND_FX,
1002 SB_ALS4000_3D_TIME_DELAY,
1003 SB_ALS4000_CR3_CONFIGURATION,
1006 static void save_mixer(struct snd_sb *chip, unsigned char *regs, int num_regs)
1008 unsigned char *val = chip->saved_regs;
1009 if (snd_BUG_ON(num_regs > ARRAY_SIZE(chip->saved_regs)))
1011 for (; num_regs; num_regs--)
1012 *val++ = snd_sbmixer_read(chip, *regs++);
1015 static void restore_mixer(struct snd_sb *chip, unsigned char *regs, int num_regs)
1017 unsigned char *val = chip->saved_regs;
1018 if (snd_BUG_ON(num_regs > ARRAY_SIZE(chip->saved_regs)))
1020 for (; num_regs; num_regs--)
1021 snd_sbmixer_write(chip, *regs++, *val++);
1024 void snd_sbmixer_suspend(struct snd_sb *chip)
1026 switch (chip->hardware) {
1029 save_mixer(chip, sb20_saved_regs, ARRAY_SIZE(sb20_saved_regs));
1032 save_mixer(chip, sbpro_saved_regs, ARRAY_SIZE(sbpro_saved_regs));
1037 save_mixer(chip, sb16_saved_regs, ARRAY_SIZE(sb16_saved_regs));
1040 save_mixer(chip, als4000_saved_regs, ARRAY_SIZE(als4000_saved_regs));
1043 save_mixer(chip, dt019x_saved_regs, ARRAY_SIZE(dt019x_saved_regs));
1050 void snd_sbmixer_resume(struct snd_sb *chip)
1052 switch (chip->hardware) {
1055 restore_mixer(chip, sb20_saved_regs, ARRAY_SIZE(sb20_saved_regs));
1058 restore_mixer(chip, sbpro_saved_regs, ARRAY_SIZE(sbpro_saved_regs));
1063 restore_mixer(chip, sb16_saved_regs, ARRAY_SIZE(sb16_saved_regs));
1066 restore_mixer(chip, als4000_saved_regs, ARRAY_SIZE(als4000_saved_regs));
1069 restore_mixer(chip, dt019x_saved_regs, ARRAY_SIZE(dt019x_saved_regs));