^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) /* speakup_soft.c - speakup driver to register and make available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * a user space device for software synthesizers. written by: Kirk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Reiser <kirk@braille.uwo.ca>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2003 Kirk Reiser.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * this code is specificly written as a driver for the speakup screenreview
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * package and is not a general device driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/miscdevice.h> /* for misc_register, and MISC_DYNAMIC_MINOR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/poll.h> /* for poll_wait() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /* schedule(), signal_pending(), TASK_INTERRUPTIBLE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "spk_priv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "speakup.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define DRV_VERSION "2.6"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define PROCSPEECH 0x0d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define CLEAR_SYNTH 0x18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static int softsynth_probe(struct spk_synth *synth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static void softsynth_release(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static int softsynth_is_alive(struct spk_synth *synth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static unsigned char get_index(struct spk_synth *synth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static struct miscdevice synth_device, synthu_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static int init_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static int misc_registered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static struct var_t vars[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) { CAPS_START, .u.s = {"\x01+3p" } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) { CAPS_STOP, .u.s = {"\x01-3p" } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) { PAUSE, .u.n = {"\x01P" } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) { RATE, .u.n = {"\x01%ds", 2, 0, 9, 0, 0, NULL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) { PITCH, .u.n = {"\x01%dp", 5, 0, 9, 0, 0, NULL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) { INFLECTION, .u.n = {"\x01%dr", 5, 0, 9, 0, 0, NULL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) { VOL, .u.n = {"\x01%dv", 5, 0, 9, 0, 0, NULL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) { TONE, .u.n = {"\x01%dx", 1, 0, 2, 0, 0, NULL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) { PUNCT, .u.n = {"\x01%db", 0, 0, 2, 0, 0, NULL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) { VOICE, .u.n = {"\x01%do", 0, 0, 7, 0, 0, NULL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) { FREQUENCY, .u.n = {"\x01%df", 5, 0, 9, 0, 0, NULL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) V_LAST_VAR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* These attributes will appear in /sys/accessibility/speakup/soft. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static struct kobj_attribute caps_start_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static struct kobj_attribute caps_stop_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static struct kobj_attribute freq_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) __ATTR(freq, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static struct kobj_attribute pitch_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) __ATTR(pitch, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static struct kobj_attribute inflection_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) __ATTR(inflection, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static struct kobj_attribute punct_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) __ATTR(punct, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static struct kobj_attribute rate_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) __ATTR(rate, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static struct kobj_attribute tone_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) __ATTR(tone, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static struct kobj_attribute voice_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) __ATTR(voice, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static struct kobj_attribute vol_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) __ATTR(vol, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * We should uncomment the following definition, when we agree on a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * method of passing a language designation to the software synthesizer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * static struct kobj_attribute lang_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * __ATTR(lang, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static struct kobj_attribute delay_time_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static struct kobj_attribute direct_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) __ATTR(direct, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static struct kobj_attribute full_time_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) __ATTR(full_time, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static struct kobj_attribute jiffy_delta_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static struct kobj_attribute trigger_time_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * Create a group of attributes so that we can create and destroy them all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * at once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static struct attribute *synth_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) &caps_start_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) &caps_stop_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) &freq_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /* &lang_attribute.attr, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) &pitch_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) &inflection_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) &punct_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) &rate_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) &tone_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) &voice_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) &vol_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) &delay_time_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) &direct_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) &full_time_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) &jiffy_delta_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) &trigger_time_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) NULL, /* need to NULL terminate the list of attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static struct spk_synth synth_soft = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .name = "soft",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .version = DRV_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .long_name = "software synth",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .init = "\01@\x01\x31y\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) .procspeech = PROCSPEECH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) .delay = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) .trigger = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .jiffies = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .full = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) .startup = SYNTH_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) .checkval = SYNTH_CHECK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) .vars = vars,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) .io_ops = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .probe = softsynth_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .release = softsynth_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .synth_immediate = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .catch_up = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) .flush = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .is_alive = softsynth_is_alive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) .synth_adjust = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .read_buff_add = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .get_index = get_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .indexing = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .command = "\x01%di",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .lowindex = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .highindex = 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .currindex = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .attributes = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .attrs = synth_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .name = "soft",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static char *get_initstring(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static char buf[40];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) char *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct var_t *var;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) memset(buf, 0, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) cp = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) var = synth_soft.vars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) while (var->var_id != MAXVARS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (var->var_id != CAPS_START && var->var_id != CAPS_STOP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) var->var_id != PAUSE && var->var_id != DIRECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) cp = cp + sprintf(cp, var->u.n.synth_fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) var->u.n.value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) var++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) cp = cp + sprintf(cp, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static int softsynth_open(struct inode *inode, struct file *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /*if ((fp->f_flags & O_ACCMODE) != O_RDONLY) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /* return -EPERM; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) spin_lock_irqsave(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (synth_soft.alive) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) synth_soft.alive = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static int softsynth_close(struct inode *inode, struct file *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) spin_lock_irqsave(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) synth_soft.alive = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) init_pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* Make sure we let applications go before leaving */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) speakup_start_ttys();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static ssize_t softsynthx_read(struct file *fp, char __user *buf, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) loff_t *pos, int unicode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) int chars_sent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) char __user *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) char *init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) size_t bytes_per_ch = unicode ? 3 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) u16 ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) int empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (count < bytes_per_ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) spin_lock_irqsave(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) synth_soft.alive = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) prepare_to_wait(&speakup_event, &wait, TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (synth_current() == &synth_soft) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (!unicode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) synth_buffer_skip_nonlatin1();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (!synth_buffer_empty() || speakup_info.flushing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (fp->f_flags & O_NONBLOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) finish_wait(&speakup_event, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (signal_pending(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) finish_wait(&speakup_event, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) spin_lock_irqsave(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) finish_wait(&speakup_event, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) cp = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) init = get_initstring();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /* Keep 3 bytes available for a 16bit UTF-8-encoded character */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) while (chars_sent <= count - bytes_per_ch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (synth_current() != &synth_soft)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (speakup_info.flushing) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) speakup_info.flushing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) ch = '\x18';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) } else if (init[init_pos]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) ch = init[init_pos++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (!unicode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) synth_buffer_skip_nonlatin1();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (synth_buffer_empty())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) ch = synth_buffer_getc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if ((!unicode && ch < 0x100) || (unicode && ch < 0x80)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) u_char c = ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (copy_to_user(cp, &c, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) chars_sent++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) cp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) } else if (unicode && ch < 0x800) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) u_char s[2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 0xc0 | (ch >> 6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 0x80 | (ch & 0x3f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (copy_to_user(cp, s, sizeof(s)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) chars_sent += sizeof(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) cp += sizeof(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) } else if (unicode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) u_char s[3] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 0xe0 | (ch >> 12),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 0x80 | ((ch >> 6) & 0x3f),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 0x80 | (ch & 0x3f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (copy_to_user(cp, s, sizeof(s)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) chars_sent += sizeof(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) cp += sizeof(s);
^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) spin_lock_irqsave(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) *pos += chars_sent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) empty = synth_buffer_empty();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (empty) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) speakup_start_ttys();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) *pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return chars_sent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static ssize_t softsynth_read(struct file *fp, char __user *buf, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) return softsynthx_read(fp, buf, count, pos, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static ssize_t softsynthu_read(struct file *fp, char __user *buf, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return softsynthx_read(fp, buf, count, pos, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static int last_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static ssize_t softsynth_write(struct file *fp, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) size_t count, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) unsigned long supplied_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) int converted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) converted = kstrtoul_from_user(buf, count, 0, &supplied_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (converted < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) return converted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) last_index = supplied_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static __poll_t softsynth_poll(struct file *fp, struct poll_table_struct *wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) __poll_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) poll_wait(fp, &speakup_event, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) spin_lock_irqsave(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (synth_current() == &synth_soft &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) (!synth_buffer_empty() || speakup_info.flushing))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) ret = EPOLLIN | EPOLLRDNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return ret;
^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 unsigned char get_index(struct spk_synth *synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) rv = last_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) last_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static const struct file_operations softsynth_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) .poll = softsynth_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) .read = softsynth_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) .write = softsynth_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) .open = softsynth_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) .release = softsynth_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) static const struct file_operations softsynthu_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) .poll = softsynth_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) .read = softsynthu_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) .write = softsynth_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) .open = softsynth_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) .release = softsynth_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) static int softsynth_probe(struct spk_synth *synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (misc_registered != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) memset(&synth_device, 0, sizeof(synth_device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) synth_device.minor = MISC_DYNAMIC_MINOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) synth_device.name = "softsynth";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) synth_device.fops = &softsynth_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (misc_register(&synth_device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) pr_warn("Couldn't initialize miscdevice /dev/softsynth.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) memset(&synthu_device, 0, sizeof(synthu_device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) synthu_device.minor = MISC_DYNAMIC_MINOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) synthu_device.name = "softsynthu";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) synthu_device.fops = &softsynthu_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (misc_register(&synthu_device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) pr_warn("Couldn't initialize miscdevice /dev/softsynthu.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) misc_registered = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) pr_info("initialized device: /dev/softsynth, node (MAJOR 10, MINOR %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) synth_device.minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) pr_info("initialized device: /dev/softsynthu, node (MAJOR 10, MINOR %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) synthu_device.minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static void softsynth_release(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) misc_deregister(&synth_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) misc_deregister(&synthu_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) misc_registered = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) pr_info("unregistered /dev/softsynth\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) pr_info("unregistered /dev/softsynthu\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static int softsynth_is_alive(struct spk_synth *synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (synth_soft.alive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) module_param_named(start, synth_soft.startup, short, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) module_spk_synth(synth_soft);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) MODULE_DESCRIPTION("Speakup userspace software synthesizer support");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) MODULE_VERSION(DRV_VERSION);