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
39 static int synth_probe(struct spk_synth
*synth
);
40 static void dtlk_release(void);
41 static const char *synth_immediate(struct spk_synth
*synth
, const char *buf
);
42 static void do_catch_up(struct spk_synth
*synth
);
43 static void synth_flush(struct spk_synth
*synth
);
46 static int port_forced
;
47 static unsigned int synth_portlist
[] = {
48 0x25e, 0x29e, 0x2de, 0x31e, 0x35e, 0x39e, 0
50 static u_char synth_status
;
52 static struct var_t vars
[] = {
53 { CAPS_START
, .u
.s
= {"\x01+35p" } },
54 { CAPS_STOP
, .u
.s
= {"\x01-35p" } },
55 { RATE
, .u
.n
= {"\x01%ds", 8, 0, 9, 0, 0, NULL
} },
56 { PITCH
, .u
.n
= {"\x01%dp", 50, 0, 99, 0, 0, NULL
} },
57 { VOL
, .u
.n
= {"\x01%dv", 5, 0, 9, 0, 0, NULL
} },
58 { TONE
, .u
.n
= {"\x01%dx", 1, 0, 2, 0, 0, NULL
} },
59 { PUNCT
, .u
.n
= {"\x01%db", 7, 0, 15, 0, 0, NULL
} },
60 { VOICE
, .u
.n
= {"\x01%do", 0, 0, 7, 0, 0, NULL
} },
61 { FREQUENCY
, .u
.n
= {"\x01%df", 5, 0, 9, 0, 0, NULL
} },
62 { DIRECT
, .u
.n
= {NULL
, 0, 0, 1, 0, 0, NULL
} },
67 * These attributes will appear in /sys/accessibility/speakup/dtlk.
69 static struct kobj_attribute caps_start_attribute
=
70 __ATTR(caps_start
, USER_RW
, spk_var_show
, spk_var_store
);
71 static struct kobj_attribute caps_stop_attribute
=
72 __ATTR(caps_stop
, USER_RW
, spk_var_show
, spk_var_store
);
73 static struct kobj_attribute freq_attribute
=
74 __ATTR(freq
, USER_RW
, spk_var_show
, spk_var_store
);
75 static struct kobj_attribute pitch_attribute
=
76 __ATTR(pitch
, USER_RW
, spk_var_show
, spk_var_store
);
77 static struct kobj_attribute punct_attribute
=
78 __ATTR(punct
, USER_RW
, spk_var_show
, spk_var_store
);
79 static struct kobj_attribute rate_attribute
=
80 __ATTR(rate
, USER_RW
, spk_var_show
, spk_var_store
);
81 static struct kobj_attribute tone_attribute
=
82 __ATTR(tone
, USER_RW
, spk_var_show
, spk_var_store
);
83 static struct kobj_attribute voice_attribute
=
84 __ATTR(voice
, USER_RW
, spk_var_show
, spk_var_store
);
85 static struct kobj_attribute vol_attribute
=
86 __ATTR(vol
, USER_RW
, spk_var_show
, spk_var_store
);
88 static struct kobj_attribute delay_time_attribute
=
89 __ATTR(delay_time
, ROOT_W
, spk_var_show
, spk_var_store
);
90 static struct kobj_attribute direct_attribute
=
91 __ATTR(direct
, USER_RW
, spk_var_show
, spk_var_store
);
92 static struct kobj_attribute full_time_attribute
=
93 __ATTR(full_time
, ROOT_W
, spk_var_show
, spk_var_store
);
94 static struct kobj_attribute jiffy_delta_attribute
=
95 __ATTR(jiffy_delta
, ROOT_W
, spk_var_show
, spk_var_store
);
96 static struct kobj_attribute trigger_time_attribute
=
97 __ATTR(trigger_time
, ROOT_W
, spk_var_show
, spk_var_store
);
100 * Create a group of attributes so that we can create and destroy them all
103 static struct attribute
*synth_attrs
[] = {
104 &caps_start_attribute
.attr
,
105 &caps_stop_attribute
.attr
,
106 &freq_attribute
.attr
,
107 &pitch_attribute
.attr
,
108 &punct_attribute
.attr
,
109 &rate_attribute
.attr
,
110 &tone_attribute
.attr
,
111 &voice_attribute
.attr
,
113 &delay_time_attribute
.attr
,
114 &direct_attribute
.attr
,
115 &full_time_attribute
.attr
,
116 &jiffy_delta_attribute
.attr
,
117 &trigger_time_attribute
.attr
,
118 NULL
, /* need to NULL terminate the list of attributes */
121 static struct spk_synth synth_dtlk
= {
123 .version
= DRV_VERSION
,
124 .long_name
= "DoubleTalk PC",
125 .init
= "\x01@\x01\x31y",
126 .procspeech
= PROCSPEECH
,
127 .clear
= SYNTH_CLEAR
,
132 .startup
= SYNTH_START
,
133 .checkval
= SYNTH_CHECK
,
135 .probe
= synth_probe
,
136 .release
= dtlk_release
,
137 .synth_immediate
= synth_immediate
,
138 .catch_up
= do_catch_up
,
139 .flush
= synth_flush
,
140 .is_alive
= spk_synth_is_alive_nop
,
141 .synth_adjust
= NULL
,
142 .read_buff_add
= NULL
,
143 .get_index
= spk_serial_in_nowait
,
145 .command
= "\x01%di",
151 .attrs
= synth_attrs
,
156 static inline bool synth_readable(void)
158 synth_status
= inb_p(speakup_info
.port_tts
+ UART_RX
);
159 return (synth_status
& TTS_READABLE
) != 0;
162 static inline bool synth_writable(void)
164 synth_status
= inb_p(speakup_info
.port_tts
+ UART_RX
);
165 return (synth_status
& TTS_WRITABLE
) != 0;
168 static inline bool synth_full(void)
170 synth_status
= inb_p(speakup_info
.port_tts
+ UART_RX
);
171 return (synth_status
& TTS_ALMOST_FULL
) != 0;
174 static void spk_out(const char ch
)
176 int timeout
= SPK_XMITR_TIMEOUT
;
177 while (!synth_writable()) {
182 outb_p(ch
, speakup_info
.port_tts
);
183 timeout
= SPK_XMITR_TIMEOUT
;
184 while (synth_writable()) {
191 static void do_catch_up(struct spk_synth
*synth
)
195 unsigned long jiff_max
;
196 struct var_t
*jiffy_delta
;
197 struct var_t
*delay_time
;
201 jiffy_delta
= get_var(JIFFY
);
202 delay_time
= get_var(DELAY
);
204 jiffy_delta_val
= jiffy_delta
->u
.n
.value
;
206 jiff_max
= jiffies
+ jiffy_delta_val
;
207 while (!kthread_should_stop()) {
209 if (speakup_info
.flushing
) {
210 speakup_info
.flushing
= 0;
215 if (synth_buffer_empty()) {
219 set_current_state(TASK_INTERRUPTIBLE
);
220 delay_time_val
= delay_time
->u
.n
.value
;
223 schedule_timeout(msecs_to_jiffies(delay_time_val
));
226 set_current_state(TASK_RUNNING
);
228 ch
= synth_buffer_getc();
233 if ((jiffies
>= jiff_max
) && (ch
== SPACE
)) {
236 delay_time_val
= delay_time
->u
.n
.value
;
237 jiffy_delta_val
= jiffy_delta
->u
.n
.value
;
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
)
249 while ((ch
= (u_char
)*buf
)) {
260 static void synth_flush(struct spk_synth
*synth
)
262 outb_p(SYNTH_CLEAR
, speakup_info
.port_tts
);
263 while (synth_writable())
267 static char synth_read_tts(void)
270 while (!synth_readable())
272 ch
= synth_status
& 0x7f;
273 outb_p(ch
, speakup_info
.port_tts
);
274 while (synth_readable())
279 /* interrogate the DoubleTalk PC and return its settings */
280 static struct synth_settings
*synth_interrogate(struct spk_synth
*synth
)
283 static char buf
[sizeof(struct synth_settings
) + 1];
285 static struct synth_settings status
;
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)
291 if (total
< sizeof(struct synth_settings
))
295 /* serial number is little endian */
296 status
.serial_number
= t
[0] + t
[1]*256;
298 for (i
= 0; *t
!= '\r'; t
++) {
299 status
.rom_version
[i
] = *t
;
300 if (i
< sizeof(status
.rom_version
)-1)
303 status
.rom_version
[i
] = 0;
306 status
.punc_level
= *t
++;
307 status
.formant_freq
= *t
++;
310 status
.volume
= *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
++;
322 static int synth_probe(struct spk_synth
*synth
)
324 unsigned int port_val
= 0;
326 struct synth_settings
*sp
;
327 pr_info("Probing for DoubleTalk.\n");
329 speakup_info
.port_tts
= port_forced
;
330 pr_info("probe forced to %x by kernel command line\n",
331 speakup_info
.port_tts
);
332 if ((port_forced
& 0xf) != 0xf)
333 pr_info("warning: port base should probably end with f\n");
334 if (synth_request_region(speakup_info
.port_tts
-1,
336 pr_warn("sorry, port already reserved\n");
339 port_val
= inw(speakup_info
.port_tts
-1);
340 synth_lpc
= speakup_info
.port_tts
-1;
342 for (i
= 0; synth_portlist
[i
]; i
++) {
343 if (synth_request_region(synth_portlist
[i
],
346 port_val
= inw(synth_portlist
[i
]) & 0xfbff;
347 if (port_val
== 0x107f) {
348 synth_lpc
= synth_portlist
[i
];
349 speakup_info
.port_tts
= synth_lpc
+1;
352 synth_release_region(synth_portlist
[i
],
357 if (port_val
!= 0x107f) {
358 pr_info("DoubleTalk PC: not found\n");
359 synth_release_region(synth_lpc
, SYNTH_IO_EXTENT
);
362 while (inw_p(synth_lpc
) != 0x147f)
363 cpu_relax(); /* wait until it's ready */
364 sp
= synth_interrogate(synth
);
365 pr_info("%s: %03x-%03x, ROM ver %s, s/n %u, driver: %s\n",
366 synth
->long_name
, synth_lpc
, synth_lpc
+SYNTH_IO_EXTENT
- 1,
367 sp
->rom_version
, sp
->serial_number
, synth
->version
);
372 static void dtlk_release(void)
374 if (speakup_info
.port_tts
)
375 synth_release_region(speakup_info
.port_tts
-1, SYNTH_IO_EXTENT
);
376 speakup_info
.port_tts
= 0;
379 module_param_named(port
, port_forced
, int, S_IRUGO
);
380 module_param_named(start
, synth_dtlk
.startup
, short, S_IRUGO
);
382 MODULE_PARM_DESC(port
, "Set the port for the synthesizer (override probing).");
383 MODULE_PARM_DESC(start
, "Start the synthesizer once it is loaded.");
385 static int __init
dtlk_init(void)
387 return synth_add(&synth_dtlk
);
390 static void __exit
dtlk_exit(void)
392 synth_remove(&synth_dtlk
);
395 module_init(dtlk_init
);
396 module_exit(dtlk_exit
);
397 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
398 MODULE_AUTHOR("David Borowski");
399 MODULE_DESCRIPTION("Speakup support for DoubleTalk PC synthesizers");
400 MODULE_LICENSE("GPL");
401 MODULE_VERSION(DRV_VERSION
);