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,
48 * access via i2c mode (for EWX 24/96, EWS 88MT&D)
51 /* send SDA and SCL */
52 static void ewx_i2c_setlines(struct snd_i2c_bus *bus, int clk, int data)
54 struct snd_ice1712 *ice = bus->private_data;
55 unsigned char tmp = 0;
57 tmp |= ICE1712_EWX2496_SERIAL_CLOCK;
59 tmp |= ICE1712_EWX2496_SERIAL_DATA;
60 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
64 static int ewx_i2c_getclock(struct snd_i2c_bus *bus)
66 struct snd_ice1712 *ice = bus->private_data;
67 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_CLOCK ? 1 : 0;
70 static int ewx_i2c_getdata(struct snd_i2c_bus *bus, int ack)
72 struct snd_ice1712 *ice = bus->private_data;
74 /* set RW pin to low */
75 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_RW);
76 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, 0);
79 bit = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_DATA ? 1 : 0;
80 /* set RW pin to high */
81 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ICE1712_EWX2496_RW);
82 /* reset write mask */
83 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_SERIAL_CLOCK);
87 static void ewx_i2c_start(struct snd_i2c_bus *bus)
89 struct snd_ice1712 *ice = bus->private_data;
92 snd_ice1712_save_gpio_status(ice);
94 mask = ICE1712_EWX2496_RW;
95 switch (ice->eeprom.subvendor) {
96 case ICE1712_SUBDEVICE_EWX2496:
97 mask |= ICE1712_EWX2496_AK4524_CS; /* CS high also */
99 case ICE1712_SUBDEVICE_DMX6FIRE:
100 mask |= ICE1712_6FIRE_AK4524_CS_MASK; /* CS high also */
103 snd_ice1712_gpio_write_bits(ice, mask, mask);
106 static void ewx_i2c_stop(struct snd_i2c_bus *bus)
108 struct snd_ice1712 *ice = bus->private_data;
109 snd_ice1712_restore_gpio_status(ice);
112 static void ewx_i2c_direction(struct snd_i2c_bus *bus, int clock, int data)
114 struct snd_ice1712 *ice = bus->private_data;
115 unsigned char mask = 0;
118 mask |= ICE1712_EWX2496_SERIAL_CLOCK; /* write SCL */
120 mask |= ICE1712_EWX2496_SERIAL_DATA; /* write SDA */
121 ice->gpio.direction &= ~(ICE1712_EWX2496_SERIAL_CLOCK|ICE1712_EWX2496_SERIAL_DATA);
122 ice->gpio.direction |= mask;
123 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio.direction);
124 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~mask);
127 static struct snd_i2c_bit_ops snd_ice1712_ewx_cs8427_bit_ops = {
128 .start = ewx_i2c_start,
129 .stop = ewx_i2c_stop,
130 .direction = ewx_i2c_direction,
131 .setlines = ewx_i2c_setlines,
132 .getclock = ewx_i2c_getclock,
133 .getdata = ewx_i2c_getdata,
141 /* AK4524 chip select; address 0x48 bit 0-3 */
142 static int snd_ice1712_ews88mt_chip_select(struct snd_ice1712 *ice, int chip_mask)
144 unsigned char data, ndata;
146 snd_assert(chip_mask >= 0 && chip_mask <= 0x0f, return -EINVAL);
147 snd_i2c_lock(ice->i2c);
148 if (snd_i2c_readbytes(ice->spec.i2cdevs[EWS_I2C_PCF2], &data, 1) != 1)
150 ndata = (data & 0xf0) | chip_mask;
152 if (snd_i2c_sendbytes(ice->spec.i2cdevs[EWS_I2C_PCF2], &ndata, 1) != 1)
154 snd_i2c_unlock(ice->i2c);
158 snd_i2c_unlock(ice->i2c);
159 snd_printk(KERN_ERR "AK4524 chip select failed, check cable to the front module\n");
163 /* start callback for EWS88MT, needs to select a certain chip mask */
164 static void ews88mt_ak4524_lock(struct snd_akm4xxx *ak, int chip)
166 struct snd_ice1712 *ice = ak->private_data[0];
168 /* assert AK4524 CS */
169 if (snd_ice1712_ews88mt_chip_select(ice, ~(1 << chip) & 0x0f) < 0)
170 snd_printk(KERN_ERR "fatal error (ews88mt chip select)\n");
171 snd_ice1712_save_gpio_status(ice);
172 tmp = ICE1712_EWS88_SERIAL_DATA |
173 ICE1712_EWS88_SERIAL_CLOCK |
175 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
176 ice->gpio.direction | tmp);
177 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
180 /* stop callback for EWS88MT, needs to deselect chip mask */
181 static void ews88mt_ak4524_unlock(struct snd_akm4xxx *ak, int chip)
183 struct snd_ice1712 *ice = ak->private_data[0];
184 snd_ice1712_restore_gpio_status(ice);
186 snd_ice1712_ews88mt_chip_select(ice, 0x0f);
189 /* start callback for EWX24/96 */
190 static void ewx2496_ak4524_lock(struct snd_akm4xxx *ak, int chip)
192 struct snd_ice1712 *ice = ak->private_data[0];
194 snd_ice1712_save_gpio_status(ice);
195 tmp = ICE1712_EWX2496_SERIAL_DATA |
196 ICE1712_EWX2496_SERIAL_CLOCK |
197 ICE1712_EWX2496_AK4524_CS |
199 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
200 ice->gpio.direction | tmp);
201 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
204 /* start callback for DMX 6fire */
205 static void dmx6fire_ak4524_lock(struct snd_akm4xxx *ak, int chip)
207 struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
208 struct snd_ice1712 *ice = ak->private_data[0];
210 snd_ice1712_save_gpio_status(ice);
211 tmp = priv->cs_mask = priv->cs_addr = (1 << chip) & ICE1712_6FIRE_AK4524_CS_MASK;
212 tmp |= ICE1712_6FIRE_SERIAL_DATA |
213 ICE1712_6FIRE_SERIAL_CLOCK |
215 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
216 ice->gpio.direction | tmp);
217 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
221 * CS8404 interface on EWS88MT/D
224 static void snd_ice1712_ews_cs8404_spdif_write(struct snd_ice1712 *ice, unsigned char bits)
226 unsigned char bytes[2];
228 snd_i2c_lock(ice->i2c);
229 switch (ice->eeprom.subvendor) {
230 case ICE1712_SUBDEVICE_EWS88MT:
231 case ICE1712_SUBDEVICE_EWS88MT_NEW:
232 case ICE1712_SUBDEVICE_PHASE88:
233 if (snd_i2c_sendbytes(ice->spec.i2cdevs[EWS_I2C_CS8404], &bits, 1) != 1)
236 case ICE1712_SUBDEVICE_EWS88D:
237 if (snd_i2c_readbytes(ice->spec.i2cdevs[EWS_I2C_88D], bytes, 2) != 2)
239 if (bits != bytes[1]) {
241 if (snd_i2c_sendbytes(ice->spec.i2cdevs[EWS_I2C_88D], bytes, 2) != 2)
247 snd_i2c_unlock(ice->i2c);
253 static void ews88_spdif_default_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
255 snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_bits);
258 static int ews88_spdif_default_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
263 val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
264 spin_lock_irq(&ice->reg_lock);
265 change = ice->spdif.cs8403_bits != val;
266 ice->spdif.cs8403_bits = val;
267 if (change && ice->playback_pro_substream == NULL) {
268 spin_unlock_irq(&ice->reg_lock);
269 snd_ice1712_ews_cs8404_spdif_write(ice, val);
271 spin_unlock_irq(&ice->reg_lock);
276 static void ews88_spdif_stream_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
278 snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_stream_bits);
281 static int ews88_spdif_stream_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
286 val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
287 spin_lock_irq(&ice->reg_lock);
288 change = ice->spdif.cs8403_stream_bits != val;
289 ice->spdif.cs8403_stream_bits = val;
290 if (change && ice->playback_pro_substream != NULL) {
291 spin_unlock_irq(&ice->reg_lock);
292 snd_ice1712_ews_cs8404_spdif_write(ice, val);
294 spin_unlock_irq(&ice->reg_lock);
301 static void ews88_open_spdif(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
303 ice->spdif.cs8403_stream_bits = ice->spdif.cs8403_bits;
306 /* set up SPDIF for EWS88MT / EWS88D */
307 static void ews88_setup_spdif(struct snd_ice1712 *ice, int rate)
313 spin_lock_irqsave(&ice->reg_lock, flags);
314 tmp = ice->spdif.cs8403_stream_bits;
315 if (tmp & 0x10) /* consumer */
316 tmp &= (tmp & 0x01) ? ~0x06 : ~0x60;
318 case 32000: tmp |= (tmp & 0x01) ? 0x02 : 0x00; break;
319 case 44100: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
320 case 48000: tmp |= (tmp & 0x01) ? 0x04 : 0x20; break;
321 default: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
323 change = ice->spdif.cs8403_stream_bits != tmp;
324 ice->spdif.cs8403_stream_bits = tmp;
325 spin_unlock_irqrestore(&ice->reg_lock, flags);
327 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &ice->spdif.stream_ctl->id);
328 snd_ice1712_ews_cs8404_spdif_write(ice, tmp);
334 static struct snd_akm4xxx akm_ews88mt __devinitdata = {
339 .lock = ews88mt_ak4524_lock,
340 .unlock = ews88mt_ak4524_unlock
344 static struct snd_ak4xxx_private akm_ews88mt_priv __devinitdata = {
346 .cif = 1, /* CIF high */
347 .data_mask = ICE1712_EWS88_SERIAL_DATA,
348 .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
351 .cs_none = 0, /* no chip select on gpio */
352 .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
356 static struct snd_akm4xxx akm_ewx2496 __devinitdata = {
361 .lock = ewx2496_ak4524_lock
365 static struct snd_ak4xxx_private akm_ewx2496_priv __devinitdata = {
367 .cif = 1, /* CIF high */
368 .data_mask = ICE1712_EWS88_SERIAL_DATA,
369 .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
370 .cs_mask = ICE1712_EWX2496_AK4524_CS,
371 .cs_addr = ICE1712_EWX2496_AK4524_CS,
373 .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
377 static struct snd_akm4xxx akm_6fire __devinitdata = {
382 .lock = dmx6fire_ak4524_lock
386 static struct snd_ak4xxx_private akm_6fire_priv __devinitdata = {
388 .cif = 1, /* CIF high */
389 .data_mask = ICE1712_6FIRE_SERIAL_DATA,
390 .clk_mask = ICE1712_6FIRE_SERIAL_CLOCK,
392 .cs_addr = 0, /* set later */
394 .add_flags = ICE1712_6FIRE_RW, /* set rw bit high */
399 * initialize the chip
403 #define PCF9554_REG_INPUT 0
404 #define PCF9554_REG_OUTPUT 1
405 #define PCF9554_REG_POLARITY 2
406 #define PCF9554_REG_CONFIG 3
408 static int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data);
410 static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice)
413 struct snd_akm4xxx *ak;
415 /* set the analog DACs */
416 switch (ice->eeprom.subvendor) {
417 case ICE1712_SUBDEVICE_EWX2496:
418 ice->num_total_dacs = 2;
419 ice->num_total_adcs = 2;
421 case ICE1712_SUBDEVICE_EWS88MT:
422 case ICE1712_SUBDEVICE_EWS88MT_NEW:
423 case ICE1712_SUBDEVICE_PHASE88:
424 ice->num_total_dacs = 8;
425 ice->num_total_adcs = 8;
427 case ICE1712_SUBDEVICE_EWS88D:
428 /* Note: not analog but ADAT I/O */
429 ice->num_total_dacs = 8;
430 ice->num_total_adcs = 8;
432 case ICE1712_SUBDEVICE_DMX6FIRE:
433 ice->num_total_dacs = 6;
434 ice->num_total_adcs = 6;
439 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
440 snd_printk(KERN_ERR "unable to create I2C bus\n");
443 ice->i2c->private_data = ice;
444 ice->i2c->hw_ops.bit = &snd_ice1712_ewx_cs8427_bit_ops;
446 /* create i2c devices */
447 switch (ice->eeprom.subvendor) {
448 case ICE1712_SUBDEVICE_DMX6FIRE:
449 if ((err = snd_i2c_device_create(ice->i2c, "PCF9554", ICE1712_6FIRE_PCF9554_ADDR, &ice->spec.i2cdevs[EWS_I2C_6FIRE])) < 0) {
450 snd_printk(KERN_ERR "PCF9554 initialization failed\n");
453 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80);
455 case ICE1712_SUBDEVICE_EWS88MT:
456 case ICE1712_SUBDEVICE_EWS88MT_NEW:
457 case ICE1712_SUBDEVICE_PHASE88:
458 if ((err = snd_i2c_device_create(ice->i2c, "CS8404", ICE1712_EWS88MT_CS8404_ADDR, &ice->spec.i2cdevs[EWS_I2C_CS8404])) < 0)
460 if ((err = snd_i2c_device_create(ice->i2c, "PCF8574 (1st)", ICE1712_EWS88MT_INPUT_ADDR, &ice->spec.i2cdevs[EWS_I2C_PCF1])) < 0)
462 if ((err = snd_i2c_device_create(ice->i2c, "PCF8574 (2nd)", ICE1712_EWS88MT_OUTPUT_ADDR, &ice->spec.i2cdevs[EWS_I2C_PCF2])) < 0)
464 /* Check if the front module is connected */
465 if ((err = snd_ice1712_ews88mt_chip_select(ice, 0x0f)) < 0)
468 case ICE1712_SUBDEVICE_EWS88D:
469 if ((err = snd_i2c_device_create(ice->i2c, "PCF8575", ICE1712_EWS88D_PCF_ADDR, &ice->spec.i2cdevs[EWS_I2C_88D])) < 0)
474 /* set up SPDIF interface */
475 switch (ice->eeprom.subvendor) {
476 case ICE1712_SUBDEVICE_EWX2496:
477 if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0)
479 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
481 case ICE1712_SUBDEVICE_DMX6FIRE:
482 if ((err = snd_ice1712_init_cs8427(ice, ICE1712_6FIRE_CS8427_ADDR)) < 0)
484 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
486 case ICE1712_SUBDEVICE_EWS88MT:
487 case ICE1712_SUBDEVICE_EWS88MT_NEW:
488 case ICE1712_SUBDEVICE_PHASE88:
489 case ICE1712_SUBDEVICE_EWS88D:
491 ice->spdif.ops.open = ews88_open_spdif;
492 ice->spdif.ops.setup_rate = ews88_setup_spdif;
493 ice->spdif.ops.default_get = ews88_spdif_default_get;
494 ice->spdif.ops.default_put = ews88_spdif_default_put;
495 ice->spdif.ops.stream_get = ews88_spdif_stream_get;
496 ice->spdif.ops.stream_put = ews88_spdif_stream_put;
497 /* Set spdif defaults */
498 snd_ice1712_ews_cs8404_spdif_write(ice, ice->spdif.cs8403_bits);
503 switch (ice->eeprom.subvendor) {
504 case ICE1712_SUBDEVICE_EWS88D:
509 ak = ice->akm = kmalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
514 switch (ice->eeprom.subvendor) {
515 case ICE1712_SUBDEVICE_EWS88MT:
516 case ICE1712_SUBDEVICE_EWS88MT_NEW:
517 case ICE1712_SUBDEVICE_PHASE88:
518 err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice);
520 case ICE1712_SUBDEVICE_EWX2496:
521 err = snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, &akm_ewx2496_priv, ice);
523 case ICE1712_SUBDEVICE_DMX6FIRE:
524 err = snd_ice1712_akm4xxx_init(ak, &akm_6fire, &akm_6fire_priv, ice);
534 * EWX 24/96 specific controls
537 /* i/o sensitivity - this callback is shared among other devices, too */
538 static int snd_ice1712_ewx_io_sense_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){
540 static char *texts[2] = {
543 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
545 uinfo->value.enumerated.items = 2;
546 if (uinfo->value.enumerated.item >= 2)
547 uinfo->value.enumerated.item = 1;
548 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
552 static int snd_ice1712_ewx_io_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
554 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
555 unsigned char mask = kcontrol->private_value & 0xff;
557 snd_ice1712_save_gpio_status(ice);
558 ucontrol->value.enumerated.item[0] = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0;
559 snd_ice1712_restore_gpio_status(ice);
563 static int snd_ice1712_ewx_io_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
565 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
566 unsigned char mask = kcontrol->private_value & 0xff;
569 if (kcontrol->private_value & (1 << 31))
571 nval = ucontrol->value.enumerated.item[0] ? mask : 0;
572 snd_ice1712_save_gpio_status(ice);
573 val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
575 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, nval);
576 snd_ice1712_restore_gpio_status(ice);
580 static struct snd_kcontrol_new snd_ice1712_ewx2496_controls[] __devinitdata = {
582 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
583 .name = "Input Sensitivity Switch",
584 .info = snd_ice1712_ewx_io_sense_info,
585 .get = snd_ice1712_ewx_io_sense_get,
586 .put = snd_ice1712_ewx_io_sense_put,
587 .private_value = ICE1712_EWX2496_AIN_SEL,
590 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
591 .name = "Output Sensitivity Switch",
592 .info = snd_ice1712_ewx_io_sense_info,
593 .get = snd_ice1712_ewx_io_sense_get,
594 .put = snd_ice1712_ewx_io_sense_put,
595 .private_value = ICE1712_EWX2496_AOUT_SEL,
601 * EWS88MT specific controls
603 /* analog output sensitivity;; address 0x48 bit 6 */
604 static int snd_ice1712_ews88mt_output_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
606 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
609 snd_i2c_lock(ice->i2c);
610 if (snd_i2c_readbytes(ice->spec.i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) {
611 snd_i2c_unlock(ice->i2c);
614 snd_i2c_unlock(ice->i2c);
615 ucontrol->value.enumerated.item[0] = data & ICE1712_EWS88MT_OUTPUT_SENSE ? 1 : 0; /* high = -10dBV, low = +4dBu */
619 /* analog output sensitivity;; address 0x48 bit 6 */
620 static int snd_ice1712_ews88mt_output_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
622 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
623 unsigned char data, ndata;
625 snd_i2c_lock(ice->i2c);
626 if (snd_i2c_readbytes(ice->spec.i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) {
627 snd_i2c_unlock(ice->i2c);
630 ndata = (data & ~ICE1712_EWS88MT_OUTPUT_SENSE) | (ucontrol->value.enumerated.item[0] ? ICE1712_EWS88MT_OUTPUT_SENSE : 0);
631 if (ndata != data && snd_i2c_sendbytes(ice->spec.i2cdevs[EWS_I2C_PCF2], &ndata, 1) != 1) {
632 snd_i2c_unlock(ice->i2c);
635 snd_i2c_unlock(ice->i2c);
636 return ndata != data;
639 /* analog input sensitivity; address 0x46 */
640 static int snd_ice1712_ews88mt_input_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
642 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
643 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
646 snd_assert(channel >= 0 && channel <= 7, return 0);
647 snd_i2c_lock(ice->i2c);
648 if (snd_i2c_readbytes(ice->spec.i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) {
649 snd_i2c_unlock(ice->i2c);
652 /* reversed; high = +4dBu, low = -10dBV */
653 ucontrol->value.enumerated.item[0] = data & (1 << channel) ? 0 : 1;
654 snd_i2c_unlock(ice->i2c);
658 /* analog output sensitivity; address 0x46 */
659 static int snd_ice1712_ews88mt_input_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
661 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
662 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
663 unsigned char data, ndata;
665 snd_assert(channel >= 0 && channel <= 7, return 0);
666 snd_i2c_lock(ice->i2c);
667 if (snd_i2c_readbytes(ice->spec.i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) {
668 snd_i2c_unlock(ice->i2c);
671 ndata = (data & ~(1 << channel)) | (ucontrol->value.enumerated.item[0] ? 0 : (1 << channel));
672 if (ndata != data && snd_i2c_sendbytes(ice->spec.i2cdevs[EWS_I2C_PCF1], &ndata, 1) != 1) {
673 snd_i2c_unlock(ice->i2c);
676 snd_i2c_unlock(ice->i2c);
677 return ndata != data;
680 static struct snd_kcontrol_new snd_ice1712_ews88mt_input_sense __devinitdata = {
681 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
682 .name = "Input Sensitivity Switch",
683 .info = snd_ice1712_ewx_io_sense_info,
684 .get = snd_ice1712_ews88mt_input_sense_get,
685 .put = snd_ice1712_ews88mt_input_sense_put,
689 static struct snd_kcontrol_new snd_ice1712_ews88mt_output_sense __devinitdata = {
690 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
691 .name = "Output Sensitivity Switch",
692 .info = snd_ice1712_ewx_io_sense_info,
693 .get = snd_ice1712_ews88mt_output_sense_get,
694 .put = snd_ice1712_ews88mt_output_sense_put,
699 * EWS88D specific controls
702 #define snd_ice1712_ews88d_control_info snd_ctl_boolean_mono_info
704 static int snd_ice1712_ews88d_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
706 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
707 int shift = kcontrol->private_value & 0xff;
708 int invert = (kcontrol->private_value >> 8) & 1;
709 unsigned char data[2];
711 snd_i2c_lock(ice->i2c);
712 if (snd_i2c_readbytes(ice->spec.i2cdevs[EWS_I2C_88D], data, 2) != 2) {
713 snd_i2c_unlock(ice->i2c);
716 snd_i2c_unlock(ice->i2c);
717 data[0] = (data[shift >> 3] >> (shift & 7)) & 0x01;
720 ucontrol->value.integer.value[0] = data[0];
724 static int snd_ice1712_ews88d_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
726 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
727 int shift = kcontrol->private_value & 0xff;
728 int invert = (kcontrol->private_value >> 8) & 1;
729 unsigned char data[2], ndata[2];
732 snd_i2c_lock(ice->i2c);
733 if (snd_i2c_readbytes(ice->spec.i2cdevs[EWS_I2C_88D], data, 2) != 2) {
734 snd_i2c_unlock(ice->i2c);
737 ndata[shift >> 3] = data[shift >> 3] & ~(1 << (shift & 7));
739 if (! ucontrol->value.integer.value[0])
740 ndata[shift >> 3] |= (1 << (shift & 7));
742 if (ucontrol->value.integer.value[0])
743 ndata[shift >> 3] |= (1 << (shift & 7));
745 change = (data[shift >> 3] != ndata[shift >> 3]);
746 if (change && snd_i2c_sendbytes(ice->spec.i2cdevs[EWS_I2C_88D], data, 2) != 2) {
747 snd_i2c_unlock(ice->i2c);
750 snd_i2c_unlock(ice->i2c);
754 #define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
758 .info = snd_ice1712_ews88d_control_info,\
759 .get = snd_ice1712_ews88d_control_get,\
760 .put = snd_ice1712_ews88d_control_put,\
761 .private_value = xshift | (xinvert << 8),\
764 static struct snd_kcontrol_new snd_ice1712_ews88d_controls[] __devinitdata = {
765 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, 1, 0), /* inverted */
766 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Output Optical", 1, 0, 0),
767 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT External Master Clock", 2, 0, 0),
768 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "Enable ADAT", 3, 0, 0),
769 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Through", 4, 1, 0),
774 * DMX 6Fire specific controls
777 static int snd_ice1712_6fire_read_pca(struct snd_ice1712 *ice, unsigned char reg)
780 snd_i2c_lock(ice->i2c);
782 snd_i2c_sendbytes(ice->spec.i2cdevs[EWS_I2C_6FIRE], &byte, 1);
784 if (snd_i2c_readbytes(ice->spec.i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) {
785 snd_i2c_unlock(ice->i2c);
786 printk(KERN_ERR "cannot read pca\n");
789 snd_i2c_unlock(ice->i2c);
793 static int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data)
795 unsigned char bytes[2];
796 snd_i2c_lock(ice->i2c);
799 if (snd_i2c_sendbytes(ice->spec.i2cdevs[EWS_I2C_6FIRE], bytes, 2) != 2) {
800 snd_i2c_unlock(ice->i2c);
803 snd_i2c_unlock(ice->i2c);
807 #define snd_ice1712_6fire_control_info snd_ctl_boolean_mono_info
809 static int snd_ice1712_6fire_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
811 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
812 int shift = kcontrol->private_value & 0xff;
813 int invert = (kcontrol->private_value >> 8) & 1;
816 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
818 data = (data >> shift) & 1;
821 ucontrol->value.integer.value[0] = data;
825 static int snd_ice1712_6fire_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
827 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
828 int shift = kcontrol->private_value & 0xff;
829 int invert = (kcontrol->private_value >> 8) & 1;
832 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
834 ndata = data & ~(1 << shift);
835 if (ucontrol->value.integer.value[0])
836 ndata |= (1 << shift);
838 ndata ^= (1 << shift);
840 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
846 static int snd_ice1712_6fire_select_input_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
848 static char *texts[4] = {
849 "Internal", "Front Input", "Rear Input", "Wave Table"
851 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
853 uinfo->value.enumerated.items = 4;
854 if (uinfo->value.enumerated.item >= 4)
855 uinfo->value.enumerated.item = 1;
856 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
860 static int snd_ice1712_6fire_select_input_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
862 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
865 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
867 ucontrol->value.integer.value[0] = data & 3;
871 static int snd_ice1712_6fire_select_input_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
873 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
876 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
879 ndata |= (ucontrol->value.integer.value[0] & 3);
881 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
888 #define DMX6FIRE_CONTROL(xname, xshift, xinvert) \
889 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
891 .info = snd_ice1712_6fire_control_info,\
892 .get = snd_ice1712_6fire_control_get,\
893 .put = snd_ice1712_6fire_control_put,\
894 .private_value = xshift | (xinvert << 8),\
897 static struct snd_kcontrol_new snd_ice1712_6fire_controls[] __devinitdata = {
899 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
900 .name = "Analog Input Select",
901 .info = snd_ice1712_6fire_select_input_info,
902 .get = snd_ice1712_6fire_select_input_get,
903 .put = snd_ice1712_6fire_select_input_put,
905 DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 1),
906 // DMX6FIRE_CONTROL("Master Clock Select", 3, 0),
907 DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0),
908 DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0),
909 DMX6FIRE_CONTROL("Breakbox LED", 6, 0),
913 static int __devinit snd_ice1712_ews_add_controls(struct snd_ice1712 *ice)
918 /* all terratec cards have spdif, but cs8427 module builds it's own controls */
919 if (ice->cs8427 == NULL) {
920 err = snd_ice1712_spdif_build_controls(ice);
925 /* ak4524 controls */
926 switch (ice->eeprom.subvendor) {
927 case ICE1712_SUBDEVICE_EWX2496:
928 case ICE1712_SUBDEVICE_EWS88MT:
929 case ICE1712_SUBDEVICE_EWS88MT_NEW:
930 case ICE1712_SUBDEVICE_PHASE88:
931 case ICE1712_SUBDEVICE_DMX6FIRE:
932 err = snd_ice1712_akm4xxx_build_controls(ice);
938 /* card specific controls */
939 switch (ice->eeprom.subvendor) {
940 case ICE1712_SUBDEVICE_EWX2496:
941 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ewx2496_controls); idx++) {
942 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ewx2496_controls[idx], ice));
947 case ICE1712_SUBDEVICE_EWS88MT:
948 case ICE1712_SUBDEVICE_EWS88MT_NEW:
949 case ICE1712_SUBDEVICE_PHASE88:
950 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice));
953 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense, ice));
957 case ICE1712_SUBDEVICE_EWS88D:
958 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ews88d_controls); idx++) {
959 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_controls[idx], ice));
964 case ICE1712_SUBDEVICE_DMX6FIRE:
965 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_6fire_controls); idx++) {
966 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_6fire_controls[idx], ice));
977 struct snd_ice1712_card_info snd_ice1712_ews_cards[] __devinitdata = {
979 .subvendor = ICE1712_SUBDEVICE_EWX2496,
980 .name = "TerraTec EWX24/96",
982 .chip_init = snd_ice1712_ews_init,
983 .build_controls = snd_ice1712_ews_add_controls,
986 .subvendor = ICE1712_SUBDEVICE_EWS88MT,
987 .name = "TerraTec EWS88MT",
989 .chip_init = snd_ice1712_ews_init,
990 .build_controls = snd_ice1712_ews_add_controls,
993 .subvendor = ICE1712_SUBDEVICE_EWS88MT_NEW,
994 .name = "TerraTec EWS88MT",
995 .model = "ews88mt_new",
996 .chip_init = snd_ice1712_ews_init,
997 .build_controls = snd_ice1712_ews_add_controls,
1000 .subvendor = ICE1712_SUBDEVICE_PHASE88,
1001 .name = "TerraTec Phase88",
1003 .chip_init = snd_ice1712_ews_init,
1004 .build_controls = snd_ice1712_ews_add_controls,
1007 .subvendor = ICE1712_SUBDEVICE_EWS88D,
1008 .name = "TerraTec EWS88D",
1010 .chip_init = snd_ice1712_ews_init,
1011 .build_controls = snd_ice1712_ews_add_controls,
1014 .subvendor = ICE1712_SUBDEVICE_DMX6FIRE,
1015 .name = "TerraTec DMX6Fire",
1016 .model = "dmx6fire",
1017 .chip_init = snd_ice1712_ews_init,
1018 .build_controls = snd_ice1712_ews_add_controls,
1019 .mpu401_1_name = "MIDI-Front DMX6fire",
1020 .mpu401_2_name = "Wavetable DMX6fire",
1021 .mpu401_2_info_flags = MPU401_INFO_OUTPUT,
1023 { } /* terminator */