2 * OSS compatible sequencer driver
4 * registration of device and proc
6 * Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de>
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.
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.
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
23 #include <sound/driver.h>
24 #include <linux/init.h>
25 #include <sound/core.h>
26 #include <sound/minors.h>
27 #include <sound/initval.h>
28 #include "seq_oss_device.h"
29 #include "seq_oss_synth.h"
34 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
35 MODULE_DESCRIPTION("OSS-compatible sequencer module");
36 MODULE_LICENSE("GPL");
37 MODULE_CLASSES("{sound}");
38 /* Takashi says this is really only for sound-service-0-, but this is OK. */
39 MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_SEQUENCER);
40 MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_MUSIC);
42 #ifdef SNDRV_SEQ_OSS_DEBUG
43 MODULE_PARM(seq_oss_debug, "i");
44 MODULE_PARM_DESC(seq_oss_debug, "debug option");
45 int seq_oss_debug = 0;
52 static int register_device(void);
53 static void unregister_device(void);
54 static int register_proc(void);
55 static void unregister_proc(void);
57 static int odev_open(struct inode *inode, struct file *file);
58 static int odev_release(struct inode *inode, struct file *file);
59 static ssize_t odev_read(struct file *file, char *buf, size_t count, loff_t *offset);
60 static ssize_t odev_write(struct file *file, const char *buf, size_t count, loff_t *offset);
61 static int odev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
62 static unsigned int odev_poll(struct file *file, poll_table * wait);
64 static void info_read(snd_info_entry_t *entry, snd_info_buffer_t *buf);
72 static int __init alsa_seq_oss_init(void)
75 static snd_seq_dev_ops_t ops = {
76 snd_seq_oss_synth_register,
77 snd_seq_oss_synth_unregister,
80 if ((rc = register_device()) < 0)
82 if ((rc = register_proc()) < 0) {
86 if ((rc = snd_seq_oss_create_client()) < 0) {
92 if ((rc = snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OSS, &ops,
93 sizeof(snd_seq_oss_reg_t))) < 0) {
94 snd_seq_oss_delete_client();
101 snd_seq_oss_synth_init();
105 static void __exit alsa_seq_oss_exit(void)
107 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_OSS);
108 snd_seq_oss_delete_client();
113 module_init(alsa_seq_oss_init)
114 module_exit(alsa_seq_oss_exit)
117 * ALSA minor device interface
120 static DECLARE_MUTEX(register_mutex);
123 odev_open(struct inode *inode, struct file *file)
127 if (iminor(inode) == SNDRV_MINOR_OSS_MUSIC)
128 level = SNDRV_SEQ_OSS_MODE_MUSIC;
130 level = SNDRV_SEQ_OSS_MODE_SYNTH;
132 down(®ister_mutex);
133 rc = snd_seq_oss_open(file, level);
140 odev_release(struct inode *inode, struct file *file)
142 seq_oss_devinfo_t *dp;
144 if ((dp = file->private_data) == NULL)
147 snd_seq_oss_drain_write(dp);
149 down(®ister_mutex);
150 snd_seq_oss_release(dp);
157 odev_read(struct file *file, char *buf, size_t count, loff_t *offset)
159 seq_oss_devinfo_t *dp;
160 dp = file->private_data;
161 snd_assert(dp != NULL, return -EIO);
162 return snd_seq_oss_read(dp, buf, count);
167 odev_write(struct file *file, const char *buf, size_t count, loff_t *offset)
169 seq_oss_devinfo_t *dp;
170 dp = file->private_data;
171 snd_assert(dp != NULL, return -EIO);
172 return snd_seq_oss_write(dp, buf, count, file);
176 odev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
178 seq_oss_devinfo_t *dp;
179 dp = file->private_data;
180 snd_assert(dp != NULL, return -EIO);
181 return snd_seq_oss_ioctl(dp, cmd, arg);
186 odev_poll(struct file *file, poll_table * wait)
188 seq_oss_devinfo_t *dp;
189 dp = file->private_data;
190 snd_assert(dp != NULL, return 0);
191 return snd_seq_oss_poll(dp, file, wait);
195 * registration of sequencer minor device
198 static struct file_operations seq_oss_f_ops =
200 .owner = THIS_MODULE,
204 .release = odev_release,
209 static snd_minor_t seq_oss_reg = {
210 .comment = "sequencer",
211 .f_ops = &seq_oss_f_ops,
215 register_device(void)
219 down(®ister_mutex);
220 if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER,
223 SNDRV_SEQ_OSS_DEVNAME)) < 0) {
224 snd_printk(KERN_ERR "can't register device seq\n");
228 if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC,
231 SNDRV_SEQ_OSS_DEVNAME)) < 0) {
232 snd_printk(KERN_ERR "can't register device music\n");
233 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0);
237 debug_printk(("device registered\n"));
243 unregister_device(void)
245 down(®ister_mutex);
246 debug_printk(("device unregistered\n"));
247 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, NULL, 0) < 0)
248 snd_printk(KERN_ERR "error unregister device music\n");
249 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0) < 0)
250 snd_printk(KERN_ERR "error unregister device seq\n");
258 #ifdef CONFIG_PROC_FS
260 static snd_info_entry_t *info_entry;
263 info_read(snd_info_entry_t *entry, snd_info_buffer_t *buf)
265 down(®ister_mutex);
266 snd_iprintf(buf, "OSS sequencer emulation version %s\n", SNDRV_SEQ_OSS_VERSION_STR);
267 snd_seq_oss_system_info_read(buf);
268 snd_seq_oss_synth_info_read(buf);
269 snd_seq_oss_midi_info_read(buf);
273 #endif /* CONFIG_PROC_FS */
278 #ifdef CONFIG_PROC_FS
279 snd_info_entry_t *entry;
281 entry = snd_info_create_module_entry(THIS_MODULE, SNDRV_SEQ_OSS_PROCNAME, snd_seq_root);
285 entry->content = SNDRV_INFO_CONTENT_TEXT;
286 entry->private_data = NULL;
287 entry->c.text.read_size = 1024;
288 entry->c.text.read = info_read;
289 if (snd_info_register(entry) < 0) {
290 snd_info_free_entry(entry);
299 unregister_proc(void)
301 #ifdef CONFIG_PROC_FS
303 snd_info_unregister(info_entry);