2 * ALSA driver for ICEnsemble VT1724 (Envy24HT)
4 * Lowlevel functions for Audiotrak Prodigy 7.1 Hifi
7 * Copyright (c) 2007 Julian Scheel <julian@jusst.de>
8 * Copyright (c) 2007 allank
9 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <linux/delay.h>
30 #include <linux/interrupt.h>
31 #include <linux/init.h>
32 #include <linux/slab.h>
33 #include <linux/mutex.h>
35 #include <sound/core.h>
36 #include <sound/info.h>
37 #include <sound/tlv.h>
41 #include "prodigy_hifi.h"
46 /* WM8776 registers */
47 #define WM_HP_ATTEN_L 0x00 /* headphone left attenuation */
48 #define WM_HP_ATTEN_R 0x01 /* headphone left attenuation */
49 #define WM_HP_MASTER 0x02 /* headphone master (both channels),
51 #define WM_DAC_ATTEN_L 0x03 /* digital left attenuation */
52 #define WM_DAC_ATTEN_R 0x04
53 #define WM_DAC_MASTER 0x05
54 #define WM_PHASE_SWAP 0x06 /* DAC phase swap */
55 #define WM_DAC_CTRL1 0x07
56 #define WM_DAC_MUTE 0x08
57 #define WM_DAC_CTRL2 0x09
58 #define WM_DAC_INT 0x0a
59 #define WM_ADC_INT 0x0b
60 #define WM_MASTER_CTRL 0x0c
61 #define WM_POWERDOWN 0x0d
62 #define WM_ADC_ATTEN_L 0x0e
63 #define WM_ADC_ATTEN_R 0x0f
64 #define WM_ALC_CTRL1 0x10
65 #define WM_ALC_CTRL2 0x11
66 #define WM_ALC_CTRL3 0x12
67 #define WM_NOISE_GATE 0x13
68 #define WM_LIMITER 0x14
69 #define WM_ADC_MUX 0x15
70 #define WM_OUT_MUX 0x16
73 /* Analog Recording Source :- Mic, LineIn, CD/Video, */
75 /* implement capture source select control for WM8776 */
77 #define WM_AIN1 "AIN1"
78 #define WM_AIN2 "AIN2"
79 #define WM_AIN3 "AIN3"
80 #define WM_AIN4 "AIN4"
81 #define WM_AIN5 "AIN5"
83 /* GPIO pins of envy24ht connected to wm8766 */
84 #define WM8766_SPI_CLK (1<<17) /* CLK, Pin97 on ICE1724 */
85 #define WM8766_SPI_MD (1<<16) /* DATA VT1724 -> WM8766, Pin96 */
86 #define WM8766_SPI_ML (1<<18) /* Latch, Pin98 */
88 /* WM8766 registers */
89 #define WM8766_DAC_CTRL 0x02 /* DAC Control */
90 #define WM8766_INT_CTRL 0x03 /* Interface Control */
91 #define WM8766_DAC_CTRL2 0x09
92 #define WM8766_DAC_CTRL3 0x0a
93 #define WM8766_RESET 0x1f
94 #define WM8766_LDA1 0x00
95 #define WM8766_LDA2 0x04
96 #define WM8766_LDA3 0x06
97 #define WM8766_RDA1 0x01
98 #define WM8766_RDA2 0x05
99 #define WM8766_RDA3 0x07
100 #define WM8766_MUTE1 0x0C
101 #define WM8766_MUTE2 0x0F
107 #define AK4396_ADDR 0x00
108 #define AK4396_CSN (1 << 8) /* CSN->GPIO8, pin 75 */
109 #define AK4396_CCLK (1 << 9) /* CCLK->GPIO9, pin 76 */
110 #define AK4396_CDTI (1 << 10) /* CDTI->GPIO10, pin 77 */
112 /* ak4396 registers */
113 #define AK4396_CTRL1 0x00
114 #define AK4396_CTRL2 0x01
115 #define AK4396_CTRL3 0x02
116 #define AK4396_LCH_ATT 0x03
117 #define AK4396_RCH_ATT 0x04
121 * get the current register value of WM codec
123 static unsigned short wm_get(struct snd_ice1712 *ice, int reg)
126 return ((unsigned short)ice->akm[0].images[reg] << 8) |
127 ice->akm[0].images[reg + 1];
131 * set the register value of WM codec and remember it
133 static void wm_put_nocache(struct snd_ice1712 *ice, int reg, unsigned short val)
136 cval = (reg << 9) | val;
137 snd_vt1724_write_i2c(ice, WM_DEV, cval >> 8, cval & 0xff);
140 static void wm_put(struct snd_ice1712 *ice, int reg, unsigned short val)
142 wm_put_nocache(ice, reg, val);
144 ice->akm[0].images[reg] = val >> 8;
145 ice->akm[0].images[reg + 1] = val;
149 * write data in the SPI mode
152 static void set_gpio_bit(struct snd_ice1712 *ice, unsigned int bit, int val)
154 unsigned int tmp = snd_ice1712_gpio_read(ice);
159 snd_ice1712_gpio_write(ice, tmp);
163 * SPI implementation for WM8766 codec - only writing supported, no readback
166 static void wm8766_spi_send_word(struct snd_ice1712 *ice, unsigned int data)
169 for (i = 0; i < 16; i++) {
170 set_gpio_bit(ice, WM8766_SPI_CLK, 0);
172 set_gpio_bit(ice, WM8766_SPI_MD, data & 0x8000);
174 set_gpio_bit(ice, WM8766_SPI_CLK, 1);
180 static void wm8766_spi_write(struct snd_ice1712 *ice, unsigned int reg, unsigned int data)
184 snd_ice1712_gpio_set_dir(ice, WM8766_SPI_MD|
185 WM8766_SPI_CLK|WM8766_SPI_ML);
186 snd_ice1712_gpio_set_mask(ice, ~(WM8766_SPI_MD|
187 WM8766_SPI_CLK|WM8766_SPI_ML));
188 /* latch must be low when writing */
189 set_gpio_bit(ice, WM8766_SPI_ML, 0);
190 block = (reg << 9) | (data & 0x1ff);
191 wm8766_spi_send_word(ice, block); /* REGISTER ADDRESS */
193 set_gpio_bit(ice, WM8766_SPI_ML, 1);
196 snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask);
197 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
202 * serial interface for ak4396 - only writing supported, no readback
205 static void ak4396_send_word(struct snd_ice1712 *ice, unsigned int data)
208 for (i = 0; i < 16; i++) {
209 set_gpio_bit(ice, AK4396_CCLK, 0);
211 set_gpio_bit(ice, AK4396_CDTI, data & 0x8000);
213 set_gpio_bit(ice, AK4396_CCLK, 1);
219 static void ak4396_write(struct snd_ice1712 *ice, unsigned int reg, unsigned int data)
223 snd_ice1712_gpio_set_dir(ice, AK4396_CSN|AK4396_CCLK|AK4396_CDTI);
224 snd_ice1712_gpio_set_mask(ice, ~(AK4396_CSN|AK4396_CCLK|AK4396_CDTI));
225 /* latch must be low when writing */
226 set_gpio_bit(ice, AK4396_CSN, 0);
227 block = ((AK4396_ADDR & 0x03) << 14) | (1 << 13) |
228 ((reg & 0x1f) << 8) | (data & 0xff);
229 ak4396_send_word(ice, block); /* REGISTER ADDRESS */
231 set_gpio_bit(ice, AK4396_CSN, 1);
234 snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask);
235 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
246 * DAC volume attenuation mixer control (-64dB to 0dB)
249 static int ak4396_dac_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
251 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
253 uinfo->value.integer.min = 0; /* mute */
254 uinfo->value.integer.max = 0xFF; /* linear */
258 static int ak4396_dac_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
260 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
263 for (i = 0; i < 2; i++) {
264 ucontrol->value.integer.value[i] =ice->spec.prodigy_hd2.vol[i];
269 static int ak4396_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
271 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
275 mutex_lock(&ice->gpio_mutex);
276 for (i = 0; i < 2; i++) {
277 if (ucontrol->value.integer.value[i] !=
278 ice->spec.prodigy_hd2.vol[i]) {
279 ice->spec.prodigy_hd2.vol[i] =
280 ucontrol->value.integer.value[i];
281 ak4396_write(ice, AK4396_LCH_ATT+i,
282 (ice->spec.prodigy_hd2.vol[i] & 0xff));
286 mutex_unlock(&ice->gpio_mutex);
290 static const DECLARE_TLV_DB_SCALE(db_scale_wm_dac, -12700, 100, 1);
292 static struct snd_kcontrol_new prodigy_hd2_controls[] __devinitdata = {
294 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
295 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
296 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
297 .name = "Front Playback Volume",
298 .info = ak4396_dac_vol_info,
299 .get = ak4396_dac_vol_get,
300 .put = ak4396_dac_vol_put,
301 .tlv = { .p = db_scale_wm_dac },
306 /* --------------- */
309 * Logarithmic volume values for WM87*6
310 * Computed as 20 * Log10(255 / x)
312 static const unsigned char wm_vol[256] = {
313 127, 48, 42, 39, 36, 34, 33, 31, 30, 29, 28, 27, 27, 26, 25, 25, 24, 24, 23,
314 23, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 18, 17, 17, 17,
315 17, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13,
316 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
317 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8,
318 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,
319 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,
320 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,
321 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,
322 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,
323 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,
327 #define WM_VOL_MAX (sizeof(wm_vol) - 1)
328 #define WM_VOL_MUTE 0x8000
333 #define DAC_MIN (DAC_0dB - DAC_RES)
336 static void wm_set_vol(struct snd_ice1712 *ice, unsigned int index, unsigned short vol, unsigned short master)
340 if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE))
343 nvol = (((vol & ~WM_VOL_MUTE) * (master & ~WM_VOL_MUTE)) / 128)
345 nvol = (nvol ? (nvol + DAC_MIN) : 0) & 0xff;
348 wm_put(ice, index, nvol);
349 wm_put_nocache(ice, index, 0x100 | nvol);
352 static void wm8766_set_vol(struct snd_ice1712 *ice, unsigned int index, unsigned short vol, unsigned short master)
356 if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE))
359 nvol = (((vol & ~WM_VOL_MUTE) * (master & ~WM_VOL_MUTE)) / 128)
361 nvol = (nvol ? (nvol + DAC_MIN) : 0) & 0xff;
365 wm8766_spi_write(ice, index, (0x0100 | nvol));
370 * DAC volume attenuation mixer control (-64dB to 0dB)
373 static int wm_dac_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
375 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
377 uinfo->value.integer.min = 0; /* mute */
378 uinfo->value.integer.max = DAC_RES; /* 0dB, 0.5dB step */
382 static int wm_dac_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
384 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
387 for (i = 0; i < 2; i++) {
388 ucontrol->value.integer.value[i] =
389 ice->spec.prodigy_hifi.vol[2+i] & ~WM_VOL_MUTE;
394 static int wm_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
396 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
397 int i, idx, change = 0;
399 mutex_lock(&ice->gpio_mutex);
400 for (i = 0; i < 2; i++) {
401 if (ucontrol->value.integer.value[i] !=
402 ice->spec.prodigy_hifi.vol[2+i]) {
403 idx = WM_DAC_ATTEN_L + i;
404 ice->spec.prodigy_hifi.vol[2+i] &= WM_VOL_MUTE;
405 ice->spec.prodigy_hifi.vol[2+i] |=
406 ucontrol->value.integer.value[i];
407 wm_set_vol(ice, idx, ice->spec.prodigy_hifi.vol[2+i],
408 ice->spec.prodigy_hifi.master[i]);
412 mutex_unlock(&ice->gpio_mutex);
418 * WM8766 DAC volume attenuation mixer control
420 static int wm8766_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
422 int voices = kcontrol->private_value >> 8;
423 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
424 uinfo->count = voices;
425 uinfo->value.integer.min = 0; /* mute */
426 uinfo->value.integer.max = DAC_RES; /* 0dB */
430 static int wm8766_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
432 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
435 voices = kcontrol->private_value >> 8;
436 ofs = kcontrol->private_value & 0xff;
437 for (i = 0; i < voices; i++)
438 ucontrol->value.integer.value[i] =
439 ice->spec.prodigy_hifi.vol[ofs+i];
443 static int wm8766_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
445 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
446 int i, idx, ofs, voices;
449 voices = kcontrol->private_value >> 8;
450 ofs = kcontrol->private_value & 0xff;
451 mutex_lock(&ice->gpio_mutex);
452 for (i = 0; i < voices; i++) {
453 if (ucontrol->value.integer.value[i] !=
454 ice->spec.prodigy_hifi.vol[ofs+i]) {
455 idx = WM8766_LDA1 + ofs + i;
456 ice->spec.prodigy_hifi.vol[ofs+i] &= WM_VOL_MUTE;
457 ice->spec.prodigy_hifi.vol[ofs+i] |=
458 ucontrol->value.integer.value[i];
459 wm8766_set_vol(ice, idx,
460 ice->spec.prodigy_hifi.vol[ofs+i],
461 ice->spec.prodigy_hifi.master[i]);
465 mutex_unlock(&ice->gpio_mutex);
470 * Master volume attenuation mixer control / applied to WM8776+WM8766
472 static int wm_master_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
474 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
476 uinfo->value.integer.min = 0;
477 uinfo->value.integer.max = DAC_RES;
481 static int wm_master_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
483 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
486 ucontrol->value.integer.value[i] =
487 ice->spec.prodigy_hifi.master[i];
491 static int wm_master_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
493 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
496 mutex_lock(&ice->gpio_mutex);
497 for (ch = 0; ch < 2; ch++) {
498 if (ucontrol->value.integer.value[ch] !=
499 ice->spec.prodigy_hifi.master[ch]) {
500 ice->spec.prodigy_hifi.master[ch] &= 0x00;
501 ice->spec.prodigy_hifi.master[ch] |=
502 ucontrol->value.integer.value[ch];
504 /* Apply to front DAC */
505 wm_set_vol(ice, WM_DAC_ATTEN_L + ch,
506 ice->spec.prodigy_hifi.vol[2 + ch],
507 ice->spec.prodigy_hifi.master[ch]);
509 wm8766_set_vol(ice, WM8766_LDA1 + ch,
510 ice->spec.prodigy_hifi.vol[0 + ch],
511 ice->spec.prodigy_hifi.master[ch]);
513 wm8766_set_vol(ice, WM8766_LDA2 + ch,
514 ice->spec.prodigy_hifi.vol[4 + ch],
515 ice->spec.prodigy_hifi.master[ch]);
517 wm8766_set_vol(ice, WM8766_LDA3 + ch,
518 ice->spec.prodigy_hifi.vol[6 + ch],
519 ice->spec.prodigy_hifi.master[ch]);
523 mutex_unlock(&ice->gpio_mutex);
531 static int wm_adc_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
533 static char* texts[32] = {"NULL", WM_AIN1, WM_AIN2, WM_AIN1 "+" WM_AIN2,
534 WM_AIN3, WM_AIN1 "+" WM_AIN3, WM_AIN2 "+" WM_AIN3,
535 WM_AIN1 "+" WM_AIN2 "+" WM_AIN3,
536 WM_AIN4, WM_AIN1 "+" WM_AIN4, WM_AIN2 "+" WM_AIN4,
537 WM_AIN1 "+" WM_AIN2 "+" WM_AIN4,
538 WM_AIN3 "+" WM_AIN4, WM_AIN1 "+" WM_AIN3 "+" WM_AIN4,
539 WM_AIN2 "+" WM_AIN3 "+" WM_AIN4,
540 WM_AIN1 "+" WM_AIN2 "+" WM_AIN3 "+" WM_AIN4,
541 WM_AIN5, WM_AIN1 "+" WM_AIN5, WM_AIN2 "+" WM_AIN5,
542 WM_AIN1 "+" WM_AIN2 "+" WM_AIN5,
543 WM_AIN3 "+" WM_AIN5, WM_AIN1 "+" WM_AIN3 "+" WM_AIN5,
544 WM_AIN2 "+" WM_AIN3 "+" WM_AIN5,
545 WM_AIN1 "+" WM_AIN2 "+" WM_AIN3 "+" WM_AIN5,
546 WM_AIN4 "+" WM_AIN5, WM_AIN1 "+" WM_AIN4 "+" WM_AIN5,
547 WM_AIN2 "+" WM_AIN4 "+" WM_AIN5,
548 WM_AIN1 "+" WM_AIN2 "+" WM_AIN4 "+" WM_AIN5,
549 WM_AIN3 "+" WM_AIN4 "+" WM_AIN5,
550 WM_AIN1 "+" WM_AIN3 "+" WM_AIN4 "+" WM_AIN5,
551 WM_AIN2 "+" WM_AIN3 "+" WM_AIN4 "+" WM_AIN5,
552 WM_AIN1 "+" WM_AIN2 "+" WM_AIN3 "+" WM_AIN4 "+" WM_AIN5};
554 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
556 uinfo->value.enumerated.items = 32;
557 if (uinfo->value.enumerated.item > 31)
558 uinfo->value.enumerated.item = 31;
559 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
563 static int wm_adc_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
565 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
567 mutex_lock(&ice->gpio_mutex);
568 ucontrol->value.integer.value[0]=wm_get(ice, WM_ADC_MUX) & 0x1f;
569 mutex_unlock(&ice->gpio_mutex);
573 static int wm_adc_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
575 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
576 unsigned short oval, nval;
578 mutex_lock(&ice->gpio_mutex);
579 oval = wm_get(ice, WM_ADC_MUX);
580 nval = ( oval & 0xe0 ) | ucontrol->value.integer.value[0] ;
581 if ( nval != oval ) {
582 wm_put(ice, WM_ADC_MUX, nval);
584 mutex_unlock(&ice->gpio_mutex);
591 * ADC gain mixer control (-64dB to 0dB)
596 #define ADC_MIN (ADC_0dB - ADC_RES)
598 static int wm_adc_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
600 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
602 uinfo->value.integer.min = 0; /* mute (-64dB) */
603 uinfo->value.integer.max = ADC_RES; /* 0dB, 0.5dB step */
607 static int wm_adc_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
609 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
613 mutex_lock(&ice->gpio_mutex);
614 for (i = 0; i < 2; i++) {
615 val = wm_get(ice, WM_ADC_ATTEN_L + i) & 0xff;
616 val = val > ADC_MIN ? (val - ADC_MIN) : 0;
617 ucontrol->value.integer.value[i] = val;
619 mutex_unlock(&ice->gpio_mutex);
623 static int wm_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
625 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
626 unsigned short ovol, nvol;
627 int i, idx, change = 0;
629 mutex_lock(&ice->gpio_mutex);
630 for (i = 0; i < 2; i++) {
631 nvol = ucontrol->value.integer.value[i];
632 nvol = nvol ? (nvol + ADC_MIN) : 0;
633 idx = WM_ADC_ATTEN_L + i;
634 ovol = wm_get(ice, idx) & 0xff;
636 wm_put(ice, idx, nvol);
640 mutex_unlock(&ice->gpio_mutex);
645 * ADC input mux mixer control
647 static int wm_adc_mux_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
649 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
651 uinfo->value.integer.min = 0;
652 uinfo->value.integer.max = 1;
656 static int wm_adc_mux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
658 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
659 int bit = kcontrol->private_value;
661 mutex_lock(&ice->gpio_mutex);
662 ucontrol->value.integer.value[0] = (wm_get(ice, WM_ADC_MUX) & (1 << bit)) ? 1 : 0;
663 mutex_unlock(&ice->gpio_mutex);
667 static int wm_adc_mux_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
669 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
670 int bit = kcontrol->private_value;
671 unsigned short oval, nval;
674 mutex_lock(&ice->gpio_mutex);
675 nval = oval = wm_get(ice, WM_ADC_MUX);
676 if (ucontrol->value.integer.value[0])
680 change = nval != oval;
682 wm_put(ice, WM_ADC_MUX, nval);
684 mutex_unlock(&ice->gpio_mutex);
689 * Analog bypass (In -> Out)
691 static int wm_bypass_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
693 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
695 uinfo->value.integer.min = 0;
696 uinfo->value.integer.max = 1;
700 static int wm_bypass_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
702 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
704 mutex_lock(&ice->gpio_mutex);
705 ucontrol->value.integer.value[0] = (wm_get(ice, WM_OUT_MUX) & 0x04) ? 1 : 0;
706 mutex_unlock(&ice->gpio_mutex);
710 static int wm_bypass_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
712 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
713 unsigned short val, oval;
716 mutex_lock(&ice->gpio_mutex);
717 val = oval = wm_get(ice, WM_OUT_MUX);
718 if (ucontrol->value.integer.value[0])
723 wm_put(ice, WM_OUT_MUX, val);
726 mutex_unlock(&ice->gpio_mutex);
733 static int wm_chswap_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
735 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
737 uinfo->value.integer.min = 0;
738 uinfo->value.integer.max = 1;
742 static int wm_chswap_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
744 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
746 mutex_lock(&ice->gpio_mutex);
747 ucontrol->value.integer.value[0] =
748 (wm_get(ice, WM_DAC_CTRL1) & 0xf0) != 0x90;
749 mutex_unlock(&ice->gpio_mutex);
753 static int wm_chswap_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
755 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
756 unsigned short val, oval;
759 mutex_lock(&ice->gpio_mutex);
760 oval = wm_get(ice, WM_DAC_CTRL1);
762 if (ucontrol->value.integer.value[0])
767 wm_put(ice, WM_DAC_CTRL1, val);
768 wm_put_nocache(ice, WM_DAC_CTRL1, val);
771 mutex_unlock(&ice->gpio_mutex);
780 static struct snd_kcontrol_new prodigy_hifi_controls[] __devinitdata = {
782 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
783 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
784 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
785 .name = "Master Playback Volume",
786 .info = wm_master_vol_info,
787 .get = wm_master_vol_get,
788 .put = wm_master_vol_put,
789 .tlv = { .p = db_scale_wm_dac }
792 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
793 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
794 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
795 .name = "Front Playback Volume",
796 .info = wm_dac_vol_info,
797 .get = wm_dac_vol_get,
798 .put = wm_dac_vol_put,
799 .tlv = { .p = db_scale_wm_dac },
802 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
803 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
804 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
805 .name = "Rear Playback Volume",
806 .info = wm8766_vol_info,
807 .get = wm8766_vol_get,
808 .put = wm8766_vol_put,
809 .private_value = (2 << 8) | 0,
810 .tlv = { .p = db_scale_wm_dac },
813 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
814 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
815 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
816 .name = "Center Playback Volume",
817 .info = wm8766_vol_info,
818 .get = wm8766_vol_get,
819 .put = wm8766_vol_put,
820 .private_value = (1 << 8) | 4,
821 .tlv = { .p = db_scale_wm_dac }
824 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
825 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
826 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
827 .name = "LFE Playback Volume",
828 .info = wm8766_vol_info,
829 .get = wm8766_vol_get,
830 .put = wm8766_vol_put,
831 .private_value = (1 << 8) | 5,
832 .tlv = { .p = db_scale_wm_dac }
835 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
836 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
837 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
838 .name = "Side Playback Volume",
839 .info = wm8766_vol_info,
840 .get = wm8766_vol_get,
841 .put = wm8766_vol_put,
842 .private_value = (2 << 8) | 6,
843 .tlv = { .p = db_scale_wm_dac },
846 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
847 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
848 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
849 .name = "Capture Volume",
850 .info = wm_adc_vol_info,
851 .get = wm_adc_vol_get,
852 .put = wm_adc_vol_put,
853 .tlv = { .p = db_scale_wm_dac },
856 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
857 .name = "CD Capture Switch",
858 .info = wm_adc_mux_info,
859 .get = wm_adc_mux_get,
860 .put = wm_adc_mux_put,
864 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
865 .name = "Line Capture Switch",
866 .info = wm_adc_mux_info,
867 .get = wm_adc_mux_get,
868 .put = wm_adc_mux_put,
872 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
873 .name = "Analog Bypass Switch",
874 .info = wm_bypass_info,
875 .get = wm_bypass_get,
876 .put = wm_bypass_put,
879 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
880 .name = "Swap Output Channels",
881 .info = wm_chswap_info,
882 .get = wm_chswap_get,
883 .put = wm_chswap_put,
886 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
887 .name = "Analog Capture Source",
888 .info = wm_adc_mux_enum_info,
889 .get = wm_adc_mux_enum_get,
890 .put = wm_adc_mux_enum_put,
897 static void wm_proc_regs_write(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
899 struct snd_ice1712 *ice = (struct snd_ice1712 *)entry->private_data;
901 unsigned int reg, val;
902 mutex_lock(&ice->gpio_mutex);
903 while (!snd_info_get_line(buffer, line, sizeof(line))) {
904 if (sscanf(line, "%x %x", ®, &val) != 2)
906 if (reg <= 0x17 && val <= 0xffff)
907 wm_put(ice, reg, val);
909 mutex_unlock(&ice->gpio_mutex);
912 static void wm_proc_regs_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
914 struct snd_ice1712 *ice = (struct snd_ice1712 *)entry->private_data;
917 mutex_lock(&ice->gpio_mutex);
918 for (reg = 0; reg <= 0x17; reg++) {
919 val = wm_get(ice, reg);
920 snd_iprintf(buffer, "%02x = %04x\n", reg, val);
922 mutex_unlock(&ice->gpio_mutex);
925 static void wm_proc_init(struct snd_ice1712 *ice)
927 struct snd_info_entry *entry;
928 if (! snd_card_proc_new(ice->card, "wm_codec", &entry)) {
929 snd_info_set_text_ops(entry, ice, wm_proc_regs_read);
930 entry->mode |= S_IWUSR;
931 entry->c.text.write = wm_proc_regs_write;
935 static int __devinit prodigy_hifi_add_controls(struct snd_ice1712 *ice)
940 for (i = 0; i < ARRAY_SIZE(prodigy_hifi_controls); i++) {
941 err = snd_ctl_add(ice->card, snd_ctl_new1(&prodigy_hifi_controls[i], ice));
951 static int __devinit prodigy_hd2_add_controls(struct snd_ice1712 *ice)
956 for (i = 0; i < ARRAY_SIZE(prodigy_hd2_controls); i++) {
957 err = snd_ctl_add(ice->card, snd_ctl_new1(&prodigy_hd2_controls[i], ice));
969 * initialize the chip
971 static int __devinit prodigy_hifi_init(struct snd_ice1712 *ice)
973 static unsigned short wm_inits[] = {
974 /* These come first to reduce init pop noise */
975 WM_ADC_MUX, 0x0003, /* ADC mute */
976 /* 0x00c0 replaced by 0x0003 */
978 WM_DAC_MUTE, 0x0001, /* DAC softmute */
979 WM_DAC_CTRL1, 0x0000, /* DAC mute */
981 WM_POWERDOWN, 0x0008, /* All power-up except HP */
982 WM_RESET, 0x0000, /* reset */
984 static unsigned short wm_inits2[] = {
985 WM_MASTER_CTRL, 0x0022, /* 256fs, slave mode */
986 WM_DAC_INT, 0x0022, /* I2S, normal polarity, 24bit */
987 WM_ADC_INT, 0x0022, /* I2S, normal polarity, 24bit */
988 WM_DAC_CTRL1, 0x0090, /* DAC L/R */
989 WM_OUT_MUX, 0x0001, /* OUT DAC */
990 WM_HP_ATTEN_L, 0x0179, /* HP 0dB */
991 WM_HP_ATTEN_R, 0x0179, /* HP 0dB */
992 WM_DAC_ATTEN_L, 0x0000, /* DAC 0dB */
993 WM_DAC_ATTEN_L, 0x0100, /* DAC 0dB */
994 WM_DAC_ATTEN_R, 0x0000, /* DAC 0dB */
995 WM_DAC_ATTEN_R, 0x0100, /* DAC 0dB */
996 WM_PHASE_SWAP, 0x0000, /* phase normal */
998 WM_DAC_MASTER, 0x0100, /* DAC master muted */
1000 WM_DAC_CTRL2, 0x0000, /* no deemphasis, no ZFLG */
1001 WM_ADC_ATTEN_L, 0x0000, /* ADC muted */
1002 WM_ADC_ATTEN_R, 0x0000, /* ADC muted */
1004 WM_ALC_CTRL1, 0x007b, /* */
1005 WM_ALC_CTRL2, 0x0000, /* */
1006 WM_ALC_CTRL3, 0x0000, /* */
1007 WM_NOISE_GATE, 0x0000, /* */
1009 WM_DAC_MUTE, 0x0000, /* DAC unmute */
1010 WM_ADC_MUX, 0x0003, /* ADC unmute, both CD/Line On */
1012 static unsigned short wm8766_inits[] = {
1013 WM8766_RESET, 0x0000,
1014 WM8766_DAC_CTRL, 0x0120,
1015 WM8766_INT_CTRL, 0x0022, /* I2S Normal Mode, 24 bit */
1016 WM8766_DAC_CTRL2, 0x0001,
1017 WM8766_DAC_CTRL3, 0x0080,
1018 WM8766_LDA1, 0x0100,
1019 WM8766_LDA2, 0x0100,
1020 WM8766_LDA3, 0x0100,
1021 WM8766_RDA1, 0x0100,
1022 WM8766_RDA2, 0x0100,
1023 WM8766_RDA3, 0x0100,
1024 WM8766_MUTE1, 0x0000,
1025 WM8766_MUTE2, 0x0000,
1034 ice->num_total_dacs = 8;
1035 ice->num_total_adcs = 1;
1036 ice->akm_codecs = 2;
1038 /* HACK - use this as the SPDIF source.
1039 * don't call snd_ice1712_gpio_get/put(), otherwise it's overwritten
1041 ice->gpio.saved[0] = 0;
1042 /* to remeber the register values */
1044 ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
1047 ice->akm_codecs = 1;
1049 /* initialize WM8776 codec */
1050 for (i = 0; i < ARRAY_SIZE(wm_inits); i += 2)
1051 wm_put(ice, wm_inits[i], wm_inits[i+1]);
1052 schedule_timeout_uninterruptible(1);
1053 for (i = 0; i < ARRAY_SIZE(wm_inits2); i += 2)
1054 wm_put(ice, wm_inits2[i], wm_inits2[i+1]);
1056 /* initialize WM8766 codec */
1058 for (i = 0; i < ARRAY_SIZE(wm8766_inits); i += 2)
1059 wm8766_spi_write(ice, wm8766_inits[i], wm8766_inits[i+1]);
1067 * initialize the chip
1069 static int __devinit prodigy_hd2_init(struct snd_ice1712 *ice)
1071 static unsigned short ak4396_inits[] = {
1072 AK4396_CTRL1, 0x87, /* I2S Normal Mode, 24 bit */
1075 AK4396_LCH_ATT, 0x00,
1076 AK4396_RCH_ATT, 0x00,
1085 ice->num_total_dacs = 1;
1086 ice->num_total_adcs = 1;
1087 ice->akm_codecs = 1;
1089 /* HACK - use this as the SPDIF source.
1090 * don't call snd_ice1712_gpio_get/put(), otherwise it's overwritten
1092 ice->gpio.saved[0] = 0;
1093 /* to remeber the register values */
1095 ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
1098 ice->akm_codecs = 1;
1100 /* initialize ak4396 codec */
1102 ak4396_write(ice, AK4396_CTRL1, 0x86);
1104 ak4396_write(ice, AK4396_CTRL1, 0x87);
1106 for (i = 0; i < ARRAY_SIZE(ak4396_inits); i += 2)
1107 ak4396_write(ice, ak4396_inits[i], ak4396_inits[i+1]);
1113 static unsigned char prodigy71hifi_eeprom[] __devinitdata = {
1114 0x4b, /* SYSCONF: clock 512, spdif-in/ADC, 4DACs */
1115 0x80, /* ACLINK: I2S */
1116 0xfc, /* I2S: vol, 96k, 24bit, 192k */
1117 0xc3, /* SPDIF: out-en, out-int, spdif-in */
1118 0xff, /* GPIO_DIR */
1119 0xff, /* GPIO_DIR1 */
1120 0x5f, /* GPIO_DIR2 */
1121 0x00, /* GPIO_MASK */
1122 0x00, /* GPIO_MASK1 */
1123 0x00, /* GPIO_MASK2 */
1124 0x00, /* GPIO_STATE */
1125 0x00, /* GPIO_STATE1 */
1126 0x00, /* GPIO_STATE2 */
1129 static unsigned char prodigyhd2_eeprom[] __devinitdata = {
1130 0x4b, /* SYSCONF: clock 512, spdif-in/ADC, 4DACs */
1131 0x80, /* ACLINK: I2S */
1132 0xfc, /* I2S: vol, 96k, 24bit, 192k */
1133 0xc3, /* SPDIF: out-en, out-int, spdif-in */
1134 0xff, /* GPIO_DIR */
1135 0xff, /* GPIO_DIR1 */
1136 0x5f, /* GPIO_DIR2 */
1137 0x00, /* GPIO_MASK */
1138 0x00, /* GPIO_MASK1 */
1139 0x00, /* GPIO_MASK2 */
1140 0x00, /* GPIO_STATE */
1141 0x00, /* GPIO_STATE1 */
1142 0x00, /* GPIO_STATE2 */
1145 static unsigned char fortissimo4_eeprom[] __devinitdata = {
1146 0x43, /* SYSCONF: clock 512, ADC, 4DACs */
1147 0x80, /* ACLINK: I2S */
1148 0xfc, /* I2S: vol, 96k, 24bit, 192k */
1149 0xc1, /* SPDIF: out-en, out-int */
1150 0xff, /* GPIO_DIR */
1151 0xff, /* GPIO_DIR1 */
1152 0x5f, /* GPIO_DIR2 */
1153 0x00, /* GPIO_MASK */
1154 0x00, /* GPIO_MASK1 */
1155 0x00, /* GPIO_MASK2 */
1156 0x00, /* GPIO_STATE */
1157 0x00, /* GPIO_STATE1 */
1158 0x00, /* GPIO_STATE2 */
1162 struct snd_ice1712_card_info snd_vt1724_prodigy_hifi_cards[] __devinitdata = {
1164 .subvendor = VT1724_SUBDEVICE_PRODIGY_HIFI,
1165 .name = "Audiotrak Prodigy 7.1 HiFi",
1166 .model = "prodigy71hifi",
1167 .chip_init = prodigy_hifi_init,
1168 .build_controls = prodigy_hifi_add_controls,
1169 .eeprom_size = sizeof(prodigy71hifi_eeprom),
1170 .eeprom_data = prodigy71hifi_eeprom,
1171 .driver = "Prodigy71HIFI",
1174 .subvendor = VT1724_SUBDEVICE_PRODIGY_HD2,
1175 .name = "Audiotrak Prodigy HD2",
1176 .model = "prodigyhd2",
1177 .chip_init = prodigy_hd2_init,
1178 .build_controls = prodigy_hd2_add_controls,
1179 .eeprom_size = sizeof(prodigyhd2_eeprom),
1180 .eeprom_data = prodigyhd2_eeprom,
1181 .driver = "Prodigy71HD2",
1184 .subvendor = VT1724_SUBDEVICE_FORTISSIMO4,
1185 .name = "Hercules Fortissimo IV",
1186 .model = "fortissimo4",
1187 .chip_init = prodigy_hifi_init,
1188 .build_controls = prodigy_hifi_add_controls,
1189 .eeprom_size = sizeof(fortissimo4_eeprom),
1190 .eeprom_data = fortissimo4_eeprom,
1191 .driver = "Fortissimo4",
1193 { } /* terminator */