blob: d18a31e188a9a594ccbe8b0ed22a487bec783703 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ALSA driver for ICEnsemble ICE1712 (Envy24)
3 *
4 * Lowlevel functions for M-Audio Revolution 7.1
5 *
6 * Copyright (c) 2003 Takashi Iwai <tiwai@suse.de>
7 *
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.
12 *
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.
17 *
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
21 *
22 */
23
24#include <sound/driver.h>
25#include <asm/io.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>
31
32#include "ice1712.h"
33#include "envy24ht.h"
34#include "revo.h"
35
Takashi Iwaiab0c7d72005-11-17 15:00:18 +010036static void revo_i2s_mclk_changed(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
38 /* assert PRST# to converters; MT05 bit 7 */
39 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
40 mdelay(5);
41 /* deassert PRST# */
42 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
43}
44
45/*
46 * change the rate of envy24HT, AK4355 and AK4381
47 */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +010048static void revo_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
50 unsigned char old, tmp, dfs;
51 int reg, shift;
52
53 if (rate == 0) /* no hint - S/PDIF input is master, simply return */
54 return;
55
56 /* adjust DFS on codecs */
57 if (rate > 96000)
58 dfs = 2;
59 else if (rate > 48000)
60 dfs = 1;
61 else
62 dfs = 0;
63
Takashi Iwai59acf762005-12-05 19:22:34 +010064 if (ak->type == SND_AK4355 || ak->type == SND_AK4358) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 reg = 2;
66 shift = 4;
67 } else {
68 reg = 1;
69 shift = 3;
70 }
71 tmp = snd_akm4xxx_get(ak, 0, reg);
72 old = (tmp >> shift) & 0x03;
73 if (old == dfs)
74 return;
75
76 /* reset DFS */
77 snd_akm4xxx_reset(ak, 1);
78 tmp = snd_akm4xxx_get(ak, 0, reg);
79 tmp &= ~(0x03 << shift);
80 tmp |= dfs << 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);
84}
85
86/*
Jochen Vossfeaa6a72006-10-04 18:08:43 +020087 * I2C access to the PT2258 volume controller on GPIO 6/7 (Revolution 5.1)
88 */
89
90static void revo_i2c_start(struct snd_i2c_bus *bus)
91{
92 struct snd_ice1712 *ice = bus->private_data;
93 snd_ice1712_save_gpio_status(ice);
94}
95
96static void revo_i2c_stop(struct snd_i2c_bus *bus)
97{
98 struct snd_ice1712 *ice = bus->private_data;
99 snd_ice1712_restore_gpio_status(ice);
100}
101
102static void revo_i2c_direction(struct snd_i2c_bus *bus, int clock, int data)
103{
104 struct snd_ice1712 *ice = bus->private_data;
105 unsigned int mask, val;
106
107 val = 0;
108 if (clock)
109 val |= VT1724_REVO_I2C_CLOCK; /* write SCL */
110 if (data)
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);
117}
118
119static void revo_i2c_setlines(struct snd_i2c_bus *bus, int clk, int data)
120{
121 struct snd_ice1712 *ice = bus->private_data;
122 unsigned int val = 0;
123
124 if (clk)
125 val |= VT1724_REVO_I2C_CLOCK;
126 if (data)
127 val |= VT1724_REVO_I2C_DATA;
128 snd_ice1712_gpio_write_bits(ice,
129 VT1724_REVO_I2C_DATA |
130 VT1724_REVO_I2C_CLOCK, val);
131 udelay(5);
132}
133
134static int revo_i2c_getdata(struct snd_i2c_bus *bus, int ack)
135{
136 struct snd_ice1712 *ice = bus->private_data;
137 int bit;
138
139 if (ack)
140 udelay(5);
141 bit = snd_ice1712_gpio_read_bits(ice, VT1724_REVO_I2C_DATA) ? 1 : 0;
142 return bit;
143}
144
145static 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,
151};
152
153static int revo51_i2c_init(struct snd_ice1712 *ice,
154 struct snd_pt2258 *pt)
155{
156 int err;
157
158 /* create the I2C bus */
159 err = snd_i2c_bus_create(ice->card, "ICE1724 GPIO6", NULL, &ice->i2c);
160 if (err < 0)
161 return err;
162
163 ice->i2c->private_data = ice;
164 ice->i2c->hw_ops.bit = &revo51_bit_ops;
165
166 /* create the I2C device */
167 err = snd_i2c_device_create(ice->i2c, "PT2258", 0x40,
168 &ice->spec.revo51.dev);
169 if (err < 0)
170 return err;
171
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;
176
177 snd_pt2258_reset(pt);
178
179 return 0;
180}
181
182/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 * initialize the chips on M-Audio Revolution cards
184 */
185
Takashi Iwai723b2b02006-08-30 16:49:54 +0200186#define AK_DAC(xname,xch) { .name = xname, .num_channels = xch }
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200187
Takashi Iwai517400c2007-01-29 15:27:56 +0100188static const struct snd_akm4xxx_dac_channel revo71_front[] = {
Pavel Hofmanea7cfcd2007-05-19 17:21:04 +0200189 {
190 .name = "PCM Playback Volume",
191 .num_channels = 2,
192 /* front channels DAC supports muting */
193 .switch_name = "PCM Playback Switch",
194 },
Takashi Iwai723b2b02006-08-30 16:49:54 +0200195};
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200196
Takashi Iwai517400c2007-01-29 15:27:56 +0100197static const struct snd_akm4xxx_dac_channel revo71_surround[] = {
Takashi Iwai723b2b02006-08-30 16:49:54 +0200198 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),
202};
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200203
Takashi Iwai517400c2007-01-29 15:27:56 +0100204static const struct snd_akm4xxx_dac_channel revo51_dac[] = {
Takashi Iwai723b2b02006-08-30 16:49:54 +0200205 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),
209};
210
Jochen Vossa58e7cb2006-10-04 18:04:10 +0200211static const char *revo51_adc_input_names[] = {
212 "Mic",
213 "Line",
214 "CD",
215 NULL
216};
217
Takashi Iwai517400c2007-01-29 15:27:56 +0100218static const struct snd_akm4xxx_adc_channel revo51_adc[] = {
Takashi Iwai723b2b02006-08-30 16:49:54 +0200219 {
220 .name = "PCM Capture Volume",
Takashi Iwai723b2b02006-08-30 16:49:54 +0200221 .switch_name = "PCM Capture Switch",
Jochen Vossa58e7cb2006-10-04 18:04:10 +0200222 .num_channels = 2,
223 .input_names = revo51_adc_input_names
Takashi Iwai723b2b02006-08-30 16:49:54 +0200224 },
225};
Jochen Voss96d9e932006-08-08 21:13:42 +0200226
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100227static struct snd_akm4xxx akm_revo_front __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 .type = SND_AK4381,
229 .num_dacs = 2,
230 .ops = {
231 .set_rate_val = revo_set_rate_val
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200232 },
Takashi Iwai723b2b02006-08-30 16:49:54 +0200233 .dac_info = revo71_front,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234};
235
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100236static struct snd_ak4xxx_private akm_revo_front_priv __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 .caddr = 1,
238 .cif = 0,
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 */
245 .mask_flags = 0,
246};
247
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100248static struct snd_akm4xxx akm_revo_surround __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 .type = SND_AK4355,
250 .idx_offset = 1,
251 .num_dacs = 6,
252 .ops = {
253 .set_rate_val = revo_set_rate_val
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200254 },
Takashi Iwai723b2b02006-08-30 16:49:54 +0200255 .dac_info = revo71_surround,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256};
257
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100258static struct snd_ak4xxx_private akm_revo_surround_priv __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 .caddr = 3,
260 .cif = 0,
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 */
267 .mask_flags = 0,
268};
269
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100270static struct snd_akm4xxx akm_revo51 __devinitdata = {
Takashi Iwai59acf762005-12-05 19:22:34 +0100271 .type = SND_AK4358,
272 .num_dacs = 6,
273 .ops = {
274 .set_rate_val = revo_set_rate_val
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200275 },
Takashi Iwai723b2b02006-08-30 16:49:54 +0200276 .dac_info = revo51_dac,
Takashi Iwai59acf762005-12-05 19:22:34 +0100277};
278
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100279static struct snd_ak4xxx_private akm_revo51_priv __devinitdata = {
Takashi Iwai59acf762005-12-05 19:22:34 +0100280 .caddr = 2,
281 .cif = 0,
282 .data_mask = VT1724_REVO_CDOUT,
283 .clk_mask = VT1724_REVO_CCLK,
Jochen Vossfeaa6a72006-10-04 18:08:43 +0200284 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1,
285 .cs_addr = VT1724_REVO_CS1,
286 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1,
Jochen Voss96d9e932006-08-08 21:13:42 +0200287 .add_flags = VT1724_REVO_CCLK, /* high at init */
288 .mask_flags = 0,
289};
290
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100291static struct snd_akm4xxx akm_revo51_adc __devinitdata = {
Jochen Voss96d9e932006-08-08 21:13:42 +0200292 .type = SND_AK5365,
293 .num_adcs = 2,
Takashi Iwai723b2b02006-08-30 16:49:54 +0200294 .adc_info = revo51_adc,
Jochen Voss96d9e932006-08-08 21:13:42 +0200295};
296
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100297static struct snd_ak4xxx_private akm_revo51_adc_priv __devinitdata = {
Jochen Voss96d9e932006-08-08 21:13:42 +0200298 .caddr = 2,
299 .cif = 0,
300 .data_mask = VT1724_REVO_CDOUT,
301 .clk_mask = VT1724_REVO_CCLK,
Jochen Vossfeaa6a72006-10-04 18:08:43 +0200302 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1,
303 .cs_addr = VT1724_REVO_CS0,
304 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1,
Takashi Iwai59acf762005-12-05 19:22:34 +0100305 .add_flags = VT1724_REVO_CCLK, /* high at init */
306 .mask_flags = 0,
307};
308
Jochen Vossfeaa6a72006-10-04 18:08:43 +0200309static struct snd_pt2258 ptc_revo51_volume;
310
Takashi Iwai56255062006-11-09 16:47:26 +0100311/* AK4358 for AP192 DAC, AK5385A for ADC */
312static void ap192_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
313{
314 struct snd_ice1712 *ice = ak->private_data[0];
315
316 revo_set_rate_val(ak, rate);
317
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);
325#endif
326}
327
Takashi Iwai517400c2007-01-29 15:27:56 +0100328static const struct snd_akm4xxx_dac_channel ap192_dac[] = {
Takashi Iwai56255062006-11-09 16:47:26 +0100329 AK_DAC("PCM Playback Volume", 2)
330};
331
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100332static struct snd_akm4xxx akm_ap192 __devinitdata = {
Takashi Iwai56255062006-11-09 16:47:26 +0100333 .type = SND_AK4358,
334 .num_dacs = 2,
335 .ops = {
336 .set_rate_val = ap192_set_rate_val
337 },
338 .dac_info = ap192_dac,
339};
340
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100341static struct snd_ak4xxx_private akm_ap192_priv __devinitdata = {
Takashi Iwai56255062006-11-09 16:47:26 +0100342 .caddr = 2,
343 .cif = 0,
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 */
350 .mask_flags = 0,
351};
352
353#if 0
354/* FIXME: ak4114 makes the sound much lower due to some confliction,
355 * so let's disable it right now...
356 */
357#define BUILD_AK4114_AP192
358#endif
359
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
366 */
367#define AK4114_ADDR 0x00
368
369static void write_data(struct snd_ice1712 *ice, unsigned int gpio,
370 unsigned int data, int idx)
371{
372 for (; idx >= 0; idx--) {
373 /* drop clock */
374 gpio &= ~VT1724_REVO_CCLK;
375 snd_ice1712_gpio_write(ice, gpio);
376 udelay(1);
377 /* set data */
378 if (data & (1 << idx))
379 gpio |= VT1724_REVO_CDOUT;
380 else
381 gpio &= ~VT1724_REVO_CDOUT;
382 snd_ice1712_gpio_write(ice, gpio);
383 udelay(1);
384 /* raise clock */
385 gpio |= VT1724_REVO_CCLK;
386 snd_ice1712_gpio_write(ice, gpio);
387 udelay(1);
388 }
389}
390
391static unsigned char read_data(struct snd_ice1712 *ice, unsigned int gpio,
392 int idx)
393{
394 unsigned char data = 0;
395
396 for (; idx >= 0; idx--) {
397 /* drop clock */
398 gpio &= ~VT1724_REVO_CCLK;
399 snd_ice1712_gpio_write(ice, gpio);
400 udelay(1);
401 /* read data */
402 if (snd_ice1712_gpio_read(ice) & VT1724_REVO_CDIN)
403 data |= (1 << idx);
404 udelay(1);
405 /* raise clock */
406 gpio |= VT1724_REVO_CCLK;
407 snd_ice1712_gpio_write(ice, gpio);
408 udelay(1);
409 }
410 return data;
411}
412
Takashi Iwaic052f042007-03-29 12:34:15 +0200413static unsigned int ap192_4wire_start(struct snd_ice1712 *ice)
Takashi Iwai56255062006-11-09 16:47:26 +0100414{
415 unsigned int tmp;
416
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);
423 udelay(1);
424 return tmp;
425}
426
427static void ap192_4wire_finish(struct snd_ice1712 *ice, unsigned int tmp)
428{
429 tmp |= VT1724_REVO_CS3;
430 tmp |= VT1724_REVO_CS0;
431 snd_ice1712_gpio_write(ice, tmp);
432 udelay(1);
433 snd_ice1712_restore_gpio_status(ice);
434}
435
436static void ap192_ak4114_write(void *private_data, unsigned char addr,
437 unsigned char data)
438{
439 struct snd_ice1712 *ice = private_data;
440 unsigned int tmp, addrdata;
441
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);
447}
448
449static unsigned char ap192_ak4114_read(void *private_data, unsigned char addr)
450{
451 struct snd_ice1712 *ice = private_data;
452 unsigned int tmp;
453 unsigned char data;
454
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);
459 return data;
460}
461
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100462static int __devinit ap192_ak4114_init(struct snd_ice1712 *ice)
Takashi Iwai56255062006-11-09 16:47:26 +0100463{
Takashi Iwai32b47da2007-01-29 15:26:36 +0100464 static const unsigned char ak4114_init_vals[] = {
Takashi Iwai56255062006-11-09 16:47:26 +0100465 AK4114_RST | AK4114_PWN | AK4114_OCKS0 | AK4114_OCKS1,
466 AK4114_DIF_I24I2S,
467 AK4114_TX1E,
468 AK4114_EFH_1024 | AK4114_DIT | AK4114_IPS(1),
469 0,
470 0
471 };
Takashi Iwai32b47da2007-01-29 15:26:36 +0100472 static const unsigned char ak4114_init_txcsb[] = {
Takashi Iwai56255062006-11-09 16:47:26 +0100473 0x41, 0x02, 0x2c, 0x00, 0x00
474 };
475 struct ak4114 *ak;
476 int err;
477
478 return snd_ak4114_create(ice->card,
479 ap192_ak4114_read,
480 ap192_ak4114_write,
481 ak4114_init_vals, ak4114_init_txcsb,
482 ice, &ak);
483}
484#endif /* BUILD_AK4114_AP192 */
485
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100486static int __devinit revo_init(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100488 struct snd_akm4xxx *ak;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 int err;
490
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;
Takashi Iwai59acf762005-12-05 19:22:34 +0100496 ice->gpio.i2s_mclk_changed = revo_i2s_mclk_changed;
497 break;
498 case VT1724_SUBDEVICE_REVOLUTION51:
499 ice->num_total_dacs = 6;
500 ice->num_total_adcs = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 break;
Takashi Iwai56255062006-11-09 16:47:26 +0100502 case VT1724_SUBDEVICE_AUDIOPHILE192:
503 ice->num_total_dacs = 2;
504 ice->num_total_adcs = 2;
505 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 default:
507 snd_BUG();
508 return -EINVAL;
509 }
510
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 /* second stage of initialization, analog parts and others */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100512 ak = ice->akm = kcalloc(2, sizeof(struct snd_akm4xxx), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 if (! ak)
514 return -ENOMEM;
515 ice->akm_codecs = 2;
516 switch (ice->eeprom.subvendor) {
517 case VT1724_SUBDEVICE_REVOLUTION71:
Takashi Iwai59acf762005-12-05 19:22:34 +0100518 ice->akm_codecs = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 if ((err = snd_ice1712_akm4xxx_init(ak, &akm_revo_front, &akm_revo_front_priv, ice)) < 0)
520 return err;
521 if ((err = snd_ice1712_akm4xxx_init(ak + 1, &akm_revo_surround, &akm_revo_surround_priv, ice)) < 0)
522 return err;
523 /* unmute all codecs */
524 snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE);
525 break;
Takashi Iwai59acf762005-12-05 19:22:34 +0100526 case VT1724_SUBDEVICE_REVOLUTION51:
Jochen Voss96d9e932006-08-08 21:13:42 +0200527 ice->akm_codecs = 2;
Jochen Vossfeaa6a72006-10-04 18:08:43 +0200528 err = snd_ice1712_akm4xxx_init(ak, &akm_revo51,
529 &akm_revo51_priv, ice);
530 if (err < 0)
Takashi Iwai59acf762005-12-05 19:22:34 +0100531 return err;
Jochen Vossfeaa6a72006-10-04 18:08:43 +0200532 err = snd_ice1712_akm4xxx_init(ak+1, &akm_revo51_adc,
Jochen Voss96d9e932006-08-08 21:13:42 +0200533 &akm_revo51_adc_priv, ice);
534 if (err < 0)
535 return err;
Jochen Vossfeaa6a72006-10-04 18:08:43 +0200536 err = revo51_i2c_init(ice, &ptc_revo51_volume);
537 if (err < 0)
538 return err;
539 /* unmute all codecs */
540 snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE,
541 VT1724_REVO_MUTE);
Takashi Iwai59acf762005-12-05 19:22:34 +0100542 break;
Takashi Iwai56255062006-11-09 16:47:26 +0100543 case VT1724_SUBDEVICE_AUDIOPHILE192:
544 ice->akm_codecs = 1;
545 err = snd_ice1712_akm4xxx_init(ak, &akm_ap192, &akm_ap192_priv,
546 ice);
547 if (err < 0)
548 return err;
549
550 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 }
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 return 0;
554}
555
556
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100557static int __devinit revo_add_controls(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558{
559 int err;
560
561 switch (ice->eeprom.subvendor) {
562 case VT1724_SUBDEVICE_REVOLUTION71:
Jochen Vossfeaa6a72006-10-04 18:08:43 +0200563 err = snd_ice1712_akm4xxx_build_controls(ice);
564 if (err < 0)
565 return err;
566 break;
Takashi Iwai59acf762005-12-05 19:22:34 +0100567 case VT1724_SUBDEVICE_REVOLUTION51:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 err = snd_ice1712_akm4xxx_build_controls(ice);
569 if (err < 0)
570 return err;
Jochen Vossfeaa6a72006-10-04 18:08:43 +0200571 err = snd_pt2258_build_controls(ice->spec.revo51.pt2258);
572 if (err < 0)
573 return err;
574 break;
Takashi Iwai56255062006-11-09 16:47:26 +0100575 case VT1724_SUBDEVICE_AUDIOPHILE192:
576 err = snd_ice1712_akm4xxx_build_controls(ice);
577 if (err < 0)
578 return err;
579#ifdef BUILD_AK4114_AP192
580 err = ap192_ak4114_init(ice);
581 if (err < 0)
582 return err;
583#endif
584 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
586 return 0;
587}
588
589/* entry point */
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100590struct snd_ice1712_card_info snd_vt1724_revo_cards[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 {
592 .subvendor = VT1724_SUBDEVICE_REVOLUTION71,
593 .name = "M Audio Revolution-7.1",
594 .model = "revo71",
595 .chip_init = revo_init,
596 .build_controls = revo_add_controls,
597 },
Takashi Iwai59acf762005-12-05 19:22:34 +0100598 {
599 .subvendor = VT1724_SUBDEVICE_REVOLUTION51,
600 .name = "M Audio Revolution-5.1",
601 .model = "revo51",
602 .chip_init = revo_init,
603 .build_controls = revo_add_controls,
604 },
Takashi Iwai56255062006-11-09 16:47:26 +0100605 {
606 .subvendor = VT1724_SUBDEVICE_AUDIOPHILE192,
607 .name = "M Audio Audiophile192",
608 .model = "ap192",
609 .chip_init = revo_init,
610 .build_controls = revo_add_controls,
611 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 { } /* terminator */
613};