2 card-opti92x-ad1848.c - driver for OPTi 82c92x based soundcards.
3 Copyright (C) 1998-2000 by Massimo Piccioni <dafastidio@libero.it>
5 Part of this code was developed at the Italian Ministry of Air Defence,
6 Sixth Division (oh, che pace ...), Rome.
8 Thanks to Maria Grazia Pollarini, Salvatore Vassallo.
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.
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.
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
26 #include <linux/init.h>
27 #include <linux/err.h>
28 #include <linux/isa.h>
29 #include <linux/delay.h>
30 #include <linux/slab.h>
31 #include <linux/pnp.h>
32 #include <linux/moduleparam.h>
35 #include <sound/core.h>
36 #include <sound/wss.h>
37 #include <sound/mpu401.h>
38 #include <sound/opl3.h>
40 #include <sound/opl4.h>
42 #define SNDRV_LEGACY_FIND_FREE_IRQ
43 #define SNDRV_LEGACY_FIND_FREE_DMA
44 #include <sound/initval.h>
46 MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
47 MODULE_LICENSE("GPL");
49 MODULE_DESCRIPTION("OPTi93X");
50 MODULE_SUPPORTED_DEVICE("{{OPTi,82C931/3}}");
53 MODULE_DESCRIPTION("OPTi92X - CS4231");
54 MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (CS4231)},"
55 "{OPTi,82C925 (CS4231)}}");
57 MODULE_DESCRIPTION("OPTi92X - AD1848");
58 MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (AD1848)},"
59 "{OPTi,82C925 (AD1848)},"
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 */
68 static int isapnp = 1; /* Enable ISA PnP detection */
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 */
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.");
87 module_param(isapnp, bool, 0444);
88 MODULE_PARM_DESC(isapnp, "Enable ISA PnP detection for specified soundcard.");
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 */
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
116 #define OPTi9XX_MC_REG(n) n
120 #define OPTi93X_STATUS 0x02
121 #define OPTi93X_PORT(chip, r) ((chip)->port + OPTi93X_##r)
123 #define OPTi93X_IRQ_PLAYBACK 0x04
124 #define OPTi93X_IRQ_CAPTURE 0x08
129 unsigned short hardware;
130 unsigned char password;
133 unsigned long mc_base;
134 struct resource *res_mc_base;
135 unsigned long mc_base_size;
137 unsigned long mc_indir_index;
138 unsigned long mc_indir_size;
139 struct resource *res_mc_indir;
140 struct snd_wss *codec;
142 unsigned long pwd_reg;
150 struct pnp_dev *devmpu;
151 #endif /* CONFIG_PNP */
154 static int snd_opti9xx_pnp_is_probed;
158 static struct pnp_card_device_id snd_opti9xx_pnpids[] = {
161 { .id = "OPT0924", .devs = { { "OPT0000" }, { "OPT0002" } }, .driver_data = 0x0924 },
163 { .id = "OPT0925", .devs = { { "OPT9250" }, { "OPT0002" } }, .driver_data = 0x0925 },
166 { .id = "OPT0931", .devs = { { "OPT9310" }, { "OPT0002" } }, .driver_data = 0x0931 },
171 MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids);
173 #endif /* CONFIG_PNP */
176 #define DEV_NAME "opti93x"
178 #define DEV_NAME "opti92x"
181 static char * snd_opti9xx_names[] = {
185 "82C930", "82C931", "82C933"
189 static long __devinit snd_legacy_find_free_ioport(long *port_table, long size)
191 while (*port_table != -1) {
192 if (request_region(*port_table, size, "ALSA test")) {
193 release_region(*port_table, size);
201 static int __devinit snd_opti9xx_init(struct snd_opti9xx *chip,
202 unsigned short hardware)
204 static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
206 chip->hardware = hardware;
207 strcpy(chip->name, snd_opti9xx_names[hardware]);
209 chip->mc_base_size = opti9xx_mc_size[hardware];
211 spin_lock_init(&chip->lock);
217 case OPTi9XX_HW_82C928:
218 case OPTi9XX_HW_82C929:
219 chip->mc_base = 0xf8c;
220 chip->password = (hardware == OPTi9XX_HW_82C928) ? 0xe2 : 0xe3;
224 case OPTi9XX_HW_82C924:
225 case OPTi9XX_HW_82C925:
226 chip->mc_base = 0xf8c;
227 chip->password = 0xe5;
232 case OPTi9XX_HW_82C930:
233 case OPTi9XX_HW_82C931:
234 case OPTi9XX_HW_82C933:
235 chip->mc_base = (hardware == OPTi9XX_HW_82C930) ? 0xf8f : 0xf8d;
236 if (!chip->mc_indir_index) {
237 chip->mc_indir_index = 0xe0e;
238 chip->mc_indir_size = 2;
240 chip->password = 0xe4;
246 snd_printk(KERN_ERR "chip %d not supported\n", hardware);
252 static unsigned char snd_opti9xx_read(struct snd_opti9xx *chip,
256 unsigned char retval = 0xff;
258 spin_lock_irqsave(&chip->lock, flags);
259 outb(chip->password, chip->mc_base + chip->pwd_reg);
261 switch (chip->hardware) {
263 case OPTi9XX_HW_82C924:
264 case OPTi9XX_HW_82C925:
266 outb(reg, chip->mc_base + 8);
267 outb(chip->password, chip->mc_base + chip->pwd_reg);
268 retval = inb(chip->mc_base + 9);
272 case OPTi9XX_HW_82C928:
273 case OPTi9XX_HW_82C929:
274 retval = inb(chip->mc_base + reg);
278 case OPTi9XX_HW_82C930:
279 case OPTi9XX_HW_82C931:
280 case OPTi9XX_HW_82C933:
281 outb(reg, chip->mc_indir_index);
282 outb(chip->password, chip->mc_base + chip->pwd_reg);
283 retval = inb(chip->mc_indir_index + 1);
288 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
291 spin_unlock_irqrestore(&chip->lock, flags);
295 static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg,
300 spin_lock_irqsave(&chip->lock, flags);
301 outb(chip->password, chip->mc_base + chip->pwd_reg);
303 switch (chip->hardware) {
305 case OPTi9XX_HW_82C924:
306 case OPTi9XX_HW_82C925:
308 outb(reg, chip->mc_base + 8);
309 outb(chip->password, chip->mc_base + chip->pwd_reg);
310 outb(value, chip->mc_base + 9);
314 case OPTi9XX_HW_82C928:
315 case OPTi9XX_HW_82C929:
316 outb(value, chip->mc_base + reg);
320 case OPTi9XX_HW_82C930:
321 case OPTi9XX_HW_82C931:
322 case OPTi9XX_HW_82C933:
323 outb(reg, chip->mc_indir_index);
324 outb(chip->password, chip->mc_base + chip->pwd_reg);
325 outb(value, chip->mc_indir_index + 1);
330 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
333 spin_unlock_irqrestore(&chip->lock, flags);
337 #define snd_opti9xx_write_mask(chip, reg, value, mask) \
338 snd_opti9xx_write(chip, reg, \
339 (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask)))
342 static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip,
344 int irq, int dma1, int dma2,
345 long mpu_port, int mpu_irq)
347 unsigned char wss_base_bits;
348 unsigned char irq_bits;
349 unsigned char dma_bits;
350 unsigned char mpu_port_bits = 0;
351 unsigned char mpu_irq_bits;
353 switch (chip->hardware) {
355 case OPTi9XX_HW_82C924:
356 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0xf0, 0xfc);
357 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
359 case OPTi9XX_HW_82C925:
360 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
361 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
362 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
364 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
366 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
370 case OPTi9XX_HW_82C928:
371 case OPTi9XX_HW_82C929:
372 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
373 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
375 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xa2, 0xae);
377 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
379 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
381 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
386 case OPTi9XX_HW_82C931:
387 case OPTi9XX_HW_82C933:
389 * The BTC 1817DW has QS1000 wavetable which is connected
390 * to the serial digital input of the OPTI931.
392 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(21), 0x82, 0xff);
394 * This bit sets OPTI931 to automaticaly select FM
395 * or digital input signal.
397 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(26), 0x01, 0x01);
398 case OPTi9XX_HW_82C930: /* FALL THROUGH */
399 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x03);
400 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0x00, 0xff);
401 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x10 |
402 (chip->hardware == OPTi9XX_HW_82C930 ? 0x00 : 0x04),
404 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x20, 0xbf);
409 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
415 wss_base_bits = 0x00;
418 wss_base_bits = 0x03;
421 wss_base_bits = 0x01;
424 wss_base_bits = 0x02;
427 snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n", wss_base);
430 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
438 //#endif /* OPTi93X */
452 snd_printk(KERN_WARNING "WSS irq # %d not valid\n", irq);
453 goto __skip_resources;
467 snd_printk(KERN_WARNING "WSS dma1 # %d not valid\n", dma1);
468 goto __skip_resources;
471 #if defined(CS4231) || defined(OPTi93X)
473 snd_printk(KERN_ERR "don't want to share dmas\n");
482 snd_printk(KERN_WARNING "WSS dma2 # %d not valid\n", dma2);
483 goto __skip_resources;
486 #endif /* CS4231 || OPTi93X */
489 outb(irq_bits << 3 | dma_bits, wss_base);
491 snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits));
495 if (chip->hardware > OPTi9XX_HW_82C928) {
501 mpu_port_bits = 0x03;
504 mpu_port_bits = 0x02;
507 mpu_port_bits = 0x01;
510 mpu_port_bits = 0x00;
513 snd_printk(KERN_WARNING
514 "MPU-401 port 0x%lx not valid\n", mpu_port);
532 snd_printk(KERN_WARNING "MPU-401 irq # %d not valid\n",
537 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6),
538 (mpu_port <= 0) ? 0x00 :
539 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
549 static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id)
551 struct snd_wss *codec = dev_id;
552 struct snd_opti9xx *chip = codec->card->private_data;
553 unsigned char status;
555 status = snd_opti9xx_read(chip, OPTi9XX_MC_REG(11));
556 if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream)
557 snd_pcm_period_elapsed(codec->playback_substream);
558 if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) {
559 snd_wss_overrange(codec);
560 snd_pcm_period_elapsed(codec->capture_substream);
562 outb(0x00, OPTi93X_PORT(codec, STATUS));
568 static int __devinit snd_opti9xx_read_check(struct snd_opti9xx *chip)
575 chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size,
577 if (chip->res_mc_base == NULL)
580 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1));
581 if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1)))
582 if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)))
585 chip->res_mc_indir = request_region(chip->mc_indir_index,
588 if (chip->res_mc_indir == NULL)
591 spin_lock_irqsave(&chip->lock, flags);
592 outb(chip->password, chip->mc_base + chip->pwd_reg);
593 outb(((chip->mc_indir_index & 0x1f0) >> 4), chip->mc_base);
594 spin_unlock_irqrestore(&chip->lock, flags);
596 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7));
597 snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value);
598 if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value)
601 release_and_free_resource(chip->res_mc_indir);
602 chip->res_mc_indir = NULL;
604 release_and_free_resource(chip->res_mc_base);
605 chip->res_mc_base = NULL;
610 static int __devinit snd_card_opti9xx_detect(struct snd_card *card,
611 struct snd_opti9xx *chip)
616 for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) {
618 for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) {
620 err = snd_opti9xx_init(chip, i);
624 err = snd_opti9xx_read_check(chip);
628 chip->mc_indir_index = 0;
635 static int __devinit snd_card_opti9xx_pnp(struct snd_opti9xx *chip,
636 struct pnp_card_link *card,
637 const struct pnp_card_device_id *pid)
639 struct pnp_dev *pdev;
642 chip->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
643 if (chip->dev == NULL)
646 chip->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
650 err = pnp_activate_dev(pdev);
652 snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err);
657 port = pnp_port_start(pdev, 0) - 4;
658 fm_port = pnp_port_start(pdev, 1) + 8;
659 chip->mc_indir_index = pnp_port_start(pdev, 3) + 2;
660 chip->mc_indir_size = pnp_port_len(pdev, 3) - 2;
662 if (pid->driver_data != 0x0924)
663 port = pnp_port_start(pdev, 1);
664 fm_port = pnp_port_start(pdev, 2) + 8;
666 irq = pnp_irq(pdev, 0);
667 dma1 = pnp_dma(pdev, 0);
668 #if defined(CS4231) || defined(OPTi93X)
669 dma2 = pnp_dma(pdev, 1);
670 #endif /* CS4231 || OPTi93X */
673 if (pdev && mpu_port > 0) {
674 err = pnp_activate_dev(pdev);
676 snd_printk(KERN_ERR "AUDIO pnp configure failure\n");
680 mpu_port = pnp_port_start(pdev, 0);
681 mpu_irq = pnp_irq(pdev, 0);
684 return pid->driver_data;
686 #endif /* CONFIG_PNP */
688 static void snd_card_opti9xx_free(struct snd_card *card)
690 struct snd_opti9xx *chip = card->private_data;
694 struct snd_wss *codec = chip->codec;
695 if (codec && codec->irq > 0) {
696 disable_irq(codec->irq);
697 free_irq(codec->irq, codec);
699 release_and_free_resource(chip->res_mc_indir);
701 release_and_free_resource(chip->res_mc_base);
705 static int __devinit snd_opti9xx_probe(struct snd_card *card)
707 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
710 struct snd_opti9xx *chip = card->private_data;
711 struct snd_wss *codec;
713 struct snd_timer *timer;
716 struct snd_rawmidi *rmidi;
717 struct snd_hwdep *synth;
719 #if defined(CS4231) || defined(OPTi93X)
725 if (port == SNDRV_AUTO_PORT) {
726 port = snd_legacy_find_free_ioport(possible_ports, 4);
728 snd_printk(KERN_ERR "unable to find a free WSS port\n");
732 error = snd_opti9xx_configure(chip, port, irq, dma1, xdma2,
737 error = snd_wss_create(card, port + 4, -1, irq, dma1, xdma2,
739 WSS_HW_OPTI93X, WSS_HWSHARE_IRQ,
749 error = snd_wss_pcm(codec, 0, &pcm);
752 error = snd_wss_mixer(codec);
756 error = snd_wss_timer(codec, 0, &timer);
761 error = request_irq(irq, snd_opti93x_interrupt,
762 IRQF_DISABLED, DEV_NAME" - WSS", codec);
764 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", chip->irq);
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, port + 4, irq, dma1, xdma2);
775 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
776 card->shortname, pcm->name, port + 4, irq, dma1);
777 #endif /* CS4231 || OPTi93X */
779 if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT)
782 error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
783 mpu_port, 0, mpu_irq, IRQF_DISABLED, &rmidi);
785 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
789 if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
790 struct snd_opl3 *opl3 = NULL;
792 if (chip->hardware == OPTi9XX_HW_82C928 ||
793 chip->hardware == OPTi9XX_HW_82C929 ||
794 chip->hardware == OPTi9XX_HW_82C924) {
795 struct snd_opl4 *opl4;
796 /* assume we have an OPL4 */
797 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
799 if (snd_opl4_create(card, fm_port, fm_port - 8,
800 2, &opl3, &opl4) < 0) {
801 /* no luck, use OPL3 instead */
802 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
806 #endif /* !OPTi93X */
807 if (!opl3 && snd_opl3_create(card, fm_port, fm_port + 2,
808 OPL3_HW_AUTO, 0, &opl3) < 0) {
809 snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
810 fm_port, fm_port + 4 - 1);
813 error = snd_opl3_hwdep_new(opl3, 0, 1, &synth);
819 return snd_card_register(card);
822 static int snd_opti9xx_card_new(struct snd_card **cardp)
824 struct snd_card *card;
827 err = snd_card_create(index, id, THIS_MODULE,
828 sizeof(struct snd_opti9xx), &card);
831 card->private_free = snd_card_opti9xx_free;
836 static int __devinit snd_opti9xx_isa_match(struct device *devptr,
840 if (snd_opti9xx_pnp_is_probed)
848 static int __devinit snd_opti9xx_isa_probe(struct device *devptr,
851 struct snd_card *card;
853 static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};
855 static int possible_irqs[] = {5, 9, 10, 11, 7, -1};
857 static int possible_irqs[] = {9, 10, 11, 7, -1};
859 static int possible_mpu_irqs[] = {5, 9, 10, 7, -1};
860 static int possible_dma1s[] = {3, 1, 0, -1};
861 #if defined(CS4231) || defined(OPTi93X)
862 static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
863 #endif /* CS4231 || OPTi93X */
865 if (mpu_port == SNDRV_AUTO_PORT) {
866 if ((mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
867 snd_printk(KERN_ERR "unable to find a free MPU401 port\n");
871 if (irq == SNDRV_AUTO_IRQ) {
872 if ((irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
873 snd_printk(KERN_ERR "unable to find a free IRQ\n");
877 if (mpu_irq == SNDRV_AUTO_IRQ) {
878 if ((mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
879 snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n");
883 if (dma1 == SNDRV_AUTO_DMA) {
884 if ((dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
885 snd_printk(KERN_ERR "unable to find a free DMA1\n");
889 #if defined(CS4231) || defined(OPTi93X)
890 if (dma2 == SNDRV_AUTO_DMA) {
891 if ((dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4])) < 0) {
892 snd_printk(KERN_ERR "unable to find a free DMA2\n");
898 error = snd_opti9xx_card_new(&card);
902 if ((error = snd_card_opti9xx_detect(card, card->private_data)) < 0) {
906 snd_card_set_dev(card, devptr);
907 if ((error = snd_opti9xx_probe(card)) < 0) {
911 dev_set_drvdata(devptr, card);
915 static int __devexit snd_opti9xx_isa_remove(struct device *devptr,
918 snd_card_free(dev_get_drvdata(devptr));
919 dev_set_drvdata(devptr, NULL);
923 static struct isa_driver snd_opti9xx_driver = {
924 .match = snd_opti9xx_isa_match,
925 .probe = snd_opti9xx_isa_probe,
926 .remove = __devexit_p(snd_opti9xx_isa_remove),
927 /* FIXME: suspend/resume */
934 static int __devinit snd_opti9xx_pnp_probe(struct pnp_card_link *pcard,
935 const struct pnp_card_device_id *pid)
937 struct snd_card *card;
939 struct snd_opti9xx *chip;
941 if (snd_opti9xx_pnp_is_probed)
945 error = snd_opti9xx_card_new(&card);
948 chip = card->private_data;
950 hw = snd_card_opti9xx_pnp(chip, pcard, pid);
953 hw = OPTi9XX_HW_82C924;
956 hw = OPTi9XX_HW_82C925;
959 hw = OPTi9XX_HW_82C931;
966 if ((error = snd_opti9xx_init(chip, hw))) {
970 if (hw <= OPTi9XX_HW_82C930)
971 chip->mc_base -= 0x80;
973 error = snd_opti9xx_read_check(chip);
975 snd_printk(KERN_ERR "OPTI chip not found\n");
979 snd_card_set_dev(card, &pcard->card->dev);
980 if ((error = snd_opti9xx_probe(card)) < 0) {
984 pnp_set_card_drvdata(pcard, card);
985 snd_opti9xx_pnp_is_probed = 1;
989 static void __devexit snd_opti9xx_pnp_remove(struct pnp_card_link * pcard)
991 snd_card_free(pnp_get_card_drvdata(pcard));
992 pnp_set_card_drvdata(pcard, NULL);
993 snd_opti9xx_pnp_is_probed = 0;
996 static struct pnp_card_driver opti9xx_pnpc_driver = {
997 .flags = PNP_DRIVER_RES_DISABLE,
999 .id_table = snd_opti9xx_pnpids,
1000 .probe = snd_opti9xx_pnp_probe,
1001 .remove = __devexit_p(snd_opti9xx_pnp_remove),
1006 #define CHIP_NAME "82C93x"
1008 #define CHIP_NAME "82C92x"
1011 static int __init alsa_card_opti9xx_init(void)
1014 pnp_register_card_driver(&opti9xx_pnpc_driver);
1015 if (snd_opti9xx_pnp_is_probed)
1017 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
1019 return isa_register_driver(&snd_opti9xx_driver, 1);
1022 static void __exit alsa_card_opti9xx_exit(void)
1024 if (!snd_opti9xx_pnp_is_probed) {
1025 isa_unregister_driver(&snd_opti9xx_driver);
1029 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
1033 module_init(alsa_card_opti9xx_init)
1034 module_exit(alsa_card_opti9xx_exit)