2 * ALSA driver for ICEnsemble ICE1712 (Envy24)
4 * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 - spdif nonaudio consumer mode does not work (at least with my
31 * 2002.09.09 Takashi Iwai <tiwai@suse.de>
32 * split the code to several files. each low-level routine
33 * is stored in the local file and called from registration
34 * function from card_info struct.
36 * 2002.11.26 James Stafford <jstafford@ampltd.com>
37 * Added support for VT1724 (Envy24HT)
38 * I have left out support for 176.4 and 192 KHz for the moment.
39 * I also haven't done anything with the internal S/PDIF transmitter or the MPU-401
41 * 2003.02.20 Taksahi Iwai <tiwai@suse.de>
42 * Split vt1724 part to an independent driver.
43 * The GPIO is accessed through the callback functions now.
45 * 2004.03.31 Doug McLain <nostar@comcast.net>
46 * Added support for Event Electronics EZ8 card to hoontech.c.
50 #include <sound/driver.h>
52 #include <linux/delay.h>
53 #include <linux/interrupt.h>
54 #include <linux/init.h>
55 #include <linux/pci.h>
56 #include <linux/slab.h>
57 #include <linux/moduleparam.h>
58 #include <linux/mutex.h>
59 #include <sound/core.h>
60 #include <sound/cs8427.h>
61 #include <sound/info.h>
62 #include <sound/mpu401.h>
63 #include <sound/initval.h>
65 #include <sound/asoundef.h>
69 /* lowlevel routines */
74 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
75 MODULE_DESCRIPTION("ICEnsemble ICE1712 (Envy24)");
76 MODULE_LICENSE("GPL");
77 MODULE_SUPPORTED_DEVICE("{"
81 "{ICEnsemble,Generic ICE1712},"
82 "{ICEnsemble,Generic Envy24}}");
84 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
85 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
86 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
87 static char *model[SNDRV_CARDS];
88 static int omni[SNDRV_CARDS]; /* Delta44 & 66 Omni I/O support */
89 static int cs8427_timeout[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 500}; /* CS8427 S/PDIF transciever reset timeout value in msec */
90 static int dxr_enable[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 500}; /* DXR enable for DMX6FIRE */
92 module_param_array(index, int, NULL, 0444);
93 MODULE_PARM_DESC(index, "Index value for ICE1712 soundcard.");
94 module_param_array(id, charp, NULL, 0444);
95 MODULE_PARM_DESC(id, "ID string for ICE1712 soundcard.");
96 module_param_array(enable, bool, NULL, 0444);
97 MODULE_PARM_DESC(enable, "Enable ICE1712 soundcard.");
98 module_param_array(omni, bool, NULL, 0444);
99 MODULE_PARM_DESC(omni, "Enable Midiman M-Audio Delta Omni I/O support.");
100 module_param_array(cs8427_timeout, int, NULL, 0444);
101 MODULE_PARM_DESC(cs8427_timeout, "Define reset timeout for cs8427 chip in msec resolution.");
102 module_param_array(model, charp, NULL, 0444);
103 MODULE_PARM_DESC(model, "Use the given board model.");
104 module_param_array(dxr_enable, int, NULL, 0444);
105 MODULE_PARM_DESC(dsr_enable, "Enable DXR support for Terratec DMX6FIRE.");
108 static struct pci_device_id snd_ice1712_ids[] = {
109 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_ICE_1712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* ICE1712 */
113 MODULE_DEVICE_TABLE(pci, snd_ice1712_ids);
115 static int snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice);
116 static int snd_ice1712_build_controls(struct snd_ice1712 *ice);
118 static int PRO_RATE_LOCKED;
119 static int PRO_RATE_RESET = 1;
120 static unsigned int PRO_RATE_DEFAULT = 44100;
126 /* check whether the clock mode is spdif-in */
127 static inline int is_spdif_master(struct snd_ice1712 *ice)
129 return (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER) ? 1 : 0;
132 static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
134 return is_spdif_master(ice) || PRO_RATE_LOCKED;
137 static inline void snd_ice1712_ds_write(struct snd_ice1712 * ice, u8 channel, u8 addr, u32 data)
139 outb((channel << 4) | addr, ICEDS(ice, INDEX));
140 outl(data, ICEDS(ice, DATA));
143 static inline u32 snd_ice1712_ds_read(struct snd_ice1712 * ice, u8 channel, u8 addr)
145 outb((channel << 4) | addr, ICEDS(ice, INDEX));
146 return inl(ICEDS(ice, DATA));
149 static void snd_ice1712_ac97_write(struct snd_ac97 *ac97,
153 struct snd_ice1712 *ice = ac97->private_data;
155 unsigned char old_cmd = 0;
157 for (tm = 0; tm < 0x10000; tm++) {
158 old_cmd = inb(ICEREG(ice, AC97_CMD));
159 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
161 if (!(old_cmd & ICE1712_AC97_READY))
165 outb(reg, ICEREG(ice, AC97_INDEX));
166 outw(val, ICEREG(ice, AC97_DATA));
167 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
168 outb(old_cmd | ICE1712_AC97_WRITE, ICEREG(ice, AC97_CMD));
169 for (tm = 0; tm < 0x10000; tm++)
170 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
174 static unsigned short snd_ice1712_ac97_read(struct snd_ac97 *ac97,
177 struct snd_ice1712 *ice = ac97->private_data;
179 unsigned char old_cmd = 0;
181 for (tm = 0; tm < 0x10000; tm++) {
182 old_cmd = inb(ICEREG(ice, AC97_CMD));
183 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
185 if (!(old_cmd & ICE1712_AC97_READY))
189 outb(reg, ICEREG(ice, AC97_INDEX));
190 outb(old_cmd | ICE1712_AC97_READ, ICEREG(ice, AC97_CMD));
191 for (tm = 0; tm < 0x10000; tm++)
192 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
194 if (tm >= 0x10000) /* timeout */
196 return inw(ICEREG(ice, AC97_DATA));
203 static void snd_ice1712_pro_ac97_write(struct snd_ac97 *ac97,
207 struct snd_ice1712 *ice = ac97->private_data;
209 unsigned char old_cmd = 0;
211 for (tm = 0; tm < 0x10000; tm++) {
212 old_cmd = inb(ICEMT(ice, AC97_CMD));
213 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
215 if (!(old_cmd & ICE1712_AC97_READY))
219 outb(reg, ICEMT(ice, AC97_INDEX));
220 outw(val, ICEMT(ice, AC97_DATA));
221 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
222 outb(old_cmd | ICE1712_AC97_WRITE, ICEMT(ice, AC97_CMD));
223 for (tm = 0; tm < 0x10000; tm++)
224 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
229 static unsigned short snd_ice1712_pro_ac97_read(struct snd_ac97 *ac97,
232 struct snd_ice1712 *ice = ac97->private_data;
234 unsigned char old_cmd = 0;
236 for (tm = 0; tm < 0x10000; tm++) {
237 old_cmd = inb(ICEMT(ice, AC97_CMD));
238 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
240 if (!(old_cmd & ICE1712_AC97_READY))
244 outb(reg, ICEMT(ice, AC97_INDEX));
245 outb(old_cmd | ICE1712_AC97_READ, ICEMT(ice, AC97_CMD));
246 for (tm = 0; tm < 0x10000; tm++)
247 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
249 if (tm >= 0x10000) /* timeout */
251 return inw(ICEMT(ice, AC97_DATA));
255 * consumer ac97 digital mix
257 static int snd_ice1712_digmix_route_ac97_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
259 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
261 uinfo->value.integer.min = 0;
262 uinfo->value.integer.max = 1;
266 static int snd_ice1712_digmix_route_ac97_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
268 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
270 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0;
274 static int snd_ice1712_digmix_route_ac97_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
276 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
277 unsigned char val, nval;
279 spin_lock_irq(&ice->reg_lock);
280 val = inb(ICEMT(ice, MONITOR_ROUTECTRL));
281 nval = val & ~ICE1712_ROUTE_AC97;
282 if (ucontrol->value.integer.value[0]) nval |= ICE1712_ROUTE_AC97;
283 outb(nval, ICEMT(ice, MONITOR_ROUTECTRL));
284 spin_unlock_irq(&ice->reg_lock);
288 static struct snd_kcontrol_new snd_ice1712_mixer_digmix_route_ac97 __devinitdata = {
289 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
290 .name = "Digital Mixer To AC97",
291 .info = snd_ice1712_digmix_route_ac97_info,
292 .get = snd_ice1712_digmix_route_ac97_get,
293 .put = snd_ice1712_digmix_route_ac97_put,
300 static void snd_ice1712_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
302 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, data);
303 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
306 static void snd_ice1712_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
308 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data);
309 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
312 static unsigned int snd_ice1712_get_gpio_data(struct snd_ice1712 *ice)
314 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
317 static void snd_ice1712_set_gpio_data(struct snd_ice1712 *ice, unsigned int val)
319 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, val);
320 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
330 * change the input clock selection
331 * spdif_clock = 1 - IEC958 input, 0 - Envy24
333 static int snd_ice1712_cs8427_set_input_clock(struct snd_ice1712 *ice, int spdif_clock)
335 unsigned char reg[2] = { 0x80 | 4, 0 }; /* CS8427 auto increment | register number 4 + data */
336 unsigned char val, nval;
339 snd_i2c_lock(ice->i2c);
340 if (snd_i2c_sendbytes(ice->cs8427, reg, 1) != 1) {
341 snd_i2c_unlock(ice->i2c);
344 if (snd_i2c_readbytes(ice->cs8427, &val, 1) != 1) {
345 snd_i2c_unlock(ice->i2c);
355 if (snd_i2c_sendbytes(ice->cs8427, reg, 2) != 2) {
361 snd_i2c_unlock(ice->i2c);
368 static void open_cs8427(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
370 snd_cs8427_iec958_active(ice->cs8427, 1);
373 static void close_cs8427(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
375 snd_cs8427_iec958_active(ice->cs8427, 0);
378 static void setup_cs8427(struct snd_ice1712 *ice, int rate)
380 snd_cs8427_iec958_pcm(ice->cs8427, rate);
384 * create and initialize callbacks for cs8427 interface
386 int __devinit snd_ice1712_init_cs8427(struct snd_ice1712 *ice, int addr)
390 if ((err = snd_cs8427_create(ice->i2c, addr,
391 (ice->cs8427_timeout * HZ) / 1000,
392 &ice->cs8427)) < 0) {
393 snd_printk(KERN_ERR "CS8427 initialization failed\n");
396 ice->spdif.ops.open = open_cs8427;
397 ice->spdif.ops.close = close_cs8427;
398 ice->spdif.ops.setup_rate = setup_cs8427;
402 static void snd_ice1712_set_input_clock_source(struct snd_ice1712 *ice, int spdif_is_master)
404 /* change CS8427 clock source too */
406 snd_ice1712_cs8427_set_input_clock(ice, spdif_is_master);
407 /* notify ak4524 chip as well */
408 if (spdif_is_master) {
410 for (i = 0; i < ice->akm_codecs; i++) {
411 if (ice->akm[i].ops.set_rate_val)
412 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
421 static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
423 struct snd_ice1712 *ice = dev_id;
424 unsigned char status;
428 status = inb(ICEREG(ice, IRQSTAT));
432 if (status & ICE1712_IRQ_MPU1) {
434 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data, regs);
435 outb(ICE1712_IRQ_MPU1, ICEREG(ice, IRQSTAT));
436 status &= ~ICE1712_IRQ_MPU1;
438 if (status & ICE1712_IRQ_TIMER)
439 outb(ICE1712_IRQ_TIMER, ICEREG(ice, IRQSTAT));
440 if (status & ICE1712_IRQ_MPU2) {
442 snd_mpu401_uart_interrupt(irq, ice->rmidi[1]->private_data, regs);
443 outb(ICE1712_IRQ_MPU2, ICEREG(ice, IRQSTAT));
444 status &= ~ICE1712_IRQ_MPU2;
446 if (status & ICE1712_IRQ_PROPCM) {
447 unsigned char mtstat = inb(ICEMT(ice, IRQ));
448 if (mtstat & ICE1712_MULTI_PBKSTATUS) {
449 if (ice->playback_pro_substream)
450 snd_pcm_period_elapsed(ice->playback_pro_substream);
451 outb(ICE1712_MULTI_PBKSTATUS, ICEMT(ice, IRQ));
453 if (mtstat & ICE1712_MULTI_CAPSTATUS) {
454 if (ice->capture_pro_substream)
455 snd_pcm_period_elapsed(ice->capture_pro_substream);
456 outb(ICE1712_MULTI_CAPSTATUS, ICEMT(ice, IRQ));
459 if (status & ICE1712_IRQ_FM)
460 outb(ICE1712_IRQ_FM, ICEREG(ice, IRQSTAT));
461 if (status & ICE1712_IRQ_PBKDS) {
464 struct snd_pcm_substream *substream;
465 pbkstatus = inw(ICEDS(ice, INTSTAT));
466 //printk("pbkstatus = 0x%x\n", pbkstatus);
467 for (idx = 0; idx < 6; idx++) {
468 if ((pbkstatus & (3 << (idx * 2))) == 0)
470 if ((substream = ice->playback_con_substream_ds[idx]) != NULL)
471 snd_pcm_period_elapsed(substream);
472 outw(3 << (idx * 2), ICEDS(ice, INTSTAT));
474 outb(ICE1712_IRQ_PBKDS, ICEREG(ice, IRQSTAT));
476 if (status & ICE1712_IRQ_CONCAP) {
477 if (ice->capture_con_substream)
478 snd_pcm_period_elapsed(ice->capture_con_substream);
479 outb(ICE1712_IRQ_CONCAP, ICEREG(ice, IRQSTAT));
481 if (status & ICE1712_IRQ_CONPBK) {
482 if (ice->playback_con_substream)
483 snd_pcm_period_elapsed(ice->playback_con_substream);
484 outb(ICE1712_IRQ_CONPBK, ICEREG(ice, IRQSTAT));
487 return IRQ_RETVAL(handled);
495 static int snd_ice1712_hw_params(struct snd_pcm_substream *substream,
496 struct snd_pcm_hw_params *hw_params)
498 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
501 static int snd_ice1712_hw_free(struct snd_pcm_substream *substream)
503 return snd_pcm_lib_free_pages(substream);
507 * PCM part - consumer I/O
510 static int snd_ice1712_playback_trigger(struct snd_pcm_substream *substream,
513 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
517 spin_lock(&ice->reg_lock);
518 tmp = snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL);
519 if (cmd == SNDRV_PCM_TRIGGER_START) {
521 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
523 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
525 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
530 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
531 spin_unlock(&ice->reg_lock);
535 static int snd_ice1712_playback_ds_trigger(struct snd_pcm_substream *substream,
538 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
542 spin_lock(&ice->reg_lock);
543 tmp = snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL);
544 if (cmd == SNDRV_PCM_TRIGGER_START) {
546 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
548 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
550 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
555 snd_ice1712_ds_write(ice, substream->number * 2, ICE1712_DSC_CONTROL, tmp);
556 spin_unlock(&ice->reg_lock);
560 static int snd_ice1712_capture_trigger(struct snd_pcm_substream *substream,
563 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
567 spin_lock(&ice->reg_lock);
568 tmp = snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL);
569 if (cmd == SNDRV_PCM_TRIGGER_START) {
571 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
576 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
577 spin_unlock(&ice->reg_lock);
581 static int snd_ice1712_playback_prepare(struct snd_pcm_substream *substream)
583 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
584 struct snd_pcm_runtime *runtime = substream->runtime;
585 u32 period_size, buf_size, rate, tmp;
587 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
588 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
590 if (snd_pcm_format_width(runtime->format) == 16)
592 if (runtime->channels == 2)
594 rate = (runtime->rate * 8192) / 375;
595 if (rate > 0x000fffff)
597 spin_lock_irq(&ice->reg_lock);
598 outb(0, ice->ddma_port + 15);
599 outb(ICE1712_DMA_MODE_WRITE | ICE1712_DMA_AUTOINIT, ice->ddma_port + 0x0b);
600 outl(runtime->dma_addr, ice->ddma_port + 0);
601 outw(buf_size, ice->ddma_port + 4);
602 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_LO, rate & 0xff);
603 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_MID, (rate >> 8) & 0xff);
604 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_HI, (rate >> 16) & 0xff);
605 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
606 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_LO, period_size & 0xff);
607 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_HI, period_size >> 8);
608 snd_ice1712_write(ice, ICE1712_IREG_PBK_LEFT, 0);
609 snd_ice1712_write(ice, ICE1712_IREG_PBK_RIGHT, 0);
610 spin_unlock_irq(&ice->reg_lock);
614 static int snd_ice1712_playback_ds_prepare(struct snd_pcm_substream *substream)
616 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
617 struct snd_pcm_runtime *runtime = substream->runtime;
618 u32 period_size, buf_size, rate, tmp, chn;
620 period_size = snd_pcm_lib_period_bytes(substream) - 1;
621 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
623 if (snd_pcm_format_width(runtime->format) == 16)
625 if (runtime->channels == 2)
627 rate = (runtime->rate * 8192) / 375;
628 if (rate > 0x000fffff)
630 ice->playback_con_active_buf[substream->number] = 0;
631 ice->playback_con_virt_addr[substream->number] = runtime->dma_addr;
632 chn = substream->number * 2;
633 spin_lock_irq(&ice->reg_lock);
634 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR0, runtime->dma_addr);
635 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT0, period_size);
636 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR1, runtime->dma_addr + (runtime->periods > 1 ? period_size + 1 : 0));
637 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT1, period_size);
638 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_RATE, rate);
639 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_VOLUME, 0);
640 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_CONTROL, tmp);
641 if (runtime->channels == 2) {
642 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_RATE, rate);
643 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_VOLUME, 0);
645 spin_unlock_irq(&ice->reg_lock);
649 static int snd_ice1712_capture_prepare(struct snd_pcm_substream *substream)
651 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
652 struct snd_pcm_runtime *runtime = substream->runtime;
653 u32 period_size, buf_size;
656 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
657 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
659 if (snd_pcm_format_width(runtime->format) == 16)
661 if (runtime->channels == 2)
663 spin_lock_irq(&ice->reg_lock);
664 outl(ice->capture_con_virt_addr = runtime->dma_addr, ICEREG(ice, CONCAP_ADDR));
665 outw(buf_size, ICEREG(ice, CONCAP_COUNT));
666 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_HI, period_size >> 8);
667 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_LO, period_size & 0xff);
668 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
669 spin_unlock_irq(&ice->reg_lock);
670 snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
674 static snd_pcm_uframes_t snd_ice1712_playback_pointer(struct snd_pcm_substream *substream)
676 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
677 struct snd_pcm_runtime *runtime = substream->runtime;
680 if (!(snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL) & 1))
682 ptr = runtime->buffer_size - inw(ice->ddma_port + 4);
683 if (ptr == runtime->buffer_size)
685 return bytes_to_frames(substream->runtime, ptr);
688 static snd_pcm_uframes_t snd_ice1712_playback_ds_pointer(struct snd_pcm_substream *substream)
690 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
694 if (!(snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL) & 1))
696 if (ice->playback_con_active_buf[substream->number])
697 addr = ICE1712_DSC_ADDR1;
699 addr = ICE1712_DSC_ADDR0;
700 ptr = snd_ice1712_ds_read(ice, substream->number * 2, addr) -
701 ice->playback_con_virt_addr[substream->number];
702 if (ptr == substream->runtime->buffer_size)
704 return bytes_to_frames(substream->runtime, ptr);
707 static snd_pcm_uframes_t snd_ice1712_capture_pointer(struct snd_pcm_substream *substream)
709 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
712 if (!(snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL) & 1))
714 ptr = inl(ICEREG(ice, CONCAP_ADDR)) - ice->capture_con_virt_addr;
715 if (ptr == substream->runtime->buffer_size)
717 return bytes_to_frames(substream->runtime, ptr);
720 static struct snd_pcm_hardware snd_ice1712_playback =
722 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
723 SNDRV_PCM_INFO_BLOCK_TRANSFER |
724 SNDRV_PCM_INFO_MMAP_VALID |
725 SNDRV_PCM_INFO_PAUSE),
726 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
727 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
732 .buffer_bytes_max = (64*1024),
733 .period_bytes_min = 64,
734 .period_bytes_max = (64*1024),
740 static struct snd_pcm_hardware snd_ice1712_playback_ds =
742 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
743 SNDRV_PCM_INFO_BLOCK_TRANSFER |
744 SNDRV_PCM_INFO_MMAP_VALID |
745 SNDRV_PCM_INFO_PAUSE),
746 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
747 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
752 .buffer_bytes_max = (128*1024),
753 .period_bytes_min = 64,
754 .period_bytes_max = (128*1024),
760 static struct snd_pcm_hardware snd_ice1712_capture =
762 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
763 SNDRV_PCM_INFO_BLOCK_TRANSFER |
764 SNDRV_PCM_INFO_MMAP_VALID),
765 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
766 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
771 .buffer_bytes_max = (64*1024),
772 .period_bytes_min = 64,
773 .period_bytes_max = (64*1024),
779 static int snd_ice1712_playback_open(struct snd_pcm_substream *substream)
781 struct snd_pcm_runtime *runtime = substream->runtime;
782 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
784 ice->playback_con_substream = substream;
785 runtime->hw = snd_ice1712_playback;
789 static int snd_ice1712_playback_ds_open(struct snd_pcm_substream *substream)
791 struct snd_pcm_runtime *runtime = substream->runtime;
792 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
795 ice->playback_con_substream_ds[substream->number] = substream;
796 runtime->hw = snd_ice1712_playback_ds;
797 spin_lock_irq(&ice->reg_lock);
798 tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2));
799 outw(tmp, ICEDS(ice, INTMASK));
800 spin_unlock_irq(&ice->reg_lock);
804 static int snd_ice1712_capture_open(struct snd_pcm_substream *substream)
806 struct snd_pcm_runtime *runtime = substream->runtime;
807 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
809 ice->capture_con_substream = substream;
810 runtime->hw = snd_ice1712_capture;
811 runtime->hw.rates = ice->ac97->rates[AC97_RATES_ADC];
812 if (!(runtime->hw.rates & SNDRV_PCM_RATE_8000))
813 runtime->hw.rate_min = 48000;
817 static int snd_ice1712_playback_close(struct snd_pcm_substream *substream)
819 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
821 ice->playback_con_substream = NULL;
825 static int snd_ice1712_playback_ds_close(struct snd_pcm_substream *substream)
827 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
830 spin_lock_irq(&ice->reg_lock);
831 tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2));
832 outw(tmp, ICEDS(ice, INTMASK));
833 spin_unlock_irq(&ice->reg_lock);
834 ice->playback_con_substream_ds[substream->number] = NULL;
838 static int snd_ice1712_capture_close(struct snd_pcm_substream *substream)
840 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
842 ice->capture_con_substream = NULL;
846 static struct snd_pcm_ops snd_ice1712_playback_ops = {
847 .open = snd_ice1712_playback_open,
848 .close = snd_ice1712_playback_close,
849 .ioctl = snd_pcm_lib_ioctl,
850 .hw_params = snd_ice1712_hw_params,
851 .hw_free = snd_ice1712_hw_free,
852 .prepare = snd_ice1712_playback_prepare,
853 .trigger = snd_ice1712_playback_trigger,
854 .pointer = snd_ice1712_playback_pointer,
857 static struct snd_pcm_ops snd_ice1712_playback_ds_ops = {
858 .open = snd_ice1712_playback_ds_open,
859 .close = snd_ice1712_playback_ds_close,
860 .ioctl = snd_pcm_lib_ioctl,
861 .hw_params = snd_ice1712_hw_params,
862 .hw_free = snd_ice1712_hw_free,
863 .prepare = snd_ice1712_playback_ds_prepare,
864 .trigger = snd_ice1712_playback_ds_trigger,
865 .pointer = snd_ice1712_playback_ds_pointer,
868 static struct snd_pcm_ops snd_ice1712_capture_ops = {
869 .open = snd_ice1712_capture_open,
870 .close = snd_ice1712_capture_close,
871 .ioctl = snd_pcm_lib_ioctl,
872 .hw_params = snd_ice1712_hw_params,
873 .hw_free = snd_ice1712_hw_free,
874 .prepare = snd_ice1712_capture_prepare,
875 .trigger = snd_ice1712_capture_trigger,
876 .pointer = snd_ice1712_capture_pointer,
879 static int __devinit snd_ice1712_pcm(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
886 err = snd_pcm_new(ice->card, "ICE1712 consumer", device, 1, 1, &pcm);
890 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ops);
891 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_ops);
893 pcm->private_data = ice;
895 strcpy(pcm->name, "ICE1712 consumer");
898 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
899 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
904 printk(KERN_WARNING "Consumer PCM code does not work well at the moment --jk\n");
909 static int __devinit snd_ice1712_pcm_ds(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
916 err = snd_pcm_new(ice->card, "ICE1712 consumer (DS)", device, 6, 0, &pcm);
920 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ds_ops);
922 pcm->private_data = ice;
924 strcpy(pcm->name, "ICE1712 consumer (DS)");
927 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
928 snd_dma_pci_data(ice->pci), 64*1024, 128*1024);
937 * PCM code - professional part (multitrack)
940 static unsigned int rates[] = { 8000, 9600, 11025, 12000, 16000, 22050, 24000,
941 32000, 44100, 48000, 64000, 88200, 96000 };
943 static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
944 .count = ARRAY_SIZE(rates),
949 static int snd_ice1712_pro_trigger(struct snd_pcm_substream *substream,
952 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
954 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
955 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
959 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
961 what = ICE1712_PLAYBACK_PAUSE;
962 snd_pcm_trigger_done(substream, substream);
963 spin_lock(&ice->reg_lock);
964 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
965 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
969 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
970 spin_unlock(&ice->reg_lock);
973 case SNDRV_PCM_TRIGGER_START:
974 case SNDRV_PCM_TRIGGER_STOP:
976 unsigned int what = 0;
978 struct list_head *pos;
979 struct snd_pcm_substream *s;
981 snd_pcm_group_for_each(pos, substream) {
982 s = snd_pcm_group_substream_entry(pos);
983 if (s == ice->playback_pro_substream) {
984 what |= ICE1712_PLAYBACK_START;
985 snd_pcm_trigger_done(s, substream);
986 } else if (s == ice->capture_pro_substream) {
987 what |= ICE1712_CAPTURE_START_SHADOW;
988 snd_pcm_trigger_done(s, substream);
991 spin_lock(&ice->reg_lock);
992 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
993 if (cmd == SNDRV_PCM_TRIGGER_START)
997 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
998 spin_unlock(&ice->reg_lock);
1009 static void snd_ice1712_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate, int force)
1011 unsigned long flags;
1012 unsigned char val, old;
1016 case 8000: val = 6; break;
1017 case 9600: val = 3; break;
1018 case 11025: val = 10; break;
1019 case 12000: val = 2; break;
1020 case 16000: val = 5; break;
1021 case 22050: val = 9; break;
1022 case 24000: val = 1; break;
1023 case 32000: val = 4; break;
1024 case 44100: val = 8; break;
1025 case 48000: val = 0; break;
1026 case 64000: val = 15; break;
1027 case 88200: val = 11; break;
1028 case 96000: val = 7; break;
1036 spin_lock_irqsave(&ice->reg_lock, flags);
1037 if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
1038 ICE1712_PLAYBACK_PAUSE|
1039 ICE1712_PLAYBACK_START)) {
1041 spin_unlock_irqrestore(&ice->reg_lock, flags);
1044 if (!force && is_pro_rate_locked(ice))
1047 old = inb(ICEMT(ice, RATE));
1048 if (!force && old == val)
1050 outb(val, ICEMT(ice, RATE));
1051 spin_unlock_irqrestore(&ice->reg_lock, flags);
1053 if (ice->gpio.set_pro_rate)
1054 ice->gpio.set_pro_rate(ice, rate);
1055 for (i = 0; i < ice->akm_codecs; i++) {
1056 if (ice->akm[i].ops.set_rate_val)
1057 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
1059 if (ice->spdif.ops.setup_rate)
1060 ice->spdif.ops.setup_rate(ice, rate);
1063 static int snd_ice1712_playback_pro_prepare(struct snd_pcm_substream *substream)
1065 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1067 ice->playback_pro_size = snd_pcm_lib_buffer_bytes(substream);
1068 spin_lock_irq(&ice->reg_lock);
1069 outl(substream->runtime->dma_addr, ICEMT(ice, PLAYBACK_ADDR));
1070 outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));
1071 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT));
1072 spin_unlock_irq(&ice->reg_lock);
1077 static int snd_ice1712_playback_pro_hw_params(struct snd_pcm_substream *substream,
1078 struct snd_pcm_hw_params *hw_params)
1080 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1082 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1083 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1086 static int snd_ice1712_capture_pro_prepare(struct snd_pcm_substream *substream)
1088 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1090 ice->capture_pro_size = snd_pcm_lib_buffer_bytes(substream);
1091 spin_lock_irq(&ice->reg_lock);
1092 outl(substream->runtime->dma_addr, ICEMT(ice, CAPTURE_ADDR));
1093 outw((ice->capture_pro_size >> 2) - 1, ICEMT(ice, CAPTURE_SIZE));
1094 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, CAPTURE_COUNT));
1095 spin_unlock_irq(&ice->reg_lock);
1099 static int snd_ice1712_capture_pro_hw_params(struct snd_pcm_substream *substream,
1100 struct snd_pcm_hw_params *hw_params)
1102 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1104 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1105 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1108 static snd_pcm_uframes_t snd_ice1712_playback_pro_pointer(struct snd_pcm_substream *substream)
1110 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1113 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_PLAYBACK_START))
1115 ptr = ice->playback_pro_size - (inw(ICEMT(ice, PLAYBACK_SIZE)) << 2);
1116 if (ptr == substream->runtime->buffer_size)
1118 return bytes_to_frames(substream->runtime, ptr);
1121 static snd_pcm_uframes_t snd_ice1712_capture_pro_pointer(struct snd_pcm_substream *substream)
1123 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1126 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_CAPTURE_START_SHADOW))
1128 ptr = ice->capture_pro_size - (inw(ICEMT(ice, CAPTURE_SIZE)) << 2);
1129 if (ptr == substream->runtime->buffer_size)
1131 return bytes_to_frames(substream->runtime, ptr);
1134 static struct snd_pcm_hardware snd_ice1712_playback_pro =
1136 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1137 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1138 SNDRV_PCM_INFO_MMAP_VALID |
1139 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1140 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1141 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1146 .buffer_bytes_max = (256*1024),
1147 .period_bytes_min = 10 * 4 * 2,
1148 .period_bytes_max = 131040,
1150 .periods_max = 1024,
1154 static struct snd_pcm_hardware snd_ice1712_capture_pro =
1156 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1157 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1158 SNDRV_PCM_INFO_MMAP_VALID |
1159 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1160 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1161 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1166 .buffer_bytes_max = (256*1024),
1167 .period_bytes_min = 12 * 4 * 2,
1168 .period_bytes_max = 131040,
1170 .periods_max = 1024,
1174 static int snd_ice1712_playback_pro_open(struct snd_pcm_substream *substream)
1176 struct snd_pcm_runtime *runtime = substream->runtime;
1177 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1179 ice->playback_pro_substream = substream;
1180 runtime->hw = snd_ice1712_playback_pro;
1181 snd_pcm_set_sync(substream);
1182 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1183 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1185 if (ice->spdif.ops.open)
1186 ice->spdif.ops.open(ice, substream);
1191 static int snd_ice1712_capture_pro_open(struct snd_pcm_substream *substream)
1193 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1194 struct snd_pcm_runtime *runtime = substream->runtime;
1196 ice->capture_pro_substream = substream;
1197 runtime->hw = snd_ice1712_capture_pro;
1198 snd_pcm_set_sync(substream);
1199 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1200 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1204 static int snd_ice1712_playback_pro_close(struct snd_pcm_substream *substream)
1206 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1209 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1210 ice->playback_pro_substream = NULL;
1211 if (ice->spdif.ops.close)
1212 ice->spdif.ops.close(ice, substream);
1217 static int snd_ice1712_capture_pro_close(struct snd_pcm_substream *substream)
1219 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1222 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1223 ice->capture_pro_substream = NULL;
1227 static struct snd_pcm_ops snd_ice1712_playback_pro_ops = {
1228 .open = snd_ice1712_playback_pro_open,
1229 .close = snd_ice1712_playback_pro_close,
1230 .ioctl = snd_pcm_lib_ioctl,
1231 .hw_params = snd_ice1712_playback_pro_hw_params,
1232 .hw_free = snd_ice1712_hw_free,
1233 .prepare = snd_ice1712_playback_pro_prepare,
1234 .trigger = snd_ice1712_pro_trigger,
1235 .pointer = snd_ice1712_playback_pro_pointer,
1238 static struct snd_pcm_ops snd_ice1712_capture_pro_ops = {
1239 .open = snd_ice1712_capture_pro_open,
1240 .close = snd_ice1712_capture_pro_close,
1241 .ioctl = snd_pcm_lib_ioctl,
1242 .hw_params = snd_ice1712_capture_pro_hw_params,
1243 .hw_free = snd_ice1712_hw_free,
1244 .prepare = snd_ice1712_capture_pro_prepare,
1245 .trigger = snd_ice1712_pro_trigger,
1246 .pointer = snd_ice1712_capture_pro_pointer,
1249 static int __devinit snd_ice1712_pcm_profi(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
1251 struct snd_pcm *pcm;
1256 err = snd_pcm_new(ice->card, "ICE1712 multi", device, 1, 1, &pcm);
1260 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_pro_ops);
1261 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_pro_ops);
1263 pcm->private_data = ice;
1264 pcm->info_flags = 0;
1265 strcpy(pcm->name, "ICE1712 multi");
1267 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1268 snd_dma_pci_data(ice->pci), 256*1024, 256*1024);
1275 /* assign channels to iec958 */
1276 err = snd_cs8427_iec958_build(ice->cs8427,
1277 pcm->streams[0].substream,
1278 pcm->streams[1].substream);
1283 if ((err = snd_ice1712_build_pro_mixer(ice)) < 0)
1292 static void snd_ice1712_update_volume(struct snd_ice1712 *ice, int index)
1294 unsigned int vol = ice->pro_volumes[index];
1295 unsigned short val = 0;
1297 val |= (vol & 0x8000) == 0 ? (96 - (vol & 0x7f)) : 0x7f;
1298 val |= ((vol & 0x80000000) == 0 ? (96 - ((vol >> 16) & 0x7f)) : 0x7f) << 8;
1299 outb(index, ICEMT(ice, MONITOR_INDEX));
1300 outw(val, ICEMT(ice, MONITOR_VOLUME));
1303 static int snd_ice1712_pro_mixer_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1305 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1307 uinfo->value.integer.min = 0;
1308 uinfo->value.integer.max = 1;
1312 static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1314 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1315 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1317 spin_lock_irq(&ice->reg_lock);
1318 ucontrol->value.integer.value[0] = !((ice->pro_volumes[index] >> 15) & 1);
1319 ucontrol->value.integer.value[1] = !((ice->pro_volumes[index] >> 31) & 1);
1320 spin_unlock_irq(&ice->reg_lock);
1324 static int snd_ice1712_pro_mixer_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1326 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1327 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1328 unsigned int nval, change;
1330 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
1331 (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
1332 spin_lock_irq(&ice->reg_lock);
1333 nval |= ice->pro_volumes[index] & ~0x80008000;
1334 change = nval != ice->pro_volumes[index];
1335 ice->pro_volumes[index] = nval;
1336 snd_ice1712_update_volume(ice, index);
1337 spin_unlock_irq(&ice->reg_lock);
1341 static int snd_ice1712_pro_mixer_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1343 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1345 uinfo->value.integer.min = 0;
1346 uinfo->value.integer.max = 96;
1350 static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1352 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1353 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1355 spin_lock_irq(&ice->reg_lock);
1356 ucontrol->value.integer.value[0] = (ice->pro_volumes[index] >> 0) & 127;
1357 ucontrol->value.integer.value[1] = (ice->pro_volumes[index] >> 16) & 127;
1358 spin_unlock_irq(&ice->reg_lock);
1362 static int snd_ice1712_pro_mixer_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1364 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1365 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1366 unsigned int nval, change;
1368 nval = (ucontrol->value.integer.value[0] & 127) |
1369 ((ucontrol->value.integer.value[1] & 127) << 16);
1370 spin_lock_irq(&ice->reg_lock);
1371 nval |= ice->pro_volumes[index] & ~0x007f007f;
1372 change = nval != ice->pro_volumes[index];
1373 ice->pro_volumes[index] = nval;
1374 snd_ice1712_update_volume(ice, index);
1375 spin_unlock_irq(&ice->reg_lock);
1380 static struct snd_kcontrol_new snd_ice1712_multi_playback_ctrls[] __devinitdata = {
1382 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1383 .name = "Multi Playback Switch",
1384 .info = snd_ice1712_pro_mixer_switch_info,
1385 .get = snd_ice1712_pro_mixer_switch_get,
1386 .put = snd_ice1712_pro_mixer_switch_put,
1391 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1392 .name = "Multi Playback Volume",
1393 .info = snd_ice1712_pro_mixer_volume_info,
1394 .get = snd_ice1712_pro_mixer_volume_get,
1395 .put = snd_ice1712_pro_mixer_volume_put,
1401 static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_switch __devinitdata = {
1402 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1403 .name = "H/W Multi Capture Switch",
1404 .info = snd_ice1712_pro_mixer_switch_info,
1405 .get = snd_ice1712_pro_mixer_switch_get,
1406 .put = snd_ice1712_pro_mixer_switch_put,
1407 .private_value = 10,
1410 static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_switch __devinitdata = {
1411 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1412 .name = SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE,SWITCH),
1413 .info = snd_ice1712_pro_mixer_switch_info,
1414 .get = snd_ice1712_pro_mixer_switch_get,
1415 .put = snd_ice1712_pro_mixer_switch_put,
1416 .private_value = 18,
1420 static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_volume __devinitdata = {
1421 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1422 .name = "H/W Multi Capture Volume",
1423 .info = snd_ice1712_pro_mixer_volume_info,
1424 .get = snd_ice1712_pro_mixer_volume_get,
1425 .put = snd_ice1712_pro_mixer_volume_put,
1426 .private_value = 10,
1429 static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_volume __devinitdata = {
1430 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1431 .name = SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE,VOLUME),
1432 .info = snd_ice1712_pro_mixer_volume_info,
1433 .get = snd_ice1712_pro_mixer_volume_get,
1434 .put = snd_ice1712_pro_mixer_volume_put,
1435 .private_value = 18,
1439 static int __devinit snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice)
1441 struct snd_card *card = ice->card;
1445 /* multi-channel mixer */
1446 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_multi_playback_ctrls); idx++) {
1447 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_playback_ctrls[idx], ice));
1452 if (ice->num_total_adcs > 0) {
1453 struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_switch;
1454 tmp.count = ice->num_total_adcs;
1455 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1460 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_switch, ice));
1464 if (ice->num_total_adcs > 0) {
1465 struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_volume;
1466 tmp.count = ice->num_total_adcs;
1467 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1472 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_volume, ice));
1476 /* initialize volumes */
1477 for (idx = 0; idx < 10; idx++) {
1478 ice->pro_volumes[idx] = 0x80008000; /* mute */
1479 snd_ice1712_update_volume(ice, idx);
1481 for (idx = 10; idx < 10 + ice->num_total_adcs; idx++) {
1482 ice->pro_volumes[idx] = 0x80008000; /* mute */
1483 snd_ice1712_update_volume(ice, idx);
1485 for (idx = 18; idx < 20; idx++) {
1486 ice->pro_volumes[idx] = 0x80008000; /* mute */
1487 snd_ice1712_update_volume(ice, idx);
1492 static void snd_ice1712_mixer_free_ac97(struct snd_ac97 *ac97)
1494 struct snd_ice1712 *ice = ac97->private_data;
1498 static int __devinit snd_ice1712_ac97_mixer(struct snd_ice1712 * ice)
1500 int err, bus_num = 0;
1501 struct snd_ac97_template ac97;
1502 struct snd_ac97_bus *pbus;
1503 static struct snd_ac97_bus_ops con_ops = {
1504 .write = snd_ice1712_ac97_write,
1505 .read = snd_ice1712_ac97_read,
1507 static struct snd_ac97_bus_ops pro_ops = {
1508 .write = snd_ice1712_pro_ac97_write,
1509 .read = snd_ice1712_pro_ac97_read,
1512 if (ice_has_con_ac97(ice)) {
1513 if ((err = snd_ac97_bus(ice->card, bus_num++, &con_ops, NULL, &pbus)) < 0)
1515 memset(&ac97, 0, sizeof(ac97));
1516 ac97.private_data = ice;
1517 ac97.private_free = snd_ice1712_mixer_free_ac97;
1518 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1519 printk(KERN_WARNING "ice1712: cannot initialize ac97 for consumer, skipped\n");
1521 if ((err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice))) < 0)
1527 if (! (ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) {
1528 if ((err = snd_ac97_bus(ice->card, bus_num, &pro_ops, NULL, &pbus)) < 0)
1530 memset(&ac97, 0, sizeof(ac97));
1531 ac97.private_data = ice;
1532 ac97.private_free = snd_ice1712_mixer_free_ac97;
1533 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1534 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1538 /* I2S mixer only */
1539 strcat(ice->card->mixername, "ICE1712 - multitrack");
1547 static inline unsigned int eeprom_double(struct snd_ice1712 *ice, int idx)
1549 return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8);
1552 static void snd_ice1712_proc_read(struct snd_info_entry *entry,
1553 struct snd_info_buffer *buffer)
1555 struct snd_ice1712 *ice = entry->private_data;
1558 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1559 snd_iprintf(buffer, "EEPROM:\n");
1561 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1562 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1563 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1564 snd_iprintf(buffer, " Codec : 0x%x\n", ice->eeprom.data[ICE_EEP1_CODEC]);
1565 snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP1_ACLINK]);
1566 snd_iprintf(buffer, " I2S ID : 0x%x\n", ice->eeprom.data[ICE_EEP1_I2SID]);
1567 snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP1_SPDIF]);
1568 snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
1569 snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
1570 snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
1571 snd_iprintf(buffer, " AC'97 main : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_MAIN_LO));
1572 snd_iprintf(buffer, " AC'97 pcm : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_PCM_LO));
1573 snd_iprintf(buffer, " AC'97 record : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_REC_LO));
1574 snd_iprintf(buffer, " AC'97 record src : 0x%x\n", ice->eeprom.data[ICE_EEP1_AC97_RECSRC]);
1575 for (idx = 0; idx < 4; idx++)
1576 snd_iprintf(buffer, " DAC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_DAC_ID + idx]);
1577 for (idx = 0; idx < 4; idx++)
1578 snd_iprintf(buffer, " ADC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_ADC_ID + idx]);
1579 for (idx = 0x1c; idx < ice->eeprom.size; idx++)
1580 snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
1582 snd_iprintf(buffer, "\nRegisters:\n");
1583 snd_iprintf(buffer, " PSDOUT03 : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_PSDOUT03)));
1584 snd_iprintf(buffer, " CAPTURE : 0x%08x\n", inl(ICEMT(ice, ROUTE_CAPTURE)));
1585 snd_iprintf(buffer, " SPDOUT : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT)));
1586 snd_iprintf(buffer, " RATE : 0x%02x\n", (unsigned)inb(ICEMT(ice, RATE)));
1589 static void __devinit snd_ice1712_proc_init(struct snd_ice1712 * ice)
1591 struct snd_info_entry *entry;
1593 if (! snd_card_proc_new(ice->card, "ice1712", &entry))
1594 snd_info_set_text_ops(entry, ice, 1024, snd_ice1712_proc_read);
1601 static int snd_ice1712_eeprom_info(struct snd_kcontrol *kcontrol,
1602 struct snd_ctl_elem_info *uinfo)
1604 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1605 uinfo->count = sizeof(struct snd_ice1712_eeprom);
1609 static int snd_ice1712_eeprom_get(struct snd_kcontrol *kcontrol,
1610 struct snd_ctl_elem_value *ucontrol)
1612 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1614 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1618 static struct snd_kcontrol_new snd_ice1712_eeprom __devinitdata = {
1619 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1620 .name = "ICE1712 EEPROM",
1621 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1622 .info = snd_ice1712_eeprom_info,
1623 .get = snd_ice1712_eeprom_get
1628 static int snd_ice1712_spdif_info(struct snd_kcontrol *kcontrol,
1629 struct snd_ctl_elem_info *uinfo)
1631 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1636 static int snd_ice1712_spdif_default_get(struct snd_kcontrol *kcontrol,
1637 struct snd_ctl_elem_value *ucontrol)
1639 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1640 if (ice->spdif.ops.default_get)
1641 ice->spdif.ops.default_get(ice, ucontrol);
1645 static int snd_ice1712_spdif_default_put(struct snd_kcontrol *kcontrol,
1646 struct snd_ctl_elem_value *ucontrol)
1648 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1649 if (ice->spdif.ops.default_put)
1650 return ice->spdif.ops.default_put(ice, ucontrol);
1654 static struct snd_kcontrol_new snd_ice1712_spdif_default __devinitdata =
1656 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1657 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1658 .info = snd_ice1712_spdif_info,
1659 .get = snd_ice1712_spdif_default_get,
1660 .put = snd_ice1712_spdif_default_put
1663 static int snd_ice1712_spdif_maskc_get(struct snd_kcontrol *kcontrol,
1664 struct snd_ctl_elem_value *ucontrol)
1666 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1667 if (ice->spdif.ops.default_get) {
1668 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1669 IEC958_AES0_PROFESSIONAL |
1670 IEC958_AES0_CON_NOT_COPYRIGHT |
1671 IEC958_AES0_CON_EMPHASIS;
1672 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1673 IEC958_AES1_CON_CATEGORY;
1674 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1676 ucontrol->value.iec958.status[0] = 0xff;
1677 ucontrol->value.iec958.status[1] = 0xff;
1678 ucontrol->value.iec958.status[2] = 0xff;
1679 ucontrol->value.iec958.status[3] = 0xff;
1680 ucontrol->value.iec958.status[4] = 0xff;
1685 static int snd_ice1712_spdif_maskp_get(struct snd_kcontrol *kcontrol,
1686 struct snd_ctl_elem_value *ucontrol)
1688 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1689 if (ice->spdif.ops.default_get) {
1690 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1691 IEC958_AES0_PROFESSIONAL |
1692 IEC958_AES0_PRO_FS |
1693 IEC958_AES0_PRO_EMPHASIS;
1694 ucontrol->value.iec958.status[1] = IEC958_AES1_PRO_MODE;
1696 ucontrol->value.iec958.status[0] = 0xff;
1697 ucontrol->value.iec958.status[1] = 0xff;
1698 ucontrol->value.iec958.status[2] = 0xff;
1699 ucontrol->value.iec958.status[3] = 0xff;
1700 ucontrol->value.iec958.status[4] = 0xff;
1705 static struct snd_kcontrol_new snd_ice1712_spdif_maskc __devinitdata =
1707 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1708 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1709 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1710 .info = snd_ice1712_spdif_info,
1711 .get = snd_ice1712_spdif_maskc_get,
1714 static struct snd_kcontrol_new snd_ice1712_spdif_maskp __devinitdata =
1716 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1717 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1718 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1719 .info = snd_ice1712_spdif_info,
1720 .get = snd_ice1712_spdif_maskp_get,
1723 static int snd_ice1712_spdif_stream_get(struct snd_kcontrol *kcontrol,
1724 struct snd_ctl_elem_value *ucontrol)
1726 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1727 if (ice->spdif.ops.stream_get)
1728 ice->spdif.ops.stream_get(ice, ucontrol);
1732 static int snd_ice1712_spdif_stream_put(struct snd_kcontrol *kcontrol,
1733 struct snd_ctl_elem_value *ucontrol)
1735 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1736 if (ice->spdif.ops.stream_put)
1737 return ice->spdif.ops.stream_put(ice, ucontrol);
1741 static struct snd_kcontrol_new snd_ice1712_spdif_stream __devinitdata =
1743 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1744 SNDRV_CTL_ELEM_ACCESS_INACTIVE),
1745 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1746 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
1747 .info = snd_ice1712_spdif_info,
1748 .get = snd_ice1712_spdif_stream_get,
1749 .put = snd_ice1712_spdif_stream_put
1752 int snd_ice1712_gpio_info(struct snd_kcontrol *kcontrol,
1753 struct snd_ctl_elem_info *uinfo)
1755 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1757 uinfo->value.integer.min = 0;
1758 uinfo->value.integer.max = 1;
1762 int snd_ice1712_gpio_get(struct snd_kcontrol *kcontrol,
1763 struct snd_ctl_elem_value *ucontrol)
1765 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1766 unsigned char mask = kcontrol->private_value & 0xff;
1767 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1769 snd_ice1712_save_gpio_status(ice);
1770 ucontrol->value.integer.value[0] =
1771 (snd_ice1712_gpio_read(ice) & mask ? 1 : 0) ^ invert;
1772 snd_ice1712_restore_gpio_status(ice);
1776 int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
1777 struct snd_ctl_elem_value *ucontrol)
1779 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1780 unsigned char mask = kcontrol->private_value & 0xff;
1781 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1782 unsigned int val, nval;
1784 if (kcontrol->private_value & (1 << 31))
1786 nval = (ucontrol->value.integer.value[0] ? mask : 0) ^ invert;
1787 snd_ice1712_save_gpio_status(ice);
1788 val = snd_ice1712_gpio_read(ice);
1789 nval |= val & ~mask;
1791 snd_ice1712_gpio_write(ice, nval);
1792 snd_ice1712_restore_gpio_status(ice);
1799 static int snd_ice1712_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1800 struct snd_ctl_elem_info *uinfo)
1802 static char *texts[] = {
1805 "11025", /* 2: 10 */
1813 "64000", /* 10: 15 */
1814 "88200", /* 11: 11 */
1815 "96000", /* 12: 7 */
1816 "IEC958 Input", /* 13: -- */
1818 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1820 uinfo->value.enumerated.items = 14;
1821 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1822 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1823 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1827 static int snd_ice1712_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1828 struct snd_ctl_elem_value *ucontrol)
1830 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1831 static unsigned char xlate[16] = {
1832 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10
1836 spin_lock_irq(&ice->reg_lock);
1837 if (is_spdif_master(ice)) {
1838 ucontrol->value.enumerated.item[0] = 13;
1840 val = xlate[inb(ICEMT(ice, RATE)) & 15];
1845 ucontrol->value.enumerated.item[0] = val;
1847 spin_unlock_irq(&ice->reg_lock);
1851 static int snd_ice1712_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1852 struct snd_ctl_elem_value *ucontrol)
1854 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1855 static unsigned int xrate[13] = {
1856 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1857 32000, 44100, 48000, 64000, 88200, 96000
1862 spin_lock_irq(&ice->reg_lock);
1863 oval = inb(ICEMT(ice, RATE));
1864 if (ucontrol->value.enumerated.item[0] == 13) {
1865 outb(oval | ICE1712_SPDIF_MASTER, ICEMT(ice, RATE));
1867 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1868 spin_unlock_irq(&ice->reg_lock);
1869 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1870 spin_lock_irq(&ice->reg_lock);
1872 change = inb(ICEMT(ice, RATE)) != oval;
1873 spin_unlock_irq(&ice->reg_lock);
1875 if ((oval & ICE1712_SPDIF_MASTER) !=
1876 (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER))
1877 snd_ice1712_set_input_clock_source(ice, is_spdif_master(ice));
1882 static struct snd_kcontrol_new snd_ice1712_pro_internal_clock __devinitdata = {
1883 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1884 .name = "Multi Track Internal Clock",
1885 .info = snd_ice1712_pro_internal_clock_info,
1886 .get = snd_ice1712_pro_internal_clock_get,
1887 .put = snd_ice1712_pro_internal_clock_put
1890 static int snd_ice1712_pro_internal_clock_default_info(struct snd_kcontrol *kcontrol,
1891 struct snd_ctl_elem_info *uinfo)
1893 static char *texts[] = {
1896 "11025", /* 2: 10 */
1904 "64000", /* 10: 15 */
1905 "88200", /* 11: 11 */
1906 "96000", /* 12: 7 */
1907 // "IEC958 Input", /* 13: -- */
1909 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1911 uinfo->value.enumerated.items = 13;
1912 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1913 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1914 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1918 static int snd_ice1712_pro_internal_clock_default_get(struct snd_kcontrol *kcontrol,
1919 struct snd_ctl_elem_value *ucontrol)
1922 static unsigned int xrate[13] = {
1923 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1924 32000, 44100, 48000, 64000, 88200, 96000
1927 for (val = 0; val < 13; val++) {
1928 if (xrate[val] == PRO_RATE_DEFAULT)
1932 ucontrol->value.enumerated.item[0] = val;
1936 static int snd_ice1712_pro_internal_clock_default_put(struct snd_kcontrol *kcontrol,
1937 struct snd_ctl_elem_value *ucontrol)
1939 static unsigned int xrate[13] = {
1940 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1941 32000, 44100, 48000, 64000, 88200, 96000
1946 oval = PRO_RATE_DEFAULT;
1947 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1948 change = PRO_RATE_DEFAULT != oval;
1953 static struct snd_kcontrol_new snd_ice1712_pro_internal_clock_default __devinitdata = {
1954 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1955 .name = "Multi Track Internal Clock Default",
1956 .info = snd_ice1712_pro_internal_clock_default_info,
1957 .get = snd_ice1712_pro_internal_clock_default_get,
1958 .put = snd_ice1712_pro_internal_clock_default_put
1961 static int snd_ice1712_pro_rate_locking_info(struct snd_kcontrol *kcontrol,
1962 struct snd_ctl_elem_info *uinfo)
1964 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1966 uinfo->value.integer.min = 0;
1967 uinfo->value.integer.max = 1;
1971 static int snd_ice1712_pro_rate_locking_get(struct snd_kcontrol *kcontrol,
1972 struct snd_ctl_elem_value *ucontrol)
1974 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1978 static int snd_ice1712_pro_rate_locking_put(struct snd_kcontrol *kcontrol,
1979 struct snd_ctl_elem_value *ucontrol)
1981 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1982 int change = 0, nval;
1984 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1985 spin_lock_irq(&ice->reg_lock);
1986 change = PRO_RATE_LOCKED != nval;
1987 PRO_RATE_LOCKED = nval;
1988 spin_unlock_irq(&ice->reg_lock);
1992 static struct snd_kcontrol_new snd_ice1712_pro_rate_locking __devinitdata = {
1993 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1994 .name = "Multi Track Rate Locking",
1995 .info = snd_ice1712_pro_rate_locking_info,
1996 .get = snd_ice1712_pro_rate_locking_get,
1997 .put = snd_ice1712_pro_rate_locking_put
2000 static int snd_ice1712_pro_rate_reset_info(struct snd_kcontrol *kcontrol,
2001 struct snd_ctl_elem_info *uinfo)
2003 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2005 uinfo->value.integer.min = 0;
2006 uinfo->value.integer.max = 1;
2010 static int snd_ice1712_pro_rate_reset_get(struct snd_kcontrol *kcontrol,
2011 struct snd_ctl_elem_value *ucontrol)
2013 ucontrol->value.integer.value[0] = PRO_RATE_RESET;
2017 static int snd_ice1712_pro_rate_reset_put(struct snd_kcontrol *kcontrol,
2018 struct snd_ctl_elem_value *ucontrol)
2020 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2021 int change = 0, nval;
2023 nval = ucontrol->value.integer.value[0] ? 1 : 0;
2024 spin_lock_irq(&ice->reg_lock);
2025 change = PRO_RATE_RESET != nval;
2026 PRO_RATE_RESET = nval;
2027 spin_unlock_irq(&ice->reg_lock);
2031 static struct snd_kcontrol_new snd_ice1712_pro_rate_reset __devinitdata = {
2032 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2033 .name = "Multi Track Rate Reset",
2034 .info = snd_ice1712_pro_rate_reset_info,
2035 .get = snd_ice1712_pro_rate_reset_get,
2036 .put = snd_ice1712_pro_rate_reset_put
2042 static int snd_ice1712_pro_route_info(struct snd_kcontrol *kcontrol,
2043 struct snd_ctl_elem_info *uinfo)
2045 static char *texts[] = {
2047 "H/W In 0", "H/W In 1", "H/W In 2", "H/W In 3", /* 1-4 */
2048 "H/W In 4", "H/W In 5", "H/W In 6", "H/W In 7", /* 5-8 */
2049 "IEC958 In L", "IEC958 In R", /* 9-10 */
2050 "Digital Mixer", /* 11 - optional */
2053 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2055 uinfo->value.enumerated.items =
2056 snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
2057 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2058 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2059 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2063 static int snd_ice1712_pro_route_analog_get(struct snd_kcontrol *kcontrol,
2064 struct snd_ctl_elem_value *ucontrol)
2066 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2067 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2068 unsigned int val, cval;
2070 spin_lock_irq(&ice->reg_lock);
2071 val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2072 cval = inl(ICEMT(ice, ROUTE_CAPTURE));
2073 spin_unlock_irq(&ice->reg_lock);
2075 val >>= ((idx % 2) * 8) + ((idx / 2) * 2);
2077 cval >>= ((idx / 2) * 8) + ((idx % 2) * 4);
2078 if (val == 1 && idx < 2)
2079 ucontrol->value.enumerated.item[0] = 11;
2081 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2083 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2085 ucontrol->value.enumerated.item[0] = 0;
2089 static int snd_ice1712_pro_route_analog_put(struct snd_kcontrol *kcontrol,
2090 struct snd_ctl_elem_value *ucontrol)
2092 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2094 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2095 unsigned int val, old_val, nval;
2098 if (ucontrol->value.enumerated.item[0] >= 11)
2099 nval = idx < 2 ? 1 : 0; /* dig mixer (or pcm) */
2100 else if (ucontrol->value.enumerated.item[0] >= 9)
2101 nval = 3; /* spdif in */
2102 else if (ucontrol->value.enumerated.item[0] >= 1)
2103 nval = 2; /* analog in */
2106 shift = ((idx % 2) * 8) + ((idx / 2) * 2);
2107 spin_lock_irq(&ice->reg_lock);
2108 val = old_val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2109 val &= ~(0x03 << shift);
2110 val |= nval << shift;
2111 change = val != old_val;
2113 outw(val, ICEMT(ice, ROUTE_PSDOUT03));
2114 spin_unlock_irq(&ice->reg_lock);
2115 if (nval < 2) /* dig mixer of pcm */
2118 /* update CAPTURE */
2119 spin_lock_irq(&ice->reg_lock);
2120 val = old_val = inl(ICEMT(ice, ROUTE_CAPTURE));
2121 shift = ((idx / 2) * 8) + ((idx % 2) * 4);
2122 if (nval == 2) { /* analog in */
2123 nval = ucontrol->value.enumerated.item[0] - 1;
2124 val &= ~(0x07 << shift);
2125 val |= nval << shift;
2126 } else { /* spdif in */
2127 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2128 val &= ~(0x08 << shift);
2129 val |= nval << shift;
2131 if (val != old_val) {
2133 outl(val, ICEMT(ice, ROUTE_CAPTURE));
2135 spin_unlock_irq(&ice->reg_lock);
2139 static int snd_ice1712_pro_route_spdif_get(struct snd_kcontrol *kcontrol,
2140 struct snd_ctl_elem_value *ucontrol)
2142 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2143 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2144 unsigned int val, cval;
2145 val = inw(ICEMT(ice, ROUTE_SPDOUT));
2146 cval = (val >> (idx * 4 + 8)) & 0x0f;
2147 val = (val >> (idx * 2)) & 0x03;
2149 ucontrol->value.enumerated.item[0] = 11;
2151 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2153 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2155 ucontrol->value.enumerated.item[0] = 0;
2159 static int snd_ice1712_pro_route_spdif_put(struct snd_kcontrol *kcontrol,
2160 struct snd_ctl_elem_value *ucontrol)
2162 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2164 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2165 unsigned int val, old_val, nval;
2168 spin_lock_irq(&ice->reg_lock);
2169 val = old_val = inw(ICEMT(ice, ROUTE_SPDOUT));
2170 if (ucontrol->value.enumerated.item[0] >= 11)
2172 else if (ucontrol->value.enumerated.item[0] >= 9)
2174 else if (ucontrol->value.enumerated.item[0] >= 1)
2179 val &= ~(0x03 << shift);
2180 val |= nval << shift;
2181 shift = idx * 4 + 8;
2183 nval = ucontrol->value.enumerated.item[0] - 1;
2184 val &= ~(0x07 << shift);
2185 val |= nval << shift;
2186 } else if (nval == 3) {
2187 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2188 val &= ~(0x08 << shift);
2189 val |= nval << shift;
2191 change = val != old_val;
2193 outw(val, ICEMT(ice, ROUTE_SPDOUT));
2194 spin_unlock_irq(&ice->reg_lock);
2198 static struct snd_kcontrol_new snd_ice1712_mixer_pro_analog_route __devinitdata = {
2199 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2200 .name = "H/W Playback Route",
2201 .info = snd_ice1712_pro_route_info,
2202 .get = snd_ice1712_pro_route_analog_get,
2203 .put = snd_ice1712_pro_route_analog_put,
2206 static struct snd_kcontrol_new snd_ice1712_mixer_pro_spdif_route __devinitdata = {
2207 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2208 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
2209 .info = snd_ice1712_pro_route_info,
2210 .get = snd_ice1712_pro_route_spdif_get,
2211 .put = snd_ice1712_pro_route_spdif_put,
2216 static int snd_ice1712_pro_volume_rate_info(struct snd_kcontrol *kcontrol,
2217 struct snd_ctl_elem_info *uinfo)
2219 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2221 uinfo->value.integer.min = 0;
2222 uinfo->value.integer.max = 255;
2226 static int snd_ice1712_pro_volume_rate_get(struct snd_kcontrol *kcontrol,
2227 struct snd_ctl_elem_value *ucontrol)
2229 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2231 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE));
2235 static int snd_ice1712_pro_volume_rate_put(struct snd_kcontrol *kcontrol,
2236 struct snd_ctl_elem_value *ucontrol)
2238 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2241 spin_lock_irq(&ice->reg_lock);
2242 change = inb(ICEMT(ice, MONITOR_RATE)) != ucontrol->value.integer.value[0];
2243 outb(ucontrol->value.integer.value[0], ICEMT(ice, MONITOR_RATE));
2244 spin_unlock_irq(&ice->reg_lock);
2248 static struct snd_kcontrol_new snd_ice1712_mixer_pro_volume_rate __devinitdata = {
2249 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2250 .name = "Multi Track Volume Rate",
2251 .info = snd_ice1712_pro_volume_rate_info,
2252 .get = snd_ice1712_pro_volume_rate_get,
2253 .put = snd_ice1712_pro_volume_rate_put
2256 static int snd_ice1712_pro_peak_info(struct snd_kcontrol *kcontrol,
2257 struct snd_ctl_elem_info *uinfo)
2259 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2261 uinfo->value.integer.min = 0;
2262 uinfo->value.integer.max = 255;
2266 static int snd_ice1712_pro_peak_get(struct snd_kcontrol *kcontrol,
2267 struct snd_ctl_elem_value *ucontrol)
2269 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2272 spin_lock_irq(&ice->reg_lock);
2273 for (idx = 0; idx < 22; idx++) {
2274 outb(idx, ICEMT(ice, MONITOR_PEAKINDEX));
2275 ucontrol->value.integer.value[idx] = inb(ICEMT(ice, MONITOR_PEAKDATA));
2277 spin_unlock_irq(&ice->reg_lock);
2281 static struct snd_kcontrol_new snd_ice1712_mixer_pro_peak __devinitdata = {
2282 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2283 .name = "Multi Track Peak",
2284 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2285 .info = snd_ice1712_pro_peak_info,
2286 .get = snd_ice1712_pro_peak_get
2294 * list of available boards
2296 static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
2297 snd_ice1712_hoontech_cards,
2298 snd_ice1712_delta_cards,
2299 snd_ice1712_ews_cards,
2303 static unsigned char __devinit snd_ice1712_read_i2c(struct snd_ice1712 *ice,
2309 outb(addr, ICEREG(ice, I2C_BYTE_ADDR));
2310 outb(dev & ~ICE1712_I2C_WRITE, ICEREG(ice, I2C_DEV_ADDR));
2311 while (t-- > 0 && (inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_BUSY)) ;
2312 return inb(ICEREG(ice, I2C_DATA));
2315 static int __devinit snd_ice1712_read_eeprom(struct snd_ice1712 *ice,
2316 const char *modelname)
2318 int dev = 0xa0; /* EEPROM device address */
2319 unsigned int i, size;
2320 struct snd_ice1712_card_info **tbl, *c;
2322 if (! modelname || ! *modelname) {
2323 ice->eeprom.subvendor = 0;
2324 if ((inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_EEPROM) != 0)
2325 ice->eeprom.subvendor = (snd_ice1712_read_i2c(ice, dev, 0x00) << 0) |
2326 (snd_ice1712_read_i2c(ice, dev, 0x01) << 8) |
2327 (snd_ice1712_read_i2c(ice, dev, 0x02) << 16) |
2328 (snd_ice1712_read_i2c(ice, dev, 0x03) << 24);
2329 if (ice->eeprom.subvendor == 0 ||
2330 ice->eeprom.subvendor == (unsigned int)-1) {
2331 /* invalid subvendor from EEPROM, try the PCI subststem ID instead */
2333 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID, &vendor);
2334 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
2335 ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device);
2336 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
2337 printk(KERN_ERR "ice1712: No valid ID is found\n");
2342 for (tbl = card_tables; *tbl; tbl++) {
2343 for (c = *tbl; c->subvendor; c++) {
2344 if (modelname && c->model && ! strcmp(modelname, c->model)) {
2345 printk(KERN_INFO "ice1712: Using board model %s\n", c->name);
2346 ice->eeprom.subvendor = c->subvendor;
2347 } else if (c->subvendor != ice->eeprom.subvendor)
2349 if (! c->eeprom_size || ! c->eeprom_data)
2351 /* if the EEPROM is given by the driver, use it */
2352 snd_printdd("using the defined eeprom..\n");
2353 ice->eeprom.version = 1;
2354 ice->eeprom.size = c->eeprom_size + 6;
2355 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
2359 printk(KERN_WARNING "ice1712: No matching model found for ID 0x%x\n",
2360 ice->eeprom.subvendor);
2363 ice->eeprom.size = snd_ice1712_read_i2c(ice, dev, 0x04);
2364 if (ice->eeprom.size < 6)
2365 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */
2366 else if (ice->eeprom.size > 32) {
2367 snd_printk(KERN_ERR "invalid EEPROM (size = %i)\n", ice->eeprom.size);
2370 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05);
2371 if (ice->eeprom.version != 1) {
2372 snd_printk(KERN_ERR "invalid EEPROM version %i\n",
2373 ice->eeprom.version);
2376 size = ice->eeprom.size - 6;
2377 for (i = 0; i < size; i++)
2378 ice->eeprom.data[i] = snd_ice1712_read_i2c(ice, dev, i + 6);
2381 ice->eeprom.gpiomask = ice->eeprom.data[ICE_EEP1_GPIO_MASK];
2382 ice->eeprom.gpiostate = ice->eeprom.data[ICE_EEP1_GPIO_STATE];
2383 ice->eeprom.gpiodir = ice->eeprom.data[ICE_EEP1_GPIO_DIR];
2390 static int __devinit snd_ice1712_chip_init(struct snd_ice1712 *ice)
2392 outb(ICE1712_RESET | ICE1712_NATIVE, ICEREG(ice, CONTROL));
2394 outb(ICE1712_NATIVE, ICEREG(ice, CONTROL));
2396 if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DMX6FIRE && !ice->dxr_enable) {
2397 /* Limit active ADCs and DACs to 6; */
2398 /* Note: DXR extension not supported */
2399 pci_write_config_byte(ice->pci, 0x60, 0x0a);
2401 pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]);
2403 pci_write_config_byte(ice->pci, 0x61, ice->eeprom.data[ICE_EEP1_ACLINK]);
2404 pci_write_config_byte(ice->pci, 0x62, ice->eeprom.data[ICE_EEP1_I2SID]);
2405 pci_write_config_byte(ice->pci, 0x63, ice->eeprom.data[ICE_EEP1_SPDIF]);
2406 if (ice->eeprom.subvendor != ICE1712_SUBDEVICE_STDSP24) {
2407 ice->gpio.write_mask = ice->eeprom.gpiomask;
2408 ice->gpio.direction = ice->eeprom.gpiodir;
2409 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK,
2410 ice->eeprom.gpiomask);
2411 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
2412 ice->eeprom.gpiodir);
2413 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA,
2414 ice->eeprom.gpiostate);
2416 ice->gpio.write_mask = 0xc0;
2417 ice->gpio.direction = 0xff;
2418 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, 0xc0);
2419 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, 0xff);
2420 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA,
2421 ICE1712_STDSP24_CLOCK_BIT);
2423 snd_ice1712_write(ice, ICE1712_IREG_PRO_POWERDOWN, 0);
2424 if (!(ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97)) {
2425 outb(ICE1712_AC97_WARM, ICEREG(ice, AC97_CMD));
2427 outb(0, ICEREG(ice, AC97_CMD));
2429 snd_ice1712_write(ice, ICE1712_IREG_CONSUMER_POWERDOWN, 0);
2431 snd_ice1712_set_pro_rate(ice, 48000, 1);
2436 int __devinit snd_ice1712_spdif_build_controls(struct snd_ice1712 *ice)
2439 struct snd_kcontrol *kctl;
2441 snd_assert(ice->pcm_pro != NULL, return -EIO);
2442 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_default, ice));
2445 kctl->id.device = ice->pcm_pro->device;
2446 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskc, ice));
2449 kctl->id.device = ice->pcm_pro->device;
2450 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskp, ice));
2453 kctl->id.device = ice->pcm_pro->device;
2454 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_stream, ice));
2457 kctl->id.device = ice->pcm_pro->device;
2458 ice->spdif.stream_ctl = kctl;
2463 static int __devinit snd_ice1712_build_controls(struct snd_ice1712 *ice)
2467 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_eeprom, ice));
2470 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock, ice));
2473 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock_default, ice));
2477 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_locking, ice));
2480 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_reset, ice));
2484 if (ice->num_total_dacs > 0) {
2485 struct snd_kcontrol_new tmp = snd_ice1712_mixer_pro_analog_route;
2486 tmp.count = ice->num_total_dacs;
2487 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2492 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice));
2496 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
2499 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice));
2506 static int snd_ice1712_free(struct snd_ice1712 *ice)
2510 /* mask all interrupts */
2511 outb(0xc0, ICEMT(ice, IRQ));
2512 outb(0xff, ICEREG(ice, IRQMASK));
2515 if (ice->irq >= 0) {
2516 synchronize_irq(ice->irq);
2517 free_irq(ice->irq, ice);
2520 pci_release_regions(ice->pci);
2521 snd_ice1712_akm4xxx_free(ice);
2522 pci_disable_device(ice->pci);
2527 static int snd_ice1712_dev_free(struct snd_device *device)
2529 struct snd_ice1712 *ice = device->device_data;
2530 return snd_ice1712_free(ice);
2533 static int __devinit snd_ice1712_create(struct snd_card *card,
2534 struct pci_dev *pci,
2535 const char *modelname,
2539 struct snd_ice1712 ** r_ice1712)
2541 struct snd_ice1712 *ice;
2543 static struct snd_device_ops ops = {
2544 .dev_free = snd_ice1712_dev_free,
2549 /* enable PCI device */
2550 if ((err = pci_enable_device(pci)) < 0)
2552 /* check, if we can restrict PCI DMA transfers to 28 bits */
2553 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 ||
2554 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) {
2555 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n");
2556 pci_disable_device(pci);
2560 ice = kzalloc(sizeof(*ice), GFP_KERNEL);
2562 pci_disable_device(pci);
2565 ice->omni = omni ? 1 : 0;
2566 if (cs8427_timeout < 1)
2568 else if (cs8427_timeout > 1000)
2569 cs8427_timeout = 1000;
2570 ice->cs8427_timeout = cs8427_timeout;
2571 ice->dxr_enable = dxr_enable;
2572 spin_lock_init(&ice->reg_lock);
2573 mutex_init(&ice->gpio_mutex);
2574 mutex_init(&ice->i2c_mutex);
2575 mutex_init(&ice->open_mutex);
2576 ice->gpio.set_mask = snd_ice1712_set_gpio_mask;
2577 ice->gpio.set_dir = snd_ice1712_set_gpio_dir;
2578 ice->gpio.set_data = snd_ice1712_set_gpio_data;
2579 ice->gpio.get_data = snd_ice1712_get_gpio_data;
2581 ice->spdif.cs8403_bits =
2582 ice->spdif.cs8403_stream_bits = (0x01 | /* consumer format */
2583 0x10 | /* no emphasis */
2584 0x20); /* PCM encoder/decoder */
2588 pci_set_master(pci);
2589 pci_write_config_word(ice->pci, 0x40, 0x807f);
2590 pci_write_config_word(ice->pci, 0x42, 0x0006);
2591 snd_ice1712_proc_init(ice);
2592 synchronize_irq(pci->irq);
2594 if ((err = pci_request_regions(pci, "ICE1712")) < 0) {
2596 pci_disable_device(pci);
2599 ice->port = pci_resource_start(pci, 0);
2600 ice->ddma_port = pci_resource_start(pci, 1);
2601 ice->dmapath_port = pci_resource_start(pci, 2);
2602 ice->profi_port = pci_resource_start(pci, 3);
2604 if (request_irq(pci->irq, snd_ice1712_interrupt, SA_INTERRUPT|SA_SHIRQ,
2606 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2607 snd_ice1712_free(ice);
2611 ice->irq = pci->irq;
2613 if (snd_ice1712_read_eeprom(ice, modelname) < 0) {
2614 snd_ice1712_free(ice);
2617 if (snd_ice1712_chip_init(ice) < 0) {
2618 snd_ice1712_free(ice);
2622 /* unmask used interrupts */
2623 outb(((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) == 0 ?
2624 ICE1712_IRQ_MPU2 : 0) |
2625 ((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97) ?
2626 ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0),
2627 ICEREG(ice, IRQMASK));
2628 outb(0x00, ICEMT(ice, IRQ));
2630 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2631 snd_ice1712_free(ice);
2635 snd_card_set_dev(card, &pci->dev);
2648 static struct snd_ice1712_card_info no_matched __devinitdata;
2650 static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2651 const struct pci_device_id *pci_id)
2654 struct snd_card *card;
2655 struct snd_ice1712 *ice;
2656 int pcm_dev = 0, err;
2657 struct snd_ice1712_card_info **tbl, *c;
2659 if (dev >= SNDRV_CARDS)
2666 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2670 strcpy(card->driver, "ICE1712");
2671 strcpy(card->shortname, "ICEnsemble ICE1712");
2673 if ((err = snd_ice1712_create(card, pci, model[dev], omni[dev],
2674 cs8427_timeout[dev], dxr_enable[dev],
2676 snd_card_free(card);
2680 for (tbl = card_tables; *tbl; tbl++) {
2681 for (c = *tbl; c->subvendor; c++) {
2682 if (c->subvendor == ice->eeprom.subvendor) {
2683 strcpy(card->shortname, c->name);
2684 if (c->driver) /* specific driver? */
2685 strcpy(card->driver, c->driver);
2687 if ((err = c->chip_init(ice)) < 0) {
2688 snd_card_free(card);
2699 if ((err = snd_ice1712_pcm_profi(ice, pcm_dev++, NULL)) < 0) {
2700 snd_card_free(card);
2704 if (ice_has_con_ac97(ice))
2705 if ((err = snd_ice1712_pcm(ice, pcm_dev++, NULL)) < 0) {
2706 snd_card_free(card);
2710 if ((err = snd_ice1712_ac97_mixer(ice)) < 0) {
2711 snd_card_free(card);
2715 if ((err = snd_ice1712_build_controls(ice)) < 0) {
2716 snd_card_free(card);
2720 if (c->build_controls) {
2721 if ((err = c->build_controls(ice)) < 0) {
2722 snd_card_free(card);
2727 if (ice_has_con_ac97(ice))
2728 if ((err = snd_ice1712_pcm_ds(ice, pcm_dev++, NULL)) < 0) {
2729 snd_card_free(card);
2733 if (! c->no_mpu401) {
2734 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2735 ICEREG(ice, MPU1_CTRL), 1,
2737 &ice->rmidi[0])) < 0) {
2738 snd_card_free(card);
2742 if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401)
2743 if ((err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712,
2744 ICEREG(ice, MPU2_CTRL), 1,
2746 &ice->rmidi[1])) < 0) {
2747 snd_card_free(card);
2752 snd_ice1712_set_input_clock_source(ice, 0);
2754 sprintf(card->longname, "%s at 0x%lx, irq %i",
2755 card->shortname, ice->port, ice->irq);
2757 if ((err = snd_card_register(card)) < 0) {
2758 snd_card_free(card);
2761 pci_set_drvdata(pci, card);
2766 static void __devexit snd_ice1712_remove(struct pci_dev *pci)
2768 snd_card_free(pci_get_drvdata(pci));
2769 pci_set_drvdata(pci, NULL);
2772 static struct pci_driver driver = {
2774 .id_table = snd_ice1712_ids,
2775 .probe = snd_ice1712_probe,
2776 .remove = __devexit_p(snd_ice1712_remove),
2779 static int __init alsa_card_ice1712_init(void)
2781 return pci_register_driver(&driver);
2784 static void __exit alsa_card_ice1712_exit(void)
2786 pci_unregister_driver(&driver);
2789 module_init(alsa_card_ice1712_init)
2790 module_exit(alsa_card_ice1712_exit)