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