2 * ALSA driver for ICEnsemble ICE1712 (Envy24)
4 * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 - spdif nonaudio consumer mode does not work (at least with my
31 * 2002.09.09 Takashi Iwai <tiwai@suse.de>
32 * split the code to several files. each low-level routine
33 * is stored in the local file and called from registration
34 * function from card_info struct.
36 * 2002.11.26 James Stafford <jstafford@ampltd.com>
37 * Added support for VT1724 (Envy24HT)
38 * I have left out support for 176.4 and 192 KHz for the moment.
39 * I also haven't done anything with the internal S/PDIF transmitter or the MPU-401
41 * 2003.02.20 Taksahi Iwai <tiwai@suse.de>
42 * Split vt1724 part to an independent driver.
43 * The GPIO is accessed through the callback functions now.
45 * 2004.03.31 Doug McLain <nostar@comcast.net>
46 * Added support for Event Electronics EZ8 card to hoontech.c.
50 #include <sound/driver.h>
52 #include <linux/delay.h>
53 #include <linux/interrupt.h>
54 #include <linux/init.h>
55 #include <linux/pci.h>
56 #include <linux/slab.h>
57 #include <linux/moduleparam.h>
58 #include <linux/mutex.h>
59 #include <sound/core.h>
60 #include <sound/cs8427.h>
61 #include <sound/info.h>
62 #include <sound/mpu401.h>
63 #include <sound/initval.h>
65 #include <sound/asoundef.h>
69 /* lowlevel routines */
74 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
75 MODULE_DESCRIPTION("ICEnsemble ICE1712 (Envy24)");
76 MODULE_LICENSE("GPL");
77 MODULE_SUPPORTED_DEVICE("{"
81 "{ICEnsemble,Generic ICE1712},"
82 "{ICEnsemble,Generic Envy24}}");
84 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
85 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
86 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
87 static char *model[SNDRV_CARDS];
88 static int omni[SNDRV_CARDS]; /* Delta44 & 66 Omni I/O support */
89 static int cs8427_timeout[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 500}; /* CS8427 S/PDIF transciever reset timeout value in msec */
91 module_param_array(index, int, NULL, 0444);
92 MODULE_PARM_DESC(index, "Index value for ICE1712 soundcard.");
93 module_param_array(id, charp, NULL, 0444);
94 MODULE_PARM_DESC(id, "ID string for ICE1712 soundcard.");
95 module_param_array(enable, bool, NULL, 0444);
96 MODULE_PARM_DESC(enable, "Enable ICE1712 soundcard.");
97 module_param_array(omni, bool, NULL, 0444);
98 MODULE_PARM_DESC(omni, "Enable Midiman M-Audio Delta Omni I/O support.");
99 module_param_array(cs8427_timeout, int, NULL, 0444);
100 MODULE_PARM_DESC(cs8427_timeout, "Define reset timeout for cs8427 chip in msec resolution.");
101 module_param_array(model, charp, NULL, 0444);
102 MODULE_PARM_DESC(model, "Use the given board model.");
105 static struct pci_device_id snd_ice1712_ids[] = {
106 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_ICE_1712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* ICE1712 */
110 MODULE_DEVICE_TABLE(pci, snd_ice1712_ids);
112 static int snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice);
113 static int snd_ice1712_build_controls(struct snd_ice1712 *ice);
115 static int PRO_RATE_LOCKED;
116 static int PRO_RATE_RESET = 1;
117 static unsigned int PRO_RATE_DEFAULT = 44100;
123 /* check whether the clock mode is spdif-in */
124 static inline int is_spdif_master(struct snd_ice1712 *ice)
126 return (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER) ? 1 : 0;
129 static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
131 return is_spdif_master(ice) || PRO_RATE_LOCKED;
134 static inline void snd_ice1712_ds_write(struct snd_ice1712 * ice, u8 channel, u8 addr, u32 data)
136 outb((channel << 4) | addr, ICEDS(ice, INDEX));
137 outl(data, ICEDS(ice, DATA));
140 static inline u32 snd_ice1712_ds_read(struct snd_ice1712 * ice, u8 channel, u8 addr)
142 outb((channel << 4) | addr, ICEDS(ice, INDEX));
143 return inl(ICEDS(ice, DATA));
146 static void snd_ice1712_ac97_write(struct snd_ac97 *ac97,
150 struct snd_ice1712 *ice = ac97->private_data;
152 unsigned char old_cmd = 0;
154 for (tm = 0; tm < 0x10000; tm++) {
155 old_cmd = inb(ICEREG(ice, AC97_CMD));
156 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
158 if (!(old_cmd & ICE1712_AC97_READY))
162 outb(reg, ICEREG(ice, AC97_INDEX));
163 outw(val, ICEREG(ice, AC97_DATA));
164 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
165 outb(old_cmd | ICE1712_AC97_WRITE, ICEREG(ice, AC97_CMD));
166 for (tm = 0; tm < 0x10000; tm++)
167 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
171 static unsigned short snd_ice1712_ac97_read(struct snd_ac97 *ac97,
174 struct snd_ice1712 *ice = ac97->private_data;
176 unsigned char old_cmd = 0;
178 for (tm = 0; tm < 0x10000; tm++) {
179 old_cmd = inb(ICEREG(ice, AC97_CMD));
180 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
182 if (!(old_cmd & ICE1712_AC97_READY))
186 outb(reg, ICEREG(ice, AC97_INDEX));
187 outb(old_cmd | ICE1712_AC97_READ, ICEREG(ice, AC97_CMD));
188 for (tm = 0; tm < 0x10000; tm++)
189 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
191 if (tm >= 0x10000) /* timeout */
193 return inw(ICEREG(ice, AC97_DATA));
200 static void snd_ice1712_pro_ac97_write(struct snd_ac97 *ac97,
204 struct snd_ice1712 *ice = ac97->private_data;
206 unsigned char old_cmd = 0;
208 for (tm = 0; tm < 0x10000; tm++) {
209 old_cmd = inb(ICEMT(ice, AC97_CMD));
210 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
212 if (!(old_cmd & ICE1712_AC97_READY))
216 outb(reg, ICEMT(ice, AC97_INDEX));
217 outw(val, ICEMT(ice, AC97_DATA));
218 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
219 outb(old_cmd | ICE1712_AC97_WRITE, ICEMT(ice, AC97_CMD));
220 for (tm = 0; tm < 0x10000; tm++)
221 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
226 static unsigned short snd_ice1712_pro_ac97_read(struct snd_ac97 *ac97,
229 struct snd_ice1712 *ice = ac97->private_data;
231 unsigned char old_cmd = 0;
233 for (tm = 0; tm < 0x10000; tm++) {
234 old_cmd = inb(ICEMT(ice, AC97_CMD));
235 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
237 if (!(old_cmd & ICE1712_AC97_READY))
241 outb(reg, ICEMT(ice, AC97_INDEX));
242 outb(old_cmd | ICE1712_AC97_READ, ICEMT(ice, AC97_CMD));
243 for (tm = 0; tm < 0x10000; tm++)
244 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
246 if (tm >= 0x10000) /* timeout */
248 return inw(ICEMT(ice, AC97_DATA));
252 * consumer ac97 digital mix
254 static int snd_ice1712_digmix_route_ac97_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
256 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
258 uinfo->value.integer.min = 0;
259 uinfo->value.integer.max = 1;
263 static int snd_ice1712_digmix_route_ac97_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
265 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
267 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0;
271 static int snd_ice1712_digmix_route_ac97_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
273 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
274 unsigned char val, nval;
276 spin_lock_irq(&ice->reg_lock);
277 val = inb(ICEMT(ice, MONITOR_ROUTECTRL));
278 nval = val & ~ICE1712_ROUTE_AC97;
279 if (ucontrol->value.integer.value[0]) nval |= ICE1712_ROUTE_AC97;
280 outb(nval, ICEMT(ice, MONITOR_ROUTECTRL));
281 spin_unlock_irq(&ice->reg_lock);
285 static struct snd_kcontrol_new snd_ice1712_mixer_digmix_route_ac97 __devinitdata = {
286 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
287 .name = "Digital Mixer To AC97",
288 .info = snd_ice1712_digmix_route_ac97_info,
289 .get = snd_ice1712_digmix_route_ac97_get,
290 .put = snd_ice1712_digmix_route_ac97_put,
297 static void snd_ice1712_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
299 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, data);
300 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
303 static void snd_ice1712_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
305 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data);
306 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
309 static unsigned int snd_ice1712_get_gpio_data(struct snd_ice1712 *ice)
311 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
314 static void snd_ice1712_set_gpio_data(struct snd_ice1712 *ice, unsigned int val)
316 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, val);
317 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
328 * change the input clock selection
329 * spdif_clock = 1 - IEC958 input, 0 - Envy24
331 static int snd_ice1712_cs8427_set_input_clock(struct snd_ice1712 *ice, int spdif_clock)
333 unsigned char reg[2] = { 0x80 | 4, 0 }; /* CS8427 auto increment | register number 4 + data */
334 unsigned char val, nval;
337 snd_i2c_lock(ice->i2c);
338 if (snd_i2c_sendbytes(ice->cs8427, reg, 1) != 1) {
339 snd_i2c_unlock(ice->i2c);
342 if (snd_i2c_readbytes(ice->cs8427, &val, 1) != 1) {
343 snd_i2c_unlock(ice->i2c);
353 if (snd_i2c_sendbytes(ice->cs8427, reg, 2) != 2) {
359 snd_i2c_unlock(ice->i2c);
366 static void open_cs8427(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
368 snd_cs8427_iec958_active(ice->cs8427, 1);
371 static void close_cs8427(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
373 snd_cs8427_iec958_active(ice->cs8427, 0);
376 static void setup_cs8427(struct snd_ice1712 *ice, int rate)
378 snd_cs8427_iec958_pcm(ice->cs8427, rate);
382 * create and initialize callbacks for cs8427 interface
384 int __devinit snd_ice1712_init_cs8427(struct snd_ice1712 *ice, int addr)
388 if ((err = snd_cs8427_create(ice->i2c, addr,
389 (ice->cs8427_timeout * HZ) / 1000,
390 &ice->cs8427)) < 0) {
391 snd_printk(KERN_ERR "CS8427 initialization failed\n");
394 ice->spdif.ops.open = open_cs8427;
395 ice->spdif.ops.close = close_cs8427;
396 ice->spdif.ops.setup_rate = setup_cs8427;
405 static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
407 struct snd_ice1712 *ice = dev_id;
408 unsigned char status;
412 status = inb(ICEREG(ice, IRQSTAT));
416 if (status & ICE1712_IRQ_MPU1) {
418 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data, regs);
419 outb(ICE1712_IRQ_MPU1, ICEREG(ice, IRQSTAT));
420 status &= ~ICE1712_IRQ_MPU1;
422 if (status & ICE1712_IRQ_TIMER)
423 outb(ICE1712_IRQ_TIMER, ICEREG(ice, IRQSTAT));
424 if (status & ICE1712_IRQ_MPU2) {
426 snd_mpu401_uart_interrupt(irq, ice->rmidi[1]->private_data, regs);
427 outb(ICE1712_IRQ_MPU2, ICEREG(ice, IRQSTAT));
428 status &= ~ICE1712_IRQ_MPU2;
430 if (status & ICE1712_IRQ_PROPCM) {
431 unsigned char mtstat = inb(ICEMT(ice, IRQ));
432 if (mtstat & ICE1712_MULTI_PBKSTATUS) {
433 if (ice->playback_pro_substream)
434 snd_pcm_period_elapsed(ice->playback_pro_substream);
435 outb(ICE1712_MULTI_PBKSTATUS, ICEMT(ice, IRQ));
437 if (mtstat & ICE1712_MULTI_CAPSTATUS) {
438 if (ice->capture_pro_substream)
439 snd_pcm_period_elapsed(ice->capture_pro_substream);
440 outb(ICE1712_MULTI_CAPSTATUS, ICEMT(ice, IRQ));
443 if (status & ICE1712_IRQ_FM)
444 outb(ICE1712_IRQ_FM, ICEREG(ice, IRQSTAT));
445 if (status & ICE1712_IRQ_PBKDS) {
448 struct snd_pcm_substream *substream;
449 pbkstatus = inw(ICEDS(ice, INTSTAT));
450 //printk("pbkstatus = 0x%x\n", pbkstatus);
451 for (idx = 0; idx < 6; idx++) {
452 if ((pbkstatus & (3 << (idx * 2))) == 0)
454 if ((substream = ice->playback_con_substream_ds[idx]) != NULL)
455 snd_pcm_period_elapsed(substream);
456 outw(3 << (idx * 2), ICEDS(ice, INTSTAT));
458 outb(ICE1712_IRQ_PBKDS, ICEREG(ice, IRQSTAT));
460 if (status & ICE1712_IRQ_CONCAP) {
461 if (ice->capture_con_substream)
462 snd_pcm_period_elapsed(ice->capture_con_substream);
463 outb(ICE1712_IRQ_CONCAP, ICEREG(ice, IRQSTAT));
465 if (status & ICE1712_IRQ_CONPBK) {
466 if (ice->playback_con_substream)
467 snd_pcm_period_elapsed(ice->playback_con_substream);
468 outb(ICE1712_IRQ_CONPBK, ICEREG(ice, IRQSTAT));
471 return IRQ_RETVAL(handled);
479 static int snd_ice1712_hw_params(struct snd_pcm_substream *substream,
480 struct snd_pcm_hw_params *hw_params)
482 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
485 static int snd_ice1712_hw_free(struct snd_pcm_substream *substream)
487 return snd_pcm_lib_free_pages(substream);
491 * PCM part - consumer I/O
494 static int snd_ice1712_playback_trigger(struct snd_pcm_substream *substream,
497 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
501 spin_lock(&ice->reg_lock);
502 tmp = snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL);
503 if (cmd == SNDRV_PCM_TRIGGER_START) {
505 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
507 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
509 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
514 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
515 spin_unlock(&ice->reg_lock);
519 static int snd_ice1712_playback_ds_trigger(struct snd_pcm_substream *substream,
522 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
526 spin_lock(&ice->reg_lock);
527 tmp = snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL);
528 if (cmd == SNDRV_PCM_TRIGGER_START) {
530 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
532 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
534 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
539 snd_ice1712_ds_write(ice, substream->number * 2, ICE1712_DSC_CONTROL, tmp);
540 spin_unlock(&ice->reg_lock);
544 static int snd_ice1712_capture_trigger(struct snd_pcm_substream *substream,
547 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
551 spin_lock(&ice->reg_lock);
552 tmp = snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL);
553 if (cmd == SNDRV_PCM_TRIGGER_START) {
555 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
560 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
561 spin_unlock(&ice->reg_lock);
565 static int snd_ice1712_playback_prepare(struct snd_pcm_substream *substream)
567 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
568 struct snd_pcm_runtime *runtime = substream->runtime;
569 u32 period_size, buf_size, rate, tmp;
571 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
572 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
574 if (snd_pcm_format_width(runtime->format) == 16)
576 if (runtime->channels == 2)
578 rate = (runtime->rate * 8192) / 375;
579 if (rate > 0x000fffff)
581 spin_lock_irq(&ice->reg_lock);
582 outb(0, ice->ddma_port + 15);
583 outb(ICE1712_DMA_MODE_WRITE | ICE1712_DMA_AUTOINIT, ice->ddma_port + 0x0b);
584 outl(runtime->dma_addr, ice->ddma_port + 0);
585 outw(buf_size, ice->ddma_port + 4);
586 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_LO, rate & 0xff);
587 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_MID, (rate >> 8) & 0xff);
588 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_HI, (rate >> 16) & 0xff);
589 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
590 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_LO, period_size & 0xff);
591 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_HI, period_size >> 8);
592 snd_ice1712_write(ice, ICE1712_IREG_PBK_LEFT, 0);
593 snd_ice1712_write(ice, ICE1712_IREG_PBK_RIGHT, 0);
594 spin_unlock_irq(&ice->reg_lock);
598 static int snd_ice1712_playback_ds_prepare(struct snd_pcm_substream *substream)
600 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
601 struct snd_pcm_runtime *runtime = substream->runtime;
602 u32 period_size, buf_size, rate, tmp, chn;
604 period_size = snd_pcm_lib_period_bytes(substream) - 1;
605 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
607 if (snd_pcm_format_width(runtime->format) == 16)
609 if (runtime->channels == 2)
611 rate = (runtime->rate * 8192) / 375;
612 if (rate > 0x000fffff)
614 ice->playback_con_active_buf[substream->number] = 0;
615 ice->playback_con_virt_addr[substream->number] = runtime->dma_addr;
616 chn = substream->number * 2;
617 spin_lock_irq(&ice->reg_lock);
618 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR0, runtime->dma_addr);
619 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT0, period_size);
620 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR1, runtime->dma_addr + (runtime->periods > 1 ? period_size + 1 : 0));
621 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT1, period_size);
622 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_RATE, rate);
623 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_VOLUME, 0);
624 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_CONTROL, tmp);
625 if (runtime->channels == 2) {
626 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_RATE, rate);
627 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_VOLUME, 0);
629 spin_unlock_irq(&ice->reg_lock);
633 static int snd_ice1712_capture_prepare(struct snd_pcm_substream *substream)
635 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
636 struct snd_pcm_runtime *runtime = substream->runtime;
637 u32 period_size, buf_size;
640 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
641 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
643 if (snd_pcm_format_width(runtime->format) == 16)
645 if (runtime->channels == 2)
647 spin_lock_irq(&ice->reg_lock);
648 outl(ice->capture_con_virt_addr = runtime->dma_addr, ICEREG(ice, CONCAP_ADDR));
649 outw(buf_size, ICEREG(ice, CONCAP_COUNT));
650 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_HI, period_size >> 8);
651 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_LO, period_size & 0xff);
652 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
653 spin_unlock_irq(&ice->reg_lock);
654 snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
658 static snd_pcm_uframes_t snd_ice1712_playback_pointer(struct snd_pcm_substream *substream)
660 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
661 struct snd_pcm_runtime *runtime = substream->runtime;
664 if (!(snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL) & 1))
666 ptr = runtime->buffer_size - inw(ice->ddma_port + 4);
667 if (ptr == runtime->buffer_size)
669 return bytes_to_frames(substream->runtime, ptr);
672 static snd_pcm_uframes_t snd_ice1712_playback_ds_pointer(struct snd_pcm_substream *substream)
674 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
678 if (!(snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL) & 1))
680 if (ice->playback_con_active_buf[substream->number])
681 addr = ICE1712_DSC_ADDR1;
683 addr = ICE1712_DSC_ADDR0;
684 ptr = snd_ice1712_ds_read(ice, substream->number * 2, addr) -
685 ice->playback_con_virt_addr[substream->number];
686 if (ptr == substream->runtime->buffer_size)
688 return bytes_to_frames(substream->runtime, ptr);
691 static snd_pcm_uframes_t snd_ice1712_capture_pointer(struct snd_pcm_substream *substream)
693 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
696 if (!(snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL) & 1))
698 ptr = inl(ICEREG(ice, CONCAP_ADDR)) - ice->capture_con_virt_addr;
699 if (ptr == substream->runtime->buffer_size)
701 return bytes_to_frames(substream->runtime, ptr);
704 static struct snd_pcm_hardware snd_ice1712_playback =
706 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
707 SNDRV_PCM_INFO_BLOCK_TRANSFER |
708 SNDRV_PCM_INFO_MMAP_VALID |
709 SNDRV_PCM_INFO_PAUSE),
710 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
711 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
716 .buffer_bytes_max = (64*1024),
717 .period_bytes_min = 64,
718 .period_bytes_max = (64*1024),
724 static struct snd_pcm_hardware snd_ice1712_playback_ds =
726 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
727 SNDRV_PCM_INFO_BLOCK_TRANSFER |
728 SNDRV_PCM_INFO_MMAP_VALID |
729 SNDRV_PCM_INFO_PAUSE),
730 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
731 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
736 .buffer_bytes_max = (128*1024),
737 .period_bytes_min = 64,
738 .period_bytes_max = (128*1024),
744 static struct snd_pcm_hardware snd_ice1712_capture =
746 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
747 SNDRV_PCM_INFO_BLOCK_TRANSFER |
748 SNDRV_PCM_INFO_MMAP_VALID),
749 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
750 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
755 .buffer_bytes_max = (64*1024),
756 .period_bytes_min = 64,
757 .period_bytes_max = (64*1024),
763 static int snd_ice1712_playback_open(struct snd_pcm_substream *substream)
765 struct snd_pcm_runtime *runtime = substream->runtime;
766 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
768 ice->playback_con_substream = substream;
769 runtime->hw = snd_ice1712_playback;
773 static int snd_ice1712_playback_ds_open(struct snd_pcm_substream *substream)
775 struct snd_pcm_runtime *runtime = substream->runtime;
776 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
779 ice->playback_con_substream_ds[substream->number] = substream;
780 runtime->hw = snd_ice1712_playback_ds;
781 spin_lock_irq(&ice->reg_lock);
782 tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2));
783 outw(tmp, ICEDS(ice, INTMASK));
784 spin_unlock_irq(&ice->reg_lock);
788 static int snd_ice1712_capture_open(struct snd_pcm_substream *substream)
790 struct snd_pcm_runtime *runtime = substream->runtime;
791 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
793 ice->capture_con_substream = substream;
794 runtime->hw = snd_ice1712_capture;
795 runtime->hw.rates = ice->ac97->rates[AC97_RATES_ADC];
796 if (!(runtime->hw.rates & SNDRV_PCM_RATE_8000))
797 runtime->hw.rate_min = 48000;
801 static int snd_ice1712_playback_close(struct snd_pcm_substream *substream)
803 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
805 ice->playback_con_substream = NULL;
809 static int snd_ice1712_playback_ds_close(struct snd_pcm_substream *substream)
811 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
814 spin_lock_irq(&ice->reg_lock);
815 tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2));
816 outw(tmp, ICEDS(ice, INTMASK));
817 spin_unlock_irq(&ice->reg_lock);
818 ice->playback_con_substream_ds[substream->number] = NULL;
822 static int snd_ice1712_capture_close(struct snd_pcm_substream *substream)
824 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
826 ice->capture_con_substream = NULL;
830 static struct snd_pcm_ops snd_ice1712_playback_ops = {
831 .open = snd_ice1712_playback_open,
832 .close = snd_ice1712_playback_close,
833 .ioctl = snd_pcm_lib_ioctl,
834 .hw_params = snd_ice1712_hw_params,
835 .hw_free = snd_ice1712_hw_free,
836 .prepare = snd_ice1712_playback_prepare,
837 .trigger = snd_ice1712_playback_trigger,
838 .pointer = snd_ice1712_playback_pointer,
841 static struct snd_pcm_ops snd_ice1712_playback_ds_ops = {
842 .open = snd_ice1712_playback_ds_open,
843 .close = snd_ice1712_playback_ds_close,
844 .ioctl = snd_pcm_lib_ioctl,
845 .hw_params = snd_ice1712_hw_params,
846 .hw_free = snd_ice1712_hw_free,
847 .prepare = snd_ice1712_playback_ds_prepare,
848 .trigger = snd_ice1712_playback_ds_trigger,
849 .pointer = snd_ice1712_playback_ds_pointer,
852 static struct snd_pcm_ops snd_ice1712_capture_ops = {
853 .open = snd_ice1712_capture_open,
854 .close = snd_ice1712_capture_close,
855 .ioctl = snd_pcm_lib_ioctl,
856 .hw_params = snd_ice1712_hw_params,
857 .hw_free = snd_ice1712_hw_free,
858 .prepare = snd_ice1712_capture_prepare,
859 .trigger = snd_ice1712_capture_trigger,
860 .pointer = snd_ice1712_capture_pointer,
863 static int __devinit snd_ice1712_pcm(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
870 err = snd_pcm_new(ice->card, "ICE1712 consumer", device, 1, 1, &pcm);
874 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ops);
875 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_ops);
877 pcm->private_data = ice;
879 strcpy(pcm->name, "ICE1712 consumer");
882 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
883 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
888 printk(KERN_WARNING "Consumer PCM code does not work well at the moment --jk\n");
893 static int __devinit snd_ice1712_pcm_ds(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
900 err = snd_pcm_new(ice->card, "ICE1712 consumer (DS)", device, 6, 0, &pcm);
904 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ds_ops);
906 pcm->private_data = ice;
908 strcpy(pcm->name, "ICE1712 consumer (DS)");
911 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
912 snd_dma_pci_data(ice->pci), 64*1024, 128*1024);
921 * PCM code - professional part (multitrack)
924 static unsigned int rates[] = { 8000, 9600, 11025, 12000, 16000, 22050, 24000,
925 32000, 44100, 48000, 64000, 88200, 96000 };
927 static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
928 .count = ARRAY_SIZE(rates),
933 static int snd_ice1712_pro_trigger(struct snd_pcm_substream *substream,
936 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
938 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
939 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
943 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
945 what = ICE1712_PLAYBACK_PAUSE;
946 snd_pcm_trigger_done(substream, substream);
947 spin_lock(&ice->reg_lock);
948 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
949 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
953 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
954 spin_unlock(&ice->reg_lock);
957 case SNDRV_PCM_TRIGGER_START:
958 case SNDRV_PCM_TRIGGER_STOP:
960 unsigned int what = 0;
962 struct list_head *pos;
963 struct snd_pcm_substream *s;
965 snd_pcm_group_for_each(pos, substream) {
966 s = snd_pcm_group_substream_entry(pos);
967 if (s == ice->playback_pro_substream) {
968 what |= ICE1712_PLAYBACK_START;
969 snd_pcm_trigger_done(s, substream);
970 } else if (s == ice->capture_pro_substream) {
971 what |= ICE1712_CAPTURE_START_SHADOW;
972 snd_pcm_trigger_done(s, substream);
975 spin_lock(&ice->reg_lock);
976 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
977 if (cmd == SNDRV_PCM_TRIGGER_START)
981 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
982 spin_unlock(&ice->reg_lock);
993 static void snd_ice1712_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate, int force)
996 unsigned char val, old;
1000 case 8000: val = 6; break;
1001 case 9600: val = 3; break;
1002 case 11025: val = 10; break;
1003 case 12000: val = 2; break;
1004 case 16000: val = 5; break;
1005 case 22050: val = 9; break;
1006 case 24000: val = 1; break;
1007 case 32000: val = 4; break;
1008 case 44100: val = 8; break;
1009 case 48000: val = 0; break;
1010 case 64000: val = 15; break;
1011 case 88200: val = 11; break;
1012 case 96000: val = 7; break;
1020 spin_lock_irqsave(&ice->reg_lock, flags);
1021 if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
1022 ICE1712_PLAYBACK_PAUSE|
1023 ICE1712_PLAYBACK_START)) {
1025 spin_unlock_irqrestore(&ice->reg_lock, flags);
1028 if (!force && is_pro_rate_locked(ice))
1031 old = inb(ICEMT(ice, RATE));
1032 if (!force && old == val)
1034 outb(val, ICEMT(ice, RATE));
1035 spin_unlock_irqrestore(&ice->reg_lock, flags);
1037 if (ice->gpio.set_pro_rate)
1038 ice->gpio.set_pro_rate(ice, rate);
1039 for (i = 0; i < ice->akm_codecs; i++) {
1040 if (ice->akm[i].ops.set_rate_val)
1041 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
1043 if (ice->spdif.ops.setup_rate)
1044 ice->spdif.ops.setup_rate(ice, rate);
1047 static int snd_ice1712_playback_pro_prepare(struct snd_pcm_substream *substream)
1049 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1051 ice->playback_pro_size = snd_pcm_lib_buffer_bytes(substream);
1052 spin_lock_irq(&ice->reg_lock);
1053 outl(substream->runtime->dma_addr, ICEMT(ice, PLAYBACK_ADDR));
1054 outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));
1055 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT));
1056 spin_unlock_irq(&ice->reg_lock);
1061 static int snd_ice1712_playback_pro_hw_params(struct snd_pcm_substream *substream,
1062 struct snd_pcm_hw_params *hw_params)
1064 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1066 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1067 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1070 static int snd_ice1712_capture_pro_prepare(struct snd_pcm_substream *substream)
1072 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1074 ice->capture_pro_size = snd_pcm_lib_buffer_bytes(substream);
1075 spin_lock_irq(&ice->reg_lock);
1076 outl(substream->runtime->dma_addr, ICEMT(ice, CAPTURE_ADDR));
1077 outw((ice->capture_pro_size >> 2) - 1, ICEMT(ice, CAPTURE_SIZE));
1078 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, CAPTURE_COUNT));
1079 spin_unlock_irq(&ice->reg_lock);
1083 static int snd_ice1712_capture_pro_hw_params(struct snd_pcm_substream *substream,
1084 struct snd_pcm_hw_params *hw_params)
1086 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1088 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1089 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1092 static snd_pcm_uframes_t snd_ice1712_playback_pro_pointer(struct snd_pcm_substream *substream)
1094 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1097 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_PLAYBACK_START))
1099 ptr = ice->playback_pro_size - (inw(ICEMT(ice, PLAYBACK_SIZE)) << 2);
1100 if (ptr == substream->runtime->buffer_size)
1102 return bytes_to_frames(substream->runtime, ptr);
1105 static snd_pcm_uframes_t snd_ice1712_capture_pro_pointer(struct snd_pcm_substream *substream)
1107 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1110 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_CAPTURE_START_SHADOW))
1112 ptr = ice->capture_pro_size - (inw(ICEMT(ice, CAPTURE_SIZE)) << 2);
1113 if (ptr == substream->runtime->buffer_size)
1115 return bytes_to_frames(substream->runtime, ptr);
1118 static struct snd_pcm_hardware snd_ice1712_playback_pro =
1120 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1121 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1122 SNDRV_PCM_INFO_MMAP_VALID |
1123 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1124 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1125 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1130 .buffer_bytes_max = (256*1024),
1131 .period_bytes_min = 10 * 4 * 2,
1132 .period_bytes_max = 131040,
1134 .periods_max = 1024,
1138 static struct snd_pcm_hardware snd_ice1712_capture_pro =
1140 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1141 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1142 SNDRV_PCM_INFO_MMAP_VALID |
1143 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1144 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1145 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1150 .buffer_bytes_max = (256*1024),
1151 .period_bytes_min = 12 * 4 * 2,
1152 .period_bytes_max = 131040,
1154 .periods_max = 1024,
1158 static int snd_ice1712_playback_pro_open(struct snd_pcm_substream *substream)
1160 struct snd_pcm_runtime *runtime = substream->runtime;
1161 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1163 ice->playback_pro_substream = substream;
1164 runtime->hw = snd_ice1712_playback_pro;
1165 snd_pcm_set_sync(substream);
1166 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1167 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1169 if (ice->spdif.ops.open)
1170 ice->spdif.ops.open(ice, substream);
1175 static int snd_ice1712_capture_pro_open(struct snd_pcm_substream *substream)
1177 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1178 struct snd_pcm_runtime *runtime = substream->runtime;
1180 ice->capture_pro_substream = substream;
1181 runtime->hw = snd_ice1712_capture_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);
1188 static int snd_ice1712_playback_pro_close(struct snd_pcm_substream *substream)
1190 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1193 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1194 ice->playback_pro_substream = NULL;
1195 if (ice->spdif.ops.close)
1196 ice->spdif.ops.close(ice, substream);
1201 static int snd_ice1712_capture_pro_close(struct snd_pcm_substream *substream)
1203 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1206 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1207 ice->capture_pro_substream = NULL;
1211 static struct snd_pcm_ops snd_ice1712_playback_pro_ops = {
1212 .open = snd_ice1712_playback_pro_open,
1213 .close = snd_ice1712_playback_pro_close,
1214 .ioctl = snd_pcm_lib_ioctl,
1215 .hw_params = snd_ice1712_playback_pro_hw_params,
1216 .hw_free = snd_ice1712_hw_free,
1217 .prepare = snd_ice1712_playback_pro_prepare,
1218 .trigger = snd_ice1712_pro_trigger,
1219 .pointer = snd_ice1712_playback_pro_pointer,
1222 static struct snd_pcm_ops snd_ice1712_capture_pro_ops = {
1223 .open = snd_ice1712_capture_pro_open,
1224 .close = snd_ice1712_capture_pro_close,
1225 .ioctl = snd_pcm_lib_ioctl,
1226 .hw_params = snd_ice1712_capture_pro_hw_params,
1227 .hw_free = snd_ice1712_hw_free,
1228 .prepare = snd_ice1712_capture_pro_prepare,
1229 .trigger = snd_ice1712_pro_trigger,
1230 .pointer = snd_ice1712_capture_pro_pointer,
1233 static int __devinit snd_ice1712_pcm_profi(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
1235 struct snd_pcm *pcm;
1240 err = snd_pcm_new(ice->card, "ICE1712 multi", device, 1, 1, &pcm);
1244 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_pro_ops);
1245 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_pro_ops);
1247 pcm->private_data = ice;
1248 pcm->info_flags = 0;
1249 strcpy(pcm->name, "ICE1712 multi");
1251 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1252 snd_dma_pci_data(ice->pci), 256*1024, 256*1024);
1259 /* assign channels to iec958 */
1260 err = snd_cs8427_iec958_build(ice->cs8427,
1261 pcm->streams[0].substream,
1262 pcm->streams[1].substream);
1267 if ((err = snd_ice1712_build_pro_mixer(ice)) < 0)
1276 static void snd_ice1712_update_volume(struct snd_ice1712 *ice, int index)
1278 unsigned int vol = ice->pro_volumes[index];
1279 unsigned short val = 0;
1281 val |= (vol & 0x8000) == 0 ? (96 - (vol & 0x7f)) : 0x7f;
1282 val |= ((vol & 0x80000000) == 0 ? (96 - ((vol >> 16) & 0x7f)) : 0x7f) << 8;
1283 outb(index, ICEMT(ice, MONITOR_INDEX));
1284 outw(val, ICEMT(ice, MONITOR_VOLUME));
1287 static int snd_ice1712_pro_mixer_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1289 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1291 uinfo->value.integer.min = 0;
1292 uinfo->value.integer.max = 1;
1296 static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1298 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1299 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1301 spin_lock_irq(&ice->reg_lock);
1302 ucontrol->value.integer.value[0] = !((ice->pro_volumes[index] >> 15) & 1);
1303 ucontrol->value.integer.value[1] = !((ice->pro_volumes[index] >> 31) & 1);
1304 spin_unlock_irq(&ice->reg_lock);
1308 static int snd_ice1712_pro_mixer_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1310 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1311 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1312 unsigned int nval, change;
1314 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
1315 (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
1316 spin_lock_irq(&ice->reg_lock);
1317 nval |= ice->pro_volumes[index] & ~0x80008000;
1318 change = nval != ice->pro_volumes[index];
1319 ice->pro_volumes[index] = nval;
1320 snd_ice1712_update_volume(ice, index);
1321 spin_unlock_irq(&ice->reg_lock);
1325 static int snd_ice1712_pro_mixer_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1327 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1329 uinfo->value.integer.min = 0;
1330 uinfo->value.integer.max = 96;
1334 static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1336 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1337 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1339 spin_lock_irq(&ice->reg_lock);
1340 ucontrol->value.integer.value[0] = (ice->pro_volumes[index] >> 0) & 127;
1341 ucontrol->value.integer.value[1] = (ice->pro_volumes[index] >> 16) & 127;
1342 spin_unlock_irq(&ice->reg_lock);
1346 static int snd_ice1712_pro_mixer_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1348 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1349 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1350 unsigned int nval, change;
1352 nval = (ucontrol->value.integer.value[0] & 127) |
1353 ((ucontrol->value.integer.value[1] & 127) << 16);
1354 spin_lock_irq(&ice->reg_lock);
1355 nval |= ice->pro_volumes[index] & ~0x007f007f;
1356 change = nval != ice->pro_volumes[index];
1357 ice->pro_volumes[index] = nval;
1358 snd_ice1712_update_volume(ice, index);
1359 spin_unlock_irq(&ice->reg_lock);
1364 static struct snd_kcontrol_new snd_ice1712_multi_playback_ctrls[] __devinitdata = {
1366 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1367 .name = "Multi Playback Switch",
1368 .info = snd_ice1712_pro_mixer_switch_info,
1369 .get = snd_ice1712_pro_mixer_switch_get,
1370 .put = snd_ice1712_pro_mixer_switch_put,
1375 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1376 .name = "Multi Playback Volume",
1377 .info = snd_ice1712_pro_mixer_volume_info,
1378 .get = snd_ice1712_pro_mixer_volume_get,
1379 .put = snd_ice1712_pro_mixer_volume_put,
1385 static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_switch __devinitdata = {
1386 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1387 .name = "H/W Multi Capture Switch",
1388 .info = snd_ice1712_pro_mixer_switch_info,
1389 .get = snd_ice1712_pro_mixer_switch_get,
1390 .put = snd_ice1712_pro_mixer_switch_put,
1391 .private_value = 10,
1394 static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_switch __devinitdata = {
1395 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1396 .name = SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE,SWITCH),
1397 .info = snd_ice1712_pro_mixer_switch_info,
1398 .get = snd_ice1712_pro_mixer_switch_get,
1399 .put = snd_ice1712_pro_mixer_switch_put,
1400 .private_value = 18,
1404 static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_volume __devinitdata = {
1405 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1406 .name = "H/W Multi Capture Volume",
1407 .info = snd_ice1712_pro_mixer_volume_info,
1408 .get = snd_ice1712_pro_mixer_volume_get,
1409 .put = snd_ice1712_pro_mixer_volume_put,
1410 .private_value = 10,
1413 static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_volume __devinitdata = {
1414 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1415 .name = SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE,VOLUME),
1416 .info = snd_ice1712_pro_mixer_volume_info,
1417 .get = snd_ice1712_pro_mixer_volume_get,
1418 .put = snd_ice1712_pro_mixer_volume_put,
1419 .private_value = 18,
1423 static int __devinit snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice)
1425 struct snd_card *card = ice->card;
1429 /* multi-channel mixer */
1430 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_multi_playback_ctrls); idx++) {
1431 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_playback_ctrls[idx], ice));
1436 if (ice->num_total_adcs > 0) {
1437 struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_switch;
1438 tmp.count = ice->num_total_adcs;
1439 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1444 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_switch, ice));
1448 if (ice->num_total_adcs > 0) {
1449 struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_volume;
1450 tmp.count = ice->num_total_adcs;
1451 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1456 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_volume, ice));
1460 /* initialize volumes */
1461 for (idx = 0; idx < 10; idx++) {
1462 ice->pro_volumes[idx] = 0x80008000; /* mute */
1463 snd_ice1712_update_volume(ice, idx);
1465 for (idx = 10; idx < 10 + ice->num_total_adcs; idx++) {
1466 ice->pro_volumes[idx] = 0x80008000; /* mute */
1467 snd_ice1712_update_volume(ice, idx);
1469 for (idx = 18; idx < 20; idx++) {
1470 ice->pro_volumes[idx] = 0x80008000; /* mute */
1471 snd_ice1712_update_volume(ice, idx);
1476 static void snd_ice1712_mixer_free_ac97(struct snd_ac97 *ac97)
1478 struct snd_ice1712 *ice = ac97->private_data;
1482 static int __devinit snd_ice1712_ac97_mixer(struct snd_ice1712 * ice)
1484 int err, bus_num = 0;
1485 struct snd_ac97_template ac97;
1486 struct snd_ac97_bus *pbus;
1487 static struct snd_ac97_bus_ops con_ops = {
1488 .write = snd_ice1712_ac97_write,
1489 .read = snd_ice1712_ac97_read,
1491 static struct snd_ac97_bus_ops pro_ops = {
1492 .write = snd_ice1712_pro_ac97_write,
1493 .read = snd_ice1712_pro_ac97_read,
1496 if (ice_has_con_ac97(ice)) {
1497 if ((err = snd_ac97_bus(ice->card, bus_num++, &con_ops, NULL, &pbus)) < 0)
1499 memset(&ac97, 0, sizeof(ac97));
1500 ac97.private_data = ice;
1501 ac97.private_free = snd_ice1712_mixer_free_ac97;
1502 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1503 printk(KERN_WARNING "ice1712: cannot initialize ac97 for consumer, skipped\n");
1505 if ((err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice))) < 0)
1511 if (! (ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) {
1512 if ((err = snd_ac97_bus(ice->card, bus_num, &pro_ops, NULL, &pbus)) < 0)
1514 memset(&ac97, 0, sizeof(ac97));
1515 ac97.private_data = ice;
1516 ac97.private_free = snd_ice1712_mixer_free_ac97;
1517 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1518 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1522 /* I2S mixer only */
1523 strcat(ice->card->mixername, "ICE1712 - multitrack");
1531 static inline unsigned int eeprom_double(struct snd_ice1712 *ice, int idx)
1533 return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8);
1536 static void snd_ice1712_proc_read(struct snd_info_entry *entry,
1537 struct snd_info_buffer *buffer)
1539 struct snd_ice1712 *ice = entry->private_data;
1542 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1543 snd_iprintf(buffer, "EEPROM:\n");
1545 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1546 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1547 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1548 snd_iprintf(buffer, " Codec : 0x%x\n", ice->eeprom.data[ICE_EEP1_CODEC]);
1549 snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP1_ACLINK]);
1550 snd_iprintf(buffer, " I2S ID : 0x%x\n", ice->eeprom.data[ICE_EEP1_I2SID]);
1551 snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP1_SPDIF]);
1552 snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
1553 snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
1554 snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
1555 snd_iprintf(buffer, " AC'97 main : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_MAIN_LO));
1556 snd_iprintf(buffer, " AC'97 pcm : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_PCM_LO));
1557 snd_iprintf(buffer, " AC'97 record : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_REC_LO));
1558 snd_iprintf(buffer, " AC'97 record src : 0x%x\n", ice->eeprom.data[ICE_EEP1_AC97_RECSRC]);
1559 for (idx = 0; idx < 4; idx++)
1560 snd_iprintf(buffer, " DAC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_DAC_ID + idx]);
1561 for (idx = 0; idx < 4; idx++)
1562 snd_iprintf(buffer, " ADC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_ADC_ID + idx]);
1563 for (idx = 0x1c; idx < ice->eeprom.size; idx++)
1564 snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
1566 snd_iprintf(buffer, "\nRegisters:\n");
1567 snd_iprintf(buffer, " PSDOUT03 : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_PSDOUT03)));
1568 snd_iprintf(buffer, " CAPTURE : 0x%08x\n", inl(ICEMT(ice, ROUTE_CAPTURE)));
1569 snd_iprintf(buffer, " SPDOUT : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT)));
1570 snd_iprintf(buffer, " RATE : 0x%02x\n", (unsigned)inb(ICEMT(ice, RATE)));
1573 static void __devinit snd_ice1712_proc_init(struct snd_ice1712 * ice)
1575 struct snd_info_entry *entry;
1577 if (! snd_card_proc_new(ice->card, "ice1712", &entry))
1578 snd_info_set_text_ops(entry, ice, 1024, snd_ice1712_proc_read);
1585 static int snd_ice1712_eeprom_info(struct snd_kcontrol *kcontrol,
1586 struct snd_ctl_elem_info *uinfo)
1588 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1589 uinfo->count = sizeof(struct snd_ice1712_eeprom);
1593 static int snd_ice1712_eeprom_get(struct snd_kcontrol *kcontrol,
1594 struct snd_ctl_elem_value *ucontrol)
1596 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1598 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1602 static struct snd_kcontrol_new snd_ice1712_eeprom __devinitdata = {
1603 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1604 .name = "ICE1712 EEPROM",
1605 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1606 .info = snd_ice1712_eeprom_info,
1607 .get = snd_ice1712_eeprom_get
1612 static int snd_ice1712_spdif_info(struct snd_kcontrol *kcontrol,
1613 struct snd_ctl_elem_info *uinfo)
1615 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1620 static int snd_ice1712_spdif_default_get(struct snd_kcontrol *kcontrol,
1621 struct snd_ctl_elem_value *ucontrol)
1623 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1624 if (ice->spdif.ops.default_get)
1625 ice->spdif.ops.default_get(ice, ucontrol);
1629 static int snd_ice1712_spdif_default_put(struct snd_kcontrol *kcontrol,
1630 struct snd_ctl_elem_value *ucontrol)
1632 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1633 if (ice->spdif.ops.default_put)
1634 return ice->spdif.ops.default_put(ice, ucontrol);
1638 static struct snd_kcontrol_new snd_ice1712_spdif_default __devinitdata =
1640 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1641 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1642 .info = snd_ice1712_spdif_info,
1643 .get = snd_ice1712_spdif_default_get,
1644 .put = snd_ice1712_spdif_default_put
1647 static int snd_ice1712_spdif_maskc_get(struct snd_kcontrol *kcontrol,
1648 struct snd_ctl_elem_value *ucontrol)
1650 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1651 if (ice->spdif.ops.default_get) {
1652 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1653 IEC958_AES0_PROFESSIONAL |
1654 IEC958_AES0_CON_NOT_COPYRIGHT |
1655 IEC958_AES0_CON_EMPHASIS;
1656 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1657 IEC958_AES1_CON_CATEGORY;
1658 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1660 ucontrol->value.iec958.status[0] = 0xff;
1661 ucontrol->value.iec958.status[1] = 0xff;
1662 ucontrol->value.iec958.status[2] = 0xff;
1663 ucontrol->value.iec958.status[3] = 0xff;
1664 ucontrol->value.iec958.status[4] = 0xff;
1669 static int snd_ice1712_spdif_maskp_get(struct snd_kcontrol *kcontrol,
1670 struct snd_ctl_elem_value *ucontrol)
1672 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1673 if (ice->spdif.ops.default_get) {
1674 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1675 IEC958_AES0_PROFESSIONAL |
1676 IEC958_AES0_PRO_FS |
1677 IEC958_AES0_PRO_EMPHASIS;
1678 ucontrol->value.iec958.status[1] = IEC958_AES1_PRO_MODE;
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 struct snd_kcontrol_new snd_ice1712_spdif_maskc __devinitdata =
1691 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1692 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1693 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1694 .info = snd_ice1712_spdif_info,
1695 .get = snd_ice1712_spdif_maskc_get,
1698 static struct snd_kcontrol_new snd_ice1712_spdif_maskp __devinitdata =
1700 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1701 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1702 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1703 .info = snd_ice1712_spdif_info,
1704 .get = snd_ice1712_spdif_maskp_get,
1707 static int snd_ice1712_spdif_stream_get(struct snd_kcontrol *kcontrol,
1708 struct snd_ctl_elem_value *ucontrol)
1710 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1711 if (ice->spdif.ops.stream_get)
1712 ice->spdif.ops.stream_get(ice, ucontrol);
1716 static int snd_ice1712_spdif_stream_put(struct snd_kcontrol *kcontrol,
1717 struct snd_ctl_elem_value *ucontrol)
1719 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1720 if (ice->spdif.ops.stream_put)
1721 return ice->spdif.ops.stream_put(ice, ucontrol);
1725 static struct snd_kcontrol_new snd_ice1712_spdif_stream __devinitdata =
1727 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1728 SNDRV_CTL_ELEM_ACCESS_INACTIVE),
1729 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1730 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
1731 .info = snd_ice1712_spdif_info,
1732 .get = snd_ice1712_spdif_stream_get,
1733 .put = snd_ice1712_spdif_stream_put
1736 int snd_ice1712_gpio_info(struct snd_kcontrol *kcontrol,
1737 struct snd_ctl_elem_info *uinfo)
1739 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1741 uinfo->value.integer.min = 0;
1742 uinfo->value.integer.max = 1;
1746 int snd_ice1712_gpio_get(struct snd_kcontrol *kcontrol,
1747 struct snd_ctl_elem_value *ucontrol)
1749 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1750 unsigned char mask = kcontrol->private_value & 0xff;
1751 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1753 snd_ice1712_save_gpio_status(ice);
1754 ucontrol->value.integer.value[0] =
1755 (snd_ice1712_gpio_read(ice) & mask ? 1 : 0) ^ invert;
1756 snd_ice1712_restore_gpio_status(ice);
1760 int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
1761 struct snd_ctl_elem_value *ucontrol)
1763 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1764 unsigned char mask = kcontrol->private_value & 0xff;
1765 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1766 unsigned int val, nval;
1768 if (kcontrol->private_value & (1 << 31))
1770 nval = (ucontrol->value.integer.value[0] ? mask : 0) ^ invert;
1771 snd_ice1712_save_gpio_status(ice);
1772 val = snd_ice1712_gpio_read(ice);
1773 nval |= val & ~mask;
1775 snd_ice1712_gpio_write(ice, nval);
1776 snd_ice1712_restore_gpio_status(ice);
1783 static int snd_ice1712_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1784 struct snd_ctl_elem_info *uinfo)
1786 static char *texts[] = {
1789 "11025", /* 2: 10 */
1797 "64000", /* 10: 15 */
1798 "88200", /* 11: 11 */
1799 "96000", /* 12: 7 */
1800 "IEC958 Input", /* 13: -- */
1802 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1804 uinfo->value.enumerated.items = 14;
1805 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1806 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1807 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1811 static int snd_ice1712_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1812 struct snd_ctl_elem_value *ucontrol)
1814 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1815 static unsigned char xlate[16] = {
1816 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10
1820 spin_lock_irq(&ice->reg_lock);
1821 if (is_spdif_master(ice)) {
1822 ucontrol->value.enumerated.item[0] = 13;
1824 val = xlate[inb(ICEMT(ice, RATE)) & 15];
1829 ucontrol->value.enumerated.item[0] = val;
1831 spin_unlock_irq(&ice->reg_lock);
1835 static int snd_ice1712_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1836 struct snd_ctl_elem_value *ucontrol)
1838 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1839 static unsigned int xrate[13] = {
1840 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1841 32000, 44100, 48000, 64000, 88200, 96000
1846 spin_lock_irq(&ice->reg_lock);
1847 oval = inb(ICEMT(ice, RATE));
1848 if (ucontrol->value.enumerated.item[0] == 13) {
1849 outb(oval | ICE1712_SPDIF_MASTER, ICEMT(ice, RATE));
1851 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1852 spin_unlock_irq(&ice->reg_lock);
1853 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1854 spin_lock_irq(&ice->reg_lock);
1856 change = inb(ICEMT(ice, RATE)) != oval;
1857 spin_unlock_irq(&ice->reg_lock);
1859 if ((oval & ICE1712_SPDIF_MASTER) !=
1860 (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER)) {
1861 /* change CS8427 clock source too */
1863 snd_ice1712_cs8427_set_input_clock(ice, is_spdif_master(ice));
1865 /* notify ak4524 chip as well */
1866 if (is_spdif_master(ice)) {
1868 for (i = 0; i < ice->akm_codecs; i++) {
1869 if (ice->akm[i].ops.set_rate_val)
1870 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
1878 static struct snd_kcontrol_new snd_ice1712_pro_internal_clock __devinitdata = {
1879 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1880 .name = "Multi Track Internal Clock",
1881 .info = snd_ice1712_pro_internal_clock_info,
1882 .get = snd_ice1712_pro_internal_clock_get,
1883 .put = snd_ice1712_pro_internal_clock_put
1886 static int snd_ice1712_pro_internal_clock_default_info(struct snd_kcontrol *kcontrol,
1887 struct snd_ctl_elem_info *uinfo)
1889 static char *texts[] = {
1892 "11025", /* 2: 10 */
1900 "64000", /* 10: 15 */
1901 "88200", /* 11: 11 */
1902 "96000", /* 12: 7 */
1903 // "IEC958 Input", /* 13: -- */
1905 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1907 uinfo->value.enumerated.items = 13;
1908 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1909 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1910 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1914 static int snd_ice1712_pro_internal_clock_default_get(struct snd_kcontrol *kcontrol,
1915 struct snd_ctl_elem_value *ucontrol)
1918 static unsigned int xrate[13] = {
1919 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1920 32000, 44100, 48000, 64000, 88200, 96000
1923 for (val = 0; val < 13; val++) {
1924 if (xrate[val] == PRO_RATE_DEFAULT)
1928 ucontrol->value.enumerated.item[0] = val;
1932 static int snd_ice1712_pro_internal_clock_default_put(struct snd_kcontrol *kcontrol,
1933 struct snd_ctl_elem_value *ucontrol)
1935 static unsigned int xrate[13] = {
1936 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1937 32000, 44100, 48000, 64000, 88200, 96000
1942 oval = PRO_RATE_DEFAULT;
1943 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1944 change = PRO_RATE_DEFAULT != oval;
1949 static struct snd_kcontrol_new snd_ice1712_pro_internal_clock_default __devinitdata = {
1950 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1951 .name = "Multi Track Internal Clock Default",
1952 .info = snd_ice1712_pro_internal_clock_default_info,
1953 .get = snd_ice1712_pro_internal_clock_default_get,
1954 .put = snd_ice1712_pro_internal_clock_default_put
1957 static int snd_ice1712_pro_rate_locking_info(struct snd_kcontrol *kcontrol,
1958 struct snd_ctl_elem_info *uinfo)
1960 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1962 uinfo->value.integer.min = 0;
1963 uinfo->value.integer.max = 1;
1967 static int snd_ice1712_pro_rate_locking_get(struct snd_kcontrol *kcontrol,
1968 struct snd_ctl_elem_value *ucontrol)
1970 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1974 static int snd_ice1712_pro_rate_locking_put(struct snd_kcontrol *kcontrol,
1975 struct snd_ctl_elem_value *ucontrol)
1977 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1978 int change = 0, nval;
1980 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1981 spin_lock_irq(&ice->reg_lock);
1982 change = PRO_RATE_LOCKED != nval;
1983 PRO_RATE_LOCKED = nval;
1984 spin_unlock_irq(&ice->reg_lock);
1988 static struct snd_kcontrol_new snd_ice1712_pro_rate_locking __devinitdata = {
1989 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1990 .name = "Multi Track Rate Locking",
1991 .info = snd_ice1712_pro_rate_locking_info,
1992 .get = snd_ice1712_pro_rate_locking_get,
1993 .put = snd_ice1712_pro_rate_locking_put
1996 static int snd_ice1712_pro_rate_reset_info(struct snd_kcontrol *kcontrol,
1997 struct snd_ctl_elem_info *uinfo)
1999 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2001 uinfo->value.integer.min = 0;
2002 uinfo->value.integer.max = 1;
2006 static int snd_ice1712_pro_rate_reset_get(struct snd_kcontrol *kcontrol,
2007 struct snd_ctl_elem_value *ucontrol)
2009 ucontrol->value.integer.value[0] = PRO_RATE_RESET;
2013 static int snd_ice1712_pro_rate_reset_put(struct snd_kcontrol *kcontrol,
2014 struct snd_ctl_elem_value *ucontrol)
2016 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2017 int change = 0, nval;
2019 nval = ucontrol->value.integer.value[0] ? 1 : 0;
2020 spin_lock_irq(&ice->reg_lock);
2021 change = PRO_RATE_RESET != nval;
2022 PRO_RATE_RESET = nval;
2023 spin_unlock_irq(&ice->reg_lock);
2027 static struct snd_kcontrol_new snd_ice1712_pro_rate_reset __devinitdata = {
2028 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2029 .name = "Multi Track Rate Reset",
2030 .info = snd_ice1712_pro_rate_reset_info,
2031 .get = snd_ice1712_pro_rate_reset_get,
2032 .put = snd_ice1712_pro_rate_reset_put
2038 static int snd_ice1712_pro_route_info(struct snd_kcontrol *kcontrol,
2039 struct snd_ctl_elem_info *uinfo)
2041 static char *texts[] = {
2043 "H/W In 0", "H/W In 1", "H/W In 2", "H/W In 3", /* 1-4 */
2044 "H/W In 4", "H/W In 5", "H/W In 6", "H/W In 7", /* 5-8 */
2045 "IEC958 In L", "IEC958 In R", /* 9-10 */
2046 "Digital Mixer", /* 11 - optional */
2049 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2051 uinfo->value.enumerated.items =
2052 snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
2053 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2054 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2055 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2059 static int snd_ice1712_pro_route_analog_get(struct snd_kcontrol *kcontrol,
2060 struct snd_ctl_elem_value *ucontrol)
2062 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2063 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2064 unsigned int val, cval;
2066 spin_lock_irq(&ice->reg_lock);
2067 val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2068 cval = inl(ICEMT(ice, ROUTE_CAPTURE));
2069 spin_unlock_irq(&ice->reg_lock);
2071 val >>= ((idx % 2) * 8) + ((idx / 2) * 2);
2073 cval >>= ((idx / 2) * 8) + ((idx % 2) * 4);
2074 if (val == 1 && idx < 2)
2075 ucontrol->value.enumerated.item[0] = 11;
2077 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2079 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2081 ucontrol->value.enumerated.item[0] = 0;
2085 static int snd_ice1712_pro_route_analog_put(struct snd_kcontrol *kcontrol,
2086 struct snd_ctl_elem_value *ucontrol)
2088 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2090 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2091 unsigned int val, old_val, nval;
2094 if (ucontrol->value.enumerated.item[0] >= 11)
2095 nval = idx < 2 ? 1 : 0; /* dig mixer (or pcm) */
2096 else if (ucontrol->value.enumerated.item[0] >= 9)
2097 nval = 3; /* spdif in */
2098 else if (ucontrol->value.enumerated.item[0] >= 1)
2099 nval = 2; /* analog in */
2102 shift = ((idx % 2) * 8) + ((idx / 2) * 2);
2103 spin_lock_irq(&ice->reg_lock);
2104 val = old_val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2105 val &= ~(0x03 << shift);
2106 val |= nval << shift;
2107 change = val != old_val;
2109 outw(val, ICEMT(ice, ROUTE_PSDOUT03));
2110 spin_unlock_irq(&ice->reg_lock);
2111 if (nval < 2) /* dig mixer of pcm */
2114 /* update CAPTURE */
2115 spin_lock_irq(&ice->reg_lock);
2116 val = old_val = inl(ICEMT(ice, ROUTE_CAPTURE));
2117 shift = ((idx / 2) * 8) + ((idx % 2) * 4);
2118 if (nval == 2) { /* analog in */
2119 nval = ucontrol->value.enumerated.item[0] - 1;
2120 val &= ~(0x07 << shift);
2121 val |= nval << shift;
2122 } else { /* spdif in */
2123 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2124 val &= ~(0x08 << shift);
2125 val |= nval << shift;
2127 if (val != old_val) {
2129 outl(val, ICEMT(ice, ROUTE_CAPTURE));
2131 spin_unlock_irq(&ice->reg_lock);
2135 static int snd_ice1712_pro_route_spdif_get(struct snd_kcontrol *kcontrol,
2136 struct snd_ctl_elem_value *ucontrol)
2138 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2139 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2140 unsigned int val, cval;
2141 val = inw(ICEMT(ice, ROUTE_SPDOUT));
2142 cval = (val >> (idx * 4 + 8)) & 0x0f;
2143 val = (val >> (idx * 2)) & 0x03;
2145 ucontrol->value.enumerated.item[0] = 11;
2147 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2149 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2151 ucontrol->value.enumerated.item[0] = 0;
2155 static int snd_ice1712_pro_route_spdif_put(struct snd_kcontrol *kcontrol,
2156 struct snd_ctl_elem_value *ucontrol)
2158 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2160 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2161 unsigned int val, old_val, nval;
2164 spin_lock_irq(&ice->reg_lock);
2165 val = old_val = inw(ICEMT(ice, ROUTE_SPDOUT));
2166 if (ucontrol->value.enumerated.item[0] >= 11)
2168 else if (ucontrol->value.enumerated.item[0] >= 9)
2170 else if (ucontrol->value.enumerated.item[0] >= 1)
2175 val &= ~(0x03 << shift);
2176 val |= nval << shift;
2177 shift = idx * 4 + 8;
2179 nval = ucontrol->value.enumerated.item[0] - 1;
2180 val &= ~(0x07 << shift);
2181 val |= nval << shift;
2182 } else if (nval == 3) {
2183 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2184 val &= ~(0x08 << shift);
2185 val |= nval << shift;
2187 change = val != old_val;
2189 outw(val, ICEMT(ice, ROUTE_SPDOUT));
2190 spin_unlock_irq(&ice->reg_lock);
2194 static struct snd_kcontrol_new snd_ice1712_mixer_pro_analog_route __devinitdata = {
2195 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2196 .name = "H/W Playback Route",
2197 .info = snd_ice1712_pro_route_info,
2198 .get = snd_ice1712_pro_route_analog_get,
2199 .put = snd_ice1712_pro_route_analog_put,
2202 static struct snd_kcontrol_new snd_ice1712_mixer_pro_spdif_route __devinitdata = {
2203 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2204 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
2205 .info = snd_ice1712_pro_route_info,
2206 .get = snd_ice1712_pro_route_spdif_get,
2207 .put = snd_ice1712_pro_route_spdif_put,
2212 static int snd_ice1712_pro_volume_rate_info(struct snd_kcontrol *kcontrol,
2213 struct snd_ctl_elem_info *uinfo)
2215 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2217 uinfo->value.integer.min = 0;
2218 uinfo->value.integer.max = 255;
2222 static int snd_ice1712_pro_volume_rate_get(struct snd_kcontrol *kcontrol,
2223 struct snd_ctl_elem_value *ucontrol)
2225 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2227 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE));
2231 static int snd_ice1712_pro_volume_rate_put(struct snd_kcontrol *kcontrol,
2232 struct snd_ctl_elem_value *ucontrol)
2234 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2237 spin_lock_irq(&ice->reg_lock);
2238 change = inb(ICEMT(ice, MONITOR_RATE)) != ucontrol->value.integer.value[0];
2239 outb(ucontrol->value.integer.value[0], ICEMT(ice, MONITOR_RATE));
2240 spin_unlock_irq(&ice->reg_lock);
2244 static struct snd_kcontrol_new snd_ice1712_mixer_pro_volume_rate __devinitdata = {
2245 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2246 .name = "Multi Track Volume Rate",
2247 .info = snd_ice1712_pro_volume_rate_info,
2248 .get = snd_ice1712_pro_volume_rate_get,
2249 .put = snd_ice1712_pro_volume_rate_put
2252 static int snd_ice1712_pro_peak_info(struct snd_kcontrol *kcontrol,
2253 struct snd_ctl_elem_info *uinfo)
2255 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2257 uinfo->value.integer.min = 0;
2258 uinfo->value.integer.max = 255;
2262 static int snd_ice1712_pro_peak_get(struct snd_kcontrol *kcontrol,
2263 struct snd_ctl_elem_value *ucontrol)
2265 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2268 spin_lock_irq(&ice->reg_lock);
2269 for (idx = 0; idx < 22; idx++) {
2270 outb(idx, ICEMT(ice, MONITOR_PEAKINDEX));
2271 ucontrol->value.integer.value[idx] = inb(ICEMT(ice, MONITOR_PEAKDATA));
2273 spin_unlock_irq(&ice->reg_lock);
2277 static struct snd_kcontrol_new snd_ice1712_mixer_pro_peak __devinitdata = {
2278 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2279 .name = "Multi Track Peak",
2280 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2281 .info = snd_ice1712_pro_peak_info,
2282 .get = snd_ice1712_pro_peak_get
2290 * list of available boards
2292 static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
2293 snd_ice1712_hoontech_cards,
2294 snd_ice1712_delta_cards,
2295 snd_ice1712_ews_cards,
2299 static unsigned char __devinit snd_ice1712_read_i2c(struct snd_ice1712 *ice,
2305 outb(addr, ICEREG(ice, I2C_BYTE_ADDR));
2306 outb(dev & ~ICE1712_I2C_WRITE, ICEREG(ice, I2C_DEV_ADDR));
2307 while (t-- > 0 && (inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_BUSY)) ;
2308 return inb(ICEREG(ice, I2C_DATA));
2311 static int __devinit snd_ice1712_read_eeprom(struct snd_ice1712 *ice,
2312 const char *modelname)
2314 int dev = 0xa0; /* EEPROM device address */
2315 unsigned int i, size;
2316 struct snd_ice1712_card_info **tbl, *c;
2318 if (! modelname || ! *modelname) {
2319 ice->eeprom.subvendor = 0;
2320 if ((inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_EEPROM) != 0)
2321 ice->eeprom.subvendor = (snd_ice1712_read_i2c(ice, dev, 0x00) << 0) |
2322 (snd_ice1712_read_i2c(ice, dev, 0x01) << 8) |
2323 (snd_ice1712_read_i2c(ice, dev, 0x02) << 16) |
2324 (snd_ice1712_read_i2c(ice, dev, 0x03) << 24);
2325 if (ice->eeprom.subvendor == 0 ||
2326 ice->eeprom.subvendor == (unsigned int)-1) {
2327 /* invalid subvendor from EEPROM, try the PCI subststem ID instead */
2329 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID, &vendor);
2330 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
2331 ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device);
2332 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
2333 printk(KERN_ERR "ice1712: No valid ID is found\n");
2338 for (tbl = card_tables; *tbl; tbl++) {
2339 for (c = *tbl; c->subvendor; c++) {
2340 if (modelname && c->model && ! strcmp(modelname, c->model)) {
2341 printk(KERN_INFO "ice1712: Using board model %s\n", c->name);
2342 ice->eeprom.subvendor = c->subvendor;
2343 } else if (c->subvendor != ice->eeprom.subvendor)
2345 if (! c->eeprom_size || ! c->eeprom_data)
2347 /* if the EEPROM is given by the driver, use it */
2348 snd_printdd("using the defined eeprom..\n");
2349 ice->eeprom.version = 1;
2350 ice->eeprom.size = c->eeprom_size + 6;
2351 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
2355 printk(KERN_WARNING "ice1712: No matching model found for ID 0x%x\n",
2356 ice->eeprom.subvendor);
2359 ice->eeprom.size = snd_ice1712_read_i2c(ice, dev, 0x04);
2360 if (ice->eeprom.size < 6)
2361 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */
2362 else if (ice->eeprom.size > 32) {
2363 snd_printk(KERN_ERR "invalid EEPROM (size = %i)\n", ice->eeprom.size);
2366 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05);
2367 if (ice->eeprom.version != 1) {
2368 snd_printk(KERN_ERR "invalid EEPROM version %i\n",
2369 ice->eeprom.version);
2372 size = ice->eeprom.size - 6;
2373 for (i = 0; i < size; i++)
2374 ice->eeprom.data[i] = snd_ice1712_read_i2c(ice, dev, i + 6);
2377 ice->eeprom.gpiomask = ice->eeprom.data[ICE_EEP1_GPIO_MASK];
2378 ice->eeprom.gpiostate = ice->eeprom.data[ICE_EEP1_GPIO_STATE];
2379 ice->eeprom.gpiodir = ice->eeprom.data[ICE_EEP1_GPIO_DIR];
2386 static int __devinit snd_ice1712_chip_init(struct snd_ice1712 *ice)
2388 outb(ICE1712_RESET | ICE1712_NATIVE, ICEREG(ice, CONTROL));
2390 outb(ICE1712_NATIVE, ICEREG(ice, CONTROL));
2392 pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]);
2393 pci_write_config_byte(ice->pci, 0x61, ice->eeprom.data[ICE_EEP1_ACLINK]);
2394 pci_write_config_byte(ice->pci, 0x62, ice->eeprom.data[ICE_EEP1_I2SID]);
2395 pci_write_config_byte(ice->pci, 0x63, ice->eeprom.data[ICE_EEP1_SPDIF]);
2396 if (ice->eeprom.subvendor != ICE1712_SUBDEVICE_STDSP24) {
2397 ice->gpio.write_mask = ice->eeprom.gpiomask;
2398 ice->gpio.direction = ice->eeprom.gpiodir;
2399 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK,
2400 ice->eeprom.gpiomask);
2401 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
2402 ice->eeprom.gpiodir);
2403 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA,
2404 ice->eeprom.gpiostate);
2406 ice->gpio.write_mask = 0xc0;
2407 ice->gpio.direction = 0xff;
2408 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, 0xc0);
2409 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, 0xff);
2410 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA,
2411 ICE1712_STDSP24_CLOCK_BIT);
2413 snd_ice1712_write(ice, ICE1712_IREG_PRO_POWERDOWN, 0);
2414 if (!(ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97)) {
2415 outb(ICE1712_AC97_WARM, ICEREG(ice, AC97_CMD));
2417 outb(0, ICEREG(ice, AC97_CMD));
2419 snd_ice1712_write(ice, ICE1712_IREG_CONSUMER_POWERDOWN, 0);
2421 snd_ice1712_set_pro_rate(ice, 48000, 1);
2426 int __devinit snd_ice1712_spdif_build_controls(struct snd_ice1712 *ice)
2429 struct snd_kcontrol *kctl;
2431 snd_assert(ice->pcm_pro != NULL, return -EIO);
2432 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_default, ice));
2435 kctl->id.device = ice->pcm_pro->device;
2436 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskc, ice));
2439 kctl->id.device = ice->pcm_pro->device;
2440 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskp, ice));
2443 kctl->id.device = ice->pcm_pro->device;
2444 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_stream, ice));
2447 kctl->id.device = ice->pcm_pro->device;
2448 ice->spdif.stream_ctl = kctl;
2453 static int __devinit snd_ice1712_build_controls(struct snd_ice1712 *ice)
2457 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_eeprom, ice));
2460 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock, ice));
2463 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock_default, ice));
2467 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_locking, ice));
2470 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_reset, ice));
2474 if (ice->num_total_dacs > 0) {
2475 struct snd_kcontrol_new tmp = snd_ice1712_mixer_pro_analog_route;
2476 tmp.count = ice->num_total_dacs;
2477 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2482 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice));
2486 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
2489 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice));
2496 static int snd_ice1712_free(struct snd_ice1712 *ice)
2500 /* mask all interrupts */
2501 outb(0xc0, ICEMT(ice, IRQ));
2502 outb(0xff, ICEREG(ice, IRQMASK));
2505 if (ice->irq >= 0) {
2506 synchronize_irq(ice->irq);
2507 free_irq(ice->irq, ice);
2510 pci_release_regions(ice->pci);
2511 snd_ice1712_akm4xxx_free(ice);
2512 pci_disable_device(ice->pci);
2517 static int snd_ice1712_dev_free(struct snd_device *device)
2519 struct snd_ice1712 *ice = device->device_data;
2520 return snd_ice1712_free(ice);
2523 static int __devinit snd_ice1712_create(struct snd_card *card,
2524 struct pci_dev *pci,
2525 const char *modelname,
2528 struct snd_ice1712 ** r_ice1712)
2530 struct snd_ice1712 *ice;
2532 static struct snd_device_ops ops = {
2533 .dev_free = snd_ice1712_dev_free,
2538 /* enable PCI device */
2539 if ((err = pci_enable_device(pci)) < 0)
2541 /* check, if we can restrict PCI DMA transfers to 28 bits */
2542 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 ||
2543 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) {
2544 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n");
2545 pci_disable_device(pci);
2549 ice = kzalloc(sizeof(*ice), GFP_KERNEL);
2551 pci_disable_device(pci);
2554 ice->omni = omni ? 1 : 0;
2555 if (cs8427_timeout < 1)
2557 else if (cs8427_timeout > 1000)
2558 cs8427_timeout = 1000;
2559 ice->cs8427_timeout = cs8427_timeout;
2560 spin_lock_init(&ice->reg_lock);
2561 mutex_init(&ice->gpio_mutex);
2562 mutex_init(&ice->i2c_mutex);
2563 mutex_init(&ice->open_mutex);
2564 ice->gpio.set_mask = snd_ice1712_set_gpio_mask;
2565 ice->gpio.set_dir = snd_ice1712_set_gpio_dir;
2566 ice->gpio.set_data = snd_ice1712_set_gpio_data;
2567 ice->gpio.get_data = snd_ice1712_get_gpio_data;
2569 ice->spdif.cs8403_bits =
2570 ice->spdif.cs8403_stream_bits = (0x01 | /* consumer format */
2571 0x10 | /* no emphasis */
2572 0x20); /* PCM encoder/decoder */
2576 pci_set_master(pci);
2577 pci_write_config_word(ice->pci, 0x40, 0x807f);
2578 pci_write_config_word(ice->pci, 0x42, 0x0006);
2579 snd_ice1712_proc_init(ice);
2580 synchronize_irq(pci->irq);
2582 if ((err = pci_request_regions(pci, "ICE1712")) < 0) {
2584 pci_disable_device(pci);
2587 ice->port = pci_resource_start(pci, 0);
2588 ice->ddma_port = pci_resource_start(pci, 1);
2589 ice->dmapath_port = pci_resource_start(pci, 2);
2590 ice->profi_port = pci_resource_start(pci, 3);
2592 if (request_irq(pci->irq, snd_ice1712_interrupt, SA_INTERRUPT|SA_SHIRQ,
2594 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2595 snd_ice1712_free(ice);
2599 ice->irq = pci->irq;
2601 if (snd_ice1712_read_eeprom(ice, modelname) < 0) {
2602 snd_ice1712_free(ice);
2605 if (snd_ice1712_chip_init(ice) < 0) {
2606 snd_ice1712_free(ice);
2610 /* unmask used interrupts */
2611 outb(((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) == 0 ?
2612 ICE1712_IRQ_MPU2 : 0) |
2613 ((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97) ?
2614 ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0),
2615 ICEREG(ice, IRQMASK));
2616 outb(0x00, ICEMT(ice, IRQ));
2618 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2619 snd_ice1712_free(ice);
2623 snd_card_set_dev(card, &pci->dev);
2636 static struct snd_ice1712_card_info no_matched __devinitdata;
2638 static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2639 const struct pci_device_id *pci_id)
2642 struct snd_card *card;
2643 struct snd_ice1712 *ice;
2644 int pcm_dev = 0, err;
2645 struct snd_ice1712_card_info **tbl, *c;
2647 if (dev >= SNDRV_CARDS)
2654 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2658 strcpy(card->driver, "ICE1712");
2659 strcpy(card->shortname, "ICEnsemble ICE1712");
2661 if ((err = snd_ice1712_create(card, pci, model[dev], omni[dev],
2662 cs8427_timeout[dev], &ice)) < 0) {
2663 snd_card_free(card);
2667 for (tbl = card_tables; *tbl; tbl++) {
2668 for (c = *tbl; c->subvendor; c++) {
2669 if (c->subvendor == ice->eeprom.subvendor) {
2670 strcpy(card->shortname, c->name);
2671 if (c->driver) /* specific driver? */
2672 strcpy(card->driver, c->driver);
2674 if ((err = c->chip_init(ice)) < 0) {
2675 snd_card_free(card);
2686 if ((err = snd_ice1712_pcm_profi(ice, pcm_dev++, NULL)) < 0) {
2687 snd_card_free(card);
2691 if (ice_has_con_ac97(ice))
2692 if ((err = snd_ice1712_pcm(ice, pcm_dev++, NULL)) < 0) {
2693 snd_card_free(card);
2697 if ((err = snd_ice1712_ac97_mixer(ice)) < 0) {
2698 snd_card_free(card);
2702 if ((err = snd_ice1712_build_controls(ice)) < 0) {
2703 snd_card_free(card);
2707 if (c->build_controls) {
2708 if ((err = c->build_controls(ice)) < 0) {
2709 snd_card_free(card);
2714 if (ice_has_con_ac97(ice))
2715 if ((err = snd_ice1712_pcm_ds(ice, pcm_dev++, NULL)) < 0) {
2716 snd_card_free(card);
2720 if (! c->no_mpu401) {
2721 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2722 ICEREG(ice, MPU1_CTRL), 1,
2724 &ice->rmidi[0])) < 0) {
2725 snd_card_free(card);
2729 if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401)
2730 if ((err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712,
2731 ICEREG(ice, MPU2_CTRL), 1,
2733 &ice->rmidi[1])) < 0) {
2734 snd_card_free(card);
2739 sprintf(card->longname, "%s at 0x%lx, irq %i",
2740 card->shortname, ice->port, ice->irq);
2742 if ((err = snd_card_register(card)) < 0) {
2743 snd_card_free(card);
2746 pci_set_drvdata(pci, card);
2751 static void __devexit snd_ice1712_remove(struct pci_dev *pci)
2753 snd_card_free(pci_get_drvdata(pci));
2754 pci_set_drvdata(pci, NULL);
2757 static struct pci_driver driver = {
2759 .id_table = snd_ice1712_ids,
2760 .probe = snd_ice1712_probe,
2761 .remove = __devexit_p(snd_ice1712_remove),
2764 static int __init alsa_card_ice1712_init(void)
2766 return pci_register_driver(&driver);
2769 static void __exit alsa_card_ice1712_exit(void)
2771 pci_unregister_driver(&driver);
2774 module_init(alsa_card_ice1712_init)
2775 module_exit(alsa_card_ice1712_exit)