0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/delay.h>
0012 #include <linux/interrupt.h>
0013 #include <linux/init.h>
0014 #include <linux/slab.h>
0015 #include <sound/core.h>
0016 #include <sound/cs8427.h>
0017 #include <sound/asoundef.h>
0018
0019 #include "ice1712.h"
0020 #include "ews.h"
0021
0022 #define SND_CS8404
0023 #include <sound/cs8403.h>
0024
0025 enum {
0026 EWS_I2C_CS8404 = 0, EWS_I2C_PCF1, EWS_I2C_PCF2,
0027 EWS_I2C_88D = 0,
0028 EWS_I2C_6FIRE = 0
0029 };
0030
0031
0032
0033 struct ews_spec {
0034 struct snd_i2c_device *i2cdevs[3];
0035 };
0036
0037
0038
0039
0040
0041
0042 static void ewx_i2c_setlines(struct snd_i2c_bus *bus, int clk, int data)
0043 {
0044 struct snd_ice1712 *ice = bus->private_data;
0045 unsigned char tmp = 0;
0046 if (clk)
0047 tmp |= ICE1712_EWX2496_SERIAL_CLOCK;
0048 if (data)
0049 tmp |= ICE1712_EWX2496_SERIAL_DATA;
0050 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
0051 udelay(5);
0052 }
0053
0054 static int ewx_i2c_getclock(struct snd_i2c_bus *bus)
0055 {
0056 struct snd_ice1712 *ice = bus->private_data;
0057 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_CLOCK ? 1 : 0;
0058 }
0059
0060 static int ewx_i2c_getdata(struct snd_i2c_bus *bus, int ack)
0061 {
0062 struct snd_ice1712 *ice = bus->private_data;
0063 int bit;
0064
0065 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_RW);
0066 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, 0);
0067 if (ack)
0068 udelay(5);
0069 bit = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_DATA ? 1 : 0;
0070
0071 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ICE1712_EWX2496_RW);
0072
0073 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_SERIAL_CLOCK);
0074 return bit;
0075 }
0076
0077 static void ewx_i2c_start(struct snd_i2c_bus *bus)
0078 {
0079 struct snd_ice1712 *ice = bus->private_data;
0080 unsigned char mask;
0081
0082 snd_ice1712_save_gpio_status(ice);
0083
0084 mask = ICE1712_EWX2496_RW;
0085 switch (ice->eeprom.subvendor) {
0086 case ICE1712_SUBDEVICE_EWX2496:
0087 mask |= ICE1712_EWX2496_AK4524_CS;
0088 break;
0089 case ICE1712_SUBDEVICE_DMX6FIRE:
0090 mask |= ICE1712_6FIRE_AK4524_CS_MASK;
0091 break;
0092 }
0093 snd_ice1712_gpio_write_bits(ice, mask, mask);
0094 }
0095
0096 static void ewx_i2c_stop(struct snd_i2c_bus *bus)
0097 {
0098 struct snd_ice1712 *ice = bus->private_data;
0099 snd_ice1712_restore_gpio_status(ice);
0100 }
0101
0102 static void ewx_i2c_direction(struct snd_i2c_bus *bus, int clock, int data)
0103 {
0104 struct snd_ice1712 *ice = bus->private_data;
0105 unsigned char mask = 0;
0106
0107 if (clock)
0108 mask |= ICE1712_EWX2496_SERIAL_CLOCK;
0109 if (data)
0110 mask |= ICE1712_EWX2496_SERIAL_DATA;
0111 ice->gpio.direction &= ~(ICE1712_EWX2496_SERIAL_CLOCK|ICE1712_EWX2496_SERIAL_DATA);
0112 ice->gpio.direction |= mask;
0113 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio.direction);
0114 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~mask);
0115 }
0116
0117 static struct snd_i2c_bit_ops snd_ice1712_ewx_cs8427_bit_ops = {
0118 .start = ewx_i2c_start,
0119 .stop = ewx_i2c_stop,
0120 .direction = ewx_i2c_direction,
0121 .setlines = ewx_i2c_setlines,
0122 .getclock = ewx_i2c_getclock,
0123 .getdata = ewx_i2c_getdata,
0124 };
0125
0126
0127
0128
0129
0130
0131
0132 static int snd_ice1712_ews88mt_chip_select(struct snd_ice1712 *ice, int chip_mask)
0133 {
0134 struct ews_spec *spec = ice->spec;
0135 unsigned char data, ndata;
0136
0137 if (snd_BUG_ON(chip_mask < 0 || chip_mask > 0x0f))
0138 return -EINVAL;
0139 snd_i2c_lock(ice->i2c);
0140 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1)
0141 goto __error;
0142 ndata = (data & 0xf0) | chip_mask;
0143 if (ndata != data)
0144 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF2], &ndata, 1)
0145 != 1)
0146 goto __error;
0147 snd_i2c_unlock(ice->i2c);
0148 return 0;
0149
0150 __error:
0151 snd_i2c_unlock(ice->i2c);
0152 dev_err(ice->card->dev,
0153 "AK4524 chip select failed, check cable to the front module\n");
0154 return -EIO;
0155 }
0156
0157
0158 static void ews88mt_ak4524_lock(struct snd_akm4xxx *ak, int chip)
0159 {
0160 struct snd_ice1712 *ice = ak->private_data[0];
0161 unsigned char tmp;
0162
0163 if (snd_ice1712_ews88mt_chip_select(ice, ~(1 << chip) & 0x0f) < 0)
0164 dev_err(ice->card->dev, "fatal error (ews88mt chip select)\n");
0165 snd_ice1712_save_gpio_status(ice);
0166 tmp = ICE1712_EWS88_SERIAL_DATA |
0167 ICE1712_EWS88_SERIAL_CLOCK |
0168 ICE1712_EWS88_RW;
0169 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
0170 ice->gpio.direction | tmp);
0171 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
0172 }
0173
0174
0175 static void ews88mt_ak4524_unlock(struct snd_akm4xxx *ak, int chip)
0176 {
0177 struct snd_ice1712 *ice = ak->private_data[0];
0178 snd_ice1712_restore_gpio_status(ice);
0179 udelay(1);
0180 snd_ice1712_ews88mt_chip_select(ice, 0x0f);
0181 }
0182
0183
0184 static void ewx2496_ak4524_lock(struct snd_akm4xxx *ak, int chip)
0185 {
0186 struct snd_ice1712 *ice = ak->private_data[0];
0187 unsigned char tmp;
0188 snd_ice1712_save_gpio_status(ice);
0189 tmp = ICE1712_EWX2496_SERIAL_DATA |
0190 ICE1712_EWX2496_SERIAL_CLOCK |
0191 ICE1712_EWX2496_AK4524_CS |
0192 ICE1712_EWX2496_RW;
0193 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
0194 ice->gpio.direction | tmp);
0195 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
0196 }
0197
0198
0199 static void dmx6fire_ak4524_lock(struct snd_akm4xxx *ak, int chip)
0200 {
0201 struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
0202 struct snd_ice1712 *ice = ak->private_data[0];
0203 unsigned char tmp;
0204 snd_ice1712_save_gpio_status(ice);
0205 tmp = priv->cs_mask = priv->cs_addr = (1 << chip) & ICE1712_6FIRE_AK4524_CS_MASK;
0206 tmp |= ICE1712_6FIRE_SERIAL_DATA |
0207 ICE1712_6FIRE_SERIAL_CLOCK |
0208 ICE1712_6FIRE_RW;
0209 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
0210 ice->gpio.direction | tmp);
0211 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
0212 }
0213
0214
0215
0216
0217
0218 static void snd_ice1712_ews_cs8404_spdif_write(struct snd_ice1712 *ice, unsigned char bits)
0219 {
0220 struct ews_spec *spec = ice->spec;
0221 unsigned char bytes[2];
0222
0223 snd_i2c_lock(ice->i2c);
0224 switch (ice->eeprom.subvendor) {
0225 case ICE1712_SUBDEVICE_EWS88MT:
0226 case ICE1712_SUBDEVICE_EWS88MT_NEW:
0227 case ICE1712_SUBDEVICE_PHASE88:
0228 case ICE1712_SUBDEVICE_TS88:
0229 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_CS8404], &bits, 1)
0230 != 1)
0231 goto _error;
0232 break;
0233 case ICE1712_SUBDEVICE_EWS88D:
0234 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], bytes, 2)
0235 != 2)
0236 goto _error;
0237 if (bits != bytes[1]) {
0238 bytes[1] = bits;
0239 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_88D],
0240 bytes, 2) != 2)
0241 goto _error;
0242 }
0243 break;
0244 }
0245 _error:
0246 snd_i2c_unlock(ice->i2c);
0247 }
0248
0249
0250
0251
0252 static void ews88_spdif_default_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
0253 {
0254 snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_bits);
0255 }
0256
0257 static int ews88_spdif_default_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
0258 {
0259 unsigned int val;
0260 int change;
0261
0262 val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
0263 spin_lock_irq(&ice->reg_lock);
0264 change = ice->spdif.cs8403_bits != val;
0265 ice->spdif.cs8403_bits = val;
0266 if (change && ice->playback_pro_substream == NULL) {
0267 spin_unlock_irq(&ice->reg_lock);
0268 snd_ice1712_ews_cs8404_spdif_write(ice, val);
0269 } else {
0270 spin_unlock_irq(&ice->reg_lock);
0271 }
0272 return change;
0273 }
0274
0275 static void ews88_spdif_stream_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
0276 {
0277 snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_stream_bits);
0278 }
0279
0280 static int ews88_spdif_stream_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
0281 {
0282 unsigned int val;
0283 int change;
0284
0285 val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
0286 spin_lock_irq(&ice->reg_lock);
0287 change = ice->spdif.cs8403_stream_bits != val;
0288 ice->spdif.cs8403_stream_bits = val;
0289 if (change && ice->playback_pro_substream != NULL) {
0290 spin_unlock_irq(&ice->reg_lock);
0291 snd_ice1712_ews_cs8404_spdif_write(ice, val);
0292 } else {
0293 spin_unlock_irq(&ice->reg_lock);
0294 }
0295 return change;
0296 }
0297
0298
0299
0300 static void ews88_open_spdif(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
0301 {
0302 ice->spdif.cs8403_stream_bits = ice->spdif.cs8403_bits;
0303 }
0304
0305
0306 static void ews88_setup_spdif(struct snd_ice1712 *ice, int rate)
0307 {
0308 unsigned long flags;
0309 unsigned char tmp;
0310 int change;
0311
0312 spin_lock_irqsave(&ice->reg_lock, flags);
0313 tmp = ice->spdif.cs8403_stream_bits;
0314 if (tmp & 0x10)
0315 tmp &= (tmp & 0x01) ? ~0x06 : ~0x60;
0316 switch (rate) {
0317 case 32000: tmp |= (tmp & 0x01) ? 0x02 : 0x00; break;
0318 case 44100: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
0319 case 48000: tmp |= (tmp & 0x01) ? 0x04 : 0x20; break;
0320 default: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
0321 }
0322 change = ice->spdif.cs8403_stream_bits != tmp;
0323 ice->spdif.cs8403_stream_bits = tmp;
0324 spin_unlock_irqrestore(&ice->reg_lock, flags);
0325 if (change)
0326 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &ice->spdif.stream_ctl->id);
0327 snd_ice1712_ews_cs8404_spdif_write(ice, tmp);
0328 }
0329
0330
0331
0332
0333 static const struct snd_akm4xxx akm_ews88mt = {
0334 .num_adcs = 8,
0335 .num_dacs = 8,
0336 .type = SND_AK4524,
0337 .ops = {
0338 .lock = ews88mt_ak4524_lock,
0339 .unlock = ews88mt_ak4524_unlock
0340 }
0341 };
0342
0343 static const struct snd_ak4xxx_private akm_ews88mt_priv = {
0344 .caddr = 2,
0345 .cif = 1,
0346 .data_mask = ICE1712_EWS88_SERIAL_DATA,
0347 .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
0348 .cs_mask = 0,
0349 .cs_addr = 0,
0350 .cs_none = 0,
0351 .add_flags = ICE1712_EWS88_RW,
0352 .mask_flags = 0,
0353 };
0354
0355 static const struct snd_akm4xxx akm_ewx2496 = {
0356 .num_adcs = 2,
0357 .num_dacs = 2,
0358 .type = SND_AK4524,
0359 .ops = {
0360 .lock = ewx2496_ak4524_lock
0361 }
0362 };
0363
0364 static const struct snd_ak4xxx_private akm_ewx2496_priv = {
0365 .caddr = 2,
0366 .cif = 1,
0367 .data_mask = ICE1712_EWS88_SERIAL_DATA,
0368 .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
0369 .cs_mask = ICE1712_EWX2496_AK4524_CS,
0370 .cs_addr = ICE1712_EWX2496_AK4524_CS,
0371 .cs_none = 0,
0372 .add_flags = ICE1712_EWS88_RW,
0373 .mask_flags = 0,
0374 };
0375
0376 static const struct snd_akm4xxx akm_6fire = {
0377 .num_adcs = 6,
0378 .num_dacs = 6,
0379 .type = SND_AK4524,
0380 .ops = {
0381 .lock = dmx6fire_ak4524_lock
0382 }
0383 };
0384
0385 static const struct snd_ak4xxx_private akm_6fire_priv = {
0386 .caddr = 2,
0387 .cif = 1,
0388 .data_mask = ICE1712_6FIRE_SERIAL_DATA,
0389 .clk_mask = ICE1712_6FIRE_SERIAL_CLOCK,
0390 .cs_mask = 0,
0391 .cs_addr = 0,
0392 .cs_none = 0,
0393 .add_flags = ICE1712_6FIRE_RW,
0394 .mask_flags = 0,
0395 };
0396
0397
0398
0399
0400
0401
0402 #define PCF9554_REG_INPUT 0
0403 #define PCF9554_REG_OUTPUT 1
0404 #define PCF9554_REG_POLARITY 2
0405 #define PCF9554_REG_CONFIG 3
0406
0407 static int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data);
0408
0409 static int snd_ice1712_ews_init(struct snd_ice1712 *ice)
0410 {
0411 int err;
0412 struct snd_akm4xxx *ak;
0413 struct ews_spec *spec;
0414
0415
0416 switch (ice->eeprom.subvendor) {
0417 case ICE1712_SUBDEVICE_EWX2496:
0418 ice->num_total_dacs = 2;
0419 ice->num_total_adcs = 2;
0420 break;
0421 case ICE1712_SUBDEVICE_EWS88MT:
0422 case ICE1712_SUBDEVICE_EWS88MT_NEW:
0423 case ICE1712_SUBDEVICE_PHASE88:
0424 case ICE1712_SUBDEVICE_TS88:
0425 ice->num_total_dacs = 8;
0426 ice->num_total_adcs = 8;
0427 break;
0428 case ICE1712_SUBDEVICE_EWS88D:
0429
0430 ice->num_total_dacs = 8;
0431 ice->num_total_adcs = 8;
0432 break;
0433 case ICE1712_SUBDEVICE_DMX6FIRE:
0434 ice->num_total_dacs = 6;
0435 ice->num_total_adcs = 6;
0436 break;
0437 }
0438
0439 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
0440 if (!spec)
0441 return -ENOMEM;
0442 ice->spec = spec;
0443
0444
0445 err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c);
0446 if (err < 0) {
0447 dev_err(ice->card->dev, "unable to create I2C bus\n");
0448 return err;
0449 }
0450 ice->i2c->private_data = ice;
0451 ice->i2c->hw_ops.bit = &snd_ice1712_ewx_cs8427_bit_ops;
0452
0453
0454 switch (ice->eeprom.subvendor) {
0455 case ICE1712_SUBDEVICE_DMX6FIRE:
0456 err = snd_i2c_device_create(ice->i2c, "PCF9554",
0457 ICE1712_6FIRE_PCF9554_ADDR,
0458 &spec->i2cdevs[EWS_I2C_6FIRE]);
0459 if (err < 0) {
0460 dev_err(ice->card->dev,
0461 "PCF9554 initialization failed\n");
0462 return err;
0463 }
0464 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80);
0465 break;
0466 case ICE1712_SUBDEVICE_EWS88MT:
0467 case ICE1712_SUBDEVICE_EWS88MT_NEW:
0468 case ICE1712_SUBDEVICE_PHASE88:
0469 case ICE1712_SUBDEVICE_TS88:
0470
0471 err = snd_i2c_device_create(ice->i2c, "CS8404",
0472 ICE1712_EWS88MT_CS8404_ADDR,
0473 &spec->i2cdevs[EWS_I2C_CS8404]);
0474 if (err < 0)
0475 return err;
0476 err = snd_i2c_device_create(ice->i2c, "PCF8574 (1st)",
0477 ICE1712_EWS88MT_INPUT_ADDR,
0478 &spec->i2cdevs[EWS_I2C_PCF1]);
0479 if (err < 0)
0480 return err;
0481 err = snd_i2c_device_create(ice->i2c, "PCF8574 (2nd)",
0482 ICE1712_EWS88MT_OUTPUT_ADDR,
0483 &spec->i2cdevs[EWS_I2C_PCF2]);
0484 if (err < 0)
0485 return err;
0486
0487 err = snd_ice1712_ews88mt_chip_select(ice, 0x0f);
0488 if (err < 0)
0489 return err;
0490 break;
0491 case ICE1712_SUBDEVICE_EWS88D:
0492 err = snd_i2c_device_create(ice->i2c, "PCF8575",
0493 ICE1712_EWS88D_PCF_ADDR,
0494 &spec->i2cdevs[EWS_I2C_88D]);
0495 if (err < 0)
0496 return err;
0497 break;
0498 }
0499
0500
0501 switch (ice->eeprom.subvendor) {
0502 case ICE1712_SUBDEVICE_EWX2496:
0503 err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR);
0504 if (err < 0)
0505 return err;
0506 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
0507 break;
0508 case ICE1712_SUBDEVICE_DMX6FIRE:
0509 err = snd_ice1712_init_cs8427(ice, ICE1712_6FIRE_CS8427_ADDR);
0510 if (err < 0)
0511 return err;
0512 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
0513 break;
0514 case ICE1712_SUBDEVICE_EWS88MT:
0515 case ICE1712_SUBDEVICE_EWS88MT_NEW:
0516 case ICE1712_SUBDEVICE_PHASE88:
0517 case ICE1712_SUBDEVICE_TS88:
0518 case ICE1712_SUBDEVICE_EWS88D:
0519
0520 ice->spdif.ops.open = ews88_open_spdif;
0521 ice->spdif.ops.setup_rate = ews88_setup_spdif;
0522 ice->spdif.ops.default_get = ews88_spdif_default_get;
0523 ice->spdif.ops.default_put = ews88_spdif_default_put;
0524 ice->spdif.ops.stream_get = ews88_spdif_stream_get;
0525 ice->spdif.ops.stream_put = ews88_spdif_stream_put;
0526
0527 snd_ice1712_ews_cs8404_spdif_write(ice, ice->spdif.cs8403_bits);
0528 break;
0529 }
0530
0531
0532 switch (ice->eeprom.subvendor) {
0533 case ICE1712_SUBDEVICE_EWS88D:
0534 return 0;
0535 }
0536
0537
0538 ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
0539 if (! ak)
0540 return -ENOMEM;
0541 ice->akm_codecs = 1;
0542
0543 switch (ice->eeprom.subvendor) {
0544 case ICE1712_SUBDEVICE_EWS88MT:
0545 case ICE1712_SUBDEVICE_EWS88MT_NEW:
0546 case ICE1712_SUBDEVICE_PHASE88:
0547 case ICE1712_SUBDEVICE_TS88:
0548 err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice);
0549 break;
0550 case ICE1712_SUBDEVICE_EWX2496:
0551 err = snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, &akm_ewx2496_priv, ice);
0552 break;
0553 case ICE1712_SUBDEVICE_DMX6FIRE:
0554 err = snd_ice1712_akm4xxx_init(ak, &akm_6fire, &akm_6fire_priv, ice);
0555 break;
0556 default:
0557 err = 0;
0558 }
0559
0560 return err;
0561 }
0562
0563
0564
0565
0566
0567
0568 static int snd_ice1712_ewx_io_sense_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){
0569
0570 static const char * const texts[2] = {
0571 "+4dBu", "-10dBV",
0572 };
0573 return snd_ctl_enum_info(uinfo, 1, 2, texts);
0574 }
0575
0576 static int snd_ice1712_ewx_io_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
0577 {
0578 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0579 unsigned char mask = kcontrol->private_value & 0xff;
0580
0581 snd_ice1712_save_gpio_status(ice);
0582 ucontrol->value.enumerated.item[0] = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0;
0583 snd_ice1712_restore_gpio_status(ice);
0584 return 0;
0585 }
0586
0587 static int snd_ice1712_ewx_io_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
0588 {
0589 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0590 unsigned char mask = kcontrol->private_value & 0xff;
0591 int val, nval;
0592
0593 if (kcontrol->private_value & (1 << 31))
0594 return -EPERM;
0595 nval = ucontrol->value.enumerated.item[0] ? mask : 0;
0596 snd_ice1712_save_gpio_status(ice);
0597 val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
0598 nval |= val & ~mask;
0599 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, nval);
0600 snd_ice1712_restore_gpio_status(ice);
0601 return val != nval;
0602 }
0603
0604 static const struct snd_kcontrol_new snd_ice1712_ewx2496_controls[] = {
0605 {
0606 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0607 .name = "Input Sensitivity Switch",
0608 .info = snd_ice1712_ewx_io_sense_info,
0609 .get = snd_ice1712_ewx_io_sense_get,
0610 .put = snd_ice1712_ewx_io_sense_put,
0611 .private_value = ICE1712_EWX2496_AIN_SEL,
0612 },
0613 {
0614 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0615 .name = "Output Sensitivity Switch",
0616 .info = snd_ice1712_ewx_io_sense_info,
0617 .get = snd_ice1712_ewx_io_sense_get,
0618 .put = snd_ice1712_ewx_io_sense_put,
0619 .private_value = ICE1712_EWX2496_AOUT_SEL,
0620 },
0621 };
0622
0623
0624
0625
0626
0627
0628 static int snd_ice1712_ews88mt_output_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
0629 {
0630 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0631 struct ews_spec *spec = ice->spec;
0632 unsigned char data;
0633
0634 snd_i2c_lock(ice->i2c);
0635 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) {
0636 snd_i2c_unlock(ice->i2c);
0637 return -EIO;
0638 }
0639 snd_i2c_unlock(ice->i2c);
0640 ucontrol->value.enumerated.item[0] = data & ICE1712_EWS88MT_OUTPUT_SENSE ? 1 : 0;
0641 return 0;
0642 }
0643
0644
0645 static int snd_ice1712_ews88mt_output_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
0646 {
0647 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0648 struct ews_spec *spec = ice->spec;
0649 unsigned char data, ndata;
0650
0651 snd_i2c_lock(ice->i2c);
0652 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) {
0653 snd_i2c_unlock(ice->i2c);
0654 return -EIO;
0655 }
0656 ndata = (data & ~ICE1712_EWS88MT_OUTPUT_SENSE) | (ucontrol->value.enumerated.item[0] ? ICE1712_EWS88MT_OUTPUT_SENSE : 0);
0657 if (ndata != data && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF2],
0658 &ndata, 1) != 1) {
0659 snd_i2c_unlock(ice->i2c);
0660 return -EIO;
0661 }
0662 snd_i2c_unlock(ice->i2c);
0663 return ndata != data;
0664 }
0665
0666
0667 static int snd_ice1712_ews88mt_input_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
0668 {
0669 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0670 struct ews_spec *spec = ice->spec;
0671 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
0672 unsigned char data;
0673
0674 if (snd_BUG_ON(channel < 0 || channel > 7))
0675 return 0;
0676 snd_i2c_lock(ice->i2c);
0677 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) {
0678 snd_i2c_unlock(ice->i2c);
0679 return -EIO;
0680 }
0681
0682 ucontrol->value.enumerated.item[0] = data & (1 << channel) ? 0 : 1;
0683 snd_i2c_unlock(ice->i2c);
0684 return 0;
0685 }
0686
0687
0688 static int snd_ice1712_ews88mt_input_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
0689 {
0690 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0691 struct ews_spec *spec = ice->spec;
0692 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
0693 unsigned char data, ndata;
0694
0695 if (snd_BUG_ON(channel < 0 || channel > 7))
0696 return 0;
0697 snd_i2c_lock(ice->i2c);
0698 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) {
0699 snd_i2c_unlock(ice->i2c);
0700 return -EIO;
0701 }
0702 ndata = (data & ~(1 << channel)) | (ucontrol->value.enumerated.item[0] ? 0 : (1 << channel));
0703 if (ndata != data && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF1],
0704 &ndata, 1) != 1) {
0705 snd_i2c_unlock(ice->i2c);
0706 return -EIO;
0707 }
0708 snd_i2c_unlock(ice->i2c);
0709 return ndata != data;
0710 }
0711
0712 static const struct snd_kcontrol_new snd_ice1712_ews88mt_input_sense = {
0713 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0714 .name = "Input Sensitivity Switch",
0715 .info = snd_ice1712_ewx_io_sense_info,
0716 .get = snd_ice1712_ews88mt_input_sense_get,
0717 .put = snd_ice1712_ews88mt_input_sense_put,
0718 .count = 8,
0719 };
0720
0721 static const struct snd_kcontrol_new snd_ice1712_ews88mt_output_sense = {
0722 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0723 .name = "Output Sensitivity Switch",
0724 .info = snd_ice1712_ewx_io_sense_info,
0725 .get = snd_ice1712_ews88mt_output_sense_get,
0726 .put = snd_ice1712_ews88mt_output_sense_put,
0727 };
0728
0729
0730
0731
0732
0733
0734 #define snd_ice1712_ews88d_control_info snd_ctl_boolean_mono_info
0735
0736 static int snd_ice1712_ews88d_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
0737 {
0738 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0739 struct ews_spec *spec = ice->spec;
0740 int shift = kcontrol->private_value & 0xff;
0741 int invert = (kcontrol->private_value >> 8) & 1;
0742 unsigned char data[2];
0743
0744 snd_i2c_lock(ice->i2c);
0745 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
0746 snd_i2c_unlock(ice->i2c);
0747 return -EIO;
0748 }
0749 snd_i2c_unlock(ice->i2c);
0750 data[0] = (data[shift >> 3] >> (shift & 7)) & 0x01;
0751 if (invert)
0752 data[0] ^= 0x01;
0753 ucontrol->value.integer.value[0] = data[0];
0754 return 0;
0755 }
0756
0757 static int snd_ice1712_ews88d_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
0758 {
0759 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0760 struct ews_spec *spec = ice->spec;
0761 int shift = kcontrol->private_value & 0xff;
0762 int invert = (kcontrol->private_value >> 8) & 1;
0763 unsigned char data[2], ndata[2];
0764 int change;
0765
0766 snd_i2c_lock(ice->i2c);
0767 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
0768 snd_i2c_unlock(ice->i2c);
0769 return -EIO;
0770 }
0771 ndata[shift >> 3] = data[shift >> 3] & ~(1 << (shift & 7));
0772 if (invert) {
0773 if (! ucontrol->value.integer.value[0])
0774 ndata[shift >> 3] |= (1 << (shift & 7));
0775 } else {
0776 if (ucontrol->value.integer.value[0])
0777 ndata[shift >> 3] |= (1 << (shift & 7));
0778 }
0779 change = (data[shift >> 3] != ndata[shift >> 3]);
0780 if (change &&
0781 snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
0782 snd_i2c_unlock(ice->i2c);
0783 return -EIO;
0784 }
0785 snd_i2c_unlock(ice->i2c);
0786 return change;
0787 }
0788
0789 #define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
0790 { .iface = xiface,\
0791 .name = xname,\
0792 .access = xaccess,\
0793 .info = snd_ice1712_ews88d_control_info,\
0794 .get = snd_ice1712_ews88d_control_get,\
0795 .put = snd_ice1712_ews88d_control_put,\
0796 .private_value = xshift | (xinvert << 8),\
0797 }
0798
0799 static const struct snd_kcontrol_new snd_ice1712_ews88d_controls[] = {
0800 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, 1, 0),
0801 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Output Optical", 1, 0, 0),
0802 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT External Master Clock", 2, 0, 0),
0803 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "Enable ADAT", 3, 0, 0),
0804 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Through", 4, 1, 0),
0805 };
0806
0807
0808
0809
0810
0811
0812 static int snd_ice1712_6fire_read_pca(struct snd_ice1712 *ice, unsigned char reg)
0813 {
0814 unsigned char byte;
0815 struct ews_spec *spec = ice->spec;
0816
0817 snd_i2c_lock(ice->i2c);
0818 byte = reg;
0819 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) {
0820 snd_i2c_unlock(ice->i2c);
0821 dev_err(ice->card->dev, "cannot send pca\n");
0822 return -EIO;
0823 }
0824
0825 byte = 0;
0826 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) {
0827 snd_i2c_unlock(ice->i2c);
0828 dev_err(ice->card->dev, "cannot read pca\n");
0829 return -EIO;
0830 }
0831 snd_i2c_unlock(ice->i2c);
0832 return byte;
0833 }
0834
0835 static int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data)
0836 {
0837 unsigned char bytes[2];
0838 struct ews_spec *spec = ice->spec;
0839
0840 snd_i2c_lock(ice->i2c);
0841 bytes[0] = reg;
0842 bytes[1] = data;
0843 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_6FIRE], bytes, 2) != 2) {
0844 snd_i2c_unlock(ice->i2c);
0845 return -EIO;
0846 }
0847 snd_i2c_unlock(ice->i2c);
0848 return 0;
0849 }
0850
0851 #define snd_ice1712_6fire_control_info snd_ctl_boolean_mono_info
0852
0853 static int snd_ice1712_6fire_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
0854 {
0855 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0856 int shift = kcontrol->private_value & 0xff;
0857 int invert = (kcontrol->private_value >> 8) & 1;
0858 int data;
0859
0860 data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT);
0861 if (data < 0)
0862 return data;
0863 data = (data >> shift) & 1;
0864 if (invert)
0865 data ^= 1;
0866 ucontrol->value.integer.value[0] = data;
0867 return 0;
0868 }
0869
0870 static int snd_ice1712_6fire_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
0871 {
0872 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0873 int shift = kcontrol->private_value & 0xff;
0874 int invert = (kcontrol->private_value >> 8) & 1;
0875 int data, ndata;
0876
0877 data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT);
0878 if (data < 0)
0879 return data;
0880 ndata = data & ~(1 << shift);
0881 if (ucontrol->value.integer.value[0])
0882 ndata |= (1 << shift);
0883 if (invert)
0884 ndata ^= (1 << shift);
0885 if (data != ndata) {
0886 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
0887 return 1;
0888 }
0889 return 0;
0890 }
0891
0892 static int snd_ice1712_6fire_select_input_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
0893 {
0894 static const char * const texts[4] = {
0895 "Internal", "Front Input", "Rear Input", "Wave Table"
0896 };
0897 return snd_ctl_enum_info(uinfo, 1, 4, texts);
0898 }
0899
0900 static int snd_ice1712_6fire_select_input_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
0901 {
0902 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0903 int data;
0904
0905 data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT);
0906 if (data < 0)
0907 return data;
0908 ucontrol->value.integer.value[0] = data & 3;
0909 return 0;
0910 }
0911
0912 static int snd_ice1712_6fire_select_input_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
0913 {
0914 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0915 int data, ndata;
0916
0917 data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT);
0918 if (data < 0)
0919 return data;
0920 ndata = data & ~3;
0921 ndata |= (ucontrol->value.integer.value[0] & 3);
0922 if (data != ndata) {
0923 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
0924 return 1;
0925 }
0926 return 0;
0927 }
0928
0929
0930 #define DMX6FIRE_CONTROL(xname, xshift, xinvert) \
0931 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
0932 .name = xname,\
0933 .info = snd_ice1712_6fire_control_info,\
0934 .get = snd_ice1712_6fire_control_get,\
0935 .put = snd_ice1712_6fire_control_put,\
0936 .private_value = xshift | (xinvert << 8),\
0937 }
0938
0939 static const struct snd_kcontrol_new snd_ice1712_6fire_controls[] = {
0940 {
0941 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0942 .name = "Analog Input Select",
0943 .info = snd_ice1712_6fire_select_input_info,
0944 .get = snd_ice1712_6fire_select_input_get,
0945 .put = snd_ice1712_6fire_select_input_put,
0946 },
0947 DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 1),
0948
0949 DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0),
0950 DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0),
0951 DMX6FIRE_CONTROL("Breakbox LED", 6, 0),
0952 };
0953
0954
0955 static int snd_ice1712_ews_add_controls(struct snd_ice1712 *ice)
0956 {
0957 unsigned int idx;
0958 int err;
0959
0960
0961 if (ice->cs8427 == NULL) {
0962 err = snd_ice1712_spdif_build_controls(ice);
0963 if (err < 0)
0964 return err;
0965 }
0966
0967
0968 switch (ice->eeprom.subvendor) {
0969 case ICE1712_SUBDEVICE_EWX2496:
0970 case ICE1712_SUBDEVICE_EWS88MT:
0971 case ICE1712_SUBDEVICE_EWS88MT_NEW:
0972 case ICE1712_SUBDEVICE_PHASE88:
0973 case ICE1712_SUBDEVICE_TS88:
0974 case ICE1712_SUBDEVICE_DMX6FIRE:
0975 err = snd_ice1712_akm4xxx_build_controls(ice);
0976 if (err < 0)
0977 return err;
0978 break;
0979 }
0980
0981
0982 switch (ice->eeprom.subvendor) {
0983 case ICE1712_SUBDEVICE_EWX2496:
0984 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ewx2496_controls); idx++) {
0985 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ewx2496_controls[idx], ice));
0986 if (err < 0)
0987 return err;
0988 }
0989 break;
0990 case ICE1712_SUBDEVICE_EWS88MT:
0991 case ICE1712_SUBDEVICE_EWS88MT_NEW:
0992 case ICE1712_SUBDEVICE_PHASE88:
0993 case ICE1712_SUBDEVICE_TS88:
0994 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice));
0995 if (err < 0)
0996 return err;
0997 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense, ice));
0998 if (err < 0)
0999 return err;
1000 break;
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));
1004 if (err < 0)
1005 return err;
1006 }
1007 break;
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));
1011 if (err < 0)
1012 return err;
1013 }
1014 break;
1015 }
1016 return 0;
1017 }
1018
1019
1020
1021 struct snd_ice1712_card_info snd_ice1712_ews_cards[] = {
1022 {
1023 .subvendor = ICE1712_SUBDEVICE_EWX2496,
1024 .name = "TerraTec EWX24/96",
1025 .model = "ewx2496",
1026 .chip_init = snd_ice1712_ews_init,
1027 .build_controls = snd_ice1712_ews_add_controls,
1028 },
1029 {
1030 .subvendor = ICE1712_SUBDEVICE_EWS88MT,
1031 .name = "TerraTec EWS88MT",
1032 .model = "ews88mt",
1033 .chip_init = snd_ice1712_ews_init,
1034 .build_controls = snd_ice1712_ews_add_controls,
1035 },
1036 {
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,
1042 },
1043 {
1044 .subvendor = ICE1712_SUBDEVICE_PHASE88,
1045 .name = "TerraTec Phase88",
1046 .model = "phase88",
1047 .chip_init = snd_ice1712_ews_init,
1048 .build_controls = snd_ice1712_ews_add_controls,
1049 },
1050 {
1051 .subvendor = ICE1712_SUBDEVICE_TS88,
1052 .name = "terrasoniq TS88",
1053 .model = "phase88",
1054 .chip_init = snd_ice1712_ews_init,
1055 .build_controls = snd_ice1712_ews_add_controls,
1056 },
1057 {
1058 .subvendor = ICE1712_SUBDEVICE_EWS88D,
1059 .name = "TerraTec EWS88D",
1060 .model = "ews88d",
1061 .chip_init = snd_ice1712_ews_init,
1062 .build_controls = snd_ice1712_ews_add_controls,
1063 },
1064 {
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,
1073 },
1074 { }
1075 };