]> Pileus Git - ~andy/linux/blob - drivers/staging/speakup/speakup_acntpc.c
Staging: add speakup to the staging directory
[~andy/linux] / drivers / staging / speakup / speakup_acntpc.c
1 /*
2  * written by: Kirk Reiser <kirk@braille.uwo.ca>
3  * this version considerably modified by David Borowski, david575@rogers.com
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  *
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
21  *
22  * this code is specificly written as a driver for the speakup screenreview
23  * package and is not a general device driver.
24  * This driver is for the Aicom Acent PC internal synthesizer.
25  */
26
27 #include <linux/jiffies.h>
28 #include <linux/sched.h>
29 #include <linux/timer.h>
30 #include <linux/kthread.h>
31
32 #include "spk_priv.h"
33 #include "serialio.h"
34 #include "speakup.h"
35 #include "speakup_acnt.h" /* local header file for Accent values */
36
37 #define DRV_VERSION "2.10"
38 #define synth_readable() (inb_p(synth_port_control) & SYNTH_READABLE)
39 #define synth_writable() (inb_p(synth_port_control) & SYNTH_WRITABLE)
40 #define synth_full() (inb_p(speakup_info.port_tts + UART_RX) == 'F')
41 #define PROCSPEECH '\r'
42
43 static int synth_probe(struct spk_synth *synth);
44 static void accent_release(void);
45 static const char *synth_immediate(struct spk_synth *synth, const char *buf);
46 static void do_catch_up(struct spk_synth *synth);
47 static void synth_flush(struct spk_synth *synth);
48
49 static int synth_port_control;
50 static int port_forced;
51 static unsigned int synth_portlist[] = { 0x2a8, 0 };
52
53 static struct var_t vars[] = {
54         { CAPS_START, .u.s = {"\033P8" }},
55         { CAPS_STOP, .u.s = {"\033P5" }},
56         { RATE, .u.n = {"\033R%c", 9, 0, 17, 0, 0, "0123456789abcdefgh" }},
57         { PITCH, .u.n = {"\033P%d", 5, 0, 9, 0, 0, NULL }},
58         { VOL, .u.n = {"\033A%d", 5, 0, 9, 0, 0, NULL }},
59         { TONE, .u.n = {"\033V%d", 5, 0, 9, 0, 0, NULL }},
60         { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL }},
61         V_LAST_VAR
62 };
63
64 /*
65  * These attributes will appear in /sys/accessibility/speakup/acntpc.
66  */
67 static struct kobj_attribute caps_start_attribute =
68         __ATTR(caps_start, USER_RW, spk_var_show, spk_var_store);
69 static struct kobj_attribute caps_stop_attribute =
70         __ATTR(caps_stop, USER_RW, spk_var_show, spk_var_store);
71 static struct kobj_attribute pitch_attribute =
72         __ATTR(pitch, USER_RW, spk_var_show, spk_var_store);
73 static struct kobj_attribute rate_attribute =
74         __ATTR(rate, USER_RW, spk_var_show, spk_var_store);
75 static struct kobj_attribute tone_attribute =
76         __ATTR(tone, USER_RW, spk_var_show, spk_var_store);
77 static struct kobj_attribute vol_attribute =
78         __ATTR(vol, USER_RW, spk_var_show, spk_var_store);
79
80 static struct kobj_attribute delay_time_attribute =
81         __ATTR(delay_time, ROOT_W, spk_var_show, spk_var_store);
82 static struct kobj_attribute direct_attribute =
83         __ATTR(direct, USER_RW, spk_var_show, spk_var_store);
84 static struct kobj_attribute full_time_attribute =
85         __ATTR(full_time, ROOT_W, spk_var_show, spk_var_store);
86 static struct kobj_attribute jiffy_delta_attribute =
87         __ATTR(jiffy_delta, ROOT_W, spk_var_show, spk_var_store);
88 static struct kobj_attribute trigger_time_attribute =
89         __ATTR(trigger_time, ROOT_W, spk_var_show, spk_var_store);
90
91 /*
92  * Create a group of attributes so that we can create and destroy them all
93  * at once.
94  */
95 static struct attribute *synth_attrs[] = {
96         &caps_start_attribute.attr,
97         &caps_stop_attribute.attr,
98         &pitch_attribute.attr,
99         &rate_attribute.attr,
100         &tone_attribute.attr,
101         &vol_attribute.attr,
102         &delay_time_attribute.attr,
103         &direct_attribute.attr,
104         &full_time_attribute.attr,
105         &jiffy_delta_attribute.attr,
106         &trigger_time_attribute.attr,
107         NULL,   /* need to NULL terminate the list of attributes */
108 };
109
110 static struct spk_synth synth_acntpc = {
111         .name = "acntpc",
112         .version = DRV_VERSION,
113         .long_name = "Accent PC",
114         .init = "\033=X \033Oi\033T2\033=M\033N1\n",
115         .procspeech = PROCSPEECH,
116         .clear = SYNTH_CLEAR,
117         .delay = 500,
118         .trigger = 50,
119         .jiffies = 50,
120         .full = 1000,
121         .startup = SYNTH_START,
122         .checkval = SYNTH_CHECK,
123         .vars = vars,
124         .probe = synth_probe,
125         .release = accent_release,
126         .synth_immediate = synth_immediate,
127         .catch_up = do_catch_up,
128         .flush = synth_flush,
129         .is_alive = spk_synth_is_alive_nop,
130         .synth_adjust = NULL,
131         .read_buff_add = NULL,
132         .get_index = NULL,
133         .indexing = {
134                 .command = NULL,
135                 .lowindex = 0,
136                 .highindex = 0,
137                 .currindex = 0,
138         },
139         .attributes = {
140                 .attrs = synth_attrs,
141                 .name = "acntpc",
142         },
143 };
144
145 static const char *synth_immediate(struct spk_synth *synth, const char *buf)
146 {
147         u_char ch;
148         while ((ch = *buf)) {
149                 int timeout = SPK_XMITR_TIMEOUT;
150                 if (ch == '\n')
151                         ch = PROCSPEECH;
152                 if (synth_full())
153                         return buf;
154                 while (synth_writable()) {
155                         if (!--timeout)
156                                 return buf;
157                         udelay(1);
158                 }
159                 outb_p(ch, speakup_info.port_tts);
160                 buf++;
161         }
162         return 0;
163 }
164
165 static void do_catch_up(struct spk_synth *synth)
166 {
167         u_char ch;
168         unsigned long flags;
169         unsigned long jiff_max;
170         int timeout;
171         int delay_time_val;
172         int jiffy_delta_val;
173         int full_time_val;
174         struct var_t *delay_time;
175         struct var_t *full_time;
176         struct var_t *jiffy_delta;
177
178         jiffy_delta = get_var(JIFFY);
179         delay_time = get_var(DELAY);
180         full_time = get_var(FULL);
181
182         spk_lock(flags);
183         jiffy_delta_val = jiffy_delta->u.n.value;
184         spk_unlock(flags);
185
186         jiff_max = jiffies + jiffy_delta_val;
187         while (!kthread_should_stop()) {
188                 spk_lock(flags);
189                 if (speakup_info.flushing) {
190                         speakup_info.flushing = 0;
191                         spk_unlock(flags);
192                         synth->flush(synth);
193                         continue;
194                 }
195                 if (synth_buffer_empty()) {
196                         spk_unlock(flags);
197                         break;
198                 }
199                 set_current_state(TASK_INTERRUPTIBLE);
200                 full_time_val = full_time->u.n.value;
201                 spk_unlock(flags);
202                 if (synth_full()) {
203                         schedule_timeout(msecs_to_jiffies(full_time_val));
204                         continue;
205                 }
206                 set_current_state(TASK_RUNNING);
207                 timeout = SPK_XMITR_TIMEOUT;
208                 while (synth_writable()) {
209                         if (!--timeout)
210                                 break;
211                         udelay(1);
212                 }
213                 spk_lock(flags);
214                 ch = synth_buffer_getc();
215                 spk_unlock(flags);
216                 if (ch == '\n')
217                         ch = PROCSPEECH;
218                 outb_p(ch, speakup_info.port_tts);
219                 if (jiffies >= jiff_max && ch == SPACE) {
220                         timeout = SPK_XMITR_TIMEOUT;
221                         while (synth_writable()) {
222                                 if (!--timeout)
223                                         break;
224                                 udelay(1);
225                         }
226                         outb_p(PROCSPEECH, speakup_info.port_tts);
227                         spk_lock(flags);
228                         jiffy_delta_val = jiffy_delta->u.n.value;
229                         delay_time_val = delay_time->u.n.value;
230                         spk_unlock(flags);
231                         schedule_timeout(msecs_to_jiffies(delay_time_val));
232                         jiff_max = jiffies+jiffy_delta_val;
233                 }
234         }
235         timeout = SPK_XMITR_TIMEOUT;
236         while (synth_writable()) {
237                 if (!--timeout)
238                         break;
239                 udelay(1);
240         }
241         outb_p(PROCSPEECH, speakup_info.port_tts);
242 }
243
244 static void synth_flush(struct spk_synth *synth)
245 {
246         outb_p(SYNTH_CLEAR, speakup_info.port_tts);
247 }
248
249 static int synth_probe(struct spk_synth *synth)
250 {
251         unsigned int port_val = 0;
252         int i = 0;
253         pr_info("Probing for %s.\n", synth->long_name);
254         if (port_forced) {
255                 speakup_info.port_tts = port_forced;
256                 pr_info("probe forced to %x by kernel command line\n",
257                                 speakup_info.port_tts);
258                 if (synth_request_region(speakup_info.port_tts-1,
259                                         SYNTH_IO_EXTENT)) {
260                         pr_warn("sorry, port already reserved\n");
261                         return -EBUSY;
262                 }
263                 port_val = inw(speakup_info.port_tts-1);
264                 synth_port_control = speakup_info.port_tts-1;
265         } else {
266                 for (i = 0; synth_portlist[i]; i++) {
267                         if (synth_request_region(synth_portlist[i],
268                                                 SYNTH_IO_EXTENT)) {
269                                 pr_warn("request_region: failed with 0x%x, %d\n",
270                                         synth_portlist[i], SYNTH_IO_EXTENT);
271                                 continue;
272                         }
273                         port_val = inw(synth_portlist[i]) & 0xfffc;
274                         if (port_val == 0x53fc) {
275                                 /* 'S' and out&input bits */
276                                 synth_port_control = synth_portlist[i];
277                                 speakup_info.port_tts = synth_port_control+1;
278                                 break;
279                         }
280                 }
281         }
282         port_val &= 0xfffc;
283         if (port_val != 0x53fc) {
284                 /* 'S' and out&input bits */
285                 pr_info("%s: not found\n", synth->long_name);
286                 synth_release_region(synth_port_control, SYNTH_IO_EXTENT);
287                 synth_port_control = 0;
288                 return -ENODEV;
289         }
290         pr_info("%s: %03x-%03x, driver version %s,\n", synth->long_name,
291                 synth_port_control, synth_port_control+SYNTH_IO_EXTENT-1,
292                 synth->version);
293         synth->alive = 1;
294         return 0;
295 }
296
297 static void accent_release(void)
298 {
299         if (speakup_info.port_tts)
300                 synth_release_region(speakup_info.port_tts-1, SYNTH_IO_EXTENT);
301         speakup_info.port_tts = 0;
302 }
303
304 module_param_named(port, port_forced, int, S_IRUGO);
305 module_param_named(start, synth_acntpc.startup, short, S_IRUGO);
306
307 MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
308 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
309
310 static int __init acntpc_init(void)
311 {
312         return synth_add(&synth_acntpc);
313 }
314
315 static void __exit acntpc_exit(void)
316 {
317         synth_remove(&synth_acntpc);
318 }
319
320 module_init(acntpc_init);
321 module_exit(acntpc_exit);
322 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
323 MODULE_AUTHOR("David Borowski");
324 MODULE_DESCRIPTION("Speakup support for Accent PC synthesizer");
325 MODULE_LICENSE("GPL");
326 MODULE_VERSION(DRV_VERSION);
327