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 static inline void snd_opti9xx_write_mask(struct snd_opti9xx *chip,
321 unsigned char reg, unsigned char value, unsigned char mask)
323 unsigned char oldval = snd_opti9xx_read(chip, reg);
325 snd_opti9xx_write(chip, reg, (oldval & ~mask) | (value & mask));
328 static int snd_opti9xx_configure(struct snd_opti9xx *chip,
330 int irq, int dma1, int dma2,
331 long mpu_port, int mpu_irq)
333 unsigned char wss_base_bits;
334 unsigned char irq_bits;
335 unsigned char dma_bits;
336 unsigned char mpu_port_bits = 0;
337 unsigned char mpu_irq_bits;
339 switch (chip->hardware) {
341 case OPTi9XX_HW_82C924:
342 /* opti 929 mode (?), OPL3 clock output, audio enable */
343 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0xf0, 0xfc);
344 /* enable wave audio */
345 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
348 case OPTi9XX_HW_82C925:
349 /* enable WSS mode */
350 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
351 /* OPL3 FM synthesis */
352 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
353 /* disable Sound Blaster IRQ and DMA */
354 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
356 /* cs4231/4248 fix enabled */
357 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
359 /* cs4231/4248 fix disabled */
360 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
364 case OPTi9XX_HW_82C928:
365 case OPTi9XX_HW_82C929:
366 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
367 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
369 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xa2, 0xae);
371 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
373 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
375 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
380 case OPTi9XX_HW_82C931:
381 /* disable 3D sound (set GPIO1 as output, low) */
382 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(20), 0x04, 0x0c);
384 case OPTi9XX_HW_82C933:
386 * The BTC 1817DW has QS1000 wavetable which is connected
387 * to the serial digital input of the OPTI931.
389 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(21), 0x82, 0xff);
391 * This bit sets OPTI931 to automaticaly select FM
392 * or digital input signal.
394 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(26), 0x01, 0x01);
396 case OPTi9XX_HW_82C930:
397 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x03);
398 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0x00, 0xff);
399 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x10 |
400 (chip->hardware == OPTi9XX_HW_82C930 ? 0x00 : 0x04),
402 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x20, 0xbf);
407 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
411 /* PnP resource says it decodes only 10 bits of address */
412 switch (port & 0x3ff) {
414 chip->wss_base = 0x530;
415 wss_base_bits = 0x00;
418 chip->wss_base = 0x604;
419 wss_base_bits = 0x03;
422 chip->wss_base = 0xe80;
423 wss_base_bits = 0x01;
426 chip->wss_base = 0xf40;
427 wss_base_bits = 0x02;
430 snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n", port);
433 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
441 //#endif /* OPTi93X */
455 snd_printk(KERN_WARNING "WSS irq # %d not valid\n", irq);
456 goto __skip_resources;
470 snd_printk(KERN_WARNING "WSS dma1 # %d not valid\n", dma1);
471 goto __skip_resources;
474 #if defined(CS4231) || defined(OPTi93X)
476 snd_printk(KERN_ERR "don't want to share dmas\n");
485 snd_printk(KERN_WARNING "WSS dma2 # %d not valid\n", dma2);
486 goto __skip_resources;
489 #endif /* CS4231 || OPTi93X */
492 outb(irq_bits << 3 | dma_bits, chip->wss_base);
494 snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits));
498 if (chip->hardware > OPTi9XX_HW_82C928) {
504 mpu_port_bits = 0x03;
507 mpu_port_bits = 0x02;
510 mpu_port_bits = 0x01;
513 mpu_port_bits = 0x00;
516 snd_printk(KERN_WARNING
517 "MPU-401 port 0x%lx not valid\n", mpu_port);
535 snd_printk(KERN_WARNING "MPU-401 irq # %d not valid\n",
540 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6),
541 (mpu_port <= 0) ? 0x00 :
542 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
552 static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_step, -9300, 300, 0);
553 static const DECLARE_TLV_DB_SCALE(db_scale_5bit, -4650, 150, 0);
554 static const DECLARE_TLV_DB_SCALE(db_scale_4bit_12db_max, -3300, 300, 0);
556 static struct snd_kcontrol_new snd_opti93x_controls[] = {
557 WSS_DOUBLE("Master Playback Switch", 0,
558 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
559 WSS_DOUBLE_TLV("Master Playback Volume", 0,
560 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1,
561 db_scale_5bit_3db_step),
562 WSS_DOUBLE_TLV("PCM Playback Volume", 0,
563 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 31, 1,
565 WSS_DOUBLE_TLV("FM Playback Volume", 0,
566 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 1, 1, 15, 1,
567 db_scale_4bit_12db_max),
568 WSS_DOUBLE("Line Playback Switch", 0,
569 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
570 WSS_DOUBLE_TLV("Line Playback Volume", 0,
571 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 15, 1,
572 db_scale_4bit_12db_max),
573 WSS_DOUBLE("Mic Playback Switch", 0,
574 OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
575 WSS_DOUBLE_TLV("Mic Playback Volume", 0,
576 OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1,
577 db_scale_4bit_12db_max),
578 WSS_DOUBLE_TLV("CD Playback Volume", 0,
579 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 1, 1, 15, 1,
580 db_scale_4bit_12db_max),
581 WSS_DOUBLE("Aux Playback Switch", 0,
582 OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
583 WSS_DOUBLE_TLV("Aux Playback Volume", 0,
584 OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1,
585 db_scale_4bit_12db_max),
588 static int snd_opti93x_mixer(struct snd_wss *chip)
590 struct snd_card *card;
592 struct snd_ctl_elem_id id1, id2;
595 if (snd_BUG_ON(!chip || !chip->pcm))
600 strcpy(card->mixername, chip->pcm->name);
602 memset(&id1, 0, sizeof(id1));
603 memset(&id2, 0, sizeof(id2));
604 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
605 /* reassign AUX0 switch to CD */
606 strcpy(id1.name, "Aux Playback Switch");
607 strcpy(id2.name, "CD Playback Switch");
608 err = snd_ctl_rename_id(card, &id1, &id2);
610 snd_printk(KERN_ERR "Cannot rename opti93x control\n");
613 /* reassign AUX1 switch to FM */
614 strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
615 strcpy(id2.name, "FM Playback Switch");
616 err = snd_ctl_rename_id(card, &id1, &id2);
618 snd_printk(KERN_ERR "Cannot rename opti93x control\n");
621 /* remove AUX1 volume */
622 strcpy(id1.name, "Aux Playback Volume"); id1.index = 1;
623 snd_ctl_remove_id(card, &id1);
625 /* Replace WSS volume controls with OPTi93x volume controls */
627 for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) {
628 strcpy(id1.name, snd_opti93x_controls[idx].name);
629 snd_ctl_remove_id(card, &id1);
631 err = snd_ctl_add(card,
632 snd_ctl_new1(&snd_opti93x_controls[idx], chip));
639 static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id)
641 struct snd_opti9xx *chip = dev_id;
642 struct snd_wss *codec = chip->codec;
643 unsigned char status;
648 status = snd_opti9xx_read(chip, OPTi9XX_MC_REG(11));
649 if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream)
650 snd_pcm_period_elapsed(codec->playback_substream);
651 if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) {
652 snd_wss_overrange(codec);
653 snd_pcm_period_elapsed(codec->capture_substream);
655 outb(0x00, OPTi93X_PORT(codec, STATUS));
661 static int snd_opti9xx_read_check(struct snd_opti9xx *chip)
668 chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size,
670 if (chip->res_mc_base == NULL)
673 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1));
674 if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1)))
675 if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)))
678 chip->res_mc_indir = request_region(chip->mc_indir_index, 2,
680 if (chip->res_mc_indir == NULL)
683 spin_lock_irqsave(&chip->lock, flags);
684 outb(chip->password, chip->mc_base + chip->pwd_reg);
685 outb(((chip->mc_indir_index & 0x1f0) >> 4), chip->mc_base);
686 spin_unlock_irqrestore(&chip->lock, flags);
688 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7));
689 snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value);
690 if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value)
693 release_and_free_resource(chip->res_mc_indir);
694 chip->res_mc_indir = NULL;
696 release_and_free_resource(chip->res_mc_base);
697 chip->res_mc_base = NULL;
702 static int snd_card_opti9xx_detect(struct snd_card *card,
703 struct snd_opti9xx *chip)
708 for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) {
710 for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) {
712 err = snd_opti9xx_init(chip, i);
716 err = snd_opti9xx_read_check(chip);
720 chip->mc_indir_index = 0;
727 static int snd_card_opti9xx_pnp(struct snd_opti9xx *chip,
728 struct pnp_card_link *card,
729 const struct pnp_card_device_id *pid)
731 struct pnp_dev *pdev;
733 struct pnp_dev *devmpu;
735 struct pnp_dev *devmc;
738 pdev = pnp_request_card_device(card, pid->devs[0].id, NULL);
742 err = pnp_activate_dev(pdev);
744 snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err);
749 port = pnp_port_start(pdev, 0) - 4;
750 fm_port = pnp_port_start(pdev, 1) + 8;
751 /* adjust mc_indir_index - some cards report it at 0xe?d,
752 other at 0xe?c but it really is always at 0xe?e */
753 chip->mc_indir_index = (pnp_port_start(pdev, 3) & ~0xf) | 0xe;
755 devmc = pnp_request_card_device(card, pid->devs[2].id, NULL);
759 err = pnp_activate_dev(devmc);
761 snd_printk(KERN_ERR "MC pnp configure failure: %d\n", err);
765 port = pnp_port_start(pdev, 1);
766 fm_port = pnp_port_start(pdev, 2) + 8;
768 * The MC(0) is never accessed and card does not
769 * include it in the PnP resource range. OPTI93x include it.
771 chip->mc_base = pnp_port_start(devmc, 0) - 1;
772 chip->mc_base_size = pnp_port_len(devmc, 0) + 1;
774 irq = pnp_irq(pdev, 0);
775 dma1 = pnp_dma(pdev, 0);
776 #if defined(CS4231) || defined(OPTi93X)
777 dma2 = pnp_dma(pdev, 1);
778 #endif /* CS4231 || OPTi93X */
780 devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
782 if (devmpu && mpu_port > 0) {
783 err = pnp_activate_dev(devmpu);
785 snd_printk(KERN_ERR "MPU401 pnp configure failure\n");
788 mpu_port = pnp_port_start(devmpu, 0);
789 mpu_irq = pnp_irq(devmpu, 0);
792 return pid->driver_data;
794 #endif /* CONFIG_PNP */
796 static void snd_card_opti9xx_free(struct snd_card *card)
798 struct snd_opti9xx *chip = card->private_data;
803 disable_irq(chip->irq);
804 free_irq(chip->irq, chip);
806 release_and_free_resource(chip->res_mc_indir);
808 release_and_free_resource(chip->res_mc_base);
812 static int snd_opti9xx_probe(struct snd_card *card)
814 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
817 struct snd_opti9xx *chip = card->private_data;
818 struct snd_wss *codec;
819 struct snd_rawmidi *rmidi;
820 struct snd_hwdep *synth;
822 #if defined(CS4231) || defined(OPTi93X)
828 if (port == SNDRV_AUTO_PORT) {
829 port = snd_legacy_find_free_ioport(possible_ports, 4);
831 snd_printk(KERN_ERR "unable to find a free WSS port\n");
835 error = snd_opti9xx_configure(chip, port, irq, dma1, xdma2,
840 error = snd_wss_create(card, chip->wss_base + 4, -1, irq, dma1, xdma2,
842 WSS_HW_OPTI93X, WSS_HWSHARE_IRQ,
850 error = snd_wss_pcm(codec, 0);
853 error = snd_wss_mixer(codec);
857 error = snd_opti93x_mixer(codec);
862 error = snd_wss_timer(codec, 0);
867 error = request_irq(irq, snd_opti93x_interrupt,
868 0, DEV_NAME" - WSS", chip);
870 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", irq);
875 strcpy(card->driver, chip->name);
876 sprintf(card->shortname, "OPTi %s", card->driver);
877 #if defined(CS4231) || defined(OPTi93X)
878 snprintf(card->longname, sizeof(card->longname),
879 "%s, %s at 0x%lx, irq %d, dma %d&%d",
880 card->shortname, codec->pcm->name,
881 chip->wss_base + 4, irq, dma1, xdma2);
883 snprintf(card->longname, sizeof(card->longname),
884 "%s, %s at 0x%lx, irq %d, dma %d",
885 card->shortname, codec->pcm->name, chip->wss_base + 4, irq,
887 #endif /* CS4231 || OPTi93X */
889 if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT)
892 error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
893 mpu_port, 0, mpu_irq, &rmidi);
895 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
899 if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
900 struct snd_opl3 *opl3 = NULL;
902 if (chip->hardware == OPTi9XX_HW_82C928 ||
903 chip->hardware == OPTi9XX_HW_82C929 ||
904 chip->hardware == OPTi9XX_HW_82C924) {
905 struct snd_opl4 *opl4;
906 /* assume we have an OPL4 */
907 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
909 if (snd_opl4_create(card, fm_port, fm_port - 8,
910 2, &opl3, &opl4) < 0) {
911 /* no luck, use OPL3 instead */
912 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
916 #endif /* !OPTi93X */
917 if (!opl3 && snd_opl3_create(card, fm_port, fm_port + 2,
918 OPL3_HW_AUTO, 0, &opl3) < 0) {
919 snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
920 fm_port, fm_port + 4 - 1);
923 error = snd_opl3_hwdep_new(opl3, 0, 1, &synth);
929 return snd_card_register(card);
932 static int snd_opti9xx_card_new(struct device *pdev, struct snd_card **cardp)
934 struct snd_card *card;
937 err = snd_card_new(pdev, index, id, THIS_MODULE,
938 sizeof(struct snd_opti9xx), &card);
941 card->private_free = snd_card_opti9xx_free;
946 static int snd_opti9xx_isa_match(struct device *devptr,
950 if (snd_opti9xx_pnp_is_probed)
958 static int snd_opti9xx_isa_probe(struct device *devptr,
961 struct snd_card *card;
963 static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};
965 static int possible_irqs[] = {5, 9, 10, 11, 7, -1};
967 static int possible_irqs[] = {9, 10, 11, 7, -1};
969 static int possible_mpu_irqs[] = {5, 9, 10, 7, -1};
970 static int possible_dma1s[] = {3, 1, 0, -1};
971 #if defined(CS4231) || defined(OPTi93X)
972 static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
973 #endif /* CS4231 || OPTi93X */
975 if (mpu_port == SNDRV_AUTO_PORT) {
976 if ((mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
977 snd_printk(KERN_ERR "unable to find a free MPU401 port\n");
981 if (irq == SNDRV_AUTO_IRQ) {
982 if ((irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
983 snd_printk(KERN_ERR "unable to find a free IRQ\n");
987 if (mpu_irq == SNDRV_AUTO_IRQ) {
988 if ((mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
989 snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n");
993 if (dma1 == SNDRV_AUTO_DMA) {
994 if ((dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
995 snd_printk(KERN_ERR "unable to find a free DMA1\n");
999 #if defined(CS4231) || defined(OPTi93X)
1000 if (dma2 == SNDRV_AUTO_DMA) {
1001 if ((dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4])) < 0) {
1002 snd_printk(KERN_ERR "unable to find a free DMA2\n");
1008 error = snd_opti9xx_card_new(devptr, &card);
1012 if ((error = snd_card_opti9xx_detect(card, card->private_data)) < 0) {
1013 snd_card_free(card);
1016 if ((error = snd_opti9xx_probe(card)) < 0) {
1017 snd_card_free(card);
1020 dev_set_drvdata(devptr, card);
1024 static int snd_opti9xx_isa_remove(struct device *devptr,
1027 snd_card_free(dev_get_drvdata(devptr));
1032 static int snd_opti9xx_suspend(struct snd_card *card)
1034 struct snd_opti9xx *chip = card->private_data;
1036 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1037 chip->codec->suspend(chip->codec);
1041 static int snd_opti9xx_resume(struct snd_card *card)
1043 struct snd_opti9xx *chip = card->private_data;
1045 #if defined(CS4231) || defined(OPTi93X)
1051 error = snd_opti9xx_configure(chip, port, irq, dma1, xdma2,
1055 chip->codec->resume(chip->codec);
1056 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
1060 static int snd_opti9xx_isa_suspend(struct device *dev, unsigned int n,
1063 return snd_opti9xx_suspend(dev_get_drvdata(dev));
1066 static int snd_opti9xx_isa_resume(struct device *dev, unsigned int n)
1068 return snd_opti9xx_resume(dev_get_drvdata(dev));
1072 static struct isa_driver snd_opti9xx_driver = {
1073 .match = snd_opti9xx_isa_match,
1074 .probe = snd_opti9xx_isa_probe,
1075 .remove = snd_opti9xx_isa_remove,
1077 .suspend = snd_opti9xx_isa_suspend,
1078 .resume = snd_opti9xx_isa_resume,
1086 static int snd_opti9xx_pnp_probe(struct pnp_card_link *pcard,
1087 const struct pnp_card_device_id *pid)
1089 struct snd_card *card;
1091 struct snd_opti9xx *chip;
1093 if (snd_opti9xx_pnp_is_probed)
1097 error = snd_opti9xx_card_new(&pcard->card->dev, &card);
1100 chip = card->private_data;
1102 hw = snd_card_opti9xx_pnp(chip, pcard, pid);
1105 hw = OPTi9XX_HW_82C924;
1108 hw = OPTi9XX_HW_82C925;
1111 hw = OPTi9XX_HW_82C931;
1114 snd_card_free(card);
1118 if ((error = snd_opti9xx_init(chip, hw))) {
1119 snd_card_free(card);
1122 error = snd_opti9xx_read_check(chip);
1124 snd_printk(KERN_ERR "OPTI chip not found\n");
1125 snd_card_free(card);
1128 if ((error = snd_opti9xx_probe(card)) < 0) {
1129 snd_card_free(card);
1132 pnp_set_card_drvdata(pcard, card);
1133 snd_opti9xx_pnp_is_probed = 1;
1137 static void snd_opti9xx_pnp_remove(struct pnp_card_link *pcard)
1139 snd_card_free(pnp_get_card_drvdata(pcard));
1140 pnp_set_card_drvdata(pcard, NULL);
1141 snd_opti9xx_pnp_is_probed = 0;
1145 static int snd_opti9xx_pnp_suspend(struct pnp_card_link *pcard,
1148 return snd_opti9xx_suspend(pnp_get_card_drvdata(pcard));
1151 static int snd_opti9xx_pnp_resume(struct pnp_card_link *pcard)
1153 return snd_opti9xx_resume(pnp_get_card_drvdata(pcard));
1157 static struct pnp_card_driver opti9xx_pnpc_driver = {
1158 .flags = PNP_DRIVER_RES_DISABLE,
1160 .id_table = snd_opti9xx_pnpids,
1161 .probe = snd_opti9xx_pnp_probe,
1162 .remove = snd_opti9xx_pnp_remove,
1164 .suspend = snd_opti9xx_pnp_suspend,
1165 .resume = snd_opti9xx_pnp_resume,
1171 #define CHIP_NAME "82C93x"
1173 #define CHIP_NAME "82C92x"
1176 static int __init alsa_card_opti9xx_init(void)
1179 pnp_register_card_driver(&opti9xx_pnpc_driver);
1180 if (snd_opti9xx_pnp_is_probed)
1182 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
1184 return isa_register_driver(&snd_opti9xx_driver, 1);
1187 static void __exit alsa_card_opti9xx_exit(void)
1189 if (!snd_opti9xx_pnp_is_probed) {
1190 isa_unregister_driver(&snd_opti9xx_driver);
1194 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
1198 module_init(alsa_card_opti9xx_init)
1199 module_exit(alsa_card_opti9xx_exit)