1 // SPDX-License-Identifier: GPL-2.0-or-later
3 card-opti92x-ad1848.c - driver for OPTi 82c92x based soundcards.
4 Copyright (C) 1998-2000 by Massimo Piccioni <dafastidio@libero.it>
6 Part of this code was developed at the Italian Ministry of Air Defence,
7 Sixth Division (oh, che pace ...), Rome.
9 Thanks to Maria Grazia Pollarini, Salvatore Vassallo.
14 #include <linux/init.h>
15 #include <linux/err.h>
16 #include <linux/isa.h>
17 #include <linux/delay.h>
18 #include <linux/pnp.h>
19 #include <linux/module.h>
22 #include <sound/core.h>
23 #include <sound/tlv.h>
24 #include <sound/wss.h>
25 #include <sound/mpu401.h>
26 #include <sound/opl3.h>
28 #include <sound/opl4.h>
30 #define SNDRV_LEGACY_FIND_FREE_IOPORT
31 #define SNDRV_LEGACY_FIND_FREE_IRQ
32 #define SNDRV_LEGACY_FIND_FREE_DMA
33 #include <sound/initval.h>
35 MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
36 MODULE_LICENSE("GPL");
38 MODULE_DESCRIPTION("OPTi93X");
39 MODULE_SUPPORTED_DEVICE("{{OPTi,82C931/3}}");
42 MODULE_DESCRIPTION("OPTi92X - CS4231");
43 MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (CS4231)},"
44 "{OPTi,82C925 (CS4231)}}");
46 MODULE_DESCRIPTION("OPTi92X - AD1848");
47 MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (AD1848)},"
48 "{OPTi,82C925 (AD1848)},"
53 static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
54 static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
55 //static bool enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */
57 static bool isapnp = true; /* Enable ISA PnP detection */
59 static long port = SNDRV_DEFAULT_PORT1; /* 0x530,0xe80,0xf40,0x604 */
60 static long mpu_port = SNDRV_DEFAULT_PORT1; /* 0x300,0x310,0x320,0x330 */
61 static long fm_port = SNDRV_DEFAULT_PORT1; /* 0x388 */
62 static int irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10,11 */
63 static int mpu_irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10 */
64 static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
65 #if defined(CS4231) || defined(OPTi93X)
66 static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
67 #endif /* CS4231 || OPTi93X */
69 module_param(index, int, 0444);
70 MODULE_PARM_DESC(index, "Index value for opti9xx based soundcard.");
71 module_param(id, charp, 0444);
72 MODULE_PARM_DESC(id, "ID string for opti9xx based soundcard.");
73 //module_param(enable, bool, 0444);
74 //MODULE_PARM_DESC(enable, "Enable opti9xx soundcard.");
76 module_param(isapnp, bool, 0444);
77 MODULE_PARM_DESC(isapnp, "Enable ISA PnP detection for specified soundcard.");
79 module_param_hw(port, long, ioport, 0444);
80 MODULE_PARM_DESC(port, "WSS port # for opti9xx driver.");
81 module_param_hw(mpu_port, long, ioport, 0444);
82 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for opti9xx driver.");
83 module_param_hw(fm_port, long, ioport, 0444);
84 MODULE_PARM_DESC(fm_port, "FM port # for opti9xx driver.");
85 module_param_hw(irq, int, irq, 0444);
86 MODULE_PARM_DESC(irq, "WSS irq # for opti9xx driver.");
87 module_param_hw(mpu_irq, int, irq, 0444);
88 MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for opti9xx driver.");
89 module_param_hw(dma1, int, dma, 0444);
90 MODULE_PARM_DESC(dma1, "1st dma # for opti9xx driver.");
91 #if defined(CS4231) || defined(OPTi93X)
92 module_param_hw(dma2, int, dma, 0444);
93 MODULE_PARM_DESC(dma2, "2nd dma # for opti9xx driver.");
94 #endif /* CS4231 || OPTi93X */
96 #define OPTi9XX_HW_82C928 1
97 #define OPTi9XX_HW_82C929 2
98 #define OPTi9XX_HW_82C924 3
99 #define OPTi9XX_HW_82C925 4
100 #define OPTi9XX_HW_82C930 5
101 #define OPTi9XX_HW_82C931 6
102 #define OPTi9XX_HW_82C933 7
103 #define OPTi9XX_HW_LAST OPTi9XX_HW_82C933
105 #define OPTi9XX_MC_REG(n) n
109 #define OPTi93X_STATUS 0x02
110 #define OPTi93X_PORT(chip, r) ((chip)->port + OPTi93X_##r)
112 #define OPTi93X_IRQ_PLAYBACK 0x04
113 #define OPTi93X_IRQ_CAPTURE 0x08
118 unsigned short hardware;
119 unsigned char password;
122 unsigned long mc_base;
123 struct resource *res_mc_base;
124 unsigned long mc_base_size;
126 unsigned long mc_indir_index;
127 struct resource *res_mc_indir;
129 struct snd_wss *codec;
130 unsigned long pwd_reg;
138 static int snd_opti9xx_pnp_is_probed;
142 static const struct pnp_card_device_id snd_opti9xx_pnpids[] = {
146 .devs = { { "OPT0000" }, { "OPT0002" }, { "OPT0005" } },
147 .driver_data = 0x0924 },
150 .devs = { { "OPT9250" }, { "OPT0002" }, { "OPT0005" } },
151 .driver_data = 0x0925 },
154 { .id = "OPT0931", .devs = { { "OPT9310" }, { "OPT0002" } },
155 .driver_data = 0x0931 },
160 MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids);
162 #endif /* CONFIG_PNP */
164 #define DEV_NAME KBUILD_MODNAME
166 static char * snd_opti9xx_names[] = {
170 "82C930", "82C931", "82C933"
173 static int snd_opti9xx_init(struct snd_opti9xx *chip,
174 unsigned short hardware)
176 static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
178 chip->hardware = hardware;
179 strcpy(chip->name, snd_opti9xx_names[hardware]);
181 spin_lock_init(&chip->lock);
187 if (isapnp && chip->mc_base)
188 /* PnP resource gives the least 10 bits */
189 chip->mc_base |= 0xc00;
191 #endif /* CONFIG_PNP */
193 chip->mc_base = 0xf8c;
194 chip->mc_base_size = opti9xx_mc_size[hardware];
197 chip->mc_base_size = opti9xx_mc_size[hardware];
202 case OPTi9XX_HW_82C928:
203 case OPTi9XX_HW_82C929:
204 chip->password = (hardware == OPTi9XX_HW_82C928) ? 0xe2 : 0xe3;
208 case OPTi9XX_HW_82C924:
209 case OPTi9XX_HW_82C925:
210 chip->password = 0xe5;
215 case OPTi9XX_HW_82C930:
216 case OPTi9XX_HW_82C931:
217 case OPTi9XX_HW_82C933:
218 chip->mc_base = (hardware == OPTi9XX_HW_82C930) ? 0xf8f : 0xf8d;
219 if (!chip->mc_indir_index)
220 chip->mc_indir_index = 0xe0e;
221 chip->password = 0xe4;
227 snd_printk(KERN_ERR "chip %d not supported\n", hardware);
233 static unsigned char snd_opti9xx_read(struct snd_opti9xx *chip,
237 unsigned char retval = 0xff;
239 spin_lock_irqsave(&chip->lock, flags);
240 outb(chip->password, chip->mc_base + chip->pwd_reg);
242 switch (chip->hardware) {
244 case OPTi9XX_HW_82C924:
245 case OPTi9XX_HW_82C925:
247 outb(reg, chip->mc_base + 8);
248 outb(chip->password, chip->mc_base + chip->pwd_reg);
249 retval = inb(chip->mc_base + 9);
254 case OPTi9XX_HW_82C928:
255 case OPTi9XX_HW_82C929:
256 retval = inb(chip->mc_base + reg);
260 case OPTi9XX_HW_82C930:
261 case OPTi9XX_HW_82C931:
262 case OPTi9XX_HW_82C933:
263 outb(reg, chip->mc_indir_index);
264 outb(chip->password, chip->mc_base + chip->pwd_reg);
265 retval = inb(chip->mc_indir_index + 1);
270 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
273 spin_unlock_irqrestore(&chip->lock, flags);
277 static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg,
282 spin_lock_irqsave(&chip->lock, flags);
283 outb(chip->password, chip->mc_base + chip->pwd_reg);
285 switch (chip->hardware) {
287 case OPTi9XX_HW_82C924:
288 case OPTi9XX_HW_82C925:
290 outb(reg, chip->mc_base + 8);
291 outb(chip->password, chip->mc_base + chip->pwd_reg);
292 outb(value, chip->mc_base + 9);
297 case OPTi9XX_HW_82C928:
298 case OPTi9XX_HW_82C929:
299 outb(value, chip->mc_base + reg);
303 case OPTi9XX_HW_82C930:
304 case OPTi9XX_HW_82C931:
305 case OPTi9XX_HW_82C933:
306 outb(reg, chip->mc_indir_index);
307 outb(chip->password, chip->mc_base + chip->pwd_reg);
308 outb(value, chip->mc_indir_index + 1);
313 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
316 spin_unlock_irqrestore(&chip->lock, flags);
320 #define snd_opti9xx_write_mask(chip, reg, value, mask) \
321 snd_opti9xx_write(chip, reg, \
322 (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask)))
325 static int snd_opti9xx_configure(struct snd_opti9xx *chip,
327 int irq, int dma1, int dma2,
328 long mpu_port, int mpu_irq)
330 unsigned char wss_base_bits;
331 unsigned char irq_bits;
332 unsigned char dma_bits;
333 unsigned char mpu_port_bits = 0;
334 unsigned char mpu_irq_bits;
336 switch (chip->hardware) {
338 case OPTi9XX_HW_82C924:
339 /* opti 929 mode (?), OPL3 clock output, audio enable */
340 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0xf0, 0xfc);
341 /* enable wave audio */
342 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
345 case OPTi9XX_HW_82C925:
346 /* enable WSS mode */
347 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
348 /* OPL3 FM synthesis */
349 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
350 /* disable Sound Blaster IRQ and DMA */
351 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
353 /* cs4231/4248 fix enabled */
354 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
356 /* cs4231/4248 fix disabled */
357 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
361 case OPTi9XX_HW_82C928:
362 case OPTi9XX_HW_82C929:
363 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
364 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
366 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xa2, 0xae);
368 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
370 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
372 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
377 case OPTi9XX_HW_82C931:
378 /* disable 3D sound (set GPIO1 as output, low) */
379 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(20), 0x04, 0x0c);
381 case OPTi9XX_HW_82C933:
383 * The BTC 1817DW has QS1000 wavetable which is connected
384 * to the serial digital input of the OPTI931.
386 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(21), 0x82, 0xff);
388 * This bit sets OPTI931 to automaticaly select FM
389 * or digital input signal.
391 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(26), 0x01, 0x01);
393 case OPTi9XX_HW_82C930:
394 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x03);
395 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0x00, 0xff);
396 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x10 |
397 (chip->hardware == OPTi9XX_HW_82C930 ? 0x00 : 0x04),
399 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x20, 0xbf);
404 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
408 /* PnP resource says it decodes only 10 bits of address */
409 switch (port & 0x3ff) {
411 chip->wss_base = 0x530;
412 wss_base_bits = 0x00;
415 chip->wss_base = 0x604;
416 wss_base_bits = 0x03;
419 chip->wss_base = 0xe80;
420 wss_base_bits = 0x01;
423 chip->wss_base = 0xf40;
424 wss_base_bits = 0x02;
427 snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n", port);
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, chip->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 const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_step, -9300, 300, 0);
550 static const DECLARE_TLV_DB_SCALE(db_scale_5bit, -4650, 150, 0);
551 static const DECLARE_TLV_DB_SCALE(db_scale_4bit_12db_max, -3300, 300, 0);
553 static struct snd_kcontrol_new snd_opti93x_controls[] = {
554 WSS_DOUBLE("Master Playback Switch", 0,
555 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
556 WSS_DOUBLE_TLV("Master Playback Volume", 0,
557 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1,
558 db_scale_5bit_3db_step),
559 WSS_DOUBLE_TLV("PCM Playback Volume", 0,
560 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 31, 1,
562 WSS_DOUBLE_TLV("FM Playback Volume", 0,
563 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 1, 1, 15, 1,
564 db_scale_4bit_12db_max),
565 WSS_DOUBLE("Line Playback Switch", 0,
566 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
567 WSS_DOUBLE_TLV("Line Playback Volume", 0,
568 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 15, 1,
569 db_scale_4bit_12db_max),
570 WSS_DOUBLE("Mic Playback Switch", 0,
571 OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
572 WSS_DOUBLE_TLV("Mic Playback Volume", 0,
573 OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1,
574 db_scale_4bit_12db_max),
575 WSS_DOUBLE_TLV("CD Playback Volume", 0,
576 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 1, 1, 15, 1,
577 db_scale_4bit_12db_max),
578 WSS_DOUBLE("Aux Playback Switch", 0,
579 OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
580 WSS_DOUBLE_TLV("Aux Playback Volume", 0,
581 OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1,
582 db_scale_4bit_12db_max),
585 static int snd_opti93x_mixer(struct snd_wss *chip)
587 struct snd_card *card;
589 struct snd_ctl_elem_id id1, id2;
592 if (snd_BUG_ON(!chip || !chip->pcm))
597 strcpy(card->mixername, chip->pcm->name);
599 memset(&id1, 0, sizeof(id1));
600 memset(&id2, 0, sizeof(id2));
601 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
602 /* reassign AUX0 switch to CD */
603 strcpy(id1.name, "Aux Playback Switch");
604 strcpy(id2.name, "CD Playback Switch");
605 err = snd_ctl_rename_id(card, &id1, &id2);
607 snd_printk(KERN_ERR "Cannot rename opti93x control\n");
610 /* reassign AUX1 switch to FM */
611 strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
612 strcpy(id2.name, "FM Playback Switch");
613 err = snd_ctl_rename_id(card, &id1, &id2);
615 snd_printk(KERN_ERR "Cannot rename opti93x control\n");
618 /* remove AUX1 volume */
619 strcpy(id1.name, "Aux Playback Volume"); id1.index = 1;
620 snd_ctl_remove_id(card, &id1);
622 /* Replace WSS volume controls with OPTi93x volume controls */
624 for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) {
625 strcpy(id1.name, snd_opti93x_controls[idx].name);
626 snd_ctl_remove_id(card, &id1);
628 err = snd_ctl_add(card,
629 snd_ctl_new1(&snd_opti93x_controls[idx], chip));
636 static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id)
638 struct snd_opti9xx *chip = dev_id;
639 struct snd_wss *codec = chip->codec;
640 unsigned char status;
645 status = snd_opti9xx_read(chip, OPTi9XX_MC_REG(11));
646 if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream)
647 snd_pcm_period_elapsed(codec->playback_substream);
648 if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) {
649 snd_wss_overrange(codec);
650 snd_pcm_period_elapsed(codec->capture_substream);
652 outb(0x00, OPTi93X_PORT(codec, STATUS));
658 static int snd_opti9xx_read_check(struct snd_opti9xx *chip)
665 chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size,
667 if (chip->res_mc_base == NULL)
670 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1));
671 if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1)))
672 if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)))
675 chip->res_mc_indir = request_region(chip->mc_indir_index, 2,
677 if (chip->res_mc_indir == NULL)
680 spin_lock_irqsave(&chip->lock, flags);
681 outb(chip->password, chip->mc_base + chip->pwd_reg);
682 outb(((chip->mc_indir_index & 0x1f0) >> 4), chip->mc_base);
683 spin_unlock_irqrestore(&chip->lock, flags);
685 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7));
686 snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value);
687 if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value)
690 release_and_free_resource(chip->res_mc_indir);
691 chip->res_mc_indir = NULL;
693 release_and_free_resource(chip->res_mc_base);
694 chip->res_mc_base = NULL;
699 static int snd_card_opti9xx_detect(struct snd_card *card,
700 struct snd_opti9xx *chip)
705 for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) {
707 for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) {
709 err = snd_opti9xx_init(chip, i);
713 err = snd_opti9xx_read_check(chip);
717 chip->mc_indir_index = 0;
724 static int snd_card_opti9xx_pnp(struct snd_opti9xx *chip,
725 struct pnp_card_link *card,
726 const struct pnp_card_device_id *pid)
728 struct pnp_dev *pdev;
730 struct pnp_dev *devmpu;
732 struct pnp_dev *devmc;
735 pdev = pnp_request_card_device(card, pid->devs[0].id, NULL);
739 err = pnp_activate_dev(pdev);
741 snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err);
746 port = pnp_port_start(pdev, 0) - 4;
747 fm_port = pnp_port_start(pdev, 1) + 8;
748 /* adjust mc_indir_index - some cards report it at 0xe?d,
749 other at 0xe?c but it really is always at 0xe?e */
750 chip->mc_indir_index = (pnp_port_start(pdev, 3) & ~0xf) | 0xe;
752 devmc = pnp_request_card_device(card, pid->devs[2].id, NULL);
756 err = pnp_activate_dev(devmc);
758 snd_printk(KERN_ERR "MC pnp configure failure: %d\n", err);
762 port = pnp_port_start(pdev, 1);
763 fm_port = pnp_port_start(pdev, 2) + 8;
765 * The MC(0) is never accessed and card does not
766 * include it in the PnP resource range. OPTI93x include it.
768 chip->mc_base = pnp_port_start(devmc, 0) - 1;
769 chip->mc_base_size = pnp_port_len(devmc, 0) + 1;
771 irq = pnp_irq(pdev, 0);
772 dma1 = pnp_dma(pdev, 0);
773 #if defined(CS4231) || defined(OPTi93X)
774 dma2 = pnp_dma(pdev, 1);
775 #endif /* CS4231 || OPTi93X */
777 devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
779 if (devmpu && mpu_port > 0) {
780 err = pnp_activate_dev(devmpu);
782 snd_printk(KERN_ERR "MPU401 pnp configure failure\n");
785 mpu_port = pnp_port_start(devmpu, 0);
786 mpu_irq = pnp_irq(devmpu, 0);
789 return pid->driver_data;
791 #endif /* CONFIG_PNP */
793 static void snd_card_opti9xx_free(struct snd_card *card)
795 struct snd_opti9xx *chip = card->private_data;
800 disable_irq(chip->irq);
801 free_irq(chip->irq, chip);
803 release_and_free_resource(chip->res_mc_indir);
805 release_and_free_resource(chip->res_mc_base);
809 static int snd_opti9xx_probe(struct snd_card *card)
811 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
814 struct snd_opti9xx *chip = card->private_data;
815 struct snd_wss *codec;
816 struct snd_rawmidi *rmidi;
817 struct snd_hwdep *synth;
819 #if defined(CS4231) || defined(OPTi93X)
825 if (port == SNDRV_AUTO_PORT) {
826 port = snd_legacy_find_free_ioport(possible_ports, 4);
828 snd_printk(KERN_ERR "unable to find a free WSS port\n");
832 error = snd_opti9xx_configure(chip, port, irq, dma1, xdma2,
837 error = snd_wss_create(card, chip->wss_base + 4, -1, irq, dma1, xdma2,
839 WSS_HW_OPTI93X, WSS_HWSHARE_IRQ,
847 error = snd_wss_pcm(codec, 0);
850 error = snd_wss_mixer(codec);
854 error = snd_opti93x_mixer(codec);
859 error = snd_wss_timer(codec, 0);
864 error = request_irq(irq, snd_opti93x_interrupt,
865 0, DEV_NAME" - WSS", chip);
867 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", irq);
872 strcpy(card->driver, chip->name);
873 sprintf(card->shortname, "OPTi %s", card->driver);
874 #if defined(CS4231) || defined(OPTi93X)
875 snprintf(card->longname, sizeof(card->longname),
876 "%s, %s at 0x%lx, irq %d, dma %d&%d",
877 card->shortname, codec->pcm->name,
878 chip->wss_base + 4, irq, dma1, xdma2);
880 snprintf(card->longname, sizeof(card->longname),
881 "%s, %s at 0x%lx, irq %d, dma %d",
882 card->shortname, codec->pcm->name, chip->wss_base + 4, irq,
884 #endif /* CS4231 || OPTi93X */
886 if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT)
889 error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
890 mpu_port, 0, mpu_irq, &rmidi);
892 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
896 if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
897 struct snd_opl3 *opl3 = NULL;
899 if (chip->hardware == OPTi9XX_HW_82C928 ||
900 chip->hardware == OPTi9XX_HW_82C929 ||
901 chip->hardware == OPTi9XX_HW_82C924) {
902 struct snd_opl4 *opl4;
903 /* assume we have an OPL4 */
904 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
906 if (snd_opl4_create(card, fm_port, fm_port - 8,
907 2, &opl3, &opl4) < 0) {
908 /* no luck, use OPL3 instead */
909 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
913 #endif /* !OPTi93X */
914 if (!opl3 && snd_opl3_create(card, fm_port, fm_port + 2,
915 OPL3_HW_AUTO, 0, &opl3) < 0) {
916 snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
917 fm_port, fm_port + 4 - 1);
920 error = snd_opl3_hwdep_new(opl3, 0, 1, &synth);
926 return snd_card_register(card);
929 static int snd_opti9xx_card_new(struct device *pdev, struct snd_card **cardp)
931 struct snd_card *card;
934 err = snd_card_new(pdev, index, id, THIS_MODULE,
935 sizeof(struct snd_opti9xx), &card);
938 card->private_free = snd_card_opti9xx_free;
943 static int snd_opti9xx_isa_match(struct device *devptr,
947 if (snd_opti9xx_pnp_is_probed)
955 static int snd_opti9xx_isa_probe(struct device *devptr,
958 struct snd_card *card;
960 static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};
962 static int possible_irqs[] = {5, 9, 10, 11, 7, -1};
964 static int possible_irqs[] = {9, 10, 11, 7, -1};
966 static int possible_mpu_irqs[] = {5, 9, 10, 7, -1};
967 static int possible_dma1s[] = {3, 1, 0, -1};
968 #if defined(CS4231) || defined(OPTi93X)
969 static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
970 #endif /* CS4231 || OPTi93X */
972 if (mpu_port == SNDRV_AUTO_PORT) {
973 if ((mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
974 snd_printk(KERN_ERR "unable to find a free MPU401 port\n");
978 if (irq == SNDRV_AUTO_IRQ) {
979 if ((irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
980 snd_printk(KERN_ERR "unable to find a free IRQ\n");
984 if (mpu_irq == SNDRV_AUTO_IRQ) {
985 if ((mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
986 snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n");
990 if (dma1 == SNDRV_AUTO_DMA) {
991 if ((dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
992 snd_printk(KERN_ERR "unable to find a free DMA1\n");
996 #if defined(CS4231) || defined(OPTi93X)
997 if (dma2 == SNDRV_AUTO_DMA) {
998 if ((dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4])) < 0) {
999 snd_printk(KERN_ERR "unable to find a free DMA2\n");
1005 error = snd_opti9xx_card_new(devptr, &card);
1009 if ((error = snd_card_opti9xx_detect(card, card->private_data)) < 0) {
1010 snd_card_free(card);
1013 if ((error = snd_opti9xx_probe(card)) < 0) {
1014 snd_card_free(card);
1017 dev_set_drvdata(devptr, card);
1021 static int snd_opti9xx_isa_remove(struct device *devptr,
1024 snd_card_free(dev_get_drvdata(devptr));
1029 static int snd_opti9xx_suspend(struct snd_card *card)
1031 struct snd_opti9xx *chip = card->private_data;
1033 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1034 chip->codec->suspend(chip->codec);
1038 static int snd_opti9xx_resume(struct snd_card *card)
1040 struct snd_opti9xx *chip = card->private_data;
1042 #if defined(CS4231) || defined(OPTi93X)
1048 error = snd_opti9xx_configure(chip, port, irq, dma1, xdma2,
1052 chip->codec->resume(chip->codec);
1053 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
1057 static int snd_opti9xx_isa_suspend(struct device *dev, unsigned int n,
1060 return snd_opti9xx_suspend(dev_get_drvdata(dev));
1063 static int snd_opti9xx_isa_resume(struct device *dev, unsigned int n)
1065 return snd_opti9xx_resume(dev_get_drvdata(dev));
1069 static struct isa_driver snd_opti9xx_driver = {
1070 .match = snd_opti9xx_isa_match,
1071 .probe = snd_opti9xx_isa_probe,
1072 .remove = snd_opti9xx_isa_remove,
1074 .suspend = snd_opti9xx_isa_suspend,
1075 .resume = snd_opti9xx_isa_resume,
1083 static int snd_opti9xx_pnp_probe(struct pnp_card_link *pcard,
1084 const struct pnp_card_device_id *pid)
1086 struct snd_card *card;
1088 struct snd_opti9xx *chip;
1090 if (snd_opti9xx_pnp_is_probed)
1094 error = snd_opti9xx_card_new(&pcard->card->dev, &card);
1097 chip = card->private_data;
1099 hw = snd_card_opti9xx_pnp(chip, pcard, pid);
1102 hw = OPTi9XX_HW_82C924;
1105 hw = OPTi9XX_HW_82C925;
1108 hw = OPTi9XX_HW_82C931;
1111 snd_card_free(card);
1115 if ((error = snd_opti9xx_init(chip, hw))) {
1116 snd_card_free(card);
1119 error = snd_opti9xx_read_check(chip);
1121 snd_printk(KERN_ERR "OPTI chip not found\n");
1122 snd_card_free(card);
1125 if ((error = snd_opti9xx_probe(card)) < 0) {
1126 snd_card_free(card);
1129 pnp_set_card_drvdata(pcard, card);
1130 snd_opti9xx_pnp_is_probed = 1;
1134 static void snd_opti9xx_pnp_remove(struct pnp_card_link *pcard)
1136 snd_card_free(pnp_get_card_drvdata(pcard));
1137 pnp_set_card_drvdata(pcard, NULL);
1138 snd_opti9xx_pnp_is_probed = 0;
1142 static int snd_opti9xx_pnp_suspend(struct pnp_card_link *pcard,
1145 return snd_opti9xx_suspend(pnp_get_card_drvdata(pcard));
1148 static int snd_opti9xx_pnp_resume(struct pnp_card_link *pcard)
1150 return snd_opti9xx_resume(pnp_get_card_drvdata(pcard));
1154 static struct pnp_card_driver opti9xx_pnpc_driver = {
1155 .flags = PNP_DRIVER_RES_DISABLE,
1157 .id_table = snd_opti9xx_pnpids,
1158 .probe = snd_opti9xx_pnp_probe,
1159 .remove = snd_opti9xx_pnp_remove,
1161 .suspend = snd_opti9xx_pnp_suspend,
1162 .resume = snd_opti9xx_pnp_resume,
1168 #define CHIP_NAME "82C93x"
1170 #define CHIP_NAME "82C92x"
1173 static int __init alsa_card_opti9xx_init(void)
1176 pnp_register_card_driver(&opti9xx_pnpc_driver);
1177 if (snd_opti9xx_pnp_is_probed)
1179 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
1181 return isa_register_driver(&snd_opti9xx_driver, 1);
1184 static void __exit alsa_card_opti9xx_exit(void)
1186 if (!snd_opti9xx_pnp_is_probed) {
1187 isa_unregister_driver(&snd_opti9xx_driver);
1191 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
1195 module_init(alsa_card_opti9xx_init)
1196 module_exit(alsa_card_opti9xx_exit)