blob: dcd3f4f89b445fedc44434a579251af44ec279ad [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ALSA driver for ICEnsemble ICE1712 (Envy24)
3 *
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02004 * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
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 *
Alexander Beregalov3d8cb462008-09-07 14:17:02 +040020 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
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)
Alexander Beregalov3d8cb462008-09-07 14:17:02 +040038 * I have left out support for 176.4 and 192 KHz for the moment.
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 * 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
Alexander Beregalov3d8cb462008-09-07 14:17:02 +040050#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/delay.h>
52#include <linux/interrupt.h>
53#include <linux/init.h>
54#include <linux/pci.h>
Tobias Klauser9d2f9282006-03-22 10:53:19 +010055#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#include <linux/slab.h>
57#include <linux/moduleparam.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010058#include <linux/mutex.h>
Matthias Gehre910638a2006-03-28 01:56:48 -080059
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include <sound/core.h>
61#include <sound/cs8427.h>
62#include <sound/info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#include <sound/initval.h>
Takashi Iwai680ef792006-08-30 16:56:30 +020064#include <sound/tlv.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66#include <sound/asoundef.h>
67
68#include "ice1712.h"
69
70/* lowlevel routines */
71#include "delta.h"
72#include "ews.h"
73#include "hoontech.h"
74
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020075MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070076MODULE_DESCRIPTION("ICEnsemble ICE1712 (Envy24)");
77MODULE_LICENSE("GPL");
78MODULE_SUPPORTED_DEVICE("{"
79 HOONTECH_DEVICE_DESC
80 DELTA_DEVICE_DESC
81 EWS_DEVICE_DESC
82 "{ICEnsemble,Generic ICE1712},"
83 "{ICEnsemble,Generic Envy24}}");
84
85static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
86static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
Alan Horstmann01a00e52006-03-21 09:57:36 +010087static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088static char *model[SNDRV_CARDS];
Alan Horstmann01a00e52006-03-21 09:57:36 +010089static int omni[SNDRV_CARDS]; /* Delta44 & 66 Omni I/O support */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090static 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 +010091static int dxr_enable[SNDRV_CARDS]; /* DXR enable for DMX6FIRE */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93module_param_array(index, int, NULL, 0444);
94MODULE_PARM_DESC(index, "Index value for ICE1712 soundcard.");
95module_param_array(id, charp, NULL, 0444);
96MODULE_PARM_DESC(id, "ID string for ICE1712 soundcard.");
97module_param_array(enable, bool, NULL, 0444);
98MODULE_PARM_DESC(enable, "Enable ICE1712 soundcard.");
99module_param_array(omni, bool, NULL, 0444);
100MODULE_PARM_DESC(omni, "Enable Midiman M-Audio Delta Omni I/O support.");
101module_param_array(cs8427_timeout, int, NULL, 0444);
102MODULE_PARM_DESC(cs8427_timeout, "Define reset timeout for cs8427 chip in msec resolution.");
103module_param_array(model, charp, NULL, 0444);
104MODULE_PARM_DESC(model, "Use the given board model.");
Alan Horstmann531af462006-02-08 07:40:33 +0100105module_param_array(dxr_enable, int, NULL, 0444);
Alan Horstmann01a00e52006-03-21 09:57:36 +0100106MODULE_PARM_DESC(dxr_enable, "Enable DXR support for Terratec DMX6FIRE.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Takashi Iwai32b47da2007-01-29 15:26:36 +0100109static const struct pci_device_id snd_ice1712_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_ICE_1712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* ICE1712 */
111 { 0, }
112};
113
114MODULE_DEVICE_TABLE(pci, snd_ice1712_ids);
115
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100116static int snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice);
117static int snd_ice1712_build_controls(struct snd_ice1712 *ice);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119static int PRO_RATE_LOCKED;
120static int PRO_RATE_RESET = 1;
121static unsigned int PRO_RATE_DEFAULT = 44100;
122
123/*
124 * Basic I/O
125 */
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127/* check whether the clock mode is spdif-in */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100128static inline int is_spdif_master(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
130 return (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER) ? 1 : 0;
131}
132
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100133static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
135 return is_spdif_master(ice) || PRO_RATE_LOCKED;
136}
137
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400138static inline void snd_ice1712_ds_write(struct snd_ice1712 *ice, u8 channel, u8 addr, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
140 outb((channel << 4) | addr, ICEDS(ice, INDEX));
141 outl(data, ICEDS(ice, DATA));
142}
143
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400144static inline u32 snd_ice1712_ds_read(struct snd_ice1712 *ice, u8 channel, u8 addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
146 outb((channel << 4) | addr, ICEDS(ice, INDEX));
147 return inl(ICEDS(ice, DATA));
148}
149
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100150static void snd_ice1712_ac97_write(struct snd_ac97 *ac97,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 unsigned short reg,
152 unsigned short val)
153{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100154 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 int tm;
156 unsigned char old_cmd = 0;
157
158 for (tm = 0; tm < 0x10000; tm++) {
159 old_cmd = inb(ICEREG(ice, AC97_CMD));
160 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
161 continue;
162 if (!(old_cmd & ICE1712_AC97_READY))
163 continue;
164 break;
165 }
166 outb(reg, ICEREG(ice, AC97_INDEX));
167 outw(val, ICEREG(ice, AC97_DATA));
168 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
169 outb(old_cmd | ICE1712_AC97_WRITE, ICEREG(ice, AC97_CMD));
170 for (tm = 0; tm < 0x10000; tm++)
171 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
172 break;
173}
174
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100175static unsigned short snd_ice1712_ac97_read(struct snd_ac97 *ac97,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 unsigned short reg)
177{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100178 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 int tm;
180 unsigned char old_cmd = 0;
181
182 for (tm = 0; tm < 0x10000; tm++) {
183 old_cmd = inb(ICEREG(ice, AC97_CMD));
184 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
185 continue;
186 if (!(old_cmd & ICE1712_AC97_READY))
187 continue;
188 break;
189 }
190 outb(reg, ICEREG(ice, AC97_INDEX));
191 outb(old_cmd | ICE1712_AC97_READ, ICEREG(ice, AC97_CMD));
192 for (tm = 0; tm < 0x10000; tm++)
193 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
194 break;
195 if (tm >= 0x10000) /* timeout */
196 return ~0;
197 return inw(ICEREG(ice, AC97_DATA));
198}
199
200/*
201 * pro ac97 section
202 */
203
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100204static void snd_ice1712_pro_ac97_write(struct snd_ac97 *ac97,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 unsigned short reg,
206 unsigned short val)
207{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100208 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 int tm;
210 unsigned char old_cmd = 0;
211
212 for (tm = 0; tm < 0x10000; tm++) {
213 old_cmd = inb(ICEMT(ice, AC97_CMD));
214 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
215 continue;
216 if (!(old_cmd & ICE1712_AC97_READY))
217 continue;
218 break;
219 }
220 outb(reg, ICEMT(ice, AC97_INDEX));
221 outw(val, ICEMT(ice, AC97_DATA));
222 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
223 outb(old_cmd | ICE1712_AC97_WRITE, ICEMT(ice, AC97_CMD));
224 for (tm = 0; tm < 0x10000; tm++)
225 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
226 break;
227}
228
229
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100230static unsigned short snd_ice1712_pro_ac97_read(struct snd_ac97 *ac97,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 unsigned short reg)
232{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100233 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 int tm;
235 unsigned char old_cmd = 0;
236
237 for (tm = 0; tm < 0x10000; tm++) {
238 old_cmd = inb(ICEMT(ice, AC97_CMD));
239 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
240 continue;
241 if (!(old_cmd & ICE1712_AC97_READY))
242 continue;
243 break;
244 }
245 outb(reg, ICEMT(ice, AC97_INDEX));
246 outb(old_cmd | ICE1712_AC97_READ, ICEMT(ice, AC97_CMD));
247 for (tm = 0; tm < 0x10000; tm++)
248 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
249 break;
250 if (tm >= 0x10000) /* timeout */
251 return ~0;
252 return inw(ICEMT(ice, AC97_DATA));
253}
254
255/*
256 * consumer ac97 digital mix
257 */
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200258#define snd_ice1712_digmix_route_ac97_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100260static int snd_ice1712_digmix_route_ac97_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100262 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0;
265 return 0;
266}
267
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100268static int snd_ice1712_digmix_route_ac97_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100270 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 unsigned char val, nval;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400272
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 spin_lock_irq(&ice->reg_lock);
274 val = inb(ICEMT(ice, MONITOR_ROUTECTRL));
275 nval = val & ~ICE1712_ROUTE_AC97;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400276 if (ucontrol->value.integer.value[0])
277 nval |= ICE1712_ROUTE_AC97;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 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;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 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
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400385 err = snd_cs8427_create(ice->i2c, addr,
386 (ice->cs8427_timeout * HZ) / 1000, &ice->cs8427);
387 if (err < 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{
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400399 /* change CS8427 clock source too */
400 if (ice->cs8427)
401 snd_ice1712_cs8427_set_input_clock(ice, spdif_is_master);
Jaroslav Kyselae957ebf2006-02-02 07:56:54 +0100402 /* 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));
Takashi Iwaie2ea7cfc2009-02-05 16:07:02 +0100461 /* printk(KERN_DEBUG "pbkstatus = 0x%x\n", pbkstatus); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 for (idx = 0; idx < 6; idx++) {
463 if ((pbkstatus & (3 << (idx * 2))) == 0)
464 continue;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400465 substream = ice->playback_con_substream_ds[idx];
466 if (substream != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 snd_pcm_period_elapsed(substream);
468 outw(3 << (idx * 2), ICEDS(ice, INTSTAT));
469 }
470 outb(ICE1712_IRQ_PBKDS, ICEREG(ice, IRQSTAT));
471 }
472 if (status & ICE1712_IRQ_CONCAP) {
473 if (ice->capture_con_substream)
474 snd_pcm_period_elapsed(ice->capture_con_substream);
475 outb(ICE1712_IRQ_CONCAP, ICEREG(ice, IRQSTAT));
476 }
477 if (status & ICE1712_IRQ_CONPBK) {
478 if (ice->playback_con_substream)
479 snd_pcm_period_elapsed(ice->playback_con_substream);
480 outb(ICE1712_IRQ_CONPBK, ICEREG(ice, IRQSTAT));
481 }
482 }
483 return IRQ_RETVAL(handled);
484}
485
486
487/*
488 * PCM part - misc
489 */
490
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100491static int snd_ice1712_hw_params(struct snd_pcm_substream *substream,
492 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
494 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
495}
496
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100497static int snd_ice1712_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
499 return snd_pcm_lib_free_pages(substream);
500}
501
502/*
503 * PCM part - consumer I/O
504 */
505
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100506static int snd_ice1712_playback_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 int cmd)
508{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100509 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 int result = 0;
511 u32 tmp;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400512
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 spin_lock(&ice->reg_lock);
514 tmp = snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL);
515 if (cmd == SNDRV_PCM_TRIGGER_START) {
516 tmp |= 1;
517 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
518 tmp &= ~1;
519 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
520 tmp |= 2;
521 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
522 tmp &= ~2;
523 } else {
524 result = -EINVAL;
525 }
526 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
527 spin_unlock(&ice->reg_lock);
528 return result;
529}
530
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100531static int snd_ice1712_playback_ds_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 int cmd)
533{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100534 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 int result = 0;
536 u32 tmp;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400537
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 spin_lock(&ice->reg_lock);
539 tmp = snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL);
540 if (cmd == SNDRV_PCM_TRIGGER_START) {
541 tmp |= 1;
542 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
543 tmp &= ~1;
544 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
545 tmp |= 2;
546 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
547 tmp &= ~2;
548 } else {
549 result = -EINVAL;
550 }
551 snd_ice1712_ds_write(ice, substream->number * 2, ICE1712_DSC_CONTROL, tmp);
552 spin_unlock(&ice->reg_lock);
553 return result;
554}
555
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100556static int snd_ice1712_capture_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 int cmd)
558{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100559 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 int result = 0;
561 u8 tmp;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 spin_lock(&ice->reg_lock);
564 tmp = snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL);
565 if (cmd == SNDRV_PCM_TRIGGER_START) {
566 tmp |= 1;
567 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
568 tmp &= ~1;
569 } else {
570 result = -EINVAL;
571 }
572 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
573 spin_unlock(&ice->reg_lock);
574 return result;
575}
576
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100577static int snd_ice1712_playback_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100579 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
580 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 u32 period_size, buf_size, rate, tmp;
582
583 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
584 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
585 tmp = 0x0000;
586 if (snd_pcm_format_width(runtime->format) == 16)
587 tmp |= 0x10;
588 if (runtime->channels == 2)
589 tmp |= 0x08;
590 rate = (runtime->rate * 8192) / 375;
591 if (rate > 0x000fffff)
592 rate = 0x000fffff;
593 spin_lock_irq(&ice->reg_lock);
594 outb(0, ice->ddma_port + 15);
595 outb(ICE1712_DMA_MODE_WRITE | ICE1712_DMA_AUTOINIT, ice->ddma_port + 0x0b);
596 outl(runtime->dma_addr, ice->ddma_port + 0);
597 outw(buf_size, ice->ddma_port + 4);
598 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_LO, rate & 0xff);
599 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_MID, (rate >> 8) & 0xff);
600 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_HI, (rate >> 16) & 0xff);
601 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
602 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_LO, period_size & 0xff);
603 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_HI, period_size >> 8);
604 snd_ice1712_write(ice, ICE1712_IREG_PBK_LEFT, 0);
605 snd_ice1712_write(ice, ICE1712_IREG_PBK_RIGHT, 0);
606 spin_unlock_irq(&ice->reg_lock);
607 return 0;
608}
609
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100610static int snd_ice1712_playback_ds_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100612 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
613 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 u32 period_size, buf_size, rate, tmp, chn;
615
616 period_size = snd_pcm_lib_period_bytes(substream) - 1;
617 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
618 tmp = 0x0064;
619 if (snd_pcm_format_width(runtime->format) == 16)
620 tmp &= ~0x04;
621 if (runtime->channels == 2)
622 tmp |= 0x08;
623 rate = (runtime->rate * 8192) / 375;
624 if (rate > 0x000fffff)
625 rate = 0x000fffff;
626 ice->playback_con_active_buf[substream->number] = 0;
627 ice->playback_con_virt_addr[substream->number] = runtime->dma_addr;
628 chn = substream->number * 2;
629 spin_lock_irq(&ice->reg_lock);
630 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR0, runtime->dma_addr);
631 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT0, period_size);
632 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR1, runtime->dma_addr + (runtime->periods > 1 ? period_size + 1 : 0));
633 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT1, period_size);
634 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_RATE, rate);
635 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_VOLUME, 0);
636 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_CONTROL, tmp);
637 if (runtime->channels == 2) {
638 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_RATE, rate);
639 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_VOLUME, 0);
640 }
641 spin_unlock_irq(&ice->reg_lock);
642 return 0;
643}
644
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100645static int snd_ice1712_capture_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100647 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
648 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 u32 period_size, buf_size;
650 u8 tmp;
651
652 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
653 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
654 tmp = 0x06;
655 if (snd_pcm_format_width(runtime->format) == 16)
656 tmp &= ~0x04;
657 if (runtime->channels == 2)
658 tmp &= ~0x02;
659 spin_lock_irq(&ice->reg_lock);
660 outl(ice->capture_con_virt_addr = runtime->dma_addr, ICEREG(ice, CONCAP_ADDR));
661 outw(buf_size, ICEREG(ice, CONCAP_COUNT));
662 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_HI, period_size >> 8);
663 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_LO, period_size & 0xff);
664 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
665 spin_unlock_irq(&ice->reg_lock);
666 snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
667 return 0;
668}
669
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100670static snd_pcm_uframes_t snd_ice1712_playback_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100672 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
673 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 size_t ptr;
675
676 if (!(snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL) & 1))
677 return 0;
678 ptr = runtime->buffer_size - inw(ice->ddma_port + 4);
679 if (ptr == runtime->buffer_size)
680 ptr = 0;
681 return bytes_to_frames(substream->runtime, ptr);
682}
683
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100684static snd_pcm_uframes_t snd_ice1712_playback_ds_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100686 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 u8 addr;
688 size_t ptr;
689
690 if (!(snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL) & 1))
691 return 0;
692 if (ice->playback_con_active_buf[substream->number])
693 addr = ICE1712_DSC_ADDR1;
694 else
695 addr = ICE1712_DSC_ADDR0;
696 ptr = snd_ice1712_ds_read(ice, substream->number * 2, addr) -
697 ice->playback_con_virt_addr[substream->number];
698 if (ptr == substream->runtime->buffer_size)
699 ptr = 0;
700 return bytes_to_frames(substream->runtime, ptr);
701}
702
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100703static snd_pcm_uframes_t snd_ice1712_capture_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100705 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 size_t ptr;
707
708 if (!(snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL) & 1))
709 return 0;
710 ptr = inl(ICEREG(ice, CONCAP_ADDR)) - ice->capture_con_virt_addr;
711 if (ptr == substream->runtime->buffer_size)
712 ptr = 0;
713 return bytes_to_frames(substream->runtime, ptr);
714}
715
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400716static const struct snd_pcm_hardware snd_ice1712_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 .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
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400735static const struct snd_pcm_hardware snd_ice1712_playback_ds = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
737 SNDRV_PCM_INFO_BLOCK_TRANSFER |
738 SNDRV_PCM_INFO_MMAP_VALID |
739 SNDRV_PCM_INFO_PAUSE),
740 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
741 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
742 .rate_min = 4000,
743 .rate_max = 48000,
744 .channels_min = 1,
745 .channels_max = 2,
746 .buffer_bytes_max = (128*1024),
747 .period_bytes_min = 64,
748 .period_bytes_max = (128*1024),
749 .periods_min = 2,
750 .periods_max = 2,
751 .fifo_size = 0,
752};
753
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400754static const struct snd_pcm_hardware snd_ice1712_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
756 SNDRV_PCM_INFO_BLOCK_TRANSFER |
757 SNDRV_PCM_INFO_MMAP_VALID),
758 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
759 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
760 .rate_min = 4000,
761 .rate_max = 48000,
762 .channels_min = 1,
763 .channels_max = 2,
764 .buffer_bytes_max = (64*1024),
765 .period_bytes_min = 64,
766 .period_bytes_max = (64*1024),
767 .periods_min = 1,
768 .periods_max = 1024,
769 .fifo_size = 0,
770};
771
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100772static int snd_ice1712_playback_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100774 struct snd_pcm_runtime *runtime = substream->runtime;
775 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
777 ice->playback_con_substream = substream;
778 runtime->hw = snd_ice1712_playback;
779 return 0;
780}
781
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100782static int snd_ice1712_playback_ds_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100784 struct snd_pcm_runtime *runtime = substream->runtime;
785 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 u32 tmp;
787
788 ice->playback_con_substream_ds[substream->number] = substream;
789 runtime->hw = snd_ice1712_playback_ds;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400790 spin_lock_irq(&ice->reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2));
792 outw(tmp, ICEDS(ice, INTMASK));
793 spin_unlock_irq(&ice->reg_lock);
794 return 0;
795}
796
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100797static int snd_ice1712_capture_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100799 struct snd_pcm_runtime *runtime = substream->runtime;
800 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 ice->capture_con_substream = substream;
803 runtime->hw = snd_ice1712_capture;
804 runtime->hw.rates = ice->ac97->rates[AC97_RATES_ADC];
805 if (!(runtime->hw.rates & SNDRV_PCM_RATE_8000))
806 runtime->hw.rate_min = 48000;
807 return 0;
808}
809
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100810static int snd_ice1712_playback_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100812 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 ice->playback_con_substream = NULL;
815 return 0;
816}
817
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100818static int snd_ice1712_playback_ds_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100820 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 u32 tmp;
822
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400823 spin_lock_irq(&ice->reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2));
825 outw(tmp, ICEDS(ice, INTMASK));
826 spin_unlock_irq(&ice->reg_lock);
827 ice->playback_con_substream_ds[substream->number] = NULL;
828 return 0;
829}
830
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100831static int snd_ice1712_capture_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100833 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
835 ice->capture_con_substream = NULL;
836 return 0;
837}
838
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100839static struct snd_pcm_ops snd_ice1712_playback_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 .open = snd_ice1712_playback_open,
841 .close = snd_ice1712_playback_close,
842 .ioctl = snd_pcm_lib_ioctl,
843 .hw_params = snd_ice1712_hw_params,
844 .hw_free = snd_ice1712_hw_free,
845 .prepare = snd_ice1712_playback_prepare,
846 .trigger = snd_ice1712_playback_trigger,
847 .pointer = snd_ice1712_playback_pointer,
848};
849
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100850static struct snd_pcm_ops snd_ice1712_playback_ds_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 .open = snd_ice1712_playback_ds_open,
852 .close = snd_ice1712_playback_ds_close,
853 .ioctl = snd_pcm_lib_ioctl,
854 .hw_params = snd_ice1712_hw_params,
855 .hw_free = snd_ice1712_hw_free,
856 .prepare = snd_ice1712_playback_ds_prepare,
857 .trigger = snd_ice1712_playback_ds_trigger,
858 .pointer = snd_ice1712_playback_ds_pointer,
859};
860
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100861static struct snd_pcm_ops snd_ice1712_capture_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 .open = snd_ice1712_capture_open,
863 .close = snd_ice1712_capture_close,
864 .ioctl = snd_pcm_lib_ioctl,
865 .hw_params = snd_ice1712_hw_params,
866 .hw_free = snd_ice1712_hw_free,
867 .prepare = snd_ice1712_capture_prepare,
868 .trigger = snd_ice1712_capture_trigger,
869 .pointer = snd_ice1712_capture_pointer,
870};
871
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400872static int __devinit snd_ice1712_pcm(struct snd_ice1712 *ice, int device, struct snd_pcm **rpcm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100874 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 int err;
876
877 if (rpcm)
878 *rpcm = NULL;
879 err = snd_pcm_new(ice->card, "ICE1712 consumer", device, 1, 1, &pcm);
880 if (err < 0)
881 return err;
882
883 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ops);
884 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_ops);
885
886 pcm->private_data = ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 pcm->info_flags = 0;
888 strcpy(pcm->name, "ICE1712 consumer");
889 ice->pcm = pcm;
890
891 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
892 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
893
894 if (rpcm)
895 *rpcm = pcm;
896
897 printk(KERN_WARNING "Consumer PCM code does not work well at the moment --jk\n");
898
899 return 0;
900}
901
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400902static int __devinit snd_ice1712_pcm_ds(struct snd_ice1712 *ice, int device, struct snd_pcm **rpcm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100904 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 int err;
906
907 if (rpcm)
908 *rpcm = NULL;
909 err = snd_pcm_new(ice->card, "ICE1712 consumer (DS)", device, 6, 0, &pcm);
910 if (err < 0)
911 return err;
912
913 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ds_ops);
914
915 pcm->private_data = ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 pcm->info_flags = 0;
917 strcpy(pcm->name, "ICE1712 consumer (DS)");
918 ice->pcm_ds = pcm;
919
920 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
921 snd_dma_pci_data(ice->pci), 64*1024, 128*1024);
922
923 if (rpcm)
924 *rpcm = pcm;
925
926 return 0;
927}
928
929/*
930 * PCM code - professional part (multitrack)
931 */
932
933static unsigned int rates[] = { 8000, 9600, 11025, 12000, 16000, 22050, 24000,
934 32000, 44100, 48000, 64000, 88200, 96000 };
935
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100936static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 .count = ARRAY_SIZE(rates),
938 .list = rates,
939 .mask = 0,
940};
941
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100942static int snd_ice1712_pro_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 int cmd)
944{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100945 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 switch (cmd) {
947 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
948 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
949 {
950 unsigned int what;
951 unsigned int old;
952 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
953 return -EINVAL;
954 what = ICE1712_PLAYBACK_PAUSE;
955 snd_pcm_trigger_done(substream, substream);
956 spin_lock(&ice->reg_lock);
957 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
958 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
959 old |= what;
960 else
961 old &= ~what;
962 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
963 spin_unlock(&ice->reg_lock);
964 break;
965 }
966 case SNDRV_PCM_TRIGGER_START:
967 case SNDRV_PCM_TRIGGER_STOP:
968 {
969 unsigned int what = 0;
970 unsigned int old;
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100971 struct snd_pcm_substream *s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Takashi Iwaief991b92007-02-22 12:52:53 +0100973 snd_pcm_group_for_each_entry(s, substream) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 if (s == ice->playback_pro_substream) {
975 what |= ICE1712_PLAYBACK_START;
976 snd_pcm_trigger_done(s, substream);
977 } else if (s == ice->capture_pro_substream) {
978 what |= ICE1712_CAPTURE_START_SHADOW;
979 snd_pcm_trigger_done(s, substream);
980 }
981 }
982 spin_lock(&ice->reg_lock);
983 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
984 if (cmd == SNDRV_PCM_TRIGGER_START)
985 old |= what;
986 else
987 old &= ~what;
988 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
989 spin_unlock(&ice->reg_lock);
990 break;
991 }
992 default:
993 return -EINVAL;
994 }
995 return 0;
996}
997
998/*
999 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001000static void snd_ice1712_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate, int force)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001{
1002 unsigned long flags;
1003 unsigned char val, old;
1004 unsigned int i;
1005
1006 switch (rate) {
1007 case 8000: val = 6; break;
1008 case 9600: val = 3; break;
1009 case 11025: val = 10; break;
1010 case 12000: val = 2; break;
1011 case 16000: val = 5; break;
1012 case 22050: val = 9; break;
1013 case 24000: val = 1; break;
1014 case 32000: val = 4; break;
1015 case 44100: val = 8; break;
1016 case 48000: val = 0; break;
1017 case 64000: val = 15; break;
1018 case 88200: val = 11; break;
1019 case 96000: val = 7; break;
1020 default:
1021 snd_BUG();
1022 val = 0;
1023 rate = 48000;
1024 break;
1025 }
1026
1027 spin_lock_irqsave(&ice->reg_lock, flags);
1028 if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
1029 ICE1712_PLAYBACK_PAUSE|
1030 ICE1712_PLAYBACK_START)) {
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001031__out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 spin_unlock_irqrestore(&ice->reg_lock, flags);
1033 return;
1034 }
1035 if (!force && is_pro_rate_locked(ice))
1036 goto __out;
1037
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001038 old = inb(ICEMT(ice, RATE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 if (!force && old == val)
1040 goto __out;
1041 outb(val, ICEMT(ice, RATE));
1042 spin_unlock_irqrestore(&ice->reg_lock, flags);
1043
1044 if (ice->gpio.set_pro_rate)
1045 ice->gpio.set_pro_rate(ice, rate);
1046 for (i = 0; i < ice->akm_codecs; i++) {
1047 if (ice->akm[i].ops.set_rate_val)
1048 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
1049 }
1050 if (ice->spdif.ops.setup_rate)
1051 ice->spdif.ops.setup_rate(ice, rate);
1052}
1053
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001054static int snd_ice1712_playback_pro_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001056 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
1058 ice->playback_pro_size = snd_pcm_lib_buffer_bytes(substream);
1059 spin_lock_irq(&ice->reg_lock);
1060 outl(substream->runtime->dma_addr, ICEMT(ice, PLAYBACK_ADDR));
1061 outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));
1062 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT));
1063 spin_unlock_irq(&ice->reg_lock);
1064
1065 return 0;
1066}
1067
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001068static int snd_ice1712_playback_pro_hw_params(struct snd_pcm_substream *substream,
1069 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001071 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
1073 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1074 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1075}
1076
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001077static int snd_ice1712_capture_pro_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001079 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
1081 ice->capture_pro_size = snd_pcm_lib_buffer_bytes(substream);
1082 spin_lock_irq(&ice->reg_lock);
1083 outl(substream->runtime->dma_addr, ICEMT(ice, CAPTURE_ADDR));
1084 outw((ice->capture_pro_size >> 2) - 1, ICEMT(ice, CAPTURE_SIZE));
1085 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, CAPTURE_COUNT));
1086 spin_unlock_irq(&ice->reg_lock);
1087 return 0;
1088}
1089
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001090static int snd_ice1712_capture_pro_hw_params(struct snd_pcm_substream *substream,
1091 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001093 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
1095 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1096 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1097}
1098
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001099static snd_pcm_uframes_t snd_ice1712_playback_pro_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001101 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 size_t ptr;
1103
1104 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_PLAYBACK_START))
1105 return 0;
1106 ptr = ice->playback_pro_size - (inw(ICEMT(ice, PLAYBACK_SIZE)) << 2);
1107 if (ptr == substream->runtime->buffer_size)
1108 ptr = 0;
1109 return bytes_to_frames(substream->runtime, ptr);
1110}
1111
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001112static snd_pcm_uframes_t snd_ice1712_capture_pro_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001114 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 size_t ptr;
1116
1117 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_CAPTURE_START_SHADOW))
1118 return 0;
1119 ptr = ice->capture_pro_size - (inw(ICEMT(ice, CAPTURE_SIZE)) << 2);
1120 if (ptr == substream->runtime->buffer_size)
1121 ptr = 0;
1122 return bytes_to_frames(substream->runtime, ptr);
1123}
1124
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001125static const struct snd_pcm_hardware snd_ice1712_playback_pro = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1127 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1128 SNDRV_PCM_INFO_MMAP_VALID |
1129 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1130 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1131 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1132 .rate_min = 4000,
1133 .rate_max = 96000,
1134 .channels_min = 10,
1135 .channels_max = 10,
1136 .buffer_bytes_max = (256*1024),
1137 .period_bytes_min = 10 * 4 * 2,
1138 .period_bytes_max = 131040,
1139 .periods_min = 1,
1140 .periods_max = 1024,
1141 .fifo_size = 0,
1142};
1143
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001144static const struct snd_pcm_hardware snd_ice1712_capture_pro = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1146 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1147 SNDRV_PCM_INFO_MMAP_VALID |
1148 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1149 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1150 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1151 .rate_min = 4000,
1152 .rate_max = 96000,
1153 .channels_min = 12,
1154 .channels_max = 12,
1155 .buffer_bytes_max = (256*1024),
1156 .period_bytes_min = 12 * 4 * 2,
1157 .period_bytes_max = 131040,
1158 .periods_min = 1,
1159 .periods_max = 1024,
1160 .fifo_size = 0,
1161};
1162
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001163static int snd_ice1712_playback_pro_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001165 struct snd_pcm_runtime *runtime = substream->runtime;
1166 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
1168 ice->playback_pro_substream = substream;
1169 runtime->hw = snd_ice1712_playback_pro;
1170 snd_pcm_set_sync(substream);
1171 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1172 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1173
1174 if (ice->spdif.ops.open)
1175 ice->spdif.ops.open(ice, substream);
1176
1177 return 0;
1178}
1179
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001180static int snd_ice1712_capture_pro_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001182 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1183 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
1185 ice->capture_pro_substream = substream;
1186 runtime->hw = snd_ice1712_capture_pro;
1187 snd_pcm_set_sync(substream);
1188 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1189 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1190 return 0;
1191}
1192
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001193static int snd_ice1712_playback_pro_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001195 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
1197 if (PRO_RATE_RESET)
1198 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1199 ice->playback_pro_substream = NULL;
1200 if (ice->spdif.ops.close)
1201 ice->spdif.ops.close(ice, substream);
1202
1203 return 0;
1204}
1205
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001206static int snd_ice1712_capture_pro_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001208 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
1210 if (PRO_RATE_RESET)
1211 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1212 ice->capture_pro_substream = NULL;
1213 return 0;
1214}
1215
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001216static struct snd_pcm_ops snd_ice1712_playback_pro_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 .open = snd_ice1712_playback_pro_open,
1218 .close = snd_ice1712_playback_pro_close,
1219 .ioctl = snd_pcm_lib_ioctl,
1220 .hw_params = snd_ice1712_playback_pro_hw_params,
1221 .hw_free = snd_ice1712_hw_free,
1222 .prepare = snd_ice1712_playback_pro_prepare,
1223 .trigger = snd_ice1712_pro_trigger,
1224 .pointer = snd_ice1712_playback_pro_pointer,
1225};
1226
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001227static struct snd_pcm_ops snd_ice1712_capture_pro_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 .open = snd_ice1712_capture_pro_open,
1229 .close = snd_ice1712_capture_pro_close,
1230 .ioctl = snd_pcm_lib_ioctl,
1231 .hw_params = snd_ice1712_capture_pro_hw_params,
1232 .hw_free = snd_ice1712_hw_free,
1233 .prepare = snd_ice1712_capture_pro_prepare,
1234 .trigger = snd_ice1712_pro_trigger,
1235 .pointer = snd_ice1712_capture_pro_pointer,
1236};
1237
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001238static int __devinit snd_ice1712_pcm_profi(struct snd_ice1712 *ice, int device, struct snd_pcm **rpcm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001240 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 int err;
1242
1243 if (rpcm)
1244 *rpcm = NULL;
1245 err = snd_pcm_new(ice->card, "ICE1712 multi", device, 1, 1, &pcm);
1246 if (err < 0)
1247 return err;
1248
1249 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_pro_ops);
1250 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_pro_ops);
1251
1252 pcm->private_data = ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 pcm->info_flags = 0;
1254 strcpy(pcm->name, "ICE1712 multi");
1255
1256 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1257 snd_dma_pci_data(ice->pci), 256*1024, 256*1024);
1258
1259 ice->pcm_pro = pcm;
1260 if (rpcm)
1261 *rpcm = pcm;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001262
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 if (ice->cs8427) {
1264 /* assign channels to iec958 */
1265 err = snd_cs8427_iec958_build(ice->cs8427,
1266 pcm->streams[0].substream,
1267 pcm->streams[1].substream);
1268 if (err < 0)
1269 return err;
1270 }
1271
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001272 err = snd_ice1712_build_pro_mixer(ice);
1273 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 return err;
1275 return 0;
1276}
1277
1278/*
1279 * Mixer section
1280 */
1281
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001282static void snd_ice1712_update_volume(struct snd_ice1712 *ice, int index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283{
1284 unsigned int vol = ice->pro_volumes[index];
1285 unsigned short val = 0;
1286
1287 val |= (vol & 0x8000) == 0 ? (96 - (vol & 0x7f)) : 0x7f;
1288 val |= ((vol & 0x80000000) == 0 ? (96 - ((vol >> 16) & 0x7f)) : 0x7f) << 8;
1289 outb(index, ICEMT(ice, MONITOR_INDEX));
1290 outw(val, ICEMT(ice, MONITOR_VOLUME));
1291}
1292
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001293#define snd_ice1712_pro_mixer_switch_info snd_ctl_boolean_stereo_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001295static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001297 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Harvey Harrisonc3daa922008-02-29 11:52:50 +01001298 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1299 kcontrol->private_value;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001300
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 spin_lock_irq(&ice->reg_lock);
Harvey Harrisonc3daa922008-02-29 11:52:50 +01001302 ucontrol->value.integer.value[0] =
1303 !((ice->pro_volumes[priv_idx] >> 15) & 1);
1304 ucontrol->value.integer.value[1] =
1305 !((ice->pro_volumes[priv_idx] >> 31) & 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 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);
Harvey Harrisonc3daa922008-02-29 11:52:50 +01001313 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1314 kcontrol->private_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 unsigned int nval, change;
1316
1317 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
1318 (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
1319 spin_lock_irq(&ice->reg_lock);
Harvey Harrisonc3daa922008-02-29 11:52:50 +01001320 nval |= ice->pro_volumes[priv_idx] & ~0x80008000;
1321 change = nval != ice->pro_volumes[priv_idx];
1322 ice->pro_volumes[priv_idx] = nval;
1323 snd_ice1712_update_volume(ice, priv_idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 spin_unlock_irq(&ice->reg_lock);
1325 return change;
1326}
1327
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001328static int snd_ice1712_pro_mixer_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329{
1330 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1331 uinfo->count = 2;
1332 uinfo->value.integer.min = 0;
1333 uinfo->value.integer.max = 96;
1334 return 0;
1335}
1336
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001337static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001339 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Harvey Harrisonc3daa922008-02-29 11:52:50 +01001340 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1341 kcontrol->private_value;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001342
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 spin_lock_irq(&ice->reg_lock);
Harvey Harrisonc3daa922008-02-29 11:52:50 +01001344 ucontrol->value.integer.value[0] =
1345 (ice->pro_volumes[priv_idx] >> 0) & 127;
1346 ucontrol->value.integer.value[1] =
1347 (ice->pro_volumes[priv_idx] >> 16) & 127;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 spin_unlock_irq(&ice->reg_lock);
1349 return 0;
1350}
1351
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001352static int snd_ice1712_pro_mixer_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001354 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Harvey Harrisonc3daa922008-02-29 11:52:50 +01001355 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1356 kcontrol->private_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 unsigned int nval, change;
1358
1359 nval = (ucontrol->value.integer.value[0] & 127) |
1360 ((ucontrol->value.integer.value[1] & 127) << 16);
1361 spin_lock_irq(&ice->reg_lock);
Harvey Harrisonc3daa922008-02-29 11:52:50 +01001362 nval |= ice->pro_volumes[priv_idx] & ~0x007f007f;
1363 change = nval != ice->pro_volumes[priv_idx];
1364 ice->pro_volumes[priv_idx] = nval;
1365 snd_ice1712_update_volume(ice, priv_idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 spin_unlock_irq(&ice->reg_lock);
1367 return change;
1368}
1369
Takashi Iwai0cb29ea2007-01-29 15:33:49 +01001370static const DECLARE_TLV_DB_SCALE(db_scale_playback, -14400, 150, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001372static struct snd_kcontrol_new snd_ice1712_multi_playback_ctrls[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 {
1374 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1375 .name = "Multi Playback Switch",
1376 .info = snd_ice1712_pro_mixer_switch_info,
1377 .get = snd_ice1712_pro_mixer_switch_get,
1378 .put = snd_ice1712_pro_mixer_switch_put,
1379 .private_value = 0,
1380 .count = 10,
1381 },
1382 {
1383 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai680ef792006-08-30 16:56:30 +02001384 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1385 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 .name = "Multi Playback Volume",
1387 .info = snd_ice1712_pro_mixer_volume_info,
1388 .get = snd_ice1712_pro_mixer_volume_get,
1389 .put = snd_ice1712_pro_mixer_volume_put,
1390 .private_value = 0,
1391 .count = 10,
Takashi Iwai680ef792006-08-30 16:56:30 +02001392 .tlv = { .p = db_scale_playback }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 },
1394};
1395
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001396static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_switch __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1398 .name = "H/W Multi Capture Switch",
1399 .info = snd_ice1712_pro_mixer_switch_info,
1400 .get = snd_ice1712_pro_mixer_switch_get,
1401 .put = snd_ice1712_pro_mixer_switch_put,
1402 .private_value = 10,
1403};
1404
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001405static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_switch __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001407 .name = SNDRV_CTL_NAME_IEC958("Multi ", CAPTURE, SWITCH),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 .info = snd_ice1712_pro_mixer_switch_info,
1409 .get = snd_ice1712_pro_mixer_switch_get,
1410 .put = snd_ice1712_pro_mixer_switch_put,
1411 .private_value = 18,
1412 .count = 2,
1413};
1414
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001415static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_volume __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai680ef792006-08-30 16:56:30 +02001417 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1418 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 .name = "H/W Multi Capture Volume",
1420 .info = snd_ice1712_pro_mixer_volume_info,
1421 .get = snd_ice1712_pro_mixer_volume_get,
1422 .put = snd_ice1712_pro_mixer_volume_put,
1423 .private_value = 10,
Takashi Iwai680ef792006-08-30 16:56:30 +02001424 .tlv = { .p = db_scale_playback }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425};
1426
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001427static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_volume __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001429 .name = SNDRV_CTL_NAME_IEC958("Multi ", CAPTURE, VOLUME),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 .info = snd_ice1712_pro_mixer_volume_info,
1431 .get = snd_ice1712_pro_mixer_volume_get,
1432 .put = snd_ice1712_pro_mixer_volume_put,
1433 .private_value = 18,
1434 .count = 2,
1435};
1436
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001437static int __devinit snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001439 struct snd_card *card = ice->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 unsigned int idx;
1441 int err;
1442
1443 /* multi-channel mixer */
1444 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_multi_playback_ctrls); idx++) {
1445 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_playback_ctrls[idx], ice));
1446 if (err < 0)
1447 return err;
1448 }
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001449
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 if (ice->num_total_adcs > 0) {
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001451 struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_switch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 tmp.count = ice->num_total_adcs;
1453 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1454 if (err < 0)
1455 return err;
1456 }
1457
1458 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_switch, ice));
1459 if (err < 0)
1460 return err;
1461
1462 if (ice->num_total_adcs > 0) {
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001463 struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_volume;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 tmp.count = ice->num_total_adcs;
1465 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1466 if (err < 0)
1467 return err;
1468 }
1469
1470 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_volume, ice));
1471 if (err < 0)
1472 return err;
1473
1474 /* initialize volumes */
1475 for (idx = 0; idx < 10; idx++) {
1476 ice->pro_volumes[idx] = 0x80008000; /* mute */
1477 snd_ice1712_update_volume(ice, idx);
1478 }
1479 for (idx = 10; idx < 10 + ice->num_total_adcs; idx++) {
1480 ice->pro_volumes[idx] = 0x80008000; /* mute */
1481 snd_ice1712_update_volume(ice, idx);
1482 }
1483 for (idx = 18; idx < 20; idx++) {
1484 ice->pro_volumes[idx] = 0x80008000; /* mute */
1485 snd_ice1712_update_volume(ice, idx);
1486 }
1487 return 0;
1488}
1489
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001490static void snd_ice1712_mixer_free_ac97(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001492 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 ice->ac97 = NULL;
1494}
1495
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001496static int __devinit snd_ice1712_ac97_mixer(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497{
1498 int err, bus_num = 0;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001499 struct snd_ac97_template ac97;
1500 struct snd_ac97_bus *pbus;
1501 static struct snd_ac97_bus_ops con_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 .write = snd_ice1712_ac97_write,
1503 .read = snd_ice1712_ac97_read,
1504 };
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001505 static struct snd_ac97_bus_ops pro_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 .write = snd_ice1712_pro_ac97_write,
1507 .read = snd_ice1712_pro_ac97_read,
1508 };
1509
1510 if (ice_has_con_ac97(ice)) {
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001511 err = snd_ac97_bus(ice->card, bus_num++, &con_ops, NULL, &pbus);
1512 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 return err;
1514 memset(&ac97, 0, sizeof(ac97));
1515 ac97.private_data = ice;
1516 ac97.private_free = snd_ice1712_mixer_free_ac97;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001517 err = snd_ac97_mixer(pbus, &ac97, &ice->ac97);
1518 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 printk(KERN_WARNING "ice1712: cannot initialize ac97 for consumer, skipped\n");
1520 else {
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001521 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice));
1522 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 return err;
1524 return 0;
1525 }
1526 }
1527
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001528 if (!(ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) {
1529 err = snd_ac97_bus(ice->card, bus_num, &pro_ops, NULL, &pbus);
1530 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 return err;
1532 memset(&ac97, 0, sizeof(ac97));
1533 ac97.private_data = ice;
1534 ac97.private_free = snd_ice1712_mixer_free_ac97;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001535 err = snd_ac97_mixer(pbus, &ac97, &ice->ac97);
1536 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1538 else
1539 return 0;
1540 }
1541 /* I2S mixer only */
1542 strcat(ice->card->mixername, "ICE1712 - multitrack");
1543 return 0;
1544}
1545
1546/*
1547 *
1548 */
1549
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001550static inline unsigned int eeprom_double(struct snd_ice1712 *ice, int idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551{
1552 return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8);
1553}
1554
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001555static void snd_ice1712_proc_read(struct snd_info_entry *entry,
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001556 struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001558 struct snd_ice1712 *ice = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 unsigned int idx;
1560
1561 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1562 snd_iprintf(buffer, "EEPROM:\n");
1563
1564 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1565 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1566 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1567 snd_iprintf(buffer, " Codec : 0x%x\n", ice->eeprom.data[ICE_EEP1_CODEC]);
1568 snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP1_ACLINK]);
1569 snd_iprintf(buffer, " I2S ID : 0x%x\n", ice->eeprom.data[ICE_EEP1_I2SID]);
1570 snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP1_SPDIF]);
1571 snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
1572 snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
1573 snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
1574 snd_iprintf(buffer, " AC'97 main : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_MAIN_LO));
1575 snd_iprintf(buffer, " AC'97 pcm : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_PCM_LO));
1576 snd_iprintf(buffer, " AC'97 record : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_REC_LO));
1577 snd_iprintf(buffer, " AC'97 record src : 0x%x\n", ice->eeprom.data[ICE_EEP1_AC97_RECSRC]);
1578 for (idx = 0; idx < 4; idx++)
1579 snd_iprintf(buffer, " DAC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_DAC_ID + idx]);
1580 for (idx = 0; idx < 4; idx++)
1581 snd_iprintf(buffer, " ADC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_ADC_ID + idx]);
1582 for (idx = 0x1c; idx < ice->eeprom.size; idx++)
1583 snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
1584
1585 snd_iprintf(buffer, "\nRegisters:\n");
1586 snd_iprintf(buffer, " PSDOUT03 : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_PSDOUT03)));
1587 snd_iprintf(buffer, " CAPTURE : 0x%08x\n", inl(ICEMT(ice, ROUTE_CAPTURE)));
1588 snd_iprintf(buffer, " SPDOUT : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT)));
1589 snd_iprintf(buffer, " RATE : 0x%02x\n", (unsigned)inb(ICEMT(ice, RATE)));
Jaroslav Kyselaf7004f32006-02-10 08:42:17 +01001590 snd_iprintf(buffer, " GPIO_DATA : 0x%02x\n", (unsigned)snd_ice1712_get_gpio_data(ice));
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001591 snd_iprintf(buffer, " GPIO_WRITE_MASK : 0x%02x\n", (unsigned)snd_ice1712_read(ice, ICE1712_IREG_GPIO_WRITE_MASK));
Jaroslav Kyselaf7004f32006-02-10 08:42:17 +01001592 snd_iprintf(buffer, " GPIO_DIRECTION : 0x%02x\n", (unsigned)snd_ice1712_read(ice, ICE1712_IREG_GPIO_DIRECTION));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593}
1594
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001595static void __devinit snd_ice1712_proc_init(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001597 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001599 if (!snd_card_proc_new(ice->card, "ice1712", &entry))
Takashi Iwaibf850202006-04-28 15:13:41 +02001600 snd_info_set_text_ops(entry, ice, snd_ice1712_proc_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601}
1602
1603/*
1604 *
1605 */
1606
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001607static int snd_ice1712_eeprom_info(struct snd_kcontrol *kcontrol,
1608 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609{
1610 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001611 uinfo->count = sizeof(struct snd_ice1712_eeprom);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 return 0;
1613}
1614
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001615static int snd_ice1712_eeprom_get(struct snd_kcontrol *kcontrol,
1616 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001618 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001619
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1621 return 0;
1622}
1623
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001624static struct snd_kcontrol_new snd_ice1712_eeprom __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1626 .name = "ICE1712 EEPROM",
1627 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1628 .info = snd_ice1712_eeprom_info,
1629 .get = snd_ice1712_eeprom_get
1630};
1631
1632/*
1633 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001634static int snd_ice1712_spdif_info(struct snd_kcontrol *kcontrol,
1635 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636{
1637 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1638 uinfo->count = 1;
1639 return 0;
1640}
1641
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001642static int snd_ice1712_spdif_default_get(struct snd_kcontrol *kcontrol,
1643 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001645 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 if (ice->spdif.ops.default_get)
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001647 ice->spdif.ops.default_get(ice, ucontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 return 0;
1649}
1650
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001651static int snd_ice1712_spdif_default_put(struct snd_kcontrol *kcontrol,
1652 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001654 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 if (ice->spdif.ops.default_put)
1656 return ice->spdif.ops.default_put(ice, ucontrol);
1657 return 0;
1658}
1659
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001660static struct snd_kcontrol_new snd_ice1712_spdif_default __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661{
1662 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001663 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 .info = snd_ice1712_spdif_info,
1665 .get = snd_ice1712_spdif_default_get,
1666 .put = snd_ice1712_spdif_default_put
1667};
1668
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001669static int snd_ice1712_spdif_maskc_get(struct snd_kcontrol *kcontrol,
1670 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001672 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 if (ice->spdif.ops.default_get) {
1674 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1675 IEC958_AES0_PROFESSIONAL |
1676 IEC958_AES0_CON_NOT_COPYRIGHT |
1677 IEC958_AES0_CON_EMPHASIS;
1678 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1679 IEC958_AES1_CON_CATEGORY;
1680 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1681 } else {
1682 ucontrol->value.iec958.status[0] = 0xff;
1683 ucontrol->value.iec958.status[1] = 0xff;
1684 ucontrol->value.iec958.status[2] = 0xff;
1685 ucontrol->value.iec958.status[3] = 0xff;
1686 ucontrol->value.iec958.status[4] = 0xff;
1687 }
1688 return 0;
1689}
1690
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001691static int snd_ice1712_spdif_maskp_get(struct snd_kcontrol *kcontrol,
1692 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001694 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 if (ice->spdif.ops.default_get) {
1696 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1697 IEC958_AES0_PROFESSIONAL |
1698 IEC958_AES0_PRO_FS |
1699 IEC958_AES0_PRO_EMPHASIS;
1700 ucontrol->value.iec958.status[1] = IEC958_AES1_PRO_MODE;
1701 } else {
1702 ucontrol->value.iec958.status[0] = 0xff;
1703 ucontrol->value.iec958.status[1] = 0xff;
1704 ucontrol->value.iec958.status[2] = 0xff;
1705 ucontrol->value.iec958.status[3] = 0xff;
1706 ucontrol->value.iec958.status[4] = 0xff;
1707 }
1708 return 0;
1709}
1710
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001711static struct snd_kcontrol_new snd_ice1712_spdif_maskc __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712{
1713 .access = SNDRV_CTL_ELEM_ACCESS_READ,
Clemens Ladisch67ed4162005-07-29 15:32:58 +02001714 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001715 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 .info = snd_ice1712_spdif_info,
1717 .get = snd_ice1712_spdif_maskc_get,
1718};
1719
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001720static struct snd_kcontrol_new snd_ice1712_spdif_maskp __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721{
1722 .access = SNDRV_CTL_ELEM_ACCESS_READ,
Clemens Ladisch67ed4162005-07-29 15:32:58 +02001723 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001724 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PRO_MASK),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 .info = snd_ice1712_spdif_info,
1726 .get = snd_ice1712_spdif_maskp_get,
1727};
1728
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001729static int snd_ice1712_spdif_stream_get(struct snd_kcontrol *kcontrol,
1730 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001732 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 if (ice->spdif.ops.stream_get)
1734 ice->spdif.ops.stream_get(ice, ucontrol);
1735 return 0;
1736}
1737
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001738static int snd_ice1712_spdif_stream_put(struct snd_kcontrol *kcontrol,
1739 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001741 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 if (ice->spdif.ops.stream_put)
1743 return ice->spdif.ops.stream_put(ice, ucontrol);
1744 return 0;
1745}
1746
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001747static struct snd_kcontrol_new snd_ice1712_spdif_stream __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001749 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1750 SNDRV_CTL_ELEM_ACCESS_INACTIVE),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001752 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 .info = snd_ice1712_spdif_info,
1754 .get = snd_ice1712_spdif_stream_get,
1755 .put = snd_ice1712_spdif_stream_put
1756};
1757
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001758int snd_ice1712_gpio_get(struct snd_kcontrol *kcontrol,
1759 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001761 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 unsigned char mask = kcontrol->private_value & 0xff;
1763 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001764
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 snd_ice1712_save_gpio_status(ice);
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001766 ucontrol->value.integer.value[0] =
1767 (snd_ice1712_gpio_read(ice) & mask ? 1 : 0) ^ invert;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 snd_ice1712_restore_gpio_status(ice);
1769 return 0;
1770}
1771
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001772int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
1773 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001775 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 unsigned char mask = kcontrol->private_value & 0xff;
1777 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1778 unsigned int val, nval;
1779
1780 if (kcontrol->private_value & (1 << 31))
1781 return -EPERM;
1782 nval = (ucontrol->value.integer.value[0] ? mask : 0) ^ invert;
1783 snd_ice1712_save_gpio_status(ice);
1784 val = snd_ice1712_gpio_read(ice);
1785 nval |= val & ~mask;
1786 if (val != nval)
1787 snd_ice1712_gpio_write(ice, nval);
1788 snd_ice1712_restore_gpio_status(ice);
1789 return val != nval;
1790}
1791
1792/*
1793 * rate
1794 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001795static int snd_ice1712_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1796 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797{
Takashi Iwai32b47da2007-01-29 15:26:36 +01001798 static const char * const texts[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 "8000", /* 0: 6 */
1800 "9600", /* 1: 3 */
1801 "11025", /* 2: 10 */
1802 "12000", /* 3: 2 */
1803 "16000", /* 4: 5 */
1804 "22050", /* 5: 9 */
1805 "24000", /* 6: 1 */
1806 "32000", /* 7: 4 */
1807 "44100", /* 8: 8 */
1808 "48000", /* 9: 0 */
1809 "64000", /* 10: 15 */
1810 "88200", /* 11: 11 */
1811 "96000", /* 12: 7 */
1812 "IEC958 Input", /* 13: -- */
1813 };
1814 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1815 uinfo->count = 1;
1816 uinfo->value.enumerated.items = 14;
1817 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1818 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1819 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1820 return 0;
1821}
1822
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001823static int snd_ice1712_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1824 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001826 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai32b47da2007-01-29 15:26:36 +01001827 static const unsigned char xlate[16] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10
1829 };
1830 unsigned char val;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001831
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 spin_lock_irq(&ice->reg_lock);
1833 if (is_spdif_master(ice)) {
1834 ucontrol->value.enumerated.item[0] = 13;
1835 } else {
1836 val = xlate[inb(ICEMT(ice, RATE)) & 15];
1837 if (val == 255) {
1838 snd_BUG();
1839 val = 0;
1840 }
1841 ucontrol->value.enumerated.item[0] = val;
1842 }
1843 spin_unlock_irq(&ice->reg_lock);
1844 return 0;
1845}
1846
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001847static int snd_ice1712_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1848 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001850 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai32b47da2007-01-29 15:26:36 +01001851 static const unsigned int xrate[13] = {
Jaroslav Kyselafe25bef2006-08-15 14:39:07 +02001852 8000, 9600, 11025, 12000, 16000, 22050, 24000,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 32000, 44100, 48000, 64000, 88200, 96000
1854 };
1855 unsigned char oval;
1856 int change = 0;
1857
1858 spin_lock_irq(&ice->reg_lock);
1859 oval = inb(ICEMT(ice, RATE));
1860 if (ucontrol->value.enumerated.item[0] == 13) {
1861 outb(oval | ICE1712_SPDIF_MASTER, ICEMT(ice, RATE));
1862 } else {
1863 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1864 spin_unlock_irq(&ice->reg_lock);
1865 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1866 spin_lock_irq(&ice->reg_lock);
1867 }
1868 change = inb(ICEMT(ice, RATE)) != oval;
1869 spin_unlock_irq(&ice->reg_lock);
1870
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001871 if ((oval & ICE1712_SPDIF_MASTER) !=
Jaroslav Kyselae957ebf2006-02-02 07:56:54 +01001872 (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER))
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001873 snd_ice1712_set_input_clock_source(ice, is_spdif_master(ice));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
1875 return change;
1876}
1877
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001878static struct snd_kcontrol_new snd_ice1712_pro_internal_clock __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1880 .name = "Multi Track Internal Clock",
1881 .info = snd_ice1712_pro_internal_clock_info,
1882 .get = snd_ice1712_pro_internal_clock_get,
1883 .put = snd_ice1712_pro_internal_clock_put
1884};
1885
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001886static int snd_ice1712_pro_internal_clock_default_info(struct snd_kcontrol *kcontrol,
1887 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888{
Takashi Iwai32b47da2007-01-29 15:26:36 +01001889 static const char * const texts[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 "8000", /* 0: 6 */
1891 "9600", /* 1: 3 */
1892 "11025", /* 2: 10 */
1893 "12000", /* 3: 2 */
1894 "16000", /* 4: 5 */
1895 "22050", /* 5: 9 */
1896 "24000", /* 6: 1 */
1897 "32000", /* 7: 4 */
1898 "44100", /* 8: 8 */
1899 "48000", /* 9: 0 */
1900 "64000", /* 10: 15 */
1901 "88200", /* 11: 11 */
1902 "96000", /* 12: 7 */
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001903 /* "IEC958 Input", 13: -- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 };
1905 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1906 uinfo->count = 1;
1907 uinfo->value.enumerated.items = 13;
1908 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1909 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1910 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1911 return 0;
1912}
1913
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001914static int snd_ice1712_pro_internal_clock_default_get(struct snd_kcontrol *kcontrol,
1915 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916{
1917 int val;
Takashi Iwai32b47da2007-01-29 15:26:36 +01001918 static const unsigned int xrate[13] = {
Jaroslav Kyselafe25bef2006-08-15 14:39:07 +02001919 8000, 9600, 11025, 12000, 16000, 22050, 24000,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 32000, 44100, 48000, 64000, 88200, 96000
1921 };
1922
1923 for (val = 0; val < 13; val++) {
1924 if (xrate[val] == PRO_RATE_DEFAULT)
1925 break;
1926 }
1927
1928 ucontrol->value.enumerated.item[0] = val;
1929 return 0;
1930}
1931
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001932static int snd_ice1712_pro_internal_clock_default_put(struct snd_kcontrol *kcontrol,
1933 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934{
Takashi Iwai32b47da2007-01-29 15:26:36 +01001935 static const unsigned int xrate[13] = {
Jaroslav Kyselafe25bef2006-08-15 14:39:07 +02001936 8000, 9600, 11025, 12000, 16000, 22050, 24000,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 32000, 44100, 48000, 64000, 88200, 96000
1938 };
1939 unsigned char oval;
1940 int change = 0;
1941
1942 oval = PRO_RATE_DEFAULT;
1943 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1944 change = PRO_RATE_DEFAULT != oval;
1945
1946 return change;
1947}
1948
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001949static struct snd_kcontrol_new snd_ice1712_pro_internal_clock_default __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1951 .name = "Multi Track Internal Clock Default",
1952 .info = snd_ice1712_pro_internal_clock_default_info,
1953 .get = snd_ice1712_pro_internal_clock_default_get,
1954 .put = snd_ice1712_pro_internal_clock_default_put
1955};
1956
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001957#define snd_ice1712_pro_rate_locking_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001959static int snd_ice1712_pro_rate_locking_get(struct snd_kcontrol *kcontrol,
1960 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961{
1962 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1963 return 0;
1964}
1965
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001966static int snd_ice1712_pro_rate_locking_put(struct snd_kcontrol *kcontrol,
1967 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001969 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 int change = 0, nval;
1971
1972 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1973 spin_lock_irq(&ice->reg_lock);
1974 change = PRO_RATE_LOCKED != nval;
1975 PRO_RATE_LOCKED = nval;
1976 spin_unlock_irq(&ice->reg_lock);
1977 return change;
1978}
1979
Ralf Baechlebf748ed2007-03-13 15:31:08 +01001980static struct snd_kcontrol_new snd_ice1712_pro_rate_locking __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1982 .name = "Multi Track Rate Locking",
1983 .info = snd_ice1712_pro_rate_locking_info,
1984 .get = snd_ice1712_pro_rate_locking_get,
1985 .put = snd_ice1712_pro_rate_locking_put
1986};
1987
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001988#define snd_ice1712_pro_rate_reset_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001990static int snd_ice1712_pro_rate_reset_get(struct snd_kcontrol *kcontrol,
1991 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992{
1993 ucontrol->value.integer.value[0] = PRO_RATE_RESET;
1994 return 0;
1995}
1996
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001997static int snd_ice1712_pro_rate_reset_put(struct snd_kcontrol *kcontrol,
1998 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002000 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 int change = 0, nval;
2002
2003 nval = ucontrol->value.integer.value[0] ? 1 : 0;
2004 spin_lock_irq(&ice->reg_lock);
2005 change = PRO_RATE_RESET != nval;
2006 PRO_RATE_RESET = nval;
2007 spin_unlock_irq(&ice->reg_lock);
2008 return change;
2009}
2010
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002011static struct snd_kcontrol_new snd_ice1712_pro_rate_reset __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2013 .name = "Multi Track Rate Reset",
2014 .info = snd_ice1712_pro_rate_reset_info,
2015 .get = snd_ice1712_pro_rate_reset_get,
2016 .put = snd_ice1712_pro_rate_reset_put
2017};
2018
2019/*
2020 * routing
2021 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002022static int snd_ice1712_pro_route_info(struct snd_kcontrol *kcontrol,
2023 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024{
Takashi Iwai32b47da2007-01-29 15:26:36 +01002025 static const char * const texts[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 "PCM Out", /* 0 */
2027 "H/W In 0", "H/W In 1", "H/W In 2", "H/W In 3", /* 1-4 */
2028 "H/W In 4", "H/W In 5", "H/W In 6", "H/W In 7", /* 5-8 */
2029 "IEC958 In L", "IEC958 In R", /* 9-10 */
2030 "Digital Mixer", /* 11 - optional */
2031 };
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002032
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2034 uinfo->count = 1;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002035 uinfo->value.enumerated.items =
2036 snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2038 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2039 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2040 return 0;
2041}
2042
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002043static int snd_ice1712_pro_route_analog_get(struct snd_kcontrol *kcontrol,
2044 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002046 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2048 unsigned int val, cval;
2049
2050 spin_lock_irq(&ice->reg_lock);
2051 val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2052 cval = inl(ICEMT(ice, ROUTE_CAPTURE));
2053 spin_unlock_irq(&ice->reg_lock);
2054
2055 val >>= ((idx % 2) * 8) + ((idx / 2) * 2);
2056 val &= 3;
2057 cval >>= ((idx / 2) * 8) + ((idx % 2) * 4);
2058 if (val == 1 && idx < 2)
2059 ucontrol->value.enumerated.item[0] = 11;
2060 else if (val == 2)
2061 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2062 else if (val == 3)
2063 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2064 else
2065 ucontrol->value.enumerated.item[0] = 0;
2066 return 0;
2067}
2068
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002069static int snd_ice1712_pro_route_analog_put(struct snd_kcontrol *kcontrol,
2070 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002072 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 int change, shift;
2074 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2075 unsigned int val, old_val, nval;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002076
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 /* update PSDOUT */
2078 if (ucontrol->value.enumerated.item[0] >= 11)
2079 nval = idx < 2 ? 1 : 0; /* dig mixer (or pcm) */
2080 else if (ucontrol->value.enumerated.item[0] >= 9)
2081 nval = 3; /* spdif in */
2082 else if (ucontrol->value.enumerated.item[0] >= 1)
2083 nval = 2; /* analog in */
2084 else
2085 nval = 0; /* pcm */
2086 shift = ((idx % 2) * 8) + ((idx / 2) * 2);
2087 spin_lock_irq(&ice->reg_lock);
2088 val = old_val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2089 val &= ~(0x03 << shift);
2090 val |= nval << shift;
2091 change = val != old_val;
2092 if (change)
2093 outw(val, ICEMT(ice, ROUTE_PSDOUT03));
2094 spin_unlock_irq(&ice->reg_lock);
2095 if (nval < 2) /* dig mixer of pcm */
2096 return change;
2097
2098 /* update CAPTURE */
2099 spin_lock_irq(&ice->reg_lock);
2100 val = old_val = inl(ICEMT(ice, ROUTE_CAPTURE));
2101 shift = ((idx / 2) * 8) + ((idx % 2) * 4);
2102 if (nval == 2) { /* analog in */
2103 nval = ucontrol->value.enumerated.item[0] - 1;
2104 val &= ~(0x07 << shift);
2105 val |= nval << shift;
2106 } else { /* spdif in */
2107 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2108 val &= ~(0x08 << shift);
2109 val |= nval << shift;
2110 }
2111 if (val != old_val) {
2112 change = 1;
2113 outl(val, ICEMT(ice, ROUTE_CAPTURE));
2114 }
2115 spin_unlock_irq(&ice->reg_lock);
2116 return change;
2117}
2118
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002119static int snd_ice1712_pro_route_spdif_get(struct snd_kcontrol *kcontrol,
2120 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002122 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2124 unsigned int val, cval;
2125 val = inw(ICEMT(ice, ROUTE_SPDOUT));
2126 cval = (val >> (idx * 4 + 8)) & 0x0f;
2127 val = (val >> (idx * 2)) & 0x03;
2128 if (val == 1)
2129 ucontrol->value.enumerated.item[0] = 11;
2130 else if (val == 2)
2131 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2132 else if (val == 3)
2133 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2134 else
2135 ucontrol->value.enumerated.item[0] = 0;
2136 return 0;
2137}
2138
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002139static int snd_ice1712_pro_route_spdif_put(struct snd_kcontrol *kcontrol,
2140 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002142 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 int change, shift;
2144 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2145 unsigned int val, old_val, nval;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002146
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 /* update SPDOUT */
2148 spin_lock_irq(&ice->reg_lock);
2149 val = old_val = inw(ICEMT(ice, ROUTE_SPDOUT));
2150 if (ucontrol->value.enumerated.item[0] >= 11)
2151 nval = 1;
2152 else if (ucontrol->value.enumerated.item[0] >= 9)
2153 nval = 3;
2154 else if (ucontrol->value.enumerated.item[0] >= 1)
2155 nval = 2;
2156 else
2157 nval = 0;
2158 shift = idx * 2;
2159 val &= ~(0x03 << shift);
2160 val |= nval << shift;
2161 shift = idx * 4 + 8;
2162 if (nval == 2) {
2163 nval = ucontrol->value.enumerated.item[0] - 1;
2164 val &= ~(0x07 << shift);
2165 val |= nval << shift;
2166 } else if (nval == 3) {
2167 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2168 val &= ~(0x08 << shift);
2169 val |= nval << shift;
2170 }
2171 change = val != old_val;
2172 if (change)
2173 outw(val, ICEMT(ice, ROUTE_SPDOUT));
2174 spin_unlock_irq(&ice->reg_lock);
2175 return change;
2176}
2177
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002178static struct snd_kcontrol_new snd_ice1712_mixer_pro_analog_route __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2180 .name = "H/W Playback Route",
2181 .info = snd_ice1712_pro_route_info,
2182 .get = snd_ice1712_pro_route_analog_get,
2183 .put = snd_ice1712_pro_route_analog_put,
2184};
2185
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002186static struct snd_kcontrol_new snd_ice1712_mixer_pro_spdif_route __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002188 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Route",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 .info = snd_ice1712_pro_route_info,
2190 .get = snd_ice1712_pro_route_spdif_get,
2191 .put = snd_ice1712_pro_route_spdif_put,
2192 .count = 2,
2193};
2194
2195
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002196static int snd_ice1712_pro_volume_rate_info(struct snd_kcontrol *kcontrol,
2197 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198{
2199 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2200 uinfo->count = 1;
2201 uinfo->value.integer.min = 0;
2202 uinfo->value.integer.max = 255;
2203 return 0;
2204}
2205
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002206static int snd_ice1712_pro_volume_rate_get(struct snd_kcontrol *kcontrol,
2207 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002209 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002210
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE));
2212 return 0;
2213}
2214
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002215static int snd_ice1712_pro_volume_rate_put(struct snd_kcontrol *kcontrol,
2216 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002218 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 int change;
2220
2221 spin_lock_irq(&ice->reg_lock);
2222 change = inb(ICEMT(ice, MONITOR_RATE)) != ucontrol->value.integer.value[0];
2223 outb(ucontrol->value.integer.value[0], ICEMT(ice, MONITOR_RATE));
2224 spin_unlock_irq(&ice->reg_lock);
2225 return change;
2226}
2227
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002228static struct snd_kcontrol_new snd_ice1712_mixer_pro_volume_rate __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2230 .name = "Multi Track Volume Rate",
2231 .info = snd_ice1712_pro_volume_rate_info,
2232 .get = snd_ice1712_pro_volume_rate_get,
2233 .put = snd_ice1712_pro_volume_rate_put
2234};
2235
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002236static int snd_ice1712_pro_peak_info(struct snd_kcontrol *kcontrol,
2237 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238{
2239 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2240 uinfo->count = 22;
2241 uinfo->value.integer.min = 0;
2242 uinfo->value.integer.max = 255;
2243 return 0;
2244}
2245
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002246static int snd_ice1712_pro_peak_get(struct snd_kcontrol *kcontrol,
2247 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002249 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 int idx;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002251
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 spin_lock_irq(&ice->reg_lock);
2253 for (idx = 0; idx < 22; idx++) {
2254 outb(idx, ICEMT(ice, MONITOR_PEAKINDEX));
2255 ucontrol->value.integer.value[idx] = inb(ICEMT(ice, MONITOR_PEAKDATA));
2256 }
2257 spin_unlock_irq(&ice->reg_lock);
2258 return 0;
2259}
2260
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002261static struct snd_kcontrol_new snd_ice1712_mixer_pro_peak __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2263 .name = "Multi Track Peak",
2264 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2265 .info = snd_ice1712_pro_peak_info,
2266 .get = snd_ice1712_pro_peak_get
2267};
2268
2269/*
2270 *
2271 */
2272
2273/*
2274 * list of available boards
2275 */
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002276static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 snd_ice1712_hoontech_cards,
2278 snd_ice1712_delta_cards,
2279 snd_ice1712_ews_cards,
2280 NULL,
2281};
2282
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002283static unsigned char __devinit snd_ice1712_read_i2c(struct snd_ice1712 *ice,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 unsigned char dev,
2285 unsigned char addr)
2286{
2287 long t = 0x10000;
2288
2289 outb(addr, ICEREG(ice, I2C_BYTE_ADDR));
2290 outb(dev & ~ICE1712_I2C_WRITE, ICEREG(ice, I2C_DEV_ADDR));
2291 while (t-- > 0 && (inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_BUSY)) ;
2292 return inb(ICEREG(ice, I2C_DATA));
2293}
2294
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002295static int __devinit snd_ice1712_read_eeprom(struct snd_ice1712 *ice,
2296 const char *modelname)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297{
2298 int dev = 0xa0; /* EEPROM device address */
2299 unsigned int i, size;
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002300 struct snd_ice1712_card_info * const *tbl, *c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002302 if (!modelname || !*modelname) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 ice->eeprom.subvendor = 0;
2304 if ((inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_EEPROM) != 0)
2305 ice->eeprom.subvendor = (snd_ice1712_read_i2c(ice, dev, 0x00) << 0) |
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002306 (snd_ice1712_read_i2c(ice, dev, 0x01) << 8) |
2307 (snd_ice1712_read_i2c(ice, dev, 0x02) << 16) |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 (snd_ice1712_read_i2c(ice, dev, 0x03) << 24);
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002309 if (ice->eeprom.subvendor == 0 ||
2310 ice->eeprom.subvendor == (unsigned int)-1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 /* invalid subvendor from EEPROM, try the PCI subststem ID instead */
2312 u16 vendor, device;
2313 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID, &vendor);
2314 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
2315 ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device);
2316 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
2317 printk(KERN_ERR "ice1712: No valid ID is found\n");
2318 return -ENXIO;
2319 }
2320 }
2321 }
2322 for (tbl = card_tables; *tbl; tbl++) {
2323 for (c = *tbl; c->subvendor; c++) {
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002324 if (modelname && c->model && !strcmp(modelname, c->model)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 printk(KERN_INFO "ice1712: Using board model %s\n", c->name);
2326 ice->eeprom.subvendor = c->subvendor;
2327 } else if (c->subvendor != ice->eeprom.subvendor)
2328 continue;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002329 if (!c->eeprom_size || !c->eeprom_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 goto found;
2331 /* if the EEPROM is given by the driver, use it */
2332 snd_printdd("using the defined eeprom..\n");
2333 ice->eeprom.version = 1;
2334 ice->eeprom.size = c->eeprom_size + 6;
2335 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
2336 goto read_skipped;
2337 }
2338 }
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002339 printk(KERN_WARNING "ice1712: No matching model found for ID 0x%x\n",
2340 ice->eeprom.subvendor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
2342 found:
2343 ice->eeprom.size = snd_ice1712_read_i2c(ice, dev, 0x04);
2344 if (ice->eeprom.size < 6)
2345 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */
2346 else if (ice->eeprom.size > 32) {
Takashi Iwai99b359b2005-10-20 18:26:44 +02002347 snd_printk(KERN_ERR "invalid EEPROM (size = %i)\n", ice->eeprom.size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 return -EIO;
2349 }
2350 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05);
2351 if (ice->eeprom.version != 1) {
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002352 snd_printk(KERN_ERR "invalid EEPROM version %i\n",
2353 ice->eeprom.version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 /* return -EIO; */
2355 }
2356 size = ice->eeprom.size - 6;
2357 for (i = 0; i < size; i++)
2358 ice->eeprom.data[i] = snd_ice1712_read_i2c(ice, dev, i + 6);
2359
2360 read_skipped:
2361 ice->eeprom.gpiomask = ice->eeprom.data[ICE_EEP1_GPIO_MASK];
2362 ice->eeprom.gpiostate = ice->eeprom.data[ICE_EEP1_GPIO_STATE];
2363 ice->eeprom.gpiodir = ice->eeprom.data[ICE_EEP1_GPIO_DIR];
2364
2365 return 0;
2366}
2367
2368
2369
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002370static int __devinit snd_ice1712_chip_init(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371{
2372 outb(ICE1712_RESET | ICE1712_NATIVE, ICEREG(ice, CONTROL));
2373 udelay(200);
2374 outb(ICE1712_NATIVE, ICEREG(ice, CONTROL));
2375 udelay(200);
Alan Horstmann721b8a22006-05-23 13:29:51 +02002376 if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DMX6FIRE &&
2377 !ice->dxr_enable)
2378 /* Set eeprom value to limit active ADCs and DACs to 6;
2379 * Also disable AC97 as no hardware in standard 6fire card/box
2380 * Note: DXR extensions are not currently supported
2381 */
2382 ice->eeprom.data[ICE_EEP1_CODEC] = 0x3a;
2383 pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 pci_write_config_byte(ice->pci, 0x61, ice->eeprom.data[ICE_EEP1_ACLINK]);
2385 pci_write_config_byte(ice->pci, 0x62, ice->eeprom.data[ICE_EEP1_I2SID]);
2386 pci_write_config_byte(ice->pci, 0x63, ice->eeprom.data[ICE_EEP1_SPDIF]);
2387 if (ice->eeprom.subvendor != ICE1712_SUBDEVICE_STDSP24) {
2388 ice->gpio.write_mask = ice->eeprom.gpiomask;
2389 ice->gpio.direction = ice->eeprom.gpiodir;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002390 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK,
2391 ice->eeprom.gpiomask);
2392 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
2393 ice->eeprom.gpiodir);
2394 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA,
2395 ice->eeprom.gpiostate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 } else {
2397 ice->gpio.write_mask = 0xc0;
2398 ice->gpio.direction = 0xff;
2399 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, 0xc0);
2400 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, 0xff);
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002401 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA,
2402 ICE1712_STDSP24_CLOCK_BIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 }
2404 snd_ice1712_write(ice, ICE1712_IREG_PRO_POWERDOWN, 0);
2405 if (!(ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97)) {
2406 outb(ICE1712_AC97_WARM, ICEREG(ice, AC97_CMD));
2407 udelay(100);
2408 outb(0, ICEREG(ice, AC97_CMD));
2409 udelay(200);
2410 snd_ice1712_write(ice, ICE1712_IREG_CONSUMER_POWERDOWN, 0);
2411 }
2412 snd_ice1712_set_pro_rate(ice, 48000, 1);
2413
2414 return 0;
2415}
2416
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002417int __devinit snd_ice1712_spdif_build_controls(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418{
2419 int err;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002420 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421
Takashi Iwaida3cec32008-08-08 17:12:14 +02002422 if (snd_BUG_ON(!ice->pcm_pro))
2423 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_default, ice));
2425 if (err < 0)
2426 return err;
2427 kctl->id.device = ice->pcm_pro->device;
2428 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskc, ice));
2429 if (err < 0)
2430 return err;
2431 kctl->id.device = ice->pcm_pro->device;
2432 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskp, ice));
2433 if (err < 0)
2434 return err;
2435 kctl->id.device = ice->pcm_pro->device;
2436 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_stream, ice));
2437 if (err < 0)
2438 return err;
2439 kctl->id.device = ice->pcm_pro->device;
2440 ice->spdif.stream_ctl = kctl;
2441 return 0;
2442}
2443
2444
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002445static int __devinit snd_ice1712_build_controls(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446{
2447 int err;
2448
2449 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_eeprom, ice));
2450 if (err < 0)
2451 return err;
2452 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock, ice));
2453 if (err < 0)
2454 return err;
2455 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock_default, ice));
2456 if (err < 0)
2457 return err;
2458
2459 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_locking, ice));
2460 if (err < 0)
2461 return err;
2462 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_reset, ice));
2463 if (err < 0)
2464 return err;
2465
2466 if (ice->num_total_dacs > 0) {
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002467 struct snd_kcontrol_new tmp = snd_ice1712_mixer_pro_analog_route;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 tmp.count = ice->num_total_dacs;
2469 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2470 if (err < 0)
2471 return err;
2472 }
2473
2474 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice));
2475 if (err < 0)
2476 return err;
2477
2478 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
2479 if (err < 0)
2480 return err;
2481 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice));
2482 if (err < 0)
2483 return err;
2484
2485 return 0;
2486}
2487
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002488static int snd_ice1712_free(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489{
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002490 if (!ice->port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 goto __hw_end;
2492 /* mask all interrupts */
2493 outb(0xc0, ICEMT(ice, IRQ));
2494 outb(0xff, ICEREG(ice, IRQMASK));
2495 /* --- */
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002496__hw_end:
Jeff Garzikf000fd82008-04-22 13:50:34 +02002497 if (ice->irq >= 0)
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002498 free_irq(ice->irq, ice);
Jeff Garzikf000fd82008-04-22 13:50:34 +02002499
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 if (ice->port)
2501 pci_release_regions(ice->pci);
2502 snd_ice1712_akm4xxx_free(ice);
2503 pci_disable_device(ice->pci);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +01002504 kfree(ice->spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 kfree(ice);
2506 return 0;
2507}
2508
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002509static int snd_ice1712_dev_free(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002511 struct snd_ice1712 *ice = device->device_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 return snd_ice1712_free(ice);
2513}
2514
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002515static int __devinit snd_ice1712_create(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 struct pci_dev *pci,
2517 const char *modelname,
2518 int omni,
2519 int cs8427_timeout,
Alan Horstmann531af462006-02-08 07:40:33 +01002520 int dxr_enable,
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002521 struct snd_ice1712 **r_ice1712)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002523 struct snd_ice1712 *ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 int err;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002525 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 .dev_free = snd_ice1712_dev_free,
2527 };
2528
2529 *r_ice1712 = NULL;
2530
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002531 /* enable PCI device */
2532 err = pci_enable_device(pci);
2533 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 return err;
2535 /* check, if we can restrict PCI DMA transfers to 28 bits */
Tobias Klauser9d2f9282006-03-22 10:53:19 +01002536 if (pci_set_dma_mask(pci, DMA_28BIT_MASK) < 0 ||
2537 pci_set_consistent_dma_mask(pci, DMA_28BIT_MASK) < 0) {
Takashi Iwai99b359b2005-10-20 18:26:44 +02002538 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 pci_disable_device(pci);
2540 return -ENXIO;
2541 }
2542
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002543 ice = kzalloc(sizeof(*ice), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 if (ice == NULL) {
2545 pci_disable_device(pci);
2546 return -ENOMEM;
2547 }
2548 ice->omni = omni ? 1 : 0;
2549 if (cs8427_timeout < 1)
2550 cs8427_timeout = 1;
2551 else if (cs8427_timeout > 1000)
2552 cs8427_timeout = 1000;
2553 ice->cs8427_timeout = cs8427_timeout;
Alan Horstmann531af462006-02-08 07:40:33 +01002554 ice->dxr_enable = dxr_enable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 spin_lock_init(&ice->reg_lock);
Ingo Molnar62932df2006-01-16 16:34:20 +01002556 mutex_init(&ice->gpio_mutex);
2557 mutex_init(&ice->i2c_mutex);
2558 mutex_init(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 ice->gpio.set_mask = snd_ice1712_set_gpio_mask;
2560 ice->gpio.set_dir = snd_ice1712_set_gpio_dir;
2561 ice->gpio.set_data = snd_ice1712_set_gpio_data;
2562 ice->gpio.get_data = snd_ice1712_get_gpio_data;
2563
2564 ice->spdif.cs8403_bits =
2565 ice->spdif.cs8403_stream_bits = (0x01 | /* consumer format */
2566 0x10 | /* no emphasis */
2567 0x20); /* PCM encoder/decoder */
2568 ice->card = card;
2569 ice->pci = pci;
2570 ice->irq = -1;
2571 pci_set_master(pci);
2572 pci_write_config_word(ice->pci, 0x40, 0x807f);
2573 pci_write_config_word(ice->pci, 0x42, 0x0006);
2574 snd_ice1712_proc_init(ice);
2575 synchronize_irq(pci->irq);
2576
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002577 err = pci_request_regions(pci, "ICE1712");
2578 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 kfree(ice);
2580 pci_disable_device(pci);
2581 return err;
2582 }
2583 ice->port = pci_resource_start(pci, 0);
2584 ice->ddma_port = pci_resource_start(pci, 1);
2585 ice->dmapath_port = pci_resource_start(pci, 2);
2586 ice->profi_port = pci_resource_start(pci, 3);
2587
Takashi Iwai437a5a42006-11-21 12:14:23 +01002588 if (request_irq(pci->irq, snd_ice1712_interrupt, IRQF_SHARED,
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002589 "ICE1712", ice)) {
Takashi Iwai99b359b2005-10-20 18:26:44 +02002590 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 snd_ice1712_free(ice);
2592 return -EIO;
2593 }
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002594
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 ice->irq = pci->irq;
2596
2597 if (snd_ice1712_read_eeprom(ice, modelname) < 0) {
2598 snd_ice1712_free(ice);
2599 return -EIO;
2600 }
2601 if (snd_ice1712_chip_init(ice) < 0) {
2602 snd_ice1712_free(ice);
2603 return -EIO;
2604 }
2605
2606 /* unmask used interrupts */
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002607 outb(((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) == 0 ?
2608 ICE1712_IRQ_MPU2 : 0) |
2609 ((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97) ?
2610 ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 ICEREG(ice, IRQMASK));
2612 outb(0x00, ICEMT(ice, IRQ));
2613
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002614 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops);
2615 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 snd_ice1712_free(ice);
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002617 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 }
2619
2620 snd_card_set_dev(card, &pci->dev);
2621
2622 *r_ice1712 = ice;
2623 return 0;
2624}
2625
2626
2627/*
2628 *
2629 * Registration
2630 *
2631 */
2632
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002633static struct snd_ice1712_card_info no_matched __devinitdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634
2635static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2636 const struct pci_device_id *pci_id)
2637{
2638 static int dev;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002639 struct snd_card *card;
2640 struct snd_ice1712 *ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 int pcm_dev = 0, err;
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002642 struct snd_ice1712_card_info * const *tbl, *c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643
2644 if (dev >= SNDRV_CARDS)
2645 return -ENODEV;
2646 if (!enable[dev]) {
2647 dev++;
2648 return -ENOENT;
2649 }
2650
2651 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2652 if (card == NULL)
2653 return -ENOMEM;
2654
2655 strcpy(card->driver, "ICE1712");
2656 strcpy(card->shortname, "ICEnsemble ICE1712");
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002657
2658 err = snd_ice1712_create(card, pci, model[dev], omni[dev],
2659 cs8427_timeout[dev], dxr_enable[dev], &ice);
2660 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 snd_card_free(card);
2662 return err;
2663 }
2664
2665 for (tbl = card_tables; *tbl; tbl++) {
2666 for (c = *tbl; c->subvendor; c++) {
2667 if (c->subvendor == ice->eeprom.subvendor) {
2668 strcpy(card->shortname, c->name);
2669 if (c->driver) /* specific driver? */
2670 strcpy(card->driver, c->driver);
2671 if (c->chip_init) {
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002672 err = c->chip_init(ice);
2673 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 snd_card_free(card);
2675 return err;
2676 }
2677 }
2678 goto __found;
2679 }
2680 }
2681 }
2682 c = &no_matched;
2683 __found:
2684
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002685 err = snd_ice1712_pcm_profi(ice, pcm_dev++, NULL);
2686 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 snd_card_free(card);
2688 return err;
2689 }
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002690
Ilpo Järvinen8cd2b262008-10-30 13:09:55 +02002691 if (ice_has_con_ac97(ice)) {
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002692 err = snd_ice1712_pcm(ice, pcm_dev++, NULL);
2693 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 snd_card_free(card);
2695 return err;
2696 }
Ilpo Järvinen8cd2b262008-10-30 13:09:55 +02002697 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002699 err = snd_ice1712_ac97_mixer(ice);
2700 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 snd_card_free(card);
2702 return err;
2703 }
2704
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002705 err = snd_ice1712_build_controls(ice);
2706 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 snd_card_free(card);
2708 return err;
2709 }
2710
2711 if (c->build_controls) {
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002712 err = c->build_controls(ice);
2713 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 snd_card_free(card);
2715 return err;
2716 }
2717 }
2718
Ilpo Järvinen8cd2b262008-10-30 13:09:55 +02002719 if (ice_has_con_ac97(ice)) {
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002720 err = snd_ice1712_pcm_ds(ice, pcm_dev++, NULL);
2721 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 snd_card_free(card);
2723 return err;
2724 }
Ilpo Järvinen8cd2b262008-10-30 13:09:55 +02002725 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002727 if (!c->no_mpu401) {
2728 err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2729 ICEREG(ice, MPU1_CTRL),
2730 (c->mpu401_1_info_flags | MPU401_INFO_INTEGRATED),
2731 ice->irq, 0, &ice->rmidi[0]);
2732 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 snd_card_free(card);
2734 return err;
2735 }
Alan Horstmann3bef2292006-04-26 18:13:59 +02002736 if (c->mpu401_1_name)
2737 /* Prefered name available in card_info */
2738 snprintf(ice->rmidi[0]->name,
2739 sizeof(ice->rmidi[0]->name),
2740 "%s %d", c->mpu401_1_name, card->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741
Alan Horstmann3bef2292006-04-26 18:13:59 +02002742 if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) {
2743 /* 2nd port used */
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002744 err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712,
2745 ICEREG(ice, MPU2_CTRL),
2746 (c->mpu401_2_info_flags | MPU401_INFO_INTEGRATED),
2747 ice->irq, 0, &ice->rmidi[1]);
2748
2749 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 snd_card_free(card);
2751 return err;
2752 }
Alan Horstmann3bef2292006-04-26 18:13:59 +02002753 if (c->mpu401_2_name)
2754 /* Prefered name available in card_info */
2755 snprintf(ice->rmidi[1]->name,
2756 sizeof(ice->rmidi[1]->name),
2757 "%s %d", c->mpu401_2_name,
2758 card->number);
2759 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 }
2761
Jaroslav Kyselae957ebf2006-02-02 07:56:54 +01002762 snd_ice1712_set_input_clock_source(ice, 0);
2763
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 sprintf(card->longname, "%s at 0x%lx, irq %i",
2765 card->shortname, ice->port, ice->irq);
2766
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002767 err = snd_card_register(card);
2768 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 snd_card_free(card);
2770 return err;
2771 }
2772 pci_set_drvdata(pci, card);
2773 dev++;
2774 return 0;
2775}
2776
2777static void __devexit snd_ice1712_remove(struct pci_dev *pci)
2778{
2779 snd_card_free(pci_get_drvdata(pci));
2780 pci_set_drvdata(pci, NULL);
2781}
2782
2783static struct pci_driver driver = {
2784 .name = "ICE1712",
2785 .id_table = snd_ice1712_ids,
2786 .probe = snd_ice1712_probe,
2787 .remove = __devexit_p(snd_ice1712_remove),
2788};
2789
2790static int __init alsa_card_ice1712_init(void)
2791{
Takashi Iwai01d25d42005-04-11 16:58:24 +02002792 return pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793}
2794
2795static void __exit alsa_card_ice1712_exit(void)
2796{
2797 pci_unregister_driver(&driver);
2798}
2799
2800module_init(alsa_card_ice1712_init)
2801module_exit(alsa_card_ice1712_exit)