2 * ALSA driver for ICEnsemble ICE1712 (Envy24)
4 * Lowlevel functions for Terratec EWS88MT/D, EWX24/96, DMX 6Fire
6 * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
7 * 2002 Takashi Iwai <tiwai@suse.de>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/delay.h>
27 #include <linux/interrupt.h>
28 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <sound/core.h>
31 #include <sound/cs8427.h>
32 #include <sound/asoundef.h>
38 #include <sound/cs8403.h>
41 EWS_I2C_CS8404
= 0, EWS_I2C_PCF1
, EWS_I2C_PCF2
,
47 /* additional i2c devices for EWS boards */
49 struct snd_i2c_device
*i2cdevs
[3];
53 * access via i2c mode (for EWX 24/96, EWS 88MT&D)
56 /* send SDA and SCL */
57 static void ewx_i2c_setlines(struct snd_i2c_bus
*bus
, int clk
, int data
)
59 struct snd_ice1712
*ice
= bus
->private_data
;
60 unsigned char tmp
= 0;
62 tmp
|= ICE1712_EWX2496_SERIAL_CLOCK
;
64 tmp
|= ICE1712_EWX2496_SERIAL_DATA
;
65 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, tmp
);
69 static int ewx_i2c_getclock(struct snd_i2c_bus
*bus
)
71 struct snd_ice1712
*ice
= bus
->private_data
;
72 return snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
) & ICE1712_EWX2496_SERIAL_CLOCK
? 1 : 0;
75 static int ewx_i2c_getdata(struct snd_i2c_bus
*bus
, int ack
)
77 struct snd_ice1712
*ice
= bus
->private_data
;
79 /* set RW pin to low */
80 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, ~ICE1712_EWX2496_RW
);
81 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, 0);
84 bit
= snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
) & ICE1712_EWX2496_SERIAL_DATA
? 1 : 0;
85 /* set RW pin to high */
86 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, ICE1712_EWX2496_RW
);
87 /* reset write mask */
88 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, ~ICE1712_EWX2496_SERIAL_CLOCK
);
92 static void ewx_i2c_start(struct snd_i2c_bus
*bus
)
94 struct snd_ice1712
*ice
= bus
->private_data
;
97 snd_ice1712_save_gpio_status(ice
);
99 mask
= ICE1712_EWX2496_RW
;
100 switch (ice
->eeprom
.subvendor
) {
101 case ICE1712_SUBDEVICE_EWX2496
:
102 mask
|= ICE1712_EWX2496_AK4524_CS
; /* CS high also */
104 case ICE1712_SUBDEVICE_DMX6FIRE
:
105 mask
|= ICE1712_6FIRE_AK4524_CS_MASK
; /* CS high also */
108 snd_ice1712_gpio_write_bits(ice
, mask
, mask
);
111 static void ewx_i2c_stop(struct snd_i2c_bus
*bus
)
113 struct snd_ice1712
*ice
= bus
->private_data
;
114 snd_ice1712_restore_gpio_status(ice
);
117 static void ewx_i2c_direction(struct snd_i2c_bus
*bus
, int clock
, int data
)
119 struct snd_ice1712
*ice
= bus
->private_data
;
120 unsigned char mask
= 0;
123 mask
|= ICE1712_EWX2496_SERIAL_CLOCK
; /* write SCL */
125 mask
|= ICE1712_EWX2496_SERIAL_DATA
; /* write SDA */
126 ice
->gpio
.direction
&= ~(ICE1712_EWX2496_SERIAL_CLOCK
|ICE1712_EWX2496_SERIAL_DATA
);
127 ice
->gpio
.direction
|= mask
;
128 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DIRECTION
, ice
->gpio
.direction
);
129 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, ~mask
);
132 static struct snd_i2c_bit_ops snd_ice1712_ewx_cs8427_bit_ops
= {
133 .start
= ewx_i2c_start
,
134 .stop
= ewx_i2c_stop
,
135 .direction
= ewx_i2c_direction
,
136 .setlines
= ewx_i2c_setlines
,
137 .getclock
= ewx_i2c_getclock
,
138 .getdata
= ewx_i2c_getdata
,
146 /* AK4524 chip select; address 0x48 bit 0-3 */
147 static int snd_ice1712_ews88mt_chip_select(struct snd_ice1712
*ice
, int chip_mask
)
149 struct ews_spec
*spec
= ice
->spec
;
150 unsigned char data
, ndata
;
152 snd_assert(chip_mask
>= 0 && chip_mask
<= 0x0f, return -EINVAL
);
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 __devinitdata
= {
351 .lock
= ews88mt_ak4524_lock
,
352 .unlock
= ews88mt_ak4524_unlock
356 static struct snd_ak4xxx_private akm_ews88mt_priv __devinitdata
= {
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 __devinitdata
= {
373 .lock
= ewx2496_ak4524_lock
377 static struct snd_ak4xxx_private akm_ewx2496_priv __devinitdata
= {
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 __devinitdata
= {
394 .lock
= dmx6fire_ak4524_lock
398 static struct snd_ak4xxx_private akm_6fire_priv __devinitdata
= {
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 __devinit
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 char *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
[] __devinitdata
= {
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 snd_assert(channel
>= 0 && channel
<= 7, return 0);
689 snd_i2c_lock(ice
->i2c
);
690 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_PCF1
], &data
, 1) != 1) {
691 snd_i2c_unlock(ice
->i2c
);
694 /* reversed; high = +4dBu, low = -10dBV */
695 ucontrol
->value
.enumerated
.item
[0] = data
& (1 << channel
) ? 0 : 1;
696 snd_i2c_unlock(ice
->i2c
);
700 /* analog output sensitivity; address 0x46 */
701 static int snd_ice1712_ews88mt_input_sense_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
703 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
704 struct ews_spec
*spec
= ice
->spec
;
705 int channel
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
706 unsigned char data
, ndata
;
708 snd_assert(channel
>= 0 && channel
<= 7, return 0);
709 snd_i2c_lock(ice
->i2c
);
710 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_PCF1
], &data
, 1) != 1) {
711 snd_i2c_unlock(ice
->i2c
);
714 ndata
= (data
& ~(1 << channel
)) | (ucontrol
->value
.enumerated
.item
[0] ? 0 : (1 << channel
));
715 if (ndata
!= data
&& snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_PCF1
],
717 snd_i2c_unlock(ice
->i2c
);
720 snd_i2c_unlock(ice
->i2c
);
721 return ndata
!= data
;
724 static struct snd_kcontrol_new snd_ice1712_ews88mt_input_sense __devinitdata
= {
725 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
726 .name
= "Input Sensitivity Switch",
727 .info
= snd_ice1712_ewx_io_sense_info
,
728 .get
= snd_ice1712_ews88mt_input_sense_get
,
729 .put
= snd_ice1712_ews88mt_input_sense_put
,
733 static struct snd_kcontrol_new snd_ice1712_ews88mt_output_sense __devinitdata
= {
734 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
735 .name
= "Output Sensitivity Switch",
736 .info
= snd_ice1712_ewx_io_sense_info
,
737 .get
= snd_ice1712_ews88mt_output_sense_get
,
738 .put
= snd_ice1712_ews88mt_output_sense_put
,
743 * EWS88D specific controls
746 #define snd_ice1712_ews88d_control_info snd_ctl_boolean_mono_info
748 static int snd_ice1712_ews88d_control_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
750 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
751 struct ews_spec
*spec
= ice
->spec
;
752 int shift
= kcontrol
->private_value
& 0xff;
753 int invert
= (kcontrol
->private_value
>> 8) & 1;
754 unsigned char data
[2];
756 snd_i2c_lock(ice
->i2c
);
757 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_88D
], data
, 2) != 2) {
758 snd_i2c_unlock(ice
->i2c
);
761 snd_i2c_unlock(ice
->i2c
);
762 data
[0] = (data
[shift
>> 3] >> (shift
& 7)) & 0x01;
765 ucontrol
->value
.integer
.value
[0] = data
[0];
769 static int snd_ice1712_ews88d_control_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
771 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
772 struct ews_spec
*spec
= ice
->spec
;
773 int shift
= kcontrol
->private_value
& 0xff;
774 int invert
= (kcontrol
->private_value
>> 8) & 1;
775 unsigned char data
[2], ndata
[2];
778 snd_i2c_lock(ice
->i2c
);
779 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_88D
], data
, 2) != 2) {
780 snd_i2c_unlock(ice
->i2c
);
783 ndata
[shift
>> 3] = data
[shift
>> 3] & ~(1 << (shift
& 7));
785 if (! ucontrol
->value
.integer
.value
[0])
786 ndata
[shift
>> 3] |= (1 << (shift
& 7));
788 if (ucontrol
->value
.integer
.value
[0])
789 ndata
[shift
>> 3] |= (1 << (shift
& 7));
791 change
= (data
[shift
>> 3] != ndata
[shift
>> 3]);
793 snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_88D
], data
, 2) != 2) {
794 snd_i2c_unlock(ice
->i2c
);
797 snd_i2c_unlock(ice
->i2c
);
801 #define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
805 .info = snd_ice1712_ews88d_control_info,\
806 .get = snd_ice1712_ews88d_control_get,\
807 .put = snd_ice1712_ews88d_control_put,\
808 .private_value = xshift | (xinvert << 8),\
811 static struct snd_kcontrol_new snd_ice1712_ews88d_controls
[] __devinitdata
= {
812 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "IEC958 Input Optical", 0, 1, 0), /* inverted */
813 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "ADAT Output Optical", 1, 0, 0),
814 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "ADAT External Master Clock", 2, 0, 0),
815 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "Enable ADAT", 3, 0, 0),
816 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "ADAT Through", 4, 1, 0),
821 * DMX 6Fire specific controls
824 static int snd_ice1712_6fire_read_pca(struct snd_ice1712
*ice
, unsigned char reg
)
827 struct ews_spec
*spec
= ice
->spec
;
829 snd_i2c_lock(ice
->i2c
);
831 snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_6FIRE
], &byte
, 1);
833 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_6FIRE
], &byte
, 1) != 1) {
834 snd_i2c_unlock(ice
->i2c
);
835 printk(KERN_ERR
"cannot read pca\n");
838 snd_i2c_unlock(ice
->i2c
);
842 static int snd_ice1712_6fire_write_pca(struct snd_ice1712
*ice
, unsigned char reg
, unsigned char data
)
844 unsigned char bytes
[2];
845 struct ews_spec
*spec
= ice
->spec
;
847 snd_i2c_lock(ice
->i2c
);
850 if (snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_6FIRE
], bytes
, 2) != 2) {
851 snd_i2c_unlock(ice
->i2c
);
854 snd_i2c_unlock(ice
->i2c
);
858 #define snd_ice1712_6fire_control_info snd_ctl_boolean_mono_info
860 static int snd_ice1712_6fire_control_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
862 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
863 int shift
= kcontrol
->private_value
& 0xff;
864 int invert
= (kcontrol
->private_value
>> 8) & 1;
867 if ((data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
)) < 0)
869 data
= (data
>> shift
) & 1;
872 ucontrol
->value
.integer
.value
[0] = data
;
876 static int snd_ice1712_6fire_control_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
878 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
879 int shift
= kcontrol
->private_value
& 0xff;
880 int invert
= (kcontrol
->private_value
>> 8) & 1;
883 if ((data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
)) < 0)
885 ndata
= data
& ~(1 << shift
);
886 if (ucontrol
->value
.integer
.value
[0])
887 ndata
|= (1 << shift
);
889 ndata
^= (1 << shift
);
891 snd_ice1712_6fire_write_pca(ice
, PCF9554_REG_OUTPUT
, (unsigned char)ndata
);
897 static int snd_ice1712_6fire_select_input_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
899 static char *texts
[4] = {
900 "Internal", "Front Input", "Rear Input", "Wave Table"
902 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
904 uinfo
->value
.enumerated
.items
= 4;
905 if (uinfo
->value
.enumerated
.item
>= 4)
906 uinfo
->value
.enumerated
.item
= 1;
907 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
911 static int snd_ice1712_6fire_select_input_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
913 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
916 if ((data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
)) < 0)
918 ucontrol
->value
.integer
.value
[0] = data
& 3;
922 static int snd_ice1712_6fire_select_input_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
924 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
927 if ((data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
)) < 0)
930 ndata
|= (ucontrol
->value
.integer
.value
[0] & 3);
932 snd_ice1712_6fire_write_pca(ice
, PCF9554_REG_OUTPUT
, (unsigned char)ndata
);
939 #define DMX6FIRE_CONTROL(xname, xshift, xinvert) \
940 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
942 .info = snd_ice1712_6fire_control_info,\
943 .get = snd_ice1712_6fire_control_get,\
944 .put = snd_ice1712_6fire_control_put,\
945 .private_value = xshift | (xinvert << 8),\
948 static struct snd_kcontrol_new snd_ice1712_6fire_controls
[] __devinitdata
= {
950 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
951 .name
= "Analog Input Select",
952 .info
= snd_ice1712_6fire_select_input_info
,
953 .get
= snd_ice1712_6fire_select_input_get
,
954 .put
= snd_ice1712_6fire_select_input_put
,
956 DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 1),
957 // DMX6FIRE_CONTROL("Master Clock Select", 3, 0),
958 DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0),
959 DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0),
960 DMX6FIRE_CONTROL("Breakbox LED", 6, 0),
964 static int __devinit
snd_ice1712_ews_add_controls(struct snd_ice1712
*ice
)
969 /* all terratec cards have spdif, but cs8427 module builds it's own controls */
970 if (ice
->cs8427
== NULL
) {
971 err
= snd_ice1712_spdif_build_controls(ice
);
976 /* ak4524 controls */
977 switch (ice
->eeprom
.subvendor
) {
978 case ICE1712_SUBDEVICE_EWX2496
:
979 case ICE1712_SUBDEVICE_EWS88MT
:
980 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
981 case ICE1712_SUBDEVICE_PHASE88
:
982 case ICE1712_SUBDEVICE_TS88
:
983 case ICE1712_SUBDEVICE_DMX6FIRE
:
984 err
= snd_ice1712_akm4xxx_build_controls(ice
);
990 /* card specific controls */
991 switch (ice
->eeprom
.subvendor
) {
992 case ICE1712_SUBDEVICE_EWX2496
:
993 for (idx
= 0; idx
< ARRAY_SIZE(snd_ice1712_ewx2496_controls
); idx
++) {
994 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ewx2496_controls
[idx
], ice
));
999 case ICE1712_SUBDEVICE_EWS88MT
:
1000 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
1001 case ICE1712_SUBDEVICE_PHASE88
:
1002 case ICE1712_SUBDEVICE_TS88
:
1003 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense
, ice
));
1006 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense
, ice
));
1010 case ICE1712_SUBDEVICE_EWS88D
:
1011 for (idx
= 0; idx
< ARRAY_SIZE(snd_ice1712_ews88d_controls
); idx
++) {
1012 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ews88d_controls
[idx
], ice
));
1017 case ICE1712_SUBDEVICE_DMX6FIRE
:
1018 for (idx
= 0; idx
< ARRAY_SIZE(snd_ice1712_6fire_controls
); idx
++) {
1019 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_6fire_controls
[idx
], ice
));
1030 struct snd_ice1712_card_info snd_ice1712_ews_cards
[] __devinitdata
= {
1032 .subvendor
= ICE1712_SUBDEVICE_EWX2496
,
1033 .name
= "TerraTec EWX24/96",
1035 .chip_init
= snd_ice1712_ews_init
,
1036 .build_controls
= snd_ice1712_ews_add_controls
,
1039 .subvendor
= ICE1712_SUBDEVICE_EWS88MT
,
1040 .name
= "TerraTec EWS88MT",
1042 .chip_init
= snd_ice1712_ews_init
,
1043 .build_controls
= snd_ice1712_ews_add_controls
,
1046 .subvendor
= ICE1712_SUBDEVICE_EWS88MT_NEW
,
1047 .name
= "TerraTec EWS88MT",
1048 .model
= "ews88mt_new",
1049 .chip_init
= snd_ice1712_ews_init
,
1050 .build_controls
= snd_ice1712_ews_add_controls
,
1053 .subvendor
= ICE1712_SUBDEVICE_PHASE88
,
1054 .name
= "TerraTec Phase88",
1056 .chip_init
= snd_ice1712_ews_init
,
1057 .build_controls
= snd_ice1712_ews_add_controls
,
1060 .subvendor
= ICE1712_SUBDEVICE_TS88
,
1061 .name
= "terrasoniq TS88",
1063 .chip_init
= snd_ice1712_ews_init
,
1064 .build_controls
= snd_ice1712_ews_add_controls
,
1067 .subvendor
= ICE1712_SUBDEVICE_EWS88D
,
1068 .name
= "TerraTec EWS88D",
1070 .chip_init
= snd_ice1712_ews_init
,
1071 .build_controls
= snd_ice1712_ews_add_controls
,
1074 .subvendor
= ICE1712_SUBDEVICE_DMX6FIRE
,
1075 .name
= "TerraTec DMX6Fire",
1076 .model
= "dmx6fire",
1077 .chip_init
= snd_ice1712_ews_init
,
1078 .build_controls
= snd_ice1712_ews_add_controls
,
1079 .mpu401_1_name
= "MIDI-Front DMX6fire",
1080 .mpu401_2_name
= "Wavetable DMX6fire",
1081 .mpu401_2_info_flags
= MPU401_INFO_OUTPUT
,
1083 { } /* terminator */