William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 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 | * specificly written as a driver for the speakup screenreview |
| 23 | * s 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.14" |
| 35 | #define SYNTH_CLEAR 0x03 |
| 36 | #define PROCSPEECH 0x0b |
| 37 | static unsigned char last_char; |
Christopher Brannon | 3d4f7ea | 2010-10-14 19:23:51 -0500 | [diff] [blame] | 38 | |
| 39 | static inline u_char get_last_char(void) |
| 40 | { |
| 41 | u_char avail = inb_p(speakup_info.port_tts + UART_LSR) & UART_LSR_DR; |
Domagoj Trsan | 8e69a81 | 2014-09-09 20:04:34 +0200 | [diff] [blame] | 42 | |
Christopher Brannon | 3d4f7ea | 2010-10-14 19:23:51 -0500 | [diff] [blame] | 43 | if (avail) |
| 44 | last_char = inb_p(speakup_info.port_tts + UART_RX); |
| 45 | return last_char; |
| 46 | } |
| 47 | |
| 48 | static inline bool synth_full(void) |
| 49 | { |
| 50 | return get_last_char() == 0x13; |
| 51 | } |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 52 | |
| 53 | static void do_catch_up(struct spk_synth *synth); |
| 54 | static void synth_flush(struct spk_synth *synth); |
| 55 | |
| 56 | static int in_escape; |
| 57 | |
| 58 | static struct var_t vars[] = { |
Christopher Brannon | 3d4f7ea | 2010-10-14 19:23:51 -0500 | [diff] [blame] | 59 | { CAPS_START, .u.s = {"[:dv ap 222]" } }, |
| 60 | { CAPS_STOP, .u.s = {"[:dv ap 100]" } }, |
| 61 | { RATE, .u.n = {"[:ra %d]", 7, 0, 9, 150, 25, NULL } }, |
| 62 | { PITCH, .u.n = {"[:dv ap %d]", 100, 0, 100, 0, 0, NULL } }, |
| 63 | { VOL, .u.n = {"[:dv gv %d]", 13, 0, 16, 0, 5, NULL } }, |
| 64 | { PUNCT, .u.n = {"[:pu %c]", 0, 0, 2, 0, 0, "nsa" } }, |
| 65 | { VOICE, .u.n = {"[:n%c]", 0, 0, 9, 0, 0, "phfdburwkv" } }, |
| 66 | { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } }, |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 67 | V_LAST_VAR |
| 68 | }; |
| 69 | |
| 70 | /* |
| 71 | * These attributes will appear in /sys/accessibility/speakup/decext. |
| 72 | */ |
| 73 | static struct kobj_attribute caps_start_attribute = |
Rusty Russell | d901aaa | 2014-04-24 13:57:49 +0930 | [diff] [blame] | 74 | __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 75 | static struct kobj_attribute caps_stop_attribute = |
Rusty Russell | d901aaa | 2014-04-24 13:57:49 +0930 | [diff] [blame] | 76 | __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 77 | static struct kobj_attribute pitch_attribute = |
Rusty Russell | d901aaa | 2014-04-24 13:57:49 +0930 | [diff] [blame] | 78 | __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 79 | static struct kobj_attribute punct_attribute = |
Rusty Russell | d901aaa | 2014-04-24 13:57:49 +0930 | [diff] [blame] | 80 | __ATTR(punct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 81 | static struct kobj_attribute rate_attribute = |
Rusty Russell | d901aaa | 2014-04-24 13:57:49 +0930 | [diff] [blame] | 82 | __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 83 | static struct kobj_attribute voice_attribute = |
Rusty Russell | d901aaa | 2014-04-24 13:57:49 +0930 | [diff] [blame] | 84 | __ATTR(voice, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 85 | static struct kobj_attribute vol_attribute = |
Rusty Russell | d901aaa | 2014-04-24 13:57:49 +0930 | [diff] [blame] | 86 | __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 87 | |
| 88 | static struct kobj_attribute delay_time_attribute = |
Rusty Russell | 22c9bca | 2014-04-01 13:30:05 +1030 | [diff] [blame] | 89 | __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 90 | static struct kobj_attribute direct_attribute = |
Rusty Russell | d901aaa | 2014-04-24 13:57:49 +0930 | [diff] [blame] | 91 | __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 92 | static struct kobj_attribute full_time_attribute = |
Rusty Russell | 22c9bca | 2014-04-01 13:30:05 +1030 | [diff] [blame] | 93 | __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 94 | static struct kobj_attribute jiffy_delta_attribute = |
Rusty Russell | 22c9bca | 2014-04-01 13:30:05 +1030 | [diff] [blame] | 95 | __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 96 | static struct kobj_attribute trigger_time_attribute = |
Rusty Russell | 22c9bca | 2014-04-01 13:30:05 +1030 | [diff] [blame] | 97 | __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 98 | |
| 99 | /* |
| 100 | * Create a group of attributes so that we can create and destroy them all |
| 101 | * at once. |
| 102 | */ |
| 103 | static struct attribute *synth_attrs[] = { |
| 104 | &caps_start_attribute.attr, |
| 105 | &caps_stop_attribute.attr, |
| 106 | &pitch_attribute.attr, |
| 107 | &punct_attribute.attr, |
| 108 | &rate_attribute.attr, |
| 109 | &voice_attribute.attr, |
| 110 | &vol_attribute.attr, |
| 111 | &delay_time_attribute.attr, |
| 112 | &direct_attribute.attr, |
| 113 | &full_time_attribute.attr, |
| 114 | &jiffy_delta_attribute.attr, |
| 115 | &trigger_time_attribute.attr, |
| 116 | NULL, /* need to NULL terminate the list of attributes */ |
| 117 | }; |
| 118 | |
| 119 | static struct spk_synth synth_decext = { |
| 120 | .name = "decext", |
| 121 | .version = DRV_VERSION, |
| 122 | .long_name = "Dectalk External", |
| 123 | .init = "[:pe -380]", |
| 124 | .procspeech = PROCSPEECH, |
| 125 | .clear = SYNTH_CLEAR, |
| 126 | .delay = 500, |
| 127 | .trigger = 50, |
| 128 | .jiffies = 50, |
| 129 | .full = 40000, |
| 130 | .flags = SF_DEC, |
| 131 | .startup = SYNTH_START, |
| 132 | .checkval = SYNTH_CHECK, |
| 133 | .vars = vars, |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 134 | .probe = spk_serial_synth_probe, |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 135 | .release = spk_serial_release, |
| 136 | .synth_immediate = spk_synth_immediate, |
| 137 | .catch_up = do_catch_up, |
| 138 | .flush = synth_flush, |
| 139 | .is_alive = spk_synth_is_alive_restart, |
| 140 | .synth_adjust = NULL, |
| 141 | .read_buff_add = NULL, |
| 142 | .get_index = NULL, |
| 143 | .indexing = { |
| 144 | .command = NULL, |
| 145 | .lowindex = 0, |
| 146 | .highindex = 0, |
| 147 | .currindex = 0, |
| 148 | }, |
| 149 | .attributes = { |
| 150 | .attrs = synth_attrs, |
| 151 | .name = "decext", |
| 152 | }, |
| 153 | }; |
| 154 | |
| 155 | static void do_catch_up(struct spk_synth *synth) |
| 156 | { |
| 157 | u_char ch; |
| 158 | static u_char last = '\0'; |
| 159 | unsigned long flags; |
| 160 | unsigned long jiff_max; |
| 161 | struct var_t *jiffy_delta; |
| 162 | struct var_t *delay_time; |
| 163 | int jiffy_delta_val = 0; |
| 164 | int delay_time_val = 0; |
| 165 | |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 166 | jiffy_delta = spk_get_var(JIFFY); |
| 167 | delay_time = spk_get_var(DELAY); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 168 | |
William Hubbs | b4b93e3 | 2013-05-13 00:03:01 -0500 | [diff] [blame] | 169 | spin_lock_irqsave(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 170 | jiffy_delta_val = jiffy_delta->u.n.value; |
William Hubbs | b4b93e3 | 2013-05-13 00:03:01 -0500 | [diff] [blame] | 171 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 172 | jiff_max = jiffies + jiffy_delta_val; |
| 173 | |
| 174 | while (!kthread_should_stop()) { |
William Hubbs | b4b93e3 | 2013-05-13 00:03:01 -0500 | [diff] [blame] | 175 | spin_lock_irqsave(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 176 | if (speakup_info.flushing) { |
| 177 | speakup_info.flushing = 0; |
William Hubbs | b4b93e3 | 2013-05-13 00:03:01 -0500 | [diff] [blame] | 178 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 179 | synth->flush(synth); |
| 180 | continue; |
| 181 | } |
| 182 | if (synth_buffer_empty()) { |
William Hubbs | b4b93e3 | 2013-05-13 00:03:01 -0500 | [diff] [blame] | 183 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 184 | break; |
| 185 | } |
| 186 | ch = synth_buffer_peek(); |
| 187 | set_current_state(TASK_INTERRUPTIBLE); |
| 188 | delay_time_val = delay_time->u.n.value; |
William Hubbs | b4b93e3 | 2013-05-13 00:03:01 -0500 | [diff] [blame] | 189 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 190 | if (ch == '\n') |
| 191 | ch = 0x0D; |
| 192 | if (synth_full() || !spk_serial_out(ch)) { |
| 193 | schedule_timeout(msecs_to_jiffies(delay_time_val)); |
| 194 | continue; |
| 195 | } |
| 196 | set_current_state(TASK_RUNNING); |
William Hubbs | b4b93e3 | 2013-05-13 00:03:01 -0500 | [diff] [blame] | 197 | spin_lock_irqsave(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 198 | synth_buffer_getc(); |
William Hubbs | b4b93e3 | 2013-05-13 00:03:01 -0500 | [diff] [blame] | 199 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 200 | if (ch == '[') |
| 201 | in_escape = 1; |
| 202 | else if (ch == ']') |
| 203 | in_escape = 0; |
| 204 | else if (ch <= SPACE) { |
| 205 | if (!in_escape && strchr(",.!?;:", last)) |
| 206 | spk_serial_out(PROCSPEECH); |
Tapasweni Pathak | 89021ec | 2014-09-21 19:22:51 +0530 | [diff] [blame] | 207 | if (time_after_eq(jiffies, jiff_max)) { |
Christopher Brannon | 3d4f7ea | 2010-10-14 19:23:51 -0500 | [diff] [blame] | 208 | if (!in_escape) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 209 | spk_serial_out(PROCSPEECH); |
Shirish Gajera | 63b8ebe | 2015-03-28 13:21:39 -0700 | [diff] [blame] | 210 | spin_lock_irqsave(&speakup_info.spinlock, |
| 211 | flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 212 | jiffy_delta_val = jiffy_delta->u.n.value; |
| 213 | delay_time_val = delay_time->u.n.value; |
Shirish Gajera | 63b8ebe | 2015-03-28 13:21:39 -0700 | [diff] [blame] | 214 | spin_unlock_irqrestore(&speakup_info.spinlock, |
| 215 | flags); |
Christopher Brannon | 3d4f7ea | 2010-10-14 19:23:51 -0500 | [diff] [blame] | 216 | schedule_timeout(msecs_to_jiffies |
| 217 | (delay_time_val)); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 218 | jiff_max = jiffies + jiffy_delta_val; |
| 219 | } |
| 220 | } |
| 221 | last = ch; |
| 222 | } |
| 223 | if (!in_escape) |
| 224 | spk_serial_out(PROCSPEECH); |
| 225 | } |
| 226 | |
| 227 | static void synth_flush(struct spk_synth *synth) |
| 228 | { |
| 229 | in_escape = 0; |
| 230 | spk_synth_immediate(synth, "\033P;10z\033\\"); |
| 231 | } |
| 232 | |
| 233 | module_param_named(ser, synth_decext.ser, int, S_IRUGO); |
| 234 | module_param_named(start, synth_decext.startup, short, S_IRUGO); |
| 235 | |
| 236 | MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based)."); |
| 237 | MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); |
| 238 | |
Vaishali Thakkar | ae89fac | 2015-03-18 23:13:10 +0530 | [diff] [blame] | 239 | module_spk_synth(synth_decext); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 240 | |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 241 | MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>"); |
| 242 | MODULE_AUTHOR("David Borowski"); |
| 243 | MODULE_DESCRIPTION("Speakup support for DECtalk External synthesizers"); |
| 244 | MODULE_LICENSE("GPL"); |
| 245 | MODULE_VERSION(DRV_VERSION); |
| 246 | |