1 | // SPDX-License-Identifier: GPL-2.0-or-later
|
---|
2 | /*
|
---|
3 | * Driver for Yamaha OPL3-SA[2,3] soundcards
|
---|
4 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include <linux/init.h>
|
---|
8 | #include <linux/err.h>
|
---|
9 | #include <linux/isa.h>
|
---|
10 | #include <linux/interrupt.h>
|
---|
11 | #include <linux/pm.h>
|
---|
12 | #include <linux/pnp.h>
|
---|
13 | #include <linux/module.h>
|
---|
14 | #include <linux/io.h>
|
---|
15 | #include <sound/core.h>
|
---|
16 | #include <sound/wss.h>
|
---|
17 | #include <sound/mpu401.h>
|
---|
18 | #include <sound/opl3.h>
|
---|
19 | #include <sound/initval.h>
|
---|
20 | #include <sound/tlv.h>
|
---|
21 |
|
---|
22 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
|
---|
23 | MODULE_DESCRIPTION("Yamaha OPL3SA2+");
|
---|
24 | MODULE_LICENSE("GPL");
|
---|
25 | MODULE_SUPPORTED_DEVICE("{{Yamaha,YMF719E-S},"
|
---|
26 | "{Genius,Sound Maker 3DX},"
|
---|
27 | "{Yamaha,OPL3SA3},"
|
---|
28 | "{Intel,AL440LX sound},"
|
---|
29 | "{NeoMagic,MagicWave 3DX}}");
|
---|
30 |
|
---|
31 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
|
---|
32 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
|
---|
33 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
|
---|
34 | #ifdef CONFIG_PNP
|
---|
35 | #ifndef TARGET_OS2
|
---|
36 | static bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
|
---|
37 | #else
|
---|
38 | static int isapnp[SNDRV_CARDS] = {1,1,1,1,1,1,1,1};
|
---|
39 | #endif
|
---|
40 | #endif
|
---|
41 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0xf86,0x370,0x100 */
|
---|
42 | static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */
|
---|
43 | static long wss_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* 0x530,0xe80,0xf40,0x604 */
|
---|
44 | static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x388 */
|
---|
45 | static long midi_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* 0x330,0x300 */
|
---|
46 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 0,1,3,5,9,11,12,15 */
|
---|
47 | static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
|
---|
48 | static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
|
---|
49 | static int opl3sa3_ymode[SNDRV_CARDS]; /* 0,1,2,3 */ /*SL Added*/
|
---|
50 |
|
---|
51 | module_param_array(index, int, NULL, 0444);
|
---|
52 | MODULE_PARM_DESC(index, "Index value for OPL3-SA soundcard.");
|
---|
53 | module_param_array(id, charp, NULL, 0444);
|
---|
54 | MODULE_PARM_DESC(id, "ID string for OPL3-SA soundcard.");
|
---|
55 | module_param_array(enable, bool, NULL, 0444);
|
---|
56 | MODULE_PARM_DESC(enable, "Enable OPL3-SA soundcard.");
|
---|
57 | #ifdef CONFIG_PNP
|
---|
58 | module_param_array(isapnp, bool, NULL, 0444);
|
---|
59 | MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
|
---|
60 | #endif
|
---|
61 | module_param_hw_array(port, long, ioport, NULL, 0444);
|
---|
62 | MODULE_PARM_DESC(port, "Port # for OPL3-SA driver.");
|
---|
63 | module_param_hw_array(sb_port, long, ioport, NULL, 0444);
|
---|
64 | MODULE_PARM_DESC(sb_port, "SB port # for OPL3-SA driver.");
|
---|
65 | module_param_hw_array(wss_port, long, ioport, NULL, 0444);
|
---|
66 | MODULE_PARM_DESC(wss_port, "WSS port # for OPL3-SA driver.");
|
---|
67 | module_param_hw_array(fm_port, long, ioport, NULL, 0444);
|
---|
68 | MODULE_PARM_DESC(fm_port, "FM port # for OPL3-SA driver.");
|
---|
69 | module_param_hw_array(midi_port, long, ioport, NULL, 0444);
|
---|
70 | MODULE_PARM_DESC(midi_port, "MIDI port # for OPL3-SA driver.");
|
---|
71 | module_param_hw_array(irq, int, irq, NULL, 0444);
|
---|
72 | MODULE_PARM_DESC(irq, "IRQ # for OPL3-SA driver.");
|
---|
73 | module_param_hw_array(dma1, int, dma, NULL, 0444);
|
---|
74 | MODULE_PARM_DESC(dma1, "DMA1 # for OPL3-SA driver.");
|
---|
75 | module_param_hw_array(dma2, int, dma, NULL, 0444);
|
---|
76 | MODULE_PARM_DESC(dma2, "DMA2 # for OPL3-SA driver.");
|
---|
77 | module_param_array(opl3sa3_ymode, int, NULL, 0444);
|
---|
78 | MODULE_PARM_DESC(opl3sa3_ymode, "Speaker size selection for 3D Enhancement mode: Desktop/Large Notebook/Small Notebook/HiFi.");
|
---|
79 |
|
---|
80 | #ifdef CONFIG_PNP
|
---|
81 | static int isa_registered;
|
---|
82 | static int pnp_registered;
|
---|
83 | static int pnpc_registered;
|
---|
84 | #endif
|
---|
85 |
|
---|
86 | /* control ports */
|
---|
87 | #define OPL3SA2_PM_CTRL 0x01
|
---|
88 | #define OPL3SA2_SYS_CTRL 0x02
|
---|
89 | #define OPL3SA2_IRQ_CONFIG 0x03
|
---|
90 | #define OPL3SA2_IRQ_STATUS 0x04
|
---|
91 | #define OPL3SA2_DMA_CONFIG 0x06
|
---|
92 | #define OPL3SA2_MASTER_LEFT 0x07
|
---|
93 | #define OPL3SA2_MASTER_RIGHT 0x08
|
---|
94 | #define OPL3SA2_MIC 0x09
|
---|
95 | #define OPL3SA2_MISC 0x0A
|
---|
96 |
|
---|
97 | /* opl3sa3 only */
|
---|
98 | #define OPL3SA3_DGTL_DOWN 0x12
|
---|
99 | #define OPL3SA3_ANLG_DOWN 0x13
|
---|
100 | #define OPL3SA3_WIDE 0x14
|
---|
101 | #define OPL3SA3_BASS 0x15
|
---|
102 | #define OPL3SA3_TREBLE 0x16
|
---|
103 |
|
---|
104 | /* power management bits */
|
---|
105 | #define OPL3SA2_PM_ADOWN 0x20
|
---|
106 | #define OPL3SA2_PM_PSV 0x04
|
---|
107 | #define OPL3SA2_PM_PDN 0x02
|
---|
108 | #define OPL3SA2_PM_PDX 0x01
|
---|
109 |
|
---|
110 | #define OPL3SA2_PM_D0 0x00
|
---|
111 | #define OPL3SA2_PM_D3 (OPL3SA2_PM_ADOWN|OPL3SA2_PM_PSV|OPL3SA2_PM_PDN|OPL3SA2_PM_PDX)
|
---|
112 |
|
---|
113 | struct snd_opl3sa2 {
|
---|
114 | int version; /* 2 or 3 */
|
---|
115 | unsigned long port; /* control port */
|
---|
116 | struct resource *res_port; /* control port resource */
|
---|
117 | int irq;
|
---|
118 | int single_dma;
|
---|
119 | spinlock_t reg_lock;
|
---|
120 | struct snd_hwdep *synth;
|
---|
121 | struct snd_rawmidi *rmidi;
|
---|
122 | struct snd_wss *wss;
|
---|
123 | unsigned char ctlregs[0x20];
|
---|
124 | int ymode; /* SL added */
|
---|
125 | struct snd_kcontrol *master_switch;
|
---|
126 | struct snd_kcontrol *master_volume;
|
---|
127 | };
|
---|
128 |
|
---|
129 | #define PFX "opl3sa2: "
|
---|
130 |
|
---|
131 | #ifdef CONFIG_PNP
|
---|
132 |
|
---|
133 | static const struct pnp_device_id snd_opl3sa2_pnpbiosids[] = {
|
---|
134 | { .id = "YMH0021" },
|
---|
135 | { .id = "NMX2210" }, /* Gateway Solo 2500 */
|
---|
136 | { .id = "" } /* end */
|
---|
137 | };
|
---|
138 |
|
---|
139 | MODULE_DEVICE_TABLE(pnp, snd_opl3sa2_pnpbiosids);
|
---|
140 |
|
---|
141 | static const struct pnp_card_device_id snd_opl3sa2_pnpids[] = {
|
---|
142 | /* Yamaha YMF719E-S (Genius Sound Maker 3DX) */
|
---|
143 | { .id = "YMH0020", .devs = { { "YMH0021" } } },
|
---|
144 | /* Yamaha OPL3-SA3 (integrated on Intel's Pentium II AL440LX motherboard) */
|
---|
145 | { .id = "YMH0030", .devs = { { "YMH0021" } } },
|
---|
146 | /* Yamaha OPL3-SA2 */
|
---|
147 | { .id = "YMH0800", .devs = { { "YMH0021" } } },
|
---|
148 | /* Yamaha OPL3-SA2 */
|
---|
149 | { .id = "YMH0801", .devs = { { "YMH0021" } } },
|
---|
150 | /* NeoMagic MagicWave 3DX */
|
---|
151 | { .id = "NMX2200", .devs = { { "YMH2210" } } },
|
---|
152 | /* NeoMagic MagicWave 3D */
|
---|
153 | { .id = "NMX2200", .devs = { { "NMX2210" } } },
|
---|
154 | /* --- */
|
---|
155 | { .id = "" } /* end */
|
---|
156 | };
|
---|
157 |
|
---|
158 | MODULE_DEVICE_TABLE(pnp_card, snd_opl3sa2_pnpids);
|
---|
159 |
|
---|
160 | #endif /* CONFIG_PNP */
|
---|
161 |
|
---|
162 |
|
---|
163 | /* read control port (w/o spinlock) */
|
---|
164 | static unsigned char __snd_opl3sa2_read(struct snd_opl3sa2 *chip, unsigned char reg)
|
---|
165 | {
|
---|
166 | unsigned char result;
|
---|
167 | #if 0
|
---|
168 | outb(0x1d, port); /* password */
|
---|
169 | printk(KERN_DEBUG "read [0x%lx] = 0x%x\n", port, inb(port));
|
---|
170 | #endif
|
---|
171 | outb(reg, chip->port); /* register */
|
---|
172 | result = inb(chip->port + 1);
|
---|
173 | #if 0
|
---|
174 | printk(KERN_DEBUG "read [0x%lx] = 0x%x [0x%x]\n",
|
---|
175 | port, result, inb(port));
|
---|
176 | #endif
|
---|
177 | return result;
|
---|
178 | }
|
---|
179 |
|
---|
180 | /* read control port (with spinlock) */
|
---|
181 | static unsigned char snd_opl3sa2_read(struct snd_opl3sa2 *chip, unsigned char reg)
|
---|
182 | {
|
---|
183 | unsigned long flags;
|
---|
184 | unsigned char result;
|
---|
185 |
|
---|
186 | spin_lock_irqsave(&chip->reg_lock, flags);
|
---|
187 | result = __snd_opl3sa2_read(chip, reg);
|
---|
188 | spin_unlock_irqrestore(&chip->reg_lock, flags);
|
---|
189 | return result;
|
---|
190 | }
|
---|
191 |
|
---|
192 | /* write control port (w/o spinlock) */
|
---|
193 | static void __snd_opl3sa2_write(struct snd_opl3sa2 *chip, unsigned char reg, unsigned char value)
|
---|
194 | {
|
---|
195 | #if 0
|
---|
196 | outb(0x1d, port); /* password */
|
---|
197 | #endif
|
---|
198 | outb(reg, chip->port); /* register */
|
---|
199 | outb(value, chip->port + 1);
|
---|
200 | chip->ctlregs[reg] = value;
|
---|
201 | }
|
---|
202 |
|
---|
203 | /* write control port (with spinlock) */
|
---|
204 | static void snd_opl3sa2_write(struct snd_opl3sa2 *chip, unsigned char reg, unsigned char value)
|
---|
205 | {
|
---|
206 | unsigned long flags;
|
---|
207 | spin_lock_irqsave(&chip->reg_lock, flags);
|
---|
208 | __snd_opl3sa2_write(chip, reg, value);
|
---|
209 | spin_unlock_irqrestore(&chip->reg_lock, flags);
|
---|
210 | }
|
---|
211 |
|
---|
212 | static int snd_opl3sa2_detect(struct snd_card *card)
|
---|
213 | {
|
---|
214 | struct snd_opl3sa2 *chip = card->private_data;
|
---|
215 | unsigned long port;
|
---|
216 | unsigned char tmp, tmp1;
|
---|
217 | char str[2];
|
---|
218 |
|
---|
219 | port = chip->port;
|
---|
220 | if ((chip->res_port = request_region(port, 2, "OPL3-SA control")) == NULL) {
|
---|
221 | snd_printk(KERN_ERR PFX "can't grab port 0x%lx\n", port);
|
---|
222 | return -EBUSY;
|
---|
223 | }
|
---|
224 | /*
|
---|
225 | snd_printk(KERN_DEBUG "REG 0A = 0x%x\n",
|
---|
226 | snd_opl3sa2_read(chip, 0x0a));
|
---|
227 | */
|
---|
228 | chip->version = 0;
|
---|
229 | tmp = snd_opl3sa2_read(chip, OPL3SA2_MISC);
|
---|
230 | if (tmp == 0xff) {
|
---|
231 | snd_printd("OPL3-SA [0x%lx] detect = 0x%x\n", port, tmp);
|
---|
232 | return -ENODEV;
|
---|
233 | }
|
---|
234 | switch (tmp & 0x07) {
|
---|
235 | case 0x01:
|
---|
236 | chip->version = 2; /* YMF711 */
|
---|
237 | break;
|
---|
238 | default:
|
---|
239 | chip->version = 3;
|
---|
240 | /* 0x02 - standard */
|
---|
241 | /* 0x03 - YM715B */
|
---|
242 | /* 0x04 - YM719 - OPL-SA4? */
|
---|
243 | /* 0x05 - OPL3-SA3 - Libretto 100 */
|
---|
244 | /* 0x07 - unknown - Neomagic MagicWave 3D */
|
---|
245 | break;
|
---|
246 | }
|
---|
247 | str[0] = chip->version + '0';
|
---|
248 | str[1] = 0;
|
---|
249 | strcat(card->shortname, str);
|
---|
250 | snd_opl3sa2_write(chip, OPL3SA2_MISC, tmp ^ 7);
|
---|
251 | if ((tmp1 = snd_opl3sa2_read(chip, OPL3SA2_MISC)) != tmp) {
|
---|
252 | snd_printd("OPL3-SA [0x%lx] detect (1) = 0x%x (0x%x)\n", port, tmp, tmp1);
|
---|
253 | return -ENODEV;
|
---|
254 | }
|
---|
255 | /* try if the MIC register is accessible */
|
---|
256 | tmp = snd_opl3sa2_read(chip, OPL3SA2_MIC);
|
---|
257 | snd_opl3sa2_write(chip, OPL3SA2_MIC, 0x8a);
|
---|
258 | if (((tmp1 = snd_opl3sa2_read(chip, OPL3SA2_MIC)) & 0x9f) != 0x8a) {
|
---|
259 | snd_printd("OPL3-SA [0x%lx] detect (2) = 0x%x (0x%x)\n", port, tmp, tmp1);
|
---|
260 | return -ENODEV;
|
---|
261 | }
|
---|
262 | snd_opl3sa2_write(chip, OPL3SA2_MIC, 0x9f);
|
---|
263 | /* initialization */
|
---|
264 | /* Power Management - full on */
|
---|
265 | snd_opl3sa2_write(chip, OPL3SA2_PM_CTRL, OPL3SA2_PM_D0);
|
---|
266 | if (chip->version > 2) {
|
---|
267 | /* ymode is bits 4&5 (of 0 to 7) on all but opl3sa2 versions */
|
---|
268 | snd_opl3sa2_write(chip, OPL3SA2_SYS_CTRL, (chip->ymode << 4));
|
---|
269 | } else {
|
---|
270 | /* default for opl3sa2 versions */
|
---|
271 | snd_opl3sa2_write(chip, OPL3SA2_SYS_CTRL, 0x00);
|
---|
272 | }
|
---|
273 | snd_opl3sa2_write(chip, OPL3SA2_IRQ_CONFIG, 0x0d); /* Interrupt Channel Configuration - IRQ A = OPL3 + MPU + WSS */
|
---|
274 | if (chip->single_dma) {
|
---|
275 | snd_opl3sa2_write(chip, OPL3SA2_DMA_CONFIG, 0x03); /* DMA Configuration - DMA A = WSS-R + WSS-P */
|
---|
276 | } else {
|
---|
277 | snd_opl3sa2_write(chip, OPL3SA2_DMA_CONFIG, 0x21); /* DMA Configuration - DMA B = WSS-R, DMA A = WSS-P */
|
---|
278 | }
|
---|
279 | snd_opl3sa2_write(chip, OPL3SA2_MISC, 0x80 | (tmp & 7)); /* Miscellaneous - default */
|
---|
280 | if (chip->version > 2) {
|
---|
281 | snd_opl3sa2_write(chip, OPL3SA3_DGTL_DOWN, 0x00); /* Digital Block Partial Power Down - default */
|
---|
282 | snd_opl3sa2_write(chip, OPL3SA3_ANLG_DOWN, 0x00); /* Analog Block Partial Power Down - default */
|
---|
283 | }
|
---|
284 | return 0;
|
---|
285 | }
|
---|
286 |
|
---|
287 | static irqreturn_t snd_opl3sa2_interrupt(int irq, void *dev_id)
|
---|
288 | {
|
---|
289 | unsigned short status;
|
---|
290 | struct snd_card *card = dev_id;
|
---|
291 | struct snd_opl3sa2 *chip;
|
---|
292 | int handled = 0;
|
---|
293 |
|
---|
294 | if (card == NULL)
|
---|
295 | return IRQ_NONE;
|
---|
296 |
|
---|
297 | chip = card->private_data;
|
---|
298 | status = snd_opl3sa2_read(chip, OPL3SA2_IRQ_STATUS);
|
---|
299 |
|
---|
300 | if (status & 0x20) {
|
---|
301 | handled = 1;
|
---|
302 | snd_opl3_interrupt(chip->synth);
|
---|
303 | }
|
---|
304 |
|
---|
305 | if ((status & 0x10) && chip->rmidi != NULL) {
|
---|
306 | handled = 1;
|
---|
307 | snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
|
---|
308 | }
|
---|
309 |
|
---|
310 | if (status & 0x07) { /* TI,CI,PI */
|
---|
311 | handled = 1;
|
---|
312 | snd_wss_interrupt(irq, chip->wss);
|
---|
313 | }
|
---|
314 |
|
---|
315 | if (status & 0x40) { /* hardware volume change */
|
---|
316 | handled = 1;
|
---|
317 | /* reading from Master Lch register at 0x07 clears this bit */
|
---|
318 | snd_opl3sa2_read(chip, OPL3SA2_MASTER_RIGHT);
|
---|
319 | snd_opl3sa2_read(chip, OPL3SA2_MASTER_LEFT);
|
---|
320 | if (chip->master_switch && chip->master_volume) {
|
---|
321 | snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
|
---|
322 | &chip->master_switch->id);
|
---|
323 | snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
|
---|
324 | &chip->master_volume->id);
|
---|
325 | }
|
---|
326 | }
|
---|
327 | return IRQ_RETVAL(handled);
|
---|
328 | }
|
---|
329 |
|
---|
330 | #define OPL3SA2_SINGLE(xname, xindex, reg, shift, mask, invert) \
|
---|
331 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
|
---|
332 | .info = snd_wss_info_single, \
|
---|
333 | .get = snd_opl3sa2_get_single, .put = snd_opl3sa2_put_single, \
|
---|
334 | .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
|
---|
335 | #define OPL3SA2_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv) \
|
---|
336 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
|
---|
337 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
|
---|
338 | .name = xname, .index = xindex, \
|
---|
339 | .info = snd_wss_info_single, \
|
---|
340 | .get = snd_opl3sa2_get_single, .put = snd_opl3sa2_put_single, \
|
---|
341 | .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24), \
|
---|
342 | .tlv = { .p = (xtlv) } }
|
---|
343 |
|
---|
344 | static int snd_opl3sa2_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
---|
345 | {
|
---|
346 | struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol);
|
---|
347 | unsigned long flags;
|
---|
348 | int reg = kcontrol->private_value & 0xff;
|
---|
349 | int shift = (kcontrol->private_value >> 8) & 0xff;
|
---|
350 | int mask = (kcontrol->private_value >> 16) & 0xff;
|
---|
351 | int invert = (kcontrol->private_value >> 24) & 0xff;
|
---|
352 |
|
---|
353 | spin_lock_irqsave(&chip->reg_lock, flags);
|
---|
354 | ucontrol->value.integer.value[0] = (chip->ctlregs[reg] >> shift) & mask;
|
---|
355 | spin_unlock_irqrestore(&chip->reg_lock, flags);
|
---|
356 | if (invert)
|
---|
357 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
|
---|
358 | return 0;
|
---|
359 | }
|
---|
360 |
|
---|
361 | static int snd_opl3sa2_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
---|
362 | {
|
---|
363 | struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol);
|
---|
364 | unsigned long flags;
|
---|
365 | int reg = kcontrol->private_value & 0xff;
|
---|
366 | int shift = (kcontrol->private_value >> 8) & 0xff;
|
---|
367 | int mask = (kcontrol->private_value >> 16) & 0xff;
|
---|
368 | int invert = (kcontrol->private_value >> 24) & 0xff;
|
---|
369 | int change;
|
---|
370 | unsigned short val, oval;
|
---|
371 |
|
---|
372 | val = (ucontrol->value.integer.value[0] & mask);
|
---|
373 | if (invert)
|
---|
374 | val = mask - val;
|
---|
375 | val <<= shift;
|
---|
376 | spin_lock_irqsave(&chip->reg_lock, flags);
|
---|
377 | oval = chip->ctlregs[reg];
|
---|
378 | val = (oval & ~(mask << shift)) | val;
|
---|
379 | change = val != oval;
|
---|
380 | __snd_opl3sa2_write(chip, reg, val);
|
---|
381 | spin_unlock_irqrestore(&chip->reg_lock, flags);
|
---|
382 | return change;
|
---|
383 | }
|
---|
384 |
|
---|
385 | #define OPL3SA2_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
|
---|
386 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
|
---|
387 | .info = snd_wss_info_double, \
|
---|
388 | .get = snd_opl3sa2_get_double, .put = snd_opl3sa2_put_double, \
|
---|
389 | .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
|
---|
390 | #define OPL3SA2_DOUBLE_TLV(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert, xtlv) \
|
---|
391 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
|
---|
392 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
|
---|
393 | .name = xname, .index = xindex, \
|
---|
394 | .info = snd_wss_info_double, \
|
---|
395 | .get = snd_opl3sa2_get_double, .put = snd_opl3sa2_put_double, \
|
---|
396 | .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22), \
|
---|
397 | .tlv = { .p = (xtlv) } }
|
---|
398 |
|
---|
399 | static int snd_opl3sa2_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
---|
400 | {
|
---|
401 | struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol);
|
---|
402 | unsigned long flags;
|
---|
403 | int left_reg = kcontrol->private_value & 0xff;
|
---|
404 | int right_reg = (kcontrol->private_value >> 8) & 0xff;
|
---|
405 | int shift_left = (kcontrol->private_value >> 16) & 0x07;
|
---|
406 | int shift_right = (kcontrol->private_value >> 19) & 0x07;
|
---|
407 | int mask = (kcontrol->private_value >> 24) & 0xff;
|
---|
408 | int invert = (kcontrol->private_value >> 22) & 1;
|
---|
409 |
|
---|
410 | spin_lock_irqsave(&chip->reg_lock, flags);
|
---|
411 | ucontrol->value.integer.value[0] = (chip->ctlregs[left_reg] >> shift_left) & mask;
|
---|
412 | ucontrol->value.integer.value[1] = (chip->ctlregs[right_reg] >> shift_right) & mask;
|
---|
413 | spin_unlock_irqrestore(&chip->reg_lock, flags);
|
---|
414 | if (invert) {
|
---|
415 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
|
---|
416 | ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
|
---|
417 | }
|
---|
418 | return 0;
|
---|
419 | }
|
---|
420 |
|
---|
421 | static int snd_opl3sa2_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
---|
422 | {
|
---|
423 | struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol);
|
---|
424 | unsigned long flags;
|
---|
425 | int left_reg = kcontrol->private_value & 0xff;
|
---|
426 | int right_reg = (kcontrol->private_value >> 8) & 0xff;
|
---|
427 | int shift_left = (kcontrol->private_value >> 16) & 0x07;
|
---|
428 | int shift_right = (kcontrol->private_value >> 19) & 0x07;
|
---|
429 | int mask = (kcontrol->private_value >> 24) & 0xff;
|
---|
430 | int invert = (kcontrol->private_value >> 22) & 1;
|
---|
431 | int change;
|
---|
432 | unsigned short val1, val2, oval1, oval2;
|
---|
433 |
|
---|
434 | val1 = ucontrol->value.integer.value[0] & mask;
|
---|
435 | val2 = ucontrol->value.integer.value[1] & mask;
|
---|
436 | if (invert) {
|
---|
437 | val1 = mask - val1;
|
---|
438 | val2 = mask - val2;
|
---|
439 | }
|
---|
440 | val1 <<= shift_left;
|
---|
441 | val2 <<= shift_right;
|
---|
442 | spin_lock_irqsave(&chip->reg_lock, flags);
|
---|
443 | if (left_reg != right_reg) {
|
---|
444 | oval1 = chip->ctlregs[left_reg];
|
---|
445 | oval2 = chip->ctlregs[right_reg];
|
---|
446 | val1 = (oval1 & ~(mask << shift_left)) | val1;
|
---|
447 | val2 = (oval2 & ~(mask << shift_right)) | val2;
|
---|
448 | change = val1 != oval1 || val2 != oval2;
|
---|
449 | __snd_opl3sa2_write(chip, left_reg, val1);
|
---|
450 | __snd_opl3sa2_write(chip, right_reg, val2);
|
---|
451 | } else {
|
---|
452 | oval1 = chip->ctlregs[left_reg];
|
---|
453 | val1 = (oval1 & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
|
---|
454 | change = val1 != oval1;
|
---|
455 | __snd_opl3sa2_write(chip, left_reg, val1);
|
---|
456 | }
|
---|
457 | spin_unlock_irqrestore(&chip->reg_lock, flags);
|
---|
458 | return change;
|
---|
459 | }
|
---|
460 |
|
---|
461 | static const DECLARE_TLV_DB_SCALE(db_scale_master, -3000, 200, 0);
|
---|
462 | static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0);
|
---|
463 |
|
---|
464 | static const struct snd_kcontrol_new snd_opl3sa2_controls[] = {
|
---|
465 | OPL3SA2_DOUBLE("Master Playback Switch", 0, 0x07, 0x08, 7, 7, 1, 1),
|
---|
466 | OPL3SA2_DOUBLE_TLV("Master Playback Volume", 0, 0x07, 0x08, 0, 0, 15, 1,
|
---|
467 | db_scale_master),
|
---|
468 | OPL3SA2_SINGLE("Mic Playback Switch", 0, 0x09, 7, 1, 1),
|
---|
469 | OPL3SA2_SINGLE_TLV("Mic Playback Volume", 0, 0x09, 0, 31, 1,
|
---|
470 | db_scale_5bit_12db_max),
|
---|
471 | OPL3SA2_SINGLE("ZV Port Switch", 0, 0x02, 0, 1, 0),
|
---|
472 | };
|
---|
473 |
|
---|
474 | static const struct snd_kcontrol_new snd_opl3sa2_tone_controls[] = {
|
---|
475 | OPL3SA2_DOUBLE("3D Control - Wide", 0, 0x14, 0x14, 4, 0, 7, 0),
|
---|
476 | OPL3SA2_DOUBLE("Tone Control - Bass", 0, 0x15, 0x15, 4, 0, 7, 0),
|
---|
477 | OPL3SA2_DOUBLE("Tone Control - Treble", 0, 0x16, 0x16, 4, 0, 7, 0)
|
---|
478 | };
|
---|
479 |
|
---|
480 | static void snd_opl3sa2_master_free(struct snd_kcontrol *kcontrol)
|
---|
481 | {
|
---|
482 | struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol);
|
---|
483 | chip->master_switch = NULL;
|
---|
484 | chip->master_volume = NULL;
|
---|
485 | }
|
---|
486 |
|
---|
487 | static int snd_opl3sa2_mixer(struct snd_card *card)
|
---|
488 | {
|
---|
489 | struct snd_opl3sa2 *chip = card->private_data;
|
---|
490 | struct snd_ctl_elem_id id1, id2;
|
---|
491 | struct snd_kcontrol *kctl;
|
---|
492 | unsigned int idx;
|
---|
493 | int err;
|
---|
494 |
|
---|
495 | memset(&id1, 0, sizeof(id1));
|
---|
496 | memset(&id2, 0, sizeof(id2));
|
---|
497 | id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
|
---|
498 | /* reassign AUX0 to CD */
|
---|
499 | strcpy(id1.name, "Aux Playback Switch");
|
---|
500 | strcpy(id2.name, "CD Playback Switch");
|
---|
501 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) {
|
---|
502 | snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n");
|
---|
503 | return err;
|
---|
504 | }
|
---|
505 | strcpy(id1.name, "Aux Playback Volume");
|
---|
506 | strcpy(id2.name, "CD Playback Volume");
|
---|
507 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) {
|
---|
508 | snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n");
|
---|
509 | return err;
|
---|
510 | }
|
---|
511 | /* reassign AUX1 to FM */
|
---|
512 | strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
|
---|
513 | strcpy(id2.name, "FM Playback Switch");
|
---|
514 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) {
|
---|
515 | snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n");
|
---|
516 | return err;
|
---|
517 | }
|
---|
518 | strcpy(id1.name, "Aux Playback Volume");
|
---|
519 | strcpy(id2.name, "FM Playback Volume");
|
---|
520 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) {
|
---|
521 | snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n");
|
---|
522 | return err;
|
---|
523 | }
|
---|
524 | /* add OPL3SA2 controls */
|
---|
525 | for (idx = 0; idx < ARRAY_SIZE(snd_opl3sa2_controls); idx++) {
|
---|
526 | if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_opl3sa2_controls[idx], chip))) < 0)
|
---|
527 | return err;
|
---|
528 | switch (idx) {
|
---|
529 | case 0: chip->master_switch = kctl; kctl->private_free = snd_opl3sa2_master_free; break;
|
---|
530 | case 1: chip->master_volume = kctl; kctl->private_free = snd_opl3sa2_master_free; break;
|
---|
531 | }
|
---|
532 | }
|
---|
533 | if (chip->version > 2) {
|
---|
534 | for (idx = 0; idx < ARRAY_SIZE(snd_opl3sa2_tone_controls); idx++)
|
---|
535 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_opl3sa2_tone_controls[idx], chip))) < 0)
|
---|
536 | return err;
|
---|
537 | }
|
---|
538 | return 0;
|
---|
539 | }
|
---|
540 |
|
---|
541 | /* Power Management support functions */
|
---|
542 | #ifdef CONFIG_PM
|
---|
543 | static int snd_opl3sa2_suspend(struct snd_card *card, pm_message_t state)
|
---|
544 | {
|
---|
545 | if (card) {
|
---|
546 | struct snd_opl3sa2 *chip = card->private_data;
|
---|
547 |
|
---|
548 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
|
---|
549 | chip->wss->suspend(chip->wss);
|
---|
550 | /* power down */
|
---|
551 | snd_opl3sa2_write(chip, OPL3SA2_PM_CTRL, OPL3SA2_PM_D3);
|
---|
552 | }
|
---|
553 |
|
---|
554 | return 0;
|
---|
555 | }
|
---|
556 |
|
---|
557 | static int snd_opl3sa2_resume(struct snd_card *card)
|
---|
558 | {
|
---|
559 | struct snd_opl3sa2 *chip;
|
---|
560 | int i;
|
---|
561 |
|
---|
562 | if (!card)
|
---|
563 | return 0;
|
---|
564 |
|
---|
565 | chip = card->private_data;
|
---|
566 | /* power up */
|
---|
567 | snd_opl3sa2_write(chip, OPL3SA2_PM_CTRL, OPL3SA2_PM_D0);
|
---|
568 |
|
---|
569 | /* restore registers */
|
---|
570 | for (i = 2; i <= 0x0a; i++) {
|
---|
571 | if (i != OPL3SA2_IRQ_STATUS)
|
---|
572 | snd_opl3sa2_write(chip, i, chip->ctlregs[i]);
|
---|
573 | }
|
---|
574 | if (chip->version > 2) {
|
---|
575 | for (i = 0x12; i <= 0x16; i++)
|
---|
576 | snd_opl3sa2_write(chip, i, chip->ctlregs[i]);
|
---|
577 | }
|
---|
578 | /* restore wss */
|
---|
579 | chip->wss->resume(chip->wss);
|
---|
580 |
|
---|
581 | snd_power_change_state(card, SNDRV_CTL_POWER_D0);
|
---|
582 | return 0;
|
---|
583 | }
|
---|
584 | #endif /* CONFIG_PM */
|
---|
585 |
|
---|
586 | #ifdef CONFIG_PNP
|
---|
587 | static int snd_opl3sa2_pnp(int dev, struct snd_opl3sa2 *chip,
|
---|
588 | struct pnp_dev *pdev)
|
---|
589 | {
|
---|
590 | if (pnp_activate_dev(pdev) < 0) {
|
---|
591 | snd_printk(KERN_ERR "PnP configure failure (out of resources?)\n");
|
---|
592 | return -EBUSY;
|
---|
593 | }
|
---|
594 | sb_port[dev] = pnp_port_start(pdev, 0);
|
---|
595 | wss_port[dev] = pnp_port_start(pdev, 1);
|
---|
596 | fm_port[dev] = pnp_port_start(pdev, 2);
|
---|
597 | midi_port[dev] = pnp_port_start(pdev, 3);
|
---|
598 | port[dev] = pnp_port_start(pdev, 4);
|
---|
599 | dma1[dev] = pnp_dma(pdev, 0);
|
---|
600 | dma2[dev] = pnp_dma(pdev, 1);
|
---|
601 | irq[dev] = pnp_irq(pdev, 0);
|
---|
602 | snd_printdd("%sPnP OPL3-SA: sb port=0x%lx, wss port=0x%lx, fm port=0x%lx, midi port=0x%lx\n",
|
---|
603 | pnp_device_is_pnpbios(pdev) ? "BIOS" : "ISA", sb_port[dev], wss_port[dev], fm_port[dev], midi_port[dev]);
|
---|
604 | snd_printdd("%sPnP OPL3-SA: control port=0x%lx, dma1=%i, dma2=%i, irq=%i\n",
|
---|
605 | pnp_device_is_pnpbios(pdev) ? "BIOS" : "ISA", port[dev], dma1[dev], dma2[dev], irq[dev]);
|
---|
606 | return 0;
|
---|
607 | }
|
---|
608 | #endif /* CONFIG_PNP */
|
---|
609 |
|
---|
610 | static void snd_opl3sa2_free(struct snd_card *card)
|
---|
611 | {
|
---|
612 | struct snd_opl3sa2 *chip = card->private_data;
|
---|
613 | if (chip->irq >= 0)
|
---|
614 | free_irq(chip->irq, card);
|
---|
615 | release_and_free_resource(chip->res_port);
|
---|
616 | }
|
---|
617 |
|
---|
618 | static int snd_opl3sa2_card_new(struct device *pdev, int dev,
|
---|
619 | struct snd_card **cardp)
|
---|
620 | {
|
---|
621 | struct snd_card *card;
|
---|
622 | struct snd_opl3sa2 *chip;
|
---|
623 | int err;
|
---|
624 |
|
---|
625 | err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
|
---|
626 | sizeof(struct snd_opl3sa2), &card);
|
---|
627 | if (err < 0)
|
---|
628 | return err;
|
---|
629 | strcpy(card->driver, "OPL3SA2");
|
---|
630 | strcpy(card->shortname, "Yamaha OPL3-SA");
|
---|
631 | chip = card->private_data;
|
---|
632 | spin_lock_init(&chip->reg_lock);
|
---|
633 | chip->irq = -1;
|
---|
634 | card->private_free = snd_opl3sa2_free;
|
---|
635 | *cardp = card;
|
---|
636 | return 0;
|
---|
637 | }
|
---|
638 |
|
---|
639 | static int snd_opl3sa2_probe(struct snd_card *card, int dev)
|
---|
640 | {
|
---|
641 | int xirq, xdma1, xdma2;
|
---|
642 | struct snd_opl3sa2 *chip;
|
---|
643 | struct snd_wss *wss;
|
---|
644 | struct snd_opl3 *opl3;
|
---|
645 | int err;
|
---|
646 |
|
---|
647 | /* initialise this card from supplied (or default) parameter*/
|
---|
648 | chip = card->private_data;
|
---|
649 | chip->ymode = opl3sa3_ymode[dev] & 0x03 ;
|
---|
650 | chip->port = port[dev];
|
---|
651 | xirq = irq[dev];
|
---|
652 | xdma1 = dma1[dev];
|
---|
653 | xdma2 = dma2[dev];
|
---|
654 | if (xdma2 < 0)
|
---|
655 | chip->single_dma = 1;
|
---|
656 | err = snd_opl3sa2_detect(card);
|
---|
657 | if (err < 0)
|
---|
658 | return err;
|
---|
659 | err = request_irq(xirq, snd_opl3sa2_interrupt, 0,
|
---|
660 | "OPL3-SA2", card);
|
---|
661 | if (err) {
|
---|
662 | snd_printk(KERN_ERR PFX "can't grab IRQ %d\n", xirq);
|
---|
663 | return -ENODEV;
|
---|
664 | }
|
---|
665 | chip->irq = xirq;
|
---|
666 | card->sync_irq = chip->irq;
|
---|
667 | err = snd_wss_create(card,
|
---|
668 | wss_port[dev] + 4, -1,
|
---|
669 | xirq, xdma1, xdma2,
|
---|
670 | WSS_HW_OPL3SA2, WSS_HWSHARE_IRQ, &wss);
|
---|
671 | if (err < 0) {
|
---|
672 | snd_printd("Oops, WSS not detected at 0x%lx\n", wss_port[dev] + 4);
|
---|
673 | return err;
|
---|
674 | }
|
---|
675 | chip->wss = wss;
|
---|
676 | err = snd_wss_pcm(wss, 0);
|
---|
677 | if (err < 0)
|
---|
678 | return err;
|
---|
679 | err = snd_wss_mixer(wss);
|
---|
680 | if (err < 0)
|
---|
681 | return err;
|
---|
682 | err = snd_opl3sa2_mixer(card);
|
---|
683 | if (err < 0)
|
---|
684 | return err;
|
---|
685 | err = snd_wss_timer(wss, 0);
|
---|
686 | if (err < 0)
|
---|
687 | return err;
|
---|
688 | if (fm_port[dev] >= 0x340 && fm_port[dev] < 0x400) {
|
---|
689 | if ((err = snd_opl3_create(card, fm_port[dev],
|
---|
690 | fm_port[dev] + 2,
|
---|
691 | OPL3_HW_OPL3, 0, &opl3)) < 0)
|
---|
692 | return err;
|
---|
693 | if ((err = snd_opl3_timer_new(opl3, 1, 2)) < 0)
|
---|
694 | return err;
|
---|
695 | if ((err = snd_opl3_hwdep_new(opl3, 0, 1, &chip->synth)) < 0)
|
---|
696 | return err;
|
---|
697 | }
|
---|
698 | if (midi_port[dev] >= 0x300 && midi_port[dev] < 0x340) {
|
---|
699 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_OPL3SA2,
|
---|
700 | midi_port[dev],
|
---|
701 | MPU401_INFO_IRQ_HOOK, -1,
|
---|
702 | &chip->rmidi)) < 0)
|
---|
703 | return err;
|
---|
704 | }
|
---|
705 | sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
|
---|
706 | card->shortname, chip->port, xirq, xdma1);
|
---|
707 | if (xdma2 >= 0)
|
---|
708 | sprintf(card->longname + strlen(card->longname), "&%d", xdma2);
|
---|
709 |
|
---|
710 | return snd_card_register(card);
|
---|
711 | }
|
---|
712 |
|
---|
713 | #ifdef CONFIG_PNP
|
---|
714 | static int snd_opl3sa2_pnp_detect(struct pnp_dev *pdev,
|
---|
715 | const struct pnp_device_id *id)
|
---|
716 | {
|
---|
717 | static int dev;
|
---|
718 | int err;
|
---|
719 | struct snd_card *card;
|
---|
720 |
|
---|
721 | if (pnp_device_is_isapnp(pdev))
|
---|
722 | return -ENOENT; /* we have another procedure - card */
|
---|
723 | for (; dev < SNDRV_CARDS; dev++) {
|
---|
724 | if (enable[dev] && isapnp[dev])
|
---|
725 | break;
|
---|
726 | }
|
---|
727 | if (dev >= SNDRV_CARDS)
|
---|
728 | return -ENODEV;
|
---|
729 |
|
---|
730 | err = snd_opl3sa2_card_new(&pdev->dev, dev, &card);
|
---|
731 | if (err < 0)
|
---|
732 | return err;
|
---|
733 | if ((err = snd_opl3sa2_pnp(dev, card->private_data, pdev)) < 0) {
|
---|
734 | snd_card_free(card);
|
---|
735 | return err;
|
---|
736 | }
|
---|
737 | if ((err = snd_opl3sa2_probe(card, dev)) < 0) {
|
---|
738 | snd_card_free(card);
|
---|
739 | return err;
|
---|
740 | }
|
---|
741 | pnp_set_drvdata(pdev, card);
|
---|
742 | dev++;
|
---|
743 | return 0;
|
---|
744 | }
|
---|
745 |
|
---|
746 | static void snd_opl3sa2_pnp_remove(struct pnp_dev *pdev)
|
---|
747 | {
|
---|
748 | snd_card_free(pnp_get_drvdata(pdev));
|
---|
749 | }
|
---|
750 |
|
---|
751 | #ifdef CONFIG_PM
|
---|
752 | static int snd_opl3sa2_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
|
---|
753 | {
|
---|
754 | return snd_opl3sa2_suspend(pnp_get_drvdata(pdev), state);
|
---|
755 | }
|
---|
756 | static int snd_opl3sa2_pnp_resume(struct pnp_dev *pdev)
|
---|
757 | {
|
---|
758 | return snd_opl3sa2_resume(pnp_get_drvdata(pdev));
|
---|
759 | }
|
---|
760 | #endif
|
---|
761 |
|
---|
762 | static struct pnp_driver opl3sa2_pnp_driver = {
|
---|
763 | .name = "snd-opl3sa2-pnpbios",
|
---|
764 | .id_table = snd_opl3sa2_pnpbiosids,
|
---|
765 | .probe = snd_opl3sa2_pnp_detect,
|
---|
766 | .remove = snd_opl3sa2_pnp_remove,
|
---|
767 | #ifdef CONFIG_PM
|
---|
768 | .suspend = snd_opl3sa2_pnp_suspend,
|
---|
769 | .resume = snd_opl3sa2_pnp_resume,
|
---|
770 | #endif
|
---|
771 | };
|
---|
772 |
|
---|
773 | static int snd_opl3sa2_pnp_cdetect(struct pnp_card_link *pcard,
|
---|
774 | const struct pnp_card_device_id *id)
|
---|
775 | {
|
---|
776 | static int dev;
|
---|
777 | struct pnp_dev *pdev;
|
---|
778 | int err;
|
---|
779 | struct snd_card *card;
|
---|
780 |
|
---|
781 | pdev = pnp_request_card_device(pcard, id->devs[0].id, NULL);
|
---|
782 | if (pdev == NULL) {
|
---|
783 | snd_printk(KERN_ERR PFX "can't get pnp device from id '%s'\n",
|
---|
784 | id->devs[0].id);
|
---|
785 | return -EBUSY;
|
---|
786 | }
|
---|
787 | for (; dev < SNDRV_CARDS; dev++) {
|
---|
788 | if (enable[dev] && isapnp[dev])
|
---|
789 | break;
|
---|
790 | }
|
---|
791 | if (dev >= SNDRV_CARDS)
|
---|
792 | return -ENODEV;
|
---|
793 |
|
---|
794 | err = snd_opl3sa2_card_new(&pdev->dev, dev, &card);
|
---|
795 | if (err < 0)
|
---|
796 | return err;
|
---|
797 | if ((err = snd_opl3sa2_pnp(dev, card->private_data, pdev)) < 0) {
|
---|
798 | snd_card_free(card);
|
---|
799 | return err;
|
---|
800 | }
|
---|
801 | if ((err = snd_opl3sa2_probe(card, dev)) < 0) {
|
---|
802 | snd_card_free(card);
|
---|
803 | return err;
|
---|
804 | }
|
---|
805 | pnp_set_card_drvdata(pcard, card);
|
---|
806 | dev++;
|
---|
807 | return 0;
|
---|
808 | }
|
---|
809 |
|
---|
810 | static void snd_opl3sa2_pnp_cremove(struct pnp_card_link *pcard)
|
---|
811 | {
|
---|
812 | snd_card_free(pnp_get_card_drvdata(pcard));
|
---|
813 | pnp_set_card_drvdata(pcard, NULL);
|
---|
814 | }
|
---|
815 |
|
---|
816 | #ifdef CONFIG_PM
|
---|
817 | static int snd_opl3sa2_pnp_csuspend(struct pnp_card_link *pcard, pm_message_t state)
|
---|
818 | {
|
---|
819 | return snd_opl3sa2_suspend(pnp_get_card_drvdata(pcard), state);
|
---|
820 | }
|
---|
821 | static int snd_opl3sa2_pnp_cresume(struct pnp_card_link *pcard)
|
---|
822 | {
|
---|
823 | return snd_opl3sa2_resume(pnp_get_card_drvdata(pcard));
|
---|
824 | }
|
---|
825 | #endif
|
---|
826 |
|
---|
827 | static struct pnp_card_driver opl3sa2_pnpc_driver = {
|
---|
828 | .flags = PNP_DRIVER_RES_DISABLE,
|
---|
829 | .name = "snd-opl3sa2-cpnp",
|
---|
830 | .id_table = snd_opl3sa2_pnpids,
|
---|
831 | .probe = snd_opl3sa2_pnp_cdetect,
|
---|
832 | .remove = snd_opl3sa2_pnp_cremove,
|
---|
833 | #ifdef CONFIG_PM
|
---|
834 | .suspend = snd_opl3sa2_pnp_csuspend,
|
---|
835 | .resume = snd_opl3sa2_pnp_cresume,
|
---|
836 | #endif
|
---|
837 | };
|
---|
838 | #endif /* CONFIG_PNP */
|
---|
839 |
|
---|
840 | static int snd_opl3sa2_isa_match(struct device *pdev,
|
---|
841 | unsigned int dev)
|
---|
842 | {
|
---|
843 | if (!enable[dev])
|
---|
844 | return 0;
|
---|
845 | #ifdef CONFIG_PNP
|
---|
846 | if (isapnp[dev])
|
---|
847 | return 0;
|
---|
848 | #endif
|
---|
849 | if (port[dev] == SNDRV_AUTO_PORT) {
|
---|
850 | snd_printk(KERN_ERR PFX "specify port\n");
|
---|
851 | return 0;
|
---|
852 | }
|
---|
853 | if (wss_port[dev] == SNDRV_AUTO_PORT) {
|
---|
854 | snd_printk(KERN_ERR PFX "specify wss_port\n");
|
---|
855 | return 0;
|
---|
856 | }
|
---|
857 | if (fm_port[dev] == SNDRV_AUTO_PORT) {
|
---|
858 | snd_printk(KERN_ERR PFX "specify fm_port\n");
|
---|
859 | return 0;
|
---|
860 | }
|
---|
861 | if (midi_port[dev] == SNDRV_AUTO_PORT) {
|
---|
862 | snd_printk(KERN_ERR PFX "specify midi_port\n");
|
---|
863 | return 0;
|
---|
864 | }
|
---|
865 | return 1;
|
---|
866 | }
|
---|
867 |
|
---|
868 | static int snd_opl3sa2_isa_probe(struct device *pdev,
|
---|
869 | unsigned int dev)
|
---|
870 | {
|
---|
871 | struct snd_card *card;
|
---|
872 | int err;
|
---|
873 |
|
---|
874 | err = snd_opl3sa2_card_new(pdev, dev, &card);
|
---|
875 | if (err < 0)
|
---|
876 | return err;
|
---|
877 | if ((err = snd_opl3sa2_probe(card, dev)) < 0) {
|
---|
878 | snd_card_free(card);
|
---|
879 | return err;
|
---|
880 | }
|
---|
881 | dev_set_drvdata(pdev, card);
|
---|
882 | return 0;
|
---|
883 | }
|
---|
884 |
|
---|
885 | static int snd_opl3sa2_isa_remove(struct device *devptr,
|
---|
886 | unsigned int dev)
|
---|
887 | {
|
---|
888 | snd_card_free(dev_get_drvdata(devptr));
|
---|
889 | return 0;
|
---|
890 | }
|
---|
891 |
|
---|
892 | #ifdef CONFIG_PM
|
---|
893 | static int snd_opl3sa2_isa_suspend(struct device *dev, unsigned int n,
|
---|
894 | pm_message_t state)
|
---|
895 | {
|
---|
896 | return snd_opl3sa2_suspend(dev_get_drvdata(dev), state);
|
---|
897 | }
|
---|
898 |
|
---|
899 | static int snd_opl3sa2_isa_resume(struct device *dev, unsigned int n)
|
---|
900 | {
|
---|
901 | return snd_opl3sa2_resume(dev_get_drvdata(dev));
|
---|
902 | }
|
---|
903 | #endif
|
---|
904 |
|
---|
905 | #define DEV_NAME "opl3sa2"
|
---|
906 |
|
---|
907 | static struct isa_driver snd_opl3sa2_isa_driver = {
|
---|
908 | .match = snd_opl3sa2_isa_match,
|
---|
909 | .probe = snd_opl3sa2_isa_probe,
|
---|
910 | .remove = snd_opl3sa2_isa_remove,
|
---|
911 | #ifdef CONFIG_PM
|
---|
912 | .suspend = snd_opl3sa2_isa_suspend,
|
---|
913 | .resume = snd_opl3sa2_isa_resume,
|
---|
914 | #endif
|
---|
915 | .driver = {
|
---|
916 | .name = DEV_NAME
|
---|
917 | },
|
---|
918 | };
|
---|
919 |
|
---|
920 | static int __init alsa_card_opl3sa2_init(void)
|
---|
921 | {
|
---|
922 | int err;
|
---|
923 |
|
---|
924 | err = isa_register_driver(&snd_opl3sa2_isa_driver, SNDRV_CARDS);
|
---|
925 | #ifdef CONFIG_PNP
|
---|
926 | if (!err)
|
---|
927 | isa_registered = 1;
|
---|
928 |
|
---|
929 | err = pnp_register_driver(&opl3sa2_pnp_driver);
|
---|
930 | if (!err)
|
---|
931 | pnp_registered = 1;
|
---|
932 |
|
---|
933 | err = pnp_register_card_driver(&opl3sa2_pnpc_driver);
|
---|
934 | if (!err)
|
---|
935 | pnpc_registered = 1;
|
---|
936 |
|
---|
937 | if (isa_registered || pnp_registered)
|
---|
938 | err = 0;
|
---|
939 | #endif
|
---|
940 | return err;
|
---|
941 | }
|
---|
942 |
|
---|
943 | static void __exit alsa_card_opl3sa2_exit(void)
|
---|
944 | {
|
---|
945 | #ifdef CONFIG_PNP
|
---|
946 | if (pnpc_registered)
|
---|
947 | pnp_unregister_card_driver(&opl3sa2_pnpc_driver);
|
---|
948 | if (pnp_registered)
|
---|
949 | pnp_unregister_driver(&opl3sa2_pnp_driver);
|
---|
950 | if (isa_registered)
|
---|
951 | #endif
|
---|
952 | isa_unregister_driver(&snd_opl3sa2_isa_driver);
|
---|
953 | }
|
---|
954 |
|
---|
955 | module_init(alsa_card_opl3sa2_init)
|
---|
956 | module_exit(alsa_card_opl3sa2_exit)
|
---|