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