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