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");
41 MODULE_DESCRIPTION("OPTi92X - CS4231");
43 MODULE_DESCRIPTION("OPTi92X - AD1848");
47 static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
48 static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
49 //static bool enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */
51 static bool isapnp = true; /* Enable ISA PnP detection */
53 static long port = SNDRV_DEFAULT_PORT1; /* 0x530,0xe80,0xf40,0x604 */
54 static long mpu_port = SNDRV_DEFAULT_PORT1; /* 0x300,0x310,0x320,0x330 */
55 static long fm_port = SNDRV_DEFAULT_PORT1; /* 0x388 */
56 static int irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10,11 */
57 static int mpu_irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10 */
58 static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
59 #if defined(CS4231) || defined(OPTi93X)
60 static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
61 #endif /* CS4231 || OPTi93X */
63 module_param(index, int, 0444);
64 MODULE_PARM_DESC(index, "Index value for opti9xx based soundcard.");
65 module_param(id, charp, 0444);
66 MODULE_PARM_DESC(id, "ID string for opti9xx based soundcard.");
67 //module_param(enable, bool, 0444);
68 //MODULE_PARM_DESC(enable, "Enable opti9xx soundcard.");
70 module_param(isapnp, bool, 0444);
71 MODULE_PARM_DESC(isapnp, "Enable ISA PnP detection for specified soundcard.");
73 module_param_hw(port, long, ioport, 0444);
74 MODULE_PARM_DESC(port, "WSS port # for opti9xx driver.");
75 module_param_hw(mpu_port, long, ioport, 0444);
76 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for opti9xx driver.");
77 module_param_hw(fm_port, long, ioport, 0444);
78 MODULE_PARM_DESC(fm_port, "FM port # for opti9xx driver.");
79 module_param_hw(irq, int, irq, 0444);
80 MODULE_PARM_DESC(irq, "WSS irq # for opti9xx driver.");
81 module_param_hw(mpu_irq, int, irq, 0444);
82 MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for opti9xx driver.");
83 module_param_hw(dma1, int, dma, 0444);
84 MODULE_PARM_DESC(dma1, "1st dma # for opti9xx driver.");
85 #if defined(CS4231) || defined(OPTi93X)
86 module_param_hw(dma2, int, dma, 0444);
87 MODULE_PARM_DESC(dma2, "2nd dma # for opti9xx driver.");
88 #endif /* CS4231 || OPTi93X */
90 #define OPTi9XX_HW_82C928 1
91 #define OPTi9XX_HW_82C929 2
92 #define OPTi9XX_HW_82C924 3
93 #define OPTi9XX_HW_82C925 4
94 #define OPTi9XX_HW_82C930 5
95 #define OPTi9XX_HW_82C931 6
96 #define OPTi9XX_HW_82C933 7
97 #define OPTi9XX_HW_LAST OPTi9XX_HW_82C933
99 #define OPTi9XX_MC_REG(n) n
103 #define OPTi93X_STATUS 0x02
104 #define OPTi93X_PORT(chip, r) ((chip)->port + OPTi93X_##r)
106 #define OPTi93X_IRQ_PLAYBACK 0x04
107 #define OPTi93X_IRQ_CAPTURE 0x08
112 unsigned short hardware;
113 unsigned char password;
116 unsigned long mc_base;
117 struct resource *res_mc_base;
118 unsigned long mc_base_size;
120 unsigned long mc_indir_index;
121 struct resource *res_mc_indir;
123 struct snd_wss *codec;
124 unsigned long pwd_reg;
132 static int snd_opti9xx_pnp_is_probed;
136 static const struct pnp_card_device_id snd_opti9xx_pnpids[] = {
140 .devs = { { "OPT0000" }, { "OPT0002" }, { "OPT0005" } },
141 .driver_data = 0x0924 },
144 .devs = { { "OPT9250" }, { "OPT0002" }, { "OPT0005" } },
145 .driver_data = 0x0925 },
148 { .id = "OPT0931", .devs = { { "OPT9310" }, { "OPT0002" } },
149 .driver_data = 0x0931 },
154 MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids);
156 #endif /* CONFIG_PNP */
158 #define DEV_NAME KBUILD_MODNAME
160 static const char * const snd_opti9xx_names[] = {
164 "82C930", "82C931", "82C933"
167 static int snd_opti9xx_init(struct snd_opti9xx *chip,
168 unsigned short hardware)
170 static const int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
172 chip->hardware = hardware;
173 strcpy(chip->name, snd_opti9xx_names[hardware]);
175 spin_lock_init(&chip->lock);
181 if (isapnp && chip->mc_base)
182 /* PnP resource gives the least 10 bits */
183 chip->mc_base |= 0xc00;
185 #endif /* CONFIG_PNP */
187 chip->mc_base = 0xf8c;
188 chip->mc_base_size = opti9xx_mc_size[hardware];
191 chip->mc_base_size = opti9xx_mc_size[hardware];
196 case OPTi9XX_HW_82C928:
197 case OPTi9XX_HW_82C929:
198 chip->password = (hardware == OPTi9XX_HW_82C928) ? 0xe2 : 0xe3;
202 case OPTi9XX_HW_82C924:
203 case OPTi9XX_HW_82C925:
204 chip->password = 0xe5;
209 case OPTi9XX_HW_82C930:
210 case OPTi9XX_HW_82C931:
211 case OPTi9XX_HW_82C933:
212 chip->mc_base = (hardware == OPTi9XX_HW_82C930) ? 0xf8f : 0xf8d;
213 if (!chip->mc_indir_index)
214 chip->mc_indir_index = 0xe0e;
215 chip->password = 0xe4;
221 snd_printk(KERN_ERR "chip %d not supported\n", hardware);
227 static unsigned char snd_opti9xx_read(struct snd_opti9xx *chip,
231 unsigned char retval = 0xff;
233 spin_lock_irqsave(&chip->lock, flags);
234 outb(chip->password, chip->mc_base + chip->pwd_reg);
236 switch (chip->hardware) {
238 case OPTi9XX_HW_82C924:
239 case OPTi9XX_HW_82C925:
241 outb(reg, chip->mc_base + 8);
242 outb(chip->password, chip->mc_base + chip->pwd_reg);
243 retval = inb(chip->mc_base + 9);
248 case OPTi9XX_HW_82C928:
249 case OPTi9XX_HW_82C929:
250 retval = inb(chip->mc_base + reg);
254 case OPTi9XX_HW_82C930:
255 case OPTi9XX_HW_82C931:
256 case OPTi9XX_HW_82C933:
257 outb(reg, chip->mc_indir_index);
258 outb(chip->password, chip->mc_base + chip->pwd_reg);
259 retval = inb(chip->mc_indir_index + 1);
264 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
267 spin_unlock_irqrestore(&chip->lock, flags);
271 static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg,
276 spin_lock_irqsave(&chip->lock, flags);
277 outb(chip->password, chip->mc_base + chip->pwd_reg);
279 switch (chip->hardware) {
281 case OPTi9XX_HW_82C924:
282 case OPTi9XX_HW_82C925:
284 outb(reg, chip->mc_base + 8);
285 outb(chip->password, chip->mc_base + chip->pwd_reg);
286 outb(value, chip->mc_base + 9);
291 case OPTi9XX_HW_82C928:
292 case OPTi9XX_HW_82C929:
293 outb(value, chip->mc_base + reg);
297 case OPTi9XX_HW_82C930:
298 case OPTi9XX_HW_82C931:
299 case OPTi9XX_HW_82C933:
300 outb(reg, chip->mc_indir_index);
301 outb(chip->password, chip->mc_base + chip->pwd_reg);
302 outb(value, chip->mc_indir_index + 1);
307 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
310 spin_unlock_irqrestore(&chip->lock, flags);
314 static inline void snd_opti9xx_write_mask(struct snd_opti9xx *chip,
315 unsigned char reg, unsigned char value, unsigned char mask)
317 unsigned char oldval = snd_opti9xx_read(chip, reg);
319 snd_opti9xx_write(chip, reg, (oldval & ~mask) | (value & mask));
322 static int snd_opti9xx_configure(struct snd_opti9xx *chip,
324 int irq, int dma1, int dma2,
325 long mpu_port, int mpu_irq)
327 unsigned char wss_base_bits;
328 unsigned char irq_bits;
329 unsigned char dma_bits;
330 unsigned char mpu_port_bits = 0;
331 unsigned char mpu_irq_bits;
333 switch (chip->hardware) {
335 case OPTi9XX_HW_82C924:
336 /* opti 929 mode (?), OPL3 clock output, audio enable */
337 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0xf0, 0xfc);
338 /* enable wave audio */
339 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
342 case OPTi9XX_HW_82C925:
343 /* enable WSS mode */
344 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
345 /* OPL3 FM synthesis */
346 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
347 /* disable Sound Blaster IRQ and DMA */
348 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
350 /* cs4231/4248 fix enabled */
351 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
353 /* cs4231/4248 fix disabled */
354 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
358 case OPTi9XX_HW_82C928:
359 case OPTi9XX_HW_82C929:
360 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
361 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
363 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xa2, 0xae);
365 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
367 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
369 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
374 case OPTi9XX_HW_82C931:
375 /* disable 3D sound (set GPIO1 as output, low) */
376 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(20), 0x04, 0x0c);
379 case OPTi9XX_HW_82C933:
381 * The BTC 1817DW has QS1000 wavetable which is connected
382 * to the serial digital input of the OPTI931.
384 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(21), 0x82, 0xff);
386 * This bit sets OPTI931 to automaticaly select FM
387 * or digital input signal.
389 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(26), 0x01, 0x01);
392 case OPTi9XX_HW_82C930:
393 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x03);
394 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0x00, 0xff);
395 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x10 |
396 (chip->hardware == OPTi9XX_HW_82C930 ? 0x00 : 0x04),
398 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x20, 0xbf);
403 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
407 /* PnP resource says it decodes only 10 bits of address */
408 switch (port & 0x3ff) {
410 chip->wss_base = 0x530;
411 wss_base_bits = 0x00;
414 chip->wss_base = 0x604;
415 wss_base_bits = 0x03;
418 chip->wss_base = 0xe80;
419 wss_base_bits = 0x01;
422 chip->wss_base = 0xf40;
423 wss_base_bits = 0x02;
426 snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n", port);
429 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
437 //#endif /* OPTi93X */
451 snd_printk(KERN_WARNING "WSS irq # %d not valid\n", irq);
452 goto __skip_resources;
466 snd_printk(KERN_WARNING "WSS dma1 # %d not valid\n", dma1);
467 goto __skip_resources;
470 #if defined(CS4231) || defined(OPTi93X)
472 snd_printk(KERN_ERR "don't want to share dmas\n");
481 snd_printk(KERN_WARNING "WSS dma2 # %d not valid\n", dma2);
482 goto __skip_resources;
485 #endif /* CS4231 || OPTi93X */
488 outb(irq_bits << 3 | dma_bits, chip->wss_base);
490 snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits));
494 if (chip->hardware > OPTi9XX_HW_82C928) {
500 mpu_port_bits = 0x03;
503 mpu_port_bits = 0x02;
506 mpu_port_bits = 0x01;
509 mpu_port_bits = 0x00;
512 snd_printk(KERN_WARNING
513 "MPU-401 port 0x%lx not valid\n", mpu_port);
531 snd_printk(KERN_WARNING "MPU-401 irq # %d not valid\n",
536 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6),
537 (mpu_port <= 0) ? 0x00 :
538 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
548 static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_step, -9300, 300, 0);
549 static const DECLARE_TLV_DB_SCALE(db_scale_5bit, -4650, 150, 0);
550 static const DECLARE_TLV_DB_SCALE(db_scale_4bit_12db_max, -3300, 300, 0);
552 static const struct snd_kcontrol_new snd_opti93x_controls[] = {
553 WSS_DOUBLE("Master Playback Switch", 0,
554 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
555 WSS_DOUBLE_TLV("Master Playback Volume", 0,
556 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1,
557 db_scale_5bit_3db_step),
558 WSS_DOUBLE_TLV("PCM Playback Volume", 0,
559 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 31, 1,
561 WSS_DOUBLE_TLV("FM Playback Volume", 0,
562 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 1, 1, 15, 1,
563 db_scale_4bit_12db_max),
564 WSS_DOUBLE("Line Playback Switch", 0,
565 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
566 WSS_DOUBLE_TLV("Line Playback Volume", 0,
567 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 15, 1,
568 db_scale_4bit_12db_max),
569 WSS_DOUBLE("Mic Playback Switch", 0,
570 OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
571 WSS_DOUBLE_TLV("Mic Playback Volume", 0,
572 OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1,
573 db_scale_4bit_12db_max),
574 WSS_DOUBLE_TLV("CD Playback Volume", 0,
575 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 1, 1, 15, 1,
576 db_scale_4bit_12db_max),
577 WSS_DOUBLE("Aux Playback Switch", 0,
578 OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
579 WSS_DOUBLE_TLV("Aux Playback Volume", 0,
580 OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1,
581 db_scale_4bit_12db_max),
584 static int snd_opti93x_mixer(struct snd_wss *chip)
586 struct snd_card *card;
588 struct snd_ctl_elem_id id1, id2;
591 if (snd_BUG_ON(!chip || !chip->pcm))
596 strcpy(card->mixername, chip->pcm->name);
598 memset(&id1, 0, sizeof(id1));
599 memset(&id2, 0, sizeof(id2));
600 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
601 /* reassign AUX0 switch to CD */
602 strcpy(id1.name, "Aux Playback Switch");
603 strcpy(id2.name, "CD Playback Switch");
604 err = snd_ctl_rename_id(card, &id1, &id2);
606 snd_printk(KERN_ERR "Cannot rename opti93x control\n");
609 /* reassign AUX1 switch to FM */
610 strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
611 strcpy(id2.name, "FM Playback Switch");
612 err = snd_ctl_rename_id(card, &id1, &id2);
614 snd_printk(KERN_ERR "Cannot rename opti93x control\n");
617 /* remove AUX1 volume */
618 strcpy(id1.name, "Aux Playback Volume"); id1.index = 1;
619 snd_ctl_remove_id(card, &id1);
621 /* Replace WSS volume controls with OPTi93x volume controls */
623 for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) {
624 strcpy(id1.name, snd_opti93x_controls[idx].name);
625 snd_ctl_remove_id(card, &id1);
627 err = snd_ctl_add(card,
628 snd_ctl_new1(&snd_opti93x_controls[idx], chip));
635 static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id)
637 struct snd_opti9xx *chip = dev_id;
638 struct snd_wss *codec = chip->codec;
639 unsigned char status;
644 status = snd_opti9xx_read(chip, OPTi9XX_MC_REG(11));
645 if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream)
646 snd_pcm_period_elapsed(codec->playback_substream);
647 if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) {
648 snd_wss_overrange(codec);
649 snd_pcm_period_elapsed(codec->capture_substream);
651 outb(0x00, OPTi93X_PORT(codec, STATUS));
657 static int snd_opti9xx_read_check(struct snd_card *card,
658 struct snd_opti9xx *chip)
666 devm_request_region(card->dev, chip->mc_base,
667 chip->mc_base_size, "OPTi9xx MC");
668 if (!chip->res_mc_base)
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)))
677 devm_request_region(card->dev, chip->mc_indir_index, 2,
679 if (!chip->res_mc_indir)
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 devm_release_resource(card->dev, chip->res_mc_indir);
693 chip->res_mc_indir = NULL;
695 devm_release_resource(card->dev, chip->res_mc_base);
696 chip->res_mc_base = NULL;
701 static int 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(card, chip);
719 chip->mc_indir_index = 0;
726 static int 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;
732 struct pnp_dev *devmpu;
734 struct pnp_dev *devmc;
737 pdev = pnp_request_card_device(card, pid->devs[0].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 /* adjust mc_indir_index - some cards report it at 0xe?d,
751 other at 0xe?c but it really is always at 0xe?e */
752 chip->mc_indir_index = (pnp_port_start(pdev, 3) & ~0xf) | 0xe;
754 devmc = pnp_request_card_device(card, pid->devs[2].id, NULL);
758 err = pnp_activate_dev(devmc);
760 snd_printk(KERN_ERR "MC pnp configure failure: %d\n", err);
764 port = pnp_port_start(pdev, 1);
765 fm_port = pnp_port_start(pdev, 2) + 8;
767 * The MC(0) is never accessed and card does not
768 * include it in the PnP resource range. OPTI93x include it.
770 chip->mc_base = pnp_port_start(devmc, 0) - 1;
771 chip->mc_base_size = pnp_port_len(devmc, 0) + 1;
773 irq = pnp_irq(pdev, 0);
774 dma1 = pnp_dma(pdev, 0);
775 #if defined(CS4231) || defined(OPTi93X)
776 dma2 = pnp_dma(pdev, 1);
777 #endif /* CS4231 || OPTi93X */
779 devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
781 if (devmpu && mpu_port > 0) {
782 err = pnp_activate_dev(devmpu);
784 snd_printk(KERN_ERR "MPU401 pnp configure failure\n");
787 mpu_port = pnp_port_start(devmpu, 0);
788 mpu_irq = pnp_irq(devmpu, 0);
791 return pid->driver_data;
793 #endif /* CONFIG_PNP */
795 static int snd_opti9xx_probe(struct snd_card *card)
797 static const long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
800 struct snd_opti9xx *chip = card->private_data;
801 struct snd_wss *codec;
802 struct snd_rawmidi *rmidi;
803 struct snd_hwdep *synth;
805 #if defined(CS4231) || defined(OPTi93X)
811 if (port == SNDRV_AUTO_PORT) {
812 port = snd_legacy_find_free_ioport(possible_ports, 4);
814 snd_printk(KERN_ERR "unable to find a free WSS port\n");
818 error = snd_opti9xx_configure(chip, port, irq, dma1, xdma2,
823 error = snd_wss_create(card, chip->wss_base + 4, -1, irq, dma1, xdma2,
825 WSS_HW_OPTI93X, WSS_HWSHARE_IRQ,
833 error = snd_wss_pcm(codec, 0);
836 error = snd_wss_mixer(codec);
840 error = snd_opti93x_mixer(codec);
845 error = snd_wss_timer(codec, 0);
850 error = devm_request_irq(card->dev, irq, snd_opti93x_interrupt,
851 0, DEV_NAME" - WSS", chip);
853 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", irq);
858 card->sync_irq = chip->irq;
859 strcpy(card->driver, chip->name);
860 sprintf(card->shortname, "OPTi %s", card->driver);
861 #if defined(CS4231) || defined(OPTi93X)
862 snprintf(card->longname, sizeof(card->longname),
863 "%s, %s at 0x%lx, irq %d, dma %d&%d",
864 card->shortname, codec->pcm->name,
865 chip->wss_base + 4, irq, dma1, xdma2);
867 snprintf(card->longname, sizeof(card->longname),
868 "%s, %s at 0x%lx, irq %d, dma %d",
869 card->shortname, codec->pcm->name, chip->wss_base + 4, irq,
871 #endif /* CS4231 || OPTi93X */
873 if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT)
876 error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
877 mpu_port, 0, mpu_irq, &rmidi);
879 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
883 if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
884 struct snd_opl3 *opl3 = NULL;
886 if (chip->hardware == OPTi9XX_HW_82C928 ||
887 chip->hardware == OPTi9XX_HW_82C929 ||
888 chip->hardware == OPTi9XX_HW_82C924) {
889 struct snd_opl4 *opl4;
890 /* assume we have an OPL4 */
891 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
893 if (snd_opl4_create(card, fm_port, fm_port - 8,
894 2, &opl3, &opl4) < 0) {
895 /* no luck, use OPL3 instead */
896 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
900 #endif /* !OPTi93X */
901 if (!opl3 && snd_opl3_create(card, fm_port, fm_port + 2,
902 OPL3_HW_AUTO, 0, &opl3) < 0) {
903 snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
904 fm_port, fm_port + 4 - 1);
907 error = snd_opl3_hwdep_new(opl3, 0, 1, &synth);
913 return snd_card_register(card);
916 static int snd_opti9xx_card_new(struct device *pdev, struct snd_card **cardp)
918 struct snd_card *card;
921 err = snd_devm_card_new(pdev, index, id, THIS_MODULE,
922 sizeof(struct snd_opti9xx), &card);
929 static int snd_opti9xx_isa_match(struct device *devptr,
933 if (snd_opti9xx_pnp_is_probed)
941 static int snd_opti9xx_isa_probe(struct device *devptr,
944 struct snd_card *card;
946 static const long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};
948 static const int possible_irqs[] = {5, 9, 10, 11, 7, -1};
950 static const int possible_irqs[] = {9, 10, 11, 7, -1};
952 static const int possible_mpu_irqs[] = {5, 9, 10, 7, -1};
953 static const int possible_dma1s[] = {3, 1, 0, -1};
954 #if defined(CS4231) || defined(OPTi93X)
955 static const int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
956 #endif /* CS4231 || OPTi93X */
958 if (mpu_port == SNDRV_AUTO_PORT) {
959 mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2);
961 snd_printk(KERN_ERR "unable to find a free MPU401 port\n");
965 if (irq == SNDRV_AUTO_IRQ) {
966 irq = snd_legacy_find_free_irq(possible_irqs);
968 snd_printk(KERN_ERR "unable to find a free IRQ\n");
972 if (mpu_irq == SNDRV_AUTO_IRQ) {
973 mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs);
975 snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n");
979 if (dma1 == SNDRV_AUTO_DMA) {
980 dma1 = snd_legacy_find_free_dma(possible_dma1s);
982 snd_printk(KERN_ERR "unable to find a free DMA1\n");
986 #if defined(CS4231) || defined(OPTi93X)
987 if (dma2 == SNDRV_AUTO_DMA) {
988 dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4]);
990 snd_printk(KERN_ERR "unable to find a free DMA2\n");
996 error = snd_opti9xx_card_new(devptr, &card);
1000 error = snd_card_opti9xx_detect(card, card->private_data);
1003 error = snd_opti9xx_probe(card);
1006 dev_set_drvdata(devptr, card);
1011 static int snd_opti9xx_suspend(struct snd_card *card)
1013 struct snd_opti9xx *chip = card->private_data;
1015 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1016 chip->codec->suspend(chip->codec);
1020 static int snd_opti9xx_resume(struct snd_card *card)
1022 struct snd_opti9xx *chip = card->private_data;
1024 #if defined(CS4231) || defined(OPTi93X)
1030 error = snd_opti9xx_configure(chip, port, irq, dma1, xdma2,
1034 chip->codec->resume(chip->codec);
1035 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
1039 static int snd_opti9xx_isa_suspend(struct device *dev, unsigned int n,
1042 return snd_opti9xx_suspend(dev_get_drvdata(dev));
1045 static int snd_opti9xx_isa_resume(struct device *dev, unsigned int n)
1047 return snd_opti9xx_resume(dev_get_drvdata(dev));
1051 static struct isa_driver snd_opti9xx_driver = {
1052 .match = snd_opti9xx_isa_match,
1053 .probe = snd_opti9xx_isa_probe,
1055 .suspend = snd_opti9xx_isa_suspend,
1056 .resume = snd_opti9xx_isa_resume,
1064 static int snd_opti9xx_pnp_probe(struct pnp_card_link *pcard,
1065 const struct pnp_card_device_id *pid)
1067 struct snd_card *card;
1069 struct snd_opti9xx *chip;
1071 if (snd_opti9xx_pnp_is_probed)
1075 error = snd_opti9xx_card_new(&pcard->card->dev, &card);
1078 chip = card->private_data;
1080 hw = snd_card_opti9xx_pnp(chip, pcard, pid);
1083 hw = OPTi9XX_HW_82C924;
1086 hw = OPTi9XX_HW_82C925;
1089 hw = OPTi9XX_HW_82C931;
1095 error = snd_opti9xx_init(chip, hw);
1098 error = snd_opti9xx_read_check(card, chip);
1100 snd_printk(KERN_ERR "OPTI chip not found\n");
1103 error = snd_opti9xx_probe(card);
1106 pnp_set_card_drvdata(pcard, card);
1107 snd_opti9xx_pnp_is_probed = 1;
1111 static void snd_opti9xx_pnp_remove(struct pnp_card_link *pcard)
1113 snd_opti9xx_pnp_is_probed = 0;
1117 static int snd_opti9xx_pnp_suspend(struct pnp_card_link *pcard,
1120 return snd_opti9xx_suspend(pnp_get_card_drvdata(pcard));
1123 static int snd_opti9xx_pnp_resume(struct pnp_card_link *pcard)
1125 return snd_opti9xx_resume(pnp_get_card_drvdata(pcard));
1129 static struct pnp_card_driver opti9xx_pnpc_driver = {
1130 .flags = PNP_DRIVER_RES_DISABLE,
1132 .id_table = snd_opti9xx_pnpids,
1133 .probe = snd_opti9xx_pnp_probe,
1134 .remove = snd_opti9xx_pnp_remove,
1136 .suspend = snd_opti9xx_pnp_suspend,
1137 .resume = snd_opti9xx_pnp_resume,
1143 #define CHIP_NAME "82C93x"
1145 #define CHIP_NAME "82C92x"
1148 static int __init alsa_card_opti9xx_init(void)
1151 pnp_register_card_driver(&opti9xx_pnpc_driver);
1152 if (snd_opti9xx_pnp_is_probed)
1154 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
1156 return isa_register_driver(&snd_opti9xx_driver, 1);
1159 static void __exit alsa_card_opti9xx_exit(void)
1161 if (!snd_opti9xx_pnp_is_probed) {
1162 isa_unregister_driver(&snd_opti9xx_driver);
1166 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
1170 module_init(alsa_card_opti9xx_init)
1171 module_exit(alsa_card_opti9xx_exit)