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
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>
38 #include <sound/cs8403.h>
41 EWS_I2C_CS8404 = 0, EWS_I2C_PCF1, EWS_I2C_PCF2,
47 /* additional i2c devices for EWS boards */
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;
62 tmp |= ICE1712_EWX2496_SERIAL_CLOCK;
64 tmp |= ICE1712_EWX2496_SERIAL_DATA;
65 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
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;
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);
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);
92 static void ewx_i2c_start(struct snd_i2c_bus *bus)
94 struct snd_ice1712 *ice = bus->private_data;
97 snd_ice1712_save_gpio_status(ice);
99 mask = ICE1712_EWX2496_RW;
100 switch (ice->eeprom.subvendor) {
101 case ICE1712_SUBDEVICE_EWX2496:
102 mask |= ICE1712_EWX2496_AK4524_CS; /* CS high also */
104 case ICE1712_SUBDEVICE_DMX6FIRE:
105 mask |= ICE1712_6FIRE_AK4524_CS_MASK; /* CS high also */
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;
123 mask |= ICE1712_EWX2496_SERIAL_CLOCK; /* write SCL */
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,
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)
156 ndata = (data & 0xf0) | chip_mask;
158 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF2], &ndata, 1)
161 snd_i2c_unlock(ice->i2c);
165 snd_i2c_unlock(ice->i2c);
166 snd_printk(KERN_ERR "AK4524 chip select failed, check cable to the front module\n");
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];
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 |
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);
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];
201 snd_ice1712_save_gpio_status(ice);
202 tmp = ICE1712_EWX2496_SERIAL_DATA |
203 ICE1712_EWX2496_SERIAL_CLOCK |
204 ICE1712_EWX2496_AK4524_CS |
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];
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 |
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 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_CS8404], &bits, 1)
245 case ICE1712_SUBDEVICE_EWS88D:
246 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], bytes, 2)
249 if (bits != bytes[1]) {
251 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_88D],
258 snd_i2c_unlock(ice->i2c);
264 static void ews88_spdif_default_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
266 snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_bits);
269 static int ews88_spdif_default_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
274 val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
275 spin_lock_irq(&ice->reg_lock);
276 change = ice->spdif.cs8403_bits != val;
277 ice->spdif.cs8403_bits = val;
278 if (change && ice->playback_pro_substream == NULL) {
279 spin_unlock_irq(&ice->reg_lock);
280 snd_ice1712_ews_cs8404_spdif_write(ice, val);
282 spin_unlock_irq(&ice->reg_lock);
287 static void ews88_spdif_stream_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
289 snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_stream_bits);
292 static int ews88_spdif_stream_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
297 val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
298 spin_lock_irq(&ice->reg_lock);
299 change = ice->spdif.cs8403_stream_bits != val;
300 ice->spdif.cs8403_stream_bits = val;
301 if (change && ice->playback_pro_substream != NULL) {
302 spin_unlock_irq(&ice->reg_lock);
303 snd_ice1712_ews_cs8404_spdif_write(ice, val);
305 spin_unlock_irq(&ice->reg_lock);
312 static void ews88_open_spdif(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
314 ice->spdif.cs8403_stream_bits = ice->spdif.cs8403_bits;
317 /* set up SPDIF for EWS88MT / EWS88D */
318 static void ews88_setup_spdif(struct snd_ice1712 *ice, int rate)
324 spin_lock_irqsave(&ice->reg_lock, flags);
325 tmp = ice->spdif.cs8403_stream_bits;
326 if (tmp & 0x10) /* consumer */
327 tmp &= (tmp & 0x01) ? ~0x06 : ~0x60;
329 case 32000: tmp |= (tmp & 0x01) ? 0x02 : 0x00; break;
330 case 44100: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
331 case 48000: tmp |= (tmp & 0x01) ? 0x04 : 0x20; break;
332 default: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
334 change = ice->spdif.cs8403_stream_bits != tmp;
335 ice->spdif.cs8403_stream_bits = tmp;
336 spin_unlock_irqrestore(&ice->reg_lock, flags);
338 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &ice->spdif.stream_ctl->id);
339 snd_ice1712_ews_cs8404_spdif_write(ice, tmp);
345 static struct snd_akm4xxx akm_ews88mt __devinitdata = {
350 .lock = ews88mt_ak4524_lock,
351 .unlock = ews88mt_ak4524_unlock
355 static struct snd_ak4xxx_private akm_ews88mt_priv __devinitdata = {
357 .cif = 1, /* CIF high */
358 .data_mask = ICE1712_EWS88_SERIAL_DATA,
359 .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
362 .cs_none = 0, /* no chip select on gpio */
363 .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
367 static struct snd_akm4xxx akm_ewx2496 __devinitdata = {
372 .lock = ewx2496_ak4524_lock
376 static struct snd_ak4xxx_private akm_ewx2496_priv __devinitdata = {
378 .cif = 1, /* CIF high */
379 .data_mask = ICE1712_EWS88_SERIAL_DATA,
380 .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
381 .cs_mask = ICE1712_EWX2496_AK4524_CS,
382 .cs_addr = ICE1712_EWX2496_AK4524_CS,
384 .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
388 static struct snd_akm4xxx akm_6fire __devinitdata = {
393 .lock = dmx6fire_ak4524_lock
397 static struct snd_ak4xxx_private akm_6fire_priv __devinitdata = {
399 .cif = 1, /* CIF high */
400 .data_mask = ICE1712_6FIRE_SERIAL_DATA,
401 .clk_mask = ICE1712_6FIRE_SERIAL_CLOCK,
403 .cs_addr = 0, /* set later */
405 .add_flags = ICE1712_6FIRE_RW, /* set rw bit high */
410 * initialize the chip
414 #define PCF9554_REG_INPUT 0
415 #define PCF9554_REG_OUTPUT 1
416 #define PCF9554_REG_POLARITY 2
417 #define PCF9554_REG_CONFIG 3
419 static int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data);
421 static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice)
424 struct snd_akm4xxx *ak;
425 struct ews_spec *spec;
427 /* set the analog DACs */
428 switch (ice->eeprom.subvendor) {
429 case ICE1712_SUBDEVICE_EWX2496:
430 ice->num_total_dacs = 2;
431 ice->num_total_adcs = 2;
433 case ICE1712_SUBDEVICE_EWS88MT:
434 case ICE1712_SUBDEVICE_EWS88MT_NEW:
435 case ICE1712_SUBDEVICE_PHASE88:
436 ice->num_total_dacs = 8;
437 ice->num_total_adcs = 8;
439 case ICE1712_SUBDEVICE_EWS88D:
440 /* Note: not analog but ADAT I/O */
441 ice->num_total_dacs = 8;
442 ice->num_total_adcs = 8;
444 case ICE1712_SUBDEVICE_DMX6FIRE:
445 ice->num_total_dacs = 6;
446 ice->num_total_adcs = 6;
450 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
456 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
457 snd_printk(KERN_ERR "unable to create I2C bus\n");
460 ice->i2c->private_data = ice;
461 ice->i2c->hw_ops.bit = &snd_ice1712_ewx_cs8427_bit_ops;
463 /* create i2c devices */
464 switch (ice->eeprom.subvendor) {
465 case ICE1712_SUBDEVICE_DMX6FIRE:
466 err = snd_i2c_device_create(ice->i2c, "PCF9554",
467 ICE1712_6FIRE_PCF9554_ADDR,
468 &spec->i2cdevs[EWS_I2C_6FIRE]);
470 snd_printk(KERN_ERR "PCF9554 initialization failed\n");
473 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80);
475 case ICE1712_SUBDEVICE_EWS88MT:
476 case ICE1712_SUBDEVICE_EWS88MT_NEW:
477 case ICE1712_SUBDEVICE_PHASE88:
478 err = snd_i2c_device_create(ice->i2c, "CS8404",
479 ICE1712_EWS88MT_CS8404_ADDR,
480 &spec->i2cdevs[EWS_I2C_CS8404]);
483 err = snd_i2c_device_create(ice->i2c, "PCF8574 (1st)",
484 ICE1712_EWS88MT_INPUT_ADDR,
485 &spec->i2cdevs[EWS_I2C_PCF1]);
488 err = snd_i2c_device_create(ice->i2c, "PCF8574 (2nd)",
489 ICE1712_EWS88MT_OUTPUT_ADDR,
490 &spec->i2cdevs[EWS_I2C_PCF2]);
493 /* Check if the front module is connected */
494 if ((err = snd_ice1712_ews88mt_chip_select(ice, 0x0f)) < 0)
497 case ICE1712_SUBDEVICE_EWS88D:
498 err = snd_i2c_device_create(ice->i2c, "PCF8575",
499 ICE1712_EWS88D_PCF_ADDR,
500 &spec->i2cdevs[EWS_I2C_88D]);
506 /* set up SPDIF interface */
507 switch (ice->eeprom.subvendor) {
508 case ICE1712_SUBDEVICE_EWX2496:
509 if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0)
511 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
513 case ICE1712_SUBDEVICE_DMX6FIRE:
514 if ((err = snd_ice1712_init_cs8427(ice, ICE1712_6FIRE_CS8427_ADDR)) < 0)
516 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
518 case ICE1712_SUBDEVICE_EWS88MT:
519 case ICE1712_SUBDEVICE_EWS88MT_NEW:
520 case ICE1712_SUBDEVICE_PHASE88:
521 case ICE1712_SUBDEVICE_EWS88D:
523 ice->spdif.ops.open = ews88_open_spdif;
524 ice->spdif.ops.setup_rate = ews88_setup_spdif;
525 ice->spdif.ops.default_get = ews88_spdif_default_get;
526 ice->spdif.ops.default_put = ews88_spdif_default_put;
527 ice->spdif.ops.stream_get = ews88_spdif_stream_get;
528 ice->spdif.ops.stream_put = ews88_spdif_stream_put;
529 /* Set spdif defaults */
530 snd_ice1712_ews_cs8404_spdif_write(ice, ice->spdif.cs8403_bits);
535 switch (ice->eeprom.subvendor) {
536 case ICE1712_SUBDEVICE_EWS88D:
541 ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
546 switch (ice->eeprom.subvendor) {
547 case ICE1712_SUBDEVICE_EWS88MT:
548 case ICE1712_SUBDEVICE_EWS88MT_NEW:
549 case ICE1712_SUBDEVICE_PHASE88:
550 err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice);
552 case ICE1712_SUBDEVICE_EWX2496:
553 err = snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, &akm_ewx2496_priv, ice);
555 case ICE1712_SUBDEVICE_DMX6FIRE:
556 err = snd_ice1712_akm4xxx_init(ak, &akm_6fire, &akm_6fire_priv, ice);
566 * EWX 24/96 specific controls
569 /* i/o sensitivity - this callback is shared among other devices, too */
570 static int snd_ice1712_ewx_io_sense_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){
572 static char *texts[2] = {
575 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
577 uinfo->value.enumerated.items = 2;
578 if (uinfo->value.enumerated.item >= 2)
579 uinfo->value.enumerated.item = 1;
580 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
584 static int snd_ice1712_ewx_io_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
586 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
587 unsigned char mask = kcontrol->private_value & 0xff;
589 snd_ice1712_save_gpio_status(ice);
590 ucontrol->value.enumerated.item[0] = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0;
591 snd_ice1712_restore_gpio_status(ice);
595 static int snd_ice1712_ewx_io_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
597 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
598 unsigned char mask = kcontrol->private_value & 0xff;
601 if (kcontrol->private_value & (1 << 31))
603 nval = ucontrol->value.enumerated.item[0] ? mask : 0;
604 snd_ice1712_save_gpio_status(ice);
605 val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
607 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, nval);
608 snd_ice1712_restore_gpio_status(ice);
612 static struct snd_kcontrol_new snd_ice1712_ewx2496_controls[] __devinitdata = {
614 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
615 .name = "Input Sensitivity Switch",
616 .info = snd_ice1712_ewx_io_sense_info,
617 .get = snd_ice1712_ewx_io_sense_get,
618 .put = snd_ice1712_ewx_io_sense_put,
619 .private_value = ICE1712_EWX2496_AIN_SEL,
622 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
623 .name = "Output Sensitivity Switch",
624 .info = snd_ice1712_ewx_io_sense_info,
625 .get = snd_ice1712_ewx_io_sense_get,
626 .put = snd_ice1712_ewx_io_sense_put,
627 .private_value = ICE1712_EWX2496_AOUT_SEL,
633 * EWS88MT specific controls
635 /* analog output sensitivity;; address 0x48 bit 6 */
636 static int snd_ice1712_ews88mt_output_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
638 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
639 struct ews_spec *spec = ice->spec;
642 snd_i2c_lock(ice->i2c);
643 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) {
644 snd_i2c_unlock(ice->i2c);
647 snd_i2c_unlock(ice->i2c);
648 ucontrol->value.enumerated.item[0] = data & ICE1712_EWS88MT_OUTPUT_SENSE ? 1 : 0; /* high = -10dBV, low = +4dBu */
652 /* analog output sensitivity;; address 0x48 bit 6 */
653 static int snd_ice1712_ews88mt_output_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
655 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
656 struct ews_spec *spec = ice->spec;
657 unsigned char data, ndata;
659 snd_i2c_lock(ice->i2c);
660 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) {
661 snd_i2c_unlock(ice->i2c);
664 ndata = (data & ~ICE1712_EWS88MT_OUTPUT_SENSE) | (ucontrol->value.enumerated.item[0] ? ICE1712_EWS88MT_OUTPUT_SENSE : 0);
665 if (ndata != data && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF2],
667 snd_i2c_unlock(ice->i2c);
670 snd_i2c_unlock(ice->i2c);
671 return ndata != data;
674 /* analog input sensitivity; address 0x46 */
675 static int snd_ice1712_ews88mt_input_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
677 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
678 struct ews_spec *spec = ice->spec;
679 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
682 snd_assert(channel >= 0 && channel <= 7, return 0);
683 snd_i2c_lock(ice->i2c);
684 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) {
685 snd_i2c_unlock(ice->i2c);
688 /* reversed; high = +4dBu, low = -10dBV */
689 ucontrol->value.enumerated.item[0] = data & (1 << channel) ? 0 : 1;
690 snd_i2c_unlock(ice->i2c);
694 /* analog output sensitivity; address 0x46 */
695 static int snd_ice1712_ews88mt_input_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
697 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
698 struct ews_spec *spec = ice->spec;
699 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
700 unsigned char data, ndata;
702 snd_assert(channel >= 0 && channel <= 7, return 0);
703 snd_i2c_lock(ice->i2c);
704 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) {
705 snd_i2c_unlock(ice->i2c);
708 ndata = (data & ~(1 << channel)) | (ucontrol->value.enumerated.item[0] ? 0 : (1 << channel));
709 if (ndata != data && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF1],
711 snd_i2c_unlock(ice->i2c);
714 snd_i2c_unlock(ice->i2c);
715 return ndata != data;
718 static struct snd_kcontrol_new snd_ice1712_ews88mt_input_sense __devinitdata = {
719 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
720 .name = "Input Sensitivity Switch",
721 .info = snd_ice1712_ewx_io_sense_info,
722 .get = snd_ice1712_ews88mt_input_sense_get,
723 .put = snd_ice1712_ews88mt_input_sense_put,
727 static struct snd_kcontrol_new snd_ice1712_ews88mt_output_sense __devinitdata = {
728 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
729 .name = "Output Sensitivity Switch",
730 .info = snd_ice1712_ewx_io_sense_info,
731 .get = snd_ice1712_ews88mt_output_sense_get,
732 .put = snd_ice1712_ews88mt_output_sense_put,
737 * EWS88D specific controls
740 #define snd_ice1712_ews88d_control_info snd_ctl_boolean_mono_info
742 static int snd_ice1712_ews88d_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
744 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
745 struct ews_spec *spec = ice->spec;
746 int shift = kcontrol->private_value & 0xff;
747 int invert = (kcontrol->private_value >> 8) & 1;
748 unsigned char data[2];
750 snd_i2c_lock(ice->i2c);
751 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
752 snd_i2c_unlock(ice->i2c);
755 snd_i2c_unlock(ice->i2c);
756 data[0] = (data[shift >> 3] >> (shift & 7)) & 0x01;
759 ucontrol->value.integer.value[0] = data[0];
763 static int snd_ice1712_ews88d_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
765 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
766 struct ews_spec *spec = ice->spec;
767 int shift = kcontrol->private_value & 0xff;
768 int invert = (kcontrol->private_value >> 8) & 1;
769 unsigned char data[2], ndata[2];
772 snd_i2c_lock(ice->i2c);
773 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
774 snd_i2c_unlock(ice->i2c);
777 ndata[shift >> 3] = data[shift >> 3] & ~(1 << (shift & 7));
779 if (! ucontrol->value.integer.value[0])
780 ndata[shift >> 3] |= (1 << (shift & 7));
782 if (ucontrol->value.integer.value[0])
783 ndata[shift >> 3] |= (1 << (shift & 7));
785 change = (data[shift >> 3] != ndata[shift >> 3]);
787 snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
788 snd_i2c_unlock(ice->i2c);
791 snd_i2c_unlock(ice->i2c);
795 #define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
799 .info = snd_ice1712_ews88d_control_info,\
800 .get = snd_ice1712_ews88d_control_get,\
801 .put = snd_ice1712_ews88d_control_put,\
802 .private_value = xshift | (xinvert << 8),\
805 static struct snd_kcontrol_new snd_ice1712_ews88d_controls[] __devinitdata = {
806 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, 1, 0), /* inverted */
807 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Output Optical", 1, 0, 0),
808 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT External Master Clock", 2, 0, 0),
809 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "Enable ADAT", 3, 0, 0),
810 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Through", 4, 1, 0),
815 * DMX 6Fire specific controls
818 static int snd_ice1712_6fire_read_pca(struct snd_ice1712 *ice, unsigned char reg)
821 struct ews_spec *spec = ice->spec;
823 snd_i2c_lock(ice->i2c);
825 snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1);
827 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) {
828 snd_i2c_unlock(ice->i2c);
829 printk(KERN_ERR "cannot read pca\n");
832 snd_i2c_unlock(ice->i2c);
836 static int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data)
838 unsigned char bytes[2];
839 struct ews_spec *spec = ice->spec;
841 snd_i2c_lock(ice->i2c);
844 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_6FIRE], bytes, 2) != 2) {
845 snd_i2c_unlock(ice->i2c);
848 snd_i2c_unlock(ice->i2c);
852 #define snd_ice1712_6fire_control_info snd_ctl_boolean_mono_info
854 static int snd_ice1712_6fire_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
856 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
857 int shift = kcontrol->private_value & 0xff;
858 int invert = (kcontrol->private_value >> 8) & 1;
861 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
863 data = (data >> shift) & 1;
866 ucontrol->value.integer.value[0] = data;
870 static int snd_ice1712_6fire_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
872 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
873 int shift = kcontrol->private_value & 0xff;
874 int invert = (kcontrol->private_value >> 8) & 1;
877 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
879 ndata = data & ~(1 << shift);
880 if (ucontrol->value.integer.value[0])
881 ndata |= (1 << shift);
883 ndata ^= (1 << shift);
885 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
891 static int snd_ice1712_6fire_select_input_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
893 static char *texts[4] = {
894 "Internal", "Front Input", "Rear Input", "Wave Table"
896 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
898 uinfo->value.enumerated.items = 4;
899 if (uinfo->value.enumerated.item >= 4)
900 uinfo->value.enumerated.item = 1;
901 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
905 static int snd_ice1712_6fire_select_input_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
907 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
910 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
912 ucontrol->value.integer.value[0] = data & 3;
916 static int snd_ice1712_6fire_select_input_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
918 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
921 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
924 ndata |= (ucontrol->value.integer.value[0] & 3);
926 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
933 #define DMX6FIRE_CONTROL(xname, xshift, xinvert) \
934 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
936 .info = snd_ice1712_6fire_control_info,\
937 .get = snd_ice1712_6fire_control_get,\
938 .put = snd_ice1712_6fire_control_put,\
939 .private_value = xshift | (xinvert << 8),\
942 static struct snd_kcontrol_new snd_ice1712_6fire_controls[] __devinitdata = {
944 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
945 .name = "Analog Input Select",
946 .info = snd_ice1712_6fire_select_input_info,
947 .get = snd_ice1712_6fire_select_input_get,
948 .put = snd_ice1712_6fire_select_input_put,
950 DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 1),
951 // DMX6FIRE_CONTROL("Master Clock Select", 3, 0),
952 DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0),
953 DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0),
954 DMX6FIRE_CONTROL("Breakbox LED", 6, 0),
958 static int __devinit snd_ice1712_ews_add_controls(struct snd_ice1712 *ice)
963 /* all terratec cards have spdif, but cs8427 module builds it's own controls */
964 if (ice->cs8427 == NULL) {
965 err = snd_ice1712_spdif_build_controls(ice);
970 /* ak4524 controls */
971 switch (ice->eeprom.subvendor) {
972 case ICE1712_SUBDEVICE_EWX2496:
973 case ICE1712_SUBDEVICE_EWS88MT:
974 case ICE1712_SUBDEVICE_EWS88MT_NEW:
975 case ICE1712_SUBDEVICE_PHASE88:
976 case ICE1712_SUBDEVICE_DMX6FIRE:
977 err = snd_ice1712_akm4xxx_build_controls(ice);
983 /* card specific controls */
984 switch (ice->eeprom.subvendor) {
985 case ICE1712_SUBDEVICE_EWX2496:
986 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ewx2496_controls); idx++) {
987 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ewx2496_controls[idx], ice));
992 case ICE1712_SUBDEVICE_EWS88MT:
993 case ICE1712_SUBDEVICE_EWS88MT_NEW:
994 case ICE1712_SUBDEVICE_PHASE88:
995 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice));
998 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense, ice));
1002 case ICE1712_SUBDEVICE_EWS88D:
1003 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ews88d_controls); idx++) {
1004 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_controls[idx], ice));
1009 case ICE1712_SUBDEVICE_DMX6FIRE:
1010 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_6fire_controls); idx++) {
1011 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_6fire_controls[idx], ice));
1022 struct snd_ice1712_card_info snd_ice1712_ews_cards[] __devinitdata = {
1024 .subvendor = ICE1712_SUBDEVICE_EWX2496,
1025 .name = "TerraTec EWX24/96",
1027 .chip_init = snd_ice1712_ews_init,
1028 .build_controls = snd_ice1712_ews_add_controls,
1031 .subvendor = ICE1712_SUBDEVICE_EWS88MT,
1032 .name = "TerraTec EWS88MT",
1034 .chip_init = snd_ice1712_ews_init,
1035 .build_controls = snd_ice1712_ews_add_controls,
1038 .subvendor = ICE1712_SUBDEVICE_EWS88MT_NEW,
1039 .name = "TerraTec EWS88MT",
1040 .model = "ews88mt_new",
1041 .chip_init = snd_ice1712_ews_init,
1042 .build_controls = snd_ice1712_ews_add_controls,
1045 .subvendor = ICE1712_SUBDEVICE_PHASE88,
1046 .name = "TerraTec Phase88",
1048 .chip_init = snd_ice1712_ews_init,
1049 .build_controls = snd_ice1712_ews_add_controls,
1052 .subvendor = ICE1712_SUBDEVICE_EWS88D,
1053 .name = "TerraTec EWS88D",
1055 .chip_init = snd_ice1712_ews_init,
1056 .build_controls = snd_ice1712_ews_add_controls,
1059 .subvendor = ICE1712_SUBDEVICE_DMX6FIRE,
1060 .name = "TerraTec DMX6Fire",
1061 .model = "dmx6fire",
1062 .chip_init = snd_ice1712_ews_init,
1063 .build_controls = snd_ice1712_ews_add_controls,
1064 .mpu401_1_name = "MIDI-Front DMX6fire",
1065 .mpu401_2_name = "Wavetable DMX6fire",
1066 .mpu401_2_info_flags = MPU401_INFO_OUTPUT,
1068 { } /* terminator */