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 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * specificly written as a driver for the speakup screenreview
23 * package it's not a general device driver.
24 * This driver is for the RC Systems DoubleTalk PC internal synthesizer.
26 #include <linux/jiffies.h>
27 #include <linux/sched.h>
28 #include <linux/timer.h>
29 #include <linux/kthread.h>
33 #include "speakup_dtlk.h" /* local header file for DoubleTalk values */
36 #define DRV_VERSION "2.10"
37 #define PROCSPEECH 0x00
38 #define synth_readable() ((synth_status = inb_p(speakup_info.port_tts + UART_RX)) & TTS_READABLE)
39 #define synth_writable() ((synth_status = inb_p(speakup_info.port_tts + UART_RX)) & TTS_WRITABLE)
40 #define synth_full() ((synth_status = inb_p(speakup_info.port_tts + UART_RX)) & TTS_ALMOST_FULL)
42 static int synth_probe(struct spk_synth *synth);
43 static void dtlk_release(void);
44 static const char *synth_immediate(struct spk_synth *synth, const char *buf);
45 static void do_catch_up(struct spk_synth *synth);
46 static void synth_flush(struct spk_synth *synth);
49 static int port_forced;
50 static unsigned int synth_portlist[] =
51 { 0x25e, 0x29e, 0x2de, 0x31e, 0x35e, 0x39e, 0 };
52 static u_char synth_status;
54 static struct var_t vars[] = {
55 { CAPS_START, .u.s = {"\x01+35p" }},
56 { CAPS_STOP, .u.s = {"\x01-35p" }},
57 { RATE, .u.n = {"\x01%ds", 8, 0, 9, 0, 0, NULL }},
58 { PITCH, .u.n = {"\x01%dp", 50, 0, 99, 0, 0, NULL }},
59 { VOL, .u.n = {"\x01%dv", 5, 0, 9, 0, 0, NULL }},
60 { TONE, .u.n = {"\x01%dx", 1, 0, 2, 0, 0, NULL }},
61 { PUNCT, .u.n = {"\x01%db", 7, 0, 15, 0, 0, NULL }},
62 { VOICE, .u.n = {"\x01%do", 0, 0, 7, 0, 0, NULL }},
63 { FREQUENCY, .u.n = {"\x01%df", 5, 0, 9, 0, 0, NULL }},
64 { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL }},
69 * These attributes will appear in /sys/accessibility/speakup/dtlk.
71 static struct kobj_attribute caps_start_attribute =
72 __ATTR(caps_start, USER_RW, spk_var_show, spk_var_store);
73 static struct kobj_attribute caps_stop_attribute =
74 __ATTR(caps_stop, USER_RW, spk_var_show, spk_var_store);
75 static struct kobj_attribute freq_attribute =
76 __ATTR(freq, USER_RW, spk_var_show, spk_var_store);
77 static struct kobj_attribute pitch_attribute =
78 __ATTR(pitch, USER_RW, spk_var_show, spk_var_store);
79 static struct kobj_attribute punct_attribute =
80 __ATTR(punct, USER_RW, spk_var_show, spk_var_store);
81 static struct kobj_attribute rate_attribute =
82 __ATTR(rate, USER_RW, spk_var_show, spk_var_store);
83 static struct kobj_attribute tone_attribute =
84 __ATTR(tone, USER_RW, spk_var_show, spk_var_store);
85 static struct kobj_attribute voice_attribute =
86 __ATTR(voice, USER_RW, spk_var_show, spk_var_store);
87 static struct kobj_attribute vol_attribute =
88 __ATTR(vol, USER_RW, spk_var_show, spk_var_store);
90 static struct kobj_attribute delay_time_attribute =
91 __ATTR(delay_time, ROOT_W, spk_var_show, spk_var_store);
92 static struct kobj_attribute direct_attribute =
93 __ATTR(direct, USER_RW, spk_var_show, spk_var_store);
94 static struct kobj_attribute full_time_attribute =
95 __ATTR(full_time, ROOT_W, spk_var_show, spk_var_store);
96 static struct kobj_attribute jiffy_delta_attribute =
97 __ATTR(jiffy_delta, ROOT_W, spk_var_show, spk_var_store);
98 static struct kobj_attribute trigger_time_attribute =
99 __ATTR(trigger_time, ROOT_W, spk_var_show, spk_var_store);
102 * Create a group of attributes so that we can create and destroy them all
105 static struct attribute *synth_attrs[] = {
106 &caps_start_attribute.attr,
107 &caps_stop_attribute.attr,
108 &freq_attribute.attr,
109 &pitch_attribute.attr,
110 &punct_attribute.attr,
111 &rate_attribute.attr,
112 &tone_attribute.attr,
113 &voice_attribute.attr,
115 &delay_time_attribute.attr,
116 &direct_attribute.attr,
117 &full_time_attribute.attr,
118 &jiffy_delta_attribute.attr,
119 &trigger_time_attribute.attr,
120 NULL, /* need to NULL terminate the list of attributes */
123 static struct spk_synth synth_dtlk = {
125 .version = DRV_VERSION,
126 .long_name = "DoubleTalk PC",
127 .init = "\x01@\x01\x31y",
128 .procspeech = PROCSPEECH,
129 .clear = SYNTH_CLEAR,
134 .startup = SYNTH_START,
135 .checkval = SYNTH_CHECK,
137 .probe = synth_probe,
138 .release = dtlk_release,
139 .synth_immediate = synth_immediate,
140 .catch_up = do_catch_up,
141 .flush = synth_flush,
142 .is_alive = spk_synth_is_alive_nop,
143 .synth_adjust = NULL,
144 .read_buff_add = NULL,
145 .get_index = spk_serial_in_nowait,
147 .command = "\x01%di",
153 .attrs = synth_attrs,
158 static void spk_out(const char ch)
160 int timeout = SPK_XMITR_TIMEOUT;
161 while (synth_writable() == 0) {
166 outb_p(ch, speakup_info.port_tts);
167 timeout = SPK_XMITR_TIMEOUT;
168 while (synth_writable() != 0) {
175 static void do_catch_up(struct spk_synth *synth)
179 unsigned long jiff_max;
180 struct var_t *jiffy_delta;
181 struct var_t *delay_time;
185 jiffy_delta = get_var(JIFFY);
186 delay_time = get_var(DELAY);
188 jiffy_delta_val = jiffy_delta->u.n.value;
190 jiff_max = jiffies + jiffy_delta_val;
191 while (!kthread_should_stop()) {
193 if (speakup_info.flushing) {
194 speakup_info.flushing = 0;
199 if (synth_buffer_empty()) {
203 set_current_state(TASK_INTERRUPTIBLE);
204 delay_time_val = delay_time->u.n.value;
207 schedule_timeout(msecs_to_jiffies(delay_time_val));
210 set_current_state(TASK_RUNNING);
212 ch = synth_buffer_getc();
217 if ((jiffies >= jiff_max) && (ch == SPACE)) {
220 delay_time_val = delay_time->u.n.value;
221 jiffy_delta_val = jiffy_delta->u.n.value;
223 schedule_timeout(msecs_to_jiffies(delay_time_val));
224 jiff_max = jiffies + jiffy_delta_val;
230 static const char *synth_immediate(struct spk_synth *synth, const char *buf)
233 while ((ch = (u_char)*buf)) {
244 static void synth_flush(struct spk_synth *synth)
246 outb_p(SYNTH_CLEAR, speakup_info.port_tts);
247 while (synth_writable() != 0)
251 static char synth_read_tts(void)
254 while (synth_readable() == 0)
256 ch = synth_status & 0x7f;
257 outb_p(ch, speakup_info.port_tts);
258 while (synth_readable() != 0)
263 /* interrogate the DoubleTalk PC and return its settings */
264 static struct synth_settings *synth_interrogate(struct spk_synth *synth)
267 static char buf[sizeof(struct synth_settings) + 1];
269 static struct synth_settings status;
270 synth_immediate(synth, "\x18\x01?");
271 for (total = 0, i = 0; i < 50; i++) {
272 buf[total] = synth_read_tts();
273 if (total > 2 && buf[total] == 0x7f)
275 if (total < sizeof(struct synth_settings))
279 /* serial number is little endian */
280 status.serial_number = t[0] + t[1]*256;
282 for (i = 0; *t != '\r'; t++) {
283 status.rom_version[i] = *t;
284 if (i < sizeof(status.rom_version)-1)
287 status.rom_version[i] = 0;
290 status.punc_level = *t++;
291 status.formant_freq = *t++;
294 status.volume = *t++;
296 status.expression = *t++;
297 status.ext_dict_loaded = *t++;
298 status.ext_dict_status = *t++;
299 status.free_ram = *t++;
300 status.articulation = *t++;
301 status.reverb = *t++;
306 static int synth_probe(struct spk_synth *synth)
308 unsigned int port_val = 0;
310 struct synth_settings *sp;
311 pr_info("Probing for DoubleTalk.\n");
313 speakup_info.port_tts = port_forced;
314 pr_info("probe forced to %x by kernel command line\n",
315 speakup_info.port_tts);
316 if ((port_forced & 0xf) != 0xf)
317 pr_info("warning: port base should probably end with f\n");
318 if (synth_request_region(speakup_info.port_tts-1,
320 pr_warn("sorry, port already reserved\n");
323 port_val = inw(speakup_info.port_tts-1);
324 synth_lpc = speakup_info.port_tts-1;
326 for (i = 0; synth_portlist[i]; i++) {
327 if (synth_request_region(synth_portlist[i],
330 port_val = inw(synth_portlist[i]) & 0xfbff;
331 if (port_val == 0x107f) {
332 synth_lpc = synth_portlist[i];
333 speakup_info.port_tts = synth_lpc+1;
336 synth_release_region(synth_portlist[i],
341 if (port_val != 0x107f) {
342 pr_info("DoubleTalk PC: not found\n");
343 synth_release_region(synth_lpc, SYNTH_IO_EXTENT);
346 while (inw_p(synth_lpc) != 0x147f)
347 cpu_relax(); /* wait until it's ready */
348 sp = synth_interrogate(synth);
349 pr_info("%s: %03x-%03x, ROM ver %s, s/n %u, driver: %s\n",
350 synth->long_name, synth_lpc, synth_lpc+SYNTH_IO_EXTENT - 1,
351 sp->rom_version, sp->serial_number, synth->version);
356 static void dtlk_release(void)
358 if (speakup_info.port_tts)
359 synth_release_region(speakup_info.port_tts-1, SYNTH_IO_EXTENT);
360 speakup_info.port_tts = 0;
363 module_param_named(port, port_forced, int, S_IRUGO);
364 module_param_named(start, synth_dtlk.startup, short, S_IRUGO);
366 MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
367 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
369 static int __init dtlk_init(void)
371 return synth_add(&synth_dtlk);
374 static void __exit dtlk_exit(void)
376 synth_remove(&synth_dtlk);
379 module_init(dtlk_init);
380 module_exit(dtlk_exit);
381 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
382 MODULE_AUTHOR("David Borowski");
383 MODULE_DESCRIPTION("Speakup support for DoubleTalk PC synthesizers");
384 MODULE_LICENSE("GPL");
385 MODULE_VERSION(DRV_VERSION);