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 err
= snd_i2c_bus_create(ice
->card
, "ICE1712 GPIO 1", NULL
, &ice
->i2c
);
447 dev_err(ice
->card
->dev
, "unable to create I2C bus\n");
450 ice
->i2c
->private_data
= ice
;
451 ice
->i2c
->hw_ops
.bit
= &snd_ice1712_ewx_cs8427_bit_ops
;
453 /* create i2c devices */
454 switch (ice
->eeprom
.subvendor
) {
455 case ICE1712_SUBDEVICE_DMX6FIRE
:
456 err
= snd_i2c_device_create(ice
->i2c
, "PCF9554",
457 ICE1712_6FIRE_PCF9554_ADDR
,
458 &spec
->i2cdevs
[EWS_I2C_6FIRE
]);
460 dev_err(ice
->card
->dev
,
461 "PCF9554 initialization failed\n");
464 snd_ice1712_6fire_write_pca(ice
, PCF9554_REG_CONFIG
, 0x80);
466 case ICE1712_SUBDEVICE_EWS88MT
:
467 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
468 case ICE1712_SUBDEVICE_PHASE88
:
469 case ICE1712_SUBDEVICE_TS88
:
471 err
= snd_i2c_device_create(ice
->i2c
, "CS8404",
472 ICE1712_EWS88MT_CS8404_ADDR
,
473 &spec
->i2cdevs
[EWS_I2C_CS8404
]);
476 err
= snd_i2c_device_create(ice
->i2c
, "PCF8574 (1st)",
477 ICE1712_EWS88MT_INPUT_ADDR
,
478 &spec
->i2cdevs
[EWS_I2C_PCF1
]);
481 err
= snd_i2c_device_create(ice
->i2c
, "PCF8574 (2nd)",
482 ICE1712_EWS88MT_OUTPUT_ADDR
,
483 &spec
->i2cdevs
[EWS_I2C_PCF2
]);
486 /* Check if the front module is connected */
487 err
= snd_ice1712_ews88mt_chip_select(ice
, 0x0f);
491 case ICE1712_SUBDEVICE_EWS88D
:
492 err
= snd_i2c_device_create(ice
->i2c
, "PCF8575",
493 ICE1712_EWS88D_PCF_ADDR
,
494 &spec
->i2cdevs
[EWS_I2C_88D
]);
500 /* set up SPDIF interface */
501 switch (ice
->eeprom
.subvendor
) {
502 case ICE1712_SUBDEVICE_EWX2496
:
503 err
= snd_ice1712_init_cs8427(ice
, CS8427_BASE_ADDR
);
506 snd_cs8427_reg_write(ice
->cs8427
, CS8427_REG_RECVERRMASK
, CS8427_UNLOCK
| CS8427_CONF
| CS8427_BIP
| CS8427_PAR
);
508 case ICE1712_SUBDEVICE_DMX6FIRE
:
509 err
= snd_ice1712_init_cs8427(ice
, ICE1712_6FIRE_CS8427_ADDR
);
512 snd_cs8427_reg_write(ice
->cs8427
, CS8427_REG_RECVERRMASK
, CS8427_UNLOCK
| CS8427_CONF
| CS8427_BIP
| CS8427_PAR
);
514 case ICE1712_SUBDEVICE_EWS88MT
:
515 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
516 case ICE1712_SUBDEVICE_PHASE88
:
517 case ICE1712_SUBDEVICE_TS88
:
518 case ICE1712_SUBDEVICE_EWS88D
:
520 ice
->spdif
.ops
.open
= ews88_open_spdif
;
521 ice
->spdif
.ops
.setup_rate
= ews88_setup_spdif
;
522 ice
->spdif
.ops
.default_get
= ews88_spdif_default_get
;
523 ice
->spdif
.ops
.default_put
= ews88_spdif_default_put
;
524 ice
->spdif
.ops
.stream_get
= ews88_spdif_stream_get
;
525 ice
->spdif
.ops
.stream_put
= ews88_spdif_stream_put
;
526 /* Set spdif defaults */
527 snd_ice1712_ews_cs8404_spdif_write(ice
, ice
->spdif
.cs8403_bits
);
532 switch (ice
->eeprom
.subvendor
) {
533 case ICE1712_SUBDEVICE_EWS88D
:
538 ak
= ice
->akm
= kzalloc(sizeof(struct snd_akm4xxx
), GFP_KERNEL
);
543 switch (ice
->eeprom
.subvendor
) {
544 case ICE1712_SUBDEVICE_EWS88MT
:
545 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
546 case ICE1712_SUBDEVICE_PHASE88
:
547 case ICE1712_SUBDEVICE_TS88
:
548 err
= snd_ice1712_akm4xxx_init(ak
, &akm_ews88mt
, &akm_ews88mt_priv
, ice
);
550 case ICE1712_SUBDEVICE_EWX2496
:
551 err
= snd_ice1712_akm4xxx_init(ak
, &akm_ewx2496
, &akm_ewx2496_priv
, ice
);
553 case ICE1712_SUBDEVICE_DMX6FIRE
:
554 err
= snd_ice1712_akm4xxx_init(ak
, &akm_6fire
, &akm_6fire_priv
, ice
);
564 * EWX 24/96 specific controls
567 /* i/o sensitivity - this callback is shared among other devices, too */
568 static int snd_ice1712_ewx_io_sense_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
){
570 static const char * const texts
[2] = {
573 return snd_ctl_enum_info(uinfo
, 1, 2, texts
);
576 static int snd_ice1712_ewx_io_sense_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
578 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
579 unsigned char mask
= kcontrol
->private_value
& 0xff;
581 snd_ice1712_save_gpio_status(ice
);
582 ucontrol
->value
.enumerated
.item
[0] = snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
) & mask
? 1 : 0;
583 snd_ice1712_restore_gpio_status(ice
);
587 static int snd_ice1712_ewx_io_sense_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
589 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
590 unsigned char mask
= kcontrol
->private_value
& 0xff;
593 if (kcontrol
->private_value
& (1 << 31))
595 nval
= ucontrol
->value
.enumerated
.item
[0] ? mask
: 0;
596 snd_ice1712_save_gpio_status(ice
);
597 val
= snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
);
599 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, nval
);
600 snd_ice1712_restore_gpio_status(ice
);
604 static const struct snd_kcontrol_new snd_ice1712_ewx2496_controls
[] = {
606 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
607 .name
= "Input Sensitivity Switch",
608 .info
= snd_ice1712_ewx_io_sense_info
,
609 .get
= snd_ice1712_ewx_io_sense_get
,
610 .put
= snd_ice1712_ewx_io_sense_put
,
611 .private_value
= ICE1712_EWX2496_AIN_SEL
,
614 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
615 .name
= "Output Sensitivity Switch",
616 .info
= snd_ice1712_ewx_io_sense_info
,
617 .get
= snd_ice1712_ewx_io_sense_get
,
618 .put
= snd_ice1712_ewx_io_sense_put
,
619 .private_value
= ICE1712_EWX2496_AOUT_SEL
,
625 * EWS88MT specific controls
627 /* analog output sensitivity;; address 0x48 bit 6 */
628 static int snd_ice1712_ews88mt_output_sense_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
630 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
631 struct ews_spec
*spec
= ice
->spec
;
634 snd_i2c_lock(ice
->i2c
);
635 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_PCF2
], &data
, 1) != 1) {
636 snd_i2c_unlock(ice
->i2c
);
639 snd_i2c_unlock(ice
->i2c
);
640 ucontrol
->value
.enumerated
.item
[0] = data
& ICE1712_EWS88MT_OUTPUT_SENSE
? 1 : 0; /* high = -10dBV, low = +4dBu */
644 /* analog output sensitivity;; address 0x48 bit 6 */
645 static int snd_ice1712_ews88mt_output_sense_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
647 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
648 struct ews_spec
*spec
= ice
->spec
;
649 unsigned char data
, ndata
;
651 snd_i2c_lock(ice
->i2c
);
652 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_PCF2
], &data
, 1) != 1) {
653 snd_i2c_unlock(ice
->i2c
);
656 ndata
= (data
& ~ICE1712_EWS88MT_OUTPUT_SENSE
) | (ucontrol
->value
.enumerated
.item
[0] ? ICE1712_EWS88MT_OUTPUT_SENSE
: 0);
657 if (ndata
!= data
&& snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_PCF2
],
659 snd_i2c_unlock(ice
->i2c
);
662 snd_i2c_unlock(ice
->i2c
);
663 return ndata
!= data
;
666 /* analog input sensitivity; address 0x46 */
667 static int snd_ice1712_ews88mt_input_sense_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
669 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
670 struct ews_spec
*spec
= ice
->spec
;
671 int channel
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
674 if (snd_BUG_ON(channel
< 0 || channel
> 7))
676 snd_i2c_lock(ice
->i2c
);
677 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_PCF1
], &data
, 1) != 1) {
678 snd_i2c_unlock(ice
->i2c
);
681 /* reversed; high = +4dBu, low = -10dBV */
682 ucontrol
->value
.enumerated
.item
[0] = data
& (1 << channel
) ? 0 : 1;
683 snd_i2c_unlock(ice
->i2c
);
687 /* analog output sensitivity; address 0x46 */
688 static int snd_ice1712_ews88mt_input_sense_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
690 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
691 struct ews_spec
*spec
= ice
->spec
;
692 int channel
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
693 unsigned char data
, ndata
;
695 if (snd_BUG_ON(channel
< 0 || channel
> 7))
697 snd_i2c_lock(ice
->i2c
);
698 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_PCF1
], &data
, 1) != 1) {
699 snd_i2c_unlock(ice
->i2c
);
702 ndata
= (data
& ~(1 << channel
)) | (ucontrol
->value
.enumerated
.item
[0] ? 0 : (1 << channel
));
703 if (ndata
!= data
&& snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_PCF1
],
705 snd_i2c_unlock(ice
->i2c
);
708 snd_i2c_unlock(ice
->i2c
);
709 return ndata
!= data
;
712 static const struct snd_kcontrol_new snd_ice1712_ews88mt_input_sense
= {
713 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
714 .name
= "Input Sensitivity Switch",
715 .info
= snd_ice1712_ewx_io_sense_info
,
716 .get
= snd_ice1712_ews88mt_input_sense_get
,
717 .put
= snd_ice1712_ews88mt_input_sense_put
,
721 static const struct snd_kcontrol_new snd_ice1712_ews88mt_output_sense
= {
722 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
723 .name
= "Output Sensitivity Switch",
724 .info
= snd_ice1712_ewx_io_sense_info
,
725 .get
= snd_ice1712_ews88mt_output_sense_get
,
726 .put
= snd_ice1712_ews88mt_output_sense_put
,
731 * EWS88D specific controls
734 #define snd_ice1712_ews88d_control_info snd_ctl_boolean_mono_info
736 static int snd_ice1712_ews88d_control_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
738 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
739 struct ews_spec
*spec
= ice
->spec
;
740 int shift
= kcontrol
->private_value
& 0xff;
741 int invert
= (kcontrol
->private_value
>> 8) & 1;
742 unsigned char data
[2];
744 snd_i2c_lock(ice
->i2c
);
745 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_88D
], data
, 2) != 2) {
746 snd_i2c_unlock(ice
->i2c
);
749 snd_i2c_unlock(ice
->i2c
);
750 data
[0] = (data
[shift
>> 3] >> (shift
& 7)) & 0x01;
753 ucontrol
->value
.integer
.value
[0] = data
[0];
757 static int snd_ice1712_ews88d_control_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
759 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
760 struct ews_spec
*spec
= ice
->spec
;
761 int shift
= kcontrol
->private_value
& 0xff;
762 int invert
= (kcontrol
->private_value
>> 8) & 1;
763 unsigned char data
[2], ndata
[2];
766 snd_i2c_lock(ice
->i2c
);
767 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_88D
], data
, 2) != 2) {
768 snd_i2c_unlock(ice
->i2c
);
771 ndata
[shift
>> 3] = data
[shift
>> 3] & ~(1 << (shift
& 7));
773 if (! ucontrol
->value
.integer
.value
[0])
774 ndata
[shift
>> 3] |= (1 << (shift
& 7));
776 if (ucontrol
->value
.integer
.value
[0])
777 ndata
[shift
>> 3] |= (1 << (shift
& 7));
779 change
= (data
[shift
>> 3] != ndata
[shift
>> 3]);
781 snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_88D
], data
, 2) != 2) {
782 snd_i2c_unlock(ice
->i2c
);
785 snd_i2c_unlock(ice
->i2c
);
789 #define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
793 .info = snd_ice1712_ews88d_control_info,\
794 .get = snd_ice1712_ews88d_control_get,\
795 .put = snd_ice1712_ews88d_control_put,\
796 .private_value = xshift | (xinvert << 8),\
799 static const struct snd_kcontrol_new snd_ice1712_ews88d_controls
[] = {
800 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "IEC958 Input Optical", 0, 1, 0), /* inverted */
801 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "ADAT Output Optical", 1, 0, 0),
802 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "ADAT External Master Clock", 2, 0, 0),
803 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "Enable ADAT", 3, 0, 0),
804 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER
, "ADAT Through", 4, 1, 0),
809 * DMX 6Fire specific controls
812 static int snd_ice1712_6fire_read_pca(struct snd_ice1712
*ice
, unsigned char reg
)
815 struct ews_spec
*spec
= ice
->spec
;
817 snd_i2c_lock(ice
->i2c
);
819 if (snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_6FIRE
], &byte
, 1) != 1) {
820 snd_i2c_unlock(ice
->i2c
);
821 dev_err(ice
->card
->dev
, "cannot send pca\n");
826 if (snd_i2c_readbytes(spec
->i2cdevs
[EWS_I2C_6FIRE
], &byte
, 1) != 1) {
827 snd_i2c_unlock(ice
->i2c
);
828 dev_err(ice
->card
->dev
, "cannot read pca\n");
831 snd_i2c_unlock(ice
->i2c
);
835 static int snd_ice1712_6fire_write_pca(struct snd_ice1712
*ice
, unsigned char reg
, unsigned char data
)
837 unsigned char bytes
[2];
838 struct ews_spec
*spec
= ice
->spec
;
840 snd_i2c_lock(ice
->i2c
);
843 if (snd_i2c_sendbytes(spec
->i2cdevs
[EWS_I2C_6FIRE
], bytes
, 2) != 2) {
844 snd_i2c_unlock(ice
->i2c
);
847 snd_i2c_unlock(ice
->i2c
);
851 #define snd_ice1712_6fire_control_info snd_ctl_boolean_mono_info
853 static int snd_ice1712_6fire_control_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
855 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
856 int shift
= kcontrol
->private_value
& 0xff;
857 int invert
= (kcontrol
->private_value
>> 8) & 1;
860 data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
);
863 data
= (data
>> shift
) & 1;
866 ucontrol
->value
.integer
.value
[0] = data
;
870 static int snd_ice1712_6fire_control_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
872 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
873 int shift
= kcontrol
->private_value
& 0xff;
874 int invert
= (kcontrol
->private_value
>> 8) & 1;
877 data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
);
880 ndata
= data
& ~(1 << shift
);
881 if (ucontrol
->value
.integer
.value
[0])
882 ndata
|= (1 << shift
);
884 ndata
^= (1 << shift
);
886 snd_ice1712_6fire_write_pca(ice
, PCF9554_REG_OUTPUT
, (unsigned char)ndata
);
892 static int snd_ice1712_6fire_select_input_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
894 static const char * const texts
[4] = {
895 "Internal", "Front Input", "Rear Input", "Wave Table"
897 return snd_ctl_enum_info(uinfo
, 1, 4, texts
);
900 static int snd_ice1712_6fire_select_input_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
902 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
905 data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
);
908 ucontrol
->value
.integer
.value
[0] = data
& 3;
912 static int snd_ice1712_6fire_select_input_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
914 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
917 data
= snd_ice1712_6fire_read_pca(ice
, PCF9554_REG_OUTPUT
);
921 ndata
|= (ucontrol
->value
.integer
.value
[0] & 3);
923 snd_ice1712_6fire_write_pca(ice
, PCF9554_REG_OUTPUT
, (unsigned char)ndata
);
930 #define DMX6FIRE_CONTROL(xname, xshift, xinvert) \
931 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
933 .info = snd_ice1712_6fire_control_info,\
934 .get = snd_ice1712_6fire_control_get,\
935 .put = snd_ice1712_6fire_control_put,\
936 .private_value = xshift | (xinvert << 8),\
939 static const struct snd_kcontrol_new snd_ice1712_6fire_controls
[] = {
941 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
942 .name
= "Analog Input Select",
943 .info
= snd_ice1712_6fire_select_input_info
,
944 .get
= snd_ice1712_6fire_select_input_get
,
945 .put
= snd_ice1712_6fire_select_input_put
,
947 DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 1),
948 // DMX6FIRE_CONTROL("Master Clock Select", 3, 0),
949 DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0),
950 DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0),
951 DMX6FIRE_CONTROL("Breakbox LED", 6, 0),
955 static int snd_ice1712_ews_add_controls(struct snd_ice1712
*ice
)
960 /* all terratec cards have spdif, but cs8427 module builds it's own controls */
961 if (ice
->cs8427
== NULL
) {
962 err
= snd_ice1712_spdif_build_controls(ice
);
967 /* ak4524 controls */
968 switch (ice
->eeprom
.subvendor
) {
969 case ICE1712_SUBDEVICE_EWX2496
:
970 case ICE1712_SUBDEVICE_EWS88MT
:
971 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
972 case ICE1712_SUBDEVICE_PHASE88
:
973 case ICE1712_SUBDEVICE_TS88
:
974 case ICE1712_SUBDEVICE_DMX6FIRE
:
975 err
= snd_ice1712_akm4xxx_build_controls(ice
);
981 /* card specific controls */
982 switch (ice
->eeprom
.subvendor
) {
983 case ICE1712_SUBDEVICE_EWX2496
:
984 for (idx
= 0; idx
< ARRAY_SIZE(snd_ice1712_ewx2496_controls
); idx
++) {
985 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ewx2496_controls
[idx
], ice
));
990 case ICE1712_SUBDEVICE_EWS88MT
:
991 case ICE1712_SUBDEVICE_EWS88MT_NEW
:
992 case ICE1712_SUBDEVICE_PHASE88
:
993 case ICE1712_SUBDEVICE_TS88
:
994 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense
, ice
));
997 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense
, ice
));
1001 case ICE1712_SUBDEVICE_EWS88D
:
1002 for (idx
= 0; idx
< ARRAY_SIZE(snd_ice1712_ews88d_controls
); idx
++) {
1003 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_ews88d_controls
[idx
], ice
));
1008 case ICE1712_SUBDEVICE_DMX6FIRE
:
1009 for (idx
= 0; idx
< ARRAY_SIZE(snd_ice1712_6fire_controls
); idx
++) {
1010 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_6fire_controls
[idx
], ice
));
1021 struct snd_ice1712_card_info snd_ice1712_ews_cards
[] = {
1023 .subvendor
= ICE1712_SUBDEVICE_EWX2496
,
1024 .name
= "TerraTec EWX24/96",
1026 .chip_init
= snd_ice1712_ews_init
,
1027 .build_controls
= snd_ice1712_ews_add_controls
,
1030 .subvendor
= ICE1712_SUBDEVICE_EWS88MT
,
1031 .name
= "TerraTec EWS88MT",
1033 .chip_init
= snd_ice1712_ews_init
,
1034 .build_controls
= snd_ice1712_ews_add_controls
,
1037 .subvendor
= ICE1712_SUBDEVICE_EWS88MT_NEW
,
1038 .name
= "TerraTec EWS88MT",
1039 .model
= "ews88mt_new",
1040 .chip_init
= snd_ice1712_ews_init
,
1041 .build_controls
= snd_ice1712_ews_add_controls
,
1044 .subvendor
= ICE1712_SUBDEVICE_PHASE88
,
1045 .name
= "TerraTec Phase88",
1047 .chip_init
= snd_ice1712_ews_init
,
1048 .build_controls
= snd_ice1712_ews_add_controls
,
1051 .subvendor
= ICE1712_SUBDEVICE_TS88
,
1052 .name
= "terrasoniq TS88",
1054 .chip_init
= snd_ice1712_ews_init
,
1055 .build_controls
= snd_ice1712_ews_add_controls
,
1058 .subvendor
= ICE1712_SUBDEVICE_EWS88D
,
1059 .name
= "TerraTec EWS88D",
1061 .chip_init
= snd_ice1712_ews_init
,
1062 .build_controls
= snd_ice1712_ews_add_controls
,
1065 .subvendor
= ICE1712_SUBDEVICE_DMX6FIRE
,
1066 .name
= "TerraTec DMX6Fire",
1067 .model
= "dmx6fire",
1068 .chip_init
= snd_ice1712_ews_init
,
1069 .build_controls
= snd_ice1712_ews_add_controls
,
1070 .mpu401_1_name
= "MIDI-Front DMX6fire",
1071 .mpu401_2_name
= "Wavetable DMX6fire",
1072 .mpu401_2_info_flags
= MPU401_INFO_OUTPUT
,
1074 { } /* terminator */