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 EWS_I2C_CS8404
= 0, EWS_I2C_PCF1
, EWS_I2C_PCF2
,
49 * access via i2c mode (for EWX 24/96, EWS 88MT&D)
52 /* send SDA and SCL */
53 static void ewx_i2c_setlines(struct snd_i2c_bus
*bus
, int clk
, int data
)
55 struct snd_ice1712
*ice
= bus
->private_data
;
56 unsigned char tmp
= 0;
58 tmp
|= ICE1712_EWX2496_SERIAL_CLOCK
;
60 tmp
|= ICE1712_EWX2496_SERIAL_DATA
;
61 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, tmp
);
65 static int ewx_i2c_getclock(struct snd_i2c_bus
*bus
)
67 struct snd_ice1712
*ice
= bus
->private_data
;
68 return snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
) & ICE1712_EWX2496_SERIAL_CLOCK
? 1 : 0;
71 static int ewx_i2c_getdata(struct snd_i2c_bus
*bus
, int ack
)
73 struct snd_ice1712
*ice
= bus
->private_data
;
75 /* set RW pin to low */
76 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, ~ICE1712_EWX2496_RW
);
77 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, 0);
80 bit
= snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
) & ICE1712_EWX2496_SERIAL_DATA
? 1 : 0;
81 /* set RW pin to high */
82 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, ICE1712_EWX2496_RW
);
83 /* reset write mask */
84 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, ~ICE1712_EWX2496_SERIAL_CLOCK
);
88 static void ewx_i2c_start(struct snd_i2c_bus
*bus
)
90 struct snd_ice1712
*ice
= bus
->private_data
;
93 snd_ice1712_save_gpio_status(ice
);
95 mask
= ICE1712_EWX2496_RW
;
96 switch (ice
->eeprom
.subvendor
) {
97 case ICE1712_SUBDEVICE_EWX2496
:
98 mask
|= ICE1712_EWX2496_AK4524_CS
; /* CS high also */
100 case ICE1712_SUBDEVICE_DMX6FIRE
:
101 mask
|= ICE1712_6FIRE_AK4524_CS_MASK
; /* CS high also */
104 snd_ice1712_gpio_write_bits(ice
, mask
, mask
);
107 static void ewx_i2c_stop(struct snd_i2c_bus
*bus
)
109 struct snd_ice1712
*ice
= bus
->private_data
;
110 snd_ice1712_restore_gpio_status(ice
);
113 static void ewx_i2c_direction(struct snd_i2c_bus
*bus
, int clock
, int data
)
115 struct snd_ice1712
*ice
= bus
->private_data
;
116 unsigned char mask
= 0;
119 mask
|= ICE1712_EWX2496_SERIAL_CLOCK
; /* write SCL */
121 mask
|= ICE1712_EWX2496_SERIAL_DATA
; /* write SDA */
122 ice
->gpio
.direction
&= ~(ICE1712_EWX2496_SERIAL_CLOCK
|ICE1712_EWX2496_SERIAL_DATA
);
123 ice
->gpio
.direction
|= mask
;
124 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DIRECTION
, ice
->gpio
.direction
);
125 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, ~mask
);
128 static struct snd_i2c_bit_ops snd_ice1712_ewx_cs8427_bit_ops
= {
129 .start
= ewx_i2c_start
,
130 .stop
= ewx_i2c_stop
,
131 .direction
= ewx_i2c_direction
,
132 .setlines
= ewx_i2c_setlines
,
133 .getclock
= ewx_i2c_getclock
,
134 .getdata
= ewx_i2c_getdata
,
142 /* AK4524 chip select; address 0x48 bit 0-3 */
143 static int snd_ice1712_ews88mt_chip_select(struct snd_ice1712
*ice
, int chip_mask
)
145 unsigned char data
, ndata
;
147 snd_assert(chip_mask
>= 0 && chip_mask
<= 0x0f, return -EINVAL
);
148 snd_i2c_lock(ice
->i2c
);
149 if (snd_i2c_readbytes(ice
->spec
.i2cdevs
[EWS_I2C_PCF2
], &data
, 1) != 1)
151 ndata
= (data
& 0xf0) | chip_mask
;
153 if (snd_i2c_sendbytes(ice
->spec
.i2cdevs
[EWS_I2C_PCF2
], &ndata
, 1) != 1)
155 snd_i2c_unlock(ice
->i2c
);
159 snd_i2c_unlock(ice
->i2c
);
160 snd_printk(KERN_ERR
"AK4524 chip select failed, check cable to the front module\n");
164 /* start callback for EWS88MT, needs to select a certain chip mask */
165 static void ews88mt_ak4524_lock(struct snd_akm4xxx
*ak
, int chip
)
167 struct snd_ice1712
*ice
= ak
->private_data
[0];
169 /* assert AK4524 CS */
170 if (snd_ice1712_ews88mt_chip_select(ice
, ~(1 << chip
) & 0x0f) < 0)
171 snd_printk(KERN_ERR
"fatal error (ews88mt chip select)\n");
172 snd_ice1712_save_gpio_status(ice
);
173 tmp
= ICE1712_EWS88_SERIAL_DATA
|
174 ICE1712_EWS88_SERIAL_CLOCK
|
176 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DIRECTION
,
177 ice
->gpio
.direction
| tmp
);
178 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, ~tmp
);
181 /* stop callback for EWS88MT, needs to deselect chip mask */
182 static void ews88mt_ak4524_unlock(struct snd_akm4xxx
*ak
, int chip
)
184 struct snd_ice1712
*ice
= ak
->private_data
[0];
185 snd_ice1712_restore_gpio_status(ice
);
187 snd_ice1712_ews88mt_chip_select(ice
, 0x0f);
190 /* start callback for EWX24/96 */
191 static void ewx2496_ak4524_lock(struct snd_akm4xxx
*ak
, int chip
)
193 struct snd_ice1712
*ice
= ak
->private_data
[0];
195 snd_ice1712_save_gpio_status(ice
);
196 tmp
= ICE1712_EWX2496_SERIAL_DATA
|
197 ICE1712_EWX2496_SERIAL_CLOCK
|
198 ICE1712_EWX2496_AK4524_CS
|
200 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DIRECTION
,
201 ice
->gpio
.direction
| tmp
);
202 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, ~tmp
);
205 /* start callback for DMX 6fire */
206 static void dmx6fire_ak4524_lock(struct snd_akm4xxx
*ak
, int chip
)
208 struct snd_ak4xxx_private
*priv
= (void *)ak
->private_value
[0];
209 struct snd_ice1712
*ice
= ak
->private_data
[0];
211 snd_ice1712_save_gpio_status(ice
);
212 tmp
= priv
->cs_mask
= priv
->cs_addr
= (1 << chip
) & ICE1712_6FIRE_AK4524_CS_MASK
;
213 tmp
|= ICE1712_6FIRE_SERIAL_DATA
|
214 ICE1712_6FIRE_SERIAL_CLOCK
|
216 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DIRECTION
,
217 ice
->gpio
.direction
| tmp
);
218 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, ~tmp
);
222 * CS8404 interface on EWS88MT/D
225 static void snd_ice1712_ews_cs8404_spdif_write(struct snd_ice1712
*ice
, unsigned char bits
)
227 unsigned char bytes
[2];
229 snd_i2c_lock(ice
->i2c
);
230 switch (ice
->eeprom
.subvendor
) {
231 case ICE1712_SUBDEVICE_EWS88MT
:
232 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
233 case ICE1712_SUBDEVICE_PHASE88
:
234 if (snd_i2c_sendbytes(ice
->spec
.i2cdevs
[EWS_I2C_CS8404
], &bits
, 1) != 1)
237 case ICE1712_SUBDEVICE_EWS88D
:
238 if (snd_i2c_readbytes(ice
->spec
.i2cdevs
[EWS_I2C_88D
], bytes
, 2) != 2)
240 if (bits
!= bytes
[1]) {
242 if (snd_i2c_sendbytes(ice
->spec
.i2cdevs
[EWS_I2C_88D
], bytes
, 2) != 2)
248 snd_i2c_unlock(ice
->i2c
);
254 static void ews88_spdif_default_get(struct snd_ice1712
*ice
, struct snd_ctl_elem_value
*ucontrol
)
256 snd_cs8404_decode_spdif_bits(&ucontrol
->value
.iec958
, ice
->spdif
.cs8403_bits
);
259 static int ews88_spdif_default_put(struct snd_ice1712
*ice
, struct snd_ctl_elem_value
*ucontrol
)
264 val
= snd_cs8404_encode_spdif_bits(&ucontrol
->value
.iec958
);
265 spin_lock_irq(&ice
->reg_lock
);
266 change
= ice
->spdif
.cs8403_bits
!= val
;
267 ice
->spdif
.cs8403_bits
= val
;
268 if (change
&& ice
->playback_pro_substream
== NULL
) {
269 spin_unlock_irq(&ice
->reg_lock
);
270 snd_ice1712_ews_cs8404_spdif_write(ice
, val
);
272 spin_unlock_irq(&ice
->reg_lock
);
277 static void ews88_spdif_stream_get(struct snd_ice1712
*ice
, struct snd_ctl_elem_value
*ucontrol
)
279 snd_cs8404_decode_spdif_bits(&ucontrol
->value
.iec958
, ice
->spdif
.cs8403_stream_bits
);
282 static int ews88_spdif_stream_put(struct snd_ice1712
*ice
, struct snd_ctl_elem_value
*ucontrol
)
287 val
= snd_cs8404_encode_spdif_bits(&ucontrol
->value
.iec958
);
288 spin_lock_irq(&ice
->reg_lock
);
289 change
= ice
->spdif
.cs8403_stream_bits
!= val
;
290 ice
->spdif
.cs8403_stream_bits
= val
;
291 if (change
&& ice
->playback_pro_substream
!= NULL
) {
292 spin_unlock_irq(&ice
->reg_lock
);
293 snd_ice1712_ews_cs8404_spdif_write(ice
, val
);
295 spin_unlock_irq(&ice
->reg_lock
);
302 static void ews88_open_spdif(struct snd_ice1712
*ice
, struct snd_pcm_substream
*substream
)
304 ice
->spdif
.cs8403_stream_bits
= ice
->spdif
.cs8403_bits
;
307 /* set up SPDIF for EWS88MT / EWS88D */
308 static void ews88_setup_spdif(struct snd_ice1712
*ice
, int rate
)
314 spin_lock_irqsave(&ice
->reg_lock
, flags
);
315 tmp
= ice
->spdif
.cs8403_stream_bits
;
316 if (tmp
& 0x10) /* consumer */
317 tmp
&= (tmp
& 0x01) ? ~0x06 : ~0x60;
319 case 32000: tmp
|= (tmp
& 0x01) ? 0x02 : 0x00; break;
320 case 44100: tmp
|= (tmp
& 0x01) ? 0x06 : 0x40; break;
321 case 48000: tmp
|= (tmp
& 0x01) ? 0x04 : 0x20; break;
322 default: tmp
|= (tmp
& 0x01) ? 0x06 : 0x40; break;
324 change
= ice
->spdif
.cs8403_stream_bits
!= tmp
;
325 ice
->spdif
.cs8403_stream_bits
= tmp
;
326 spin_unlock_irqrestore(&ice
->reg_lock
, flags
);
328 snd_ctl_notify(ice
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &ice
->spdif
.stream_ctl
->id
);
329 snd_ice1712_ews_cs8404_spdif_write(ice
, tmp
);
335 static struct snd_akm4xxx akm_ews88mt __devinitdata
= {
340 .lock
= ews88mt_ak4524_lock
,
341 .unlock
= ews88mt_ak4524_unlock
345 static struct snd_ak4xxx_private akm_ews88mt_priv __devinitdata
= {
347 .cif
= 1, /* CIF high */
348 .data_mask
= ICE1712_EWS88_SERIAL_DATA
,
349 .clk_mask
= ICE1712_EWS88_SERIAL_CLOCK
,
352 .cs_none
= 0, /* no chip select on gpio */
353 .add_flags
= ICE1712_EWS88_RW
, /* set rw bit high */
357 static struct snd_akm4xxx akm_ewx2496 __devinitdata
= {
362 .lock
= ewx2496_ak4524_lock
366 static struct snd_ak4xxx_private akm_ewx2496_priv __devinitdata
= {
368 .cif
= 1, /* CIF high */
369 .data_mask
= ICE1712_EWS88_SERIAL_DATA
,
370 .clk_mask
= ICE1712_EWS88_SERIAL_CLOCK
,
371 .cs_mask
= ICE1712_EWX2496_AK4524_CS
,
372 .cs_addr
= ICE1712_EWX2496_AK4524_CS
,
374 .add_flags
= ICE1712_EWS88_RW
, /* set rw bit high */
378 static struct snd_akm4xxx akm_6fire __devinitdata
= {
383 .lock
= dmx6fire_ak4524_lock
387 static struct snd_ak4xxx_private akm_6fire_priv __devinitdata
= {
389 .cif
= 1, /* CIF high */
390 .data_mask
= ICE1712_6FIRE_SERIAL_DATA
,
391 .clk_mask
= ICE1712_6FIRE_SERIAL_CLOCK
,
393 .cs_addr
= 0, /* set later */
395 .add_flags
= ICE1712_6FIRE_RW
, /* set rw bit high */
400 * initialize the chip
404 #define PCF9554_REG_INPUT 0
405 #define PCF9554_REG_OUTPUT 1
406 #define PCF9554_REG_POLARITY 2
407 #define PCF9554_REG_CONFIG 3
409 static int snd_ice1712_6fire_write_pca(struct snd_ice1712
*ice
, unsigned char reg
, unsigned char data
);
411 static int __devinit
snd_ice1712_ews_init(struct snd_ice1712
*ice
)
414 struct snd_akm4xxx
*ak
;
416 /* set the analog DACs */
417 switch (ice
->eeprom
.subvendor
) {
418 case ICE1712_SUBDEVICE_EWX2496
:
419 ice
->num_total_dacs
= 2;
420 ice
->num_total_adcs
= 2;
422 case ICE1712_SUBDEVICE_EWS88MT
:
423 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
424 case ICE1712_SUBDEVICE_PHASE88
:
425 ice
->num_total_dacs
= 8;
426 ice
->num_total_adcs
= 8;
428 case ICE1712_SUBDEVICE_EWS88D
:
429 /* Note: not analog but ADAT I/O */
430 ice
->num_total_dacs
= 8;
431 ice
->num_total_adcs
= 8;
433 case ICE1712_SUBDEVICE_DMX6FIRE
:
434 ice
->num_total_dacs
= 6;
435 ice
->num_total_adcs
= 6;
440 if ((err
= snd_i2c_bus_create(ice
->card
, "ICE1712 GPIO 1", NULL
, &ice
->i2c
)) < 0) {
441 snd_printk(KERN_ERR
"unable to create I2C bus\n");
444 ice
->i2c
->private_data
= ice
;
445 ice
->i2c
->hw_ops
.bit
= &snd_ice1712_ewx_cs8427_bit_ops
;
447 /* create i2c devices */
448 switch (ice
->eeprom
.subvendor
) {
449 case ICE1712_SUBDEVICE_DMX6FIRE
:
450 if ((err
= snd_i2c_device_create(ice
->i2c
, "PCF9554", ICE1712_6FIRE_PCF9554_ADDR
, &ice
->spec
.i2cdevs
[EWS_I2C_6FIRE
])) < 0) {
451 snd_printk(KERN_ERR
"PCF9554 initialization failed\n");
454 snd_ice1712_6fire_write_pca(ice
, PCF9554_REG_CONFIG
, 0x80);
456 case ICE1712_SUBDEVICE_EWS88MT
:
457 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
458 case ICE1712_SUBDEVICE_PHASE88
:
459 if ((err
= snd_i2c_device_create(ice
->i2c
, "CS8404", ICE1712_EWS88MT_CS8404_ADDR
, &ice
->spec
.i2cdevs
[EWS_I2C_CS8404
])) < 0)
461 if ((err
= snd_i2c_device_create(ice
->i2c
, "PCF8574 (1st)", ICE1712_EWS88MT_INPUT_ADDR
, &ice
->spec
.i2cdevs
[EWS_I2C_PCF1
])) < 0)
463 if ((err
= snd_i2c_device_create(ice
->i2c
, "PCF8574 (2nd)", ICE1712_EWS88MT_OUTPUT_ADDR
, &ice
->spec
.i2cdevs
[EWS_I2C_PCF2
])) < 0)
465 /* Check if the front module is connected */
466 if ((err
= snd_ice1712_ews88mt_chip_select(ice
, 0x0f)) < 0)
469 case ICE1712_SUBDEVICE_EWS88D
:
470 if ((err
= snd_i2c_device_create(ice
->i2c
, "PCF8575", ICE1712_EWS88D_PCF_ADDR
, &ice
->spec
.i2cdevs
[EWS_I2C_88D
])) < 0)
475 /* set up SPDIF interface */
476 switch (ice
->eeprom
.subvendor
) {
477 case ICE1712_SUBDEVICE_EWX2496
:
478 if ((err
= snd_ice1712_init_cs8427(ice
, CS8427_BASE_ADDR
)) < 0)
480 snd_cs8427_reg_write(ice
->cs8427
, CS8427_REG_RECVERRMASK
, CS8427_UNLOCK
| CS8427_CONF
| CS8427_BIP
| CS8427_PAR
);
482 case ICE1712_SUBDEVICE_DMX6FIRE
:
483 if ((err
= snd_ice1712_init_cs8427(ice
, ICE1712_6FIRE_CS8427_ADDR
)) < 0)
485 snd_cs8427_reg_write(ice
->cs8427
, CS8427_REG_RECVERRMASK
, CS8427_UNLOCK
| CS8427_CONF
| CS8427_BIP
| CS8427_PAR
);
487 case ICE1712_SUBDEVICE_EWS88MT
:
488 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
489 case ICE1712_SUBDEVICE_PHASE88
:
490 case ICE1712_SUBDEVICE_EWS88D
:
492 ice
->spdif
.ops
.open
= ews88_open_spdif
;
493 ice
->spdif
.ops
.setup_rate
= ews88_setup_spdif
;
494 ice
->spdif
.ops
.default_get
= ews88_spdif_default_get
;
495 ice
->spdif
.ops
.default_put
= ews88_spdif_default_put
;
496 ice
->spdif
.ops
.stream_get
= ews88_spdif_stream_get
;
497 ice
->spdif
.ops
.stream_put
= ews88_spdif_stream_put
;
498 /* Set spdif defaults */
499 snd_ice1712_ews_cs8404_spdif_write(ice
, ice
->spdif
.cs8403_bits
);
504 switch (ice
->eeprom
.subvendor
) {
505 case ICE1712_SUBDEVICE_EWS88D
:
510 ak
= ice
->akm
= kmalloc(sizeof(struct snd_akm4xxx
), GFP_KERNEL
);
515 switch (ice
->eeprom
.subvendor
) {
516 case ICE1712_SUBDEVICE_EWS88MT
:
517 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
518 case ICE1712_SUBDEVICE_PHASE88
:
519 err
= snd_ice1712_akm4xxx_init(ak
, &akm_ews88mt
, &akm_ews88mt_priv
, ice
);
521 case ICE1712_SUBDEVICE_EWX2496
:
522 err
= snd_ice1712_akm4xxx_init(ak
, &akm_ewx2496
, &akm_ewx2496_priv
, ice
);
524 case ICE1712_SUBDEVICE_DMX6FIRE
:
525 err
= snd_ice1712_akm4xxx_init(ak
, &akm_6fire
, &akm_6fire_priv
, ice
);
535 * EWX 24/96 specific controls
538 /* i/o sensitivity - this callback is shared among other devices, too */
539 static int snd_ice1712_ewx_io_sense_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
){
541 static char *texts
[2] = {
544 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
546 uinfo
->value
.enumerated
.items
= 2;
547 if (uinfo
->value
.enumerated
.item
>= 2)
548 uinfo
->value
.enumerated
.item
= 1;
549 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
553 static int snd_ice1712_ewx_io_sense_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
555 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
556 unsigned char mask
= kcontrol
->private_value
& 0xff;
558 snd_ice1712_save_gpio_status(ice
);
559 ucontrol
->value
.enumerated
.item
[0] = snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
) & mask
? 1 : 0;
560 snd_ice1712_restore_gpio_status(ice
);
564 static int snd_ice1712_ewx_io_sense_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
566 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
567 unsigned char mask
= kcontrol
->private_value
& 0xff;
570 if (kcontrol
->private_value
& (1 << 31))
572 nval
= ucontrol
->value
.enumerated
.item
[0] ? mask
: 0;
573 snd_ice1712_save_gpio_status(ice
);
574 val
= snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
);
576 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, nval
);
577 snd_ice1712_restore_gpio_status(ice
);
581 static struct snd_kcontrol_new snd_ice1712_ewx2496_controls
[] __devinitdata
= {
583 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
584 .name
= "Input Sensitivity Switch",
585 .info
= snd_ice1712_ewx_io_sense_info
,
586 .get
= snd_ice1712_ewx_io_sense_get
,
587 .put
= snd_ice1712_ewx_io_sense_put
,
588 .private_value
= ICE1712_EWX2496_AIN_SEL
,
591 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
592 .name
= "Output Sensitivity Switch",
593 .info
= snd_ice1712_ewx_io_sense_info
,
594 .get
= snd_ice1712_ewx_io_sense_get
,
595 .put
= snd_ice1712_ewx_io_sense_put
,
596 .private_value
= ICE1712_EWX2496_AOUT_SEL
,
602 * EWS88MT specific controls
604 /* analog output sensitivity;; address 0x48 bit 6 */
605 static int snd_ice1712_ews88mt_output_sense_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
607 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
610 snd_i2c_lock(ice
->i2c
);
611 if (snd_i2c_readbytes(ice
->spec
.i2cdevs
[EWS_I2C_PCF2
], &data
, 1) != 1) {
612 snd_i2c_unlock(ice
->i2c
);
615 snd_i2c_unlock(ice
->i2c
);
616 ucontrol
->value
.enumerated
.item
[0] = data
& ICE1712_EWS88MT_OUTPUT_SENSE
? 1 : 0; /* high = -10dBV, low = +4dBu */
620 /* analog output sensitivity;; address 0x48 bit 6 */
621 static int snd_ice1712_ews88mt_output_sense_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
623 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
624 unsigned char data
, ndata
;
626 snd_i2c_lock(ice
->i2c
);
627 if (snd_i2c_readbytes(ice
->spec
.i2cdevs
[EWS_I2C_PCF2
], &data
, 1) != 1) {
628 snd_i2c_unlock(ice
->i2c
);
631 ndata
= (data
& ~ICE1712_EWS88MT_OUTPUT_SENSE
) | (ucontrol
->value
.enumerated
.item
[0] ? ICE1712_EWS88MT_OUTPUT_SENSE
: 0);
632 if (ndata
!= data
&& snd_i2c_sendbytes(ice
->spec
.i2cdevs
[EWS_I2C_PCF2
], &ndata
, 1) != 1) {
633 snd_i2c_unlock(ice
->i2c
);
636 snd_i2c_unlock(ice
->i2c
);
637 return ndata
!= data
;
640 /* analog input sensitivity; address 0x46 */
641 static int snd_ice1712_ews88mt_input_sense_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
643 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
644 int channel
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
647 snd_assert(channel
>= 0 && channel
<= 7, return 0);
648 snd_i2c_lock(ice
->i2c
);
649 if (snd_i2c_readbytes(ice
->spec
.i2cdevs
[EWS_I2C_PCF1
], &data
, 1) != 1) {
650 snd_i2c_unlock(ice
->i2c
);
653 /* reversed; high = +4dBu, low = -10dBV */
654 ucontrol
->value
.enumerated
.item
[0] = data
& (1 << channel
) ? 0 : 1;
655 snd_i2c_unlock(ice
->i2c
);
659 /* analog output sensitivity; address 0x46 */
660 static int snd_ice1712_ews88mt_input_sense_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
662 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
663 int channel
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
664 unsigned char data
, ndata
;
666 snd_assert(channel
>= 0 && channel
<= 7, return 0);
667 snd_i2c_lock(ice
->i2c
);
668 if (snd_i2c_readbytes(ice
->spec
.i2cdevs
[EWS_I2C_PCF1
], &data
, 1) != 1) {
669 snd_i2c_unlock(ice
->i2c
);
672 ndata
= (data
& ~(1 << channel
)) | (ucontrol
->value
.enumerated
.item
[0] ? 0 : (1 << channel
));
673 if (ndata
!= data
&& snd_i2c_sendbytes(ice
->spec
.i2cdevs
[EWS_I2C_PCF1
], &ndata
, 1) != 1) {
674 snd_i2c_unlock(ice
->i2c
);
677 snd_i2c_unlock(ice
->i2c
);
678 return ndata
!= data
;
681 static struct snd_kcontrol_new snd_ice1712_ews88mt_input_sense __devinitdata
= {
682 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
683 .name
= "Input Sensitivity Switch",
684 .info
= snd_ice1712_ewx_io_sense_info
,
685 .get
= snd_ice1712_ews88mt_input_sense_get
,
686 .put
= snd_ice1712_ews88mt_input_sense_put
,
690 static struct snd_kcontrol_new snd_ice1712_ews88mt_output_sense __devinitdata
= {
691 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
692 .name
= "Output Sensitivity Switch",
693 .info
= snd_ice1712_ewx_io_sense_info
,
694 .get
= snd_ice1712_ews88mt_output_sense_get
,
695 .put
= snd_ice1712_ews88mt_output_sense_put
,
700 * EWS88D specific controls
703 static int snd_ice1712_ews88d_control_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
705 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
707 uinfo
->value
.integer
.min
= 0;
708 uinfo
->value
.integer
.max
= 1;
712 static int snd_ice1712_ews88d_control_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
714 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
715 int shift
= kcontrol
->private_value
& 0xff;
716 int invert
= (kcontrol
->private_value
>> 8) & 1;
717 unsigned char data
[2];
719 snd_i2c_lock(ice
->i2c
);
720 if (snd_i2c_readbytes(ice
->spec
.i2cdevs
[EWS_I2C_88D
], data
, 2) != 2) {
721 snd_i2c_unlock(ice
->i2c
);
724 snd_i2c_unlock(ice
->i2c
);
725 data
[0] = (data
[shift
>> 3] >> (shift
& 7)) & 0x01;
728 ucontrol
->value
.integer
.value
[0] = data
[0];
732 static int snd_ice1712_ews88d_control_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
734 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
735 int shift
= kcontrol
->private_value
& 0xff;
736 int invert
= (kcontrol
->private_value
>> 8) & 1;
737 unsigned char data
[2], ndata
[2];
740 snd_i2c_lock(ice
->i2c
);
741 if (snd_i2c_readbytes(ice
->spec
.i2cdevs
[EWS_I2C_88D
], data
, 2) != 2) {
742 snd_i2c_unlock(ice
->i2c
);
745 ndata
[shift
>> 3] = data
[shift
>> 3] & ~(1 << (shift
& 7));
747 if (! ucontrol
->value
.integer
.value
[0])
748 ndata
[shift
>> 3] |= (1 << (shift
& 7));
750 if (ucontrol
->value
.integer
.value
[0])
751 ndata
[shift
>> 3] |= (1 << (shift
& 7));
753 change
= (data
[shift
>> 3] != ndata
[shift
>> 3]);
754 if (change
&& snd_i2c_sendbytes(ice
->spec
.i2cdevs
[EWS_I2C_88D
], data
, 2) != 2) {
755 snd_i2c_unlock(ice
->i2c
);
758 snd_i2c_unlock(ice
->i2c
);
762 #define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
766 .info = snd_ice1712_ews88d_control_info,\
767 .get = snd_ice1712_ews88d_control_get,\
768 .put = snd_ice1712_ews88d_control_put,\
769 .private_value = xshift | (xinvert << 8),\
772 static struct snd_kcontrol_new snd_ice1712_ews88d_controls
[] __devinitdata
= {
773 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "IEC958 Input Optical", 0, 1, 0), /* inverted */
774 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "ADAT Output Optical", 1, 0, 0),
775 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "ADAT External Master Clock", 2, 0, 0),
776 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "Enable ADAT", 3, 0, 0),
777 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "ADAT Through", 4, 1, 0),
782 * DMX 6Fire specific controls
785 static int snd_ice1712_6fire_read_pca(struct snd_ice1712
*ice
, unsigned char reg
)
788 snd_i2c_lock(ice
->i2c
);
790 snd_i2c_sendbytes(ice
->spec
.i2cdevs
[EWS_I2C_6FIRE
], &byte
, 1);
792 if (snd_i2c_readbytes(ice
->spec
.i2cdevs
[EWS_I2C_6FIRE
], &byte
, 1) != 1) {
793 snd_i2c_unlock(ice
->i2c
);
794 printk(KERN_ERR
"cannot read pca\n");
797 snd_i2c_unlock(ice
->i2c
);
801 static int snd_ice1712_6fire_write_pca(struct snd_ice1712
*ice
, unsigned char reg
, unsigned char data
)
803 unsigned char bytes
[2];
804 snd_i2c_lock(ice
->i2c
);
807 if (snd_i2c_sendbytes(ice
->spec
.i2cdevs
[EWS_I2C_6FIRE
], bytes
, 2) != 2) {
808 snd_i2c_unlock(ice
->i2c
);
811 snd_i2c_unlock(ice
->i2c
);
815 static int snd_ice1712_6fire_control_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
817 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
819 uinfo
->value
.integer
.min
= 0;
820 uinfo
->value
.integer
.max
= 1;
824 static int snd_ice1712_6fire_control_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
826 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
827 int shift
= kcontrol
->private_value
& 0xff;
828 int invert
= (kcontrol
->private_value
>> 8) & 1;
831 if ((data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
)) < 0)
833 data
= (data
>> shift
) & 1;
836 ucontrol
->value
.integer
.value
[0] = data
;
840 static int snd_ice1712_6fire_control_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
842 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
843 int shift
= kcontrol
->private_value
& 0xff;
844 int invert
= (kcontrol
->private_value
>> 8) & 1;
847 if ((data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
)) < 0)
849 ndata
= data
& ~(1 << shift
);
850 if (ucontrol
->value
.integer
.value
[0])
851 ndata
|= (1 << shift
);
853 ndata
^= (1 << shift
);
855 snd_ice1712_6fire_write_pca(ice
, PCF9554_REG_OUTPUT
, (unsigned char)ndata
);
861 static int snd_ice1712_6fire_select_input_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
863 static char *texts
[4] = {
864 "Internal", "Front Input", "Rear Input", "Wave Table"
866 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
868 uinfo
->value
.enumerated
.items
= 4;
869 if (uinfo
->value
.enumerated
.item
>= 4)
870 uinfo
->value
.enumerated
.item
= 1;
871 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
875 static int snd_ice1712_6fire_select_input_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
877 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
880 if ((data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
)) < 0)
882 ucontrol
->value
.integer
.value
[0] = data
& 3;
886 static int snd_ice1712_6fire_select_input_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
888 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
891 if ((data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
)) < 0)
894 ndata
|= (ucontrol
->value
.integer
.value
[0] & 3);
896 snd_ice1712_6fire_write_pca(ice
, PCF9554_REG_OUTPUT
, (unsigned char)ndata
);
903 #define DMX6FIRE_CONTROL(xname, xshift, xinvert) \
904 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
906 .info = snd_ice1712_6fire_control_info,\
907 .get = snd_ice1712_6fire_control_get,\
908 .put = snd_ice1712_6fire_control_put,\
909 .private_value = xshift | (xinvert << 8),\
912 static struct snd_kcontrol_new snd_ice1712_6fire_controls
[] __devinitdata
= {
914 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
915 .name
= "Analog Input Select",
916 .info
= snd_ice1712_6fire_select_input_info
,
917 .get
= snd_ice1712_6fire_select_input_get
,
918 .put
= snd_ice1712_6fire_select_input_put
,
920 DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 1),
921 // DMX6FIRE_CONTROL("Master Clock Select", 3, 0),
922 DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0),
923 DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0),
924 DMX6FIRE_CONTROL("Breakbox LED", 6, 0),
928 static int __devinit
snd_ice1712_ews_add_controls(struct snd_ice1712
*ice
)
933 /* all terratec cards have spdif, but cs8427 module builds it's own controls */
934 if (ice
->cs8427
== NULL
) {
935 err
= snd_ice1712_spdif_build_controls(ice
);
940 /* ak4524 controls */
941 switch (ice
->eeprom
.subvendor
) {
942 case ICE1712_SUBDEVICE_EWX2496
:
943 case ICE1712_SUBDEVICE_EWS88MT
:
944 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
945 case ICE1712_SUBDEVICE_PHASE88
:
946 case ICE1712_SUBDEVICE_DMX6FIRE
:
947 err
= snd_ice1712_akm4xxx_build_controls(ice
);
953 /* card specific controls */
954 switch (ice
->eeprom
.subvendor
) {
955 case ICE1712_SUBDEVICE_EWX2496
:
956 for (idx
= 0; idx
< ARRAY_SIZE(snd_ice1712_ewx2496_controls
); idx
++) {
957 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ewx2496_controls
[idx
], ice
));
962 case ICE1712_SUBDEVICE_EWS88MT
:
963 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
964 case ICE1712_SUBDEVICE_PHASE88
:
965 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense
, ice
));
968 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense
, ice
));
972 case ICE1712_SUBDEVICE_EWS88D
:
973 for (idx
= 0; idx
< ARRAY_SIZE(snd_ice1712_ews88d_controls
); idx
++) {
974 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ews88d_controls
[idx
], ice
));
979 case ICE1712_SUBDEVICE_DMX6FIRE
:
980 for (idx
= 0; idx
< ARRAY_SIZE(snd_ice1712_6fire_controls
); idx
++) {
981 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_6fire_controls
[idx
], ice
));
992 struct snd_ice1712_card_info snd_ice1712_ews_cards
[] __devinitdata
= {
994 .subvendor
= ICE1712_SUBDEVICE_EWX2496
,
995 .name
= "TerraTec EWX24/96",
997 .chip_init
= snd_ice1712_ews_init
,
998 .build_controls
= snd_ice1712_ews_add_controls
,
1001 .subvendor
= ICE1712_SUBDEVICE_EWS88MT
,
1002 .name
= "TerraTec EWS88MT",
1004 .chip_init
= snd_ice1712_ews_init
,
1005 .build_controls
= snd_ice1712_ews_add_controls
,
1008 .subvendor
= ICE1712_SUBDEVICE_EWS88MT_NEW
,
1009 .name
= "TerraTec EWS88MT",
1010 .model
= "ews88mt_new",
1011 .chip_init
= snd_ice1712_ews_init
,
1012 .build_controls
= snd_ice1712_ews_add_controls
,
1015 .subvendor
= ICE1712_SUBDEVICE_PHASE88
,
1016 .name
= "TerraTec Phase88",
1018 .chip_init
= snd_ice1712_ews_init
,
1019 .build_controls
= snd_ice1712_ews_add_controls
,
1022 .subvendor
= ICE1712_SUBDEVICE_EWS88D
,
1023 .name
= "TerraTec EWS88D",
1025 .chip_init
= snd_ice1712_ews_init
,
1026 .build_controls
= snd_ice1712_ews_add_controls
,
1029 .subvendor
= ICE1712_SUBDEVICE_DMX6FIRE
,
1030 .name
= "TerraTec DMX6Fire",
1031 .model
= "dmx6fire",
1032 .chip_init
= snd_ice1712_ews_init
,
1033 .build_controls
= snd_ice1712_ews_add_controls
,
1034 .mpu401_1_name
= "MIDI-Front DMX6fire",
1035 .mpu401_2_name
= "Wavetable DMX6fire",
1036 .mpu401_2_info_flags
= MPU401_INFO_OUTPUT
,
1038 { } /* terminator */