blob: 3bfd70577d7a7f096d6baa1d2d4c722dcfd235bc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ALSA driver for VT1724 ICEnsemble ICE1724 / VIA VT1724 (Envy24HT)
3 * VIA VT1720 (Envy24PT)
4 *
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02005 * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * 2002 James Stafford <jstafford@ampltd.com>
7 * 2003 Takashi Iwai <tiwai@suse.de>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/io.h>
26#include <linux/delay.h>
27#include <linux/interrupt.h>
28#include <linux/init.h>
29#include <linux/pci.h>
30#include <linux/slab.h>
31#include <linux/moduleparam.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010032#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <sound/core.h>
34#include <sound/info.h>
35#include <sound/mpu401.h>
36#include <sound/initval.h>
37
38#include <sound/asoundef.h>
39
40#include "ice1712.h"
41#include "envy24ht.h"
42
43/* lowlevel routines */
44#include "amp.h"
45#include "revo.h"
46#include "aureon.h"
47#include "vt1720_mobo.h"
48#include "pontis.h"
49#include "prodigy192.h"
Julian Scheel6b8d6e52008-01-16 19:50:00 +010050#include "prodigy_hifi.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include "juli.h"
52#include "phase.h"
Clement Guedezf6cdab52007-01-08 10:48:41 +010053#include "wtm.h"
Shin-ya Okadaf31639b2007-10-23 15:08:18 +020054#include "se.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020056MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070057MODULE_DESCRIPTION("VIA ICEnsemble ICE1724/1720 (Envy24HT/PT)");
58MODULE_LICENSE("GPL");
59MODULE_SUPPORTED_DEVICE("{"
60 REVO_DEVICE_DESC
61 AMP_AUDIO2000_DEVICE_DESC
62 AUREON_DEVICE_DESC
63 VT1720_MOBO_DEVICE_DESC
64 PONTIS_DEVICE_DESC
65 PRODIGY192_DEVICE_DESC
Julian Scheel6b8d6e52008-01-16 19:50:00 +010066 PRODIGY_HIFI_DEVICE_DESC
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 JULI_DEVICE_DESC
68 PHASE_DEVICE_DESC
Clement Guedezf6cdab52007-01-08 10:48:41 +010069 WTM_DEVICE_DESC
Shin-ya Okadaf31639b2007-10-23 15:08:18 +020070 SE_DEVICE_DESC
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 "{VIA,VT1720},"
72 "{VIA,VT1724},"
73 "{ICEnsemble,Generic ICE1724},"
74 "{ICEnsemble,Generic Envy24HT}"
75 "{ICEnsemble,Generic Envy24PT}}");
76
77static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
78static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
79static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
80static char *model[SNDRV_CARDS];
81
82module_param_array(index, int, NULL, 0444);
83MODULE_PARM_DESC(index, "Index value for ICE1724 soundcard.");
84module_param_array(id, charp, NULL, 0444);
85MODULE_PARM_DESC(id, "ID string for ICE1724 soundcard.");
86module_param_array(enable, bool, NULL, 0444);
87MODULE_PARM_DESC(enable, "Enable ICE1724 soundcard.");
88module_param_array(model, charp, NULL, 0444);
89MODULE_PARM_DESC(model, "Use the given board model.");
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92/* Both VT1720 and VT1724 have the same PCI IDs */
Takashi Iwai32b47da2007-01-29 15:26:36 +010093static const struct pci_device_id snd_vt1724_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_VT1724, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
95 { 0, }
96};
97
98MODULE_DEVICE_TABLE(pci, snd_vt1724_ids);
99
100
101static int PRO_RATE_LOCKED;
102static int PRO_RATE_RESET = 1;
103static unsigned int PRO_RATE_DEFAULT = 44100;
104
105/*
106 * Basic I/O
107 */
108
109/* check whether the clock mode is spdif-in */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100110static inline int is_spdif_master(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0;
113}
114
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100115static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
117 return is_spdif_master(ice) || PRO_RATE_LOCKED;
118}
119
120/*
121 * ac97 section
122 */
123
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100124static unsigned char snd_vt1724_ac97_ready(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
126 unsigned char old_cmd;
127 int tm;
128 for (tm = 0; tm < 0x10000; tm++) {
129 old_cmd = inb(ICEMT1724(ice, AC97_CMD));
130 if (old_cmd & (VT1724_AC97_WRITE | VT1724_AC97_READ))
131 continue;
132 if (!(old_cmd & VT1724_AC97_READY))
133 continue;
134 return old_cmd;
135 }
136 snd_printd(KERN_ERR "snd_vt1724_ac97_ready: timeout\n");
137 return old_cmd;
138}
139
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100140static int snd_vt1724_ac97_wait_bit(struct snd_ice1712 *ice, unsigned char bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
142 int tm;
143 for (tm = 0; tm < 0x10000; tm++)
144 if ((inb(ICEMT1724(ice, AC97_CMD)) & bit) == 0)
145 return 0;
146 snd_printd(KERN_ERR "snd_vt1724_ac97_wait_bit: timeout\n");
147 return -EIO;
148}
149
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100150static void snd_vt1724_ac97_write(struct snd_ac97 *ac97,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 unsigned short reg,
152 unsigned short val)
153{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100154 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 unsigned char old_cmd;
156
157 old_cmd = snd_vt1724_ac97_ready(ice);
158 old_cmd &= ~VT1724_AC97_ID_MASK;
159 old_cmd |= ac97->num;
160 outb(reg, ICEMT1724(ice, AC97_INDEX));
161 outw(val, ICEMT1724(ice, AC97_DATA));
162 outb(old_cmd | VT1724_AC97_WRITE, ICEMT1724(ice, AC97_CMD));
163 snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_WRITE);
164}
165
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100166static unsigned short snd_vt1724_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100168 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 unsigned char old_cmd;
170
171 old_cmd = snd_vt1724_ac97_ready(ice);
172 old_cmd &= ~VT1724_AC97_ID_MASK;
173 old_cmd |= ac97->num;
174 outb(reg, ICEMT1724(ice, AC97_INDEX));
175 outb(old_cmd | VT1724_AC97_READ, ICEMT1724(ice, AC97_CMD));
176 if (snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_READ) < 0)
177 return ~0;
178 return inw(ICEMT1724(ice, AC97_DATA));
179}
180
181
182/*
183 * GPIO operations
184 */
185
186/* set gpio direction 0 = read, 1 = write */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100187static void snd_vt1724_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
189 outl(data, ICEREG1724(ice, GPIO_DIRECTION));
190 inw(ICEREG1724(ice, GPIO_DIRECTION)); /* dummy read for pci-posting */
191}
192
193/* set the gpio mask (0 = writable) */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100194static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
196 outw(data, ICEREG1724(ice, GPIO_WRITE_MASK));
197 if (! ice->vt1720) /* VT1720 supports only 16 GPIO bits */
198 outb((data >> 16) & 0xff, ICEREG1724(ice, GPIO_WRITE_MASK_22));
199 inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */
200}
201
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100202static void snd_vt1724_set_gpio_data(struct snd_ice1712 *ice, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203{
204 outw(data, ICEREG1724(ice, GPIO_DATA));
205 if (! ice->vt1720)
206 outb(data >> 16, ICEREG1724(ice, GPIO_DATA_22));
207 inw(ICEREG1724(ice, GPIO_DATA)); /* dummy read for pci-posting */
208}
209
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100210static unsigned int snd_vt1724_get_gpio_data(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
212 unsigned int data;
213 if (! ice->vt1720)
214 data = (unsigned int)inb(ICEREG1724(ice, GPIO_DATA_22));
215 else
216 data = 0;
217 data = (data << 16) | inw(ICEREG1724(ice, GPIO_DATA));
218 return data;
219}
220
221/*
222 * Interrupt handler
223 */
224
David Howells7d12e782006-10-05 14:55:46 +0100225static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100227 struct snd_ice1712 *ice = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 unsigned char status;
229 int handled = 0;
230
231 while (1) {
232 status = inb(ICEREG1724(ice, IRQSTAT));
233 if (status == 0)
234 break;
235
236 handled = 1;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100237 /* these should probably be separated at some point,
238 * but as we don't currently have MPU support on the board
239 * I will leave it
240 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 if ((status & VT1724_IRQ_MPU_RX)||(status & VT1724_IRQ_MPU_TX)) {
242 if (ice->rmidi[0])
David Howells7d12e782006-10-05 14:55:46 +0100243 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 outb(status & (VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX), ICEREG1724(ice, IRQSTAT));
245 status &= ~(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX);
246 }
247 if (status & VT1724_IRQ_MTPCM) {
248 /*
249 * Multi-track PCM
250 * PCM assignment are:
251 * Playback DMA0 (M/C) = playback_pro_substream
252 * Playback DMA1 = playback_con_substream_ds[0]
253 * Playback DMA2 = playback_con_substream_ds[1]
254 * Playback DMA3 = playback_con_substream_ds[2]
255 * Playback DMA4 (SPDIF) = playback_con_substream
256 * Record DMA0 = capture_pro_substream
257 * Record DMA1 = capture_con_substream
258 */
259 unsigned char mtstat = inb(ICEMT1724(ice, IRQ));
260 if (mtstat & VT1724_MULTI_PDMA0) {
261 if (ice->playback_pro_substream)
262 snd_pcm_period_elapsed(ice->playback_pro_substream);
263 }
264 if (mtstat & VT1724_MULTI_RDMA0) {
265 if (ice->capture_pro_substream)
266 snd_pcm_period_elapsed(ice->capture_pro_substream);
267 }
268 if (mtstat & VT1724_MULTI_PDMA1) {
269 if (ice->playback_con_substream_ds[0])
270 snd_pcm_period_elapsed(ice->playback_con_substream_ds[0]);
271 }
272 if (mtstat & VT1724_MULTI_PDMA2) {
273 if (ice->playback_con_substream_ds[1])
274 snd_pcm_period_elapsed(ice->playback_con_substream_ds[1]);
275 }
276 if (mtstat & VT1724_MULTI_PDMA3) {
277 if (ice->playback_con_substream_ds[2])
278 snd_pcm_period_elapsed(ice->playback_con_substream_ds[2]);
279 }
280 if (mtstat & VT1724_MULTI_PDMA4) {
281 if (ice->playback_con_substream)
282 snd_pcm_period_elapsed(ice->playback_con_substream);
283 }
284 if (mtstat & VT1724_MULTI_RDMA1) {
285 if (ice->capture_con_substream)
286 snd_pcm_period_elapsed(ice->capture_con_substream);
287 }
288 /* ack anyway to avoid freeze */
289 outb(mtstat, ICEMT1724(ice, IRQ));
290 /* ought to really handle this properly */
291 if (mtstat & VT1724_MULTI_FIFO_ERR) {
292 unsigned char fstat = inb(ICEMT1724(ice, DMA_FIFO_ERR));
293 outb(fstat, ICEMT1724(ice, DMA_FIFO_ERR));
294 outb(VT1724_MULTI_FIFO_ERR | inb(ICEMT1724(ice, DMA_INT_MASK)), ICEMT1724(ice, DMA_INT_MASK));
295 /* If I don't do this, I get machine lockup due to continual interrupts */
296 }
297
298 }
299 }
300 return IRQ_RETVAL(handled);
301}
302
303/*
304 * PCM code - professional part (multitrack)
305 */
306
307static unsigned int rates[] = {
308 8000, 9600, 11025, 12000, 16000, 22050, 24000,
309 32000, 44100, 48000, 64000, 88200, 96000,
310 176400, 192000,
311};
312
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100313static struct snd_pcm_hw_constraint_list hw_constraints_rates_96 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 .count = ARRAY_SIZE(rates) - 2, /* up to 96000 */
315 .list = rates,
316 .mask = 0,
317};
318
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100319static struct snd_pcm_hw_constraint_list hw_constraints_rates_48 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 .count = ARRAY_SIZE(rates) - 5, /* up to 48000 */
321 .list = rates,
322 .mask = 0,
323};
324
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100325static struct snd_pcm_hw_constraint_list hw_constraints_rates_192 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 .count = ARRAY_SIZE(rates),
327 .list = rates,
328 .mask = 0,
329};
330
331struct vt1724_pcm_reg {
332 unsigned int addr; /* ADDR register offset */
333 unsigned int size; /* SIZE register offset */
334 unsigned int count; /* COUNT register offset */
335 unsigned int start; /* start & pause bit */
336};
337
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100338static int snd_vt1724_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100340 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 unsigned char what;
342 unsigned char old;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100343 struct snd_pcm_substream *s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
345 what = 0;
Takashi Iwaief991b92007-02-22 12:52:53 +0100346 snd_pcm_group_for_each_entry(s, substream) {
Clemens Ladisch29998d22007-07-30 08:14:31 +0200347 if (snd_pcm_substream_chip(s) == ice) {
348 const struct vt1724_pcm_reg *reg;
349 reg = s->runtime->private_data;
350 what |= reg->start;
351 snd_pcm_trigger_done(s, substream);
352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 }
354
355 switch (cmd) {
356 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
357 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
358 spin_lock(&ice->reg_lock);
359 old = inb(ICEMT1724(ice, DMA_PAUSE));
360 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
361 old |= what;
362 else
363 old &= ~what;
364 outb(old, ICEMT1724(ice, DMA_PAUSE));
365 spin_unlock(&ice->reg_lock);
366 break;
367
368 case SNDRV_PCM_TRIGGER_START:
369 case SNDRV_PCM_TRIGGER_STOP:
370 spin_lock(&ice->reg_lock);
371 old = inb(ICEMT1724(ice, DMA_CONTROL));
372 if (cmd == SNDRV_PCM_TRIGGER_START)
373 old |= what;
374 else
375 old &= ~what;
376 outb(old, ICEMT1724(ice, DMA_CONTROL));
377 spin_unlock(&ice->reg_lock);
378 break;
379
380 default:
381 return -EINVAL;
382 }
383 return 0;
384}
385
386/*
387 */
388
389#define DMA_STARTS (VT1724_RDMA0_START|VT1724_PDMA0_START|VT1724_RDMA1_START|\
390 VT1724_PDMA1_START|VT1724_PDMA2_START|VT1724_PDMA3_START|VT1724_PDMA4_START)
391#define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\
392 VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE)
393
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100394static int get_max_rate(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
396 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
397 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
398 return 192000;
399 else
400 return 96000;
401 } else
402 return 48000;
403}
404
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100405static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
406 int force)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407{
408 unsigned long flags;
409 unsigned char val, old;
410 unsigned int i, mclk_change;
411
412 if (rate > get_max_rate(ice))
413 return;
414
415 switch (rate) {
416 case 8000: val = 6; break;
417 case 9600: val = 3; break;
418 case 11025: val = 10; break;
419 case 12000: val = 2; break;
420 case 16000: val = 5; break;
421 case 22050: val = 9; break;
422 case 24000: val = 1; break;
423 case 32000: val = 4; break;
424 case 44100: val = 8; break;
425 case 48000: val = 0; break;
426 case 64000: val = 15; break;
427 case 88200: val = 11; break;
428 case 96000: val = 7; break;
429 case 176400: val = 12; break;
430 case 192000: val = 14; break;
431 default:
432 snd_BUG();
433 val = 0;
434 break;
435 }
436
437 spin_lock_irqsave(&ice->reg_lock, flags);
438 if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) ||
439 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
440 /* running? we cannot change the rate now... */
441 spin_unlock_irqrestore(&ice->reg_lock, flags);
442 return;
443 }
444 if (!force && is_pro_rate_locked(ice)) {
445 spin_unlock_irqrestore(&ice->reg_lock, flags);
446 return;
447 }
448
449 old = inb(ICEMT1724(ice, RATE));
450 if (force || old != val)
451 outb(val, ICEMT1724(ice, RATE));
452 else if (rate == ice->cur_rate) {
453 spin_unlock_irqrestore(&ice->reg_lock, flags);
454 return;
455 }
456
457 ice->cur_rate = rate;
458
459 /* check MT02 */
460 mclk_change = 0;
461 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
462 val = old = inb(ICEMT1724(ice, I2S_FORMAT));
463 if (rate > 96000)
464 val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
465 else
466 val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
467 if (val != old) {
468 outb(val, ICEMT1724(ice, I2S_FORMAT));
469 mclk_change = 1;
470 }
471 }
472 spin_unlock_irqrestore(&ice->reg_lock, flags);
473
474 if (mclk_change && ice->gpio.i2s_mclk_changed)
475 ice->gpio.i2s_mclk_changed(ice);
476 if (ice->gpio.set_pro_rate)
477 ice->gpio.set_pro_rate(ice, rate);
478
479 /* set up codecs */
480 for (i = 0; i < ice->akm_codecs; i++) {
481 if (ice->akm[i].ops.set_rate_val)
482 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
483 }
484 if (ice->spdif.ops.setup_rate)
485 ice->spdif.ops.setup_rate(ice, rate);
486}
487
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100488static int snd_vt1724_pcm_hw_params(struct snd_pcm_substream *substream,
489 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100491 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 int i, chs;
493
494 chs = params_channels(hw_params);
Ingo Molnar62932df2006-01-16 16:34:20 +0100495 mutex_lock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 /* mark surround channels */
497 if (substream == ice->playback_pro_substream) {
498 /* PDMA0 can be multi-channel up to 8 */
499 chs = chs / 2 - 1;
500 for (i = 0; i < chs; i++) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100501 if (ice->pcm_reserved[i] &&
502 ice->pcm_reserved[i] != substream) {
Ingo Molnar62932df2006-01-16 16:34:20 +0100503 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 return -EBUSY;
505 }
506 ice->pcm_reserved[i] = substream;
507 }
508 for (; i < 3; i++) {
509 if (ice->pcm_reserved[i] == substream)
510 ice->pcm_reserved[i] = NULL;
511 }
512 } else {
513 for (i = 0; i < 3; i++) {
514 /* check individual playback stream */
515 if (ice->playback_con_substream_ds[i] == substream) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100516 if (ice->pcm_reserved[i] &&
517 ice->pcm_reserved[i] != substream) {
Ingo Molnar62932df2006-01-16 16:34:20 +0100518 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 return -EBUSY;
520 }
521 ice->pcm_reserved[i] = substream;
522 break;
523 }
524 }
525 }
Ingo Molnar62932df2006-01-16 16:34:20 +0100526 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 snd_vt1724_set_pro_rate(ice, params_rate(hw_params), 0);
528 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
529}
530
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100531static int snd_vt1724_pcm_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100533 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 int i;
535
Ingo Molnar62932df2006-01-16 16:34:20 +0100536 mutex_lock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 /* unmark surround channels */
538 for (i = 0; i < 3; i++)
539 if (ice->pcm_reserved[i] == substream)
540 ice->pcm_reserved[i] = NULL;
Ingo Molnar62932df2006-01-16 16:34:20 +0100541 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 return snd_pcm_lib_free_pages(substream);
543}
544
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100545static int snd_vt1724_playback_pro_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100547 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 unsigned char val;
549 unsigned int size;
550
551 spin_lock_irq(&ice->reg_lock);
552 val = (8 - substream->runtime->channels) >> 1;
553 outb(val, ICEMT1724(ice, BURST));
554
555 outl(substream->runtime->dma_addr, ICEMT1724(ice, PLAYBACK_ADDR));
556
557 size = (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1;
558 // outl(size, ICEMT1724(ice, PLAYBACK_SIZE));
559 outw(size, ICEMT1724(ice, PLAYBACK_SIZE));
560 outb(size >> 16, ICEMT1724(ice, PLAYBACK_SIZE) + 2);
561 size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
562 // outl(size, ICEMT1724(ice, PLAYBACK_COUNT));
563 outw(size, ICEMT1724(ice, PLAYBACK_COUNT));
564 outb(size >> 16, ICEMT1724(ice, PLAYBACK_COUNT) + 2);
565
566 spin_unlock_irq(&ice->reg_lock);
567
568 // printk("pro prepare: ch = %d, addr = 0x%x, buffer = 0x%x, period = 0x%x\n", substream->runtime->channels, (unsigned int)substream->runtime->dma_addr, snd_pcm_lib_buffer_bytes(substream), snd_pcm_lib_period_bytes(substream));
569 return 0;
570}
571
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100572static snd_pcm_uframes_t snd_vt1724_playback_pro_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100574 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 size_t ptr;
576
577 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & VT1724_PDMA0_START))
578 return 0;
579#if 0 /* read PLAYBACK_ADDR */
580 ptr = inl(ICEMT1724(ice, PLAYBACK_ADDR));
581 if (ptr < substream->runtime->dma_addr) {
582 snd_printd("ice1724: invalid negative ptr\n");
583 return 0;
584 }
585 ptr -= substream->runtime->dma_addr;
586 ptr = bytes_to_frames(substream->runtime, ptr);
587 if (ptr >= substream->runtime->buffer_size) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100588 snd_printd("ice1724: invalid ptr %d (size=%d)\n",
589 (int)ptr, (int)substream->runtime->period_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 return 0;
591 }
592#else /* read PLAYBACK_SIZE */
593 ptr = inl(ICEMT1724(ice, PLAYBACK_SIZE)) & 0xffffff;
594 ptr = (ptr + 1) << 2;
595 ptr = bytes_to_frames(substream->runtime, ptr);
596 if (! ptr)
597 ;
598 else if (ptr <= substream->runtime->buffer_size)
599 ptr = substream->runtime->buffer_size - ptr;
600 else {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100601 snd_printd("ice1724: invalid ptr %d (size=%d)\n",
602 (int)ptr, (int)substream->runtime->buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 ptr = 0;
604 }
605#endif
606 return ptr;
607}
608
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100609static int snd_vt1724_pcm_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100611 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Takashi Iwai32b47da2007-01-29 15:26:36 +0100612 const struct vt1724_pcm_reg *reg = substream->runtime->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
614 spin_lock_irq(&ice->reg_lock);
615 outl(substream->runtime->dma_addr, ice->profi_port + reg->addr);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100616 outw((snd_pcm_lib_buffer_bytes(substream) >> 2) - 1,
617 ice->profi_port + reg->size);
618 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1,
619 ice->profi_port + reg->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 spin_unlock_irq(&ice->reg_lock);
621 return 0;
622}
623
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100624static snd_pcm_uframes_t snd_vt1724_pcm_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100626 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Takashi Iwai32b47da2007-01-29 15:26:36 +0100627 const struct vt1724_pcm_reg *reg = substream->runtime->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 size_t ptr;
629
630 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & reg->start))
631 return 0;
632#if 0 /* use ADDR register */
633 ptr = inl(ice->profi_port + reg->addr);
634 ptr -= substream->runtime->dma_addr;
635 return bytes_to_frames(substream->runtime, ptr);
636#else /* use SIZE register */
637 ptr = inw(ice->profi_port + reg->size);
638 ptr = (ptr + 1) << 2;
639 ptr = bytes_to_frames(substream->runtime, ptr);
640 if (! ptr)
641 ;
642 else if (ptr <= substream->runtime->buffer_size)
643 ptr = substream->runtime->buffer_size - ptr;
644 else {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100645 snd_printd("ice1724: invalid ptr %d (size=%d)\n",
646 (int)ptr, (int)substream->runtime->buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 ptr = 0;
648 }
649 return ptr;
650#endif
651}
652
Takashi Iwai32b47da2007-01-29 15:26:36 +0100653static const struct vt1724_pcm_reg vt1724_playback_pro_reg = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 .addr = VT1724_MT_PLAYBACK_ADDR,
655 .size = VT1724_MT_PLAYBACK_SIZE,
656 .count = VT1724_MT_PLAYBACK_COUNT,
657 .start = VT1724_PDMA0_START,
658};
659
Takashi Iwai32b47da2007-01-29 15:26:36 +0100660static const struct vt1724_pcm_reg vt1724_capture_pro_reg = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 .addr = VT1724_MT_CAPTURE_ADDR,
662 .size = VT1724_MT_CAPTURE_SIZE,
663 .count = VT1724_MT_CAPTURE_COUNT,
664 .start = VT1724_RDMA0_START,
665};
666
Takashi Iwai32b47da2007-01-29 15:26:36 +0100667static const struct snd_pcm_hardware snd_vt1724_playback_pro =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668{
669 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
670 SNDRV_PCM_INFO_BLOCK_TRANSFER |
671 SNDRV_PCM_INFO_MMAP_VALID |
672 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
673 .formats = SNDRV_PCM_FMTBIT_S32_LE,
674 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
675 .rate_min = 8000,
676 .rate_max = 192000,
677 .channels_min = 2,
678 .channels_max = 8,
679 .buffer_bytes_max = (1UL << 21), /* 19bits dword */
680 .period_bytes_min = 8 * 4 * 2, /* FIXME: constraints needed */
681 .period_bytes_max = (1UL << 21),
682 .periods_min = 2,
683 .periods_max = 1024,
684};
685
Takashi Iwai32b47da2007-01-29 15:26:36 +0100686static const struct snd_pcm_hardware snd_vt1724_spdif =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687{
688 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
689 SNDRV_PCM_INFO_BLOCK_TRANSFER |
690 SNDRV_PCM_INFO_MMAP_VALID |
691 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
692 .formats = SNDRV_PCM_FMTBIT_S32_LE,
Takashi Iwai2dfbeca2005-10-12 10:04:42 +0200693 .rates = (SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100|
694 SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_88200|
695 SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_176400|
696 SNDRV_PCM_RATE_192000),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 .rate_min = 32000,
Takashi Iwai2dfbeca2005-10-12 10:04:42 +0200698 .rate_max = 192000,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 .channels_min = 2,
700 .channels_max = 2,
701 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
702 .period_bytes_min = 2 * 4 * 2,
703 .period_bytes_max = (1UL << 18),
704 .periods_min = 2,
705 .periods_max = 1024,
706};
707
Takashi Iwai32b47da2007-01-29 15:26:36 +0100708static const struct snd_pcm_hardware snd_vt1724_2ch_stereo =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709{
710 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
711 SNDRV_PCM_INFO_BLOCK_TRANSFER |
712 SNDRV_PCM_INFO_MMAP_VALID |
713 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
714 .formats = SNDRV_PCM_FMTBIT_S32_LE,
715 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
716 .rate_min = 8000,
717 .rate_max = 192000,
718 .channels_min = 2,
719 .channels_max = 2,
720 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
721 .period_bytes_min = 2 * 4 * 2,
722 .period_bytes_max = (1UL << 18),
723 .periods_min = 2,
724 .periods_max = 1024,
725};
726
727/*
728 * set rate constraints
729 */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100730static int set_rate_constraints(struct snd_ice1712 *ice,
731 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100733 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 if (ice->hw_rates) {
735 /* hardware specific */
736 runtime->hw.rate_min = ice->hw_rates->list[0];
737 runtime->hw.rate_max = ice->hw_rates->list[ice->hw_rates->count - 1];
738 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100739 return snd_pcm_hw_constraint_list(runtime, 0,
740 SNDRV_PCM_HW_PARAM_RATE,
741 ice->hw_rates);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 }
743 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
744 /* I2S */
745 /* VT1720 doesn't support more than 96kHz */
746 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100747 return snd_pcm_hw_constraint_list(runtime, 0,
748 SNDRV_PCM_HW_PARAM_RATE,
749 &hw_constraints_rates_192);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 else {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100751 runtime->hw.rates = SNDRV_PCM_RATE_KNOT |
752 SNDRV_PCM_RATE_8000_96000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 runtime->hw.rate_max = 96000;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100754 return snd_pcm_hw_constraint_list(runtime, 0,
755 SNDRV_PCM_HW_PARAM_RATE,
756 &hw_constraints_rates_96);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 }
758 } else if (ice->ac97) {
759 /* ACLINK */
760 runtime->hw.rate_max = 48000;
761 runtime->hw.rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100762 return snd_pcm_hw_constraint_list(runtime, 0,
763 SNDRV_PCM_HW_PARAM_RATE,
764 &hw_constraints_rates_48);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 }
766 return 0;
767}
768
769/* multi-channel playback needs alignment 8x32bit regardless of the channels
770 * actually used
771 */
772#define VT1724_BUFFER_ALIGN 0x20
773
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100774static int snd_vt1724_playback_pro_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100776 struct snd_pcm_runtime *runtime = substream->runtime;
777 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 int chs;
779
Takashi Iwai32b47da2007-01-29 15:26:36 +0100780 runtime->private_data = (void *)&vt1724_playback_pro_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 ice->playback_pro_substream = substream;
782 runtime->hw = snd_vt1724_playback_pro;
783 snd_pcm_set_sync(substream);
784 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
785 set_rate_constraints(ice, substream);
Ingo Molnar62932df2006-01-16 16:34:20 +0100786 mutex_lock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 /* calculate the currently available channels */
788 for (chs = 0; chs < 3; chs++) {
789 if (ice->pcm_reserved[chs])
790 break;
791 }
792 chs = (chs + 1) * 2;
793 runtime->hw.channels_max = chs;
794 if (chs > 2) /* channels must be even */
795 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Ingo Molnar62932df2006-01-16 16:34:20 +0100796 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
798 VT1724_BUFFER_ALIGN);
799 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
800 VT1724_BUFFER_ALIGN);
801 return 0;
802}
803
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100804static int snd_vt1724_capture_pro_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100806 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
807 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Takashi Iwai32b47da2007-01-29 15:26:36 +0100809 runtime->private_data = (void *)&vt1724_capture_pro_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 ice->capture_pro_substream = substream;
811 runtime->hw = snd_vt1724_2ch_stereo;
812 snd_pcm_set_sync(substream);
813 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
814 set_rate_constraints(ice, substream);
815 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
816 VT1724_BUFFER_ALIGN);
817 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
818 VT1724_BUFFER_ALIGN);
819 return 0;
820}
821
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100822static int snd_vt1724_playback_pro_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100824 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 if (PRO_RATE_RESET)
827 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
828 ice->playback_pro_substream = NULL;
829
830 return 0;
831}
832
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100833static int snd_vt1724_capture_pro_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100835 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
837 if (PRO_RATE_RESET)
838 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
839 ice->capture_pro_substream = NULL;
840 return 0;
841}
842
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100843static struct snd_pcm_ops snd_vt1724_playback_pro_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 .open = snd_vt1724_playback_pro_open,
845 .close = snd_vt1724_playback_pro_close,
846 .ioctl = snd_pcm_lib_ioctl,
847 .hw_params = snd_vt1724_pcm_hw_params,
848 .hw_free = snd_vt1724_pcm_hw_free,
849 .prepare = snd_vt1724_playback_pro_prepare,
850 .trigger = snd_vt1724_pcm_trigger,
851 .pointer = snd_vt1724_playback_pro_pointer,
852};
853
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100854static struct snd_pcm_ops snd_vt1724_capture_pro_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 .open = snd_vt1724_capture_pro_open,
856 .close = snd_vt1724_capture_pro_close,
857 .ioctl = snd_pcm_lib_ioctl,
858 .hw_params = snd_vt1724_pcm_hw_params,
859 .hw_free = snd_vt1724_pcm_hw_free,
860 .prepare = snd_vt1724_pcm_prepare,
861 .trigger = snd_vt1724_pcm_trigger,
862 .pointer = snd_vt1724_pcm_pointer,
863};
864
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100865static int __devinit snd_vt1724_pcm_profi(struct snd_ice1712 * ice, int device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100867 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 int err;
869
870 err = snd_pcm_new(ice->card, "ICE1724", device, 1, 1, &pcm);
871 if (err < 0)
872 return err;
873
874 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_vt1724_playback_pro_ops);
875 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_vt1724_capture_pro_ops);
876
877 pcm->private_data = ice;
878 pcm->info_flags = 0;
879 strcpy(pcm->name, "ICE1724");
880
881 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100882 snd_dma_pci_data(ice->pci),
883 256*1024, 256*1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884
885 ice->pcm_pro = pcm;
886
887 return 0;
888}
889
890
891/*
892 * SPDIF PCM
893 */
894
Takashi Iwai32b47da2007-01-29 15:26:36 +0100895static const struct vt1724_pcm_reg vt1724_playback_spdif_reg = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 .addr = VT1724_MT_PDMA4_ADDR,
897 .size = VT1724_MT_PDMA4_SIZE,
898 .count = VT1724_MT_PDMA4_COUNT,
899 .start = VT1724_PDMA4_START,
900};
901
Takashi Iwai32b47da2007-01-29 15:26:36 +0100902static const struct vt1724_pcm_reg vt1724_capture_spdif_reg = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 .addr = VT1724_MT_RDMA1_ADDR,
904 .size = VT1724_MT_RDMA1_SIZE,
905 .count = VT1724_MT_RDMA1_COUNT,
906 .start = VT1724_RDMA1_START,
907};
908
909/* update spdif control bits; call with reg_lock */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100910static void update_spdif_bits(struct snd_ice1712 *ice, unsigned int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911{
912 unsigned char cbit, disabled;
913
914 cbit = inb(ICEREG1724(ice, SPDIF_CFG));
915 disabled = cbit & ~VT1724_CFG_SPDIF_OUT_EN;
916 if (cbit != disabled)
917 outb(disabled, ICEREG1724(ice, SPDIF_CFG));
918 outw(val, ICEMT1724(ice, SPDIF_CTRL));
919 if (cbit != disabled)
920 outb(cbit, ICEREG1724(ice, SPDIF_CFG));
921 outw(val, ICEMT1724(ice, SPDIF_CTRL));
922}
923
924/* update SPDIF control bits according to the given rate */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100925static void update_spdif_rate(struct snd_ice1712 *ice, unsigned int rate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926{
927 unsigned int val, nval;
928 unsigned long flags;
929
930 spin_lock_irqsave(&ice->reg_lock, flags);
931 nval = val = inw(ICEMT1724(ice, SPDIF_CTRL));
932 nval &= ~(7 << 12);
933 switch (rate) {
934 case 44100: break;
935 case 48000: nval |= 2 << 12; break;
936 case 32000: nval |= 3 << 12; break;
Takashi Iwai2dfbeca2005-10-12 10:04:42 +0200937 case 88200: nval |= 4 << 12; break;
938 case 96000: nval |= 5 << 12; break;
939 case 192000: nval |= 6 << 12; break;
940 case 176400: nval |= 7 << 12; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 }
942 if (val != nval)
943 update_spdif_bits(ice, nval);
944 spin_unlock_irqrestore(&ice->reg_lock, flags);
945}
946
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100947static int snd_vt1724_playback_spdif_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100949 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 if (! ice->force_pdma4)
951 update_spdif_rate(ice, substream->runtime->rate);
952 return snd_vt1724_pcm_prepare(substream);
953}
954
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100955static int snd_vt1724_playback_spdif_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100957 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
958 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
Takashi Iwai32b47da2007-01-29 15:26:36 +0100960 runtime->private_data = (void *)&vt1724_playback_spdif_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 ice->playback_con_substream = substream;
962 if (ice->force_pdma4) {
963 runtime->hw = snd_vt1724_2ch_stereo;
964 set_rate_constraints(ice, substream);
965 } else
966 runtime->hw = snd_vt1724_spdif;
967 snd_pcm_set_sync(substream);
968 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
969 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
970 VT1724_BUFFER_ALIGN);
971 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
972 VT1724_BUFFER_ALIGN);
Takashi Iwaic93f5a12008-03-14 17:17:09 +0100973 if (ice->spdif.ops.open)
974 ice->spdif.ops.open(ice, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 return 0;
976}
977
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100978static int snd_vt1724_playback_spdif_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100980 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
982 if (PRO_RATE_RESET)
983 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
984 ice->playback_con_substream = NULL;
Takashi Iwaic93f5a12008-03-14 17:17:09 +0100985 if (ice->spdif.ops.close)
986 ice->spdif.ops.close(ice, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
988 return 0;
989}
990
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100991static int snd_vt1724_capture_spdif_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100993 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
994 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
Takashi Iwai32b47da2007-01-29 15:26:36 +0100996 runtime->private_data = (void *)&vt1724_capture_spdif_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 ice->capture_con_substream = substream;
998 if (ice->force_rdma1) {
999 runtime->hw = snd_vt1724_2ch_stereo;
1000 set_rate_constraints(ice, substream);
1001 } else
1002 runtime->hw = snd_vt1724_spdif;
1003 snd_pcm_set_sync(substream);
1004 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1005 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
1006 VT1724_BUFFER_ALIGN);
1007 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
1008 VT1724_BUFFER_ALIGN);
Takashi Iwaic93f5a12008-03-14 17:17:09 +01001009 if (ice->spdif.ops.open)
1010 ice->spdif.ops.open(ice, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 return 0;
1012}
1013
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001014static int snd_vt1724_capture_spdif_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001016 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
1018 if (PRO_RATE_RESET)
1019 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1020 ice->capture_con_substream = NULL;
Takashi Iwaic93f5a12008-03-14 17:17:09 +01001021 if (ice->spdif.ops.close)
1022 ice->spdif.ops.close(ice, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
1024 return 0;
1025}
1026
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001027static struct snd_pcm_ops snd_vt1724_playback_spdif_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 .open = snd_vt1724_playback_spdif_open,
1029 .close = snd_vt1724_playback_spdif_close,
1030 .ioctl = snd_pcm_lib_ioctl,
1031 .hw_params = snd_vt1724_pcm_hw_params,
1032 .hw_free = snd_vt1724_pcm_hw_free,
1033 .prepare = snd_vt1724_playback_spdif_prepare,
1034 .trigger = snd_vt1724_pcm_trigger,
1035 .pointer = snd_vt1724_pcm_pointer,
1036};
1037
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001038static struct snd_pcm_ops snd_vt1724_capture_spdif_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 .open = snd_vt1724_capture_spdif_open,
1040 .close = snd_vt1724_capture_spdif_close,
1041 .ioctl = snd_pcm_lib_ioctl,
1042 .hw_params = snd_vt1724_pcm_hw_params,
1043 .hw_free = snd_vt1724_pcm_hw_free,
1044 .prepare = snd_vt1724_pcm_prepare,
1045 .trigger = snd_vt1724_pcm_trigger,
1046 .pointer = snd_vt1724_pcm_pointer,
1047};
1048
1049
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001050static int __devinit snd_vt1724_pcm_spdif(struct snd_ice1712 * ice, int device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051{
1052 char *name;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001053 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 int play, capt;
1055 int err;
1056
1057 if (ice->force_pdma4 ||
1058 (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_OUT_INT)) {
1059 play = 1;
1060 ice->has_spdif = 1;
1061 } else
1062 play = 0;
1063 if (ice->force_rdma1 ||
1064 (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_IN)) {
1065 capt = 1;
1066 ice->has_spdif = 1;
1067 } else
1068 capt = 0;
1069 if (! play && ! capt)
1070 return 0; /* no spdif device */
1071
1072 if (ice->force_pdma4 || ice->force_rdma1)
1073 name = "ICE1724 Secondary";
1074 else
1075 name = "IEC1724 IEC958";
1076 err = snd_pcm_new(ice->card, name, device, play, capt, &pcm);
1077 if (err < 0)
1078 return err;
1079
1080 if (play)
1081 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1082 &snd_vt1724_playback_spdif_ops);
1083 if (capt)
1084 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1085 &snd_vt1724_capture_spdif_ops);
1086
1087 pcm->private_data = ice;
1088 pcm->info_flags = 0;
1089 strcpy(pcm->name, name);
1090
1091 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001092 snd_dma_pci_data(ice->pci),
1093 64*1024, 64*1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
1095 ice->pcm = pcm;
1096
1097 return 0;
1098}
1099
1100
1101/*
1102 * independent surround PCMs
1103 */
1104
Takashi Iwai32b47da2007-01-29 15:26:36 +01001105static const struct vt1724_pcm_reg vt1724_playback_dma_regs[3] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 {
1107 .addr = VT1724_MT_PDMA1_ADDR,
1108 .size = VT1724_MT_PDMA1_SIZE,
1109 .count = VT1724_MT_PDMA1_COUNT,
1110 .start = VT1724_PDMA1_START,
1111 },
1112 {
1113 .addr = VT1724_MT_PDMA2_ADDR,
1114 .size = VT1724_MT_PDMA2_SIZE,
1115 .count = VT1724_MT_PDMA2_COUNT,
1116 .start = VT1724_PDMA2_START,
1117 },
1118 {
1119 .addr = VT1724_MT_PDMA3_ADDR,
1120 .size = VT1724_MT_PDMA3_SIZE,
1121 .count = VT1724_MT_PDMA3_COUNT,
1122 .start = VT1724_PDMA3_START,
1123 },
1124};
1125
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001126static int snd_vt1724_playback_indep_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001128 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 unsigned char val;
1130
1131 spin_lock_irq(&ice->reg_lock);
1132 val = 3 - substream->number;
1133 if (inb(ICEMT1724(ice, BURST)) < val)
1134 outb(val, ICEMT1724(ice, BURST));
1135 spin_unlock_irq(&ice->reg_lock);
1136 return snd_vt1724_pcm_prepare(substream);
1137}
1138
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001139static int snd_vt1724_playback_indep_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001141 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1142 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
Ingo Molnar62932df2006-01-16 16:34:20 +01001144 mutex_lock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 /* already used by PDMA0? */
1146 if (ice->pcm_reserved[substream->number]) {
Ingo Molnar62932df2006-01-16 16:34:20 +01001147 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 return -EBUSY; /* FIXME: should handle blocking mode properly */
1149 }
Ingo Molnar62932df2006-01-16 16:34:20 +01001150 mutex_unlock(&ice->open_mutex);
Takashi Iwai32b47da2007-01-29 15:26:36 +01001151 runtime->private_data = (void *)&vt1724_playback_dma_regs[substream->number];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 ice->playback_con_substream_ds[substream->number] = substream;
1153 runtime->hw = snd_vt1724_2ch_stereo;
1154 snd_pcm_set_sync(substream);
1155 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1156 set_rate_constraints(ice, substream);
1157 return 0;
1158}
1159
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001160static int snd_vt1724_playback_indep_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001162 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
1164 if (PRO_RATE_RESET)
1165 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1166 ice->playback_con_substream_ds[substream->number] = NULL;
1167 ice->pcm_reserved[substream->number] = NULL;
1168
1169 return 0;
1170}
1171
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001172static struct snd_pcm_ops snd_vt1724_playback_indep_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 .open = snd_vt1724_playback_indep_open,
1174 .close = snd_vt1724_playback_indep_close,
1175 .ioctl = snd_pcm_lib_ioctl,
1176 .hw_params = snd_vt1724_pcm_hw_params,
1177 .hw_free = snd_vt1724_pcm_hw_free,
1178 .prepare = snd_vt1724_playback_indep_prepare,
1179 .trigger = snd_vt1724_pcm_trigger,
1180 .pointer = snd_vt1724_pcm_pointer,
1181};
1182
1183
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001184static int __devinit snd_vt1724_pcm_indep(struct snd_ice1712 * ice, int device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001186 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 int play;
1188 int err;
1189
1190 play = ice->num_total_dacs / 2 - 1;
1191 if (play <= 0)
1192 return 0;
1193
1194 err = snd_pcm_new(ice->card, "ICE1724 Surrounds", device, play, 0, &pcm);
1195 if (err < 0)
1196 return err;
1197
1198 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1199 &snd_vt1724_playback_indep_ops);
1200
1201 pcm->private_data = ice;
1202 pcm->info_flags = 0;
1203 strcpy(pcm->name, "ICE1724 Surround PCM");
1204
1205 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001206 snd_dma_pci_data(ice->pci),
1207 64*1024, 64*1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
1209 ice->pcm_ds = pcm;
1210
1211 return 0;
1212}
1213
1214
1215/*
1216 * Mixer section
1217 */
1218
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001219static int __devinit snd_vt1724_ac97_mixer(struct snd_ice1712 * ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220{
1221 int err;
1222
1223 if (! (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S)) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001224 struct snd_ac97_bus *pbus;
1225 struct snd_ac97_template ac97;
1226 static struct snd_ac97_bus_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 .write = snd_vt1724_ac97_write,
1228 .read = snd_vt1724_ac97_read,
1229 };
1230
1231 /* cold reset */
1232 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
1233 mdelay(5); /* FIXME */
1234 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
1235
1236 if ((err = snd_ac97_bus(ice->card, 0, &ops, NULL, &pbus)) < 0)
1237 return err;
1238 memset(&ac97, 0, sizeof(ac97));
1239 ac97.private_data = ice;
1240 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1241 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1242 else
1243 return 0;
1244 }
1245 /* I2S mixer only */
1246 strcat(ice->card->mixername, "ICE1724 - multitrack");
1247 return 0;
1248}
1249
1250/*
1251 *
1252 */
1253
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001254static inline unsigned int eeprom_triple(struct snd_ice1712 *ice, int idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255{
1256 return (unsigned int)ice->eeprom.data[idx] | \
1257 ((unsigned int)ice->eeprom.data[idx + 1] << 8) | \
1258 ((unsigned int)ice->eeprom.data[idx + 2] << 16);
1259}
1260
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001261static void snd_vt1724_proc_read(struct snd_info_entry *entry,
1262 struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001264 struct snd_ice1712 *ice = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 unsigned int idx;
1266
1267 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1268 snd_iprintf(buffer, "EEPROM:\n");
1269
1270 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1271 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1272 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001273 snd_iprintf(buffer, " System Config : 0x%x\n",
1274 ice->eeprom.data[ICE_EEP2_SYSCONF]);
1275 snd_iprintf(buffer, " ACLink : 0x%x\n",
1276 ice->eeprom.data[ICE_EEP2_ACLINK]);
1277 snd_iprintf(buffer, " I2S : 0x%x\n",
1278 ice->eeprom.data[ICE_EEP2_I2S]);
1279 snd_iprintf(buffer, " S/PDIF : 0x%x\n",
1280 ice->eeprom.data[ICE_EEP2_SPDIF]);
1281 snd_iprintf(buffer, " GPIO direction : 0x%x\n",
1282 ice->eeprom.gpiodir);
1283 snd_iprintf(buffer, " GPIO mask : 0x%x\n",
1284 ice->eeprom.gpiomask);
1285 snd_iprintf(buffer, " GPIO state : 0x%x\n",
1286 ice->eeprom.gpiostate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 for (idx = 0x12; idx < ice->eeprom.size; idx++)
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001288 snd_iprintf(buffer, " Extra #%02i : 0x%x\n",
1289 idx, ice->eeprom.data[idx]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
1291 snd_iprintf(buffer, "\nRegisters:\n");
1292
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001293 snd_iprintf(buffer, " PSDOUT03 : 0x%08x\n",
1294 (unsigned)inl(ICEMT1724(ice, ROUTE_PLAYBACK)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 for (idx = 0x0; idx < 0x20 ; idx++)
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001296 snd_iprintf(buffer, " CCS%02x : 0x%02x\n",
1297 idx, inb(ice->port+idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 for (idx = 0x0; idx < 0x30 ; idx++)
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001299 snd_iprintf(buffer, " MT%02x : 0x%02x\n",
1300 idx, inb(ice->profi_port+idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301}
1302
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001303static void __devinit snd_vt1724_proc_init(struct snd_ice1712 * ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001305 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
1307 if (! snd_card_proc_new(ice->card, "ice1724", &entry))
Takashi Iwaibf850202006-04-28 15:13:41 +02001308 snd_info_set_text_ops(entry, ice, snd_vt1724_proc_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309}
1310
1311/*
1312 *
1313 */
1314
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001315static int snd_vt1724_eeprom_info(struct snd_kcontrol *kcontrol,
1316 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317{
1318 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001319 uinfo->count = sizeof(struct snd_ice1712_eeprom);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 return 0;
1321}
1322
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001323static int snd_vt1724_eeprom_get(struct snd_kcontrol *kcontrol,
1324 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001326 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
1328 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1329 return 0;
1330}
1331
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001332static struct snd_kcontrol_new snd_vt1724_eeprom __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1334 .name = "ICE1724 EEPROM",
1335 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1336 .info = snd_vt1724_eeprom_info,
1337 .get = snd_vt1724_eeprom_get
1338};
1339
1340/*
1341 */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001342static int snd_vt1724_spdif_info(struct snd_kcontrol *kcontrol,
1343 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344{
1345 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1346 uinfo->count = 1;
1347 return 0;
1348}
1349
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001350static unsigned int encode_spdif_bits(struct snd_aes_iec958 *diga)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351{
Takashi Iwai2dfbeca2005-10-12 10:04:42 +02001352 unsigned int val, rbits;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353
1354 val = diga->status[0] & 0x03; /* professional, non-audio */
1355 if (val & 0x01) {
1356 /* professional */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001357 if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) ==
1358 IEC958_AES0_PRO_EMPHASIS_5015)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 val |= 1U << 3;
Takashi Iwai2dfbeca2005-10-12 10:04:42 +02001360 rbits = (diga->status[4] >> 3) & 0x0f;
1361 if (rbits) {
1362 switch (rbits) {
1363 case 2: val |= 5 << 12; break; /* 96k */
1364 case 3: val |= 6 << 12; break; /* 192k */
1365 case 10: val |= 4 << 12; break; /* 88.2k */
1366 case 11: val |= 7 << 12; break; /* 176.4k */
1367 }
1368 } else {
1369 switch (diga->status[0] & IEC958_AES0_PRO_FS) {
1370 case IEC958_AES0_PRO_FS_44100:
1371 break;
1372 case IEC958_AES0_PRO_FS_32000:
1373 val |= 3U << 12;
1374 break;
1375 default:
1376 val |= 2U << 12;
1377 break;
1378 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 }
1380 } else {
1381 /* consumer */
1382 val |= diga->status[1] & 0x04; /* copyright */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001383 if ((diga->status[0] & IEC958_AES0_CON_EMPHASIS) ==
1384 IEC958_AES0_CON_EMPHASIS_5015)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 val |= 1U << 3;
1386 val |= (unsigned int)(diga->status[1] & 0x3f) << 4; /* category */
1387 val |= (unsigned int)(diga->status[3] & IEC958_AES3_CON_FS) << 12; /* fs */
1388 }
1389 return val;
1390}
1391
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001392static void decode_spdif_bits(struct snd_aes_iec958 *diga, unsigned int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393{
1394 memset(diga->status, 0, sizeof(diga->status));
1395 diga->status[0] = val & 0x03; /* professional, non-audio */
1396 if (val & 0x01) {
1397 /* professional */
1398 if (val & (1U << 3))
1399 diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_5015;
1400 switch ((val >> 12) & 0x7) {
1401 case 0:
1402 break;
1403 case 2:
1404 diga->status[0] |= IEC958_AES0_PRO_FS_32000;
1405 break;
1406 default:
1407 diga->status[0] |= IEC958_AES0_PRO_FS_48000;
1408 break;
1409 }
1410 } else {
1411 /* consumer */
1412 diga->status[0] |= val & (1U << 2); /* copyright */
1413 if (val & (1U << 3))
1414 diga->status[0] |= IEC958_AES0_CON_EMPHASIS_5015;
1415 diga->status[1] |= (val >> 4) & 0x3f; /* category */
1416 diga->status[3] |= (val >> 12) & 0x07; /* fs */
1417 }
1418}
1419
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001420static int snd_vt1724_spdif_default_get(struct snd_kcontrol *kcontrol,
1421 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001423 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 unsigned int val;
1425 val = inw(ICEMT1724(ice, SPDIF_CTRL));
1426 decode_spdif_bits(&ucontrol->value.iec958, val);
1427 return 0;
1428}
1429
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001430static int snd_vt1724_spdif_default_put(struct snd_kcontrol *kcontrol,
1431 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001433 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 unsigned int val, old;
1435
1436 val = encode_spdif_bits(&ucontrol->value.iec958);
1437 spin_lock_irq(&ice->reg_lock);
1438 old = inw(ICEMT1724(ice, SPDIF_CTRL));
1439 if (val != old)
1440 update_spdif_bits(ice, val);
1441 spin_unlock_irq(&ice->reg_lock);
1442 return (val != old);
1443}
1444
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001445static struct snd_kcontrol_new snd_vt1724_spdif_default __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446{
1447 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1448 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1449 .info = snd_vt1724_spdif_info,
1450 .get = snd_vt1724_spdif_default_get,
1451 .put = snd_vt1724_spdif_default_put
1452};
1453
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001454static int snd_vt1724_spdif_maskc_get(struct snd_kcontrol *kcontrol,
1455 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456{
1457 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1458 IEC958_AES0_PROFESSIONAL |
1459 IEC958_AES0_CON_NOT_COPYRIGHT |
1460 IEC958_AES0_CON_EMPHASIS;
1461 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1462 IEC958_AES1_CON_CATEGORY;
1463 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1464 return 0;
1465}
1466
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001467static int snd_vt1724_spdif_maskp_get(struct snd_kcontrol *kcontrol,
1468 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469{
1470 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1471 IEC958_AES0_PROFESSIONAL |
1472 IEC958_AES0_PRO_FS |
1473 IEC958_AES0_PRO_EMPHASIS;
1474 return 0;
1475}
1476
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001477static struct snd_kcontrol_new snd_vt1724_spdif_maskc __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478{
1479 .access = SNDRV_CTL_ELEM_ACCESS_READ,
Clemens Ladisch67ed4162005-07-29 15:32:58 +02001480 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1482 .info = snd_vt1724_spdif_info,
1483 .get = snd_vt1724_spdif_maskc_get,
1484};
1485
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001486static struct snd_kcontrol_new snd_vt1724_spdif_maskp __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487{
1488 .access = SNDRV_CTL_ELEM_ACCESS_READ,
Clemens Ladisch67ed4162005-07-29 15:32:58 +02001489 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1491 .info = snd_vt1724_spdif_info,
1492 .get = snd_vt1724_spdif_maskp_get,
1493};
1494
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001495#define snd_vt1724_spdif_sw_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001497static int snd_vt1724_spdif_sw_get(struct snd_kcontrol *kcontrol,
1498 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001500 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1501 ucontrol->value.integer.value[0] = inb(ICEREG1724(ice, SPDIF_CFG)) &
1502 VT1724_CFG_SPDIF_OUT_EN ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 return 0;
1504}
1505
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001506static int snd_vt1724_spdif_sw_put(struct snd_kcontrol *kcontrol,
1507 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001509 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 unsigned char old, val;
1511
1512 spin_lock_irq(&ice->reg_lock);
1513 old = val = inb(ICEREG1724(ice, SPDIF_CFG));
1514 val &= ~VT1724_CFG_SPDIF_OUT_EN;
1515 if (ucontrol->value.integer.value[0])
1516 val |= VT1724_CFG_SPDIF_OUT_EN;
1517 if (old != val)
1518 outb(val, ICEREG1724(ice, SPDIF_CFG));
1519 spin_unlock_irq(&ice->reg_lock);
1520 return old != val;
1521}
1522
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001523static struct snd_kcontrol_new snd_vt1724_spdif_switch __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524{
1525 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1526 /* FIXME: the following conflict with IEC958 Playback Route */
1527 // .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),
Clemens Ladisch10e8d782005-08-03 13:40:08 +02001528 .name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 .info = snd_vt1724_spdif_sw_info,
1530 .get = snd_vt1724_spdif_sw_get,
1531 .put = snd_vt1724_spdif_sw_put
1532};
1533
1534
1535#if 0 /* NOT USED YET */
1536/*
1537 * GPIO access from extern
1538 */
1539
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001540#define snd_vt1724_gpio_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001542int snd_vt1724_gpio_get(struct snd_kcontrol *kcontrol,
1543 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001545 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 int shift = kcontrol->private_value & 0xff;
1547 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1548
1549 snd_ice1712_save_gpio_status(ice);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001550 ucontrol->value.integer.value[0] =
1551 (snd_ice1712_gpio_read(ice) & (1 << shift) ? 1 : 0) ^ invert;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 snd_ice1712_restore_gpio_status(ice);
1553 return 0;
1554}
1555
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001556int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
1557 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001559 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 int shift = kcontrol->private_value & 0xff;
1561 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1562 unsigned int val, nval;
1563
1564 if (kcontrol->private_value & (1 << 31))
1565 return -EPERM;
1566 nval = (ucontrol->value.integer.value[0] ? (1 << shift) : 0) ^ invert;
1567 snd_ice1712_save_gpio_status(ice);
1568 val = snd_ice1712_gpio_read(ice);
1569 nval |= val & ~(1 << shift);
1570 if (val != nval)
1571 snd_ice1712_gpio_write(ice, nval);
1572 snd_ice1712_restore_gpio_status(ice);
1573 return val != nval;
1574}
1575#endif /* NOT USED YET */
1576
1577/*
1578 * rate
1579 */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001580static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1581 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582{
Takashi Iwai32b47da2007-01-29 15:26:36 +01001583 static const char * const texts_1724[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 "8000", /* 0: 6 */
1585 "9600", /* 1: 3 */
1586 "11025", /* 2: 10 */
1587 "12000", /* 3: 2 */
1588 "16000", /* 4: 5 */
1589 "22050", /* 5: 9 */
1590 "24000", /* 6: 1 */
1591 "32000", /* 7: 4 */
1592 "44100", /* 8: 8 */
1593 "48000", /* 9: 0 */
1594 "64000", /* 10: 15 */
1595 "88200", /* 11: 11 */
1596 "96000", /* 12: 7 */
1597 "176400", /* 13: 12 */
1598 "192000", /* 14: 14 */
1599 "IEC958 Input", /* 15: -- */
1600 };
Takashi Iwai32b47da2007-01-29 15:26:36 +01001601 static const char * const texts_1720[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 "8000", /* 0: 6 */
1603 "9600", /* 1: 3 */
1604 "11025", /* 2: 10 */
1605 "12000", /* 3: 2 */
1606 "16000", /* 4: 5 */
1607 "22050", /* 5: 9 */
1608 "24000", /* 6: 1 */
1609 "32000", /* 7: 4 */
1610 "44100", /* 8: 8 */
1611 "48000", /* 9: 0 */
1612 "64000", /* 10: 15 */
1613 "88200", /* 11: 11 */
1614 "96000", /* 12: 7 */
1615 "IEC958 Input", /* 13: -- */
1616 };
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001617 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618
1619 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1620 uinfo->count = 1;
1621 uinfo->value.enumerated.items = ice->vt1720 ? 14 : 16;
1622 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1623 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1624 strcpy(uinfo->value.enumerated.name,
1625 ice->vt1720 ? texts_1720[uinfo->value.enumerated.item] :
1626 texts_1724[uinfo->value.enumerated.item]);
1627 return 0;
1628}
1629
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001630static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1631 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001633 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai32b47da2007-01-29 15:26:36 +01001634 static const unsigned char xlate[16] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 13, 255, 14, 10
1636 };
1637 unsigned char val;
1638
1639 spin_lock_irq(&ice->reg_lock);
1640 if (is_spdif_master(ice)) {
1641 ucontrol->value.enumerated.item[0] = ice->vt1720 ? 13 : 15;
1642 } else {
1643 val = xlate[inb(ICEMT1724(ice, RATE)) & 15];
1644 if (val == 255) {
1645 snd_BUG();
1646 val = 0;
1647 }
1648 ucontrol->value.enumerated.item[0] = val;
1649 }
1650 spin_unlock_irq(&ice->reg_lock);
1651 return 0;
1652}
1653
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001654static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1655 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001657 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 unsigned char oval;
1659 int rate;
1660 int change = 0;
1661 int spdif = ice->vt1720 ? 13 : 15;
1662
1663 spin_lock_irq(&ice->reg_lock);
1664 oval = inb(ICEMT1724(ice, RATE));
1665 if (ucontrol->value.enumerated.item[0] == spdif) {
Pavel Hofmanc5a30f82007-04-24 12:27:36 +02001666 unsigned char i2s_oval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
Pavel Hofmanc5a30f82007-04-24 12:27:36 +02001668 /* setting 256fs */
1669 i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT));
1670 outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X,
1671 ICEMT1724(ice, I2S_FORMAT));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 } else {
1673 rate = rates[ucontrol->value.integer.value[0] % 15];
1674 if (rate <= get_max_rate(ice)) {
1675 PRO_RATE_DEFAULT = rate;
1676 spin_unlock_irq(&ice->reg_lock);
1677 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1678 spin_lock_irq(&ice->reg_lock);
1679 }
1680 }
1681 change = inb(ICEMT1724(ice, RATE)) != oval;
1682 spin_unlock_irq(&ice->reg_lock);
1683
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001684 if ((oval & VT1724_SPDIF_MASTER) !=
1685 (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 /* notify akm chips as well */
1687 if (is_spdif_master(ice)) {
1688 unsigned int i;
1689 for (i = 0; i < ice->akm_codecs; i++) {
1690 if (ice->akm[i].ops.set_rate_val)
1691 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
1692 }
1693 }
1694 }
1695 return change;
1696}
1697
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001698static struct snd_kcontrol_new snd_vt1724_pro_internal_clock __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1700 .name = "Multi Track Internal Clock",
1701 .info = snd_vt1724_pro_internal_clock_info,
1702 .get = snd_vt1724_pro_internal_clock_get,
1703 .put = snd_vt1724_pro_internal_clock_put
1704};
1705
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001706#define snd_vt1724_pro_rate_locking_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001708static int snd_vt1724_pro_rate_locking_get(struct snd_kcontrol *kcontrol,
1709 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710{
1711 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1712 return 0;
1713}
1714
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001715static int snd_vt1724_pro_rate_locking_put(struct snd_kcontrol *kcontrol,
1716 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001718 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 int change = 0, nval;
1720
1721 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1722 spin_lock_irq(&ice->reg_lock);
1723 change = PRO_RATE_LOCKED != nval;
1724 PRO_RATE_LOCKED = nval;
1725 spin_unlock_irq(&ice->reg_lock);
1726 return change;
1727}
1728
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001729static struct snd_kcontrol_new snd_vt1724_pro_rate_locking __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1731 .name = "Multi Track Rate Locking",
1732 .info = snd_vt1724_pro_rate_locking_info,
1733 .get = snd_vt1724_pro_rate_locking_get,
1734 .put = snd_vt1724_pro_rate_locking_put
1735};
1736
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001737#define snd_vt1724_pro_rate_reset_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001739static int snd_vt1724_pro_rate_reset_get(struct snd_kcontrol *kcontrol,
1740 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741{
1742 ucontrol->value.integer.value[0] = PRO_RATE_RESET ? 1 : 0;
1743 return 0;
1744}
1745
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001746static int snd_vt1724_pro_rate_reset_put(struct snd_kcontrol *kcontrol,
1747 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001749 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 int change = 0, nval;
1751
1752 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1753 spin_lock_irq(&ice->reg_lock);
1754 change = PRO_RATE_RESET != nval;
1755 PRO_RATE_RESET = nval;
1756 spin_unlock_irq(&ice->reg_lock);
1757 return change;
1758}
1759
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001760static struct snd_kcontrol_new snd_vt1724_pro_rate_reset __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1762 .name = "Multi Track Rate Reset",
1763 .info = snd_vt1724_pro_rate_reset_info,
1764 .get = snd_vt1724_pro_rate_reset_get,
1765 .put = snd_vt1724_pro_rate_reset_put
1766};
1767
1768
1769/*
1770 * routing
1771 */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001772static int snd_vt1724_pro_route_info(struct snd_kcontrol *kcontrol,
1773 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774{
1775 static char *texts[] = {
1776 "PCM Out", /* 0 */
1777 "H/W In 0", "H/W In 1", /* 1-2 */
1778 "IEC958 In L", "IEC958 In R", /* 3-4 */
1779 };
1780
1781 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1782 uinfo->count = 1;
1783 uinfo->value.enumerated.items = 5;
1784 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1785 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1786 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1787 return 0;
1788}
1789
1790static inline int analog_route_shift(int idx)
1791{
1792 return (idx % 2) * 12 + ((idx / 2) * 3) + 8;
1793}
1794
1795static inline int digital_route_shift(int idx)
1796{
1797 return idx * 3;
1798}
1799
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001800static int get_route_val(struct snd_ice1712 *ice, int shift)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801{
1802 unsigned long val;
1803 unsigned char eitem;
Takashi Iwai32b47da2007-01-29 15:26:36 +01001804 static const unsigned char xlate[8] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 0, 255, 1, 2, 255, 255, 3, 4,
1806 };
1807
1808 val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1809 val >>= shift;
1810 val &= 7; //we now have 3 bits per output
1811 eitem = xlate[val];
1812 if (eitem == 255) {
1813 snd_BUG();
1814 return 0;
1815 }
1816 return eitem;
1817}
1818
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001819static int put_route_val(struct snd_ice1712 *ice, unsigned int val, int shift)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820{
1821 unsigned int old_val, nval;
1822 int change;
Takashi Iwai32b47da2007-01-29 15:26:36 +01001823 static const unsigned char xroute[8] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 0, /* PCM */
1825 2, /* PSDIN0 Left */
1826 3, /* PSDIN0 Right */
1827 6, /* SPDIN Left */
1828 7, /* SPDIN Right */
1829 };
1830
1831 nval = xroute[val % 5];
1832 val = old_val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1833 val &= ~(0x07 << shift);
1834 val |= nval << shift;
1835 change = val != old_val;
1836 if (change)
1837 outl(val, ICEMT1724(ice, ROUTE_PLAYBACK));
1838 return change;
1839}
1840
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001841static int snd_vt1724_pro_route_analog_get(struct snd_kcontrol *kcontrol,
1842 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001844 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001846 ucontrol->value.enumerated.item[0] =
1847 get_route_val(ice, analog_route_shift(idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 return 0;
1849}
1850
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001851static int snd_vt1724_pro_route_analog_put(struct snd_kcontrol *kcontrol,
1852 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001854 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1856 return put_route_val(ice, ucontrol->value.enumerated.item[0],
1857 analog_route_shift(idx));
1858}
1859
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001860static int snd_vt1724_pro_route_spdif_get(struct snd_kcontrol *kcontrol,
1861 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001863 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001865 ucontrol->value.enumerated.item[0] =
1866 get_route_val(ice, digital_route_shift(idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 return 0;
1868}
1869
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001870static int snd_vt1724_pro_route_spdif_put(struct snd_kcontrol *kcontrol,
1871 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001873 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1875 return put_route_val(ice, ucontrol->value.enumerated.item[0],
1876 digital_route_shift(idx));
1877}
1878
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001879static struct snd_kcontrol_new snd_vt1724_mixer_pro_analog_route __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1881 .name = "H/W Playback Route",
1882 .info = snd_vt1724_pro_route_info,
1883 .get = snd_vt1724_pro_route_analog_get,
1884 .put = snd_vt1724_pro_route_analog_put,
1885};
1886
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001887static struct snd_kcontrol_new snd_vt1724_mixer_pro_spdif_route __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1889 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
1890 .info = snd_vt1724_pro_route_info,
1891 .get = snd_vt1724_pro_route_spdif_get,
1892 .put = snd_vt1724_pro_route_spdif_put,
1893 .count = 2,
1894};
1895
1896
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001897static int snd_vt1724_pro_peak_info(struct snd_kcontrol *kcontrol,
1898 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899{
1900 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1901 uinfo->count = 22; /* FIXME: for compatibility with ice1712... */
1902 uinfo->value.integer.min = 0;
1903 uinfo->value.integer.max = 255;
1904 return 0;
1905}
1906
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001907static int snd_vt1724_pro_peak_get(struct snd_kcontrol *kcontrol,
1908 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001910 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 int idx;
1912
1913 spin_lock_irq(&ice->reg_lock);
1914 for (idx = 0; idx < 22; idx++) {
1915 outb(idx, ICEMT1724(ice, MONITOR_PEAKINDEX));
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001916 ucontrol->value.integer.value[idx] =
1917 inb(ICEMT1724(ice, MONITOR_PEAKDATA));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 }
1919 spin_unlock_irq(&ice->reg_lock);
1920 return 0;
1921}
1922
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001923static struct snd_kcontrol_new snd_vt1724_mixer_pro_peak __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1925 .name = "Multi Track Peak",
1926 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1927 .info = snd_vt1724_pro_peak_info,
1928 .get = snd_vt1724_pro_peak_get
1929};
1930
1931/*
1932 *
1933 */
1934
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001935static struct snd_ice1712_card_info no_matched __devinitdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001937static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 snd_vt1724_revo_cards,
1939 snd_vt1724_amp_cards,
1940 snd_vt1724_aureon_cards,
1941 snd_vt1720_mobo_cards,
1942 snd_vt1720_pontis_cards,
Julian Scheel6b8d6e52008-01-16 19:50:00 +01001943 snd_vt1724_prodigy_hifi_cards,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 snd_vt1724_prodigy192_cards,
1945 snd_vt1724_juli_cards,
1946 snd_vt1724_phase_cards,
Clement Guedezf6cdab52007-01-08 10:48:41 +01001947 snd_vt1724_wtm_cards,
Shin-ya Okadaf31639b2007-10-23 15:08:18 +02001948 snd_vt1724_se_cards,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 NULL,
1950};
1951
1952
1953/*
1954 */
1955
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001956static void wait_i2c_busy(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957{
1958 int t = 0x10000;
1959 while ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY) && t--)
1960 ;
1961 if (t == -1)
1962 printk(KERN_ERR "ice1724: i2c busy timeout\n");
1963}
1964
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001965unsigned char snd_vt1724_read_i2c(struct snd_ice1712 *ice,
1966 unsigned char dev, unsigned char addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967{
1968 unsigned char val;
1969
Ingo Molnar62932df2006-01-16 16:34:20 +01001970 mutex_lock(&ice->i2c_mutex);
Pavel Hofmanacec30f2007-12-03 12:37:17 +01001971 wait_i2c_busy(ice);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1973 outb(dev & ~VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1974 wait_i2c_busy(ice);
1975 val = inb(ICEREG1724(ice, I2C_DATA));
Ingo Molnar62932df2006-01-16 16:34:20 +01001976 mutex_unlock(&ice->i2c_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 //printk("i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val);
1978 return val;
1979}
1980
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001981void snd_vt1724_write_i2c(struct snd_ice1712 *ice,
1982 unsigned char dev, unsigned char addr, unsigned char data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983{
Ingo Molnar62932df2006-01-16 16:34:20 +01001984 mutex_lock(&ice->i2c_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 wait_i2c_busy(ice);
1986 //printk("i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data);
1987 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1988 outb(data, ICEREG1724(ice, I2C_DATA));
1989 outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1990 wait_i2c_busy(ice);
Ingo Molnar62932df2006-01-16 16:34:20 +01001991 mutex_unlock(&ice->i2c_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992}
1993
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001994static int __devinit snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
1995 const char *modelname)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996{
1997 const int dev = 0xa0; /* EEPROM device address */
1998 unsigned int i, size;
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001999 struct snd_ice1712_card_info * const *tbl, *c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000
2001 if (! modelname || ! *modelname) {
2002 ice->eeprom.subvendor = 0;
2003 if ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_EEPROM) != 0)
2004 ice->eeprom.subvendor =
2005 (snd_vt1724_read_i2c(ice, dev, 0x00) << 0) |
2006 (snd_vt1724_read_i2c(ice, dev, 0x01) << 8) |
2007 (snd_vt1724_read_i2c(ice, dev, 0x02) << 16) |
2008 (snd_vt1724_read_i2c(ice, dev, 0x03) << 24);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002009 if (ice->eeprom.subvendor == 0 ||
2010 ice->eeprom.subvendor == (unsigned int)-1) {
2011 /* invalid subvendor from EEPROM, try the PCI
2012 * subststem ID instead
2013 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 u16 vendor, device;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002015 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID,
2016 &vendor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002018 ice->eeprom.subvendor =
2019 ((unsigned int)swab16(vendor) << 16) | swab16(device);
2020 if (ice->eeprom.subvendor == 0 ||
2021 ice->eeprom.subvendor == (unsigned int)-1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 printk(KERN_ERR "ice1724: No valid ID is found\n");
2023 return -ENXIO;
2024 }
2025 }
2026 }
2027 for (tbl = card_tables; *tbl; tbl++) {
2028 for (c = *tbl; c->subvendor; c++) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002029 if (modelname && c->model &&
2030 ! strcmp(modelname, c->model)) {
2031 printk(KERN_INFO "ice1724: Using board model %s\n",
2032 c->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 ice->eeprom.subvendor = c->subvendor;
2034 } else if (c->subvendor != ice->eeprom.subvendor)
2035 continue;
2036 if (! c->eeprom_size || ! c->eeprom_data)
2037 goto found;
2038 /* if the EEPROM is given by the driver, use it */
2039 snd_printdd("using the defined eeprom..\n");
2040 ice->eeprom.version = 2;
2041 ice->eeprom.size = c->eeprom_size + 6;
2042 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
2043 goto read_skipped;
2044 }
2045 }
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002046 printk(KERN_WARNING "ice1724: No matching model found for ID 0x%x\n",
2047 ice->eeprom.subvendor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048
2049 found:
2050 ice->eeprom.size = snd_vt1724_read_i2c(ice, dev, 0x04);
2051 if (ice->eeprom.size < 6)
2052 ice->eeprom.size = 32;
2053 else if (ice->eeprom.size > 32) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002054 printk(KERN_ERR "ice1724: Invalid EEPROM (size = %i)\n",
2055 ice->eeprom.size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 return -EIO;
2057 }
2058 ice->eeprom.version = snd_vt1724_read_i2c(ice, dev, 0x05);
2059 if (ice->eeprom.version != 2)
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002060 printk(KERN_WARNING "ice1724: Invalid EEPROM version %i\n",
2061 ice->eeprom.version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 size = ice->eeprom.size - 6;
2063 for (i = 0; i < size; i++)
2064 ice->eeprom.data[i] = snd_vt1724_read_i2c(ice, dev, i + 6);
2065
2066 read_skipped:
2067 ice->eeprom.gpiomask = eeprom_triple(ice, ICE_EEP2_GPIO_MASK);
2068 ice->eeprom.gpiostate = eeprom_triple(ice, ICE_EEP2_GPIO_STATE);
2069 ice->eeprom.gpiodir = eeprom_triple(ice, ICE_EEP2_GPIO_DIR);
2070
2071 return 0;
2072}
2073
2074
2075
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002076static int __devinit snd_vt1724_chip_init(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077{
2078 outb(VT1724_RESET , ICEREG1724(ice, CONTROL));
2079 udelay(200);
2080 outb(0, ICEREG1724(ice, CONTROL));
2081 udelay(200);
2082 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG));
2083 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG));
2084 outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES));
2085 outb(ice->eeprom.data[ICE_EEP2_SPDIF], ICEREG1724(ice, SPDIF_CFG));
2086
2087 ice->gpio.write_mask = ice->eeprom.gpiomask;
2088 ice->gpio.direction = ice->eeprom.gpiodir;
2089 snd_vt1724_set_gpio_mask(ice, ice->eeprom.gpiomask);
2090 snd_vt1724_set_gpio_dir(ice, ice->eeprom.gpiodir);
2091 snd_vt1724_set_gpio_data(ice, ice->eeprom.gpiostate);
2092
2093 outb(0, ICEREG1724(ice, POWERDOWN));
2094
2095 return 0;
2096}
2097
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002098static int __devinit snd_vt1724_spdif_build_controls(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099{
2100 int err;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002101 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
2103 snd_assert(ice->pcm != NULL, return -EIO);
2104
2105 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice));
2106 if (err < 0)
2107 return err;
2108
2109 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_spdif_switch, ice));
2110 if (err < 0)
2111 return err;
2112
2113 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_default, ice));
2114 if (err < 0)
2115 return err;
2116 kctl->id.device = ice->pcm->device;
2117 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskc, ice));
2118 if (err < 0)
2119 return err;
2120 kctl->id.device = ice->pcm->device;
2121 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskp, ice));
2122 if (err < 0)
2123 return err;
2124 kctl->id.device = ice->pcm->device;
2125#if 0 /* use default only */
2126 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_stream, ice));
2127 if (err < 0)
2128 return err;
2129 kctl->id.device = ice->pcm->device;
2130 ice->spdif.stream_ctl = kctl;
2131#endif
2132 return 0;
2133}
2134
2135
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002136static int __devinit snd_vt1724_build_controls(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137{
2138 int err;
2139
2140 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_eeprom, ice));
2141 if (err < 0)
2142 return err;
2143 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_internal_clock, ice));
2144 if (err < 0)
2145 return err;
2146
2147 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_locking, ice));
2148 if (err < 0)
2149 return err;
2150 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_reset, ice));
2151 if (err < 0)
2152 return err;
2153
2154 if (ice->num_total_dacs > 0) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002155 struct snd_kcontrol_new tmp = snd_vt1724_mixer_pro_analog_route;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 tmp.count = ice->num_total_dacs;
2157 if (ice->vt1720 && tmp.count > 2)
2158 tmp.count = 2;
2159 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2160 if (err < 0)
2161 return err;
2162 }
2163
2164 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_peak, ice));
2165 if (err < 0)
2166 return err;
2167
2168 return 0;
2169}
2170
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002171static int snd_vt1724_free(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172{
2173 if (! ice->port)
2174 goto __hw_end;
2175 /* mask all interrupts */
2176 outb(0xff, ICEMT1724(ice, DMA_INT_MASK));
2177 outb(0xff, ICEREG1724(ice, IRQMASK));
2178 /* --- */
2179 __hw_end:
2180 if (ice->irq >= 0) {
2181 synchronize_irq(ice->irq);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002182 free_irq(ice->irq, ice);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 }
2184 pci_release_regions(ice->pci);
2185 snd_ice1712_akm4xxx_free(ice);
2186 pci_disable_device(ice->pci);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +01002187 kfree(ice->spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 kfree(ice);
2189 return 0;
2190}
2191
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002192static int snd_vt1724_dev_free(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002194 struct snd_ice1712 *ice = device->device_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 return snd_vt1724_free(ice);
2196}
2197
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002198static int __devinit snd_vt1724_create(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 struct pci_dev *pci,
2200 const char *modelname,
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002201 struct snd_ice1712 ** r_ice1712)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002203 struct snd_ice1712 *ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 int err;
2205 unsigned char mask;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002206 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 .dev_free = snd_vt1724_dev_free,
2208 };
2209
2210 *r_ice1712 = NULL;
2211
2212 /* enable PCI device */
2213 if ((err = pci_enable_device(pci)) < 0)
2214 return err;
2215
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002216 ice = kzalloc(sizeof(*ice), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 if (ice == NULL) {
2218 pci_disable_device(pci);
2219 return -ENOMEM;
2220 }
2221 ice->vt1724 = 1;
2222 spin_lock_init(&ice->reg_lock);
Ingo Molnar62932df2006-01-16 16:34:20 +01002223 mutex_init(&ice->gpio_mutex);
2224 mutex_init(&ice->open_mutex);
2225 mutex_init(&ice->i2c_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 ice->gpio.set_mask = snd_vt1724_set_gpio_mask;
2227 ice->gpio.set_dir = snd_vt1724_set_gpio_dir;
2228 ice->gpio.set_data = snd_vt1724_set_gpio_data;
2229 ice->gpio.get_data = snd_vt1724_get_gpio_data;
2230 ice->card = card;
2231 ice->pci = pci;
2232 ice->irq = -1;
2233 pci_set_master(pci);
2234 snd_vt1724_proc_init(ice);
2235 synchronize_irq(pci->irq);
2236
2237 if ((err = pci_request_regions(pci, "ICE1724")) < 0) {
2238 kfree(ice);
2239 pci_disable_device(pci);
2240 return err;
2241 }
2242 ice->port = pci_resource_start(pci, 0);
2243 ice->profi_port = pci_resource_start(pci, 1);
2244
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002245 if (request_irq(pci->irq, snd_vt1724_interrupt,
Takashi Iwai437a5a42006-11-21 12:14:23 +01002246 IRQF_SHARED, "ICE1724", ice)) {
Takashi Iwai99b359b2005-10-20 18:26:44 +02002247 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 snd_vt1724_free(ice);
2249 return -EIO;
2250 }
2251
2252 ice->irq = pci->irq;
2253
2254 if (snd_vt1724_read_eeprom(ice, modelname) < 0) {
2255 snd_vt1724_free(ice);
2256 return -EIO;
2257 }
2258 if (snd_vt1724_chip_init(ice) < 0) {
2259 snd_vt1724_free(ice);
2260 return -EIO;
2261 }
2262
2263 /* unmask used interrupts */
2264 if (! (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401))
2265 mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
2266 else
2267 mask = 0;
2268 outb(mask, ICEREG1724(ice, IRQMASK));
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002269 /* don't handle FIFO overrun/underruns (just yet),
2270 * since they cause machine lockups
2271 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK));
2273
2274 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2275 snd_vt1724_free(ice);
2276 return err;
2277 }
2278
2279 snd_card_set_dev(card, &pci->dev);
2280
2281 *r_ice1712 = ice;
2282 return 0;
2283}
2284
2285
2286/*
2287 *
2288 * Registration
2289 *
2290 */
2291
2292static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2293 const struct pci_device_id *pci_id)
2294{
2295 static int dev;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002296 struct snd_card *card;
2297 struct snd_ice1712 *ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 int pcm_dev = 0, err;
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01002299 struct snd_ice1712_card_info * const *tbl, *c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300
2301 if (dev >= SNDRV_CARDS)
2302 return -ENODEV;
2303 if (!enable[dev]) {
2304 dev++;
2305 return -ENOENT;
2306 }
2307
2308 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2309 if (card == NULL)
2310 return -ENOMEM;
2311
2312 strcpy(card->driver, "ICE1724");
2313 strcpy(card->shortname, "ICEnsemble ICE1724");
2314
2315 if ((err = snd_vt1724_create(card, pci, model[dev], &ice)) < 0) {
2316 snd_card_free(card);
2317 return err;
2318 }
2319
2320 for (tbl = card_tables; *tbl; tbl++) {
2321 for (c = *tbl; c->subvendor; c++) {
2322 if (c->subvendor == ice->eeprom.subvendor) {
2323 strcpy(card->shortname, c->name);
2324 if (c->driver) /* specific driver? */
2325 strcpy(card->driver, c->driver);
2326 if (c->chip_init) {
2327 if ((err = c->chip_init(ice)) < 0) {
2328 snd_card_free(card);
2329 return err;
2330 }
2331 }
2332 goto __found;
2333 }
2334 }
2335 }
2336 c = &no_matched;
2337 __found:
Takashi Iwaif06934b2007-04-10 11:15:34 +02002338 /*
2339 * VT1724 has separate DMAs for the analog and the SPDIF streams while
2340 * ICE1712 has only one for both (mixed up).
2341 *
2342 * Confusingly the analog PCM is named "professional" here because it
2343 * was called so in ice1712 driver, and vt1724 driver is derived from
2344 * ice1712 driver.
2345 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346
2347 if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) {
2348 snd_card_free(card);
2349 return err;
2350 }
2351
2352 if ((err = snd_vt1724_pcm_spdif(ice, pcm_dev++)) < 0) {
2353 snd_card_free(card);
2354 return err;
2355 }
2356
2357 if ((err = snd_vt1724_pcm_indep(ice, pcm_dev++)) < 0) {
2358 snd_card_free(card);
2359 return err;
2360 }
2361
2362 if ((err = snd_vt1724_ac97_mixer(ice)) < 0) {
2363 snd_card_free(card);
2364 return err;
2365 }
2366
2367 if ((err = snd_vt1724_build_controls(ice)) < 0) {
2368 snd_card_free(card);
2369 return err;
2370 }
2371
2372 if (ice->pcm && ice->has_spdif) { /* has SPDIF I/O */
2373 if ((err = snd_vt1724_spdif_build_controls(ice)) < 0) {
2374 snd_card_free(card);
2375 return err;
2376 }
2377 }
2378
2379 if (c->build_controls) {
2380 if ((err = c->build_controls(ice)) < 0) {
2381 snd_card_free(card);
2382 return err;
2383 }
2384 }
2385
2386 if (! c->no_mpu401) {
2387 if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) {
2388 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
Takashi Iwai302e4c22006-05-23 13:24:30 +02002389 ICEREG1724(ice, MPU_CTRL),
2390 MPU401_INFO_INTEGRATED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 ice->irq, 0,
2392 &ice->rmidi[0])) < 0) {
2393 snd_card_free(card);
2394 return err;
2395 }
2396 }
2397 }
2398
2399 sprintf(card->longname, "%s at 0x%lx, irq %i",
2400 card->shortname, ice->port, ice->irq);
2401
2402 if ((err = snd_card_register(card)) < 0) {
2403 snd_card_free(card);
2404 return err;
2405 }
2406 pci_set_drvdata(pci, card);
2407 dev++;
2408 return 0;
2409}
2410
2411static void __devexit snd_vt1724_remove(struct pci_dev *pci)
2412{
2413 snd_card_free(pci_get_drvdata(pci));
2414 pci_set_drvdata(pci, NULL);
2415}
2416
2417static struct pci_driver driver = {
2418 .name = "ICE1724",
2419 .id_table = snd_vt1724_ids,
2420 .probe = snd_vt1724_probe,
2421 .remove = __devexit_p(snd_vt1724_remove),
2422};
2423
2424static int __init alsa_card_ice1724_init(void)
2425{
Takashi Iwai01d25d42005-04-11 16:58:24 +02002426 return pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427}
2428
2429static void __exit alsa_card_ice1724_exit(void)
2430{
2431 pci_unregister_driver(&driver);
2432}
2433
2434module_init(alsa_card_ice1724_init)
2435module_exit(alsa_card_ice1724_exit)