blob: 3d72742b342fad200f351199e5806adb2f4f4dda [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * and (c) 1999 Steve Ratcliffe <steve@parabola.demon.co.uk>
4 * Copyright (C) 1999-2000 Takashi Iwai <tiwai@suse.de>
5 *
6 * Emu8000 synth plug-in routine
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include "emu8000_local.h"
24#include <linux/init.h>
25#include <sound/initval.h>
26
27MODULE_AUTHOR("Takashi Iwai, Steve Ratcliffe");
28MODULE_DESCRIPTION("Emu8000 synth plug-in routine");
29MODULE_LICENSE("GPL");
30
31/*----------------------------------------------------------------*/
32
33/*
34 * create a new hardware dependent device for Emu8000
35 */
Takashi Iwai029d64b2005-11-17 14:34:36 +010036static int snd_emu8000_new_device(struct snd_seq_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
Takashi Iwai029d64b2005-11-17 14:34:36 +010038 struct snd_emu8000 *hw;
39 struct snd_emux *emu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Takashi Iwai029d64b2005-11-17 14:34:36 +010041 hw = *(struct snd_emu8000**)SNDRV_SEQ_DEVICE_ARGPTR(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 if (hw == NULL)
43 return -EINVAL;
44
45 if (hw->emu)
46 return -EBUSY; /* already exists..? */
47
48 if (snd_emux_new(&emu) < 0)
49 return -ENOMEM;
50
51 hw->emu = emu;
52 snd_emu8000_ops_setup(hw);
53
54 emu->hw = hw;
55 emu->max_voices = EMU8000_DRAM_VOICES;
56 emu->num_ports = hw->seq_ports;
57
58 if (hw->memhdr) {
Takashi Iwai99b359b2005-10-20 18:26:44 +020059 snd_printk(KERN_ERR "memhdr is already initialized!?\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 snd_util_memhdr_free(hw->memhdr);
61 }
62 hw->memhdr = snd_util_memhdr_new(hw->mem_size);
63 if (hw->memhdr == NULL) {
64 snd_emux_free(emu);
65 hw->emu = NULL;
66 return -ENOMEM;
67 }
68
69 emu->memhdr = hw->memhdr;
70 emu->midi_ports = hw->seq_ports < 2 ? hw->seq_ports : 2; /* number of virmidi ports */
71 emu->midi_devidx = 1;
72 emu->linear_panning = 1;
73 emu->hwdep_idx = 2; /* FIXED */
74
75 if (snd_emux_register(emu, dev->card, hw->index, "Emu8000") < 0) {
76 snd_emux_free(emu);
77 snd_util_memhdr_free(hw->memhdr);
78 hw->emu = NULL;
79 hw->memhdr = NULL;
80 return -ENOMEM;
81 }
82
83 if (hw->mem_size > 0)
84 snd_emu8000_pcm_new(dev->card, hw, 1);
85
86 dev->driver_data = hw;
87
88 return 0;
89}
90
91
92/*
93 * free all resources
94 */
Takashi Iwai029d64b2005-11-17 14:34:36 +010095static int snd_emu8000_delete_device(struct snd_seq_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
Takashi Iwai029d64b2005-11-17 14:34:36 +010097 struct snd_emu8000 *hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99 if (dev->driver_data == NULL)
100 return 0; /* no synth was allocated actually */
101
102 hw = dev->driver_data;
103 if (hw->pcm)
104 snd_device_free(dev->card, hw->pcm);
105 if (hw->emu)
106 snd_emux_free(hw->emu);
107 if (hw->memhdr)
108 snd_util_memhdr_free(hw->memhdr);
109 hw->emu = NULL;
110 hw->memhdr = NULL;
111 return 0;
112}
113
114/*
115 * INIT part
116 */
117
118static int __init alsa_emu8000_init(void)
119{
120
Takashi Iwai029d64b2005-11-17 14:34:36 +0100121 static struct snd_seq_dev_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 snd_emu8000_new_device,
123 snd_emu8000_delete_device,
124 };
Takashi Iwai029d64b2005-11-17 14:34:36 +0100125 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
126 sizeof(struct snd_emu8000*));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
129static void __exit alsa_emu8000_exit(void)
130{
131 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_EMU8000);
132}
133
134module_init(alsa_emu8000_init)
135module_exit(alsa_emu8000_exit)