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
24 #include <sound/driver.h>
26 #include <linux/delay.h>
27 #include <linux/interrupt.h>
28 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <sound/core.h>
36 static void revo_i2s_mclk_changed(struct snd_ice1712 *ice)
38 /* assert PRST# to converters; MT05 bit 7 */
39 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
42 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
46 * change the rate of envy24HT, AK4355 and AK4381
48 static void revo_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
50 unsigned char old, tmp, dfs;
53 if (rate == 0) /* no hint - S/PDIF input is master, simply return */
56 /* adjust DFS on codecs */
59 else if (rate > 48000)
64 if (ak->type == SND_AK4355 || ak->type == SND_AK4358) {
71 tmp = snd_akm4xxx_get(ak, 0, reg);
72 old = (tmp >> shift) & 0x03;
77 snd_akm4xxx_reset(ak, 1);
78 tmp = snd_akm4xxx_get(ak, 0, reg);
79 tmp &= ~(0x03 << shift);
81 // snd_akm4xxx_write(ak, 0, reg, tmp);
82 snd_akm4xxx_set(ak, 0, reg, tmp); /* the value is written in reset(0) */
83 snd_akm4xxx_reset(ak, 0);
87 * I2C access to the PT2258 volume controller on GPIO 6/7 (Revolution 5.1)
90 static void revo_i2c_start(struct snd_i2c_bus *bus)
92 struct snd_ice1712 *ice = bus->private_data;
93 snd_ice1712_save_gpio_status(ice);
96 static void revo_i2c_stop(struct snd_i2c_bus *bus)
98 struct snd_ice1712 *ice = bus->private_data;
99 snd_ice1712_restore_gpio_status(ice);
102 static void revo_i2c_direction(struct snd_i2c_bus *bus, int clock, int data)
104 struct snd_ice1712 *ice = bus->private_data;
105 unsigned int mask, val;
109 val |= VT1724_REVO_I2C_CLOCK; /* write SCL */
111 val |= VT1724_REVO_I2C_DATA; /* write SDA */
112 mask = VT1724_REVO_I2C_CLOCK | VT1724_REVO_I2C_DATA;
113 ice->gpio.direction &= ~mask;
114 ice->gpio.direction |= val;
115 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
116 snd_ice1712_gpio_set_mask(ice, ~mask);
119 static void revo_i2c_setlines(struct snd_i2c_bus *bus, int clk, int data)
121 struct snd_ice1712 *ice = bus->private_data;
122 unsigned int val = 0;
125 val |= VT1724_REVO_I2C_CLOCK;
127 val |= VT1724_REVO_I2C_DATA;
128 snd_ice1712_gpio_write_bits(ice,
129 VT1724_REVO_I2C_DATA |
130 VT1724_REVO_I2C_CLOCK, val);
134 static int revo_i2c_getdata(struct snd_i2c_bus *bus, int ack)
136 struct snd_ice1712 *ice = bus->private_data;
141 bit = snd_ice1712_gpio_read_bits(ice, VT1724_REVO_I2C_DATA) ? 1 : 0;
145 static struct snd_i2c_bit_ops revo51_bit_ops = {
146 .start = revo_i2c_start,
147 .stop = revo_i2c_stop,
148 .direction = revo_i2c_direction,
149 .setlines = revo_i2c_setlines,
150 .getdata = revo_i2c_getdata,
153 static int revo51_i2c_init(struct snd_ice1712 *ice,
154 struct snd_pt2258 *pt)
158 /* create the I2C bus */
159 err = snd_i2c_bus_create(ice->card, "ICE1724 GPIO6", NULL, &ice->i2c);
163 ice->i2c->private_data = ice;
164 ice->i2c->hw_ops.bit = &revo51_bit_ops;
166 /* create the I2C device */
167 err = snd_i2c_device_create(ice->i2c, "PT2258", 0x40,
168 &ice->spec.revo51.dev);
172 pt->card = ice->card;
173 pt->i2c_bus = ice->i2c;
174 pt->i2c_dev = ice->spec.revo51.dev;
175 ice->spec.revo51.pt2258 = pt;
177 snd_pt2258_reset(pt);
183 * initialize the chips on M-Audio Revolution cards
186 #define AK_DAC(xname,xch) { .name = xname, .num_channels = xch }
188 static const struct snd_akm4xxx_dac_channel revo71_front[] = {
190 .name = "PCM Playback Volume",
192 /* front channels DAC supports muting */
193 .switch_name = "PCM Playback Switch",
197 static const struct snd_akm4xxx_dac_channel revo71_surround[] = {
198 AK_DAC("PCM Center Playback Volume", 1),
199 AK_DAC("PCM LFE Playback Volume", 1),
200 AK_DAC("PCM Side Playback Volume", 2),
201 AK_DAC("PCM Rear Playback Volume", 2),
204 static const struct snd_akm4xxx_dac_channel revo51_dac[] = {
205 AK_DAC("PCM Playback Volume", 2),
206 AK_DAC("PCM Center Playback Volume", 1),
207 AK_DAC("PCM LFE Playback Volume", 1),
208 AK_DAC("PCM Rear Playback Volume", 2),
211 static const char *revo51_adc_input_names[] = {
218 static const struct snd_akm4xxx_adc_channel revo51_adc[] = {
220 .name = "PCM Capture Volume",
221 .switch_name = "PCM Capture Switch",
223 .input_names = revo51_adc_input_names
227 static struct snd_akm4xxx akm_revo_front __devinitdata = {
231 .set_rate_val = revo_set_rate_val
233 .dac_info = revo71_front,
236 static struct snd_ak4xxx_private akm_revo_front_priv __devinitdata = {
239 .data_mask = VT1724_REVO_CDOUT,
240 .clk_mask = VT1724_REVO_CCLK,
241 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
242 .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS2,
243 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
244 .add_flags = VT1724_REVO_CCLK, /* high at init */
248 static struct snd_akm4xxx akm_revo_surround __devinitdata = {
253 .set_rate_val = revo_set_rate_val
255 .dac_info = revo71_surround,
258 static struct snd_ak4xxx_private akm_revo_surround_priv __devinitdata = {
261 .data_mask = VT1724_REVO_CDOUT,
262 .clk_mask = VT1724_REVO_CCLK,
263 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
264 .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS1,
265 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
266 .add_flags = VT1724_REVO_CCLK, /* high at init */
270 static struct snd_akm4xxx akm_revo51 __devinitdata = {
274 .set_rate_val = revo_set_rate_val
276 .dac_info = revo51_dac,
279 static struct snd_ak4xxx_private akm_revo51_priv __devinitdata = {
282 .data_mask = VT1724_REVO_CDOUT,
283 .clk_mask = VT1724_REVO_CCLK,
284 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1,
285 .cs_addr = VT1724_REVO_CS1,
286 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1,
287 .add_flags = VT1724_REVO_CCLK, /* high at init */
291 static struct snd_akm4xxx akm_revo51_adc __devinitdata = {
294 .adc_info = revo51_adc,
297 static struct snd_ak4xxx_private akm_revo51_adc_priv __devinitdata = {
300 .data_mask = VT1724_REVO_CDOUT,
301 .clk_mask = VT1724_REVO_CCLK,
302 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1,
303 .cs_addr = VT1724_REVO_CS0,
304 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1,
305 .add_flags = VT1724_REVO_CCLK, /* high at init */
309 static struct snd_pt2258 ptc_revo51_volume;
311 /* AK4358 for AP192 DAC, AK5385A for ADC */
312 static void ap192_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
314 struct snd_ice1712 *ice = ak->private_data[0];
316 revo_set_rate_val(ak, rate);
318 #if 1 /* FIXME: do we need this procedure? */
319 /* reset DFS pin of AK5385A for ADC, too */
320 /* DFS0 (pin 18) -- GPIO10 pin 77 */
321 snd_ice1712_save_gpio_status(ice);
322 snd_ice1712_gpio_write_bits(ice, 1 << 10,
323 rate > 48000 ? (1 << 10) : 0);
324 snd_ice1712_restore_gpio_status(ice);
328 static const struct snd_akm4xxx_dac_channel ap192_dac[] = {
329 AK_DAC("PCM Playback Volume", 2)
332 static struct snd_akm4xxx akm_ap192 __devinitdata = {
336 .set_rate_val = ap192_set_rate_val
338 .dac_info = ap192_dac,
341 static struct snd_ak4xxx_private akm_ap192_priv __devinitdata = {
344 .data_mask = VT1724_REVO_CDOUT,
345 .clk_mask = VT1724_REVO_CCLK,
346 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS3,
347 .cs_addr = VT1724_REVO_CS3,
348 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS3,
349 .add_flags = VT1724_REVO_CCLK, /* high at init */
354 /* FIXME: ak4114 makes the sound much lower due to some confliction,
355 * so let's disable it right now...
357 #define BUILD_AK4114_AP192
360 #ifdef BUILD_AK4114_AP192
361 /* AK4114 support on Audiophile 192 */
362 /* CDTO (pin 32) -- GPIO2 pin 52
363 * CDTI (pin 33) -- GPIO3 pin 53 (shared with AK4358)
364 * CCLK (pin 34) -- GPIO1 pin 51 (shared with AK4358)
365 * CSN (pin 35) -- GPIO7 pin 59
367 #define AK4114_ADDR 0x00
369 static void write_data(struct snd_ice1712 *ice, unsigned int gpio,
370 unsigned int data, int idx)
372 for (; idx >= 0; idx--) {
374 gpio &= ~VT1724_REVO_CCLK;
375 snd_ice1712_gpio_write(ice, gpio);
378 if (data & (1 << idx))
379 gpio |= VT1724_REVO_CDOUT;
381 gpio &= ~VT1724_REVO_CDOUT;
382 snd_ice1712_gpio_write(ice, gpio);
385 gpio |= VT1724_REVO_CCLK;
386 snd_ice1712_gpio_write(ice, gpio);
391 static unsigned char read_data(struct snd_ice1712 *ice, unsigned int gpio,
394 unsigned char data = 0;
396 for (; idx >= 0; idx--) {
398 gpio &= ~VT1724_REVO_CCLK;
399 snd_ice1712_gpio_write(ice, gpio);
402 if (snd_ice1712_gpio_read(ice) & VT1724_REVO_CDIN)
406 gpio |= VT1724_REVO_CCLK;
407 snd_ice1712_gpio_write(ice, gpio);
413 static unsigned int ap192_4wire_start(struct snd_ice1712 *ice)
417 snd_ice1712_save_gpio_status(ice);
418 tmp = snd_ice1712_gpio_read(ice);
419 tmp |= VT1724_REVO_CCLK; /* high at init */
420 tmp |= VT1724_REVO_CS0;
421 tmp &= ~VT1724_REVO_CS3;
422 snd_ice1712_gpio_write(ice, tmp);
427 static void ap192_4wire_finish(struct snd_ice1712 *ice, unsigned int tmp)
429 tmp |= VT1724_REVO_CS3;
430 tmp |= VT1724_REVO_CS0;
431 snd_ice1712_gpio_write(ice, tmp);
433 snd_ice1712_restore_gpio_status(ice);
436 static void ap192_ak4114_write(void *private_data, unsigned char addr,
439 struct snd_ice1712 *ice = private_data;
440 unsigned int tmp, addrdata;
442 tmp = ap192_4wire_start(ice);
443 addrdata = (AK4114_ADDR << 6) | 0x20 | (addr & 0x1f);
444 addrdata = (addrdata << 8) | data;
445 write_data(ice, tmp, addrdata, 15);
446 ap192_4wire_finish(ice, tmp);
449 static unsigned char ap192_ak4114_read(void *private_data, unsigned char addr)
451 struct snd_ice1712 *ice = private_data;
455 tmp = ap192_4wire_start(ice);
456 write_data(ice, tmp, (AK4114_ADDR << 6) | (addr & 0x1f), 7);
457 data = read_data(ice, tmp, 7);
458 ap192_4wire_finish(ice, tmp);
462 static int __devinit ap192_ak4114_init(struct snd_ice1712 *ice)
464 static const unsigned char ak4114_init_vals[] = {
465 AK4114_RST | AK4114_PWN | AK4114_OCKS0 | AK4114_OCKS1,
468 AK4114_EFH_1024 | AK4114_DIT | AK4114_IPS(1),
472 static const unsigned char ak4114_init_txcsb[] = {
473 0x41, 0x02, 0x2c, 0x00, 0x00
478 return snd_ak4114_create(ice->card,
481 ak4114_init_vals, ak4114_init_txcsb,
484 #endif /* BUILD_AK4114_AP192 */
486 static int __devinit revo_init(struct snd_ice1712 *ice)
488 struct snd_akm4xxx *ak;
491 /* determine I2C, DACs and ADCs */
492 switch (ice->eeprom.subvendor) {
493 case VT1724_SUBDEVICE_REVOLUTION71:
494 ice->num_total_dacs = 8;
495 ice->num_total_adcs = 2;
496 ice->gpio.i2s_mclk_changed = revo_i2s_mclk_changed;
498 case VT1724_SUBDEVICE_REVOLUTION51:
499 ice->num_total_dacs = 6;
500 ice->num_total_adcs = 2;
502 case VT1724_SUBDEVICE_AUDIOPHILE192:
503 ice->num_total_dacs = 2;
504 ice->num_total_adcs = 2;
511 /* second stage of initialization, analog parts and others */
512 ak = ice->akm = kcalloc(2, sizeof(struct snd_akm4xxx), GFP_KERNEL);
516 switch (ice->eeprom.subvendor) {
517 case VT1724_SUBDEVICE_REVOLUTION71:
519 if ((err = snd_ice1712_akm4xxx_init(ak, &akm_revo_front, &akm_revo_front_priv, ice)) < 0)
521 if ((err = snd_ice1712_akm4xxx_init(ak + 1, &akm_revo_surround, &akm_revo_surround_priv, ice)) < 0)
523 /* unmute all codecs */
524 snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE);
526 case VT1724_SUBDEVICE_REVOLUTION51:
528 err = snd_ice1712_akm4xxx_init(ak, &akm_revo51,
529 &akm_revo51_priv, ice);
532 err = snd_ice1712_akm4xxx_init(ak+1, &akm_revo51_adc,
533 &akm_revo51_adc_priv, ice);
536 err = revo51_i2c_init(ice, &ptc_revo51_volume);
539 /* unmute all codecs */
540 snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE,
543 case VT1724_SUBDEVICE_AUDIOPHILE192:
545 err = snd_ice1712_akm4xxx_init(ak, &akm_ap192, &akm_ap192_priv,
557 static int __devinit revo_add_controls(struct snd_ice1712 *ice)
561 switch (ice->eeprom.subvendor) {
562 case VT1724_SUBDEVICE_REVOLUTION71:
563 err = snd_ice1712_akm4xxx_build_controls(ice);
567 case VT1724_SUBDEVICE_REVOLUTION51:
568 err = snd_ice1712_akm4xxx_build_controls(ice);
571 err = snd_pt2258_build_controls(ice->spec.revo51.pt2258);
575 case VT1724_SUBDEVICE_AUDIOPHILE192:
576 err = snd_ice1712_akm4xxx_build_controls(ice);
579 #ifdef BUILD_AK4114_AP192
580 err = ap192_ak4114_init(ice);
590 struct snd_ice1712_card_info snd_vt1724_revo_cards[] __devinitdata = {
592 .subvendor = VT1724_SUBDEVICE_REVOLUTION71,
593 .name = "M Audio Revolution-7.1",
595 .chip_init = revo_init,
596 .build_controls = revo_add_controls,
599 .subvendor = VT1724_SUBDEVICE_REVOLUTION51,
600 .name = "M Audio Revolution-5.1",
602 .chip_init = revo_init,
603 .build_controls = revo_add_controls,
606 .subvendor = VT1724_SUBDEVICE_AUDIOPHILE192,
607 .name = "M Audio Audiophile192",
609 .chip_init = revo_init,
610 .build_controls = revo_add_controls,