WIP FPC-III support
[linux/fpc-iii.git] / sound / core / seq / oss / seq_oss.c
blob250a92b1872658f74700a891bbcbeac09998682f
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * OSS compatible sequencer driver
5 * registration of device and proc
7 * Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de>
8 */
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"
21 * module option
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);
32 * prototypes
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);
39 #else
40 static inline int register_proc(void) { return 0; }
41 static inline void unregister_proc(void) {}
42 #endif
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);
53 * module interface
56 static struct snd_seq_driver seq_oss_synth_driver = {
57 .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)
68 int rc;
70 if ((rc = register_device()) < 0)
71 goto error;
72 if ((rc = register_proc()) < 0) {
73 unregister_device();
74 goto error;
76 if ((rc = snd_seq_oss_create_client()) < 0) {
77 unregister_proc();
78 unregister_device();
79 goto error;
82 rc = snd_seq_driver_register(&seq_oss_synth_driver);
83 if (rc < 0) {
84 snd_seq_oss_delete_client();
85 unregister_proc();
86 unregister_device();
87 goto error;
90 /* success */
91 snd_seq_oss_synth_init();
93 error:
94 return rc;
97 static void __exit alsa_seq_oss_exit(void)
99 snd_seq_driver_unregister(&seq_oss_synth_driver);
100 snd_seq_oss_delete_client();
101 unregister_proc();
102 unregister_device();
105 module_init(alsa_seq_oss_init)
106 module_exit(alsa_seq_oss_exit)
109 * ALSA minor device interface
112 static DEFINE_MUTEX(register_mutex);
114 static int
115 odev_open(struct inode *inode, struct file *file)
117 int level, rc;
119 if (iminor(inode) == SNDRV_MINOR_OSS_MUSIC)
120 level = SNDRV_SEQ_OSS_MODE_MUSIC;
121 else
122 level = SNDRV_SEQ_OSS_MODE_SYNTH;
124 mutex_lock(&register_mutex);
125 rc = snd_seq_oss_open(file, level);
126 mutex_unlock(&register_mutex);
128 return rc;
131 static int
132 odev_release(struct inode *inode, struct file *file)
134 struct seq_oss_devinfo *dp;
136 if ((dp = file->private_data) == NULL)
137 return 0;
139 mutex_lock(&register_mutex);
140 snd_seq_oss_release(dp);
141 mutex_unlock(&register_mutex);
143 return 0;
146 static ssize_t
147 odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
149 struct seq_oss_devinfo *dp;
150 dp = file->private_data;
151 if (snd_BUG_ON(!dp))
152 return -ENXIO;
153 return snd_seq_oss_read(dp, buf, count);
157 static ssize_t
158 odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
160 struct seq_oss_devinfo *dp;
161 dp = file->private_data;
162 if (snd_BUG_ON(!dp))
163 return -ENXIO;
164 return snd_seq_oss_write(dp, buf, count, file);
167 static long
168 odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
170 struct seq_oss_devinfo *dp;
171 long rc;
173 dp = file->private_data;
174 if (snd_BUG_ON(!dp))
175 return -ENXIO;
177 if (cmd != SNDCTL_SEQ_SYNC &&
178 mutex_lock_interruptible(&register_mutex))
179 return -ERESTARTSYS;
180 rc = snd_seq_oss_ioctl(dp, cmd, arg);
181 if (cmd != SNDCTL_SEQ_SYNC)
182 mutex_unlock(&register_mutex);
183 return rc;
186 #ifdef CONFIG_COMPAT
187 static long odev_ioctl_compat(struct file *file, unsigned int cmd,
188 unsigned long arg)
190 return odev_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
192 #else
193 #define odev_ioctl_compat NULL
194 #endif
196 static __poll_t
197 odev_poll(struct file *file, poll_table * wait)
199 struct seq_oss_devinfo *dp;
200 dp = file->private_data;
201 if (snd_BUG_ON(!dp))
202 return EPOLLERR;
203 return snd_seq_oss_poll(dp, file, wait);
207 * registration of sequencer minor device
210 static const struct file_operations seq_oss_f_ops =
212 .owner = THIS_MODULE,
213 .read = odev_read,
214 .write = odev_write,
215 .open = odev_open,
216 .release = odev_release,
217 .poll = odev_poll,
218 .unlocked_ioctl = odev_ioctl,
219 .compat_ioctl = odev_ioctl_compat,
220 .llseek = noop_llseek,
223 static int __init
224 register_device(void)
226 int rc;
228 mutex_lock(&register_mutex);
229 if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER,
230 NULL, 0,
231 &seq_oss_f_ops, NULL)) < 0) {
232 pr_err("ALSA: seq_oss: can't register device seq\n");
233 mutex_unlock(&register_mutex);
234 return rc;
236 if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC,
237 NULL, 0,
238 &seq_oss_f_ops, NULL)) < 0) {
239 pr_err("ALSA: seq_oss: can't register device music\n");
240 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0);
241 mutex_unlock(&register_mutex);
242 return rc;
244 mutex_unlock(&register_mutex);
245 return 0;
248 static void
249 unregister_device(void)
251 mutex_lock(&register_mutex);
252 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, NULL, 0) < 0)
253 pr_err("ALSA: seq_oss: error unregister device music\n");
254 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0) < 0)
255 pr_err("ALSA: seq_oss: error unregister device seq\n");
256 mutex_unlock(&register_mutex);
260 * /proc interface
263 #ifdef CONFIG_SND_PROC_FS
265 static struct snd_info_entry *info_entry;
267 static void
268 info_read(struct snd_info_entry *entry, struct snd_info_buffer *buf)
270 mutex_lock(&register_mutex);
271 snd_iprintf(buf, "OSS sequencer emulation version %s\n", SNDRV_SEQ_OSS_VERSION_STR);
272 snd_seq_oss_system_info_read(buf);
273 snd_seq_oss_synth_info_read(buf);
274 snd_seq_oss_midi_info_read(buf);
275 mutex_unlock(&register_mutex);
279 static int __init
280 register_proc(void)
282 struct snd_info_entry *entry;
284 entry = snd_info_create_module_entry(THIS_MODULE, SNDRV_SEQ_OSS_PROCNAME, snd_seq_root);
285 if (entry == NULL)
286 return -ENOMEM;
288 entry->content = SNDRV_INFO_CONTENT_TEXT;
289 entry->private_data = NULL;
290 entry->c.text.read = info_read;
291 if (snd_info_register(entry) < 0) {
292 snd_info_free_entry(entry);
293 return -ENOMEM;
295 info_entry = entry;
296 return 0;
299 static void
300 unregister_proc(void)
302 snd_info_free_entry(info_entry);
303 info_entry = NULL;
305 #endif /* CONFIG_SND_PROC_FS */