2 * ALSA driver for ICEnsemble ICE1712 (Envy24)
4 * Lowlevel functions for M-Audio Revolution 7.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
;
39 <<<<<<< HEAD
:sound
/pci
/ice1712
/revo
.c
43 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:sound
/pci
/ice1712
/revo
.c
45 static void revo_i2s_mclk_changed(struct snd_ice1712
*ice
)
47 /* assert PRST# to converters; MT05 bit 7 */
48 outb(inb(ICEMT1724(ice
, AC97_CMD
)) | 0x80, ICEMT1724(ice
, AC97_CMD
));
51 outb(inb(ICEMT1724(ice
, AC97_CMD
)) & ~0x80, ICEMT1724(ice
, AC97_CMD
));
55 * change the rate of envy24HT, AK4355 and AK4381
57 static void revo_set_rate_val(struct snd_akm4xxx
*ak
, unsigned int rate
)
59 unsigned char old
, tmp
, dfs
;
62 if (rate
== 0) /* no hint - S/PDIF input is master, simply return */
65 /* adjust DFS on codecs */
68 else if (rate
> 48000)
73 if (ak
->type
== SND_AK4355
|| ak
->type
== SND_AK4358
) {
80 tmp
= snd_akm4xxx_get(ak
, 0, reg
);
81 old
= (tmp
>> shift
) & 0x03;
86 snd_akm4xxx_reset(ak
, 1);
87 tmp
= snd_akm4xxx_get(ak
, 0, reg
);
88 tmp
&= ~(0x03 << shift
);
90 // snd_akm4xxx_write(ak, 0, reg, tmp);
91 snd_akm4xxx_set(ak
, 0, reg
, tmp
); /* the value is written in reset(0) */
92 snd_akm4xxx_reset(ak
, 0);
96 * I2C access to the PT2258 volume controller on GPIO 6/7 (Revolution 5.1)
99 static void revo_i2c_start(struct snd_i2c_bus
*bus
)
101 struct snd_ice1712
*ice
= bus
->private_data
;
102 snd_ice1712_save_gpio_status(ice
);
105 static void revo_i2c_stop(struct snd_i2c_bus
*bus
)
107 struct snd_ice1712
*ice
= bus
->private_data
;
108 snd_ice1712_restore_gpio_status(ice
);
111 static void revo_i2c_direction(struct snd_i2c_bus
*bus
, int clock
, int data
)
113 struct snd_ice1712
*ice
= bus
->private_data
;
114 unsigned int mask
, val
;
118 val
|= VT1724_REVO_I2C_CLOCK
; /* write SCL */
120 val
|= VT1724_REVO_I2C_DATA
; /* write SDA */
121 mask
= VT1724_REVO_I2C_CLOCK
| VT1724_REVO_I2C_DATA
;
122 ice
->gpio
.direction
&= ~mask
;
123 ice
->gpio
.direction
|= val
;
124 snd_ice1712_gpio_set_dir(ice
, ice
->gpio
.direction
);
125 snd_ice1712_gpio_set_mask(ice
, ~mask
);
128 static void revo_i2c_setlines(struct snd_i2c_bus
*bus
, int clk
, int data
)
130 struct snd_ice1712
*ice
= bus
->private_data
;
131 unsigned int val
= 0;
134 val
|= VT1724_REVO_I2C_CLOCK
;
136 val
|= VT1724_REVO_I2C_DATA
;
137 snd_ice1712_gpio_write_bits(ice
,
138 VT1724_REVO_I2C_DATA
|
139 VT1724_REVO_I2C_CLOCK
, val
);
143 static int revo_i2c_getdata(struct snd_i2c_bus
*bus
, int ack
)
145 struct snd_ice1712
*ice
= bus
->private_data
;
150 bit
= snd_ice1712_gpio_read_bits(ice
, VT1724_REVO_I2C_DATA
) ? 1 : 0;
154 static struct snd_i2c_bit_ops revo51_bit_ops
= {
155 .start
= revo_i2c_start
,
156 .stop
= revo_i2c_stop
,
157 .direction
= revo_i2c_direction
,
158 .setlines
= revo_i2c_setlines
,
159 .getdata
= revo_i2c_getdata
,
162 static int revo51_i2c_init(struct snd_ice1712
*ice
,
163 struct snd_pt2258
*pt
)
165 struct revo51_spec
*spec
;
168 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
173 /* create the I2C bus */
174 err
= snd_i2c_bus_create(ice
->card
, "ICE1724 GPIO6", NULL
, &ice
->i2c
);
178 ice
->i2c
->private_data
= ice
;
179 ice
->i2c
->hw_ops
.bit
= &revo51_bit_ops
;
181 /* create the I2C device */
182 err
= snd_i2c_device_create(ice
->i2c
, "PT2258", 0x40, &spec
->dev
);
186 pt
->card
= ice
->card
;
187 pt
->i2c_bus
= ice
->i2c
;
188 pt
->i2c_dev
= spec
->dev
;
191 snd_pt2258_reset(pt
);
197 * initialize the chips on M-Audio Revolution cards
200 #define AK_DAC(xname,xch) { .name = xname, .num_channels = xch }
202 static const struct snd_akm4xxx_dac_channel revo71_front
[] = {
204 .name
= "PCM Playback Volume",
206 /* front channels DAC supports muting */
207 .switch_name
= "PCM Playback Switch",
211 static const struct snd_akm4xxx_dac_channel revo71_surround
[] = {
212 AK_DAC("PCM Center Playback Volume", 1),
213 AK_DAC("PCM LFE Playback Volume", 1),
214 AK_DAC("PCM Side Playback Volume", 2),
215 AK_DAC("PCM Rear Playback Volume", 2),
218 static const struct snd_akm4xxx_dac_channel revo51_dac
[] = {
219 AK_DAC("PCM Playback Volume", 2),
220 AK_DAC("PCM Center Playback Volume", 1),
221 AK_DAC("PCM LFE Playback Volume", 1),
222 AK_DAC("PCM Rear Playback Volume", 2),
225 static const char *revo51_adc_input_names
[] = {
232 static const struct snd_akm4xxx_adc_channel revo51_adc
[] = {
234 .name
= "PCM Capture Volume",
235 .switch_name
= "PCM Capture Switch",
237 .input_names
= revo51_adc_input_names
241 static struct snd_akm4xxx akm_revo_front __devinitdata
= {
245 .set_rate_val
= revo_set_rate_val
247 .dac_info
= revo71_front
,
250 static struct snd_ak4xxx_private akm_revo_front_priv __devinitdata
= {
253 .data_mask
= VT1724_REVO_CDOUT
,
254 .clk_mask
= VT1724_REVO_CCLK
,
255 .cs_mask
= VT1724_REVO_CS0
| VT1724_REVO_CS1
| VT1724_REVO_CS2
,
256 .cs_addr
= VT1724_REVO_CS0
| VT1724_REVO_CS2
,
257 .cs_none
= VT1724_REVO_CS0
| VT1724_REVO_CS1
| VT1724_REVO_CS2
,
258 .add_flags
= VT1724_REVO_CCLK
, /* high at init */
262 static struct snd_akm4xxx akm_revo_surround __devinitdata
= {
267 .set_rate_val
= revo_set_rate_val
269 .dac_info
= revo71_surround
,
272 static struct snd_ak4xxx_private akm_revo_surround_priv __devinitdata
= {
275 .data_mask
= VT1724_REVO_CDOUT
,
276 .clk_mask
= VT1724_REVO_CCLK
,
277 .cs_mask
= VT1724_REVO_CS0
| VT1724_REVO_CS1
| VT1724_REVO_CS2
,
278 .cs_addr
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
279 .cs_none
= VT1724_REVO_CS0
| VT1724_REVO_CS1
| VT1724_REVO_CS2
,
280 .add_flags
= VT1724_REVO_CCLK
, /* high at init */
284 static struct snd_akm4xxx akm_revo51 __devinitdata
= {
288 .set_rate_val
= revo_set_rate_val
290 .dac_info
= revo51_dac
,
293 static struct snd_ak4xxx_private akm_revo51_priv __devinitdata
= {
296 .data_mask
= VT1724_REVO_CDOUT
,
297 .clk_mask
= VT1724_REVO_CCLK
,
298 .cs_mask
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
299 .cs_addr
= VT1724_REVO_CS1
,
300 .cs_none
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
301 .add_flags
= VT1724_REVO_CCLK
, /* high at init */
305 static struct snd_akm4xxx akm_revo51_adc __devinitdata
= {
308 .adc_info
= revo51_adc
,
311 static struct snd_ak4xxx_private akm_revo51_adc_priv __devinitdata
= {
314 .data_mask
= VT1724_REVO_CDOUT
,
315 .clk_mask
= VT1724_REVO_CCLK
,
316 .cs_mask
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
317 .cs_addr
= VT1724_REVO_CS0
,
318 .cs_none
= VT1724_REVO_CS0
| VT1724_REVO_CS1
,
319 .add_flags
= VT1724_REVO_CCLK
, /* high at init */
323 static struct snd_pt2258 ptc_revo51_volume
;
325 /* AK4358 for AP192 DAC, AK5385A for ADC */
326 static void ap192_set_rate_val(struct snd_akm4xxx
*ak
, unsigned int rate
)
328 struct snd_ice1712
*ice
= ak
->private_data
[0];
330 revo_set_rate_val(ak
, rate
);
332 #if 1 /* FIXME: do we need this procedure? */
333 /* reset DFS pin of AK5385A for ADC, too */
334 /* DFS0 (pin 18) -- GPIO10 pin 77 */
335 snd_ice1712_save_gpio_status(ice
);
336 snd_ice1712_gpio_write_bits(ice
, 1 << 10,
337 rate
> 48000 ? (1 << 10) : 0);
338 snd_ice1712_restore_gpio_status(ice
);
342 static const struct snd_akm4xxx_dac_channel ap192_dac
[] = {
343 AK_DAC("PCM Playback Volume", 2)
346 static struct snd_akm4xxx akm_ap192 __devinitdata
= {
350 .set_rate_val
= ap192_set_rate_val
352 .dac_info
= ap192_dac
,
355 static struct snd_ak4xxx_private akm_ap192_priv __devinitdata
= {
358 .data_mask
= VT1724_REVO_CDOUT
,
359 .clk_mask
= VT1724_REVO_CCLK
,
360 .cs_mask
= VT1724_REVO_CS0
| VT1724_REVO_CS3
,
361 .cs_addr
= VT1724_REVO_CS3
,
362 .cs_none
= VT1724_REVO_CS0
| VT1724_REVO_CS3
,
363 .add_flags
= VT1724_REVO_CCLK
, /* high at init */
368 /* FIXME: ak4114 makes the sound much lower due to some confliction,
369 * so let's disable it right now...
371 #define BUILD_AK4114_AP192
374 #ifdef BUILD_AK4114_AP192
375 /* AK4114 support on Audiophile 192 */
376 /* CDTO (pin 32) -- GPIO2 pin 52
377 * CDTI (pin 33) -- GPIO3 pin 53 (shared with AK4358)
378 * CCLK (pin 34) -- GPIO1 pin 51 (shared with AK4358)
379 * CSN (pin 35) -- GPIO7 pin 59
381 #define AK4114_ADDR 0x00
383 static void write_data(struct snd_ice1712
*ice
, unsigned int gpio
,
384 unsigned int data
, int idx
)
386 for (; idx
>= 0; idx
--) {
388 gpio
&= ~VT1724_REVO_CCLK
;
389 snd_ice1712_gpio_write(ice
, gpio
);
392 if (data
& (1 << idx
))
393 gpio
|= VT1724_REVO_CDOUT
;
395 gpio
&= ~VT1724_REVO_CDOUT
;
396 snd_ice1712_gpio_write(ice
, gpio
);
399 gpio
|= VT1724_REVO_CCLK
;
400 snd_ice1712_gpio_write(ice
, gpio
);
405 static unsigned char read_data(struct snd_ice1712
*ice
, unsigned int gpio
,
408 unsigned char data
= 0;
410 for (; idx
>= 0; idx
--) {
412 gpio
&= ~VT1724_REVO_CCLK
;
413 snd_ice1712_gpio_write(ice
, gpio
);
416 if (snd_ice1712_gpio_read(ice
) & VT1724_REVO_CDIN
)
420 gpio
|= VT1724_REVO_CCLK
;
421 snd_ice1712_gpio_write(ice
, gpio
);
427 static unsigned int ap192_4wire_start(struct snd_ice1712
*ice
)
431 snd_ice1712_save_gpio_status(ice
);
432 tmp
= snd_ice1712_gpio_read(ice
);
433 tmp
|= VT1724_REVO_CCLK
; /* high at init */
434 tmp
|= VT1724_REVO_CS0
;
435 tmp
&= ~VT1724_REVO_CS3
;
436 snd_ice1712_gpio_write(ice
, tmp
);
441 static void ap192_4wire_finish(struct snd_ice1712
*ice
, unsigned int tmp
)
443 tmp
|= VT1724_REVO_CS3
;
444 tmp
|= VT1724_REVO_CS0
;
445 snd_ice1712_gpio_write(ice
, tmp
);
447 snd_ice1712_restore_gpio_status(ice
);
450 static void ap192_ak4114_write(void *private_data
, unsigned char addr
,
453 struct snd_ice1712
*ice
= private_data
;
454 unsigned int tmp
, addrdata
;
456 tmp
= ap192_4wire_start(ice
);
457 addrdata
= (AK4114_ADDR
<< 6) | 0x20 | (addr
& 0x1f);
458 addrdata
= (addrdata
<< 8) | data
;
459 write_data(ice
, tmp
, addrdata
, 15);
460 ap192_4wire_finish(ice
, tmp
);
463 static unsigned char ap192_ak4114_read(void *private_data
, unsigned char addr
)
465 struct snd_ice1712
*ice
= private_data
;
469 tmp
= ap192_4wire_start(ice
);
470 write_data(ice
, tmp
, (AK4114_ADDR
<< 6) | (addr
& 0x1f), 7);
471 data
= read_data(ice
, tmp
, 7);
472 ap192_4wire_finish(ice
, tmp
);
476 static int __devinit
ap192_ak4114_init(struct snd_ice1712
*ice
)
478 static const unsigned char ak4114_init_vals
[] = {
479 AK4114_RST
| AK4114_PWN
| AK4114_OCKS0
| AK4114_OCKS1
,
482 AK4114_EFH_1024
| AK4114_DIT
| AK4114_IPS(1),
486 static const unsigned char ak4114_init_txcsb
[] = {
487 0x41, 0x02, 0x2c, 0x00, 0x00
492 return snd_ak4114_create(ice
->card
,
495 ak4114_init_vals
, ak4114_init_txcsb
,
498 #endif /* BUILD_AK4114_AP192 */
500 static int __devinit
revo_init(struct snd_ice1712
*ice
)
502 struct snd_akm4xxx
*ak
;
505 /* determine I2C, DACs and ADCs */
506 switch (ice
->eeprom
.subvendor
) {
507 case VT1724_SUBDEVICE_REVOLUTION71
:
508 ice
->num_total_dacs
= 8;
509 ice
->num_total_adcs
= 2;
510 ice
->gpio
.i2s_mclk_changed
= revo_i2s_mclk_changed
;
512 case VT1724_SUBDEVICE_REVOLUTION51
:
513 ice
->num_total_dacs
= 6;
514 ice
->num_total_adcs
= 2;
516 case VT1724_SUBDEVICE_AUDIOPHILE192
:
517 ice
->num_total_dacs
= 2;
518 ice
->num_total_adcs
= 2;
525 /* second stage of initialization, analog parts and others */
526 ak
= ice
->akm
= kcalloc(2, sizeof(struct snd_akm4xxx
), GFP_KERNEL
);
530 switch (ice
->eeprom
.subvendor
) {
531 case VT1724_SUBDEVICE_REVOLUTION71
:
533 if ((err
= snd_ice1712_akm4xxx_init(ak
, &akm_revo_front
, &akm_revo_front_priv
, ice
)) < 0)
535 if ((err
= snd_ice1712_akm4xxx_init(ak
+ 1, &akm_revo_surround
, &akm_revo_surround_priv
, ice
)) < 0)
537 /* unmute all codecs */
538 snd_ice1712_gpio_write_bits(ice
, VT1724_REVO_MUTE
, VT1724_REVO_MUTE
);
540 case VT1724_SUBDEVICE_REVOLUTION51
:
542 err
= snd_ice1712_akm4xxx_init(ak
, &akm_revo51
,
543 &akm_revo51_priv
, ice
);
546 err
= snd_ice1712_akm4xxx_init(ak
+1, &akm_revo51_adc
,
547 &akm_revo51_adc_priv
, ice
);
550 err
= revo51_i2c_init(ice
, &ptc_revo51_volume
);
553 /* unmute all codecs */
554 snd_ice1712_gpio_write_bits(ice
, VT1724_REVO_MUTE
,
557 case VT1724_SUBDEVICE_AUDIOPHILE192
:
559 err
= snd_ice1712_akm4xxx_init(ak
, &akm_ap192
, &akm_ap192_priv
,
571 static int __devinit
revo_add_controls(struct snd_ice1712
*ice
)
573 struct revo51_spec
*spec
;
576 switch (ice
->eeprom
.subvendor
) {
577 case VT1724_SUBDEVICE_REVOLUTION71
:
578 err
= snd_ice1712_akm4xxx_build_controls(ice
);
582 case VT1724_SUBDEVICE_REVOLUTION51
:
583 err
= snd_ice1712_akm4xxx_build_controls(ice
);
587 err
= snd_pt2258_build_controls(spec
->pt2258
);
591 case VT1724_SUBDEVICE_AUDIOPHILE192
:
592 err
= snd_ice1712_akm4xxx_build_controls(ice
);
595 #ifdef BUILD_AK4114_AP192
596 err
= ap192_ak4114_init(ice
);
606 struct snd_ice1712_card_info snd_vt1724_revo_cards
[] __devinitdata
= {
608 .subvendor
= VT1724_SUBDEVICE_REVOLUTION71
,
609 .name
= "M Audio Revolution-7.1",
611 .chip_init
= revo_init
,
612 .build_controls
= revo_add_controls
,
615 .subvendor
= VT1724_SUBDEVICE_REVOLUTION51
,
616 .name
= "M Audio Revolution-5.1",
618 .chip_init
= revo_init
,
619 .build_controls
= revo_add_controls
,
622 .subvendor
= VT1724_SUBDEVICE_AUDIOPHILE192
,
623 .name
= "M Audio Audiophile192",
625 .chip_init
= revo_init
,
626 .build_controls
= revo_add_controls
,