1/* 2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 3* this version considerably modified by David Borowski, david575@rogers.com 4 * 5 * Copyright (C) 1998-99 Kirk Reiser. 6 * Copyright (C) 2003 David Borowski. 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * 22 * this code is specificly written as a driver for the speakup screenreview 23 * package and is not a general device driver. 24 */ 25#include <linux/jiffies.h> 26#include <linux/sched.h> 27#include <linux/timer.h> 28#include <linux/kthread.h> 29 30#include "spk_priv.h" 31#include "serialio.h" 32#include "speakup.h" 33 34#define DRV_VERSION "2.21" 35#define SYNTH_CLEAR 0x18 36#define PROCSPEECH '\r' 37 38static void do_catch_up(struct spk_synth *synth); 39 40static struct var_t vars[] = { 41 { CAPS_START, .u.s = {"cap, " } }, 42 { CAPS_STOP, .u.s = {"" } }, 43 { RATE, .u.n = {"@W%d", 6, 1, 9, 0, 0, NULL } }, 44 { PITCH, .u.n = {"@F%x", 10, 0, 15, 0, 0, NULL } }, 45 { VOL, .u.n = {"@A%x", 10, 0, 15, 0, 0, NULL } }, 46 { VOICE, .u.n = {"@V%d", 1, 1, 6, 0, 0, NULL } }, 47 { LANG, .u.n = {"@=%d,", 1, 1, 4, 0, 0, NULL } }, 48 { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } }, 49 V_LAST_VAR 50}; 51 52/* 53 * These attributes will appear in /sys/accessibility/speakup/apollo. 54 */ 55static struct kobj_attribute caps_start_attribute = 56 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 57static struct kobj_attribute caps_stop_attribute = 58 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 59static struct kobj_attribute lang_attribute = 60 __ATTR(lang, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 61static struct kobj_attribute pitch_attribute = 62 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 63static struct kobj_attribute rate_attribute = 64 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 65static struct kobj_attribute voice_attribute = 66 __ATTR(voice, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 67static struct kobj_attribute vol_attribute = 68 __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 69 70static struct kobj_attribute delay_time_attribute = 71 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 72static struct kobj_attribute direct_attribute = 73 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 74static struct kobj_attribute full_time_attribute = 75 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 76static struct kobj_attribute jiffy_delta_attribute = 77 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 78static struct kobj_attribute trigger_time_attribute = 79 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 80 81/* 82 * Create a group of attributes so that we can create and destroy them all 83 * at once. 84 */ 85static struct attribute *synth_attrs[] = { 86 &caps_start_attribute.attr, 87 &caps_stop_attribute.attr, 88 &lang_attribute.attr, 89 &pitch_attribute.attr, 90 &rate_attribute.attr, 91 &voice_attribute.attr, 92 &vol_attribute.attr, 93 &delay_time_attribute.attr, 94 &direct_attribute.attr, 95 &full_time_attribute.attr, 96 &jiffy_delta_attribute.attr, 97 &trigger_time_attribute.attr, 98 NULL, /* need to NULL terminate the list of attributes */ 99}; 100 101static struct spk_synth synth_apollo = { 102 .name = "apollo", 103 .version = DRV_VERSION, 104 .long_name = "Apollo", 105 .init = "@R3@D0@K1\r", 106 .procspeech = PROCSPEECH, 107 .clear = SYNTH_CLEAR, 108 .delay = 500, 109 .trigger = 50, 110 .jiffies = 50, 111 .full = 40000, 112 .startup = SYNTH_START, 113 .checkval = SYNTH_CHECK, 114 .vars = vars, 115 .probe = spk_serial_synth_probe, 116 .release = spk_serial_release, 117 .synth_immediate = spk_synth_immediate, 118 .catch_up = do_catch_up, 119 .flush = spk_synth_flush, 120 .is_alive = spk_synth_is_alive_restart, 121 .synth_adjust = NULL, 122 .read_buff_add = NULL, 123 .get_index = NULL, 124 .indexing = { 125 .command = NULL, 126 .lowindex = 0, 127 .highindex = 0, 128 .currindex = 0, 129 }, 130 .attributes = { 131 .attrs = synth_attrs, 132 .name = "apollo", 133 }, 134}; 135 136static void do_catch_up(struct spk_synth *synth) 137{ 138 u_char ch; 139 unsigned long flags; 140 unsigned long jiff_max; 141 struct var_t *jiffy_delta; 142 struct var_t *delay_time; 143 struct var_t *full_time; 144 int full_time_val = 0; 145 int delay_time_val = 0; 146 int jiffy_delta_val = 0; 147 148 jiffy_delta = spk_get_var(JIFFY); 149 delay_time = spk_get_var(DELAY); 150 full_time = spk_get_var(FULL); 151 spin_lock_irqsave(&speakup_info.spinlock, flags); 152 jiffy_delta_val = jiffy_delta->u.n.value; 153 spin_unlock_irqrestore(&speakup_info.spinlock, flags); 154 jiff_max = jiffies + jiffy_delta_val; 155 156 while (!kthread_should_stop()) { 157 spin_lock_irqsave(&speakup_info.spinlock, flags); 158 jiffy_delta_val = jiffy_delta->u.n.value; 159 full_time_val = full_time->u.n.value; 160 delay_time_val = delay_time->u.n.value; 161 if (speakup_info.flushing) { 162 speakup_info.flushing = 0; 163 spin_unlock_irqrestore(&speakup_info.spinlock, flags); 164 synth->flush(synth); 165 continue; 166 } 167 if (synth_buffer_empty()) { 168 spin_unlock_irqrestore(&speakup_info.spinlock, flags); 169 break; 170 } 171 ch = synth_buffer_peek(); 172 set_current_state(TASK_INTERRUPTIBLE); 173 full_time_val = full_time->u.n.value; 174 spin_unlock_irqrestore(&speakup_info.spinlock, flags); 175 if (!spk_serial_out(ch)) { 176 outb(UART_MCR_DTR, speakup_info.port_tts + UART_MCR); 177 outb(UART_MCR_DTR | UART_MCR_RTS, 178 speakup_info.port_tts + UART_MCR); 179 schedule_timeout(msecs_to_jiffies(full_time_val)); 180 continue; 181 } 182 if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) { 183 spin_lock_irqsave(&speakup_info.spinlock, flags); 184 jiffy_delta_val = jiffy_delta->u.n.value; 185 full_time_val = full_time->u.n.value; 186 delay_time_val = delay_time->u.n.value; 187 spin_unlock_irqrestore(&speakup_info.spinlock, flags); 188 if (spk_serial_out(synth->procspeech)) 189 schedule_timeout(msecs_to_jiffies 190 (delay_time_val)); 191 else 192 schedule_timeout(msecs_to_jiffies 193 (full_time_val)); 194 jiff_max = jiffies + jiffy_delta_val; 195 } 196 set_current_state(TASK_RUNNING); 197 spin_lock_irqsave(&speakup_info.spinlock, flags); 198 synth_buffer_getc(); 199 spin_unlock_irqrestore(&speakup_info.spinlock, flags); 200 } 201 spk_serial_out(PROCSPEECH); 202} 203 204module_param_named(ser, synth_apollo.ser, int, S_IRUGO); 205module_param_named(start, synth_apollo.startup, short, S_IRUGO); 206 207MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based)."); 208MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 209 210static int __init apollo_init(void) 211{ 212 return synth_add(&synth_apollo); 213} 214 215static void __exit apollo_exit(void) 216{ 217 synth_remove(&synth_apollo); 218} 219 220module_init(apollo_init); 221module_exit(apollo_exit); 222MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>"); 223MODULE_AUTHOR("David Borowski"); 224MODULE_DESCRIPTION("Speakup support for Apollo II synthesizer"); 225MODULE_LICENSE("GPL"); 226MODULE_VERSION(DRV_VERSION); 227 228