blob: 013fc4f0482282fce0fb25da5a0a63b2012c6956 [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 <asm/io.h>
26#include <linux/delay.h>
27#include <linux/interrupt.h>
28#include <linux/init.h>
29#include <linux/slab.h>
30#include <sound/core.h>
31#include <sound/cs8427.h>
32#include <sound/asoundef.h>
33
34#include "ice1712.h"
35#include "ews.h"
36
37#define SND_CS8404
38#include <sound/cs8403.h>
39
40enum {
41 EWS_I2C_CS8404 = 0, EWS_I2C_PCF1, EWS_I2C_PCF2,
42 EWS_I2C_88D = 0,
43 EWS_I2C_6FIRE = 0
44};
45
46
Takashi Iwai7cda8ba2008-01-18 13:36:07 +010047/* additional i2c devices for EWS boards */
48struct ews_spec {
49 struct snd_i2c_device *i2cdevs[3];
50};
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052/*
53 * access via i2c mode (for EWX 24/96, EWS 88MT&D)
54 */
55
56/* send SDA and SCL */
Takashi Iwai6ca308d2005-11-17 14:59:52 +010057static void ewx_i2c_setlines(struct snd_i2c_bus *bus, int clk, int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
Takashi Iwai6ca308d2005-11-17 14:59:52 +010059 struct snd_ice1712 *ice = bus->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 unsigned char tmp = 0;
61 if (clk)
62 tmp |= ICE1712_EWX2496_SERIAL_CLOCK;
63 if (data)
64 tmp |= ICE1712_EWX2496_SERIAL_DATA;
65 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
66 udelay(5);
67}
68
Takashi Iwai6ca308d2005-11-17 14:59:52 +010069static int ewx_i2c_getclock(struct snd_i2c_bus *bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
Takashi Iwai6ca308d2005-11-17 14:59:52 +010071 struct snd_ice1712 *ice = bus->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_CLOCK ? 1 : 0;
73}
74
Takashi Iwai6ca308d2005-11-17 14:59:52 +010075static int ewx_i2c_getdata(struct snd_i2c_bus *bus, int ack)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Takashi Iwai6ca308d2005-11-17 14:59:52 +010077 struct snd_ice1712 *ice = bus->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 int bit;
79 /* set RW pin to low */
80 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_RW);
81 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, 0);
82 if (ack)
83 udelay(5);
84 bit = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_DATA ? 1 : 0;
85 /* set RW pin to high */
86 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ICE1712_EWX2496_RW);
87 /* reset write mask */
88 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_SERIAL_CLOCK);
89 return bit;
90}
91
Takashi Iwai6ca308d2005-11-17 14:59:52 +010092static void ewx_i2c_start(struct snd_i2c_bus *bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
Takashi Iwai6ca308d2005-11-17 14:59:52 +010094 struct snd_ice1712 *ice = bus->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 unsigned char mask;
96
97 snd_ice1712_save_gpio_status(ice);
98 /* set RW high */
99 mask = ICE1712_EWX2496_RW;
100 switch (ice->eeprom.subvendor) {
101 case ICE1712_SUBDEVICE_EWX2496:
102 mask |= ICE1712_EWX2496_AK4524_CS; /* CS high also */
103 break;
104 case ICE1712_SUBDEVICE_DMX6FIRE:
105 mask |= ICE1712_6FIRE_AK4524_CS_MASK; /* CS high also */
106 break;
107 }
108 snd_ice1712_gpio_write_bits(ice, mask, mask);
109}
110
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100111static void ewx_i2c_stop(struct snd_i2c_bus *bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100113 struct snd_ice1712 *ice = bus->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 snd_ice1712_restore_gpio_status(ice);
115}
116
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100117static void ewx_i2c_direction(struct snd_i2c_bus *bus, int clock, int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100119 struct snd_ice1712 *ice = bus->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 unsigned char mask = 0;
121
122 if (clock)
123 mask |= ICE1712_EWX2496_SERIAL_CLOCK; /* write SCL */
124 if (data)
125 mask |= ICE1712_EWX2496_SERIAL_DATA; /* write SDA */
126 ice->gpio.direction &= ~(ICE1712_EWX2496_SERIAL_CLOCK|ICE1712_EWX2496_SERIAL_DATA);
127 ice->gpio.direction |= mask;
128 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio.direction);
129 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~mask);
130}
131
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100132static struct snd_i2c_bit_ops snd_ice1712_ewx_cs8427_bit_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 .start = ewx_i2c_start,
134 .stop = ewx_i2c_stop,
135 .direction = ewx_i2c_direction,
136 .setlines = ewx_i2c_setlines,
137 .getclock = ewx_i2c_getclock,
138 .getdata = ewx_i2c_getdata,
139};
140
141
142/*
143 * AK4524 access
144 */
145
146/* AK4524 chip select; address 0x48 bit 0-3 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100147static int snd_ice1712_ews88mt_chip_select(struct snd_ice1712 *ice, int chip_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100149 struct ews_spec *spec = ice->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 unsigned char data, ndata;
151
152 snd_assert(chip_mask >= 0 && chip_mask <= 0x0f, return -EINVAL);
153 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);
166 snd_printk(KERN_ERR "AK4524 chip select failed, check cable to the front module\n");
167 return -EIO;
168}
169
170/* start callback for EWS88MT, needs to select a certain chip mask */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100171static void ews88mt_ak4524_lock(struct snd_akm4xxx *ak, int chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100173 struct snd_ice1712 *ice = ak->private_data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 unsigned char tmp;
175 /* assert AK4524 CS */
176 if (snd_ice1712_ews88mt_chip_select(ice, ~(1 << chip) & 0x0f) < 0)
177 snd_printk(KERN_ERR "fatal error (ews88mt chip select)\n");
178 snd_ice1712_save_gpio_status(ice);
179 tmp = ICE1712_EWS88_SERIAL_DATA |
180 ICE1712_EWS88_SERIAL_CLOCK |
181 ICE1712_EWS88_RW;
182 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
183 ice->gpio.direction | tmp);
184 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
185}
186
187/* stop callback for EWS88MT, needs to deselect chip mask */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100188static void ews88mt_ak4524_unlock(struct snd_akm4xxx *ak, int chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100190 struct snd_ice1712 *ice = ak->private_data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 snd_ice1712_restore_gpio_status(ice);
192 udelay(1);
193 snd_ice1712_ews88mt_chip_select(ice, 0x0f);
194}
195
196/* start callback for EWX24/96 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100197static void ewx2496_ak4524_lock(struct snd_akm4xxx *ak, int chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100199 struct snd_ice1712 *ice = ak->private_data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 unsigned char tmp;
201 snd_ice1712_save_gpio_status(ice);
202 tmp = ICE1712_EWX2496_SERIAL_DATA |
203 ICE1712_EWX2496_SERIAL_CLOCK |
204 ICE1712_EWX2496_AK4524_CS |
205 ICE1712_EWX2496_RW;
206 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
207 ice->gpio.direction | tmp);
208 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
209}
210
211/* start callback for DMX 6fire */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100212static void dmx6fire_ak4524_lock(struct snd_akm4xxx *ak, int chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
214 struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100215 struct snd_ice1712 *ice = ak->private_data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 unsigned char tmp;
217 snd_ice1712_save_gpio_status(ice);
218 tmp = priv->cs_mask = priv->cs_addr = (1 << chip) & ICE1712_6FIRE_AK4524_CS_MASK;
219 tmp |= ICE1712_6FIRE_SERIAL_DATA |
220 ICE1712_6FIRE_SERIAL_CLOCK |
221 ICE1712_6FIRE_RW;
222 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
223 ice->gpio.direction | tmp);
224 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
225}
226
227/*
228 * CS8404 interface on EWS88MT/D
229 */
230
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100231static void snd_ice1712_ews_cs8404_spdif_write(struct snd_ice1712 *ice, unsigned char bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100233 struct ews_spec *spec = ice->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 unsigned char bytes[2];
235
236 snd_i2c_lock(ice->i2c);
237 switch (ice->eeprom.subvendor) {
238 case ICE1712_SUBDEVICE_EWS88MT:
239 case ICE1712_SUBDEVICE_EWS88MT_NEW:
240 case ICE1712_SUBDEVICE_PHASE88:
Peter Lienigd80fd092008-04-22 17:05:07 +0200241 case ICE1712_SUBDEVICE_TS88:
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100242 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_CS8404], &bits, 1)
243 != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 goto _error;
245 break;
246 case ICE1712_SUBDEVICE_EWS88D:
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100247 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], bytes, 2)
248 != 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 goto _error;
250 if (bits != bytes[1]) {
251 bytes[1] = bits;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100252 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_88D],
253 bytes, 2) != 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 goto _error;
255 }
256 break;
257 }
258 _error:
259 snd_i2c_unlock(ice->i2c);
260}
261
262/*
263 */
264
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100265static void ews88_spdif_default_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
267 snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_bits);
268}
269
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100270static int ews88_spdif_default_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271{
272 unsigned int val;
273 int change;
274
275 val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
276 spin_lock_irq(&ice->reg_lock);
277 change = ice->spdif.cs8403_bits != val;
278 ice->spdif.cs8403_bits = val;
279 if (change && ice->playback_pro_substream == NULL) {
280 spin_unlock_irq(&ice->reg_lock);
281 snd_ice1712_ews_cs8404_spdif_write(ice, val);
282 } else {
283 spin_unlock_irq(&ice->reg_lock);
284 }
285 return change;
286}
287
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100288static void ews88_spdif_stream_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
290 snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_stream_bits);
291}
292
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100293static int ews88_spdif_stream_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
295 unsigned int val;
296 int change;
297
298 val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
299 spin_lock_irq(&ice->reg_lock);
300 change = ice->spdif.cs8403_stream_bits != val;
301 ice->spdif.cs8403_stream_bits = val;
302 if (change && ice->playback_pro_substream != NULL) {
303 spin_unlock_irq(&ice->reg_lock);
304 snd_ice1712_ews_cs8404_spdif_write(ice, val);
305 } else {
306 spin_unlock_irq(&ice->reg_lock);
307 }
308 return change;
309}
310
311
312/* open callback */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100313static void ews88_open_spdif(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
315 ice->spdif.cs8403_stream_bits = ice->spdif.cs8403_bits;
316}
317
318/* set up SPDIF for EWS88MT / EWS88D */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100319static void ews88_setup_spdif(struct snd_ice1712 *ice, int rate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
321 unsigned long flags;
322 unsigned char tmp;
323 int change;
324
325 spin_lock_irqsave(&ice->reg_lock, flags);
326 tmp = ice->spdif.cs8403_stream_bits;
327 if (tmp & 0x10) /* consumer */
328 tmp &= (tmp & 0x01) ? ~0x06 : ~0x60;
329 switch (rate) {
330 case 32000: tmp |= (tmp & 0x01) ? 0x02 : 0x00; break;
331 case 44100: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
332 case 48000: tmp |= (tmp & 0x01) ? 0x04 : 0x20; break;
333 default: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
334 }
335 change = ice->spdif.cs8403_stream_bits != tmp;
336 ice->spdif.cs8403_stream_bits = tmp;
337 spin_unlock_irqrestore(&ice->reg_lock, flags);
338 if (change)
339 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &ice->spdif.stream_ctl->id);
340 snd_ice1712_ews_cs8404_spdif_write(ice, tmp);
341}
342
343
344/*
345 */
Ralf Baechlebf748ed2007-03-13 15:31:08 +0100346static struct snd_akm4xxx akm_ews88mt __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 .num_adcs = 8,
348 .num_dacs = 8,
349 .type = SND_AK4524,
350 .ops = {
351 .lock = ews88mt_ak4524_lock,
352 .unlock = ews88mt_ak4524_unlock
353 }
354};
355
Ralf Baechlebf748ed2007-03-13 15:31:08 +0100356static struct snd_ak4xxx_private akm_ews88mt_priv __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 .caddr = 2,
358 .cif = 1, /* CIF high */
359 .data_mask = ICE1712_EWS88_SERIAL_DATA,
360 .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
361 .cs_mask = 0,
362 .cs_addr = 0,
363 .cs_none = 0, /* no chip select on gpio */
364 .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
365 .mask_flags = 0,
366};
367
Ralf Baechlebf748ed2007-03-13 15:31:08 +0100368static struct snd_akm4xxx akm_ewx2496 __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 .num_adcs = 2,
370 .num_dacs = 2,
371 .type = SND_AK4524,
372 .ops = {
373 .lock = ewx2496_ak4524_lock
374 }
375};
376
Ralf Baechlebf748ed2007-03-13 15:31:08 +0100377static struct snd_ak4xxx_private akm_ewx2496_priv __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 .caddr = 2,
379 .cif = 1, /* CIF high */
380 .data_mask = ICE1712_EWS88_SERIAL_DATA,
381 .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
382 .cs_mask = ICE1712_EWX2496_AK4524_CS,
383 .cs_addr = ICE1712_EWX2496_AK4524_CS,
384 .cs_none = 0,
385 .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
386 .mask_flags = 0,
387};
388
Ralf Baechlebf748ed2007-03-13 15:31:08 +0100389static struct snd_akm4xxx akm_6fire __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 .num_adcs = 6,
391 .num_dacs = 6,
392 .type = SND_AK4524,
393 .ops = {
394 .lock = dmx6fire_ak4524_lock
395 }
396};
397
Ralf Baechlebf748ed2007-03-13 15:31:08 +0100398static struct snd_ak4xxx_private akm_6fire_priv __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 .caddr = 2,
400 .cif = 1, /* CIF high */
401 .data_mask = ICE1712_6FIRE_SERIAL_DATA,
402 .clk_mask = ICE1712_6FIRE_SERIAL_CLOCK,
403 .cs_mask = 0,
404 .cs_addr = 0, /* set later */
405 .cs_none = 0,
406 .add_flags = ICE1712_6FIRE_RW, /* set rw bit high */
407 .mask_flags = 0,
408};
409
410/*
411 * initialize the chip
412 */
413
414/* 6fire specific */
415#define PCF9554_REG_INPUT 0
416#define PCF9554_REG_OUTPUT 1
417#define PCF9554_REG_POLARITY 2
418#define PCF9554_REG_CONFIG 3
419
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100420static int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100422static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
424 int err;
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100425 struct snd_akm4xxx *ak;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100426 struct ews_spec *spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
428 /* set the analog DACs */
429 switch (ice->eeprom.subvendor) {
430 case ICE1712_SUBDEVICE_EWX2496:
431 ice->num_total_dacs = 2;
432 ice->num_total_adcs = 2;
433 break;
434 case ICE1712_SUBDEVICE_EWS88MT:
435 case ICE1712_SUBDEVICE_EWS88MT_NEW:
436 case ICE1712_SUBDEVICE_PHASE88:
Peter Lienigd80fd092008-04-22 17:05:07 +0200437 case ICE1712_SUBDEVICE_TS88:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 ice->num_total_dacs = 8;
439 ice->num_total_adcs = 8;
440 break;
441 case ICE1712_SUBDEVICE_EWS88D:
442 /* Note: not analog but ADAT I/O */
443 ice->num_total_dacs = 8;
444 ice->num_total_adcs = 8;
445 break;
446 case ICE1712_SUBDEVICE_DMX6FIRE:
447 ice->num_total_dacs = 6;
448 ice->num_total_adcs = 6;
449 break;
450 }
451
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100452 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
453 if (!spec)
454 return -ENOMEM;
455 ice->spec = spec;
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 /* create i2c */
458 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
Takashi Iwai99b359b2005-10-20 18:26:44 +0200459 snd_printk(KERN_ERR "unable to create I2C bus\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 return err;
461 }
462 ice->i2c->private_data = ice;
463 ice->i2c->hw_ops.bit = &snd_ice1712_ewx_cs8427_bit_ops;
464
465 /* create i2c devices */
466 switch (ice->eeprom.subvendor) {
467 case ICE1712_SUBDEVICE_DMX6FIRE:
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100468 err = snd_i2c_device_create(ice->i2c, "PCF9554",
469 ICE1712_6FIRE_PCF9554_ADDR,
470 &spec->i2cdevs[EWS_I2C_6FIRE]);
471 if (err < 0) {
Takashi Iwai99b359b2005-10-20 18:26:44 +0200472 snd_printk(KERN_ERR "PCF9554 initialization failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 return err;
474 }
475 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80);
476 break;
477 case ICE1712_SUBDEVICE_EWS88MT:
478 case ICE1712_SUBDEVICE_EWS88MT_NEW:
479 case ICE1712_SUBDEVICE_PHASE88:
Peter Lienigd80fd092008-04-22 17:05:07 +0200480 case ICE1712_SUBDEVICE_TS88:
481
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100482 err = snd_i2c_device_create(ice->i2c, "CS8404",
483 ICE1712_EWS88MT_CS8404_ADDR,
484 &spec->i2cdevs[EWS_I2C_CS8404]);
485 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 return err;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100487 err = snd_i2c_device_create(ice->i2c, "PCF8574 (1st)",
488 ICE1712_EWS88MT_INPUT_ADDR,
489 &spec->i2cdevs[EWS_I2C_PCF1]);
490 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 return err;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100492 err = snd_i2c_device_create(ice->i2c, "PCF8574 (2nd)",
493 ICE1712_EWS88MT_OUTPUT_ADDR,
494 &spec->i2cdevs[EWS_I2C_PCF2]);
495 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 return err;
497 /* Check if the front module is connected */
498 if ((err = snd_ice1712_ews88mt_chip_select(ice, 0x0f)) < 0)
499 return err;
500 break;
501 case ICE1712_SUBDEVICE_EWS88D:
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100502 err = snd_i2c_device_create(ice->i2c, "PCF8575",
503 ICE1712_EWS88D_PCF_ADDR,
504 &spec->i2cdevs[EWS_I2C_88D]);
505 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 return err;
507 break;
508 }
509
510 /* set up SPDIF interface */
511 switch (ice->eeprom.subvendor) {
512 case ICE1712_SUBDEVICE_EWX2496:
513 if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0)
514 return err;
515 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
516 break;
517 case ICE1712_SUBDEVICE_DMX6FIRE:
518 if ((err = snd_ice1712_init_cs8427(ice, ICE1712_6FIRE_CS8427_ADDR)) < 0)
519 return err;
520 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
521 break;
522 case ICE1712_SUBDEVICE_EWS88MT:
523 case ICE1712_SUBDEVICE_EWS88MT_NEW:
524 case ICE1712_SUBDEVICE_PHASE88:
Peter Lienigd80fd092008-04-22 17:05:07 +0200525 case ICE1712_SUBDEVICE_TS88:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 case ICE1712_SUBDEVICE_EWS88D:
527 /* set up CS8404 */
528 ice->spdif.ops.open = ews88_open_spdif;
529 ice->spdif.ops.setup_rate = ews88_setup_spdif;
530 ice->spdif.ops.default_get = ews88_spdif_default_get;
531 ice->spdif.ops.default_put = ews88_spdif_default_put;
532 ice->spdif.ops.stream_get = ews88_spdif_stream_get;
533 ice->spdif.ops.stream_put = ews88_spdif_stream_put;
534 /* Set spdif defaults */
535 snd_ice1712_ews_cs8404_spdif_write(ice, ice->spdif.cs8403_bits);
536 break;
537 }
538
539 /* no analog? */
540 switch (ice->eeprom.subvendor) {
541 case ICE1712_SUBDEVICE_EWS88D:
542 return 0;
543 }
544
545 /* analog section */
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100546 ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 if (! ak)
548 return -ENOMEM;
549 ice->akm_codecs = 1;
550
551 switch (ice->eeprom.subvendor) {
552 case ICE1712_SUBDEVICE_EWS88MT:
553 case ICE1712_SUBDEVICE_EWS88MT_NEW:
554 case ICE1712_SUBDEVICE_PHASE88:
Peter Lienigd80fd092008-04-22 17:05:07 +0200555 case ICE1712_SUBDEVICE_TS88:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice);
557 break;
558 case ICE1712_SUBDEVICE_EWX2496:
559 err = snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, &akm_ewx2496_priv, ice);
560 break;
561 case ICE1712_SUBDEVICE_DMX6FIRE:
562 err = snd_ice1712_akm4xxx_init(ak, &akm_6fire, &akm_6fire_priv, ice);
563 break;
564 default:
565 err = 0;
566 }
567
568 return err;
569}
570
571/*
572 * EWX 24/96 specific controls
573 */
574
575/* i/o sensitivity - this callback is shared among other devices, too */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100576static int snd_ice1712_ewx_io_sense_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 static char *texts[2] = {
579 "+4dBu", "-10dBV",
580 };
581 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
582 uinfo->count = 1;
583 uinfo->value.enumerated.items = 2;
584 if (uinfo->value.enumerated.item >= 2)
585 uinfo->value.enumerated.item = 1;
586 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
587 return 0;
588}
589
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100590static int snd_ice1712_ewx_io_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100592 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 unsigned char mask = kcontrol->private_value & 0xff;
594
595 snd_ice1712_save_gpio_status(ice);
596 ucontrol->value.enumerated.item[0] = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0;
597 snd_ice1712_restore_gpio_status(ice);
598 return 0;
599}
600
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100601static int snd_ice1712_ewx_io_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100603 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 unsigned char mask = kcontrol->private_value & 0xff;
605 int val, nval;
606
607 if (kcontrol->private_value & (1 << 31))
608 return -EPERM;
609 nval = ucontrol->value.enumerated.item[0] ? mask : 0;
610 snd_ice1712_save_gpio_status(ice);
611 val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
612 nval |= val & ~mask;
613 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, nval);
614 snd_ice1712_restore_gpio_status(ice);
615 return val != nval;
616}
617
Ralf Baechlebf748ed2007-03-13 15:31:08 +0100618static struct snd_kcontrol_new snd_ice1712_ewx2496_controls[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 {
620 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
621 .name = "Input Sensitivity Switch",
622 .info = snd_ice1712_ewx_io_sense_info,
623 .get = snd_ice1712_ewx_io_sense_get,
624 .put = snd_ice1712_ewx_io_sense_put,
625 .private_value = ICE1712_EWX2496_AIN_SEL,
626 },
627 {
628 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
629 .name = "Output Sensitivity Switch",
630 .info = snd_ice1712_ewx_io_sense_info,
631 .get = snd_ice1712_ewx_io_sense_get,
632 .put = snd_ice1712_ewx_io_sense_put,
633 .private_value = ICE1712_EWX2496_AOUT_SEL,
634 },
635};
636
637
638/*
639 * EWS88MT specific controls
640 */
641/* analog output sensitivity;; address 0x48 bit 6 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100642static int snd_ice1712_ews88mt_output_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100644 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100645 struct ews_spec *spec = ice->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 unsigned char data;
647
648 snd_i2c_lock(ice->i2c);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100649 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 snd_i2c_unlock(ice->i2c);
651 return -EIO;
652 }
653 snd_i2c_unlock(ice->i2c);
654 ucontrol->value.enumerated.item[0] = data & ICE1712_EWS88MT_OUTPUT_SENSE ? 1 : 0; /* high = -10dBV, low = +4dBu */
655 return 0;
656}
657
658/* analog output sensitivity;; address 0x48 bit 6 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100659static int snd_ice1712_ews88mt_output_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100661 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100662 struct ews_spec *spec = ice->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 unsigned char data, ndata;
664
665 snd_i2c_lock(ice->i2c);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100666 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 snd_i2c_unlock(ice->i2c);
668 return -EIO;
669 }
670 ndata = (data & ~ICE1712_EWS88MT_OUTPUT_SENSE) | (ucontrol->value.enumerated.item[0] ? ICE1712_EWS88MT_OUTPUT_SENSE : 0);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100671 if (ndata != data && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF2],
672 &ndata, 1) != 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 snd_i2c_unlock(ice->i2c);
674 return -EIO;
675 }
676 snd_i2c_unlock(ice->i2c);
677 return ndata != data;
678}
679
680/* analog input sensitivity; address 0x46 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100681static int snd_ice1712_ews88mt_input_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100683 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100684 struct ews_spec *spec = ice->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
686 unsigned char data;
687
688 snd_assert(channel >= 0 && channel <= 7, return 0);
689 snd_i2c_lock(ice->i2c);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100690 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 snd_i2c_unlock(ice->i2c);
692 return -EIO;
693 }
694 /* reversed; high = +4dBu, low = -10dBV */
695 ucontrol->value.enumerated.item[0] = data & (1 << channel) ? 0 : 1;
696 snd_i2c_unlock(ice->i2c);
697 return 0;
698}
699
700/* analog output sensitivity; address 0x46 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100701static int snd_ice1712_ews88mt_input_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100703 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100704 struct ews_spec *spec = ice->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
706 unsigned char data, ndata;
707
708 snd_assert(channel >= 0 && channel <= 7, return 0);
709 snd_i2c_lock(ice->i2c);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100710 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 snd_i2c_unlock(ice->i2c);
712 return -EIO;
713 }
714 ndata = (data & ~(1 << channel)) | (ucontrol->value.enumerated.item[0] ? 0 : (1 << channel));
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100715 if (ndata != data && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF1],
716 &ndata, 1) != 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 snd_i2c_unlock(ice->i2c);
718 return -EIO;
719 }
720 snd_i2c_unlock(ice->i2c);
721 return ndata != data;
722}
723
Ralf Baechlebf748ed2007-03-13 15:31:08 +0100724static struct snd_kcontrol_new snd_ice1712_ews88mt_input_sense __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
726 .name = "Input Sensitivity Switch",
727 .info = snd_ice1712_ewx_io_sense_info,
728 .get = snd_ice1712_ews88mt_input_sense_get,
729 .put = snd_ice1712_ews88mt_input_sense_put,
730 .count = 8,
731};
732
Ralf Baechlebf748ed2007-03-13 15:31:08 +0100733static struct snd_kcontrol_new snd_ice1712_ews88mt_output_sense __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
735 .name = "Output Sensitivity Switch",
736 .info = snd_ice1712_ewx_io_sense_info,
737 .get = snd_ice1712_ews88mt_output_sense_get,
738 .put = snd_ice1712_ews88mt_output_sense_put,
739};
740
741
742/*
743 * EWS88D specific controls
744 */
745
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200746#define snd_ice1712_ews88d_control_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100748static int snd_ice1712_ews88d_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100750 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100751 struct ews_spec *spec = ice->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 int shift = kcontrol->private_value & 0xff;
753 int invert = (kcontrol->private_value >> 8) & 1;
754 unsigned char data[2];
755
756 snd_i2c_lock(ice->i2c);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100757 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 snd_i2c_unlock(ice->i2c);
759 return -EIO;
760 }
761 snd_i2c_unlock(ice->i2c);
762 data[0] = (data[shift >> 3] >> (shift & 7)) & 0x01;
763 if (invert)
764 data[0] ^= 0x01;
765 ucontrol->value.integer.value[0] = data[0];
766 return 0;
767}
768
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100769static int snd_ice1712_ews88d_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100771 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100772 struct ews_spec *spec = ice->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 int shift = kcontrol->private_value & 0xff;
774 int invert = (kcontrol->private_value >> 8) & 1;
775 unsigned char data[2], ndata[2];
776 int change;
777
778 snd_i2c_lock(ice->i2c);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100779 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 snd_i2c_unlock(ice->i2c);
781 return -EIO;
782 }
783 ndata[shift >> 3] = data[shift >> 3] & ~(1 << (shift & 7));
784 if (invert) {
785 if (! ucontrol->value.integer.value[0])
786 ndata[shift >> 3] |= (1 << (shift & 7));
787 } else {
788 if (ucontrol->value.integer.value[0])
789 ndata[shift >> 3] |= (1 << (shift & 7));
790 }
791 change = (data[shift >> 3] != ndata[shift >> 3]);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100792 if (change &&
793 snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 snd_i2c_unlock(ice->i2c);
795 return -EIO;
796 }
797 snd_i2c_unlock(ice->i2c);
798 return change;
799}
800
801#define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
802{ .iface = xiface,\
803 .name = xname,\
804 .access = xaccess,\
805 .info = snd_ice1712_ews88d_control_info,\
806 .get = snd_ice1712_ews88d_control_get,\
807 .put = snd_ice1712_ews88d_control_put,\
808 .private_value = xshift | (xinvert << 8),\
809}
810
Ralf Baechlebf748ed2007-03-13 15:31:08 +0100811static struct snd_kcontrol_new snd_ice1712_ews88d_controls[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, 1, 0), /* inverted */
813 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Output Optical", 1, 0, 0),
814 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT External Master Clock", 2, 0, 0),
815 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "Enable ADAT", 3, 0, 0),
816 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Through", 4, 1, 0),
817};
818
819
820/*
821 * DMX 6Fire specific controls
822 */
823
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100824static int snd_ice1712_6fire_read_pca(struct snd_ice1712 *ice, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825{
826 unsigned char byte;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100827 struct ews_spec *spec = ice->spec;
828
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 snd_i2c_lock(ice->i2c);
830 byte = reg;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100831 snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 byte = 0;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100833 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 snd_i2c_unlock(ice->i2c);
Takashi Iwai99b359b2005-10-20 18:26:44 +0200835 printk(KERN_ERR "cannot read pca\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 return -EIO;
837 }
838 snd_i2c_unlock(ice->i2c);
839 return byte;
840}
841
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100842static int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
844 unsigned char bytes[2];
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100845 struct ews_spec *spec = ice->spec;
846
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 snd_i2c_lock(ice->i2c);
848 bytes[0] = reg;
849 bytes[1] = data;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100850 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_6FIRE], bytes, 2) != 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 snd_i2c_unlock(ice->i2c);
852 return -EIO;
853 }
854 snd_i2c_unlock(ice->i2c);
855 return 0;
856}
857
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200858#define snd_ice1712_6fire_control_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100860static int snd_ice1712_6fire_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100862 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 int shift = kcontrol->private_value & 0xff;
864 int invert = (kcontrol->private_value >> 8) & 1;
865 int data;
866
867 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
868 return data;
869 data = (data >> shift) & 1;
870 if (invert)
871 data ^= 1;
872 ucontrol->value.integer.value[0] = data;
873 return 0;
874}
875
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100876static int snd_ice1712_6fire_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100878 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 int shift = kcontrol->private_value & 0xff;
880 int invert = (kcontrol->private_value >> 8) & 1;
881 int data, ndata;
882
883 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
884 return data;
885 ndata = data & ~(1 << shift);
886 if (ucontrol->value.integer.value[0])
887 ndata |= (1 << shift);
888 if (invert)
889 ndata ^= (1 << shift);
890 if (data != ndata) {
891 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
892 return 1;
893 }
894 return 0;
895}
896
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100897static int snd_ice1712_6fire_select_input_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898{
899 static char *texts[4] = {
900 "Internal", "Front Input", "Rear Input", "Wave Table"
901 };
902 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
903 uinfo->count = 1;
904 uinfo->value.enumerated.items = 4;
905 if (uinfo->value.enumerated.item >= 4)
906 uinfo->value.enumerated.item = 1;
907 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
908 return 0;
909}
910
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100911static int snd_ice1712_6fire_select_input_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100913 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 int data;
915
916 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
917 return data;
918 ucontrol->value.integer.value[0] = data & 3;
919 return 0;
920}
921
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100922static int snd_ice1712_6fire_select_input_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100924 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 int data, ndata;
926
927 if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
928 return data;
929 ndata = data & ~3;
930 ndata |= (ucontrol->value.integer.value[0] & 3);
931 if (data != ndata) {
932 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
933 return 1;
934 }
935 return 0;
936}
937
938
939#define DMX6FIRE_CONTROL(xname, xshift, xinvert) \
940{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
941 .name = xname,\
942 .info = snd_ice1712_6fire_control_info,\
943 .get = snd_ice1712_6fire_control_get,\
944 .put = snd_ice1712_6fire_control_put,\
945 .private_value = xshift | (xinvert << 8),\
946}
947
Ralf Baechlebf748ed2007-03-13 15:31:08 +0100948static struct snd_kcontrol_new snd_ice1712_6fire_controls[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 {
950 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
951 .name = "Analog Input Select",
952 .info = snd_ice1712_6fire_select_input_info,
953 .get = snd_ice1712_6fire_select_input_get,
954 .put = snd_ice1712_6fire_select_input_put,
955 },
Takashi Iwai6a81dbf2005-11-22 14:33:27 +0100956 DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 // DMX6FIRE_CONTROL("Master Clock Select", 3, 0),
958 DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0),
959 DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0),
960 DMX6FIRE_CONTROL("Breakbox LED", 6, 0),
961};
962
963
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100964static int __devinit snd_ice1712_ews_add_controls(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965{
966 unsigned int idx;
967 int err;
968
969 /* all terratec cards have spdif, but cs8427 module builds it's own controls */
970 if (ice->cs8427 == NULL) {
971 err = snd_ice1712_spdif_build_controls(ice);
972 if (err < 0)
973 return err;
974 }
975
976 /* ak4524 controls */
977 switch (ice->eeprom.subvendor) {
978 case ICE1712_SUBDEVICE_EWX2496:
979 case ICE1712_SUBDEVICE_EWS88MT:
980 case ICE1712_SUBDEVICE_EWS88MT_NEW:
981 case ICE1712_SUBDEVICE_PHASE88:
Peter Lienigd80fd092008-04-22 17:05:07 +0200982 case ICE1712_SUBDEVICE_TS88:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 case ICE1712_SUBDEVICE_DMX6FIRE:
984 err = snd_ice1712_akm4xxx_build_controls(ice);
985 if (err < 0)
986 return err;
987 break;
988 }
989
990 /* card specific controls */
991 switch (ice->eeprom.subvendor) {
992 case ICE1712_SUBDEVICE_EWX2496:
993 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ewx2496_controls); idx++) {
994 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ewx2496_controls[idx], ice));
995 if (err < 0)
996 return err;
997 }
998 break;
999 case ICE1712_SUBDEVICE_EWS88MT:
1000 case ICE1712_SUBDEVICE_EWS88MT_NEW:
1001 case ICE1712_SUBDEVICE_PHASE88:
Peter Lienigd80fd092008-04-22 17:05:07 +02001002 case ICE1712_SUBDEVICE_TS88:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice));
1004 if (err < 0)
1005 return err;
1006 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense, ice));
1007 if (err < 0)
1008 return err;
1009 break;
1010 case ICE1712_SUBDEVICE_EWS88D:
1011 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ews88d_controls); idx++) {
1012 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_controls[idx], ice));
1013 if (err < 0)
1014 return err;
1015 }
1016 break;
1017 case ICE1712_SUBDEVICE_DMX6FIRE:
1018 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_6fire_controls); idx++) {
1019 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_6fire_controls[idx], ice));
1020 if (err < 0)
1021 return err;
1022 }
1023 break;
1024 }
1025 return 0;
1026}
1027
1028
1029/* entry point */
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001030struct snd_ice1712_card_info snd_ice1712_ews_cards[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 {
1032 .subvendor = ICE1712_SUBDEVICE_EWX2496,
1033 .name = "TerraTec EWX24/96",
1034 .model = "ewx2496",
1035 .chip_init = snd_ice1712_ews_init,
1036 .build_controls = snd_ice1712_ews_add_controls,
1037 },
1038 {
1039 .subvendor = ICE1712_SUBDEVICE_EWS88MT,
1040 .name = "TerraTec EWS88MT",
1041 .model = "ews88mt",
1042 .chip_init = snd_ice1712_ews_init,
1043 .build_controls = snd_ice1712_ews_add_controls,
1044 },
1045 {
1046 .subvendor = ICE1712_SUBDEVICE_EWS88MT_NEW,
1047 .name = "TerraTec EWS88MT",
1048 .model = "ews88mt_new",
1049 .chip_init = snd_ice1712_ews_init,
1050 .build_controls = snd_ice1712_ews_add_controls,
1051 },
1052 {
1053 .subvendor = ICE1712_SUBDEVICE_PHASE88,
1054 .name = "TerraTec Phase88",
1055 .model = "phase88",
1056 .chip_init = snd_ice1712_ews_init,
1057 .build_controls = snd_ice1712_ews_add_controls,
1058 },
1059 {
Peter Lienigd80fd092008-04-22 17:05:07 +02001060 .subvendor = ICE1712_SUBDEVICE_TS88,
1061 .name = "terrasoniq TS88",
1062 .model = "phase88",
1063 .chip_init = snd_ice1712_ews_init,
1064 .build_controls = snd_ice1712_ews_add_controls,
1065 },
1066 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 .subvendor = ICE1712_SUBDEVICE_EWS88D,
1068 .name = "TerraTec EWS88D",
1069 .model = "ews88d",
1070 .chip_init = snd_ice1712_ews_init,
1071 .build_controls = snd_ice1712_ews_add_controls,
1072 },
1073 {
1074 .subvendor = ICE1712_SUBDEVICE_DMX6FIRE,
1075 .name = "TerraTec DMX6Fire",
1076 .model = "dmx6fire",
1077 .chip_init = snd_ice1712_ews_init,
1078 .build_controls = snd_ice1712_ews_add_controls,
Alan Horstmann3bef2292006-04-26 18:13:59 +02001079 .mpu401_1_name = "MIDI-Front DMX6fire",
1080 .mpu401_2_name = "Wavetable DMX6fire",
Alan Horstmanncf78ee22006-05-26 17:19:34 +02001081 .mpu401_2_info_flags = MPU401_INFO_OUTPUT,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 },
1083 { } /* terminator */
1084};