blob: 91d14224f6b332de1119d89bc07bff76c00f37cc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02002 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Routines for Sound Blaster mixer control
4 *
5 *
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.
10 *
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.
15 *
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
19 *
20 */
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#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>
28
29#undef IO_DEBUG
30
Takashi Iwai029d64b2005-11-17 14:34:36 +010031void snd_sbmixer_write(struct snd_sb *chip, unsigned char reg, unsigned char data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
33 outb(reg, SBP(chip, MIXER_ADDR));
34 udelay(10);
35 outb(data, SBP(chip, MIXER_DATA));
36 udelay(10);
37#ifdef IO_DEBUG
Takashi Iwai99b359b2005-10-20 18:26:44 +020038 snd_printk(KERN_DEBUG "mixer_write 0x%x 0x%x\n", reg, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#endif
40}
41
Takashi Iwai029d64b2005-11-17 14:34:36 +010042unsigned char snd_sbmixer_read(struct snd_sb *chip, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
44 unsigned char result;
45
46 outb(reg, SBP(chip, MIXER_ADDR));
47 udelay(10);
48 result = inb(SBP(chip, MIXER_DATA));
49 udelay(10);
50#ifdef IO_DEBUG
Takashi Iwai99b359b2005-10-20 18:26:44 +020051 snd_printk(KERN_DEBUG "mixer_read 0x%x 0x%x\n", reg, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#endif
53 return result;
54}
55
56/*
57 * Single channel mixer element
58 */
59
Takashi Iwai029d64b2005-11-17 14:34:36 +010060static int snd_sbmixer_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
62 int mask = (kcontrol->private_value >> 24) & 0xff;
63
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;
69}
70
Takashi Iwai029d64b2005-11-17 14:34:36 +010071static int snd_sbmixer_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
Takashi Iwai029d64b2005-11-17 14:34:36 +010073 struct snd_sb *sb = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 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;
79
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;
85}
86
Takashi Iwai029d64b2005-11-17 14:34:36 +010087static int snd_sbmixer_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
Takashi Iwai029d64b2005-11-17 14:34:36 +010089 struct snd_sb *sb = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 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;
96
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;
106}
107
108/*
109 * Double channel mixer element
110 */
111
Takashi Iwai029d64b2005-11-17 14:34:36 +0100112static int snd_sbmixer_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
114 int mask = (kcontrol->private_value >> 24) & 0xff;
115
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;
121}
122
Takashi Iwai029d64b2005-11-17 14:34:36 +0100123static int snd_sbmixer_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Takashi Iwai029d64b2005-11-17 14:34:36 +0100125 struct snd_sb *sb = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 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;
133
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;
141}
142
Takashi Iwai029d64b2005-11-17 14:34:36 +0100143static int snd_sbmixer_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
Takashi Iwai029d64b2005-11-17 14:34:36 +0100145 struct snd_sb *sb = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 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;
154
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);
173 }
174 }
175 spin_unlock_irqrestore(&sb->mixer_lock, flags);
176 return change;
177}
178
179/*
180 * DT-019x / ALS-007 capture/input switch
181 */
182
Takashi Iwai029d64b2005-11-17 14:34:36 +0100183static int snd_dt019x_input_sw_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
185 static char *texts[5] = {
186 "CD", "Mic", "Line", "Synth", "Master"
187 };
188
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;
196}
197
Takashi Iwai029d64b2005-11-17 14:34:36 +0100198static int snd_dt019x_input_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
Takashi Iwai029d64b2005-11-17 14:34:36 +0100200 struct snd_sb *sb = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 unsigned long flags;
202 unsigned char oval;
203
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;
226 */
227 default:
228 ucontrol->value.enumerated.item[0] = 4;
229 break;
230 }
231 return 0;
232}
233
Takashi Iwai029d64b2005-11-17 14:34:36 +0100234static int snd_dt019x_input_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235{
Takashi Iwai029d64b2005-11-17 14:34:36 +0100236 struct snd_sb *sb = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 unsigned long flags;
238 int change;
239 unsigned char nval, oval;
240
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;
261 }
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;
269}
270
271/*
272 * SBPRO input multiplexer
273 */
274
Takashi Iwai029d64b2005-11-17 14:34:36 +0100275static int snd_sb8mixer_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
277 static char *texts[3] = {
278 "Mic", "CD", "Line"
279 };
280
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;
288}
289
290
Takashi Iwai029d64b2005-11-17 14:34:36 +0100291static int snd_sb8mixer_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
Takashi Iwai029d64b2005-11-17 14:34:36 +0100293 struct snd_sb *sb = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 unsigned long flags;
295 unsigned char oval;
296
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;
310 }
311 return 0;
312}
313
Takashi Iwai029d64b2005-11-17 14:34:36 +0100314static int snd_sb8mixer_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
Takashi Iwai029d64b2005-11-17 14:34:36 +0100316 struct snd_sb *sb = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 unsigned long flags;
318 int change;
319 unsigned char nval, oval;
320
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;
332 }
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;
342}
343
344/*
345 * SB16 input switch
346 */
347
Takashi Iwai029d64b2005-11-17 14:34:36 +0100348static int snd_sb16mixer_info_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
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;
355}
356
Takashi Iwai029d64b2005-11-17 14:34:36 +0100357static int snd_sb16mixer_get_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
Takashi Iwai029d64b2005-11-17 14:34:36 +0100359 struct snd_sb *sb = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 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;
366
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;
376}
377
Takashi Iwai029d64b2005-11-17 14:34:36 +0100378static int snd_sb16mixer_put_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
Takashi Iwai029d64b2005-11-17 14:34:36 +0100380 struct snd_sb *sb = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 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;
388
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);
402 }
403 spin_unlock_irqrestore(&sb->mixer_lock, flags);
404 return change;
405}
406
407
408/*
409 */
410/*
411 */
Takashi Iwai029d64b2005-11-17 14:34:36 +0100412int snd_sbmixer_add_ctl(struct snd_sb *chip, const char *name, int index, int type, unsigned long value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
Takashi Iwai029d64b2005-11-17 14:34:36 +0100414 static struct snd_kcontrol_new newctls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 [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,
420 },
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,
426 },
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,
432 },
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,
438 },
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,
444 },
445 };
Takashi Iwai029d64b2005-11-17 14:34:36 +0100446 struct snd_kcontrol *ctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 int err;
448
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;
Dave Jonesbcc54f92006-03-06 13:28:34 +0100455 if ((err = snd_ctl_add(chip->card, ctl)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 return 0;
458}
459
460/*
461 * SB 2.0 specific mixer elements
462 */
463
464static struct sbmix_elem snd_sb20_ctl_master_play_vol =
465 SB_SINGLE("Master Playback Volume", SB_DSP20_MASTER_DEV, 1, 7);
466static struct sbmix_elem snd_sb20_ctl_pcm_play_vol =
467 SB_SINGLE("PCM Playback Volume", SB_DSP20_PCM_DEV, 1, 3);
468static struct sbmix_elem snd_sb20_ctl_synth_play_vol =
469 SB_SINGLE("Synth Playback Volume", SB_DSP20_FM_DEV, 1, 7);
470static struct sbmix_elem snd_sb20_ctl_cd_play_vol =
471 SB_SINGLE("CD Playback Volume", SB_DSP20_CD_DEV, 1, 7);
472
473static 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
478};
479
480static unsigned char snd_sb20_init_values[][2] = {
481 { SB_DSP20_MASTER_DEV, 0 },
482 { SB_DSP20_FM_DEV, 0 },
483};
484
485/*
486 * SB Pro specific mixer elements
487 */
488static 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);
490static 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);
492static struct sbmix_elem snd_sbpro_ctl_pcm_play_filter =
493 SB_SINGLE("PCM Playback Filter", SB_DSP_PLAYBACK_FILT, 5, 1);
494static 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);
496static 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);
498static 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);
500static struct sbmix_elem snd_sbpro_ctl_mic_play_vol =
501 SB_SINGLE("Mic Playback Volume", SB_DSP_MIC_DEV, 1, 3);
502static struct sbmix_elem snd_sbpro_ctl_capture_source =
503 {
504 .name = "Capture Source",
505 .type = SB_MIX_CAPTURE_PRO
506 };
507static struct sbmix_elem snd_sbpro_ctl_capture_filter =
508 SB_SINGLE("Capture Filter", SB_DSP_CAPTURE_FILT, 5, 1);
509static struct sbmix_elem snd_sbpro_ctl_capture_low_filter =
510 SB_SINGLE("Capture Low-Pass Filter", SB_DSP_CAPTURE_FILT, 3, 1);
511
512static 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
523};
524
525static 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 },
529};
530
531/*
532 * SB16 specific mixer elements
533 */
534static 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);
536static struct sbmix_elem snd_sb16_ctl_3d_enhance_switch =
537 SB_SINGLE("3D Enhancement Switch", SB_DSP4_3DSE, 0, 1);
538static 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);
540static 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);
542static 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);
544static 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);
546static 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);
548static 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);
550static 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);
552static 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);
554static 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);
556static 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);
558static 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);
560static 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);
562static struct sbmix_elem snd_sb16_ctl_mic_play_switch =
563 SB_SINGLE("Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1);
564static struct sbmix_elem snd_sb16_ctl_mic_play_vol =
565 SB_SINGLE("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31);
566static struct sbmix_elem snd_sb16_ctl_pc_speaker_vol =
567 SB_SINGLE("PC Speaker Volume", SB_DSP4_SPEAKER_DEV, 6, 3);
568static 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);
570static 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);
572static struct sbmix_elem snd_sb16_ctl_auto_mic_gain =
573 SB_SINGLE("Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1);
574
575static 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
596};
597
598static 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 },
609};
610
611/*
612 * DT019x specific mixer elements
613 */
614static 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);
616static 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);
618static 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);
620static 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);
622static struct sbmix_elem snd_dt019x_ctl_mic_play_vol =
623 SB_SINGLE("Mic Playback Volume", SB_DT019X_MIC_DEV, 4, 7);
624static struct sbmix_elem snd_dt019x_ctl_pc_speaker_vol =
625 SB_SINGLE("PC Speaker Volume", SB_DT019X_SPKR_DEV, 0, 7);
626static 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);
628static 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);
630static 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);
632static struct sbmix_elem snd_dt019x_ctl_capture_source =
633 {
634 .name = "Capture Source",
635 .type = SB_MIX_CAPTURE_DT019X
636 };
637
638static 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
652};
653
654static 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 },
664};
665
666/*
667 * ALS4000 specific mixer elements
668 */
Andreas Mohrba7301c2005-11-17 11:03:31 +0100669/* FIXME: SB_ALS4000_MONO_IO_CTRL needs output select ctrl! */
670static struct sbmix_elem snd_als4000_ctl_master_mono_playback_switch =
671 SB_SINGLE("Master Mono Playback Switch", SB_ALS4000_MONO_IO_CTRL, 5, 1);
672static 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? */
675static struct sbmix_elem snd_als4000_ctl_mono_playback_switch =
676 SB_SINGLE("Mono Playback Switch", SB_DT019X_OUTPUT_SW2, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677static struct sbmix_elem snd_als4000_ctl_mic_20db_boost =
678 SB_SINGLE("Mic Boost (+20dB)", SB_ALS4000_MIC_IN_GAIN, 0, 0x03);
Andreas Mohrba7301c2005-11-17 11:03:31 +0100679static 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 */
683static struct sbmix_elem snd_als4000_3d_control_switch =
684 SB_SINGLE("3D Control - Switch", SB_ALS4000_3D_SND_FX, 6, 0x01);
685static struct sbmix_elem snd_als4000_3d_control_ratio =
686 SB_SINGLE("3D Control - Level", SB_ALS4000_3D_SND_FX, 0, 0x07);
687static 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);
690static 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);
695static struct sbmix_elem snd_als4000_3d_control_poweroff_switch =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 SB_SINGLE("3D PowerOff Switch", SB_ALS4000_3D_TIME_DELAY, 4, 0x01);
Olaf Hering44456d32005-07-27 11:45:17 -0700697#ifdef NOT_AVAILABLE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698static struct sbmix_elem snd_als4000_ctl_fmdac =
699 SB_SINGLE("FMDAC Switch (Option ?)", SB_ALS4000_FMDAC, 0, 0x01);
700static struct sbmix_elem snd_als4000_ctl_qsound =
701 SB_SINGLE("QSound Mode", SB_ALS4000_QSOUND, 1, 0x1f);
702#endif
703
704static 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,
Andreas Mohrba7301c2005-11-17 11:03:31 +0100725 &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,
Olaf Hering44456d32005-07-27 11:45:17 -0700734#ifdef NOT_AVAILABLE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 &snd_als4000_ctl_fmdac,
736 &snd_als4000_ctl_qsound,
737#endif
738};
739
740static 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 },
753};
754
755
756/*
757 */
Takashi Iwai029d64b2005-11-17 14:34:36 +0100758static int snd_sbmixer_init(struct snd_sb *chip,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 struct sbmix_elem **controls,
760 int controls_count,
761 unsigned char map[][2],
762 int map_count,
763 char *name)
764{
765 unsigned long flags;
Takashi Iwai029d64b2005-11-17 14:34:36 +0100766 struct snd_card *card = chip->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 int idx, err;
768
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);
773
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);
779 }
780
781 for (idx = 0; idx < controls_count; idx++) {
782 if ((err = snd_sbmixer_add_ctl_elem(chip, controls[idx])) < 0)
783 return err;
784 }
785 snd_component_add(card, name);
786 strcpy(card->mixername, name);
787 return 0;
788}
789
Takashi Iwai029d64b2005-11-17 14:34:36 +0100790int snd_sbmixer_new(struct snd_sb *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791{
Takashi Iwai029d64b2005-11-17 14:34:36 +0100792 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 int err;
794
795 snd_assert(chip != NULL && chip->card != NULL, return -EINVAL);
796
797 card = chip->card;
798
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:
Takashi Iwai621887a2007-05-24 18:46:54 +0200823 case SB_HW_CS5530:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 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, "???");
851 }
852 return 0;
853}
Takashi Iwai5bdb6a12005-11-17 16:16:10 +0100854
855#ifdef CONFIG_PM
856static 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,
861};
862
863static 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,
873};
874
875static 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
891};
892
893static 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,
904};
905
906static 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,
923};
924
925static void save_mixer(struct snd_sb *chip, unsigned char *regs, int num_regs)
926{
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++);
931}
932
933static void restore_mixer(struct snd_sb *chip, unsigned char *regs, int num_regs)
934{
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++);
939}
940
941void snd_sbmixer_suspend(struct snd_sb *chip)
942{
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:
Takashi Iwai621887a2007-05-24 18:46:54 +0200953 case SB_HW_CS5530:
Takashi Iwai5bdb6a12005-11-17 16:16:10 +0100954 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;
964 }
965}
966
967void snd_sbmixer_resume(struct snd_sb *chip)
968{
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:
Takashi Iwai621887a2007-05-24 18:46:54 +0200979 case SB_HW_CS5530:
Takashi Iwai5bdb6a12005-11-17 16:16:10 +0100980 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;
990 }
991}
992#endif