Lines Matching refs:opl3
12 #include <sound/opl3.h>
26 static void snd_opl2_command(struct snd_opl3 * opl3, unsigned short cmd, unsigned char val)
36 port = (cmd & OPL3_RIGHT) ? opl3->r_port : opl3->l_port;
38 spin_lock_irqsave(&opl3->reg_lock, flags);
46 spin_unlock_irqrestore(&opl3->reg_lock, flags);
49 static void snd_opl3_command(struct snd_opl3 * opl3, unsigned short cmd, unsigned char val)
59 port = (cmd & OPL3_RIGHT) ? opl3->r_port : opl3->l_port;
61 spin_lock_irqsave(&opl3->reg_lock, flags);
64 inb(opl3->l_port);
65 inb(opl3->l_port);
68 inb(opl3->l_port);
69 inb(opl3->l_port);
71 spin_unlock_irqrestore(&opl3->reg_lock, flags);
74 static int snd_opl3_detect(struct snd_opl3 * opl3)
90 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_TIMER1_MASK | OPL3_TIMER2_MASK);
92 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_IRQ_RESET);
93 signature = stat1 = inb(opl3->l_port); /* Status register */
99 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER1, 0xff);
101 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_TIMER2_MASK | OPL3_TIMER1_START);
105 stat2 = inb(opl3->l_port);
107 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_TIMER1_MASK | OPL3_TIMER2_MASK);
109 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_IRQ_RESET);
117 if (opl3->hardware != OPL3_HW_AUTO)
122 opl3->hardware = OPL3_HW_OPL2;
125 * If we had an OPL4 chip, opl3->hardware would have been set
128 if (snd_BUG_ON(!opl3->r_port))
130 opl3->hardware = OPL3_HW_OPL3;
148 struct snd_opl3 *opl3;
150 opl3 = snd_timer_chip(timer);
151 spin_lock_irqsave(&opl3->timer_lock, flags);
153 tmp = (opl3->timer_enable | OPL3_TIMER1_START) & ~OPL3_TIMER1_MASK;
154 opl3->timer_enable = tmp;
155 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER1, 256 - ticks); /* timer 1 count */
156 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* enable timer 1 IRQ */
157 spin_unlock_irqrestore(&opl3->timer_lock, flags);
165 struct snd_opl3 *opl3;
167 opl3 = snd_timer_chip(timer);
168 spin_lock_irqsave(&opl3->timer_lock, flags);
169 tmp = (opl3->timer_enable | OPL3_TIMER1_MASK) & ~OPL3_TIMER1_START;
170 opl3->timer_enable = tmp;
171 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* disable timer #1 */
172 spin_unlock_irqrestore(&opl3->timer_lock, flags);
185 struct snd_opl3 *opl3;
187 opl3 = snd_timer_chip(timer);
188 spin_lock_irqsave(&opl3->timer_lock, flags);
190 tmp = (opl3->timer_enable | OPL3_TIMER2_START) & ~OPL3_TIMER2_MASK;
191 opl3->timer_enable = tmp;
192 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER2, 256 - ticks); /* timer 1 count */
193 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* enable timer 1 IRQ */
194 spin_unlock_irqrestore(&opl3->timer_lock, flags);
202 struct snd_opl3 *opl3;
204 opl3 = snd_timer_chip(timer);
205 spin_lock_irqsave(&opl3->timer_lock, flags);
206 tmp = (opl3->timer_enable | OPL3_TIMER2_MASK) & ~OPL3_TIMER2_START;
207 opl3->timer_enable = tmp;
208 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* disable timer #1 */
209 spin_unlock_irqrestore(&opl3->timer_lock, flags);
235 static int snd_opl3_timer1_init(struct snd_opl3 * opl3, int timer_no)
243 tid.card = opl3->card->number;
246 err = snd_timer_new(opl3->card, "AdLib timer #1", &tid, &timer);
249 timer->private_data = opl3;
252 opl3->timer1 = timer;
256 static int snd_opl3_timer2_init(struct snd_opl3 * opl3, int timer_no)
264 tid.card = opl3->card->number;
267 err = snd_timer_new(opl3->card, "AdLib timer #2", &tid, &timer);
270 timer->private_data = opl3;
273 opl3->timer2 = timer;
284 struct snd_opl3 *opl3;
290 opl3 = hw->private_data;
291 status = inb(opl3->l_port);
299 timer = opl3->timer1;
303 timer = opl3->timer2;
314 static int snd_opl3_free(struct snd_opl3 *opl3)
316 if (snd_BUG_ON(!opl3))
318 if (opl3->private_free)
319 opl3->private_free(opl3);
320 snd_opl3_clear_patches(opl3);
321 release_and_free_resource(opl3->res_l_port);
322 release_and_free_resource(opl3->res_r_port);
323 kfree(opl3);
329 struct snd_opl3 *opl3 = device->device_data;
330 return snd_opl3_free(opl3);
340 struct snd_opl3 *opl3;
344 opl3 = kzalloc(sizeof(*opl3), GFP_KERNEL);
345 if (!opl3)
348 opl3->card = card;
349 opl3->hardware = hardware;
350 spin_lock_init(&opl3->reg_lock);
351 spin_lock_init(&opl3->timer_lock);
353 err = snd_device_new(card, SNDRV_DEV_CODEC, opl3, &ops);
355 snd_opl3_free(opl3);
359 *ropl3 = opl3;
365 int snd_opl3_init(struct snd_opl3 *opl3)
367 if (! opl3->command) {
372 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TEST, OPL3_ENABLE_WAVE_SELECT);
374 opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION, 0x00);
376 switch (opl3->hardware & OPL3_HW_MASK) {
378 opl3->max_voices = MAX_OPL2_VOICES;
382 opl3->max_voices = MAX_OPL3_VOICES;
384 opl3->command(opl3, OPL3_RIGHT | OPL3_REG_MODE, OPL3_OPL3_ENABLE);
398 struct snd_opl3 *opl3;
402 err = snd_opl3_new(card, hardware, &opl3);
406 opl3->res_l_port = request_region(l_port, 2, "OPL2/3 (left)");
407 if (!opl3->res_l_port) {
408 snd_printk(KERN_ERR "opl3: can't grab left port 0x%lx\n", l_port);
409 snd_device_free(card, opl3);
413 opl3->res_r_port = request_region(r_port, 2, "OPL2/3 (right)");
414 if (!opl3->res_r_port) {
415 snd_printk(KERN_ERR "opl3: can't grab right port 0x%lx\n", r_port);
416 snd_device_free(card, opl3);
421 opl3->l_port = l_port;
422 opl3->r_port = r_port;
424 switch (opl3->hardware) {
429 opl3->command = &snd_opl3_command;
432 opl3->command = &snd_opl2_command;
433 err = snd_opl3_detect(opl3);
436 opl3->l_port, opl3->r_port);
437 snd_device_free(card, opl3);
441 switch (opl3->hardware & OPL3_HW_MASK) {
444 opl3->command = &snd_opl3_command;
448 snd_opl3_init(opl3);
450 *ropl3 = opl3;
456 int snd_opl3_timer_new(struct snd_opl3 * opl3, int timer1_dev, int timer2_dev)
461 err = snd_opl3_timer1_init(opl3, timer1_dev);
466 err = snd_opl3_timer2_init(opl3, timer2_dev);
468 snd_device_free(opl3->card, opl3->timer1);
469 opl3->timer1 = NULL;
478 int snd_opl3_hwdep_new(struct snd_opl3 * opl3,
483 struct snd_card *card = opl3->card;
493 snd_device_free(card, opl3);
496 hw->private_data = opl3;
503 switch (opl3->hardware & OPL3_HW_MASK) {
524 opl3->hwdep = hw;
525 opl3->seq_dev_num = seq_device;
528 sizeof(struct snd_opl3 *), &opl3->seq_dev) >= 0) {
529 strcpy(opl3->seq_dev->name, hw->name);
530 *(struct snd_opl3 **)SNDRV_SEQ_DEVICE_ARGPTR(opl3->seq_dev) = opl3;