blob: fcb5813183fbf81611411c0afb432c61bfee4c7c [file] [log] [blame]
Clemens Ladischd0ce9942007-12-23 19:50:57 +01001/*
2 * C-Media CMI8788 driver - mixer code
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 *
6 *
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.
9 *
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.
14 *
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
18 */
19
Clemens Ladischd0ce9942007-12-23 19:50:57 +010020#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"
26
27static int dac_volume_info(struct snd_kcontrol *ctl,
28 struct snd_ctl_elem_info *info)
29{
30 struct oxygen *chip = ctl->private_data;
31
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;
37}
38
39static int dac_volume_get(struct snd_kcontrol *ctl,
40 struct snd_ctl_elem_value *value)
41{
42 struct oxygen *chip = ctl->private_data;
43 unsigned int i;
44
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;
50}
51
52static int dac_volume_put(struct snd_kcontrol *ctl,
53 struct snd_ctl_elem_value *value)
54{
55 struct oxygen *chip = ctl->private_data;
56 unsigned int i;
57 int changed;
58
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;
65 }
66 if (changed)
67 chip->model->update_dac_volume(chip);
68 mutex_unlock(&chip->mutex);
69 return changed;
70}
71
72static int dac_mute_get(struct snd_kcontrol *ctl,
73 struct snd_ctl_elem_value *value)
74{
75 struct oxygen *chip = ctl->private_data;
76
77 mutex_lock(&chip->mutex);
78 value->value.integer.value[0] = !chip->dac_mute;
79 mutex_unlock(&chip->mutex);
80 return 0;
81}
82
83static int dac_mute_put(struct snd_kcontrol *ctl,
84 struct snd_ctl_elem_value *value)
85{
86 struct oxygen *chip = ctl->private_data;
87 int changed;
88
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);
94 }
95 mutex_unlock(&chip->mutex);
96 return changed;
97}
98
99static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
100{
101 static const char *const names[3] = {
Clemens Ladisch7113e952008-01-14 08:55:03 +0100102 "Front", "Front+Surround", "Front+Surround+Back"
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100103 };
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;
111}
112
113static int upmix_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
114{
115 struct oxygen *chip = ctl->private_data;
116
117 mutex_lock(&chip->mutex);
118 value->value.enumerated.item[0] = chip->dac_routing;
119 mutex_unlock(&chip->mutex);
120 return 0;
121}
122
123void oxygen_update_dac_routing(struct oxygen *chip)
124{
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100125 static const unsigned int reg_values[3] = {
Clemens Ladisch7113e952008-01-14 08:55:03 +0100126 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 */
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100129 };
Clemens Ladisch7113e952008-01-14 08:55:03 +0100130 u8 channels;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100131 unsigned int reg_value;
132
Clemens Ladisch7113e952008-01-14 08:55:03 +0100133 channels = oxygen_read8(chip, OXYGEN_PLAY_CHANNELS) &
134 OXYGEN_PLAY_CHANNELS_MASK;
135 if (channels == OXYGEN_PLAY_CHANNELS_2)
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100136 reg_value = reg_values[chip->dac_routing];
Clemens Ladisch7113e952008-01-14 08:55:03 +0100137 else if (channels == OXYGEN_PLAY_CHANNELS_8)
138 reg_value = 0x6c00; /* surround <- 3, back <- 1 */
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100139 else
Clemens Ladisch7113e952008-01-14 08:55:03 +0100140 reg_value = 0xe100;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100141 oxygen_write16_masked(chip, OXYGEN_PLAY_ROUTING, reg_value, 0xff00);
142}
143
144static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
145{
146 struct oxygen *chip = ctl->private_data;
147 int changed;
148
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);
156 }
157 mutex_unlock(&chip->mutex);
158 return changed;
159}
160
161static int spdif_switch_get(struct snd_kcontrol *ctl,
162 struct snd_ctl_elem_value *value)
163{
164 struct oxygen *chip = ctl->private_data;
165
166 mutex_lock(&chip->mutex);
167 value->value.integer.value[0] = chip->spdif_playback_enable;
168 mutex_unlock(&chip->mutex);
169 return 0;
170}
171
172static unsigned int oxygen_spdif_rate(unsigned int oxygen_rate)
173{
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;
191 }
192}
193
194void oxygen_update_spdif_source(struct oxygen *chip)
195{
196 u32 old_control, new_control;
197 u16 old_routing, new_routing;
198 unsigned int oxygen_rate;
199
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;
220 }
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);
225 }
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);
232}
233
234static int spdif_switch_put(struct snd_kcontrol *ctl,
235 struct snd_ctl_elem_value *value)
236{
237 struct oxygen *chip = ctl->private_data;
238 int changed;
239
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);
247 }
248 mutex_unlock(&chip->mutex);
249 return changed;
250}
251
252static int spdif_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
253{
254 info->type = SNDRV_CTL_ELEM_TYPE_IEC958;
255 info->count = 1;
256 return 0;
257}
258
259static void oxygen_to_iec958(u32 bits, struct snd_ctl_elem_value *value)
260{
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;
266}
267
268static u32 iec958_to_oxygen(struct snd_ctl_elem_value *value)
269{
270 u32 bits;
271
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;
279}
280
281static inline void write_spdif_bits(struct oxygen *chip, u32 bits)
282{
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);
290}
291
292static int spdif_default_get(struct snd_kcontrol *ctl,
293 struct snd_ctl_elem_value *value)
294{
295 struct oxygen *chip = ctl->private_data;
296
297 mutex_lock(&chip->mutex);
298 oxygen_to_iec958(chip->spdif_bits, value);
299 mutex_unlock(&chip->mutex);
300 return 0;
301}
302
303static int spdif_default_put(struct snd_kcontrol *ctl,
304 struct snd_ctl_elem_value *value)
305{
306 struct oxygen *chip = ctl->private_data;
307 u32 new_bits;
308 int changed;
309
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);
317 }
318 mutex_unlock(&chip->mutex);
319 return changed;
320}
321
322static int spdif_mask_get(struct snd_kcontrol *ctl,
323 struct snd_ctl_elem_value *value)
324{
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;
330}
331
332static int spdif_pcm_get(struct snd_kcontrol *ctl,
333 struct snd_ctl_elem_value *value)
334{
335 struct oxygen *chip = ctl->private_data;
336
337 mutex_lock(&chip->mutex);
338 oxygen_to_iec958(chip->spdif_pcm_bits, value);
339 mutex_unlock(&chip->mutex);
340 return 0;
341}
342
343static int spdif_pcm_put(struct snd_kcontrol *ctl,
344 struct snd_ctl_elem_value *value)
345{
346 struct oxygen *chip = ctl->private_data;
347 u32 new_bits;
348 int changed;
349
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);
357 }
358 mutex_unlock(&chip->mutex);
359 return changed;
360}
361
362static int spdif_input_mask_get(struct snd_kcontrol *ctl,
363 struct snd_ctl_elem_value *value)
364{
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;
370}
371
372static int spdif_input_default_get(struct snd_kcontrol *ctl,
373 struct snd_ctl_elem_value *value)
374{
375 struct oxygen *chip = ctl->private_data;
376 u32 bits;
377
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;
384}
385
386static int ac97_switch_get(struct snd_kcontrol *ctl,
387 struct snd_ctl_elem_value *value)
388{
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;
394
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;
403}
404
Clemens Ladisch893e44b2008-01-14 08:57:05 +0100405static void ac97_mute_ctl(struct oxygen *chip, unsigned int control)
406{
407 unsigned int index = chip->controls[control]->private_value & 0xff;
408 u16 value;
409
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);
415 }
416}
417
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100418static int ac97_switch_put(struct snd_kcontrol *ctl,
419 struct snd_ctl_elem_value *value)
420{
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;
427
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);
Clemens Ladisch893e44b2008-01-14 08:57:05 +0100438 if (index == AC97_LINE) {
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100439 oxygen_write_ac97_masked(chip, 0, 0x72,
440 !!(newreg & 0x8000), 0x0001);
Clemens Ladisch893e44b2008-01-14 08:57:05 +0100441 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);
445 }
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);
451 }
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100452 }
453 mutex_unlock(&chip->mutex);
454 return change;
455}
456
457static int ac97_volume_info(struct snd_kcontrol *ctl,
458 struct snd_ctl_elem_info *info)
459{
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;
465}
466
467static int ac97_volume_get(struct snd_kcontrol *ctl,
468 struct snd_ctl_elem_value *value)
469{
470 struct oxygen *chip = ctl->private_data;
471 unsigned int index = ctl->private_value;
472 u16 reg;
473
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;
480}
481
482static int ac97_volume_put(struct snd_kcontrol *ctl,
483 struct snd_ctl_elem_value *value)
484{
485 struct oxygen *chip = ctl->private_data;
486 unsigned int index = ctl->private_value;
487 u16 oldreg, newreg;
488 int change;
489
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;
502}
503
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), \
511 }
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), \
520 }
521
522static DECLARE_TLV_DB_SCALE(ac97_db_scale, -3450, 150, 0);
523
524static const struct snd_kcontrol_new controls[] = {
525 {
526 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
527 .name = "PCM 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 */
535 },
536 },
537 {
538 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
539 .name = "PCM Playback Switch",
540 .info = snd_ctl_boolean_mono_info,
541 .get = dac_mute_get,
542 .put = dac_mute_put,
543 },
544 {
545 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
546 .name = "Stereo Upmixing",
547 .info = upmix_info,
548 .get = upmix_get,
549 .put = upmix_put,
550 },
551 {
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,
557 },
558 {
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,
565 },
566 {
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,
573 },
574 {
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,
583 },
584 {
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,
591 },
592 {
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,
599 },
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),
608};
609
610static void oxygen_any_ctl_free(struct snd_kcontrol *ctl)
611{
612 struct oxygen *chip = ctl->private_data;
Clemens Ladisch01a3aff2008-01-14 08:56:01 +0100613 unsigned int i;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100614
615 /* I'm too lazy to write a function for each control :-) */
Clemens Ladisch01a3aff2008-01-14 08:56:01 +0100616 for (i = 0; i < ARRAY_SIZE(chip->controls); ++i)
617 chip->controls[i] = NULL;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100618}
619
620int oxygen_mixer_init(struct oxygen *chip)
621{
Clemens Ladisch01a3aff2008-01-14 08:56:01 +0100622 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),
Clemens Ladisch893e44b2008-01-14 08:57:05 +0100627 [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",
Clemens Ladisch01a3aff2008-01-14 08:56:01 +0100631 };
632 unsigned int i, j;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100633 struct snd_kcontrol *ctl;
634 int err;
635
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, "PCM 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;
Clemens Ladisch01a3aff2008-01-14 08:56:01 +0100648 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;
652 }
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100653 }
654 return chip->model->mixer_init ? chip->model->mixer_init(chip) : 0;
655}