2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3 * this version considerably modified by David Borowski, david575@rogers.com
5 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski.
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.
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.
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.
22 #include <linux/jiffies.h>
23 #include <linux/sched.h>
24 #include <linux/timer.h>
25 #include <linux/kthread.h>
29 #include "speakup_dtlk.h" /* local header file for DoubleTalk values */
32 #define DRV_VERSION "2.10"
33 #define PROCSPEECH 0x00
35 static int synth_probe(struct spk_synth *synth);
36 static void dtlk_release(void);
37 static const char *synth_immediate(struct spk_synth *synth, const char *buf);
38 static void do_catch_up(struct spk_synth *synth);
39 static void synth_flush(struct spk_synth *synth);
42 static int port_forced;
43 static unsigned int synth_portlist[] = {
44 0x25e, 0x29e, 0x2de, 0x31e, 0x35e, 0x39e, 0
47 static u_char synth_status;
49 static struct var_t vars[] = {
50 { CAPS_START, .u.s = {"\x01+35p" } },
51 { CAPS_STOP, .u.s = {"\x01-35p" } },
52 { RATE, .u.n = {"\x01%ds", 8, 0, 9, 0, 0, NULL } },
53 { PITCH, .u.n = {"\x01%dp", 50, 0, 99, 0, 0, NULL } },
54 { VOL, .u.n = {"\x01%dv", 5, 0, 9, 0, 0, NULL } },
55 { TONE, .u.n = {"\x01%dx", 1, 0, 2, 0, 0, NULL } },
56 { PUNCT, .u.n = {"\x01%db", 7, 0, 15, 0, 0, NULL } },
57 { VOICE, .u.n = {"\x01%do", 0, 0, 7, 0, 0, NULL } },
58 { FREQUENCY, .u.n = {"\x01%df", 5, 0, 9, 0, 0, NULL } },
59 { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
64 * These attributes will appear in /sys/accessibility/speakup/dtlk.
66 static struct kobj_attribute caps_start_attribute =
67 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
68 static struct kobj_attribute caps_stop_attribute =
69 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
70 static struct kobj_attribute freq_attribute =
71 __ATTR(freq, 0644, spk_var_show, spk_var_store);
72 static struct kobj_attribute pitch_attribute =
73 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
74 static struct kobj_attribute punct_attribute =
75 __ATTR(punct, 0644, spk_var_show, spk_var_store);
76 static struct kobj_attribute rate_attribute =
77 __ATTR(rate, 0644, spk_var_show, spk_var_store);
78 static struct kobj_attribute tone_attribute =
79 __ATTR(tone, 0644, spk_var_show, spk_var_store);
80 static struct kobj_attribute voice_attribute =
81 __ATTR(voice, 0644, spk_var_show, spk_var_store);
82 static struct kobj_attribute vol_attribute =
83 __ATTR(vol, 0644, spk_var_show, spk_var_store);
85 static struct kobj_attribute delay_time_attribute =
86 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
87 static struct kobj_attribute direct_attribute =
88 __ATTR(direct, 0644, spk_var_show, spk_var_store);
89 static struct kobj_attribute full_time_attribute =
90 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
91 static struct kobj_attribute jiffy_delta_attribute =
92 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
93 static struct kobj_attribute trigger_time_attribute =
94 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
97 * Create a group of attributes so that we can create and destroy them all
100 static struct attribute *synth_attrs[] = {
101 &caps_start_attribute.attr,
102 &caps_stop_attribute.attr,
103 &freq_attribute.attr,
104 &pitch_attribute.attr,
105 &punct_attribute.attr,
106 &rate_attribute.attr,
107 &tone_attribute.attr,
108 &voice_attribute.attr,
110 &delay_time_attribute.attr,
111 &direct_attribute.attr,
112 &full_time_attribute.attr,
113 &jiffy_delta_attribute.attr,
114 &trigger_time_attribute.attr,
115 NULL, /* need to NULL terminate the list of attributes */
118 static struct spk_synth synth_dtlk = {
120 .version = DRV_VERSION,
121 .long_name = "DoubleTalk PC",
122 .init = "\x01@\x01\x31y",
123 .procspeech = PROCSPEECH,
124 .clear = SYNTH_CLEAR,
129 .startup = SYNTH_START,
130 .checkval = SYNTH_CHECK,
132 .io_ops = &spk_serial_io_ops,
133 .probe = synth_probe,
134 .release = dtlk_release,
135 .synth_immediate = synth_immediate,
136 .catch_up = do_catch_up,
137 .flush = synth_flush,
138 .is_alive = spk_synth_is_alive_nop,
139 .synth_adjust = NULL,
140 .read_buff_add = NULL,
141 .get_index = spk_synth_get_index,
143 .command = "\x01%di",
149 .attrs = synth_attrs,
154 static inline bool synth_readable(void)
156 synth_status = inb_p(speakup_info.port_tts + UART_RX);
157 return (synth_status & TTS_READABLE) != 0;
160 static inline bool synth_writable(void)
162 synth_status = inb_p(speakup_info.port_tts + UART_RX);
163 return (synth_status & TTS_WRITABLE) != 0;
166 static inline bool synth_full(void)
168 synth_status = inb_p(speakup_info.port_tts + UART_RX);
169 return (synth_status & TTS_ALMOST_FULL) != 0;
172 static void spk_out(const char ch)
174 int timeout = SPK_XMITR_TIMEOUT;
176 while (!synth_writable()) {
181 outb_p(ch, speakup_info.port_tts);
182 timeout = SPK_XMITR_TIMEOUT;
183 while (synth_writable()) {
190 static void do_catch_up(struct spk_synth *synth)
194 unsigned long jiff_max;
195 struct var_t *jiffy_delta;
196 struct var_t *delay_time;
200 jiffy_delta = spk_get_var(JIFFY);
201 delay_time = spk_get_var(DELAY);
202 spin_lock_irqsave(&speakup_info.spinlock, flags);
203 jiffy_delta_val = jiffy_delta->u.n.value;
204 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
205 jiff_max = jiffies + jiffy_delta_val;
206 while (!kthread_should_stop()) {
207 spin_lock_irqsave(&speakup_info.spinlock, flags);
208 if (speakup_info.flushing) {
209 speakup_info.flushing = 0;
210 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
214 synth_buffer_skip_nonlatin1();
215 if (synth_buffer_empty()) {
216 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
219 set_current_state(TASK_INTERRUPTIBLE);
220 delay_time_val = delay_time->u.n.value;
221 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
223 schedule_timeout(msecs_to_jiffies(delay_time_val));
226 set_current_state(TASK_RUNNING);
227 spin_lock_irqsave(&speakup_info.spinlock, flags);
228 ch = synth_buffer_getc();
229 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
233 if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) {
235 spin_lock_irqsave(&speakup_info.spinlock, flags);
236 delay_time_val = delay_time->u.n.value;
237 jiffy_delta_val = jiffy_delta->u.n.value;
238 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
239 schedule_timeout(msecs_to_jiffies(delay_time_val));
240 jiff_max = jiffies + jiffy_delta_val;
246 static const char *synth_immediate(struct spk_synth *synth, const char *buf)
250 while ((ch = (u_char)*buf)) {
261 static void synth_flush(struct spk_synth *synth)
263 outb_p(SYNTH_CLEAR, speakup_info.port_tts);
264 while (synth_writable())
268 static char synth_read_tts(void)
272 while (!synth_readable())
274 ch = synth_status & 0x7f;
275 outb_p(ch, speakup_info.port_tts);
276 while (synth_readable())
281 /* interrogate the DoubleTalk PC and return its settings */
282 static struct synth_settings *synth_interrogate(struct spk_synth *synth)
285 static char buf[sizeof(struct synth_settings) + 1];
287 static struct synth_settings status;
289 synth_immediate(synth, "\x18\x01?");
290 for (total = 0, i = 0; i < 50; i++) {
291 buf[total] = synth_read_tts();
292 if (total > 2 && buf[total] == 0x7f)
294 if (total < sizeof(struct synth_settings))
298 /* serial number is little endian */
299 status.serial_number = t[0] + t[1]*256;
301 for (i = 0; *t != '\r'; t++) {
302 status.rom_version[i] = *t;
303 if (i < sizeof(status.rom_version) - 1)
306 status.rom_version[i] = 0;
309 status.punc_level = *t++;
310 status.formant_freq = *t++;
313 status.volume = *t++;
315 status.expression = *t++;
316 status.ext_dict_loaded = *t++;
317 status.ext_dict_status = *t++;
318 status.free_ram = *t++;
319 status.articulation = *t++;
320 status.reverb = *t++;
325 static int synth_probe(struct spk_synth *synth)
327 unsigned int port_val = 0;
329 struct synth_settings *sp;
331 pr_info("Probing for DoubleTalk.\n");
333 speakup_info.port_tts = port_forced;
334 pr_info("probe forced to %x by kernel command line\n",
335 speakup_info.port_tts);
336 if ((port_forced & 0xf) != 0xf)
337 pr_info("warning: port base should probably end with f\n");
338 if (synth_request_region(speakup_info.port_tts-1,
340 pr_warn("sorry, port already reserved\n");
343 port_val = inw(speakup_info.port_tts-1);
344 synth_lpc = speakup_info.port_tts-1;
346 for (i = 0; synth_portlist[i]; i++) {
347 if (synth_request_region(synth_portlist[i],
350 port_val = inw(synth_portlist[i]) & 0xfbff;
351 if (port_val == 0x107f) {
352 synth_lpc = synth_portlist[i];
353 speakup_info.port_tts = synth_lpc+1;
356 synth_release_region(synth_portlist[i],
361 if (port_val != 0x107f) {
362 pr_info("DoubleTalk PC: not found\n");
364 synth_release_region(synth_lpc, SYNTH_IO_EXTENT);
367 while (inw_p(synth_lpc) != 0x147f)
368 cpu_relax(); /* wait until it's ready */
369 sp = synth_interrogate(synth);
370 pr_info("%s: %03x-%03x, ROM ver %s, s/n %u, driver: %s\n",
371 synth->long_name, synth_lpc, synth_lpc+SYNTH_IO_EXTENT - 1,
372 sp->rom_version, sp->serial_number, synth->version);
377 static void dtlk_release(void)
379 spk_stop_serial_interrupt();
380 if (speakup_info.port_tts)
381 synth_release_region(speakup_info.port_tts-1, SYNTH_IO_EXTENT);
382 speakup_info.port_tts = 0;
385 module_param_hw_named(port, port_forced, int, ioport, 0444);
386 module_param_named(start, synth_dtlk.startup, short, 0444);
388 MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
389 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
391 module_spk_synth(synth_dtlk);
393 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
394 MODULE_AUTHOR("David Borowski");
395 MODULE_DESCRIPTION("Speakup support for DoubleTalk PC synthesizers");
396 MODULE_LICENSE("GPL");
397 MODULE_VERSION(DRV_VERSION);