Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * ALSA driver for ICEnsemble ICE1712 (Envy24) | |
3 | * | |
4 | * Lowlevel functions for Terratec EWS88MT/D, EWX24/96, DMX 6Fire | |
5 | * | |
c1017a4c | 6 | * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz> |
1da177e4 LT |
7 | * 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 | ||
1da177e4 LT |
25 | #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 | ||
40 | enum { | |
41 | EWS_I2C_CS8404 = 0, EWS_I2C_PCF1, EWS_I2C_PCF2, | |
42 | EWS_I2C_88D = 0, | |
43 | EWS_I2C_6FIRE = 0 | |
44 | }; | |
45 | ||
46 | ||
7cda8ba9 TI |
47 | /* additional i2c devices for EWS boards */ |
48 | struct ews_spec { | |
49 | struct snd_i2c_device *i2cdevs[3]; | |
50 | }; | |
51 | ||
1da177e4 LT |
52 | /* |
53 | * access via i2c mode (for EWX 24/96, EWS 88MT&D) | |
54 | */ | |
55 | ||
56 | /* send SDA and SCL */ | |
6ca308d4 | 57 | static void ewx_i2c_setlines(struct snd_i2c_bus *bus, int clk, int data) |
1da177e4 | 58 | { |
6ca308d4 | 59 | struct snd_ice1712 *ice = bus->private_data; |
1da177e4 LT |
60 | 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 | ||
6ca308d4 | 69 | static int ewx_i2c_getclock(struct snd_i2c_bus *bus) |
1da177e4 | 70 | { |
6ca308d4 | 71 | struct snd_ice1712 *ice = bus->private_data; |
1da177e4 LT |
72 | return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_CLOCK ? 1 : 0; |
73 | } | |
74 | ||
6ca308d4 | 75 | static int ewx_i2c_getdata(struct snd_i2c_bus *bus, int ack) |
1da177e4 | 76 | { |
6ca308d4 | 77 | struct snd_ice1712 *ice = bus->private_data; |
1da177e4 LT |
78 | 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 | ||
6ca308d4 | 92 | static void ewx_i2c_start(struct snd_i2c_bus *bus) |
1da177e4 | 93 | { |
6ca308d4 | 94 | struct snd_ice1712 *ice = bus->private_data; |
1da177e4 LT |
95 | 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 | ||
6ca308d4 | 111 | static void ewx_i2c_stop(struct snd_i2c_bus *bus) |
1da177e4 | 112 | { |
6ca308d4 | 113 | struct snd_ice1712 *ice = bus->private_data; |
1da177e4 LT |
114 | snd_ice1712_restore_gpio_status(ice); |
115 | } | |
116 | ||
6ca308d4 | 117 | static void ewx_i2c_direction(struct snd_i2c_bus *bus, int clock, int data) |
1da177e4 | 118 | { |
6ca308d4 | 119 | struct snd_ice1712 *ice = bus->private_data; |
1da177e4 LT |
120 | 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 | ||
6ca308d4 | 132 | static struct snd_i2c_bit_ops snd_ice1712_ewx_cs8427_bit_ops = { |
1da177e4 LT |
133 | .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 */ | |
6ca308d4 | 147 | static int snd_ice1712_ews88mt_chip_select(struct snd_ice1712 *ice, int chip_mask) |
1da177e4 | 148 | { |
7cda8ba9 | 149 | struct ews_spec *spec = ice->spec; |
1da177e4 LT |
150 | unsigned char data, ndata; |
151 | ||
da3cec35 TI |
152 | if (snd_BUG_ON(chip_mask < 0 || chip_mask > 0x0f)) |
153 | return -EINVAL; | |
1da177e4 | 154 | snd_i2c_lock(ice->i2c); |
7cda8ba9 | 155 | if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) |
1da177e4 LT |
156 | goto __error; |
157 | ndata = (data & 0xf0) | chip_mask; | |
158 | if (ndata != data) | |
7cda8ba9 TI |
159 | if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF2], &ndata, 1) |
160 | != 1) | |
1da177e4 LT |
161 | goto __error; |
162 | snd_i2c_unlock(ice->i2c); | |
163 | return 0; | |
164 | ||
165 | __error: | |
166 | snd_i2c_unlock(ice->i2c); | |
167 | snd_printk(KERN_ERR "AK4524 chip select failed, check cable to the front module\n"); | |
168 | return -EIO; | |
169 | } | |
170 | ||
171 | /* start callback for EWS88MT, needs to select a certain chip mask */ | |
6ca308d4 | 172 | static void ews88mt_ak4524_lock(struct snd_akm4xxx *ak, int chip) |
1da177e4 | 173 | { |
6ca308d4 | 174 | struct snd_ice1712 *ice = ak->private_data[0]; |
1da177e4 LT |
175 | unsigned char tmp; |
176 | /* assert AK4524 CS */ | |
177 | if (snd_ice1712_ews88mt_chip_select(ice, ~(1 << chip) & 0x0f) < 0) | |
178 | snd_printk(KERN_ERR "fatal error (ews88mt chip select)\n"); | |
179 | 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 */ | |
6ca308d4 | 189 | static void ews88mt_ak4524_unlock(struct snd_akm4xxx *ak, int chip) |
1da177e4 | 190 | { |
6ca308d4 | 191 | struct snd_ice1712 *ice = ak->private_data[0]; |
1da177e4 LT |
192 | 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 */ | |
6ca308d4 | 198 | static void ewx2496_ak4524_lock(struct snd_akm4xxx *ak, int chip) |
1da177e4 | 199 | { |
6ca308d4 | 200 | struct snd_ice1712 *ice = ak->private_data[0]; |
1da177e4 LT |
201 | 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 */ | |
6ca308d4 | 213 | static void dmx6fire_ak4524_lock(struct snd_akm4xxx *ak, int chip) |
1da177e4 LT |
214 | { |
215 | struct snd_ak4xxx_private *priv = (void *)ak->private_value[0]; | |
6ca308d4 | 216 | struct snd_ice1712 *ice = ak->private_data[0]; |
1da177e4 LT |
217 | 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 | ||
6ca308d4 | 232 | static void snd_ice1712_ews_cs8404_spdif_write(struct snd_ice1712 *ice, unsigned char bits) |
1da177e4 | 233 | { |
7cda8ba9 | 234 | struct ews_spec *spec = ice->spec; |
1da177e4 LT |
235 | 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: | |
d80fd093 | 242 | case ICE1712_SUBDEVICE_TS88: |
7cda8ba9 TI |
243 | if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_CS8404], &bits, 1) |
244 | != 1) | |
1da177e4 LT |
245 | goto _error; |
246 | break; | |
247 | case ICE1712_SUBDEVICE_EWS88D: | |
7cda8ba9 TI |
248 | if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], bytes, 2) |
249 | != 2) | |
1da177e4 LT |
250 | goto _error; |
251 | if (bits != bytes[1]) { | |
252 | bytes[1] = bits; | |
7cda8ba9 TI |
253 | if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_88D], |
254 | bytes, 2) != 2) | |
1da177e4 LT |
255 | goto _error; |
256 | } | |
257 | break; | |
258 | } | |
259 | _error: | |
260 | snd_i2c_unlock(ice->i2c); | |
261 | } | |
262 | ||
263 | /* | |
264 | */ | |
265 | ||
6ca308d4 | 266 | static void ews88_spdif_default_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol) |
1da177e4 LT |
267 | { |
268 | snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_bits); | |
269 | } | |
270 | ||
6ca308d4 | 271 | static int ews88_spdif_default_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol) |
1da177e4 LT |
272 | { |
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 | ||
6ca308d4 | 289 | static void ews88_spdif_stream_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol) |
1da177e4 LT |
290 | { |
291 | snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_stream_bits); | |
292 | } | |
293 | ||
6ca308d4 | 294 | static int ews88_spdif_stream_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol) |
1da177e4 LT |
295 | { |
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 */ | |
6ca308d4 | 314 | static void ews88_open_spdif(struct snd_ice1712 *ice, struct snd_pcm_substream *substream) |
1da177e4 LT |
315 | { |
316 | ice->spdif.cs8403_stream_bits = ice->spdif.cs8403_bits; | |
317 | } | |
318 | ||
319 | /* set up SPDIF for EWS88MT / EWS88D */ | |
6ca308d4 | 320 | static void ews88_setup_spdif(struct snd_ice1712 *ice, int rate) |
1da177e4 LT |
321 | { |
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 | */ | |
bf748ed7 | 347 | static struct snd_akm4xxx akm_ews88mt __devinitdata = { |
1da177e4 LT |
348 | .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 | ||
bf748ed7 | 357 | static struct snd_ak4xxx_private akm_ews88mt_priv __devinitdata = { |
1da177e4 LT |
358 | .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 | ||
bf748ed7 | 369 | static struct snd_akm4xxx akm_ewx2496 __devinitdata = { |
1da177e4 LT |
370 | .num_adcs = 2, |
371 | .num_dacs = 2, | |
372 | .type = SND_AK4524, | |
373 | .ops = { | |
374 | .lock = ewx2496_ak4524_lock | |
375 | } | |
376 | }; | |
377 | ||
bf748ed7 | 378 | static struct snd_ak4xxx_private akm_ewx2496_priv __devinitdata = { |
1da177e4 LT |
379 | .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 | ||
bf748ed7 | 390 | static struct snd_akm4xxx akm_6fire __devinitdata = { |
1da177e4 LT |
391 | .num_adcs = 6, |
392 | .num_dacs = 6, | |
393 | .type = SND_AK4524, | |
394 | .ops = { | |
395 | .lock = dmx6fire_ak4524_lock | |
396 | } | |
397 | }; | |
398 | ||
bf748ed7 | 399 | static struct snd_ak4xxx_private akm_6fire_priv __devinitdata = { |
1da177e4 LT |
400 | .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 | ||
6ca308d4 | 421 | static int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data); |
1da177e4 | 422 | |
6ca308d4 | 423 | static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice) |
1da177e4 LT |
424 | { |
425 | int err; | |
6ca308d4 | 426 | struct snd_akm4xxx *ak; |
7cda8ba9 | 427 | struct ews_spec *spec; |
1da177e4 LT |
428 | |
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: | |
d80fd093 | 438 | case ICE1712_SUBDEVICE_TS88: |
1da177e4 LT |
439 | 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 | ||
7cda8ba9 TI |
453 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
454 | if (!spec) | |
455 | return -ENOMEM; | |
456 | ice->spec = spec; | |
457 | ||
1da177e4 LT |
458 | /* create i2c */ |
459 | if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) { | |
99b359ba | 460 | snd_printk(KERN_ERR "unable to create I2C bus\n"); |
1da177e4 LT |
461 | 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: | |
7cda8ba9 TI |
469 | err = snd_i2c_device_create(ice->i2c, "PCF9554", |
470 | ICE1712_6FIRE_PCF9554_ADDR, | |
471 | &spec->i2cdevs[EWS_I2C_6FIRE]); | |
472 | if (err < 0) { | |
99b359ba | 473 | snd_printk(KERN_ERR "PCF9554 initialization failed\n"); |
1da177e4 LT |
474 | return err; |
475 | } | |
476 | snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80); | |
477 | break; | |
478 | case ICE1712_SUBDEVICE_EWS88MT: | |
479 | case ICE1712_SUBDEVICE_EWS88MT_NEW: | |
480 | case ICE1712_SUBDEVICE_PHASE88: | |
d80fd093 PL |
481 | case ICE1712_SUBDEVICE_TS88: |
482 | ||
7cda8ba9 TI |
483 | err = snd_i2c_device_create(ice->i2c, "CS8404", |
484 | ICE1712_EWS88MT_CS8404_ADDR, | |
485 | &spec->i2cdevs[EWS_I2C_CS8404]); | |
486 | if (err < 0) | |
1da177e4 | 487 | return err; |
7cda8ba9 TI |
488 | err = snd_i2c_device_create(ice->i2c, "PCF8574 (1st)", |
489 | ICE1712_EWS88MT_INPUT_ADDR, | |
490 | &spec->i2cdevs[EWS_I2C_PCF1]); | |
491 | if (err < 0) | |
1da177e4 | 492 | return err; |
7cda8ba9 TI |
493 | err = snd_i2c_device_create(ice->i2c, "PCF8574 (2nd)", |
494 | ICE1712_EWS88MT_OUTPUT_ADDR, | |
495 | &spec->i2cdevs[EWS_I2C_PCF2]); | |
496 | if (err < 0) | |
1da177e4 LT |
497 | return err; |
498 | /* Check if the front module is connected */ | |
499 | if ((err = snd_ice1712_ews88mt_chip_select(ice, 0x0f)) < 0) | |
500 | return err; | |
501 | break; | |
502 | case ICE1712_SUBDEVICE_EWS88D: | |
7cda8ba9 TI |
503 | err = snd_i2c_device_create(ice->i2c, "PCF8575", |
504 | ICE1712_EWS88D_PCF_ADDR, | |
505 | &spec->i2cdevs[EWS_I2C_88D]); | |
506 | if (err < 0) | |
1da177e4 LT |
507 | return err; |
508 | break; | |
509 | } | |
510 | ||
511 | /* set up SPDIF interface */ | |
512 | switch (ice->eeprom.subvendor) { | |
513 | case ICE1712_SUBDEVICE_EWX2496: | |
514 | if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0) | |
515 | return err; | |
516 | snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR); | |
517 | break; | |
518 | case ICE1712_SUBDEVICE_DMX6FIRE: | |
519 | if ((err = snd_ice1712_init_cs8427(ice, ICE1712_6FIRE_CS8427_ADDR)) < 0) | |
520 | return err; | |
521 | snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR); | |
522 | break; | |
523 | case ICE1712_SUBDEVICE_EWS88MT: | |
524 | case ICE1712_SUBDEVICE_EWS88MT_NEW: | |
525 | case ICE1712_SUBDEVICE_PHASE88: | |
d80fd093 | 526 | case ICE1712_SUBDEVICE_TS88: |
1da177e4 LT |
527 | case ICE1712_SUBDEVICE_EWS88D: |
528 | /* set up CS8404 */ | |
529 | ice->spdif.ops.open = ews88_open_spdif; | |
530 | ice->spdif.ops.setup_rate = ews88_setup_spdif; | |
531 | ice->spdif.ops.default_get = ews88_spdif_default_get; | |
532 | ice->spdif.ops.default_put = ews88_spdif_default_put; | |
533 | ice->spdif.ops.stream_get = ews88_spdif_stream_get; | |
534 | ice->spdif.ops.stream_put = ews88_spdif_stream_put; | |
535 | /* Set spdif defaults */ | |
536 | snd_ice1712_ews_cs8404_spdif_write(ice, ice->spdif.cs8403_bits); | |
537 | break; | |
538 | } | |
539 | ||
540 | /* no analog? */ | |
541 | switch (ice->eeprom.subvendor) { | |
542 | case ICE1712_SUBDEVICE_EWS88D: | |
543 | return 0; | |
544 | } | |
545 | ||
546 | /* analog section */ | |
7cda8ba9 | 547 | ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL); |
1da177e4 LT |
548 | if (! ak) |
549 | return -ENOMEM; | |
550 | ice->akm_codecs = 1; | |
551 | ||
552 | switch (ice->eeprom.subvendor) { | |
553 | case ICE1712_SUBDEVICE_EWS88MT: | |
554 | case ICE1712_SUBDEVICE_EWS88MT_NEW: | |
555 | case ICE1712_SUBDEVICE_PHASE88: | |
d80fd093 | 556 | case ICE1712_SUBDEVICE_TS88: |
1da177e4 LT |
557 | err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice); |
558 | break; | |
559 | case ICE1712_SUBDEVICE_EWX2496: | |
560 | err = snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, &akm_ewx2496_priv, ice); | |
561 | break; | |
562 | case ICE1712_SUBDEVICE_DMX6FIRE: | |
563 | err = snd_ice1712_akm4xxx_init(ak, &akm_6fire, &akm_6fire_priv, ice); | |
564 | break; | |
565 | default: | |
566 | err = 0; | |
567 | } | |
568 | ||
569 | return err; | |
570 | } | |
571 | ||
572 | /* | |
573 | * EWX 24/96 specific controls | |
574 | */ | |
575 | ||
576 | /* i/o sensitivity - this callback is shared among other devices, too */ | |
6ca308d4 | 577 | static int snd_ice1712_ewx_io_sense_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ |
1da177e4 LT |
578 | |
579 | static char *texts[2] = { | |
580 | "+4dBu", "-10dBV", | |
581 | }; | |
582 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | |
583 | uinfo->count = 1; | |
584 | uinfo->value.enumerated.items = 2; | |
585 | if (uinfo->value.enumerated.item >= 2) | |
586 | uinfo->value.enumerated.item = 1; | |
587 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); | |
588 | return 0; | |
589 | } | |
590 | ||
6ca308d4 | 591 | static int snd_ice1712_ewx_io_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 592 | { |
6ca308d4 | 593 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
594 | unsigned char mask = kcontrol->private_value & 0xff; |
595 | ||
596 | snd_ice1712_save_gpio_status(ice); | |
597 | ucontrol->value.enumerated.item[0] = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0; | |
598 | snd_ice1712_restore_gpio_status(ice); | |
599 | return 0; | |
600 | } | |
601 | ||
6ca308d4 | 602 | static int snd_ice1712_ewx_io_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 603 | { |
6ca308d4 | 604 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
605 | unsigned char mask = kcontrol->private_value & 0xff; |
606 | int val, nval; | |
607 | ||
608 | if (kcontrol->private_value & (1 << 31)) | |
609 | return -EPERM; | |
610 | nval = ucontrol->value.enumerated.item[0] ? mask : 0; | |
611 | snd_ice1712_save_gpio_status(ice); | |
612 | val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA); | |
613 | nval |= val & ~mask; | |
614 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, nval); | |
615 | snd_ice1712_restore_gpio_status(ice); | |
616 | return val != nval; | |
617 | } | |
618 | ||
bf748ed7 | 619 | static struct snd_kcontrol_new snd_ice1712_ewx2496_controls[] __devinitdata = { |
1da177e4 LT |
620 | { |
621 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
622 | .name = "Input Sensitivity Switch", | |
623 | .info = snd_ice1712_ewx_io_sense_info, | |
624 | .get = snd_ice1712_ewx_io_sense_get, | |
625 | .put = snd_ice1712_ewx_io_sense_put, | |
626 | .private_value = ICE1712_EWX2496_AIN_SEL, | |
627 | }, | |
628 | { | |
629 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
630 | .name = "Output Sensitivity Switch", | |
631 | .info = snd_ice1712_ewx_io_sense_info, | |
632 | .get = snd_ice1712_ewx_io_sense_get, | |
633 | .put = snd_ice1712_ewx_io_sense_put, | |
634 | .private_value = ICE1712_EWX2496_AOUT_SEL, | |
635 | }, | |
636 | }; | |
637 | ||
638 | ||
639 | /* | |
640 | * EWS88MT specific controls | |
641 | */ | |
642 | /* analog output sensitivity;; address 0x48 bit 6 */ | |
6ca308d4 | 643 | static int snd_ice1712_ews88mt_output_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 644 | { |
6ca308d4 | 645 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
7cda8ba9 | 646 | struct ews_spec *spec = ice->spec; |
1da177e4 LT |
647 | unsigned char data; |
648 | ||
649 | snd_i2c_lock(ice->i2c); | |
7cda8ba9 | 650 | if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) { |
1da177e4 LT |
651 | snd_i2c_unlock(ice->i2c); |
652 | return -EIO; | |
653 | } | |
654 | snd_i2c_unlock(ice->i2c); | |
655 | ucontrol->value.enumerated.item[0] = data & ICE1712_EWS88MT_OUTPUT_SENSE ? 1 : 0; /* high = -10dBV, low = +4dBu */ | |
656 | return 0; | |
657 | } | |
658 | ||
659 | /* analog output sensitivity;; address 0x48 bit 6 */ | |
6ca308d4 | 660 | static int snd_ice1712_ews88mt_output_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 661 | { |
6ca308d4 | 662 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
7cda8ba9 | 663 | struct ews_spec *spec = ice->spec; |
1da177e4 LT |
664 | unsigned char data, ndata; |
665 | ||
666 | snd_i2c_lock(ice->i2c); | |
7cda8ba9 | 667 | if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) { |
1da177e4 LT |
668 | snd_i2c_unlock(ice->i2c); |
669 | return -EIO; | |
670 | } | |
671 | ndata = (data & ~ICE1712_EWS88MT_OUTPUT_SENSE) | (ucontrol->value.enumerated.item[0] ? ICE1712_EWS88MT_OUTPUT_SENSE : 0); | |
7cda8ba9 TI |
672 | if (ndata != data && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF2], |
673 | &ndata, 1) != 1) { | |
1da177e4 LT |
674 | snd_i2c_unlock(ice->i2c); |
675 | return -EIO; | |
676 | } | |
677 | snd_i2c_unlock(ice->i2c); | |
678 | return ndata != data; | |
679 | } | |
680 | ||
681 | /* analog input sensitivity; address 0x46 */ | |
6ca308d4 | 682 | static int snd_ice1712_ews88mt_input_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 683 | { |
6ca308d4 | 684 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
7cda8ba9 | 685 | struct ews_spec *spec = ice->spec; |
1da177e4 LT |
686 | int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
687 | unsigned char data; | |
688 | ||
da3cec35 TI |
689 | if (snd_BUG_ON(channel < 0 || channel > 7)) |
690 | return 0; | |
1da177e4 | 691 | snd_i2c_lock(ice->i2c); |
7cda8ba9 | 692 | if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) { |
1da177e4 LT |
693 | snd_i2c_unlock(ice->i2c); |
694 | return -EIO; | |
695 | } | |
696 | /* reversed; high = +4dBu, low = -10dBV */ | |
697 | ucontrol->value.enumerated.item[0] = data & (1 << channel) ? 0 : 1; | |
698 | snd_i2c_unlock(ice->i2c); | |
699 | return 0; | |
700 | } | |
701 | ||
702 | /* analog output sensitivity; address 0x46 */ | |
6ca308d4 | 703 | static int snd_ice1712_ews88mt_input_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 704 | { |
6ca308d4 | 705 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
7cda8ba9 | 706 | struct ews_spec *spec = ice->spec; |
1da177e4 LT |
707 | int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
708 | unsigned char data, ndata; | |
709 | ||
da3cec35 TI |
710 | if (snd_BUG_ON(channel < 0 || channel > 7)) |
711 | return 0; | |
1da177e4 | 712 | snd_i2c_lock(ice->i2c); |
7cda8ba9 | 713 | if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) { |
1da177e4 LT |
714 | snd_i2c_unlock(ice->i2c); |
715 | return -EIO; | |
716 | } | |
717 | ndata = (data & ~(1 << channel)) | (ucontrol->value.enumerated.item[0] ? 0 : (1 << channel)); | |
7cda8ba9 TI |
718 | if (ndata != data && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF1], |
719 | &ndata, 1) != 1) { | |
1da177e4 LT |
720 | snd_i2c_unlock(ice->i2c); |
721 | return -EIO; | |
722 | } | |
723 | snd_i2c_unlock(ice->i2c); | |
724 | return ndata != data; | |
725 | } | |
726 | ||
bf748ed7 | 727 | static struct snd_kcontrol_new snd_ice1712_ews88mt_input_sense __devinitdata = { |
1da177e4 LT |
728 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
729 | .name = "Input Sensitivity Switch", | |
730 | .info = snd_ice1712_ewx_io_sense_info, | |
731 | .get = snd_ice1712_ews88mt_input_sense_get, | |
732 | .put = snd_ice1712_ews88mt_input_sense_put, | |
733 | .count = 8, | |
734 | }; | |
735 | ||
bf748ed7 | 736 | static struct snd_kcontrol_new snd_ice1712_ews88mt_output_sense __devinitdata = { |
1da177e4 LT |
737 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
738 | .name = "Output Sensitivity Switch", | |
739 | .info = snd_ice1712_ewx_io_sense_info, | |
740 | .get = snd_ice1712_ews88mt_output_sense_get, | |
741 | .put = snd_ice1712_ews88mt_output_sense_put, | |
742 | }; | |
743 | ||
744 | ||
745 | /* | |
746 | * EWS88D specific controls | |
747 | */ | |
748 | ||
a5ce8890 | 749 | #define snd_ice1712_ews88d_control_info snd_ctl_boolean_mono_info |
1da177e4 | 750 | |
6ca308d4 | 751 | static int snd_ice1712_ews88d_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 752 | { |
6ca308d4 | 753 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
7cda8ba9 | 754 | struct ews_spec *spec = ice->spec; |
1da177e4 LT |
755 | int shift = kcontrol->private_value & 0xff; |
756 | int invert = (kcontrol->private_value >> 8) & 1; | |
757 | unsigned char data[2]; | |
758 | ||
759 | snd_i2c_lock(ice->i2c); | |
7cda8ba9 | 760 | if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) { |
1da177e4 LT |
761 | snd_i2c_unlock(ice->i2c); |
762 | return -EIO; | |
763 | } | |
764 | snd_i2c_unlock(ice->i2c); | |
765 | data[0] = (data[shift >> 3] >> (shift & 7)) & 0x01; | |
766 | if (invert) | |
767 | data[0] ^= 0x01; | |
768 | ucontrol->value.integer.value[0] = data[0]; | |
769 | return 0; | |
770 | } | |
771 | ||
6ca308d4 | 772 | static int snd_ice1712_ews88d_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 773 | { |
6ca308d4 | 774 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
7cda8ba9 | 775 | struct ews_spec *spec = ice->spec; |
1da177e4 LT |
776 | int shift = kcontrol->private_value & 0xff; |
777 | int invert = (kcontrol->private_value >> 8) & 1; | |
778 | unsigned char data[2], ndata[2]; | |
779 | int change; | |
780 | ||
781 | snd_i2c_lock(ice->i2c); | |
7cda8ba9 | 782 | if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) { |
1da177e4 LT |
783 | snd_i2c_unlock(ice->i2c); |
784 | return -EIO; | |
785 | } | |
786 | ndata[shift >> 3] = data[shift >> 3] & ~(1 << (shift & 7)); | |
787 | if (invert) { | |
788 | if (! ucontrol->value.integer.value[0]) | |
789 | ndata[shift >> 3] |= (1 << (shift & 7)); | |
790 | } else { | |
791 | if (ucontrol->value.integer.value[0]) | |
792 | ndata[shift >> 3] |= (1 << (shift & 7)); | |
793 | } | |
794 | change = (data[shift >> 3] != ndata[shift >> 3]); | |
7cda8ba9 TI |
795 | if (change && |
796 | snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) { | |
1da177e4 LT |
797 | snd_i2c_unlock(ice->i2c); |
798 | return -EIO; | |
799 | } | |
800 | snd_i2c_unlock(ice->i2c); | |
801 | return change; | |
802 | } | |
803 | ||
804 | #define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \ | |
805 | { .iface = xiface,\ | |
806 | .name = xname,\ | |
807 | .access = xaccess,\ | |
808 | .info = snd_ice1712_ews88d_control_info,\ | |
809 | .get = snd_ice1712_ews88d_control_get,\ | |
810 | .put = snd_ice1712_ews88d_control_put,\ | |
811 | .private_value = xshift | (xinvert << 8),\ | |
812 | } | |
813 | ||
bf748ed7 | 814 | static struct snd_kcontrol_new snd_ice1712_ews88d_controls[] __devinitdata = { |
1da177e4 LT |
815 | EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, 1, 0), /* inverted */ |
816 | EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Output Optical", 1, 0, 0), | |
817 | EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT External Master Clock", 2, 0, 0), | |
818 | EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "Enable ADAT", 3, 0, 0), | |
819 | EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Through", 4, 1, 0), | |
820 | }; | |
821 | ||
822 | ||
823 | /* | |
824 | * DMX 6Fire specific controls | |
825 | */ | |
826 | ||
6ca308d4 | 827 | static int snd_ice1712_6fire_read_pca(struct snd_ice1712 *ice, unsigned char reg) |
1da177e4 LT |
828 | { |
829 | unsigned char byte; | |
7cda8ba9 TI |
830 | struct ews_spec *spec = ice->spec; |
831 | ||
1da177e4 LT |
832 | snd_i2c_lock(ice->i2c); |
833 | byte = reg; | |
7cda8ba9 | 834 | snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1); |
1da177e4 | 835 | byte = 0; |
7cda8ba9 | 836 | if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) { |
1da177e4 | 837 | snd_i2c_unlock(ice->i2c); |
99b359ba | 838 | printk(KERN_ERR "cannot read pca\n"); |
1da177e4 LT |
839 | return -EIO; |
840 | } | |
841 | snd_i2c_unlock(ice->i2c); | |
842 | return byte; | |
843 | } | |
844 | ||
6ca308d4 | 845 | static int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data) |
1da177e4 LT |
846 | { |
847 | unsigned char bytes[2]; | |
7cda8ba9 TI |
848 | struct ews_spec *spec = ice->spec; |
849 | ||
1da177e4 LT |
850 | snd_i2c_lock(ice->i2c); |
851 | bytes[0] = reg; | |
852 | bytes[1] = data; | |
7cda8ba9 | 853 | if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_6FIRE], bytes, 2) != 2) { |
1da177e4 LT |
854 | snd_i2c_unlock(ice->i2c); |
855 | return -EIO; | |
856 | } | |
857 | snd_i2c_unlock(ice->i2c); | |
858 | return 0; | |
859 | } | |
860 | ||
a5ce8890 | 861 | #define snd_ice1712_6fire_control_info snd_ctl_boolean_mono_info |
1da177e4 | 862 | |
6ca308d4 | 863 | static int snd_ice1712_6fire_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 864 | { |
6ca308d4 | 865 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
866 | int shift = kcontrol->private_value & 0xff; |
867 | int invert = (kcontrol->private_value >> 8) & 1; | |
868 | int data; | |
869 | ||
870 | if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0) | |
871 | return data; | |
872 | data = (data >> shift) & 1; | |
873 | if (invert) | |
874 | data ^= 1; | |
875 | ucontrol->value.integer.value[0] = data; | |
876 | return 0; | |
877 | } | |
878 | ||
6ca308d4 | 879 | static int snd_ice1712_6fire_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 880 | { |
6ca308d4 | 881 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
882 | int shift = kcontrol->private_value & 0xff; |
883 | int invert = (kcontrol->private_value >> 8) & 1; | |
884 | int data, ndata; | |
885 | ||
886 | if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0) | |
887 | return data; | |
888 | ndata = data & ~(1 << shift); | |
889 | if (ucontrol->value.integer.value[0]) | |
890 | ndata |= (1 << shift); | |
891 | if (invert) | |
892 | ndata ^= (1 << shift); | |
893 | if (data != ndata) { | |
894 | snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata); | |
895 | return 1; | |
896 | } | |
897 | return 0; | |
898 | } | |
899 | ||
6ca308d4 | 900 | static int snd_ice1712_6fire_select_input_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
1da177e4 LT |
901 | { |
902 | static char *texts[4] = { | |
903 | "Internal", "Front Input", "Rear Input", "Wave Table" | |
904 | }; | |
905 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | |
906 | uinfo->count = 1; | |
907 | uinfo->value.enumerated.items = 4; | |
908 | if (uinfo->value.enumerated.item >= 4) | |
909 | uinfo->value.enumerated.item = 1; | |
910 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); | |
911 | return 0; | |
912 | } | |
913 | ||
6ca308d4 | 914 | static int snd_ice1712_6fire_select_input_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 915 | { |
6ca308d4 | 916 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
917 | int data; |
918 | ||
919 | if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0) | |
920 | return data; | |
921 | ucontrol->value.integer.value[0] = data & 3; | |
922 | return 0; | |
923 | } | |
924 | ||
6ca308d4 | 925 | static int snd_ice1712_6fire_select_input_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 926 | { |
6ca308d4 | 927 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
928 | int data, ndata; |
929 | ||
930 | if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0) | |
931 | return data; | |
932 | ndata = data & ~3; | |
933 | ndata |= (ucontrol->value.integer.value[0] & 3); | |
934 | if (data != ndata) { | |
935 | snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata); | |
936 | return 1; | |
937 | } | |
938 | return 0; | |
939 | } | |
940 | ||
941 | ||
942 | #define DMX6FIRE_CONTROL(xname, xshift, xinvert) \ | |
943 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\ | |
944 | .name = xname,\ | |
945 | .info = snd_ice1712_6fire_control_info,\ | |
946 | .get = snd_ice1712_6fire_control_get,\ | |
947 | .put = snd_ice1712_6fire_control_put,\ | |
948 | .private_value = xshift | (xinvert << 8),\ | |
949 | } | |
950 | ||
bf748ed7 | 951 | static struct snd_kcontrol_new snd_ice1712_6fire_controls[] __devinitdata = { |
1da177e4 LT |
952 | { |
953 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
954 | .name = "Analog Input Select", | |
955 | .info = snd_ice1712_6fire_select_input_info, | |
956 | .get = snd_ice1712_6fire_select_input_get, | |
957 | .put = snd_ice1712_6fire_select_input_put, | |
958 | }, | |
6a81dbf2 | 959 | DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 1), |
1da177e4 LT |
960 | // DMX6FIRE_CONTROL("Master Clock Select", 3, 0), |
961 | DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0), | |
962 | DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0), | |
963 | DMX6FIRE_CONTROL("Breakbox LED", 6, 0), | |
964 | }; | |
965 | ||
966 | ||
6ca308d4 | 967 | static int __devinit snd_ice1712_ews_add_controls(struct snd_ice1712 *ice) |
1da177e4 LT |
968 | { |
969 | unsigned int idx; | |
970 | int err; | |
971 | ||
972 | /* all terratec cards have spdif, but cs8427 module builds it's own controls */ | |
973 | if (ice->cs8427 == NULL) { | |
974 | err = snd_ice1712_spdif_build_controls(ice); | |
975 | if (err < 0) | |
976 | return err; | |
977 | } | |
978 | ||
979 | /* ak4524 controls */ | |
980 | switch (ice->eeprom.subvendor) { | |
981 | case ICE1712_SUBDEVICE_EWX2496: | |
982 | case ICE1712_SUBDEVICE_EWS88MT: | |
983 | case ICE1712_SUBDEVICE_EWS88MT_NEW: | |
984 | case ICE1712_SUBDEVICE_PHASE88: | |
d80fd093 | 985 | case ICE1712_SUBDEVICE_TS88: |
1da177e4 LT |
986 | case ICE1712_SUBDEVICE_DMX6FIRE: |
987 | err = snd_ice1712_akm4xxx_build_controls(ice); | |
988 | if (err < 0) | |
989 | return err; | |
990 | break; | |
991 | } | |
992 | ||
993 | /* card specific controls */ | |
994 | switch (ice->eeprom.subvendor) { | |
995 | case ICE1712_SUBDEVICE_EWX2496: | |
996 | for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ewx2496_controls); idx++) { | |
997 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ewx2496_controls[idx], ice)); | |
998 | if (err < 0) | |
999 | return err; | |
1000 | } | |
1001 | break; | |
1002 | case ICE1712_SUBDEVICE_EWS88MT: | |
1003 | case ICE1712_SUBDEVICE_EWS88MT_NEW: | |
1004 | case ICE1712_SUBDEVICE_PHASE88: | |
d80fd093 | 1005 | case ICE1712_SUBDEVICE_TS88: |
1da177e4 LT |
1006 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice)); |
1007 | if (err < 0) | |
1008 | return err; | |
1009 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense, ice)); | |
1010 | if (err < 0) | |
1011 | return err; | |
1012 | break; | |
1013 | case ICE1712_SUBDEVICE_EWS88D: | |
1014 | for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ews88d_controls); idx++) { | |
1015 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_controls[idx], ice)); | |
1016 | if (err < 0) | |
1017 | return err; | |
1018 | } | |
1019 | break; | |
1020 | case ICE1712_SUBDEVICE_DMX6FIRE: | |
1021 | for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_6fire_controls); idx++) { | |
1022 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_6fire_controls[idx], ice)); | |
1023 | if (err < 0) | |
1024 | return err; | |
1025 | } | |
1026 | break; | |
1027 | } | |
1028 | return 0; | |
1029 | } | |
1030 | ||
1031 | ||
1032 | /* entry point */ | |
bf748ed7 | 1033 | struct snd_ice1712_card_info snd_ice1712_ews_cards[] __devinitdata = { |
1da177e4 LT |
1034 | { |
1035 | .subvendor = ICE1712_SUBDEVICE_EWX2496, | |
1036 | .name = "TerraTec EWX24/96", | |
1037 | .model = "ewx2496", | |
1038 | .chip_init = snd_ice1712_ews_init, | |
1039 | .build_controls = snd_ice1712_ews_add_controls, | |
1040 | }, | |
1041 | { | |
1042 | .subvendor = ICE1712_SUBDEVICE_EWS88MT, | |
1043 | .name = "TerraTec EWS88MT", | |
1044 | .model = "ews88mt", | |
1045 | .chip_init = snd_ice1712_ews_init, | |
1046 | .build_controls = snd_ice1712_ews_add_controls, | |
1047 | }, | |
1048 | { | |
1049 | .subvendor = ICE1712_SUBDEVICE_EWS88MT_NEW, | |
1050 | .name = "TerraTec EWS88MT", | |
1051 | .model = "ews88mt_new", | |
1052 | .chip_init = snd_ice1712_ews_init, | |
1053 | .build_controls = snd_ice1712_ews_add_controls, | |
1054 | }, | |
1055 | { | |
1056 | .subvendor = ICE1712_SUBDEVICE_PHASE88, | |
1057 | .name = "TerraTec Phase88", | |
1058 | .model = "phase88", | |
1059 | .chip_init = snd_ice1712_ews_init, | |
1060 | .build_controls = snd_ice1712_ews_add_controls, | |
1061 | }, | |
d80fd093 PL |
1062 | { |
1063 | .subvendor = ICE1712_SUBDEVICE_TS88, | |
1064 | .name = "terrasoniq TS88", | |
1065 | .model = "phase88", | |
1066 | .chip_init = snd_ice1712_ews_init, | |
1067 | .build_controls = snd_ice1712_ews_add_controls, | |
1068 | }, | |
1da177e4 LT |
1069 | { |
1070 | .subvendor = ICE1712_SUBDEVICE_EWS88D, | |
1071 | .name = "TerraTec EWS88D", | |
1072 | .model = "ews88d", | |
1073 | .chip_init = snd_ice1712_ews_init, | |
1074 | .build_controls = snd_ice1712_ews_add_controls, | |
1075 | }, | |
1076 | { | |
1077 | .subvendor = ICE1712_SUBDEVICE_DMX6FIRE, | |
1078 | .name = "TerraTec DMX6Fire", | |
1079 | .model = "dmx6fire", | |
1080 | .chip_init = snd_ice1712_ews_init, | |
1081 | .build_controls = snd_ice1712_ews_add_controls, | |
3bef229e AH |
1082 | .mpu401_1_name = "MIDI-Front DMX6fire", |
1083 | .mpu401_2_name = "Wavetable DMX6fire", | |
cf78ee2c | 1084 | .mpu401_2_info_flags = MPU401_INFO_OUTPUT, |
1da177e4 LT |
1085 | }, |
1086 | { } /* terminator */ | |
1087 | }; |