32 #include <linux/slab.h>
45 unsigned short vol[8];
52 #define WM_HP_ATTEN_L 0x00
53 #define WM_HP_ATTEN_R 0x01
54 #define WM_HP_MASTER 0x02
56 #define WM_DAC_ATTEN_L 0x03
57 #define WM_DAC_ATTEN_R 0x04
58 #define WM_DAC_MASTER 0x05
59 #define WM_PHASE_SWAP 0x06
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
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"
89 #define WM8766_SPI_CLK (1<<17)
90 #define WM8766_SPI_MD (1<<16)
91 #define WM8766_SPI_ML (1<<18)
94 #define WM8766_DAC_CTRL 0x02
95 #define WM8766_INT_CTRL 0x03
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)
114 #define AK4396_CCLK (1 << 9)
115 #define AK4396_CDTI (1 << 10)
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
131 return ((
unsigned short)ice->
akm[0].images[reg] << 8) |
132 ice->
akm[0].images[reg + 1];
141 cval = (reg << 9) | val;
147 wm_put_nocache(ice, reg, val);
149 ice->
akm[0].images[
reg] = val >> 8;
150 ice->
akm[0].images[reg + 1] =
val;
159 unsigned int tmp = snd_ice1712_gpio_read(ice);
164 snd_ice1712_gpio_write(ice, tmp);
171 static void wm8766_spi_send_word(
struct snd_ice1712 *ice,
unsigned int data)
174 for (i = 0; i < 16; i++) {
185 static void wm8766_spi_write(
struct snd_ice1712 *ice,
unsigned int reg,
196 block = (reg << 9) | (data & 0x1ff);
197 wm8766_spi_send_word(ice, block);
202 snd_ice1712_gpio_set_mask(ice, ice->
gpio.write_mask);
203 snd_ice1712_gpio_set_dir(ice, ice->
gpio.direction);
211 static void ak4396_send_word(
struct snd_ice1712 *ice,
unsigned int data)
214 for (i = 0; i < 16; i++) {
225 static void ak4396_write(
struct snd_ice1712 *ice,
unsigned int reg,
235 ((reg & 0x1f) << 8) | (data & 0xff);
236 ak4396_send_word(ice, block);
241 snd_ice1712_gpio_set_mask(ice, ice->
gpio.write_mask);
242 snd_ice1712_gpio_set_dir(ice, ice->
gpio.direction);
256 static int ak4396_dac_vol_info(
struct snd_kcontrol *kcontrol,
266 static int ak4396_dac_vol_get(
struct snd_kcontrol *kcontrol,
273 for (i = 0; i < 2; i++)
274 ucontrol->
value.integer.value[i] = spec->
vol[i];
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];
291 spec->
vol[i] & 0xff);
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 },
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)
347 unsigned short vol,
unsigned short master)
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);
364 unsigned short vol,
unsigned short master)
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));
384 static int wm_dac_vol_info(
struct snd_kcontrol *kcontrol,
394 static int wm_dac_vol_get(
struct snd_kcontrol *kcontrol,
401 for (i = 0; i < 2; i++)
402 ucontrol->
value.integer.value[i] =
403 spec->
vol[2 + i] & ~WM_VOL_MUTE;
411 int i,
idx, change = 0;
414 for (i = 0; i < 2; i++) {
415 if (ucontrol->
value.integer.value[i] != spec->
vol[2 + i]) {
418 spec->
vol[2 +
i] |= ucontrol->
value.integer.value[
i];
419 wm_set_vol(ice, idx, spec->
vol[2 + i], spec->
master[i]);
431 static int wm8766_vol_info(
struct snd_kcontrol *kcontrol,
436 uinfo->
count = voices;
442 static int wm8766_vol_get(
struct snd_kcontrol *kcontrol,
451 for (i = 0; i < voices; i++)
452 ucontrol->
value.integer.value[i] = spec->
vol[ofs + i];
460 int i,
idx, ofs, voices;
466 for (i = 0; i < voices; i++) {
467 if (ucontrol->
value.integer.value[i] != spec->
vol[ofs + i]) {
470 spec->
vol[ofs +
i] |= ucontrol->
value.integer.value[
i];
471 wm8766_set_vol(ice, idx,
483 static int wm_master_vol_info(
struct snd_kcontrol *kcontrol,
493 static int wm_master_vol_get(
struct snd_kcontrol *kcontrol,
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,
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];
538 static int wm_adc_mux_enum_info(
struct snd_kcontrol *kcontrol,
541 static char* texts[32] = {
548 WM_AIN2
"+" WM_AIN3
"+" WM_AIN4,
553 WM_AIN2
"+" WM_AIN3
"+" WM_AIN5,
556 WM_AIN2
"+" WM_AIN4
"+" WM_AIN5,
558 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
574 static int wm_adc_mux_enum_get(
struct snd_kcontrol *kcontrol,
585 static int wm_adc_mux_enum_put(
struct snd_kcontrol *kcontrol,
589 unsigned short oval, nval;
594 nval = (oval & 0xe0) | ucontrol->
value.integer.value[0];
611 #define ADC_MIN (ADC_0dB - ADC_RES)
613 static int wm_adc_vol_info(
struct snd_kcontrol *kcontrol,
623 static int wm_adc_vol_get(
struct snd_kcontrol *kcontrol,
631 for (i = 0; i < 2; i++) {
640 static int wm_adc_vol_put(
struct snd_kcontrol *kcontrol,
644 unsigned short ovol, nvol;
645 int i,
idx, change = 0;
648 for (i = 0; i < 2; i++) {
649 nvol = ucontrol->
value.integer.value[
i];
650 nvol = nvol ? (nvol +
ADC_MIN) : 0;
652 ovol = wm_get(ice, idx) & 0xff;
654 wm_put(ice, idx, nvol);
665 #define wm_adc_mux_info snd_ctl_boolean_mono_info
667 static int wm_adc_mux_get(
struct snd_kcontrol *kcontrol,
674 ucontrol->
value.integer.value[0] =
680 static int wm_adc_mux_put(
struct snd_kcontrol *kcontrol,
685 unsigned short oval, nval;
690 if (ucontrol->
value.integer.value[0])
694 change = nval != oval;
705 #define wm_bypass_info snd_ctl_boolean_mono_info
713 ucontrol->
value.integer.value[0] =
723 unsigned short val, oval;
728 if (ucontrol->
value.integer.value[0])
743 #define wm_chswap_info snd_ctl_boolean_mono_info
751 ucontrol->
value.integer.value[0] =
761 unsigned short val, oval;
767 if (ucontrol->
value.integer.value[0])
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 }
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 },
810 .
name =
"Rear Playback Volume",
811 .
info = wm8766_vol_info,
812 .
get = wm8766_vol_get,
813 .
put = wm8766_vol_put,
815 .tlv = { .p = db_scale_wm_dac },
821 .
name =
"Center Playback Volume",
822 .
info = wm8766_vol_info,
823 .
get = wm8766_vol_get,
824 .
put = wm8766_vol_put,
826 .tlv = { .p = db_scale_wm_dac }
832 .
name =
"LFE Playback Volume",
833 .
info = wm8766_vol_info,
834 .
get = wm8766_vol_get,
835 .
put = wm8766_vol_put,
837 .tlv = { .p = db_scale_wm_dac }
843 .
name =
"Side Playback Volume",
844 .
info = wm8766_vol_info,
845 .
get = wm8766_vol_get,
846 .
put = wm8766_vol_put,
848 .tlv = { .p = db_scale_wm_dac },
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 },
862 .name =
"CD Capture Switch",
864 .get = wm_adc_mux_get,
865 .put = wm_adc_mux_put,
870 .name =
"Line Capture Switch",
872 .get = wm_adc_mux_get,
873 .put = wm_adc_mux_put,
878 .name =
"Analog Bypass Switch",
880 .get = wm_bypass_get,
881 .put = wm_bypass_put,
885 .name =
"Swap Output Channels",
887 .get = wm_chswap_get,
888 .put = wm_chswap_put,
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,
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);
925 for (reg = 0; reg <= 0x17; reg++) {
926 val = wm_get(ice, reg);
927 snd_iprintf(buffer,
"%02x = %04x\n", reg, val);
935 if (!snd_card_proc_new(ice->
card,
"wm_codec", &entry)) {
936 snd_info_set_text_ops(entry, ice, wm_proc_regs_read);
938 entry->
c.
text.write = wm_proc_regs_write;
947 for (i = 0; i <
ARRAY_SIZE(prodigy_hifi_controls); i++) {
964 for (i = 0; i <
ARRAY_SIZE(prodigy_hd2_controls); i++) {
982 static unsigned short wm_inits[] = {
993 static unsigned short wm_inits2[] = {
1021 static unsigned short wm8766_inits[] = {
1049 ice->
gpio.saved[0] = 0;
1063 for (i = 0; i <
ARRAY_SIZE(wm_inits); i += 2)
1064 wm_put(ice, wm_inits[i], wm_inits[i+1]);
1066 for (i = 0; i <
ARRAY_SIZE(wm_inits2); i += 2)
1067 wm_put(ice, wm_inits2[i], wm_inits2[i+1]);
1070 for (i = 0; i <
ARRAY_SIZE(wm8766_inits); i += 2)
1071 wm8766_spi_write(ice, wm8766_inits[i], wm8766_inits[i+1]);
1083 static unsigned short ak4396_inits[] = {
1099 for (i = 0; i <
ARRAY_SIZE(ak4396_inits); i += 2)
1100 ak4396_write(ice, ak4396_inits[i], ak4396_inits[i+1]);
1103 #ifdef CONFIG_PM_SLEEP
1104 static int prodigy_hd2_resume(
struct snd_ice1712 *ice)
1111 for (i = 0; i < 2; i++)
1131 ice->
gpio.saved[0] = 0;
1144 #ifdef CONFIG_PM_SLEEP
1145 ice->pm_resume = &prodigy_hd2_resume;
1146 ice->pm_suspend_enabled = 1;
1155 static unsigned char prodigy71hifi_eeprom[] __devinitdata = {
1171 static unsigned char prodigyhd2_eeprom[] __devinitdata = {
1187 static unsigned char fortissimo4_eeprom[] __devinitdata = {
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),
1213 .
driver =
"Prodigy71HIFI",
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),
1223 .
driver =
"Prodigy71HD2",
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),