blob: a27e6bbf05da308b80b125ded1d2b1f1bf8e9a49 [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 *
Tom Rix0b4efcb2022-03-29 12:54:01 -07009 * this code is specifically written as a driver for the speakup screenreview
William Hubbsc6e3fd22010-10-07 13:20:02 -050010 * 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
Osama Muhammadcf0b4652022-11-10 02:51:07 +050037enum default_vars_id {
38 CAPS_START_ID = 0, CAPS_STOP_ID,
39 RATE_ID, PITCH_ID,
40 VOL_ID, TONE_ID,
41 DIRECT_ID, V_LAST_VAR_ID,
42 NB_ID
43};
44
45
46static struct var_t vars[NB_ID] = {
47 [CAPS_START_ID] = { CAPS_START, .u.s = {"\033P8" } },
48 [CAPS_STOP_ID] = { CAPS_STOP, .u.s = {"\033P5" } },
49 [RATE_ID] = { RATE, .u.n = {"\033R%c", 9, 0, 17, 0, 0, "0123456789abcdefgh" } },
50 [PITCH_ID] = { PITCH, .u.n = {"\033P%d", 5, 0, 9, 0, 0, NULL } },
51 [VOL_ID] = { VOL, .u.n = {"\033A%d", 5, 0, 9, 0, 0, NULL } },
52 [TONE_ID] = { TONE, .u.n = {"\033V%d", 5, 0, 9, 0, 0, NULL } },
53 [DIRECT_ID] = { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
William Hubbsc6e3fd22010-10-07 13:20:02 -050054 V_LAST_VAR
55};
56
57/*
58 * These attributes will appear in /sys/accessibility/speakup/acntpc.
59 */
60static struct kobj_attribute caps_start_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130061 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050062static struct kobj_attribute caps_stop_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130063 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050064static struct kobj_attribute pitch_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130065 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050066static struct kobj_attribute rate_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130067 __ATTR(rate, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050068static struct kobj_attribute tone_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130069 __ATTR(tone, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050070static struct kobj_attribute vol_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130071 __ATTR(vol, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050072
73static struct kobj_attribute delay_time_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130074 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050075static struct kobj_attribute direct_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130076 __ATTR(direct, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050077static struct kobj_attribute full_time_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130078 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050079static struct kobj_attribute jiffy_delta_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130080 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050081static struct kobj_attribute trigger_time_attribute =
Derek Robson73c37002017-01-28 19:35:01 +130082 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
William Hubbsc6e3fd22010-10-07 13:20:02 -050083
84/*
85 * Create a group of attributes so that we can create and destroy them all
86 * at once.
87 */
88static struct attribute *synth_attrs[] = {
89 &caps_start_attribute.attr,
90 &caps_stop_attribute.attr,
91 &pitch_attribute.attr,
92 &rate_attribute.attr,
93 &tone_attribute.attr,
94 &vol_attribute.attr,
95 &delay_time_attribute.attr,
96 &direct_attribute.attr,
97 &full_time_attribute.attr,
98 &jiffy_delta_attribute.attr,
99 &trigger_time_attribute.attr,
100 NULL, /* need to NULL terminate the list of attributes */
101};
102
103static struct spk_synth synth_acntpc = {
104 .name = "acntpc",
105 .version = DRV_VERSION,
106 .long_name = "Accent PC",
107 .init = "\033=X \033Oi\033T2\033=M\033N1\n",
108 .procspeech = PROCSPEECH,
109 .clear = SYNTH_CLEAR,
110 .delay = 500,
111 .trigger = 50,
112 .jiffies = 50,
113 .full = 1000,
114 .startup = SYNTH_START,
115 .checkval = SYNTH_CHECK,
116 .vars = vars,
Okash Khawaja1e441592017-03-14 13:41:53 +0000117 .io_ops = &spk_serial_io_ops,
William Hubbsc6e3fd22010-10-07 13:20:02 -0500118 .probe = synth_probe,
119 .release = accent_release,
120 .synth_immediate = synth_immediate,
121 .catch_up = do_catch_up,
122 .flush = synth_flush,
123 .is_alive = spk_synth_is_alive_nop,
124 .synth_adjust = NULL,
125 .read_buff_add = NULL,
126 .get_index = NULL,
127 .indexing = {
128 .command = NULL,
129 .lowindex = 0,
130 .highindex = 0,
131 .currindex = 0,
132 },
133 .attributes = {
134 .attrs = synth_attrs,
135 .name = "acntpc",
136 },
137};
138
Christopher Brannonbf4a4ba2010-10-14 19:23:46 -0500139static inline bool synth_writable(void)
140{
141 return inb_p(synth_port_control) & SYNTH_WRITABLE;
142}
143
144static inline bool synth_full(void)
145{
146 return inb_p(speakup_info.port_tts + UART_RX) == 'F';
147}
148
William Hubbsc6e3fd22010-10-07 13:20:02 -0500149static const char *synth_immediate(struct spk_synth *synth, const char *buf)
150{
151 u_char ch;
Domagoj Trsan8e69a812014-09-09 20:04:34 +0200152
William Hubbsc6e3fd22010-10-07 13:20:02 -0500153 while ((ch = *buf)) {
154 int timeout = SPK_XMITR_TIMEOUT;
Domagoj Trsan8e69a812014-09-09 20:04:34 +0200155
William Hubbsc6e3fd22010-10-07 13:20:02 -0500156 if (ch == '\n')
157 ch = PROCSPEECH;
158 if (synth_full())
159 return buf;
160 while (synth_writable()) {
161 if (!--timeout)
162 return buf;
163 udelay(1);
164 }
165 outb_p(ch, speakup_info.port_tts);
166 buf++;
167 }
Sachin Kamatdbbe6862013-05-22 14:37:20 +0530168 return NULL;
William Hubbsc6e3fd22010-10-07 13:20:02 -0500169}
170
171static void do_catch_up(struct spk_synth *synth)
172{
173 u_char ch;
174 unsigned long flags;
175 unsigned long jiff_max;
176 int timeout;
177 int delay_time_val;
178 int jiffy_delta_val;
179 int full_time_val;
180 struct var_t *delay_time;
181 struct var_t *full_time;
182 struct var_t *jiffy_delta;
183
Samuel Thibaultca2beaf2013-01-02 02:37:40 +0100184 jiffy_delta = spk_get_var(JIFFY);
185 delay_time = spk_get_var(DELAY);
186 full_time = spk_get_var(FULL);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500187
William Hubbs995b9042013-05-13 00:02:59 -0500188 spin_lock_irqsave(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500189 jiffy_delta_val = jiffy_delta->u.n.value;
William Hubbs995b9042013-05-13 00:02:59 -0500190 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500191
192 jiff_max = jiffies + jiffy_delta_val;
193 while (!kthread_should_stop()) {
William Hubbs995b9042013-05-13 00:02:59 -0500194 spin_lock_irqsave(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500195 if (speakup_info.flushing) {
196 speakup_info.flushing = 0;
William Hubbs995b9042013-05-13 00:02:59 -0500197 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500198 synth->flush(synth);
199 continue;
200 }
Samuel Thibault89fc2ae2017-03-04 15:01:55 +0100201 synth_buffer_skip_nonlatin1();
William Hubbsc6e3fd22010-10-07 13:20:02 -0500202 if (synth_buffer_empty()) {
William Hubbs995b9042013-05-13 00:02:59 -0500203 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500204 break;
205 }
206 set_current_state(TASK_INTERRUPTIBLE);
207 full_time_val = full_time->u.n.value;
William Hubbs995b9042013-05-13 00:02:59 -0500208 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500209 if (synth_full()) {
210 schedule_timeout(msecs_to_jiffies(full_time_val));
211 continue;
212 }
213 set_current_state(TASK_RUNNING);
214 timeout = SPK_XMITR_TIMEOUT;
215 while (synth_writable()) {
216 if (!--timeout)
217 break;
218 udelay(1);
219 }
William Hubbs995b9042013-05-13 00:02:59 -0500220 spin_lock_irqsave(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500221 ch = synth_buffer_getc();
William Hubbs995b9042013-05-13 00:02:59 -0500222 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500223 if (ch == '\n')
224 ch = PROCSPEECH;
225 outb_p(ch, speakup_info.port_tts);
Ashvini Varatharaj75b76b42013-10-19 08:51:20 +0530226 if (time_after_eq(jiffies, jiff_max) && ch == SPACE) {
William Hubbsc6e3fd22010-10-07 13:20:02 -0500227 timeout = SPK_XMITR_TIMEOUT;
228 while (synth_writable()) {
229 if (!--timeout)
230 break;
231 udelay(1);
232 }
233 outb_p(PROCSPEECH, speakup_info.port_tts);
William Hubbs995b9042013-05-13 00:02:59 -0500234 spin_lock_irqsave(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500235 jiffy_delta_val = jiffy_delta->u.n.value;
236 delay_time_val = delay_time->u.n.value;
William Hubbs995b9042013-05-13 00:02:59 -0500237 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500238 schedule_timeout(msecs_to_jiffies(delay_time_val));
Varsha Raoe3bab5e2017-02-22 23:16:40 +0530239 jiff_max = jiffies + jiffy_delta_val;
William Hubbsc6e3fd22010-10-07 13:20:02 -0500240 }
241 }
242 timeout = SPK_XMITR_TIMEOUT;
243 while (synth_writable()) {
244 if (!--timeout)
245 break;
246 udelay(1);
247 }
248 outb_p(PROCSPEECH, speakup_info.port_tts);
249}
250
251static void synth_flush(struct spk_synth *synth)
252{
253 outb_p(SYNTH_CLEAR, speakup_info.port_tts);
254}
255
256static int synth_probe(struct spk_synth *synth)
257{
258 unsigned int port_val = 0;
Colin Ian King1f8ff522021-11-10 23:33:42 +0000259 int i;
Domagoj Trsan8e69a812014-09-09 20:04:34 +0200260
William Hubbsc6e3fd22010-10-07 13:20:02 -0500261 pr_info("Probing for %s.\n", synth->long_name);
262 if (port_forced) {
263 speakup_info.port_tts = port_forced;
264 pr_info("probe forced to %x by kernel command line\n",
Arushi Singhal65bf4ea12017-03-21 17:12:34 +0530265 speakup_info.port_tts);
Varsha Raoe3bab5e2017-02-22 23:16:40 +0530266 if (synth_request_region(speakup_info.port_tts - 1,
Arushi Singhal65bf4ea12017-03-21 17:12:34 +0530267 SYNTH_IO_EXTENT)) {
William Hubbsc6e3fd22010-10-07 13:20:02 -0500268 pr_warn("sorry, port already reserved\n");
269 return -EBUSY;
270 }
Varsha Raoe3bab5e2017-02-22 23:16:40 +0530271 port_val = inw(speakup_info.port_tts - 1);
272 synth_port_control = speakup_info.port_tts - 1;
William Hubbsc6e3fd22010-10-07 13:20:02 -0500273 } else {
274 for (i = 0; synth_portlist[i]; i++) {
275 if (synth_request_region(synth_portlist[i],
Arushi Singhal65bf4ea12017-03-21 17:12:34 +0530276 SYNTH_IO_EXTENT)) {
Christopher Brannonbf4a4ba2010-10-14 19:23:46 -0500277 pr_warn
278 ("request_region: failed with 0x%x, %d\n",
279 synth_portlist[i], SYNTH_IO_EXTENT);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500280 continue;
281 }
282 port_val = inw(synth_portlist[i]) & 0xfffc;
283 if (port_val == 0x53fc) {
284 /* 'S' and out&input bits */
285 synth_port_control = synth_portlist[i];
Arushi Singhal205931e2017-03-21 17:12:31 +0530286 speakup_info.port_tts = synth_port_control + 1;
William Hubbsc6e3fd22010-10-07 13:20:02 -0500287 break;
288 }
289 }
290 }
291 port_val &= 0xfffc;
292 if (port_val != 0x53fc) {
293 /* 'S' and out&input bits */
294 pr_info("%s: not found\n", synth->long_name);
295 synth_release_region(synth_port_control, SYNTH_IO_EXTENT);
296 synth_port_control = 0;
297 return -ENODEV;
298 }
299 pr_info("%s: %03x-%03x, driver version %s,\n", synth->long_name,
Varsha Raoe3bab5e2017-02-22 23:16:40 +0530300 synth_port_control, synth_port_control + SYNTH_IO_EXTENT - 1,
William Hubbsc6e3fd22010-10-07 13:20:02 -0500301 synth->version);
302 synth->alive = 1;
303 return 0;
304}
305
Samuel Thibault1941ab12021-01-26 23:21:44 +0100306static void accent_release(struct spk_synth *synth)
William Hubbsc6e3fd22010-10-07 13:20:02 -0500307{
Okash Khawajaa50ef312017-03-14 13:41:54 +0000308 spk_stop_serial_interrupt();
William Hubbsc6e3fd22010-10-07 13:20:02 -0500309 if (speakup_info.port_tts)
Ioannis Valasakis8d0f5a62018-11-06 02:20:56 +0000310 synth_release_region(speakup_info.port_tts - 1,
311 SYNTH_IO_EXTENT);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500312 speakup_info.port_tts = 0;
313}
314
David Howellsdbf05cb2017-04-04 16:54:28 +0100315module_param_hw_named(port, port_forced, int, ioport, 0444);
Derek Robson73c37002017-01-28 19:35:01 +1300316module_param_named(start, synth_acntpc.startup, short, 0444);
Osama Muhammadcf0b4652022-11-10 02:51:07 +0500317module_param_named(rate, vars[RATE_ID].u.n.default_val, int, 0444);
318module_param_named(pitch, vars[PITCH_ID].u.n.default_val, int, 0444);
319module_param_named(vol, vars[VOL_ID].u.n.default_val, int, 0444);
320module_param_named(tone, vars[TONE_ID].u.n.default_val, int, 0444);
321module_param_named(direct, vars[DIRECT_ID].u.n.default_val, int, 0444);
322
323
William Hubbsc6e3fd22010-10-07 13:20:02 -0500324
325MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
326MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
Osama Muhammadcf0b4652022-11-10 02:51:07 +0500327MODULE_PARM_DESC(rate, "Set the rate variable on load.");
328MODULE_PARM_DESC(pitch, "Set the pitch variable on load.");
329MODULE_PARM_DESC(vol, "Set the vol variable on load.");
330MODULE_PARM_DESC(tone, "Set the tone variable on load.");
331MODULE_PARM_DESC(direct, "Set the direct variable on load.");
332
William Hubbsc6e3fd22010-10-07 13:20:02 -0500333
Vaishali Thakkarae89fac2015-03-18 23:13:10 +0530334module_spk_synth(synth_acntpc);
William Hubbsc6e3fd22010-10-07 13:20:02 -0500335
William Hubbsc6e3fd22010-10-07 13:20:02 -0500336MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
337MODULE_AUTHOR("David Borowski");
338MODULE_DESCRIPTION("Speakup support for Accent PC synthesizer");
339MODULE_LICENSE("GPL");
340MODULE_VERSION(DRV_VERSION);
341