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 #if defined(CS4231) || defined(OPTi93X)
37 #include <sound/cs4231.h>
39 #include <sound/ad1848.h>
41 #include <sound/mpu401.h>
42 #include <sound/opl3.h>
44 #include <sound/opl4.h>
46 #define SNDRV_LEGACY_FIND_FREE_IRQ
47 #define SNDRV_LEGACY_FIND_FREE_DMA
48 #include <sound/initval.h>
50 MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
51 MODULE_LICENSE("GPL");
53 MODULE_DESCRIPTION("OPTi93X");
54 MODULE_SUPPORTED_DEVICE("{{OPTi,82C931/3}}");
57 MODULE_DESCRIPTION("OPTi92X - CS4231");
58 MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (CS4231)},"
59 "{OPTi,82C925 (CS4231)}}");
61 MODULE_DESCRIPTION("OPTi92X - AD1848");
62 MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (AD1848)},"
63 "{OPTi,82C925 (AD1848)},"
68 static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
69 static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
70 //static int enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */
71 static int isapnp = 1; /* Enable ISA PnP detection */
72 static long port = SNDRV_DEFAULT_PORT1; /* 0x530,0xe80,0xf40,0x604 */
73 static long mpu_port = SNDRV_DEFAULT_PORT1; /* 0x300,0x310,0x320,0x330 */
74 static long fm_port = SNDRV_DEFAULT_PORT1; /* 0x388 */
75 static int irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10,11 */
76 static int mpu_irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10 */
77 static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
78 #if defined(CS4231) || defined(OPTi93X)
79 static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
80 #endif /* CS4231 || OPTi93X */
82 module_param(index, int, 0444);
83 MODULE_PARM_DESC(index, "Index value for opti9xx based soundcard.");
84 module_param(id, charp, 0444);
85 MODULE_PARM_DESC(id, "ID string for opti9xx based soundcard.");
86 //module_param(enable, bool, 0444);
87 //MODULE_PARM_DESC(enable, "Enable opti9xx soundcard.");
88 module_param(isapnp, bool, 0444);
89 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_cs4231 *codec;
140 unsigned long pwd_reg;
147 #if defined(CS4231) || defined(OPTi93X)
149 #endif /* CS4231 || OPTi93X */
158 struct pnp_dev *devmpu;
159 #endif /* CONFIG_PNP */
162 static int snd_opti9xx_pnp_is_probed;
166 static struct pnp_card_device_id snd_opti9xx_pnpids[] = {
169 { .id = "OPT0924", .devs = { { "OPT0000" }, { "OPT0002" } }, .driver_data = 0x0924 },
171 { .id = "OPT0925", .devs = { { "OPT9250" }, { "OPT0002" } }, .driver_data = 0x0925 },
174 { .id = "OPT0931", .devs = { { "OPT9310" }, { "OPT0002" } }, .driver_data = 0x0931 },
179 MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids);
181 #endif /* CONFIG_PNP */
184 #define DEV_NAME "opti93x"
186 #define DEV_NAME "opti92x"
189 static char * snd_opti9xx_names[] = {
193 "82C930", "82C931", "82C933"
197 static long __devinit snd_legacy_find_free_ioport(long *port_table, long size)
199 while (*port_table != -1) {
200 if (request_region(*port_table, size, "ALSA test")) {
201 release_region(*port_table, size);
209 static int __devinit snd_opti9xx_init(struct snd_opti9xx *chip,
210 unsigned short hardware)
212 static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
214 chip->hardware = hardware;
215 strcpy(chip->name, snd_opti9xx_names[hardware]);
217 chip->mc_base_size = opti9xx_mc_size[hardware];
219 spin_lock_init(&chip->lock);
224 #if defined(CS4231) || defined (OPTi93X)
226 #endif /* CS4231 || OPTi93X */
233 case OPTi9XX_HW_82C928:
234 case OPTi9XX_HW_82C929:
235 chip->mc_base = 0xf8c;
236 chip->password = (hardware == OPTi9XX_HW_82C928) ? 0xe2 : 0xe3;
240 case OPTi9XX_HW_82C924:
241 case OPTi9XX_HW_82C925:
242 chip->mc_base = 0xf8c;
243 chip->password = 0xe5;
248 case OPTi9XX_HW_82C930:
249 case OPTi9XX_HW_82C931:
250 case OPTi9XX_HW_82C933:
251 chip->mc_base = (hardware == OPTi9XX_HW_82C930) ? 0xf8f : 0xf8d;
252 chip->mc_indir_index = 0xe0e;
253 chip->password = 0xe4;
259 snd_printk("chip %d not supported\n", hardware);
265 static unsigned char snd_opti9xx_read(struct snd_opti9xx *chip,
269 unsigned char retval = 0xff;
271 spin_lock_irqsave(&chip->lock, flags);
272 outb(chip->password, chip->mc_base + chip->pwd_reg);
274 switch (chip->hardware) {
276 case OPTi9XX_HW_82C924:
277 case OPTi9XX_HW_82C925:
279 outb(reg, chip->mc_base + 8);
280 outb(chip->password, chip->mc_base + chip->pwd_reg);
281 retval = inb(chip->mc_base + 9);
285 case OPTi9XX_HW_82C928:
286 case OPTi9XX_HW_82C929:
287 retval = inb(chip->mc_base + reg);
291 case OPTi9XX_HW_82C930:
292 case OPTi9XX_HW_82C931:
293 case OPTi9XX_HW_82C933:
294 outb(reg, chip->mc_indir_index);
295 outb(chip->password, chip->mc_base + chip->pwd_reg);
296 retval = inb(chip->mc_indir_index + 1);
301 snd_printk("chip %d not supported\n", chip->hardware);
304 spin_unlock_irqrestore(&chip->lock, flags);
308 static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg,
313 spin_lock_irqsave(&chip->lock, flags);
314 outb(chip->password, chip->mc_base + chip->pwd_reg);
316 switch (chip->hardware) {
318 case OPTi9XX_HW_82C924:
319 case OPTi9XX_HW_82C925:
321 outb(reg, chip->mc_base + 8);
322 outb(chip->password, chip->mc_base + chip->pwd_reg);
323 outb(value, chip->mc_base + 9);
327 case OPTi9XX_HW_82C928:
328 case OPTi9XX_HW_82C929:
329 outb(value, chip->mc_base + reg);
333 case OPTi9XX_HW_82C930:
334 case OPTi9XX_HW_82C931:
335 case OPTi9XX_HW_82C933:
336 outb(reg, chip->mc_indir_index);
337 outb(chip->password, chip->mc_base + chip->pwd_reg);
338 outb(value, chip->mc_indir_index + 1);
343 snd_printk("chip %d not supported\n", chip->hardware);
346 spin_unlock_irqrestore(&chip->lock, flags);
350 #define snd_opti9xx_write_mask(chip, reg, value, mask) \
351 snd_opti9xx_write(chip, reg, \
352 (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask)))
355 static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip)
357 unsigned char wss_base_bits;
358 unsigned char irq_bits;
359 unsigned char dma_bits;
360 unsigned char mpu_port_bits = 0;
361 unsigned char mpu_irq_bits;
363 switch (chip->hardware) {
365 case OPTi9XX_HW_82C924:
366 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0xf0, 0xfc);
367 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
369 case OPTi9XX_HW_82C925:
370 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
371 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
372 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
374 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
376 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
380 case OPTi9XX_HW_82C928:
381 case OPTi9XX_HW_82C929:
382 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
383 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
385 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xa2, 0xae);
387 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
389 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
391 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
396 case OPTi9XX_HW_82C931:
397 case OPTi9XX_HW_82C933:
399 * The BTC 1817DW has QS1000 wavetable which is connected
400 * to the serial digital input of the OPTI931.
402 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(21), 0x82, 0xff);
404 * This bit sets OPTI931 to automaticaly select FM
405 * or digital input signal.
407 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(26), 0x01, 0x01);
408 case OPTi9XX_HW_82C930: /* FALL THROUGH */
409 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x03);
410 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0x00, 0xff);
411 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x10 |
412 (chip->hardware == OPTi9XX_HW_82C930 ? 0x00 : 0x04),
414 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x20, 0xbf);
419 snd_printk("chip %d not supported\n", chip->hardware);
423 switch (chip->wss_base) {
425 wss_base_bits = 0x00;
428 wss_base_bits = 0x03;
431 wss_base_bits = 0x01;
434 wss_base_bits = 0x02;
437 snd_printk("WSS port 0x%lx not valid\n", chip->wss_base);
440 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
448 //#endif /* OPTi93X */
462 snd_printk("WSS irq # %d not valid\n", chip->irq);
463 goto __skip_resources;
466 switch (chip->dma1) {
477 snd_printk("WSS dma1 # %d not valid\n", chip->dma1);
478 goto __skip_resources;
481 #if defined(CS4231) || defined(OPTi93X)
482 if (chip->dma1 == chip->dma2) {
483 snd_printk("don't want to share dmas\n");
487 switch (chip->dma2) {
492 snd_printk("WSS dma2 # %d not valid\n", chip->dma2);
493 goto __skip_resources;
496 #endif /* CS4231 || OPTi93X */
499 outb(irq_bits << 3 | dma_bits, chip->wss_base);
501 snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits));
505 if (chip->hardware > OPTi9XX_HW_82C928) {
506 switch (chip->mpu_port) {
511 mpu_port_bits = 0x03;
514 mpu_port_bits = 0x02;
517 mpu_port_bits = 0x01;
520 mpu_port_bits = 0x00;
523 snd_printk("MPU-401 port 0x%lx not valid\n",
528 switch (chip->mpu_irq) {
542 snd_printk("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_cs4231 *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_cs4231_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_cs4231 *codec = chip->codec;
691 if (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 #if defined(CS4231) || defined(OPTi93X)
706 struct snd_cs4231 *codec;
708 struct snd_timer *timer;
711 struct snd_ad1848 *codec;
714 struct snd_rawmidi *rmidi;
715 struct snd_hwdep *synth;
717 if (! chip->res_mc_base &&
718 (chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size,
719 "OPTi9xx MC")) == NULL)
722 chip->wss_base = port;
723 chip->fm_port = fm_port;
724 chip->mpu_port = mpu_port;
726 chip->mpu_irq = mpu_irq;
728 #if defined(CS4231) || defined(OPTi93X)
732 if (chip->wss_base == SNDRV_AUTO_PORT) {
733 if ((chip->wss_base = snd_legacy_find_free_ioport(possible_ports, 4)) < 0) {
734 snd_printk("unable to find a free WSS port\n");
738 if ((error = snd_opti9xx_configure(chip)))
741 #if defined(CS4231) || defined(OPTi93X)
742 if ((error = snd_cs4231_create(card, chip->wss_base + 4, -1,
743 chip->irq, chip->dma1, chip->dma2,
747 CS4231_HW_OPTI93X, CS4231_HWSHARE_IRQ,
754 if ((error = snd_cs4231_pcm(codec, 0, &pcm)) < 0)
756 if ((error = snd_cs4231_mixer(codec)) < 0)
759 if ((error = snd_cs4231_timer(codec, 0, &timer)) < 0)
762 error = request_irq(chip->irq, snd_opti93x_interrupt,
763 IRQF_DISABLED, DEV_NAME" - WSS", codec);
765 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", chip->irq);
770 if ((error = snd_ad1848_create(card, chip->wss_base + 4,
771 chip->irq, chip->dma1,
772 AD1848_HW_DETECT, &codec)) < 0)
774 if ((error = snd_ad1848_pcm(codec, 0, &pcm)) < 0)
776 if ((error = snd_ad1848_mixer(codec)) < 0)
779 strcpy(card->driver, chip->name);
780 sprintf(card->shortname, "OPTi %s", card->driver);
781 #if defined(CS4231) || defined(OPTi93X)
782 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
783 card->shortname, pcm->name, chip->wss_base + 4,
784 chip->irq, chip->dma1, chip->dma2);
786 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
787 card->shortname, pcm->name, chip->wss_base + 4,
788 chip->irq, chip->dma1);
789 #endif /* CS4231 || OPTi93X */
791 if (chip->mpu_port <= 0 || chip->mpu_port == SNDRV_AUTO_PORT)
794 if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
795 chip->mpu_port, 0, chip->mpu_irq, IRQF_DISABLED,
797 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
800 if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) {
801 struct snd_opl3 *opl3 = NULL;
803 if (chip->hardware == OPTi9XX_HW_82C928 ||
804 chip->hardware == OPTi9XX_HW_82C929 ||
805 chip->hardware == OPTi9XX_HW_82C924) {
806 struct snd_opl4 *opl4;
807 /* assume we have an OPL4 */
808 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
810 if (snd_opl4_create(card,
813 2, &opl3, &opl4) < 0) {
814 /* no luck, use OPL3 instead */
815 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
819 #endif /* !OPTi93X */
820 if (!opl3 && snd_opl3_create(card,
823 OPL3_HW_AUTO, 0, &opl3) < 0) {
824 snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
825 chip->fm_port, chip->fm_port + 4 - 1);
833 if ((error = snd_opl3_timer_new(opl3, t1dev, t1dev+1)) < 0)
835 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, &synth)) < 0)
840 return snd_card_register(card);
843 static struct snd_card *snd_opti9xx_card_new(void)
845 struct snd_card *card;
847 card = snd_card_new(index, id, THIS_MODULE, sizeof(struct snd_opti9xx));
850 card->private_free = snd_card_opti9xx_free;
854 static int __devinit snd_opti9xx_isa_match(struct device *devptr,
858 if (snd_opti9xx_pnp_is_probed)
866 static int __devinit snd_opti9xx_isa_probe(struct device *devptr,
869 struct snd_card *card;
871 static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};
873 static int possible_irqs[] = {5, 9, 10, 11, 7, -1};
875 static int possible_irqs[] = {9, 10, 11, 7, -1};
877 static int possible_mpu_irqs[] = {5, 9, 10, 7, -1};
878 static int possible_dma1s[] = {3, 1, 0, -1};
879 #if defined(CS4231) || defined(OPTi93X)
880 static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
881 #endif /* CS4231 || OPTi93X */
883 if (mpu_port == SNDRV_AUTO_PORT) {
884 if ((mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
885 snd_printk(KERN_ERR "unable to find a free MPU401 port\n");
889 if (irq == SNDRV_AUTO_IRQ) {
890 if ((irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
891 snd_printk(KERN_ERR "unable to find a free IRQ\n");
895 if (mpu_irq == SNDRV_AUTO_IRQ) {
896 if ((mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
897 snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n");
901 if (dma1 == SNDRV_AUTO_DMA) {
902 if ((dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
903 snd_printk(KERN_ERR "unable to find a free DMA1\n");
907 #if defined(CS4231) || defined(OPTi93X)
908 if (dma2 == SNDRV_AUTO_DMA) {
909 if ((dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4])) < 0) {
910 snd_printk("unable to find a free DMA2\n");
916 card = snd_opti9xx_card_new();
920 if ((error = snd_card_opti9xx_detect(card, card->private_data)) < 0) {
924 snd_card_set_dev(card, devptr);
925 if ((error = snd_opti9xx_probe(card)) < 0) {
929 dev_set_drvdata(devptr, card);
933 static int __devexit snd_opti9xx_isa_remove(struct device *devptr,
936 snd_card_free(dev_get_drvdata(devptr));
937 dev_set_drvdata(devptr, NULL);
941 static struct isa_driver snd_opti9xx_driver = {
942 .match = snd_opti9xx_isa_match,
943 .probe = snd_opti9xx_isa_probe,
944 .remove = __devexit_p(snd_opti9xx_isa_remove),
945 /* FIXME: suspend/resume */
952 static int __devinit snd_opti9xx_pnp_probe(struct pnp_card_link *pcard,
953 const struct pnp_card_device_id *pid)
955 struct snd_card *card;
957 struct snd_opti9xx *chip;
959 if (snd_opti9xx_pnp_is_probed)
963 card = snd_opti9xx_card_new();
966 chip = card->private_data;
968 hw = snd_card_opti9xx_pnp(chip, pcard, pid);
971 hw = OPTi9XX_HW_82C924;
974 hw = OPTi9XX_HW_82C925;
977 hw = OPTi9XX_HW_82C931;
984 if ((error = snd_opti9xx_init(chip, hw))) {
988 if (hw <= OPTi9XX_HW_82C930)
989 chip->mc_base -= 0x80;
990 snd_card_set_dev(card, &pcard->card->dev);
991 if ((error = snd_opti9xx_probe(card)) < 0) {
995 pnp_set_card_drvdata(pcard, card);
996 snd_opti9xx_pnp_is_probed = 1;
1000 static void __devexit snd_opti9xx_pnp_remove(struct pnp_card_link * pcard)
1002 snd_card_free(pnp_get_card_drvdata(pcard));
1003 pnp_set_card_drvdata(pcard, NULL);
1004 snd_opti9xx_pnp_is_probed = 0;
1007 static struct pnp_card_driver opti9xx_pnpc_driver = {
1008 .flags = PNP_DRIVER_RES_DISABLE,
1010 .id_table = snd_opti9xx_pnpids,
1011 .probe = snd_opti9xx_pnp_probe,
1012 .remove = __devexit_p(snd_opti9xx_pnp_remove),
1017 #define CHIP_NAME "82C93x"
1019 #define CHIP_NAME "82C92x"
1022 static int __init alsa_card_opti9xx_init(void)
1025 pnp_register_card_driver(&opti9xx_pnpc_driver);
1026 if (snd_opti9xx_pnp_is_probed)
1028 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
1030 return isa_register_driver(&snd_opti9xx_driver, 1);
1033 static void __exit alsa_card_opti9xx_exit(void)
1035 if (!snd_opti9xx_pnp_is_probed) {
1036 isa_unregister_driver(&snd_opti9xx_driver);
1040 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
1044 module_init(alsa_card_opti9xx_init)
1045 module_exit(alsa_card_opti9xx_exit)