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 */
90 static int dxr_enable
[SNDRV_CARDS
]; /* DXR enable for DMX6FIRE */
92 module_param_array(index
, int, NULL
, 0444);
93 MODULE_PARM_DESC(index
, "Index value for ICE1712 soundcard.");
94 module_param_array(id
, charp
, NULL
, 0444);
95 MODULE_PARM_DESC(id
, "ID string for ICE1712 soundcard.");
96 module_param_array(enable
, bool, NULL
, 0444);
97 MODULE_PARM_DESC(enable
, "Enable ICE1712 soundcard.");
98 module_param_array(omni
, bool, NULL
, 0444);
99 MODULE_PARM_DESC(omni
, "Enable Midiman M-Audio Delta Omni I/O support.");
100 module_param_array(cs8427_timeout
, int, NULL
, 0444);
101 MODULE_PARM_DESC(cs8427_timeout
, "Define reset timeout for cs8427 chip in msec resolution.");
102 module_param_array(model
, charp
, NULL
, 0444);
103 MODULE_PARM_DESC(model
, "Use the given board model.");
104 module_param_array(dxr_enable
, int, NULL
, 0444);
105 MODULE_PARM_DESC(dxr_enable
, "Enable DXR support for Terratec DMX6FIRE.");
108 static struct pci_device_id snd_ice1712_ids
[] = {
109 { PCI_VENDOR_ID_ICE
, PCI_DEVICE_ID_ICE_1712
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 }, /* ICE1712 */
113 MODULE_DEVICE_TABLE(pci
, snd_ice1712_ids
);
115 static int snd_ice1712_build_pro_mixer(struct snd_ice1712
*ice
);
116 static int snd_ice1712_build_controls(struct snd_ice1712
*ice
);
118 static int PRO_RATE_LOCKED
;
119 static int PRO_RATE_RESET
= 1;
120 static unsigned int PRO_RATE_DEFAULT
= 44100;
126 /* check whether the clock mode is spdif-in */
127 static inline int is_spdif_master(struct snd_ice1712
*ice
)
129 return (inb(ICEMT(ice
, RATE
)) & ICE1712_SPDIF_MASTER
) ? 1 : 0;
132 static inline int is_pro_rate_locked(struct snd_ice1712
*ice
)
134 return is_spdif_master(ice
) || PRO_RATE_LOCKED
;
137 static inline void snd_ice1712_ds_write(struct snd_ice1712
* ice
, u8 channel
, u8 addr
, u32 data
)
139 outb((channel
<< 4) | addr
, ICEDS(ice
, INDEX
));
140 outl(data
, ICEDS(ice
, DATA
));
143 static inline u32
snd_ice1712_ds_read(struct snd_ice1712
* ice
, u8 channel
, u8 addr
)
145 outb((channel
<< 4) | addr
, ICEDS(ice
, INDEX
));
146 return inl(ICEDS(ice
, DATA
));
149 static void snd_ice1712_ac97_write(struct snd_ac97
*ac97
,
153 struct snd_ice1712
*ice
= ac97
->private_data
;
155 unsigned char old_cmd
= 0;
157 for (tm
= 0; tm
< 0x10000; tm
++) {
158 old_cmd
= inb(ICEREG(ice
, AC97_CMD
));
159 if (old_cmd
& (ICE1712_AC97_WRITE
| ICE1712_AC97_READ
))
161 if (!(old_cmd
& ICE1712_AC97_READY
))
165 outb(reg
, ICEREG(ice
, AC97_INDEX
));
166 outw(val
, ICEREG(ice
, AC97_DATA
));
167 old_cmd
&= ~(ICE1712_AC97_PBK_VSR
| ICE1712_AC97_CAP_VSR
);
168 outb(old_cmd
| ICE1712_AC97_WRITE
, ICEREG(ice
, AC97_CMD
));
169 for (tm
= 0; tm
< 0x10000; tm
++)
170 if ((inb(ICEREG(ice
, AC97_CMD
)) & ICE1712_AC97_WRITE
) == 0)
174 static unsigned short snd_ice1712_ac97_read(struct snd_ac97
*ac97
,
177 struct snd_ice1712
*ice
= ac97
->private_data
;
179 unsigned char old_cmd
= 0;
181 for (tm
= 0; tm
< 0x10000; tm
++) {
182 old_cmd
= inb(ICEREG(ice
, AC97_CMD
));
183 if (old_cmd
& (ICE1712_AC97_WRITE
| ICE1712_AC97_READ
))
185 if (!(old_cmd
& ICE1712_AC97_READY
))
189 outb(reg
, ICEREG(ice
, AC97_INDEX
));
190 outb(old_cmd
| ICE1712_AC97_READ
, ICEREG(ice
, AC97_CMD
));
191 for (tm
= 0; tm
< 0x10000; tm
++)
192 if ((inb(ICEREG(ice
, AC97_CMD
)) & ICE1712_AC97_READ
) == 0)
194 if (tm
>= 0x10000) /* timeout */
196 return inw(ICEREG(ice
, AC97_DATA
));
203 static void snd_ice1712_pro_ac97_write(struct snd_ac97
*ac97
,
207 struct snd_ice1712
*ice
= ac97
->private_data
;
209 unsigned char old_cmd
= 0;
211 for (tm
= 0; tm
< 0x10000; tm
++) {
212 old_cmd
= inb(ICEMT(ice
, AC97_CMD
));
213 if (old_cmd
& (ICE1712_AC97_WRITE
| ICE1712_AC97_READ
))
215 if (!(old_cmd
& ICE1712_AC97_READY
))
219 outb(reg
, ICEMT(ice
, AC97_INDEX
));
220 outw(val
, ICEMT(ice
, AC97_DATA
));
221 old_cmd
&= ~(ICE1712_AC97_PBK_VSR
| ICE1712_AC97_CAP_VSR
);
222 outb(old_cmd
| ICE1712_AC97_WRITE
, ICEMT(ice
, AC97_CMD
));
223 for (tm
= 0; tm
< 0x10000; tm
++)
224 if ((inb(ICEMT(ice
, AC97_CMD
)) & ICE1712_AC97_WRITE
) == 0)
229 static unsigned short snd_ice1712_pro_ac97_read(struct snd_ac97
*ac97
,
232 struct snd_ice1712
*ice
= ac97
->private_data
;
234 unsigned char old_cmd
= 0;
236 for (tm
= 0; tm
< 0x10000; tm
++) {
237 old_cmd
= inb(ICEMT(ice
, AC97_CMD
));
238 if (old_cmd
& (ICE1712_AC97_WRITE
| ICE1712_AC97_READ
))
240 if (!(old_cmd
& ICE1712_AC97_READY
))
244 outb(reg
, ICEMT(ice
, AC97_INDEX
));
245 outb(old_cmd
| ICE1712_AC97_READ
, ICEMT(ice
, AC97_CMD
));
246 for (tm
= 0; tm
< 0x10000; tm
++)
247 if ((inb(ICEMT(ice
, AC97_CMD
)) & ICE1712_AC97_READ
) == 0)
249 if (tm
>= 0x10000) /* timeout */
251 return inw(ICEMT(ice
, AC97_DATA
));
255 * consumer ac97 digital mix
257 static int snd_ice1712_digmix_route_ac97_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
259 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
261 uinfo
->value
.integer
.min
= 0;
262 uinfo
->value
.integer
.max
= 1;
266 static int snd_ice1712_digmix_route_ac97_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
268 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
270 ucontrol
->value
.integer
.value
[0] = inb(ICEMT(ice
, MONITOR_ROUTECTRL
)) & ICE1712_ROUTE_AC97
? 1 : 0;
274 static int snd_ice1712_digmix_route_ac97_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
276 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
277 unsigned char val
, nval
;
279 spin_lock_irq(&ice
->reg_lock
);
280 val
= inb(ICEMT(ice
, MONITOR_ROUTECTRL
));
281 nval
= val
& ~ICE1712_ROUTE_AC97
;
282 if (ucontrol
->value
.integer
.value
[0]) nval
|= ICE1712_ROUTE_AC97
;
283 outb(nval
, ICEMT(ice
, MONITOR_ROUTECTRL
));
284 spin_unlock_irq(&ice
->reg_lock
);
288 static struct snd_kcontrol_new snd_ice1712_mixer_digmix_route_ac97 __devinitdata
= {
289 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
290 .name
= "Digital Mixer To AC97",
291 .info
= snd_ice1712_digmix_route_ac97_info
,
292 .get
= snd_ice1712_digmix_route_ac97_get
,
293 .put
= snd_ice1712_digmix_route_ac97_put
,
300 static void snd_ice1712_set_gpio_dir(struct snd_ice1712
*ice
, unsigned int data
)
302 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DIRECTION
, data
);
303 inb(ICEREG(ice
, DATA
)); /* dummy read for pci-posting */
306 static void snd_ice1712_set_gpio_mask(struct snd_ice1712
*ice
, unsigned int data
)
308 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, data
);
309 inb(ICEREG(ice
, DATA
)); /* dummy read for pci-posting */
312 static unsigned int snd_ice1712_get_gpio_data(struct snd_ice1712
*ice
)
314 return snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DATA
);
317 static void snd_ice1712_set_gpio_data(struct snd_ice1712
*ice
, unsigned int val
)
319 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
, val
);
320 inb(ICEREG(ice
, DATA
)); /* dummy read for pci-posting */
330 * change the input clock selection
331 * spdif_clock = 1 - IEC958 input, 0 - Envy24
333 static int snd_ice1712_cs8427_set_input_clock(struct snd_ice1712
*ice
, int spdif_clock
)
335 unsigned char reg
[2] = { 0x80 | 4, 0 }; /* CS8427 auto increment | register number 4 + data */
336 unsigned char val
, nval
;
339 snd_i2c_lock(ice
->i2c
);
340 if (snd_i2c_sendbytes(ice
->cs8427
, reg
, 1) != 1) {
341 snd_i2c_unlock(ice
->i2c
);
344 if (snd_i2c_readbytes(ice
->cs8427
, &val
, 1) != 1) {
345 snd_i2c_unlock(ice
->i2c
);
355 if (snd_i2c_sendbytes(ice
->cs8427
, reg
, 2) != 2) {
361 snd_i2c_unlock(ice
->i2c
);
368 static void open_cs8427(struct snd_ice1712
*ice
, struct snd_pcm_substream
*substream
)
370 snd_cs8427_iec958_active(ice
->cs8427
, 1);
373 static void close_cs8427(struct snd_ice1712
*ice
, struct snd_pcm_substream
*substream
)
375 snd_cs8427_iec958_active(ice
->cs8427
, 0);
378 static void setup_cs8427(struct snd_ice1712
*ice
, int rate
)
380 snd_cs8427_iec958_pcm(ice
->cs8427
, rate
);
384 * create and initialize callbacks for cs8427 interface
386 int __devinit
snd_ice1712_init_cs8427(struct snd_ice1712
*ice
, int addr
)
390 if ((err
= snd_cs8427_create(ice
->i2c
, addr
,
391 (ice
->cs8427_timeout
* HZ
) / 1000,
392 &ice
->cs8427
)) < 0) {
393 snd_printk(KERN_ERR
"CS8427 initialization failed\n");
396 ice
->spdif
.ops
.open
= open_cs8427
;
397 ice
->spdif
.ops
.close
= close_cs8427
;
398 ice
->spdif
.ops
.setup_rate
= setup_cs8427
;
402 static void snd_ice1712_set_input_clock_source(struct snd_ice1712
*ice
, int spdif_is_master
)
404 /* change CS8427 clock source too */
406 snd_ice1712_cs8427_set_input_clock(ice
, spdif_is_master
);
407 /* notify ak4524 chip as well */
408 if (spdif_is_master
) {
410 for (i
= 0; i
< ice
->akm_codecs
; i
++) {
411 if (ice
->akm
[i
].ops
.set_rate_val
)
412 ice
->akm
[i
].ops
.set_rate_val(&ice
->akm
[i
], 0);
421 static irqreturn_t
snd_ice1712_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
423 struct snd_ice1712
*ice
= dev_id
;
424 unsigned char status
;
428 status
= inb(ICEREG(ice
, IRQSTAT
));
432 if (status
& ICE1712_IRQ_MPU1
) {
434 snd_mpu401_uart_interrupt(irq
, ice
->rmidi
[0]->private_data
, regs
);
435 outb(ICE1712_IRQ_MPU1
, ICEREG(ice
, IRQSTAT
));
436 status
&= ~ICE1712_IRQ_MPU1
;
438 if (status
& ICE1712_IRQ_TIMER
)
439 outb(ICE1712_IRQ_TIMER
, ICEREG(ice
, IRQSTAT
));
440 if (status
& ICE1712_IRQ_MPU2
) {
442 snd_mpu401_uart_interrupt(irq
, ice
->rmidi
[1]->private_data
, regs
);
443 outb(ICE1712_IRQ_MPU2
, ICEREG(ice
, IRQSTAT
));
444 status
&= ~ICE1712_IRQ_MPU2
;
446 if (status
& ICE1712_IRQ_PROPCM
) {
447 unsigned char mtstat
= inb(ICEMT(ice
, IRQ
));
448 if (mtstat
& ICE1712_MULTI_PBKSTATUS
) {
449 if (ice
->playback_pro_substream
)
450 snd_pcm_period_elapsed(ice
->playback_pro_substream
);
451 outb(ICE1712_MULTI_PBKSTATUS
, ICEMT(ice
, IRQ
));
453 if (mtstat
& ICE1712_MULTI_CAPSTATUS
) {
454 if (ice
->capture_pro_substream
)
455 snd_pcm_period_elapsed(ice
->capture_pro_substream
);
456 outb(ICE1712_MULTI_CAPSTATUS
, ICEMT(ice
, IRQ
));
459 if (status
& ICE1712_IRQ_FM
)
460 outb(ICE1712_IRQ_FM
, ICEREG(ice
, IRQSTAT
));
461 if (status
& ICE1712_IRQ_PBKDS
) {
464 struct snd_pcm_substream
*substream
;
465 pbkstatus
= inw(ICEDS(ice
, INTSTAT
));
466 //printk("pbkstatus = 0x%x\n", pbkstatus);
467 for (idx
= 0; idx
< 6; idx
++) {
468 if ((pbkstatus
& (3 << (idx
* 2))) == 0)
470 if ((substream
= ice
->playback_con_substream_ds
[idx
]) != NULL
)
471 snd_pcm_period_elapsed(substream
);
472 outw(3 << (idx
* 2), ICEDS(ice
, INTSTAT
));
474 outb(ICE1712_IRQ_PBKDS
, ICEREG(ice
, IRQSTAT
));
476 if (status
& ICE1712_IRQ_CONCAP
) {
477 if (ice
->capture_con_substream
)
478 snd_pcm_period_elapsed(ice
->capture_con_substream
);
479 outb(ICE1712_IRQ_CONCAP
, ICEREG(ice
, IRQSTAT
));
481 if (status
& ICE1712_IRQ_CONPBK
) {
482 if (ice
->playback_con_substream
)
483 snd_pcm_period_elapsed(ice
->playback_con_substream
);
484 outb(ICE1712_IRQ_CONPBK
, ICEREG(ice
, IRQSTAT
));
487 return IRQ_RETVAL(handled
);
495 static int snd_ice1712_hw_params(struct snd_pcm_substream
*substream
,
496 struct snd_pcm_hw_params
*hw_params
)
498 return snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
501 static int snd_ice1712_hw_free(struct snd_pcm_substream
*substream
)
503 return snd_pcm_lib_free_pages(substream
);
507 * PCM part - consumer I/O
510 static int snd_ice1712_playback_trigger(struct snd_pcm_substream
*substream
,
513 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
517 spin_lock(&ice
->reg_lock
);
518 tmp
= snd_ice1712_read(ice
, ICE1712_IREG_PBK_CTRL
);
519 if (cmd
== SNDRV_PCM_TRIGGER_START
) {
521 } else if (cmd
== SNDRV_PCM_TRIGGER_STOP
) {
523 } else if (cmd
== SNDRV_PCM_TRIGGER_PAUSE_PUSH
) {
525 } else if (cmd
== SNDRV_PCM_TRIGGER_PAUSE_RELEASE
) {
530 snd_ice1712_write(ice
, ICE1712_IREG_PBK_CTRL
, tmp
);
531 spin_unlock(&ice
->reg_lock
);
535 static int snd_ice1712_playback_ds_trigger(struct snd_pcm_substream
*substream
,
538 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
542 spin_lock(&ice
->reg_lock
);
543 tmp
= snd_ice1712_ds_read(ice
, substream
->number
* 2, ICE1712_DSC_CONTROL
);
544 if (cmd
== SNDRV_PCM_TRIGGER_START
) {
546 } else if (cmd
== SNDRV_PCM_TRIGGER_STOP
) {
548 } else if (cmd
== SNDRV_PCM_TRIGGER_PAUSE_PUSH
) {
550 } else if (cmd
== SNDRV_PCM_TRIGGER_PAUSE_RELEASE
) {
555 snd_ice1712_ds_write(ice
, substream
->number
* 2, ICE1712_DSC_CONTROL
, tmp
);
556 spin_unlock(&ice
->reg_lock
);
560 static int snd_ice1712_capture_trigger(struct snd_pcm_substream
*substream
,
563 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
567 spin_lock(&ice
->reg_lock
);
568 tmp
= snd_ice1712_read(ice
, ICE1712_IREG_CAP_CTRL
);
569 if (cmd
== SNDRV_PCM_TRIGGER_START
) {
571 } else if (cmd
== SNDRV_PCM_TRIGGER_STOP
) {
576 snd_ice1712_write(ice
, ICE1712_IREG_CAP_CTRL
, tmp
);
577 spin_unlock(&ice
->reg_lock
);
581 static int snd_ice1712_playback_prepare(struct snd_pcm_substream
*substream
)
583 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
584 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
585 u32 period_size
, buf_size
, rate
, tmp
;
587 period_size
= (snd_pcm_lib_period_bytes(substream
) >> 2) - 1;
588 buf_size
= snd_pcm_lib_buffer_bytes(substream
) - 1;
590 if (snd_pcm_format_width(runtime
->format
) == 16)
592 if (runtime
->channels
== 2)
594 rate
= (runtime
->rate
* 8192) / 375;
595 if (rate
> 0x000fffff)
597 spin_lock_irq(&ice
->reg_lock
);
598 outb(0, ice
->ddma_port
+ 15);
599 outb(ICE1712_DMA_MODE_WRITE
| ICE1712_DMA_AUTOINIT
, ice
->ddma_port
+ 0x0b);
600 outl(runtime
->dma_addr
, ice
->ddma_port
+ 0);
601 outw(buf_size
, ice
->ddma_port
+ 4);
602 snd_ice1712_write(ice
, ICE1712_IREG_PBK_RATE_LO
, rate
& 0xff);
603 snd_ice1712_write(ice
, ICE1712_IREG_PBK_RATE_MID
, (rate
>> 8) & 0xff);
604 snd_ice1712_write(ice
, ICE1712_IREG_PBK_RATE_HI
, (rate
>> 16) & 0xff);
605 snd_ice1712_write(ice
, ICE1712_IREG_PBK_CTRL
, tmp
);
606 snd_ice1712_write(ice
, ICE1712_IREG_PBK_COUNT_LO
, period_size
& 0xff);
607 snd_ice1712_write(ice
, ICE1712_IREG_PBK_COUNT_HI
, period_size
>> 8);
608 snd_ice1712_write(ice
, ICE1712_IREG_PBK_LEFT
, 0);
609 snd_ice1712_write(ice
, ICE1712_IREG_PBK_RIGHT
, 0);
610 spin_unlock_irq(&ice
->reg_lock
);
614 static int snd_ice1712_playback_ds_prepare(struct snd_pcm_substream
*substream
)
616 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
617 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
618 u32 period_size
, buf_size
, rate
, tmp
, chn
;
620 period_size
= snd_pcm_lib_period_bytes(substream
) - 1;
621 buf_size
= snd_pcm_lib_buffer_bytes(substream
) - 1;
623 if (snd_pcm_format_width(runtime
->format
) == 16)
625 if (runtime
->channels
== 2)
627 rate
= (runtime
->rate
* 8192) / 375;
628 if (rate
> 0x000fffff)
630 ice
->playback_con_active_buf
[substream
->number
] = 0;
631 ice
->playback_con_virt_addr
[substream
->number
] = runtime
->dma_addr
;
632 chn
= substream
->number
* 2;
633 spin_lock_irq(&ice
->reg_lock
);
634 snd_ice1712_ds_write(ice
, chn
, ICE1712_DSC_ADDR0
, runtime
->dma_addr
);
635 snd_ice1712_ds_write(ice
, chn
, ICE1712_DSC_COUNT0
, period_size
);
636 snd_ice1712_ds_write(ice
, chn
, ICE1712_DSC_ADDR1
, runtime
->dma_addr
+ (runtime
->periods
> 1 ? period_size
+ 1 : 0));
637 snd_ice1712_ds_write(ice
, chn
, ICE1712_DSC_COUNT1
, period_size
);
638 snd_ice1712_ds_write(ice
, chn
, ICE1712_DSC_RATE
, rate
);
639 snd_ice1712_ds_write(ice
, chn
, ICE1712_DSC_VOLUME
, 0);
640 snd_ice1712_ds_write(ice
, chn
, ICE1712_DSC_CONTROL
, tmp
);
641 if (runtime
->channels
== 2) {
642 snd_ice1712_ds_write(ice
, chn
+ 1, ICE1712_DSC_RATE
, rate
);
643 snd_ice1712_ds_write(ice
, chn
+ 1, ICE1712_DSC_VOLUME
, 0);
645 spin_unlock_irq(&ice
->reg_lock
);
649 static int snd_ice1712_capture_prepare(struct snd_pcm_substream
*substream
)
651 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
652 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
653 u32 period_size
, buf_size
;
656 period_size
= (snd_pcm_lib_period_bytes(substream
) >> 2) - 1;
657 buf_size
= snd_pcm_lib_buffer_bytes(substream
) - 1;
659 if (snd_pcm_format_width(runtime
->format
) == 16)
661 if (runtime
->channels
== 2)
663 spin_lock_irq(&ice
->reg_lock
);
664 outl(ice
->capture_con_virt_addr
= runtime
->dma_addr
, ICEREG(ice
, CONCAP_ADDR
));
665 outw(buf_size
, ICEREG(ice
, CONCAP_COUNT
));
666 snd_ice1712_write(ice
, ICE1712_IREG_CAP_COUNT_HI
, period_size
>> 8);
667 snd_ice1712_write(ice
, ICE1712_IREG_CAP_COUNT_LO
, period_size
& 0xff);
668 snd_ice1712_write(ice
, ICE1712_IREG_CAP_CTRL
, tmp
);
669 spin_unlock_irq(&ice
->reg_lock
);
670 snd_ac97_set_rate(ice
->ac97
, AC97_PCM_LR_ADC_RATE
, runtime
->rate
);
674 static snd_pcm_uframes_t
snd_ice1712_playback_pointer(struct snd_pcm_substream
*substream
)
676 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
677 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
680 if (!(snd_ice1712_read(ice
, ICE1712_IREG_PBK_CTRL
) & 1))
682 ptr
= runtime
->buffer_size
- inw(ice
->ddma_port
+ 4);
683 if (ptr
== runtime
->buffer_size
)
685 return bytes_to_frames(substream
->runtime
, ptr
);
688 static snd_pcm_uframes_t
snd_ice1712_playback_ds_pointer(struct snd_pcm_substream
*substream
)
690 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
694 if (!(snd_ice1712_ds_read(ice
, substream
->number
* 2, ICE1712_DSC_CONTROL
) & 1))
696 if (ice
->playback_con_active_buf
[substream
->number
])
697 addr
= ICE1712_DSC_ADDR1
;
699 addr
= ICE1712_DSC_ADDR0
;
700 ptr
= snd_ice1712_ds_read(ice
, substream
->number
* 2, addr
) -
701 ice
->playback_con_virt_addr
[substream
->number
];
702 if (ptr
== substream
->runtime
->buffer_size
)
704 return bytes_to_frames(substream
->runtime
, ptr
);
707 static snd_pcm_uframes_t
snd_ice1712_capture_pointer(struct snd_pcm_substream
*substream
)
709 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
712 if (!(snd_ice1712_read(ice
, ICE1712_IREG_CAP_CTRL
) & 1))
714 ptr
= inl(ICEREG(ice
, CONCAP_ADDR
)) - ice
->capture_con_virt_addr
;
715 if (ptr
== substream
->runtime
->buffer_size
)
717 return bytes_to_frames(substream
->runtime
, ptr
);
720 static struct snd_pcm_hardware snd_ice1712_playback
=
722 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
723 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
724 SNDRV_PCM_INFO_MMAP_VALID
|
725 SNDRV_PCM_INFO_PAUSE
),
726 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
727 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
732 .buffer_bytes_max
= (64*1024),
733 .period_bytes_min
= 64,
734 .period_bytes_max
= (64*1024),
740 static struct snd_pcm_hardware snd_ice1712_playback_ds
=
742 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
743 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
744 SNDRV_PCM_INFO_MMAP_VALID
|
745 SNDRV_PCM_INFO_PAUSE
),
746 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
747 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
752 .buffer_bytes_max
= (128*1024),
753 .period_bytes_min
= 64,
754 .period_bytes_max
= (128*1024),
760 static struct snd_pcm_hardware snd_ice1712_capture
=
762 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
763 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
764 SNDRV_PCM_INFO_MMAP_VALID
),
765 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
766 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
771 .buffer_bytes_max
= (64*1024),
772 .period_bytes_min
= 64,
773 .period_bytes_max
= (64*1024),
779 static int snd_ice1712_playback_open(struct snd_pcm_substream
*substream
)
781 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
782 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
784 ice
->playback_con_substream
= substream
;
785 runtime
->hw
= snd_ice1712_playback
;
789 static int snd_ice1712_playback_ds_open(struct snd_pcm_substream
*substream
)
791 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
792 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
795 ice
->playback_con_substream_ds
[substream
->number
] = substream
;
796 runtime
->hw
= snd_ice1712_playback_ds
;
797 spin_lock_irq(&ice
->reg_lock
);
798 tmp
= inw(ICEDS(ice
, INTMASK
)) & ~(1 << (substream
->number
* 2));
799 outw(tmp
, ICEDS(ice
, INTMASK
));
800 spin_unlock_irq(&ice
->reg_lock
);
804 static int snd_ice1712_capture_open(struct snd_pcm_substream
*substream
)
806 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
807 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
809 ice
->capture_con_substream
= substream
;
810 runtime
->hw
= snd_ice1712_capture
;
811 runtime
->hw
.rates
= ice
->ac97
->rates
[AC97_RATES_ADC
];
812 if (!(runtime
->hw
.rates
& SNDRV_PCM_RATE_8000
))
813 runtime
->hw
.rate_min
= 48000;
817 static int snd_ice1712_playback_close(struct snd_pcm_substream
*substream
)
819 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
821 ice
->playback_con_substream
= NULL
;
825 static int snd_ice1712_playback_ds_close(struct snd_pcm_substream
*substream
)
827 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
830 spin_lock_irq(&ice
->reg_lock
);
831 tmp
= inw(ICEDS(ice
, INTMASK
)) | (3 << (substream
->number
* 2));
832 outw(tmp
, ICEDS(ice
, INTMASK
));
833 spin_unlock_irq(&ice
->reg_lock
);
834 ice
->playback_con_substream_ds
[substream
->number
] = NULL
;
838 static int snd_ice1712_capture_close(struct snd_pcm_substream
*substream
)
840 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
842 ice
->capture_con_substream
= NULL
;
846 static struct snd_pcm_ops snd_ice1712_playback_ops
= {
847 .open
= snd_ice1712_playback_open
,
848 .close
= snd_ice1712_playback_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_prepare
,
853 .trigger
= snd_ice1712_playback_trigger
,
854 .pointer
= snd_ice1712_playback_pointer
,
857 static struct snd_pcm_ops snd_ice1712_playback_ds_ops
= {
858 .open
= snd_ice1712_playback_ds_open
,
859 .close
= snd_ice1712_playback_ds_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_playback_ds_prepare
,
864 .trigger
= snd_ice1712_playback_ds_trigger
,
865 .pointer
= snd_ice1712_playback_ds_pointer
,
868 static struct snd_pcm_ops snd_ice1712_capture_ops
= {
869 .open
= snd_ice1712_capture_open
,
870 .close
= snd_ice1712_capture_close
,
871 .ioctl
= snd_pcm_lib_ioctl
,
872 .hw_params
= snd_ice1712_hw_params
,
873 .hw_free
= snd_ice1712_hw_free
,
874 .prepare
= snd_ice1712_capture_prepare
,
875 .trigger
= snd_ice1712_capture_trigger
,
876 .pointer
= snd_ice1712_capture_pointer
,
879 static int __devinit
snd_ice1712_pcm(struct snd_ice1712
* ice
, int device
, struct snd_pcm
** rpcm
)
886 err
= snd_pcm_new(ice
->card
, "ICE1712 consumer", device
, 1, 1, &pcm
);
890 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_ice1712_playback_ops
);
891 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_ice1712_capture_ops
);
893 pcm
->private_data
= ice
;
895 strcpy(pcm
->name
, "ICE1712 consumer");
898 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
899 snd_dma_pci_data(ice
->pci
), 64*1024, 64*1024);
904 printk(KERN_WARNING
"Consumer PCM code does not work well at the moment --jk\n");
909 static int __devinit
snd_ice1712_pcm_ds(struct snd_ice1712
* ice
, int device
, struct snd_pcm
** rpcm
)
916 err
= snd_pcm_new(ice
->card
, "ICE1712 consumer (DS)", device
, 6, 0, &pcm
);
920 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_ice1712_playback_ds_ops
);
922 pcm
->private_data
= ice
;
924 strcpy(pcm
->name
, "ICE1712 consumer (DS)");
927 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
928 snd_dma_pci_data(ice
->pci
), 64*1024, 128*1024);
937 * PCM code - professional part (multitrack)
940 static unsigned int rates
[] = { 8000, 9600, 11025, 12000, 16000, 22050, 24000,
941 32000, 44100, 48000, 64000, 88200, 96000 };
943 static struct snd_pcm_hw_constraint_list hw_constraints_rates
= {
944 .count
= ARRAY_SIZE(rates
),
949 static int snd_ice1712_pro_trigger(struct snd_pcm_substream
*substream
,
952 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
954 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
955 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
959 if (substream
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
)
961 what
= ICE1712_PLAYBACK_PAUSE
;
962 snd_pcm_trigger_done(substream
, substream
);
963 spin_lock(&ice
->reg_lock
);
964 old
= inl(ICEMT(ice
, PLAYBACK_CONTROL
));
965 if (cmd
== SNDRV_PCM_TRIGGER_PAUSE_PUSH
)
969 outl(old
, ICEMT(ice
, PLAYBACK_CONTROL
));
970 spin_unlock(&ice
->reg_lock
);
973 case SNDRV_PCM_TRIGGER_START
:
974 case SNDRV_PCM_TRIGGER_STOP
:
976 unsigned int what
= 0;
978 struct list_head
*pos
;
979 struct snd_pcm_substream
*s
;
981 snd_pcm_group_for_each(pos
, substream
) {
982 s
= snd_pcm_group_substream_entry(pos
);
983 if (s
== ice
->playback_pro_substream
) {
984 what
|= ICE1712_PLAYBACK_START
;
985 snd_pcm_trigger_done(s
, substream
);
986 } else if (s
== ice
->capture_pro_substream
) {
987 what
|= ICE1712_CAPTURE_START_SHADOW
;
988 snd_pcm_trigger_done(s
, substream
);
991 spin_lock(&ice
->reg_lock
);
992 old
= inl(ICEMT(ice
, PLAYBACK_CONTROL
));
993 if (cmd
== SNDRV_PCM_TRIGGER_START
)
997 outl(old
, ICEMT(ice
, PLAYBACK_CONTROL
));
998 spin_unlock(&ice
->reg_lock
);
1009 static void snd_ice1712_set_pro_rate(struct snd_ice1712
*ice
, unsigned int rate
, int force
)
1011 unsigned long flags
;
1012 unsigned char val
, old
;
1016 case 8000: val
= 6; break;
1017 case 9600: val
= 3; break;
1018 case 11025: val
= 10; break;
1019 case 12000: val
= 2; break;
1020 case 16000: val
= 5; break;
1021 case 22050: val
= 9; break;
1022 case 24000: val
= 1; break;
1023 case 32000: val
= 4; break;
1024 case 44100: val
= 8; break;
1025 case 48000: val
= 0; break;
1026 case 64000: val
= 15; break;
1027 case 88200: val
= 11; break;
1028 case 96000: val
= 7; break;
1036 spin_lock_irqsave(&ice
->reg_lock
, flags
);
1037 if (inb(ICEMT(ice
, PLAYBACK_CONTROL
)) & (ICE1712_CAPTURE_START_SHADOW
|
1038 ICE1712_PLAYBACK_PAUSE
|
1039 ICE1712_PLAYBACK_START
)) {
1041 spin_unlock_irqrestore(&ice
->reg_lock
, flags
);
1044 if (!force
&& is_pro_rate_locked(ice
))
1047 old
= inb(ICEMT(ice
, RATE
));
1048 if (!force
&& old
== val
)
1050 outb(val
, ICEMT(ice
, RATE
));
1051 spin_unlock_irqrestore(&ice
->reg_lock
, flags
);
1053 if (ice
->gpio
.set_pro_rate
)
1054 ice
->gpio
.set_pro_rate(ice
, rate
);
1055 for (i
= 0; i
< ice
->akm_codecs
; i
++) {
1056 if (ice
->akm
[i
].ops
.set_rate_val
)
1057 ice
->akm
[i
].ops
.set_rate_val(&ice
->akm
[i
], rate
);
1059 if (ice
->spdif
.ops
.setup_rate
)
1060 ice
->spdif
.ops
.setup_rate(ice
, rate
);
1063 static int snd_ice1712_playback_pro_prepare(struct snd_pcm_substream
*substream
)
1065 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
1067 ice
->playback_pro_size
= snd_pcm_lib_buffer_bytes(substream
);
1068 spin_lock_irq(&ice
->reg_lock
);
1069 outl(substream
->runtime
->dma_addr
, ICEMT(ice
, PLAYBACK_ADDR
));
1070 outw((ice
->playback_pro_size
>> 2) - 1, ICEMT(ice
, PLAYBACK_SIZE
));
1071 outw((snd_pcm_lib_period_bytes(substream
) >> 2) - 1, ICEMT(ice
, PLAYBACK_COUNT
));
1072 spin_unlock_irq(&ice
->reg_lock
);
1077 static int snd_ice1712_playback_pro_hw_params(struct snd_pcm_substream
*substream
,
1078 struct snd_pcm_hw_params
*hw_params
)
1080 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
1082 snd_ice1712_set_pro_rate(ice
, params_rate(hw_params
), 0);
1083 return snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
1086 static int snd_ice1712_capture_pro_prepare(struct snd_pcm_substream
*substream
)
1088 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
1090 ice
->capture_pro_size
= snd_pcm_lib_buffer_bytes(substream
);
1091 spin_lock_irq(&ice
->reg_lock
);
1092 outl(substream
->runtime
->dma_addr
, ICEMT(ice
, CAPTURE_ADDR
));
1093 outw((ice
->capture_pro_size
>> 2) - 1, ICEMT(ice
, CAPTURE_SIZE
));
1094 outw((snd_pcm_lib_period_bytes(substream
) >> 2) - 1, ICEMT(ice
, CAPTURE_COUNT
));
1095 spin_unlock_irq(&ice
->reg_lock
);
1099 static int snd_ice1712_capture_pro_hw_params(struct snd_pcm_substream
*substream
,
1100 struct snd_pcm_hw_params
*hw_params
)
1102 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
1104 snd_ice1712_set_pro_rate(ice
, params_rate(hw_params
), 0);
1105 return snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
1108 static snd_pcm_uframes_t
snd_ice1712_playback_pro_pointer(struct snd_pcm_substream
*substream
)
1110 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
1113 if (!(inl(ICEMT(ice
, PLAYBACK_CONTROL
)) & ICE1712_PLAYBACK_START
))
1115 ptr
= ice
->playback_pro_size
- (inw(ICEMT(ice
, PLAYBACK_SIZE
)) << 2);
1116 if (ptr
== substream
->runtime
->buffer_size
)
1118 return bytes_to_frames(substream
->runtime
, ptr
);
1121 static snd_pcm_uframes_t
snd_ice1712_capture_pro_pointer(struct snd_pcm_substream
*substream
)
1123 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
1126 if (!(inl(ICEMT(ice
, PLAYBACK_CONTROL
)) & ICE1712_CAPTURE_START_SHADOW
))
1128 ptr
= ice
->capture_pro_size
- (inw(ICEMT(ice
, CAPTURE_SIZE
)) << 2);
1129 if (ptr
== substream
->runtime
->buffer_size
)
1131 return bytes_to_frames(substream
->runtime
, ptr
);
1134 static struct snd_pcm_hardware snd_ice1712_playback_pro
=
1136 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1137 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1138 SNDRV_PCM_INFO_MMAP_VALID
|
1139 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_SYNC_START
),
1140 .formats
= SNDRV_PCM_FMTBIT_S32_LE
,
1141 .rates
= SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_8000_96000
,
1146 .buffer_bytes_max
= (256*1024),
1147 .period_bytes_min
= 10 * 4 * 2,
1148 .period_bytes_max
= 131040,
1150 .periods_max
= 1024,
1154 static struct snd_pcm_hardware snd_ice1712_capture_pro
=
1156 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1157 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1158 SNDRV_PCM_INFO_MMAP_VALID
|
1159 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_SYNC_START
),
1160 .formats
= SNDRV_PCM_FMTBIT_S32_LE
,
1161 .rates
= SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_8000_96000
,
1166 .buffer_bytes_max
= (256*1024),
1167 .period_bytes_min
= 12 * 4 * 2,
1168 .period_bytes_max
= 131040,
1170 .periods_max
= 1024,
1174 static int snd_ice1712_playback_pro_open(struct snd_pcm_substream
*substream
)
1176 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1177 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
1179 ice
->playback_pro_substream
= substream
;
1180 runtime
->hw
= snd_ice1712_playback_pro
;
1181 snd_pcm_set_sync(substream
);
1182 snd_pcm_hw_constraint_msbits(runtime
, 0, 32, 24);
1183 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
, &hw_constraints_rates
);
1185 if (ice
->spdif
.ops
.open
)
1186 ice
->spdif
.ops
.open(ice
, substream
);
1191 static int snd_ice1712_capture_pro_open(struct snd_pcm_substream
*substream
)
1193 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
1194 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1196 ice
->capture_pro_substream
= substream
;
1197 runtime
->hw
= snd_ice1712_capture_pro
;
1198 snd_pcm_set_sync(substream
);
1199 snd_pcm_hw_constraint_msbits(runtime
, 0, 32, 24);
1200 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
, &hw_constraints_rates
);
1204 static int snd_ice1712_playback_pro_close(struct snd_pcm_substream
*substream
)
1206 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
1209 snd_ice1712_set_pro_rate(ice
, PRO_RATE_DEFAULT
, 0);
1210 ice
->playback_pro_substream
= NULL
;
1211 if (ice
->spdif
.ops
.close
)
1212 ice
->spdif
.ops
.close(ice
, substream
);
1217 static int snd_ice1712_capture_pro_close(struct snd_pcm_substream
*substream
)
1219 struct snd_ice1712
*ice
= snd_pcm_substream_chip(substream
);
1222 snd_ice1712_set_pro_rate(ice
, PRO_RATE_DEFAULT
, 0);
1223 ice
->capture_pro_substream
= NULL
;
1227 static struct snd_pcm_ops snd_ice1712_playback_pro_ops
= {
1228 .open
= snd_ice1712_playback_pro_open
,
1229 .close
= snd_ice1712_playback_pro_close
,
1230 .ioctl
= snd_pcm_lib_ioctl
,
1231 .hw_params
= snd_ice1712_playback_pro_hw_params
,
1232 .hw_free
= snd_ice1712_hw_free
,
1233 .prepare
= snd_ice1712_playback_pro_prepare
,
1234 .trigger
= snd_ice1712_pro_trigger
,
1235 .pointer
= snd_ice1712_playback_pro_pointer
,
1238 static struct snd_pcm_ops snd_ice1712_capture_pro_ops
= {
1239 .open
= snd_ice1712_capture_pro_open
,
1240 .close
= snd_ice1712_capture_pro_close
,
1241 .ioctl
= snd_pcm_lib_ioctl
,
1242 .hw_params
= snd_ice1712_capture_pro_hw_params
,
1243 .hw_free
= snd_ice1712_hw_free
,
1244 .prepare
= snd_ice1712_capture_pro_prepare
,
1245 .trigger
= snd_ice1712_pro_trigger
,
1246 .pointer
= snd_ice1712_capture_pro_pointer
,
1249 static int __devinit
snd_ice1712_pcm_profi(struct snd_ice1712
* ice
, int device
, struct snd_pcm
** rpcm
)
1251 struct snd_pcm
*pcm
;
1256 err
= snd_pcm_new(ice
->card
, "ICE1712 multi", device
, 1, 1, &pcm
);
1260 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_ice1712_playback_pro_ops
);
1261 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_ice1712_capture_pro_ops
);
1263 pcm
->private_data
= ice
;
1264 pcm
->info_flags
= 0;
1265 strcpy(pcm
->name
, "ICE1712 multi");
1267 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1268 snd_dma_pci_data(ice
->pci
), 256*1024, 256*1024);
1275 /* assign channels to iec958 */
1276 err
= snd_cs8427_iec958_build(ice
->cs8427
,
1277 pcm
->streams
[0].substream
,
1278 pcm
->streams
[1].substream
);
1283 if ((err
= snd_ice1712_build_pro_mixer(ice
)) < 0)
1292 static void snd_ice1712_update_volume(struct snd_ice1712
*ice
, int index
)
1294 unsigned int vol
= ice
->pro_volumes
[index
];
1295 unsigned short val
= 0;
1297 val
|= (vol
& 0x8000) == 0 ? (96 - (vol
& 0x7f)) : 0x7f;
1298 val
|= ((vol
& 0x80000000) == 0 ? (96 - ((vol
>> 16) & 0x7f)) : 0x7f) << 8;
1299 outb(index
, ICEMT(ice
, MONITOR_INDEX
));
1300 outw(val
, ICEMT(ice
, MONITOR_VOLUME
));
1303 static int snd_ice1712_pro_mixer_switch_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1305 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1307 uinfo
->value
.integer
.min
= 0;
1308 uinfo
->value
.integer
.max
= 1;
1312 static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1314 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
1315 int index
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
) + kcontrol
->private_value
;
1317 spin_lock_irq(&ice
->reg_lock
);
1318 ucontrol
->value
.integer
.value
[0] = !((ice
->pro_volumes
[index
] >> 15) & 1);
1319 ucontrol
->value
.integer
.value
[1] = !((ice
->pro_volumes
[index
] >> 31) & 1);
1320 spin_unlock_irq(&ice
->reg_lock
);
1324 static int snd_ice1712_pro_mixer_switch_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1326 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
1327 int index
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
) + kcontrol
->private_value
;
1328 unsigned int nval
, change
;
1330 nval
= (ucontrol
->value
.integer
.value
[0] ? 0 : 0x00008000) |
1331 (ucontrol
->value
.integer
.value
[1] ? 0 : 0x80000000);
1332 spin_lock_irq(&ice
->reg_lock
);
1333 nval
|= ice
->pro_volumes
[index
] & ~0x80008000;
1334 change
= nval
!= ice
->pro_volumes
[index
];
1335 ice
->pro_volumes
[index
] = nval
;
1336 snd_ice1712_update_volume(ice
, index
);
1337 spin_unlock_irq(&ice
->reg_lock
);
1341 static int snd_ice1712_pro_mixer_volume_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1343 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1345 uinfo
->value
.integer
.min
= 0;
1346 uinfo
->value
.integer
.max
= 96;
1350 static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1352 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
1353 int index
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
) + kcontrol
->private_value
;
1355 spin_lock_irq(&ice
->reg_lock
);
1356 ucontrol
->value
.integer
.value
[0] = (ice
->pro_volumes
[index
] >> 0) & 127;
1357 ucontrol
->value
.integer
.value
[1] = (ice
->pro_volumes
[index
] >> 16) & 127;
1358 spin_unlock_irq(&ice
->reg_lock
);
1362 static int snd_ice1712_pro_mixer_volume_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1364 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
1365 int index
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
) + kcontrol
->private_value
;
1366 unsigned int nval
, change
;
1368 nval
= (ucontrol
->value
.integer
.value
[0] & 127) |
1369 ((ucontrol
->value
.integer
.value
[1] & 127) << 16);
1370 spin_lock_irq(&ice
->reg_lock
);
1371 nval
|= ice
->pro_volumes
[index
] & ~0x007f007f;
1372 change
= nval
!= ice
->pro_volumes
[index
];
1373 ice
->pro_volumes
[index
] = nval
;
1374 snd_ice1712_update_volume(ice
, index
);
1375 spin_unlock_irq(&ice
->reg_lock
);
1380 static struct snd_kcontrol_new snd_ice1712_multi_playback_ctrls
[] __devinitdata
= {
1382 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1383 .name
= "Multi Playback Switch",
1384 .info
= snd_ice1712_pro_mixer_switch_info
,
1385 .get
= snd_ice1712_pro_mixer_switch_get
,
1386 .put
= snd_ice1712_pro_mixer_switch_put
,
1391 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1392 .name
= "Multi Playback Volume",
1393 .info
= snd_ice1712_pro_mixer_volume_info
,
1394 .get
= snd_ice1712_pro_mixer_volume_get
,
1395 .put
= snd_ice1712_pro_mixer_volume_put
,
1401 static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_switch __devinitdata
= {
1402 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1403 .name
= "H/W Multi Capture Switch",
1404 .info
= snd_ice1712_pro_mixer_switch_info
,
1405 .get
= snd_ice1712_pro_mixer_switch_get
,
1406 .put
= snd_ice1712_pro_mixer_switch_put
,
1407 .private_value
= 10,
1410 static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_switch __devinitdata
= {
1411 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1412 .name
= SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE
,SWITCH
),
1413 .info
= snd_ice1712_pro_mixer_switch_info
,
1414 .get
= snd_ice1712_pro_mixer_switch_get
,
1415 .put
= snd_ice1712_pro_mixer_switch_put
,
1416 .private_value
= 18,
1420 static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_volume __devinitdata
= {
1421 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1422 .name
= "H/W Multi Capture Volume",
1423 .info
= snd_ice1712_pro_mixer_volume_info
,
1424 .get
= snd_ice1712_pro_mixer_volume_get
,
1425 .put
= snd_ice1712_pro_mixer_volume_put
,
1426 .private_value
= 10,
1429 static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_volume __devinitdata
= {
1430 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1431 .name
= SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE
,VOLUME
),
1432 .info
= snd_ice1712_pro_mixer_volume_info
,
1433 .get
= snd_ice1712_pro_mixer_volume_get
,
1434 .put
= snd_ice1712_pro_mixer_volume_put
,
1435 .private_value
= 18,
1439 static int __devinit
snd_ice1712_build_pro_mixer(struct snd_ice1712
*ice
)
1441 struct snd_card
*card
= ice
->card
;
1445 /* multi-channel mixer */
1446 for (idx
= 0; idx
< ARRAY_SIZE(snd_ice1712_multi_playback_ctrls
); idx
++) {
1447 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_ice1712_multi_playback_ctrls
[idx
], ice
));
1452 if (ice
->num_total_adcs
> 0) {
1453 struct snd_kcontrol_new tmp
= snd_ice1712_multi_capture_analog_switch
;
1454 tmp
.count
= ice
->num_total_adcs
;
1455 err
= snd_ctl_add(card
, snd_ctl_new1(&tmp
, ice
));
1460 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_switch
, ice
));
1464 if (ice
->num_total_adcs
> 0) {
1465 struct snd_kcontrol_new tmp
= snd_ice1712_multi_capture_analog_volume
;
1466 tmp
.count
= ice
->num_total_adcs
;
1467 err
= snd_ctl_add(card
, snd_ctl_new1(&tmp
, ice
));
1472 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_volume
, ice
));
1476 /* initialize volumes */
1477 for (idx
= 0; idx
< 10; idx
++) {
1478 ice
->pro_volumes
[idx
] = 0x80008000; /* mute */
1479 snd_ice1712_update_volume(ice
, idx
);
1481 for (idx
= 10; idx
< 10 + ice
->num_total_adcs
; idx
++) {
1482 ice
->pro_volumes
[idx
] = 0x80008000; /* mute */
1483 snd_ice1712_update_volume(ice
, idx
);
1485 for (idx
= 18; idx
< 20; idx
++) {
1486 ice
->pro_volumes
[idx
] = 0x80008000; /* mute */
1487 snd_ice1712_update_volume(ice
, idx
);
1492 static void snd_ice1712_mixer_free_ac97(struct snd_ac97
*ac97
)
1494 struct snd_ice1712
*ice
= ac97
->private_data
;
1498 static int __devinit
snd_ice1712_ac97_mixer(struct snd_ice1712
* ice
)
1500 int err
, bus_num
= 0;
1501 struct snd_ac97_template ac97
;
1502 struct snd_ac97_bus
*pbus
;
1503 static struct snd_ac97_bus_ops con_ops
= {
1504 .write
= snd_ice1712_ac97_write
,
1505 .read
= snd_ice1712_ac97_read
,
1507 static struct snd_ac97_bus_ops pro_ops
= {
1508 .write
= snd_ice1712_pro_ac97_write
,
1509 .read
= snd_ice1712_pro_ac97_read
,
1512 if (ice_has_con_ac97(ice
)) {
1513 if ((err
= snd_ac97_bus(ice
->card
, bus_num
++, &con_ops
, NULL
, &pbus
)) < 0)
1515 memset(&ac97
, 0, sizeof(ac97
));
1516 ac97
.private_data
= ice
;
1517 ac97
.private_free
= snd_ice1712_mixer_free_ac97
;
1518 if ((err
= snd_ac97_mixer(pbus
, &ac97
, &ice
->ac97
)) < 0)
1519 printk(KERN_WARNING
"ice1712: cannot initialize ac97 for consumer, skipped\n");
1521 if ((err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97
, ice
))) < 0)
1527 if (! (ice
->eeprom
.data
[ICE_EEP1_ACLINK
] & ICE1712_CFG_PRO_I2S
)) {
1528 if ((err
= snd_ac97_bus(ice
->card
, bus_num
, &pro_ops
, NULL
, &pbus
)) < 0)
1530 memset(&ac97
, 0, sizeof(ac97
));
1531 ac97
.private_data
= ice
;
1532 ac97
.private_free
= snd_ice1712_mixer_free_ac97
;
1533 if ((err
= snd_ac97_mixer(pbus
, &ac97
, &ice
->ac97
)) < 0)
1534 printk(KERN_WARNING
"ice1712: cannot initialize pro ac97, skipped\n");
1538 /* I2S mixer only */
1539 strcat(ice
->card
->mixername
, "ICE1712 - multitrack");
1547 static inline unsigned int eeprom_double(struct snd_ice1712
*ice
, int idx
)
1549 return (unsigned int)ice
->eeprom
.data
[idx
] | ((unsigned int)ice
->eeprom
.data
[idx
+ 1] << 8);
1552 static void snd_ice1712_proc_read(struct snd_info_entry
*entry
,
1553 struct snd_info_buffer
*buffer
)
1555 struct snd_ice1712
*ice
= entry
->private_data
;
1558 snd_iprintf(buffer
, "%s\n\n", ice
->card
->longname
);
1559 snd_iprintf(buffer
, "EEPROM:\n");
1561 snd_iprintf(buffer
, " Subvendor : 0x%x\n", ice
->eeprom
.subvendor
);
1562 snd_iprintf(buffer
, " Size : %i bytes\n", ice
->eeprom
.size
);
1563 snd_iprintf(buffer
, " Version : %i\n", ice
->eeprom
.version
);
1564 snd_iprintf(buffer
, " Codec : 0x%x\n", ice
->eeprom
.data
[ICE_EEP1_CODEC
]);
1565 snd_iprintf(buffer
, " ACLink : 0x%x\n", ice
->eeprom
.data
[ICE_EEP1_ACLINK
]);
1566 snd_iprintf(buffer
, " I2S ID : 0x%x\n", ice
->eeprom
.data
[ICE_EEP1_I2SID
]);
1567 snd_iprintf(buffer
, " S/PDIF : 0x%x\n", ice
->eeprom
.data
[ICE_EEP1_SPDIF
]);
1568 snd_iprintf(buffer
, " GPIO mask : 0x%x\n", ice
->eeprom
.gpiomask
);
1569 snd_iprintf(buffer
, " GPIO state : 0x%x\n", ice
->eeprom
.gpiostate
);
1570 snd_iprintf(buffer
, " GPIO direction : 0x%x\n", ice
->eeprom
.gpiodir
);
1571 snd_iprintf(buffer
, " AC'97 main : 0x%x\n", eeprom_double(ice
, ICE_EEP1_AC97_MAIN_LO
));
1572 snd_iprintf(buffer
, " AC'97 pcm : 0x%x\n", eeprom_double(ice
, ICE_EEP1_AC97_PCM_LO
));
1573 snd_iprintf(buffer
, " AC'97 record : 0x%x\n", eeprom_double(ice
, ICE_EEP1_AC97_REC_LO
));
1574 snd_iprintf(buffer
, " AC'97 record src : 0x%x\n", ice
->eeprom
.data
[ICE_EEP1_AC97_RECSRC
]);
1575 for (idx
= 0; idx
< 4; idx
++)
1576 snd_iprintf(buffer
, " DAC ID #%i : 0x%x\n", idx
, ice
->eeprom
.data
[ICE_EEP1_DAC_ID
+ idx
]);
1577 for (idx
= 0; idx
< 4; idx
++)
1578 snd_iprintf(buffer
, " ADC ID #%i : 0x%x\n", idx
, ice
->eeprom
.data
[ICE_EEP1_ADC_ID
+ idx
]);
1579 for (idx
= 0x1c; idx
< ice
->eeprom
.size
; idx
++)
1580 snd_iprintf(buffer
, " Extra #%02i : 0x%x\n", idx
, ice
->eeprom
.data
[idx
]);
1582 snd_iprintf(buffer
, "\nRegisters:\n");
1583 snd_iprintf(buffer
, " PSDOUT03 : 0x%04x\n", (unsigned)inw(ICEMT(ice
, ROUTE_PSDOUT03
)));
1584 snd_iprintf(buffer
, " CAPTURE : 0x%08x\n", inl(ICEMT(ice
, ROUTE_CAPTURE
)));
1585 snd_iprintf(buffer
, " SPDOUT : 0x%04x\n", (unsigned)inw(ICEMT(ice
, ROUTE_SPDOUT
)));
1586 snd_iprintf(buffer
, " RATE : 0x%02x\n", (unsigned)inb(ICEMT(ice
, RATE
)));
1587 snd_iprintf(buffer
, " GPIO_DATA : 0x%02x\n", (unsigned)snd_ice1712_get_gpio_data(ice
));
1588 snd_iprintf(buffer
, " GPIO_WRITE_MASK : 0x%02x\n", (unsigned)snd_ice1712_read(ice
, ICE1712_IREG_GPIO_WRITE_MASK
));
1589 snd_iprintf(buffer
, " GPIO_DIRECTION : 0x%02x\n", (unsigned)snd_ice1712_read(ice
, ICE1712_IREG_GPIO_DIRECTION
));
1592 static void __devinit
snd_ice1712_proc_init(struct snd_ice1712
* ice
)
1594 struct snd_info_entry
*entry
;
1596 if (! snd_card_proc_new(ice
->card
, "ice1712", &entry
))
1597 snd_info_set_text_ops(entry
, ice
, 1024, snd_ice1712_proc_read
);
1604 static int snd_ice1712_eeprom_info(struct snd_kcontrol
*kcontrol
,
1605 struct snd_ctl_elem_info
*uinfo
)
1607 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BYTES
;
1608 uinfo
->count
= sizeof(struct snd_ice1712_eeprom
);
1612 static int snd_ice1712_eeprom_get(struct snd_kcontrol
*kcontrol
,
1613 struct snd_ctl_elem_value
*ucontrol
)
1615 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
1617 memcpy(ucontrol
->value
.bytes
.data
, &ice
->eeprom
, sizeof(ice
->eeprom
));
1621 static struct snd_kcontrol_new snd_ice1712_eeprom __devinitdata
= {
1622 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1623 .name
= "ICE1712 EEPROM",
1624 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1625 .info
= snd_ice1712_eeprom_info
,
1626 .get
= snd_ice1712_eeprom_get
1631 static int snd_ice1712_spdif_info(struct snd_kcontrol
*kcontrol
,
1632 struct snd_ctl_elem_info
*uinfo
)
1634 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
1639 static int snd_ice1712_spdif_default_get(struct snd_kcontrol
*kcontrol
,
1640 struct snd_ctl_elem_value
*ucontrol
)
1642 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
1643 if (ice
->spdif
.ops
.default_get
)
1644 ice
->spdif
.ops
.default_get(ice
, ucontrol
);
1648 static int snd_ice1712_spdif_default_put(struct snd_kcontrol
*kcontrol
,
1649 struct snd_ctl_elem_value
*ucontrol
)
1651 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
1652 if (ice
->spdif
.ops
.default_put
)
1653 return ice
->spdif
.ops
.default_put(ice
, ucontrol
);
1657 static struct snd_kcontrol_new snd_ice1712_spdif_default __devinitdata
=
1659 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1660 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,DEFAULT
),
1661 .info
= snd_ice1712_spdif_info
,
1662 .get
= snd_ice1712_spdif_default_get
,
1663 .put
= snd_ice1712_spdif_default_put
1666 static int snd_ice1712_spdif_maskc_get(struct snd_kcontrol
*kcontrol
,
1667 struct snd_ctl_elem_value
*ucontrol
)
1669 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
1670 if (ice
->spdif
.ops
.default_get
) {
1671 ucontrol
->value
.iec958
.status
[0] = IEC958_AES0_NONAUDIO
|
1672 IEC958_AES0_PROFESSIONAL
|
1673 IEC958_AES0_CON_NOT_COPYRIGHT
|
1674 IEC958_AES0_CON_EMPHASIS
;
1675 ucontrol
->value
.iec958
.status
[1] = IEC958_AES1_CON_ORIGINAL
|
1676 IEC958_AES1_CON_CATEGORY
;
1677 ucontrol
->value
.iec958
.status
[3] = IEC958_AES3_CON_FS
;
1679 ucontrol
->value
.iec958
.status
[0] = 0xff;
1680 ucontrol
->value
.iec958
.status
[1] = 0xff;
1681 ucontrol
->value
.iec958
.status
[2] = 0xff;
1682 ucontrol
->value
.iec958
.status
[3] = 0xff;
1683 ucontrol
->value
.iec958
.status
[4] = 0xff;
1688 static int snd_ice1712_spdif_maskp_get(struct snd_kcontrol
*kcontrol
,
1689 struct snd_ctl_elem_value
*ucontrol
)
1691 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
1692 if (ice
->spdif
.ops
.default_get
) {
1693 ucontrol
->value
.iec958
.status
[0] = IEC958_AES0_NONAUDIO
|
1694 IEC958_AES0_PROFESSIONAL
|
1695 IEC958_AES0_PRO_FS
|
1696 IEC958_AES0_PRO_EMPHASIS
;
1697 ucontrol
->value
.iec958
.status
[1] = IEC958_AES1_PRO_MODE
;
1699 ucontrol
->value
.iec958
.status
[0] = 0xff;
1700 ucontrol
->value
.iec958
.status
[1] = 0xff;
1701 ucontrol
->value
.iec958
.status
[2] = 0xff;
1702 ucontrol
->value
.iec958
.status
[3] = 0xff;
1703 ucontrol
->value
.iec958
.status
[4] = 0xff;
1708 static struct snd_kcontrol_new snd_ice1712_spdif_maskc __devinitdata
=
1710 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1711 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1712 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,CON_MASK
),
1713 .info
= snd_ice1712_spdif_info
,
1714 .get
= snd_ice1712_spdif_maskc_get
,
1717 static struct snd_kcontrol_new snd_ice1712_spdif_maskp __devinitdata
=
1719 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1720 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1721 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,PRO_MASK
),
1722 .info
= snd_ice1712_spdif_info
,
1723 .get
= snd_ice1712_spdif_maskp_get
,
1726 static int snd_ice1712_spdif_stream_get(struct snd_kcontrol
*kcontrol
,
1727 struct snd_ctl_elem_value
*ucontrol
)
1729 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
1730 if (ice
->spdif
.ops
.stream_get
)
1731 ice
->spdif
.ops
.stream_get(ice
, ucontrol
);
1735 static int snd_ice1712_spdif_stream_put(struct snd_kcontrol
*kcontrol
,
1736 struct snd_ctl_elem_value
*ucontrol
)
1738 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
1739 if (ice
->spdif
.ops
.stream_put
)
1740 return ice
->spdif
.ops
.stream_put(ice
, ucontrol
);
1744 static struct snd_kcontrol_new snd_ice1712_spdif_stream __devinitdata
=
1746 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
1747 SNDRV_CTL_ELEM_ACCESS_INACTIVE
),
1748 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1749 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,PCM_STREAM
),
1750 .info
= snd_ice1712_spdif_info
,
1751 .get
= snd_ice1712_spdif_stream_get
,
1752 .put
= snd_ice1712_spdif_stream_put
1755 int snd_ice1712_gpio_info(struct snd_kcontrol
*kcontrol
,
1756 struct snd_ctl_elem_info
*uinfo
)
1758 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1760 uinfo
->value
.integer
.min
= 0;
1761 uinfo
->value
.integer
.max
= 1;
1765 int snd_ice1712_gpio_get(struct snd_kcontrol
*kcontrol
,
1766 struct snd_ctl_elem_value
*ucontrol
)
1768 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
1769 unsigned char mask
= kcontrol
->private_value
& 0xff;
1770 int invert
= (kcontrol
->private_value
& (1<<24)) ? 1 : 0;
1772 snd_ice1712_save_gpio_status(ice
);
1773 ucontrol
->value
.integer
.value
[0] =
1774 (snd_ice1712_gpio_read(ice
) & mask
? 1 : 0) ^ invert
;
1775 snd_ice1712_restore_gpio_status(ice
);
1779 int snd_ice1712_gpio_put(struct snd_kcontrol
*kcontrol
,
1780 struct snd_ctl_elem_value
*ucontrol
)
1782 struct snd_ice1712
*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(struct snd_kcontrol
*kcontrol
,
1803 struct snd_ctl_elem_info
*uinfo
)
1805 static char *texts
[] = {
1808 "11025", /* 2: 10 */
1816 "64000", /* 10: 15 */
1817 "88200", /* 11: 11 */
1818 "96000", /* 12: 7 */
1819 "IEC958 Input", /* 13: -- */
1821 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1823 uinfo
->value
.enumerated
.items
= 14;
1824 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
1825 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
1826 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1830 static int snd_ice1712_pro_internal_clock_get(struct snd_kcontrol
*kcontrol
,
1831 struct snd_ctl_elem_value
*ucontrol
)
1833 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
1834 static unsigned char xlate
[16] = {
1835 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10
1839 spin_lock_irq(&ice
->reg_lock
);
1840 if (is_spdif_master(ice
)) {
1841 ucontrol
->value
.enumerated
.item
[0] = 13;
1843 val
= xlate
[inb(ICEMT(ice
, RATE
)) & 15];
1848 ucontrol
->value
.enumerated
.item
[0] = val
;
1850 spin_unlock_irq(&ice
->reg_lock
);
1854 static int snd_ice1712_pro_internal_clock_put(struct snd_kcontrol
*kcontrol
,
1855 struct snd_ctl_elem_value
*ucontrol
)
1857 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
1858 static unsigned int xrate
[13] = {
1859 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1860 32000, 44100, 48000, 64000, 88200, 96000
1865 spin_lock_irq(&ice
->reg_lock
);
1866 oval
= inb(ICEMT(ice
, RATE
));
1867 if (ucontrol
->value
.enumerated
.item
[0] == 13) {
1868 outb(oval
| ICE1712_SPDIF_MASTER
, ICEMT(ice
, RATE
));
1870 PRO_RATE_DEFAULT
= xrate
[ucontrol
->value
.integer
.value
[0] % 13];
1871 spin_unlock_irq(&ice
->reg_lock
);
1872 snd_ice1712_set_pro_rate(ice
, PRO_RATE_DEFAULT
, 1);
1873 spin_lock_irq(&ice
->reg_lock
);
1875 change
= inb(ICEMT(ice
, RATE
)) != oval
;
1876 spin_unlock_irq(&ice
->reg_lock
);
1878 if ((oval
& ICE1712_SPDIF_MASTER
) !=
1879 (inb(ICEMT(ice
, RATE
)) & ICE1712_SPDIF_MASTER
))
1880 snd_ice1712_set_input_clock_source(ice
, is_spdif_master(ice
));
1885 static struct snd_kcontrol_new snd_ice1712_pro_internal_clock __devinitdata
= {
1886 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1887 .name
= "Multi Track Internal Clock",
1888 .info
= snd_ice1712_pro_internal_clock_info
,
1889 .get
= snd_ice1712_pro_internal_clock_get
,
1890 .put
= snd_ice1712_pro_internal_clock_put
1893 static int snd_ice1712_pro_internal_clock_default_info(struct snd_kcontrol
*kcontrol
,
1894 struct snd_ctl_elem_info
*uinfo
)
1896 static char *texts
[] = {
1899 "11025", /* 2: 10 */
1907 "64000", /* 10: 15 */
1908 "88200", /* 11: 11 */
1909 "96000", /* 12: 7 */
1910 // "IEC958 Input", /* 13: -- */
1912 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1914 uinfo
->value
.enumerated
.items
= 13;
1915 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
1916 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
1917 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1921 static int snd_ice1712_pro_internal_clock_default_get(struct snd_kcontrol
*kcontrol
,
1922 struct snd_ctl_elem_value
*ucontrol
)
1925 static unsigned int xrate
[13] = {
1926 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1927 32000, 44100, 48000, 64000, 88200, 96000
1930 for (val
= 0; val
< 13; val
++) {
1931 if (xrate
[val
] == PRO_RATE_DEFAULT
)
1935 ucontrol
->value
.enumerated
.item
[0] = val
;
1939 static int snd_ice1712_pro_internal_clock_default_put(struct snd_kcontrol
*kcontrol
,
1940 struct snd_ctl_elem_value
*ucontrol
)
1942 static unsigned int xrate
[13] = {
1943 8000, 9600, 11025, 12000, 1600, 22050, 24000,
1944 32000, 44100, 48000, 64000, 88200, 96000
1949 oval
= PRO_RATE_DEFAULT
;
1950 PRO_RATE_DEFAULT
= xrate
[ucontrol
->value
.integer
.value
[0] % 13];
1951 change
= PRO_RATE_DEFAULT
!= oval
;
1956 static struct snd_kcontrol_new snd_ice1712_pro_internal_clock_default __devinitdata
= {
1957 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1958 .name
= "Multi Track Internal Clock Default",
1959 .info
= snd_ice1712_pro_internal_clock_default_info
,
1960 .get
= snd_ice1712_pro_internal_clock_default_get
,
1961 .put
= snd_ice1712_pro_internal_clock_default_put
1964 static int snd_ice1712_pro_rate_locking_info(struct snd_kcontrol
*kcontrol
,
1965 struct snd_ctl_elem_info
*uinfo
)
1967 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1969 uinfo
->value
.integer
.min
= 0;
1970 uinfo
->value
.integer
.max
= 1;
1974 static int snd_ice1712_pro_rate_locking_get(struct snd_kcontrol
*kcontrol
,
1975 struct snd_ctl_elem_value
*ucontrol
)
1977 ucontrol
->value
.integer
.value
[0] = PRO_RATE_LOCKED
;
1981 static int snd_ice1712_pro_rate_locking_put(struct snd_kcontrol
*kcontrol
,
1982 struct snd_ctl_elem_value
*ucontrol
)
1984 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
1985 int change
= 0, nval
;
1987 nval
= ucontrol
->value
.integer
.value
[0] ? 1 : 0;
1988 spin_lock_irq(&ice
->reg_lock
);
1989 change
= PRO_RATE_LOCKED
!= nval
;
1990 PRO_RATE_LOCKED
= nval
;
1991 spin_unlock_irq(&ice
->reg_lock
);
1995 static struct snd_kcontrol_new snd_ice1712_pro_rate_locking __devinitdata
= {
1996 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1997 .name
= "Multi Track Rate Locking",
1998 .info
= snd_ice1712_pro_rate_locking_info
,
1999 .get
= snd_ice1712_pro_rate_locking_get
,
2000 .put
= snd_ice1712_pro_rate_locking_put
2003 static int snd_ice1712_pro_rate_reset_info(struct snd_kcontrol
*kcontrol
,
2004 struct snd_ctl_elem_info
*uinfo
)
2006 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2008 uinfo
->value
.integer
.min
= 0;
2009 uinfo
->value
.integer
.max
= 1;
2013 static int snd_ice1712_pro_rate_reset_get(struct snd_kcontrol
*kcontrol
,
2014 struct snd_ctl_elem_value
*ucontrol
)
2016 ucontrol
->value
.integer
.value
[0] = PRO_RATE_RESET
;
2020 static int snd_ice1712_pro_rate_reset_put(struct snd_kcontrol
*kcontrol
,
2021 struct snd_ctl_elem_value
*ucontrol
)
2023 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
2024 int change
= 0, nval
;
2026 nval
= ucontrol
->value
.integer
.value
[0] ? 1 : 0;
2027 spin_lock_irq(&ice
->reg_lock
);
2028 change
= PRO_RATE_RESET
!= nval
;
2029 PRO_RATE_RESET
= nval
;
2030 spin_unlock_irq(&ice
->reg_lock
);
2034 static struct snd_kcontrol_new snd_ice1712_pro_rate_reset __devinitdata
= {
2035 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2036 .name
= "Multi Track Rate Reset",
2037 .info
= snd_ice1712_pro_rate_reset_info
,
2038 .get
= snd_ice1712_pro_rate_reset_get
,
2039 .put
= snd_ice1712_pro_rate_reset_put
2045 static int snd_ice1712_pro_route_info(struct snd_kcontrol
*kcontrol
,
2046 struct snd_ctl_elem_info
*uinfo
)
2048 static char *texts
[] = {
2050 "H/W In 0", "H/W In 1", "H/W In 2", "H/W In 3", /* 1-4 */
2051 "H/W In 4", "H/W In 5", "H/W In 6", "H/W In 7", /* 5-8 */
2052 "IEC958 In L", "IEC958 In R", /* 9-10 */
2053 "Digital Mixer", /* 11 - optional */
2056 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2058 uinfo
->value
.enumerated
.items
=
2059 snd_ctl_get_ioffidx(kcontrol
, &uinfo
->id
) < 2 ? 12 : 11;
2060 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2061 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2062 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2066 static int snd_ice1712_pro_route_analog_get(struct snd_kcontrol
*kcontrol
,
2067 struct snd_ctl_elem_value
*ucontrol
)
2069 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
2070 int idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
2071 unsigned int val
, cval
;
2073 spin_lock_irq(&ice
->reg_lock
);
2074 val
= inw(ICEMT(ice
, ROUTE_PSDOUT03
));
2075 cval
= inl(ICEMT(ice
, ROUTE_CAPTURE
));
2076 spin_unlock_irq(&ice
->reg_lock
);
2078 val
>>= ((idx
% 2) * 8) + ((idx
/ 2) * 2);
2080 cval
>>= ((idx
/ 2) * 8) + ((idx
% 2) * 4);
2081 if (val
== 1 && idx
< 2)
2082 ucontrol
->value
.enumerated
.item
[0] = 11;
2084 ucontrol
->value
.enumerated
.item
[0] = (cval
& 7) + 1;
2086 ucontrol
->value
.enumerated
.item
[0] = ((cval
>> 3) & 1) + 9;
2088 ucontrol
->value
.enumerated
.item
[0] = 0;
2092 static int snd_ice1712_pro_route_analog_put(struct snd_kcontrol
*kcontrol
,
2093 struct snd_ctl_elem_value
*ucontrol
)
2095 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
2097 int idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
2098 unsigned int val
, old_val
, nval
;
2101 if (ucontrol
->value
.enumerated
.item
[0] >= 11)
2102 nval
= idx
< 2 ? 1 : 0; /* dig mixer (or pcm) */
2103 else if (ucontrol
->value
.enumerated
.item
[0] >= 9)
2104 nval
= 3; /* spdif in */
2105 else if (ucontrol
->value
.enumerated
.item
[0] >= 1)
2106 nval
= 2; /* analog in */
2109 shift
= ((idx
% 2) * 8) + ((idx
/ 2) * 2);
2110 spin_lock_irq(&ice
->reg_lock
);
2111 val
= old_val
= inw(ICEMT(ice
, ROUTE_PSDOUT03
));
2112 val
&= ~(0x03 << shift
);
2113 val
|= nval
<< shift
;
2114 change
= val
!= old_val
;
2116 outw(val
, ICEMT(ice
, ROUTE_PSDOUT03
));
2117 spin_unlock_irq(&ice
->reg_lock
);
2118 if (nval
< 2) /* dig mixer of pcm */
2121 /* update CAPTURE */
2122 spin_lock_irq(&ice
->reg_lock
);
2123 val
= old_val
= inl(ICEMT(ice
, ROUTE_CAPTURE
));
2124 shift
= ((idx
/ 2) * 8) + ((idx
% 2) * 4);
2125 if (nval
== 2) { /* analog in */
2126 nval
= ucontrol
->value
.enumerated
.item
[0] - 1;
2127 val
&= ~(0x07 << shift
);
2128 val
|= nval
<< shift
;
2129 } else { /* spdif in */
2130 nval
= (ucontrol
->value
.enumerated
.item
[0] - 9) << 3;
2131 val
&= ~(0x08 << shift
);
2132 val
|= nval
<< shift
;
2134 if (val
!= old_val
) {
2136 outl(val
, ICEMT(ice
, ROUTE_CAPTURE
));
2138 spin_unlock_irq(&ice
->reg_lock
);
2142 static int snd_ice1712_pro_route_spdif_get(struct snd_kcontrol
*kcontrol
,
2143 struct snd_ctl_elem_value
*ucontrol
)
2145 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
2146 int idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
2147 unsigned int val
, cval
;
2148 val
= inw(ICEMT(ice
, ROUTE_SPDOUT
));
2149 cval
= (val
>> (idx
* 4 + 8)) & 0x0f;
2150 val
= (val
>> (idx
* 2)) & 0x03;
2152 ucontrol
->value
.enumerated
.item
[0] = 11;
2154 ucontrol
->value
.enumerated
.item
[0] = (cval
& 7) + 1;
2156 ucontrol
->value
.enumerated
.item
[0] = ((cval
>> 3) & 1) + 9;
2158 ucontrol
->value
.enumerated
.item
[0] = 0;
2162 static int snd_ice1712_pro_route_spdif_put(struct snd_kcontrol
*kcontrol
,
2163 struct snd_ctl_elem_value
*ucontrol
)
2165 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
2167 int idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
2168 unsigned int val
, old_val
, nval
;
2171 spin_lock_irq(&ice
->reg_lock
);
2172 val
= old_val
= inw(ICEMT(ice
, ROUTE_SPDOUT
));
2173 if (ucontrol
->value
.enumerated
.item
[0] >= 11)
2175 else if (ucontrol
->value
.enumerated
.item
[0] >= 9)
2177 else if (ucontrol
->value
.enumerated
.item
[0] >= 1)
2182 val
&= ~(0x03 << shift
);
2183 val
|= nval
<< shift
;
2184 shift
= idx
* 4 + 8;
2186 nval
= ucontrol
->value
.enumerated
.item
[0] - 1;
2187 val
&= ~(0x07 << shift
);
2188 val
|= nval
<< shift
;
2189 } else if (nval
== 3) {
2190 nval
= (ucontrol
->value
.enumerated
.item
[0] - 9) << 3;
2191 val
&= ~(0x08 << shift
);
2192 val
|= nval
<< shift
;
2194 change
= val
!= old_val
;
2196 outw(val
, ICEMT(ice
, ROUTE_SPDOUT
));
2197 spin_unlock_irq(&ice
->reg_lock
);
2201 static struct snd_kcontrol_new snd_ice1712_mixer_pro_analog_route __devinitdata
= {
2202 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2203 .name
= "H/W Playback Route",
2204 .info
= snd_ice1712_pro_route_info
,
2205 .get
= snd_ice1712_pro_route_analog_get
,
2206 .put
= snd_ice1712_pro_route_analog_put
,
2209 static struct snd_kcontrol_new snd_ice1712_mixer_pro_spdif_route __devinitdata
= {
2210 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2211 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Route",
2212 .info
= snd_ice1712_pro_route_info
,
2213 .get
= snd_ice1712_pro_route_spdif_get
,
2214 .put
= snd_ice1712_pro_route_spdif_put
,
2219 static int snd_ice1712_pro_volume_rate_info(struct snd_kcontrol
*kcontrol
,
2220 struct snd_ctl_elem_info
*uinfo
)
2222 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2224 uinfo
->value
.integer
.min
= 0;
2225 uinfo
->value
.integer
.max
= 255;
2229 static int snd_ice1712_pro_volume_rate_get(struct snd_kcontrol
*kcontrol
,
2230 struct snd_ctl_elem_value
*ucontrol
)
2232 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
2234 ucontrol
->value
.integer
.value
[0] = inb(ICEMT(ice
, MONITOR_RATE
));
2238 static int snd_ice1712_pro_volume_rate_put(struct snd_kcontrol
*kcontrol
,
2239 struct snd_ctl_elem_value
*ucontrol
)
2241 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
2244 spin_lock_irq(&ice
->reg_lock
);
2245 change
= inb(ICEMT(ice
, MONITOR_RATE
)) != ucontrol
->value
.integer
.value
[0];
2246 outb(ucontrol
->value
.integer
.value
[0], ICEMT(ice
, MONITOR_RATE
));
2247 spin_unlock_irq(&ice
->reg_lock
);
2251 static struct snd_kcontrol_new snd_ice1712_mixer_pro_volume_rate __devinitdata
= {
2252 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2253 .name
= "Multi Track Volume Rate",
2254 .info
= snd_ice1712_pro_volume_rate_info
,
2255 .get
= snd_ice1712_pro_volume_rate_get
,
2256 .put
= snd_ice1712_pro_volume_rate_put
2259 static int snd_ice1712_pro_peak_info(struct snd_kcontrol
*kcontrol
,
2260 struct snd_ctl_elem_info
*uinfo
)
2262 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2264 uinfo
->value
.integer
.min
= 0;
2265 uinfo
->value
.integer
.max
= 255;
2269 static int snd_ice1712_pro_peak_get(struct snd_kcontrol
*kcontrol
,
2270 struct snd_ctl_elem_value
*ucontrol
)
2272 struct snd_ice1712
*ice
= snd_kcontrol_chip(kcontrol
);
2275 spin_lock_irq(&ice
->reg_lock
);
2276 for (idx
= 0; idx
< 22; idx
++) {
2277 outb(idx
, ICEMT(ice
, MONITOR_PEAKINDEX
));
2278 ucontrol
->value
.integer
.value
[idx
] = inb(ICEMT(ice
, MONITOR_PEAKDATA
));
2280 spin_unlock_irq(&ice
->reg_lock
);
2284 static struct snd_kcontrol_new snd_ice1712_mixer_pro_peak __devinitdata
= {
2285 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2286 .name
= "Multi Track Peak",
2287 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
2288 .info
= snd_ice1712_pro_peak_info
,
2289 .get
= snd_ice1712_pro_peak_get
2297 * list of available boards
2299 static struct snd_ice1712_card_info
*card_tables
[] __devinitdata
= {
2300 snd_ice1712_hoontech_cards
,
2301 snd_ice1712_delta_cards
,
2302 snd_ice1712_ews_cards
,
2306 static unsigned char __devinit
snd_ice1712_read_i2c(struct snd_ice1712
*ice
,
2312 outb(addr
, ICEREG(ice
, I2C_BYTE_ADDR
));
2313 outb(dev
& ~ICE1712_I2C_WRITE
, ICEREG(ice
, I2C_DEV_ADDR
));
2314 while (t
-- > 0 && (inb(ICEREG(ice
, I2C_CTRL
)) & ICE1712_I2C_BUSY
)) ;
2315 return inb(ICEREG(ice
, I2C_DATA
));
2318 static int __devinit
snd_ice1712_read_eeprom(struct snd_ice1712
*ice
,
2319 const char *modelname
)
2321 int dev
= 0xa0; /* EEPROM device address */
2322 unsigned int i
, size
;
2323 struct snd_ice1712_card_info
**tbl
, *c
;
2325 if (! modelname
|| ! *modelname
) {
2326 ice
->eeprom
.subvendor
= 0;
2327 if ((inb(ICEREG(ice
, I2C_CTRL
)) & ICE1712_I2C_EEPROM
) != 0)
2328 ice
->eeprom
.subvendor
= (snd_ice1712_read_i2c(ice
, dev
, 0x00) << 0) |
2329 (snd_ice1712_read_i2c(ice
, dev
, 0x01) << 8) |
2330 (snd_ice1712_read_i2c(ice
, dev
, 0x02) << 16) |
2331 (snd_ice1712_read_i2c(ice
, dev
, 0x03) << 24);
2332 if (ice
->eeprom
.subvendor
== 0 ||
2333 ice
->eeprom
.subvendor
== (unsigned int)-1) {
2334 /* invalid subvendor from EEPROM, try the PCI subststem ID instead */
2336 pci_read_config_word(ice
->pci
, PCI_SUBSYSTEM_VENDOR_ID
, &vendor
);
2337 pci_read_config_word(ice
->pci
, PCI_SUBSYSTEM_ID
, &device
);
2338 ice
->eeprom
.subvendor
= ((unsigned int)swab16(vendor
) << 16) | swab16(device
);
2339 if (ice
->eeprom
.subvendor
== 0 || ice
->eeprom
.subvendor
== (unsigned int)-1) {
2340 printk(KERN_ERR
"ice1712: No valid ID is found\n");
2345 for (tbl
= card_tables
; *tbl
; tbl
++) {
2346 for (c
= *tbl
; c
->subvendor
; c
++) {
2347 if (modelname
&& c
->model
&& ! strcmp(modelname
, c
->model
)) {
2348 printk(KERN_INFO
"ice1712: Using board model %s\n", c
->name
);
2349 ice
->eeprom
.subvendor
= c
->subvendor
;
2350 } else if (c
->subvendor
!= ice
->eeprom
.subvendor
)
2352 if (! c
->eeprom_size
|| ! c
->eeprom_data
)
2354 /* if the EEPROM is given by the driver, use it */
2355 snd_printdd("using the defined eeprom..\n");
2356 ice
->eeprom
.version
= 1;
2357 ice
->eeprom
.size
= c
->eeprom_size
+ 6;
2358 memcpy(ice
->eeprom
.data
, c
->eeprom_data
, c
->eeprom_size
);
2362 printk(KERN_WARNING
"ice1712: No matching model found for ID 0x%x\n",
2363 ice
->eeprom
.subvendor
);
2366 ice
->eeprom
.size
= snd_ice1712_read_i2c(ice
, dev
, 0x04);
2367 if (ice
->eeprom
.size
< 6)
2368 ice
->eeprom
.size
= 32; /* FIXME: any cards without the correct size? */
2369 else if (ice
->eeprom
.size
> 32) {
2370 snd_printk(KERN_ERR
"invalid EEPROM (size = %i)\n", ice
->eeprom
.size
);
2373 ice
->eeprom
.version
= snd_ice1712_read_i2c(ice
, dev
, 0x05);
2374 if (ice
->eeprom
.version
!= 1) {
2375 snd_printk(KERN_ERR
"invalid EEPROM version %i\n",
2376 ice
->eeprom
.version
);
2379 size
= ice
->eeprom
.size
- 6;
2380 for (i
= 0; i
< size
; i
++)
2381 ice
->eeprom
.data
[i
] = snd_ice1712_read_i2c(ice
, dev
, i
+ 6);
2384 ice
->eeprom
.gpiomask
= ice
->eeprom
.data
[ICE_EEP1_GPIO_MASK
];
2385 ice
->eeprom
.gpiostate
= ice
->eeprom
.data
[ICE_EEP1_GPIO_STATE
];
2386 ice
->eeprom
.gpiodir
= ice
->eeprom
.data
[ICE_EEP1_GPIO_DIR
];
2393 static int __devinit
snd_ice1712_chip_init(struct snd_ice1712
*ice
)
2395 outb(ICE1712_RESET
| ICE1712_NATIVE
, ICEREG(ice
, CONTROL
));
2397 outb(ICE1712_NATIVE
, ICEREG(ice
, CONTROL
));
2399 if (ice
->eeprom
.subvendor
== ICE1712_SUBDEVICE_DMX6FIRE
&& !ice
->dxr_enable
) {
2400 /* Limit active ADCs and DACs to 6; */
2401 /* Note: DXR extension not supported */
2402 pci_write_config_byte(ice
->pci
, 0x60, 0x0a);
2404 pci_write_config_byte(ice
->pci
, 0x60, ice
->eeprom
.data
[ICE_EEP1_CODEC
]);
2406 pci_write_config_byte(ice
->pci
, 0x61, ice
->eeprom
.data
[ICE_EEP1_ACLINK
]);
2407 pci_write_config_byte(ice
->pci
, 0x62, ice
->eeprom
.data
[ICE_EEP1_I2SID
]);
2408 pci_write_config_byte(ice
->pci
, 0x63, ice
->eeprom
.data
[ICE_EEP1_SPDIF
]);
2409 if (ice
->eeprom
.subvendor
!= ICE1712_SUBDEVICE_STDSP24
) {
2410 ice
->gpio
.write_mask
= ice
->eeprom
.gpiomask
;
2411 ice
->gpio
.direction
= ice
->eeprom
.gpiodir
;
2412 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
,
2413 ice
->eeprom
.gpiomask
);
2414 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DIRECTION
,
2415 ice
->eeprom
.gpiodir
);
2416 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
,
2417 ice
->eeprom
.gpiostate
);
2419 ice
->gpio
.write_mask
= 0xc0;
2420 ice
->gpio
.direction
= 0xff;
2421 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_WRITE_MASK
, 0xc0);
2422 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DIRECTION
, 0xff);
2423 snd_ice1712_write(ice
, ICE1712_IREG_GPIO_DATA
,
2424 ICE1712_STDSP24_CLOCK_BIT
);
2426 snd_ice1712_write(ice
, ICE1712_IREG_PRO_POWERDOWN
, 0);
2427 if (!(ice
->eeprom
.data
[ICE_EEP1_CODEC
] & ICE1712_CFG_NO_CON_AC97
)) {
2428 outb(ICE1712_AC97_WARM
, ICEREG(ice
, AC97_CMD
));
2430 outb(0, ICEREG(ice
, AC97_CMD
));
2432 snd_ice1712_write(ice
, ICE1712_IREG_CONSUMER_POWERDOWN
, 0);
2434 snd_ice1712_set_pro_rate(ice
, 48000, 1);
2439 int __devinit
snd_ice1712_spdif_build_controls(struct snd_ice1712
*ice
)
2442 struct snd_kcontrol
*kctl
;
2444 snd_assert(ice
->pcm_pro
!= NULL
, return -EIO
);
2445 err
= snd_ctl_add(ice
->card
, kctl
= snd_ctl_new1(&snd_ice1712_spdif_default
, ice
));
2448 kctl
->id
.device
= ice
->pcm_pro
->device
;
2449 err
= snd_ctl_add(ice
->card
, kctl
= snd_ctl_new1(&snd_ice1712_spdif_maskc
, ice
));
2452 kctl
->id
.device
= ice
->pcm_pro
->device
;
2453 err
= snd_ctl_add(ice
->card
, kctl
= snd_ctl_new1(&snd_ice1712_spdif_maskp
, ice
));
2456 kctl
->id
.device
= ice
->pcm_pro
->device
;
2457 err
= snd_ctl_add(ice
->card
, kctl
= snd_ctl_new1(&snd_ice1712_spdif_stream
, ice
));
2460 kctl
->id
.device
= ice
->pcm_pro
->device
;
2461 ice
->spdif
.stream_ctl
= kctl
;
2466 static int __devinit
snd_ice1712_build_controls(struct snd_ice1712
*ice
)
2470 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_eeprom
, ice
));
2473 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_pro_internal_clock
, ice
));
2476 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_pro_internal_clock_default
, ice
));
2480 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_pro_rate_locking
, ice
));
2483 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_pro_rate_reset
, ice
));
2487 if (ice
->num_total_dacs
> 0) {
2488 struct snd_kcontrol_new tmp
= snd_ice1712_mixer_pro_analog_route
;
2489 tmp
.count
= ice
->num_total_dacs
;
2490 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&tmp
, ice
));
2495 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route
, ice
));
2499 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate
, ice
));
2502 err
= snd_ctl_add(ice
->card
, snd_ctl_new1(&snd_ice1712_mixer_pro_peak
, ice
));
2509 static int snd_ice1712_free(struct snd_ice1712
*ice
)
2513 /* mask all interrupts */
2514 outb(0xc0, ICEMT(ice
, IRQ
));
2515 outb(0xff, ICEREG(ice
, IRQMASK
));
2518 if (ice
->irq
>= 0) {
2519 synchronize_irq(ice
->irq
);
2520 free_irq(ice
->irq
, ice
);
2523 pci_release_regions(ice
->pci
);
2524 snd_ice1712_akm4xxx_free(ice
);
2525 pci_disable_device(ice
->pci
);
2530 static int snd_ice1712_dev_free(struct snd_device
*device
)
2532 struct snd_ice1712
*ice
= device
->device_data
;
2533 return snd_ice1712_free(ice
);
2536 static int __devinit
snd_ice1712_create(struct snd_card
*card
,
2537 struct pci_dev
*pci
,
2538 const char *modelname
,
2542 struct snd_ice1712
** r_ice1712
)
2544 struct snd_ice1712
*ice
;
2546 static struct snd_device_ops ops
= {
2547 .dev_free
= snd_ice1712_dev_free
,
2552 /* enable PCI device */
2553 if ((err
= pci_enable_device(pci
)) < 0)
2555 /* check, if we can restrict PCI DMA transfers to 28 bits */
2556 if (pci_set_dma_mask(pci
, 0x0fffffff) < 0 ||
2557 pci_set_consistent_dma_mask(pci
, 0x0fffffff) < 0) {
2558 snd_printk(KERN_ERR
"architecture does not support 28bit PCI busmaster DMA\n");
2559 pci_disable_device(pci
);
2563 ice
= kzalloc(sizeof(*ice
), GFP_KERNEL
);
2565 pci_disable_device(pci
);
2568 ice
->omni
= omni
? 1 : 0;
2569 if (cs8427_timeout
< 1)
2571 else if (cs8427_timeout
> 1000)
2572 cs8427_timeout
= 1000;
2573 ice
->cs8427_timeout
= cs8427_timeout
;
2574 ice
->dxr_enable
= dxr_enable
;
2575 spin_lock_init(&ice
->reg_lock
);
2576 mutex_init(&ice
->gpio_mutex
);
2577 mutex_init(&ice
->i2c_mutex
);
2578 mutex_init(&ice
->open_mutex
);
2579 ice
->gpio
.set_mask
= snd_ice1712_set_gpio_mask
;
2580 ice
->gpio
.set_dir
= snd_ice1712_set_gpio_dir
;
2581 ice
->gpio
.set_data
= snd_ice1712_set_gpio_data
;
2582 ice
->gpio
.get_data
= snd_ice1712_get_gpio_data
;
2584 ice
->spdif
.cs8403_bits
=
2585 ice
->spdif
.cs8403_stream_bits
= (0x01 | /* consumer format */
2586 0x10 | /* no emphasis */
2587 0x20); /* PCM encoder/decoder */
2591 pci_set_master(pci
);
2592 pci_write_config_word(ice
->pci
, 0x40, 0x807f);
2593 pci_write_config_word(ice
->pci
, 0x42, 0x0006);
2594 snd_ice1712_proc_init(ice
);
2595 synchronize_irq(pci
->irq
);
2597 if ((err
= pci_request_regions(pci
, "ICE1712")) < 0) {
2599 pci_disable_device(pci
);
2602 ice
->port
= pci_resource_start(pci
, 0);
2603 ice
->ddma_port
= pci_resource_start(pci
, 1);
2604 ice
->dmapath_port
= pci_resource_start(pci
, 2);
2605 ice
->profi_port
= pci_resource_start(pci
, 3);
2607 if (request_irq(pci
->irq
, snd_ice1712_interrupt
, SA_INTERRUPT
|SA_SHIRQ
,
2609 snd_printk(KERN_ERR
"unable to grab IRQ %d\n", pci
->irq
);
2610 snd_ice1712_free(ice
);
2614 ice
->irq
= pci
->irq
;
2616 if (snd_ice1712_read_eeprom(ice
, modelname
) < 0) {
2617 snd_ice1712_free(ice
);
2620 if (snd_ice1712_chip_init(ice
) < 0) {
2621 snd_ice1712_free(ice
);
2625 /* unmask used interrupts */
2626 outb(((ice
->eeprom
.data
[ICE_EEP1_CODEC
] & ICE1712_CFG_2xMPU401
) == 0 ?
2627 ICE1712_IRQ_MPU2
: 0) |
2628 ((ice
->eeprom
.data
[ICE_EEP1_CODEC
] & ICE1712_CFG_NO_CON_AC97
) ?
2629 ICE1712_IRQ_PBKDS
| ICE1712_IRQ_CONCAP
| ICE1712_IRQ_CONPBK
: 0),
2630 ICEREG(ice
, IRQMASK
));
2631 outb(0x00, ICEMT(ice
, IRQ
));
2633 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, ice
, &ops
)) < 0) {
2634 snd_ice1712_free(ice
);
2638 snd_card_set_dev(card
, &pci
->dev
);
2651 static struct snd_ice1712_card_info no_matched __devinitdata
;
2653 static int __devinit
snd_ice1712_probe(struct pci_dev
*pci
,
2654 const struct pci_device_id
*pci_id
)
2657 struct snd_card
*card
;
2658 struct snd_ice1712
*ice
;
2659 int pcm_dev
= 0, err
;
2660 struct snd_ice1712_card_info
**tbl
, *c
;
2662 if (dev
>= SNDRV_CARDS
)
2669 card
= snd_card_new(index
[dev
], id
[dev
], THIS_MODULE
, 0);
2673 strcpy(card
->driver
, "ICE1712");
2674 strcpy(card
->shortname
, "ICEnsemble ICE1712");
2676 if ((err
= snd_ice1712_create(card
, pci
, model
[dev
], omni
[dev
],
2677 cs8427_timeout
[dev
], dxr_enable
[dev
],
2679 snd_card_free(card
);
2683 for (tbl
= card_tables
; *tbl
; tbl
++) {
2684 for (c
= *tbl
; c
->subvendor
; c
++) {
2685 if (c
->subvendor
== ice
->eeprom
.subvendor
) {
2686 strcpy(card
->shortname
, c
->name
);
2687 if (c
->driver
) /* specific driver? */
2688 strcpy(card
->driver
, c
->driver
);
2690 if ((err
= c
->chip_init(ice
)) < 0) {
2691 snd_card_free(card
);
2702 if ((err
= snd_ice1712_pcm_profi(ice
, pcm_dev
++, NULL
)) < 0) {
2703 snd_card_free(card
);
2707 if (ice_has_con_ac97(ice
))
2708 if ((err
= snd_ice1712_pcm(ice
, pcm_dev
++, NULL
)) < 0) {
2709 snd_card_free(card
);
2713 if ((err
= snd_ice1712_ac97_mixer(ice
)) < 0) {
2714 snd_card_free(card
);
2718 if ((err
= snd_ice1712_build_controls(ice
)) < 0) {
2719 snd_card_free(card
);
2723 if (c
->build_controls
) {
2724 if ((err
= c
->build_controls(ice
)) < 0) {
2725 snd_card_free(card
);
2730 if (ice_has_con_ac97(ice
))
2731 if ((err
= snd_ice1712_pcm_ds(ice
, pcm_dev
++, NULL
)) < 0) {
2732 snd_card_free(card
);
2736 if (! c
->no_mpu401
) {
2737 if ((err
= snd_mpu401_uart_new(card
, 0, MPU401_HW_ICE1712
,
2738 ICEREG(ice
, MPU1_CTRL
), 1,
2740 &ice
->rmidi
[0])) < 0) {
2741 snd_card_free(card
);
2745 if (ice
->eeprom
.data
[ICE_EEP1_CODEC
] & ICE1712_CFG_2xMPU401
)
2746 if ((err
= snd_mpu401_uart_new(card
, 1, MPU401_HW_ICE1712
,
2747 ICEREG(ice
, MPU2_CTRL
), 1,
2749 &ice
->rmidi
[1])) < 0) {
2750 snd_card_free(card
);
2755 snd_ice1712_set_input_clock_source(ice
, 0);
2757 sprintf(card
->longname
, "%s at 0x%lx, irq %i",
2758 card
->shortname
, ice
->port
, ice
->irq
);
2760 if ((err
= snd_card_register(card
)) < 0) {
2761 snd_card_free(card
);
2764 pci_set_drvdata(pci
, card
);
2769 static void __devexit
snd_ice1712_remove(struct pci_dev
*pci
)
2771 snd_card_free(pci_get_drvdata(pci
));
2772 pci_set_drvdata(pci
, NULL
);
2775 static struct pci_driver driver
= {
2777 .id_table
= snd_ice1712_ids
,
2778 .probe
= snd_ice1712_probe
,
2779 .remove
= __devexit_p(snd_ice1712_remove
),
2782 static int __init
alsa_card_ice1712_init(void)
2784 return pci_register_driver(&driver
);
2787 static void __exit
alsa_card_ice1712_exit(void)
2789 pci_unregister_driver(&driver
);
2792 module_init(alsa_card_ice1712_init
)
2793 module_exit(alsa_card_ice1712_exit
)