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@suse.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
25 #include <sound/driver.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>
39 #include <sound/cs8403.h>
42 * access via i2c mode (for EWX 24/96, EWS 88MT&D)
45 /* send SDA and SCL */
46 static void ewx_i2c_setlines(snd_i2c_bus_t *bus, int clk, int data)
48 ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return);
49 unsigned char tmp = 0;
51 tmp |= ICE1712_EWX2496_SERIAL_CLOCK;
53 tmp |= ICE1712_EWX2496_SERIAL_DATA;
54 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
58 static int ewx_i2c_getclock(snd_i2c_bus_t *bus)
60 ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return -EIO);
61 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_CLOCK ? 1 : 0;
64 static int ewx_i2c_getdata(snd_i2c_bus_t *bus, int ack)
66 ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return -EIO);
68 /* set RW pin to low */
69 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_RW);
70 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, 0);
73 bit = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_DATA ? 1 : 0;
74 /* set RW pin to high */
75 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ICE1712_EWX2496_RW);
76 /* reset write mask */
77 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_SERIAL_CLOCK);
81 static void ewx_i2c_start(snd_i2c_bus_t *bus)
83 ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return);
86 snd_ice1712_save_gpio_status(ice);
88 mask = ICE1712_EWX2496_RW;
89 switch (ice->eeprom.subvendor) {
90 case ICE1712_SUBDEVICE_EWX2496:
91 mask |= ICE1712_EWX2496_AK4524_CS; /* CS high also */
93 case ICE1712_SUBDEVICE_DMX6FIRE:
94 mask |= ICE1712_6FIRE_AK4524_CS_MASK; /* CS high also */
97 snd_ice1712_gpio_write_bits(ice, mask, mask);
100 static void ewx_i2c_stop(snd_i2c_bus_t *bus)
102 ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return);
103 snd_ice1712_restore_gpio_status(ice);
106 static void ewx_i2c_direction(snd_i2c_bus_t *bus, int clock, int data)
108 ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return);
109 unsigned char mask = 0;
112 mask |= ICE1712_EWX2496_SERIAL_CLOCK; /* write SCL */
114 mask |= ICE1712_EWX2496_SERIAL_DATA; /* write SDA */
115 ice->gpio.direction &= ~(ICE1712_EWX2496_SERIAL_CLOCK|ICE1712_EWX2496_SERIAL_DATA);
116 ice->gpio.direction |= mask;
117 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio.direction);
118 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~mask);
121 static snd_i2c_bit_ops_t snd_ice1712_ewx_cs8427_bit_ops = {
122 .start = ewx_i2c_start,
123 .stop = ewx_i2c_stop,
124 .direction = ewx_i2c_direction,
125 .setlines = ewx_i2c_setlines,
126 .getclock = ewx_i2c_getclock,
127 .getdata = ewx_i2c_getdata,
135 /* AK4524 chip select; address 0x48 bit 0-3 */
136 static int snd_ice1712_ews88mt_chip_select(ice1712_t *ice, int chip_mask)
138 unsigned char data, ndata;
140 snd_assert(chip_mask >= 0 && chip_mask <= 0x0f, return -EINVAL);
141 snd_i2c_lock(ice->i2c);
142 if (snd_i2c_readbytes(ice->i2cdevs[1], &data, 1) != 1)
144 ndata = (data & 0xf0) | chip_mask;
146 if (snd_i2c_sendbytes(ice->i2cdevs[1], &ndata, 1) != 1)
148 snd_i2c_unlock(ice->i2c);
152 snd_i2c_unlock(ice->i2c);
153 snd_printk(KERN_ERR "AK4524 chip select failed, check cable to the front module\n");
157 /* start callback for EWS88MT, needs to select a certain chip mask */
158 static void ews88mt_ak4524_lock(akm4xxx_t *ak, int chip)
160 ice1712_t *ice = ak->private_data[0];
162 /* assert AK4524 CS */
163 if (snd_ice1712_ews88mt_chip_select(ice, ~(1 << chip) & 0x0f) < 0)
164 snd_printk(KERN_ERR "fatal error (ews88mt chip select)\n");
165 snd_ice1712_save_gpio_status(ice);
166 tmp = ICE1712_EWS88_SERIAL_DATA |
167 ICE1712_EWS88_SERIAL_CLOCK |
169 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
170 ice->gpio.direction | tmp);
171 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
174 /* stop callback for EWS88MT, needs to deselect chip mask */
175 static void ews88mt_ak4524_unlock(akm4xxx_t *ak, int chip)
177 ice1712_t *ice = ak->private_data[0];
178 snd_ice1712_restore_gpio_status(ice);
180 snd_ice1712_ews88mt_chip_select(ice, 0x0f);
183 /* start callback for EWX24/96 */
184 static void ewx2496_ak4524_lock(akm4xxx_t *ak, int chip)
186 ice1712_t *ice = ak->private_data[0];
188 snd_ice1712_save_gpio_status(ice);
189 tmp = ICE1712_EWX2496_SERIAL_DATA |
190 ICE1712_EWX2496_SERIAL_CLOCK |
191 ICE1712_EWX2496_AK4524_CS |
193 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
194 ice->gpio.direction | tmp);
195 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
198 /* start callback for DMX 6fire */
199 static void dmx6fire_ak4524_lock(akm4xxx_t *ak, int chip)
201 struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
202 ice1712_t *ice = ak->private_data[0];
204 snd_ice1712_save_gpio_status(ice);
205 tmp = priv->cs_mask = priv->cs_addr = (1 << chip) & ICE1712_6FIRE_AK4524_CS_MASK;
206 tmp |= ICE1712_6FIRE_SERIAL_DATA |
207 ICE1712_6FIRE_SERIAL_CLOCK |
209 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
210 ice->gpio.direction | tmp);
211 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
215 * CS8404 interface on EWS88MT/D
218 static void snd_ice1712_ews_cs8404_spdif_write(ice1712_t *ice, unsigned char bits)
220 unsigned char bytes[2];
222 snd_i2c_lock(ice->i2c);
223 switch (ice->eeprom.subvendor) {
224 case ICE1712_SUBDEVICE_EWS88MT:
225 case ICE1712_SUBDEVICE_EWS88MT_NEW:
226 snd_runtime_check(snd_i2c_sendbytes(ice->cs8404, &bits, 1) == 1, goto _error);
228 case ICE1712_SUBDEVICE_EWS88D:
229 snd_runtime_check(snd_i2c_readbytes(ice->i2cdevs[0], bytes, 2) == 2, goto _error);
230 if (bits != bytes[1]) {
232 snd_runtime_check(snd_i2c_readbytes(ice->i2cdevs[0], bytes, 2) == 2, goto _error);
237 snd_i2c_unlock(ice->i2c);
243 static void ews88_spdif_default_get(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
245 snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_bits);
248 static int ews88_spdif_default_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
253 val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
254 spin_lock_irq(&ice->reg_lock);
255 change = ice->spdif.cs8403_bits != val;
256 ice->spdif.cs8403_bits = val;
257 if (change && ice->playback_pro_substream == NULL) {
258 spin_unlock_irq(&ice->reg_lock);
259 snd_ice1712_ews_cs8404_spdif_write(ice, val);
261 spin_unlock_irq(&ice->reg_lock);
266 static void ews88_spdif_stream_get(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
268 snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_stream_bits);
271 static int ews88_spdif_stream_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
276 val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
277 spin_lock_irq(&ice->reg_lock);
278 change = ice->spdif.cs8403_stream_bits != val;
279 ice->spdif.cs8403_stream_bits = val;
280 if (change && ice->playback_pro_substream != NULL) {
281 spin_unlock_irq(&ice->reg_lock);
282 snd_ice1712_ews_cs8404_spdif_write(ice, val);
284 spin_unlock_irq(&ice->reg_lock);
291 static void ews88_open_spdif(ice1712_t *ice, snd_pcm_substream_t * substream)
293 ice->spdif.cs8403_stream_bits = ice->spdif.cs8403_bits;
296 /* set up SPDIF for EWS88MT / EWS88D */
297 static void ews88_setup_spdif(ice1712_t *ice, int rate)
303 spin_lock_irqsave(&ice->reg_lock, flags);
304 tmp = ice->spdif.cs8403_stream_bits;
305 if (tmp & 0x10) /* consumer */
306 tmp &= (tmp & 0x01) ? ~0x06 : ~0x60;
308 case 32000: tmp |= (tmp & 0x01) ? 0x02 : 0x00; break;
309 case 44100: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
310 case 48000: tmp |= (tmp & 0x01) ? 0x04 : 0x20; break;
311 default: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
313 change = ice->spdif.cs8403_stream_bits != tmp;
314 ice->spdif.cs8403_stream_bits = tmp;
315 spin_unlock_irqrestore(&ice->reg_lock, flags);
317 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &ice->spdif.stream_ctl->id);
318 snd_ice1712_ews_cs8404_spdif_write(ice, tmp);
324 static akm4xxx_t akm_ews88mt __devinitdata = {
329 .lock = ews88mt_ak4524_lock,
330 .unlock = ews88mt_ak4524_unlock
334 static struct snd_ak4xxx_private akm_ews88mt_priv __devinitdata = {
336 .cif = 1, /* CIF high */
337 .data_mask = ICE1712_EWS88_SERIAL_DATA,
338 .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
341 .cs_none = 0, /* no chip select on gpio */
342 .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
346 static akm4xxx_t akm_ewx2496 __devinitdata = {
351 .lock = ewx2496_ak4524_lock
355 static struct snd_ak4xxx_private akm_ewx2496_priv __devinitdata = {
357 .cif = 1, /* CIF high */
358 .data_mask = ICE1712_EWS88_SERIAL_DATA,
359 .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
360 .cs_mask = ICE1712_EWX2496_AK4524_CS,
361 .cs_addr = ICE1712_EWX2496_AK4524_CS,
363 .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
367 static akm4xxx_t akm_6fire __devinitdata = {
372 .lock = dmx6fire_ak4524_lock
376 static struct snd_ak4xxx_private akm_6fire_priv __devinitdata = {
378 .cif = 1, /* CIF high */
379 .data_mask = ICE1712_6FIRE_SERIAL_DATA,
380 .clk_mask = ICE1712_6FIRE_SERIAL_CLOCK,
382 .cs_addr = 0, /* set later */
384 .add_flags = ICE1712_6FIRE_RW, /* set rw bit high */
389 * initialize the chip
393 #define PCF9554_REG_INPUT 0
394 #define PCF9554_REG_OUTPUT 1
395 #define PCF9554_REG_POLARITY 2
396 #define PCF9554_REG_CONFIG 3
398 static int snd_ice1712_6fire_write_pca(ice1712_t *ice, unsigned char reg, unsigned char data);
400 static int __devinit snd_ice1712_ews_init(ice1712_t *ice)
405 /* set the analog DACs */
406 switch (ice->eeprom.subvendor) {
407 case ICE1712_SUBDEVICE_EWX2496:
408 ice->num_total_dacs = 2;
409 ice->num_total_adcs = 2;
411 case ICE1712_SUBDEVICE_EWS88MT:
412 case ICE1712_SUBDEVICE_EWS88MT_NEW:
413 ice->num_total_dacs = 8;
414 ice->num_total_adcs = 8;
416 case ICE1712_SUBDEVICE_EWS88D:
417 break; /* no analog */
418 case ICE1712_SUBDEVICE_DMX6FIRE:
419 ice->num_total_dacs = 6;
420 ice->num_total_adcs = 6;
425 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
426 snd_printk("unable to create I2C bus\n");
429 ice->i2c->private_data = ice;
430 ice->i2c->hw_ops.bit = &snd_ice1712_ewx_cs8427_bit_ops;
432 /* create i2c devices */
433 switch (ice->eeprom.subvendor) {
434 case ICE1712_SUBDEVICE_DMX6FIRE:
435 if ((err = snd_i2c_device_create(ice->i2c, "PCF9554", ICE1712_6FIRE_PCF9554_ADDR, &ice->i2cdevs[0])) < 0) {
436 snd_printk("PCF9554 initialization failed\n");
439 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80);
441 case ICE1712_SUBDEVICE_EWS88MT:
442 case ICE1712_SUBDEVICE_EWS88MT_NEW:
443 if ((err = snd_i2c_device_create(ice->i2c, "CS8404", ICE1712_EWS88MT_CS8404_ADDR, &ice->cs8404)) < 0)
445 if ((err = snd_i2c_device_create(ice->i2c, "PCF8574 (1st)", ICE1712_EWS88MT_INPUT_ADDR, &ice->i2cdevs[0])) < 0)
447 if ((err = snd_i2c_device_create(ice->i2c, "PCF8574 (2nd)", ICE1712_EWS88MT_OUTPUT_ADDR, &ice->i2cdevs[1])) < 0)
449 /* Check if the front module is connected */
450 if ((err = snd_ice1712_ews88mt_chip_select(ice, 0x0f)) < 0)
453 case ICE1712_SUBDEVICE_EWS88D:
454 if ((err = snd_i2c_device_create(ice->i2c, "PCF8575", ICE1712_EWS88D_PCF_ADDR, &ice->i2cdevs[0])) < 0)
459 /* set up SPDIF interface */
460 switch (ice->eeprom.subvendor) {
461 case ICE1712_SUBDEVICE_EWX2496:
462 if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0)
464 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
466 case ICE1712_SUBDEVICE_DMX6FIRE:
467 if ((err = snd_ice1712_init_cs8427(ice, ICE1712_6FIRE_CS8427_ADDR)) < 0)
469 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
471 case ICE1712_SUBDEVICE_EWS88MT:
472 case ICE1712_SUBDEVICE_EWS88MT_NEW:
473 case ICE1712_SUBDEVICE_EWS88D:
475 ice->spdif.ops.open = ews88_open_spdif;
476 ice->spdif.ops.setup_rate = ews88_setup_spdif;
477 ice->spdif.ops.default_get = ews88_spdif_default_get;
478 ice->spdif.ops.default_put = ews88_spdif_default_put;
479 ice->spdif.ops.stream_get = ews88_spdif_stream_get;
480 ice->spdif.ops.stream_put = ews88_spdif_stream_put;
481 /* Set spdif defaults */
482 snd_ice1712_ews_cs8404_spdif_write(ice, ice->spdif.cs8403_bits);
487 switch (ice->eeprom.subvendor) {
488 case ICE1712_SUBDEVICE_EWS88D:
493 ak = ice->akm = kmalloc(sizeof(akm4xxx_t), GFP_KERNEL);
498 switch (ice->eeprom.subvendor) {
499 case ICE1712_SUBDEVICE_EWS88MT:
500 case ICE1712_SUBDEVICE_EWS88MT_NEW:
501 err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice);
503 case ICE1712_SUBDEVICE_EWX2496:
504 err = snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, &akm_ewx2496_priv, ice);
506 case ICE1712_SUBDEVICE_DMX6FIRE:
507 err = snd_ice1712_akm4xxx_init(ak, &akm_6fire, &akm_6fire_priv, ice);
517 * EWX 24/96 specific controls
520 /* i/o sensitivity - this callback is shared among other devices, too */
521 static int snd_ice1712_ewx_io_sense_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo){
523 static char *texts[2] = {
526 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
528 uinfo->value.enumerated.items = 2;
529 if (uinfo->value.enumerated.item >= 2)
530 uinfo->value.enumerated.item = 1;
531 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
535 static int snd_ice1712_ewx_io_sense_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
537 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
538 unsigned char mask = kcontrol->private_value & 0xff;
540 snd_ice1712_save_gpio_status(ice);
541 ucontrol->value.enumerated.item[0] = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0;
542 snd_ice1712_restore_gpio_status(ice);
546 static int snd_ice1712_ewx_io_sense_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
548 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
549 unsigned char mask = kcontrol->private_value & 0xff;
552 if (kcontrol->private_value & (1 << 31))
554 nval = ucontrol->value.enumerated.item[0] ? mask : 0;
555 snd_ice1712_save_gpio_status(ice);
556 val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
558 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, nval);
559 snd_ice1712_restore_gpio_status(ice);
563 static snd_kcontrol_new_t snd_ice1712_ewx2496_controls[] __devinitdata = {
565 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
566 .name = "Input Sensitivity Switch",
567 .info = snd_ice1712_ewx_io_sense_info,
568 .get = snd_ice1712_ewx_io_sense_get,
569 .put = snd_ice1712_ewx_io_sense_put,
570 .private_value = ICE1712_EWX2496_AIN_SEL,
573 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
574 .name = "Output Sensitivity Switch",
575 .info = snd_ice1712_ewx_io_sense_info,
576 .get = snd_ice1712_ewx_io_sense_get,
577 .put = snd_ice1712_ewx_io_sense_put,
578 .private_value = ICE1712_EWX2496_AOUT_SEL,
584 * EWS88MT specific controls
586 /* analog output sensitivity;; address 0x48 bit 6 */
587 static int snd_ice1712_ews88mt_output_sense_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
589 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
592 snd_i2c_lock(ice->i2c);
593 if (snd_i2c_readbytes(ice->i2cdevs[1], &data, 1) != 1) {
594 snd_i2c_unlock(ice->i2c);
597 snd_i2c_unlock(ice->i2c);
598 ucontrol->value.enumerated.item[0] = data & ICE1712_EWS88MT_OUTPUT_SENSE ? 1 : 0; /* high = -10dBV, low = +4dBu */
602 /* analog output sensitivity;; address 0x48 bit 6 */
603 static int snd_ice1712_ews88mt_output_sense_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
605 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
606 unsigned char data, ndata;
608 snd_i2c_lock(ice->i2c);
609 if (snd_i2c_readbytes(ice->i2cdevs[1], &data, 1) != 1) {
610 snd_i2c_unlock(ice->i2c);
613 ndata = (data & ~ICE1712_EWS88MT_OUTPUT_SENSE) | (ucontrol->value.enumerated.item[0] ? ICE1712_EWS88MT_OUTPUT_SENSE : 0);
614 if (ndata != data && snd_i2c_sendbytes(ice->i2cdevs[1], &ndata, 1) != 1) {
615 snd_i2c_unlock(ice->i2c);
618 snd_i2c_unlock(ice->i2c);
619 return ndata != data;
622 /* analog input sensitivity; address 0x46 */
623 static int snd_ice1712_ews88mt_input_sense_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
625 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
626 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
629 snd_assert(channel >= 0 && channel <= 7, return 0);
630 snd_i2c_lock(ice->i2c);
631 if (snd_i2c_readbytes(ice->i2cdevs[0], &data, 1) != 1) {
632 snd_i2c_unlock(ice->i2c);
635 /* reversed; high = +4dBu, low = -10dBV */
636 ucontrol->value.enumerated.item[0] = data & (1 << channel) ? 0 : 1;
637 snd_i2c_unlock(ice->i2c);
641 /* analog output sensitivity; address 0x46 */
642 static int snd_ice1712_ews88mt_input_sense_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
644 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
645 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
646 unsigned char data, ndata;
648 snd_assert(channel >= 0 && channel <= 7, return 0);
649 snd_i2c_lock(ice->i2c);
650 if (snd_i2c_readbytes(ice->i2cdevs[0], &data, 1) != 1) {
651 snd_i2c_unlock(ice->i2c);
654 ndata = (data & ~(1 << channel)) | (ucontrol->value.enumerated.item[0] ? 0 : (1 << channel));
655 if (ndata != data && snd_i2c_sendbytes(ice->i2cdevs[0], &ndata, 1) != 1) {
656 snd_i2c_unlock(ice->i2c);
659 snd_i2c_unlock(ice->i2c);
660 return ndata != data;
663 static snd_kcontrol_new_t snd_ice1712_ews88mt_input_sense __devinitdata = {
664 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
665 .name = "Input Sensitivity Switch",
666 .info = snd_ice1712_ewx_io_sense_info,
667 .get = snd_ice1712_ews88mt_input_sense_get,
668 .put = snd_ice1712_ews88mt_input_sense_put,
672 static snd_kcontrol_new_t snd_ice1712_ews88mt_output_sense __devinitdata = {
673 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
674 .name = "Output Sensitivity Switch",
675 .info = snd_ice1712_ewx_io_sense_info,
676 .get = snd_ice1712_ews88mt_output_sense_get,
677 .put = snd_ice1712_ews88mt_output_sense_put,
682 * EWS88D specific controls
685 static int snd_ice1712_ews88d_control_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
687 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
689 uinfo->value.integer.min = 0;
690 uinfo->value.integer.max = 1;
694 static int snd_ice1712_ews88d_control_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
696 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
697 int shift = kcontrol->private_value & 0xff;
698 int invert = (kcontrol->private_value >> 8) & 1;
699 unsigned char data[2];
701 snd_i2c_lock(ice->i2c);
702 if (snd_i2c_readbytes(ice->i2cdevs[0], data, 2) != 2) {
703 snd_i2c_unlock(ice->i2c);
706 snd_i2c_unlock(ice->i2c);
707 data[0] = (data[shift >> 3] >> (shift & 7)) & 0x01;
710 ucontrol->value.integer.value[0] = data[0];
714 static int snd_ice1712_ews88d_control_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
716 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
717 int shift = kcontrol->private_value & 0xff;
718 int invert = (kcontrol->private_value >> 8) & 1;
719 unsigned char data[2], ndata[2];
722 snd_i2c_lock(ice->i2c);
723 if (snd_i2c_readbytes(ice->i2cdevs[0], data, 2) != 2) {
724 snd_i2c_unlock(ice->i2c);
727 ndata[shift >> 3] = data[shift >> 3] & ~(1 << (shift & 7));
729 if (! ucontrol->value.integer.value[0])
730 ndata[shift >> 3] |= (1 << (shift & 7));
732 if (ucontrol->value.integer.value[0])
733 ndata[shift >> 3] |= (1 << (shift & 7));
735 change = (data[shift >> 3] != ndata[shift >> 3]);
736 if (change && snd_i2c_sendbytes(ice->i2cdevs[0], data, 2) != 2) {
737 snd_i2c_unlock(ice->i2c);
740 snd_i2c_unlock(ice->i2c);
744 #define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
748 .info = snd_ice1712_ews88d_control_info,\
749 .get = snd_ice1712_ews88d_control_get,\
750 .put = snd_ice1712_ews88d_control_put,\
751 .private_value = xshift | (xinvert << 8),\
754 static snd_kcontrol_new_t snd_ice1712_ews88d_controls[] __devinitdata = {
755 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, 1, 0), /* inverted */
756 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Output Optical", 1, 0, 0),
757 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT External Master Clock", 2, 0, 0),
758 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "Enable ADAT", 3, 0, 0),
759 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Through", 4, 1, 0),
764 * DMX 6Fire specific controls
767 static int snd_ice1712_6fire_read_pca(ice1712_t *ice, unsigned char reg)
770 snd_i2c_lock(ice->i2c);
772 snd_i2c_sendbytes(ice->i2cdevs[0], &byte, 1);
774 if (snd_i2c_readbytes(ice->i2cdevs[0], &byte, 1) != 1) {
775 snd_i2c_unlock(ice->i2c);
776 printk("cannot read pca\n");
779 snd_i2c_unlock(ice->i2c);
783 static int snd_ice1712_6fire_write_pca(ice1712_t *ice, unsigned char reg, unsigned char data)
785 unsigned char bytes[2];
786 snd_i2c_lock(ice->i2c);
789 if (snd_i2c_sendbytes(ice->i2cdevs[0], bytes, 2) != 2) {
790 snd_i2c_unlock(ice->i2c);
793 snd_i2c_unlock(ice->i2c);
797 static int snd_ice1712_6fire_control_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
799 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
801 uinfo->value.integer.min = 0;
802 uinfo->value.integer.max = 1;
806 static int snd_ice1712_6fire_control_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
808 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
809 int shift = kcontrol->private_value & 0xff;
810 int invert = (kcontrol->private_value >> 8) & 1;
813 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
815 data = (data >> shift) & 1;
818 ucontrol->value.integer.value[0] = data;
822 static int snd_ice1712_6fire_control_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
824 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
825 int shift = kcontrol->private_value & 0xff;
826 int invert = (kcontrol->private_value >> 8) & 1;
829 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
831 ndata = data & ~(1 << shift);
832 if (ucontrol->value.integer.value[0])
833 ndata |= (1 << shift);
835 ndata ^= (1 << shift);
837 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
843 static int snd_ice1712_6fire_select_input_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
845 static char *texts[4] = {
846 "Internal", "Front Input", "Rear Input", "Wave Table"
848 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
850 uinfo->value.enumerated.items = 4;
851 if (uinfo->value.enumerated.item >= 4)
852 uinfo->value.enumerated.item = 1;
853 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
857 static int snd_ice1712_6fire_select_input_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
859 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
862 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
864 ucontrol->value.integer.value[0] = data & 3;
868 static int snd_ice1712_6fire_select_input_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
870 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
873 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
876 ndata |= (ucontrol->value.integer.value[0] & 3);
878 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
885 #define DMX6FIRE_CONTROL(xname, xshift, xinvert) \
886 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
888 .info = snd_ice1712_6fire_control_info,\
889 .get = snd_ice1712_6fire_control_get,\
890 .put = snd_ice1712_6fire_control_put,\
891 .private_value = xshift | (xinvert << 8),\
894 static snd_kcontrol_new_t snd_ice1712_6fire_controls[] __devinitdata = {
896 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
897 .name = "Analog Input Select",
898 .info = snd_ice1712_6fire_select_input_info,
899 .get = snd_ice1712_6fire_select_input_get,
900 .put = snd_ice1712_6fire_select_input_put,
902 DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 0),
903 // DMX6FIRE_CONTROL("Master Clock Select", 3, 0),
904 DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0),
905 DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0),
906 DMX6FIRE_CONTROL("Breakbox LED", 6, 0),
910 static int __devinit snd_ice1712_ews_add_controls(ice1712_t *ice)
915 /* all terratec cards have spdif, but cs8427 module builds it's own controls */
916 if (ice->cs8427 == NULL) {
917 err = snd_ice1712_spdif_build_controls(ice);
922 /* ak4524 controls */
923 switch (ice->eeprom.subvendor) {
924 case ICE1712_SUBDEVICE_EWX2496:
925 case ICE1712_SUBDEVICE_EWS88MT:
926 case ICE1712_SUBDEVICE_EWS88MT_NEW:
927 case ICE1712_SUBDEVICE_DMX6FIRE:
928 err = snd_ice1712_akm4xxx_build_controls(ice);
934 /* card specific controls */
935 switch (ice->eeprom.subvendor) {
936 case ICE1712_SUBDEVICE_EWX2496:
937 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ewx2496_controls); idx++) {
938 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ewx2496_controls[idx], ice));
943 case ICE1712_SUBDEVICE_EWS88MT:
944 case ICE1712_SUBDEVICE_EWS88MT_NEW:
945 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice));
948 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense, ice));
952 case ICE1712_SUBDEVICE_EWS88D:
953 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ews88d_controls); idx++) {
954 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_controls[idx], ice));
959 case ICE1712_SUBDEVICE_DMX6FIRE:
960 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_6fire_controls); idx++) {
961 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_6fire_controls[idx], ice));
972 struct snd_ice1712_card_info snd_ice1712_ews_cards[] __devinitdata = {
974 ICE1712_SUBDEVICE_EWX2496,
976 snd_ice1712_ews_init,
977 snd_ice1712_ews_add_controls,
980 ICE1712_SUBDEVICE_EWS88MT,
982 snd_ice1712_ews_init,
983 snd_ice1712_ews_add_controls,
986 ICE1712_SUBDEVICE_EWS88MT_NEW,
988 snd_ice1712_ews_init,
989 snd_ice1712_ews_add_controls,
992 ICE1712_SUBDEVICE_EWS88D,
994 snd_ice1712_ews_init,
995 snd_ice1712_ews_add_controls,
998 ICE1712_SUBDEVICE_DMX6FIRE,
1000 snd_ice1712_ews_init,
1001 snd_ice1712_ews_add_controls,
1003 { } /* terminator */