blob: 206ed2cbcef9024a13f7a859bebfe53a8050f7f8 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <linux/delay.h>
51#include <linux/interrupt.h>
52#include <linux/init.h>
53#include <linux/pci.h>
Tobias Klauser9d2f9282006-03-22 10:53:19 +010054#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <linux/slab.h>
Paul Gortmaker65a77212011-07-15 13:13:37 -040056#include <linux/module.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010057#include <linux/mutex.h>
Matthias Gehre910638a2006-03-28 01:56:48 -080058
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#include <sound/core.h>
60#include <sound/cs8427.h>
61#include <sound/info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#include <sound/initval.h>
Takashi Iwai680ef792006-08-30 16:56:30 +020063#include <sound/tlv.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65#include <sound/asoundef.h>
66
67#include "ice1712.h"
68
69/* lowlevel routines */
70#include "delta.h"
71#include "ews.h"
72#include "hoontech.h"
73
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020074MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070075MODULE_DESCRIPTION("ICEnsemble ICE1712 (Envy24)");
76MODULE_LICENSE("GPL");
77MODULE_SUPPORTED_DEVICE("{"
78 HOONTECH_DEVICE_DESC
79 DELTA_DEVICE_DESC
80 EWS_DEVICE_DESC
81 "{ICEnsemble,Generic ICE1712},"
82 "{ICEnsemble,Generic Envy24}}");
83
84static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
85static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
Rusty Russella67ff6a2011-12-15 13:49:36 +103086static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static char *model[SNDRV_CARDS];
Rusty Russella67ff6a2011-12-15 13:49:36 +103088static bool omni[SNDRV_CARDS]; /* Delta44 & 66 Omni I/O support */
Joe Perches7c9d4402011-06-23 11:39:20 -070089static int cs8427_timeout[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 500}; /* CS8427 S/PDIF transceiver reset timeout value in msec */
Alan Horstmann01a00e52006-03-21 09:57:36 +010090static int dxr_enable[SNDRV_CARDS]; /* DXR enable for DMX6FIRE */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92module_param_array(index, int, NULL, 0444);
93MODULE_PARM_DESC(index, "Index value for ICE1712 soundcard.");
94module_param_array(id, charp, NULL, 0444);
95MODULE_PARM_DESC(id, "ID string for ICE1712 soundcard.");
96module_param_array(enable, bool, NULL, 0444);
97MODULE_PARM_DESC(enable, "Enable ICE1712 soundcard.");
98module_param_array(omni, bool, NULL, 0444);
99MODULE_PARM_DESC(omni, "Enable Midiman M-Audio Delta Omni I/O support.");
100module_param_array(cs8427_timeout, int, NULL, 0444);
101MODULE_PARM_DESC(cs8427_timeout, "Define reset timeout for cs8427 chip in msec resolution.");
102module_param_array(model, charp, NULL, 0444);
103MODULE_PARM_DESC(model, "Use the given board model.");
Alan Horstmann531af462006-02-08 07:40:33 +0100104module_param_array(dxr_enable, int, NULL, 0444);
Alan Horstmann01a00e52006-03-21 09:57:36 +0100105MODULE_PARM_DESC(dxr_enable, "Enable DXR support for Terratec DMX6FIRE.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Benoit Taine9baa3c32014-08-08 15:56:03 +0200108static const struct pci_device_id snd_ice1712_ids[] = {
Joe Perches28d27aa2009-06-24 22:13:35 -0700109 { PCI_VDEVICE(ICE, PCI_DEVICE_ID_ICE_1712), 0 }, /* ICE1712 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 { 0, }
111};
112
113MODULE_DEVICE_TABLE(pci, snd_ice1712_ids);
114
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100115static int snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice);
116static int snd_ice1712_build_controls(struct snd_ice1712 *ice);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118static int PRO_RATE_LOCKED;
119static int PRO_RATE_RESET = 1;
120static unsigned int PRO_RATE_DEFAULT = 44100;
121
122/*
123 * Basic I/O
124 */
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126/* check whether the clock mode is spdif-in */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100127static inline int is_spdif_master(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
129 return (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER) ? 1 : 0;
130}
131
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100132static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
134 return is_spdif_master(ice) || PRO_RATE_LOCKED;
135}
136
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400137static inline void snd_ice1712_ds_write(struct snd_ice1712 *ice, u8 channel, u8 addr, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
139 outb((channel << 4) | addr, ICEDS(ice, INDEX));
140 outl(data, ICEDS(ice, DATA));
141}
142
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400143static inline u32 snd_ice1712_ds_read(struct snd_ice1712 *ice, u8 channel, u8 addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
145 outb((channel << 4) | addr, ICEDS(ice, INDEX));
146 return inl(ICEDS(ice, DATA));
147}
148
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100149static void snd_ice1712_ac97_write(struct snd_ac97 *ac97,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 unsigned short reg,
151 unsigned short val)
152{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100153 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 int tm;
155 unsigned char old_cmd = 0;
156
157 for (tm = 0; tm < 0x10000; tm++) {
158 old_cmd = inb(ICEREG(ice, AC97_CMD));
159 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
160 continue;
161 if (!(old_cmd & ICE1712_AC97_READY))
162 continue;
163 break;
164 }
165 outb(reg, ICEREG(ice, AC97_INDEX));
166 outw(val, ICEREG(ice, AC97_DATA));
167 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
168 outb(old_cmd | ICE1712_AC97_WRITE, ICEREG(ice, AC97_CMD));
169 for (tm = 0; tm < 0x10000; tm++)
170 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
171 break;
172}
173
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100174static unsigned short snd_ice1712_ac97_read(struct snd_ac97 *ac97,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 unsigned short reg)
176{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100177 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 int tm;
179 unsigned char old_cmd = 0;
180
181 for (tm = 0; tm < 0x10000; tm++) {
182 old_cmd = inb(ICEREG(ice, AC97_CMD));
183 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
184 continue;
185 if (!(old_cmd & ICE1712_AC97_READY))
186 continue;
187 break;
188 }
189 outb(reg, ICEREG(ice, AC97_INDEX));
190 outb(old_cmd | ICE1712_AC97_READ, ICEREG(ice, AC97_CMD));
191 for (tm = 0; tm < 0x10000; tm++)
192 if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
193 break;
194 if (tm >= 0x10000) /* timeout */
195 return ~0;
196 return inw(ICEREG(ice, AC97_DATA));
197}
198
199/*
200 * pro ac97 section
201 */
202
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100203static void snd_ice1712_pro_ac97_write(struct snd_ac97 *ac97,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 unsigned short reg,
205 unsigned short val)
206{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100207 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 int tm;
209 unsigned char old_cmd = 0;
210
211 for (tm = 0; tm < 0x10000; tm++) {
212 old_cmd = inb(ICEMT(ice, AC97_CMD));
213 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
214 continue;
215 if (!(old_cmd & ICE1712_AC97_READY))
216 continue;
217 break;
218 }
219 outb(reg, ICEMT(ice, AC97_INDEX));
220 outw(val, ICEMT(ice, AC97_DATA));
221 old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
222 outb(old_cmd | ICE1712_AC97_WRITE, ICEMT(ice, AC97_CMD));
223 for (tm = 0; tm < 0x10000; tm++)
224 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
225 break;
226}
227
228
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100229static unsigned short snd_ice1712_pro_ac97_read(struct snd_ac97 *ac97,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 unsigned short reg)
231{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100232 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 int tm;
234 unsigned char old_cmd = 0;
235
236 for (tm = 0; tm < 0x10000; tm++) {
237 old_cmd = inb(ICEMT(ice, AC97_CMD));
238 if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
239 continue;
240 if (!(old_cmd & ICE1712_AC97_READY))
241 continue;
242 break;
243 }
244 outb(reg, ICEMT(ice, AC97_INDEX));
245 outb(old_cmd | ICE1712_AC97_READ, ICEMT(ice, AC97_CMD));
246 for (tm = 0; tm < 0x10000; tm++)
247 if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
248 break;
249 if (tm >= 0x10000) /* timeout */
250 return ~0;
251 return inw(ICEMT(ice, AC97_DATA));
252}
253
254/*
255 * consumer ac97 digital mix
256 */
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200257#define snd_ice1712_digmix_route_ac97_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100259static int snd_ice1712_digmix_route_ac97_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100261 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0;
264 return 0;
265}
266
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100267static int snd_ice1712_digmix_route_ac97_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100269 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 unsigned char val, nval;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 spin_lock_irq(&ice->reg_lock);
273 val = inb(ICEMT(ice, MONITOR_ROUTECTRL));
274 nval = val & ~ICE1712_ROUTE_AC97;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400275 if (ucontrol->value.integer.value[0])
276 nval |= ICE1712_ROUTE_AC97;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 outb(nval, ICEMT(ice, MONITOR_ROUTECTRL));
278 spin_unlock_irq(&ice->reg_lock);
279 return val != nval;
280}
281
Bill Pembertone23e7a12012-12-06 12:35:10 -0500282static struct snd_kcontrol_new snd_ice1712_mixer_digmix_route_ac97 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
284 .name = "Digital Mixer To AC97",
285 .info = snd_ice1712_digmix_route_ac97_info,
286 .get = snd_ice1712_digmix_route_ac97_get,
287 .put = snd_ice1712_digmix_route_ac97_put,
288};
289
290
291/*
292 * gpio operations
293 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100294static void snd_ice1712_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
296 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, data);
297 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
298}
299
Pavel Hofman49470302009-09-16 22:25:38 +0200300static unsigned int snd_ice1712_get_gpio_dir(struct snd_ice1712 *ice)
301{
302 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DIRECTION);
303}
304
305static unsigned int snd_ice1712_get_gpio_mask(struct snd_ice1712 *ice)
306{
307 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_WRITE_MASK);
308}
309
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100310static void snd_ice1712_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
312 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data);
313 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
314}
315
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100316static unsigned int snd_ice1712_get_gpio_data(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
318 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
319}
320
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100321static void snd_ice1712_set_gpio_data(struct snd_ice1712 *ice, unsigned int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
323 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, val);
324 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
325}
326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327/*
328 *
329 * CS8427 interface
330 *
331 */
332
333/*
334 * change the input clock selection
335 * spdif_clock = 1 - IEC958 input, 0 - Envy24
336 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100337static int snd_ice1712_cs8427_set_input_clock(struct snd_ice1712 *ice, int spdif_clock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
339 unsigned char reg[2] = { 0x80 | 4, 0 }; /* CS8427 auto increment | register number 4 + data */
340 unsigned char val, nval;
341 int res = 0;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 snd_i2c_lock(ice->i2c);
344 if (snd_i2c_sendbytes(ice->cs8427, reg, 1) != 1) {
345 snd_i2c_unlock(ice->i2c);
346 return -EIO;
347 }
348 if (snd_i2c_readbytes(ice->cs8427, &val, 1) != 1) {
349 snd_i2c_unlock(ice->i2c);
350 return -EIO;
351 }
352 nval = val & 0xf0;
353 if (spdif_clock)
354 nval |= 0x01;
355 else
356 nval |= 0x04;
357 if (val != nval) {
358 reg[1] = nval;
359 if (snd_i2c_sendbytes(ice->cs8427, reg, 2) != 2) {
360 res = -EIO;
361 } else {
362 res++;
363 }
364 }
365 snd_i2c_unlock(ice->i2c);
366 return res;
367}
368
369/*
370 * spdif callbacks
371 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100372static void open_cs8427(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
374 snd_cs8427_iec958_active(ice->cs8427, 1);
375}
376
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100377static void close_cs8427(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
379 snd_cs8427_iec958_active(ice->cs8427, 0);
380}
381
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100382static void setup_cs8427(struct snd_ice1712 *ice, int rate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383{
384 snd_cs8427_iec958_pcm(ice->cs8427, rate);
385}
386
387/*
388 * create and initialize callbacks for cs8427 interface
389 */
Bill Pembertone23e7a12012-12-06 12:35:10 -0500390int snd_ice1712_init_cs8427(struct snd_ice1712 *ice, int addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391{
392 int err;
393
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400394 err = snd_cs8427_create(ice->i2c, addr,
395 (ice->cs8427_timeout * HZ) / 1000, &ice->cs8427);
396 if (err < 0) {
Takashi Iwai6dfb5af2014-02-25 17:16:16 +0100397 dev_err(ice->card->dev, "CS8427 initialization failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 return err;
399 }
400 ice->spdif.ops.open = open_cs8427;
401 ice->spdif.ops.close = close_cs8427;
402 ice->spdif.ops.setup_rate = setup_cs8427;
403 return 0;
404}
405
Jaroslav Kyselae957ebf2006-02-02 07:56:54 +0100406static void snd_ice1712_set_input_clock_source(struct snd_ice1712 *ice, int spdif_is_master)
407{
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400408 /* change CS8427 clock source too */
409 if (ice->cs8427)
410 snd_ice1712_cs8427_set_input_clock(ice, spdif_is_master);
Jaroslav Kyselae957ebf2006-02-02 07:56:54 +0100411 /* notify ak4524 chip as well */
412 if (spdif_is_master) {
413 unsigned int i;
414 for (i = 0; i < ice->akm_codecs; i++) {
415 if (ice->akm[i].ops.set_rate_val)
416 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
417 }
418 }
419}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421/*
422 * Interrupt handler
423 */
424
David Howells7d12e782006-10-05 14:55:46 +0100425static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100427 struct snd_ice1712 *ice = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 unsigned char status;
429 int handled = 0;
430
431 while (1) {
432 status = inb(ICEREG(ice, IRQSTAT));
433 if (status == 0)
434 break;
435 handled = 1;
436 if (status & ICE1712_IRQ_MPU1) {
437 if (ice->rmidi[0])
David Howells7d12e782006-10-05 14:55:46 +0100438 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 outb(ICE1712_IRQ_MPU1, ICEREG(ice, IRQSTAT));
440 status &= ~ICE1712_IRQ_MPU1;
441 }
442 if (status & ICE1712_IRQ_TIMER)
443 outb(ICE1712_IRQ_TIMER, ICEREG(ice, IRQSTAT));
444 if (status & ICE1712_IRQ_MPU2) {
445 if (ice->rmidi[1])
David Howells7d12e782006-10-05 14:55:46 +0100446 snd_mpu401_uart_interrupt(irq, ice->rmidi[1]->private_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 outb(ICE1712_IRQ_MPU2, ICEREG(ice, IRQSTAT));
448 status &= ~ICE1712_IRQ_MPU2;
449 }
450 if (status & ICE1712_IRQ_PROPCM) {
451 unsigned char mtstat = inb(ICEMT(ice, IRQ));
452 if (mtstat & ICE1712_MULTI_PBKSTATUS) {
453 if (ice->playback_pro_substream)
454 snd_pcm_period_elapsed(ice->playback_pro_substream);
455 outb(ICE1712_MULTI_PBKSTATUS, ICEMT(ice, IRQ));
456 }
457 if (mtstat & ICE1712_MULTI_CAPSTATUS) {
458 if (ice->capture_pro_substream)
459 snd_pcm_period_elapsed(ice->capture_pro_substream);
460 outb(ICE1712_MULTI_CAPSTATUS, ICEMT(ice, IRQ));
461 }
462 }
463 if (status & ICE1712_IRQ_FM)
464 outb(ICE1712_IRQ_FM, ICEREG(ice, IRQSTAT));
465 if (status & ICE1712_IRQ_PBKDS) {
466 u32 idx;
467 u16 pbkstatus;
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100468 struct snd_pcm_substream *substream;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 pbkstatus = inw(ICEDS(ice, INTSTAT));
Takashi Iwai6dfb5af2014-02-25 17:16:16 +0100470 /* dev_dbg(ice->card->dev, "pbkstatus = 0x%x\n", pbkstatus); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 for (idx = 0; idx < 6; idx++) {
472 if ((pbkstatus & (3 << (idx * 2))) == 0)
473 continue;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400474 substream = ice->playback_con_substream_ds[idx];
475 if (substream != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 snd_pcm_period_elapsed(substream);
477 outw(3 << (idx * 2), ICEDS(ice, INTSTAT));
478 }
479 outb(ICE1712_IRQ_PBKDS, ICEREG(ice, IRQSTAT));
480 }
481 if (status & ICE1712_IRQ_CONCAP) {
482 if (ice->capture_con_substream)
483 snd_pcm_period_elapsed(ice->capture_con_substream);
484 outb(ICE1712_IRQ_CONCAP, ICEREG(ice, IRQSTAT));
485 }
486 if (status & ICE1712_IRQ_CONPBK) {
487 if (ice->playback_con_substream)
488 snd_pcm_period_elapsed(ice->playback_con_substream);
489 outb(ICE1712_IRQ_CONPBK, ICEREG(ice, IRQSTAT));
490 }
491 }
492 return IRQ_RETVAL(handled);
493}
494
495
496/*
497 * PCM part - misc
498 */
499
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100500static int snd_ice1712_hw_params(struct snd_pcm_substream *substream,
501 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502{
503 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
504}
505
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100506static int snd_ice1712_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
508 return snd_pcm_lib_free_pages(substream);
509}
510
511/*
512 * PCM part - consumer I/O
513 */
514
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100515static int snd_ice1712_playback_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 int cmd)
517{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100518 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 int result = 0;
520 u32 tmp;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 spin_lock(&ice->reg_lock);
523 tmp = snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL);
524 if (cmd == SNDRV_PCM_TRIGGER_START) {
525 tmp |= 1;
526 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
527 tmp &= ~1;
528 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
529 tmp |= 2;
530 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
531 tmp &= ~2;
532 } else {
533 result = -EINVAL;
534 }
535 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
536 spin_unlock(&ice->reg_lock);
537 return result;
538}
539
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100540static int snd_ice1712_playback_ds_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 int cmd)
542{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100543 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 int result = 0;
545 u32 tmp;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 spin_lock(&ice->reg_lock);
548 tmp = snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL);
549 if (cmd == SNDRV_PCM_TRIGGER_START) {
550 tmp |= 1;
551 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
552 tmp &= ~1;
553 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
554 tmp |= 2;
555 } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
556 tmp &= ~2;
557 } else {
558 result = -EINVAL;
559 }
560 snd_ice1712_ds_write(ice, substream->number * 2, ICE1712_DSC_CONTROL, tmp);
561 spin_unlock(&ice->reg_lock);
562 return result;
563}
564
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100565static int snd_ice1712_capture_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 int cmd)
567{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100568 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 int result = 0;
570 u8 tmp;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 spin_lock(&ice->reg_lock);
573 tmp = snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL);
574 if (cmd == SNDRV_PCM_TRIGGER_START) {
575 tmp |= 1;
576 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
577 tmp &= ~1;
578 } else {
579 result = -EINVAL;
580 }
581 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
582 spin_unlock(&ice->reg_lock);
583 return result;
584}
585
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100586static int snd_ice1712_playback_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100588 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
589 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 u32 period_size, buf_size, rate, tmp;
591
592 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
593 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
594 tmp = 0x0000;
595 if (snd_pcm_format_width(runtime->format) == 16)
596 tmp |= 0x10;
597 if (runtime->channels == 2)
598 tmp |= 0x08;
599 rate = (runtime->rate * 8192) / 375;
600 if (rate > 0x000fffff)
601 rate = 0x000fffff;
602 spin_lock_irq(&ice->reg_lock);
603 outb(0, ice->ddma_port + 15);
604 outb(ICE1712_DMA_MODE_WRITE | ICE1712_DMA_AUTOINIT, ice->ddma_port + 0x0b);
605 outl(runtime->dma_addr, ice->ddma_port + 0);
606 outw(buf_size, ice->ddma_port + 4);
607 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_LO, rate & 0xff);
608 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_MID, (rate >> 8) & 0xff);
609 snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_HI, (rate >> 16) & 0xff);
610 snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
611 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_LO, period_size & 0xff);
612 snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_HI, period_size >> 8);
613 snd_ice1712_write(ice, ICE1712_IREG_PBK_LEFT, 0);
614 snd_ice1712_write(ice, ICE1712_IREG_PBK_RIGHT, 0);
615 spin_unlock_irq(&ice->reg_lock);
616 return 0;
617}
618
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100619static int snd_ice1712_playback_ds_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100621 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
622 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 u32 period_size, buf_size, rate, tmp, chn;
624
625 period_size = snd_pcm_lib_period_bytes(substream) - 1;
626 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
627 tmp = 0x0064;
628 if (snd_pcm_format_width(runtime->format) == 16)
629 tmp &= ~0x04;
630 if (runtime->channels == 2)
631 tmp |= 0x08;
632 rate = (runtime->rate * 8192) / 375;
633 if (rate > 0x000fffff)
634 rate = 0x000fffff;
635 ice->playback_con_active_buf[substream->number] = 0;
636 ice->playback_con_virt_addr[substream->number] = runtime->dma_addr;
637 chn = substream->number * 2;
638 spin_lock_irq(&ice->reg_lock);
639 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR0, runtime->dma_addr);
640 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT0, period_size);
641 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR1, runtime->dma_addr + (runtime->periods > 1 ? period_size + 1 : 0));
642 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT1, period_size);
643 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_RATE, rate);
644 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_VOLUME, 0);
645 snd_ice1712_ds_write(ice, chn, ICE1712_DSC_CONTROL, tmp);
646 if (runtime->channels == 2) {
647 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_RATE, rate);
648 snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_VOLUME, 0);
649 }
650 spin_unlock_irq(&ice->reg_lock);
651 return 0;
652}
653
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100654static int snd_ice1712_capture_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100656 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
657 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 u32 period_size, buf_size;
659 u8 tmp;
660
661 period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
662 buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
663 tmp = 0x06;
664 if (snd_pcm_format_width(runtime->format) == 16)
665 tmp &= ~0x04;
666 if (runtime->channels == 2)
667 tmp &= ~0x02;
668 spin_lock_irq(&ice->reg_lock);
669 outl(ice->capture_con_virt_addr = runtime->dma_addr, ICEREG(ice, CONCAP_ADDR));
670 outw(buf_size, ICEREG(ice, CONCAP_COUNT));
671 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_HI, period_size >> 8);
672 snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_LO, period_size & 0xff);
673 snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
674 spin_unlock_irq(&ice->reg_lock);
675 snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
676 return 0;
677}
678
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100679static snd_pcm_uframes_t snd_ice1712_playback_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100681 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
682 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 size_t ptr;
684
685 if (!(snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL) & 1))
686 return 0;
687 ptr = runtime->buffer_size - inw(ice->ddma_port + 4);
Takashi Iwai4f8e9402014-04-08 16:58:34 +0200688 ptr = bytes_to_frames(substream->runtime, ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 if (ptr == runtime->buffer_size)
690 ptr = 0;
Takashi Iwai4f8e9402014-04-08 16:58:34 +0200691 return ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692}
693
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100694static snd_pcm_uframes_t snd_ice1712_playback_ds_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100696 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 u8 addr;
698 size_t ptr;
699
700 if (!(snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL) & 1))
701 return 0;
702 if (ice->playback_con_active_buf[substream->number])
703 addr = ICE1712_DSC_ADDR1;
704 else
705 addr = ICE1712_DSC_ADDR0;
706 ptr = snd_ice1712_ds_read(ice, substream->number * 2, addr) -
707 ice->playback_con_virt_addr[substream->number];
Takashi Iwai4f8e9402014-04-08 16:58:34 +0200708 ptr = bytes_to_frames(substream->runtime, ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 if (ptr == substream->runtime->buffer_size)
710 ptr = 0;
Takashi Iwai4f8e9402014-04-08 16:58:34 +0200711 return ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712}
713
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100714static snd_pcm_uframes_t snd_ice1712_capture_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100716 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 size_t ptr;
718
719 if (!(snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL) & 1))
720 return 0;
721 ptr = inl(ICEREG(ice, CONCAP_ADDR)) - ice->capture_con_virt_addr;
Takashi Iwai4f8e9402014-04-08 16:58:34 +0200722 ptr = bytes_to_frames(substream->runtime, ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 if (ptr == substream->runtime->buffer_size)
724 ptr = 0;
Takashi Iwai4f8e9402014-04-08 16:58:34 +0200725 return ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726}
727
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400728static const struct snd_pcm_hardware snd_ice1712_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
730 SNDRV_PCM_INFO_BLOCK_TRANSFER |
731 SNDRV_PCM_INFO_MMAP_VALID |
732 SNDRV_PCM_INFO_PAUSE),
733 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
734 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
735 .rate_min = 4000,
736 .rate_max = 48000,
737 .channels_min = 1,
738 .channels_max = 2,
739 .buffer_bytes_max = (64*1024),
740 .period_bytes_min = 64,
741 .period_bytes_max = (64*1024),
742 .periods_min = 1,
743 .periods_max = 1024,
744 .fifo_size = 0,
745};
746
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400747static const struct snd_pcm_hardware snd_ice1712_playback_ds = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
749 SNDRV_PCM_INFO_BLOCK_TRANSFER |
750 SNDRV_PCM_INFO_MMAP_VALID |
751 SNDRV_PCM_INFO_PAUSE),
752 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
753 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
754 .rate_min = 4000,
755 .rate_max = 48000,
756 .channels_min = 1,
757 .channels_max = 2,
758 .buffer_bytes_max = (128*1024),
759 .period_bytes_min = 64,
760 .period_bytes_max = (128*1024),
761 .periods_min = 2,
762 .periods_max = 2,
763 .fifo_size = 0,
764};
765
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400766static const struct snd_pcm_hardware snd_ice1712_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
768 SNDRV_PCM_INFO_BLOCK_TRANSFER |
769 SNDRV_PCM_INFO_MMAP_VALID),
770 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
771 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
772 .rate_min = 4000,
773 .rate_max = 48000,
774 .channels_min = 1,
775 .channels_max = 2,
776 .buffer_bytes_max = (64*1024),
777 .period_bytes_min = 64,
778 .period_bytes_max = (64*1024),
779 .periods_min = 1,
780 .periods_max = 1024,
781 .fifo_size = 0,
782};
783
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100784static int snd_ice1712_playback_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100786 struct snd_pcm_runtime *runtime = substream->runtime;
787 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
789 ice->playback_con_substream = substream;
790 runtime->hw = snd_ice1712_playback;
791 return 0;
792}
793
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100794static int snd_ice1712_playback_ds_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100796 struct snd_pcm_runtime *runtime = substream->runtime;
797 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 u32 tmp;
799
800 ice->playback_con_substream_ds[substream->number] = substream;
801 runtime->hw = snd_ice1712_playback_ds;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400802 spin_lock_irq(&ice->reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2));
804 outw(tmp, ICEDS(ice, INTMASK));
805 spin_unlock_irq(&ice->reg_lock);
806 return 0;
807}
808
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100809static int snd_ice1712_capture_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100811 struct snd_pcm_runtime *runtime = substream->runtime;
812 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 ice->capture_con_substream = substream;
815 runtime->hw = snd_ice1712_capture;
816 runtime->hw.rates = ice->ac97->rates[AC97_RATES_ADC];
817 if (!(runtime->hw.rates & SNDRV_PCM_RATE_8000))
818 runtime->hw.rate_min = 48000;
819 return 0;
820}
821
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100822static int snd_ice1712_playback_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100824 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 ice->playback_con_substream = NULL;
827 return 0;
828}
829
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100830static int snd_ice1712_playback_ds_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100832 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 u32 tmp;
834
Alexander Beregalov3d8cb462008-09-07 14:17:02 +0400835 spin_lock_irq(&ice->reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2));
837 outw(tmp, ICEDS(ice, INTMASK));
838 spin_unlock_irq(&ice->reg_lock);
839 ice->playback_con_substream_ds[substream->number] = NULL;
840 return 0;
841}
842
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100843static int snd_ice1712_capture_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100845 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
847 ice->capture_con_substream = NULL;
848 return 0;
849}
850
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100851static struct snd_pcm_ops snd_ice1712_playback_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 .open = snd_ice1712_playback_open,
853 .close = snd_ice1712_playback_close,
854 .ioctl = snd_pcm_lib_ioctl,
855 .hw_params = snd_ice1712_hw_params,
856 .hw_free = snd_ice1712_hw_free,
857 .prepare = snd_ice1712_playback_prepare,
858 .trigger = snd_ice1712_playback_trigger,
859 .pointer = snd_ice1712_playback_pointer,
860};
861
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100862static struct snd_pcm_ops snd_ice1712_playback_ds_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 .open = snd_ice1712_playback_ds_open,
864 .close = snd_ice1712_playback_ds_close,
865 .ioctl = snd_pcm_lib_ioctl,
866 .hw_params = snd_ice1712_hw_params,
867 .hw_free = snd_ice1712_hw_free,
868 .prepare = snd_ice1712_playback_ds_prepare,
869 .trigger = snd_ice1712_playback_ds_trigger,
870 .pointer = snd_ice1712_playback_ds_pointer,
871};
872
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100873static struct snd_pcm_ops snd_ice1712_capture_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 .open = snd_ice1712_capture_open,
875 .close = snd_ice1712_capture_close,
876 .ioctl = snd_pcm_lib_ioctl,
877 .hw_params = snd_ice1712_hw_params,
878 .hw_free = snd_ice1712_hw_free,
879 .prepare = snd_ice1712_capture_prepare,
880 .trigger = snd_ice1712_capture_trigger,
881 .pointer = snd_ice1712_capture_pointer,
882};
883
Bill Pembertone23e7a12012-12-06 12:35:10 -0500884static int snd_ice1712_pcm(struct snd_ice1712 *ice, int device, struct snd_pcm **rpcm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100886 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 int err;
888
889 if (rpcm)
890 *rpcm = NULL;
891 err = snd_pcm_new(ice->card, "ICE1712 consumer", device, 1, 1, &pcm);
892 if (err < 0)
893 return err;
894
895 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ops);
896 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_ops);
897
898 pcm->private_data = ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 pcm->info_flags = 0;
900 strcpy(pcm->name, "ICE1712 consumer");
901 ice->pcm = pcm;
902
903 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
904 snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
905
906 if (rpcm)
907 *rpcm = pcm;
908
Takashi Iwai6dfb5af2014-02-25 17:16:16 +0100909 dev_warn(ice->card->dev,
910 "Consumer PCM code does not work well at the moment --jk\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912 return 0;
913}
914
Bill Pembertone23e7a12012-12-06 12:35:10 -0500915static int snd_ice1712_pcm_ds(struct snd_ice1712 *ice, int device, struct snd_pcm **rpcm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100917 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 int err;
919
920 if (rpcm)
921 *rpcm = NULL;
922 err = snd_pcm_new(ice->card, "ICE1712 consumer (DS)", device, 6, 0, &pcm);
923 if (err < 0)
924 return err;
925
926 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ds_ops);
927
928 pcm->private_data = ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 pcm->info_flags = 0;
930 strcpy(pcm->name, "ICE1712 consumer (DS)");
931 ice->pcm_ds = pcm;
932
933 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
934 snd_dma_pci_data(ice->pci), 64*1024, 128*1024);
935
936 if (rpcm)
937 *rpcm = pcm;
938
939 return 0;
940}
941
942/*
943 * PCM code - professional part (multitrack)
944 */
945
946static unsigned int rates[] = { 8000, 9600, 11025, 12000, 16000, 22050, 24000,
947 32000, 44100, 48000, 64000, 88200, 96000 };
948
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100949static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 .count = ARRAY_SIZE(rates),
951 .list = rates,
952 .mask = 0,
953};
954
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100955static int snd_ice1712_pro_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 int cmd)
957{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100958 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 switch (cmd) {
960 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
961 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
962 {
963 unsigned int what;
964 unsigned int old;
965 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
966 return -EINVAL;
967 what = ICE1712_PLAYBACK_PAUSE;
968 snd_pcm_trigger_done(substream, substream);
969 spin_lock(&ice->reg_lock);
970 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
971 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
972 old |= what;
973 else
974 old &= ~what;
975 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
976 spin_unlock(&ice->reg_lock);
977 break;
978 }
979 case SNDRV_PCM_TRIGGER_START:
980 case SNDRV_PCM_TRIGGER_STOP:
981 {
982 unsigned int what = 0;
983 unsigned int old;
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100984 struct snd_pcm_substream *s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
Takashi Iwaief991b92007-02-22 12:52:53 +0100986 snd_pcm_group_for_each_entry(s, substream) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 if (s == ice->playback_pro_substream) {
988 what |= ICE1712_PLAYBACK_START;
989 snd_pcm_trigger_done(s, substream);
990 } else if (s == ice->capture_pro_substream) {
991 what |= ICE1712_CAPTURE_START_SHADOW;
992 snd_pcm_trigger_done(s, substream);
993 }
994 }
995 spin_lock(&ice->reg_lock);
996 old = inl(ICEMT(ice, PLAYBACK_CONTROL));
997 if (cmd == SNDRV_PCM_TRIGGER_START)
998 old |= what;
999 else
1000 old &= ~what;
1001 outl(old, ICEMT(ice, PLAYBACK_CONTROL));
1002 spin_unlock(&ice->reg_lock);
1003 break;
1004 }
1005 default:
1006 return -EINVAL;
1007 }
1008 return 0;
1009}
1010
1011/*
1012 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001013static void snd_ice1712_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate, int force)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014{
1015 unsigned long flags;
1016 unsigned char val, old;
1017 unsigned int i;
1018
1019 switch (rate) {
1020 case 8000: val = 6; break;
1021 case 9600: val = 3; break;
1022 case 11025: val = 10; break;
1023 case 12000: val = 2; break;
1024 case 16000: val = 5; break;
1025 case 22050: val = 9; break;
1026 case 24000: val = 1; break;
1027 case 32000: val = 4; break;
1028 case 44100: val = 8; break;
1029 case 48000: val = 0; break;
1030 case 64000: val = 15; break;
1031 case 88200: val = 11; break;
1032 case 96000: val = 7; break;
1033 default:
1034 snd_BUG();
1035 val = 0;
1036 rate = 48000;
1037 break;
1038 }
1039
1040 spin_lock_irqsave(&ice->reg_lock, flags);
1041 if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
1042 ICE1712_PLAYBACK_PAUSE|
1043 ICE1712_PLAYBACK_START)) {
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001044__out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 spin_unlock_irqrestore(&ice->reg_lock, flags);
1046 return;
1047 }
1048 if (!force && is_pro_rate_locked(ice))
1049 goto __out;
1050
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001051 old = inb(ICEMT(ice, RATE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 if (!force && old == val)
1053 goto __out;
Ondrej Zary6ea0cae2014-04-03 23:09:38 +02001054
1055 ice->cur_rate = rate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 outb(val, ICEMT(ice, RATE));
1057 spin_unlock_irqrestore(&ice->reg_lock, flags);
1058
1059 if (ice->gpio.set_pro_rate)
1060 ice->gpio.set_pro_rate(ice, rate);
1061 for (i = 0; i < ice->akm_codecs; i++) {
1062 if (ice->akm[i].ops.set_rate_val)
1063 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
1064 }
1065 if (ice->spdif.ops.setup_rate)
1066 ice->spdif.ops.setup_rate(ice, rate);
1067}
1068
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001069static int snd_ice1712_playback_pro_prepare(struct snd_pcm_substream *substream)
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 ice->playback_pro_size = snd_pcm_lib_buffer_bytes(substream);
1074 spin_lock_irq(&ice->reg_lock);
1075 outl(substream->runtime->dma_addr, ICEMT(ice, PLAYBACK_ADDR));
1076 outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));
1077 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT));
1078 spin_unlock_irq(&ice->reg_lock);
1079
1080 return 0;
1081}
1082
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001083static int snd_ice1712_playback_pro_hw_params(struct snd_pcm_substream *substream,
1084 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001086 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
1088 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1089 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1090}
1091
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001092static int snd_ice1712_capture_pro_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001094 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
1096 ice->capture_pro_size = snd_pcm_lib_buffer_bytes(substream);
1097 spin_lock_irq(&ice->reg_lock);
1098 outl(substream->runtime->dma_addr, ICEMT(ice, CAPTURE_ADDR));
1099 outw((ice->capture_pro_size >> 2) - 1, ICEMT(ice, CAPTURE_SIZE));
1100 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, CAPTURE_COUNT));
1101 spin_unlock_irq(&ice->reg_lock);
1102 return 0;
1103}
1104
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001105static int snd_ice1712_capture_pro_hw_params(struct snd_pcm_substream *substream,
1106 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001108 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
1110 snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
1111 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1112}
1113
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001114static snd_pcm_uframes_t snd_ice1712_playback_pro_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001116 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 size_t ptr;
1118
1119 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_PLAYBACK_START))
1120 return 0;
1121 ptr = ice->playback_pro_size - (inw(ICEMT(ice, PLAYBACK_SIZE)) << 2);
Takashi Iwai4f8e9402014-04-08 16:58:34 +02001122 ptr = bytes_to_frames(substream->runtime, ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 if (ptr == substream->runtime->buffer_size)
1124 ptr = 0;
Takashi Iwai4f8e9402014-04-08 16:58:34 +02001125 return ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126}
1127
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001128static snd_pcm_uframes_t snd_ice1712_capture_pro_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001130 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 size_t ptr;
1132
1133 if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_CAPTURE_START_SHADOW))
1134 return 0;
1135 ptr = ice->capture_pro_size - (inw(ICEMT(ice, CAPTURE_SIZE)) << 2);
Takashi Iwai4f8e9402014-04-08 16:58:34 +02001136 ptr = bytes_to_frames(substream->runtime, ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 if (ptr == substream->runtime->buffer_size)
1138 ptr = 0;
Takashi Iwai4f8e9402014-04-08 16:58:34 +02001139 return ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140}
1141
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001142static const struct snd_pcm_hardware snd_ice1712_playback_pro = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1144 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1145 SNDRV_PCM_INFO_MMAP_VALID |
1146 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1147 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1148 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1149 .rate_min = 4000,
1150 .rate_max = 96000,
1151 .channels_min = 10,
1152 .channels_max = 10,
1153 .buffer_bytes_max = (256*1024),
1154 .period_bytes_min = 10 * 4 * 2,
1155 .period_bytes_max = 131040,
1156 .periods_min = 1,
1157 .periods_max = 1024,
1158 .fifo_size = 0,
1159};
1160
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001161static const struct snd_pcm_hardware snd_ice1712_capture_pro = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1163 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1164 SNDRV_PCM_INFO_MMAP_VALID |
1165 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
1166 .formats = SNDRV_PCM_FMTBIT_S32_LE,
1167 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
1168 .rate_min = 4000,
1169 .rate_max = 96000,
1170 .channels_min = 12,
1171 .channels_max = 12,
1172 .buffer_bytes_max = (256*1024),
1173 .period_bytes_min = 12 * 4 * 2,
1174 .period_bytes_max = 131040,
1175 .periods_min = 1,
1176 .periods_max = 1024,
1177 .fifo_size = 0,
1178};
1179
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001180static int snd_ice1712_playback_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_pcm_runtime *runtime = substream->runtime;
1183 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
1185 ice->playback_pro_substream = substream;
1186 runtime->hw = snd_ice1712_playback_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);
Sebastien Alaiwan350a5142010-02-05 08:58:20 +01001190 if (is_pro_rate_locked(ice)) {
1191 runtime->hw.rate_min = PRO_RATE_DEFAULT;
1192 runtime->hw.rate_max = PRO_RATE_DEFAULT;
1193 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
1195 if (ice->spdif.ops.open)
1196 ice->spdif.ops.open(ice, substream);
1197
1198 return 0;
1199}
1200
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001201static int snd_ice1712_capture_pro_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001203 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1204 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
1206 ice->capture_pro_substream = substream;
1207 runtime->hw = snd_ice1712_capture_pro;
1208 snd_pcm_set_sync(substream);
1209 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1210 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
Sebastien Alaiwan350a5142010-02-05 08:58:20 +01001211 if (is_pro_rate_locked(ice)) {
1212 runtime->hw.rate_min = PRO_RATE_DEFAULT;
1213 runtime->hw.rate_max = PRO_RATE_DEFAULT;
1214 }
1215
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 return 0;
1217}
1218
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001219static int snd_ice1712_playback_pro_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001221 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
1223 if (PRO_RATE_RESET)
1224 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1225 ice->playback_pro_substream = NULL;
1226 if (ice->spdif.ops.close)
1227 ice->spdif.ops.close(ice, substream);
1228
1229 return 0;
1230}
1231
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001232static int snd_ice1712_capture_pro_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001234 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
1236 if (PRO_RATE_RESET)
1237 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1238 ice->capture_pro_substream = NULL;
1239 return 0;
1240}
1241
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001242static struct snd_pcm_ops snd_ice1712_playback_pro_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 .open = snd_ice1712_playback_pro_open,
1244 .close = snd_ice1712_playback_pro_close,
1245 .ioctl = snd_pcm_lib_ioctl,
1246 .hw_params = snd_ice1712_playback_pro_hw_params,
1247 .hw_free = snd_ice1712_hw_free,
1248 .prepare = snd_ice1712_playback_pro_prepare,
1249 .trigger = snd_ice1712_pro_trigger,
1250 .pointer = snd_ice1712_playback_pro_pointer,
1251};
1252
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001253static struct snd_pcm_ops snd_ice1712_capture_pro_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 .open = snd_ice1712_capture_pro_open,
1255 .close = snd_ice1712_capture_pro_close,
1256 .ioctl = snd_pcm_lib_ioctl,
1257 .hw_params = snd_ice1712_capture_pro_hw_params,
1258 .hw_free = snd_ice1712_hw_free,
1259 .prepare = snd_ice1712_capture_pro_prepare,
1260 .trigger = snd_ice1712_pro_trigger,
1261 .pointer = snd_ice1712_capture_pro_pointer,
1262};
1263
Bill Pembertone23e7a12012-12-06 12:35:10 -05001264static int snd_ice1712_pcm_profi(struct snd_ice1712 *ice, int device, struct snd_pcm **rpcm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001266 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 int err;
1268
1269 if (rpcm)
1270 *rpcm = NULL;
1271 err = snd_pcm_new(ice->card, "ICE1712 multi", device, 1, 1, &pcm);
1272 if (err < 0)
1273 return err;
1274
1275 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_pro_ops);
1276 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_pro_ops);
1277
1278 pcm->private_data = ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 pcm->info_flags = 0;
1280 strcpy(pcm->name, "ICE1712 multi");
1281
1282 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1283 snd_dma_pci_data(ice->pci), 256*1024, 256*1024);
1284
1285 ice->pcm_pro = pcm;
1286 if (rpcm)
1287 *rpcm = pcm;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001288
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 if (ice->cs8427) {
1290 /* assign channels to iec958 */
1291 err = snd_cs8427_iec958_build(ice->cs8427,
1292 pcm->streams[0].substream,
1293 pcm->streams[1].substream);
1294 if (err < 0)
1295 return err;
1296 }
1297
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001298 err = snd_ice1712_build_pro_mixer(ice);
1299 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 return err;
1301 return 0;
1302}
1303
1304/*
1305 * Mixer section
1306 */
1307
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001308static void snd_ice1712_update_volume(struct snd_ice1712 *ice, int index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309{
1310 unsigned int vol = ice->pro_volumes[index];
1311 unsigned short val = 0;
1312
1313 val |= (vol & 0x8000) == 0 ? (96 - (vol & 0x7f)) : 0x7f;
1314 val |= ((vol & 0x80000000) == 0 ? (96 - ((vol >> 16) & 0x7f)) : 0x7f) << 8;
1315 outb(index, ICEMT(ice, MONITOR_INDEX));
1316 outw(val, ICEMT(ice, MONITOR_VOLUME));
1317}
1318
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001319#define snd_ice1712_pro_mixer_switch_info snd_ctl_boolean_stereo_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001321static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001323 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Harvey Harrisonc3daa922008-02-29 11:52:50 +01001324 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1325 kcontrol->private_value;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001326
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 spin_lock_irq(&ice->reg_lock);
Harvey Harrisonc3daa922008-02-29 11:52:50 +01001328 ucontrol->value.integer.value[0] =
1329 !((ice->pro_volumes[priv_idx] >> 15) & 1);
1330 ucontrol->value.integer.value[1] =
1331 !((ice->pro_volumes[priv_idx] >> 31) & 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 spin_unlock_irq(&ice->reg_lock);
1333 return 0;
1334}
1335
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001336static int snd_ice1712_pro_mixer_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001338 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Harvey Harrisonc3daa922008-02-29 11:52:50 +01001339 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1340 kcontrol->private_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 unsigned int nval, change;
1342
1343 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
1344 (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
1345 spin_lock_irq(&ice->reg_lock);
Harvey Harrisonc3daa922008-02-29 11:52:50 +01001346 nval |= ice->pro_volumes[priv_idx] & ~0x80008000;
1347 change = nval != ice->pro_volumes[priv_idx];
1348 ice->pro_volumes[priv_idx] = nval;
1349 snd_ice1712_update_volume(ice, priv_idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 spin_unlock_irq(&ice->reg_lock);
1351 return change;
1352}
1353
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001354static int snd_ice1712_pro_mixer_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355{
1356 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1357 uinfo->count = 2;
1358 uinfo->value.integer.min = 0;
1359 uinfo->value.integer.max = 96;
1360 return 0;
1361}
1362
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001363static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001365 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Harvey Harrisonc3daa922008-02-29 11:52:50 +01001366 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1367 kcontrol->private_value;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001368
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 spin_lock_irq(&ice->reg_lock);
Harvey Harrisonc3daa922008-02-29 11:52:50 +01001370 ucontrol->value.integer.value[0] =
1371 (ice->pro_volumes[priv_idx] >> 0) & 127;
1372 ucontrol->value.integer.value[1] =
1373 (ice->pro_volumes[priv_idx] >> 16) & 127;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 spin_unlock_irq(&ice->reg_lock);
1375 return 0;
1376}
1377
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001378static int snd_ice1712_pro_mixer_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001380 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Harvey Harrisonc3daa922008-02-29 11:52:50 +01001381 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1382 kcontrol->private_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 unsigned int nval, change;
1384
1385 nval = (ucontrol->value.integer.value[0] & 127) |
1386 ((ucontrol->value.integer.value[1] & 127) << 16);
1387 spin_lock_irq(&ice->reg_lock);
Harvey Harrisonc3daa922008-02-29 11:52:50 +01001388 nval |= ice->pro_volumes[priv_idx] & ~0x007f007f;
1389 change = nval != ice->pro_volumes[priv_idx];
1390 ice->pro_volumes[priv_idx] = nval;
1391 snd_ice1712_update_volume(ice, priv_idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 spin_unlock_irq(&ice->reg_lock);
1393 return change;
1394}
1395
Takashi Iwai0cb29ea2007-01-29 15:33:49 +01001396static const DECLARE_TLV_DB_SCALE(db_scale_playback, -14400, 150, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
Bill Pembertone23e7a12012-12-06 12:35:10 -05001398static struct snd_kcontrol_new snd_ice1712_multi_playback_ctrls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 {
1400 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1401 .name = "Multi Playback Switch",
1402 .info = snd_ice1712_pro_mixer_switch_info,
1403 .get = snd_ice1712_pro_mixer_switch_get,
1404 .put = snd_ice1712_pro_mixer_switch_put,
1405 .private_value = 0,
1406 .count = 10,
1407 },
1408 {
1409 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai680ef792006-08-30 16:56:30 +02001410 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1411 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 .name = "Multi Playback Volume",
1413 .info = snd_ice1712_pro_mixer_volume_info,
1414 .get = snd_ice1712_pro_mixer_volume_get,
1415 .put = snd_ice1712_pro_mixer_volume_put,
1416 .private_value = 0,
1417 .count = 10,
Takashi Iwai680ef792006-08-30 16:56:30 +02001418 .tlv = { .p = db_scale_playback }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 },
1420};
1421
Bill Pembertone23e7a12012-12-06 12:35:10 -05001422static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_switch = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1424 .name = "H/W Multi Capture Switch",
1425 .info = snd_ice1712_pro_mixer_switch_info,
1426 .get = snd_ice1712_pro_mixer_switch_get,
1427 .put = snd_ice1712_pro_mixer_switch_put,
1428 .private_value = 10,
1429};
1430
Bill Pembertone23e7a12012-12-06 12:35:10 -05001431static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_switch = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001433 .name = SNDRV_CTL_NAME_IEC958("Multi ", CAPTURE, SWITCH),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 .info = snd_ice1712_pro_mixer_switch_info,
1435 .get = snd_ice1712_pro_mixer_switch_get,
1436 .put = snd_ice1712_pro_mixer_switch_put,
1437 .private_value = 18,
1438 .count = 2,
1439};
1440
Bill Pembertone23e7a12012-12-06 12:35:10 -05001441static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_volume = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai680ef792006-08-30 16:56:30 +02001443 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1444 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 .name = "H/W Multi Capture Volume",
1446 .info = snd_ice1712_pro_mixer_volume_info,
1447 .get = snd_ice1712_pro_mixer_volume_get,
1448 .put = snd_ice1712_pro_mixer_volume_put,
1449 .private_value = 10,
Takashi Iwai680ef792006-08-30 16:56:30 +02001450 .tlv = { .p = db_scale_playback }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451};
1452
Bill Pembertone23e7a12012-12-06 12:35:10 -05001453static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_volume = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001455 .name = SNDRV_CTL_NAME_IEC958("Multi ", CAPTURE, VOLUME),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 .info = snd_ice1712_pro_mixer_volume_info,
1457 .get = snd_ice1712_pro_mixer_volume_get,
1458 .put = snd_ice1712_pro_mixer_volume_put,
1459 .private_value = 18,
1460 .count = 2,
1461};
1462
Bill Pembertone23e7a12012-12-06 12:35:10 -05001463static int snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001465 struct snd_card *card = ice->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 unsigned int idx;
1467 int err;
1468
1469 /* multi-channel mixer */
1470 for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_multi_playback_ctrls); idx++) {
1471 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_playback_ctrls[idx], ice));
1472 if (err < 0)
1473 return err;
1474 }
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001475
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 if (ice->num_total_adcs > 0) {
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001477 struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_switch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 tmp.count = ice->num_total_adcs;
1479 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1480 if (err < 0)
1481 return err;
1482 }
1483
1484 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_switch, ice));
1485 if (err < 0)
1486 return err;
1487
1488 if (ice->num_total_adcs > 0) {
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001489 struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_volume;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 tmp.count = ice->num_total_adcs;
1491 err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
1492 if (err < 0)
1493 return err;
1494 }
1495
1496 err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_volume, ice));
1497 if (err < 0)
1498 return err;
1499
1500 /* initialize volumes */
1501 for (idx = 0; idx < 10; idx++) {
1502 ice->pro_volumes[idx] = 0x80008000; /* mute */
1503 snd_ice1712_update_volume(ice, idx);
1504 }
1505 for (idx = 10; idx < 10 + ice->num_total_adcs; idx++) {
1506 ice->pro_volumes[idx] = 0x80008000; /* mute */
1507 snd_ice1712_update_volume(ice, idx);
1508 }
1509 for (idx = 18; idx < 20; idx++) {
1510 ice->pro_volumes[idx] = 0x80008000; /* mute */
1511 snd_ice1712_update_volume(ice, idx);
1512 }
1513 return 0;
1514}
1515
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001516static void snd_ice1712_mixer_free_ac97(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001518 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 ice->ac97 = NULL;
1520}
1521
Bill Pembertone23e7a12012-12-06 12:35:10 -05001522static int snd_ice1712_ac97_mixer(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523{
1524 int err, bus_num = 0;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001525 struct snd_ac97_template ac97;
1526 struct snd_ac97_bus *pbus;
1527 static struct snd_ac97_bus_ops con_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 .write = snd_ice1712_ac97_write,
1529 .read = snd_ice1712_ac97_read,
1530 };
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001531 static struct snd_ac97_bus_ops pro_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 .write = snd_ice1712_pro_ac97_write,
1533 .read = snd_ice1712_pro_ac97_read,
1534 };
1535
1536 if (ice_has_con_ac97(ice)) {
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001537 err = snd_ac97_bus(ice->card, bus_num++, &con_ops, NULL, &pbus);
1538 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 return err;
1540 memset(&ac97, 0, sizeof(ac97));
1541 ac97.private_data = ice;
1542 ac97.private_free = snd_ice1712_mixer_free_ac97;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001543 err = snd_ac97_mixer(pbus, &ac97, &ice->ac97);
1544 if (err < 0)
Takashi Iwai6dfb5af2014-02-25 17:16:16 +01001545 dev_warn(ice->card->dev,
1546 "cannot initialize ac97 for consumer, skipped\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 else {
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001548 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice));
1549 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 return err;
1551 return 0;
1552 }
1553 }
1554
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001555 if (!(ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) {
1556 err = snd_ac97_bus(ice->card, bus_num, &pro_ops, NULL, &pbus);
1557 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 return err;
1559 memset(&ac97, 0, sizeof(ac97));
1560 ac97.private_data = ice;
1561 ac97.private_free = snd_ice1712_mixer_free_ac97;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001562 err = snd_ac97_mixer(pbus, &ac97, &ice->ac97);
1563 if (err < 0)
Takashi Iwai6dfb5af2014-02-25 17:16:16 +01001564 dev_warn(ice->card->dev,
1565 "cannot initialize pro ac97, skipped\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 else
1567 return 0;
1568 }
1569 /* I2S mixer only */
1570 strcat(ice->card->mixername, "ICE1712 - multitrack");
1571 return 0;
1572}
1573
1574/*
1575 *
1576 */
1577
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001578static inline unsigned int eeprom_double(struct snd_ice1712 *ice, int idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579{
1580 return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8);
1581}
1582
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001583static void snd_ice1712_proc_read(struct snd_info_entry *entry,
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001584 struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001586 struct snd_ice1712 *ice = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 unsigned int idx;
1588
1589 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1590 snd_iprintf(buffer, "EEPROM:\n");
1591
1592 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1593 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1594 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
1595 snd_iprintf(buffer, " Codec : 0x%x\n", ice->eeprom.data[ICE_EEP1_CODEC]);
1596 snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP1_ACLINK]);
1597 snd_iprintf(buffer, " I2S ID : 0x%x\n", ice->eeprom.data[ICE_EEP1_I2SID]);
1598 snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP1_SPDIF]);
1599 snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
1600 snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
1601 snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
1602 snd_iprintf(buffer, " AC'97 main : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_MAIN_LO));
1603 snd_iprintf(buffer, " AC'97 pcm : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_PCM_LO));
1604 snd_iprintf(buffer, " AC'97 record : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_REC_LO));
1605 snd_iprintf(buffer, " AC'97 record src : 0x%x\n", ice->eeprom.data[ICE_EEP1_AC97_RECSRC]);
1606 for (idx = 0; idx < 4; idx++)
1607 snd_iprintf(buffer, " DAC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_DAC_ID + idx]);
1608 for (idx = 0; idx < 4; idx++)
1609 snd_iprintf(buffer, " ADC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_ADC_ID + idx]);
1610 for (idx = 0x1c; idx < ice->eeprom.size; idx++)
1611 snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
1612
1613 snd_iprintf(buffer, "\nRegisters:\n");
1614 snd_iprintf(buffer, " PSDOUT03 : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_PSDOUT03)));
1615 snd_iprintf(buffer, " CAPTURE : 0x%08x\n", inl(ICEMT(ice, ROUTE_CAPTURE)));
1616 snd_iprintf(buffer, " SPDOUT : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT)));
1617 snd_iprintf(buffer, " RATE : 0x%02x\n", (unsigned)inb(ICEMT(ice, RATE)));
Jaroslav Kyselaf7004f32006-02-10 08:42:17 +01001618 snd_iprintf(buffer, " GPIO_DATA : 0x%02x\n", (unsigned)snd_ice1712_get_gpio_data(ice));
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001619 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 +01001620 snd_iprintf(buffer, " GPIO_DIRECTION : 0x%02x\n", (unsigned)snd_ice1712_read(ice, ICE1712_IREG_GPIO_DIRECTION));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621}
1622
Bill Pembertone23e7a12012-12-06 12:35:10 -05001623static void snd_ice1712_proc_init(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001625 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001627 if (!snd_card_proc_new(ice->card, "ice1712", &entry))
Takashi Iwaibf850202006-04-28 15:13:41 +02001628 snd_info_set_text_ops(entry, ice, snd_ice1712_proc_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629}
1630
1631/*
1632 *
1633 */
1634
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001635static int snd_ice1712_eeprom_info(struct snd_kcontrol *kcontrol,
1636 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637{
1638 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001639 uinfo->count = sizeof(struct snd_ice1712_eeprom);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 return 0;
1641}
1642
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001643static int snd_ice1712_eeprom_get(struct snd_kcontrol *kcontrol,
1644 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001646 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001647
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1649 return 0;
1650}
1651
Bill Pembertone23e7a12012-12-06 12:35:10 -05001652static struct snd_kcontrol_new snd_ice1712_eeprom = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1654 .name = "ICE1712 EEPROM",
1655 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1656 .info = snd_ice1712_eeprom_info,
1657 .get = snd_ice1712_eeprom_get
1658};
1659
1660/*
1661 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001662static int snd_ice1712_spdif_info(struct snd_kcontrol *kcontrol,
1663 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664{
1665 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1666 uinfo->count = 1;
1667 return 0;
1668}
1669
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001670static int snd_ice1712_spdif_default_get(struct snd_kcontrol *kcontrol,
1671 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001673 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 if (ice->spdif.ops.default_get)
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001675 ice->spdif.ops.default_get(ice, ucontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 return 0;
1677}
1678
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001679static int snd_ice1712_spdif_default_put(struct snd_kcontrol *kcontrol,
1680 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001682 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 if (ice->spdif.ops.default_put)
1684 return ice->spdif.ops.default_put(ice, ucontrol);
1685 return 0;
1686}
1687
Bill Pembertone23e7a12012-12-06 12:35:10 -05001688static struct snd_kcontrol_new snd_ice1712_spdif_default =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689{
1690 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001691 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 .info = snd_ice1712_spdif_info,
1693 .get = snd_ice1712_spdif_default_get,
1694 .put = snd_ice1712_spdif_default_put
1695};
1696
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001697static int snd_ice1712_spdif_maskc_get(struct snd_kcontrol *kcontrol,
1698 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001700 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 if (ice->spdif.ops.default_get) {
1702 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1703 IEC958_AES0_PROFESSIONAL |
1704 IEC958_AES0_CON_NOT_COPYRIGHT |
1705 IEC958_AES0_CON_EMPHASIS;
1706 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1707 IEC958_AES1_CON_CATEGORY;
1708 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1709 } else {
1710 ucontrol->value.iec958.status[0] = 0xff;
1711 ucontrol->value.iec958.status[1] = 0xff;
1712 ucontrol->value.iec958.status[2] = 0xff;
1713 ucontrol->value.iec958.status[3] = 0xff;
1714 ucontrol->value.iec958.status[4] = 0xff;
1715 }
1716 return 0;
1717}
1718
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001719static int snd_ice1712_spdif_maskp_get(struct snd_kcontrol *kcontrol,
1720 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001722 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 if (ice->spdif.ops.default_get) {
1724 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1725 IEC958_AES0_PROFESSIONAL |
1726 IEC958_AES0_PRO_FS |
1727 IEC958_AES0_PRO_EMPHASIS;
1728 ucontrol->value.iec958.status[1] = IEC958_AES1_PRO_MODE;
1729 } else {
1730 ucontrol->value.iec958.status[0] = 0xff;
1731 ucontrol->value.iec958.status[1] = 0xff;
1732 ucontrol->value.iec958.status[2] = 0xff;
1733 ucontrol->value.iec958.status[3] = 0xff;
1734 ucontrol->value.iec958.status[4] = 0xff;
1735 }
1736 return 0;
1737}
1738
Bill Pembertone23e7a12012-12-06 12:35:10 -05001739static struct snd_kcontrol_new snd_ice1712_spdif_maskc =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740{
1741 .access = SNDRV_CTL_ELEM_ACCESS_READ,
Clemens Ladisch67ed4162005-07-29 15:32:58 +02001742 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001743 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 .info = snd_ice1712_spdif_info,
1745 .get = snd_ice1712_spdif_maskc_get,
1746};
1747
Bill Pembertone23e7a12012-12-06 12:35:10 -05001748static struct snd_kcontrol_new snd_ice1712_spdif_maskp =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749{
1750 .access = SNDRV_CTL_ELEM_ACCESS_READ,
Clemens Ladisch67ed4162005-07-29 15:32:58 +02001751 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001752 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PRO_MASK),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 .info = snd_ice1712_spdif_info,
1754 .get = snd_ice1712_spdif_maskp_get,
1755};
1756
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001757static int snd_ice1712_spdif_stream_get(struct snd_kcontrol *kcontrol,
1758 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001760 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 if (ice->spdif.ops.stream_get)
1762 ice->spdif.ops.stream_get(ice, ucontrol);
1763 return 0;
1764}
1765
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001766static int snd_ice1712_spdif_stream_put(struct snd_kcontrol *kcontrol,
1767 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001769 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 if (ice->spdif.ops.stream_put)
1771 return ice->spdif.ops.stream_put(ice, ucontrol);
1772 return 0;
1773}
1774
Bill Pembertone23e7a12012-12-06 12:35:10 -05001775static struct snd_kcontrol_new snd_ice1712_spdif_stream =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001777 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1778 SNDRV_CTL_ELEM_ACCESS_INACTIVE),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001780 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 .info = snd_ice1712_spdif_info,
1782 .get = snd_ice1712_spdif_stream_get,
1783 .put = snd_ice1712_spdif_stream_put
1784};
1785
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001786int snd_ice1712_gpio_get(struct snd_kcontrol *kcontrol,
1787 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001789 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 unsigned char mask = kcontrol->private_value & 0xff;
1791 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001792
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 snd_ice1712_save_gpio_status(ice);
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001794 ucontrol->value.integer.value[0] =
1795 (snd_ice1712_gpio_read(ice) & mask ? 1 : 0) ^ invert;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 snd_ice1712_restore_gpio_status(ice);
1797 return 0;
1798}
1799
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001800int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
1801 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001803 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 unsigned char mask = kcontrol->private_value & 0xff;
1805 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1806 unsigned int val, nval;
1807
1808 if (kcontrol->private_value & (1 << 31))
1809 return -EPERM;
1810 nval = (ucontrol->value.integer.value[0] ? mask : 0) ^ invert;
1811 snd_ice1712_save_gpio_status(ice);
1812 val = snd_ice1712_gpio_read(ice);
1813 nval |= val & ~mask;
1814 if (val != nval)
1815 snd_ice1712_gpio_write(ice, nval);
1816 snd_ice1712_restore_gpio_status(ice);
1817 return val != nval;
1818}
1819
1820/*
1821 * rate
1822 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001823static int snd_ice1712_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1824 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825{
Takashi Iwai32b47da2007-01-29 15:26:36 +01001826 static const char * const texts[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 "8000", /* 0: 6 */
1828 "9600", /* 1: 3 */
1829 "11025", /* 2: 10 */
1830 "12000", /* 3: 2 */
1831 "16000", /* 4: 5 */
1832 "22050", /* 5: 9 */
1833 "24000", /* 6: 1 */
1834 "32000", /* 7: 4 */
1835 "44100", /* 8: 8 */
1836 "48000", /* 9: 0 */
1837 "64000", /* 10: 15 */
1838 "88200", /* 11: 11 */
1839 "96000", /* 12: 7 */
1840 "IEC958 Input", /* 13: -- */
1841 };
1842 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1843 uinfo->count = 1;
1844 uinfo->value.enumerated.items = 14;
1845 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1846 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1847 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1848 return 0;
1849}
1850
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001851static int snd_ice1712_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1852 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001854 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai32b47da2007-01-29 15:26:36 +01001855 static const unsigned char xlate[16] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10
1857 };
1858 unsigned char val;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001859
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 spin_lock_irq(&ice->reg_lock);
1861 if (is_spdif_master(ice)) {
1862 ucontrol->value.enumerated.item[0] = 13;
1863 } else {
1864 val = xlate[inb(ICEMT(ice, RATE)) & 15];
1865 if (val == 255) {
1866 snd_BUG();
1867 val = 0;
1868 }
1869 ucontrol->value.enumerated.item[0] = val;
1870 }
1871 spin_unlock_irq(&ice->reg_lock);
1872 return 0;
1873}
1874
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001875static int snd_ice1712_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1876 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001878 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai32b47da2007-01-29 15:26:36 +01001879 static const unsigned int xrate[13] = {
Jaroslav Kyselafe25bef2006-08-15 14:39:07 +02001880 8000, 9600, 11025, 12000, 16000, 22050, 24000,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 32000, 44100, 48000, 64000, 88200, 96000
1882 };
1883 unsigned char oval;
1884 int change = 0;
1885
1886 spin_lock_irq(&ice->reg_lock);
1887 oval = inb(ICEMT(ice, RATE));
1888 if (ucontrol->value.enumerated.item[0] == 13) {
1889 outb(oval | ICE1712_SPDIF_MASTER, ICEMT(ice, RATE));
1890 } else {
1891 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1892 spin_unlock_irq(&ice->reg_lock);
1893 snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1894 spin_lock_irq(&ice->reg_lock);
1895 }
1896 change = inb(ICEMT(ice, RATE)) != oval;
1897 spin_unlock_irq(&ice->reg_lock);
1898
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001899 if ((oval & ICE1712_SPDIF_MASTER) !=
Jaroslav Kyselae957ebf2006-02-02 07:56:54 +01001900 (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER))
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001901 snd_ice1712_set_input_clock_source(ice, is_spdif_master(ice));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902
1903 return change;
1904}
1905
Bill Pembertone23e7a12012-12-06 12:35:10 -05001906static struct snd_kcontrol_new snd_ice1712_pro_internal_clock = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1908 .name = "Multi Track Internal Clock",
1909 .info = snd_ice1712_pro_internal_clock_info,
1910 .get = snd_ice1712_pro_internal_clock_get,
1911 .put = snd_ice1712_pro_internal_clock_put
1912};
1913
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001914static int snd_ice1712_pro_internal_clock_default_info(struct snd_kcontrol *kcontrol,
1915 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916{
Takashi Iwai32b47da2007-01-29 15:26:36 +01001917 static const char * const texts[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 "8000", /* 0: 6 */
1919 "9600", /* 1: 3 */
1920 "11025", /* 2: 10 */
1921 "12000", /* 3: 2 */
1922 "16000", /* 4: 5 */
1923 "22050", /* 5: 9 */
1924 "24000", /* 6: 1 */
1925 "32000", /* 7: 4 */
1926 "44100", /* 8: 8 */
1927 "48000", /* 9: 0 */
1928 "64000", /* 10: 15 */
1929 "88200", /* 11: 11 */
1930 "96000", /* 12: 7 */
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04001931 /* "IEC958 Input", 13: -- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 };
1933 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1934 uinfo->count = 1;
1935 uinfo->value.enumerated.items = 13;
1936 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1937 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1938 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1939 return 0;
1940}
1941
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001942static int snd_ice1712_pro_internal_clock_default_get(struct snd_kcontrol *kcontrol,
1943 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944{
1945 int val;
Takashi Iwai32b47da2007-01-29 15:26:36 +01001946 static const unsigned int xrate[13] = {
Jaroslav Kyselafe25bef2006-08-15 14:39:07 +02001947 8000, 9600, 11025, 12000, 16000, 22050, 24000,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 32000, 44100, 48000, 64000, 88200, 96000
1949 };
1950
1951 for (val = 0; val < 13; val++) {
1952 if (xrate[val] == PRO_RATE_DEFAULT)
1953 break;
1954 }
1955
1956 ucontrol->value.enumerated.item[0] = val;
1957 return 0;
1958}
1959
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001960static int snd_ice1712_pro_internal_clock_default_put(struct snd_kcontrol *kcontrol,
1961 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962{
Takashi Iwai32b47da2007-01-29 15:26:36 +01001963 static const unsigned int xrate[13] = {
Jaroslav Kyselafe25bef2006-08-15 14:39:07 +02001964 8000, 9600, 11025, 12000, 16000, 22050, 24000,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 32000, 44100, 48000, 64000, 88200, 96000
1966 };
1967 unsigned char oval;
1968 int change = 0;
1969
1970 oval = PRO_RATE_DEFAULT;
1971 PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
1972 change = PRO_RATE_DEFAULT != oval;
1973
1974 return change;
1975}
1976
Bill Pembertone23e7a12012-12-06 12:35:10 -05001977static struct snd_kcontrol_new snd_ice1712_pro_internal_clock_default = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1979 .name = "Multi Track Internal Clock Default",
1980 .info = snd_ice1712_pro_internal_clock_default_info,
1981 .get = snd_ice1712_pro_internal_clock_default_get,
1982 .put = snd_ice1712_pro_internal_clock_default_put
1983};
1984
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001985#define snd_ice1712_pro_rate_locking_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001987static int snd_ice1712_pro_rate_locking_get(struct snd_kcontrol *kcontrol,
1988 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989{
1990 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1991 return 0;
1992}
1993
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001994static int snd_ice1712_pro_rate_locking_put(struct snd_kcontrol *kcontrol,
1995 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01001997 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 int change = 0, nval;
1999
2000 nval = ucontrol->value.integer.value[0] ? 1 : 0;
2001 spin_lock_irq(&ice->reg_lock);
2002 change = PRO_RATE_LOCKED != nval;
2003 PRO_RATE_LOCKED = nval;
2004 spin_unlock_irq(&ice->reg_lock);
2005 return change;
2006}
2007
Bill Pembertone23e7a12012-12-06 12:35:10 -05002008static struct snd_kcontrol_new snd_ice1712_pro_rate_locking = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2010 .name = "Multi Track Rate Locking",
2011 .info = snd_ice1712_pro_rate_locking_info,
2012 .get = snd_ice1712_pro_rate_locking_get,
2013 .put = snd_ice1712_pro_rate_locking_put
2014};
2015
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002016#define snd_ice1712_pro_rate_reset_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002018static int snd_ice1712_pro_rate_reset_get(struct snd_kcontrol *kcontrol,
2019 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020{
2021 ucontrol->value.integer.value[0] = PRO_RATE_RESET;
2022 return 0;
2023}
2024
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002025static int snd_ice1712_pro_rate_reset_put(struct snd_kcontrol *kcontrol,
2026 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002028 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 int change = 0, nval;
2030
2031 nval = ucontrol->value.integer.value[0] ? 1 : 0;
2032 spin_lock_irq(&ice->reg_lock);
2033 change = PRO_RATE_RESET != nval;
2034 PRO_RATE_RESET = nval;
2035 spin_unlock_irq(&ice->reg_lock);
2036 return change;
2037}
2038
Bill Pembertone23e7a12012-12-06 12:35:10 -05002039static struct snd_kcontrol_new snd_ice1712_pro_rate_reset = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2041 .name = "Multi Track Rate Reset",
2042 .info = snd_ice1712_pro_rate_reset_info,
2043 .get = snd_ice1712_pro_rate_reset_get,
2044 .put = snd_ice1712_pro_rate_reset_put
2045};
2046
2047/*
2048 * routing
2049 */
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002050static int snd_ice1712_pro_route_info(struct snd_kcontrol *kcontrol,
2051 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052{
Takashi Iwai32b47da2007-01-29 15:26:36 +01002053 static const char * const texts[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 "PCM Out", /* 0 */
2055 "H/W In 0", "H/W In 1", "H/W In 2", "H/W In 3", /* 1-4 */
2056 "H/W In 4", "H/W In 5", "H/W In 6", "H/W In 7", /* 5-8 */
2057 "IEC958 In L", "IEC958 In R", /* 9-10 */
2058 "Digital Mixer", /* 11 - optional */
2059 };
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002060
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2062 uinfo->count = 1;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002063 uinfo->value.enumerated.items =
2064 snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2066 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2067 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2068 return 0;
2069}
2070
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002071static int snd_ice1712_pro_route_analog_get(struct snd_kcontrol *kcontrol,
2072 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002074 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2076 unsigned int val, cval;
2077
2078 spin_lock_irq(&ice->reg_lock);
2079 val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2080 cval = inl(ICEMT(ice, ROUTE_CAPTURE));
2081 spin_unlock_irq(&ice->reg_lock);
2082
2083 val >>= ((idx % 2) * 8) + ((idx / 2) * 2);
2084 val &= 3;
2085 cval >>= ((idx / 2) * 8) + ((idx % 2) * 4);
2086 if (val == 1 && idx < 2)
2087 ucontrol->value.enumerated.item[0] = 11;
2088 else if (val == 2)
2089 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2090 else if (val == 3)
2091 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2092 else
2093 ucontrol->value.enumerated.item[0] = 0;
2094 return 0;
2095}
2096
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002097static int snd_ice1712_pro_route_analog_put(struct snd_kcontrol *kcontrol,
2098 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002100 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 int change, shift;
2102 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2103 unsigned int val, old_val, nval;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002104
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 /* update PSDOUT */
2106 if (ucontrol->value.enumerated.item[0] >= 11)
2107 nval = idx < 2 ? 1 : 0; /* dig mixer (or pcm) */
2108 else if (ucontrol->value.enumerated.item[0] >= 9)
2109 nval = 3; /* spdif in */
2110 else if (ucontrol->value.enumerated.item[0] >= 1)
2111 nval = 2; /* analog in */
2112 else
2113 nval = 0; /* pcm */
2114 shift = ((idx % 2) * 8) + ((idx / 2) * 2);
2115 spin_lock_irq(&ice->reg_lock);
2116 val = old_val = inw(ICEMT(ice, ROUTE_PSDOUT03));
2117 val &= ~(0x03 << shift);
2118 val |= nval << shift;
2119 change = val != old_val;
2120 if (change)
2121 outw(val, ICEMT(ice, ROUTE_PSDOUT03));
2122 spin_unlock_irq(&ice->reg_lock);
2123 if (nval < 2) /* dig mixer of pcm */
2124 return change;
2125
2126 /* update CAPTURE */
2127 spin_lock_irq(&ice->reg_lock);
2128 val = old_val = inl(ICEMT(ice, ROUTE_CAPTURE));
2129 shift = ((idx / 2) * 8) + ((idx % 2) * 4);
2130 if (nval == 2) { /* analog in */
2131 nval = ucontrol->value.enumerated.item[0] - 1;
2132 val &= ~(0x07 << shift);
2133 val |= nval << shift;
2134 } else { /* spdif in */
2135 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2136 val &= ~(0x08 << shift);
2137 val |= nval << shift;
2138 }
2139 if (val != old_val) {
2140 change = 1;
2141 outl(val, ICEMT(ice, ROUTE_CAPTURE));
2142 }
2143 spin_unlock_irq(&ice->reg_lock);
2144 return change;
2145}
2146
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002147static int snd_ice1712_pro_route_spdif_get(struct snd_kcontrol *kcontrol,
2148 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002150 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2152 unsigned int val, cval;
2153 val = inw(ICEMT(ice, ROUTE_SPDOUT));
2154 cval = (val >> (idx * 4 + 8)) & 0x0f;
2155 val = (val >> (idx * 2)) & 0x03;
2156 if (val == 1)
2157 ucontrol->value.enumerated.item[0] = 11;
2158 else if (val == 2)
2159 ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
2160 else if (val == 3)
2161 ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
2162 else
2163 ucontrol->value.enumerated.item[0] = 0;
2164 return 0;
2165}
2166
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002167static int snd_ice1712_pro_route_spdif_put(struct snd_kcontrol *kcontrol,
2168 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002170 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 int change, shift;
2172 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2173 unsigned int val, old_val, nval;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002174
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 /* update SPDOUT */
2176 spin_lock_irq(&ice->reg_lock);
2177 val = old_val = inw(ICEMT(ice, ROUTE_SPDOUT));
2178 if (ucontrol->value.enumerated.item[0] >= 11)
2179 nval = 1;
2180 else if (ucontrol->value.enumerated.item[0] >= 9)
2181 nval = 3;
2182 else if (ucontrol->value.enumerated.item[0] >= 1)
2183 nval = 2;
2184 else
2185 nval = 0;
2186 shift = idx * 2;
2187 val &= ~(0x03 << shift);
2188 val |= nval << shift;
2189 shift = idx * 4 + 8;
2190 if (nval == 2) {
2191 nval = ucontrol->value.enumerated.item[0] - 1;
2192 val &= ~(0x07 << shift);
2193 val |= nval << shift;
2194 } else if (nval == 3) {
2195 nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
2196 val &= ~(0x08 << shift);
2197 val |= nval << shift;
2198 }
2199 change = val != old_val;
2200 if (change)
2201 outw(val, ICEMT(ice, ROUTE_SPDOUT));
2202 spin_unlock_irq(&ice->reg_lock);
2203 return change;
2204}
2205
Bill Pembertone23e7a12012-12-06 12:35:10 -05002206static struct snd_kcontrol_new snd_ice1712_mixer_pro_analog_route = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2208 .name = "H/W Playback Route",
2209 .info = snd_ice1712_pro_route_info,
2210 .get = snd_ice1712_pro_route_analog_get,
2211 .put = snd_ice1712_pro_route_analog_put,
2212};
2213
Bill Pembertone23e7a12012-12-06 12:35:10 -05002214static struct snd_kcontrol_new snd_ice1712_mixer_pro_spdif_route = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002216 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Route",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 .info = snd_ice1712_pro_route_info,
2218 .get = snd_ice1712_pro_route_spdif_get,
2219 .put = snd_ice1712_pro_route_spdif_put,
2220 .count = 2,
2221};
2222
2223
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002224static int snd_ice1712_pro_volume_rate_info(struct snd_kcontrol *kcontrol,
2225 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226{
2227 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2228 uinfo->count = 1;
2229 uinfo->value.integer.min = 0;
2230 uinfo->value.integer.max = 255;
2231 return 0;
2232}
2233
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002234static int snd_ice1712_pro_volume_rate_get(struct snd_kcontrol *kcontrol,
2235 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002237 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002238
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE));
2240 return 0;
2241}
2242
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002243static int snd_ice1712_pro_volume_rate_put(struct snd_kcontrol *kcontrol,
2244 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002246 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 int change;
2248
2249 spin_lock_irq(&ice->reg_lock);
2250 change = inb(ICEMT(ice, MONITOR_RATE)) != ucontrol->value.integer.value[0];
2251 outb(ucontrol->value.integer.value[0], ICEMT(ice, MONITOR_RATE));
2252 spin_unlock_irq(&ice->reg_lock);
2253 return change;
2254}
2255
Bill Pembertone23e7a12012-12-06 12:35:10 -05002256static struct snd_kcontrol_new snd_ice1712_mixer_pro_volume_rate = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2258 .name = "Multi Track Volume Rate",
2259 .info = snd_ice1712_pro_volume_rate_info,
2260 .get = snd_ice1712_pro_volume_rate_get,
2261 .put = snd_ice1712_pro_volume_rate_put
2262};
2263
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002264static int snd_ice1712_pro_peak_info(struct snd_kcontrol *kcontrol,
2265 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266{
2267 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2268 uinfo->count = 22;
2269 uinfo->value.integer.min = 0;
2270 uinfo->value.integer.max = 255;
2271 return 0;
2272}
2273
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002274static int snd_ice1712_pro_peak_get(struct snd_kcontrol *kcontrol,
2275 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002277 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 int idx;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002279
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 spin_lock_irq(&ice->reg_lock);
2281 for (idx = 0; idx < 22; idx++) {
2282 outb(idx, ICEMT(ice, MONITOR_PEAKINDEX));
2283 ucontrol->value.integer.value[idx] = inb(ICEMT(ice, MONITOR_PEAKDATA));
2284 }
2285 spin_unlock_irq(&ice->reg_lock);
2286 return 0;
2287}
2288
Bill Pembertone23e7a12012-12-06 12:35:10 -05002289static struct snd_kcontrol_new snd_ice1712_mixer_pro_peak = {
Pavel Hofman2bdf6632009-10-06 16:04:11 +02002290 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 .name = "Multi Track Peak",
2292 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2293 .info = snd_ice1712_pro_peak_info,
2294 .get = snd_ice1712_pro_peak_get
2295};
2296
2297/*
2298 *
2299 */
2300
2301/*
2302 * list of available boards
2303 */
Bill Pembertone23e7a12012-12-06 12:35:10 -05002304static struct snd_ice1712_card_info *card_tables[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 snd_ice1712_hoontech_cards,
2306 snd_ice1712_delta_cards,
2307 snd_ice1712_ews_cards,
2308 NULL,
2309};
2310
Bill Pembertone23e7a12012-12-06 12:35:10 -05002311static unsigned char snd_ice1712_read_i2c(struct snd_ice1712 *ice,
2312 unsigned char dev,
2313 unsigned char addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314{
2315 long t = 0x10000;
2316
2317 outb(addr, ICEREG(ice, I2C_BYTE_ADDR));
2318 outb(dev & ~ICE1712_I2C_WRITE, ICEREG(ice, I2C_DEV_ADDR));
2319 while (t-- > 0 && (inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_BUSY)) ;
2320 return inb(ICEREG(ice, I2C_DATA));
2321}
2322
Bill Pembertone23e7a12012-12-06 12:35:10 -05002323static int snd_ice1712_read_eeprom(struct snd_ice1712 *ice,
2324 const char *modelname)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325{
2326 int dev = 0xa0; /* EEPROM device address */
2327 unsigned int i, size;
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002328 struct snd_ice1712_card_info * const *tbl, *c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002330 if (!modelname || !*modelname) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 ice->eeprom.subvendor = 0;
2332 if ((inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_EEPROM) != 0)
2333 ice->eeprom.subvendor = (snd_ice1712_read_i2c(ice, dev, 0x00) << 0) |
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002334 (snd_ice1712_read_i2c(ice, dev, 0x01) << 8) |
2335 (snd_ice1712_read_i2c(ice, dev, 0x02) << 16) |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 (snd_ice1712_read_i2c(ice, dev, 0x03) << 24);
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002337 if (ice->eeprom.subvendor == 0 ||
2338 ice->eeprom.subvendor == (unsigned int)-1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 /* invalid subvendor from EEPROM, try the PCI subststem ID instead */
2340 u16 vendor, device;
2341 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID, &vendor);
2342 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
2343 ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device);
2344 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
Takashi Iwai6dfb5af2014-02-25 17:16:16 +01002345 dev_err(ice->card->dev,
2346 "No valid ID is found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 return -ENXIO;
2348 }
2349 }
2350 }
2351 for (tbl = card_tables; *tbl; tbl++) {
2352 for (c = *tbl; c->subvendor; c++) {
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002353 if (modelname && c->model && !strcmp(modelname, c->model)) {
Takashi Iwai6dfb5af2014-02-25 17:16:16 +01002354 dev_info(ice->card->dev,
2355 "Using board model %s\n", c->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 ice->eeprom.subvendor = c->subvendor;
2357 } else if (c->subvendor != ice->eeprom.subvendor)
2358 continue;
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002359 if (!c->eeprom_size || !c->eeprom_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 goto found;
2361 /* if the EEPROM is given by the driver, use it */
Takashi Iwai6dfb5af2014-02-25 17:16:16 +01002362 dev_dbg(ice->card->dev, "using the defined eeprom..\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 ice->eeprom.version = 1;
2364 ice->eeprom.size = c->eeprom_size + 6;
2365 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
2366 goto read_skipped;
2367 }
2368 }
Takashi Iwai6dfb5af2014-02-25 17:16:16 +01002369 dev_warn(ice->card->dev, "No matching model found for ID 0x%x\n",
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002370 ice->eeprom.subvendor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371
2372 found:
2373 ice->eeprom.size = snd_ice1712_read_i2c(ice, dev, 0x04);
2374 if (ice->eeprom.size < 6)
2375 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */
2376 else if (ice->eeprom.size > 32) {
Takashi Iwai6dfb5af2014-02-25 17:16:16 +01002377 dev_err(ice->card->dev,
2378 "invalid EEPROM (size = %i)\n", ice->eeprom.size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 return -EIO;
2380 }
2381 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05);
2382 if (ice->eeprom.version != 1) {
Takashi Iwai6dfb5af2014-02-25 17:16:16 +01002383 dev_err(ice->card->dev, "invalid EEPROM version %i\n",
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002384 ice->eeprom.version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 /* return -EIO; */
2386 }
2387 size = ice->eeprom.size - 6;
2388 for (i = 0; i < size; i++)
2389 ice->eeprom.data[i] = snd_ice1712_read_i2c(ice, dev, i + 6);
2390
2391 read_skipped:
2392 ice->eeprom.gpiomask = ice->eeprom.data[ICE_EEP1_GPIO_MASK];
2393 ice->eeprom.gpiostate = ice->eeprom.data[ICE_EEP1_GPIO_STATE];
2394 ice->eeprom.gpiodir = ice->eeprom.data[ICE_EEP1_GPIO_DIR];
2395
2396 return 0;
2397}
2398
2399
2400
Bill Pembertone23e7a12012-12-06 12:35:10 -05002401static int snd_ice1712_chip_init(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402{
2403 outb(ICE1712_RESET | ICE1712_NATIVE, ICEREG(ice, CONTROL));
2404 udelay(200);
2405 outb(ICE1712_NATIVE, ICEREG(ice, CONTROL));
2406 udelay(200);
Alan Horstmann721b8a22006-05-23 13:29:51 +02002407 if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DMX6FIRE &&
2408 !ice->dxr_enable)
2409 /* Set eeprom value to limit active ADCs and DACs to 6;
2410 * Also disable AC97 as no hardware in standard 6fire card/box
2411 * Note: DXR extensions are not currently supported
2412 */
2413 ice->eeprom.data[ICE_EEP1_CODEC] = 0x3a;
2414 pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 pci_write_config_byte(ice->pci, 0x61, ice->eeprom.data[ICE_EEP1_ACLINK]);
2416 pci_write_config_byte(ice->pci, 0x62, ice->eeprom.data[ICE_EEP1_I2SID]);
2417 pci_write_config_byte(ice->pci, 0x63, ice->eeprom.data[ICE_EEP1_SPDIF]);
2418 if (ice->eeprom.subvendor != ICE1712_SUBDEVICE_STDSP24) {
2419 ice->gpio.write_mask = ice->eeprom.gpiomask;
2420 ice->gpio.direction = ice->eeprom.gpiodir;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002421 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK,
2422 ice->eeprom.gpiomask);
2423 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
2424 ice->eeprom.gpiodir);
2425 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA,
2426 ice->eeprom.gpiostate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 } else {
2428 ice->gpio.write_mask = 0xc0;
2429 ice->gpio.direction = 0xff;
2430 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, 0xc0);
2431 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, 0xff);
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002432 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA,
2433 ICE1712_STDSP24_CLOCK_BIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 }
2435 snd_ice1712_write(ice, ICE1712_IREG_PRO_POWERDOWN, 0);
2436 if (!(ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97)) {
2437 outb(ICE1712_AC97_WARM, ICEREG(ice, AC97_CMD));
2438 udelay(100);
2439 outb(0, ICEREG(ice, AC97_CMD));
2440 udelay(200);
2441 snd_ice1712_write(ice, ICE1712_IREG_CONSUMER_POWERDOWN, 0);
2442 }
2443 snd_ice1712_set_pro_rate(ice, 48000, 1);
Ondrej Zaryca051e82014-03-30 23:37:30 +02002444 /* unmask used interrupts */
2445 outb(((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) == 0 ?
2446 ICE1712_IRQ_MPU2 : 0) |
2447 ((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97) ?
2448 ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0),
2449 ICEREG(ice, IRQMASK));
2450 outb(0x00, ICEMT(ice, IRQ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451
2452 return 0;
2453}
2454
Bill Pembertone23e7a12012-12-06 12:35:10 -05002455int snd_ice1712_spdif_build_controls(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456{
2457 int err;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002458 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459
Takashi Iwaida3cec32008-08-08 17:12:14 +02002460 if (snd_BUG_ON(!ice->pcm_pro))
2461 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_default, ice));
2463 if (err < 0)
2464 return err;
2465 kctl->id.device = ice->pcm_pro->device;
2466 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskc, ice));
2467 if (err < 0)
2468 return err;
2469 kctl->id.device = ice->pcm_pro->device;
2470 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskp, ice));
2471 if (err < 0)
2472 return err;
2473 kctl->id.device = ice->pcm_pro->device;
2474 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_stream, ice));
2475 if (err < 0)
2476 return err;
2477 kctl->id.device = ice->pcm_pro->device;
2478 ice->spdif.stream_ctl = kctl;
2479 return 0;
2480}
2481
2482
Bill Pembertone23e7a12012-12-06 12:35:10 -05002483static int snd_ice1712_build_controls(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484{
2485 int err;
2486
2487 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_eeprom, ice));
2488 if (err < 0)
2489 return err;
2490 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock, ice));
2491 if (err < 0)
2492 return err;
2493 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock_default, ice));
2494 if (err < 0)
2495 return err;
2496
2497 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_locking, ice));
2498 if (err < 0)
2499 return err;
2500 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_reset, ice));
2501 if (err < 0)
2502 return err;
2503
2504 if (ice->num_total_dacs > 0) {
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002505 struct snd_kcontrol_new tmp = snd_ice1712_mixer_pro_analog_route;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 tmp.count = ice->num_total_dacs;
2507 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2508 if (err < 0)
2509 return err;
2510 }
2511
2512 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice));
2513 if (err < 0)
2514 return err;
2515
2516 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
2517 if (err < 0)
2518 return err;
2519 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice));
2520 if (err < 0)
2521 return err;
2522
2523 return 0;
2524}
2525
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002526static int snd_ice1712_free(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527{
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002528 if (!ice->port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 goto __hw_end;
2530 /* mask all interrupts */
Konstantinos Tsimpoukas890b13a2014-08-26 23:21:48 -05002531 outb(ICE1712_MULTI_CAPTURE | ICE1712_MULTI_PLAYBACK, ICEMT(ice, IRQ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 outb(0xff, ICEREG(ice, IRQMASK));
2533 /* --- */
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002534__hw_end:
Jeff Garzikf000fd82008-04-22 13:50:34 +02002535 if (ice->irq >= 0)
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002536 free_irq(ice->irq, ice);
Jeff Garzikf000fd82008-04-22 13:50:34 +02002537
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 if (ice->port)
2539 pci_release_regions(ice->pci);
2540 snd_ice1712_akm4xxx_free(ice);
2541 pci_disable_device(ice->pci);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +01002542 kfree(ice->spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 kfree(ice);
2544 return 0;
2545}
2546
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002547static int snd_ice1712_dev_free(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002549 struct snd_ice1712 *ice = device->device_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 return snd_ice1712_free(ice);
2551}
2552
Bill Pembertone23e7a12012-12-06 12:35:10 -05002553static int snd_ice1712_create(struct snd_card *card,
2554 struct pci_dev *pci,
2555 const char *modelname,
2556 int omni,
2557 int cs8427_timeout,
2558 int dxr_enable,
2559 struct snd_ice1712 **r_ice1712)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560{
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002561 struct snd_ice1712 *ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 int err;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002563 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 .dev_free = snd_ice1712_dev_free,
2565 };
2566
2567 *r_ice1712 = NULL;
2568
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002569 /* enable PCI device */
2570 err = pci_enable_device(pci);
2571 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 return err;
2573 /* check, if we can restrict PCI DMA transfers to 28 bits */
Yang Hongyangce0b6202009-04-06 19:01:17 -07002574 if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 ||
2575 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) {
Takashi Iwai6dfb5af2014-02-25 17:16:16 +01002576 dev_err(card->dev,
2577 "architecture does not support 28bit PCI busmaster DMA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 pci_disable_device(pci);
2579 return -ENXIO;
2580 }
2581
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002582 ice = kzalloc(sizeof(*ice), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 if (ice == NULL) {
2584 pci_disable_device(pci);
2585 return -ENOMEM;
2586 }
2587 ice->omni = omni ? 1 : 0;
2588 if (cs8427_timeout < 1)
2589 cs8427_timeout = 1;
2590 else if (cs8427_timeout > 1000)
2591 cs8427_timeout = 1000;
2592 ice->cs8427_timeout = cs8427_timeout;
Alan Horstmann531af462006-02-08 07:40:33 +01002593 ice->dxr_enable = dxr_enable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 spin_lock_init(&ice->reg_lock);
Ingo Molnar62932df2006-01-16 16:34:20 +01002595 mutex_init(&ice->gpio_mutex);
2596 mutex_init(&ice->i2c_mutex);
2597 mutex_init(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 ice->gpio.set_mask = snd_ice1712_set_gpio_mask;
Pavel Hofman49470302009-09-16 22:25:38 +02002599 ice->gpio.get_mask = snd_ice1712_get_gpio_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 ice->gpio.set_dir = snd_ice1712_set_gpio_dir;
Pavel Hofman49470302009-09-16 22:25:38 +02002601 ice->gpio.get_dir = snd_ice1712_get_gpio_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 ice->gpio.set_data = snd_ice1712_set_gpio_data;
2603 ice->gpio.get_data = snd_ice1712_get_gpio_data;
2604
2605 ice->spdif.cs8403_bits =
2606 ice->spdif.cs8403_stream_bits = (0x01 | /* consumer format */
2607 0x10 | /* no emphasis */
2608 0x20); /* PCM encoder/decoder */
2609 ice->card = card;
2610 ice->pci = pci;
2611 ice->irq = -1;
2612 pci_set_master(pci);
Ondrej Zaryca051e82014-03-30 23:37:30 +02002613 /* disable legacy emulation */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 pci_write_config_word(ice->pci, 0x40, 0x807f);
2615 pci_write_config_word(ice->pci, 0x42, 0x0006);
2616 snd_ice1712_proc_init(ice);
2617 synchronize_irq(pci->irq);
2618
Sean Connor69a4cfd2013-02-28 09:20:00 -05002619 card->private_data = ice;
2620
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002621 err = pci_request_regions(pci, "ICE1712");
2622 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 kfree(ice);
2624 pci_disable_device(pci);
2625 return err;
2626 }
2627 ice->port = pci_resource_start(pci, 0);
2628 ice->ddma_port = pci_resource_start(pci, 1);
2629 ice->dmapath_port = pci_resource_start(pci, 2);
2630 ice->profi_port = pci_resource_start(pci, 3);
2631
Takashi Iwai437a5a42006-11-21 12:14:23 +01002632 if (request_irq(pci->irq, snd_ice1712_interrupt, IRQF_SHARED,
Takashi Iwai934c2b62011-06-10 16:36:37 +02002633 KBUILD_MODNAME, ice)) {
Takashi Iwai6dfb5af2014-02-25 17:16:16 +01002634 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 snd_ice1712_free(ice);
2636 return -EIO;
2637 }
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002638
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 ice->irq = pci->irq;
2640
2641 if (snd_ice1712_read_eeprom(ice, modelname) < 0) {
2642 snd_ice1712_free(ice);
2643 return -EIO;
2644 }
2645 if (snd_ice1712_chip_init(ice) < 0) {
2646 snd_ice1712_free(ice);
2647 return -EIO;
2648 }
2649
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002650 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops);
2651 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 snd_ice1712_free(ice);
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002653 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 }
2655
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 *r_ice1712 = ice;
2657 return 0;
2658}
2659
2660
2661/*
2662 *
2663 * Registration
2664 *
2665 */
2666
Bill Pembertone23e7a12012-12-06 12:35:10 -05002667static struct snd_ice1712_card_info no_matched;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668
Bill Pembertone23e7a12012-12-06 12:35:10 -05002669static int snd_ice1712_probe(struct pci_dev *pci,
2670 const struct pci_device_id *pci_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671{
2672 static int dev;
Takashi Iwai6ca308d2005-11-17 14:59:52 +01002673 struct snd_card *card;
2674 struct snd_ice1712 *ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 int pcm_dev = 0, err;
Ralf Baechlebf748ed2007-03-13 15:31:08 +01002676 struct snd_ice1712_card_info * const *tbl, *c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677
2678 if (dev >= SNDRV_CARDS)
2679 return -ENODEV;
2680 if (!enable[dev]) {
2681 dev++;
2682 return -ENOENT;
2683 }
2684
Takashi Iwai60c57722014-01-29 14:20:19 +01002685 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2686 0, &card);
Takashi Iwaie58de7b2008-12-28 16:44:30 +01002687 if (err < 0)
2688 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689
2690 strcpy(card->driver, "ICE1712");
2691 strcpy(card->shortname, "ICEnsemble ICE1712");
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002692
2693 err = snd_ice1712_create(card, pci, model[dev], omni[dev],
2694 cs8427_timeout[dev], dxr_enable[dev], &ice);
2695 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 snd_card_free(card);
2697 return err;
2698 }
2699
2700 for (tbl = card_tables; *tbl; tbl++) {
2701 for (c = *tbl; c->subvendor; c++) {
2702 if (c->subvendor == ice->eeprom.subvendor) {
Ondrej Zary267bcca2012-10-14 21:09:19 +02002703 ice->card_info = c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 strcpy(card->shortname, c->name);
2705 if (c->driver) /* specific driver? */
2706 strcpy(card->driver, c->driver);
2707 if (c->chip_init) {
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002708 err = c->chip_init(ice);
2709 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 snd_card_free(card);
2711 return err;
2712 }
2713 }
2714 goto __found;
2715 }
2716 }
2717 }
2718 c = &no_matched;
2719 __found:
2720
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002721 err = snd_ice1712_pcm_profi(ice, pcm_dev++, NULL);
2722 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 snd_card_free(card);
2724 return err;
2725 }
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002726
Ilpo Järvinen8cd2b262008-10-30 13:09:55 +02002727 if (ice_has_con_ac97(ice)) {
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002728 err = snd_ice1712_pcm(ice, pcm_dev++, NULL);
2729 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 snd_card_free(card);
2731 return err;
2732 }
Ilpo Järvinen8cd2b262008-10-30 13:09:55 +02002733 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002735 err = snd_ice1712_ac97_mixer(ice);
2736 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 snd_card_free(card);
2738 return err;
2739 }
2740
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002741 err = snd_ice1712_build_controls(ice);
2742 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 snd_card_free(card);
2744 return err;
2745 }
2746
2747 if (c->build_controls) {
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002748 err = c->build_controls(ice);
2749 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 snd_card_free(card);
2751 return err;
2752 }
2753 }
2754
Ilpo Järvinen8cd2b262008-10-30 13:09:55 +02002755 if (ice_has_con_ac97(ice)) {
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002756 err = snd_ice1712_pcm_ds(ice, pcm_dev++, NULL);
2757 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 snd_card_free(card);
2759 return err;
2760 }
Ilpo Järvinen8cd2b262008-10-30 13:09:55 +02002761 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002763 if (!c->no_mpu401) {
2764 err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2765 ICEREG(ice, MPU1_CTRL),
Clemens Ladischdba8b462011-09-13 11:24:41 +02002766 c->mpu401_1_info_flags |
2767 MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
2768 -1, &ice->rmidi[0]);
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002769 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 snd_card_free(card);
2771 return err;
2772 }
Alan Horstmann3bef2292006-04-26 18:13:59 +02002773 if (c->mpu401_1_name)
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002774 /* Preferred name available in card_info */
Alan Horstmann3bef2292006-04-26 18:13:59 +02002775 snprintf(ice->rmidi[0]->name,
2776 sizeof(ice->rmidi[0]->name),
2777 "%s %d", c->mpu401_1_name, card->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778
Alan Horstmann3bef2292006-04-26 18:13:59 +02002779 if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) {
2780 /* 2nd port used */
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002781 err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712,
2782 ICEREG(ice, MPU2_CTRL),
Clemens Ladischdba8b462011-09-13 11:24:41 +02002783 c->mpu401_2_info_flags |
2784 MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
2785 -1, &ice->rmidi[1]);
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002786
2787 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 snd_card_free(card);
2789 return err;
2790 }
Alan Horstmann3bef2292006-04-26 18:13:59 +02002791 if (c->mpu401_2_name)
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002792 /* Preferred name available in card_info */
Alan Horstmann3bef2292006-04-26 18:13:59 +02002793 snprintf(ice->rmidi[1]->name,
2794 sizeof(ice->rmidi[1]->name),
2795 "%s %d", c->mpu401_2_name,
2796 card->number);
2797 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 }
2799
Jaroslav Kyselae957ebf2006-02-02 07:56:54 +01002800 snd_ice1712_set_input_clock_source(ice, 0);
2801
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 sprintf(card->longname, "%s at 0x%lx, irq %i",
2803 card->shortname, ice->port, ice->irq);
2804
Alexander Beregalov3d8cb462008-09-07 14:17:02 +04002805 err = snd_card_register(card);
2806 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 snd_card_free(card);
2808 return err;
2809 }
2810 pci_set_drvdata(pci, card);
2811 dev++;
2812 return 0;
2813}
2814
Bill Pembertone23e7a12012-12-06 12:35:10 -05002815static void snd_ice1712_remove(struct pci_dev *pci)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816{
Ondrej Zary267bcca2012-10-14 21:09:19 +02002817 struct snd_card *card = pci_get_drvdata(pci);
2818 struct snd_ice1712 *ice = card->private_data;
2819
2820 if (ice->card_info && ice->card_info->chip_exit)
2821 ice->card_info->chip_exit(ice);
2822 snd_card_free(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823}
2824
Ondrej Zaryca051e82014-03-30 23:37:30 +02002825#ifdef CONFIG_PM_SLEEP
2826static int snd_ice1712_suspend(struct device *dev)
2827{
2828 struct pci_dev *pci = to_pci_dev(dev);
2829 struct snd_card *card = dev_get_drvdata(dev);
2830 struct snd_ice1712 *ice = card->private_data;
2831
2832 if (!ice->pm_suspend_enabled)
2833 return 0;
2834
2835 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
2836
2837 snd_pcm_suspend_all(ice->pcm);
2838 snd_pcm_suspend_all(ice->pcm_pro);
2839 snd_pcm_suspend_all(ice->pcm_ds);
2840 snd_ac97_suspend(ice->ac97);
2841
Ondrej Zary6ea0cae2014-04-03 23:09:38 +02002842 spin_lock_irq(&ice->reg_lock);
2843 ice->pm_saved_is_spdif_master = is_spdif_master(ice);
2844 ice->pm_saved_spdif_ctrl = inw(ICEMT(ice, ROUTE_SPDOUT));
2845 ice->pm_saved_route = inw(ICEMT(ice, ROUTE_PSDOUT03));
2846 spin_unlock_irq(&ice->reg_lock);
2847
Ondrej Zaryca051e82014-03-30 23:37:30 +02002848 if (ice->pm_suspend)
2849 ice->pm_suspend(ice);
2850
2851 pci_disable_device(pci);
2852 pci_save_state(pci);
2853 pci_set_power_state(pci, PCI_D3hot);
2854 return 0;
2855}
2856
2857static int snd_ice1712_resume(struct device *dev)
2858{
2859 struct pci_dev *pci = to_pci_dev(dev);
2860 struct snd_card *card = dev_get_drvdata(dev);
2861 struct snd_ice1712 *ice = card->private_data;
Ondrej Zary6ea0cae2014-04-03 23:09:38 +02002862 int rate;
Ondrej Zaryca051e82014-03-30 23:37:30 +02002863
2864 if (!ice->pm_suspend_enabled)
2865 return 0;
2866
2867 pci_set_power_state(pci, PCI_D0);
2868 pci_restore_state(pci);
2869
2870 if (pci_enable_device(pci) < 0) {
2871 snd_card_disconnect(card);
2872 return -EIO;
2873 }
2874
2875 pci_set_master(pci);
2876
Ondrej Zary6ea0cae2014-04-03 23:09:38 +02002877 if (ice->cur_rate)
2878 rate = ice->cur_rate;
2879 else
2880 rate = PRO_RATE_DEFAULT;
2881
Ondrej Zaryca051e82014-03-30 23:37:30 +02002882 if (snd_ice1712_chip_init(ice) < 0) {
2883 snd_card_disconnect(card);
2884 return -EIO;
2885 }
2886
Ondrej Zary6ea0cae2014-04-03 23:09:38 +02002887 ice->cur_rate = rate;
2888
Ondrej Zaryca051e82014-03-30 23:37:30 +02002889 if (ice->pm_resume)
2890 ice->pm_resume(ice);
2891
Ondrej Zary6ea0cae2014-04-03 23:09:38 +02002892 if (ice->pm_saved_is_spdif_master) {
2893 /* switching to external clock via SPDIF */
2894 spin_lock_irq(&ice->reg_lock);
2895 outb(inb(ICEMT(ice, RATE)) | ICE1712_SPDIF_MASTER,
2896 ICEMT(ice, RATE));
2897 spin_unlock_irq(&ice->reg_lock);
2898 snd_ice1712_set_input_clock_source(ice, 1);
2899 } else {
2900 /* internal on-card clock */
2901 snd_ice1712_set_pro_rate(ice, rate, 1);
2902 snd_ice1712_set_input_clock_source(ice, 0);
2903 }
2904
2905 outw(ice->pm_saved_spdif_ctrl, ICEMT(ice, ROUTE_SPDOUT));
2906 outw(ice->pm_saved_route, ICEMT(ice, ROUTE_PSDOUT03));
2907
Ondrej Zaryca051e82014-03-30 23:37:30 +02002908 if (ice->ac97)
2909 snd_ac97_resume(ice->ac97);
2910
2911 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
2912 return 0;
2913}
2914
2915static SIMPLE_DEV_PM_OPS(snd_ice1712_pm, snd_ice1712_suspend, snd_ice1712_resume);
2916#define SND_VT1712_PM_OPS &snd_ice1712_pm
2917#else
2918#define SND_VT1712_PM_OPS NULL
2919#endif /* CONFIG_PM_SLEEP */
2920
Takashi Iwaie9f66d92012-04-24 12:25:00 +02002921static struct pci_driver ice1712_driver = {
Takashi Iwai3733e422011-06-10 16:20:20 +02002922 .name = KBUILD_MODNAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 .id_table = snd_ice1712_ids,
2924 .probe = snd_ice1712_probe,
Bill Pembertone23e7a12012-12-06 12:35:10 -05002925 .remove = snd_ice1712_remove,
Ondrej Zaryca051e82014-03-30 23:37:30 +02002926 .driver = {
2927 .pm = SND_VT1712_PM_OPS,
2928 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929};
2930
Takashi Iwaie9f66d92012-04-24 12:25:00 +02002931module_pci_driver(ice1712_driver);