blob: 6b15e1cbfe4f5e3f8498f798ab95b571ad10b734 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ALSA driver for VT1724 ICEnsemble ICE1724 / VIA VT1724 (Envy24HT)
3 * VIA VT1720 (Envy24PT)
4 *
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02005 * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * 2002 James Stafford <jstafford@ampltd.com>
7 * 2003 Takashi Iwai <tiwai@suse.de>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/io.h>
26#include <linux/delay.h>
27#include <linux/interrupt.h>
28#include <linux/init.h>
29#include <linux/pci.h>
30#include <linux/slab.h>
31#include <linux/moduleparam.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010032#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <sound/core.h>
34#include <sound/info.h>
35#include <sound/mpu401.h>
36#include <sound/initval.h>
37
38#include <sound/asoundef.h>
39
40#include "ice1712.h"
41#include "envy24ht.h"
42
43/* lowlevel routines */
44#include "amp.h"
45#include "revo.h"
46#include "aureon.h"
47#include "vt1720_mobo.h"
48#include "pontis.h"
49#include "prodigy192.h"
Julian Scheel6b8d6e52008-01-16 19:50:00 +010050#include "prodigy_hifi.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include "juli.h"
52#include "phase.h"
Clement Guedezf6cdab52007-01-08 10:48:41 +010053#include "wtm.h"
Shin-ya Okadaf31639b2007-10-23 15:08:18 +020054#include "se.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020056MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070057MODULE_DESCRIPTION("VIA ICEnsemble ICE1724/1720 (Envy24HT/PT)");
58MODULE_LICENSE("GPL");
59MODULE_SUPPORTED_DEVICE("{"
60 REVO_DEVICE_DESC
61 AMP_AUDIO2000_DEVICE_DESC
62 AUREON_DEVICE_DESC
63 VT1720_MOBO_DEVICE_DESC
64 PONTIS_DEVICE_DESC
65 PRODIGY192_DEVICE_DESC
Julian Scheel6b8d6e52008-01-16 19:50:00 +010066 PRODIGY_HIFI_DEVICE_DESC
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 JULI_DEVICE_DESC
68 PHASE_DEVICE_DESC
Clement Guedezf6cdab52007-01-08 10:48:41 +010069 WTM_DEVICE_DESC
Shin-ya Okadaf31639b2007-10-23 15:08:18 +020070 SE_DEVICE_DESC
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 "{VIA,VT1720},"
72 "{VIA,VT1724},"
73 "{ICEnsemble,Generic ICE1724},"
74 "{ICEnsemble,Generic Envy24HT}"
75 "{ICEnsemble,Generic Envy24PT}}");
76
77static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
78static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
79static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
80static char *model[SNDRV_CARDS];
81
82module_param_array(index, int, NULL, 0444);
83MODULE_PARM_DESC(index, "Index value for ICE1724 soundcard.");
84module_param_array(id, charp, NULL, 0444);
85MODULE_PARM_DESC(id, "ID string for ICE1724 soundcard.");
86module_param_array(enable, bool, NULL, 0444);
87MODULE_PARM_DESC(enable, "Enable ICE1724 soundcard.");
88module_param_array(model, charp, NULL, 0444);
89MODULE_PARM_DESC(model, "Use the given board model.");
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92/* Both VT1720 and VT1724 have the same PCI IDs */
Takashi Iwai32b47da2007-01-29 15:26:36 +010093static const struct pci_device_id snd_vt1724_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_VT1724, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
95 { 0, }
96};
97
98MODULE_DEVICE_TABLE(pci, snd_vt1724_ids);
99
100
101static int PRO_RATE_LOCKED;
102static int PRO_RATE_RESET = 1;
103static unsigned int PRO_RATE_DEFAULT = 44100;
104
105/*
106 * Basic I/O
107 */
108
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100109/*
110 * default rates, default clock routines
111 */
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/* check whether the clock mode is spdif-in */
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100114static inline int stdclock_is_spdif_master(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
116 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0;
117}
118
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100119static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100121 return ice->is_spdif_master(ice) || PRO_RATE_LOCKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123
124/*
125 * ac97 section
126 */
127
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100128static unsigned char snd_vt1724_ac97_ready(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
130 unsigned char old_cmd;
131 int tm;
132 for (tm = 0; tm < 0x10000; tm++) {
133 old_cmd = inb(ICEMT1724(ice, AC97_CMD));
134 if (old_cmd & (VT1724_AC97_WRITE | VT1724_AC97_READ))
135 continue;
136 if (!(old_cmd & VT1724_AC97_READY))
137 continue;
138 return old_cmd;
139 }
140 snd_printd(KERN_ERR "snd_vt1724_ac97_ready: timeout\n");
141 return old_cmd;
142}
143
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100144static int snd_vt1724_ac97_wait_bit(struct snd_ice1712 *ice, unsigned char bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
146 int tm;
147 for (tm = 0; tm < 0x10000; tm++)
148 if ((inb(ICEMT1724(ice, AC97_CMD)) & bit) == 0)
149 return 0;
150 snd_printd(KERN_ERR "snd_vt1724_ac97_wait_bit: timeout\n");
151 return -EIO;
152}
153
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100154static void snd_vt1724_ac97_write(struct snd_ac97 *ac97,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 unsigned short reg,
156 unsigned short val)
157{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100158 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 unsigned char old_cmd;
160
161 old_cmd = snd_vt1724_ac97_ready(ice);
162 old_cmd &= ~VT1724_AC97_ID_MASK;
163 old_cmd |= ac97->num;
164 outb(reg, ICEMT1724(ice, AC97_INDEX));
165 outw(val, ICEMT1724(ice, AC97_DATA));
166 outb(old_cmd | VT1724_AC97_WRITE, ICEMT1724(ice, AC97_CMD));
167 snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_WRITE);
168}
169
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100170static unsigned short snd_vt1724_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100172 struct snd_ice1712 *ice = ac97->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 unsigned char old_cmd;
174
175 old_cmd = snd_vt1724_ac97_ready(ice);
176 old_cmd &= ~VT1724_AC97_ID_MASK;
177 old_cmd |= ac97->num;
178 outb(reg, ICEMT1724(ice, AC97_INDEX));
179 outb(old_cmd | VT1724_AC97_READ, ICEMT1724(ice, AC97_CMD));
180 if (snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_READ) < 0)
181 return ~0;
182 return inw(ICEMT1724(ice, AC97_DATA));
183}
184
185
186/*
187 * GPIO operations
188 */
189
190/* set gpio direction 0 = read, 1 = write */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100191static void snd_vt1724_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
193 outl(data, ICEREG1724(ice, GPIO_DIRECTION));
194 inw(ICEREG1724(ice, GPIO_DIRECTION)); /* dummy read for pci-posting */
195}
196
197/* set the gpio mask (0 = writable) */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100198static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
200 outw(data, ICEREG1724(ice, GPIO_WRITE_MASK));
201 if (! ice->vt1720) /* VT1720 supports only 16 GPIO bits */
202 outb((data >> 16) & 0xff, ICEREG1724(ice, GPIO_WRITE_MASK_22));
203 inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */
204}
205
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100206static void snd_vt1724_set_gpio_data(struct snd_ice1712 *ice, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207{
208 outw(data, ICEREG1724(ice, GPIO_DATA));
209 if (! ice->vt1720)
210 outb(data >> 16, ICEREG1724(ice, GPIO_DATA_22));
211 inw(ICEREG1724(ice, GPIO_DATA)); /* dummy read for pci-posting */
212}
213
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100214static unsigned int snd_vt1724_get_gpio_data(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215{
216 unsigned int data;
217 if (! ice->vt1720)
218 data = (unsigned int)inb(ICEREG1724(ice, GPIO_DATA_22));
219 else
220 data = 0;
221 data = (data << 16) | inw(ICEREG1724(ice, GPIO_DATA));
222 return data;
223}
224
225/*
226 * Interrupt handler
227 */
228
David Howells7d12e782006-10-05 14:55:46 +0100229static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100231 struct snd_ice1712 *ice = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 unsigned char status;
233 int handled = 0;
234
235 while (1) {
236 status = inb(ICEREG1724(ice, IRQSTAT));
237 if (status == 0)
238 break;
239
240 handled = 1;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100241 /* these should probably be separated at some point,
242 * but as we don't currently have MPU support on the board
243 * I will leave it
244 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 if ((status & VT1724_IRQ_MPU_RX)||(status & VT1724_IRQ_MPU_TX)) {
246 if (ice->rmidi[0])
David Howells7d12e782006-10-05 14:55:46 +0100247 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 outb(status & (VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX), ICEREG1724(ice, IRQSTAT));
249 status &= ~(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX);
250 }
251 if (status & VT1724_IRQ_MTPCM) {
252 /*
253 * Multi-track PCM
254 * PCM assignment are:
255 * Playback DMA0 (M/C) = playback_pro_substream
256 * Playback DMA1 = playback_con_substream_ds[0]
257 * Playback DMA2 = playback_con_substream_ds[1]
258 * Playback DMA3 = playback_con_substream_ds[2]
259 * Playback DMA4 (SPDIF) = playback_con_substream
260 * Record DMA0 = capture_pro_substream
261 * Record DMA1 = capture_con_substream
262 */
263 unsigned char mtstat = inb(ICEMT1724(ice, IRQ));
264 if (mtstat & VT1724_MULTI_PDMA0) {
265 if (ice->playback_pro_substream)
266 snd_pcm_period_elapsed(ice->playback_pro_substream);
267 }
268 if (mtstat & VT1724_MULTI_RDMA0) {
269 if (ice->capture_pro_substream)
270 snd_pcm_period_elapsed(ice->capture_pro_substream);
271 }
272 if (mtstat & VT1724_MULTI_PDMA1) {
273 if (ice->playback_con_substream_ds[0])
274 snd_pcm_period_elapsed(ice->playback_con_substream_ds[0]);
275 }
276 if (mtstat & VT1724_MULTI_PDMA2) {
277 if (ice->playback_con_substream_ds[1])
278 snd_pcm_period_elapsed(ice->playback_con_substream_ds[1]);
279 }
280 if (mtstat & VT1724_MULTI_PDMA3) {
281 if (ice->playback_con_substream_ds[2])
282 snd_pcm_period_elapsed(ice->playback_con_substream_ds[2]);
283 }
284 if (mtstat & VT1724_MULTI_PDMA4) {
285 if (ice->playback_con_substream)
286 snd_pcm_period_elapsed(ice->playback_con_substream);
287 }
288 if (mtstat & VT1724_MULTI_RDMA1) {
289 if (ice->capture_con_substream)
290 snd_pcm_period_elapsed(ice->capture_con_substream);
291 }
292 /* ack anyway to avoid freeze */
293 outb(mtstat, ICEMT1724(ice, IRQ));
294 /* ought to really handle this properly */
295 if (mtstat & VT1724_MULTI_FIFO_ERR) {
296 unsigned char fstat = inb(ICEMT1724(ice, DMA_FIFO_ERR));
297 outb(fstat, ICEMT1724(ice, DMA_FIFO_ERR));
298 outb(VT1724_MULTI_FIFO_ERR | inb(ICEMT1724(ice, DMA_INT_MASK)), ICEMT1724(ice, DMA_INT_MASK));
299 /* If I don't do this, I get machine lockup due to continual interrupts */
300 }
301
302 }
303 }
304 return IRQ_RETVAL(handled);
305}
306
307/*
308 * PCM code - professional part (multitrack)
309 */
310
311static unsigned int rates[] = {
312 8000, 9600, 11025, 12000, 16000, 22050, 24000,
313 32000, 44100, 48000, 64000, 88200, 96000,
314 176400, 192000,
315};
316
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100317static struct snd_pcm_hw_constraint_list hw_constraints_rates_96 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 .count = ARRAY_SIZE(rates) - 2, /* up to 96000 */
319 .list = rates,
320 .mask = 0,
321};
322
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100323static struct snd_pcm_hw_constraint_list hw_constraints_rates_48 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 .count = ARRAY_SIZE(rates) - 5, /* up to 48000 */
325 .list = rates,
326 .mask = 0,
327};
328
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100329static struct snd_pcm_hw_constraint_list hw_constraints_rates_192 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 .count = ARRAY_SIZE(rates),
331 .list = rates,
332 .mask = 0,
333};
334
335struct vt1724_pcm_reg {
336 unsigned int addr; /* ADDR register offset */
337 unsigned int size; /* SIZE register offset */
338 unsigned int count; /* COUNT register offset */
339 unsigned int start; /* start & pause bit */
340};
341
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100342static int snd_vt1724_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100344 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 unsigned char what;
346 unsigned char old;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100347 struct snd_pcm_substream *s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349 what = 0;
Takashi Iwaief991b92007-02-22 12:52:53 +0100350 snd_pcm_group_for_each_entry(s, substream) {
Clemens Ladisch29998d22007-07-30 08:14:31 +0200351 if (snd_pcm_substream_chip(s) == ice) {
352 const struct vt1724_pcm_reg *reg;
353 reg = s->runtime->private_data;
354 what |= reg->start;
355 snd_pcm_trigger_done(s, substream);
356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 }
358
359 switch (cmd) {
360 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
361 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
362 spin_lock(&ice->reg_lock);
363 old = inb(ICEMT1724(ice, DMA_PAUSE));
364 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
365 old |= what;
366 else
367 old &= ~what;
368 outb(old, ICEMT1724(ice, DMA_PAUSE));
369 spin_unlock(&ice->reg_lock);
370 break;
371
372 case SNDRV_PCM_TRIGGER_START:
373 case SNDRV_PCM_TRIGGER_STOP:
374 spin_lock(&ice->reg_lock);
375 old = inb(ICEMT1724(ice, DMA_CONTROL));
376 if (cmd == SNDRV_PCM_TRIGGER_START)
377 old |= what;
378 else
379 old &= ~what;
380 outb(old, ICEMT1724(ice, DMA_CONTROL));
381 spin_unlock(&ice->reg_lock);
382 break;
383
384 default:
385 return -EINVAL;
386 }
387 return 0;
388}
389
390/*
391 */
392
393#define DMA_STARTS (VT1724_RDMA0_START|VT1724_PDMA0_START|VT1724_RDMA1_START|\
394 VT1724_PDMA1_START|VT1724_PDMA2_START|VT1724_PDMA3_START|VT1724_PDMA4_START)
395#define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\
396 VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE)
397
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100398static const unsigned int stdclock_rate_list[16] = {
399 48000, 24000, 12000, 9600, 32000, 16000, 8000, 96000, 44100,
400 22050, 11025, 88200, 176400, 0, 192000, 64000
401};
402
403static unsigned int stdclock_get_rate(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100405 unsigned int rate;
406 rate = stdclock_rate_list[inb(ICEMT1724(ice, RATE)) & 15];
407 return rate;
408}
409
410static void stdclock_set_rate(struct snd_ice1712 *ice, unsigned int rate)
411{
412 int i;
413 for (i = 0; i < ARRAY_SIZE(stdclock_rate_list); i++) {
414 if (stdclock_rate_list[i] == rate) {
415 outb(i, ICEMT1724(ice, RATE));
416 return;
417 }
418 }
419}
420
421static unsigned char stdclock_set_mclk(struct snd_ice1712 *ice,
422 unsigned int rate)
423{
424 unsigned char val, old;
425 /* check MT02 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100427 val = old = inb(ICEMT1724(ice, I2S_FORMAT));
428 if (rate > 96000)
429 val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 else
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100431 val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
432 if (val != old) {
433 outb(val, ICEMT1724(ice, I2S_FORMAT));
434 /* master clock changed */
435 return 1;
436 }
437 }
438 /* no change in master clock */
439 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100442static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
443 int force)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
445 unsigned long flags;
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100446 unsigned char mclk_change;
447 unsigned int i, old_rate;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100449 if (rate > ice->hw_rates->list[ice->hw_rates->count - 1])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 spin_lock_irqsave(&ice->reg_lock, flags);
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100452 if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
454 /* running? we cannot change the rate now... */
455 spin_unlock_irqrestore(&ice->reg_lock, flags);
456 return;
457 }
458 if (!force && is_pro_rate_locked(ice)) {
459 spin_unlock_irqrestore(&ice->reg_lock, flags);
460 return;
461 }
462
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100463 old_rate = ice->get_rate(ice);
464 if (force || (old_rate != rate))
465 ice->set_rate(ice, rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 else if (rate == ice->cur_rate) {
467 spin_unlock_irqrestore(&ice->reg_lock, flags);
468 return;
469 }
470
471 ice->cur_rate = rate;
472
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100473 /* setting master clock */
474 mclk_change = ice->set_mclk(ice, rate);
475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 spin_unlock_irqrestore(&ice->reg_lock, flags);
477
478 if (mclk_change && ice->gpio.i2s_mclk_changed)
479 ice->gpio.i2s_mclk_changed(ice);
480 if (ice->gpio.set_pro_rate)
481 ice->gpio.set_pro_rate(ice, rate);
482
483 /* set up codecs */
484 for (i = 0; i < ice->akm_codecs; i++) {
485 if (ice->akm[i].ops.set_rate_val)
486 ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
487 }
488 if (ice->spdif.ops.setup_rate)
489 ice->spdif.ops.setup_rate(ice, rate);
490}
491
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100492static int snd_vt1724_pcm_hw_params(struct snd_pcm_substream *substream,
493 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100495 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 int i, chs;
497
498 chs = params_channels(hw_params);
Ingo Molnar62932df2006-01-16 16:34:20 +0100499 mutex_lock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 /* mark surround channels */
501 if (substream == ice->playback_pro_substream) {
502 /* PDMA0 can be multi-channel up to 8 */
503 chs = chs / 2 - 1;
504 for (i = 0; i < chs; i++) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100505 if (ice->pcm_reserved[i] &&
506 ice->pcm_reserved[i] != substream) {
Ingo Molnar62932df2006-01-16 16:34:20 +0100507 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 return -EBUSY;
509 }
510 ice->pcm_reserved[i] = substream;
511 }
512 for (; i < 3; i++) {
513 if (ice->pcm_reserved[i] == substream)
514 ice->pcm_reserved[i] = NULL;
515 }
516 } else {
517 for (i = 0; i < 3; i++) {
518 /* check individual playback stream */
519 if (ice->playback_con_substream_ds[i] == substream) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100520 if (ice->pcm_reserved[i] &&
521 ice->pcm_reserved[i] != substream) {
Ingo Molnar62932df2006-01-16 16:34:20 +0100522 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 return -EBUSY;
524 }
525 ice->pcm_reserved[i] = substream;
526 break;
527 }
528 }
529 }
Ingo Molnar62932df2006-01-16 16:34:20 +0100530 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 snd_vt1724_set_pro_rate(ice, params_rate(hw_params), 0);
532 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
533}
534
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100535static int snd_vt1724_pcm_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100537 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 int i;
539
Ingo Molnar62932df2006-01-16 16:34:20 +0100540 mutex_lock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 /* unmark surround channels */
542 for (i = 0; i < 3; i++)
543 if (ice->pcm_reserved[i] == substream)
544 ice->pcm_reserved[i] = NULL;
Ingo Molnar62932df2006-01-16 16:34:20 +0100545 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 return snd_pcm_lib_free_pages(substream);
547}
548
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100549static int snd_vt1724_playback_pro_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100551 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 unsigned char val;
553 unsigned int size;
554
555 spin_lock_irq(&ice->reg_lock);
556 val = (8 - substream->runtime->channels) >> 1;
557 outb(val, ICEMT1724(ice, BURST));
558
559 outl(substream->runtime->dma_addr, ICEMT1724(ice, PLAYBACK_ADDR));
560
561 size = (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1;
562 // outl(size, ICEMT1724(ice, PLAYBACK_SIZE));
563 outw(size, ICEMT1724(ice, PLAYBACK_SIZE));
564 outb(size >> 16, ICEMT1724(ice, PLAYBACK_SIZE) + 2);
565 size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
566 // outl(size, ICEMT1724(ice, PLAYBACK_COUNT));
567 outw(size, ICEMT1724(ice, PLAYBACK_COUNT));
568 outb(size >> 16, ICEMT1724(ice, PLAYBACK_COUNT) + 2);
569
570 spin_unlock_irq(&ice->reg_lock);
571
572 // 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));
573 return 0;
574}
575
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100576static snd_pcm_uframes_t snd_vt1724_playback_pro_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100578 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 size_t ptr;
580
581 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & VT1724_PDMA0_START))
582 return 0;
583#if 0 /* read PLAYBACK_ADDR */
584 ptr = inl(ICEMT1724(ice, PLAYBACK_ADDR));
585 if (ptr < substream->runtime->dma_addr) {
586 snd_printd("ice1724: invalid negative ptr\n");
587 return 0;
588 }
589 ptr -= substream->runtime->dma_addr;
590 ptr = bytes_to_frames(substream->runtime, ptr);
591 if (ptr >= substream->runtime->buffer_size) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100592 snd_printd("ice1724: invalid ptr %d (size=%d)\n",
593 (int)ptr, (int)substream->runtime->period_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 return 0;
595 }
596#else /* read PLAYBACK_SIZE */
597 ptr = inl(ICEMT1724(ice, PLAYBACK_SIZE)) & 0xffffff;
598 ptr = (ptr + 1) << 2;
599 ptr = bytes_to_frames(substream->runtime, ptr);
600 if (! ptr)
601 ;
602 else if (ptr <= substream->runtime->buffer_size)
603 ptr = substream->runtime->buffer_size - ptr;
604 else {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100605 snd_printd("ice1724: invalid ptr %d (size=%d)\n",
606 (int)ptr, (int)substream->runtime->buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 ptr = 0;
608 }
609#endif
610 return ptr;
611}
612
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100613static int snd_vt1724_pcm_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100615 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Takashi Iwai32b47da2007-01-29 15:26:36 +0100616 const struct vt1724_pcm_reg *reg = substream->runtime->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
618 spin_lock_irq(&ice->reg_lock);
619 outl(substream->runtime->dma_addr, ice->profi_port + reg->addr);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100620 outw((snd_pcm_lib_buffer_bytes(substream) >> 2) - 1,
621 ice->profi_port + reg->size);
622 outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1,
623 ice->profi_port + reg->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 spin_unlock_irq(&ice->reg_lock);
625 return 0;
626}
627
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100628static snd_pcm_uframes_t snd_vt1724_pcm_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100630 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Takashi Iwai32b47da2007-01-29 15:26:36 +0100631 const struct vt1724_pcm_reg *reg = substream->runtime->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 size_t ptr;
633
634 if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & reg->start))
635 return 0;
636#if 0 /* use ADDR register */
637 ptr = inl(ice->profi_port + reg->addr);
638 ptr -= substream->runtime->dma_addr;
639 return bytes_to_frames(substream->runtime, ptr);
640#else /* use SIZE register */
641 ptr = inw(ice->profi_port + reg->size);
642 ptr = (ptr + 1) << 2;
643 ptr = bytes_to_frames(substream->runtime, ptr);
644 if (! ptr)
645 ;
646 else if (ptr <= substream->runtime->buffer_size)
647 ptr = substream->runtime->buffer_size - ptr;
648 else {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100649 snd_printd("ice1724: invalid ptr %d (size=%d)\n",
650 (int)ptr, (int)substream->runtime->buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 ptr = 0;
652 }
653 return ptr;
654#endif
655}
656
Takashi Iwai32b47da2007-01-29 15:26:36 +0100657static const struct vt1724_pcm_reg vt1724_playback_pro_reg = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 .addr = VT1724_MT_PLAYBACK_ADDR,
659 .size = VT1724_MT_PLAYBACK_SIZE,
660 .count = VT1724_MT_PLAYBACK_COUNT,
661 .start = VT1724_PDMA0_START,
662};
663
Takashi Iwai32b47da2007-01-29 15:26:36 +0100664static const struct vt1724_pcm_reg vt1724_capture_pro_reg = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 .addr = VT1724_MT_CAPTURE_ADDR,
666 .size = VT1724_MT_CAPTURE_SIZE,
667 .count = VT1724_MT_CAPTURE_COUNT,
668 .start = VT1724_RDMA0_START,
669};
670
Takashi Iwai32b47da2007-01-29 15:26:36 +0100671static const struct snd_pcm_hardware snd_vt1724_playback_pro =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672{
673 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
674 SNDRV_PCM_INFO_BLOCK_TRANSFER |
675 SNDRV_PCM_INFO_MMAP_VALID |
676 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
677 .formats = SNDRV_PCM_FMTBIT_S32_LE,
678 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
679 .rate_min = 8000,
680 .rate_max = 192000,
681 .channels_min = 2,
682 .channels_max = 8,
683 .buffer_bytes_max = (1UL << 21), /* 19bits dword */
684 .period_bytes_min = 8 * 4 * 2, /* FIXME: constraints needed */
685 .period_bytes_max = (1UL << 21),
686 .periods_min = 2,
687 .periods_max = 1024,
688};
689
Takashi Iwai32b47da2007-01-29 15:26:36 +0100690static const struct snd_pcm_hardware snd_vt1724_spdif =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691{
692 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
693 SNDRV_PCM_INFO_BLOCK_TRANSFER |
694 SNDRV_PCM_INFO_MMAP_VALID |
695 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
696 .formats = SNDRV_PCM_FMTBIT_S32_LE,
Takashi Iwai2dfbeca2005-10-12 10:04:42 +0200697 .rates = (SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100|
698 SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_88200|
699 SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_176400|
700 SNDRV_PCM_RATE_192000),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 .rate_min = 32000,
Takashi Iwai2dfbeca2005-10-12 10:04:42 +0200702 .rate_max = 192000,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 .channels_min = 2,
704 .channels_max = 2,
705 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
706 .period_bytes_min = 2 * 4 * 2,
707 .period_bytes_max = (1UL << 18),
708 .periods_min = 2,
709 .periods_max = 1024,
710};
711
Takashi Iwai32b47da2007-01-29 15:26:36 +0100712static const struct snd_pcm_hardware snd_vt1724_2ch_stereo =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713{
714 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
715 SNDRV_PCM_INFO_BLOCK_TRANSFER |
716 SNDRV_PCM_INFO_MMAP_VALID |
717 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
718 .formats = SNDRV_PCM_FMTBIT_S32_LE,
719 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
720 .rate_min = 8000,
721 .rate_max = 192000,
722 .channels_min = 2,
723 .channels_max = 2,
724 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
725 .period_bytes_min = 2 * 4 * 2,
726 .period_bytes_max = (1UL << 18),
727 .periods_min = 2,
728 .periods_max = 1024,
729};
730
731/*
732 * set rate constraints
733 */
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100734static void set_std_hw_rates(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
737 /* I2S */
738 /* VT1720 doesn't support more than 96kHz */
739 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100740 ice->hw_rates = &hw_constraints_rates_192;
741 else
742 ice->hw_rates = &hw_constraints_rates_96;
743 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 /* ACLINK */
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100745 ice->hw_rates = &hw_constraints_rates_48;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 }
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100747}
748
749static int set_rate_constraints(struct snd_ice1712 *ice,
750 struct snd_pcm_substream *substream)
751{
752 struct snd_pcm_runtime *runtime = substream->runtime;
753
754 runtime->hw.rate_min = ice->hw_rates->list[0];
755 runtime->hw.rate_max = ice->hw_rates->list[ice->hw_rates->count - 1];
756 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
757 return snd_pcm_hw_constraint_list(runtime, 0,
758 SNDRV_PCM_HW_PARAM_RATE,
759 ice->hw_rates);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760}
761
762/* multi-channel playback needs alignment 8x32bit regardless of the channels
763 * actually used
764 */
765#define VT1724_BUFFER_ALIGN 0x20
766
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100767static int snd_vt1724_playback_pro_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100769 struct snd_pcm_runtime *runtime = substream->runtime;
770 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 int chs;
772
Takashi Iwai32b47da2007-01-29 15:26:36 +0100773 runtime->private_data = (void *)&vt1724_playback_pro_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 ice->playback_pro_substream = substream;
775 runtime->hw = snd_vt1724_playback_pro;
776 snd_pcm_set_sync(substream);
777 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
778 set_rate_constraints(ice, substream);
Ingo Molnar62932df2006-01-16 16:34:20 +0100779 mutex_lock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 /* calculate the currently available channels */
781 for (chs = 0; chs < 3; chs++) {
782 if (ice->pcm_reserved[chs])
783 break;
784 }
785 chs = (chs + 1) * 2;
786 runtime->hw.channels_max = chs;
787 if (chs > 2) /* channels must be even */
788 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Ingo Molnar62932df2006-01-16 16:34:20 +0100789 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
791 VT1724_BUFFER_ALIGN);
792 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
793 VT1724_BUFFER_ALIGN);
794 return 0;
795}
796
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100797static int snd_vt1724_capture_pro_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100799 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
800 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Takashi Iwai32b47da2007-01-29 15:26:36 +0100802 runtime->private_data = (void *)&vt1724_capture_pro_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 ice->capture_pro_substream = substream;
804 runtime->hw = snd_vt1724_2ch_stereo;
805 snd_pcm_set_sync(substream);
806 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
807 set_rate_constraints(ice, substream);
808 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
809 VT1724_BUFFER_ALIGN);
810 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
811 VT1724_BUFFER_ALIGN);
812 return 0;
813}
814
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100815static int snd_vt1724_playback_pro_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100817 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
819 if (PRO_RATE_RESET)
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100820 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 ice->playback_pro_substream = NULL;
822
823 return 0;
824}
825
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100826static int snd_vt1724_capture_pro_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100828 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 if (PRO_RATE_RESET)
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100831 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 ice->capture_pro_substream = NULL;
833 return 0;
834}
835
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100836static struct snd_pcm_ops snd_vt1724_playback_pro_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 .open = snd_vt1724_playback_pro_open,
838 .close = snd_vt1724_playback_pro_close,
839 .ioctl = snd_pcm_lib_ioctl,
840 .hw_params = snd_vt1724_pcm_hw_params,
841 .hw_free = snd_vt1724_pcm_hw_free,
842 .prepare = snd_vt1724_playback_pro_prepare,
843 .trigger = snd_vt1724_pcm_trigger,
844 .pointer = snd_vt1724_playback_pro_pointer,
845};
846
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100847static struct snd_pcm_ops snd_vt1724_capture_pro_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 .open = snd_vt1724_capture_pro_open,
849 .close = snd_vt1724_capture_pro_close,
850 .ioctl = snd_pcm_lib_ioctl,
851 .hw_params = snd_vt1724_pcm_hw_params,
852 .hw_free = snd_vt1724_pcm_hw_free,
853 .prepare = snd_vt1724_pcm_prepare,
854 .trigger = snd_vt1724_pcm_trigger,
855 .pointer = snd_vt1724_pcm_pointer,
856};
857
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100858static int __devinit snd_vt1724_pcm_profi(struct snd_ice1712 * ice, int device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100860 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 int err;
862
863 err = snd_pcm_new(ice->card, "ICE1724", device, 1, 1, &pcm);
864 if (err < 0)
865 return err;
866
867 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_vt1724_playback_pro_ops);
868 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_vt1724_capture_pro_ops);
869
870 pcm->private_data = ice;
871 pcm->info_flags = 0;
872 strcpy(pcm->name, "ICE1724");
873
874 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100875 snd_dma_pci_data(ice->pci),
876 256*1024, 256*1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
878 ice->pcm_pro = pcm;
879
880 return 0;
881}
882
883
884/*
885 * SPDIF PCM
886 */
887
Takashi Iwai32b47da2007-01-29 15:26:36 +0100888static const struct vt1724_pcm_reg vt1724_playback_spdif_reg = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 .addr = VT1724_MT_PDMA4_ADDR,
890 .size = VT1724_MT_PDMA4_SIZE,
891 .count = VT1724_MT_PDMA4_COUNT,
892 .start = VT1724_PDMA4_START,
893};
894
Takashi Iwai32b47da2007-01-29 15:26:36 +0100895static const struct vt1724_pcm_reg vt1724_capture_spdif_reg = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 .addr = VT1724_MT_RDMA1_ADDR,
897 .size = VT1724_MT_RDMA1_SIZE,
898 .count = VT1724_MT_RDMA1_COUNT,
899 .start = VT1724_RDMA1_START,
900};
901
902/* update spdif control bits; call with reg_lock */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100903static void update_spdif_bits(struct snd_ice1712 *ice, unsigned int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904{
905 unsigned char cbit, disabled;
906
907 cbit = inb(ICEREG1724(ice, SPDIF_CFG));
908 disabled = cbit & ~VT1724_CFG_SPDIF_OUT_EN;
909 if (cbit != disabled)
910 outb(disabled, ICEREG1724(ice, SPDIF_CFG));
911 outw(val, ICEMT1724(ice, SPDIF_CTRL));
912 if (cbit != disabled)
913 outb(cbit, ICEREG1724(ice, SPDIF_CFG));
914 outw(val, ICEMT1724(ice, SPDIF_CTRL));
915}
916
917/* update SPDIF control bits according to the given rate */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100918static void update_spdif_rate(struct snd_ice1712 *ice, unsigned int rate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919{
920 unsigned int val, nval;
921 unsigned long flags;
922
923 spin_lock_irqsave(&ice->reg_lock, flags);
924 nval = val = inw(ICEMT1724(ice, SPDIF_CTRL));
925 nval &= ~(7 << 12);
926 switch (rate) {
927 case 44100: break;
928 case 48000: nval |= 2 << 12; break;
929 case 32000: nval |= 3 << 12; break;
Takashi Iwai2dfbeca2005-10-12 10:04:42 +0200930 case 88200: nval |= 4 << 12; break;
931 case 96000: nval |= 5 << 12; break;
932 case 192000: nval |= 6 << 12; break;
933 case 176400: nval |= 7 << 12; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 }
935 if (val != nval)
936 update_spdif_bits(ice, nval);
937 spin_unlock_irqrestore(&ice->reg_lock, flags);
938}
939
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100940static int snd_vt1724_playback_spdif_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100942 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 if (! ice->force_pdma4)
944 update_spdif_rate(ice, substream->runtime->rate);
945 return snd_vt1724_pcm_prepare(substream);
946}
947
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100948static int snd_vt1724_playback_spdif_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100950 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
951 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Takashi Iwai32b47da2007-01-29 15:26:36 +0100953 runtime->private_data = (void *)&vt1724_playback_spdif_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 ice->playback_con_substream = substream;
955 if (ice->force_pdma4) {
956 runtime->hw = snd_vt1724_2ch_stereo;
957 set_rate_constraints(ice, substream);
958 } else
959 runtime->hw = snd_vt1724_spdif;
960 snd_pcm_set_sync(substream);
961 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
962 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
963 VT1724_BUFFER_ALIGN);
964 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
965 VT1724_BUFFER_ALIGN);
Takashi Iwaic93f5a12008-03-14 17:17:09 +0100966 if (ice->spdif.ops.open)
967 ice->spdif.ops.open(ice, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 return 0;
969}
970
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100971static int snd_vt1724_playback_spdif_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100973 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
975 if (PRO_RATE_RESET)
Pavel Hofmand16be8e2008-03-20 12:10:27 +0100976 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 ice->playback_con_substream = NULL;
Takashi Iwaic93f5a12008-03-14 17:17:09 +0100978 if (ice->spdif.ops.close)
979 ice->spdif.ops.close(ice, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
981 return 0;
982}
983
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100984static int snd_vt1724_capture_spdif_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100986 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
987 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
Takashi Iwai32b47da2007-01-29 15:26:36 +0100989 runtime->private_data = (void *)&vt1724_capture_spdif_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 ice->capture_con_substream = substream;
991 if (ice->force_rdma1) {
992 runtime->hw = snd_vt1724_2ch_stereo;
993 set_rate_constraints(ice, substream);
994 } else
995 runtime->hw = snd_vt1724_spdif;
996 snd_pcm_set_sync(substream);
997 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
998 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
999 VT1724_BUFFER_ALIGN);
1000 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
1001 VT1724_BUFFER_ALIGN);
Takashi Iwaic93f5a12008-03-14 17:17:09 +01001002 if (ice->spdif.ops.open)
1003 ice->spdif.ops.open(ice, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 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)
Pavel Hofmand16be8e2008-03-20 12:10:27 +01001012 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 ice->capture_con_substream = NULL;
Takashi Iwaic93f5a12008-03-14 17:17:09 +01001014 if (ice->spdif.ops.close)
1015 ice->spdif.ops.close(ice, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
1017 return 0;
1018}
1019
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001020static struct snd_pcm_ops snd_vt1724_playback_spdif_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 .open = snd_vt1724_playback_spdif_open,
1022 .close = snd_vt1724_playback_spdif_close,
1023 .ioctl = snd_pcm_lib_ioctl,
1024 .hw_params = snd_vt1724_pcm_hw_params,
1025 .hw_free = snd_vt1724_pcm_hw_free,
1026 .prepare = snd_vt1724_playback_spdif_prepare,
1027 .trigger = snd_vt1724_pcm_trigger,
1028 .pointer = snd_vt1724_pcm_pointer,
1029};
1030
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001031static struct snd_pcm_ops snd_vt1724_capture_spdif_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 .open = snd_vt1724_capture_spdif_open,
1033 .close = snd_vt1724_capture_spdif_close,
1034 .ioctl = snd_pcm_lib_ioctl,
1035 .hw_params = snd_vt1724_pcm_hw_params,
1036 .hw_free = snd_vt1724_pcm_hw_free,
1037 .prepare = snd_vt1724_pcm_prepare,
1038 .trigger = snd_vt1724_pcm_trigger,
1039 .pointer = snd_vt1724_pcm_pointer,
1040};
1041
1042
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001043static int __devinit snd_vt1724_pcm_spdif(struct snd_ice1712 * ice, int device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044{
1045 char *name;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001046 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 int play, capt;
1048 int err;
1049
1050 if (ice->force_pdma4 ||
1051 (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_OUT_INT)) {
1052 play = 1;
1053 ice->has_spdif = 1;
1054 } else
1055 play = 0;
1056 if (ice->force_rdma1 ||
1057 (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_IN)) {
1058 capt = 1;
1059 ice->has_spdif = 1;
1060 } else
1061 capt = 0;
1062 if (! play && ! capt)
1063 return 0; /* no spdif device */
1064
1065 if (ice->force_pdma4 || ice->force_rdma1)
1066 name = "ICE1724 Secondary";
1067 else
1068 name = "IEC1724 IEC958";
1069 err = snd_pcm_new(ice->card, name, device, play, capt, &pcm);
1070 if (err < 0)
1071 return err;
1072
1073 if (play)
1074 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1075 &snd_vt1724_playback_spdif_ops);
1076 if (capt)
1077 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1078 &snd_vt1724_capture_spdif_ops);
1079
1080 pcm->private_data = ice;
1081 pcm->info_flags = 0;
1082 strcpy(pcm->name, name);
1083
1084 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001085 snd_dma_pci_data(ice->pci),
1086 64*1024, 64*1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
1088 ice->pcm = pcm;
1089
1090 return 0;
1091}
1092
1093
1094/*
1095 * independent surround PCMs
1096 */
1097
Takashi Iwai32b47da2007-01-29 15:26:36 +01001098static const struct vt1724_pcm_reg vt1724_playback_dma_regs[3] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 {
1100 .addr = VT1724_MT_PDMA1_ADDR,
1101 .size = VT1724_MT_PDMA1_SIZE,
1102 .count = VT1724_MT_PDMA1_COUNT,
1103 .start = VT1724_PDMA1_START,
1104 },
1105 {
1106 .addr = VT1724_MT_PDMA2_ADDR,
1107 .size = VT1724_MT_PDMA2_SIZE,
1108 .count = VT1724_MT_PDMA2_COUNT,
1109 .start = VT1724_PDMA2_START,
1110 },
1111 {
1112 .addr = VT1724_MT_PDMA3_ADDR,
1113 .size = VT1724_MT_PDMA3_SIZE,
1114 .count = VT1724_MT_PDMA3_COUNT,
1115 .start = VT1724_PDMA3_START,
1116 },
1117};
1118
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001119static int snd_vt1724_playback_indep_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001121 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 unsigned char val;
1123
1124 spin_lock_irq(&ice->reg_lock);
1125 val = 3 - substream->number;
1126 if (inb(ICEMT1724(ice, BURST)) < val)
1127 outb(val, ICEMT1724(ice, BURST));
1128 spin_unlock_irq(&ice->reg_lock);
1129 return snd_vt1724_pcm_prepare(substream);
1130}
1131
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001132static int snd_vt1724_playback_indep_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001134 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1135 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
Ingo Molnar62932df2006-01-16 16:34:20 +01001137 mutex_lock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 /* already used by PDMA0? */
1139 if (ice->pcm_reserved[substream->number]) {
Ingo Molnar62932df2006-01-16 16:34:20 +01001140 mutex_unlock(&ice->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 return -EBUSY; /* FIXME: should handle blocking mode properly */
1142 }
Ingo Molnar62932df2006-01-16 16:34:20 +01001143 mutex_unlock(&ice->open_mutex);
Takashi Iwai32b47da2007-01-29 15:26:36 +01001144 runtime->private_data = (void *)&vt1724_playback_dma_regs[substream->number];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 ice->playback_con_substream_ds[substream->number] = substream;
1146 runtime->hw = snd_vt1724_2ch_stereo;
1147 snd_pcm_set_sync(substream);
1148 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1149 set_rate_constraints(ice, substream);
1150 return 0;
1151}
1152
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001153static int snd_vt1724_playback_indep_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001155 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
1157 if (PRO_RATE_RESET)
Pavel Hofmand16be8e2008-03-20 12:10:27 +01001158 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 ice->playback_con_substream_ds[substream->number] = NULL;
1160 ice->pcm_reserved[substream->number] = NULL;
1161
1162 return 0;
1163}
1164
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001165static struct snd_pcm_ops snd_vt1724_playback_indep_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 .open = snd_vt1724_playback_indep_open,
1167 .close = snd_vt1724_playback_indep_close,
1168 .ioctl = snd_pcm_lib_ioctl,
1169 .hw_params = snd_vt1724_pcm_hw_params,
1170 .hw_free = snd_vt1724_pcm_hw_free,
1171 .prepare = snd_vt1724_playback_indep_prepare,
1172 .trigger = snd_vt1724_pcm_trigger,
1173 .pointer = snd_vt1724_pcm_pointer,
1174};
1175
1176
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001177static int __devinit snd_vt1724_pcm_indep(struct snd_ice1712 * ice, int device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001179 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 int play;
1181 int err;
1182
1183 play = ice->num_total_dacs / 2 - 1;
1184 if (play <= 0)
1185 return 0;
1186
1187 err = snd_pcm_new(ice->card, "ICE1724 Surrounds", device, play, 0, &pcm);
1188 if (err < 0)
1189 return err;
1190
1191 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1192 &snd_vt1724_playback_indep_ops);
1193
1194 pcm->private_data = ice;
1195 pcm->info_flags = 0;
1196 strcpy(pcm->name, "ICE1724 Surround PCM");
1197
1198 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001199 snd_dma_pci_data(ice->pci),
1200 64*1024, 64*1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
1202 ice->pcm_ds = pcm;
1203
1204 return 0;
1205}
1206
1207
1208/*
1209 * Mixer section
1210 */
1211
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001212static int __devinit snd_vt1724_ac97_mixer(struct snd_ice1712 * ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
1214 int err;
1215
1216 if (! (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S)) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001217 struct snd_ac97_bus *pbus;
1218 struct snd_ac97_template ac97;
1219 static struct snd_ac97_bus_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 .write = snd_vt1724_ac97_write,
1221 .read = snd_vt1724_ac97_read,
1222 };
1223
1224 /* cold reset */
1225 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
1226 mdelay(5); /* FIXME */
1227 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
1228
1229 if ((err = snd_ac97_bus(ice->card, 0, &ops, NULL, &pbus)) < 0)
1230 return err;
1231 memset(&ac97, 0, sizeof(ac97));
1232 ac97.private_data = ice;
1233 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
1234 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1235 else
1236 return 0;
1237 }
1238 /* I2S mixer only */
1239 strcat(ice->card->mixername, "ICE1724 - multitrack");
1240 return 0;
1241}
1242
1243/*
1244 *
1245 */
1246
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001247static inline unsigned int eeprom_triple(struct snd_ice1712 *ice, int idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248{
1249 return (unsigned int)ice->eeprom.data[idx] | \
1250 ((unsigned int)ice->eeprom.data[idx + 1] << 8) | \
1251 ((unsigned int)ice->eeprom.data[idx + 2] << 16);
1252}
1253
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001254static void snd_vt1724_proc_read(struct snd_info_entry *entry,
1255 struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001257 struct snd_ice1712 *ice = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 unsigned int idx;
1259
1260 snd_iprintf(buffer, "%s\n\n", ice->card->longname);
1261 snd_iprintf(buffer, "EEPROM:\n");
1262
1263 snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
1264 snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
1265 snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001266 snd_iprintf(buffer, " System Config : 0x%x\n",
1267 ice->eeprom.data[ICE_EEP2_SYSCONF]);
1268 snd_iprintf(buffer, " ACLink : 0x%x\n",
1269 ice->eeprom.data[ICE_EEP2_ACLINK]);
1270 snd_iprintf(buffer, " I2S : 0x%x\n",
1271 ice->eeprom.data[ICE_EEP2_I2S]);
1272 snd_iprintf(buffer, " S/PDIF : 0x%x\n",
1273 ice->eeprom.data[ICE_EEP2_SPDIF]);
1274 snd_iprintf(buffer, " GPIO direction : 0x%x\n",
1275 ice->eeprom.gpiodir);
1276 snd_iprintf(buffer, " GPIO mask : 0x%x\n",
1277 ice->eeprom.gpiomask);
1278 snd_iprintf(buffer, " GPIO state : 0x%x\n",
1279 ice->eeprom.gpiostate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 for (idx = 0x12; idx < ice->eeprom.size; idx++)
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001281 snd_iprintf(buffer, " Extra #%02i : 0x%x\n",
1282 idx, ice->eeprom.data[idx]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
1284 snd_iprintf(buffer, "\nRegisters:\n");
1285
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001286 snd_iprintf(buffer, " PSDOUT03 : 0x%08x\n",
1287 (unsigned)inl(ICEMT1724(ice, ROUTE_PLAYBACK)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 for (idx = 0x0; idx < 0x20 ; idx++)
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001289 snd_iprintf(buffer, " CCS%02x : 0x%02x\n",
1290 idx, inb(ice->port+idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 for (idx = 0x0; idx < 0x30 ; idx++)
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001292 snd_iprintf(buffer, " MT%02x : 0x%02x\n",
1293 idx, inb(ice->profi_port+idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294}
1295
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001296static void __devinit snd_vt1724_proc_init(struct snd_ice1712 * ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001298 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
1300 if (! snd_card_proc_new(ice->card, "ice1724", &entry))
Takashi Iwaibf850202006-04-28 15:13:41 +02001301 snd_info_set_text_ops(entry, ice, snd_vt1724_proc_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302}
1303
1304/*
1305 *
1306 */
1307
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001308static int snd_vt1724_eeprom_info(struct snd_kcontrol *kcontrol,
1309 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310{
1311 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001312 uinfo->count = sizeof(struct snd_ice1712_eeprom);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 return 0;
1314}
1315
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001316static int snd_vt1724_eeprom_get(struct snd_kcontrol *kcontrol,
1317 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001319 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
1321 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1322 return 0;
1323}
1324
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001325static struct snd_kcontrol_new snd_vt1724_eeprom __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1327 .name = "ICE1724 EEPROM",
1328 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1329 .info = snd_vt1724_eeprom_info,
1330 .get = snd_vt1724_eeprom_get
1331};
1332
1333/*
1334 */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001335static int snd_vt1724_spdif_info(struct snd_kcontrol *kcontrol,
1336 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337{
1338 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1339 uinfo->count = 1;
1340 return 0;
1341}
1342
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001343static unsigned int encode_spdif_bits(struct snd_aes_iec958 *diga)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344{
Takashi Iwai2dfbeca2005-10-12 10:04:42 +02001345 unsigned int val, rbits;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
1347 val = diga->status[0] & 0x03; /* professional, non-audio */
1348 if (val & 0x01) {
1349 /* professional */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001350 if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) ==
1351 IEC958_AES0_PRO_EMPHASIS_5015)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 val |= 1U << 3;
Takashi Iwai2dfbeca2005-10-12 10:04:42 +02001353 rbits = (diga->status[4] >> 3) & 0x0f;
1354 if (rbits) {
1355 switch (rbits) {
1356 case 2: val |= 5 << 12; break; /* 96k */
1357 case 3: val |= 6 << 12; break; /* 192k */
1358 case 10: val |= 4 << 12; break; /* 88.2k */
1359 case 11: val |= 7 << 12; break; /* 176.4k */
1360 }
1361 } else {
1362 switch (diga->status[0] & IEC958_AES0_PRO_FS) {
1363 case IEC958_AES0_PRO_FS_44100:
1364 break;
1365 case IEC958_AES0_PRO_FS_32000:
1366 val |= 3U << 12;
1367 break;
1368 default:
1369 val |= 2U << 12;
1370 break;
1371 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 }
1373 } else {
1374 /* consumer */
1375 val |= diga->status[1] & 0x04; /* copyright */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001376 if ((diga->status[0] & IEC958_AES0_CON_EMPHASIS) ==
1377 IEC958_AES0_CON_EMPHASIS_5015)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 val |= 1U << 3;
1379 val |= (unsigned int)(diga->status[1] & 0x3f) << 4; /* category */
1380 val |= (unsigned int)(diga->status[3] & IEC958_AES3_CON_FS) << 12; /* fs */
1381 }
1382 return val;
1383}
1384
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001385static void decode_spdif_bits(struct snd_aes_iec958 *diga, unsigned int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386{
1387 memset(diga->status, 0, sizeof(diga->status));
1388 diga->status[0] = val & 0x03; /* professional, non-audio */
1389 if (val & 0x01) {
1390 /* professional */
1391 if (val & (1U << 3))
1392 diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_5015;
1393 switch ((val >> 12) & 0x7) {
1394 case 0:
1395 break;
1396 case 2:
1397 diga->status[0] |= IEC958_AES0_PRO_FS_32000;
1398 break;
1399 default:
1400 diga->status[0] |= IEC958_AES0_PRO_FS_48000;
1401 break;
1402 }
1403 } else {
1404 /* consumer */
1405 diga->status[0] |= val & (1U << 2); /* copyright */
1406 if (val & (1U << 3))
1407 diga->status[0] |= IEC958_AES0_CON_EMPHASIS_5015;
1408 diga->status[1] |= (val >> 4) & 0x3f; /* category */
1409 diga->status[3] |= (val >> 12) & 0x07; /* fs */
1410 }
1411}
1412
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001413static int snd_vt1724_spdif_default_get(struct snd_kcontrol *kcontrol,
1414 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001416 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 unsigned int val;
1418 val = inw(ICEMT1724(ice, SPDIF_CTRL));
1419 decode_spdif_bits(&ucontrol->value.iec958, val);
1420 return 0;
1421}
1422
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001423static int snd_vt1724_spdif_default_put(struct snd_kcontrol *kcontrol,
1424 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001426 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 unsigned int val, old;
1428
1429 val = encode_spdif_bits(&ucontrol->value.iec958);
1430 spin_lock_irq(&ice->reg_lock);
1431 old = inw(ICEMT1724(ice, SPDIF_CTRL));
1432 if (val != old)
1433 update_spdif_bits(ice, val);
1434 spin_unlock_irq(&ice->reg_lock);
1435 return (val != old);
1436}
1437
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001438static struct snd_kcontrol_new snd_vt1724_spdif_default __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
1440 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1441 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1442 .info = snd_vt1724_spdif_info,
1443 .get = snd_vt1724_spdif_default_get,
1444 .put = snd_vt1724_spdif_default_put
1445};
1446
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001447static int snd_vt1724_spdif_maskc_get(struct snd_kcontrol *kcontrol,
1448 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449{
1450 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1451 IEC958_AES0_PROFESSIONAL |
1452 IEC958_AES0_CON_NOT_COPYRIGHT |
1453 IEC958_AES0_CON_EMPHASIS;
1454 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
1455 IEC958_AES1_CON_CATEGORY;
1456 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
1457 return 0;
1458}
1459
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001460static int snd_vt1724_spdif_maskp_get(struct snd_kcontrol *kcontrol,
1461 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462{
1463 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
1464 IEC958_AES0_PROFESSIONAL |
1465 IEC958_AES0_PRO_FS |
1466 IEC958_AES0_PRO_EMPHASIS;
1467 return 0;
1468}
1469
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001470static struct snd_kcontrol_new snd_vt1724_spdif_maskc __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471{
1472 .access = SNDRV_CTL_ELEM_ACCESS_READ,
Clemens Ladisch67ed4162005-07-29 15:32:58 +02001473 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1475 .info = snd_vt1724_spdif_info,
1476 .get = snd_vt1724_spdif_maskc_get,
1477};
1478
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001479static struct snd_kcontrol_new snd_vt1724_spdif_maskp __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480{
1481 .access = SNDRV_CTL_ELEM_ACCESS_READ,
Clemens Ladisch67ed4162005-07-29 15:32:58 +02001482 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1484 .info = snd_vt1724_spdif_info,
1485 .get = snd_vt1724_spdif_maskp_get,
1486};
1487
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001488#define snd_vt1724_spdif_sw_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001490static int snd_vt1724_spdif_sw_get(struct snd_kcontrol *kcontrol,
1491 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001493 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1494 ucontrol->value.integer.value[0] = inb(ICEREG1724(ice, SPDIF_CFG)) &
1495 VT1724_CFG_SPDIF_OUT_EN ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 return 0;
1497}
1498
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001499static int snd_vt1724_spdif_sw_put(struct snd_kcontrol *kcontrol,
1500 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001502 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 unsigned char old, val;
1504
1505 spin_lock_irq(&ice->reg_lock);
1506 old = val = inb(ICEREG1724(ice, SPDIF_CFG));
1507 val &= ~VT1724_CFG_SPDIF_OUT_EN;
1508 if (ucontrol->value.integer.value[0])
1509 val |= VT1724_CFG_SPDIF_OUT_EN;
1510 if (old != val)
1511 outb(val, ICEREG1724(ice, SPDIF_CFG));
1512 spin_unlock_irq(&ice->reg_lock);
1513 return old != val;
1514}
1515
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001516static struct snd_kcontrol_new snd_vt1724_spdif_switch __devinitdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517{
1518 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1519 /* FIXME: the following conflict with IEC958 Playback Route */
1520 // .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),
Clemens Ladisch10e8d782005-08-03 13:40:08 +02001521 .name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 .info = snd_vt1724_spdif_sw_info,
1523 .get = snd_vt1724_spdif_sw_get,
1524 .put = snd_vt1724_spdif_sw_put
1525};
1526
1527
1528#if 0 /* NOT USED YET */
1529/*
1530 * GPIO access from extern
1531 */
1532
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001533#define snd_vt1724_gpio_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001535int snd_vt1724_gpio_get(struct snd_kcontrol *kcontrol,
1536 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001538 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 int shift = kcontrol->private_value & 0xff;
1540 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1541
1542 snd_ice1712_save_gpio_status(ice);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001543 ucontrol->value.integer.value[0] =
1544 (snd_ice1712_gpio_read(ice) & (1 << shift) ? 1 : 0) ^ invert;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 snd_ice1712_restore_gpio_status(ice);
1546 return 0;
1547}
1548
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001549int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
1550 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001552 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 int shift = kcontrol->private_value & 0xff;
1554 int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
1555 unsigned int val, nval;
1556
1557 if (kcontrol->private_value & (1 << 31))
1558 return -EPERM;
1559 nval = (ucontrol->value.integer.value[0] ? (1 << shift) : 0) ^ invert;
1560 snd_ice1712_save_gpio_status(ice);
1561 val = snd_ice1712_gpio_read(ice);
1562 nval |= val & ~(1 << shift);
1563 if (val != nval)
1564 snd_ice1712_gpio_write(ice, nval);
1565 snd_ice1712_restore_gpio_status(ice);
1566 return val != nval;
1567}
1568#endif /* NOT USED YET */
1569
1570/*
1571 * rate
1572 */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001573static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1574 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001576 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
1578 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1579 uinfo->count = 1;
Pavel Hofmand16be8e2008-03-20 12:10:27 +01001580 uinfo->value.enumerated.items = ice->hw_rates->count + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1582 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Pavel Hofmand16be8e2008-03-20 12:10:27 +01001583 if (uinfo->value.enumerated.item == uinfo->value.enumerated.items - 1)
1584 strcpy(uinfo->value.enumerated.name, "IEC958 Input");
1585 else
1586 sprintf(uinfo->value.enumerated.name, "%d",
1587 ice->hw_rates->list[uinfo->value.enumerated.item]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 return 0;
1589}
1590
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001591static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1592 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001594 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Pavel Hofmand16be8e2008-03-20 12:10:27 +01001595 unsigned int i, rate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
1597 spin_lock_irq(&ice->reg_lock);
Pavel Hofmand16be8e2008-03-20 12:10:27 +01001598 if (ice->is_spdif_master(ice)) {
1599 ucontrol->value.enumerated.item[0] = ice->hw_rates->count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 } else {
Pavel Hofmand16be8e2008-03-20 12:10:27 +01001601 rate = ice->get_rate(ice);
1602 ucontrol->value.enumerated.item[0] = 0;
1603 for (i = 0; i < ice->hw_rates->count; i++) {
1604 if (ice->hw_rates->list[i] == rate) {
1605 ucontrol->value.enumerated.item[0] = i;
1606 break;
1607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 }
1610 spin_unlock_irq(&ice->reg_lock);
1611 return 0;
1612}
1613
Pavel Hofmand16be8e2008-03-20 12:10:27 +01001614/* setting clock to external - SPDIF */
1615static void stdclock_set_spdif_clock(struct snd_ice1712 *ice)
1616{
1617 unsigned char oval;
1618 unsigned char i2s_oval;
1619 oval = inb(ICEMT1724(ice, RATE));
1620 outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
1621 /* setting 256fs */
1622 i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT));
1623 outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X, ICEMT1724(ice, I2S_FORMAT));
1624}
1625
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001626static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1627 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001629 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Pavel Hofmand16be8e2008-03-20 12:10:27 +01001630 unsigned int old_rate, new_rate;
1631 unsigned int item = ucontrol->value.enumerated.item[0];
1632 unsigned int spdif = ice->hw_rates->count;
1633
1634 if (item > spdif)
1635 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
1637 spin_lock_irq(&ice->reg_lock);
Pavel Hofmand16be8e2008-03-20 12:10:27 +01001638 if (ice->is_spdif_master(ice))
1639 old_rate = 0;
1640 else
1641 old_rate = ice->get_rate(ice);
1642 if (item == spdif) {
1643 /* switching to external clock via SPDIF */
1644 ice->set_spdif_clock(ice);
1645 new_rate = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 } else {
Pavel Hofmand16be8e2008-03-20 12:10:27 +01001647 /* internal on-card clock */
1648 new_rate = ice->hw_rates->list[item];
1649 ice->pro_rate_default = new_rate;
1650 spin_unlock_irq(&ice->reg_lock);
1651 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 1);
1652 spin_lock_irq(&ice->reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 spin_unlock_irq(&ice->reg_lock);
1655
Pavel Hofmand16be8e2008-03-20 12:10:27 +01001656 /* the first reset to the SPDIF master mode? */
1657 if (old_rate != new_rate && !new_rate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 /* notify akm chips as well */
Pavel Hofmand16be8e2008-03-20 12:10:27 +01001659 unsigned int i;
1660 if (ice->gpio.set_pro_rate)
1661 ice->gpio.set_pro_rate(ice, 0);
1662 for (i = 0; i < ice->akm_codecs; i++) {
1663 if (ice->akm[i].ops.set_rate_val)
1664 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 }
1666 }
Pavel Hofmand16be8e2008-03-20 12:10:27 +01001667 return old_rate != new_rate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668}
1669
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001670static struct snd_kcontrol_new snd_vt1724_pro_internal_clock __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1672 .name = "Multi Track Internal Clock",
1673 .info = snd_vt1724_pro_internal_clock_info,
1674 .get = snd_vt1724_pro_internal_clock_get,
1675 .put = snd_vt1724_pro_internal_clock_put
1676};
1677
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001678#define snd_vt1724_pro_rate_locking_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001680static int snd_vt1724_pro_rate_locking_get(struct snd_kcontrol *kcontrol,
1681 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682{
1683 ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
1684 return 0;
1685}
1686
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001687static int snd_vt1724_pro_rate_locking_put(struct snd_kcontrol *kcontrol,
1688 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001690 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 int change = 0, nval;
1692
1693 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1694 spin_lock_irq(&ice->reg_lock);
1695 change = PRO_RATE_LOCKED != nval;
1696 PRO_RATE_LOCKED = nval;
1697 spin_unlock_irq(&ice->reg_lock);
1698 return change;
1699}
1700
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001701static struct snd_kcontrol_new snd_vt1724_pro_rate_locking __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1703 .name = "Multi Track Rate Locking",
1704 .info = snd_vt1724_pro_rate_locking_info,
1705 .get = snd_vt1724_pro_rate_locking_get,
1706 .put = snd_vt1724_pro_rate_locking_put
1707};
1708
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001709#define snd_vt1724_pro_rate_reset_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001711static int snd_vt1724_pro_rate_reset_get(struct snd_kcontrol *kcontrol,
1712 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713{
1714 ucontrol->value.integer.value[0] = PRO_RATE_RESET ? 1 : 0;
1715 return 0;
1716}
1717
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001718static int snd_vt1724_pro_rate_reset_put(struct snd_kcontrol *kcontrol,
1719 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001721 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 int change = 0, nval;
1723
1724 nval = ucontrol->value.integer.value[0] ? 1 : 0;
1725 spin_lock_irq(&ice->reg_lock);
1726 change = PRO_RATE_RESET != nval;
1727 PRO_RATE_RESET = nval;
1728 spin_unlock_irq(&ice->reg_lock);
1729 return change;
1730}
1731
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001732static struct snd_kcontrol_new snd_vt1724_pro_rate_reset __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1734 .name = "Multi Track Rate Reset",
1735 .info = snd_vt1724_pro_rate_reset_info,
1736 .get = snd_vt1724_pro_rate_reset_get,
1737 .put = snd_vt1724_pro_rate_reset_put
1738};
1739
1740
1741/*
1742 * routing
1743 */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001744static int snd_vt1724_pro_route_info(struct snd_kcontrol *kcontrol,
1745 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746{
1747 static char *texts[] = {
1748 "PCM Out", /* 0 */
1749 "H/W In 0", "H/W In 1", /* 1-2 */
1750 "IEC958 In L", "IEC958 In R", /* 3-4 */
1751 };
1752
1753 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1754 uinfo->count = 1;
1755 uinfo->value.enumerated.items = 5;
1756 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1757 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1758 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1759 return 0;
1760}
1761
1762static inline int analog_route_shift(int idx)
1763{
1764 return (idx % 2) * 12 + ((idx / 2) * 3) + 8;
1765}
1766
1767static inline int digital_route_shift(int idx)
1768{
1769 return idx * 3;
1770}
1771
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001772static int get_route_val(struct snd_ice1712 *ice, int shift)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773{
1774 unsigned long val;
1775 unsigned char eitem;
Takashi Iwai32b47da2007-01-29 15:26:36 +01001776 static const unsigned char xlate[8] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 0, 255, 1, 2, 255, 255, 3, 4,
1778 };
1779
1780 val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1781 val >>= shift;
1782 val &= 7; //we now have 3 bits per output
1783 eitem = xlate[val];
1784 if (eitem == 255) {
1785 snd_BUG();
1786 return 0;
1787 }
1788 return eitem;
1789}
1790
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001791static int put_route_val(struct snd_ice1712 *ice, unsigned int val, int shift)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792{
1793 unsigned int old_val, nval;
1794 int change;
Takashi Iwai32b47da2007-01-29 15:26:36 +01001795 static const unsigned char xroute[8] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 0, /* PCM */
1797 2, /* PSDIN0 Left */
1798 3, /* PSDIN0 Right */
1799 6, /* SPDIN Left */
1800 7, /* SPDIN Right */
1801 };
1802
1803 nval = xroute[val % 5];
1804 val = old_val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1805 val &= ~(0x07 << shift);
1806 val |= nval << shift;
1807 change = val != old_val;
1808 if (change)
1809 outl(val, ICEMT1724(ice, ROUTE_PLAYBACK));
1810 return change;
1811}
1812
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001813static int snd_vt1724_pro_route_analog_get(struct snd_kcontrol *kcontrol,
1814 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001816 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001818 ucontrol->value.enumerated.item[0] =
1819 get_route_val(ice, analog_route_shift(idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 return 0;
1821}
1822
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001823static int snd_vt1724_pro_route_analog_put(struct snd_kcontrol *kcontrol,
1824 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001826 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1828 return put_route_val(ice, ucontrol->value.enumerated.item[0],
1829 analog_route_shift(idx));
1830}
1831
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001832static int snd_vt1724_pro_route_spdif_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, digital_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_spdif_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 digital_route_shift(idx));
1849}
1850
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001851static struct snd_kcontrol_new snd_vt1724_mixer_pro_analog_route __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1853 .name = "H/W Playback Route",
1854 .info = snd_vt1724_pro_route_info,
1855 .get = snd_vt1724_pro_route_analog_get,
1856 .put = snd_vt1724_pro_route_analog_put,
1857};
1858
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001859static struct snd_kcontrol_new snd_vt1724_mixer_pro_spdif_route __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1861 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
1862 .info = snd_vt1724_pro_route_info,
1863 .get = snd_vt1724_pro_route_spdif_get,
1864 .put = snd_vt1724_pro_route_spdif_put,
1865 .count = 2,
1866};
1867
1868
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001869static int snd_vt1724_pro_peak_info(struct snd_kcontrol *kcontrol,
1870 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871{
1872 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1873 uinfo->count = 22; /* FIXME: for compatibility with ice1712... */
1874 uinfo->value.integer.min = 0;
1875 uinfo->value.integer.max = 255;
1876 return 0;
1877}
1878
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001879static int snd_vt1724_pro_peak_get(struct snd_kcontrol *kcontrol,
1880 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001882 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 int idx;
1884
1885 spin_lock_irq(&ice->reg_lock);
1886 for (idx = 0; idx < 22; idx++) {
1887 outb(idx, ICEMT1724(ice, MONITOR_PEAKINDEX));
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001888 ucontrol->value.integer.value[idx] =
1889 inb(ICEMT1724(ice, MONITOR_PEAKDATA));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 }
1891 spin_unlock_irq(&ice->reg_lock);
1892 return 0;
1893}
1894
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001895static struct snd_kcontrol_new snd_vt1724_mixer_pro_peak __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1897 .name = "Multi Track Peak",
1898 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1899 .info = snd_vt1724_pro_peak_info,
1900 .get = snd_vt1724_pro_peak_get
1901};
1902
1903/*
1904 *
1905 */
1906
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001907static struct snd_ice1712_card_info no_matched __devinitdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001909static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 snd_vt1724_revo_cards,
1911 snd_vt1724_amp_cards,
1912 snd_vt1724_aureon_cards,
1913 snd_vt1720_mobo_cards,
1914 snd_vt1720_pontis_cards,
Julian Scheel6b8d6e52008-01-16 19:50:00 +01001915 snd_vt1724_prodigy_hifi_cards,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 snd_vt1724_prodigy192_cards,
1917 snd_vt1724_juli_cards,
1918 snd_vt1724_phase_cards,
Clement Guedezf6cdab52007-01-08 10:48:41 +01001919 snd_vt1724_wtm_cards,
Shin-ya Okadaf31639b2007-10-23 15:08:18 +02001920 snd_vt1724_se_cards,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 NULL,
1922};
1923
1924
1925/*
1926 */
1927
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001928static void wait_i2c_busy(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929{
1930 int t = 0x10000;
1931 while ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY) && t--)
1932 ;
1933 if (t == -1)
1934 printk(KERN_ERR "ice1724: i2c busy timeout\n");
1935}
1936
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001937unsigned char snd_vt1724_read_i2c(struct snd_ice1712 *ice,
1938 unsigned char dev, unsigned char addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939{
1940 unsigned char val;
1941
Ingo Molnar62932df2006-01-16 16:34:20 +01001942 mutex_lock(&ice->i2c_mutex);
Pavel Hofmanacec30f2007-12-03 12:37:17 +01001943 wait_i2c_busy(ice);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1945 outb(dev & ~VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1946 wait_i2c_busy(ice);
1947 val = inb(ICEREG1724(ice, I2C_DATA));
Ingo Molnar62932df2006-01-16 16:34:20 +01001948 mutex_unlock(&ice->i2c_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 //printk("i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val);
1950 return val;
1951}
1952
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001953void snd_vt1724_write_i2c(struct snd_ice1712 *ice,
1954 unsigned char dev, unsigned char addr, unsigned char data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955{
Ingo Molnar62932df2006-01-16 16:34:20 +01001956 mutex_lock(&ice->i2c_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 wait_i2c_busy(ice);
1958 //printk("i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data);
1959 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
1960 outb(data, ICEREG1724(ice, I2C_DATA));
1961 outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
1962 wait_i2c_busy(ice);
Ingo Molnar62932df2006-01-16 16:34:20 +01001963 mutex_unlock(&ice->i2c_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964}
1965
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001966static int __devinit snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
1967 const char *modelname)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968{
1969 const int dev = 0xa0; /* EEPROM device address */
1970 unsigned int i, size;
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01001971 struct snd_ice1712_card_info * const *tbl, *c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
1973 if (! modelname || ! *modelname) {
1974 ice->eeprom.subvendor = 0;
1975 if ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_EEPROM) != 0)
1976 ice->eeprom.subvendor =
1977 (snd_vt1724_read_i2c(ice, dev, 0x00) << 0) |
1978 (snd_vt1724_read_i2c(ice, dev, 0x01) << 8) |
1979 (snd_vt1724_read_i2c(ice, dev, 0x02) << 16) |
1980 (snd_vt1724_read_i2c(ice, dev, 0x03) << 24);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001981 if (ice->eeprom.subvendor == 0 ||
1982 ice->eeprom.subvendor == (unsigned int)-1) {
1983 /* invalid subvendor from EEPROM, try the PCI
1984 * subststem ID instead
1985 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 u16 vendor, device;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001987 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID,
1988 &vendor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01001990 ice->eeprom.subvendor =
1991 ((unsigned int)swab16(vendor) << 16) | swab16(device);
1992 if (ice->eeprom.subvendor == 0 ||
1993 ice->eeprom.subvendor == (unsigned int)-1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 printk(KERN_ERR "ice1724: No valid ID is found\n");
1995 return -ENXIO;
1996 }
1997 }
1998 }
1999 for (tbl = card_tables; *tbl; tbl++) {
2000 for (c = *tbl; c->subvendor; c++) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002001 if (modelname && c->model &&
2002 ! strcmp(modelname, c->model)) {
2003 printk(KERN_INFO "ice1724: Using board model %s\n",
2004 c->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 ice->eeprom.subvendor = c->subvendor;
2006 } else if (c->subvendor != ice->eeprom.subvendor)
2007 continue;
2008 if (! c->eeprom_size || ! c->eeprom_data)
2009 goto found;
2010 /* if the EEPROM is given by the driver, use it */
2011 snd_printdd("using the defined eeprom..\n");
2012 ice->eeprom.version = 2;
2013 ice->eeprom.size = c->eeprom_size + 6;
2014 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
2015 goto read_skipped;
2016 }
2017 }
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002018 printk(KERN_WARNING "ice1724: No matching model found for ID 0x%x\n",
2019 ice->eeprom.subvendor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020
2021 found:
2022 ice->eeprom.size = snd_vt1724_read_i2c(ice, dev, 0x04);
2023 if (ice->eeprom.size < 6)
2024 ice->eeprom.size = 32;
2025 else if (ice->eeprom.size > 32) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002026 printk(KERN_ERR "ice1724: Invalid EEPROM (size = %i)\n",
2027 ice->eeprom.size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 return -EIO;
2029 }
2030 ice->eeprom.version = snd_vt1724_read_i2c(ice, dev, 0x05);
2031 if (ice->eeprom.version != 2)
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002032 printk(KERN_WARNING "ice1724: Invalid EEPROM version %i\n",
2033 ice->eeprom.version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 size = ice->eeprom.size - 6;
2035 for (i = 0; i < size; i++)
2036 ice->eeprom.data[i] = snd_vt1724_read_i2c(ice, dev, i + 6);
2037
2038 read_skipped:
2039 ice->eeprom.gpiomask = eeprom_triple(ice, ICE_EEP2_GPIO_MASK);
2040 ice->eeprom.gpiostate = eeprom_triple(ice, ICE_EEP2_GPIO_STATE);
2041 ice->eeprom.gpiodir = eeprom_triple(ice, ICE_EEP2_GPIO_DIR);
2042
2043 return 0;
2044}
2045
2046
2047
Karsten Wiese988f0662008-04-22 12:52:15 +02002048static void __devinit snd_vt1724_chip_reset(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049{
2050 outb(VT1724_RESET , ICEREG1724(ice, CONTROL));
Karsten Wiese988f0662008-04-22 12:52:15 +02002051 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 outb(0, ICEREG1724(ice, CONTROL));
Karsten Wiese988f0662008-04-22 12:52:15 +02002053 msleep(10);
2054}
2055
2056static int __devinit snd_vt1724_chip_init(struct snd_ice1712 *ice)
2057{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG));
2059 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG));
2060 outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES));
2061 outb(ice->eeprom.data[ICE_EEP2_SPDIF], ICEREG1724(ice, SPDIF_CFG));
2062
2063 ice->gpio.write_mask = ice->eeprom.gpiomask;
2064 ice->gpio.direction = ice->eeprom.gpiodir;
2065 snd_vt1724_set_gpio_mask(ice, ice->eeprom.gpiomask);
2066 snd_vt1724_set_gpio_dir(ice, ice->eeprom.gpiodir);
2067 snd_vt1724_set_gpio_data(ice, ice->eeprom.gpiostate);
2068
2069 outb(0, ICEREG1724(ice, POWERDOWN));
2070
2071 return 0;
2072}
2073
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002074static int __devinit snd_vt1724_spdif_build_controls(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075{
2076 int err;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002077 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078
2079 snd_assert(ice->pcm != NULL, return -EIO);
2080
2081 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice));
2082 if (err < 0)
2083 return err;
2084
2085 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_spdif_switch, ice));
2086 if (err < 0)
2087 return err;
2088
2089 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_default, ice));
2090 if (err < 0)
2091 return err;
2092 kctl->id.device = ice->pcm->device;
2093 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskc, ice));
2094 if (err < 0)
2095 return err;
2096 kctl->id.device = ice->pcm->device;
2097 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskp, ice));
2098 if (err < 0)
2099 return err;
2100 kctl->id.device = ice->pcm->device;
2101#if 0 /* use default only */
2102 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_stream, ice));
2103 if (err < 0)
2104 return err;
2105 kctl->id.device = ice->pcm->device;
2106 ice->spdif.stream_ctl = kctl;
2107#endif
2108 return 0;
2109}
2110
2111
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002112static int __devinit snd_vt1724_build_controls(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
2114 int err;
2115
2116 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_eeprom, ice));
2117 if (err < 0)
2118 return err;
2119 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_internal_clock, ice));
2120 if (err < 0)
2121 return err;
2122
2123 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_locking, ice));
2124 if (err < 0)
2125 return err;
2126 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_reset, ice));
2127 if (err < 0)
2128 return err;
2129
2130 if (ice->num_total_dacs > 0) {
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002131 struct snd_kcontrol_new tmp = snd_vt1724_mixer_pro_analog_route;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 tmp.count = ice->num_total_dacs;
2133 if (ice->vt1720 && tmp.count > 2)
2134 tmp.count = 2;
2135 err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
2136 if (err < 0)
2137 return err;
2138 }
2139
2140 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_peak, ice));
2141 if (err < 0)
2142 return err;
2143
2144 return 0;
2145}
2146
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002147static int snd_vt1724_free(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148{
2149 if (! ice->port)
2150 goto __hw_end;
2151 /* mask all interrupts */
2152 outb(0xff, ICEMT1724(ice, DMA_INT_MASK));
2153 outb(0xff, ICEREG1724(ice, IRQMASK));
2154 /* --- */
2155 __hw_end:
2156 if (ice->irq >= 0) {
2157 synchronize_irq(ice->irq);
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002158 free_irq(ice->irq, ice);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 }
2160 pci_release_regions(ice->pci);
2161 snd_ice1712_akm4xxx_free(ice);
2162 pci_disable_device(ice->pci);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +01002163 kfree(ice->spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 kfree(ice);
2165 return 0;
2166}
2167
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002168static int snd_vt1724_dev_free(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002170 struct snd_ice1712 *ice = device->device_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 return snd_vt1724_free(ice);
2172}
2173
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002174static int __devinit snd_vt1724_create(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 struct pci_dev *pci,
2176 const char *modelname,
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002177 struct snd_ice1712 ** r_ice1712)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002179 struct snd_ice1712 *ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 int err;
2181 unsigned char mask;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002182 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 .dev_free = snd_vt1724_dev_free,
2184 };
2185
2186 *r_ice1712 = NULL;
2187
2188 /* enable PCI device */
2189 if ((err = pci_enable_device(pci)) < 0)
2190 return err;
2191
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002192 ice = kzalloc(sizeof(*ice), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 if (ice == NULL) {
2194 pci_disable_device(pci);
2195 return -ENOMEM;
2196 }
2197 ice->vt1724 = 1;
2198 spin_lock_init(&ice->reg_lock);
Ingo Molnar62932df2006-01-16 16:34:20 +01002199 mutex_init(&ice->gpio_mutex);
2200 mutex_init(&ice->open_mutex);
2201 mutex_init(&ice->i2c_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 ice->gpio.set_mask = snd_vt1724_set_gpio_mask;
2203 ice->gpio.set_dir = snd_vt1724_set_gpio_dir;
2204 ice->gpio.set_data = snd_vt1724_set_gpio_data;
2205 ice->gpio.get_data = snd_vt1724_get_gpio_data;
2206 ice->card = card;
2207 ice->pci = pci;
2208 ice->irq = -1;
2209 pci_set_master(pci);
2210 snd_vt1724_proc_init(ice);
2211 synchronize_irq(pci->irq);
2212
2213 if ((err = pci_request_regions(pci, "ICE1724")) < 0) {
2214 kfree(ice);
2215 pci_disable_device(pci);
2216 return err;
2217 }
2218 ice->port = pci_resource_start(pci, 0);
2219 ice->profi_port = pci_resource_start(pci, 1);
2220
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002221 if (request_irq(pci->irq, snd_vt1724_interrupt,
Takashi Iwai437a5a42006-11-21 12:14:23 +01002222 IRQF_SHARED, "ICE1724", ice)) {
Takashi Iwai99b359b2005-10-20 18:26:44 +02002223 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 snd_vt1724_free(ice);
2225 return -EIO;
2226 }
2227
2228 ice->irq = pci->irq;
2229
Karsten Wiese988f0662008-04-22 12:52:15 +02002230 snd_vt1724_chip_reset(ice);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 if (snd_vt1724_read_eeprom(ice, modelname) < 0) {
2232 snd_vt1724_free(ice);
2233 return -EIO;
2234 }
2235 if (snd_vt1724_chip_init(ice) < 0) {
2236 snd_vt1724_free(ice);
2237 return -EIO;
2238 }
2239
2240 /* unmask used interrupts */
2241 if (! (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401))
2242 mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
2243 else
2244 mask = 0;
2245 outb(mask, ICEREG1724(ice, IRQMASK));
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002246 /* don't handle FIFO overrun/underruns (just yet),
2247 * since they cause machine lockups
2248 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK));
2250
2251 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
2252 snd_vt1724_free(ice);
2253 return err;
2254 }
2255
2256 snd_card_set_dev(card, &pci->dev);
2257
2258 *r_ice1712 = ice;
2259 return 0;
2260}
2261
2262
2263/*
2264 *
2265 * Registration
2266 *
2267 */
2268
2269static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2270 const struct pci_device_id *pci_id)
2271{
2272 static int dev;
Takashi Iwaiab0c7d72005-11-17 15:00:18 +01002273 struct snd_card *card;
2274 struct snd_ice1712 *ice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 int pcm_dev = 0, err;
Takashi Iwai1b60f6b2007-03-13 22:13:47 +01002276 struct snd_ice1712_card_info * const *tbl, *c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277
2278 if (dev >= SNDRV_CARDS)
2279 return -ENODEV;
2280 if (!enable[dev]) {
2281 dev++;
2282 return -ENOENT;
2283 }
2284
2285 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2286 if (card == NULL)
2287 return -ENOMEM;
2288
2289 strcpy(card->driver, "ICE1724");
2290 strcpy(card->shortname, "ICEnsemble ICE1724");
2291
2292 if ((err = snd_vt1724_create(card, pci, model[dev], &ice)) < 0) {
2293 snd_card_free(card);
2294 return err;
2295 }
2296
2297 for (tbl = card_tables; *tbl; tbl++) {
2298 for (c = *tbl; c->subvendor; c++) {
2299 if (c->subvendor == ice->eeprom.subvendor) {
2300 strcpy(card->shortname, c->name);
2301 if (c->driver) /* specific driver? */
2302 strcpy(card->driver, c->driver);
2303 if (c->chip_init) {
2304 if ((err = c->chip_init(ice)) < 0) {
2305 snd_card_free(card);
2306 return err;
2307 }
2308 }
2309 goto __found;
2310 }
2311 }
2312 }
2313 c = &no_matched;
2314 __found:
Takashi Iwaif06934b2007-04-10 11:15:34 +02002315 /*
2316 * VT1724 has separate DMAs for the analog and the SPDIF streams while
2317 * ICE1712 has only one for both (mixed up).
2318 *
2319 * Confusingly the analog PCM is named "professional" here because it
2320 * was called so in ice1712 driver, and vt1724 driver is derived from
2321 * ice1712 driver.
2322 */
Pavel Hofmand16be8e2008-03-20 12:10:27 +01002323 ice->pro_rate_default = PRO_RATE_DEFAULT;
2324 if (!ice->is_spdif_master)
2325 ice->is_spdif_master = stdclock_is_spdif_master;
2326 if (!ice->get_rate)
2327 ice->get_rate = stdclock_get_rate;
2328 if (!ice->set_rate)
2329 ice->set_rate = stdclock_set_rate;
2330 if (!ice->set_mclk)
2331 ice->set_mclk = stdclock_set_mclk;
2332 if (!ice->set_spdif_clock)
2333 ice->set_spdif_clock = stdclock_set_spdif_clock;
2334 if (!ice->hw_rates)
2335 set_std_hw_rates(ice);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336
2337 if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) {
2338 snd_card_free(card);
2339 return err;
2340 }
2341
2342 if ((err = snd_vt1724_pcm_spdif(ice, pcm_dev++)) < 0) {
2343 snd_card_free(card);
2344 return err;
2345 }
2346
2347 if ((err = snd_vt1724_pcm_indep(ice, pcm_dev++)) < 0) {
2348 snd_card_free(card);
2349 return err;
2350 }
2351
2352 if ((err = snd_vt1724_ac97_mixer(ice)) < 0) {
2353 snd_card_free(card);
2354 return err;
2355 }
2356
2357 if ((err = snd_vt1724_build_controls(ice)) < 0) {
2358 snd_card_free(card);
2359 return err;
2360 }
2361
2362 if (ice->pcm && ice->has_spdif) { /* has SPDIF I/O */
2363 if ((err = snd_vt1724_spdif_build_controls(ice)) < 0) {
2364 snd_card_free(card);
2365 return err;
2366 }
2367 }
2368
2369 if (c->build_controls) {
2370 if ((err = c->build_controls(ice)) < 0) {
2371 snd_card_free(card);
2372 return err;
2373 }
2374 }
2375
2376 if (! c->no_mpu401) {
2377 if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) {
2378 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
Takashi Iwai302e4c22006-05-23 13:24:30 +02002379 ICEREG1724(ice, MPU_CTRL),
2380 MPU401_INFO_INTEGRATED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 ice->irq, 0,
2382 &ice->rmidi[0])) < 0) {
2383 snd_card_free(card);
2384 return err;
2385 }
2386 }
2387 }
2388
2389 sprintf(card->longname, "%s at 0x%lx, irq %i",
2390 card->shortname, ice->port, ice->irq);
2391
2392 if ((err = snd_card_register(card)) < 0) {
2393 snd_card_free(card);
2394 return err;
2395 }
2396 pci_set_drvdata(pci, card);
2397 dev++;
2398 return 0;
2399}
2400
2401static void __devexit snd_vt1724_remove(struct pci_dev *pci)
2402{
2403 snd_card_free(pci_get_drvdata(pci));
2404 pci_set_drvdata(pci, NULL);
2405}
2406
2407static struct pci_driver driver = {
2408 .name = "ICE1724",
2409 .id_table = snd_vt1724_ids,
2410 .probe = snd_vt1724_probe,
2411 .remove = __devexit_p(snd_vt1724_remove),
2412};
2413
2414static int __init alsa_card_ice1724_init(void)
2415{
Takashi Iwai01d25d42005-04-11 16:58:24 +02002416 return pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417}
2418
2419static void __exit alsa_card_ice1724_exit(void)
2420{
2421 pci_unregister_driver(&driver);
2422}
2423
2424module_init(alsa_card_ice1724_init)
2425module_exit(alsa_card_ice1724_exit)