blob: cd41c7eb6c6b4f31686f12a3e062dc07d57db3e6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ALSA driver for ICEnsemble ICE1712 (Envy24)
3 *
4 * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
5 *
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.
10 *
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.
15 *
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
19 *
20 */
21
22/*
23 NOTES:
24 - spdif nonaudio consumer mode does not work (at least with my
25 Sony STR-DB830)
26*/
27
28/*
29 * Changes:
30 *
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.
35 *
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
40 *
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.
44 *
45 * 2004.03.31 Doug McLain <nostar@comcast.net>
46 * Added support for Event Electronics EZ8 card to hoontech.c.
47 */
48
49
50#include <sound/driver.h>
51#include <asm/io.h>
52#include <linux/delay.h>
53#include <linux/interrupt.h>
54#include <linux/init.h>
55#include <linux/pci.h>
Tobias Klauser9d2f9282006-03-22 10:53:19 +010056#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#include <linux/slab.h>
58#include <linux/moduleparam.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010059#include <linux/mutex.h>
Matthias Gehre910638a2006-03-28 01:56:48 -080060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include <sound/core.h>
62#include <sound/cs8427.h>
63#include <sound/info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#include <sound/initval.h>
Takashi Iwai680ef792006-08-30 16:56:30 +020065#include <sound/tlv.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67#include <sound/asoundef.h>
68
69#include "ice1712.h"
70
71/* lowlevel routines */
72#include "delta.h"
73#include "ews.h"
74#include "hoontech.h"
75
76MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
77MODULE_DESCRIPTION("ICEnsemble ICE1712 (Envy24)");
78MODULE_LICENSE("GPL");
79MODULE_SUPPORTED_DEVICE("{"
80 HOONTECH_DEVICE_DESC
81 DELTA_DEVICE_DESC
82 EWS_DEVICE_DESC
83 "{ICEnsemble,Generic ICE1712},"
84 "{ICEnsemble,Generic Envy24}}");
85
86static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
87static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
Alan Horstmann01a00e52006-03-21 09:57:36 +010088static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089static char *model[SNDRV_CARDS];
Alan Horstmann01a00e52006-03-21 09:57:36 +010090static int omni[SNDRV_CARDS]; /* Delta44 & 66 Omni I/O support */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091static int cs8427_timeout[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 500}; /* CS8427 S/PDIF transciever reset timeout value in msec */
Alan Horstmann01a00e52006-03-21 09:57:36 +010092static int dxr_enable[SNDRV_CARDS]; /* DXR enable for DMX6FIRE */
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94module_param_array(index, int, NULL, 0444);
95MODULE_PARM_DESC(index, "Index value for ICE1712 soundcard.");
96module_param_array(id, charp, NULL, 0444);
97MODULE_PARM_DESC(id, "ID string for ICE1712 soundcard.");
98module_param_array(enable, bool, NULL, 0444);
99MODULE_PARM_DESC(enable, "Enable ICE1712 soundcard.");
100module_param_array(omni, bool, NULL, 0444);
101MODULE_PARM_DESC(omni, "Enable Midiman M-Audio Delta Omni I/O support.");
102module_param_array(cs8427_timeout, int, NULL, 0444);
103MODULE_PARM_DESC(cs8427_timeout, "Define reset timeout for cs8427 chip in msec resolution.");
104module_param_array(model, charp, NULL, 0444);
105MODULE_PARM_DESC(model, "Use the given board model.");
Alan Horstmann531af462006-02-08 07:40:33 +0100106module_param_array(dxr_enable, int, NULL, 0444);
Alan Horstmann01a00e52006-03-21 09:57:36 +0100107MODULE_PARM_DESC(dxr_enable, "Enable DXR support for Terratec DMX6FIRE.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Takashi Iwai32b47da2007-01-29 15:26:36 +0100110static const struct pci_device_id snd_ice1712_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_ICE_1712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* ICE1712 */
112 { 0, }
113};
114
115MODULE_DEVICE_TABLE(pci, snd_ice1712_ids);
116
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100117static int snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice);
118static int snd_ice1712_build_controls(struct snd_ice1712 *ice);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120static int PRO_RATE_LOCKED;
121static int PRO_RATE_RESET = 1;
122static unsigned int PRO_RATE_DEFAULT = 44100;
123
124/*
125 * Basic I/O
126 */
127
128/* check whether the clock mode is spdif-in */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100129static inline int is_spdif_master(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
131 return (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER) ? 1 : 0;
132}
133
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100134static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
136 return is_spdif_master(ice) || PRO_RATE_LOCKED;
137}
138
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100139static inline void snd_ice1712_ds_write(struct snd_ice1712 * ice, u8 channel, u8 addr, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
141 outb((channel << 4) | addr, ICEDS(ice, INDEX));
142 outl(data, ICEDS(ice, DATA));
143}
144
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100145static inline u32 snd_ice1712_ds_read(struct snd_ice1712 * ice, u8 channel, u8 addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
147 outb((channel << 4) | addr, ICEDS(ice, INDEX));
148 return inl(ICEDS(ice, DATA));
149}
150
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100151static void snd_ice1712_ac97_write(struct snd_ac97 *ac97,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 unsigned short reg,
153 unsigned short val)
154{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100155 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 int tm;
157 unsigned char old_cmd = 0;
158
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))
162 continue;
163 if (!(old_cmd & ICE1712_AC97_READY))
164 continue;
165 break;
166 }
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)
173 break;
174}
175
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100176static unsigned short snd_ice1712_ac97_read(struct snd_ac97 *ac97,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 unsigned short reg)
178{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100179 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 int tm;
181 unsigned char old_cmd = 0;
182
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))
186 continue;
187 if (!(old_cmd & ICE1712_AC97_READY))
188 continue;
189 break;
190 }
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)
195 break;
196 if (tm >= 0x10000) /* timeout */
197 return ~0;
198 return inw(ICEREG(ice, AC97_DATA));
199}
200
201/*
202 * pro ac97 section
203 */
204
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100205static void snd_ice1712_pro_ac97_write(struct snd_ac97 *ac97,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 unsigned short reg,
207 unsigned short val)
208{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100209 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 int tm;
211 unsigned char old_cmd = 0;
212
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))
216 continue;
217 if (!(old_cmd & ICE1712_AC97_READY))
218 continue;
219 break;
220 }
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)
227 break;
228}
229
230
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100231static unsigned short snd_ice1712_pro_ac97_read(struct snd_ac97 *ac97,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 unsigned short reg)
233{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100234 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 int tm;
236 unsigned char old_cmd = 0;
237
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))
241 continue;
242 if (!(old_cmd & ICE1712_AC97_READY))
243 continue;
244 break;
245 }
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)
250 break;
251 if (tm >= 0x10000) /* timeout */
252 return ~0;
253 return inw(ICEMT(ice, AC97_DATA));
254}
255
256/*
257 * consumer ac97 digital mix
258 */
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200259#define snd_ice1712_digmix_route_ac97_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100261static int snd_ice1712_digmix_route_ac97_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100263 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0;
266 return 0;
267}
268
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100269static int snd_ice1712_digmix_route_ac97_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100271 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 unsigned char val, nval;
273
274 spin_lock_irq(&ice->reg_lock);
275 val = inb(ICEMT(ice, MONITOR_ROUTECTRL));
276 nval = val & ~ICE1712_ROUTE_AC97;
277 if (ucontrol->value.integer.value[0]) nval |= ICE1712_ROUTE_AC97;
278 outb(nval, ICEMT(ice, MONITOR_ROUTECTRL));
279 spin_unlock_irq(&ice->reg_lock);
280 return val != nval;
281}
282
Ralf Baechlebf748ed2007-03-13 15:31:08 +0100283static struct snd_kcontrol_new snd_ice1712_mixer_digmix_route_ac97 __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
285 .name = "Digital Mixer To AC97",
286 .info = snd_ice1712_digmix_route_ac97_info,
287 .get = snd_ice1712_digmix_route_ac97_get,
288 .put = snd_ice1712_digmix_route_ac97_put,
289};
290
291
292/*
293 * gpio operations
294 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100295static void snd_ice1712_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296{
297 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, data);
298 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
299}
300
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100301static void snd_ice1712_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
303 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data);
304 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
305}
306
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100307static unsigned int snd_ice1712_get_gpio_data(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
309 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
310}
311
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100312static void snd_ice1712_set_gpio_data(struct snd_ice1712 *ice, unsigned int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
314 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, val);
315 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
316}
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318/*
319 *
320 * CS8427 interface
321 *
322 */
323
324/*
325 * change the input clock selection
326 * spdif_clock = 1 - IEC958 input, 0 - Envy24
327 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100328static int snd_ice1712_cs8427_set_input_clock(struct snd_ice1712 *ice, int spdif_clock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
330 unsigned char reg[2] = { 0x80 | 4, 0 }; /* CS8427 auto increment | register number 4 + data */
331 unsigned char val, nval;
332 int res = 0;
333
334 snd_i2c_lock(ice->i2c);
335 if (snd_i2c_sendbytes(ice->cs8427, reg, 1) != 1) {
336 snd_i2c_unlock(ice->i2c);
337 return -EIO;
338 }
339 if (snd_i2c_readbytes(ice->cs8427, &val, 1) != 1) {
340 snd_i2c_unlock(ice->i2c);
341 return -EIO;
342 }
343 nval = val & 0xf0;
344 if (spdif_clock)
345 nval |= 0x01;
346 else
347 nval |= 0x04;
348 if (val != nval) {
349 reg[1] = nval;
350 if (snd_i2c_sendbytes(ice->cs8427, reg, 2) != 2) {
351 res = -EIO;
352 } else {
353 res++;
354 }
355 }
356 snd_i2c_unlock(ice->i2c);
357 return res;
358}
359
360/*
361 * spdif callbacks
362 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100363static void open_cs8427(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
365 snd_cs8427_iec958_active(ice->cs8427, 1);
366}
367
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100368static void close_cs8427(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
370 snd_cs8427_iec958_active(ice->cs8427, 0);
371}
372
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100373static void setup_cs8427(struct snd_ice1712 *ice, int rate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
375 snd_cs8427_iec958_pcm(ice->cs8427, rate);
376}
377
378/*
379 * create and initialize callbacks for cs8427 interface
380 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100381int __devinit snd_ice1712_init_cs8427(struct snd_ice1712 *ice, int addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
383 int err;
384
385 if ((err = snd_cs8427_create(ice->i2c, addr,
386 (ice->cs8427_timeout * HZ) / 1000,
387 &ice->cs8427)) < 0) {
Takashi Iwai99b359b2005-10-20 18:26:44 +0200388 snd_printk(KERN_ERR "CS8427 initialization failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 return err;
390 }
391 ice->spdif.ops.open = open_cs8427;
392 ice->spdif.ops.close = close_cs8427;
393 ice->spdif.ops.setup_rate = setup_cs8427;
394 return 0;
395}
396
Jaroslav Kyselae957ebf2006-02-02 07:56:54 +0100397static void snd_ice1712_set_input_clock_source(struct snd_ice1712 *ice, int spdif_is_master)
398{
399 /* change CS8427 clock source too */
400 if (ice->cs8427)
401 snd_ice1712_cs8427_set_input_clock(ice, spdif_is_master);
402 /* notify ak4524 chip as well */
403 if (spdif_is_master) {
404 unsigned int i;
405 for (i = 0; i < ice->akm_codecs; i++) {
406 if (ice->akm[i].ops.set_rate_val)
407 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
408 }
409 }
410}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412/*
413 * Interrupt handler
414 */
415
David Howells7d12e782006-10-05 14:55:46 +0100416static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100418 struct snd_ice1712 *ice = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 unsigned char status;
420 int handled = 0;
421
422 while (1) {
423 status = inb(ICEREG(ice, IRQSTAT));
424 if (status == 0)
425 break;
426 handled = 1;
427 if (status & ICE1712_IRQ_MPU1) {
428 if (ice->rmidi[0])
David Howells7d12e782006-10-05 14:55:46 +0100429 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 outb(ICE1712_IRQ_MPU1, ICEREG(ice, IRQSTAT));
431 status &= ~ICE1712_IRQ_MPU1;
432 }
433 if (status & ICE1712_IRQ_TIMER)
434 outb(ICE1712_IRQ_TIMER, ICEREG(ice, IRQSTAT));
435 if (status & ICE1712_IRQ_MPU2) {
436 if (ice->rmidi[1])
David Howells7d12e782006-10-05 14:55:46 +0100437 snd_mpu401_uart_interrupt(irq, ice->rmidi[1]->private_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 outb(ICE1712_IRQ_MPU2, ICEREG(ice, IRQSTAT));
439 status &= ~ICE1712_IRQ_MPU2;
440 }
441 if (status & ICE1712_IRQ_PROPCM) {
442 unsigned char mtstat = inb(ICEMT(ice, IRQ));
443 if (mtstat & ICE1712_MULTI_PBKSTATUS) {
444 if (ice->playback_pro_substream)
445 snd_pcm_period_elapsed(ice->playback_pro_substream);
446 outb(ICE1712_MULTI_PBKSTATUS, ICEMT(ice, IRQ));
447 }
448 if (mtstat & ICE1712_MULTI_CAPSTATUS) {
449 if (ice->capture_pro_substream)
450 snd_pcm_period_elapsed(ice->capture_pro_substream);
451 outb(ICE1712_MULTI_CAPSTATUS, ICEMT(ice, IRQ));
452 }
453 }
454 if (status & ICE1712_IRQ_FM)
455 outb(ICE1712_IRQ_FM, ICEREG(ice, IRQSTAT));
456 if (status & ICE1712_IRQ_PBKDS) {
457 u32 idx;
458 u16 pbkstatus;
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100459 struct snd_pcm_substream *substream;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 pbkstatus = inw(ICEDS(ice, INTSTAT));
461 //printk("pbkstatus = 0x%x\n", pbkstatus);
462 for (idx = 0; idx < 6; idx++) {
463 if ((pbkstatus & (3 << (idx * 2))) == 0)
464 continue;
465 if ((substream = ice->playback_con_substream_ds[idx]) != NULL)
466 snd_pcm_period_elapsed(substream);
467 outw(3 << (idx * 2), ICEDS(ice, INTSTAT));
468 }
469 outb(ICE1712_IRQ_PBKDS, ICEREG(ice, IRQSTAT));
470 }
471 if (status & ICE1712_IRQ_CONCAP) {
472 if (ice->capture_con_substream)
473 snd_pcm_period_elapsed(ice->capture_con_substream);
474 outb(ICE1712_IRQ_CONCAP, ICEREG(ice, IRQSTAT));
475 }
476 if (status & ICE1712_IRQ_CONPBK) {
477 if (ice->playback_con_substream)
478 snd_pcm_period_elapsed(ice->playback_con_substream);
479 outb(ICE1712_IRQ_CONPBK, ICEREG(ice, IRQSTAT));
480 }
481 }
482 return IRQ_RETVAL(handled);
483}
484
485
486/*
487 * PCM part - misc
488 */
489
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100490static int snd_ice1712_hw_params(struct snd_pcm_substream *substream,
491 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492{
493 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
494}
495
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100496static int snd_ice1712_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497{
498 return snd_pcm_lib_free_pages(substream);
499}
500
501/*
502 * PCM part - consumer I/O
503 */
504
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100505static int snd_ice1712_playback_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 int cmd)
507{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100508 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 int result = 0;
510 u32 tmp;
511
512 spin_lock(&ice->reg_lock);
513 tmp = snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL);
514 if (cmd == SNDRV_PCM_TRIGGER_START) {
515 tmp |= 1;
516 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
517 tmp &= ~1;
518 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
519 tmp |= 2;
520 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
521 tmp &= ~2;
522 } else {
523 result = -EINVAL;
524 }
525 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
526 spin_unlock(&ice->reg_lock);
527 return result;
528}
529
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100530static int snd_ice1712_playback_ds_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 int cmd)
532{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100533 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 int result = 0;
535 u32 tmp;
536
537 spin_lock(&ice->reg_lock);
538 tmp = snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL);
539 if (cmd == SNDRV_PCM_TRIGGER_START) {
540 tmp |= 1;
541 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
542 tmp &= ~1;
543 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
544 tmp |= 2;
545 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
546 tmp &= ~2;
547 } else {
548 result = -EINVAL;
549 }
550 snd_ice1712_ds_write(ice, substream->number * 2, ICE1712_DSC_CONTROL, tmp);
551 spin_unlock(&ice->reg_lock);
552 return result;
553}
554
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100555static int snd_ice1712_capture_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 int cmd)
557{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100558 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 int result = 0;
560 u8 tmp;
561
562 spin_lock(&ice->reg_lock);
563 tmp = snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL);
564 if (cmd == SNDRV_PCM_TRIGGER_START) {
565 tmp |= 1;
566 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
567 tmp &= ~1;
568 } else {
569 result = -EINVAL;
570 }
571 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
572 spin_unlock(&ice->reg_lock);
573 return result;
574}
575
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100576static int snd_ice1712_playback_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100578 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
579 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 u32 period_size, buf_size, rate, tmp;
581
582 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
583 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
584 tmp = 0x0000;
585 if (snd_pcm_format_width(runtime->format) == 16)
586 tmp |= 0x10;
587 if (runtime->channels == 2)
588 tmp |= 0x08;
589 rate = (runtime->rate * 8192) / 375;
590 if (rate > 0x000fffff)
591 rate = 0x000fffff;
592 spin_lock_irq(&ice->reg_lock);
593 outb(0, ice->ddma_port + 15);
594 outb(ICE1712_DMA_MODE_WRITE | ICE1712_DMA_AUTOINIT, ice->ddma_port + 0x0b);
595 outl(runtime->dma_addr, ice->ddma_port + 0);
596 outw(buf_size, ice->ddma_port + 4);
597 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_LO, rate & 0xff);
598 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_MID, (rate >> 8) & 0xff);
599 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_HI, (rate >> 16) & 0xff);
600 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
601 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_LO, period_size & 0xff);
602 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_HI, period_size >> 8);
603 snd_ice1712_write(ice, ICE1712_IREG_PBK_LEFT, 0);
604 snd_ice1712_write(ice, ICE1712_IREG_PBK_RIGHT, 0);
605 spin_unlock_irq(&ice->reg_lock);
606 return 0;
607}
608
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100609static int snd_ice1712_playback_ds_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100611 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
612 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 u32 period_size, buf_size, rate, tmp, chn;
614
615 period_size = snd_pcm_lib_period_bytes(substream) - 1;
616 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
617 tmp = 0x0064;
618 if (snd_pcm_format_width(runtime->format) == 16)
619 tmp &= ~0x04;
620 if (runtime->channels == 2)
621 tmp |= 0x08;
622 rate = (runtime->rate * 8192) / 375;
623 if (rate > 0x000fffff)
624 rate = 0x000fffff;
625 ice->playback_con_active_buf[substream->number] = 0;
626 ice->playback_con_virt_addr[substream->number] = runtime->dma_addr;
627 chn = substream->number * 2;
628 spin_lock_irq(&ice->reg_lock);
629 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR0, runtime->dma_addr);
630 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT0, period_size);
631 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR1, runtime->dma_addr + (runtime->periods > 1 ? period_size + 1 : 0));
632 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT1, period_size);
633 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_RATE, rate);
634 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_VOLUME, 0);
635 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_CONTROL, tmp);
636 if (runtime->channels == 2) {
637 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_RATE, rate);
638 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_VOLUME, 0);
639 }
640 spin_unlock_irq(&ice->reg_lock);
641 return 0;
642}
643
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100644static int snd_ice1712_capture_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100646 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
647 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 u32 period_size, buf_size;
649 u8 tmp;
650
651 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
652 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
653 tmp = 0x06;
654 if (snd_pcm_format_width(runtime->format) == 16)
655 tmp &= ~0x04;
656 if (runtime->channels == 2)
657 tmp &= ~0x02;
658 spin_lock_irq(&ice->reg_lock);
659 outl(ice->capture_con_virt_addr = runtime->dma_addr, ICEREG(ice, CONCAP_ADDR));
660 outw(buf_size, ICEREG(ice, CONCAP_COUNT));
661 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_HI, period_size >> 8);
662 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_LO, period_size & 0xff);
663 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
664 spin_unlock_irq(&ice->reg_lock);
665 snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
666 return 0;
667}
668
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100669static snd_pcm_uframes_t snd_ice1712_playback_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100671 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
672 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 size_t ptr;
674
675 if (!(snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL) & 1))
676 return 0;
677 ptr = runtime->buffer_size - inw(ice->ddma_port + 4);
678 if (ptr == runtime->buffer_size)
679 ptr = 0;
680 return bytes_to_frames(substream->runtime, ptr);
681}
682
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100683static snd_pcm_uframes_t snd_ice1712_playback_ds_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100685 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 u8 addr;
687 size_t ptr;
688
689 if (!(snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL) & 1))
690 return 0;
691 if (ice->playback_con_active_buf[substream->number])
692 addr = ICE1712_DSC_ADDR1;
693 else
694 addr = ICE1712_DSC_ADDR0;
695 ptr = snd_ice1712_ds_read(ice, substream->number * 2, addr) -
696 ice->playback_con_virt_addr[substream->number];
697 if (ptr == substream->runtime->buffer_size)
698 ptr = 0;
699 return bytes_to_frames(substream->runtime, ptr);
700}
701
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100702static snd_pcm_uframes_t snd_ice1712_capture_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100704 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 size_t ptr;
706
707 if (!(snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL) & 1))
708 return 0;
709 ptr = inl(ICEREG(ice, CONCAP_ADDR)) - ice->capture_con_virt_addr;
710 if (ptr == substream->runtime->buffer_size)
711 ptr = 0;
712 return bytes_to_frames(substream->runtime, ptr);
713}
714
Takashi Iwai32b47da2007-01-29 15:26:36 +0100715static const struct snd_pcm_hardware snd_ice1712_playback =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716{
717 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
718 SNDRV_PCM_INFO_BLOCK_TRANSFER |
719 SNDRV_PCM_INFO_MMAP_VALID |
720 SNDRV_PCM_INFO_PAUSE),
721 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
722 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
723 .rate_min = 4000,
724 .rate_max = 48000,
725 .channels_min = 1,
726 .channels_max = 2,
727 .buffer_bytes_max = (64*1024),
728 .period_bytes_min = 64,
729 .period_bytes_max = (64*1024),
730 .periods_min = 1,
731 .periods_max = 1024,
732 .fifo_size = 0,
733};
734
Takashi Iwai32b47da2007-01-29 15:26:36 +0100735static const struct snd_pcm_hardware snd_ice1712_playback_ds =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736{
737 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
738 SNDRV_PCM_INFO_BLOCK_TRANSFER |
739 SNDRV_PCM_INFO_MMAP_VALID |
740 SNDRV_PCM_INFO_PAUSE),
741 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
742 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
743 .rate_min = 4000,
744 .rate_max = 48000,
745 .channels_min = 1,
746 .channels_max = 2,
747 .buffer_bytes_max = (128*1024),
748 .period_bytes_min = 64,
749 .period_bytes_max = (128*1024),
750 .periods_min = 2,
751 .periods_max = 2,
752 .fifo_size = 0,
753};
754
Takashi Iwai32b47da2007-01-29 15:26:36 +0100755static const struct snd_pcm_hardware snd_ice1712_capture =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756{
757 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
758 SNDRV_PCM_INFO_BLOCK_TRANSFER |
759 SNDRV_PCM_INFO_MMAP_VALID),
760 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
761 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
762 .rate_min = 4000,
763 .rate_max = 48000,
764 .channels_min = 1,
765 .channels_max = 2,
766 .buffer_bytes_max = (64*1024),
767 .period_bytes_min = 64,
768 .period_bytes_max = (64*1024),
769 .periods_min = 1,
770 .periods_max = 1024,
771 .fifo_size = 0,
772};
773
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100774static int snd_ice1712_playback_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100776 struct snd_pcm_runtime *runtime = substream->runtime;
777 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779 ice->playback_con_substream = substream;
780 runtime->hw = snd_ice1712_playback;
781 return 0;
782}
783
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100784static int snd_ice1712_playback_ds_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100786 struct snd_pcm_runtime *runtime = substream->runtime;
787 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 u32 tmp;
789
790 ice->playback_con_substream_ds[substream->number] = substream;
791 runtime->hw = snd_ice1712_playback_ds;
792 spin_lock_irq(&ice->reg_lock);
793 tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2));
794 outw(tmp, ICEDS(ice, INTMASK));
795 spin_unlock_irq(&ice->reg_lock);
796 return 0;
797}
798
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100799static int snd_ice1712_capture_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100801 struct snd_pcm_runtime *runtime = substream->runtime;
802 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
804 ice->capture_con_substream = substream;
805 runtime->hw = snd_ice1712_capture;
806 runtime->hw.rates = ice->ac97->rates[AC97_RATES_ADC];
807 if (!(runtime->hw.rates & SNDRV_PCM_RATE_8000))
808 runtime->hw.rate_min = 48000;
809 return 0;
810}
811
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100812static int snd_ice1712_playback_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100814 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
816 ice->playback_con_substream = NULL;
817 return 0;
818}
819
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100820static int snd_ice1712_playback_ds_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100822 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 u32 tmp;
824
825 spin_lock_irq(&ice->reg_lock);
826 tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2));
827 outw(tmp, ICEDS(ice, INTMASK));
828 spin_unlock_irq(&ice->reg_lock);
829 ice->playback_con_substream_ds[substream->number] = NULL;
830 return 0;
831}
832
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100833static int snd_ice1712_capture_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100835 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
837 ice->capture_con_substream = NULL;
838 return 0;
839}
840
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100841static struct snd_pcm_ops snd_ice1712_playback_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 .open = snd_ice1712_playback_open,
843 .close = snd_ice1712_playback_close,
844 .ioctl = snd_pcm_lib_ioctl,
845 .hw_params = snd_ice1712_hw_params,
846 .hw_free = snd_ice1712_hw_free,
847 .prepare = snd_ice1712_playback_prepare,
848 .trigger = snd_ice1712_playback_trigger,
849 .pointer = snd_ice1712_playback_pointer,
850};
851
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100852static struct snd_pcm_ops snd_ice1712_playback_ds_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 .open = snd_ice1712_playback_ds_open,
854 .close = snd_ice1712_playback_ds_close,
855 .ioctl = snd_pcm_lib_ioctl,
856 .hw_params = snd_ice1712_hw_params,
857 .hw_free = snd_ice1712_hw_free,
858 .prepare = snd_ice1712_playback_ds_prepare,
859 .trigger = snd_ice1712_playback_ds_trigger,
860 .pointer = snd_ice1712_playback_ds_pointer,
861};
862
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100863static struct snd_pcm_ops snd_ice1712_capture_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 .open = snd_ice1712_capture_open,
865 .close = snd_ice1712_capture_close,
866 .ioctl = snd_pcm_lib_ioctl,
867 .hw_params = snd_ice1712_hw_params,
868 .hw_free = snd_ice1712_hw_free,
869 .prepare = snd_ice1712_capture_prepare,
870 .trigger = snd_ice1712_capture_trigger,
871 .pointer = snd_ice1712_capture_pointer,
872};
873
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100874static int __devinit snd_ice1712_pcm(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100876 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 int err;
878
879 if (rpcm)
880 *rpcm = NULL;
881 err = snd_pcm_new(ice->card, "ICE1712 consumer", device, 1, 1, &pcm);
882 if (err < 0)
883 return err;
884
885 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ops);
886 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_ops);
887
888 pcm->private_data = ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 pcm->info_flags = 0;
890 strcpy(pcm->name, "ICE1712 consumer");
891 ice->pcm = pcm;
892
893 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
894 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
895
896 if (rpcm)
897 *rpcm = pcm;
898
899 printk(KERN_WARNING "Consumer PCM code does not work well at the moment --jk\n");
900
901 return 0;
902}
903
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100904static int __devinit snd_ice1712_pcm_ds(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100906 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 int err;
908
909 if (rpcm)
910 *rpcm = NULL;
911 err = snd_pcm_new(ice->card, "ICE1712 consumer (DS)", device, 6, 0, &pcm);
912 if (err < 0)
913 return err;
914
915 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ds_ops);
916
917 pcm->private_data = ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 pcm->info_flags = 0;
919 strcpy(pcm->name, "ICE1712 consumer (DS)");
920 ice->pcm_ds = pcm;
921
922 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
923 snd_dma_pci_data(ice->pci), 64*1024, 128*1024);
924
925 if (rpcm)
926 *rpcm = pcm;
927
928 return 0;
929}
930
931/*
932 * PCM code - professional part (multitrack)
933 */
934
935static unsigned int rates[] = { 8000, 9600, 11025, 12000, 16000, 22050, 24000,
936 32000, 44100, 48000, 64000, 88200, 96000 };
937
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100938static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 .count = ARRAY_SIZE(rates),
940 .list = rates,
941 .mask = 0,
942};
943
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100944static int snd_ice1712_pro_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 int cmd)
946{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100947 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 switch (cmd) {
949 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
950 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
951 {
952 unsigned int what;
953 unsigned int old;
954 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
955 return -EINVAL;
956 what = ICE1712_PLAYBACK_PAUSE;
957 snd_pcm_trigger_done(substream, substream);
958 spin_lock(&ice->reg_lock);
959 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
960 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
961 old |= what;
962 else
963 old &= ~what;
964 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
965 spin_unlock(&ice->reg_lock);
966 break;
967 }
968 case SNDRV_PCM_TRIGGER_START:
969 case SNDRV_PCM_TRIGGER_STOP:
970 {
971 unsigned int what = 0;
972 unsigned int old;
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100973 struct snd_pcm_substream *s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Takashi Iwaief991b92007-02-22 12:52:53 +0100975 snd_pcm_group_for_each_entry(s, substream) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 if (s == ice->playback_pro_substream) {
977 what |= ICE1712_PLAYBACK_START;
978 snd_pcm_trigger_done(s, substream);
979 } else if (s == ice->capture_pro_substream) {
980 what |= ICE1712_CAPTURE_START_SHADOW;
981 snd_pcm_trigger_done(s, substream);
982 }
983 }
984 spin_lock(&ice->reg_lock);
985 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
986 if (cmd == SNDRV_PCM_TRIGGER_START)
987 old |= what;
988 else
989 old &= ~what;
990 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
991 spin_unlock(&ice->reg_lock);
992 break;
993 }
994 default:
995 return -EINVAL;
996 }
997 return 0;
998}
999
1000/*
1001 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001002static void snd_ice1712_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate, int force)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003{
1004 unsigned long flags;
1005 unsigned char val, old;
1006 unsigned int i;
1007
1008 switch (rate) {
1009 case 8000: val = 6; break;
1010 case 9600: val = 3; break;
1011 case 11025: val = 10; break;
1012 case 12000: val = 2; break;
1013 case 16000: val = 5; break;
1014 case 22050: val = 9; break;
1015 case 24000: val = 1; break;
1016 case 32000: val = 4; break;
1017 case 44100: val = 8; break;
1018 case 48000: val = 0; break;
1019 case 64000: val = 15; break;
1020 case 88200: val = 11; break;
1021 case 96000: val = 7; break;
1022 default:
1023 snd_BUG();
1024 val = 0;
1025 rate = 48000;
1026 break;
1027 }
1028
1029 spin_lock_irqsave(&ice->reg_lock, flags);
1030 if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
1031 ICE1712_PLAYBACK_PAUSE|
1032 ICE1712_PLAYBACK_START)) {
1033 __out:
1034 spin_unlock_irqrestore(&ice->reg_lock, flags);
1035 return;
1036 }
1037 if (!force && is_pro_rate_locked(ice))
1038 goto __out;
1039
1040 old = inb(ICEMT(ice, RATE));
1041 if (!force && old == val)
1042 goto __out;
1043 outb(val, ICEMT(ice, RATE));
1044 spin_unlock_irqrestore(&ice->reg_lock, flags);
1045
1046 if (ice->gpio.set_pro_rate)
1047 ice->gpio.set_pro_rate(ice, rate);
1048 for (i = 0; i < ice->akm_codecs; i++) {
1049 if (ice->akm[i].ops.set_rate_val)
1050 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
1051 }
1052 if (ice->spdif.ops.setup_rate)
1053 ice->spdif.ops.setup_rate(ice, rate);
1054}
1055
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001056static int snd_ice1712_playback_pro_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001058 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
1060 ice->playback_pro_size = snd_pcm_lib_buffer_bytes(substream);
1061 spin_lock_irq(&ice->reg_lock);
1062 outl(substream->runtime->dma_addr, ICEMT(ice, PLAYBACK_ADDR));
1063 outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));
1064 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT));
1065 spin_unlock_irq(&ice->reg_lock);
1066
1067 return 0;
1068}
1069
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001070static int snd_ice1712_playback_pro_hw_params(struct snd_pcm_substream *substream,
1071 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001073 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
1075 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1076 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1077}
1078
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001079static int snd_ice1712_capture_pro_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001081 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
1083 ice->capture_pro_size = snd_pcm_lib_buffer_bytes(substream);
1084 spin_lock_irq(&ice->reg_lock);
1085 outl(substream->runtime->dma_addr, ICEMT(ice, CAPTURE_ADDR));
1086 outw((ice->capture_pro_size >> 2) - 1, ICEMT(ice, CAPTURE_SIZE));
1087 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, CAPTURE_COUNT));
1088 spin_unlock_irq(&ice->reg_lock);
1089 return 0;
1090}
1091
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001092static int snd_ice1712_capture_pro_hw_params(struct snd_pcm_substream *substream,
1093 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001095 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1098 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1099}
1100
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001101static snd_pcm_uframes_t snd_ice1712_playback_pro_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001103 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 size_t ptr;
1105
1106 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_PLAYBACK_START))
1107 return 0;
1108 ptr = ice->playback_pro_size - (inw(ICEMT(ice, PLAYBACK_SIZE)) << 2);
1109 if (ptr == substream->runtime->buffer_size)
1110 ptr = 0;
1111 return bytes_to_frames(substream->runtime, ptr);
1112}
1113
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001114static snd_pcm_uframes_t snd_ice1712_capture_pro_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001116 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 size_t ptr;
1118
1119 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_CAPTURE_START_SHADOW))
1120 return 0;
1121 ptr = ice->capture_pro_size - (inw(ICEMT(ice, CAPTURE_SIZE)) << 2);
1122 if (ptr == substream->runtime->buffer_size)
1123 ptr = 0;
1124 return bytes_to_frames(substream->runtime, ptr);
1125}
1126
Takashi Iwai32b47da2007-01-29 15:26:36 +01001127static const struct snd_pcm_hardware snd_ice1712_playback_pro =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128{
1129 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1130 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1131 SNDRV_PCM_INFO_MMAP_VALID |
1132 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1133 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1134 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1135 .rate_min = 4000,
1136 .rate_max = 96000,
1137 .channels_min = 10,
1138 .channels_max = 10,
1139 .buffer_bytes_max = (256*1024),
1140 .period_bytes_min = 10 * 4 * 2,
1141 .period_bytes_max = 131040,
1142 .periods_min = 1,
1143 .periods_max = 1024,
1144 .fifo_size = 0,
1145};
1146
Takashi Iwai32b47da2007-01-29 15:26:36 +01001147static const struct snd_pcm_hardware snd_ice1712_capture_pro =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148{
1149 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1150 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1151 SNDRV_PCM_INFO_MMAP_VALID |
1152 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1153 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1154 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1155 .rate_min = 4000,
1156 .rate_max = 96000,
1157 .channels_min = 12,
1158 .channels_max = 12,
1159 .buffer_bytes_max = (256*1024),
1160 .period_bytes_min = 12 * 4 * 2,
1161 .period_bytes_max = 131040,
1162 .periods_min = 1,
1163 .periods_max = 1024,
1164 .fifo_size = 0,
1165};
1166
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001167static int snd_ice1712_playback_pro_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001169 struct snd_pcm_runtime *runtime = substream->runtime;
1170 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
1172 ice->playback_pro_substream = substream;
1173 runtime->hw = snd_ice1712_playback_pro;
1174 snd_pcm_set_sync(substream);
1175 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1176 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1177
1178 if (ice->spdif.ops.open)
1179 ice->spdif.ops.open(ice, substream);
1180
1181 return 0;
1182}
1183
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001184static int snd_ice1712_capture_pro_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001186 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1187 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
1189 ice->capture_pro_substream = substream;
1190 runtime->hw = snd_ice1712_capture_pro;
1191 snd_pcm_set_sync(substream);
1192 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1193 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1194 return 0;
1195}
1196
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001197static int snd_ice1712_playback_pro_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001199 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
1201 if (PRO_RATE_RESET)
1202 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1203 ice->playback_pro_substream = NULL;
1204 if (ice->spdif.ops.close)
1205 ice->spdif.ops.close(ice, substream);
1206
1207 return 0;
1208}
1209
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001210static int snd_ice1712_capture_pro_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001212 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
1214 if (PRO_RATE_RESET)
1215 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1216 ice->capture_pro_substream = NULL;
1217 return 0;
1218}
1219
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001220static struct snd_pcm_ops snd_ice1712_playback_pro_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 .open = snd_ice1712_playback_pro_open,
1222 .close = snd_ice1712_playback_pro_close,
1223 .ioctl = snd_pcm_lib_ioctl,
1224 .hw_params = snd_ice1712_playback_pro_hw_params,
1225 .hw_free = snd_ice1712_hw_free,
1226 .prepare = snd_ice1712_playback_pro_prepare,
1227 .trigger = snd_ice1712_pro_trigger,
1228 .pointer = snd_ice1712_playback_pro_pointer,
1229};
1230
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001231static struct snd_pcm_ops snd_ice1712_capture_pro_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 .open = snd_ice1712_capture_pro_open,
1233 .close = snd_ice1712_capture_pro_close,
1234 .ioctl = snd_pcm_lib_ioctl,
1235 .hw_params = snd_ice1712_capture_pro_hw_params,
1236 .hw_free = snd_ice1712_hw_free,
1237 .prepare = snd_ice1712_capture_pro_prepare,
1238 .trigger = snd_ice1712_pro_trigger,
1239 .pointer = snd_ice1712_capture_pro_pointer,
1240};
1241
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001242static int __devinit snd_ice1712_pcm_profi(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001244 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 int err;
1246
1247 if (rpcm)
1248 *rpcm = NULL;
1249 err = snd_pcm_new(ice->card, "ICE1712 multi", device, 1, 1, &pcm);
1250 if (err < 0)
1251 return err;
1252
1253 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_pro_ops);
1254 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_pro_ops);
1255
1256 pcm->private_data = ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 pcm->info_flags = 0;
1258 strcpy(pcm->name, "ICE1712 multi");
1259
1260 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1261 snd_dma_pci_data(ice->pci), 256*1024, 256*1024);
1262
1263 ice->pcm_pro = pcm;
1264 if (rpcm)
1265 *rpcm = pcm;
1266
1267 if (ice->cs8427) {
1268 /* assign channels to iec958 */
1269 err = snd_cs8427_iec958_build(ice->cs8427,
1270 pcm->streams[0].substream,
1271 pcm->streams[1].substream);
1272 if (err < 0)
1273 return err;
1274 }
1275
1276 if ((err = snd_ice1712_build_pro_mixer(ice)) < 0)
1277 return err;
1278 return 0;
1279}
1280
1281/*
1282 * Mixer section
1283 */
1284
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001285static void snd_ice1712_update_volume(struct snd_ice1712 *ice, int index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286{
1287 unsigned int vol = ice->pro_volumes[index];
1288 unsigned short val = 0;
1289
1290 val |= (vol & 0x8000) == 0 ? (96 - (vol & 0x7f)) : 0x7f;
1291 val |= ((vol & 0x80000000) == 0 ? (96 - ((vol >> 16) & 0x7f)) : 0x7f) << 8;
1292 outb(index, ICEMT(ice, MONITOR_INDEX));
1293 outw(val, ICEMT(ice, MONITOR_VOLUME));
1294}
1295
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001296#define snd_ice1712_pro_mixer_switch_info snd_ctl_boolean_stereo_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001298static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001300 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1302
1303 spin_lock_irq(&ice->reg_lock);
1304 ucontrol->value.integer.value[0] = !((ice->pro_volumes[index] >> 15) & 1);
1305 ucontrol->value.integer.value[1] = !((ice->pro_volumes[index] >> 31) & 1);
1306 spin_unlock_irq(&ice->reg_lock);
1307 return 0;
1308}
1309
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001310static int snd_ice1712_pro_mixer_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001312 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1314 unsigned int nval, change;
1315
1316 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
1317 (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
1318 spin_lock_irq(&ice->reg_lock);
1319 nval |= ice->pro_volumes[index] & ~0x80008000;
1320 change = nval != ice->pro_volumes[index];
1321 ice->pro_volumes[index] = nval;
1322 snd_ice1712_update_volume(ice, index);
1323 spin_unlock_irq(&ice->reg_lock);
1324 return change;
1325}
1326
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001327static int snd_ice1712_pro_mixer_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328{
1329 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1330 uinfo->count = 2;
1331 uinfo->value.integer.min = 0;
1332 uinfo->value.integer.max = 96;
1333 return 0;
1334}
1335
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001336static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001338 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1340
1341 spin_lock_irq(&ice->reg_lock);
1342 ucontrol->value.integer.value[0] = (ice->pro_volumes[index] >> 0) & 127;
1343 ucontrol->value.integer.value[1] = (ice->pro_volumes[index] >> 16) & 127;
1344 spin_unlock_irq(&ice->reg_lock);
1345 return 0;
1346}
1347
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001348static int snd_ice1712_pro_mixer_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001350 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
1352 unsigned int nval, change;
1353
1354 nval = (ucontrol->value.integer.value[0] & 127) |
1355 ((ucontrol->value.integer.value[1] & 127) << 16);
1356 spin_lock_irq(&ice->reg_lock);
1357 nval |= ice->pro_volumes[index] & ~0x007f007f;
1358 change = nval != ice->pro_volumes[index];
1359 ice->pro_volumes[index] = nval;
1360 snd_ice1712_update_volume(ice, index);
1361 spin_unlock_irq(&ice->reg_lock);
1362 return change;
1363}
1364
Takashi Iwai0cb29ea2007-01-29 15:33:49 +01001365static const DECLARE_TLV_DB_SCALE(db_scale_playback, -14400, 150, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001367static struct snd_kcontrol_new snd_ice1712_multi_playback_ctrls[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 {
1369 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1370 .name = "Multi Playback Switch",
1371 .info = snd_ice1712_pro_mixer_switch_info,
1372 .get = snd_ice1712_pro_mixer_switch_get,
1373 .put = snd_ice1712_pro_mixer_switch_put,
1374 .private_value = 0,
1375 .count = 10,
1376 },
1377 {
1378 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai680ef792006-08-30 16:56:30 +02001379 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1380 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 .name = "Multi Playback Volume",
1382 .info = snd_ice1712_pro_mixer_volume_info,
1383 .get = snd_ice1712_pro_mixer_volume_get,
1384 .put = snd_ice1712_pro_mixer_volume_put,
1385 .private_value = 0,
1386 .count = 10,
Takashi Iwai680ef792006-08-30 16:56:30 +02001387 .tlv = { .p = db_scale_playback }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 },
1389};
1390
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001391static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_switch __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1393 .name = "H/W Multi Capture Switch",
1394 .info = snd_ice1712_pro_mixer_switch_info,
1395 .get = snd_ice1712_pro_mixer_switch_get,
1396 .put = snd_ice1712_pro_mixer_switch_put,
1397 .private_value = 10,
1398};
1399
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001400static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_switch __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Clemens Ladisch10e8d782005-08-03 13:40:08 +02001402 .name = SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE,SWITCH),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 .info = snd_ice1712_pro_mixer_switch_info,
1404 .get = snd_ice1712_pro_mixer_switch_get,
1405 .put = snd_ice1712_pro_mixer_switch_put,
1406 .private_value = 18,
1407 .count = 2,
1408};
1409
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001410static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_volume __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai680ef792006-08-30 16:56:30 +02001412 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1413 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 .name = "H/W Multi Capture Volume",
1415 .info = snd_ice1712_pro_mixer_volume_info,
1416 .get = snd_ice1712_pro_mixer_volume_get,
1417 .put = snd_ice1712_pro_mixer_volume_put,
1418 .private_value = 10,
Takashi Iwai680ef792006-08-30 16:56:30 +02001419 .tlv = { .p = db_scale_playback }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420};
1421
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001422static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_volume __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Clemens Ladisch10e8d782005-08-03 13:40:08 +02001424 .name = SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE,VOLUME),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 .info = snd_ice1712_pro_mixer_volume_info,
1426 .get = snd_ice1712_pro_mixer_volume_get,
1427 .put = snd_ice1712_pro_mixer_volume_put,
1428 .private_value = 18,
1429 .count = 2,
1430};
1431
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001432static int __devinit snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001434 struct snd_card *card = ice->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 unsigned int idx;
1436 int err;
1437
1438 /* multi-channel mixer */
1439 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_multi_playback_ctrls); idx++) {
1440 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_playback_ctrls[idx], ice));
1441 if (err < 0)
1442 return err;
1443 }
1444
1445 if (ice->num_total_adcs > 0) {
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001446 struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_switch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 tmp.count = ice->num_total_adcs;
1448 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1449 if (err < 0)
1450 return err;
1451 }
1452
1453 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_switch, ice));
1454 if (err < 0)
1455 return err;
1456
1457 if (ice->num_total_adcs > 0) {
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001458 struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_volume;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 tmp.count = ice->num_total_adcs;
1460 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1461 if (err < 0)
1462 return err;
1463 }
1464
1465 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_volume, ice));
1466 if (err < 0)
1467 return err;
1468
1469 /* initialize volumes */
1470 for (idx = 0; idx < 10; idx++) {
1471 ice->pro_volumes[idx] = 0x80008000; /* mute */
1472 snd_ice1712_update_volume(ice, idx);
1473 }
1474 for (idx = 10; idx < 10 + ice->num_total_adcs; idx++) {
1475 ice->pro_volumes[idx] = 0x80008000; /* mute */
1476 snd_ice1712_update_volume(ice, idx);
1477 }
1478 for (idx = 18; idx < 20; idx++) {
1479 ice->pro_volumes[idx] = 0x80008000; /* mute */
1480 snd_ice1712_update_volume(ice, idx);
1481 }
1482 return 0;
1483}
1484
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001485static void snd_ice1712_mixer_free_ac97(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001487 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 ice->ac97 = NULL;
1489}
1490
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001491static int __devinit snd_ice1712_ac97_mixer(struct snd_ice1712 * ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492{
1493 int err, bus_num = 0;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001494 struct snd_ac97_template ac97;
1495 struct snd_ac97_bus *pbus;
1496 static struct snd_ac97_bus_ops con_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 .write = snd_ice1712_ac97_write,
1498 .read = snd_ice1712_ac97_read,
1499 };
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001500 static struct snd_ac97_bus_ops pro_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 .write = snd_ice1712_pro_ac97_write,
1502 .read = snd_ice1712_pro_ac97_read,
1503 };
1504
1505 if (ice_has_con_ac97(ice)) {
1506 if ((err = snd_ac97_bus(ice->card, bus_num++, &con_ops, NULL, &pbus)) < 0)
1507 return err;
1508 memset(&ac97, 0, sizeof(ac97));
1509 ac97.private_data = ice;
1510 ac97.private_free = snd_ice1712_mixer_free_ac97;
1511 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1512 printk(KERN_WARNING "ice1712: cannot initialize ac97 for consumer, skipped\n");
1513 else {
1514 if ((err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice))) < 0)
1515 return err;
1516 return 0;
1517 }
1518 }
1519
1520 if (! (ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) {
1521 if ((err = snd_ac97_bus(ice->card, bus_num, &pro_ops, NULL, &pbus)) < 0)
1522 return err;
1523 memset(&ac97, 0, sizeof(ac97));
1524 ac97.private_data = ice;
1525 ac97.private_free = snd_ice1712_mixer_free_ac97;
1526 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1527 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1528 else
1529 return 0;
1530 }
1531 /* I2S mixer only */
1532 strcat(ice->card->mixername, "ICE1712 - multitrack");
1533 return 0;
1534}
1535
1536/*
1537 *
1538 */
1539
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001540static inline unsigned int eeprom_double(struct snd_ice1712 *ice, int idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541{
1542 return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8);
1543}
1544
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001545static void snd_ice1712_proc_read(struct snd_info_entry *entry,
1546 struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001548 struct snd_ice1712 *ice = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 unsigned int idx;
1550
1551 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1552 snd_iprintf(buffer, "EEPROM:\n");
1553
1554 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1555 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1556 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1557 snd_iprintf(buffer, " Codec : 0x%x\n", ice->eeprom.data[ICE_EEP1_CODEC]);
1558 snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP1_ACLINK]);
1559 snd_iprintf(buffer, " I2S ID : 0x%x\n", ice->eeprom.data[ICE_EEP1_I2SID]);
1560 snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP1_SPDIF]);
1561 snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
1562 snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
1563 snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
1564 snd_iprintf(buffer, " AC'97 main : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_MAIN_LO));
1565 snd_iprintf(buffer, " AC'97 pcm : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_PCM_LO));
1566 snd_iprintf(buffer, " AC'97 record : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_REC_LO));
1567 snd_iprintf(buffer, " AC'97 record src : 0x%x\n", ice->eeprom.data[ICE_EEP1_AC97_RECSRC]);
1568 for (idx = 0; idx < 4; idx++)
1569 snd_iprintf(buffer, " DAC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_DAC_ID + idx]);
1570 for (idx = 0; idx < 4; idx++)
1571 snd_iprintf(buffer, " ADC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_ADC_ID + idx]);
1572 for (idx = 0x1c; idx < ice->eeprom.size; idx++)
1573 snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
1574
1575 snd_iprintf(buffer, "\nRegisters:\n");
1576 snd_iprintf(buffer, " PSDOUT03 : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_PSDOUT03)));
1577 snd_iprintf(buffer, " CAPTURE : 0x%08x\n", inl(ICEMT(ice, ROUTE_CAPTURE)));
1578 snd_iprintf(buffer, " SPDOUT : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT)));
1579 snd_iprintf(buffer, " RATE : 0x%02x\n", (unsigned)inb(ICEMT(ice, RATE)));
Jaroslav Kyselaf7004f32006-02-10 08:42:17 +01001580 snd_iprintf(buffer, " GPIO_DATA : 0x%02x\n", (unsigned)snd_ice1712_get_gpio_data(ice));
1581 snd_iprintf(buffer, " GPIO_WRITE_MASK : 0x%02x\n", (unsigned)snd_ice1712_read(ice, ICE1712_IREG_GPIO_WRITE_MASK));
1582 snd_iprintf(buffer, " GPIO_DIRECTION : 0x%02x\n", (unsigned)snd_ice1712_read(ice, ICE1712_IREG_GPIO_DIRECTION));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583}
1584
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001585static void __devinit snd_ice1712_proc_init(struct snd_ice1712 * ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001587 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
1589 if (! snd_card_proc_new(ice->card, "ice1712", &entry))
Takashi Iwaibf850202006-04-28 15:13:41 +02001590 snd_info_set_text_ops(entry, ice, snd_ice1712_proc_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591}
1592
1593/*
1594 *
1595 */
1596
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001597static int snd_ice1712_eeprom_info(struct snd_kcontrol *kcontrol,
1598 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599{
1600 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001601 uinfo->count = sizeof(struct snd_ice1712_eeprom);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 return 0;
1603}
1604
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001605static int snd_ice1712_eeprom_get(struct snd_kcontrol *kcontrol,
1606 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001608 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
1610 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1611 return 0;
1612}
1613
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001614static struct snd_kcontrol_new snd_ice1712_eeprom __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1616 .name = "ICE1712 EEPROM",
1617 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1618 .info = snd_ice1712_eeprom_info,
1619 .get = snd_ice1712_eeprom_get
1620};
1621
1622/*
1623 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001624static int snd_ice1712_spdif_info(struct snd_kcontrol *kcontrol,
1625 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626{
1627 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1628 uinfo->count = 1;
1629 return 0;
1630}
1631
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001632static int snd_ice1712_spdif_default_get(struct snd_kcontrol *kcontrol,
1633 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001635 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 if (ice->spdif.ops.default_get)
1637 ice->spdif.ops.default_get(ice, ucontrol);
1638 return 0;
1639}
1640
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001641static int snd_ice1712_spdif_default_put(struct snd_kcontrol *kcontrol,
1642 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001644 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 if (ice->spdif.ops.default_put)
1646 return ice->spdif.ops.default_put(ice, ucontrol);
1647 return 0;
1648}
1649
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001650static struct snd_kcontrol_new snd_ice1712_spdif_default __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651{
1652 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1653 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1654 .info = snd_ice1712_spdif_info,
1655 .get = snd_ice1712_spdif_default_get,
1656 .put = snd_ice1712_spdif_default_put
1657};
1658
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001659static int snd_ice1712_spdif_maskc_get(struct snd_kcontrol *kcontrol,
1660 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001662 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 if (ice->spdif.ops.default_get) {
1664 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1665 IEC958_AES0_PROFESSIONAL |
1666 IEC958_AES0_CON_NOT_COPYRIGHT |
1667 IEC958_AES0_CON_EMPHASIS;
1668 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1669 IEC958_AES1_CON_CATEGORY;
1670 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1671 } else {
1672 ucontrol->value.iec958.status[0] = 0xff;
1673 ucontrol->value.iec958.status[1] = 0xff;
1674 ucontrol->value.iec958.status[2] = 0xff;
1675 ucontrol->value.iec958.status[3] = 0xff;
1676 ucontrol->value.iec958.status[4] = 0xff;
1677 }
1678 return 0;
1679}
1680
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001681static int snd_ice1712_spdif_maskp_get(struct snd_kcontrol *kcontrol,
1682 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001684 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 if (ice->spdif.ops.default_get) {
1686 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1687 IEC958_AES0_PROFESSIONAL |
1688 IEC958_AES0_PRO_FS |
1689 IEC958_AES0_PRO_EMPHASIS;
1690 ucontrol->value.iec958.status[1] = IEC958_AES1_PRO_MODE;
1691 } else {
1692 ucontrol->value.iec958.status[0] = 0xff;
1693 ucontrol->value.iec958.status[1] = 0xff;
1694 ucontrol->value.iec958.status[2] = 0xff;
1695 ucontrol->value.iec958.status[3] = 0xff;
1696 ucontrol->value.iec958.status[4] = 0xff;
1697 }
1698 return 0;
1699}
1700
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001701static struct snd_kcontrol_new snd_ice1712_spdif_maskc __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702{
1703 .access = SNDRV_CTL_ELEM_ACCESS_READ,
Clemens Ladisch67ed4162005-07-29 15:32:58 +02001704 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1706 .info = snd_ice1712_spdif_info,
1707 .get = snd_ice1712_spdif_maskc_get,
1708};
1709
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001710static struct snd_kcontrol_new snd_ice1712_spdif_maskp __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711{
1712 .access = SNDRV_CTL_ELEM_ACCESS_READ,
Clemens Ladisch67ed4162005-07-29 15:32:58 +02001713 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1715 .info = snd_ice1712_spdif_info,
1716 .get = snd_ice1712_spdif_maskp_get,
1717};
1718
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001719static int snd_ice1712_spdif_stream_get(struct snd_kcontrol *kcontrol,
1720 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001722 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 if (ice->spdif.ops.stream_get)
1724 ice->spdif.ops.stream_get(ice, ucontrol);
1725 return 0;
1726}
1727
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001728static int snd_ice1712_spdif_stream_put(struct snd_kcontrol *kcontrol,
1729 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001731 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 if (ice->spdif.ops.stream_put)
1733 return ice->spdif.ops.stream_put(ice, ucontrol);
1734 return 0;
1735}
1736
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001737static struct snd_kcontrol_new snd_ice1712_spdif_stream __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001739 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1740 SNDRV_CTL_ELEM_ACCESS_INACTIVE),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1742 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
1743 .info = snd_ice1712_spdif_info,
1744 .get = snd_ice1712_spdif_stream_get,
1745 .put = snd_ice1712_spdif_stream_put
1746};
1747
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001748#define snd_ice1712_gpio_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001750int snd_ice1712_gpio_get(struct snd_kcontrol *kcontrol,
1751 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001753 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 unsigned char mask = kcontrol->private_value & 0xff;
1755 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1756
1757 snd_ice1712_save_gpio_status(ice);
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001758 ucontrol->value.integer.value[0] =
1759 (snd_ice1712_gpio_read(ice) & mask ? 1 : 0) ^ invert;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 snd_ice1712_restore_gpio_status(ice);
1761 return 0;
1762}
1763
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001764int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
1765 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001767 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 unsigned char mask = kcontrol->private_value & 0xff;
1769 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1770 unsigned int val, nval;
1771
1772 if (kcontrol->private_value & (1 << 31))
1773 return -EPERM;
1774 nval = (ucontrol->value.integer.value[0] ? mask : 0) ^ invert;
1775 snd_ice1712_save_gpio_status(ice);
1776 val = snd_ice1712_gpio_read(ice);
1777 nval |= val & ~mask;
1778 if (val != nval)
1779 snd_ice1712_gpio_write(ice, nval);
1780 snd_ice1712_restore_gpio_status(ice);
1781 return val != nval;
1782}
1783
1784/*
1785 * rate
1786 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001787static int snd_ice1712_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1788 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789{
Takashi Iwai32b47da2007-01-29 15:26:36 +01001790 static const char * const texts[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 "8000", /* 0: 6 */
1792 "9600", /* 1: 3 */
1793 "11025", /* 2: 10 */
1794 "12000", /* 3: 2 */
1795 "16000", /* 4: 5 */
1796 "22050", /* 5: 9 */
1797 "24000", /* 6: 1 */
1798 "32000", /* 7: 4 */
1799 "44100", /* 8: 8 */
1800 "48000", /* 9: 0 */
1801 "64000", /* 10: 15 */
1802 "88200", /* 11: 11 */
1803 "96000", /* 12: 7 */
1804 "IEC958 Input", /* 13: -- */
1805 };
1806 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1807 uinfo->count = 1;
1808 uinfo->value.enumerated.items = 14;
1809 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1810 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1811 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1812 return 0;
1813}
1814
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001815static int snd_ice1712_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1816 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001818 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai32b47da2007-01-29 15:26:36 +01001819 static const unsigned char xlate[16] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10
1821 };
1822 unsigned char val;
1823
1824 spin_lock_irq(&ice->reg_lock);
1825 if (is_spdif_master(ice)) {
1826 ucontrol->value.enumerated.item[0] = 13;
1827 } else {
1828 val = xlate[inb(ICEMT(ice, RATE)) & 15];
1829 if (val == 255) {
1830 snd_BUG();
1831 val = 0;
1832 }
1833 ucontrol->value.enumerated.item[0] = val;
1834 }
1835 spin_unlock_irq(&ice->reg_lock);
1836 return 0;
1837}
1838
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001839static int snd_ice1712_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1840 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001842 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai32b47da2007-01-29 15:26:36 +01001843 static const unsigned int xrate[13] = {
Jaroslav Kyselafe25bef2006-08-15 14:39:07 +02001844 8000, 9600, 11025, 12000, 16000, 22050, 24000,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 32000, 44100, 48000, 64000, 88200, 96000
1846 };
1847 unsigned char oval;
1848 int change = 0;
1849
1850 spin_lock_irq(&ice->reg_lock);
1851 oval = inb(ICEMT(ice, RATE));
1852 if (ucontrol->value.enumerated.item[0] == 13) {
1853 outb(oval | ICE1712_SPDIF_MASTER, ICEMT(ice, RATE));
1854 } else {
1855 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1856 spin_unlock_irq(&ice->reg_lock);
1857 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1858 spin_lock_irq(&ice->reg_lock);
1859 }
1860 change = inb(ICEMT(ice, RATE)) != oval;
1861 spin_unlock_irq(&ice->reg_lock);
1862
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001863 if ((oval & ICE1712_SPDIF_MASTER) !=
Jaroslav Kyselae957ebf2006-02-02 07:56:54 +01001864 (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER))
1865 snd_ice1712_set_input_clock_source(ice, is_spdif_master(ice));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866
1867 return change;
1868}
1869
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001870static struct snd_kcontrol_new snd_ice1712_pro_internal_clock __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1872 .name = "Multi Track Internal Clock",
1873 .info = snd_ice1712_pro_internal_clock_info,
1874 .get = snd_ice1712_pro_internal_clock_get,
1875 .put = snd_ice1712_pro_internal_clock_put
1876};
1877
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001878static int snd_ice1712_pro_internal_clock_default_info(struct snd_kcontrol *kcontrol,
1879 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880{
Takashi Iwai32b47da2007-01-29 15:26:36 +01001881 static const char * const texts[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 "8000", /* 0: 6 */
1883 "9600", /* 1: 3 */
1884 "11025", /* 2: 10 */
1885 "12000", /* 3: 2 */
1886 "16000", /* 4: 5 */
1887 "22050", /* 5: 9 */
1888 "24000", /* 6: 1 */
1889 "32000", /* 7: 4 */
1890 "44100", /* 8: 8 */
1891 "48000", /* 9: 0 */
1892 "64000", /* 10: 15 */
1893 "88200", /* 11: 11 */
1894 "96000", /* 12: 7 */
1895 // "IEC958 Input", /* 13: -- */
1896 };
1897 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1898 uinfo->count = 1;
1899 uinfo->value.enumerated.items = 13;
1900 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1901 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1902 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1903 return 0;
1904}
1905
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001906static int snd_ice1712_pro_internal_clock_default_get(struct snd_kcontrol *kcontrol,
1907 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908{
1909 int val;
Takashi Iwai32b47da2007-01-29 15:26:36 +01001910 static const unsigned int xrate[13] = {
Jaroslav Kyselafe25bef2006-08-15 14:39:07 +02001911 8000, 9600, 11025, 12000, 16000, 22050, 24000,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 32000, 44100, 48000, 64000, 88200, 96000
1913 };
1914
1915 for (val = 0; val < 13; val++) {
1916 if (xrate[val] == PRO_RATE_DEFAULT)
1917 break;
1918 }
1919
1920 ucontrol->value.enumerated.item[0] = val;
1921 return 0;
1922}
1923
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001924static int snd_ice1712_pro_internal_clock_default_put(struct snd_kcontrol *kcontrol,
1925 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926{
Takashi Iwai32b47da2007-01-29 15:26:36 +01001927 static const unsigned int xrate[13] = {
Jaroslav Kyselafe25bef2006-08-15 14:39:07 +02001928 8000, 9600, 11025, 12000, 16000, 22050, 24000,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 32000, 44100, 48000, 64000, 88200, 96000
1930 };
1931 unsigned char oval;
1932 int change = 0;
1933
1934 oval = PRO_RATE_DEFAULT;
1935 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1936 change = PRO_RATE_DEFAULT != oval;
1937
1938 return change;
1939}
1940
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001941static struct snd_kcontrol_new snd_ice1712_pro_internal_clock_default __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1943 .name = "Multi Track Internal Clock Default",
1944 .info = snd_ice1712_pro_internal_clock_default_info,
1945 .get = snd_ice1712_pro_internal_clock_default_get,
1946 .put = snd_ice1712_pro_internal_clock_default_put
1947};
1948
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001949#define snd_ice1712_pro_rate_locking_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001951static int snd_ice1712_pro_rate_locking_get(struct snd_kcontrol *kcontrol,
1952 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953{
1954 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1955 return 0;
1956}
1957
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001958static int snd_ice1712_pro_rate_locking_put(struct snd_kcontrol *kcontrol,
1959 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001961 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 int change = 0, nval;
1963
1964 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1965 spin_lock_irq(&ice->reg_lock);
1966 change = PRO_RATE_LOCKED != nval;
1967 PRO_RATE_LOCKED = nval;
1968 spin_unlock_irq(&ice->reg_lock);
1969 return change;
1970}
1971
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001972static struct snd_kcontrol_new snd_ice1712_pro_rate_locking __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1974 .name = "Multi Track Rate Locking",
1975 .info = snd_ice1712_pro_rate_locking_info,
1976 .get = snd_ice1712_pro_rate_locking_get,
1977 .put = snd_ice1712_pro_rate_locking_put
1978};
1979
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001980#define snd_ice1712_pro_rate_reset_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001982static int snd_ice1712_pro_rate_reset_get(struct snd_kcontrol *kcontrol,
1983 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984{
1985 ucontrol->value.integer.value[0] = PRO_RATE_RESET;
1986 return 0;
1987}
1988
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001989static int snd_ice1712_pro_rate_reset_put(struct snd_kcontrol *kcontrol,
1990 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001992 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 int change = 0, nval;
1994
1995 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1996 spin_lock_irq(&ice->reg_lock);
1997 change = PRO_RATE_RESET != nval;
1998 PRO_RATE_RESET = nval;
1999 spin_unlock_irq(&ice->reg_lock);
2000 return change;
2001}
2002
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002003static struct snd_kcontrol_new snd_ice1712_pro_rate_reset __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2005 .name = "Multi Track Rate Reset",
2006 .info = snd_ice1712_pro_rate_reset_info,
2007 .get = snd_ice1712_pro_rate_reset_get,
2008 .put = snd_ice1712_pro_rate_reset_put
2009};
2010
2011/*
2012 * routing
2013 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002014static int snd_ice1712_pro_route_info(struct snd_kcontrol *kcontrol,
2015 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016{
Takashi Iwai32b47da2007-01-29 15:26:36 +01002017 static const char * const texts[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 "PCM Out", /* 0 */
2019 "H/W In 0", "H/W In 1", "H/W In 2", "H/W In 3", /* 1-4 */
2020 "H/W In 4", "H/W In 5", "H/W In 6", "H/W In 7", /* 5-8 */
2021 "IEC958 In L", "IEC958 In R", /* 9-10 */
2022 "Digital Mixer", /* 11 - optional */
2023 };
2024
2025 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2026 uinfo->count = 1;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002027 uinfo->value.enumerated.items =
2028 snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2030 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2031 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2032 return 0;
2033}
2034
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002035static int snd_ice1712_pro_route_analog_get(struct snd_kcontrol *kcontrol,
2036 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002038 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2040 unsigned int val, cval;
2041
2042 spin_lock_irq(&ice->reg_lock);
2043 val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2044 cval = inl(ICEMT(ice, ROUTE_CAPTURE));
2045 spin_unlock_irq(&ice->reg_lock);
2046
2047 val >>= ((idx % 2) * 8) + ((idx / 2) * 2);
2048 val &= 3;
2049 cval >>= ((idx / 2) * 8) + ((idx % 2) * 4);
2050 if (val == 1 && idx < 2)
2051 ucontrol->value.enumerated.item[0] = 11;
2052 else if (val == 2)
2053 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2054 else if (val == 3)
2055 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2056 else
2057 ucontrol->value.enumerated.item[0] = 0;
2058 return 0;
2059}
2060
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002061static int snd_ice1712_pro_route_analog_put(struct snd_kcontrol *kcontrol,
2062 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002064 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 int change, shift;
2066 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2067 unsigned int val, old_val, nval;
2068
2069 /* update PSDOUT */
2070 if (ucontrol->value.enumerated.item[0] >= 11)
2071 nval = idx < 2 ? 1 : 0; /* dig mixer (or pcm) */
2072 else if (ucontrol->value.enumerated.item[0] >= 9)
2073 nval = 3; /* spdif in */
2074 else if (ucontrol->value.enumerated.item[0] >= 1)
2075 nval = 2; /* analog in */
2076 else
2077 nval = 0; /* pcm */
2078 shift = ((idx % 2) * 8) + ((idx / 2) * 2);
2079 spin_lock_irq(&ice->reg_lock);
2080 val = old_val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2081 val &= ~(0x03 << shift);
2082 val |= nval << shift;
2083 change = val != old_val;
2084 if (change)
2085 outw(val, ICEMT(ice, ROUTE_PSDOUT03));
2086 spin_unlock_irq(&ice->reg_lock);
2087 if (nval < 2) /* dig mixer of pcm */
2088 return change;
2089
2090 /* update CAPTURE */
2091 spin_lock_irq(&ice->reg_lock);
2092 val = old_val = inl(ICEMT(ice, ROUTE_CAPTURE));
2093 shift = ((idx / 2) * 8) + ((idx % 2) * 4);
2094 if (nval == 2) { /* analog in */
2095 nval = ucontrol->value.enumerated.item[0] - 1;
2096 val &= ~(0x07 << shift);
2097 val |= nval << shift;
2098 } else { /* spdif in */
2099 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2100 val &= ~(0x08 << shift);
2101 val |= nval << shift;
2102 }
2103 if (val != old_val) {
2104 change = 1;
2105 outl(val, ICEMT(ice, ROUTE_CAPTURE));
2106 }
2107 spin_unlock_irq(&ice->reg_lock);
2108 return change;
2109}
2110
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002111static int snd_ice1712_pro_route_spdif_get(struct snd_kcontrol *kcontrol,
2112 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002114 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2116 unsigned int val, cval;
2117 val = inw(ICEMT(ice, ROUTE_SPDOUT));
2118 cval = (val >> (idx * 4 + 8)) & 0x0f;
2119 val = (val >> (idx * 2)) & 0x03;
2120 if (val == 1)
2121 ucontrol->value.enumerated.item[0] = 11;
2122 else if (val == 2)
2123 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2124 else if (val == 3)
2125 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2126 else
2127 ucontrol->value.enumerated.item[0] = 0;
2128 return 0;
2129}
2130
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002131static int snd_ice1712_pro_route_spdif_put(struct snd_kcontrol *kcontrol,
2132 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002134 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 int change, shift;
2136 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2137 unsigned int val, old_val, nval;
2138
2139 /* update SPDOUT */
2140 spin_lock_irq(&ice->reg_lock);
2141 val = old_val = inw(ICEMT(ice, ROUTE_SPDOUT));
2142 if (ucontrol->value.enumerated.item[0] >= 11)
2143 nval = 1;
2144 else if (ucontrol->value.enumerated.item[0] >= 9)
2145 nval = 3;
2146 else if (ucontrol->value.enumerated.item[0] >= 1)
2147 nval = 2;
2148 else
2149 nval = 0;
2150 shift = idx * 2;
2151 val &= ~(0x03 << shift);
2152 val |= nval << shift;
2153 shift = idx * 4 + 8;
2154 if (nval == 2) {
2155 nval = ucontrol->value.enumerated.item[0] - 1;
2156 val &= ~(0x07 << shift);
2157 val |= nval << shift;
2158 } else if (nval == 3) {
2159 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2160 val &= ~(0x08 << shift);
2161 val |= nval << shift;
2162 }
2163 change = val != old_val;
2164 if (change)
2165 outw(val, ICEMT(ice, ROUTE_SPDOUT));
2166 spin_unlock_irq(&ice->reg_lock);
2167 return change;
2168}
2169
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002170static struct snd_kcontrol_new snd_ice1712_mixer_pro_analog_route __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2172 .name = "H/W Playback Route",
2173 .info = snd_ice1712_pro_route_info,
2174 .get = snd_ice1712_pro_route_analog_get,
2175 .put = snd_ice1712_pro_route_analog_put,
2176};
2177
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002178static struct snd_kcontrol_new snd_ice1712_mixer_pro_spdif_route __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002180 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 .info = snd_ice1712_pro_route_info,
2182 .get = snd_ice1712_pro_route_spdif_get,
2183 .put = snd_ice1712_pro_route_spdif_put,
2184 .count = 2,
2185};
2186
2187
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002188static int snd_ice1712_pro_volume_rate_info(struct snd_kcontrol *kcontrol,
2189 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190{
2191 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2192 uinfo->count = 1;
2193 uinfo->value.integer.min = 0;
2194 uinfo->value.integer.max = 255;
2195 return 0;
2196}
2197
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002198static int snd_ice1712_pro_volume_rate_get(struct snd_kcontrol *kcontrol,
2199 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002201 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
2203 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE));
2204 return 0;
2205}
2206
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002207static int snd_ice1712_pro_volume_rate_put(struct snd_kcontrol *kcontrol,
2208 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002210 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 int change;
2212
2213 spin_lock_irq(&ice->reg_lock);
2214 change = inb(ICEMT(ice, MONITOR_RATE)) != ucontrol->value.integer.value[0];
2215 outb(ucontrol->value.integer.value[0], ICEMT(ice, MONITOR_RATE));
2216 spin_unlock_irq(&ice->reg_lock);
2217 return change;
2218}
2219
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002220static struct snd_kcontrol_new snd_ice1712_mixer_pro_volume_rate __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2222 .name = "Multi Track Volume Rate",
2223 .info = snd_ice1712_pro_volume_rate_info,
2224 .get = snd_ice1712_pro_volume_rate_get,
2225 .put = snd_ice1712_pro_volume_rate_put
2226};
2227
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002228static int snd_ice1712_pro_peak_info(struct snd_kcontrol *kcontrol,
2229 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230{
2231 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2232 uinfo->count = 22;
2233 uinfo->value.integer.min = 0;
2234 uinfo->value.integer.max = 255;
2235 return 0;
2236}
2237
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002238static int snd_ice1712_pro_peak_get(struct snd_kcontrol *kcontrol,
2239 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002241 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 int idx;
2243
2244 spin_lock_irq(&ice->reg_lock);
2245 for (idx = 0; idx < 22; idx++) {
2246 outb(idx, ICEMT(ice, MONITOR_PEAKINDEX));
2247 ucontrol->value.integer.value[idx] = inb(ICEMT(ice, MONITOR_PEAKDATA));
2248 }
2249 spin_unlock_irq(&ice->reg_lock);
2250 return 0;
2251}
2252
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002253static struct snd_kcontrol_new snd_ice1712_mixer_pro_peak __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2255 .name = "Multi Track Peak",
2256 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2257 .info = snd_ice1712_pro_peak_info,
2258 .get = snd_ice1712_pro_peak_get
2259};
2260
2261/*
2262 *
2263 */
2264
2265/*
2266 * list of available boards
2267 */
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002268static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 snd_ice1712_hoontech_cards,
2270 snd_ice1712_delta_cards,
2271 snd_ice1712_ews_cards,
2272 NULL,
2273};
2274
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002275static unsigned char __devinit snd_ice1712_read_i2c(struct snd_ice1712 *ice,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 unsigned char dev,
2277 unsigned char addr)
2278{
2279 long t = 0x10000;
2280
2281 outb(addr, ICEREG(ice, I2C_BYTE_ADDR));
2282 outb(dev & ~ICE1712_I2C_WRITE, ICEREG(ice, I2C_DEV_ADDR));
2283 while (t-- > 0 && (inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_BUSY)) ;
2284 return inb(ICEREG(ice, I2C_DATA));
2285}
2286
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002287static int __devinit snd_ice1712_read_eeprom(struct snd_ice1712 *ice,
2288 const char *modelname)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289{
2290 int dev = 0xa0; /* EEPROM device address */
2291 unsigned int i, size;
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002292 struct snd_ice1712_card_info * const *tbl, *c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293
2294 if (! modelname || ! *modelname) {
2295 ice->eeprom.subvendor = 0;
2296 if ((inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_EEPROM) != 0)
2297 ice->eeprom.subvendor = (snd_ice1712_read_i2c(ice, dev, 0x00) << 0) |
2298 (snd_ice1712_read_i2c(ice, dev, 0x01) << 8) |
2299 (snd_ice1712_read_i2c(ice, dev, 0x02) << 16) |
2300 (snd_ice1712_read_i2c(ice, dev, 0x03) << 24);
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002301 if (ice->eeprom.subvendor == 0 ||
2302 ice->eeprom.subvendor == (unsigned int)-1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 /* invalid subvendor from EEPROM, try the PCI subststem ID instead */
2304 u16 vendor, device;
2305 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID, &vendor);
2306 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
2307 ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device);
2308 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
2309 printk(KERN_ERR "ice1712: No valid ID is found\n");
2310 return -ENXIO;
2311 }
2312 }
2313 }
2314 for (tbl = card_tables; *tbl; tbl++) {
2315 for (c = *tbl; c->subvendor; c++) {
2316 if (modelname && c->model && ! strcmp(modelname, c->model)) {
2317 printk(KERN_INFO "ice1712: Using board model %s\n", c->name);
2318 ice->eeprom.subvendor = c->subvendor;
2319 } else if (c->subvendor != ice->eeprom.subvendor)
2320 continue;
2321 if (! c->eeprom_size || ! c->eeprom_data)
2322 goto found;
2323 /* if the EEPROM is given by the driver, use it */
2324 snd_printdd("using the defined eeprom..\n");
2325 ice->eeprom.version = 1;
2326 ice->eeprom.size = c->eeprom_size + 6;
2327 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
2328 goto read_skipped;
2329 }
2330 }
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002331 printk(KERN_WARNING "ice1712: No matching model found for ID 0x%x\n",
2332 ice->eeprom.subvendor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
2334 found:
2335 ice->eeprom.size = snd_ice1712_read_i2c(ice, dev, 0x04);
2336 if (ice->eeprom.size < 6)
2337 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */
2338 else if (ice->eeprom.size > 32) {
Takashi Iwai99b359b2005-10-20 18:26:44 +02002339 snd_printk(KERN_ERR "invalid EEPROM (size = %i)\n", ice->eeprom.size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 return -EIO;
2341 }
2342 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05);
2343 if (ice->eeprom.version != 1) {
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002344 snd_printk(KERN_ERR "invalid EEPROM version %i\n",
2345 ice->eeprom.version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 /* return -EIO; */
2347 }
2348 size = ice->eeprom.size - 6;
2349 for (i = 0; i < size; i++)
2350 ice->eeprom.data[i] = snd_ice1712_read_i2c(ice, dev, i + 6);
2351
2352 read_skipped:
2353 ice->eeprom.gpiomask = ice->eeprom.data[ICE_EEP1_GPIO_MASK];
2354 ice->eeprom.gpiostate = ice->eeprom.data[ICE_EEP1_GPIO_STATE];
2355 ice->eeprom.gpiodir = ice->eeprom.data[ICE_EEP1_GPIO_DIR];
2356
2357 return 0;
2358}
2359
2360
2361
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002362static int __devinit snd_ice1712_chip_init(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363{
2364 outb(ICE1712_RESET | ICE1712_NATIVE, ICEREG(ice, CONTROL));
2365 udelay(200);
2366 outb(ICE1712_NATIVE, ICEREG(ice, CONTROL));
2367 udelay(200);
Alan Horstmann721b8a22006-05-23 13:29:51 +02002368 if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DMX6FIRE &&
2369 !ice->dxr_enable)
2370 /* Set eeprom value to limit active ADCs and DACs to 6;
2371 * Also disable AC97 as no hardware in standard 6fire card/box
2372 * Note: DXR extensions are not currently supported
2373 */
2374 ice->eeprom.data[ICE_EEP1_CODEC] = 0x3a;
2375 pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 pci_write_config_byte(ice->pci, 0x61, ice->eeprom.data[ICE_EEP1_ACLINK]);
2377 pci_write_config_byte(ice->pci, 0x62, ice->eeprom.data[ICE_EEP1_I2SID]);
2378 pci_write_config_byte(ice->pci, 0x63, ice->eeprom.data[ICE_EEP1_SPDIF]);
2379 if (ice->eeprom.subvendor != ICE1712_SUBDEVICE_STDSP24) {
2380 ice->gpio.write_mask = ice->eeprom.gpiomask;
2381 ice->gpio.direction = ice->eeprom.gpiodir;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002382 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK,
2383 ice->eeprom.gpiomask);
2384 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
2385 ice->eeprom.gpiodir);
2386 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA,
2387 ice->eeprom.gpiostate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 } else {
2389 ice->gpio.write_mask = 0xc0;
2390 ice->gpio.direction = 0xff;
2391 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, 0xc0);
2392 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, 0xff);
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002393 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA,
2394 ICE1712_STDSP24_CLOCK_BIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 }
2396 snd_ice1712_write(ice, ICE1712_IREG_PRO_POWERDOWN, 0);
2397 if (!(ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97)) {
2398 outb(ICE1712_AC97_WARM, ICEREG(ice, AC97_CMD));
2399 udelay(100);
2400 outb(0, ICEREG(ice, AC97_CMD));
2401 udelay(200);
2402 snd_ice1712_write(ice, ICE1712_IREG_CONSUMER_POWERDOWN, 0);
2403 }
2404 snd_ice1712_set_pro_rate(ice, 48000, 1);
2405
2406 return 0;
2407}
2408
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002409int __devinit snd_ice1712_spdif_build_controls(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410{
2411 int err;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002412 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413
2414 snd_assert(ice->pcm_pro != NULL, return -EIO);
2415 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_default, ice));
2416 if (err < 0)
2417 return err;
2418 kctl->id.device = ice->pcm_pro->device;
2419 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskc, ice));
2420 if (err < 0)
2421 return err;
2422 kctl->id.device = ice->pcm_pro->device;
2423 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskp, ice));
2424 if (err < 0)
2425 return err;
2426 kctl->id.device = ice->pcm_pro->device;
2427 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_stream, ice));
2428 if (err < 0)
2429 return err;
2430 kctl->id.device = ice->pcm_pro->device;
2431 ice->spdif.stream_ctl = kctl;
2432 return 0;
2433}
2434
2435
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002436static int __devinit snd_ice1712_build_controls(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437{
2438 int err;
2439
2440 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_eeprom, ice));
2441 if (err < 0)
2442 return err;
2443 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock, ice));
2444 if (err < 0)
2445 return err;
2446 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock_default, ice));
2447 if (err < 0)
2448 return err;
2449
2450 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_locking, ice));
2451 if (err < 0)
2452 return err;
2453 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_reset, ice));
2454 if (err < 0)
2455 return err;
2456
2457 if (ice->num_total_dacs > 0) {
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002458 struct snd_kcontrol_new tmp = snd_ice1712_mixer_pro_analog_route;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 tmp.count = ice->num_total_dacs;
2460 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2461 if (err < 0)
2462 return err;
2463 }
2464
2465 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice));
2466 if (err < 0)
2467 return err;
2468
2469 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
2470 if (err < 0)
2471 return err;
2472 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice));
2473 if (err < 0)
2474 return err;
2475
2476 return 0;
2477}
2478
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002479static int snd_ice1712_free(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480{
2481 if (! ice->port)
2482 goto __hw_end;
2483 /* mask all interrupts */
2484 outb(0xc0, ICEMT(ice, IRQ));
2485 outb(0xff, ICEREG(ice, IRQMASK));
2486 /* --- */
2487 __hw_end:
2488 if (ice->irq >= 0) {
2489 synchronize_irq(ice->irq);
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002490 free_irq(ice->irq, ice);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 }
2492 if (ice->port)
2493 pci_release_regions(ice->pci);
2494 snd_ice1712_akm4xxx_free(ice);
2495 pci_disable_device(ice->pci);
2496 kfree(ice);
2497 return 0;
2498}
2499
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002500static int snd_ice1712_dev_free(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002502 struct snd_ice1712 *ice = device->device_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 return snd_ice1712_free(ice);
2504}
2505
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002506static int __devinit snd_ice1712_create(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 struct pci_dev *pci,
2508 const char *modelname,
2509 int omni,
2510 int cs8427_timeout,
Alan Horstmann531af462006-02-08 07:40:33 +01002511 int dxr_enable,
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002512 struct snd_ice1712 ** r_ice1712)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002514 struct snd_ice1712 *ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 int err;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002516 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 .dev_free = snd_ice1712_dev_free,
2518 };
2519
2520 *r_ice1712 = NULL;
2521
2522 /* enable PCI device */
2523 if ((err = pci_enable_device(pci)) < 0)
2524 return err;
2525 /* check, if we can restrict PCI DMA transfers to 28 bits */
Tobias Klauser9d2f9282006-03-22 10:53:19 +01002526 if (pci_set_dma_mask(pci, DMA_28BIT_MASK) < 0 ||
2527 pci_set_consistent_dma_mask(pci, DMA_28BIT_MASK) < 0) {
Takashi Iwai99b359b2005-10-20 18:26:44 +02002528 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 pci_disable_device(pci);
2530 return -ENXIO;
2531 }
2532
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002533 ice = kzalloc(sizeof(*ice), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 if (ice == NULL) {
2535 pci_disable_device(pci);
2536 return -ENOMEM;
2537 }
2538 ice->omni = omni ? 1 : 0;
2539 if (cs8427_timeout < 1)
2540 cs8427_timeout = 1;
2541 else if (cs8427_timeout > 1000)
2542 cs8427_timeout = 1000;
2543 ice->cs8427_timeout = cs8427_timeout;
Alan Horstmann531af462006-02-08 07:40:33 +01002544 ice->dxr_enable = dxr_enable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 spin_lock_init(&ice->reg_lock);
Ingo Molnar62932df2006-01-16 16:34:20 +01002546 mutex_init(&ice->gpio_mutex);
2547 mutex_init(&ice->i2c_mutex);
2548 mutex_init(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 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;
2553
2554 ice->spdif.cs8403_bits =
2555 ice->spdif.cs8403_stream_bits = (0x01 | /* consumer format */
2556 0x10 | /* no emphasis */
2557 0x20); /* PCM encoder/decoder */
2558 ice->card = card;
2559 ice->pci = pci;
2560 ice->irq = -1;
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);
2566
2567 if ((err = pci_request_regions(pci, "ICE1712")) < 0) {
2568 kfree(ice);
2569 pci_disable_device(pci);
2570 return err;
2571 }
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);
2576
Takashi Iwai437a5a42006-11-21 12:14:23 +01002577 if (request_irq(pci->irq, snd_ice1712_interrupt, IRQF_SHARED,
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002578 "ICE1712", ice)) {
Takashi Iwai99b359b2005-10-20 18:26:44 +02002579 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 snd_ice1712_free(ice);
2581 return -EIO;
2582 }
2583
2584 ice->irq = pci->irq;
2585
2586 if (snd_ice1712_read_eeprom(ice, modelname) < 0) {
2587 snd_ice1712_free(ice);
2588 return -EIO;
2589 }
2590 if (snd_ice1712_chip_init(ice) < 0) {
2591 snd_ice1712_free(ice);
2592 return -EIO;
2593 }
2594
2595 /* unmask used interrupts */
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002596 outb(((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) == 0 ?
2597 ICE1712_IRQ_MPU2 : 0) |
2598 ((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97) ?
2599 ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 ICEREG(ice, IRQMASK));
2601 outb(0x00, ICEMT(ice, IRQ));
2602
2603 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2604 snd_ice1712_free(ice);
2605 return err;
2606 }
2607
2608 snd_card_set_dev(card, &pci->dev);
2609
2610 *r_ice1712 = ice;
2611 return 0;
2612}
2613
2614
2615/*
2616 *
2617 * Registration
2618 *
2619 */
2620
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002621static struct snd_ice1712_card_info no_matched __devinitdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622
2623static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2624 const struct pci_device_id *pci_id)
2625{
2626 static int dev;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002627 struct snd_card *card;
2628 struct snd_ice1712 *ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 int pcm_dev = 0, err;
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002630 struct snd_ice1712_card_info * const *tbl, *c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631
2632 if (dev >= SNDRV_CARDS)
2633 return -ENODEV;
2634 if (!enable[dev]) {
2635 dev++;
2636 return -ENOENT;
2637 }
2638
2639 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2640 if (card == NULL)
2641 return -ENOMEM;
2642
2643 strcpy(card->driver, "ICE1712");
2644 strcpy(card->shortname, "ICEnsemble ICE1712");
2645
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002646 if ((err = snd_ice1712_create(card, pci, model[dev], omni[dev],
Alan Horstmann531af462006-02-08 07:40:33 +01002647 cs8427_timeout[dev], dxr_enable[dev],
2648 &ice)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 snd_card_free(card);
2650 return err;
2651 }
2652
2653 for (tbl = card_tables; *tbl; tbl++) {
2654 for (c = *tbl; c->subvendor; c++) {
2655 if (c->subvendor == ice->eeprom.subvendor) {
2656 strcpy(card->shortname, c->name);
2657 if (c->driver) /* specific driver? */
2658 strcpy(card->driver, c->driver);
2659 if (c->chip_init) {
2660 if ((err = c->chip_init(ice)) < 0) {
2661 snd_card_free(card);
2662 return err;
2663 }
2664 }
2665 goto __found;
2666 }
2667 }
2668 }
2669 c = &no_matched;
2670 __found:
2671
2672 if ((err = snd_ice1712_pcm_profi(ice, pcm_dev++, NULL)) < 0) {
2673 snd_card_free(card);
2674 return err;
2675 }
2676
2677 if (ice_has_con_ac97(ice))
2678 if ((err = snd_ice1712_pcm(ice, pcm_dev++, NULL)) < 0) {
2679 snd_card_free(card);
2680 return err;
2681 }
2682
2683 if ((err = snd_ice1712_ac97_mixer(ice)) < 0) {
2684 snd_card_free(card);
2685 return err;
2686 }
2687
2688 if ((err = snd_ice1712_build_controls(ice)) < 0) {
2689 snd_card_free(card);
2690 return err;
2691 }
2692
2693 if (c->build_controls) {
2694 if ((err = c->build_controls(ice)) < 0) {
2695 snd_card_free(card);
2696 return err;
2697 }
2698 }
2699
2700 if (ice_has_con_ac97(ice))
2701 if ((err = snd_ice1712_pcm_ds(ice, pcm_dev++, NULL)) < 0) {
2702 snd_card_free(card);
2703 return err;
2704 }
2705
2706 if (! c->no_mpu401) {
2707 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
Takashi Iwai302e4c22006-05-23 13:24:30 +02002708 ICEREG(ice, MPU1_CTRL),
Alan Horstmanncf78ee22006-05-26 17:19:34 +02002709 (c->mpu401_1_info_flags |
2710 MPU401_INFO_INTEGRATED),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 ice->irq, 0,
2712 &ice->rmidi[0])) < 0) {
2713 snd_card_free(card);
2714 return err;
2715 }
Alan Horstmann3bef2292006-04-26 18:13:59 +02002716 if (c->mpu401_1_name)
2717 /* Prefered name available in card_info */
2718 snprintf(ice->rmidi[0]->name,
2719 sizeof(ice->rmidi[0]->name),
2720 "%s %d", c->mpu401_1_name, card->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721
Alan Horstmann3bef2292006-04-26 18:13:59 +02002722 if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) {
2723 /* 2nd port used */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 if ((err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712,
Takashi Iwai302e4c22006-05-23 13:24:30 +02002725 ICEREG(ice, MPU2_CTRL),
Alan Horstmanncf78ee22006-05-26 17:19:34 +02002726 (c->mpu401_2_info_flags |
2727 MPU401_INFO_INTEGRATED),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 ice->irq, 0,
2729 &ice->rmidi[1])) < 0) {
2730 snd_card_free(card);
2731 return err;
2732 }
Alan Horstmann3bef2292006-04-26 18:13:59 +02002733 if (c->mpu401_2_name)
2734 /* Prefered name available in card_info */
2735 snprintf(ice->rmidi[1]->name,
2736 sizeof(ice->rmidi[1]->name),
2737 "%s %d", c->mpu401_2_name,
2738 card->number);
2739 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 }
2741
Jaroslav Kyselae957ebf2006-02-02 07:56:54 +01002742 snd_ice1712_set_input_clock_source(ice, 0);
2743
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 sprintf(card->longname, "%s at 0x%lx, irq %i",
2745 card->shortname, ice->port, ice->irq);
2746
2747 if ((err = snd_card_register(card)) < 0) {
2748 snd_card_free(card);
2749 return err;
2750 }
2751 pci_set_drvdata(pci, card);
2752 dev++;
2753 return 0;
2754}
2755
2756static void __devexit snd_ice1712_remove(struct pci_dev *pci)
2757{
2758 snd_card_free(pci_get_drvdata(pci));
2759 pci_set_drvdata(pci, NULL);
2760}
2761
2762static struct pci_driver driver = {
2763 .name = "ICE1712",
2764 .id_table = snd_ice1712_ids,
2765 .probe = snd_ice1712_probe,
2766 .remove = __devexit_p(snd_ice1712_remove),
2767};
2768
2769static int __init alsa_card_ice1712_init(void)
2770{
Takashi Iwai01d25d42005-04-11 16:58:24 +02002771 return pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772}
2773
2774static void __exit alsa_card_ice1712_exit(void)
2775{
2776 pci_unregister_driver(&driver);
2777}
2778
2779module_init(alsa_card_ice1712_init)
2780module_exit(alsa_card_ice1712_exit)