blob: ec07136fc288ca349fa2ab18eac27e3a7e7451eb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ALSA driver for ICEnsemble ICE1712 (Envy24)
3 *
4 * Lowlevel functions for Terratec EWS88MT/D, EWX24/96, DMX 6Fire
5 *
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02006 * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * 2002 Takashi Iwai <tiwai@suse.de>
8 *
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.
13 *
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.
18 *
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
22 *
23 */
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/delay.h>
26#include <linux/interrupt.h>
27#include <linux/init.h>
28#include <linux/slab.h>
29#include <sound/core.h>
30#include <sound/cs8427.h>
31#include <sound/asoundef.h>
32
33#include "ice1712.h"
34#include "ews.h"
35
36#define SND_CS8404
37#include <sound/cs8403.h>
38
39enum {
40 EWS_I2C_CS8404 = 0, EWS_I2C_PCF1, EWS_I2C_PCF2,
41 EWS_I2C_88D = 0,
42 EWS_I2C_6FIRE = 0
43};
44
45
Takashi Iwai7cda8ba2008-01-18 13:36:07 +010046/* additional i2c devices for EWS boards */
47struct ews_spec {
48 struct snd_i2c_device *i2cdevs[3];
49};
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051/*
52 * access via i2c mode (for EWX 24/96, EWS 88MT&D)
53 */
54
55/* send SDA and SCL */
Takashi Iwai6ca308d2005-11-17 14:59:52 +010056static void ewx_i2c_setlines(struct snd_i2c_bus *bus, int clk, int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Takashi Iwai6ca308d2005-11-17 14:59:52 +010058 struct snd_ice1712 *ice = bus->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 unsigned char tmp = 0;
60 if (clk)
61 tmp |= ICE1712_EWX2496_SERIAL_CLOCK;
62 if (data)
63 tmp |= ICE1712_EWX2496_SERIAL_DATA;
64 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
65 udelay(5);
66}
67
Takashi Iwai6ca308d2005-11-17 14:59:52 +010068static int ewx_i2c_getclock(struct snd_i2c_bus *bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Takashi Iwai6ca308d2005-11-17 14:59:52 +010070 struct snd_ice1712 *ice = bus->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_CLOCK ? 1 : 0;
72}
73
Takashi Iwai6ca308d2005-11-17 14:59:52 +010074static int ewx_i2c_getdata(struct snd_i2c_bus *bus, int ack)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Takashi Iwai6ca308d2005-11-17 14:59:52 +010076 struct snd_ice1712 *ice = bus->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 int bit;
78 /* set RW pin to low */
79 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_RW);
80 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, 0);
81 if (ack)
82 udelay(5);
83 bit = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_DATA ? 1 : 0;
84 /* set RW pin to high */
85 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ICE1712_EWX2496_RW);
86 /* reset write mask */
87 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_SERIAL_CLOCK);
88 return bit;
89}
90
Takashi Iwai6ca308d2005-11-17 14:59:52 +010091static void ewx_i2c_start(struct snd_i2c_bus *bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
Takashi Iwai6ca308d2005-11-17 14:59:52 +010093 struct snd_ice1712 *ice = bus->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 unsigned char mask;
95
96 snd_ice1712_save_gpio_status(ice);
97 /* set RW high */
98 mask = ICE1712_EWX2496_RW;
99 switch (ice->eeprom.subvendor) {
100 case ICE1712_SUBDEVICE_EWX2496:
101 mask |= ICE1712_EWX2496_AK4524_CS; /* CS high also */
102 break;
103 case ICE1712_SUBDEVICE_DMX6FIRE:
104 mask |= ICE1712_6FIRE_AK4524_CS_MASK; /* CS high also */
105 break;
106 }
107 snd_ice1712_gpio_write_bits(ice, mask, mask);
108}
109
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100110static void ewx_i2c_stop(struct snd_i2c_bus *bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100112 struct snd_ice1712 *ice = bus->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 snd_ice1712_restore_gpio_status(ice);
114}
115
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100116static void ewx_i2c_direction(struct snd_i2c_bus *bus, int clock, int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100118 struct snd_ice1712 *ice = bus->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 unsigned char mask = 0;
120
121 if (clock)
122 mask |= ICE1712_EWX2496_SERIAL_CLOCK; /* write SCL */
123 if (data)
124 mask |= ICE1712_EWX2496_SERIAL_DATA; /* write SDA */
125 ice->gpio.direction &= ~(ICE1712_EWX2496_SERIAL_CLOCK|ICE1712_EWX2496_SERIAL_DATA);
126 ice->gpio.direction |= mask;
127 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio.direction);
128 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~mask);
129}
130
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100131static struct snd_i2c_bit_ops snd_ice1712_ewx_cs8427_bit_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 .start = ewx_i2c_start,
133 .stop = ewx_i2c_stop,
134 .direction = ewx_i2c_direction,
135 .setlines = ewx_i2c_setlines,
136 .getclock = ewx_i2c_getclock,
137 .getdata = ewx_i2c_getdata,
138};
139
140
141/*
142 * AK4524 access
143 */
144
145/* AK4524 chip select; address 0x48 bit 0-3 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100146static int snd_ice1712_ews88mt_chip_select(struct snd_ice1712 *ice, int chip_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100148 struct ews_spec *spec = ice->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 unsigned char data, ndata;
150
Takashi Iwaida3cec32008-08-08 17:12:14 +0200151 if (snd_BUG_ON(chip_mask < 0 || chip_mask > 0x0f))
152 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 snd_i2c_lock(ice->i2c);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100154 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 goto __error;
156 ndata = (data & 0xf0) | chip_mask;
157 if (ndata != data)
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100158 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF2], &ndata, 1)
159 != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 goto __error;
161 snd_i2c_unlock(ice->i2c);
162 return 0;
163
164 __error:
165 snd_i2c_unlock(ice->i2c);
Takashi Iwai6dfb5af2014-02-25 17:16:16 +0100166 dev_err(ice->card->dev,
167 "AK4524 chip select failed, check cable to the front module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return -EIO;
169}
170
171/* start callback for EWS88MT, needs to select a certain chip mask */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100172static void ews88mt_ak4524_lock(struct snd_akm4xxx *ak, int chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100174 struct snd_ice1712 *ice = ak->private_data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 unsigned char tmp;
176 /* assert AK4524 CS */
177 if (snd_ice1712_ews88mt_chip_select(ice, ~(1 << chip) & 0x0f) < 0)
Takashi Iwai6dfb5af2014-02-25 17:16:16 +0100178 dev_err(ice->card->dev, "fatal error (ews88mt chip select)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 snd_ice1712_save_gpio_status(ice);
180 tmp = ICE1712_EWS88_SERIAL_DATA |
181 ICE1712_EWS88_SERIAL_CLOCK |
182 ICE1712_EWS88_RW;
183 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
184 ice->gpio.direction | tmp);
185 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
186}
187
188/* stop callback for EWS88MT, needs to deselect chip mask */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100189static void ews88mt_ak4524_unlock(struct snd_akm4xxx *ak, int chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100191 struct snd_ice1712 *ice = ak->private_data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 snd_ice1712_restore_gpio_status(ice);
193 udelay(1);
194 snd_ice1712_ews88mt_chip_select(ice, 0x0f);
195}
196
197/* start callback for EWX24/96 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100198static void ewx2496_ak4524_lock(struct snd_akm4xxx *ak, int chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100200 struct snd_ice1712 *ice = ak->private_data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 unsigned char tmp;
202 snd_ice1712_save_gpio_status(ice);
203 tmp = ICE1712_EWX2496_SERIAL_DATA |
204 ICE1712_EWX2496_SERIAL_CLOCK |
205 ICE1712_EWX2496_AK4524_CS |
206 ICE1712_EWX2496_RW;
207 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
208 ice->gpio.direction | tmp);
209 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
210}
211
212/* start callback for DMX 6fire */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100213static void dmx6fire_ak4524_lock(struct snd_akm4xxx *ak, int chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
215 struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100216 struct snd_ice1712 *ice = ak->private_data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 unsigned char tmp;
218 snd_ice1712_save_gpio_status(ice);
219 tmp = priv->cs_mask = priv->cs_addr = (1 << chip) & ICE1712_6FIRE_AK4524_CS_MASK;
220 tmp |= ICE1712_6FIRE_SERIAL_DATA |
221 ICE1712_6FIRE_SERIAL_CLOCK |
222 ICE1712_6FIRE_RW;
223 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
224 ice->gpio.direction | tmp);
225 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
226}
227
228/*
229 * CS8404 interface on EWS88MT/D
230 */
231
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100232static void snd_ice1712_ews_cs8404_spdif_write(struct snd_ice1712 *ice, unsigned char bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100234 struct ews_spec *spec = ice->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 unsigned char bytes[2];
236
237 snd_i2c_lock(ice->i2c);
238 switch (ice->eeprom.subvendor) {
239 case ICE1712_SUBDEVICE_EWS88MT:
240 case ICE1712_SUBDEVICE_EWS88MT_NEW:
241 case ICE1712_SUBDEVICE_PHASE88:
Peter Lienigd80fd092008-04-22 17:05:07 +0200242 case ICE1712_SUBDEVICE_TS88:
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100243 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_CS8404], &bits, 1)
244 != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 goto _error;
246 break;
247 case ICE1712_SUBDEVICE_EWS88D:
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100248 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], bytes, 2)
249 != 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 goto _error;
251 if (bits != bytes[1]) {
252 bytes[1] = bits;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100253 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_88D],
254 bytes, 2) != 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 goto _error;
256 }
257 break;
258 }
259 _error:
260 snd_i2c_unlock(ice->i2c);
261}
262
263/*
264 */
265
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100266static void ews88_spdif_default_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
268 snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_bits);
269}
270
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100271static int ews88_spdif_default_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
273 unsigned int val;
274 int change;
275
276 val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
277 spin_lock_irq(&ice->reg_lock);
278 change = ice->spdif.cs8403_bits != val;
279 ice->spdif.cs8403_bits = val;
280 if (change && ice->playback_pro_substream == NULL) {
281 spin_unlock_irq(&ice->reg_lock);
282 snd_ice1712_ews_cs8404_spdif_write(ice, val);
283 } else {
284 spin_unlock_irq(&ice->reg_lock);
285 }
286 return change;
287}
288
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100289static void ews88_spdif_stream_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
291 snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_stream_bits);
292}
293
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100294static int ews88_spdif_stream_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
296 unsigned int val;
297 int change;
298
299 val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
300 spin_lock_irq(&ice->reg_lock);
301 change = ice->spdif.cs8403_stream_bits != val;
302 ice->spdif.cs8403_stream_bits = val;
303 if (change && ice->playback_pro_substream != NULL) {
304 spin_unlock_irq(&ice->reg_lock);
305 snd_ice1712_ews_cs8404_spdif_write(ice, val);
306 } else {
307 spin_unlock_irq(&ice->reg_lock);
308 }
309 return change;
310}
311
312
313/* open callback */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100314static void ews88_open_spdif(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
316 ice->spdif.cs8403_stream_bits = ice->spdif.cs8403_bits;
317}
318
319/* set up SPDIF for EWS88MT / EWS88D */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100320static void ews88_setup_spdif(struct snd_ice1712 *ice, int rate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
322 unsigned long flags;
323 unsigned char tmp;
324 int change;
325
326 spin_lock_irqsave(&ice->reg_lock, flags);
327 tmp = ice->spdif.cs8403_stream_bits;
328 if (tmp & 0x10) /* consumer */
329 tmp &= (tmp & 0x01) ? ~0x06 : ~0x60;
330 switch (rate) {
331 case 32000: tmp |= (tmp & 0x01) ? 0x02 : 0x00; break;
332 case 44100: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
333 case 48000: tmp |= (tmp & 0x01) ? 0x04 : 0x20; break;
334 default: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
335 }
336 change = ice->spdif.cs8403_stream_bits != tmp;
337 ice->spdif.cs8403_stream_bits = tmp;
338 spin_unlock_irqrestore(&ice->reg_lock, flags);
339 if (change)
340 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &ice->spdif.stream_ctl->id);
341 snd_ice1712_ews_cs8404_spdif_write(ice, tmp);
342}
343
344
345/*
346 */
Bill Pembertone23e7a12012-12-06 12:35:10 -0500347static struct snd_akm4xxx akm_ews88mt = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 .num_adcs = 8,
349 .num_dacs = 8,
350 .type = SND_AK4524,
351 .ops = {
352 .lock = ews88mt_ak4524_lock,
353 .unlock = ews88mt_ak4524_unlock
354 }
355};
356
Bill Pembertone23e7a12012-12-06 12:35:10 -0500357static struct snd_ak4xxx_private akm_ews88mt_priv = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 .caddr = 2,
359 .cif = 1, /* CIF high */
360 .data_mask = ICE1712_EWS88_SERIAL_DATA,
361 .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
362 .cs_mask = 0,
363 .cs_addr = 0,
364 .cs_none = 0, /* no chip select on gpio */
365 .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
366 .mask_flags = 0,
367};
368
Bill Pembertone23e7a12012-12-06 12:35:10 -0500369static struct snd_akm4xxx akm_ewx2496 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 .num_adcs = 2,
371 .num_dacs = 2,
372 .type = SND_AK4524,
373 .ops = {
374 .lock = ewx2496_ak4524_lock
375 }
376};
377
Bill Pembertone23e7a12012-12-06 12:35:10 -0500378static struct snd_ak4xxx_private akm_ewx2496_priv = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 .caddr = 2,
380 .cif = 1, /* CIF high */
381 .data_mask = ICE1712_EWS88_SERIAL_DATA,
382 .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
383 .cs_mask = ICE1712_EWX2496_AK4524_CS,
384 .cs_addr = ICE1712_EWX2496_AK4524_CS,
385 .cs_none = 0,
386 .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
387 .mask_flags = 0,
388};
389
Bill Pembertone23e7a12012-12-06 12:35:10 -0500390static struct snd_akm4xxx akm_6fire = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 .num_adcs = 6,
392 .num_dacs = 6,
393 .type = SND_AK4524,
394 .ops = {
395 .lock = dmx6fire_ak4524_lock
396 }
397};
398
Bill Pembertone23e7a12012-12-06 12:35:10 -0500399static struct snd_ak4xxx_private akm_6fire_priv = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 .caddr = 2,
401 .cif = 1, /* CIF high */
402 .data_mask = ICE1712_6FIRE_SERIAL_DATA,
403 .clk_mask = ICE1712_6FIRE_SERIAL_CLOCK,
404 .cs_mask = 0,
405 .cs_addr = 0, /* set later */
406 .cs_none = 0,
407 .add_flags = ICE1712_6FIRE_RW, /* set rw bit high */
408 .mask_flags = 0,
409};
410
411/*
412 * initialize the chip
413 */
414
415/* 6fire specific */
416#define PCF9554_REG_INPUT 0
417#define PCF9554_REG_OUTPUT 1
418#define PCF9554_REG_POLARITY 2
419#define PCF9554_REG_CONFIG 3
420
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100421static int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Bill Pembertone23e7a12012-12-06 12:35:10 -0500423static int snd_ice1712_ews_init(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
425 int err;
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100426 struct snd_akm4xxx *ak;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100427 struct ews_spec *spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429 /* set the analog DACs */
430 switch (ice->eeprom.subvendor) {
431 case ICE1712_SUBDEVICE_EWX2496:
432 ice->num_total_dacs = 2;
433 ice->num_total_adcs = 2;
434 break;
435 case ICE1712_SUBDEVICE_EWS88MT:
436 case ICE1712_SUBDEVICE_EWS88MT_NEW:
437 case ICE1712_SUBDEVICE_PHASE88:
Peter Lienigd80fd092008-04-22 17:05:07 +0200438 case ICE1712_SUBDEVICE_TS88:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 ice->num_total_dacs = 8;
440 ice->num_total_adcs = 8;
441 break;
442 case ICE1712_SUBDEVICE_EWS88D:
443 /* Note: not analog but ADAT I/O */
444 ice->num_total_dacs = 8;
445 ice->num_total_adcs = 8;
446 break;
447 case ICE1712_SUBDEVICE_DMX6FIRE:
448 ice->num_total_dacs = 6;
449 ice->num_total_adcs = 6;
450 break;
451 }
452
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100453 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
454 if (!spec)
455 return -ENOMEM;
456 ice->spec = spec;
457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 /* create i2c */
459 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
Takashi Iwai6dfb5af2014-02-25 17:16:16 +0100460 dev_err(ice->card->dev, "unable to create I2C bus\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 return err;
462 }
463 ice->i2c->private_data = ice;
464 ice->i2c->hw_ops.bit = &snd_ice1712_ewx_cs8427_bit_ops;
465
466 /* create i2c devices */
467 switch (ice->eeprom.subvendor) {
468 case ICE1712_SUBDEVICE_DMX6FIRE:
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100469 err = snd_i2c_device_create(ice->i2c, "PCF9554",
470 ICE1712_6FIRE_PCF9554_ADDR,
471 &spec->i2cdevs[EWS_I2C_6FIRE]);
472 if (err < 0) {
Takashi Iwai6dfb5af2014-02-25 17:16:16 +0100473 dev_err(ice->card->dev,
474 "PCF9554 initialization failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 return err;
476 }
477 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80);
478 break;
479 case ICE1712_SUBDEVICE_EWS88MT:
480 case ICE1712_SUBDEVICE_EWS88MT_NEW:
481 case ICE1712_SUBDEVICE_PHASE88:
Peter Lienigd80fd092008-04-22 17:05:07 +0200482 case ICE1712_SUBDEVICE_TS88:
483
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100484 err = snd_i2c_device_create(ice->i2c, "CS8404",
485 ICE1712_EWS88MT_CS8404_ADDR,
486 &spec->i2cdevs[EWS_I2C_CS8404]);
487 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 return err;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100489 err = snd_i2c_device_create(ice->i2c, "PCF8574 (1st)",
490 ICE1712_EWS88MT_INPUT_ADDR,
491 &spec->i2cdevs[EWS_I2C_PCF1]);
492 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 return err;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100494 err = snd_i2c_device_create(ice->i2c, "PCF8574 (2nd)",
495 ICE1712_EWS88MT_OUTPUT_ADDR,
496 &spec->i2cdevs[EWS_I2C_PCF2]);
497 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 return err;
499 /* Check if the front module is connected */
500 if ((err = snd_ice1712_ews88mt_chip_select(ice, 0x0f)) < 0)
501 return err;
502 break;
503 case ICE1712_SUBDEVICE_EWS88D:
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100504 err = snd_i2c_device_create(ice->i2c, "PCF8575",
505 ICE1712_EWS88D_PCF_ADDR,
506 &spec->i2cdevs[EWS_I2C_88D]);
507 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 return err;
509 break;
510 }
511
512 /* set up SPDIF interface */
513 switch (ice->eeprom.subvendor) {
514 case ICE1712_SUBDEVICE_EWX2496:
515 if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0)
516 return err;
517 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
518 break;
519 case ICE1712_SUBDEVICE_DMX6FIRE:
520 if ((err = snd_ice1712_init_cs8427(ice, ICE1712_6FIRE_CS8427_ADDR)) < 0)
521 return err;
522 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
523 break;
524 case ICE1712_SUBDEVICE_EWS88MT:
525 case ICE1712_SUBDEVICE_EWS88MT_NEW:
526 case ICE1712_SUBDEVICE_PHASE88:
Peter Lienigd80fd092008-04-22 17:05:07 +0200527 case ICE1712_SUBDEVICE_TS88:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 case ICE1712_SUBDEVICE_EWS88D:
529 /* set up CS8404 */
530 ice->spdif.ops.open = ews88_open_spdif;
531 ice->spdif.ops.setup_rate = ews88_setup_spdif;
532 ice->spdif.ops.default_get = ews88_spdif_default_get;
533 ice->spdif.ops.default_put = ews88_spdif_default_put;
534 ice->spdif.ops.stream_get = ews88_spdif_stream_get;
535 ice->spdif.ops.stream_put = ews88_spdif_stream_put;
536 /* Set spdif defaults */
537 snd_ice1712_ews_cs8404_spdif_write(ice, ice->spdif.cs8403_bits);
538 break;
539 }
540
541 /* no analog? */
542 switch (ice->eeprom.subvendor) {
543 case ICE1712_SUBDEVICE_EWS88D:
544 return 0;
545 }
546
547 /* analog section */
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100548 ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 if (! ak)
550 return -ENOMEM;
551 ice->akm_codecs = 1;
552
553 switch (ice->eeprom.subvendor) {
554 case ICE1712_SUBDEVICE_EWS88MT:
555 case ICE1712_SUBDEVICE_EWS88MT_NEW:
556 case ICE1712_SUBDEVICE_PHASE88:
Peter Lienigd80fd092008-04-22 17:05:07 +0200557 case ICE1712_SUBDEVICE_TS88:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice);
559 break;
560 case ICE1712_SUBDEVICE_EWX2496:
561 err = snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, &akm_ewx2496_priv, ice);
562 break;
563 case ICE1712_SUBDEVICE_DMX6FIRE:
564 err = snd_ice1712_akm4xxx_init(ak, &akm_6fire, &akm_6fire_priv, ice);
565 break;
566 default:
567 err = 0;
568 }
569
570 return err;
571}
572
573/*
574 * EWX 24/96 specific controls
575 */
576
577/* i/o sensitivity - this callback is shared among other devices, too */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100578static int snd_ice1712_ewx_io_sense_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Takashi Iwaia2af0502012-10-17 09:21:48 +0200580 static const char * const texts[2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 "+4dBu", "-10dBV",
582 };
Takashi Iwaic4fa2512014-10-20 18:18:33 +0200583 return snd_ctl_enum_info(uinfo, 1, 2, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584}
585
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100586static int snd_ice1712_ewx_io_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100588 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 unsigned char mask = kcontrol->private_value & 0xff;
590
591 snd_ice1712_save_gpio_status(ice);
592 ucontrol->value.enumerated.item[0] = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0;
593 snd_ice1712_restore_gpio_status(ice);
594 return 0;
595}
596
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100597static int snd_ice1712_ewx_io_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100599 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 unsigned char mask = kcontrol->private_value & 0xff;
601 int val, nval;
602
603 if (kcontrol->private_value & (1 << 31))
604 return -EPERM;
605 nval = ucontrol->value.enumerated.item[0] ? mask : 0;
606 snd_ice1712_save_gpio_status(ice);
607 val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
608 nval |= val & ~mask;
609 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, nval);
610 snd_ice1712_restore_gpio_status(ice);
611 return val != nval;
612}
613
Bill Pembertone23e7a12012-12-06 12:35:10 -0500614static struct snd_kcontrol_new snd_ice1712_ewx2496_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 {
616 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
617 .name = "Input Sensitivity Switch",
618 .info = snd_ice1712_ewx_io_sense_info,
619 .get = snd_ice1712_ewx_io_sense_get,
620 .put = snd_ice1712_ewx_io_sense_put,
621 .private_value = ICE1712_EWX2496_AIN_SEL,
622 },
623 {
624 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
625 .name = "Output Sensitivity Switch",
626 .info = snd_ice1712_ewx_io_sense_info,
627 .get = snd_ice1712_ewx_io_sense_get,
628 .put = snd_ice1712_ewx_io_sense_put,
629 .private_value = ICE1712_EWX2496_AOUT_SEL,
630 },
631};
632
633
634/*
635 * EWS88MT specific controls
636 */
637/* analog output sensitivity;; address 0x48 bit 6 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100638static int snd_ice1712_ews88mt_output_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100640 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100641 struct ews_spec *spec = ice->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 unsigned char data;
643
644 snd_i2c_lock(ice->i2c);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100645 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 snd_i2c_unlock(ice->i2c);
647 return -EIO;
648 }
649 snd_i2c_unlock(ice->i2c);
650 ucontrol->value.enumerated.item[0] = data & ICE1712_EWS88MT_OUTPUT_SENSE ? 1 : 0; /* high = -10dBV, low = +4dBu */
651 return 0;
652}
653
654/* analog output sensitivity;; address 0x48 bit 6 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100655static int snd_ice1712_ews88mt_output_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100657 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100658 struct ews_spec *spec = ice->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 unsigned char data, ndata;
660
661 snd_i2c_lock(ice->i2c);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100662 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 snd_i2c_unlock(ice->i2c);
664 return -EIO;
665 }
666 ndata = (data & ~ICE1712_EWS88MT_OUTPUT_SENSE) | (ucontrol->value.enumerated.item[0] ? ICE1712_EWS88MT_OUTPUT_SENSE : 0);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100667 if (ndata != data && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF2],
668 &ndata, 1) != 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 snd_i2c_unlock(ice->i2c);
670 return -EIO;
671 }
672 snd_i2c_unlock(ice->i2c);
673 return ndata != data;
674}
675
676/* analog input sensitivity; address 0x46 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100677static int snd_ice1712_ews88mt_input_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100679 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100680 struct ews_spec *spec = ice->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
682 unsigned char data;
683
Takashi Iwaida3cec32008-08-08 17:12:14 +0200684 if (snd_BUG_ON(channel < 0 || channel > 7))
685 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 snd_i2c_lock(ice->i2c);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100687 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 snd_i2c_unlock(ice->i2c);
689 return -EIO;
690 }
691 /* reversed; high = +4dBu, low = -10dBV */
692 ucontrol->value.enumerated.item[0] = data & (1 << channel) ? 0 : 1;
693 snd_i2c_unlock(ice->i2c);
694 return 0;
695}
696
697/* analog output sensitivity; address 0x46 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100698static int snd_ice1712_ews88mt_input_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100700 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100701 struct ews_spec *spec = ice->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
703 unsigned char data, ndata;
704
Takashi Iwaida3cec32008-08-08 17:12:14 +0200705 if (snd_BUG_ON(channel < 0 || channel > 7))
706 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 snd_i2c_lock(ice->i2c);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100708 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 snd_i2c_unlock(ice->i2c);
710 return -EIO;
711 }
712 ndata = (data & ~(1 << channel)) | (ucontrol->value.enumerated.item[0] ? 0 : (1 << channel));
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100713 if (ndata != data && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF1],
714 &ndata, 1) != 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 snd_i2c_unlock(ice->i2c);
716 return -EIO;
717 }
718 snd_i2c_unlock(ice->i2c);
719 return ndata != data;
720}
721
Bhumika Goyalf3b827e2017-02-20 00:18:09 +0530722static const struct snd_kcontrol_new snd_ice1712_ews88mt_input_sense = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
724 .name = "Input Sensitivity Switch",
725 .info = snd_ice1712_ewx_io_sense_info,
726 .get = snd_ice1712_ews88mt_input_sense_get,
727 .put = snd_ice1712_ews88mt_input_sense_put,
728 .count = 8,
729};
730
Bhumika Goyalf3b827e2017-02-20 00:18:09 +0530731static const struct snd_kcontrol_new snd_ice1712_ews88mt_output_sense = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
733 .name = "Output Sensitivity Switch",
734 .info = snd_ice1712_ewx_io_sense_info,
735 .get = snd_ice1712_ews88mt_output_sense_get,
736 .put = snd_ice1712_ews88mt_output_sense_put,
737};
738
739
740/*
741 * EWS88D specific controls
742 */
743
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200744#define snd_ice1712_ews88d_control_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100746static int snd_ice1712_ews88d_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100748 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100749 struct ews_spec *spec = ice->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 int shift = kcontrol->private_value & 0xff;
751 int invert = (kcontrol->private_value >> 8) & 1;
752 unsigned char data[2];
753
754 snd_i2c_lock(ice->i2c);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100755 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 snd_i2c_unlock(ice->i2c);
757 return -EIO;
758 }
759 snd_i2c_unlock(ice->i2c);
760 data[0] = (data[shift >> 3] >> (shift & 7)) & 0x01;
761 if (invert)
762 data[0] ^= 0x01;
763 ucontrol->value.integer.value[0] = data[0];
764 return 0;
765}
766
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100767static int snd_ice1712_ews88d_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100769 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100770 struct ews_spec *spec = ice->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 int shift = kcontrol->private_value & 0xff;
772 int invert = (kcontrol->private_value >> 8) & 1;
773 unsigned char data[2], ndata[2];
774 int change;
775
776 snd_i2c_lock(ice->i2c);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100777 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 snd_i2c_unlock(ice->i2c);
779 return -EIO;
780 }
781 ndata[shift >> 3] = data[shift >> 3] & ~(1 << (shift & 7));
782 if (invert) {
783 if (! ucontrol->value.integer.value[0])
784 ndata[shift >> 3] |= (1 << (shift & 7));
785 } else {
786 if (ucontrol->value.integer.value[0])
787 ndata[shift >> 3] |= (1 << (shift & 7));
788 }
789 change = (data[shift >> 3] != ndata[shift >> 3]);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100790 if (change &&
791 snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 snd_i2c_unlock(ice->i2c);
793 return -EIO;
794 }
795 snd_i2c_unlock(ice->i2c);
796 return change;
797}
798
799#define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
800{ .iface = xiface,\
801 .name = xname,\
802 .access = xaccess,\
803 .info = snd_ice1712_ews88d_control_info,\
804 .get = snd_ice1712_ews88d_control_get,\
805 .put = snd_ice1712_ews88d_control_put,\
806 .private_value = xshift | (xinvert << 8),\
807}
808
Bill Pembertone23e7a12012-12-06 12:35:10 -0500809static struct snd_kcontrol_new snd_ice1712_ews88d_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, 1, 0), /* inverted */
811 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Output Optical", 1, 0, 0),
812 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT External Master Clock", 2, 0, 0),
813 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "Enable ADAT", 3, 0, 0),
814 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Through", 4, 1, 0),
815};
816
817
818/*
819 * DMX 6Fire specific controls
820 */
821
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100822static int snd_ice1712_6fire_read_pca(struct snd_ice1712 *ice, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
824 unsigned char byte;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100825 struct ews_spec *spec = ice->spec;
826
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 snd_i2c_lock(ice->i2c);
828 byte = reg;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100829 snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 byte = 0;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100831 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 snd_i2c_unlock(ice->i2c);
Takashi Iwai6dfb5af2014-02-25 17:16:16 +0100833 dev_err(ice->card->dev, "cannot read pca\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 return -EIO;
835 }
836 snd_i2c_unlock(ice->i2c);
837 return byte;
838}
839
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100840static int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
842 unsigned char bytes[2];
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100843 struct ews_spec *spec = ice->spec;
844
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 snd_i2c_lock(ice->i2c);
846 bytes[0] = reg;
847 bytes[1] = data;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100848 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_6FIRE], bytes, 2) != 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 snd_i2c_unlock(ice->i2c);
850 return -EIO;
851 }
852 snd_i2c_unlock(ice->i2c);
853 return 0;
854}
855
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200856#define snd_ice1712_6fire_control_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100858static int snd_ice1712_6fire_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100860 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 int shift = kcontrol->private_value & 0xff;
862 int invert = (kcontrol->private_value >> 8) & 1;
863 int data;
864
865 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
866 return data;
867 data = (data >> shift) & 1;
868 if (invert)
869 data ^= 1;
870 ucontrol->value.integer.value[0] = data;
871 return 0;
872}
873
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100874static int snd_ice1712_6fire_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100876 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 int shift = kcontrol->private_value & 0xff;
878 int invert = (kcontrol->private_value >> 8) & 1;
879 int data, ndata;
880
881 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
882 return data;
883 ndata = data & ~(1 << shift);
884 if (ucontrol->value.integer.value[0])
885 ndata |= (1 << shift);
886 if (invert)
887 ndata ^= (1 << shift);
888 if (data != ndata) {
889 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
890 return 1;
891 }
892 return 0;
893}
894
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100895static int snd_ice1712_6fire_select_input_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896{
Takashi Iwaia2af0502012-10-17 09:21:48 +0200897 static const char * const texts[4] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 "Internal", "Front Input", "Rear Input", "Wave Table"
899 };
Takashi Iwaic4fa2512014-10-20 18:18:33 +0200900 return snd_ctl_enum_info(uinfo, 1, 4, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901}
902
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100903static int snd_ice1712_6fire_select_input_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100905 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 int data;
907
908 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
909 return data;
910 ucontrol->value.integer.value[0] = data & 3;
911 return 0;
912}
913
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100914static int snd_ice1712_6fire_select_input_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100916 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 int data, ndata;
918
919 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
920 return data;
921 ndata = data & ~3;
922 ndata |= (ucontrol->value.integer.value[0] & 3);
923 if (data != ndata) {
924 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
925 return 1;
926 }
927 return 0;
928}
929
930
931#define DMX6FIRE_CONTROL(xname, xshift, xinvert) \
932{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
933 .name = xname,\
934 .info = snd_ice1712_6fire_control_info,\
935 .get = snd_ice1712_6fire_control_get,\
936 .put = snd_ice1712_6fire_control_put,\
937 .private_value = xshift | (xinvert << 8),\
938}
939
Bill Pembertone23e7a12012-12-06 12:35:10 -0500940static struct snd_kcontrol_new snd_ice1712_6fire_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 {
942 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
943 .name = "Analog Input Select",
944 .info = snd_ice1712_6fire_select_input_info,
945 .get = snd_ice1712_6fire_select_input_get,
946 .put = snd_ice1712_6fire_select_input_put,
947 },
Takashi Iwai6a81dbf2005-11-22 14:33:27 +0100948 DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 // DMX6FIRE_CONTROL("Master Clock Select", 3, 0),
950 DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0),
951 DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0),
952 DMX6FIRE_CONTROL("Breakbox LED", 6, 0),
953};
954
955
Bill Pembertone23e7a12012-12-06 12:35:10 -0500956static int snd_ice1712_ews_add_controls(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957{
958 unsigned int idx;
959 int err;
960
961 /* all terratec cards have spdif, but cs8427 module builds it's own controls */
962 if (ice->cs8427 == NULL) {
963 err = snd_ice1712_spdif_build_controls(ice);
964 if (err < 0)
965 return err;
966 }
967
968 /* ak4524 controls */
969 switch (ice->eeprom.subvendor) {
970 case ICE1712_SUBDEVICE_EWX2496:
971 case ICE1712_SUBDEVICE_EWS88MT:
972 case ICE1712_SUBDEVICE_EWS88MT_NEW:
973 case ICE1712_SUBDEVICE_PHASE88:
Peter Lienigd80fd092008-04-22 17:05:07 +0200974 case ICE1712_SUBDEVICE_TS88:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 case ICE1712_SUBDEVICE_DMX6FIRE:
976 err = snd_ice1712_akm4xxx_build_controls(ice);
977 if (err < 0)
978 return err;
979 break;
980 }
981
982 /* card specific controls */
983 switch (ice->eeprom.subvendor) {
984 case ICE1712_SUBDEVICE_EWX2496:
985 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ewx2496_controls); idx++) {
986 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ewx2496_controls[idx], ice));
987 if (err < 0)
988 return err;
989 }
990 break;
991 case ICE1712_SUBDEVICE_EWS88MT:
992 case ICE1712_SUBDEVICE_EWS88MT_NEW:
993 case ICE1712_SUBDEVICE_PHASE88:
Peter Lienigd80fd092008-04-22 17:05:07 +0200994 case ICE1712_SUBDEVICE_TS88:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice));
996 if (err < 0)
997 return err;
998 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense, ice));
999 if (err < 0)
1000 return err;
1001 break;
1002 case ICE1712_SUBDEVICE_EWS88D:
1003 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ews88d_controls); idx++) {
1004 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_controls[idx], ice));
1005 if (err < 0)
1006 return err;
1007 }
1008 break;
1009 case ICE1712_SUBDEVICE_DMX6FIRE:
1010 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_6fire_controls); idx++) {
1011 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_6fire_controls[idx], ice));
1012 if (err < 0)
1013 return err;
1014 }
1015 break;
1016 }
1017 return 0;
1018}
1019
1020
1021/* entry point */
Bill Pembertone23e7a12012-12-06 12:35:10 -05001022struct snd_ice1712_card_info snd_ice1712_ews_cards[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 {
1024 .subvendor = ICE1712_SUBDEVICE_EWX2496,
1025 .name = "TerraTec EWX24/96",
1026 .model = "ewx2496",
1027 .chip_init = snd_ice1712_ews_init,
1028 .build_controls = snd_ice1712_ews_add_controls,
1029 },
1030 {
1031 .subvendor = ICE1712_SUBDEVICE_EWS88MT,
1032 .name = "TerraTec EWS88MT",
1033 .model = "ews88mt",
1034 .chip_init = snd_ice1712_ews_init,
1035 .build_controls = snd_ice1712_ews_add_controls,
1036 },
1037 {
1038 .subvendor = ICE1712_SUBDEVICE_EWS88MT_NEW,
1039 .name = "TerraTec EWS88MT",
1040 .model = "ews88mt_new",
1041 .chip_init = snd_ice1712_ews_init,
1042 .build_controls = snd_ice1712_ews_add_controls,
1043 },
1044 {
1045 .subvendor = ICE1712_SUBDEVICE_PHASE88,
1046 .name = "TerraTec Phase88",
1047 .model = "phase88",
1048 .chip_init = snd_ice1712_ews_init,
1049 .build_controls = snd_ice1712_ews_add_controls,
1050 },
1051 {
Peter Lienigd80fd092008-04-22 17:05:07 +02001052 .subvendor = ICE1712_SUBDEVICE_TS88,
1053 .name = "terrasoniq TS88",
1054 .model = "phase88",
1055 .chip_init = snd_ice1712_ews_init,
1056 .build_controls = snd_ice1712_ews_add_controls,
1057 },
1058 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 .subvendor = ICE1712_SUBDEVICE_EWS88D,
1060 .name = "TerraTec EWS88D",
1061 .model = "ews88d",
1062 .chip_init = snd_ice1712_ews_init,
1063 .build_controls = snd_ice1712_ews_add_controls,
1064 },
1065 {
1066 .subvendor = ICE1712_SUBDEVICE_DMX6FIRE,
1067 .name = "TerraTec DMX6Fire",
1068 .model = "dmx6fire",
1069 .chip_init = snd_ice1712_ews_init,
1070 .build_controls = snd_ice1712_ews_add_controls,
Alan Horstmann3bef2292006-04-26 18:13:59 +02001071 .mpu401_1_name = "MIDI-Front DMX6fire",
1072 .mpu401_2_name = "Wavetable DMX6fire",
Alan Horstmanncf78ee22006-05-26 17:19:34 +02001073 .mpu401_2_info_flags = MPU401_INFO_OUTPUT,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 },
1075 { } /* terminator */
1076};