Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * OSS compatible sequencer driver | |
3 | * | |
4 | * registration of device and proc | |
5 | * | |
6 | * Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de> | |
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 <sound/driver.h> | |
24 | #include <linux/init.h> | |
25 | #include <linux/smp_lock.h> | |
26 | #include <linux/moduleparam.h> | |
27 | #include <sound/core.h> | |
28 | #include <sound/minors.h> | |
29 | #include <sound/initval.h> | |
30 | #include "seq_oss_device.h" | |
31 | #include "seq_oss_synth.h" | |
32 | ||
33 | /* | |
34 | * module option | |
35 | */ | |
36 | MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>"); | |
37 | MODULE_DESCRIPTION("OSS-compatible sequencer module"); | |
38 | MODULE_LICENSE("GPL"); | |
39 | /* Takashi says this is really only for sound-service-0-, but this is OK. */ | |
40 | MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_SEQUENCER); | |
41 | MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_MUSIC); | |
42 | ||
43 | #ifdef SNDRV_SEQ_OSS_DEBUG | |
44 | module_param(seq_oss_debug, int, 0644); | |
45 | MODULE_PARM_DESC(seq_oss_debug, "debug option"); | |
46 | int seq_oss_debug = 0; | |
47 | #endif | |
48 | ||
49 | ||
50 | /* | |
51 | * prototypes | |
52 | */ | |
53 | static int register_device(void); | |
54 | static void unregister_device(void); | |
55 | static int register_proc(void); | |
56 | static void unregister_proc(void); | |
57 | ||
58 | static int odev_open(struct inode *inode, struct file *file); | |
59 | static int odev_release(struct inode *inode, struct file *file); | |
60 | static ssize_t odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset); | |
61 | static ssize_t odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset); | |
62 | static long odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | |
63 | static unsigned int odev_poll(struct file *file, poll_table * wait); | |
64 | #ifdef CONFIG_PROC_FS | |
65 | static void info_read(snd_info_entry_t *entry, snd_info_buffer_t *buf); | |
66 | #endif | |
67 | ||
68 | ||
69 | /* | |
70 | * module interface | |
71 | */ | |
72 | ||
73 | static int __init alsa_seq_oss_init(void) | |
74 | { | |
75 | int rc; | |
76 | static snd_seq_dev_ops_t ops = { | |
77 | snd_seq_oss_synth_register, | |
78 | snd_seq_oss_synth_unregister, | |
79 | }; | |
80 | ||
81 | snd_seq_autoload_lock(); | |
82 | if ((rc = register_device()) < 0) | |
83 | goto error; | |
84 | if ((rc = register_proc()) < 0) { | |
85 | unregister_device(); | |
86 | goto error; | |
87 | } | |
88 | if ((rc = snd_seq_oss_create_client()) < 0) { | |
89 | unregister_proc(); | |
90 | unregister_device(); | |
91 | goto error; | |
92 | } | |
93 | ||
94 | if ((rc = snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OSS, &ops, | |
95 | sizeof(snd_seq_oss_reg_t))) < 0) { | |
96 | snd_seq_oss_delete_client(); | |
97 | unregister_proc(); | |
98 | unregister_device(); | |
99 | goto error; | |
100 | } | |
101 | ||
102 | /* success */ | |
103 | snd_seq_oss_synth_init(); | |
104 | ||
105 | error: | |
106 | snd_seq_autoload_unlock(); | |
107 | return rc; | |
108 | } | |
109 | ||
110 | static void __exit alsa_seq_oss_exit(void) | |
111 | { | |
112 | snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_OSS); | |
113 | snd_seq_oss_delete_client(); | |
114 | unregister_proc(); | |
115 | unregister_device(); | |
116 | } | |
117 | ||
118 | module_init(alsa_seq_oss_init) | |
119 | module_exit(alsa_seq_oss_exit) | |
120 | ||
121 | /* | |
122 | * ALSA minor device interface | |
123 | */ | |
124 | ||
125 | static DECLARE_MUTEX(register_mutex); | |
126 | ||
127 | static int | |
128 | odev_open(struct inode *inode, struct file *file) | |
129 | { | |
130 | int level, rc; | |
131 | ||
132 | if (iminor(inode) == SNDRV_MINOR_OSS_MUSIC) | |
133 | level = SNDRV_SEQ_OSS_MODE_MUSIC; | |
134 | else | |
135 | level = SNDRV_SEQ_OSS_MODE_SYNTH; | |
136 | ||
137 | down(®ister_mutex); | |
138 | rc = snd_seq_oss_open(file, level); | |
139 | up(®ister_mutex); | |
140 | ||
141 | return rc; | |
142 | } | |
143 | ||
144 | static int | |
145 | odev_release(struct inode *inode, struct file *file) | |
146 | { | |
147 | seq_oss_devinfo_t *dp; | |
148 | ||
149 | if ((dp = file->private_data) == NULL) | |
150 | return 0; | |
151 | ||
152 | snd_seq_oss_drain_write(dp); | |
153 | ||
154 | down(®ister_mutex); | |
155 | snd_seq_oss_release(dp); | |
156 | up(®ister_mutex); | |
157 | ||
158 | return 0; | |
159 | } | |
160 | ||
161 | static ssize_t | |
162 | odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset) | |
163 | { | |
164 | seq_oss_devinfo_t *dp; | |
165 | dp = file->private_data; | |
166 | snd_assert(dp != NULL, return -EIO); | |
167 | return snd_seq_oss_read(dp, buf, count); | |
168 | } | |
169 | ||
170 | ||
171 | static ssize_t | |
172 | odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset) | |
173 | { | |
174 | seq_oss_devinfo_t *dp; | |
175 | dp = file->private_data; | |
176 | snd_assert(dp != NULL, return -EIO); | |
177 | return snd_seq_oss_write(dp, buf, count, file); | |
178 | } | |
179 | ||
180 | static long | |
181 | odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
182 | { | |
183 | seq_oss_devinfo_t *dp; | |
184 | dp = file->private_data; | |
185 | snd_assert(dp != NULL, return -EIO); | |
186 | return snd_seq_oss_ioctl(dp, cmd, arg); | |
187 | } | |
188 | ||
189 | #ifdef CONFIG_COMPAT | |
190 | #define odev_ioctl_compat odev_ioctl | |
191 | #else | |
192 | #define odev_ioctl_compat NULL | |
193 | #endif | |
194 | ||
195 | static unsigned int | |
196 | odev_poll(struct file *file, poll_table * wait) | |
197 | { | |
198 | seq_oss_devinfo_t *dp; | |
199 | dp = file->private_data; | |
200 | snd_assert(dp != NULL, return 0); | |
201 | return snd_seq_oss_poll(dp, file, wait); | |
202 | } | |
203 | ||
204 | /* | |
205 | * registration of sequencer minor device | |
206 | */ | |
207 | ||
208 | static struct file_operations seq_oss_f_ops = | |
209 | { | |
210 | .owner = THIS_MODULE, | |
211 | .read = odev_read, | |
212 | .write = odev_write, | |
213 | .open = odev_open, | |
214 | .release = odev_release, | |
215 | .poll = odev_poll, | |
216 | .unlocked_ioctl = odev_ioctl, | |
217 | .compat_ioctl = odev_ioctl_compat, | |
218 | }; | |
219 | ||
220 | static snd_minor_t seq_oss_reg = { | |
221 | .comment = "sequencer", | |
222 | .f_ops = &seq_oss_f_ops, | |
223 | }; | |
224 | ||
225 | static int __init | |
226 | register_device(void) | |
227 | { | |
228 | int rc; | |
229 | ||
230 | down(®ister_mutex); | |
231 | if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, | |
232 | NULL, 0, | |
233 | &seq_oss_reg, | |
234 | SNDRV_SEQ_OSS_DEVNAME)) < 0) { | |
235 | snd_printk(KERN_ERR "can't register device seq\n"); | |
236 | up(®ister_mutex); | |
237 | return rc; | |
238 | } | |
239 | if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, | |
240 | NULL, 0, | |
241 | &seq_oss_reg, | |
242 | SNDRV_SEQ_OSS_DEVNAME)) < 0) { | |
243 | snd_printk(KERN_ERR "can't register device music\n"); | |
244 | snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0); | |
245 | up(®ister_mutex); | |
246 | return rc; | |
247 | } | |
248 | debug_printk(("device registered\n")); | |
249 | up(®ister_mutex); | |
250 | return 0; | |
251 | } | |
252 | ||
253 | static void | |
254 | unregister_device(void) | |
255 | { | |
256 | down(®ister_mutex); | |
257 | debug_printk(("device unregistered\n")); | |
258 | if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, NULL, 0) < 0) | |
259 | snd_printk(KERN_ERR "error unregister device music\n"); | |
260 | if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0) < 0) | |
261 | snd_printk(KERN_ERR "error unregister device seq\n"); | |
262 | up(®ister_mutex); | |
263 | } | |
264 | ||
265 | /* | |
266 | * /proc interface | |
267 | */ | |
268 | ||
269 | #ifdef CONFIG_PROC_FS | |
270 | ||
271 | static snd_info_entry_t *info_entry; | |
272 | ||
273 | static void | |
274 | info_read(snd_info_entry_t *entry, snd_info_buffer_t *buf) | |
275 | { | |
276 | down(®ister_mutex); | |
277 | snd_iprintf(buf, "OSS sequencer emulation version %s\n", SNDRV_SEQ_OSS_VERSION_STR); | |
278 | snd_seq_oss_system_info_read(buf); | |
279 | snd_seq_oss_synth_info_read(buf); | |
280 | snd_seq_oss_midi_info_read(buf); | |
281 | up(®ister_mutex); | |
282 | } | |
283 | ||
284 | #endif /* CONFIG_PROC_FS */ | |
285 | ||
286 | static int __init | |
287 | register_proc(void) | |
288 | { | |
289 | #ifdef CONFIG_PROC_FS | |
290 | snd_info_entry_t *entry; | |
291 | ||
292 | entry = snd_info_create_module_entry(THIS_MODULE, SNDRV_SEQ_OSS_PROCNAME, snd_seq_root); | |
293 | if (entry == NULL) | |
294 | return -ENOMEM; | |
295 | ||
296 | entry->content = SNDRV_INFO_CONTENT_TEXT; | |
297 | entry->private_data = NULL; | |
298 | entry->c.text.read_size = 1024; | |
299 | entry->c.text.read = info_read; | |
300 | if (snd_info_register(entry) < 0) { | |
301 | snd_info_free_entry(entry); | |
302 | return -ENOMEM; | |
303 | } | |
304 | info_entry = entry; | |
305 | #endif | |
306 | return 0; | |
307 | } | |
308 | ||
309 | static void | |
310 | unregister_proc(void) | |
311 | { | |
312 | #ifdef CONFIG_PROC_FS | |
313 | if (info_entry) | |
314 | snd_info_unregister(info_entry); | |
315 | info_entry = NULL; | |
316 | #endif | |
317 | } |