2 * This is the DECtalk PC speakup driver
4 * Some constants from DEC's DOS driver:
5 * Copyright (c) by Digital Equipment Corp.
7 * 386BSD DECtalk PC driver:
8 * Copyright (c) 1996 Brian Buhrow <buhrow@lothlorien.nfbcal.org>
10 * Linux DECtalk PC driver:
11 * Copyright (c) 1997 Nicolas Pitre <nico@cam.org>
13 * speakup DECtalk PC Internal driver:
14 * Copyright (c) 2003 David Borowski <david575@golden.net>
16 * All rights reserved.
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #include <linux/jiffies.h>
33 #include <linux/sched.h>
34 #include <linux/timer.h>
35 #include <linux/kthread.h>
40 #define MODULE_init 0x0dec /* module in boot code */
41 #define MODULE_self_test 0x8800 /* module in self-test */
42 #define MODULE_reset 0xffff /* reinit the whole module */
44 #define MODE_mask 0xf000 /* mode bits in high nibble */
45 #define MODE_null 0x0000
46 #define MODE_test 0x2000 /* in testing mode */
47 #define MODE_status 0x8000
48 #define STAT_int 0x0001 /* running in interrupt mode */
49 #define STAT_tr_char 0x0002 /* character data to transmit */
50 #define STAT_rr_char 0x0004 /* ready to receive char data */
51 #define STAT_cmd_ready 0x0008 /* ready to accept commands */
52 #define STAT_dma_ready 0x0010 /* dma command ready */
53 #define STAT_digitized 0x0020 /* spc in digitized mode */
54 #define STAT_new_index 0x0040 /* new last index ready */
55 #define STAT_new_status 0x0080 /* new status posted */
56 #define STAT_dma_state 0x0100 /* dma state toggle */
57 #define STAT_index_valid 0x0200 /* indexs are valid */
58 #define STAT_flushing 0x0400 /* flush in progress */
59 #define STAT_self_test 0x0800 /* module in self test */
60 #define MODE_ready 0xc000 /* module ready for next phase */
61 #define READY_boot 0x0000
62 #define READY_kernel 0x0001
63 #define MODE_error 0xf000
65 #define CMD_mask 0xf000 /* mask for command nibble */
66 #define CMD_null 0x0000 /* post status */
67 #define CMD_control 0x1000 /* hard control command */
68 #define CTRL_mask 0x0F00 /* mask off control nibble */
69 #define CTRL_data 0x00FF /* mask to get data byte */
70 #define CTRL_null 0x0000 /* null control */
71 #define CTRL_vol_up 0x0100 /* increase volume */
72 #define CTRL_vol_down 0x0200 /* decrease volume */
73 #define CTRL_vol_set 0x0300 /* set volume */
74 #define CTRL_pause 0x0400 /* pause spc */
75 #define CTRL_resume 0x0500 /* resume spc clock */
76 #define CTRL_resume_spc 0x0001 /* resume spc soft pause */
77 #define CTRL_flush 0x0600 /* flush all buffers */
78 #define CTRL_int_enable 0x0700 /* enable status change ints */
79 #define CTRL_buff_free 0x0800 /* buffer remain count */
80 #define CTRL_buff_used 0x0900 /* buffer in use */
81 #define CTRL_speech 0x0a00 /* immediate speech change */
82 #define CTRL_SP_voice 0x0001 /* voice change */
83 #define CTRL_SP_rate 0x0002 /* rate change */
84 #define CTRL_SP_comma 0x0003 /* comma pause change */
85 #define CTRL_SP_period 0x0004 /* period pause change */
86 #define CTRL_SP_rate_delta 0x0005 /* delta rate change */
87 #define CTRL_SP_get_param 0x0006 /* return the desired parameter */
88 #define CTRL_last_index 0x0b00 /* get last index spoken */
89 #define CTRL_io_priority 0x0c00 /* change i/o priority */
90 #define CTRL_free_mem 0x0d00 /* get free paragraphs on module */
91 #define CTRL_get_lang 0x0e00 /* return bit mask of loaded
94 #define CMD_test 0x2000 /* self-test request */
95 #define TEST_mask 0x0F00 /* isolate test field */
96 #define TEST_null 0x0000 /* no test requested */
97 #define TEST_isa_int 0x0100 /* assert isa irq */
98 #define TEST_echo 0x0200 /* make data in == data out */
99 #define TEST_seg 0x0300 /* set peek/poke segment */
100 #define TEST_off 0x0400 /* set peek/poke offset */
101 #define TEST_peek 0x0500 /* data out == *peek */
102 #define TEST_poke 0x0600 /* *peek == data in */
103 #define TEST_sub_code 0x00FF /* user defined test sub codes */
104 #define CMD_id 0x3000 /* return software id */
105 #define ID_null 0x0000 /* null id */
106 #define ID_kernel 0x0100 /* kernel code executing */
107 #define ID_boot 0x0200 /* boot code executing */
108 #define CMD_dma 0x4000 /* force a dma start */
109 #define CMD_reset 0x5000 /* reset module status */
110 #define CMD_sync 0x6000 /* kernel sync command */
111 #define CMD_char_in 0x7000 /* single character send */
112 #define CMD_char_out 0x8000 /* single character get */
113 #define CHAR_count_1 0x0100 /* one char in cmd_low */
114 #define CHAR_count_2 0x0200 /* the second in data_low */
115 #define CHAR_count_3 0x0300 /* the third in data_high */
116 #define CMD_spc_mode 0x9000 /* change spc mode */
117 #define CMD_spc_to_text 0x0100 /* set to text mode */
118 #define CMD_spc_to_digit 0x0200 /* set to digital mode */
119 #define CMD_spc_rate 0x0400 /* change spc data rate */
120 #define CMD_error 0xf000 /* severe error */
122 enum { PRIMARY_DIC = 0, USER_DIC, COMMAND_DIC, ABBREV_DIC };
124 #define DMA_single_in 0x01
125 #define DMA_single_out 0x02
126 #define DMA_buff_in 0x03
127 #define DMA_buff_out 0x04
128 #define DMA_control 0x05
129 #define DT_MEM_ALLOC 0x03
130 #define DT_SET_DIC 0x04
131 #define DT_START_TASK 0x05
132 #define DT_LOAD_MEM 0x06
133 #define DT_READ_MEM 0x07
134 #define DT_DIGITAL_IN 0x08
135 #define DMA_sync 0x06
136 #define DMA_sync_char 0x07
138 #define DRV_VERSION "2.12"
139 #define PROCSPEECH 0x0b
140 #define SYNTH_IO_EXTENT 8
142 static int synth_probe(struct spk_synth *synth);
143 static void dtpc_release(void);
144 static const char *synth_immediate(struct spk_synth *synth, const char *buf);
145 static void do_catch_up(struct spk_synth *synth);
146 static void synth_flush(struct spk_synth *synth);
148 static int synth_portlist[] = { 0x340, 0x350, 0x240, 0x250, 0 };
149 static int in_escape, is_flushing;
150 static int dt_stat, dma_state;
152 static struct var_t vars[] = {
153 { CAPS_START, .u.s = {"[:dv ap 200]" } },
154 { CAPS_STOP, .u.s = {"[:dv ap 100]" } },
155 { RATE, .u.n = {"[:ra %d]", 9, 0, 18, 150, 25, NULL } },
156 { PITCH, .u.n = {"[:dv ap %d]", 80, 0, 100, 20, 0, NULL } },
157 { VOL, .u.n = {"[:vo se %d]", 5, 0, 9, 5, 10, NULL } },
158 { PUNCT, .u.n = {"[:pu %c]", 0, 0, 2, 0, 0, "nsa" } },
159 { VOICE, .u.n = {"[:n%c]", 0, 0, 9, 0, 0, "phfdburwkv" } },
160 { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
165 * These attributes will appear in /sys/accessibility/speakup/decpc.
167 static struct kobj_attribute caps_start_attribute =
168 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
169 static struct kobj_attribute caps_stop_attribute =
170 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
171 static struct kobj_attribute pitch_attribute =
172 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
173 static struct kobj_attribute punct_attribute =
174 __ATTR(punct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
175 static struct kobj_attribute rate_attribute =
176 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
177 static struct kobj_attribute voice_attribute =
178 __ATTR(voice, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
179 static struct kobj_attribute vol_attribute =
180 __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
182 static struct kobj_attribute delay_time_attribute =
183 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
184 static struct kobj_attribute direct_attribute =
185 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
186 static struct kobj_attribute full_time_attribute =
187 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
188 static struct kobj_attribute jiffy_delta_attribute =
189 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
190 static struct kobj_attribute trigger_time_attribute =
191 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
194 * Create a group of attributes so that we can create and destroy them all
197 static struct attribute *synth_attrs[] = {
198 &caps_start_attribute.attr,
199 &caps_stop_attribute.attr,
200 &pitch_attribute.attr,
201 &punct_attribute.attr,
202 &rate_attribute.attr,
203 &voice_attribute.attr,
205 &delay_time_attribute.attr,
206 &direct_attribute.attr,
207 &full_time_attribute.attr,
208 &jiffy_delta_attribute.attr,
209 &trigger_time_attribute.attr,
210 NULL, /* need to NULL terminate the list of attributes */
213 static struct spk_synth synth_dec_pc = {
215 .version = DRV_VERSION,
216 .long_name = "Dectalk PC",
217 .init = "[:pe -380]",
218 .procspeech = PROCSPEECH,
224 .startup = SYNTH_START,
225 .checkval = SYNTH_CHECK,
227 .probe = synth_probe,
228 .release = dtpc_release,
229 .synth_immediate = synth_immediate,
230 .catch_up = do_catch_up,
231 .flush = synth_flush,
232 .is_alive = spk_synth_is_alive_nop,
233 .synth_adjust = NULL,
234 .read_buff_add = NULL,
243 .attrs = synth_attrs,
248 static int dt_getstatus(void)
250 dt_stat = inb_p(speakup_info.port_tts) |
251 (inb_p(speakup_info.port_tts + 1) << 8);
255 static void dt_sendcmd(u_int cmd)
257 outb_p(cmd & 0xFF, speakup_info.port_tts);
258 outb_p((cmd >> 8) & 0xFF, speakup_info.port_tts+1);
261 static int dt_waitbit(int bit)
265 while (--timeout > 0) {
266 if ((dt_getstatus() & bit) == bit)
273 static int dt_wait_dma(void)
275 int timeout = 100, state = dma_state;
277 if (!dt_waitbit(STAT_dma_ready))
279 while (--timeout > 0) {
280 if ((dt_getstatus()&STAT_dma_state) == state)
284 dma_state = dt_getstatus() & STAT_dma_state;
288 static int dt_ctrl(u_int cmd)
292 if (!dt_waitbit(STAT_cmd_ready))
294 outb_p(0, speakup_info.port_tts+2);
295 outb_p(0, speakup_info.port_tts+3);
297 dt_sendcmd(CMD_control|cmd);
298 outb_p(0, speakup_info.port_tts+6);
299 while (dt_getstatus() & STAT_cmd_ready) {
304 dt_sendcmd(CMD_null);
308 static void synth_flush(struct spk_synth *synth)
316 while (dt_ctrl(CTRL_flush)) {
321 for (timeout = 0; timeout < 10; timeout++) {
322 if (dt_waitbit(STAT_dma_ready))
326 outb_p(DMA_sync, speakup_info.port_tts+4);
327 outb_p(0, speakup_info.port_tts+4);
329 for (timeout = 0; timeout < 10; timeout++) {
330 if (!(dt_getstatus() & STAT_flushing))
334 dma_state = dt_getstatus() & STAT_dma_state;
335 dma_state ^= STAT_dma_state;
339 static int dt_sendchar(char ch)
343 if (!(dt_stat & STAT_rr_char))
345 outb_p(DMA_single_in, speakup_info.port_tts+4);
346 outb_p(ch, speakup_info.port_tts+4);
347 dma_state ^= STAT_dma_state;
351 static int testkernel(void)
355 if (dt_getstatus() == 0xffff) {
359 dt_sendcmd(CMD_sync);
360 if (!dt_waitbit(STAT_cmd_ready))
362 else if (dt_stat&0x8000)
364 else if (dt_stat == 0x0dec)
365 pr_warn("dec_pc at 0x%x, software not loaded\n",
366 speakup_info.port_tts);
368 oops: synth_release_region(speakup_info.port_tts, SYNTH_IO_EXTENT);
369 speakup_info.port_tts = 0;
373 static void do_catch_up(struct spk_synth *synth)
378 unsigned long jiff_max;
379 struct var_t *jiffy_delta;
380 struct var_t *delay_time;
384 jiffy_delta = spk_get_var(JIFFY);
385 delay_time = spk_get_var(DELAY);
386 spin_lock_irqsave(&speakup_info.spinlock, flags);
387 jiffy_delta_val = jiffy_delta->u.n.value;
388 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
389 jiff_max = jiffies + jiffy_delta_val;
391 while (!kthread_should_stop()) {
392 spin_lock_irqsave(&speakup_info.spinlock, flags);
393 if (speakup_info.flushing) {
394 speakup_info.flushing = 0;
395 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
399 if (synth_buffer_empty()) {
400 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
403 ch = synth_buffer_peek();
404 set_current_state(TASK_INTERRUPTIBLE);
405 delay_time_val = delay_time->u.n.value;
406 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
409 if (dt_sendchar(ch)) {
410 schedule_timeout(msecs_to_jiffies(delay_time_val));
413 set_current_state(TASK_RUNNING);
414 spin_lock_irqsave(&speakup_info.spinlock, flags);
416 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
421 else if (ch <= SPACE) {
422 if (!in_escape && strchr(",.!?;:", last))
423 dt_sendchar(PROCSPEECH);
424 if (time_after_eq(jiffies, jiff_max)) {
426 dt_sendchar(PROCSPEECH);
427 spin_lock_irqsave(&speakup_info.spinlock,
429 jiffy_delta_val = jiffy_delta->u.n.value;
430 delay_time_val = delay_time->u.n.value;
431 spin_unlock_irqrestore(&speakup_info.spinlock,
433 schedule_timeout(msecs_to_jiffies
435 jiff_max = jiffies + jiffy_delta_val;
442 dt_sendchar(PROCSPEECH);
445 static const char *synth_immediate(struct spk_synth *synth, const char *buf)
449 while ((ch = *buf)) {
459 static int synth_probe(struct spk_synth *synth)
461 int i = 0, failed = 0;
463 pr_info("Probing for %s.\n", synth->long_name);
464 for (i = 0; synth_portlist[i]; i++) {
465 if (synth_request_region(synth_portlist[i], SYNTH_IO_EXTENT)) {
466 pr_warn("request_region: failed with 0x%x, %d\n",
467 synth_portlist[i], SYNTH_IO_EXTENT);
470 speakup_info.port_tts = synth_portlist[i];
471 failed = testkernel();
476 pr_info("%s: not found\n", synth->long_name);
479 pr_info("%s: %03x-%03x, Driver Version %s,\n", synth->long_name,
480 speakup_info.port_tts, speakup_info.port_tts + 7,
486 static void dtpc_release(void)
488 if (speakup_info.port_tts)
489 synth_release_region(speakup_info.port_tts, SYNTH_IO_EXTENT);
490 speakup_info.port_tts = 0;
493 module_param_named(start, synth_dec_pc.startup, short, S_IRUGO);
495 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
497 module_spk_synth(synth_dec_pc);
499 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
500 MODULE_AUTHOR("David Borowski");
501 MODULE_DESCRIPTION("Speakup support for DECtalk PC synthesizers");
502 MODULE_LICENSE("GPL");
503 MODULE_VERSION(DRV_VERSION);