spi-topcliff-pch: add recovery processing in case wait-event timeout
[zen-stable.git] / drivers / staging / speakup / speakup_decext.c
blobb4ef9153f42e10afea800aea912ccf52ae102cf9
1 /*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3 * this version considerably modified by David Borowski, david575@rogers.com
5 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski.
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.
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.
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
22 * specificly written as a driver for the speakup screenreview
23 * s not a general device driver.
25 #include <linux/jiffies.h>
26 #include <linux/sched.h>
27 #include <linux/timer.h>
28 #include <linux/kthread.h>
30 #include "spk_priv.h"
31 #include "serialio.h"
32 #include "speakup.h"
34 #define DRV_VERSION "2.14"
35 #define SYNTH_CLEAR 0x03
36 #define PROCSPEECH 0x0b
37 static unsigned char last_char;
39 static inline u_char get_last_char(void)
41 u_char avail = inb_p(speakup_info.port_tts + UART_LSR) & UART_LSR_DR;
42 if (avail)
43 last_char = inb_p(speakup_info.port_tts + UART_RX);
44 return last_char;
47 static inline bool synth_full(void)
49 return get_last_char() == 0x13;
52 static void do_catch_up(struct spk_synth *synth);
53 static void synth_flush(struct spk_synth *synth);
55 static int in_escape;
57 static struct var_t vars[] = {
58 { CAPS_START, .u.s = {"[:dv ap 222]" } },
59 { CAPS_STOP, .u.s = {"[:dv ap 100]" } },
60 { RATE, .u.n = {"[:ra %d]", 7, 0, 9, 150, 25, NULL } },
61 { PITCH, .u.n = {"[:dv ap %d]", 100, 0, 100, 0, 0, NULL } },
62 { VOL, .u.n = {"[:dv gv %d]", 13, 0, 16, 0, 5, NULL } },
63 { PUNCT, .u.n = {"[:pu %c]", 0, 0, 2, 0, 0, "nsa" } },
64 { VOICE, .u.n = {"[:n%c]", 0, 0, 9, 0, 0, "phfdburwkv" } },
65 { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
66 V_LAST_VAR
70 * These attributes will appear in /sys/accessibility/speakup/decext.
72 static struct kobj_attribute caps_start_attribute =
73 __ATTR(caps_start, USER_RW, spk_var_show, spk_var_store);
74 static struct kobj_attribute caps_stop_attribute =
75 __ATTR(caps_stop, USER_RW, spk_var_show, spk_var_store);
76 static struct kobj_attribute pitch_attribute =
77 __ATTR(pitch, USER_RW, spk_var_show, spk_var_store);
78 static struct kobj_attribute punct_attribute =
79 __ATTR(punct, USER_RW, spk_var_show, spk_var_store);
80 static struct kobj_attribute rate_attribute =
81 __ATTR(rate, USER_RW, spk_var_show, spk_var_store);
82 static struct kobj_attribute voice_attribute =
83 __ATTR(voice, USER_RW, spk_var_show, spk_var_store);
84 static struct kobj_attribute vol_attribute =
85 __ATTR(vol, USER_RW, spk_var_show, spk_var_store);
87 static struct kobj_attribute delay_time_attribute =
88 __ATTR(delay_time, ROOT_W, spk_var_show, spk_var_store);
89 static struct kobj_attribute direct_attribute =
90 __ATTR(direct, USER_RW, spk_var_show, spk_var_store);
91 static struct kobj_attribute full_time_attribute =
92 __ATTR(full_time, ROOT_W, spk_var_show, spk_var_store);
93 static struct kobj_attribute jiffy_delta_attribute =
94 __ATTR(jiffy_delta, ROOT_W, spk_var_show, spk_var_store);
95 static struct kobj_attribute trigger_time_attribute =
96 __ATTR(trigger_time, ROOT_W, spk_var_show, spk_var_store);
99 * Create a group of attributes so that we can create and destroy them all
100 * at once.
102 static struct attribute *synth_attrs[] = {
103 &caps_start_attribute.attr,
104 &caps_stop_attribute.attr,
105 &pitch_attribute.attr,
106 &punct_attribute.attr,
107 &rate_attribute.attr,
108 &voice_attribute.attr,
109 &vol_attribute.attr,
110 &delay_time_attribute.attr,
111 &direct_attribute.attr,
112 &full_time_attribute.attr,
113 &jiffy_delta_attribute.attr,
114 &trigger_time_attribute.attr,
115 NULL, /* need to NULL terminate the list of attributes */
118 static struct spk_synth synth_decext = {
119 .name = "decext",
120 .version = DRV_VERSION,
121 .long_name = "Dectalk External",
122 .init = "[:pe -380]",
123 .procspeech = PROCSPEECH,
124 .clear = SYNTH_CLEAR,
125 .delay = 500,
126 .trigger = 50,
127 .jiffies = 50,
128 .full = 40000,
129 .flags = SF_DEC,
130 .startup = SYNTH_START,
131 .checkval = SYNTH_CHECK,
132 .vars = vars,
133 .probe = serial_synth_probe,
134 .release = spk_serial_release,
135 .synth_immediate = spk_synth_immediate,
136 .catch_up = do_catch_up,
137 .flush = synth_flush,
138 .is_alive = spk_synth_is_alive_restart,
139 .synth_adjust = NULL,
140 .read_buff_add = NULL,
141 .get_index = NULL,
142 .indexing = {
143 .command = NULL,
144 .lowindex = 0,
145 .highindex = 0,
146 .currindex = 0,
148 .attributes = {
149 .attrs = synth_attrs,
150 .name = "decext",
154 static void do_catch_up(struct spk_synth *synth)
156 u_char ch;
157 static u_char last = '\0';
158 unsigned long flags;
159 unsigned long jiff_max;
160 struct var_t *jiffy_delta;
161 struct var_t *delay_time;
162 int jiffy_delta_val = 0;
163 int delay_time_val = 0;
165 jiffy_delta = get_var(JIFFY);
166 delay_time = get_var(DELAY);
168 spk_lock(flags);
169 jiffy_delta_val = jiffy_delta->u.n.value;
170 spk_unlock(flags);
171 jiff_max = jiffies + jiffy_delta_val;
173 while (!kthread_should_stop()) {
174 spk_lock(flags);
175 if (speakup_info.flushing) {
176 speakup_info.flushing = 0;
177 spk_unlock(flags);
178 synth->flush(synth);
179 continue;
181 if (synth_buffer_empty()) {
182 spk_unlock(flags);
183 break;
185 ch = synth_buffer_peek();
186 set_current_state(TASK_INTERRUPTIBLE);
187 delay_time_val = delay_time->u.n.value;
188 spk_unlock(flags);
189 if (ch == '\n')
190 ch = 0x0D;
191 if (synth_full() || !spk_serial_out(ch)) {
192 schedule_timeout(msecs_to_jiffies(delay_time_val));
193 continue;
195 set_current_state(TASK_RUNNING);
196 spk_lock(flags);
197 synth_buffer_getc();
198 spk_unlock(flags);
199 if (ch == '[')
200 in_escape = 1;
201 else if (ch == ']')
202 in_escape = 0;
203 else if (ch <= SPACE) {
204 if (!in_escape && strchr(",.!?;:", last))
205 spk_serial_out(PROCSPEECH);
206 if (jiffies >= jiff_max) {
207 if (!in_escape)
208 spk_serial_out(PROCSPEECH);
209 spk_lock(flags);
210 jiffy_delta_val = jiffy_delta->u.n.value;
211 delay_time_val = delay_time->u.n.value;
212 spk_unlock(flags);
213 schedule_timeout(msecs_to_jiffies
214 (delay_time_val));
215 jiff_max = jiffies + jiffy_delta_val;
218 last = ch;
220 if (!in_escape)
221 spk_serial_out(PROCSPEECH);
224 static void synth_flush(struct spk_synth *synth)
226 in_escape = 0;
227 spk_synth_immediate(synth, "\033P;10z\033\\");
230 module_param_named(ser, synth_decext.ser, int, S_IRUGO);
231 module_param_named(start, synth_decext.startup, short, S_IRUGO);
233 MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
234 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
236 static int __init decext_init(void)
238 return synth_add(&synth_decext);
241 static void __exit decext_exit(void)
243 synth_remove(&synth_decext);
246 module_init(decext_init);
247 module_exit(decext_exit);
248 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
249 MODULE_AUTHOR("David Borowski");
250 MODULE_DESCRIPTION("Speakup support for DECtalk External synthesizers");
251 MODULE_LICENSE("GPL");
252 MODULE_VERSION(DRV_VERSION);