ARM: dts: Kirkwood: Fix QNAP TS219 power-off
[linux/fpc-iii.git] / sound / core / seq / oss / seq_oss.c
blob7354b8bed86099072227fba427a355acf868cba8
1 /*
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 <linux/init.h>
24 #include <linux/module.h>
25 #include <linux/mutex.h>
26 #include <sound/core.h>
27 #include <sound/minors.h>
28 #include <sound/initval.h>
29 #include "seq_oss_device.h"
30 #include "seq_oss_synth.h"
33 * module option
35 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
36 MODULE_DESCRIPTION("OSS-compatible sequencer module");
37 MODULE_LICENSE("GPL");
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);
44 * prototypes
46 static int register_device(void);
47 static void unregister_device(void);
48 #ifdef CONFIG_SND_PROC_FS
49 static int register_proc(void);
50 static void unregister_proc(void);
51 #else
52 static inline int register_proc(void) { return 0; }
53 static inline void unregister_proc(void) {}
54 #endif
56 static int odev_open(struct inode *inode, struct file *file);
57 static int odev_release(struct inode *inode, struct file *file);
58 static ssize_t odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset);
59 static ssize_t odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset);
60 static long odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
61 static unsigned int odev_poll(struct file *file, poll_table * wait);
65 * module interface
68 static struct snd_seq_driver seq_oss_synth_driver = {
69 .driver = {
70 .name = KBUILD_MODNAME,
71 .probe = snd_seq_oss_synth_probe,
72 .remove = snd_seq_oss_synth_remove,
74 .id = SNDRV_SEQ_DEV_ID_OSS,
75 .argsize = sizeof(struct snd_seq_oss_reg),
78 static int __init alsa_seq_oss_init(void)
80 int rc;
82 if ((rc = register_device()) < 0)
83 goto error;
84 if ((rc = register_proc()) < 0) {
85 unregister_device();
86 goto error;
88 if ((rc = snd_seq_oss_create_client()) < 0) {
89 unregister_proc();
90 unregister_device();
91 goto error;
94 rc = snd_seq_driver_register(&seq_oss_synth_driver);
95 if (rc < 0) {
96 snd_seq_oss_delete_client();
97 unregister_proc();
98 unregister_device();
99 goto error;
102 /* success */
103 snd_seq_oss_synth_init();
105 error:
106 return rc;
109 static void __exit alsa_seq_oss_exit(void)
111 snd_seq_driver_unregister(&seq_oss_synth_driver);
112 snd_seq_oss_delete_client();
113 unregister_proc();
114 unregister_device();
117 module_init(alsa_seq_oss_init)
118 module_exit(alsa_seq_oss_exit)
121 * ALSA minor device interface
124 static DEFINE_MUTEX(register_mutex);
126 static int
127 odev_open(struct inode *inode, struct file *file)
129 int level, rc;
131 if (iminor(inode) == SNDRV_MINOR_OSS_MUSIC)
132 level = SNDRV_SEQ_OSS_MODE_MUSIC;
133 else
134 level = SNDRV_SEQ_OSS_MODE_SYNTH;
136 mutex_lock(&register_mutex);
137 rc = snd_seq_oss_open(file, level);
138 mutex_unlock(&register_mutex);
140 return rc;
143 static int
144 odev_release(struct inode *inode, struct file *file)
146 struct seq_oss_devinfo *dp;
148 if ((dp = file->private_data) == NULL)
149 return 0;
151 snd_seq_oss_drain_write(dp);
153 mutex_lock(&register_mutex);
154 snd_seq_oss_release(dp);
155 mutex_unlock(&register_mutex);
157 return 0;
160 static ssize_t
161 odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
163 struct seq_oss_devinfo *dp;
164 dp = file->private_data;
165 if (snd_BUG_ON(!dp))
166 return -ENXIO;
167 return snd_seq_oss_read(dp, buf, count);
171 static ssize_t
172 odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
174 struct seq_oss_devinfo *dp;
175 dp = file->private_data;
176 if (snd_BUG_ON(!dp))
177 return -ENXIO;
178 return snd_seq_oss_write(dp, buf, count, file);
181 static long
182 odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
184 struct seq_oss_devinfo *dp;
185 dp = file->private_data;
186 if (snd_BUG_ON(!dp))
187 return -ENXIO;
188 return snd_seq_oss_ioctl(dp, cmd, arg);
191 #ifdef CONFIG_COMPAT
192 #define odev_ioctl_compat odev_ioctl
193 #else
194 #define odev_ioctl_compat NULL
195 #endif
197 static unsigned int
198 odev_poll(struct file *file, poll_table * wait)
200 struct seq_oss_devinfo *dp;
201 dp = file->private_data;
202 if (snd_BUG_ON(!dp))
203 return -ENXIO;
204 return snd_seq_oss_poll(dp, file, wait);
208 * registration of sequencer minor device
211 static const struct file_operations seq_oss_f_ops =
213 .owner = THIS_MODULE,
214 .read = odev_read,
215 .write = odev_write,
216 .open = odev_open,
217 .release = odev_release,
218 .poll = odev_poll,
219 .unlocked_ioctl = odev_ioctl,
220 .compat_ioctl = odev_ioctl_compat,
221 .llseek = noop_llseek,
224 static int __init
225 register_device(void)
227 int rc;
229 mutex_lock(&register_mutex);
230 if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER,
231 NULL, 0,
232 &seq_oss_f_ops, NULL)) < 0) {
233 pr_err("ALSA: seq_oss: can't register device seq\n");
234 mutex_unlock(&register_mutex);
235 return rc;
237 if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC,
238 NULL, 0,
239 &seq_oss_f_ops, NULL)) < 0) {
240 pr_err("ALSA: seq_oss: can't register device music\n");
241 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0);
242 mutex_unlock(&register_mutex);
243 return rc;
245 mutex_unlock(&register_mutex);
246 return 0;
249 static void
250 unregister_device(void)
252 mutex_lock(&register_mutex);
253 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, NULL, 0) < 0)
254 pr_err("ALSA: seq_oss: error unregister device music\n");
255 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0) < 0)
256 pr_err("ALSA: seq_oss: error unregister device seq\n");
257 mutex_unlock(&register_mutex);
261 * /proc interface
264 #ifdef CONFIG_SND_PROC_FS
266 static struct snd_info_entry *info_entry;
268 static void
269 info_read(struct snd_info_entry *entry, struct snd_info_buffer *buf)
271 mutex_lock(&register_mutex);
272 snd_iprintf(buf, "OSS sequencer emulation version %s\n", SNDRV_SEQ_OSS_VERSION_STR);
273 snd_seq_oss_system_info_read(buf);
274 snd_seq_oss_synth_info_read(buf);
275 snd_seq_oss_midi_info_read(buf);
276 mutex_unlock(&register_mutex);
280 static int __init
281 register_proc(void)
283 struct snd_info_entry *entry;
285 entry = snd_info_create_module_entry(THIS_MODULE, SNDRV_SEQ_OSS_PROCNAME, snd_seq_root);
286 if (entry == NULL)
287 return -ENOMEM;
289 entry->content = SNDRV_INFO_CONTENT_TEXT;
290 entry->private_data = NULL;
291 entry->c.text.read = info_read;
292 if (snd_info_register(entry) < 0) {
293 snd_info_free_entry(entry);
294 return -ENOMEM;
296 info_entry = entry;
297 return 0;
300 static void
301 unregister_proc(void)
303 snd_info_free_entry(info_entry);
304 info_entry = NULL;
306 #endif /* CONFIG_SND_PROC_FS */