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 * specificly written as a driver for the speakup screenreview
19 * s not a general device driver.
21 #include <linux/jiffies.h>
22 #include <linux/sched.h>
23 #include <linux/timer.h>
24 #include <linux/kthread.h>
30 #define DRV_VERSION "2.14"
31 #define SYNTH_CLEAR 0x03
32 #define PROCSPEECH 0x0b
33 static unsigned char last_char;
35 static inline u_char get_last_char(void)
37 u_char avail = inb_p(speakup_info.port_tts + UART_LSR) & UART_LSR_DR;
40 last_char = inb_p(speakup_info.port_tts + UART_RX);
44 static inline bool synth_full(void)
46 return get_last_char() == 0x13;
49 static void do_catch_up(struct spk_synth *synth);
50 static void synth_flush(struct spk_synth *synth);
54 static struct var_t vars[] = {
55 { CAPS_START, .u.s = {"[:dv ap 222]" } },
56 { CAPS_STOP, .u.s = {"[:dv ap 100]" } },
57 { RATE, .u.n = {"[:ra %d]", 7, 0, 9, 150, 25, NULL } },
58 { PITCH, .u.n = {"[:dv ap %d]", 100, 0, 100, 0, 0, NULL } },
59 { VOL, .u.n = {"[:dv gv %d]", 13, 0, 16, 0, 5, NULL } },
60 { PUNCT, .u.n = {"[:pu %c]", 0, 0, 2, 0, 0, "nsa" } },
61 { VOICE, .u.n = {"[:n%c]", 0, 0, 9, 0, 0, "phfdburwkv" } },
62 { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
67 * These attributes will appear in /sys/accessibility/speakup/decext.
69 static struct kobj_attribute caps_start_attribute =
70 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
71 static struct kobj_attribute caps_stop_attribute =
72 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
73 static struct kobj_attribute pitch_attribute =
74 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
75 static struct kobj_attribute punct_attribute =
76 __ATTR(punct, 0644, spk_var_show, spk_var_store);
77 static struct kobj_attribute rate_attribute =
78 __ATTR(rate, 0644, spk_var_show, spk_var_store);
79 static struct kobj_attribute voice_attribute =
80 __ATTR(voice, 0644, spk_var_show, spk_var_store);
81 static struct kobj_attribute vol_attribute =
82 __ATTR(vol, 0644, spk_var_show, spk_var_store);
84 static struct kobj_attribute delay_time_attribute =
85 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
86 static struct kobj_attribute direct_attribute =
87 __ATTR(direct, 0644, spk_var_show, spk_var_store);
88 static struct kobj_attribute full_time_attribute =
89 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
90 static struct kobj_attribute jiffy_delta_attribute =
91 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
92 static struct kobj_attribute trigger_time_attribute =
93 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
96 * Create a group of attributes so that we can create and destroy them all
99 static struct attribute *synth_attrs[] = {
100 &caps_start_attribute.attr,
101 &caps_stop_attribute.attr,
102 &pitch_attribute.attr,
103 &punct_attribute.attr,
104 &rate_attribute.attr,
105 &voice_attribute.attr,
107 &delay_time_attribute.attr,
108 &direct_attribute.attr,
109 &full_time_attribute.attr,
110 &jiffy_delta_attribute.attr,
111 &trigger_time_attribute.attr,
112 NULL, /* need to NULL terminate the list of attributes */
115 static struct spk_synth synth_decext = {
117 .version = DRV_VERSION,
118 .long_name = "Dectalk External",
119 .init = "[:pe -380]",
120 .procspeech = PROCSPEECH,
121 .clear = SYNTH_CLEAR,
127 .startup = SYNTH_START,
128 .checkval = SYNTH_CHECK,
130 .io_ops = &spk_serial_io_ops,
131 .probe = spk_serial_synth_probe,
132 .release = spk_serial_release,
133 .synth_immediate = spk_serial_synth_immediate,
134 .catch_up = do_catch_up,
135 .flush = synth_flush,
136 .is_alive = spk_synth_is_alive_restart,
137 .synth_adjust = NULL,
138 .read_buff_add = NULL,
147 .attrs = synth_attrs,
152 static void do_catch_up(struct spk_synth *synth)
155 static u_char last = '\0';
157 unsigned long jiff_max;
158 struct var_t *jiffy_delta;
159 struct var_t *delay_time;
160 int jiffy_delta_val = 0;
161 int delay_time_val = 0;
163 jiffy_delta = spk_get_var(JIFFY);
164 delay_time = spk_get_var(DELAY);
166 spin_lock_irqsave(&speakup_info.spinlock, flags);
167 jiffy_delta_val = jiffy_delta->u.n.value;
168 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
169 jiff_max = jiffies + jiffy_delta_val;
171 while (!kthread_should_stop()) {
172 spin_lock_irqsave(&speakup_info.spinlock, flags);
173 if (speakup_info.flushing) {
174 speakup_info.flushing = 0;
175 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
179 synth_buffer_skip_nonlatin1();
180 if (synth_buffer_empty()) {
181 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
184 ch = synth_buffer_peek();
185 set_current_state(TASK_INTERRUPTIBLE);
186 delay_time_val = delay_time->u.n.value;
187 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
190 if (synth_full() || !synth->io_ops->synth_out(synth, ch)) {
191 schedule_timeout(msecs_to_jiffies(delay_time_val));
194 set_current_state(TASK_RUNNING);
195 spin_lock_irqsave(&speakup_info.spinlock, flags);
197 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
200 } else if (ch == ']') {
202 } else if (ch <= SPACE) {
203 if (!in_escape && strchr(",.!?;:", last))
204 synth->io_ops->synth_out(synth, PROCSPEECH);
205 if (time_after_eq(jiffies, jiff_max)) {
207 synth->io_ops->synth_out(synth, PROCSPEECH);
208 spin_lock_irqsave(&speakup_info.spinlock,
210 jiffy_delta_val = jiffy_delta->u.n.value;
211 delay_time_val = delay_time->u.n.value;
212 spin_unlock_irqrestore(&speakup_info.spinlock,
214 schedule_timeout(msecs_to_jiffies
216 jiff_max = jiffies + jiffy_delta_val;
222 synth->io_ops->synth_out(synth, PROCSPEECH);
225 static void synth_flush(struct spk_synth *synth)
228 synth->synth_immediate(synth, "\033P;10z\033\\");
231 module_param_named(ser, synth_decext.ser, int, 0444);
232 module_param_named(start, synth_decext.startup, short, 0444);
234 MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
235 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
237 module_spk_synth(synth_decext);
239 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
240 MODULE_AUTHOR("David Borowski");
241 MODULE_DESCRIPTION("Speakup support for DECtalk External synthesizers");
242 MODULE_LICENSE("GPL");
243 MODULE_VERSION(DRV_VERSION);