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 "sound_config.h"
78 #define OPL3SA2_MODULE_NAME "opl3sa2"
79 #define PFX OPL3SA2_MODULE_NAME ": "
81 /* Useful control port indexes: */
82 #define OPL3SA2_PM 0x01
83 #define OPL3SA2_SYS_CTRL 0x02
84 #define OPL3SA2_IRQ_CONFIG 0x03
85 #define OPL3SA2_DMA_CONFIG 0x06
86 #define OPL3SA2_MASTER_LEFT 0x07
87 #define OPL3SA2_MASTER_RIGHT 0x08
88 #define OPL3SA2_MIC 0x09
89 #define OPL3SA2_MISC 0x0A
91 #define OPL3SA3_WIDE 0x14
92 #define OPL3SA3_BASS 0x15
93 #define OPL3SA3_TREBLE 0x16
95 /* Useful constants: */
96 #define DEFAULT_VOLUME 50
97 #define DEFAULT_MIC 50
98 #define DEFAULT_TIMBRE 0
100 /* Power saving modes */
101 #define OPL3SA2_PM_MODE0 0x00
102 #define OPL3SA2_PM_MODE1 0x04 /* PSV */
103 #define OPL3SA2_PM_MODE2 0x05 /* PSV | PDX */
104 #define OPL3SA2_PM_MODE3 0x27 /* ADOWN | PSV | PDN | PDX */
107 /* For checking against what the card returns: */
108 #define VERSION_UNKNOWN 0
109 #define VERSION_YMF711 1
110 #define VERSION_YMF715 2
111 #define VERSION_YMF715B 3
112 #define VERSION_YMF715E 4
113 /* also assuming that anything > 4 but <= 7 is a 715E */
115 /* Chipset type constants for use below */
116 #define CHIPSET_UNKNOWN -1
117 #define CHIPSET_OPL3SA2 0
118 #define CHIPSET_OPL3SA3 1
119 static const char *CHIPSET_TABLE[] = {"OPL3-SA2", "OPL3-SA3"};
122 #define OPL3SA2_CARDS_MAX 4
124 #define OPL3SA2_CARDS_MAX 1
127 /* This should be pretty obvious */
128 static int opl3sa2_cards_num;
131 /* device resources */
132 unsigned short cfg_port;
133 struct address_info cfg;
134 struct address_info cfg_mss;
135 struct address_info cfg_mpu;
138 struct pnp_dev* pdev;
139 int activated; /* Whether said devices have been activated */
142 unsigned int in_suspend;
143 struct pm_dev *pmdev;
146 int chipset; /* What's my version(s)? */
151 unsigned int volume_l;
152 unsigned int volume_r;
156 unsigned int treble_l;
157 unsigned int treble_r;
161 static opl3sa2_state_t opl3sa2_state[OPL3SA2_CARDS_MAX];
166 static int __initdata io = -1;
167 static int __initdata mss_io = -1;
168 static int __initdata mpu_io = -1;
169 static int __initdata irq = -1;
170 static int __initdata dma = -1;
171 static int __initdata dma2 = -1;
172 static int __initdata ymode = -1;
173 static int __initdata loopback = -1;
176 /* PnP specific parameters */
177 static int __initdata isapnp = 1;
178 static int __initdata multiple = 1;
180 /* Whether said devices have been activated */
181 static int opl3sa2_activated[OPL3SA2_CARDS_MAX];
183 static int __initdata isapnp; /* = 0 */
184 static int __initdata multiple; /* = 0 */
187 MODULE_DESCRIPTION("Module for OPL3-SA2 and SA3 sound cards (uses AD1848 MSS driver).");
188 MODULE_AUTHOR("Scott Murray <scott@spiteful.org>");
189 MODULE_LICENSE("GPL");
192 module_param(io, int, 0);
193 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)");
195 module_param(mss_io, int, 0);
196 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)");
198 module_param(mpu_io, int, 0);
199 MODULE_PARM_DESC(mpu_io, "Set MIDI I/O base (0x330 or other. Address must be even and must be from 0x300 to 0x334)");
201 module_param(irq, int, 0);
202 MODULE_PARM_DESC(irq, "Set MSS (audio) IRQ (5, 7, 9, 10, 11, 12)");
204 module_param(dma, int, 0);
205 MODULE_PARM_DESC(dma, "Set MSS (audio) first DMA channel (0, 1, 3)");
207 module_param(dma2, int, 0);
208 MODULE_PARM_DESC(dma2, "Set MSS (audio) second DMA channel (0, 1, 3)");
210 module_param(ymode, int, 0);
211 MODULE_PARM_DESC(ymode, "Set Yamaha 3D enhancement mode (0 = Desktop/Normal, 1 = Notebook PC (1), 2 = Notebook PC (2), 3 = Hi-Fi)");
213 module_param(loopback, int, 0);
214 MODULE_PARM_DESC(loopback, "Set A/D input source. Useful for echo cancellation (0 = Mic Rch (default), 1 = Mono output loopback)");
217 module_param(isapnp, bool, 0);
218 MODULE_PARM_DESC(isapnp, "When set to 0, ISA PnP support will be disabled");
220 module_param(multiple, bool, 0);
221 MODULE_PARM_DESC(multiple, "When set to 0, will not search for multiple cards");
226 * Standard read and write functions
229 static inline void opl3sa2_write(unsigned short port,
234 outb(data, port + 1);
238 static inline void opl3sa2_read(unsigned short port,
243 *data = inb(port + 1);
248 * All of the mixer functions...
251 static void opl3sa2_set_volume(opl3sa2_state_t* devc, int left, int right)
253 static unsigned char scale[101] = {
254 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e,
255 0x0e, 0x0e, 0x0e, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0c,
256 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0b, 0x0b, 0x0b, 0x0b,
257 0x0b, 0x0b, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x09, 0x09,
258 0x09, 0x09, 0x09, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x08,
259 0x08, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06,
260 0x06, 0x06, 0x06, 0x06, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
261 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03,
262 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01,
263 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
270 /* If level is zero, turn on mute */
274 opl3sa2_write(devc->cfg_port, OPL3SA2_MASTER_LEFT, vol);
278 /* If level is zero, turn on mute */
282 opl3sa2_write(devc->cfg_port, OPL3SA2_MASTER_RIGHT, vol);
286 static void opl3sa2_set_mic(opl3sa2_state_t* devc, int level)
288 unsigned char vol = 0x1F;
290 if((level >= 0) && (level <= 100))
291 vol = 0x1F - (unsigned char) (32 * level / 101);
293 /* If level is zero, turn on mute */
297 opl3sa2_write(devc->cfg_port, OPL3SA2_MIC, vol);
301 static void opl3sa3_set_bass(opl3sa2_state_t* devc, int left, int right)
305 bass = left ? ((unsigned char) (8 * left / 101)) : 0;
306 bass |= (right ? ((unsigned char) (8 * right / 101)) : 0) << 4;
308 opl3sa2_write(devc->cfg_port, OPL3SA3_BASS, bass);
312 static void opl3sa3_set_treble(opl3sa2_state_t* devc, int left, int right)
314 unsigned char treble;
316 treble = left ? ((unsigned char) (8 * left / 101)) : 0;
317 treble |= (right ? ((unsigned char) (8 * right / 101)) : 0) << 4;
319 opl3sa2_write(devc->cfg_port, OPL3SA3_TREBLE, treble);
325 static void opl3sa2_mixer_reset(opl3sa2_state_t* devc)
328 opl3sa2_set_volume(devc, DEFAULT_VOLUME, DEFAULT_VOLUME);
329 devc->volume_l = devc->volume_r = DEFAULT_VOLUME;
331 opl3sa2_set_mic(devc, DEFAULT_MIC);
332 devc->mic = DEFAULT_MIC;
334 if (devc->chipset == CHIPSET_OPL3SA3) {
335 opl3sa3_set_bass(devc, DEFAULT_TIMBRE, DEFAULT_TIMBRE);
336 devc->bass_l = devc->bass_r = DEFAULT_TIMBRE;
337 opl3sa3_set_treble(devc, DEFAULT_TIMBRE, DEFAULT_TIMBRE);
338 devc->treble_l = devc->treble_r = DEFAULT_TIMBRE;
343 /* Currently only used for power management */
345 static void opl3sa2_mixer_restore(opl3sa2_state_t* devc)
348 opl3sa2_set_volume(devc, devc->volume_l, devc->volume_r);
349 opl3sa2_set_mic(devc, devc->mic);
351 if (devc->chipset == CHIPSET_OPL3SA3) {
352 opl3sa3_set_bass(devc, devc->bass_l, devc->bass_r);
353 opl3sa3_set_treble(devc, devc->treble_l, devc->treble_r);
359 static inline void arg_to_vol_mono(unsigned int vol, int* value)
370 static inline void arg_to_vol_stereo(unsigned int vol, int* aleft, int* aright)
372 arg_to_vol_mono(vol, aleft);
373 arg_to_vol_mono(vol >> 8, aright);
377 static inline int ret_vol_mono(int vol)
379 return ((vol << 8) | vol);
383 static inline int ret_vol_stereo(int left, int right)
385 return ((right << 8) | left);
389 static int opl3sa2_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
391 int retval, value, cmdf = cmd & 0xff;
392 int __user *p = (int __user *)arg;
394 opl3sa2_state_t* devc = &opl3sa2_state[dev];
397 case SOUND_MIXER_VOLUME:
398 case SOUND_MIXER_MIC:
399 case SOUND_MIXER_DEVMASK:
400 case SOUND_MIXER_STEREODEVS:
401 case SOUND_MIXER_RECMASK:
402 case SOUND_MIXER_RECSRC:
403 case SOUND_MIXER_CAPS:
410 if (((cmd >> 8) & 0xff) != 'M')
414 if (_SIOC_DIR (cmd) & _SIOC_WRITE) {
416 case SOUND_MIXER_VOLUME:
417 retval = get_user(value, (unsigned __user *) arg);
420 arg_to_vol_stereo(value, &devc->volume_l, &devc->volume_r);
421 opl3sa2_set_volume(devc, devc->volume_l, devc->volume_r);
422 value = ret_vol_stereo(devc->volume_l, devc->volume_r);
423 retval = put_user(value, p);
426 case SOUND_MIXER_MIC:
427 retval = get_user(value, (unsigned __user *) arg);
430 arg_to_vol_mono(value, &devc->mic);
431 opl3sa2_set_mic(devc, devc->mic);
432 value = ret_vol_mono(devc->mic);
433 retval = put_user(value, p);
445 case SOUND_MIXER_DEVMASK:
446 retval = put_user(SOUND_MASK_VOLUME | SOUND_MASK_MIC, p);
449 case SOUND_MIXER_STEREODEVS:
450 retval = put_user(SOUND_MASK_VOLUME, p);
453 case SOUND_MIXER_RECMASK:
454 /* No recording devices */
455 retval = put_user(0, p);
458 case SOUND_MIXER_CAPS:
459 retval = put_user(SOUND_CAP_EXCL_INPUT, p);
462 case SOUND_MIXER_RECSRC:
463 /* No recording source */
464 retval = put_user(0, p);
467 case SOUND_MIXER_VOLUME:
468 value = ret_vol_stereo(devc->volume_l, devc->volume_r);
469 retval = put_user(value, p);
472 case SOUND_MIXER_MIC:
473 value = ret_vol_mono(devc->mic);
483 /* opl3sa2_mixer_ioctl end */
486 static int opl3sa3_mixer_ioctl(int dev, unsigned int cmd, void __user * arg)
488 int value, retval, cmdf = cmd & 0xff;
490 opl3sa2_state_t* devc = &opl3sa2_state[dev];
493 case SOUND_MIXER_BASS:
494 value = ret_vol_stereo(devc->bass_l, devc->bass_r);
495 retval = put_user(value, (int __user *) arg);
498 case SOUND_MIXER_TREBLE:
499 value = ret_vol_stereo(devc->treble_l, devc->treble_r);
500 retval = put_user(value, (int __user *) arg);
503 case SOUND_MIXER_DIGITAL1:
504 value = ret_vol_stereo(devc->wide_l, devc->wide_r);
505 retval = put_user(value, (int __user *) arg);
513 /* opl3sa3_mixer_ioctl end */
516 static struct mixer_operations opl3sa2_mixer_operations =
518 .owner = THIS_MODULE,
520 .name = "Yamaha OPL3-SA2",
521 .ioctl = opl3sa2_mixer_ioctl
524 static struct mixer_operations opl3sa3_mixer_operations =
526 .owner = THIS_MODULE,
528 .name = "Yamaha OPL3-SA3",
529 .ioctl = opl3sa3_mixer_ioctl
532 /* End of mixer-related stuff */
536 * Component probe, attach, unload functions
539 static inline void __exit unload_opl3sa2_mpu(struct address_info *hw_config)
541 unload_mpu401(hw_config);
545 static void __init attach_opl3sa2_mss(struct address_info* hw_config, struct resource *ports)
549 initial_mixers = num_mixers;
550 attach_ms_sound(hw_config, ports, THIS_MODULE); /* Slot 0 */
551 if (hw_config->slots[0] != -1) {
552 /* Did the MSS driver install? */
553 if(num_mixers == (initial_mixers + 1)) {
554 /* The MSS mixer is installed, reroute mixers appropiately */
555 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_CD);
556 AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_SYNTH);
557 AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_LINE);
560 printk(KERN_ERR PFX "MSS mixer not installed?\n");
566 static inline void __exit unload_opl3sa2_mss(struct address_info* hw_config)
568 unload_ms_sound(hw_config);
572 static int __init probe_opl3sa2(struct address_info* hw_config, int card)
576 unsigned char version;
579 * Try and allocate our I/O port range.
581 if (!request_region(hw_config->io_base, 2, OPL3SA2_MODULE_NAME)) {
582 printk(KERN_ERR PFX "Control I/O port %#x not free\n",
588 * Check if writing to the read-only version bits of the miscellaneous
589 * register succeeds or not (it should not).
591 opl3sa2_read(hw_config->io_base, OPL3SA2_MISC, &misc);
592 opl3sa2_write(hw_config->io_base, OPL3SA2_MISC, misc ^ 0x07);
593 opl3sa2_read(hw_config->io_base, OPL3SA2_MISC, &tmp);
595 printk(KERN_ERR PFX "Control I/O port %#x is not a YMF7xx chipset!\n",
601 * Check if the MIC register is accessible.
603 opl3sa2_read(hw_config->io_base, OPL3SA2_MIC, &tmp);
604 opl3sa2_write(hw_config->io_base, OPL3SA2_MIC, 0x8a);
605 opl3sa2_read(hw_config->io_base, OPL3SA2_MIC, &tmp);
606 if((tmp & 0x9f) != 0x8a) {
608 PFX "Control I/O port %#x is not a YMF7xx chipset!\n",
612 opl3sa2_write(hw_config->io_base, OPL3SA2_MIC, tmp);
615 * Determine chipset type (SA2 or SA3)
617 * This is done by looking at the chipset version in the lower 3 bits
618 * of the miscellaneous register.
620 version = misc & 0x07;
621 printk(KERN_DEBUG PFX "Chipset version = %#x\n", version);
624 opl3sa2_state[card].chipset = CHIPSET_UNKNOWN;
626 PFX "Unknown Yamaha audio controller version\n");
630 opl3sa2_state[card].chipset = CHIPSET_OPL3SA2;
631 printk(KERN_INFO PFX "Found OPL3-SA2 (YMF711)\n");
635 opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
637 PFX "Found OPL3-SA3 (YMF715 or YMF719)\n");
640 case VERSION_YMF715B:
641 opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
643 PFX "Found OPL3-SA3 (YMF715B or YMF719B)\n");
646 case VERSION_YMF715E:
648 opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
650 PFX "Found OPL3-SA3 (YMF715E or YMF719E)\n");
654 if (opl3sa2_state[card].chipset != CHIPSET_UNKNOWN) {
655 /* Generate a pretty name */
656 opl3sa2_state[card].chipset_name = (char *)CHIPSET_TABLE[opl3sa2_state[card].chipset];
661 release_region(hw_config->io_base, 2);
667 static void __init attach_opl3sa2(struct address_info* hw_config, int card)
669 /* Initialize IRQ configuration to IRQ-B: -, IRQ-A: WSS+MPU+OPL3 */
670 opl3sa2_write(hw_config->io_base, OPL3SA2_IRQ_CONFIG, 0x0d);
672 /* Initialize DMA configuration */
673 if(hw_config->dma2 == hw_config->dma) {
674 /* Want DMA configuration DMA-B: -, DMA-A: WSS-P+WSS-R */
675 opl3sa2_write(hw_config->io_base, OPL3SA2_DMA_CONFIG, 0x03);
678 /* Want DMA configuration DMA-B: WSS-R, DMA-A: WSS-P */
679 opl3sa2_write(hw_config->io_base, OPL3SA2_DMA_CONFIG, 0x21);
684 static void __init attach_opl3sa2_mixer(struct address_info *hw_config, int card)
686 struct mixer_operations* mixer_operations;
687 opl3sa2_state_t* devc = &opl3sa2_state[card];
689 /* Install master mixer */
690 if (devc->chipset == CHIPSET_OPL3SA3) {
691 mixer_operations = &opl3sa3_mixer_operations;
694 mixer_operations = &opl3sa2_mixer_operations;
697 devc->cfg_port = hw_config->io_base;
698 devc->mixer = sound_install_mixer(MIXER_DRIVER_VERSION,
699 mixer_operations->name,
701 sizeof(struct mixer_operations),
703 if(devc->mixer < 0) {
704 printk(KERN_ERR PFX "Could not install %s master mixer\n",
705 mixer_operations->name);
708 opl3sa2_mixer_reset(devc);
714 static void opl3sa2_clear_slots(struct address_info* hw_config)
718 for(i = 0; i < 6; i++) {
719 hw_config->slots[i] = -1;
724 static void __init opl3sa2_set_ymode(struct address_info* hw_config, int ymode)
727 * Set the Yamaha 3D enhancement mode (aka Ymersion) if asked to and
730 * 0: Desktop (aka normal) 5-12 cm speakers
731 * 1: Notebook PC mode 1 3 cm speakers
732 * 2: Notebook PC mode 2 1.5 cm speakers
733 * 3: Hi-fi 16-38 cm speakers
735 if(ymode >= 0 && ymode <= 3) {
736 unsigned char sys_ctrl;
738 opl3sa2_read(hw_config->io_base, OPL3SA2_SYS_CTRL, &sys_ctrl);
739 sys_ctrl = (sys_ctrl & 0xcf) | ((ymode & 3) << 4);
740 opl3sa2_write(hw_config->io_base, OPL3SA2_SYS_CTRL, sys_ctrl);
743 printk(KERN_ERR PFX "not setting ymode, it must be one of 0,1,2,3\n");
748 static void __init opl3sa2_set_loopback(struct address_info* hw_config, int loopback)
750 if(loopback >= 0 && loopback <= 1) {
753 opl3sa2_read(hw_config->io_base, OPL3SA2_MISC, &misc);
754 misc = (misc & 0xef) | ((loopback & 1) << 4);
755 opl3sa2_write(hw_config->io_base, OPL3SA2_MISC, misc);
758 printk(KERN_ERR PFX "not setting loopback, it must be either 0 or 1\n");
763 static void __exit unload_opl3sa2(struct address_info* hw_config, int card)
765 /* Release control ports */
766 release_region(hw_config->io_base, 2);
769 if(opl3sa2_state[card].mixer >= 0)
770 sound_unload_mixerdev(opl3sa2_state[card].mixer);
775 static struct pnp_device_id pnp_opl3sa2_list[] = {
776 {.id = "YMH0021", .driver_data = 0},
780 MODULE_DEVICE_TABLE(pnp, pnp_opl3sa2_list);
782 static int opl3sa2_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
784 int card = opl3sa2_cards_num;
786 /* we don't actually want to return an error as the user may have specified
787 * no multiple card search
790 if (opl3sa2_cards_num == OPL3SA2_CARDS_MAX)
792 opl3sa2_activated[card] = 1;
794 /* Our own config: */
795 opl3sa2_state[card].cfg.io_base = pnp_port_start(dev, 4);
796 opl3sa2_state[card].cfg.irq = pnp_irq(dev, 0);
797 opl3sa2_state[card].cfg.dma = pnp_dma(dev, 0);
798 opl3sa2_state[card].cfg.dma2 = pnp_dma(dev, 1);
800 /* The MSS config: */
801 opl3sa2_state[card].cfg_mss.io_base = pnp_port_start(dev, 1);
802 opl3sa2_state[card].cfg_mss.irq = pnp_irq(dev, 0);
803 opl3sa2_state[card].cfg_mss.dma = pnp_dma(dev, 0);
804 opl3sa2_state[card].cfg_mss.dma2 = pnp_dma(dev, 1);
805 opl3sa2_state[card].cfg_mss.card_subtype = 1; /* No IRQ or DMA setup */
807 opl3sa2_state[card].cfg_mpu.io_base = pnp_port_start(dev, 3);
808 opl3sa2_state[card].cfg_mpu.irq = pnp_irq(dev, 0);
809 opl3sa2_state[card].cfg_mpu.dma = -1;
810 opl3sa2_state[card].cfg_mpu.dma2 = -1;
811 opl3sa2_state[card].cfg_mpu.always_detect = 1; /* It's there, so use shared IRQs */
813 /* Call me paranoid: */
814 opl3sa2_clear_slots(&opl3sa2_state[card].cfg);
815 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mss);
816 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mpu);
818 opl3sa2_state[card].pdev = dev;
824 static struct pnp_driver opl3sa2_driver = {
826 .id_table = pnp_opl3sa2_list,
827 .probe = opl3sa2_pnp_probe,
830 #endif /* CONFIG_PNP */
832 /* End of component functions */
835 static DEFINE_SPINLOCK(opl3sa2_lock);
837 /* Power Management support functions */
838 static int opl3sa2_suspend(struct pm_dev *pdev, unsigned int pm_mode)
846 spin_lock_irqsave(&opl3sa2_lock,flags);
848 p = (opl3sa2_state_t *) pdev->data;
851 pm_mode = OPL3SA2_PM_MODE1;
854 pm_mode = OPL3SA2_PM_MODE2;
857 pm_mode = OPL3SA2_PM_MODE3;
860 /* we don't know howto handle this... */
861 spin_unlock_irqrestore(&opl3sa2_lock, flags);
867 /* its supposed to automute before suspending, so we won't bother */
868 opl3sa2_write(p->cfg_port, OPL3SA2_PM, pm_mode);
869 /* wait a while for the clock oscillator to stabilise */
872 spin_unlock_irqrestore(&opl3sa2_lock,flags);
876 static int opl3sa2_resume(struct pm_dev *pdev)
884 p = (opl3sa2_state_t *) pdev->data;
885 spin_lock_irqsave(&opl3sa2_lock,flags);
887 /* I don't think this is necessary */
888 opl3sa2_write(p->cfg_port, OPL3SA2_PM, OPL3SA2_PM_MODE0);
889 opl3sa2_mixer_restore(p);
892 spin_unlock_irqrestore(&opl3sa2_lock,flags);
896 static int opl3sa2_pm_callback(struct pm_dev *pdev, pm_request_t rqst, void *data)
898 unsigned long mode = (unsigned long)data;
902 return opl3sa2_suspend(pdev, mode);
905 return opl3sa2_resume(pdev);
909 #endif /* CONFIG_PM */
912 * Install OPL3-SA2 based card(s).
914 * Need to have ad1848 and mpu401 loaded ready.
916 static int __init init_opl3sa2(void)
920 /* Sanitize isapnp and multiple settings */
921 isapnp = isapnp != 0 ? 1 : 0;
922 multiple = multiple != 0 ? 1 : 0;
924 max = (multiple && isapnp) ? OPL3SA2_CARDS_MAX : 1;
928 pnp_register_driver(&opl3sa2_driver);
929 if(!opl3sa2_cards_num){
930 printk(KERN_INFO PFX "No PnP cards found\n");
933 max = opl3sa2_cards_num;
937 for (card = 0; card < max; card++) {
938 /* If a user wants an I/O then assume they meant it */
939 struct resource *ports;
943 if (io == -1 || irq == -1 || dma == -1 ||
944 dma2 == -1 || mss_io == -1) {
946 PFX "io, mss_io, irq, dma, and dma2 must be set\n");
953 * (NOTE: IRQ and DMA aren't used, so they're set to
954 * give pretty output from conf_printf. :)
956 opl3sa2_state[card].cfg.io_base = io;
957 opl3sa2_state[card].cfg.irq = irq;
958 opl3sa2_state[card].cfg.dma = dma;
959 opl3sa2_state[card].cfg.dma2 = dma2;
961 /* The MSS config: */
962 opl3sa2_state[card].cfg_mss.io_base = mss_io;
963 opl3sa2_state[card].cfg_mss.irq = irq;
964 opl3sa2_state[card].cfg_mss.dma = dma;
965 opl3sa2_state[card].cfg_mss.dma2 = dma2;
966 opl3sa2_state[card].cfg_mss.card_subtype = 1; /* No IRQ or DMA setup */
968 opl3sa2_state[card].cfg_mpu.io_base = mpu_io;
969 opl3sa2_state[card].cfg_mpu.irq = irq;
970 opl3sa2_state[card].cfg_mpu.dma = -1;
971 opl3sa2_state[card].cfg_mpu.always_detect = 1; /* Use shared IRQs */
973 /* Call me paranoid: */
974 opl3sa2_clear_slots(&opl3sa2_state[card].cfg);
975 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mss);
976 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mpu);
980 if (probe_opl3sa2(&opl3sa2_state[card].cfg, card))
983 base = opl3sa2_state[card].cfg_mss.io_base;
985 if (!request_region(base, 4, "WSS config"))
988 ports = request_region(base + 4, 4, "ad1848");
992 if (!probe_ms_sound(&opl3sa2_state[card].cfg_mss, ports)) {
994 * If one or more cards are already registered, don't
995 * return an error but print a warning. Note, this
996 * should never really happen unless the hardware or
997 * ISA PnP screwed up.
999 release_region(base + 4, 4);
1001 release_region(base, 4);
1003 release_region(opl3sa2_state[card].cfg.io_base, 2);
1005 if (opl3sa2_cards_num) {
1007 PFX "There was a problem probing one "
1008 " of the ISA PNP cards, continuing\n");
1009 opl3sa2_cards_num--;
1015 attach_opl3sa2(&opl3sa2_state[card].cfg, card);
1016 conf_printf(opl3sa2_state[card].chipset_name, &opl3sa2_state[card].cfg);
1017 attach_opl3sa2_mixer(&opl3sa2_state[card].cfg, card);
1018 attach_opl3sa2_mss(&opl3sa2_state[card].cfg_mss, ports);
1021 opl3sa2_state[card].card = card;
1023 /* register our power management capabilities */
1024 opl3sa2_state[card].pmdev = pm_register(PM_ISA_DEV, card, opl3sa2_pm_callback);
1025 if (opl3sa2_state[card].pmdev)
1026 opl3sa2_state[card].pmdev->data = &opl3sa2_state[card];
1027 #endif /* CONFIG_PM */
1030 * Set the Yamaha 3D enhancement mode (aka Ymersion) if asked to and
1034 if (opl3sa2_state[card].chipset == CHIPSET_OPL3SA2) {
1036 PFX "ymode not supported on OPL3-SA2\n");
1039 opl3sa2_set_ymode(&opl3sa2_state[card].cfg, ymode);
1044 /* Set A/D input to Mono loopback if asked to. */
1045 if (loopback != -1) {
1046 opl3sa2_set_loopback(&opl3sa2_state[card].cfg, loopback);
1049 /* Attach MPU if we've been asked to do so, failure isn't fatal */
1050 if (opl3sa2_state[card].cfg_mpu.io_base != -1) {
1051 int base = opl3sa2_state[card].cfg_mpu.io_base;
1052 struct resource *ports;
1053 ports = request_region(base, 2, "mpu401");
1056 if (!probe_mpu401(&opl3sa2_state[card].cfg_mpu, ports)) {
1057 release_region(base, 2);
1060 if (attach_mpu401(&opl3sa2_state[card].cfg_mpu, THIS_MODULE)) {
1061 printk(KERN_ERR PFX "failed to attach MPU401\n");
1062 opl3sa2_state[card].cfg_mpu.slots[1] = -1;
1069 printk(KERN_NOTICE PFX "%d PnP card(s) found.\n", opl3sa2_cards_num);
1077 * Uninstall OPL3-SA2 based card(s).
1079 static void __exit cleanup_opl3sa2(void)
1083 for(card = 0; card < opl3sa2_cards_num; card++) {
1085 if (opl3sa2_state[card].pmdev)
1086 pm_unregister(opl3sa2_state[card].pmdev);
1088 if (opl3sa2_state[card].cfg_mpu.slots[1] != -1) {
1089 unload_opl3sa2_mpu(&opl3sa2_state[card].cfg_mpu);
1091 unload_opl3sa2_mss(&opl3sa2_state[card].cfg_mss);
1092 unload_opl3sa2(&opl3sa2_state[card].cfg, card);
1094 pnp_unregister_driver(&opl3sa2_driver);
1099 module_init(init_opl3sa2);
1100 module_exit(cleanup_opl3sa2);
1103 static int __init setup_opl3sa2(char *str)
1105 /* io, irq, dma, dma2,... */
1111 str = get_options(str, ARRAY_SIZE(ints), ints);
1123 multiple = ints[10];
1128 __setup("opl3sa2=", setup_opl3sa2);