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