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/dma-mapping.h>
57 #include <linux/slab.h>
58 #include <linux/moduleparam.h>
59 #include <linux/mutex.h>
61 #include <sound/core.h>
62 #include <sound/cs8427.h>
63 #include <sound/info.h>
64 #include <sound/initval.h>
66 #include <sound/asoundef.h>
70 /* lowlevel routines */
75 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
76 MODULE_DESCRIPTION("ICEnsemble ICE1712 (Envy24)");
77 MODULE_LICENSE("GPL");
78 MODULE_SUPPORTED_DEVICE("{"
82 "{ICEnsemble,Generic ICE1712},"
83 "{ICEnsemble,Generic Envy24}}");
85 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
86 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
87 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
88 static char *model[SNDRV_CARDS];
89 static int omni[SNDRV_CARDS]; /* Delta44 & 66 Omni I/O support */
90 static int cs8427_timeout[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 500}; /* CS8427 S/PDIF transciever reset timeout value in msec */
91 static int dxr_enable[SNDRV_CARDS]; /* DXR enable for DMX6FIRE */
93 module_param_array(index, int, NULL, 0444);
94 MODULE_PARM_DESC(index, "Index value for ICE1712 soundcard.");
95 module_param_array(id, charp, NULL, 0444);
96 MODULE_PARM_DESC(id, "ID string for ICE1712 soundcard.");
97 module_param_array(enable, bool, NULL, 0444);
98 MODULE_PARM_DESC(enable, "Enable ICE1712 soundcard.");
99 module_param_array(omni, bool, NULL, 0444);
100 MODULE_PARM_DESC(omni, "Enable Midiman M-Audio Delta Omni I/O support.");
101 module_param_array(cs8427_timeout, int, NULL, 0444);
102 MODULE_PARM_DESC(cs8427_timeout, "Define reset timeout for cs8427 chip in msec resolution.");
103 module_param_array(model, charp, NULL, 0444);
104 MODULE_PARM_DESC(model, "Use the given board model.");
105 module_param_array(dxr_enable, int, NULL, 0444);
106 MODULE_PARM_DESC(dxr_enable, "Enable DXR support for Terratec DMX6FIRE.");
109 static struct pci_device_id snd_ice1712_ids[] __devinitdata = {
110 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_ICE_1712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* ICE1712 */
114 MODULE_DEVICE_TABLE(pci, snd_ice1712_ids);
116 static int snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice);
117 static int snd_ice1712_build_controls(struct snd_ice1712 *ice);
119 static int PRO_RATE_LOCKED;
120 static int PRO_RATE_RESET = 1;
121 static unsigned int PRO_RATE_DEFAULT = 44100;
127 /* check whether the clock mode is spdif-in */
128 static inline int is_spdif_master(struct snd_ice1712 *ice)
130 return (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER) ? 1 : 0;
133 static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
135 return is_spdif_master(ice) || PRO_RATE_LOCKED;
138 static inline void snd_ice1712_ds_write(struct snd_ice1712 * ice, u8 channel, u8 addr, u32 data)
140 outb((channel << 4) | addr, ICEDS(ice, INDEX));
141 outl(data, ICEDS(ice, DATA));
144 static inline u32 snd_ice1712_ds_read(struct snd_ice1712 * ice, u8 channel, u8 addr)
146 outb((channel << 4) | addr, ICEDS(ice, INDEX));
147 return inl(ICEDS(ice, DATA));
150 static void snd_ice1712_ac97_write(struct snd_ac97 *ac97,
154 struct snd_ice1712 *ice = ac97->private_data;
156 unsigned char old_cmd = 0;
158 for (tm = 0; tm < 0x10000; tm++) {
159 old_cmd = inb(ICEREG(ice, AC97_CMD));
160 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
162 if (!(old_cmd & ICE1712_AC97_READY))
166 outb(reg, ICEREG(ice, AC97_INDEX));
167 outw(val, ICEREG(ice, AC97_DATA));
168 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
169 outb(old_cmd | ICE1712_AC97_WRITE, ICEREG(ice, AC97_CMD));
170 for (tm = 0; tm < 0x10000; tm++)
171 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
175 static unsigned short snd_ice1712_ac97_read(struct snd_ac97 *ac97,
178 struct snd_ice1712 *ice = ac97->private_data;
180 unsigned char old_cmd = 0;
182 for (tm = 0; tm < 0x10000; tm++) {
183 old_cmd = inb(ICEREG(ice, AC97_CMD));
184 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
186 if (!(old_cmd & ICE1712_AC97_READY))
190 outb(reg, ICEREG(ice, AC97_INDEX));
191 outb(old_cmd | ICE1712_AC97_READ, ICEREG(ice, AC97_CMD));
192 for (tm = 0; tm < 0x10000; tm++)
193 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
195 if (tm >= 0x10000) /* timeout */
197 return inw(ICEREG(ice, AC97_DATA));
204 static void snd_ice1712_pro_ac97_write(struct snd_ac97 *ac97,
208 struct snd_ice1712 *ice = ac97->private_data;
210 unsigned char old_cmd = 0;
212 for (tm = 0; tm < 0x10000; tm++) {
213 old_cmd = inb(ICEMT(ice, AC97_CMD));
214 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
216 if (!(old_cmd & ICE1712_AC97_READY))
220 outb(reg, ICEMT(ice, AC97_INDEX));
221 outw(val, ICEMT(ice, AC97_DATA));
222 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
223 outb(old_cmd | ICE1712_AC97_WRITE, ICEMT(ice, AC97_CMD));
224 for (tm = 0; tm < 0x10000; tm++)
225 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
230 static unsigned short snd_ice1712_pro_ac97_read(struct snd_ac97 *ac97,
233 struct snd_ice1712 *ice = ac97->private_data;
235 unsigned char old_cmd = 0;
237 for (tm = 0; tm < 0x10000; tm++) {
238 old_cmd = inb(ICEMT(ice, AC97_CMD));
239 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
241 if (!(old_cmd & ICE1712_AC97_READY))
245 outb(reg, ICEMT(ice, AC97_INDEX));
246 outb(old_cmd | ICE1712_AC97_READ, ICEMT(ice, AC97_CMD));
247 for (tm = 0; tm < 0x10000; tm++)
248 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
250 if (tm >= 0x10000) /* timeout */
252 return inw(ICEMT(ice, AC97_DATA));
256 * consumer ac97 digital mix
258 static int snd_ice1712_digmix_route_ac97_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
260 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
262 uinfo->value.integer.min = 0;
263 uinfo->value.integer.max = 1;
267 static int snd_ice1712_digmix_route_ac97_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
269 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
271 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0;
275 static int snd_ice1712_digmix_route_ac97_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
277 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
278 unsigned char val, nval;
280 spin_lock_irq(&ice->reg_lock);
281 val = inb(ICEMT(ice, MONITOR_ROUTECTRL));
282 nval = val & ~ICE1712_ROUTE_AC97;
283 if (ucontrol->value.integer.value[0]) nval |= ICE1712_ROUTE_AC97;
284 outb(nval, ICEMT(ice, MONITOR_ROUTECTRL));
285 spin_unlock_irq(&ice->reg_lock);
289 static struct snd_kcontrol_new snd_ice1712_mixer_digmix_route_ac97 __devinitdata = {
290 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
291 .name = "Digital Mixer To AC97",
292 .info = snd_ice1712_digmix_route_ac97_info,
293 .get = snd_ice1712_digmix_route_ac97_get,
294 .put = snd_ice1712_digmix_route_ac97_put,
301 static void snd_ice1712_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
303 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, data);
304 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
307 static void snd_ice1712_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
309 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data);
310 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
313 static unsigned int snd_ice1712_get_gpio_data(struct snd_ice1712 *ice)
315 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
318 static void snd_ice1712_set_gpio_data(struct snd_ice1712 *ice, unsigned int val)
320 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, val);
321 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
331 * change the input clock selection
332 * spdif_clock = 1 - IEC958 input, 0 - Envy24
334 static int snd_ice1712_cs8427_set_input_clock(struct snd_ice1712 *ice, int spdif_clock)
336 unsigned char reg[2] = { 0x80 | 4, 0 }; /* CS8427 auto increment | register number 4 + data */
337 unsigned char val, nval;
340 snd_i2c_lock(ice->i2c);
341 if (snd_i2c_sendbytes(ice->cs8427, reg, 1) != 1) {
342 snd_i2c_unlock(ice->i2c);
345 if (snd_i2c_readbytes(ice->cs8427, &val, 1) != 1) {
346 snd_i2c_unlock(ice->i2c);
356 if (snd_i2c_sendbytes(ice->cs8427, reg, 2) != 2) {
362 snd_i2c_unlock(ice->i2c);
369 static void open_cs8427(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
371 snd_cs8427_iec958_active(ice->cs8427, 1);
374 static void close_cs8427(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
376 snd_cs8427_iec958_active(ice->cs8427, 0);
379 static void setup_cs8427(struct snd_ice1712 *ice, int rate)
381 snd_cs8427_iec958_pcm(ice->cs8427, rate);
385 * create and initialize callbacks for cs8427 interface
387 int __devinit snd_ice1712_init_cs8427(struct snd_ice1712 *ice, int addr)
391 if ((err = snd_cs8427_create(ice->i2c, addr,
392 (ice->cs8427_timeout * HZ) / 1000,
393 &ice->cs8427)) < 0) {
394 snd_printk(KERN_ERR "CS8427 initialization failed\n");
397 ice->spdif.ops.open = open_cs8427;
398 ice->spdif.ops.close = close_cs8427;
399 ice->spdif.ops.setup_rate = setup_cs8427;
403 static void snd_ice1712_set_input_clock_source(struct snd_ice1712 *ice, int spdif_is_master)
405 /* change CS8427 clock source too */
407 snd_ice1712_cs8427_set_input_clock(ice, spdif_is_master);
408 /* notify ak4524 chip as well */
409 if (spdif_is_master) {
411 for (i = 0; i < ice->akm_codecs; i++) {
412 if (ice->akm[i].ops.set_rate_val)
413 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
422 static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
424 struct snd_ice1712 *ice = dev_id;
425 unsigned char status;
429 status = inb(ICEREG(ice, IRQSTAT));
433 if (status & ICE1712_IRQ_MPU1) {
435 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data, regs);
436 outb(ICE1712_IRQ_MPU1, ICEREG(ice, IRQSTAT));
437 status &= ~ICE1712_IRQ_MPU1;
439 if (status & ICE1712_IRQ_TIMER)
440 outb(ICE1712_IRQ_TIMER, ICEREG(ice, IRQSTAT));
441 if (status & ICE1712_IRQ_MPU2) {
443 snd_mpu401_uart_interrupt(irq, ice->rmidi[1]->private_data, regs);
444 outb(ICE1712_IRQ_MPU2, ICEREG(ice, IRQSTAT));
445 status &= ~ICE1712_IRQ_MPU2;
447 if (status & ICE1712_IRQ_PROPCM) {
448 unsigned char mtstat = inb(ICEMT(ice, IRQ));
449 if (mtstat & ICE1712_MULTI_PBKSTATUS) {
450 if (ice->playback_pro_substream)
451 snd_pcm_period_elapsed(ice->playback_pro_substream);
452 outb(ICE1712_MULTI_PBKSTATUS, ICEMT(ice, IRQ));
454 if (mtstat & ICE1712_MULTI_CAPSTATUS) {
455 if (ice->capture_pro_substream)
456 snd_pcm_period_elapsed(ice->capture_pro_substream);
457 outb(ICE1712_MULTI_CAPSTATUS, ICEMT(ice, IRQ));
460 if (status & ICE1712_IRQ_FM)
461 outb(ICE1712_IRQ_FM, ICEREG(ice, IRQSTAT));
462 if (status & ICE1712_IRQ_PBKDS) {
465 struct snd_pcm_substream *substream;
466 pbkstatus = inw(ICEDS(ice, INTSTAT));
467 //printk("pbkstatus = 0x%x\n", pbkstatus);
468 for (idx = 0; idx < 6; idx++) {
469 if ((pbkstatus & (3 << (idx * 2))) == 0)
471 if ((substream = ice->playback_con_substream_ds[idx]) != NULL)
472 snd_pcm_period_elapsed(substream);
473 outw(3 << (idx * 2), ICEDS(ice, INTSTAT));
475 outb(ICE1712_IRQ_PBKDS, ICEREG(ice, IRQSTAT));
477 if (status & ICE1712_IRQ_CONCAP) {
478 if (ice->capture_con_substream)
479 snd_pcm_period_elapsed(ice->capture_con_substream);
480 outb(ICE1712_IRQ_CONCAP, ICEREG(ice, IRQSTAT));
482 if (status & ICE1712_IRQ_CONPBK) {
483 if (ice->playback_con_substream)
484 snd_pcm_period_elapsed(ice->playback_con_substream);
485 outb(ICE1712_IRQ_CONPBK, ICEREG(ice, IRQSTAT));
488 return IRQ_RETVAL(handled);
496 static int snd_ice1712_hw_params(struct snd_pcm_substream *substream,
497 struct snd_pcm_hw_params *hw_params)
499 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
502 static int snd_ice1712_hw_free(struct snd_pcm_substream *substream)
504 return snd_pcm_lib_free_pages(substream);
508 * PCM part - consumer I/O
511 static int snd_ice1712_playback_trigger(struct snd_pcm_substream *substream,
514 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
518 spin_lock(&ice->reg_lock);
519 tmp = snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL);
520 if (cmd == SNDRV_PCM_TRIGGER_START) {
522 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
524 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
526 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
531 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
532 spin_unlock(&ice->reg_lock);
536 static int snd_ice1712_playback_ds_trigger(struct snd_pcm_substream *substream,
539 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
543 spin_lock(&ice->reg_lock);
544 tmp = snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL);
545 if (cmd == SNDRV_PCM_TRIGGER_START) {
547 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
549 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
551 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
556 snd_ice1712_ds_write(ice, substream->number * 2, ICE1712_DSC_CONTROL, tmp);
557 spin_unlock(&ice->reg_lock);
561 static int snd_ice1712_capture_trigger(struct snd_pcm_substream *substream,
564 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
568 spin_lock(&ice->reg_lock);
569 tmp = snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL);
570 if (cmd == SNDRV_PCM_TRIGGER_START) {
572 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
577 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
578 spin_unlock(&ice->reg_lock);
582 static int snd_ice1712_playback_prepare(struct snd_pcm_substream *substream)
584 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
585 struct snd_pcm_runtime *runtime = substream->runtime;
586 u32 period_size, buf_size, rate, tmp;
588 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
589 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
591 if (snd_pcm_format_width(runtime->format) == 16)
593 if (runtime->channels == 2)
595 rate = (runtime->rate * 8192) / 375;
596 if (rate > 0x000fffff)
598 spin_lock_irq(&ice->reg_lock);
599 outb(0, ice->ddma_port + 15);
600 outb(ICE1712_DMA_MODE_WRITE | ICE1712_DMA_AUTOINIT, ice->ddma_port + 0x0b);
601 outl(runtime->dma_addr, ice->ddma_port + 0);
602 outw(buf_size, ice->ddma_port + 4);
603 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_LO, rate & 0xff);
604 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_MID, (rate >> 8) & 0xff);
605 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_HI, (rate >> 16) & 0xff);
606 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
607 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_LO, period_size & 0xff);
608 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_HI, period_size >> 8);
609 snd_ice1712_write(ice, ICE1712_IREG_PBK_LEFT, 0);
610 snd_ice1712_write(ice, ICE1712_IREG_PBK_RIGHT, 0);
611 spin_unlock_irq(&ice->reg_lock);
615 static int snd_ice1712_playback_ds_prepare(struct snd_pcm_substream *substream)
617 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
618 struct snd_pcm_runtime *runtime = substream->runtime;
619 u32 period_size, buf_size, rate, tmp, chn;
621 period_size = snd_pcm_lib_period_bytes(substream) - 1;
622 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
624 if (snd_pcm_format_width(runtime->format) == 16)
626 if (runtime->channels == 2)
628 rate = (runtime->rate * 8192) / 375;
629 if (rate > 0x000fffff)
631 ice->playback_con_active_buf[substream->number] = 0;
632 ice->playback_con_virt_addr[substream->number] = runtime->dma_addr;
633 chn = substream->number * 2;
634 spin_lock_irq(&ice->reg_lock);
635 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR0, runtime->dma_addr);
636 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT0, period_size);
637 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR1, runtime->dma_addr + (runtime->periods > 1 ? period_size + 1 : 0));
638 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT1, period_size);
639 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_RATE, rate);
640 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_VOLUME, 0);
641 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_CONTROL, tmp);
642 if (runtime->channels == 2) {
643 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_RATE, rate);
644 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_VOLUME, 0);
646 spin_unlock_irq(&ice->reg_lock);
650 static int snd_ice1712_capture_prepare(struct snd_pcm_substream *substream)
652 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
653 struct snd_pcm_runtime *runtime = substream->runtime;
654 u32 period_size, buf_size;
657 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
658 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
660 if (snd_pcm_format_width(runtime->format) == 16)
662 if (runtime->channels == 2)
664 spin_lock_irq(&ice->reg_lock);
665 outl(ice->capture_con_virt_addr = runtime->dma_addr, ICEREG(ice, CONCAP_ADDR));
666 outw(buf_size, ICEREG(ice, CONCAP_COUNT));
667 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_HI, period_size >> 8);
668 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_LO, period_size & 0xff);
669 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
670 spin_unlock_irq(&ice->reg_lock);
671 snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
675 static snd_pcm_uframes_t snd_ice1712_playback_pointer(struct snd_pcm_substream *substream)
677 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
678 struct snd_pcm_runtime *runtime = substream->runtime;
681 if (!(snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL) & 1))
683 ptr = runtime->buffer_size - inw(ice->ddma_port + 4);
684 if (ptr == runtime->buffer_size)
686 return bytes_to_frames(substream->runtime, ptr);
689 static snd_pcm_uframes_t snd_ice1712_playback_ds_pointer(struct snd_pcm_substream *substream)
691 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
695 if (!(snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL) & 1))
697 if (ice->playback_con_active_buf[substream->number])
698 addr = ICE1712_DSC_ADDR1;
700 addr = ICE1712_DSC_ADDR0;
701 ptr = snd_ice1712_ds_read(ice, substream->number * 2, addr) -
702 ice->playback_con_virt_addr[substream->number];
703 if (ptr == substream->runtime->buffer_size)
705 return bytes_to_frames(substream->runtime, ptr);
708 static snd_pcm_uframes_t snd_ice1712_capture_pointer(struct snd_pcm_substream *substream)
710 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
713 if (!(snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL) & 1))
715 ptr = inl(ICEREG(ice, CONCAP_ADDR)) - ice->capture_con_virt_addr;
716 if (ptr == substream->runtime->buffer_size)
718 return bytes_to_frames(substream->runtime, ptr);
721 static struct snd_pcm_hardware snd_ice1712_playback =
723 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
724 SNDRV_PCM_INFO_BLOCK_TRANSFER |
725 SNDRV_PCM_INFO_MMAP_VALID |
726 SNDRV_PCM_INFO_PAUSE),
727 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
728 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
733 .buffer_bytes_max = (64*1024),
734 .period_bytes_min = 64,
735 .period_bytes_max = (64*1024),
741 static struct snd_pcm_hardware snd_ice1712_playback_ds =
743 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
744 SNDRV_PCM_INFO_BLOCK_TRANSFER |
745 SNDRV_PCM_INFO_MMAP_VALID |
746 SNDRV_PCM_INFO_PAUSE),
747 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
748 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
753 .buffer_bytes_max = (128*1024),
754 .period_bytes_min = 64,
755 .period_bytes_max = (128*1024),
761 static struct snd_pcm_hardware snd_ice1712_capture =
763 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
764 SNDRV_PCM_INFO_BLOCK_TRANSFER |
765 SNDRV_PCM_INFO_MMAP_VALID),
766 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
767 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
772 .buffer_bytes_max = (64*1024),
773 .period_bytes_min = 64,
774 .period_bytes_max = (64*1024),
780 static int snd_ice1712_playback_open(struct snd_pcm_substream *substream)
782 struct snd_pcm_runtime *runtime = substream->runtime;
783 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
785 ice->playback_con_substream = substream;
786 runtime->hw = snd_ice1712_playback;
790 static int snd_ice1712_playback_ds_open(struct snd_pcm_substream *substream)
792 struct snd_pcm_runtime *runtime = substream->runtime;
793 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
796 ice->playback_con_substream_ds[substream->number] = substream;
797 runtime->hw = snd_ice1712_playback_ds;
798 spin_lock_irq(&ice->reg_lock);
799 tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2));
800 outw(tmp, ICEDS(ice, INTMASK));
801 spin_unlock_irq(&ice->reg_lock);
805 static int snd_ice1712_capture_open(struct snd_pcm_substream *substream)
807 struct snd_pcm_runtime *runtime = substream->runtime;
808 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
810 ice->capture_con_substream = substream;
811 runtime->hw = snd_ice1712_capture;
812 runtime->hw.rates = ice->ac97->rates[AC97_RATES_ADC];
813 if (!(runtime->hw.rates & SNDRV_PCM_RATE_8000))
814 runtime->hw.rate_min = 48000;
818 static int snd_ice1712_playback_close(struct snd_pcm_substream *substream)
820 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
822 ice->playback_con_substream = NULL;
826 static int snd_ice1712_playback_ds_close(struct snd_pcm_substream *substream)
828 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
831 spin_lock_irq(&ice->reg_lock);
832 tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2));
833 outw(tmp, ICEDS(ice, INTMASK));
834 spin_unlock_irq(&ice->reg_lock);
835 ice->playback_con_substream_ds[substream->number] = NULL;
839 static int snd_ice1712_capture_close(struct snd_pcm_substream *substream)
841 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
843 ice->capture_con_substream = NULL;
847 static struct snd_pcm_ops snd_ice1712_playback_ops = {
848 .open = snd_ice1712_playback_open,
849 .close = snd_ice1712_playback_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_prepare,
854 .trigger = snd_ice1712_playback_trigger,
855 .pointer = snd_ice1712_playback_pointer,
858 static struct snd_pcm_ops snd_ice1712_playback_ds_ops = {
859 .open = snd_ice1712_playback_ds_open,
860 .close = snd_ice1712_playback_ds_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_playback_ds_prepare,
865 .trigger = snd_ice1712_playback_ds_trigger,
866 .pointer = snd_ice1712_playback_ds_pointer,
869 static struct snd_pcm_ops snd_ice1712_capture_ops = {
870 .open = snd_ice1712_capture_open,
871 .close = snd_ice1712_capture_close,
872 .ioctl = snd_pcm_lib_ioctl,
873 .hw_params = snd_ice1712_hw_params,
874 .hw_free = snd_ice1712_hw_free,
875 .prepare = snd_ice1712_capture_prepare,
876 .trigger = snd_ice1712_capture_trigger,
877 .pointer = snd_ice1712_capture_pointer,
880 static int __devinit snd_ice1712_pcm(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
887 err = snd_pcm_new(ice->card, "ICE1712 consumer", device, 1, 1, &pcm);
891 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ops);
892 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_ops);
894 pcm->private_data = ice;
896 strcpy(pcm->name, "ICE1712 consumer");
899 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
900 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
905 printk(KERN_WARNING "Consumer PCM code does not work well at the moment --jk\n");
910 static int __devinit snd_ice1712_pcm_ds(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
917 err = snd_pcm_new(ice->card, "ICE1712 consumer (DS)", device, 6, 0, &pcm);
921 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ds_ops);
923 pcm->private_data = ice;
925 strcpy(pcm->name, "ICE1712 consumer (DS)");
928 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
929 snd_dma_pci_data(ice->pci), 64*1024, 128*1024);
938 * PCM code - professional part (multitrack)
941 static unsigned int rates[] = { 8000, 9600, 11025, 12000, 16000, 22050, 24000,
942 32000, 44100, 48000, 64000, 88200, 96000 };
944 static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
945 .count = ARRAY_SIZE(rates),
950 static int snd_ice1712_pro_trigger(struct snd_pcm_substream *substream,
953 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
955 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
956 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
960 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
962 what = ICE1712_PLAYBACK_PAUSE;
963 snd_pcm_trigger_done(substream, substream);
964 spin_lock(&ice->reg_lock);
965 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
966 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
970 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
971 spin_unlock(&ice->reg_lock);
974 case SNDRV_PCM_TRIGGER_START:
975 case SNDRV_PCM_TRIGGER_STOP:
977 unsigned int what = 0;
979 struct list_head *pos;
980 struct snd_pcm_substream *s;
982 snd_pcm_group_for_each(pos, substream) {
983 s = snd_pcm_group_substream_entry(pos);
984 if (s == ice->playback_pro_substream) {
985 what |= ICE1712_PLAYBACK_START;
986 snd_pcm_trigger_done(s, substream);
987 } else if (s == ice->capture_pro_substream) {
988 what |= ICE1712_CAPTURE_START_SHADOW;
989 snd_pcm_trigger_done(s, substream);
992 spin_lock(&ice->reg_lock);
993 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
994 if (cmd == SNDRV_PCM_TRIGGER_START)
998 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
999 spin_unlock(&ice->reg_lock);
1010 static void snd_ice1712_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate, int force)
1012 unsigned long flags;
1013 unsigned char val, old;
1017 case 8000: val = 6; break;
1018 case 9600: val = 3; break;
1019 case 11025: val = 10; break;
1020 case 12000: val = 2; break;
1021 case 16000: val = 5; break;
1022 case 22050: val = 9; break;
1023 case 24000: val = 1; break;
1024 case 32000: val = 4; break;
1025 case 44100: val = 8; break;
1026 case 48000: val = 0; break;
1027 case 64000: val = 15; break;
1028 case 88200: val = 11; break;
1029 case 96000: val = 7; break;
1037 spin_lock_irqsave(&ice->reg_lock, flags);
1038 if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
1039 ICE1712_PLAYBACK_PAUSE|
1040 ICE1712_PLAYBACK_START)) {
1042 spin_unlock_irqrestore(&ice->reg_lock, flags);
1045 if (!force && is_pro_rate_locked(ice))
1048 old = inb(ICEMT(ice, RATE));
1049 if (!force && old == val)
1051 outb(val, ICEMT(ice, RATE));
1052 spin_unlock_irqrestore(&ice->reg_lock, flags);
1054 if (ice->gpio.set_pro_rate)
1055 ice->gpio.set_pro_rate(ice, rate);
1056 for (i = 0; i < ice->akm_codecs; i++) {
1057 if (ice->akm[i].ops.set_rate_val)
1058 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
1060 if (ice->spdif.ops.setup_rate)
1061 ice->spdif.ops.setup_rate(ice, rate);
1064 static int snd_ice1712_playback_pro_prepare(struct snd_pcm_substream *substream)
1066 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1068 ice->playback_pro_size = snd_pcm_lib_buffer_bytes(substream);
1069 spin_lock_irq(&ice->reg_lock);
1070 outl(substream->runtime->dma_addr, ICEMT(ice, PLAYBACK_ADDR));
1071 outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));
1072 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT));
1073 spin_unlock_irq(&ice->reg_lock);
1078 static int snd_ice1712_playback_pro_hw_params(struct snd_pcm_substream *substream,
1079 struct snd_pcm_hw_params *hw_params)
1081 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1083 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1084 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1087 static int snd_ice1712_capture_pro_prepare(struct snd_pcm_substream *substream)
1089 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1091 ice->capture_pro_size = snd_pcm_lib_buffer_bytes(substream);
1092 spin_lock_irq(&ice->reg_lock);
1093 outl(substream->runtime->dma_addr, ICEMT(ice, CAPTURE_ADDR));
1094 outw((ice->capture_pro_size >> 2) - 1, ICEMT(ice, CAPTURE_SIZE));
1095 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, CAPTURE_COUNT));
1096 spin_unlock_irq(&ice->reg_lock);
1100 static int snd_ice1712_capture_pro_hw_params(struct snd_pcm_substream *substream,
1101 struct snd_pcm_hw_params *hw_params)
1103 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1105 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1106 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1109 static snd_pcm_uframes_t snd_ice1712_playback_pro_pointer(struct snd_pcm_substream *substream)
1111 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1114 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_PLAYBACK_START))
1116 ptr = ice->playback_pro_size - (inw(ICEMT(ice, PLAYBACK_SIZE)) << 2);
1117 if (ptr == substream->runtime->buffer_size)
1119 return bytes_to_frames(substream->runtime, ptr);
1122 static snd_pcm_uframes_t snd_ice1712_capture_pro_pointer(struct snd_pcm_substream *substream)
1124 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1127 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_CAPTURE_START_SHADOW))
1129 ptr = ice->capture_pro_size - (inw(ICEMT(ice, CAPTURE_SIZE)) << 2);
1130 if (ptr == substream->runtime->buffer_size)
1132 return bytes_to_frames(substream->runtime, ptr);
1135 static struct snd_pcm_hardware snd_ice1712_playback_pro =
1137 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1138 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1139 SNDRV_PCM_INFO_MMAP_VALID |
1140 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1141 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1142 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1147 .buffer_bytes_max = (256*1024),
1148 .period_bytes_min = 10 * 4 * 2,
1149 .period_bytes_max = 131040,
1151 .periods_max = 1024,
1155 static struct snd_pcm_hardware snd_ice1712_capture_pro =
1157 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1158 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1159 SNDRV_PCM_INFO_MMAP_VALID |
1160 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1161 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1162 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1167 .buffer_bytes_max = (256*1024),
1168 .period_bytes_min = 12 * 4 * 2,
1169 .period_bytes_max = 131040,
1171 .periods_max = 1024,
1175 static int snd_ice1712_playback_pro_open(struct snd_pcm_substream *substream)
1177 struct snd_pcm_runtime *runtime = substream->runtime;
1178 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1180 ice->playback_pro_substream = substream;
1181 runtime->hw = snd_ice1712_playback_pro;
1182 snd_pcm_set_sync(substream);
1183 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1184 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1186 if (ice->spdif.ops.open)
1187 ice->spdif.ops.open(ice, substream);
1192 static int snd_ice1712_capture_pro_open(struct snd_pcm_substream *substream)
1194 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1195 struct snd_pcm_runtime *runtime = substream->runtime;
1197 ice->capture_pro_substream = substream;
1198 runtime->hw = snd_ice1712_capture_pro;
1199 snd_pcm_set_sync(substream);
1200 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1201 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1205 static int snd_ice1712_playback_pro_close(struct snd_pcm_substream *substream)
1207 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1210 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1211 ice->playback_pro_substream = NULL;
1212 if (ice->spdif.ops.close)
1213 ice->spdif.ops.close(ice, substream);
1218 static int snd_ice1712_capture_pro_close(struct snd_pcm_substream *substream)
1220 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1223 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1224 ice->capture_pro_substream = NULL;
1228 static struct snd_pcm_ops snd_ice1712_playback_pro_ops = {
1229 .open = snd_ice1712_playback_pro_open,
1230 .close = snd_ice1712_playback_pro_close,
1231 .ioctl = snd_pcm_lib_ioctl,
1232 .hw_params = snd_ice1712_playback_pro_hw_params,
1233 .hw_free = snd_ice1712_hw_free,
1234 .prepare = snd_ice1712_playback_pro_prepare,
1235 .trigger = snd_ice1712_pro_trigger,
1236 .pointer = snd_ice1712_playback_pro_pointer,
1239 static struct snd_pcm_ops snd_ice1712_capture_pro_ops = {
1240 .open = snd_ice1712_capture_pro_open,
1241 .close = snd_ice1712_capture_pro_close,
1242 .ioctl = snd_pcm_lib_ioctl,
1243 .hw_params = snd_ice1712_capture_pro_hw_params,
1244 .hw_free = snd_ice1712_hw_free,
1245 .prepare = snd_ice1712_capture_pro_prepare,
1246 .trigger = snd_ice1712_pro_trigger,
1247 .pointer = snd_ice1712_capture_pro_pointer,
1250 static int __devinit snd_ice1712_pcm_profi(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
1252 struct snd_pcm *pcm;
1257 err = snd_pcm_new(ice->card, "ICE1712 multi", device, 1, 1, &pcm);
1261 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_pro_ops);
1262 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_pro_ops);
1264 pcm->private_data = ice;
1265 pcm->info_flags = 0;
1266 strcpy(pcm->name, "ICE1712 multi");
1268 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1269 snd_dma_pci_data(ice->pci), 256*1024, 256*1024);
1276 /* assign channels to iec958 */
1277 err = snd_cs8427_iec958_build(ice->cs8427,
1278 pcm->streams[0].substream,
1279 pcm->streams[1].substream);
1284 if ((err = snd_ice1712_build_pro_mixer(ice)) < 0)
1293 static void snd_ice1712_update_volume(struct snd_ice1712 *ice, int index)
1295 unsigned int vol = ice->pro_volumes[index];
1296 unsigned short val = 0;
1298 val |= (vol & 0x8000) == 0 ? (96 - (vol & 0x7f)) : 0x7f;
1299 val |= ((vol & 0x80000000) == 0 ? (96 - ((vol >> 16) & 0x7f)) : 0x7f) << 8;
1300 outb(index, ICEMT(ice, MONITOR_INDEX));
1301 outw(val, ICEMT(ice, MONITOR_VOLUME));
1304 static int snd_ice1712_pro_mixer_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1306 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1308 uinfo->value.integer.min = 0;
1309 uinfo->value.integer.max = 1;
1313 static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1315 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1316 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1318 spin_lock_irq(&ice->reg_lock);
1319 ucontrol->value.integer.value[0] = !((ice->pro_volumes[index] >> 15) & 1);
1320 ucontrol->value.integer.value[1] = !((ice->pro_volumes[index] >> 31) & 1);
1321 spin_unlock_irq(&ice->reg_lock);
1325 static int snd_ice1712_pro_mixer_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1327 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1328 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1329 unsigned int nval, change;
1331 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
1332 (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
1333 spin_lock_irq(&ice->reg_lock);
1334 nval |= ice->pro_volumes[index] & ~0x80008000;
1335 change = nval != ice->pro_volumes[index];
1336 ice->pro_volumes[index] = nval;
1337 snd_ice1712_update_volume(ice, index);
1338 spin_unlock_irq(&ice->reg_lock);
1342 static int snd_ice1712_pro_mixer_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1344 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1346 uinfo->value.integer.min = 0;
1347 uinfo->value.integer.max = 96;
1351 static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1353 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1354 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1356 spin_lock_irq(&ice->reg_lock);
1357 ucontrol->value.integer.value[0] = (ice->pro_volumes[index] >> 0) & 127;
1358 ucontrol->value.integer.value[1] = (ice->pro_volumes[index] >> 16) & 127;
1359 spin_unlock_irq(&ice->reg_lock);
1363 static int snd_ice1712_pro_mixer_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1365 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1366 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1367 unsigned int nval, change;
1369 nval = (ucontrol->value.integer.value[0] & 127) |
1370 ((ucontrol->value.integer.value[1] & 127) << 16);
1371 spin_lock_irq(&ice->reg_lock);
1372 nval |= ice->pro_volumes[index] & ~0x007f007f;
1373 change = nval != ice->pro_volumes[index];
1374 ice->pro_volumes[index] = nval;
1375 snd_ice1712_update_volume(ice, index);
1376 spin_unlock_irq(&ice->reg_lock);
1381 static struct snd_kcontrol_new snd_ice1712_multi_playback_ctrls[] __devinitdata = {
1383 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1384 .name = "Multi Playback Switch",
1385 .info = snd_ice1712_pro_mixer_switch_info,
1386 .get = snd_ice1712_pro_mixer_switch_get,
1387 .put = snd_ice1712_pro_mixer_switch_put,
1392 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1393 .name = "Multi Playback Volume",
1394 .info = snd_ice1712_pro_mixer_volume_info,
1395 .get = snd_ice1712_pro_mixer_volume_get,
1396 .put = snd_ice1712_pro_mixer_volume_put,
1402 static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_switch __devinitdata = {
1403 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1404 .name = "H/W Multi Capture Switch",
1405 .info = snd_ice1712_pro_mixer_switch_info,
1406 .get = snd_ice1712_pro_mixer_switch_get,
1407 .put = snd_ice1712_pro_mixer_switch_put,
1408 .private_value = 10,
1411 static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_switch __devinitdata = {
1412 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1413 .name = SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE,SWITCH),
1414 .info = snd_ice1712_pro_mixer_switch_info,
1415 .get = snd_ice1712_pro_mixer_switch_get,
1416 .put = snd_ice1712_pro_mixer_switch_put,
1417 .private_value = 18,
1421 static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_volume __devinitdata = {
1422 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1423 .name = "H/W Multi Capture Volume",
1424 .info = snd_ice1712_pro_mixer_volume_info,
1425 .get = snd_ice1712_pro_mixer_volume_get,
1426 .put = snd_ice1712_pro_mixer_volume_put,
1427 .private_value = 10,
1430 static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_volume __devinitdata = {
1431 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1432 .name = SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE,VOLUME),
1433 .info = snd_ice1712_pro_mixer_volume_info,
1434 .get = snd_ice1712_pro_mixer_volume_get,
1435 .put = snd_ice1712_pro_mixer_volume_put,
1436 .private_value = 18,
1440 static int __devinit snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice)
1442 struct snd_card *card = ice->card;
1446 /* multi-channel mixer */
1447 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_multi_playback_ctrls); idx++) {
1448 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_playback_ctrls[idx], ice));
1453 if (ice->num_total_adcs > 0) {
1454 struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_switch;
1455 tmp.count = ice->num_total_adcs;
1456 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1461 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_switch, ice));
1465 if (ice->num_total_adcs > 0) {
1466 struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_volume;
1467 tmp.count = ice->num_total_adcs;
1468 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1473 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_volume, ice));
1477 /* initialize volumes */
1478 for (idx = 0; idx < 10; idx++) {
1479 ice->pro_volumes[idx] = 0x80008000; /* mute */
1480 snd_ice1712_update_volume(ice, idx);
1482 for (idx = 10; idx < 10 + ice->num_total_adcs; idx++) {
1483 ice->pro_volumes[idx] = 0x80008000; /* mute */
1484 snd_ice1712_update_volume(ice, idx);
1486 for (idx = 18; idx < 20; idx++) {
1487 ice->pro_volumes[idx] = 0x80008000; /* mute */
1488 snd_ice1712_update_volume(ice, idx);
1493 static void snd_ice1712_mixer_free_ac97(struct snd_ac97 *ac97)
1495 struct snd_ice1712 *ice = ac97->private_data;
1499 static int __devinit snd_ice1712_ac97_mixer(struct snd_ice1712 * ice)
1501 int err, bus_num = 0;
1502 struct snd_ac97_template ac97;
1503 struct snd_ac97_bus *pbus;
1504 static struct snd_ac97_bus_ops con_ops = {
1505 .write = snd_ice1712_ac97_write,
1506 .read = snd_ice1712_ac97_read,
1508 static struct snd_ac97_bus_ops pro_ops = {
1509 .write = snd_ice1712_pro_ac97_write,
1510 .read = snd_ice1712_pro_ac97_read,
1513 if (ice_has_con_ac97(ice)) {
1514 if ((err = snd_ac97_bus(ice->card, bus_num++, &con_ops, NULL, &pbus)) < 0)
1516 memset(&ac97, 0, sizeof(ac97));
1517 ac97.private_data = ice;
1518 ac97.private_free = snd_ice1712_mixer_free_ac97;
1519 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1520 printk(KERN_WARNING "ice1712: cannot initialize ac97 for consumer, skipped\n");
1522 if ((err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice))) < 0)
1528 if (! (ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) {
1529 if ((err = snd_ac97_bus(ice->card, bus_num, &pro_ops, NULL, &pbus)) < 0)
1531 memset(&ac97, 0, sizeof(ac97));
1532 ac97.private_data = ice;
1533 ac97.private_free = snd_ice1712_mixer_free_ac97;
1534 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1535 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1539 /* I2S mixer only */
1540 strcat(ice->card->mixername, "ICE1712 - multitrack");
1548 static inline unsigned int eeprom_double(struct snd_ice1712 *ice, int idx)
1550 return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8);
1553 static void snd_ice1712_proc_read(struct snd_info_entry *entry,
1554 struct snd_info_buffer *buffer)
1556 struct snd_ice1712 *ice = entry->private_data;
1559 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1560 snd_iprintf(buffer, "EEPROM:\n");
1562 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1563 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1564 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1565 snd_iprintf(buffer, " Codec : 0x%x\n", ice->eeprom.data[ICE_EEP1_CODEC]);
1566 snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP1_ACLINK]);
1567 snd_iprintf(buffer, " I2S ID : 0x%x\n", ice->eeprom.data[ICE_EEP1_I2SID]);
1568 snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP1_SPDIF]);
1569 snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
1570 snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
1571 snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
1572 snd_iprintf(buffer, " AC'97 main : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_MAIN_LO));
1573 snd_iprintf(buffer, " AC'97 pcm : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_PCM_LO));
1574 snd_iprintf(buffer, " AC'97 record : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_REC_LO));
1575 snd_iprintf(buffer, " AC'97 record src : 0x%x\n", ice->eeprom.data[ICE_EEP1_AC97_RECSRC]);
1576 for (idx = 0; idx < 4; idx++)
1577 snd_iprintf(buffer, " DAC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_DAC_ID + idx]);
1578 for (idx = 0; idx < 4; idx++)
1579 snd_iprintf(buffer, " ADC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_ADC_ID + idx]);
1580 for (idx = 0x1c; idx < ice->eeprom.size; idx++)
1581 snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
1583 snd_iprintf(buffer, "\nRegisters:\n");
1584 snd_iprintf(buffer, " PSDOUT03 : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_PSDOUT03)));
1585 snd_iprintf(buffer, " CAPTURE : 0x%08x\n", inl(ICEMT(ice, ROUTE_CAPTURE)));
1586 snd_iprintf(buffer, " SPDOUT : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT)));
1587 snd_iprintf(buffer, " RATE : 0x%02x\n", (unsigned)inb(ICEMT(ice, RATE)));
1588 snd_iprintf(buffer, " GPIO_DATA : 0x%02x\n", (unsigned)snd_ice1712_get_gpio_data(ice));
1589 snd_iprintf(buffer, " GPIO_WRITE_MASK : 0x%02x\n", (unsigned)snd_ice1712_read(ice, ICE1712_IREG_GPIO_WRITE_MASK));
1590 snd_iprintf(buffer, " GPIO_DIRECTION : 0x%02x\n", (unsigned)snd_ice1712_read(ice, ICE1712_IREG_GPIO_DIRECTION));
1593 static void __devinit snd_ice1712_proc_init(struct snd_ice1712 * ice)
1595 struct snd_info_entry *entry;
1597 if (! snd_card_proc_new(ice->card, "ice1712", &entry))
1598 snd_info_set_text_ops(entry, ice, snd_ice1712_proc_read);
1605 static int snd_ice1712_eeprom_info(struct snd_kcontrol *kcontrol,
1606 struct snd_ctl_elem_info *uinfo)
1608 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1609 uinfo->count = sizeof(struct snd_ice1712_eeprom);
1613 static int snd_ice1712_eeprom_get(struct snd_kcontrol *kcontrol,
1614 struct snd_ctl_elem_value *ucontrol)
1616 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1618 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1622 static struct snd_kcontrol_new snd_ice1712_eeprom __devinitdata = {
1623 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1624 .name = "ICE1712 EEPROM",
1625 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1626 .info = snd_ice1712_eeprom_info,
1627 .get = snd_ice1712_eeprom_get
1632 static int snd_ice1712_spdif_info(struct snd_kcontrol *kcontrol,
1633 struct snd_ctl_elem_info *uinfo)
1635 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1640 static int snd_ice1712_spdif_default_get(struct snd_kcontrol *kcontrol,
1641 struct snd_ctl_elem_value *ucontrol)
1643 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1644 if (ice->spdif.ops.default_get)
1645 ice->spdif.ops.default_get(ice, ucontrol);
1649 static int snd_ice1712_spdif_default_put(struct snd_kcontrol *kcontrol,
1650 struct snd_ctl_elem_value *ucontrol)
1652 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1653 if (ice->spdif.ops.default_put)
1654 return ice->spdif.ops.default_put(ice, ucontrol);
1658 static struct snd_kcontrol_new snd_ice1712_spdif_default __devinitdata =
1660 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1661 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1662 .info = snd_ice1712_spdif_info,
1663 .get = snd_ice1712_spdif_default_get,
1664 .put = snd_ice1712_spdif_default_put
1667 static int snd_ice1712_spdif_maskc_get(struct snd_kcontrol *kcontrol,
1668 struct snd_ctl_elem_value *ucontrol)
1670 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1671 if (ice->spdif.ops.default_get) {
1672 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1673 IEC958_AES0_PROFESSIONAL |
1674 IEC958_AES0_CON_NOT_COPYRIGHT |
1675 IEC958_AES0_CON_EMPHASIS;
1676 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1677 IEC958_AES1_CON_CATEGORY;
1678 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1680 ucontrol->value.iec958.status[0] = 0xff;
1681 ucontrol->value.iec958.status[1] = 0xff;
1682 ucontrol->value.iec958.status[2] = 0xff;
1683 ucontrol->value.iec958.status[3] = 0xff;
1684 ucontrol->value.iec958.status[4] = 0xff;
1689 static int snd_ice1712_spdif_maskp_get(struct snd_kcontrol *kcontrol,
1690 struct snd_ctl_elem_value *ucontrol)
1692 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1693 if (ice->spdif.ops.default_get) {
1694 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1695 IEC958_AES0_PROFESSIONAL |
1696 IEC958_AES0_PRO_FS |
1697 IEC958_AES0_PRO_EMPHASIS;
1698 ucontrol->value.iec958.status[1] = IEC958_AES1_PRO_MODE;
1700 ucontrol->value.iec958.status[0] = 0xff;
1701 ucontrol->value.iec958.status[1] = 0xff;
1702 ucontrol->value.iec958.status[2] = 0xff;
1703 ucontrol->value.iec958.status[3] = 0xff;
1704 ucontrol->value.iec958.status[4] = 0xff;
1709 static struct snd_kcontrol_new snd_ice1712_spdif_maskc __devinitdata =
1711 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1712 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1713 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1714 .info = snd_ice1712_spdif_info,
1715 .get = snd_ice1712_spdif_maskc_get,
1718 static struct snd_kcontrol_new snd_ice1712_spdif_maskp __devinitdata =
1720 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1721 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1722 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1723 .info = snd_ice1712_spdif_info,
1724 .get = snd_ice1712_spdif_maskp_get,
1727 static int snd_ice1712_spdif_stream_get(struct snd_kcontrol *kcontrol,
1728 struct snd_ctl_elem_value *ucontrol)
1730 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1731 if (ice->spdif.ops.stream_get)
1732 ice->spdif.ops.stream_get(ice, ucontrol);
1736 static int snd_ice1712_spdif_stream_put(struct snd_kcontrol *kcontrol,
1737 struct snd_ctl_elem_value *ucontrol)
1739 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1740 if (ice->spdif.ops.stream_put)
1741 return ice->spdif.ops.stream_put(ice, ucontrol);
1745 static struct snd_kcontrol_new snd_ice1712_spdif_stream __devinitdata =
1747 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1748 SNDRV_CTL_ELEM_ACCESS_INACTIVE),
1749 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1750 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
1751 .info = snd_ice1712_spdif_info,
1752 .get = snd_ice1712_spdif_stream_get,
1753 .put = snd_ice1712_spdif_stream_put
1756 int snd_ice1712_gpio_info(struct snd_kcontrol *kcontrol,
1757 struct snd_ctl_elem_info *uinfo)
1759 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1761 uinfo->value.integer.min = 0;
1762 uinfo->value.integer.max = 1;
1766 int snd_ice1712_gpio_get(struct snd_kcontrol *kcontrol,
1767 struct snd_ctl_elem_value *ucontrol)
1769 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1770 unsigned char mask = kcontrol->private_value & 0xff;
1771 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1773 snd_ice1712_save_gpio_status(ice);
1774 ucontrol->value.integer.value[0] =
1775 (snd_ice1712_gpio_read(ice) & mask ? 1 : 0) ^ invert;
1776 snd_ice1712_restore_gpio_status(ice);
1780 int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
1781 struct snd_ctl_elem_value *ucontrol)
1783 struct snd_ice1712 *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(struct snd_kcontrol *kcontrol,
1804 struct snd_ctl_elem_info *uinfo)
1806 static char *texts[] = {
1809 "11025", /* 2: 10 */
1817 "64000", /* 10: 15 */
1818 "88200", /* 11: 11 */
1819 "96000", /* 12: 7 */
1820 "IEC958 Input", /* 13: -- */
1822 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1824 uinfo->value.enumerated.items = 14;
1825 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1826 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1827 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1831 static int snd_ice1712_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1832 struct snd_ctl_elem_value *ucontrol)
1834 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1835 static unsigned char xlate[16] = {
1836 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10
1840 spin_lock_irq(&ice->reg_lock);
1841 if (is_spdif_master(ice)) {
1842 ucontrol->value.enumerated.item[0] = 13;
1844 val = xlate[inb(ICEMT(ice, RATE)) & 15];
1849 ucontrol->value.enumerated.item[0] = val;
1851 spin_unlock_irq(&ice->reg_lock);
1855 static int snd_ice1712_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1856 struct snd_ctl_elem_value *ucontrol)
1858 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1859 static unsigned int xrate[13] = {
1860 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1861 32000, 44100, 48000, 64000, 88200, 96000
1866 spin_lock_irq(&ice->reg_lock);
1867 oval = inb(ICEMT(ice, RATE));
1868 if (ucontrol->value.enumerated.item[0] == 13) {
1869 outb(oval | ICE1712_SPDIF_MASTER, ICEMT(ice, RATE));
1871 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1872 spin_unlock_irq(&ice->reg_lock);
1873 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1874 spin_lock_irq(&ice->reg_lock);
1876 change = inb(ICEMT(ice, RATE)) != oval;
1877 spin_unlock_irq(&ice->reg_lock);
1879 if ((oval & ICE1712_SPDIF_MASTER) !=
1880 (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER))
1881 snd_ice1712_set_input_clock_source(ice, is_spdif_master(ice));
1886 static struct snd_kcontrol_new snd_ice1712_pro_internal_clock __devinitdata = {
1887 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1888 .name = "Multi Track Internal Clock",
1889 .info = snd_ice1712_pro_internal_clock_info,
1890 .get = snd_ice1712_pro_internal_clock_get,
1891 .put = snd_ice1712_pro_internal_clock_put
1894 static int snd_ice1712_pro_internal_clock_default_info(struct snd_kcontrol *kcontrol,
1895 struct snd_ctl_elem_info *uinfo)
1897 static char *texts[] = {
1900 "11025", /* 2: 10 */
1908 "64000", /* 10: 15 */
1909 "88200", /* 11: 11 */
1910 "96000", /* 12: 7 */
1911 // "IEC958 Input", /* 13: -- */
1913 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1915 uinfo->value.enumerated.items = 13;
1916 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1917 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1918 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1922 static int snd_ice1712_pro_internal_clock_default_get(struct snd_kcontrol *kcontrol,
1923 struct snd_ctl_elem_value *ucontrol)
1926 static unsigned int xrate[13] = {
1927 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1928 32000, 44100, 48000, 64000, 88200, 96000
1931 for (val = 0; val < 13; val++) {
1932 if (xrate[val] == PRO_RATE_DEFAULT)
1936 ucontrol->value.enumerated.item[0] = val;
1940 static int snd_ice1712_pro_internal_clock_default_put(struct snd_kcontrol *kcontrol,
1941 struct snd_ctl_elem_value *ucontrol)
1943 static unsigned int xrate[13] = {
1944 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1945 32000, 44100, 48000, 64000, 88200, 96000
1950 oval = PRO_RATE_DEFAULT;
1951 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1952 change = PRO_RATE_DEFAULT != oval;
1957 static struct snd_kcontrol_new snd_ice1712_pro_internal_clock_default __devinitdata = {
1958 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1959 .name = "Multi Track Internal Clock Default",
1960 .info = snd_ice1712_pro_internal_clock_default_info,
1961 .get = snd_ice1712_pro_internal_clock_default_get,
1962 .put = snd_ice1712_pro_internal_clock_default_put
1965 static int snd_ice1712_pro_rate_locking_info(struct snd_kcontrol *kcontrol,
1966 struct snd_ctl_elem_info *uinfo)
1968 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1970 uinfo->value.integer.min = 0;
1971 uinfo->value.integer.max = 1;
1975 static int snd_ice1712_pro_rate_locking_get(struct snd_kcontrol *kcontrol,
1976 struct snd_ctl_elem_value *ucontrol)
1978 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1982 static int snd_ice1712_pro_rate_locking_put(struct snd_kcontrol *kcontrol,
1983 struct snd_ctl_elem_value *ucontrol)
1985 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1986 int change = 0, nval;
1988 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1989 spin_lock_irq(&ice->reg_lock);
1990 change = PRO_RATE_LOCKED != nval;
1991 PRO_RATE_LOCKED = nval;
1992 spin_unlock_irq(&ice->reg_lock);
1996 static struct snd_kcontrol_new snd_ice1712_pro_rate_locking __devinitdata = {
1997 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1998 .name = "Multi Track Rate Locking",
1999 .info = snd_ice1712_pro_rate_locking_info,
2000 .get = snd_ice1712_pro_rate_locking_get,
2001 .put = snd_ice1712_pro_rate_locking_put
2004 static int snd_ice1712_pro_rate_reset_info(struct snd_kcontrol *kcontrol,
2005 struct snd_ctl_elem_info *uinfo)
2007 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2009 uinfo->value.integer.min = 0;
2010 uinfo->value.integer.max = 1;
2014 static int snd_ice1712_pro_rate_reset_get(struct snd_kcontrol *kcontrol,
2015 struct snd_ctl_elem_value *ucontrol)
2017 ucontrol->value.integer.value[0] = PRO_RATE_RESET;
2021 static int snd_ice1712_pro_rate_reset_put(struct snd_kcontrol *kcontrol,
2022 struct snd_ctl_elem_value *ucontrol)
2024 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2025 int change = 0, nval;
2027 nval = ucontrol->value.integer.value[0] ? 1 : 0;
2028 spin_lock_irq(&ice->reg_lock);
2029 change = PRO_RATE_RESET != nval;
2030 PRO_RATE_RESET = nval;
2031 spin_unlock_irq(&ice->reg_lock);
2035 static struct snd_kcontrol_new snd_ice1712_pro_rate_reset __devinitdata = {
2036 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2037 .name = "Multi Track Rate Reset",
2038 .info = snd_ice1712_pro_rate_reset_info,
2039 .get = snd_ice1712_pro_rate_reset_get,
2040 .put = snd_ice1712_pro_rate_reset_put
2046 static int snd_ice1712_pro_route_info(struct snd_kcontrol *kcontrol,
2047 struct snd_ctl_elem_info *uinfo)
2049 static char *texts[] = {
2051 "H/W In 0", "H/W In 1", "H/W In 2", "H/W In 3", /* 1-4 */
2052 "H/W In 4", "H/W In 5", "H/W In 6", "H/W In 7", /* 5-8 */
2053 "IEC958 In L", "IEC958 In R", /* 9-10 */
2054 "Digital Mixer", /* 11 - optional */
2057 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2059 uinfo->value.enumerated.items =
2060 snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
2061 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2062 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2063 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2067 static int snd_ice1712_pro_route_analog_get(struct snd_kcontrol *kcontrol,
2068 struct snd_ctl_elem_value *ucontrol)
2070 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2071 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2072 unsigned int val, cval;
2074 spin_lock_irq(&ice->reg_lock);
2075 val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2076 cval = inl(ICEMT(ice, ROUTE_CAPTURE));
2077 spin_unlock_irq(&ice->reg_lock);
2079 val >>= ((idx % 2) * 8) + ((idx / 2) * 2);
2081 cval >>= ((idx / 2) * 8) + ((idx % 2) * 4);
2082 if (val == 1 && idx < 2)
2083 ucontrol->value.enumerated.item[0] = 11;
2085 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2087 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2089 ucontrol->value.enumerated.item[0] = 0;
2093 static int snd_ice1712_pro_route_analog_put(struct snd_kcontrol *kcontrol,
2094 struct snd_ctl_elem_value *ucontrol)
2096 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2098 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2099 unsigned int val, old_val, nval;
2102 if (ucontrol->value.enumerated.item[0] >= 11)
2103 nval = idx < 2 ? 1 : 0; /* dig mixer (or pcm) */
2104 else if (ucontrol->value.enumerated.item[0] >= 9)
2105 nval = 3; /* spdif in */
2106 else if (ucontrol->value.enumerated.item[0] >= 1)
2107 nval = 2; /* analog in */
2110 shift = ((idx % 2) * 8) + ((idx / 2) * 2);
2111 spin_lock_irq(&ice->reg_lock);
2112 val = old_val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2113 val &= ~(0x03 << shift);
2114 val |= nval << shift;
2115 change = val != old_val;
2117 outw(val, ICEMT(ice, ROUTE_PSDOUT03));
2118 spin_unlock_irq(&ice->reg_lock);
2119 if (nval < 2) /* dig mixer of pcm */
2122 /* update CAPTURE */
2123 spin_lock_irq(&ice->reg_lock);
2124 val = old_val = inl(ICEMT(ice, ROUTE_CAPTURE));
2125 shift = ((idx / 2) * 8) + ((idx % 2) * 4);
2126 if (nval == 2) { /* analog in */
2127 nval = ucontrol->value.enumerated.item[0] - 1;
2128 val &= ~(0x07 << shift);
2129 val |= nval << shift;
2130 } else { /* spdif in */
2131 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2132 val &= ~(0x08 << shift);
2133 val |= nval << shift;
2135 if (val != old_val) {
2137 outl(val, ICEMT(ice, ROUTE_CAPTURE));
2139 spin_unlock_irq(&ice->reg_lock);
2143 static int snd_ice1712_pro_route_spdif_get(struct snd_kcontrol *kcontrol,
2144 struct snd_ctl_elem_value *ucontrol)
2146 struct snd_ice1712 *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(struct snd_kcontrol *kcontrol,
2164 struct snd_ctl_elem_value *ucontrol)
2166 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2168 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2169 unsigned int val, old_val, nval;
2172 spin_lock_irq(&ice->reg_lock);
2173 val = old_val = inw(ICEMT(ice, ROUTE_SPDOUT));
2174 if (ucontrol->value.enumerated.item[0] >= 11)
2176 else if (ucontrol->value.enumerated.item[0] >= 9)
2178 else if (ucontrol->value.enumerated.item[0] >= 1)
2183 val &= ~(0x03 << shift);
2184 val |= nval << shift;
2185 shift = idx * 4 + 8;
2187 nval = ucontrol->value.enumerated.item[0] - 1;
2188 val &= ~(0x07 << shift);
2189 val |= nval << shift;
2190 } else if (nval == 3) {
2191 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2192 val &= ~(0x08 << shift);
2193 val |= nval << shift;
2195 change = val != old_val;
2197 outw(val, ICEMT(ice, ROUTE_SPDOUT));
2198 spin_unlock_irq(&ice->reg_lock);
2202 static struct snd_kcontrol_new snd_ice1712_mixer_pro_analog_route __devinitdata = {
2203 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2204 .name = "H/W Playback Route",
2205 .info = snd_ice1712_pro_route_info,
2206 .get = snd_ice1712_pro_route_analog_get,
2207 .put = snd_ice1712_pro_route_analog_put,
2210 static struct snd_kcontrol_new snd_ice1712_mixer_pro_spdif_route __devinitdata = {
2211 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2212 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
2213 .info = snd_ice1712_pro_route_info,
2214 .get = snd_ice1712_pro_route_spdif_get,
2215 .put = snd_ice1712_pro_route_spdif_put,
2220 static int snd_ice1712_pro_volume_rate_info(struct snd_kcontrol *kcontrol,
2221 struct snd_ctl_elem_info *uinfo)
2223 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2225 uinfo->value.integer.min = 0;
2226 uinfo->value.integer.max = 255;
2230 static int snd_ice1712_pro_volume_rate_get(struct snd_kcontrol *kcontrol,
2231 struct snd_ctl_elem_value *ucontrol)
2233 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2235 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE));
2239 static int snd_ice1712_pro_volume_rate_put(struct snd_kcontrol *kcontrol,
2240 struct snd_ctl_elem_value *ucontrol)
2242 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2245 spin_lock_irq(&ice->reg_lock);
2246 change = inb(ICEMT(ice, MONITOR_RATE)) != ucontrol->value.integer.value[0];
2247 outb(ucontrol->value.integer.value[0], ICEMT(ice, MONITOR_RATE));
2248 spin_unlock_irq(&ice->reg_lock);
2252 static struct snd_kcontrol_new snd_ice1712_mixer_pro_volume_rate __devinitdata = {
2253 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2254 .name = "Multi Track Volume Rate",
2255 .info = snd_ice1712_pro_volume_rate_info,
2256 .get = snd_ice1712_pro_volume_rate_get,
2257 .put = snd_ice1712_pro_volume_rate_put
2260 static int snd_ice1712_pro_peak_info(struct snd_kcontrol *kcontrol,
2261 struct snd_ctl_elem_info *uinfo)
2263 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2265 uinfo->value.integer.min = 0;
2266 uinfo->value.integer.max = 255;
2270 static int snd_ice1712_pro_peak_get(struct snd_kcontrol *kcontrol,
2271 struct snd_ctl_elem_value *ucontrol)
2273 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2276 spin_lock_irq(&ice->reg_lock);
2277 for (idx = 0; idx < 22; idx++) {
2278 outb(idx, ICEMT(ice, MONITOR_PEAKINDEX));
2279 ucontrol->value.integer.value[idx] = inb(ICEMT(ice, MONITOR_PEAKDATA));
2281 spin_unlock_irq(&ice->reg_lock);
2285 static struct snd_kcontrol_new snd_ice1712_mixer_pro_peak __devinitdata = {
2286 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2287 .name = "Multi Track Peak",
2288 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2289 .info = snd_ice1712_pro_peak_info,
2290 .get = snd_ice1712_pro_peak_get
2298 * list of available boards
2300 static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
2301 snd_ice1712_hoontech_cards,
2302 snd_ice1712_delta_cards,
2303 snd_ice1712_ews_cards,
2307 static unsigned char __devinit snd_ice1712_read_i2c(struct snd_ice1712 *ice,
2313 outb(addr, ICEREG(ice, I2C_BYTE_ADDR));
2314 outb(dev & ~ICE1712_I2C_WRITE, ICEREG(ice, I2C_DEV_ADDR));
2315 while (t-- > 0 && (inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_BUSY)) ;
2316 return inb(ICEREG(ice, I2C_DATA));
2319 static int __devinit snd_ice1712_read_eeprom(struct snd_ice1712 *ice,
2320 const char *modelname)
2322 int dev = 0xa0; /* EEPROM device address */
2323 unsigned int i, size;
2324 struct snd_ice1712_card_info **tbl, *c;
2326 if (! modelname || ! *modelname) {
2327 ice->eeprom.subvendor = 0;
2328 if ((inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_EEPROM) != 0)
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 if (ice->eeprom.subvendor == 0 ||
2334 ice->eeprom.subvendor == (unsigned int)-1) {
2335 /* invalid subvendor from EEPROM, try the PCI subststem ID instead */
2337 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID, &vendor);
2338 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
2339 ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device);
2340 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
2341 printk(KERN_ERR "ice1712: No valid ID is found\n");
2346 for (tbl = card_tables; *tbl; tbl++) {
2347 for (c = *tbl; c->subvendor; c++) {
2348 if (modelname && c->model && ! strcmp(modelname, c->model)) {
2349 printk(KERN_INFO "ice1712: Using board model %s\n", c->name);
2350 ice->eeprom.subvendor = c->subvendor;
2351 } else if (c->subvendor != ice->eeprom.subvendor)
2353 if (! c->eeprom_size || ! c->eeprom_data)
2355 /* if the EEPROM is given by the driver, use it */
2356 snd_printdd("using the defined eeprom..\n");
2357 ice->eeprom.version = 1;
2358 ice->eeprom.size = c->eeprom_size + 6;
2359 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
2363 printk(KERN_WARNING "ice1712: No matching model found for ID 0x%x\n",
2364 ice->eeprom.subvendor);
2367 ice->eeprom.size = snd_ice1712_read_i2c(ice, dev, 0x04);
2368 if (ice->eeprom.size < 6)
2369 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */
2370 else if (ice->eeprom.size > 32) {
2371 snd_printk(KERN_ERR "invalid EEPROM (size = %i)\n", ice->eeprom.size);
2374 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05);
2375 if (ice->eeprom.version != 1) {
2376 snd_printk(KERN_ERR "invalid EEPROM version %i\n",
2377 ice->eeprom.version);
2380 size = ice->eeprom.size - 6;
2381 for (i = 0; i < size; i++)
2382 ice->eeprom.data[i] = snd_ice1712_read_i2c(ice, dev, i + 6);
2385 ice->eeprom.gpiomask = ice->eeprom.data[ICE_EEP1_GPIO_MASK];
2386 ice->eeprom.gpiostate = ice->eeprom.data[ICE_EEP1_GPIO_STATE];
2387 ice->eeprom.gpiodir = ice->eeprom.data[ICE_EEP1_GPIO_DIR];
2394 static int __devinit snd_ice1712_chip_init(struct snd_ice1712 *ice)
2396 outb(ICE1712_RESET | ICE1712_NATIVE, ICEREG(ice, CONTROL));
2398 outb(ICE1712_NATIVE, ICEREG(ice, CONTROL));
2400 if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DMX6FIRE &&
2402 /* Set eeprom value to limit active ADCs and DACs to 6;
2403 * Also disable AC97 as no hardware in standard 6fire card/box
2404 * Note: DXR extensions are not currently supported
2406 ice->eeprom.data[ICE_EEP1_CODEC] = 0x3a;
2407 pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]);
2408 pci_write_config_byte(ice->pci, 0x61, ice->eeprom.data[ICE_EEP1_ACLINK]);
2409 pci_write_config_byte(ice->pci, 0x62, ice->eeprom.data[ICE_EEP1_I2SID]);
2410 pci_write_config_byte(ice->pci, 0x63, ice->eeprom.data[ICE_EEP1_SPDIF]);
2411 if (ice->eeprom.subvendor != ICE1712_SUBDEVICE_STDSP24) {
2412 ice->gpio.write_mask = ice->eeprom.gpiomask;
2413 ice->gpio.direction = ice->eeprom.gpiodir;
2414 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK,
2415 ice->eeprom.gpiomask);
2416 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
2417 ice->eeprom.gpiodir);
2418 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA,
2419 ice->eeprom.gpiostate);
2421 ice->gpio.write_mask = 0xc0;
2422 ice->gpio.direction = 0xff;
2423 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, 0xc0);
2424 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, 0xff);
2425 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA,
2426 ICE1712_STDSP24_CLOCK_BIT);
2428 snd_ice1712_write(ice, ICE1712_IREG_PRO_POWERDOWN, 0);
2429 if (!(ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97)) {
2430 outb(ICE1712_AC97_WARM, ICEREG(ice, AC97_CMD));
2432 outb(0, ICEREG(ice, AC97_CMD));
2434 snd_ice1712_write(ice, ICE1712_IREG_CONSUMER_POWERDOWN, 0);
2436 snd_ice1712_set_pro_rate(ice, 48000, 1);
2441 int __devinit snd_ice1712_spdif_build_controls(struct snd_ice1712 *ice)
2444 struct snd_kcontrol *kctl;
2446 snd_assert(ice->pcm_pro != NULL, return -EIO);
2447 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_default, ice));
2450 kctl->id.device = ice->pcm_pro->device;
2451 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskc, ice));
2454 kctl->id.device = ice->pcm_pro->device;
2455 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskp, ice));
2458 kctl->id.device = ice->pcm_pro->device;
2459 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_stream, ice));
2462 kctl->id.device = ice->pcm_pro->device;
2463 ice->spdif.stream_ctl = kctl;
2468 static int __devinit snd_ice1712_build_controls(struct snd_ice1712 *ice)
2472 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_eeprom, ice));
2475 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock, ice));
2478 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock_default, ice));
2482 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_locking, ice));
2485 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_reset, ice));
2489 if (ice->num_total_dacs > 0) {
2490 struct snd_kcontrol_new tmp = snd_ice1712_mixer_pro_analog_route;
2491 tmp.count = ice->num_total_dacs;
2492 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2497 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice));
2501 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
2504 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice));
2511 static int snd_ice1712_free(struct snd_ice1712 *ice)
2515 /* mask all interrupts */
2516 outb(0xc0, ICEMT(ice, IRQ));
2517 outb(0xff, ICEREG(ice, IRQMASK));
2520 if (ice->irq >= 0) {
2521 synchronize_irq(ice->irq);
2522 free_irq(ice->irq, ice);
2525 pci_release_regions(ice->pci);
2526 snd_ice1712_akm4xxx_free(ice);
2527 pci_disable_device(ice->pci);
2532 static int snd_ice1712_dev_free(struct snd_device *device)
2534 struct snd_ice1712 *ice = device->device_data;
2535 return snd_ice1712_free(ice);
2538 static int __devinit snd_ice1712_create(struct snd_card *card,
2539 struct pci_dev *pci,
2540 const char *modelname,
2544 struct snd_ice1712 ** r_ice1712)
2546 struct snd_ice1712 *ice;
2548 static struct snd_device_ops ops = {
2549 .dev_free = snd_ice1712_dev_free,
2554 /* enable PCI device */
2555 if ((err = pci_enable_device(pci)) < 0)
2557 /* check, if we can restrict PCI DMA transfers to 28 bits */
2558 if (pci_set_dma_mask(pci, DMA_28BIT_MASK) < 0 ||
2559 pci_set_consistent_dma_mask(pci, DMA_28BIT_MASK) < 0) {
2560 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n");
2561 pci_disable_device(pci);
2565 ice = kzalloc(sizeof(*ice), GFP_KERNEL);
2567 pci_disable_device(pci);
2570 ice->omni = omni ? 1 : 0;
2571 if (cs8427_timeout < 1)
2573 else if (cs8427_timeout > 1000)
2574 cs8427_timeout = 1000;
2575 ice->cs8427_timeout = cs8427_timeout;
2576 ice->dxr_enable = dxr_enable;
2577 spin_lock_init(&ice->reg_lock);
2578 mutex_init(&ice->gpio_mutex);
2579 mutex_init(&ice->i2c_mutex);
2580 mutex_init(&ice->open_mutex);
2581 ice->gpio.set_mask = snd_ice1712_set_gpio_mask;
2582 ice->gpio.set_dir = snd_ice1712_set_gpio_dir;
2583 ice->gpio.set_data = snd_ice1712_set_gpio_data;
2584 ice->gpio.get_data = snd_ice1712_get_gpio_data;
2586 ice->spdif.cs8403_bits =
2587 ice->spdif.cs8403_stream_bits = (0x01 | /* consumer format */
2588 0x10 | /* no emphasis */
2589 0x20); /* PCM encoder/decoder */
2593 pci_set_master(pci);
2594 pci_write_config_word(ice->pci, 0x40, 0x807f);
2595 pci_write_config_word(ice->pci, 0x42, 0x0006);
2596 snd_ice1712_proc_init(ice);
2597 synchronize_irq(pci->irq);
2599 if ((err = pci_request_regions(pci, "ICE1712")) < 0) {
2601 pci_disable_device(pci);
2604 ice->port = pci_resource_start(pci, 0);
2605 ice->ddma_port = pci_resource_start(pci, 1);
2606 ice->dmapath_port = pci_resource_start(pci, 2);
2607 ice->profi_port = pci_resource_start(pci, 3);
2609 if (request_irq(pci->irq, snd_ice1712_interrupt, SA_INTERRUPT|SA_SHIRQ,
2611 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2612 snd_ice1712_free(ice);
2616 ice->irq = pci->irq;
2618 if (snd_ice1712_read_eeprom(ice, modelname) < 0) {
2619 snd_ice1712_free(ice);
2622 if (snd_ice1712_chip_init(ice) < 0) {
2623 snd_ice1712_free(ice);
2627 /* unmask used interrupts */
2628 outb(((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) == 0 ?
2629 ICE1712_IRQ_MPU2 : 0) |
2630 ((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97) ?
2631 ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0),
2632 ICEREG(ice, IRQMASK));
2633 outb(0x00, ICEMT(ice, IRQ));
2635 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2636 snd_ice1712_free(ice);
2640 snd_card_set_dev(card, &pci->dev);
2653 static struct snd_ice1712_card_info no_matched __devinitdata;
2655 static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2656 const struct pci_device_id *pci_id)
2659 struct snd_card *card;
2660 struct snd_ice1712 *ice;
2661 int pcm_dev = 0, err;
2662 struct snd_ice1712_card_info **tbl, *c;
2664 if (dev >= SNDRV_CARDS)
2671 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2675 strcpy(card->driver, "ICE1712");
2676 strcpy(card->shortname, "ICEnsemble ICE1712");
2678 if ((err = snd_ice1712_create(card, pci, model[dev], omni[dev],
2679 cs8427_timeout[dev], dxr_enable[dev],
2681 snd_card_free(card);
2685 for (tbl = card_tables; *tbl; tbl++) {
2686 for (c = *tbl; c->subvendor; c++) {
2687 if (c->subvendor == ice->eeprom.subvendor) {
2688 strcpy(card->shortname, c->name);
2689 if (c->driver) /* specific driver? */
2690 strcpy(card->driver, c->driver);
2692 if ((err = c->chip_init(ice)) < 0) {
2693 snd_card_free(card);
2704 if ((err = snd_ice1712_pcm_profi(ice, pcm_dev++, NULL)) < 0) {
2705 snd_card_free(card);
2709 if (ice_has_con_ac97(ice))
2710 if ((err = snd_ice1712_pcm(ice, pcm_dev++, NULL)) < 0) {
2711 snd_card_free(card);
2715 if ((err = snd_ice1712_ac97_mixer(ice)) < 0) {
2716 snd_card_free(card);
2720 if ((err = snd_ice1712_build_controls(ice)) < 0) {
2721 snd_card_free(card);
2725 if (c->build_controls) {
2726 if ((err = c->build_controls(ice)) < 0) {
2727 snd_card_free(card);
2732 if (ice_has_con_ac97(ice))
2733 if ((err = snd_ice1712_pcm_ds(ice, pcm_dev++, NULL)) < 0) {
2734 snd_card_free(card);
2738 if (! c->no_mpu401) {
2739 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2740 ICEREG(ice, MPU1_CTRL),
2741 (c->mpu401_1_info_flags |
2742 MPU401_INFO_INTEGRATED),
2744 &ice->rmidi[0])) < 0) {
2745 snd_card_free(card);
2748 if (c->mpu401_1_name)
2749 /* Prefered name available in card_info */
2750 snprintf(ice->rmidi[0]->name,
2751 sizeof(ice->rmidi[0]->name),
2752 "%s %d", c->mpu401_1_name, card->number);
2754 if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) {
2756 if ((err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712,
2757 ICEREG(ice, MPU2_CTRL),
2758 (c->mpu401_2_info_flags |
2759 MPU401_INFO_INTEGRATED),
2761 &ice->rmidi[1])) < 0) {
2762 snd_card_free(card);
2765 if (c->mpu401_2_name)
2766 /* Prefered name available in card_info */
2767 snprintf(ice->rmidi[1]->name,
2768 sizeof(ice->rmidi[1]->name),
2769 "%s %d", c->mpu401_2_name,
2774 snd_ice1712_set_input_clock_source(ice, 0);
2776 sprintf(card->longname, "%s at 0x%lx, irq %i",
2777 card->shortname, ice->port, ice->irq);
2779 if ((err = snd_card_register(card)) < 0) {
2780 snd_card_free(card);
2783 pci_set_drvdata(pci, card);
2788 static void __devexit snd_ice1712_remove(struct pci_dev *pci)
2790 snd_card_free(pci_get_drvdata(pci));
2791 pci_set_drvdata(pci, NULL);
2794 static struct pci_driver driver = {
2796 .id_table = snd_ice1712_ids,
2797 .probe = snd_ice1712_probe,
2798 .remove = __devexit_p(snd_ice1712_remove),
2801 static int __init alsa_card_ice1712_init(void)
2803 return pci_register_driver(&driver);
2806 static void __exit alsa_card_ice1712_exit(void)
2808 pci_unregister_driver(&driver);
2811 module_init(alsa_card_ice1712_init)
2812 module_exit(alsa_card_ice1712_exit)