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;
181 struct pnp_dev* opl3sa2_dev[OPL3SA2_CARDS_MAX];
183 /* Whether said devices have been activated */
184 static int opl3sa2_activated[OPL3SA2_CARDS_MAX];
186 static int __initdata isapnp; /* = 0 */
187 static int __initdata multiple; /* = 0 */
190 MODULE_DESCRIPTION("Module for OPL3-SA2 and SA3 sound cards (uses AD1848 MSS driver).");
191 MODULE_AUTHOR("Scott Murray <scott@spiteful.org>");
192 MODULE_LICENSE("GPL");
195 MODULE_PARM(io, "i");
196 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)");
198 MODULE_PARM(mss_io, "i");
199 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)");
201 MODULE_PARM(mpu_io, "i");
202 MODULE_PARM_DESC(mpu_io, "Set MIDI I/O base (0x330 or other. Address must be even and must be from 0x300 to 0x334)");
204 MODULE_PARM(irq, "i");
205 MODULE_PARM_DESC(mss_irq, "Set MSS (audio) IRQ (5, 7, 9, 10, 11, 12)");
207 MODULE_PARM(dma, "i");
208 MODULE_PARM_DESC(dma, "Set MSS (audio) first DMA channel (0, 1, 3)");
210 MODULE_PARM(dma2, "i");
211 MODULE_PARM_DESC(dma2, "Set MSS (audio) second DMA channel (0, 1, 3)");
213 MODULE_PARM(ymode, "i");
214 MODULE_PARM_DESC(ymode, "Set Yamaha 3D enhancement mode (0 = Desktop/Normal, 1 = Notebook PC (1), 2 = Notebook PC (2), 3 = Hi-Fi)");
216 MODULE_PARM(loopback, "i");
217 MODULE_PARM_DESC(loopback, "Set A/D input source. Useful for echo cancellation (0 = Mic Rch (default), 1 = Mono output loopback)");
220 MODULE_PARM(isapnp, "i");
221 MODULE_PARM_DESC(isapnp, "When set to 0, ISA PnP support will be disabled");
223 MODULE_PARM(multiple, "i");
224 MODULE_PARM_DESC(multiple, "When set to 0, will not search for multiple cards");
229 * Standard read and write functions
232 static inline void opl3sa2_write(unsigned short port,
237 outb(data, port + 1);
241 static inline void opl3sa2_read(unsigned short port,
246 *data = inb(port + 1);
251 * All of the mixer functions...
254 static void opl3sa2_set_volume(opl3sa2_state_t* devc, int left, int right)
256 static unsigned char scale[101] = {
257 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e,
258 0x0e, 0x0e, 0x0e, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0c,
259 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0b, 0x0b, 0x0b, 0x0b,
260 0x0b, 0x0b, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x09, 0x09,
261 0x09, 0x09, 0x09, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x08,
262 0x08, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06,
263 0x06, 0x06, 0x06, 0x06, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
264 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03,
265 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01,
266 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
273 /* If level is zero, turn on mute */
277 opl3sa2_write(devc->cfg_port, OPL3SA2_MASTER_LEFT, vol);
281 /* If level is zero, turn on mute */
285 opl3sa2_write(devc->cfg_port, OPL3SA2_MASTER_RIGHT, vol);
289 static void opl3sa2_set_mic(opl3sa2_state_t* devc, int level)
291 unsigned char vol = 0x1F;
293 if((level >= 0) && (level <= 100))
294 vol = 0x1F - (unsigned char) (32 * level / 101);
296 /* If level is zero, turn on mute */
300 opl3sa2_write(devc->cfg_port, OPL3SA2_MIC, vol);
304 static void opl3sa3_set_bass(opl3sa2_state_t* devc, int left, int right)
308 bass = left ? ((unsigned char) (8 * left / 101)) : 0;
309 bass |= (right ? ((unsigned char) (8 * right / 101)) : 0) << 4;
311 opl3sa2_write(devc->cfg_port, OPL3SA3_BASS, bass);
315 static void opl3sa3_set_treble(opl3sa2_state_t* devc, int left, int right)
317 unsigned char treble;
319 treble = left ? ((unsigned char) (8 * left / 101)) : 0;
320 treble |= (right ? ((unsigned char) (8 * right / 101)) : 0) << 4;
322 opl3sa2_write(devc->cfg_port, OPL3SA3_TREBLE, treble);
328 static void opl3sa2_mixer_reset(opl3sa2_state_t* devc)
331 opl3sa2_set_volume(devc, DEFAULT_VOLUME, DEFAULT_VOLUME);
332 devc->volume_l = devc->volume_r = DEFAULT_VOLUME;
334 opl3sa2_set_mic(devc, DEFAULT_MIC);
335 devc->mic = DEFAULT_MIC;
337 if (devc->chipset == CHIPSET_OPL3SA3) {
338 opl3sa3_set_bass(devc, DEFAULT_TIMBRE, DEFAULT_TIMBRE);
339 devc->bass_l = devc->bass_r = DEFAULT_TIMBRE;
340 opl3sa3_set_treble(devc, DEFAULT_TIMBRE, DEFAULT_TIMBRE);
341 devc->treble_l = devc->treble_r = DEFAULT_TIMBRE;
346 /* Currently only used for power management */
348 static void opl3sa2_mixer_restore(opl3sa2_state_t* devc)
351 opl3sa2_set_volume(devc, devc->volume_l, devc->volume_r);
352 opl3sa2_set_mic(devc, devc->mic);
354 if (devc->chipset == CHIPSET_OPL3SA3) {
355 opl3sa3_set_bass(devc, devc->bass_l, devc->bass_r);
356 opl3sa3_set_treble(devc, devc->treble_l, devc->treble_r);
362 static inline void arg_to_vol_mono(unsigned int vol, int* value)
373 static inline void arg_to_vol_stereo(unsigned int vol, int* aleft, int* aright)
375 arg_to_vol_mono(vol, aleft);
376 arg_to_vol_mono(vol >> 8, aright);
380 static inline int ret_vol_mono(int vol)
382 return ((vol << 8) | vol);
386 static inline int ret_vol_stereo(int left, int right)
388 return ((right << 8) | left);
392 static int opl3sa2_mixer_ioctl(int dev, unsigned int cmd, caddr_t arg)
394 int retval, value, cmdf = cmd & 0xff;
396 opl3sa2_state_t* devc = &opl3sa2_state[dev];
399 case SOUND_MIXER_VOLUME:
400 case SOUND_MIXER_MIC:
401 case SOUND_MIXER_DEVMASK:
402 case SOUND_MIXER_STEREODEVS:
403 case SOUND_MIXER_RECMASK:
404 case SOUND_MIXER_RECSRC:
405 case SOUND_MIXER_CAPS:
412 if (((cmd >> 8) & 0xff) != 'M')
416 if (_SIOC_DIR (cmd) & _SIOC_WRITE) {
418 case SOUND_MIXER_VOLUME:
419 retval = get_user(value, (unsigned int *) arg);
422 arg_to_vol_stereo(value, &devc->volume_l, &devc->volume_r);
423 opl3sa2_set_volume(devc, devc->volume_l, devc->volume_r);
424 value = ret_vol_stereo(devc->volume_l, devc->volume_r);
425 retval = put_user(value, (int *) arg);
428 case SOUND_MIXER_MIC:
429 retval = get_user(value, (unsigned int *) arg);
432 arg_to_vol_mono(value, &devc->mic);
433 opl3sa2_set_mic(devc, devc->mic);
434 value = ret_vol_mono(devc->mic);
435 retval = put_user(value, (int *) arg);
447 case SOUND_MIXER_DEVMASK:
448 retval = put_user(SOUND_MASK_VOLUME | SOUND_MASK_MIC, (int *) arg);
451 case SOUND_MIXER_STEREODEVS:
452 retval = put_user(SOUND_MASK_VOLUME, (int *) arg);
455 case SOUND_MIXER_RECMASK:
456 /* No recording devices */
457 retval = put_user(0, (int *) arg);
460 case SOUND_MIXER_CAPS:
461 retval = put_user(SOUND_CAP_EXCL_INPUT, (int *) arg);
464 case SOUND_MIXER_RECSRC:
465 /* No recording source */
466 retval = put_user(0, (int *) arg);
469 case SOUND_MIXER_VOLUME:
470 value = ret_vol_stereo(devc->volume_l, devc->volume_r);
471 retval = put_user(value, (int *) arg);
474 case SOUND_MIXER_MIC:
475 value = ret_vol_mono(devc->mic);
476 put_user(value, (int *) arg);
485 /* opl3sa2_mixer_ioctl end */
488 static int opl3sa3_mixer_ioctl(int dev, unsigned int cmd, caddr_t arg)
490 int value, retval, cmdf = cmd & 0xff;
492 opl3sa2_state_t* devc = &opl3sa2_state[dev];
495 case SOUND_MIXER_BASS:
496 value = ret_vol_stereo(devc->bass_l, devc->bass_r);
497 retval = put_user(value, (int *) arg);
500 case SOUND_MIXER_TREBLE:
501 value = ret_vol_stereo(devc->treble_l, devc->treble_r);
502 retval = put_user(value, (int *) arg);
505 case SOUND_MIXER_DIGITAL1:
506 value = ret_vol_stereo(devc->wide_l, devc->wide_r);
507 retval = put_user(value, (int *) arg);
515 /* opl3sa3_mixer_ioctl end */
518 static struct mixer_operations opl3sa2_mixer_operations =
520 .owner = THIS_MODULE,
522 .name = "Yamaha OPL3-SA2",
523 .ioctl = opl3sa2_mixer_ioctl
526 static struct mixer_operations opl3sa3_mixer_operations =
528 .owner = THIS_MODULE,
530 .name = "Yamaha OPL3-SA3",
531 .ioctl = opl3sa3_mixer_ioctl
534 /* End of mixer-related stuff */
538 * Component probe, attach, unload functions
541 static inline int __init probe_opl3sa2_mpu(struct address_info* hw_config)
543 return probe_mpu401(hw_config);
547 static inline int __init attach_opl3sa2_mpu(struct address_info* hw_config)
549 return attach_mpu401(hw_config, THIS_MODULE);
553 static inline void __exit unload_opl3sa2_mpu(struct address_info *hw_config)
555 unload_mpu401(hw_config);
559 static inline int __init probe_opl3sa2_mss(struct address_info* hw_config)
561 return probe_ms_sound(hw_config);
565 static void __init attach_opl3sa2_mss(struct address_info* hw_config)
569 initial_mixers = num_mixers;
570 attach_ms_sound(hw_config, THIS_MODULE); /* Slot 0 */
571 if (hw_config->slots[0] != -1) {
572 /* Did the MSS driver install? */
573 if(num_mixers == (initial_mixers + 1)) {
574 /* The MSS mixer is installed, reroute mixers appropiately */
575 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_CD);
576 AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_SYNTH);
577 AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_LINE);
580 printk(KERN_ERR PFX "MSS mixer not installed?\n");
586 static inline void __exit unload_opl3sa2_mss(struct address_info* hw_config)
588 unload_ms_sound(hw_config);
592 static int __init probe_opl3sa2(struct address_info* hw_config, int card)
596 unsigned char version;
599 * Try and allocate our I/O port range.
601 if (!request_region(hw_config->io_base, 2, OPL3SA2_MODULE_NAME)) {
602 printk(KERN_ERR PFX "Control I/O port %#x not free\n",
608 * Check if writing to the read-only version bits of the miscellaneous
609 * register succeeds or not (it should not).
611 opl3sa2_read(hw_config->io_base, OPL3SA2_MISC, &misc);
612 opl3sa2_write(hw_config->io_base, OPL3SA2_MISC, misc ^ 0x07);
613 opl3sa2_read(hw_config->io_base, OPL3SA2_MISC, &tmp);
615 printk(KERN_ERR PFX "Control I/O port %#x is not a YMF7xx chipset!\n",
621 * Check if the MIC register is accessible.
623 opl3sa2_read(hw_config->io_base, OPL3SA2_MIC, &tmp);
624 opl3sa2_write(hw_config->io_base, OPL3SA2_MIC, 0x8a);
625 opl3sa2_read(hw_config->io_base, OPL3SA2_MIC, &tmp);
626 if((tmp & 0x9f) != 0x8a) {
628 PFX "Control I/O port %#x is not a YMF7xx chipset!\n",
632 opl3sa2_write(hw_config->io_base, OPL3SA2_MIC, tmp);
635 * Determine chipset type (SA2 or SA3)
637 * This is done by looking at the chipset version in the lower 3 bits
638 * of the miscellaneous register.
640 version = misc & 0x07;
641 printk(KERN_DEBUG PFX "Chipset version = %#x\n", version);
644 opl3sa2_state[card].chipset = CHIPSET_UNKNOWN;
646 PFX "Unknown Yamaha audio controller version\n");
650 opl3sa2_state[card].chipset = CHIPSET_OPL3SA2;
651 printk(KERN_INFO PFX "Found OPL3-SA2 (YMF711)\n");
655 opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
657 PFX "Found OPL3-SA3 (YMF715 or YMF719)\n");
660 case VERSION_YMF715B:
661 opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
663 PFX "Found OPL3-SA3 (YMF715B or YMF719B)\n");
666 case VERSION_YMF715E:
668 opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
670 PFX "Found OPL3-SA3 (YMF715E or YMF719E)\n");
674 if (opl3sa2_state[card].chipset != CHIPSET_UNKNOWN) {
675 /* Generate a pretty name */
676 opl3sa2_state[card].chipset_name = (char *)CHIPSET_TABLE[opl3sa2_state[card].chipset];
681 release_region(hw_config->io_base, 2);
687 static void __init attach_opl3sa2(struct address_info* hw_config, int card)
689 /* Initialize IRQ configuration to IRQ-B: -, IRQ-A: WSS+MPU+OPL3 */
690 opl3sa2_write(hw_config->io_base, OPL3SA2_IRQ_CONFIG, 0x0d);
692 /* Initialize DMA configuration */
693 if(hw_config->dma2 == hw_config->dma) {
694 /* Want DMA configuration DMA-B: -, DMA-A: WSS-P+WSS-R */
695 opl3sa2_write(hw_config->io_base, OPL3SA2_DMA_CONFIG, 0x03);
698 /* Want DMA configuration DMA-B: WSS-R, DMA-A: WSS-P */
699 opl3sa2_write(hw_config->io_base, OPL3SA2_DMA_CONFIG, 0x21);
704 static void __init attach_opl3sa2_mixer(struct address_info *hw_config, int card)
706 struct mixer_operations* mixer_operations;
707 opl3sa2_state_t* devc = &opl3sa2_state[card];
709 /* Install master mixer */
710 if (devc->chipset == CHIPSET_OPL3SA3) {
711 mixer_operations = &opl3sa3_mixer_operations;
714 mixer_operations = &opl3sa2_mixer_operations;
717 devc->cfg_port = hw_config->io_base;
718 devc->mixer = sound_install_mixer(MIXER_DRIVER_VERSION,
719 mixer_operations->name,
721 sizeof(struct mixer_operations),
723 if(devc->mixer < 0) {
724 printk(KERN_ERR PFX "Could not install %s master mixer\n",
725 mixer_operations->name);
728 opl3sa2_mixer_reset(devc);
734 static void __init opl3sa2_clear_slots(struct address_info* hw_config)
738 for(i = 0; i < 6; i++) {
739 hw_config->slots[i] = -1;
744 static void __init opl3sa2_set_ymode(struct address_info* hw_config, int ymode)
747 * Set the Yamaha 3D enhancement mode (aka Ymersion) if asked to and
750 * 0: Desktop (aka normal) 5-12 cm speakers
751 * 1: Notebook PC mode 1 3 cm speakers
752 * 2: Notebook PC mode 2 1.5 cm speakers
753 * 3: Hi-fi 16-38 cm speakers
755 if(ymode >= 0 && ymode <= 3) {
756 unsigned char sys_ctrl;
758 opl3sa2_read(hw_config->io_base, OPL3SA2_SYS_CTRL, &sys_ctrl);
759 sys_ctrl = (sys_ctrl & 0xcf) | ((ymode & 3) << 4);
760 opl3sa2_write(hw_config->io_base, OPL3SA2_SYS_CTRL, sys_ctrl);
763 printk(KERN_ERR PFX "not setting ymode, it must be one of 0,1,2,3\n");
768 static void __init opl3sa2_set_loopback(struct address_info* hw_config, int loopback)
770 if(loopback >= 0 && loopback <= 1) {
773 opl3sa2_read(hw_config->io_base, OPL3SA2_MISC, &misc);
774 misc = (misc & 0xef) | ((loopback & 1) << 4);
775 opl3sa2_write(hw_config->io_base, OPL3SA2_MISC, misc);
778 printk(KERN_ERR PFX "not setting loopback, it must be either 0 or 1\n");
783 static void __exit unload_opl3sa2(struct address_info* hw_config, int card)
785 /* Release control ports */
786 release_region(hw_config->io_base, 2);
789 if(opl3sa2_state[card].mixer >= 0)
790 sound_unload_mixerdev(opl3sa2_state[card].mixer);
795 struct pnp_device_id pnp_opl3sa2_list[] = {
796 {.id = "YMH0021", .driver_data = 0},
800 MODULE_DEVICE_TABLE(pnp, pnp_opl3sa2_list);
802 static int opl3sa2_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
804 int card = opl3sa2_cards_num;
806 /* we don't actually want to return an error as the user may have specified
807 * no multiple card search
810 if (opl3sa2_cards_num == OPL3SA2_CARDS_MAX)
812 opl3sa2_activated[card] = 1;
814 /* Our own config: */
815 opl3sa2_state[card].cfg.io_base = pnp_port_start(dev, 4);
816 opl3sa2_state[card].cfg.irq = pnp_irq(dev, 0);
817 opl3sa2_state[card].cfg.dma = pnp_dma(dev, 0);
818 opl3sa2_state[card].cfg.dma2 = pnp_dma(dev, 1);
820 /* The MSS config: */
821 opl3sa2_state[card].cfg_mss.io_base = pnp_port_start(dev, 1);
822 opl3sa2_state[card].cfg_mss.irq = pnp_irq(dev, 0);
823 opl3sa2_state[card].cfg_mss.dma = pnp_dma(dev, 0);
824 opl3sa2_state[card].cfg_mss.dma2 = pnp_dma(dev, 1);
825 opl3sa2_state[card].cfg_mss.card_subtype = 1; /* No IRQ or DMA setup */
827 opl3sa2_state[card].cfg_mpu.io_base = pnp_port_start(dev, 3);
828 opl3sa2_state[card].cfg_mpu.irq = pnp_irq(dev, 0);
829 opl3sa2_state[card].cfg_mpu.dma = -1;
830 opl3sa2_state[card].cfg_mpu.dma2 = -1;
831 opl3sa2_state[card].cfg_mpu.always_detect = 1; /* It's there, so use shared IRQs */
833 /* Call me paranoid: */
834 opl3sa2_clear_slots(&opl3sa2_state[card].cfg);
835 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mss);
836 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mpu);
838 opl3sa2_state[card].pdev = dev;
844 static struct pnp_driver opl3sa2_driver = {
846 .id_table = pnp_opl3sa2_list,
847 .probe = opl3sa2_pnp_probe,
850 #endif /* CONFIG_PNP */
852 /* End of component functions */
855 static spinlock_t opl3sa2_lock = SPIN_LOCK_UNLOCKED;
857 /* Power Management support functions */
858 static int opl3sa2_suspend(struct pm_dev *pdev, unsigned int pm_mode)
866 spin_lock_irqsave(&opl3sa2_lock,flags);
868 p = (opl3sa2_state_t *) pdev->data;
871 pm_mode = OPL3SA2_PM_MODE1;
874 pm_mode = OPL3SA2_PM_MODE2;
877 pm_mode = OPL3SA2_PM_MODE3;
880 /* we don't know howto handle this... */
881 spin_unlock_irqrestore(&opl3sa2_lock, flags);
887 /* its supposed to automute before suspending, so we won't bother */
888 opl3sa2_write(p->cfg_port, OPL3SA2_PM, pm_mode);
889 /* wait a while for the clock oscillator to stabilise */
892 spin_unlock_irqrestore(&opl3sa2_lock,flags);
896 static int opl3sa2_resume(struct pm_dev *pdev)
904 p = (opl3sa2_state_t *) pdev->data;
905 spin_lock_irqsave(&opl3sa2_lock,flags);
907 /* I don't think this is necessary */
908 opl3sa2_write(p->cfg_port, OPL3SA2_PM, OPL3SA2_PM_MODE0);
909 opl3sa2_mixer_restore(p);
912 spin_unlock_irqrestore(&opl3sa2_lock,flags);
916 static int opl3sa2_pm_callback(struct pm_dev *pdev, pm_request_t rqst, void *data)
918 unsigned long mode = (unsigned long)data;
922 return opl3sa2_suspend(pdev, mode);
925 return opl3sa2_resume(pdev);
929 #endif /* CONFIG_PM */
932 * Install OPL3-SA2 based card(s).
934 * Need to have ad1848 and mpu401 loaded ready.
936 static int __init init_opl3sa2(void)
940 /* Sanitize isapnp and multiple settings */
941 isapnp = isapnp != 0 ? 1 : 0;
942 multiple = multiple != 0 ? 1 : 0;
944 max = (multiple && isapnp) ? OPL3SA2_CARDS_MAX : 1;
948 pnp_register_driver(&opl3sa2_driver);
949 if(!opl3sa2_cards_num){
950 printk(KERN_INFO PFX "No PnP cards found\n");
953 max = opl3sa2_cards_num;
957 for (card = 0; card < max; card++) {
958 /* If a user wants an I/O then assume they meant it */
961 if (io == -1 || irq == -1 || dma == -1 ||
962 dma2 == -1 || mss_io == -1) {
964 PFX "io, mss_io, irq, dma, and dma2 must be set\n");
971 * (NOTE: IRQ and DMA aren't used, so they're set to
972 * give pretty output from conf_printf. :)
974 opl3sa2_state[card].cfg.io_base = io;
975 opl3sa2_state[card].cfg.irq = irq;
976 opl3sa2_state[card].cfg.dma = dma;
977 opl3sa2_state[card].cfg.dma2 = dma2;
979 /* The MSS config: */
980 opl3sa2_state[card].cfg_mss.io_base = mss_io;
981 opl3sa2_state[card].cfg_mss.irq = irq;
982 opl3sa2_state[card].cfg_mss.dma = dma;
983 opl3sa2_state[card].cfg_mss.dma2 = dma2;
984 opl3sa2_state[card].cfg_mss.card_subtype = 1; /* No IRQ or DMA setup */
986 opl3sa2_state[card].cfg_mpu.io_base = mpu_io;
987 opl3sa2_state[card].cfg_mpu.irq = irq;
988 opl3sa2_state[card].cfg_mpu.dma = -1;
989 opl3sa2_state[card].cfg_mpu.always_detect = 1; /* Use shared IRQs */
991 /* Call me paranoid: */
992 opl3sa2_clear_slots(&opl3sa2_state[card].cfg);
993 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mss);
994 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mpu);
997 if (probe_opl3sa2(&opl3sa2_state[card].cfg, card))
1001 if (!probe_opl3sa2_mss(&opl3sa2_state[card].cfg_mss)) {
1003 * If one or more cards are already registered, don't
1004 * return an error but print a warning. Note, this
1005 * should never really happen unless the hardware or
1006 * ISA PnP screwed up.
1008 release_region(opl3sa2_state[card].cfg.io_base, 2);
1010 if (opl3sa2_cards_num) {
1012 PFX "There was a problem probing one "
1013 " of the ISA PNP cards, continuing\n");
1014 opl3sa2_cards_num--;
1020 attach_opl3sa2(&opl3sa2_state[card].cfg, card);
1021 conf_printf(opl3sa2_state[card].chipset_name, &opl3sa2_state[card].cfg);
1022 attach_opl3sa2_mixer(&opl3sa2_state[card].cfg, card);
1023 attach_opl3sa2_mss(&opl3sa2_state[card].cfg_mss);
1026 opl3sa2_state[card].card = card;
1028 /* register our power management capabilities */
1029 opl3sa2_state[card].pmdev = pm_register(PM_ISA_DEV, card, opl3sa2_pm_callback);
1030 if (opl3sa2_state[card].pmdev)
1031 opl3sa2_state[card].pmdev->data = &opl3sa2_state[card];
1032 #endif /* CONFIG_PM */
1035 * Set the Yamaha 3D enhancement mode (aka Ymersion) if asked to and
1039 if (opl3sa2_state[card].chipset == CHIPSET_OPL3SA2) {
1041 PFX "ymode not supported on OPL3-SA2\n");
1044 opl3sa2_set_ymode(&opl3sa2_state[card].cfg, ymode);
1049 /* Set A/D input to Mono loopback if asked to. */
1050 if (loopback != -1) {
1051 opl3sa2_set_loopback(&opl3sa2_state[card].cfg, loopback);
1054 /* Attach MPU if we've been asked to do so, failure isn't fatal */
1055 if (opl3sa2_state[card].cfg_mpu.io_base != -1) {
1056 if (probe_opl3sa2_mpu(&opl3sa2_state[card].cfg_mpu)) {
1057 if (attach_opl3sa2_mpu(&opl3sa2_state[card].cfg_mpu)) {
1058 printk(KERN_ERR PFX "failed to attach MPU401\n");
1059 opl3sa2_state[card].cfg_mpu.slots[1] = -1;
1066 printk(KERN_NOTICE PFX "%d PnP card(s) found.\n", opl3sa2_cards_num);
1074 * Uninstall OPL3-SA2 based card(s).
1076 static void __exit cleanup_opl3sa2(void)
1080 for(card = 0; card < opl3sa2_cards_num; card++) {
1082 if (opl3sa2_state[card].pmdev)
1083 pm_unregister(opl3sa2_state[card].pmdev);
1085 if (opl3sa2_state[card].cfg_mpu.slots[1] != -1) {
1086 unload_opl3sa2_mpu(&opl3sa2_state[card].cfg_mpu);
1088 unload_opl3sa2_mss(&opl3sa2_state[card].cfg_mss);
1089 unload_opl3sa2(&opl3sa2_state[card].cfg, card);
1091 pnp_unregister_driver(&opl3sa2_driver);
1096 module_init(init_opl3sa2);
1097 module_exit(cleanup_opl3sa2);
1100 static int __init setup_opl3sa2(char *str)
1102 /* io, irq, dma, dma2,... */
1108 str = get_options(str, ARRAY_SIZE(ints), ints);
1120 multiple = ints[10];
1125 __setup("opl3sa2=", setup_opl3sa2);