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 if ((err = snd_timer_new(opl3->card, "AdLib timer #1", &tid, &timer)) >= 0) {
248 timer->private_data = opl3;
251 opl3->timer1 = timer;
255 static int snd_opl3_timer2_init(struct snd_opl3 * opl3, int timer_no)
263 tid.card = opl3->card->number;
266 if ((err = snd_timer_new(opl3->card, "AdLib timer #2", &tid, &timer)) >= 0) {
268 timer->private_data = opl3;
271 opl3->timer2 = timer;
282 struct snd_opl3 *opl3;
288 opl3 = hw->private_data;
289 status = inb(opl3->l_port);
297 timer = opl3->timer1;
301 timer = opl3->timer2;
312 static int snd_opl3_free(struct snd_opl3 *opl3)
314 if (snd_BUG_ON(!opl3))
316 if (opl3->private_free)
317 opl3->private_free(opl3);
318 snd_opl3_clear_patches(opl3);
319 release_and_free_resource(opl3->res_l_port);
320 release_and_free_resource(opl3->res_r_port);
321 kfree(opl3);
327 struct snd_opl3 *opl3 = device->device_data;
328 return snd_opl3_free(opl3);
338 struct snd_opl3 *opl3;
342 opl3 = kzalloc(sizeof(*opl3), GFP_KERNEL);
343 if (!opl3)
346 opl3->card = card;
347 opl3->hardware = hardware;
348 spin_lock_init(&opl3->reg_lock);
349 spin_lock_init(&opl3->timer_lock);
351 if ((err = snd_device_new(card, SNDRV_DEV_CODEC, opl3, &ops)) < 0) {
352 snd_opl3_free(opl3);
356 *ropl3 = opl3;
362 int snd_opl3_init(struct snd_opl3 *opl3)
364 if (! opl3->command) {
369 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TEST, OPL3_ENABLE_WAVE_SELECT);
371 opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION, 0x00);
373 switch (opl3->hardware & OPL3_HW_MASK) {
375 opl3->max_voices = MAX_OPL2_VOICES;
379 opl3->max_voices = MAX_OPL3_VOICES;
381 opl3->command(opl3, OPL3_RIGHT | OPL3_REG_MODE, OPL3_OPL3_ENABLE);
395 struct snd_opl3 *opl3;
399 if ((err = snd_opl3_new(card, hardware, &opl3)) < 0)
402 if ((opl3->res_l_port = request_region(l_port, 2, "OPL2/3 (left)")) == NULL) {
403 snd_printk(KERN_ERR "opl3: can't grab left port 0x%lx\n", l_port);
404 snd_device_free(card, opl3);
408 (opl3->res_r_port = request_region(r_port, 2, "OPL2/3 (right)")) == NULL) {
409 snd_printk(KERN_ERR "opl3: can't grab right port 0x%lx\n", r_port);
410 snd_device_free(card, opl3);
414 opl3->l_port = l_port;
415 opl3->r_port = r_port;
417 switch (opl3->hardware) {
422 opl3->command = &snd_opl3_command;
425 opl3->command = &snd_opl2_command;
426 if ((err = snd_opl3_detect(opl3)) < 0) {
428 opl3->l_port, opl3->r_port);
429 snd_device_free(card, opl3);
433 switch (opl3->hardware & OPL3_HW_MASK) {
436 opl3->command = &snd_opl3_command;
440 snd_opl3_init(opl3);
442 *ropl3 = opl3;
448 int snd_opl3_timer_new(struct snd_opl3 * opl3, int timer1_dev, int timer2_dev)
453 if ((err = snd_opl3_timer1_init(opl3, timer1_dev)) < 0)
456 if ((err = snd_opl3_timer2_init(opl3, timer2_dev)) < 0) {
457 snd_device_free(opl3->card, opl3->timer1);
458 opl3->timer1 = NULL;
467 int snd_opl3_hwdep_new(struct snd_opl3 * opl3,
472 struct snd_card *card = opl3->card;
481 snd_device_free(card, opl3);
484 hw->private_data = opl3;
491 switch (opl3->hardware & OPL3_HW_MASK) {
512 opl3->hwdep = hw;
513 opl3->seq_dev_num = seq_device;
516 sizeof(struct snd_opl3 *), &opl3->seq_dev) >= 0) {
517 strcpy(opl3->seq_dev->name, hw->name);
518 *(struct snd_opl3 **)SNDRV_SEQ_DEVICE_ARGPTR(opl3->seq_dev) = opl3;