source: GPL/trunk/alsa-kernel/isa/opl3sa2.c@ 135

Last change on this file since 135 was 135, checked in by stevenhl, 18 years ago

Get rid of spurious warnings

File size: 28.6 KB
Line 
1/*
2 * Driver for Yamaha OPL3-SA[2,3] soundcards
3 * Copyright (c) by Jaroslav Kysela <perex@suse.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., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 */
21
22#define SNDRV_MAIN_OBJECT_FILE
23#include <sound/driver.h>
24#include <sound/cs4231.h>
25#include <sound/mpu401.h>
26#include <sound/opl3.h>
27#define SNDRV_GET_ID
28#include <sound/initval.h>
29
30EXPORT_NO_SYMBOLS;
31MODULE_DESCRIPTION("Yamaha OPL3SA2+");
32MODULE_CLASSES("{sound}");
33MODULE_DEVICES("{{Yamaha,YMF719E-S},"
34 "{Genius,Sound Maker 3DX},"
35 "{Yamaha,OPL3SA3},"
36 "{Intel,AL440LX sound},"
37 "{NeoMagic,MagicWave 3DX}}");
38
39static int snd_index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
40static char *snd_id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
41static int snd_enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
42#ifdef __ISAPNP__
43#ifdef TARGET_OS2
44static int snd_isapnp[SNDRV_CARDS] = {1,1,1,1,1,1,1,1};
45#else
46static int snd_isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
47#endif
48#endif
49static long snd_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0xf86,0x370,0x100 */
50static long snd_sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */
51static long snd_wss_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* 0x530,0xe80,0xf40,0x604 */
52static long snd_fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x388 */
53static long snd_midi_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* 0x330,0x300 */
54static int snd_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 0,1,3,5,9,11,12,15 */
55static int snd_dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
56static int snd_dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
57#ifdef TARGET_OS2
58static int snd_opl3sa3_ymode[SNDRV_CARDS] = { 0,0,0,0,0,0,0,0 }; /* 0,1,2,3 */ /*SL Added*/
59#else
60static int snd_opl3sa3_ymode[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 0 }; /* 0,1,2,3 */ /*SL Added*/
61#endif
62
63MODULE_PARM(snd_index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
64MODULE_PARM_DESC(snd_index, "Index value for OPL3-SA soundcard.");
65MODULE_PARM_SYNTAX(snd_index, SNDRV_INDEX_DESC);
66MODULE_PARM(snd_id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
67MODULE_PARM_DESC(snd_id, "ID string for OPL3-SA soundcard.");
68MODULE_PARM_SYNTAX(snd_id, SNDRV_ID_DESC);
69MODULE_PARM(snd_enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
70MODULE_PARM_DESC(snd_enable, "Enable OPL3-SA soundcard.");
71MODULE_PARM_SYNTAX(snd_enable, SNDRV_ENABLE_DESC);
72MODULE_PARM(snd_isapnp, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
73MODULE_PARM_DESC(snd_isapnp, "ISA PnP detection for specified soundcard.");
74MODULE_PARM_SYNTAX(snd_isapnp, SNDRV_ISAPNP_DESC);
75MODULE_PARM(snd_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
76MODULE_PARM_DESC(snd_port, "Port # for OPL3-SA driver.");
77MODULE_PARM_SYNTAX(snd_port, SNDRV_ENABLED ",allows:{{0xf86},{0x370},{0x100}},dialog:list");
78MODULE_PARM(snd_sb_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
79MODULE_PARM_DESC(snd_sb_port, "SB port # for OPL3-SA driver.");
80MODULE_PARM_SYNTAX(snd_sb_port, SNDRV_ENABLED ",allows:{{0x220},{0x240},{0x260}},dialog:list");
81MODULE_PARM(snd_wss_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
82MODULE_PARM_DESC(snd_wss_port, "WSS port # for OPL3-SA driver.");
83MODULE_PARM_SYNTAX(snd_wss_port, SNDRV_ENABLED ",allows:{{0x530},{0xe80},{0xf40},{0x604}},dialog:list");
84MODULE_PARM(snd_fm_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
85MODULE_PARM_DESC(snd_fm_port, "FM port # for OPL3-SA driver.");
86MODULE_PARM_SYNTAX(snd_fm_port, SNDRV_ENABLED ",allows:{{0x388}},dialog:list");
87MODULE_PARM(snd_midi_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
88MODULE_PARM_DESC(snd_midi_port, "MIDI port # for OPL3-SA driver.");
89MODULE_PARM_SYNTAX(snd_midi_port, SNDRV_ENABLED ",allows:{{0x330},{0x300}},dialog:list");
90MODULE_PARM(snd_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
91MODULE_PARM_DESC(snd_irq, "IRQ # for OPL3-SA driver.");
92MODULE_PARM_SYNTAX(snd_irq, SNDRV_ENABLED ",allows:{{0},{1},{3},{5},{9},{11},{12},{15}},dialog:list");
93MODULE_PARM(snd_dma1, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
94MODULE_PARM_DESC(snd_dma1, "DMA1 # for OPL3-SA driver.");
95MODULE_PARM_SYNTAX(snd_dma1, SNDRV_ENABLED ",allows:{{1},{3},{5},{6},{7}},dialog:list");
96MODULE_PARM(snd_dma2, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
97MODULE_PARM_DESC(snd_dma2, "DMA2 # for OPL3-SA driver.");
98MODULE_PARM_SYNTAX(snd_dma2, SNDRV_ENABLED ",allows:{{1},{3},{5},{6},{7}},dialog:list");
99MODULE_PARM(snd_opl3sa3_ymode, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); /* SL Added */
100MODULE_PARM_DESC(snd_opl3sa3_ymode, "Speaker size selection for 3D Enhancement mode: Desktop/Large Notebook/Small Notebook/HiFi.");
101MODULE_PARM_SYNTAX(snd_opl3sa3_ymode, SNDRV_ENABLED ",allows:{{0,3}},dialog:list"); /* SL Added */
102
103struct snd_opl3sa {
104 snd_card_t *card;
105 int version; /* 2 or 3 */
106 unsigned long port; /* control port */
107 struct resource *res_port; /* control port resource */
108 int irq;
109 int single_dma;
110 spinlock_t reg_lock;
111 snd_hwdep_t *synth;
112 snd_rawmidi_t *rmidi;
113 cs4231_t *cs4231;
114#ifdef __ISAPNP__
115 struct isapnp_dev *dev;
116#endif
117 unsigned char ctlregs[0x20];
118 int ymode; /* SL added */
119 snd_kcontrol_t *master_switch;
120 snd_kcontrol_t *master_volume;
121};
122
123static snd_card_t *snd_opl3sa_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
124
125#ifdef __ISAPNP__
126
127static struct isapnp_card *snd_opl3sa2_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
128static const struct isapnp_card_id *snd_opl3sa2_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
129
130#ifdef TARGET_OS2
131#define ISAPNP_OPL3SA2(_va, _vb, _vc, _device, _function) \
132 { \
133 0, ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
134 { ISAPNP_DEVICE_ID(_va, _vb, _vc, _function), } \
135 }
136#else
137#define ISAPNP_OPL3SA2(_va, _vb, _vc, _device, _function) \
138 { \
139 ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
140 devs : { ISAPNP_DEVICE_ID(_va, _vb, _vc, _function), } \
141 }
142#endif
143
144static struct isapnp_card_id snd_opl3sa2_pnpids[] __devinitdata = {
145 /* Yamaha YMF719E-S (Genius Sound Maker 3DX) */
146 ISAPNP_OPL3SA2('Y','M','H',0x0020,0x0021),
147 /* Yamaha OPL3-SA3 (integrated on Intel's Pentium II AL440LX motherboard) */
148 ISAPNP_OPL3SA2('Y','M','H',0x0030,0x0021),
149 /* ??? */
150 ISAPNP_OPL3SA2('Y','M','H',0x0800,0x0021),
151 /* NeoMagic MagicWave 3DX */
152 ISAPNP_OPL3SA2('N','M','X',0x2200,0x2210),
153 /* --- */
154 { ISAPNP_CARD_END, } /* end */
155};
156
157ISAPNP_CARD_TABLE(snd_opl3sa2_pnpids);
158
159#endif /* __ISAPNP__ */
160
161static unsigned char snd_opl3sa_read(unsigned long port, unsigned char reg)
162{
163 u32 flags;
164 unsigned char result;
165
166 save_flags(&flags); // 12 Jun 07 SHL
167 cli();
168#if 0
169 outb(0x1d, port); /* password */
170 printk("read [0x%lx] = 0x%x\n", port, inb(port));
171#endif
172 outb(reg, port); /* register */
173 result = inb(port + 1);
174 restore_flags(flags);
175#if 0
176 printk("read [0x%lx] = 0x%x [0x%x]\n", port, result, inb(port));
177#endif
178 return result;
179}
180
181static void snd_opl3sa_write(unsigned long port,
182 unsigned char reg, unsigned char value)
183{
184 u32 flags;
185
186 save_flags(&flags);
187 cli();
188#if 0
189 outb(0x1d, port); /* password */
190#endif
191 outb(reg, port); /* register */
192 outb(value, port + 1);
193 restore_flags(flags);
194}
195
196static int __init snd_opl3sa_detect(struct snd_opl3sa *oplcard)
197{
198 snd_card_t *card;
199 unsigned long port;
200 unsigned char tmp, tmp1;
201 char str[2];
202
203 card = oplcard->card;
204 port = oplcard->port;
205 if ((oplcard->res_port = request_region(port, 2, "OPL3-SA control")) == NULL)
206 return -EBUSY;
207 // snd_printk("REG 0A = 0x%x\n", snd_opl3sa_read(port, 0x0a));
208 oplcard->version = 0;
209 tmp = snd_opl3sa_read(port, 0x0a);
210 if (tmp == 0xff) {
211 snd_printd("OPL3-SA [0x%lx] detect = 0x%x\n", port, tmp);
212 return -ENODEV;
213 }
214 switch (tmp & 0x07) {
215 case 0x01:
216 oplcard->version = 2;
217 break;
218 default:
219 oplcard->version = 3;
220 /* 0x02 - standard */
221 /* 0x03 - YM715B */
222 /* 0x04 - YM719 - OPL-SA4? */
223 /* 0x05 - OPL3-SA3 - Libretto 100 */
224 break;
225 }
226 str[0] = oplcard->version + '0';
227 str[1] = 0;
228 strcat(card->shortname, str);
229 snd_opl3sa_write(port, 0x0a, tmp ^ 7);
230 if ((tmp1 = snd_opl3sa_read(port, 0x0a)) != tmp) {
231 snd_printd("OPL3-SA [0x%lx] detect (1) = 0x%x (0x%x)\n", port, tmp, tmp1);
232 return -ENODEV;
233 }
234 /* try if the MIC register is accesible */
235 tmp = snd_opl3sa_read(port, 0x09);
236 snd_opl3sa_write(port, 0x09, 0x8a);
237 if (((tmp1 = snd_opl3sa_read(port, 0x09)) & 0x9f) != 0x8a) {
238 snd_printd("OPL3-SA [0x%lx] detect (2) = 0x%x (0x%x)\n", port, tmp, tmp1);
239 return -ENODEV;
240 }
241 snd_opl3sa_write(port, 0x09, 0x9f);
242 /* initialization */
243 snd_opl3sa_write(port, 0x01, 0x00); /* Power Management - default */
244 if (oplcard->version > 2) { /* SL Added */
245 snd_opl3sa_write(port, 0x02, (oplcard->ymode << 4)); /* SL Modified - System Control - ymode is bits 4&5 (of 0 to 7) on all but opl3sa2 versions */
246 } else { /* SL Added */
247 snd_opl3sa_write(port, 0x02, 0x00); /* SL Modified - System Control - default for opl3sa2 versions */
248 } /* SL Added */
249 snd_opl3sa_write(port, 0x03, 0x0d); /* Interrupt Channel Configuration - IRQ A = OPL3 + MPU + WSS */
250 if (oplcard->single_dma) {
251 snd_opl3sa_write(port, 0x06, 0x03); /* DMA Configuration - DMA A = WSS-R + WSS-P */
252 } else {
253 snd_opl3sa_write(port, 0x06, 0x21); /* DMA Configuration - DMA B = WSS-R, DMA A = WSS-P */
254 }
255 snd_opl3sa_write(port, 0x0a, 0x80 | (tmp & 7)); /* Miscellaneous - default */
256 if (oplcard->version > 2) {
257 snd_opl3sa_write(port, 0x12, 0x00); /* Digital Block Partial Power Down - default */
258 snd_opl3sa_write(port, 0x13, 0x00); /* Analog Block Partial Power Down - default */
259 }
260 return 0;
261}
262
263static int snd_opl3sa_interrupt(int irq, void *dev_id, struct pt_regs *regs)
264{
265 unsigned short status;
266 struct snd_opl3sa *oplcard = (struct snd_opl3sa *) dev_id;
267
268 if (oplcard == NULL || oplcard->card == NULL)
269 return 0;
270
271 spin_lock(&oplcard->reg_lock);
272 outb(0x04, oplcard->port); /* register - Interrupt IRQ-A status */
273 status = inb(oplcard->port + 1);
274 spin_unlock(&oplcard->reg_lock);
275
276 if (status & 0x20)
277 snd_opl3_interrupt(oplcard->synth);
278
279 if ((status & 0x10) && oplcard->rmidi != NULL)
280 snd_mpu401_uart_interrupt(irq, oplcard->rmidi->private_data, regs);
281
282 if (status & 0x07) /* TI,CI,PI */
283 snd_cs4231_interrupt(irq, oplcard->cs4231, regs);
284
285 if (status & 0x40) {
286 /* reading from Master Lch register at 0x07 clears this bit */
287 snd_opl3sa_read(oplcard->port, 0x08);
288 snd_opl3sa_read(oplcard->port, 0x07);
289 snd_ctl_notify(oplcard->card, SNDRV_CTL_EVENT_MASK_VALUE, &oplcard->master_switch->id);
290 snd_ctl_notify(oplcard->card, SNDRV_CTL_EVENT_MASK_VALUE, &oplcard->master_volume->id);
291 }
292 return 0;
293}
294
295#ifdef TARGET_OS2
296#define OPL3SA_SINGLE(xname, xindex, reg, shift, mask, invert) \
297{ SNDRV_CTL_ELEM_IFACE_MIXER, 0, 0, xname, xindex, \
298 0, 0, snd_opl3sa_info_single, \
299 snd_opl3sa_get_single, snd_opl3sa_put_single, \
300 0, \
301 reg | (shift << 8) | (mask << 16) | (invert << 24) }
302
303#else
304#define OPL3SA_SINGLE(xname, xindex, reg, shift, mask, invert) \
305{ iface: SNDRV_CTL_ELEM_IFACE_MIXER, name: xname, index: xindex, \
306 info: snd_opl3sa_info_single, \
307 get: snd_opl3sa_get_single, put: snd_opl3sa_put_single, \
308 private_value: reg | (shift << 8) | (mask << 16) | (invert << 24) }
309#endif
310
311static int snd_opl3sa_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
312{
313 int mask = (kcontrol->private_value >> 16) & 0xff;
314
315 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
316 uinfo->count = 1;
317 uinfo->value.integer.min = 0;
318 uinfo->value.integer.max = mask;
319 return 0;
320}
321
322int snd_opl3sa_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
323{
324 struct snd_opl3sa *oplcard = (struct snd_opl3sa *)_snd_kcontrol_chip(kcontrol);
325 unsigned long flags;
326 int reg = kcontrol->private_value & 0xff;
327 int shift = (kcontrol->private_value >> 8) & 0xff;
328 int mask = (kcontrol->private_value >> 16) & 0xff;
329 int invert = (kcontrol->private_value >> 24) & 0xff;
330
331 spin_lock_irqsave(&oplcard->reg_lock, flags);
332 ucontrol->value.integer.value[0] = (oplcard->ctlregs[reg] >> shift) & mask;
333 spin_unlock_irqrestore(&oplcard->reg_lock, flags);
334 if (invert)
335 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
336 return 0;
337}
338
339int snd_opl3sa_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
340{
341 struct snd_opl3sa *oplcard = (struct snd_opl3sa *)_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 int change;
348 unsigned short val, oval;
349
350 val = (ucontrol->value.integer.value[0] & mask);
351 if (invert)
352 val = mask - val;
353 val <<= shift;
354 spin_lock_irqsave(&oplcard->reg_lock, flags);
355 oval = oplcard->ctlregs[reg];
356 val = (oval & ~(mask << shift)) | val;
357 change = val != oval;
358 snd_opl3sa_write(oplcard->port, reg, oplcard->ctlregs[reg] = val);
359 spin_unlock_irqrestore(&oplcard->reg_lock, flags);
360 return change;
361}
362
363#ifdef TARGET_OS2
364#define OPL3SA_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
365{ SNDRV_CTL_ELEM_IFACE_MIXER, 0, 0, xname, xindex, \
366 0, 0, snd_opl3sa_info_double, \
367 snd_opl3sa_get_double, snd_opl3sa_put_double, \
368 0, \
369 left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
370
371#else
372#define OPL3SA_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
373{ iface: SNDRV_CTL_ELEM_IFACE_MIXER, name: xname, index: xindex, \
374 info: snd_opl3sa_info_double, \
375 get: snd_opl3sa_get_double, put: snd_opl3sa_put_double, \
376 private_value: left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
377#endif
378
379int snd_opl3sa_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
380{
381 int mask = (kcontrol->private_value >> 24) & 0xff;
382
383 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
384 uinfo->count = 2;
385 uinfo->value.integer.min = 0;
386 uinfo->value.integer.max = mask;
387 return 0;
388}
389
390int snd_opl3sa_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
391{
392 struct snd_opl3sa *oplcard = (struct snd_opl3sa *)_snd_kcontrol_chip(kcontrol);
393 unsigned long flags;
394 int left_reg = kcontrol->private_value & 0xff;
395 int right_reg = (kcontrol->private_value >> 8) & 0xff;
396 int shift_left = (kcontrol->private_value >> 16) & 0x07;
397 int shift_right = (kcontrol->private_value >> 19) & 0x07;
398 int mask = (kcontrol->private_value >> 24) & 0xff;
399 int invert = (kcontrol->private_value >> 22) & 1;
400
401 spin_lock_irqsave(&oplcard->reg_lock, flags);
402 ucontrol->value.integer.value[0] = (oplcard->ctlregs[left_reg] >> shift_left) & mask;
403 ucontrol->value.integer.value[1] = (oplcard->ctlregs[right_reg] >> shift_right) & mask;
404 spin_unlock_irqrestore(&oplcard->reg_lock, flags);
405 if (invert) {
406 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
407 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
408 }
409 return 0;
410}
411
412int snd_opl3sa_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
413{
414 struct snd_opl3sa *oplcard = (struct snd_opl3sa *)_snd_kcontrol_chip(kcontrol);
415 unsigned long flags;
416 int left_reg = kcontrol->private_value & 0xff;
417 int right_reg = (kcontrol->private_value >> 8) & 0xff;
418 int shift_left = (kcontrol->private_value >> 16) & 0x07;
419 int shift_right = (kcontrol->private_value >> 19) & 0x07;
420 int mask = (kcontrol->private_value >> 24) & 0xff;
421 int invert = (kcontrol->private_value >> 22) & 1;
422 int change;
423 unsigned short val1, val2, oval1, oval2;
424
425 val1 = ucontrol->value.integer.value[0] & mask;
426 val2 = ucontrol->value.integer.value[1] & mask;
427 if (invert) {
428 val1 = mask - val1;
429 val2 = mask - val2;
430 }
431 val1 <<= shift_left;
432 val2 <<= shift_right;
433 spin_lock_irqsave(&oplcard->reg_lock, flags);
434 if (left_reg != right_reg) {
435 oval1 = oplcard->ctlregs[left_reg];
436 oval2 = oplcard->ctlregs[right_reg];
437 val1 = (oval1 & ~(mask << shift_left)) | val1;
438 val2 = (oval2 & ~(mask << shift_right)) | val2;
439 change = val1 != oval1 || val2 != oval2;
440 snd_opl3sa_write(oplcard->port, left_reg, oplcard->ctlregs[left_reg] = val1);
441 snd_opl3sa_write(oplcard->port, right_reg, oplcard->ctlregs[right_reg] = val2);
442 } else {
443 oval1 = oplcard->ctlregs[left_reg];
444 val1 = (oval1 & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
445 change = val1 != oval1;
446 snd_opl3sa_write(oplcard->port, left_reg, oplcard->ctlregs[left_reg] = val1);
447 }
448 spin_unlock_irqrestore(&oplcard->reg_lock, flags);
449 return change;
450}
451
452#define OPL3SA_CONTROLS (sizeof(snd_opl3sa_controls)/sizeof(snd_kcontrol_new_t))
453
454static snd_kcontrol_new_t snd_opl3sa_controls[] = {
455OPL3SA_DOUBLE("Master Playback Switch", 0, 0x07, 0x08, 7, 7, 1, 1),
456OPL3SA_DOUBLE("Master Playback Volume", 0, 0x07, 0x08, 0, 0, 15, 1),
457OPL3SA_SINGLE("Mic Playback Switch", 0, 0x09, 7, 1, 1),
458OPL3SA_SINGLE("Mic Playback Volume", 0, 0x09, 0, 31, 1)
459};
460
461#define OPL3SA_TONE_CONTROLS (sizeof(snd_opl3sa_tone_controls)/sizeof(snd_kcontrol_new_t))
462
463static snd_kcontrol_new_t snd_opl3sa_tone_controls[] = {
464OPL3SA_DOUBLE("3D Control - Wide", 0, 0x14, 0x14, 4, 0, 7, 0),
465OPL3SA_DOUBLE("Tone Control - Bass", 0, 0x15, 0x15, 4, 0, 7, 0),
466OPL3SA_DOUBLE("Tone Control - Treble", 0, 0x16, 0x16, 4, 0, 7, 0)
467};
468
469static void snd_opl3sa_master_free(snd_kcontrol_t *kcontrol)
470{
471 struct snd_opl3sa *oplcard = (struct snd_opl3sa *)_snd_kcontrol_chip(kcontrol);
472
473 oplcard->master_switch = NULL;
474 oplcard->master_volume = NULL;
475}
476
477static int __init snd_opl3sa_mixer(struct snd_opl3sa *oplcard)
478{
479 snd_card_t *card = oplcard->card;
480 snd_ctl_elem_id_t id1, id2;
481 snd_kcontrol_t *kctl;
482 int idx, err;
483
484 memset(&id1, 0, sizeof(id1));
485 memset(&id2, 0, sizeof(id2));
486 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
487 /* reassign AUX0 to CD */
488 strcpy(id1.name, "Aux Playback Switch");
489 strcpy(id2.name, "CD Playback Switch");
490 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
491 return err;
492 strcpy(id1.name, "Aux Playback Volume");
493 strcpy(id2.name, "CD Playback Volume");
494 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
495 return err;
496 /* reassign AUX1 to FM */
497 strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
498 strcpy(id2.name, "FM Playback Switch");
499 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
500 return err;
501 strcpy(id1.name, "Aux Playback Volume");
502 strcpy(id2.name, "FM Playback Volume");
503 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
504 return err;
505 /* add OPL3SA2 controls */
506 for (idx = 0; idx < OPL3SA_CONTROLS; idx++) {
507 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_opl3sa_controls[idx], oplcard))) < 0)
508 return err;
509 switch (idx) {
510 case 0: oplcard->master_switch = kctl; kctl->private_free = snd_opl3sa_master_free; break;
511 case 1: oplcard->master_volume = kctl; kctl->private_free = snd_opl3sa_master_free; break;
512 }
513 }
514 if (oplcard->version > 2) {
515 for (idx = 0; idx < OPL3SA_TONE_CONTROLS; idx++)
516 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_opl3sa_tone_controls[idx], oplcard))) < 0)
517 return err;
518 }
519 return 0;
520}
521
522#ifdef __ISAPNP__
523static int __init snd_opl3sa_isapnp(int dev, struct snd_opl3sa *oplcard)
524{
525 const struct isapnp_card_id *id = snd_opl3sa2_isapnp_id[dev];
526 struct isapnp_card *card = snd_opl3sa2_isapnp_cards[dev];
527 struct isapnp_dev *pdev;
528
529 oplcard->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
530 if (oplcard->dev->active) {
531 oplcard->dev = NULL;
532 return -EBUSY;
533 }
534 /* PnP initialization */
535 pdev = oplcard->dev;
536 if (pdev->prepare(pdev)<0)
537 return -EAGAIN;
538 if (snd_sb_port[dev] != SNDRV_AUTO_PORT)
539 isapnp_resource_change(&pdev->resource[0], snd_sb_port[dev], 16);
540 if (snd_wss_port[dev] != SNDRV_AUTO_PORT)
541 isapnp_resource_change(&pdev->resource[1], snd_wss_port[dev], 8);
542 if (snd_fm_port[dev] != SNDRV_AUTO_PORT)
543 isapnp_resource_change(&pdev->resource[2], snd_fm_port[dev], 4);
544 if (snd_midi_port[dev] != SNDRV_AUTO_PORT)
545 isapnp_resource_change(&pdev->resource[3], snd_midi_port[dev], 2);
546 if (snd_port[dev] != SNDRV_AUTO_PORT)
547 isapnp_resource_change(&pdev->resource[4], snd_port[dev], 2);
548 if (snd_dma1[dev] != SNDRV_AUTO_DMA)
549 isapnp_resource_change(&pdev->dma_resource[0], snd_dma1[dev], 1);
550 if (snd_dma2[dev] != SNDRV_AUTO_DMA)
551 isapnp_resource_change(&pdev->dma_resource[1], snd_dma2[dev], 1);
552 if (snd_irq[dev] != SNDRV_AUTO_IRQ)
553 isapnp_resource_change(&pdev->irq_resource[0], snd_irq[dev], 1);
554 if (pdev->activate(pdev)<0) {
555 snd_printk("isapnp configure failure (out of resources?)\n");
556 return -EBUSY;
557 }
558 snd_sb_port[dev] = pdev->resource[0].start;
559 snd_wss_port[dev] = pdev->resource[1].start;
560 snd_fm_port[dev] = pdev->resource[2].start;
561 snd_midi_port[dev] = pdev->resource[3].start;
562 snd_port[dev] = pdev->resource[4].start;
563 snd_dma1[dev] = pdev->dma_resource[0].start;
564 snd_dma2[dev] = pdev->dma_resource[1].start;
565 snd_irq[dev] = pdev->irq_resource[0].start;
566 snd_printdd("isapnp OPL3-SA: sb port=0x%lx, wss port=0x%lx, fm port=0x%lx, midi port=0x%lx\n",
567 snd_sb_port[dev], snd_wss_port[dev], snd_fm_port[dev], snd_midi_port[dev]);
568 snd_printdd("isapnp OPL3-SA: control port=0x%lx, dma1=%i, dma2=%i, irq=%i\n",
569 snd_port[dev], snd_dma1[dev], snd_dma2[dev], snd_irq[dev]);
570 return 0;
571}
572
573static void snd_opl3sa_deactivate(struct snd_opl3sa *oplcard)
574{
575 if (oplcard->dev) {
576 oplcard->dev->deactivate(oplcard->dev);
577 oplcard->dev = NULL;
578 }
579}
580#endif /* __ISAPNP__ */
581
582static void snd_card_opl3sa2_free(snd_card_t *card)
583{
584 struct snd_opl3sa *acard = (struct snd_opl3sa *)card->private_data;
585
586 if (acard) {
587#ifdef __ISAPNP__
588 snd_opl3sa_deactivate(acard);
589#endif
590 if (acard->irq >= 0)
591 free_irq(acard->irq, (void *)acard);
592 if (acard->res_port)
593 release_resource(acard->res_port);
594 }
595}
596
597static int __init snd_opl3sa_probe(int dev)
598{
599 int irq, dma1, dma2;
600 snd_card_t *card;
601 struct snd_opl3sa *oplcard;
602 cs4231_t *cs4231;
603 opl3_t *opl3;
604 int err;
605
606#ifdef __ISAPNP__
607 if (!snd_isapnp[dev]) {
608#endif
609 if (snd_port[dev] == SNDRV_AUTO_PORT) {
610 snd_printk("specify snd_port\n");
611 return -EINVAL;
612 }
613 if (snd_wss_port[dev] == SNDRV_AUTO_PORT) {
614 snd_printk("specify snd_wss_port\n");
615 return -EINVAL;
616 }
617 if (snd_fm_port[dev] == SNDRV_AUTO_PORT) {
618 snd_printk("specify snd_fm_port\n");
619 return -EINVAL;
620 }
621 if (snd_midi_port[dev] == SNDRV_AUTO_PORT) {
622 snd_printk("specify snd_midi_port\n");
623 return -EINVAL;
624 }
625#ifdef __ISAPNP__
626 }
627#endif
628 card = snd_card_new(snd_index[dev], snd_id[dev], THIS_MODULE,
629 sizeof(struct snd_opl3sa));
630 if (card == NULL)
631 return -ENOMEM;
632 oplcard = (struct snd_opl3sa *)card->private_data;
633 oplcard->irq = -1;
634 card->private_free = snd_card_opl3sa2_free;
635 strcpy(card->driver, "OPL3SA2");
636 strcpy(card->shortname, "Yamaha OPL3-SA2");
637#ifdef __ISAPNP__
638 if (snd_isapnp[dev] && snd_opl3sa_isapnp(dev, oplcard) < 0) {
639 snd_card_free(card);
640 return -EBUSY;
641 }
642#endif
643 oplcard->ymode = snd_opl3sa3_ymode[dev] & 0x03 ; /* SL Added - initialise this card from supplied (or default) parameter*/
644 oplcard->card = card;
645 oplcard->port = snd_port[dev];
646 irq = snd_irq[dev];
647 dma1 = snd_dma1[dev];
648 dma2 = snd_dma2[dev];
649 if (dma2 < 0)
650 oplcard->single_dma = 1;
651 if ((snd_opl3sa_detect(oplcard)) < 0) {
652 snd_card_free(card);
653 return -ENODEV;
654 }
655 if (request_irq(irq, snd_opl3sa_interrupt, SA_INTERRUPT, "OPL3-SA2/3", (void *)oplcard)) {
656 snd_card_free(card);
657 return -ENODEV;
658 }
659 oplcard->irq = irq;
660 if ((err = snd_cs4231_create(card,
661 snd_wss_port[dev] + 4, -1,
662 irq, dma1, dma2,
663 CS4231_HW_OPL3SA2,
664 CS4231_HWSHARE_IRQ,
665 &cs4231)) < 0) {
666 snd_printd("Oops, WSS not detected at 0x%lx\n", snd_wss_port[dev] + 4);
667 snd_card_free(card);
668 return err;
669 }
670 oplcard->cs4231 = cs4231;
671 if ((err = snd_cs4231_pcm(cs4231, 0, NULL)) < 0) {
672 snd_card_free(card);
673 return err;
674 }
675 if ((err = snd_cs4231_mixer(cs4231)) < 0) {
676 snd_card_free(card);
677 return err;
678 }
679 if ((err = snd_opl3sa_mixer(oplcard)) < 0) {
680 snd_card_free(card);
681 return err;
682 }
683 if ((err = snd_cs4231_timer(cs4231, 0, NULL)) < 0) {
684 snd_card_free(card);
685 return err;
686 }
687 if (snd_fm_port[dev] >= 0x340 && snd_fm_port[dev] < 0x400) {
688 if ((err = snd_opl3_create(card, snd_fm_port[dev],
689 snd_fm_port[dev] + 2,
690 OPL3_HW_OPL3, 0, &opl3)) < 0) {
691 snd_card_free(card);
692 return err;
693 }
694 if ((err = snd_opl3_timer_new(opl3, 1, 2)) < 0) {
695 snd_card_free(card);
696 return err;
697 }
698 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, &oplcard->synth)) < 0) {
699 snd_card_free(card);
700 return err;
701 }
702 }
703 if (snd_midi_port[dev] >= 0x300 && snd_midi_port[dev] < 0x340) {
704 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_OPL3SA2,
705 snd_midi_port[dev], 0,
706 irq, 0, &oplcard->rmidi)) < 0) {
707 snd_card_free(card);
708 return err;
709 }
710 }
711 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
712 card->shortname, oplcard->port, irq, dma1);
713 if (dma2 >= 0)
714 sprintf(card->longname + strlen(card->longname), "&%d", dma2);
715
716 if ((err = snd_card_register(card)) < 0) {
717 snd_card_free(card);
718 return err;
719 }
720 snd_opl3sa_cards[dev] = card;
721 return 0;
722}
723
724#ifdef __ISAPNP__
725static int __init snd_opl3sa2_isapnp_detect(struct isapnp_card *card,
726 const struct isapnp_card_id *id)
727{
728 static int dev = 0;
729 int res;
730
731 for ( ; dev < SNDRV_CARDS; dev++) {
732 if (!snd_enable[dev])
733 continue;
734 snd_opl3sa2_isapnp_cards[dev] = card;
735 snd_opl3sa2_isapnp_id[dev] = id;
736 res = snd_opl3sa_probe(dev);
737 if (res < 0)
738 return res;
739 dev++;
740 return 0;
741 }
742 return -ENODEV;
743}
744#endif /* __ISAPNP__ */
745
746static int __init alsa_card_opl3sa2_init(void)
747{
748 int dev, cards = 0;
749
750 for (dev = 0; dev < SNDRV_CARDS; dev++) {
751 if (!snd_enable[dev])
752 continue;
753#ifdef __ISAPNP__
754 if (snd_isapnp[dev])
755 continue;
756#endif
757 if (snd_opl3sa_probe(dev) >= 0)
758 cards++;
759 }
760#ifdef __ISAPNP__
761 cards += isapnp_probe_cards(snd_opl3sa2_pnpids, snd_opl3sa2_isapnp_detect);
762#endif
763 if (!cards) {
764#ifdef MODULE
765 snd_printk("Yamaha OPL3-SA soundcard not found or device busy\n");
766#endif
767 return -ENODEV;
768 }
769 return 0;
770}
771
772static void __exit alsa_card_opl3sa2_exit(void)
773{
774 int idx;
775
776 for (idx = 0; idx < SNDRV_CARDS; idx++)
777 snd_card_free(snd_opl3sa_cards[idx]);
778}
779
780module_init(alsa_card_opl3sa2_init)
781module_exit(alsa_card_opl3sa2_exit)
782
783#ifndef MODULE
784
785/* format is: snd-card-opl3sa2=snd_enable,snd_index,snd_id,snd_isapnp,
786 snd_port,snd_sb_port,snd_wss_port,snd_fm_port,
787 snd_midi_port,snd_irq,snd_dma1,snd_dma2,
788 snd_opl3sa3_ymode */
789
790static int __init alsa_card_opl3sa2_setup(char *str)
791{
792 static unsigned __initdata nr_dev = 0;
793 int __attribute__ ((__unused__)) pnp = INT_MAX;
794
795 if (nr_dev >= SNDRV_CARDS)
796 return 0;
797 (void)(get_option(&str,&snd_enable[nr_dev]) == 2 &&
798 get_option(&str,&snd_index[nr_dev]) == 2 &&
799 get_id(&str,&snd_id[nr_dev]) == 2 &&
800 get_option(&str,&pnp) == 2 &&
801 get_option(&str,(int *)&snd_port[nr_dev]) == 2 &&
802 get_option(&str,(int *)&snd_sb_port[nr_dev]) == 2 &&
803 get_option(&str,(int *)&snd_wss_port[nr_dev]) == 2 &&
804 get_option(&str,(int *)&snd_fm_port[nr_dev]) == 2 &&
805 get_option(&str,(int *)&snd_midi_port[nr_dev]) == 2 &&
806 get_option(&str,&snd_irq[nr_dev]) == 2 &&
807 get_option(&str,&snd_dma1[nr_dev]) == 2 &&
808 get_option(&str,&snd_dma2[nr_dev]) == 2 &&
809 get_option(&str,&snd_opl3sa3_ymode[nr_dev]) == 2);
810#ifdef __ISAPNP__
811 if (pnp != INT_MAX)
812 snd_isapnp[nr_dev] = pnp;
813#endif
814 nr_dev++;
815 return 1;
816}
817
818__setup("snd-card-opl3sa2=", alsa_card_opl3sa2_setup);
819
820#endif /* ifndef MODULE */
Note: See TracBrowser for help on using the repository browser.