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 <sound/core.h>
59 #include <sound/cs8427.h>
60 #include <sound/info.h>
61 #include <sound/mpu401.h>
62 #include <sound/initval.h>
64 #include <sound/asoundef.h>
68 /* lowlevel routines */
73 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
74 MODULE_DESCRIPTION("ICEnsemble ICE1712 (Envy24)");
75 MODULE_LICENSE("GPL");
76 MODULE_SUPPORTED_DEVICE("{"
80 "{ICEnsemble,Generic ICE1712},"
81 "{ICEnsemble,Generic Envy24}}");
83 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
84 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
85 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
86 static char *model[SNDRV_CARDS];
87 static int omni[SNDRV_CARDS]; /* Delta44 & 66 Omni I/O support */
88 static int cs8427_timeout[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 500}; /* CS8427 S/PDIF transciever reset timeout value in msec */
91 module_param_array(index, int, boot_devs, 0444);
92 MODULE_PARM_DESC(index, "Index value for ICE1712 soundcard.");
93 module_param_array(id, charp, boot_devs, 0444);
94 MODULE_PARM_DESC(id, "ID string for ICE1712 soundcard.");
95 module_param_array(enable, bool, boot_devs, 0444);
96 MODULE_PARM_DESC(enable, "Enable ICE1712 soundcard.");
97 module_param_array(omni, bool, boot_devs, 0444);
98 MODULE_PARM_DESC(omni, "Enable Midiman M-Audio Delta Omni I/O support.");
99 module_param_array(cs8427_timeout, int, boot_devs, 0444);
100 MODULE_PARM_DESC(cs8427_timeout, "Define reset timeout for cs8427 chip in msec resolution.");
101 module_param_array(model, charp, boot_devs, 0444);
102 MODULE_PARM_DESC(model, "Use the given board model.");
104 #ifndef PCI_VENDOR_ID_ICE
105 #define PCI_VENDOR_ID_ICE 0x1412
107 #ifndef PCI_DEVICE_ID_ICE_1712
108 #define PCI_DEVICE_ID_ICE_1712 0x1712
111 static struct pci_device_id snd_ice1712_ids[] = {
112 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_ICE_1712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* ICE1712 */
116 MODULE_DEVICE_TABLE(pci, snd_ice1712_ids);
118 static int snd_ice1712_build_pro_mixer(ice1712_t *ice);
119 static int snd_ice1712_build_controls(ice1712_t *ice);
121 static int PRO_RATE_LOCKED;
122 static int PRO_RATE_RESET = 1;
123 static unsigned int PRO_RATE_DEFAULT = 44100;
129 /* check whether the clock mode is spdif-in */
130 static inline int is_spdif_master(ice1712_t *ice)
132 return (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER) ? 1 : 0;
135 static inline int is_pro_rate_locked(ice1712_t *ice)
137 return is_spdif_master(ice) || PRO_RATE_LOCKED;
140 static inline void snd_ice1712_ds_write(ice1712_t * ice, u8 channel, u8 addr, u32 data)
142 outb((channel << 4) | addr, ICEDS(ice, INDEX));
143 outl(data, ICEDS(ice, DATA));
146 static inline u32 snd_ice1712_ds_read(ice1712_t * ice, u8 channel, u8 addr)
148 outb((channel << 4) | addr, ICEDS(ice, INDEX));
149 return inl(ICEDS(ice, DATA));
152 static void snd_ice1712_ac97_write(ac97_t *ac97,
156 ice1712_t *ice = (ice1712_t *)ac97->private_data;
158 unsigned char old_cmd = 0;
160 for (tm = 0; tm < 0x10000; tm++) {
161 old_cmd = inb(ICEREG(ice, AC97_CMD));
162 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
164 if (!(old_cmd & ICE1712_AC97_READY))
168 outb(reg, ICEREG(ice, AC97_INDEX));
169 outw(val, ICEREG(ice, AC97_DATA));
170 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
171 outb(old_cmd | ICE1712_AC97_WRITE, ICEREG(ice, AC97_CMD));
172 for (tm = 0; tm < 0x10000; tm++)
173 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
177 static unsigned short snd_ice1712_ac97_read(ac97_t *ac97,
180 ice1712_t *ice = (ice1712_t *)ac97->private_data;
182 unsigned char old_cmd = 0;
184 for (tm = 0; tm < 0x10000; tm++) {
185 old_cmd = inb(ICEREG(ice, AC97_CMD));
186 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
188 if (!(old_cmd & ICE1712_AC97_READY))
192 outb(reg, ICEREG(ice, AC97_INDEX));
193 outb(old_cmd | ICE1712_AC97_READ, ICEREG(ice, AC97_CMD));
194 for (tm = 0; tm < 0x10000; tm++)
195 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
197 if (tm >= 0x10000) /* timeout */
199 return inw(ICEREG(ice, AC97_DATA));
206 static void snd_ice1712_pro_ac97_write(ac97_t *ac97,
210 ice1712_t *ice = (ice1712_t *)ac97->private_data;
212 unsigned char old_cmd = 0;
214 for (tm = 0; tm < 0x10000; tm++) {
215 old_cmd = inb(ICEMT(ice, AC97_CMD));
216 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
218 if (!(old_cmd & ICE1712_AC97_READY))
222 outb(reg, ICEMT(ice, AC97_INDEX));
223 outw(val, ICEMT(ice, AC97_DATA));
224 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
225 outb(old_cmd | ICE1712_AC97_WRITE, ICEMT(ice, AC97_CMD));
226 for (tm = 0; tm < 0x10000; tm++)
227 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
232 static unsigned short snd_ice1712_pro_ac97_read(ac97_t *ac97,
235 ice1712_t *ice = (ice1712_t *)ac97->private_data;
237 unsigned char old_cmd = 0;
239 for (tm = 0; tm < 0x10000; tm++) {
240 old_cmd = inb(ICEMT(ice, AC97_CMD));
241 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
243 if (!(old_cmd & ICE1712_AC97_READY))
247 outb(reg, ICEMT(ice, AC97_INDEX));
248 outb(old_cmd | ICE1712_AC97_READ, ICEMT(ice, AC97_CMD));
249 for (tm = 0; tm < 0x10000; tm++)
250 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
252 if (tm >= 0x10000) /* timeout */
254 return inw(ICEMT(ice, AC97_DATA));
258 * consumer ac97 digital mix
260 static int snd_ice1712_digmix_route_ac97_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
262 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
264 uinfo->value.integer.min = 0;
265 uinfo->value.integer.max = 1;
269 static int snd_ice1712_digmix_route_ac97_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
271 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
273 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0;
277 static int snd_ice1712_digmix_route_ac97_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
279 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
280 unsigned char val, nval;
282 spin_lock_irq(&ice->reg_lock);
283 val = inb(ICEMT(ice, MONITOR_ROUTECTRL));
284 nval = val & ~ICE1712_ROUTE_AC97;
285 if (ucontrol->value.integer.value[0]) nval |= ICE1712_ROUTE_AC97;
286 outb(nval, ICEMT(ice, MONITOR_ROUTECTRL));
287 spin_unlock_irq(&ice->reg_lock);
291 static snd_kcontrol_new_t snd_ice1712_mixer_digmix_route_ac97 __devinitdata = {
292 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
293 .name = "Digital Mixer To AC97",
294 .info = snd_ice1712_digmix_route_ac97_info,
295 .get = snd_ice1712_digmix_route_ac97_get,
296 .put = snd_ice1712_digmix_route_ac97_put,
303 static void snd_ice1712_set_gpio_dir(ice1712_t *ice, unsigned int data)
305 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, data);
306 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
309 static void snd_ice1712_set_gpio_mask(ice1712_t *ice, unsigned int data)
311 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data);
312 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
315 static unsigned int snd_ice1712_get_gpio_data(ice1712_t *ice)
317 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
320 static void snd_ice1712_set_gpio_data(ice1712_t *ice, unsigned int val)
322 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, val);
323 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
334 * change the input clock selection
335 * spdif_clock = 1 - IEC958 input, 0 - Envy24
337 static int snd_ice1712_cs8427_set_input_clock(ice1712_t *ice, int spdif_clock)
339 unsigned char reg[2] = { 0x80 | 4, 0 }; /* CS8427 auto increment | register number 4 + data */
340 unsigned char val, nval;
343 snd_i2c_lock(ice->i2c);
344 if (snd_i2c_sendbytes(ice->cs8427, reg, 1) != 1) {
345 snd_i2c_unlock(ice->i2c);
348 if (snd_i2c_readbytes(ice->cs8427, &val, 1) != 1) {
349 snd_i2c_unlock(ice->i2c);
359 if (snd_i2c_sendbytes(ice->cs8427, reg, 2) != 2) {
365 snd_i2c_unlock(ice->i2c);
372 static void open_cs8427(ice1712_t *ice, snd_pcm_substream_t * substream)
374 snd_cs8427_iec958_active(ice->cs8427, 1);
377 static void close_cs8427(ice1712_t *ice, snd_pcm_substream_t * substream)
379 snd_cs8427_iec958_active(ice->cs8427, 0);
382 static void setup_cs8427(ice1712_t *ice, int rate)
384 snd_cs8427_iec958_pcm(ice->cs8427, rate);
388 * create and initialize callbacks for cs8427 interface
390 int __devinit snd_ice1712_init_cs8427(ice1712_t *ice, int addr)
394 if ((err = snd_cs8427_create(ice->i2c, addr,
395 (ice->cs8427_timeout * HZ) / 1000,
396 &ice->cs8427)) < 0) {
397 snd_printk("CS8427 initialization failed\n");
400 ice->spdif.ops.open = open_cs8427;
401 ice->spdif.ops.close = close_cs8427;
402 ice->spdif.ops.setup_rate = setup_cs8427;
411 static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
413 ice1712_t *ice = dev_id;
414 unsigned char status;
418 status = inb(ICEREG(ice, IRQSTAT));
422 if (status & ICE1712_IRQ_MPU1) {
424 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data, regs);
425 outb(ICE1712_IRQ_MPU1, ICEREG(ice, IRQSTAT));
426 status &= ~ICE1712_IRQ_MPU1;
428 if (status & ICE1712_IRQ_TIMER)
429 outb(ICE1712_IRQ_TIMER, ICEREG(ice, IRQSTAT));
430 if (status & ICE1712_IRQ_MPU2) {
432 snd_mpu401_uart_interrupt(irq, ice->rmidi[1]->private_data, regs);
433 outb(ICE1712_IRQ_MPU2, ICEREG(ice, IRQSTAT));
434 status &= ~ICE1712_IRQ_MPU2;
436 if (status & ICE1712_IRQ_PROPCM) {
437 unsigned char mtstat = inb(ICEMT(ice, IRQ));
438 if (mtstat & ICE1712_MULTI_PBKSTATUS) {
439 if (ice->playback_pro_substream)
440 snd_pcm_period_elapsed(ice->playback_pro_substream);
441 outb(ICE1712_MULTI_PBKSTATUS, ICEMT(ice, IRQ));
443 if (mtstat & ICE1712_MULTI_CAPSTATUS) {
444 if (ice->capture_pro_substream)
445 snd_pcm_period_elapsed(ice->capture_pro_substream);
446 outb(ICE1712_MULTI_CAPSTATUS, ICEMT(ice, IRQ));
449 if (status & ICE1712_IRQ_FM)
450 outb(ICE1712_IRQ_FM, ICEREG(ice, IRQSTAT));
451 if (status & ICE1712_IRQ_PBKDS) {
454 snd_pcm_substream_t *substream;
455 pbkstatus = inw(ICEDS(ice, INTSTAT));
456 //printk("pbkstatus = 0x%x\n", pbkstatus);
457 for (idx = 0; idx < 6; idx++) {
458 if ((pbkstatus & (3 << (idx * 2))) == 0)
460 if ((substream = ice->playback_con_substream_ds[idx]) != NULL)
461 snd_pcm_period_elapsed(substream);
462 outw(3 << (idx * 2), ICEDS(ice, INTSTAT));
464 outb(ICE1712_IRQ_PBKDS, ICEREG(ice, IRQSTAT));
466 if (status & ICE1712_IRQ_CONCAP) {
467 if (ice->capture_con_substream)
468 snd_pcm_period_elapsed(ice->capture_con_substream);
469 outb(ICE1712_IRQ_CONCAP, ICEREG(ice, IRQSTAT));
471 if (status & ICE1712_IRQ_CONPBK) {
472 if (ice->playback_con_substream)
473 snd_pcm_period_elapsed(ice->playback_con_substream);
474 outb(ICE1712_IRQ_CONPBK, ICEREG(ice, IRQSTAT));
477 return IRQ_RETVAL(handled);
485 static int snd_ice1712_hw_params(snd_pcm_substream_t * substream,
486 snd_pcm_hw_params_t * hw_params)
488 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
491 static int snd_ice1712_hw_free(snd_pcm_substream_t * substream)
493 return snd_pcm_lib_free_pages(substream);
497 * PCM part - consumer I/O
500 static int snd_ice1712_playback_trigger(snd_pcm_substream_t * substream,
503 ice1712_t *ice = snd_pcm_substream_chip(substream);
507 spin_lock(&ice->reg_lock);
508 tmp = snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL);
509 if (cmd == SNDRV_PCM_TRIGGER_START) {
511 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
513 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
515 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
520 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
521 spin_unlock(&ice->reg_lock);
525 static int snd_ice1712_playback_ds_trigger(snd_pcm_substream_t * substream,
528 ice1712_t *ice = snd_pcm_substream_chip(substream);
532 spin_lock(&ice->reg_lock);
533 tmp = snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL);
534 if (cmd == SNDRV_PCM_TRIGGER_START) {
536 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
538 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
540 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
545 snd_ice1712_ds_write(ice, substream->number * 2, ICE1712_DSC_CONTROL, tmp);
546 spin_unlock(&ice->reg_lock);
550 static int snd_ice1712_capture_trigger(snd_pcm_substream_t * substream,
553 ice1712_t *ice = snd_pcm_substream_chip(substream);
557 spin_lock(&ice->reg_lock);
558 tmp = snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL);
559 if (cmd == SNDRV_PCM_TRIGGER_START) {
561 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
566 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
567 spin_unlock(&ice->reg_lock);
571 static int snd_ice1712_playback_prepare(snd_pcm_substream_t * substream)
573 ice1712_t *ice = snd_pcm_substream_chip(substream);
574 snd_pcm_runtime_t *runtime = substream->runtime;
575 u32 period_size, buf_size, rate, tmp;
577 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
578 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
580 if (snd_pcm_format_width(runtime->format) == 16)
582 if (runtime->channels == 2)
584 rate = (runtime->rate * 8192) / 375;
585 if (rate > 0x000fffff)
587 spin_lock_irq(&ice->reg_lock);
588 outb(0, ice->ddma_port + 15);
589 outb(ICE1712_DMA_MODE_WRITE | ICE1712_DMA_AUTOINIT, ice->ddma_port + 0x0b);
590 outl(runtime->dma_addr, ice->ddma_port + 0);
591 outw(buf_size, ice->ddma_port + 4);
592 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_LO, rate & 0xff);
593 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_MID, (rate >> 8) & 0xff);
594 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_HI, (rate >> 16) & 0xff);
595 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
596 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_LO, period_size & 0xff);
597 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_HI, period_size >> 8);
598 snd_ice1712_write(ice, ICE1712_IREG_PBK_LEFT, 0);
599 snd_ice1712_write(ice, ICE1712_IREG_PBK_RIGHT, 0);
600 spin_unlock_irq(&ice->reg_lock);
604 static int snd_ice1712_playback_ds_prepare(snd_pcm_substream_t * substream)
606 ice1712_t *ice = snd_pcm_substream_chip(substream);
607 snd_pcm_runtime_t *runtime = substream->runtime;
608 u32 period_size, buf_size, rate, tmp, chn;
610 period_size = snd_pcm_lib_period_bytes(substream) - 1;
611 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
613 if (snd_pcm_format_width(runtime->format) == 16)
615 if (runtime->channels == 2)
617 rate = (runtime->rate * 8192) / 375;
618 if (rate > 0x000fffff)
620 ice->playback_con_active_buf[substream->number] = 0;
621 ice->playback_con_virt_addr[substream->number] = runtime->dma_addr;
622 chn = substream->number * 2;
623 spin_lock_irq(&ice->reg_lock);
624 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR0, runtime->dma_addr);
625 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT0, period_size);
626 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR1, runtime->dma_addr + (runtime->periods > 1 ? period_size + 1 : 0));
627 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT1, period_size);
628 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_RATE, rate);
629 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_VOLUME, 0);
630 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_CONTROL, tmp);
631 if (runtime->channels == 2) {
632 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_RATE, rate);
633 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_VOLUME, 0);
635 spin_unlock_irq(&ice->reg_lock);
639 static int snd_ice1712_capture_prepare(snd_pcm_substream_t * substream)
641 ice1712_t *ice = snd_pcm_substream_chip(substream);
642 snd_pcm_runtime_t *runtime = substream->runtime;
643 u32 period_size, buf_size;
646 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
647 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
649 if (snd_pcm_format_width(runtime->format) == 16)
651 if (runtime->channels == 2)
653 spin_lock_irq(&ice->reg_lock);
654 outl(ice->capture_con_virt_addr = runtime->dma_addr, ICEREG(ice, CONCAP_ADDR));
655 outw(buf_size, ICEREG(ice, CONCAP_COUNT));
656 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_HI, period_size >> 8);
657 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_LO, period_size & 0xff);
658 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
659 spin_unlock_irq(&ice->reg_lock);
660 snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
664 static snd_pcm_uframes_t snd_ice1712_playback_pointer(snd_pcm_substream_t * substream)
666 ice1712_t *ice = snd_pcm_substream_chip(substream);
667 snd_pcm_runtime_t *runtime = substream->runtime;
670 if (!(snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL) & 1))
672 ptr = runtime->buffer_size - inw(ice->ddma_port + 4);
673 if (ptr == runtime->buffer_size)
675 return bytes_to_frames(substream->runtime, ptr);
678 static snd_pcm_uframes_t snd_ice1712_playback_ds_pointer(snd_pcm_substream_t * substream)
680 ice1712_t *ice = snd_pcm_substream_chip(substream);
684 if (!(snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL) & 1))
686 if (ice->playback_con_active_buf[substream->number])
687 addr = ICE1712_DSC_ADDR1;
689 addr = ICE1712_DSC_ADDR0;
690 ptr = snd_ice1712_ds_read(ice, substream->number * 2, addr) -
691 ice->playback_con_virt_addr[substream->number];
692 if (ptr == substream->runtime->buffer_size)
694 return bytes_to_frames(substream->runtime, ptr);
697 static snd_pcm_uframes_t snd_ice1712_capture_pointer(snd_pcm_substream_t * substream)
699 ice1712_t *ice = snd_pcm_substream_chip(substream);
702 if (!(snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL) & 1))
704 ptr = inl(ICEREG(ice, CONCAP_ADDR)) - ice->capture_con_virt_addr;
705 if (ptr == substream->runtime->buffer_size)
707 return bytes_to_frames(substream->runtime, ptr);
710 static snd_pcm_hardware_t snd_ice1712_playback =
712 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
713 SNDRV_PCM_INFO_BLOCK_TRANSFER |
714 SNDRV_PCM_INFO_MMAP_VALID |
715 SNDRV_PCM_INFO_PAUSE),
716 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
717 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
722 .buffer_bytes_max = (64*1024),
723 .period_bytes_min = 64,
724 .period_bytes_max = (64*1024),
730 static snd_pcm_hardware_t snd_ice1712_playback_ds =
732 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
733 SNDRV_PCM_INFO_BLOCK_TRANSFER |
734 SNDRV_PCM_INFO_MMAP_VALID |
735 SNDRV_PCM_INFO_PAUSE),
736 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
737 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
742 .buffer_bytes_max = (128*1024),
743 .period_bytes_min = 64,
744 .period_bytes_max = (128*1024),
750 static snd_pcm_hardware_t snd_ice1712_capture =
752 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
753 SNDRV_PCM_INFO_BLOCK_TRANSFER |
754 SNDRV_PCM_INFO_MMAP_VALID),
755 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
756 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
761 .buffer_bytes_max = (64*1024),
762 .period_bytes_min = 64,
763 .period_bytes_max = (64*1024),
769 static int snd_ice1712_playback_open(snd_pcm_substream_t * substream)
771 snd_pcm_runtime_t *runtime = substream->runtime;
772 ice1712_t *ice = snd_pcm_substream_chip(substream);
774 ice->playback_con_substream = substream;
775 runtime->hw = snd_ice1712_playback;
779 static int snd_ice1712_playback_ds_open(snd_pcm_substream_t * substream)
781 snd_pcm_runtime_t *runtime = substream->runtime;
782 ice1712_t *ice = snd_pcm_substream_chip(substream);
785 ice->playback_con_substream_ds[substream->number] = substream;
786 runtime->hw = snd_ice1712_playback_ds;
787 spin_lock_irq(&ice->reg_lock);
788 tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2));
789 outw(tmp, ICEDS(ice, INTMASK));
790 spin_unlock_irq(&ice->reg_lock);
794 static int snd_ice1712_capture_open(snd_pcm_substream_t * substream)
796 snd_pcm_runtime_t *runtime = substream->runtime;
797 ice1712_t *ice = snd_pcm_substream_chip(substream);
799 ice->capture_con_substream = substream;
800 runtime->hw = snd_ice1712_capture;
801 runtime->hw.rates = ice->ac97->rates[AC97_RATES_ADC];
802 if (!(runtime->hw.rates & SNDRV_PCM_RATE_8000))
803 runtime->hw.rate_min = 48000;
807 static int snd_ice1712_playback_close(snd_pcm_substream_t * substream)
809 ice1712_t *ice = snd_pcm_substream_chip(substream);
811 ice->playback_con_substream = NULL;
815 static int snd_ice1712_playback_ds_close(snd_pcm_substream_t * substream)
817 ice1712_t *ice = snd_pcm_substream_chip(substream);
820 spin_lock_irq(&ice->reg_lock);
821 tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2));
822 outw(tmp, ICEDS(ice, INTMASK));
823 spin_unlock_irq(&ice->reg_lock);
824 ice->playback_con_substream_ds[substream->number] = NULL;
828 static int snd_ice1712_capture_close(snd_pcm_substream_t * substream)
830 ice1712_t *ice = snd_pcm_substream_chip(substream);
832 ice->capture_con_substream = NULL;
836 static snd_pcm_ops_t snd_ice1712_playback_ops = {
837 .open = snd_ice1712_playback_open,
838 .close = snd_ice1712_playback_close,
839 .ioctl = snd_pcm_lib_ioctl,
840 .hw_params = snd_ice1712_hw_params,
841 .hw_free = snd_ice1712_hw_free,
842 .prepare = snd_ice1712_playback_prepare,
843 .trigger = snd_ice1712_playback_trigger,
844 .pointer = snd_ice1712_playback_pointer,
847 static snd_pcm_ops_t snd_ice1712_playback_ds_ops = {
848 .open = snd_ice1712_playback_ds_open,
849 .close = snd_ice1712_playback_ds_close,
850 .ioctl = snd_pcm_lib_ioctl,
851 .hw_params = snd_ice1712_hw_params,
852 .hw_free = snd_ice1712_hw_free,
853 .prepare = snd_ice1712_playback_ds_prepare,
854 .trigger = snd_ice1712_playback_ds_trigger,
855 .pointer = snd_ice1712_playback_ds_pointer,
858 static snd_pcm_ops_t snd_ice1712_capture_ops = {
859 .open = snd_ice1712_capture_open,
860 .close = snd_ice1712_capture_close,
861 .ioctl = snd_pcm_lib_ioctl,
862 .hw_params = snd_ice1712_hw_params,
863 .hw_free = snd_ice1712_hw_free,
864 .prepare = snd_ice1712_capture_prepare,
865 .trigger = snd_ice1712_capture_trigger,
866 .pointer = snd_ice1712_capture_pointer,
869 static void snd_ice1712_pcm_free(snd_pcm_t *pcm)
871 ice1712_t *ice = pcm->private_data;
873 snd_pcm_lib_preallocate_free_for_all(pcm);
876 static int __devinit snd_ice1712_pcm(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
883 err = snd_pcm_new(ice->card, "ICE1712 consumer", device, 1, 1, &pcm);
887 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ops);
888 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_ops);
890 pcm->private_data = ice;
891 pcm->private_free = snd_ice1712_pcm_free;
893 strcpy(pcm->name, "ICE1712 consumer");
896 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
897 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
902 printk(KERN_WARNING "Consumer PCM code does not work well at the moment --jk\n");
907 static void snd_ice1712_pcm_free_ds(snd_pcm_t *pcm)
909 ice1712_t *ice = pcm->private_data;
911 snd_pcm_lib_preallocate_free_for_all(pcm);
914 static int __devinit snd_ice1712_pcm_ds(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
921 err = snd_pcm_new(ice->card, "ICE1712 consumer (DS)", device, 6, 0, &pcm);
925 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ds_ops);
927 pcm->private_data = ice;
928 pcm->private_free = snd_ice1712_pcm_free_ds;
930 strcpy(pcm->name, "ICE1712 consumer (DS)");
933 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
934 snd_dma_pci_data(ice->pci), 64*1024, 128*1024);
943 * PCM code - professional part (multitrack)
946 static unsigned int rates[] = { 8000, 9600, 11025, 12000, 16000, 22050, 24000,
947 32000, 44100, 48000, 64000, 88200, 96000 };
949 static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
950 .count = ARRAY_SIZE(rates),
955 static int snd_ice1712_pro_trigger(snd_pcm_substream_t *substream,
958 ice1712_t *ice = snd_pcm_substream_chip(substream);
960 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
961 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
965 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
967 what = ICE1712_PLAYBACK_PAUSE;
968 snd_pcm_trigger_done(substream, substream);
969 spin_lock(&ice->reg_lock);
970 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
971 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
975 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
976 spin_unlock(&ice->reg_lock);
979 case SNDRV_PCM_TRIGGER_START:
980 case SNDRV_PCM_TRIGGER_STOP:
982 unsigned int what = 0;
984 struct list_head *pos;
985 snd_pcm_substream_t *s;
987 snd_pcm_group_for_each(pos, substream) {
988 s = snd_pcm_group_substream_entry(pos);
989 if (s == ice->playback_pro_substream) {
990 what |= ICE1712_PLAYBACK_START;
991 snd_pcm_trigger_done(s, substream);
992 } else if (s == ice->capture_pro_substream) {
993 what |= ICE1712_CAPTURE_START_SHADOW;
994 snd_pcm_trigger_done(s, substream);
997 spin_lock(&ice->reg_lock);
998 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
999 if (cmd == SNDRV_PCM_TRIGGER_START)
1003 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
1004 spin_unlock(&ice->reg_lock);
1015 static void snd_ice1712_set_pro_rate(ice1712_t *ice, unsigned int rate, int force)
1017 unsigned long flags;
1021 spin_lock_irqsave(&ice->reg_lock, flags);
1022 if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
1023 ICE1712_PLAYBACK_PAUSE|
1024 ICE1712_PLAYBACK_START)) {
1025 spin_unlock_irqrestore(&ice->reg_lock, flags);
1028 if (!force && is_pro_rate_locked(ice)) {
1029 spin_unlock_irqrestore(&ice->reg_lock, flags);
1034 case 8000: val = 6; break;
1035 case 9600: val = 3; break;
1036 case 11025: val = 10; break;
1037 case 12000: val = 2; break;
1038 case 16000: val = 5; break;
1039 case 22050: val = 9; break;
1040 case 24000: val = 1; break;
1041 case 32000: val = 4; break;
1042 case 44100: val = 8; break;
1043 case 48000: val = 0; break;
1044 case 64000: val = 15; break;
1045 case 88200: val = 11; break;
1046 case 96000: val = 7; break;
1053 outb(val, ICEMT(ice, RATE));
1055 spin_unlock_irqrestore(&ice->reg_lock, flags);
1057 if (ice->gpio.set_pro_rate)
1058 ice->gpio.set_pro_rate(ice, rate);
1059 for (i = 0; i < ice->akm_codecs; i++) {
1060 if (ice->akm[i].ops.set_rate_val)
1061 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
1063 if (ice->spdif.ops.setup_rate)
1064 ice->spdif.ops.setup_rate(ice, rate);
1067 static int snd_ice1712_playback_pro_prepare(snd_pcm_substream_t * substream)
1069 ice1712_t *ice = snd_pcm_substream_chip(substream);
1071 ice->playback_pro_size = snd_pcm_lib_buffer_bytes(substream);
1072 spin_lock_irq(&ice->reg_lock);
1073 outl(substream->runtime->dma_addr, ICEMT(ice, PLAYBACK_ADDR));
1074 outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));
1075 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT));
1076 spin_unlock_irq(&ice->reg_lock);
1081 static int snd_ice1712_playback_pro_hw_params(snd_pcm_substream_t * substream,
1082 snd_pcm_hw_params_t * hw_params)
1084 ice1712_t *ice = snd_pcm_substream_chip(substream);
1086 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1087 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1090 static int snd_ice1712_capture_pro_prepare(snd_pcm_substream_t * substream)
1092 ice1712_t *ice = snd_pcm_substream_chip(substream);
1094 ice->capture_pro_size = snd_pcm_lib_buffer_bytes(substream);
1095 spin_lock_irq(&ice->reg_lock);
1096 outl(substream->runtime->dma_addr, ICEMT(ice, CAPTURE_ADDR));
1097 outw((ice->capture_pro_size >> 2) - 1, ICEMT(ice, CAPTURE_SIZE));
1098 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, CAPTURE_COUNT));
1099 spin_unlock_irq(&ice->reg_lock);
1103 static int snd_ice1712_capture_pro_hw_params(snd_pcm_substream_t * substream,
1104 snd_pcm_hw_params_t * hw_params)
1106 ice1712_t *ice = snd_pcm_substream_chip(substream);
1108 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1109 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1112 static snd_pcm_uframes_t snd_ice1712_playback_pro_pointer(snd_pcm_substream_t * substream)
1114 ice1712_t *ice = snd_pcm_substream_chip(substream);
1117 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_PLAYBACK_START))
1119 ptr = ice->playback_pro_size - (inw(ICEMT(ice, PLAYBACK_SIZE)) << 2);
1120 if (ptr == substream->runtime->buffer_size)
1122 return bytes_to_frames(substream->runtime, ptr);
1125 static snd_pcm_uframes_t snd_ice1712_capture_pro_pointer(snd_pcm_substream_t * substream)
1127 ice1712_t *ice = snd_pcm_substream_chip(substream);
1130 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_CAPTURE_START_SHADOW))
1132 ptr = ice->capture_pro_size - (inw(ICEMT(ice, CAPTURE_SIZE)) << 2);
1133 if (ptr == substream->runtime->buffer_size)
1135 return bytes_to_frames(substream->runtime, ptr);
1138 static snd_pcm_hardware_t snd_ice1712_playback_pro =
1140 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1141 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1142 SNDRV_PCM_INFO_MMAP_VALID |
1143 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1144 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1145 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1150 .buffer_bytes_max = (256*1024),
1151 .period_bytes_min = 10 * 4 * 2,
1152 .period_bytes_max = 131040,
1154 .periods_max = 1024,
1158 static snd_pcm_hardware_t snd_ice1712_capture_pro =
1160 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1161 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1162 SNDRV_PCM_INFO_MMAP_VALID |
1163 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1164 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1165 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1170 .buffer_bytes_max = (256*1024),
1171 .period_bytes_min = 12 * 4 * 2,
1172 .period_bytes_max = 131040,
1174 .periods_max = 1024,
1178 static int snd_ice1712_playback_pro_open(snd_pcm_substream_t * substream)
1180 snd_pcm_runtime_t *runtime = substream->runtime;
1181 ice1712_t *ice = snd_pcm_substream_chip(substream);
1183 ice->playback_pro_substream = substream;
1184 runtime->hw = snd_ice1712_playback_pro;
1185 snd_pcm_set_sync(substream);
1186 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1187 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1189 if (ice->spdif.ops.open)
1190 ice->spdif.ops.open(ice, substream);
1195 static int snd_ice1712_capture_pro_open(snd_pcm_substream_t * substream)
1197 ice1712_t *ice = snd_pcm_substream_chip(substream);
1198 snd_pcm_runtime_t *runtime = substream->runtime;
1200 ice->capture_pro_substream = substream;
1201 runtime->hw = snd_ice1712_capture_pro;
1202 snd_pcm_set_sync(substream);
1203 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1204 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1208 static int snd_ice1712_playback_pro_close(snd_pcm_substream_t * substream)
1210 ice1712_t *ice = snd_pcm_substream_chip(substream);
1213 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1214 ice->playback_pro_substream = NULL;
1215 if (ice->spdif.ops.close)
1216 ice->spdif.ops.close(ice, substream);
1221 static int snd_ice1712_capture_pro_close(snd_pcm_substream_t * substream)
1223 ice1712_t *ice = snd_pcm_substream_chip(substream);
1226 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1227 ice->capture_pro_substream = NULL;
1231 static void snd_ice1712_pcm_profi_free(snd_pcm_t *pcm)
1233 ice1712_t *ice = pcm->private_data;
1234 ice->pcm_pro = NULL;
1235 snd_pcm_lib_preallocate_free_for_all(pcm);
1238 static snd_pcm_ops_t snd_ice1712_playback_pro_ops = {
1239 .open = snd_ice1712_playback_pro_open,
1240 .close = snd_ice1712_playback_pro_close,
1241 .ioctl = snd_pcm_lib_ioctl,
1242 .hw_params = snd_ice1712_playback_pro_hw_params,
1243 .hw_free = snd_ice1712_hw_free,
1244 .prepare = snd_ice1712_playback_pro_prepare,
1245 .trigger = snd_ice1712_pro_trigger,
1246 .pointer = snd_ice1712_playback_pro_pointer,
1249 static snd_pcm_ops_t snd_ice1712_capture_pro_ops = {
1250 .open = snd_ice1712_capture_pro_open,
1251 .close = snd_ice1712_capture_pro_close,
1252 .ioctl = snd_pcm_lib_ioctl,
1253 .hw_params = snd_ice1712_capture_pro_hw_params,
1254 .hw_free = snd_ice1712_hw_free,
1255 .prepare = snd_ice1712_capture_pro_prepare,
1256 .trigger = snd_ice1712_pro_trigger,
1257 .pointer = snd_ice1712_capture_pro_pointer,
1260 static int __devinit snd_ice1712_pcm_profi(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
1267 err = snd_pcm_new(ice->card, "ICE1712 multi", device, 1, 1, &pcm);
1271 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_pro_ops);
1272 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_pro_ops);
1274 pcm->private_data = ice;
1275 pcm->private_free = snd_ice1712_pcm_profi_free;
1276 pcm->info_flags = 0;
1277 strcpy(pcm->name, "ICE1712 multi");
1279 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1280 snd_dma_pci_data(ice->pci), 256*1024, 256*1024);
1287 /* assign channels to iec958 */
1288 err = snd_cs8427_iec958_build(ice->cs8427,
1289 pcm->streams[0].substream,
1290 pcm->streams[1].substream);
1295 if ((err = snd_ice1712_build_pro_mixer(ice)) < 0)
1304 static void snd_ice1712_update_volume(ice1712_t *ice, int index)
1306 unsigned int vol = ice->pro_volumes[index];
1307 unsigned short val = 0;
1309 val |= (vol & 0x8000) == 0 ? (96 - (vol & 0x7f)) : 0x7f;
1310 val |= ((vol & 0x80000000) == 0 ? (96 - ((vol >> 16) & 0x7f)) : 0x7f) << 8;
1311 outb(index, ICEMT(ice, MONITOR_INDEX));
1312 outw(val, ICEMT(ice, MONITOR_VOLUME));
1315 static int snd_ice1712_pro_mixer_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1317 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1319 uinfo->value.integer.min = 0;
1320 uinfo->value.integer.max = 1;
1324 static int snd_ice1712_pro_mixer_switch_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1326 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1327 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1329 spin_lock_irq(&ice->reg_lock);
1330 ucontrol->value.integer.value[0] = !((ice->pro_volumes[index] >> 15) & 1);
1331 ucontrol->value.integer.value[1] = !((ice->pro_volumes[index] >> 31) & 1);
1332 spin_unlock_irq(&ice->reg_lock);
1336 static int snd_ice1712_pro_mixer_switch_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1338 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1339 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1340 unsigned int nval, change;
1342 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
1343 (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
1344 spin_lock_irq(&ice->reg_lock);
1345 nval |= ice->pro_volumes[index] & ~0x80008000;
1346 change = nval != ice->pro_volumes[index];
1347 ice->pro_volumes[index] = nval;
1348 snd_ice1712_update_volume(ice, index);
1349 spin_unlock_irq(&ice->reg_lock);
1353 static int snd_ice1712_pro_mixer_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1355 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1357 uinfo->value.integer.min = 0;
1358 uinfo->value.integer.max = 96;
1362 static int snd_ice1712_pro_mixer_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1364 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1365 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1367 spin_lock_irq(&ice->reg_lock);
1368 ucontrol->value.integer.value[0] = (ice->pro_volumes[index] >> 0) & 127;
1369 ucontrol->value.integer.value[1] = (ice->pro_volumes[index] >> 16) & 127;
1370 spin_unlock_irq(&ice->reg_lock);
1374 static int snd_ice1712_pro_mixer_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1376 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1377 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1378 unsigned int nval, change;
1380 nval = (ucontrol->value.integer.value[0] & 127) |
1381 ((ucontrol->value.integer.value[1] & 127) << 16);
1382 spin_lock_irq(&ice->reg_lock);
1383 nval |= ice->pro_volumes[index] & ~0x007f007f;
1384 change = nval != ice->pro_volumes[index];
1385 ice->pro_volumes[index] = nval;
1386 snd_ice1712_update_volume(ice, index);
1387 spin_unlock_irq(&ice->reg_lock);
1392 static snd_kcontrol_new_t snd_ice1712_multi_playback_ctrls[] __devinitdata = {
1394 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1395 .name = "Multi Playback Switch",
1396 .info = snd_ice1712_pro_mixer_switch_info,
1397 .get = snd_ice1712_pro_mixer_switch_get,
1398 .put = snd_ice1712_pro_mixer_switch_put,
1403 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1404 .name = "Multi Playback Volume",
1405 .info = snd_ice1712_pro_mixer_volume_info,
1406 .get = snd_ice1712_pro_mixer_volume_get,
1407 .put = snd_ice1712_pro_mixer_volume_put,
1413 static snd_kcontrol_new_t snd_ice1712_multi_capture_analog_switch __devinitdata = {
1414 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1415 .name = "H/W Multi Capture Switch",
1416 .info = snd_ice1712_pro_mixer_switch_info,
1417 .get = snd_ice1712_pro_mixer_switch_get,
1418 .put = snd_ice1712_pro_mixer_switch_put,
1419 .private_value = 10,
1422 static snd_kcontrol_new_t snd_ice1712_multi_capture_spdif_switch __devinitdata = {
1423 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1424 .name = "IEC958 Multi Capture Switch",
1425 .info = snd_ice1712_pro_mixer_switch_info,
1426 .get = snd_ice1712_pro_mixer_switch_get,
1427 .put = snd_ice1712_pro_mixer_switch_put,
1428 .private_value = 18,
1432 static snd_kcontrol_new_t snd_ice1712_multi_capture_analog_volume __devinitdata = {
1433 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1434 .name = "H/W Multi Capture Volume",
1435 .info = snd_ice1712_pro_mixer_volume_info,
1436 .get = snd_ice1712_pro_mixer_volume_get,
1437 .put = snd_ice1712_pro_mixer_volume_put,
1438 .private_value = 10,
1441 static snd_kcontrol_new_t snd_ice1712_multi_capture_spdif_volume __devinitdata = {
1442 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1443 .name = "IEC958 Multi Capture Volume",
1444 .info = snd_ice1712_pro_mixer_volume_info,
1445 .get = snd_ice1712_pro_mixer_volume_get,
1446 .put = snd_ice1712_pro_mixer_volume_put,
1447 .private_value = 18,
1451 static int __devinit snd_ice1712_build_pro_mixer(ice1712_t *ice)
1453 snd_card_t * card = ice->card;
1457 /* multi-channel mixer */
1458 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_multi_playback_ctrls); idx++) {
1459 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_playback_ctrls[idx], ice));
1464 if (ice->num_total_adcs > 0) {
1465 snd_kcontrol_new_t tmp = snd_ice1712_multi_capture_analog_switch;
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_switch, ice));
1476 if (ice->num_total_adcs > 0) {
1477 snd_kcontrol_new_t tmp = snd_ice1712_multi_capture_analog_volume;
1478 tmp.count = ice->num_total_adcs;
1479 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1484 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_volume, ice));
1488 /* initialize volumes */
1489 for (idx = 0; idx < 10; idx++) {
1490 ice->pro_volumes[idx] = 0x80008000; /* mute */
1491 snd_ice1712_update_volume(ice, idx);
1493 for (idx = 10; idx < 10 + ice->num_total_adcs; idx++) {
1494 ice->pro_volumes[idx] = 0x80008000; /* mute */
1495 snd_ice1712_update_volume(ice, idx);
1497 for (idx = 18; idx < 20; idx++) {
1498 ice->pro_volumes[idx] = 0x80008000; /* mute */
1499 snd_ice1712_update_volume(ice, idx);
1504 static void snd_ice1712_mixer_free_ac97(ac97_t *ac97)
1506 ice1712_t *ice = ac97->private_data;
1510 static int __devinit snd_ice1712_ac97_mixer(ice1712_t * ice)
1512 int err, bus_num = 0;
1513 ac97_template_t ac97;
1515 static ac97_bus_ops_t con_ops = {
1516 .write = snd_ice1712_ac97_write,
1517 .read = snd_ice1712_ac97_read,
1519 static ac97_bus_ops_t pro_ops = {
1520 .write = snd_ice1712_pro_ac97_write,
1521 .read = snd_ice1712_pro_ac97_read,
1524 if (ice_has_con_ac97(ice)) {
1525 if ((err = snd_ac97_bus(ice->card, bus_num++, &con_ops, NULL, &pbus)) < 0)
1527 memset(&ac97, 0, sizeof(ac97));
1528 ac97.private_data = ice;
1529 ac97.private_free = snd_ice1712_mixer_free_ac97;
1530 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1531 printk(KERN_WARNING "ice1712: cannot initialize ac97 for consumer, skipped\n");
1533 if ((err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice))) < 0)
1539 if (! (ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) {
1540 if ((err = snd_ac97_bus(ice->card, bus_num, &pro_ops, NULL, &pbus)) < 0)
1542 memset(&ac97, 0, sizeof(ac97));
1543 ac97.private_data = ice;
1544 ac97.private_free = snd_ice1712_mixer_free_ac97;
1545 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1546 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1550 /* I2S mixer only */
1551 strcat(ice->card->mixername, "ICE1712 - multitrack");
1559 static inline unsigned int eeprom_double(ice1712_t *ice, int idx)
1561 return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8);
1564 static void snd_ice1712_proc_read(snd_info_entry_t *entry,
1565 snd_info_buffer_t * buffer)
1567 ice1712_t *ice = entry->private_data;
1570 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1571 snd_iprintf(buffer, "EEPROM:\n");
1573 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1574 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1575 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1576 snd_iprintf(buffer, " Codec : 0x%x\n", ice->eeprom.data[ICE_EEP1_CODEC]);
1577 snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP1_ACLINK]);
1578 snd_iprintf(buffer, " I2S ID : 0x%x\n", ice->eeprom.data[ICE_EEP1_I2SID]);
1579 snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP1_SPDIF]);
1580 snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
1581 snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
1582 snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
1583 snd_iprintf(buffer, " AC'97 main : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_MAIN_LO));
1584 snd_iprintf(buffer, " AC'97 pcm : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_PCM_LO));
1585 snd_iprintf(buffer, " AC'97 record : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_REC_LO));
1586 snd_iprintf(buffer, " AC'97 record src : 0x%x\n", ice->eeprom.data[ICE_EEP1_AC97_RECSRC]);
1587 for (idx = 0; idx < 4; idx++)
1588 snd_iprintf(buffer, " DAC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_DAC_ID + idx]);
1589 for (idx = 0; idx < 4; idx++)
1590 snd_iprintf(buffer, " ADC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_ADC_ID + idx]);
1591 for (idx = 0x1c; idx < ice->eeprom.size; idx++)
1592 snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
1594 snd_iprintf(buffer, "\nRegisters:\n");
1595 snd_iprintf(buffer, " PSDOUT03 : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_PSDOUT03)));
1596 snd_iprintf(buffer, " CAPTURE : 0x%08x\n", inl(ICEMT(ice, ROUTE_CAPTURE)));
1597 snd_iprintf(buffer, " SPDOUT : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT)));
1598 snd_iprintf(buffer, " RATE : 0x%02x\n", (unsigned)inb(ICEMT(ice, RATE)));
1601 static void __devinit snd_ice1712_proc_init(ice1712_t * ice)
1603 snd_info_entry_t *entry;
1605 if (! snd_card_proc_new(ice->card, "ice1712", &entry))
1606 snd_info_set_text_ops(entry, ice, 1024, snd_ice1712_proc_read);
1613 static int snd_ice1712_eeprom_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1615 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1616 uinfo->count = sizeof(ice1712_eeprom_t);
1620 static int snd_ice1712_eeprom_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1622 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1624 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1628 static snd_kcontrol_new_t snd_ice1712_eeprom __devinitdata = {
1629 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1630 .name = "ICE1712 EEPROM",
1631 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1632 .info = snd_ice1712_eeprom_info,
1633 .get = snd_ice1712_eeprom_get
1638 static int snd_ice1712_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1640 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1645 static int snd_ice1712_spdif_default_get(snd_kcontrol_t * kcontrol,
1646 snd_ctl_elem_value_t * ucontrol)
1648 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1649 if (ice->spdif.ops.default_get)
1650 ice->spdif.ops.default_get(ice, ucontrol);
1654 static int snd_ice1712_spdif_default_put(snd_kcontrol_t * kcontrol,
1655 snd_ctl_elem_value_t * ucontrol)
1657 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1658 if (ice->spdif.ops.default_put)
1659 return ice->spdif.ops.default_put(ice, ucontrol);
1663 static snd_kcontrol_new_t snd_ice1712_spdif_default __devinitdata =
1665 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1666 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1667 .info = snd_ice1712_spdif_info,
1668 .get = snd_ice1712_spdif_default_get,
1669 .put = snd_ice1712_spdif_default_put
1672 static int snd_ice1712_spdif_maskc_get(snd_kcontrol_t * kcontrol,
1673 snd_ctl_elem_value_t * ucontrol)
1675 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1676 if (ice->spdif.ops.default_get) {
1677 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1678 IEC958_AES0_PROFESSIONAL |
1679 IEC958_AES0_CON_NOT_COPYRIGHT |
1680 IEC958_AES0_CON_EMPHASIS;
1681 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1682 IEC958_AES1_CON_CATEGORY;
1683 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1685 ucontrol->value.iec958.status[0] = 0xff;
1686 ucontrol->value.iec958.status[1] = 0xff;
1687 ucontrol->value.iec958.status[2] = 0xff;
1688 ucontrol->value.iec958.status[3] = 0xff;
1689 ucontrol->value.iec958.status[4] = 0xff;
1694 static int snd_ice1712_spdif_maskp_get(snd_kcontrol_t * kcontrol,
1695 snd_ctl_elem_value_t * ucontrol)
1697 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1698 if (ice->spdif.ops.default_get) {
1699 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1700 IEC958_AES0_PROFESSIONAL |
1701 IEC958_AES0_PRO_FS |
1702 IEC958_AES0_PRO_EMPHASIS;
1703 ucontrol->value.iec958.status[1] = IEC958_AES1_PRO_MODE;
1705 ucontrol->value.iec958.status[0] = 0xff;
1706 ucontrol->value.iec958.status[1] = 0xff;
1707 ucontrol->value.iec958.status[2] = 0xff;
1708 ucontrol->value.iec958.status[3] = 0xff;
1709 ucontrol->value.iec958.status[4] = 0xff;
1714 static snd_kcontrol_new_t snd_ice1712_spdif_maskc __devinitdata =
1716 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1717 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1718 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1719 .info = snd_ice1712_spdif_info,
1720 .get = snd_ice1712_spdif_maskc_get,
1723 static snd_kcontrol_new_t snd_ice1712_spdif_maskp __devinitdata =
1725 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1726 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1727 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1728 .info = snd_ice1712_spdif_info,
1729 .get = snd_ice1712_spdif_maskp_get,
1732 static int snd_ice1712_spdif_stream_get(snd_kcontrol_t * kcontrol,
1733 snd_ctl_elem_value_t * ucontrol)
1735 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1736 if (ice->spdif.ops.stream_get)
1737 ice->spdif.ops.stream_get(ice, ucontrol);
1741 static int snd_ice1712_spdif_stream_put(snd_kcontrol_t * kcontrol,
1742 snd_ctl_elem_value_t * ucontrol)
1744 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1745 if (ice->spdif.ops.stream_put)
1746 return ice->spdif.ops.stream_put(ice, ucontrol);
1750 static snd_kcontrol_new_t snd_ice1712_spdif_stream __devinitdata =
1752 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1753 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1754 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
1755 .info = snd_ice1712_spdif_info,
1756 .get = snd_ice1712_spdif_stream_get,
1757 .put = snd_ice1712_spdif_stream_put
1760 int snd_ice1712_gpio_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1762 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1764 uinfo->value.integer.min = 0;
1765 uinfo->value.integer.max = 1;
1769 int snd_ice1712_gpio_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1771 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1772 unsigned char mask = kcontrol->private_value & 0xff;
1773 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1775 snd_ice1712_save_gpio_status(ice);
1776 ucontrol->value.integer.value[0] = (snd_ice1712_gpio_read(ice) & mask ? 1 : 0) ^ invert;
1777 snd_ice1712_restore_gpio_status(ice);
1781 int snd_ice1712_gpio_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1783 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1784 unsigned char mask = kcontrol->private_value & 0xff;
1785 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1786 unsigned int val, nval;
1788 if (kcontrol->private_value & (1 << 31))
1790 nval = (ucontrol->value.integer.value[0] ? mask : 0) ^ invert;
1791 snd_ice1712_save_gpio_status(ice);
1792 val = snd_ice1712_gpio_read(ice);
1793 nval |= val & ~mask;
1795 snd_ice1712_gpio_write(ice, nval);
1796 snd_ice1712_restore_gpio_status(ice);
1803 static int snd_ice1712_pro_internal_clock_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1805 static char *texts[] = {
1808 "11025", /* 2: 10 */
1816 "64000", /* 10: 15 */
1817 "88200", /* 11: 11 */
1818 "96000", /* 12: 7 */
1819 "IEC958 Input", /* 13: -- */
1821 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1823 uinfo->value.enumerated.items = 14;
1824 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1825 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1826 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1830 static int snd_ice1712_pro_internal_clock_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1832 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1833 static unsigned char xlate[16] = {
1834 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10
1838 spin_lock_irq(&ice->reg_lock);
1839 if (is_spdif_master(ice)) {
1840 ucontrol->value.enumerated.item[0] = 13;
1842 val = xlate[inb(ICEMT(ice, RATE)) & 15];
1847 ucontrol->value.enumerated.item[0] = val;
1849 spin_unlock_irq(&ice->reg_lock);
1853 static int snd_ice1712_pro_internal_clock_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1855 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1856 static unsigned int xrate[13] = {
1857 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1858 32000, 44100, 48000, 64000, 88200, 96000
1863 spin_lock_irq(&ice->reg_lock);
1864 oval = inb(ICEMT(ice, RATE));
1865 if (ucontrol->value.enumerated.item[0] == 13) {
1866 outb(oval | ICE1712_SPDIF_MASTER, ICEMT(ice, RATE));
1868 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1869 spin_unlock_irq(&ice->reg_lock);
1870 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1871 spin_lock_irq(&ice->reg_lock);
1873 change = inb(ICEMT(ice, RATE)) != oval;
1874 spin_unlock_irq(&ice->reg_lock);
1876 if ((oval & ICE1712_SPDIF_MASTER) != (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER)) {
1877 /* change CS8427 clock source too */
1879 snd_ice1712_cs8427_set_input_clock(ice, is_spdif_master(ice));
1881 /* notify ak4524 chip as well */
1882 if (is_spdif_master(ice)) {
1884 for (i = 0; i < ice->akm_codecs; i++) {
1885 if (ice->akm[i].ops.set_rate_val)
1886 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
1894 static snd_kcontrol_new_t snd_ice1712_pro_internal_clock __devinitdata = {
1895 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1896 .name = "Multi Track Internal Clock",
1897 .info = snd_ice1712_pro_internal_clock_info,
1898 .get = snd_ice1712_pro_internal_clock_get,
1899 .put = snd_ice1712_pro_internal_clock_put
1902 static int snd_ice1712_pro_internal_clock_default_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1904 static char *texts[] = {
1907 "11025", /* 2: 10 */
1915 "64000", /* 10: 15 */
1916 "88200", /* 11: 11 */
1917 "96000", /* 12: 7 */
1918 // "IEC958 Input", /* 13: -- */
1920 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1922 uinfo->value.enumerated.items = 13;
1923 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1924 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1925 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1929 static int snd_ice1712_pro_internal_clock_default_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1932 static unsigned int xrate[13] = {
1933 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1934 32000, 44100, 48000, 64000, 88200, 96000
1937 for (val = 0; val < 13; val++) {
1938 if (xrate[val] == PRO_RATE_DEFAULT)
1942 ucontrol->value.enumerated.item[0] = val;
1946 static int snd_ice1712_pro_internal_clock_default_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1948 static unsigned int xrate[13] = {
1949 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1950 32000, 44100, 48000, 64000, 88200, 96000
1955 oval = PRO_RATE_DEFAULT;
1956 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1957 change = PRO_RATE_DEFAULT != oval;
1962 static snd_kcontrol_new_t snd_ice1712_pro_internal_clock_default __devinitdata = {
1963 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1964 .name = "Multi Track Internal Clock Default",
1965 .info = snd_ice1712_pro_internal_clock_default_info,
1966 .get = snd_ice1712_pro_internal_clock_default_get,
1967 .put = snd_ice1712_pro_internal_clock_default_put
1970 static int snd_ice1712_pro_rate_locking_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1972 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1974 uinfo->value.integer.min = 0;
1975 uinfo->value.integer.max = 1;
1979 static int snd_ice1712_pro_rate_locking_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1981 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1985 static int snd_ice1712_pro_rate_locking_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1987 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1988 int change = 0, nval;
1990 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1991 spin_lock_irq(&ice->reg_lock);
1992 change = PRO_RATE_LOCKED != nval;
1993 PRO_RATE_LOCKED = nval;
1994 spin_unlock_irq(&ice->reg_lock);
1998 static snd_kcontrol_new_t snd_ice1712_pro_rate_locking __devinitdata = {
1999 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2000 .name = "Multi Track Rate Locking",
2001 .info = snd_ice1712_pro_rate_locking_info,
2002 .get = snd_ice1712_pro_rate_locking_get,
2003 .put = snd_ice1712_pro_rate_locking_put
2006 static int snd_ice1712_pro_rate_reset_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2008 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2010 uinfo->value.integer.min = 0;
2011 uinfo->value.integer.max = 1;
2015 static int snd_ice1712_pro_rate_reset_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2017 ucontrol->value.integer.value[0] = PRO_RATE_RESET;
2021 static int snd_ice1712_pro_rate_reset_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2023 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2024 int change = 0, nval;
2026 nval = ucontrol->value.integer.value[0] ? 1 : 0;
2027 spin_lock_irq(&ice->reg_lock);
2028 change = PRO_RATE_RESET != nval;
2029 PRO_RATE_RESET = nval;
2030 spin_unlock_irq(&ice->reg_lock);
2034 static snd_kcontrol_new_t snd_ice1712_pro_rate_reset __devinitdata = {
2035 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2036 .name = "Multi Track Rate Reset",
2037 .info = snd_ice1712_pro_rate_reset_info,
2038 .get = snd_ice1712_pro_rate_reset_get,
2039 .put = snd_ice1712_pro_rate_reset_put
2045 static int snd_ice1712_pro_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2047 static char *texts[] = {
2049 "H/W In 0", "H/W In 1", "H/W In 2", "H/W In 3", /* 1-4 */
2050 "H/W In 4", "H/W In 5", "H/W In 6", "H/W In 7", /* 5-8 */
2051 "IEC958 In L", "IEC958 In R", /* 9-10 */
2052 "Digital Mixer", /* 11 - optional */
2055 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2057 uinfo->value.enumerated.items = snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
2058 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2059 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2060 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2064 static int snd_ice1712_pro_route_analog_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
2066 ice1712_t *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(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
2091 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2093 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2094 unsigned int val, old_val, nval;
2097 if (ucontrol->value.enumerated.item[0] >= 11)
2098 nval = idx < 2 ? 1 : 0; /* dig mixer (or pcm) */
2099 else if (ucontrol->value.enumerated.item[0] >= 9)
2100 nval = 3; /* spdif in */
2101 else if (ucontrol->value.enumerated.item[0] >= 1)
2102 nval = 2; /* analog in */
2105 shift = ((idx % 2) * 8) + ((idx / 2) * 2);
2106 spin_lock_irq(&ice->reg_lock);
2107 val = old_val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2108 val &= ~(0x03 << shift);
2109 val |= nval << shift;
2110 change = val != old_val;
2112 outw(val, ICEMT(ice, ROUTE_PSDOUT03));
2113 spin_unlock_irq(&ice->reg_lock);
2114 if (nval < 2) /* dig mixer of pcm */
2117 /* update CAPTURE */
2118 spin_lock_irq(&ice->reg_lock);
2119 val = old_val = inl(ICEMT(ice, ROUTE_CAPTURE));
2120 shift = ((idx / 2) * 8) + ((idx % 2) * 4);
2121 if (nval == 2) { /* analog in */
2122 nval = ucontrol->value.enumerated.item[0] - 1;
2123 val &= ~(0x07 << shift);
2124 val |= nval << shift;
2125 } else { /* spdif in */
2126 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2127 val &= ~(0x08 << shift);
2128 val |= nval << shift;
2130 if (val != old_val) {
2132 outl(val, ICEMT(ice, ROUTE_CAPTURE));
2134 spin_unlock_irq(&ice->reg_lock);
2138 static int snd_ice1712_pro_route_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
2140 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2141 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2142 unsigned int val, cval;
2143 val = inw(ICEMT(ice, ROUTE_SPDOUT));
2144 cval = (val >> (idx * 4 + 8)) & 0x0f;
2145 val = (val >> (idx * 2)) & 0x03;
2147 ucontrol->value.enumerated.item[0] = 11;
2149 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2151 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2153 ucontrol->value.enumerated.item[0] = 0;
2157 static int snd_ice1712_pro_route_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
2159 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2161 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2162 unsigned int val, old_val, nval;
2165 spin_lock_irq(&ice->reg_lock);
2166 val = old_val = inw(ICEMT(ice, ROUTE_SPDOUT));
2167 if (ucontrol->value.enumerated.item[0] >= 11)
2169 else if (ucontrol->value.enumerated.item[0] >= 9)
2171 else if (ucontrol->value.enumerated.item[0] >= 1)
2176 val &= ~(0x03 << shift);
2177 val |= nval << shift;
2178 shift = idx * 4 + 8;
2180 nval = ucontrol->value.enumerated.item[0] - 1;
2181 val &= ~(0x07 << shift);
2182 val |= nval << shift;
2183 } else if (nval == 3) {
2184 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2185 val &= ~(0x08 << shift);
2186 val |= nval << shift;
2188 change = val != old_val;
2190 outw(val, ICEMT(ice, ROUTE_SPDOUT));
2191 spin_unlock_irq(&ice->reg_lock);
2195 static snd_kcontrol_new_t snd_ice1712_mixer_pro_analog_route __devinitdata = {
2196 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2197 .name = "H/W Playback Route",
2198 .info = snd_ice1712_pro_route_info,
2199 .get = snd_ice1712_pro_route_analog_get,
2200 .put = snd_ice1712_pro_route_analog_put,
2203 static snd_kcontrol_new_t snd_ice1712_mixer_pro_spdif_route __devinitdata = {
2204 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2205 .name = "IEC958 Playback Route",
2206 .info = snd_ice1712_pro_route_info,
2207 .get = snd_ice1712_pro_route_spdif_get,
2208 .put = snd_ice1712_pro_route_spdif_put,
2213 static int snd_ice1712_pro_volume_rate_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2215 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2217 uinfo->value.integer.min = 0;
2218 uinfo->value.integer.max = 255;
2222 static int snd_ice1712_pro_volume_rate_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2224 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2226 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE));
2230 static int snd_ice1712_pro_volume_rate_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2232 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2235 spin_lock_irq(&ice->reg_lock);
2236 change = inb(ICEMT(ice, MONITOR_RATE)) != ucontrol->value.integer.value[0];
2237 outb(ucontrol->value.integer.value[0], ICEMT(ice, MONITOR_RATE));
2238 spin_unlock_irq(&ice->reg_lock);
2242 static snd_kcontrol_new_t snd_ice1712_mixer_pro_volume_rate __devinitdata = {
2243 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2244 .name = "Multi Track Volume Rate",
2245 .info = snd_ice1712_pro_volume_rate_info,
2246 .get = snd_ice1712_pro_volume_rate_get,
2247 .put = snd_ice1712_pro_volume_rate_put
2250 static int snd_ice1712_pro_peak_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2252 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2254 uinfo->value.integer.min = 0;
2255 uinfo->value.integer.max = 255;
2259 static int snd_ice1712_pro_peak_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2261 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2264 spin_lock_irq(&ice->reg_lock);
2265 for (idx = 0; idx < 22; idx++) {
2266 outb(idx, ICEMT(ice, MONITOR_PEAKINDEX));
2267 ucontrol->value.integer.value[idx] = inb(ICEMT(ice, MONITOR_PEAKDATA));
2269 spin_unlock_irq(&ice->reg_lock);
2273 static snd_kcontrol_new_t snd_ice1712_mixer_pro_peak __devinitdata = {
2274 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2275 .name = "Multi Track Peak",
2276 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2277 .info = snd_ice1712_pro_peak_info,
2278 .get = snd_ice1712_pro_peak_get
2286 * list of available boards
2288 static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
2289 snd_ice1712_hoontech_cards,
2290 snd_ice1712_delta_cards,
2291 snd_ice1712_ews_cards,
2295 static unsigned char __devinit snd_ice1712_read_i2c(ice1712_t *ice,
2301 outb(addr, ICEREG(ice, I2C_BYTE_ADDR));
2302 outb(dev & ~ICE1712_I2C_WRITE, ICEREG(ice, I2C_DEV_ADDR));
2303 while (t-- > 0 && (inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_BUSY)) ;
2304 return inb(ICEREG(ice, I2C_DATA));
2307 static int __devinit snd_ice1712_read_eeprom(ice1712_t *ice, const char *modelname)
2309 int dev = 0xa0; /* EEPROM device address */
2310 unsigned int i, size;
2312 if ((inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_EEPROM) == 0) {
2313 snd_printk("ICE1712 has not detected EEPROM\n");
2316 if (modelname && *modelname) {
2317 struct snd_ice1712_card_info **tbl, *c;
2318 for (tbl = card_tables; *tbl; tbl++) {
2319 for (c = *tbl; c->subvendor; c++) {
2320 if (c->model && !strcmp(modelname, c->model)) {
2321 /* use the given subvendor */
2322 printk(KERN_INFO "ice1712: Using board model %s\n", c->name);
2323 ice->eeprom.subvendor = c->subvendor;
2329 ice->eeprom.subvendor = (snd_ice1712_read_i2c(ice, dev, 0x00) << 0) |
2330 (snd_ice1712_read_i2c(ice, dev, 0x01) << 8) |
2331 (snd_ice1712_read_i2c(ice, dev, 0x02) << 16) |
2332 (snd_ice1712_read_i2c(ice, dev, 0x03) << 24);
2333 ice->eeprom.size = snd_ice1712_read_i2c(ice, dev, 0x04);
2334 if (ice->eeprom.size < 6)
2335 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */
2336 else if (ice->eeprom.size > 32) {
2337 snd_printk("invalid EEPROM (size = %i)\n", ice->eeprom.size);
2340 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05);
2341 if (ice->eeprom.version != 1) {
2342 snd_printk("invalid EEPROM version %i\n", ice->eeprom.version);
2345 size = ice->eeprom.size - 6;
2346 for (i = 0; i < size; i++)
2347 ice->eeprom.data[i] = snd_ice1712_read_i2c(ice, dev, i + 6);
2349 ice->eeprom.gpiomask = ice->eeprom.data[ICE_EEP1_GPIO_MASK];
2350 ice->eeprom.gpiostate = ice->eeprom.data[ICE_EEP1_GPIO_STATE];
2351 ice->eeprom.gpiodir = ice->eeprom.data[ICE_EEP1_GPIO_DIR];
2358 static int __devinit snd_ice1712_chip_init(ice1712_t *ice)
2360 outb(ICE1712_RESET | ICE1712_NATIVE, ICEREG(ice, CONTROL));
2362 outb(ICE1712_NATIVE, ICEREG(ice, CONTROL));
2364 pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]);
2365 pci_write_config_byte(ice->pci, 0x61, ice->eeprom.data[ICE_EEP1_ACLINK]);
2366 pci_write_config_byte(ice->pci, 0x62, ice->eeprom.data[ICE_EEP1_I2SID]);
2367 pci_write_config_byte(ice->pci, 0x63, ice->eeprom.data[ICE_EEP1_SPDIF]);
2368 if (ice->eeprom.subvendor != ICE1712_SUBDEVICE_STDSP24) {
2369 ice->gpio.write_mask = ice->eeprom.gpiomask;
2370 ice->gpio.direction = ice->eeprom.gpiodir;
2371 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ice->eeprom.gpiomask);
2372 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->eeprom.gpiodir);
2373 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ice->eeprom.gpiostate);
2375 ice->gpio.write_mask = 0xc0;
2376 ice->gpio.direction = 0xff;
2377 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, 0xc0);
2378 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, 0xff);
2379 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ICE1712_STDSP24_CLOCK_BIT);
2381 snd_ice1712_write(ice, ICE1712_IREG_PRO_POWERDOWN, 0);
2382 if (!(ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97)) {
2383 outb(ICE1712_AC97_WARM, ICEREG(ice, AC97_CMD));
2385 outb(0, ICEREG(ice, AC97_CMD));
2387 snd_ice1712_write(ice, ICE1712_IREG_CONSUMER_POWERDOWN, 0);
2393 int __devinit snd_ice1712_spdif_build_controls(ice1712_t *ice)
2396 snd_kcontrol_t *kctl;
2398 snd_assert(ice->pcm_pro != NULL, return -EIO);
2399 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_default, ice));
2402 kctl->id.device = ice->pcm_pro->device;
2403 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskc, ice));
2406 kctl->id.device = ice->pcm_pro->device;
2407 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskp, ice));
2410 kctl->id.device = ice->pcm_pro->device;
2411 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_stream, ice));
2414 kctl->id.device = ice->pcm_pro->device;
2415 ice->spdif.stream_ctl = kctl;
2420 static int __devinit snd_ice1712_build_controls(ice1712_t *ice)
2424 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_eeprom, ice));
2427 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock, ice));
2430 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock_default, ice));
2434 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_locking, ice));
2437 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_reset, ice));
2441 if (ice->num_total_dacs > 0) {
2442 snd_kcontrol_new_t tmp = snd_ice1712_mixer_pro_analog_route;
2443 tmp.count = ice->num_total_dacs;
2444 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2449 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice));
2453 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
2456 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice));
2463 static int snd_ice1712_free(ice1712_t *ice)
2467 /* mask all interrupts */
2468 outb(0xc0, ICEMT(ice, IRQ));
2469 outb(0xff, ICEREG(ice, IRQMASK));
2472 if (ice->irq >= 0) {
2473 synchronize_irq(ice->irq);
2474 free_irq(ice->irq, (void *) ice);
2477 pci_release_regions(ice->pci);
2478 snd_ice1712_akm4xxx_free(ice);
2483 static int snd_ice1712_dev_free(snd_device_t *device)
2485 ice1712_t *ice = device->device_data;
2486 return snd_ice1712_free(ice);
2489 static int __devinit snd_ice1712_create(snd_card_t * card,
2490 struct pci_dev *pci,
2491 const char *modelname,
2494 ice1712_t ** r_ice1712)
2498 static snd_device_ops_t ops = {
2499 .dev_free = snd_ice1712_dev_free,
2504 /* enable PCI device */
2505 if ((err = pci_enable_device(pci)) < 0)
2507 /* check, if we can restrict PCI DMA transfers to 28 bits */
2508 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 ||
2509 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) {
2510 snd_printk("architecture does not support 28bit PCI busmaster DMA\n");
2514 ice = kcalloc(1, sizeof(*ice), GFP_KERNEL);
2517 ice->omni = omni ? 1 : 0;
2518 if (cs8427_timeout < 1)
2520 else if (cs8427_timeout > 1000)
2521 cs8427_timeout = 1000;
2522 ice->cs8427_timeout = cs8427_timeout;
2523 spin_lock_init(&ice->reg_lock);
2524 init_MUTEX(&ice->gpio_mutex);
2525 init_MUTEX(&ice->open_mutex);
2526 ice->gpio.set_mask = snd_ice1712_set_gpio_mask;
2527 ice->gpio.set_dir = snd_ice1712_set_gpio_dir;
2528 ice->gpio.set_data = snd_ice1712_set_gpio_data;
2529 ice->gpio.get_data = snd_ice1712_get_gpio_data;
2531 ice->spdif.cs8403_bits =
2532 ice->spdif.cs8403_stream_bits = (0x01 | /* consumer format */
2533 0x10 | /* no emphasis */
2534 0x20); /* PCM encoder/decoder */
2538 pci_set_master(pci);
2539 pci_write_config_word(ice->pci, 0x40, 0x807f);
2540 pci_write_config_word(ice->pci, 0x42, 0x0006);
2541 snd_ice1712_proc_init(ice);
2542 synchronize_irq(pci->irq);
2544 if ((err = pci_request_regions(pci, "ICE1712")) < 0) {
2548 ice->port = pci_resource_start(pci, 0);
2549 ice->ddma_port = pci_resource_start(pci, 1);
2550 ice->dmapath_port = pci_resource_start(pci, 2);
2551 ice->profi_port = pci_resource_start(pci, 3);
2553 if (request_irq(pci->irq, snd_ice1712_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1712", (void *) ice)) {
2554 snd_printk("unable to grab IRQ %d\n", pci->irq);
2555 snd_ice1712_free(ice);
2559 ice->irq = pci->irq;
2561 if (snd_ice1712_read_eeprom(ice, modelname) < 0) {
2562 snd_ice1712_free(ice);
2565 if (snd_ice1712_chip_init(ice) < 0) {
2566 snd_ice1712_free(ice);
2570 /* unmask used interrupts */
2571 outb((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) == 0 ? ICE1712_IRQ_MPU2 : 0 |
2572 (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97) ? ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0,
2573 ICEREG(ice, IRQMASK));
2574 outb(0x00, ICEMT(ice, IRQ));
2576 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2577 snd_ice1712_free(ice);
2581 snd_card_set_dev(card, &pci->dev);
2594 static struct snd_ice1712_card_info no_matched __devinitdata;
2596 static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2597 const struct pci_device_id *pci_id)
2602 int pcm_dev = 0, err;
2603 struct snd_ice1712_card_info **tbl, *c;
2605 if (dev >= SNDRV_CARDS)
2612 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2616 strcpy(card->driver, "ICE1712");
2617 strcpy(card->shortname, "ICEnsemble ICE1712");
2619 if ((err = snd_ice1712_create(card, pci, model[dev], omni[dev], cs8427_timeout[dev], &ice)) < 0) {
2620 snd_card_free(card);
2624 for (tbl = card_tables; *tbl; tbl++) {
2625 for (c = *tbl; c->subvendor; c++) {
2626 if (c->subvendor == ice->eeprom.subvendor) {
2627 strcpy(card->shortname, c->name);
2628 if (c->driver) /* specific driver? */
2629 strcpy(card->driver, c->driver);
2631 if ((err = c->chip_init(ice)) < 0) {
2632 snd_card_free(card);
2643 if ((err = snd_ice1712_pcm_profi(ice, pcm_dev++, NULL)) < 0) {
2644 snd_card_free(card);
2648 if (ice_has_con_ac97(ice))
2649 if ((err = snd_ice1712_pcm(ice, pcm_dev++, NULL)) < 0) {
2650 snd_card_free(card);
2654 if ((err = snd_ice1712_ac97_mixer(ice)) < 0) {
2655 snd_card_free(card);
2659 if ((err = snd_ice1712_build_controls(ice)) < 0) {
2660 snd_card_free(card);
2664 if (c->build_controls) {
2665 if ((err = c->build_controls(ice)) < 0) {
2666 snd_card_free(card);
2671 if (ice_has_con_ac97(ice))
2672 if ((err = snd_ice1712_pcm_ds(ice, pcm_dev++, NULL)) < 0) {
2673 snd_card_free(card);
2677 if (! c->no_mpu401) {
2678 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2679 ICEREG(ice, MPU1_CTRL), 1,
2681 &ice->rmidi[0])) < 0) {
2682 snd_card_free(card);
2686 if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401)
2687 if ((err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712,
2688 ICEREG(ice, MPU2_CTRL), 1,
2690 &ice->rmidi[1])) < 0) {
2691 snd_card_free(card);
2696 sprintf(card->longname, "%s at 0x%lx, irq %i",
2697 card->shortname, ice->port, ice->irq);
2699 if ((err = snd_card_register(card)) < 0) {
2700 snd_card_free(card);
2703 pci_set_drvdata(pci, card);
2708 static void __devexit snd_ice1712_remove(struct pci_dev *pci)
2710 snd_card_free(pci_get_drvdata(pci));
2711 pci_set_drvdata(pci, NULL);
2714 static struct pci_driver driver = {
2716 .id_table = snd_ice1712_ids,
2717 .probe = snd_ice1712_probe,
2718 .remove = __devexit_p(snd_ice1712_remove),
2721 static int __init alsa_card_ice1712_init(void)
2723 return pci_module_init(&driver);
2726 static void __exit alsa_card_ice1712_exit(void)
2728 pci_unregister_driver(&driver);
2731 module_init(alsa_card_ice1712_init)
2732 module_exit(alsa_card_ice1712_exit)