Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2002 Steve Schmidtke |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include "linux/fs.h" |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 7 | #include "linux/module.h" |
| 8 | #include "linux/slab.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include "linux/sound.h" |
| 10 | #include "linux/soundcard.h" |
| 11 | #include "asm/uaccess.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include "init.h" |
| 13 | #include "os.h" |
| 14 | |
| 15 | struct hostaudio_state { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 16 | int fd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | }; |
| 18 | |
| 19 | struct hostmixer_state { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 20 | int fd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | }; |
| 22 | |
| 23 | #define HOSTAUDIO_DEV_DSP "/dev/sound/dsp" |
| 24 | #define HOSTAUDIO_DEV_MIXER "/dev/sound/mixer" |
| 25 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 26 | /* |
| 27 | * Changed either at boot time or module load time. At boot, this is |
Jeff Dike | b612e47 | 2007-02-10 01:43:59 -0800 | [diff] [blame] | 28 | * single-threaded; at module load, multiple modules would each have |
| 29 | * their own copy of these variables. |
| 30 | */ |
| 31 | static char *dsp = HOSTAUDIO_DEV_DSP; |
| 32 | static char *mixer = HOSTAUDIO_DEV_MIXER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | #define DSP_HELP \ |
| 35 | " This is used to specify the host dsp device to the hostaudio driver.\n" \ |
| 36 | " The default is \"" HOSTAUDIO_DEV_DSP "\".\n\n" |
| 37 | |
| 38 | #define MIXER_HELP \ |
| 39 | " This is used to specify the host mixer device to the hostaudio driver.\n"\ |
| 40 | " The default is \"" HOSTAUDIO_DEV_MIXER "\".\n\n" |
| 41 | |
| 42 | #ifndef MODULE |
| 43 | static int set_dsp(char *name, int *add) |
| 44 | { |
| 45 | dsp = name; |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 46 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | __uml_setup("dsp=", set_dsp, "dsp=<dsp device>\n" DSP_HELP); |
| 50 | |
| 51 | static int set_mixer(char *name, int *add) |
| 52 | { |
| 53 | mixer = name; |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 54 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | __uml_setup("mixer=", set_mixer, "mixer=<mixer device>\n" MIXER_HELP); |
| 58 | |
| 59 | #else /*MODULE*/ |
| 60 | |
Dominik Hackl | 20a64f1 | 2005-07-27 11:43:32 -0700 | [diff] [blame] | 61 | module_param(dsp, charp, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | MODULE_PARM_DESC(dsp, DSP_HELP); |
| 63 | |
Dominik Hackl | 20a64f1 | 2005-07-27 11:43:32 -0700 | [diff] [blame] | 64 | module_param(mixer, charp, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | MODULE_PARM_DESC(mixer, MIXER_HELP); |
| 66 | |
| 67 | #endif |
| 68 | |
| 69 | /* /dev/dsp file operations */ |
| 70 | |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 71 | static ssize_t hostaudio_read(struct file *file, char __user *buffer, |
| 72 | size_t count, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 74 | struct hostaudio_state *state = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | void *kbuf; |
| 76 | int err; |
| 77 | |
| 78 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 79 | printk(KERN_DEBUG "hostaudio: read called, count = %d\n", count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | #endif |
| 81 | |
| 82 | kbuf = kmalloc(count, GFP_KERNEL); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 83 | if (kbuf == NULL) |
| 84 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
Jeff Dike | a6ea4cc | 2007-05-06 14:51:43 -0700 | [diff] [blame] | 86 | err = os_read_file(state->fd, kbuf, count); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 87 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | goto out; |
| 89 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 90 | if (copy_to_user(buffer, kbuf, err)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | err = -EFAULT; |
| 92 | |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 93 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | kfree(kbuf); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 95 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 98 | static ssize_t hostaudio_write(struct file *file, const char __user *buffer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | size_t count, loff_t *ppos) |
| 100 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 101 | struct hostaudio_state *state = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | void *kbuf; |
| 103 | int err; |
| 104 | |
| 105 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 106 | printk(KERN_DEBUG "hostaudio: write called, count = %d\n", count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | #endif |
| 108 | |
| 109 | kbuf = kmalloc(count, GFP_KERNEL); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 110 | if (kbuf == NULL) |
| 111 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | err = -EFAULT; |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 114 | if (copy_from_user(kbuf, buffer, count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | goto out; |
| 116 | |
Jeff Dike | a6ea4cc | 2007-05-06 14:51:43 -0700 | [diff] [blame] | 117 | err = os_write_file(state->fd, kbuf, count); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 118 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | goto out; |
| 120 | *ppos += err; |
| 121 | |
| 122 | out: |
| 123 | kfree(kbuf); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 124 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 127 | static unsigned int hostaudio_poll(struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | struct poll_table_struct *wait) |
| 129 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 130 | unsigned int mask = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 133 | printk(KERN_DEBUG "hostaudio: poll called (unimplemented)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | #endif |
| 135 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 136 | return mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 139 | static int hostaudio_ioctl(struct inode *inode, struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | unsigned int cmd, unsigned long arg) |
| 141 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 142 | struct hostaudio_state *state = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | unsigned long data = 0; |
| 144 | int err; |
| 145 | |
| 146 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 147 | printk(KERN_DEBUG "hostaudio: ioctl called, cmd = %u\n", cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | #endif |
| 149 | switch(cmd){ |
| 150 | case SNDCTL_DSP_SPEED: |
| 151 | case SNDCTL_DSP_STEREO: |
| 152 | case SNDCTL_DSP_GETBLKSIZE: |
| 153 | case SNDCTL_DSP_CHANNELS: |
| 154 | case SNDCTL_DSP_SUBDIVIDE: |
| 155 | case SNDCTL_DSP_SETFRAGMENT: |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 156 | if (get_user(data, (int __user *) arg)) |
Johann Felix Soden | 484f1e2 | 2008-05-12 14:01:51 -0700 | [diff] [blame] | 157 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | break; |
| 159 | default: |
| 160 | break; |
| 161 | } |
| 162 | |
| 163 | err = os_ioctl_generic(state->fd, cmd, (unsigned long) &data); |
| 164 | |
| 165 | switch(cmd){ |
| 166 | case SNDCTL_DSP_SPEED: |
| 167 | case SNDCTL_DSP_STEREO: |
| 168 | case SNDCTL_DSP_GETBLKSIZE: |
| 169 | case SNDCTL_DSP_CHANNELS: |
| 170 | case SNDCTL_DSP_SUBDIVIDE: |
| 171 | case SNDCTL_DSP_SETFRAGMENT: |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 172 | if (put_user(data, (int __user *) arg)) |
| 173 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | break; |
| 175 | default: |
| 176 | break; |
| 177 | } |
| 178 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 179 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | static int hostaudio_open(struct inode *inode, struct file *file) |
| 183 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 184 | struct hostaudio_state *state; |
| 185 | int r = 0, w = 0; |
| 186 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 189 | printk(KERN_DEBUG "hostaudio: open called (host: %s)\n", dsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | #endif |
| 191 | |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 192 | state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 193 | if (state == NULL) |
| 194 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 196 | if (file->f_mode & FMODE_READ) |
| 197 | r = 1; |
| 198 | if (file->f_mode & FMODE_WRITE) |
| 199 | w = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
| 201 | ret = os_open_file(dsp, of_set_rw(OPENFLAGS(), r, w), 0); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 202 | if (ret < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | kfree(state); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 204 | return ret; |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 205 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | state->fd = ret; |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 207 | file->private_data = state; |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 208 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | static int hostaudio_release(struct inode *inode, struct file *file) |
| 212 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 213 | struct hostaudio_state *state = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 216 | printk(KERN_DEBUG "hostaudio: release called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | #endif |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 218 | os_close_file(state->fd); |
| 219 | kfree(state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 221 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | /* /dev/mixer file operations */ |
| 225 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 226 | static int hostmixer_ioctl_mixdev(struct inode *inode, struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | unsigned int cmd, unsigned long arg) |
| 228 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 229 | struct hostmixer_state *state = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
| 231 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 232 | printk(KERN_DEBUG "hostmixer: ioctl called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | #endif |
| 234 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 235 | return os_ioctl_generic(state->fd, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | static int hostmixer_open_mixdev(struct inode *inode, struct file *file) |
| 239 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 240 | struct hostmixer_state *state; |
| 241 | int r = 0, w = 0; |
| 242 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
| 244 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 245 | printk(KERN_DEBUG "hostmixer: open called (host: %s)\n", mixer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | #endif |
| 247 | |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 248 | state = kmalloc(sizeof(struct hostmixer_state), GFP_KERNEL); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 249 | if (state == NULL) |
| 250 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 252 | if (file->f_mode & FMODE_READ) |
| 253 | r = 1; |
| 254 | if (file->f_mode & FMODE_WRITE) |
| 255 | w = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
| 257 | ret = os_open_file(mixer, of_set_rw(OPENFLAGS(), r, w), 0); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 258 | |
| 259 | if (ret < 0) { |
| 260 | printk(KERN_ERR "hostaudio_open_mixdev failed to open '%s', " |
| 261 | "err = %d\n", dsp, -ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | kfree(state); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 263 | return ret; |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 264 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 266 | file->private_data = state; |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 267 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | static int hostmixer_release(struct inode *inode, struct file *file) |
| 271 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 272 | struct hostmixer_state *state = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
| 274 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 275 | printk(KERN_DEBUG "hostmixer: release called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | #endif |
| 277 | |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 278 | os_close_file(state->fd); |
| 279 | kfree(state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 281 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | /* kernel module operations */ |
| 285 | |
Jeff Dike | 5e7672e | 2006-09-27 01:50:33 -0700 | [diff] [blame] | 286 | static const struct file_operations hostaudio_fops = { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 287 | .owner = THIS_MODULE, |
| 288 | .llseek = no_llseek, |
| 289 | .read = hostaudio_read, |
| 290 | .write = hostaudio_write, |
| 291 | .poll = hostaudio_poll, |
| 292 | .ioctl = hostaudio_ioctl, |
| 293 | .mmap = NULL, |
| 294 | .open = hostaudio_open, |
| 295 | .release = hostaudio_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | }; |
| 297 | |
Jeff Dike | 5e7672e | 2006-09-27 01:50:33 -0700 | [diff] [blame] | 298 | static const struct file_operations hostmixer_fops = { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 299 | .owner = THIS_MODULE, |
| 300 | .llseek = no_llseek, |
| 301 | .ioctl = hostmixer_ioctl_mixdev, |
| 302 | .open = hostmixer_open_mixdev, |
| 303 | .release = hostmixer_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | }; |
| 305 | |
| 306 | struct { |
| 307 | int dev_audio; |
| 308 | int dev_mixer; |
| 309 | } module_data; |
| 310 | |
| 311 | MODULE_AUTHOR("Steve Schmidtke"); |
| 312 | MODULE_DESCRIPTION("UML Audio Relay"); |
| 313 | MODULE_LICENSE("GPL"); |
| 314 | |
| 315 | static int __init hostaudio_init_module(void) |
| 316 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 317 | printk(KERN_INFO "UML Audio Relay (host dsp = %s, host mixer = %s)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | dsp, mixer); |
| 319 | |
| 320 | module_data.dev_audio = register_sound_dsp(&hostaudio_fops, -1); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 321 | if (module_data.dev_audio < 0) { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 322 | printk(KERN_ERR "hostaudio: couldn't register DSP device!\n"); |
| 323 | return -ENODEV; |
| 324 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
| 326 | module_data.dev_mixer = register_sound_mixer(&hostmixer_fops, -1); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 327 | if (module_data.dev_mixer < 0) { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 328 | printk(KERN_ERR "hostmixer: couldn't register mixer " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | "device!\n"); |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 330 | unregister_sound_dsp(module_data.dev_audio); |
| 331 | return -ENODEV; |
| 332 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 334 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | static void __exit hostaudio_cleanup_module (void) |
| 338 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 339 | unregister_sound_mixer(module_data.dev_mixer); |
| 340 | unregister_sound_dsp(module_data.dev_audio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | module_init(hostaudio_init_module); |
| 344 | module_exit(hostaudio_cleanup_module); |