blob: a657da922b4dad0b4e8c0b4ddd724a8b71ad3ec9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02002 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Hannu Savolainen 1993-1996,
4 * Rob Hooft
5 *
6 * Routines for control of AdLib FM cards (OPL2/OPL3/OPL4 chips)
7 *
8 * Most if code is ported from OSS/Lite.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26#include <sound/opl3.h>
27#include <asm/io.h>
28#include <linux/delay.h>
29#include <linux/init.h>
30#include <linux/slab.h>
31#include <linux/ioport.h>
32#include <sound/minors.h>
33
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020034MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, Hannu Savolainen 1993-1996, Rob Hooft");
Linus Torvalds1da177e2005-04-16 15:20:36 -070035MODULE_DESCRIPTION("Routines for control of AdLib FM cards (OPL2/OPL3/OPL4 chips)");
36MODULE_LICENSE("GPL");
37
38extern char snd_opl3_regmap[MAX_OPL2_VOICES][4];
39
Takashi Iwai5b1646a2005-11-17 14:13:14 +010040static void snd_opl2_command(struct snd_opl3 * opl3, unsigned short cmd, unsigned char val)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
42 unsigned long flags;
43 unsigned long port;
44
45 /*
46 * The original 2-OP synth requires a quite long delay
47 * after writing to a register.
48 */
49
50 port = (cmd & OPL3_RIGHT) ? opl3->r_port : opl3->l_port;
51
52 spin_lock_irqsave(&opl3->reg_lock, flags);
53
54 outb((unsigned char) cmd, port);
55 udelay(10);
56
57 outb((unsigned char) val, port + 1);
58 udelay(30);
59
60 spin_unlock_irqrestore(&opl3->reg_lock, flags);
61}
62
Takashi Iwai5b1646a2005-11-17 14:13:14 +010063static void snd_opl3_command(struct snd_opl3 * opl3, unsigned short cmd, unsigned char val)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
65 unsigned long flags;
66 unsigned long port;
67
68 /*
69 * The OPL-3 survives with just two INBs
70 * after writing to a register.
71 */
72
73 port = (cmd & OPL3_RIGHT) ? opl3->r_port : opl3->l_port;
74
75 spin_lock_irqsave(&opl3->reg_lock, flags);
76
77 outb((unsigned char) cmd, port);
78 inb(opl3->l_port);
79 inb(opl3->l_port);
80
81 outb((unsigned char) val, port + 1);
82 inb(opl3->l_port);
83 inb(opl3->l_port);
84
85 spin_unlock_irqrestore(&opl3->reg_lock, flags);
86}
87
Takashi Iwai5b1646a2005-11-17 14:13:14 +010088static int snd_opl3_detect(struct snd_opl3 * opl3)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
90 /*
91 * This function returns 1 if the FM chip is present at the given I/O port
92 * The detection algorithm plays with the timer built in the FM chip and
93 * looks for a change in the status register.
94 *
95 * Note! The timers of the FM chip are not connected to AdLib (and compatible)
96 * boards.
97 *
98 * Note2! The chip is initialized if detected.
99 */
100
101 unsigned char stat1, stat2, signature;
102
103 /* Reset timers 1 and 2 */
104 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_TIMER1_MASK | OPL3_TIMER2_MASK);
105 /* Reset the IRQ of the FM chip */
106 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_IRQ_RESET);
107 signature = stat1 = inb(opl3->l_port); /* Status register */
108 if ((stat1 & 0xe0) != 0x00) { /* Should be 0x00 */
109 snd_printd("OPL3: stat1 = 0x%x\n", stat1);
110 return -ENODEV;
111 }
112 /* Set timer1 to 0xff */
113 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER1, 0xff);
114 /* Unmask and start timer 1 */
115 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_TIMER2_MASK | OPL3_TIMER1_START);
116 /* Now we have to delay at least 80us */
117 udelay(200);
118 /* Read status after timers have expired */
119 stat2 = inb(opl3->l_port);
120 /* Stop the timers */
121 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_TIMER1_MASK | OPL3_TIMER2_MASK);
122 /* Reset the IRQ of the FM chip */
123 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_IRQ_RESET);
124 if ((stat2 & 0xe0) != 0xc0) { /* There is no YM3812 */
125 snd_printd("OPL3: stat2 = 0x%x\n", stat2);
126 return -ENODEV;
127 }
128
129 /* If the toplevel code knows exactly the type of chip, don't try
130 to detect it. */
131 if (opl3->hardware != OPL3_HW_AUTO)
132 return 0;
133
134 /* There is a FM chip on this address. Detect the type (OPL2 to OPL4) */
135 if (signature == 0x06) { /* OPL2 */
136 opl3->hardware = OPL3_HW_OPL2;
137 } else {
138 /*
139 * If we had an OPL4 chip, opl3->hardware would have been set
140 * by the OPL4 driver; so we can assume OPL3 here.
141 */
142 snd_assert(opl3->r_port != 0, return -ENODEV);
143 opl3->hardware = OPL3_HW_OPL3;
144 }
145 return 0;
146}
147
148/*
149 * AdLib timers
150 */
151
152/*
153 * Timer 1 - 80us
154 */
155
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100156static int snd_opl3_timer1_start(struct snd_timer * timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
158 unsigned long flags;
159 unsigned char tmp;
160 unsigned int ticks;
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100161 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 opl3 = snd_timer_chip(timer);
164 spin_lock_irqsave(&opl3->timer_lock, flags);
165 ticks = timer->sticks;
166 tmp = (opl3->timer_enable | OPL3_TIMER1_START) & ~OPL3_TIMER1_MASK;
167 opl3->timer_enable = tmp;
168 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER1, 256 - ticks); /* timer 1 count */
169 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* enable timer 1 IRQ */
170 spin_unlock_irqrestore(&opl3->timer_lock, flags);
171 return 0;
172}
173
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100174static int snd_opl3_timer1_stop(struct snd_timer * timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
176 unsigned long flags;
177 unsigned char tmp;
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100178 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 opl3 = snd_timer_chip(timer);
181 spin_lock_irqsave(&opl3->timer_lock, flags);
182 tmp = (opl3->timer_enable | OPL3_TIMER1_MASK) & ~OPL3_TIMER1_START;
183 opl3->timer_enable = tmp;
184 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* disable timer #1 */
185 spin_unlock_irqrestore(&opl3->timer_lock, flags);
186 return 0;
187}
188
189/*
190 * Timer 2 - 320us
191 */
192
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100193static int snd_opl3_timer2_start(struct snd_timer * timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
195 unsigned long flags;
196 unsigned char tmp;
197 unsigned int ticks;
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100198 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 opl3 = snd_timer_chip(timer);
201 spin_lock_irqsave(&opl3->timer_lock, flags);
202 ticks = timer->sticks;
203 tmp = (opl3->timer_enable | OPL3_TIMER2_START) & ~OPL3_TIMER2_MASK;
204 opl3->timer_enable = tmp;
205 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER2, 256 - ticks); /* timer 1 count */
206 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* enable timer 1 IRQ */
207 spin_unlock_irqrestore(&opl3->timer_lock, flags);
208 return 0;
209}
210
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100211static int snd_opl3_timer2_stop(struct snd_timer * timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
213 unsigned long flags;
214 unsigned char tmp;
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100215 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 opl3 = snd_timer_chip(timer);
218 spin_lock_irqsave(&opl3->timer_lock, flags);
219 tmp = (opl3->timer_enable | OPL3_TIMER2_MASK) & ~OPL3_TIMER2_START;
220 opl3->timer_enable = tmp;
221 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* disable timer #1 */
222 spin_unlock_irqrestore(&opl3->timer_lock, flags);
223 return 0;
224}
225
226/*
227
228 */
229
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100230static struct snd_timer_hardware snd_opl3_timer1 =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
232 .flags = SNDRV_TIMER_HW_STOP,
233 .resolution = 80000,
234 .ticks = 256,
235 .start = snd_opl3_timer1_start,
236 .stop = snd_opl3_timer1_stop,
237};
238
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100239static struct snd_timer_hardware snd_opl3_timer2 =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
241 .flags = SNDRV_TIMER_HW_STOP,
242 .resolution = 320000,
243 .ticks = 256,
244 .start = snd_opl3_timer2_start,
245 .stop = snd_opl3_timer2_stop,
246};
247
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100248static int snd_opl3_timer1_init(struct snd_opl3 * opl3, int timer_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100250 struct snd_timer *timer = NULL;
251 struct snd_timer_id tid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 int err;
253
254 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
255 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
256 tid.card = opl3->card->number;
257 tid.device = timer_no;
258 tid.subdevice = 0;
259 if ((err = snd_timer_new(opl3->card, "AdLib timer #1", &tid, &timer)) >= 0) {
260 strcpy(timer->name, "AdLib timer #1");
261 timer->private_data = opl3;
262 timer->hw = snd_opl3_timer1;
263 }
264 opl3->timer1 = timer;
265 return err;
266}
267
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100268static int snd_opl3_timer2_init(struct snd_opl3 * opl3, int timer_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100270 struct snd_timer *timer = NULL;
271 struct snd_timer_id tid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 int err;
273
274 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
275 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
276 tid.card = opl3->card->number;
277 tid.device = timer_no;
278 tid.subdevice = 0;
279 if ((err = snd_timer_new(opl3->card, "AdLib timer #2", &tid, &timer)) >= 0) {
280 strcpy(timer->name, "AdLib timer #2");
281 timer->private_data = opl3;
282 timer->hw = snd_opl3_timer2;
283 }
284 opl3->timer2 = timer;
285 return err;
286}
287
288/*
289
290 */
291
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100292void snd_opl3_interrupt(struct snd_hwdep * hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{
294 unsigned char status;
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100295 struct snd_opl3 *opl3;
296 struct snd_timer *timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298 if (hw == NULL)
299 return;
300
301 opl3 = hw->private_data;
302 status = inb(opl3->l_port);
303#if 0
304 snd_printk("AdLib IRQ status = 0x%x\n", status);
305#endif
306 if (!(status & 0x80))
307 return;
308
309 if (status & 0x40) {
310 timer = opl3->timer1;
311 snd_timer_interrupt(timer, timer->sticks);
312 }
313 if (status & 0x20) {
314 timer = opl3->timer2;
315 snd_timer_interrupt(timer, timer->sticks);
316 }
317}
318
Takashi Iwaiac19e192006-04-28 15:13:39 +0200319EXPORT_SYMBOL(snd_opl3_interrupt);
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321/*
322
323 */
324
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100325static int snd_opl3_free(struct snd_opl3 *opl3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
327 snd_assert(opl3 != NULL, return -ENXIO);
328 if (opl3->private_free)
329 opl3->private_free(opl3);
Takashi Iwai224a0332007-10-30 11:49:22 +0100330 snd_opl3_clear_patches(opl3);
Takashi Iwaib1d57762005-10-10 11:56:31 +0200331 release_and_free_resource(opl3->res_l_port);
332 release_and_free_resource(opl3->res_r_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 kfree(opl3);
334 return 0;
335}
336
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100337static int snd_opl3_dev_free(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100339 struct snd_opl3 *opl3 = device->device_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 return snd_opl3_free(opl3);
341}
342
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100343int snd_opl3_new(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 unsigned short hardware,
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100345 struct snd_opl3 **ropl3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100347 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 .dev_free = snd_opl3_dev_free,
349 };
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100350 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 int err;
352
353 *ropl3 = NULL;
Takashi Iwai561b2202005-09-09 14:22:34 +0200354 opl3 = kzalloc(sizeof(*opl3), GFP_KERNEL);
Takashi Iwai73e77ba2005-11-17 17:44:01 +0100355 if (opl3 == NULL) {
356 snd_printk(KERN_ERR "opl3: cannot allocate\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 return -ENOMEM;
Takashi Iwai73e77ba2005-11-17 17:44:01 +0100358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360 opl3->card = card;
361 opl3->hardware = hardware;
362 spin_lock_init(&opl3->reg_lock);
363 spin_lock_init(&opl3->timer_lock);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100364 mutex_init(&opl3->access_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366 if ((err = snd_device_new(card, SNDRV_DEV_CODEC, opl3, &ops)) < 0) {
367 snd_opl3_free(opl3);
368 return err;
369 }
370
371 *ropl3 = opl3;
372 return 0;
373}
374
Takashi Iwaiac19e192006-04-28 15:13:39 +0200375EXPORT_SYMBOL(snd_opl3_new);
376
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100377int snd_opl3_init(struct snd_opl3 *opl3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
379 if (! opl3->command) {
380 printk(KERN_ERR "snd_opl3_init: command not defined!\n");
381 return -EINVAL;
382 }
383
384 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TEST, OPL3_ENABLE_WAVE_SELECT);
385 /* Melodic mode */
386 opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION, 0x00);
387
388 switch (opl3->hardware & OPL3_HW_MASK) {
389 case OPL3_HW_OPL2:
390 opl3->max_voices = MAX_OPL2_VOICES;
391 break;
392 case OPL3_HW_OPL3:
393 case OPL3_HW_OPL4:
394 opl3->max_voices = MAX_OPL3_VOICES;
395 /* Enter OPL3 mode */
396 opl3->command(opl3, OPL3_RIGHT | OPL3_REG_MODE, OPL3_OPL3_ENABLE);
397 }
398 return 0;
399}
400
Takashi Iwaiac19e192006-04-28 15:13:39 +0200401EXPORT_SYMBOL(snd_opl3_init);
402
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100403int snd_opl3_create(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 unsigned long l_port,
405 unsigned long r_port,
406 unsigned short hardware,
407 int integrated,
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100408 struct snd_opl3 ** ropl3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409{
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100410 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 int err;
412
413 *ropl3 = NULL;
414 if ((err = snd_opl3_new(card, hardware, &opl3)) < 0)
415 return err;
416 if (! integrated) {
417 if ((opl3->res_l_port = request_region(l_port, 2, "OPL2/3 (left)")) == NULL) {
418 snd_printk(KERN_ERR "opl3: can't grab left port 0x%lx\n", l_port);
Takashi Iwai676338a2006-01-03 19:56:55 +0100419 snd_device_free(card, opl3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 return -EBUSY;
421 }
422 if (r_port != 0 &&
423 (opl3->res_r_port = request_region(r_port, 2, "OPL2/3 (right)")) == NULL) {
424 snd_printk(KERN_ERR "opl3: can't grab right port 0x%lx\n", r_port);
Takashi Iwai676338a2006-01-03 19:56:55 +0100425 snd_device_free(card, opl3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 return -EBUSY;
427 }
428 }
429 opl3->l_port = l_port;
430 opl3->r_port = r_port;
431
432 switch (opl3->hardware) {
433 /* some hardware doesn't support timers */
434 case OPL3_HW_OPL3_SV:
435 case OPL3_HW_OPL3_CS:
436 case OPL3_HW_OPL3_FM801:
437 opl3->command = &snd_opl3_command;
438 break;
439 default:
440 opl3->command = &snd_opl2_command;
441 if ((err = snd_opl3_detect(opl3)) < 0) {
442 snd_printd("OPL2/3 chip not detected at 0x%lx/0x%lx\n",
443 opl3->l_port, opl3->r_port);
Takashi Iwai676338a2006-01-03 19:56:55 +0100444 snd_device_free(card, opl3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 return err;
446 }
447 /* detect routine returns correct hardware type */
448 switch (opl3->hardware & OPL3_HW_MASK) {
449 case OPL3_HW_OPL3:
450 case OPL3_HW_OPL4:
451 opl3->command = &snd_opl3_command;
452 }
453 }
454
455 snd_opl3_init(opl3);
456
457 *ropl3 = opl3;
458 return 0;
459}
460
Takashi Iwaiac19e192006-04-28 15:13:39 +0200461EXPORT_SYMBOL(snd_opl3_create);
462
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100463int snd_opl3_timer_new(struct snd_opl3 * opl3, int timer1_dev, int timer2_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
465 int err;
466
467 if (timer1_dev >= 0)
468 if ((err = snd_opl3_timer1_init(opl3, timer1_dev)) < 0)
469 return err;
470 if (timer2_dev >= 0) {
471 if ((err = snd_opl3_timer2_init(opl3, timer2_dev)) < 0) {
472 snd_device_free(opl3->card, opl3->timer1);
473 opl3->timer1 = NULL;
474 return err;
475 }
476 }
477 return 0;
478}
479
Takashi Iwaiac19e192006-04-28 15:13:39 +0200480EXPORT_SYMBOL(snd_opl3_timer_new);
481
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100482int snd_opl3_hwdep_new(struct snd_opl3 * opl3,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 int device, int seq_device,
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100484 struct snd_hwdep ** rhwdep)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100486 struct snd_hwdep *hw;
487 struct snd_card *card = opl3->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 int err;
489
490 if (rhwdep)
491 *rhwdep = NULL;
492
493 /* create hardware dependent device (direct FM) */
494
495 if ((err = snd_hwdep_new(card, "OPL2/OPL3", device, &hw)) < 0) {
496 snd_device_free(card, opl3);
497 return err;
498 }
499 hw->private_data = opl3;
500#ifdef CONFIG_SND_OSSEMUL
501 if (device == 0) {
502 hw->oss_type = SNDRV_OSS_DEVICE_TYPE_DMFM;
503 sprintf(hw->oss_dev, "dmfm%i", card->number);
504 }
505#endif
506 strcpy(hw->name, hw->id);
507 switch (opl3->hardware & OPL3_HW_MASK) {
508 case OPL3_HW_OPL2:
509 strcpy(hw->name, "OPL2 FM");
510 hw->iface = SNDRV_HWDEP_IFACE_OPL2;
511 break;
512 case OPL3_HW_OPL3:
513 strcpy(hw->name, "OPL3 FM");
514 hw->iface = SNDRV_HWDEP_IFACE_OPL3;
515 break;
516 case OPL3_HW_OPL4:
517 strcpy(hw->name, "OPL4 FM");
518 hw->iface = SNDRV_HWDEP_IFACE_OPL4;
519 break;
520 }
521
522 /* operators - only ioctl */
523 hw->ops.open = snd_opl3_open;
524 hw->ops.ioctl = snd_opl3_ioctl;
Takashi Iwai224a0332007-10-30 11:49:22 +0100525 hw->ops.write = snd_opl3_write;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 hw->ops.release = snd_opl3_release;
527
528 opl3->seq_dev_num = seq_device;
529#if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
530 if (snd_seq_device_new(card, seq_device, SNDRV_SEQ_DEV_ID_OPL3,
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100531 sizeof(struct snd_opl3 *), &opl3->seq_dev) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 strcpy(opl3->seq_dev->name, hw->name);
Takashi Iwai5b1646a2005-11-17 14:13:14 +0100533 *(struct snd_opl3 **)SNDRV_SEQ_DEVICE_ARGPTR(opl3->seq_dev) = opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 }
535#endif
536 if (rhwdep)
537 *rhwdep = hw;
538 return 0;
539}
540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541EXPORT_SYMBOL(snd_opl3_hwdep_new);
542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543/*
544 * INIT part
545 */
546
547static int __init alsa_opl3_init(void)
548{
549 return 0;
550}
551
552static void __exit alsa_opl3_exit(void)
553{
554}
555
556module_init(alsa_opl3_init)
557module_exit(alsa_opl3_exit)