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, void __user *arg)
394 int retval, value, cmdf = cmd & 0xff;
395 int __user *p = (int __user *)arg;
397 opl3sa2_state_t* devc = &opl3sa2_state[dev];
400 case SOUND_MIXER_VOLUME:
401 case SOUND_MIXER_MIC:
402 case SOUND_MIXER_DEVMASK:
403 case SOUND_MIXER_STEREODEVS:
404 case SOUND_MIXER_RECMASK:
405 case SOUND_MIXER_RECSRC:
406 case SOUND_MIXER_CAPS:
413 if (((cmd >> 8) & 0xff) != 'M')
417 if (_SIOC_DIR (cmd) & _SIOC_WRITE) {
419 case SOUND_MIXER_VOLUME:
420 retval = get_user(value, (unsigned __user *) arg);
423 arg_to_vol_stereo(value, &devc->volume_l, &devc->volume_r);
424 opl3sa2_set_volume(devc, devc->volume_l, devc->volume_r);
425 value = ret_vol_stereo(devc->volume_l, devc->volume_r);
426 retval = put_user(value, p);
429 case SOUND_MIXER_MIC:
430 retval = get_user(value, (unsigned __user *) arg);
433 arg_to_vol_mono(value, &devc->mic);
434 opl3sa2_set_mic(devc, devc->mic);
435 value = ret_vol_mono(devc->mic);
436 retval = put_user(value, p);
448 case SOUND_MIXER_DEVMASK:
449 retval = put_user(SOUND_MASK_VOLUME | SOUND_MASK_MIC, p);
452 case SOUND_MIXER_STEREODEVS:
453 retval = put_user(SOUND_MASK_VOLUME, p);
456 case SOUND_MIXER_RECMASK:
457 /* No recording devices */
458 retval = put_user(0, p);
461 case SOUND_MIXER_CAPS:
462 retval = put_user(SOUND_CAP_EXCL_INPUT, p);
465 case SOUND_MIXER_RECSRC:
466 /* No recording source */
467 retval = put_user(0, p);
470 case SOUND_MIXER_VOLUME:
471 value = ret_vol_stereo(devc->volume_l, devc->volume_r);
472 retval = put_user(value, p);
475 case SOUND_MIXER_MIC:
476 value = ret_vol_mono(devc->mic);
486 /* opl3sa2_mixer_ioctl end */
489 static int opl3sa3_mixer_ioctl(int dev, unsigned int cmd, void __user * arg)
491 int value, retval, cmdf = cmd & 0xff;
493 opl3sa2_state_t* devc = &opl3sa2_state[dev];
496 case SOUND_MIXER_BASS:
497 value = ret_vol_stereo(devc->bass_l, devc->bass_r);
498 retval = put_user(value, (int __user *) arg);
501 case SOUND_MIXER_TREBLE:
502 value = ret_vol_stereo(devc->treble_l, devc->treble_r);
503 retval = put_user(value, (int __user *) arg);
506 case SOUND_MIXER_DIGITAL1:
507 value = ret_vol_stereo(devc->wide_l, devc->wide_r);
508 retval = put_user(value, (int __user *) arg);
516 /* opl3sa3_mixer_ioctl end */
519 static struct mixer_operations opl3sa2_mixer_operations =
521 .owner = THIS_MODULE,
523 .name = "Yamaha OPL3-SA2",
524 .ioctl = opl3sa2_mixer_ioctl
527 static struct mixer_operations opl3sa3_mixer_operations =
529 .owner = THIS_MODULE,
531 .name = "Yamaha OPL3-SA3",
532 .ioctl = opl3sa3_mixer_ioctl
535 /* End of mixer-related stuff */
539 * Component probe, attach, unload functions
542 static inline int __init probe_opl3sa2_mpu(struct address_info* hw_config)
544 return probe_mpu401(hw_config);
548 static inline int __init attach_opl3sa2_mpu(struct address_info* hw_config)
550 return attach_mpu401(hw_config, THIS_MODULE);
554 static inline void __exit unload_opl3sa2_mpu(struct address_info *hw_config)
556 unload_mpu401(hw_config);
560 static inline int __init probe_opl3sa2_mss(struct address_info* hw_config)
562 return probe_ms_sound(hw_config);
566 static void __init attach_opl3sa2_mss(struct address_info* hw_config)
570 initial_mixers = num_mixers;
571 attach_ms_sound(hw_config, THIS_MODULE); /* Slot 0 */
572 if (hw_config->slots[0] != -1) {
573 /* Did the MSS driver install? */
574 if(num_mixers == (initial_mixers + 1)) {
575 /* The MSS mixer is installed, reroute mixers appropiately */
576 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_CD);
577 AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_SYNTH);
578 AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_LINE);
581 printk(KERN_ERR PFX "MSS mixer not installed?\n");
587 static inline void __exit unload_opl3sa2_mss(struct address_info* hw_config)
589 unload_ms_sound(hw_config);
593 static int __init probe_opl3sa2(struct address_info* hw_config, int card)
597 unsigned char version;
600 * Try and allocate our I/O port range.
602 if (!request_region(hw_config->io_base, 2, OPL3SA2_MODULE_NAME)) {
603 printk(KERN_ERR PFX "Control I/O port %#x not free\n",
609 * Check if writing to the read-only version bits of the miscellaneous
610 * register succeeds or not (it should not).
612 opl3sa2_read(hw_config->io_base, OPL3SA2_MISC, &misc);
613 opl3sa2_write(hw_config->io_base, OPL3SA2_MISC, misc ^ 0x07);
614 opl3sa2_read(hw_config->io_base, OPL3SA2_MISC, &tmp);
616 printk(KERN_ERR PFX "Control I/O port %#x is not a YMF7xx chipset!\n",
622 * Check if the MIC register is accessible.
624 opl3sa2_read(hw_config->io_base, OPL3SA2_MIC, &tmp);
625 opl3sa2_write(hw_config->io_base, OPL3SA2_MIC, 0x8a);
626 opl3sa2_read(hw_config->io_base, OPL3SA2_MIC, &tmp);
627 if((tmp & 0x9f) != 0x8a) {
629 PFX "Control I/O port %#x is not a YMF7xx chipset!\n",
633 opl3sa2_write(hw_config->io_base, OPL3SA2_MIC, tmp);
636 * Determine chipset type (SA2 or SA3)
638 * This is done by looking at the chipset version in the lower 3 bits
639 * of the miscellaneous register.
641 version = misc & 0x07;
642 printk(KERN_DEBUG PFX "Chipset version = %#x\n", version);
645 opl3sa2_state[card].chipset = CHIPSET_UNKNOWN;
647 PFX "Unknown Yamaha audio controller version\n");
651 opl3sa2_state[card].chipset = CHIPSET_OPL3SA2;
652 printk(KERN_INFO PFX "Found OPL3-SA2 (YMF711)\n");
656 opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
658 PFX "Found OPL3-SA3 (YMF715 or YMF719)\n");
661 case VERSION_YMF715B:
662 opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
664 PFX "Found OPL3-SA3 (YMF715B or YMF719B)\n");
667 case VERSION_YMF715E:
669 opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
671 PFX "Found OPL3-SA3 (YMF715E or YMF719E)\n");
675 if (opl3sa2_state[card].chipset != CHIPSET_UNKNOWN) {
676 /* Generate a pretty name */
677 opl3sa2_state[card].chipset_name = (char *)CHIPSET_TABLE[opl3sa2_state[card].chipset];
682 release_region(hw_config->io_base, 2);
688 static void __init attach_opl3sa2(struct address_info* hw_config, int card)
690 /* Initialize IRQ configuration to IRQ-B: -, IRQ-A: WSS+MPU+OPL3 */
691 opl3sa2_write(hw_config->io_base, OPL3SA2_IRQ_CONFIG, 0x0d);
693 /* Initialize DMA configuration */
694 if(hw_config->dma2 == hw_config->dma) {
695 /* Want DMA configuration DMA-B: -, DMA-A: WSS-P+WSS-R */
696 opl3sa2_write(hw_config->io_base, OPL3SA2_DMA_CONFIG, 0x03);
699 /* Want DMA configuration DMA-B: WSS-R, DMA-A: WSS-P */
700 opl3sa2_write(hw_config->io_base, OPL3SA2_DMA_CONFIG, 0x21);
705 static void __init attach_opl3sa2_mixer(struct address_info *hw_config, int card)
707 struct mixer_operations* mixer_operations;
708 opl3sa2_state_t* devc = &opl3sa2_state[card];
710 /* Install master mixer */
711 if (devc->chipset == CHIPSET_OPL3SA3) {
712 mixer_operations = &opl3sa3_mixer_operations;
715 mixer_operations = &opl3sa2_mixer_operations;
718 devc->cfg_port = hw_config->io_base;
719 devc->mixer = sound_install_mixer(MIXER_DRIVER_VERSION,
720 mixer_operations->name,
722 sizeof(struct mixer_operations),
724 if(devc->mixer < 0) {
725 printk(KERN_ERR PFX "Could not install %s master mixer\n",
726 mixer_operations->name);
729 opl3sa2_mixer_reset(devc);
735 static void __init opl3sa2_clear_slots(struct address_info* hw_config)
739 for(i = 0; i < 6; i++) {
740 hw_config->slots[i] = -1;
745 static void __init opl3sa2_set_ymode(struct address_info* hw_config, int ymode)
748 * Set the Yamaha 3D enhancement mode (aka Ymersion) if asked to and
751 * 0: Desktop (aka normal) 5-12 cm speakers
752 * 1: Notebook PC mode 1 3 cm speakers
753 * 2: Notebook PC mode 2 1.5 cm speakers
754 * 3: Hi-fi 16-38 cm speakers
756 if(ymode >= 0 && ymode <= 3) {
757 unsigned char sys_ctrl;
759 opl3sa2_read(hw_config->io_base, OPL3SA2_SYS_CTRL, &sys_ctrl);
760 sys_ctrl = (sys_ctrl & 0xcf) | ((ymode & 3) << 4);
761 opl3sa2_write(hw_config->io_base, OPL3SA2_SYS_CTRL, sys_ctrl);
764 printk(KERN_ERR PFX "not setting ymode, it must be one of 0,1,2,3\n");
769 static void __init opl3sa2_set_loopback(struct address_info* hw_config, int loopback)
771 if(loopback >= 0 && loopback <= 1) {
774 opl3sa2_read(hw_config->io_base, OPL3SA2_MISC, &misc);
775 misc = (misc & 0xef) | ((loopback & 1) << 4);
776 opl3sa2_write(hw_config->io_base, OPL3SA2_MISC, misc);
779 printk(KERN_ERR PFX "not setting loopback, it must be either 0 or 1\n");
784 static void __exit unload_opl3sa2(struct address_info* hw_config, int card)
786 /* Release control ports */
787 release_region(hw_config->io_base, 2);
790 if(opl3sa2_state[card].mixer >= 0)
791 sound_unload_mixerdev(opl3sa2_state[card].mixer);
796 struct pnp_device_id pnp_opl3sa2_list[] = {
797 {.id = "YMH0021", .driver_data = 0},
801 MODULE_DEVICE_TABLE(pnp, pnp_opl3sa2_list);
803 static int opl3sa2_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
805 int card = opl3sa2_cards_num;
807 /* we don't actually want to return an error as the user may have specified
808 * no multiple card search
811 if (opl3sa2_cards_num == OPL3SA2_CARDS_MAX)
813 opl3sa2_activated[card] = 1;
815 /* Our own config: */
816 opl3sa2_state[card].cfg.io_base = pnp_port_start(dev, 4);
817 opl3sa2_state[card].cfg.irq = pnp_irq(dev, 0);
818 opl3sa2_state[card].cfg.dma = pnp_dma(dev, 0);
819 opl3sa2_state[card].cfg.dma2 = pnp_dma(dev, 1);
821 /* The MSS config: */
822 opl3sa2_state[card].cfg_mss.io_base = pnp_port_start(dev, 1);
823 opl3sa2_state[card].cfg_mss.irq = pnp_irq(dev, 0);
824 opl3sa2_state[card].cfg_mss.dma = pnp_dma(dev, 0);
825 opl3sa2_state[card].cfg_mss.dma2 = pnp_dma(dev, 1);
826 opl3sa2_state[card].cfg_mss.card_subtype = 1; /* No IRQ or DMA setup */
828 opl3sa2_state[card].cfg_mpu.io_base = pnp_port_start(dev, 3);
829 opl3sa2_state[card].cfg_mpu.irq = pnp_irq(dev, 0);
830 opl3sa2_state[card].cfg_mpu.dma = -1;
831 opl3sa2_state[card].cfg_mpu.dma2 = -1;
832 opl3sa2_state[card].cfg_mpu.always_detect = 1; /* It's there, so use shared IRQs */
834 /* Call me paranoid: */
835 opl3sa2_clear_slots(&opl3sa2_state[card].cfg);
836 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mss);
837 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mpu);
839 opl3sa2_state[card].pdev = dev;
845 static struct pnp_driver opl3sa2_driver = {
847 .id_table = pnp_opl3sa2_list,
848 .probe = opl3sa2_pnp_probe,
851 #endif /* CONFIG_PNP */
853 /* End of component functions */
856 static spinlock_t opl3sa2_lock = SPIN_LOCK_UNLOCKED;
858 /* Power Management support functions */
859 static int opl3sa2_suspend(struct pm_dev *pdev, unsigned int pm_mode)
867 spin_lock_irqsave(&opl3sa2_lock,flags);
869 p = (opl3sa2_state_t *) pdev->data;
872 pm_mode = OPL3SA2_PM_MODE1;
875 pm_mode = OPL3SA2_PM_MODE2;
878 pm_mode = OPL3SA2_PM_MODE3;
881 /* we don't know howto handle this... */
882 spin_unlock_irqrestore(&opl3sa2_lock, flags);
888 /* its supposed to automute before suspending, so we won't bother */
889 opl3sa2_write(p->cfg_port, OPL3SA2_PM, pm_mode);
890 /* wait a while for the clock oscillator to stabilise */
893 spin_unlock_irqrestore(&opl3sa2_lock,flags);
897 static int opl3sa2_resume(struct pm_dev *pdev)
905 p = (opl3sa2_state_t *) pdev->data;
906 spin_lock_irqsave(&opl3sa2_lock,flags);
908 /* I don't think this is necessary */
909 opl3sa2_write(p->cfg_port, OPL3SA2_PM, OPL3SA2_PM_MODE0);
910 opl3sa2_mixer_restore(p);
913 spin_unlock_irqrestore(&opl3sa2_lock,flags);
917 static int opl3sa2_pm_callback(struct pm_dev *pdev, pm_request_t rqst, void *data)
919 unsigned long mode = (unsigned long)data;
923 return opl3sa2_suspend(pdev, mode);
926 return opl3sa2_resume(pdev);
930 #endif /* CONFIG_PM */
933 * Install OPL3-SA2 based card(s).
935 * Need to have ad1848 and mpu401 loaded ready.
937 static int __init init_opl3sa2(void)
941 /* Sanitize isapnp and multiple settings */
942 isapnp = isapnp != 0 ? 1 : 0;
943 multiple = multiple != 0 ? 1 : 0;
945 max = (multiple && isapnp) ? OPL3SA2_CARDS_MAX : 1;
949 pnp_register_driver(&opl3sa2_driver);
950 if(!opl3sa2_cards_num){
951 printk(KERN_INFO PFX "No PnP cards found\n");
954 max = opl3sa2_cards_num;
958 for (card = 0; card < max; card++) {
959 /* If a user wants an I/O then assume they meant it */
962 if (io == -1 || irq == -1 || dma == -1 ||
963 dma2 == -1 || mss_io == -1) {
965 PFX "io, mss_io, irq, dma, and dma2 must be set\n");
972 * (NOTE: IRQ and DMA aren't used, so they're set to
973 * give pretty output from conf_printf. :)
975 opl3sa2_state[card].cfg.io_base = io;
976 opl3sa2_state[card].cfg.irq = irq;
977 opl3sa2_state[card].cfg.dma = dma;
978 opl3sa2_state[card].cfg.dma2 = dma2;
980 /* The MSS config: */
981 opl3sa2_state[card].cfg_mss.io_base = mss_io;
982 opl3sa2_state[card].cfg_mss.irq = irq;
983 opl3sa2_state[card].cfg_mss.dma = dma;
984 opl3sa2_state[card].cfg_mss.dma2 = dma2;
985 opl3sa2_state[card].cfg_mss.card_subtype = 1; /* No IRQ or DMA setup */
987 opl3sa2_state[card].cfg_mpu.io_base = mpu_io;
988 opl3sa2_state[card].cfg_mpu.irq = irq;
989 opl3sa2_state[card].cfg_mpu.dma = -1;
990 opl3sa2_state[card].cfg_mpu.always_detect = 1; /* Use shared IRQs */
992 /* Call me paranoid: */
993 opl3sa2_clear_slots(&opl3sa2_state[card].cfg);
994 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mss);
995 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mpu);
998 if (probe_opl3sa2(&opl3sa2_state[card].cfg, card))
1002 if (!probe_opl3sa2_mss(&opl3sa2_state[card].cfg_mss)) {
1004 * If one or more cards are already registered, don't
1005 * return an error but print a warning. Note, this
1006 * should never really happen unless the hardware or
1007 * ISA PnP screwed up.
1009 release_region(opl3sa2_state[card].cfg.io_base, 2);
1011 if (opl3sa2_cards_num) {
1013 PFX "There was a problem probing one "
1014 " of the ISA PNP cards, continuing\n");
1015 opl3sa2_cards_num--;
1021 attach_opl3sa2(&opl3sa2_state[card].cfg, card);
1022 conf_printf(opl3sa2_state[card].chipset_name, &opl3sa2_state[card].cfg);
1023 attach_opl3sa2_mixer(&opl3sa2_state[card].cfg, card);
1024 attach_opl3sa2_mss(&opl3sa2_state[card].cfg_mss);
1027 opl3sa2_state[card].card = card;
1029 /* register our power management capabilities */
1030 opl3sa2_state[card].pmdev = pm_register(PM_ISA_DEV, card, opl3sa2_pm_callback);
1031 if (opl3sa2_state[card].pmdev)
1032 opl3sa2_state[card].pmdev->data = &opl3sa2_state[card];
1033 #endif /* CONFIG_PM */
1036 * Set the Yamaha 3D enhancement mode (aka Ymersion) if asked to and
1040 if (opl3sa2_state[card].chipset == CHIPSET_OPL3SA2) {
1042 PFX "ymode not supported on OPL3-SA2\n");
1045 opl3sa2_set_ymode(&opl3sa2_state[card].cfg, ymode);
1050 /* Set A/D input to Mono loopback if asked to. */
1051 if (loopback != -1) {
1052 opl3sa2_set_loopback(&opl3sa2_state[card].cfg, loopback);
1055 /* Attach MPU if we've been asked to do so, failure isn't fatal */
1056 if (opl3sa2_state[card].cfg_mpu.io_base != -1) {
1057 if (probe_opl3sa2_mpu(&opl3sa2_state[card].cfg_mpu)) {
1058 if (attach_opl3sa2_mpu(&opl3sa2_state[card].cfg_mpu)) {
1059 printk(KERN_ERR PFX "failed to attach MPU401\n");
1060 opl3sa2_state[card].cfg_mpu.slots[1] = -1;
1067 printk(KERN_NOTICE PFX "%d PnP card(s) found.\n", opl3sa2_cards_num);
1075 * Uninstall OPL3-SA2 based card(s).
1077 static void __exit cleanup_opl3sa2(void)
1081 for(card = 0; card < opl3sa2_cards_num; card++) {
1083 if (opl3sa2_state[card].pmdev)
1084 pm_unregister(opl3sa2_state[card].pmdev);
1086 if (opl3sa2_state[card].cfg_mpu.slots[1] != -1) {
1087 unload_opl3sa2_mpu(&opl3sa2_state[card].cfg_mpu);
1089 unload_opl3sa2_mss(&opl3sa2_state[card].cfg_mss);
1090 unload_opl3sa2(&opl3sa2_state[card].cfg, card);
1092 pnp_unregister_driver(&opl3sa2_driver);
1097 module_init(init_opl3sa2);
1098 module_exit(cleanup_opl3sa2);
1101 static int __init setup_opl3sa2(char *str)
1103 /* io, irq, dma, dma2,... */
1109 str = get_options(str, ARRAY_SIZE(ints), ints);
1121 multiple = ints[10];
1126 __setup("opl3sa2=", setup_opl3sa2);