2 * ALSA driver for ICEnsemble ICE1724 (Envy24)
4 * Lowlevel functions for Terratec PHASE 22
6 * Copyright (c) 2005 Misha Zhilin <misha@epiphan.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Audio controller: VIA Envy24HT-S (slightly trimmed down version of Envy24HT)
26 * Analog chip: AK4524 (partially via Philip's 74HCT125)
27 * Digital receiver: CS8414-CS (not supported in this release)
29 * Envy connects to AK4524
30 * - CS directly from GPIO 10
31 * - CCLK via 74HCT125's gate #4 from GPIO 4
32 * - CDTI via 74HCT125's gate #2 from GPIO 5
33 * CDTI may be completely blocked by 74HCT125's gate #1 controlled by GPIO 3
36 #include <sound/driver.h>
38 #include <linux/delay.h>
39 #include <linux/interrupt.h>
40 #include <linux/init.h>
41 #include <linux/slab.h>
42 #include <sound/core.h>
48 /* WM8770 registers */
49 #define WM_DAC_ATTEN 0x00 /* DAC1-8 analog attenuation */
50 #define WM_DAC_MASTER_ATTEN 0x08 /* DAC master analog attenuation */
51 #define WM_DAC_DIG_ATTEN 0x09 /* DAC1-8 digital attenuation */
52 #define WM_DAC_DIG_MASTER_ATTEN 0x11 /* DAC master digital attenuation */
53 #define WM_PHASE_SWAP 0x12 /* DAC phase */
54 #define WM_DAC_CTRL1 0x13 /* DAC control bits */
55 #define WM_MUTE 0x14 /* mute controls */
56 #define WM_DAC_CTRL2 0x15 /* de-emphasis and zefo-flag */
57 #define WM_INT_CTRL 0x16 /* interface control */
58 #define WM_MASTER 0x17 /* master clock and mode */
59 #define WM_POWERDOWN 0x18 /* power-down controls */
60 #define WM_ADC_GAIN 0x19 /* ADC gain L(19)/R(1a) */
61 #define WM_ADC_MUX 0x1b /* input MUX */
62 #define WM_OUT_MUX1 0x1c /* output MUX */
63 #define WM_OUT_MUX2 0x1e /* output MUX */
64 #define WM_RESET 0x1f /* software reset */
68 * Logarithmic volume values for WM8770
69 * Computed as 20 * Log10(255 / x)
71 static unsigned char wm_vol[256] = {
72 127, 48, 42, 39, 36, 34, 33, 31, 30, 29, 28, 27, 27, 26, 25, 25, 24, 24, 23,
73 23, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 18, 17, 17, 17,
74 17, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13,
75 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
76 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8,
77 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6,
78 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
79 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3,
80 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
81 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
82 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
86 #define WM_VOL_MAX (sizeof(wm_vol) - 1)
87 #define WM_VOL_MUTE 0x8000
89 static struct snd_akm4xxx akm_phase22 __devinitdata = {
95 static struct snd_ak4xxx_private akm_phase22_priv __devinitdata = {
107 static int __devinit phase22_init(struct snd_ice1712 *ice)
109 struct snd_akm4xxx *ak;
112 // Configure DAC/ADC description for generic part of ice1724
113 switch (ice->eeprom.subvendor) {
114 case VT1724_SUBDEVICE_PHASE22:
115 ice->num_total_dacs = 2;
116 ice->num_total_adcs = 2;
117 ice->vt1720 = 1; // Envy24HT-S have 16 bit wide GPIO
124 // Initialize analog chips
125 ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
129 switch (ice->eeprom.subvendor) {
130 case VT1724_SUBDEVICE_PHASE22:
131 if ((err = snd_ice1712_akm4xxx_init(ak, &akm_phase22, &akm_phase22_priv, ice)) < 0)
139 static int __devinit phase22_add_controls(struct snd_ice1712 *ice)
143 switch (ice->eeprom.subvendor) {
144 case VT1724_SUBDEVICE_PHASE22:
145 err = snd_ice1712_akm4xxx_build_controls(ice);
152 static unsigned char phase22_eeprom[] __devinitdata = {
153 0x00, /* SYSCONF: 1xADC, 1xDACs */
154 0x80, /* ACLINK: I2S */
155 0xf8, /* I2S: vol, 96k, 24bit*/
156 0xc3, /* SPDIF: out-en, out-int, spdif-in */
158 0xFF, /* GPIO_DIR1 */
159 0xFF, /* GPIO_DIR2 */
160 0x00, /* GPIO_MASK */
161 0x00, /* GPIO_MASK1 */
162 0x00, /* GPIO_MASK2 */
163 0x00, /* GPIO_STATE: */
164 0x00, /* GPIO_STATE1: */
165 0x00, /* GPIO_STATE2 */
168 static unsigned char phase28_eeprom[] __devinitdata = {
169 0x0b, /* SYSCONF: clock 512, spdif-in/ADC, 4DACs */
170 0x80, /* ACLINK: I2S */
171 0xfc, /* I2S: vol, 96k, 24bit, 192k */
172 0xc3, /* SPDIF: out-en, out-int, spdif-in */
174 0xff, /* GPIO_DIR1 */
175 0x5f, /* GPIO_DIR2 */
176 0x00, /* GPIO_MASK */
177 0x00, /* GPIO_MASK1 */
178 0x00, /* GPIO_MASK2 */
179 0x00, /* GPIO_STATE */
180 0x00, /* GPIO_STATE1 */
181 0x00, /* GPIO_STATE2 */
185 * write data in the SPI mode
187 static void phase28_spi_write(struct snd_ice1712 *ice, unsigned int cs, unsigned int data, int bits)
192 tmp = snd_ice1712_gpio_read(ice);
194 snd_ice1712_gpio_set_mask(ice, ~(PHASE28_WM_RW|PHASE28_SPI_MOSI|PHASE28_SPI_CLK|
196 tmp |= PHASE28_WM_RW;
198 snd_ice1712_gpio_write(ice, tmp);
201 for (i = bits - 1; i >= 0; i--) {
202 tmp &= ~PHASE28_SPI_CLK;
203 snd_ice1712_gpio_write(ice, tmp);
206 tmp |= PHASE28_SPI_MOSI;
208 tmp &= ~PHASE28_SPI_MOSI;
209 snd_ice1712_gpio_write(ice, tmp);
211 tmp |= PHASE28_SPI_CLK;
212 snd_ice1712_gpio_write(ice, tmp);
216 tmp &= ~PHASE28_SPI_CLK;
218 snd_ice1712_gpio_write(ice, tmp);
220 tmp |= PHASE28_SPI_CLK;
221 snd_ice1712_gpio_write(ice, tmp);
226 * get the current register value of WM codec
228 static unsigned short wm_get(struct snd_ice1712 *ice, int reg)
231 return ((unsigned short)ice->akm[0].images[reg] << 8) |
232 ice->akm[0].images[reg + 1];
236 * set the register value of WM codec
238 static void wm_put_nocache(struct snd_ice1712 *ice, int reg, unsigned short val)
240 phase28_spi_write(ice, PHASE28_WM_CS, (reg << 9) | (val & 0x1ff), 16);
244 * set the register value of WM codec and remember it
246 static void wm_put(struct snd_ice1712 *ice, int reg, unsigned short val)
248 wm_put_nocache(ice, reg, val);
250 ice->akm[0].images[reg] = val >> 8;
251 ice->akm[0].images[reg + 1] = val;
254 static void wm_set_vol(struct snd_ice1712 *ice, unsigned int index, unsigned short vol, unsigned short master)
258 if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE))
261 nvol = 127 - wm_vol[(((vol & ~WM_VOL_MUTE) * (master & ~WM_VOL_MUTE)) / 127) & WM_VOL_MAX];
263 wm_put(ice, index, nvol);
264 wm_put_nocache(ice, index, 0x180 | nvol);
270 #define wm_pcm_mute_info phase28_mono_bool_info
272 static int wm_pcm_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
274 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
276 down(&ice->gpio_mutex);
277 ucontrol->value.integer.value[0] = (wm_get(ice, WM_MUTE) & 0x10) ? 0 : 1;
278 up(&ice->gpio_mutex);
282 static int wm_pcm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
284 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
285 unsigned short nval, oval;
288 snd_ice1712_save_gpio_status(ice);
289 oval = wm_get(ice, WM_MUTE);
290 nval = (oval & ~0x10) | (ucontrol->value.integer.value[0] ? 0 : 0x10);
291 if ((change = (nval != oval)))
292 wm_put(ice, WM_MUTE, nval);
293 snd_ice1712_restore_gpio_status(ice);
299 * Master volume attenuation mixer control
301 static int wm_master_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
303 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
305 uinfo->value.integer.min = 0;
306 uinfo->value.integer.max = WM_VOL_MAX;
310 static int wm_master_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
312 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
315 ucontrol->value.integer.value[i] = ice->spec.phase28.master[i] & ~WM_VOL_MUTE;
319 static int wm_master_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
321 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
324 snd_ice1712_save_gpio_status(ice);
325 for (ch = 0; ch < 2; ch++) {
326 if (ucontrol->value.integer.value[ch] != ice->spec.phase28.master[ch]) {
328 ice->spec.phase28.master[ch] &= WM_VOL_MUTE;
329 ice->spec.phase28.master[ch] |= ucontrol->value.integer.value[ch];
330 for (dac = 0; dac < ice->num_total_dacs; dac += 2)
331 wm_set_vol(ice, WM_DAC_ATTEN + dac + ch,
332 ice->spec.phase28.vol[dac + ch],
333 ice->spec.phase28.master[ch]);
337 snd_ice1712_restore_gpio_status(ice);
341 static int __devinit phase28_init(struct snd_ice1712 *ice)
343 static unsigned short wm_inits_phase28[] = {
344 /* These come first to reduce init pop noise */
345 0x1b, 0x044, /* ADC Mux (AC'97 source) */
346 0x1c, 0x00B, /* Out Mux1 (VOUT1 = DAC+AUX, VOUT2 = DAC) */
347 0x1d, 0x009, /* Out Mux2 (VOUT2 = DAC, VOUT3 = DAC) */
349 0x18, 0x000, /* All power-up */
351 0x16, 0x122, /* I2S, normal polarity, 24bit */
352 0x17, 0x022, /* 256fs, slave mode */
353 0x00, 0, /* DAC1 analog mute */
354 0x01, 0, /* DAC2 analog mute */
355 0x02, 0, /* DAC3 analog mute */
356 0x03, 0, /* DAC4 analog mute */
357 0x04, 0, /* DAC5 analog mute */
358 0x05, 0, /* DAC6 analog mute */
359 0x06, 0, /* DAC7 analog mute */
360 0x07, 0, /* DAC8 analog mute */
361 0x08, 0x100, /* master analog mute */
362 0x09, 0xff, /* DAC1 digital full */
363 0x0a, 0xff, /* DAC2 digital full */
364 0x0b, 0xff, /* DAC3 digital full */
365 0x0c, 0xff, /* DAC4 digital full */
366 0x0d, 0xff, /* DAC5 digital full */
367 0x0e, 0xff, /* DAC6 digital full */
368 0x0f, 0xff, /* DAC7 digital full */
369 0x10, 0xff, /* DAC8 digital full */
370 0x11, 0x1ff, /* master digital full */
371 0x12, 0x000, /* phase normal */
372 0x13, 0x090, /* unmute DAC L/R */
373 0x14, 0x000, /* all unmute */
374 0x15, 0x000, /* no deemphasis, no ZFLG */
375 0x19, 0x000, /* -12dB ADC/L */
376 0x1a, 0x000, /* -12dB ADC/R */
381 struct snd_akm4xxx *ak;
385 ice->num_total_dacs = 8;
386 ice->num_total_adcs = 2;
388 // Initialize analog chips
389 ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
394 snd_ice1712_gpio_set_dir(ice, 0x5fffff); /* fix this for the time being */
396 /* reset the wm codec as the SPI mode */
397 snd_ice1712_save_gpio_status(ice);
398 snd_ice1712_gpio_set_mask(ice, ~(PHASE28_WM_RESET|PHASE28_WM_CS|PHASE28_HP_SEL));
400 tmp = snd_ice1712_gpio_read(ice);
401 tmp &= ~PHASE28_WM_RESET;
402 snd_ice1712_gpio_write(ice, tmp);
404 tmp |= PHASE28_WM_CS;
405 snd_ice1712_gpio_write(ice, tmp);
407 tmp |= PHASE28_WM_RESET;
408 snd_ice1712_gpio_write(ice, tmp);
411 p = wm_inits_phase28;
412 for (; *p != (unsigned short)-1; p += 2)
413 wm_put(ice, p[0], p[1]);
415 snd_ice1712_restore_gpio_status(ice);
417 ice->spec.phase28.master[0] = WM_VOL_MUTE;
418 ice->spec.phase28.master[1] = WM_VOL_MUTE;
419 for (i = 0; i < ice->num_total_dacs; i++) {
420 ice->spec.phase28.vol[i] = WM_VOL_MUTE;
421 wm_set_vol(ice, i, ice->spec.phase28.vol[i], ice->spec.phase28.master[i % 2]);
428 * DAC volume attenuation mixer control
430 static int wm_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
432 int voices = kcontrol->private_value >> 8;
433 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
434 uinfo->count = voices;
435 uinfo->value.integer.min = 0; /* mute (-101dB) */
436 uinfo->value.integer.max = 0x7F; /* 0dB */
440 static int wm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
442 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
445 voices = kcontrol->private_value >> 8;
446 ofs = kcontrol->private_value & 0xff;
447 for (i = 0; i < voices; i++)
448 ucontrol->value.integer.value[i] = ice->spec.phase28.vol[ofs+i] & ~WM_VOL_MUTE;
452 static int wm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
454 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
455 int i, idx, ofs, voices;
458 voices = kcontrol->private_value >> 8;
459 ofs = kcontrol->private_value & 0xff;
460 snd_ice1712_save_gpio_status(ice);
461 for (i = 0; i < voices; i++) {
462 idx = WM_DAC_ATTEN + ofs + i;
463 if (ucontrol->value.integer.value[i] != ice->spec.phase28.vol[ofs+i]) {
464 ice->spec.phase28.vol[ofs+i] &= WM_VOL_MUTE;
465 ice->spec.phase28.vol[ofs+i] |= ucontrol->value.integer.value[i];
466 wm_set_vol(ice, idx, ice->spec.phase28.vol[ofs+i],
467 ice->spec.phase28.master[i]);
471 snd_ice1712_restore_gpio_status(ice);
476 * WM8770 mute control
478 static int wm_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) {
479 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
480 uinfo->count = kcontrol->private_value >> 8;
481 uinfo->value.integer.min = 0;
482 uinfo->value.integer.max = 1;
486 static int wm_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
488 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
491 voices = kcontrol->private_value >> 8;
492 ofs = kcontrol->private_value & 0xFF;
494 for (i = 0; i < voices; i++)
495 ucontrol->value.integer.value[i] = (ice->spec.phase28.vol[ofs+i] & WM_VOL_MUTE) ? 0 : 1;
499 static int wm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
501 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
502 int change = 0, voices, ofs, i;
504 voices = kcontrol->private_value >> 8;
505 ofs = kcontrol->private_value & 0xFF;
507 snd_ice1712_save_gpio_status(ice);
508 for (i = 0; i < voices; i++) {
509 int val = (ice->spec.phase28.vol[ofs + i] & WM_VOL_MUTE) ? 0 : 1;
510 if (ucontrol->value.integer.value[i] != val) {
511 ice->spec.phase28.vol[ofs + i] &= ~WM_VOL_MUTE;
512 ice->spec.phase28.vol[ofs + i] |=
513 ucontrol->value.integer.value[i] ? 0 : WM_VOL_MUTE;
514 wm_set_vol(ice, ofs + i, ice->spec.phase28.vol[ofs + i],
515 ice->spec.phase28.master[i]);
519 snd_ice1712_restore_gpio_status(ice);
525 * WM8770 master mute control
527 static int wm_master_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) {
528 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
530 uinfo->value.integer.min = 0;
531 uinfo->value.integer.max = 1;
535 static int wm_master_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
537 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
539 ucontrol->value.integer.value[0] = (ice->spec.phase28.master[0] & WM_VOL_MUTE) ? 0 : 1;
540 ucontrol->value.integer.value[1] = (ice->spec.phase28.master[1] & WM_VOL_MUTE) ? 0 : 1;
544 static int wm_master_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
546 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
549 snd_ice1712_save_gpio_status(ice);
550 for (i = 0; i < 2; i++) {
551 int val = (ice->spec.phase28.master[i] & WM_VOL_MUTE) ? 0 : 1;
552 if (ucontrol->value.integer.value[i] != val) {
554 ice->spec.phase28.master[i] &= ~WM_VOL_MUTE;
555 ice->spec.phase28.master[i] |=
556 ucontrol->value.integer.value[i] ? 0 : WM_VOL_MUTE;
557 for (dac = 0; dac < ice->num_total_dacs; dac += 2)
558 wm_set_vol(ice, WM_DAC_ATTEN + dac + i,
559 ice->spec.phase28.vol[dac + i],
560 ice->spec.phase28.master[i]);
564 snd_ice1712_restore_gpio_status(ice);
569 /* digital master volume */
571 #define PCM_RES 128 /* -64dB */
572 #define PCM_MIN (PCM_0dB - PCM_RES)
573 static int wm_pcm_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
575 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
577 uinfo->value.integer.min = 0; /* mute (-64dB) */
578 uinfo->value.integer.max = PCM_RES; /* 0dB */
582 static int wm_pcm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
584 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
587 down(&ice->gpio_mutex);
588 val = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff;
589 val = val > PCM_MIN ? (val - PCM_MIN) : 0;
590 ucontrol->value.integer.value[0] = val;
591 up(&ice->gpio_mutex);
595 static int wm_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
597 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
598 unsigned short ovol, nvol;
601 snd_ice1712_save_gpio_status(ice);
602 nvol = ucontrol->value.integer.value[0];
603 nvol = (nvol ? (nvol + PCM_MIN) : 0) & 0xff;
604 ovol = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff;
606 wm_put(ice, WM_DAC_DIG_MASTER_ATTEN, nvol); /* prelatch */
607 wm_put_nocache(ice, WM_DAC_DIG_MASTER_ATTEN, nvol | 0x100); /* update */
610 snd_ice1712_restore_gpio_status(ice);
616 static int phase28_mono_bool_info(struct snd_kcontrol *k, struct snd_ctl_elem_info *uinfo)
618 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
620 uinfo->value.integer.min = 0;
621 uinfo->value.integer.max = 1;
628 #define phase28_deemp_info phase28_mono_bool_info
630 static int phase28_deemp_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
632 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
633 ucontrol->value.integer.value[0] = (wm_get(ice, WM_DAC_CTRL2) & 0xf) == 0xf;
637 static int phase28_deemp_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
639 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
641 temp2 = temp = wm_get(ice, WM_DAC_CTRL2);
642 if (ucontrol->value.integer.value[0])
647 wm_put(ice, WM_DAC_CTRL2, temp);
656 static int phase28_oversampling_info(struct snd_kcontrol *k, struct snd_ctl_elem_info *uinfo)
658 static char *texts[2] = { "128x", "64x" };
660 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
662 uinfo->value.enumerated.items = 2;
664 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
665 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
666 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
671 static int phase28_oversampling_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
673 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
674 ucontrol->value.enumerated.item[0] = (wm_get(ice, WM_MASTER) & 0x8) == 0x8;
678 static int phase28_oversampling_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
681 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
683 temp2 = temp = wm_get(ice, WM_MASTER);
685 if (ucontrol->value.enumerated.item[0])
691 wm_put(ice, WM_MASTER, temp);
697 static struct snd_kcontrol_new phase28_dac_controls[] __devinitdata = {
699 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
700 .name = "Master Playback Switch",
701 .info = wm_master_mute_info,
702 .get = wm_master_mute_get,
703 .put = wm_master_mute_put
706 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
707 .name = "Master Playback Volume",
708 .info = wm_master_vol_info,
709 .get = wm_master_vol_get,
710 .put = wm_master_vol_put
713 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
714 .name = "Front Playback Switch",
715 .info = wm_mute_info,
718 .private_value = (2 << 8) | 0
721 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
722 .name = "Front Playback Volume",
726 .private_value = (2 << 8) | 0
729 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
730 .name = "Rear Playback Switch",
731 .info = wm_mute_info,
734 .private_value = (2 << 8) | 2
737 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
738 .name = "Rear Playback Volume",
742 .private_value = (2 << 8) | 2
745 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
746 .name = "Center Playback Switch",
747 .info = wm_mute_info,
750 .private_value = (1 << 8) | 4
753 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
754 .name = "Center Playback Volume",
758 .private_value = (1 << 8) | 4
761 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
762 .name = "LFE Playback Switch",
763 .info = wm_mute_info,
766 .private_value = (1 << 8) | 5
769 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
770 .name = "LFE Playback Volume",
774 .private_value = (1 << 8) | 5
777 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
778 .name = "Side Playback Switch",
779 .info = wm_mute_info,
782 .private_value = (2 << 8) | 6
785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
786 .name = "Side Playback Volume",
790 .private_value = (2 << 8) | 6
794 static struct snd_kcontrol_new wm_controls[] __devinitdata = {
796 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
797 .name = "PCM Playback Switch",
798 .info = wm_pcm_mute_info,
799 .get = wm_pcm_mute_get,
800 .put = wm_pcm_mute_put
803 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
804 .name = "PCM Playback Volume",
805 .info = wm_pcm_vol_info,
806 .get = wm_pcm_vol_get,
807 .put = wm_pcm_vol_put
810 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
811 .name = "DAC Deemphasis Switch",
812 .info = phase28_deemp_info,
813 .get = phase28_deemp_get,
814 .put = phase28_deemp_put
817 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
818 .name = "ADC Oversampling",
819 .info = phase28_oversampling_info,
820 .get = phase28_oversampling_get,
821 .put = phase28_oversampling_put
825 static int __devinit phase28_add_controls(struct snd_ice1712 *ice)
827 unsigned int i, counts;
830 counts = ARRAY_SIZE(phase28_dac_controls);
831 for (i = 0; i < counts; i++) {
832 err = snd_ctl_add(ice->card, snd_ctl_new1(&phase28_dac_controls[i], ice));
837 for (i = 0; i < ARRAY_SIZE(wm_controls); i++) {
838 err = snd_ctl_add(ice->card, snd_ctl_new1(&wm_controls[i], ice));
846 struct snd_ice1712_card_info snd_vt1724_phase_cards[] __devinitdata = {
848 .subvendor = VT1724_SUBDEVICE_PHASE22,
849 .name = "Terratec PHASE 22",
851 .chip_init = phase22_init,
852 .build_controls = phase22_add_controls,
853 .eeprom_size = sizeof(phase22_eeprom),
854 .eeprom_data = phase22_eeprom,
857 .subvendor = VT1724_SUBDEVICE_PHASE28,
858 .name = "Terratec PHASE 28",
860 .chip_init = phase28_init,
861 .build_controls = phase28_add_controls,
862 .eeprom_size = sizeof(phase28_eeprom),
863 .eeprom_data = phase28_eeprom,