2 * ALSA driver for ICEnsemble VT1724 (Envy24HT)
4 * Lowlevel functions for Infrasonic Quartet
6 * Copyright (c) 2009 Pavel Hofman <pavel.hofman@ivitera.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/delay.h>
26 #include <linux/interrupt.h>
27 #include <linux/init.h>
28 #include <linux/slab.h>
29 #include <sound/core.h>
30 #include <sound/tlv.h>
31 #include <sound/info.h>
35 #include <sound/ak4113.h>
39 struct ak4113
*ak4113
;
40 unsigned int scr
; /* system control register */
41 unsigned int mcr
; /* monitoring control register */
42 unsigned int cpld
; /* cpld register */
45 struct qtet_kcontrol_private
{
47 void (*set_register
)(struct snd_ice1712
*ice
, unsigned int val
);
48 unsigned int (*get_register
)(struct snd_ice1712
*ice
);
49 unsigned char * const texts
[2];
65 static const char * const ext_clock_names
[3] = {"IEC958 In", "Word Clock 1xFS",
68 /* chip address on I2C bus */
69 #define AK4113_ADDR 0x26 /* S/PDIF receiver */
71 /* chip address on SPI bus */
72 #define AK4620_ADDR 0x02 /* ADC/DAC */
79 /* GPIO0 - O - DATA0, def. 0 */
80 #define GPIO_D0 (1<<0)
81 /* GPIO1 - I/O - DATA1, Jack Detect Input0 (0:present, 1:missing), def. 1 */
82 #define GPIO_D1_JACKDTC0 (1<<1)
83 /* GPIO2 - I/O - DATA2, Jack Detect Input1 (0:present, 1:missing), def. 1 */
84 #define GPIO_D2_JACKDTC1 (1<<2)
85 /* GPIO3 - I/O - DATA3, def. 1 */
86 #define GPIO_D3 (1<<3)
87 /* GPIO4 - I/O - DATA4, SPI CDTO, def. 1 */
88 #define GPIO_D4_SPI_CDTO (1<<4)
89 /* GPIO5 - I/O - DATA5, SPI CCLK, def. 1 */
90 #define GPIO_D5_SPI_CCLK (1<<5)
91 /* GPIO6 - I/O - DATA6, Cable Detect Input (0:detected, 1:not detected */
92 #define GPIO_D6_CD (1<<6)
93 /* GPIO7 - I/O - DATA7, Device Detect Input (0:detected, 1:not detected */
94 #define GPIO_D7_DD (1<<7)
95 /* GPIO8 - O - CPLD Chip Select, def. 1 */
96 #define GPIO_CPLD_CSN (1<<8)
97 /* GPIO9 - O - CPLD register read/write (0:write, 1:read), def. 0 */
98 #define GPIO_CPLD_RW (1<<9)
99 /* GPIO10 - O - SPI Chip Select for CODEC#0, def. 1 */
100 #define GPIO_SPI_CSN0 (1<<10)
101 /* GPIO11 - O - SPI Chip Select for CODEC#1, def. 1 */
102 #define GPIO_SPI_CSN1 (1<<11)
103 /* GPIO12 - O - Ex. Register Output Enable (0:enable, 1:disable), def. 1,
105 #define GPIO_EX_GPIOE (1<<12)
106 /* GPIO13 - O - Ex. Register0 Chip Select for System Control Register,
108 #define GPIO_SCR (1<<13)
109 /* GPIO14 - O - Ex. Register1 Chip Select for Monitor Control Register,
111 #define GPIO_MCR (1<<14)
113 #define GPIO_SPI_ALL (GPIO_D4_SPI_CDTO | GPIO_D5_SPI_CCLK |\
114 GPIO_SPI_CSN0 | GPIO_SPI_CSN1)
116 #define GPIO_DATA_MASK (GPIO_D0 | GPIO_D1_JACKDTC0 | \
117 GPIO_D2_JACKDTC1 | GPIO_D3 | \
118 GPIO_D4_SPI_CDTO | GPIO_D5_SPI_CCLK | \
119 GPIO_D6_CD | GPIO_D7_DD)
121 /* System Control Register GPIO_SCR data bits */
122 /* Mic/Line select relay (0:line, 1:mic) */
123 #define SCR_RELAY GPIO_D0
124 /* Phantom power drive control (0:5V, 1:48V) */
125 #define SCR_PHP_V GPIO_D1_JACKDTC0
126 /* H/W mute control (0:Normal, 1:Mute) */
127 #define SCR_MUTE GPIO_D2_JACKDTC1
128 /* Phantom power control (0:Phantom on, 1:off) */
129 #define SCR_PHP GPIO_D3
130 /* Analog input 1/2 Source Select */
131 #define SCR_AIN12_SEL0 GPIO_D4_SPI_CDTO
132 #define SCR_AIN12_SEL1 GPIO_D5_SPI_CCLK
133 /* Analog input 3/4 Source Select (0:line, 1:hi-z) */
134 #define SCR_AIN34_SEL GPIO_D6_CD
135 /* Codec Power Down (0:power down, 1:normal) */
136 #define SCR_CODEC_PDN GPIO_D7_DD
138 #define SCR_AIN12_LINE (0)
139 #define SCR_AIN12_MIC (SCR_AIN12_SEL0)
140 #define SCR_AIN12_LOWCUT (SCR_AIN12_SEL1 | SCR_AIN12_SEL0)
142 /* Monitor Control Register GPIO_MCR data bits */
143 /* Input 1/2 to Monitor 1/2 (0:off, 1:on) */
144 #define MCR_IN12_MON12 GPIO_D0
145 /* Input 1/2 to Monitor 3/4 (0:off, 1:on) */
146 #define MCR_IN12_MON34 GPIO_D1_JACKDTC0
147 /* Input 3/4 to Monitor 1/2 (0:off, 1:on) */
148 #define MCR_IN34_MON12 GPIO_D2_JACKDTC1
149 /* Input 3/4 to Monitor 3/4 (0:off, 1:on) */
150 #define MCR_IN34_MON34 GPIO_D3
151 /* Output to Monitor 1/2 (0:off, 1:on) */
152 #define MCR_OUT34_MON12 GPIO_D4_SPI_CDTO
153 /* Output to Monitor 3/4 (0:off, 1:on) */
154 #define MCR_OUT12_MON34 GPIO_D5_SPI_CCLK
156 /* CPLD Register DATA bits */
157 /* Clock Rate Select */
158 #define CPLD_CKS0 GPIO_D0
159 #define CPLD_CKS1 GPIO_D1_JACKDTC0
160 #define CPLD_CKS2 GPIO_D2_JACKDTC1
161 /* Sync Source Select (0:Internal, 1:External) */
162 #define CPLD_SYNC_SEL GPIO_D3
163 /* Word Clock FS Select (0:FS, 1:256FS) */
164 #define CPLD_WORD_SEL GPIO_D4_SPI_CDTO
165 /* Coaxial Output Source (IS-Link) (0:SPDIF, 1:I2S) */
166 #define CPLD_COAX_OUT GPIO_D5_SPI_CCLK
167 /* Input 1/2 Source Select (0:Analog12, 1:An34) */
168 #define CPLD_IN12_SEL GPIO_D6_CD
169 /* Input 3/4 Source Select (0:Analog34, 1:Digital In) */
170 #define CPLD_IN34_SEL GPIO_D7_DD
172 /* internal clock (CPLD_SYNC_SEL = 0) options */
173 #define CPLD_CKS_44100HZ (0)
174 #define CPLD_CKS_48000HZ (CPLD_CKS0)
175 #define CPLD_CKS_88200HZ (CPLD_CKS1)
176 #define CPLD_CKS_96000HZ (CPLD_CKS1 | CPLD_CKS0)
177 #define CPLD_CKS_176400HZ (CPLD_CKS2)
178 #define CPLD_CKS_192000HZ (CPLD_CKS2 | CPLD_CKS0)
180 #define CPLD_CKS_MASK (CPLD_CKS0 | CPLD_CKS1 | CPLD_CKS2)
182 /* external clock (CPLD_SYNC_SEL = 1) options */
183 /* external clock - SPDIF */
184 #define CPLD_EXT_SPDIF (0 | CPLD_SYNC_SEL)
185 /* external clock - WordClock 1xfs */
186 #define CPLD_EXT_WORDCLOCK_1FS (CPLD_CKS1 | CPLD_SYNC_SEL)
187 /* external clock - WordClock 256xfs */
188 #define CPLD_EXT_WORDCLOCK_256FS (CPLD_CKS1 | CPLD_WORD_SEL |\
191 #define EXT_SPDIF_TYPE 0
192 #define EXT_WORDCLOCK_1FS_TYPE 1
193 #define EXT_WORDCLOCK_256FS_TYPE 2
195 #define AK4620_DFS0 (1<<0)
196 #define AK4620_DFS1 (1<<1)
197 #define AK4620_CKS0 (1<<2)
198 #define AK4620_CKS1 (1<<3)
199 /* Clock and Format Control register */
200 #define AK4620_DFS_REG 0x02
202 /* Deem and Volume Control register */
203 #define AK4620_DEEMVOL_REG 0x03
204 #define AK4620_SMUTE (1<<7)
206 #ifdef CONFIG_PROC_FS
208 * Conversion from int value to its binary form. Used for debugging.
209 * The output buffer must be allocated prior to calling the function.
211 static char *get_binary(char *buffer
, int value
)
215 for (i
= 0; i
< 4; ++i
) {
216 for (j
= 0; j
< 8; ++j
) {
217 if (value
& (1 << (31-(i
*8 + j
))))
231 #endif /* CONFIG_PROC_FS */
234 * Initial setup of the conversion array GPIO <-> rate
236 static unsigned int qtet_rates
[] = {
238 96000, 176400, 192000,
241 static unsigned int cks_vals
[] = {
242 CPLD_CKS_44100HZ
, CPLD_CKS_48000HZ
, CPLD_CKS_88200HZ
,
243 CPLD_CKS_96000HZ
, CPLD_CKS_176400HZ
, CPLD_CKS_192000HZ
,
246 static struct snd_pcm_hw_constraint_list qtet_rates_info
= {
247 .count
= ARRAY_SIZE(qtet_rates
),
252 static void qtet_ak4113_write(void *private_data
, unsigned char reg
,
255 snd_vt1724_write_i2c((struct snd_ice1712
*)private_data
, AK4113_ADDR
,
259 static unsigned char qtet_ak4113_read(void *private_data
, unsigned char reg
)
261 return snd_vt1724_read_i2c((struct snd_ice1712
*)private_data
,
271 * Write data to addr register of ak4620
273 static void qtet_akm_write(struct snd_akm4xxx
*ak
, int chip
,
274 unsigned char addr
, unsigned char data
)
276 unsigned int tmp
, orig_dir
;
278 unsigned int addrdata
;
279 struct snd_ice1712
*ice
= ak
->private_data
[0];
281 if (snd_BUG_ON(chip
< 0 || chip
>= 4))
283 /*dev_dbg(ice->card->dev, "Writing to AK4620: chip=%d, addr=0x%x,
284 data=0x%x\n", chip, addr, data);*/
285 orig_dir
= ice
->gpio
.get_dir(ice
);
286 ice
->gpio
.set_dir(ice
, orig_dir
| GPIO_SPI_ALL
);
287 /* set mask - only SPI bits */
288 ice
->gpio
.set_mask(ice
, ~GPIO_SPI_ALL
);
290 tmp
= ice
->gpio
.get_data(ice
);
293 ice
->gpio
.set_data(ice
, tmp
);
295 /* drop chip select */
298 tmp
&= ~GPIO_SPI_CSN1
;
300 tmp
&= ~GPIO_SPI_CSN0
;
301 ice
->gpio
.set_data(ice
, tmp
);
304 /* build I2C address + data byte */
305 addrdata
= (AK4620_ADDR
<< 6) | 0x20 | (addr
& 0x1f);
306 addrdata
= (addrdata
<< 8) | data
;
307 for (idx
= 15; idx
>= 0; idx
--) {
309 tmp
&= ~GPIO_D5_SPI_CCLK
;
310 ice
->gpio
.set_data(ice
, tmp
);
313 if (addrdata
& (1 << idx
))
314 tmp
|= GPIO_D4_SPI_CDTO
;
316 tmp
&= ~GPIO_D4_SPI_CDTO
;
317 ice
->gpio
.set_data(ice
, tmp
);
320 tmp
|= GPIO_D5_SPI_CCLK
;
321 ice
->gpio
.set_data(ice
, tmp
);
326 ice
->gpio
.set_data(ice
, tmp
);
329 /* return all gpios to non-writable */
330 ice
->gpio
.set_mask(ice
, 0xffffff);
331 /* restore GPIOs direction */
332 ice
->gpio
.set_dir(ice
, orig_dir
);
335 static void qtet_akm_set_regs(struct snd_akm4xxx
*ak
, unsigned char addr
,
336 unsigned char mask
, unsigned char value
)
340 for (chip
= 0; chip
< ak
->num_chips
; chip
++) {
341 tmp
= snd_akm4xxx_get(ak
, chip
, addr
);
344 /* set the new bits */
346 snd_akm4xxx_write(ak
, chip
, addr
, tmp
);
351 * change the rate of AK4620
353 static void qtet_akm_set_rate_val(struct snd_akm4xxx
*ak
, unsigned int rate
)
355 unsigned char ak4620_dfs
;
357 if (rate
== 0) /* no hint - S/PDIF input is master or the new spdif
358 input rate undetected, simply return */
361 /* adjust DFS on codecs - see datasheet */
363 ak4620_dfs
= AK4620_DFS1
| AK4620_CKS1
;
364 else if (rate
> 54000)
365 ak4620_dfs
= AK4620_DFS0
| AK4620_CKS0
;
370 qtet_akm_set_regs(ak
, AK4620_DFS_REG
, AK4620_DFS0
| AK4620_DFS1
|
371 AK4620_CKS0
| AK4620_CKS1
, ak4620_dfs
);
374 #define AK_CONTROL(xname, xch) { .name = xname, .num_channels = xch }
376 #define PCM_12_PLAYBACK_VOLUME "PCM 1/2 Playback Volume"
377 #define PCM_34_PLAYBACK_VOLUME "PCM 3/4 Playback Volume"
378 #define PCM_12_CAPTURE_VOLUME "PCM 1/2 Capture Volume"
379 #define PCM_34_CAPTURE_VOLUME "PCM 3/4 Capture Volume"
381 static const struct snd_akm4xxx_dac_channel qtet_dac
[] = {
382 AK_CONTROL(PCM_12_PLAYBACK_VOLUME
, 2),
383 AK_CONTROL(PCM_34_PLAYBACK_VOLUME
, 2),
386 static const struct snd_akm4xxx_adc_channel qtet_adc
[] = {
387 AK_CONTROL(PCM_12_CAPTURE_VOLUME
, 2),
388 AK_CONTROL(PCM_34_CAPTURE_VOLUME
, 2),
391 static struct snd_akm4xxx akm_qtet_dac
= {
393 .num_dacs
= 4, /* DAC1 - Output 12
395 .num_adcs
= 4, /* ADC1 - Input 12
398 .write
= qtet_akm_write
,
399 .set_rate_val
= qtet_akm_set_rate_val
,
401 .dac_info
= qtet_dac
,
402 .adc_info
= qtet_adc
,
405 /* Communication routines with the CPLD */
408 /* Writes data to external register reg, both reg and data are
409 * GPIO representations */
410 static void reg_write(struct snd_ice1712
*ice
, unsigned int reg
,
415 mutex_lock(&ice
->gpio_mutex
);
416 /* set direction of used GPIOs*/
419 ice
->gpio
.set_dir(ice
, tmp
);
420 /* mask - writable bits */
421 ice
->gpio
.set_mask(ice
, ~(tmp
));
423 tmp
= ice
->gpio
.get_data(ice
);
424 tmp
&= ~GPIO_DATA_MASK
;
426 ice
->gpio
.set_data(ice
, tmp
);
428 /* drop output enable */
429 tmp
&= ~GPIO_EX_GPIOE
;
430 ice
->gpio
.set_data(ice
, tmp
);
432 /* drop the register gpio */
434 ice
->gpio
.set_data(ice
, tmp
);
436 /* raise the register GPIO */
438 ice
->gpio
.set_data(ice
, tmp
);
441 /* raise all data gpios */
442 tmp
|= GPIO_DATA_MASK
;
443 ice
->gpio
.set_data(ice
, tmp
);
444 /* mask - immutable bits */
445 ice
->gpio
.set_mask(ice
, 0xffffff);
446 /* outputs only 8-15 */
447 ice
->gpio
.set_dir(ice
, 0x00ff00);
448 mutex_unlock(&ice
->gpio_mutex
);
451 static unsigned int get_scr(struct snd_ice1712
*ice
)
453 struct qtet_spec
*spec
= ice
->spec
;
457 static unsigned int get_mcr(struct snd_ice1712
*ice
)
459 struct qtet_spec
*spec
= ice
->spec
;
463 static unsigned int get_cpld(struct snd_ice1712
*ice
)
465 struct qtet_spec
*spec
= ice
->spec
;
469 static void set_scr(struct snd_ice1712
*ice
, unsigned int val
)
471 struct qtet_spec
*spec
= ice
->spec
;
472 reg_write(ice
, GPIO_SCR
, val
);
476 static void set_mcr(struct snd_ice1712
*ice
, unsigned int val
)
478 struct qtet_spec
*spec
= ice
->spec
;
479 reg_write(ice
, GPIO_MCR
, val
);
483 static void set_cpld(struct snd_ice1712
*ice
, unsigned int val
)
485 struct qtet_spec
*spec
= ice
->spec
;
486 reg_write(ice
, GPIO_CPLD_CSN
, val
);
489 #ifdef CONFIG_PROC_FS
490 static void proc_regs_read(struct snd_info_entry
*entry
,
491 struct snd_info_buffer
*buffer
)
493 struct snd_ice1712
*ice
= entry
->private_data
;
496 snd_iprintf(buffer
, "SCR: %s\n", get_binary(bin_buffer
,
498 snd_iprintf(buffer
, "MCR: %s\n", get_binary(bin_buffer
,
500 snd_iprintf(buffer
, "CPLD: %s\n", get_binary(bin_buffer
,
504 static void proc_init(struct snd_ice1712
*ice
)
506 struct snd_info_entry
*entry
;
507 if (!snd_card_proc_new(ice
->card
, "quartet", &entry
))
508 snd_info_set_text_ops(entry
, ice
, proc_regs_read
);
510 #else /* !CONFIG_PROC_FS */
511 static void proc_init(struct snd_ice1712
*ice
) {}
514 static int qtet_mute_get(struct snd_kcontrol
*kcontrol
,
515 struct snd_ctl_elem_value
*ucontrol
)
517 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
519 val
= get_scr(ice
) & SCR_MUTE
;
520 ucontrol
->value
.integer
.value
[0] = (val
) ? 0 : 1;
524 static int qtet_mute_put(struct snd_kcontrol
*kcontrol
,
525 struct snd_ctl_elem_value
*ucontrol
)
527 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
528 unsigned int old
, new, smute
;
529 old
= get_scr(ice
) & SCR_MUTE
;
530 if (ucontrol
->value
.integer
.value
[0]) {
539 smute
= AK4620_SMUTE
;
542 struct snd_akm4xxx
*ak
= ice
->akm
;
543 set_scr(ice
, (get_scr(ice
) & ~SCR_MUTE
) | new);
545 qtet_akm_set_regs(ak
, AK4620_DEEMVOL_REG
, AK4620_SMUTE
, smute
);
552 static int qtet_ain12_enum_info(struct snd_kcontrol
*kcontrol
,
553 struct snd_ctl_elem_info
*uinfo
)
555 static const char * const texts
[3] =
556 {"Line In 1/2", "Mic", "Mic + Low-cut"};
557 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
559 uinfo
->value
.enumerated
.items
= ARRAY_SIZE(texts
);
561 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
562 uinfo
->value
.enumerated
.item
=
563 uinfo
->value
.enumerated
.items
- 1;
564 strcpy(uinfo
->value
.enumerated
.name
,
565 texts
[uinfo
->value
.enumerated
.item
]);
570 static int qtet_ain12_sw_get(struct snd_kcontrol
*kcontrol
,
571 struct snd_ctl_elem_value
*ucontrol
)
573 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
574 unsigned int val
, result
;
575 val
= get_scr(ice
) & (SCR_AIN12_SEL1
| SCR_AIN12_SEL0
);
583 case SCR_AIN12_LOWCUT
:
587 /* BUG - no other combinations allowed */
591 ucontrol
->value
.integer
.value
[0] = result
;
595 static int qtet_ain12_sw_put(struct snd_kcontrol
*kcontrol
,
596 struct snd_ctl_elem_value
*ucontrol
)
598 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
599 unsigned int old
, new, tmp
, masked_old
;
600 old
= new = get_scr(ice
);
601 masked_old
= old
& (SCR_AIN12_SEL1
| SCR_AIN12_SEL0
);
602 tmp
= ucontrol
->value
.integer
.value
[0];
604 tmp
= 3; /* binary 10 is not supported */
605 tmp
<<= 4; /* shifting to SCR_AIN12_SEL0 */
606 if (tmp
!= masked_old
) {
607 /* change requested */
610 new = old
& ~(SCR_AIN12_SEL1
| SCR_AIN12_SEL0
);
618 new = old
| SCR_RELAY
;
620 new = (new & ~SCR_AIN12_SEL1
) | SCR_AIN12_SEL0
;
623 case SCR_AIN12_LOWCUT
:
625 new = old
| SCR_RELAY
;
627 new |= SCR_AIN12_SEL1
| SCR_AIN12_SEL0
;
639 static int qtet_php_get(struct snd_kcontrol
*kcontrol
,
640 struct snd_ctl_elem_value
*ucontrol
)
642 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
644 /* if phantom voltage =48V, phantom on */
645 val
= get_scr(ice
) & SCR_PHP_V
;
646 ucontrol
->value
.integer
.value
[0] = val
? 1 : 0;
650 static int qtet_php_put(struct snd_kcontrol
*kcontrol
,
651 struct snd_ctl_elem_value
*ucontrol
)
653 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
654 unsigned int old
, new;
655 old
= new = get_scr(ice
);
656 if (ucontrol
->value
.integer
.value
[0] /* phantom on requested */
657 && (~old
& SCR_PHP_V
)) /* 0 = voltage 5V */ {
658 /* is off, turn on */
659 /* turn voltage on first, = 1 */
660 new = old
| SCR_PHP_V
;
662 /* turn phantom on, = 0 */
665 } else if (!ucontrol
->value
.integer
.value
[0] && (old
& SCR_PHP_V
)) {
666 /* phantom off requested and 1 = voltage 48V */
667 /* is on, turn off */
668 /* turn voltage off first, = 0 */
669 new = old
& ~SCR_PHP_V
;
671 /* turn phantom off, = 1 */
681 #define PRIV_SW(xid, xbit, xreg) [xid] = {.bit = xbit,\
682 .set_register = set_##xreg,\
683 .get_register = get_##xreg, }
686 #define PRIV_ENUM2(xid, xbit, xreg, xtext1, xtext2) [xid] = {.bit = xbit,\
687 .set_register = set_##xreg,\
688 .get_register = get_##xreg,\
689 .texts = {xtext1, xtext2} }
691 static struct qtet_kcontrol_private qtet_privates
[] = {
692 PRIV_ENUM2(IN12_SEL
, CPLD_IN12_SEL
, cpld
, "An In 1/2", "An In 3/4"),
693 PRIV_ENUM2(IN34_SEL
, CPLD_IN34_SEL
, cpld
, "An In 3/4", "IEC958 In"),
694 PRIV_ENUM2(AIN34_SEL
, SCR_AIN34_SEL
, scr
, "Line In 3/4", "Hi-Z"),
695 PRIV_ENUM2(COAX_OUT
, CPLD_COAX_OUT
, cpld
, "IEC958", "I2S"),
696 PRIV_SW(IN12_MON12
, MCR_IN12_MON12
, mcr
),
697 PRIV_SW(IN12_MON34
, MCR_IN12_MON34
, mcr
),
698 PRIV_SW(IN34_MON12
, MCR_IN34_MON12
, mcr
),
699 PRIV_SW(IN34_MON34
, MCR_IN34_MON34
, mcr
),
700 PRIV_SW(OUT12_MON34
, MCR_OUT12_MON34
, mcr
),
701 PRIV_SW(OUT34_MON12
, MCR_OUT34_MON12
, mcr
),
704 static int qtet_enum_info(struct snd_kcontrol
*kcontrol
,
705 struct snd_ctl_elem_info
*uinfo
)
707 struct qtet_kcontrol_private
private =
708 qtet_privates
[kcontrol
->private_value
];
709 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
711 uinfo
->value
.enumerated
.items
= ARRAY_SIZE(private.texts
);
713 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
714 uinfo
->value
.enumerated
.item
=
715 uinfo
->value
.enumerated
.items
- 1;
716 strcpy(uinfo
->value
.enumerated
.name
,
717 private.texts
[uinfo
->value
.enumerated
.item
]);
722 static int qtet_sw_get(struct snd_kcontrol
*kcontrol
,
723 struct snd_ctl_elem_value
*ucontrol
)
725 struct qtet_kcontrol_private
private =
726 qtet_privates
[kcontrol
->private_value
];
727 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
728 ucontrol
->value
.integer
.value
[0] =
729 (private.get_register(ice
) & private.bit
) ? 1 : 0;
733 static int qtet_sw_put(struct snd_kcontrol
*kcontrol
,
734 struct snd_ctl_elem_value
*ucontrol
)
736 struct qtet_kcontrol_private
private =
737 qtet_privates
[kcontrol
->private_value
];
738 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
739 unsigned int old
, new;
740 old
= private.get_register(ice
);
741 if (ucontrol
->value
.integer
.value
[0])
742 new = old
| private.bit
;
744 new = old
& ~private.bit
;
746 private.set_register(ice
, new);
753 #define qtet_sw_info snd_ctl_boolean_mono_info
755 #define QTET_CONTROL(xname, xtype, xpriv) \
756 {.iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
758 .info = qtet_##xtype##_info,\
761 .private_value = xpriv }
763 static struct snd_kcontrol_new qtet_controls
[] = {
765 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
766 .name
= "Master Playback Switch",
767 .info
= qtet_sw_info
,
768 .get
= qtet_mute_get
,
769 .put
= qtet_mute_put
,
773 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
774 .name
= "Phantom Power",
775 .info
= qtet_sw_info
,
781 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
782 .name
= "Analog In 1/2 Capture Switch",
783 .info
= qtet_ain12_enum_info
,
784 .get
= qtet_ain12_sw_get
,
785 .put
= qtet_ain12_sw_put
,
788 QTET_CONTROL("Analog In 3/4 Capture Switch", enum, AIN34_SEL
),
789 QTET_CONTROL("PCM In 1/2 Capture Switch", enum, IN12_SEL
),
790 QTET_CONTROL("PCM In 3/4 Capture Switch", enum, IN34_SEL
),
791 QTET_CONTROL("Coax Output Source", enum, COAX_OUT
),
792 QTET_CONTROL("Analog In 1/2 to Monitor 1/2", sw
, IN12_MON12
),
793 QTET_CONTROL("Analog In 1/2 to Monitor 3/4", sw
, IN12_MON34
),
794 QTET_CONTROL("Analog In 3/4 to Monitor 1/2", sw
, IN34_MON12
),
795 QTET_CONTROL("Analog In 3/4 to Monitor 3/4", sw
, IN34_MON34
),
796 QTET_CONTROL("Output 1/2 to Monitor 3/4", sw
, OUT12_MON34
),
797 QTET_CONTROL("Output 3/4 to Monitor 1/2", sw
, OUT34_MON12
),
800 static char *slave_vols
[] = {
801 PCM_12_PLAYBACK_VOLUME
,
802 PCM_34_PLAYBACK_VOLUME
,
807 DECLARE_TLV_DB_SCALE(qtet_master_db_scale
, -6350, 50, 1);
809 static struct snd_kcontrol
*ctl_find(struct snd_card
*card
,
812 struct snd_ctl_elem_id sid
;
813 memset(&sid
, 0, sizeof(sid
));
814 /* FIXME: strcpy is bad. */
815 strcpy(sid
.name
, name
);
816 sid
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
817 return snd_ctl_find_id(card
, &sid
);
820 static void add_slaves(struct snd_card
*card
,
821 struct snd_kcontrol
*master
, char * const *list
)
823 for (; *list
; list
++) {
824 struct snd_kcontrol
*slave
= ctl_find(card
, *list
);
826 snd_ctl_add_slave(master
, slave
);
830 static int qtet_add_controls(struct snd_ice1712
*ice
)
832 struct qtet_spec
*spec
= ice
->spec
;
834 struct snd_kcontrol
*vmaster
;
835 err
= snd_ice1712_akm4xxx_build_controls(ice
);
838 for (i
= 0; i
< ARRAY_SIZE(qtet_controls
); i
++) {
839 err
= snd_ctl_add(ice
->card
,
840 snd_ctl_new1(&qtet_controls
[i
], ice
));
845 /* Create virtual master control */
846 vmaster
= snd_ctl_make_virtual_master("Master Playback Volume",
847 qtet_master_db_scale
);
850 add_slaves(ice
->card
, vmaster
, slave_vols
);
851 err
= snd_ctl_add(ice
->card
, vmaster
);
854 /* only capture SPDIF over AK4113 */
855 err
= snd_ak4113_build(spec
->ak4113
,
856 ice
->pcm
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
);
862 static inline int qtet_is_spdif_master(struct snd_ice1712
*ice
)
864 /* CPLD_SYNC_SEL: 0 = internal, 1 = external (i.e. spdif master) */
865 return (get_cpld(ice
) & CPLD_SYNC_SEL
) ? 1 : 0;
868 static unsigned int qtet_get_rate(struct snd_ice1712
*ice
)
871 unsigned char result
;
873 result
= get_cpld(ice
) & CPLD_CKS_MASK
;
874 for (i
= 0; i
< ARRAY_SIZE(cks_vals
); i
++)
875 if (cks_vals
[i
] == result
)
876 return qtet_rates
[i
];
880 static int get_cks_val(int rate
)
883 for (i
= 0; i
< ARRAY_SIZE(qtet_rates
); i
++)
884 if (qtet_rates
[i
] == rate
)
889 /* setting new rate */
890 static void qtet_set_rate(struct snd_ice1712
*ice
, unsigned int rate
)
894 /* switching ice1724 to external clock - supplied by ext. circuits */
895 val
= inb(ICEMT1724(ice
, RATE
));
896 outb(val
| VT1724_SPDIF_MASTER
, ICEMT1724(ice
, RATE
));
898 new = (get_cpld(ice
) & ~CPLD_CKS_MASK
) | get_cks_val(rate
);
899 /* switch to internal clock, drop CPLD_SYNC_SEL */
900 new &= ~CPLD_SYNC_SEL
;
901 /* dev_dbg(ice->card->dev, "QT - set_rate: old %x, new %x\n",
902 get_cpld(ice), new); */
906 static inline unsigned char qtet_set_mclk(struct snd_ice1712
*ice
,
909 /* no change in master clock */
913 /* setting clock to external - SPDIF */
914 static int qtet_set_spdif_clock(struct snd_ice1712
*ice
, int type
)
916 unsigned int old
, new;
918 old
= new = get_cpld(ice
);
919 new &= ~(CPLD_CKS_MASK
| CPLD_WORD_SEL
);
922 new |= CPLD_EXT_SPDIF
;
924 case EXT_WORDCLOCK_1FS_TYPE
:
925 new |= CPLD_EXT_WORDCLOCK_1FS
;
927 case EXT_WORDCLOCK_256FS_TYPE
:
928 new |= CPLD_EXT_WORDCLOCK_256FS
;
941 static int qtet_get_spdif_master_type(struct snd_ice1712
*ice
)
946 /* checking only rate/clock-related bits */
947 val
&= (CPLD_CKS_MASK
| CPLD_WORD_SEL
| CPLD_SYNC_SEL
);
948 if (!(val
& CPLD_SYNC_SEL
)) {
949 /* switched to internal clock, is not any external type */
953 case (CPLD_EXT_SPDIF
):
954 result
= EXT_SPDIF_TYPE
;
956 case (CPLD_EXT_WORDCLOCK_1FS
):
957 result
= EXT_WORDCLOCK_1FS_TYPE
;
959 case (CPLD_EXT_WORDCLOCK_256FS
):
960 result
= EXT_WORDCLOCK_256FS_TYPE
;
963 /* undefined combination of external clock setup */
971 /* Called when ak4113 detects change in the input SPDIF stream */
972 static void qtet_ak4113_change(struct ak4113
*ak4113
, unsigned char c0
,
975 struct snd_ice1712
*ice
= ak4113
->change_callback_private
;
977 if ((qtet_get_spdif_master_type(ice
) == EXT_SPDIF_TYPE
) &&
979 /* only for SPDIF master mode, rate was changed */
980 rate
= snd_ak4113_external_rate(ak4113
);
981 /* dev_dbg(ice->card->dev, "ak4113 - input rate changed to %d\n",
983 qtet_akm_set_rate_val(ice
->akm
, rate
);
988 * If clock slaved to SPDIF-IN, setting runtime rate
989 * to the detected external rate
991 static void qtet_spdif_in_open(struct snd_ice1712
*ice
,
992 struct snd_pcm_substream
*substream
)
994 struct qtet_spec
*spec
= ice
->spec
;
995 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
998 if (qtet_get_spdif_master_type(ice
) != EXT_SPDIF_TYPE
)
999 /* not external SPDIF, no rate limitation */
1001 /* only external SPDIF can detect incoming sample rate */
1002 rate
= snd_ak4113_external_rate(spec
->ak4113
);
1003 if (rate
>= runtime
->hw
.rate_min
&& rate
<= runtime
->hw
.rate_max
) {
1004 runtime
->hw
.rate_min
= rate
;
1005 runtime
->hw
.rate_max
= rate
;
1010 * initialize the chip
1012 static int qtet_init(struct snd_ice1712
*ice
)
1014 static const unsigned char ak4113_init_vals
[] = {
1015 /* AK4113_REG_PWRDN */ AK4113_RST
| AK4113_PWN
|
1016 AK4113_OCKS0
| AK4113_OCKS1
,
1017 /* AK4113_REQ_FORMAT */ AK4113_DIF_I24I2S
| AK4113_VTX
|
1018 AK4113_DEM_OFF
| AK4113_DEAU
,
1019 /* AK4113_REG_IO0 */ AK4113_OPS2
| AK4113_TXE
|
1021 /* AK4113_REG_IO1 */ AK4113_EFH_1024LRCLK
| AK4113_IPS(0),
1022 /* AK4113_REG_INT0_MASK */ 0,
1023 /* AK4113_REG_INT1_MASK */ 0,
1024 /* AK4113_REG_DATDTS */ 0,
1027 struct qtet_spec
*spec
;
1028 struct snd_akm4xxx
*ak
;
1031 /* switching ice1724 to external clock - supplied by ext. circuits */
1032 val
= inb(ICEMT1724(ice
, RATE
));
1033 outb(val
| VT1724_SPDIF_MASTER
, ICEMT1724(ice
, RATE
));
1035 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1038 /* qtet is clocked by Xilinx array */
1039 ice
->hw_rates
= &qtet_rates_info
;
1040 ice
->is_spdif_master
= qtet_is_spdif_master
;
1041 ice
->get_rate
= qtet_get_rate
;
1042 ice
->set_rate
= qtet_set_rate
;
1043 ice
->set_mclk
= qtet_set_mclk
;
1044 ice
->set_spdif_clock
= qtet_set_spdif_clock
;
1045 ice
->get_spdif_master_type
= qtet_get_spdif_master_type
;
1046 ice
->ext_clock_names
= ext_clock_names
;
1047 ice
->ext_clock_count
= ARRAY_SIZE(ext_clock_names
);
1048 /* since Qtet can detect correct SPDIF-in rate, all streams can be
1049 * limited to this specific rate */
1050 ice
->spdif
.ops
.open
= ice
->pro_open
= qtet_spdif_in_open
;
1055 /* keep codec power down first */
1056 set_scr(ice
, SCR_PHP
);
1058 /* codec power up */
1059 set_scr(ice
, SCR_PHP
| SCR_CODEC_PDN
);
1061 /* MCR Initialize */
1064 /* CPLD Initialize */
1068 ice
->num_total_dacs
= 2;
1069 ice
->num_total_adcs
= 2;
1071 ice
->akm
= kcalloc(2, sizeof(struct snd_akm4xxx
), GFP_KERNEL
);
1075 /* only one codec with two chips */
1076 ice
->akm_codecs
= 1;
1077 err
= snd_ice1712_akm4xxx_init(ak
, &akm_qtet_dac
, NULL
, ice
);
1080 err
= snd_ak4113_create(ice
->card
,
1084 ice
, &spec
->ak4113
);
1087 /* callback for codecs rate setting */
1088 spec
->ak4113
->change_callback
= qtet_ak4113_change
;
1089 spec
->ak4113
->change_callback_private
= ice
;
1090 /* AK41143 in Quartet can detect external rate correctly
1091 * (i.e. check_flags = 0) */
1092 spec
->ak4113
->check_flags
= 0;
1096 qtet_set_rate(ice
, 44100);
1100 static unsigned char qtet_eeprom
[] = {
1101 [ICE_EEP2_SYSCONF
] = 0x28, /* clock 256(24MHz), mpu401, 1xADC,
1103 [ICE_EEP2_ACLINK
] = 0x80, /* I2S */
1104 [ICE_EEP2_I2S
] = 0x78, /* 96k, 24bit, 192k */
1105 [ICE_EEP2_SPDIF
] = 0xc3, /* out-en, out-int, in, out-ext */
1106 [ICE_EEP2_GPIO_DIR
] = 0x00, /* 0-7 inputs, switched to output
1107 only during output operations */
1108 [ICE_EEP2_GPIO_DIR1
] = 0xff, /* 8-15 outputs */
1109 [ICE_EEP2_GPIO_DIR2
] = 0x00,
1110 [ICE_EEP2_GPIO_MASK
] = 0xff, /* changed only for OUT operations */
1111 [ICE_EEP2_GPIO_MASK1
] = 0x00,
1112 [ICE_EEP2_GPIO_MASK2
] = 0xff,
1114 [ICE_EEP2_GPIO_STATE
] = 0x00, /* inputs */
1115 [ICE_EEP2_GPIO_STATE1
] = 0x7d, /* all 1, but GPIO_CPLD_RW
1116 and GPIO15 always zero */
1117 [ICE_EEP2_GPIO_STATE2
] = 0x00, /* inputs */
1121 struct snd_ice1712_card_info snd_vt1724_qtet_cards
[] = {
1123 .subvendor
= VT1724_SUBDEVICE_QTET
,
1124 .name
= "Infrasonic Quartet",
1126 .chip_init
= qtet_init
,
1127 .build_controls
= qtet_add_controls
,
1128 .eeprom_size
= sizeof(qtet_eeprom
),
1129 .eeprom_data
= qtet_eeprom
,
1131 { } /* terminator */