Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | card-opti92x-ad1848.c - driver for OPTi 82c92x based soundcards. | |
3 | Copyright (C) 1998-2000 by Massimo Piccioni <dafastidio@libero.it> | |
4 | ||
5 | Part of this code was developed at the Italian Ministry of Air Defence, | |
6 | Sixth Division (oh, che pace ...), Rome. | |
7 | ||
8 | Thanks to Maria Grazia Pollarini, Salvatore Vassallo. | |
9 | ||
10 | This program is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2 of the License, or | |
13 | (at your option) any later version. | |
14 | ||
15 | This program is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with this program; if not, write to the Free Software | |
22 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 | */ | |
24 | ||
25 | ||
1da177e4 | 26 | #include <linux/init.h> |
99a0b768 | 27 | #include <linux/err.h> |
5e24c1c1 | 28 | #include <linux/isa.h> |
99a0b768 | 29 | #include <linux/delay.h> |
1da177e4 LT |
30 | #include <linux/slab.h> |
31 | #include <linux/pnp.h> | |
32 | #include <linux/moduleparam.h> | |
99a0b768 TI |
33 | #include <asm/io.h> |
34 | #include <asm/dma.h> | |
1da177e4 | 35 | #include <sound/core.h> |
61ef19d7 | 36 | #include <sound/wss.h> |
1da177e4 LT |
37 | #include <sound/mpu401.h> |
38 | #include <sound/opl3.h> | |
39 | #ifndef OPTi93X | |
40 | #include <sound/opl4.h> | |
41 | #endif | |
42 | #define SNDRV_LEGACY_FIND_FREE_IRQ | |
43 | #define SNDRV_LEGACY_FIND_FREE_DMA | |
44 | #include <sound/initval.h> | |
45 | ||
46 | MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>"); | |
47 | MODULE_LICENSE("GPL"); | |
48 | #ifdef OPTi93X | |
49 | MODULE_DESCRIPTION("OPTi93X"); | |
50 | MODULE_SUPPORTED_DEVICE("{{OPTi,82C931/3}}"); | |
51 | #else /* OPTi93X */ | |
52 | #ifdef CS4231 | |
53 | MODULE_DESCRIPTION("OPTi92X - CS4231"); | |
54 | MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (CS4231)}," | |
55 | "{OPTi,82C925 (CS4231)}}"); | |
56 | #else /* CS4231 */ | |
57 | MODULE_DESCRIPTION("OPTi92X - AD1848"); | |
58 | MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (AD1848)}," | |
59 | "{OPTi,82C925 (AD1848)}," | |
60 | "{OAK,Mozart}}"); | |
61 | #endif /* CS4231 */ | |
62 | #endif /* OPTi93X */ | |
63 | ||
64 | static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ | |
65 | static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ | |
66 | //static int enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */ | |
51f6baad | 67 | #ifdef CONFIG_PNP |
1da177e4 | 68 | static int isapnp = 1; /* Enable ISA PnP detection */ |
51f6baad | 69 | #endif |
1da177e4 LT |
70 | static long port = SNDRV_DEFAULT_PORT1; /* 0x530,0xe80,0xf40,0x604 */ |
71 | static long mpu_port = SNDRV_DEFAULT_PORT1; /* 0x300,0x310,0x320,0x330 */ | |
72 | static long fm_port = SNDRV_DEFAULT_PORT1; /* 0x388 */ | |
73 | static int irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10,11 */ | |
74 | static int mpu_irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10 */ | |
75 | static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */ | |
76 | #if defined(CS4231) || defined(OPTi93X) | |
77 | static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */ | |
78 | #endif /* CS4231 || OPTi93X */ | |
79 | ||
80 | module_param(index, int, 0444); | |
81 | MODULE_PARM_DESC(index, "Index value for opti9xx based soundcard."); | |
82 | module_param(id, charp, 0444); | |
83 | MODULE_PARM_DESC(id, "ID string for opti9xx based soundcard."); | |
84 | //module_param(enable, bool, 0444); | |
85 | //MODULE_PARM_DESC(enable, "Enable opti9xx soundcard."); | |
51f6baad | 86 | #ifdef CONFIG_PNP |
1da177e4 LT |
87 | module_param(isapnp, bool, 0444); |
88 | MODULE_PARM_DESC(isapnp, "Enable ISA PnP detection for specified soundcard."); | |
51f6baad | 89 | #endif |
1da177e4 LT |
90 | module_param(port, long, 0444); |
91 | MODULE_PARM_DESC(port, "WSS port # for opti9xx driver."); | |
92 | module_param(mpu_port, long, 0444); | |
93 | MODULE_PARM_DESC(mpu_port, "MPU-401 port # for opti9xx driver."); | |
94 | module_param(fm_port, long, 0444); | |
95 | MODULE_PARM_DESC(fm_port, "FM port # for opti9xx driver."); | |
96 | module_param(irq, int, 0444); | |
97 | MODULE_PARM_DESC(irq, "WSS irq # for opti9xx driver."); | |
98 | module_param(mpu_irq, int, 0444); | |
99 | MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for opti9xx driver."); | |
100 | module_param(dma1, int, 0444); | |
101 | MODULE_PARM_DESC(dma1, "1st dma # for opti9xx driver."); | |
102 | #if defined(CS4231) || defined(OPTi93X) | |
103 | module_param(dma2, int, 0444); | |
104 | MODULE_PARM_DESC(dma2, "2nd dma # for opti9xx driver."); | |
105 | #endif /* CS4231 || OPTi93X */ | |
106 | ||
1da177e4 LT |
107 | #define OPTi9XX_HW_82C928 1 |
108 | #define OPTi9XX_HW_82C929 2 | |
109 | #define OPTi9XX_HW_82C924 3 | |
110 | #define OPTi9XX_HW_82C925 4 | |
111 | #define OPTi9XX_HW_82C930 5 | |
112 | #define OPTi9XX_HW_82C931 6 | |
113 | #define OPTi9XX_HW_82C933 7 | |
114 | #define OPTi9XX_HW_LAST OPTi9XX_HW_82C933 | |
115 | ||
116 | #define OPTi9XX_MC_REG(n) n | |
117 | ||
1da177e4 LT |
118 | #ifdef OPTi93X |
119 | ||
1da177e4 | 120 | #define OPTi93X_STATUS 0x02 |
1da177e4 LT |
121 | #define OPTi93X_PORT(chip, r) ((chip)->port + OPTi93X_##r) |
122 | ||
1da177e4 LT |
123 | #define OPTi93X_IRQ_PLAYBACK 0x04 |
124 | #define OPTi93X_IRQ_CAPTURE 0x08 | |
125 | ||
1da177e4 LT |
126 | #endif /* OPTi93X */ |
127 | ||
346c7a68 | 128 | struct snd_opti9xx { |
1da177e4 LT |
129 | unsigned short hardware; |
130 | unsigned char password; | |
131 | char name[7]; | |
132 | ||
133 | unsigned long mc_base; | |
134 | struct resource *res_mc_base; | |
135 | unsigned long mc_base_size; | |
136 | #ifdef OPTi93X | |
137 | unsigned long mc_indir_index; | |
7779f75f | 138 | struct snd_wss *codec; |
1da177e4 LT |
139 | #endif /* OPTi93X */ |
140 | unsigned long pwd_reg; | |
141 | ||
142 | spinlock_t lock; | |
143 | ||
144 | long wss_base; | |
145 | int irq; | |
146 | int dma1; | |
1da177e4 | 147 | int dma2; |
1da177e4 LT |
148 | |
149 | long fm_port; | |
150 | ||
151 | long mpu_port; | |
152 | int mpu_irq; | |
153 | ||
154 | #ifdef CONFIG_PNP | |
155 | struct pnp_dev *dev; | |
156 | struct pnp_dev *devmpu; | |
157 | #endif /* CONFIG_PNP */ | |
158 | }; | |
159 | ||
99a0b768 | 160 | static int snd_opti9xx_pnp_is_probed; |
1da177e4 LT |
161 | |
162 | #ifdef CONFIG_PNP | |
163 | ||
164 | static struct pnp_card_device_id snd_opti9xx_pnpids[] = { | |
165 | #ifndef OPTi93X | |
166 | /* OPTi 82C924 */ | |
167 | { .id = "OPT0924", .devs = { { "OPT0000" }, { "OPT0002" } }, .driver_data = 0x0924 }, | |
168 | /* OPTi 82C925 */ | |
169 | { .id = "OPT0925", .devs = { { "OPT9250" }, { "OPT0002" } }, .driver_data = 0x0925 }, | |
170 | #else | |
171 | /* OPTi 82C931/3 */ | |
172 | { .id = "OPT0931", .devs = { { "OPT9310" }, { "OPT0002" } }, .driver_data = 0x0931 }, | |
173 | #endif /* OPTi93X */ | |
174 | { .id = "" } | |
175 | }; | |
176 | ||
177 | MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids); | |
178 | ||
179 | #endif /* CONFIG_PNP */ | |
180 | ||
181 | #ifdef OPTi93X | |
83c51c0a | 182 | #define DEV_NAME "opti93x" |
1da177e4 | 183 | #else |
83c51c0a RH |
184 | #define DEV_NAME "opti92x" |
185 | #endif | |
1da177e4 LT |
186 | |
187 | static char * snd_opti9xx_names[] = { | |
188 | "unkown", | |
189 | "82C928", "82C929", | |
190 | "82C924", "82C925", | |
191 | "82C930", "82C931", "82C933" | |
192 | }; | |
193 | ||
194 | ||
5e24c1c1 | 195 | static long __devinit snd_legacy_find_free_ioport(long *port_table, long size) |
1da177e4 LT |
196 | { |
197 | while (*port_table != -1) { | |
b1d5776d TI |
198 | if (request_region(*port_table, size, "ALSA test")) { |
199 | release_region(*port_table, size); | |
1da177e4 LT |
200 | return *port_table; |
201 | } | |
202 | port_table++; | |
203 | } | |
204 | return -1; | |
205 | } | |
206 | ||
5e24c1c1 TI |
207 | static int __devinit snd_opti9xx_init(struct snd_opti9xx *chip, |
208 | unsigned short hardware) | |
1da177e4 LT |
209 | { |
210 | static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2}; | |
211 | ||
212 | chip->hardware = hardware; | |
213 | strcpy(chip->name, snd_opti9xx_names[hardware]); | |
214 | ||
215 | chip->mc_base_size = opti9xx_mc_size[hardware]; | |
216 | ||
217 | spin_lock_init(&chip->lock); | |
218 | ||
219 | chip->wss_base = -1; | |
220 | chip->irq = -1; | |
221 | chip->dma1 = -1; | |
1da177e4 | 222 | chip->dma2 = -1; |
1da177e4 LT |
223 | chip->fm_port = -1; |
224 | chip->mpu_port = -1; | |
225 | chip->mpu_irq = -1; | |
226 | ||
227 | switch (hardware) { | |
228 | #ifndef OPTi93X | |
229 | case OPTi9XX_HW_82C928: | |
230 | case OPTi9XX_HW_82C929: | |
231 | chip->mc_base = 0xf8c; | |
232 | chip->password = (hardware == OPTi9XX_HW_82C928) ? 0xe2 : 0xe3; | |
233 | chip->pwd_reg = 3; | |
234 | break; | |
235 | ||
236 | case OPTi9XX_HW_82C924: | |
237 | case OPTi9XX_HW_82C925: | |
238 | chip->mc_base = 0xf8c; | |
239 | chip->password = 0xe5; | |
240 | chip->pwd_reg = 3; | |
241 | break; | |
242 | #else /* OPTi93X */ | |
243 | ||
244 | case OPTi9XX_HW_82C930: | |
245 | case OPTi9XX_HW_82C931: | |
246 | case OPTi9XX_HW_82C933: | |
247 | chip->mc_base = (hardware == OPTi9XX_HW_82C930) ? 0xf8f : 0xf8d; | |
248 | chip->mc_indir_index = 0xe0e; | |
249 | chip->password = 0xe4; | |
250 | chip->pwd_reg = 0; | |
251 | break; | |
252 | #endif /* OPTi93X */ | |
253 | ||
254 | default: | |
255 | snd_printk("chip %d not supported\n", hardware); | |
256 | return -ENODEV; | |
257 | } | |
258 | return 0; | |
259 | } | |
260 | ||
346c7a68 | 261 | static unsigned char snd_opti9xx_read(struct snd_opti9xx *chip, |
1da177e4 LT |
262 | unsigned char reg) |
263 | { | |
264 | unsigned long flags; | |
265 | unsigned char retval = 0xff; | |
266 | ||
267 | spin_lock_irqsave(&chip->lock, flags); | |
268 | outb(chip->password, chip->mc_base + chip->pwd_reg); | |
269 | ||
270 | switch (chip->hardware) { | |
271 | #ifndef OPTi93X | |
272 | case OPTi9XX_HW_82C924: | |
273 | case OPTi9XX_HW_82C925: | |
274 | if (reg > 7) { | |
275 | outb(reg, chip->mc_base + 8); | |
276 | outb(chip->password, chip->mc_base + chip->pwd_reg); | |
277 | retval = inb(chip->mc_base + 9); | |
278 | break; | |
279 | } | |
280 | ||
281 | case OPTi9XX_HW_82C928: | |
282 | case OPTi9XX_HW_82C929: | |
283 | retval = inb(chip->mc_base + reg); | |
284 | break; | |
285 | #else /* OPTi93X */ | |
286 | ||
287 | case OPTi9XX_HW_82C930: | |
288 | case OPTi9XX_HW_82C931: | |
289 | case OPTi9XX_HW_82C933: | |
290 | outb(reg, chip->mc_indir_index); | |
291 | outb(chip->password, chip->mc_base + chip->pwd_reg); | |
292 | retval = inb(chip->mc_indir_index + 1); | |
293 | break; | |
294 | #endif /* OPTi93X */ | |
295 | ||
296 | default: | |
297 | snd_printk("chip %d not supported\n", chip->hardware); | |
298 | } | |
299 | ||
300 | spin_unlock_irqrestore(&chip->lock, flags); | |
301 | return retval; | |
302 | } | |
303 | ||
346c7a68 | 304 | static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg, |
1da177e4 LT |
305 | unsigned char value) |
306 | { | |
307 | unsigned long flags; | |
308 | ||
309 | spin_lock_irqsave(&chip->lock, flags); | |
310 | outb(chip->password, chip->mc_base + chip->pwd_reg); | |
311 | ||
312 | switch (chip->hardware) { | |
313 | #ifndef OPTi93X | |
314 | case OPTi9XX_HW_82C924: | |
315 | case OPTi9XX_HW_82C925: | |
316 | if (reg > 7) { | |
317 | outb(reg, chip->mc_base + 8); | |
318 | outb(chip->password, chip->mc_base + chip->pwd_reg); | |
319 | outb(value, chip->mc_base + 9); | |
320 | break; | |
321 | } | |
322 | ||
323 | case OPTi9XX_HW_82C928: | |
324 | case OPTi9XX_HW_82C929: | |
325 | outb(value, chip->mc_base + reg); | |
326 | break; | |
327 | #else /* OPTi93X */ | |
328 | ||
329 | case OPTi9XX_HW_82C930: | |
330 | case OPTi9XX_HW_82C931: | |
331 | case OPTi9XX_HW_82C933: | |
332 | outb(reg, chip->mc_indir_index); | |
333 | outb(chip->password, chip->mc_base + chip->pwd_reg); | |
334 | outb(value, chip->mc_indir_index + 1); | |
335 | break; | |
336 | #endif /* OPTi93X */ | |
337 | ||
338 | default: | |
339 | snd_printk("chip %d not supported\n", chip->hardware); | |
340 | } | |
341 | ||
342 | spin_unlock_irqrestore(&chip->lock, flags); | |
343 | } | |
344 | ||
345 | ||
346 | #define snd_opti9xx_write_mask(chip, reg, value, mask) \ | |
347 | snd_opti9xx_write(chip, reg, \ | |
348 | (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask))) | |
349 | ||
350 | ||
5e24c1c1 | 351 | static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip) |
1da177e4 LT |
352 | { |
353 | unsigned char wss_base_bits; | |
354 | unsigned char irq_bits; | |
355 | unsigned char dma_bits; | |
356 | unsigned char mpu_port_bits = 0; | |
357 | unsigned char mpu_irq_bits; | |
358 | ||
359 | switch (chip->hardware) { | |
360 | #ifndef OPTi93X | |
361 | case OPTi9XX_HW_82C924: | |
362 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0xf0, 0xfc); | |
363 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02); | |
364 | ||
365 | case OPTi9XX_HW_82C925: | |
366 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80); | |
367 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20); | |
368 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff); | |
369 | #ifdef CS4231 | |
370 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02); | |
371 | #else | |
372 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02); | |
373 | #endif /* CS4231 */ | |
374 | break; | |
375 | ||
376 | case OPTi9XX_HW_82C928: | |
377 | case OPTi9XX_HW_82C929: | |
378 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80); | |
379 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20); | |
380 | /* | |
381 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xa2, 0xae); | |
382 | */ | |
383 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c); | |
384 | #ifdef CS4231 | |
385 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02); | |
386 | #else | |
387 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02); | |
388 | #endif /* CS4231 */ | |
389 | break; | |
390 | ||
391 | #else /* OPTi93X */ | |
1da177e4 LT |
392 | case OPTi9XX_HW_82C931: |
393 | case OPTi9XX_HW_82C933: | |
3ae5f36a | 394 | /* |
f81b953d KH |
395 | * The BTC 1817DW has QS1000 wavetable which is connected |
396 | * to the serial digital input of the OPTI931. | |
397 | */ | |
398 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(21), 0x82, 0xff); | |
399 | /* | |
400 | * This bit sets OPTI931 to automaticaly select FM | |
401 | * or digital input signal. | |
402 | */ | |
403 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(26), 0x01, 0x01); | |
3ae5f36a KH |
404 | case OPTi9XX_HW_82C930: /* FALL THROUGH */ |
405 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x03); | |
406 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0x00, 0xff); | |
407 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x10 | | |
408 | (chip->hardware == OPTi9XX_HW_82C930 ? 0x00 : 0x04), | |
409 | 0x34); | |
410 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x20, 0xbf); | |
1da177e4 LT |
411 | break; |
412 | #endif /* OPTi93X */ | |
413 | ||
414 | default: | |
415 | snd_printk("chip %d not supported\n", chip->hardware); | |
416 | return -EINVAL; | |
417 | } | |
418 | ||
419 | switch (chip->wss_base) { | |
420 | case 0x530: | |
421 | wss_base_bits = 0x00; | |
422 | break; | |
423 | case 0x604: | |
424 | wss_base_bits = 0x03; | |
425 | break; | |
426 | case 0xe80: | |
427 | wss_base_bits = 0x01; | |
428 | break; | |
429 | case 0xf40: | |
430 | wss_base_bits = 0x02; | |
431 | break; | |
432 | default: | |
433 | snd_printk("WSS port 0x%lx not valid\n", chip->wss_base); | |
434 | goto __skip_base; | |
435 | } | |
436 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30); | |
437 | ||
438 | __skip_base: | |
439 | switch (chip->irq) { | |
440 | //#ifdef OPTi93X | |
441 | case 5: | |
442 | irq_bits = 0x05; | |
443 | break; | |
444 | //#endif /* OPTi93X */ | |
445 | case 7: | |
446 | irq_bits = 0x01; | |
447 | break; | |
448 | case 9: | |
449 | irq_bits = 0x02; | |
450 | break; | |
451 | case 10: | |
452 | irq_bits = 0x03; | |
453 | break; | |
454 | case 11: | |
455 | irq_bits = 0x04; | |
456 | break; | |
457 | default: | |
458 | snd_printk("WSS irq # %d not valid\n", chip->irq); | |
459 | goto __skip_resources; | |
460 | } | |
461 | ||
462 | switch (chip->dma1) { | |
463 | case 0: | |
464 | dma_bits = 0x01; | |
465 | break; | |
466 | case 1: | |
467 | dma_bits = 0x02; | |
468 | break; | |
469 | case 3: | |
470 | dma_bits = 0x03; | |
471 | break; | |
472 | default: | |
473 | snd_printk("WSS dma1 # %d not valid\n", chip->dma1); | |
474 | goto __skip_resources; | |
475 | } | |
476 | ||
477 | #if defined(CS4231) || defined(OPTi93X) | |
478 | if (chip->dma1 == chip->dma2) { | |
479 | snd_printk("don't want to share dmas\n"); | |
480 | return -EBUSY; | |
481 | } | |
482 | ||
483 | switch (chip->dma2) { | |
484 | case 0: | |
485 | case 1: | |
486 | break; | |
487 | default: | |
488 | snd_printk("WSS dma2 # %d not valid\n", chip->dma2); | |
489 | goto __skip_resources; | |
490 | } | |
491 | dma_bits |= 0x04; | |
492 | #endif /* CS4231 || OPTi93X */ | |
493 | ||
494 | #ifndef OPTi93X | |
495 | outb(irq_bits << 3 | dma_bits, chip->wss_base); | |
496 | #else /* OPTi93X */ | |
497 | snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits)); | |
498 | #endif /* OPTi93X */ | |
499 | ||
500 | __skip_resources: | |
501 | if (chip->hardware > OPTi9XX_HW_82C928) { | |
502 | switch (chip->mpu_port) { | |
503 | case 0: | |
504 | case -1: | |
505 | break; | |
506 | case 0x300: | |
507 | mpu_port_bits = 0x03; | |
508 | break; | |
509 | case 0x310: | |
510 | mpu_port_bits = 0x02; | |
511 | break; | |
512 | case 0x320: | |
513 | mpu_port_bits = 0x01; | |
514 | break; | |
515 | case 0x330: | |
516 | mpu_port_bits = 0x00; | |
517 | break; | |
518 | default: | |
519 | snd_printk("MPU-401 port 0x%lx not valid\n", | |
520 | chip->mpu_port); | |
521 | goto __skip_mpu; | |
522 | } | |
523 | ||
524 | switch (chip->mpu_irq) { | |
525 | case 5: | |
526 | mpu_irq_bits = 0x02; | |
527 | break; | |
528 | case 7: | |
529 | mpu_irq_bits = 0x03; | |
530 | break; | |
531 | case 9: | |
532 | mpu_irq_bits = 0x00; | |
533 | break; | |
534 | case 10: | |
535 | mpu_irq_bits = 0x01; | |
536 | break; | |
537 | default: | |
538 | snd_printk("MPU-401 irq # %d not valid\n", | |
539 | chip->mpu_irq); | |
540 | goto __skip_mpu; | |
541 | } | |
542 | ||
543 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), | |
544 | (chip->mpu_port <= 0) ? 0x00 : | |
545 | 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3, | |
546 | 0xf8); | |
547 | } | |
548 | __skip_mpu: | |
549 | ||
550 | return 0; | |
551 | } | |
552 | ||
553 | #ifdef OPTi93X | |
554 | ||
7d12e780 | 555 | static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id) |
1da177e4 | 556 | { |
7779f75f | 557 | struct snd_wss *codec = dev_id; |
9f240a55 | 558 | struct snd_opti9xx *chip = codec->card->private_data; |
1da177e4 LT |
559 | unsigned char status; |
560 | ||
9f240a55 | 561 | status = snd_opti9xx_read(chip, OPTi9XX_MC_REG(11)); |
1da177e4 LT |
562 | if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream) |
563 | snd_pcm_period_elapsed(codec->playback_substream); | |
564 | if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) { | |
7779f75f | 565 | snd_wss_overrange(codec); |
1da177e4 LT |
566 | snd_pcm_period_elapsed(codec->capture_substream); |
567 | } | |
568 | outb(0x00, OPTi93X_PORT(codec, STATUS)); | |
569 | return IRQ_HANDLED; | |
570 | } | |
571 | ||
1da177e4 LT |
572 | #endif /* OPTi93X */ |
573 | ||
5e24c1c1 TI |
574 | static int __devinit snd_card_opti9xx_detect(struct snd_card *card, |
575 | struct snd_opti9xx *chip) | |
1da177e4 LT |
576 | { |
577 | int i, err; | |
578 | ||
579 | #ifndef OPTi93X | |
580 | for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) { | |
581 | unsigned char value; | |
582 | ||
583 | if ((err = snd_opti9xx_init(chip, i)) < 0) | |
584 | return err; | |
585 | ||
586 | if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) | |
587 | continue; | |
588 | ||
589 | value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)); | |
590 | if ((value != 0xff) && (value != inb(chip->mc_base + 1))) | |
591 | if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1))) | |
592 | return 1; | |
593 | ||
b1d5776d | 594 | release_and_free_resource(chip->res_mc_base); |
1da177e4 LT |
595 | chip->res_mc_base = NULL; |
596 | ||
597 | } | |
598 | #else /* OPTi93X */ | |
599 | for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) { | |
600 | unsigned long flags; | |
601 | unsigned char value; | |
602 | ||
603 | if ((err = snd_opti9xx_init(chip, i)) < 0) | |
604 | return err; | |
605 | ||
606 | if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) | |
607 | continue; | |
608 | ||
609 | spin_lock_irqsave(&chip->lock, flags); | |
610 | outb(chip->password, chip->mc_base + chip->pwd_reg); | |
611 | outb(((chip->mc_indir_index & (1 << 8)) >> 4) | | |
612 | ((chip->mc_indir_index & 0xf0) >> 4), chip->mc_base); | |
613 | spin_unlock_irqrestore(&chip->lock, flags); | |
614 | ||
615 | value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)); | |
616 | snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value); | |
617 | if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value) | |
618 | return 1; | |
619 | ||
b1d5776d | 620 | release_and_free_resource(chip->res_mc_base); |
1da177e4 LT |
621 | chip->res_mc_base = NULL; |
622 | } | |
623 | #endif /* OPTi93X */ | |
624 | ||
625 | return -ENODEV; | |
626 | } | |
627 | ||
628 | #ifdef CONFIG_PNP | |
5e24c1c1 TI |
629 | static int __devinit snd_card_opti9xx_pnp(struct snd_opti9xx *chip, |
630 | struct pnp_card_link *card, | |
631 | const struct pnp_card_device_id *pid) | |
1da177e4 LT |
632 | { |
633 | struct pnp_dev *pdev; | |
1da177e4 LT |
634 | int err; |
635 | ||
636 | chip->dev = pnp_request_card_device(card, pid->devs[0].id, NULL); | |
109c53f8 | 637 | if (chip->dev == NULL) |
1da177e4 | 638 | return -EBUSY; |
109c53f8 | 639 | |
1da177e4 LT |
640 | chip->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL); |
641 | ||
642 | pdev = chip->dev; | |
1da177e4 | 643 | |
1da177e4 LT |
644 | err = pnp_activate_dev(pdev); |
645 | if (err < 0) { | |
646 | snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err); | |
1da177e4 LT |
647 | return err; |
648 | } | |
649 | ||
650 | #ifdef OPTi93X | |
651 | port = pnp_port_start(pdev, 0) - 4; | |
1ea73412 | 652 | fm_port = pnp_port_start(pdev, 1) + 8; |
1da177e4 LT |
653 | #else |
654 | if (pid->driver_data != 0x0924) | |
655 | port = pnp_port_start(pdev, 1); | |
1ea73412 | 656 | fm_port = pnp_port_start(pdev, 2) + 8; |
1da177e4 LT |
657 | #endif /* OPTi93X */ |
658 | irq = pnp_irq(pdev, 0); | |
659 | dma1 = pnp_dma(pdev, 0); | |
660 | #if defined(CS4231) || defined(OPTi93X) | |
661 | dma2 = pnp_dma(pdev, 1); | |
662 | #endif /* CS4231 || OPTi93X */ | |
663 | ||
664 | pdev = chip->devmpu; | |
665 | if (pdev && mpu_port > 0) { | |
1da177e4 LT |
666 | err = pnp_activate_dev(pdev); |
667 | if (err < 0) { | |
668 | snd_printk(KERN_ERR "AUDIO pnp configure failure\n"); | |
669 | mpu_port = -1; | |
670 | chip->devmpu = NULL; | |
671 | } else { | |
672 | mpu_port = pnp_port_start(pdev, 0); | |
673 | mpu_irq = pnp_irq(pdev, 0); | |
674 | } | |
675 | } | |
1da177e4 LT |
676 | return pid->driver_data; |
677 | } | |
678 | #endif /* CONFIG_PNP */ | |
679 | ||
346c7a68 | 680 | static void snd_card_opti9xx_free(struct snd_card *card) |
1da177e4 | 681 | { |
99a0b768 | 682 | struct snd_opti9xx *chip = card->private_data; |
1da177e4 | 683 | |
9f240a55 KH |
684 | if (chip) { |
685 | #ifdef OPTi93X | |
7779f75f | 686 | struct snd_wss *codec = chip->codec; |
82af6bc0 | 687 | if (codec && codec->irq > 0) { |
9f240a55 KH |
688 | disable_irq(codec->irq); |
689 | free_irq(codec->irq, codec); | |
690 | } | |
691 | #endif | |
b1d5776d | 692 | release_and_free_resource(chip->res_mc_base); |
9f240a55 | 693 | } |
1da177e4 LT |
694 | } |
695 | ||
5e24c1c1 | 696 | static int __devinit snd_opti9xx_probe(struct snd_card *card) |
1da177e4 LT |
697 | { |
698 | static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1}; | |
1da177e4 | 699 | int error; |
99a0b768 | 700 | struct snd_opti9xx *chip = card->private_data; |
7779f75f | 701 | struct snd_wss *codec; |
9f240a55 | 702 | #ifdef CS4231 |
346c7a68 | 703 | struct snd_timer *timer; |
1da177e4 | 704 | #endif |
346c7a68 TI |
705 | struct snd_pcm *pcm; |
706 | struct snd_rawmidi *rmidi; | |
707 | struct snd_hwdep *synth; | |
1da177e4 LT |
708 | |
709 | if (! chip->res_mc_base && | |
99a0b768 TI |
710 | (chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, |
711 | "OPTi9xx MC")) == NULL) | |
1da177e4 | 712 | return -ENOMEM; |
1da177e4 LT |
713 | |
714 | chip->wss_base = port; | |
715 | chip->fm_port = fm_port; | |
716 | chip->mpu_port = mpu_port; | |
717 | chip->irq = irq; | |
718 | chip->mpu_irq = mpu_irq; | |
719 | chip->dma1 = dma1; | |
720 | #if defined(CS4231) || defined(OPTi93X) | |
721 | chip->dma2 = dma2; | |
a0d9274c RH |
722 | #else |
723 | chip->dma2 = -1; | |
1da177e4 LT |
724 | #endif |
725 | ||
726 | if (chip->wss_base == SNDRV_AUTO_PORT) { | |
7779f75f KH |
727 | chip->wss_base = snd_legacy_find_free_ioport(possible_ports, 4); |
728 | if (chip->wss_base < 0) { | |
1da177e4 LT |
729 | snd_printk("unable to find a free WSS port\n"); |
730 | return -EBUSY; | |
731 | } | |
732 | } | |
7779f75f KH |
733 | error = snd_opti9xx_configure(chip); |
734 | if (error) | |
1da177e4 | 735 | return error; |
1da177e4 | 736 | |
7779f75f KH |
737 | error = snd_wss_create(card, chip->wss_base + 4, -1, |
738 | chip->irq, chip->dma1, chip->dma2, | |
a0d9274c | 739 | #ifdef OPTi93X |
7779f75f | 740 | WSS_HW_OPTI93X, WSS_HWSHARE_IRQ, |
a0d9274c RH |
741 | #else |
742 | WSS_HW_DETECT, 0, | |
9f240a55 | 743 | #endif |
7779f75f KH |
744 | &codec); |
745 | if (error < 0) | |
1da177e4 | 746 | return error; |
9f240a55 KH |
747 | #ifdef OPTi93X |
748 | chip->codec = codec; | |
ead893c0 KH |
749 | #endif |
750 | error = snd_wss_pcm(codec, 0, &pcm); | |
5664daa1 KH |
751 | if (error < 0) |
752 | return error; | |
7779f75f KH |
753 | error = snd_wss_mixer(codec); |
754 | if (error < 0) | |
1da177e4 | 755 | return error; |
9f240a55 | 756 | #ifdef CS4231 |
7779f75f KH |
757 | error = snd_wss_timer(codec, 0, &timer); |
758 | if (error < 0) | |
1da177e4 | 759 | return error; |
5664daa1 KH |
760 | #endif |
761 | #ifdef OPTi93X | |
9f240a55 KH |
762 | error = request_irq(chip->irq, snd_opti93x_interrupt, |
763 | IRQF_DISABLED, DEV_NAME" - WSS", codec); | |
764 | if (error < 0) { | |
765 | snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", chip->irq); | |
766 | return error; | |
767 | } | |
1da177e4 LT |
768 | #endif |
769 | strcpy(card->driver, chip->name); | |
770 | sprintf(card->shortname, "OPTi %s", card->driver); | |
771 | #if defined(CS4231) || defined(OPTi93X) | |
772 | sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d", | |
773 | card->shortname, pcm->name, chip->wss_base + 4, | |
774 | chip->irq, chip->dma1, chip->dma2); | |
775 | #else | |
776 | sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d", | |
777 | card->shortname, pcm->name, chip->wss_base + 4, | |
778 | chip->irq, chip->dma1); | |
779 | #endif /* CS4231 || OPTi93X */ | |
780 | ||
781 | if (chip->mpu_port <= 0 || chip->mpu_port == SNDRV_AUTO_PORT) | |
782 | rmidi = NULL; | |
783 | else | |
784 | if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, | |
65ca68b3 | 785 | chip->mpu_port, 0, chip->mpu_irq, IRQF_DISABLED, |
1da177e4 | 786 | &rmidi))) |
99a0b768 TI |
787 | snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", |
788 | chip->mpu_port); | |
1da177e4 LT |
789 | |
790 | if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) { | |
346c7a68 | 791 | struct snd_opl3 *opl3 = NULL; |
1da177e4 LT |
792 | #ifndef OPTi93X |
793 | if (chip->hardware == OPTi9XX_HW_82C928 || | |
794 | chip->hardware == OPTi9XX_HW_82C929 || | |
795 | chip->hardware == OPTi9XX_HW_82C924) { | |
346c7a68 | 796 | struct snd_opl4 *opl4; |
1da177e4 LT |
797 | /* assume we have an OPL4 */ |
798 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), | |
799 | 0x20, 0x20); | |
800 | if (snd_opl4_create(card, | |
801 | chip->fm_port, | |
802 | chip->fm_port - 8, | |
803 | 2, &opl3, &opl4) < 0) { | |
804 | /* no luck, use OPL3 instead */ | |
805 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), | |
806 | 0x00, 0x20); | |
807 | } | |
808 | } | |
809 | #endif /* !OPTi93X */ | |
810 | if (!opl3 && snd_opl3_create(card, | |
811 | chip->fm_port, | |
812 | chip->fm_port + 2, | |
813 | OPL3_HW_AUTO, 0, &opl3) < 0) { | |
99a0b768 | 814 | snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n", |
1da177e4 LT |
815 | chip->fm_port, chip->fm_port + 4 - 1); |
816 | } | |
817 | if (opl3) { | |
1da177e4 | 818 | #ifdef CS4231 |
99a0b768 | 819 | const int t1dev = 1; |
1da177e4 | 820 | #else |
99a0b768 TI |
821 | const int t1dev = 0; |
822 | #endif | |
823 | if ((error = snd_opl3_timer_new(opl3, t1dev, t1dev+1)) < 0) | |
1da177e4 | 824 | return error; |
99a0b768 | 825 | if ((error = snd_opl3_hwdep_new(opl3, 0, 1, &synth)) < 0) |
1da177e4 | 826 | return error; |
1da177e4 LT |
827 | } |
828 | } | |
829 | ||
99a0b768 TI |
830 | return snd_card_register(card); |
831 | } | |
832 | ||
833 | static struct snd_card *snd_opti9xx_card_new(void) | |
834 | { | |
835 | struct snd_card *card; | |
c95eadd2 | 836 | int err; |
99a0b768 | 837 | |
c95eadd2 TI |
838 | err = snd_card_create(index, id, THIS_MODULE, |
839 | sizeof(struct snd_opti9xx), &card); | |
840 | if (err < 0) | |
99a0b768 TI |
841 | return NULL; |
842 | card->private_free = snd_card_opti9xx_free; | |
843 | return card; | |
844 | } | |
845 | ||
5e24c1c1 TI |
846 | static int __devinit snd_opti9xx_isa_match(struct device *devptr, |
847 | unsigned int dev) | |
848 | { | |
101f6f4b | 849 | #ifdef CONFIG_PNP |
5e24c1c1 TI |
850 | if (snd_opti9xx_pnp_is_probed) |
851 | return 0; | |
852 | if (isapnp) | |
853 | return 0; | |
101f6f4b | 854 | #endif |
5e24c1c1 TI |
855 | return 1; |
856 | } | |
857 | ||
858 | static int __devinit snd_opti9xx_isa_probe(struct device *devptr, | |
859 | unsigned int dev) | |
99a0b768 TI |
860 | { |
861 | struct snd_card *card; | |
862 | int error; | |
863 | static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1}; | |
864 | #ifdef OPTi93X | |
865 | static int possible_irqs[] = {5, 9, 10, 11, 7, -1}; | |
866 | #else | |
867 | static int possible_irqs[] = {9, 10, 11, 7, -1}; | |
868 | #endif /* OPTi93X */ | |
869 | static int possible_mpu_irqs[] = {5, 9, 10, 7, -1}; | |
870 | static int possible_dma1s[] = {3, 1, 0, -1}; | |
871 | #if defined(CS4231) || defined(OPTi93X) | |
872 | static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}}; | |
873 | #endif /* CS4231 || OPTi93X */ | |
874 | ||
99a0b768 TI |
875 | if (mpu_port == SNDRV_AUTO_PORT) { |
876 | if ((mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) { | |
877 | snd_printk(KERN_ERR "unable to find a free MPU401 port\n"); | |
878 | return -EBUSY; | |
879 | } | |
880 | } | |
881 | if (irq == SNDRV_AUTO_IRQ) { | |
882 | if ((irq = snd_legacy_find_free_irq(possible_irqs)) < 0) { | |
883 | snd_printk(KERN_ERR "unable to find a free IRQ\n"); | |
884 | return -EBUSY; | |
885 | } | |
886 | } | |
887 | if (mpu_irq == SNDRV_AUTO_IRQ) { | |
888 | if ((mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) { | |
889 | snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n"); | |
890 | return -EBUSY; | |
891 | } | |
892 | } | |
893 | if (dma1 == SNDRV_AUTO_DMA) { | |
894 | if ((dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) { | |
895 | snd_printk(KERN_ERR "unable to find a free DMA1\n"); | |
896 | return -EBUSY; | |
897 | } | |
898 | } | |
899 | #if defined(CS4231) || defined(OPTi93X) | |
900 | if (dma2 == SNDRV_AUTO_DMA) { | |
901 | if ((dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4])) < 0) { | |
902 | snd_printk("unable to find a free DMA2\n"); | |
903 | return -EBUSY; | |
904 | } | |
905 | } | |
906 | #endif | |
907 | ||
908 | card = snd_opti9xx_card_new(); | |
909 | if (! card) | |
910 | return -ENOMEM; | |
911 | ||
912 | if ((error = snd_card_opti9xx_detect(card, card->private_data)) < 0) { | |
1da177e4 LT |
913 | snd_card_free(card); |
914 | return error; | |
915 | } | |
5e24c1c1 | 916 | snd_card_set_dev(card, devptr); |
99a0b768 TI |
917 | if ((error = snd_opti9xx_probe(card)) < 0) { |
918 | snd_card_free(card); | |
919 | return error; | |
920 | } | |
5e24c1c1 | 921 | dev_set_drvdata(devptr, card); |
99a0b768 TI |
922 | return 0; |
923 | } | |
924 | ||
5e24c1c1 TI |
925 | static int __devexit snd_opti9xx_isa_remove(struct device *devptr, |
926 | unsigned int dev) | |
99a0b768 | 927 | { |
5e24c1c1 TI |
928 | snd_card_free(dev_get_drvdata(devptr)); |
929 | dev_set_drvdata(devptr, NULL); | |
1da177e4 LT |
930 | return 0; |
931 | } | |
932 | ||
5e24c1c1 TI |
933 | static struct isa_driver snd_opti9xx_driver = { |
934 | .match = snd_opti9xx_isa_match, | |
935 | .probe = snd_opti9xx_isa_probe, | |
936 | .remove = __devexit_p(snd_opti9xx_isa_remove), | |
99a0b768 TI |
937 | /* FIXME: suspend/resume */ |
938 | .driver = { | |
83c51c0a | 939 | .name = DEV_NAME |
99a0b768 TI |
940 | }, |
941 | }; | |
942 | ||
1da177e4 | 943 | #ifdef CONFIG_PNP |
5e24c1c1 TI |
944 | static int __devinit snd_opti9xx_pnp_probe(struct pnp_card_link *pcard, |
945 | const struct pnp_card_device_id *pid) | |
1da177e4 | 946 | { |
99a0b768 TI |
947 | struct snd_card *card; |
948 | int error, hw; | |
949 | struct snd_opti9xx *chip; | |
950 | ||
951 | if (snd_opti9xx_pnp_is_probed) | |
952 | return -EBUSY; | |
953 | if (! isapnp) | |
954 | return -ENODEV; | |
955 | card = snd_opti9xx_card_new(); | |
956 | if (! card) | |
957 | return -ENOMEM; | |
958 | chip = card->private_data; | |
1da177e4 | 959 | |
99a0b768 TI |
960 | hw = snd_card_opti9xx_pnp(chip, pcard, pid); |
961 | switch (hw) { | |
962 | case 0x0924: | |
963 | hw = OPTi9XX_HW_82C924; | |
964 | break; | |
965 | case 0x0925: | |
966 | hw = OPTi9XX_HW_82C925; | |
967 | break; | |
968 | case 0x0931: | |
969 | hw = OPTi9XX_HW_82C931; | |
970 | break; | |
971 | default: | |
972 | snd_card_free(card); | |
973 | return -ENODEV; | |
974 | } | |
975 | ||
976 | if ((error = snd_opti9xx_init(chip, hw))) { | |
977 | snd_card_free(card); | |
978 | return error; | |
979 | } | |
980 | if (hw <= OPTi9XX_HW_82C930) | |
981 | chip->mc_base -= 0x80; | |
982 | snd_card_set_dev(card, &pcard->card->dev); | |
983 | if ((error = snd_opti9xx_probe(card)) < 0) { | |
984 | snd_card_free(card); | |
985 | return error; | |
986 | } | |
987 | pnp_set_card_drvdata(pcard, card); | |
988 | snd_opti9xx_pnp_is_probed = 1; | |
989 | return 0; | |
990 | } | |
991 | ||
992 | static void __devexit snd_opti9xx_pnp_remove(struct pnp_card_link * pcard) | |
993 | { | |
994 | snd_card_free(pnp_get_card_drvdata(pcard)); | |
995 | pnp_set_card_drvdata(pcard, NULL); | |
996 | snd_opti9xx_pnp_is_probed = 0; | |
1da177e4 LT |
997 | } |
998 | ||
999 | static struct pnp_card_driver opti9xx_pnpc_driver = { | |
1000 | .flags = PNP_DRIVER_RES_DISABLE, | |
1001 | .name = "opti9xx", | |
1002 | .id_table = snd_opti9xx_pnpids, | |
99a0b768 | 1003 | .probe = snd_opti9xx_pnp_probe, |
1da177e4 LT |
1004 | .remove = __devexit_p(snd_opti9xx_pnp_remove), |
1005 | }; | |
1006 | #endif | |
1007 | ||
1da177e4 | 1008 | #ifdef OPTi93X |
99a0b768 | 1009 | #define CHIP_NAME "82C93x" |
1da177e4 | 1010 | #else |
99a0b768 | 1011 | #define CHIP_NAME "82C92x" |
1da177e4 | 1012 | #endif |
99a0b768 TI |
1013 | |
1014 | static int __init alsa_card_opti9xx_init(void) | |
1015 | { | |
0bbbc4ca | 1016 | #ifdef CONFIG_PNP |
99a0b768 TI |
1017 | pnp_register_card_driver(&opti9xx_pnpc_driver); |
1018 | if (snd_opti9xx_pnp_is_probed) | |
1019 | return 0; | |
101f6f4b | 1020 | pnp_unregister_card_driver(&opti9xx_pnpc_driver); |
0bbbc4ca | 1021 | #endif |
5e24c1c1 | 1022 | return isa_register_driver(&snd_opti9xx_driver, 1); |
1da177e4 LT |
1023 | } |
1024 | ||
1025 | static void __exit alsa_card_opti9xx_exit(void) | |
1026 | { | |
f7a9275d | 1027 | if (!snd_opti9xx_pnp_is_probed) { |
5e24c1c1 TI |
1028 | isa_unregister_driver(&snd_opti9xx_driver); |
1029 | return; | |
f7a9275d | 1030 | } |
0bbbc4ca | 1031 | #ifdef CONFIG_PNP |
1da177e4 | 1032 | pnp_unregister_card_driver(&opti9xx_pnpc_driver); |
0bbbc4ca | 1033 | #endif |
1da177e4 LT |
1034 | } |
1035 | ||
1036 | module_init(alsa_card_opti9xx_init) | |
1037 | module_exit(alsa_card_opti9xx_exit) |