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>
28 static int dac_volume_info(struct snd_kcontrol *ctl,
29 struct snd_ctl_elem_info *info)
31 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
33 info->value.integer.min = 0;
34 info->value.integer.max = 0xff;
38 static int dac_volume_get(struct snd_kcontrol *ctl,
39 struct snd_ctl_elem_value *value)
41 struct oxygen *chip = ctl->private_data;
44 mutex_lock(&chip->mutex);
45 for (i = 0; i < 8; ++i)
46 value->value.integer.value[i] = chip->dac_volume[i];
47 mutex_unlock(&chip->mutex);
51 static int dac_volume_put(struct snd_kcontrol *ctl,
52 struct snd_ctl_elem_value *value)
54 struct oxygen *chip = ctl->private_data;
59 mutex_lock(&chip->mutex);
60 for (i = 0; i < 8; ++i)
61 if (value->value.integer.value[i] != chip->dac_volume[i]) {
62 chip->dac_volume[i] = value->value.integer.value[i];
66 chip->model->update_dac_volume(chip);
67 mutex_unlock(&chip->mutex);
71 static int dac_mute_get(struct snd_kcontrol *ctl,
72 struct snd_ctl_elem_value *value)
74 struct oxygen *chip = ctl->private_data;
76 mutex_lock(&chip->mutex);
77 value->value.integer.value[0] = !chip->dac_mute;
78 mutex_unlock(&chip->mutex);
82 static int dac_mute_put(struct snd_kcontrol *ctl,
83 struct snd_ctl_elem_value *value)
85 struct oxygen *chip = ctl->private_data;
88 mutex_lock(&chip->mutex);
89 changed = !value->value.integer.value[0] != chip->dac_mute;
91 chip->dac_mute = !value->value.integer.value[0];
92 chip->model->update_dac_mute(chip);
94 mutex_unlock(&chip->mutex);
98 static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
100 static const char *const names[3] = {
101 "Front", "Front+Surround", "Front+Surround+Back"
103 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
105 info->value.enumerated.items = 3;
106 if (info->value.enumerated.item > 2)
107 info->value.enumerated.item = 2;
108 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
112 static int upmix_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
114 struct oxygen *chip = ctl->private_data;
116 mutex_lock(&chip->mutex);
117 value->value.enumerated.item[0] = chip->dac_routing;
118 mutex_unlock(&chip->mutex);
122 void oxygen_update_dac_routing(struct oxygen *chip)
124 /* DAC 0: front, DAC 1: surround, DAC 2: center/LFE, DAC 3: back */
125 static const unsigned int reg_values[3] = {
126 /* stereo -> front */
127 (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
128 (1 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
129 (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
130 (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT),
131 /* stereo -> front+surround */
132 (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
133 (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
134 (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
135 (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT),
136 /* stereo -> front+surround+back */
137 (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
138 (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
139 (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
140 (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT),
143 unsigned int reg_value;
145 channels = oxygen_read8(chip, OXYGEN_PLAY_CHANNELS) &
146 OXYGEN_PLAY_CHANNELS_MASK;
147 if (channels == OXYGEN_PLAY_CHANNELS_2)
148 reg_value = reg_values[chip->dac_routing];
149 else if (channels == OXYGEN_PLAY_CHANNELS_8)
150 /* in 7.1 mode, "rear" channels go to the "back" jack */
151 reg_value = (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
152 (3 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
153 (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
154 (1 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT);
156 reg_value = (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
157 (1 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
158 (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
159 (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT);
160 oxygen_write16_masked(chip, OXYGEN_PLAY_ROUTING, reg_value,
161 OXYGEN_PLAY_DAC0_SOURCE_MASK |
162 OXYGEN_PLAY_DAC1_SOURCE_MASK |
163 OXYGEN_PLAY_DAC2_SOURCE_MASK |
164 OXYGEN_PLAY_DAC3_SOURCE_MASK);
167 static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
169 struct oxygen *chip = ctl->private_data;
172 mutex_lock(&chip->mutex);
173 changed = value->value.enumerated.item[0] != chip->dac_routing;
175 chip->dac_routing = min(value->value.enumerated.item[0], 2u);
176 spin_lock_irq(&chip->reg_lock);
177 oxygen_update_dac_routing(chip);
178 spin_unlock_irq(&chip->reg_lock);
180 mutex_unlock(&chip->mutex);
184 static int spdif_switch_get(struct snd_kcontrol *ctl,
185 struct snd_ctl_elem_value *value)
187 struct oxygen *chip = ctl->private_data;
189 mutex_lock(&chip->mutex);
190 value->value.integer.value[0] = chip->spdif_playback_enable;
191 mutex_unlock(&chip->mutex);
195 static unsigned int oxygen_spdif_rate(unsigned int oxygen_rate)
197 switch (oxygen_rate) {
198 case OXYGEN_RATE_32000:
199 return IEC958_AES3_CON_FS_32000 << OXYGEN_SPDIF_CS_RATE_SHIFT;
200 case OXYGEN_RATE_44100:
201 return IEC958_AES3_CON_FS_44100 << OXYGEN_SPDIF_CS_RATE_SHIFT;
202 default: /* OXYGEN_RATE_48000 */
203 return IEC958_AES3_CON_FS_48000 << OXYGEN_SPDIF_CS_RATE_SHIFT;
204 case OXYGEN_RATE_64000:
205 return 0xb << OXYGEN_SPDIF_CS_RATE_SHIFT;
206 case OXYGEN_RATE_88200:
207 return 0x8 << OXYGEN_SPDIF_CS_RATE_SHIFT;
208 case OXYGEN_RATE_96000:
209 return 0xa << OXYGEN_SPDIF_CS_RATE_SHIFT;
210 case OXYGEN_RATE_176400:
211 return 0xc << OXYGEN_SPDIF_CS_RATE_SHIFT;
212 case OXYGEN_RATE_192000:
213 return 0xe << OXYGEN_SPDIF_CS_RATE_SHIFT;
217 void oxygen_update_spdif_source(struct oxygen *chip)
219 u32 old_control, new_control;
220 u16 old_routing, new_routing;
221 unsigned int oxygen_rate;
223 old_control = oxygen_read32(chip, OXYGEN_SPDIF_CONTROL);
224 old_routing = oxygen_read16(chip, OXYGEN_PLAY_ROUTING);
225 if (chip->pcm_active & (1 << PCM_SPDIF)) {
226 new_control = old_control | OXYGEN_SPDIF_OUT_ENABLE;
227 new_routing = (old_routing & ~OXYGEN_PLAY_SPDIF_MASK)
228 | OXYGEN_PLAY_SPDIF_SPDIF;
229 oxygen_rate = (old_control >> OXYGEN_SPDIF_OUT_RATE_SHIFT)
230 & OXYGEN_I2S_RATE_MASK;
231 /* S/PDIF rate was already set by the caller */
232 } else if ((chip->pcm_active & (1 << PCM_MULTICH)) &&
233 chip->spdif_playback_enable) {
234 new_routing = (old_routing & ~OXYGEN_PLAY_SPDIF_MASK)
235 | OXYGEN_PLAY_SPDIF_MULTICH_01;
236 oxygen_rate = oxygen_read16(chip, OXYGEN_I2S_MULTICH_FORMAT)
237 & OXYGEN_I2S_RATE_MASK;
238 new_control = (old_control & ~OXYGEN_SPDIF_OUT_RATE_MASK) |
239 (oxygen_rate << OXYGEN_SPDIF_OUT_RATE_SHIFT) |
240 OXYGEN_SPDIF_OUT_ENABLE;
242 new_control = old_control & ~OXYGEN_SPDIF_OUT_ENABLE;
243 new_routing = old_routing;
244 oxygen_rate = OXYGEN_RATE_44100;
246 if (old_routing != new_routing) {
247 oxygen_write32(chip, OXYGEN_SPDIF_CONTROL,
248 new_control & ~OXYGEN_SPDIF_OUT_ENABLE);
249 oxygen_write16(chip, OXYGEN_PLAY_ROUTING, new_routing);
251 if (new_control & OXYGEN_SPDIF_OUT_ENABLE)
252 oxygen_write32(chip, OXYGEN_SPDIF_OUTPUT_BITS,
253 oxygen_spdif_rate(oxygen_rate) |
254 ((chip->pcm_active & (1 << PCM_SPDIF)) ?
255 chip->spdif_pcm_bits : chip->spdif_bits));
256 oxygen_write32(chip, OXYGEN_SPDIF_CONTROL, new_control);
259 static int spdif_switch_put(struct snd_kcontrol *ctl,
260 struct snd_ctl_elem_value *value)
262 struct oxygen *chip = ctl->private_data;
265 mutex_lock(&chip->mutex);
266 changed = value->value.integer.value[0] != chip->spdif_playback_enable;
268 chip->spdif_playback_enable = !!value->value.integer.value[0];
269 spin_lock_irq(&chip->reg_lock);
270 oxygen_update_spdif_source(chip);
271 spin_unlock_irq(&chip->reg_lock);
273 mutex_unlock(&chip->mutex);
277 static int spdif_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
279 info->type = SNDRV_CTL_ELEM_TYPE_IEC958;
284 static void oxygen_to_iec958(u32 bits, struct snd_ctl_elem_value *value)
286 value->value.iec958.status[0] =
287 bits & (OXYGEN_SPDIF_NONAUDIO | OXYGEN_SPDIF_C |
288 OXYGEN_SPDIF_PREEMPHASIS);
289 value->value.iec958.status[1] = /* category and original */
290 bits >> OXYGEN_SPDIF_CATEGORY_SHIFT;
293 static u32 iec958_to_oxygen(struct snd_ctl_elem_value *value)
297 bits = value->value.iec958.status[0] &
298 (OXYGEN_SPDIF_NONAUDIO | OXYGEN_SPDIF_C |
299 OXYGEN_SPDIF_PREEMPHASIS);
300 bits |= value->value.iec958.status[1] << OXYGEN_SPDIF_CATEGORY_SHIFT;
301 if (bits & OXYGEN_SPDIF_NONAUDIO)
302 bits |= OXYGEN_SPDIF_V;
306 static inline void write_spdif_bits(struct oxygen *chip, u32 bits)
308 oxygen_write32_masked(chip, OXYGEN_SPDIF_OUTPUT_BITS, bits,
309 OXYGEN_SPDIF_NONAUDIO |
311 OXYGEN_SPDIF_PREEMPHASIS |
312 OXYGEN_SPDIF_CATEGORY_MASK |
313 OXYGEN_SPDIF_ORIGINAL |
317 static int spdif_default_get(struct snd_kcontrol *ctl,
318 struct snd_ctl_elem_value *value)
320 struct oxygen *chip = ctl->private_data;
322 mutex_lock(&chip->mutex);
323 oxygen_to_iec958(chip->spdif_bits, value);
324 mutex_unlock(&chip->mutex);
328 static int spdif_default_put(struct snd_kcontrol *ctl,
329 struct snd_ctl_elem_value *value)
331 struct oxygen *chip = ctl->private_data;
335 new_bits = iec958_to_oxygen(value);
336 mutex_lock(&chip->mutex);
337 changed = new_bits != chip->spdif_bits;
339 chip->spdif_bits = new_bits;
340 if (!(chip->pcm_active & (1 << PCM_SPDIF)))
341 write_spdif_bits(chip, new_bits);
343 mutex_unlock(&chip->mutex);
347 static int spdif_mask_get(struct snd_kcontrol *ctl,
348 struct snd_ctl_elem_value *value)
350 value->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
351 IEC958_AES0_CON_NOT_COPYRIGHT | IEC958_AES0_CON_EMPHASIS;
352 value->value.iec958.status[1] =
353 IEC958_AES1_CON_CATEGORY | IEC958_AES1_CON_ORIGINAL;
357 static int spdif_pcm_get(struct snd_kcontrol *ctl,
358 struct snd_ctl_elem_value *value)
360 struct oxygen *chip = ctl->private_data;
362 mutex_lock(&chip->mutex);
363 oxygen_to_iec958(chip->spdif_pcm_bits, value);
364 mutex_unlock(&chip->mutex);
368 static int spdif_pcm_put(struct snd_kcontrol *ctl,
369 struct snd_ctl_elem_value *value)
371 struct oxygen *chip = ctl->private_data;
375 new_bits = iec958_to_oxygen(value);
376 mutex_lock(&chip->mutex);
377 changed = new_bits != chip->spdif_pcm_bits;
379 chip->spdif_pcm_bits = new_bits;
380 if (chip->pcm_active & (1 << PCM_SPDIF))
381 write_spdif_bits(chip, new_bits);
383 mutex_unlock(&chip->mutex);
387 static int spdif_input_mask_get(struct snd_kcontrol *ctl,
388 struct snd_ctl_elem_value *value)
390 value->value.iec958.status[0] = 0xff;
391 value->value.iec958.status[1] = 0xff;
392 value->value.iec958.status[2] = 0xff;
393 value->value.iec958.status[3] = 0xff;
397 static int spdif_input_default_get(struct snd_kcontrol *ctl,
398 struct snd_ctl_elem_value *value)
400 struct oxygen *chip = ctl->private_data;
403 bits = oxygen_read32(chip, OXYGEN_SPDIF_INPUT_BITS);
404 value->value.iec958.status[0] = bits;
405 value->value.iec958.status[1] = bits >> 8;
406 value->value.iec958.status[2] = bits >> 16;
407 value->value.iec958.status[3] = bits >> 24;
411 static int ac97_switch_get(struct snd_kcontrol *ctl,
412 struct snd_ctl_elem_value *value)
414 struct oxygen *chip = ctl->private_data;
415 unsigned int index = ctl->private_value & 0xff;
416 unsigned int bitnr = (ctl->private_value >> 8) & 0xff;
417 int invert = ctl->private_value & (1 << 16);
420 mutex_lock(&chip->mutex);
421 reg = oxygen_read_ac97(chip, 0, index);
422 mutex_unlock(&chip->mutex);
423 if (!(reg & (1 << bitnr)) ^ !invert)
424 value->value.integer.value[0] = 1;
426 value->value.integer.value[0] = 0;
430 static void ac97_mute_ctl(struct oxygen *chip, unsigned int control)
432 unsigned int index = chip->controls[control]->private_value & 0xff;
435 value = oxygen_read_ac97(chip, 0, index);
436 if (!(value & 0x8000)) {
437 oxygen_write_ac97(chip, 0, index, value | 0x8000);
438 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
439 &chip->controls[control]->id);
443 static int ac97_switch_put(struct snd_kcontrol *ctl,
444 struct snd_ctl_elem_value *value)
446 struct oxygen *chip = ctl->private_data;
447 unsigned int index = ctl->private_value & 0xff;
448 unsigned int bitnr = (ctl->private_value >> 8) & 0xff;
449 int invert = ctl->private_value & (1 << 16);
453 mutex_lock(&chip->mutex);
454 oldreg = oxygen_read_ac97(chip, 0, index);
456 if (!value->value.integer.value[0] ^ !invert)
457 newreg |= 1 << bitnr;
459 newreg &= ~(1 << bitnr);
460 change = newreg != oldreg;
462 oxygen_write_ac97(chip, 0, index, newreg);
463 if (index == AC97_LINE) {
464 oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
466 CM9780_GPO0 : 0, CM9780_GPO0);
467 if (!(newreg & 0x8000)) {
468 ac97_mute_ctl(chip, CONTROL_MIC_CAPTURE_SWITCH);
469 ac97_mute_ctl(chip, CONTROL_CD_CAPTURE_SWITCH);
470 ac97_mute_ctl(chip, CONTROL_AUX_CAPTURE_SWITCH);
472 } else if ((index == AC97_MIC || index == AC97_CD ||
473 index == AC97_VIDEO || index == AC97_AUX) &&
474 bitnr == 15 && !(newreg & 0x8000)) {
475 ac97_mute_ctl(chip, CONTROL_LINE_CAPTURE_SWITCH);
476 oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
477 CM9780_GPO0, CM9780_GPO0);
480 mutex_unlock(&chip->mutex);
484 static int ac97_volume_info(struct snd_kcontrol *ctl,
485 struct snd_ctl_elem_info *info)
487 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
489 info->value.integer.min = 0;
490 info->value.integer.max = 0x1f;
494 static int ac97_volume_get(struct snd_kcontrol *ctl,
495 struct snd_ctl_elem_value *value)
497 struct oxygen *chip = ctl->private_data;
498 unsigned int index = ctl->private_value;
501 mutex_lock(&chip->mutex);
502 reg = oxygen_read_ac97(chip, 0, index);
503 mutex_unlock(&chip->mutex);
504 value->value.integer.value[0] = 31 - (reg & 0x1f);
505 value->value.integer.value[1] = 31 - ((reg >> 8) & 0x1f);
509 static int ac97_volume_put(struct snd_kcontrol *ctl,
510 struct snd_ctl_elem_value *value)
512 struct oxygen *chip = ctl->private_data;
513 unsigned int index = ctl->private_value;
517 mutex_lock(&chip->mutex);
518 oldreg = oxygen_read_ac97(chip, 0, index);
520 newreg = (newreg & ~0x1f) |
521 (31 - (value->value.integer.value[0] & 0x1f));
522 newreg = (newreg & ~0x1f00) |
523 ((31 - (value->value.integer.value[0] & 0x1f)) << 8);
524 change = newreg != oldreg;
526 oxygen_write_ac97(chip, 0, index, newreg);
527 mutex_unlock(&chip->mutex);
531 #define AC97_SWITCH(xname, index, bitnr, invert) { \
532 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
534 .info = snd_ctl_boolean_mono_info, \
535 .get = ac97_switch_get, \
536 .put = ac97_switch_put, \
537 .private_value = ((invert) << 16) | ((bitnr) << 8) | (index), \
539 #define AC97_VOLUME(xname, index) { \
540 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
542 .info = ac97_volume_info, \
543 .get = ac97_volume_get, \
544 .put = ac97_volume_put, \
545 .tlv = { .p = ac97_db_scale, }, \
546 .private_value = (index), \
549 static DECLARE_TLV_DB_SCALE(ac97_db_scale, -3450, 150, 0);
551 static const struct snd_kcontrol_new controls[] = {
553 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
554 .name = "Master Playback Volume",
555 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
556 .info = dac_volume_info,
557 .get = dac_volume_get,
558 .put = dac_volume_put,
561 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
562 .name = "Master Playback Switch",
563 .info = snd_ctl_boolean_mono_info,
568 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
569 .name = "Stereo Upmixing",
575 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
576 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
577 .info = snd_ctl_boolean_mono_info,
578 .get = spdif_switch_get,
579 .put = spdif_switch_put,
582 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
584 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
586 .get = spdif_default_get,
587 .put = spdif_default_put,
590 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
592 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
593 .access = SNDRV_CTL_ELEM_ACCESS_READ,
595 .get = spdif_mask_get,
598 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
600 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
601 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
602 SNDRV_CTL_ELEM_ACCESS_INACTIVE,
604 .get = spdif_pcm_get,
605 .put = spdif_pcm_put,
608 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
610 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK),
611 .access = SNDRV_CTL_ELEM_ACCESS_READ,
613 .get = spdif_input_mask_get,
616 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
618 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
619 .access = SNDRV_CTL_ELEM_ACCESS_READ,
621 .get = spdif_input_default_get,
625 static const struct snd_kcontrol_new ac97_controls[] = {
626 AC97_VOLUME("Mic Capture Volume", AC97_MIC),
627 AC97_SWITCH("Mic Capture Switch", AC97_MIC, 15, 1),
628 AC97_SWITCH("Mic Boost (+20dB)", AC97_MIC, 6, 0),
629 AC97_SWITCH("Line Capture Switch", AC97_LINE, 15, 1),
630 AC97_VOLUME("CD Capture Volume", AC97_CD),
631 AC97_SWITCH("CD Capture Switch", AC97_CD, 15, 1),
632 AC97_VOLUME("Aux Capture Volume", AC97_AUX),
633 AC97_SWITCH("Aux Capture Switch", AC97_AUX, 15, 1),
636 static void oxygen_any_ctl_free(struct snd_kcontrol *ctl)
638 struct oxygen *chip = ctl->private_data;
641 /* I'm too lazy to write a function for each control :-) */
642 for (i = 0; i < ARRAY_SIZE(chip->controls); ++i)
643 chip->controls[i] = NULL;
646 static int add_controls(struct oxygen *chip,
647 const struct snd_kcontrol_new controls[],
650 static const char *const known_ctl_names[CONTROL_COUNT] = {
651 [CONTROL_SPDIF_PCM] =
652 SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
653 [CONTROL_SPDIF_INPUT_BITS] =
654 SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
655 [CONTROL_MIC_CAPTURE_SWITCH] = "Mic Capture Switch",
656 [CONTROL_LINE_CAPTURE_SWITCH] = "Line Capture Switch",
657 [CONTROL_CD_CAPTURE_SWITCH] = "CD Capture Switch",
658 [CONTROL_AUX_CAPTURE_SWITCH] = "Aux Capture Switch",
661 struct snd_kcontrol_new template;
662 struct snd_kcontrol *ctl;
665 for (i = 0; i < count; ++i) {
666 template = controls[i];
667 err = chip->model->control_filter(&template);
670 ctl = snd_ctl_new1(&controls[i], chip);
673 err = snd_ctl_add(chip->card, ctl);
676 for (j = 0; j < CONTROL_COUNT; ++j)
677 if (!strcmp(ctl->id.name, known_ctl_names[j])) {
678 chip->controls[j] = ctl;
679 ctl->private_free = oxygen_any_ctl_free;
685 int oxygen_mixer_init(struct oxygen *chip)
689 err = add_controls(chip, controls, ARRAY_SIZE(controls));
692 if (chip->has_ac97_0) {
693 err = add_controls(chip, ac97_controls,
694 ARRAY_SIZE(ac97_controls));
698 return chip->model->mixer_init ? chip->model->mixer_init(chip) : 0;