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
25 #include <linux/delay.h>
26 #include <linux/interrupt.h>
27 #include <linux/init.h>
28 #include <linux/slab.h>
29 #include <sound/core.h>
30 #include <sound/cs8427.h>
31 #include <sound/asoundef.h>
37 #include <sound/cs8403.h>
40 EWS_I2C_CS8404
= 0, EWS_I2C_PCF1
, EWS_I2C_PCF2
,
46 /* additional i2c devices for EWS boards */
48 struct snd_i2c_device
*i2cdevs
[3];
52 * access via i2c mode (for EWX 24/96, EWS 88MT&D)
55 /* send SDA and SCL */
56 static void ewx_i2c_setlines(struct snd_i2c_bus
*bus
, int clk
, int data
)
58 struct snd_ice1712
*ice
= bus
->private_data
;
59 unsigned char tmp
= 0;
61 tmp
|= ICE1712_EWX2496_SERIAL_CLOCK
;
63 tmp
|= ICE1712_EWX2496_SERIAL_DATA
;
64 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, tmp
);
68 static int ewx_i2c_getclock(struct snd_i2c_bus
*bus
)
70 struct snd_ice1712
*ice
= bus
->private_data
;
71 return snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
) & ICE1712_EWX2496_SERIAL_CLOCK
? 1 : 0;
74 static int ewx_i2c_getdata(struct snd_i2c_bus
*bus
, int ack
)
76 struct snd_ice1712
*ice
= bus
->private_data
;
78 /* set RW pin to low */
79 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, ~ICE1712_EWX2496_RW
);
80 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, 0);
83 bit
= snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
) & ICE1712_EWX2496_SERIAL_DATA
? 1 : 0;
84 /* set RW pin to high */
85 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, ICE1712_EWX2496_RW
);
86 /* reset write mask */
87 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, ~ICE1712_EWX2496_SERIAL_CLOCK
);
91 static void ewx_i2c_start(struct snd_i2c_bus
*bus
)
93 struct snd_ice1712
*ice
= bus
->private_data
;
96 snd_ice1712_save_gpio_status(ice
);
98 mask
= ICE1712_EWX2496_RW
;
99 switch (ice
->eeprom
.subvendor
) {
100 case ICE1712_SUBDEVICE_EWX2496
:
101 mask
|= ICE1712_EWX2496_AK4524_CS
; /* CS high also */
103 case ICE1712_SUBDEVICE_DMX6FIRE
:
104 mask
|= ICE1712_6FIRE_AK4524_CS_MASK
; /* CS high also */
107 snd_ice1712_gpio_write_bits(ice
, mask
, mask
);
110 static void ewx_i2c_stop(struct snd_i2c_bus
*bus
)
112 struct snd_ice1712
*ice
= bus
->private_data
;
113 snd_ice1712_restore_gpio_status(ice
);
116 static void ewx_i2c_direction(struct snd_i2c_bus
*bus
, int clock
, int data
)
118 struct snd_ice1712
*ice
= bus
->private_data
;
119 unsigned char mask
= 0;
122 mask
|= ICE1712_EWX2496_SERIAL_CLOCK
; /* write SCL */
124 mask
|= ICE1712_EWX2496_SERIAL_DATA
; /* write SDA */
125 ice
->gpio
.direction
&= ~(ICE1712_EWX2496_SERIAL_CLOCK
|ICE1712_EWX2496_SERIAL_DATA
);
126 ice
->gpio
.direction
|= mask
;
127 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DIRECTION
, ice
->gpio
.direction
);
128 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, ~mask
);
131 static struct snd_i2c_bit_ops snd_ice1712_ewx_cs8427_bit_ops
= {
132 .start
= ewx_i2c_start
,
133 .stop
= ewx_i2c_stop
,
134 .direction
= ewx_i2c_direction
,
135 .setlines
= ewx_i2c_setlines
,
136 .getclock
= ewx_i2c_getclock
,
137 .getdata
= ewx_i2c_getdata
,
145 /* AK4524 chip select; address 0x48 bit 0-3 */
146 static int snd_ice1712_ews88mt_chip_select(struct snd_ice1712
*ice
, int chip_mask
)
148 struct ews_spec
*spec
= ice
->spec
;
149 unsigned char data
, ndata
;
151 if (snd_BUG_ON(chip_mask
< 0 || chip_mask
> 0x0f))
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 case ICE1712_SUBDEVICE_TS88
:
242 if (snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_CS8404
], &bits
, 1)
246 case ICE1712_SUBDEVICE_EWS88D
:
247 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_88D
], bytes
, 2)
250 if (bits
!= bytes
[1]) {
252 if (snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_88D
],
259 snd_i2c_unlock(ice
->i2c
);
265 static void ews88_spdif_default_get(struct snd_ice1712
*ice
, struct snd_ctl_elem_value
*ucontrol
)
267 snd_cs8404_decode_spdif_bits(&ucontrol
->value
.iec958
, ice
->spdif
.cs8403_bits
);
270 static int ews88_spdif_default_put(struct snd_ice1712
*ice
, struct snd_ctl_elem_value
*ucontrol
)
275 val
= snd_cs8404_encode_spdif_bits(&ucontrol
->value
.iec958
);
276 spin_lock_irq(&ice
->reg_lock
);
277 change
= ice
->spdif
.cs8403_bits
!= val
;
278 ice
->spdif
.cs8403_bits
= val
;
279 if (change
&& ice
->playback_pro_substream
== NULL
) {
280 spin_unlock_irq(&ice
->reg_lock
);
281 snd_ice1712_ews_cs8404_spdif_write(ice
, val
);
283 spin_unlock_irq(&ice
->reg_lock
);
288 static void ews88_spdif_stream_get(struct snd_ice1712
*ice
, struct snd_ctl_elem_value
*ucontrol
)
290 snd_cs8404_decode_spdif_bits(&ucontrol
->value
.iec958
, ice
->spdif
.cs8403_stream_bits
);
293 static int ews88_spdif_stream_put(struct snd_ice1712
*ice
, struct snd_ctl_elem_value
*ucontrol
)
298 val
= snd_cs8404_encode_spdif_bits(&ucontrol
->value
.iec958
);
299 spin_lock_irq(&ice
->reg_lock
);
300 change
= ice
->spdif
.cs8403_stream_bits
!= val
;
301 ice
->spdif
.cs8403_stream_bits
= val
;
302 if (change
&& ice
->playback_pro_substream
!= NULL
) {
303 spin_unlock_irq(&ice
->reg_lock
);
304 snd_ice1712_ews_cs8404_spdif_write(ice
, val
);
306 spin_unlock_irq(&ice
->reg_lock
);
313 static void ews88_open_spdif(struct snd_ice1712
*ice
, struct snd_pcm_substream
*substream
)
315 ice
->spdif
.cs8403_stream_bits
= ice
->spdif
.cs8403_bits
;
318 /* set up SPDIF for EWS88MT / EWS88D */
319 static void ews88_setup_spdif(struct snd_ice1712
*ice
, int rate
)
325 spin_lock_irqsave(&ice
->reg_lock
, flags
);
326 tmp
= ice
->spdif
.cs8403_stream_bits
;
327 if (tmp
& 0x10) /* consumer */
328 tmp
&= (tmp
& 0x01) ? ~0x06 : ~0x60;
330 case 32000: tmp
|= (tmp
& 0x01) ? 0x02 : 0x00; break;
331 case 44100: tmp
|= (tmp
& 0x01) ? 0x06 : 0x40; break;
332 case 48000: tmp
|= (tmp
& 0x01) ? 0x04 : 0x20; break;
333 default: tmp
|= (tmp
& 0x01) ? 0x06 : 0x40; break;
335 change
= ice
->spdif
.cs8403_stream_bits
!= tmp
;
336 ice
->spdif
.cs8403_stream_bits
= tmp
;
337 spin_unlock_irqrestore(&ice
->reg_lock
, flags
);
339 snd_ctl_notify(ice
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &ice
->spdif
.stream_ctl
->id
);
340 snd_ice1712_ews_cs8404_spdif_write(ice
, tmp
);
346 static struct snd_akm4xxx akm_ews88mt
= {
351 .lock
= ews88mt_ak4524_lock
,
352 .unlock
= ews88mt_ak4524_unlock
356 static struct snd_ak4xxx_private akm_ews88mt_priv
= {
358 .cif
= 1, /* CIF high */
359 .data_mask
= ICE1712_EWS88_SERIAL_DATA
,
360 .clk_mask
= ICE1712_EWS88_SERIAL_CLOCK
,
363 .cs_none
= 0, /* no chip select on gpio */
364 .add_flags
= ICE1712_EWS88_RW
, /* set rw bit high */
368 static struct snd_akm4xxx akm_ewx2496
= {
373 .lock
= ewx2496_ak4524_lock
377 static struct snd_ak4xxx_private akm_ewx2496_priv
= {
379 .cif
= 1, /* CIF high */
380 .data_mask
= ICE1712_EWS88_SERIAL_DATA
,
381 .clk_mask
= ICE1712_EWS88_SERIAL_CLOCK
,
382 .cs_mask
= ICE1712_EWX2496_AK4524_CS
,
383 .cs_addr
= ICE1712_EWX2496_AK4524_CS
,
385 .add_flags
= ICE1712_EWS88_RW
, /* set rw bit high */
389 static struct snd_akm4xxx akm_6fire
= {
394 .lock
= dmx6fire_ak4524_lock
398 static struct snd_ak4xxx_private akm_6fire_priv
= {
400 .cif
= 1, /* CIF high */
401 .data_mask
= ICE1712_6FIRE_SERIAL_DATA
,
402 .clk_mask
= ICE1712_6FIRE_SERIAL_CLOCK
,
404 .cs_addr
= 0, /* set later */
406 .add_flags
= ICE1712_6FIRE_RW
, /* set rw bit high */
411 * initialize the chip
415 #define PCF9554_REG_INPUT 0
416 #define PCF9554_REG_OUTPUT 1
417 #define PCF9554_REG_POLARITY 2
418 #define PCF9554_REG_CONFIG 3
420 static int snd_ice1712_6fire_write_pca(struct snd_ice1712
*ice
, unsigned char reg
, unsigned char data
);
422 static int snd_ice1712_ews_init(struct snd_ice1712
*ice
)
425 struct snd_akm4xxx
*ak
;
426 struct ews_spec
*spec
;
428 /* set the analog DACs */
429 switch (ice
->eeprom
.subvendor
) {
430 case ICE1712_SUBDEVICE_EWX2496
:
431 ice
->num_total_dacs
= 2;
432 ice
->num_total_adcs
= 2;
434 case ICE1712_SUBDEVICE_EWS88MT
:
435 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
436 case ICE1712_SUBDEVICE_PHASE88
:
437 case ICE1712_SUBDEVICE_TS88
:
438 ice
->num_total_dacs
= 8;
439 ice
->num_total_adcs
= 8;
441 case ICE1712_SUBDEVICE_EWS88D
:
442 /* Note: not analog but ADAT I/O */
443 ice
->num_total_dacs
= 8;
444 ice
->num_total_adcs
= 8;
446 case ICE1712_SUBDEVICE_DMX6FIRE
:
447 ice
->num_total_dacs
= 6;
448 ice
->num_total_adcs
= 6;
452 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
458 if ((err
= snd_i2c_bus_create(ice
->card
, "ICE1712 GPIO 1", NULL
, &ice
->i2c
)) < 0) {
459 snd_printk(KERN_ERR
"unable to create I2C bus\n");
462 ice
->i2c
->private_data
= ice
;
463 ice
->i2c
->hw_ops
.bit
= &snd_ice1712_ewx_cs8427_bit_ops
;
465 /* create i2c devices */
466 switch (ice
->eeprom
.subvendor
) {
467 case ICE1712_SUBDEVICE_DMX6FIRE
:
468 err
= snd_i2c_device_create(ice
->i2c
, "PCF9554",
469 ICE1712_6FIRE_PCF9554_ADDR
,
470 &spec
->i2cdevs
[EWS_I2C_6FIRE
]);
472 snd_printk(KERN_ERR
"PCF9554 initialization failed\n");
475 snd_ice1712_6fire_write_pca(ice
, PCF9554_REG_CONFIG
, 0x80);
477 case ICE1712_SUBDEVICE_EWS88MT
:
478 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
479 case ICE1712_SUBDEVICE_PHASE88
:
480 case ICE1712_SUBDEVICE_TS88
:
482 err
= snd_i2c_device_create(ice
->i2c
, "CS8404",
483 ICE1712_EWS88MT_CS8404_ADDR
,
484 &spec
->i2cdevs
[EWS_I2C_CS8404
]);
487 err
= snd_i2c_device_create(ice
->i2c
, "PCF8574 (1st)",
488 ICE1712_EWS88MT_INPUT_ADDR
,
489 &spec
->i2cdevs
[EWS_I2C_PCF1
]);
492 err
= snd_i2c_device_create(ice
->i2c
, "PCF8574 (2nd)",
493 ICE1712_EWS88MT_OUTPUT_ADDR
,
494 &spec
->i2cdevs
[EWS_I2C_PCF2
]);
497 /* Check if the front module is connected */
498 if ((err
= snd_ice1712_ews88mt_chip_select(ice
, 0x0f)) < 0)
501 case ICE1712_SUBDEVICE_EWS88D
:
502 err
= snd_i2c_device_create(ice
->i2c
, "PCF8575",
503 ICE1712_EWS88D_PCF_ADDR
,
504 &spec
->i2cdevs
[EWS_I2C_88D
]);
510 /* set up SPDIF interface */
511 switch (ice
->eeprom
.subvendor
) {
512 case ICE1712_SUBDEVICE_EWX2496
:
513 if ((err
= snd_ice1712_init_cs8427(ice
, CS8427_BASE_ADDR
)) < 0)
515 snd_cs8427_reg_write(ice
->cs8427
, CS8427_REG_RECVERRMASK
, CS8427_UNLOCK
| CS8427_CONF
| CS8427_BIP
| CS8427_PAR
);
517 case ICE1712_SUBDEVICE_DMX6FIRE
:
518 if ((err
= snd_ice1712_init_cs8427(ice
, ICE1712_6FIRE_CS8427_ADDR
)) < 0)
520 snd_cs8427_reg_write(ice
->cs8427
, CS8427_REG_RECVERRMASK
, CS8427_UNLOCK
| CS8427_CONF
| CS8427_BIP
| CS8427_PAR
);
522 case ICE1712_SUBDEVICE_EWS88MT
:
523 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
524 case ICE1712_SUBDEVICE_PHASE88
:
525 case ICE1712_SUBDEVICE_TS88
:
526 case ICE1712_SUBDEVICE_EWS88D
:
528 ice
->spdif
.ops
.open
= ews88_open_spdif
;
529 ice
->spdif
.ops
.setup_rate
= ews88_setup_spdif
;
530 ice
->spdif
.ops
.default_get
= ews88_spdif_default_get
;
531 ice
->spdif
.ops
.default_put
= ews88_spdif_default_put
;
532 ice
->spdif
.ops
.stream_get
= ews88_spdif_stream_get
;
533 ice
->spdif
.ops
.stream_put
= ews88_spdif_stream_put
;
534 /* Set spdif defaults */
535 snd_ice1712_ews_cs8404_spdif_write(ice
, ice
->spdif
.cs8403_bits
);
540 switch (ice
->eeprom
.subvendor
) {
541 case ICE1712_SUBDEVICE_EWS88D
:
546 ak
= ice
->akm
= kzalloc(sizeof(struct snd_akm4xxx
), GFP_KERNEL
);
551 switch (ice
->eeprom
.subvendor
) {
552 case ICE1712_SUBDEVICE_EWS88MT
:
553 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
554 case ICE1712_SUBDEVICE_PHASE88
:
555 case ICE1712_SUBDEVICE_TS88
:
556 err
= snd_ice1712_akm4xxx_init(ak
, &akm_ews88mt
, &akm_ews88mt_priv
, ice
);
558 case ICE1712_SUBDEVICE_EWX2496
:
559 err
= snd_ice1712_akm4xxx_init(ak
, &akm_ewx2496
, &akm_ewx2496_priv
, ice
);
561 case ICE1712_SUBDEVICE_DMX6FIRE
:
562 err
= snd_ice1712_akm4xxx_init(ak
, &akm_6fire
, &akm_6fire_priv
, ice
);
572 * EWX 24/96 specific controls
575 /* i/o sensitivity - this callback is shared among other devices, too */
576 static int snd_ice1712_ewx_io_sense_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
){
578 static const char * const texts
[2] = {
581 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
583 uinfo
->value
.enumerated
.items
= 2;
584 if (uinfo
->value
.enumerated
.item
>= 2)
585 uinfo
->value
.enumerated
.item
= 1;
586 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
590 static int snd_ice1712_ewx_io_sense_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
592 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
593 unsigned char mask
= kcontrol
->private_value
& 0xff;
595 snd_ice1712_save_gpio_status(ice
);
596 ucontrol
->value
.enumerated
.item
[0] = snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
) & mask
? 1 : 0;
597 snd_ice1712_restore_gpio_status(ice
);
601 static int snd_ice1712_ewx_io_sense_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
603 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
604 unsigned char mask
= kcontrol
->private_value
& 0xff;
607 if (kcontrol
->private_value
& (1 << 31))
609 nval
= ucontrol
->value
.enumerated
.item
[0] ? mask
: 0;
610 snd_ice1712_save_gpio_status(ice
);
611 val
= snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
);
613 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, nval
);
614 snd_ice1712_restore_gpio_status(ice
);
618 static struct snd_kcontrol_new snd_ice1712_ewx2496_controls
[] = {
620 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
621 .name
= "Input Sensitivity Switch",
622 .info
= snd_ice1712_ewx_io_sense_info
,
623 .get
= snd_ice1712_ewx_io_sense_get
,
624 .put
= snd_ice1712_ewx_io_sense_put
,
625 .private_value
= ICE1712_EWX2496_AIN_SEL
,
628 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
629 .name
= "Output Sensitivity Switch",
630 .info
= snd_ice1712_ewx_io_sense_info
,
631 .get
= snd_ice1712_ewx_io_sense_get
,
632 .put
= snd_ice1712_ewx_io_sense_put
,
633 .private_value
= ICE1712_EWX2496_AOUT_SEL
,
639 * EWS88MT specific controls
641 /* analog output sensitivity;; address 0x48 bit 6 */
642 static int snd_ice1712_ews88mt_output_sense_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
644 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
645 struct ews_spec
*spec
= ice
->spec
;
648 snd_i2c_lock(ice
->i2c
);
649 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_PCF2
], &data
, 1) != 1) {
650 snd_i2c_unlock(ice
->i2c
);
653 snd_i2c_unlock(ice
->i2c
);
654 ucontrol
->value
.enumerated
.item
[0] = data
& ICE1712_EWS88MT_OUTPUT_SENSE
? 1 : 0; /* high = -10dBV, low = +4dBu */
658 /* analog output sensitivity;; address 0x48 bit 6 */
659 static int snd_ice1712_ews88mt_output_sense_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
661 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
662 struct ews_spec
*spec
= ice
->spec
;
663 unsigned char data
, ndata
;
665 snd_i2c_lock(ice
->i2c
);
666 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_PCF2
], &data
, 1) != 1) {
667 snd_i2c_unlock(ice
->i2c
);
670 ndata
= (data
& ~ICE1712_EWS88MT_OUTPUT_SENSE
) | (ucontrol
->value
.enumerated
.item
[0] ? ICE1712_EWS88MT_OUTPUT_SENSE
: 0);
671 if (ndata
!= data
&& snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_PCF2
],
673 snd_i2c_unlock(ice
->i2c
);
676 snd_i2c_unlock(ice
->i2c
);
677 return ndata
!= data
;
680 /* analog input sensitivity; address 0x46 */
681 static int snd_ice1712_ews88mt_input_sense_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
683 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
684 struct ews_spec
*spec
= ice
->spec
;
685 int channel
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
688 if (snd_BUG_ON(channel
< 0 || channel
> 7))
690 snd_i2c_lock(ice
->i2c
);
691 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_PCF1
], &data
, 1) != 1) {
692 snd_i2c_unlock(ice
->i2c
);
695 /* reversed; high = +4dBu, low = -10dBV */
696 ucontrol
->value
.enumerated
.item
[0] = data
& (1 << channel
) ? 0 : 1;
697 snd_i2c_unlock(ice
->i2c
);
701 /* analog output sensitivity; address 0x46 */
702 static int snd_ice1712_ews88mt_input_sense_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
704 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
705 struct ews_spec
*spec
= ice
->spec
;
706 int channel
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
707 unsigned char data
, ndata
;
709 if (snd_BUG_ON(channel
< 0 || channel
> 7))
711 snd_i2c_lock(ice
->i2c
);
712 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_PCF1
], &data
, 1) != 1) {
713 snd_i2c_unlock(ice
->i2c
);
716 ndata
= (data
& ~(1 << channel
)) | (ucontrol
->value
.enumerated
.item
[0] ? 0 : (1 << channel
));
717 if (ndata
!= data
&& snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_PCF1
],
719 snd_i2c_unlock(ice
->i2c
);
722 snd_i2c_unlock(ice
->i2c
);
723 return ndata
!= data
;
726 static struct snd_kcontrol_new snd_ice1712_ews88mt_input_sense
= {
727 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
728 .name
= "Input Sensitivity Switch",
729 .info
= snd_ice1712_ewx_io_sense_info
,
730 .get
= snd_ice1712_ews88mt_input_sense_get
,
731 .put
= snd_ice1712_ews88mt_input_sense_put
,
735 static struct snd_kcontrol_new snd_ice1712_ews88mt_output_sense
= {
736 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
737 .name
= "Output Sensitivity Switch",
738 .info
= snd_ice1712_ewx_io_sense_info
,
739 .get
= snd_ice1712_ews88mt_output_sense_get
,
740 .put
= snd_ice1712_ews88mt_output_sense_put
,
745 * EWS88D specific controls
748 #define snd_ice1712_ews88d_control_info snd_ctl_boolean_mono_info
750 static int snd_ice1712_ews88d_control_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
752 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
753 struct ews_spec
*spec
= ice
->spec
;
754 int shift
= kcontrol
->private_value
& 0xff;
755 int invert
= (kcontrol
->private_value
>> 8) & 1;
756 unsigned char data
[2];
758 snd_i2c_lock(ice
->i2c
);
759 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_88D
], data
, 2) != 2) {
760 snd_i2c_unlock(ice
->i2c
);
763 snd_i2c_unlock(ice
->i2c
);
764 data
[0] = (data
[shift
>> 3] >> (shift
& 7)) & 0x01;
767 ucontrol
->value
.integer
.value
[0] = data
[0];
771 static int snd_ice1712_ews88d_control_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
773 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
774 struct ews_spec
*spec
= ice
->spec
;
775 int shift
= kcontrol
->private_value
& 0xff;
776 int invert
= (kcontrol
->private_value
>> 8) & 1;
777 unsigned char data
[2], ndata
[2];
780 snd_i2c_lock(ice
->i2c
);
781 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_88D
], data
, 2) != 2) {
782 snd_i2c_unlock(ice
->i2c
);
785 ndata
[shift
>> 3] = data
[shift
>> 3] & ~(1 << (shift
& 7));
787 if (! ucontrol
->value
.integer
.value
[0])
788 ndata
[shift
>> 3] |= (1 << (shift
& 7));
790 if (ucontrol
->value
.integer
.value
[0])
791 ndata
[shift
>> 3] |= (1 << (shift
& 7));
793 change
= (data
[shift
>> 3] != ndata
[shift
>> 3]);
795 snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_88D
], data
, 2) != 2) {
796 snd_i2c_unlock(ice
->i2c
);
799 snd_i2c_unlock(ice
->i2c
);
803 #define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
807 .info = snd_ice1712_ews88d_control_info,\
808 .get = snd_ice1712_ews88d_control_get,\
809 .put = snd_ice1712_ews88d_control_put,\
810 .private_value = xshift | (xinvert << 8),\
813 static struct snd_kcontrol_new snd_ice1712_ews88d_controls
[] = {
814 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "IEC958 Input Optical", 0, 1, 0), /* inverted */
815 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "ADAT Output Optical", 1, 0, 0),
816 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "ADAT External Master Clock", 2, 0, 0),
817 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "Enable ADAT", 3, 0, 0),
818 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "ADAT Through", 4, 1, 0),
823 * DMX 6Fire specific controls
826 static int snd_ice1712_6fire_read_pca(struct snd_ice1712
*ice
, unsigned char reg
)
829 struct ews_spec
*spec
= ice
->spec
;
831 snd_i2c_lock(ice
->i2c
);
833 snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_6FIRE
], &byte
, 1);
835 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_6FIRE
], &byte
, 1) != 1) {
836 snd_i2c_unlock(ice
->i2c
);
837 printk(KERN_ERR
"cannot read pca\n");
840 snd_i2c_unlock(ice
->i2c
);
844 static int snd_ice1712_6fire_write_pca(struct snd_ice1712
*ice
, unsigned char reg
, unsigned char data
)
846 unsigned char bytes
[2];
847 struct ews_spec
*spec
= ice
->spec
;
849 snd_i2c_lock(ice
->i2c
);
852 if (snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_6FIRE
], bytes
, 2) != 2) {
853 snd_i2c_unlock(ice
->i2c
);
856 snd_i2c_unlock(ice
->i2c
);
860 #define snd_ice1712_6fire_control_info snd_ctl_boolean_mono_info
862 static int snd_ice1712_6fire_control_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
864 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
865 int shift
= kcontrol
->private_value
& 0xff;
866 int invert
= (kcontrol
->private_value
>> 8) & 1;
869 if ((data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
)) < 0)
871 data
= (data
>> shift
) & 1;
874 ucontrol
->value
.integer
.value
[0] = data
;
878 static int snd_ice1712_6fire_control_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
880 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
881 int shift
= kcontrol
->private_value
& 0xff;
882 int invert
= (kcontrol
->private_value
>> 8) & 1;
885 if ((data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
)) < 0)
887 ndata
= data
& ~(1 << shift
);
888 if (ucontrol
->value
.integer
.value
[0])
889 ndata
|= (1 << shift
);
891 ndata
^= (1 << shift
);
893 snd_ice1712_6fire_write_pca(ice
, PCF9554_REG_OUTPUT
, (unsigned char)ndata
);
899 static int snd_ice1712_6fire_select_input_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
901 static const char * const texts
[4] = {
902 "Internal", "Front Input", "Rear Input", "Wave Table"
904 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
906 uinfo
->value
.enumerated
.items
= 4;
907 if (uinfo
->value
.enumerated
.item
>= 4)
908 uinfo
->value
.enumerated
.item
= 1;
909 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
913 static int snd_ice1712_6fire_select_input_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
915 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
918 if ((data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
)) < 0)
920 ucontrol
->value
.integer
.value
[0] = data
& 3;
924 static int snd_ice1712_6fire_select_input_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
926 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
929 if ((data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
)) < 0)
932 ndata
|= (ucontrol
->value
.integer
.value
[0] & 3);
934 snd_ice1712_6fire_write_pca(ice
, PCF9554_REG_OUTPUT
, (unsigned char)ndata
);
941 #define DMX6FIRE_CONTROL(xname, xshift, xinvert) \
942 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
944 .info = snd_ice1712_6fire_control_info,\
945 .get = snd_ice1712_6fire_control_get,\
946 .put = snd_ice1712_6fire_control_put,\
947 .private_value = xshift | (xinvert << 8),\
950 static struct snd_kcontrol_new snd_ice1712_6fire_controls
[] = {
952 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
953 .name
= "Analog Input Select",
954 .info
= snd_ice1712_6fire_select_input_info
,
955 .get
= snd_ice1712_6fire_select_input_get
,
956 .put
= snd_ice1712_6fire_select_input_put
,
958 DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 1),
959 // DMX6FIRE_CONTROL("Master Clock Select", 3, 0),
960 DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0),
961 DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0),
962 DMX6FIRE_CONTROL("Breakbox LED", 6, 0),
966 static int snd_ice1712_ews_add_controls(struct snd_ice1712
*ice
)
971 /* all terratec cards have spdif, but cs8427 module builds it's own controls */
972 if (ice
->cs8427
== NULL
) {
973 err
= snd_ice1712_spdif_build_controls(ice
);
978 /* ak4524 controls */
979 switch (ice
->eeprom
.subvendor
) {
980 case ICE1712_SUBDEVICE_EWX2496
:
981 case ICE1712_SUBDEVICE_EWS88MT
:
982 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
983 case ICE1712_SUBDEVICE_PHASE88
:
984 case ICE1712_SUBDEVICE_TS88
:
985 case ICE1712_SUBDEVICE_DMX6FIRE
:
986 err
= snd_ice1712_akm4xxx_build_controls(ice
);
992 /* card specific controls */
993 switch (ice
->eeprom
.subvendor
) {
994 case ICE1712_SUBDEVICE_EWX2496
:
995 for (idx
= 0; idx
< ARRAY_SIZE(snd_ice1712_ewx2496_controls
); idx
++) {
996 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ewx2496_controls
[idx
], ice
));
1001 case ICE1712_SUBDEVICE_EWS88MT
:
1002 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
1003 case ICE1712_SUBDEVICE_PHASE88
:
1004 case ICE1712_SUBDEVICE_TS88
:
1005 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense
, ice
));
1008 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense
, ice
));
1012 case ICE1712_SUBDEVICE_EWS88D
:
1013 for (idx
= 0; idx
< ARRAY_SIZE(snd_ice1712_ews88d_controls
); idx
++) {
1014 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ews88d_controls
[idx
], ice
));
1019 case ICE1712_SUBDEVICE_DMX6FIRE
:
1020 for (idx
= 0; idx
< ARRAY_SIZE(snd_ice1712_6fire_controls
); idx
++) {
1021 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_6fire_controls
[idx
], ice
));
1032 struct snd_ice1712_card_info snd_ice1712_ews_cards
[] = {
1034 .subvendor
= ICE1712_SUBDEVICE_EWX2496
,
1035 .name
= "TerraTec EWX24/96",
1037 .chip_init
= snd_ice1712_ews_init
,
1038 .build_controls
= snd_ice1712_ews_add_controls
,
1041 .subvendor
= ICE1712_SUBDEVICE_EWS88MT
,
1042 .name
= "TerraTec EWS88MT",
1044 .chip_init
= snd_ice1712_ews_init
,
1045 .build_controls
= snd_ice1712_ews_add_controls
,
1048 .subvendor
= ICE1712_SUBDEVICE_EWS88MT_NEW
,
1049 .name
= "TerraTec EWS88MT",
1050 .model
= "ews88mt_new",
1051 .chip_init
= snd_ice1712_ews_init
,
1052 .build_controls
= snd_ice1712_ews_add_controls
,
1055 .subvendor
= ICE1712_SUBDEVICE_PHASE88
,
1056 .name
= "TerraTec Phase88",
1058 .chip_init
= snd_ice1712_ews_init
,
1059 .build_controls
= snd_ice1712_ews_add_controls
,
1062 .subvendor
= ICE1712_SUBDEVICE_TS88
,
1063 .name
= "terrasoniq TS88",
1065 .chip_init
= snd_ice1712_ews_init
,
1066 .build_controls
= snd_ice1712_ews_add_controls
,
1069 .subvendor
= ICE1712_SUBDEVICE_EWS88D
,
1070 .name
= "TerraTec EWS88D",
1072 .chip_init
= snd_ice1712_ews_init
,
1073 .build_controls
= snd_ice1712_ews_add_controls
,
1076 .subvendor
= ICE1712_SUBDEVICE_DMX6FIRE
,
1077 .name
= "TerraTec DMX6Fire",
1078 .model
= "dmx6fire",
1079 .chip_init
= snd_ice1712_ews_init
,
1080 .build_controls
= snd_ice1712_ews_add_controls
,
1081 .mpu401_1_name
= "MIDI-Front DMX6fire",
1082 .mpu401_2_name
= "Wavetable DMX6fire",
1083 .mpu401_2_info_flags
= MPU401_INFO_OUTPUT
,
1085 { } /* terminator */