Path: blob/master/drivers/accessibility/speakup/speakup_dectlk.c
26282 views
// SPDX-License-Identifier: GPL-2.0+1/*2* originally written by: Kirk Reiser <[email protected]>3* this version considerably modified by David Borowski, [email protected]4*5* Copyright (C) 1998-99 Kirk Reiser.6* Copyright (C) 2003 David Borowski.7*8* specifically written as a driver for the speakup screenreview9* s not a general device driver.10*/11#include <linux/unistd.h>12#include <linux/proc_fs.h>13#include <linux/jiffies.h>14#include <linux/spinlock.h>15#include <linux/sched.h>16#include <linux/timer.h>17#include <linux/kthread.h>18#include "speakup.h"19#include "spk_priv.h"2021#define DRV_VERSION "2.20"22#define SYNTH_CLEAR 0x0323#define PROCSPEECH 0x0b24static int xoff;2526static inline int synth_full(void)27{28return xoff;29}3031static void do_catch_up(struct spk_synth *synth);32static void synth_flush(struct spk_synth *synth);33static void read_buff_add(u_char c);34static unsigned char get_index(struct spk_synth *synth);3536static int in_escape;37static int is_flushing;3839static DEFINE_SPINLOCK(flush_lock);40static DECLARE_WAIT_QUEUE_HEAD(flush);4142enum default_vars_id {43CAPS_START_ID = 0, CAPS_STOP_ID,44RATE_ID, PITCH_ID, INFLECTION_ID,45VOL_ID, PUNCT_ID, VOICE_ID,46DIRECT_ID, V_LAST_VAR_ID,47NB_ID,48};4950static struct var_t vars[NB_ID] = {51[CAPS_START_ID] = { CAPS_START, .u.s = {"[:dv ap 160] " } },52[CAPS_STOP_ID] = { CAPS_STOP, .u.s = {"[:dv ap 100 ] " } },53[RATE_ID] = { RATE, .u.n = {"[:ra %d] ", 180, 75, 650, 0, 0, NULL } },54[PITCH_ID] = { PITCH, .u.n = {"[:dv ap %d] ", 122, 50, 350, 0, 0, NULL } },55[INFLECTION_ID] = { INFLECTION, .u.n = {"[:dv pr %d] ", 100, 0, 10000, 0, 0, NULL } },56[VOL_ID] = { VOL, .u.n = {"[:dv g5 %d] ", 86, 60, 86, 0, 0, NULL } },57[PUNCT_ID] = { PUNCT, .u.n = {"[:pu %c] ", 0, 0, 2, 0, 0, "nsa" } },58[VOICE_ID] = { VOICE, .u.n = {"[:n%c] ", 0, 0, 9, 0, 0, "phfdburwkv" } },59[DIRECT_ID] = { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },60V_LAST_VAR61};6263/*64* These attributes will appear in /sys/accessibility/speakup/dectlk.65*/66static struct kobj_attribute caps_start_attribute =67__ATTR(caps_start, 0644, spk_var_show, spk_var_store);68static struct kobj_attribute caps_stop_attribute =69__ATTR(caps_stop, 0644, spk_var_show, spk_var_store);70static struct kobj_attribute pitch_attribute =71__ATTR(pitch, 0644, spk_var_show, spk_var_store);72static struct kobj_attribute inflection_attribute =73__ATTR(inflection, 0644, spk_var_show, spk_var_store);74static struct kobj_attribute punct_attribute =75__ATTR(punct, 0644, spk_var_show, spk_var_store);76static struct kobj_attribute rate_attribute =77__ATTR(rate, 0644, spk_var_show, spk_var_store);78static struct kobj_attribute voice_attribute =79__ATTR(voice, 0644, spk_var_show, spk_var_store);80static struct kobj_attribute vol_attribute =81__ATTR(vol, 0644, spk_var_show, spk_var_store);8283static struct kobj_attribute delay_time_attribute =84__ATTR(delay_time, 0644, spk_var_show, spk_var_store);85static struct kobj_attribute direct_attribute =86__ATTR(direct, 0644, spk_var_show, spk_var_store);87static struct kobj_attribute full_time_attribute =88__ATTR(full_time, 0644, spk_var_show, spk_var_store);89static struct kobj_attribute flush_time_attribute =90__ATTR(flush_time, 0644, spk_var_show, spk_var_store);91static struct kobj_attribute jiffy_delta_attribute =92__ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);93static struct kobj_attribute trigger_time_attribute =94__ATTR(trigger_time, 0644, spk_var_show, spk_var_store);9596/*97* Create a group of attributes so that we can create and destroy them all98* at once.99*/100static struct attribute *synth_attrs[] = {101&caps_start_attribute.attr,102&caps_stop_attribute.attr,103&pitch_attribute.attr,104&inflection_attribute.attr,105&punct_attribute.attr,106&rate_attribute.attr,107&voice_attribute.attr,108&vol_attribute.attr,109&delay_time_attribute.attr,110&direct_attribute.attr,111&full_time_attribute.attr,112&flush_time_attribute.attr,113&jiffy_delta_attribute.attr,114&trigger_time_attribute.attr,115NULL, /* need to NULL terminate the list of attributes */116};117118static int ap_defaults[] = {122, 89, 155, 110, 208, 240, 200, 106, 306};119static int g5_defaults[] = {86, 81, 86, 84, 81, 80, 83, 83, 73};120121static struct spk_synth synth_dectlk = {122.name = "dectlk",123.version = DRV_VERSION,124.long_name = "Dectalk Express",125.init = "[:error sp :name paul :rate 180 :tsr off] ",126.procspeech = PROCSPEECH,127.clear = SYNTH_CLEAR,128.delay = 500,129.trigger = 50,130.jiffies = 50,131.full = 40000,132.flush_time = 4000,133.dev_name = SYNTH_DEFAULT_DEV,134.startup = SYNTH_START,135.checkval = SYNTH_CHECK,136.vars = vars,137.default_pitch = ap_defaults,138.default_vol = g5_defaults,139.io_ops = &spk_ttyio_ops,140.probe = spk_ttyio_synth_probe,141.release = spk_ttyio_release,142.synth_immediate = spk_ttyio_synth_immediate,143.catch_up = do_catch_up,144.flush = synth_flush,145.is_alive = spk_synth_is_alive_restart,146.synth_adjust = NULL,147.read_buff_add = read_buff_add,148.get_index = get_index,149.indexing = {150.command = "[:in re %d ] ",151.lowindex = 1,152.highindex = 8,153.currindex = 1,154},155.attributes = {156.attrs = synth_attrs,157.name = "dectlk",158},159};160161static int is_indnum(u_char *ch)162{163if ((*ch >= '0') && (*ch <= '9')) {164*ch = *ch - '0';165return 1;166}167return 0;168}169170static u_char lastind;171172static unsigned char get_index(struct spk_synth *synth)173{174u_char rv;175176rv = lastind;177lastind = 0;178return rv;179}180181static void read_buff_add(u_char c)182{183static int ind = -1;184185if (c == 0x01) {186unsigned long flags;187188spin_lock_irqsave(&flush_lock, flags);189is_flushing = 0;190wake_up_interruptible(&flush);191spin_unlock_irqrestore(&flush_lock, flags);192} else if (c == 0x13) {193xoff = 1;194} else if (c == 0x11) {195xoff = 0;196} else if (is_indnum(&c)) {197if (ind == -1)198ind = c;199else200ind = ind * 10 + c;201} else if ((c > 31) && (c < 127)) {202if (ind != -1)203lastind = (u_char)ind;204ind = -1;205}206}207208static void do_catch_up(struct spk_synth *synth)209{210int synth_full_val = 0;211static u_char ch;212static u_char last = '\0';213unsigned long flags;214unsigned long jiff_max;215unsigned long timeout;216DEFINE_WAIT(wait);217struct var_t *jiffy_delta;218struct var_t *delay_time;219struct var_t *flush_time;220int jiffy_delta_val;221int delay_time_val;222int timeout_val;223224jiffy_delta = spk_get_var(JIFFY);225delay_time = spk_get_var(DELAY);226flush_time = spk_get_var(FLUSH);227spin_lock_irqsave(&speakup_info.spinlock, flags);228jiffy_delta_val = jiffy_delta->u.n.value;229timeout_val = flush_time->u.n.value;230spin_unlock_irqrestore(&speakup_info.spinlock, flags);231timeout = msecs_to_jiffies(timeout_val);232jiff_max = jiffies + jiffy_delta_val;233234while (!kthread_should_stop()) {235/* if no ctl-a in 4, send data anyway */236spin_lock_irqsave(&flush_lock, flags);237while (is_flushing && timeout) {238prepare_to_wait(&flush, &wait, TASK_INTERRUPTIBLE);239spin_unlock_irqrestore(&flush_lock, flags);240timeout = schedule_timeout(timeout);241spin_lock_irqsave(&flush_lock, flags);242}243finish_wait(&flush, &wait);244is_flushing = 0;245spin_unlock_irqrestore(&flush_lock, flags);246247spin_lock_irqsave(&speakup_info.spinlock, flags);248if (speakup_info.flushing) {249speakup_info.flushing = 0;250spin_unlock_irqrestore(&speakup_info.spinlock, flags);251synth->flush(synth);252continue;253}254synth_buffer_skip_nonlatin1();255if (synth_buffer_empty()) {256spin_unlock_irqrestore(&speakup_info.spinlock, flags);257break;258}259ch = synth_buffer_peek();260set_current_state(TASK_INTERRUPTIBLE);261delay_time_val = delay_time->u.n.value;262synth_full_val = synth_full();263spin_unlock_irqrestore(&speakup_info.spinlock, flags);264if (ch == '\n')265ch = 0x0D;266if (synth_full_val || !synth->io_ops->synth_out(synth, ch)) {267schedule_timeout(msecs_to_jiffies(delay_time_val));268continue;269}270set_current_state(TASK_RUNNING);271spin_lock_irqsave(&speakup_info.spinlock, flags);272synth_buffer_getc();273spin_unlock_irqrestore(&speakup_info.spinlock, flags);274if (ch == '[') {275in_escape = 1;276} else if (ch == ']') {277in_escape = 0;278} else if (ch <= SPACE) {279if (!in_escape && strchr(",.!?;:", last))280synth->io_ops->synth_out(synth, PROCSPEECH);281if (time_after_eq(jiffies, jiff_max)) {282if (!in_escape)283synth->io_ops->synth_out(synth,284PROCSPEECH);285spin_lock_irqsave(&speakup_info.spinlock,286flags);287jiffy_delta_val = jiffy_delta->u.n.value;288delay_time_val = delay_time->u.n.value;289spin_unlock_irqrestore(&speakup_info.spinlock,290flags);291schedule_timeout(msecs_to_jiffies292(delay_time_val));293jiff_max = jiffies + jiffy_delta_val;294}295}296last = ch;297}298if (!in_escape)299synth->io_ops->synth_out(synth, PROCSPEECH);300}301302static void synth_flush(struct spk_synth *synth)303{304if (in_escape)305/* if in command output ']' so we don't get an error */306synth->io_ops->synth_out(synth, ']');307in_escape = 0;308is_flushing = 1;309synth->io_ops->flush_buffer(synth);310synth->io_ops->synth_out(synth, SYNTH_CLEAR);311}312313module_param_named(ser, synth_dectlk.ser, int, 0444);314module_param_named(dev, synth_dectlk.dev_name, charp, 0444);315module_param_named(start, synth_dectlk.startup, short, 0444);316module_param_named(rate, vars[RATE_ID].u.n.default_val, int, 0444);317module_param_named(pitch, vars[PITCH_ID].u.n.default_val, int, 0444);318module_param_named(inflection, vars[INFLECTION_ID].u.n.default_val, int, 0444);319module_param_named(vol, vars[VOL_ID].u.n.default_val, int, 0444);320module_param_named(punct, vars[PUNCT_ID].u.n.default_val, int, 0444);321module_param_named(voice, vars[VOICE_ID].u.n.default_val, int, 0444);322module_param_named(direct, vars[DIRECT_ID].u.n.default_val, int, 0444);323324325326MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");327MODULE_PARM_DESC(dev, "Set the device e.g. ttyUSB0, for the synthesizer.");328MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");329MODULE_PARM_DESC(rate, "Set the rate variable on load.");330MODULE_PARM_DESC(pitch, "Set the pitch variable on load.");331MODULE_PARM_DESC(inflection, "Set the inflection variable on load.");332MODULE_PARM_DESC(vol, "Set the vol variable on load.");333MODULE_PARM_DESC(punct, "Set the punct variable on load.");334MODULE_PARM_DESC(voice, "Set the voice variable on load.");335MODULE_PARM_DESC(direct, "Set the direct variable on load.");336337338module_spk_synth(synth_dectlk);339340MODULE_AUTHOR("Kirk Reiser <[email protected]>");341MODULE_AUTHOR("David Borowski");342MODULE_DESCRIPTION("Speakup support for DECtalk Express synthesizers");343MODULE_LICENSE("GPL");344MODULE_VERSION(DRV_VERSION);345346347348