Loading...
1#include <linux/types.h>
2#include <linux/ctype.h> /* for isdigit() and friends */
3#include <linux/fs.h>
4#include <linux/mm.h> /* for verify_area */
5#include <linux/errno.h> /* for -EBUSY */
6#include <linux/ioport.h> /* for check_region, request_region */
7#include <linux/interrupt.h>
8#include <linux/delay.h> /* for loops_per_sec */
9#include <linux/kmod.h>
10#include <linux/jiffies.h>
11#include <linux/uaccess.h> /* for copy_from_user */
12#include <linux/sched.h>
13#include <linux/timer.h>
14#include <linux/kthread.h>
15
16#include "spk_priv.h"
17#include "speakup.h"
18#include "serialio.h"
19
20#define MAXSYNTHS 16 /* Max number of synths in array. */
21static struct spk_synth *synths[MAXSYNTHS];
22struct spk_synth *synth;
23char pitch_buff[32] = "";
24static int module_status;
25int quiet_boot;
26
27struct speakup_info_t speakup_info = {
28 .spinlock = __SPIN_LOCK_UNLOCKED(speakup_info.spinlock),
29 .flushing = 0,
30};
31EXPORT_SYMBOL_GPL(speakup_info);
32
33static int do_synth_init(struct spk_synth *in_synth);
34
35int serial_synth_probe(struct spk_synth *synth)
36{
37 struct serial_state *ser;
38 int failed = 0;
39
40 if ((synth->ser >= SPK_LO_TTY) && (synth->ser <= SPK_HI_TTY)) {
41 ser = spk_serial_init(synth->ser);
42 if (ser == NULL) {
43 failed = -1;
44 } else {
45 outb_p(0, ser->port);
46 mdelay(1);
47 outb_p('\r', ser->port);
48 }
49 } else {
50 failed = -1;
51 pr_warn("ttyS%i is an invalid port\n", synth->ser);
52 }
53 if (failed) {
54 pr_info("%s: not found\n", synth->long_name);
55 return -ENODEV;
56 }
57 pr_info("%s: ttyS%i, Driver Version %s\n",
58 synth->long_name, synth->ser, synth->version);
59 synth->alive = 1;
60 return 0;
61}
62EXPORT_SYMBOL_GPL(serial_synth_probe);
63
64/* Main loop of the progression thread: keep eating from the buffer
65 * and push to the serial port, waiting as needed
66 *
67 * For devices that have a "full" notification mecanism, the driver can
68 * adapt the loop the way they prefer.
69 */
70void spk_do_catch_up(struct spk_synth *synth)
71{
72 u_char ch;
73 unsigned long flags;
74 unsigned long jiff_max;
75 struct var_t *delay_time;
76 struct var_t *full_time;
77 struct var_t *jiffy_delta;
78 int jiffy_delta_val;
79 int delay_time_val;
80 int full_time_val;
81
82 jiffy_delta = get_var(JIFFY);
83 full_time = get_var(FULL);
84 delay_time = get_var(DELAY);
85
86 spk_lock(flags);
87 jiffy_delta_val = jiffy_delta->u.n.value;
88 spk_unlock(flags);
89
90 jiff_max = jiffies + jiffy_delta_val;
91 while (!kthread_should_stop()) {
92 spk_lock(flags);
93 if (speakup_info.flushing) {
94 speakup_info.flushing = 0;
95 spk_unlock(flags);
96 synth->flush(synth);
97 continue;
98 }
99 if (synth_buffer_empty()) {
100 spk_unlock(flags);
101 break;
102 }
103 ch = synth_buffer_peek();
104 set_current_state(TASK_INTERRUPTIBLE);
105 full_time_val = full_time->u.n.value;
106 spk_unlock(flags);
107 if (ch == '\n')
108 ch = synth->procspeech;
109 if (!spk_serial_out(ch)) {
110 schedule_timeout(msecs_to_jiffies(full_time_val));
111 continue;
112 }
113 if ((jiffies >= jiff_max) && (ch == SPACE)) {
114 spk_lock(flags);
115 jiffy_delta_val = jiffy_delta->u.n.value;
116 delay_time_val = delay_time->u.n.value;
117 full_time_val = full_time->u.n.value;
118 spk_unlock(flags);
119 if (spk_serial_out(synth->procspeech))
120 schedule_timeout(
121 msecs_to_jiffies(delay_time_val));
122 else
123 schedule_timeout(
124 msecs_to_jiffies(full_time_val));
125 jiff_max = jiffies + jiffy_delta_val;
126 }
127 set_current_state(TASK_RUNNING);
128 spk_lock(flags);
129 synth_buffer_getc();
130 spk_unlock(flags);
131 }
132 spk_serial_out(synth->procspeech);
133}
134EXPORT_SYMBOL_GPL(spk_do_catch_up);
135
136const char *spk_synth_immediate(struct spk_synth *synth, const char *buff)
137{
138 u_char ch;
139 while ((ch = *buff)) {
140 if (ch == '\n')
141 ch = synth->procspeech;
142 if (wait_for_xmitr())
143 outb(ch, speakup_info.port_tts);
144 else
145 return buff;
146 buff++;
147 }
148 return 0;
149}
150EXPORT_SYMBOL_GPL(spk_synth_immediate);
151
152void spk_synth_flush(struct spk_synth *synth)
153{
154 spk_serial_out(synth->clear);
155}
156EXPORT_SYMBOL_GPL(spk_synth_flush);
157
158int spk_synth_is_alive_nop(struct spk_synth *synth)
159{
160 synth->alive = 1;
161 return 1;
162}
163EXPORT_SYMBOL_GPL(spk_synth_is_alive_nop);
164
165int spk_synth_is_alive_restart(struct spk_synth *synth)
166{
167 if (synth->alive)
168 return 1;
169 if (!synth->alive && wait_for_xmitr() > 0) {
170 /* restart */
171 synth->alive = 1;
172 synth_printf("%s", synth->init);
173 return 2; /* reenabled */
174 }
175 pr_warn("%s: can't restart synth\n", synth->long_name);
176 return 0;
177}
178EXPORT_SYMBOL_GPL(spk_synth_is_alive_restart);
179
180static void thread_wake_up(u_long data)
181{
182 wake_up_interruptible_all(&speakup_event);
183}
184
185static DEFINE_TIMER(thread_timer, thread_wake_up, 0, 0);
186
187void synth_start(void)
188{
189 struct var_t *trigger_time;
190
191 if (!synth->alive) {
192 synth_buffer_clear();
193 return;
194 }
195 trigger_time = get_var(TRIGGER);
196 if (!timer_pending(&thread_timer))
197 mod_timer(&thread_timer, jiffies +
198 msecs_to_jiffies(trigger_time->u.n.value));
199}
200
201void do_flush(void)
202{
203 speakup_info.flushing = 1;
204 synth_buffer_clear();
205 if (synth->alive) {
206 if (pitch_shift) {
207 synth_printf("%s", pitch_buff);
208 pitch_shift = 0;
209 }
210 }
211 wake_up_interruptible_all(&speakup_event);
212 wake_up_process(speakup_task);
213}
214
215void synth_write(const char *buf, size_t count)
216{
217 while (count--)
218 synth_buffer_add(*buf++);
219 synth_start();
220}
221
222void synth_printf(const char *fmt, ...)
223{
224 va_list args;
225 unsigned char buf[160], *p;
226 int r;
227
228 va_start(args, fmt);
229 r = vsnprintf(buf, sizeof(buf), fmt, args);
230 va_end(args);
231 if (r > sizeof(buf) - 1)
232 r = sizeof(buf) - 1;
233
234 p = buf;
235 while (r--)
236 synth_buffer_add(*p++);
237 synth_start();
238}
239EXPORT_SYMBOL_GPL(synth_printf);
240
241static int index_count;
242static int sentence_count;
243
244void reset_index_count(int sc)
245{
246 static int first = 1;
247 if (first)
248 first = 0;
249 else
250 synth->get_index();
251 index_count = 0;
252 sentence_count = sc;
253}
254
255int synth_supports_indexing(void)
256{
257 if (synth->get_index != NULL)
258 return 1;
259 return 0;
260}
261
262void synth_insert_next_index(int sent_num)
263{
264 int out;
265 if (synth->alive) {
266 if (sent_num == 0) {
267 synth->indexing.currindex++;
268 index_count++;
269 if (synth->indexing.currindex >
270 synth->indexing.highindex)
271 synth->indexing.currindex =
272 synth->indexing.lowindex;
273 }
274
275 out = synth->indexing.currindex * 10 + sent_num;
276 synth_printf(synth->indexing.command, out, out);
277 }
278}
279
280void get_index_count(int *linecount, int *sentcount)
281{
282 int ind = synth->get_index();
283 if (ind) {
284 sentence_count = ind % 10;
285
286 if ((ind / 10) <= synth->indexing.currindex)
287 index_count = synth->indexing.currindex-(ind/10);
288 else
289 index_count = synth->indexing.currindex
290 -synth->indexing.lowindex
291 + synth->indexing.highindex-(ind/10)+1;
292
293 }
294 *sentcount = sentence_count;
295 *linecount = index_count;
296}
297
298static struct resource synth_res;
299
300int synth_request_region(unsigned long start, unsigned long n)
301{
302 struct resource *parent = &ioport_resource;
303 memset(&synth_res, 0, sizeof(synth_res));
304 synth_res.name = synth->name;
305 synth_res.start = start;
306 synth_res.end = start + n - 1;
307 synth_res.flags = IORESOURCE_BUSY;
308 return request_resource(parent, &synth_res);
309}
310EXPORT_SYMBOL_GPL(synth_request_region);
311
312int synth_release_region(unsigned long start, unsigned long n)
313{
314 return release_resource(&synth_res);
315}
316EXPORT_SYMBOL_GPL(synth_release_region);
317
318struct var_t synth_time_vars[] = {
319 { DELAY, .u.n = {NULL, 100, 100, 2000, 0, 0, NULL } },
320 { TRIGGER, .u.n = {NULL, 20, 10, 2000, 0, 0, NULL } },
321 { JIFFY, .u.n = {NULL, 50, 20, 200, 0, 0, NULL } },
322 { FULL, .u.n = {NULL, 400, 200, 60000, 0, 0, NULL } },
323 V_LAST_VAR
324};
325
326/* called by: speakup_init() */
327int synth_init(char *synth_name)
328{
329 int i;
330 int ret = 0;
331 struct spk_synth *synth = NULL;
332
333 if (synth_name == NULL)
334 return 0;
335
336 if (strcmp(synth_name, "none") == 0) {
337 mutex_lock(&spk_mutex);
338 synth_release();
339 mutex_unlock(&spk_mutex);
340 return 0;
341 }
342
343 mutex_lock(&spk_mutex);
344 /* First, check if we already have it loaded. */
345 for (i = 0; synths[i] != NULL && i < MAXSYNTHS; i++)
346 if (strcmp(synths[i]->name, synth_name) == 0)
347 synth = synths[i];
348
349 /* If we got one, initialize it now. */
350 if (synth)
351 ret = do_synth_init(synth);
352 else
353 ret = -ENODEV;
354 mutex_unlock(&spk_mutex);
355
356 return ret;
357}
358
359/* called by: synth_add() */
360static int do_synth_init(struct spk_synth *in_synth)
361{
362 struct var_t *var;
363
364 synth_release();
365 if (in_synth->checkval != SYNTH_CHECK)
366 return -EINVAL;
367 synth = in_synth;
368 synth->alive = 0;
369 pr_warn("synth probe\n");
370 if (synth->probe(synth) < 0) {
371 pr_warn("%s: device probe failed\n", in_synth->name);
372 synth = NULL;
373 return -ENODEV;
374 }
375 synth_time_vars[0].u.n.value =
376 synth_time_vars[0].u.n.default_val = synth->delay;
377 synth_time_vars[1].u.n.value =
378 synth_time_vars[1].u.n.default_val = synth->trigger;
379 synth_time_vars[2].u.n.value =
380 synth_time_vars[2].u.n.default_val = synth->jiffies;
381 synth_time_vars[3].u.n.value =
382 synth_time_vars[3].u.n.default_val = synth->full;
383 synth_printf("%s", synth->init);
384 for (var = synth->vars;
385 (var->var_id >= 0) && (var->var_id < MAXVARS); var++)
386 speakup_register_var(var);
387 if (!quiet_boot)
388 synth_printf("%s found\n", synth->long_name);
389 if (synth->attributes.name
390 && sysfs_create_group(speakup_kobj, &(synth->attributes)) < 0)
391 return -ENOMEM;
392 synth_flags = synth->flags;
393 wake_up_interruptible_all(&speakup_event);
394 if (speakup_task)
395 wake_up_process(speakup_task);
396 return 0;
397}
398
399void synth_release(void)
400{
401 struct var_t *var;
402 unsigned long flags;
403
404 if (synth == NULL)
405 return;
406 spk_lock(flags);
407 pr_info("releasing synth %s\n", synth->name);
408 synth->alive = 0;
409 del_timer(&thread_timer);
410 spk_unlock(flags);
411 if (synth->attributes.name)
412 sysfs_remove_group(speakup_kobj, &(synth->attributes));
413 for (var = synth->vars; var->var_id != MAXVARS; var++)
414 speakup_unregister_var(var->var_id);
415 stop_serial_interrupt();
416 synth->release();
417 synth = NULL;
418}
419
420/* called by: all_driver_init() */
421int synth_add(struct spk_synth *in_synth)
422{
423 int i;
424 int status = 0;
425 mutex_lock(&spk_mutex);
426 for (i = 0; synths[i] != NULL && i < MAXSYNTHS; i++)
427 /* synth_remove() is responsible for rotating the array down */
428 if (in_synth == synths[i]) {
429 mutex_unlock(&spk_mutex);
430 return 0;
431 }
432 if (i == MAXSYNTHS) {
433 pr_warn("Error: attempting to add a synth past end of array\n");
434 mutex_unlock(&spk_mutex);
435 return -1;
436 }
437 synths[i++] = in_synth;
438 synths[i] = NULL;
439 if (in_synth->startup)
440 status = do_synth_init(in_synth);
441 mutex_unlock(&spk_mutex);
442 return status;
443}
444EXPORT_SYMBOL_GPL(synth_add);
445
446void synth_remove(struct spk_synth *in_synth)
447{
448 int i;
449 mutex_lock(&spk_mutex);
450 if (synth == in_synth)
451 synth_release();
452 for (i = 0; synths[i] != NULL; i++) {
453 if (in_synth == synths[i])
454 break;
455 }
456 for ( ; synths[i] != NULL; i++) /* compress table */
457 synths[i] = synths[i+1];
458 module_status = 0;
459 mutex_unlock(&spk_mutex);
460}
461EXPORT_SYMBOL_GPL(synth_remove);
462
463short punc_masks[] = { 0, SOME, MOST, PUNC, PUNC|B_SYM };
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/types.h>
3#include <linux/ctype.h> /* for isdigit() and friends */
4#include <linux/fs.h>
5#include <linux/mm.h> /* for verify_area */
6#include <linux/errno.h> /* for -EBUSY */
7#include <linux/ioport.h> /* for check_region, request_region */
8#include <linux/interrupt.h>
9#include <linux/delay.h> /* for loops_per_sec */
10#include <linux/kmod.h>
11#include <linux/jiffies.h>
12#include <linux/uaccess.h> /* for copy_from_user */
13#include <linux/sched.h>
14#include <linux/timer.h>
15#include <linux/kthread.h>
16
17#include "spk_priv.h"
18#include "speakup.h"
19#include "serialio.h"
20
21static LIST_HEAD(synths);
22struct spk_synth *synth;
23char spk_pitch_buff[32] = "";
24static int module_status;
25bool spk_quiet_boot;
26
27struct speakup_info_t speakup_info = {
28 /*
29 * This spinlock is used to protect the entire speakup machinery, and
30 * must be taken at each kernel->speakup transition and released at
31 * each corresponding speakup->kernel transition.
32 *
33 * The progression thread only interferes with the speakup machinery
34 * through the synth buffer, so only needs to take the lock
35 * while tinkering with the buffer.
36 *
37 * We use spin_lock/trylock_irqsave and spin_unlock_irqrestore with this
38 * spinlock because speakup needs to disable the keyboard IRQ.
39 */
40 .spinlock = __SPIN_LOCK_UNLOCKED(speakup_info.spinlock),
41 .flushing = 0,
42};
43EXPORT_SYMBOL_GPL(speakup_info);
44
45static int do_synth_init(struct spk_synth *in_synth);
46
47/*
48 * Main loop of the progression thread: keep eating from the buffer
49 * and push to the serial port, waiting as needed
50 *
51 * For devices that have a "full" notification mechanism, the driver can
52 * adapt the loop the way they prefer.
53 */
54static void _spk_do_catch_up(struct spk_synth *synth, int unicode)
55{
56 u16 ch;
57 unsigned long flags;
58 unsigned long jiff_max;
59 struct var_t *delay_time;
60 struct var_t *full_time;
61 struct var_t *jiffy_delta;
62 int jiffy_delta_val;
63 int delay_time_val;
64 int full_time_val;
65 int ret;
66
67 jiffy_delta = spk_get_var(JIFFY);
68 full_time = spk_get_var(FULL);
69 delay_time = spk_get_var(DELAY);
70
71 spin_lock_irqsave(&speakup_info.spinlock, flags);
72 jiffy_delta_val = jiffy_delta->u.n.value;
73 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
74
75 jiff_max = jiffies + jiffy_delta_val;
76 while (!kthread_should_stop()) {
77 spin_lock_irqsave(&speakup_info.spinlock, flags);
78 if (speakup_info.flushing) {
79 speakup_info.flushing = 0;
80 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
81 synth->flush(synth);
82 continue;
83 }
84 if (!unicode)
85 synth_buffer_skip_nonlatin1();
86 if (synth_buffer_empty()) {
87 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
88 break;
89 }
90 ch = synth_buffer_peek();
91 set_current_state(TASK_INTERRUPTIBLE);
92 full_time_val = full_time->u.n.value;
93 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
94 if (ch == '\n')
95 ch = synth->procspeech;
96 if (unicode)
97 ret = synth->io_ops->synth_out_unicode(synth, ch);
98 else
99 ret = synth->io_ops->synth_out(synth, ch);
100 if (!ret) {
101 schedule_timeout(msecs_to_jiffies(full_time_val));
102 continue;
103 }
104 if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) {
105 spin_lock_irqsave(&speakup_info.spinlock, flags);
106 jiffy_delta_val = jiffy_delta->u.n.value;
107 delay_time_val = delay_time->u.n.value;
108 full_time_val = full_time->u.n.value;
109 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
110 if (synth->io_ops->synth_out(synth, synth->procspeech))
111 schedule_timeout(
112 msecs_to_jiffies(delay_time_val));
113 else
114 schedule_timeout(
115 msecs_to_jiffies(full_time_val));
116 jiff_max = jiffies + jiffy_delta_val;
117 }
118 set_current_state(TASK_RUNNING);
119 spin_lock_irqsave(&speakup_info.spinlock, flags);
120 synth_buffer_getc();
121 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
122 }
123 synth->io_ops->synth_out(synth, synth->procspeech);
124}
125
126void spk_do_catch_up(struct spk_synth *synth)
127{
128 _spk_do_catch_up(synth, 0);
129}
130EXPORT_SYMBOL_GPL(spk_do_catch_up);
131
132void spk_do_catch_up_unicode(struct spk_synth *synth)
133{
134 _spk_do_catch_up(synth, 1);
135}
136EXPORT_SYMBOL_GPL(spk_do_catch_up_unicode);
137
138void spk_synth_flush(struct spk_synth *synth)
139{
140 synth->io_ops->flush_buffer();
141 synth->io_ops->synth_out(synth, synth->clear);
142}
143EXPORT_SYMBOL_GPL(spk_synth_flush);
144
145unsigned char spk_synth_get_index(struct spk_synth *synth)
146{
147 return synth->io_ops->synth_in_nowait();
148}
149EXPORT_SYMBOL_GPL(spk_synth_get_index);
150
151int spk_synth_is_alive_nop(struct spk_synth *synth)
152{
153 synth->alive = 1;
154 return 1;
155}
156EXPORT_SYMBOL_GPL(spk_synth_is_alive_nop);
157
158int spk_synth_is_alive_restart(struct spk_synth *synth)
159{
160 if (synth->alive)
161 return 1;
162 if (spk_wait_for_xmitr(synth) > 0) {
163 /* restart */
164 synth->alive = 1;
165 synth_printf("%s", synth->init);
166 return 2; /* reenabled */
167 }
168 pr_warn("%s: can't restart synth\n", synth->long_name);
169 return 0;
170}
171EXPORT_SYMBOL_GPL(spk_synth_is_alive_restart);
172
173static void thread_wake_up(struct timer_list *unused)
174{
175 wake_up_interruptible_all(&speakup_event);
176}
177
178static DEFINE_TIMER(thread_timer, thread_wake_up);
179
180void synth_start(void)
181{
182 struct var_t *trigger_time;
183
184 if (!synth->alive) {
185 synth_buffer_clear();
186 return;
187 }
188 trigger_time = spk_get_var(TRIGGER);
189 if (!timer_pending(&thread_timer))
190 mod_timer(&thread_timer, jiffies +
191 msecs_to_jiffies(trigger_time->u.n.value));
192}
193
194void spk_do_flush(void)
195{
196 if (!synth)
197 return;
198
199 speakup_info.flushing = 1;
200 synth_buffer_clear();
201 if (synth->alive) {
202 if (spk_pitch_shift) {
203 synth_printf("%s", spk_pitch_buff);
204 spk_pitch_shift = 0;
205 }
206 }
207 wake_up_interruptible_all(&speakup_event);
208 wake_up_process(speakup_task);
209}
210
211void synth_write(const char *buf, size_t count)
212{
213 while (count--)
214 synth_buffer_add(*buf++);
215 synth_start();
216}
217
218void synth_printf(const char *fmt, ...)
219{
220 va_list args;
221 unsigned char buf[160], *p;
222 int r;
223
224 va_start(args, fmt);
225 r = vsnprintf(buf, sizeof(buf), fmt, args);
226 va_end(args);
227 if (r > sizeof(buf) - 1)
228 r = sizeof(buf) - 1;
229
230 p = buf;
231 while (r--)
232 synth_buffer_add(*p++);
233 synth_start();
234}
235EXPORT_SYMBOL_GPL(synth_printf);
236
237void synth_putwc(u16 wc)
238{
239 synth_buffer_add(wc);
240}
241EXPORT_SYMBOL_GPL(synth_putwc);
242
243void synth_putwc_s(u16 wc)
244{
245 synth_buffer_add(wc);
246 synth_start();
247}
248EXPORT_SYMBOL_GPL(synth_putwc_s);
249
250void synth_putws(const u16 *buf)
251{
252 const u16 *p;
253
254 for (p = buf; *p; p++)
255 synth_buffer_add(*p);
256}
257EXPORT_SYMBOL_GPL(synth_putws);
258
259void synth_putws_s(const u16 *buf)
260{
261 synth_putws(buf);
262 synth_start();
263}
264EXPORT_SYMBOL_GPL(synth_putws_s);
265
266static int index_count;
267static int sentence_count;
268
269void spk_reset_index_count(int sc)
270{
271 static int first = 1;
272
273 if (first)
274 first = 0;
275 else
276 synth->get_index(synth);
277 index_count = 0;
278 sentence_count = sc;
279}
280
281int synth_supports_indexing(void)
282{
283 if (synth->get_index)
284 return 1;
285 return 0;
286}
287
288void synth_insert_next_index(int sent_num)
289{
290 int out;
291
292 if (synth->alive) {
293 if (sent_num == 0) {
294 synth->indexing.currindex++;
295 index_count++;
296 if (synth->indexing.currindex >
297 synth->indexing.highindex)
298 synth->indexing.currindex =
299 synth->indexing.lowindex;
300 }
301
302 out = synth->indexing.currindex * 10 + sent_num;
303 synth_printf(synth->indexing.command, out, out);
304 }
305}
306
307void spk_get_index_count(int *linecount, int *sentcount)
308{
309 int ind = synth->get_index(synth);
310
311 if (ind) {
312 sentence_count = ind % 10;
313
314 if ((ind / 10) <= synth->indexing.currindex)
315 index_count = synth->indexing.currindex - (ind / 10);
316 else
317 index_count = synth->indexing.currindex
318 - synth->indexing.lowindex
319 + synth->indexing.highindex - (ind / 10) + 1;
320 }
321 *sentcount = sentence_count;
322 *linecount = index_count;
323}
324
325static struct resource synth_res;
326
327int synth_request_region(unsigned long start, unsigned long n)
328{
329 struct resource *parent = &ioport_resource;
330
331 memset(&synth_res, 0, sizeof(synth_res));
332 synth_res.name = synth->name;
333 synth_res.start = start;
334 synth_res.end = start + n - 1;
335 synth_res.flags = IORESOURCE_BUSY;
336 return request_resource(parent, &synth_res);
337}
338EXPORT_SYMBOL_GPL(synth_request_region);
339
340int synth_release_region(unsigned long start, unsigned long n)
341{
342 return release_resource(&synth_res);
343}
344EXPORT_SYMBOL_GPL(synth_release_region);
345
346struct var_t synth_time_vars[] = {
347 { DELAY, .u.n = {NULL, 100, 100, 2000, 0, 0, NULL } },
348 { TRIGGER, .u.n = {NULL, 20, 10, 2000, 0, 0, NULL } },
349 { JIFFY, .u.n = {NULL, 50, 20, 200, 0, 0, NULL } },
350 { FULL, .u.n = {NULL, 400, 200, 60000, 0, 0, NULL } },
351 V_LAST_VAR
352};
353
354/* called by: speakup_init() */
355int synth_init(char *synth_name)
356{
357 int ret = 0;
358 struct spk_synth *tmp, *synth = NULL;
359
360 if (!synth_name)
361 return 0;
362
363 if (strcmp(synth_name, "none") == 0) {
364 mutex_lock(&spk_mutex);
365 synth_release();
366 mutex_unlock(&spk_mutex);
367 return 0;
368 }
369
370 mutex_lock(&spk_mutex);
371 /* First, check if we already have it loaded. */
372 list_for_each_entry(tmp, &synths, node) {
373 if (strcmp(tmp->name, synth_name) == 0)
374 synth = tmp;
375 }
376
377 /* If we got one, initialize it now. */
378 if (synth)
379 ret = do_synth_init(synth);
380 else
381 ret = -ENODEV;
382 mutex_unlock(&spk_mutex);
383
384 return ret;
385}
386
387/* called by: synth_add() */
388static int do_synth_init(struct spk_synth *in_synth)
389{
390 struct var_t *var;
391
392 synth_release();
393 if (in_synth->checkval != SYNTH_CHECK)
394 return -EINVAL;
395 synth = in_synth;
396 synth->alive = 0;
397 pr_warn("synth probe\n");
398 if (synth->probe(synth) < 0) {
399 pr_warn("%s: device probe failed\n", in_synth->name);
400 synth = NULL;
401 return -ENODEV;
402 }
403 synth_time_vars[0].u.n.value =
404 synth_time_vars[0].u.n.default_val = synth->delay;
405 synth_time_vars[1].u.n.value =
406 synth_time_vars[1].u.n.default_val = synth->trigger;
407 synth_time_vars[2].u.n.value =
408 synth_time_vars[2].u.n.default_val = synth->jiffies;
409 synth_time_vars[3].u.n.value =
410 synth_time_vars[3].u.n.default_val = synth->full;
411 synth_printf("%s", synth->init);
412 for (var = synth->vars;
413 (var->var_id >= 0) && (var->var_id < MAXVARS); var++)
414 speakup_register_var(var);
415 if (!spk_quiet_boot)
416 synth_printf("%s found\n", synth->long_name);
417 if (synth->attributes.name &&
418 sysfs_create_group(speakup_kobj, &synth->attributes) < 0)
419 return -ENOMEM;
420 synth_flags = synth->flags;
421 wake_up_interruptible_all(&speakup_event);
422 if (speakup_task)
423 wake_up_process(speakup_task);
424 return 0;
425}
426
427void synth_release(void)
428{
429 struct var_t *var;
430 unsigned long flags;
431
432 if (!synth)
433 return;
434 spin_lock_irqsave(&speakup_info.spinlock, flags);
435 pr_info("releasing synth %s\n", synth->name);
436 synth->alive = 0;
437 del_timer(&thread_timer);
438 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
439 if (synth->attributes.name)
440 sysfs_remove_group(speakup_kobj, &synth->attributes);
441 for (var = synth->vars; var->var_id != MAXVARS; var++)
442 speakup_unregister_var(var->var_id);
443 synth->release();
444 synth = NULL;
445}
446
447/* called by: all_driver_init() */
448int synth_add(struct spk_synth *in_synth)
449{
450 int status = 0;
451 struct spk_synth *tmp;
452
453 mutex_lock(&spk_mutex);
454
455 list_for_each_entry(tmp, &synths, node) {
456 if (tmp == in_synth) {
457 mutex_unlock(&spk_mutex);
458 return 0;
459 }
460 }
461
462 if (in_synth->startup)
463 status = do_synth_init(in_synth);
464
465 if (!status)
466 list_add_tail(&in_synth->node, &synths);
467
468 mutex_unlock(&spk_mutex);
469 return status;
470}
471EXPORT_SYMBOL_GPL(synth_add);
472
473void synth_remove(struct spk_synth *in_synth)
474{
475 mutex_lock(&spk_mutex);
476 if (synth == in_synth)
477 synth_release();
478 list_del(&in_synth->node);
479 module_status = 0;
480 mutex_unlock(&spk_mutex);
481}
482EXPORT_SYMBOL_GPL(synth_remove);
483
484struct spk_synth *synth_current(void)
485{
486 return synth;
487}
488EXPORT_SYMBOL_GPL(synth_current);
489
490short spk_punc_masks[] = { 0, SOME, MOST, PUNC, PUNC | B_SYM };