2 * ALSA driver for ICEnsemble ICE1712 (Envy24)
4 * Lowlevel functions for M-Audio Audiophile 192, Revolution 7.1 and 5.1
6 * Copyright (c) 2003 Takashi Iwai <tiwai@suse.de>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * 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>
35 /* a non-standard I2C device for revo51 */
37 struct snd_i2c_device
*dev
;
38 struct snd_pt2258
*pt2258
;
41 static void revo_i2s_mclk_changed(struct snd_ice1712
*ice
)
43 /* assert PRST# to converters; MT05 bit 7 */
44 outb(inb(ICEMT1724(ice
, AC97_CMD
)) | 0x80, ICEMT1724(ice
, AC97_CMD
));
47 outb(inb(ICEMT1724(ice
, AC97_CMD
)) & ~0x80, ICEMT1724(ice
, AC97_CMD
));
51 * change the rate of Envy24HT, AK4355 and AK4381
53 static void revo_set_rate_val(struct snd_akm4xxx
*ak
, unsigned int rate
)
55 unsigned char old
, tmp
, dfs
;
58 if (rate
== 0) /* no hint - S/PDIF input is master, simply return */
61 /* adjust DFS on codecs */
64 else if (rate
> 48000)
69 if (ak
->type
== SND_AK4355
|| ak
->type
== SND_AK4358
) {
76 tmp
= snd_akm4xxx_get(ak
, 0, reg
);
77 old
= (tmp
>> shift
) & 0x03;
82 snd_akm4xxx_reset(ak
, 1);
83 tmp
= snd_akm4xxx_get(ak
, 0, reg
);
84 tmp
&= ~(0x03 << shift
);
86 /* snd_akm4xxx_write(ak, 0, reg, tmp); */
87 snd_akm4xxx_set(ak
, 0, reg
, tmp
); /* value is written in reset(0) */
88 snd_akm4xxx_reset(ak
, 0);
92 * I2C access to the PT2258 volume controller on GPIO 6/7 (Revolution 5.1)
95 static void revo_i2c_start(struct snd_i2c_bus
*bus
)
97 struct snd_ice1712
*ice
= bus
->private_data
;
98 snd_ice1712_save_gpio_status(ice
);
101 static void revo_i2c_stop(struct snd_i2c_bus
*bus
)
103 struct snd_ice1712
*ice
= bus
->private_data
;
104 snd_ice1712_restore_gpio_status(ice
);
107 static void revo_i2c_direction(struct snd_i2c_bus
*bus
, int clock
, int data
)
109 struct snd_ice1712
*ice
= bus
->private_data
;
110 unsigned int mask
, val
;
114 val
|= VT1724_REVO_I2C_CLOCK
; /* write SCL */
116 val
|= VT1724_REVO_I2C_DATA
; /* write SDA */
117 mask
= VT1724_REVO_I2C_CLOCK
| VT1724_REVO_I2C_DATA
;
118 ice
->gpio
.direction
&= ~mask
;
119 ice
->gpio
.direction
|= val
;
120 snd_ice1712_gpio_set_dir(ice
, ice
->gpio
.direction
);
121 snd_ice1712_gpio_set_mask(ice
, ~mask
);
124 static void revo_i2c_setlines(struct snd_i2c_bus
*bus
, int clk
, int data
)
126 struct snd_ice1712
*ice
= bus
->private_data
;
127 unsigned int val
= 0;
130 val
|= VT1724_REVO_I2C_CLOCK
;
132 val
|= VT1724_REVO_I2C_DATA
;
133 snd_ice1712_gpio_write_bits(ice
,
134 VT1724_REVO_I2C_DATA
|
135 VT1724_REVO_I2C_CLOCK
, val
);
139 static int revo_i2c_getdata(struct snd_i2c_bus
*bus
, int ack
)
141 struct snd_ice1712
*ice
= bus
->private_data
;
146 bit
= snd_ice1712_gpio_read_bits(ice
, VT1724_REVO_I2C_DATA
) ? 1 : 0;
150 static struct snd_i2c_bit_ops revo51_bit_ops
= {
151 .start
= revo_i2c_start
,
152 .stop
= revo_i2c_stop
,
153 .direction
= revo_i2c_direction
,
154 .setlines
= revo_i2c_setlines
,
155 .getdata
= revo_i2c_getdata
,
158 static int revo51_i2c_init(struct snd_ice1712
*ice
,
159 struct snd_pt2258
*pt
)
161 struct revo51_spec
*spec
;
164 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
169 /* create the I2C bus */
170 err
= snd_i2c_bus_create(ice
->card
, "ICE1724 GPIO6", NULL
, &ice
->i2c
);
174 ice
->i2c
->private_data
= ice
;
175 ice
->i2c
->hw_ops
.bit
= &revo51_bit_ops
;
177 /* create the I2C device */
178 err
= snd_i2c_device_create(ice
->i2c
, "PT2258", 0x40, &spec
->dev
);
182 pt
->card
= ice
->card
;
183 pt
->i2c_bus
= ice
->i2c
;
184 pt
->i2c_dev
= spec
->dev
;
187 snd_pt2258_reset(pt
);
193 * initialize the chips on M-Audio Revolution cards
196 #define AK_DAC(xname,xch) { .name = xname, .num_channels = xch }
198 static const struct snd_akm4xxx_dac_channel revo71_front
[] = {
200 .name
= "PCM Playback Volume",
202 /* front channels DAC supports muting */
203 .switch_name
= "PCM Playback Switch",
207 static const struct snd_akm4xxx_dac_channel revo71_surround
[] = {
208 AK_DAC("PCM Center Playback Volume", 1),
209 AK_DAC("PCM LFE Playback Volume", 1),
210 AK_DAC("PCM Side Playback Volume", 2),
211 AK_DAC("PCM Rear Playback Volume", 2),
214 static const struct snd_akm4xxx_dac_channel revo51_dac
[] = {
215 AK_DAC("PCM Playback Volume", 2),
216 AK_DAC("PCM Center Playback Volume", 1),
217 AK_DAC("PCM LFE Playback Volume", 1),
218 AK_DAC("PCM Rear Playback Volume", 2),
219 AK_DAC("PCM Headphone Volume", 2),
222 static const char *revo51_adc_input_names
[] = {
229 static const struct snd_akm4xxx_adc_channel revo51_adc
[] = {
231 .name
= "PCM Capture Volume",
232 .switch_name
= "PCM Capture Switch",
234 .input_names
= revo51_adc_input_names
238 static struct snd_akm4xxx akm_revo_front __devinitdata
= {
242 .set_rate_val
= revo_set_rate_val
244 .dac_info
= revo71_front
,
247 static struct snd_ak4xxx_private akm_revo_front_priv __devinitdata
= {
250 .data_mask
= VT1724_REVO_CDOUT
,
251 .clk_mask
= VT1724_REVO_CCLK
,
252 .cs_mask
= VT1724_REVO_CS0
| VT1724_REVO_CS1
| VT1724_REVO_CS2
,
253 .cs_addr
= VT1724_REVO_CS0
| VT1724_REVO_CS2
,
254 .cs_none
= VT1724_REVO_CS0
| VT1724_REVO_CS1
| VT1724_REVO_CS2
,
255 .add_flags
= VT1724_REVO_CCLK
, /* high at init */
259 static struct snd_akm4xxx akm_revo_surround __devinitdata
= {
264 .set_rate_val
= revo_set_rate_val
266 .dac_info
= revo71_surround
,
269 static struct snd_ak4xxx_private akm_revo_surround_priv __devinitdata
= {
272 .data_mask
= VT1724_REVO_CDOUT
,
273 .clk_mask
= VT1724_REVO_CCLK
,
274 .cs_mask
= VT1724_REVO_CS0
| VT1724_REVO_CS1
| VT1724_REVO_CS2
,
275 .cs_addr
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
276 .cs_none
= VT1724_REVO_CS0
| VT1724_REVO_CS1
| VT1724_REVO_CS2
,
277 .add_flags
= VT1724_REVO_CCLK
, /* high at init */
281 static struct snd_akm4xxx akm_revo51 __devinitdata
= {
285 .set_rate_val
= revo_set_rate_val
287 .dac_info
= revo51_dac
,
290 static struct snd_ak4xxx_private akm_revo51_priv __devinitdata
= {
293 .data_mask
= VT1724_REVO_CDOUT
,
294 .clk_mask
= VT1724_REVO_CCLK
,
295 .cs_mask
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
296 .cs_addr
= VT1724_REVO_CS1
,
297 .cs_none
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
298 .add_flags
= VT1724_REVO_CCLK
, /* high at init */
302 static struct snd_akm4xxx akm_revo51_adc __devinitdata
= {
305 .adc_info
= revo51_adc
,
308 static struct snd_ak4xxx_private akm_revo51_adc_priv __devinitdata
= {
311 .data_mask
= VT1724_REVO_CDOUT
,
312 .clk_mask
= VT1724_REVO_CCLK
,
313 .cs_mask
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
314 .cs_addr
= VT1724_REVO_CS0
,
315 .cs_none
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
316 .add_flags
= VT1724_REVO_CCLK
, /* high at init */
320 static struct snd_pt2258 ptc_revo51_volume
;
322 /* AK4358 for AP192 DAC, AK5385A for ADC */
323 static void ap192_set_rate_val(struct snd_akm4xxx
*ak
, unsigned int rate
)
325 struct snd_ice1712
*ice
= ak
->private_data
[0];
328 revo_set_rate_val(ak
, rate
);
331 snd_ice1712_gpio_write_bits(ice
, 1 << 8, rate
> 96000 ? 1 << 8 : 0);
332 /* reset DFS pins of AK5385A for ADC, too */
335 else if (rate
> 48000)
339 snd_ice1712_gpio_write_bits(ice
, 3 << 9, dfs
<< 9);
341 snd_ice1712_gpio_write_bits(ice
, 1 << 11, 0);
342 snd_ice1712_gpio_write_bits(ice
, 1 << 11, 1 << 11);
345 static const struct snd_akm4xxx_dac_channel ap192_dac
[] = {
346 AK_DAC("PCM Playback Volume", 2)
349 static struct snd_akm4xxx akm_ap192 __devinitdata
= {
353 .set_rate_val
= ap192_set_rate_val
355 .dac_info
= ap192_dac
,
358 static struct snd_ak4xxx_private akm_ap192_priv __devinitdata
= {
361 .data_mask
= VT1724_REVO_CDOUT
,
362 .clk_mask
= VT1724_REVO_CCLK
,
363 .cs_mask
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
364 .cs_addr
= VT1724_REVO_CS1
,
365 .cs_none
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
366 .add_flags
= VT1724_REVO_CCLK
, /* high at init */
370 /* AK4114 support on Audiophile 192 */
371 /* CDTO (pin 32) -- GPIO2 pin 52
372 * CDTI (pin 33) -- GPIO3 pin 53 (shared with AK4358)
373 * CCLK (pin 34) -- GPIO1 pin 51 (shared with AK4358)
374 * CSN (pin 35) -- GPIO7 pin 59
376 #define AK4114_ADDR 0x02
378 static void write_data(struct snd_ice1712
*ice
, unsigned int gpio
,
379 unsigned int data
, int idx
)
381 for (; idx
>= 0; idx
--) {
383 gpio
&= ~VT1724_REVO_CCLK
;
384 snd_ice1712_gpio_write(ice
, gpio
);
387 if (data
& (1 << idx
))
388 gpio
|= VT1724_REVO_CDOUT
;
390 gpio
&= ~VT1724_REVO_CDOUT
;
391 snd_ice1712_gpio_write(ice
, gpio
);
394 gpio
|= VT1724_REVO_CCLK
;
395 snd_ice1712_gpio_write(ice
, gpio
);
400 static unsigned char read_data(struct snd_ice1712
*ice
, unsigned int gpio
,
403 unsigned char data
= 0;
405 for (; idx
>= 0; idx
--) {
407 gpio
&= ~VT1724_REVO_CCLK
;
408 snd_ice1712_gpio_write(ice
, gpio
);
411 if (snd_ice1712_gpio_read(ice
) & VT1724_REVO_CDIN
)
415 gpio
|= VT1724_REVO_CCLK
;
416 snd_ice1712_gpio_write(ice
, gpio
);
422 static unsigned int ap192_4wire_start(struct snd_ice1712
*ice
)
426 snd_ice1712_save_gpio_status(ice
);
427 tmp
= snd_ice1712_gpio_read(ice
);
428 tmp
|= VT1724_REVO_CCLK
; /* high at init */
429 tmp
|= VT1724_REVO_CS0
;
430 tmp
&= ~VT1724_REVO_CS1
;
431 snd_ice1712_gpio_write(ice
, tmp
);
436 static void ap192_4wire_finish(struct snd_ice1712
*ice
, unsigned int tmp
)
438 tmp
|= VT1724_REVO_CS1
;
439 tmp
|= VT1724_REVO_CS0
;
440 snd_ice1712_gpio_write(ice
, tmp
);
442 snd_ice1712_restore_gpio_status(ice
);
445 static void ap192_ak4114_write(void *private_data
, unsigned char addr
,
448 struct snd_ice1712
*ice
= private_data
;
449 unsigned int tmp
, addrdata
;
451 tmp
= ap192_4wire_start(ice
);
452 addrdata
= (AK4114_ADDR
<< 6) | 0x20 | (addr
& 0x1f);
453 addrdata
= (addrdata
<< 8) | data
;
454 write_data(ice
, tmp
, addrdata
, 15);
455 ap192_4wire_finish(ice
, tmp
);
458 static unsigned char ap192_ak4114_read(void *private_data
, unsigned char addr
)
460 struct snd_ice1712
*ice
= private_data
;
464 tmp
= ap192_4wire_start(ice
);
465 write_data(ice
, tmp
, (AK4114_ADDR
<< 6) | (addr
& 0x1f), 7);
466 data
= read_data(ice
, tmp
, 7);
467 ap192_4wire_finish(ice
, tmp
);
471 static int __devinit
ap192_ak4114_init(struct snd_ice1712
*ice
)
473 static const unsigned char ak4114_init_vals
[] = {
474 AK4114_RST
| AK4114_PWN
| AK4114_OCKS0
| AK4114_OCKS1
,
477 AK4114_EFH_1024
| AK4114_DIT
| AK4114_IPS(1),
481 static const unsigned char ak4114_init_txcsb
[] = {
482 0x41, 0x02, 0x2c, 0x00, 0x00
487 err
= snd_ak4114_create(ice
->card
,
490 ak4114_init_vals
, ak4114_init_txcsb
,
492 /* AK4114 in Revo cannot detect external rate correctly.
493 * No reason to stop capture stream due to incorrect checks */
494 ak
->check_flags
= AK4114_CHECK_NO_RATE
;
496 return 0; /* error ignored; it's no fatal error */
499 static int __devinit
revo_init(struct snd_ice1712
*ice
)
501 struct snd_akm4xxx
*ak
;
504 /* determine I2C, DACs and ADCs */
505 switch (ice
->eeprom
.subvendor
) {
506 case VT1724_SUBDEVICE_REVOLUTION71
:
507 ice
->num_total_dacs
= 8;
508 ice
->num_total_adcs
= 2;
509 ice
->gpio
.i2s_mclk_changed
= revo_i2s_mclk_changed
;
511 case VT1724_SUBDEVICE_REVOLUTION51
:
512 ice
->num_total_dacs
= 8;
513 ice
->num_total_adcs
= 2;
515 case VT1724_SUBDEVICE_AUDIOPHILE192
:
516 ice
->num_total_dacs
= 2;
517 ice
->num_total_adcs
= 2;
524 /* second stage of initialization, analog parts and others */
525 ak
= ice
->akm
= kcalloc(2, sizeof(struct snd_akm4xxx
), GFP_KERNEL
);
528 switch (ice
->eeprom
.subvendor
) {
529 case VT1724_SUBDEVICE_REVOLUTION71
:
531 err
= snd_ice1712_akm4xxx_init(ak
, &akm_revo_front
,
532 &akm_revo_front_priv
, ice
);
535 err
= snd_ice1712_akm4xxx_init(ak
+1, &akm_revo_surround
,
536 &akm_revo_surround_priv
, ice
);
539 /* unmute all codecs */
540 snd_ice1712_gpio_write_bits(ice
, VT1724_REVO_MUTE
,
543 case VT1724_SUBDEVICE_REVOLUTION51
:
545 err
= snd_ice1712_akm4xxx_init(ak
, &akm_revo51
,
546 &akm_revo51_priv
, ice
);
549 err
= snd_ice1712_akm4xxx_init(ak
+1, &akm_revo51_adc
,
550 &akm_revo51_adc_priv
, ice
);
553 err
= revo51_i2c_init(ice
, &ptc_revo51_volume
);
556 /* unmute all codecs */
557 snd_ice1712_gpio_write_bits(ice
, VT1724_REVO_MUTE
,
560 case VT1724_SUBDEVICE_AUDIOPHILE192
:
562 err
= snd_ice1712_akm4xxx_init(ak
, &akm_ap192
, &akm_ap192_priv
,
567 /* unmute all codecs */
568 snd_ice1712_gpio_write_bits(ice
, VT1724_REVO_MUTE
,
577 static int __devinit
revo_add_controls(struct snd_ice1712
*ice
)
579 struct revo51_spec
*spec
;
582 switch (ice
->eeprom
.subvendor
) {
583 case VT1724_SUBDEVICE_REVOLUTION71
:
584 err
= snd_ice1712_akm4xxx_build_controls(ice
);
588 case VT1724_SUBDEVICE_REVOLUTION51
:
589 err
= snd_ice1712_akm4xxx_build_controls(ice
);
593 err
= snd_pt2258_build_controls(spec
->pt2258
);
597 case VT1724_SUBDEVICE_AUDIOPHILE192
:
598 err
= snd_ice1712_akm4xxx_build_controls(ice
);
601 err
= ap192_ak4114_init(ice
);
610 struct snd_ice1712_card_info snd_vt1724_revo_cards
[] __devinitdata
= {
612 .subvendor
= VT1724_SUBDEVICE_REVOLUTION71
,
613 .name
= "M Audio Revolution-7.1",
615 .chip_init
= revo_init
,
616 .build_controls
= revo_add_controls
,
619 .subvendor
= VT1724_SUBDEVICE_REVOLUTION51
,
620 .name
= "M Audio Revolution-5.1",
622 .chip_init
= revo_init
,
623 .build_controls
= revo_add_controls
,
626 .subvendor
= VT1724_SUBDEVICE_AUDIOPHILE192
,
627 .name
= "M Audio Audiophile192",
629 .chip_init
= revo_init
,
630 .build_controls
= revo_add_controls
,