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 * this code is specificly written as a driver for the speakup screenreview
19 * package and is 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>
25 #include <linux/serial_reg.h> /* for UART_MCR* constants */
30 #define DRV_VERSION "2.21"
31 #define SYNTH_CLEAR 0x18
32 #define PROCSPEECH '\r'
34 static void do_catch_up(struct spk_synth *synth);
36 static struct var_t vars[] = {
37 { CAPS_START, .u.s = {"cap, " } },
38 { CAPS_STOP, .u.s = {"" } },
39 { RATE, .u.n = {"@W%d", 6, 1, 9, 0, 0, NULL } },
40 { PITCH, .u.n = {"@F%x", 10, 0, 15, 0, 0, NULL } },
41 { VOL, .u.n = {"@A%x", 10, 0, 15, 0, 0, NULL } },
42 { VOICE, .u.n = {"@V%d", 1, 1, 6, 0, 0, NULL } },
43 { LANG, .u.n = {"@=%d,", 1, 1, 4, 0, 0, NULL } },
44 { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
49 * These attributes will appear in /sys/accessibility/speakup/apollo.
51 static struct kobj_attribute caps_start_attribute =
52 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
53 static struct kobj_attribute caps_stop_attribute =
54 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
55 static struct kobj_attribute lang_attribute =
56 __ATTR(lang, 0644, spk_var_show, spk_var_store);
57 static struct kobj_attribute pitch_attribute =
58 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
59 static struct kobj_attribute rate_attribute =
60 __ATTR(rate, 0644, spk_var_show, spk_var_store);
61 static struct kobj_attribute voice_attribute =
62 __ATTR(voice, 0644, spk_var_show, spk_var_store);
63 static struct kobj_attribute vol_attribute =
64 __ATTR(vol, 0644, spk_var_show, spk_var_store);
66 static struct kobj_attribute delay_time_attribute =
67 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
68 static struct kobj_attribute direct_attribute =
69 __ATTR(direct, 0644, spk_var_show, spk_var_store);
70 static struct kobj_attribute full_time_attribute =
71 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
72 static struct kobj_attribute jiffy_delta_attribute =
73 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
74 static struct kobj_attribute trigger_time_attribute =
75 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
78 * Create a group of attributes so that we can create and destroy them all
81 static struct attribute *synth_attrs[] = {
82 &caps_start_attribute.attr,
83 &caps_stop_attribute.attr,
85 &pitch_attribute.attr,
87 &voice_attribute.attr,
89 &delay_time_attribute.attr,
90 &direct_attribute.attr,
91 &full_time_attribute.attr,
92 &jiffy_delta_attribute.attr,
93 &trigger_time_attribute.attr,
94 NULL, /* need to NULL terminate the list of attributes */
97 static struct spk_synth synth_apollo = {
99 .version = DRV_VERSION,
100 .long_name = "Apollo",
101 .init = "@R3@D0@K1\r",
102 .procspeech = PROCSPEECH,
103 .clear = SYNTH_CLEAR,
108 .dev_name = SYNTH_DEFAULT_DEV,
109 .startup = SYNTH_START,
110 .checkval = SYNTH_CHECK,
112 .io_ops = &spk_ttyio_ops,
113 .probe = spk_ttyio_synth_probe,
114 .release = spk_ttyio_release,
115 .synth_immediate = spk_ttyio_synth_immediate,
116 .catch_up = do_catch_up,
117 .flush = spk_synth_flush,
118 .is_alive = spk_synth_is_alive_restart,
119 .synth_adjust = NULL,
120 .read_buff_add = NULL,
129 .attrs = synth_attrs,
134 static void do_catch_up(struct spk_synth *synth)
138 unsigned long jiff_max;
139 struct var_t *jiffy_delta;
140 struct var_t *delay_time;
141 struct var_t *full_time;
142 int full_time_val = 0;
143 int delay_time_val = 0;
144 int jiffy_delta_val = 0;
146 jiffy_delta = spk_get_var(JIFFY);
147 delay_time = spk_get_var(DELAY);
148 full_time = spk_get_var(FULL);
149 spin_lock_irqsave(&speakup_info.spinlock, flags);
150 jiffy_delta_val = jiffy_delta->u.n.value;
151 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
152 jiff_max = jiffies + jiffy_delta_val;
154 while (!kthread_should_stop()) {
155 spin_lock_irqsave(&speakup_info.spinlock, flags);
156 jiffy_delta_val = jiffy_delta->u.n.value;
157 full_time_val = full_time->u.n.value;
158 delay_time_val = delay_time->u.n.value;
159 if (speakup_info.flushing) {
160 speakup_info.flushing = 0;
161 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
165 synth_buffer_skip_nonlatin1();
166 if (synth_buffer_empty()) {
167 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
170 ch = synth_buffer_peek();
171 set_current_state(TASK_INTERRUPTIBLE);
172 full_time_val = full_time->u.n.value;
173 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
174 if (!synth->io_ops->synth_out(synth, ch)) {
175 synth->io_ops->tiocmset(0, UART_MCR_RTS);
176 synth->io_ops->tiocmset(UART_MCR_RTS, 0);
177 schedule_timeout(msecs_to_jiffies(full_time_val));
180 if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) {
181 spin_lock_irqsave(&speakup_info.spinlock, flags);
182 jiffy_delta_val = jiffy_delta->u.n.value;
183 full_time_val = full_time->u.n.value;
184 delay_time_val = delay_time->u.n.value;
185 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
186 if (synth->io_ops->synth_out(synth, synth->procspeech))
187 schedule_timeout(msecs_to_jiffies
190 schedule_timeout(msecs_to_jiffies
192 jiff_max = jiffies + jiffy_delta_val;
194 set_current_state(TASK_RUNNING);
195 spin_lock_irqsave(&speakup_info.spinlock, flags);
197 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
199 synth->io_ops->synth_out(synth, PROCSPEECH);
202 module_param_named(ser, synth_apollo.ser, int, 0444);
203 module_param_named(dev, synth_apollo.dev_name, charp, S_IRUGO);
204 module_param_named(start, synth_apollo.startup, short, 0444);
206 MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
207 MODULE_PARM_DESC(dev, "Set the device e.g. ttyUSB0, for the synthesizer.");
208 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
210 module_spk_synth(synth_apollo);
212 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
213 MODULE_AUTHOR("David Borowski");
214 MODULE_DESCRIPTION("Speakup support for Apollo II synthesizer");
215 MODULE_LICENSE("GPL");
216 MODULE_VERSION(DRV_VERSION);