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