AT91: Added a generic way to setup AT91 serial ports in Kconfig
[linux-2.6/pdupreez.git] / sound / pci / ice1712 / ews.c
blob013fc4f0482282fce0fb25da5a0a63b2012c6956
1 /*
2 * ALSA driver for ICEnsemble ICE1712 (Envy24)
4 * Lowlevel functions for Terratec EWS88MT/D, EWX24/96, DMX 6Fire
6 * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
7 * 2002 Takashi Iwai <tiwai@suse.de>
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.
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.
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
23 */
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 #include <sound/cs8427.h>
32 #include <sound/asoundef.h>
34 #include "ice1712.h"
35 #include "ews.h"
37 #define SND_CS8404
38 #include <sound/cs8403.h>
40 enum {
41 EWS_I2C_CS8404 = 0, EWS_I2C_PCF1, EWS_I2C_PCF2,
42 EWS_I2C_88D = 0,
43 EWS_I2C_6FIRE = 0
47 /* additional i2c devices for EWS boards */
48 struct ews_spec {
49 struct snd_i2c_device *i2cdevs[3];
53 * access via i2c mode (for EWX 24/96, EWS 88MT&D)
56 /* send SDA and SCL */
57 static void ewx_i2c_setlines(struct snd_i2c_bus *bus, int clk, int data)
59 struct snd_ice1712 *ice = bus->private_data;
60 unsigned char tmp = 0;
61 if (clk)
62 tmp |= ICE1712_EWX2496_SERIAL_CLOCK;
63 if (data)
64 tmp |= ICE1712_EWX2496_SERIAL_DATA;
65 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
66 udelay(5);
69 static int ewx_i2c_getclock(struct snd_i2c_bus *bus)
71 struct snd_ice1712 *ice = bus->private_data;
72 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_CLOCK ? 1 : 0;
75 static int ewx_i2c_getdata(struct snd_i2c_bus *bus, int ack)
77 struct snd_ice1712 *ice = bus->private_data;
78 int bit;
79 /* set RW pin to low */
80 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_RW);
81 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, 0);
82 if (ack)
83 udelay(5);
84 bit = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_DATA ? 1 : 0;
85 /* set RW pin to high */
86 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ICE1712_EWX2496_RW);
87 /* reset write mask */
88 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_SERIAL_CLOCK);
89 return bit;
92 static void ewx_i2c_start(struct snd_i2c_bus *bus)
94 struct snd_ice1712 *ice = bus->private_data;
95 unsigned char mask;
97 snd_ice1712_save_gpio_status(ice);
98 /* set RW high */
99 mask = ICE1712_EWX2496_RW;
100 switch (ice->eeprom.subvendor) {
101 case ICE1712_SUBDEVICE_EWX2496:
102 mask |= ICE1712_EWX2496_AK4524_CS; /* CS high also */
103 break;
104 case ICE1712_SUBDEVICE_DMX6FIRE:
105 mask |= ICE1712_6FIRE_AK4524_CS_MASK; /* CS high also */
106 break;
108 snd_ice1712_gpio_write_bits(ice, mask, mask);
111 static void ewx_i2c_stop(struct snd_i2c_bus *bus)
113 struct snd_ice1712 *ice = bus->private_data;
114 snd_ice1712_restore_gpio_status(ice);
117 static void ewx_i2c_direction(struct snd_i2c_bus *bus, int clock, int data)
119 struct snd_ice1712 *ice = bus->private_data;
120 unsigned char mask = 0;
122 if (clock)
123 mask |= ICE1712_EWX2496_SERIAL_CLOCK; /* write SCL */
124 if (data)
125 mask |= ICE1712_EWX2496_SERIAL_DATA; /* write SDA */
126 ice->gpio.direction &= ~(ICE1712_EWX2496_SERIAL_CLOCK|ICE1712_EWX2496_SERIAL_DATA);
127 ice->gpio.direction |= mask;
128 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio.direction);
129 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~mask);
132 static struct snd_i2c_bit_ops snd_ice1712_ewx_cs8427_bit_ops = {
133 .start = ewx_i2c_start,
134 .stop = ewx_i2c_stop,
135 .direction = ewx_i2c_direction,
136 .setlines = ewx_i2c_setlines,
137 .getclock = ewx_i2c_getclock,
138 .getdata = ewx_i2c_getdata,
143 * AK4524 access
146 /* AK4524 chip select; address 0x48 bit 0-3 */
147 static int snd_ice1712_ews88mt_chip_select(struct snd_ice1712 *ice, int chip_mask)
149 struct ews_spec *spec = ice->spec;
150 unsigned char data, ndata;
152 snd_assert(chip_mask >= 0 && chip_mask <= 0x0f, return -EINVAL);
153 snd_i2c_lock(ice->i2c);
154 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1)
155 goto __error;
156 ndata = (data & 0xf0) | chip_mask;
157 if (ndata != data)
158 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF2], &ndata, 1)
159 != 1)
160 goto __error;
161 snd_i2c_unlock(ice->i2c);
162 return 0;
164 __error:
165 snd_i2c_unlock(ice->i2c);
166 snd_printk(KERN_ERR "AK4524 chip select failed, check cable to the front module\n");
167 return -EIO;
170 /* start callback for EWS88MT, needs to select a certain chip mask */
171 static void ews88mt_ak4524_lock(struct snd_akm4xxx *ak, int chip)
173 struct snd_ice1712 *ice = ak->private_data[0];
174 unsigned char tmp;
175 /* assert AK4524 CS */
176 if (snd_ice1712_ews88mt_chip_select(ice, ~(1 << chip) & 0x0f) < 0)
177 snd_printk(KERN_ERR "fatal error (ews88mt chip select)\n");
178 snd_ice1712_save_gpio_status(ice);
179 tmp = ICE1712_EWS88_SERIAL_DATA |
180 ICE1712_EWS88_SERIAL_CLOCK |
181 ICE1712_EWS88_RW;
182 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
183 ice->gpio.direction | tmp);
184 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
187 /* stop callback for EWS88MT, needs to deselect chip mask */
188 static void ews88mt_ak4524_unlock(struct snd_akm4xxx *ak, int chip)
190 struct snd_ice1712 *ice = ak->private_data[0];
191 snd_ice1712_restore_gpio_status(ice);
192 udelay(1);
193 snd_ice1712_ews88mt_chip_select(ice, 0x0f);
196 /* start callback for EWX24/96 */
197 static void ewx2496_ak4524_lock(struct snd_akm4xxx *ak, int chip)
199 struct snd_ice1712 *ice = ak->private_data[0];
200 unsigned char tmp;
201 snd_ice1712_save_gpio_status(ice);
202 tmp = ICE1712_EWX2496_SERIAL_DATA |
203 ICE1712_EWX2496_SERIAL_CLOCK |
204 ICE1712_EWX2496_AK4524_CS |
205 ICE1712_EWX2496_RW;
206 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
207 ice->gpio.direction | tmp);
208 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
211 /* start callback for DMX 6fire */
212 static void dmx6fire_ak4524_lock(struct snd_akm4xxx *ak, int chip)
214 struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
215 struct snd_ice1712 *ice = ak->private_data[0];
216 unsigned char tmp;
217 snd_ice1712_save_gpio_status(ice);
218 tmp = priv->cs_mask = priv->cs_addr = (1 << chip) & ICE1712_6FIRE_AK4524_CS_MASK;
219 tmp |= ICE1712_6FIRE_SERIAL_DATA |
220 ICE1712_6FIRE_SERIAL_CLOCK |
221 ICE1712_6FIRE_RW;
222 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
223 ice->gpio.direction | tmp);
224 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
228 * CS8404 interface on EWS88MT/D
231 static void snd_ice1712_ews_cs8404_spdif_write(struct snd_ice1712 *ice, unsigned char bits)
233 struct ews_spec *spec = ice->spec;
234 unsigned char bytes[2];
236 snd_i2c_lock(ice->i2c);
237 switch (ice->eeprom.subvendor) {
238 case ICE1712_SUBDEVICE_EWS88MT:
239 case ICE1712_SUBDEVICE_EWS88MT_NEW:
240 case ICE1712_SUBDEVICE_PHASE88:
241 case ICE1712_SUBDEVICE_TS88:
242 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_CS8404], &bits, 1)
243 != 1)
244 goto _error;
245 break;
246 case ICE1712_SUBDEVICE_EWS88D:
247 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], bytes, 2)
248 != 2)
249 goto _error;
250 if (bits != bytes[1]) {
251 bytes[1] = bits;
252 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_88D],
253 bytes, 2) != 2)
254 goto _error;
256 break;
258 _error:
259 snd_i2c_unlock(ice->i2c);
265 static void ews88_spdif_default_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
267 snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_bits);
270 static int ews88_spdif_default_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
272 unsigned int val;
273 int change;
275 val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
276 spin_lock_irq(&ice->reg_lock);
277 change = ice->spdif.cs8403_bits != val;
278 ice->spdif.cs8403_bits = val;
279 if (change && ice->playback_pro_substream == NULL) {
280 spin_unlock_irq(&ice->reg_lock);
281 snd_ice1712_ews_cs8404_spdif_write(ice, val);
282 } else {
283 spin_unlock_irq(&ice->reg_lock);
285 return change;
288 static void ews88_spdif_stream_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
290 snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_stream_bits);
293 static int ews88_spdif_stream_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
295 unsigned int val;
296 int change;
298 val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
299 spin_lock_irq(&ice->reg_lock);
300 change = ice->spdif.cs8403_stream_bits != val;
301 ice->spdif.cs8403_stream_bits = val;
302 if (change && ice->playback_pro_substream != NULL) {
303 spin_unlock_irq(&ice->reg_lock);
304 snd_ice1712_ews_cs8404_spdif_write(ice, val);
305 } else {
306 spin_unlock_irq(&ice->reg_lock);
308 return change;
312 /* open callback */
313 static void ews88_open_spdif(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
315 ice->spdif.cs8403_stream_bits = ice->spdif.cs8403_bits;
318 /* set up SPDIF for EWS88MT / EWS88D */
319 static void ews88_setup_spdif(struct snd_ice1712 *ice, int rate)
321 unsigned long flags;
322 unsigned char tmp;
323 int change;
325 spin_lock_irqsave(&ice->reg_lock, flags);
326 tmp = ice->spdif.cs8403_stream_bits;
327 if (tmp & 0x10) /* consumer */
328 tmp &= (tmp & 0x01) ? ~0x06 : ~0x60;
329 switch (rate) {
330 case 32000: tmp |= (tmp & 0x01) ? 0x02 : 0x00; break;
331 case 44100: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
332 case 48000: tmp |= (tmp & 0x01) ? 0x04 : 0x20; break;
333 default: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
335 change = ice->spdif.cs8403_stream_bits != tmp;
336 ice->spdif.cs8403_stream_bits = tmp;
337 spin_unlock_irqrestore(&ice->reg_lock, flags);
338 if (change)
339 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &ice->spdif.stream_ctl->id);
340 snd_ice1712_ews_cs8404_spdif_write(ice, tmp);
346 static struct snd_akm4xxx akm_ews88mt __devinitdata = {
347 .num_adcs = 8,
348 .num_dacs = 8,
349 .type = SND_AK4524,
350 .ops = {
351 .lock = ews88mt_ak4524_lock,
352 .unlock = ews88mt_ak4524_unlock
356 static struct snd_ak4xxx_private akm_ews88mt_priv __devinitdata = {
357 .caddr = 2,
358 .cif = 1, /* CIF high */
359 .data_mask = ICE1712_EWS88_SERIAL_DATA,
360 .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
361 .cs_mask = 0,
362 .cs_addr = 0,
363 .cs_none = 0, /* no chip select on gpio */
364 .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
365 .mask_flags = 0,
368 static struct snd_akm4xxx akm_ewx2496 __devinitdata = {
369 .num_adcs = 2,
370 .num_dacs = 2,
371 .type = SND_AK4524,
372 .ops = {
373 .lock = ewx2496_ak4524_lock
377 static struct snd_ak4xxx_private akm_ewx2496_priv __devinitdata = {
378 .caddr = 2,
379 .cif = 1, /* CIF high */
380 .data_mask = ICE1712_EWS88_SERIAL_DATA,
381 .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
382 .cs_mask = ICE1712_EWX2496_AK4524_CS,
383 .cs_addr = ICE1712_EWX2496_AK4524_CS,
384 .cs_none = 0,
385 .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
386 .mask_flags = 0,
389 static struct snd_akm4xxx akm_6fire __devinitdata = {
390 .num_adcs = 6,
391 .num_dacs = 6,
392 .type = SND_AK4524,
393 .ops = {
394 .lock = dmx6fire_ak4524_lock
398 static struct snd_ak4xxx_private akm_6fire_priv __devinitdata = {
399 .caddr = 2,
400 .cif = 1, /* CIF high */
401 .data_mask = ICE1712_6FIRE_SERIAL_DATA,
402 .clk_mask = ICE1712_6FIRE_SERIAL_CLOCK,
403 .cs_mask = 0,
404 .cs_addr = 0, /* set later */
405 .cs_none = 0,
406 .add_flags = ICE1712_6FIRE_RW, /* set rw bit high */
407 .mask_flags = 0,
411 * initialize the chip
414 /* 6fire specific */
415 #define PCF9554_REG_INPUT 0
416 #define PCF9554_REG_OUTPUT 1
417 #define PCF9554_REG_POLARITY 2
418 #define PCF9554_REG_CONFIG 3
420 static int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data);
422 static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice)
424 int err;
425 struct snd_akm4xxx *ak;
426 struct ews_spec *spec;
428 /* set the analog DACs */
429 switch (ice->eeprom.subvendor) {
430 case ICE1712_SUBDEVICE_EWX2496:
431 ice->num_total_dacs = 2;
432 ice->num_total_adcs = 2;
433 break;
434 case ICE1712_SUBDEVICE_EWS88MT:
435 case ICE1712_SUBDEVICE_EWS88MT_NEW:
436 case ICE1712_SUBDEVICE_PHASE88:
437 case ICE1712_SUBDEVICE_TS88:
438 ice->num_total_dacs = 8;
439 ice->num_total_adcs = 8;
440 break;
441 case ICE1712_SUBDEVICE_EWS88D:
442 /* Note: not analog but ADAT I/O */
443 ice->num_total_dacs = 8;
444 ice->num_total_adcs = 8;
445 break;
446 case ICE1712_SUBDEVICE_DMX6FIRE:
447 ice->num_total_dacs = 6;
448 ice->num_total_adcs = 6;
449 break;
452 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
453 if (!spec)
454 return -ENOMEM;
455 ice->spec = spec;
457 /* create i2c */
458 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
459 snd_printk(KERN_ERR "unable to create I2C bus\n");
460 return err;
462 ice->i2c->private_data = ice;
463 ice->i2c->hw_ops.bit = &snd_ice1712_ewx_cs8427_bit_ops;
465 /* create i2c devices */
466 switch (ice->eeprom.subvendor) {
467 case ICE1712_SUBDEVICE_DMX6FIRE:
468 err = snd_i2c_device_create(ice->i2c, "PCF9554",
469 ICE1712_6FIRE_PCF9554_ADDR,
470 &spec->i2cdevs[EWS_I2C_6FIRE]);
471 if (err < 0) {
472 snd_printk(KERN_ERR "PCF9554 initialization failed\n");
473 return err;
475 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80);
476 break;
477 case ICE1712_SUBDEVICE_EWS88MT:
478 case ICE1712_SUBDEVICE_EWS88MT_NEW:
479 case ICE1712_SUBDEVICE_PHASE88:
480 case ICE1712_SUBDEVICE_TS88:
482 err = snd_i2c_device_create(ice->i2c, "CS8404",
483 ICE1712_EWS88MT_CS8404_ADDR,
484 &spec->i2cdevs[EWS_I2C_CS8404]);
485 if (err < 0)
486 return err;
487 err = snd_i2c_device_create(ice->i2c, "PCF8574 (1st)",
488 ICE1712_EWS88MT_INPUT_ADDR,
489 &spec->i2cdevs[EWS_I2C_PCF1]);
490 if (err < 0)
491 return err;
492 err = snd_i2c_device_create(ice->i2c, "PCF8574 (2nd)",
493 ICE1712_EWS88MT_OUTPUT_ADDR,
494 &spec->i2cdevs[EWS_I2C_PCF2]);
495 if (err < 0)
496 return err;
497 /* Check if the front module is connected */
498 if ((err = snd_ice1712_ews88mt_chip_select(ice, 0x0f)) < 0)
499 return err;
500 break;
501 case ICE1712_SUBDEVICE_EWS88D:
502 err = snd_i2c_device_create(ice->i2c, "PCF8575",
503 ICE1712_EWS88D_PCF_ADDR,
504 &spec->i2cdevs[EWS_I2C_88D]);
505 if (err < 0)
506 return err;
507 break;
510 /* set up SPDIF interface */
511 switch (ice->eeprom.subvendor) {
512 case ICE1712_SUBDEVICE_EWX2496:
513 if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0)
514 return err;
515 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
516 break;
517 case ICE1712_SUBDEVICE_DMX6FIRE:
518 if ((err = snd_ice1712_init_cs8427(ice, ICE1712_6FIRE_CS8427_ADDR)) < 0)
519 return err;
520 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
521 break;
522 case ICE1712_SUBDEVICE_EWS88MT:
523 case ICE1712_SUBDEVICE_EWS88MT_NEW:
524 case ICE1712_SUBDEVICE_PHASE88:
525 case ICE1712_SUBDEVICE_TS88:
526 case ICE1712_SUBDEVICE_EWS88D:
527 /* set up CS8404 */
528 ice->spdif.ops.open = ews88_open_spdif;
529 ice->spdif.ops.setup_rate = ews88_setup_spdif;
530 ice->spdif.ops.default_get = ews88_spdif_default_get;
531 ice->spdif.ops.default_put = ews88_spdif_default_put;
532 ice->spdif.ops.stream_get = ews88_spdif_stream_get;
533 ice->spdif.ops.stream_put = ews88_spdif_stream_put;
534 /* Set spdif defaults */
535 snd_ice1712_ews_cs8404_spdif_write(ice, ice->spdif.cs8403_bits);
536 break;
539 /* no analog? */
540 switch (ice->eeprom.subvendor) {
541 case ICE1712_SUBDEVICE_EWS88D:
542 return 0;
545 /* analog section */
546 ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
547 if (! ak)
548 return -ENOMEM;
549 ice->akm_codecs = 1;
551 switch (ice->eeprom.subvendor) {
552 case ICE1712_SUBDEVICE_EWS88MT:
553 case ICE1712_SUBDEVICE_EWS88MT_NEW:
554 case ICE1712_SUBDEVICE_PHASE88:
555 case ICE1712_SUBDEVICE_TS88:
556 err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice);
557 break;
558 case ICE1712_SUBDEVICE_EWX2496:
559 err = snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, &akm_ewx2496_priv, ice);
560 break;
561 case ICE1712_SUBDEVICE_DMX6FIRE:
562 err = snd_ice1712_akm4xxx_init(ak, &akm_6fire, &akm_6fire_priv, ice);
563 break;
564 default:
565 err = 0;
568 return err;
572 * EWX 24/96 specific controls
575 /* i/o sensitivity - this callback is shared among other devices, too */
576 static int snd_ice1712_ewx_io_sense_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){
578 static char *texts[2] = {
579 "+4dBu", "-10dBV",
581 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
582 uinfo->count = 1;
583 uinfo->value.enumerated.items = 2;
584 if (uinfo->value.enumerated.item >= 2)
585 uinfo->value.enumerated.item = 1;
586 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
587 return 0;
590 static int snd_ice1712_ewx_io_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
592 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
593 unsigned char mask = kcontrol->private_value & 0xff;
595 snd_ice1712_save_gpio_status(ice);
596 ucontrol->value.enumerated.item[0] = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0;
597 snd_ice1712_restore_gpio_status(ice);
598 return 0;
601 static int snd_ice1712_ewx_io_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
603 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
604 unsigned char mask = kcontrol->private_value & 0xff;
605 int val, nval;
607 if (kcontrol->private_value & (1 << 31))
608 return -EPERM;
609 nval = ucontrol->value.enumerated.item[0] ? mask : 0;
610 snd_ice1712_save_gpio_status(ice);
611 val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
612 nval |= val & ~mask;
613 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, nval);
614 snd_ice1712_restore_gpio_status(ice);
615 return val != nval;
618 static struct snd_kcontrol_new snd_ice1712_ewx2496_controls[] __devinitdata = {
620 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
621 .name = "Input Sensitivity Switch",
622 .info = snd_ice1712_ewx_io_sense_info,
623 .get = snd_ice1712_ewx_io_sense_get,
624 .put = snd_ice1712_ewx_io_sense_put,
625 .private_value = ICE1712_EWX2496_AIN_SEL,
628 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
629 .name = "Output Sensitivity Switch",
630 .info = snd_ice1712_ewx_io_sense_info,
631 .get = snd_ice1712_ewx_io_sense_get,
632 .put = snd_ice1712_ewx_io_sense_put,
633 .private_value = ICE1712_EWX2496_AOUT_SEL,
639 * EWS88MT specific controls
641 /* analog output sensitivity;; address 0x48 bit 6 */
642 static int snd_ice1712_ews88mt_output_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
644 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
645 struct ews_spec *spec = ice->spec;
646 unsigned char data;
648 snd_i2c_lock(ice->i2c);
649 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) {
650 snd_i2c_unlock(ice->i2c);
651 return -EIO;
653 snd_i2c_unlock(ice->i2c);
654 ucontrol->value.enumerated.item[0] = data & ICE1712_EWS88MT_OUTPUT_SENSE ? 1 : 0; /* high = -10dBV, low = +4dBu */
655 return 0;
658 /* analog output sensitivity;; address 0x48 bit 6 */
659 static int snd_ice1712_ews88mt_output_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
661 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
662 struct ews_spec *spec = ice->spec;
663 unsigned char data, ndata;
665 snd_i2c_lock(ice->i2c);
666 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) {
667 snd_i2c_unlock(ice->i2c);
668 return -EIO;
670 ndata = (data & ~ICE1712_EWS88MT_OUTPUT_SENSE) | (ucontrol->value.enumerated.item[0] ? ICE1712_EWS88MT_OUTPUT_SENSE : 0);
671 if (ndata != data && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF2],
672 &ndata, 1) != 1) {
673 snd_i2c_unlock(ice->i2c);
674 return -EIO;
676 snd_i2c_unlock(ice->i2c);
677 return ndata != data;
680 /* analog input sensitivity; address 0x46 */
681 static int snd_ice1712_ews88mt_input_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
683 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
684 struct ews_spec *spec = ice->spec;
685 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
686 unsigned char data;
688 snd_assert(channel >= 0 && channel <= 7, return 0);
689 snd_i2c_lock(ice->i2c);
690 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) {
691 snd_i2c_unlock(ice->i2c);
692 return -EIO;
694 /* reversed; high = +4dBu, low = -10dBV */
695 ucontrol->value.enumerated.item[0] = data & (1 << channel) ? 0 : 1;
696 snd_i2c_unlock(ice->i2c);
697 return 0;
700 /* analog output sensitivity; address 0x46 */
701 static int snd_ice1712_ews88mt_input_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
703 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
704 struct ews_spec *spec = ice->spec;
705 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
706 unsigned char data, ndata;
708 snd_assert(channel >= 0 && channel <= 7, return 0);
709 snd_i2c_lock(ice->i2c);
710 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) {
711 snd_i2c_unlock(ice->i2c);
712 return -EIO;
714 ndata = (data & ~(1 << channel)) | (ucontrol->value.enumerated.item[0] ? 0 : (1 << channel));
715 if (ndata != data && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF1],
716 &ndata, 1) != 1) {
717 snd_i2c_unlock(ice->i2c);
718 return -EIO;
720 snd_i2c_unlock(ice->i2c);
721 return ndata != data;
724 static struct snd_kcontrol_new snd_ice1712_ews88mt_input_sense __devinitdata = {
725 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
726 .name = "Input Sensitivity Switch",
727 .info = snd_ice1712_ewx_io_sense_info,
728 .get = snd_ice1712_ews88mt_input_sense_get,
729 .put = snd_ice1712_ews88mt_input_sense_put,
730 .count = 8,
733 static struct snd_kcontrol_new snd_ice1712_ews88mt_output_sense __devinitdata = {
734 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
735 .name = "Output Sensitivity Switch",
736 .info = snd_ice1712_ewx_io_sense_info,
737 .get = snd_ice1712_ews88mt_output_sense_get,
738 .put = snd_ice1712_ews88mt_output_sense_put,
743 * EWS88D specific controls
746 #define snd_ice1712_ews88d_control_info snd_ctl_boolean_mono_info
748 static int snd_ice1712_ews88d_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
750 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
751 struct ews_spec *spec = ice->spec;
752 int shift = kcontrol->private_value & 0xff;
753 int invert = (kcontrol->private_value >> 8) & 1;
754 unsigned char data[2];
756 snd_i2c_lock(ice->i2c);
757 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
758 snd_i2c_unlock(ice->i2c);
759 return -EIO;
761 snd_i2c_unlock(ice->i2c);
762 data[0] = (data[shift >> 3] >> (shift & 7)) & 0x01;
763 if (invert)
764 data[0] ^= 0x01;
765 ucontrol->value.integer.value[0] = data[0];
766 return 0;
769 static int snd_ice1712_ews88d_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
771 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
772 struct ews_spec *spec = ice->spec;
773 int shift = kcontrol->private_value & 0xff;
774 int invert = (kcontrol->private_value >> 8) & 1;
775 unsigned char data[2], ndata[2];
776 int change;
778 snd_i2c_lock(ice->i2c);
779 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
780 snd_i2c_unlock(ice->i2c);
781 return -EIO;
783 ndata[shift >> 3] = data[shift >> 3] & ~(1 << (shift & 7));
784 if (invert) {
785 if (! ucontrol->value.integer.value[0])
786 ndata[shift >> 3] |= (1 << (shift & 7));
787 } else {
788 if (ucontrol->value.integer.value[0])
789 ndata[shift >> 3] |= (1 << (shift & 7));
791 change = (data[shift >> 3] != ndata[shift >> 3]);
792 if (change &&
793 snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
794 snd_i2c_unlock(ice->i2c);
795 return -EIO;
797 snd_i2c_unlock(ice->i2c);
798 return change;
801 #define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
802 { .iface = xiface,\
803 .name = xname,\
804 .access = xaccess,\
805 .info = snd_ice1712_ews88d_control_info,\
806 .get = snd_ice1712_ews88d_control_get,\
807 .put = snd_ice1712_ews88d_control_put,\
808 .private_value = xshift | (xinvert << 8),\
811 static struct snd_kcontrol_new snd_ice1712_ews88d_controls[] __devinitdata = {
812 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, 1, 0), /* inverted */
813 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Output Optical", 1, 0, 0),
814 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT External Master Clock", 2, 0, 0),
815 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "Enable ADAT", 3, 0, 0),
816 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Through", 4, 1, 0),
821 * DMX 6Fire specific controls
824 static int snd_ice1712_6fire_read_pca(struct snd_ice1712 *ice, unsigned char reg)
826 unsigned char byte;
827 struct ews_spec *spec = ice->spec;
829 snd_i2c_lock(ice->i2c);
830 byte = reg;
831 snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1);
832 byte = 0;
833 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) {
834 snd_i2c_unlock(ice->i2c);
835 printk(KERN_ERR "cannot read pca\n");
836 return -EIO;
838 snd_i2c_unlock(ice->i2c);
839 return byte;
842 static int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data)
844 unsigned char bytes[2];
845 struct ews_spec *spec = ice->spec;
847 snd_i2c_lock(ice->i2c);
848 bytes[0] = reg;
849 bytes[1] = data;
850 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_6FIRE], bytes, 2) != 2) {
851 snd_i2c_unlock(ice->i2c);
852 return -EIO;
854 snd_i2c_unlock(ice->i2c);
855 return 0;
858 #define snd_ice1712_6fire_control_info snd_ctl_boolean_mono_info
860 static int snd_ice1712_6fire_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
862 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
863 int shift = kcontrol->private_value & 0xff;
864 int invert = (kcontrol->private_value >> 8) & 1;
865 int data;
867 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
868 return data;
869 data = (data >> shift) & 1;
870 if (invert)
871 data ^= 1;
872 ucontrol->value.integer.value[0] = data;
873 return 0;
876 static int snd_ice1712_6fire_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
878 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
879 int shift = kcontrol->private_value & 0xff;
880 int invert = (kcontrol->private_value >> 8) & 1;
881 int data, ndata;
883 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
884 return data;
885 ndata = data & ~(1 << shift);
886 if (ucontrol->value.integer.value[0])
887 ndata |= (1 << shift);
888 if (invert)
889 ndata ^= (1 << shift);
890 if (data != ndata) {
891 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
892 return 1;
894 return 0;
897 static int snd_ice1712_6fire_select_input_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
899 static char *texts[4] = {
900 "Internal", "Front Input", "Rear Input", "Wave Table"
902 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
903 uinfo->count = 1;
904 uinfo->value.enumerated.items = 4;
905 if (uinfo->value.enumerated.item >= 4)
906 uinfo->value.enumerated.item = 1;
907 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
908 return 0;
911 static int snd_ice1712_6fire_select_input_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
913 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
914 int data;
916 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
917 return data;
918 ucontrol->value.integer.value[0] = data & 3;
919 return 0;
922 static int snd_ice1712_6fire_select_input_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
924 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
925 int data, ndata;
927 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
928 return data;
929 ndata = data & ~3;
930 ndata |= (ucontrol->value.integer.value[0] & 3);
931 if (data != ndata) {
932 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
933 return 1;
935 return 0;
939 #define DMX6FIRE_CONTROL(xname, xshift, xinvert) \
940 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
941 .name = xname,\
942 .info = snd_ice1712_6fire_control_info,\
943 .get = snd_ice1712_6fire_control_get,\
944 .put = snd_ice1712_6fire_control_put,\
945 .private_value = xshift | (xinvert << 8),\
948 static struct snd_kcontrol_new snd_ice1712_6fire_controls[] __devinitdata = {
950 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
951 .name = "Analog Input Select",
952 .info = snd_ice1712_6fire_select_input_info,
953 .get = snd_ice1712_6fire_select_input_get,
954 .put = snd_ice1712_6fire_select_input_put,
956 DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 1),
957 // DMX6FIRE_CONTROL("Master Clock Select", 3, 0),
958 DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0),
959 DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0),
960 DMX6FIRE_CONTROL("Breakbox LED", 6, 0),
964 static int __devinit snd_ice1712_ews_add_controls(struct snd_ice1712 *ice)
966 unsigned int idx;
967 int err;
969 /* all terratec cards have spdif, but cs8427 module builds it's own controls */
970 if (ice->cs8427 == NULL) {
971 err = snd_ice1712_spdif_build_controls(ice);
972 if (err < 0)
973 return err;
976 /* ak4524 controls */
977 switch (ice->eeprom.subvendor) {
978 case ICE1712_SUBDEVICE_EWX2496:
979 case ICE1712_SUBDEVICE_EWS88MT:
980 case ICE1712_SUBDEVICE_EWS88MT_NEW:
981 case ICE1712_SUBDEVICE_PHASE88:
982 case ICE1712_SUBDEVICE_TS88:
983 case ICE1712_SUBDEVICE_DMX6FIRE:
984 err = snd_ice1712_akm4xxx_build_controls(ice);
985 if (err < 0)
986 return err;
987 break;
990 /* card specific controls */
991 switch (ice->eeprom.subvendor) {
992 case ICE1712_SUBDEVICE_EWX2496:
993 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ewx2496_controls); idx++) {
994 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ewx2496_controls[idx], ice));
995 if (err < 0)
996 return err;
998 break;
999 case ICE1712_SUBDEVICE_EWS88MT:
1000 case ICE1712_SUBDEVICE_EWS88MT_NEW:
1001 case ICE1712_SUBDEVICE_PHASE88:
1002 case ICE1712_SUBDEVICE_TS88:
1003 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice));
1004 if (err < 0)
1005 return err;
1006 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense, ice));
1007 if (err < 0)
1008 return err;
1009 break;
1010 case ICE1712_SUBDEVICE_EWS88D:
1011 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ews88d_controls); idx++) {
1012 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_controls[idx], ice));
1013 if (err < 0)
1014 return err;
1016 break;
1017 case ICE1712_SUBDEVICE_DMX6FIRE:
1018 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_6fire_controls); idx++) {
1019 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_6fire_controls[idx], ice));
1020 if (err < 0)
1021 return err;
1023 break;
1025 return 0;
1029 /* entry point */
1030 struct snd_ice1712_card_info snd_ice1712_ews_cards[] __devinitdata = {
1032 .subvendor = ICE1712_SUBDEVICE_EWX2496,
1033 .name = "TerraTec EWX24/96",
1034 .model = "ewx2496",
1035 .chip_init = snd_ice1712_ews_init,
1036 .build_controls = snd_ice1712_ews_add_controls,
1039 .subvendor = ICE1712_SUBDEVICE_EWS88MT,
1040 .name = "TerraTec EWS88MT",
1041 .model = "ews88mt",
1042 .chip_init = snd_ice1712_ews_init,
1043 .build_controls = snd_ice1712_ews_add_controls,
1046 .subvendor = ICE1712_SUBDEVICE_EWS88MT_NEW,
1047 .name = "TerraTec EWS88MT",
1048 .model = "ews88mt_new",
1049 .chip_init = snd_ice1712_ews_init,
1050 .build_controls = snd_ice1712_ews_add_controls,
1053 .subvendor = ICE1712_SUBDEVICE_PHASE88,
1054 .name = "TerraTec Phase88",
1055 .model = "phase88",
1056 .chip_init = snd_ice1712_ews_init,
1057 .build_controls = snd_ice1712_ews_add_controls,
1060 .subvendor = ICE1712_SUBDEVICE_TS88,
1061 .name = "terrasoniq TS88",
1062 .model = "phase88",
1063 .chip_init = snd_ice1712_ews_init,
1064 .build_controls = snd_ice1712_ews_add_controls,
1067 .subvendor = ICE1712_SUBDEVICE_EWS88D,
1068 .name = "TerraTec EWS88D",
1069 .model = "ews88d",
1070 .chip_init = snd_ice1712_ews_init,
1071 .build_controls = snd_ice1712_ews_add_controls,
1074 .subvendor = ICE1712_SUBDEVICE_DMX6FIRE,
1075 .name = "TerraTec DMX6Fire",
1076 .model = "dmx6fire",
1077 .chip_init = snd_ice1712_ews_init,
1078 .build_controls = snd_ice1712_ews_add_controls,
1079 .mpu401_1_name = "MIDI-Front DMX6fire",
1080 .mpu401_2_name = "Wavetable DMX6fire",
1081 .mpu401_2_info_flags = MPU401_INFO_OUTPUT,
1083 { } /* terminator */