]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/staging/speakup/speakup_dtlk.c
Annotate hardware config module parameters in drivers/staging/speakup/
[mirror_ubuntu-artful-kernel.git] / drivers / staging / speakup / speakup_dtlk.c
CommitLineData
c6e3fd22
WH
1/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
4d0bdcb1 3 * this version considerably modified by David Borowski, david575@rogers.com
c6e3fd22
WH
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 *
c6e3fd22
WH
18 * specificly written as a driver for the speakup screenreview
19 * package it's not a general device driver.
20 * This driver is for the RC Systems DoubleTalk PC internal synthesizer.
21 */
22#include <linux/jiffies.h>
23#include <linux/sched.h>
24#include <linux/timer.h>
25#include <linux/kthread.h>
26
27#include "spk_priv.h"
28#include "serialio.h"
29#include "speakup_dtlk.h" /* local header file for DoubleTalk values */
30#include "speakup.h"
31
32#define DRV_VERSION "2.10"
33#define PROCSPEECH 0x00
c6e3fd22
WH
34
35static int synth_probe(struct spk_synth *synth);
36static void dtlk_release(void);
37static const char *synth_immediate(struct spk_synth *synth, const char *buf);
38static void do_catch_up(struct spk_synth *synth);
39static void synth_flush(struct spk_synth *synth);
40
41static int synth_lpc;
42static int port_forced;
2c9e0cb0
CB
43static unsigned int synth_portlist[] = {
44 0x25e, 0x29e, 0x2de, 0x31e, 0x35e, 0x39e, 0
45};
c6e3fd22
WH
46static u_char synth_status;
47
48static struct var_t vars[] = {
2c9e0cb0
CB
49 { CAPS_START, .u.s = {"\x01+35p" } },
50 { CAPS_STOP, .u.s = {"\x01-35p" } },
51 { RATE, .u.n = {"\x01%ds", 8, 0, 9, 0, 0, NULL } },
52 { PITCH, .u.n = {"\x01%dp", 50, 0, 99, 0, 0, NULL } },
53 { VOL, .u.n = {"\x01%dv", 5, 0, 9, 0, 0, NULL } },
54 { TONE, .u.n = {"\x01%dx", 1, 0, 2, 0, 0, NULL } },
55 { PUNCT, .u.n = {"\x01%db", 7, 0, 15, 0, 0, NULL } },
56 { VOICE, .u.n = {"\x01%do", 0, 0, 7, 0, 0, NULL } },
57 { FREQUENCY, .u.n = {"\x01%df", 5, 0, 9, 0, 0, NULL } },
58 { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
c6e3fd22
WH
59 V_LAST_VAR
60};
61
62/*
63 * These attributes will appear in /sys/accessibility/speakup/dtlk.
64 */
65static struct kobj_attribute caps_start_attribute =
73c3700e 66 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
c6e3fd22 67static struct kobj_attribute caps_stop_attribute =
73c3700e 68 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
c6e3fd22 69static struct kobj_attribute freq_attribute =
73c3700e 70 __ATTR(freq, 0644, spk_var_show, spk_var_store);
c6e3fd22 71static struct kobj_attribute pitch_attribute =
73c3700e 72 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
c6e3fd22 73static struct kobj_attribute punct_attribute =
73c3700e 74 __ATTR(punct, 0644, spk_var_show, spk_var_store);
c6e3fd22 75static struct kobj_attribute rate_attribute =
73c3700e 76 __ATTR(rate, 0644, spk_var_show, spk_var_store);
c6e3fd22 77static struct kobj_attribute tone_attribute =
73c3700e 78 __ATTR(tone, 0644, spk_var_show, spk_var_store);
c6e3fd22 79static struct kobj_attribute voice_attribute =
73c3700e 80 __ATTR(voice, 0644, spk_var_show, spk_var_store);
c6e3fd22 81static struct kobj_attribute vol_attribute =
73c3700e 82 __ATTR(vol, 0644, spk_var_show, spk_var_store);
c6e3fd22
WH
83
84static struct kobj_attribute delay_time_attribute =
73c3700e 85 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
c6e3fd22 86static struct kobj_attribute direct_attribute =
73c3700e 87 __ATTR(direct, 0644, spk_var_show, spk_var_store);
c6e3fd22 88static struct kobj_attribute full_time_attribute =
73c3700e 89 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
c6e3fd22 90static struct kobj_attribute jiffy_delta_attribute =
73c3700e 91 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
c6e3fd22 92static struct kobj_attribute trigger_time_attribute =
73c3700e 93 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
c6e3fd22
WH
94
95/*
96 * Create a group of attributes so that we can create and destroy them all
97 * at once.
98 */
99static struct attribute *synth_attrs[] = {
100 &caps_start_attribute.attr,
101 &caps_stop_attribute.attr,
102 &freq_attribute.attr,
103 &pitch_attribute.attr,
104 &punct_attribute.attr,
105 &rate_attribute.attr,
106 &tone_attribute.attr,
107 &voice_attribute.attr,
108 &vol_attribute.attr,
109 &delay_time_attribute.attr,
110 &direct_attribute.attr,
111 &full_time_attribute.attr,
112 &jiffy_delta_attribute.attr,
113 &trigger_time_attribute.attr,
114 NULL, /* need to NULL terminate the list of attributes */
115};
116
117static struct spk_synth synth_dtlk = {
118 .name = "dtlk",
119 .version = DRV_VERSION,
120 .long_name = "DoubleTalk PC",
121 .init = "\x01@\x01\x31y",
122 .procspeech = PROCSPEECH,
123 .clear = SYNTH_CLEAR,
124 .delay = 500,
125 .trigger = 30,
126 .jiffies = 50,
127 .full = 1000,
128 .startup = SYNTH_START,
129 .checkval = SYNTH_CHECK,
130 .vars = vars,
131 .probe = synth_probe,
132 .release = dtlk_release,
133 .synth_immediate = synth_immediate,
134 .catch_up = do_catch_up,
135 .flush = synth_flush,
136 .is_alive = spk_synth_is_alive_nop,
137 .synth_adjust = NULL,
138 .read_buff_add = NULL,
139 .get_index = spk_serial_in_nowait,
140 .indexing = {
141 .command = "\x01%di",
142 .lowindex = 1,
143 .highindex = 5,
144 .currindex = 1,
145 },
146 .attributes = {
147 .attrs = synth_attrs,
148 .name = "dtlk",
149 },
150};
151
2c9e0cb0
CB
152static inline bool synth_readable(void)
153{
154 synth_status = inb_p(speakup_info.port_tts + UART_RX);
155 return (synth_status & TTS_READABLE) != 0;
156}
157
158static inline bool synth_writable(void)
159{
160 synth_status = inb_p(speakup_info.port_tts + UART_RX);
161 return (synth_status & TTS_WRITABLE) != 0;
162}
163
164static inline bool synth_full(void)
165{
166 synth_status = inb_p(speakup_info.port_tts + UART_RX);
167 return (synth_status & TTS_ALMOST_FULL) != 0;
168}
169
c6e3fd22
WH
170static void spk_out(const char ch)
171{
172 int timeout = SPK_XMITR_TIMEOUT;
8e69a811 173
2c9e0cb0 174 while (!synth_writable()) {
c6e3fd22
WH
175 if (!--timeout)
176 break;
177 udelay(1);
178 }
179 outb_p(ch, speakup_info.port_tts);
180 timeout = SPK_XMITR_TIMEOUT;
2c9e0cb0 181 while (synth_writable()) {
c6e3fd22
WH
182 if (!--timeout)
183 break;
184 udelay(1);
185 }
186}
187
188static void do_catch_up(struct spk_synth *synth)
189{
190 u_char ch;
191 unsigned long flags;
192 unsigned long jiff_max;
193 struct var_t *jiffy_delta;
194 struct var_t *delay_time;
195 int jiffy_delta_val;
196 int delay_time_val;
197
ca2beaf8
ST
198 jiffy_delta = spk_get_var(JIFFY);
199 delay_time = spk_get_var(DELAY);
62c8c835 200 spin_lock_irqsave(&speakup_info.spinlock, flags);
c6e3fd22 201 jiffy_delta_val = jiffy_delta->u.n.value;
62c8c835 202 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
c6e3fd22
WH
203 jiff_max = jiffies + jiffy_delta_val;
204 while (!kthread_should_stop()) {
62c8c835 205 spin_lock_irqsave(&speakup_info.spinlock, flags);
c6e3fd22
WH
206 if (speakup_info.flushing) {
207 speakup_info.flushing = 0;
62c8c835 208 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
c6e3fd22
WH
209 synth->flush(synth);
210 continue;
211 }
212 if (synth_buffer_empty()) {
62c8c835 213 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
c6e3fd22
WH
214 break;
215 }
216 set_current_state(TASK_INTERRUPTIBLE);
217 delay_time_val = delay_time->u.n.value;
62c8c835 218 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
c6e3fd22
WH
219 if (synth_full()) {
220 schedule_timeout(msecs_to_jiffies(delay_time_val));
221 continue;
222 }
223 set_current_state(TASK_RUNNING);
62c8c835 224 spin_lock_irqsave(&speakup_info.spinlock, flags);
c6e3fd22 225 ch = synth_buffer_getc();
62c8c835 226 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
c6e3fd22
WH
227 if (ch == '\n')
228 ch = PROCSPEECH;
229 spk_out(ch);
c65cfb5e 230 if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) {
c6e3fd22 231 spk_out(PROCSPEECH);
62c8c835 232 spin_lock_irqsave(&speakup_info.spinlock, flags);
c6e3fd22
WH
233 delay_time_val = delay_time->u.n.value;
234 jiffy_delta_val = jiffy_delta->u.n.value;
62c8c835 235 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
c6e3fd22
WH
236 schedule_timeout(msecs_to_jiffies(delay_time_val));
237 jiff_max = jiffies + jiffy_delta_val;
238 }
239 }
240 spk_out(PROCSPEECH);
241}
242
243static const char *synth_immediate(struct spk_synth *synth, const char *buf)
244{
245 u_char ch;
8e69a811 246
c6e3fd22
WH
247 while ((ch = (u_char)*buf)) {
248 if (synth_full())
249 return buf;
250 if (ch == '\n')
251 ch = PROCSPEECH;
252 spk_out(ch);
253 buf++;
254 }
61b7a284 255 return NULL;
c6e3fd22
WH
256}
257
258static void synth_flush(struct spk_synth *synth)
259{
260 outb_p(SYNTH_CLEAR, speakup_info.port_tts);
2c9e0cb0 261 while (synth_writable())
c6e3fd22
WH
262 cpu_relax();
263}
264
265static char synth_read_tts(void)
266{
267 u_char ch;
8e69a811 268
2c9e0cb0 269 while (!synth_readable())
c6e3fd22
WH
270 cpu_relax();
271 ch = synth_status & 0x7f;
272 outb_p(ch, speakup_info.port_tts);
2c9e0cb0 273 while (synth_readable())
c6e3fd22
WH
274 cpu_relax();
275 return (char) ch;
276}
277
278/* interrogate the DoubleTalk PC and return its settings */
279static struct synth_settings *synth_interrogate(struct spk_synth *synth)
280{
281 u_char *t;
282 static char buf[sizeof(struct synth_settings) + 1];
283 int total, i;
284 static struct synth_settings status;
8e69a811 285
c6e3fd22
WH
286 synth_immediate(synth, "\x18\x01?");
287 for (total = 0, i = 0; i < 50; i++) {
288 buf[total] = synth_read_tts();
289 if (total > 2 && buf[total] == 0x7f)
290 break;
291 if (total < sizeof(struct synth_settings))
292 total++;
293 }
294 t = buf;
295 /* serial number is little endian */
296 status.serial_number = t[0] + t[1]*256;
297 t += 2;
298 for (i = 0; *t != '\r'; t++) {
299 status.rom_version[i] = *t;
300 if (i < sizeof(status.rom_version)-1)
301 i++;
302 }
303 status.rom_version[i] = 0;
304 t++;
305 status.mode = *t++;
306 status.punc_level = *t++;
307 status.formant_freq = *t++;
308 status.pitch = *t++;
309 status.speed = *t++;
310 status.volume = *t++;
311 status.tone = *t++;
312 status.expression = *t++;
313 status.ext_dict_loaded = *t++;
314 status.ext_dict_status = *t++;
315 status.free_ram = *t++;
316 status.articulation = *t++;
317 status.reverb = *t++;
318 status.eob = *t++;
319 return &status;
320}
321
322static int synth_probe(struct spk_synth *synth)
323{
7aa4d5c8 324 unsigned int port_val = 0;
c6e3fd22
WH
325 int i = 0;
326 struct synth_settings *sp;
8e69a811 327
c6e3fd22
WH
328 pr_info("Probing for DoubleTalk.\n");
329 if (port_forced) {
330 speakup_info.port_tts = port_forced;
331 pr_info("probe forced to %x by kernel command line\n",
332 speakup_info.port_tts);
333 if ((port_forced & 0xf) != 0xf)
334 pr_info("warning: port base should probably end with f\n");
335 if (synth_request_region(speakup_info.port_tts-1,
336 SYNTH_IO_EXTENT)) {
337 pr_warn("sorry, port already reserved\n");
338 return -EBUSY;
339 }
340 port_val = inw(speakup_info.port_tts-1);
341 synth_lpc = speakup_info.port_tts-1;
342 } else {
343 for (i = 0; synth_portlist[i]; i++) {
344 if (synth_request_region(synth_portlist[i],
345 SYNTH_IO_EXTENT))
346 continue;
347 port_val = inw(synth_portlist[i]) & 0xfbff;
348 if (port_val == 0x107f) {
349 synth_lpc = synth_portlist[i];
350 speakup_info.port_tts = synth_lpc+1;
351 break;
352 }
353 synth_release_region(synth_portlist[i],
354 SYNTH_IO_EXTENT);
355 }
356 }
357 port_val &= 0xfbff;
358 if (port_val != 0x107f) {
359 pr_info("DoubleTalk PC: not found\n");
7aa4d5c8
AC
360 if (synth_lpc)
361 synth_release_region(synth_lpc, SYNTH_IO_EXTENT);
c6e3fd22
WH
362 return -ENODEV;
363 }
364 while (inw_p(synth_lpc) != 0x147f)
365 cpu_relax(); /* wait until it's ready */
366 sp = synth_interrogate(synth);
367 pr_info("%s: %03x-%03x, ROM ver %s, s/n %u, driver: %s\n",
368 synth->long_name, synth_lpc, synth_lpc+SYNTH_IO_EXTENT - 1,
7aa4d5c8 369 sp->rom_version, sp->serial_number, synth->version);
c6e3fd22
WH
370 synth->alive = 1;
371 return 0;
372}
373
374static void dtlk_release(void)
375{
376 if (speakup_info.port_tts)
377 synth_release_region(speakup_info.port_tts-1, SYNTH_IO_EXTENT);
378 speakup_info.port_tts = 0;
379}
380
dbf05cb0 381module_param_hw_named(port, port_forced, int, ioport, 0444);
73c3700e 382module_param_named(start, synth_dtlk.startup, short, 0444);
c6e3fd22
WH
383
384MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
385MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
386
ae89facc 387module_spk_synth(synth_dtlk);
c6e3fd22 388
c6e3fd22
WH
389MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
390MODULE_AUTHOR("David Borowski");
391MODULE_DESCRIPTION("Speakup support for DoubleTalk PC synthesizers");
392MODULE_LICENSE("GPL");
393MODULE_VERSION(DRV_VERSION);
394