1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * OSS compatible sequencer driver
5 * registration of device and proc
7 * Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de>
10 #include <linux/init.h>
11 #include <linux/module.h>
12 #include <linux/mutex.h>
13 #include <linux/compat.h>
14 #include <sound/core.h>
15 #include <sound/minors.h>
16 #include <sound/initval.h>
17 #include "seq_oss_device.h"
18 #include "seq_oss_synth.h"
23 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
24 MODULE_DESCRIPTION("OSS-compatible sequencer module");
25 MODULE_LICENSE("GPL");
26 /* Takashi says this is really only for sound-service-0-, but this is OK. */
27 MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_SEQUENCER);
28 MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_MUSIC);
34 static int register_device(void);
35 static void unregister_device(void);
36 #ifdef CONFIG_SND_PROC_FS
37 static int register_proc(void);
38 static void unregister_proc(void);
40 static inline int register_proc(void) { return 0; }
41 static inline void unregister_proc(void) {}
44 static int odev_open(struct inode *inode, struct file *file);
45 static int odev_release(struct inode *inode, struct file *file);
46 static ssize_t odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset);
47 static ssize_t odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset);
48 static long odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
49 static __poll_t odev_poll(struct file *file, poll_table * wait);
56 static struct snd_seq_driver seq_oss_synth_driver = {
58 .name = KBUILD_MODNAME,
59 .probe = snd_seq_oss_synth_probe,
60 .remove = snd_seq_oss_synth_remove,
62 .id = SNDRV_SEQ_DEV_ID_OSS,
63 .argsize = sizeof(struct snd_seq_oss_reg),
66 static int __init alsa_seq_oss_init(void)
70 rc = register_device();
78 rc = snd_seq_oss_create_client();
85 rc = snd_seq_driver_register(&seq_oss_synth_driver);
87 snd_seq_oss_delete_client();
94 snd_seq_oss_synth_init();
100 static void __exit alsa_seq_oss_exit(void)
102 snd_seq_driver_unregister(&seq_oss_synth_driver);
103 snd_seq_oss_delete_client();
108 module_init(alsa_seq_oss_init)
109 module_exit(alsa_seq_oss_exit)
112 * ALSA minor device interface
115 static DEFINE_MUTEX(register_mutex);
118 odev_open(struct inode *inode, struct file *file)
122 if (iminor(inode) == SNDRV_MINOR_OSS_MUSIC)
123 level = SNDRV_SEQ_OSS_MODE_MUSIC;
125 level = SNDRV_SEQ_OSS_MODE_SYNTH;
127 mutex_lock(®ister_mutex);
128 rc = snd_seq_oss_open(file, level);
129 mutex_unlock(®ister_mutex);
135 odev_release(struct inode *inode, struct file *file)
137 struct seq_oss_devinfo *dp;
139 dp = file->private_data;
143 mutex_lock(®ister_mutex);
144 snd_seq_oss_release(dp);
145 mutex_unlock(®ister_mutex);
151 odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
153 struct seq_oss_devinfo *dp;
154 dp = file->private_data;
157 return snd_seq_oss_read(dp, buf, count);
162 odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
164 struct seq_oss_devinfo *dp;
165 dp = file->private_data;
168 return snd_seq_oss_write(dp, buf, count, file);
172 odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
174 struct seq_oss_devinfo *dp;
177 dp = file->private_data;
181 if (cmd != SNDCTL_SEQ_SYNC &&
182 mutex_lock_interruptible(®ister_mutex))
184 rc = snd_seq_oss_ioctl(dp, cmd, arg);
185 if (cmd != SNDCTL_SEQ_SYNC)
186 mutex_unlock(®ister_mutex);
191 static long odev_ioctl_compat(struct file *file, unsigned int cmd,
194 return odev_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
197 #define odev_ioctl_compat NULL
201 odev_poll(struct file *file, poll_table * wait)
203 struct seq_oss_devinfo *dp;
204 dp = file->private_data;
207 return snd_seq_oss_poll(dp, file, wait);
211 * registration of sequencer minor device
214 static const struct file_operations seq_oss_f_ops =
216 .owner = THIS_MODULE,
220 .release = odev_release,
222 .unlocked_ioctl = odev_ioctl,
223 .compat_ioctl = odev_ioctl_compat,
224 .llseek = noop_llseek,
228 register_device(void)
232 mutex_lock(®ister_mutex);
233 rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER,
235 &seq_oss_f_ops, NULL);
237 pr_err("ALSA: seq_oss: can't register device seq\n");
238 mutex_unlock(®ister_mutex);
241 rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC,
243 &seq_oss_f_ops, NULL);
245 pr_err("ALSA: seq_oss: can't register device music\n");
246 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0);
247 mutex_unlock(®ister_mutex);
250 mutex_unlock(®ister_mutex);
255 unregister_device(void)
257 mutex_lock(®ister_mutex);
258 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, NULL, 0) < 0)
259 pr_err("ALSA: seq_oss: error unregister device music\n");
260 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0) < 0)
261 pr_err("ALSA: seq_oss: error unregister device seq\n");
262 mutex_unlock(®ister_mutex);
269 #ifdef CONFIG_SND_PROC_FS
271 static struct snd_info_entry *info_entry;
274 info_read(struct snd_info_entry *entry, struct snd_info_buffer *buf)
276 mutex_lock(®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 mutex_unlock(®ister_mutex);
288 struct snd_info_entry *entry;
290 entry = snd_info_create_module_entry(THIS_MODULE, SNDRV_SEQ_OSS_PROCNAME, snd_seq_root);
294 entry->content = SNDRV_INFO_CONTENT_TEXT;
295 entry->private_data = NULL;
296 entry->c.text.read = info_read;
297 if (snd_info_register(entry) < 0) {
298 snd_info_free_entry(entry);
306 unregister_proc(void)
308 snd_info_free_entry(info_entry);
311 #endif /* CONFIG_SND_PROC_FS */