Linux 2.6.25.20
[linux/fpc-iii.git] / sound / isa / sb / sb_mixer.c
blob91d14224f6b332de1119d89bc07bff76c00f37cc
1 /*
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
22 #include <asm/io.h>
23 #include <linux/delay.h>
24 #include <linux/time.h>
25 #include <sound/core.h>
26 #include <sound/sb.h>
27 #include <sound/control.h>
29 #undef IO_DEBUG
31 void snd_sbmixer_write(struct snd_sb *chip, unsigned char reg, unsigned char data)
33 outb(reg, SBP(chip, MIXER_ADDR));
34 udelay(10);
35 outb(data, SBP(chip, MIXER_DATA));
36 udelay(10);
37 #ifdef IO_DEBUG
38 snd_printk(KERN_DEBUG "mixer_write 0x%x 0x%x\n", reg, data);
39 #endif
42 unsigned char snd_sbmixer_read(struct snd_sb *chip, unsigned char reg)
44 unsigned char result;
46 outb(reg, SBP(chip, MIXER_ADDR));
47 udelay(10);
48 result = inb(SBP(chip, MIXER_DATA));
49 udelay(10);
50 #ifdef IO_DEBUG
51 snd_printk(KERN_DEBUG "mixer_read 0x%x 0x%x\n", reg, result);
52 #endif
53 return 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;
65 uinfo->count = 1;
66 uinfo->value.integer.min = 0;
67 uinfo->value.integer.max = mask;
68 return 0;
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);
74 unsigned long flags;
75 int reg = kcontrol->private_value & 0xff;
76 int shift = (kcontrol->private_value >> 16) & 0xff;
77 int mask = (kcontrol->private_value >> 24) & 0xff;
78 unsigned char val;
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;
84 return 0;
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);
90 unsigned long flags;
91 int reg = kcontrol->private_value & 0xff;
92 int shift = (kcontrol->private_value >> 16) & 0x07;
93 int mask = (kcontrol->private_value >> 24) & 0xff;
94 int change;
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;
102 if (change)
103 snd_sbmixer_write(sb, reg, val);
104 spin_unlock_irqrestore(&sb->mixer_lock, flags);
105 return change;
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;
117 uinfo->count = 2;
118 uinfo->value.integer.min = 0;
119 uinfo->value.integer.max = mask;
120 return 0;
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);
126 unsigned long flags;
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;
140 return 0;
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);
146 unsigned long flags;
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;
152 int change;
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;
162 if (change)
163 snd_sbmixer_write(sb, left_reg, left);
164 } else {
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;
170 if (change) {
171 snd_sbmixer_write(sb, left_reg, left);
172 snd_sbmixer_write(sb, right_reg, right);
175 spin_unlock_irqrestore(&sb->mixer_lock, flags);
176 return change;
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 char *texts[5] = {
186 "CD", "Mic", "Line", "Synth", "Master"
189 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
190 uinfo->count = 1;
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]);
195 return 0;
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);
201 unsigned long flags;
202 unsigned char oval;
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;
210 break;
211 case SB_DT019X_CAP_MIC:
212 ucontrol->value.enumerated.item[0] = 1;
213 break;
214 case SB_DT019X_CAP_LINE:
215 ucontrol->value.enumerated.item[0] = 2;
216 break;
217 case SB_DT019X_CAP_MAIN:
218 ucontrol->value.enumerated.item[0] = 4;
219 break;
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;
225 * break;
227 default:
228 ucontrol->value.enumerated.item[0] = 4;
229 break;
231 return 0;
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);
237 unsigned long flags;
238 int change;
239 unsigned char nval, oval;
241 if (ucontrol->value.enumerated.item[0] > 4)
242 return -EINVAL;
243 switch (ucontrol->value.enumerated.item[0]) {
244 case 0:
245 nval = SB_DT019X_CAP_CD;
246 break;
247 case 1:
248 nval = SB_DT019X_CAP_MIC;
249 break;
250 case 2:
251 nval = SB_DT019X_CAP_LINE;
252 break;
253 case 3:
254 nval = SB_DT019X_CAP_SYNTH;
255 break;
256 case 4:
257 nval = SB_DT019X_CAP_MAIN;
258 break;
259 default:
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;
265 if (change)
266 snd_sbmixer_write(sb, SB_DT019X_CAPTURE_SW, nval);
267 spin_unlock_irqrestore(&sb->mixer_lock, flags);
268 return change;
272 * SBPRO input multiplexer
275 static int snd_sb8mixer_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
277 static char *texts[3] = {
278 "Mic", "CD", "Line"
281 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
282 uinfo->count = 1;
283 uinfo->value.enumerated.items = 3;
284 if (uinfo->value.enumerated.item > 2)
285 uinfo->value.enumerated.item = 2;
286 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
287 return 0;
291 static int snd_sb8mixer_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
293 struct snd_sb *sb = snd_kcontrol_chip(kcontrol);
294 unsigned long flags;
295 unsigned char oval;
297 spin_lock_irqsave(&sb->mixer_lock, flags);
298 oval = snd_sbmixer_read(sb, SB_DSP_CAPTURE_SOURCE);
299 spin_unlock_irqrestore(&sb->mixer_lock, flags);
300 switch ((oval >> 0x01) & 0x03) {
301 case SB_DSP_MIXS_CD:
302 ucontrol->value.enumerated.item[0] = 1;
303 break;
304 case SB_DSP_MIXS_LINE:
305 ucontrol->value.enumerated.item[0] = 2;
306 break;
307 default:
308 ucontrol->value.enumerated.item[0] = 0;
309 break;
311 return 0;
314 static int snd_sb8mixer_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
316 struct snd_sb *sb = snd_kcontrol_chip(kcontrol);
317 unsigned long flags;
318 int change;
319 unsigned char nval, oval;
321 if (ucontrol->value.enumerated.item[0] > 2)
322 return -EINVAL;
323 switch (ucontrol->value.enumerated.item[0]) {
324 case 1:
325 nval = SB_DSP_MIXS_CD;
326 break;
327 case 2:
328 nval = SB_DSP_MIXS_LINE;
329 break;
330 default:
331 nval = SB_DSP_MIXS_MIC;
333 nval <<= 1;
334 spin_lock_irqsave(&sb->mixer_lock, flags);
335 oval = snd_sbmixer_read(sb, SB_DSP_CAPTURE_SOURCE);
336 nval |= oval & ~0x06;
337 change = nval != oval;
338 if (change)
339 snd_sbmixer_write(sb, SB_DSP_CAPTURE_SOURCE, nval);
340 spin_unlock_irqrestore(&sb->mixer_lock, flags);
341 return change;
345 * SB16 input switch
348 static int snd_sb16mixer_info_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
350 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
351 uinfo->count = 4;
352 uinfo->value.integer.min = 0;
353 uinfo->value.integer.max = 1;
354 return 0;
357 static int snd_sb16mixer_get_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
359 struct snd_sb *sb = snd_kcontrol_chip(kcontrol);
360 unsigned long flags;
361 int reg1 = kcontrol->private_value & 0xff;
362 int reg2 = (kcontrol->private_value >> 8) & 0xff;
363 int left_shift = (kcontrol->private_value >> 16) & 0x0f;
364 int right_shift = (kcontrol->private_value >> 24) & 0x0f;
365 unsigned char val1, val2;
367 spin_lock_irqsave(&sb->mixer_lock, flags);
368 val1 = snd_sbmixer_read(sb, reg1);
369 val2 = snd_sbmixer_read(sb, reg2);
370 spin_unlock_irqrestore(&sb->mixer_lock, flags);
371 ucontrol->value.integer.value[0] = (val1 >> left_shift) & 0x01;
372 ucontrol->value.integer.value[1] = (val2 >> left_shift) & 0x01;
373 ucontrol->value.integer.value[2] = (val1 >> right_shift) & 0x01;
374 ucontrol->value.integer.value[3] = (val2 >> right_shift) & 0x01;
375 return 0;
378 static int snd_sb16mixer_put_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
380 struct snd_sb *sb = snd_kcontrol_chip(kcontrol);
381 unsigned long flags;
382 int reg1 = kcontrol->private_value & 0xff;
383 int reg2 = (kcontrol->private_value >> 8) & 0xff;
384 int left_shift = (kcontrol->private_value >> 16) & 0x0f;
385 int right_shift = (kcontrol->private_value >> 24) & 0x0f;
386 int change;
387 unsigned char val1, val2, oval1, oval2;
389 spin_lock_irqsave(&sb->mixer_lock, flags);
390 oval1 = snd_sbmixer_read(sb, reg1);
391 oval2 = snd_sbmixer_read(sb, reg2);
392 val1 = oval1 & ~((1 << left_shift) | (1 << right_shift));
393 val2 = oval2 & ~((1 << left_shift) | (1 << right_shift));
394 val1 |= (ucontrol->value.integer.value[0] & 1) << left_shift;
395 val2 |= (ucontrol->value.integer.value[1] & 1) << left_shift;
396 val1 |= (ucontrol->value.integer.value[2] & 1) << right_shift;
397 val2 |= (ucontrol->value.integer.value[3] & 1) << right_shift;
398 change = val1 != oval1 || val2 != oval2;
399 if (change) {
400 snd_sbmixer_write(sb, reg1, val1);
401 snd_sbmixer_write(sb, reg2, val2);
403 spin_unlock_irqrestore(&sb->mixer_lock, flags);
404 return change;
412 int snd_sbmixer_add_ctl(struct snd_sb *chip, const char *name, int index, int type, unsigned long value)
414 static struct snd_kcontrol_new newctls[] = {
415 [SB_MIX_SINGLE] = {
416 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
417 .info = snd_sbmixer_info_single,
418 .get = snd_sbmixer_get_single,
419 .put = snd_sbmixer_put_single,
421 [SB_MIX_DOUBLE] = {
422 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
423 .info = snd_sbmixer_info_double,
424 .get = snd_sbmixer_get_double,
425 .put = snd_sbmixer_put_double,
427 [SB_MIX_INPUT_SW] = {
428 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
429 .info = snd_sb16mixer_info_input_sw,
430 .get = snd_sb16mixer_get_input_sw,
431 .put = snd_sb16mixer_put_input_sw,
433 [SB_MIX_CAPTURE_PRO] = {
434 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
435 .info = snd_sb8mixer_info_mux,
436 .get = snd_sb8mixer_get_mux,
437 .put = snd_sb8mixer_put_mux,
439 [SB_MIX_CAPTURE_DT019X] = {
440 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
441 .info = snd_dt019x_input_sw_info,
442 .get = snd_dt019x_input_sw_get,
443 .put = snd_dt019x_input_sw_put,
446 struct snd_kcontrol *ctl;
447 int err;
449 ctl = snd_ctl_new1(&newctls[type], chip);
450 if (! ctl)
451 return -ENOMEM;
452 strlcpy(ctl->id.name, name, sizeof(ctl->id.name));
453 ctl->id.index = index;
454 ctl->private_value = value;
455 if ((err = snd_ctl_add(chip->card, ctl)) < 0)
456 return err;
457 return 0;
461 * SB 2.0 specific mixer elements
464 static struct sbmix_elem snd_sb20_ctl_master_play_vol =
465 SB_SINGLE("Master Playback Volume", SB_DSP20_MASTER_DEV, 1, 7);
466 static struct sbmix_elem snd_sb20_ctl_pcm_play_vol =
467 SB_SINGLE("PCM Playback Volume", SB_DSP20_PCM_DEV, 1, 3);
468 static struct sbmix_elem snd_sb20_ctl_synth_play_vol =
469 SB_SINGLE("Synth Playback Volume", SB_DSP20_FM_DEV, 1, 7);
470 static struct sbmix_elem snd_sb20_ctl_cd_play_vol =
471 SB_SINGLE("CD Playback Volume", SB_DSP20_CD_DEV, 1, 7);
473 static struct sbmix_elem *snd_sb20_controls[] = {
474 &snd_sb20_ctl_master_play_vol,
475 &snd_sb20_ctl_pcm_play_vol,
476 &snd_sb20_ctl_synth_play_vol,
477 &snd_sb20_ctl_cd_play_vol
480 static unsigned char snd_sb20_init_values[][2] = {
481 { SB_DSP20_MASTER_DEV, 0 },
482 { SB_DSP20_FM_DEV, 0 },
486 * SB Pro specific mixer elements
488 static struct sbmix_elem snd_sbpro_ctl_master_play_vol =
489 SB_DOUBLE("Master Playback Volume", SB_DSP_MASTER_DEV, SB_DSP_MASTER_DEV, 5, 1, 7);
490 static struct sbmix_elem snd_sbpro_ctl_pcm_play_vol =
491 SB_DOUBLE("PCM Playback Volume", SB_DSP_PCM_DEV, SB_DSP_PCM_DEV, 5, 1, 7);
492 static struct sbmix_elem snd_sbpro_ctl_pcm_play_filter =
493 SB_SINGLE("PCM Playback Filter", SB_DSP_PLAYBACK_FILT, 5, 1);
494 static struct sbmix_elem snd_sbpro_ctl_synth_play_vol =
495 SB_DOUBLE("Synth Playback Volume", SB_DSP_FM_DEV, SB_DSP_FM_DEV, 5, 1, 7);
496 static struct sbmix_elem snd_sbpro_ctl_cd_play_vol =
497 SB_DOUBLE("CD Playback Volume", SB_DSP_CD_DEV, SB_DSP_CD_DEV, 5, 1, 7);
498 static struct sbmix_elem snd_sbpro_ctl_line_play_vol =
499 SB_DOUBLE("Line Playback Volume", SB_DSP_LINE_DEV, SB_DSP_LINE_DEV, 5, 1, 7);
500 static struct sbmix_elem snd_sbpro_ctl_mic_play_vol =
501 SB_SINGLE("Mic Playback Volume", SB_DSP_MIC_DEV, 1, 3);
502 static struct sbmix_elem snd_sbpro_ctl_capture_source =
504 .name = "Capture Source",
505 .type = SB_MIX_CAPTURE_PRO
507 static struct sbmix_elem snd_sbpro_ctl_capture_filter =
508 SB_SINGLE("Capture Filter", SB_DSP_CAPTURE_FILT, 5, 1);
509 static struct sbmix_elem snd_sbpro_ctl_capture_low_filter =
510 SB_SINGLE("Capture Low-Pass Filter", SB_DSP_CAPTURE_FILT, 3, 1);
512 static struct sbmix_elem *snd_sbpro_controls[] = {
513 &snd_sbpro_ctl_master_play_vol,
514 &snd_sbpro_ctl_pcm_play_vol,
515 &snd_sbpro_ctl_pcm_play_filter,
516 &snd_sbpro_ctl_synth_play_vol,
517 &snd_sbpro_ctl_cd_play_vol,
518 &snd_sbpro_ctl_line_play_vol,
519 &snd_sbpro_ctl_mic_play_vol,
520 &snd_sbpro_ctl_capture_source,
521 &snd_sbpro_ctl_capture_filter,
522 &snd_sbpro_ctl_capture_low_filter
525 static unsigned char snd_sbpro_init_values[][2] = {
526 { SB_DSP_MASTER_DEV, 0 },
527 { SB_DSP_PCM_DEV, 0 },
528 { SB_DSP_FM_DEV, 0 },
532 * SB16 specific mixer elements
534 static struct sbmix_elem snd_sb16_ctl_master_play_vol =
535 SB_DOUBLE("Master Playback Volume", SB_DSP4_MASTER_DEV, (SB_DSP4_MASTER_DEV + 1), 3, 3, 31);
536 static struct sbmix_elem snd_sb16_ctl_3d_enhance_switch =
537 SB_SINGLE("3D Enhancement Switch", SB_DSP4_3DSE, 0, 1);
538 static struct sbmix_elem snd_sb16_ctl_tone_bass =
539 SB_DOUBLE("Tone Control - Bass", SB_DSP4_BASS_DEV, (SB_DSP4_BASS_DEV + 1), 4, 4, 15);
540 static struct sbmix_elem snd_sb16_ctl_tone_treble =
541 SB_DOUBLE("Tone Control - Treble", SB_DSP4_TREBLE_DEV, (SB_DSP4_TREBLE_DEV + 1), 4, 4, 15);
542 static struct sbmix_elem snd_sb16_ctl_pcm_play_vol =
543 SB_DOUBLE("PCM Playback Volume", SB_DSP4_PCM_DEV, (SB_DSP4_PCM_DEV + 1), 3, 3, 31);
544 static struct sbmix_elem snd_sb16_ctl_synth_capture_route =
545 SB16_INPUT_SW("Synth Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 6, 5);
546 static struct sbmix_elem snd_sb16_ctl_synth_play_vol =
547 SB_DOUBLE("Synth Playback Volume", SB_DSP4_SYNTH_DEV, (SB_DSP4_SYNTH_DEV + 1), 3, 3, 31);
548 static struct sbmix_elem snd_sb16_ctl_cd_capture_route =
549 SB16_INPUT_SW("CD Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 2, 1);
550 static struct sbmix_elem snd_sb16_ctl_cd_play_switch =
551 SB_DOUBLE("CD Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1);
552 static struct sbmix_elem snd_sb16_ctl_cd_play_vol =
553 SB_DOUBLE("CD Playback Volume", SB_DSP4_CD_DEV, (SB_DSP4_CD_DEV + 1), 3, 3, 31);
554 static struct sbmix_elem snd_sb16_ctl_line_capture_route =
555 SB16_INPUT_SW("Line Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 4, 3);
556 static struct sbmix_elem snd_sb16_ctl_line_play_switch =
557 SB_DOUBLE("Line Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1);
558 static struct sbmix_elem snd_sb16_ctl_line_play_vol =
559 SB_DOUBLE("Line Playback Volume", SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31);
560 static struct sbmix_elem snd_sb16_ctl_mic_capture_route =
561 SB16_INPUT_SW("Mic Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0);
562 static struct sbmix_elem snd_sb16_ctl_mic_play_switch =
563 SB_SINGLE("Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1);
564 static struct sbmix_elem snd_sb16_ctl_mic_play_vol =
565 SB_SINGLE("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31);
566 static struct sbmix_elem snd_sb16_ctl_pc_speaker_vol =
567 SB_SINGLE("PC Speaker Volume", SB_DSP4_SPEAKER_DEV, 6, 3);
568 static struct sbmix_elem snd_sb16_ctl_capture_vol =
569 SB_DOUBLE("Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3);
570 static struct sbmix_elem snd_sb16_ctl_play_vol =
571 SB_DOUBLE("Playback Volume", SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3);
572 static struct sbmix_elem snd_sb16_ctl_auto_mic_gain =
573 SB_SINGLE("Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1);
575 static struct sbmix_elem *snd_sb16_controls[] = {
576 &snd_sb16_ctl_master_play_vol,
577 &snd_sb16_ctl_3d_enhance_switch,
578 &snd_sb16_ctl_tone_bass,
579 &snd_sb16_ctl_tone_treble,
580 &snd_sb16_ctl_pcm_play_vol,
581 &snd_sb16_ctl_synth_capture_route,
582 &snd_sb16_ctl_synth_play_vol,
583 &snd_sb16_ctl_cd_capture_route,
584 &snd_sb16_ctl_cd_play_switch,
585 &snd_sb16_ctl_cd_play_vol,
586 &snd_sb16_ctl_line_capture_route,
587 &snd_sb16_ctl_line_play_switch,
588 &snd_sb16_ctl_line_play_vol,
589 &snd_sb16_ctl_mic_capture_route,
590 &snd_sb16_ctl_mic_play_switch,
591 &snd_sb16_ctl_mic_play_vol,
592 &snd_sb16_ctl_pc_speaker_vol,
593 &snd_sb16_ctl_capture_vol,
594 &snd_sb16_ctl_play_vol,
595 &snd_sb16_ctl_auto_mic_gain
598 static unsigned char snd_sb16_init_values[][2] = {
599 { SB_DSP4_MASTER_DEV + 0, 0 },
600 { SB_DSP4_MASTER_DEV + 1, 0 },
601 { SB_DSP4_PCM_DEV + 0, 0 },
602 { SB_DSP4_PCM_DEV + 1, 0 },
603 { SB_DSP4_SYNTH_DEV + 0, 0 },
604 { SB_DSP4_SYNTH_DEV + 1, 0 },
605 { SB_DSP4_INPUT_LEFT, 0 },
606 { SB_DSP4_INPUT_RIGHT, 0 },
607 { SB_DSP4_OUTPUT_SW, 0 },
608 { SB_DSP4_SPEAKER_DEV, 0 },
612 * DT019x specific mixer elements
614 static struct sbmix_elem snd_dt019x_ctl_master_play_vol =
615 SB_DOUBLE("Master Playback Volume", SB_DT019X_MASTER_DEV, SB_DT019X_MASTER_DEV, 4,0, 15);
616 static struct sbmix_elem snd_dt019x_ctl_pcm_play_vol =
617 SB_DOUBLE("PCM Playback Volume", SB_DT019X_PCM_DEV, SB_DT019X_PCM_DEV, 4,0, 15);
618 static struct sbmix_elem snd_dt019x_ctl_synth_play_vol =
619 SB_DOUBLE("Synth Playback Volume", SB_DT019X_SYNTH_DEV, SB_DT019X_SYNTH_DEV, 4,0, 15);
620 static struct sbmix_elem snd_dt019x_ctl_cd_play_vol =
621 SB_DOUBLE("CD Playback Volume", SB_DT019X_CD_DEV, SB_DT019X_CD_DEV, 4,0, 15);
622 static struct sbmix_elem snd_dt019x_ctl_mic_play_vol =
623 SB_SINGLE("Mic Playback Volume", SB_DT019X_MIC_DEV, 4, 7);
624 static struct sbmix_elem snd_dt019x_ctl_pc_speaker_vol =
625 SB_SINGLE("PC Speaker Volume", SB_DT019X_SPKR_DEV, 0, 7);
626 static struct sbmix_elem snd_dt019x_ctl_line_play_vol =
627 SB_DOUBLE("Line Playback Volume", SB_DT019X_LINE_DEV, SB_DT019X_LINE_DEV, 4,0, 15);
628 static struct sbmix_elem snd_dt019x_ctl_pcm_play_switch =
629 SB_DOUBLE("PCM Playback Switch", SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 2,1, 1);
630 static struct sbmix_elem snd_dt019x_ctl_synth_play_switch =
631 SB_DOUBLE("Synth Playback Switch", SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 4,3, 1);
632 static struct sbmix_elem snd_dt019x_ctl_capture_source =
634 .name = "Capture Source",
635 .type = SB_MIX_CAPTURE_DT019X
638 static struct sbmix_elem *snd_dt019x_controls[] = {
639 &snd_dt019x_ctl_master_play_vol,
640 &snd_dt019x_ctl_pcm_play_vol,
641 &snd_dt019x_ctl_synth_play_vol,
642 &snd_dt019x_ctl_cd_play_vol,
643 &snd_dt019x_ctl_mic_play_vol,
644 &snd_dt019x_ctl_pc_speaker_vol,
645 &snd_dt019x_ctl_line_play_vol,
646 &snd_sb16_ctl_mic_play_switch,
647 &snd_sb16_ctl_cd_play_switch,
648 &snd_sb16_ctl_line_play_switch,
649 &snd_dt019x_ctl_pcm_play_switch,
650 &snd_dt019x_ctl_synth_play_switch,
651 &snd_dt019x_ctl_capture_source
654 static unsigned char snd_dt019x_init_values[][2] = {
655 { SB_DT019X_MASTER_DEV, 0 },
656 { SB_DT019X_PCM_DEV, 0 },
657 { SB_DT019X_SYNTH_DEV, 0 },
658 { SB_DT019X_CD_DEV, 0 },
659 { SB_DT019X_MIC_DEV, 0 }, /* Includes PC-speaker in high nibble */
660 { SB_DT019X_LINE_DEV, 0 },
661 { SB_DSP4_OUTPUT_SW, 0 },
662 { SB_DT019X_OUTPUT_SW2, 0 },
663 { SB_DT019X_CAPTURE_SW, 0x06 },
667 * ALS4000 specific mixer elements
669 /* FIXME: SB_ALS4000_MONO_IO_CTRL needs output select ctrl! */
670 static struct sbmix_elem snd_als4000_ctl_master_mono_playback_switch =
671 SB_SINGLE("Master Mono Playback Switch", SB_ALS4000_MONO_IO_CTRL, 5, 1);
672 static struct sbmix_elem snd_als4000_ctl_master_mono_capture_route =
673 SB_SINGLE("Master Mono Capture Route", SB_ALS4000_MONO_IO_CTRL, 6, 0x03);
674 /* FIXME: mono playback switch also available on DT019X? */
675 static struct sbmix_elem snd_als4000_ctl_mono_playback_switch =
676 SB_SINGLE("Mono Playback Switch", SB_DT019X_OUTPUT_SW2, 0, 1);
677 static struct sbmix_elem snd_als4000_ctl_mic_20db_boost =
678 SB_SINGLE("Mic Boost (+20dB)", SB_ALS4000_MIC_IN_GAIN, 0, 0x03);
679 static struct sbmix_elem snd_als4000_ctl_mixer_loopback =
680 SB_SINGLE("Analog Loopback", SB_ALS4000_MIC_IN_GAIN, 7, 0x01);
681 /* FIXME: functionality of 3D controls might be swapped, I didn't find
682 * a description of how to identify what is supposed to be what */
683 static struct sbmix_elem snd_als4000_3d_control_switch =
684 SB_SINGLE("3D Control - Switch", SB_ALS4000_3D_SND_FX, 6, 0x01);
685 static struct sbmix_elem snd_als4000_3d_control_ratio =
686 SB_SINGLE("3D Control - Level", SB_ALS4000_3D_SND_FX, 0, 0x07);
687 static struct sbmix_elem snd_als4000_3d_control_freq =
688 /* FIXME: maybe there's actually some standard 3D ctrl name for it?? */
689 SB_SINGLE("3D Control - Freq", SB_ALS4000_3D_SND_FX, 4, 0x03);
690 static struct sbmix_elem snd_als4000_3d_control_delay =
691 /* FIXME: ALS4000a.pdf mentions BBD (Bucket Brigade Device) time delay,
692 * but what ALSA 3D attribute is that actually? "Center", "Depth",
693 * "Wide" or "Space" or even "Level"? Assuming "Wide" for now... */
694 SB_SINGLE("3D Control - Wide", SB_ALS4000_3D_TIME_DELAY, 0, 0x0f);
695 static struct sbmix_elem snd_als4000_3d_control_poweroff_switch =
696 SB_SINGLE("3D PowerOff Switch", SB_ALS4000_3D_TIME_DELAY, 4, 0x01);
697 #ifdef NOT_AVAILABLE
698 static struct sbmix_elem snd_als4000_ctl_fmdac =
699 SB_SINGLE("FMDAC Switch (Option ?)", SB_ALS4000_FMDAC, 0, 0x01);
700 static struct sbmix_elem snd_als4000_ctl_qsound =
701 SB_SINGLE("QSound Mode", SB_ALS4000_QSOUND, 1, 0x1f);
702 #endif
704 static struct sbmix_elem *snd_als4000_controls[] = {
705 &snd_sb16_ctl_master_play_vol,
706 &snd_dt019x_ctl_pcm_play_switch,
707 &snd_sb16_ctl_pcm_play_vol,
708 &snd_sb16_ctl_synth_capture_route,
709 &snd_dt019x_ctl_synth_play_switch,
710 &snd_sb16_ctl_synth_play_vol,
711 &snd_sb16_ctl_cd_capture_route,
712 &snd_sb16_ctl_cd_play_switch,
713 &snd_sb16_ctl_cd_play_vol,
714 &snd_sb16_ctl_line_capture_route,
715 &snd_sb16_ctl_line_play_switch,
716 &snd_sb16_ctl_line_play_vol,
717 &snd_sb16_ctl_mic_capture_route,
718 &snd_als4000_ctl_mic_20db_boost,
719 &snd_sb16_ctl_auto_mic_gain,
720 &snd_sb16_ctl_mic_play_switch,
721 &snd_sb16_ctl_mic_play_vol,
722 &snd_sb16_ctl_pc_speaker_vol,
723 &snd_sb16_ctl_capture_vol,
724 &snd_sb16_ctl_play_vol,
725 &snd_als4000_ctl_master_mono_playback_switch,
726 &snd_als4000_ctl_master_mono_capture_route,
727 &snd_als4000_ctl_mono_playback_switch,
728 &snd_als4000_ctl_mixer_loopback,
729 &snd_als4000_3d_control_switch,
730 &snd_als4000_3d_control_ratio,
731 &snd_als4000_3d_control_freq,
732 &snd_als4000_3d_control_delay,
733 &snd_als4000_3d_control_poweroff_switch,
734 #ifdef NOT_AVAILABLE
735 &snd_als4000_ctl_fmdac,
736 &snd_als4000_ctl_qsound,
737 #endif
740 static unsigned char snd_als4000_init_values[][2] = {
741 { SB_DSP4_MASTER_DEV + 0, 0 },
742 { SB_DSP4_MASTER_DEV + 1, 0 },
743 { SB_DSP4_PCM_DEV + 0, 0 },
744 { SB_DSP4_PCM_DEV + 1, 0 },
745 { SB_DSP4_SYNTH_DEV + 0, 0 },
746 { SB_DSP4_SYNTH_DEV + 1, 0 },
747 { SB_DSP4_SPEAKER_DEV, 0 },
748 { SB_DSP4_OUTPUT_SW, 0 },
749 { SB_DSP4_INPUT_LEFT, 0 },
750 { SB_DSP4_INPUT_RIGHT, 0 },
751 { SB_DT019X_OUTPUT_SW2, 0 },
752 { SB_ALS4000_MIC_IN_GAIN, 0 },
758 static int snd_sbmixer_init(struct snd_sb *chip,
759 struct sbmix_elem **controls,
760 int controls_count,
761 unsigned char map[][2],
762 int map_count,
763 char *name)
765 unsigned long flags;
766 struct snd_card *card = chip->card;
767 int idx, err;
769 /* mixer reset */
770 spin_lock_irqsave(&chip->mixer_lock, flags);
771 snd_sbmixer_write(chip, 0x00, 0x00);
772 spin_unlock_irqrestore(&chip->mixer_lock, flags);
774 /* mute and zero volume channels */
775 for (idx = 0; idx < map_count; idx++) {
776 spin_lock_irqsave(&chip->mixer_lock, flags);
777 snd_sbmixer_write(chip, map[idx][0], map[idx][1]);
778 spin_unlock_irqrestore(&chip->mixer_lock, flags);
781 for (idx = 0; idx < controls_count; idx++) {
782 if ((err = snd_sbmixer_add_ctl_elem(chip, controls[idx])) < 0)
783 return err;
785 snd_component_add(card, name);
786 strcpy(card->mixername, name);
787 return 0;
790 int snd_sbmixer_new(struct snd_sb *chip)
792 struct snd_card *card;
793 int err;
795 snd_assert(chip != NULL && chip->card != NULL, return -EINVAL);
797 card = chip->card;
799 switch (chip->hardware) {
800 case SB_HW_10:
801 return 0; /* no mixer chip on SB1.x */
802 case SB_HW_20:
803 case SB_HW_201:
804 if ((err = snd_sbmixer_init(chip,
805 snd_sb20_controls,
806 ARRAY_SIZE(snd_sb20_controls),
807 snd_sb20_init_values,
808 ARRAY_SIZE(snd_sb20_init_values),
809 "CTL1335")) < 0)
810 return err;
811 break;
812 case SB_HW_PRO:
813 if ((err = snd_sbmixer_init(chip,
814 snd_sbpro_controls,
815 ARRAY_SIZE(snd_sbpro_controls),
816 snd_sbpro_init_values,
817 ARRAY_SIZE(snd_sbpro_init_values),
818 "CTL1345")) < 0)
819 return err;
820 break;
821 case SB_HW_16:
822 case SB_HW_ALS100:
823 case SB_HW_CS5530:
824 if ((err = snd_sbmixer_init(chip,
825 snd_sb16_controls,
826 ARRAY_SIZE(snd_sb16_controls),
827 snd_sb16_init_values,
828 ARRAY_SIZE(snd_sb16_init_values),
829 "CTL1745")) < 0)
830 return err;
831 break;
832 case SB_HW_ALS4000:
833 if ((err = snd_sbmixer_init(chip,
834 snd_als4000_controls,
835 ARRAY_SIZE(snd_als4000_controls),
836 snd_als4000_init_values,
837 ARRAY_SIZE(snd_als4000_init_values),
838 "ALS4000")) < 0)
839 return err;
840 break;
841 case SB_HW_DT019X:
842 if ((err = snd_sbmixer_init(chip,
843 snd_dt019x_controls,
844 ARRAY_SIZE(snd_dt019x_controls),
845 snd_dt019x_init_values,
846 ARRAY_SIZE(snd_dt019x_init_values),
847 "DT019X")) < 0)
848 break;
849 default:
850 strcpy(card->mixername, "???");
852 return 0;
855 #ifdef CONFIG_PM
856 static unsigned char sb20_saved_regs[] = {
857 SB_DSP20_MASTER_DEV,
858 SB_DSP20_PCM_DEV,
859 SB_DSP20_FM_DEV,
860 SB_DSP20_CD_DEV,
863 static unsigned char sbpro_saved_regs[] = {
864 SB_DSP_MASTER_DEV,
865 SB_DSP_PCM_DEV,
866 SB_DSP_PLAYBACK_FILT,
867 SB_DSP_FM_DEV,
868 SB_DSP_CD_DEV,
869 SB_DSP_LINE_DEV,
870 SB_DSP_MIC_DEV,
871 SB_DSP_CAPTURE_SOURCE,
872 SB_DSP_CAPTURE_FILT,
875 static unsigned char sb16_saved_regs[] = {
876 SB_DSP4_MASTER_DEV, SB_DSP4_MASTER_DEV + 1,
877 SB_DSP4_3DSE,
878 SB_DSP4_BASS_DEV, SB_DSP4_BASS_DEV + 1,
879 SB_DSP4_TREBLE_DEV, SB_DSP4_TREBLE_DEV + 1,
880 SB_DSP4_PCM_DEV, SB_DSP4_PCM_DEV + 1,
881 SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT,
882 SB_DSP4_SYNTH_DEV, SB_DSP4_SYNTH_DEV + 1,
883 SB_DSP4_OUTPUT_SW,
884 SB_DSP4_CD_DEV, SB_DSP4_CD_DEV + 1,
885 SB_DSP4_LINE_DEV, SB_DSP4_LINE_DEV + 1,
886 SB_DSP4_MIC_DEV,
887 SB_DSP4_SPEAKER_DEV,
888 SB_DSP4_IGAIN_DEV, SB_DSP4_IGAIN_DEV + 1,
889 SB_DSP4_OGAIN_DEV, SB_DSP4_OGAIN_DEV + 1,
890 SB_DSP4_MIC_AGC
893 static unsigned char dt019x_saved_regs[] = {
894 SB_DT019X_MASTER_DEV,
895 SB_DT019X_PCM_DEV,
896 SB_DT019X_SYNTH_DEV,
897 SB_DT019X_CD_DEV,
898 SB_DT019X_MIC_DEV,
899 SB_DT019X_SPKR_DEV,
900 SB_DT019X_LINE_DEV,
901 SB_DSP4_OUTPUT_SW,
902 SB_DT019X_OUTPUT_SW2,
903 SB_DT019X_CAPTURE_SW,
906 static unsigned char als4000_saved_regs[] = {
907 SB_DSP4_MASTER_DEV, SB_DSP4_MASTER_DEV + 1,
908 SB_DSP4_OUTPUT_SW,
909 SB_DSP4_PCM_DEV, SB_DSP4_PCM_DEV + 1,
910 SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT,
911 SB_DSP4_SYNTH_DEV, SB_DSP4_SYNTH_DEV + 1,
912 SB_DSP4_CD_DEV, SB_DSP4_CD_DEV + 1,
913 SB_DSP4_MIC_AGC,
914 SB_DSP4_MIC_DEV,
915 SB_DSP4_SPEAKER_DEV,
916 SB_DSP4_IGAIN_DEV, SB_DSP4_IGAIN_DEV + 1,
917 SB_DSP4_OGAIN_DEV, SB_DSP4_OGAIN_DEV + 1,
918 SB_DT019X_OUTPUT_SW2,
919 SB_ALS4000_MONO_IO_CTRL,
920 SB_ALS4000_MIC_IN_GAIN,
921 SB_ALS4000_3D_SND_FX,
922 SB_ALS4000_3D_TIME_DELAY,
925 static void save_mixer(struct snd_sb *chip, unsigned char *regs, int num_regs)
927 unsigned char *val = chip->saved_regs;
928 snd_assert(num_regs > ARRAY_SIZE(chip->saved_regs), return);
929 for (; num_regs; num_regs--)
930 *val++ = snd_sbmixer_read(chip, *regs++);
933 static void restore_mixer(struct snd_sb *chip, unsigned char *regs, int num_regs)
935 unsigned char *val = chip->saved_regs;
936 snd_assert(num_regs > ARRAY_SIZE(chip->saved_regs), return);
937 for (; num_regs; num_regs--)
938 snd_sbmixer_write(chip, *regs++, *val++);
941 void snd_sbmixer_suspend(struct snd_sb *chip)
943 switch (chip->hardware) {
944 case SB_HW_20:
945 case SB_HW_201:
946 save_mixer(chip, sb20_saved_regs, ARRAY_SIZE(sb20_saved_regs));
947 break;
948 case SB_HW_PRO:
949 save_mixer(chip, sbpro_saved_regs, ARRAY_SIZE(sbpro_saved_regs));
950 break;
951 case SB_HW_16:
952 case SB_HW_ALS100:
953 case SB_HW_CS5530:
954 save_mixer(chip, sb16_saved_regs, ARRAY_SIZE(sb16_saved_regs));
955 break;
956 case SB_HW_ALS4000:
957 save_mixer(chip, als4000_saved_regs, ARRAY_SIZE(als4000_saved_regs));
958 break;
959 case SB_HW_DT019X:
960 save_mixer(chip, dt019x_saved_regs, ARRAY_SIZE(dt019x_saved_regs));
961 break;
962 default:
963 break;
967 void snd_sbmixer_resume(struct snd_sb *chip)
969 switch (chip->hardware) {
970 case SB_HW_20:
971 case SB_HW_201:
972 restore_mixer(chip, sb20_saved_regs, ARRAY_SIZE(sb20_saved_regs));
973 break;
974 case SB_HW_PRO:
975 restore_mixer(chip, sbpro_saved_regs, ARRAY_SIZE(sbpro_saved_regs));
976 break;
977 case SB_HW_16:
978 case SB_HW_ALS100:
979 case SB_HW_CS5530:
980 restore_mixer(chip, sb16_saved_regs, ARRAY_SIZE(sb16_saved_regs));
981 break;
982 case SB_HW_ALS4000:
983 restore_mixer(chip, als4000_saved_regs, ARRAY_SIZE(als4000_saved_regs));
984 break;
985 case SB_HW_DT019X:
986 restore_mixer(chip, dt019x_saved_regs, ARRAY_SIZE(dt019x_saved_regs));
987 break;
988 default:
989 break;
992 #endif