Path: blob/master/drivers/accessibility/speakup/speakup_apollo.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* this code is specifically written as a driver for the speakup screenreview9* package and is not a general device driver.10*/11#include <linux/jiffies.h>12#include <linux/sched.h>13#include <linux/timer.h>14#include <linux/kthread.h>15#include <linux/serial_reg.h> /* for UART_MCR* constants */1617#include "spk_priv.h"18#include "speakup.h"1920#define DRV_VERSION "2.21"21#define SYNTH_CLEAR 0x1822#define PROCSPEECH '\r'2324static void do_catch_up(struct spk_synth *synth);25262728enum default_vars_id {29CAPS_START_ID = 0, CAPS_STOP_ID,30RATE_ID, PITCH_ID,31VOL_ID, VOICE_ID, LANG_ID,32DIRECT_ID, V_LAST_VAR_ID,33NB_ID34};3536373839static struct var_t vars[NB_ID] = {40[CAPS_START_ID] = { CAPS_START, .u.s = {"cap, " } },41[CAPS_STOP_ID] = { CAPS_STOP, .u.s = {"" } },42[RATE_ID] = { RATE, .u.n = {"@W%d", 6, 1, 9, 0, 0, NULL } },43[PITCH_ID] = { PITCH, .u.n = {"@F%x", 10, 0, 15, 0, 0, NULL } },44[VOL_ID] = { VOL, .u.n = {"@A%x", 10, 0, 15, 0, 0, NULL } },45[VOICE_ID] = { VOICE, .u.n = {"@V%d", 1, 1, 6, 0, 0, NULL } },46[LANG_ID] = { LANG, .u.n = {"@=%d,", 1, 1, 4, 0, 0, NULL } },47[DIRECT_ID] = { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },48V_LAST_VAR49};5051/*52* These attributes will appear in /sys/accessibility/speakup/apollo.53*/54static struct kobj_attribute caps_start_attribute =55__ATTR(caps_start, 0644, spk_var_show, spk_var_store);56static struct kobj_attribute caps_stop_attribute =57__ATTR(caps_stop, 0644, spk_var_show, spk_var_store);58static struct kobj_attribute lang_attribute =59__ATTR(lang, 0644, spk_var_show, spk_var_store);60static struct kobj_attribute pitch_attribute =61__ATTR(pitch, 0644, spk_var_show, spk_var_store);62static struct kobj_attribute rate_attribute =63__ATTR(rate, 0644, spk_var_show, spk_var_store);64static struct kobj_attribute voice_attribute =65__ATTR(voice, 0644, spk_var_show, spk_var_store);66static struct kobj_attribute vol_attribute =67__ATTR(vol, 0644, spk_var_show, spk_var_store);6869static struct kobj_attribute delay_time_attribute =70__ATTR(delay_time, 0644, spk_var_show, spk_var_store);71static struct kobj_attribute direct_attribute =72__ATTR(direct, 0644, spk_var_show, spk_var_store);73static struct kobj_attribute full_time_attribute =74__ATTR(full_time, 0644, spk_var_show, spk_var_store);75static struct kobj_attribute jiffy_delta_attribute =76__ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);77static struct kobj_attribute trigger_time_attribute =78__ATTR(trigger_time, 0644, spk_var_show, spk_var_store);7980/*81* Create a group of attributes so that we can create and destroy them all82* at once.83*/84static struct attribute *synth_attrs[] = {85&caps_start_attribute.attr,86&caps_stop_attribute.attr,87&lang_attribute.attr,88&pitch_attribute.attr,89&rate_attribute.attr,90&voice_attribute.attr,91&vol_attribute.attr,92&delay_time_attribute.attr,93&direct_attribute.attr,94&full_time_attribute.attr,95&jiffy_delta_attribute.attr,96&trigger_time_attribute.attr,97NULL, /* need to NULL terminate the list of attributes */98};99100static struct spk_synth synth_apollo = {101.name = "apollo",102.version = DRV_VERSION,103.long_name = "Apollo",104.init = "@R3@D0@K1\r",105.procspeech = PROCSPEECH,106.clear = SYNTH_CLEAR,107.delay = 500,108.trigger = 50,109.jiffies = 50,110.full = 40000,111.dev_name = SYNTH_DEFAULT_DEV,112.startup = SYNTH_START,113.checkval = SYNTH_CHECK,114.vars = vars,115.io_ops = &spk_ttyio_ops,116.probe = spk_ttyio_synth_probe,117.release = spk_ttyio_release,118.synth_immediate = spk_ttyio_synth_immediate,119.catch_up = do_catch_up,120.flush = spk_synth_flush,121.is_alive = spk_synth_is_alive_restart,122.synth_adjust = NULL,123.read_buff_add = NULL,124.get_index = NULL,125.indexing = {126.command = NULL,127.lowindex = 0,128.highindex = 0,129.currindex = 0,130},131.attributes = {132.attrs = synth_attrs,133.name = "apollo",134},135};136137static void do_catch_up(struct spk_synth *synth)138{139u_char ch;140unsigned long flags;141unsigned long jiff_max;142struct var_t *jiffy_delta;143struct var_t *delay_time;144struct var_t *full_time;145int full_time_val = 0;146int delay_time_val = 0;147int jiffy_delta_val = 0;148149jiffy_delta = spk_get_var(JIFFY);150delay_time = spk_get_var(DELAY);151full_time = spk_get_var(FULL);152spin_lock_irqsave(&speakup_info.spinlock, flags);153jiffy_delta_val = jiffy_delta->u.n.value;154spin_unlock_irqrestore(&speakup_info.spinlock, flags);155jiff_max = jiffies + jiffy_delta_val;156157while (!kthread_should_stop()) {158spin_lock_irqsave(&speakup_info.spinlock, flags);159jiffy_delta_val = jiffy_delta->u.n.value;160full_time_val = full_time->u.n.value;161delay_time_val = delay_time->u.n.value;162if (speakup_info.flushing) {163speakup_info.flushing = 0;164spin_unlock_irqrestore(&speakup_info.spinlock, flags);165synth->flush(synth);166continue;167}168synth_buffer_skip_nonlatin1();169if (synth_buffer_empty()) {170spin_unlock_irqrestore(&speakup_info.spinlock, flags);171break;172}173ch = synth_buffer_peek();174set_current_state(TASK_INTERRUPTIBLE);175full_time_val = full_time->u.n.value;176spin_unlock_irqrestore(&speakup_info.spinlock, flags);177if (!synth->io_ops->synth_out(synth, ch)) {178synth->io_ops->tiocmset(synth, 0, UART_MCR_RTS);179synth->io_ops->tiocmset(synth, UART_MCR_RTS, 0);180schedule_timeout(msecs_to_jiffies(full_time_val));181continue;182}183if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) {184spin_lock_irqsave(&speakup_info.spinlock, flags);185jiffy_delta_val = jiffy_delta->u.n.value;186full_time_val = full_time->u.n.value;187delay_time_val = delay_time->u.n.value;188spin_unlock_irqrestore(&speakup_info.spinlock, flags);189if (synth->io_ops->synth_out(synth, synth->procspeech))190schedule_timeout(msecs_to_jiffies191(delay_time_val));192else193schedule_timeout(msecs_to_jiffies194(full_time_val));195jiff_max = jiffies + jiffy_delta_val;196}197set_current_state(TASK_RUNNING);198spin_lock_irqsave(&speakup_info.spinlock, flags);199synth_buffer_getc();200spin_unlock_irqrestore(&speakup_info.spinlock, flags);201}202synth->io_ops->synth_out(synth, PROCSPEECH);203}204205module_param_named(ser, synth_apollo.ser, int, 0444);206module_param_named(dev, synth_apollo.dev_name, charp, 0444);207module_param_named(start, synth_apollo.startup, short, 0444);208module_param_named(rate, vars[RATE_ID].u.n.default_val, int, 0444);209module_param_named(pitch, vars[PITCH_ID].u.n.default_val, int, 0444);210module_param_named(vol, vars[VOL_ID].u.n.default_val, int, 0444);211module_param_named(voice, vars[VOICE_ID].u.n.default_val, int, 0444);212module_param_named(lang, vars[LANG_ID].u.n.default_val, int, 0444);213module_param_named(direct, vars[DIRECT_ID].u.n.default_val, int, 0444);214215216MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");217MODULE_PARM_DESC(dev, "Set the device e.g. ttyUSB0, for the synthesizer.");218MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");219MODULE_PARM_DESC(rate, "Set the rate variable on load.");220MODULE_PARM_DESC(pitch, "Set the pitch variable on load.");221MODULE_PARM_DESC(vol, "Set the vol variable on load.");222MODULE_PARM_DESC(voice, "Set the voice variable on load.");223MODULE_PARM_DESC(lang, "Set the lang variable on load.");224MODULE_PARM_DESC(direct, "Set the direct variable on load.");225226227228module_spk_synth(synth_apollo);229230MODULE_AUTHOR("Kirk Reiser <[email protected]>");231MODULE_AUTHOR("David Borowski");232MODULE_DESCRIPTION("Speakup support for Apollo II synthesizer");233MODULE_LICENSE("GPL");234MODULE_VERSION(DRV_VERSION);235236237238