rtc: rtc-omap footprint shrinkage
[linux-ginger.git] / sound / core / seq / oss / seq_oss.c
blob777796e9449047c2ec2b0ec851638cac9733fd7e
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/moduleparam.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);
42 #ifdef SNDRV_SEQ_OSS_DEBUG
43 module_param(seq_oss_debug, int, 0644);
44 MODULE_PARM_DESC(seq_oss_debug, "debug option");
45 int seq_oss_debug = 0;
46 #endif
50 * prototypes
52 static int register_device(void);
53 static void unregister_device(void);
54 #ifdef CONFIG_PROC_FS
55 static int register_proc(void);
56 static void unregister_proc(void);
57 #else
58 static inline int register_proc(void) { return 0; }
59 static inline void unregister_proc(void) {}
60 #endif
62 static int odev_open(struct inode *inode, struct file *file);
63 static int odev_release(struct inode *inode, struct file *file);
64 static ssize_t odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset);
65 static ssize_t odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset);
66 static long odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
67 static unsigned int odev_poll(struct file *file, poll_table * wait);
71 * module interface
74 static int __init alsa_seq_oss_init(void)
76 int rc;
77 static struct snd_seq_dev_ops ops = {
78 snd_seq_oss_synth_register,
79 snd_seq_oss_synth_unregister,
82 snd_seq_autoload_lock();
83 if ((rc = register_device()) < 0)
84 goto error;
85 if ((rc = register_proc()) < 0) {
86 unregister_device();
87 goto error;
89 if ((rc = snd_seq_oss_create_client()) < 0) {
90 unregister_proc();
91 unregister_device();
92 goto error;
95 if ((rc = snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OSS, &ops,
96 sizeof(struct snd_seq_oss_reg))) < 0) {
97 snd_seq_oss_delete_client();
98 unregister_proc();
99 unregister_device();
100 goto error;
103 /* success */
104 snd_seq_oss_synth_init();
106 error:
107 snd_seq_autoload_unlock();
108 return rc;
111 static void __exit alsa_seq_oss_exit(void)
113 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_OSS);
114 snd_seq_oss_delete_client();
115 unregister_proc();
116 unregister_device();
119 module_init(alsa_seq_oss_init)
120 module_exit(alsa_seq_oss_exit)
123 * ALSA minor device interface
126 static DEFINE_MUTEX(register_mutex);
128 static int
129 odev_open(struct inode *inode, struct file *file)
131 int level, rc;
133 if (iminor(inode) == SNDRV_MINOR_OSS_MUSIC)
134 level = SNDRV_SEQ_OSS_MODE_MUSIC;
135 else
136 level = SNDRV_SEQ_OSS_MODE_SYNTH;
138 mutex_lock(&register_mutex);
139 rc = snd_seq_oss_open(file, level);
140 mutex_unlock(&register_mutex);
142 return rc;
145 static int
146 odev_release(struct inode *inode, struct file *file)
148 struct seq_oss_devinfo *dp;
150 if ((dp = file->private_data) == NULL)
151 return 0;
153 snd_seq_oss_drain_write(dp);
155 mutex_lock(&register_mutex);
156 snd_seq_oss_release(dp);
157 mutex_unlock(&register_mutex);
159 return 0;
162 static ssize_t
163 odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
165 struct seq_oss_devinfo *dp;
166 dp = file->private_data;
167 snd_assert(dp != NULL, return -EIO);
168 return snd_seq_oss_read(dp, buf, count);
172 static ssize_t
173 odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
175 struct seq_oss_devinfo *dp;
176 dp = file->private_data;
177 snd_assert(dp != NULL, return -EIO);
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 snd_assert(dp != NULL, return -EIO);
187 return snd_seq_oss_ioctl(dp, cmd, arg);
190 #ifdef CONFIG_COMPAT
191 #define odev_ioctl_compat odev_ioctl
192 #else
193 #define odev_ioctl_compat NULL
194 #endif
196 static unsigned int
197 odev_poll(struct file *file, poll_table * wait)
199 struct seq_oss_devinfo *dp;
200 dp = file->private_data;
201 snd_assert(dp != NULL, return 0);
202 return snd_seq_oss_poll(dp, file, wait);
206 * registration of sequencer minor device
209 static const struct file_operations seq_oss_f_ops =
211 .owner = THIS_MODULE,
212 .read = odev_read,
213 .write = odev_write,
214 .open = odev_open,
215 .release = odev_release,
216 .poll = odev_poll,
217 .unlocked_ioctl = odev_ioctl,
218 .compat_ioctl = odev_ioctl_compat,
221 static int __init
222 register_device(void)
224 int rc;
226 mutex_lock(&register_mutex);
227 if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER,
228 NULL, 0,
229 &seq_oss_f_ops, NULL,
230 SNDRV_SEQ_OSS_DEVNAME)) < 0) {
231 snd_printk(KERN_ERR "can't register device seq\n");
232 mutex_unlock(&register_mutex);
233 return rc;
235 if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC,
236 NULL, 0,
237 &seq_oss_f_ops, NULL,
238 SNDRV_SEQ_OSS_DEVNAME)) < 0) {
239 snd_printk(KERN_ERR "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 debug_printk(("device registered\n"));
245 mutex_unlock(&register_mutex);
246 return 0;
249 static void
250 unregister_device(void)
252 mutex_lock(&register_mutex);
253 debug_printk(("device unregistered\n"));
254 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, NULL, 0) < 0)
255 snd_printk(KERN_ERR "error unregister device music\n");
256 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0) < 0)
257 snd_printk(KERN_ERR "error unregister device seq\n");
258 mutex_unlock(&register_mutex);
262 * /proc interface
265 #ifdef CONFIG_PROC_FS
267 static struct snd_info_entry *info_entry;
269 static void
270 info_read(struct snd_info_entry *entry, struct snd_info_buffer *buf)
272 mutex_lock(&register_mutex);
273 snd_iprintf(buf, "OSS sequencer emulation version %s\n", SNDRV_SEQ_OSS_VERSION_STR);
274 snd_seq_oss_system_info_read(buf);
275 snd_seq_oss_synth_info_read(buf);
276 snd_seq_oss_midi_info_read(buf);
277 mutex_unlock(&register_mutex);
281 static int __init
282 register_proc(void)
284 struct snd_info_entry *entry;
286 entry = snd_info_create_module_entry(THIS_MODULE, SNDRV_SEQ_OSS_PROCNAME, snd_seq_root);
287 if (entry == NULL)
288 return -ENOMEM;
290 entry->content = SNDRV_INFO_CONTENT_TEXT;
291 entry->private_data = NULL;
292 entry->c.text.read = info_read;
293 if (snd_info_register(entry) < 0) {
294 snd_info_free_entry(entry);
295 return -ENOMEM;
297 info_entry = entry;
298 return 0;
301 static void
302 unregister_proc(void)
304 snd_info_free_entry(info_entry);
305 info_entry = NULL;
307 #endif /* CONFIG_PROC_FS */