blob: 357bdbe21c8fb490da8d67838d3bcf6ce60b419a [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
25#include <sound/driver.h>
26#include <asm/io.h>
27#include <linux/delay.h>
28#include <linux/interrupt.h>
29#include <linux/init.h>
30#include <linux/pci.h>
31#include <linux/slab.h>
32#include <linux/moduleparam.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010033#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <sound/core.h>
35#include <sound/info.h>
36#include <sound/mpu401.h>
37#include <sound/initval.h>
38
39#include <sound/asoundef.h>
40
41#include "ice1712.h"
42#include "envy24ht.h"
43
44/* lowlevel routines */
45#include "amp.h"
46#include "revo.h"
47#include "aureon.h"
48#include "vt1720_mobo.h"
49#include "pontis.h"
50#include "prodigy192.h"
51#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
66 JULI_DEVICE_DESC
67 PHASE_DEVICE_DESC
Clement Guedezf6cdab52007-01-08 10:48:41 +010068 WTM_DEVICE_DESC
Shin-ya Okadaf31639b2007-10-23 15:08:18 +020069 SE_DEVICE_DESC
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 "{VIA,VT1720},"
71 "{VIA,VT1724},"
72 "{ICEnsemble,Generic ICE1724},"
73 "{ICEnsemble,Generic Envy24HT}"
74 "{ICEnsemble,Generic Envy24PT}}");
75
76static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
77static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
78static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
79static char *model[SNDRV_CARDS];
80
81module_param_array(index, int, NULL, 0444);
82MODULE_PARM_DESC(index, "Index value for ICE1724 soundcard.");
83module_param_array(id, charp, NULL, 0444);
84MODULE_PARM_DESC(id, "ID string for ICE1724 soundcard.");
85module_param_array(enable, bool, NULL, 0444);
86MODULE_PARM_DESC(enable, "Enable ICE1724 soundcard.");
87module_param_array(model, charp, NULL, 0444);
88MODULE_PARM_DESC(model, "Use the given board model.");
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91/* Both VT1720 and VT1724 have the same PCI IDs */
Takashi Iwai32b47da2007-01-29 15:26:36 +010092static const struct pci_device_id snd_vt1724_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_VT1724, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
94 { 0, }
95};
96
97MODULE_DEVICE_TABLE(pci, snd_vt1724_ids);
98
99
100static int PRO_RATE_LOCKED;
101static int PRO_RATE_RESET = 1;
102static unsigned int PRO_RATE_DEFAULT = 44100;
103
104/*
105 * Basic I/O
106 */
107
108/* check whether the clock mode is spdif-in */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100109static inline int is_spdif_master(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
111 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0;
112}
113
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100114static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
116 return is_spdif_master(ice) || PRO_RATE_LOCKED;
117}
118
119/*
120 * ac97 section
121 */
122
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100123static unsigned char snd_vt1724_ac97_ready(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
125 unsigned char old_cmd;
126 int tm;
127 for (tm = 0; tm < 0x10000; tm++) {
128 old_cmd = inb(ICEMT1724(ice, AC97_CMD));
129 if (old_cmd & (VT1724_AC97_WRITE | VT1724_AC97_READ))
130 continue;
131 if (!(old_cmd & VT1724_AC97_READY))
132 continue;
133 return old_cmd;
134 }
135 snd_printd(KERN_ERR "snd_vt1724_ac97_ready: timeout\n");
136 return old_cmd;
137}
138
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100139static int snd_vt1724_ac97_wait_bit(struct snd_ice1712 *ice, unsigned char bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
141 int tm;
142 for (tm = 0; tm < 0x10000; tm++)
143 if ((inb(ICEMT1724(ice, AC97_CMD)) & bit) == 0)
144 return 0;
145 snd_printd(KERN_ERR "snd_vt1724_ac97_wait_bit: timeout\n");
146 return -EIO;
147}
148
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100149static void snd_vt1724_ac97_write(struct snd_ac97 *ac97,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 unsigned short reg,
151 unsigned short val)
152{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100153 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 unsigned char old_cmd;
155
156 old_cmd = snd_vt1724_ac97_ready(ice);
157 old_cmd &= ~VT1724_AC97_ID_MASK;
158 old_cmd |= ac97->num;
159 outb(reg, ICEMT1724(ice, AC97_INDEX));
160 outw(val, ICEMT1724(ice, AC97_DATA));
161 outb(old_cmd | VT1724_AC97_WRITE, ICEMT1724(ice, AC97_CMD));
162 snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_WRITE);
163}
164
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100165static unsigned short snd_vt1724_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100167 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 unsigned char old_cmd;
169
170 old_cmd = snd_vt1724_ac97_ready(ice);
171 old_cmd &= ~VT1724_AC97_ID_MASK;
172 old_cmd |= ac97->num;
173 outb(reg, ICEMT1724(ice, AC97_INDEX));
174 outb(old_cmd | VT1724_AC97_READ, ICEMT1724(ice, AC97_CMD));
175 if (snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_READ) < 0)
176 return ~0;
177 return inw(ICEMT1724(ice, AC97_DATA));
178}
179
180
181/*
182 * GPIO operations
183 */
184
185/* set gpio direction 0 = read, 1 = write */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100186static void snd_vt1724_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
188 outl(data, ICEREG1724(ice, GPIO_DIRECTION));
189 inw(ICEREG1724(ice, GPIO_DIRECTION)); /* dummy read for pci-posting */
190}
191
192/* set the gpio mask (0 = writable) */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100193static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
195 outw(data, ICEREG1724(ice, GPIO_WRITE_MASK));
196 if (! ice->vt1720) /* VT1720 supports only 16 GPIO bits */
197 outb((data >> 16) & 0xff, ICEREG1724(ice, GPIO_WRITE_MASK_22));
198 inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */
199}
200
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100201static void snd_vt1724_set_gpio_data(struct snd_ice1712 *ice, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202{
203 outw(data, ICEREG1724(ice, GPIO_DATA));
204 if (! ice->vt1720)
205 outb(data >> 16, ICEREG1724(ice, GPIO_DATA_22));
206 inw(ICEREG1724(ice, GPIO_DATA)); /* dummy read for pci-posting */
207}
208
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100209static unsigned int snd_vt1724_get_gpio_data(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
211 unsigned int data;
212 if (! ice->vt1720)
213 data = (unsigned int)inb(ICEREG1724(ice, GPIO_DATA_22));
214 else
215 data = 0;
216 data = (data << 16) | inw(ICEREG1724(ice, GPIO_DATA));
217 return data;
218}
219
220/*
221 * Interrupt handler
222 */
223
David Howells7d12e782006-10-05 14:55:46 +0100224static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100226 struct snd_ice1712 *ice = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 unsigned char status;
228 int handled = 0;
229
230 while (1) {
231 status = inb(ICEREG1724(ice, IRQSTAT));
232 if (status == 0)
233 break;
234
235 handled = 1;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100236 /* these should probably be separated at some point,
237 * but as we don't currently have MPU support on the board
238 * I will leave it
239 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 if ((status & VT1724_IRQ_MPU_RX)||(status & VT1724_IRQ_MPU_TX)) {
241 if (ice->rmidi[0])
David Howells7d12e782006-10-05 14:55:46 +0100242 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 outb(status & (VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX), ICEREG1724(ice, IRQSTAT));
244 status &= ~(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX);
245 }
246 if (status & VT1724_IRQ_MTPCM) {
247 /*
248 * Multi-track PCM
249 * PCM assignment are:
250 * Playback DMA0 (M/C) = playback_pro_substream
251 * Playback DMA1 = playback_con_substream_ds[0]
252 * Playback DMA2 = playback_con_substream_ds[1]
253 * Playback DMA3 = playback_con_substream_ds[2]
254 * Playback DMA4 (SPDIF) = playback_con_substream
255 * Record DMA0 = capture_pro_substream
256 * Record DMA1 = capture_con_substream
257 */
258 unsigned char mtstat = inb(ICEMT1724(ice, IRQ));
259 if (mtstat & VT1724_MULTI_PDMA0) {
260 if (ice->playback_pro_substream)
261 snd_pcm_period_elapsed(ice->playback_pro_substream);
262 }
263 if (mtstat & VT1724_MULTI_RDMA0) {
264 if (ice->capture_pro_substream)
265 snd_pcm_period_elapsed(ice->capture_pro_substream);
266 }
267 if (mtstat & VT1724_MULTI_PDMA1) {
268 if (ice->playback_con_substream_ds[0])
269 snd_pcm_period_elapsed(ice->playback_con_substream_ds[0]);
270 }
271 if (mtstat & VT1724_MULTI_PDMA2) {
272 if (ice->playback_con_substream_ds[1])
273 snd_pcm_period_elapsed(ice->playback_con_substream_ds[1]);
274 }
275 if (mtstat & VT1724_MULTI_PDMA3) {
276 if (ice->playback_con_substream_ds[2])
277 snd_pcm_period_elapsed(ice->playback_con_substream_ds[2]);
278 }
279 if (mtstat & VT1724_MULTI_PDMA4) {
280 if (ice->playback_con_substream)
281 snd_pcm_period_elapsed(ice->playback_con_substream);
282 }
283 if (mtstat & VT1724_MULTI_RDMA1) {
284 if (ice->capture_con_substream)
285 snd_pcm_period_elapsed(ice->capture_con_substream);
286 }
287 /* ack anyway to avoid freeze */
288 outb(mtstat, ICEMT1724(ice, IRQ));
289 /* ought to really handle this properly */
290 if (mtstat & VT1724_MULTI_FIFO_ERR) {
291 unsigned char fstat = inb(ICEMT1724(ice, DMA_FIFO_ERR));
292 outb(fstat, ICEMT1724(ice, DMA_FIFO_ERR));
293 outb(VT1724_MULTI_FIFO_ERR | inb(ICEMT1724(ice, DMA_INT_MASK)), ICEMT1724(ice, DMA_INT_MASK));
294 /* If I don't do this, I get machine lockup due to continual interrupts */
295 }
296
297 }
298 }
299 return IRQ_RETVAL(handled);
300}
301
302/*
303 * PCM code - professional part (multitrack)
304 */
305
306static unsigned int rates[] = {
307 8000, 9600, 11025, 12000, 16000, 22050, 24000,
308 32000, 44100, 48000, 64000, 88200, 96000,
309 176400, 192000,
310};
311
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100312static struct snd_pcm_hw_constraint_list hw_constraints_rates_96 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 .count = ARRAY_SIZE(rates) - 2, /* up to 96000 */
314 .list = rates,
315 .mask = 0,
316};
317
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100318static struct snd_pcm_hw_constraint_list hw_constraints_rates_48 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 .count = ARRAY_SIZE(rates) - 5, /* up to 48000 */
320 .list = rates,
321 .mask = 0,
322};
323
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100324static struct snd_pcm_hw_constraint_list hw_constraints_rates_192 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 .count = ARRAY_SIZE(rates),
326 .list = rates,
327 .mask = 0,
328};
329
330struct vt1724_pcm_reg {
331 unsigned int addr; /* ADDR register offset */
332 unsigned int size; /* SIZE register offset */
333 unsigned int count; /* COUNT register offset */
334 unsigned int start; /* start & pause bit */
335};
336
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100337static int snd_vt1724_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100339 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 unsigned char what;
341 unsigned char old;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100342 struct snd_pcm_substream *s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 what = 0;
Takashi Iwaief991b92007-02-22 12:52:53 +0100345 snd_pcm_group_for_each_entry(s, substream) {
Clemens Ladisch29998d22007-07-30 08:14:31 +0200346 if (snd_pcm_substream_chip(s) == ice) {
347 const struct vt1724_pcm_reg *reg;
348 reg = s->runtime->private_data;
349 what |= reg->start;
350 snd_pcm_trigger_done(s, substream);
351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 }
353
354 switch (cmd) {
355 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
356 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
357 spin_lock(&ice->reg_lock);
358 old = inb(ICEMT1724(ice, DMA_PAUSE));
359 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
360 old |= what;
361 else
362 old &= ~what;
363 outb(old, ICEMT1724(ice, DMA_PAUSE));
364 spin_unlock(&ice->reg_lock);
365 break;
366
367 case SNDRV_PCM_TRIGGER_START:
368 case SNDRV_PCM_TRIGGER_STOP:
369 spin_lock(&ice->reg_lock);
370 old = inb(ICEMT1724(ice, DMA_CONTROL));
371 if (cmd == SNDRV_PCM_TRIGGER_START)
372 old |= what;
373 else
374 old &= ~what;
375 outb(old, ICEMT1724(ice, DMA_CONTROL));
376 spin_unlock(&ice->reg_lock);
377 break;
378
379 default:
380 return -EINVAL;
381 }
382 return 0;
383}
384
385/*
386 */
387
388#define DMA_STARTS (VT1724_RDMA0_START|VT1724_PDMA0_START|VT1724_RDMA1_START|\
389 VT1724_PDMA1_START|VT1724_PDMA2_START|VT1724_PDMA3_START|VT1724_PDMA4_START)
390#define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\
391 VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE)
392
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100393static int get_max_rate(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
395 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
396 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
397 return 192000;
398 else
399 return 96000;
400 } else
401 return 48000;
402}
403
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100404static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
405 int force)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
407 unsigned long flags;
408 unsigned char val, old;
409 unsigned int i, mclk_change;
410
411 if (rate > get_max_rate(ice))
412 return;
413
414 switch (rate) {
415 case 8000: val = 6; break;
416 case 9600: val = 3; break;
417 case 11025: val = 10; break;
418 case 12000: val = 2; break;
419 case 16000: val = 5; break;
420 case 22050: val = 9; break;
421 case 24000: val = 1; break;
422 case 32000: val = 4; break;
423 case 44100: val = 8; break;
424 case 48000: val = 0; break;
425 case 64000: val = 15; break;
426 case 88200: val = 11; break;
427 case 96000: val = 7; break;
428 case 176400: val = 12; break;
429 case 192000: val = 14; break;
430 default:
431 snd_BUG();
432 val = 0;
433 break;
434 }
435
436 spin_lock_irqsave(&ice->reg_lock, flags);
437 if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) ||
438 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
439 /* running? we cannot change the rate now... */
440 spin_unlock_irqrestore(&ice->reg_lock, flags);
441 return;
442 }
443 if (!force && is_pro_rate_locked(ice)) {
444 spin_unlock_irqrestore(&ice->reg_lock, flags);
445 return;
446 }
447
448 old = inb(ICEMT1724(ice, RATE));
449 if (force || old != val)
450 outb(val, ICEMT1724(ice, RATE));
451 else if (rate == ice->cur_rate) {
452 spin_unlock_irqrestore(&ice->reg_lock, flags);
453 return;
454 }
455
456 ice->cur_rate = rate;
457
458 /* check MT02 */
459 mclk_change = 0;
460 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
461 val = old = inb(ICEMT1724(ice, I2S_FORMAT));
462 if (rate > 96000)
463 val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
464 else
465 val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
466 if (val != old) {
467 outb(val, ICEMT1724(ice, I2S_FORMAT));
468 mclk_change = 1;
469 }
470 }
471 spin_unlock_irqrestore(&ice->reg_lock, flags);
472
473 if (mclk_change && ice->gpio.i2s_mclk_changed)
474 ice->gpio.i2s_mclk_changed(ice);
475 if (ice->gpio.set_pro_rate)
476 ice->gpio.set_pro_rate(ice, rate);
477
478 /* set up codecs */
479 for (i = 0; i < ice->akm_codecs; i++) {
480 if (ice->akm[i].ops.set_rate_val)
481 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
482 }
483 if (ice->spdif.ops.setup_rate)
484 ice->spdif.ops.setup_rate(ice, rate);
485}
486
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100487static int snd_vt1724_pcm_hw_params(struct snd_pcm_substream *substream,
488 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100490 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 int i, chs;
492
493 chs = params_channels(hw_params);
Ingo Molnar62932df2006-01-16 16:34:20 +0100494 mutex_lock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 /* mark surround channels */
496 if (substream == ice->playback_pro_substream) {
497 /* PDMA0 can be multi-channel up to 8 */
498 chs = chs / 2 - 1;
499 for (i = 0; i < chs; i++) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100500 if (ice->pcm_reserved[i] &&
501 ice->pcm_reserved[i] != substream) {
Ingo Molnar62932df2006-01-16 16:34:20 +0100502 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 return -EBUSY;
504 }
505 ice->pcm_reserved[i] = substream;
506 }
507 for (; i < 3; i++) {
508 if (ice->pcm_reserved[i] == substream)
509 ice->pcm_reserved[i] = NULL;
510 }
511 } else {
512 for (i = 0; i < 3; i++) {
513 /* check individual playback stream */
514 if (ice->playback_con_substream_ds[i] == substream) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100515 if (ice->pcm_reserved[i] &&
516 ice->pcm_reserved[i] != substream) {
Ingo Molnar62932df2006-01-16 16:34:20 +0100517 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 return -EBUSY;
519 }
520 ice->pcm_reserved[i] = substream;
521 break;
522 }
523 }
524 }
Ingo Molnar62932df2006-01-16 16:34:20 +0100525 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 snd_vt1724_set_pro_rate(ice, params_rate(hw_params), 0);
527 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
528}
529
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100530static int snd_vt1724_pcm_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100532 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 int i;
534
Ingo Molnar62932df2006-01-16 16:34:20 +0100535 mutex_lock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 /* unmark surround channels */
537 for (i = 0; i < 3; i++)
538 if (ice->pcm_reserved[i] == substream)
539 ice->pcm_reserved[i] = NULL;
Ingo Molnar62932df2006-01-16 16:34:20 +0100540 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 return snd_pcm_lib_free_pages(substream);
542}
543
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100544static int snd_vt1724_playback_pro_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100546 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 unsigned char val;
548 unsigned int size;
549
550 spin_lock_irq(&ice->reg_lock);
551 val = (8 - substream->runtime->channels) >> 1;
552 outb(val, ICEMT1724(ice, BURST));
553
554 outl(substream->runtime->dma_addr, ICEMT1724(ice, PLAYBACK_ADDR));
555
556 size = (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1;
557 // outl(size, ICEMT1724(ice, PLAYBACK_SIZE));
558 outw(size, ICEMT1724(ice, PLAYBACK_SIZE));
559 outb(size >> 16, ICEMT1724(ice, PLAYBACK_SIZE) + 2);
560 size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
561 // outl(size, ICEMT1724(ice, PLAYBACK_COUNT));
562 outw(size, ICEMT1724(ice, PLAYBACK_COUNT));
563 outb(size >> 16, ICEMT1724(ice, PLAYBACK_COUNT) + 2);
564
565 spin_unlock_irq(&ice->reg_lock);
566
567 // 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));
568 return 0;
569}
570
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100571static snd_pcm_uframes_t snd_vt1724_playback_pro_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100573 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 size_t ptr;
575
576 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & VT1724_PDMA0_START))
577 return 0;
578#if 0 /* read PLAYBACK_ADDR */
579 ptr = inl(ICEMT1724(ice, PLAYBACK_ADDR));
580 if (ptr < substream->runtime->dma_addr) {
581 snd_printd("ice1724: invalid negative ptr\n");
582 return 0;
583 }
584 ptr -= substream->runtime->dma_addr;
585 ptr = bytes_to_frames(substream->runtime, ptr);
586 if (ptr >= substream->runtime->buffer_size) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100587 snd_printd("ice1724: invalid ptr %d (size=%d)\n",
588 (int)ptr, (int)substream->runtime->period_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 return 0;
590 }
591#else /* read PLAYBACK_SIZE */
592 ptr = inl(ICEMT1724(ice, PLAYBACK_SIZE)) & 0xffffff;
593 ptr = (ptr + 1) << 2;
594 ptr = bytes_to_frames(substream->runtime, ptr);
595 if (! ptr)
596 ;
597 else if (ptr <= substream->runtime->buffer_size)
598 ptr = substream->runtime->buffer_size - ptr;
599 else {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100600 snd_printd("ice1724: invalid ptr %d (size=%d)\n",
601 (int)ptr, (int)substream->runtime->buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 ptr = 0;
603 }
604#endif
605 return ptr;
606}
607
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100608static int snd_vt1724_pcm_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100610 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Takashi Iwai32b47da2007-01-29 15:26:36 +0100611 const struct vt1724_pcm_reg *reg = substream->runtime->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613 spin_lock_irq(&ice->reg_lock);
614 outl(substream->runtime->dma_addr, ice->profi_port + reg->addr);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100615 outw((snd_pcm_lib_buffer_bytes(substream) >> 2) - 1,
616 ice->profi_port + reg->size);
617 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1,
618 ice->profi_port + reg->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 spin_unlock_irq(&ice->reg_lock);
620 return 0;
621}
622
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100623static snd_pcm_uframes_t snd_vt1724_pcm_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100625 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Takashi Iwai32b47da2007-01-29 15:26:36 +0100626 const struct vt1724_pcm_reg *reg = substream->runtime->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 size_t ptr;
628
629 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & reg->start))
630 return 0;
631#if 0 /* use ADDR register */
632 ptr = inl(ice->profi_port + reg->addr);
633 ptr -= substream->runtime->dma_addr;
634 return bytes_to_frames(substream->runtime, ptr);
635#else /* use SIZE register */
636 ptr = inw(ice->profi_port + reg->size);
637 ptr = (ptr + 1) << 2;
638 ptr = bytes_to_frames(substream->runtime, ptr);
639 if (! ptr)
640 ;
641 else if (ptr <= substream->runtime->buffer_size)
642 ptr = substream->runtime->buffer_size - ptr;
643 else {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100644 snd_printd("ice1724: invalid ptr %d (size=%d)\n",
645 (int)ptr, (int)substream->runtime->buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 ptr = 0;
647 }
648 return ptr;
649#endif
650}
651
Takashi Iwai32b47da2007-01-29 15:26:36 +0100652static const struct vt1724_pcm_reg vt1724_playback_pro_reg = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 .addr = VT1724_MT_PLAYBACK_ADDR,
654 .size = VT1724_MT_PLAYBACK_SIZE,
655 .count = VT1724_MT_PLAYBACK_COUNT,
656 .start = VT1724_PDMA0_START,
657};
658
Takashi Iwai32b47da2007-01-29 15:26:36 +0100659static const struct vt1724_pcm_reg vt1724_capture_pro_reg = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 .addr = VT1724_MT_CAPTURE_ADDR,
661 .size = VT1724_MT_CAPTURE_SIZE,
662 .count = VT1724_MT_CAPTURE_COUNT,
663 .start = VT1724_RDMA0_START,
664};
665
Takashi Iwai32b47da2007-01-29 15:26:36 +0100666static const struct snd_pcm_hardware snd_vt1724_playback_pro =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667{
668 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
669 SNDRV_PCM_INFO_BLOCK_TRANSFER |
670 SNDRV_PCM_INFO_MMAP_VALID |
671 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
672 .formats = SNDRV_PCM_FMTBIT_S32_LE,
673 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
674 .rate_min = 8000,
675 .rate_max = 192000,
676 .channels_min = 2,
677 .channels_max = 8,
678 .buffer_bytes_max = (1UL << 21), /* 19bits dword */
679 .period_bytes_min = 8 * 4 * 2, /* FIXME: constraints needed */
680 .period_bytes_max = (1UL << 21),
681 .periods_min = 2,
682 .periods_max = 1024,
683};
684
Takashi Iwai32b47da2007-01-29 15:26:36 +0100685static const struct snd_pcm_hardware snd_vt1724_spdif =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
687 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
688 SNDRV_PCM_INFO_BLOCK_TRANSFER |
689 SNDRV_PCM_INFO_MMAP_VALID |
690 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
691 .formats = SNDRV_PCM_FMTBIT_S32_LE,
Takashi Iwai2dfbeca2005-10-12 10:04:42 +0200692 .rates = (SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100|
693 SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_88200|
694 SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_176400|
695 SNDRV_PCM_RATE_192000),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 .rate_min = 32000,
Takashi Iwai2dfbeca2005-10-12 10:04:42 +0200697 .rate_max = 192000,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 .channels_min = 2,
699 .channels_max = 2,
700 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
701 .period_bytes_min = 2 * 4 * 2,
702 .period_bytes_max = (1UL << 18),
703 .periods_min = 2,
704 .periods_max = 1024,
705};
706
Takashi Iwai32b47da2007-01-29 15:26:36 +0100707static const struct snd_pcm_hardware snd_vt1724_2ch_stereo =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708{
709 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
710 SNDRV_PCM_INFO_BLOCK_TRANSFER |
711 SNDRV_PCM_INFO_MMAP_VALID |
712 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
713 .formats = SNDRV_PCM_FMTBIT_S32_LE,
714 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
715 .rate_min = 8000,
716 .rate_max = 192000,
717 .channels_min = 2,
718 .channels_max = 2,
719 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
720 .period_bytes_min = 2 * 4 * 2,
721 .period_bytes_max = (1UL << 18),
722 .periods_min = 2,
723 .periods_max = 1024,
724};
725
726/*
727 * set rate constraints
728 */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100729static int set_rate_constraints(struct snd_ice1712 *ice,
730 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100732 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 if (ice->hw_rates) {
734 /* hardware specific */
735 runtime->hw.rate_min = ice->hw_rates->list[0];
736 runtime->hw.rate_max = ice->hw_rates->list[ice->hw_rates->count - 1];
737 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100738 return snd_pcm_hw_constraint_list(runtime, 0,
739 SNDRV_PCM_HW_PARAM_RATE,
740 ice->hw_rates);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 }
742 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
743 /* I2S */
744 /* VT1720 doesn't support more than 96kHz */
745 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100746 return snd_pcm_hw_constraint_list(runtime, 0,
747 SNDRV_PCM_HW_PARAM_RATE,
748 &hw_constraints_rates_192);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 else {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100750 runtime->hw.rates = SNDRV_PCM_RATE_KNOT |
751 SNDRV_PCM_RATE_8000_96000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 runtime->hw.rate_max = 96000;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100753 return snd_pcm_hw_constraint_list(runtime, 0,
754 SNDRV_PCM_HW_PARAM_RATE,
755 &hw_constraints_rates_96);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 }
757 } else if (ice->ac97) {
758 /* ACLINK */
759 runtime->hw.rate_max = 48000;
760 runtime->hw.rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100761 return snd_pcm_hw_constraint_list(runtime, 0,
762 SNDRV_PCM_HW_PARAM_RATE,
763 &hw_constraints_rates_48);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 }
765 return 0;
766}
767
768/* multi-channel playback needs alignment 8x32bit regardless of the channels
769 * actually used
770 */
771#define VT1724_BUFFER_ALIGN 0x20
772
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100773static int snd_vt1724_playback_pro_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100775 struct snd_pcm_runtime *runtime = substream->runtime;
776 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 int chs;
778
Takashi Iwai32b47da2007-01-29 15:26:36 +0100779 runtime->private_data = (void *)&vt1724_playback_pro_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 ice->playback_pro_substream = substream;
781 runtime->hw = snd_vt1724_playback_pro;
782 snd_pcm_set_sync(substream);
783 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
784 set_rate_constraints(ice, substream);
Ingo Molnar62932df2006-01-16 16:34:20 +0100785 mutex_lock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 /* calculate the currently available channels */
787 for (chs = 0; chs < 3; chs++) {
788 if (ice->pcm_reserved[chs])
789 break;
790 }
791 chs = (chs + 1) * 2;
792 runtime->hw.channels_max = chs;
793 if (chs > 2) /* channels must be even */
794 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Ingo Molnar62932df2006-01-16 16:34:20 +0100795 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
797 VT1724_BUFFER_ALIGN);
798 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
799 VT1724_BUFFER_ALIGN);
800 return 0;
801}
802
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100803static int snd_vt1724_capture_pro_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100805 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
806 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
Takashi Iwai32b47da2007-01-29 15:26:36 +0100808 runtime->private_data = (void *)&vt1724_capture_pro_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 ice->capture_pro_substream = substream;
810 runtime->hw = snd_vt1724_2ch_stereo;
811 snd_pcm_set_sync(substream);
812 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
813 set_rate_constraints(ice, substream);
814 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
815 VT1724_BUFFER_ALIGN);
816 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
817 VT1724_BUFFER_ALIGN);
818 return 0;
819}
820
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100821static int snd_vt1724_playback_pro_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100823 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825 if (PRO_RATE_RESET)
826 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
827 ice->playback_pro_substream = NULL;
828
829 return 0;
830}
831
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100832static int snd_vt1724_capture_pro_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100834 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836 if (PRO_RATE_RESET)
837 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
838 ice->capture_pro_substream = NULL;
839 return 0;
840}
841
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100842static struct snd_pcm_ops snd_vt1724_playback_pro_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 .open = snd_vt1724_playback_pro_open,
844 .close = snd_vt1724_playback_pro_close,
845 .ioctl = snd_pcm_lib_ioctl,
846 .hw_params = snd_vt1724_pcm_hw_params,
847 .hw_free = snd_vt1724_pcm_hw_free,
848 .prepare = snd_vt1724_playback_pro_prepare,
849 .trigger = snd_vt1724_pcm_trigger,
850 .pointer = snd_vt1724_playback_pro_pointer,
851};
852
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100853static struct snd_pcm_ops snd_vt1724_capture_pro_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 .open = snd_vt1724_capture_pro_open,
855 .close = snd_vt1724_capture_pro_close,
856 .ioctl = snd_pcm_lib_ioctl,
857 .hw_params = snd_vt1724_pcm_hw_params,
858 .hw_free = snd_vt1724_pcm_hw_free,
859 .prepare = snd_vt1724_pcm_prepare,
860 .trigger = snd_vt1724_pcm_trigger,
861 .pointer = snd_vt1724_pcm_pointer,
862};
863
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100864static int __devinit snd_vt1724_pcm_profi(struct snd_ice1712 * ice, int device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100866 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 int err;
868
869 err = snd_pcm_new(ice->card, "ICE1724", device, 1, 1, &pcm);
870 if (err < 0)
871 return err;
872
873 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_vt1724_playback_pro_ops);
874 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_vt1724_capture_pro_ops);
875
876 pcm->private_data = ice;
877 pcm->info_flags = 0;
878 strcpy(pcm->name, "ICE1724");
879
880 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100881 snd_dma_pci_data(ice->pci),
882 256*1024, 256*1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
884 ice->pcm_pro = pcm;
885
886 return 0;
887}
888
889
890/*
891 * SPDIF PCM
892 */
893
Takashi Iwai32b47da2007-01-29 15:26:36 +0100894static const struct vt1724_pcm_reg vt1724_playback_spdif_reg = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 .addr = VT1724_MT_PDMA4_ADDR,
896 .size = VT1724_MT_PDMA4_SIZE,
897 .count = VT1724_MT_PDMA4_COUNT,
898 .start = VT1724_PDMA4_START,
899};
900
Takashi Iwai32b47da2007-01-29 15:26:36 +0100901static const struct vt1724_pcm_reg vt1724_capture_spdif_reg = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 .addr = VT1724_MT_RDMA1_ADDR,
903 .size = VT1724_MT_RDMA1_SIZE,
904 .count = VT1724_MT_RDMA1_COUNT,
905 .start = VT1724_RDMA1_START,
906};
907
908/* update spdif control bits; call with reg_lock */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100909static void update_spdif_bits(struct snd_ice1712 *ice, unsigned int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910{
911 unsigned char cbit, disabled;
912
913 cbit = inb(ICEREG1724(ice, SPDIF_CFG));
914 disabled = cbit & ~VT1724_CFG_SPDIF_OUT_EN;
915 if (cbit != disabled)
916 outb(disabled, ICEREG1724(ice, SPDIF_CFG));
917 outw(val, ICEMT1724(ice, SPDIF_CTRL));
918 if (cbit != disabled)
919 outb(cbit, ICEREG1724(ice, SPDIF_CFG));
920 outw(val, ICEMT1724(ice, SPDIF_CTRL));
921}
922
923/* update SPDIF control bits according to the given rate */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100924static void update_spdif_rate(struct snd_ice1712 *ice, unsigned int rate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925{
926 unsigned int val, nval;
927 unsigned long flags;
928
929 spin_lock_irqsave(&ice->reg_lock, flags);
930 nval = val = inw(ICEMT1724(ice, SPDIF_CTRL));
931 nval &= ~(7 << 12);
932 switch (rate) {
933 case 44100: break;
934 case 48000: nval |= 2 << 12; break;
935 case 32000: nval |= 3 << 12; break;
Takashi Iwai2dfbeca2005-10-12 10:04:42 +0200936 case 88200: nval |= 4 << 12; break;
937 case 96000: nval |= 5 << 12; break;
938 case 192000: nval |= 6 << 12; break;
939 case 176400: nval |= 7 << 12; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 }
941 if (val != nval)
942 update_spdif_bits(ice, nval);
943 spin_unlock_irqrestore(&ice->reg_lock, flags);
944}
945
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100946static int snd_vt1724_playback_spdif_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100948 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 if (! ice->force_pdma4)
950 update_spdif_rate(ice, substream->runtime->rate);
951 return snd_vt1724_pcm_prepare(substream);
952}
953
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100954static int snd_vt1724_playback_spdif_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100956 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
957 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Takashi Iwai32b47da2007-01-29 15:26:36 +0100959 runtime->private_data = (void *)&vt1724_playback_spdif_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 ice->playback_con_substream = substream;
961 if (ice->force_pdma4) {
962 runtime->hw = snd_vt1724_2ch_stereo;
963 set_rate_constraints(ice, substream);
964 } else
965 runtime->hw = snd_vt1724_spdif;
966 snd_pcm_set_sync(substream);
967 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
968 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
969 VT1724_BUFFER_ALIGN);
970 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
971 VT1724_BUFFER_ALIGN);
972 return 0;
973}
974
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100975static int snd_vt1724_playback_spdif_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100977 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
979 if (PRO_RATE_RESET)
980 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
981 ice->playback_con_substream = NULL;
982
983 return 0;
984}
985
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100986static int snd_vt1724_capture_spdif_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100988 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
989 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
Takashi Iwai32b47da2007-01-29 15:26:36 +0100991 runtime->private_data = (void *)&vt1724_capture_spdif_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 ice->capture_con_substream = substream;
993 if (ice->force_rdma1) {
994 runtime->hw = snd_vt1724_2ch_stereo;
995 set_rate_constraints(ice, substream);
996 } else
997 runtime->hw = snd_vt1724_spdif;
998 snd_pcm_set_sync(substream);
999 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1000 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
1001 VT1724_BUFFER_ALIGN);
1002 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
1003 VT1724_BUFFER_ALIGN);
1004 return 0;
1005}
1006
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001007static int snd_vt1724_capture_spdif_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001009 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
1011 if (PRO_RATE_RESET)
1012 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1013 ice->capture_con_substream = NULL;
1014
1015 return 0;
1016}
1017
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001018static struct snd_pcm_ops snd_vt1724_playback_spdif_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 .open = snd_vt1724_playback_spdif_open,
1020 .close = snd_vt1724_playback_spdif_close,
1021 .ioctl = snd_pcm_lib_ioctl,
1022 .hw_params = snd_vt1724_pcm_hw_params,
1023 .hw_free = snd_vt1724_pcm_hw_free,
1024 .prepare = snd_vt1724_playback_spdif_prepare,
1025 .trigger = snd_vt1724_pcm_trigger,
1026 .pointer = snd_vt1724_pcm_pointer,
1027};
1028
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001029static struct snd_pcm_ops snd_vt1724_capture_spdif_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 .open = snd_vt1724_capture_spdif_open,
1031 .close = snd_vt1724_capture_spdif_close,
1032 .ioctl = snd_pcm_lib_ioctl,
1033 .hw_params = snd_vt1724_pcm_hw_params,
1034 .hw_free = snd_vt1724_pcm_hw_free,
1035 .prepare = snd_vt1724_pcm_prepare,
1036 .trigger = snd_vt1724_pcm_trigger,
1037 .pointer = snd_vt1724_pcm_pointer,
1038};
1039
1040
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001041static int __devinit snd_vt1724_pcm_spdif(struct snd_ice1712 * ice, int device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042{
1043 char *name;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001044 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 int play, capt;
1046 int err;
1047
1048 if (ice->force_pdma4 ||
1049 (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_OUT_INT)) {
1050 play = 1;
1051 ice->has_spdif = 1;
1052 } else
1053 play = 0;
1054 if (ice->force_rdma1 ||
1055 (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_IN)) {
1056 capt = 1;
1057 ice->has_spdif = 1;
1058 } else
1059 capt = 0;
1060 if (! play && ! capt)
1061 return 0; /* no spdif device */
1062
1063 if (ice->force_pdma4 || ice->force_rdma1)
1064 name = "ICE1724 Secondary";
1065 else
1066 name = "IEC1724 IEC958";
1067 err = snd_pcm_new(ice->card, name, device, play, capt, &pcm);
1068 if (err < 0)
1069 return err;
1070
1071 if (play)
1072 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1073 &snd_vt1724_playback_spdif_ops);
1074 if (capt)
1075 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1076 &snd_vt1724_capture_spdif_ops);
1077
1078 pcm->private_data = ice;
1079 pcm->info_flags = 0;
1080 strcpy(pcm->name, name);
1081
1082 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001083 snd_dma_pci_data(ice->pci),
1084 64*1024, 64*1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
1086 ice->pcm = pcm;
1087
1088 return 0;
1089}
1090
1091
1092/*
1093 * independent surround PCMs
1094 */
1095
Takashi Iwai32b47da2007-01-29 15:26:36 +01001096static const struct vt1724_pcm_reg vt1724_playback_dma_regs[3] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 {
1098 .addr = VT1724_MT_PDMA1_ADDR,
1099 .size = VT1724_MT_PDMA1_SIZE,
1100 .count = VT1724_MT_PDMA1_COUNT,
1101 .start = VT1724_PDMA1_START,
1102 },
1103 {
1104 .addr = VT1724_MT_PDMA2_ADDR,
1105 .size = VT1724_MT_PDMA2_SIZE,
1106 .count = VT1724_MT_PDMA2_COUNT,
1107 .start = VT1724_PDMA2_START,
1108 },
1109 {
1110 .addr = VT1724_MT_PDMA3_ADDR,
1111 .size = VT1724_MT_PDMA3_SIZE,
1112 .count = VT1724_MT_PDMA3_COUNT,
1113 .start = VT1724_PDMA3_START,
1114 },
1115};
1116
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001117static int snd_vt1724_playback_indep_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001119 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 unsigned char val;
1121
1122 spin_lock_irq(&ice->reg_lock);
1123 val = 3 - substream->number;
1124 if (inb(ICEMT1724(ice, BURST)) < val)
1125 outb(val, ICEMT1724(ice, BURST));
1126 spin_unlock_irq(&ice->reg_lock);
1127 return snd_vt1724_pcm_prepare(substream);
1128}
1129
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001130static int snd_vt1724_playback_indep_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001132 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1133 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
Ingo Molnar62932df2006-01-16 16:34:20 +01001135 mutex_lock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 /* already used by PDMA0? */
1137 if (ice->pcm_reserved[substream->number]) {
Ingo Molnar62932df2006-01-16 16:34:20 +01001138 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 return -EBUSY; /* FIXME: should handle blocking mode properly */
1140 }
Ingo Molnar62932df2006-01-16 16:34:20 +01001141 mutex_unlock(&ice->open_mutex);
Takashi Iwai32b47da2007-01-29 15:26:36 +01001142 runtime->private_data = (void *)&vt1724_playback_dma_regs[substream->number];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 ice->playback_con_substream_ds[substream->number] = substream;
1144 runtime->hw = snd_vt1724_2ch_stereo;
1145 snd_pcm_set_sync(substream);
1146 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1147 set_rate_constraints(ice, substream);
1148 return 0;
1149}
1150
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001151static int snd_vt1724_playback_indep_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001153 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
1155 if (PRO_RATE_RESET)
1156 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
1157 ice->playback_con_substream_ds[substream->number] = NULL;
1158 ice->pcm_reserved[substream->number] = NULL;
1159
1160 return 0;
1161}
1162
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001163static struct snd_pcm_ops snd_vt1724_playback_indep_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 .open = snd_vt1724_playback_indep_open,
1165 .close = snd_vt1724_playback_indep_close,
1166 .ioctl = snd_pcm_lib_ioctl,
1167 .hw_params = snd_vt1724_pcm_hw_params,
1168 .hw_free = snd_vt1724_pcm_hw_free,
1169 .prepare = snd_vt1724_playback_indep_prepare,
1170 .trigger = snd_vt1724_pcm_trigger,
1171 .pointer = snd_vt1724_pcm_pointer,
1172};
1173
1174
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001175static int __devinit snd_vt1724_pcm_indep(struct snd_ice1712 * ice, int device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001177 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 int play;
1179 int err;
1180
1181 play = ice->num_total_dacs / 2 - 1;
1182 if (play <= 0)
1183 return 0;
1184
1185 err = snd_pcm_new(ice->card, "ICE1724 Surrounds", device, play, 0, &pcm);
1186 if (err < 0)
1187 return err;
1188
1189 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1190 &snd_vt1724_playback_indep_ops);
1191
1192 pcm->private_data = ice;
1193 pcm->info_flags = 0;
1194 strcpy(pcm->name, "ICE1724 Surround PCM");
1195
1196 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001197 snd_dma_pci_data(ice->pci),
1198 64*1024, 64*1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
1200 ice->pcm_ds = pcm;
1201
1202 return 0;
1203}
1204
1205
1206/*
1207 * Mixer section
1208 */
1209
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001210static int __devinit snd_vt1724_ac97_mixer(struct snd_ice1712 * ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211{
1212 int err;
1213
1214 if (! (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S)) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001215 struct snd_ac97_bus *pbus;
1216 struct snd_ac97_template ac97;
1217 static struct snd_ac97_bus_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 .write = snd_vt1724_ac97_write,
1219 .read = snd_vt1724_ac97_read,
1220 };
1221
1222 /* cold reset */
1223 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
1224 mdelay(5); /* FIXME */
1225 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
1226
1227 if ((err = snd_ac97_bus(ice->card, 0, &ops, NULL, &pbus)) < 0)
1228 return err;
1229 memset(&ac97, 0, sizeof(ac97));
1230 ac97.private_data = ice;
1231 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1232 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1233 else
1234 return 0;
1235 }
1236 /* I2S mixer only */
1237 strcat(ice->card->mixername, "ICE1724 - multitrack");
1238 return 0;
1239}
1240
1241/*
1242 *
1243 */
1244
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001245static inline unsigned int eeprom_triple(struct snd_ice1712 *ice, int idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246{
1247 return (unsigned int)ice->eeprom.data[idx] | \
1248 ((unsigned int)ice->eeprom.data[idx + 1] << 8) | \
1249 ((unsigned int)ice->eeprom.data[idx + 2] << 16);
1250}
1251
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001252static void snd_vt1724_proc_read(struct snd_info_entry *entry,
1253 struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001255 struct snd_ice1712 *ice = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 unsigned int idx;
1257
1258 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1259 snd_iprintf(buffer, "EEPROM:\n");
1260
1261 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1262 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1263 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001264 snd_iprintf(buffer, " System Config : 0x%x\n",
1265 ice->eeprom.data[ICE_EEP2_SYSCONF]);
1266 snd_iprintf(buffer, " ACLink : 0x%x\n",
1267 ice->eeprom.data[ICE_EEP2_ACLINK]);
1268 snd_iprintf(buffer, " I2S : 0x%x\n",
1269 ice->eeprom.data[ICE_EEP2_I2S]);
1270 snd_iprintf(buffer, " S/PDIF : 0x%x\n",
1271 ice->eeprom.data[ICE_EEP2_SPDIF]);
1272 snd_iprintf(buffer, " GPIO direction : 0x%x\n",
1273 ice->eeprom.gpiodir);
1274 snd_iprintf(buffer, " GPIO mask : 0x%x\n",
1275 ice->eeprom.gpiomask);
1276 snd_iprintf(buffer, " GPIO state : 0x%x\n",
1277 ice->eeprom.gpiostate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 for (idx = 0x12; idx < ice->eeprom.size; idx++)
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001279 snd_iprintf(buffer, " Extra #%02i : 0x%x\n",
1280 idx, ice->eeprom.data[idx]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
1282 snd_iprintf(buffer, "\nRegisters:\n");
1283
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001284 snd_iprintf(buffer, " PSDOUT03 : 0x%08x\n",
1285 (unsigned)inl(ICEMT1724(ice, ROUTE_PLAYBACK)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 for (idx = 0x0; idx < 0x20 ; idx++)
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001287 snd_iprintf(buffer, " CCS%02x : 0x%02x\n",
1288 idx, inb(ice->port+idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 for (idx = 0x0; idx < 0x30 ; idx++)
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001290 snd_iprintf(buffer, " MT%02x : 0x%02x\n",
1291 idx, inb(ice->profi_port+idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292}
1293
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001294static void __devinit snd_vt1724_proc_init(struct snd_ice1712 * ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001296 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
1298 if (! snd_card_proc_new(ice->card, "ice1724", &entry))
Takashi Iwaibf850202006-04-28 15:13:41 +02001299 snd_info_set_text_ops(entry, ice, snd_vt1724_proc_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300}
1301
1302/*
1303 *
1304 */
1305
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001306static int snd_vt1724_eeprom_info(struct snd_kcontrol *kcontrol,
1307 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308{
1309 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001310 uinfo->count = sizeof(struct snd_ice1712_eeprom);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 return 0;
1312}
1313
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001314static int snd_vt1724_eeprom_get(struct snd_kcontrol *kcontrol,
1315 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001317 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
1319 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1320 return 0;
1321}
1322
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001323static struct snd_kcontrol_new snd_vt1724_eeprom __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1325 .name = "ICE1724 EEPROM",
1326 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1327 .info = snd_vt1724_eeprom_info,
1328 .get = snd_vt1724_eeprom_get
1329};
1330
1331/*
1332 */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001333static int snd_vt1724_spdif_info(struct snd_kcontrol *kcontrol,
1334 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335{
1336 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1337 uinfo->count = 1;
1338 return 0;
1339}
1340
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001341static unsigned int encode_spdif_bits(struct snd_aes_iec958 *diga)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342{
Takashi Iwai2dfbeca2005-10-12 10:04:42 +02001343 unsigned int val, rbits;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
1345 val = diga->status[0] & 0x03; /* professional, non-audio */
1346 if (val & 0x01) {
1347 /* professional */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001348 if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) ==
1349 IEC958_AES0_PRO_EMPHASIS_5015)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 val |= 1U << 3;
Takashi Iwai2dfbeca2005-10-12 10:04:42 +02001351 rbits = (diga->status[4] >> 3) & 0x0f;
1352 if (rbits) {
1353 switch (rbits) {
1354 case 2: val |= 5 << 12; break; /* 96k */
1355 case 3: val |= 6 << 12; break; /* 192k */
1356 case 10: val |= 4 << 12; break; /* 88.2k */
1357 case 11: val |= 7 << 12; break; /* 176.4k */
1358 }
1359 } else {
1360 switch (diga->status[0] & IEC958_AES0_PRO_FS) {
1361 case IEC958_AES0_PRO_FS_44100:
1362 break;
1363 case IEC958_AES0_PRO_FS_32000:
1364 val |= 3U << 12;
1365 break;
1366 default:
1367 val |= 2U << 12;
1368 break;
1369 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 }
1371 } else {
1372 /* consumer */
1373 val |= diga->status[1] & 0x04; /* copyright */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001374 if ((diga->status[0] & IEC958_AES0_CON_EMPHASIS) ==
1375 IEC958_AES0_CON_EMPHASIS_5015)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 val |= 1U << 3;
1377 val |= (unsigned int)(diga->status[1] & 0x3f) << 4; /* category */
1378 val |= (unsigned int)(diga->status[3] & IEC958_AES3_CON_FS) << 12; /* fs */
1379 }
1380 return val;
1381}
1382
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001383static void decode_spdif_bits(struct snd_aes_iec958 *diga, unsigned int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384{
1385 memset(diga->status, 0, sizeof(diga->status));
1386 diga->status[0] = val & 0x03; /* professional, non-audio */
1387 if (val & 0x01) {
1388 /* professional */
1389 if (val & (1U << 3))
1390 diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_5015;
1391 switch ((val >> 12) & 0x7) {
1392 case 0:
1393 break;
1394 case 2:
1395 diga->status[0] |= IEC958_AES0_PRO_FS_32000;
1396 break;
1397 default:
1398 diga->status[0] |= IEC958_AES0_PRO_FS_48000;
1399 break;
1400 }
1401 } else {
1402 /* consumer */
1403 diga->status[0] |= val & (1U << 2); /* copyright */
1404 if (val & (1U << 3))
1405 diga->status[0] |= IEC958_AES0_CON_EMPHASIS_5015;
1406 diga->status[1] |= (val >> 4) & 0x3f; /* category */
1407 diga->status[3] |= (val >> 12) & 0x07; /* fs */
1408 }
1409}
1410
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001411static int snd_vt1724_spdif_default_get(struct snd_kcontrol *kcontrol,
1412 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001414 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 unsigned int val;
1416 val = inw(ICEMT1724(ice, SPDIF_CTRL));
1417 decode_spdif_bits(&ucontrol->value.iec958, val);
1418 return 0;
1419}
1420
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001421static int snd_vt1724_spdif_default_put(struct snd_kcontrol *kcontrol,
1422 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001424 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 unsigned int val, old;
1426
1427 val = encode_spdif_bits(&ucontrol->value.iec958);
1428 spin_lock_irq(&ice->reg_lock);
1429 old = inw(ICEMT1724(ice, SPDIF_CTRL));
1430 if (val != old)
1431 update_spdif_bits(ice, val);
1432 spin_unlock_irq(&ice->reg_lock);
1433 return (val != old);
1434}
1435
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001436static struct snd_kcontrol_new snd_vt1724_spdif_default __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437{
1438 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1439 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1440 .info = snd_vt1724_spdif_info,
1441 .get = snd_vt1724_spdif_default_get,
1442 .put = snd_vt1724_spdif_default_put
1443};
1444
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001445static int snd_vt1724_spdif_maskc_get(struct snd_kcontrol *kcontrol,
1446 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447{
1448 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1449 IEC958_AES0_PROFESSIONAL |
1450 IEC958_AES0_CON_NOT_COPYRIGHT |
1451 IEC958_AES0_CON_EMPHASIS;
1452 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1453 IEC958_AES1_CON_CATEGORY;
1454 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1455 return 0;
1456}
1457
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001458static int snd_vt1724_spdif_maskp_get(struct snd_kcontrol *kcontrol,
1459 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460{
1461 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1462 IEC958_AES0_PROFESSIONAL |
1463 IEC958_AES0_PRO_FS |
1464 IEC958_AES0_PRO_EMPHASIS;
1465 return 0;
1466}
1467
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001468static struct snd_kcontrol_new snd_vt1724_spdif_maskc __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469{
1470 .access = SNDRV_CTL_ELEM_ACCESS_READ,
Clemens Ladisch67ed4162005-07-29 15:32:58 +02001471 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1473 .info = snd_vt1724_spdif_info,
1474 .get = snd_vt1724_spdif_maskc_get,
1475};
1476
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001477static struct snd_kcontrol_new snd_vt1724_spdif_maskp __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,PRO_MASK),
1482 .info = snd_vt1724_spdif_info,
1483 .get = snd_vt1724_spdif_maskp_get,
1484};
1485
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001486#define snd_vt1724_spdif_sw_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001488static int snd_vt1724_spdif_sw_get(struct snd_kcontrol *kcontrol,
1489 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001491 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1492 ucontrol->value.integer.value[0] = inb(ICEREG1724(ice, SPDIF_CFG)) &
1493 VT1724_CFG_SPDIF_OUT_EN ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 return 0;
1495}
1496
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001497static int snd_vt1724_spdif_sw_put(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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 unsigned char old, val;
1502
1503 spin_lock_irq(&ice->reg_lock);
1504 old = val = inb(ICEREG1724(ice, SPDIF_CFG));
1505 val &= ~VT1724_CFG_SPDIF_OUT_EN;
1506 if (ucontrol->value.integer.value[0])
1507 val |= VT1724_CFG_SPDIF_OUT_EN;
1508 if (old != val)
1509 outb(val, ICEREG1724(ice, SPDIF_CFG));
1510 spin_unlock_irq(&ice->reg_lock);
1511 return old != val;
1512}
1513
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001514static struct snd_kcontrol_new snd_vt1724_spdif_switch __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515{
1516 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1517 /* FIXME: the following conflict with IEC958 Playback Route */
1518 // .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),
Clemens Ladisch10e8d782005-08-03 13:40:08 +02001519 .name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 .info = snd_vt1724_spdif_sw_info,
1521 .get = snd_vt1724_spdif_sw_get,
1522 .put = snd_vt1724_spdif_sw_put
1523};
1524
1525
1526#if 0 /* NOT USED YET */
1527/*
1528 * GPIO access from extern
1529 */
1530
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001531#define snd_vt1724_gpio_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001533int snd_vt1724_gpio_get(struct snd_kcontrol *kcontrol,
1534 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001536 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 int shift = kcontrol->private_value & 0xff;
1538 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1539
1540 snd_ice1712_save_gpio_status(ice);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001541 ucontrol->value.integer.value[0] =
1542 (snd_ice1712_gpio_read(ice) & (1 << shift) ? 1 : 0) ^ invert;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 snd_ice1712_restore_gpio_status(ice);
1544 return 0;
1545}
1546
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001547int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
1548 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001550 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 int shift = kcontrol->private_value & 0xff;
1552 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1553 unsigned int val, nval;
1554
1555 if (kcontrol->private_value & (1 << 31))
1556 return -EPERM;
1557 nval = (ucontrol->value.integer.value[0] ? (1 << shift) : 0) ^ invert;
1558 snd_ice1712_save_gpio_status(ice);
1559 val = snd_ice1712_gpio_read(ice);
1560 nval |= val & ~(1 << shift);
1561 if (val != nval)
1562 snd_ice1712_gpio_write(ice, nval);
1563 snd_ice1712_restore_gpio_status(ice);
1564 return val != nval;
1565}
1566#endif /* NOT USED YET */
1567
1568/*
1569 * rate
1570 */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001571static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1572 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573{
Takashi Iwai32b47da2007-01-29 15:26:36 +01001574 static const char * const texts_1724[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 "8000", /* 0: 6 */
1576 "9600", /* 1: 3 */
1577 "11025", /* 2: 10 */
1578 "12000", /* 3: 2 */
1579 "16000", /* 4: 5 */
1580 "22050", /* 5: 9 */
1581 "24000", /* 6: 1 */
1582 "32000", /* 7: 4 */
1583 "44100", /* 8: 8 */
1584 "48000", /* 9: 0 */
1585 "64000", /* 10: 15 */
1586 "88200", /* 11: 11 */
1587 "96000", /* 12: 7 */
1588 "176400", /* 13: 12 */
1589 "192000", /* 14: 14 */
1590 "IEC958 Input", /* 15: -- */
1591 };
Takashi Iwai32b47da2007-01-29 15:26:36 +01001592 static const char * const texts_1720[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 "8000", /* 0: 6 */
1594 "9600", /* 1: 3 */
1595 "11025", /* 2: 10 */
1596 "12000", /* 3: 2 */
1597 "16000", /* 4: 5 */
1598 "22050", /* 5: 9 */
1599 "24000", /* 6: 1 */
1600 "32000", /* 7: 4 */
1601 "44100", /* 8: 8 */
1602 "48000", /* 9: 0 */
1603 "64000", /* 10: 15 */
1604 "88200", /* 11: 11 */
1605 "96000", /* 12: 7 */
1606 "IEC958 Input", /* 13: -- */
1607 };
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001608 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
1610 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1611 uinfo->count = 1;
1612 uinfo->value.enumerated.items = ice->vt1720 ? 14 : 16;
1613 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1614 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1615 strcpy(uinfo->value.enumerated.name,
1616 ice->vt1720 ? texts_1720[uinfo->value.enumerated.item] :
1617 texts_1724[uinfo->value.enumerated.item]);
1618 return 0;
1619}
1620
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001621static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1622 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001624 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Takashi Iwai32b47da2007-01-29 15:26:36 +01001625 static const unsigned char xlate[16] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 13, 255, 14, 10
1627 };
1628 unsigned char val;
1629
1630 spin_lock_irq(&ice->reg_lock);
1631 if (is_spdif_master(ice)) {
1632 ucontrol->value.enumerated.item[0] = ice->vt1720 ? 13 : 15;
1633 } else {
1634 val = xlate[inb(ICEMT1724(ice, RATE)) & 15];
1635 if (val == 255) {
1636 snd_BUG();
1637 val = 0;
1638 }
1639 ucontrol->value.enumerated.item[0] = val;
1640 }
1641 spin_unlock_irq(&ice->reg_lock);
1642 return 0;
1643}
1644
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001645static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1646 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001648 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 unsigned char oval;
1650 int rate;
1651 int change = 0;
1652 int spdif = ice->vt1720 ? 13 : 15;
1653
1654 spin_lock_irq(&ice->reg_lock);
1655 oval = inb(ICEMT1724(ice, RATE));
1656 if (ucontrol->value.enumerated.item[0] == spdif) {
Pavel Hofmanc5a30f82007-04-24 12:27:36 +02001657 unsigned char i2s_oval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
Pavel Hofmanc5a30f82007-04-24 12:27:36 +02001659 /* setting 256fs */
1660 i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT));
1661 outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X,
1662 ICEMT1724(ice, I2S_FORMAT));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 } else {
1664 rate = rates[ucontrol->value.integer.value[0] % 15];
1665 if (rate <= get_max_rate(ice)) {
1666 PRO_RATE_DEFAULT = rate;
1667 spin_unlock_irq(&ice->reg_lock);
1668 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
1669 spin_lock_irq(&ice->reg_lock);
1670 }
1671 }
1672 change = inb(ICEMT1724(ice, RATE)) != oval;
1673 spin_unlock_irq(&ice->reg_lock);
1674
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001675 if ((oval & VT1724_SPDIF_MASTER) !=
1676 (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 /* notify akm chips as well */
1678 if (is_spdif_master(ice)) {
1679 unsigned int i;
1680 for (i = 0; i < ice->akm_codecs; i++) {
1681 if (ice->akm[i].ops.set_rate_val)
1682 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
1683 }
1684 }
1685 }
1686 return change;
1687}
1688
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001689static struct snd_kcontrol_new snd_vt1724_pro_internal_clock __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1691 .name = "Multi Track Internal Clock",
1692 .info = snd_vt1724_pro_internal_clock_info,
1693 .get = snd_vt1724_pro_internal_clock_get,
1694 .put = snd_vt1724_pro_internal_clock_put
1695};
1696
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001697#define snd_vt1724_pro_rate_locking_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001699static int snd_vt1724_pro_rate_locking_get(struct snd_kcontrol *kcontrol,
1700 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701{
1702 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1703 return 0;
1704}
1705
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001706static int snd_vt1724_pro_rate_locking_put(struct snd_kcontrol *kcontrol,
1707 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001709 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 int change = 0, nval;
1711
1712 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1713 spin_lock_irq(&ice->reg_lock);
1714 change = PRO_RATE_LOCKED != nval;
1715 PRO_RATE_LOCKED = nval;
1716 spin_unlock_irq(&ice->reg_lock);
1717 return change;
1718}
1719
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001720static struct snd_kcontrol_new snd_vt1724_pro_rate_locking __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1722 .name = "Multi Track Rate Locking",
1723 .info = snd_vt1724_pro_rate_locking_info,
1724 .get = snd_vt1724_pro_rate_locking_get,
1725 .put = snd_vt1724_pro_rate_locking_put
1726};
1727
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001728#define snd_vt1724_pro_rate_reset_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001730static int snd_vt1724_pro_rate_reset_get(struct snd_kcontrol *kcontrol,
1731 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732{
1733 ucontrol->value.integer.value[0] = PRO_RATE_RESET ? 1 : 0;
1734 return 0;
1735}
1736
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001737static int snd_vt1724_pro_rate_reset_put(struct snd_kcontrol *kcontrol,
1738 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001740 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 int change = 0, nval;
1742
1743 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1744 spin_lock_irq(&ice->reg_lock);
1745 change = PRO_RATE_RESET != nval;
1746 PRO_RATE_RESET = nval;
1747 spin_unlock_irq(&ice->reg_lock);
1748 return change;
1749}
1750
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001751static struct snd_kcontrol_new snd_vt1724_pro_rate_reset __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1753 .name = "Multi Track Rate Reset",
1754 .info = snd_vt1724_pro_rate_reset_info,
1755 .get = snd_vt1724_pro_rate_reset_get,
1756 .put = snd_vt1724_pro_rate_reset_put
1757};
1758
1759
1760/*
1761 * routing
1762 */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001763static int snd_vt1724_pro_route_info(struct snd_kcontrol *kcontrol,
1764 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765{
1766 static char *texts[] = {
1767 "PCM Out", /* 0 */
1768 "H/W In 0", "H/W In 1", /* 1-2 */
1769 "IEC958 In L", "IEC958 In R", /* 3-4 */
1770 };
1771
1772 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1773 uinfo->count = 1;
1774 uinfo->value.enumerated.items = 5;
1775 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1776 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1777 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1778 return 0;
1779}
1780
1781static inline int analog_route_shift(int idx)
1782{
1783 return (idx % 2) * 12 + ((idx / 2) * 3) + 8;
1784}
1785
1786static inline int digital_route_shift(int idx)
1787{
1788 return idx * 3;
1789}
1790
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001791static int get_route_val(struct snd_ice1712 *ice, int shift)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792{
1793 unsigned long val;
1794 unsigned char eitem;
Takashi Iwai32b47da2007-01-29 15:26:36 +01001795 static const unsigned char xlate[8] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 0, 255, 1, 2, 255, 255, 3, 4,
1797 };
1798
1799 val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1800 val >>= shift;
1801 val &= 7; //we now have 3 bits per output
1802 eitem = xlate[val];
1803 if (eitem == 255) {
1804 snd_BUG();
1805 return 0;
1806 }
1807 return eitem;
1808}
1809
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001810static int put_route_val(struct snd_ice1712 *ice, unsigned int val, int shift)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811{
1812 unsigned int old_val, nval;
1813 int change;
Takashi Iwai32b47da2007-01-29 15:26:36 +01001814 static const unsigned char xroute[8] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 0, /* PCM */
1816 2, /* PSDIN0 Left */
1817 3, /* PSDIN0 Right */
1818 6, /* SPDIN Left */
1819 7, /* SPDIN Right */
1820 };
1821
1822 nval = xroute[val % 5];
1823 val = old_val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1824 val &= ~(0x07 << shift);
1825 val |= nval << shift;
1826 change = val != old_val;
1827 if (change)
1828 outl(val, ICEMT1724(ice, ROUTE_PLAYBACK));
1829 return change;
1830}
1831
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001832static int snd_vt1724_pro_route_analog_get(struct snd_kcontrol *kcontrol,
1833 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001835 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001837 ucontrol->value.enumerated.item[0] =
1838 get_route_val(ice, analog_route_shift(idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 return 0;
1840}
1841
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001842static int snd_vt1724_pro_route_analog_put(struct snd_kcontrol *kcontrol,
1843 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001845 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1847 return put_route_val(ice, ucontrol->value.enumerated.item[0],
1848 analog_route_shift(idx));
1849}
1850
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001851static int snd_vt1724_pro_route_spdif_get(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);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001856 ucontrol->value.enumerated.item[0] =
1857 get_route_val(ice, digital_route_shift(idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 return 0;
1859}
1860
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001861static int snd_vt1724_pro_route_spdif_put(struct snd_kcontrol *kcontrol,
1862 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001864 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1866 return put_route_val(ice, ucontrol->value.enumerated.item[0],
1867 digital_route_shift(idx));
1868}
1869
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001870static struct snd_kcontrol_new snd_vt1724_mixer_pro_analog_route __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1872 .name = "H/W Playback Route",
1873 .info = snd_vt1724_pro_route_info,
1874 .get = snd_vt1724_pro_route_analog_get,
1875 .put = snd_vt1724_pro_route_analog_put,
1876};
1877
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001878static struct snd_kcontrol_new snd_vt1724_mixer_pro_spdif_route __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1880 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
1881 .info = snd_vt1724_pro_route_info,
1882 .get = snd_vt1724_pro_route_spdif_get,
1883 .put = snd_vt1724_pro_route_spdif_put,
1884 .count = 2,
1885};
1886
1887
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001888static int snd_vt1724_pro_peak_info(struct snd_kcontrol *kcontrol,
1889 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890{
1891 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1892 uinfo->count = 22; /* FIXME: for compatibility with ice1712... */
1893 uinfo->value.integer.min = 0;
1894 uinfo->value.integer.max = 255;
1895 return 0;
1896}
1897
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001898static int snd_vt1724_pro_peak_get(struct snd_kcontrol *kcontrol,
1899 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001901 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 int idx;
1903
1904 spin_lock_irq(&ice->reg_lock);
1905 for (idx = 0; idx < 22; idx++) {
1906 outb(idx, ICEMT1724(ice, MONITOR_PEAKINDEX));
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001907 ucontrol->value.integer.value[idx] =
1908 inb(ICEMT1724(ice, MONITOR_PEAKDATA));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 }
1910 spin_unlock_irq(&ice->reg_lock);
1911 return 0;
1912}
1913
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001914static struct snd_kcontrol_new snd_vt1724_mixer_pro_peak __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1916 .name = "Multi Track Peak",
1917 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1918 .info = snd_vt1724_pro_peak_info,
1919 .get = snd_vt1724_pro_peak_get
1920};
1921
1922/*
1923 *
1924 */
1925
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001926static struct snd_ice1712_card_info no_matched __devinitdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001928static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 snd_vt1724_revo_cards,
1930 snd_vt1724_amp_cards,
1931 snd_vt1724_aureon_cards,
1932 snd_vt1720_mobo_cards,
1933 snd_vt1720_pontis_cards,
1934 snd_vt1724_prodigy192_cards,
1935 snd_vt1724_juli_cards,
1936 snd_vt1724_phase_cards,
Clement Guedezf6cdab52007-01-08 10:48:41 +01001937 snd_vt1724_wtm_cards,
Shin-ya Okadaf31639b2007-10-23 15:08:18 +02001938 snd_vt1724_se_cards,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 NULL,
1940};
1941
1942
1943/*
1944 */
1945
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001946static void wait_i2c_busy(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947{
1948 int t = 0x10000;
1949 while ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY) && t--)
1950 ;
1951 if (t == -1)
1952 printk(KERN_ERR "ice1724: i2c busy timeout\n");
1953}
1954
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001955unsigned char snd_vt1724_read_i2c(struct snd_ice1712 *ice,
1956 unsigned char dev, unsigned char addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957{
1958 unsigned char val;
1959
Ingo Molnar62932df2006-01-16 16:34:20 +01001960 mutex_lock(&ice->i2c_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1962 outb(dev & ~VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1963 wait_i2c_busy(ice);
1964 val = inb(ICEREG1724(ice, I2C_DATA));
Ingo Molnar62932df2006-01-16 16:34:20 +01001965 mutex_unlock(&ice->i2c_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 //printk("i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val);
1967 return val;
1968}
1969
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001970void snd_vt1724_write_i2c(struct snd_ice1712 *ice,
1971 unsigned char dev, unsigned char addr, unsigned char data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972{
Ingo Molnar62932df2006-01-16 16:34:20 +01001973 mutex_lock(&ice->i2c_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 wait_i2c_busy(ice);
1975 //printk("i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data);
1976 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1977 outb(data, ICEREG1724(ice, I2C_DATA));
1978 outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1979 wait_i2c_busy(ice);
Ingo Molnar62932df2006-01-16 16:34:20 +01001980 mutex_unlock(&ice->i2c_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981}
1982
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001983static int __devinit snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
1984 const char *modelname)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985{
1986 const int dev = 0xa0; /* EEPROM device address */
1987 unsigned int i, size;
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001988 struct snd_ice1712_card_info * const *tbl, *c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
1990 if (! modelname || ! *modelname) {
1991 ice->eeprom.subvendor = 0;
1992 if ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_EEPROM) != 0)
1993 ice->eeprom.subvendor =
1994 (snd_vt1724_read_i2c(ice, dev, 0x00) << 0) |
1995 (snd_vt1724_read_i2c(ice, dev, 0x01) << 8) |
1996 (snd_vt1724_read_i2c(ice, dev, 0x02) << 16) |
1997 (snd_vt1724_read_i2c(ice, dev, 0x03) << 24);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001998 if (ice->eeprom.subvendor == 0 ||
1999 ice->eeprom.subvendor == (unsigned int)-1) {
2000 /* invalid subvendor from EEPROM, try the PCI
2001 * subststem ID instead
2002 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 u16 vendor, device;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002004 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID,
2005 &vendor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002007 ice->eeprom.subvendor =
2008 ((unsigned int)swab16(vendor) << 16) | swab16(device);
2009 if (ice->eeprom.subvendor == 0 ||
2010 ice->eeprom.subvendor == (unsigned int)-1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 printk(KERN_ERR "ice1724: No valid ID is found\n");
2012 return -ENXIO;
2013 }
2014 }
2015 }
2016 for (tbl = card_tables; *tbl; tbl++) {
2017 for (c = *tbl; c->subvendor; c++) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002018 if (modelname && c->model &&
2019 ! strcmp(modelname, c->model)) {
2020 printk(KERN_INFO "ice1724: Using board model %s\n",
2021 c->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 ice->eeprom.subvendor = c->subvendor;
2023 } else if (c->subvendor != ice->eeprom.subvendor)
2024 continue;
2025 if (! c->eeprom_size || ! c->eeprom_data)
2026 goto found;
2027 /* if the EEPROM is given by the driver, use it */
2028 snd_printdd("using the defined eeprom..\n");
2029 ice->eeprom.version = 2;
2030 ice->eeprom.size = c->eeprom_size + 6;
2031 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
2032 goto read_skipped;
2033 }
2034 }
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002035 printk(KERN_WARNING "ice1724: No matching model found for ID 0x%x\n",
2036 ice->eeprom.subvendor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037
2038 found:
2039 ice->eeprom.size = snd_vt1724_read_i2c(ice, dev, 0x04);
2040 if (ice->eeprom.size < 6)
2041 ice->eeprom.size = 32;
2042 else if (ice->eeprom.size > 32) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002043 printk(KERN_ERR "ice1724: Invalid EEPROM (size = %i)\n",
2044 ice->eeprom.size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 return -EIO;
2046 }
2047 ice->eeprom.version = snd_vt1724_read_i2c(ice, dev, 0x05);
2048 if (ice->eeprom.version != 2)
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002049 printk(KERN_WARNING "ice1724: Invalid EEPROM version %i\n",
2050 ice->eeprom.version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 size = ice->eeprom.size - 6;
2052 for (i = 0; i < size; i++)
2053 ice->eeprom.data[i] = snd_vt1724_read_i2c(ice, dev, i + 6);
2054
2055 read_skipped:
2056 ice->eeprom.gpiomask = eeprom_triple(ice, ICE_EEP2_GPIO_MASK);
2057 ice->eeprom.gpiostate = eeprom_triple(ice, ICE_EEP2_GPIO_STATE);
2058 ice->eeprom.gpiodir = eeprom_triple(ice, ICE_EEP2_GPIO_DIR);
2059
2060 return 0;
2061}
2062
2063
2064
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002065static int __devinit snd_vt1724_chip_init(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066{
2067 outb(VT1724_RESET , ICEREG1724(ice, CONTROL));
2068 udelay(200);
2069 outb(0, ICEREG1724(ice, CONTROL));
2070 udelay(200);
2071 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG));
2072 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG));
2073 outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES));
2074 outb(ice->eeprom.data[ICE_EEP2_SPDIF], ICEREG1724(ice, SPDIF_CFG));
2075
2076 ice->gpio.write_mask = ice->eeprom.gpiomask;
2077 ice->gpio.direction = ice->eeprom.gpiodir;
2078 snd_vt1724_set_gpio_mask(ice, ice->eeprom.gpiomask);
2079 snd_vt1724_set_gpio_dir(ice, ice->eeprom.gpiodir);
2080 snd_vt1724_set_gpio_data(ice, ice->eeprom.gpiostate);
2081
2082 outb(0, ICEREG1724(ice, POWERDOWN));
2083
2084 return 0;
2085}
2086
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002087static int __devinit snd_vt1724_spdif_build_controls(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088{
2089 int err;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002090 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
2092 snd_assert(ice->pcm != NULL, return -EIO);
2093
2094 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice));
2095 if (err < 0)
2096 return err;
2097
2098 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_spdif_switch, ice));
2099 if (err < 0)
2100 return err;
2101
2102 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_default, ice));
2103 if (err < 0)
2104 return err;
2105 kctl->id.device = ice->pcm->device;
2106 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskc, ice));
2107 if (err < 0)
2108 return err;
2109 kctl->id.device = ice->pcm->device;
2110 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskp, ice));
2111 if (err < 0)
2112 return err;
2113 kctl->id.device = ice->pcm->device;
2114#if 0 /* use default only */
2115 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_stream, ice));
2116 if (err < 0)
2117 return err;
2118 kctl->id.device = ice->pcm->device;
2119 ice->spdif.stream_ctl = kctl;
2120#endif
2121 return 0;
2122}
2123
2124
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002125static int __devinit snd_vt1724_build_controls(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126{
2127 int err;
2128
2129 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_eeprom, ice));
2130 if (err < 0)
2131 return err;
2132 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_internal_clock, ice));
2133 if (err < 0)
2134 return err;
2135
2136 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_locking, ice));
2137 if (err < 0)
2138 return err;
2139 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_reset, ice));
2140 if (err < 0)
2141 return err;
2142
2143 if (ice->num_total_dacs > 0) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002144 struct snd_kcontrol_new tmp = snd_vt1724_mixer_pro_analog_route;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 tmp.count = ice->num_total_dacs;
2146 if (ice->vt1720 && tmp.count > 2)
2147 tmp.count = 2;
2148 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2149 if (err < 0)
2150 return err;
2151 }
2152
2153 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_peak, ice));
2154 if (err < 0)
2155 return err;
2156
2157 return 0;
2158}
2159
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002160static int snd_vt1724_free(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161{
2162 if (! ice->port)
2163 goto __hw_end;
2164 /* mask all interrupts */
2165 outb(0xff, ICEMT1724(ice, DMA_INT_MASK));
2166 outb(0xff, ICEREG1724(ice, IRQMASK));
2167 /* --- */
2168 __hw_end:
2169 if (ice->irq >= 0) {
2170 synchronize_irq(ice->irq);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002171 free_irq(ice->irq, ice);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 }
2173 pci_release_regions(ice->pci);
2174 snd_ice1712_akm4xxx_free(ice);
2175 pci_disable_device(ice->pci);
2176 kfree(ice);
2177 return 0;
2178}
2179
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002180static int snd_vt1724_dev_free(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002182 struct snd_ice1712 *ice = device->device_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 return snd_vt1724_free(ice);
2184}
2185
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002186static int __devinit snd_vt1724_create(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 struct pci_dev *pci,
2188 const char *modelname,
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002189 struct snd_ice1712 ** r_ice1712)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002191 struct snd_ice1712 *ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 int err;
2193 unsigned char mask;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002194 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 .dev_free = snd_vt1724_dev_free,
2196 };
2197
2198 *r_ice1712 = NULL;
2199
2200 /* enable PCI device */
2201 if ((err = pci_enable_device(pci)) < 0)
2202 return err;
2203
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002204 ice = kzalloc(sizeof(*ice), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 if (ice == NULL) {
2206 pci_disable_device(pci);
2207 return -ENOMEM;
2208 }
2209 ice->vt1724 = 1;
2210 spin_lock_init(&ice->reg_lock);
Ingo Molnar62932df2006-01-16 16:34:20 +01002211 mutex_init(&ice->gpio_mutex);
2212 mutex_init(&ice->open_mutex);
2213 mutex_init(&ice->i2c_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 ice->gpio.set_mask = snd_vt1724_set_gpio_mask;
2215 ice->gpio.set_dir = snd_vt1724_set_gpio_dir;
2216 ice->gpio.set_data = snd_vt1724_set_gpio_data;
2217 ice->gpio.get_data = snd_vt1724_get_gpio_data;
2218 ice->card = card;
2219 ice->pci = pci;
2220 ice->irq = -1;
2221 pci_set_master(pci);
2222 snd_vt1724_proc_init(ice);
2223 synchronize_irq(pci->irq);
2224
2225 if ((err = pci_request_regions(pci, "ICE1724")) < 0) {
2226 kfree(ice);
2227 pci_disable_device(pci);
2228 return err;
2229 }
2230 ice->port = pci_resource_start(pci, 0);
2231 ice->profi_port = pci_resource_start(pci, 1);
2232
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002233 if (request_irq(pci->irq, snd_vt1724_interrupt,
Takashi Iwai437a5a42006-11-21 12:14:23 +01002234 IRQF_SHARED, "ICE1724", ice)) {
Takashi Iwai99b359b2005-10-20 18:26:44 +02002235 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 snd_vt1724_free(ice);
2237 return -EIO;
2238 }
2239
2240 ice->irq = pci->irq;
2241
2242 if (snd_vt1724_read_eeprom(ice, modelname) < 0) {
2243 snd_vt1724_free(ice);
2244 return -EIO;
2245 }
2246 if (snd_vt1724_chip_init(ice) < 0) {
2247 snd_vt1724_free(ice);
2248 return -EIO;
2249 }
2250
2251 /* unmask used interrupts */
2252 if (! (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401))
2253 mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
2254 else
2255 mask = 0;
2256 outb(mask, ICEREG1724(ice, IRQMASK));
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002257 /* don't handle FIFO overrun/underruns (just yet),
2258 * since they cause machine lockups
2259 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK));
2261
2262 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2263 snd_vt1724_free(ice);
2264 return err;
2265 }
2266
2267 snd_card_set_dev(card, &pci->dev);
2268
2269 *r_ice1712 = ice;
2270 return 0;
2271}
2272
2273
2274/*
2275 *
2276 * Registration
2277 *
2278 */
2279
2280static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2281 const struct pci_device_id *pci_id)
2282{
2283 static int dev;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002284 struct snd_card *card;
2285 struct snd_ice1712 *ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 int pcm_dev = 0, err;
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01002287 struct snd_ice1712_card_info * const *tbl, *c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288
2289 if (dev >= SNDRV_CARDS)
2290 return -ENODEV;
2291 if (!enable[dev]) {
2292 dev++;
2293 return -ENOENT;
2294 }
2295
2296 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2297 if (card == NULL)
2298 return -ENOMEM;
2299
2300 strcpy(card->driver, "ICE1724");
2301 strcpy(card->shortname, "ICEnsemble ICE1724");
2302
2303 if ((err = snd_vt1724_create(card, pci, model[dev], &ice)) < 0) {
2304 snd_card_free(card);
2305 return err;
2306 }
2307
2308 for (tbl = card_tables; *tbl; tbl++) {
2309 for (c = *tbl; c->subvendor; c++) {
2310 if (c->subvendor == ice->eeprom.subvendor) {
2311 strcpy(card->shortname, c->name);
2312 if (c->driver) /* specific driver? */
2313 strcpy(card->driver, c->driver);
2314 if (c->chip_init) {
2315 if ((err = c->chip_init(ice)) < 0) {
2316 snd_card_free(card);
2317 return err;
2318 }
2319 }
2320 goto __found;
2321 }
2322 }
2323 }
2324 c = &no_matched;
2325 __found:
Takashi Iwaif06934b2007-04-10 11:15:34 +02002326 /*
2327 * VT1724 has separate DMAs for the analog and the SPDIF streams while
2328 * ICE1712 has only one for both (mixed up).
2329 *
2330 * Confusingly the analog PCM is named "professional" here because it
2331 * was called so in ice1712 driver, and vt1724 driver is derived from
2332 * ice1712 driver.
2333 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334
2335 if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) {
2336 snd_card_free(card);
2337 return err;
2338 }
2339
2340 if ((err = snd_vt1724_pcm_spdif(ice, pcm_dev++)) < 0) {
2341 snd_card_free(card);
2342 return err;
2343 }
2344
2345 if ((err = snd_vt1724_pcm_indep(ice, pcm_dev++)) < 0) {
2346 snd_card_free(card);
2347 return err;
2348 }
2349
2350 if ((err = snd_vt1724_ac97_mixer(ice)) < 0) {
2351 snd_card_free(card);
2352 return err;
2353 }
2354
2355 if ((err = snd_vt1724_build_controls(ice)) < 0) {
2356 snd_card_free(card);
2357 return err;
2358 }
2359
2360 if (ice->pcm && ice->has_spdif) { /* has SPDIF I/O */
2361 if ((err = snd_vt1724_spdif_build_controls(ice)) < 0) {
2362 snd_card_free(card);
2363 return err;
2364 }
2365 }
2366
2367 if (c->build_controls) {
2368 if ((err = c->build_controls(ice)) < 0) {
2369 snd_card_free(card);
2370 return err;
2371 }
2372 }
2373
2374 if (! c->no_mpu401) {
2375 if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) {
2376 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
Takashi Iwai302e4c22006-05-23 13:24:30 +02002377 ICEREG1724(ice, MPU_CTRL),
2378 MPU401_INFO_INTEGRATED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 ice->irq, 0,
2380 &ice->rmidi[0])) < 0) {
2381 snd_card_free(card);
2382 return err;
2383 }
2384 }
2385 }
2386
2387 sprintf(card->longname, "%s at 0x%lx, irq %i",
2388 card->shortname, ice->port, ice->irq);
2389
2390 if ((err = snd_card_register(card)) < 0) {
2391 snd_card_free(card);
2392 return err;
2393 }
2394 pci_set_drvdata(pci, card);
2395 dev++;
2396 return 0;
2397}
2398
2399static void __devexit snd_vt1724_remove(struct pci_dev *pci)
2400{
2401 snd_card_free(pci_get_drvdata(pci));
2402 pci_set_drvdata(pci, NULL);
2403}
2404
2405static struct pci_driver driver = {
2406 .name = "ICE1724",
2407 .id_table = snd_vt1724_ids,
2408 .probe = snd_vt1724_probe,
2409 .remove = __devexit_p(snd_vt1724_remove),
2410};
2411
2412static int __init alsa_card_ice1724_init(void)
2413{
Takashi Iwai01d25d42005-04-11 16:58:24 +02002414 return pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415}
2416
2417static void __exit alsa_card_ice1724_exit(void)
2418{
2419 pci_unregister_driver(&driver);
2420}
2421
2422module_init(alsa_card_ice1724_init)
2423module_exit(alsa_card_ice1724_exit)