blob: c1ec087dca1307f8934942ac4a8f13103ab746f3 [file] [log] [blame]
Greg Kroah-Hartman64969222018-01-11 11:08:40 +01001// SPDX-License-Identifier: GPL-2.0+
William Hubbsc6e3fd22010-10-07 13:20:02 -05002/*
3 * written by: Kirk Reiser <kirk@braille.uwo.ca>
4 * this version considerably modified by David Borowski, david575@rogers.com
5 *
6 * Copyright (C) 1998-99 Kirk Reiser.
7 * Copyright (C) 2003 David Borowski.
8 *
William Hubbsc6e3fd22010-10-07 13:20:02 -05009 * this code is specificly written as a driver for the speakup screenreview
10 * package and is not a general device driver.
11 * This driver is for the Aicom Acent PC internal synthesizer.
12 */
13
14#include <linux/jiffies.h>
15#include <linux/sched.h>
16#include <linux/timer.h>
17#include <linux/kthread.h>
18
19#include "spk_priv.h"
20#include "serialio.h"
21#include "speakup.h"
22#include "speakup_acnt.h" /* local header file for Accent values */
23
24#define DRV_VERSION "2.10"
William Hubbsc6e3fd22010-10-07 13:20:02 -050025#define PROCSPEECH '\r'
26
27static int synth_probe(struct spk_synth *synth);
Samuel Thibault1941ab12021-01-26 23:21:44 +010028static void accent_release(struct spk_synth *synth);
William Hubbsc6e3fd22010-10-07 13:20:02 -050029static const char *synth_immediate(struct spk_synth *synth, const char *buf);
30static void do_catch_up(struct spk_synth *synth);
31static void synth_flush(struct spk_synth *synth);
32
33static int synth_port_control;
34static int port_forced;
35static unsigned int synth_portlist[] = { 0x2a8, 0 };
36
37static struct var_t vars[] = {
Christopher Brannonbf4a4ba2010-10-14 19:23:46 -050038 { CAPS_START, .u.s = {"\033P8" } },
39 { CAPS_STOP, .u.s = {"\033P5" } },
40 { RATE, .u.n = {"\033R%c", 9, 0, 17, 0, 0, "0123456789abcdefgh" } },
41 { PITCH, .u.n = {"\033P%d", 5, 0, 9, 0, 0, NULL } },
42 { VOL, .u.n = {"\033A%d", 5, 0, 9, 0, 0, NULL } },
43 { TONE, .u.n = {"\033V%d", 5, 0, 9, 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/acntpc.
50 */
51static struct kobj_attribute caps_start_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130052 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050053static struct kobj_attribute caps_stop_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130054 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050055static struct kobj_attribute pitch_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130056 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050057static struct kobj_attribute rate_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130058 __ATTR(rate, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050059static struct kobj_attribute tone_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130060 __ATTR(tone, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050061static struct kobj_attribute vol_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130062 __ATTR(vol, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050063
64static struct kobj_attribute delay_time_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130065 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050066static struct kobj_attribute direct_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130067 __ATTR(direct, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050068static struct kobj_attribute full_time_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130069 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050070static struct kobj_attribute jiffy_delta_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130071 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050072static struct kobj_attribute trigger_time_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130073 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050074
75/*
76 * Create a group of attributes so that we can create and destroy them all
77 * at once.
78 */
79static struct attribute *synth_attrs[] = {
80 &caps_start_attribute.attr,
81 &caps_stop_attribute.attr,
82 &pitch_attribute.attr,
83 &rate_attribute.attr,
84 &tone_attribute.attr,
85 &vol_attribute.attr,
86 &delay_time_attribute.attr,
87 &direct_attribute.attr,
88 &full_time_attribute.attr,
89 &jiffy_delta_attribute.attr,
90 &trigger_time_attribute.attr,
91 NULL, /* need to NULL terminate the list of attributes */
92};
93
94static struct spk_synth synth_acntpc = {
95 .name = "acntpc",
96 .version = DRV_VERSION,
97 .long_name = "Accent PC",
98 .init = "\033=X \033Oi\033T2\033=M\033N1\n",
99 .procspeech = PROCSPEECH,
100 .clear = SYNTH_CLEAR,
101 .delay = 500,
102 .trigger = 50,
103 .jiffies = 50,
104 .full = 1000,
105 .startup = SYNTH_START,
106 .checkval = SYNTH_CHECK,
107 .vars = vars,
Okash Khawaja1e441592017-03-14 13:41:53 +0000108 .io_ops = &spk_serial_io_ops,
William Hubbsc6e3fd22010-10-07 13:20:02 -0500109 .probe = synth_probe,
110 .release = accent_release,
111 .synth_immediate = synth_immediate,
112 .catch_up = do_catch_up,
113 .flush = synth_flush,
114 .is_alive = spk_synth_is_alive_nop,
115 .synth_adjust = NULL,
116 .read_buff_add = NULL,
117 .get_index = NULL,
118 .indexing = {
119 .command = NULL,
120 .lowindex = 0,
121 .highindex = 0,
122 .currindex = 0,
123 },
124 .attributes = {
125 .attrs = synth_attrs,
126 .name = "acntpc",
127 },
128};
129
Christopher Brannonbf4a4ba2010-10-14 19:23:46 -0500130static inline bool synth_writable(void)
131{
132 return inb_p(synth_port_control) & SYNTH_WRITABLE;
133}
134
135static inline bool synth_full(void)
136{
137 return inb_p(speakup_info.port_tts + UART_RX) == 'F';
138}
139
William Hubbsc6e3fd22010-10-07 13:20:02 -0500140static const char *synth_immediate(struct spk_synth *synth, const char *buf)
141{
142 u_char ch;
Domagoj Trsan8e69a812014-09-09 20:04:34 +0200143
William Hubbsc6e3fd22010-10-07 13:20:02 -0500144 while ((ch = *buf)) {
145 int timeout = SPK_XMITR_TIMEOUT;
Domagoj Trsan8e69a812014-09-09 20:04:34 +0200146
William Hubbsc6e3fd22010-10-07 13:20:02 -0500147 if (ch == '\n')
148 ch = PROCSPEECH;
149 if (synth_full())
150 return buf;
151 while (synth_writable()) {
152 if (!--timeout)
153 return buf;
154 udelay(1);
155 }
156 outb_p(ch, speakup_info.port_tts);
157 buf++;
158 }
Sachin Kamatdbbe6862013-05-22 14:37:20 +0530159 return NULL;
William Hubbsc6e3fd22010-10-07 13:20:02 -0500160}
161
162static void do_catch_up(struct spk_synth *synth)
163{
164 u_char ch;
165 unsigned long flags;
166 unsigned long jiff_max;
167 int timeout;
168 int delay_time_val;
169 int jiffy_delta_val;
170 int full_time_val;
171 struct var_t *delay_time;
172 struct var_t *full_time;
173 struct var_t *jiffy_delta;
174
Samuel Thibaultca2beaf2013-01-02 02:37:40 +0100175 jiffy_delta = spk_get_var(JIFFY);
176 delay_time = spk_get_var(DELAY);
177 full_time = spk_get_var(FULL);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500178
William Hubbs995b9042013-05-13 00:02:59 -0500179 spin_lock_irqsave(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500180 jiffy_delta_val = jiffy_delta->u.n.value;
William Hubbs995b9042013-05-13 00:02:59 -0500181 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500182
183 jiff_max = jiffies + jiffy_delta_val;
184 while (!kthread_should_stop()) {
William Hubbs995b9042013-05-13 00:02:59 -0500185 spin_lock_irqsave(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500186 if (speakup_info.flushing) {
187 speakup_info.flushing = 0;
William Hubbs995b9042013-05-13 00:02:59 -0500188 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500189 synth->flush(synth);
190 continue;
191 }
Samuel Thibault89fc2ae2017-03-04 15:01:55 +0100192 synth_buffer_skip_nonlatin1();
William Hubbsc6e3fd22010-10-07 13:20:02 -0500193 if (synth_buffer_empty()) {
William Hubbs995b9042013-05-13 00:02:59 -0500194 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500195 break;
196 }
197 set_current_state(TASK_INTERRUPTIBLE);
198 full_time_val = full_time->u.n.value;
William Hubbs995b9042013-05-13 00:02:59 -0500199 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500200 if (synth_full()) {
201 schedule_timeout(msecs_to_jiffies(full_time_val));
202 continue;
203 }
204 set_current_state(TASK_RUNNING);
205 timeout = SPK_XMITR_TIMEOUT;
206 while (synth_writable()) {
207 if (!--timeout)
208 break;
209 udelay(1);
210 }
William Hubbs995b9042013-05-13 00:02:59 -0500211 spin_lock_irqsave(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500212 ch = synth_buffer_getc();
William Hubbs995b9042013-05-13 00:02:59 -0500213 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500214 if (ch == '\n')
215 ch = PROCSPEECH;
216 outb_p(ch, speakup_info.port_tts);
Ashvini Varatharaj75b76b42013-10-19 08:51:20 +0530217 if (time_after_eq(jiffies, jiff_max) && ch == SPACE) {
William Hubbsc6e3fd22010-10-07 13:20:02 -0500218 timeout = SPK_XMITR_TIMEOUT;
219 while (synth_writable()) {
220 if (!--timeout)
221 break;
222 udelay(1);
223 }
224 outb_p(PROCSPEECH, speakup_info.port_tts);
William Hubbs995b9042013-05-13 00:02:59 -0500225 spin_lock_irqsave(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500226 jiffy_delta_val = jiffy_delta->u.n.value;
227 delay_time_val = delay_time->u.n.value;
William Hubbs995b9042013-05-13 00:02:59 -0500228 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500229 schedule_timeout(msecs_to_jiffies(delay_time_val));
Varsha Raoe3bab5e2017-02-22 23:16:40 +0530230 jiff_max = jiffies + jiffy_delta_val;
William Hubbsc6e3fd22010-10-07 13:20:02 -0500231 }
232 }
233 timeout = SPK_XMITR_TIMEOUT;
234 while (synth_writable()) {
235 if (!--timeout)
236 break;
237 udelay(1);
238 }
239 outb_p(PROCSPEECH, speakup_info.port_tts);
240}
241
242static void synth_flush(struct spk_synth *synth)
243{
244 outb_p(SYNTH_CLEAR, speakup_info.port_tts);
245}
246
247static int synth_probe(struct spk_synth *synth)
248{
249 unsigned int port_val = 0;
250 int i = 0;
Domagoj Trsan8e69a812014-09-09 20:04:34 +0200251
William Hubbsc6e3fd22010-10-07 13:20:02 -0500252 pr_info("Probing for %s.\n", synth->long_name);
253 if (port_forced) {
254 speakup_info.port_tts = port_forced;
255 pr_info("probe forced to %x by kernel command line\n",
Arushi Singhal65bf4ea12017-03-21 17:12:34 +0530256 speakup_info.port_tts);
Varsha Raoe3bab5e2017-02-22 23:16:40 +0530257 if (synth_request_region(speakup_info.port_tts - 1,
Arushi Singhal65bf4ea12017-03-21 17:12:34 +0530258 SYNTH_IO_EXTENT)) {
William Hubbsc6e3fd22010-10-07 13:20:02 -0500259 pr_warn("sorry, port already reserved\n");
260 return -EBUSY;
261 }
Varsha Raoe3bab5e2017-02-22 23:16:40 +0530262 port_val = inw(speakup_info.port_tts - 1);
263 synth_port_control = speakup_info.port_tts - 1;
William Hubbsc6e3fd22010-10-07 13:20:02 -0500264 } else {
265 for (i = 0; synth_portlist[i]; i++) {
266 if (synth_request_region(synth_portlist[i],
Arushi Singhal65bf4ea12017-03-21 17:12:34 +0530267 SYNTH_IO_EXTENT)) {
Christopher Brannonbf4a4ba2010-10-14 19:23:46 -0500268 pr_warn
269 ("request_region: failed with 0x%x, %d\n",
270 synth_portlist[i], SYNTH_IO_EXTENT);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500271 continue;
272 }
273 port_val = inw(synth_portlist[i]) & 0xfffc;
274 if (port_val == 0x53fc) {
275 /* 'S' and out&input bits */
276 synth_port_control = synth_portlist[i];
Arushi Singhal205931e2017-03-21 17:12:31 +0530277 speakup_info.port_tts = synth_port_control + 1;
William Hubbsc6e3fd22010-10-07 13:20:02 -0500278 break;
279 }
280 }
281 }
282 port_val &= 0xfffc;
283 if (port_val != 0x53fc) {
284 /* 'S' and out&input bits */
285 pr_info("%s: not found\n", synth->long_name);
286 synth_release_region(synth_port_control, SYNTH_IO_EXTENT);
287 synth_port_control = 0;
288 return -ENODEV;
289 }
290 pr_info("%s: %03x-%03x, driver version %s,\n", synth->long_name,
Varsha Raoe3bab5e2017-02-22 23:16:40 +0530291 synth_port_control, synth_port_control + SYNTH_IO_EXTENT - 1,
William Hubbsc6e3fd22010-10-07 13:20:02 -0500292 synth->version);
293 synth->alive = 1;
294 return 0;
295}
296
Samuel Thibault1941ab12021-01-26 23:21:44 +0100297static void accent_release(struct spk_synth *synth)
William Hubbsc6e3fd22010-10-07 13:20:02 -0500298{
Okash Khawajaa50ef312017-03-14 13:41:54 +0000299 spk_stop_serial_interrupt();
William Hubbsc6e3fd22010-10-07 13:20:02 -0500300 if (speakup_info.port_tts)
Ioannis Valasakis8d0f5a62018-11-06 02:20:56 +0000301 synth_release_region(speakup_info.port_tts - 1,
302 SYNTH_IO_EXTENT);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500303 speakup_info.port_tts = 0;
304}
305
David Howellsdbf05cb2017-04-04 16:54:28 +0100306module_param_hw_named(port, port_forced, int, ioport, 0444);
Derek Robson73c37002017-01-28 19:35:01 +1300307module_param_named(start, synth_acntpc.startup, short, 0444);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500308
309MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
310MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
311
Vaishali Thakkarae89fac2015-03-18 23:13:10 +0530312module_spk_synth(synth_acntpc);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500313
William Hubbsc6e3fd22010-10-07 13:20:02 -0500314MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
315MODULE_AUTHOR("David Borowski");
316MODULE_DESCRIPTION("Speakup support for Accent PC synthesizer");
317MODULE_LICENSE("GPL");
318MODULE_VERSION(DRV_VERSION);
319