1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ALSA driver for ICEnsemble ICE1712 (Envy24)
5 * Lowlevel functions for M-Audio Audiophile 192, Revolution 7.1 and 5.1
7 * Copyright (c) 2003 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 <sound/core.h>
20 /* a non-standard I2C device for revo51 */
22 struct snd_i2c_device
*dev
;
23 struct snd_pt2258
*pt2258
;
24 struct ak4114
*ak4114
;
27 static void revo_i2s_mclk_changed(struct snd_ice1712
*ice
)
29 /* assert PRST# to converters; MT05 bit 7 */
30 outb(inb(ICEMT1724(ice
, AC97_CMD
)) | 0x80, ICEMT1724(ice
, AC97_CMD
));
33 outb(inb(ICEMT1724(ice
, AC97_CMD
)) & ~0x80, ICEMT1724(ice
, AC97_CMD
));
37 * change the rate of Envy24HT, AK4355 and AK4381
39 static void revo_set_rate_val(struct snd_akm4xxx
*ak
, unsigned int rate
)
41 unsigned char old
, tmp
, dfs
;
44 if (rate
== 0) /* no hint - S/PDIF input is master, simply return */
47 /* adjust DFS on codecs */
50 else if (rate
> 48000)
55 if (ak
->type
== SND_AK4355
|| ak
->type
== SND_AK4358
) {
62 tmp
= snd_akm4xxx_get(ak
, 0, reg
);
63 old
= (tmp
>> shift
) & 0x03;
68 snd_akm4xxx_reset(ak
, 1);
69 tmp
= snd_akm4xxx_get(ak
, 0, reg
);
70 tmp
&= ~(0x03 << shift
);
72 /* snd_akm4xxx_write(ak, 0, reg, tmp); */
73 snd_akm4xxx_set(ak
, 0, reg
, tmp
); /* value is written in reset(0) */
74 snd_akm4xxx_reset(ak
, 0);
78 * I2C access to the PT2258 volume controller on GPIO 6/7 (Revolution 5.1)
81 static void revo_i2c_start(struct snd_i2c_bus
*bus
)
83 struct snd_ice1712
*ice
= bus
->private_data
;
84 snd_ice1712_save_gpio_status(ice
);
87 static void revo_i2c_stop(struct snd_i2c_bus
*bus
)
89 struct snd_ice1712
*ice
= bus
->private_data
;
90 snd_ice1712_restore_gpio_status(ice
);
93 static void revo_i2c_direction(struct snd_i2c_bus
*bus
, int clock
, int data
)
95 struct snd_ice1712
*ice
= bus
->private_data
;
96 unsigned int mask
, val
;
100 val
|= VT1724_REVO_I2C_CLOCK
; /* write SCL */
102 val
|= VT1724_REVO_I2C_DATA
; /* write SDA */
103 mask
= VT1724_REVO_I2C_CLOCK
| VT1724_REVO_I2C_DATA
;
104 ice
->gpio
.direction
&= ~mask
;
105 ice
->gpio
.direction
|= val
;
106 snd_ice1712_gpio_set_dir(ice
, ice
->gpio
.direction
);
107 snd_ice1712_gpio_set_mask(ice
, ~mask
);
110 static void revo_i2c_setlines(struct snd_i2c_bus
*bus
, int clk
, int data
)
112 struct snd_ice1712
*ice
= bus
->private_data
;
113 unsigned int val
= 0;
116 val
|= VT1724_REVO_I2C_CLOCK
;
118 val
|= VT1724_REVO_I2C_DATA
;
119 snd_ice1712_gpio_write_bits(ice
,
120 VT1724_REVO_I2C_DATA
|
121 VT1724_REVO_I2C_CLOCK
, val
);
125 static int revo_i2c_getdata(struct snd_i2c_bus
*bus
, int ack
)
127 struct snd_ice1712
*ice
= bus
->private_data
;
132 bit
= snd_ice1712_gpio_read_bits(ice
, VT1724_REVO_I2C_DATA
) ? 1 : 0;
136 static struct snd_i2c_bit_ops revo51_bit_ops
= {
137 .start
= revo_i2c_start
,
138 .stop
= revo_i2c_stop
,
139 .direction
= revo_i2c_direction
,
140 .setlines
= revo_i2c_setlines
,
141 .getdata
= revo_i2c_getdata
,
144 static int revo51_i2c_init(struct snd_ice1712
*ice
,
145 struct snd_pt2258
*pt
)
147 struct revo51_spec
*spec
;
150 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
155 /* create the I2C bus */
156 err
= snd_i2c_bus_create(ice
->card
, "ICE1724 GPIO6", NULL
, &ice
->i2c
);
160 ice
->i2c
->private_data
= ice
;
161 ice
->i2c
->hw_ops
.bit
= &revo51_bit_ops
;
163 /* create the I2C device */
164 err
= snd_i2c_device_create(ice
->i2c
, "PT2258", 0x40, &spec
->dev
);
168 pt
->card
= ice
->card
;
169 pt
->i2c_bus
= ice
->i2c
;
170 pt
->i2c_dev
= spec
->dev
;
173 snd_pt2258_reset(pt
);
179 * initialize the chips on M-Audio Revolution cards
182 #define AK_DAC(xname,xch) { .name = xname, .num_channels = xch }
184 static const struct snd_akm4xxx_dac_channel revo71_front
[] = {
186 .name
= "PCM Playback Volume",
188 /* front channels DAC supports muting */
189 .switch_name
= "PCM Playback Switch",
193 static const struct snd_akm4xxx_dac_channel revo71_surround
[] = {
194 AK_DAC("PCM Center Playback Volume", 1),
195 AK_DAC("PCM LFE Playback Volume", 1),
196 AK_DAC("PCM Side Playback Volume", 2),
197 AK_DAC("PCM Rear Playback Volume", 2),
200 static const struct snd_akm4xxx_dac_channel revo51_dac
[] = {
201 AK_DAC("PCM Playback Volume", 2),
202 AK_DAC("PCM Center Playback Volume", 1),
203 AK_DAC("PCM LFE Playback Volume", 1),
204 AK_DAC("PCM Rear Playback Volume", 2),
205 AK_DAC("PCM Headphone Volume", 2),
208 static const char *revo51_adc_input_names
[] = {
215 static const struct snd_akm4xxx_adc_channel revo51_adc
[] = {
217 .name
= "PCM Capture Volume",
218 .switch_name
= "PCM Capture Switch",
220 .input_names
= revo51_adc_input_names
224 static const struct snd_akm4xxx akm_revo_front
= {
228 .set_rate_val
= revo_set_rate_val
230 .dac_info
= revo71_front
,
233 static const struct snd_ak4xxx_private akm_revo_front_priv
= {
236 .data_mask
= VT1724_REVO_CDOUT
,
237 .clk_mask
= VT1724_REVO_CCLK
,
238 .cs_mask
= VT1724_REVO_CS0
| VT1724_REVO_CS1
| VT1724_REVO_CS2
,
239 .cs_addr
= VT1724_REVO_CS0
| VT1724_REVO_CS2
,
240 .cs_none
= VT1724_REVO_CS0
| VT1724_REVO_CS1
| VT1724_REVO_CS2
,
241 .add_flags
= VT1724_REVO_CCLK
, /* high at init */
245 static const struct snd_akm4xxx akm_revo_surround
= {
250 .set_rate_val
= revo_set_rate_val
252 .dac_info
= revo71_surround
,
255 static const struct snd_ak4xxx_private akm_revo_surround_priv
= {
258 .data_mask
= VT1724_REVO_CDOUT
,
259 .clk_mask
= VT1724_REVO_CCLK
,
260 .cs_mask
= VT1724_REVO_CS0
| VT1724_REVO_CS1
| VT1724_REVO_CS2
,
261 .cs_addr
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
262 .cs_none
= VT1724_REVO_CS0
| VT1724_REVO_CS1
| VT1724_REVO_CS2
,
263 .add_flags
= VT1724_REVO_CCLK
, /* high at init */
267 static const struct snd_akm4xxx akm_revo51
= {
271 .set_rate_val
= revo_set_rate_val
273 .dac_info
= revo51_dac
,
276 static const struct snd_ak4xxx_private akm_revo51_priv
= {
279 .data_mask
= VT1724_REVO_CDOUT
,
280 .clk_mask
= VT1724_REVO_CCLK
,
281 .cs_mask
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
282 .cs_addr
= VT1724_REVO_CS1
,
283 .cs_none
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
284 .add_flags
= VT1724_REVO_CCLK
, /* high at init */
288 static const struct snd_akm4xxx akm_revo51_adc
= {
291 .adc_info
= revo51_adc
,
294 static const struct snd_ak4xxx_private akm_revo51_adc_priv
= {
297 .data_mask
= VT1724_REVO_CDOUT
,
298 .clk_mask
= VT1724_REVO_CCLK
,
299 .cs_mask
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
300 .cs_addr
= VT1724_REVO_CS0
,
301 .cs_none
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
302 .add_flags
= VT1724_REVO_CCLK
, /* high at init */
306 static struct snd_pt2258 ptc_revo51_volume
;
308 /* AK4358 for AP192 DAC, AK5385A for ADC */
309 static void ap192_set_rate_val(struct snd_akm4xxx
*ak
, unsigned int rate
)
311 struct snd_ice1712
*ice
= ak
->private_data
[0];
314 revo_set_rate_val(ak
, rate
);
317 snd_ice1712_gpio_write_bits(ice
, 1 << 8, rate
> 96000 ? 1 << 8 : 0);
318 /* reset DFS pins of AK5385A for ADC, too */
321 else if (rate
> 48000)
325 snd_ice1712_gpio_write_bits(ice
, 3 << 9, dfs
<< 9);
327 snd_ice1712_gpio_write_bits(ice
, 1 << 11, 0);
328 snd_ice1712_gpio_write_bits(ice
, 1 << 11, 1 << 11);
331 static const struct snd_akm4xxx_dac_channel ap192_dac
[] = {
332 AK_DAC("PCM Playback Volume", 2)
335 static const struct snd_akm4xxx akm_ap192
= {
339 .set_rate_val
= ap192_set_rate_val
341 .dac_info
= ap192_dac
,
344 static const struct snd_ak4xxx_private akm_ap192_priv
= {
347 .data_mask
= VT1724_REVO_CDOUT
,
348 .clk_mask
= VT1724_REVO_CCLK
,
349 .cs_mask
= VT1724_REVO_CS0
| VT1724_REVO_CS3
,
350 .cs_addr
= VT1724_REVO_CS3
,
351 .cs_none
= VT1724_REVO_CS0
| VT1724_REVO_CS3
,
352 .add_flags
= VT1724_REVO_CCLK
, /* high at init */
356 /* AK4114 support on Audiophile 192 */
357 /* CDTO (pin 32) -- GPIO2 pin 52
358 * CDTI (pin 33) -- GPIO3 pin 53 (shared with AK4358)
359 * CCLK (pin 34) -- GPIO1 pin 51 (shared with AK4358)
360 * CSN (pin 35) -- GPIO7 pin 59
362 #define AK4114_ADDR 0x00
364 static void write_data(struct snd_ice1712
*ice
, unsigned int gpio
,
365 unsigned int data
, int idx
)
367 for (; idx
>= 0; idx
--) {
369 gpio
&= ~VT1724_REVO_CCLK
;
370 snd_ice1712_gpio_write(ice
, gpio
);
373 if (data
& (1 << idx
))
374 gpio
|= VT1724_REVO_CDOUT
;
376 gpio
&= ~VT1724_REVO_CDOUT
;
377 snd_ice1712_gpio_write(ice
, gpio
);
380 gpio
|= VT1724_REVO_CCLK
;
381 snd_ice1712_gpio_write(ice
, gpio
);
386 static unsigned char read_data(struct snd_ice1712
*ice
, unsigned int gpio
,
389 unsigned char data
= 0;
391 for (; idx
>= 0; idx
--) {
393 gpio
&= ~VT1724_REVO_CCLK
;
394 snd_ice1712_gpio_write(ice
, gpio
);
397 if (snd_ice1712_gpio_read(ice
) & VT1724_REVO_CDIN
)
401 gpio
|= VT1724_REVO_CCLK
;
402 snd_ice1712_gpio_write(ice
, gpio
);
408 static unsigned int ap192_4wire_start(struct snd_ice1712
*ice
)
412 snd_ice1712_save_gpio_status(ice
);
413 tmp
= snd_ice1712_gpio_read(ice
);
414 tmp
|= VT1724_REVO_CCLK
; /* high at init */
415 tmp
|= VT1724_REVO_CS0
;
416 tmp
&= ~VT1724_REVO_CS3
;
417 snd_ice1712_gpio_write(ice
, tmp
);
422 static void ap192_4wire_finish(struct snd_ice1712
*ice
, unsigned int tmp
)
424 tmp
|= VT1724_REVO_CS3
;
425 tmp
|= VT1724_REVO_CS0
;
426 snd_ice1712_gpio_write(ice
, tmp
);
428 snd_ice1712_restore_gpio_status(ice
);
431 static void ap192_ak4114_write(void *private_data
, unsigned char addr
,
434 struct snd_ice1712
*ice
= private_data
;
435 unsigned int tmp
, addrdata
;
437 tmp
= ap192_4wire_start(ice
);
438 addrdata
= (AK4114_ADDR
<< 6) | 0x20 | (addr
& 0x1f);
439 addrdata
= (addrdata
<< 8) | data
;
440 write_data(ice
, tmp
, addrdata
, 15);
441 ap192_4wire_finish(ice
, tmp
);
444 static unsigned char ap192_ak4114_read(void *private_data
, unsigned char addr
)
446 struct snd_ice1712
*ice
= private_data
;
450 tmp
= ap192_4wire_start(ice
);
451 write_data(ice
, tmp
, (AK4114_ADDR
<< 6) | (addr
& 0x1f), 7);
452 data
= read_data(ice
, tmp
, 7);
453 ap192_4wire_finish(ice
, tmp
);
457 static int ap192_ak4114_init(struct snd_ice1712
*ice
)
459 static const unsigned char ak4114_init_vals
[] = {
460 AK4114_RST
| AK4114_PWN
| AK4114_OCKS0
,
463 AK4114_EFH_1024
| AK4114_DIT
| AK4114_IPS(0),
467 static const unsigned char ak4114_init_txcsb
[] = {
468 0x41, 0x02, 0x2c, 0x00, 0x00
472 struct revo51_spec
*spec
;
473 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
478 err
= snd_ak4114_create(ice
->card
,
481 ak4114_init_vals
, ak4114_init_txcsb
,
485 /* AK4114 in Revo cannot detect external rate correctly.
486 * No reason to stop capture stream due to incorrect checks */
487 spec
->ak4114
->check_flags
= AK4114_CHECK_NO_RATE
;
492 static int revo_init(struct snd_ice1712
*ice
)
494 struct snd_akm4xxx
*ak
;
497 /* determine I2C, DACs and ADCs */
498 switch (ice
->eeprom
.subvendor
) {
499 case VT1724_SUBDEVICE_REVOLUTION71
:
500 ice
->num_total_dacs
= 8;
501 ice
->num_total_adcs
= 2;
502 ice
->gpio
.i2s_mclk_changed
= revo_i2s_mclk_changed
;
504 case VT1724_SUBDEVICE_REVOLUTION51
:
505 ice
->num_total_dacs
= 8;
506 ice
->num_total_adcs
= 2;
508 case VT1724_SUBDEVICE_AUDIOPHILE192
:
509 ice
->num_total_dacs
= 2;
510 ice
->num_total_adcs
= 2;
517 /* second stage of initialization, analog parts and others */
518 ak
= ice
->akm
= kcalloc(2, sizeof(struct snd_akm4xxx
), GFP_KERNEL
);
521 switch (ice
->eeprom
.subvendor
) {
522 case VT1724_SUBDEVICE_REVOLUTION71
:
524 err
= snd_ice1712_akm4xxx_init(ak
, &akm_revo_front
,
525 &akm_revo_front_priv
, ice
);
528 err
= snd_ice1712_akm4xxx_init(ak
+1, &akm_revo_surround
,
529 &akm_revo_surround_priv
, ice
);
532 /* unmute all codecs */
533 snd_ice1712_gpio_write_bits(ice
, VT1724_REVO_MUTE
,
536 case VT1724_SUBDEVICE_REVOLUTION51
:
538 err
= snd_ice1712_akm4xxx_init(ak
, &akm_revo51
,
539 &akm_revo51_priv
, ice
);
542 err
= snd_ice1712_akm4xxx_init(ak
+1, &akm_revo51_adc
,
543 &akm_revo51_adc_priv
, ice
);
546 err
= revo51_i2c_init(ice
, &ptc_revo51_volume
);
549 /* unmute all codecs */
550 snd_ice1712_gpio_write_bits(ice
, VT1724_REVO_MUTE
,
553 case VT1724_SUBDEVICE_AUDIOPHILE192
:
555 err
= snd_ice1712_akm4xxx_init(ak
, &akm_ap192
, &akm_ap192_priv
,
559 err
= ap192_ak4114_init(ice
);
563 /* unmute all codecs */
564 snd_ice1712_gpio_write_bits(ice
, VT1724_REVO_MUTE
,
573 static int revo_add_controls(struct snd_ice1712
*ice
)
575 struct revo51_spec
*spec
= ice
->spec
;
578 switch (ice
->eeprom
.subvendor
) {
579 case VT1724_SUBDEVICE_REVOLUTION71
:
580 err
= snd_ice1712_akm4xxx_build_controls(ice
);
584 case VT1724_SUBDEVICE_REVOLUTION51
:
585 err
= snd_ice1712_akm4xxx_build_controls(ice
);
589 err
= snd_pt2258_build_controls(spec
->pt2258
);
593 case VT1724_SUBDEVICE_AUDIOPHILE192
:
594 err
= snd_ice1712_akm4xxx_build_controls(ice
);
597 /* only capture SPDIF over AK4114 */
598 err
= snd_ak4114_build(spec
->ak4114
, NULL
,
599 ice
->pcm
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
);
608 struct snd_ice1712_card_info snd_vt1724_revo_cards
[] = {
610 .subvendor
= VT1724_SUBDEVICE_REVOLUTION71
,
611 .name
= "M Audio Revolution-7.1",
613 .chip_init
= revo_init
,
614 .build_controls
= revo_add_controls
,
617 .subvendor
= VT1724_SUBDEVICE_REVOLUTION51
,
618 .name
= "M Audio Revolution-5.1",
620 .chip_init
= revo_init
,
621 .build_controls
= revo_add_controls
,
624 .subvendor
= VT1724_SUBDEVICE_AUDIOPHILE192
,
625 .name
= "M Audio Audiophile192",
627 .chip_init
= revo_init
,
628 .build_controls
= revo_add_controls
,