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 = bus->private_data;
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 = bus->private_data;
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 = bus->private_data;
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 = bus->private_data;
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 = bus->private_data;
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 = bus->private_data;
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 case ICE1712_SUBDEVICE_PHASE88:
227 snd_runtime_check(snd_i2c_sendbytes(ice->cs8404, &bits, 1) == 1, goto _error);
229 case ICE1712_SUBDEVICE_EWS88D:
230 snd_runtime_check(snd_i2c_readbytes(ice->i2cdevs[0], bytes, 2) == 2, goto _error);
231 if (bits != bytes[1]) {
233 snd_runtime_check(snd_i2c_readbytes(ice->i2cdevs[0], bytes, 2) == 2, goto _error);
238 snd_i2c_unlock(ice->i2c);
244 static void ews88_spdif_default_get(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
246 snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_bits);
249 static int ews88_spdif_default_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
254 val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
255 spin_lock_irq(&ice->reg_lock);
256 change = ice->spdif.cs8403_bits != val;
257 ice->spdif.cs8403_bits = val;
258 if (change && ice->playback_pro_substream == NULL) {
259 spin_unlock_irq(&ice->reg_lock);
260 snd_ice1712_ews_cs8404_spdif_write(ice, val);
262 spin_unlock_irq(&ice->reg_lock);
267 static void ews88_spdif_stream_get(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
269 snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_stream_bits);
272 static int ews88_spdif_stream_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
277 val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
278 spin_lock_irq(&ice->reg_lock);
279 change = ice->spdif.cs8403_stream_bits != val;
280 ice->spdif.cs8403_stream_bits = val;
281 if (change && ice->playback_pro_substream != NULL) {
282 spin_unlock_irq(&ice->reg_lock);
283 snd_ice1712_ews_cs8404_spdif_write(ice, val);
285 spin_unlock_irq(&ice->reg_lock);
292 static void ews88_open_spdif(ice1712_t *ice, snd_pcm_substream_t * substream)
294 ice->spdif.cs8403_stream_bits = ice->spdif.cs8403_bits;
297 /* set up SPDIF for EWS88MT / EWS88D */
298 static void ews88_setup_spdif(ice1712_t *ice, int rate)
304 spin_lock_irqsave(&ice->reg_lock, flags);
305 tmp = ice->spdif.cs8403_stream_bits;
306 if (tmp & 0x10) /* consumer */
307 tmp &= (tmp & 0x01) ? ~0x06 : ~0x60;
309 case 32000: tmp |= (tmp & 0x01) ? 0x02 : 0x00; break;
310 case 44100: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
311 case 48000: tmp |= (tmp & 0x01) ? 0x04 : 0x20; break;
312 default: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
314 change = ice->spdif.cs8403_stream_bits != tmp;
315 ice->spdif.cs8403_stream_bits = tmp;
316 spin_unlock_irqrestore(&ice->reg_lock, flags);
318 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &ice->spdif.stream_ctl->id);
319 snd_ice1712_ews_cs8404_spdif_write(ice, tmp);
325 static akm4xxx_t akm_ews88mt __devinitdata = {
330 .lock = ews88mt_ak4524_lock,
331 .unlock = ews88mt_ak4524_unlock
335 static struct snd_ak4xxx_private akm_ews88mt_priv __devinitdata = {
337 .cif = 1, /* CIF high */
338 .data_mask = ICE1712_EWS88_SERIAL_DATA,
339 .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
342 .cs_none = 0, /* no chip select on gpio */
343 .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
347 static akm4xxx_t akm_ewx2496 __devinitdata = {
352 .lock = ewx2496_ak4524_lock
356 static struct snd_ak4xxx_private akm_ewx2496_priv __devinitdata = {
358 .cif = 1, /* CIF high */
359 .data_mask = ICE1712_EWS88_SERIAL_DATA,
360 .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
361 .cs_mask = ICE1712_EWX2496_AK4524_CS,
362 .cs_addr = ICE1712_EWX2496_AK4524_CS,
364 .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
368 static akm4xxx_t akm_6fire __devinitdata = {
373 .lock = dmx6fire_ak4524_lock
377 static struct snd_ak4xxx_private akm_6fire_priv __devinitdata = {
379 .cif = 1, /* CIF high */
380 .data_mask = ICE1712_6FIRE_SERIAL_DATA,
381 .clk_mask = ICE1712_6FIRE_SERIAL_CLOCK,
383 .cs_addr = 0, /* set later */
385 .add_flags = ICE1712_6FIRE_RW, /* set rw bit high */
390 * initialize the chip
394 #define PCF9554_REG_INPUT 0
395 #define PCF9554_REG_OUTPUT 1
396 #define PCF9554_REG_POLARITY 2
397 #define PCF9554_REG_CONFIG 3
399 static int snd_ice1712_6fire_write_pca(ice1712_t *ice, unsigned char reg, unsigned char data);
401 static int __devinit snd_ice1712_ews_init(ice1712_t *ice)
406 /* set the analog DACs */
407 switch (ice->eeprom.subvendor) {
408 case ICE1712_SUBDEVICE_EWX2496:
409 ice->num_total_dacs = 2;
410 ice->num_total_adcs = 2;
412 case ICE1712_SUBDEVICE_EWS88MT:
413 case ICE1712_SUBDEVICE_EWS88MT_NEW:
414 case ICE1712_SUBDEVICE_PHASE88:
415 ice->num_total_dacs = 8;
416 ice->num_total_adcs = 8;
418 case ICE1712_SUBDEVICE_EWS88D:
419 break; /* no analog */
420 case ICE1712_SUBDEVICE_DMX6FIRE:
421 ice->num_total_dacs = 6;
422 ice->num_total_adcs = 6;
427 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
428 snd_printk("unable to create I2C bus\n");
431 ice->i2c->private_data = ice;
432 ice->i2c->hw_ops.bit = &snd_ice1712_ewx_cs8427_bit_ops;
434 /* create i2c devices */
435 switch (ice->eeprom.subvendor) {
436 case ICE1712_SUBDEVICE_DMX6FIRE:
437 if ((err = snd_i2c_device_create(ice->i2c, "PCF9554", ICE1712_6FIRE_PCF9554_ADDR, &ice->i2cdevs[0])) < 0) {
438 snd_printk("PCF9554 initialization failed\n");
441 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80);
443 case ICE1712_SUBDEVICE_EWS88MT:
444 case ICE1712_SUBDEVICE_EWS88MT_NEW:
445 case ICE1712_SUBDEVICE_PHASE88:
446 if ((err = snd_i2c_device_create(ice->i2c, "CS8404", ICE1712_EWS88MT_CS8404_ADDR, &ice->cs8404)) < 0)
448 if ((err = snd_i2c_device_create(ice->i2c, "PCF8574 (1st)", ICE1712_EWS88MT_INPUT_ADDR, &ice->i2cdevs[0])) < 0)
450 if ((err = snd_i2c_device_create(ice->i2c, "PCF8574 (2nd)", ICE1712_EWS88MT_OUTPUT_ADDR, &ice->i2cdevs[1])) < 0)
452 /* Check if the front module is connected */
453 if ((err = snd_ice1712_ews88mt_chip_select(ice, 0x0f)) < 0)
456 case ICE1712_SUBDEVICE_EWS88D:
457 if ((err = snd_i2c_device_create(ice->i2c, "PCF8575", ICE1712_EWS88D_PCF_ADDR, &ice->i2cdevs[0])) < 0)
462 /* set up SPDIF interface */
463 switch (ice->eeprom.subvendor) {
464 case ICE1712_SUBDEVICE_EWX2496:
465 if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0)
467 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
469 case ICE1712_SUBDEVICE_DMX6FIRE:
470 if ((err = snd_ice1712_init_cs8427(ice, ICE1712_6FIRE_CS8427_ADDR)) < 0)
472 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
474 case ICE1712_SUBDEVICE_EWS88MT:
475 case ICE1712_SUBDEVICE_EWS88MT_NEW:
476 case ICE1712_SUBDEVICE_PHASE88:
477 case ICE1712_SUBDEVICE_EWS88D:
479 ice->spdif.ops.open = ews88_open_spdif;
480 ice->spdif.ops.setup_rate = ews88_setup_spdif;
481 ice->spdif.ops.default_get = ews88_spdif_default_get;
482 ice->spdif.ops.default_put = ews88_spdif_default_put;
483 ice->spdif.ops.stream_get = ews88_spdif_stream_get;
484 ice->spdif.ops.stream_put = ews88_spdif_stream_put;
485 /* Set spdif defaults */
486 snd_ice1712_ews_cs8404_spdif_write(ice, ice->spdif.cs8403_bits);
491 switch (ice->eeprom.subvendor) {
492 case ICE1712_SUBDEVICE_EWS88D:
497 ak = ice->akm = kmalloc(sizeof(akm4xxx_t), GFP_KERNEL);
502 switch (ice->eeprom.subvendor) {
503 case ICE1712_SUBDEVICE_EWS88MT:
504 case ICE1712_SUBDEVICE_EWS88MT_NEW:
505 case ICE1712_SUBDEVICE_PHASE88:
506 err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice);
508 case ICE1712_SUBDEVICE_EWX2496:
509 err = snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, &akm_ewx2496_priv, ice);
511 case ICE1712_SUBDEVICE_DMX6FIRE:
512 err = snd_ice1712_akm4xxx_init(ak, &akm_6fire, &akm_6fire_priv, ice);
522 * EWX 24/96 specific controls
525 /* i/o sensitivity - this callback is shared among other devices, too */
526 static int snd_ice1712_ewx_io_sense_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo){
528 static char *texts[2] = {
531 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
533 uinfo->value.enumerated.items = 2;
534 if (uinfo->value.enumerated.item >= 2)
535 uinfo->value.enumerated.item = 1;
536 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
540 static int snd_ice1712_ewx_io_sense_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
542 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
543 unsigned char mask = kcontrol->private_value & 0xff;
545 snd_ice1712_save_gpio_status(ice);
546 ucontrol->value.enumerated.item[0] = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0;
547 snd_ice1712_restore_gpio_status(ice);
551 static int snd_ice1712_ewx_io_sense_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
553 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
554 unsigned char mask = kcontrol->private_value & 0xff;
557 if (kcontrol->private_value & (1 << 31))
559 nval = ucontrol->value.enumerated.item[0] ? mask : 0;
560 snd_ice1712_save_gpio_status(ice);
561 val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
563 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, nval);
564 snd_ice1712_restore_gpio_status(ice);
568 static snd_kcontrol_new_t snd_ice1712_ewx2496_controls[] __devinitdata = {
570 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
571 .name = "Input Sensitivity Switch",
572 .info = snd_ice1712_ewx_io_sense_info,
573 .get = snd_ice1712_ewx_io_sense_get,
574 .put = snd_ice1712_ewx_io_sense_put,
575 .private_value = ICE1712_EWX2496_AIN_SEL,
578 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
579 .name = "Output Sensitivity Switch",
580 .info = snd_ice1712_ewx_io_sense_info,
581 .get = snd_ice1712_ewx_io_sense_get,
582 .put = snd_ice1712_ewx_io_sense_put,
583 .private_value = ICE1712_EWX2496_AOUT_SEL,
589 * EWS88MT specific controls
591 /* analog output sensitivity;; address 0x48 bit 6 */
592 static int snd_ice1712_ews88mt_output_sense_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
594 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
597 snd_i2c_lock(ice->i2c);
598 if (snd_i2c_readbytes(ice->i2cdevs[1], &data, 1) != 1) {
599 snd_i2c_unlock(ice->i2c);
602 snd_i2c_unlock(ice->i2c);
603 ucontrol->value.enumerated.item[0] = data & ICE1712_EWS88MT_OUTPUT_SENSE ? 1 : 0; /* high = -10dBV, low = +4dBu */
607 /* analog output sensitivity;; address 0x48 bit 6 */
608 static int snd_ice1712_ews88mt_output_sense_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
610 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
611 unsigned char data, ndata;
613 snd_i2c_lock(ice->i2c);
614 if (snd_i2c_readbytes(ice->i2cdevs[1], &data, 1) != 1) {
615 snd_i2c_unlock(ice->i2c);
618 ndata = (data & ~ICE1712_EWS88MT_OUTPUT_SENSE) | (ucontrol->value.enumerated.item[0] ? ICE1712_EWS88MT_OUTPUT_SENSE : 0);
619 if (ndata != data && snd_i2c_sendbytes(ice->i2cdevs[1], &ndata, 1) != 1) {
620 snd_i2c_unlock(ice->i2c);
623 snd_i2c_unlock(ice->i2c);
624 return ndata != data;
627 /* analog input sensitivity; address 0x46 */
628 static int snd_ice1712_ews88mt_input_sense_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
630 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
631 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
634 snd_assert(channel >= 0 && channel <= 7, return 0);
635 snd_i2c_lock(ice->i2c);
636 if (snd_i2c_readbytes(ice->i2cdevs[0], &data, 1) != 1) {
637 snd_i2c_unlock(ice->i2c);
640 /* reversed; high = +4dBu, low = -10dBV */
641 ucontrol->value.enumerated.item[0] = data & (1 << channel) ? 0 : 1;
642 snd_i2c_unlock(ice->i2c);
646 /* analog output sensitivity; address 0x46 */
647 static int snd_ice1712_ews88mt_input_sense_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
649 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
650 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
651 unsigned char data, ndata;
653 snd_assert(channel >= 0 && channel <= 7, return 0);
654 snd_i2c_lock(ice->i2c);
655 if (snd_i2c_readbytes(ice->i2cdevs[0], &data, 1) != 1) {
656 snd_i2c_unlock(ice->i2c);
659 ndata = (data & ~(1 << channel)) | (ucontrol->value.enumerated.item[0] ? 0 : (1 << channel));
660 if (ndata != data && snd_i2c_sendbytes(ice->i2cdevs[0], &ndata, 1) != 1) {
661 snd_i2c_unlock(ice->i2c);
664 snd_i2c_unlock(ice->i2c);
665 return ndata != data;
668 static snd_kcontrol_new_t snd_ice1712_ews88mt_input_sense __devinitdata = {
669 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
670 .name = "Input Sensitivity Switch",
671 .info = snd_ice1712_ewx_io_sense_info,
672 .get = snd_ice1712_ews88mt_input_sense_get,
673 .put = snd_ice1712_ews88mt_input_sense_put,
677 static snd_kcontrol_new_t snd_ice1712_ews88mt_output_sense __devinitdata = {
678 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
679 .name = "Output Sensitivity Switch",
680 .info = snd_ice1712_ewx_io_sense_info,
681 .get = snd_ice1712_ews88mt_output_sense_get,
682 .put = snd_ice1712_ews88mt_output_sense_put,
687 * EWS88D specific controls
690 static int snd_ice1712_ews88d_control_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
692 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
694 uinfo->value.integer.min = 0;
695 uinfo->value.integer.max = 1;
699 static int snd_ice1712_ews88d_control_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
701 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
702 int shift = kcontrol->private_value & 0xff;
703 int invert = (kcontrol->private_value >> 8) & 1;
704 unsigned char data[2];
706 snd_i2c_lock(ice->i2c);
707 if (snd_i2c_readbytes(ice->i2cdevs[0], data, 2) != 2) {
708 snd_i2c_unlock(ice->i2c);
711 snd_i2c_unlock(ice->i2c);
712 data[0] = (data[shift >> 3] >> (shift & 7)) & 0x01;
715 ucontrol->value.integer.value[0] = data[0];
719 static int snd_ice1712_ews88d_control_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
721 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
722 int shift = kcontrol->private_value & 0xff;
723 int invert = (kcontrol->private_value >> 8) & 1;
724 unsigned char data[2], ndata[2];
727 snd_i2c_lock(ice->i2c);
728 if (snd_i2c_readbytes(ice->i2cdevs[0], data, 2) != 2) {
729 snd_i2c_unlock(ice->i2c);
732 ndata[shift >> 3] = data[shift >> 3] & ~(1 << (shift & 7));
734 if (! ucontrol->value.integer.value[0])
735 ndata[shift >> 3] |= (1 << (shift & 7));
737 if (ucontrol->value.integer.value[0])
738 ndata[shift >> 3] |= (1 << (shift & 7));
740 change = (data[shift >> 3] != ndata[shift >> 3]);
741 if (change && snd_i2c_sendbytes(ice->i2cdevs[0], data, 2) != 2) {
742 snd_i2c_unlock(ice->i2c);
745 snd_i2c_unlock(ice->i2c);
749 #define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
753 .info = snd_ice1712_ews88d_control_info,\
754 .get = snd_ice1712_ews88d_control_get,\
755 .put = snd_ice1712_ews88d_control_put,\
756 .private_value = xshift | (xinvert << 8),\
759 static snd_kcontrol_new_t snd_ice1712_ews88d_controls[] __devinitdata = {
760 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, 1, 0), /* inverted */
761 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Output Optical", 1, 0, 0),
762 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT External Master Clock", 2, 0, 0),
763 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "Enable ADAT", 3, 0, 0),
764 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Through", 4, 1, 0),
769 * DMX 6Fire specific controls
772 static int snd_ice1712_6fire_read_pca(ice1712_t *ice, unsigned char reg)
775 snd_i2c_lock(ice->i2c);
777 snd_i2c_sendbytes(ice->i2cdevs[0], &byte, 1);
779 if (snd_i2c_readbytes(ice->i2cdevs[0], &byte, 1) != 1) {
780 snd_i2c_unlock(ice->i2c);
781 printk("cannot read pca\n");
784 snd_i2c_unlock(ice->i2c);
788 static int snd_ice1712_6fire_write_pca(ice1712_t *ice, unsigned char reg, unsigned char data)
790 unsigned char bytes[2];
791 snd_i2c_lock(ice->i2c);
794 if (snd_i2c_sendbytes(ice->i2cdevs[0], bytes, 2) != 2) {
795 snd_i2c_unlock(ice->i2c);
798 snd_i2c_unlock(ice->i2c);
802 static int snd_ice1712_6fire_control_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
804 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
806 uinfo->value.integer.min = 0;
807 uinfo->value.integer.max = 1;
811 static int snd_ice1712_6fire_control_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
813 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
814 int shift = kcontrol->private_value & 0xff;
815 int invert = (kcontrol->private_value >> 8) & 1;
818 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
820 data = (data >> shift) & 1;
823 ucontrol->value.integer.value[0] = data;
827 static int snd_ice1712_6fire_control_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
829 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
830 int shift = kcontrol->private_value & 0xff;
831 int invert = (kcontrol->private_value >> 8) & 1;
834 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
836 ndata = data & ~(1 << shift);
837 if (ucontrol->value.integer.value[0])
838 ndata |= (1 << shift);
840 ndata ^= (1 << shift);
842 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
848 static int snd_ice1712_6fire_select_input_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
850 static char *texts[4] = {
851 "Internal", "Front Input", "Rear Input", "Wave Table"
853 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
855 uinfo->value.enumerated.items = 4;
856 if (uinfo->value.enumerated.item >= 4)
857 uinfo->value.enumerated.item = 1;
858 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
862 static int snd_ice1712_6fire_select_input_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
864 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
867 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
869 ucontrol->value.integer.value[0] = data & 3;
873 static int snd_ice1712_6fire_select_input_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
875 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
878 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
881 ndata |= (ucontrol->value.integer.value[0] & 3);
883 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
890 #define DMX6FIRE_CONTROL(xname, xshift, xinvert) \
891 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
893 .info = snd_ice1712_6fire_control_info,\
894 .get = snd_ice1712_6fire_control_get,\
895 .put = snd_ice1712_6fire_control_put,\
896 .private_value = xshift | (xinvert << 8),\
899 static snd_kcontrol_new_t snd_ice1712_6fire_controls[] __devinitdata = {
901 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
902 .name = "Analog Input Select",
903 .info = snd_ice1712_6fire_select_input_info,
904 .get = snd_ice1712_6fire_select_input_get,
905 .put = snd_ice1712_6fire_select_input_put,
907 DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 0),
908 // DMX6FIRE_CONTROL("Master Clock Select", 3, 0),
909 DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0),
910 DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0),
911 DMX6FIRE_CONTROL("Breakbox LED", 6, 0),
915 static int __devinit snd_ice1712_ews_add_controls(ice1712_t *ice)
920 /* all terratec cards have spdif, but cs8427 module builds it's own controls */
921 if (ice->cs8427 == NULL) {
922 err = snd_ice1712_spdif_build_controls(ice);
927 /* ak4524 controls */
928 switch (ice->eeprom.subvendor) {
929 case ICE1712_SUBDEVICE_EWX2496:
930 case ICE1712_SUBDEVICE_EWS88MT:
931 case ICE1712_SUBDEVICE_EWS88MT_NEW:
932 case ICE1712_SUBDEVICE_PHASE88:
933 case ICE1712_SUBDEVICE_DMX6FIRE:
934 err = snd_ice1712_akm4xxx_build_controls(ice);
940 /* card specific controls */
941 switch (ice->eeprom.subvendor) {
942 case ICE1712_SUBDEVICE_EWX2496:
943 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ewx2496_controls); idx++) {
944 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ewx2496_controls[idx], ice));
949 case ICE1712_SUBDEVICE_EWS88MT:
950 case ICE1712_SUBDEVICE_EWS88MT_NEW:
951 case ICE1712_SUBDEVICE_PHASE88:
952 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice));
955 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense, ice));
959 case ICE1712_SUBDEVICE_EWS88D:
960 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ews88d_controls); idx++) {
961 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_controls[idx], ice));
966 case ICE1712_SUBDEVICE_DMX6FIRE:
967 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_6fire_controls); idx++) {
968 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_6fire_controls[idx], ice));
979 struct snd_ice1712_card_info snd_ice1712_ews_cards[] __devinitdata = {
981 .subvendor = ICE1712_SUBDEVICE_EWX2496,
982 .name = "TerraTec EWX24/96",
984 .chip_init = snd_ice1712_ews_init,
985 .build_controls = snd_ice1712_ews_add_controls,
988 .subvendor = ICE1712_SUBDEVICE_EWS88MT,
989 .name = "TerraTec EWS88MT",
991 .chip_init = snd_ice1712_ews_init,
992 .build_controls = snd_ice1712_ews_add_controls,
995 .subvendor = ICE1712_SUBDEVICE_EWS88MT_NEW,
996 .name = "TerraTec EWS88MT",
997 .model = "ews88mt_new",
998 .chip_init = snd_ice1712_ews_init,
999 .build_controls = snd_ice1712_ews_add_controls,
1002 .subvendor = ICE1712_SUBDEVICE_PHASE88,
1003 .name = "TerraTec Phase88",
1005 .chip_init = snd_ice1712_ews_init,
1006 .build_controls = snd_ice1712_ews_add_controls,
1009 .subvendor = ICE1712_SUBDEVICE_EWS88D,
1010 .name = "TerraTec EWS88D",
1012 .chip_init = snd_ice1712_ews_init,
1013 .build_controls = snd_ice1712_ews_add_controls,
1016 .subvendor = ICE1712_SUBDEVICE_DMX6FIRE,
1017 .name = "TerraTec DMX6Fire",
1018 .model = "dmx6fire",
1019 .chip_init = snd_ice1712_ews_init,
1020 .build_controls = snd_ice1712_ews_add_controls,
1022 { } /* terminator */