1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ALSA driver for ICEnsemble ICE1712 (Envy24)
5 * Lowlevel functions for Terratec EWS88MT/D, EWX24/96, DMX 6Fire
7 * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
8 * 2002 Takashi Iwai <tiwai@suse.de>
11 #include <linux/delay.h>
12 #include <linux/interrupt.h>
13 #include <linux/init.h>
14 #include <linux/slab.h>
15 #include <sound/core.h>
16 #include <sound/cs8427.h>
17 #include <sound/asoundef.h>
23 #include <sound/cs8403.h>
26 EWS_I2C_CS8404
= 0, EWS_I2C_PCF1
, EWS_I2C_PCF2
,
32 /* additional i2c devices for EWS boards */
34 struct snd_i2c_device
*i2cdevs
[3];
38 * access via i2c mode (for EWX 24/96, EWS 88MT&D)
41 /* send SDA and SCL */
42 static void ewx_i2c_setlines(struct snd_i2c_bus
*bus
, int clk
, int data
)
44 struct snd_ice1712
*ice
= bus
->private_data
;
45 unsigned char tmp
= 0;
47 tmp
|= ICE1712_EWX2496_SERIAL_CLOCK
;
49 tmp
|= ICE1712_EWX2496_SERIAL_DATA
;
50 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, tmp
);
54 static int ewx_i2c_getclock(struct snd_i2c_bus
*bus
)
56 struct snd_ice1712
*ice
= bus
->private_data
;
57 return snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
) & ICE1712_EWX2496_SERIAL_CLOCK
? 1 : 0;
60 static int ewx_i2c_getdata(struct snd_i2c_bus
*bus
, int ack
)
62 struct snd_ice1712
*ice
= bus
->private_data
;
64 /* set RW pin to low */
65 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, ~ICE1712_EWX2496_RW
);
66 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, 0);
69 bit
= snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
) & ICE1712_EWX2496_SERIAL_DATA
? 1 : 0;
70 /* set RW pin to high */
71 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, ICE1712_EWX2496_RW
);
72 /* reset write mask */
73 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, ~ICE1712_EWX2496_SERIAL_CLOCK
);
77 static void ewx_i2c_start(struct snd_i2c_bus
*bus
)
79 struct snd_ice1712
*ice
= bus
->private_data
;
82 snd_ice1712_save_gpio_status(ice
);
84 mask
= ICE1712_EWX2496_RW
;
85 switch (ice
->eeprom
.subvendor
) {
86 case ICE1712_SUBDEVICE_EWX2496
:
87 mask
|= ICE1712_EWX2496_AK4524_CS
; /* CS high also */
89 case ICE1712_SUBDEVICE_DMX6FIRE
:
90 mask
|= ICE1712_6FIRE_AK4524_CS_MASK
; /* CS high also */
93 snd_ice1712_gpio_write_bits(ice
, mask
, mask
);
96 static void ewx_i2c_stop(struct snd_i2c_bus
*bus
)
98 struct snd_ice1712
*ice
= bus
->private_data
;
99 snd_ice1712_restore_gpio_status(ice
);
102 static void ewx_i2c_direction(struct snd_i2c_bus
*bus
, int clock
, int data
)
104 struct snd_ice1712
*ice
= bus
->private_data
;
105 unsigned char mask
= 0;
108 mask
|= ICE1712_EWX2496_SERIAL_CLOCK
; /* write SCL */
110 mask
|= ICE1712_EWX2496_SERIAL_DATA
; /* write SDA */
111 ice
->gpio
.direction
&= ~(ICE1712_EWX2496_SERIAL_CLOCK
|ICE1712_EWX2496_SERIAL_DATA
);
112 ice
->gpio
.direction
|= mask
;
113 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DIRECTION
, ice
->gpio
.direction
);
114 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, ~mask
);
117 static struct snd_i2c_bit_ops snd_ice1712_ewx_cs8427_bit_ops
= {
118 .start
= ewx_i2c_start
,
119 .stop
= ewx_i2c_stop
,
120 .direction
= ewx_i2c_direction
,
121 .setlines
= ewx_i2c_setlines
,
122 .getclock
= ewx_i2c_getclock
,
123 .getdata
= ewx_i2c_getdata
,
131 /* AK4524 chip select; address 0x48 bit 0-3 */
132 static int snd_ice1712_ews88mt_chip_select(struct snd_ice1712
*ice
, int chip_mask
)
134 struct ews_spec
*spec
= ice
->spec
;
135 unsigned char data
, ndata
;
137 if (snd_BUG_ON(chip_mask
< 0 || chip_mask
> 0x0f))
139 snd_i2c_lock(ice
->i2c
);
140 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_PCF2
], &data
, 1) != 1)
142 ndata
= (data
& 0xf0) | chip_mask
;
144 if (snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_PCF2
], &ndata
, 1)
147 snd_i2c_unlock(ice
->i2c
);
151 snd_i2c_unlock(ice
->i2c
);
152 dev_err(ice
->card
->dev
,
153 "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(struct snd_akm4xxx
*ak
, int chip
)
160 struct snd_ice1712
*ice
= ak
->private_data
[0];
162 /* assert AK4524 CS */
163 if (snd_ice1712_ews88mt_chip_select(ice
, ~(1 << chip
) & 0x0f) < 0)
164 dev_err(ice
->card
->dev
, "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(struct snd_akm4xxx
*ak
, int chip
)
177 struct snd_ice1712
*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(struct snd_akm4xxx
*ak
, int chip
)
186 struct snd_ice1712
*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(struct snd_akm4xxx
*ak
, int chip
)
201 struct snd_ak4xxx_private
*priv
= (void *)ak
->private_value
[0];
202 struct snd_ice1712
*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(struct snd_ice1712
*ice
, unsigned char bits
)
220 struct ews_spec
*spec
= ice
->spec
;
221 unsigned char bytes
[2];
223 snd_i2c_lock(ice
->i2c
);
224 switch (ice
->eeprom
.subvendor
) {
225 case ICE1712_SUBDEVICE_EWS88MT
:
226 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
227 case ICE1712_SUBDEVICE_PHASE88
:
228 case ICE1712_SUBDEVICE_TS88
:
229 if (snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_CS8404
], &bits
, 1)
233 case ICE1712_SUBDEVICE_EWS88D
:
234 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_88D
], bytes
, 2)
237 if (bits
!= bytes
[1]) {
239 if (snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_88D
],
246 snd_i2c_unlock(ice
->i2c
);
252 static void ews88_spdif_default_get(struct snd_ice1712
*ice
, struct snd_ctl_elem_value
*ucontrol
)
254 snd_cs8404_decode_spdif_bits(&ucontrol
->value
.iec958
, ice
->spdif
.cs8403_bits
);
257 static int ews88_spdif_default_put(struct snd_ice1712
*ice
, struct snd_ctl_elem_value
*ucontrol
)
262 val
= snd_cs8404_encode_spdif_bits(&ucontrol
->value
.iec958
);
263 spin_lock_irq(&ice
->reg_lock
);
264 change
= ice
->spdif
.cs8403_bits
!= val
;
265 ice
->spdif
.cs8403_bits
= val
;
266 if (change
&& ice
->playback_pro_substream
== NULL
) {
267 spin_unlock_irq(&ice
->reg_lock
);
268 snd_ice1712_ews_cs8404_spdif_write(ice
, val
);
270 spin_unlock_irq(&ice
->reg_lock
);
275 static void ews88_spdif_stream_get(struct snd_ice1712
*ice
, struct snd_ctl_elem_value
*ucontrol
)
277 snd_cs8404_decode_spdif_bits(&ucontrol
->value
.iec958
, ice
->spdif
.cs8403_stream_bits
);
280 static int ews88_spdif_stream_put(struct snd_ice1712
*ice
, struct snd_ctl_elem_value
*ucontrol
)
285 val
= snd_cs8404_encode_spdif_bits(&ucontrol
->value
.iec958
);
286 spin_lock_irq(&ice
->reg_lock
);
287 change
= ice
->spdif
.cs8403_stream_bits
!= val
;
288 ice
->spdif
.cs8403_stream_bits
= val
;
289 if (change
&& ice
->playback_pro_substream
!= NULL
) {
290 spin_unlock_irq(&ice
->reg_lock
);
291 snd_ice1712_ews_cs8404_spdif_write(ice
, val
);
293 spin_unlock_irq(&ice
->reg_lock
);
300 static void ews88_open_spdif(struct snd_ice1712
*ice
, struct snd_pcm_substream
*substream
)
302 ice
->spdif
.cs8403_stream_bits
= ice
->spdif
.cs8403_bits
;
305 /* set up SPDIF for EWS88MT / EWS88D */
306 static void ews88_setup_spdif(struct snd_ice1712
*ice
, int rate
)
312 spin_lock_irqsave(&ice
->reg_lock
, flags
);
313 tmp
= ice
->spdif
.cs8403_stream_bits
;
314 if (tmp
& 0x10) /* consumer */
315 tmp
&= (tmp
& 0x01) ? ~0x06 : ~0x60;
317 case 32000: tmp
|= (tmp
& 0x01) ? 0x02 : 0x00; break;
318 case 44100: tmp
|= (tmp
& 0x01) ? 0x06 : 0x40; break;
319 case 48000: tmp
|= (tmp
& 0x01) ? 0x04 : 0x20; break;
320 default: tmp
|= (tmp
& 0x01) ? 0x06 : 0x40; break;
322 change
= ice
->spdif
.cs8403_stream_bits
!= tmp
;
323 ice
->spdif
.cs8403_stream_bits
= tmp
;
324 spin_unlock_irqrestore(&ice
->reg_lock
, flags
);
326 snd_ctl_notify(ice
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &ice
->spdif
.stream_ctl
->id
);
327 snd_ice1712_ews_cs8404_spdif_write(ice
, tmp
);
333 static const struct snd_akm4xxx akm_ews88mt
= {
338 .lock
= ews88mt_ak4524_lock
,
339 .unlock
= ews88mt_ak4524_unlock
343 static const struct snd_ak4xxx_private akm_ews88mt_priv
= {
345 .cif
= 1, /* CIF high */
346 .data_mask
= ICE1712_EWS88_SERIAL_DATA
,
347 .clk_mask
= ICE1712_EWS88_SERIAL_CLOCK
,
350 .cs_none
= 0, /* no chip select on gpio */
351 .add_flags
= ICE1712_EWS88_RW
, /* set rw bit high */
355 static const struct snd_akm4xxx akm_ewx2496
= {
360 .lock
= ewx2496_ak4524_lock
364 static const struct snd_ak4xxx_private akm_ewx2496_priv
= {
366 .cif
= 1, /* CIF high */
367 .data_mask
= ICE1712_EWS88_SERIAL_DATA
,
368 .clk_mask
= ICE1712_EWS88_SERIAL_CLOCK
,
369 .cs_mask
= ICE1712_EWX2496_AK4524_CS
,
370 .cs_addr
= ICE1712_EWX2496_AK4524_CS
,
372 .add_flags
= ICE1712_EWS88_RW
, /* set rw bit high */
376 static const struct snd_akm4xxx akm_6fire
= {
381 .lock
= dmx6fire_ak4524_lock
385 static const struct snd_ak4xxx_private akm_6fire_priv
= {
387 .cif
= 1, /* CIF high */
388 .data_mask
= ICE1712_6FIRE_SERIAL_DATA
,
389 .clk_mask
= ICE1712_6FIRE_SERIAL_CLOCK
,
391 .cs_addr
= 0, /* set later */
393 .add_flags
= ICE1712_6FIRE_RW
, /* set rw bit high */
398 * initialize the chip
402 #define PCF9554_REG_INPUT 0
403 #define PCF9554_REG_OUTPUT 1
404 #define PCF9554_REG_POLARITY 2
405 #define PCF9554_REG_CONFIG 3
407 static int snd_ice1712_6fire_write_pca(struct snd_ice1712
*ice
, unsigned char reg
, unsigned char data
);
409 static int snd_ice1712_ews_init(struct snd_ice1712
*ice
)
412 struct snd_akm4xxx
*ak
;
413 struct ews_spec
*spec
;
415 /* set the analog DACs */
416 switch (ice
->eeprom
.subvendor
) {
417 case ICE1712_SUBDEVICE_EWX2496
:
418 ice
->num_total_dacs
= 2;
419 ice
->num_total_adcs
= 2;
421 case ICE1712_SUBDEVICE_EWS88MT
:
422 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
423 case ICE1712_SUBDEVICE_PHASE88
:
424 case ICE1712_SUBDEVICE_TS88
:
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;
439 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
445 if ((err
= snd_i2c_bus_create(ice
->card
, "ICE1712 GPIO 1", NULL
, &ice
->i2c
)) < 0) {
446 dev_err(ice
->card
->dev
, "unable to create I2C bus\n");
449 ice
->i2c
->private_data
= ice
;
450 ice
->i2c
->hw_ops
.bit
= &snd_ice1712_ewx_cs8427_bit_ops
;
452 /* create i2c devices */
453 switch (ice
->eeprom
.subvendor
) {
454 case ICE1712_SUBDEVICE_DMX6FIRE
:
455 err
= snd_i2c_device_create(ice
->i2c
, "PCF9554",
456 ICE1712_6FIRE_PCF9554_ADDR
,
457 &spec
->i2cdevs
[EWS_I2C_6FIRE
]);
459 dev_err(ice
->card
->dev
,
460 "PCF9554 initialization failed\n");
463 snd_ice1712_6fire_write_pca(ice
, PCF9554_REG_CONFIG
, 0x80);
465 case ICE1712_SUBDEVICE_EWS88MT
:
466 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
467 case ICE1712_SUBDEVICE_PHASE88
:
468 case ICE1712_SUBDEVICE_TS88
:
470 err
= snd_i2c_device_create(ice
->i2c
, "CS8404",
471 ICE1712_EWS88MT_CS8404_ADDR
,
472 &spec
->i2cdevs
[EWS_I2C_CS8404
]);
475 err
= snd_i2c_device_create(ice
->i2c
, "PCF8574 (1st)",
476 ICE1712_EWS88MT_INPUT_ADDR
,
477 &spec
->i2cdevs
[EWS_I2C_PCF1
]);
480 err
= snd_i2c_device_create(ice
->i2c
, "PCF8574 (2nd)",
481 ICE1712_EWS88MT_OUTPUT_ADDR
,
482 &spec
->i2cdevs
[EWS_I2C_PCF2
]);
485 /* Check if the front module is connected */
486 if ((err
= snd_ice1712_ews88mt_chip_select(ice
, 0x0f)) < 0)
489 case ICE1712_SUBDEVICE_EWS88D
:
490 err
= snd_i2c_device_create(ice
->i2c
, "PCF8575",
491 ICE1712_EWS88D_PCF_ADDR
,
492 &spec
->i2cdevs
[EWS_I2C_88D
]);
498 /* set up SPDIF interface */
499 switch (ice
->eeprom
.subvendor
) {
500 case ICE1712_SUBDEVICE_EWX2496
:
501 if ((err
= snd_ice1712_init_cs8427(ice
, CS8427_BASE_ADDR
)) < 0)
503 snd_cs8427_reg_write(ice
->cs8427
, CS8427_REG_RECVERRMASK
, CS8427_UNLOCK
| CS8427_CONF
| CS8427_BIP
| CS8427_PAR
);
505 case ICE1712_SUBDEVICE_DMX6FIRE
:
506 if ((err
= snd_ice1712_init_cs8427(ice
, ICE1712_6FIRE_CS8427_ADDR
)) < 0)
508 snd_cs8427_reg_write(ice
->cs8427
, CS8427_REG_RECVERRMASK
, CS8427_UNLOCK
| CS8427_CONF
| CS8427_BIP
| CS8427_PAR
);
510 case ICE1712_SUBDEVICE_EWS88MT
:
511 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
512 case ICE1712_SUBDEVICE_PHASE88
:
513 case ICE1712_SUBDEVICE_TS88
:
514 case ICE1712_SUBDEVICE_EWS88D
:
516 ice
->spdif
.ops
.open
= ews88_open_spdif
;
517 ice
->spdif
.ops
.setup_rate
= ews88_setup_spdif
;
518 ice
->spdif
.ops
.default_get
= ews88_spdif_default_get
;
519 ice
->spdif
.ops
.default_put
= ews88_spdif_default_put
;
520 ice
->spdif
.ops
.stream_get
= ews88_spdif_stream_get
;
521 ice
->spdif
.ops
.stream_put
= ews88_spdif_stream_put
;
522 /* Set spdif defaults */
523 snd_ice1712_ews_cs8404_spdif_write(ice
, ice
->spdif
.cs8403_bits
);
528 switch (ice
->eeprom
.subvendor
) {
529 case ICE1712_SUBDEVICE_EWS88D
:
534 ak
= ice
->akm
= kzalloc(sizeof(struct snd_akm4xxx
), GFP_KERNEL
);
539 switch (ice
->eeprom
.subvendor
) {
540 case ICE1712_SUBDEVICE_EWS88MT
:
541 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
542 case ICE1712_SUBDEVICE_PHASE88
:
543 case ICE1712_SUBDEVICE_TS88
:
544 err
= snd_ice1712_akm4xxx_init(ak
, &akm_ews88mt
, &akm_ews88mt_priv
, ice
);
546 case ICE1712_SUBDEVICE_EWX2496
:
547 err
= snd_ice1712_akm4xxx_init(ak
, &akm_ewx2496
, &akm_ewx2496_priv
, ice
);
549 case ICE1712_SUBDEVICE_DMX6FIRE
:
550 err
= snd_ice1712_akm4xxx_init(ak
, &akm_6fire
, &akm_6fire_priv
, ice
);
560 * EWX 24/96 specific controls
563 /* i/o sensitivity - this callback is shared among other devices, too */
564 static int snd_ice1712_ewx_io_sense_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
){
566 static const char * const texts
[2] = {
569 return snd_ctl_enum_info(uinfo
, 1, 2, texts
);
572 static int snd_ice1712_ewx_io_sense_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
574 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
575 unsigned char mask
= kcontrol
->private_value
& 0xff;
577 snd_ice1712_save_gpio_status(ice
);
578 ucontrol
->value
.enumerated
.item
[0] = snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
) & mask
? 1 : 0;
579 snd_ice1712_restore_gpio_status(ice
);
583 static int snd_ice1712_ewx_io_sense_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
585 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
586 unsigned char mask
= kcontrol
->private_value
& 0xff;
589 if (kcontrol
->private_value
& (1 << 31))
591 nval
= ucontrol
->value
.enumerated
.item
[0] ? mask
: 0;
592 snd_ice1712_save_gpio_status(ice
);
593 val
= snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
);
595 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, nval
);
596 snd_ice1712_restore_gpio_status(ice
);
600 static struct snd_kcontrol_new snd_ice1712_ewx2496_controls
[] = {
602 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
603 .name
= "Input Sensitivity Switch",
604 .info
= snd_ice1712_ewx_io_sense_info
,
605 .get
= snd_ice1712_ewx_io_sense_get
,
606 .put
= snd_ice1712_ewx_io_sense_put
,
607 .private_value
= ICE1712_EWX2496_AIN_SEL
,
610 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
611 .name
= "Output Sensitivity Switch",
612 .info
= snd_ice1712_ewx_io_sense_info
,
613 .get
= snd_ice1712_ewx_io_sense_get
,
614 .put
= snd_ice1712_ewx_io_sense_put
,
615 .private_value
= ICE1712_EWX2496_AOUT_SEL
,
621 * EWS88MT specific controls
623 /* analog output sensitivity;; address 0x48 bit 6 */
624 static int snd_ice1712_ews88mt_output_sense_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
626 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
627 struct ews_spec
*spec
= ice
->spec
;
630 snd_i2c_lock(ice
->i2c
);
631 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_PCF2
], &data
, 1) != 1) {
632 snd_i2c_unlock(ice
->i2c
);
635 snd_i2c_unlock(ice
->i2c
);
636 ucontrol
->value
.enumerated
.item
[0] = data
& ICE1712_EWS88MT_OUTPUT_SENSE
? 1 : 0; /* high = -10dBV, low = +4dBu */
640 /* analog output sensitivity;; address 0x48 bit 6 */
641 static int snd_ice1712_ews88mt_output_sense_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
643 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
644 struct ews_spec
*spec
= ice
->spec
;
645 unsigned char data
, ndata
;
647 snd_i2c_lock(ice
->i2c
);
648 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_PCF2
], &data
, 1) != 1) {
649 snd_i2c_unlock(ice
->i2c
);
652 ndata
= (data
& ~ICE1712_EWS88MT_OUTPUT_SENSE
) | (ucontrol
->value
.enumerated
.item
[0] ? ICE1712_EWS88MT_OUTPUT_SENSE
: 0);
653 if (ndata
!= data
&& snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_PCF2
],
655 snd_i2c_unlock(ice
->i2c
);
658 snd_i2c_unlock(ice
->i2c
);
659 return ndata
!= data
;
662 /* analog input sensitivity; address 0x46 */
663 static int snd_ice1712_ews88mt_input_sense_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
665 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
666 struct ews_spec
*spec
= ice
->spec
;
667 int channel
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
670 if (snd_BUG_ON(channel
< 0 || channel
> 7))
672 snd_i2c_lock(ice
->i2c
);
673 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_PCF1
], &data
, 1) != 1) {
674 snd_i2c_unlock(ice
->i2c
);
677 /* reversed; high = +4dBu, low = -10dBV */
678 ucontrol
->value
.enumerated
.item
[0] = data
& (1 << channel
) ? 0 : 1;
679 snd_i2c_unlock(ice
->i2c
);
683 /* analog output sensitivity; address 0x46 */
684 static int snd_ice1712_ews88mt_input_sense_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
686 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
687 struct ews_spec
*spec
= ice
->spec
;
688 int channel
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
689 unsigned char data
, ndata
;
691 if (snd_BUG_ON(channel
< 0 || channel
> 7))
693 snd_i2c_lock(ice
->i2c
);
694 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_PCF1
], &data
, 1) != 1) {
695 snd_i2c_unlock(ice
->i2c
);
698 ndata
= (data
& ~(1 << channel
)) | (ucontrol
->value
.enumerated
.item
[0] ? 0 : (1 << channel
));
699 if (ndata
!= data
&& snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_PCF1
],
701 snd_i2c_unlock(ice
->i2c
);
704 snd_i2c_unlock(ice
->i2c
);
705 return ndata
!= data
;
708 static const struct snd_kcontrol_new snd_ice1712_ews88mt_input_sense
= {
709 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
710 .name
= "Input Sensitivity Switch",
711 .info
= snd_ice1712_ewx_io_sense_info
,
712 .get
= snd_ice1712_ews88mt_input_sense_get
,
713 .put
= snd_ice1712_ews88mt_input_sense_put
,
717 static const struct snd_kcontrol_new snd_ice1712_ews88mt_output_sense
= {
718 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
719 .name
= "Output Sensitivity Switch",
720 .info
= snd_ice1712_ewx_io_sense_info
,
721 .get
= snd_ice1712_ews88mt_output_sense_get
,
722 .put
= snd_ice1712_ews88mt_output_sense_put
,
727 * EWS88D specific controls
730 #define snd_ice1712_ews88d_control_info snd_ctl_boolean_mono_info
732 static int snd_ice1712_ews88d_control_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
734 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
735 struct ews_spec
*spec
= ice
->spec
;
736 int shift
= kcontrol
->private_value
& 0xff;
737 int invert
= (kcontrol
->private_value
>> 8) & 1;
738 unsigned char data
[2];
740 snd_i2c_lock(ice
->i2c
);
741 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_88D
], data
, 2) != 2) {
742 snd_i2c_unlock(ice
->i2c
);
745 snd_i2c_unlock(ice
->i2c
);
746 data
[0] = (data
[shift
>> 3] >> (shift
& 7)) & 0x01;
749 ucontrol
->value
.integer
.value
[0] = data
[0];
753 static int snd_ice1712_ews88d_control_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
755 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
756 struct ews_spec
*spec
= ice
->spec
;
757 int shift
= kcontrol
->private_value
& 0xff;
758 int invert
= (kcontrol
->private_value
>> 8) & 1;
759 unsigned char data
[2], ndata
[2];
762 snd_i2c_lock(ice
->i2c
);
763 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_88D
], data
, 2) != 2) {
764 snd_i2c_unlock(ice
->i2c
);
767 ndata
[shift
>> 3] = data
[shift
>> 3] & ~(1 << (shift
& 7));
769 if (! ucontrol
->value
.integer
.value
[0])
770 ndata
[shift
>> 3] |= (1 << (shift
& 7));
772 if (ucontrol
->value
.integer
.value
[0])
773 ndata
[shift
>> 3] |= (1 << (shift
& 7));
775 change
= (data
[shift
>> 3] != ndata
[shift
>> 3]);
777 snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_88D
], data
, 2) != 2) {
778 snd_i2c_unlock(ice
->i2c
);
781 snd_i2c_unlock(ice
->i2c
);
785 #define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
789 .info = snd_ice1712_ews88d_control_info,\
790 .get = snd_ice1712_ews88d_control_get,\
791 .put = snd_ice1712_ews88d_control_put,\
792 .private_value = xshift | (xinvert << 8),\
795 static struct snd_kcontrol_new snd_ice1712_ews88d_controls
[] = {
796 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "IEC958 Input Optical", 0, 1, 0), /* inverted */
797 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "ADAT Output Optical", 1, 0, 0),
798 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "ADAT External Master Clock", 2, 0, 0),
799 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "Enable ADAT", 3, 0, 0),
800 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "ADAT Through", 4, 1, 0),
805 * DMX 6Fire specific controls
808 static int snd_ice1712_6fire_read_pca(struct snd_ice1712
*ice
, unsigned char reg
)
811 struct ews_spec
*spec
= ice
->spec
;
813 snd_i2c_lock(ice
->i2c
);
815 if (snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_6FIRE
], &byte
, 1) != 1) {
816 snd_i2c_unlock(ice
->i2c
);
817 dev_err(ice
->card
->dev
, "cannot send pca\n");
822 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_6FIRE
], &byte
, 1) != 1) {
823 snd_i2c_unlock(ice
->i2c
);
824 dev_err(ice
->card
->dev
, "cannot read pca\n");
827 snd_i2c_unlock(ice
->i2c
);
831 static int snd_ice1712_6fire_write_pca(struct snd_ice1712
*ice
, unsigned char reg
, unsigned char data
)
833 unsigned char bytes
[2];
834 struct ews_spec
*spec
= ice
->spec
;
836 snd_i2c_lock(ice
->i2c
);
839 if (snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_6FIRE
], bytes
, 2) != 2) {
840 snd_i2c_unlock(ice
->i2c
);
843 snd_i2c_unlock(ice
->i2c
);
847 #define snd_ice1712_6fire_control_info snd_ctl_boolean_mono_info
849 static int snd_ice1712_6fire_control_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
851 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
852 int shift
= kcontrol
->private_value
& 0xff;
853 int invert
= (kcontrol
->private_value
>> 8) & 1;
856 if ((data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
)) < 0)
858 data
= (data
>> shift
) & 1;
861 ucontrol
->value
.integer
.value
[0] = data
;
865 static int snd_ice1712_6fire_control_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
867 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
868 int shift
= kcontrol
->private_value
& 0xff;
869 int invert
= (kcontrol
->private_value
>> 8) & 1;
872 if ((data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
)) < 0)
874 ndata
= data
& ~(1 << shift
);
875 if (ucontrol
->value
.integer
.value
[0])
876 ndata
|= (1 << shift
);
878 ndata
^= (1 << shift
);
880 snd_ice1712_6fire_write_pca(ice
, PCF9554_REG_OUTPUT
, (unsigned char)ndata
);
886 static int snd_ice1712_6fire_select_input_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
888 static const char * const texts
[4] = {
889 "Internal", "Front Input", "Rear Input", "Wave Table"
891 return snd_ctl_enum_info(uinfo
, 1, 4, texts
);
894 static int snd_ice1712_6fire_select_input_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
896 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
899 if ((data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
)) < 0)
901 ucontrol
->value
.integer
.value
[0] = data
& 3;
905 static int snd_ice1712_6fire_select_input_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
907 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
910 if ((data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
)) < 0)
913 ndata
|= (ucontrol
->value
.integer
.value
[0] & 3);
915 snd_ice1712_6fire_write_pca(ice
, PCF9554_REG_OUTPUT
, (unsigned char)ndata
);
922 #define DMX6FIRE_CONTROL(xname, xshift, xinvert) \
923 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
925 .info = snd_ice1712_6fire_control_info,\
926 .get = snd_ice1712_6fire_control_get,\
927 .put = snd_ice1712_6fire_control_put,\
928 .private_value = xshift | (xinvert << 8),\
931 static struct snd_kcontrol_new snd_ice1712_6fire_controls
[] = {
933 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
934 .name
= "Analog Input Select",
935 .info
= snd_ice1712_6fire_select_input_info
,
936 .get
= snd_ice1712_6fire_select_input_get
,
937 .put
= snd_ice1712_6fire_select_input_put
,
939 DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 1),
940 // DMX6FIRE_CONTROL("Master Clock Select", 3, 0),
941 DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0),
942 DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0),
943 DMX6FIRE_CONTROL("Breakbox LED", 6, 0),
947 static int snd_ice1712_ews_add_controls(struct snd_ice1712
*ice
)
952 /* all terratec cards have spdif, but cs8427 module builds it's own controls */
953 if (ice
->cs8427
== NULL
) {
954 err
= snd_ice1712_spdif_build_controls(ice
);
959 /* ak4524 controls */
960 switch (ice
->eeprom
.subvendor
) {
961 case ICE1712_SUBDEVICE_EWX2496
:
962 case ICE1712_SUBDEVICE_EWS88MT
:
963 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
964 case ICE1712_SUBDEVICE_PHASE88
:
965 case ICE1712_SUBDEVICE_TS88
:
966 case ICE1712_SUBDEVICE_DMX6FIRE
:
967 err
= snd_ice1712_akm4xxx_build_controls(ice
);
973 /* card specific controls */
974 switch (ice
->eeprom
.subvendor
) {
975 case ICE1712_SUBDEVICE_EWX2496
:
976 for (idx
= 0; idx
< ARRAY_SIZE(snd_ice1712_ewx2496_controls
); idx
++) {
977 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ewx2496_controls
[idx
], ice
));
982 case ICE1712_SUBDEVICE_EWS88MT
:
983 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
984 case ICE1712_SUBDEVICE_PHASE88
:
985 case ICE1712_SUBDEVICE_TS88
:
986 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense
, ice
));
989 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense
, ice
));
993 case ICE1712_SUBDEVICE_EWS88D
:
994 for (idx
= 0; idx
< ARRAY_SIZE(snd_ice1712_ews88d_controls
); idx
++) {
995 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ews88d_controls
[idx
], ice
));
1000 case ICE1712_SUBDEVICE_DMX6FIRE
:
1001 for (idx
= 0; idx
< ARRAY_SIZE(snd_ice1712_6fire_controls
); idx
++) {
1002 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_6fire_controls
[idx
], ice
));
1013 struct snd_ice1712_card_info snd_ice1712_ews_cards
[] = {
1015 .subvendor
= ICE1712_SUBDEVICE_EWX2496
,
1016 .name
= "TerraTec EWX24/96",
1018 .chip_init
= snd_ice1712_ews_init
,
1019 .build_controls
= snd_ice1712_ews_add_controls
,
1022 .subvendor
= ICE1712_SUBDEVICE_EWS88MT
,
1023 .name
= "TerraTec EWS88MT",
1025 .chip_init
= snd_ice1712_ews_init
,
1026 .build_controls
= snd_ice1712_ews_add_controls
,
1029 .subvendor
= ICE1712_SUBDEVICE_EWS88MT_NEW
,
1030 .name
= "TerraTec EWS88MT",
1031 .model
= "ews88mt_new",
1032 .chip_init
= snd_ice1712_ews_init
,
1033 .build_controls
= snd_ice1712_ews_add_controls
,
1036 .subvendor
= ICE1712_SUBDEVICE_PHASE88
,
1037 .name
= "TerraTec Phase88",
1039 .chip_init
= snd_ice1712_ews_init
,
1040 .build_controls
= snd_ice1712_ews_add_controls
,
1043 .subvendor
= ICE1712_SUBDEVICE_TS88
,
1044 .name
= "terrasoniq TS88",
1046 .chip_init
= snd_ice1712_ews_init
,
1047 .build_controls
= snd_ice1712_ews_add_controls
,
1050 .subvendor
= ICE1712_SUBDEVICE_EWS88D
,
1051 .name
= "TerraTec EWS88D",
1053 .chip_init
= snd_ice1712_ews_init
,
1054 .build_controls
= snd_ice1712_ews_add_controls
,
1057 .subvendor
= ICE1712_SUBDEVICE_DMX6FIRE
,
1058 .name
= "TerraTec DMX6Fire",
1059 .model
= "dmx6fire",
1060 .chip_init
= snd_ice1712_ews_init
,
1061 .build_controls
= snd_ice1712_ews_add_controls
,
1062 .mpu401_1_name
= "MIDI-Front DMX6fire",
1063 .mpu401_2_name
= "Wavetable DMX6fire",
1064 .mpu401_2_info_flags
= MPU401_INFO_OUTPUT
,
1066 { } /* terminator */