[PATCH] mark struct file_operations const 9
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / sound / core / seq / oss / seq_oss.c
1 /*
2 * OSS compatible sequencer driver
3 *
4 * registration of device and proc
5 *
6 * Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de>
7 *
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.
12 *
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.
17 *
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
21 */
22
23 #include <sound/driver.h>
24 #include <linux/init.h>
25 #include <linux/smp_lock.h>
26 #include <linux/moduleparam.h>
27 #include <linux/mutex.h>
28 #include <sound/core.h>
29 #include <sound/minors.h>
30 #include <sound/initval.h>
31 #include "seq_oss_device.h"
32 #include "seq_oss_synth.h"
33
34 /*
35 * module option
36 */
37 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
38 MODULE_DESCRIPTION("OSS-compatible sequencer module");
39 MODULE_LICENSE("GPL");
40 /* Takashi says this is really only for sound-service-0-, but this is OK. */
41 MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_SEQUENCER);
42 MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_MUSIC);
43
44 #ifdef SNDRV_SEQ_OSS_DEBUG
45 module_param(seq_oss_debug, int, 0644);
46 MODULE_PARM_DESC(seq_oss_debug, "debug option");
47 int seq_oss_debug = 0;
48 #endif
49
50
51 /*
52 * prototypes
53 */
54 static int register_device(void);
55 static void unregister_device(void);
56 #ifdef CONFIG_PROC_FS
57 static int register_proc(void);
58 static void unregister_proc(void);
59 #else
60 static inline int register_proc(void) { return 0; }
61 static inline void unregister_proc(void) {}
62 #endif
63
64 static int odev_open(struct inode *inode, struct file *file);
65 static int odev_release(struct inode *inode, struct file *file);
66 static ssize_t odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset);
67 static ssize_t odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset);
68 static long odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
69 static unsigned int odev_poll(struct file *file, poll_table * wait);
70
71
72 /*
73 * module interface
74 */
75
76 static int __init alsa_seq_oss_init(void)
77 {
78 int rc;
79 static struct snd_seq_dev_ops ops = {
80 snd_seq_oss_synth_register,
81 snd_seq_oss_synth_unregister,
82 };
83
84 snd_seq_autoload_lock();
85 if ((rc = register_device()) < 0)
86 goto error;
87 if ((rc = register_proc()) < 0) {
88 unregister_device();
89 goto error;
90 }
91 if ((rc = snd_seq_oss_create_client()) < 0) {
92 unregister_proc();
93 unregister_device();
94 goto error;
95 }
96
97 if ((rc = snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OSS, &ops,
98 sizeof(struct snd_seq_oss_reg))) < 0) {
99 snd_seq_oss_delete_client();
100 unregister_proc();
101 unregister_device();
102 goto error;
103 }
104
105 /* success */
106 snd_seq_oss_synth_init();
107
108 error:
109 snd_seq_autoload_unlock();
110 return rc;
111 }
112
113 static void __exit alsa_seq_oss_exit(void)
114 {
115 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_OSS);
116 snd_seq_oss_delete_client();
117 unregister_proc();
118 unregister_device();
119 }
120
121 module_init(alsa_seq_oss_init)
122 module_exit(alsa_seq_oss_exit)
123
124 /*
125 * ALSA minor device interface
126 */
127
128 static DEFINE_MUTEX(register_mutex);
129
130 static int
131 odev_open(struct inode *inode, struct file *file)
132 {
133 int level, rc;
134
135 if (iminor(inode) == SNDRV_MINOR_OSS_MUSIC)
136 level = SNDRV_SEQ_OSS_MODE_MUSIC;
137 else
138 level = SNDRV_SEQ_OSS_MODE_SYNTH;
139
140 mutex_lock(&register_mutex);
141 rc = snd_seq_oss_open(file, level);
142 mutex_unlock(&register_mutex);
143
144 return rc;
145 }
146
147 static int
148 odev_release(struct inode *inode, struct file *file)
149 {
150 struct seq_oss_devinfo *dp;
151
152 if ((dp = file->private_data) == NULL)
153 return 0;
154
155 snd_seq_oss_drain_write(dp);
156
157 mutex_lock(&register_mutex);
158 snd_seq_oss_release(dp);
159 mutex_unlock(&register_mutex);
160
161 return 0;
162 }
163
164 static ssize_t
165 odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
166 {
167 struct seq_oss_devinfo *dp;
168 dp = file->private_data;
169 snd_assert(dp != NULL, return -EIO);
170 return snd_seq_oss_read(dp, buf, count);
171 }
172
173
174 static ssize_t
175 odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
176 {
177 struct seq_oss_devinfo *dp;
178 dp = file->private_data;
179 snd_assert(dp != NULL, return -EIO);
180 return snd_seq_oss_write(dp, buf, count, file);
181 }
182
183 static long
184 odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
185 {
186 struct seq_oss_devinfo *dp;
187 dp = file->private_data;
188 snd_assert(dp != NULL, return -EIO);
189 return snd_seq_oss_ioctl(dp, cmd, arg);
190 }
191
192 #ifdef CONFIG_COMPAT
193 #define odev_ioctl_compat odev_ioctl
194 #else
195 #define odev_ioctl_compat NULL
196 #endif
197
198 static unsigned int
199 odev_poll(struct file *file, poll_table * wait)
200 {
201 struct seq_oss_devinfo *dp;
202 dp = file->private_data;
203 snd_assert(dp != NULL, return 0);
204 return snd_seq_oss_poll(dp, file, wait);
205 }
206
207 /*
208 * registration of sequencer minor device
209 */
210
211 static const struct file_operations seq_oss_f_ops =
212 {
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 };
222
223 static int __init
224 register_device(void)
225 {
226 int rc;
227
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,
232 SNDRV_SEQ_OSS_DEVNAME)) < 0) {
233 snd_printk(KERN_ERR "can't register device seq\n");
234 mutex_unlock(&register_mutex);
235 return rc;
236 }
237 if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC,
238 NULL, 0,
239 &seq_oss_f_ops, NULL,
240 SNDRV_SEQ_OSS_DEVNAME)) < 0) {
241 snd_printk(KERN_ERR "can't register device music\n");
242 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0);
243 mutex_unlock(&register_mutex);
244 return rc;
245 }
246 debug_printk(("device registered\n"));
247 mutex_unlock(&register_mutex);
248 return 0;
249 }
250
251 static void
252 unregister_device(void)
253 {
254 mutex_lock(&register_mutex);
255 debug_printk(("device unregistered\n"));
256 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, NULL, 0) < 0)
257 snd_printk(KERN_ERR "error unregister device music\n");
258 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0) < 0)
259 snd_printk(KERN_ERR "error unregister device seq\n");
260 mutex_unlock(&register_mutex);
261 }
262
263 /*
264 * /proc interface
265 */
266
267 #ifdef CONFIG_PROC_FS
268
269 static struct snd_info_entry *info_entry;
270
271 static void
272 info_read(struct snd_info_entry *entry, struct snd_info_buffer *buf)
273 {
274 mutex_lock(&register_mutex);
275 snd_iprintf(buf, "OSS sequencer emulation version %s\n", SNDRV_SEQ_OSS_VERSION_STR);
276 snd_seq_oss_system_info_read(buf);
277 snd_seq_oss_synth_info_read(buf);
278 snd_seq_oss_midi_info_read(buf);
279 mutex_unlock(&register_mutex);
280 }
281
282
283 static int __init
284 register_proc(void)
285 {
286 struct snd_info_entry *entry;
287
288 entry = snd_info_create_module_entry(THIS_MODULE, SNDRV_SEQ_OSS_PROCNAME, snd_seq_root);
289 if (entry == NULL)
290 return -ENOMEM;
291
292 entry->content = SNDRV_INFO_CONTENT_TEXT;
293 entry->private_data = NULL;
294 entry->c.text.read = info_read;
295 if (snd_info_register(entry) < 0) {
296 snd_info_free_entry(entry);
297 return -ENOMEM;
298 }
299 info_entry = entry;
300 return 0;
301 }
302
303 static void
304 unregister_proc(void)
305 {
306 snd_info_free_entry(info_entry);
307 info_entry = NULL;
308 }
309 #endif /* CONFIG_PROC_FS */