2 * ALSA driver for ICEnsemble ICE1712 (Envy24)
4 * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 - spdif nonaudio consumer mode does not work (at least with my
31 * 2002.09.09 Takashi Iwai <tiwai@suse.de>
32 * split the code to several files. each low-level routine
33 * is stored in the local file and called from registration
34 * function from card_info struct.
36 * 2002.11.26 James Stafford <jstafford@ampltd.com>
37 * Added support for VT1724 (Envy24HT)
38 * I have left out support for 176.4 and 192 KHz for the moment.
39 * I also haven't done anything with the internal S/PDIF transmitter or the MPU-401
41 * 2003.02.20 Taksahi Iwai <tiwai@suse.de>
42 * Split vt1724 part to an independent driver.
43 * The GPIO is accessed through the callback functions now.
45 * 2004.03.31 Doug McLain <nostar@comcast.net>
46 * Added support for Event Electronics EZ8 card to hoontech.c.
50 #include <sound/driver.h>
52 #include <linux/delay.h>
53 #include <linux/interrupt.h>
54 #include <linux/init.h>
55 #include <linux/pci.h>
56 #include <linux/slab.h>
57 #include <linux/moduleparam.h>
58 #include <sound/core.h>
59 #include <sound/cs8427.h>
60 #include <sound/info.h>
61 #include <sound/mpu401.h>
62 #include <sound/initval.h>
64 #include <sound/asoundef.h>
68 /* lowlevel routines */
73 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
74 MODULE_DESCRIPTION("ICEnsemble ICE1712 (Envy24)");
75 MODULE_LICENSE("GPL");
76 MODULE_SUPPORTED_DEVICE("{"
80 "{ICEnsemble,Generic ICE1712},"
81 "{ICEnsemble,Generic Envy24}}");
83 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
84 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
85 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
86 static char *model[SNDRV_CARDS];
87 static int omni[SNDRV_CARDS]; /* Delta44 & 66 Omni I/O support */
88 static int cs8427_timeout[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 500}; /* CS8427 S/PDIF transciever reset timeout value in msec */
90 module_param_array(index, int, NULL, 0444);
91 MODULE_PARM_DESC(index, "Index value for ICE1712 soundcard.");
92 module_param_array(id, charp, NULL, 0444);
93 MODULE_PARM_DESC(id, "ID string for ICE1712 soundcard.");
94 module_param_array(enable, bool, NULL, 0444);
95 MODULE_PARM_DESC(enable, "Enable ICE1712 soundcard.");
96 module_param_array(omni, bool, NULL, 0444);
97 MODULE_PARM_DESC(omni, "Enable Midiman M-Audio Delta Omni I/O support.");
98 module_param_array(cs8427_timeout, int, NULL, 0444);
99 MODULE_PARM_DESC(cs8427_timeout, "Define reset timeout for cs8427 chip in msec resolution.");
100 module_param_array(model, charp, NULL, 0444);
101 MODULE_PARM_DESC(model, "Use the given board model.");
104 static struct pci_device_id snd_ice1712_ids[] = {
105 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_ICE_1712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* ICE1712 */
109 MODULE_DEVICE_TABLE(pci, snd_ice1712_ids);
111 static int snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice);
112 static int snd_ice1712_build_controls(struct snd_ice1712 *ice);
114 static int PRO_RATE_LOCKED;
115 static int PRO_RATE_RESET = 1;
116 static unsigned int PRO_RATE_DEFAULT = 44100;
122 /* check whether the clock mode is spdif-in */
123 static inline int is_spdif_master(struct snd_ice1712 *ice)
125 return (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER) ? 1 : 0;
128 static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
130 return is_spdif_master(ice) || PRO_RATE_LOCKED;
133 static inline void snd_ice1712_ds_write(struct snd_ice1712 * ice, u8 channel, u8 addr, u32 data)
135 outb((channel << 4) | addr, ICEDS(ice, INDEX));
136 outl(data, ICEDS(ice, DATA));
139 static inline u32 snd_ice1712_ds_read(struct snd_ice1712 * ice, u8 channel, u8 addr)
141 outb((channel << 4) | addr, ICEDS(ice, INDEX));
142 return inl(ICEDS(ice, DATA));
145 static void snd_ice1712_ac97_write(struct snd_ac97 *ac97,
149 struct snd_ice1712 *ice = ac97->private_data;
151 unsigned char old_cmd = 0;
153 for (tm = 0; tm < 0x10000; tm++) {
154 old_cmd = inb(ICEREG(ice, AC97_CMD));
155 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
157 if (!(old_cmd & ICE1712_AC97_READY))
161 outb(reg, ICEREG(ice, AC97_INDEX));
162 outw(val, ICEREG(ice, AC97_DATA));
163 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
164 outb(old_cmd | ICE1712_AC97_WRITE, ICEREG(ice, AC97_CMD));
165 for (tm = 0; tm < 0x10000; tm++)
166 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
170 static unsigned short snd_ice1712_ac97_read(struct snd_ac97 *ac97,
173 struct snd_ice1712 *ice = ac97->private_data;
175 unsigned char old_cmd = 0;
177 for (tm = 0; tm < 0x10000; tm++) {
178 old_cmd = inb(ICEREG(ice, AC97_CMD));
179 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
181 if (!(old_cmd & ICE1712_AC97_READY))
185 outb(reg, ICEREG(ice, AC97_INDEX));
186 outb(old_cmd | ICE1712_AC97_READ, ICEREG(ice, AC97_CMD));
187 for (tm = 0; tm < 0x10000; tm++)
188 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
190 if (tm >= 0x10000) /* timeout */
192 return inw(ICEREG(ice, AC97_DATA));
199 static void snd_ice1712_pro_ac97_write(struct snd_ac97 *ac97,
203 struct snd_ice1712 *ice = ac97->private_data;
205 unsigned char old_cmd = 0;
207 for (tm = 0; tm < 0x10000; tm++) {
208 old_cmd = inb(ICEMT(ice, AC97_CMD));
209 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
211 if (!(old_cmd & ICE1712_AC97_READY))
215 outb(reg, ICEMT(ice, AC97_INDEX));
216 outw(val, ICEMT(ice, AC97_DATA));
217 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
218 outb(old_cmd | ICE1712_AC97_WRITE, ICEMT(ice, AC97_CMD));
219 for (tm = 0; tm < 0x10000; tm++)
220 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
225 static unsigned short snd_ice1712_pro_ac97_read(struct snd_ac97 *ac97,
228 struct snd_ice1712 *ice = ac97->private_data;
230 unsigned char old_cmd = 0;
232 for (tm = 0; tm < 0x10000; tm++) {
233 old_cmd = inb(ICEMT(ice, AC97_CMD));
234 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
236 if (!(old_cmd & ICE1712_AC97_READY))
240 outb(reg, ICEMT(ice, AC97_INDEX));
241 outb(old_cmd | ICE1712_AC97_READ, ICEMT(ice, AC97_CMD));
242 for (tm = 0; tm < 0x10000; tm++)
243 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
245 if (tm >= 0x10000) /* timeout */
247 return inw(ICEMT(ice, AC97_DATA));
251 * consumer ac97 digital mix
253 static int snd_ice1712_digmix_route_ac97_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
255 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
257 uinfo->value.integer.min = 0;
258 uinfo->value.integer.max = 1;
262 static int snd_ice1712_digmix_route_ac97_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
264 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
266 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0;
270 static int snd_ice1712_digmix_route_ac97_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
272 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
273 unsigned char val, nval;
275 spin_lock_irq(&ice->reg_lock);
276 val = inb(ICEMT(ice, MONITOR_ROUTECTRL));
277 nval = val & ~ICE1712_ROUTE_AC97;
278 if (ucontrol->value.integer.value[0]) nval |= ICE1712_ROUTE_AC97;
279 outb(nval, ICEMT(ice, MONITOR_ROUTECTRL));
280 spin_unlock_irq(&ice->reg_lock);
284 static struct snd_kcontrol_new snd_ice1712_mixer_digmix_route_ac97 __devinitdata = {
285 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
286 .name = "Digital Mixer To AC97",
287 .info = snd_ice1712_digmix_route_ac97_info,
288 .get = snd_ice1712_digmix_route_ac97_get,
289 .put = snd_ice1712_digmix_route_ac97_put,
296 static void snd_ice1712_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
298 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, data);
299 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
302 static void snd_ice1712_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
304 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data);
305 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
308 static unsigned int snd_ice1712_get_gpio_data(struct snd_ice1712 *ice)
310 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
313 static void snd_ice1712_set_gpio_data(struct snd_ice1712 *ice, unsigned int val)
315 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, val);
316 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
327 * change the input clock selection
328 * spdif_clock = 1 - IEC958 input, 0 - Envy24
330 static int snd_ice1712_cs8427_set_input_clock(struct snd_ice1712 *ice, int spdif_clock)
332 unsigned char reg[2] = { 0x80 | 4, 0 }; /* CS8427 auto increment | register number 4 + data */
333 unsigned char val, nval;
336 snd_i2c_lock(ice->i2c);
337 if (snd_i2c_sendbytes(ice->cs8427, reg, 1) != 1) {
338 snd_i2c_unlock(ice->i2c);
341 if (snd_i2c_readbytes(ice->cs8427, &val, 1) != 1) {
342 snd_i2c_unlock(ice->i2c);
352 if (snd_i2c_sendbytes(ice->cs8427, reg, 2) != 2) {
358 snd_i2c_unlock(ice->i2c);
365 static void open_cs8427(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
367 snd_cs8427_iec958_active(ice->cs8427, 1);
370 static void close_cs8427(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
372 snd_cs8427_iec958_active(ice->cs8427, 0);
375 static void setup_cs8427(struct snd_ice1712 *ice, int rate)
377 snd_cs8427_iec958_pcm(ice->cs8427, rate);
381 * create and initialize callbacks for cs8427 interface
383 int __devinit snd_ice1712_init_cs8427(struct snd_ice1712 *ice, int addr)
387 if ((err = snd_cs8427_create(ice->i2c, addr,
388 (ice->cs8427_timeout * HZ) / 1000,
389 &ice->cs8427)) < 0) {
390 snd_printk(KERN_ERR "CS8427 initialization failed\n");
393 ice->spdif.ops.open = open_cs8427;
394 ice->spdif.ops.close = close_cs8427;
395 ice->spdif.ops.setup_rate = setup_cs8427;
404 static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
406 struct snd_ice1712 *ice = dev_id;
407 unsigned char status;
411 status = inb(ICEREG(ice, IRQSTAT));
415 if (status & ICE1712_IRQ_MPU1) {
417 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data, regs);
418 outb(ICE1712_IRQ_MPU1, ICEREG(ice, IRQSTAT));
419 status &= ~ICE1712_IRQ_MPU1;
421 if (status & ICE1712_IRQ_TIMER)
422 outb(ICE1712_IRQ_TIMER, ICEREG(ice, IRQSTAT));
423 if (status & ICE1712_IRQ_MPU2) {
425 snd_mpu401_uart_interrupt(irq, ice->rmidi[1]->private_data, regs);
426 outb(ICE1712_IRQ_MPU2, ICEREG(ice, IRQSTAT));
427 status &= ~ICE1712_IRQ_MPU2;
429 if (status & ICE1712_IRQ_PROPCM) {
430 unsigned char mtstat = inb(ICEMT(ice, IRQ));
431 if (mtstat & ICE1712_MULTI_PBKSTATUS) {
432 if (ice->playback_pro_substream)
433 snd_pcm_period_elapsed(ice->playback_pro_substream);
434 outb(ICE1712_MULTI_PBKSTATUS, ICEMT(ice, IRQ));
436 if (mtstat & ICE1712_MULTI_CAPSTATUS) {
437 if (ice->capture_pro_substream)
438 snd_pcm_period_elapsed(ice->capture_pro_substream);
439 outb(ICE1712_MULTI_CAPSTATUS, ICEMT(ice, IRQ));
442 if (status & ICE1712_IRQ_FM)
443 outb(ICE1712_IRQ_FM, ICEREG(ice, IRQSTAT));
444 if (status & ICE1712_IRQ_PBKDS) {
447 struct snd_pcm_substream *substream;
448 pbkstatus = inw(ICEDS(ice, INTSTAT));
449 //printk("pbkstatus = 0x%x\n", pbkstatus);
450 for (idx = 0; idx < 6; idx++) {
451 if ((pbkstatus & (3 << (idx * 2))) == 0)
453 if ((substream = ice->playback_con_substream_ds[idx]) != NULL)
454 snd_pcm_period_elapsed(substream);
455 outw(3 << (idx * 2), ICEDS(ice, INTSTAT));
457 outb(ICE1712_IRQ_PBKDS, ICEREG(ice, IRQSTAT));
459 if (status & ICE1712_IRQ_CONCAP) {
460 if (ice->capture_con_substream)
461 snd_pcm_period_elapsed(ice->capture_con_substream);
462 outb(ICE1712_IRQ_CONCAP, ICEREG(ice, IRQSTAT));
464 if (status & ICE1712_IRQ_CONPBK) {
465 if (ice->playback_con_substream)
466 snd_pcm_period_elapsed(ice->playback_con_substream);
467 outb(ICE1712_IRQ_CONPBK, ICEREG(ice, IRQSTAT));
470 return IRQ_RETVAL(handled);
478 static int snd_ice1712_hw_params(struct snd_pcm_substream *substream,
479 struct snd_pcm_hw_params *hw_params)
481 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
484 static int snd_ice1712_hw_free(struct snd_pcm_substream *substream)
486 return snd_pcm_lib_free_pages(substream);
490 * PCM part - consumer I/O
493 static int snd_ice1712_playback_trigger(struct snd_pcm_substream *substream,
496 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
500 spin_lock(&ice->reg_lock);
501 tmp = snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL);
502 if (cmd == SNDRV_PCM_TRIGGER_START) {
504 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
506 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
508 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
513 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
514 spin_unlock(&ice->reg_lock);
518 static int snd_ice1712_playback_ds_trigger(struct snd_pcm_substream *substream,
521 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
525 spin_lock(&ice->reg_lock);
526 tmp = snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL);
527 if (cmd == SNDRV_PCM_TRIGGER_START) {
529 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
531 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
533 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
538 snd_ice1712_ds_write(ice, substream->number * 2, ICE1712_DSC_CONTROL, tmp);
539 spin_unlock(&ice->reg_lock);
543 static int snd_ice1712_capture_trigger(struct snd_pcm_substream *substream,
546 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
550 spin_lock(&ice->reg_lock);
551 tmp = snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL);
552 if (cmd == SNDRV_PCM_TRIGGER_START) {
554 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
559 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
560 spin_unlock(&ice->reg_lock);
564 static int snd_ice1712_playback_prepare(struct snd_pcm_substream *substream)
566 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
567 struct snd_pcm_runtime *runtime = substream->runtime;
568 u32 period_size, buf_size, rate, tmp;
570 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
571 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
573 if (snd_pcm_format_width(runtime->format) == 16)
575 if (runtime->channels == 2)
577 rate = (runtime->rate * 8192) / 375;
578 if (rate > 0x000fffff)
580 spin_lock_irq(&ice->reg_lock);
581 outb(0, ice->ddma_port + 15);
582 outb(ICE1712_DMA_MODE_WRITE | ICE1712_DMA_AUTOINIT, ice->ddma_port + 0x0b);
583 outl(runtime->dma_addr, ice->ddma_port + 0);
584 outw(buf_size, ice->ddma_port + 4);
585 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_LO, rate & 0xff);
586 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_MID, (rate >> 8) & 0xff);
587 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_HI, (rate >> 16) & 0xff);
588 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
589 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_LO, period_size & 0xff);
590 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_HI, period_size >> 8);
591 snd_ice1712_write(ice, ICE1712_IREG_PBK_LEFT, 0);
592 snd_ice1712_write(ice, ICE1712_IREG_PBK_RIGHT, 0);
593 spin_unlock_irq(&ice->reg_lock);
597 static int snd_ice1712_playback_ds_prepare(struct snd_pcm_substream *substream)
599 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
600 struct snd_pcm_runtime *runtime = substream->runtime;
601 u32 period_size, buf_size, rate, tmp, chn;
603 period_size = snd_pcm_lib_period_bytes(substream) - 1;
604 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
606 if (snd_pcm_format_width(runtime->format) == 16)
608 if (runtime->channels == 2)
610 rate = (runtime->rate * 8192) / 375;
611 if (rate > 0x000fffff)
613 ice->playback_con_active_buf[substream->number] = 0;
614 ice->playback_con_virt_addr[substream->number] = runtime->dma_addr;
615 chn = substream->number * 2;
616 spin_lock_irq(&ice->reg_lock);
617 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR0, runtime->dma_addr);
618 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT0, period_size);
619 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR1, runtime->dma_addr + (runtime->periods > 1 ? period_size + 1 : 0));
620 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT1, period_size);
621 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_RATE, rate);
622 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_VOLUME, 0);
623 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_CONTROL, tmp);
624 if (runtime->channels == 2) {
625 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_RATE, rate);
626 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_VOLUME, 0);
628 spin_unlock_irq(&ice->reg_lock);
632 static int snd_ice1712_capture_prepare(struct snd_pcm_substream *substream)
634 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
635 struct snd_pcm_runtime *runtime = substream->runtime;
636 u32 period_size, buf_size;
639 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
640 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
642 if (snd_pcm_format_width(runtime->format) == 16)
644 if (runtime->channels == 2)
646 spin_lock_irq(&ice->reg_lock);
647 outl(ice->capture_con_virt_addr = runtime->dma_addr, ICEREG(ice, CONCAP_ADDR));
648 outw(buf_size, ICEREG(ice, CONCAP_COUNT));
649 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_HI, period_size >> 8);
650 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_LO, period_size & 0xff);
651 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
652 spin_unlock_irq(&ice->reg_lock);
653 snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
657 static snd_pcm_uframes_t snd_ice1712_playback_pointer(struct snd_pcm_substream *substream)
659 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
660 struct snd_pcm_runtime *runtime = substream->runtime;
663 if (!(snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL) & 1))
665 ptr = runtime->buffer_size - inw(ice->ddma_port + 4);
666 if (ptr == runtime->buffer_size)
668 return bytes_to_frames(substream->runtime, ptr);
671 static snd_pcm_uframes_t snd_ice1712_playback_ds_pointer(struct snd_pcm_substream *substream)
673 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
677 if (!(snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL) & 1))
679 if (ice->playback_con_active_buf[substream->number])
680 addr = ICE1712_DSC_ADDR1;
682 addr = ICE1712_DSC_ADDR0;
683 ptr = snd_ice1712_ds_read(ice, substream->number * 2, addr) -
684 ice->playback_con_virt_addr[substream->number];
685 if (ptr == substream->runtime->buffer_size)
687 return bytes_to_frames(substream->runtime, ptr);
690 static snd_pcm_uframes_t snd_ice1712_capture_pointer(struct snd_pcm_substream *substream)
692 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
695 if (!(snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL) & 1))
697 ptr = inl(ICEREG(ice, CONCAP_ADDR)) - ice->capture_con_virt_addr;
698 if (ptr == substream->runtime->buffer_size)
700 return bytes_to_frames(substream->runtime, ptr);
703 static struct snd_pcm_hardware snd_ice1712_playback =
705 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
706 SNDRV_PCM_INFO_BLOCK_TRANSFER |
707 SNDRV_PCM_INFO_MMAP_VALID |
708 SNDRV_PCM_INFO_PAUSE),
709 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
710 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
715 .buffer_bytes_max = (64*1024),
716 .period_bytes_min = 64,
717 .period_bytes_max = (64*1024),
723 static struct snd_pcm_hardware snd_ice1712_playback_ds =
725 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
726 SNDRV_PCM_INFO_BLOCK_TRANSFER |
727 SNDRV_PCM_INFO_MMAP_VALID |
728 SNDRV_PCM_INFO_PAUSE),
729 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
730 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
735 .buffer_bytes_max = (128*1024),
736 .period_bytes_min = 64,
737 .period_bytes_max = (128*1024),
743 static struct snd_pcm_hardware snd_ice1712_capture =
745 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
746 SNDRV_PCM_INFO_BLOCK_TRANSFER |
747 SNDRV_PCM_INFO_MMAP_VALID),
748 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
749 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
754 .buffer_bytes_max = (64*1024),
755 .period_bytes_min = 64,
756 .period_bytes_max = (64*1024),
762 static int snd_ice1712_playback_open(struct snd_pcm_substream *substream)
764 struct snd_pcm_runtime *runtime = substream->runtime;
765 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
767 ice->playback_con_substream = substream;
768 runtime->hw = snd_ice1712_playback;
772 static int snd_ice1712_playback_ds_open(struct snd_pcm_substream *substream)
774 struct snd_pcm_runtime *runtime = substream->runtime;
775 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
778 ice->playback_con_substream_ds[substream->number] = substream;
779 runtime->hw = snd_ice1712_playback_ds;
780 spin_lock_irq(&ice->reg_lock);
781 tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2));
782 outw(tmp, ICEDS(ice, INTMASK));
783 spin_unlock_irq(&ice->reg_lock);
787 static int snd_ice1712_capture_open(struct snd_pcm_substream *substream)
789 struct snd_pcm_runtime *runtime = substream->runtime;
790 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
792 ice->capture_con_substream = substream;
793 runtime->hw = snd_ice1712_capture;
794 runtime->hw.rates = ice->ac97->rates[AC97_RATES_ADC];
795 if (!(runtime->hw.rates & SNDRV_PCM_RATE_8000))
796 runtime->hw.rate_min = 48000;
800 static int snd_ice1712_playback_close(struct snd_pcm_substream *substream)
802 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
804 ice->playback_con_substream = NULL;
808 static int snd_ice1712_playback_ds_close(struct snd_pcm_substream *substream)
810 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
813 spin_lock_irq(&ice->reg_lock);
814 tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2));
815 outw(tmp, ICEDS(ice, INTMASK));
816 spin_unlock_irq(&ice->reg_lock);
817 ice->playback_con_substream_ds[substream->number] = NULL;
821 static int snd_ice1712_capture_close(struct snd_pcm_substream *substream)
823 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
825 ice->capture_con_substream = NULL;
829 static struct snd_pcm_ops snd_ice1712_playback_ops = {
830 .open = snd_ice1712_playback_open,
831 .close = snd_ice1712_playback_close,
832 .ioctl = snd_pcm_lib_ioctl,
833 .hw_params = snd_ice1712_hw_params,
834 .hw_free = snd_ice1712_hw_free,
835 .prepare = snd_ice1712_playback_prepare,
836 .trigger = snd_ice1712_playback_trigger,
837 .pointer = snd_ice1712_playback_pointer,
840 static struct snd_pcm_ops snd_ice1712_playback_ds_ops = {
841 .open = snd_ice1712_playback_ds_open,
842 .close = snd_ice1712_playback_ds_close,
843 .ioctl = snd_pcm_lib_ioctl,
844 .hw_params = snd_ice1712_hw_params,
845 .hw_free = snd_ice1712_hw_free,
846 .prepare = snd_ice1712_playback_ds_prepare,
847 .trigger = snd_ice1712_playback_ds_trigger,
848 .pointer = snd_ice1712_playback_ds_pointer,
851 static struct snd_pcm_ops snd_ice1712_capture_ops = {
852 .open = snd_ice1712_capture_open,
853 .close = snd_ice1712_capture_close,
854 .ioctl = snd_pcm_lib_ioctl,
855 .hw_params = snd_ice1712_hw_params,
856 .hw_free = snd_ice1712_hw_free,
857 .prepare = snd_ice1712_capture_prepare,
858 .trigger = snd_ice1712_capture_trigger,
859 .pointer = snd_ice1712_capture_pointer,
862 static int __devinit snd_ice1712_pcm(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
869 err = snd_pcm_new(ice->card, "ICE1712 consumer", device, 1, 1, &pcm);
873 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ops);
874 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_ops);
876 pcm->private_data = ice;
878 strcpy(pcm->name, "ICE1712 consumer");
881 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
882 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
887 printk(KERN_WARNING "Consumer PCM code does not work well at the moment --jk\n");
892 static int __devinit snd_ice1712_pcm_ds(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
899 err = snd_pcm_new(ice->card, "ICE1712 consumer (DS)", device, 6, 0, &pcm);
903 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ds_ops);
905 pcm->private_data = ice;
907 strcpy(pcm->name, "ICE1712 consumer (DS)");
910 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
911 snd_dma_pci_data(ice->pci), 64*1024, 128*1024);
920 * PCM code - professional part (multitrack)
923 static unsigned int rates[] = { 8000, 9600, 11025, 12000, 16000, 22050, 24000,
924 32000, 44100, 48000, 64000, 88200, 96000 };
926 static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
927 .count = ARRAY_SIZE(rates),
932 static int snd_ice1712_pro_trigger(struct snd_pcm_substream *substream,
935 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
937 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
938 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
942 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
944 what = ICE1712_PLAYBACK_PAUSE;
945 snd_pcm_trigger_done(substream, substream);
946 spin_lock(&ice->reg_lock);
947 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
948 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
952 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
953 spin_unlock(&ice->reg_lock);
956 case SNDRV_PCM_TRIGGER_START:
957 case SNDRV_PCM_TRIGGER_STOP:
959 unsigned int what = 0;
961 struct list_head *pos;
962 struct snd_pcm_substream *s;
964 snd_pcm_group_for_each(pos, substream) {
965 s = snd_pcm_group_substream_entry(pos);
966 if (s == ice->playback_pro_substream) {
967 what |= ICE1712_PLAYBACK_START;
968 snd_pcm_trigger_done(s, substream);
969 } else if (s == ice->capture_pro_substream) {
970 what |= ICE1712_CAPTURE_START_SHADOW;
971 snd_pcm_trigger_done(s, substream);
974 spin_lock(&ice->reg_lock);
975 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
976 if (cmd == SNDRV_PCM_TRIGGER_START)
980 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
981 spin_unlock(&ice->reg_lock);
992 static void snd_ice1712_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate, int force)
995 unsigned char val, old;
999 case 8000: val = 6; break;
1000 case 9600: val = 3; break;
1001 case 11025: val = 10; break;
1002 case 12000: val = 2; break;
1003 case 16000: val = 5; break;
1004 case 22050: val = 9; break;
1005 case 24000: val = 1; break;
1006 case 32000: val = 4; break;
1007 case 44100: val = 8; break;
1008 case 48000: val = 0; break;
1009 case 64000: val = 15; break;
1010 case 88200: val = 11; break;
1011 case 96000: val = 7; break;
1019 spin_lock_irqsave(&ice->reg_lock, flags);
1020 if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
1021 ICE1712_PLAYBACK_PAUSE|
1022 ICE1712_PLAYBACK_START)) {
1024 spin_unlock_irqrestore(&ice->reg_lock, flags);
1027 if (!force && is_pro_rate_locked(ice))
1030 old = inb(ICEMT(ice, RATE));
1031 if (!force && old == val)
1033 outb(val, ICEMT(ice, RATE));
1034 spin_unlock_irqrestore(&ice->reg_lock, flags);
1036 if (ice->gpio.set_pro_rate)
1037 ice->gpio.set_pro_rate(ice, rate);
1038 for (i = 0; i < ice->akm_codecs; i++) {
1039 if (ice->akm[i].ops.set_rate_val)
1040 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
1042 if (ice->spdif.ops.setup_rate)
1043 ice->spdif.ops.setup_rate(ice, rate);
1046 static int snd_ice1712_playback_pro_prepare(struct snd_pcm_substream *substream)
1048 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1050 ice->playback_pro_size = snd_pcm_lib_buffer_bytes(substream);
1051 spin_lock_irq(&ice->reg_lock);
1052 outl(substream->runtime->dma_addr, ICEMT(ice, PLAYBACK_ADDR));
1053 outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));
1054 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT));
1055 spin_unlock_irq(&ice->reg_lock);
1060 static int snd_ice1712_playback_pro_hw_params(struct snd_pcm_substream *substream,
1061 struct snd_pcm_hw_params *hw_params)
1063 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1065 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1066 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1069 static int snd_ice1712_capture_pro_prepare(struct snd_pcm_substream *substream)
1071 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1073 ice->capture_pro_size = snd_pcm_lib_buffer_bytes(substream);
1074 spin_lock_irq(&ice->reg_lock);
1075 outl(substream->runtime->dma_addr, ICEMT(ice, CAPTURE_ADDR));
1076 outw((ice->capture_pro_size >> 2) - 1, ICEMT(ice, CAPTURE_SIZE));
1077 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, CAPTURE_COUNT));
1078 spin_unlock_irq(&ice->reg_lock);
1082 static int snd_ice1712_capture_pro_hw_params(struct snd_pcm_substream *substream,
1083 struct snd_pcm_hw_params *hw_params)
1085 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1087 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1088 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1091 static snd_pcm_uframes_t snd_ice1712_playback_pro_pointer(struct snd_pcm_substream *substream)
1093 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1096 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_PLAYBACK_START))
1098 ptr = ice->playback_pro_size - (inw(ICEMT(ice, PLAYBACK_SIZE)) << 2);
1099 if (ptr == substream->runtime->buffer_size)
1101 return bytes_to_frames(substream->runtime, ptr);
1104 static snd_pcm_uframes_t snd_ice1712_capture_pro_pointer(struct snd_pcm_substream *substream)
1106 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1109 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_CAPTURE_START_SHADOW))
1111 ptr = ice->capture_pro_size - (inw(ICEMT(ice, CAPTURE_SIZE)) << 2);
1112 if (ptr == substream->runtime->buffer_size)
1114 return bytes_to_frames(substream->runtime, ptr);
1117 static struct snd_pcm_hardware snd_ice1712_playback_pro =
1119 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1120 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1121 SNDRV_PCM_INFO_MMAP_VALID |
1122 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1123 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1124 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1129 .buffer_bytes_max = (256*1024),
1130 .period_bytes_min = 10 * 4 * 2,
1131 .period_bytes_max = 131040,
1133 .periods_max = 1024,
1137 static struct snd_pcm_hardware snd_ice1712_capture_pro =
1139 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1140 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1141 SNDRV_PCM_INFO_MMAP_VALID |
1142 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1143 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1144 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1149 .buffer_bytes_max = (256*1024),
1150 .period_bytes_min = 12 * 4 * 2,
1151 .period_bytes_max = 131040,
1153 .periods_max = 1024,
1157 static int snd_ice1712_playback_pro_open(struct snd_pcm_substream *substream)
1159 struct snd_pcm_runtime *runtime = substream->runtime;
1160 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1162 ice->playback_pro_substream = substream;
1163 runtime->hw = snd_ice1712_playback_pro;
1164 snd_pcm_set_sync(substream);
1165 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1166 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1168 if (ice->spdif.ops.open)
1169 ice->spdif.ops.open(ice, substream);
1174 static int snd_ice1712_capture_pro_open(struct snd_pcm_substream *substream)
1176 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1177 struct snd_pcm_runtime *runtime = substream->runtime;
1179 ice->capture_pro_substream = substream;
1180 runtime->hw = snd_ice1712_capture_pro;
1181 snd_pcm_set_sync(substream);
1182 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1183 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1187 static int snd_ice1712_playback_pro_close(struct snd_pcm_substream *substream)
1189 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1192 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1193 ice->playback_pro_substream = NULL;
1194 if (ice->spdif.ops.close)
1195 ice->spdif.ops.close(ice, substream);
1200 static int snd_ice1712_capture_pro_close(struct snd_pcm_substream *substream)
1202 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1205 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1206 ice->capture_pro_substream = NULL;
1210 static struct snd_pcm_ops snd_ice1712_playback_pro_ops = {
1211 .open = snd_ice1712_playback_pro_open,
1212 .close = snd_ice1712_playback_pro_close,
1213 .ioctl = snd_pcm_lib_ioctl,
1214 .hw_params = snd_ice1712_playback_pro_hw_params,
1215 .hw_free = snd_ice1712_hw_free,
1216 .prepare = snd_ice1712_playback_pro_prepare,
1217 .trigger = snd_ice1712_pro_trigger,
1218 .pointer = snd_ice1712_playback_pro_pointer,
1221 static struct snd_pcm_ops snd_ice1712_capture_pro_ops = {
1222 .open = snd_ice1712_capture_pro_open,
1223 .close = snd_ice1712_capture_pro_close,
1224 .ioctl = snd_pcm_lib_ioctl,
1225 .hw_params = snd_ice1712_capture_pro_hw_params,
1226 .hw_free = snd_ice1712_hw_free,
1227 .prepare = snd_ice1712_capture_pro_prepare,
1228 .trigger = snd_ice1712_pro_trigger,
1229 .pointer = snd_ice1712_capture_pro_pointer,
1232 static int __devinit snd_ice1712_pcm_profi(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
1234 struct snd_pcm *pcm;
1239 err = snd_pcm_new(ice->card, "ICE1712 multi", device, 1, 1, &pcm);
1243 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_pro_ops);
1244 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_pro_ops);
1246 pcm->private_data = ice;
1247 pcm->info_flags = 0;
1248 strcpy(pcm->name, "ICE1712 multi");
1250 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1251 snd_dma_pci_data(ice->pci), 256*1024, 256*1024);
1258 /* assign channels to iec958 */
1259 err = snd_cs8427_iec958_build(ice->cs8427,
1260 pcm->streams[0].substream,
1261 pcm->streams[1].substream);
1266 if ((err = snd_ice1712_build_pro_mixer(ice)) < 0)
1275 static void snd_ice1712_update_volume(struct snd_ice1712 *ice, int index)
1277 unsigned int vol = ice->pro_volumes[index];
1278 unsigned short val = 0;
1280 val |= (vol & 0x8000) == 0 ? (96 - (vol & 0x7f)) : 0x7f;
1281 val |= ((vol & 0x80000000) == 0 ? (96 - ((vol >> 16) & 0x7f)) : 0x7f) << 8;
1282 outb(index, ICEMT(ice, MONITOR_INDEX));
1283 outw(val, ICEMT(ice, MONITOR_VOLUME));
1286 static int snd_ice1712_pro_mixer_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1288 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1290 uinfo->value.integer.min = 0;
1291 uinfo->value.integer.max = 1;
1295 static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1297 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1298 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1300 spin_lock_irq(&ice->reg_lock);
1301 ucontrol->value.integer.value[0] = !((ice->pro_volumes[index] >> 15) & 1);
1302 ucontrol->value.integer.value[1] = !((ice->pro_volumes[index] >> 31) & 1);
1303 spin_unlock_irq(&ice->reg_lock);
1307 static int snd_ice1712_pro_mixer_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1309 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1310 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1311 unsigned int nval, change;
1313 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
1314 (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
1315 spin_lock_irq(&ice->reg_lock);
1316 nval |= ice->pro_volumes[index] & ~0x80008000;
1317 change = nval != ice->pro_volumes[index];
1318 ice->pro_volumes[index] = nval;
1319 snd_ice1712_update_volume(ice, index);
1320 spin_unlock_irq(&ice->reg_lock);
1324 static int snd_ice1712_pro_mixer_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1326 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1328 uinfo->value.integer.min = 0;
1329 uinfo->value.integer.max = 96;
1333 static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1335 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1336 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1338 spin_lock_irq(&ice->reg_lock);
1339 ucontrol->value.integer.value[0] = (ice->pro_volumes[index] >> 0) & 127;
1340 ucontrol->value.integer.value[1] = (ice->pro_volumes[index] >> 16) & 127;
1341 spin_unlock_irq(&ice->reg_lock);
1345 static int snd_ice1712_pro_mixer_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1347 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1348 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1349 unsigned int nval, change;
1351 nval = (ucontrol->value.integer.value[0] & 127) |
1352 ((ucontrol->value.integer.value[1] & 127) << 16);
1353 spin_lock_irq(&ice->reg_lock);
1354 nval |= ice->pro_volumes[index] & ~0x007f007f;
1355 change = nval != ice->pro_volumes[index];
1356 ice->pro_volumes[index] = nval;
1357 snd_ice1712_update_volume(ice, index);
1358 spin_unlock_irq(&ice->reg_lock);
1363 static struct snd_kcontrol_new snd_ice1712_multi_playback_ctrls[] __devinitdata = {
1365 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1366 .name = "Multi Playback Switch",
1367 .info = snd_ice1712_pro_mixer_switch_info,
1368 .get = snd_ice1712_pro_mixer_switch_get,
1369 .put = snd_ice1712_pro_mixer_switch_put,
1374 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1375 .name = "Multi Playback Volume",
1376 .info = snd_ice1712_pro_mixer_volume_info,
1377 .get = snd_ice1712_pro_mixer_volume_get,
1378 .put = snd_ice1712_pro_mixer_volume_put,
1384 static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_switch __devinitdata = {
1385 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1386 .name = "H/W Multi Capture Switch",
1387 .info = snd_ice1712_pro_mixer_switch_info,
1388 .get = snd_ice1712_pro_mixer_switch_get,
1389 .put = snd_ice1712_pro_mixer_switch_put,
1390 .private_value = 10,
1393 static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_switch __devinitdata = {
1394 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1395 .name = SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE,SWITCH),
1396 .info = snd_ice1712_pro_mixer_switch_info,
1397 .get = snd_ice1712_pro_mixer_switch_get,
1398 .put = snd_ice1712_pro_mixer_switch_put,
1399 .private_value = 18,
1403 static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_volume __devinitdata = {
1404 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1405 .name = "H/W Multi Capture Volume",
1406 .info = snd_ice1712_pro_mixer_volume_info,
1407 .get = snd_ice1712_pro_mixer_volume_get,
1408 .put = snd_ice1712_pro_mixer_volume_put,
1409 .private_value = 10,
1412 static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_volume __devinitdata = {
1413 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1414 .name = SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE,VOLUME),
1415 .info = snd_ice1712_pro_mixer_volume_info,
1416 .get = snd_ice1712_pro_mixer_volume_get,
1417 .put = snd_ice1712_pro_mixer_volume_put,
1418 .private_value = 18,
1422 static int __devinit snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice)
1424 struct snd_card *card = ice->card;
1428 /* multi-channel mixer */
1429 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_multi_playback_ctrls); idx++) {
1430 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_playback_ctrls[idx], ice));
1435 if (ice->num_total_adcs > 0) {
1436 struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_switch;
1437 tmp.count = ice->num_total_adcs;
1438 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1443 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_switch, ice));
1447 if (ice->num_total_adcs > 0) {
1448 struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_volume;
1449 tmp.count = ice->num_total_adcs;
1450 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1455 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_volume, ice));
1459 /* initialize volumes */
1460 for (idx = 0; idx < 10; idx++) {
1461 ice->pro_volumes[idx] = 0x80008000; /* mute */
1462 snd_ice1712_update_volume(ice, idx);
1464 for (idx = 10; idx < 10 + ice->num_total_adcs; idx++) {
1465 ice->pro_volumes[idx] = 0x80008000; /* mute */
1466 snd_ice1712_update_volume(ice, idx);
1468 for (idx = 18; idx < 20; idx++) {
1469 ice->pro_volumes[idx] = 0x80008000; /* mute */
1470 snd_ice1712_update_volume(ice, idx);
1475 static void snd_ice1712_mixer_free_ac97(struct snd_ac97 *ac97)
1477 struct snd_ice1712 *ice = ac97->private_data;
1481 static int __devinit snd_ice1712_ac97_mixer(struct snd_ice1712 * ice)
1483 int err, bus_num = 0;
1484 struct snd_ac97_template ac97;
1485 struct snd_ac97_bus *pbus;
1486 static struct snd_ac97_bus_ops con_ops = {
1487 .write = snd_ice1712_ac97_write,
1488 .read = snd_ice1712_ac97_read,
1490 static struct snd_ac97_bus_ops pro_ops = {
1491 .write = snd_ice1712_pro_ac97_write,
1492 .read = snd_ice1712_pro_ac97_read,
1495 if (ice_has_con_ac97(ice)) {
1496 if ((err = snd_ac97_bus(ice->card, bus_num++, &con_ops, NULL, &pbus)) < 0)
1498 memset(&ac97, 0, sizeof(ac97));
1499 ac97.private_data = ice;
1500 ac97.private_free = snd_ice1712_mixer_free_ac97;
1501 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1502 printk(KERN_WARNING "ice1712: cannot initialize ac97 for consumer, skipped\n");
1504 if ((err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice))) < 0)
1510 if (! (ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) {
1511 if ((err = snd_ac97_bus(ice->card, bus_num, &pro_ops, NULL, &pbus)) < 0)
1513 memset(&ac97, 0, sizeof(ac97));
1514 ac97.private_data = ice;
1515 ac97.private_free = snd_ice1712_mixer_free_ac97;
1516 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1517 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1521 /* I2S mixer only */
1522 strcat(ice->card->mixername, "ICE1712 - multitrack");
1530 static inline unsigned int eeprom_double(struct snd_ice1712 *ice, int idx)
1532 return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8);
1535 static void snd_ice1712_proc_read(struct snd_info_entry *entry,
1536 struct snd_info_buffer *buffer)
1538 struct snd_ice1712 *ice = entry->private_data;
1541 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1542 snd_iprintf(buffer, "EEPROM:\n");
1544 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1545 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1546 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1547 snd_iprintf(buffer, " Codec : 0x%x\n", ice->eeprom.data[ICE_EEP1_CODEC]);
1548 snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP1_ACLINK]);
1549 snd_iprintf(buffer, " I2S ID : 0x%x\n", ice->eeprom.data[ICE_EEP1_I2SID]);
1550 snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP1_SPDIF]);
1551 snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
1552 snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
1553 snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
1554 snd_iprintf(buffer, " AC'97 main : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_MAIN_LO));
1555 snd_iprintf(buffer, " AC'97 pcm : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_PCM_LO));
1556 snd_iprintf(buffer, " AC'97 record : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_REC_LO));
1557 snd_iprintf(buffer, " AC'97 record src : 0x%x\n", ice->eeprom.data[ICE_EEP1_AC97_RECSRC]);
1558 for (idx = 0; idx < 4; idx++)
1559 snd_iprintf(buffer, " DAC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_DAC_ID + idx]);
1560 for (idx = 0; idx < 4; idx++)
1561 snd_iprintf(buffer, " ADC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_ADC_ID + idx]);
1562 for (idx = 0x1c; idx < ice->eeprom.size; idx++)
1563 snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
1565 snd_iprintf(buffer, "\nRegisters:\n");
1566 snd_iprintf(buffer, " PSDOUT03 : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_PSDOUT03)));
1567 snd_iprintf(buffer, " CAPTURE : 0x%08x\n", inl(ICEMT(ice, ROUTE_CAPTURE)));
1568 snd_iprintf(buffer, " SPDOUT : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT)));
1569 snd_iprintf(buffer, " RATE : 0x%02x\n", (unsigned)inb(ICEMT(ice, RATE)));
1572 static void __devinit snd_ice1712_proc_init(struct snd_ice1712 * ice)
1574 struct snd_info_entry *entry;
1576 if (! snd_card_proc_new(ice->card, "ice1712", &entry))
1577 snd_info_set_text_ops(entry, ice, 1024, snd_ice1712_proc_read);
1584 static int snd_ice1712_eeprom_info(struct snd_kcontrol *kcontrol,
1585 struct snd_ctl_elem_info *uinfo)
1587 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1588 uinfo->count = sizeof(struct snd_ice1712_eeprom);
1592 static int snd_ice1712_eeprom_get(struct snd_kcontrol *kcontrol,
1593 struct snd_ctl_elem_value *ucontrol)
1595 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1597 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1601 static struct snd_kcontrol_new snd_ice1712_eeprom __devinitdata = {
1602 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1603 .name = "ICE1712 EEPROM",
1604 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1605 .info = snd_ice1712_eeprom_info,
1606 .get = snd_ice1712_eeprom_get
1611 static int snd_ice1712_spdif_info(struct snd_kcontrol *kcontrol,
1612 struct snd_ctl_elem_info *uinfo)
1614 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1619 static int snd_ice1712_spdif_default_get(struct snd_kcontrol *kcontrol,
1620 struct snd_ctl_elem_value *ucontrol)
1622 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1623 if (ice->spdif.ops.default_get)
1624 ice->spdif.ops.default_get(ice, ucontrol);
1628 static int snd_ice1712_spdif_default_put(struct snd_kcontrol *kcontrol,
1629 struct snd_ctl_elem_value *ucontrol)
1631 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1632 if (ice->spdif.ops.default_put)
1633 return ice->spdif.ops.default_put(ice, ucontrol);
1637 static struct snd_kcontrol_new snd_ice1712_spdif_default __devinitdata =
1639 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1640 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1641 .info = snd_ice1712_spdif_info,
1642 .get = snd_ice1712_spdif_default_get,
1643 .put = snd_ice1712_spdif_default_put
1646 static int snd_ice1712_spdif_maskc_get(struct snd_kcontrol *kcontrol,
1647 struct snd_ctl_elem_value *ucontrol)
1649 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1650 if (ice->spdif.ops.default_get) {
1651 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1652 IEC958_AES0_PROFESSIONAL |
1653 IEC958_AES0_CON_NOT_COPYRIGHT |
1654 IEC958_AES0_CON_EMPHASIS;
1655 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1656 IEC958_AES1_CON_CATEGORY;
1657 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1659 ucontrol->value.iec958.status[0] = 0xff;
1660 ucontrol->value.iec958.status[1] = 0xff;
1661 ucontrol->value.iec958.status[2] = 0xff;
1662 ucontrol->value.iec958.status[3] = 0xff;
1663 ucontrol->value.iec958.status[4] = 0xff;
1668 static int snd_ice1712_spdif_maskp_get(struct snd_kcontrol *kcontrol,
1669 struct snd_ctl_elem_value *ucontrol)
1671 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1672 if (ice->spdif.ops.default_get) {
1673 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1674 IEC958_AES0_PROFESSIONAL |
1675 IEC958_AES0_PRO_FS |
1676 IEC958_AES0_PRO_EMPHASIS;
1677 ucontrol->value.iec958.status[1] = IEC958_AES1_PRO_MODE;
1679 ucontrol->value.iec958.status[0] = 0xff;
1680 ucontrol->value.iec958.status[1] = 0xff;
1681 ucontrol->value.iec958.status[2] = 0xff;
1682 ucontrol->value.iec958.status[3] = 0xff;
1683 ucontrol->value.iec958.status[4] = 0xff;
1688 static struct snd_kcontrol_new snd_ice1712_spdif_maskc __devinitdata =
1690 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1691 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1692 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1693 .info = snd_ice1712_spdif_info,
1694 .get = snd_ice1712_spdif_maskc_get,
1697 static struct snd_kcontrol_new snd_ice1712_spdif_maskp __devinitdata =
1699 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1700 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1701 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1702 .info = snd_ice1712_spdif_info,
1703 .get = snd_ice1712_spdif_maskp_get,
1706 static int snd_ice1712_spdif_stream_get(struct snd_kcontrol *kcontrol,
1707 struct snd_ctl_elem_value *ucontrol)
1709 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1710 if (ice->spdif.ops.stream_get)
1711 ice->spdif.ops.stream_get(ice, ucontrol);
1715 static int snd_ice1712_spdif_stream_put(struct snd_kcontrol *kcontrol,
1716 struct snd_ctl_elem_value *ucontrol)
1718 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1719 if (ice->spdif.ops.stream_put)
1720 return ice->spdif.ops.stream_put(ice, ucontrol);
1724 static struct snd_kcontrol_new snd_ice1712_spdif_stream __devinitdata =
1726 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1727 SNDRV_CTL_ELEM_ACCESS_INACTIVE),
1728 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1729 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
1730 .info = snd_ice1712_spdif_info,
1731 .get = snd_ice1712_spdif_stream_get,
1732 .put = snd_ice1712_spdif_stream_put
1735 int snd_ice1712_gpio_info(struct snd_kcontrol *kcontrol,
1736 struct snd_ctl_elem_info *uinfo)
1738 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1740 uinfo->value.integer.min = 0;
1741 uinfo->value.integer.max = 1;
1745 int snd_ice1712_gpio_get(struct snd_kcontrol *kcontrol,
1746 struct snd_ctl_elem_value *ucontrol)
1748 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1749 unsigned char mask = kcontrol->private_value & 0xff;
1750 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1752 snd_ice1712_save_gpio_status(ice);
1753 ucontrol->value.integer.value[0] =
1754 (snd_ice1712_gpio_read(ice) & mask ? 1 : 0) ^ invert;
1755 snd_ice1712_restore_gpio_status(ice);
1759 int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
1760 struct snd_ctl_elem_value *ucontrol)
1762 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1763 unsigned char mask = kcontrol->private_value & 0xff;
1764 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1765 unsigned int val, nval;
1767 if (kcontrol->private_value & (1 << 31))
1769 nval = (ucontrol->value.integer.value[0] ? mask : 0) ^ invert;
1770 snd_ice1712_save_gpio_status(ice);
1771 val = snd_ice1712_gpio_read(ice);
1772 nval |= val & ~mask;
1774 snd_ice1712_gpio_write(ice, nval);
1775 snd_ice1712_restore_gpio_status(ice);
1782 static int snd_ice1712_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1783 struct snd_ctl_elem_info *uinfo)
1785 static char *texts[] = {
1788 "11025", /* 2: 10 */
1796 "64000", /* 10: 15 */
1797 "88200", /* 11: 11 */
1798 "96000", /* 12: 7 */
1799 "IEC958 Input", /* 13: -- */
1801 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1803 uinfo->value.enumerated.items = 14;
1804 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1805 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1806 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1810 static int snd_ice1712_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1811 struct snd_ctl_elem_value *ucontrol)
1813 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1814 static unsigned char xlate[16] = {
1815 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10
1819 spin_lock_irq(&ice->reg_lock);
1820 if (is_spdif_master(ice)) {
1821 ucontrol->value.enumerated.item[0] = 13;
1823 val = xlate[inb(ICEMT(ice, RATE)) & 15];
1828 ucontrol->value.enumerated.item[0] = val;
1830 spin_unlock_irq(&ice->reg_lock);
1834 static int snd_ice1712_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1835 struct snd_ctl_elem_value *ucontrol)
1837 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1838 static unsigned int xrate[13] = {
1839 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1840 32000, 44100, 48000, 64000, 88200, 96000
1845 spin_lock_irq(&ice->reg_lock);
1846 oval = inb(ICEMT(ice, RATE));
1847 if (ucontrol->value.enumerated.item[0] == 13) {
1848 outb(oval | ICE1712_SPDIF_MASTER, ICEMT(ice, RATE));
1850 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1851 spin_unlock_irq(&ice->reg_lock);
1852 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1853 spin_lock_irq(&ice->reg_lock);
1855 change = inb(ICEMT(ice, RATE)) != oval;
1856 spin_unlock_irq(&ice->reg_lock);
1858 if ((oval & ICE1712_SPDIF_MASTER) !=
1859 (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER)) {
1860 /* change CS8427 clock source too */
1862 snd_ice1712_cs8427_set_input_clock(ice, is_spdif_master(ice));
1864 /* notify ak4524 chip as well */
1865 if (is_spdif_master(ice)) {
1867 for (i = 0; i < ice->akm_codecs; i++) {
1868 if (ice->akm[i].ops.set_rate_val)
1869 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
1877 static struct snd_kcontrol_new snd_ice1712_pro_internal_clock __devinitdata = {
1878 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1879 .name = "Multi Track Internal Clock",
1880 .info = snd_ice1712_pro_internal_clock_info,
1881 .get = snd_ice1712_pro_internal_clock_get,
1882 .put = snd_ice1712_pro_internal_clock_put
1885 static int snd_ice1712_pro_internal_clock_default_info(struct snd_kcontrol *kcontrol,
1886 struct snd_ctl_elem_info *uinfo)
1888 static char *texts[] = {
1891 "11025", /* 2: 10 */
1899 "64000", /* 10: 15 */
1900 "88200", /* 11: 11 */
1901 "96000", /* 12: 7 */
1902 // "IEC958 Input", /* 13: -- */
1904 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1906 uinfo->value.enumerated.items = 13;
1907 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1908 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1909 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1913 static int snd_ice1712_pro_internal_clock_default_get(struct snd_kcontrol *kcontrol,
1914 struct snd_ctl_elem_value *ucontrol)
1917 static unsigned int xrate[13] = {
1918 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1919 32000, 44100, 48000, 64000, 88200, 96000
1922 for (val = 0; val < 13; val++) {
1923 if (xrate[val] == PRO_RATE_DEFAULT)
1927 ucontrol->value.enumerated.item[0] = val;
1931 static int snd_ice1712_pro_internal_clock_default_put(struct snd_kcontrol *kcontrol,
1932 struct snd_ctl_elem_value *ucontrol)
1934 static unsigned int xrate[13] = {
1935 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1936 32000, 44100, 48000, 64000, 88200, 96000
1941 oval = PRO_RATE_DEFAULT;
1942 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1943 change = PRO_RATE_DEFAULT != oval;
1948 static struct snd_kcontrol_new snd_ice1712_pro_internal_clock_default __devinitdata = {
1949 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1950 .name = "Multi Track Internal Clock Default",
1951 .info = snd_ice1712_pro_internal_clock_default_info,
1952 .get = snd_ice1712_pro_internal_clock_default_get,
1953 .put = snd_ice1712_pro_internal_clock_default_put
1956 static int snd_ice1712_pro_rate_locking_info(struct snd_kcontrol *kcontrol,
1957 struct snd_ctl_elem_info *uinfo)
1959 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1961 uinfo->value.integer.min = 0;
1962 uinfo->value.integer.max = 1;
1966 static int snd_ice1712_pro_rate_locking_get(struct snd_kcontrol *kcontrol,
1967 struct snd_ctl_elem_value *ucontrol)
1969 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1973 static int snd_ice1712_pro_rate_locking_put(struct snd_kcontrol *kcontrol,
1974 struct snd_ctl_elem_value *ucontrol)
1976 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1977 int change = 0, nval;
1979 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1980 spin_lock_irq(&ice->reg_lock);
1981 change = PRO_RATE_LOCKED != nval;
1982 PRO_RATE_LOCKED = nval;
1983 spin_unlock_irq(&ice->reg_lock);
1987 static struct snd_kcontrol_new snd_ice1712_pro_rate_locking __devinitdata = {
1988 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1989 .name = "Multi Track Rate Locking",
1990 .info = snd_ice1712_pro_rate_locking_info,
1991 .get = snd_ice1712_pro_rate_locking_get,
1992 .put = snd_ice1712_pro_rate_locking_put
1995 static int snd_ice1712_pro_rate_reset_info(struct snd_kcontrol *kcontrol,
1996 struct snd_ctl_elem_info *uinfo)
1998 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2000 uinfo->value.integer.min = 0;
2001 uinfo->value.integer.max = 1;
2005 static int snd_ice1712_pro_rate_reset_get(struct snd_kcontrol *kcontrol,
2006 struct snd_ctl_elem_value *ucontrol)
2008 ucontrol->value.integer.value[0] = PRO_RATE_RESET;
2012 static int snd_ice1712_pro_rate_reset_put(struct snd_kcontrol *kcontrol,
2013 struct snd_ctl_elem_value *ucontrol)
2015 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2016 int change = 0, nval;
2018 nval = ucontrol->value.integer.value[0] ? 1 : 0;
2019 spin_lock_irq(&ice->reg_lock);
2020 change = PRO_RATE_RESET != nval;
2021 PRO_RATE_RESET = nval;
2022 spin_unlock_irq(&ice->reg_lock);
2026 static struct snd_kcontrol_new snd_ice1712_pro_rate_reset __devinitdata = {
2027 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2028 .name = "Multi Track Rate Reset",
2029 .info = snd_ice1712_pro_rate_reset_info,
2030 .get = snd_ice1712_pro_rate_reset_get,
2031 .put = snd_ice1712_pro_rate_reset_put
2037 static int snd_ice1712_pro_route_info(struct snd_kcontrol *kcontrol,
2038 struct snd_ctl_elem_info *uinfo)
2040 static char *texts[] = {
2042 "H/W In 0", "H/W In 1", "H/W In 2", "H/W In 3", /* 1-4 */
2043 "H/W In 4", "H/W In 5", "H/W In 6", "H/W In 7", /* 5-8 */
2044 "IEC958 In L", "IEC958 In R", /* 9-10 */
2045 "Digital Mixer", /* 11 - optional */
2048 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2050 uinfo->value.enumerated.items =
2051 snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
2052 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2053 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2054 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2058 static int snd_ice1712_pro_route_analog_get(struct snd_kcontrol *kcontrol,
2059 struct snd_ctl_elem_value *ucontrol)
2061 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2062 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2063 unsigned int val, cval;
2065 spin_lock_irq(&ice->reg_lock);
2066 val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2067 cval = inl(ICEMT(ice, ROUTE_CAPTURE));
2068 spin_unlock_irq(&ice->reg_lock);
2070 val >>= ((idx % 2) * 8) + ((idx / 2) * 2);
2072 cval >>= ((idx / 2) * 8) + ((idx % 2) * 4);
2073 if (val == 1 && idx < 2)
2074 ucontrol->value.enumerated.item[0] = 11;
2076 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2078 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2080 ucontrol->value.enumerated.item[0] = 0;
2084 static int snd_ice1712_pro_route_analog_put(struct snd_kcontrol *kcontrol,
2085 struct snd_ctl_elem_value *ucontrol)
2087 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2089 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2090 unsigned int val, old_val, nval;
2093 if (ucontrol->value.enumerated.item[0] >= 11)
2094 nval = idx < 2 ? 1 : 0; /* dig mixer (or pcm) */
2095 else if (ucontrol->value.enumerated.item[0] >= 9)
2096 nval = 3; /* spdif in */
2097 else if (ucontrol->value.enumerated.item[0] >= 1)
2098 nval = 2; /* analog in */
2101 shift = ((idx % 2) * 8) + ((idx / 2) * 2);
2102 spin_lock_irq(&ice->reg_lock);
2103 val = old_val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2104 val &= ~(0x03 << shift);
2105 val |= nval << shift;
2106 change = val != old_val;
2108 outw(val, ICEMT(ice, ROUTE_PSDOUT03));
2109 spin_unlock_irq(&ice->reg_lock);
2110 if (nval < 2) /* dig mixer of pcm */
2113 /* update CAPTURE */
2114 spin_lock_irq(&ice->reg_lock);
2115 val = old_val = inl(ICEMT(ice, ROUTE_CAPTURE));
2116 shift = ((idx / 2) * 8) + ((idx % 2) * 4);
2117 if (nval == 2) { /* analog in */
2118 nval = ucontrol->value.enumerated.item[0] - 1;
2119 val &= ~(0x07 << shift);
2120 val |= nval << shift;
2121 } else { /* spdif in */
2122 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2123 val &= ~(0x08 << shift);
2124 val |= nval << shift;
2126 if (val != old_val) {
2128 outl(val, ICEMT(ice, ROUTE_CAPTURE));
2130 spin_unlock_irq(&ice->reg_lock);
2134 static int snd_ice1712_pro_route_spdif_get(struct snd_kcontrol *kcontrol,
2135 struct snd_ctl_elem_value *ucontrol)
2137 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2138 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2139 unsigned int val, cval;
2140 val = inw(ICEMT(ice, ROUTE_SPDOUT));
2141 cval = (val >> (idx * 4 + 8)) & 0x0f;
2142 val = (val >> (idx * 2)) & 0x03;
2144 ucontrol->value.enumerated.item[0] = 11;
2146 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2148 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2150 ucontrol->value.enumerated.item[0] = 0;
2154 static int snd_ice1712_pro_route_spdif_put(struct snd_kcontrol *kcontrol,
2155 struct snd_ctl_elem_value *ucontrol)
2157 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2159 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2160 unsigned int val, old_val, nval;
2163 spin_lock_irq(&ice->reg_lock);
2164 val = old_val = inw(ICEMT(ice, ROUTE_SPDOUT));
2165 if (ucontrol->value.enumerated.item[0] >= 11)
2167 else if (ucontrol->value.enumerated.item[0] >= 9)
2169 else if (ucontrol->value.enumerated.item[0] >= 1)
2174 val &= ~(0x03 << shift);
2175 val |= nval << shift;
2176 shift = idx * 4 + 8;
2178 nval = ucontrol->value.enumerated.item[0] - 1;
2179 val &= ~(0x07 << shift);
2180 val |= nval << shift;
2181 } else if (nval == 3) {
2182 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2183 val &= ~(0x08 << shift);
2184 val |= nval << shift;
2186 change = val != old_val;
2188 outw(val, ICEMT(ice, ROUTE_SPDOUT));
2189 spin_unlock_irq(&ice->reg_lock);
2193 static struct snd_kcontrol_new snd_ice1712_mixer_pro_analog_route __devinitdata = {
2194 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2195 .name = "H/W Playback Route",
2196 .info = snd_ice1712_pro_route_info,
2197 .get = snd_ice1712_pro_route_analog_get,
2198 .put = snd_ice1712_pro_route_analog_put,
2201 static struct snd_kcontrol_new snd_ice1712_mixer_pro_spdif_route __devinitdata = {
2202 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2203 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
2204 .info = snd_ice1712_pro_route_info,
2205 .get = snd_ice1712_pro_route_spdif_get,
2206 .put = snd_ice1712_pro_route_spdif_put,
2211 static int snd_ice1712_pro_volume_rate_info(struct snd_kcontrol *kcontrol,
2212 struct snd_ctl_elem_info *uinfo)
2214 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2216 uinfo->value.integer.min = 0;
2217 uinfo->value.integer.max = 255;
2221 static int snd_ice1712_pro_volume_rate_get(struct snd_kcontrol *kcontrol,
2222 struct snd_ctl_elem_value *ucontrol)
2224 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2226 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE));
2230 static int snd_ice1712_pro_volume_rate_put(struct snd_kcontrol *kcontrol,
2231 struct snd_ctl_elem_value *ucontrol)
2233 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2236 spin_lock_irq(&ice->reg_lock);
2237 change = inb(ICEMT(ice, MONITOR_RATE)) != ucontrol->value.integer.value[0];
2238 outb(ucontrol->value.integer.value[0], ICEMT(ice, MONITOR_RATE));
2239 spin_unlock_irq(&ice->reg_lock);
2243 static struct snd_kcontrol_new snd_ice1712_mixer_pro_volume_rate __devinitdata = {
2244 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2245 .name = "Multi Track Volume Rate",
2246 .info = snd_ice1712_pro_volume_rate_info,
2247 .get = snd_ice1712_pro_volume_rate_get,
2248 .put = snd_ice1712_pro_volume_rate_put
2251 static int snd_ice1712_pro_peak_info(struct snd_kcontrol *kcontrol,
2252 struct snd_ctl_elem_info *uinfo)
2254 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2256 uinfo->value.integer.min = 0;
2257 uinfo->value.integer.max = 255;
2261 static int snd_ice1712_pro_peak_get(struct snd_kcontrol *kcontrol,
2262 struct snd_ctl_elem_value *ucontrol)
2264 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2267 spin_lock_irq(&ice->reg_lock);
2268 for (idx = 0; idx < 22; idx++) {
2269 outb(idx, ICEMT(ice, MONITOR_PEAKINDEX));
2270 ucontrol->value.integer.value[idx] = inb(ICEMT(ice, MONITOR_PEAKDATA));
2272 spin_unlock_irq(&ice->reg_lock);
2276 static struct snd_kcontrol_new snd_ice1712_mixer_pro_peak __devinitdata = {
2277 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2278 .name = "Multi Track Peak",
2279 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2280 .info = snd_ice1712_pro_peak_info,
2281 .get = snd_ice1712_pro_peak_get
2289 * list of available boards
2291 static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
2292 snd_ice1712_hoontech_cards,
2293 snd_ice1712_delta_cards,
2294 snd_ice1712_ews_cards,
2298 static unsigned char __devinit snd_ice1712_read_i2c(struct snd_ice1712 *ice,
2304 outb(addr, ICEREG(ice, I2C_BYTE_ADDR));
2305 outb(dev & ~ICE1712_I2C_WRITE, ICEREG(ice, I2C_DEV_ADDR));
2306 while (t-- > 0 && (inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_BUSY)) ;
2307 return inb(ICEREG(ice, I2C_DATA));
2310 static int __devinit snd_ice1712_read_eeprom(struct snd_ice1712 *ice,
2311 const char *modelname)
2313 int dev = 0xa0; /* EEPROM device address */
2314 unsigned int i, size;
2315 struct snd_ice1712_card_info **tbl, *c;
2317 if (! modelname || ! *modelname) {
2318 ice->eeprom.subvendor = 0;
2319 if ((inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_EEPROM) != 0)
2320 ice->eeprom.subvendor = (snd_ice1712_read_i2c(ice, dev, 0x00) << 0) |
2321 (snd_ice1712_read_i2c(ice, dev, 0x01) << 8) |
2322 (snd_ice1712_read_i2c(ice, dev, 0x02) << 16) |
2323 (snd_ice1712_read_i2c(ice, dev, 0x03) << 24);
2324 if (ice->eeprom.subvendor == 0 ||
2325 ice->eeprom.subvendor == (unsigned int)-1) {
2326 /* invalid subvendor from EEPROM, try the PCI subststem ID instead */
2328 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID, &vendor);
2329 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
2330 ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device);
2331 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
2332 printk(KERN_ERR "ice1712: No valid ID is found\n");
2337 for (tbl = card_tables; *tbl; tbl++) {
2338 for (c = *tbl; c->subvendor; c++) {
2339 if (modelname && c->model && ! strcmp(modelname, c->model)) {
2340 printk(KERN_INFO "ice1712: Using board model %s\n", c->name);
2341 ice->eeprom.subvendor = c->subvendor;
2342 } else if (c->subvendor != ice->eeprom.subvendor)
2344 if (! c->eeprom_size || ! c->eeprom_data)
2346 /* if the EEPROM is given by the driver, use it */
2347 snd_printdd("using the defined eeprom..\n");
2348 ice->eeprom.version = 1;
2349 ice->eeprom.size = c->eeprom_size + 6;
2350 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
2354 printk(KERN_WARNING "ice1712: No matching model found for ID 0x%x\n",
2355 ice->eeprom.subvendor);
2358 ice->eeprom.size = snd_ice1712_read_i2c(ice, dev, 0x04);
2359 if (ice->eeprom.size < 6)
2360 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */
2361 else if (ice->eeprom.size > 32) {
2362 snd_printk(KERN_ERR "invalid EEPROM (size = %i)\n", ice->eeprom.size);
2365 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05);
2366 if (ice->eeprom.version != 1) {
2367 snd_printk(KERN_ERR "invalid EEPROM version %i\n",
2368 ice->eeprom.version);
2371 size = ice->eeprom.size - 6;
2372 for (i = 0; i < size; i++)
2373 ice->eeprom.data[i] = snd_ice1712_read_i2c(ice, dev, i + 6);
2376 ice->eeprom.gpiomask = ice->eeprom.data[ICE_EEP1_GPIO_MASK];
2377 ice->eeprom.gpiostate = ice->eeprom.data[ICE_EEP1_GPIO_STATE];
2378 ice->eeprom.gpiodir = ice->eeprom.data[ICE_EEP1_GPIO_DIR];
2385 static int __devinit snd_ice1712_chip_init(struct snd_ice1712 *ice)
2387 outb(ICE1712_RESET | ICE1712_NATIVE, ICEREG(ice, CONTROL));
2389 outb(ICE1712_NATIVE, ICEREG(ice, CONTROL));
2391 pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]);
2392 pci_write_config_byte(ice->pci, 0x61, ice->eeprom.data[ICE_EEP1_ACLINK]);
2393 pci_write_config_byte(ice->pci, 0x62, ice->eeprom.data[ICE_EEP1_I2SID]);
2394 pci_write_config_byte(ice->pci, 0x63, ice->eeprom.data[ICE_EEP1_SPDIF]);
2395 if (ice->eeprom.subvendor != ICE1712_SUBDEVICE_STDSP24) {
2396 ice->gpio.write_mask = ice->eeprom.gpiomask;
2397 ice->gpio.direction = ice->eeprom.gpiodir;
2398 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK,
2399 ice->eeprom.gpiomask);
2400 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
2401 ice->eeprom.gpiodir);
2402 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA,
2403 ice->eeprom.gpiostate);
2405 ice->gpio.write_mask = 0xc0;
2406 ice->gpio.direction = 0xff;
2407 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, 0xc0);
2408 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, 0xff);
2409 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA,
2410 ICE1712_STDSP24_CLOCK_BIT);
2412 snd_ice1712_write(ice, ICE1712_IREG_PRO_POWERDOWN, 0);
2413 if (!(ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97)) {
2414 outb(ICE1712_AC97_WARM, ICEREG(ice, AC97_CMD));
2416 outb(0, ICEREG(ice, AC97_CMD));
2418 snd_ice1712_write(ice, ICE1712_IREG_CONSUMER_POWERDOWN, 0);
2420 snd_ice1712_set_pro_rate(ice, 48000, 1);
2425 int __devinit snd_ice1712_spdif_build_controls(struct snd_ice1712 *ice)
2428 struct snd_kcontrol *kctl;
2430 snd_assert(ice->pcm_pro != NULL, return -EIO);
2431 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_default, ice));
2434 kctl->id.device = ice->pcm_pro->device;
2435 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskc, ice));
2438 kctl->id.device = ice->pcm_pro->device;
2439 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskp, ice));
2442 kctl->id.device = ice->pcm_pro->device;
2443 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_stream, ice));
2446 kctl->id.device = ice->pcm_pro->device;
2447 ice->spdif.stream_ctl = kctl;
2452 static int __devinit snd_ice1712_build_controls(struct snd_ice1712 *ice)
2456 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_eeprom, ice));
2459 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock, ice));
2462 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock_default, ice));
2466 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_locking, ice));
2469 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_reset, ice));
2473 if (ice->num_total_dacs > 0) {
2474 struct snd_kcontrol_new tmp = snd_ice1712_mixer_pro_analog_route;
2475 tmp.count = ice->num_total_dacs;
2476 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2481 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice));
2485 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
2488 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice));
2495 static int snd_ice1712_free(struct snd_ice1712 *ice)
2499 /* mask all interrupts */
2500 outb(0xc0, ICEMT(ice, IRQ));
2501 outb(0xff, ICEREG(ice, IRQMASK));
2504 if (ice->irq >= 0) {
2505 synchronize_irq(ice->irq);
2506 free_irq(ice->irq, ice);
2509 pci_release_regions(ice->pci);
2510 snd_ice1712_akm4xxx_free(ice);
2511 pci_disable_device(ice->pci);
2516 static int snd_ice1712_dev_free(struct snd_device *device)
2518 struct snd_ice1712 *ice = device->device_data;
2519 return snd_ice1712_free(ice);
2522 static int __devinit snd_ice1712_create(struct snd_card *card,
2523 struct pci_dev *pci,
2524 const char *modelname,
2527 struct snd_ice1712 ** r_ice1712)
2529 struct snd_ice1712 *ice;
2531 static struct snd_device_ops ops = {
2532 .dev_free = snd_ice1712_dev_free,
2537 /* enable PCI device */
2538 if ((err = pci_enable_device(pci)) < 0)
2540 /* check, if we can restrict PCI DMA transfers to 28 bits */
2541 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 ||
2542 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) {
2543 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n");
2544 pci_disable_device(pci);
2548 ice = kzalloc(sizeof(*ice), GFP_KERNEL);
2550 pci_disable_device(pci);
2553 ice->omni = omni ? 1 : 0;
2554 if (cs8427_timeout < 1)
2556 else if (cs8427_timeout > 1000)
2557 cs8427_timeout = 1000;
2558 ice->cs8427_timeout = cs8427_timeout;
2559 spin_lock_init(&ice->reg_lock);
2560 init_MUTEX(&ice->gpio_mutex);
2561 init_MUTEX(&ice->i2c_mutex);
2562 init_MUTEX(&ice->open_mutex);
2563 ice->gpio.set_mask = snd_ice1712_set_gpio_mask;
2564 ice->gpio.set_dir = snd_ice1712_set_gpio_dir;
2565 ice->gpio.set_data = snd_ice1712_set_gpio_data;
2566 ice->gpio.get_data = snd_ice1712_get_gpio_data;
2568 ice->spdif.cs8403_bits =
2569 ice->spdif.cs8403_stream_bits = (0x01 | /* consumer format */
2570 0x10 | /* no emphasis */
2571 0x20); /* PCM encoder/decoder */
2575 pci_set_master(pci);
2576 pci_write_config_word(ice->pci, 0x40, 0x807f);
2577 pci_write_config_word(ice->pci, 0x42, 0x0006);
2578 snd_ice1712_proc_init(ice);
2579 synchronize_irq(pci->irq);
2581 if ((err = pci_request_regions(pci, "ICE1712")) < 0) {
2583 pci_disable_device(pci);
2586 ice->port = pci_resource_start(pci, 0);
2587 ice->ddma_port = pci_resource_start(pci, 1);
2588 ice->dmapath_port = pci_resource_start(pci, 2);
2589 ice->profi_port = pci_resource_start(pci, 3);
2591 if (request_irq(pci->irq, snd_ice1712_interrupt, SA_INTERRUPT|SA_SHIRQ,
2593 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2594 snd_ice1712_free(ice);
2598 ice->irq = pci->irq;
2600 if (snd_ice1712_read_eeprom(ice, modelname) < 0) {
2601 snd_ice1712_free(ice);
2604 if (snd_ice1712_chip_init(ice) < 0) {
2605 snd_ice1712_free(ice);
2609 /* unmask used interrupts */
2610 outb(((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) == 0 ?
2611 ICE1712_IRQ_MPU2 : 0) |
2612 ((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97) ?
2613 ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0),
2614 ICEREG(ice, IRQMASK));
2615 outb(0x00, ICEMT(ice, IRQ));
2617 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2618 snd_ice1712_free(ice);
2622 snd_card_set_dev(card, &pci->dev);
2635 static struct snd_ice1712_card_info no_matched __devinitdata;
2637 static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2638 const struct pci_device_id *pci_id)
2641 struct snd_card *card;
2642 struct snd_ice1712 *ice;
2643 int pcm_dev = 0, err;
2644 struct snd_ice1712_card_info **tbl, *c;
2646 if (dev >= SNDRV_CARDS)
2653 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2657 strcpy(card->driver, "ICE1712");
2658 strcpy(card->shortname, "ICEnsemble ICE1712");
2660 if ((err = snd_ice1712_create(card, pci, model[dev], omni[dev],
2661 cs8427_timeout[dev], &ice)) < 0) {
2662 snd_card_free(card);
2666 for (tbl = card_tables; *tbl; tbl++) {
2667 for (c = *tbl; c->subvendor; c++) {
2668 if (c->subvendor == ice->eeprom.subvendor) {
2669 strcpy(card->shortname, c->name);
2670 if (c->driver) /* specific driver? */
2671 strcpy(card->driver, c->driver);
2673 if ((err = c->chip_init(ice)) < 0) {
2674 snd_card_free(card);
2685 if ((err = snd_ice1712_pcm_profi(ice, pcm_dev++, NULL)) < 0) {
2686 snd_card_free(card);
2690 if (ice_has_con_ac97(ice))
2691 if ((err = snd_ice1712_pcm(ice, pcm_dev++, NULL)) < 0) {
2692 snd_card_free(card);
2696 if ((err = snd_ice1712_ac97_mixer(ice)) < 0) {
2697 snd_card_free(card);
2701 if ((err = snd_ice1712_build_controls(ice)) < 0) {
2702 snd_card_free(card);
2706 if (c->build_controls) {
2707 if ((err = c->build_controls(ice)) < 0) {
2708 snd_card_free(card);
2713 if (ice_has_con_ac97(ice))
2714 if ((err = snd_ice1712_pcm_ds(ice, pcm_dev++, NULL)) < 0) {
2715 snd_card_free(card);
2719 if (! c->no_mpu401) {
2720 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2721 ICEREG(ice, MPU1_CTRL), 1,
2723 &ice->rmidi[0])) < 0) {
2724 snd_card_free(card);
2728 if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401)
2729 if ((err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712,
2730 ICEREG(ice, MPU2_CTRL), 1,
2732 &ice->rmidi[1])) < 0) {
2733 snd_card_free(card);
2738 sprintf(card->longname, "%s at 0x%lx, irq %i",
2739 card->shortname, ice->port, ice->irq);
2741 if ((err = snd_card_register(card)) < 0) {
2742 snd_card_free(card);
2745 pci_set_drvdata(pci, card);
2750 static void __devexit snd_ice1712_remove(struct pci_dev *pci)
2752 snd_card_free(pci_get_drvdata(pci));
2753 pci_set_drvdata(pci, NULL);
2756 static struct pci_driver driver = {
2758 .id_table = snd_ice1712_ids,
2759 .probe = snd_ice1712_probe,
2760 .remove = __devexit_p(snd_ice1712_remove),
2763 static int __init alsa_card_ice1712_init(void)
2765 return pci_register_driver(&driver);
2768 static void __exit alsa_card_ice1712_exit(void)
2770 pci_unregister_driver(&driver);
2773 module_init(alsa_card_ice1712_init)
2774 module_exit(alsa_card_ice1712_exit)