^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) by Uros Bizjak <uros@kss-loka.si>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Midi Sequencer interface routines for OPL2/OPL3/OPL4 FM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * OPL2/3 FM instrument loader:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * alsa-tools/seq/sbiload/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "opl3_voice.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) MODULE_AUTHOR("Uros Bizjak <uros@kss-loka.si>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) MODULE_DESCRIPTION("ALSA driver for OPL3 FM synth");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) bool use_internal_drums = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) module_param(use_internal_drums, bool, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) MODULE_PARM_DESC(use_internal_drums, "Enable internal OPL2/3 drums.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) int snd_opl3_synth_use_inc(struct snd_opl3 * opl3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) if (!try_module_get(opl3->card->module))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) void snd_opl3_synth_use_dec(struct snd_opl3 * opl3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) module_put(opl3->card->module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int snd_opl3_synth_setup(struct snd_opl3 * opl3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct snd_hwdep *hwdep = opl3->hwdep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) mutex_lock(&hwdep->open_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (hwdep->used) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) mutex_unlock(&hwdep->open_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) hwdep->used++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) mutex_unlock(&hwdep->open_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) snd_opl3_reset(opl3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) for (idx = 0; idx < MAX_OPL3_VOICES; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) opl3->voices[idx].state = SNDRV_OPL3_ST_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) opl3->voices[idx].time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) opl3->voices[idx].keyon_reg = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) opl3->use_time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) opl3->connection_reg = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (opl3->hardware >= OPL3_HW_OPL3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* Clear 4-op connections */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) opl3->command(opl3, OPL3_RIGHT | OPL3_REG_CONNECTION_SELECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) opl3->connection_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) opl3->max_voices = MAX_OPL3_VOICES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) void snd_opl3_synth_cleanup(struct snd_opl3 * opl3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct snd_hwdep *hwdep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* Stop system timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) spin_lock_irqsave(&opl3->sys_timer_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (opl3->sys_timer_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) del_timer(&opl3->tlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) opl3->sys_timer_status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) spin_unlock_irqrestore(&opl3->sys_timer_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) snd_opl3_reset(opl3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) hwdep = opl3->hwdep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) mutex_lock(&hwdep->open_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) hwdep->used--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) mutex_unlock(&hwdep->open_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) wake_up(&hwdep->open_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static int snd_opl3_synth_use(void *private_data, struct snd_seq_port_subscribe * info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct snd_opl3 *opl3 = private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if ((err = snd_opl3_synth_setup(opl3)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (use_internal_drums) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* Percussion mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) opl3->voices[6].state = opl3->voices[7].state =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) opl3->voices[8].state = SNDRV_OPL3_ST_NOT_AVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) snd_opl3_load_drums(opl3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) opl3->drum_reg = OPL3_PERCUSSION_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION, opl3->drum_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) opl3->drum_reg = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (info->sender.client != SNDRV_SEQ_CLIENT_SYSTEM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if ((err = snd_opl3_synth_use_inc(opl3)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) opl3->synth_mode = SNDRV_OPL3_MODE_SEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static int snd_opl3_synth_unuse(void *private_data, struct snd_seq_port_subscribe * info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct snd_opl3 *opl3 = private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) snd_opl3_synth_cleanup(opl3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (info->sender.client != SNDRV_SEQ_CLIENT_SYSTEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) snd_opl3_synth_use_dec(opl3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * MIDI emulation operators
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) const struct snd_midi_op opl3_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .note_on = snd_opl3_note_on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .note_off = snd_opl3_note_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) .key_press = snd_opl3_key_press,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .note_terminate = snd_opl3_terminate_note,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) .control = snd_opl3_control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .nrpn = snd_opl3_nrpn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .sysex = snd_opl3_sysex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static int snd_opl3_synth_event_input(struct snd_seq_event * ev, int direct,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) void *private_data, int atomic, int hop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct snd_opl3 *opl3 = private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) snd_midi_process_event(&opl3_ops, ev, opl3->chset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /* ------------------------------ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static void snd_opl3_synth_free_port(void *private_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct snd_opl3 *opl3 = private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) snd_midi_channel_free_set(opl3->chset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static int snd_opl3_synth_create_port(struct snd_opl3 * opl3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct snd_seq_port_callback callbacks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) char name[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) int voices, opl_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) voices = (opl3->hardware < OPL3_HW_OPL3) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) MAX_OPL2_VOICES : MAX_OPL3_VOICES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) opl3->chset = snd_midi_channel_alloc_set(16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (opl3->chset == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) opl3->chset->private_data = opl3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) memset(&callbacks, 0, sizeof(callbacks));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) callbacks.owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) callbacks.use = snd_opl3_synth_use;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) callbacks.unuse = snd_opl3_synth_unuse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) callbacks.event_input = snd_opl3_synth_event_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) callbacks.private_free = snd_opl3_synth_free_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) callbacks.private_data = opl3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) opl_ver = (opl3->hardware & OPL3_HW_MASK) >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) sprintf(name, "OPL%i FM Port", opl_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) opl3->chset->client = opl3->seq_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) opl3->chset->port = snd_seq_event_port_attach(opl3->seq_client, &callbacks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) SNDRV_SEQ_PORT_CAP_WRITE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) SNDRV_SEQ_PORT_CAP_SUBS_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) SNDRV_SEQ_PORT_TYPE_MIDI_GM |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) SNDRV_SEQ_PORT_TYPE_DIRECT_SAMPLE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) SNDRV_SEQ_PORT_TYPE_HARDWARE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) SNDRV_SEQ_PORT_TYPE_SYNTHESIZER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 16, voices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (opl3->chset->port < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) port = opl3->chset->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) snd_midi_channel_free_set(opl3->chset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /* ------------------------------ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static int snd_opl3_seq_probe(struct device *_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct snd_seq_device *dev = to_seq_dev(_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct snd_opl3 *opl3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) int client, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) char name[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int opl_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) opl3 = *(struct snd_opl3 **)SNDRV_SEQ_DEVICE_ARGPTR(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (opl3 == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) spin_lock_init(&opl3->voice_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) opl3->seq_client = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /* allocate new client */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) opl_ver = (opl3->hardware & OPL3_HW_MASK) >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) sprintf(name, "OPL%i FM synth", opl_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) client = opl3->seq_client =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) snd_seq_create_kernel_client(opl3->card, opl3->seq_dev_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (client < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if ((err = snd_opl3_synth_create_port(opl3)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) snd_seq_delete_kernel_client(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) opl3->seq_client = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /* setup system timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) timer_setup(&opl3->tlist, snd_opl3_timer_func, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) spin_lock_init(&opl3->sys_timer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) opl3->sys_timer_status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) snd_opl3_init_seq_oss(opl3, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static int snd_opl3_seq_remove(struct device *_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct snd_seq_device *dev = to_seq_dev(_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct snd_opl3 *opl3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) opl3 = *(struct snd_opl3 **)SNDRV_SEQ_DEVICE_ARGPTR(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (opl3 == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) snd_opl3_free_seq_oss(opl3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (opl3->seq_client >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) snd_seq_delete_kernel_client(opl3->seq_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) opl3->seq_client = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static struct snd_seq_driver opl3_seq_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) .name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) .probe = snd_opl3_seq_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) .remove = snd_opl3_seq_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) .id = SNDRV_SEQ_DEV_ID_OPL3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) .argsize = sizeof(struct snd_opl3 *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) module_snd_seq_driver(opl3_seq_driver);