blob: 38c8c2221e4e1c47022d14d6437cf14d3c8e054e [file] [log] [blame]
William Hubbsc6e3fd22010-10-07 13:20:02 -05001/*
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[] = {
Christopher Brannonf4931442010-10-14 19:23:48 -050041 { 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 } },
William Hubbsc6e3fd22010-10-07 13:20:02 -050049 V_LAST_VAR
50};
51
52/*
53 * These attributes will appear in /sys/accessibility/speakup/apollo.
54 */
55static struct kobj_attribute caps_start_attribute =
Rusty Russell22c9bca2014-04-01 13:30:05 +103056 __ATTR(caps_start, S_IWUGO|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050057static struct kobj_attribute caps_stop_attribute =
Rusty Russell22c9bca2014-04-01 13:30:05 +103058 __ATTR(caps_stop, S_IWUGO|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050059static struct kobj_attribute lang_attribute =
Rusty Russell22c9bca2014-04-01 13:30:05 +103060 __ATTR(lang, S_IWUGO|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050061static struct kobj_attribute pitch_attribute =
Rusty Russell22c9bca2014-04-01 13:30:05 +103062 __ATTR(pitch, S_IWUGO|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050063static struct kobj_attribute rate_attribute =
Rusty Russell22c9bca2014-04-01 13:30:05 +103064 __ATTR(rate, S_IWUGO|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050065static struct kobj_attribute voice_attribute =
Rusty Russell22c9bca2014-04-01 13:30:05 +103066 __ATTR(voice, S_IWUGO|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050067static struct kobj_attribute vol_attribute =
Rusty Russell22c9bca2014-04-01 13:30:05 +103068 __ATTR(vol, S_IWUGO|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050069
70static struct kobj_attribute delay_time_attribute =
Rusty Russell22c9bca2014-04-01 13:30:05 +103071 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050072static struct kobj_attribute direct_attribute =
Rusty Russell22c9bca2014-04-01 13:30:05 +103073 __ATTR(direct, S_IWUGO|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050074static struct kobj_attribute full_time_attribute =
Rusty Russell22c9bca2014-04-01 13:30:05 +103075 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050076static struct kobj_attribute jiffy_delta_attribute =
Rusty Russell22c9bca2014-04-01 13:30:05 +103077 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050078static struct kobj_attribute trigger_time_attribute =
Rusty Russell22c9bca2014-04-01 13:30:05 +103079 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050080
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,
Samuel Thibaultca2beaf2013-01-02 02:37:40 +0100115 .probe = spk_serial_synth_probe,
William Hubbsc6e3fd22010-10-07 13:20:02 -0500116 .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
Samuel Thibaultca2beaf2013-01-02 02:37:40 +0100148 jiffy_delta = spk_get_var(JIFFY);
149 delay_time = spk_get_var(DELAY);
150 full_time = spk_get_var(FULL);
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500151 spin_lock_irqsave(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500152 jiffy_delta_val = jiffy_delta->u.n.value;
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500153 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500154 jiff_max = jiffies + jiffy_delta_val;
155
156 while (!kthread_should_stop()) {
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500157 spin_lock_irqsave(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500158 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;
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500163 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500164 synth->flush(synth);
165 continue;
166 }
167 if (synth_buffer_empty()) {
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500168 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500169 break;
170 }
171 ch = synth_buffer_peek();
172 set_current_state(TASK_INTERRUPTIBLE);
173 full_time_val = full_time->u.n.value;
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500174 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500175 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 }
Ashvini Varatharajc45a9a92013-10-19 09:00:59 +0530182 if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) {
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500183 spin_lock_irqsave(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500184 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;
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500187 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500188 if (spk_serial_out(synth->procspeech))
Christopher Brannonf4931442010-10-14 19:23:48 -0500189 schedule_timeout(msecs_to_jiffies
190 (delay_time_val));
William Hubbsc6e3fd22010-10-07 13:20:02 -0500191 else
Christopher Brannonf4931442010-10-14 19:23:48 -0500192 schedule_timeout(msecs_to_jiffies
193 (full_time_val));
William Hubbsc6e3fd22010-10-07 13:20:02 -0500194 jiff_max = jiffies + jiffy_delta_val;
195 }
196 set_current_state(TASK_RUNNING);
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500197 spin_lock_irqsave(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500198 synth_buffer_getc();
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500199 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500200 }
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