Linux 2.6.17.7
[linux/fpc-iii.git] / arch / um / drivers / hostaudio_kern.c
blob37232f908cd74e1c86e88874f68f41bb342fabcf
1 /*
2 * Copyright (C) 2002 Steve Schmidtke
3 * Licensed under the GPL
4 */
6 #include "linux/config.h"
7 #include "linux/module.h"
8 #include "linux/init.h"
9 #include "linux/slab.h"
10 #include "linux/fs.h"
11 #include "linux/sound.h"
12 #include "linux/soundcard.h"
13 #include "asm/uaccess.h"
14 #include "kern_util.h"
15 #include "init.h"
16 #include "os.h"
18 struct hostaudio_state {
19 int fd;
22 struct hostmixer_state {
23 int fd;
26 #define HOSTAUDIO_DEV_DSP "/dev/sound/dsp"
27 #define HOSTAUDIO_DEV_MIXER "/dev/sound/mixer"
29 /* Only changed from linux_main at boot time */
30 char *dsp = HOSTAUDIO_DEV_DSP;
31 char *mixer = HOSTAUDIO_DEV_MIXER;
33 #define DSP_HELP \
34 " This is used to specify the host dsp device to the hostaudio driver.\n" \
35 " The default is \"" HOSTAUDIO_DEV_DSP "\".\n\n"
37 #define MIXER_HELP \
38 " This is used to specify the host mixer device to the hostaudio driver.\n"\
39 " The default is \"" HOSTAUDIO_DEV_MIXER "\".\n\n"
41 #ifndef MODULE
42 static int set_dsp(char *name, int *add)
44 dsp = name;
45 return(0);
48 __uml_setup("dsp=", set_dsp, "dsp=<dsp device>\n" DSP_HELP);
50 static int set_mixer(char *name, int *add)
52 mixer = name;
53 return(0);
56 __uml_setup("mixer=", set_mixer, "mixer=<mixer device>\n" MIXER_HELP);
58 #else /*MODULE*/
60 module_param(dsp, charp, 0644);
61 MODULE_PARM_DESC(dsp, DSP_HELP);
63 module_param(mixer, charp, 0644);
64 MODULE_PARM_DESC(mixer, MIXER_HELP);
66 #endif
68 /* /dev/dsp file operations */
70 static ssize_t hostaudio_read(struct file *file, char __user *buffer,
71 size_t count, loff_t *ppos)
73 struct hostaudio_state *state = file->private_data;
74 void *kbuf;
75 int err;
77 #ifdef DEBUG
78 printk("hostaudio: read called, count = %d\n", count);
79 #endif
81 kbuf = kmalloc(count, GFP_KERNEL);
82 if(kbuf == NULL)
83 return(-ENOMEM);
85 err = os_read_file(state->fd, kbuf, count);
86 if(err < 0)
87 goto out;
89 if(copy_to_user(buffer, kbuf, err))
90 err = -EFAULT;
92 out:
93 kfree(kbuf);
94 return(err);
97 static ssize_t hostaudio_write(struct file *file, const char __user *buffer,
98 size_t count, loff_t *ppos)
100 struct hostaudio_state *state = file->private_data;
101 void *kbuf;
102 int err;
104 #ifdef DEBUG
105 printk("hostaudio: write called, count = %d\n", count);
106 #endif
108 kbuf = kmalloc(count, GFP_KERNEL);
109 if(kbuf == NULL)
110 return(-ENOMEM);
112 err = -EFAULT;
113 if(copy_from_user(kbuf, buffer, count))
114 goto out;
116 err = os_write_file(state->fd, kbuf, count);
117 if(err < 0)
118 goto out;
119 *ppos += err;
121 out:
122 kfree(kbuf);
123 return(err);
126 static unsigned int hostaudio_poll(struct file *file,
127 struct poll_table_struct *wait)
129 unsigned int mask = 0;
131 #ifdef DEBUG
132 printk("hostaudio: poll called (unimplemented)\n");
133 #endif
135 return(mask);
138 static int hostaudio_ioctl(struct inode *inode, struct file *file,
139 unsigned int cmd, unsigned long arg)
141 struct hostaudio_state *state = file->private_data;
142 unsigned long data = 0;
143 int err;
145 #ifdef DEBUG
146 printk("hostaudio: ioctl called, cmd = %u\n", cmd);
147 #endif
148 switch(cmd){
149 case SNDCTL_DSP_SPEED:
150 case SNDCTL_DSP_STEREO:
151 case SNDCTL_DSP_GETBLKSIZE:
152 case SNDCTL_DSP_CHANNELS:
153 case SNDCTL_DSP_SUBDIVIDE:
154 case SNDCTL_DSP_SETFRAGMENT:
155 if(get_user(data, (int __user *) arg))
156 return(-EFAULT);
157 break;
158 default:
159 break;
162 err = os_ioctl_generic(state->fd, cmd, (unsigned long) &data);
164 switch(cmd){
165 case SNDCTL_DSP_SPEED:
166 case SNDCTL_DSP_STEREO:
167 case SNDCTL_DSP_GETBLKSIZE:
168 case SNDCTL_DSP_CHANNELS:
169 case SNDCTL_DSP_SUBDIVIDE:
170 case SNDCTL_DSP_SETFRAGMENT:
171 if(put_user(data, (int __user *) arg))
172 return(-EFAULT);
173 break;
174 default:
175 break;
178 return(err);
181 static int hostaudio_open(struct inode *inode, struct file *file)
183 struct hostaudio_state *state;
184 int r = 0, w = 0;
185 int ret;
187 #ifdef DEBUG
188 printk("hostaudio: open called (host: %s)\n", dsp);
189 #endif
191 state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL);
192 if(state == NULL)
193 return(-ENOMEM);
195 if(file->f_mode & FMODE_READ) r = 1;
196 if(file->f_mode & FMODE_WRITE) w = 1;
198 ret = os_open_file(dsp, of_set_rw(OPENFLAGS(), r, w), 0);
199 if(ret < 0){
200 kfree(state);
201 return(ret);
204 state->fd = ret;
205 file->private_data = state;
206 return(0);
209 static int hostaudio_release(struct inode *inode, struct file *file)
211 struct hostaudio_state *state = file->private_data;
213 #ifdef DEBUG
214 printk("hostaudio: release called\n");
215 #endif
217 os_close_file(state->fd);
218 kfree(state);
220 return(0);
223 /* /dev/mixer file operations */
225 static int hostmixer_ioctl_mixdev(struct inode *inode, struct file *file,
226 unsigned int cmd, unsigned long arg)
228 struct hostmixer_state *state = file->private_data;
230 #ifdef DEBUG
231 printk("hostmixer: ioctl called\n");
232 #endif
234 return(os_ioctl_generic(state->fd, cmd, arg));
237 static int hostmixer_open_mixdev(struct inode *inode, struct file *file)
239 struct hostmixer_state *state;
240 int r = 0, w = 0;
241 int ret;
243 #ifdef DEBUG
244 printk("hostmixer: open called (host: %s)\n", mixer);
245 #endif
247 state = kmalloc(sizeof(struct hostmixer_state), GFP_KERNEL);
248 if(state == NULL) return(-ENOMEM);
250 if(file->f_mode & FMODE_READ) r = 1;
251 if(file->f_mode & FMODE_WRITE) w = 1;
253 ret = os_open_file(mixer, of_set_rw(OPENFLAGS(), r, w), 0);
255 if(ret < 0){
256 printk("hostaudio_open_mixdev failed to open '%s', err = %d\n",
257 dsp, -ret);
258 kfree(state);
259 return(ret);
262 file->private_data = state;
263 return(0);
266 static int hostmixer_release(struct inode *inode, struct file *file)
268 struct hostmixer_state *state = file->private_data;
270 #ifdef DEBUG
271 printk("hostmixer: release called\n");
272 #endif
274 os_close_file(state->fd);
275 kfree(state);
277 return(0);
281 /* kernel module operations */
283 static struct file_operations hostaudio_fops = {
284 .owner = THIS_MODULE,
285 .llseek = no_llseek,
286 .read = hostaudio_read,
287 .write = hostaudio_write,
288 .poll = hostaudio_poll,
289 .ioctl = hostaudio_ioctl,
290 .mmap = NULL,
291 .open = hostaudio_open,
292 .release = hostaudio_release,
295 static struct file_operations hostmixer_fops = {
296 .owner = THIS_MODULE,
297 .llseek = no_llseek,
298 .ioctl = hostmixer_ioctl_mixdev,
299 .open = hostmixer_open_mixdev,
300 .release = hostmixer_release,
303 struct {
304 int dev_audio;
305 int dev_mixer;
306 } module_data;
308 MODULE_AUTHOR("Steve Schmidtke");
309 MODULE_DESCRIPTION("UML Audio Relay");
310 MODULE_LICENSE("GPL");
312 static int __init hostaudio_init_module(void)
314 printk(KERN_INFO "UML Audio Relay (host dsp = %s, host mixer = %s)\n",
315 dsp, mixer);
317 module_data.dev_audio = register_sound_dsp(&hostaudio_fops, -1);
318 if(module_data.dev_audio < 0){
319 printk(KERN_ERR "hostaudio: couldn't register DSP device!\n");
320 return -ENODEV;
323 module_data.dev_mixer = register_sound_mixer(&hostmixer_fops, -1);
324 if(module_data.dev_mixer < 0){
325 printk(KERN_ERR "hostmixer: couldn't register mixer "
326 "device!\n");
327 unregister_sound_dsp(module_data.dev_audio);
328 return -ENODEV;
331 return 0;
334 static void __exit hostaudio_cleanup_module (void)
336 unregister_sound_mixer(module_data.dev_mixer);
337 unregister_sound_dsp(module_data.dev_audio);
340 module_init(hostaudio_init_module);
341 module_exit(hostaudio_cleanup_module);
344 * Overrides for Emacs so that we follow Linus's tabbing style.
345 * Emacs will notice this stuff at the end of the file and automatically
346 * adjust the settings for this buffer only. This must remain at the end
347 * of the file.
348 * ---------------------------------------------------------------------------
349 * Local variables:
350 * c-file-style: "linux"
351 * End: