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