]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/accessibility/speakup/speakup_acntpc.c
Merge tag 'iommu-updates-v5.11' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mirror_ubuntu-hirsute-kernel.git] / drivers / accessibility / speakup / speakup_acntpc.c
CommitLineData
64969228 1// SPDX-License-Identifier: GPL-2.0+
c6e3fd22
WH
2/*
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 *
c6e3fd22
WH
9 * 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"
c6e3fd22
WH
25#define PROCSPEECH '\r'
26
27static int synth_probe(struct spk_synth *synth);
28static void accent_release(void);
29static 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[] = {
bf4a4bac
CB
38 { 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 } },
c6e3fd22
WH
45 V_LAST_VAR
46};
47
48/*
49 * These attributes will appear in /sys/accessibility/speakup/acntpc.
50 */
51static struct kobj_attribute caps_start_attribute =
73c3700e 52 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
c6e3fd22 53static struct kobj_attribute caps_stop_attribute =
73c3700e 54 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
c6e3fd22 55static struct kobj_attribute pitch_attribute =
73c3700e 56 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
c6e3fd22 57static struct kobj_attribute rate_attribute =
73c3700e 58 __ATTR(rate, 0644, spk_var_show, spk_var_store);
c6e3fd22 59static struct kobj_attribute tone_attribute =
73c3700e 60 __ATTR(tone, 0644, spk_var_show, spk_var_store);
c6e3fd22 61static struct kobj_attribute vol_attribute =
73c3700e 62 __ATTR(vol, 0644, spk_var_show, spk_var_store);
c6e3fd22
WH
63
64static struct kobj_attribute delay_time_attribute =
73c3700e 65 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
c6e3fd22 66static struct kobj_attribute direct_attribute =
73c3700e 67 __ATTR(direct, 0644, spk_var_show, spk_var_store);
c6e3fd22 68static struct kobj_attribute full_time_attribute =
73c3700e 69 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
c6e3fd22 70static struct kobj_attribute jiffy_delta_attribute =
73c3700e 71 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
c6e3fd22 72static struct kobj_attribute trigger_time_attribute =
73c3700e 73 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
c6e3fd22
WH
74
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,
1e441594 108 .io_ops = &spk_serial_io_ops,
c6e3fd22
WH
109 .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
bf4a4bac
CB
130static 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
c6e3fd22
WH
140static const char *synth_immediate(struct spk_synth *synth, const char *buf)
141{
142 u_char ch;
8e69a811 143
c6e3fd22
WH
144 while ((ch = *buf)) {
145 int timeout = SPK_XMITR_TIMEOUT;
8e69a811 146
c6e3fd22
WH
147 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 }
dbbe6863 159 return NULL;
c6e3fd22
WH
160}
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
ca2beaf8
ST
175 jiffy_delta = spk_get_var(JIFFY);
176 delay_time = spk_get_var(DELAY);
177 full_time = spk_get_var(FULL);
c6e3fd22 178
995b9040 179 spin_lock_irqsave(&speakup_info.spinlock, flags);
c6e3fd22 180 jiffy_delta_val = jiffy_delta->u.n.value;
995b9040 181 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
c6e3fd22
WH
182
183 jiff_max = jiffies + jiffy_delta_val;
184 while (!kthread_should_stop()) {
995b9040 185 spin_lock_irqsave(&speakup_info.spinlock, flags);
c6e3fd22
WH
186 if (speakup_info.flushing) {
187 speakup_info.flushing = 0;
995b9040 188 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
c6e3fd22
WH
189 synth->flush(synth);
190 continue;
191 }
89fc2ae8 192 synth_buffer_skip_nonlatin1();
c6e3fd22 193 if (synth_buffer_empty()) {
995b9040 194 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
c6e3fd22
WH
195 break;
196 }
197 set_current_state(TASK_INTERRUPTIBLE);
198 full_time_val = full_time->u.n.value;
995b9040 199 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
c6e3fd22
WH
200 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 }
995b9040 211 spin_lock_irqsave(&speakup_info.spinlock, flags);
c6e3fd22 212 ch = synth_buffer_getc();
995b9040 213 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
c6e3fd22
WH
214 if (ch == '\n')
215 ch = PROCSPEECH;
216 outb_p(ch, speakup_info.port_tts);
75b76b47 217 if (time_after_eq(jiffies, jiff_max) && ch == SPACE) {
c6e3fd22
WH
218 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);
995b9040 225 spin_lock_irqsave(&speakup_info.spinlock, flags);
c6e3fd22
WH
226 jiffy_delta_val = jiffy_delta->u.n.value;
227 delay_time_val = delay_time->u.n.value;
995b9040 228 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
c6e3fd22 229 schedule_timeout(msecs_to_jiffies(delay_time_val));
e3bab5eb 230 jiff_max = jiffies + jiffy_delta_val;
c6e3fd22
WH
231 }
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;
8e69a811 251
c6e3fd22
WH
252 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",
65bf4ea1 256 speakup_info.port_tts);
e3bab5eb 257 if (synth_request_region(speakup_info.port_tts - 1,
65bf4ea1 258 SYNTH_IO_EXTENT)) {
c6e3fd22
WH
259 pr_warn("sorry, port already reserved\n");
260 return -EBUSY;
261 }
e3bab5eb
VR
262 port_val = inw(speakup_info.port_tts - 1);
263 synth_port_control = speakup_info.port_tts - 1;
c6e3fd22
WH
264 } else {
265 for (i = 0; synth_portlist[i]; i++) {
266 if (synth_request_region(synth_portlist[i],
65bf4ea1 267 SYNTH_IO_EXTENT)) {
bf4a4bac
CB
268 pr_warn
269 ("request_region: failed with 0x%x, %d\n",
270 synth_portlist[i], SYNTH_IO_EXTENT);
c6e3fd22
WH
271 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];
205931ea 277 speakup_info.port_tts = synth_port_control + 1;
c6e3fd22
WH
278 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,
e3bab5eb 291 synth_port_control, synth_port_control + SYNTH_IO_EXTENT - 1,
c6e3fd22
WH
292 synth->version);
293 synth->alive = 1;
294 return 0;
295}
296
297static void accent_release(void)
298{
a50ef316 299 spk_stop_serial_interrupt();
c6e3fd22 300 if (speakup_info.port_tts)
8d0f5a65
IV
301 synth_release_region(speakup_info.port_tts - 1,
302 SYNTH_IO_EXTENT);
c6e3fd22
WH
303 speakup_info.port_tts = 0;
304}
305
dbf05cb0 306module_param_hw_named(port, port_forced, int, ioport, 0444);
73c3700e 307module_param_named(start, synth_acntpc.startup, short, 0444);
c6e3fd22
WH
308
309MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
310MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
311
ae89facc 312module_spk_synth(synth_acntpc);
c6e3fd22 313
c6e3fd22
WH
314MODULE_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