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 */
72 static int isapnp = 1; /* Enable ISA PnP detection */
74 static long port = SNDRV_DEFAULT_PORT1; /* 0x530,0xe80,0xf40,0x604 */
75 static long mpu_port = SNDRV_DEFAULT_PORT1; /* 0x300,0x310,0x320,0x330 */
76 static long fm_port = SNDRV_DEFAULT_PORT1; /* 0x388 */
77 static int irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10,11 */
78 static int mpu_irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10 */
79 static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
80 #if defined(CS4231) || defined(OPTi93X)
81 static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
82 #endif /* CS4231 || OPTi93X */
84 module_param(index, int, 0444);
85 MODULE_PARM_DESC(index, "Index value for opti9xx based soundcard.");
86 module_param(id, charp, 0444);
87 MODULE_PARM_DESC(id, "ID string for opti9xx based soundcard.");
88 //module_param(enable, bool, 0444);
89 //MODULE_PARM_DESC(enable, "Enable opti9xx soundcard.");
91 module_param(isapnp, bool, 0444);
92 MODULE_PARM_DESC(isapnp, "Enable ISA PnP detection for specified soundcard.");
94 module_param(port, long, 0444);
95 MODULE_PARM_DESC(port, "WSS port # for opti9xx driver.");
96 module_param(mpu_port, long, 0444);
97 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for opti9xx driver.");
98 module_param(fm_port, long, 0444);
99 MODULE_PARM_DESC(fm_port, "FM port # for opti9xx driver.");
100 module_param(irq, int, 0444);
101 MODULE_PARM_DESC(irq, "WSS irq # for opti9xx driver.");
102 module_param(mpu_irq, int, 0444);
103 MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for opti9xx driver.");
104 module_param(dma1, int, 0444);
105 MODULE_PARM_DESC(dma1, "1st dma # for opti9xx driver.");
106 #if defined(CS4231) || defined(OPTi93X)
107 module_param(dma2, int, 0444);
108 MODULE_PARM_DESC(dma2, "2nd dma # for opti9xx driver.");
109 #endif /* CS4231 || OPTi93X */
111 #define OPTi9XX_HW_82C928 1
112 #define OPTi9XX_HW_82C929 2
113 #define OPTi9XX_HW_82C924 3
114 #define OPTi9XX_HW_82C925 4
115 #define OPTi9XX_HW_82C930 5
116 #define OPTi9XX_HW_82C931 6
117 #define OPTi9XX_HW_82C933 7
118 #define OPTi9XX_HW_LAST OPTi9XX_HW_82C933
120 #define OPTi9XX_MC_REG(n) n
124 #define OPTi93X_STATUS 0x02
125 #define OPTi93X_PORT(chip, r) ((chip)->port + OPTi93X_##r)
127 #define OPTi93X_IRQ_PLAYBACK 0x04
128 #define OPTi93X_IRQ_CAPTURE 0x08
133 unsigned short hardware;
134 unsigned char password;
137 unsigned long mc_base;
138 struct resource *res_mc_base;
139 unsigned long mc_base_size;
141 unsigned long mc_indir_index;
142 struct snd_cs4231 *codec;
144 unsigned long pwd_reg;
151 #if defined(CS4231) || defined(OPTi93X)
153 #endif /* CS4231 || OPTi93X */
162 struct pnp_dev *devmpu;
163 #endif /* CONFIG_PNP */
166 static int snd_opti9xx_pnp_is_probed;
170 static struct pnp_card_device_id snd_opti9xx_pnpids[] = {
173 { .id = "OPT0924", .devs = { { "OPT0000" }, { "OPT0002" } }, .driver_data = 0x0924 },
175 { .id = "OPT0925", .devs = { { "OPT9250" }, { "OPT0002" } }, .driver_data = 0x0925 },
178 { .id = "OPT0931", .devs = { { "OPT9310" }, { "OPT0002" } }, .driver_data = 0x0931 },
183 MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids);
185 #endif /* CONFIG_PNP */
188 #define DEV_NAME "opti93x"
190 #define DEV_NAME "opti92x"
193 static char * snd_opti9xx_names[] = {
197 "82C930", "82C931", "82C933"
201 static long __devinit snd_legacy_find_free_ioport(long *port_table, long size)
203 while (*port_table != -1) {
204 if (request_region(*port_table, size, "ALSA test")) {
205 release_region(*port_table, size);
213 static int __devinit snd_opti9xx_init(struct snd_opti9xx *chip,
214 unsigned short hardware)
216 static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
218 chip->hardware = hardware;
219 strcpy(chip->name, snd_opti9xx_names[hardware]);
221 chip->mc_base_size = opti9xx_mc_size[hardware];
223 spin_lock_init(&chip->lock);
228 #if defined(CS4231) || defined (OPTi93X)
230 #endif /* CS4231 || OPTi93X */
237 case OPTi9XX_HW_82C928:
238 case OPTi9XX_HW_82C929:
239 chip->mc_base = 0xf8c;
240 chip->password = (hardware == OPTi9XX_HW_82C928) ? 0xe2 : 0xe3;
244 case OPTi9XX_HW_82C924:
245 case OPTi9XX_HW_82C925:
246 chip->mc_base = 0xf8c;
247 chip->password = 0xe5;
252 case OPTi9XX_HW_82C930:
253 case OPTi9XX_HW_82C931:
254 case OPTi9XX_HW_82C933:
255 chip->mc_base = (hardware == OPTi9XX_HW_82C930) ? 0xf8f : 0xf8d;
256 chip->mc_indir_index = 0xe0e;
257 chip->password = 0xe4;
263 snd_printk("chip %d not supported\n", hardware);
269 static unsigned char snd_opti9xx_read(struct snd_opti9xx *chip,
273 unsigned char retval = 0xff;
275 spin_lock_irqsave(&chip->lock, flags);
276 outb(chip->password, chip->mc_base + chip->pwd_reg);
278 switch (chip->hardware) {
280 case OPTi9XX_HW_82C924:
281 case OPTi9XX_HW_82C925:
283 outb(reg, chip->mc_base + 8);
284 outb(chip->password, chip->mc_base + chip->pwd_reg);
285 retval = inb(chip->mc_base + 9);
289 case OPTi9XX_HW_82C928:
290 case OPTi9XX_HW_82C929:
291 retval = inb(chip->mc_base + reg);
295 case OPTi9XX_HW_82C930:
296 case OPTi9XX_HW_82C931:
297 case OPTi9XX_HW_82C933:
298 outb(reg, chip->mc_indir_index);
299 outb(chip->password, chip->mc_base + chip->pwd_reg);
300 retval = inb(chip->mc_indir_index + 1);
305 snd_printk("chip %d not supported\n", chip->hardware);
308 spin_unlock_irqrestore(&chip->lock, flags);
312 static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg,
317 spin_lock_irqsave(&chip->lock, flags);
318 outb(chip->password, chip->mc_base + chip->pwd_reg);
320 switch (chip->hardware) {
322 case OPTi9XX_HW_82C924:
323 case OPTi9XX_HW_82C925:
325 outb(reg, chip->mc_base + 8);
326 outb(chip->password, chip->mc_base + chip->pwd_reg);
327 outb(value, chip->mc_base + 9);
331 case OPTi9XX_HW_82C928:
332 case OPTi9XX_HW_82C929:
333 outb(value, chip->mc_base + reg);
337 case OPTi9XX_HW_82C930:
338 case OPTi9XX_HW_82C931:
339 case OPTi9XX_HW_82C933:
340 outb(reg, chip->mc_indir_index);
341 outb(chip->password, chip->mc_base + chip->pwd_reg);
342 outb(value, chip->mc_indir_index + 1);
347 snd_printk("chip %d not supported\n", chip->hardware);
350 spin_unlock_irqrestore(&chip->lock, flags);
354 #define snd_opti9xx_write_mask(chip, reg, value, mask) \
355 snd_opti9xx_write(chip, reg, \
356 (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask)))
359 static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip)
361 unsigned char wss_base_bits;
362 unsigned char irq_bits;
363 unsigned char dma_bits;
364 unsigned char mpu_port_bits = 0;
365 unsigned char mpu_irq_bits;
367 switch (chip->hardware) {
369 case OPTi9XX_HW_82C924:
370 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0xf0, 0xfc);
371 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
373 case OPTi9XX_HW_82C925:
374 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
375 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
376 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
378 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
380 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
384 case OPTi9XX_HW_82C928:
385 case OPTi9XX_HW_82C929:
386 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
387 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
389 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xa2, 0xae);
391 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
393 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
395 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
400 case OPTi9XX_HW_82C931:
401 case OPTi9XX_HW_82C933:
403 * The BTC 1817DW has QS1000 wavetable which is connected
404 * to the serial digital input of the OPTI931.
406 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(21), 0x82, 0xff);
408 * This bit sets OPTI931 to automaticaly select FM
409 * or digital input signal.
411 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(26), 0x01, 0x01);
412 case OPTi9XX_HW_82C930: /* FALL THROUGH */
413 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x03);
414 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0x00, 0xff);
415 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x10 |
416 (chip->hardware == OPTi9XX_HW_82C930 ? 0x00 : 0x04),
418 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x20, 0xbf);
423 snd_printk("chip %d not supported\n", chip->hardware);
427 switch (chip->wss_base) {
429 wss_base_bits = 0x00;
432 wss_base_bits = 0x03;
435 wss_base_bits = 0x01;
438 wss_base_bits = 0x02;
441 snd_printk("WSS port 0x%lx not valid\n", chip->wss_base);
444 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
452 //#endif /* OPTi93X */
466 snd_printk("WSS irq # %d not valid\n", chip->irq);
467 goto __skip_resources;
470 switch (chip->dma1) {
481 snd_printk("WSS dma1 # %d not valid\n", chip->dma1);
482 goto __skip_resources;
485 #if defined(CS4231) || defined(OPTi93X)
486 if (chip->dma1 == chip->dma2) {
487 snd_printk("don't want to share dmas\n");
491 switch (chip->dma2) {
496 snd_printk("WSS dma2 # %d not valid\n", chip->dma2);
497 goto __skip_resources;
500 #endif /* CS4231 || OPTi93X */
503 outb(irq_bits << 3 | dma_bits, chip->wss_base);
505 snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits));
509 if (chip->hardware > OPTi9XX_HW_82C928) {
510 switch (chip->mpu_port) {
515 mpu_port_bits = 0x03;
518 mpu_port_bits = 0x02;
521 mpu_port_bits = 0x01;
524 mpu_port_bits = 0x00;
527 snd_printk("MPU-401 port 0x%lx not valid\n",
532 switch (chip->mpu_irq) {
546 snd_printk("MPU-401 irq # %d not valid\n",
551 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6),
552 (chip->mpu_port <= 0) ? 0x00 :
553 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
563 static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id)
565 struct snd_cs4231 *codec = dev_id;
566 struct snd_opti9xx *chip = codec->card->private_data;
567 unsigned char status;
569 status = snd_opti9xx_read(chip, OPTi9XX_MC_REG(11));
570 if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream)
571 snd_pcm_period_elapsed(codec->playback_substream);
572 if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) {
573 snd_cs4231_overrange(codec);
574 snd_pcm_period_elapsed(codec->capture_substream);
576 outb(0x00, OPTi93X_PORT(codec, STATUS));
582 static int __devinit snd_card_opti9xx_detect(struct snd_card *card,
583 struct snd_opti9xx *chip)
588 for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) {
591 if ((err = snd_opti9xx_init(chip, i)) < 0)
594 if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL)
597 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1));
598 if ((value != 0xff) && (value != inb(chip->mc_base + 1)))
599 if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)))
602 release_and_free_resource(chip->res_mc_base);
603 chip->res_mc_base = NULL;
607 for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) {
611 if ((err = snd_opti9xx_init(chip, i)) < 0)
614 if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL)
617 spin_lock_irqsave(&chip->lock, flags);
618 outb(chip->password, chip->mc_base + chip->pwd_reg);
619 outb(((chip->mc_indir_index & (1 << 8)) >> 4) |
620 ((chip->mc_indir_index & 0xf0) >> 4), chip->mc_base);
621 spin_unlock_irqrestore(&chip->lock, flags);
623 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7));
624 snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value);
625 if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value)
628 release_and_free_resource(chip->res_mc_base);
629 chip->res_mc_base = NULL;
637 static int __devinit snd_card_opti9xx_pnp(struct snd_opti9xx *chip,
638 struct pnp_card_link *card,
639 const struct pnp_card_device_id *pid)
641 struct pnp_dev *pdev;
644 chip->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
645 if (chip->dev == NULL)
648 chip->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
652 err = pnp_activate_dev(pdev);
654 snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err);
659 port = pnp_port_start(pdev, 0) - 4;
660 fm_port = pnp_port_start(pdev, 1) + 8;
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_cs4231 *codec = chip->codec;
695 if (codec && codec->irq > 0) {
696 disable_irq(codec->irq);
697 free_irq(codec->irq, codec);
700 release_and_free_resource(chip->res_mc_base);
704 static int __devinit snd_opti9xx_probe(struct snd_card *card)
706 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
708 struct snd_opti9xx *chip = card->private_data;
709 #if defined(CS4231) || defined(OPTi93X)
710 struct snd_cs4231 *codec;
712 struct snd_timer *timer;
715 struct snd_ad1848 *codec;
718 struct snd_rawmidi *rmidi;
719 struct snd_hwdep *synth;
721 if (! chip->res_mc_base &&
722 (chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size,
723 "OPTi9xx MC")) == NULL)
726 chip->wss_base = port;
727 chip->fm_port = fm_port;
728 chip->mpu_port = mpu_port;
730 chip->mpu_irq = mpu_irq;
732 #if defined(CS4231) || defined(OPTi93X)
736 if (chip->wss_base == SNDRV_AUTO_PORT) {
737 if ((chip->wss_base = snd_legacy_find_free_ioport(possible_ports, 4)) < 0) {
738 snd_printk("unable to find a free WSS port\n");
742 if ((error = snd_opti9xx_configure(chip)))
745 #if defined(CS4231) || defined(OPTi93X)
746 if ((error = snd_cs4231_create(card, chip->wss_base + 4, -1,
747 chip->irq, chip->dma1, chip->dma2,
751 CS4231_HW_OPTI93X, CS4231_HWSHARE_IRQ,
758 if ((error = snd_cs4231_pcm(codec, 0, &pcm)) < 0)
760 if ((error = snd_cs4231_mixer(codec)) < 0)
763 if ((error = snd_cs4231_timer(codec, 0, &timer)) < 0)
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);
774 if ((error = snd_ad1848_create(card, chip->wss_base + 4,
775 chip->irq, chip->dma1,
776 AD1848_HW_DETECT, &codec)) < 0)
778 if ((error = snd_ad1848_pcm(codec, 0, &pcm)) < 0)
780 if ((error = snd_ad1848_mixer(codec)) < 0)
783 strcpy(card->driver, chip->name);
784 sprintf(card->shortname, "OPTi %s", card->driver);
785 #if defined(CS4231) || defined(OPTi93X)
786 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
787 card->shortname, pcm->name, chip->wss_base + 4,
788 chip->irq, chip->dma1, chip->dma2);
790 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
791 card->shortname, pcm->name, chip->wss_base + 4,
792 chip->irq, chip->dma1);
793 #endif /* CS4231 || OPTi93X */
795 if (chip->mpu_port <= 0 || chip->mpu_port == SNDRV_AUTO_PORT)
798 if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
799 chip->mpu_port, 0, chip->mpu_irq, IRQF_DISABLED,
801 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
804 if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) {
805 struct snd_opl3 *opl3 = NULL;
807 if (chip->hardware == OPTi9XX_HW_82C928 ||
808 chip->hardware == OPTi9XX_HW_82C929 ||
809 chip->hardware == OPTi9XX_HW_82C924) {
810 struct snd_opl4 *opl4;
811 /* assume we have an OPL4 */
812 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
814 if (snd_opl4_create(card,
817 2, &opl3, &opl4) < 0) {
818 /* no luck, use OPL3 instead */
819 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
823 #endif /* !OPTi93X */
824 if (!opl3 && snd_opl3_create(card,
827 OPL3_HW_AUTO, 0, &opl3) < 0) {
828 snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
829 chip->fm_port, chip->fm_port + 4 - 1);
837 if ((error = snd_opl3_timer_new(opl3, t1dev, t1dev+1)) < 0)
839 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, &synth)) < 0)
844 return snd_card_register(card);
847 static struct snd_card *snd_opti9xx_card_new(void)
849 struct snd_card *card;
851 card = snd_card_new(index, id, THIS_MODULE, sizeof(struct snd_opti9xx));
854 card->private_free = snd_card_opti9xx_free;
858 static int __devinit snd_opti9xx_isa_match(struct device *devptr,
862 if (snd_opti9xx_pnp_is_probed)
870 static int __devinit snd_opti9xx_isa_probe(struct device *devptr,
873 struct snd_card *card;
875 static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};
877 static int possible_irqs[] = {5, 9, 10, 11, 7, -1};
879 static int possible_irqs[] = {9, 10, 11, 7, -1};
881 static int possible_mpu_irqs[] = {5, 9, 10, 7, -1};
882 static int possible_dma1s[] = {3, 1, 0, -1};
883 #if defined(CS4231) || defined(OPTi93X)
884 static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
885 #endif /* CS4231 || OPTi93X */
887 if (mpu_port == SNDRV_AUTO_PORT) {
888 if ((mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
889 snd_printk(KERN_ERR "unable to find a free MPU401 port\n");
893 if (irq == SNDRV_AUTO_IRQ) {
894 if ((irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
895 snd_printk(KERN_ERR "unable to find a free IRQ\n");
899 if (mpu_irq == SNDRV_AUTO_IRQ) {
900 if ((mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
901 snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n");
905 if (dma1 == SNDRV_AUTO_DMA) {
906 if ((dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
907 snd_printk(KERN_ERR "unable to find a free DMA1\n");
911 #if defined(CS4231) || defined(OPTi93X)
912 if (dma2 == SNDRV_AUTO_DMA) {
913 if ((dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4])) < 0) {
914 snd_printk("unable to find a free DMA2\n");
920 card = snd_opti9xx_card_new();
924 if ((error = snd_card_opti9xx_detect(card, card->private_data)) < 0) {
928 snd_card_set_dev(card, devptr);
929 if ((error = snd_opti9xx_probe(card)) < 0) {
933 dev_set_drvdata(devptr, card);
937 static int __devexit snd_opti9xx_isa_remove(struct device *devptr,
940 snd_card_free(dev_get_drvdata(devptr));
941 dev_set_drvdata(devptr, NULL);
945 static struct isa_driver snd_opti9xx_driver = {
946 .match = snd_opti9xx_isa_match,
947 .probe = snd_opti9xx_isa_probe,
948 .remove = __devexit_p(snd_opti9xx_isa_remove),
949 /* FIXME: suspend/resume */
956 static int __devinit snd_opti9xx_pnp_probe(struct pnp_card_link *pcard,
957 const struct pnp_card_device_id *pid)
959 struct snd_card *card;
961 struct snd_opti9xx *chip;
963 if (snd_opti9xx_pnp_is_probed)
967 card = snd_opti9xx_card_new();
970 chip = card->private_data;
972 hw = snd_card_opti9xx_pnp(chip, pcard, pid);
975 hw = OPTi9XX_HW_82C924;
978 hw = OPTi9XX_HW_82C925;
981 hw = OPTi9XX_HW_82C931;
988 if ((error = snd_opti9xx_init(chip, hw))) {
992 if (hw <= OPTi9XX_HW_82C930)
993 chip->mc_base -= 0x80;
994 snd_card_set_dev(card, &pcard->card->dev);
995 if ((error = snd_opti9xx_probe(card)) < 0) {
999 pnp_set_card_drvdata(pcard, card);
1000 snd_opti9xx_pnp_is_probed = 1;
1004 static void __devexit snd_opti9xx_pnp_remove(struct pnp_card_link * pcard)
1006 snd_card_free(pnp_get_card_drvdata(pcard));
1007 pnp_set_card_drvdata(pcard, NULL);
1008 snd_opti9xx_pnp_is_probed = 0;
1011 static struct pnp_card_driver opti9xx_pnpc_driver = {
1012 .flags = PNP_DRIVER_RES_DISABLE,
1014 .id_table = snd_opti9xx_pnpids,
1015 .probe = snd_opti9xx_pnp_probe,
1016 .remove = __devexit_p(snd_opti9xx_pnp_remove),
1021 #define CHIP_NAME "82C93x"
1023 #define CHIP_NAME "82C92x"
1026 static int __init alsa_card_opti9xx_init(void)
1029 pnp_register_card_driver(&opti9xx_pnpc_driver);
1030 if (snd_opti9xx_pnp_is_probed)
1032 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
1034 return isa_register_driver(&snd_opti9xx_driver, 1);
1037 static void __exit alsa_card_opti9xx_exit(void)
1039 if (!snd_opti9xx_pnp_is_probed) {
1040 isa_unregister_driver(&snd_opti9xx_driver);
1044 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
1048 module_init(alsa_card_opti9xx_init)
1049 module_exit(alsa_card_opti9xx_exit)