[ALSA] oxygen: rename PCM to Master
[wrt350n-kernel.git] / sound / pci / oxygen / oxygen_mixer.c
blobaa3a5c53d6055d7f54180c6cba9bb8240229b821
1 /*
2 * C-Media CMI8788 driver - mixer code
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2.
10 * This driver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this driver; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/mutex.h>
21 #include <sound/ac97_codec.h>
22 #include <sound/asoundef.h>
23 #include <sound/control.h>
24 #include <sound/tlv.h>
25 #include "oxygen.h"
27 static int dac_volume_info(struct snd_kcontrol *ctl,
28 struct snd_ctl_elem_info *info)
30 struct oxygen *chip = ctl->private_data;
32 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
33 info->count = 8;
34 info->value.integer.min = chip->model->dac_minimum_volume;
35 info->value.integer.max = 0xff;
36 return 0;
39 static int dac_volume_get(struct snd_kcontrol *ctl,
40 struct snd_ctl_elem_value *value)
42 struct oxygen *chip = ctl->private_data;
43 unsigned int i;
45 mutex_lock(&chip->mutex);
46 for (i = 0; i < 8; ++i)
47 value->value.integer.value[i] = chip->dac_volume[i];
48 mutex_unlock(&chip->mutex);
49 return 0;
52 static int dac_volume_put(struct snd_kcontrol *ctl,
53 struct snd_ctl_elem_value *value)
55 struct oxygen *chip = ctl->private_data;
56 unsigned int i;
57 int changed;
59 changed = 0;
60 mutex_lock(&chip->mutex);
61 for (i = 0; i < 8; ++i)
62 if (value->value.integer.value[i] != chip->dac_volume[i]) {
63 chip->dac_volume[i] = value->value.integer.value[i];
64 changed = 1;
66 if (changed)
67 chip->model->update_dac_volume(chip);
68 mutex_unlock(&chip->mutex);
69 return changed;
72 static int dac_mute_get(struct snd_kcontrol *ctl,
73 struct snd_ctl_elem_value *value)
75 struct oxygen *chip = ctl->private_data;
77 mutex_lock(&chip->mutex);
78 value->value.integer.value[0] = !chip->dac_mute;
79 mutex_unlock(&chip->mutex);
80 return 0;
83 static int dac_mute_put(struct snd_kcontrol *ctl,
84 struct snd_ctl_elem_value *value)
86 struct oxygen *chip = ctl->private_data;
87 int changed;
89 mutex_lock(&chip->mutex);
90 changed = !value->value.integer.value[0] != chip->dac_mute;
91 if (changed) {
92 chip->dac_mute = !value->value.integer.value[0];
93 chip->model->update_dac_mute(chip);
95 mutex_unlock(&chip->mutex);
96 return changed;
99 static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
101 static const char *const names[3] = {
102 "Front", "Front+Surround", "Front+Surround+Back"
104 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
105 info->count = 1;
106 info->value.enumerated.items = 3;
107 if (info->value.enumerated.item > 2)
108 info->value.enumerated.item = 2;
109 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
110 return 0;
113 static int upmix_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
115 struct oxygen *chip = ctl->private_data;
117 mutex_lock(&chip->mutex);
118 value->value.enumerated.item[0] = chip->dac_routing;
119 mutex_unlock(&chip->mutex);
120 return 0;
123 void oxygen_update_dac_routing(struct oxygen *chip)
125 static const unsigned int reg_values[3] = {
126 0xe100, /* front <- 0, surround <- 1, center <- 2, back <- 3 */
127 0xe000, /* front <- 0, surround <- 0, center <- 2, back <- 3 */
128 0x2000 /* front <- 0, surround <- 0, center <- 2, back <- 0 */
130 u8 channels;
131 unsigned int reg_value;
133 channels = oxygen_read8(chip, OXYGEN_PLAY_CHANNELS) &
134 OXYGEN_PLAY_CHANNELS_MASK;
135 if (channels == OXYGEN_PLAY_CHANNELS_2)
136 reg_value = reg_values[chip->dac_routing];
137 else if (channels == OXYGEN_PLAY_CHANNELS_8)
138 reg_value = 0x6c00; /* surround <- 3, back <- 1 */
139 else
140 reg_value = 0xe100;
141 oxygen_write16_masked(chip, OXYGEN_PLAY_ROUTING, reg_value, 0xff00);
144 static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
146 struct oxygen *chip = ctl->private_data;
147 int changed;
149 mutex_lock(&chip->mutex);
150 changed = value->value.enumerated.item[0] != chip->dac_routing;
151 if (changed) {
152 chip->dac_routing = min(value->value.enumerated.item[0], 2u);
153 spin_lock_irq(&chip->reg_lock);
154 oxygen_update_dac_routing(chip);
155 spin_unlock_irq(&chip->reg_lock);
157 mutex_unlock(&chip->mutex);
158 return changed;
161 static int spdif_switch_get(struct snd_kcontrol *ctl,
162 struct snd_ctl_elem_value *value)
164 struct oxygen *chip = ctl->private_data;
166 mutex_lock(&chip->mutex);
167 value->value.integer.value[0] = chip->spdif_playback_enable;
168 mutex_unlock(&chip->mutex);
169 return 0;
172 static unsigned int oxygen_spdif_rate(unsigned int oxygen_rate)
174 switch (oxygen_rate) {
175 case OXYGEN_RATE_32000:
176 return IEC958_AES3_CON_FS_32000 << OXYGEN_SPDIF_CS_RATE_SHIFT;
177 case OXYGEN_RATE_44100:
178 return IEC958_AES3_CON_FS_44100 << OXYGEN_SPDIF_CS_RATE_SHIFT;
179 default: /* OXYGEN_RATE_48000 */
180 return IEC958_AES3_CON_FS_48000 << OXYGEN_SPDIF_CS_RATE_SHIFT;
181 case OXYGEN_RATE_64000:
182 return 0xb << OXYGEN_SPDIF_CS_RATE_SHIFT;
183 case OXYGEN_RATE_88200:
184 return 0x8 << OXYGEN_SPDIF_CS_RATE_SHIFT;
185 case OXYGEN_RATE_96000:
186 return 0xa << OXYGEN_SPDIF_CS_RATE_SHIFT;
187 case OXYGEN_RATE_176400:
188 return 0xc << OXYGEN_SPDIF_CS_RATE_SHIFT;
189 case OXYGEN_RATE_192000:
190 return 0xe << OXYGEN_SPDIF_CS_RATE_SHIFT;
194 void oxygen_update_spdif_source(struct oxygen *chip)
196 u32 old_control, new_control;
197 u16 old_routing, new_routing;
198 unsigned int oxygen_rate;
200 old_control = oxygen_read32(chip, OXYGEN_SPDIF_CONTROL);
201 old_routing = oxygen_read16(chip, OXYGEN_PLAY_ROUTING);
202 if (chip->pcm_active & (1 << PCM_SPDIF)) {
203 new_control = old_control | OXYGEN_SPDIF_OUT_ENABLE;
204 new_routing = (old_routing & ~0x00e0) | 0x0000;
205 oxygen_rate = (old_control >> OXYGEN_SPDIF_OUT_RATE_SHIFT)
206 & OXYGEN_I2S_RATE_MASK;
207 /* S/PDIF rate was already set by the caller */
208 } else if ((chip->pcm_active & (1 << PCM_MULTICH)) &&
209 chip->spdif_playback_enable) {
210 new_routing = (old_routing & ~0x00e0) | 0x0020;
211 oxygen_rate = oxygen_read16(chip, OXYGEN_I2S_MULTICH_FORMAT)
212 & OXYGEN_I2S_RATE_MASK;
213 new_control = (old_control & ~OXYGEN_SPDIF_OUT_RATE_MASK) |
214 (oxygen_rate << OXYGEN_SPDIF_OUT_RATE_SHIFT) |
215 OXYGEN_SPDIF_OUT_ENABLE;
216 } else {
217 new_control = old_control & ~OXYGEN_SPDIF_OUT_ENABLE;
218 new_routing = old_routing;
219 oxygen_rate = OXYGEN_RATE_44100;
221 if (old_routing != new_routing) {
222 oxygen_write32(chip, OXYGEN_SPDIF_CONTROL,
223 new_control & ~OXYGEN_SPDIF_OUT_ENABLE);
224 oxygen_write16(chip, OXYGEN_PLAY_ROUTING, new_routing);
226 if (new_control & OXYGEN_SPDIF_OUT_ENABLE)
227 oxygen_write32(chip, OXYGEN_SPDIF_OUTPUT_BITS,
228 oxygen_spdif_rate(oxygen_rate) |
229 ((chip->pcm_active & (1 << PCM_SPDIF)) ?
230 chip->spdif_pcm_bits : chip->spdif_bits));
231 oxygen_write32(chip, OXYGEN_SPDIF_CONTROL, new_control);
234 static int spdif_switch_put(struct snd_kcontrol *ctl,
235 struct snd_ctl_elem_value *value)
237 struct oxygen *chip = ctl->private_data;
238 int changed;
240 mutex_lock(&chip->mutex);
241 changed = value->value.integer.value[0] != chip->spdif_playback_enable;
242 if (changed) {
243 chip->spdif_playback_enable = !!value->value.integer.value[0];
244 spin_lock_irq(&chip->reg_lock);
245 oxygen_update_spdif_source(chip);
246 spin_unlock_irq(&chip->reg_lock);
248 mutex_unlock(&chip->mutex);
249 return changed;
252 static int spdif_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
254 info->type = SNDRV_CTL_ELEM_TYPE_IEC958;
255 info->count = 1;
256 return 0;
259 static void oxygen_to_iec958(u32 bits, struct snd_ctl_elem_value *value)
261 value->value.iec958.status[0] =
262 bits & (OXYGEN_SPDIF_NONAUDIO | OXYGEN_SPDIF_C |
263 OXYGEN_SPDIF_PREEMPHASIS);
264 value->value.iec958.status[1] = /* category and original */
265 bits >> OXYGEN_SPDIF_CATEGORY_SHIFT;
268 static u32 iec958_to_oxygen(struct snd_ctl_elem_value *value)
270 u32 bits;
272 bits = value->value.iec958.status[0] &
273 (OXYGEN_SPDIF_NONAUDIO | OXYGEN_SPDIF_C |
274 OXYGEN_SPDIF_PREEMPHASIS);
275 bits |= value->value.iec958.status[1] << OXYGEN_SPDIF_CATEGORY_SHIFT;
276 if (bits & OXYGEN_SPDIF_NONAUDIO)
277 bits |= OXYGEN_SPDIF_V;
278 return bits;
281 static inline void write_spdif_bits(struct oxygen *chip, u32 bits)
283 oxygen_write32_masked(chip, OXYGEN_SPDIF_OUTPUT_BITS, bits,
284 OXYGEN_SPDIF_NONAUDIO |
285 OXYGEN_SPDIF_C |
286 OXYGEN_SPDIF_PREEMPHASIS |
287 OXYGEN_SPDIF_CATEGORY_MASK |
288 OXYGEN_SPDIF_ORIGINAL |
289 OXYGEN_SPDIF_V);
292 static int spdif_default_get(struct snd_kcontrol *ctl,
293 struct snd_ctl_elem_value *value)
295 struct oxygen *chip = ctl->private_data;
297 mutex_lock(&chip->mutex);
298 oxygen_to_iec958(chip->spdif_bits, value);
299 mutex_unlock(&chip->mutex);
300 return 0;
303 static int spdif_default_put(struct snd_kcontrol *ctl,
304 struct snd_ctl_elem_value *value)
306 struct oxygen *chip = ctl->private_data;
307 u32 new_bits;
308 int changed;
310 new_bits = iec958_to_oxygen(value);
311 mutex_lock(&chip->mutex);
312 changed = new_bits != chip->spdif_bits;
313 if (changed) {
314 chip->spdif_bits = new_bits;
315 if (!(chip->pcm_active & (1 << PCM_SPDIF)))
316 write_spdif_bits(chip, new_bits);
318 mutex_unlock(&chip->mutex);
319 return changed;
322 static int spdif_mask_get(struct snd_kcontrol *ctl,
323 struct snd_ctl_elem_value *value)
325 value->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
326 IEC958_AES0_CON_NOT_COPYRIGHT | IEC958_AES0_CON_EMPHASIS;
327 value->value.iec958.status[1] =
328 IEC958_AES1_CON_CATEGORY | IEC958_AES1_CON_ORIGINAL;
329 return 0;
332 static int spdif_pcm_get(struct snd_kcontrol *ctl,
333 struct snd_ctl_elem_value *value)
335 struct oxygen *chip = ctl->private_data;
337 mutex_lock(&chip->mutex);
338 oxygen_to_iec958(chip->spdif_pcm_bits, value);
339 mutex_unlock(&chip->mutex);
340 return 0;
343 static int spdif_pcm_put(struct snd_kcontrol *ctl,
344 struct snd_ctl_elem_value *value)
346 struct oxygen *chip = ctl->private_data;
347 u32 new_bits;
348 int changed;
350 new_bits = iec958_to_oxygen(value);
351 mutex_lock(&chip->mutex);
352 changed = new_bits != chip->spdif_pcm_bits;
353 if (changed) {
354 chip->spdif_pcm_bits = new_bits;
355 if (chip->pcm_active & (1 << PCM_SPDIF))
356 write_spdif_bits(chip, new_bits);
358 mutex_unlock(&chip->mutex);
359 return changed;
362 static int spdif_input_mask_get(struct snd_kcontrol *ctl,
363 struct snd_ctl_elem_value *value)
365 value->value.iec958.status[0] = 0xff;
366 value->value.iec958.status[1] = 0xff;
367 value->value.iec958.status[2] = 0xff;
368 value->value.iec958.status[3] = 0xff;
369 return 0;
372 static int spdif_input_default_get(struct snd_kcontrol *ctl,
373 struct snd_ctl_elem_value *value)
375 struct oxygen *chip = ctl->private_data;
376 u32 bits;
378 bits = oxygen_read32(chip, OXYGEN_SPDIF_INPUT_BITS);
379 value->value.iec958.status[0] = bits;
380 value->value.iec958.status[1] = bits >> 8;
381 value->value.iec958.status[2] = bits >> 16;
382 value->value.iec958.status[3] = bits >> 24;
383 return 0;
386 static int ac97_switch_get(struct snd_kcontrol *ctl,
387 struct snd_ctl_elem_value *value)
389 struct oxygen *chip = ctl->private_data;
390 unsigned int index = ctl->private_value & 0xff;
391 unsigned int bitnr = (ctl->private_value >> 8) & 0xff;
392 int invert = ctl->private_value & (1 << 16);
393 u16 reg;
395 mutex_lock(&chip->mutex);
396 reg = oxygen_read_ac97(chip, 0, index);
397 mutex_unlock(&chip->mutex);
398 if (!(reg & (1 << bitnr)) ^ !invert)
399 value->value.integer.value[0] = 1;
400 else
401 value->value.integer.value[0] = 0;
402 return 0;
405 static void ac97_mute_ctl(struct oxygen *chip, unsigned int control)
407 unsigned int index = chip->controls[control]->private_value & 0xff;
408 u16 value;
410 value = oxygen_read_ac97(chip, 0, index);
411 if (!(value & 0x8000)) {
412 oxygen_write_ac97(chip, 0, index, value | 0x8000);
413 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
414 &chip->controls[control]->id);
418 static int ac97_switch_put(struct snd_kcontrol *ctl,
419 struct snd_ctl_elem_value *value)
421 struct oxygen *chip = ctl->private_data;
422 unsigned int index = ctl->private_value & 0xff;
423 unsigned int bitnr = (ctl->private_value >> 8) & 0xff;
424 int invert = ctl->private_value & (1 << 16);
425 u16 oldreg, newreg;
426 int change;
428 mutex_lock(&chip->mutex);
429 oldreg = oxygen_read_ac97(chip, 0, index);
430 newreg = oldreg;
431 if (!value->value.integer.value[0] ^ !invert)
432 newreg |= 1 << bitnr;
433 else
434 newreg &= ~(1 << bitnr);
435 change = newreg != oldreg;
436 if (change) {
437 oxygen_write_ac97(chip, 0, index, newreg);
438 if (index == AC97_LINE) {
439 oxygen_write_ac97_masked(chip, 0, 0x72,
440 !!(newreg & 0x8000), 0x0001);
441 if (!(newreg & 0x8000)) {
442 ac97_mute_ctl(chip, CONTROL_MIC_CAPTURE_SWITCH);
443 ac97_mute_ctl(chip, CONTROL_CD_CAPTURE_SWITCH);
444 ac97_mute_ctl(chip, CONTROL_AUX_CAPTURE_SWITCH);
446 } else if ((index == AC97_MIC || index == AC97_CD ||
447 index == AC97_VIDEO || index == AC97_AUX) &&
448 bitnr == 15 && !(newreg & 0x8000)) {
449 ac97_mute_ctl(chip, CONTROL_LINE_CAPTURE_SWITCH);
450 oxygen_write_ac97_masked(chip, 0, 0x72, 0x0001, 0x0001);
453 mutex_unlock(&chip->mutex);
454 return change;
457 static int ac97_volume_info(struct snd_kcontrol *ctl,
458 struct snd_ctl_elem_info *info)
460 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
461 info->count = 2;
462 info->value.integer.min = 0;
463 info->value.integer.max = 0x1f;
464 return 0;
467 static int ac97_volume_get(struct snd_kcontrol *ctl,
468 struct snd_ctl_elem_value *value)
470 struct oxygen *chip = ctl->private_data;
471 unsigned int index = ctl->private_value;
472 u16 reg;
474 mutex_lock(&chip->mutex);
475 reg = oxygen_read_ac97(chip, 0, index);
476 mutex_unlock(&chip->mutex);
477 value->value.integer.value[0] = 31 - (reg & 0x1f);
478 value->value.integer.value[1] = 31 - ((reg >> 8) & 0x1f);
479 return 0;
482 static int ac97_volume_put(struct snd_kcontrol *ctl,
483 struct snd_ctl_elem_value *value)
485 struct oxygen *chip = ctl->private_data;
486 unsigned int index = ctl->private_value;
487 u16 oldreg, newreg;
488 int change;
490 mutex_lock(&chip->mutex);
491 oldreg = oxygen_read_ac97(chip, 0, index);
492 newreg = oldreg;
493 newreg = (newreg & ~0x1f) |
494 (31 - (value->value.integer.value[0] & 0x1f));
495 newreg = (newreg & ~0x1f00) |
496 ((31 - (value->value.integer.value[0] & 0x1f)) << 8);
497 change = newreg != oldreg;
498 if (change)
499 oxygen_write_ac97(chip, 0, index, newreg);
500 mutex_unlock(&chip->mutex);
501 return change;
504 #define AC97_SWITCH(xname, index, bitnr, invert) { \
505 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
506 .name = xname, \
507 .info = snd_ctl_boolean_mono_info, \
508 .get = ac97_switch_get, \
509 .put = ac97_switch_put, \
510 .private_value = ((invert) << 16) | ((bitnr) << 8) | (index), \
512 #define AC97_VOLUME(xname, index) { \
513 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
514 .name = xname, \
515 .info = ac97_volume_info, \
516 .get = ac97_volume_get, \
517 .put = ac97_volume_put, \
518 .tlv = { .p = ac97_db_scale, }, \
519 .private_value = (index), \
522 static DECLARE_TLV_DB_SCALE(ac97_db_scale, -3450, 150, 0);
524 static const struct snd_kcontrol_new controls[] = {
526 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
527 .name = "Master Playback Volume",
528 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
529 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
530 .info = dac_volume_info,
531 .get = dac_volume_get,
532 .put = dac_volume_put,
533 .tlv = {
534 .p = NULL, /* set later */
538 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
539 .name = "Master Playback Switch",
540 .info = snd_ctl_boolean_mono_info,
541 .get = dac_mute_get,
542 .put = dac_mute_put,
545 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
546 .name = "Stereo Upmixing",
547 .info = upmix_info,
548 .get = upmix_get,
549 .put = upmix_put,
552 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
553 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
554 .info = snd_ctl_boolean_mono_info,
555 .get = spdif_switch_get,
556 .put = spdif_switch_put,
559 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
560 .device = 1,
561 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
562 .info = spdif_info,
563 .get = spdif_default_get,
564 .put = spdif_default_put,
567 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
568 .device = 1,
569 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
570 .access = SNDRV_CTL_ELEM_ACCESS_READ,
571 .info = spdif_info,
572 .get = spdif_mask_get,
575 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
576 .device = 1,
577 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
578 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
579 SNDRV_CTL_ELEM_ACCESS_INACTIVE,
580 .info = spdif_info,
581 .get = spdif_pcm_get,
582 .put = spdif_pcm_put,
585 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
586 .device = 1,
587 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK),
588 .access = SNDRV_CTL_ELEM_ACCESS_READ,
589 .info = spdif_info,
590 .get = spdif_input_mask_get,
593 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
594 .device = 1,
595 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
596 .access = SNDRV_CTL_ELEM_ACCESS_READ,
597 .info = spdif_info,
598 .get = spdif_input_default_get,
600 AC97_VOLUME("Mic Capture Volume", AC97_MIC),
601 AC97_SWITCH("Mic Capture Switch", AC97_MIC, 15, 1),
602 AC97_SWITCH("Mic Boost (+20dB)", AC97_MIC, 6, 0),
603 AC97_SWITCH("Line Capture Switch", AC97_LINE, 15, 1),
604 AC97_VOLUME("CD Capture Volume", AC97_CD),
605 AC97_SWITCH("CD Capture Switch", AC97_CD, 15, 1),
606 AC97_VOLUME("Aux Capture Volume", AC97_AUX),
607 AC97_SWITCH("Aux Capture Switch", AC97_AUX, 15, 1),
610 static void oxygen_any_ctl_free(struct snd_kcontrol *ctl)
612 struct oxygen *chip = ctl->private_data;
613 unsigned int i;
615 /* I'm too lazy to write a function for each control :-) */
616 for (i = 0; i < ARRAY_SIZE(chip->controls); ++i)
617 chip->controls[i] = NULL;
620 int oxygen_mixer_init(struct oxygen *chip)
622 static const char *const known_ctl_names[CONTROL_COUNT] = {
623 [CONTROL_SPDIF_PCM] =
624 SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
625 [CONTROL_SPDIF_INPUT_BITS] =
626 SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
627 [CONTROL_MIC_CAPTURE_SWITCH] = "Mic Capture Switch",
628 [CONTROL_LINE_CAPTURE_SWITCH] = "Line Capture Switch",
629 [CONTROL_CD_CAPTURE_SWITCH] = "CD Capture Switch",
630 [CONTROL_AUX_CAPTURE_SWITCH] = "Aux Capture Switch",
632 unsigned int i, j;
633 struct snd_kcontrol *ctl;
634 int err;
636 for (i = 0; i < ARRAY_SIZE(controls); ++i) {
637 ctl = snd_ctl_new1(&controls[i], chip);
638 if (!ctl)
639 return -ENOMEM;
640 if (!strcmp(ctl->id.name, "Master Playback Volume"))
641 ctl->tlv.p = chip->model->dac_tlv;
642 else if (chip->model->cd_in_from_video_in &&
643 !strncmp(ctl->id.name, "CD Capture ", 11))
644 ctl->private_value ^= AC97_CD ^ AC97_VIDEO;
645 err = snd_ctl_add(chip->card, ctl);
646 if (err < 0)
647 return err;
648 for (j = 0; j < CONTROL_COUNT; ++j)
649 if (!strcmp(ctl->id.name, known_ctl_names[j])) {
650 chip->controls[j] = ctl;
651 ctl->private_free = oxygen_any_ctl_free;
654 return chip->model->mixer_init ? chip->model->mixer_init(chip) : 0;