Lines Matching refs:opl3
41 static void snd_opl2_command(struct snd_opl3 * opl3, unsigned short cmd, unsigned char val) in snd_opl2_command() argument
51 port = (cmd & OPL3_RIGHT) ? opl3->r_port : opl3->l_port; in snd_opl2_command()
53 spin_lock_irqsave(&opl3->reg_lock, flags); in snd_opl2_command()
61 spin_unlock_irqrestore(&opl3->reg_lock, flags); in snd_opl2_command()
64 static void snd_opl3_command(struct snd_opl3 * opl3, unsigned short cmd, unsigned char val) in snd_opl3_command() argument
74 port = (cmd & OPL3_RIGHT) ? opl3->r_port : opl3->l_port; in snd_opl3_command()
76 spin_lock_irqsave(&opl3->reg_lock, flags); in snd_opl3_command()
79 inb(opl3->l_port); in snd_opl3_command()
80 inb(opl3->l_port); in snd_opl3_command()
83 inb(opl3->l_port); in snd_opl3_command()
84 inb(opl3->l_port); in snd_opl3_command()
86 spin_unlock_irqrestore(&opl3->reg_lock, flags); in snd_opl3_command()
89 static int snd_opl3_detect(struct snd_opl3 * opl3) in snd_opl3_detect() argument
105 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_TIMER1_MASK | OPL3_TIMER2_MASK); in snd_opl3_detect()
107 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_IRQ_RESET); in snd_opl3_detect()
108 signature = stat1 = inb(opl3->l_port); /* Status register */ in snd_opl3_detect()
114 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER1, 0xff); in snd_opl3_detect()
116 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_TIMER2_MASK | OPL3_TIMER1_START); in snd_opl3_detect()
120 stat2 = inb(opl3->l_port); in snd_opl3_detect()
122 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_TIMER1_MASK | OPL3_TIMER2_MASK); in snd_opl3_detect()
124 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_IRQ_RESET); in snd_opl3_detect()
132 if (opl3->hardware != OPL3_HW_AUTO) in snd_opl3_detect()
137 opl3->hardware = OPL3_HW_OPL2; in snd_opl3_detect()
143 if (snd_BUG_ON(!opl3->r_port)) in snd_opl3_detect()
145 opl3->hardware = OPL3_HW_OPL3; in snd_opl3_detect()
163 struct snd_opl3 *opl3; in snd_opl3_timer1_start() local
165 opl3 = snd_timer_chip(timer); in snd_opl3_timer1_start()
166 spin_lock_irqsave(&opl3->timer_lock, flags); in snd_opl3_timer1_start()
168 tmp = (opl3->timer_enable | OPL3_TIMER1_START) & ~OPL3_TIMER1_MASK; in snd_opl3_timer1_start()
169 opl3->timer_enable = tmp; in snd_opl3_timer1_start()
170 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER1, 256 - ticks); /* timer 1 count */ in snd_opl3_timer1_start()
171 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* enable timer 1 IRQ */ in snd_opl3_timer1_start()
172 spin_unlock_irqrestore(&opl3->timer_lock, flags); in snd_opl3_timer1_start()
180 struct snd_opl3 *opl3; in snd_opl3_timer1_stop() local
182 opl3 = snd_timer_chip(timer); in snd_opl3_timer1_stop()
183 spin_lock_irqsave(&opl3->timer_lock, flags); in snd_opl3_timer1_stop()
184 tmp = (opl3->timer_enable | OPL3_TIMER1_MASK) & ~OPL3_TIMER1_START; in snd_opl3_timer1_stop()
185 opl3->timer_enable = tmp; in snd_opl3_timer1_stop()
186 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* disable timer #1 */ in snd_opl3_timer1_stop()
187 spin_unlock_irqrestore(&opl3->timer_lock, flags); in snd_opl3_timer1_stop()
200 struct snd_opl3 *opl3; in snd_opl3_timer2_start() local
202 opl3 = snd_timer_chip(timer); in snd_opl3_timer2_start()
203 spin_lock_irqsave(&opl3->timer_lock, flags); in snd_opl3_timer2_start()
205 tmp = (opl3->timer_enable | OPL3_TIMER2_START) & ~OPL3_TIMER2_MASK; in snd_opl3_timer2_start()
206 opl3->timer_enable = tmp; in snd_opl3_timer2_start()
207 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER2, 256 - ticks); /* timer 1 count */ in snd_opl3_timer2_start()
208 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* enable timer 1 IRQ */ in snd_opl3_timer2_start()
209 spin_unlock_irqrestore(&opl3->timer_lock, flags); in snd_opl3_timer2_start()
217 struct snd_opl3 *opl3; in snd_opl3_timer2_stop() local
219 opl3 = snd_timer_chip(timer); in snd_opl3_timer2_stop()
220 spin_lock_irqsave(&opl3->timer_lock, flags); in snd_opl3_timer2_stop()
221 tmp = (opl3->timer_enable | OPL3_TIMER2_MASK) & ~OPL3_TIMER2_START; in snd_opl3_timer2_stop()
222 opl3->timer_enable = tmp; in snd_opl3_timer2_stop()
223 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* disable timer #1 */ in snd_opl3_timer2_stop()
224 spin_unlock_irqrestore(&opl3->timer_lock, flags); in snd_opl3_timer2_stop()
250 static int snd_opl3_timer1_init(struct snd_opl3 * opl3, int timer_no) in snd_opl3_timer1_init() argument
258 tid.card = opl3->card->number; in snd_opl3_timer1_init()
261 if ((err = snd_timer_new(opl3->card, "AdLib timer #1", &tid, &timer)) >= 0) { in snd_opl3_timer1_init()
263 timer->private_data = opl3; in snd_opl3_timer1_init()
266 opl3->timer1 = timer; in snd_opl3_timer1_init()
270 static int snd_opl3_timer2_init(struct snd_opl3 * opl3, int timer_no) in snd_opl3_timer2_init() argument
278 tid.card = opl3->card->number; in snd_opl3_timer2_init()
281 if ((err = snd_timer_new(opl3->card, "AdLib timer #2", &tid, &timer)) >= 0) { in snd_opl3_timer2_init()
283 timer->private_data = opl3; in snd_opl3_timer2_init()
286 opl3->timer2 = timer; in snd_opl3_timer2_init()
297 struct snd_opl3 *opl3; in snd_opl3_interrupt() local
303 opl3 = hw->private_data; in snd_opl3_interrupt()
304 status = inb(opl3->l_port); in snd_opl3_interrupt()
312 timer = opl3->timer1; in snd_opl3_interrupt()
316 timer = opl3->timer2; in snd_opl3_interrupt()
327 static int snd_opl3_free(struct snd_opl3 *opl3) in snd_opl3_free() argument
329 if (snd_BUG_ON(!opl3)) in snd_opl3_free()
331 if (opl3->private_free) in snd_opl3_free()
332 opl3->private_free(opl3); in snd_opl3_free()
333 snd_opl3_clear_patches(opl3); in snd_opl3_free()
334 release_and_free_resource(opl3->res_l_port); in snd_opl3_free()
335 release_and_free_resource(opl3->res_r_port); in snd_opl3_free()
336 kfree(opl3); in snd_opl3_free()
342 struct snd_opl3 *opl3 = device->device_data; in snd_opl3_dev_free() local
343 return snd_opl3_free(opl3); in snd_opl3_dev_free()
353 struct snd_opl3 *opl3; in snd_opl3_new() local
357 opl3 = kzalloc(sizeof(*opl3), GFP_KERNEL); in snd_opl3_new()
358 if (opl3 == NULL) { in snd_opl3_new()
363 opl3->card = card; in snd_opl3_new()
364 opl3->hardware = hardware; in snd_opl3_new()
365 spin_lock_init(&opl3->reg_lock); in snd_opl3_new()
366 spin_lock_init(&opl3->timer_lock); in snd_opl3_new()
368 if ((err = snd_device_new(card, SNDRV_DEV_CODEC, opl3, &ops)) < 0) { in snd_opl3_new()
369 snd_opl3_free(opl3); in snd_opl3_new()
373 *ropl3 = opl3; in snd_opl3_new()
379 int snd_opl3_init(struct snd_opl3 *opl3) in snd_opl3_init() argument
381 if (! opl3->command) { in snd_opl3_init()
386 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TEST, OPL3_ENABLE_WAVE_SELECT); in snd_opl3_init()
388 opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION, 0x00); in snd_opl3_init()
390 switch (opl3->hardware & OPL3_HW_MASK) { in snd_opl3_init()
392 opl3->max_voices = MAX_OPL2_VOICES; in snd_opl3_init()
396 opl3->max_voices = MAX_OPL3_VOICES; in snd_opl3_init()
398 opl3->command(opl3, OPL3_RIGHT | OPL3_REG_MODE, OPL3_OPL3_ENABLE); in snd_opl3_init()
412 struct snd_opl3 *opl3; in snd_opl3_create() local
416 if ((err = snd_opl3_new(card, hardware, &opl3)) < 0) in snd_opl3_create()
419 if ((opl3->res_l_port = request_region(l_port, 2, "OPL2/3 (left)")) == NULL) { in snd_opl3_create()
421 snd_device_free(card, opl3); in snd_opl3_create()
425 (opl3->res_r_port = request_region(r_port, 2, "OPL2/3 (right)")) == NULL) { in snd_opl3_create()
427 snd_device_free(card, opl3); in snd_opl3_create()
431 opl3->l_port = l_port; in snd_opl3_create()
432 opl3->r_port = r_port; in snd_opl3_create()
434 switch (opl3->hardware) { in snd_opl3_create()
439 opl3->command = &snd_opl3_command; in snd_opl3_create()
442 opl3->command = &snd_opl2_command; in snd_opl3_create()
443 if ((err = snd_opl3_detect(opl3)) < 0) { in snd_opl3_create()
445 opl3->l_port, opl3->r_port); in snd_opl3_create()
446 snd_device_free(card, opl3); in snd_opl3_create()
450 switch (opl3->hardware & OPL3_HW_MASK) { in snd_opl3_create()
453 opl3->command = &snd_opl3_command; in snd_opl3_create()
457 snd_opl3_init(opl3); in snd_opl3_create()
459 *ropl3 = opl3; in snd_opl3_create()
465 int snd_opl3_timer_new(struct snd_opl3 * opl3, int timer1_dev, int timer2_dev) in snd_opl3_timer_new() argument
470 if ((err = snd_opl3_timer1_init(opl3, timer1_dev)) < 0) in snd_opl3_timer_new()
473 if ((err = snd_opl3_timer2_init(opl3, timer2_dev)) < 0) { in snd_opl3_timer_new()
474 snd_device_free(opl3->card, opl3->timer1); in snd_opl3_timer_new()
475 opl3->timer1 = NULL; in snd_opl3_timer_new()
484 int snd_opl3_hwdep_new(struct snd_opl3 * opl3, in snd_opl3_hwdep_new() argument
489 struct snd_card *card = opl3->card; in snd_opl3_hwdep_new()
498 snd_device_free(card, opl3); in snd_opl3_hwdep_new()
501 hw->private_data = opl3; in snd_opl3_hwdep_new()
510 switch (opl3->hardware & OPL3_HW_MASK) { in snd_opl3_hwdep_new()
531 opl3->hwdep = hw; in snd_opl3_hwdep_new()
532 opl3->seq_dev_num = seq_device; in snd_opl3_hwdep_new()
535 sizeof(struct snd_opl3 *), &opl3->seq_dev) >= 0) { in snd_opl3_hwdep_new()
536 strcpy(opl3->seq_dev->name, hw->name); in snd_opl3_hwdep_new()
537 *(struct snd_opl3 **)SNDRV_SEQ_DEVICE_ARGPTR(opl3->seq_dev) = opl3; in snd_opl3_hwdep_new()