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
28 #include <linux/delay.h>
29 #include <linux/interrupt.h>
30 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/mutex.h>
34 #include <sound/core.h>
35 #include <sound/info.h>
36 #include <sound/tlv.h>
40 #include "prodigy_hifi.h"
42 struct prodigy_hifi_spec
{
43 unsigned short master
[2];
44 unsigned short vol
[8];
50 /* WM8776 registers */
51 #define WM_HP_ATTEN_L 0x00 /* headphone left attenuation */
52 #define WM_HP_ATTEN_R 0x01 /* headphone left attenuation */
53 #define WM_HP_MASTER 0x02 /* headphone master (both channels),
55 #define WM_DAC_ATTEN_L 0x03 /* digital left attenuation */
56 #define WM_DAC_ATTEN_R 0x04
57 #define WM_DAC_MASTER 0x05
58 #define WM_PHASE_SWAP 0x06 /* DAC phase swap */
59 #define WM_DAC_CTRL1 0x07
60 #define WM_DAC_MUTE 0x08
61 #define WM_DAC_CTRL2 0x09
62 #define WM_DAC_INT 0x0a
63 #define WM_ADC_INT 0x0b
64 #define WM_MASTER_CTRL 0x0c
65 #define WM_POWERDOWN 0x0d
66 #define WM_ADC_ATTEN_L 0x0e
67 #define WM_ADC_ATTEN_R 0x0f
68 #define WM_ALC_CTRL1 0x10
69 #define WM_ALC_CTRL2 0x11
70 #define WM_ALC_CTRL3 0x12
71 #define WM_NOISE_GATE 0x13
72 #define WM_LIMITER 0x14
73 #define WM_ADC_MUX 0x15
74 #define WM_OUT_MUX 0x16
77 /* Analog Recording Source :- Mic, LineIn, CD/Video, */
79 /* implement capture source select control for WM8776 */
81 #define WM_AIN1 "AIN1"
82 #define WM_AIN2 "AIN2"
83 #define WM_AIN3 "AIN3"
84 #define WM_AIN4 "AIN4"
85 #define WM_AIN5 "AIN5"
87 /* GPIO pins of envy24ht connected to wm8766 */
88 #define WM8766_SPI_CLK (1<<17) /* CLK, Pin97 on ICE1724 */
89 #define WM8766_SPI_MD (1<<16) /* DATA VT1724 -> WM8766, Pin96 */
90 #define WM8766_SPI_ML (1<<18) /* Latch, Pin98 */
92 /* WM8766 registers */
93 #define WM8766_DAC_CTRL 0x02 /* DAC Control */
94 #define WM8766_INT_CTRL 0x03 /* Interface Control */
95 #define WM8766_DAC_CTRL2 0x09
96 #define WM8766_DAC_CTRL3 0x0a
97 #define WM8766_RESET 0x1f
98 #define WM8766_LDA1 0x00
99 #define WM8766_LDA2 0x04
100 #define WM8766_LDA3 0x06
101 #define WM8766_RDA1 0x01
102 #define WM8766_RDA2 0x05
103 #define WM8766_RDA3 0x07
104 #define WM8766_MUTE1 0x0C
105 #define WM8766_MUTE2 0x0F
111 #define AK4396_ADDR 0x00
112 #define AK4396_CSN (1 << 8) /* CSN->GPIO8, pin 75 */
113 #define AK4396_CCLK (1 << 9) /* CCLK->GPIO9, pin 76 */
114 #define AK4396_CDTI (1 << 10) /* CDTI->GPIO10, pin 77 */
116 /* ak4396 registers */
117 #define AK4396_CTRL1 0x00
118 #define AK4396_CTRL2 0x01
119 #define AK4396_CTRL3 0x02
120 #define AK4396_LCH_ATT 0x03
121 #define AK4396_RCH_ATT 0x04
125 * get the current register value of WM codec
127 static unsigned short wm_get(struct snd_ice1712
*ice
, int reg
)
130 return ((unsigned short)ice
->akm
[0].images
[reg
] << 8) |
131 ice
->akm
[0].images
[reg
+ 1];
135 * set the register value of WM codec and remember it
137 static void wm_put_nocache(struct snd_ice1712
*ice
, int reg
, unsigned short val
)
140 cval
= (reg
<< 9) | val
;
141 snd_vt1724_write_i2c(ice
, WM_DEV
, cval
>> 8, cval
& 0xff);
144 static void wm_put(struct snd_ice1712
*ice
, int reg
, unsigned short val
)
146 wm_put_nocache(ice
, reg
, val
);
148 ice
->akm
[0].images
[reg
] = val
>> 8;
149 ice
->akm
[0].images
[reg
+ 1] = val
;
153 * write data in the SPI mode
156 static void set_gpio_bit(struct snd_ice1712
*ice
, unsigned int bit
, int val
)
158 unsigned int tmp
= snd_ice1712_gpio_read(ice
);
163 snd_ice1712_gpio_write(ice
, tmp
);
167 * SPI implementation for WM8766 codec - only writing supported, no readback
170 static void wm8766_spi_send_word(struct snd_ice1712
*ice
, unsigned int data
)
173 for (i
= 0; i
< 16; i
++) {
174 set_gpio_bit(ice
, WM8766_SPI_CLK
, 0);
176 set_gpio_bit(ice
, WM8766_SPI_MD
, data
& 0x8000);
178 set_gpio_bit(ice
, WM8766_SPI_CLK
, 1);
184 static void wm8766_spi_write(struct snd_ice1712
*ice
, unsigned int reg
,
189 snd_ice1712_gpio_set_dir(ice
, WM8766_SPI_MD
|
190 WM8766_SPI_CLK
|WM8766_SPI_ML
);
191 snd_ice1712_gpio_set_mask(ice
, ~(WM8766_SPI_MD
|
192 WM8766_SPI_CLK
|WM8766_SPI_ML
));
193 /* latch must be low when writing */
194 set_gpio_bit(ice
, WM8766_SPI_ML
, 0);
195 block
= (reg
<< 9) | (data
& 0x1ff);
196 wm8766_spi_send_word(ice
, block
); /* REGISTER ADDRESS */
198 set_gpio_bit(ice
, WM8766_SPI_ML
, 1);
201 snd_ice1712_gpio_set_mask(ice
, ice
->gpio
.write_mask
);
202 snd_ice1712_gpio_set_dir(ice
, ice
->gpio
.direction
);
207 * serial interface for ak4396 - only writing supported, no readback
210 static void ak4396_send_word(struct snd_ice1712
*ice
, unsigned int data
)
213 for (i
= 0; i
< 16; i
++) {
214 set_gpio_bit(ice
, AK4396_CCLK
, 0);
216 set_gpio_bit(ice
, AK4396_CDTI
, data
& 0x8000);
218 set_gpio_bit(ice
, AK4396_CCLK
, 1);
224 static void ak4396_write(struct snd_ice1712
*ice
, unsigned int reg
,
229 snd_ice1712_gpio_set_dir(ice
, AK4396_CSN
|AK4396_CCLK
|AK4396_CDTI
);
230 snd_ice1712_gpio_set_mask(ice
, ~(AK4396_CSN
|AK4396_CCLK
|AK4396_CDTI
));
231 /* latch must be low when writing */
232 set_gpio_bit(ice
, AK4396_CSN
, 0);
233 block
= ((AK4396_ADDR
& 0x03) << 14) | (1 << 13) |
234 ((reg
& 0x1f) << 8) | (data
& 0xff);
235 ak4396_send_word(ice
, block
); /* REGISTER ADDRESS */
237 set_gpio_bit(ice
, AK4396_CSN
, 1);
240 snd_ice1712_gpio_set_mask(ice
, ice
->gpio
.write_mask
);
241 snd_ice1712_gpio_set_dir(ice
, ice
->gpio
.direction
);
252 * DAC volume attenuation mixer control (-64dB to 0dB)
255 static int ak4396_dac_vol_info(struct snd_kcontrol
*kcontrol
,
256 struct snd_ctl_elem_info
*uinfo
)
258 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
260 uinfo
->value
.integer
.min
= 0; /* mute */
261 uinfo
->value
.integer
.max
= 0xFF; /* linear */
265 static int ak4396_dac_vol_get(struct snd_kcontrol
*kcontrol
,
266 struct snd_ctl_elem_value
*ucontrol
)
268 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
269 struct prodigy_hifi_spec
*spec
= ice
->spec
;
272 for (i
= 0; i
< 2; i
++)
273 ucontrol
->value
.integer
.value
[i
] = spec
->vol
[i
];
278 static int ak4396_dac_vol_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
280 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
281 struct prodigy_hifi_spec
*spec
= ice
->spec
;
285 mutex_lock(&ice
->gpio_mutex
);
286 for (i
= 0; i
< 2; i
++) {
287 if (ucontrol
->value
.integer
.value
[i
] != spec
->vol
[i
]) {
288 spec
->vol
[i
] = ucontrol
->value
.integer
.value
[i
];
289 ak4396_write(ice
, AK4396_LCH_ATT
+ i
,
290 spec
->vol
[i
] & 0xff);
294 mutex_unlock(&ice
->gpio_mutex
);
298 static const DECLARE_TLV_DB_SCALE(db_scale_wm_dac
, -12700, 100, 1);
299 static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale
, TLV_DB_GAIN_MUTE
, 0);
301 static struct snd_kcontrol_new prodigy_hd2_controls
[] = {
303 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
304 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
305 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
306 .name
= "Front Playback Volume",
307 .info
= ak4396_dac_vol_info
,
308 .get
= ak4396_dac_vol_get
,
309 .put
= ak4396_dac_vol_put
,
310 .tlv
= { .p
= ak4396_db_scale
},
315 /* --------------- */
318 * Logarithmic volume values for WM87*6
319 * Computed as 20 * Log10(255 / x)
321 static const unsigned char wm_vol
[256] = {
322 127, 48, 42, 39, 36, 34, 33, 31, 30, 29, 28, 27, 27, 26, 25, 25, 24, 24, 23,
323 23, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 18, 17, 17, 17,
324 17, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13,
325 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
326 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8,
327 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,
328 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,
329 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,
330 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,
331 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,
332 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,
336 #define WM_VOL_MAX (sizeof(wm_vol) - 1)
337 #define WM_VOL_MUTE 0x8000
342 #define DAC_MIN (DAC_0dB - DAC_RES)
345 static void wm_set_vol(struct snd_ice1712
*ice
, unsigned int index
,
346 unsigned short vol
, unsigned short master
)
350 if ((master
& WM_VOL_MUTE
) || (vol
& WM_VOL_MUTE
))
353 nvol
= (((vol
& ~WM_VOL_MUTE
) * (master
& ~WM_VOL_MUTE
)) / 128)
355 nvol
= (nvol
? (nvol
+ DAC_MIN
) : 0) & 0xff;
358 wm_put(ice
, index
, nvol
);
359 wm_put_nocache(ice
, index
, 0x100 | nvol
);
362 static void wm8766_set_vol(struct snd_ice1712
*ice
, unsigned int index
,
363 unsigned short vol
, unsigned short master
)
367 if ((master
& WM_VOL_MUTE
) || (vol
& WM_VOL_MUTE
))
370 nvol
= (((vol
& ~WM_VOL_MUTE
) * (master
& ~WM_VOL_MUTE
)) / 128)
372 nvol
= (nvol
? (nvol
+ DAC_MIN
) : 0) & 0xff;
375 wm8766_spi_write(ice
, index
, (0x0100 | nvol
));
380 * DAC volume attenuation mixer control (-64dB to 0dB)
383 static int wm_dac_vol_info(struct snd_kcontrol
*kcontrol
,
384 struct snd_ctl_elem_info
*uinfo
)
386 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
388 uinfo
->value
.integer
.min
= 0; /* mute */
389 uinfo
->value
.integer
.max
= DAC_RES
; /* 0dB, 0.5dB step */
393 static int wm_dac_vol_get(struct snd_kcontrol
*kcontrol
,
394 struct snd_ctl_elem_value
*ucontrol
)
396 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
397 struct prodigy_hifi_spec
*spec
= ice
->spec
;
400 for (i
= 0; i
< 2; i
++)
401 ucontrol
->value
.integer
.value
[i
] =
402 spec
->vol
[2 + i
] & ~WM_VOL_MUTE
;
406 static int wm_dac_vol_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
408 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
409 struct prodigy_hifi_spec
*spec
= ice
->spec
;
410 int i
, idx
, change
= 0;
412 mutex_lock(&ice
->gpio_mutex
);
413 for (i
= 0; i
< 2; i
++) {
414 if (ucontrol
->value
.integer
.value
[i
] != spec
->vol
[2 + i
]) {
415 idx
= WM_DAC_ATTEN_L
+ i
;
416 spec
->vol
[2 + i
] &= WM_VOL_MUTE
;
417 spec
->vol
[2 + i
] |= ucontrol
->value
.integer
.value
[i
];
418 wm_set_vol(ice
, idx
, spec
->vol
[2 + i
], spec
->master
[i
]);
422 mutex_unlock(&ice
->gpio_mutex
);
428 * WM8766 DAC volume attenuation mixer control
430 static int wm8766_vol_info(struct snd_kcontrol
*kcontrol
,
431 struct snd_ctl_elem_info
*uinfo
)
433 int voices
= kcontrol
->private_value
>> 8;
434 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
435 uinfo
->count
= voices
;
436 uinfo
->value
.integer
.min
= 0; /* mute */
437 uinfo
->value
.integer
.max
= DAC_RES
; /* 0dB */
441 static int wm8766_vol_get(struct snd_kcontrol
*kcontrol
,
442 struct snd_ctl_elem_value
*ucontrol
)
444 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
445 struct prodigy_hifi_spec
*spec
= ice
->spec
;
448 voices
= kcontrol
->private_value
>> 8;
449 ofs
= kcontrol
->private_value
& 0xff;
450 for (i
= 0; i
< voices
; i
++)
451 ucontrol
->value
.integer
.value
[i
] = spec
->vol
[ofs
+ i
];
455 static int wm8766_vol_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
457 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
458 struct prodigy_hifi_spec
*spec
= ice
->spec
;
459 int i
, idx
, ofs
, voices
;
462 voices
= kcontrol
->private_value
>> 8;
463 ofs
= kcontrol
->private_value
& 0xff;
464 mutex_lock(&ice
->gpio_mutex
);
465 for (i
= 0; i
< voices
; i
++) {
466 if (ucontrol
->value
.integer
.value
[i
] != spec
->vol
[ofs
+ i
]) {
467 idx
= WM8766_LDA1
+ ofs
+ i
;
468 spec
->vol
[ofs
+ i
] &= WM_VOL_MUTE
;
469 spec
->vol
[ofs
+ i
] |= ucontrol
->value
.integer
.value
[i
];
470 wm8766_set_vol(ice
, idx
,
471 spec
->vol
[ofs
+ i
], spec
->master
[i
]);
475 mutex_unlock(&ice
->gpio_mutex
);
480 * Master volume attenuation mixer control / applied to WM8776+WM8766
482 static int wm_master_vol_info(struct snd_kcontrol
*kcontrol
,
483 struct snd_ctl_elem_info
*uinfo
)
485 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
487 uinfo
->value
.integer
.min
= 0;
488 uinfo
->value
.integer
.max
= DAC_RES
;
492 static int wm_master_vol_get(struct snd_kcontrol
*kcontrol
,
493 struct snd_ctl_elem_value
*ucontrol
)
495 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
496 struct prodigy_hifi_spec
*spec
= ice
->spec
;
498 for (i
= 0; i
< 2; i
++)
499 ucontrol
->value
.integer
.value
[i
] = spec
->master
[i
];
503 static int wm_master_vol_put(struct snd_kcontrol
*kcontrol
,
504 struct snd_ctl_elem_value
*ucontrol
)
506 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
507 struct prodigy_hifi_spec
*spec
= ice
->spec
;
510 mutex_lock(&ice
->gpio_mutex
);
511 for (ch
= 0; ch
< 2; ch
++) {
512 if (ucontrol
->value
.integer
.value
[ch
] != spec
->master
[ch
]) {
513 spec
->master
[ch
] = ucontrol
->value
.integer
.value
[ch
];
515 /* Apply to front DAC */
516 wm_set_vol(ice
, WM_DAC_ATTEN_L
+ ch
,
517 spec
->vol
[2 + ch
], spec
->master
[ch
]);
519 wm8766_set_vol(ice
, WM8766_LDA1
+ ch
,
520 spec
->vol
[0 + ch
], spec
->master
[ch
]);
522 wm8766_set_vol(ice
, WM8766_LDA2
+ ch
,
523 spec
->vol
[4 + ch
], spec
->master
[ch
]);
525 wm8766_set_vol(ice
, WM8766_LDA3
+ ch
,
526 spec
->vol
[6 + ch
], spec
->master
[ch
]);
530 mutex_unlock(&ice
->gpio_mutex
);
537 static int wm_adc_mux_enum_info(struct snd_kcontrol
*kcontrol
,
538 struct snd_ctl_elem_info
*uinfo
)
540 static char* texts
[32] = {
541 "NULL", WM_AIN1
, WM_AIN2
, WM_AIN1
"+" WM_AIN2
,
542 WM_AIN3
, WM_AIN1
"+" WM_AIN3
, WM_AIN2
"+" WM_AIN3
,
543 WM_AIN1
"+" WM_AIN2
"+" WM_AIN3
,
544 WM_AIN4
, WM_AIN1
"+" WM_AIN4
, WM_AIN2
"+" WM_AIN4
,
545 WM_AIN1
"+" WM_AIN2
"+" WM_AIN4
,
546 WM_AIN3
"+" WM_AIN4
, WM_AIN1
"+" WM_AIN3
"+" WM_AIN4
,
547 WM_AIN2
"+" WM_AIN3
"+" WM_AIN4
,
548 WM_AIN1
"+" WM_AIN2
"+" WM_AIN3
"+" WM_AIN4
,
549 WM_AIN5
, WM_AIN1
"+" WM_AIN5
, WM_AIN2
"+" WM_AIN5
,
550 WM_AIN1
"+" WM_AIN2
"+" WM_AIN5
,
551 WM_AIN3
"+" WM_AIN5
, WM_AIN1
"+" WM_AIN3
"+" WM_AIN5
,
552 WM_AIN2
"+" WM_AIN3
"+" WM_AIN5
,
553 WM_AIN1
"+" WM_AIN2
"+" WM_AIN3
"+" WM_AIN5
,
554 WM_AIN4
"+" WM_AIN5
, WM_AIN1
"+" WM_AIN4
"+" WM_AIN5
,
555 WM_AIN2
"+" WM_AIN4
"+" WM_AIN5
,
556 WM_AIN1
"+" WM_AIN2
"+" WM_AIN4
"+" WM_AIN5
,
557 WM_AIN3
"+" WM_AIN4
"+" WM_AIN5
,
558 WM_AIN1
"+" WM_AIN3
"+" WM_AIN4
"+" WM_AIN5
,
559 WM_AIN2
"+" WM_AIN3
"+" WM_AIN4
"+" WM_AIN5
,
560 WM_AIN1
"+" WM_AIN2
"+" WM_AIN3
"+" WM_AIN4
"+" WM_AIN5
563 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
565 uinfo
->value
.enumerated
.items
= 32;
566 if (uinfo
->value
.enumerated
.item
> 31)
567 uinfo
->value
.enumerated
.item
= 31;
568 strcpy(uinfo
->value
.enumerated
.name
,
569 texts
[uinfo
->value
.enumerated
.item
]);
573 static int wm_adc_mux_enum_get(struct snd_kcontrol
*kcontrol
,
574 struct snd_ctl_elem_value
*ucontrol
)
576 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
578 mutex_lock(&ice
->gpio_mutex
);
579 ucontrol
->value
.integer
.value
[0] = wm_get(ice
, WM_ADC_MUX
) & 0x1f;
580 mutex_unlock(&ice
->gpio_mutex
);
584 static int wm_adc_mux_enum_put(struct snd_kcontrol
*kcontrol
,
585 struct snd_ctl_elem_value
*ucontrol
)
587 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
588 unsigned short oval
, nval
;
591 mutex_lock(&ice
->gpio_mutex
);
592 oval
= wm_get(ice
, WM_ADC_MUX
);
593 nval
= (oval
& 0xe0) | ucontrol
->value
.integer
.value
[0];
595 wm_put(ice
, WM_ADC_MUX
, nval
);
598 mutex_unlock(&ice
->gpio_mutex
);
605 * ADC gain mixer control (-64dB to 0dB)
610 #define ADC_MIN (ADC_0dB - ADC_RES)
612 static int wm_adc_vol_info(struct snd_kcontrol
*kcontrol
,
613 struct snd_ctl_elem_info
*uinfo
)
615 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
617 uinfo
->value
.integer
.min
= 0; /* mute (-64dB) */
618 uinfo
->value
.integer
.max
= ADC_RES
; /* 0dB, 0.5dB step */
622 static int wm_adc_vol_get(struct snd_kcontrol
*kcontrol
,
623 struct snd_ctl_elem_value
*ucontrol
)
625 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
629 mutex_lock(&ice
->gpio_mutex
);
630 for (i
= 0; i
< 2; i
++) {
631 val
= wm_get(ice
, WM_ADC_ATTEN_L
+ i
) & 0xff;
632 val
= val
> ADC_MIN
? (val
- ADC_MIN
) : 0;
633 ucontrol
->value
.integer
.value
[i
] = val
;
635 mutex_unlock(&ice
->gpio_mutex
);
639 static int wm_adc_vol_put(struct snd_kcontrol
*kcontrol
,
640 struct snd_ctl_elem_value
*ucontrol
)
642 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
643 unsigned short ovol
, nvol
;
644 int i
, idx
, change
= 0;
646 mutex_lock(&ice
->gpio_mutex
);
647 for (i
= 0; i
< 2; i
++) {
648 nvol
= ucontrol
->value
.integer
.value
[i
];
649 nvol
= nvol
? (nvol
+ ADC_MIN
) : 0;
650 idx
= WM_ADC_ATTEN_L
+ i
;
651 ovol
= wm_get(ice
, idx
) & 0xff;
653 wm_put(ice
, idx
, nvol
);
657 mutex_unlock(&ice
->gpio_mutex
);
662 * ADC input mux mixer control
664 #define wm_adc_mux_info snd_ctl_boolean_mono_info
666 static int wm_adc_mux_get(struct snd_kcontrol
*kcontrol
,
667 struct snd_ctl_elem_value
*ucontrol
)
669 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
670 int bit
= kcontrol
->private_value
;
672 mutex_lock(&ice
->gpio_mutex
);
673 ucontrol
->value
.integer
.value
[0] =
674 (wm_get(ice
, WM_ADC_MUX
) & (1 << bit
)) ? 1 : 0;
675 mutex_unlock(&ice
->gpio_mutex
);
679 static int wm_adc_mux_put(struct snd_kcontrol
*kcontrol
,
680 struct snd_ctl_elem_value
*ucontrol
)
682 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
683 int bit
= kcontrol
->private_value
;
684 unsigned short oval
, nval
;
687 mutex_lock(&ice
->gpio_mutex
);
688 nval
= oval
= wm_get(ice
, WM_ADC_MUX
);
689 if (ucontrol
->value
.integer
.value
[0])
693 change
= nval
!= oval
;
695 wm_put(ice
, WM_ADC_MUX
, nval
);
697 mutex_unlock(&ice
->gpio_mutex
);
702 * Analog bypass (In -> Out)
704 #define wm_bypass_info snd_ctl_boolean_mono_info
706 static int wm_bypass_get(struct snd_kcontrol
*kcontrol
,
707 struct snd_ctl_elem_value
*ucontrol
)
709 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
711 mutex_lock(&ice
->gpio_mutex
);
712 ucontrol
->value
.integer
.value
[0] =
713 (wm_get(ice
, WM_OUT_MUX
) & 0x04) ? 1 : 0;
714 mutex_unlock(&ice
->gpio_mutex
);
718 static int wm_bypass_put(struct snd_kcontrol
*kcontrol
,
719 struct snd_ctl_elem_value
*ucontrol
)
721 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
722 unsigned short val
, oval
;
725 mutex_lock(&ice
->gpio_mutex
);
726 val
= oval
= wm_get(ice
, WM_OUT_MUX
);
727 if (ucontrol
->value
.integer
.value
[0])
732 wm_put(ice
, WM_OUT_MUX
, val
);
735 mutex_unlock(&ice
->gpio_mutex
);
742 #define wm_chswap_info snd_ctl_boolean_mono_info
744 static int wm_chswap_get(struct snd_kcontrol
*kcontrol
,
745 struct snd_ctl_elem_value
*ucontrol
)
747 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
749 mutex_lock(&ice
->gpio_mutex
);
750 ucontrol
->value
.integer
.value
[0] =
751 (wm_get(ice
, WM_DAC_CTRL1
) & 0xf0) != 0x90;
752 mutex_unlock(&ice
->gpio_mutex
);
756 static int wm_chswap_put(struct snd_kcontrol
*kcontrol
,
757 struct snd_ctl_elem_value
*ucontrol
)
759 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
760 unsigned short val
, oval
;
763 mutex_lock(&ice
->gpio_mutex
);
764 oval
= wm_get(ice
, WM_DAC_CTRL1
);
766 if (ucontrol
->value
.integer
.value
[0])
771 wm_put(ice
, WM_DAC_CTRL1
, val
);
772 wm_put_nocache(ice
, WM_DAC_CTRL1
, val
);
775 mutex_unlock(&ice
->gpio_mutex
);
784 static struct snd_kcontrol_new prodigy_hifi_controls
[] = {
786 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
787 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
788 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
789 .name
= "Master Playback Volume",
790 .info
= wm_master_vol_info
,
791 .get
= wm_master_vol_get
,
792 .put
= wm_master_vol_put
,
793 .tlv
= { .p
= db_scale_wm_dac
}
796 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
797 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
798 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
799 .name
= "Front Playback Volume",
800 .info
= wm_dac_vol_info
,
801 .get
= wm_dac_vol_get
,
802 .put
= wm_dac_vol_put
,
803 .tlv
= { .p
= db_scale_wm_dac
},
806 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
807 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
808 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
809 .name
= "Rear Playback Volume",
810 .info
= wm8766_vol_info
,
811 .get
= wm8766_vol_get
,
812 .put
= wm8766_vol_put
,
813 .private_value
= (2 << 8) | 0,
814 .tlv
= { .p
= db_scale_wm_dac
},
817 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
818 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
819 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
820 .name
= "Center Playback Volume",
821 .info
= wm8766_vol_info
,
822 .get
= wm8766_vol_get
,
823 .put
= wm8766_vol_put
,
824 .private_value
= (1 << 8) | 4,
825 .tlv
= { .p
= db_scale_wm_dac
}
828 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
829 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
830 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
831 .name
= "LFE Playback Volume",
832 .info
= wm8766_vol_info
,
833 .get
= wm8766_vol_get
,
834 .put
= wm8766_vol_put
,
835 .private_value
= (1 << 8) | 5,
836 .tlv
= { .p
= db_scale_wm_dac
}
839 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
840 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
841 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
842 .name
= "Side Playback Volume",
843 .info
= wm8766_vol_info
,
844 .get
= wm8766_vol_get
,
845 .put
= wm8766_vol_put
,
846 .private_value
= (2 << 8) | 6,
847 .tlv
= { .p
= db_scale_wm_dac
},
850 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
851 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
852 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
853 .name
= "Capture Volume",
854 .info
= wm_adc_vol_info
,
855 .get
= wm_adc_vol_get
,
856 .put
= wm_adc_vol_put
,
857 .tlv
= { .p
= db_scale_wm_dac
},
860 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
861 .name
= "CD Capture Switch",
862 .info
= wm_adc_mux_info
,
863 .get
= wm_adc_mux_get
,
864 .put
= wm_adc_mux_put
,
868 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
869 .name
= "Line Capture Switch",
870 .info
= wm_adc_mux_info
,
871 .get
= wm_adc_mux_get
,
872 .put
= wm_adc_mux_put
,
876 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
877 .name
= "Analog Bypass Switch",
878 .info
= wm_bypass_info
,
879 .get
= wm_bypass_get
,
880 .put
= wm_bypass_put
,
883 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
884 .name
= "Swap Output Channels",
885 .info
= wm_chswap_info
,
886 .get
= wm_chswap_get
,
887 .put
= wm_chswap_put
,
890 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
891 .name
= "Analog Capture Source",
892 .info
= wm_adc_mux_enum_info
,
893 .get
= wm_adc_mux_enum_get
,
894 .put
= wm_adc_mux_enum_put
,
901 static void wm_proc_regs_write(struct snd_info_entry
*entry
,
902 struct snd_info_buffer
*buffer
)
904 struct snd_ice1712
*ice
= entry
->private_data
;
906 unsigned int reg
, val
;
907 mutex_lock(&ice
->gpio_mutex
);
908 while (!snd_info_get_line(buffer
, line
, sizeof(line
))) {
909 if (sscanf(line
, "%x %x", ®
, &val
) != 2)
911 if (reg
<= 0x17 && val
<= 0xffff)
912 wm_put(ice
, reg
, val
);
914 mutex_unlock(&ice
->gpio_mutex
);
917 static void wm_proc_regs_read(struct snd_info_entry
*entry
,
918 struct snd_info_buffer
*buffer
)
920 struct snd_ice1712
*ice
= entry
->private_data
;
923 mutex_lock(&ice
->gpio_mutex
);
924 for (reg
= 0; reg
<= 0x17; reg
++) {
925 val
= wm_get(ice
, reg
);
926 snd_iprintf(buffer
, "%02x = %04x\n", reg
, val
);
928 mutex_unlock(&ice
->gpio_mutex
);
931 static void wm_proc_init(struct snd_ice1712
*ice
)
933 struct snd_info_entry
*entry
;
934 if (!snd_card_proc_new(ice
->card
, "wm_codec", &entry
)) {
935 snd_info_set_text_ops(entry
, ice
, wm_proc_regs_read
);
936 entry
->mode
|= S_IWUSR
;
937 entry
->c
.text
.write
= wm_proc_regs_write
;
941 static int prodigy_hifi_add_controls(struct snd_ice1712
*ice
)
946 for (i
= 0; i
< ARRAY_SIZE(prodigy_hifi_controls
); i
++) {
947 err
= snd_ctl_add(ice
->card
,
948 snd_ctl_new1(&prodigy_hifi_controls
[i
], ice
));
958 static int prodigy_hd2_add_controls(struct snd_ice1712
*ice
)
963 for (i
= 0; i
< ARRAY_SIZE(prodigy_hd2_controls
); i
++) {
964 err
= snd_ctl_add(ice
->card
,
965 snd_ctl_new1(&prodigy_hd2_controls
[i
], ice
));
977 * initialize the chip
979 static int prodigy_hifi_init(struct snd_ice1712
*ice
)
981 static unsigned short wm_inits
[] = {
982 /* These come first to reduce init pop noise */
983 WM_ADC_MUX
, 0x0003, /* ADC mute */
984 /* 0x00c0 replaced by 0x0003 */
986 WM_DAC_MUTE
, 0x0001, /* DAC softmute */
987 WM_DAC_CTRL1
, 0x0000, /* DAC mute */
989 WM_POWERDOWN
, 0x0008, /* All power-up except HP */
990 WM_RESET
, 0x0000, /* reset */
992 static unsigned short wm_inits2
[] = {
993 WM_MASTER_CTRL
, 0x0022, /* 256fs, slave mode */
994 WM_DAC_INT
, 0x0022, /* I2S, normal polarity, 24bit */
995 WM_ADC_INT
, 0x0022, /* I2S, normal polarity, 24bit */
996 WM_DAC_CTRL1
, 0x0090, /* DAC L/R */
997 WM_OUT_MUX
, 0x0001, /* OUT DAC */
998 WM_HP_ATTEN_L
, 0x0179, /* HP 0dB */
999 WM_HP_ATTEN_R
, 0x0179, /* HP 0dB */
1000 WM_DAC_ATTEN_L
, 0x0000, /* DAC 0dB */
1001 WM_DAC_ATTEN_L
, 0x0100, /* DAC 0dB */
1002 WM_DAC_ATTEN_R
, 0x0000, /* DAC 0dB */
1003 WM_DAC_ATTEN_R
, 0x0100, /* DAC 0dB */
1004 WM_PHASE_SWAP
, 0x0000, /* phase normal */
1006 WM_DAC_MASTER
, 0x0100, /* DAC master muted */
1008 WM_DAC_CTRL2
, 0x0000, /* no deemphasis, no ZFLG */
1009 WM_ADC_ATTEN_L
, 0x0000, /* ADC muted */
1010 WM_ADC_ATTEN_R
, 0x0000, /* ADC muted */
1012 WM_ALC_CTRL1
, 0x007b, /* */
1013 WM_ALC_CTRL2
, 0x0000, /* */
1014 WM_ALC_CTRL3
, 0x0000, /* */
1015 WM_NOISE_GATE
, 0x0000, /* */
1017 WM_DAC_MUTE
, 0x0000, /* DAC unmute */
1018 WM_ADC_MUX
, 0x0003, /* ADC unmute, both CD/Line On */
1020 static unsigned short wm8766_inits
[] = {
1021 WM8766_RESET
, 0x0000,
1022 WM8766_DAC_CTRL
, 0x0120,
1023 WM8766_INT_CTRL
, 0x0022, /* I2S Normal Mode, 24 bit */
1024 WM8766_DAC_CTRL2
, 0x0001,
1025 WM8766_DAC_CTRL3
, 0x0080,
1026 WM8766_LDA1
, 0x0100,
1027 WM8766_LDA2
, 0x0100,
1028 WM8766_LDA3
, 0x0100,
1029 WM8766_RDA1
, 0x0100,
1030 WM8766_RDA2
, 0x0100,
1031 WM8766_RDA3
, 0x0100,
1032 WM8766_MUTE1
, 0x0000,
1033 WM8766_MUTE2
, 0x0000,
1036 struct prodigy_hifi_spec
*spec
;
1042 ice
->num_total_dacs
= 8;
1043 ice
->num_total_adcs
= 1;
1045 /* HACK - use this as the SPDIF source.
1046 * don't call snd_ice1712_gpio_get/put(), otherwise it's overwritten
1048 ice
->gpio
.saved
[0] = 0;
1049 /* to remember the register values */
1051 ice
->akm
= kzalloc(sizeof(struct snd_akm4xxx
), GFP_KERNEL
);
1054 ice
->akm_codecs
= 1;
1056 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1061 /* initialize WM8776 codec */
1062 for (i
= 0; i
< ARRAY_SIZE(wm_inits
); i
+= 2)
1063 wm_put(ice
, wm_inits
[i
], wm_inits
[i
+1]);
1064 schedule_timeout_uninterruptible(1);
1065 for (i
= 0; i
< ARRAY_SIZE(wm_inits2
); i
+= 2)
1066 wm_put(ice
, wm_inits2
[i
], wm_inits2
[i
+1]);
1068 /* initialize WM8766 codec */
1069 for (i
= 0; i
< ARRAY_SIZE(wm8766_inits
); i
+= 2)
1070 wm8766_spi_write(ice
, wm8766_inits
[i
], wm8766_inits
[i
+1]);
1078 * initialize the chip
1080 static void ak4396_init(struct snd_ice1712
*ice
)
1082 static unsigned short ak4396_inits
[] = {
1083 AK4396_CTRL1
, 0x87, /* I2S Normal Mode, 24 bit */
1086 AK4396_LCH_ATT
, 0x00,
1087 AK4396_RCH_ATT
, 0x00,
1092 /* initialize ak4396 codec */
1094 ak4396_write(ice
, AK4396_CTRL1
, 0x86);
1096 ak4396_write(ice
, AK4396_CTRL1
, 0x87);
1098 for (i
= 0; i
< ARRAY_SIZE(ak4396_inits
); i
+= 2)
1099 ak4396_write(ice
, ak4396_inits
[i
], ak4396_inits
[i
+1]);
1102 #ifdef CONFIG_PM_SLEEP
1103 static int prodigy_hd2_resume(struct snd_ice1712
*ice
)
1105 /* initialize ak4396 codec and restore previous mixer volumes */
1106 struct prodigy_hifi_spec
*spec
= ice
->spec
;
1108 mutex_lock(&ice
->gpio_mutex
);
1110 for (i
= 0; i
< 2; i
++)
1111 ak4396_write(ice
, AK4396_LCH_ATT
+ i
, spec
->vol
[i
] & 0xff);
1112 mutex_unlock(&ice
->gpio_mutex
);
1117 static int prodigy_hd2_init(struct snd_ice1712
*ice
)
1119 struct prodigy_hifi_spec
*spec
;
1124 ice
->num_total_dacs
= 1;
1125 ice
->num_total_adcs
= 1;
1127 /* HACK - use this as the SPDIF source.
1128 * don't call snd_ice1712_gpio_get/put(), otherwise it's overwritten
1130 ice
->gpio
.saved
[0] = 0;
1131 /* to remember the register values */
1133 ice
->akm
= kzalloc(sizeof(struct snd_akm4xxx
), GFP_KERNEL
);
1136 ice
->akm_codecs
= 1;
1138 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1143 #ifdef CONFIG_PM_SLEEP
1144 ice
->pm_resume
= &prodigy_hd2_resume
;
1145 ice
->pm_suspend_enabled
= 1;
1154 static unsigned char prodigy71hifi_eeprom
[] = {
1155 0x4b, /* SYSCONF: clock 512, spdif-in/ADC, 4DACs */
1156 0x80, /* ACLINK: I2S */
1157 0xfc, /* I2S: vol, 96k, 24bit, 192k */
1158 0xc3, /* SPDIF: out-en, out-int, spdif-in */
1159 0xff, /* GPIO_DIR */
1160 0xff, /* GPIO_DIR1 */
1161 0x5f, /* GPIO_DIR2 */
1162 0x00, /* GPIO_MASK */
1163 0x00, /* GPIO_MASK1 */
1164 0x00, /* GPIO_MASK2 */
1165 0x00, /* GPIO_STATE */
1166 0x00, /* GPIO_STATE1 */
1167 0x00, /* GPIO_STATE2 */
1170 static unsigned char prodigyhd2_eeprom
[] = {
1171 0x4b, /* SYSCONF: clock 512, spdif-in/ADC, 4DACs */
1172 0x80, /* ACLINK: I2S */
1173 0xfc, /* I2S: vol, 96k, 24bit, 192k */
1174 0xc3, /* SPDIF: out-en, out-int, spdif-in */
1175 0xff, /* GPIO_DIR */
1176 0xff, /* GPIO_DIR1 */
1177 0x5f, /* GPIO_DIR2 */
1178 0x00, /* GPIO_MASK */
1179 0x00, /* GPIO_MASK1 */
1180 0x00, /* GPIO_MASK2 */
1181 0x00, /* GPIO_STATE */
1182 0x00, /* GPIO_STATE1 */
1183 0x00, /* GPIO_STATE2 */
1186 static unsigned char fortissimo4_eeprom
[] = {
1187 0x43, /* SYSCONF: clock 512, ADC, 4DACs */
1188 0x80, /* ACLINK: I2S */
1189 0xfc, /* I2S: vol, 96k, 24bit, 192k */
1190 0xc1, /* SPDIF: out-en, out-int */
1191 0xff, /* GPIO_DIR */
1192 0xff, /* GPIO_DIR1 */
1193 0x5f, /* GPIO_DIR2 */
1194 0x00, /* GPIO_MASK */
1195 0x00, /* GPIO_MASK1 */
1196 0x00, /* GPIO_MASK2 */
1197 0x00, /* GPIO_STATE */
1198 0x00, /* GPIO_STATE1 */
1199 0x00, /* GPIO_STATE2 */
1203 struct snd_ice1712_card_info snd_vt1724_prodigy_hifi_cards
[] = {
1205 .subvendor
= VT1724_SUBDEVICE_PRODIGY_HIFI
,
1206 .name
= "Audiotrak Prodigy 7.1 HiFi",
1207 .model
= "prodigy71hifi",
1208 .chip_init
= prodigy_hifi_init
,
1209 .build_controls
= prodigy_hifi_add_controls
,
1210 .eeprom_size
= sizeof(prodigy71hifi_eeprom
),
1211 .eeprom_data
= prodigy71hifi_eeprom
,
1212 .driver
= "Prodigy71HIFI",
1215 .subvendor
= VT1724_SUBDEVICE_PRODIGY_HD2
,
1216 .name
= "Audiotrak Prodigy HD2",
1217 .model
= "prodigyhd2",
1218 .chip_init
= prodigy_hd2_init
,
1219 .build_controls
= prodigy_hd2_add_controls
,
1220 .eeprom_size
= sizeof(prodigyhd2_eeprom
),
1221 .eeprom_data
= prodigyhd2_eeprom
,
1222 .driver
= "Prodigy71HD2",
1225 .subvendor
= VT1724_SUBDEVICE_FORTISSIMO4
,
1226 .name
= "Hercules Fortissimo IV",
1227 .model
= "fortissimo4",
1228 .chip_init
= prodigy_hifi_init
,
1229 .build_controls
= prodigy_hifi_add_controls
,
1230 .eeprom_size
= sizeof(fortissimo4_eeprom
),
1231 .eeprom_data
= fortissimo4_eeprom
,
1232 .driver
= "Fortissimo4",
1234 { } /* terminator */