blob: 70d0040484c89c7e2bd0d15303a917c71154b729 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Driver for AMD InterWave soundcard
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02003 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * 1999/07/22 Erik Inge Bolso <knan@mo.himolde.no>
21 * * mixer group handlers
22 *
23 */
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/init.h>
Takashi Iwai654aa662005-11-17 17:13:43 +010026#include <linux/err.h>
Takashi Iwai5e24c1c2007-02-22 12:50:54 +010027#include <linux/isa.h>
Takashi Iwai654aa662005-11-17 17:13:43 +010028#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/pnp.h>
Paul Gortmaker65a77212011-07-15 13:13:37 -040030#include <linux/module.h>
Takashi Iwai654aa662005-11-17 17:13:43 +010031#include <asm/dma.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <sound/core.h>
33#include <sound/gus.h>
Krzysztof Helt61ef19d2008-07-31 21:02:42 +020034#include <sound/wss.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#ifdef SNDRV_STB
36#include <sound/tea6330t.h>
37#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#define SNDRV_LEGACY_FIND_FREE_IRQ
39#define SNDRV_LEGACY_FIND_FREE_DMA
40#include <sound/initval.h>
41
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020042MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070043MODULE_LICENSE("GPL");
44#ifndef SNDRV_STB
45MODULE_DESCRIPTION("AMD InterWave");
46MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Plug & Play},"
47 "{STB,SoundRage32},"
48 "{MED,MED3210},"
49 "{Dynasonix,Dynasonix Pro},"
50 "{Panasonic,PCA761AW}}");
51#else
52MODULE_DESCRIPTION("AMD InterWave STB with TEA6330T");
53MODULE_SUPPORTED_DEVICE("{{AMD,InterWave STB with TEA6330T}}");
54#endif
55
56static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
57static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
Rusty Russella67ff6a2011-12-15 13:49:36 +103058static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#ifdef CONFIG_PNP
Rusty Russella67ff6a2011-12-15 13:49:36 +103060static bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#endif
62static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x210,0x220,0x230,0x240,0x250,0x260 */
63#ifdef SNDRV_STB
64static long port_tc[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x350,0x360,0x370,0x380 */
65#endif
66static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 2,3,5,9,11,12,15 */
67static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
68static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
69static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
70 /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
Takashi Iwai6581f4e2006-05-17 17:14:51 +020071static int midi[SNDRV_CARDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070072static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
Takashi Iwai6581f4e2006-05-17 17:14:51 +020073static int effect[SNDRV_CARDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Takashi Iwai43bcd972005-09-05 17:19:20 +020075#ifdef SNDRV_STB
76#define PFX "interwave-stb: "
Takashi Iwai654aa662005-11-17 17:13:43 +010077#define INTERWAVE_DRIVER "snd_interwave_stb"
78#define INTERWAVE_PNP_DRIVER "interwave-stb"
Takashi Iwai43bcd972005-09-05 17:19:20 +020079#else
80#define PFX "interwave: "
Takashi Iwai654aa662005-11-17 17:13:43 +010081#define INTERWAVE_DRIVER "snd_interwave"
82#define INTERWAVE_PNP_DRIVER "interwave"
Takashi Iwai43bcd972005-09-05 17:19:20 +020083#endif
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085module_param_array(index, int, NULL, 0444);
86MODULE_PARM_DESC(index, "Index value for InterWave soundcard.");
87module_param_array(id, charp, NULL, 0444);
88MODULE_PARM_DESC(id, "ID string for InterWave soundcard.");
89module_param_array(enable, bool, NULL, 0444);
90MODULE_PARM_DESC(enable, "Enable InterWave soundcard.");
91#ifdef CONFIG_PNP
92module_param_array(isapnp, bool, NULL, 0444);
93MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
94#endif
95module_param_array(port, long, NULL, 0444);
96MODULE_PARM_DESC(port, "Port # for InterWave driver.");
97#ifdef SNDRV_STB
98module_param_array(port_tc, long, NULL, 0444);
99MODULE_PARM_DESC(port_tc, "Tone control (TEA6330T - i2c bus) port # for InterWave driver.");
100#endif
101module_param_array(irq, int, NULL, 0444);
102MODULE_PARM_DESC(irq, "IRQ # for InterWave driver.");
103module_param_array(dma1, int, NULL, 0444);
104MODULE_PARM_DESC(dma1, "DMA1 # for InterWave driver.");
105module_param_array(dma2, int, NULL, 0444);
106MODULE_PARM_DESC(dma2, "DMA2 # for InterWave driver.");
107module_param_array(joystick_dac, int, NULL, 0444);
108MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for InterWave driver.");
109module_param_array(midi, int, NULL, 0444);
110MODULE_PARM_DESC(midi, "MIDI UART enable for InterWave driver.");
111module_param_array(pcm_channels, int, NULL, 0444);
112MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for InterWave driver.");
113module_param_array(effect, int, NULL, 0444);
114MODULE_PARM_DESC(effect, "Effects enable for InterWave driver.");
115
116struct snd_interwave {
117 int irq;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100118 struct snd_card *card;
119 struct snd_gus_card *gus;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200120 struct snd_wss *wss;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121#ifdef SNDRV_STB
122 struct resource *i2c_res;
123#endif
124 unsigned short gus_status_reg;
125 unsigned short pcm_status_reg;
126#ifdef CONFIG_PNP
127 struct pnp_dev *dev;
128#ifdef SNDRV_STB
129 struct pnp_dev *devtc;
130#endif
131#endif
132};
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135#ifdef CONFIG_PNP
Rene Herman609d7692007-05-15 11:42:56 +0200136static int isa_registered;
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100137static int pnp_registered;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139static struct pnp_card_device_id snd_interwave_pnpids[] = {
140#ifndef SNDRV_STB
141 /* Gravis UltraSound Plug & Play */
142 { .id = "GRV0001", .devs = { { .id = "GRV0000" } } },
143 /* STB SoundRage32 */
144 { .id = "STB011a", .devs = { { .id = "STB0010" } } },
145 /* MED3210 */
146 { .id = "DXP3201", .devs = { { .id = "DXP0010" } } },
147 /* Dynasonic Pro */
148 /* This device also have CDC1117:DynaSonix Pro Audio Effects Processor */
149 { .id = "CDC1111", .devs = { { .id = "CDC1112" } } },
150 /* Panasonic PCA761AW Audio Card */
151 { .id = "ADV55ff", .devs = { { .id = "ADV0010" } } },
152 /* InterWave STB without TEA6330T */
153 { .id = "ADV550a", .devs = { { .id = "ADV0010" } } },
154#else
155 /* InterWave STB with TEA6330T */
156 { .id = "ADV550a", .devs = { { .id = "ADV0010" }, { .id = "ADV0015" } } },
157#endif
158 { .id = "" }
159};
160
161MODULE_DEVICE_TABLE(pnp_card, snd_interwave_pnpids);
162
163#endif /* CONFIG_PNP */
164
165
166#ifdef SNDRV_STB
Takashi Iwai5e2da202005-11-17 14:36:44 +0100167static void snd_interwave_i2c_setlines(struct snd_i2c_bus *bus, int ctrl, int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
169 unsigned long port = bus->private_value;
170
171#if 0
Takashi Iwai91f05062009-02-05 15:46:48 +0100172 printk(KERN_DEBUG "i2c_setlines - 0x%lx <- %i,%i\n", port, ctrl, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173#endif
174 outb((data << 1) | ctrl, port);
175 udelay(10);
176}
177
Takashi Iwai5e2da202005-11-17 14:36:44 +0100178static int snd_interwave_i2c_getclockline(struct snd_i2c_bus *bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
180 unsigned long port = bus->private_value;
181 unsigned char res;
182
183 res = inb(port) & 1;
184#if 0
Takashi Iwai91f05062009-02-05 15:46:48 +0100185 printk(KERN_DEBUG "i2c_getclockline - 0x%lx -> %i\n", port, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186#endif
187 return res;
188}
189
Takashi Iwai5e2da202005-11-17 14:36:44 +0100190static int snd_interwave_i2c_getdataline(struct snd_i2c_bus *bus, int ack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
192 unsigned long port = bus->private_value;
193 unsigned char res;
194
195 if (ack)
196 udelay(10);
197 res = (inb(port) & 2) >> 1;
198#if 0
Takashi Iwai91f05062009-02-05 15:46:48 +0100199 printk(KERN_DEBUG "i2c_getdataline - 0x%lx -> %i\n", port, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#endif
201 return res;
202}
203
Takashi Iwai5e2da202005-11-17 14:36:44 +0100204static struct snd_i2c_bit_ops snd_interwave_i2c_bit_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 .setlines = snd_interwave_i2c_setlines,
206 .getclock = snd_interwave_i2c_getclockline,
207 .getdata = snd_interwave_i2c_getdataline,
208};
209
Bill Pemberton1bff2922012-12-06 12:35:21 -0500210static int snd_interwave_detect_stb(struct snd_interwave *iwcard,
211 struct snd_gus_card *gus, int dev,
212 struct snd_i2c_bus **rbus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
214 unsigned long port;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100215 struct snd_i2c_bus *bus;
216 struct snd_card *card = iwcard->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 char name[32];
218 int err;
219
220 *rbus = NULL;
221 port = port_tc[dev];
222 if (port == SNDRV_AUTO_PORT) {
223 port = 0x350;
224 if (gus->gf1.port == 0x250) {
225 port = 0x360;
226 }
227 while (port <= 0x380) {
228 if ((iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)")) != NULL)
229 break;
230 port += 0x10;
231 }
232 } else {
233 iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)");
234 }
235 if (iwcard->i2c_res == NULL) {
236 snd_printk(KERN_ERR "interwave: can't grab i2c bus port\n");
237 return -ENODEV;
238 }
239
240 sprintf(name, "InterWave-%i", card->number);
241 if ((err = snd_i2c_bus_create(card, name, NULL, &bus)) < 0)
242 return err;
243 bus->private_value = port;
244 bus->hw_ops.bit = &snd_interwave_i2c_bit_ops;
245 if ((err = snd_tea6330t_detect(bus, 0)) < 0)
246 return err;
247 *rbus = bus;
248 return 0;
249}
250#endif
251
Bill Pemberton1bff2922012-12-06 12:35:21 -0500252static int snd_interwave_detect(struct snd_interwave *iwcard,
253 struct snd_gus_card *gus,
254 int dev
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255#ifdef SNDRV_STB
Bill Pemberton1bff2922012-12-06 12:35:21 -0500256 , struct snd_i2c_bus **rbus
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#endif
258 )
259{
260 unsigned long flags;
261 unsigned char rev1, rev2;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200262 int d;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
Takashi Iwai43bcd972005-09-05 17:19:20 +0200265 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
266 snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 return -ENODEV;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200268 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 udelay(160);
270 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
271 udelay(160);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200272 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
273 snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 return -ENODEV;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200275 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 spin_lock_irqsave(&gus->reg_lock, flags);
277 rev1 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER);
278 snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, ~rev1);
279 rev2 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER);
280 snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, rev1);
281 spin_unlock_irqrestore(&gus->reg_lock, flags);
282 snd_printdd("[0x%lx] InterWave check - rev1=0x%x, rev2=0x%x\n", gus->gf1.port, rev1, rev2);
283 if ((rev1 & 0xf0) == (rev2 & 0xf0) &&
284 (rev1 & 0x0f) != (rev2 & 0x0f)) {
285 snd_printdd("[0x%lx] InterWave check - passed\n", gus->gf1.port);
286 gus->interwave = 1;
287 strcpy(gus->card->shortname, "AMD InterWave");
288 gus->revision = rev1 >> 4;
289#ifndef SNDRV_STB
290 return 0; /* ok.. We have an InterWave board */
291#else
292 return snd_interwave_detect_stb(iwcard, gus, dev, rbus);
293#endif
294 }
295 snd_printdd("[0x%lx] InterWave check - failed\n", gus->gf1.port);
296 return -ENODEV;
297}
298
David Howells7d12e782006-10-05 14:55:46 +0100299static irqreturn_t snd_interwave_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400301 struct snd_interwave *iwcard = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 int loop, max = 5;
303 int handled = 0;
304
305 do {
306 loop = 0;
307 if (inb(iwcard->gus_status_reg)) {
308 handled = 1;
David Howells7d12e782006-10-05 14:55:46 +0100309 snd_gus_interrupt(irq, iwcard->gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 loop++;
311 }
312 if (inb(iwcard->pcm_status_reg) & 0x01) { /* IRQ bit is set? */
313 handled = 1;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200314 snd_wss_interrupt(irq, iwcard->wss);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 loop++;
316 }
317 } while (loop && --max > 0);
318 return IRQ_RETVAL(handled);
319}
320
Bill Pemberton1bff2922012-12-06 12:35:21 -0500321static void snd_interwave_reset(struct snd_gus_card *gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
323 snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x00);
324 udelay(160);
325 snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x01);
326 udelay(160);
327}
328
Bill Pemberton1bff2922012-12-06 12:35:21 -0500329static void snd_interwave_bank_sizes(struct snd_gus_card *gus, int *sizes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330{
331 unsigned int idx;
332 unsigned int local;
333 unsigned char d;
334
335 for (idx = 0; idx < 4; idx++) {
336 sizes[idx] = 0;
337 d = 0x55;
338 for (local = idx << 22;
339 local < (idx << 22) + 0x400000;
340 local += 0x40000, d++) {
341 snd_gf1_poke(gus, local, d);
342 snd_gf1_poke(gus, local + 1, d + 1);
343#if 0
Takashi Iwai91f05062009-02-05 15:46:48 +0100344 printk(KERN_DEBUG "d = 0x%x, local = 0x%x, "
345 "local + 1 = 0x%x, idx << 22 = 0x%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 d,
347 snd_gf1_peek(gus, local),
348 snd_gf1_peek(gus, local + 1),
349 snd_gf1_peek(gus, idx << 22));
350#endif
351 if (snd_gf1_peek(gus, local) != d ||
352 snd_gf1_peek(gus, local + 1) != d + 1 ||
353 snd_gf1_peek(gus, idx << 22) != 0x55)
354 break;
355 sizes[idx]++;
356 }
357 }
358#if 0
Takashi Iwai91f05062009-02-05 15:46:48 +0100359 printk(KERN_DEBUG "sizes: %i %i %i %i\n",
360 sizes[0], sizes[1], sizes[2], sizes[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361#endif
362}
363
364struct rom_hdr {
365 /* 000 */ unsigned char iwave[8];
366 /* 008 */ unsigned char rom_hdr_revision;
367 /* 009 */ unsigned char series_number;
368 /* 010 */ unsigned char series_name[16];
369 /* 026 */ unsigned char date[10];
370 /* 036 */ unsigned short vendor_revision_major;
371 /* 038 */ unsigned short vendor_revision_minor;
372 /* 040 */ unsigned int rom_size;
373 /* 044 */ unsigned char copyright[128];
374 /* 172 */ unsigned char vendor_name[64];
375 /* 236 */ unsigned char rom_description[128];
376 /* 364 */ unsigned char pad[147];
377 /* 511 */ unsigned char csum;
378};
379
Bill Pemberton1bff2922012-12-06 12:35:21 -0500380static void snd_interwave_detect_memory(struct snd_gus_card *gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
382 static unsigned int lmc[13] =
383 {
384 0x00000001, 0x00000101, 0x01010101, 0x00000401,
385 0x04040401, 0x00040101, 0x04040101, 0x00000004,
386 0x00000404, 0x04040404, 0x00000010, 0x00001010,
387 0x10101010
388 };
389
390 int bank_pos, pages;
391 unsigned int i, lmct;
392 int psizes[4];
393 unsigned char iwave[8];
394 unsigned char csum;
395
396 snd_interwave_reset(gus);
397 snd_gf1_write8(gus, SNDRV_GF1_GB_GLOBAL_MODE, snd_gf1_read8(gus, SNDRV_GF1_GB_GLOBAL_MODE) | 0x01); /* enhanced mode */
398 snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01); /* DRAM I/O cycles selected */
399 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xff10) | 0x004c);
400 /* ok.. simple test of memory size */
401 pages = 0;
402 snd_gf1_poke(gus, 0, 0x55);
403 snd_gf1_poke(gus, 1, 0xaa);
404#if 1
405 if (snd_gf1_peek(gus, 0) == 0x55 && snd_gf1_peek(gus, 1) == 0xaa)
406#else
407 if (0) /* ok.. for testing of 0k RAM */
408#endif
409 {
410 snd_interwave_bank_sizes(gus, psizes);
411 lmct = (psizes[3] << 24) | (psizes[2] << 16) |
412 (psizes[1] << 8) | psizes[0];
413#if 0
Takashi Iwai91f05062009-02-05 15:46:48 +0100414 printk(KERN_DEBUG "lmct = 0x%08x\n", lmct);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415#endif
416 for (i = 0; i < ARRAY_SIZE(lmc); i++)
417 if (lmct == lmc[i]) {
418#if 0
Takashi Iwai91f05062009-02-05 15:46:48 +0100419 printk(KERN_DEBUG "found !!! %i\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420#endif
421 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | i);
422 snd_interwave_bank_sizes(gus, psizes);
423 break;
424 }
425 if (i >= ARRAY_SIZE(lmc) && !gus->gf1.enh_mode)
426 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | 2);
427 for (i = 0; i < 4; i++) {
428 gus->gf1.mem_alloc.banks_8[i].address =
429 gus->gf1.mem_alloc.banks_16[i].address = i << 22;
430 gus->gf1.mem_alloc.banks_8[i].size =
431 gus->gf1.mem_alloc.banks_16[i].size = psizes[i] << 18;
432 pages += psizes[i];
433 }
434 }
435 pages <<= 18;
436 gus->gf1.memory = pages;
437
438 snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x03); /* select ROM */
439 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xff1f) | (4 << 5));
440 gus->gf1.rom_banks = 0;
441 gus->gf1.rom_memory = 0;
442 for (bank_pos = 0; bank_pos < 16L * 1024L * 1024L; bank_pos += 4L * 1024L * 1024L) {
443 for (i = 0; i < 8; ++i)
444 iwave[i] = snd_gf1_peek(gus, bank_pos + i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 if (strncmp(iwave, "INTRWAVE", 8))
446 continue; /* first check */
447 csum = 0;
448 for (i = 0; i < sizeof(struct rom_hdr); i++)
449 csum += snd_gf1_peek(gus, bank_pos + i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 if (csum != 0)
451 continue; /* not valid rom */
452 gus->gf1.rom_banks++;
453 gus->gf1.rom_present |= 1 << (bank_pos >> 22);
454 gus->gf1.rom_memory = snd_gf1_peek(gus, bank_pos + 40) |
455 (snd_gf1_peek(gus, bank_pos + 41) << 8) |
456 (snd_gf1_peek(gus, bank_pos + 42) << 16) |
457 (snd_gf1_peek(gus, bank_pos + 43) << 24);
458 }
459#if 0
460 if (gus->gf1.rom_memory > 0) {
461 if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8)
462 gus->card->type = SNDRV_CARD_TYPE_IW_DYNASONIC;
463 }
464#endif
465 snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x00); /* select RAM */
466
467 if (!gus->gf1.enh_mode)
468 snd_interwave_reset(gus);
469}
470
Bill Pemberton1bff2922012-12-06 12:35:21 -0500471static void snd_interwave_init(int dev, struct snd_gus_card *gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
473 unsigned long flags;
474
475 /* ok.. some InterWave specific initialization */
476 spin_lock_irqsave(&gus->reg_lock, flags);
477 snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, 0x00);
478 snd_gf1_write8(gus, SNDRV_GF1_GB_COMPATIBILITY, 0x1f);
479 snd_gf1_write8(gus, SNDRV_GF1_GB_DECODE_CONTROL, 0x49);
480 snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, 0x11);
481 snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_A, 0x00);
482 snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_B, 0x30);
483 snd_gf1_write8(gus, SNDRV_GF1_GB_EMULATION_IRQ, 0x00);
484 spin_unlock_irqrestore(&gus->reg_lock, flags);
485 gus->equal_irq = 1;
486 gus->codec_flag = 1;
487 gus->interwave = 1;
488 gus->max_flag = 1;
489 gus->joystick_dac = joystick_dac[dev];
490
491}
492
Takashi Iwai5e2da202005-11-17 14:36:44 +0100493static struct snd_kcontrol_new snd_interwave_controls[] = {
Krzysztof Helt7779f752008-07-31 21:03:41 +0200494WSS_DOUBLE("Master Playback Switch", 0,
495 CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 7, 7, 1, 1),
496WSS_DOUBLE("Master Playback Volume", 0,
497 CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 0, 0, 31, 1),
498WSS_DOUBLE("Mic Playback Switch", 0,
499 CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 7, 7, 1, 1),
500WSS_DOUBLE("Mic Playback Volume", 0,
501 CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 0, 0, 31, 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502};
503
Bill Pemberton1bff2922012-12-06 12:35:21 -0500504static int snd_interwave_mixer(struct snd_wss *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505{
Takashi Iwai5e2da202005-11-17 14:36:44 +0100506 struct snd_card *card = chip->card;
507 struct snd_ctl_elem_id id1, id2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 unsigned int idx;
509 int err;
510
511 memset(&id1, 0, sizeof(id1));
512 memset(&id2, 0, sizeof(id2));
513 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
514#if 0
515 /* remove mono microphone controls */
516 strcpy(id1.name, "Mic Playback Switch");
517 if ((err = snd_ctl_remove_id(card, &id1)) < 0)
518 return err;
519 strcpy(id1.name, "Mic Playback Volume");
520 if ((err = snd_ctl_remove_id(card, &id1)) < 0)
521 return err;
522#endif
523 /* add new master and mic controls */
524 for (idx = 0; idx < ARRAY_SIZE(snd_interwave_controls); idx++)
525 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_interwave_controls[idx], chip))) < 0)
526 return err;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200527 snd_wss_out(chip, CS4231_LINE_LEFT_OUTPUT, 0x9f);
528 snd_wss_out(chip, CS4231_LINE_RIGHT_OUTPUT, 0x9f);
529 snd_wss_out(chip, CS4231_LEFT_MIC_INPUT, 0x9f);
530 snd_wss_out(chip, CS4231_RIGHT_MIC_INPUT, 0x9f);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 /* reassign AUXA to SYNTHESIZER */
532 strcpy(id1.name, "Aux Playback Switch");
533 strcpy(id2.name, "Synth Playback Switch");
534 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
535 return err;
536 strcpy(id1.name, "Aux Playback Volume");
537 strcpy(id2.name, "Synth Playback Volume");
538 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
539 return err;
540 /* reassign AUXB to CD */
541 strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
542 strcpy(id2.name, "CD Playback Switch");
543 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
544 return err;
545 strcpy(id1.name, "Aux Playback Volume");
546 strcpy(id2.name, "CD Playback Volume");
547 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
548 return err;
549 return 0;
550}
551
552#ifdef CONFIG_PNP
553
Bill Pemberton1bff2922012-12-06 12:35:21 -0500554static int snd_interwave_pnp(int dev, struct snd_interwave *iwcard,
555 struct pnp_card_link *card,
556 const struct pnp_card_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
558 struct pnp_dev *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 int err;
560
561 iwcard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
Rene Herman109c53f842007-11-30 17:59:25 +0100562 if (iwcard->dev == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 return -EBUSY;
Rene Herman109c53f842007-11-30 17:59:25 +0100564
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#ifdef SNDRV_STB
566 iwcard->devtc = pnp_request_card_device(card, id->devs[1].id, NULL);
Rene Herman109c53f842007-11-30 17:59:25 +0100567 if (iwcard->devtc == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569#endif
570 /* Synth & Codec initialization */
571 pdev = iwcard->dev;
Rene Herman109c53f842007-11-30 17:59:25 +0100572
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 err = pnp_activate_dev(pdev);
574 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 snd_printk(KERN_ERR "InterWave PnP configure failure (out of resources?)\n");
576 return err;
577 }
578 if (pnp_port_start(pdev, 0) + 0x100 != pnp_port_start(pdev, 1) ||
579 pnp_port_start(pdev, 0) + 0x10c != pnp_port_start(pdev, 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 snd_printk(KERN_ERR "PnP configure failure (wrong ports)\n");
581 return -ENOENT;
582 }
583 port[dev] = pnp_port_start(pdev, 0);
584 dma1[dev] = pnp_dma(pdev, 0);
585 if (dma2[dev] >= 0)
586 dma2[dev] = pnp_dma(pdev, 1);
587 irq[dev] = pnp_irq(pdev, 0);
Greg Kroah-Hartmanaa0a2dd2006-06-12 14:50:27 -0700588 snd_printdd("isapnp IW: sb port=0x%llx, gf1 port=0x%llx, codec port=0x%llx\n",
589 (unsigned long long)pnp_port_start(pdev, 0),
590 (unsigned long long)pnp_port_start(pdev, 1),
591 (unsigned long long)pnp_port_start(pdev, 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 snd_printdd("isapnp IW: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]);
593#ifdef SNDRV_STB
594 /* Tone Control initialization */
595 pdev = iwcard->devtc;
Rene Herman109c53f842007-11-30 17:59:25 +0100596
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 err = pnp_activate_dev(pdev);
598 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 snd_printk(KERN_ERR "InterWave ToneControl PnP configure failure (out of resources?)\n");
600 return err;
601 }
602 port_tc[dev] = pnp_port_start(pdev, 0);
603 snd_printdd("isapnp IW: tone control port=0x%lx\n", port_tc[dev]);
604#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 return 0;
606}
607#endif /* CONFIG_PNP */
608
Takashi Iwai5e2da202005-11-17 14:36:44 +0100609static void snd_interwave_free(struct snd_card *card)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
Takashi Iwai654aa662005-11-17 17:13:43 +0100611 struct snd_interwave *iwcard = card->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613 if (iwcard == NULL)
614 return;
615#ifdef SNDRV_STB
Takashi Iwaib1d57762005-10-10 11:56:31 +0200616 release_and_free_resource(iwcard->i2c_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617#endif
618 if (iwcard->irq >= 0)
619 free_irq(iwcard->irq, (void *)iwcard);
620}
621
Takashi Iwai4323cc42014-01-29 13:03:56 +0100622static int snd_interwave_card_new(struct device *pdev, int dev,
623 struct snd_card **cardp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624{
Takashi Iwai5e2da202005-11-17 14:36:44 +0100625 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 struct snd_interwave *iwcard;
Takashi Iwaic95eadd2008-12-28 16:43:35 +0100627 int err;
Takashi Iwai654aa662005-11-17 17:13:43 +0100628
Takashi Iwai4323cc42014-01-29 13:03:56 +0100629 err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
630 sizeof(struct snd_interwave), &card);
Takashi Iwaic95eadd2008-12-28 16:43:35 +0100631 if (err < 0)
Takashi Iwai3e7fb9f2008-12-28 16:47:30 +0100632 return err;
Takashi Iwai654aa662005-11-17 17:13:43 +0100633 iwcard = card->private_data;
634 iwcard->card = card;
635 iwcard->irq = -1;
636 card->private_free = snd_interwave_free;
Takashi Iwai3e7fb9f2008-12-28 16:47:30 +0100637 *cardp = card;
638 return 0;
Takashi Iwai654aa662005-11-17 17:13:43 +0100639}
640
Bill Pemberton1bff2922012-12-06 12:35:21 -0500641static int snd_interwave_probe(struct snd_card *card, int dev)
Takashi Iwai654aa662005-11-17 17:13:43 +0100642{
643 int xirq, xdma1, xdma2;
644 struct snd_interwave *iwcard = card->private_data;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200645 struct snd_wss *wss;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100646 struct snd_gus_card *gus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647#ifdef SNDRV_STB
Takashi Iwai5e2da202005-11-17 14:36:44 +0100648 struct snd_i2c_bus *i2c_bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 char *str;
651 int err;
652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 xirq = irq[dev];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 xdma1 = dma1[dev];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 xdma2 = dma2[dev];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
657 if ((err = snd_gus_create(card,
658 port[dev],
659 -xirq, xdma1, xdma2,
660 0, 32,
Takashi Iwai43bcd972005-09-05 17:19:20 +0200661 pcm_channels[dev], effect[dev], &gus)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100662 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 if ((err = snd_interwave_detect(iwcard, gus, dev
665#ifdef SNDRV_STB
666 , &i2c_bus
667#endif
Takashi Iwai43bcd972005-09-05 17:19:20 +0200668 )) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100669 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200670
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 iwcard->gus_status_reg = gus->gf1.reg_irqstat;
672 iwcard->pcm_status_reg = gus->gf1.port + 0x10c + 2;
673
674 snd_interwave_init(dev, gus);
675 snd_interwave_detect_memory(gus);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200676 if ((err = snd_gus_initialize(gus)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100677 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Yong Zhang88e24c32011-09-22 16:59:20 +0800679 if (request_irq(xirq, snd_interwave_interrupt, 0,
Takashi Iwai654aa662005-11-17 17:13:43 +0100680 "InterWave", iwcard)) {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200681 snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq);
Takashi Iwai654aa662005-11-17 17:13:43 +0100682 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 }
684 iwcard->irq = xirq;
685
Krzysztof Helt7779f752008-07-31 21:03:41 +0200686 err = snd_wss_create(card,
687 gus->gf1.port + 0x10c, -1, xirq,
688 xdma2 < 0 ? xdma1 : xdma2, xdma1,
689 WSS_HW_INTERWAVE,
690 WSS_HWSHARE_IRQ |
691 WSS_HWSHARE_DMA1 |
692 WSS_HWSHARE_DMA2,
693 &wss);
694 if (err < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100695 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200696
Lars-Peter Clausenfa60c062015-01-02 12:24:43 +0100697 err = snd_wss_pcm(wss, 0);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200698 if (err < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100699 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200700
Lars-Peter Clausenfa60c062015-01-02 12:24:43 +0100701 sprintf(wss->pcm->name + strlen(wss->pcm->name), " rev %c",
702 gus->revision + 'A');
703 strcat(wss->pcm->name, " (codec)");
Takashi Iwai43bcd972005-09-05 17:19:20 +0200704
Lars-Peter Clausenfa60c062015-01-02 12:24:43 +0100705 err = snd_wss_timer(wss, 2);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200706 if (err < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100707 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200708
Krzysztof Helt7779f752008-07-31 21:03:41 +0200709 err = snd_wss_mixer(wss);
710 if (err < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100711 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200712
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 if (pcm_channels[dev] > 0) {
Lars-Peter Clausendb5abb32015-01-02 12:24:39 +0100714 err = snd_gf1_pcm_new(gus, 1, 1);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200715 if (err < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100716 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 }
Krzysztof Helt7779f752008-07-31 21:03:41 +0200718 err = snd_interwave_mixer(wss);
719 if (err < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100720 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722#ifdef SNDRV_STB
723 {
Takashi Iwai5e2da202005-11-17 14:36:44 +0100724 struct snd_ctl_elem_id id1, id2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 memset(&id1, 0, sizeof(id1));
726 memset(&id2, 0, sizeof(id2));
727 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
728 strcpy(id1.name, "Master Playback Switch");
729 strcpy(id2.name, id1.name);
730 id2.index = 1;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200731 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100732 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 strcpy(id1.name, "Master Playback Volume");
734 strcpy(id2.name, id1.name);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200735 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100736 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200737 if ((err = snd_tea6330t_update_mixer(card, i2c_bus, 0, 1)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100738 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 }
740#endif
741
742 gus->uart_enable = midi[dev];
Lars-Peter Clausendb5abb32015-01-02 12:24:39 +0100743 if ((err = snd_gf1_rawmidi_new(gus, 0)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100744 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
746#ifndef SNDRV_STB
747 str = "AMD InterWave";
748 if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8)
749 str = "Dynasonic 3-D";
750#else
751 str = "InterWave STB";
752#endif
753 strcpy(card->driver, str);
754 strcpy(card->shortname, str);
755 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %d",
756 str,
757 gus->gf1.port,
758 xirq,
759 xdma1);
760 if (xdma2 >= 0)
761 sprintf(card->longname + strlen(card->longname), "&%d", xdma2);
762
Krzysztof Helt7779f752008-07-31 21:03:41 +0200763 err = snd_card_register(card);
764 if (err < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100765 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
Krzysztof Helt7779f752008-07-31 21:03:41 +0200767 iwcard->wss = wss;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 iwcard->gus = gus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770}
771
Bill Pemberton1bff2922012-12-06 12:35:21 -0500772static int snd_interwave_isa_probe1(int dev, struct device *devptr)
Takashi Iwai654aa662005-11-17 17:13:43 +0100773{
774 struct snd_card *card;
775 int err;
776
Takashi Iwai4323cc42014-01-29 13:03:56 +0100777 err = snd_interwave_card_new(devptr, dev, &card);
Takashi Iwai3e7fb9f2008-12-28 16:47:30 +0100778 if (err < 0)
779 return err;
Takashi Iwai654aa662005-11-17 17:13:43 +0100780
Takashi Iwai654aa662005-11-17 17:13:43 +0100781 if ((err = snd_interwave_probe(card, dev)) < 0) {
782 snd_card_free(card);
783 return err;
784 }
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100785 dev_set_drvdata(devptr, card);
Takashi Iwai654aa662005-11-17 17:13:43 +0100786 return 0;
787}
788
Bill Pemberton1bff2922012-12-06 12:35:21 -0500789static int snd_interwave_isa_match(struct device *pdev,
790 unsigned int dev)
Takashi Iwai654aa662005-11-17 17:13:43 +0100791{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100792 if (!enable[dev])
793 return 0;
794#ifdef CONFIG_PNP
795 if (isapnp[dev])
796 return 0;
797#endif
798 return 1;
799}
800
Bill Pemberton1bff2922012-12-06 12:35:21 -0500801static int snd_interwave_isa_probe(struct device *pdev,
802 unsigned int dev)
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100803{
Takashi Iwai654aa662005-11-17 17:13:43 +0100804 int err;
805 static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, -1};
806 static int possible_dmas[] = {0, 1, 3, 5, 6, 7, -1};
807
808 if (irq[dev] == SNDRV_AUTO_IRQ) {
809 if ((irq[dev] = snd_legacy_find_free_irq(possible_irqs)) < 0) {
810 snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
811 return -EBUSY;
812 }
813 }
814 if (dma1[dev] == SNDRV_AUTO_DMA) {
815 if ((dma1[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) {
816 snd_printk(KERN_ERR PFX "unable to find a free DMA1\n");
817 return -EBUSY;
818 }
819 }
820 if (dma2[dev] == SNDRV_AUTO_DMA) {
821 if ((dma2[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) {
822 snd_printk(KERN_ERR PFX "unable to find a free DMA2\n");
823 return -EBUSY;
824 }
825 }
826
827 if (port[dev] != SNDRV_AUTO_PORT)
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100828 return snd_interwave_isa_probe1(dev, pdev);
Takashi Iwai654aa662005-11-17 17:13:43 +0100829 else {
830 static long possible_ports[] = {0x210, 0x220, 0x230, 0x240, 0x250, 0x260};
831 int i;
832 for (i = 0; i < ARRAY_SIZE(possible_ports); i++) {
833 port[dev] = possible_ports[i];
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100834 err = snd_interwave_isa_probe1(dev, pdev);
Takashi Iwai654aa662005-11-17 17:13:43 +0100835 if (! err)
836 return 0;
837 }
838 return err;
839 }
840}
841
Bill Pemberton1bff2922012-12-06 12:35:21 -0500842static int snd_interwave_isa_remove(struct device *devptr, unsigned int dev)
Takashi Iwai654aa662005-11-17 17:13:43 +0100843{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100844 snd_card_free(dev_get_drvdata(devptr));
Takashi Iwai654aa662005-11-17 17:13:43 +0100845 return 0;
846}
847
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100848static struct isa_driver snd_interwave_driver = {
849 .match = snd_interwave_isa_match,
850 .probe = snd_interwave_isa_probe,
Bill Pemberton1bff2922012-12-06 12:35:21 -0500851 .remove = snd_interwave_isa_remove,
Takashi Iwai654aa662005-11-17 17:13:43 +0100852 /* FIXME: suspend,resume */
853 .driver = {
854 .name = INTERWAVE_DRIVER
855 },
856};
857
858#ifdef CONFIG_PNP
Bill Pemberton1bff2922012-12-06 12:35:21 -0500859static int snd_interwave_pnp_detect(struct pnp_card_link *pcard,
860 const struct pnp_card_device_id *pid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861{
862 static int dev;
Takashi Iwai654aa662005-11-17 17:13:43 +0100863 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 int res;
865
866 for ( ; dev < SNDRV_CARDS; dev++) {
Takashi Iwai654aa662005-11-17 17:13:43 +0100867 if (enable[dev] && isapnp[dev])
868 break;
869 }
870 if (dev >= SNDRV_CARDS)
871 return -ENODEV;
872
Takashi Iwai4323cc42014-01-29 13:03:56 +0100873 res = snd_interwave_card_new(&pcard->card->dev, dev, &card);
Takashi Iwai3e7fb9f2008-12-28 16:47:30 +0100874 if (res < 0)
875 return res;
Takashi Iwai654aa662005-11-17 17:13:43 +0100876
877 if ((res = snd_interwave_pnp(dev, card->private_data, pcard, pid)) < 0) {
878 snd_card_free(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 return res;
880 }
Takashi Iwai654aa662005-11-17 17:13:43 +0100881 if ((res = snd_interwave_probe(card, dev)) < 0) {
882 snd_card_free(card);
883 return res;
884 }
885 pnp_set_card_drvdata(pcard, card);
886 dev++;
887 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888}
889
Bill Pemberton1bff2922012-12-06 12:35:21 -0500890static void snd_interwave_pnp_remove(struct pnp_card_link *pcard)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891{
Takashi Iwai654aa662005-11-17 17:13:43 +0100892 snd_card_free(pnp_get_card_drvdata(pcard));
893 pnp_set_card_drvdata(pcard, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894}
895
896static struct pnp_card_driver interwave_pnpc_driver = {
897 .flags = PNP_DRIVER_RES_DISABLE,
Takashi Iwai654aa662005-11-17 17:13:43 +0100898 .name = INTERWAVE_PNP_DRIVER,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 .id_table = snd_interwave_pnpids,
900 .probe = snd_interwave_pnp_detect,
Bill Pemberton1bff2922012-12-06 12:35:21 -0500901 .remove = snd_interwave_pnp_remove,
Takashi Iwai654aa662005-11-17 17:13:43 +0100902 /* FIXME: suspend,resume */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903};
904
905#endif /* CONFIG_PNP */
906
907static int __init alsa_card_interwave_init(void)
908{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100909 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100911 err = isa_register_driver(&snd_interwave_driver, SNDRV_CARDS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912#ifdef CONFIG_PNP
Rene Herman609d7692007-05-15 11:42:56 +0200913 if (!err)
914 isa_registered = 1;
915
Bjorn Helgaasebdb71e2006-03-27 01:17:14 -0800916 err = pnp_register_card_driver(&interwave_pnpc_driver);
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100917 if (!err)
Clemens Ladischf7a92752005-12-07 09:13:42 +0100918 pnp_registered = 1;
Rene Herman609d7692007-05-15 11:42:56 +0200919
920 if (isa_registered)
921 err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922#endif
Rene Herman609d7692007-05-15 11:42:56 +0200923 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924}
925
926static void __exit alsa_card_interwave_exit(void)
927{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100928#ifdef CONFIG_PNP
929 if (pnp_registered)
930 pnp_unregister_card_driver(&interwave_pnpc_driver);
Rene Herman609d7692007-05-15 11:42:56 +0200931 if (isa_registered)
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100932#endif
Rene Herman609d7692007-05-15 11:42:56 +0200933 isa_unregister_driver(&snd_interwave_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934}
935
936module_init(alsa_card_interwave_init)
937module_exit(alsa_card_interwave_exit)