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.");
103 #ifndef PCI_VENDOR_ID_ICE
104 #define PCI_VENDOR_ID_ICE 0x1412
106 #ifndef PCI_DEVICE_ID_ICE_1712
107 #define PCI_DEVICE_ID_ICE_1712 0x1712
110 static struct pci_device_id snd_ice1712_ids[] = {
111 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_ICE_1712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* ICE1712 */
115 MODULE_DEVICE_TABLE(pci, snd_ice1712_ids);
117 static int snd_ice1712_build_pro_mixer(ice1712_t *ice);
118 static int snd_ice1712_build_controls(ice1712_t *ice);
120 static int PRO_RATE_LOCKED;
121 static int PRO_RATE_RESET = 1;
122 static unsigned int PRO_RATE_DEFAULT = 44100;
128 /* check whether the clock mode is spdif-in */
129 static inline int is_spdif_master(ice1712_t *ice)
131 return (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER) ? 1 : 0;
134 static inline int is_pro_rate_locked(ice1712_t *ice)
136 return is_spdif_master(ice) || PRO_RATE_LOCKED;
139 static inline void snd_ice1712_ds_write(ice1712_t * ice, u8 channel, u8 addr, u32 data)
141 outb((channel << 4) | addr, ICEDS(ice, INDEX));
142 outl(data, ICEDS(ice, DATA));
145 static inline u32 snd_ice1712_ds_read(ice1712_t * ice, u8 channel, u8 addr)
147 outb((channel << 4) | addr, ICEDS(ice, INDEX));
148 return inl(ICEDS(ice, DATA));
151 static void snd_ice1712_ac97_write(ac97_t *ac97,
155 ice1712_t *ice = (ice1712_t *)ac97->private_data;
157 unsigned char old_cmd = 0;
159 for (tm = 0; tm < 0x10000; tm++) {
160 old_cmd = inb(ICEREG(ice, AC97_CMD));
161 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
163 if (!(old_cmd & ICE1712_AC97_READY))
167 outb(reg, ICEREG(ice, AC97_INDEX));
168 outw(val, ICEREG(ice, AC97_DATA));
169 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
170 outb(old_cmd | ICE1712_AC97_WRITE, ICEREG(ice, AC97_CMD));
171 for (tm = 0; tm < 0x10000; tm++)
172 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
176 static unsigned short snd_ice1712_ac97_read(ac97_t *ac97,
179 ice1712_t *ice = (ice1712_t *)ac97->private_data;
181 unsigned char old_cmd = 0;
183 for (tm = 0; tm < 0x10000; tm++) {
184 old_cmd = inb(ICEREG(ice, AC97_CMD));
185 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
187 if (!(old_cmd & ICE1712_AC97_READY))
191 outb(reg, ICEREG(ice, AC97_INDEX));
192 outb(old_cmd | ICE1712_AC97_READ, ICEREG(ice, AC97_CMD));
193 for (tm = 0; tm < 0x10000; tm++)
194 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
196 if (tm >= 0x10000) /* timeout */
198 return inw(ICEREG(ice, AC97_DATA));
205 static void snd_ice1712_pro_ac97_write(ac97_t *ac97,
209 ice1712_t *ice = (ice1712_t *)ac97->private_data;
211 unsigned char old_cmd = 0;
213 for (tm = 0; tm < 0x10000; tm++) {
214 old_cmd = inb(ICEMT(ice, AC97_CMD));
215 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
217 if (!(old_cmd & ICE1712_AC97_READY))
221 outb(reg, ICEMT(ice, AC97_INDEX));
222 outw(val, ICEMT(ice, AC97_DATA));
223 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
224 outb(old_cmd | ICE1712_AC97_WRITE, ICEMT(ice, AC97_CMD));
225 for (tm = 0; tm < 0x10000; tm++)
226 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
231 static unsigned short snd_ice1712_pro_ac97_read(ac97_t *ac97,
234 ice1712_t *ice = (ice1712_t *)ac97->private_data;
236 unsigned char old_cmd = 0;
238 for (tm = 0; tm < 0x10000; tm++) {
239 old_cmd = inb(ICEMT(ice, AC97_CMD));
240 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
242 if (!(old_cmd & ICE1712_AC97_READY))
246 outb(reg, ICEMT(ice, AC97_INDEX));
247 outb(old_cmd | ICE1712_AC97_READ, ICEMT(ice, AC97_CMD));
248 for (tm = 0; tm < 0x10000; tm++)
249 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
251 if (tm >= 0x10000) /* timeout */
253 return inw(ICEMT(ice, AC97_DATA));
257 * consumer ac97 digital mix
259 static int snd_ice1712_digmix_route_ac97_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
261 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
263 uinfo->value.integer.min = 0;
264 uinfo->value.integer.max = 1;
268 static int snd_ice1712_digmix_route_ac97_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
270 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
272 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0;
276 static int snd_ice1712_digmix_route_ac97_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
278 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
279 unsigned char val, nval;
281 spin_lock_irq(&ice->reg_lock);
282 val = inb(ICEMT(ice, MONITOR_ROUTECTRL));
283 nval = val & ~ICE1712_ROUTE_AC97;
284 if (ucontrol->value.integer.value[0]) nval |= ICE1712_ROUTE_AC97;
285 outb(nval, ICEMT(ice, MONITOR_ROUTECTRL));
286 spin_unlock_irq(&ice->reg_lock);
290 static snd_kcontrol_new_t snd_ice1712_mixer_digmix_route_ac97 __devinitdata = {
291 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
292 .name = "Digital Mixer To AC97",
293 .info = snd_ice1712_digmix_route_ac97_info,
294 .get = snd_ice1712_digmix_route_ac97_get,
295 .put = snd_ice1712_digmix_route_ac97_put,
302 static void snd_ice1712_set_gpio_dir(ice1712_t *ice, unsigned int data)
304 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, data);
305 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
308 static void snd_ice1712_set_gpio_mask(ice1712_t *ice, unsigned int data)
310 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data);
311 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
314 static unsigned int snd_ice1712_get_gpio_data(ice1712_t *ice)
316 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
319 static void snd_ice1712_set_gpio_data(ice1712_t *ice, unsigned int val)
321 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, val);
322 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
333 * change the input clock selection
334 * spdif_clock = 1 - IEC958 input, 0 - Envy24
336 static int snd_ice1712_cs8427_set_input_clock(ice1712_t *ice, int spdif_clock)
338 unsigned char reg[2] = { 0x80 | 4, 0 }; /* CS8427 auto increment | register number 4 + data */
339 unsigned char val, nval;
342 snd_i2c_lock(ice->i2c);
343 if (snd_i2c_sendbytes(ice->cs8427, reg, 1) != 1) {
344 snd_i2c_unlock(ice->i2c);
347 if (snd_i2c_readbytes(ice->cs8427, &val, 1) != 1) {
348 snd_i2c_unlock(ice->i2c);
358 if (snd_i2c_sendbytes(ice->cs8427, reg, 2) != 2) {
364 snd_i2c_unlock(ice->i2c);
371 static void open_cs8427(ice1712_t *ice, snd_pcm_substream_t * substream)
373 snd_cs8427_iec958_active(ice->cs8427, 1);
376 static void close_cs8427(ice1712_t *ice, snd_pcm_substream_t * substream)
378 snd_cs8427_iec958_active(ice->cs8427, 0);
381 static void setup_cs8427(ice1712_t *ice, int rate)
383 snd_cs8427_iec958_pcm(ice->cs8427, rate);
387 * create and initialize callbacks for cs8427 interface
389 int __devinit snd_ice1712_init_cs8427(ice1712_t *ice, int addr)
393 if ((err = snd_cs8427_create(ice->i2c, addr,
394 (ice->cs8427_timeout * HZ) / 1000,
395 &ice->cs8427)) < 0) {
396 snd_printk("CS8427 initialization failed\n");
399 ice->spdif.ops.open = open_cs8427;
400 ice->spdif.ops.close = close_cs8427;
401 ice->spdif.ops.setup_rate = setup_cs8427;
410 static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
412 ice1712_t *ice = dev_id;
413 unsigned char status;
417 status = inb(ICEREG(ice, IRQSTAT));
421 if (status & ICE1712_IRQ_MPU1) {
423 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data, regs);
424 outb(ICE1712_IRQ_MPU1, ICEREG(ice, IRQSTAT));
425 status &= ~ICE1712_IRQ_MPU1;
427 if (status & ICE1712_IRQ_TIMER)
428 outb(ICE1712_IRQ_TIMER, ICEREG(ice, IRQSTAT));
429 if (status & ICE1712_IRQ_MPU2) {
431 snd_mpu401_uart_interrupt(irq, ice->rmidi[1]->private_data, regs);
432 outb(ICE1712_IRQ_MPU2, ICEREG(ice, IRQSTAT));
433 status &= ~ICE1712_IRQ_MPU2;
435 if (status & ICE1712_IRQ_PROPCM) {
436 unsigned char mtstat = inb(ICEMT(ice, IRQ));
437 if (mtstat & ICE1712_MULTI_PBKSTATUS) {
438 if (ice->playback_pro_substream)
439 snd_pcm_period_elapsed(ice->playback_pro_substream);
440 outb(ICE1712_MULTI_PBKSTATUS, ICEMT(ice, IRQ));
442 if (mtstat & ICE1712_MULTI_CAPSTATUS) {
443 if (ice->capture_pro_substream)
444 snd_pcm_period_elapsed(ice->capture_pro_substream);
445 outb(ICE1712_MULTI_CAPSTATUS, ICEMT(ice, IRQ));
448 if (status & ICE1712_IRQ_FM)
449 outb(ICE1712_IRQ_FM, ICEREG(ice, IRQSTAT));
450 if (status & ICE1712_IRQ_PBKDS) {
453 snd_pcm_substream_t *substream;
454 pbkstatus = inw(ICEDS(ice, INTSTAT));
455 //printk("pbkstatus = 0x%x\n", pbkstatus);
456 for (idx = 0; idx < 6; idx++) {
457 if ((pbkstatus & (3 << (idx * 2))) == 0)
459 if ((substream = ice->playback_con_substream_ds[idx]) != NULL)
460 snd_pcm_period_elapsed(substream);
461 outw(3 << (idx * 2), ICEDS(ice, INTSTAT));
463 outb(ICE1712_IRQ_PBKDS, ICEREG(ice, IRQSTAT));
465 if (status & ICE1712_IRQ_CONCAP) {
466 if (ice->capture_con_substream)
467 snd_pcm_period_elapsed(ice->capture_con_substream);
468 outb(ICE1712_IRQ_CONCAP, ICEREG(ice, IRQSTAT));
470 if (status & ICE1712_IRQ_CONPBK) {
471 if (ice->playback_con_substream)
472 snd_pcm_period_elapsed(ice->playback_con_substream);
473 outb(ICE1712_IRQ_CONPBK, ICEREG(ice, IRQSTAT));
476 return IRQ_RETVAL(handled);
484 static int snd_ice1712_hw_params(snd_pcm_substream_t * substream,
485 snd_pcm_hw_params_t * hw_params)
487 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
490 static int snd_ice1712_hw_free(snd_pcm_substream_t * substream)
492 return snd_pcm_lib_free_pages(substream);
496 * PCM part - consumer I/O
499 static int snd_ice1712_playback_trigger(snd_pcm_substream_t * substream,
502 ice1712_t *ice = snd_pcm_substream_chip(substream);
506 spin_lock(&ice->reg_lock);
507 tmp = snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL);
508 if (cmd == SNDRV_PCM_TRIGGER_START) {
510 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
512 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
514 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
519 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
520 spin_unlock(&ice->reg_lock);
524 static int snd_ice1712_playback_ds_trigger(snd_pcm_substream_t * substream,
527 ice1712_t *ice = snd_pcm_substream_chip(substream);
531 spin_lock(&ice->reg_lock);
532 tmp = snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL);
533 if (cmd == SNDRV_PCM_TRIGGER_START) {
535 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
537 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
539 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
544 snd_ice1712_ds_write(ice, substream->number * 2, ICE1712_DSC_CONTROL, tmp);
545 spin_unlock(&ice->reg_lock);
549 static int snd_ice1712_capture_trigger(snd_pcm_substream_t * substream,
552 ice1712_t *ice = snd_pcm_substream_chip(substream);
556 spin_lock(&ice->reg_lock);
557 tmp = snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL);
558 if (cmd == SNDRV_PCM_TRIGGER_START) {
560 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
565 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
566 spin_unlock(&ice->reg_lock);
570 static int snd_ice1712_playback_prepare(snd_pcm_substream_t * substream)
572 ice1712_t *ice = snd_pcm_substream_chip(substream);
573 snd_pcm_runtime_t *runtime = substream->runtime;
574 u32 period_size, buf_size, rate, tmp;
576 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
577 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
579 if (snd_pcm_format_width(runtime->format) == 16)
581 if (runtime->channels == 2)
583 rate = (runtime->rate * 8192) / 375;
584 if (rate > 0x000fffff)
586 spin_lock_irq(&ice->reg_lock);
587 outb(0, ice->ddma_port + 15);
588 outb(ICE1712_DMA_MODE_WRITE | ICE1712_DMA_AUTOINIT, ice->ddma_port + 0x0b);
589 outl(runtime->dma_addr, ice->ddma_port + 0);
590 outw(buf_size, ice->ddma_port + 4);
591 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_LO, rate & 0xff);
592 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_MID, (rate >> 8) & 0xff);
593 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_HI, (rate >> 16) & 0xff);
594 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
595 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_LO, period_size & 0xff);
596 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_HI, period_size >> 8);
597 snd_ice1712_write(ice, ICE1712_IREG_PBK_LEFT, 0);
598 snd_ice1712_write(ice, ICE1712_IREG_PBK_RIGHT, 0);
599 spin_unlock_irq(&ice->reg_lock);
603 static int snd_ice1712_playback_ds_prepare(snd_pcm_substream_t * substream)
605 ice1712_t *ice = snd_pcm_substream_chip(substream);
606 snd_pcm_runtime_t *runtime = substream->runtime;
607 u32 period_size, buf_size, rate, tmp, chn;
609 period_size = snd_pcm_lib_period_bytes(substream) - 1;
610 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
612 if (snd_pcm_format_width(runtime->format) == 16)
614 if (runtime->channels == 2)
616 rate = (runtime->rate * 8192) / 375;
617 if (rate > 0x000fffff)
619 ice->playback_con_active_buf[substream->number] = 0;
620 ice->playback_con_virt_addr[substream->number] = runtime->dma_addr;
621 chn = substream->number * 2;
622 spin_lock_irq(&ice->reg_lock);
623 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR0, runtime->dma_addr);
624 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT0, period_size);
625 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR1, runtime->dma_addr + (runtime->periods > 1 ? period_size + 1 : 0));
626 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT1, period_size);
627 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_RATE, rate);
628 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_VOLUME, 0);
629 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_CONTROL, tmp);
630 if (runtime->channels == 2) {
631 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_RATE, rate);
632 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_VOLUME, 0);
634 spin_unlock_irq(&ice->reg_lock);
638 static int snd_ice1712_capture_prepare(snd_pcm_substream_t * substream)
640 ice1712_t *ice = snd_pcm_substream_chip(substream);
641 snd_pcm_runtime_t *runtime = substream->runtime;
642 u32 period_size, buf_size;
645 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
646 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
648 if (snd_pcm_format_width(runtime->format) == 16)
650 if (runtime->channels == 2)
652 spin_lock_irq(&ice->reg_lock);
653 outl(ice->capture_con_virt_addr = runtime->dma_addr, ICEREG(ice, CONCAP_ADDR));
654 outw(buf_size, ICEREG(ice, CONCAP_COUNT));
655 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_HI, period_size >> 8);
656 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_LO, period_size & 0xff);
657 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
658 spin_unlock_irq(&ice->reg_lock);
659 snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
663 static snd_pcm_uframes_t snd_ice1712_playback_pointer(snd_pcm_substream_t * substream)
665 ice1712_t *ice = snd_pcm_substream_chip(substream);
666 snd_pcm_runtime_t *runtime = substream->runtime;
669 if (!(snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL) & 1))
671 ptr = runtime->buffer_size - inw(ice->ddma_port + 4);
672 if (ptr == runtime->buffer_size)
674 return bytes_to_frames(substream->runtime, ptr);
677 static snd_pcm_uframes_t snd_ice1712_playback_ds_pointer(snd_pcm_substream_t * substream)
679 ice1712_t *ice = snd_pcm_substream_chip(substream);
683 if (!(snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL) & 1))
685 if (ice->playback_con_active_buf[substream->number])
686 addr = ICE1712_DSC_ADDR1;
688 addr = ICE1712_DSC_ADDR0;
689 ptr = snd_ice1712_ds_read(ice, substream->number * 2, addr) -
690 ice->playback_con_virt_addr[substream->number];
691 if (ptr == substream->runtime->buffer_size)
693 return bytes_to_frames(substream->runtime, ptr);
696 static snd_pcm_uframes_t snd_ice1712_capture_pointer(snd_pcm_substream_t * substream)
698 ice1712_t *ice = snd_pcm_substream_chip(substream);
701 if (!(snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL) & 1))
703 ptr = inl(ICEREG(ice, CONCAP_ADDR)) - ice->capture_con_virt_addr;
704 if (ptr == substream->runtime->buffer_size)
706 return bytes_to_frames(substream->runtime, ptr);
709 static snd_pcm_hardware_t snd_ice1712_playback =
711 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
712 SNDRV_PCM_INFO_BLOCK_TRANSFER |
713 SNDRV_PCM_INFO_MMAP_VALID |
714 SNDRV_PCM_INFO_PAUSE),
715 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
716 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
721 .buffer_bytes_max = (64*1024),
722 .period_bytes_min = 64,
723 .period_bytes_max = (64*1024),
729 static snd_pcm_hardware_t snd_ice1712_playback_ds =
731 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
732 SNDRV_PCM_INFO_BLOCK_TRANSFER |
733 SNDRV_PCM_INFO_MMAP_VALID |
734 SNDRV_PCM_INFO_PAUSE),
735 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
736 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
741 .buffer_bytes_max = (128*1024),
742 .period_bytes_min = 64,
743 .period_bytes_max = (128*1024),
749 static snd_pcm_hardware_t snd_ice1712_capture =
751 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
752 SNDRV_PCM_INFO_BLOCK_TRANSFER |
753 SNDRV_PCM_INFO_MMAP_VALID),
754 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
755 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
760 .buffer_bytes_max = (64*1024),
761 .period_bytes_min = 64,
762 .period_bytes_max = (64*1024),
768 static int snd_ice1712_playback_open(snd_pcm_substream_t * substream)
770 snd_pcm_runtime_t *runtime = substream->runtime;
771 ice1712_t *ice = snd_pcm_substream_chip(substream);
773 ice->playback_con_substream = substream;
774 runtime->hw = snd_ice1712_playback;
778 static int snd_ice1712_playback_ds_open(snd_pcm_substream_t * substream)
780 snd_pcm_runtime_t *runtime = substream->runtime;
781 ice1712_t *ice = snd_pcm_substream_chip(substream);
784 ice->playback_con_substream_ds[substream->number] = substream;
785 runtime->hw = snd_ice1712_playback_ds;
786 spin_lock_irq(&ice->reg_lock);
787 tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2));
788 outw(tmp, ICEDS(ice, INTMASK));
789 spin_unlock_irq(&ice->reg_lock);
793 static int snd_ice1712_capture_open(snd_pcm_substream_t * substream)
795 snd_pcm_runtime_t *runtime = substream->runtime;
796 ice1712_t *ice = snd_pcm_substream_chip(substream);
798 ice->capture_con_substream = substream;
799 runtime->hw = snd_ice1712_capture;
800 runtime->hw.rates = ice->ac97->rates[AC97_RATES_ADC];
801 if (!(runtime->hw.rates & SNDRV_PCM_RATE_8000))
802 runtime->hw.rate_min = 48000;
806 static int snd_ice1712_playback_close(snd_pcm_substream_t * substream)
808 ice1712_t *ice = snd_pcm_substream_chip(substream);
810 ice->playback_con_substream = NULL;
814 static int snd_ice1712_playback_ds_close(snd_pcm_substream_t * substream)
816 ice1712_t *ice = snd_pcm_substream_chip(substream);
819 spin_lock_irq(&ice->reg_lock);
820 tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2));
821 outw(tmp, ICEDS(ice, INTMASK));
822 spin_unlock_irq(&ice->reg_lock);
823 ice->playback_con_substream_ds[substream->number] = NULL;
827 static int snd_ice1712_capture_close(snd_pcm_substream_t * substream)
829 ice1712_t *ice = snd_pcm_substream_chip(substream);
831 ice->capture_con_substream = NULL;
835 static snd_pcm_ops_t snd_ice1712_playback_ops = {
836 .open = snd_ice1712_playback_open,
837 .close = snd_ice1712_playback_close,
838 .ioctl = snd_pcm_lib_ioctl,
839 .hw_params = snd_ice1712_hw_params,
840 .hw_free = snd_ice1712_hw_free,
841 .prepare = snd_ice1712_playback_prepare,
842 .trigger = snd_ice1712_playback_trigger,
843 .pointer = snd_ice1712_playback_pointer,
846 static snd_pcm_ops_t snd_ice1712_playback_ds_ops = {
847 .open = snd_ice1712_playback_ds_open,
848 .close = snd_ice1712_playback_ds_close,
849 .ioctl = snd_pcm_lib_ioctl,
850 .hw_params = snd_ice1712_hw_params,
851 .hw_free = snd_ice1712_hw_free,
852 .prepare = snd_ice1712_playback_ds_prepare,
853 .trigger = snd_ice1712_playback_ds_trigger,
854 .pointer = snd_ice1712_playback_ds_pointer,
857 static snd_pcm_ops_t snd_ice1712_capture_ops = {
858 .open = snd_ice1712_capture_open,
859 .close = snd_ice1712_capture_close,
860 .ioctl = snd_pcm_lib_ioctl,
861 .hw_params = snd_ice1712_hw_params,
862 .hw_free = snd_ice1712_hw_free,
863 .prepare = snd_ice1712_capture_prepare,
864 .trigger = snd_ice1712_capture_trigger,
865 .pointer = snd_ice1712_capture_pointer,
868 static void snd_ice1712_pcm_free(snd_pcm_t *pcm)
870 ice1712_t *ice = pcm->private_data;
872 snd_pcm_lib_preallocate_free_for_all(pcm);
875 static int __devinit snd_ice1712_pcm(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
882 err = snd_pcm_new(ice->card, "ICE1712 consumer", device, 1, 1, &pcm);
886 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ops);
887 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_ops);
889 pcm->private_data = ice;
890 pcm->private_free = snd_ice1712_pcm_free;
892 strcpy(pcm->name, "ICE1712 consumer");
895 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
896 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
901 printk(KERN_WARNING "Consumer PCM code does not work well at the moment --jk\n");
906 static void snd_ice1712_pcm_free_ds(snd_pcm_t *pcm)
908 ice1712_t *ice = pcm->private_data;
910 snd_pcm_lib_preallocate_free_for_all(pcm);
913 static int __devinit snd_ice1712_pcm_ds(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
920 err = snd_pcm_new(ice->card, "ICE1712 consumer (DS)", device, 6, 0, &pcm);
924 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ds_ops);
926 pcm->private_data = ice;
927 pcm->private_free = snd_ice1712_pcm_free_ds;
929 strcpy(pcm->name, "ICE1712 consumer (DS)");
932 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
933 snd_dma_pci_data(ice->pci), 64*1024, 128*1024);
942 * PCM code - professional part (multitrack)
945 static unsigned int rates[] = { 8000, 9600, 11025, 12000, 16000, 22050, 24000,
946 32000, 44100, 48000, 64000, 88200, 96000 };
948 static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
949 .count = ARRAY_SIZE(rates),
954 static int snd_ice1712_pro_trigger(snd_pcm_substream_t *substream,
957 ice1712_t *ice = snd_pcm_substream_chip(substream);
959 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
960 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
964 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
966 what = ICE1712_PLAYBACK_PAUSE;
967 snd_pcm_trigger_done(substream, substream);
968 spin_lock(&ice->reg_lock);
969 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
970 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
974 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
975 spin_unlock(&ice->reg_lock);
978 case SNDRV_PCM_TRIGGER_START:
979 case SNDRV_PCM_TRIGGER_STOP:
981 unsigned int what = 0;
983 struct list_head *pos;
984 snd_pcm_substream_t *s;
986 snd_pcm_group_for_each(pos, substream) {
987 s = snd_pcm_group_substream_entry(pos);
988 if (s == ice->playback_pro_substream) {
989 what |= ICE1712_PLAYBACK_START;
990 snd_pcm_trigger_done(s, substream);
991 } else if (s == ice->capture_pro_substream) {
992 what |= ICE1712_CAPTURE_START_SHADOW;
993 snd_pcm_trigger_done(s, substream);
996 spin_lock(&ice->reg_lock);
997 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
998 if (cmd == SNDRV_PCM_TRIGGER_START)
1002 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
1003 spin_unlock(&ice->reg_lock);
1014 static void snd_ice1712_set_pro_rate(ice1712_t *ice, unsigned int rate, int force)
1016 unsigned long flags;
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)) {
1024 spin_unlock_irqrestore(&ice->reg_lock, flags);
1027 if (!force && is_pro_rate_locked(ice)) {
1028 spin_unlock_irqrestore(&ice->reg_lock, flags);
1033 case 8000: val = 6; break;
1034 case 9600: val = 3; break;
1035 case 11025: val = 10; break;
1036 case 12000: val = 2; break;
1037 case 16000: val = 5; break;
1038 case 22050: val = 9; break;
1039 case 24000: val = 1; break;
1040 case 32000: val = 4; break;
1041 case 44100: val = 8; break;
1042 case 48000: val = 0; break;
1043 case 64000: val = 15; break;
1044 case 88200: val = 11; break;
1045 case 96000: val = 7; break;
1052 outb(val, ICEMT(ice, RATE));
1054 spin_unlock_irqrestore(&ice->reg_lock, flags);
1056 if (ice->gpio.set_pro_rate)
1057 ice->gpio.set_pro_rate(ice, rate);
1058 for (i = 0; i < ice->akm_codecs; i++) {
1059 if (ice->akm[i].ops.set_rate_val)
1060 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
1062 if (ice->spdif.ops.setup_rate)
1063 ice->spdif.ops.setup_rate(ice, rate);
1066 static int snd_ice1712_playback_pro_prepare(snd_pcm_substream_t * substream)
1068 ice1712_t *ice = snd_pcm_substream_chip(substream);
1070 ice->playback_pro_size = snd_pcm_lib_buffer_bytes(substream);
1071 spin_lock_irq(&ice->reg_lock);
1072 outl(substream->runtime->dma_addr, ICEMT(ice, PLAYBACK_ADDR));
1073 outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));
1074 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT));
1075 spin_unlock_irq(&ice->reg_lock);
1080 static int snd_ice1712_playback_pro_hw_params(snd_pcm_substream_t * substream,
1081 snd_pcm_hw_params_t * hw_params)
1083 ice1712_t *ice = snd_pcm_substream_chip(substream);
1085 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1086 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1089 static int snd_ice1712_capture_pro_prepare(snd_pcm_substream_t * substream)
1091 ice1712_t *ice = snd_pcm_substream_chip(substream);
1093 ice->capture_pro_size = snd_pcm_lib_buffer_bytes(substream);
1094 spin_lock_irq(&ice->reg_lock);
1095 outl(substream->runtime->dma_addr, ICEMT(ice, CAPTURE_ADDR));
1096 outw((ice->capture_pro_size >> 2) - 1, ICEMT(ice, CAPTURE_SIZE));
1097 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, CAPTURE_COUNT));
1098 spin_unlock_irq(&ice->reg_lock);
1102 static int snd_ice1712_capture_pro_hw_params(snd_pcm_substream_t * substream,
1103 snd_pcm_hw_params_t * hw_params)
1105 ice1712_t *ice = snd_pcm_substream_chip(substream);
1107 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1108 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1111 static snd_pcm_uframes_t snd_ice1712_playback_pro_pointer(snd_pcm_substream_t * substream)
1113 ice1712_t *ice = snd_pcm_substream_chip(substream);
1116 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_PLAYBACK_START))
1118 ptr = ice->playback_pro_size - (inw(ICEMT(ice, PLAYBACK_SIZE)) << 2);
1119 if (ptr == substream->runtime->buffer_size)
1121 return bytes_to_frames(substream->runtime, ptr);
1124 static snd_pcm_uframes_t snd_ice1712_capture_pro_pointer(snd_pcm_substream_t * substream)
1126 ice1712_t *ice = snd_pcm_substream_chip(substream);
1129 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_CAPTURE_START_SHADOW))
1131 ptr = ice->capture_pro_size - (inw(ICEMT(ice, CAPTURE_SIZE)) << 2);
1132 if (ptr == substream->runtime->buffer_size)
1134 return bytes_to_frames(substream->runtime, ptr);
1137 static snd_pcm_hardware_t snd_ice1712_playback_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 = 10 * 4 * 2,
1151 .period_bytes_max = 131040,
1153 .periods_max = 1024,
1157 static snd_pcm_hardware_t snd_ice1712_capture_pro =
1159 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1160 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1161 SNDRV_PCM_INFO_MMAP_VALID |
1162 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1163 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1164 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1169 .buffer_bytes_max = (256*1024),
1170 .period_bytes_min = 12 * 4 * 2,
1171 .period_bytes_max = 131040,
1173 .periods_max = 1024,
1177 static int snd_ice1712_playback_pro_open(snd_pcm_substream_t * substream)
1179 snd_pcm_runtime_t *runtime = substream->runtime;
1180 ice1712_t *ice = snd_pcm_substream_chip(substream);
1182 ice->playback_pro_substream = substream;
1183 runtime->hw = snd_ice1712_playback_pro;
1184 snd_pcm_set_sync(substream);
1185 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1186 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1188 if (ice->spdif.ops.open)
1189 ice->spdif.ops.open(ice, substream);
1194 static int snd_ice1712_capture_pro_open(snd_pcm_substream_t * substream)
1196 ice1712_t *ice = snd_pcm_substream_chip(substream);
1197 snd_pcm_runtime_t *runtime = substream->runtime;
1199 ice->capture_pro_substream = substream;
1200 runtime->hw = snd_ice1712_capture_pro;
1201 snd_pcm_set_sync(substream);
1202 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1203 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1207 static int snd_ice1712_playback_pro_close(snd_pcm_substream_t * substream)
1209 ice1712_t *ice = snd_pcm_substream_chip(substream);
1212 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1213 ice->playback_pro_substream = NULL;
1214 if (ice->spdif.ops.close)
1215 ice->spdif.ops.close(ice, substream);
1220 static int snd_ice1712_capture_pro_close(snd_pcm_substream_t * substream)
1222 ice1712_t *ice = snd_pcm_substream_chip(substream);
1225 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1226 ice->capture_pro_substream = NULL;
1230 static void snd_ice1712_pcm_profi_free(snd_pcm_t *pcm)
1232 ice1712_t *ice = pcm->private_data;
1233 ice->pcm_pro = NULL;
1234 snd_pcm_lib_preallocate_free_for_all(pcm);
1237 static snd_pcm_ops_t snd_ice1712_playback_pro_ops = {
1238 .open = snd_ice1712_playback_pro_open,
1239 .close = snd_ice1712_playback_pro_close,
1240 .ioctl = snd_pcm_lib_ioctl,
1241 .hw_params = snd_ice1712_playback_pro_hw_params,
1242 .hw_free = snd_ice1712_hw_free,
1243 .prepare = snd_ice1712_playback_pro_prepare,
1244 .trigger = snd_ice1712_pro_trigger,
1245 .pointer = snd_ice1712_playback_pro_pointer,
1248 static snd_pcm_ops_t snd_ice1712_capture_pro_ops = {
1249 .open = snd_ice1712_capture_pro_open,
1250 .close = snd_ice1712_capture_pro_close,
1251 .ioctl = snd_pcm_lib_ioctl,
1252 .hw_params = snd_ice1712_capture_pro_hw_params,
1253 .hw_free = snd_ice1712_hw_free,
1254 .prepare = snd_ice1712_capture_pro_prepare,
1255 .trigger = snd_ice1712_pro_trigger,
1256 .pointer = snd_ice1712_capture_pro_pointer,
1259 static int __devinit snd_ice1712_pcm_profi(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
1266 err = snd_pcm_new(ice->card, "ICE1712 multi", device, 1, 1, &pcm);
1270 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_pro_ops);
1271 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_pro_ops);
1273 pcm->private_data = ice;
1274 pcm->private_free = snd_ice1712_pcm_profi_free;
1275 pcm->info_flags = 0;
1276 strcpy(pcm->name, "ICE1712 multi");
1278 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1279 snd_dma_pci_data(ice->pci), 256*1024, 256*1024);
1286 /* assign channels to iec958 */
1287 err = snd_cs8427_iec958_build(ice->cs8427,
1288 pcm->streams[0].substream,
1289 pcm->streams[1].substream);
1294 if ((err = snd_ice1712_build_pro_mixer(ice)) < 0)
1303 static void snd_ice1712_update_volume(ice1712_t *ice, int index)
1305 unsigned int vol = ice->pro_volumes[index];
1306 unsigned short val = 0;
1308 val |= (vol & 0x8000) == 0 ? (96 - (vol & 0x7f)) : 0x7f;
1309 val |= ((vol & 0x80000000) == 0 ? (96 - ((vol >> 16) & 0x7f)) : 0x7f) << 8;
1310 outb(index, ICEMT(ice, MONITOR_INDEX));
1311 outw(val, ICEMT(ice, MONITOR_VOLUME));
1314 static int snd_ice1712_pro_mixer_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1316 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1318 uinfo->value.integer.min = 0;
1319 uinfo->value.integer.max = 1;
1323 static int snd_ice1712_pro_mixer_switch_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1325 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1326 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1328 spin_lock_irq(&ice->reg_lock);
1329 ucontrol->value.integer.value[0] = !((ice->pro_volumes[index] >> 15) & 1);
1330 ucontrol->value.integer.value[1] = !((ice->pro_volumes[index] >> 31) & 1);
1331 spin_unlock_irq(&ice->reg_lock);
1335 static int snd_ice1712_pro_mixer_switch_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1337 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1338 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1339 unsigned int nval, change;
1341 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
1342 (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
1343 spin_lock_irq(&ice->reg_lock);
1344 nval |= ice->pro_volumes[index] & ~0x80008000;
1345 change = nval != ice->pro_volumes[index];
1346 ice->pro_volumes[index] = nval;
1347 snd_ice1712_update_volume(ice, index);
1348 spin_unlock_irq(&ice->reg_lock);
1352 static int snd_ice1712_pro_mixer_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1354 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1356 uinfo->value.integer.min = 0;
1357 uinfo->value.integer.max = 96;
1361 static int snd_ice1712_pro_mixer_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1363 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1364 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1366 spin_lock_irq(&ice->reg_lock);
1367 ucontrol->value.integer.value[0] = (ice->pro_volumes[index] >> 0) & 127;
1368 ucontrol->value.integer.value[1] = (ice->pro_volumes[index] >> 16) & 127;
1369 spin_unlock_irq(&ice->reg_lock);
1373 static int snd_ice1712_pro_mixer_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1375 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1376 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1377 unsigned int nval, change;
1379 nval = (ucontrol->value.integer.value[0] & 127) |
1380 ((ucontrol->value.integer.value[1] & 127) << 16);
1381 spin_lock_irq(&ice->reg_lock);
1382 nval |= ice->pro_volumes[index] & ~0x007f007f;
1383 change = nval != ice->pro_volumes[index];
1384 ice->pro_volumes[index] = nval;
1385 snd_ice1712_update_volume(ice, index);
1386 spin_unlock_irq(&ice->reg_lock);
1391 static snd_kcontrol_new_t snd_ice1712_multi_playback_ctrls[] __devinitdata = {
1393 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1394 .name = "Multi Playback Switch",
1395 .info = snd_ice1712_pro_mixer_switch_info,
1396 .get = snd_ice1712_pro_mixer_switch_get,
1397 .put = snd_ice1712_pro_mixer_switch_put,
1402 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1403 .name = "Multi Playback Volume",
1404 .info = snd_ice1712_pro_mixer_volume_info,
1405 .get = snd_ice1712_pro_mixer_volume_get,
1406 .put = snd_ice1712_pro_mixer_volume_put,
1412 static snd_kcontrol_new_t snd_ice1712_multi_capture_analog_switch __devinitdata = {
1413 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1414 .name = "H/W Multi Capture Switch",
1415 .info = snd_ice1712_pro_mixer_switch_info,
1416 .get = snd_ice1712_pro_mixer_switch_get,
1417 .put = snd_ice1712_pro_mixer_switch_put,
1418 .private_value = 10,
1421 static snd_kcontrol_new_t snd_ice1712_multi_capture_spdif_switch __devinitdata = {
1422 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1423 .name = "IEC958 Multi Capture Switch",
1424 .info = snd_ice1712_pro_mixer_switch_info,
1425 .get = snd_ice1712_pro_mixer_switch_get,
1426 .put = snd_ice1712_pro_mixer_switch_put,
1427 .private_value = 18,
1431 static snd_kcontrol_new_t snd_ice1712_multi_capture_analog_volume __devinitdata = {
1432 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1433 .name = "H/W Multi Capture Volume",
1434 .info = snd_ice1712_pro_mixer_volume_info,
1435 .get = snd_ice1712_pro_mixer_volume_get,
1436 .put = snd_ice1712_pro_mixer_volume_put,
1437 .private_value = 10,
1440 static snd_kcontrol_new_t snd_ice1712_multi_capture_spdif_volume __devinitdata = {
1441 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1442 .name = "IEC958 Multi Capture Volume",
1443 .info = snd_ice1712_pro_mixer_volume_info,
1444 .get = snd_ice1712_pro_mixer_volume_get,
1445 .put = snd_ice1712_pro_mixer_volume_put,
1446 .private_value = 18,
1450 static int __devinit snd_ice1712_build_pro_mixer(ice1712_t *ice)
1452 snd_card_t * card = ice->card;
1456 /* multi-channel mixer */
1457 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_multi_playback_ctrls); idx++) {
1458 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_playback_ctrls[idx], ice));
1463 if (ice->num_total_adcs > 0) {
1464 snd_kcontrol_new_t tmp = snd_ice1712_multi_capture_analog_switch;
1465 tmp.count = ice->num_total_adcs;
1466 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1471 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_switch, ice));
1475 if (ice->num_total_adcs > 0) {
1476 snd_kcontrol_new_t tmp = snd_ice1712_multi_capture_analog_volume;
1477 tmp.count = ice->num_total_adcs;
1478 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1483 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_volume, ice));
1487 /* initialize volumes */
1488 for (idx = 0; idx < 10; idx++) {
1489 ice->pro_volumes[idx] = 0x80008000; /* mute */
1490 snd_ice1712_update_volume(ice, idx);
1492 for (idx = 10; idx < 10 + ice->num_total_adcs; idx++) {
1493 ice->pro_volumes[idx] = 0x80008000; /* mute */
1494 snd_ice1712_update_volume(ice, idx);
1496 for (idx = 18; idx < 20; idx++) {
1497 ice->pro_volumes[idx] = 0x80008000; /* mute */
1498 snd_ice1712_update_volume(ice, idx);
1503 static void snd_ice1712_mixer_free_ac97(ac97_t *ac97)
1505 ice1712_t *ice = ac97->private_data;
1509 static int __devinit snd_ice1712_ac97_mixer(ice1712_t * ice)
1511 int err, bus_num = 0;
1512 ac97_template_t ac97;
1514 static ac97_bus_ops_t con_ops = {
1515 .write = snd_ice1712_ac97_write,
1516 .read = snd_ice1712_ac97_read,
1518 static ac97_bus_ops_t pro_ops = {
1519 .write = snd_ice1712_pro_ac97_write,
1520 .read = snd_ice1712_pro_ac97_read,
1523 if (ice_has_con_ac97(ice)) {
1524 if ((err = snd_ac97_bus(ice->card, bus_num++, &con_ops, NULL, &pbus)) < 0)
1526 memset(&ac97, 0, sizeof(ac97));
1527 ac97.private_data = ice;
1528 ac97.private_free = snd_ice1712_mixer_free_ac97;
1529 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1530 printk(KERN_WARNING "ice1712: cannot initialize ac97 for consumer, skipped\n");
1532 if ((err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice))) < 0)
1538 if (! (ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) {
1539 if ((err = snd_ac97_bus(ice->card, bus_num, &pro_ops, NULL, &pbus)) < 0)
1541 memset(&ac97, 0, sizeof(ac97));
1542 ac97.private_data = ice;
1543 ac97.private_free = snd_ice1712_mixer_free_ac97;
1544 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1545 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1549 /* I2S mixer only */
1550 strcat(ice->card->mixername, "ICE1712 - multitrack");
1558 static inline unsigned int eeprom_double(ice1712_t *ice, int idx)
1560 return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8);
1563 static void snd_ice1712_proc_read(snd_info_entry_t *entry,
1564 snd_info_buffer_t * buffer)
1566 ice1712_t *ice = entry->private_data;
1569 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1570 snd_iprintf(buffer, "EEPROM:\n");
1572 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1573 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1574 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1575 snd_iprintf(buffer, " Codec : 0x%x\n", ice->eeprom.data[ICE_EEP1_CODEC]);
1576 snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP1_ACLINK]);
1577 snd_iprintf(buffer, " I2S ID : 0x%x\n", ice->eeprom.data[ICE_EEP1_I2SID]);
1578 snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP1_SPDIF]);
1579 snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
1580 snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
1581 snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
1582 snd_iprintf(buffer, " AC'97 main : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_MAIN_LO));
1583 snd_iprintf(buffer, " AC'97 pcm : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_PCM_LO));
1584 snd_iprintf(buffer, " AC'97 record : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_REC_LO));
1585 snd_iprintf(buffer, " AC'97 record src : 0x%x\n", ice->eeprom.data[ICE_EEP1_AC97_RECSRC]);
1586 for (idx = 0; idx < 4; idx++)
1587 snd_iprintf(buffer, " DAC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_DAC_ID + idx]);
1588 for (idx = 0; idx < 4; idx++)
1589 snd_iprintf(buffer, " ADC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_ADC_ID + idx]);
1590 for (idx = 0x1c; idx < ice->eeprom.size; idx++)
1591 snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
1593 snd_iprintf(buffer, "\nRegisters:\n");
1594 snd_iprintf(buffer, " PSDOUT03 : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_PSDOUT03)));
1595 snd_iprintf(buffer, " CAPTURE : 0x%08x\n", inl(ICEMT(ice, ROUTE_CAPTURE)));
1596 snd_iprintf(buffer, " SPDOUT : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT)));
1597 snd_iprintf(buffer, " RATE : 0x%02x\n", (unsigned)inb(ICEMT(ice, RATE)));
1600 static void __devinit snd_ice1712_proc_init(ice1712_t * ice)
1602 snd_info_entry_t *entry;
1604 if (! snd_card_proc_new(ice->card, "ice1712", &entry))
1605 snd_info_set_text_ops(entry, ice, 1024, snd_ice1712_proc_read);
1612 static int snd_ice1712_eeprom_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1614 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1615 uinfo->count = sizeof(ice1712_eeprom_t);
1619 static int snd_ice1712_eeprom_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1621 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1623 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1627 static snd_kcontrol_new_t snd_ice1712_eeprom __devinitdata = {
1628 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1629 .name = "ICE1712 EEPROM",
1630 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1631 .info = snd_ice1712_eeprom_info,
1632 .get = snd_ice1712_eeprom_get
1637 static int snd_ice1712_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1639 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1644 static int snd_ice1712_spdif_default_get(snd_kcontrol_t * kcontrol,
1645 snd_ctl_elem_value_t * ucontrol)
1647 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1648 if (ice->spdif.ops.default_get)
1649 ice->spdif.ops.default_get(ice, ucontrol);
1653 static int snd_ice1712_spdif_default_put(snd_kcontrol_t * kcontrol,
1654 snd_ctl_elem_value_t * ucontrol)
1656 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1657 if (ice->spdif.ops.default_put)
1658 return ice->spdif.ops.default_put(ice, ucontrol);
1662 static snd_kcontrol_new_t snd_ice1712_spdif_default __devinitdata =
1664 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1665 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1666 .info = snd_ice1712_spdif_info,
1667 .get = snd_ice1712_spdif_default_get,
1668 .put = snd_ice1712_spdif_default_put
1671 static int snd_ice1712_spdif_maskc_get(snd_kcontrol_t * kcontrol,
1672 snd_ctl_elem_value_t * ucontrol)
1674 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1675 if (ice->spdif.ops.default_get) {
1676 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1677 IEC958_AES0_PROFESSIONAL |
1678 IEC958_AES0_CON_NOT_COPYRIGHT |
1679 IEC958_AES0_CON_EMPHASIS;
1680 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1681 IEC958_AES1_CON_CATEGORY;
1682 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1684 ucontrol->value.iec958.status[0] = 0xff;
1685 ucontrol->value.iec958.status[1] = 0xff;
1686 ucontrol->value.iec958.status[2] = 0xff;
1687 ucontrol->value.iec958.status[3] = 0xff;
1688 ucontrol->value.iec958.status[4] = 0xff;
1693 static int snd_ice1712_spdif_maskp_get(snd_kcontrol_t * kcontrol,
1694 snd_ctl_elem_value_t * ucontrol)
1696 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1697 if (ice->spdif.ops.default_get) {
1698 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1699 IEC958_AES0_PROFESSIONAL |
1700 IEC958_AES0_PRO_FS |
1701 IEC958_AES0_PRO_EMPHASIS;
1702 ucontrol->value.iec958.status[1] = IEC958_AES1_PRO_MODE;
1704 ucontrol->value.iec958.status[0] = 0xff;
1705 ucontrol->value.iec958.status[1] = 0xff;
1706 ucontrol->value.iec958.status[2] = 0xff;
1707 ucontrol->value.iec958.status[3] = 0xff;
1708 ucontrol->value.iec958.status[4] = 0xff;
1713 static snd_kcontrol_new_t snd_ice1712_spdif_maskc __devinitdata =
1715 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1716 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1717 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1718 .info = snd_ice1712_spdif_info,
1719 .get = snd_ice1712_spdif_maskc_get,
1722 static snd_kcontrol_new_t snd_ice1712_spdif_maskp __devinitdata =
1724 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1725 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1726 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1727 .info = snd_ice1712_spdif_info,
1728 .get = snd_ice1712_spdif_maskp_get,
1731 static int snd_ice1712_spdif_stream_get(snd_kcontrol_t * kcontrol,
1732 snd_ctl_elem_value_t * ucontrol)
1734 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1735 if (ice->spdif.ops.stream_get)
1736 ice->spdif.ops.stream_get(ice, ucontrol);
1740 static int snd_ice1712_spdif_stream_put(snd_kcontrol_t * kcontrol,
1741 snd_ctl_elem_value_t * ucontrol)
1743 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1744 if (ice->spdif.ops.stream_put)
1745 return ice->spdif.ops.stream_put(ice, ucontrol);
1749 static snd_kcontrol_new_t snd_ice1712_spdif_stream __devinitdata =
1751 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1752 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1753 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
1754 .info = snd_ice1712_spdif_info,
1755 .get = snd_ice1712_spdif_stream_get,
1756 .put = snd_ice1712_spdif_stream_put
1759 int snd_ice1712_gpio_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1761 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1763 uinfo->value.integer.min = 0;
1764 uinfo->value.integer.max = 1;
1768 int snd_ice1712_gpio_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1770 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1771 unsigned char mask = kcontrol->private_value & 0xff;
1772 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1774 snd_ice1712_save_gpio_status(ice);
1775 ucontrol->value.integer.value[0] = (snd_ice1712_gpio_read(ice) & mask ? 1 : 0) ^ invert;
1776 snd_ice1712_restore_gpio_status(ice);
1780 int snd_ice1712_gpio_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1782 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1783 unsigned char mask = kcontrol->private_value & 0xff;
1784 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1785 unsigned int val, nval;
1787 if (kcontrol->private_value & (1 << 31))
1789 nval = (ucontrol->value.integer.value[0] ? mask : 0) ^ invert;
1790 snd_ice1712_save_gpio_status(ice);
1791 val = snd_ice1712_gpio_read(ice);
1792 nval |= val & ~mask;
1794 snd_ice1712_gpio_write(ice, nval);
1795 snd_ice1712_restore_gpio_status(ice);
1802 static int snd_ice1712_pro_internal_clock_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1804 static char *texts[] = {
1807 "11025", /* 2: 10 */
1815 "64000", /* 10: 15 */
1816 "88200", /* 11: 11 */
1817 "96000", /* 12: 7 */
1818 "IEC958 Input", /* 13: -- */
1820 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1822 uinfo->value.enumerated.items = 14;
1823 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1824 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1825 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1829 static int snd_ice1712_pro_internal_clock_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1831 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1832 static unsigned char xlate[16] = {
1833 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10
1837 spin_lock_irq(&ice->reg_lock);
1838 if (is_spdif_master(ice)) {
1839 ucontrol->value.enumerated.item[0] = 13;
1841 val = xlate[inb(ICEMT(ice, RATE)) & 15];
1846 ucontrol->value.enumerated.item[0] = val;
1848 spin_unlock_irq(&ice->reg_lock);
1852 static int snd_ice1712_pro_internal_clock_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1854 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1855 static unsigned int xrate[13] = {
1856 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1857 32000, 44100, 48000, 64000, 88200, 96000
1862 spin_lock_irq(&ice->reg_lock);
1863 oval = inb(ICEMT(ice, RATE));
1864 if (ucontrol->value.enumerated.item[0] == 13) {
1865 outb(oval | ICE1712_SPDIF_MASTER, ICEMT(ice, RATE));
1867 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1868 spin_unlock_irq(&ice->reg_lock);
1869 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1870 spin_lock_irq(&ice->reg_lock);
1872 change = inb(ICEMT(ice, RATE)) != oval;
1873 spin_unlock_irq(&ice->reg_lock);
1875 if ((oval & ICE1712_SPDIF_MASTER) != (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER)) {
1876 /* change CS8427 clock source too */
1878 snd_ice1712_cs8427_set_input_clock(ice, is_spdif_master(ice));
1880 /* notify ak4524 chip as well */
1881 if (is_spdif_master(ice)) {
1883 for (i = 0; i < ice->akm_codecs; i++) {
1884 if (ice->akm[i].ops.set_rate_val)
1885 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
1893 static snd_kcontrol_new_t snd_ice1712_pro_internal_clock __devinitdata = {
1894 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1895 .name = "Multi Track Internal Clock",
1896 .info = snd_ice1712_pro_internal_clock_info,
1897 .get = snd_ice1712_pro_internal_clock_get,
1898 .put = snd_ice1712_pro_internal_clock_put
1901 static int snd_ice1712_pro_internal_clock_default_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1903 static char *texts[] = {
1906 "11025", /* 2: 10 */
1914 "64000", /* 10: 15 */
1915 "88200", /* 11: 11 */
1916 "96000", /* 12: 7 */
1917 // "IEC958 Input", /* 13: -- */
1919 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1921 uinfo->value.enumerated.items = 13;
1922 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1923 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1924 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1928 static int snd_ice1712_pro_internal_clock_default_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1931 static unsigned int xrate[13] = {
1932 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1933 32000, 44100, 48000, 64000, 88200, 96000
1936 for (val = 0; val < 13; val++) {
1937 if (xrate[val] == PRO_RATE_DEFAULT)
1941 ucontrol->value.enumerated.item[0] = val;
1945 static int snd_ice1712_pro_internal_clock_default_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1947 static unsigned int xrate[13] = {
1948 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1949 32000, 44100, 48000, 64000, 88200, 96000
1954 oval = PRO_RATE_DEFAULT;
1955 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1956 change = PRO_RATE_DEFAULT != oval;
1961 static snd_kcontrol_new_t snd_ice1712_pro_internal_clock_default __devinitdata = {
1962 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1963 .name = "Multi Track Internal Clock Default",
1964 .info = snd_ice1712_pro_internal_clock_default_info,
1965 .get = snd_ice1712_pro_internal_clock_default_get,
1966 .put = snd_ice1712_pro_internal_clock_default_put
1969 static int snd_ice1712_pro_rate_locking_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1971 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1973 uinfo->value.integer.min = 0;
1974 uinfo->value.integer.max = 1;
1978 static int snd_ice1712_pro_rate_locking_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1980 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1984 static int snd_ice1712_pro_rate_locking_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1986 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
1987 int change = 0, nval;
1989 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1990 spin_lock_irq(&ice->reg_lock);
1991 change = PRO_RATE_LOCKED != nval;
1992 PRO_RATE_LOCKED = nval;
1993 spin_unlock_irq(&ice->reg_lock);
1997 static snd_kcontrol_new_t snd_ice1712_pro_rate_locking __devinitdata = {
1998 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1999 .name = "Multi Track Rate Locking",
2000 .info = snd_ice1712_pro_rate_locking_info,
2001 .get = snd_ice1712_pro_rate_locking_get,
2002 .put = snd_ice1712_pro_rate_locking_put
2005 static int snd_ice1712_pro_rate_reset_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2007 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2009 uinfo->value.integer.min = 0;
2010 uinfo->value.integer.max = 1;
2014 static int snd_ice1712_pro_rate_reset_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2016 ucontrol->value.integer.value[0] = PRO_RATE_RESET;
2020 static int snd_ice1712_pro_rate_reset_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2022 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2023 int change = 0, nval;
2025 nval = ucontrol->value.integer.value[0] ? 1 : 0;
2026 spin_lock_irq(&ice->reg_lock);
2027 change = PRO_RATE_RESET != nval;
2028 PRO_RATE_RESET = nval;
2029 spin_unlock_irq(&ice->reg_lock);
2033 static snd_kcontrol_new_t snd_ice1712_pro_rate_reset __devinitdata = {
2034 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2035 .name = "Multi Track Rate Reset",
2036 .info = snd_ice1712_pro_rate_reset_info,
2037 .get = snd_ice1712_pro_rate_reset_get,
2038 .put = snd_ice1712_pro_rate_reset_put
2044 static int snd_ice1712_pro_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2046 static char *texts[] = {
2048 "H/W In 0", "H/W In 1", "H/W In 2", "H/W In 3", /* 1-4 */
2049 "H/W In 4", "H/W In 5", "H/W In 6", "H/W In 7", /* 5-8 */
2050 "IEC958 In L", "IEC958 In R", /* 9-10 */
2051 "Digital Mixer", /* 11 - optional */
2054 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2056 uinfo->value.enumerated.items = snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
2057 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2058 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2059 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2063 static int snd_ice1712_pro_route_analog_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
2065 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2066 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2067 unsigned int val, cval;
2069 spin_lock_irq(&ice->reg_lock);
2070 val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2071 cval = inl(ICEMT(ice, ROUTE_CAPTURE));
2072 spin_unlock_irq(&ice->reg_lock);
2074 val >>= ((idx % 2) * 8) + ((idx / 2) * 2);
2076 cval >>= ((idx / 2) * 8) + ((idx % 2) * 4);
2077 if (val == 1 && idx < 2)
2078 ucontrol->value.enumerated.item[0] = 11;
2080 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2082 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2084 ucontrol->value.enumerated.item[0] = 0;
2088 static int snd_ice1712_pro_route_analog_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
2090 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2092 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2093 unsigned int val, old_val, nval;
2096 if (ucontrol->value.enumerated.item[0] >= 11)
2097 nval = idx < 2 ? 1 : 0; /* dig mixer (or pcm) */
2098 else if (ucontrol->value.enumerated.item[0] >= 9)
2099 nval = 3; /* spdif in */
2100 else if (ucontrol->value.enumerated.item[0] >= 1)
2101 nval = 2; /* analog in */
2104 shift = ((idx % 2) * 8) + ((idx / 2) * 2);
2105 spin_lock_irq(&ice->reg_lock);
2106 val = old_val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2107 val &= ~(0x03 << shift);
2108 val |= nval << shift;
2109 change = val != old_val;
2111 outw(val, ICEMT(ice, ROUTE_PSDOUT03));
2112 spin_unlock_irq(&ice->reg_lock);
2113 if (nval < 2) /* dig mixer of pcm */
2116 /* update CAPTURE */
2117 spin_lock_irq(&ice->reg_lock);
2118 val = old_val = inl(ICEMT(ice, ROUTE_CAPTURE));
2119 shift = ((idx / 2) * 8) + ((idx % 2) * 4);
2120 if (nval == 2) { /* analog in */
2121 nval = ucontrol->value.enumerated.item[0] - 1;
2122 val &= ~(0x07 << shift);
2123 val |= nval << shift;
2124 } else { /* spdif in */
2125 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2126 val &= ~(0x08 << shift);
2127 val |= nval << shift;
2129 if (val != old_val) {
2131 outl(val, ICEMT(ice, ROUTE_CAPTURE));
2133 spin_unlock_irq(&ice->reg_lock);
2137 static int snd_ice1712_pro_route_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
2139 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2140 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2141 unsigned int val, cval;
2142 val = inw(ICEMT(ice, ROUTE_SPDOUT));
2143 cval = (val >> (idx * 4 + 8)) & 0x0f;
2144 val = (val >> (idx * 2)) & 0x03;
2146 ucontrol->value.enumerated.item[0] = 11;
2148 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2150 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2152 ucontrol->value.enumerated.item[0] = 0;
2156 static int snd_ice1712_pro_route_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
2158 ice1712_t *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 snd_kcontrol_new_t 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 snd_kcontrol_new_t snd_ice1712_mixer_pro_spdif_route __devinitdata = {
2203 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2204 .name = "IEC958 Playback 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(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * 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(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2223 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2225 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE));
2229 static int snd_ice1712_pro_volume_rate_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2231 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2234 spin_lock_irq(&ice->reg_lock);
2235 change = inb(ICEMT(ice, MONITOR_RATE)) != ucontrol->value.integer.value[0];
2236 outb(ucontrol->value.integer.value[0], ICEMT(ice, MONITOR_RATE));
2237 spin_unlock_irq(&ice->reg_lock);
2241 static snd_kcontrol_new_t snd_ice1712_mixer_pro_volume_rate __devinitdata = {
2242 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2243 .name = "Multi Track Volume Rate",
2244 .info = snd_ice1712_pro_volume_rate_info,
2245 .get = snd_ice1712_pro_volume_rate_get,
2246 .put = snd_ice1712_pro_volume_rate_put
2249 static int snd_ice1712_pro_peak_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2251 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2253 uinfo->value.integer.min = 0;
2254 uinfo->value.integer.max = 255;
2258 static int snd_ice1712_pro_peak_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2260 ice1712_t *ice = snd_kcontrol_chip(kcontrol);
2263 spin_lock_irq(&ice->reg_lock);
2264 for (idx = 0; idx < 22; idx++) {
2265 outb(idx, ICEMT(ice, MONITOR_PEAKINDEX));
2266 ucontrol->value.integer.value[idx] = inb(ICEMT(ice, MONITOR_PEAKDATA));
2268 spin_unlock_irq(&ice->reg_lock);
2272 static snd_kcontrol_new_t snd_ice1712_mixer_pro_peak __devinitdata = {
2273 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2274 .name = "Multi Track Peak",
2275 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2276 .info = snd_ice1712_pro_peak_info,
2277 .get = snd_ice1712_pro_peak_get
2285 * list of available boards
2287 static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
2288 snd_ice1712_hoontech_cards,
2289 snd_ice1712_delta_cards,
2290 snd_ice1712_ews_cards,
2294 static unsigned char __devinit snd_ice1712_read_i2c(ice1712_t *ice,
2300 outb(addr, ICEREG(ice, I2C_BYTE_ADDR));
2301 outb(dev & ~ICE1712_I2C_WRITE, ICEREG(ice, I2C_DEV_ADDR));
2302 while (t-- > 0 && (inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_BUSY)) ;
2303 return inb(ICEREG(ice, I2C_DATA));
2306 static int __devinit snd_ice1712_read_eeprom(ice1712_t *ice, const char *modelname)
2308 int dev = 0xa0; /* EEPROM device address */
2309 unsigned int i, size;
2310 struct snd_ice1712_card_info **tbl, *c;
2312 if (! modelname || ! *modelname) {
2313 ice->eeprom.subvendor = 0;
2314 if ((inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_EEPROM) != 0)
2315 ice->eeprom.subvendor = (snd_ice1712_read_i2c(ice, dev, 0x00) << 0) |
2316 (snd_ice1712_read_i2c(ice, dev, 0x01) << 8) |
2317 (snd_ice1712_read_i2c(ice, dev, 0x02) << 16) |
2318 (snd_ice1712_read_i2c(ice, dev, 0x03) << 24);
2319 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
2320 /* invalid subvendor from EEPROM, try the PCI subststem ID instead */
2322 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID, &vendor);
2323 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
2324 ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device);
2325 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
2326 printk(KERN_ERR "ice1712: No valid ID is found\n");
2331 for (tbl = card_tables; *tbl; tbl++) {
2332 for (c = *tbl; c->subvendor; c++) {
2333 if (modelname && c->model && ! strcmp(modelname, c->model)) {
2334 printk(KERN_INFO "ice1712: Using board model %s\n", c->name);
2335 ice->eeprom.subvendor = c->subvendor;
2336 } else if (c->subvendor != ice->eeprom.subvendor)
2338 if (! c->eeprom_size || ! c->eeprom_data)
2340 /* if the EEPROM is given by the driver, use it */
2341 snd_printdd("using the defined eeprom..\n");
2342 ice->eeprom.version = 1;
2343 ice->eeprom.size = c->eeprom_size + 6;
2344 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
2348 printk(KERN_WARNING "ice1712: No matching model found for ID 0x%x\n", ice->eeprom.subvendor);
2351 ice->eeprom.size = snd_ice1712_read_i2c(ice, dev, 0x04);
2352 if (ice->eeprom.size < 6)
2353 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */
2354 else if (ice->eeprom.size > 32) {
2355 snd_printk("invalid EEPROM (size = %i)\n", ice->eeprom.size);
2358 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05);
2359 if (ice->eeprom.version != 1) {
2360 snd_printk("invalid EEPROM version %i\n", ice->eeprom.version);
2363 size = ice->eeprom.size - 6;
2364 for (i = 0; i < size; i++)
2365 ice->eeprom.data[i] = snd_ice1712_read_i2c(ice, dev, i + 6);
2368 ice->eeprom.gpiomask = ice->eeprom.data[ICE_EEP1_GPIO_MASK];
2369 ice->eeprom.gpiostate = ice->eeprom.data[ICE_EEP1_GPIO_STATE];
2370 ice->eeprom.gpiodir = ice->eeprom.data[ICE_EEP1_GPIO_DIR];
2377 static int __devinit snd_ice1712_chip_init(ice1712_t *ice)
2379 outb(ICE1712_RESET | ICE1712_NATIVE, ICEREG(ice, CONTROL));
2381 outb(ICE1712_NATIVE, ICEREG(ice, CONTROL));
2383 pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]);
2384 pci_write_config_byte(ice->pci, 0x61, ice->eeprom.data[ICE_EEP1_ACLINK]);
2385 pci_write_config_byte(ice->pci, 0x62, ice->eeprom.data[ICE_EEP1_I2SID]);
2386 pci_write_config_byte(ice->pci, 0x63, ice->eeprom.data[ICE_EEP1_SPDIF]);
2387 if (ice->eeprom.subvendor != ICE1712_SUBDEVICE_STDSP24) {
2388 ice->gpio.write_mask = ice->eeprom.gpiomask;
2389 ice->gpio.direction = ice->eeprom.gpiodir;
2390 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ice->eeprom.gpiomask);
2391 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->eeprom.gpiodir);
2392 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ice->eeprom.gpiostate);
2394 ice->gpio.write_mask = 0xc0;
2395 ice->gpio.direction = 0xff;
2396 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, 0xc0);
2397 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, 0xff);
2398 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ICE1712_STDSP24_CLOCK_BIT);
2400 snd_ice1712_write(ice, ICE1712_IREG_PRO_POWERDOWN, 0);
2401 if (!(ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97)) {
2402 outb(ICE1712_AC97_WARM, ICEREG(ice, AC97_CMD));
2404 outb(0, ICEREG(ice, AC97_CMD));
2406 snd_ice1712_write(ice, ICE1712_IREG_CONSUMER_POWERDOWN, 0);
2412 int __devinit snd_ice1712_spdif_build_controls(ice1712_t *ice)
2415 snd_kcontrol_t *kctl;
2417 snd_assert(ice->pcm_pro != NULL, return -EIO);
2418 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_default, ice));
2421 kctl->id.device = ice->pcm_pro->device;
2422 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskc, ice));
2425 kctl->id.device = ice->pcm_pro->device;
2426 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskp, ice));
2429 kctl->id.device = ice->pcm_pro->device;
2430 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_stream, ice));
2433 kctl->id.device = ice->pcm_pro->device;
2434 ice->spdif.stream_ctl = kctl;
2439 static int __devinit snd_ice1712_build_controls(ice1712_t *ice)
2443 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_eeprom, ice));
2446 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock, ice));
2449 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock_default, ice));
2453 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_locking, ice));
2456 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_reset, ice));
2460 if (ice->num_total_dacs > 0) {
2461 snd_kcontrol_new_t tmp = snd_ice1712_mixer_pro_analog_route;
2462 tmp.count = ice->num_total_dacs;
2463 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2468 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice));
2472 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
2475 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice));
2482 static int snd_ice1712_free(ice1712_t *ice)
2486 /* mask all interrupts */
2487 outb(0xc0, ICEMT(ice, IRQ));
2488 outb(0xff, ICEREG(ice, IRQMASK));
2491 if (ice->irq >= 0) {
2492 synchronize_irq(ice->irq);
2493 free_irq(ice->irq, (void *) ice);
2496 pci_release_regions(ice->pci);
2497 snd_ice1712_akm4xxx_free(ice);
2498 pci_disable_device(ice->pci);
2503 static int snd_ice1712_dev_free(snd_device_t *device)
2505 ice1712_t *ice = device->device_data;
2506 return snd_ice1712_free(ice);
2509 static int __devinit snd_ice1712_create(snd_card_t * card,
2510 struct pci_dev *pci,
2511 const char *modelname,
2514 ice1712_t ** r_ice1712)
2518 static snd_device_ops_t ops = {
2519 .dev_free = snd_ice1712_dev_free,
2524 /* enable PCI device */
2525 if ((err = pci_enable_device(pci)) < 0)
2527 /* check, if we can restrict PCI DMA transfers to 28 bits */
2528 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 ||
2529 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) {
2530 snd_printk("architecture does not support 28bit PCI busmaster DMA\n");
2531 pci_disable_device(pci);
2535 ice = kcalloc(1, sizeof(*ice), GFP_KERNEL);
2537 pci_disable_device(pci);
2540 ice->omni = omni ? 1 : 0;
2541 if (cs8427_timeout < 1)
2543 else if (cs8427_timeout > 1000)
2544 cs8427_timeout = 1000;
2545 ice->cs8427_timeout = cs8427_timeout;
2546 spin_lock_init(&ice->reg_lock);
2547 init_MUTEX(&ice->gpio_mutex);
2548 init_MUTEX(&ice->open_mutex);
2549 ice->gpio.set_mask = snd_ice1712_set_gpio_mask;
2550 ice->gpio.set_dir = snd_ice1712_set_gpio_dir;
2551 ice->gpio.set_data = snd_ice1712_set_gpio_data;
2552 ice->gpio.get_data = snd_ice1712_get_gpio_data;
2554 ice->spdif.cs8403_bits =
2555 ice->spdif.cs8403_stream_bits = (0x01 | /* consumer format */
2556 0x10 | /* no emphasis */
2557 0x20); /* PCM encoder/decoder */
2561 pci_set_master(pci);
2562 pci_write_config_word(ice->pci, 0x40, 0x807f);
2563 pci_write_config_word(ice->pci, 0x42, 0x0006);
2564 snd_ice1712_proc_init(ice);
2565 synchronize_irq(pci->irq);
2567 if ((err = pci_request_regions(pci, "ICE1712")) < 0) {
2569 pci_disable_device(pci);
2572 ice->port = pci_resource_start(pci, 0);
2573 ice->ddma_port = pci_resource_start(pci, 1);
2574 ice->dmapath_port = pci_resource_start(pci, 2);
2575 ice->profi_port = pci_resource_start(pci, 3);
2577 if (request_irq(pci->irq, snd_ice1712_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1712", (void *) ice)) {
2578 snd_printk("unable to grab IRQ %d\n", pci->irq);
2579 snd_ice1712_free(ice);
2583 ice->irq = pci->irq;
2585 if (snd_ice1712_read_eeprom(ice, modelname) < 0) {
2586 snd_ice1712_free(ice);
2589 if (snd_ice1712_chip_init(ice) < 0) {
2590 snd_ice1712_free(ice);
2594 /* unmask used interrupts */
2595 outb((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) == 0 ? ICE1712_IRQ_MPU2 : 0 |
2596 (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97) ? ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0,
2597 ICEREG(ice, IRQMASK));
2598 outb(0x00, ICEMT(ice, IRQ));
2600 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2601 snd_ice1712_free(ice);
2605 snd_card_set_dev(card, &pci->dev);
2618 static struct snd_ice1712_card_info no_matched __devinitdata;
2620 static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2621 const struct pci_device_id *pci_id)
2626 int pcm_dev = 0, err;
2627 struct snd_ice1712_card_info **tbl, *c;
2629 if (dev >= SNDRV_CARDS)
2636 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2640 strcpy(card->driver, "ICE1712");
2641 strcpy(card->shortname, "ICEnsemble ICE1712");
2643 if ((err = snd_ice1712_create(card, pci, model[dev], omni[dev], cs8427_timeout[dev], &ice)) < 0) {
2644 snd_card_free(card);
2648 for (tbl = card_tables; *tbl; tbl++) {
2649 for (c = *tbl; c->subvendor; c++) {
2650 if (c->subvendor == ice->eeprom.subvendor) {
2651 strcpy(card->shortname, c->name);
2652 if (c->driver) /* specific driver? */
2653 strcpy(card->driver, c->driver);
2655 if ((err = c->chip_init(ice)) < 0) {
2656 snd_card_free(card);
2667 if ((err = snd_ice1712_pcm_profi(ice, pcm_dev++, NULL)) < 0) {
2668 snd_card_free(card);
2672 if (ice_has_con_ac97(ice))
2673 if ((err = snd_ice1712_pcm(ice, pcm_dev++, NULL)) < 0) {
2674 snd_card_free(card);
2678 if ((err = snd_ice1712_ac97_mixer(ice)) < 0) {
2679 snd_card_free(card);
2683 if ((err = snd_ice1712_build_controls(ice)) < 0) {
2684 snd_card_free(card);
2688 if (c->build_controls) {
2689 if ((err = c->build_controls(ice)) < 0) {
2690 snd_card_free(card);
2695 if (ice_has_con_ac97(ice))
2696 if ((err = snd_ice1712_pcm_ds(ice, pcm_dev++, NULL)) < 0) {
2697 snd_card_free(card);
2701 if (! c->no_mpu401) {
2702 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2703 ICEREG(ice, MPU1_CTRL), 1,
2705 &ice->rmidi[0])) < 0) {
2706 snd_card_free(card);
2710 if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401)
2711 if ((err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712,
2712 ICEREG(ice, MPU2_CTRL), 1,
2714 &ice->rmidi[1])) < 0) {
2715 snd_card_free(card);
2720 sprintf(card->longname, "%s at 0x%lx, irq %i",
2721 card->shortname, ice->port, ice->irq);
2723 if ((err = snd_card_register(card)) < 0) {
2724 snd_card_free(card);
2727 pci_set_drvdata(pci, card);
2732 static void __devexit snd_ice1712_remove(struct pci_dev *pci)
2734 snd_card_free(pci_get_drvdata(pci));
2735 pci_set_drvdata(pci, NULL);
2738 static struct pci_driver driver = {
2740 .id_table = snd_ice1712_ids,
2741 .probe = snd_ice1712_probe,
2742 .remove = __devexit_p(snd_ice1712_remove),
2745 static int __init alsa_card_ice1712_init(void)
2747 return pci_module_init(&driver);
2750 static void __exit alsa_card_ice1712_exit(void)
2752 pci_unregister_driver(&driver);
2755 module_init(alsa_card_ice1712_init)
2756 module_exit(alsa_card_ice1712_exit)