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/tlv.h>
37 #include <sound/wss.h>
38 #include <sound/mpu401.h>
39 #include <sound/opl3.h>
41 #include <sound/opl4.h>
43 #define SNDRV_LEGACY_FIND_FREE_IRQ
44 #define SNDRV_LEGACY_FIND_FREE_DMA
45 #include <sound/initval.h>
47 MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
48 MODULE_LICENSE("GPL");
50 MODULE_DESCRIPTION("OPTi93X");
51 MODULE_SUPPORTED_DEVICE("{{OPTi,82C931/3}}");
54 MODULE_DESCRIPTION("OPTi92X - CS4231");
55 MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (CS4231)},"
56 "{OPTi,82C925 (CS4231)}}");
58 MODULE_DESCRIPTION("OPTi92X - AD1848");
59 MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (AD1848)},"
60 "{OPTi,82C925 (AD1848)},"
65 static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
66 static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
67 //static int enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */
69 static int isapnp = 1; /* Enable ISA PnP detection */
71 static long port = SNDRV_DEFAULT_PORT1; /* 0x530,0xe80,0xf40,0x604 */
72 static long mpu_port = SNDRV_DEFAULT_PORT1; /* 0x300,0x310,0x320,0x330 */
73 static long fm_port = SNDRV_DEFAULT_PORT1; /* 0x388 */
74 static int irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10,11 */
75 static int mpu_irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10 */
76 static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
77 #if defined(CS4231) || defined(OPTi93X)
78 static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
79 #endif /* CS4231 || OPTi93X */
81 module_param(index, int, 0444);
82 MODULE_PARM_DESC(index, "Index value for opti9xx based soundcard.");
83 module_param(id, charp, 0444);
84 MODULE_PARM_DESC(id, "ID string for opti9xx based soundcard.");
85 //module_param(enable, bool, 0444);
86 //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.");
91 module_param(port, long, 0444);
92 MODULE_PARM_DESC(port, "WSS port # for opti9xx driver.");
93 module_param(mpu_port, long, 0444);
94 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for opti9xx driver.");
95 module_param(fm_port, long, 0444);
96 MODULE_PARM_DESC(fm_port, "FM port # for opti9xx driver.");
97 module_param(irq, int, 0444);
98 MODULE_PARM_DESC(irq, "WSS irq # for opti9xx driver.");
99 module_param(mpu_irq, int, 0444);
100 MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for opti9xx driver.");
101 module_param(dma1, int, 0444);
102 MODULE_PARM_DESC(dma1, "1st dma # for opti9xx driver.");
103 #if defined(CS4231) || defined(OPTi93X)
104 module_param(dma2, int, 0444);
105 MODULE_PARM_DESC(dma2, "2nd dma # for opti9xx driver.");
106 #endif /* CS4231 || OPTi93X */
108 #define OPTi9XX_HW_82C928 1
109 #define OPTi9XX_HW_82C929 2
110 #define OPTi9XX_HW_82C924 3
111 #define OPTi9XX_HW_82C925 4
112 #define OPTi9XX_HW_82C930 5
113 #define OPTi9XX_HW_82C931 6
114 #define OPTi9XX_HW_82C933 7
115 #define OPTi9XX_HW_LAST OPTi9XX_HW_82C933
117 #define OPTi9XX_MC_REG(n) n
121 #define OPTi93X_STATUS 0x02
122 #define OPTi93X_PORT(chip, r) ((chip)->port + OPTi93X_##r)
124 #define OPTi93X_IRQ_PLAYBACK 0x04
125 #define OPTi93X_IRQ_CAPTURE 0x08
130 unsigned short hardware;
131 unsigned char password;
134 unsigned long mc_base;
135 struct resource *res_mc_base;
136 unsigned long mc_base_size;
138 unsigned long mc_indir_index;
139 unsigned long mc_indir_size;
140 struct resource *res_mc_indir;
141 struct snd_wss *codec;
143 unsigned long pwd_reg;
151 struct pnp_dev *devmpu;
152 #endif /* CONFIG_PNP */
155 static int snd_opti9xx_pnp_is_probed;
159 static struct pnp_card_device_id snd_opti9xx_pnpids[] = {
162 { .id = "OPT0924", .devs = { { "OPT0000" }, { "OPT0002" } }, .driver_data = 0x0924 },
164 { .id = "OPT0925", .devs = { { "OPT9250" }, { "OPT0002" } }, .driver_data = 0x0925 },
167 { .id = "OPT0931", .devs = { { "OPT9310" }, { "OPT0002" } }, .driver_data = 0x0931 },
172 MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids);
174 #endif /* CONFIG_PNP */
177 #define DEV_NAME "opti93x"
179 #define DEV_NAME "opti92x"
182 static char * snd_opti9xx_names[] = {
186 "82C930", "82C931", "82C933"
190 static long __devinit snd_legacy_find_free_ioport(long *port_table, long size)
192 while (*port_table != -1) {
193 if (request_region(*port_table, size, "ALSA test")) {
194 release_region(*port_table, size);
202 static int __devinit snd_opti9xx_init(struct snd_opti9xx *chip,
203 unsigned short hardware)
205 static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
207 chip->hardware = hardware;
208 strcpy(chip->name, snd_opti9xx_names[hardware]);
210 chip->mc_base_size = opti9xx_mc_size[hardware];
212 spin_lock_init(&chip->lock);
218 case OPTi9XX_HW_82C928:
219 case OPTi9XX_HW_82C929:
220 chip->mc_base = 0xf8c;
221 chip->password = (hardware == OPTi9XX_HW_82C928) ? 0xe2 : 0xe3;
225 case OPTi9XX_HW_82C924:
226 case OPTi9XX_HW_82C925:
227 chip->mc_base = 0xf8c;
228 chip->password = 0xe5;
233 case OPTi9XX_HW_82C930:
234 case OPTi9XX_HW_82C931:
235 case OPTi9XX_HW_82C933:
236 chip->mc_base = (hardware == OPTi9XX_HW_82C930) ? 0xf8f : 0xf8d;
237 if (!chip->mc_indir_index) {
238 chip->mc_indir_index = 0xe0e;
239 chip->mc_indir_size = 2;
241 chip->password = 0xe4;
247 snd_printk(KERN_ERR "chip %d not supported\n", hardware);
253 static unsigned char snd_opti9xx_read(struct snd_opti9xx *chip,
257 unsigned char retval = 0xff;
259 spin_lock_irqsave(&chip->lock, flags);
260 outb(chip->password, chip->mc_base + chip->pwd_reg);
262 switch (chip->hardware) {
264 case OPTi9XX_HW_82C924:
265 case OPTi9XX_HW_82C925:
267 outb(reg, chip->mc_base + 8);
268 outb(chip->password, chip->mc_base + chip->pwd_reg);
269 retval = inb(chip->mc_base + 9);
273 case OPTi9XX_HW_82C928:
274 case OPTi9XX_HW_82C929:
275 retval = inb(chip->mc_base + reg);
279 case OPTi9XX_HW_82C930:
280 case OPTi9XX_HW_82C931:
281 case OPTi9XX_HW_82C933:
282 outb(reg, chip->mc_indir_index);
283 outb(chip->password, chip->mc_base + chip->pwd_reg);
284 retval = inb(chip->mc_indir_index + 1);
289 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
292 spin_unlock_irqrestore(&chip->lock, flags);
296 static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg,
301 spin_lock_irqsave(&chip->lock, flags);
302 outb(chip->password, chip->mc_base + chip->pwd_reg);
304 switch (chip->hardware) {
306 case OPTi9XX_HW_82C924:
307 case OPTi9XX_HW_82C925:
309 outb(reg, chip->mc_base + 8);
310 outb(chip->password, chip->mc_base + chip->pwd_reg);
311 outb(value, chip->mc_base + 9);
315 case OPTi9XX_HW_82C928:
316 case OPTi9XX_HW_82C929:
317 outb(value, chip->mc_base + reg);
321 case OPTi9XX_HW_82C930:
322 case OPTi9XX_HW_82C931:
323 case OPTi9XX_HW_82C933:
324 outb(reg, chip->mc_indir_index);
325 outb(chip->password, chip->mc_base + chip->pwd_reg);
326 outb(value, chip->mc_indir_index + 1);
331 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
334 spin_unlock_irqrestore(&chip->lock, flags);
338 #define snd_opti9xx_write_mask(chip, reg, value, mask) \
339 snd_opti9xx_write(chip, reg, \
340 (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask)))
343 static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip,
345 int irq, int dma1, int dma2,
346 long mpu_port, int mpu_irq)
348 unsigned char wss_base_bits;
349 unsigned char irq_bits;
350 unsigned char dma_bits;
351 unsigned char mpu_port_bits = 0;
352 unsigned char mpu_irq_bits;
354 switch (chip->hardware) {
356 case OPTi9XX_HW_82C924:
357 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0xf0, 0xfc);
358 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
360 case OPTi9XX_HW_82C925:
361 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
362 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
363 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
365 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
367 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
371 case OPTi9XX_HW_82C928:
372 case OPTi9XX_HW_82C929:
373 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
374 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
376 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xa2, 0xae);
378 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
380 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
382 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
387 case OPTi9XX_HW_82C931:
388 case OPTi9XX_HW_82C933:
390 * The BTC 1817DW has QS1000 wavetable which is connected
391 * to the serial digital input of the OPTI931.
393 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(21), 0x82, 0xff);
395 * This bit sets OPTI931 to automaticaly select FM
396 * or digital input signal.
398 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(26), 0x01, 0x01);
399 case OPTi9XX_HW_82C930: /* FALL THROUGH */
400 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x03);
401 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0x00, 0xff);
402 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x10 |
403 (chip->hardware == OPTi9XX_HW_82C930 ? 0x00 : 0x04),
405 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x20, 0xbf);
410 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
416 wss_base_bits = 0x00;
419 wss_base_bits = 0x03;
422 wss_base_bits = 0x01;
425 wss_base_bits = 0x02;
428 snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n", wss_base);
431 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
439 //#endif /* OPTi93X */
453 snd_printk(KERN_WARNING "WSS irq # %d not valid\n", irq);
454 goto __skip_resources;
468 snd_printk(KERN_WARNING "WSS dma1 # %d not valid\n", dma1);
469 goto __skip_resources;
472 #if defined(CS4231) || defined(OPTi93X)
474 snd_printk(KERN_ERR "don't want to share dmas\n");
483 snd_printk(KERN_WARNING "WSS dma2 # %d not valid\n", dma2);
484 goto __skip_resources;
487 #endif /* CS4231 || OPTi93X */
490 outb(irq_bits << 3 | dma_bits, wss_base);
492 snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits));
496 if (chip->hardware > OPTi9XX_HW_82C928) {
502 mpu_port_bits = 0x03;
505 mpu_port_bits = 0x02;
508 mpu_port_bits = 0x01;
511 mpu_port_bits = 0x00;
514 snd_printk(KERN_WARNING
515 "MPU-401 port 0x%lx not valid\n", mpu_port);
533 snd_printk(KERN_WARNING "MPU-401 irq # %d not valid\n",
538 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6),
539 (mpu_port <= 0) ? 0x00 :
540 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
550 static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_step, -9300, 300, 0);
551 static const DECLARE_TLV_DB_SCALE(db_scale_5bit, -4650, 150, 0);
552 static const DECLARE_TLV_DB_SCALE(db_scale_4bit_12db_max, -3300, 300, 0);
554 static struct snd_kcontrol_new snd_opti93x_controls[] = {
555 WSS_DOUBLE("Master Playback Switch", 0,
556 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
557 WSS_DOUBLE_TLV("Master Playback Volume", 0,
558 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1,
559 db_scale_5bit_3db_step),
560 WSS_DOUBLE_TLV("PCM Playback Volume", 0,
561 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 31, 1,
563 WSS_DOUBLE_TLV("FM Playback Volume", 0,
564 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 1, 1, 15, 1,
565 db_scale_4bit_12db_max),
566 WSS_DOUBLE("Line Playback Switch", 0,
567 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
568 WSS_DOUBLE_TLV("Line Playback Volume", 0,
569 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 15, 1,
570 db_scale_4bit_12db_max),
571 WSS_DOUBLE("Mic Playback Switch", 0,
572 OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
573 WSS_DOUBLE_TLV("Mic Playback Volume", 0,
574 OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1,
575 db_scale_4bit_12db_max),
576 WSS_DOUBLE_TLV("CD Playback Volume", 0,
577 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 1, 1, 15, 1,
578 db_scale_4bit_12db_max),
579 WSS_DOUBLE("Aux Playback Switch", 0,
580 OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
581 WSS_DOUBLE_TLV("Aux Playback Volume", 0,
582 OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1,
583 db_scale_4bit_12db_max),
586 static int __devinit snd_opti93x_mixer(struct snd_wss *chip)
588 struct snd_card *card;
590 struct snd_ctl_elem_id id1, id2;
593 if (snd_BUG_ON(!chip || !chip->pcm))
598 strcpy(card->mixername, chip->pcm->name);
600 memset(&id1, 0, sizeof(id1));
601 memset(&id2, 0, sizeof(id2));
602 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
603 /* reassign AUX0 switch to CD */
604 strcpy(id1.name, "Aux Playback Switch");
605 strcpy(id2.name, "CD Playback Switch");
606 err = snd_ctl_rename_id(card, &id1, &id2);
608 snd_printk(KERN_ERR "Cannot rename opti93x control\n");
611 /* reassign AUX1 switch to FM */
612 strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
613 strcpy(id2.name, "FM Playback Switch");
614 err = snd_ctl_rename_id(card, &id1, &id2);
616 snd_printk(KERN_ERR "Cannot rename opti93x control\n");
619 /* remove AUX1 volume */
620 strcpy(id1.name, "Aux Playback Volume"); id1.index = 1;
621 snd_ctl_remove_id(card, &id1);
623 /* Replace WSS volume controls with OPTi93x volume controls */
625 for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) {
626 strcpy(id1.name, snd_opti93x_controls[idx].name);
627 snd_ctl_remove_id(card, &id1);
629 err = snd_ctl_add(card,
630 snd_ctl_new1(&snd_opti93x_controls[idx], chip));
637 static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id)
639 struct snd_opti9xx *chip = dev_id;
640 struct snd_wss *codec = chip->codec;
641 unsigned char status;
646 status = snd_opti9xx_read(chip, OPTi9XX_MC_REG(11));
647 if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream)
648 snd_pcm_period_elapsed(codec->playback_substream);
649 if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) {
650 snd_wss_overrange(codec);
651 snd_pcm_period_elapsed(codec->capture_substream);
653 outb(0x00, OPTi93X_PORT(codec, STATUS));
659 static int __devinit snd_opti9xx_read_check(struct snd_opti9xx *chip)
666 chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size,
668 if (chip->res_mc_base == NULL)
671 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1));
672 if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1)))
673 if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)))
676 chip->res_mc_indir = request_region(chip->mc_indir_index,
679 if (chip->res_mc_indir == NULL)
682 spin_lock_irqsave(&chip->lock, flags);
683 outb(chip->password, chip->mc_base + chip->pwd_reg);
684 outb(((chip->mc_indir_index & 0x1f0) >> 4), chip->mc_base);
685 spin_unlock_irqrestore(&chip->lock, flags);
687 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7));
688 snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value);
689 if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value)
692 release_and_free_resource(chip->res_mc_indir);
693 chip->res_mc_indir = NULL;
695 release_and_free_resource(chip->res_mc_base);
696 chip->res_mc_base = NULL;
701 static int __devinit snd_card_opti9xx_detect(struct snd_card *card,
702 struct snd_opti9xx *chip)
707 for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) {
709 for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) {
711 err = snd_opti9xx_init(chip, i);
715 err = snd_opti9xx_read_check(chip);
719 chip->mc_indir_index = 0;
726 static int __devinit snd_card_opti9xx_pnp(struct snd_opti9xx *chip,
727 struct pnp_card_link *card,
728 const struct pnp_card_device_id *pid)
730 struct pnp_dev *pdev;
733 chip->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
734 if (chip->dev == NULL)
737 chip->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
741 err = pnp_activate_dev(pdev);
743 snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err);
748 port = pnp_port_start(pdev, 0) - 4;
749 fm_port = pnp_port_start(pdev, 1) + 8;
750 chip->mc_indir_index = pnp_port_start(pdev, 3) + 2;
751 chip->mc_indir_size = pnp_port_len(pdev, 3) - 2;
753 if (pid->driver_data != 0x0924)
754 port = pnp_port_start(pdev, 1);
755 fm_port = pnp_port_start(pdev, 2) + 8;
757 irq = pnp_irq(pdev, 0);
758 dma1 = pnp_dma(pdev, 0);
759 #if defined(CS4231) || defined(OPTi93X)
760 dma2 = pnp_dma(pdev, 1);
761 #endif /* CS4231 || OPTi93X */
764 if (pdev && mpu_port > 0) {
765 err = pnp_activate_dev(pdev);
767 snd_printk(KERN_ERR "AUDIO pnp configure failure\n");
771 mpu_port = pnp_port_start(pdev, 0);
772 mpu_irq = pnp_irq(pdev, 0);
775 return pid->driver_data;
777 #endif /* CONFIG_PNP */
779 static void snd_card_opti9xx_free(struct snd_card *card)
781 struct snd_opti9xx *chip = card->private_data;
786 disable_irq(chip->irq);
787 free_irq(chip->irq, chip);
789 release_and_free_resource(chip->res_mc_indir);
791 release_and_free_resource(chip->res_mc_base);
795 static int __devinit snd_opti9xx_probe(struct snd_card *card)
797 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
800 struct snd_opti9xx *chip = card->private_data;
801 struct snd_wss *codec;
803 struct snd_timer *timer;
806 struct snd_rawmidi *rmidi;
807 struct snd_hwdep *synth;
809 #if defined(CS4231) || defined(OPTi93X)
815 if (port == SNDRV_AUTO_PORT) {
816 port = snd_legacy_find_free_ioport(possible_ports, 4);
818 snd_printk(KERN_ERR "unable to find a free WSS port\n");
822 error = snd_opti9xx_configure(chip, port, irq, dma1, xdma2,
827 error = snd_wss_create(card, port + 4, -1, irq, dma1, xdma2,
829 WSS_HW_OPTI93X, WSS_HWSHARE_IRQ,
839 error = snd_wss_pcm(codec, 0, &pcm);
842 error = snd_wss_mixer(codec);
846 error = snd_opti93x_mixer(codec);
851 error = snd_wss_timer(codec, 0, &timer);
856 error = request_irq(irq, snd_opti93x_interrupt,
857 IRQF_DISABLED, DEV_NAME" - WSS", chip);
859 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", irq);
864 strcpy(card->driver, chip->name);
865 sprintf(card->shortname, "OPTi %s", card->driver);
866 #if defined(CS4231) || defined(OPTi93X)
867 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
868 card->shortname, pcm->name, port + 4, irq, dma1, xdma2);
870 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
871 card->shortname, pcm->name, port + 4, irq, dma1);
872 #endif /* CS4231 || OPTi93X */
874 if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT)
877 error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
878 mpu_port, 0, mpu_irq, IRQF_DISABLED, &rmidi);
880 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
884 if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
885 struct snd_opl3 *opl3 = NULL;
887 if (chip->hardware == OPTi9XX_HW_82C928 ||
888 chip->hardware == OPTi9XX_HW_82C929 ||
889 chip->hardware == OPTi9XX_HW_82C924) {
890 struct snd_opl4 *opl4;
891 /* assume we have an OPL4 */
892 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
894 if (snd_opl4_create(card, fm_port, fm_port - 8,
895 2, &opl3, &opl4) < 0) {
896 /* no luck, use OPL3 instead */
897 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
901 #endif /* !OPTi93X */
902 if (!opl3 && snd_opl3_create(card, fm_port, fm_port + 2,
903 OPL3_HW_AUTO, 0, &opl3) < 0) {
904 snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
905 fm_port, fm_port + 4 - 1);
908 error = snd_opl3_hwdep_new(opl3, 0, 1, &synth);
914 return snd_card_register(card);
917 static int snd_opti9xx_card_new(struct snd_card **cardp)
919 struct snd_card *card;
922 err = snd_card_create(index, id, THIS_MODULE,
923 sizeof(struct snd_opti9xx), &card);
926 card->private_free = snd_card_opti9xx_free;
931 static int __devinit snd_opti9xx_isa_match(struct device *devptr,
935 if (snd_opti9xx_pnp_is_probed)
943 static int __devinit snd_opti9xx_isa_probe(struct device *devptr,
946 struct snd_card *card;
948 static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};
950 static int possible_irqs[] = {5, 9, 10, 11, 7, -1};
952 static int possible_irqs[] = {9, 10, 11, 7, -1};
954 static int possible_mpu_irqs[] = {5, 9, 10, 7, -1};
955 static int possible_dma1s[] = {3, 1, 0, -1};
956 #if defined(CS4231) || defined(OPTi93X)
957 static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
958 #endif /* CS4231 || OPTi93X */
960 if (mpu_port == SNDRV_AUTO_PORT) {
961 if ((mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
962 snd_printk(KERN_ERR "unable to find a free MPU401 port\n");
966 if (irq == SNDRV_AUTO_IRQ) {
967 if ((irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
968 snd_printk(KERN_ERR "unable to find a free IRQ\n");
972 if (mpu_irq == SNDRV_AUTO_IRQ) {
973 if ((mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
974 snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n");
978 if (dma1 == SNDRV_AUTO_DMA) {
979 if ((dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
980 snd_printk(KERN_ERR "unable to find a free DMA1\n");
984 #if defined(CS4231) || defined(OPTi93X)
985 if (dma2 == SNDRV_AUTO_DMA) {
986 if ((dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4])) < 0) {
987 snd_printk(KERN_ERR "unable to find a free DMA2\n");
993 error = snd_opti9xx_card_new(&card);
997 if ((error = snd_card_opti9xx_detect(card, card->private_data)) < 0) {
1001 snd_card_set_dev(card, devptr);
1002 if ((error = snd_opti9xx_probe(card)) < 0) {
1003 snd_card_free(card);
1006 dev_set_drvdata(devptr, card);
1010 static int __devexit snd_opti9xx_isa_remove(struct device *devptr,
1013 snd_card_free(dev_get_drvdata(devptr));
1014 dev_set_drvdata(devptr, NULL);
1018 static struct isa_driver snd_opti9xx_driver = {
1019 .match = snd_opti9xx_isa_match,
1020 .probe = snd_opti9xx_isa_probe,
1021 .remove = __devexit_p(snd_opti9xx_isa_remove),
1022 /* FIXME: suspend/resume */
1029 static int __devinit snd_opti9xx_pnp_probe(struct pnp_card_link *pcard,
1030 const struct pnp_card_device_id *pid)
1032 struct snd_card *card;
1034 struct snd_opti9xx *chip;
1036 if (snd_opti9xx_pnp_is_probed)
1040 error = snd_opti9xx_card_new(&card);
1043 chip = card->private_data;
1045 hw = snd_card_opti9xx_pnp(chip, pcard, pid);
1048 hw = OPTi9XX_HW_82C924;
1051 hw = OPTi9XX_HW_82C925;
1054 hw = OPTi9XX_HW_82C931;
1057 snd_card_free(card);
1061 if ((error = snd_opti9xx_init(chip, hw))) {
1062 snd_card_free(card);
1065 if (hw <= OPTi9XX_HW_82C930)
1066 chip->mc_base -= 0x80;
1068 error = snd_opti9xx_read_check(chip);
1070 snd_printk(KERN_ERR "OPTI chip not found\n");
1071 snd_card_free(card);
1074 snd_card_set_dev(card, &pcard->card->dev);
1075 if ((error = snd_opti9xx_probe(card)) < 0) {
1076 snd_card_free(card);
1079 pnp_set_card_drvdata(pcard, card);
1080 snd_opti9xx_pnp_is_probed = 1;
1084 static void __devexit snd_opti9xx_pnp_remove(struct pnp_card_link * pcard)
1086 snd_card_free(pnp_get_card_drvdata(pcard));
1087 pnp_set_card_drvdata(pcard, NULL);
1088 snd_opti9xx_pnp_is_probed = 0;
1091 static struct pnp_card_driver opti9xx_pnpc_driver = {
1092 .flags = PNP_DRIVER_RES_DISABLE,
1094 .id_table = snd_opti9xx_pnpids,
1095 .probe = snd_opti9xx_pnp_probe,
1096 .remove = __devexit_p(snd_opti9xx_pnp_remove),
1101 #define CHIP_NAME "82C93x"
1103 #define CHIP_NAME "82C92x"
1106 static int __init alsa_card_opti9xx_init(void)
1109 pnp_register_card_driver(&opti9xx_pnpc_driver);
1110 if (snd_opti9xx_pnp_is_probed)
1112 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
1114 return isa_register_driver(&snd_opti9xx_driver, 1);
1117 static void __exit alsa_card_opti9xx_exit(void)
1119 if (!snd_opti9xx_pnp_is_probed) {
1120 isa_unregister_driver(&snd_opti9xx_driver);
1124 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
1128 module_init(alsa_card_opti9xx_init)
1129 module_exit(alsa_card_opti9xx_exit)