Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Driver for AMD InterWave soundcard | |
c1017a4c | 3 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
1da177e4 LT |
4 | * |
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 | ||
1da177e4 | 25 | #include <linux/init.h> |
654aa661 | 26 | #include <linux/err.h> |
5e24c1c1 | 27 | #include <linux/isa.h> |
654aa661 | 28 | #include <linux/delay.h> |
1da177e4 LT |
29 | #include <linux/slab.h> |
30 | #include <linux/pnp.h> | |
31 | #include <linux/moduleparam.h> | |
654aa661 | 32 | #include <asm/dma.h> |
1da177e4 LT |
33 | #include <sound/core.h> |
34 | #include <sound/gus.h> | |
61ef19d7 | 35 | #include <sound/wss.h> |
1da177e4 LT |
36 | #ifdef SNDRV_STB |
37 | #include <sound/tea6330t.h> | |
38 | #endif | |
1da177e4 LT |
39 | #define SNDRV_LEGACY_FIND_FREE_IRQ |
40 | #define SNDRV_LEGACY_FIND_FREE_DMA | |
41 | #include <sound/initval.h> | |
42 | ||
c1017a4c | 43 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
1da177e4 LT |
44 | MODULE_LICENSE("GPL"); |
45 | #ifndef SNDRV_STB | |
46 | MODULE_DESCRIPTION("AMD InterWave"); | |
47 | MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Plug & Play}," | |
48 | "{STB,SoundRage32}," | |
49 | "{MED,MED3210}," | |
50 | "{Dynasonix,Dynasonix Pro}," | |
51 | "{Panasonic,PCA761AW}}"); | |
52 | #else | |
53 | MODULE_DESCRIPTION("AMD InterWave STB with TEA6330T"); | |
54 | MODULE_SUPPORTED_DEVICE("{{AMD,InterWave STB with TEA6330T}}"); | |
55 | #endif | |
56 | ||
57 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ | |
58 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ | |
59 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */ | |
60 | #ifdef CONFIG_PNP | |
61 | static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; | |
62 | #endif | |
63 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x210,0x220,0x230,0x240,0x250,0x260 */ | |
64 | #ifdef SNDRV_STB | |
65 | static long port_tc[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x350,0x360,0x370,0x380 */ | |
66 | #endif | |
67 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 2,3,5,9,11,12,15 */ | |
68 | static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */ | |
69 | static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */ | |
70 | static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29}; | |
71 | /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */ | |
6581f4e7 | 72 | static int midi[SNDRV_CARDS]; |
1da177e4 | 73 | static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; |
6581f4e7 | 74 | static int effect[SNDRV_CARDS]; |
1da177e4 | 75 | |
43bcd973 TI |
76 | #ifdef SNDRV_STB |
77 | #define PFX "interwave-stb: " | |
654aa661 TI |
78 | #define INTERWAVE_DRIVER "snd_interwave_stb" |
79 | #define INTERWAVE_PNP_DRIVER "interwave-stb" | |
43bcd973 TI |
80 | #else |
81 | #define PFX "interwave: " | |
654aa661 TI |
82 | #define INTERWAVE_DRIVER "snd_interwave" |
83 | #define INTERWAVE_PNP_DRIVER "interwave" | |
43bcd973 TI |
84 | #endif |
85 | ||
1da177e4 LT |
86 | module_param_array(index, int, NULL, 0444); |
87 | MODULE_PARM_DESC(index, "Index value for InterWave soundcard."); | |
88 | module_param_array(id, charp, NULL, 0444); | |
89 | MODULE_PARM_DESC(id, "ID string for InterWave soundcard."); | |
90 | module_param_array(enable, bool, NULL, 0444); | |
91 | MODULE_PARM_DESC(enable, "Enable InterWave soundcard."); | |
92 | #ifdef CONFIG_PNP | |
93 | module_param_array(isapnp, bool, NULL, 0444); | |
94 | MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard."); | |
95 | #endif | |
96 | module_param_array(port, long, NULL, 0444); | |
97 | MODULE_PARM_DESC(port, "Port # for InterWave driver."); | |
98 | #ifdef SNDRV_STB | |
99 | module_param_array(port_tc, long, NULL, 0444); | |
100 | MODULE_PARM_DESC(port_tc, "Tone control (TEA6330T - i2c bus) port # for InterWave driver."); | |
101 | #endif | |
102 | module_param_array(irq, int, NULL, 0444); | |
103 | MODULE_PARM_DESC(irq, "IRQ # for InterWave driver."); | |
104 | module_param_array(dma1, int, NULL, 0444); | |
105 | MODULE_PARM_DESC(dma1, "DMA1 # for InterWave driver."); | |
106 | module_param_array(dma2, int, NULL, 0444); | |
107 | MODULE_PARM_DESC(dma2, "DMA2 # for InterWave driver."); | |
108 | module_param_array(joystick_dac, int, NULL, 0444); | |
109 | MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for InterWave driver."); | |
110 | module_param_array(midi, int, NULL, 0444); | |
111 | MODULE_PARM_DESC(midi, "MIDI UART enable for InterWave driver."); | |
112 | module_param_array(pcm_channels, int, NULL, 0444); | |
113 | MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for InterWave driver."); | |
114 | module_param_array(effect, int, NULL, 0444); | |
115 | MODULE_PARM_DESC(effect, "Effects enable for InterWave driver."); | |
116 | ||
117 | struct snd_interwave { | |
118 | int irq; | |
5e2da206 TI |
119 | struct snd_card *card; |
120 | struct snd_gus_card *gus; | |
7779f75f | 121 | struct snd_wss *wss; |
1da177e4 LT |
122 | #ifdef SNDRV_STB |
123 | struct resource *i2c_res; | |
124 | #endif | |
125 | unsigned short gus_status_reg; | |
126 | unsigned short pcm_status_reg; | |
127 | #ifdef CONFIG_PNP | |
128 | struct pnp_dev *dev; | |
129 | #ifdef SNDRV_STB | |
130 | struct pnp_dev *devtc; | |
131 | #endif | |
132 | #endif | |
133 | }; | |
134 | ||
1da177e4 LT |
135 | |
136 | #ifdef CONFIG_PNP | |
609d7694 | 137 | static int isa_registered; |
5e24c1c1 | 138 | static int pnp_registered; |
1da177e4 LT |
139 | |
140 | static struct pnp_card_device_id snd_interwave_pnpids[] = { | |
141 | #ifndef SNDRV_STB | |
142 | /* Gravis UltraSound Plug & Play */ | |
143 | { .id = "GRV0001", .devs = { { .id = "GRV0000" } } }, | |
144 | /* STB SoundRage32 */ | |
145 | { .id = "STB011a", .devs = { { .id = "STB0010" } } }, | |
146 | /* MED3210 */ | |
147 | { .id = "DXP3201", .devs = { { .id = "DXP0010" } } }, | |
148 | /* Dynasonic Pro */ | |
149 | /* This device also have CDC1117:DynaSonix Pro Audio Effects Processor */ | |
150 | { .id = "CDC1111", .devs = { { .id = "CDC1112" } } }, | |
151 | /* Panasonic PCA761AW Audio Card */ | |
152 | { .id = "ADV55ff", .devs = { { .id = "ADV0010" } } }, | |
153 | /* InterWave STB without TEA6330T */ | |
154 | { .id = "ADV550a", .devs = { { .id = "ADV0010" } } }, | |
155 | #else | |
156 | /* InterWave STB with TEA6330T */ | |
157 | { .id = "ADV550a", .devs = { { .id = "ADV0010" }, { .id = "ADV0015" } } }, | |
158 | #endif | |
159 | { .id = "" } | |
160 | }; | |
161 | ||
162 | MODULE_DEVICE_TABLE(pnp_card, snd_interwave_pnpids); | |
163 | ||
164 | #endif /* CONFIG_PNP */ | |
165 | ||
166 | ||
167 | #ifdef SNDRV_STB | |
5e2da206 | 168 | static void snd_interwave_i2c_setlines(struct snd_i2c_bus *bus, int ctrl, int data) |
1da177e4 LT |
169 | { |
170 | unsigned long port = bus->private_value; | |
171 | ||
172 | #if 0 | |
91f05060 | 173 | printk(KERN_DEBUG "i2c_setlines - 0x%lx <- %i,%i\n", port, ctrl, data); |
1da177e4 LT |
174 | #endif |
175 | outb((data << 1) | ctrl, port); | |
176 | udelay(10); | |
177 | } | |
178 | ||
5e2da206 | 179 | static int snd_interwave_i2c_getclockline(struct snd_i2c_bus *bus) |
1da177e4 LT |
180 | { |
181 | unsigned long port = bus->private_value; | |
182 | unsigned char res; | |
183 | ||
184 | res = inb(port) & 1; | |
185 | #if 0 | |
91f05060 | 186 | printk(KERN_DEBUG "i2c_getclockline - 0x%lx -> %i\n", port, res); |
1da177e4 LT |
187 | #endif |
188 | return res; | |
189 | } | |
190 | ||
5e2da206 | 191 | static int snd_interwave_i2c_getdataline(struct snd_i2c_bus *bus, int ack) |
1da177e4 LT |
192 | { |
193 | unsigned long port = bus->private_value; | |
194 | unsigned char res; | |
195 | ||
196 | if (ack) | |
197 | udelay(10); | |
198 | res = (inb(port) & 2) >> 1; | |
199 | #if 0 | |
91f05060 | 200 | printk(KERN_DEBUG "i2c_getdataline - 0x%lx -> %i\n", port, res); |
1da177e4 LT |
201 | #endif |
202 | return res; | |
203 | } | |
204 | ||
5e2da206 | 205 | static struct snd_i2c_bit_ops snd_interwave_i2c_bit_ops = { |
1da177e4 LT |
206 | .setlines = snd_interwave_i2c_setlines, |
207 | .getclock = snd_interwave_i2c_getclockline, | |
208 | .getdata = snd_interwave_i2c_getdataline, | |
209 | }; | |
210 | ||
211 | static int __devinit snd_interwave_detect_stb(struct snd_interwave *iwcard, | |
5e2da206 TI |
212 | struct snd_gus_card * gus, int dev, |
213 | struct snd_i2c_bus **rbus) | |
1da177e4 LT |
214 | { |
215 | unsigned long port; | |
5e2da206 TI |
216 | struct snd_i2c_bus *bus; |
217 | struct snd_card *card = iwcard->card; | |
1da177e4 LT |
218 | char name[32]; |
219 | int err; | |
220 | ||
221 | *rbus = NULL; | |
222 | port = port_tc[dev]; | |
223 | if (port == SNDRV_AUTO_PORT) { | |
224 | port = 0x350; | |
225 | if (gus->gf1.port == 0x250) { | |
226 | port = 0x360; | |
227 | } | |
228 | while (port <= 0x380) { | |
229 | if ((iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)")) != NULL) | |
230 | break; | |
231 | port += 0x10; | |
232 | } | |
233 | } else { | |
234 | iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)"); | |
235 | } | |
236 | if (iwcard->i2c_res == NULL) { | |
237 | snd_printk(KERN_ERR "interwave: can't grab i2c bus port\n"); | |
238 | return -ENODEV; | |
239 | } | |
240 | ||
241 | sprintf(name, "InterWave-%i", card->number); | |
242 | if ((err = snd_i2c_bus_create(card, name, NULL, &bus)) < 0) | |
243 | return err; | |
244 | bus->private_value = port; | |
245 | bus->hw_ops.bit = &snd_interwave_i2c_bit_ops; | |
246 | if ((err = snd_tea6330t_detect(bus, 0)) < 0) | |
247 | return err; | |
248 | *rbus = bus; | |
249 | return 0; | |
250 | } | |
251 | #endif | |
252 | ||
253 | static int __devinit snd_interwave_detect(struct snd_interwave *iwcard, | |
5e2da206 | 254 | struct snd_gus_card * gus, |
1da177e4 LT |
255 | int dev |
256 | #ifdef SNDRV_STB | |
5e2da206 | 257 | , struct snd_i2c_bus **rbus |
1da177e4 LT |
258 | #endif |
259 | ) | |
260 | { | |
261 | unsigned long flags; | |
262 | unsigned char rev1, rev2; | |
43bcd973 | 263 | int d; |
1da177e4 LT |
264 | |
265 | snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */ | |
43bcd973 TI |
266 | if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) { |
267 | snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d); | |
1da177e4 | 268 | return -ENODEV; |
43bcd973 | 269 | } |
1da177e4 LT |
270 | udelay(160); |
271 | snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */ | |
272 | udelay(160); | |
43bcd973 TI |
273 | if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) { |
274 | snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d); | |
1da177e4 | 275 | return -ENODEV; |
43bcd973 | 276 | } |
1da177e4 LT |
277 | spin_lock_irqsave(&gus->reg_lock, flags); |
278 | rev1 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER); | |
279 | snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, ~rev1); | |
280 | rev2 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER); | |
281 | snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, rev1); | |
282 | spin_unlock_irqrestore(&gus->reg_lock, flags); | |
283 | snd_printdd("[0x%lx] InterWave check - rev1=0x%x, rev2=0x%x\n", gus->gf1.port, rev1, rev2); | |
284 | if ((rev1 & 0xf0) == (rev2 & 0xf0) && | |
285 | (rev1 & 0x0f) != (rev2 & 0x0f)) { | |
286 | snd_printdd("[0x%lx] InterWave check - passed\n", gus->gf1.port); | |
287 | gus->interwave = 1; | |
288 | strcpy(gus->card->shortname, "AMD InterWave"); | |
289 | gus->revision = rev1 >> 4; | |
290 | #ifndef SNDRV_STB | |
291 | return 0; /* ok.. We have an InterWave board */ | |
292 | #else | |
293 | return snd_interwave_detect_stb(iwcard, gus, dev, rbus); | |
294 | #endif | |
295 | } | |
296 | snd_printdd("[0x%lx] InterWave check - failed\n", gus->gf1.port); | |
297 | return -ENODEV; | |
298 | } | |
299 | ||
7d12e780 | 300 | static irqreturn_t snd_interwave_interrupt(int irq, void *dev_id) |
1da177e4 | 301 | { |
c7bec5ab | 302 | struct snd_interwave *iwcard = dev_id; |
1da177e4 LT |
303 | int loop, max = 5; |
304 | int handled = 0; | |
305 | ||
306 | do { | |
307 | loop = 0; | |
308 | if (inb(iwcard->gus_status_reg)) { | |
309 | handled = 1; | |
7d12e780 | 310 | snd_gus_interrupt(irq, iwcard->gus); |
1da177e4 LT |
311 | loop++; |
312 | } | |
313 | if (inb(iwcard->pcm_status_reg) & 0x01) { /* IRQ bit is set? */ | |
314 | handled = 1; | |
7779f75f | 315 | snd_wss_interrupt(irq, iwcard->wss); |
1da177e4 LT |
316 | loop++; |
317 | } | |
318 | } while (loop && --max > 0); | |
319 | return IRQ_RETVAL(handled); | |
320 | } | |
321 | ||
5e2da206 | 322 | static void __devinit snd_interwave_reset(struct snd_gus_card * gus) |
1da177e4 LT |
323 | { |
324 | snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x00); | |
325 | udelay(160); | |
326 | snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x01); | |
327 | udelay(160); | |
328 | } | |
329 | ||
5e2da206 | 330 | static void __devinit snd_interwave_bank_sizes(struct snd_gus_card * gus, int *sizes) |
1da177e4 LT |
331 | { |
332 | unsigned int idx; | |
333 | unsigned int local; | |
334 | unsigned char d; | |
335 | ||
336 | for (idx = 0; idx < 4; idx++) { | |
337 | sizes[idx] = 0; | |
338 | d = 0x55; | |
339 | for (local = idx << 22; | |
340 | local < (idx << 22) + 0x400000; | |
341 | local += 0x40000, d++) { | |
342 | snd_gf1_poke(gus, local, d); | |
343 | snd_gf1_poke(gus, local + 1, d + 1); | |
344 | #if 0 | |
91f05060 TI |
345 | printk(KERN_DEBUG "d = 0x%x, local = 0x%x, " |
346 | "local + 1 = 0x%x, idx << 22 = 0x%x\n", | |
1da177e4 LT |
347 | d, |
348 | snd_gf1_peek(gus, local), | |
349 | snd_gf1_peek(gus, local + 1), | |
350 | snd_gf1_peek(gus, idx << 22)); | |
351 | #endif | |
352 | if (snd_gf1_peek(gus, local) != d || | |
353 | snd_gf1_peek(gus, local + 1) != d + 1 || | |
354 | snd_gf1_peek(gus, idx << 22) != 0x55) | |
355 | break; | |
356 | sizes[idx]++; | |
357 | } | |
358 | } | |
359 | #if 0 | |
91f05060 TI |
360 | printk(KERN_DEBUG "sizes: %i %i %i %i\n", |
361 | sizes[0], sizes[1], sizes[2], sizes[3]); | |
1da177e4 LT |
362 | #endif |
363 | } | |
364 | ||
365 | struct rom_hdr { | |
366 | /* 000 */ unsigned char iwave[8]; | |
367 | /* 008 */ unsigned char rom_hdr_revision; | |
368 | /* 009 */ unsigned char series_number; | |
369 | /* 010 */ unsigned char series_name[16]; | |
370 | /* 026 */ unsigned char date[10]; | |
371 | /* 036 */ unsigned short vendor_revision_major; | |
372 | /* 038 */ unsigned short vendor_revision_minor; | |
373 | /* 040 */ unsigned int rom_size; | |
374 | /* 044 */ unsigned char copyright[128]; | |
375 | /* 172 */ unsigned char vendor_name[64]; | |
376 | /* 236 */ unsigned char rom_description[128]; | |
377 | /* 364 */ unsigned char pad[147]; | |
378 | /* 511 */ unsigned char csum; | |
379 | }; | |
380 | ||
5e2da206 | 381 | static void __devinit snd_interwave_detect_memory(struct snd_gus_card * gus) |
1da177e4 LT |
382 | { |
383 | static unsigned int lmc[13] = | |
384 | { | |
385 | 0x00000001, 0x00000101, 0x01010101, 0x00000401, | |
386 | 0x04040401, 0x00040101, 0x04040101, 0x00000004, | |
387 | 0x00000404, 0x04040404, 0x00000010, 0x00001010, | |
388 | 0x10101010 | |
389 | }; | |
390 | ||
391 | int bank_pos, pages; | |
392 | unsigned int i, lmct; | |
393 | int psizes[4]; | |
394 | unsigned char iwave[8]; | |
395 | unsigned char csum; | |
396 | ||
397 | snd_interwave_reset(gus); | |
398 | snd_gf1_write8(gus, SNDRV_GF1_GB_GLOBAL_MODE, snd_gf1_read8(gus, SNDRV_GF1_GB_GLOBAL_MODE) | 0x01); /* enhanced mode */ | |
399 | snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01); /* DRAM I/O cycles selected */ | |
400 | snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xff10) | 0x004c); | |
401 | /* ok.. simple test of memory size */ | |
402 | pages = 0; | |
403 | snd_gf1_poke(gus, 0, 0x55); | |
404 | snd_gf1_poke(gus, 1, 0xaa); | |
405 | #if 1 | |
406 | if (snd_gf1_peek(gus, 0) == 0x55 && snd_gf1_peek(gus, 1) == 0xaa) | |
407 | #else | |
408 | if (0) /* ok.. for testing of 0k RAM */ | |
409 | #endif | |
410 | { | |
411 | snd_interwave_bank_sizes(gus, psizes); | |
412 | lmct = (psizes[3] << 24) | (psizes[2] << 16) | | |
413 | (psizes[1] << 8) | psizes[0]; | |
414 | #if 0 | |
91f05060 | 415 | printk(KERN_DEBUG "lmct = 0x%08x\n", lmct); |
1da177e4 LT |
416 | #endif |
417 | for (i = 0; i < ARRAY_SIZE(lmc); i++) | |
418 | if (lmct == lmc[i]) { | |
419 | #if 0 | |
91f05060 | 420 | printk(KERN_DEBUG "found !!! %i\n", i); |
1da177e4 LT |
421 | #endif |
422 | snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | i); | |
423 | snd_interwave_bank_sizes(gus, psizes); | |
424 | break; | |
425 | } | |
426 | if (i >= ARRAY_SIZE(lmc) && !gus->gf1.enh_mode) | |
427 | snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | 2); | |
428 | for (i = 0; i < 4; i++) { | |
429 | gus->gf1.mem_alloc.banks_8[i].address = | |
430 | gus->gf1.mem_alloc.banks_16[i].address = i << 22; | |
431 | gus->gf1.mem_alloc.banks_8[i].size = | |
432 | gus->gf1.mem_alloc.banks_16[i].size = psizes[i] << 18; | |
433 | pages += psizes[i]; | |
434 | } | |
435 | } | |
436 | pages <<= 18; | |
437 | gus->gf1.memory = pages; | |
438 | ||
439 | snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x03); /* select ROM */ | |
440 | snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xff1f) | (4 << 5)); | |
441 | gus->gf1.rom_banks = 0; | |
442 | gus->gf1.rom_memory = 0; | |
443 | for (bank_pos = 0; bank_pos < 16L * 1024L * 1024L; bank_pos += 4L * 1024L * 1024L) { | |
444 | for (i = 0; i < 8; ++i) | |
445 | iwave[i] = snd_gf1_peek(gus, bank_pos + i); | |
446 | #ifdef CONFIG_SND_DEBUG_ROM | |
99b359ba | 447 | printk(KERN_DEBUG "ROM at 0x%06x = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", bank_pos, |
1da177e4 LT |
448 | iwave[0], iwave[1], iwave[2], iwave[3], |
449 | iwave[4], iwave[5], iwave[6], iwave[7]); | |
450 | #endif | |
451 | if (strncmp(iwave, "INTRWAVE", 8)) | |
452 | continue; /* first check */ | |
453 | csum = 0; | |
454 | for (i = 0; i < sizeof(struct rom_hdr); i++) | |
455 | csum += snd_gf1_peek(gus, bank_pos + i); | |
456 | #ifdef CONFIG_SND_DEBUG_ROM | |
99b359ba | 457 | printk(KERN_DEBUG "ROM checksum = 0x%x (computed)\n", csum); |
1da177e4 LT |
458 | #endif |
459 | if (csum != 0) | |
460 | continue; /* not valid rom */ | |
461 | gus->gf1.rom_banks++; | |
462 | gus->gf1.rom_present |= 1 << (bank_pos >> 22); | |
463 | gus->gf1.rom_memory = snd_gf1_peek(gus, bank_pos + 40) | | |
464 | (snd_gf1_peek(gus, bank_pos + 41) << 8) | | |
465 | (snd_gf1_peek(gus, bank_pos + 42) << 16) | | |
466 | (snd_gf1_peek(gus, bank_pos + 43) << 24); | |
467 | } | |
468 | #if 0 | |
469 | if (gus->gf1.rom_memory > 0) { | |
470 | if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8) | |
471 | gus->card->type = SNDRV_CARD_TYPE_IW_DYNASONIC; | |
472 | } | |
473 | #endif | |
474 | snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x00); /* select RAM */ | |
475 | ||
476 | if (!gus->gf1.enh_mode) | |
477 | snd_interwave_reset(gus); | |
478 | } | |
479 | ||
5e2da206 | 480 | static void __devinit snd_interwave_init(int dev, struct snd_gus_card * gus) |
1da177e4 LT |
481 | { |
482 | unsigned long flags; | |
483 | ||
484 | /* ok.. some InterWave specific initialization */ | |
485 | spin_lock_irqsave(&gus->reg_lock, flags); | |
486 | snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, 0x00); | |
487 | snd_gf1_write8(gus, SNDRV_GF1_GB_COMPATIBILITY, 0x1f); | |
488 | snd_gf1_write8(gus, SNDRV_GF1_GB_DECODE_CONTROL, 0x49); | |
489 | snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, 0x11); | |
490 | snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_A, 0x00); | |
491 | snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_B, 0x30); | |
492 | snd_gf1_write8(gus, SNDRV_GF1_GB_EMULATION_IRQ, 0x00); | |
493 | spin_unlock_irqrestore(&gus->reg_lock, flags); | |
494 | gus->equal_irq = 1; | |
495 | gus->codec_flag = 1; | |
496 | gus->interwave = 1; | |
497 | gus->max_flag = 1; | |
498 | gus->joystick_dac = joystick_dac[dev]; | |
499 | ||
500 | } | |
501 | ||
5e2da206 | 502 | static struct snd_kcontrol_new snd_interwave_controls[] = { |
7779f75f KH |
503 | WSS_DOUBLE("Master Playback Switch", 0, |
504 | CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 7, 7, 1, 1), | |
505 | WSS_DOUBLE("Master Playback Volume", 0, | |
506 | CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 0, 0, 31, 1), | |
507 | WSS_DOUBLE("Mic Playback Switch", 0, | |
508 | CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 7, 7, 1, 1), | |
509 | WSS_DOUBLE("Mic Playback Volume", 0, | |
510 | CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 0, 0, 31, 1) | |
1da177e4 LT |
511 | }; |
512 | ||
7779f75f | 513 | static int __devinit snd_interwave_mixer(struct snd_wss *chip) |
1da177e4 | 514 | { |
5e2da206 TI |
515 | struct snd_card *card = chip->card; |
516 | struct snd_ctl_elem_id id1, id2; | |
1da177e4 LT |
517 | unsigned int idx; |
518 | int err; | |
519 | ||
520 | memset(&id1, 0, sizeof(id1)); | |
521 | memset(&id2, 0, sizeof(id2)); | |
522 | id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | |
523 | #if 0 | |
524 | /* remove mono microphone controls */ | |
525 | strcpy(id1.name, "Mic Playback Switch"); | |
526 | if ((err = snd_ctl_remove_id(card, &id1)) < 0) | |
527 | return err; | |
528 | strcpy(id1.name, "Mic Playback Volume"); | |
529 | if ((err = snd_ctl_remove_id(card, &id1)) < 0) | |
530 | return err; | |
531 | #endif | |
532 | /* add new master and mic controls */ | |
533 | for (idx = 0; idx < ARRAY_SIZE(snd_interwave_controls); idx++) | |
534 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_interwave_controls[idx], chip))) < 0) | |
535 | return err; | |
7779f75f KH |
536 | snd_wss_out(chip, CS4231_LINE_LEFT_OUTPUT, 0x9f); |
537 | snd_wss_out(chip, CS4231_LINE_RIGHT_OUTPUT, 0x9f); | |
538 | snd_wss_out(chip, CS4231_LEFT_MIC_INPUT, 0x9f); | |
539 | snd_wss_out(chip, CS4231_RIGHT_MIC_INPUT, 0x9f); | |
1da177e4 LT |
540 | /* reassign AUXA to SYNTHESIZER */ |
541 | strcpy(id1.name, "Aux Playback Switch"); | |
542 | strcpy(id2.name, "Synth 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, "Synth Playback Volume"); | |
547 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) | |
548 | return err; | |
549 | /* reassign AUXB to CD */ | |
550 | strcpy(id1.name, "Aux Playback Switch"); id1.index = 1; | |
551 | strcpy(id2.name, "CD Playback Switch"); | |
552 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) | |
553 | return err; | |
554 | strcpy(id1.name, "Aux Playback Volume"); | |
555 | strcpy(id2.name, "CD Playback Volume"); | |
556 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) | |
557 | return err; | |
558 | return 0; | |
559 | } | |
560 | ||
561 | #ifdef CONFIG_PNP | |
562 | ||
563 | static int __devinit snd_interwave_pnp(int dev, struct snd_interwave *iwcard, | |
564 | struct pnp_card_link *card, | |
565 | const struct pnp_card_device_id *id) | |
566 | { | |
567 | struct pnp_dev *pdev; | |
1da177e4 LT |
568 | int err; |
569 | ||
570 | iwcard->dev = pnp_request_card_device(card, id->devs[0].id, NULL); | |
109c53f8 | 571 | if (iwcard->dev == NULL) |
1da177e4 | 572 | return -EBUSY; |
109c53f8 | 573 | |
1da177e4 LT |
574 | #ifdef SNDRV_STB |
575 | iwcard->devtc = pnp_request_card_device(card, id->devs[1].id, NULL); | |
109c53f8 | 576 | if (iwcard->devtc == NULL) |
1da177e4 | 577 | return -EBUSY; |
1da177e4 LT |
578 | #endif |
579 | /* Synth & Codec initialization */ | |
580 | pdev = iwcard->dev; | |
109c53f8 | 581 | |
1da177e4 LT |
582 | err = pnp_activate_dev(pdev); |
583 | if (err < 0) { | |
1da177e4 LT |
584 | snd_printk(KERN_ERR "InterWave PnP configure failure (out of resources?)\n"); |
585 | return err; | |
586 | } | |
587 | if (pnp_port_start(pdev, 0) + 0x100 != pnp_port_start(pdev, 1) || | |
588 | pnp_port_start(pdev, 0) + 0x10c != pnp_port_start(pdev, 2)) { | |
1da177e4 LT |
589 | snd_printk(KERN_ERR "PnP configure failure (wrong ports)\n"); |
590 | return -ENOENT; | |
591 | } | |
592 | port[dev] = pnp_port_start(pdev, 0); | |
593 | dma1[dev] = pnp_dma(pdev, 0); | |
594 | if (dma2[dev] >= 0) | |
595 | dma2[dev] = pnp_dma(pdev, 1); | |
596 | irq[dev] = pnp_irq(pdev, 0); | |
aa0a2ddc GKH |
597 | snd_printdd("isapnp IW: sb port=0x%llx, gf1 port=0x%llx, codec port=0x%llx\n", |
598 | (unsigned long long)pnp_port_start(pdev, 0), | |
599 | (unsigned long long)pnp_port_start(pdev, 1), | |
600 | (unsigned long long)pnp_port_start(pdev, 2)); | |
1da177e4 LT |
601 | snd_printdd("isapnp IW: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]); |
602 | #ifdef SNDRV_STB | |
603 | /* Tone Control initialization */ | |
604 | pdev = iwcard->devtc; | |
109c53f8 | 605 | |
1da177e4 LT |
606 | err = pnp_activate_dev(pdev); |
607 | if (err < 0) { | |
1da177e4 LT |
608 | snd_printk(KERN_ERR "InterWave ToneControl PnP configure failure (out of resources?)\n"); |
609 | return err; | |
610 | } | |
611 | port_tc[dev] = pnp_port_start(pdev, 0); | |
612 | snd_printdd("isapnp IW: tone control port=0x%lx\n", port_tc[dev]); | |
613 | #endif | |
1da177e4 LT |
614 | return 0; |
615 | } | |
616 | #endif /* CONFIG_PNP */ | |
617 | ||
5e2da206 | 618 | static void snd_interwave_free(struct snd_card *card) |
1da177e4 | 619 | { |
654aa661 | 620 | struct snd_interwave *iwcard = card->private_data; |
1da177e4 LT |
621 | |
622 | if (iwcard == NULL) | |
623 | return; | |
624 | #ifdef SNDRV_STB | |
b1d5776d | 625 | release_and_free_resource(iwcard->i2c_res); |
1da177e4 LT |
626 | #endif |
627 | if (iwcard->irq >= 0) | |
628 | free_irq(iwcard->irq, (void *)iwcard); | |
629 | } | |
630 | ||
654aa661 | 631 | static struct snd_card *snd_interwave_card_new(int dev) |
1da177e4 | 632 | { |
5e2da206 | 633 | struct snd_card *card; |
1da177e4 | 634 | struct snd_interwave *iwcard; |
654aa661 TI |
635 | |
636 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, | |
637 | sizeof(struct snd_interwave)); | |
638 | if (card == NULL) | |
639 | return NULL; | |
640 | iwcard = card->private_data; | |
641 | iwcard->card = card; | |
642 | iwcard->irq = -1; | |
643 | card->private_free = snd_interwave_free; | |
644 | return card; | |
645 | } | |
646 | ||
647 | static int __devinit snd_interwave_probe(struct snd_card *card, int dev) | |
648 | { | |
649 | int xirq, xdma1, xdma2; | |
650 | struct snd_interwave *iwcard = card->private_data; | |
7779f75f | 651 | struct snd_wss *wss; |
5e2da206 | 652 | struct snd_gus_card *gus; |
1da177e4 | 653 | #ifdef SNDRV_STB |
5e2da206 | 654 | struct snd_i2c_bus *i2c_bus; |
1da177e4 | 655 | #endif |
5e2da206 | 656 | struct snd_pcm *pcm; |
1da177e4 LT |
657 | char *str; |
658 | int err; | |
659 | ||
1da177e4 | 660 | xirq = irq[dev]; |
1da177e4 | 661 | xdma1 = dma1[dev]; |
1da177e4 | 662 | xdma2 = dma2[dev]; |
1da177e4 LT |
663 | |
664 | if ((err = snd_gus_create(card, | |
665 | port[dev], | |
666 | -xirq, xdma1, xdma2, | |
667 | 0, 32, | |
43bcd973 | 668 | pcm_channels[dev], effect[dev], &gus)) < 0) |
654aa661 | 669 | return err; |
43bcd973 | 670 | |
1da177e4 LT |
671 | if ((err = snd_interwave_detect(iwcard, gus, dev |
672 | #ifdef SNDRV_STB | |
673 | , &i2c_bus | |
674 | #endif | |
43bcd973 | 675 | )) < 0) |
654aa661 | 676 | return err; |
43bcd973 | 677 | |
1da177e4 LT |
678 | iwcard->gus_status_reg = gus->gf1.reg_irqstat; |
679 | iwcard->pcm_status_reg = gus->gf1.port + 0x10c + 2; | |
680 | ||
681 | snd_interwave_init(dev, gus); | |
682 | snd_interwave_detect_memory(gus); | |
43bcd973 | 683 | if ((err = snd_gus_initialize(gus)) < 0) |
654aa661 | 684 | return err; |
1da177e4 | 685 | |
65ca68b3 | 686 | if (request_irq(xirq, snd_interwave_interrupt, IRQF_DISABLED, |
654aa661 | 687 | "InterWave", iwcard)) { |
43bcd973 | 688 | snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq); |
654aa661 | 689 | return -EBUSY; |
1da177e4 LT |
690 | } |
691 | iwcard->irq = xirq; | |
692 | ||
7779f75f KH |
693 | err = snd_wss_create(card, |
694 | gus->gf1.port + 0x10c, -1, xirq, | |
695 | xdma2 < 0 ? xdma1 : xdma2, xdma1, | |
696 | WSS_HW_INTERWAVE, | |
697 | WSS_HWSHARE_IRQ | | |
698 | WSS_HWSHARE_DMA1 | | |
699 | WSS_HWSHARE_DMA2, | |
700 | &wss); | |
701 | if (err < 0) | |
654aa661 | 702 | return err; |
43bcd973 | 703 | |
7779f75f KH |
704 | err = snd_wss_pcm(wss, 0, &pcm); |
705 | if (err < 0) | |
654aa661 | 706 | return err; |
43bcd973 | 707 | |
1da177e4 LT |
708 | sprintf(pcm->name + strlen(pcm->name), " rev %c", gus->revision + 'A'); |
709 | strcat(pcm->name, " (codec)"); | |
43bcd973 | 710 | |
7779f75f KH |
711 | err = snd_wss_timer(wss, 2, NULL); |
712 | if (err < 0) | |
654aa661 | 713 | return err; |
43bcd973 | 714 | |
7779f75f KH |
715 | err = snd_wss_mixer(wss); |
716 | if (err < 0) | |
654aa661 | 717 | return err; |
43bcd973 | 718 | |
1da177e4 | 719 | if (pcm_channels[dev] > 0) { |
7779f75f KH |
720 | err = snd_gf1_pcm_new(gus, 1, 1, NULL); |
721 | if (err < 0) | |
654aa661 | 722 | return err; |
1da177e4 | 723 | } |
7779f75f KH |
724 | err = snd_interwave_mixer(wss); |
725 | if (err < 0) | |
654aa661 | 726 | return err; |
43bcd973 | 727 | |
1da177e4 LT |
728 | #ifdef SNDRV_STB |
729 | { | |
5e2da206 | 730 | struct snd_ctl_elem_id id1, id2; |
1da177e4 LT |
731 | memset(&id1, 0, sizeof(id1)); |
732 | memset(&id2, 0, sizeof(id2)); | |
733 | id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | |
734 | strcpy(id1.name, "Master Playback Switch"); | |
735 | strcpy(id2.name, id1.name); | |
736 | id2.index = 1; | |
43bcd973 | 737 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) |
654aa661 | 738 | return err; |
1da177e4 LT |
739 | strcpy(id1.name, "Master Playback Volume"); |
740 | strcpy(id2.name, id1.name); | |
43bcd973 | 741 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) |
654aa661 | 742 | return err; |
43bcd973 | 743 | if ((err = snd_tea6330t_update_mixer(card, i2c_bus, 0, 1)) < 0) |
654aa661 | 744 | return err; |
1da177e4 LT |
745 | } |
746 | #endif | |
747 | ||
748 | gus->uart_enable = midi[dev]; | |
43bcd973 | 749 | if ((err = snd_gf1_rawmidi_new(gus, 0, NULL)) < 0) |
654aa661 | 750 | return err; |
1da177e4 LT |
751 | |
752 | #ifndef SNDRV_STB | |
753 | str = "AMD InterWave"; | |
754 | if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8) | |
755 | str = "Dynasonic 3-D"; | |
756 | #else | |
757 | str = "InterWave STB"; | |
758 | #endif | |
759 | strcpy(card->driver, str); | |
760 | strcpy(card->shortname, str); | |
761 | sprintf(card->longname, "%s at 0x%lx, irq %i, dma %d", | |
762 | str, | |
763 | gus->gf1.port, | |
764 | xirq, | |
765 | xdma1); | |
766 | if (xdma2 >= 0) | |
767 | sprintf(card->longname + strlen(card->longname), "&%d", xdma2); | |
768 | ||
7779f75f KH |
769 | err = snd_card_register(card); |
770 | if (err < 0) | |
654aa661 | 771 | return err; |
1da177e4 | 772 | |
7779f75f | 773 | iwcard->wss = wss; |
1da177e4 | 774 | iwcard->gus = gus; |
1da177e4 | 775 | return 0; |
654aa661 | 776 | } |
43bcd973 | 777 | |
5e24c1c1 | 778 | static int __devinit snd_interwave_isa_probe1(int dev, struct device *devptr) |
654aa661 TI |
779 | { |
780 | struct snd_card *card; | |
781 | int err; | |
782 | ||
783 | card = snd_interwave_card_new(dev); | |
784 | if (! card) | |
785 | return -ENOMEM; | |
786 | ||
5e24c1c1 | 787 | snd_card_set_dev(card, devptr); |
654aa661 TI |
788 | if ((err = snd_interwave_probe(card, dev)) < 0) { |
789 | snd_card_free(card); | |
790 | return err; | |
791 | } | |
5e24c1c1 | 792 | dev_set_drvdata(devptr, card); |
654aa661 | 793 | return 0; |
1da177e4 LT |
794 | } |
795 | ||
5e24c1c1 TI |
796 | static int __devinit snd_interwave_isa_match(struct device *pdev, |
797 | unsigned int dev) | |
798 | { | |
799 | if (!enable[dev]) | |
800 | return 0; | |
801 | #ifdef CONFIG_PNP | |
802 | if (isapnp[dev]) | |
803 | return 0; | |
804 | #endif | |
805 | return 1; | |
806 | } | |
807 | ||
808 | static int __devinit snd_interwave_isa_probe(struct device *pdev, | |
809 | unsigned int dev) | |
1da177e4 | 810 | { |
654aa661 TI |
811 | int err; |
812 | static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, -1}; | |
813 | static int possible_dmas[] = {0, 1, 3, 5, 6, 7, -1}; | |
1da177e4 | 814 | |
654aa661 TI |
815 | if (irq[dev] == SNDRV_AUTO_IRQ) { |
816 | if ((irq[dev] = snd_legacy_find_free_irq(possible_irqs)) < 0) { | |
817 | snd_printk(KERN_ERR PFX "unable to find a free IRQ\n"); | |
818 | return -EBUSY; | |
819 | } | |
820 | } | |
821 | if (dma1[dev] == SNDRV_AUTO_DMA) { | |
822 | if ((dma1[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) { | |
823 | snd_printk(KERN_ERR PFX "unable to find a free DMA1\n"); | |
824 | return -EBUSY; | |
825 | } | |
826 | } | |
827 | if (dma2[dev] == SNDRV_AUTO_DMA) { | |
828 | if ((dma2[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) { | |
829 | snd_printk(KERN_ERR PFX "unable to find a free DMA2\n"); | |
830 | return -EBUSY; | |
831 | } | |
832 | } | |
833 | ||
834 | if (port[dev] != SNDRV_AUTO_PORT) | |
5e24c1c1 | 835 | return snd_interwave_isa_probe1(dev, pdev); |
654aa661 TI |
836 | else { |
837 | static long possible_ports[] = {0x210, 0x220, 0x230, 0x240, 0x250, 0x260}; | |
838 | int i; | |
839 | for (i = 0; i < ARRAY_SIZE(possible_ports); i++) { | |
840 | port[dev] = possible_ports[i]; | |
5e24c1c1 | 841 | err = snd_interwave_isa_probe1(dev, pdev); |
654aa661 TI |
842 | if (! err) |
843 | return 0; | |
844 | } | |
845 | return err; | |
1da177e4 | 846 | } |
1da177e4 LT |
847 | } |
848 | ||
5e24c1c1 | 849 | static int __devexit snd_interwave_isa_remove(struct device *devptr, unsigned int dev) |
654aa661 | 850 | { |
5e24c1c1 TI |
851 | snd_card_free(dev_get_drvdata(devptr)); |
852 | dev_set_drvdata(devptr, NULL); | |
654aa661 TI |
853 | return 0; |
854 | } | |
855 | ||
5e24c1c1 TI |
856 | static struct isa_driver snd_interwave_driver = { |
857 | .match = snd_interwave_isa_match, | |
858 | .probe = snd_interwave_isa_probe, | |
859 | .remove = __devexit_p(snd_interwave_isa_remove), | |
654aa661 TI |
860 | /* FIXME: suspend,resume */ |
861 | .driver = { | |
862 | .name = INTERWAVE_DRIVER | |
863 | }, | |
864 | }; | |
865 | ||
1da177e4 | 866 | #ifdef CONFIG_PNP |
654aa661 TI |
867 | static int __devinit snd_interwave_pnp_detect(struct pnp_card_link *pcard, |
868 | const struct pnp_card_device_id *pid) | |
1da177e4 LT |
869 | { |
870 | static int dev; | |
654aa661 | 871 | struct snd_card *card; |
1da177e4 LT |
872 | int res; |
873 | ||
874 | for ( ; dev < SNDRV_CARDS; dev++) { | |
654aa661 TI |
875 | if (enable[dev] && isapnp[dev]) |
876 | break; | |
877 | } | |
878 | if (dev >= SNDRV_CARDS) | |
879 | return -ENODEV; | |
880 | ||
881 | card = snd_interwave_card_new(dev); | |
882 | if (! card) | |
883 | return -ENOMEM; | |
884 | ||
885 | if ((res = snd_interwave_pnp(dev, card->private_data, pcard, pid)) < 0) { | |
886 | snd_card_free(card); | |
887 | return res; | |
888 | } | |
889 | snd_card_set_dev(card, &pcard->card->dev); | |
890 | if ((res = snd_interwave_probe(card, dev)) < 0) { | |
891 | snd_card_free(card); | |
892 | return res; | |
893 | } | |
894 | pnp_set_card_drvdata(pcard, card); | |
895 | dev++; | |
896 | return 0; | |
1da177e4 LT |
897 | } |
898 | ||
899 | static void __devexit snd_interwave_pnp_remove(struct pnp_card_link * pcard) | |
900 | { | |
654aa661 TI |
901 | snd_card_free(pnp_get_card_drvdata(pcard)); |
902 | pnp_set_card_drvdata(pcard, NULL); | |
1da177e4 LT |
903 | } |
904 | ||
905 | static struct pnp_card_driver interwave_pnpc_driver = { | |
906 | .flags = PNP_DRIVER_RES_DISABLE, | |
654aa661 | 907 | .name = INTERWAVE_PNP_DRIVER, |
1da177e4 LT |
908 | .id_table = snd_interwave_pnpids, |
909 | .probe = snd_interwave_pnp_detect, | |
910 | .remove = __devexit_p(snd_interwave_pnp_remove), | |
654aa661 | 911 | /* FIXME: suspend,resume */ |
1da177e4 LT |
912 | }; |
913 | ||
914 | #endif /* CONFIG_PNP */ | |
915 | ||
916 | static int __init alsa_card_interwave_init(void) | |
917 | { | |
5e24c1c1 | 918 | int err; |
1da177e4 | 919 | |
5e24c1c1 | 920 | err = isa_register_driver(&snd_interwave_driver, SNDRV_CARDS); |
1da177e4 | 921 | #ifdef CONFIG_PNP |
609d7694 RH |
922 | if (!err) |
923 | isa_registered = 1; | |
924 | ||
ebdb71ea | 925 | err = pnp_register_card_driver(&interwave_pnpc_driver); |
5e24c1c1 | 926 | if (!err) |
f7a9275d | 927 | pnp_registered = 1; |
609d7694 RH |
928 | |
929 | if (isa_registered) | |
930 | err = 0; | |
1da177e4 | 931 | #endif |
609d7694 | 932 | return err; |
1da177e4 LT |
933 | } |
934 | ||
935 | static void __exit alsa_card_interwave_exit(void) | |
936 | { | |
5e24c1c1 TI |
937 | #ifdef CONFIG_PNP |
938 | if (pnp_registered) | |
939 | pnp_unregister_card_driver(&interwave_pnpc_driver); | |
609d7694 | 940 | if (isa_registered) |
5e24c1c1 | 941 | #endif |
609d7694 | 942 | isa_unregister_driver(&snd_interwave_driver); |
1da177e4 LT |
943 | } |
944 | ||
945 | module_init(alsa_card_interwave_init) | |
946 | module_exit(alsa_card_interwave_exit) |