49 #include <linux/slab.h>
62 unsigned short vol[8];
66 #define WM_DAC_ATTEN 0x00
67 #define WM_DAC_MASTER_ATTEN 0x08
68 #define WM_DAC_DIG_ATTEN 0x09
69 #define WM_DAC_DIG_MASTER_ATTEN 0x11
70 #define WM_PHASE_SWAP 0x12
71 #define WM_DAC_CTRL1 0x13
73 #define WM_DAC_CTRL2 0x15
74 #define WM_INT_CTRL 0x16
75 #define WM_MASTER 0x17
76 #define WM_POWERDOWN 0x18
77 #define WM_ADC_GAIN 0x19
78 #define WM_ADC_MUX 0x1b
79 #define WM_OUT_MUX1 0x1c
80 #define WM_OUT_MUX2 0x1e
88 static const unsigned char wm_vol[256] = {
89 127, 48, 42, 39, 36, 34, 33, 31, 30, 29, 28, 27, 27, 26, 25, 25, 24,
90 24, 23, 23, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 18,
91 17, 17, 17, 17, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14,
92 14, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11,
93 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9,
94 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7,
95 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5,
96 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
97 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
98 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
99 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
100 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
103 #define WM_VOL_MAX (sizeof(wm_vol) - 1)
104 #define WM_VOL_MUTE 0x8000
130 switch (ice->
eeprom.subvendor) {
148 switch (ice->
eeprom.subvendor) {
152 &akm_phase22_priv, ice);
165 switch (ice->
eeprom.subvendor) {
175 static unsigned char phase22_eeprom[] __devinitdata = {
192 static unsigned char phase28_eeprom[] __devinitdata = {
212 static void phase28_spi_write(
struct snd_ice1712 *ice,
unsigned int cs,
218 tmp = snd_ice1712_gpio_read(ice);
224 snd_ice1712_gpio_write(ice, tmp);
227 for (i = bits - 1; i >= 0; i--) {
229 snd_ice1712_gpio_write(ice, tmp);
235 snd_ice1712_gpio_write(ice, tmp);
238 snd_ice1712_gpio_write(ice, tmp);
244 snd_ice1712_gpio_write(ice, tmp);
247 snd_ice1712_gpio_write(ice, tmp);
257 return ((
unsigned short)ice->
akm[0].images[reg] << 8) |
258 ice->
akm[0].images[reg + 1];
264 static void wm_put_nocache(
struct snd_ice1712 *ice,
int reg,
unsigned short val)
266 phase28_spi_write(ice,
PHASE28_WM_CS, (reg << 9) | (val & 0x1ff), 16);
272 static void wm_put(
struct snd_ice1712 *ice,
int reg,
unsigned short val)
274 wm_put_nocache(ice, reg, val);
276 ice->
akm[0].images[
reg] = val >> 8;
277 ice->
akm[0].images[reg + 1] =
val;
281 unsigned short vol,
unsigned short master)
288 nvol = 127 - wm_vol[(((vol & ~WM_VOL_MUTE) *
289 (master & ~WM_VOL_MUTE)) / 127) &
WM_VOL_MAX];
291 wm_put(ice, index, nvol);
292 wm_put_nocache(ice, index, 0x180 | nvol);
298 #define wm_pcm_mute_info snd_ctl_boolean_mono_info
300 static int wm_pcm_mute_get(
struct snd_kcontrol *kcontrol,
306 ucontrol->
value.integer.value[0] = (wm_get(ice,
WM_MUTE) & 0x10) ?
312 static int wm_pcm_mute_put(
struct snd_kcontrol *kcontrol,
316 unsigned short nval, oval;
319 snd_ice1712_save_gpio_status(ice);
321 nval = (oval & ~0x10) | (ucontrol->
value.integer.value[0] ? 0 : 0x10);
322 change = (nval != oval);
325 snd_ice1712_restore_gpio_status(ice);
333 static int wm_master_vol_info(
struct snd_kcontrol *kcontrol,
343 static int wm_master_vol_get(
struct snd_kcontrol *kcontrol,
349 for (i = 0; i < 2; i++)
350 ucontrol->
value.integer.value[i] = spec->
master[i] &
355 static int wm_master_vol_put(
struct snd_kcontrol *kcontrol,
362 snd_ice1712_save_gpio_status(ice);
363 for (ch = 0; ch < 2; ch++) {
364 unsigned int vol = ucontrol->
value.integer.value[ch];
368 if (vol != spec->
master[ch]) {
378 snd_ice1712_restore_gpio_status(ice);
384 static const unsigned short wm_inits_phase28[] = {
424 const unsigned short *
p;
442 snd_ice1712_gpio_set_dir(ice, 0x5fffff);
445 snd_ice1712_save_gpio_status(ice);
449 tmp = snd_ice1712_gpio_read(ice);
451 snd_ice1712_gpio_write(ice, tmp);
454 snd_ice1712_gpio_write(ice, tmp);
457 snd_ice1712_gpio_write(ice, tmp);
460 p = wm_inits_phase28;
461 for (; *p != (
unsigned short)-1; p += 2)
462 wm_put(ice, p[0], p[1]);
464 snd_ice1712_restore_gpio_status(ice);
470 wm_set_vol(ice, i, spec->
vol[i], spec->
master[i % 2]);
484 uinfo->
count = voices;
499 for (i = 0; i < voices; i++)
500 ucontrol->
value.integer.value[i] =
510 int i,
idx, ofs, voices;
515 snd_ice1712_save_gpio_status(ice);
516 for (i = 0; i < voices; i++) {
518 vol = ucontrol->
value.integer.value[
i];
522 if (vol != spec->
vol[ofs+i]) {
525 wm_set_vol(ice, idx, spec->
vol[ofs+i],
530 snd_ice1712_restore_gpio_status(ice);
556 for (i = 0; i < voices; i++)
557 ucontrol->
value.integer.value[i] =
567 int change = 0, voices, ofs,
i;
572 snd_ice1712_save_gpio_status(ice);
573 for (i = 0; i < voices; i++) {
575 if (ucontrol->
value.integer.value[i] != val) {
577 spec->
vol[ofs +
i] |=
578 ucontrol->
value.integer.value[
i] ? 0 :
580 wm_set_vol(ice, ofs + i, spec->
vol[ofs + i],
585 snd_ice1712_restore_gpio_status(ice);
593 #define wm_master_mute_info snd_ctl_boolean_stereo_info
595 static int wm_master_mute_get(
struct snd_kcontrol *kcontrol,
601 ucontrol->
value.integer.value[0] =
603 ucontrol->
value.integer.value[1] =
608 static int wm_master_mute_put(
struct snd_kcontrol *kcontrol,
615 snd_ice1712_save_gpio_status(ice);
616 for (i = 0; i < 2; i++) {
618 if (ucontrol->
value.integer.value[i] != val) {
622 ucontrol->
value.integer.value[
i] ? 0 :
631 snd_ice1712_restore_gpio_status(ice);
639 #define PCM_MIN (PCM_0dB - PCM_RES)
640 static int wm_pcm_vol_info(
struct snd_kcontrol *kcontrol,
650 static int wm_pcm_vol_get(
struct snd_kcontrol *kcontrol,
659 ucontrol->
value.integer.value[0] =
val;
664 static int wm_pcm_vol_put(
struct snd_kcontrol *kcontrol,
668 unsigned short ovol, nvol;
671 nvol = ucontrol->
value.integer.value[0];
674 snd_ice1712_save_gpio_status(ice);
675 nvol = (nvol ? (nvol +
PCM_MIN) : 0) & 0xff;
683 snd_ice1712_restore_gpio_status(ice);
690 #define phase28_deemp_info snd_ctl_boolean_mono_info
692 static int phase28_deemp_get(
struct snd_kcontrol *kcontrol,
701 static int phase28_deemp_put(
struct snd_kcontrol *kcontrol,
708 if (ucontrol->
value.integer.value[0])
725 static char *texts[2] = {
"128x",
"64x" };
740 static int phase28_oversampling_get(
struct snd_kcontrol *kcontrol,
744 ucontrol->
value.enumerated.item[0] = (wm_get(ice,
WM_MASTER) & 0x8) ==
749 static int phase28_oversampling_put(
struct snd_kcontrol *kcontrol,
758 if (ucontrol->
value.enumerated.item[0])
776 .name =
"Master Playback Switch",
778 .get = wm_master_mute_get,
779 .put = wm_master_mute_put
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 }
793 .name =
"Front Playback Switch",
794 .info = wm_mute_info,
797 .private_value = (2 << 8) | 0
803 .
name =
"Front Playback Volume",
808 .tlv = { .p = db_scale_wm_dac }
812 .name =
"Rear Playback Switch",
813 .info = wm_mute_info,
816 .private_value = (2 << 8) | 2
822 .
name =
"Rear Playback Volume",
827 .tlv = { .p = db_scale_wm_dac }
831 .name =
"Center Playback Switch",
832 .info = wm_mute_info,
835 .private_value = (1 << 8) | 4
841 .
name =
"Center Playback Volume",
846 .tlv = { .p = db_scale_wm_dac }
850 .name =
"LFE Playback Switch",
851 .info = wm_mute_info,
854 .private_value = (1 << 8) | 5
860 .
name =
"LFE Playback Volume",
865 .tlv = { .p = db_scale_wm_dac }
869 .name =
"Side Playback Switch",
870 .info = wm_mute_info,
873 .private_value = (2 << 8) | 6
879 .
name =
"Side Playback Volume",
884 .tlv = { .p = db_scale_wm_dac }
891 .name =
"PCM Playback Switch",
893 .get = wm_pcm_mute_get,
894 .put = wm_pcm_mute_put
900 .
name =
"PCM Playback Volume",
901 .
info = wm_pcm_vol_info,
902 .
get = wm_pcm_vol_get,
903 .
put = wm_pcm_vol_put,
904 .
tlv = { .p = db_scale_wm_pcm }
908 .name =
"DAC Deemphasis Switch",
910 .get = phase28_deemp_get,
911 .put = phase28_deemp_put
915 .name =
"ADC Oversampling",
916 .info = phase28_oversampling_info,
917 .get = phase28_oversampling_get,
918 .put = phase28_oversampling_put
924 unsigned int i, counts;
928 for (i = 0; i < counts; i++) {
936 for (i = 0; i <
ARRAY_SIZE(wm_controls); i++) {
949 .name =
"Terratec PHASE 22",
951 .chip_init = phase22_init,
952 .build_controls = phase22_add_controls,
953 .eeprom_size =
sizeof(phase22_eeprom),
958 .name =
"Terratec PHASE 28",
960 .chip_init = phase28_init,
961 .build_controls = phase28_add_controls,
962 .eeprom_size =
sizeof(phase28_eeprom),
967 .name =
"Terrasoniq TS22 PCI",
969 .chip_init = phase22_init,
970 .build_controls = phase22_add_controls,
971 .eeprom_size =
sizeof(phase22_eeprom),