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 static void revo_i2s_mclk_changed(struct snd_ice1712 *ice)
37 /* assert PRST# to converters; MT05 bit 7 */
38 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
41 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
45 * change the rate of envy24HT, AK4355 and AK4381
47 static void revo_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
49 unsigned char old, tmp, dfs;
52 if (rate == 0) /* no hint - S/PDIF input is master, simply return */
55 /* adjust DFS on codecs */
58 else if (rate > 48000)
63 if (ak->type == SND_AK4355 || ak->type == SND_AK4358) {
70 tmp = snd_akm4xxx_get(ak, 0, reg);
71 old = (tmp >> shift) & 0x03;
76 snd_akm4xxx_reset(ak, 1);
77 tmp = snd_akm4xxx_get(ak, 0, reg);
78 tmp &= ~(0x03 << shift);
80 // snd_akm4xxx_write(ak, 0, reg, tmp);
81 snd_akm4xxx_set(ak, 0, reg, tmp); /* the value is written in reset(0) */
82 snd_akm4xxx_reset(ak, 0);
86 * I2C access to the PT2258 volume controller on GPIO 6/7 (Revolution 5.1)
89 static void revo_i2c_start(struct snd_i2c_bus *bus)
91 struct snd_ice1712 *ice = bus->private_data;
92 snd_ice1712_save_gpio_status(ice);
95 static void revo_i2c_stop(struct snd_i2c_bus *bus)
97 struct snd_ice1712 *ice = bus->private_data;
98 snd_ice1712_restore_gpio_status(ice);
101 static void revo_i2c_direction(struct snd_i2c_bus *bus, int clock, int data)
103 struct snd_ice1712 *ice = bus->private_data;
104 unsigned int mask, val;
108 val |= VT1724_REVO_I2C_CLOCK; /* write SCL */
110 val |= VT1724_REVO_I2C_DATA; /* write SDA */
111 mask = VT1724_REVO_I2C_CLOCK | VT1724_REVO_I2C_DATA;
112 ice->gpio.direction &= ~mask;
113 ice->gpio.direction |= val;
114 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
115 snd_ice1712_gpio_set_mask(ice, ~mask);
118 static void revo_i2c_setlines(struct snd_i2c_bus *bus, int clk, int data)
120 struct snd_ice1712 *ice = bus->private_data;
121 unsigned int val = 0;
124 val |= VT1724_REVO_I2C_CLOCK;
126 val |= VT1724_REVO_I2C_DATA;
127 snd_ice1712_gpio_write_bits(ice,
128 VT1724_REVO_I2C_DATA |
129 VT1724_REVO_I2C_CLOCK, val);
133 static int revo_i2c_getdata(struct snd_i2c_bus *bus, int ack)
135 struct snd_ice1712 *ice = bus->private_data;
140 bit = snd_ice1712_gpio_read_bits(ice, VT1724_REVO_I2C_DATA) ? 1 : 0;
144 static struct snd_i2c_bit_ops revo51_bit_ops = {
145 .start = revo_i2c_start,
146 .stop = revo_i2c_stop,
147 .direction = revo_i2c_direction,
148 .setlines = revo_i2c_setlines,
149 .getdata = revo_i2c_getdata,
152 static int revo51_i2c_init(struct snd_ice1712 *ice,
153 struct snd_pt2258 *pt)
157 /* create the I2C bus */
158 err = snd_i2c_bus_create(ice->card, "ICE1724 GPIO6", NULL, &ice->i2c);
162 ice->i2c->private_data = ice;
163 ice->i2c->hw_ops.bit = &revo51_bit_ops;
165 /* create the I2C device */
166 err = snd_i2c_device_create(ice->i2c, "PT2258", 0x40,
167 &ice->spec.revo51.dev);
171 pt->card = ice->card;
172 pt->i2c_bus = ice->i2c;
173 pt->i2c_dev = ice->spec.revo51.dev;
174 ice->spec.revo51.pt2258 = pt;
176 snd_pt2258_reset(pt);
182 * initialize the chips on M-Audio Revolution cards
185 #define AK_DAC(xname,xch) { .name = xname, .num_channels = xch }
187 static const struct snd_akm4xxx_dac_channel revo71_front[] = {
189 .name = "PCM Playback Volume",
191 /* front channels DAC supports muting */
192 .switch_name = "PCM Playback Switch",
196 static const struct snd_akm4xxx_dac_channel revo71_surround[] = {
197 AK_DAC("PCM Center Playback Volume", 1),
198 AK_DAC("PCM LFE Playback Volume", 1),
199 AK_DAC("PCM Side Playback Volume", 2),
200 AK_DAC("PCM Rear Playback Volume", 2),
203 static const struct snd_akm4xxx_dac_channel revo51_dac[] = {
204 AK_DAC("PCM Playback Volume", 2),
205 AK_DAC("PCM Center Playback Volume", 1),
206 AK_DAC("PCM LFE Playback Volume", 1),
207 AK_DAC("PCM Rear Playback Volume", 2),
210 static const char *revo51_adc_input_names[] = {
217 static const struct snd_akm4xxx_adc_channel revo51_adc[] = {
219 .name = "PCM Capture Volume",
220 .switch_name = "PCM Capture Switch",
222 .input_names = revo51_adc_input_names
226 static struct snd_akm4xxx akm_revo_front __devinitdata = {
230 .set_rate_val = revo_set_rate_val
232 .dac_info = revo71_front,
235 static struct snd_ak4xxx_private akm_revo_front_priv __devinitdata = {
238 .data_mask = VT1724_REVO_CDOUT,
239 .clk_mask = VT1724_REVO_CCLK,
240 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
241 .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS2,
242 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
243 .add_flags = VT1724_REVO_CCLK, /* high at init */
247 static struct snd_akm4xxx akm_revo_surround __devinitdata = {
252 .set_rate_val = revo_set_rate_val
254 .dac_info = revo71_surround,
257 static struct snd_ak4xxx_private akm_revo_surround_priv __devinitdata = {
260 .data_mask = VT1724_REVO_CDOUT,
261 .clk_mask = VT1724_REVO_CCLK,
262 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
263 .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS1,
264 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
265 .add_flags = VT1724_REVO_CCLK, /* high at init */
269 static struct snd_akm4xxx akm_revo51 __devinitdata = {
273 .set_rate_val = revo_set_rate_val
275 .dac_info = revo51_dac,
278 static struct snd_ak4xxx_private akm_revo51_priv __devinitdata = {
281 .data_mask = VT1724_REVO_CDOUT,
282 .clk_mask = VT1724_REVO_CCLK,
283 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1,
284 .cs_addr = VT1724_REVO_CS1,
285 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1,
286 .add_flags = VT1724_REVO_CCLK, /* high at init */
290 static struct snd_akm4xxx akm_revo51_adc __devinitdata = {
293 .adc_info = revo51_adc,
296 static struct snd_ak4xxx_private akm_revo51_adc_priv __devinitdata = {
299 .data_mask = VT1724_REVO_CDOUT,
300 .clk_mask = VT1724_REVO_CCLK,
301 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1,
302 .cs_addr = VT1724_REVO_CS0,
303 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1,
304 .add_flags = VT1724_REVO_CCLK, /* high at init */
308 static struct snd_pt2258 ptc_revo51_volume;
310 /* AK4358 for AP192 DAC, AK5385A for ADC */
311 static void ap192_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
313 struct snd_ice1712 *ice = ak->private_data[0];
315 revo_set_rate_val(ak, rate);
317 #if 1 /* FIXME: do we need this procedure? */
318 /* reset DFS pin of AK5385A for ADC, too */
319 /* DFS0 (pin 18) -- GPIO10 pin 77 */
320 snd_ice1712_save_gpio_status(ice);
321 snd_ice1712_gpio_write_bits(ice, 1 << 10,
322 rate > 48000 ? (1 << 10) : 0);
323 snd_ice1712_restore_gpio_status(ice);
327 static const struct snd_akm4xxx_dac_channel ap192_dac[] = {
328 AK_DAC("PCM Playback Volume", 2)
331 static struct snd_akm4xxx akm_ap192 __devinitdata = {
335 .set_rate_val = ap192_set_rate_val
337 .dac_info = ap192_dac,
340 static struct snd_ak4xxx_private akm_ap192_priv __devinitdata = {
343 .data_mask = VT1724_REVO_CDOUT,
344 .clk_mask = VT1724_REVO_CCLK,
345 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS3,
346 .cs_addr = VT1724_REVO_CS3,
347 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS3,
348 .add_flags = VT1724_REVO_CCLK, /* high at init */
353 /* FIXME: ak4114 makes the sound much lower due to some confliction,
354 * so let's disable it right now...
356 #define BUILD_AK4114_AP192
359 #ifdef BUILD_AK4114_AP192
360 /* AK4114 support on Audiophile 192 */
361 /* CDTO (pin 32) -- GPIO2 pin 52
362 * CDTI (pin 33) -- GPIO3 pin 53 (shared with AK4358)
363 * CCLK (pin 34) -- GPIO1 pin 51 (shared with AK4358)
364 * CSN (pin 35) -- GPIO7 pin 59
366 #define AK4114_ADDR 0x00
368 static void write_data(struct snd_ice1712 *ice, unsigned int gpio,
369 unsigned int data, int idx)
371 for (; idx >= 0; idx--) {
373 gpio &= ~VT1724_REVO_CCLK;
374 snd_ice1712_gpio_write(ice, gpio);
377 if (data & (1 << idx))
378 gpio |= VT1724_REVO_CDOUT;
380 gpio &= ~VT1724_REVO_CDOUT;
381 snd_ice1712_gpio_write(ice, gpio);
384 gpio |= VT1724_REVO_CCLK;
385 snd_ice1712_gpio_write(ice, gpio);
390 static unsigned char read_data(struct snd_ice1712 *ice, unsigned int gpio,
393 unsigned char data = 0;
395 for (; idx >= 0; idx--) {
397 gpio &= ~VT1724_REVO_CCLK;
398 snd_ice1712_gpio_write(ice, gpio);
401 if (snd_ice1712_gpio_read(ice) & VT1724_REVO_CDIN)
405 gpio |= VT1724_REVO_CCLK;
406 snd_ice1712_gpio_write(ice, gpio);
412 static unsigned int ap192_4wire_start(struct snd_ice1712 *ice)
416 snd_ice1712_save_gpio_status(ice);
417 tmp = snd_ice1712_gpio_read(ice);
418 tmp |= VT1724_REVO_CCLK; /* high at init */
419 tmp |= VT1724_REVO_CS0;
420 tmp &= ~VT1724_REVO_CS3;
421 snd_ice1712_gpio_write(ice, tmp);
426 static void ap192_4wire_finish(struct snd_ice1712 *ice, unsigned int tmp)
428 tmp |= VT1724_REVO_CS3;
429 tmp |= VT1724_REVO_CS0;
430 snd_ice1712_gpio_write(ice, tmp);
432 snd_ice1712_restore_gpio_status(ice);
435 static void ap192_ak4114_write(void *private_data, unsigned char addr,
438 struct snd_ice1712 *ice = private_data;
439 unsigned int tmp, addrdata;
441 tmp = ap192_4wire_start(ice);
442 addrdata = (AK4114_ADDR << 6) | 0x20 | (addr & 0x1f);
443 addrdata = (addrdata << 8) | data;
444 write_data(ice, tmp, addrdata, 15);
445 ap192_4wire_finish(ice, tmp);
448 static unsigned char ap192_ak4114_read(void *private_data, unsigned char addr)
450 struct snd_ice1712 *ice = private_data;
454 tmp = ap192_4wire_start(ice);
455 write_data(ice, tmp, (AK4114_ADDR << 6) | (addr & 0x1f), 7);
456 data = read_data(ice, tmp, 7);
457 ap192_4wire_finish(ice, tmp);
461 static int __devinit ap192_ak4114_init(struct snd_ice1712 *ice)
463 static const unsigned char ak4114_init_vals[] = {
464 AK4114_RST | AK4114_PWN | AK4114_OCKS0 | AK4114_OCKS1,
467 AK4114_EFH_1024 | AK4114_DIT | AK4114_IPS(1),
471 static const unsigned char ak4114_init_txcsb[] = {
472 0x41, 0x02, 0x2c, 0x00, 0x00
477 return snd_ak4114_create(ice->card,
480 ak4114_init_vals, ak4114_init_txcsb,
483 #endif /* BUILD_AK4114_AP192 */
485 static int __devinit revo_init(struct snd_ice1712 *ice)
487 struct snd_akm4xxx *ak;
490 /* determine I2C, DACs and ADCs */
491 switch (ice->eeprom.subvendor) {
492 case VT1724_SUBDEVICE_REVOLUTION71:
493 ice->num_total_dacs = 8;
494 ice->num_total_adcs = 2;
495 ice->gpio.i2s_mclk_changed = revo_i2s_mclk_changed;
497 case VT1724_SUBDEVICE_REVOLUTION51:
498 ice->num_total_dacs = 6;
499 ice->num_total_adcs = 2;
501 case VT1724_SUBDEVICE_AUDIOPHILE192:
502 ice->num_total_dacs = 2;
503 ice->num_total_adcs = 2;
510 /* second stage of initialization, analog parts and others */
511 ak = ice->akm = kcalloc(2, sizeof(struct snd_akm4xxx), GFP_KERNEL);
515 switch (ice->eeprom.subvendor) {
516 case VT1724_SUBDEVICE_REVOLUTION71:
518 if ((err = snd_ice1712_akm4xxx_init(ak, &akm_revo_front, &akm_revo_front_priv, ice)) < 0)
520 if ((err = snd_ice1712_akm4xxx_init(ak + 1, &akm_revo_surround, &akm_revo_surround_priv, ice)) < 0)
522 /* unmute all codecs */
523 snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE);
525 case VT1724_SUBDEVICE_REVOLUTION51:
527 err = snd_ice1712_akm4xxx_init(ak, &akm_revo51,
528 &akm_revo51_priv, ice);
531 err = snd_ice1712_akm4xxx_init(ak+1, &akm_revo51_adc,
532 &akm_revo51_adc_priv, ice);
535 err = revo51_i2c_init(ice, &ptc_revo51_volume);
538 /* unmute all codecs */
539 snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE,
542 case VT1724_SUBDEVICE_AUDIOPHILE192:
544 err = snd_ice1712_akm4xxx_init(ak, &akm_ap192, &akm_ap192_priv,
556 static int __devinit revo_add_controls(struct snd_ice1712 *ice)
560 switch (ice->eeprom.subvendor) {
561 case VT1724_SUBDEVICE_REVOLUTION71:
562 err = snd_ice1712_akm4xxx_build_controls(ice);
566 case VT1724_SUBDEVICE_REVOLUTION51:
567 err = snd_ice1712_akm4xxx_build_controls(ice);
570 err = snd_pt2258_build_controls(ice->spec.revo51.pt2258);
574 case VT1724_SUBDEVICE_AUDIOPHILE192:
575 err = snd_ice1712_akm4xxx_build_controls(ice);
578 #ifdef BUILD_AK4114_AP192
579 err = ap192_ak4114_init(ice);
589 struct snd_ice1712_card_info snd_vt1724_revo_cards[] __devinitdata = {
591 .subvendor = VT1724_SUBDEVICE_REVOLUTION71,
592 .name = "M Audio Revolution-7.1",
594 .chip_init = revo_init,
595 .build_controls = revo_add_controls,
598 .subvendor = VT1724_SUBDEVICE_REVOLUTION51,
599 .name = "M Audio Revolution-5.1",
601 .chip_init = revo_init,
602 .build_controls = revo_add_controls,
605 .subvendor = VT1724_SUBDEVICE_AUDIOPHILE192,
606 .name = "M Audio Audiophile192",
608 .chip_init = revo_init,
609 .build_controls = revo_add_controls,