^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) 2000 Takashi Iwai <tiwai@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Routines for control of EMU10K1 WaveTable synth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "emu10k1_synth_local.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) MODULE_AUTHOR("Takashi Iwai");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) MODULE_DESCRIPTION("Routines for control of EMU10K1 WaveTable synth");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * create a new hardware dependent device for Emu10k1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static int snd_emu10k1_synth_probe(struct device *_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct snd_seq_device *dev = to_seq_dev(_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct snd_emux *emux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct snd_emu10k1 *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct snd_emu10k1_synth_arg *arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) arg = SNDRV_SEQ_DEVICE_ARGPTR(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (arg == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (arg->seq_ports <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) return 0; /* nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) if (arg->max_voices < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) arg->max_voices = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) else if (arg->max_voices > 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) arg->max_voices = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (snd_emux_new(&emux) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) snd_emu10k1_ops_setup(emux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) hw = arg->hwptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) emux->hw = hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) emux->max_voices = arg->max_voices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) emux->num_ports = arg->seq_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) emux->pitch_shift = -501;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) emux->memhdr = hw->memhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* maximum two ports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) emux->midi_ports = arg->seq_ports < 2 ? arg->seq_ports : 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* audigy has two external midis */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) emux->midi_devidx = hw->audigy ? 2 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) emux->linear_panning = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) emux->hwdep_idx = 2; /* FIXED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (snd_emux_register(emux, dev->card, arg->index, "Emu10k1") < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) snd_emux_free(emux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) spin_lock_irqsave(&hw->voice_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) hw->synth = emux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) hw->get_synth_voice = snd_emu10k1_synth_get_voice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) spin_unlock_irqrestore(&hw->voice_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) dev->driver_data = emux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static int snd_emu10k1_synth_remove(struct device *_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct snd_seq_device *dev = to_seq_dev(_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct snd_emux *emux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct snd_emu10k1 *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (dev->driver_data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return 0; /* not registered actually */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) emux = dev->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) hw = emux->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) spin_lock_irqsave(&hw->voice_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) hw->synth = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) hw->get_synth_voice = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) spin_unlock_irqrestore(&hw->voice_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) snd_emux_free(emux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * INIT part
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static struct snd_seq_driver emu10k1_synth_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .probe = snd_emu10k1_synth_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .remove = snd_emu10k1_synth_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .id = SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .argsize = sizeof(struct snd_emu10k1_synth_arg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) module_snd_seq_driver(emu10k1_synth_driver);