blob: 4c41c903a840b5a6d3f802970b6ced5246b54462 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
3 *
4 * Routines for control of EMU10K1 WaveTable synth
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include "emu10k1_synth_local.h"
22#include <linux/init.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040023#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25MODULE_AUTHOR("Takashi Iwai");
26MODULE_DESCRIPTION("Routines for control of EMU10K1 WaveTable synth");
27MODULE_LICENSE("GPL");
28
29/*
30 * create a new hardware dependent device for Emu10k1
31 */
Takashi Iwaieb4698f2005-11-17 14:50:13 +010032static int snd_emu10k1_synth_new_device(struct snd_seq_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
James Courtier-Duttonc94fa4c2007-11-10 17:55:14 +000034 struct snd_emux *emux;
Takashi Iwaieb4698f2005-11-17 14:50:13 +010035 struct snd_emu10k1 *hw;
36 struct snd_emu10k1_synth_arg *arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 unsigned long flags;
38
39 arg = SNDRV_SEQ_DEVICE_ARGPTR(dev);
40 if (arg == NULL)
41 return -EINVAL;
42
43 if (arg->seq_ports <= 0)
44 return 0; /* nothing */
45 if (arg->max_voices < 1)
46 arg->max_voices = 1;
47 else if (arg->max_voices > 64)
48 arg->max_voices = 64;
49
James Courtier-Duttonc94fa4c2007-11-10 17:55:14 +000050 if (snd_emux_new(&emux) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 return -ENOMEM;
52
James Courtier-Duttonc94fa4c2007-11-10 17:55:14 +000053 snd_emu10k1_ops_setup(emux);
54 hw = arg->hwptr;
55 emux->hw = hw;
56 emux->max_voices = arg->max_voices;
57 emux->num_ports = arg->seq_ports;
58 emux->pitch_shift = -501;
59 emux->memhdr = hw->memhdr;
60 /* maximum two ports */
61 emux->midi_ports = arg->seq_ports < 2 ? arg->seq_ports : 2;
62 /* audigy has two external midis */
63 emux->midi_devidx = hw->audigy ? 2 : 1;
64 emux->linear_panning = 0;
65 emux->hwdep_idx = 2; /* FIXED */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
James Courtier-Duttonc94fa4c2007-11-10 17:55:14 +000067 if (snd_emux_register(emux, dev->card, arg->index, "Emu10k1") < 0) {
68 snd_emux_free(emux);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 return -ENOMEM;
70 }
71
72 spin_lock_irqsave(&hw->voice_lock, flags);
James Courtier-Duttonc94fa4c2007-11-10 17:55:14 +000073 hw->synth = emux;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 hw->get_synth_voice = snd_emu10k1_synth_get_voice;
75 spin_unlock_irqrestore(&hw->voice_lock, flags);
76
James Courtier-Duttonc94fa4c2007-11-10 17:55:14 +000077 dev->driver_data = emux;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79 return 0;
80}
81
Takashi Iwaieb4698f2005-11-17 14:50:13 +010082static int snd_emu10k1_synth_delete_device(struct snd_seq_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
James Courtier-Duttonc94fa4c2007-11-10 17:55:14 +000084 struct snd_emux *emux;
Takashi Iwaieb4698f2005-11-17 14:50:13 +010085 struct snd_emu10k1 *hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 unsigned long flags;
87
88 if (dev->driver_data == NULL)
89 return 0; /* not registered actually */
90
James Courtier-Duttonc94fa4c2007-11-10 17:55:14 +000091 emux = dev->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
James Courtier-Duttonc94fa4c2007-11-10 17:55:14 +000093 hw = emux->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 spin_lock_irqsave(&hw->voice_lock, flags);
95 hw->synth = NULL;
96 hw->get_synth_voice = NULL;
97 spin_unlock_irqrestore(&hw->voice_lock, flags);
98
James Courtier-Duttonc94fa4c2007-11-10 17:55:14 +000099 snd_emux_free(emux);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 return 0;
101}
102
103/*
104 * INIT part
105 */
106
107static int __init alsa_emu10k1_synth_init(void)
108{
109
Takashi Iwaieb4698f2005-11-17 14:50:13 +0100110 static struct snd_seq_dev_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 snd_emu10k1_synth_new_device,
112 snd_emu10k1_synth_delete_device,
113 };
Takashi Iwaieb4698f2005-11-17 14:50:13 +0100114 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
115 sizeof(struct snd_emu10k1_synth_arg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116}
117
118static void __exit alsa_emu10k1_synth_exit(void)
119{
120 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH);
121}
122
123module_init(alsa_emu10k1_synth_init)
124module_exit(alsa_emu10k1_synth_exit)