ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / um / drivers / hostaudio_kern.c
1 /* 
2  * Copyright (C) 2002 Steve Schmidtke 
3  * Licensed under the GPL
4  */
5
6 #include "linux/config.h"
7 #include "linux/module.h"
8 #include "linux/version.h"
9 #include "linux/init.h"
10 #include "linux/slab.h"
11 #include "linux/fs.h"
12 #include "linux/sound.h"
13 #include "linux/soundcard.h"
14 #include "kern_util.h"
15 #include "init.h"
16 #include "hostaudio.h"
17
18 /* Only changed from linux_main at boot time */
19 char *dsp = HOSTAUDIO_DEV_DSP;
20 char *mixer = HOSTAUDIO_DEV_MIXER;
21
22 #ifndef MODULE
23 static int set_dsp(char *name, int *add)
24 {
25         dsp = uml_strdup(name);
26         return(0);
27 }
28
29 __uml_setup("dsp=", set_dsp,
30 "dsp=<dsp device>\n"
31 "    This is used to specify the host dsp device to the hostaudio driver.\n"
32 "    The default is \"" HOSTAUDIO_DEV_DSP "\".\n\n"
33 );
34
35 static int set_mixer(char *name, int *add)
36 {
37         mixer = uml_strdup(name);
38         return(0);
39 }
40
41 __uml_setup("mixer=", set_mixer,
42 "mixer=<mixer device>\n"
43 "    This is used to specify the host mixer device to the hostaudio driver.\n"
44 "    The default is \"" HOSTAUDIO_DEV_MIXER "\".\n\n"
45 );
46 #endif
47
48 /* /dev/dsp file operations */
49
50 static ssize_t hostaudio_read(struct file *file, char *buffer, size_t count, 
51                               loff_t *ppos)
52 {
53         struct hostaudio_state *state = file->private_data;
54
55 #ifdef DEBUG
56         printk("hostaudio: read called, count = %d\n", count);
57 #endif
58
59         return(hostaudio_read_user(state, buffer, count, ppos));
60 }
61
62 static ssize_t hostaudio_write(struct file *file, const char *buffer, 
63                                size_t count, loff_t *ppos)
64 {
65         struct hostaudio_state *state = file->private_data;
66
67 #ifdef DEBUG
68         printk("hostaudio: write called, count = %d\n", count);
69 #endif
70         return(hostaudio_write_user(state, buffer, count, ppos));
71 }
72
73 static unsigned int hostaudio_poll(struct file *file, 
74                                    struct poll_table_struct *wait)
75 {
76         unsigned int mask = 0;
77
78 #ifdef DEBUG
79         printk("hostaudio: poll called (unimplemented)\n");
80 #endif
81
82         return(mask);
83 }
84
85 static int hostaudio_ioctl(struct inode *inode, struct file *file, 
86                            unsigned int cmd, unsigned long arg)
87 {
88         struct hostaudio_state *state = file->private_data;
89
90 #ifdef DEBUG
91         printk("hostaudio: ioctl called, cmd = %u\n", cmd);
92 #endif
93
94         return(hostaudio_ioctl_user(state, cmd, arg));
95 }
96
97 static int hostaudio_open(struct inode *inode, struct file *file)
98 {
99         struct hostaudio_state *state;
100         int r = 0, w = 0;
101         int ret;
102
103 #ifdef DEBUG
104         printk("hostaudio: open called (host: %s)\n", dsp);
105 #endif
106
107         state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL);
108         if(state == NULL) return(-ENOMEM);
109
110         if(file->f_mode & FMODE_READ) r = 1;
111         if(file->f_mode & FMODE_WRITE) w = 1;
112
113         ret = hostaudio_open_user(state, r, w, dsp);
114         if(ret < 0){
115                 kfree(state);
116                 return(ret);
117         }
118
119         file->private_data = state;
120         return(0);
121 }
122
123 static int hostaudio_release(struct inode *inode, struct file *file)
124 {
125         struct hostaudio_state *state = file->private_data;
126         int ret;
127
128 #ifdef DEBUG
129         printk("hostaudio: release called\n");
130 #endif
131
132         ret = hostaudio_release_user(state);
133         kfree(state);
134
135         return(ret);
136 }
137
138 /* /dev/mixer file operations */
139
140 static int hostmixer_ioctl_mixdev(struct inode *inode, struct file *file, 
141                                   unsigned int cmd, unsigned long arg)
142 {
143         struct hostmixer_state *state = file->private_data;
144
145 #ifdef DEBUG
146         printk("hostmixer: ioctl called\n");
147 #endif
148
149         return(hostmixer_ioctl_mixdev_user(state, cmd, arg));
150 }
151
152 static int hostmixer_open_mixdev(struct inode *inode, struct file *file)
153 {
154         struct hostmixer_state *state;
155         int r = 0, w = 0;
156         int ret;
157
158 #ifdef DEBUG
159         printk("hostmixer: open called (host: %s)\n", mixer);
160 #endif
161
162         state = kmalloc(sizeof(struct hostmixer_state), GFP_KERNEL);
163         if(state == NULL) return(-ENOMEM);
164
165         if(file->f_mode & FMODE_READ) r = 1;
166         if(file->f_mode & FMODE_WRITE) w = 1;
167
168         ret = hostmixer_open_mixdev_user(state, r, w, mixer);
169         
170         if(ret < 0){
171                 kfree(state);
172                 return(ret);
173         }
174
175         file->private_data = state;
176         return(0);
177 }
178
179 static int hostmixer_release(struct inode *inode, struct file *file)
180 {
181         struct hostmixer_state *state = file->private_data;
182         int ret;
183
184 #ifdef DEBUG
185         printk("hostmixer: release called\n");
186 #endif
187
188         ret = hostmixer_release_mixdev_user(state);
189         kfree(state);
190
191         return(ret);
192 }
193
194
195 /* kernel module operations */
196
197 static struct file_operations hostaudio_fops = {
198         .owner          = THIS_MODULE,
199         .llseek         = no_llseek,
200         .read           = hostaudio_read,
201         .write          = hostaudio_write,
202         .poll           = hostaudio_poll,
203         .ioctl          = hostaudio_ioctl,
204         .mmap           = NULL,
205         .open           = hostaudio_open,
206         .release        = hostaudio_release,
207 };
208
209 static struct file_operations hostmixer_fops = {
210         .owner          = THIS_MODULE,
211         .llseek         = no_llseek,
212         .ioctl          = hostmixer_ioctl_mixdev,
213         .open           = hostmixer_open_mixdev,
214         .release        = hostmixer_release,
215 };
216
217 struct {
218         int dev_audio;
219         int dev_mixer;
220 } module_data;
221
222 MODULE_AUTHOR("Steve Schmidtke");
223 MODULE_DESCRIPTION("UML Audio Relay");
224 MODULE_LICENSE("GPL");
225
226 static int __init hostaudio_init_module(void)
227 {
228         printk(KERN_INFO "UML Audio Relay\n");
229
230         module_data.dev_audio = register_sound_dsp(&hostaudio_fops, -1);
231         if(module_data.dev_audio < 0){
232                 printk(KERN_ERR "hostaudio: couldn't register DSP device!\n");
233                 return -ENODEV;
234         }
235
236         module_data.dev_mixer = register_sound_mixer(&hostmixer_fops, -1);
237         if(module_data.dev_mixer < 0){
238                 printk(KERN_ERR "hostmixer: couldn't register mixer "
239                        "device!\n");
240                 unregister_sound_dsp(module_data.dev_audio);
241                 return -ENODEV;
242         }
243
244         return 0;
245 }
246
247 static void __exit hostaudio_cleanup_module (void)
248 {
249        unregister_sound_mixer(module_data.dev_mixer);
250        unregister_sound_dsp(module_data.dev_audio);
251 }
252
253 module_init(hostaudio_init_module);
254 module_exit(hostaudio_cleanup_module);
255
256 /*
257  * Overrides for Emacs so that we follow Linus's tabbing style.
258  * Emacs will notice this stuff at the end of the file and automatically
259  * adjust the settings for this buffer only.  This must remain at the end
260  * of the file.
261  * ---------------------------------------------------------------------------
262  * Local variables:
263  * c-file-style: "linux"
264  * End:
265  */