1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ALSA driver for ICEnsemble VT1724 (Envy24HT)
5 * Lowlevel functions for Pontis MS300
7 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
10 #include <linux/delay.h>
11 #include <linux/interrupt.h>
12 #include <linux/init.h>
13 #include <linux/slab.h>
14 #include <linux/mutex.h>
16 #include <sound/core.h>
17 #include <sound/info.h>
18 #include <sound/tlv.h>
28 /* WM8776 registers */
29 #define WM_HP_ATTEN_L 0x00 /* headphone left attenuation */
30 #define WM_HP_ATTEN_R 0x01 /* headphone left attenuation */
31 #define WM_HP_MASTER 0x02 /* headphone master (both channels) */
33 #define WM_DAC_ATTEN_L 0x03 /* digital left attenuation */
34 #define WM_DAC_ATTEN_R 0x04
35 #define WM_DAC_MASTER 0x05
36 #define WM_PHASE_SWAP 0x06 /* DAC phase swap */
37 #define WM_DAC_CTRL1 0x07
38 #define WM_DAC_MUTE 0x08
39 #define WM_DAC_CTRL2 0x09
40 #define WM_DAC_INT 0x0a
41 #define WM_ADC_INT 0x0b
42 #define WM_MASTER_CTRL 0x0c
43 #define WM_POWERDOWN 0x0d
44 #define WM_ADC_ATTEN_L 0x0e
45 #define WM_ADC_ATTEN_R 0x0f
46 #define WM_ALC_CTRL1 0x10
47 #define WM_ALC_CTRL2 0x11
48 #define WM_ALC_CTRL3 0x12
49 #define WM_NOISE_GATE 0x13
50 #define WM_LIMITER 0x14
51 #define WM_ADC_MUX 0x15
52 #define WM_OUT_MUX 0x16
58 #define PONTIS_CS_CS (1<<4) /* CS */
59 #define PONTIS_CS_CLK (1<<5) /* CLK */
60 #define PONTIS_CS_RDATA (1<<6) /* CS8416 -> VT1720 */
61 #define PONTIS_CS_WDATA (1<<7) /* VT1720 -> CS8416 */
65 * get the current register value of WM codec
67 static unsigned short wm_get(struct snd_ice1712
*ice
, int reg
)
70 return ((unsigned short)ice
->akm
[0].images
[reg
] << 8) |
71 ice
->akm
[0].images
[reg
+ 1];
75 * set the register value of WM codec and remember it
77 static void wm_put_nocache(struct snd_ice1712
*ice
, int reg
, unsigned short val
)
80 cval
= (reg
<< 9) | val
;
81 snd_vt1724_write_i2c(ice
, WM_DEV
, cval
>> 8, cval
& 0xff);
84 static void wm_put(struct snd_ice1712
*ice
, int reg
, unsigned short val
)
86 wm_put_nocache(ice
, reg
, val
);
88 ice
->akm
[0].images
[reg
] = val
>> 8;
89 ice
->akm
[0].images
[reg
+ 1] = val
;
93 * DAC volume attenuation mixer control (-64dB to 0dB)
98 #define DAC_MIN (DAC_0dB - DAC_RES)
100 static int wm_dac_vol_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
102 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
104 uinfo
->value
.integer
.min
= 0; /* mute */
105 uinfo
->value
.integer
.max
= DAC_RES
; /* 0dB, 0.5dB step */
109 static int wm_dac_vol_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
111 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
115 mutex_lock(&ice
->gpio_mutex
);
116 for (i
= 0; i
< 2; i
++) {
117 val
= wm_get(ice
, WM_DAC_ATTEN_L
+ i
) & 0xff;
118 val
= val
> DAC_MIN
? (val
- DAC_MIN
) : 0;
119 ucontrol
->value
.integer
.value
[i
] = val
;
121 mutex_unlock(&ice
->gpio_mutex
);
125 static int wm_dac_vol_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
127 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
128 unsigned short oval
, nval
;
129 int i
, idx
, change
= 0;
131 mutex_lock(&ice
->gpio_mutex
);
132 for (i
= 0; i
< 2; i
++) {
133 nval
= ucontrol
->value
.integer
.value
[i
];
134 nval
= (nval
? (nval
+ DAC_MIN
) : 0) & 0xff;
135 idx
= WM_DAC_ATTEN_L
+ i
;
136 oval
= wm_get(ice
, idx
) & 0xff;
138 wm_put(ice
, idx
, nval
);
139 wm_put_nocache(ice
, idx
, nval
| 0x100);
143 mutex_unlock(&ice
->gpio_mutex
);
148 * ADC gain mixer control (-64dB to 0dB)
153 #define ADC_MIN (ADC_0dB - ADC_RES)
155 static int wm_adc_vol_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
157 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
159 uinfo
->value
.integer
.min
= 0; /* mute (-64dB) */
160 uinfo
->value
.integer
.max
= ADC_RES
; /* 0dB, 0.5dB step */
164 static int wm_adc_vol_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
166 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
170 mutex_lock(&ice
->gpio_mutex
);
171 for (i
= 0; i
< 2; i
++) {
172 val
= wm_get(ice
, WM_ADC_ATTEN_L
+ i
) & 0xff;
173 val
= val
> ADC_MIN
? (val
- ADC_MIN
) : 0;
174 ucontrol
->value
.integer
.value
[i
] = val
;
176 mutex_unlock(&ice
->gpio_mutex
);
180 static int wm_adc_vol_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
182 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
183 unsigned short ovol
, nvol
;
184 int i
, idx
, change
= 0;
186 mutex_lock(&ice
->gpio_mutex
);
187 for (i
= 0; i
< 2; i
++) {
188 nvol
= ucontrol
->value
.integer
.value
[i
];
189 nvol
= nvol
? (nvol
+ ADC_MIN
) : 0;
190 idx
= WM_ADC_ATTEN_L
+ i
;
191 ovol
= wm_get(ice
, idx
) & 0xff;
193 wm_put(ice
, idx
, nvol
);
197 mutex_unlock(&ice
->gpio_mutex
);
202 * ADC input mux mixer control
204 #define wm_adc_mux_info snd_ctl_boolean_mono_info
206 static int wm_adc_mux_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
208 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
209 int bit
= kcontrol
->private_value
;
211 mutex_lock(&ice
->gpio_mutex
);
212 ucontrol
->value
.integer
.value
[0] = (wm_get(ice
, WM_ADC_MUX
) & (1 << bit
)) ? 1 : 0;
213 mutex_unlock(&ice
->gpio_mutex
);
217 static int wm_adc_mux_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
219 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
220 int bit
= kcontrol
->private_value
;
221 unsigned short oval
, nval
;
224 mutex_lock(&ice
->gpio_mutex
);
225 nval
= oval
= wm_get(ice
, WM_ADC_MUX
);
226 if (ucontrol
->value
.integer
.value
[0])
230 change
= nval
!= oval
;
232 wm_put(ice
, WM_ADC_MUX
, nval
);
234 mutex_unlock(&ice
->gpio_mutex
);
239 * Analog bypass (In -> Out)
241 #define wm_bypass_info snd_ctl_boolean_mono_info
243 static int wm_bypass_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
245 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
247 mutex_lock(&ice
->gpio_mutex
);
248 ucontrol
->value
.integer
.value
[0] = (wm_get(ice
, WM_OUT_MUX
) & 0x04) ? 1 : 0;
249 mutex_unlock(&ice
->gpio_mutex
);
253 static int wm_bypass_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
255 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
256 unsigned short val
, oval
;
259 mutex_lock(&ice
->gpio_mutex
);
260 val
= oval
= wm_get(ice
, WM_OUT_MUX
);
261 if (ucontrol
->value
.integer
.value
[0])
266 wm_put(ice
, WM_OUT_MUX
, val
);
269 mutex_unlock(&ice
->gpio_mutex
);
276 #define wm_chswap_info snd_ctl_boolean_mono_info
278 static int wm_chswap_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
280 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
282 mutex_lock(&ice
->gpio_mutex
);
283 ucontrol
->value
.integer
.value
[0] = (wm_get(ice
, WM_DAC_CTRL1
) & 0xf0) != 0x90;
284 mutex_unlock(&ice
->gpio_mutex
);
288 static int wm_chswap_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
290 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
291 unsigned short val
, oval
;
294 mutex_lock(&ice
->gpio_mutex
);
295 oval
= wm_get(ice
, WM_DAC_CTRL1
);
297 if (ucontrol
->value
.integer
.value
[0])
302 wm_put(ice
, WM_DAC_CTRL1
, val
);
303 wm_put_nocache(ice
, WM_DAC_CTRL1
, val
);
306 mutex_unlock(&ice
->gpio_mutex
);
311 * write data in the SPI mode
313 static void set_gpio_bit(struct snd_ice1712
*ice
, unsigned int bit
, int val
)
315 unsigned int tmp
= snd_ice1712_gpio_read(ice
);
320 snd_ice1712_gpio_write(ice
, tmp
);
323 static void spi_send_byte(struct snd_ice1712
*ice
, unsigned char data
)
326 for (i
= 0; i
< 8; i
++) {
327 set_gpio_bit(ice
, PONTIS_CS_CLK
, 0);
329 set_gpio_bit(ice
, PONTIS_CS_WDATA
, data
& 0x80);
331 set_gpio_bit(ice
, PONTIS_CS_CLK
, 1);
337 static unsigned int spi_read_byte(struct snd_ice1712
*ice
)
340 unsigned int val
= 0;
342 for (i
= 0; i
< 8; i
++) {
344 set_gpio_bit(ice
, PONTIS_CS_CLK
, 0);
346 if (snd_ice1712_gpio_read(ice
) & PONTIS_CS_RDATA
)
349 set_gpio_bit(ice
, PONTIS_CS_CLK
, 1);
356 static void spi_write(struct snd_ice1712
*ice
, unsigned int dev
, unsigned int reg
, unsigned int data
)
358 snd_ice1712_gpio_set_dir(ice
, PONTIS_CS_CS
|PONTIS_CS_WDATA
|PONTIS_CS_CLK
);
359 snd_ice1712_gpio_set_mask(ice
, ~(PONTIS_CS_CS
|PONTIS_CS_WDATA
|PONTIS_CS_CLK
));
360 set_gpio_bit(ice
, PONTIS_CS_CS
, 0);
361 spi_send_byte(ice
, dev
& ~1); /* WRITE */
362 spi_send_byte(ice
, reg
); /* MAP */
363 spi_send_byte(ice
, data
); /* DATA */
365 set_gpio_bit(ice
, PONTIS_CS_CS
, 1);
368 snd_ice1712_gpio_set_mask(ice
, ice
->gpio
.write_mask
);
369 snd_ice1712_gpio_set_dir(ice
, ice
->gpio
.direction
);
372 static unsigned int spi_read(struct snd_ice1712
*ice
, unsigned int dev
, unsigned int reg
)
375 snd_ice1712_gpio_set_dir(ice
, PONTIS_CS_CS
|PONTIS_CS_WDATA
|PONTIS_CS_CLK
);
376 snd_ice1712_gpio_set_mask(ice
, ~(PONTIS_CS_CS
|PONTIS_CS_WDATA
|PONTIS_CS_CLK
));
377 set_gpio_bit(ice
, PONTIS_CS_CS
, 0);
378 spi_send_byte(ice
, dev
& ~1); /* WRITE */
379 spi_send_byte(ice
, reg
); /* MAP */
381 set_gpio_bit(ice
, PONTIS_CS_CS
, 1);
383 set_gpio_bit(ice
, PONTIS_CS_CS
, 0);
384 spi_send_byte(ice
, dev
| 1); /* READ */
385 val
= spi_read_byte(ice
);
387 set_gpio_bit(ice
, PONTIS_CS_CS
, 1);
390 snd_ice1712_gpio_set_mask(ice
, ice
->gpio
.write_mask
);
391 snd_ice1712_gpio_set_dir(ice
, ice
->gpio
.direction
);
399 static int cs_source_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
401 static const char * const texts
[] = {
403 "Optical", /* RXP1 */
406 return snd_ctl_enum_info(uinfo
, 1, 3, texts
);
409 static int cs_source_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
411 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
413 mutex_lock(&ice
->gpio_mutex
);
414 ucontrol
->value
.enumerated
.item
[0] = ice
->gpio
.saved
[0];
415 mutex_unlock(&ice
->gpio_mutex
);
419 static int cs_source_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
421 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
425 mutex_lock(&ice
->gpio_mutex
);
426 if (ucontrol
->value
.enumerated
.item
[0] != ice
->gpio
.saved
[0]) {
427 ice
->gpio
.saved
[0] = ucontrol
->value
.enumerated
.item
[0] & 3;
428 val
= 0x80 | (ice
->gpio
.saved
[0] << 3);
429 spi_write(ice
, CS_DEV
, 0x04, val
);
432 mutex_unlock(&ice
->gpio_mutex
);
440 static int pontis_gpio_mask_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
442 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
444 uinfo
->value
.integer
.min
= 0;
445 uinfo
->value
.integer
.max
= 0xffff; /* 16bit */
449 static int pontis_gpio_mask_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
451 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
452 mutex_lock(&ice
->gpio_mutex
);
454 ucontrol
->value
.integer
.value
[0] = (~ice
->gpio
.write_mask
& 0xffff) | 0x00f0;
455 mutex_unlock(&ice
->gpio_mutex
);
459 static int pontis_gpio_mask_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
461 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
464 mutex_lock(&ice
->gpio_mutex
);
466 val
= (~ucontrol
->value
.integer
.value
[0] & 0xffff) | 0x00f0;
467 changed
= val
!= ice
->gpio
.write_mask
;
468 ice
->gpio
.write_mask
= val
;
469 mutex_unlock(&ice
->gpio_mutex
);
473 static int pontis_gpio_dir_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
475 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
476 mutex_lock(&ice
->gpio_mutex
);
478 ucontrol
->value
.integer
.value
[0] = ice
->gpio
.direction
& 0xff0f;
479 mutex_unlock(&ice
->gpio_mutex
);
483 static int pontis_gpio_dir_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
485 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
488 mutex_lock(&ice
->gpio_mutex
);
490 val
= ucontrol
->value
.integer
.value
[0] & 0xff0f;
491 changed
= (val
!= ice
->gpio
.direction
);
492 ice
->gpio
.direction
= val
;
493 mutex_unlock(&ice
->gpio_mutex
);
497 static int pontis_gpio_data_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
499 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
500 mutex_lock(&ice
->gpio_mutex
);
501 snd_ice1712_gpio_set_dir(ice
, ice
->gpio
.direction
);
502 snd_ice1712_gpio_set_mask(ice
, ice
->gpio
.write_mask
);
503 ucontrol
->value
.integer
.value
[0] = snd_ice1712_gpio_read(ice
) & 0xffff;
504 mutex_unlock(&ice
->gpio_mutex
);
508 static int pontis_gpio_data_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
510 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
511 unsigned int val
, nval
;
513 mutex_lock(&ice
->gpio_mutex
);
514 snd_ice1712_gpio_set_dir(ice
, ice
->gpio
.direction
);
515 snd_ice1712_gpio_set_mask(ice
, ice
->gpio
.write_mask
);
516 val
= snd_ice1712_gpio_read(ice
) & 0xffff;
517 nval
= ucontrol
->value
.integer
.value
[0] & 0xffff;
519 snd_ice1712_gpio_write(ice
, nval
);
522 mutex_unlock(&ice
->gpio_mutex
);
526 static const DECLARE_TLV_DB_SCALE(db_scale_volume
, -6400, 50, 1);
532 static const struct snd_kcontrol_new pontis_controls
[] = {
534 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
535 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
536 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
537 .name
= "PCM Playback Volume",
538 .info
= wm_dac_vol_info
,
539 .get
= wm_dac_vol_get
,
540 .put
= wm_dac_vol_put
,
541 .tlv
= { .p
= db_scale_volume
},
544 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
545 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
546 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
547 .name
= "Capture Volume",
548 .info
= wm_adc_vol_info
,
549 .get
= wm_adc_vol_get
,
550 .put
= wm_adc_vol_put
,
551 .tlv
= { .p
= db_scale_volume
},
554 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
555 .name
= "CD Capture Switch",
556 .info
= wm_adc_mux_info
,
557 .get
= wm_adc_mux_get
,
558 .put
= wm_adc_mux_put
,
562 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
563 .name
= "Line Capture Switch",
564 .info
= wm_adc_mux_info
,
565 .get
= wm_adc_mux_get
,
566 .put
= wm_adc_mux_put
,
570 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
571 .name
= "Analog Bypass Switch",
572 .info
= wm_bypass_info
,
573 .get
= wm_bypass_get
,
574 .put
= wm_bypass_put
,
577 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
578 .name
= "Swap Output Channels",
579 .info
= wm_chswap_info
,
580 .get
= wm_chswap_get
,
581 .put
= wm_chswap_put
,
584 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
585 .name
= "IEC958 Input Source",
586 .info
= cs_source_info
,
587 .get
= cs_source_get
,
588 .put
= cs_source_put
,
590 /* FIXME: which interface? */
592 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
594 .info
= pontis_gpio_mask_info
,
595 .get
= pontis_gpio_mask_get
,
596 .put
= pontis_gpio_mask_put
,
599 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
600 .name
= "GPIO Direction",
601 .info
= pontis_gpio_mask_info
,
602 .get
= pontis_gpio_dir_get
,
603 .put
= pontis_gpio_dir_put
,
606 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
608 .info
= pontis_gpio_mask_info
,
609 .get
= pontis_gpio_data_get
,
610 .put
= pontis_gpio_data_put
,
618 static void wm_proc_regs_write(struct snd_info_entry
*entry
, struct snd_info_buffer
*buffer
)
620 struct snd_ice1712
*ice
= entry
->private_data
;
622 unsigned int reg
, val
;
623 mutex_lock(&ice
->gpio_mutex
);
624 while (!snd_info_get_line(buffer
, line
, sizeof(line
))) {
625 if (sscanf(line
, "%x %x", ®
, &val
) != 2)
627 if (reg
<= 0x17 && val
<= 0xffff)
628 wm_put(ice
, reg
, val
);
630 mutex_unlock(&ice
->gpio_mutex
);
633 static void wm_proc_regs_read(struct snd_info_entry
*entry
, struct snd_info_buffer
*buffer
)
635 struct snd_ice1712
*ice
= entry
->private_data
;
638 mutex_lock(&ice
->gpio_mutex
);
639 for (reg
= 0; reg
<= 0x17; reg
++) {
640 val
= wm_get(ice
, reg
);
641 snd_iprintf(buffer
, "%02x = %04x\n", reg
, val
);
643 mutex_unlock(&ice
->gpio_mutex
);
646 static void wm_proc_init(struct snd_ice1712
*ice
)
648 snd_card_rw_proc_new(ice
->card
, "wm_codec", ice
, wm_proc_regs_read
,
652 static void cs_proc_regs_read(struct snd_info_entry
*entry
, struct snd_info_buffer
*buffer
)
654 struct snd_ice1712
*ice
= entry
->private_data
;
657 mutex_lock(&ice
->gpio_mutex
);
658 for (reg
= 0; reg
<= 0x26; reg
++) {
659 val
= spi_read(ice
, CS_DEV
, reg
);
660 snd_iprintf(buffer
, "%02x = %02x\n", reg
, val
);
662 val
= spi_read(ice
, CS_DEV
, 0x7f);
663 snd_iprintf(buffer
, "%02x = %02x\n", 0x7f, val
);
664 mutex_unlock(&ice
->gpio_mutex
);
667 static void cs_proc_init(struct snd_ice1712
*ice
)
669 snd_card_ro_proc_new(ice
->card
, "cs_codec", ice
, cs_proc_regs_read
);
673 static int pontis_add_controls(struct snd_ice1712
*ice
)
678 for (i
= 0; i
< ARRAY_SIZE(pontis_controls
); i
++) {
679 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&pontis_controls
[i
], ice
));
692 * initialize the chip
694 static int pontis_init(struct snd_ice1712
*ice
)
696 static const unsigned short wm_inits
[] = {
697 /* These come first to reduce init pop noise */
698 WM_ADC_MUX
, 0x00c0, /* ADC mute */
699 WM_DAC_MUTE
, 0x0001, /* DAC softmute */
700 WM_DAC_CTRL1
, 0x0000, /* DAC mute */
702 WM_POWERDOWN
, 0x0008, /* All power-up except HP */
703 WM_RESET
, 0x0000, /* reset */
705 static const unsigned short wm_inits2
[] = {
706 WM_MASTER_CTRL
, 0x0022, /* 256fs, slave mode */
707 WM_DAC_INT
, 0x0022, /* I2S, normal polarity, 24bit */
708 WM_ADC_INT
, 0x0022, /* I2S, normal polarity, 24bit */
709 WM_DAC_CTRL1
, 0x0090, /* DAC L/R */
710 WM_OUT_MUX
, 0x0001, /* OUT DAC */
711 WM_HP_ATTEN_L
, 0x0179, /* HP 0dB */
712 WM_HP_ATTEN_R
, 0x0179, /* HP 0dB */
713 WM_DAC_ATTEN_L
, 0x0000, /* DAC 0dB */
714 WM_DAC_ATTEN_L
, 0x0100, /* DAC 0dB */
715 WM_DAC_ATTEN_R
, 0x0000, /* DAC 0dB */
716 WM_DAC_ATTEN_R
, 0x0100, /* DAC 0dB */
717 /* WM_DAC_MASTER, 0x0100, */ /* DAC master muted */
718 WM_PHASE_SWAP
, 0x0000, /* phase normal */
719 WM_DAC_CTRL2
, 0x0000, /* no deemphasis, no ZFLG */
720 WM_ADC_ATTEN_L
, 0x0000, /* ADC muted */
721 WM_ADC_ATTEN_R
, 0x0000, /* ADC muted */
723 WM_ALC_CTRL1
, 0x007b, /* */
724 WM_ALC_CTRL2
, 0x0000, /* */
725 WM_ALC_CTRL3
, 0x0000, /* */
726 WM_NOISE_GATE
, 0x0000, /* */
728 WM_DAC_MUTE
, 0x0000, /* DAC unmute */
729 WM_ADC_MUX
, 0x0003, /* ADC unmute, both CD/Line On */
731 static const unsigned char cs_inits
[] = {
732 0x04, 0x80, /* RUN, RXP0 */
733 0x05, 0x05, /* slave, 24bit */
741 ice
->num_total_dacs
= 2;
742 ice
->num_total_adcs
= 2;
744 /* to remember the register values */
745 ice
->akm
= kzalloc(sizeof(struct snd_akm4xxx
), GFP_KERNEL
);
750 /* HACK - use this as the SPDIF source.
751 * don't call snd_ice1712_gpio_get/put(), otherwise it's overwritten
753 ice
->gpio
.saved
[0] = 0;
755 /* initialize WM8776 codec */
756 for (i
= 0; i
< ARRAY_SIZE(wm_inits
); i
+= 2)
757 wm_put(ice
, wm_inits
[i
], wm_inits
[i
+1]);
758 schedule_timeout_uninterruptible(1);
759 for (i
= 0; i
< ARRAY_SIZE(wm_inits2
); i
+= 2)
760 wm_put(ice
, wm_inits2
[i
], wm_inits2
[i
+1]);
762 /* initialize CS8416 codec */
763 /* assert PRST#; MT05 bit 7 */
764 outb(inb(ICEMT1724(ice
, AC97_CMD
)) | 0x80, ICEMT1724(ice
, AC97_CMD
));
767 outb(inb(ICEMT1724(ice
, AC97_CMD
)) & ~0x80, ICEMT1724(ice
, AC97_CMD
));
769 for (i
= 0; i
< ARRAY_SIZE(cs_inits
); i
+= 2)
770 spi_write(ice
, CS_DEV
, cs_inits
[i
], cs_inits
[i
+1]);
777 * Pontis boards don't provide the EEPROM data at all.
778 * hence the driver needs to sets up it properly.
781 static const unsigned char pontis_eeprom
[] = {
782 [ICE_EEP2_SYSCONF
] = 0x08, /* clock 256, mpu401, spdif-in/ADC, 1DAC */
783 [ICE_EEP2_ACLINK
] = 0x80, /* I2S */
784 [ICE_EEP2_I2S
] = 0xf8, /* vol, 96k, 24bit, 192k */
785 [ICE_EEP2_SPDIF
] = 0xc3, /* out-en, out-int, spdif-in */
786 [ICE_EEP2_GPIO_DIR
] = 0x07,
787 [ICE_EEP2_GPIO_DIR1
] = 0x00,
788 [ICE_EEP2_GPIO_DIR2
] = 0x00, /* ignored */
789 [ICE_EEP2_GPIO_MASK
] = 0x0f, /* 4-7 reserved for CS8416 */
790 [ICE_EEP2_GPIO_MASK1
] = 0xff,
791 [ICE_EEP2_GPIO_MASK2
] = 0x00, /* ignored */
792 [ICE_EEP2_GPIO_STATE
] = 0x06, /* 0-low, 1-high, 2-high */
793 [ICE_EEP2_GPIO_STATE1
] = 0x00,
794 [ICE_EEP2_GPIO_STATE2
] = 0x00, /* ignored */
798 struct snd_ice1712_card_info snd_vt1720_pontis_cards
[] = {
800 .subvendor
= VT1720_SUBDEVICE_PONTIS_MS300
,
801 .name
= "Pontis MS300",
803 .chip_init
= pontis_init
,
804 .build_controls
= pontis_add_controls
,
805 .eeprom_size
= sizeof(pontis_eeprom
),
806 .eeprom_data
= pontis_eeprom
,