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