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 struct snd_wss *codec;
140 unsigned long pwd_reg;
156 struct pnp_dev *devmpu;
157 #endif /* CONFIG_PNP */
160 static int snd_opti9xx_pnp_is_probed;
164 static struct pnp_card_device_id snd_opti9xx_pnpids[] = {
167 { .id = "OPT0924", .devs = { { "OPT0000" }, { "OPT0002" } }, .driver_data = 0x0924 },
169 { .id = "OPT0925", .devs = { { "OPT9250" }, { "OPT0002" } }, .driver_data = 0x0925 },
172 { .id = "OPT0931", .devs = { { "OPT9310" }, { "OPT0002" } }, .driver_data = 0x0931 },
177 MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids);
179 #endif /* CONFIG_PNP */
182 #define DEV_NAME "opti93x"
184 #define DEV_NAME "opti92x"
187 static char * snd_opti9xx_names[] = {
191 "82C930", "82C931", "82C933"
195 static long __devinit snd_legacy_find_free_ioport(long *port_table, long size)
197 while (*port_table != -1) {
198 if (request_region(*port_table, size, "ALSA test")) {
199 release_region(*port_table, size);
207 static int __devinit snd_opti9xx_init(struct snd_opti9xx *chip,
208 unsigned short hardware)
210 static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
212 chip->hardware = hardware;
213 strcpy(chip->name, snd_opti9xx_names[hardware]);
215 chip->mc_base_size = opti9xx_mc_size[hardware];
217 spin_lock_init(&chip->lock);
229 case OPTi9XX_HW_82C928:
230 case OPTi9XX_HW_82C929:
231 chip->mc_base = 0xf8c;
232 chip->password = (hardware == OPTi9XX_HW_82C928) ? 0xe2 : 0xe3;
236 case OPTi9XX_HW_82C924:
237 case OPTi9XX_HW_82C925:
238 chip->mc_base = 0xf8c;
239 chip->password = 0xe5;
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;
255 snd_printk(KERN_ERR "chip %d not supported\n", hardware);
261 static unsigned char snd_opti9xx_read(struct snd_opti9xx *chip,
265 unsigned char retval = 0xff;
267 spin_lock_irqsave(&chip->lock, flags);
268 outb(chip->password, chip->mc_base + chip->pwd_reg);
270 switch (chip->hardware) {
272 case OPTi9XX_HW_82C924:
273 case OPTi9XX_HW_82C925:
275 outb(reg, chip->mc_base + 8);
276 outb(chip->password, chip->mc_base + chip->pwd_reg);
277 retval = inb(chip->mc_base + 9);
281 case OPTi9XX_HW_82C928:
282 case OPTi9XX_HW_82C929:
283 retval = inb(chip->mc_base + reg);
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);
297 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
300 spin_unlock_irqrestore(&chip->lock, flags);
304 static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg,
309 spin_lock_irqsave(&chip->lock, flags);
310 outb(chip->password, chip->mc_base + chip->pwd_reg);
312 switch (chip->hardware) {
314 case OPTi9XX_HW_82C924:
315 case OPTi9XX_HW_82C925:
317 outb(reg, chip->mc_base + 8);
318 outb(chip->password, chip->mc_base + chip->pwd_reg);
319 outb(value, chip->mc_base + 9);
323 case OPTi9XX_HW_82C928:
324 case OPTi9XX_HW_82C929:
325 outb(value, chip->mc_base + reg);
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);
339 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
342 spin_unlock_irqrestore(&chip->lock, flags);
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)))
351 static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip)
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;
359 switch (chip->hardware) {
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);
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);
370 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
372 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
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);
381 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xa2, 0xae);
383 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
385 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
387 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
392 case OPTi9XX_HW_82C931:
393 case OPTi9XX_HW_82C933:
395 * The BTC 1817DW has QS1000 wavetable which is connected
396 * to the serial digital input of the OPTI931.
398 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(21), 0x82, 0xff);
400 * This bit sets OPTI931 to automaticaly select FM
401 * or digital input signal.
403 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(26), 0x01, 0x01);
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),
410 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x20, 0xbf);
415 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
419 switch (chip->wss_base) {
421 wss_base_bits = 0x00;
424 wss_base_bits = 0x03;
427 wss_base_bits = 0x01;
430 wss_base_bits = 0x02;
433 snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n",
437 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
445 //#endif /* OPTi93X */
459 snd_printk(KERN_WARNING "WSS irq # %d not valid\n", chip->irq);
460 goto __skip_resources;
463 switch (chip->dma1) {
474 snd_printk(KERN_WARNING "WSS dma1 # %d not valid\n",
476 goto __skip_resources;
479 #if defined(CS4231) || defined(OPTi93X)
480 if (chip->dma1 == chip->dma2) {
481 snd_printk(KERN_ERR "don't want to share dmas\n");
485 switch (chip->dma2) {
490 snd_printk(KERN_WARNING "WSS dma2 # %d not valid\n",
492 goto __skip_resources;
495 #endif /* CS4231 || OPTi93X */
498 outb(irq_bits << 3 | dma_bits, chip->wss_base);
500 snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits));
504 if (chip->hardware > OPTi9XX_HW_82C928) {
505 switch (chip->mpu_port) {
510 mpu_port_bits = 0x03;
513 mpu_port_bits = 0x02;
516 mpu_port_bits = 0x01;
519 mpu_port_bits = 0x00;
522 snd_printk(KERN_WARNING
523 "MPU-401 port 0x%lx not valid\n",
528 switch (chip->mpu_irq) {
542 snd_printk(KERN_WARNING "MPU-401 irq # %d not valid\n",
547 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6),
548 (chip->mpu_port <= 0) ? 0x00 :
549 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
559 static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id)
561 struct snd_wss *codec = dev_id;
562 struct snd_opti9xx *chip = codec->card->private_data;
563 unsigned char status;
565 status = snd_opti9xx_read(chip, OPTi9XX_MC_REG(11));
566 if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream)
567 snd_pcm_period_elapsed(codec->playback_substream);
568 if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) {
569 snd_wss_overrange(codec);
570 snd_pcm_period_elapsed(codec->capture_substream);
572 outb(0x00, OPTi93X_PORT(codec, STATUS));
578 static int __devinit snd_card_opti9xx_detect(struct snd_card *card,
579 struct snd_opti9xx *chip)
584 for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) {
587 if ((err = snd_opti9xx_init(chip, i)) < 0)
590 if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL)
593 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1));
594 if ((value != 0xff) && (value != inb(chip->mc_base + 1)))
595 if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)))
598 release_and_free_resource(chip->res_mc_base);
599 chip->res_mc_base = NULL;
603 for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) {
607 if ((err = snd_opti9xx_init(chip, i)) < 0)
610 if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL)
613 spin_lock_irqsave(&chip->lock, flags);
614 outb(chip->password, chip->mc_base + chip->pwd_reg);
615 outb(((chip->mc_indir_index & (1 << 8)) >> 4) |
616 ((chip->mc_indir_index & 0xf0) >> 4), chip->mc_base);
617 spin_unlock_irqrestore(&chip->lock, flags);
619 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7));
620 snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value);
621 if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value)
624 release_and_free_resource(chip->res_mc_base);
625 chip->res_mc_base = NULL;
633 static int __devinit snd_card_opti9xx_pnp(struct snd_opti9xx *chip,
634 struct pnp_card_link *card,
635 const struct pnp_card_device_id *pid)
637 struct pnp_dev *pdev;
640 chip->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
641 if (chip->dev == NULL)
644 chip->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
648 err = pnp_activate_dev(pdev);
650 snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err);
655 port = pnp_port_start(pdev, 0) - 4;
656 fm_port = pnp_port_start(pdev, 1) + 8;
658 if (pid->driver_data != 0x0924)
659 port = pnp_port_start(pdev, 1);
660 fm_port = pnp_port_start(pdev, 2) + 8;
662 irq = pnp_irq(pdev, 0);
663 dma1 = pnp_dma(pdev, 0);
664 #if defined(CS4231) || defined(OPTi93X)
665 dma2 = pnp_dma(pdev, 1);
666 #endif /* CS4231 || OPTi93X */
669 if (pdev && mpu_port > 0) {
670 err = pnp_activate_dev(pdev);
672 snd_printk(KERN_ERR "AUDIO pnp configure failure\n");
676 mpu_port = pnp_port_start(pdev, 0);
677 mpu_irq = pnp_irq(pdev, 0);
680 return pid->driver_data;
682 #endif /* CONFIG_PNP */
684 static void snd_card_opti9xx_free(struct snd_card *card)
686 struct snd_opti9xx *chip = card->private_data;
690 struct snd_wss *codec = chip->codec;
691 if (codec && codec->irq > 0) {
692 disable_irq(codec->irq);
693 free_irq(codec->irq, codec);
696 release_and_free_resource(chip->res_mc_base);
700 static int __devinit snd_opti9xx_probe(struct snd_card *card)
702 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
704 struct snd_opti9xx *chip = card->private_data;
705 struct snd_wss *codec;
707 struct snd_timer *timer;
710 struct snd_rawmidi *rmidi;
711 struct snd_hwdep *synth;
713 if (! chip->res_mc_base &&
714 (chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size,
715 "OPTi9xx MC")) == NULL)
718 chip->wss_base = port;
719 chip->fm_port = fm_port;
720 chip->mpu_port = mpu_port;
722 chip->mpu_irq = mpu_irq;
724 #if defined(CS4231) || defined(OPTi93X)
730 if (chip->wss_base == SNDRV_AUTO_PORT) {
731 chip->wss_base = snd_legacy_find_free_ioport(possible_ports, 4);
732 if (chip->wss_base < 0) {
733 snd_printk(KERN_ERR "unable to find a free WSS port\n");
737 error = snd_opti9xx_configure(chip);
741 error = snd_wss_create(card, chip->wss_base + 4, -1,
742 chip->irq, chip->dma1, chip->dma2,
744 WSS_HW_OPTI93X, WSS_HWSHARE_IRQ,
754 error = snd_wss_pcm(codec, 0, &pcm);
757 error = snd_wss_mixer(codec);
761 error = snd_wss_timer(codec, 0, &timer);
766 error = request_irq(chip->irq, snd_opti93x_interrupt,
767 IRQF_DISABLED, DEV_NAME" - WSS", codec);
769 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", chip->irq);
773 strcpy(card->driver, chip->name);
774 sprintf(card->shortname, "OPTi %s", card->driver);
775 #if defined(CS4231) || defined(OPTi93X)
776 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
777 card->shortname, pcm->name, chip->wss_base + 4,
778 chip->irq, chip->dma1, chip->dma2);
780 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
781 card->shortname, pcm->name, chip->wss_base + 4,
782 chip->irq, chip->dma1);
783 #endif /* CS4231 || OPTi93X */
785 if (chip->mpu_port <= 0 || chip->mpu_port == SNDRV_AUTO_PORT)
788 if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
789 chip->mpu_port, 0, chip->mpu_irq, IRQF_DISABLED,
791 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
794 if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) {
795 struct snd_opl3 *opl3 = NULL;
797 if (chip->hardware == OPTi9XX_HW_82C928 ||
798 chip->hardware == OPTi9XX_HW_82C929 ||
799 chip->hardware == OPTi9XX_HW_82C924) {
800 struct snd_opl4 *opl4;
801 /* assume we have an OPL4 */
802 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
804 if (snd_opl4_create(card,
807 2, &opl3, &opl4) < 0) {
808 /* no luck, use OPL3 instead */
809 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
813 #endif /* !OPTi93X */
814 if (!opl3 && snd_opl3_create(card,
817 OPL3_HW_AUTO, 0, &opl3) < 0) {
818 snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
819 chip->fm_port, chip->fm_port + 4 - 1);
822 error = snd_opl3_hwdep_new(opl3, 0, 1, &synth);
828 return snd_card_register(card);
831 static int snd_opti9xx_card_new(struct snd_card **cardp)
833 struct snd_card *card;
836 err = snd_card_create(index, id, THIS_MODULE,
837 sizeof(struct snd_opti9xx), &card);
840 card->private_free = snd_card_opti9xx_free;
845 static int __devinit snd_opti9xx_isa_match(struct device *devptr,
849 if (snd_opti9xx_pnp_is_probed)
857 static int __devinit snd_opti9xx_isa_probe(struct device *devptr,
860 struct snd_card *card;
862 static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};
864 static int possible_irqs[] = {5, 9, 10, 11, 7, -1};
866 static int possible_irqs[] = {9, 10, 11, 7, -1};
868 static int possible_mpu_irqs[] = {5, 9, 10, 7, -1};
869 static int possible_dma1s[] = {3, 1, 0, -1};
870 #if defined(CS4231) || defined(OPTi93X)
871 static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
872 #endif /* CS4231 || OPTi93X */
874 if (mpu_port == SNDRV_AUTO_PORT) {
875 if ((mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
876 snd_printk(KERN_ERR "unable to find a free MPU401 port\n");
880 if (irq == SNDRV_AUTO_IRQ) {
881 if ((irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
882 snd_printk(KERN_ERR "unable to find a free IRQ\n");
886 if (mpu_irq == SNDRV_AUTO_IRQ) {
887 if ((mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
888 snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n");
892 if (dma1 == SNDRV_AUTO_DMA) {
893 if ((dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
894 snd_printk(KERN_ERR "unable to find a free DMA1\n");
898 #if defined(CS4231) || defined(OPTi93X)
899 if (dma2 == SNDRV_AUTO_DMA) {
900 if ((dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4])) < 0) {
901 snd_printk(KERN_ERR "unable to find a free DMA2\n");
907 error = snd_opti9xx_card_new(&card);
911 if ((error = snd_card_opti9xx_detect(card, card->private_data)) < 0) {
915 snd_card_set_dev(card, devptr);
916 if ((error = snd_opti9xx_probe(card)) < 0) {
920 dev_set_drvdata(devptr, card);
924 static int __devexit snd_opti9xx_isa_remove(struct device *devptr,
927 snd_card_free(dev_get_drvdata(devptr));
928 dev_set_drvdata(devptr, NULL);
932 static struct isa_driver snd_opti9xx_driver = {
933 .match = snd_opti9xx_isa_match,
934 .probe = snd_opti9xx_isa_probe,
935 .remove = __devexit_p(snd_opti9xx_isa_remove),
936 /* FIXME: suspend/resume */
943 static int __devinit snd_opti9xx_pnp_probe(struct pnp_card_link *pcard,
944 const struct pnp_card_device_id *pid)
946 struct snd_card *card;
948 struct snd_opti9xx *chip;
950 if (snd_opti9xx_pnp_is_probed)
954 error = snd_opti9xx_card_new(&card);
957 chip = card->private_data;
959 hw = snd_card_opti9xx_pnp(chip, pcard, pid);
962 hw = OPTi9XX_HW_82C924;
965 hw = OPTi9XX_HW_82C925;
968 hw = OPTi9XX_HW_82C931;
975 if ((error = snd_opti9xx_init(chip, hw))) {
979 if (hw <= OPTi9XX_HW_82C930)
980 chip->mc_base -= 0x80;
981 snd_card_set_dev(card, &pcard->card->dev);
982 if ((error = snd_opti9xx_probe(card)) < 0) {
986 pnp_set_card_drvdata(pcard, card);
987 snd_opti9xx_pnp_is_probed = 1;
991 static void __devexit snd_opti9xx_pnp_remove(struct pnp_card_link * pcard)
993 snd_card_free(pnp_get_card_drvdata(pcard));
994 pnp_set_card_drvdata(pcard, NULL);
995 snd_opti9xx_pnp_is_probed = 0;
998 static struct pnp_card_driver opti9xx_pnpc_driver = {
999 .flags = PNP_DRIVER_RES_DISABLE,
1001 .id_table = snd_opti9xx_pnpids,
1002 .probe = snd_opti9xx_pnp_probe,
1003 .remove = __devexit_p(snd_opti9xx_pnp_remove),
1008 #define CHIP_NAME "82C93x"
1010 #define CHIP_NAME "82C92x"
1013 static int __init alsa_card_opti9xx_init(void)
1016 pnp_register_card_driver(&opti9xx_pnpc_driver);
1017 if (snd_opti9xx_pnp_is_probed)
1019 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
1021 return isa_register_driver(&snd_opti9xx_driver, 1);
1024 static void __exit alsa_card_opti9xx_exit(void)
1026 if (!snd_opti9xx_pnp_is_probed) {
1027 isa_unregister_driver(&snd_opti9xx_driver);
1031 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
1035 module_init(alsa_card_opti9xx_init)
1036 module_exit(alsa_card_opti9xx_exit)