Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * ALSA driver for ICEnsemble ICE1712 (Envy24) | |
3 | * | |
4 | * Lowlevel functions for M-Audio Delta 1010, 44, 66, Dio2496, Audiophile | |
5 | * Digigram VX442 | |
6 | * | |
7 | * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz> | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 | * | |
23 | */ | |
24 | ||
25 | #include <sound/driver.h> | |
26 | #include <asm/io.h> | |
27 | #include <linux/delay.h> | |
28 | #include <linux/interrupt.h> | |
29 | #include <linux/init.h> | |
30 | #include <linux/slab.h> | |
31 | #include <sound/core.h> | |
32 | #include <sound/cs8427.h> | |
33 | #include <sound/asoundef.h> | |
34 | ||
35 | #include "ice1712.h" | |
36 | #include "delta.h" | |
37 | ||
38 | #define SND_CS8403 | |
39 | #include <sound/cs8403.h> | |
40 | ||
41 | ||
42 | /* | |
43 | * CS8427 via SPI mode (for Audiophile), emulated I2C | |
44 | */ | |
45 | ||
46 | /* send 8 bits */ | |
47 | static void ap_cs8427_write_byte(ice1712_t *ice, unsigned char data, unsigned char tmp) | |
48 | { | |
49 | int idx; | |
50 | ||
51 | for (idx = 7; idx >= 0; idx--) { | |
52 | tmp &= ~(ICE1712_DELTA_AP_DOUT|ICE1712_DELTA_AP_CCLK); | |
53 | if (data & (1 << idx)) | |
54 | tmp |= ICE1712_DELTA_AP_DOUT; | |
55 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp); | |
56 | udelay(5); | |
57 | tmp |= ICE1712_DELTA_AP_CCLK; | |
58 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp); | |
59 | udelay(5); | |
60 | } | |
61 | } | |
62 | ||
63 | /* read 8 bits */ | |
64 | static unsigned char ap_cs8427_read_byte(ice1712_t *ice, unsigned char tmp) | |
65 | { | |
66 | unsigned char data = 0; | |
67 | int idx; | |
68 | ||
69 | for (idx = 7; idx >= 0; idx--) { | |
70 | tmp &= ~ICE1712_DELTA_AP_CCLK; | |
71 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp); | |
72 | udelay(5); | |
73 | if (snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_DELTA_AP_DIN) | |
74 | data |= 1 << idx; | |
75 | tmp |= ICE1712_DELTA_AP_CCLK; | |
76 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp); | |
77 | udelay(5); | |
78 | } | |
79 | return data; | |
80 | } | |
81 | ||
82 | /* assert chip select */ | |
83 | static unsigned char ap_cs8427_codec_select(ice1712_t *ice) | |
84 | { | |
85 | unsigned char tmp; | |
86 | tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA); | |
87 | switch (ice->eeprom.subvendor) { | |
88 | case ICE1712_SUBDEVICE_DELTA1010LT: | |
89 | tmp &= ~ICE1712_DELTA_1010LT_CS; | |
90 | tmp |= ICE1712_DELTA_1010LT_CCLK | ICE1712_DELTA_1010LT_CS_CS8427; | |
91 | break; | |
92 | case ICE1712_SUBDEVICE_AUDIOPHILE: | |
93 | case ICE1712_SUBDEVICE_DELTA410: | |
94 | tmp |= ICE1712_DELTA_AP_CCLK | ICE1712_DELTA_AP_CS_CODEC; | |
95 | tmp &= ~ICE1712_DELTA_AP_CS_DIGITAL; | |
96 | break; | |
97 | case ICE1712_SUBDEVICE_VX442: | |
98 | tmp |= ICE1712_VX442_CCLK | ICE1712_VX442_CODEC_CHIP_A | ICE1712_VX442_CODEC_CHIP_B; | |
99 | tmp &= ~ICE1712_VX442_CS_DIGITAL; | |
100 | break; | |
101 | } | |
102 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp); | |
103 | udelay(5); | |
104 | return tmp; | |
105 | } | |
106 | ||
107 | /* deassert chip select */ | |
108 | static void ap_cs8427_codec_deassert(ice1712_t *ice, unsigned char tmp) | |
109 | { | |
110 | switch (ice->eeprom.subvendor) { | |
111 | case ICE1712_SUBDEVICE_DELTA1010LT: | |
112 | tmp &= ~ICE1712_DELTA_1010LT_CS; | |
113 | tmp |= ICE1712_DELTA_1010LT_CS_NONE; | |
114 | break; | |
115 | case ICE1712_SUBDEVICE_AUDIOPHILE: | |
116 | case ICE1712_SUBDEVICE_DELTA410: | |
117 | tmp |= ICE1712_DELTA_AP_CS_DIGITAL; | |
118 | break; | |
119 | case ICE1712_SUBDEVICE_VX442: | |
120 | tmp |= ICE1712_VX442_CS_DIGITAL; | |
121 | break; | |
122 | } | |
123 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp); | |
124 | } | |
125 | ||
126 | /* sequential write */ | |
127 | static int ap_cs8427_sendbytes(snd_i2c_device_t *device, unsigned char *bytes, int count) | |
128 | { | |
129 | ice1712_t *ice = device->bus->private_data; | |
130 | int res = count; | |
131 | unsigned char tmp; | |
132 | ||
133 | down(&ice->gpio_mutex); | |
134 | tmp = ap_cs8427_codec_select(ice); | |
135 | ap_cs8427_write_byte(ice, (device->addr << 1) | 0, tmp); /* address + write mode */ | |
136 | while (count-- > 0) | |
137 | ap_cs8427_write_byte(ice, *bytes++, tmp); | |
138 | ap_cs8427_codec_deassert(ice, tmp); | |
139 | up(&ice->gpio_mutex); | |
140 | return res; | |
141 | } | |
142 | ||
143 | /* sequential read */ | |
144 | static int ap_cs8427_readbytes(snd_i2c_device_t *device, unsigned char *bytes, int count) | |
145 | { | |
146 | ice1712_t *ice = device->bus->private_data; | |
147 | int res = count; | |
148 | unsigned char tmp; | |
149 | ||
150 | down(&ice->gpio_mutex); | |
151 | tmp = ap_cs8427_codec_select(ice); | |
152 | ap_cs8427_write_byte(ice, (device->addr << 1) | 1, tmp); /* address + read mode */ | |
153 | while (count-- > 0) | |
154 | *bytes++ = ap_cs8427_read_byte(ice, tmp); | |
155 | ap_cs8427_codec_deassert(ice, tmp); | |
156 | up(&ice->gpio_mutex); | |
157 | return res; | |
158 | } | |
159 | ||
160 | static int ap_cs8427_probeaddr(snd_i2c_bus_t *bus, unsigned short addr) | |
161 | { | |
162 | if (addr == 0x10) | |
163 | return 1; | |
164 | return -ENOENT; | |
165 | } | |
166 | ||
167 | static snd_i2c_ops_t ap_cs8427_i2c_ops = { | |
168 | .sendbytes = ap_cs8427_sendbytes, | |
169 | .readbytes = ap_cs8427_readbytes, | |
170 | .probeaddr = ap_cs8427_probeaddr, | |
171 | }; | |
172 | ||
173 | /* | |
174 | */ | |
175 | ||
176 | static void snd_ice1712_delta_cs8403_spdif_write(ice1712_t *ice, unsigned char bits) | |
177 | { | |
178 | unsigned char tmp, mask1, mask2; | |
179 | int idx; | |
180 | /* send byte to transmitter */ | |
181 | mask1 = ICE1712_DELTA_SPDIF_OUT_STAT_CLOCK; | |
182 | mask2 = ICE1712_DELTA_SPDIF_OUT_STAT_DATA; | |
183 | down(&ice->gpio_mutex); | |
184 | tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA); | |
185 | for (idx = 7; idx >= 0; idx--) { | |
186 | tmp &= ~(mask1 | mask2); | |
187 | if (bits & (1 << idx)) | |
188 | tmp |= mask2; | |
189 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp); | |
190 | udelay(100); | |
191 | tmp |= mask1; | |
192 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp); | |
193 | udelay(100); | |
194 | } | |
195 | tmp &= ~mask1; | |
196 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp); | |
197 | up(&ice->gpio_mutex); | |
198 | } | |
199 | ||
200 | ||
201 | static void delta_spdif_default_get(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol) | |
202 | { | |
203 | snd_cs8403_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_bits); | |
204 | } | |
205 | ||
206 | static int delta_spdif_default_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol) | |
207 | { | |
208 | unsigned int val; | |
209 | int change; | |
210 | ||
211 | val = snd_cs8403_encode_spdif_bits(&ucontrol->value.iec958); | |
212 | spin_lock_irq(&ice->reg_lock); | |
213 | change = ice->spdif.cs8403_bits != val; | |
214 | ice->spdif.cs8403_bits = val; | |
215 | if (change && ice->playback_pro_substream == NULL) { | |
216 | spin_unlock_irq(&ice->reg_lock); | |
217 | snd_ice1712_delta_cs8403_spdif_write(ice, val); | |
218 | } else { | |
219 | spin_unlock_irq(&ice->reg_lock); | |
220 | } | |
221 | return change; | |
222 | } | |
223 | ||
224 | static void delta_spdif_stream_get(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol) | |
225 | { | |
226 | snd_cs8403_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_stream_bits); | |
227 | } | |
228 | ||
229 | static int delta_spdif_stream_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol) | |
230 | { | |
231 | unsigned int val; | |
232 | int change; | |
233 | ||
234 | val = snd_cs8403_encode_spdif_bits(&ucontrol->value.iec958); | |
235 | spin_lock_irq(&ice->reg_lock); | |
236 | change = ice->spdif.cs8403_stream_bits != val; | |
237 | ice->spdif.cs8403_stream_bits = val; | |
238 | if (change && ice->playback_pro_substream != NULL) { | |
239 | spin_unlock_irq(&ice->reg_lock); | |
240 | snd_ice1712_delta_cs8403_spdif_write(ice, val); | |
241 | } else { | |
242 | spin_unlock_irq(&ice->reg_lock); | |
243 | } | |
244 | return change; | |
245 | } | |
246 | ||
247 | ||
248 | /* | |
249 | * AK4524 on Delta 44 and 66 to choose the chip mask | |
250 | */ | |
251 | static void delta_ak4524_lock(akm4xxx_t *ak, int chip) | |
252 | { | |
253 | struct snd_ak4xxx_private *priv = (void *)ak->private_value[0]; | |
254 | ice1712_t *ice = ak->private_data[0]; | |
255 | ||
256 | snd_ice1712_save_gpio_status(ice); | |
257 | priv->cs_mask = | |
258 | priv->cs_addr = chip == 0 ? ICE1712_DELTA_CODEC_CHIP_A : | |
259 | ICE1712_DELTA_CODEC_CHIP_B; | |
260 | } | |
261 | ||
262 | /* | |
263 | * AK4524 on Delta1010LT to choose the chip address | |
264 | */ | |
265 | static void delta1010lt_ak4524_lock(akm4xxx_t *ak, int chip) | |
266 | { | |
267 | struct snd_ak4xxx_private *priv = (void *)ak->private_value[0]; | |
268 | ice1712_t *ice = ak->private_data[0]; | |
269 | ||
270 | snd_ice1712_save_gpio_status(ice); | |
271 | priv->cs_mask = ICE1712_DELTA_1010LT_CS; | |
272 | priv->cs_addr = chip << 4; | |
273 | } | |
274 | ||
275 | /* | |
276 | * AK4528 on VX442 to choose the chip mask | |
277 | */ | |
278 | static void vx442_ak4524_lock(akm4xxx_t *ak, int chip) | |
279 | { | |
280 | struct snd_ak4xxx_private *priv = (void *)ak->private_value[0]; | |
281 | ice1712_t *ice = ak->private_data[0]; | |
282 | ||
283 | snd_ice1712_save_gpio_status(ice); | |
284 | priv->cs_mask = | |
285 | priv->cs_addr = chip == 0 ? ICE1712_VX442_CODEC_CHIP_A : | |
286 | ICE1712_VX442_CODEC_CHIP_B; | |
287 | } | |
288 | ||
289 | /* | |
290 | * change the DFS bit according rate for Delta1010 | |
291 | */ | |
292 | static void delta_1010_set_rate_val(ice1712_t *ice, unsigned int rate) | |
293 | { | |
294 | unsigned char tmp, tmp2; | |
295 | ||
296 | if (rate == 0) /* no hint - S/PDIF input is master, simply return */ | |
297 | return; | |
298 | ||
299 | down(&ice->gpio_mutex); | |
300 | tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA); | |
301 | tmp2 = tmp & ~ICE1712_DELTA_DFS; | |
302 | if (rate > 48000) | |
303 | tmp2 |= ICE1712_DELTA_DFS; | |
304 | if (tmp != tmp2) | |
305 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp2); | |
306 | up(&ice->gpio_mutex); | |
307 | } | |
308 | ||
309 | /* | |
310 | * change the rate of AK4524 on Delta 44/66, AP, 1010LT | |
311 | */ | |
312 | static void delta_ak4524_set_rate_val(akm4xxx_t *ak, unsigned int rate) | |
313 | { | |
314 | unsigned char tmp, tmp2; | |
315 | ice1712_t *ice = ak->private_data[0]; | |
316 | ||
317 | if (rate == 0) /* no hint - S/PDIF input is master, simply return */ | |
318 | return; | |
319 | ||
320 | /* check before reset ak4524 to avoid unnecessary clicks */ | |
321 | down(&ice->gpio_mutex); | |
322 | tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA); | |
323 | up(&ice->gpio_mutex); | |
324 | tmp2 = tmp & ~ICE1712_DELTA_DFS; | |
325 | if (rate > 48000) | |
326 | tmp2 |= ICE1712_DELTA_DFS; | |
327 | if (tmp == tmp2) | |
328 | return; | |
329 | ||
330 | /* do it again */ | |
331 | snd_akm4xxx_reset(ak, 1); | |
332 | down(&ice->gpio_mutex); | |
333 | tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ~ICE1712_DELTA_DFS; | |
334 | if (rate > 48000) | |
335 | tmp |= ICE1712_DELTA_DFS; | |
336 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp); | |
337 | up(&ice->gpio_mutex); | |
338 | snd_akm4xxx_reset(ak, 0); | |
339 | } | |
340 | ||
341 | /* | |
342 | * change the rate of AK4524 on VX442 | |
343 | */ | |
344 | static void vx442_ak4524_set_rate_val(akm4xxx_t *ak, unsigned int rate) | |
345 | { | |
346 | unsigned char val; | |
347 | ||
348 | val = (rate > 48000) ? 0x65 : 0x60; | |
349 | if (snd_akm4xxx_get(ak, 0, 0x02) != val || | |
350 | snd_akm4xxx_get(ak, 1, 0x02) != val) { | |
351 | snd_akm4xxx_reset(ak, 1); | |
352 | snd_akm4xxx_write(ak, 0, 0x02, val); | |
353 | snd_akm4xxx_write(ak, 1, 0x02, val); | |
354 | snd_akm4xxx_reset(ak, 0); | |
355 | } | |
356 | } | |
357 | ||
358 | ||
359 | /* | |
360 | * SPDIF ops for Delta 1010, Dio, 66 | |
361 | */ | |
362 | ||
363 | /* open callback */ | |
364 | static void delta_open_spdif(ice1712_t *ice, snd_pcm_substream_t * substream) | |
365 | { | |
366 | ice->spdif.cs8403_stream_bits = ice->spdif.cs8403_bits; | |
367 | } | |
368 | ||
369 | /* set up */ | |
370 | static void delta_setup_spdif(ice1712_t *ice, int rate) | |
371 | { | |
372 | unsigned long flags; | |
373 | unsigned int tmp; | |
374 | int change; | |
375 | ||
376 | spin_lock_irqsave(&ice->reg_lock, flags); | |
377 | tmp = ice->spdif.cs8403_stream_bits; | |
378 | if (tmp & 0x01) /* consumer */ | |
379 | tmp &= (tmp & 0x01) ? ~0x06 : ~0x18; | |
380 | switch (rate) { | |
381 | case 32000: tmp |= (tmp & 0x01) ? 0x04 : 0x00; break; | |
382 | case 44100: tmp |= (tmp & 0x01) ? 0x00 : 0x10; break; | |
383 | case 48000: tmp |= (tmp & 0x01) ? 0x02 : 0x08; break; | |
384 | default: tmp |= (tmp & 0x01) ? 0x00 : 0x18; break; | |
385 | } | |
386 | change = ice->spdif.cs8403_stream_bits != tmp; | |
387 | ice->spdif.cs8403_stream_bits = tmp; | |
388 | spin_unlock_irqrestore(&ice->reg_lock, flags); | |
389 | if (change) | |
390 | snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &ice->spdif.stream_ctl->id); | |
391 | snd_ice1712_delta_cs8403_spdif_write(ice, tmp); | |
392 | } | |
393 | ||
394 | ||
395 | /* | |
396 | * initialize the chips on M-Audio cards | |
397 | */ | |
398 | ||
399 | static akm4xxx_t akm_audiophile __devinitdata = { | |
400 | .type = SND_AK4528, | |
401 | .num_adcs = 2, | |
402 | .num_dacs = 2, | |
403 | .ops = { | |
404 | .set_rate_val = delta_ak4524_set_rate_val | |
405 | } | |
406 | }; | |
407 | ||
408 | static struct snd_ak4xxx_private akm_audiophile_priv __devinitdata = { | |
409 | .caddr = 2, | |
410 | .cif = 0, | |
411 | .data_mask = ICE1712_DELTA_AP_DOUT, | |
412 | .clk_mask = ICE1712_DELTA_AP_CCLK, | |
413 | .cs_mask = ICE1712_DELTA_AP_CS_CODEC, | |
414 | .cs_addr = ICE1712_DELTA_AP_CS_CODEC, | |
415 | .cs_none = 0, | |
416 | .add_flags = ICE1712_DELTA_AP_CS_DIGITAL, | |
417 | .mask_flags = 0, | |
418 | }; | |
419 | ||
420 | static akm4xxx_t akm_delta410 __devinitdata = { | |
421 | .type = SND_AK4529, | |
422 | .num_adcs = 2, | |
423 | .num_dacs = 8, | |
424 | .ops = { | |
425 | .set_rate_val = delta_ak4524_set_rate_val | |
426 | } | |
427 | }; | |
428 | ||
429 | static struct snd_ak4xxx_private akm_delta410_priv __devinitdata = { | |
430 | .caddr = 0, | |
431 | .cif = 0, | |
432 | .data_mask = ICE1712_DELTA_AP_DOUT, | |
433 | .clk_mask = ICE1712_DELTA_AP_CCLK, | |
434 | .cs_mask = ICE1712_DELTA_AP_CS_CODEC, | |
435 | .cs_addr = ICE1712_DELTA_AP_CS_CODEC, | |
436 | .cs_none = 0, | |
437 | .add_flags = ICE1712_DELTA_AP_CS_DIGITAL, | |
438 | .mask_flags = 0, | |
439 | }; | |
440 | ||
441 | static akm4xxx_t akm_delta1010lt __devinitdata = { | |
442 | .type = SND_AK4524, | |
443 | .num_adcs = 8, | |
444 | .num_dacs = 8, | |
445 | .ops = { | |
446 | .lock = delta1010lt_ak4524_lock, | |
447 | .set_rate_val = delta_ak4524_set_rate_val | |
448 | } | |
449 | }; | |
450 | ||
451 | static struct snd_ak4xxx_private akm_delta1010lt_priv __devinitdata = { | |
452 | .caddr = 2, | |
453 | .cif = 0, /* the default level of the CIF pin from AK4524 */ | |
454 | .data_mask = ICE1712_DELTA_1010LT_DOUT, | |
455 | .clk_mask = ICE1712_DELTA_1010LT_CCLK, | |
456 | .cs_mask = 0, | |
457 | .cs_addr = 0, /* set later */ | |
458 | .cs_none = ICE1712_DELTA_1010LT_CS_NONE, | |
459 | .add_flags = 0, | |
460 | .mask_flags = 0, | |
461 | }; | |
462 | ||
463 | static akm4xxx_t akm_delta44 __devinitdata = { | |
464 | .type = SND_AK4524, | |
465 | .num_adcs = 4, | |
466 | .num_dacs = 4, | |
467 | .ops = { | |
468 | .lock = delta_ak4524_lock, | |
469 | .set_rate_val = delta_ak4524_set_rate_val | |
470 | } | |
471 | }; | |
472 | ||
473 | static struct snd_ak4xxx_private akm_delta44_priv __devinitdata = { | |
474 | .caddr = 2, | |
475 | .cif = 0, /* the default level of the CIF pin from AK4524 */ | |
476 | .data_mask = ICE1712_DELTA_CODEC_SERIAL_DATA, | |
477 | .clk_mask = ICE1712_DELTA_CODEC_SERIAL_CLOCK, | |
478 | .cs_mask = 0, | |
479 | .cs_addr = 0, /* set later */ | |
480 | .cs_none = 0, | |
481 | .add_flags = 0, | |
482 | .mask_flags = 0, | |
483 | }; | |
484 | ||
485 | static akm4xxx_t akm_vx442 __devinitdata = { | |
486 | .type = SND_AK4524, | |
487 | .num_adcs = 4, | |
488 | .num_dacs = 4, | |
489 | .ops = { | |
490 | .lock = vx442_ak4524_lock, | |
491 | .set_rate_val = vx442_ak4524_set_rate_val | |
492 | } | |
493 | }; | |
494 | ||
495 | static struct snd_ak4xxx_private akm_vx442_priv __devinitdata = { | |
496 | .caddr = 2, | |
497 | .cif = 0, | |
498 | .data_mask = ICE1712_VX442_DOUT, | |
499 | .clk_mask = ICE1712_VX442_CCLK, | |
500 | .cs_mask = 0, | |
501 | .cs_addr = 0, /* set later */ | |
502 | .cs_none = 0, | |
503 | .add_flags = 0, | |
504 | .mask_flags = 0, | |
505 | }; | |
506 | ||
507 | static int __devinit snd_ice1712_delta_init(ice1712_t *ice) | |
508 | { | |
509 | int err; | |
510 | akm4xxx_t *ak; | |
511 | ||
512 | /* determine I2C, DACs and ADCs */ | |
513 | switch (ice->eeprom.subvendor) { | |
514 | case ICE1712_SUBDEVICE_AUDIOPHILE: | |
515 | ice->num_total_dacs = 2; | |
516 | ice->num_total_adcs = 2; | |
517 | break; | |
518 | case ICE1712_SUBDEVICE_DELTA410: | |
519 | ice->num_total_dacs = 8; | |
520 | ice->num_total_adcs = 2; | |
521 | break; | |
522 | case ICE1712_SUBDEVICE_DELTA44: | |
523 | case ICE1712_SUBDEVICE_DELTA66: | |
524 | ice->num_total_dacs = ice->omni ? 8 : 4; | |
525 | ice->num_total_adcs = ice->omni ? 8 : 4; | |
526 | break; | |
527 | case ICE1712_SUBDEVICE_DELTA1010: | |
528 | case ICE1712_SUBDEVICE_DELTA1010LT: | |
529 | case ICE1712_SUBDEVICE_MEDIASTATION: | |
530 | ice->num_total_dacs = 8; | |
531 | ice->num_total_adcs = 8; | |
532 | break; | |
533 | case ICE1712_SUBDEVICE_DELTADIO2496: | |
534 | ice->num_total_dacs = 4; /* two AK4324 codecs */ | |
535 | break; | |
536 | case ICE1712_SUBDEVICE_VX442: | |
537 | ice->num_total_dacs = 4; | |
538 | ice->num_total_adcs = 4; | |
539 | break; | |
540 | } | |
541 | ||
542 | /* initialize spdif */ | |
543 | switch (ice->eeprom.subvendor) { | |
544 | case ICE1712_SUBDEVICE_AUDIOPHILE: | |
545 | case ICE1712_SUBDEVICE_DELTA410: | |
546 | case ICE1712_SUBDEVICE_DELTA1010LT: | |
547 | case ICE1712_SUBDEVICE_VX442: | |
548 | if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) { | |
549 | snd_printk("unable to create I2C bus\n"); | |
550 | return err; | |
551 | } | |
552 | ice->i2c->private_data = ice; | |
553 | ice->i2c->ops = &ap_cs8427_i2c_ops; | |
554 | if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0) | |
555 | return err; | |
556 | break; | |
557 | case ICE1712_SUBDEVICE_DELTA1010: | |
558 | case ICE1712_SUBDEVICE_MEDIASTATION: | |
559 | ice->gpio.set_pro_rate = delta_1010_set_rate_val; | |
560 | break; | |
561 | case ICE1712_SUBDEVICE_DELTADIO2496: | |
562 | ice->gpio.set_pro_rate = delta_1010_set_rate_val; | |
563 | /* fall thru */ | |
564 | case ICE1712_SUBDEVICE_DELTA66: | |
565 | ice->spdif.ops.open = delta_open_spdif; | |
566 | ice->spdif.ops.setup_rate = delta_setup_spdif; | |
567 | ice->spdif.ops.default_get = delta_spdif_default_get; | |
568 | ice->spdif.ops.default_put = delta_spdif_default_put; | |
569 | ice->spdif.ops.stream_get = delta_spdif_stream_get; | |
570 | ice->spdif.ops.stream_put = delta_spdif_stream_put; | |
571 | /* Set spdif defaults */ | |
572 | snd_ice1712_delta_cs8403_spdif_write(ice, ice->spdif.cs8403_bits); | |
573 | break; | |
574 | } | |
575 | ||
576 | /* no analog? */ | |
577 | switch (ice->eeprom.subvendor) { | |
578 | case ICE1712_SUBDEVICE_DELTA1010: | |
579 | case ICE1712_SUBDEVICE_DELTADIO2496: | |
580 | case ICE1712_SUBDEVICE_MEDIASTATION: | |
581 | return 0; | |
582 | } | |
583 | ||
584 | /* second stage of initialization, analog parts and others */ | |
585 | ak = ice->akm = kmalloc(sizeof(akm4xxx_t), GFP_KERNEL); | |
586 | if (! ak) | |
587 | return -ENOMEM; | |
588 | ice->akm_codecs = 1; | |
589 | ||
590 | switch (ice->eeprom.subvendor) { | |
591 | case ICE1712_SUBDEVICE_AUDIOPHILE: | |
592 | err = snd_ice1712_akm4xxx_init(ak, &akm_audiophile, &akm_audiophile_priv, ice); | |
593 | break; | |
594 | case ICE1712_SUBDEVICE_DELTA410: | |
595 | err = snd_ice1712_akm4xxx_init(ak, &akm_delta410, &akm_delta410_priv, ice); | |
596 | break; | |
597 | case ICE1712_SUBDEVICE_DELTA1010LT: | |
598 | err = snd_ice1712_akm4xxx_init(ak, &akm_delta1010lt, &akm_delta1010lt_priv, ice); | |
599 | break; | |
600 | case ICE1712_SUBDEVICE_DELTA66: | |
601 | case ICE1712_SUBDEVICE_DELTA44: | |
602 | err = snd_ice1712_akm4xxx_init(ak, &akm_delta44, &akm_delta44_priv, ice); | |
603 | break; | |
604 | case ICE1712_SUBDEVICE_VX442: | |
605 | err = snd_ice1712_akm4xxx_init(ak, &akm_vx442, &akm_vx442_priv, ice); | |
606 | break; | |
607 | default: | |
608 | snd_BUG(); | |
609 | return -EINVAL; | |
610 | } | |
611 | ||
612 | return err; | |
613 | } | |
614 | ||
615 | ||
616 | /* | |
617 | * additional controls for M-Audio cards | |
618 | */ | |
619 | ||
620 | static snd_kcontrol_new_t snd_ice1712_delta1010_wordclock_select __devinitdata = | |
67ed4161 | 621 | ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "Word Clock Sync", 0, ICE1712_DELTA_WORD_CLOCK_SELECT, 1, 0); |
1da177e4 | 622 | static snd_kcontrol_new_t snd_ice1712_delta1010lt_wordclock_select __devinitdata = |
67ed4161 | 623 | ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "Word Clock Sync", 0, ICE1712_DELTA_1010LT_WORDCLOCK, 1, 0); |
1da177e4 | 624 | static snd_kcontrol_new_t snd_ice1712_delta1010_wordclock_status __devinitdata = |
67ed4161 | 625 | ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "Word Clock Status", 0, ICE1712_DELTA_WORD_CLOCK_STATUS, 1, SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE); |
1da177e4 | 626 | static snd_kcontrol_new_t snd_ice1712_deltadio2496_spdif_in_select __devinitdata = |
67ed4161 | 627 | ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, ICE1712_DELTA_SPDIF_INPUT_SELECT, 0, 0); |
1da177e4 | 628 | static snd_kcontrol_new_t snd_ice1712_delta_spdif_in_status __devinitdata = |
67ed4161 | 629 | ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "Delta IEC958 Input Status", 0, ICE1712_DELTA_SPDIF_IN_STAT, 1, SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE); |
1da177e4 LT |
630 | |
631 | ||
632 | static int __devinit snd_ice1712_delta_add_controls(ice1712_t *ice) | |
633 | { | |
634 | int err; | |
635 | ||
636 | /* 1010 and dio specific controls */ | |
637 | switch (ice->eeprom.subvendor) { | |
638 | case ICE1712_SUBDEVICE_DELTA1010: | |
639 | case ICE1712_SUBDEVICE_MEDIASTATION: | |
640 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010_wordclock_select, ice)); | |
641 | if (err < 0) | |
642 | return err; | |
643 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010_wordclock_status, ice)); | |
644 | if (err < 0) | |
645 | return err; | |
646 | break; | |
647 | case ICE1712_SUBDEVICE_DELTADIO2496: | |
648 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_deltadio2496_spdif_in_select, ice)); | |
649 | if (err < 0) | |
650 | return err; | |
651 | break; | |
652 | case ICE1712_SUBDEVICE_DELTA1010LT: | |
653 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010lt_wordclock_select, ice)); | |
654 | if (err < 0) | |
655 | return err; | |
656 | break; | |
657 | } | |
658 | ||
659 | /* normal spdif controls */ | |
660 | switch (ice->eeprom.subvendor) { | |
661 | case ICE1712_SUBDEVICE_DELTA1010: | |
662 | case ICE1712_SUBDEVICE_DELTADIO2496: | |
663 | case ICE1712_SUBDEVICE_DELTA66: | |
664 | case ICE1712_SUBDEVICE_MEDIASTATION: | |
665 | err = snd_ice1712_spdif_build_controls(ice); | |
666 | if (err < 0) | |
667 | return err; | |
668 | break; | |
669 | } | |
670 | ||
671 | /* spdif status in */ | |
672 | switch (ice->eeprom.subvendor) { | |
673 | case ICE1712_SUBDEVICE_DELTA1010: | |
674 | case ICE1712_SUBDEVICE_DELTADIO2496: | |
675 | case ICE1712_SUBDEVICE_DELTA66: | |
676 | case ICE1712_SUBDEVICE_MEDIASTATION: | |
677 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta_spdif_in_status, ice)); | |
678 | if (err < 0) | |
679 | return err; | |
680 | break; | |
681 | } | |
682 | ||
683 | /* ak4524 controls */ | |
684 | switch (ice->eeprom.subvendor) { | |
685 | case ICE1712_SUBDEVICE_DELTA1010LT: | |
686 | case ICE1712_SUBDEVICE_AUDIOPHILE: | |
687 | case ICE1712_SUBDEVICE_DELTA410: | |
688 | case ICE1712_SUBDEVICE_DELTA44: | |
689 | case ICE1712_SUBDEVICE_DELTA66: | |
690 | case ICE1712_SUBDEVICE_VX442: | |
691 | err = snd_ice1712_akm4xxx_build_controls(ice); | |
692 | if (err < 0) | |
693 | return err; | |
694 | break; | |
695 | } | |
696 | ||
697 | return 0; | |
698 | } | |
699 | ||
700 | ||
701 | /* entry point */ | |
702 | struct snd_ice1712_card_info snd_ice1712_delta_cards[] __devinitdata = { | |
703 | { | |
704 | .subvendor = ICE1712_SUBDEVICE_DELTA1010, | |
705 | .name = "M Audio Delta 1010", | |
706 | .model = "delta1010", | |
707 | .chip_init = snd_ice1712_delta_init, | |
708 | .build_controls = snd_ice1712_delta_add_controls, | |
709 | }, | |
710 | { | |
711 | .subvendor = ICE1712_SUBDEVICE_DELTADIO2496, | |
712 | .name = "M Audio Delta DiO 2496", | |
713 | .model = "dio2496", | |
714 | .chip_init = snd_ice1712_delta_init, | |
715 | .build_controls = snd_ice1712_delta_add_controls, | |
716 | .no_mpu401 = 1, | |
717 | }, | |
718 | { | |
719 | .subvendor = ICE1712_SUBDEVICE_DELTA66, | |
720 | .name = "M Audio Delta 66", | |
721 | .model = "delta66", | |
722 | .chip_init = snd_ice1712_delta_init, | |
723 | .build_controls = snd_ice1712_delta_add_controls, | |
724 | .no_mpu401 = 1, | |
725 | }, | |
726 | { | |
727 | .subvendor = ICE1712_SUBDEVICE_DELTA44, | |
728 | .name = "M Audio Delta 44", | |
729 | .model = "delta44", | |
730 | .chip_init = snd_ice1712_delta_init, | |
731 | .build_controls = snd_ice1712_delta_add_controls, | |
732 | .no_mpu401 = 1, | |
733 | }, | |
734 | { | |
735 | .subvendor = ICE1712_SUBDEVICE_AUDIOPHILE, | |
736 | .name = "M Audio Audiophile 24/96", | |
737 | .model = "audiophile", | |
738 | .chip_init = snd_ice1712_delta_init, | |
739 | .build_controls = snd_ice1712_delta_add_controls, | |
740 | }, | |
741 | { | |
742 | .subvendor = ICE1712_SUBDEVICE_DELTA410, | |
743 | .name = "M Audio Delta 410", | |
744 | .model = "delta410", | |
745 | .chip_init = snd_ice1712_delta_init, | |
746 | .build_controls = snd_ice1712_delta_add_controls, | |
747 | }, | |
748 | { | |
749 | .subvendor = ICE1712_SUBDEVICE_DELTA1010LT, | |
750 | .name = "M Audio Delta 1010LT", | |
751 | .model = "delta1010lt", | |
752 | .chip_init = snd_ice1712_delta_init, | |
753 | .build_controls = snd_ice1712_delta_add_controls, | |
754 | }, | |
755 | { | |
756 | .subvendor = ICE1712_SUBDEVICE_VX442, | |
757 | .name = "Digigram VX442", | |
758 | .model = "vx442", | |
759 | .chip_init = snd_ice1712_delta_init, | |
760 | .build_controls = snd_ice1712_delta_add_controls, | |
761 | .no_mpu401 = 1, | |
762 | }, | |
763 | { | |
764 | .subvendor = ICE1712_SUBDEVICE_MEDIASTATION, | |
765 | .name = "Lionstracs Mediastation", | |
766 | .model = "mediastation", | |
767 | .chip_init = snd_ice1712_delta_init, | |
768 | .build_controls = snd_ice1712_delta_add_controls, | |
769 | }, | |
770 | { } /* terminator */ | |
771 | }; |