blob: 3cbc8a7ad1ef38941711820bde70c160ffaaec92 [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 *
William Hubbsc6e3fd22010-10-07 13:20:02 -050018 * this code is specificly written as a driver for the speakup screenreview
19 * package and is not a general device driver.
20 */
21#include <linux/jiffies.h>
22#include <linux/sched.h>
23#include <linux/timer.h>
24#include <linux/kthread.h>
25
26#include "spk_priv.h"
27#include "serialio.h"
28#include "speakup.h"
29
30#define DRV_VERSION "2.21"
31#define SYNTH_CLEAR 0x18
32#define PROCSPEECH '\r'
33
34static void do_catch_up(struct spk_synth *synth);
35
36static struct var_t vars[] = {
Christopher Brannonf4931442010-10-14 19:23:48 -050037 { 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 } },
William Hubbsc6e3fd22010-10-07 13:20:02 -050045 V_LAST_VAR
46};
47
48/*
49 * These attributes will appear in /sys/accessibility/speakup/apollo.
50 */
51static struct kobj_attribute caps_start_attribute =
Rusty Russelld901aaa2014-04-24 13:57:49 +093052 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050053static struct kobj_attribute caps_stop_attribute =
Rusty Russelld901aaa2014-04-24 13:57:49 +093054 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050055static struct kobj_attribute lang_attribute =
Rusty Russelld901aaa2014-04-24 13:57:49 +093056 __ATTR(lang, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050057static struct kobj_attribute pitch_attribute =
Rusty Russelld901aaa2014-04-24 13:57:49 +093058 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050059static struct kobj_attribute rate_attribute =
Rusty Russelld901aaa2014-04-24 13:57:49 +093060 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050061static struct kobj_attribute voice_attribute =
Rusty Russelld901aaa2014-04-24 13:57:49 +093062 __ATTR(voice, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050063static struct kobj_attribute vol_attribute =
Rusty Russelld901aaa2014-04-24 13:57:49 +093064 __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050065
66static struct kobj_attribute delay_time_attribute =
Rusty Russell22c9bca2014-04-01 13:30:05 +103067 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050068static struct kobj_attribute direct_attribute =
Rusty Russelld901aaa2014-04-24 13:57:49 +093069 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050070static struct kobj_attribute full_time_attribute =
Rusty Russell22c9bca2014-04-01 13:30:05 +103071 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050072static struct kobj_attribute jiffy_delta_attribute =
Rusty Russell22c9bca2014-04-01 13:30:05 +103073 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050074static struct kobj_attribute trigger_time_attribute =
Rusty Russell22c9bca2014-04-01 13:30:05 +103075 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050076
77/*
78 * Create a group of attributes so that we can create and destroy them all
79 * at once.
80 */
81static struct attribute *synth_attrs[] = {
82 &caps_start_attribute.attr,
83 &caps_stop_attribute.attr,
84 &lang_attribute.attr,
85 &pitch_attribute.attr,
86 &rate_attribute.attr,
87 &voice_attribute.attr,
88 &vol_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 */
95};
96
97static struct spk_synth synth_apollo = {
98 .name = "apollo",
99 .version = DRV_VERSION,
100 .long_name = "Apollo",
101 .init = "@R3@D0@K1\r",
102 .procspeech = PROCSPEECH,
103 .clear = SYNTH_CLEAR,
104 .delay = 500,
105 .trigger = 50,
106 .jiffies = 50,
107 .full = 40000,
108 .startup = SYNTH_START,
109 .checkval = SYNTH_CHECK,
110 .vars = vars,
Samuel Thibaultca2beaf2013-01-02 02:37:40 +0100111 .probe = spk_serial_synth_probe,
William Hubbsc6e3fd22010-10-07 13:20:02 -0500112 .release = spk_serial_release,
113 .synth_immediate = spk_synth_immediate,
114 .catch_up = do_catch_up,
115 .flush = spk_synth_flush,
116 .is_alive = spk_synth_is_alive_restart,
117 .synth_adjust = NULL,
118 .read_buff_add = NULL,
119 .get_index = NULL,
120 .indexing = {
121 .command = NULL,
122 .lowindex = 0,
123 .highindex = 0,
124 .currindex = 0,
125 },
126 .attributes = {
127 .attrs = synth_attrs,
128 .name = "apollo",
129 },
130};
131
132static void do_catch_up(struct spk_synth *synth)
133{
134 u_char ch;
135 unsigned long flags;
136 unsigned long jiff_max;
137 struct var_t *jiffy_delta;
138 struct var_t *delay_time;
139 struct var_t *full_time;
140 int full_time_val = 0;
141 int delay_time_val = 0;
142 int jiffy_delta_val = 0;
143
Samuel Thibaultca2beaf2013-01-02 02:37:40 +0100144 jiffy_delta = spk_get_var(JIFFY);
145 delay_time = spk_get_var(DELAY);
146 full_time = spk_get_var(FULL);
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500147 spin_lock_irqsave(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500148 jiffy_delta_val = jiffy_delta->u.n.value;
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500149 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500150 jiff_max = jiffies + jiffy_delta_val;
151
152 while (!kthread_should_stop()) {
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500153 spin_lock_irqsave(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500154 jiffy_delta_val = jiffy_delta->u.n.value;
155 full_time_val = full_time->u.n.value;
156 delay_time_val = delay_time->u.n.value;
157 if (speakup_info.flushing) {
158 speakup_info.flushing = 0;
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500159 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500160 synth->flush(synth);
161 continue;
162 }
163 if (synth_buffer_empty()) {
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500164 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500165 break;
166 }
167 ch = synth_buffer_peek();
168 set_current_state(TASK_INTERRUPTIBLE);
169 full_time_val = full_time->u.n.value;
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500170 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500171 if (!spk_serial_out(ch)) {
172 outb(UART_MCR_DTR, speakup_info.port_tts + UART_MCR);
173 outb(UART_MCR_DTR | UART_MCR_RTS,
174 speakup_info.port_tts + UART_MCR);
175 schedule_timeout(msecs_to_jiffies(full_time_val));
176 continue;
177 }
Ashvini Varatharajc45a9a92013-10-19 09:00:59 +0530178 if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) {
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500179 spin_lock_irqsave(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500180 jiffy_delta_val = jiffy_delta->u.n.value;
181 full_time_val = full_time->u.n.value;
182 delay_time_val = delay_time->u.n.value;
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500183 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500184 if (spk_serial_out(synth->procspeech))
Christopher Brannonf4931442010-10-14 19:23:48 -0500185 schedule_timeout(msecs_to_jiffies
186 (delay_time_val));
William Hubbsc6e3fd22010-10-07 13:20:02 -0500187 else
Christopher Brannonf4931442010-10-14 19:23:48 -0500188 schedule_timeout(msecs_to_jiffies
189 (full_time_val));
William Hubbsc6e3fd22010-10-07 13:20:02 -0500190 jiff_max = jiffies + jiffy_delta_val;
191 }
192 set_current_state(TASK_RUNNING);
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500193 spin_lock_irqsave(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500194 synth_buffer_getc();
William Hubbs6ca4dbe2013-05-13 00:03:00 -0500195 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500196 }
197 spk_serial_out(PROCSPEECH);
198}
199
200module_param_named(ser, synth_apollo.ser, int, S_IRUGO);
201module_param_named(start, synth_apollo.startup, short, S_IRUGO);
202
203MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
204MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
205
Vaishali Thakkarae89fac2015-03-18 23:13:10 +0530206module_spk_synth(synth_apollo);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500207
William Hubbsc6e3fd22010-10-07 13:20:02 -0500208MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
209MODULE_AUTHOR("David Borowski");
210MODULE_DESCRIPTION("Speakup support for Apollo II synthesizer");
211MODULE_LICENSE("GPL");
212MODULE_VERSION(DRV_VERSION);
213