4 * A low level driver for Yamaha OPL3-SA2 and SA3 cards.
5 * NOTE: All traces of the name OPL3-SAx have now (December 2000) been
6 * removed from the driver code, as an email exchange with Yamaha
7 * provided the information that the YMF-719 is indeed just a
10 * Copyright 1998-2001 Scott Murray <scott@spiteful.org>
12 * Originally based on the CS4232 driver (in cs4232.c) by Hannu Savolainen
13 * and others. Now incorporates code/ideas from pss.c, also by Hannu
14 * Savolainen. Both of those files are distributed with the following
17 * "Copyright (C) by Hannu Savolainen 1993-1997
19 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
20 * Version 2 (June 1991). See the "COPYING" file distributed with this software
23 * As such, in accordance with the above license, this file, opl3sa2.c, is
24 * distributed under the GNU GENERAL PUBLIC LICENSE (GPL) Version 2 (June 1991).
25 * See the "COPYING" file distributed with this software for more information.
29 * Scott Murray Original driver (Jun 14, 1998)
30 * Paul J.Y. Lahaie Changed probing / attach code order
31 * Scott Murray Added mixer support (Dec 03, 1998)
32 * Scott Murray Changed detection code to be more forgiving,
33 * added force option as last resort,
34 * fixed ioctl return values. (Dec 30, 1998)
35 * Scott Murray Simpler detection code should work all the time now
36 * (with thanks to Ben Hutchings for the heuristic),
37 * removed now unnecessary force option. (Jan 5, 1999)
38 * Christoph Hellwig Adapted to module_init/module_exit (Mar 4, 2000)
39 * Scott Murray Reworked SA2 versus SA3 mixer code, updated chipset
40 * version detection code (again!). (Dec 5, 2000)
41 * Scott Murray Adjusted master volume mixer scaling. (Dec 6, 2000)
42 * Scott Murray Based on a patch by Joel Yliluoma (aka Bisqwit),
43 * integrated wide mixer and adjusted mic, bass, treble
44 * scaling. (Dec 6, 2000)
45 * Scott Murray Based on a patch by Peter Englmaier, integrated
46 * ymode and loopback options. (Dec 6, 2000)
47 * Scott Murray Inspired by a patch by Peter Englmaier, and based on
48 * what ALSA does, added initialization code for the
49 * default DMA and IRQ settings. (Dec 6, 2000)
50 * Scott Murray Added some more checks to the card detection code,
51 * based on what ALSA does. (Dec 12, 2000)
52 * Scott Murray Inspired by similar patches from John Fremlin,
53 * Jim Radford, Mike Rolig, and Ingmar Steen, added 2.4
54 * ISA PnP API support, mainly based on bits from
55 * sb_card.c and awe_wave.c. (Dec 12, 2000)
56 * Scott Murray Some small cleanups to the init code output.
58 * Zwane Mwaikambo Added PM support. (Dec 4 2001)
60 * Adam Belay Converted driver to new PnP Layer (Oct 12, 2002)
61 * Zwane Mwaikambo Code, data structure cleanups. (Feb 15 2002)
62 * Zwane Mwaikambo Free resources during auxiliary device probe
63 * failures (Apr 29 2002)
67 #include <linux/config.h>
68 #include <linux/pnp.h>
69 #include <linux/init.h>
70 #include <linux/module.h>
71 #include <linux/delay.h>
73 #include <linux/pm_legacy.h>
74 #include "sound_config.h"
79 #define OPL3SA2_MODULE_NAME "opl3sa2"
80 #define PFX OPL3SA2_MODULE_NAME ": "
82 /* Useful control port indexes: */
83 #define OPL3SA2_PM 0x01
84 #define OPL3SA2_SYS_CTRL 0x02
85 #define OPL3SA2_IRQ_CONFIG 0x03
86 #define OPL3SA2_DMA_CONFIG 0x06
87 #define OPL3SA2_MASTER_LEFT 0x07
88 #define OPL3SA2_MASTER_RIGHT 0x08
89 #define OPL3SA2_MIC 0x09
90 #define OPL3SA2_MISC 0x0A
92 #define OPL3SA3_WIDE 0x14
93 #define OPL3SA3_BASS 0x15
94 #define OPL3SA3_TREBLE 0x16
96 /* Useful constants: */
97 #define DEFAULT_VOLUME 50
98 #define DEFAULT_MIC 50
99 #define DEFAULT_TIMBRE 0
101 /* Power saving modes */
102 #define OPL3SA2_PM_MODE0 0x00
103 #define OPL3SA2_PM_MODE1 0x04 /* PSV */
104 #define OPL3SA2_PM_MODE2 0x05 /* PSV | PDX */
105 #define OPL3SA2_PM_MODE3 0x27 /* ADOWN | PSV | PDN | PDX */
108 /* For checking against what the card returns: */
109 #define VERSION_UNKNOWN 0
110 #define VERSION_YMF711 1
111 #define VERSION_YMF715 2
112 #define VERSION_YMF715B 3
113 #define VERSION_YMF715E 4
114 /* also assuming that anything > 4 but <= 7 is a 715E */
116 /* Chipset type constants for use below */
117 #define CHIPSET_UNKNOWN -1
118 #define CHIPSET_OPL3SA2 0
119 #define CHIPSET_OPL3SA3 1
120 static const char *CHIPSET_TABLE[] = {"OPL3-SA2", "OPL3-SA3"};
123 #define OPL3SA2_CARDS_MAX 4
125 #define OPL3SA2_CARDS_MAX 1
128 /* This should be pretty obvious */
129 static int opl3sa2_cards_num;
132 /* device resources */
133 unsigned short cfg_port;
134 struct address_info cfg;
135 struct address_info cfg_mss;
136 struct address_info cfg_mpu;
139 struct pnp_dev* pdev;
140 int activated; /* Whether said devices have been activated */
142 #ifdef CONFIG_PM_LEGACY
143 unsigned int in_suspend;
144 struct pm_dev *pmdev;
147 int chipset; /* What's my version(s)? */
152 unsigned int volume_l;
153 unsigned int volume_r;
157 unsigned int treble_l;
158 unsigned int treble_r;
162 static opl3sa2_state_t opl3sa2_state[OPL3SA2_CARDS_MAX];
167 static int __initdata io = -1;
168 static int __initdata mss_io = -1;
169 static int __initdata mpu_io = -1;
170 static int __initdata irq = -1;
171 static int __initdata dma = -1;
172 static int __initdata dma2 = -1;
173 static int __initdata ymode = -1;
174 static int __initdata loopback = -1;
177 /* PnP specific parameters */
178 static int __initdata isapnp = 1;
179 static int __initdata multiple = 1;
181 /* Whether said devices have been activated */
182 static int opl3sa2_activated[OPL3SA2_CARDS_MAX];
184 static int __initdata isapnp; /* = 0 */
185 static int __initdata multiple; /* = 0 */
188 MODULE_DESCRIPTION("Module for OPL3-SA2 and SA3 sound cards (uses AD1848 MSS driver).");
189 MODULE_AUTHOR("Scott Murray <scott@spiteful.org>");
190 MODULE_LICENSE("GPL");
193 module_param(io, int, 0);
194 MODULE_PARM_DESC(io, "Set I/O base of OPL3-SA2 or SA3 card (usually 0x370. Address must be even and must be from 0x100 to 0xFFE)");
196 module_param(mss_io, int, 0);
197 MODULE_PARM_DESC(mss_io, "Set MSS (audio) I/O base (0x530, 0xE80, or other. Address must end in 0 or 4 and must be from 0x530 to 0xF48)");
199 module_param(mpu_io, int, 0);
200 MODULE_PARM_DESC(mpu_io, "Set MIDI I/O base (0x330 or other. Address must be even and must be from 0x300 to 0x334)");
202 module_param(irq, int, 0);
203 MODULE_PARM_DESC(irq, "Set MSS (audio) IRQ (5, 7, 9, 10, 11, 12)");
205 module_param(dma, int, 0);
206 MODULE_PARM_DESC(dma, "Set MSS (audio) first DMA channel (0, 1, 3)");
208 module_param(dma2, int, 0);
209 MODULE_PARM_DESC(dma2, "Set MSS (audio) second DMA channel (0, 1, 3)");
211 module_param(ymode, int, 0);
212 MODULE_PARM_DESC(ymode, "Set Yamaha 3D enhancement mode (0 = Desktop/Normal, 1 = Notebook PC (1), 2 = Notebook PC (2), 3 = Hi-Fi)");
214 module_param(loopback, int, 0);
215 MODULE_PARM_DESC(loopback, "Set A/D input source. Useful for echo cancellation (0 = Mic Rch (default), 1 = Mono output loopback)");
218 module_param(isapnp, bool, 0);
219 MODULE_PARM_DESC(isapnp, "When set to 0, ISA PnP support will be disabled");
221 module_param(multiple, bool, 0);
222 MODULE_PARM_DESC(multiple, "When set to 0, will not search for multiple cards");
227 * Standard read and write functions
230 static inline void opl3sa2_write(unsigned short port,
235 outb(data, port + 1);
239 static inline void opl3sa2_read(unsigned short port,
244 *data = inb(port + 1);
249 * All of the mixer functions...
252 static void opl3sa2_set_volume(opl3sa2_state_t* devc, int left, int right)
254 static unsigned char scale[101] = {
255 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e,
256 0x0e, 0x0e, 0x0e, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0c,
257 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0b, 0x0b, 0x0b, 0x0b,
258 0x0b, 0x0b, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x09, 0x09,
259 0x09, 0x09, 0x09, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x08,
260 0x08, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06,
261 0x06, 0x06, 0x06, 0x06, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
262 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03,
263 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01,
264 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
271 /* If level is zero, turn on mute */
275 opl3sa2_write(devc->cfg_port, OPL3SA2_MASTER_LEFT, vol);
279 /* If level is zero, turn on mute */
283 opl3sa2_write(devc->cfg_port, OPL3SA2_MASTER_RIGHT, vol);
287 static void opl3sa2_set_mic(opl3sa2_state_t* devc, int level)
289 unsigned char vol = 0x1F;
291 if((level >= 0) && (level <= 100))
292 vol = 0x1F - (unsigned char) (32 * level / 101);
294 /* If level is zero, turn on mute */
298 opl3sa2_write(devc->cfg_port, OPL3SA2_MIC, vol);
302 static void opl3sa3_set_bass(opl3sa2_state_t* devc, int left, int right)
306 bass = left ? ((unsigned char) (8 * left / 101)) : 0;
307 bass |= (right ? ((unsigned char) (8 * right / 101)) : 0) << 4;
309 opl3sa2_write(devc->cfg_port, OPL3SA3_BASS, bass);
313 static void opl3sa3_set_treble(opl3sa2_state_t* devc, int left, int right)
315 unsigned char treble;
317 treble = left ? ((unsigned char) (8 * left / 101)) : 0;
318 treble |= (right ? ((unsigned char) (8 * right / 101)) : 0) << 4;
320 opl3sa2_write(devc->cfg_port, OPL3SA3_TREBLE, treble);
326 static void opl3sa2_mixer_reset(opl3sa2_state_t* devc)
329 opl3sa2_set_volume(devc, DEFAULT_VOLUME, DEFAULT_VOLUME);
330 devc->volume_l = devc->volume_r = DEFAULT_VOLUME;
332 opl3sa2_set_mic(devc, DEFAULT_MIC);
333 devc->mic = DEFAULT_MIC;
335 if (devc->chipset == CHIPSET_OPL3SA3) {
336 opl3sa3_set_bass(devc, DEFAULT_TIMBRE, DEFAULT_TIMBRE);
337 devc->bass_l = devc->bass_r = DEFAULT_TIMBRE;
338 opl3sa3_set_treble(devc, DEFAULT_TIMBRE, DEFAULT_TIMBRE);
339 devc->treble_l = devc->treble_r = DEFAULT_TIMBRE;
344 /* Currently only used for power management */
345 #ifdef CONFIG_PM_LEGACY
346 static void opl3sa2_mixer_restore(opl3sa2_state_t* devc)
349 opl3sa2_set_volume(devc, devc->volume_l, devc->volume_r);
350 opl3sa2_set_mic(devc, devc->mic);
352 if (devc->chipset == CHIPSET_OPL3SA3) {
353 opl3sa3_set_bass(devc, devc->bass_l, devc->bass_r);
354 opl3sa3_set_treble(devc, devc->treble_l, devc->treble_r);
358 #endif /* CONFIG_PM_LEGACY */
360 static inline void arg_to_vol_mono(unsigned int vol, int* value)
371 static inline void arg_to_vol_stereo(unsigned int vol, int* aleft, int* aright)
373 arg_to_vol_mono(vol, aleft);
374 arg_to_vol_mono(vol >> 8, aright);
378 static inline int ret_vol_mono(int vol)
380 return ((vol << 8) | vol);
384 static inline int ret_vol_stereo(int left, int right)
386 return ((right << 8) | left);
390 static int opl3sa2_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
392 int retval, value, cmdf = cmd & 0xff;
393 int __user *p = (int __user *)arg;
395 opl3sa2_state_t* devc = &opl3sa2_state[dev];
398 case SOUND_MIXER_VOLUME:
399 case SOUND_MIXER_MIC:
400 case SOUND_MIXER_DEVMASK:
401 case SOUND_MIXER_STEREODEVS:
402 case SOUND_MIXER_RECMASK:
403 case SOUND_MIXER_RECSRC:
404 case SOUND_MIXER_CAPS:
411 if (((cmd >> 8) & 0xff) != 'M')
415 if (_SIOC_DIR (cmd) & _SIOC_WRITE) {
417 case SOUND_MIXER_VOLUME:
418 retval = get_user(value, (unsigned __user *) arg);
421 arg_to_vol_stereo(value, &devc->volume_l, &devc->volume_r);
422 opl3sa2_set_volume(devc, devc->volume_l, devc->volume_r);
423 value = ret_vol_stereo(devc->volume_l, devc->volume_r);
424 retval = put_user(value, p);
427 case SOUND_MIXER_MIC:
428 retval = get_user(value, (unsigned __user *) arg);
431 arg_to_vol_mono(value, &devc->mic);
432 opl3sa2_set_mic(devc, devc->mic);
433 value = ret_vol_mono(devc->mic);
434 retval = put_user(value, p);
446 case SOUND_MIXER_DEVMASK:
447 retval = put_user(SOUND_MASK_VOLUME | SOUND_MASK_MIC, p);
450 case SOUND_MIXER_STEREODEVS:
451 retval = put_user(SOUND_MASK_VOLUME, p);
454 case SOUND_MIXER_RECMASK:
455 /* No recording devices */
456 retval = put_user(0, p);
459 case SOUND_MIXER_CAPS:
460 retval = put_user(SOUND_CAP_EXCL_INPUT, p);
463 case SOUND_MIXER_RECSRC:
464 /* No recording source */
465 retval = put_user(0, p);
468 case SOUND_MIXER_VOLUME:
469 value = ret_vol_stereo(devc->volume_l, devc->volume_r);
470 retval = put_user(value, p);
473 case SOUND_MIXER_MIC:
474 value = ret_vol_mono(devc->mic);
484 /* opl3sa2_mixer_ioctl end */
487 static int opl3sa3_mixer_ioctl(int dev, unsigned int cmd, void __user * arg)
489 int value, retval, cmdf = cmd & 0xff;
491 opl3sa2_state_t* devc = &opl3sa2_state[dev];
494 case SOUND_MIXER_BASS:
495 value = ret_vol_stereo(devc->bass_l, devc->bass_r);
496 retval = put_user(value, (int __user *) arg);
499 case SOUND_MIXER_TREBLE:
500 value = ret_vol_stereo(devc->treble_l, devc->treble_r);
501 retval = put_user(value, (int __user *) arg);
504 case SOUND_MIXER_DIGITAL1:
505 value = ret_vol_stereo(devc->wide_l, devc->wide_r);
506 retval = put_user(value, (int __user *) arg);
514 /* opl3sa3_mixer_ioctl end */
517 static struct mixer_operations opl3sa2_mixer_operations =
519 .owner = THIS_MODULE,
521 .name = "Yamaha OPL3-SA2",
522 .ioctl = opl3sa2_mixer_ioctl
525 static struct mixer_operations opl3sa3_mixer_operations =
527 .owner = THIS_MODULE,
529 .name = "Yamaha OPL3-SA3",
530 .ioctl = opl3sa3_mixer_ioctl
533 /* End of mixer-related stuff */
537 * Component probe, attach, unload functions
540 static inline void __exit unload_opl3sa2_mpu(struct address_info *hw_config)
542 unload_mpu401(hw_config);
546 static void __init attach_opl3sa2_mss(struct address_info* hw_config, struct resource *ports)
550 initial_mixers = num_mixers;
551 attach_ms_sound(hw_config, ports, THIS_MODULE); /* Slot 0 */
552 if (hw_config->slots[0] != -1) {
553 /* Did the MSS driver install? */
554 if(num_mixers == (initial_mixers + 1)) {
555 /* The MSS mixer is installed, reroute mixers appropiately */
556 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_CD);
557 AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_SYNTH);
558 AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_LINE);
561 printk(KERN_ERR PFX "MSS mixer not installed?\n");
567 static inline void __exit unload_opl3sa2_mss(struct address_info* hw_config)
569 unload_ms_sound(hw_config);
573 static int __init probe_opl3sa2(struct address_info* hw_config, int card)
577 unsigned char version;
580 * Try and allocate our I/O port range.
582 if (!request_region(hw_config->io_base, 2, OPL3SA2_MODULE_NAME)) {
583 printk(KERN_ERR PFX "Control I/O port %#x not free\n",
589 * Check if writing to the read-only version bits of the miscellaneous
590 * register succeeds or not (it should not).
592 opl3sa2_read(hw_config->io_base, OPL3SA2_MISC, &misc);
593 opl3sa2_write(hw_config->io_base, OPL3SA2_MISC, misc ^ 0x07);
594 opl3sa2_read(hw_config->io_base, OPL3SA2_MISC, &tmp);
596 printk(KERN_ERR PFX "Control I/O port %#x is not a YMF7xx chipset!\n",
602 * Check if the MIC register is accessible.
604 opl3sa2_read(hw_config->io_base, OPL3SA2_MIC, &tmp);
605 opl3sa2_write(hw_config->io_base, OPL3SA2_MIC, 0x8a);
606 opl3sa2_read(hw_config->io_base, OPL3SA2_MIC, &tmp);
607 if((tmp & 0x9f) != 0x8a) {
609 PFX "Control I/O port %#x is not a YMF7xx chipset!\n",
613 opl3sa2_write(hw_config->io_base, OPL3SA2_MIC, tmp);
616 * Determine chipset type (SA2 or SA3)
618 * This is done by looking at the chipset version in the lower 3 bits
619 * of the miscellaneous register.
621 version = misc & 0x07;
622 printk(KERN_DEBUG PFX "Chipset version = %#x\n", version);
625 opl3sa2_state[card].chipset = CHIPSET_UNKNOWN;
627 PFX "Unknown Yamaha audio controller version\n");
631 opl3sa2_state[card].chipset = CHIPSET_OPL3SA2;
632 printk(KERN_INFO PFX "Found OPL3-SA2 (YMF711)\n");
636 opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
638 PFX "Found OPL3-SA3 (YMF715 or YMF719)\n");
641 case VERSION_YMF715B:
642 opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
644 PFX "Found OPL3-SA3 (YMF715B or YMF719B)\n");
647 case VERSION_YMF715E:
649 opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
651 PFX "Found OPL3-SA3 (YMF715E or YMF719E)\n");
655 if (opl3sa2_state[card].chipset != CHIPSET_UNKNOWN) {
656 /* Generate a pretty name */
657 opl3sa2_state[card].chipset_name = (char *)CHIPSET_TABLE[opl3sa2_state[card].chipset];
662 release_region(hw_config->io_base, 2);
668 static void __init attach_opl3sa2(struct address_info* hw_config, int card)
670 /* Initialize IRQ configuration to IRQ-B: -, IRQ-A: WSS+MPU+OPL3 */
671 opl3sa2_write(hw_config->io_base, OPL3SA2_IRQ_CONFIG, 0x0d);
673 /* Initialize DMA configuration */
674 if(hw_config->dma2 == hw_config->dma) {
675 /* Want DMA configuration DMA-B: -, DMA-A: WSS-P+WSS-R */
676 opl3sa2_write(hw_config->io_base, OPL3SA2_DMA_CONFIG, 0x03);
679 /* Want DMA configuration DMA-B: WSS-R, DMA-A: WSS-P */
680 opl3sa2_write(hw_config->io_base, OPL3SA2_DMA_CONFIG, 0x21);
685 static void __init attach_opl3sa2_mixer(struct address_info *hw_config, int card)
687 struct mixer_operations* mixer_operations;
688 opl3sa2_state_t* devc = &opl3sa2_state[card];
690 /* Install master mixer */
691 if (devc->chipset == CHIPSET_OPL3SA3) {
692 mixer_operations = &opl3sa3_mixer_operations;
695 mixer_operations = &opl3sa2_mixer_operations;
698 devc->cfg_port = hw_config->io_base;
699 devc->mixer = sound_install_mixer(MIXER_DRIVER_VERSION,
700 mixer_operations->name,
702 sizeof(struct mixer_operations),
704 if(devc->mixer < 0) {
705 printk(KERN_ERR PFX "Could not install %s master mixer\n",
706 mixer_operations->name);
709 opl3sa2_mixer_reset(devc);
715 static void opl3sa2_clear_slots(struct address_info* hw_config)
719 for(i = 0; i < 6; i++) {
720 hw_config->slots[i] = -1;
725 static void __init opl3sa2_set_ymode(struct address_info* hw_config, int ymode)
728 * Set the Yamaha 3D enhancement mode (aka Ymersion) if asked to and
731 * 0: Desktop (aka normal) 5-12 cm speakers
732 * 1: Notebook PC mode 1 3 cm speakers
733 * 2: Notebook PC mode 2 1.5 cm speakers
734 * 3: Hi-fi 16-38 cm speakers
736 if(ymode >= 0 && ymode <= 3) {
737 unsigned char sys_ctrl;
739 opl3sa2_read(hw_config->io_base, OPL3SA2_SYS_CTRL, &sys_ctrl);
740 sys_ctrl = (sys_ctrl & 0xcf) | ((ymode & 3) << 4);
741 opl3sa2_write(hw_config->io_base, OPL3SA2_SYS_CTRL, sys_ctrl);
744 printk(KERN_ERR PFX "not setting ymode, it must be one of 0,1,2,3\n");
749 static void __init opl3sa2_set_loopback(struct address_info* hw_config, int loopback)
751 if(loopback >= 0 && loopback <= 1) {
754 opl3sa2_read(hw_config->io_base, OPL3SA2_MISC, &misc);
755 misc = (misc & 0xef) | ((loopback & 1) << 4);
756 opl3sa2_write(hw_config->io_base, OPL3SA2_MISC, misc);
759 printk(KERN_ERR PFX "not setting loopback, it must be either 0 or 1\n");
764 static void __exit unload_opl3sa2(struct address_info* hw_config, int card)
766 /* Release control ports */
767 release_region(hw_config->io_base, 2);
770 if(opl3sa2_state[card].mixer >= 0)
771 sound_unload_mixerdev(opl3sa2_state[card].mixer);
776 static struct pnp_device_id pnp_opl3sa2_list[] = {
777 {.id = "YMH0021", .driver_data = 0},
781 MODULE_DEVICE_TABLE(pnp, pnp_opl3sa2_list);
783 static int opl3sa2_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
785 int card = opl3sa2_cards_num;
787 /* we don't actually want to return an error as the user may have specified
788 * no multiple card search
791 if (opl3sa2_cards_num == OPL3SA2_CARDS_MAX)
793 opl3sa2_activated[card] = 1;
795 /* Our own config: */
796 opl3sa2_state[card].cfg.io_base = pnp_port_start(dev, 4);
797 opl3sa2_state[card].cfg.irq = pnp_irq(dev, 0);
798 opl3sa2_state[card].cfg.dma = pnp_dma(dev, 0);
799 opl3sa2_state[card].cfg.dma2 = pnp_dma(dev, 1);
801 /* The MSS config: */
802 opl3sa2_state[card].cfg_mss.io_base = pnp_port_start(dev, 1);
803 opl3sa2_state[card].cfg_mss.irq = pnp_irq(dev, 0);
804 opl3sa2_state[card].cfg_mss.dma = pnp_dma(dev, 0);
805 opl3sa2_state[card].cfg_mss.dma2 = pnp_dma(dev, 1);
806 opl3sa2_state[card].cfg_mss.card_subtype = 1; /* No IRQ or DMA setup */
808 opl3sa2_state[card].cfg_mpu.io_base = pnp_port_start(dev, 3);
809 opl3sa2_state[card].cfg_mpu.irq = pnp_irq(dev, 0);
810 opl3sa2_state[card].cfg_mpu.dma = -1;
811 opl3sa2_state[card].cfg_mpu.dma2 = -1;
812 opl3sa2_state[card].cfg_mpu.always_detect = 1; /* It's there, so use shared IRQs */
814 /* Call me paranoid: */
815 opl3sa2_clear_slots(&opl3sa2_state[card].cfg);
816 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mss);
817 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mpu);
819 opl3sa2_state[card].pdev = dev;
825 static struct pnp_driver opl3sa2_driver = {
827 .id_table = pnp_opl3sa2_list,
828 .probe = opl3sa2_pnp_probe,
831 #endif /* CONFIG_PNP */
833 /* End of component functions */
835 #ifdef CONFIG_PM_LEGACY
837 static DEFINE_SPINLOCK(opl3sa2_lock);
839 /* Power Management support functions */
840 static int opl3sa2_suspend(struct pm_dev *pdev, unsigned int pm_mode)
848 spin_lock_irqsave(&opl3sa2_lock,flags);
850 p = (opl3sa2_state_t *) pdev->data;
853 pm_mode = OPL3SA2_PM_MODE1;
856 pm_mode = OPL3SA2_PM_MODE2;
859 pm_mode = OPL3SA2_PM_MODE3;
862 /* we don't know howto handle this... */
863 spin_unlock_irqrestore(&opl3sa2_lock, flags);
869 /* its supposed to automute before suspending, so we won't bother */
870 opl3sa2_write(p->cfg_port, OPL3SA2_PM, pm_mode);
871 /* wait a while for the clock oscillator to stabilise */
874 spin_unlock_irqrestore(&opl3sa2_lock,flags);
878 static int opl3sa2_resume(struct pm_dev *pdev)
886 p = (opl3sa2_state_t *) pdev->data;
887 spin_lock_irqsave(&opl3sa2_lock,flags);
889 /* I don't think this is necessary */
890 opl3sa2_write(p->cfg_port, OPL3SA2_PM, OPL3SA2_PM_MODE0);
891 opl3sa2_mixer_restore(p);
894 spin_unlock_irqrestore(&opl3sa2_lock,flags);
898 static int opl3sa2_pm_callback(struct pm_dev *pdev, pm_request_t rqst, void *data)
900 unsigned long mode = (unsigned long)data;
904 return opl3sa2_suspend(pdev, mode);
907 return opl3sa2_resume(pdev);
911 #endif /* CONFIG_PM_LEGACY */
914 * Install OPL3-SA2 based card(s).
916 * Need to have ad1848 and mpu401 loaded ready.
918 static int __init init_opl3sa2(void)
922 /* Sanitize isapnp and multiple settings */
923 isapnp = isapnp != 0 ? 1 : 0;
924 multiple = multiple != 0 ? 1 : 0;
926 max = (multiple && isapnp) ? OPL3SA2_CARDS_MAX : 1;
930 pnp_register_driver(&opl3sa2_driver);
931 if(!opl3sa2_cards_num){
932 printk(KERN_INFO PFX "No PnP cards found\n");
935 max = opl3sa2_cards_num;
939 for (card = 0; card < max; card++) {
940 /* If a user wants an I/O then assume they meant it */
941 struct resource *ports;
945 if (io == -1 || irq == -1 || dma == -1 ||
946 dma2 == -1 || mss_io == -1) {
948 PFX "io, mss_io, irq, dma, and dma2 must be set\n");
955 * (NOTE: IRQ and DMA aren't used, so they're set to
956 * give pretty output from conf_printf. :)
958 opl3sa2_state[card].cfg.io_base = io;
959 opl3sa2_state[card].cfg.irq = irq;
960 opl3sa2_state[card].cfg.dma = dma;
961 opl3sa2_state[card].cfg.dma2 = dma2;
963 /* The MSS config: */
964 opl3sa2_state[card].cfg_mss.io_base = mss_io;
965 opl3sa2_state[card].cfg_mss.irq = irq;
966 opl3sa2_state[card].cfg_mss.dma = dma;
967 opl3sa2_state[card].cfg_mss.dma2 = dma2;
968 opl3sa2_state[card].cfg_mss.card_subtype = 1; /* No IRQ or DMA setup */
970 opl3sa2_state[card].cfg_mpu.io_base = mpu_io;
971 opl3sa2_state[card].cfg_mpu.irq = irq;
972 opl3sa2_state[card].cfg_mpu.dma = -1;
973 opl3sa2_state[card].cfg_mpu.always_detect = 1; /* Use shared IRQs */
975 /* Call me paranoid: */
976 opl3sa2_clear_slots(&opl3sa2_state[card].cfg);
977 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mss);
978 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mpu);
982 if (probe_opl3sa2(&opl3sa2_state[card].cfg, card))
985 base = opl3sa2_state[card].cfg_mss.io_base;
987 if (!request_region(base, 4, "WSS config"))
990 ports = request_region(base + 4, 4, "ad1848");
994 if (!probe_ms_sound(&opl3sa2_state[card].cfg_mss, ports)) {
996 * If one or more cards are already registered, don't
997 * return an error but print a warning. Note, this
998 * should never really happen unless the hardware or
999 * ISA PnP screwed up.
1001 release_region(base + 4, 4);
1003 release_region(base, 4);
1005 release_region(opl3sa2_state[card].cfg.io_base, 2);
1007 if (opl3sa2_cards_num) {
1009 PFX "There was a problem probing one "
1010 " of the ISA PNP cards, continuing\n");
1011 opl3sa2_cards_num--;
1017 attach_opl3sa2(&opl3sa2_state[card].cfg, card);
1018 conf_printf(opl3sa2_state[card].chipset_name, &opl3sa2_state[card].cfg);
1019 attach_opl3sa2_mixer(&opl3sa2_state[card].cfg, card);
1020 attach_opl3sa2_mss(&opl3sa2_state[card].cfg_mss, ports);
1023 opl3sa2_state[card].card = card;
1024 #ifdef CONFIG_PM_LEGACY
1025 /* register our power management capabilities */
1026 opl3sa2_state[card].pmdev = pm_register(PM_ISA_DEV, card, opl3sa2_pm_callback);
1027 if (opl3sa2_state[card].pmdev)
1028 opl3sa2_state[card].pmdev->data = &opl3sa2_state[card];
1029 #endif /* CONFIG_PM_LEGACY */
1032 * Set the Yamaha 3D enhancement mode (aka Ymersion) if asked to and
1036 if (opl3sa2_state[card].chipset == CHIPSET_OPL3SA2) {
1038 PFX "ymode not supported on OPL3-SA2\n");
1041 opl3sa2_set_ymode(&opl3sa2_state[card].cfg, ymode);
1046 /* Set A/D input to Mono loopback if asked to. */
1047 if (loopback != -1) {
1048 opl3sa2_set_loopback(&opl3sa2_state[card].cfg, loopback);
1051 /* Attach MPU if we've been asked to do so, failure isn't fatal */
1052 if (opl3sa2_state[card].cfg_mpu.io_base != -1) {
1053 int base = opl3sa2_state[card].cfg_mpu.io_base;
1054 struct resource *ports;
1055 ports = request_region(base, 2, "mpu401");
1058 if (!probe_mpu401(&opl3sa2_state[card].cfg_mpu, ports)) {
1059 release_region(base, 2);
1062 if (attach_mpu401(&opl3sa2_state[card].cfg_mpu, THIS_MODULE)) {
1063 printk(KERN_ERR PFX "failed to attach MPU401\n");
1064 opl3sa2_state[card].cfg_mpu.slots[1] = -1;
1071 printk(KERN_NOTICE PFX "%d PnP card(s) found.\n", opl3sa2_cards_num);
1079 * Uninstall OPL3-SA2 based card(s).
1081 static void __exit cleanup_opl3sa2(void)
1085 for(card = 0; card < opl3sa2_cards_num; card++) {
1086 #ifdef CONFIG_PM_LEGACY
1087 if (opl3sa2_state[card].pmdev)
1088 pm_unregister(opl3sa2_state[card].pmdev);
1090 if (opl3sa2_state[card].cfg_mpu.slots[1] != -1) {
1091 unload_opl3sa2_mpu(&opl3sa2_state[card].cfg_mpu);
1093 unload_opl3sa2_mss(&opl3sa2_state[card].cfg_mss);
1094 unload_opl3sa2(&opl3sa2_state[card].cfg, card);
1096 pnp_unregister_driver(&opl3sa2_driver);
1101 module_init(init_opl3sa2);
1102 module_exit(cleanup_opl3sa2);
1105 static int __init setup_opl3sa2(char *str)
1107 /* io, irq, dma, dma2,... */
1113 str = get_options(str, ARRAY_SIZE(ints), ints);
1125 multiple = ints[10];
1130 __setup("opl3sa2=", setup_opl3sa2);