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_CLASSES("{sound}");
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 */
92 module_param_array(index, int, boot_devs, 0444);
93 MODULE_PARM_DESC(index, "Index value for ICE1712 soundcard.");
94 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
95 module_param_array(id, charp, boot_devs, 0444);
96 MODULE_PARM_DESC(id, "ID string for ICE1712 soundcard.");
97 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
98 module_param_array(enable, bool, boot_devs, 0444);
99 MODULE_PARM_DESC(enable, "Enable ICE1712 soundcard.");
100 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
101 module_param_array(omni, bool, boot_devs, 0444);
102 MODULE_PARM_DESC(omni, "Enable Midiman M-Audio Delta Omni I/O support.");
103 MODULE_PARM_SYNTAX(omni, SNDRV_ENABLED "," SNDRV_ENABLE_DESC);
104 module_param_array(cs8427_timeout, int, boot_devs, 0444);
105 MODULE_PARM_DESC(cs8427_timeout, "Define reset timeout for cs8427 chip in msec resolution.");
106 MODULE_PARM_SYNTAX(cs8427_timeout, SNDRV_ENABLED ", allows:{{1,1000}},default=500,skill:advanced");
107 module_param_array(model, charp, boot_devs, 0444);
108 MODULE_PARM_DESC(model, "Use the given board model.");
110 #ifndef PCI_VENDOR_ID_ICE
111 #define PCI_VENDOR_ID_ICE 0x1412
113 #ifndef PCI_DEVICE_ID_ICE_1712
114 #define PCI_DEVICE_ID_ICE_1712 0x1712
117 static struct pci_device_id snd_ice1712_ids[] = {
118 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_ICE_1712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* ICE1712 */
122 MODULE_DEVICE_TABLE(pci, snd_ice1712_ids);
124 static int snd_ice1712_build_pro_mixer(ice1712_t *ice);
125 static int snd_ice1712_build_controls(ice1712_t *ice);
127 static int PRO_RATE_LOCKED;
128 static int PRO_RATE_RESET = 1;
129 static unsigned int PRO_RATE_DEFAULT = 44100;
135 /* check whether the clock mode is spdif-in */
136 static inline int is_spdif_master(ice1712_t *ice)
138 return (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER) ? 1 : 0;
141 static inline int is_pro_rate_locked(ice1712_t *ice)
143 return is_spdif_master(ice) || PRO_RATE_LOCKED;
146 static inline void snd_ice1712_ds_write(ice1712_t * ice, u8 channel, u8 addr, u32 data)
148 outb((channel << 4) | addr, ICEDS(ice, INDEX));
149 outl(data, ICEDS(ice, DATA));
152 static inline u32 snd_ice1712_ds_read(ice1712_t * ice, u8 channel, u8 addr)
154 outb((channel << 4) | addr, ICEDS(ice, INDEX));
155 return inl(ICEDS(ice, DATA));
158 static void snd_ice1712_ac97_write(ac97_t *ac97,
162 ice1712_t *ice = (ice1712_t *)ac97->private_data;
164 unsigned char old_cmd = 0;
166 for (tm = 0; tm < 0x10000; tm++) {
167 old_cmd = inb(ICEREG(ice, AC97_CMD));
168 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
170 if (!(old_cmd & ICE1712_AC97_READY))
174 outb(reg, ICEREG(ice, AC97_INDEX));
175 outw(val, ICEREG(ice, AC97_DATA));
176 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
177 outb(old_cmd | ICE1712_AC97_WRITE, ICEREG(ice, AC97_CMD));
178 for (tm = 0; tm < 0x10000; tm++)
179 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
183 static unsigned short snd_ice1712_ac97_read(ac97_t *ac97,
186 ice1712_t *ice = (ice1712_t *)ac97->private_data;
188 unsigned char old_cmd = 0;
190 for (tm = 0; tm < 0x10000; tm++) {
191 old_cmd = inb(ICEREG(ice, AC97_CMD));
192 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
194 if (!(old_cmd & ICE1712_AC97_READY))
198 outb(reg, ICEREG(ice, AC97_INDEX));
199 outb(old_cmd | ICE1712_AC97_READ, ICEREG(ice, AC97_CMD));
200 for (tm = 0; tm < 0x10000; tm++)
201 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
203 if (tm >= 0x10000) /* timeout */
205 return inw(ICEREG(ice, AC97_DATA));
212 static void snd_ice1712_pro_ac97_write(ac97_t *ac97,
216 ice1712_t *ice = (ice1712_t *)ac97->private_data;
218 unsigned char old_cmd = 0;
220 for (tm = 0; tm < 0x10000; tm++) {
221 old_cmd = inb(ICEMT(ice, AC97_CMD));
222 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
224 if (!(old_cmd & ICE1712_AC97_READY))
228 outb(reg, ICEMT(ice, AC97_INDEX));
229 outw(val, ICEMT(ice, AC97_DATA));
230 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
231 outb(old_cmd | ICE1712_AC97_WRITE, ICEMT(ice, AC97_CMD));
232 for (tm = 0; tm < 0x10000; tm++)
233 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
238 static unsigned short snd_ice1712_pro_ac97_read(ac97_t *ac97,
241 ice1712_t *ice = (ice1712_t *)ac97->private_data;
243 unsigned char old_cmd = 0;
245 for (tm = 0; tm < 0x10000; tm++) {
246 old_cmd = inb(ICEMT(ice, AC97_CMD));
247 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
249 if (!(old_cmd & ICE1712_AC97_READY))
253 outb(reg, ICEMT(ice, AC97_INDEX));
254 outb(old_cmd | ICE1712_AC97_READ, ICEMT(ice, AC97_CMD));
255 for (tm = 0; tm < 0x10000; tm++)
256 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
258 if (tm >= 0x10000) /* timeout */
260 return inw(ICEMT(ice, AC97_DATA));
264 * consumer ac97 digital mix
266 static int snd_ice1712_digmix_route_ac97_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
268 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
270 uinfo->value.integer.min = 0;
271 uinfo->value.integer.max = 1;
275 static int snd_ice1712_digmix_route_ac97_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
277 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
279 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0;
283 static int snd_ice1712_digmix_route_ac97_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
285 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
286 unsigned char val, nval;
288 spin_lock_irq(&ice->reg_lock);
289 val = inb(ICEMT(ice, MONITOR_ROUTECTRL));
290 nval = val & ~ICE1712_ROUTE_AC97;
291 if (ucontrol->value.integer.value[0]) nval |= ICE1712_ROUTE_AC97;
292 outb(nval, ICEMT(ice, MONITOR_ROUTECTRL));
293 spin_unlock_irq(&ice->reg_lock);
297 static snd_kcontrol_new_t snd_ice1712_mixer_digmix_route_ac97 __devinitdata = {
298 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
299 .name = "Digital Mixer To AC97",
300 .info = snd_ice1712_digmix_route_ac97_info,
301 .get = snd_ice1712_digmix_route_ac97_get,
302 .put = snd_ice1712_digmix_route_ac97_put,
309 static void snd_ice1712_set_gpio_dir(ice1712_t *ice, unsigned int data)
311 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, data);
312 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
315 static void snd_ice1712_set_gpio_mask(ice1712_t *ice, unsigned int data)
317 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data);
318 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
321 static unsigned int snd_ice1712_get_gpio_data(ice1712_t *ice)
323 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
326 static void snd_ice1712_set_gpio_data(ice1712_t *ice, unsigned int val)
328 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, val);
329 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
340 * change the input clock selection
341 * spdif_clock = 1 - IEC958 input, 0 - Envy24
343 static int snd_ice1712_cs8427_set_input_clock(ice1712_t *ice, int spdif_clock)
345 unsigned char reg[2] = { 0x80 | 4, 0 }; /* CS8427 auto increment | register number 4 + data */
346 unsigned char val, nval;
349 snd_i2c_lock(ice->i2c);
350 if (snd_i2c_sendbytes(ice->cs8427, reg, 1) != 1) {
351 snd_i2c_unlock(ice->i2c);
354 if (snd_i2c_readbytes(ice->cs8427, &val, 1) != 1) {
355 snd_i2c_unlock(ice->i2c);
365 if (snd_i2c_sendbytes(ice->cs8427, reg, 2) != 2) {
371 snd_i2c_unlock(ice->i2c);
378 static void open_cs8427(ice1712_t *ice, snd_pcm_substream_t * substream)
380 snd_cs8427_iec958_active(ice->cs8427, 1);
383 static void close_cs8427(ice1712_t *ice, snd_pcm_substream_t * substream)
385 snd_cs8427_iec958_active(ice->cs8427, 0);
388 static void setup_cs8427(ice1712_t *ice, int rate)
390 snd_cs8427_iec958_pcm(ice->cs8427, rate);
394 * create and initialize callbacks for cs8427 interface
396 int __devinit snd_ice1712_init_cs8427(ice1712_t *ice, int addr)
400 if ((err = snd_cs8427_create(ice->i2c, addr,
401 (ice->cs8427_timeout * HZ) / 1000,
402 &ice->cs8427)) < 0) {
403 snd_printk("CS8427 initialization failed\n");
406 ice->spdif.ops.open = open_cs8427;
407 ice->spdif.ops.close = close_cs8427;
408 ice->spdif.ops.setup_rate = setup_cs8427;
417 static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
419 ice1712_t *ice = snd_magic_cast(ice1712_t, dev_id, return IRQ_NONE);
420 unsigned char status;
424 status = inb(ICEREG(ice, IRQSTAT));
428 if (status & ICE1712_IRQ_MPU1) {
430 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data, regs);
431 outb(ICE1712_IRQ_MPU1, ICEREG(ice, IRQSTAT));
432 status &= ~ICE1712_IRQ_MPU1;
434 if (status & ICE1712_IRQ_TIMER)
435 outb(ICE1712_IRQ_TIMER, ICEREG(ice, IRQSTAT));
436 if (status & ICE1712_IRQ_MPU2) {
438 snd_mpu401_uart_interrupt(irq, ice->rmidi[1]->private_data, regs);
439 outb(ICE1712_IRQ_MPU2, ICEREG(ice, IRQSTAT));
440 status &= ~ICE1712_IRQ_MPU2;
442 if (status & ICE1712_IRQ_PROPCM) {
443 unsigned char mtstat = inb(ICEMT(ice, IRQ));
444 if (mtstat & ICE1712_MULTI_PBKSTATUS) {
445 if (ice->playback_pro_substream)
446 snd_pcm_period_elapsed(ice->playback_pro_substream);
447 outb(ICE1712_MULTI_PBKSTATUS, ICEMT(ice, IRQ));
449 if (mtstat & ICE1712_MULTI_CAPSTATUS) {
450 if (ice->capture_pro_substream)
451 snd_pcm_period_elapsed(ice->capture_pro_substream);
452 outb(ICE1712_MULTI_CAPSTATUS, ICEMT(ice, IRQ));
455 if (status & ICE1712_IRQ_FM)
456 outb(ICE1712_IRQ_FM, ICEREG(ice, IRQSTAT));
457 if (status & ICE1712_IRQ_PBKDS) {
460 snd_pcm_substream_t *substream;
461 pbkstatus = inw(ICEDS(ice, INTSTAT));
462 //printk("pbkstatus = 0x%x\n", pbkstatus);
463 for (idx = 0; idx < 6; idx++) {
464 if ((pbkstatus & (3 << (idx * 2))) == 0)
466 if ((substream = ice->playback_con_substream_ds[idx]) != NULL)
467 snd_pcm_period_elapsed(substream);
468 outw(3 << (idx * 2), ICEDS(ice, INTSTAT));
470 outb(ICE1712_IRQ_PBKDS, ICEREG(ice, IRQSTAT));
472 if (status & ICE1712_IRQ_CONCAP) {
473 if (ice->capture_con_substream)
474 snd_pcm_period_elapsed(ice->capture_con_substream);
475 outb(ICE1712_IRQ_CONCAP, ICEREG(ice, IRQSTAT));
477 if (status & ICE1712_IRQ_CONPBK) {
478 if (ice->playback_con_substream)
479 snd_pcm_period_elapsed(ice->playback_con_substream);
480 outb(ICE1712_IRQ_CONPBK, ICEREG(ice, IRQSTAT));
483 return IRQ_RETVAL(handled);
491 static int snd_ice1712_hw_params(snd_pcm_substream_t * substream,
492 snd_pcm_hw_params_t * hw_params)
494 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
497 static int snd_ice1712_hw_free(snd_pcm_substream_t * substream)
499 return snd_pcm_lib_free_pages(substream);
503 * PCM part - consumer I/O
506 static int snd_ice1712_playback_trigger(snd_pcm_substream_t * substream,
509 ice1712_t *ice = snd_pcm_substream_chip(substream);
513 spin_lock(&ice->reg_lock);
514 tmp = snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL);
515 if (cmd == SNDRV_PCM_TRIGGER_START) {
517 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
519 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
521 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
526 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
527 spin_unlock(&ice->reg_lock);
531 static int snd_ice1712_playback_ds_trigger(snd_pcm_substream_t * substream,
534 ice1712_t *ice = snd_pcm_substream_chip(substream);
538 spin_lock(&ice->reg_lock);
539 tmp = snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL);
540 if (cmd == SNDRV_PCM_TRIGGER_START) {
542 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
544 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
546 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
551 snd_ice1712_ds_write(ice, substream->number * 2, ICE1712_DSC_CONTROL, tmp);
552 spin_unlock(&ice->reg_lock);
556 static int snd_ice1712_capture_trigger(snd_pcm_substream_t * substream,
559 ice1712_t *ice = snd_pcm_substream_chip(substream);
563 spin_lock(&ice->reg_lock);
564 tmp = snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL);
565 if (cmd == SNDRV_PCM_TRIGGER_START) {
567 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
572 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
573 spin_unlock(&ice->reg_lock);
577 static int snd_ice1712_playback_prepare(snd_pcm_substream_t * substream)
579 ice1712_t *ice = snd_pcm_substream_chip(substream);
580 snd_pcm_runtime_t *runtime = substream->runtime;
581 u32 period_size, buf_size, rate, tmp;
583 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
584 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
586 if (snd_pcm_format_width(runtime->format) == 16)
588 if (runtime->channels == 2)
590 rate = (runtime->rate * 8192) / 375;
591 if (rate > 0x000fffff)
593 spin_lock(&ice->reg_lock);
594 outb(0, ice->ddma_port + 15);
595 outb(ICE1712_DMA_MODE_WRITE | ICE1712_DMA_AUTOINIT, ice->ddma_port + 0x0b);
596 outl(runtime->dma_addr, ice->ddma_port + 0);
597 outw(buf_size, ice->ddma_port + 4);
598 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_LO, rate & 0xff);
599 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_MID, (rate >> 8) & 0xff);
600 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_HI, (rate >> 16) & 0xff);
601 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
602 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_LO, period_size & 0xff);
603 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_HI, period_size >> 8);
604 snd_ice1712_write(ice, ICE1712_IREG_PBK_LEFT, 0);
605 snd_ice1712_write(ice, ICE1712_IREG_PBK_RIGHT, 0);
606 spin_unlock(&ice->reg_lock);
610 static int snd_ice1712_playback_ds_prepare(snd_pcm_substream_t * substream)
612 ice1712_t *ice = snd_pcm_substream_chip(substream);
613 snd_pcm_runtime_t *runtime = substream->runtime;
614 u32 period_size, buf_size, rate, tmp, chn;
616 period_size = snd_pcm_lib_period_bytes(substream) - 1;
617 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
619 if (snd_pcm_format_width(runtime->format) == 16)
621 if (runtime->channels == 2)
623 rate = (runtime->rate * 8192) / 375;
624 if (rate > 0x000fffff)
626 ice->playback_con_active_buf[substream->number] = 0;
627 ice->playback_con_virt_addr[substream->number] = runtime->dma_addr;
628 chn = substream->number * 2;
629 spin_lock(&ice->reg_lock);
630 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR0, runtime->dma_addr);
631 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT0, period_size);
632 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR1, runtime->dma_addr + (runtime->periods > 1 ? period_size + 1 : 0));
633 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT1, period_size);
634 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_RATE, rate);
635 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_VOLUME, 0);
636 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_CONTROL, tmp);
637 if (runtime->channels == 2) {
638 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_RATE, rate);
639 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_VOLUME, 0);
641 spin_unlock(&ice->reg_lock);
645 static int snd_ice1712_capture_prepare(snd_pcm_substream_t * substream)
647 ice1712_t *ice = snd_pcm_substream_chip(substream);
648 snd_pcm_runtime_t *runtime = substream->runtime;
649 u32 period_size, buf_size;
652 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
653 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
655 if (snd_pcm_format_width(runtime->format) == 16)
657 if (runtime->channels == 2)
659 spin_lock(&ice->reg_lock);
660 outl(ice->capture_con_virt_addr = runtime->dma_addr, ICEREG(ice, CONCAP_ADDR));
661 outw(buf_size, ICEREG(ice, CONCAP_COUNT));
662 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_HI, period_size >> 8);
663 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_LO, period_size & 0xff);
664 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
665 spin_unlock(&ice->reg_lock);
666 snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
670 static snd_pcm_uframes_t snd_ice1712_playback_pointer(snd_pcm_substream_t * substream)
672 ice1712_t *ice = snd_pcm_substream_chip(substream);
673 snd_pcm_runtime_t *runtime = substream->runtime;
676 if (!(snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL) & 1))
678 ptr = runtime->buffer_size - inw(ice->ddma_port + 4);
679 if (ptr == runtime->buffer_size)
681 return bytes_to_frames(substream->runtime, ptr);
684 static snd_pcm_uframes_t snd_ice1712_playback_ds_pointer(snd_pcm_substream_t * substream)
686 ice1712_t *ice = snd_pcm_substream_chip(substream);
690 if (!(snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL) & 1))
692 if (ice->playback_con_active_buf[substream->number])
693 addr = ICE1712_DSC_ADDR1;
695 addr = ICE1712_DSC_ADDR0;
696 ptr = snd_ice1712_ds_read(ice, substream->number * 2, addr) -
697 ice->playback_con_virt_addr[substream->number];
698 if (ptr == substream->runtime->buffer_size)
700 return bytes_to_frames(substream->runtime, ptr);
703 static snd_pcm_uframes_t snd_ice1712_capture_pointer(snd_pcm_substream_t * substream)
705 ice1712_t *ice = snd_pcm_substream_chip(substream);
708 if (!(snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL) & 1))
710 ptr = inl(ICEREG(ice, CONCAP_ADDR)) - ice->capture_con_virt_addr;
711 if (ptr == substream->runtime->buffer_size)
713 return bytes_to_frames(substream->runtime, ptr);
716 static snd_pcm_hardware_t snd_ice1712_playback =
718 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
719 SNDRV_PCM_INFO_BLOCK_TRANSFER |
720 SNDRV_PCM_INFO_MMAP_VALID |
721 SNDRV_PCM_INFO_PAUSE),
722 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
723 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
728 .buffer_bytes_max = (64*1024),
729 .period_bytes_min = 64,
730 .period_bytes_max = (64*1024),
736 static snd_pcm_hardware_t snd_ice1712_playback_ds =
738 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
739 SNDRV_PCM_INFO_BLOCK_TRANSFER |
740 SNDRV_PCM_INFO_MMAP_VALID |
741 SNDRV_PCM_INFO_PAUSE),
742 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
743 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
748 .buffer_bytes_max = (128*1024),
749 .period_bytes_min = 64,
750 .period_bytes_max = (128*1024),
756 static snd_pcm_hardware_t snd_ice1712_capture =
758 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
759 SNDRV_PCM_INFO_BLOCK_TRANSFER |
760 SNDRV_PCM_INFO_MMAP_VALID),
761 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
762 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
767 .buffer_bytes_max = (64*1024),
768 .period_bytes_min = 64,
769 .period_bytes_max = (64*1024),
775 static int snd_ice1712_playback_open(snd_pcm_substream_t * substream)
777 snd_pcm_runtime_t *runtime = substream->runtime;
778 ice1712_t *ice = snd_pcm_substream_chip(substream);
780 ice->playback_con_substream = substream;
781 runtime->hw = snd_ice1712_playback;
785 static int snd_ice1712_playback_ds_open(snd_pcm_substream_t * substream)
787 snd_pcm_runtime_t *runtime = substream->runtime;
788 ice1712_t *ice = snd_pcm_substream_chip(substream);
791 ice->playback_con_substream_ds[substream->number] = substream;
792 runtime->hw = snd_ice1712_playback_ds;
793 spin_lock_irq(&ice->reg_lock);
794 tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2));
795 outw(tmp, ICEDS(ice, INTMASK));
796 spin_unlock_irq(&ice->reg_lock);
800 static int snd_ice1712_capture_open(snd_pcm_substream_t * substream)
802 snd_pcm_runtime_t *runtime = substream->runtime;
803 ice1712_t *ice = snd_pcm_substream_chip(substream);
805 ice->capture_con_substream = substream;
806 runtime->hw = snd_ice1712_capture;
807 runtime->hw.rates = ice->ac97->rates[AC97_RATES_ADC];
808 if (!(runtime->hw.rates & SNDRV_PCM_RATE_8000))
809 runtime->hw.rate_min = 48000;
813 static int snd_ice1712_playback_close(snd_pcm_substream_t * substream)
815 ice1712_t *ice = snd_pcm_substream_chip(substream);
817 ice->playback_con_substream = NULL;
821 static int snd_ice1712_playback_ds_close(snd_pcm_substream_t * substream)
823 ice1712_t *ice = snd_pcm_substream_chip(substream);
826 spin_lock_irq(&ice->reg_lock);
827 tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2));
828 outw(tmp, ICEDS(ice, INTMASK));
829 spin_unlock_irq(&ice->reg_lock);
830 ice->playback_con_substream_ds[substream->number] = NULL;
834 static int snd_ice1712_capture_close(snd_pcm_substream_t * substream)
836 ice1712_t *ice = snd_pcm_substream_chip(substream);
838 ice->capture_con_substream = NULL;
842 static snd_pcm_ops_t snd_ice1712_playback_ops = {
843 .open = snd_ice1712_playback_open,
844 .close = snd_ice1712_playback_close,
845 .ioctl = snd_pcm_lib_ioctl,
846 .hw_params = snd_ice1712_hw_params,
847 .hw_free = snd_ice1712_hw_free,
848 .prepare = snd_ice1712_playback_prepare,
849 .trigger = snd_ice1712_playback_trigger,
850 .pointer = snd_ice1712_playback_pointer,
853 static snd_pcm_ops_t snd_ice1712_playback_ds_ops = {
854 .open = snd_ice1712_playback_ds_open,
855 .close = snd_ice1712_playback_ds_close,
856 .ioctl = snd_pcm_lib_ioctl,
857 .hw_params = snd_ice1712_hw_params,
858 .hw_free = snd_ice1712_hw_free,
859 .prepare = snd_ice1712_playback_ds_prepare,
860 .trigger = snd_ice1712_playback_ds_trigger,
861 .pointer = snd_ice1712_playback_ds_pointer,
864 static snd_pcm_ops_t snd_ice1712_capture_ops = {
865 .open = snd_ice1712_capture_open,
866 .close = snd_ice1712_capture_close,
867 .ioctl = snd_pcm_lib_ioctl,
868 .hw_params = snd_ice1712_hw_params,
869 .hw_free = snd_ice1712_hw_free,
870 .prepare = snd_ice1712_capture_prepare,
871 .trigger = snd_ice1712_capture_trigger,
872 .pointer = snd_ice1712_capture_pointer,
875 static void snd_ice1712_pcm_free(snd_pcm_t *pcm)
877 ice1712_t *ice = snd_magic_cast(ice1712_t, pcm->private_data, return);
879 snd_pcm_lib_preallocate_free_for_all(pcm);
882 static int __devinit snd_ice1712_pcm(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
889 err = snd_pcm_new(ice->card, "ICE1712 consumer", device, 1, 1, &pcm);
893 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ops);
894 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_ops);
896 pcm->private_data = ice;
897 pcm->private_free = snd_ice1712_pcm_free;
899 strcpy(pcm->name, "ICE1712 consumer");
902 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
903 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
908 printk(KERN_WARNING "Consumer PCM code does not work well at the moment --jk\n");
913 static void snd_ice1712_pcm_free_ds(snd_pcm_t *pcm)
915 ice1712_t *ice = snd_magic_cast(ice1712_t, pcm->private_data, return);
917 snd_pcm_lib_preallocate_free_for_all(pcm);
920 static int __devinit snd_ice1712_pcm_ds(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
927 err = snd_pcm_new(ice->card, "ICE1712 consumer (DS)", device, 6, 0, &pcm);
931 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ds_ops);
933 pcm->private_data = ice;
934 pcm->private_free = snd_ice1712_pcm_free_ds;
936 strcpy(pcm->name, "ICE1712 consumer (DS)");
939 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
940 snd_dma_pci_data(ice->pci), 64*1024, 128*1024);
949 * PCM code - professional part (multitrack)
952 static unsigned int rates[] = { 8000, 9600, 11025, 12000, 16000, 22050, 24000,
953 32000, 44100, 48000, 64000, 88200, 96000 };
955 #define RATES sizeof(rates) / sizeof(rates[0])
957 static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
963 static int snd_ice1712_pro_trigger(snd_pcm_substream_t *substream,
966 ice1712_t *ice = snd_pcm_substream_chip(substream);
968 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
969 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
973 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
975 what = ICE1712_PLAYBACK_PAUSE;
976 snd_pcm_trigger_done(substream, substream);
977 spin_lock(&ice->reg_lock);
978 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
979 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
983 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
984 spin_unlock(&ice->reg_lock);
987 case SNDRV_PCM_TRIGGER_START:
988 case SNDRV_PCM_TRIGGER_STOP:
990 unsigned int what = 0;
992 struct list_head *pos;
993 snd_pcm_substream_t *s;
995 snd_pcm_group_for_each(pos, substream) {
996 s = snd_pcm_group_substream_entry(pos);
997 if (s == ice->playback_pro_substream) {
998 what |= ICE1712_PLAYBACK_START;
999 snd_pcm_trigger_done(s, substream);
1000 } else if (s == ice->capture_pro_substream) {
1001 what |= ICE1712_CAPTURE_START_SHADOW;
1002 snd_pcm_trigger_done(s, substream);
1005 spin_lock(&ice->reg_lock);
1006 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
1007 if (cmd == SNDRV_PCM_TRIGGER_START)
1011 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
1012 spin_unlock(&ice->reg_lock);
1023 static void snd_ice1712_set_pro_rate(ice1712_t *ice, unsigned int rate, int force)
1025 unsigned long flags;
1029 spin_lock_irqsave(&ice->reg_lock, flags);
1030 if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
1031 ICE1712_PLAYBACK_PAUSE|
1032 ICE1712_PLAYBACK_START)) {
1033 spin_unlock_irqrestore(&ice->reg_lock, flags);
1036 if (!force && is_pro_rate_locked(ice)) {
1037 spin_unlock_irqrestore(&ice->reg_lock, flags);
1042 case 8000: val = 6; break;
1043 case 9600: val = 3; break;
1044 case 11025: val = 10; break;
1045 case 12000: val = 2; break;
1046 case 16000: val = 5; break;
1047 case 22050: val = 9; break;
1048 case 24000: val = 1; break;
1049 case 32000: val = 4; break;
1050 case 44100: val = 8; break;
1051 case 48000: val = 0; break;
1052 case 64000: val = 15; break;
1053 case 88200: val = 11; break;
1054 case 96000: val = 7; break;
1061 outb(val, ICEMT(ice, RATE));
1063 spin_unlock_irqrestore(&ice->reg_lock, flags);
1065 if (ice->gpio.set_pro_rate)
1066 ice->gpio.set_pro_rate(ice, rate);
1067 for (i = 0; i < ice->akm_codecs; i++) {
1068 if (ice->akm[i].ops.set_rate_val)
1069 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
1071 if (ice->spdif.ops.setup_rate)
1072 ice->spdif.ops.setup_rate(ice, rate);
1075 static int snd_ice1712_playback_pro_prepare(snd_pcm_substream_t * substream)
1077 ice1712_t *ice = snd_pcm_substream_chip(substream);
1079 ice->playback_pro_size = snd_pcm_lib_buffer_bytes(substream);
1080 spin_lock(&ice->reg_lock);
1081 outl(substream->runtime->dma_addr, ICEMT(ice, PLAYBACK_ADDR));
1082 outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));
1083 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT));
1084 spin_unlock(&ice->reg_lock);
1089 static int snd_ice1712_playback_pro_hw_params(snd_pcm_substream_t * substream,
1090 snd_pcm_hw_params_t * hw_params)
1092 ice1712_t *ice = snd_pcm_substream_chip(substream);
1094 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1095 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1098 static int snd_ice1712_capture_pro_prepare(snd_pcm_substream_t * substream)
1100 ice1712_t *ice = snd_pcm_substream_chip(substream);
1102 ice->capture_pro_size = snd_pcm_lib_buffer_bytes(substream);
1103 spin_lock(&ice->reg_lock);
1104 outl(substream->runtime->dma_addr, ICEMT(ice, CAPTURE_ADDR));
1105 outw((ice->capture_pro_size >> 2) - 1, ICEMT(ice, CAPTURE_SIZE));
1106 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, CAPTURE_COUNT));
1107 spin_unlock(&ice->reg_lock);
1111 static int snd_ice1712_capture_pro_hw_params(snd_pcm_substream_t * substream,
1112 snd_pcm_hw_params_t * hw_params)
1114 ice1712_t *ice = snd_pcm_substream_chip(substream);
1116 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1117 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1120 static snd_pcm_uframes_t snd_ice1712_playback_pro_pointer(snd_pcm_substream_t * substream)
1122 ice1712_t *ice = snd_pcm_substream_chip(substream);
1125 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_PLAYBACK_START))
1127 ptr = ice->playback_pro_size - (inw(ICEMT(ice, PLAYBACK_SIZE)) << 2);
1128 if (ptr == substream->runtime->buffer_size)
1130 return bytes_to_frames(substream->runtime, ptr);
1133 static snd_pcm_uframes_t snd_ice1712_capture_pro_pointer(snd_pcm_substream_t * substream)
1135 ice1712_t *ice = snd_pcm_substream_chip(substream);
1138 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_CAPTURE_START_SHADOW))
1140 ptr = ice->capture_pro_size - (inw(ICEMT(ice, CAPTURE_SIZE)) << 2);
1141 if (ptr == substream->runtime->buffer_size)
1143 return bytes_to_frames(substream->runtime, ptr);
1146 static snd_pcm_hardware_t snd_ice1712_playback_pro =
1148 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1149 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1150 SNDRV_PCM_INFO_MMAP_VALID |
1151 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1152 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1153 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1158 .buffer_bytes_max = (256*1024),
1159 .period_bytes_min = 10 * 4 * 2,
1160 .period_bytes_max = 131040,
1162 .periods_max = 1024,
1166 static snd_pcm_hardware_t snd_ice1712_capture_pro =
1168 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1169 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1170 SNDRV_PCM_INFO_MMAP_VALID |
1171 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1172 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1173 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1178 .buffer_bytes_max = (256*1024),
1179 .period_bytes_min = 12 * 4 * 2,
1180 .period_bytes_max = 131040,
1182 .periods_max = 1024,
1186 static int snd_ice1712_playback_pro_open(snd_pcm_substream_t * substream)
1188 snd_pcm_runtime_t *runtime = substream->runtime;
1189 ice1712_t *ice = snd_pcm_substream_chip(substream);
1191 ice->playback_pro_substream = substream;
1192 runtime->hw = snd_ice1712_playback_pro;
1193 snd_pcm_set_sync(substream);
1194 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1195 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1197 if (ice->spdif.ops.open)
1198 ice->spdif.ops.open(ice, substream);
1203 static int snd_ice1712_capture_pro_open(snd_pcm_substream_t * substream)
1205 ice1712_t *ice = snd_pcm_substream_chip(substream);
1206 snd_pcm_runtime_t *runtime = substream->runtime;
1208 ice->capture_pro_substream = substream;
1209 runtime->hw = snd_ice1712_capture_pro;
1210 snd_pcm_set_sync(substream);
1211 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1212 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1216 static int snd_ice1712_playback_pro_close(snd_pcm_substream_t * substream)
1218 ice1712_t *ice = snd_pcm_substream_chip(substream);
1221 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1222 ice->playback_pro_substream = NULL;
1223 if (ice->spdif.ops.close)
1224 ice->spdif.ops.close(ice, substream);
1229 static int snd_ice1712_capture_pro_close(snd_pcm_substream_t * substream)
1231 ice1712_t *ice = snd_pcm_substream_chip(substream);
1234 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1235 ice->capture_pro_substream = NULL;
1239 static void snd_ice1712_pcm_profi_free(snd_pcm_t *pcm)
1241 ice1712_t *ice = snd_magic_cast(ice1712_t, pcm->private_data, return);
1242 ice->pcm_pro = NULL;
1243 snd_pcm_lib_preallocate_free_for_all(pcm);
1246 static snd_pcm_ops_t snd_ice1712_playback_pro_ops = {
1247 .open = snd_ice1712_playback_pro_open,
1248 .close = snd_ice1712_playback_pro_close,
1249 .ioctl = snd_pcm_lib_ioctl,
1250 .hw_params = snd_ice1712_playback_pro_hw_params,
1251 .hw_free = snd_ice1712_hw_free,
1252 .prepare = snd_ice1712_playback_pro_prepare,
1253 .trigger = snd_ice1712_pro_trigger,
1254 .pointer = snd_ice1712_playback_pro_pointer,
1257 static snd_pcm_ops_t snd_ice1712_capture_pro_ops = {
1258 .open = snd_ice1712_capture_pro_open,
1259 .close = snd_ice1712_capture_pro_close,
1260 .ioctl = snd_pcm_lib_ioctl,
1261 .hw_params = snd_ice1712_capture_pro_hw_params,
1262 .hw_free = snd_ice1712_hw_free,
1263 .prepare = snd_ice1712_capture_pro_prepare,
1264 .trigger = snd_ice1712_pro_trigger,
1265 .pointer = snd_ice1712_capture_pro_pointer,
1268 static int __devinit snd_ice1712_pcm_profi(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
1275 err = snd_pcm_new(ice->card, "ICE1712 multi", device, 1, 1, &pcm);
1279 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_pro_ops);
1280 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_pro_ops);
1282 pcm->private_data = ice;
1283 pcm->private_free = snd_ice1712_pcm_profi_free;
1284 pcm->info_flags = 0;
1285 strcpy(pcm->name, "ICE1712 multi");
1287 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1288 snd_dma_pci_data(ice->pci), 256*1024, 256*1024);
1295 /* assign channels to iec958 */
1296 err = snd_cs8427_iec958_build(ice->cs8427,
1297 pcm->streams[0].substream,
1298 pcm->streams[1].substream);
1303 if ((err = snd_ice1712_build_pro_mixer(ice)) < 0)
1312 static void snd_ice1712_update_volume(ice1712_t *ice, int index)
1314 unsigned int vol = ice->pro_volumes[index];
1315 unsigned short val = 0;
1317 val |= (vol & 0x8000) == 0 ? (96 - (vol & 0x7f)) : 0x7f;
1318 val |= ((vol & 0x80000000) == 0 ? (96 - ((vol >> 16) & 0x7f)) : 0x7f) << 8;
1319 outb(index, ICEMT(ice, MONITOR_INDEX));
1320 outw(val, ICEMT(ice, MONITOR_VOLUME));
1323 static int snd_ice1712_pro_mixer_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1325 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1327 uinfo->value.integer.min = 0;
1328 uinfo->value.integer.max = 1;
1332 static int snd_ice1712_pro_mixer_switch_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1334 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1335 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1337 spin_lock_irq(&ice->reg_lock);
1338 ucontrol->value.integer.value[0] = !((ice->pro_volumes[index] >> 15) & 1);
1339 ucontrol->value.integer.value[1] = !((ice->pro_volumes[index] >> 31) & 1);
1340 spin_unlock_irq(&ice->reg_lock);
1344 static int snd_ice1712_pro_mixer_switch_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1346 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1347 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1348 unsigned int nval, change;
1350 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
1351 (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
1352 spin_lock_irq(&ice->reg_lock);
1353 nval |= ice->pro_volumes[index] & ~0x80008000;
1354 change = nval != ice->pro_volumes[index];
1355 ice->pro_volumes[index] = nval;
1356 snd_ice1712_update_volume(ice, index);
1357 spin_unlock_irq(&ice->reg_lock);
1361 static int snd_ice1712_pro_mixer_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1363 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1365 uinfo->value.integer.min = 0;
1366 uinfo->value.integer.max = 96;
1370 static int snd_ice1712_pro_mixer_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1372 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1373 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1375 spin_lock_irq(&ice->reg_lock);
1376 ucontrol->value.integer.value[0] = (ice->pro_volumes[index] >> 0) & 127;
1377 ucontrol->value.integer.value[1] = (ice->pro_volumes[index] >> 16) & 127;
1378 spin_unlock_irq(&ice->reg_lock);
1382 static int snd_ice1712_pro_mixer_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1384 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1385 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1386 unsigned int nval, change;
1388 nval = (ucontrol->value.integer.value[0] & 127) |
1389 ((ucontrol->value.integer.value[1] & 127) << 16);
1390 spin_lock_irq(&ice->reg_lock);
1391 nval |= ice->pro_volumes[index] & ~0x007f007f;
1392 change = nval != ice->pro_volumes[index];
1393 ice->pro_volumes[index] = nval;
1394 snd_ice1712_update_volume(ice, index);
1395 spin_unlock_irq(&ice->reg_lock);
1400 static snd_kcontrol_new_t snd_ice1712_multi_playback_ctrls[] __devinitdata = {
1402 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1403 .name = "Multi Playback 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,
1411 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1412 .name = "Multi Playback Volume",
1413 .info = snd_ice1712_pro_mixer_volume_info,
1414 .get = snd_ice1712_pro_mixer_volume_get,
1415 .put = snd_ice1712_pro_mixer_volume_put,
1421 static snd_kcontrol_new_t snd_ice1712_multi_capture_analog_switch __devinitdata = {
1422 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1423 .name = "H/W Multi Capture Switch",
1424 .info = snd_ice1712_pro_mixer_switch_info,
1425 .get = snd_ice1712_pro_mixer_switch_get,
1426 .put = snd_ice1712_pro_mixer_switch_put,
1427 .private_value = 10,
1430 static snd_kcontrol_new_t snd_ice1712_multi_capture_spdif_switch __devinitdata = {
1431 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1432 .name = "IEC958 Multi Capture Switch",
1433 .info = snd_ice1712_pro_mixer_switch_info,
1434 .get = snd_ice1712_pro_mixer_switch_get,
1435 .put = snd_ice1712_pro_mixer_switch_put,
1436 .private_value = 18,
1440 static snd_kcontrol_new_t snd_ice1712_multi_capture_analog_volume __devinitdata = {
1441 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1442 .name = "H/W Multi Capture Volume",
1443 .info = snd_ice1712_pro_mixer_volume_info,
1444 .get = snd_ice1712_pro_mixer_volume_get,
1445 .put = snd_ice1712_pro_mixer_volume_put,
1446 .private_value = 10,
1449 static snd_kcontrol_new_t snd_ice1712_multi_capture_spdif_volume __devinitdata = {
1450 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1451 .name = "IEC958 Multi Capture Volume",
1452 .info = snd_ice1712_pro_mixer_volume_info,
1453 .get = snd_ice1712_pro_mixer_volume_get,
1454 .put = snd_ice1712_pro_mixer_volume_put,
1455 .private_value = 18,
1459 static int __devinit snd_ice1712_build_pro_mixer(ice1712_t *ice)
1461 snd_card_t * card = ice->card;
1465 /* multi-channel mixer */
1466 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_multi_playback_ctrls); idx++) {
1467 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_playback_ctrls[idx], ice));
1472 if (ice->num_total_adcs > 0) {
1473 snd_kcontrol_new_t tmp = snd_ice1712_multi_capture_analog_switch;
1474 tmp.count = ice->num_total_adcs;
1475 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1480 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_switch, ice));
1484 if (ice->num_total_adcs > 0) {
1485 snd_kcontrol_new_t tmp = snd_ice1712_multi_capture_analog_volume;
1486 tmp.count = ice->num_total_adcs;
1487 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1492 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_volume, ice));
1496 /* initialize volumes */
1497 for (idx = 0; idx < 10; idx++) {
1498 ice->pro_volumes[idx] = 0x80008000; /* mute */
1499 snd_ice1712_update_volume(ice, idx);
1501 for (idx = 10; idx < 10 + ice->num_total_adcs; idx++) {
1502 ice->pro_volumes[idx] = 0x80008000; /* mute */
1503 snd_ice1712_update_volume(ice, idx);
1505 for (idx = 18; idx < 20; idx++) {
1506 ice->pro_volumes[idx] = 0x80008000; /* mute */
1507 snd_ice1712_update_volume(ice, idx);
1512 static void snd_ice1712_mixer_free_ac97(ac97_t *ac97)
1514 ice1712_t *ice = snd_magic_cast(ice1712_t, ac97->private_data, return);
1518 static int __devinit snd_ice1712_ac97_mixer(ice1712_t * ice)
1522 ac97_bus_t bus, *pbus;
1524 if (ice_has_con_ac97(ice)) {
1525 memset(&bus, 0, sizeof(bus));
1526 bus.write = snd_ice1712_ac97_write;
1527 bus.read = snd_ice1712_ac97_read;
1528 if ((err = snd_ac97_bus(ice->card, &bus, &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 ac97 for consumer, skipped\n");
1536 if ((err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice))) < 0)
1542 if (! (ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) {
1543 memset(&bus, 0, sizeof(bus));
1544 bus.write = snd_ice1712_pro_ac97_write;
1545 bus.read = snd_ice1712_pro_ac97_read;
1546 if ((err = snd_ac97_bus(ice->card, &bus, &pbus)) < 0)
1548 memset(&ac97, 0, sizeof(ac97));
1549 ac97.private_data = ice;
1550 ac97.private_free = snd_ice1712_mixer_free_ac97;
1551 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1552 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1556 /* I2S mixer only */
1557 strcat(ice->card->mixername, "ICE1712 - multitrack");
1565 static inline unsigned int eeprom_double(ice1712_t *ice, int idx)
1567 return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8);
1570 static void snd_ice1712_proc_read(snd_info_entry_t *entry,
1571 snd_info_buffer_t * buffer)
1573 ice1712_t *ice = snd_magic_cast(ice1712_t, entry->private_data, return);
1576 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1577 snd_iprintf(buffer, "EEPROM:\n");
1579 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1580 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1581 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1582 snd_iprintf(buffer, " Codec : 0x%x\n", ice->eeprom.data[ICE_EEP1_CODEC]);
1583 snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP1_ACLINK]);
1584 snd_iprintf(buffer, " I2S ID : 0x%x\n", ice->eeprom.data[ICE_EEP1_I2SID]);
1585 snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP1_SPDIF]);
1586 snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
1587 snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
1588 snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
1589 snd_iprintf(buffer, " AC'97 main : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_MAIN_LO));
1590 snd_iprintf(buffer, " AC'97 pcm : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_PCM_LO));
1591 snd_iprintf(buffer, " AC'97 record : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_REC_LO));
1592 snd_iprintf(buffer, " AC'97 record src : 0x%x\n", ice->eeprom.data[ICE_EEP1_AC97_RECSRC]);
1593 for (idx = 0; idx < 4; idx++)
1594 snd_iprintf(buffer, " DAC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_DAC_ID + idx]);
1595 for (idx = 0; idx < 4; idx++)
1596 snd_iprintf(buffer, " ADC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_ADC_ID + idx]);
1597 for (idx = 0x1c; idx < ice->eeprom.size; idx++)
1598 snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
1600 snd_iprintf(buffer, "\nRegisters:\n");
1601 snd_iprintf(buffer, " PSDOUT03 : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_PSDOUT03)));
1602 snd_iprintf(buffer, " CAPTURE : 0x%08x\n", inl(ICEMT(ice, ROUTE_CAPTURE)));
1603 snd_iprintf(buffer, " SPDOUT : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT)));
1604 snd_iprintf(buffer, " RATE : 0x%02x\n", (unsigned)inb(ICEMT(ice, RATE)));
1607 static void __devinit snd_ice1712_proc_init(ice1712_t * ice)
1609 snd_info_entry_t *entry;
1611 if (! snd_card_proc_new(ice->card, "ice1712", &entry))
1612 snd_info_set_text_ops(entry, ice, 1024, snd_ice1712_proc_read);
1619 static int snd_ice1712_eeprom_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1621 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1622 uinfo->count = sizeof(ice1712_eeprom_t);
1626 static int snd_ice1712_eeprom_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1628 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1630 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1634 static snd_kcontrol_new_t snd_ice1712_eeprom __devinitdata = {
1635 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1636 .name = "ICE1712 EEPROM",
1637 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1638 .info = snd_ice1712_eeprom_info,
1639 .get = snd_ice1712_eeprom_get
1644 static int snd_ice1712_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1646 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1651 static int snd_ice1712_spdif_default_get(snd_kcontrol_t * kcontrol,
1652 snd_ctl_elem_value_t * ucontrol)
1654 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1655 if (ice->spdif.ops.default_get)
1656 ice->spdif.ops.default_get(ice, ucontrol);
1660 static int snd_ice1712_spdif_default_put(snd_kcontrol_t * kcontrol,
1661 snd_ctl_elem_value_t * ucontrol)
1663 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1664 if (ice->spdif.ops.default_put)
1665 return ice->spdif.ops.default_put(ice, ucontrol);
1669 static snd_kcontrol_new_t snd_ice1712_spdif_default __devinitdata =
1671 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1672 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1673 .info = snd_ice1712_spdif_info,
1674 .get = snd_ice1712_spdif_default_get,
1675 .put = snd_ice1712_spdif_default_put
1678 static int snd_ice1712_spdif_maskc_get(snd_kcontrol_t * kcontrol,
1679 snd_ctl_elem_value_t * ucontrol)
1681 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1682 if (ice->spdif.ops.default_get) {
1683 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1684 IEC958_AES0_PROFESSIONAL |
1685 IEC958_AES0_CON_NOT_COPYRIGHT |
1686 IEC958_AES0_CON_EMPHASIS;
1687 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1688 IEC958_AES1_CON_CATEGORY;
1689 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1691 ucontrol->value.iec958.status[0] = 0xff;
1692 ucontrol->value.iec958.status[1] = 0xff;
1693 ucontrol->value.iec958.status[2] = 0xff;
1694 ucontrol->value.iec958.status[3] = 0xff;
1695 ucontrol->value.iec958.status[4] = 0xff;
1700 static int snd_ice1712_spdif_maskp_get(snd_kcontrol_t * kcontrol,
1701 snd_ctl_elem_value_t * ucontrol)
1703 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1704 if (ice->spdif.ops.default_get) {
1705 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1706 IEC958_AES0_PROFESSIONAL |
1707 IEC958_AES0_PRO_FS |
1708 IEC958_AES0_PRO_EMPHASIS;
1709 ucontrol->value.iec958.status[1] = IEC958_AES1_PRO_MODE;
1711 ucontrol->value.iec958.status[0] = 0xff;
1712 ucontrol->value.iec958.status[1] = 0xff;
1713 ucontrol->value.iec958.status[2] = 0xff;
1714 ucontrol->value.iec958.status[3] = 0xff;
1715 ucontrol->value.iec958.status[4] = 0xff;
1720 static snd_kcontrol_new_t snd_ice1712_spdif_maskc __devinitdata =
1722 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1723 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1724 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1725 .info = snd_ice1712_spdif_info,
1726 .get = snd_ice1712_spdif_maskc_get,
1729 static snd_kcontrol_new_t snd_ice1712_spdif_maskp __devinitdata =
1731 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1732 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1733 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1734 .info = snd_ice1712_spdif_info,
1735 .get = snd_ice1712_spdif_maskp_get,
1738 static int snd_ice1712_spdif_stream_get(snd_kcontrol_t * kcontrol,
1739 snd_ctl_elem_value_t * ucontrol)
1741 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1742 if (ice->spdif.ops.stream_get)
1743 ice->spdif.ops.stream_get(ice, ucontrol);
1747 static int snd_ice1712_spdif_stream_put(snd_kcontrol_t * kcontrol,
1748 snd_ctl_elem_value_t * ucontrol)
1750 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1751 if (ice->spdif.ops.stream_put)
1752 return ice->spdif.ops.stream_put(ice, ucontrol);
1756 static snd_kcontrol_new_t snd_ice1712_spdif_stream __devinitdata =
1758 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1759 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1760 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
1761 .info = snd_ice1712_spdif_info,
1762 .get = snd_ice1712_spdif_stream_get,
1763 .put = snd_ice1712_spdif_stream_put
1766 int snd_ice1712_gpio_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1768 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1770 uinfo->value.integer.min = 0;
1771 uinfo->value.integer.max = 1;
1775 int snd_ice1712_gpio_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1777 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1778 unsigned char mask = kcontrol->private_value & 0xff;
1779 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1781 snd_ice1712_save_gpio_status(ice);
1782 ucontrol->value.integer.value[0] = (snd_ice1712_gpio_read(ice) & mask ? 1 : 0) ^ invert;
1783 snd_ice1712_restore_gpio_status(ice);
1787 int snd_ice1712_gpio_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1789 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1790 unsigned char mask = kcontrol->private_value & 0xff;
1791 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1792 unsigned int val, nval;
1794 if (kcontrol->private_value & (1 << 31))
1796 nval = (ucontrol->value.integer.value[0] ? mask : 0) ^ invert;
1797 snd_ice1712_save_gpio_status(ice);
1798 val = snd_ice1712_gpio_read(ice);
1799 nval |= val & ~mask;
1801 snd_ice1712_gpio_write(ice, nval);
1802 snd_ice1712_restore_gpio_status(ice);
1809 static int snd_ice1712_pro_internal_clock_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1811 static char *texts[] = {
1814 "11025", /* 2: 10 */
1822 "64000", /* 10: 15 */
1823 "88200", /* 11: 11 */
1824 "96000", /* 12: 7 */
1825 "IEC958 Input", /* 13: -- */
1827 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1829 uinfo->value.enumerated.items = 14;
1830 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1831 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1832 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1836 static int snd_ice1712_pro_internal_clock_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1838 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1839 static unsigned char xlate[16] = {
1840 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10
1844 spin_lock_irq(&ice->reg_lock);
1845 if (is_spdif_master(ice)) {
1846 ucontrol->value.enumerated.item[0] = 13;
1848 val = xlate[inb(ICEMT(ice, RATE)) & 15];
1853 ucontrol->value.enumerated.item[0] = val;
1855 spin_unlock_irq(&ice->reg_lock);
1859 static int snd_ice1712_pro_internal_clock_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1861 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1862 static unsigned int xrate[13] = {
1863 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1864 32000, 44100, 48000, 64000, 88200, 96000
1869 spin_lock_irq(&ice->reg_lock);
1870 oval = inb(ICEMT(ice, RATE));
1871 if (ucontrol->value.enumerated.item[0] == 13) {
1872 outb(oval | ICE1712_SPDIF_MASTER, ICEMT(ice, RATE));
1874 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1875 spin_unlock_irq(&ice->reg_lock);
1876 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1877 spin_lock_irq(&ice->reg_lock);
1879 change = inb(ICEMT(ice, RATE)) != oval;
1880 spin_unlock_irq(&ice->reg_lock);
1882 if ((oval & ICE1712_SPDIF_MASTER) != (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER)) {
1883 /* change CS8427 clock source too */
1885 snd_ice1712_cs8427_set_input_clock(ice, is_spdif_master(ice));
1887 /* notify ak4524 chip as well */
1888 if (is_spdif_master(ice)) {
1890 for (i = 0; i < ice->akm_codecs; i++) {
1891 if (ice->akm[i].ops.set_rate_val)
1892 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
1900 static snd_kcontrol_new_t snd_ice1712_pro_internal_clock __devinitdata = {
1901 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1902 .name = "Multi Track Internal Clock",
1903 .info = snd_ice1712_pro_internal_clock_info,
1904 .get = snd_ice1712_pro_internal_clock_get,
1905 .put = snd_ice1712_pro_internal_clock_put
1908 static int snd_ice1712_pro_internal_clock_default_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1910 static char *texts[] = {
1913 "11025", /* 2: 10 */
1921 "64000", /* 10: 15 */
1922 "88200", /* 11: 11 */
1923 "96000", /* 12: 7 */
1924 // "IEC958 Input", /* 13: -- */
1926 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1928 uinfo->value.enumerated.items = 13;
1929 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1930 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1931 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1935 static int snd_ice1712_pro_internal_clock_default_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1938 static unsigned int xrate[13] = {
1939 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1940 32000, 44100, 48000, 64000, 88200, 96000
1943 for (val = 0; val < 13; val++) {
1944 if (xrate[val] == PRO_RATE_DEFAULT)
1948 ucontrol->value.enumerated.item[0] = val;
1952 static int snd_ice1712_pro_internal_clock_default_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1954 static unsigned int xrate[13] = {
1955 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1956 32000, 44100, 48000, 64000, 88200, 96000
1961 oval = PRO_RATE_DEFAULT;
1962 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1963 change = PRO_RATE_DEFAULT != oval;
1968 static snd_kcontrol_new_t snd_ice1712_pro_internal_clock_default __devinitdata = {
1969 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1970 .name = "Multi Track Internal Clock Default",
1971 .info = snd_ice1712_pro_internal_clock_default_info,
1972 .get = snd_ice1712_pro_internal_clock_default_get,
1973 .put = snd_ice1712_pro_internal_clock_default_put
1976 static int snd_ice1712_pro_rate_locking_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1978 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1980 uinfo->value.integer.min = 0;
1981 uinfo->value.integer.max = 1;
1985 static int snd_ice1712_pro_rate_locking_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1987 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1991 static int snd_ice1712_pro_rate_locking_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1993 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1994 int change = 0, nval;
1996 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1997 spin_lock_irq(&ice->reg_lock);
1998 change = PRO_RATE_LOCKED != nval;
1999 PRO_RATE_LOCKED = nval;
2000 spin_unlock_irq(&ice->reg_lock);
2004 static snd_kcontrol_new_t snd_ice1712_pro_rate_locking __devinitdata = {
2005 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2006 .name = "Multi Track Rate Locking",
2007 .info = snd_ice1712_pro_rate_locking_info,
2008 .get = snd_ice1712_pro_rate_locking_get,
2009 .put = snd_ice1712_pro_rate_locking_put
2012 static int snd_ice1712_pro_rate_reset_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2014 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2016 uinfo->value.integer.min = 0;
2017 uinfo->value.integer.max = 1;
2021 static int snd_ice1712_pro_rate_reset_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2023 ucontrol->value.integer.value[0] = PRO_RATE_RESET;
2027 static int snd_ice1712_pro_rate_reset_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2029 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2030 int change = 0, nval;
2032 nval = ucontrol->value.integer.value[0] ? 1 : 0;
2033 spin_lock_irq(&ice->reg_lock);
2034 change = PRO_RATE_RESET != nval;
2035 PRO_RATE_RESET = nval;
2036 spin_unlock_irq(&ice->reg_lock);
2040 static snd_kcontrol_new_t snd_ice1712_pro_rate_reset __devinitdata = {
2041 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2042 .name = "Multi Track Rate Reset",
2043 .info = snd_ice1712_pro_rate_reset_info,
2044 .get = snd_ice1712_pro_rate_reset_get,
2045 .put = snd_ice1712_pro_rate_reset_put
2051 static int snd_ice1712_pro_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2053 static char *texts[] = {
2055 "H/W In 0", "H/W In 1", "H/W In 2", "H/W In 3", /* 1-4 */
2056 "H/W In 4", "H/W In 5", "H/W In 6", "H/W In 7", /* 5-8 */
2057 "IEC958 In L", "IEC958 In R", /* 9-10 */
2058 "Digital Mixer", /* 11 - optional */
2061 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2063 uinfo->value.enumerated.items = snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
2064 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2065 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2066 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2070 static int snd_ice1712_pro_route_analog_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
2072 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2073 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2074 unsigned int val, cval;
2076 spin_lock_irq(&ice->reg_lock);
2077 val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2078 cval = inl(ICEMT(ice, ROUTE_CAPTURE));
2079 spin_unlock_irq(&ice->reg_lock);
2081 val >>= ((idx % 2) * 8) + ((idx / 2) * 2);
2083 cval >>= ((idx / 2) * 8) + ((idx % 2) * 4);
2084 if (val == 1 && idx < 2)
2085 ucontrol->value.enumerated.item[0] = 11;
2087 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2089 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2091 ucontrol->value.enumerated.item[0] = 0;
2095 static int snd_ice1712_pro_route_analog_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
2097 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2099 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2100 unsigned int val, old_val, nval;
2103 if (ucontrol->value.enumerated.item[0] >= 11)
2104 nval = idx < 2 ? 1 : 0; /* dig mixer (or pcm) */
2105 else if (ucontrol->value.enumerated.item[0] >= 9)
2106 nval = 3; /* spdif in */
2107 else if (ucontrol->value.enumerated.item[0] >= 1)
2108 nval = 2; /* analog in */
2111 shift = ((idx % 2) * 8) + ((idx / 2) * 2);
2112 spin_lock_irq(&ice->reg_lock);
2113 val = old_val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2114 val &= ~(0x03 << shift);
2115 val |= nval << shift;
2116 change = val != old_val;
2118 outw(val, ICEMT(ice, ROUTE_PSDOUT03));
2119 spin_unlock_irq(&ice->reg_lock);
2120 if (nval < 2) /* dig mixer of pcm */
2123 /* update CAPTURE */
2124 spin_lock_irq(&ice->reg_lock);
2125 val = old_val = inl(ICEMT(ice, ROUTE_CAPTURE));
2126 shift = ((idx / 2) * 8) + ((idx % 2) * 4);
2127 if (nval == 2) { /* analog in */
2128 nval = ucontrol->value.enumerated.item[0] - 1;
2129 val &= ~(0x07 << shift);
2130 val |= nval << shift;
2131 } else { /* spdif in */
2132 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2133 val &= ~(0x08 << shift);
2134 val |= nval << shift;
2136 if (val != old_val) {
2138 outl(val, ICEMT(ice, ROUTE_CAPTURE));
2140 spin_unlock_irq(&ice->reg_lock);
2144 static int snd_ice1712_pro_route_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
2146 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2147 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2148 unsigned int val, cval;
2149 val = inw(ICEMT(ice, ROUTE_SPDOUT));
2150 cval = (val >> (idx * 4 + 8)) & 0x0f;
2151 val = (val >> (idx * 2)) & 0x03;
2153 ucontrol->value.enumerated.item[0] = 11;
2155 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2157 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2159 ucontrol->value.enumerated.item[0] = 0;
2163 static int snd_ice1712_pro_route_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
2165 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2167 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2168 unsigned int val, old_val, nval;
2171 spin_lock_irq(&ice->reg_lock);
2172 val = old_val = inw(ICEMT(ice, ROUTE_SPDOUT));
2173 if (ucontrol->value.enumerated.item[0] >= 11)
2175 else if (ucontrol->value.enumerated.item[0] >= 9)
2177 else if (ucontrol->value.enumerated.item[0] >= 1)
2182 val &= ~(0x03 << shift);
2183 val |= nval << shift;
2184 shift = idx * 4 + 8;
2186 nval = ucontrol->value.enumerated.item[0] - 1;
2187 val &= ~(0x07 << shift);
2188 val |= nval << shift;
2189 } else if (nval == 3) {
2190 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2191 val &= ~(0x08 << shift);
2192 val |= nval << shift;
2194 change = val != old_val;
2196 outw(val, ICEMT(ice, ROUTE_SPDOUT));
2197 spin_unlock_irq(&ice->reg_lock);
2201 static snd_kcontrol_new_t snd_ice1712_mixer_pro_analog_route __devinitdata = {
2202 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2203 .name = "H/W Playback Route",
2204 .info = snd_ice1712_pro_route_info,
2205 .get = snd_ice1712_pro_route_analog_get,
2206 .put = snd_ice1712_pro_route_analog_put,
2209 static snd_kcontrol_new_t snd_ice1712_mixer_pro_spdif_route __devinitdata = {
2210 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2211 .name = "IEC958 Playback Route",
2212 .info = snd_ice1712_pro_route_info,
2213 .get = snd_ice1712_pro_route_spdif_get,
2214 .put = snd_ice1712_pro_route_spdif_put,
2219 static int snd_ice1712_pro_volume_rate_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2221 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2223 uinfo->value.integer.min = 0;
2224 uinfo->value.integer.max = 255;
2228 static int snd_ice1712_pro_volume_rate_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2230 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2232 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE));
2236 static int snd_ice1712_pro_volume_rate_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2238 ice1712_t *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 snd_kcontrol_new_t 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(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2258 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2260 uinfo->value.integer.min = 0;
2261 uinfo->value.integer.max = 255;
2265 static int snd_ice1712_pro_peak_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2267 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2270 spin_lock_irq(&ice->reg_lock);
2271 for (idx = 0; idx < 22; idx++) {
2272 outb(idx, ICEMT(ice, MONITOR_PEAKINDEX));
2273 ucontrol->value.integer.value[idx] = inb(ICEMT(ice, MONITOR_PEAKDATA));
2275 spin_unlock_irq(&ice->reg_lock);
2279 static snd_kcontrol_new_t snd_ice1712_mixer_pro_peak __devinitdata = {
2280 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2281 .name = "Multi Track Peak",
2282 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2283 .info = snd_ice1712_pro_peak_info,
2284 .get = snd_ice1712_pro_peak_get
2292 * list of available boards
2294 static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
2295 snd_ice1712_hoontech_cards,
2296 snd_ice1712_delta_cards,
2297 snd_ice1712_ews_cards,
2301 static unsigned char __devinit snd_ice1712_read_i2c(ice1712_t *ice,
2307 outb(addr, ICEREG(ice, I2C_BYTE_ADDR));
2308 outb(dev & ~ICE1712_I2C_WRITE, ICEREG(ice, I2C_DEV_ADDR));
2309 while (t-- > 0 && (inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_BUSY)) ;
2310 return inb(ICEREG(ice, I2C_DATA));
2313 static int __devinit snd_ice1712_read_eeprom(ice1712_t *ice, const char *modelname)
2315 int dev = 0xa0; /* EEPROM device address */
2316 unsigned int i, size;
2318 if ((inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_EEPROM) == 0) {
2319 snd_printk("ICE1712 has not detected EEPROM\n");
2322 if (modelname && *modelname) {
2323 struct snd_ice1712_card_info **tbl, *c;
2324 for (tbl = card_tables; *tbl; tbl++) {
2325 for (c = *tbl; c->subvendor; c++) {
2326 if (c->model && !strcmp(modelname, c->model)) {
2327 /* use the given subvendor */
2328 printk(KERN_INFO "ice1712: Using board model %s\n", c->name);
2329 ice->eeprom.subvendor = c->subvendor;
2335 ice->eeprom.subvendor = (snd_ice1712_read_i2c(ice, dev, 0x00) << 0) |
2336 (snd_ice1712_read_i2c(ice, dev, 0x01) << 8) |
2337 (snd_ice1712_read_i2c(ice, dev, 0x02) << 16) |
2338 (snd_ice1712_read_i2c(ice, dev, 0x03) << 24);
2339 ice->eeprom.size = snd_ice1712_read_i2c(ice, dev, 0x04);
2340 if (ice->eeprom.size < 6)
2341 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */
2342 else if (ice->eeprom.size > 32) {
2343 snd_printk("invalid EEPROM (size = %i)\n", ice->eeprom.size);
2346 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05);
2347 if (ice->eeprom.version != 1) {
2348 snd_printk("invalid EEPROM version %i\n", ice->eeprom.version);
2351 size = ice->eeprom.size - 6;
2352 for (i = 0; i < size; i++)
2353 ice->eeprom.data[i] = snd_ice1712_read_i2c(ice, dev, i + 6);
2355 ice->eeprom.gpiomask = ice->eeprom.data[ICE_EEP1_GPIO_MASK];
2356 ice->eeprom.gpiostate = ice->eeprom.data[ICE_EEP1_GPIO_STATE];
2357 ice->eeprom.gpiodir = ice->eeprom.data[ICE_EEP1_GPIO_DIR];
2364 static int __devinit snd_ice1712_chip_init(ice1712_t *ice)
2366 outb(ICE1712_RESET | ICE1712_NATIVE, ICEREG(ice, CONTROL));
2368 outb(ICE1712_NATIVE, ICEREG(ice, CONTROL));
2370 pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]);
2371 pci_write_config_byte(ice->pci, 0x61, ice->eeprom.data[ICE_EEP1_ACLINK]);
2372 pci_write_config_byte(ice->pci, 0x62, ice->eeprom.data[ICE_EEP1_I2SID]);
2373 pci_write_config_byte(ice->pci, 0x63, ice->eeprom.data[ICE_EEP1_SPDIF]);
2374 if (ice->eeprom.subvendor != ICE1712_SUBDEVICE_STDSP24) {
2375 ice->gpio.write_mask = ice->eeprom.gpiomask;
2376 ice->gpio.direction = ice->eeprom.gpiodir;
2377 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ice->eeprom.gpiomask);
2378 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->eeprom.gpiodir);
2379 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ice->eeprom.gpiostate);
2381 ice->gpio.write_mask = 0xc0;
2382 ice->gpio.direction = 0xff;
2383 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, 0xc0);
2384 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, 0xff);
2385 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ICE1712_STDSP24_CLOCK_BIT);
2387 snd_ice1712_write(ice, ICE1712_IREG_PRO_POWERDOWN, 0);
2388 if (!(ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97)) {
2389 outb(ICE1712_AC97_WARM, ICEREG(ice, AC97_CMD));
2391 outb(0, ICEREG(ice, AC97_CMD));
2393 snd_ice1712_write(ice, ICE1712_IREG_CONSUMER_POWERDOWN, 0);
2399 int __devinit snd_ice1712_spdif_build_controls(ice1712_t *ice)
2402 snd_kcontrol_t *kctl;
2404 snd_assert(ice->pcm_pro != NULL, return -EIO);
2405 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_default, ice));
2408 kctl->id.device = ice->pcm_pro->device;
2409 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskc, ice));
2412 kctl->id.device = ice->pcm_pro->device;
2413 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskp, ice));
2416 kctl->id.device = ice->pcm_pro->device;
2417 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_stream, ice));
2420 kctl->id.device = ice->pcm_pro->device;
2421 ice->spdif.stream_ctl = kctl;
2426 static int __devinit snd_ice1712_build_controls(ice1712_t *ice)
2430 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_eeprom, ice));
2433 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock, ice));
2436 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock_default, ice));
2440 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_locking, ice));
2443 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_reset, ice));
2447 if (ice->num_total_dacs > 0) {
2448 snd_kcontrol_new_t tmp = snd_ice1712_mixer_pro_analog_route;
2449 tmp.count = ice->num_total_dacs;
2450 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2455 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice));
2459 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
2462 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice));
2469 static int snd_ice1712_free(ice1712_t *ice)
2471 if (ice->res_port == NULL)
2473 /* mask all interrupts */
2474 outb(0xc0, ICEMT(ice, IRQ));
2475 outb(0xff, ICEREG(ice, IRQMASK));
2478 if (ice->irq >= 0) {
2479 synchronize_irq(ice->irq);
2480 free_irq(ice->irq, (void *) ice);
2482 if (ice->res_port) {
2483 release_resource(ice->res_port);
2484 kfree_nocheck(ice->res_port);
2486 if (ice->res_ddma_port) {
2487 release_resource(ice->res_ddma_port);
2488 kfree_nocheck(ice->res_ddma_port);
2490 if (ice->res_dmapath_port) {
2491 release_resource(ice->res_dmapath_port);
2492 kfree_nocheck(ice->res_dmapath_port);
2494 if (ice->res_profi_port) {
2495 release_resource(ice->res_profi_port);
2496 kfree_nocheck(ice->res_profi_port);
2498 snd_ice1712_akm4xxx_free(ice);
2499 snd_magic_kfree(ice);
2503 static int snd_ice1712_dev_free(snd_device_t *device)
2505 ice1712_t *ice = snd_magic_cast(ice1712_t, device->device_data, return -ENXIO);
2506 return snd_ice1712_free(ice);
2509 static int __devinit snd_ice1712_create(snd_card_t * card,
2510 struct pci_dev *pci,
2511 const char *modelname,
2514 ice1712_t ** r_ice1712)
2518 static snd_device_ops_t ops = {
2519 .dev_free = snd_ice1712_dev_free,
2524 /* enable PCI device */
2525 if ((err = pci_enable_device(pci)) < 0)
2527 /* check, if we can restrict PCI DMA transfers to 28 bits */
2528 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 ||
2529 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) {
2530 snd_printk("architecture does not support 28bit PCI busmaster DMA\n");
2534 ice = snd_magic_kcalloc(ice1712_t, 0, GFP_KERNEL);
2537 ice->omni = omni ? 1 : 0;
2538 if (cs8427_timeout < 1)
2540 else if (cs8427_timeout > 1000)
2541 cs8427_timeout = 1000;
2542 ice->cs8427_timeout = cs8427_timeout;
2543 spin_lock_init(&ice->reg_lock);
2544 init_MUTEX(&ice->gpio_mutex);
2545 init_MUTEX(&ice->open_mutex);
2546 ice->gpio.set_mask = snd_ice1712_set_gpio_mask;
2547 ice->gpio.set_dir = snd_ice1712_set_gpio_dir;
2548 ice->gpio.set_data = snd_ice1712_set_gpio_data;
2549 ice->gpio.get_data = snd_ice1712_get_gpio_data;
2551 ice->spdif.cs8403_bits =
2552 ice->spdif.cs8403_stream_bits = (0x01 | /* consumer format */
2553 0x10 | /* no emphasis */
2554 0x20); /* PCM encoder/decoder */
2558 ice->port = pci_resource_start(pci, 0);
2559 ice->ddma_port = pci_resource_start(pci, 1);
2560 ice->dmapath_port = pci_resource_start(pci, 2);
2561 ice->profi_port = pci_resource_start(pci, 3);
2562 pci_set_master(pci);
2563 pci_write_config_word(ice->pci, 0x40, 0x807f);
2564 pci_write_config_word(ice->pci, 0x42, 0x0006);
2565 snd_ice1712_proc_init(ice);
2566 synchronize_irq(pci->irq);
2568 if ((ice->res_port = request_region(ice->port, 32, "ICE1712 - Controller")) == NULL) {
2569 snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->port, ice->port + 32 - 1);
2570 snd_ice1712_free(ice);
2573 if ((ice->res_ddma_port = request_region(ice->ddma_port, 16, "ICE1712 - DDMA")) == NULL) {
2574 snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->ddma_port, ice->ddma_port + 16 - 1);
2575 snd_ice1712_free(ice);
2578 if ((ice->res_dmapath_port = request_region(ice->dmapath_port, 16, "ICE1712 - DMA path")) == NULL) {
2579 snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->dmapath_port, ice->dmapath_port + 16 - 1);
2580 snd_ice1712_free(ice);
2583 if ((ice->res_profi_port = request_region(ice->profi_port, 64, "ICE1712 - Professional")) == NULL) {
2584 snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->profi_port, ice->profi_port + 16 - 1);
2585 snd_ice1712_free(ice);
2588 if (request_irq(pci->irq, snd_ice1712_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1712", (void *) ice)) {
2589 snd_printk("unable to grab IRQ %d\n", pci->irq);
2590 snd_ice1712_free(ice);
2594 ice->irq = pci->irq;
2596 if (snd_ice1712_read_eeprom(ice, modelname) < 0) {
2597 snd_ice1712_free(ice);
2600 if (snd_ice1712_chip_init(ice) < 0) {
2601 snd_ice1712_free(ice);
2605 /* unmask used interrupts */
2606 outb((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) == 0 ? ICE1712_IRQ_MPU2 : 0 |
2607 (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97) ? ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0,
2608 ICEREG(ice, IRQMASK));
2609 outb(0x00, ICEMT(ice, IRQ));
2611 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2612 snd_ice1712_free(ice);
2616 snd_card_set_dev(card, &pci->dev);
2629 static struct snd_ice1712_card_info no_matched __devinitdata;
2631 static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2632 const struct pci_device_id *pci_id)
2637 int pcm_dev = 0, err;
2638 struct snd_ice1712_card_info **tbl, *c;
2640 if (dev >= SNDRV_CARDS)
2647 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2651 strcpy(card->driver, "ICE1712");
2652 strcpy(card->shortname, "ICEnsemble ICE1712");
2654 if ((err = snd_ice1712_create(card, pci, model[dev], omni[dev], cs8427_timeout[dev], &ice)) < 0) {
2655 snd_card_free(card);
2659 for (tbl = card_tables; *tbl; tbl++) {
2660 for (c = *tbl; c->subvendor; c++) {
2661 if (c->subvendor == ice->eeprom.subvendor) {
2662 strcpy(card->shortname, c->name);
2663 if (c->driver) /* specific driver? */
2664 strcpy(card->driver, c->driver);
2666 if ((err = c->chip_init(ice)) < 0) {
2667 snd_card_free(card);
2678 if ((err = snd_ice1712_pcm_profi(ice, pcm_dev++, NULL)) < 0) {
2679 snd_card_free(card);
2683 if (ice_has_con_ac97(ice))
2684 if ((err = snd_ice1712_pcm(ice, pcm_dev++, NULL)) < 0) {
2685 snd_card_free(card);
2689 if ((err = snd_ice1712_ac97_mixer(ice)) < 0) {
2690 snd_card_free(card);
2694 if ((err = snd_ice1712_build_controls(ice)) < 0) {
2695 snd_card_free(card);
2699 if (c->build_controls) {
2700 if ((err = c->build_controls(ice)) < 0) {
2701 snd_card_free(card);
2706 if (ice_has_con_ac97(ice))
2707 if ((err = snd_ice1712_pcm_ds(ice, pcm_dev++, NULL)) < 0) {
2708 snd_card_free(card);
2712 if (! c->no_mpu401) {
2713 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2714 ICEREG(ice, MPU1_CTRL), 1,
2716 &ice->rmidi[0])) < 0) {
2717 snd_card_free(card);
2721 if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401)
2722 if ((err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712,
2723 ICEREG(ice, MPU2_CTRL), 1,
2725 &ice->rmidi[1])) < 0) {
2726 snd_card_free(card);
2731 sprintf(card->longname, "%s at 0x%lx, irq %i",
2732 card->shortname, ice->port, ice->irq);
2734 if ((err = snd_card_register(card)) < 0) {
2735 snd_card_free(card);
2738 pci_set_drvdata(pci, card);
2743 static void __devexit snd_ice1712_remove(struct pci_dev *pci)
2745 snd_card_free(pci_get_drvdata(pci));
2746 pci_set_drvdata(pci, NULL);
2749 static struct pci_driver driver = {
2751 .id_table = snd_ice1712_ids,
2752 .probe = snd_ice1712_probe,
2753 .remove = __devexit_p(snd_ice1712_remove),
2756 static int __init alsa_card_ice1712_init(void)
2758 return pci_module_init(&driver);
2761 static void __exit alsa_card_ice1712_exit(void)
2763 pci_unregister_driver(&driver);
2766 module_init(alsa_card_ice1712_init)
2767 module_exit(alsa_card_ice1712_exit)