~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/pci/ice1712/ews.c

Version: ~ [ linux-5.16-rc3 ] ~ [ linux-5.15.5 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.82 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.162 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.218 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.256 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.291 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.293 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *   ALSA driver for ICEnsemble ICE1712 (Envy24)
  3  *
  4  *   Lowlevel functions for Terratec EWS88MT/D, EWX24/96, DMX 6Fire
  5  *
  6  *      Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
  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 
 25 #include <sound/driver.h>
 26 #include <asm/io.h>
 27 #include <linux/delay.h>
 28 #include <linux/interrupt.h>
 29 #include <linux/init.h>
 30 #include <linux/slab.h>
 31 #include <sound/core.h>
 32 #include <sound/cs8427.h>
 33 #include <sound/asoundef.h>
 34 
 35 #include "ice1712.h"
 36 #include "ews.h"
 37 
 38 #define SND_CS8404
 39 #include <sound/cs8403.h>
 40 
 41 /*
 42  * access via i2c mode (for EWX 24/96, EWS 88MT&D)
 43  */
 44 
 45 /* send SDA and SCL */
 46 static void ewx_i2c_setlines(snd_i2c_bus_t *bus, int clk, int data)
 47 {
 48         ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return);
 49         unsigned char tmp = 0;
 50         if (clk)
 51                 tmp |= ICE1712_EWX2496_SERIAL_CLOCK;
 52         if (data)
 53                 tmp |= ICE1712_EWX2496_SERIAL_DATA;
 54         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
 55         udelay(5);
 56 }
 57 
 58 static int ewx_i2c_getclock(snd_i2c_bus_t *bus)
 59 {
 60         ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return -EIO);
 61         return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_CLOCK ? 1 : 0;
 62 }
 63 
 64 static int ewx_i2c_getdata(snd_i2c_bus_t *bus, int ack)
 65 {
 66         ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return -EIO);
 67         int bit;
 68         /* set RW pin to low */
 69         snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_RW);
 70         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, 0);
 71         if (ack)
 72                 udelay(5);
 73         bit = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_DATA ? 1 : 0;
 74         /* set RW pin to high */
 75         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ICE1712_EWX2496_RW);
 76         /* reset write mask */
 77         snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_SERIAL_CLOCK);
 78         return bit;
 79 }
 80 
 81 static void ewx_i2c_start(snd_i2c_bus_t *bus)
 82 {
 83         ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return);
 84         unsigned char mask;
 85 
 86         snd_ice1712_save_gpio_status(ice);
 87         /* set RW high */
 88         mask = ICE1712_EWX2496_RW;
 89         switch (ice->eeprom.subvendor) {
 90         case ICE1712_SUBDEVICE_EWX2496:
 91                 mask |= ICE1712_EWX2496_AK4524_CS; /* CS high also */
 92                 break;
 93         case ICE1712_SUBDEVICE_DMX6FIRE:
 94                 mask |= ICE1712_6FIRE_AK4524_CS_MASK; /* CS high also */
 95                 break;
 96         }
 97         snd_ice1712_gpio_write_bits(ice, mask, mask);
 98 }
 99 
100 static void ewx_i2c_stop(snd_i2c_bus_t *bus)
101 {
102         ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return);
103         snd_ice1712_restore_gpio_status(ice);
104 }
105 
106 static void ewx_i2c_direction(snd_i2c_bus_t *bus, int clock, int data)
107 {
108         ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return);
109         unsigned char mask = 0;
110 
111         if (clock)
112                 mask |= ICE1712_EWX2496_SERIAL_CLOCK; /* write SCL */
113         if (data)
114                 mask |= ICE1712_EWX2496_SERIAL_DATA; /* write SDA */
115         ice->gpio.direction &= ~(ICE1712_EWX2496_SERIAL_CLOCK|ICE1712_EWX2496_SERIAL_DATA);
116         ice->gpio.direction |= mask;
117         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio.direction);
118         snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~mask);
119 }
120 
121 static snd_i2c_bit_ops_t snd_ice1712_ewx_cs8427_bit_ops = {
122         .start = ewx_i2c_start,
123         .stop = ewx_i2c_stop,
124         .direction = ewx_i2c_direction,
125         .setlines = ewx_i2c_setlines,
126         .getclock = ewx_i2c_getclock,
127         .getdata = ewx_i2c_getdata,
128 };
129 
130 
131 /*
132  * AK4524 access
133  */
134 
135 /* AK4524 chip select; address 0x48 bit 0-3 */
136 static int snd_ice1712_ews88mt_chip_select(ice1712_t *ice, int chip_mask)
137 {
138         unsigned char data, ndata;
139 
140         snd_assert(chip_mask >= 0 && chip_mask <= 0x0f, return -EINVAL);
141         snd_i2c_lock(ice->i2c);
142         if (snd_i2c_readbytes(ice->i2cdevs[1], &data, 1) != 1)
143                 goto __error;
144         ndata = (data & 0xf0) | chip_mask;
145         if (ndata != data)
146                 if (snd_i2c_sendbytes(ice->i2cdevs[1], &ndata, 1) != 1)
147                         goto __error;
148         snd_i2c_unlock(ice->i2c);
149         return 0;
150 
151      __error:
152         snd_i2c_unlock(ice->i2c);
153         snd_printk(KERN_ERR "AK4524 chip select failed, check cable to the front module\n");
154         return -EIO;
155 }
156 
157 /* start callback for EWS88MT, needs to select a certain chip mask */
158 static void ews88mt_ak4524_lock(akm4xxx_t *ak, int chip)
159 {
160         ice1712_t *ice = ak->private_data[0];
161         unsigned char tmp;
162         /* assert AK4524 CS */
163         if (snd_ice1712_ews88mt_chip_select(ice, ~(1 << chip) & 0x0f) < 0)
164                 snd_printk(KERN_ERR "fatal error (ews88mt chip select)\n");
165         snd_ice1712_save_gpio_status(ice);
166         tmp = ICE1712_EWS88_SERIAL_DATA |
167                 ICE1712_EWS88_SERIAL_CLOCK |
168                 ICE1712_EWS88_RW;
169         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
170                           ice->gpio.direction | tmp);
171         snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
172 }
173 
174 /* stop callback for EWS88MT, needs to deselect chip mask */
175 static void ews88mt_ak4524_unlock(akm4xxx_t *ak, int chip)
176 {
177         ice1712_t *ice = ak->private_data[0];
178         snd_ice1712_restore_gpio_status(ice);
179         udelay(1);
180         snd_ice1712_ews88mt_chip_select(ice, 0x0f);
181 }
182 
183 /* start callback for EWX24/96 */
184 static void ewx2496_ak4524_lock(akm4xxx_t *ak, int chip)
185 {
186         ice1712_t *ice = ak->private_data[0];
187         unsigned char tmp;
188         snd_ice1712_save_gpio_status(ice);
189         tmp =  ICE1712_EWX2496_SERIAL_DATA |
190                 ICE1712_EWX2496_SERIAL_CLOCK |
191                 ICE1712_EWX2496_AK4524_CS |
192                 ICE1712_EWX2496_RW;
193         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
194                           ice->gpio.direction | tmp);
195         snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
196 }
197 
198 /* start callback for DMX 6fire */
199 static void dmx6fire_ak4524_lock(akm4xxx_t *ak, int chip)
200 {
201         struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
202         ice1712_t *ice = ak->private_data[0];
203         unsigned char tmp;
204         snd_ice1712_save_gpio_status(ice);
205         tmp = priv->cs_mask = priv->cs_addr = (1 << chip) & ICE1712_6FIRE_AK4524_CS_MASK;
206         tmp |= ICE1712_6FIRE_SERIAL_DATA |
207                 ICE1712_6FIRE_SERIAL_CLOCK |
208                 ICE1712_6FIRE_RW;
209         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
210                           ice->gpio.direction | tmp);
211         snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
212 }
213 
214 /*
215  * CS8404 interface on EWS88MT/D
216  */
217 
218 static void snd_ice1712_ews_cs8404_spdif_write(ice1712_t *ice, unsigned char bits)
219 {
220         unsigned char bytes[2];
221 
222         snd_i2c_lock(ice->i2c);
223         switch (ice->eeprom.subvendor) {
224         case ICE1712_SUBDEVICE_EWS88MT:
225         case ICE1712_SUBDEVICE_EWS88MT_NEW:
226                 snd_runtime_check(snd_i2c_sendbytes(ice->cs8404, &bits, 1) == 1, goto _error);
227                 break;
228         case ICE1712_SUBDEVICE_EWS88D:
229                 snd_runtime_check(snd_i2c_readbytes(ice->i2cdevs[0], bytes, 2) == 2, goto _error);
230                 if (bits != bytes[1]) {
231                         bytes[1] = bits;
232                         snd_runtime_check(snd_i2c_readbytes(ice->i2cdevs[0], bytes, 2) == 2, goto _error);
233                 }
234                 break;
235         }
236  _error:
237         snd_i2c_unlock(ice->i2c);
238 }
239 
240 /*
241  */
242 
243 static void ews88_spdif_default_get(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
244 {
245         snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_bits);
246 }
247 
248 static int ews88_spdif_default_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
249 {
250         unsigned int val;
251         int change;
252 
253         val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
254         spin_lock_irq(&ice->reg_lock);
255         change = ice->spdif.cs8403_bits != val;
256         ice->spdif.cs8403_bits = val;
257         if (change && ice->playback_pro_substream == NULL) {
258                 spin_unlock_irq(&ice->reg_lock);
259                 snd_ice1712_ews_cs8404_spdif_write(ice, val);
260         } else {
261                 spin_unlock_irq(&ice->reg_lock);
262         }
263         return change;
264 }
265 
266 static void ews88_spdif_stream_get(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
267 {
268         snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_stream_bits);
269 }
270 
271 static int ews88_spdif_stream_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
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_stream_bits != val;
279         ice->spdif.cs8403_stream_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 
289 
290 /* open callback */
291 static void ews88_open_spdif(ice1712_t *ice, snd_pcm_substream_t * substream)
292 {
293         ice->spdif.cs8403_stream_bits = ice->spdif.cs8403_bits;
294 }
295 
296 /* set up SPDIF for EWS88MT / EWS88D */
297 static void ews88_setup_spdif(ice1712_t *ice, int rate)
298 {
299         unsigned long flags;
300         unsigned char tmp;
301         int change;
302 
303         spin_lock_irqsave(&ice->reg_lock, flags);
304         tmp = ice->spdif.cs8403_stream_bits;
305         if (tmp & 0x10)         /* consumer */
306                 tmp &= (tmp & 0x01) ? ~0x06 : ~0x60;
307         switch (rate) {
308         case 32000: tmp |= (tmp & 0x01) ? 0x02 : 0x00; break;
309         case 44100: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
310         case 48000: tmp |= (tmp & 0x01) ? 0x04 : 0x20; break;
311         default: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
312         }
313         change = ice->spdif.cs8403_stream_bits != tmp;
314         ice->spdif.cs8403_stream_bits = tmp;
315         spin_unlock_irqrestore(&ice->reg_lock, flags);
316         if (change)
317                 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &ice->spdif.stream_ctl->id);
318         snd_ice1712_ews_cs8404_spdif_write(ice, tmp);
319 }
320 
321 
322 /*
323  */
324 static akm4xxx_t akm_ews88mt __devinitdata = {
325         .num_adcs = 8,
326         .num_dacs = 8,
327         .type = SND_AK4524,
328         .ops = {
329                 .lock = ews88mt_ak4524_lock,
330                 .unlock = ews88mt_ak4524_unlock
331         }
332 };
333 
334 static struct snd_ak4xxx_private akm_ews88mt_priv __devinitdata = {
335         .caddr = 2,
336         .cif = 1, /* CIF high */
337         .data_mask = ICE1712_EWS88_SERIAL_DATA,
338         .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
339         .cs_mask = 0,
340         .cs_addr = 0,
341         .cs_none = 0, /* no chip select on gpio */
342         .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
343         .mask_flags = 0,
344 };
345 
346 static akm4xxx_t akm_ewx2496 __devinitdata = {
347         .num_adcs = 2,
348         .num_dacs = 2,
349         .type = SND_AK4524,
350         .ops = {
351                 .lock = ewx2496_ak4524_lock
352         }
353 };
354 
355 static struct snd_ak4xxx_private akm_ewx2496_priv __devinitdata = {
356         .caddr = 2,
357         .cif = 1, /* CIF high */
358         .data_mask = ICE1712_EWS88_SERIAL_DATA,
359         .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
360         .cs_mask = ICE1712_EWX2496_AK4524_CS,
361         .cs_addr = ICE1712_EWX2496_AK4524_CS,
362         .cs_none = 0,
363         .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
364         .mask_flags = 0,
365 };
366 
367 static akm4xxx_t akm_6fire __devinitdata = {
368         .num_adcs = 6,
369         .num_dacs = 6,
370         .type = SND_AK4524,
371         .ops = {
372                 .lock = dmx6fire_ak4524_lock
373         }
374 };
375 
376 static struct snd_ak4xxx_private akm_6fire_priv __devinitdata = {
377         .caddr = 2,
378         .cif = 1, /* CIF high */
379         .data_mask = ICE1712_6FIRE_SERIAL_DATA,
380         .clk_mask = ICE1712_6FIRE_SERIAL_CLOCK,
381         .cs_mask = 0,
382         .cs_addr = 0, /* set later */
383         .cs_none = 0,
384         .add_flags = ICE1712_6FIRE_RW, /* set rw bit high */
385         .mask_flags = 0,
386 };
387 
388 /*
389  * initialize the chip
390  */
391 
392 /* 6fire specific */
393 #define PCF9554_REG_INPUT      0
394 #define PCF9554_REG_OUTPUT     1
395 #define PCF9554_REG_POLARITY   2
396 #define PCF9554_REG_CONFIG     3
397 
398 static int snd_ice1712_6fire_write_pca(ice1712_t *ice, unsigned char reg, unsigned char data);
399 
400 static int __devinit snd_ice1712_ews_init(ice1712_t *ice)
401 {
402         int err;
403         akm4xxx_t *ak;
404 
405         /* set the analog DACs */
406         switch (ice->eeprom.subvendor) {
407         case ICE1712_SUBDEVICE_EWX2496:
408                 ice->num_total_dacs = 2;
409                 break;  
410         case ICE1712_SUBDEVICE_EWS88MT:
411         case ICE1712_SUBDEVICE_EWS88MT_NEW:
412                 ice->num_total_dacs = 8;
413                 break;
414         case ICE1712_SUBDEVICE_EWS88D:
415                 break; /* no analog */
416         case ICE1712_SUBDEVICE_DMX6FIRE:
417                 ice->num_total_dacs = 6;
418                 break;
419         }
420 
421         /* create i2c */
422         if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
423                 snd_printk("unable to create I2C bus\n");
424                 return err;
425         }
426         ice->i2c->private_data = ice;
427         ice->i2c->hw_ops.bit = &snd_ice1712_ewx_cs8427_bit_ops;
428 
429         /* create i2c devices */
430         switch (ice->eeprom.subvendor) {
431         case ICE1712_SUBDEVICE_DMX6FIRE:
432                 if ((err = snd_i2c_device_create(ice->i2c, "PCF9554", ICE1712_6FIRE_PCF9554_ADDR, &ice->i2cdevs[0])) < 0) {
433                         snd_printk("PCF9554 initialization failed\n");
434                         return err;
435                 }
436                 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80);
437                 break;
438         case ICE1712_SUBDEVICE_EWS88MT:
439         case ICE1712_SUBDEVICE_EWS88MT_NEW:
440                 if ((err = snd_i2c_device_create(ice->i2c, "CS8404", ICE1712_EWS88MT_CS8404_ADDR, &ice->cs8404)) < 0)
441                         return err;
442                 if ((err = snd_i2c_device_create(ice->i2c, "PCF8574 (1st)", ICE1712_EWS88MT_INPUT_ADDR, &ice->i2cdevs[0])) < 0)
443                         return err;
444                 if ((err = snd_i2c_device_create(ice->i2c, "PCF8574 (2nd)", ICE1712_EWS88MT_OUTPUT_ADDR, &ice->i2cdevs[1])) < 0)
445                         return err;
446                 /* Check if the front module is connected */
447                 if ((err = snd_ice1712_ews88mt_chip_select(ice, 0x0f)) < 0)
448                         return err;
449                 break;
450         case ICE1712_SUBDEVICE_EWS88D:
451                 if ((err = snd_i2c_device_create(ice->i2c, "PCF8575", ICE1712_EWS88D_PCF_ADDR, &ice->i2cdevs[0])) < 0)
452                         return err;
453                 break;
454         }
455 
456         /* set up SPDIF interface */
457         switch (ice->eeprom.subvendor) {
458         case ICE1712_SUBDEVICE_EWX2496:
459                 if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0)
460                         return err;
461                 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
462                 break;
463         case ICE1712_SUBDEVICE_DMX6FIRE:
464                 if ((err = snd_ice1712_init_cs8427(ice, ICE1712_6FIRE_CS8427_ADDR)) < 0)
465                         return err;
466                 snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
467                 break;
468         case ICE1712_SUBDEVICE_EWS88MT:
469         case ICE1712_SUBDEVICE_EWS88MT_NEW:
470         case ICE1712_SUBDEVICE_EWS88D:
471                 /* set up CS8404 */
472                 ice->spdif.ops.open = ews88_open_spdif;
473                 ice->spdif.ops.setup_rate = ews88_setup_spdif;
474                 ice->spdif.ops.default_get = ews88_spdif_default_get;
475                 ice->spdif.ops.default_put = ews88_spdif_default_put;
476                 ice->spdif.ops.stream_get = ews88_spdif_stream_get;
477                 ice->spdif.ops.stream_put = ews88_spdif_stream_put;
478                 /* Set spdif defaults */
479                 snd_ice1712_ews_cs8404_spdif_write(ice, ice->spdif.cs8403_bits);
480                 break;
481         }
482 
483         /* no analog? */
484         switch (ice->eeprom.subvendor) {
485         case ICE1712_SUBDEVICE_EWS88D:
486                 return 0;
487         }
488 
489         /* analog section */
490         ak = ice->akm = kmalloc(sizeof(akm4xxx_t), GFP_KERNEL);
491         if (! ak)
492                 return -ENOMEM;
493         ice->akm_codecs = 1;
494 
495         switch (ice->eeprom.subvendor) {
496         case ICE1712_SUBDEVICE_EWS88MT:
497         case ICE1712_SUBDEVICE_EWS88MT_NEW:
498                 err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice);
499                 break;
500         case ICE1712_SUBDEVICE_EWX2496:
501                 err = snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, &akm_ewx2496_priv, ice);
502                 break;
503         case ICE1712_SUBDEVICE_DMX6FIRE:
504                 err = snd_ice1712_akm4xxx_init(ak, &akm_6fire, &akm_6fire_priv, ice);
505                 break;
506         default:
507                 err = 0;
508         }
509 
510         return err;
511 }
512 
513 /*
514  * EWX 24/96 specific controls
515  */
516 
517 /* i/o sensitivity - this callback is shared among other devices, too */
518 static int snd_ice1712_ewx_io_sense_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo){
519 
520         static char *texts[2] = {
521                 "+4dBu", "-10dBV",
522         };
523         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
524         uinfo->count = 1;
525         uinfo->value.enumerated.items = 2;
526         if (uinfo->value.enumerated.item >= 2)
527                 uinfo->value.enumerated.item = 1;
528         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
529         return 0;
530 }
531 
532 static int snd_ice1712_ewx_io_sense_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
533 {
534         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
535         unsigned char mask = kcontrol->private_value & 0xff;
536         
537         snd_ice1712_save_gpio_status(ice);
538         ucontrol->value.enumerated.item[0] = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0;
539         snd_ice1712_restore_gpio_status(ice);
540         return 0;
541 }
542 
543 static int snd_ice1712_ewx_io_sense_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
544 {
545         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
546         unsigned char mask = kcontrol->private_value & 0xff;
547         int val, nval;
548 
549         if (kcontrol->private_value & (1 << 31))
550                 return -EPERM;
551         nval = ucontrol->value.enumerated.item[0] ? mask : 0;
552         snd_ice1712_save_gpio_status(ice);
553         val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
554         nval |= val & ~mask;
555         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, nval);
556         snd_ice1712_restore_gpio_status(ice);
557         return val != nval;
558 }
559 
560 static snd_kcontrol_new_t snd_ice1712_ewx2496_controls[] __devinitdata = {
561         {
562                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
563                 .name = "Input Sensitivity Switch",
564                 .info = snd_ice1712_ewx_io_sense_info,
565                 .get = snd_ice1712_ewx_io_sense_get,
566                 .put = snd_ice1712_ewx_io_sense_put,
567                 .private_value = ICE1712_EWX2496_AIN_SEL,
568         },
569         {
570                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
571                 .name = "Output Sensitivity Switch",
572                 .info = snd_ice1712_ewx_io_sense_info,
573                 .get = snd_ice1712_ewx_io_sense_get,
574                 .put = snd_ice1712_ewx_io_sense_put,
575                 .private_value = ICE1712_EWX2496_AOUT_SEL,
576         },
577 };
578 
579 
580 /*
581  * EWS88MT specific controls
582  */
583 /* analog output sensitivity;; address 0x48 bit 6 */
584 static int snd_ice1712_ews88mt_output_sense_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
585 {
586         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
587         unsigned char data;
588 
589         snd_i2c_lock(ice->i2c);
590         if (snd_i2c_readbytes(ice->i2cdevs[1], &data, 1) != 1) {
591                 snd_i2c_unlock(ice->i2c);
592                 return -EIO;
593         }
594         snd_i2c_unlock(ice->i2c);
595         ucontrol->value.enumerated.item[0] = data & ICE1712_EWS88MT_OUTPUT_SENSE ? 1 : 0; /* high = -10dBV, low = +4dBu */
596         return 0;
597 }
598 
599 /* analog output sensitivity;; address 0x48 bit 6 */
600 static int snd_ice1712_ews88mt_output_sense_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
601 {
602         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
603         unsigned char data, ndata;
604 
605         snd_i2c_lock(ice->i2c);
606         if (snd_i2c_readbytes(ice->i2cdevs[1], &data, 1) != 1) {
607                 snd_i2c_unlock(ice->i2c);
608                 return -EIO;
609         }
610         ndata = (data & ~ICE1712_EWS88MT_OUTPUT_SENSE) | (ucontrol->value.enumerated.item[0] ? ICE1712_EWS88MT_OUTPUT_SENSE : 0);
611         if (ndata != data && snd_i2c_sendbytes(ice->i2cdevs[1], &ndata, 1) != 1) {
612                 snd_i2c_unlock(ice->i2c);
613                 return -EIO;
614         }
615         snd_i2c_unlock(ice->i2c);
616         return ndata != data;
617 }
618 
619 /* analog input sensitivity; address 0x46 */
620 static int snd_ice1712_ews88mt_input_sense_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
621 {
622         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
623         int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
624         unsigned char data;
625 
626         snd_assert(channel >= 0 && channel <= 7, return 0);
627         snd_i2c_lock(ice->i2c);
628         if (snd_i2c_readbytes(ice->i2cdevs[0], &data, 1) != 1) {
629                 snd_i2c_unlock(ice->i2c);
630                 return -EIO;
631         }
632         /* reversed; high = +4dBu, low = -10dBV */
633         ucontrol->value.enumerated.item[0] = data & (1 << channel) ? 0 : 1;
634         snd_i2c_unlock(ice->i2c);
635         return 0;
636 }
637 
638 /* analog output sensitivity; address 0x46 */
639 static int snd_ice1712_ews88mt_input_sense_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
640 {
641         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
642         int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
643         unsigned char data, ndata;
644 
645         snd_assert(channel >= 0 && channel <= 7, return 0);
646         snd_i2c_lock(ice->i2c);
647         if (snd_i2c_readbytes(ice->i2cdevs[0], &data, 1) != 1) {
648                 snd_i2c_unlock(ice->i2c);
649                 return -EIO;
650         }
651         ndata = (data & ~(1 << channel)) | (ucontrol->value.enumerated.item[0] ? 0 : (1 << channel));
652         if (ndata != data && snd_i2c_sendbytes(ice->i2cdevs[0], &ndata, 1) != 1) {
653                 snd_i2c_unlock(ice->i2c);
654                 return -EIO;
655         }
656         snd_i2c_unlock(ice->i2c);
657         return ndata != data;
658 }
659 
660 static snd_kcontrol_new_t snd_ice1712_ews88mt_input_sense __devinitdata = {
661         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
662         .name = "Input Sensitivity Switch",
663         .info = snd_ice1712_ewx_io_sense_info,
664         .get = snd_ice1712_ews88mt_input_sense_get,
665         .put = snd_ice1712_ews88mt_input_sense_put,
666         .count = 8,
667 };
668 
669 static snd_kcontrol_new_t snd_ice1712_ews88mt_output_sense __devinitdata = {
670         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
671         .name = "Output Sensitivity Switch",
672         .info = snd_ice1712_ewx_io_sense_info,
673         .get = snd_ice1712_ews88mt_output_sense_get,
674         .put = snd_ice1712_ews88mt_output_sense_put,
675 };
676 
677 
678 /*
679  * EWS88D specific controls
680  */
681 
682 static int snd_ice1712_ews88d_control_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
683 {
684         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
685         uinfo->count = 1;
686         uinfo->value.integer.min = 0;
687         uinfo->value.integer.max = 1;
688         return 0;
689 }
690 
691 static int snd_ice1712_ews88d_control_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
692 {
693         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
694         int shift = kcontrol->private_value & 0xff;
695         int invert = (kcontrol->private_value >> 8) & 1;
696         unsigned char data[2];
697         
698         snd_i2c_lock(ice->i2c);
699         if (snd_i2c_readbytes(ice->i2cdevs[0], data, 2) != 2) {
700                 snd_i2c_unlock(ice->i2c);
701                 return -EIO;
702         }
703         snd_i2c_unlock(ice->i2c);
704         data[0] = (data[shift >> 3] >> (shift & 7)) & 0x01;
705         if (invert)
706                 data[0] ^= 0x01;
707         ucontrol->value.integer.value[0] = data[0];
708         return 0;
709 }
710 
711 static int snd_ice1712_ews88d_control_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
712 {
713         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
714         int shift = kcontrol->private_value & 0xff;
715         int invert = (kcontrol->private_value >> 8) & 1;
716         unsigned char data[2], ndata[2];
717         int change;
718 
719         snd_i2c_lock(ice->i2c);
720         if (snd_i2c_readbytes(ice->i2cdevs[0], data, 2) != 2) {
721                 snd_i2c_unlock(ice->i2c);
722                 return -EIO;
723         }
724         ndata[shift >> 3] = data[shift >> 3] & ~(1 << (shift & 7));
725         if (invert) {
726                 if (! ucontrol->value.integer.value[0])
727                         ndata[shift >> 3] |= (1 << (shift & 7));
728         } else {
729                 if (ucontrol->value.integer.value[0])
730                         ndata[shift >> 3] |= (1 << (shift & 7));
731         }
732         change = (data[shift >> 3] != ndata[shift >> 3]);
733         if (change && snd_i2c_sendbytes(ice->i2cdevs[0], data, 2) != 2) {
734                 snd_i2c_unlock(ice->i2c);
735                 return -EIO;
736         }
737         snd_i2c_unlock(ice->i2c);
738         return change;
739 }
740 
741 #define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
742 { .iface = xiface,\
743   .name = xname,\
744   .access = xaccess,\
745   .info = snd_ice1712_ews88d_control_info,\
746   .get = snd_ice1712_ews88d_control_get,\
747   .put = snd_ice1712_ews88d_control_put,\
748   .private_value = xshift | (xinvert << 8),\
749 }
750 
751 static snd_kcontrol_new_t snd_ice1712_ews88d_controls[] __devinitdata = {
752         EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, 1, 0), /* inverted */
753         EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Output Optical", 1, 0, 0),
754         EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT External Master Clock", 2, 0, 0),
755         EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "Enable ADAT", 3, 0, 0),
756         EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Through", 4, 1, 0),
757 };
758 
759 
760 /*
761  * DMX 6Fire specific controls
762  */
763 
764 static int snd_ice1712_6fire_read_pca(ice1712_t *ice, unsigned char reg)
765 {
766         unsigned char byte;
767         snd_i2c_lock(ice->i2c);
768         byte = reg;
769         snd_i2c_sendbytes(ice->i2cdevs[0], &byte, 1);
770         byte = 0;
771         if (snd_i2c_readbytes(ice->i2cdevs[0], &byte, 1) != 1) {
772                 snd_i2c_unlock(ice->i2c);
773                 printk("cannot read pca\n");
774                 return -EIO;
775         }
776         snd_i2c_unlock(ice->i2c);
777         return byte;
778 }
779 
780 static int snd_ice1712_6fire_write_pca(ice1712_t *ice, unsigned char reg, unsigned char data)
781 {
782         unsigned char bytes[2];
783         snd_i2c_lock(ice->i2c);
784         bytes[0] = reg;
785         bytes[1] = data;
786         if (snd_i2c_sendbytes(ice->i2cdevs[0], bytes, 2) != 2) {
787                 snd_i2c_unlock(ice->i2c);
788                 return -EIO;
789         }
790         snd_i2c_unlock(ice->i2c);
791         return 0;
792 }
793 
794 static int snd_ice1712_6fire_control_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
795 {
796         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
797         uinfo->count = 1;
798         uinfo->value.integer.min = 0;
799         uinfo->value.integer.max = 1;
800         return 0;
801 }
802 
803 static int snd_ice1712_6fire_control_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
804 {
805         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
806         int shift = kcontrol->private_value & 0xff;
807         int invert = (kcontrol->private_value >> 8) & 1;
808         int data;
809         
810         if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
811                 return data;
812         data = (data >> shift) & 1;
813         if (invert)
814                 data ^= 1;
815         ucontrol->value.integer.value[0] = data;
816         return 0;
817 }
818 
819 static int snd_ice1712_6fire_control_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
820 {
821         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
822         int shift = kcontrol->private_value & 0xff;
823         int invert = (kcontrol->private_value >> 8) & 1;
824         int data, ndata;
825         
826         if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
827                 return data;
828         ndata = data & ~(1 << shift);
829         if (ucontrol->value.integer.value[0])
830                 ndata |= (1 << shift);
831         if (invert)
832                 ndata ^= (1 << shift);
833         if (data != ndata) {
834                 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
835                 return 1;
836         }
837         return 0;
838 }
839 
840 static int snd_ice1712_6fire_select_input_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
841 {
842         static char *texts[4] = {
843                 "Internal", "Front Input", "Rear Input", "Wave Table"
844         };
845         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
846         uinfo->count = 1;
847         uinfo->value.enumerated.items = 4;
848         if (uinfo->value.enumerated.item >= 4)
849                 uinfo->value.enumerated.item = 1;
850         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
851         return 0;
852 }
853      
854 static int snd_ice1712_6fire_select_input_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
855 {
856         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
857         int data;
858         
859         if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
860                 return data;
861         ucontrol->value.integer.value[0] = data & 3;
862         return 0;
863 }
864 
865 static int snd_ice1712_6fire_select_input_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
866 {
867         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
868         int data, ndata;
869         
870         if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
871                 return data;
872         ndata = data & ~3;
873         ndata |= (ucontrol->value.integer.value[0] & 3);
874         if (data != ndata) {
875                 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
876                 return 1;
877         }
878         return 0;
879 }
880 
881 
882 #define DMX6FIRE_CONTROL(xname, xshift, xinvert) \
883 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
884   .name = xname,\
885   .info = snd_ice1712_6fire_control_info,\
886   .get = snd_ice1712_6fire_control_get,\
887   .put = snd_ice1712_6fire_control_put,\
888   .private_value = xshift | (xinvert << 8),\
889 }
890 
891 static snd_kcontrol_new_t snd_ice1712_6fire_controls[] __devinitdata = {
892         {
893                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
894                 .name = "Analog Input Select",
895                 .info = snd_ice1712_6fire_select_input_info,
896                 .get = snd_ice1712_6fire_select_input_get,
897                 .put = snd_ice1712_6fire_select_input_put,
898         },
899         DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 0),
900         // DMX6FIRE_CONTROL("Master Clock Select", 3, 0),
901         DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0),
902         DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0),
903         DMX6FIRE_CONTROL("Breakbox LED", 6, 0),
904 };
905 
906 
907 static int __devinit snd_ice1712_ews_add_controls(ice1712_t *ice)
908 {
909         unsigned int idx;
910         int err;
911         
912         /* all terratec cards have spdif, but cs8427 module builds it's own controls */
913         if (ice->cs8427 == NULL) {
914                 err = snd_ice1712_spdif_build_controls(ice);
915                 if (err < 0)
916                         return err;
917         }
918 
919         /* ak4524 controls */
920         switch (ice->eeprom.subvendor) {
921         case ICE1712_SUBDEVICE_EWX2496:
922         case ICE1712_SUBDEVICE_EWS88MT:
923         case ICE1712_SUBDEVICE_EWS88MT_NEW:
924         case ICE1712_SUBDEVICE_DMX6FIRE:
925                 err = snd_ice1712_akm4xxx_build_controls(ice);
926                 if (err < 0)
927                         return err;
928                 break;
929         }
930 
931         /* card specific controls */
932         switch (ice->eeprom.subvendor) {
933         case ICE1712_SUBDEVICE_EWX2496:
934                 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ewx2496_controls); idx++) {
935                         err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ewx2496_controls[idx], ice));
936                         if (err < 0)
937                                 return err;
938                 }
939                 break;
940         case ICE1712_SUBDEVICE_EWS88MT:
941         case ICE1712_SUBDEVICE_EWS88MT_NEW:
942                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice));
943                 if (err < 0)
944                         return err;
945                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense, ice));
946                 if (err < 0)
947                         return err;
948                 break;
949         case ICE1712_SUBDEVICE_EWS88D:
950                 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ews88d_controls); idx++) {
951                         err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_controls[idx], ice));
952                         if (err < 0)
953                                 return err;
954                 }
955                 break;
956         case ICE1712_SUBDEVICE_DMX6FIRE:
957                 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_6fire_controls); idx++) {
958                         err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_6fire_controls[idx], ice));
959                         if (err < 0)
960                                 return err;
961                 }
962                 break;
963         }
964         return 0;
965 }
966 
967 
968 /* entry point */
969 struct snd_ice1712_card_info snd_ice1712_ews_cards[] __devinitdata = {
970         {
971                 ICE1712_SUBDEVICE_EWX2496,
972                 "TerraTec EWX24/96",
973                 snd_ice1712_ews_init,
974                 snd_ice1712_ews_add_controls,
975         },
976         {
977                 ICE1712_SUBDEVICE_EWS88MT,
978                 "TerraTec EWS88MT",
979                 snd_ice1712_ews_init,
980                 snd_ice1712_ews_add_controls,
981         },
982         {
983                 ICE1712_SUBDEVICE_EWS88MT_NEW,
984                 "TerraTec EWS88MT",
985                 snd_ice1712_ews_init,
986                 snd_ice1712_ews_add_controls,
987         },
988         {
989                 ICE1712_SUBDEVICE_EWS88D,
990                 "TerraTec EWS88D",
991                 snd_ice1712_ews_init,
992                 snd_ice1712_ews_add_controls,
993         },
994         {
995                 ICE1712_SUBDEVICE_DMX6FIRE,
996                 "TerraTec DMX6Fire",
997                 snd_ice1712_ews_init,
998                 snd_ice1712_ews_add_controls,
999         },
1000         { } /* terminator */
1001 };
1002 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp