| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 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> | 
 | 23 |  | 
 | 24 | MODULE_AUTHOR("Takashi Iwai"); | 
 | 25 | MODULE_DESCRIPTION("Routines for control of EMU10K1 WaveTable synth"); | 
 | 26 | MODULE_LICENSE("GPL"); | 
 | 27 |  | 
 | 28 | /* | 
 | 29 |  * create a new hardware dependent device for Emu10k1 | 
 | 30 |  */ | 
| Takashi Iwai | eb4698f | 2005-11-17 14:50:13 +0100 | [diff] [blame] | 31 | static int snd_emu10k1_synth_new_device(struct snd_seq_device *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | { | 
| James Courtier-Dutton | c94fa4c | 2007-11-10 17:55:14 +0000 | [diff] [blame] | 33 | 	struct snd_emux *emux; | 
| Takashi Iwai | eb4698f | 2005-11-17 14:50:13 +0100 | [diff] [blame] | 34 | 	struct snd_emu10k1 *hw; | 
 | 35 | 	struct snd_emu10k1_synth_arg *arg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | 	unsigned long flags; | 
 | 37 |  | 
 | 38 | 	arg = SNDRV_SEQ_DEVICE_ARGPTR(dev); | 
 | 39 | 	if (arg == NULL) | 
 | 40 | 		return -EINVAL; | 
 | 41 |  | 
 | 42 | 	if (arg->seq_ports <= 0) | 
 | 43 | 		return 0; /* nothing */ | 
 | 44 | 	if (arg->max_voices < 1) | 
 | 45 | 		arg->max_voices = 1; | 
 | 46 | 	else if (arg->max_voices > 64) | 
 | 47 | 		arg->max_voices = 64; | 
 | 48 |  | 
| James Courtier-Dutton | c94fa4c | 2007-11-10 17:55:14 +0000 | [diff] [blame] | 49 | 	if (snd_emux_new(&emux) < 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | 		return -ENOMEM; | 
 | 51 |  | 
| James Courtier-Dutton | c94fa4c | 2007-11-10 17:55:14 +0000 | [diff] [blame] | 52 | 	snd_emu10k1_ops_setup(emux); | 
 | 53 | 	hw = arg->hwptr; | 
 | 54 | 	emux->hw = hw; | 
 | 55 | 	emux->max_voices = arg->max_voices; | 
 | 56 | 	emux->num_ports = arg->seq_ports; | 
 | 57 | 	emux->pitch_shift = -501; | 
 | 58 | 	emux->memhdr = hw->memhdr; | 
 | 59 | 	/* maximum two ports */ | 
 | 60 | 	emux->midi_ports = arg->seq_ports < 2 ? arg->seq_ports : 2; | 
 | 61 | 	/* audigy has two external midis */ | 
 | 62 | 	emux->midi_devidx = hw->audigy ? 2 : 1; | 
 | 63 | 	emux->linear_panning = 0; | 
 | 64 | 	emux->hwdep_idx = 2; /* FIXED */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 |  | 
| James Courtier-Dutton | c94fa4c | 2007-11-10 17:55:14 +0000 | [diff] [blame] | 66 | 	if (snd_emux_register(emux, dev->card, arg->index, "Emu10k1") < 0) { | 
 | 67 | 		snd_emux_free(emux); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | 		return -ENOMEM; | 
 | 69 | 	} | 
 | 70 |  | 
 | 71 | 	spin_lock_irqsave(&hw->voice_lock, flags); | 
| James Courtier-Dutton | c94fa4c | 2007-11-10 17:55:14 +0000 | [diff] [blame] | 72 | 	hw->synth = emux; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | 	hw->get_synth_voice = snd_emu10k1_synth_get_voice; | 
 | 74 | 	spin_unlock_irqrestore(&hw->voice_lock, flags); | 
 | 75 |  | 
| James Courtier-Dutton | c94fa4c | 2007-11-10 17:55:14 +0000 | [diff] [blame] | 76 | 	dev->driver_data = emux; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 |  | 
 | 78 | 	return 0; | 
 | 79 | } | 
 | 80 |  | 
| Takashi Iwai | eb4698f | 2005-11-17 14:50:13 +0100 | [diff] [blame] | 81 | static int snd_emu10k1_synth_delete_device(struct snd_seq_device *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { | 
| James Courtier-Dutton | c94fa4c | 2007-11-10 17:55:14 +0000 | [diff] [blame] | 83 | 	struct snd_emux *emux; | 
| Takashi Iwai | eb4698f | 2005-11-17 14:50:13 +0100 | [diff] [blame] | 84 | 	struct snd_emu10k1 *hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | 	unsigned long flags; | 
 | 86 |  | 
 | 87 | 	if (dev->driver_data == NULL) | 
 | 88 | 		return 0; /* not registered actually */ | 
 | 89 |  | 
| James Courtier-Dutton | c94fa4c | 2007-11-10 17:55:14 +0000 | [diff] [blame] | 90 | 	emux = dev->driver_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 |  | 
| James Courtier-Dutton | c94fa4c | 2007-11-10 17:55:14 +0000 | [diff] [blame] | 92 | 	hw = emux->hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | 	spin_lock_irqsave(&hw->voice_lock, flags); | 
 | 94 | 	hw->synth = NULL; | 
 | 95 | 	hw->get_synth_voice = NULL; | 
 | 96 | 	spin_unlock_irqrestore(&hw->voice_lock, flags); | 
 | 97 |  | 
| James Courtier-Dutton | c94fa4c | 2007-11-10 17:55:14 +0000 | [diff] [blame] | 98 | 	snd_emux_free(emux); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | 	return 0; | 
 | 100 | } | 
 | 101 |  | 
 | 102 | /* | 
 | 103 |  *  INIT part | 
 | 104 |  */ | 
 | 105 |  | 
 | 106 | static int __init alsa_emu10k1_synth_init(void) | 
 | 107 | { | 
 | 108 | 	 | 
| Takashi Iwai | eb4698f | 2005-11-17 14:50:13 +0100 | [diff] [blame] | 109 | 	static struct snd_seq_dev_ops ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | 		snd_emu10k1_synth_new_device, | 
 | 111 | 		snd_emu10k1_synth_delete_device, | 
 | 112 | 	}; | 
| Takashi Iwai | eb4698f | 2005-11-17 14:50:13 +0100 | [diff] [blame] | 113 | 	return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops, | 
 | 114 | 					      sizeof(struct snd_emu10k1_synth_arg)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } | 
 | 116 |  | 
 | 117 | static void __exit alsa_emu10k1_synth_exit(void) | 
 | 118 | { | 
 | 119 | 	snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH); | 
 | 120 | } | 
 | 121 |  | 
 | 122 | module_init(alsa_emu10k1_synth_init) | 
 | 123 | module_exit(alsa_emu10k1_synth_exit) |