1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ALSA driver for ICEnsemble ICE1724 (Envy24)
5 * Lowlevel functions for Terratec PHASE 22
7 * Copyright (c) 2005 Misha Zhilin <misha@epiphan.com>
11 * Audio controller: VIA Envy24HT-S (slightly trimmed down Envy24HT, 4in/4out)
12 * Analog chip: AK4524 (partially via Philip's 74HCT125)
13 * Digital receiver: CS8414-CS (supported in this release)
14 * PHASE 22 revision 2.0 and Terrasoniq/Musonik TS22PCI have CS8416
15 * (support status unknown, please test and report)
17 * Envy connects to AK4524
18 * - CS directly from GPIO 10
19 * - CCLK via 74HCT125's gate #4 from GPIO 4
20 * - CDTI via 74HCT125's gate #2 from GPIO 5
21 * CDTI may be completely blocked by 74HCT125's gate #1
22 * controlled by GPIO 3
26 * Audio controller: VIA Envy24HT (full untrimmed version, 4in/8out)
27 * Analog chip: WM8770 (8 channel 192k DAC, 2 channel 96k ADC)
28 * Digital receiver: CS8414-CS (supported in this release)
31 #include <linux/delay.h>
32 #include <linux/interrupt.h>
33 #include <linux/init.h>
34 #include <linux/slab.h>
35 #include <linux/mutex.h>
37 #include <sound/core.h>
42 #include <sound/tlv.h>
44 /* AC97 register cache for Phase28 */
46 unsigned short master
[2];
47 unsigned short vol
[8];
50 /* WM8770 registers */
51 #define WM_DAC_ATTEN 0x00 /* DAC1-8 analog attenuation */
52 #define WM_DAC_MASTER_ATTEN 0x08 /* DAC master analog attenuation */
53 #define WM_DAC_DIG_ATTEN 0x09 /* DAC1-8 digital attenuation */
54 #define WM_DAC_DIG_MASTER_ATTEN 0x11 /* DAC master digital attenuation */
55 #define WM_PHASE_SWAP 0x12 /* DAC phase */
56 #define WM_DAC_CTRL1 0x13 /* DAC control bits */
57 #define WM_MUTE 0x14 /* mute controls */
58 #define WM_DAC_CTRL2 0x15 /* de-emphasis and zefo-flag */
59 #define WM_INT_CTRL 0x16 /* interface control */
60 #define WM_MASTER 0x17 /* master clock and mode */
61 #define WM_POWERDOWN 0x18 /* power-down controls */
62 #define WM_ADC_GAIN 0x19 /* ADC gain L(19)/R(1a) */
63 #define WM_ADC_MUX 0x1b /* input MUX */
64 #define WM_OUT_MUX1 0x1c /* output MUX */
65 #define WM_OUT_MUX2 0x1e /* output MUX */
66 #define WM_RESET 0x1f /* software reset */
70 * Logarithmic volume values for WM8770
71 * Computed as 20 * Log10(255 / x)
73 static const unsigned char wm_vol
[256] = {
74 127, 48, 42, 39, 36, 34, 33, 31, 30, 29, 28, 27, 27, 26, 25, 25, 24,
75 24, 23, 23, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 18,
76 17, 17, 17, 17, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14,
77 14, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11,
78 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9,
79 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7,
80 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5,
81 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
82 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
83 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
84 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
85 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
88 #define WM_VOL_MAX (sizeof(wm_vol) - 1)
89 #define WM_VOL_MUTE 0x8000
91 static const struct snd_akm4xxx akm_phase22
= {
97 static const struct snd_ak4xxx_private akm_phase22_priv
= {
109 static int phase22_init(struct snd_ice1712
*ice
)
111 struct snd_akm4xxx
*ak
;
114 /* Configure DAC/ADC description for generic part of ice1724 */
115 switch (ice
->eeprom
.subvendor
) {
116 case VT1724_SUBDEVICE_PHASE22
:
117 case VT1724_SUBDEVICE_TS22
:
118 ice
->num_total_dacs
= 2;
119 ice
->num_total_adcs
= 2;
120 ice
->vt1720
= 1; /* Envy24HT-S have 16 bit wide GPIO */
127 /* Initialize analog chips */
128 ice
->akm
= kzalloc(sizeof(struct snd_akm4xxx
), GFP_KERNEL
);
133 switch (ice
->eeprom
.subvendor
) {
134 case VT1724_SUBDEVICE_PHASE22
:
135 case VT1724_SUBDEVICE_TS22
:
136 err
= snd_ice1712_akm4xxx_init(ak
, &akm_phase22
,
137 &akm_phase22_priv
, ice
);
146 static int phase22_add_controls(struct snd_ice1712
*ice
)
150 switch (ice
->eeprom
.subvendor
) {
151 case VT1724_SUBDEVICE_PHASE22
:
152 case VT1724_SUBDEVICE_TS22
:
153 err
= snd_ice1712_akm4xxx_build_controls(ice
);
160 static const unsigned char phase22_eeprom
[] = {
161 [ICE_EEP2_SYSCONF
] = 0x28, /* clock 512, mpu 401,
162 spdif-in/1xADC, 1xDACs */
163 [ICE_EEP2_ACLINK
] = 0x80, /* I2S */
164 [ICE_EEP2_I2S
] = 0xf0, /* vol, 96k, 24bit */
165 [ICE_EEP2_SPDIF
] = 0xc3, /* out-en, out-int, spdif-in */
166 [ICE_EEP2_GPIO_DIR
] = 0xff,
167 [ICE_EEP2_GPIO_DIR1
] = 0xff,
168 [ICE_EEP2_GPIO_DIR2
] = 0xff,
169 [ICE_EEP2_GPIO_MASK
] = 0x00,
170 [ICE_EEP2_GPIO_MASK1
] = 0x00,
171 [ICE_EEP2_GPIO_MASK2
] = 0x00,
172 [ICE_EEP2_GPIO_STATE
] = 0x00,
173 [ICE_EEP2_GPIO_STATE1
] = 0x00,
174 [ICE_EEP2_GPIO_STATE2
] = 0x00,
177 static const unsigned char phase28_eeprom
[] = {
178 [ICE_EEP2_SYSCONF
] = 0x2b, /* clock 512, mpu401,
179 spdif-in/1xADC, 4xDACs */
180 [ICE_EEP2_ACLINK
] = 0x80, /* I2S */
181 [ICE_EEP2_I2S
] = 0xfc, /* vol, 96k, 24bit, 192k */
182 [ICE_EEP2_SPDIF
] = 0xc3, /* out-en, out-int, spdif-in */
183 [ICE_EEP2_GPIO_DIR
] = 0xff,
184 [ICE_EEP2_GPIO_DIR1
] = 0xff,
185 [ICE_EEP2_GPIO_DIR2
] = 0x5f,
186 [ICE_EEP2_GPIO_MASK
] = 0x00,
187 [ICE_EEP2_GPIO_MASK1
] = 0x00,
188 [ICE_EEP2_GPIO_MASK2
] = 0x00,
189 [ICE_EEP2_GPIO_STATE
] = 0x00,
190 [ICE_EEP2_GPIO_STATE1
] = 0x00,
191 [ICE_EEP2_GPIO_STATE2
] = 0x00,
195 * write data in the SPI mode
197 static void phase28_spi_write(struct snd_ice1712
*ice
, unsigned int cs
,
198 unsigned int data
, int bits
)
203 tmp
= snd_ice1712_gpio_read(ice
);
205 snd_ice1712_gpio_set_mask(ice
, ~(PHASE28_WM_RW
|PHASE28_SPI_MOSI
|
206 PHASE28_SPI_CLK
|PHASE28_WM_CS
));
207 tmp
|= PHASE28_WM_RW
;
209 snd_ice1712_gpio_write(ice
, tmp
);
212 for (i
= bits
- 1; i
>= 0; i
--) {
213 tmp
&= ~PHASE28_SPI_CLK
;
214 snd_ice1712_gpio_write(ice
, tmp
);
217 tmp
|= PHASE28_SPI_MOSI
;
219 tmp
&= ~PHASE28_SPI_MOSI
;
220 snd_ice1712_gpio_write(ice
, tmp
);
222 tmp
|= PHASE28_SPI_CLK
;
223 snd_ice1712_gpio_write(ice
, tmp
);
227 tmp
&= ~PHASE28_SPI_CLK
;
229 snd_ice1712_gpio_write(ice
, tmp
);
231 tmp
|= PHASE28_SPI_CLK
;
232 snd_ice1712_gpio_write(ice
, tmp
);
237 * get the current register value of WM codec
239 static unsigned short wm_get(struct snd_ice1712
*ice
, int reg
)
242 return ((unsigned short)ice
->akm
[0].images
[reg
] << 8) |
243 ice
->akm
[0].images
[reg
+ 1];
247 * set the register value of WM codec
249 static void wm_put_nocache(struct snd_ice1712
*ice
, int reg
, unsigned short val
)
251 phase28_spi_write(ice
, PHASE28_WM_CS
, (reg
<< 9) | (val
& 0x1ff), 16);
255 * set the register value of WM codec and remember it
257 static void wm_put(struct snd_ice1712
*ice
, int reg
, unsigned short val
)
259 wm_put_nocache(ice
, reg
, val
);
261 ice
->akm
[0].images
[reg
] = val
>> 8;
262 ice
->akm
[0].images
[reg
+ 1] = val
;
265 static void wm_set_vol(struct snd_ice1712
*ice
, unsigned int index
,
266 unsigned short vol
, unsigned short master
)
270 if ((master
& WM_VOL_MUTE
) || (vol
& WM_VOL_MUTE
))
273 nvol
= 127 - wm_vol
[(((vol
& ~WM_VOL_MUTE
) *
274 (master
& ~WM_VOL_MUTE
)) / 127) & WM_VOL_MAX
];
276 wm_put(ice
, index
, nvol
);
277 wm_put_nocache(ice
, index
, 0x180 | nvol
);
283 #define wm_pcm_mute_info snd_ctl_boolean_mono_info
285 static int wm_pcm_mute_get(struct snd_kcontrol
*kcontrol
,
286 struct snd_ctl_elem_value
*ucontrol
)
288 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
290 mutex_lock(&ice
->gpio_mutex
);
291 ucontrol
->value
.integer
.value
[0] = (wm_get(ice
, WM_MUTE
) & 0x10) ?
293 mutex_unlock(&ice
->gpio_mutex
);
297 static int wm_pcm_mute_put(struct snd_kcontrol
*kcontrol
,
298 struct snd_ctl_elem_value
*ucontrol
)
300 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
301 unsigned short nval
, oval
;
304 snd_ice1712_save_gpio_status(ice
);
305 oval
= wm_get(ice
, WM_MUTE
);
306 nval
= (oval
& ~0x10) | (ucontrol
->value
.integer
.value
[0] ? 0 : 0x10);
307 change
= (nval
!= oval
);
309 wm_put(ice
, WM_MUTE
, nval
);
310 snd_ice1712_restore_gpio_status(ice
);
316 * Master volume attenuation mixer control
318 static int wm_master_vol_info(struct snd_kcontrol
*kcontrol
,
319 struct snd_ctl_elem_info
*uinfo
)
321 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
323 uinfo
->value
.integer
.min
= 0;
324 uinfo
->value
.integer
.max
= WM_VOL_MAX
;
328 static int wm_master_vol_get(struct snd_kcontrol
*kcontrol
,
329 struct snd_ctl_elem_value
*ucontrol
)
331 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
332 struct phase28_spec
*spec
= ice
->spec
;
334 for (i
= 0; i
< 2; i
++)
335 ucontrol
->value
.integer
.value
[i
] = spec
->master
[i
] &
340 static int wm_master_vol_put(struct snd_kcontrol
*kcontrol
,
341 struct snd_ctl_elem_value
*ucontrol
)
343 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
344 struct phase28_spec
*spec
= ice
->spec
;
347 snd_ice1712_save_gpio_status(ice
);
348 for (ch
= 0; ch
< 2; ch
++) {
349 unsigned int vol
= ucontrol
->value
.integer
.value
[ch
];
350 if (vol
> WM_VOL_MAX
)
352 vol
|= spec
->master
[ch
] & WM_VOL_MUTE
;
353 if (vol
!= spec
->master
[ch
]) {
355 spec
->master
[ch
] = vol
;
356 for (dac
= 0; dac
< ice
->num_total_dacs
; dac
+= 2)
357 wm_set_vol(ice
, WM_DAC_ATTEN
+ dac
+ ch
,
363 snd_ice1712_restore_gpio_status(ice
);
367 static int phase28_init(struct snd_ice1712
*ice
)
369 static const unsigned short wm_inits_phase28
[] = {
370 /* These come first to reduce init pop noise */
371 0x1b, 0x044, /* ADC Mux (AC'97 source) */
372 0x1c, 0x00B, /* Out Mux1 (VOUT1 = DAC+AUX, VOUT2 = DAC) */
373 0x1d, 0x009, /* Out Mux2 (VOUT2 = DAC, VOUT3 = DAC) */
375 0x18, 0x000, /* All power-up */
377 0x16, 0x122, /* I2S, normal polarity, 24bit */
378 0x17, 0x022, /* 256fs, slave mode */
379 0x00, 0, /* DAC1 analog mute */
380 0x01, 0, /* DAC2 analog mute */
381 0x02, 0, /* DAC3 analog mute */
382 0x03, 0, /* DAC4 analog mute */
383 0x04, 0, /* DAC5 analog mute */
384 0x05, 0, /* DAC6 analog mute */
385 0x06, 0, /* DAC7 analog mute */
386 0x07, 0, /* DAC8 analog mute */
387 0x08, 0x100, /* master analog mute */
388 0x09, 0xff, /* DAC1 digital full */
389 0x0a, 0xff, /* DAC2 digital full */
390 0x0b, 0xff, /* DAC3 digital full */
391 0x0c, 0xff, /* DAC4 digital full */
392 0x0d, 0xff, /* DAC5 digital full */
393 0x0e, 0xff, /* DAC6 digital full */
394 0x0f, 0xff, /* DAC7 digital full */
395 0x10, 0xff, /* DAC8 digital full */
396 0x11, 0x1ff, /* master digital full */
397 0x12, 0x000, /* phase normal */
398 0x13, 0x090, /* unmute DAC L/R */
399 0x14, 0x000, /* all unmute */
400 0x15, 0x000, /* no deemphasis, no ZFLG */
401 0x19, 0x000, /* -12dB ADC/L */
402 0x1a, 0x000, /* -12dB ADC/R */
407 struct snd_akm4xxx
*ak
;
408 struct phase28_spec
*spec
;
409 const unsigned short *p
;
412 ice
->num_total_dacs
= 8;
413 ice
->num_total_adcs
= 2;
415 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
420 /* Initialize analog chips */
421 ice
->akm
= kzalloc(sizeof(struct snd_akm4xxx
), GFP_KERNEL
);
427 snd_ice1712_gpio_set_dir(ice
, 0x5fffff); /* fix this for time being */
429 /* reset the wm codec as the SPI mode */
430 snd_ice1712_save_gpio_status(ice
);
431 snd_ice1712_gpio_set_mask(ice
, ~(PHASE28_WM_RESET
|PHASE28_WM_CS
|
434 tmp
= snd_ice1712_gpio_read(ice
);
435 tmp
&= ~PHASE28_WM_RESET
;
436 snd_ice1712_gpio_write(ice
, tmp
);
438 tmp
|= PHASE28_WM_CS
;
439 snd_ice1712_gpio_write(ice
, tmp
);
441 tmp
|= PHASE28_WM_RESET
;
442 snd_ice1712_gpio_write(ice
, tmp
);
445 p
= wm_inits_phase28
;
446 for (; *p
!= (unsigned short)-1; p
+= 2)
447 wm_put(ice
, p
[0], p
[1]);
449 snd_ice1712_restore_gpio_status(ice
);
451 spec
->master
[0] = WM_VOL_MUTE
;
452 spec
->master
[1] = WM_VOL_MUTE
;
453 for (i
= 0; i
< ice
->num_total_dacs
; i
++) {
454 spec
->vol
[i
] = WM_VOL_MUTE
;
455 wm_set_vol(ice
, i
, spec
->vol
[i
], spec
->master
[i
% 2]);
462 * DAC volume attenuation mixer control
464 static int wm_vol_info(struct snd_kcontrol
*kcontrol
,
465 struct snd_ctl_elem_info
*uinfo
)
467 int voices
= kcontrol
->private_value
>> 8;
468 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
469 uinfo
->count
= voices
;
470 uinfo
->value
.integer
.min
= 0; /* mute (-101dB) */
471 uinfo
->value
.integer
.max
= 0x7F; /* 0dB */
475 static int wm_vol_get(struct snd_kcontrol
*kcontrol
,
476 struct snd_ctl_elem_value
*ucontrol
)
478 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
479 struct phase28_spec
*spec
= ice
->spec
;
482 voices
= kcontrol
->private_value
>> 8;
483 ofs
= kcontrol
->private_value
& 0xff;
484 for (i
= 0; i
< voices
; i
++)
485 ucontrol
->value
.integer
.value
[i
] =
486 spec
->vol
[ofs
+i
] & ~WM_VOL_MUTE
;
490 static int wm_vol_put(struct snd_kcontrol
*kcontrol
,
491 struct snd_ctl_elem_value
*ucontrol
)
493 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
494 struct phase28_spec
*spec
= ice
->spec
;
495 int i
, idx
, ofs
, voices
;
498 voices
= kcontrol
->private_value
>> 8;
499 ofs
= kcontrol
->private_value
& 0xff;
500 snd_ice1712_save_gpio_status(ice
);
501 for (i
= 0; i
< voices
; i
++) {
503 vol
= ucontrol
->value
.integer
.value
[i
];
506 vol
|= spec
->vol
[ofs
+i
] & WM_VOL_MUTE
;
507 if (vol
!= spec
->vol
[ofs
+i
]) {
508 spec
->vol
[ofs
+i
] = vol
;
509 idx
= WM_DAC_ATTEN
+ ofs
+ i
;
510 wm_set_vol(ice
, idx
, spec
->vol
[ofs
+i
],
515 snd_ice1712_restore_gpio_status(ice
);
520 * WM8770 mute control
522 static int wm_mute_info(struct snd_kcontrol
*kcontrol
,
523 struct snd_ctl_elem_info
*uinfo
) {
524 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
525 uinfo
->count
= kcontrol
->private_value
>> 8;
526 uinfo
->value
.integer
.min
= 0;
527 uinfo
->value
.integer
.max
= 1;
531 static int wm_mute_get(struct snd_kcontrol
*kcontrol
,
532 struct snd_ctl_elem_value
*ucontrol
)
534 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
535 struct phase28_spec
*spec
= ice
->spec
;
538 voices
= kcontrol
->private_value
>> 8;
539 ofs
= kcontrol
->private_value
& 0xFF;
541 for (i
= 0; i
< voices
; i
++)
542 ucontrol
->value
.integer
.value
[i
] =
543 (spec
->vol
[ofs
+i
] & WM_VOL_MUTE
) ? 0 : 1;
547 static int wm_mute_put(struct snd_kcontrol
*kcontrol
,
548 struct snd_ctl_elem_value
*ucontrol
)
550 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
551 struct phase28_spec
*spec
= ice
->spec
;
552 int change
= 0, voices
, ofs
, i
;
554 voices
= kcontrol
->private_value
>> 8;
555 ofs
= kcontrol
->private_value
& 0xFF;
557 snd_ice1712_save_gpio_status(ice
);
558 for (i
= 0; i
< voices
; i
++) {
559 int val
= (spec
->vol
[ofs
+ i
] & WM_VOL_MUTE
) ? 0 : 1;
560 if (ucontrol
->value
.integer
.value
[i
] != val
) {
561 spec
->vol
[ofs
+ i
] &= ~WM_VOL_MUTE
;
562 spec
->vol
[ofs
+ i
] |=
563 ucontrol
->value
.integer
.value
[i
] ? 0 :
565 wm_set_vol(ice
, ofs
+ i
, spec
->vol
[ofs
+ i
],
570 snd_ice1712_restore_gpio_status(ice
);
576 * WM8770 master mute control
578 #define wm_master_mute_info snd_ctl_boolean_stereo_info
580 static int wm_master_mute_get(struct snd_kcontrol
*kcontrol
,
581 struct snd_ctl_elem_value
*ucontrol
)
583 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
584 struct phase28_spec
*spec
= ice
->spec
;
586 ucontrol
->value
.integer
.value
[0] =
587 (spec
->master
[0] & WM_VOL_MUTE
) ? 0 : 1;
588 ucontrol
->value
.integer
.value
[1] =
589 (spec
->master
[1] & WM_VOL_MUTE
) ? 0 : 1;
593 static int wm_master_mute_put(struct snd_kcontrol
*kcontrol
,
594 struct snd_ctl_elem_value
*ucontrol
)
596 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
597 struct phase28_spec
*spec
= ice
->spec
;
600 snd_ice1712_save_gpio_status(ice
);
601 for (i
= 0; i
< 2; i
++) {
602 int val
= (spec
->master
[i
] & WM_VOL_MUTE
) ? 0 : 1;
603 if (ucontrol
->value
.integer
.value
[i
] != val
) {
605 spec
->master
[i
] &= ~WM_VOL_MUTE
;
607 ucontrol
->value
.integer
.value
[i
] ? 0 :
609 for (dac
= 0; dac
< ice
->num_total_dacs
; dac
+= 2)
610 wm_set_vol(ice
, WM_DAC_ATTEN
+ dac
+ i
,
616 snd_ice1712_restore_gpio_status(ice
);
621 /* digital master volume */
623 #define PCM_RES 128 /* -64dB */
624 #define PCM_MIN (PCM_0dB - PCM_RES)
625 static int wm_pcm_vol_info(struct snd_kcontrol
*kcontrol
,
626 struct snd_ctl_elem_info
*uinfo
)
628 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
630 uinfo
->value
.integer
.min
= 0; /* mute (-64dB) */
631 uinfo
->value
.integer
.max
= PCM_RES
; /* 0dB */
635 static int wm_pcm_vol_get(struct snd_kcontrol
*kcontrol
,
636 struct snd_ctl_elem_value
*ucontrol
)
638 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
641 mutex_lock(&ice
->gpio_mutex
);
642 val
= wm_get(ice
, WM_DAC_DIG_MASTER_ATTEN
) & 0xff;
643 val
= val
> PCM_MIN
? (val
- PCM_MIN
) : 0;
644 ucontrol
->value
.integer
.value
[0] = val
;
645 mutex_unlock(&ice
->gpio_mutex
);
649 static int wm_pcm_vol_put(struct snd_kcontrol
*kcontrol
,
650 struct snd_ctl_elem_value
*ucontrol
)
652 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
653 unsigned short ovol
, nvol
;
656 nvol
= ucontrol
->value
.integer
.value
[0];
659 snd_ice1712_save_gpio_status(ice
);
660 nvol
= (nvol
? (nvol
+ PCM_MIN
) : 0) & 0xff;
661 ovol
= wm_get(ice
, WM_DAC_DIG_MASTER_ATTEN
) & 0xff;
663 wm_put(ice
, WM_DAC_DIG_MASTER_ATTEN
, nvol
); /* prelatch */
665 wm_put_nocache(ice
, WM_DAC_DIG_MASTER_ATTEN
, nvol
| 0x100);
668 snd_ice1712_restore_gpio_status(ice
);
675 #define phase28_deemp_info snd_ctl_boolean_mono_info
677 static int phase28_deemp_get(struct snd_kcontrol
*kcontrol
,
678 struct snd_ctl_elem_value
*ucontrol
)
680 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
681 ucontrol
->value
.integer
.value
[0] = (wm_get(ice
, WM_DAC_CTRL2
) & 0xf) ==
686 static int phase28_deemp_put(struct snd_kcontrol
*kcontrol
,
687 struct snd_ctl_elem_value
*ucontrol
)
689 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
691 temp
= wm_get(ice
, WM_DAC_CTRL2
);
693 if (ucontrol
->value
.integer
.value
[0])
698 wm_put(ice
, WM_DAC_CTRL2
, temp
);
707 static int phase28_oversampling_info(struct snd_kcontrol
*k
,
708 struct snd_ctl_elem_info
*uinfo
)
710 static const char * const texts
[2] = { "128x", "64x" };
712 return snd_ctl_enum_info(uinfo
, 1, 2, texts
);
715 static int phase28_oversampling_get(struct snd_kcontrol
*kcontrol
,
716 struct snd_ctl_elem_value
*ucontrol
)
718 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
719 ucontrol
->value
.enumerated
.item
[0] = (wm_get(ice
, WM_MASTER
) & 0x8) ==
724 static int phase28_oversampling_put(struct snd_kcontrol
*kcontrol
,
725 struct snd_ctl_elem_value
*ucontrol
)
728 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
730 temp
= wm_get(ice
, WM_MASTER
);
733 if (ucontrol
->value
.enumerated
.item
[0])
739 wm_put(ice
, WM_MASTER
, temp
);
745 static const DECLARE_TLV_DB_SCALE(db_scale_wm_dac
, -12700, 100, 1);
746 static const DECLARE_TLV_DB_SCALE(db_scale_wm_pcm
, -6400, 50, 1);
748 static const struct snd_kcontrol_new phase28_dac_controls
[] = {
750 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
751 .name
= "Master Playback Switch",
752 .info
= wm_master_mute_info
,
753 .get
= wm_master_mute_get
,
754 .put
= wm_master_mute_put
757 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
758 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
759 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
760 .name
= "Master Playback Volume",
761 .info
= wm_master_vol_info
,
762 .get
= wm_master_vol_get
,
763 .put
= wm_master_vol_put
,
764 .tlv
= { .p
= db_scale_wm_dac
}
767 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
768 .name
= "Front Playback Switch",
769 .info
= wm_mute_info
,
772 .private_value
= (2 << 8) | 0
775 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
776 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
777 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
778 .name
= "Front Playback Volume",
782 .private_value
= (2 << 8) | 0,
783 .tlv
= { .p
= db_scale_wm_dac
}
786 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
787 .name
= "Rear Playback Switch",
788 .info
= wm_mute_info
,
791 .private_value
= (2 << 8) | 2
794 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
795 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
796 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
797 .name
= "Rear Playback Volume",
801 .private_value
= (2 << 8) | 2,
802 .tlv
= { .p
= db_scale_wm_dac
}
805 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
806 .name
= "Center Playback Switch",
807 .info
= wm_mute_info
,
810 .private_value
= (1 << 8) | 4
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",
820 .private_value
= (1 << 8) | 4,
821 .tlv
= { .p
= db_scale_wm_dac
}
824 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
825 .name
= "LFE Playback Switch",
826 .info
= wm_mute_info
,
829 .private_value
= (1 << 8) | 5
832 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
833 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
834 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
835 .name
= "LFE Playback Volume",
839 .private_value
= (1 << 8) | 5,
840 .tlv
= { .p
= db_scale_wm_dac
}
843 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
844 .name
= "Side Playback Switch",
845 .info
= wm_mute_info
,
848 .private_value
= (2 << 8) | 6
851 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
852 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
853 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
854 .name
= "Side Playback Volume",
858 .private_value
= (2 << 8) | 6,
859 .tlv
= { .p
= db_scale_wm_dac
}
863 static const struct snd_kcontrol_new wm_controls
[] = {
865 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
866 .name
= "PCM Playback Switch",
867 .info
= wm_pcm_mute_info
,
868 .get
= wm_pcm_mute_get
,
869 .put
= wm_pcm_mute_put
872 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
873 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
874 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
875 .name
= "PCM Playback Volume",
876 .info
= wm_pcm_vol_info
,
877 .get
= wm_pcm_vol_get
,
878 .put
= wm_pcm_vol_put
,
879 .tlv
= { .p
= db_scale_wm_pcm
}
882 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
883 .name
= "DAC Deemphasis Switch",
884 .info
= phase28_deemp_info
,
885 .get
= phase28_deemp_get
,
886 .put
= phase28_deemp_put
889 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
890 .name
= "ADC Oversampling",
891 .info
= phase28_oversampling_info
,
892 .get
= phase28_oversampling_get
,
893 .put
= phase28_oversampling_put
897 static int phase28_add_controls(struct snd_ice1712
*ice
)
899 unsigned int i
, counts
;
902 counts
= ARRAY_SIZE(phase28_dac_controls
);
903 for (i
= 0; i
< counts
; i
++) {
904 err
= snd_ctl_add(ice
->card
,
905 snd_ctl_new1(&phase28_dac_controls
[i
],
911 for (i
= 0; i
< ARRAY_SIZE(wm_controls
); i
++) {
912 err
= snd_ctl_add(ice
->card
,
913 snd_ctl_new1(&wm_controls
[i
], ice
));
921 struct snd_ice1712_card_info snd_vt1724_phase_cards
[] = {
923 .subvendor
= VT1724_SUBDEVICE_PHASE22
,
924 .name
= "Terratec PHASE 22",
926 .chip_init
= phase22_init
,
927 .build_controls
= phase22_add_controls
,
928 .eeprom_size
= sizeof(phase22_eeprom
),
929 .eeprom_data
= phase22_eeprom
,
932 .subvendor
= VT1724_SUBDEVICE_PHASE28
,
933 .name
= "Terratec PHASE 28",
935 .chip_init
= phase28_init
,
936 .build_controls
= phase28_add_controls
,
937 .eeprom_size
= sizeof(phase28_eeprom
),
938 .eeprom_data
= phase28_eeprom
,
941 .subvendor
= VT1724_SUBDEVICE_TS22
,
942 .name
= "Terrasoniq TS22 PCI",
944 .chip_init
= phase22_init
,
945 .build_controls
= phase22_add_controls
,
946 .eeprom_size
= sizeof(phase22_eeprom
),
947 .eeprom_data
= phase22_eeprom
,