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"
43 struct prodigy_hifi_spec
{
44 unsigned short master
[2];
45 unsigned short vol
[8];
51 /* WM8776 registers */
52 #define WM_HP_ATTEN_L 0x00 /* headphone left attenuation */
53 #define WM_HP_ATTEN_R 0x01 /* headphone left attenuation */
54 #define WM_HP_MASTER 0x02 /* headphone master (both channels),
56 #define WM_DAC_ATTEN_L 0x03 /* digital left attenuation */
57 #define WM_DAC_ATTEN_R 0x04
58 #define WM_DAC_MASTER 0x05
59 #define WM_PHASE_SWAP 0x06 /* DAC phase swap */
60 #define WM_DAC_CTRL1 0x07
61 #define WM_DAC_MUTE 0x08
62 #define WM_DAC_CTRL2 0x09
63 #define WM_DAC_INT 0x0a
64 #define WM_ADC_INT 0x0b
65 #define WM_MASTER_CTRL 0x0c
66 #define WM_POWERDOWN 0x0d
67 #define WM_ADC_ATTEN_L 0x0e
68 #define WM_ADC_ATTEN_R 0x0f
69 #define WM_ALC_CTRL1 0x10
70 #define WM_ALC_CTRL2 0x11
71 #define WM_ALC_CTRL3 0x12
72 #define WM_NOISE_GATE 0x13
73 #define WM_LIMITER 0x14
74 #define WM_ADC_MUX 0x15
75 #define WM_OUT_MUX 0x16
78 /* Analog Recording Source :- Mic, LineIn, CD/Video, */
80 /* implement capture source select control for WM8776 */
82 #define WM_AIN1 "AIN1"
83 #define WM_AIN2 "AIN2"
84 #define WM_AIN3 "AIN3"
85 #define WM_AIN4 "AIN4"
86 #define WM_AIN5 "AIN5"
88 /* GPIO pins of envy24ht connected to wm8766 */
89 #define WM8766_SPI_CLK (1<<17) /* CLK, Pin97 on ICE1724 */
90 #define WM8766_SPI_MD (1<<16) /* DATA VT1724 -> WM8766, Pin96 */
91 #define WM8766_SPI_ML (1<<18) /* Latch, Pin98 */
93 /* WM8766 registers */
94 #define WM8766_DAC_CTRL 0x02 /* DAC Control */
95 #define WM8766_INT_CTRL 0x03 /* Interface Control */
96 #define WM8766_DAC_CTRL2 0x09
97 #define WM8766_DAC_CTRL3 0x0a
98 #define WM8766_RESET 0x1f
99 #define WM8766_LDA1 0x00
100 #define WM8766_LDA2 0x04
101 #define WM8766_LDA3 0x06
102 #define WM8766_RDA1 0x01
103 #define WM8766_RDA2 0x05
104 #define WM8766_RDA3 0x07
105 #define WM8766_MUTE1 0x0C
106 #define WM8766_MUTE2 0x0F
112 #define AK4396_ADDR 0x00
113 #define AK4396_CSN (1 << 8) /* CSN->GPIO8, pin 75 */
114 #define AK4396_CCLK (1 << 9) /* CCLK->GPIO9, pin 76 */
115 #define AK4396_CDTI (1 << 10) /* CDTI->GPIO10, pin 77 */
117 /* ak4396 registers */
118 #define AK4396_CTRL1 0x00
119 #define AK4396_CTRL2 0x01
120 #define AK4396_CTRL3 0x02
121 #define AK4396_LCH_ATT 0x03
122 #define AK4396_RCH_ATT 0x04
126 * get the current register value of WM codec
128 static unsigned short wm_get(struct snd_ice1712
*ice
, int reg
)
131 return ((unsigned short)ice
->akm
[0].images
[reg
] << 8) |
132 ice
->akm
[0].images
[reg
+ 1];
136 * set the register value of WM codec and remember it
138 static void wm_put_nocache(struct snd_ice1712
*ice
, int reg
, unsigned short val
)
141 cval
= (reg
<< 9) | val
;
142 snd_vt1724_write_i2c(ice
, WM_DEV
, cval
>> 8, cval
& 0xff);
145 static void wm_put(struct snd_ice1712
*ice
, int reg
, unsigned short val
)
147 wm_put_nocache(ice
, reg
, val
);
149 ice
->akm
[0].images
[reg
] = val
>> 8;
150 ice
->akm
[0].images
[reg
+ 1] = val
;
154 * write data in the SPI mode
157 static void set_gpio_bit(struct snd_ice1712
*ice
, unsigned int bit
, int val
)
159 unsigned int tmp
= snd_ice1712_gpio_read(ice
);
164 snd_ice1712_gpio_write(ice
, tmp
);
168 * SPI implementation for WM8766 codec - only writing supported, no readback
171 static void wm8766_spi_send_word(struct snd_ice1712
*ice
, unsigned int data
)
174 for (i
= 0; i
< 16; i
++) {
175 set_gpio_bit(ice
, WM8766_SPI_CLK
, 0);
177 set_gpio_bit(ice
, WM8766_SPI_MD
, data
& 0x8000);
179 set_gpio_bit(ice
, WM8766_SPI_CLK
, 1);
185 static void wm8766_spi_write(struct snd_ice1712
*ice
, unsigned int reg
,
190 snd_ice1712_gpio_set_dir(ice
, WM8766_SPI_MD
|
191 WM8766_SPI_CLK
|WM8766_SPI_ML
);
192 snd_ice1712_gpio_set_mask(ice
, ~(WM8766_SPI_MD
|
193 WM8766_SPI_CLK
|WM8766_SPI_ML
));
194 /* latch must be low when writing */
195 set_gpio_bit(ice
, WM8766_SPI_ML
, 0);
196 block
= (reg
<< 9) | (data
& 0x1ff);
197 wm8766_spi_send_word(ice
, block
); /* REGISTER ADDRESS */
199 set_gpio_bit(ice
, WM8766_SPI_ML
, 1);
202 snd_ice1712_gpio_set_mask(ice
, ice
->gpio
.write_mask
);
203 snd_ice1712_gpio_set_dir(ice
, ice
->gpio
.direction
);
208 * serial interface for ak4396 - only writing supported, no readback
211 static void ak4396_send_word(struct snd_ice1712
*ice
, unsigned int data
)
214 for (i
= 0; i
< 16; i
++) {
215 set_gpio_bit(ice
, AK4396_CCLK
, 0);
217 set_gpio_bit(ice
, AK4396_CDTI
, data
& 0x8000);
219 set_gpio_bit(ice
, AK4396_CCLK
, 1);
225 static void ak4396_write(struct snd_ice1712
*ice
, unsigned int reg
,
230 snd_ice1712_gpio_set_dir(ice
, AK4396_CSN
|AK4396_CCLK
|AK4396_CDTI
);
231 snd_ice1712_gpio_set_mask(ice
, ~(AK4396_CSN
|AK4396_CCLK
|AK4396_CDTI
));
232 /* latch must be low when writing */
233 set_gpio_bit(ice
, AK4396_CSN
, 0);
234 block
= ((AK4396_ADDR
& 0x03) << 14) | (1 << 13) |
235 ((reg
& 0x1f) << 8) | (data
& 0xff);
236 ak4396_send_word(ice
, block
); /* REGISTER ADDRESS */
238 set_gpio_bit(ice
, AK4396_CSN
, 1);
241 snd_ice1712_gpio_set_mask(ice
, ice
->gpio
.write_mask
);
242 snd_ice1712_gpio_set_dir(ice
, ice
->gpio
.direction
);
253 * DAC volume attenuation mixer control (-64dB to 0dB)
256 static int ak4396_dac_vol_info(struct snd_kcontrol
*kcontrol
,
257 struct snd_ctl_elem_info
*uinfo
)
259 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
261 uinfo
->value
.integer
.min
= 0; /* mute */
262 uinfo
->value
.integer
.max
= 0xFF; /* linear */
266 static int ak4396_dac_vol_get(struct snd_kcontrol
*kcontrol
,
267 struct snd_ctl_elem_value
*ucontrol
)
269 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
270 struct prodigy_hifi_spec
*spec
= ice
->spec
;
273 for (i
= 0; i
< 2; i
++)
274 ucontrol
->value
.integer
.value
[i
] = spec
->vol
[i
];
279 static int ak4396_dac_vol_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
281 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
282 struct prodigy_hifi_spec
*spec
= ice
->spec
;
286 mutex_lock(&ice
->gpio_mutex
);
287 for (i
= 0; i
< 2; i
++) {
288 if (ucontrol
->value
.integer
.value
[i
] != spec
->vol
[i
]) {
289 spec
->vol
[i
] = ucontrol
->value
.integer
.value
[i
];
290 ak4396_write(ice
, AK4396_LCH_ATT
+ i
,
291 spec
->vol
[i
] & 0xff);
295 mutex_unlock(&ice
->gpio_mutex
);
299 static const DECLARE_TLV_DB_SCALE(db_scale_wm_dac
, -12700, 100, 1);
300 static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale
, TLV_DB_GAIN_MUTE
, 0);
302 static struct snd_kcontrol_new prodigy_hd2_controls
[] __devinitdata
= {
304 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
305 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
306 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
307 .name
= "Front Playback Volume",
308 .info
= ak4396_dac_vol_info
,
309 .get
= ak4396_dac_vol_get
,
310 .put
= ak4396_dac_vol_put
,
311 .tlv
= { .p
= ak4396_db_scale
},
316 /* --------------- */
319 * Logarithmic volume values for WM87*6
320 * Computed as 20 * Log10(255 / x)
322 static const unsigned char wm_vol
[256] = {
323 127, 48, 42, 39, 36, 34, 33, 31, 30, 29, 28, 27, 27, 26, 25, 25, 24, 24, 23,
324 23, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 18, 17, 17, 17,
325 17, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13,
326 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
327 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8,
328 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,
329 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,
330 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,
331 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,
332 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,
333 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,
337 #define WM_VOL_MAX (sizeof(wm_vol) - 1)
338 #define WM_VOL_MUTE 0x8000
343 #define DAC_MIN (DAC_0dB - DAC_RES)
346 static void wm_set_vol(struct snd_ice1712
*ice
, unsigned int index
,
347 unsigned short vol
, unsigned short master
)
351 if ((master
& WM_VOL_MUTE
) || (vol
& WM_VOL_MUTE
))
354 nvol
= (((vol
& ~WM_VOL_MUTE
) * (master
& ~WM_VOL_MUTE
)) / 128)
356 nvol
= (nvol
? (nvol
+ DAC_MIN
) : 0) & 0xff;
359 wm_put(ice
, index
, nvol
);
360 wm_put_nocache(ice
, index
, 0x100 | nvol
);
363 static void wm8766_set_vol(struct snd_ice1712
*ice
, unsigned int index
,
364 unsigned short vol
, unsigned short master
)
368 if ((master
& WM_VOL_MUTE
) || (vol
& WM_VOL_MUTE
))
371 nvol
= (((vol
& ~WM_VOL_MUTE
) * (master
& ~WM_VOL_MUTE
)) / 128)
373 nvol
= (nvol
? (nvol
+ DAC_MIN
) : 0) & 0xff;
376 wm8766_spi_write(ice
, index
, (0x0100 | nvol
));
381 * DAC volume attenuation mixer control (-64dB to 0dB)
384 static int wm_dac_vol_info(struct snd_kcontrol
*kcontrol
,
385 struct snd_ctl_elem_info
*uinfo
)
387 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
389 uinfo
->value
.integer
.min
= 0; /* mute */
390 uinfo
->value
.integer
.max
= DAC_RES
; /* 0dB, 0.5dB step */
394 static int wm_dac_vol_get(struct snd_kcontrol
*kcontrol
,
395 struct snd_ctl_elem_value
*ucontrol
)
397 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
398 struct prodigy_hifi_spec
*spec
= ice
->spec
;
401 for (i
= 0; i
< 2; i
++)
402 ucontrol
->value
.integer
.value
[i
] =
403 spec
->vol
[2 + i
] & ~WM_VOL_MUTE
;
407 static int wm_dac_vol_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
409 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
410 struct prodigy_hifi_spec
*spec
= ice
->spec
;
411 int i
, idx
, change
= 0;
413 mutex_lock(&ice
->gpio_mutex
);
414 for (i
= 0; i
< 2; i
++) {
415 if (ucontrol
->value
.integer
.value
[i
] != spec
->vol
[2 + i
]) {
416 idx
= WM_DAC_ATTEN_L
+ i
;
417 spec
->vol
[2 + i
] &= WM_VOL_MUTE
;
418 spec
->vol
[2 + i
] |= ucontrol
->value
.integer
.value
[i
];
419 wm_set_vol(ice
, idx
, spec
->vol
[2 + i
], spec
->master
[i
]);
423 mutex_unlock(&ice
->gpio_mutex
);
429 * WM8766 DAC volume attenuation mixer control
431 static int wm8766_vol_info(struct snd_kcontrol
*kcontrol
,
432 struct snd_ctl_elem_info
*uinfo
)
434 int voices
= kcontrol
->private_value
>> 8;
435 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
436 uinfo
->count
= voices
;
437 uinfo
->value
.integer
.min
= 0; /* mute */
438 uinfo
->value
.integer
.max
= DAC_RES
; /* 0dB */
442 static int wm8766_vol_get(struct snd_kcontrol
*kcontrol
,
443 struct snd_ctl_elem_value
*ucontrol
)
445 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
446 struct prodigy_hifi_spec
*spec
= ice
->spec
;
449 voices
= kcontrol
->private_value
>> 8;
450 ofs
= kcontrol
->private_value
& 0xff;
451 for (i
= 0; i
< voices
; i
++)
452 ucontrol
->value
.integer
.value
[i
] = spec
->vol
[ofs
+ i
];
456 static int wm8766_vol_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
458 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
459 struct prodigy_hifi_spec
*spec
= ice
->spec
;
460 int i
, idx
, ofs
, voices
;
463 voices
= kcontrol
->private_value
>> 8;
464 ofs
= kcontrol
->private_value
& 0xff;
465 mutex_lock(&ice
->gpio_mutex
);
466 for (i
= 0; i
< voices
; i
++) {
467 if (ucontrol
->value
.integer
.value
[i
] != spec
->vol
[ofs
+ i
]) {
468 idx
= WM8766_LDA1
+ ofs
+ i
;
469 spec
->vol
[ofs
+ i
] &= WM_VOL_MUTE
;
470 spec
->vol
[ofs
+ i
] |= ucontrol
->value
.integer
.value
[i
];
471 wm8766_set_vol(ice
, idx
,
472 spec
->vol
[ofs
+ i
], spec
->master
[i
]);
476 mutex_unlock(&ice
->gpio_mutex
);
481 * Master volume attenuation mixer control / applied to WM8776+WM8766
483 static int wm_master_vol_info(struct snd_kcontrol
*kcontrol
,
484 struct snd_ctl_elem_info
*uinfo
)
486 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
488 uinfo
->value
.integer
.min
= 0;
489 uinfo
->value
.integer
.max
= DAC_RES
;
493 static int wm_master_vol_get(struct snd_kcontrol
*kcontrol
,
494 struct snd_ctl_elem_value
*ucontrol
)
496 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
497 struct prodigy_hifi_spec
*spec
= ice
->spec
;
499 for (i
= 0; i
< 2; i
++)
500 ucontrol
->value
.integer
.value
[i
] = spec
->master
[i
];
504 static int wm_master_vol_put(struct snd_kcontrol
*kcontrol
,
505 struct snd_ctl_elem_value
*ucontrol
)
507 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
508 struct prodigy_hifi_spec
*spec
= ice
->spec
;
511 mutex_lock(&ice
->gpio_mutex
);
512 for (ch
= 0; ch
< 2; ch
++) {
513 if (ucontrol
->value
.integer
.value
[ch
] != spec
->master
[ch
]) {
514 spec
->master
[ch
] = ucontrol
->value
.integer
.value
[ch
];
516 /* Apply to front DAC */
517 wm_set_vol(ice
, WM_DAC_ATTEN_L
+ ch
,
518 spec
->vol
[2 + ch
], spec
->master
[ch
]);
520 wm8766_set_vol(ice
, WM8766_LDA1
+ ch
,
521 spec
->vol
[0 + ch
], spec
->master
[ch
]);
523 wm8766_set_vol(ice
, WM8766_LDA2
+ ch
,
524 spec
->vol
[4 + ch
], spec
->master
[ch
]);
526 wm8766_set_vol(ice
, WM8766_LDA3
+ ch
,
527 spec
->vol
[6 + ch
], spec
->master
[ch
]);
531 mutex_unlock(&ice
->gpio_mutex
);
538 static int wm_adc_mux_enum_info(struct snd_kcontrol
*kcontrol
,
539 struct snd_ctl_elem_info
*uinfo
)
541 static char* texts
[32] = {
542 "NULL", WM_AIN1
, WM_AIN2
, WM_AIN1
"+" WM_AIN2
,
543 WM_AIN3
, WM_AIN1
"+" WM_AIN3
, WM_AIN2
"+" WM_AIN3
,
544 WM_AIN1
"+" WM_AIN2
"+" WM_AIN3
,
545 WM_AIN4
, WM_AIN1
"+" WM_AIN4
, WM_AIN2
"+" WM_AIN4
,
546 WM_AIN1
"+" WM_AIN2
"+" WM_AIN4
,
547 WM_AIN3
"+" WM_AIN4
, WM_AIN1
"+" WM_AIN3
"+" WM_AIN4
,
548 WM_AIN2
"+" WM_AIN3
"+" WM_AIN4
,
549 WM_AIN1
"+" WM_AIN2
"+" WM_AIN3
"+" WM_AIN4
,
550 WM_AIN5
, WM_AIN1
"+" WM_AIN5
, WM_AIN2
"+" WM_AIN5
,
551 WM_AIN1
"+" WM_AIN2
"+" WM_AIN5
,
552 WM_AIN3
"+" WM_AIN5
, WM_AIN1
"+" WM_AIN3
"+" WM_AIN5
,
553 WM_AIN2
"+" WM_AIN3
"+" WM_AIN5
,
554 WM_AIN1
"+" WM_AIN2
"+" WM_AIN3
"+" WM_AIN5
,
555 WM_AIN4
"+" WM_AIN5
, WM_AIN1
"+" WM_AIN4
"+" WM_AIN5
,
556 WM_AIN2
"+" WM_AIN4
"+" WM_AIN5
,
557 WM_AIN1
"+" WM_AIN2
"+" WM_AIN4
"+" WM_AIN5
,
558 WM_AIN3
"+" WM_AIN4
"+" WM_AIN5
,
559 WM_AIN1
"+" WM_AIN3
"+" WM_AIN4
"+" WM_AIN5
,
560 WM_AIN2
"+" WM_AIN3
"+" WM_AIN4
"+" WM_AIN5
,
561 WM_AIN1
"+" WM_AIN2
"+" WM_AIN3
"+" WM_AIN4
"+" WM_AIN5
564 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
566 uinfo
->value
.enumerated
.items
= 32;
567 if (uinfo
->value
.enumerated
.item
> 31)
568 uinfo
->value
.enumerated
.item
= 31;
569 strcpy(uinfo
->value
.enumerated
.name
,
570 texts
[uinfo
->value
.enumerated
.item
]);
574 static int wm_adc_mux_enum_get(struct snd_kcontrol
*kcontrol
,
575 struct snd_ctl_elem_value
*ucontrol
)
577 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
579 mutex_lock(&ice
->gpio_mutex
);
580 ucontrol
->value
.integer
.value
[0] = wm_get(ice
, WM_ADC_MUX
) & 0x1f;
581 mutex_unlock(&ice
->gpio_mutex
);
585 static int wm_adc_mux_enum_put(struct snd_kcontrol
*kcontrol
,
586 struct snd_ctl_elem_value
*ucontrol
)
588 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
589 unsigned short oval
, nval
;
592 mutex_lock(&ice
->gpio_mutex
);
593 oval
= wm_get(ice
, WM_ADC_MUX
);
594 nval
= (oval
& 0xe0) | ucontrol
->value
.integer
.value
[0];
596 wm_put(ice
, WM_ADC_MUX
, nval
);
599 mutex_unlock(&ice
->gpio_mutex
);
606 * ADC gain mixer control (-64dB to 0dB)
611 #define ADC_MIN (ADC_0dB - ADC_RES)
613 static int wm_adc_vol_info(struct snd_kcontrol
*kcontrol
,
614 struct snd_ctl_elem_info
*uinfo
)
616 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
618 uinfo
->value
.integer
.min
= 0; /* mute (-64dB) */
619 uinfo
->value
.integer
.max
= ADC_RES
; /* 0dB, 0.5dB step */
623 static int wm_adc_vol_get(struct snd_kcontrol
*kcontrol
,
624 struct snd_ctl_elem_value
*ucontrol
)
626 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
630 mutex_lock(&ice
->gpio_mutex
);
631 for (i
= 0; i
< 2; i
++) {
632 val
= wm_get(ice
, WM_ADC_ATTEN_L
+ i
) & 0xff;
633 val
= val
> ADC_MIN
? (val
- ADC_MIN
) : 0;
634 ucontrol
->value
.integer
.value
[i
] = val
;
636 mutex_unlock(&ice
->gpio_mutex
);
640 static int wm_adc_vol_put(struct snd_kcontrol
*kcontrol
,
641 struct snd_ctl_elem_value
*ucontrol
)
643 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
644 unsigned short ovol
, nvol
;
645 int i
, idx
, change
= 0;
647 mutex_lock(&ice
->gpio_mutex
);
648 for (i
= 0; i
< 2; i
++) {
649 nvol
= ucontrol
->value
.integer
.value
[i
];
650 nvol
= nvol
? (nvol
+ ADC_MIN
) : 0;
651 idx
= WM_ADC_ATTEN_L
+ i
;
652 ovol
= wm_get(ice
, idx
) & 0xff;
654 wm_put(ice
, idx
, nvol
);
658 mutex_unlock(&ice
->gpio_mutex
);
663 * ADC input mux mixer control
665 #define wm_adc_mux_info snd_ctl_boolean_mono_info
667 static int wm_adc_mux_get(struct snd_kcontrol
*kcontrol
,
668 struct snd_ctl_elem_value
*ucontrol
)
670 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
671 int bit
= kcontrol
->private_value
;
673 mutex_lock(&ice
->gpio_mutex
);
674 ucontrol
->value
.integer
.value
[0] =
675 (wm_get(ice
, WM_ADC_MUX
) & (1 << bit
)) ? 1 : 0;
676 mutex_unlock(&ice
->gpio_mutex
);
680 static int wm_adc_mux_put(struct snd_kcontrol
*kcontrol
,
681 struct snd_ctl_elem_value
*ucontrol
)
683 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
684 int bit
= kcontrol
->private_value
;
685 unsigned short oval
, nval
;
688 mutex_lock(&ice
->gpio_mutex
);
689 nval
= oval
= wm_get(ice
, WM_ADC_MUX
);
690 if (ucontrol
->value
.integer
.value
[0])
694 change
= nval
!= oval
;
696 wm_put(ice
, WM_ADC_MUX
, nval
);
698 mutex_unlock(&ice
->gpio_mutex
);
703 * Analog bypass (In -> Out)
705 #define wm_bypass_info snd_ctl_boolean_mono_info
707 static int wm_bypass_get(struct snd_kcontrol
*kcontrol
,
708 struct snd_ctl_elem_value
*ucontrol
)
710 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
712 mutex_lock(&ice
->gpio_mutex
);
713 ucontrol
->value
.integer
.value
[0] =
714 (wm_get(ice
, WM_OUT_MUX
) & 0x04) ? 1 : 0;
715 mutex_unlock(&ice
->gpio_mutex
);
719 static int wm_bypass_put(struct snd_kcontrol
*kcontrol
,
720 struct snd_ctl_elem_value
*ucontrol
)
722 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
723 unsigned short val
, oval
;
726 mutex_lock(&ice
->gpio_mutex
);
727 val
= oval
= wm_get(ice
, WM_OUT_MUX
);
728 if (ucontrol
->value
.integer
.value
[0])
733 wm_put(ice
, WM_OUT_MUX
, val
);
736 mutex_unlock(&ice
->gpio_mutex
);
743 #define wm_chswap_info snd_ctl_boolean_mono_info
745 static int wm_chswap_get(struct snd_kcontrol
*kcontrol
,
746 struct snd_ctl_elem_value
*ucontrol
)
748 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
750 mutex_lock(&ice
->gpio_mutex
);
751 ucontrol
->value
.integer
.value
[0] =
752 (wm_get(ice
, WM_DAC_CTRL1
) & 0xf0) != 0x90;
753 mutex_unlock(&ice
->gpio_mutex
);
757 static int wm_chswap_put(struct snd_kcontrol
*kcontrol
,
758 struct snd_ctl_elem_value
*ucontrol
)
760 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
761 unsigned short val
, oval
;
764 mutex_lock(&ice
->gpio_mutex
);
765 oval
= wm_get(ice
, WM_DAC_CTRL1
);
767 if (ucontrol
->value
.integer
.value
[0])
772 wm_put(ice
, WM_DAC_CTRL1
, val
);
773 wm_put_nocache(ice
, WM_DAC_CTRL1
, val
);
776 mutex_unlock(&ice
->gpio_mutex
);
785 static struct snd_kcontrol_new prodigy_hifi_controls
[] __devinitdata
= {
787 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
788 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
789 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
790 .name
= "Master Playback Volume",
791 .info
= wm_master_vol_info
,
792 .get
= wm_master_vol_get
,
793 .put
= wm_master_vol_put
,
794 .tlv
= { .p
= db_scale_wm_dac
}
797 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
798 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
799 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
800 .name
= "Front Playback Volume",
801 .info
= wm_dac_vol_info
,
802 .get
= wm_dac_vol_get
,
803 .put
= wm_dac_vol_put
,
804 .tlv
= { .p
= db_scale_wm_dac
},
807 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
808 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
809 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
810 .name
= "Rear Playback Volume",
811 .info
= wm8766_vol_info
,
812 .get
= wm8766_vol_get
,
813 .put
= wm8766_vol_put
,
814 .private_value
= (2 << 8) | 0,
815 .tlv
= { .p
= db_scale_wm_dac
},
818 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
819 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
820 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
821 .name
= "Center Playback Volume",
822 .info
= wm8766_vol_info
,
823 .get
= wm8766_vol_get
,
824 .put
= wm8766_vol_put
,
825 .private_value
= (1 << 8) | 4,
826 .tlv
= { .p
= db_scale_wm_dac
}
829 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
830 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
831 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
832 .name
= "LFE Playback Volume",
833 .info
= wm8766_vol_info
,
834 .get
= wm8766_vol_get
,
835 .put
= wm8766_vol_put
,
836 .private_value
= (1 << 8) | 5,
837 .tlv
= { .p
= db_scale_wm_dac
}
840 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
841 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
842 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
843 .name
= "Side Playback Volume",
844 .info
= wm8766_vol_info
,
845 .get
= wm8766_vol_get
,
846 .put
= wm8766_vol_put
,
847 .private_value
= (2 << 8) | 6,
848 .tlv
= { .p
= db_scale_wm_dac
},
851 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
852 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
853 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
854 .name
= "Capture Volume",
855 .info
= wm_adc_vol_info
,
856 .get
= wm_adc_vol_get
,
857 .put
= wm_adc_vol_put
,
858 .tlv
= { .p
= db_scale_wm_dac
},
861 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
862 .name
= "CD Capture Switch",
863 .info
= wm_adc_mux_info
,
864 .get
= wm_adc_mux_get
,
865 .put
= wm_adc_mux_put
,
869 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
870 .name
= "Line Capture Switch",
871 .info
= wm_adc_mux_info
,
872 .get
= wm_adc_mux_get
,
873 .put
= wm_adc_mux_put
,
877 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
878 .name
= "Analog Bypass Switch",
879 .info
= wm_bypass_info
,
880 .get
= wm_bypass_get
,
881 .put
= wm_bypass_put
,
884 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
885 .name
= "Swap Output Channels",
886 .info
= wm_chswap_info
,
887 .get
= wm_chswap_get
,
888 .put
= wm_chswap_put
,
891 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
892 .name
= "Analog Capture Source",
893 .info
= wm_adc_mux_enum_info
,
894 .get
= wm_adc_mux_enum_get
,
895 .put
= wm_adc_mux_enum_put
,
902 static void wm_proc_regs_write(struct snd_info_entry
*entry
,
903 struct snd_info_buffer
*buffer
)
905 struct snd_ice1712
*ice
= entry
->private_data
;
907 unsigned int reg
, val
;
908 mutex_lock(&ice
->gpio_mutex
);
909 while (!snd_info_get_line(buffer
, line
, sizeof(line
))) {
910 if (sscanf(line
, "%x %x", ®
, &val
) != 2)
912 if (reg
<= 0x17 && val
<= 0xffff)
913 wm_put(ice
, reg
, val
);
915 mutex_unlock(&ice
->gpio_mutex
);
918 static void wm_proc_regs_read(struct snd_info_entry
*entry
,
919 struct snd_info_buffer
*buffer
)
921 struct snd_ice1712
*ice
= entry
->private_data
;
924 mutex_lock(&ice
->gpio_mutex
);
925 for (reg
= 0; reg
<= 0x17; reg
++) {
926 val
= wm_get(ice
, reg
);
927 snd_iprintf(buffer
, "%02x = %04x\n", reg
, val
);
929 mutex_unlock(&ice
->gpio_mutex
);
932 static void wm_proc_init(struct snd_ice1712
*ice
)
934 struct snd_info_entry
*entry
;
935 if (!snd_card_proc_new(ice
->card
, "wm_codec", &entry
)) {
936 snd_info_set_text_ops(entry
, ice
, wm_proc_regs_read
);
937 entry
->mode
|= S_IWUSR
;
938 entry
->c
.text
.write
= wm_proc_regs_write
;
942 static int __devinit
prodigy_hifi_add_controls(struct snd_ice1712
*ice
)
947 for (i
= 0; i
< ARRAY_SIZE(prodigy_hifi_controls
); i
++) {
948 err
= snd_ctl_add(ice
->card
,
949 snd_ctl_new1(&prodigy_hifi_controls
[i
], ice
));
959 static int __devinit
prodigy_hd2_add_controls(struct snd_ice1712
*ice
)
964 for (i
= 0; i
< ARRAY_SIZE(prodigy_hd2_controls
); i
++) {
965 err
= snd_ctl_add(ice
->card
,
966 snd_ctl_new1(&prodigy_hd2_controls
[i
], ice
));
978 * initialize the chip
980 static int __devinit
prodigy_hifi_init(struct snd_ice1712
*ice
)
982 static unsigned short wm_inits
[] = {
983 /* These come first to reduce init pop noise */
984 WM_ADC_MUX
, 0x0003, /* ADC mute */
985 /* 0x00c0 replaced by 0x0003 */
987 WM_DAC_MUTE
, 0x0001, /* DAC softmute */
988 WM_DAC_CTRL1
, 0x0000, /* DAC mute */
990 WM_POWERDOWN
, 0x0008, /* All power-up except HP */
991 WM_RESET
, 0x0000, /* reset */
993 static unsigned short wm_inits2
[] = {
994 WM_MASTER_CTRL
, 0x0022, /* 256fs, slave mode */
995 WM_DAC_INT
, 0x0022, /* I2S, normal polarity, 24bit */
996 WM_ADC_INT
, 0x0022, /* I2S, normal polarity, 24bit */
997 WM_DAC_CTRL1
, 0x0090, /* DAC L/R */
998 WM_OUT_MUX
, 0x0001, /* OUT DAC */
999 WM_HP_ATTEN_L
, 0x0179, /* HP 0dB */
1000 WM_HP_ATTEN_R
, 0x0179, /* HP 0dB */
1001 WM_DAC_ATTEN_L
, 0x0000, /* DAC 0dB */
1002 WM_DAC_ATTEN_L
, 0x0100, /* DAC 0dB */
1003 WM_DAC_ATTEN_R
, 0x0000, /* DAC 0dB */
1004 WM_DAC_ATTEN_R
, 0x0100, /* DAC 0dB */
1005 WM_PHASE_SWAP
, 0x0000, /* phase normal */
1007 WM_DAC_MASTER
, 0x0100, /* DAC master muted */
1009 WM_DAC_CTRL2
, 0x0000, /* no deemphasis, no ZFLG */
1010 WM_ADC_ATTEN_L
, 0x0000, /* ADC muted */
1011 WM_ADC_ATTEN_R
, 0x0000, /* ADC muted */
1013 WM_ALC_CTRL1
, 0x007b, /* */
1014 WM_ALC_CTRL2
, 0x0000, /* */
1015 WM_ALC_CTRL3
, 0x0000, /* */
1016 WM_NOISE_GATE
, 0x0000, /* */
1018 WM_DAC_MUTE
, 0x0000, /* DAC unmute */
1019 WM_ADC_MUX
, 0x0003, /* ADC unmute, both CD/Line On */
1021 static unsigned short wm8766_inits
[] = {
1022 WM8766_RESET
, 0x0000,
1023 WM8766_DAC_CTRL
, 0x0120,
1024 WM8766_INT_CTRL
, 0x0022, /* I2S Normal Mode, 24 bit */
1025 WM8766_DAC_CTRL2
, 0x0001,
1026 WM8766_DAC_CTRL3
, 0x0080,
1027 WM8766_LDA1
, 0x0100,
1028 WM8766_LDA2
, 0x0100,
1029 WM8766_LDA3
, 0x0100,
1030 WM8766_RDA1
, 0x0100,
1031 WM8766_RDA2
, 0x0100,
1032 WM8766_RDA3
, 0x0100,
1033 WM8766_MUTE1
, 0x0000,
1034 WM8766_MUTE2
, 0x0000,
1037 struct prodigy_hifi_spec
*spec
;
1043 ice
->num_total_dacs
= 8;
1044 ice
->num_total_adcs
= 1;
1046 /* HACK - use this as the SPDIF source.
1047 * don't call snd_ice1712_gpio_get/put(), otherwise it's overwritten
1049 ice
->gpio
.saved
[0] = 0;
1050 /* to remember the register values */
1052 ice
->akm
= kzalloc(sizeof(struct snd_akm4xxx
), GFP_KERNEL
);
1055 ice
->akm_codecs
= 1;
1057 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1062 /* initialize WM8776 codec */
1063 for (i
= 0; i
< ARRAY_SIZE(wm_inits
); i
+= 2)
1064 wm_put(ice
, wm_inits
[i
], wm_inits
[i
+1]);
1065 schedule_timeout_uninterruptible(1);
1066 for (i
= 0; i
< ARRAY_SIZE(wm_inits2
); i
+= 2)
1067 wm_put(ice
, wm_inits2
[i
], wm_inits2
[i
+1]);
1069 /* initialize WM8766 codec */
1070 for (i
= 0; i
< ARRAY_SIZE(wm8766_inits
); i
+= 2)
1071 wm8766_spi_write(ice
, wm8766_inits
[i
], wm8766_inits
[i
+1]);
1079 * initialize the chip
1081 static void ak4396_init(struct snd_ice1712
*ice
)
1083 static unsigned short ak4396_inits
[] = {
1084 AK4396_CTRL1
, 0x87, /* I2S Normal Mode, 24 bit */
1087 AK4396_LCH_ATT
, 0x00,
1088 AK4396_RCH_ATT
, 0x00,
1093 /* initialize ak4396 codec */
1095 ak4396_write(ice
, AK4396_CTRL1
, 0x86);
1097 ak4396_write(ice
, AK4396_CTRL1
, 0x87);
1099 for (i
= 0; i
< ARRAY_SIZE(ak4396_inits
); i
+= 2)
1100 ak4396_write(ice
, ak4396_inits
[i
], ak4396_inits
[i
+1]);
1104 static int prodigy_hd2_resume(struct snd_ice1712
*ice
)
1106 /* initialize ak4396 codec and restore previous mixer volumes */
1107 struct prodigy_hifi_spec
*spec
= ice
->spec
;
1109 mutex_lock(&ice
->gpio_mutex
);
1111 for (i
= 0; i
< 2; i
++)
1112 ak4396_write(ice
, AK4396_LCH_ATT
+ i
, spec
->vol
[i
] & 0xff);
1113 mutex_unlock(&ice
->gpio_mutex
);
1118 static int __devinit
prodigy_hd2_init(struct snd_ice1712
*ice
)
1120 struct prodigy_hifi_spec
*spec
;
1125 ice
->num_total_dacs
= 1;
1126 ice
->num_total_adcs
= 1;
1128 /* HACK - use this as the SPDIF source.
1129 * don't call snd_ice1712_gpio_get/put(), otherwise it's overwritten
1131 ice
->gpio
.saved
[0] = 0;
1132 /* to remember the register values */
1134 ice
->akm
= kzalloc(sizeof(struct snd_akm4xxx
), GFP_KERNEL
);
1137 ice
->akm_codecs
= 1;
1139 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1145 ice
->pm_resume
= &prodigy_hd2_resume
;
1146 ice
->pm_suspend_enabled
= 1;
1155 static unsigned char prodigy71hifi_eeprom
[] __devinitdata
= {
1156 0x4b, /* SYSCONF: clock 512, spdif-in/ADC, 4DACs */
1157 0x80, /* ACLINK: I2S */
1158 0xfc, /* I2S: vol, 96k, 24bit, 192k */
1159 0xc3, /* SPDIF: out-en, out-int, spdif-in */
1160 0xff, /* GPIO_DIR */
1161 0xff, /* GPIO_DIR1 */
1162 0x5f, /* GPIO_DIR2 */
1163 0x00, /* GPIO_MASK */
1164 0x00, /* GPIO_MASK1 */
1165 0x00, /* GPIO_MASK2 */
1166 0x00, /* GPIO_STATE */
1167 0x00, /* GPIO_STATE1 */
1168 0x00, /* GPIO_STATE2 */
1171 static unsigned char prodigyhd2_eeprom
[] __devinitdata
= {
1172 0x4b, /* SYSCONF: clock 512, spdif-in/ADC, 4DACs */
1173 0x80, /* ACLINK: I2S */
1174 0xfc, /* I2S: vol, 96k, 24bit, 192k */
1175 0xc3, /* SPDIF: out-en, out-int, spdif-in */
1176 0xff, /* GPIO_DIR */
1177 0xff, /* GPIO_DIR1 */
1178 0x5f, /* GPIO_DIR2 */
1179 0x00, /* GPIO_MASK */
1180 0x00, /* GPIO_MASK1 */
1181 0x00, /* GPIO_MASK2 */
1182 0x00, /* GPIO_STATE */
1183 0x00, /* GPIO_STATE1 */
1184 0x00, /* GPIO_STATE2 */
1187 static unsigned char fortissimo4_eeprom
[] __devinitdata
= {
1188 0x43, /* SYSCONF: clock 512, ADC, 4DACs */
1189 0x80, /* ACLINK: I2S */
1190 0xfc, /* I2S: vol, 96k, 24bit, 192k */
1191 0xc1, /* SPDIF: out-en, out-int */
1192 0xff, /* GPIO_DIR */
1193 0xff, /* GPIO_DIR1 */
1194 0x5f, /* GPIO_DIR2 */
1195 0x00, /* GPIO_MASK */
1196 0x00, /* GPIO_MASK1 */
1197 0x00, /* GPIO_MASK2 */
1198 0x00, /* GPIO_STATE */
1199 0x00, /* GPIO_STATE1 */
1200 0x00, /* GPIO_STATE2 */
1204 struct snd_ice1712_card_info snd_vt1724_prodigy_hifi_cards
[] __devinitdata
= {
1206 .subvendor
= VT1724_SUBDEVICE_PRODIGY_HIFI
,
1207 .name
= "Audiotrak Prodigy 7.1 HiFi",
1208 .model
= "prodigy71hifi",
1209 .chip_init
= prodigy_hifi_init
,
1210 .build_controls
= prodigy_hifi_add_controls
,
1211 .eeprom_size
= sizeof(prodigy71hifi_eeprom
),
1212 .eeprom_data
= prodigy71hifi_eeprom
,
1213 .driver
= "Prodigy71HIFI",
1216 .subvendor
= VT1724_SUBDEVICE_PRODIGY_HD2
,
1217 .name
= "Audiotrak Prodigy HD2",
1218 .model
= "prodigyhd2",
1219 .chip_init
= prodigy_hd2_init
,
1220 .build_controls
= prodigy_hd2_add_controls
,
1221 .eeprom_size
= sizeof(prodigyhd2_eeprom
),
1222 .eeprom_data
= prodigyhd2_eeprom
,
1223 .driver
= "Prodigy71HD2",
1226 .subvendor
= VT1724_SUBDEVICE_FORTISSIMO4
,
1227 .name
= "Hercules Fortissimo IV",
1228 .model
= "fortissimo4",
1229 .chip_init
= prodigy_hifi_init
,
1230 .build_controls
= prodigy_hifi_add_controls
,
1231 .eeprom_size
= sizeof(fortissimo4_eeprom
),
1232 .eeprom_data
= fortissimo4_eeprom
,
1233 .driver
= "Fortissimo4",
1235 { } /* terminator */