Merge tag 'xfs-for-linus-4.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[deliverable/linux.git] / drivers / staging / speakup / speakup_apollo.c
1 /*
2 * originally 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 * this code is specificly written as a driver for the speakup screenreview
19 * package and is not a general device driver.
20 */
21 #include <linux/jiffies.h>
22 #include <linux/sched.h>
23 #include <linux/timer.h>
24 #include <linux/kthread.h>
25
26 #include "spk_priv.h"
27 #include "serialio.h"
28 #include "speakup.h"
29
30 #define DRV_VERSION "2.21"
31 #define SYNTH_CLEAR 0x18
32 #define PROCSPEECH '\r'
33
34 static void do_catch_up(struct spk_synth *synth);
35
36 static struct var_t vars[] = {
37 { CAPS_START, .u.s = {"cap, " } },
38 { CAPS_STOP, .u.s = {"" } },
39 { RATE, .u.n = {"@W%d", 6, 1, 9, 0, 0, NULL } },
40 { PITCH, .u.n = {"@F%x", 10, 0, 15, 0, 0, NULL } },
41 { VOL, .u.n = {"@A%x", 10, 0, 15, 0, 0, NULL } },
42 { VOICE, .u.n = {"@V%d", 1, 1, 6, 0, 0, NULL } },
43 { LANG, .u.n = {"@=%d,", 1, 1, 4, 0, 0, NULL } },
44 { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
45 V_LAST_VAR
46 };
47
48 /*
49 * These attributes will appear in /sys/accessibility/speakup/apollo.
50 */
51 static struct kobj_attribute caps_start_attribute =
52 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
53 static struct kobj_attribute caps_stop_attribute =
54 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
55 static struct kobj_attribute lang_attribute =
56 __ATTR(lang, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
57 static struct kobj_attribute pitch_attribute =
58 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
59 static struct kobj_attribute rate_attribute =
60 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
61 static struct kobj_attribute voice_attribute =
62 __ATTR(voice, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
63 static struct kobj_attribute vol_attribute =
64 __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
65
66 static struct kobj_attribute delay_time_attribute =
67 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
68 static struct kobj_attribute direct_attribute =
69 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
70 static struct kobj_attribute full_time_attribute =
71 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
72 static struct kobj_attribute jiffy_delta_attribute =
73 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
74 static struct kobj_attribute trigger_time_attribute =
75 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
76
77 /*
78 * Create a group of attributes so that we can create and destroy them all
79 * at once.
80 */
81 static struct attribute *synth_attrs[] = {
82 &caps_start_attribute.attr,
83 &caps_stop_attribute.attr,
84 &lang_attribute.attr,
85 &pitch_attribute.attr,
86 &rate_attribute.attr,
87 &voice_attribute.attr,
88 &vol_attribute.attr,
89 &delay_time_attribute.attr,
90 &direct_attribute.attr,
91 &full_time_attribute.attr,
92 &jiffy_delta_attribute.attr,
93 &trigger_time_attribute.attr,
94 NULL, /* need to NULL terminate the list of attributes */
95 };
96
97 static struct spk_synth synth_apollo = {
98 .name = "apollo",
99 .version = DRV_VERSION,
100 .long_name = "Apollo",
101 .init = "@R3@D0@K1\r",
102 .procspeech = PROCSPEECH,
103 .clear = SYNTH_CLEAR,
104 .delay = 500,
105 .trigger = 50,
106 .jiffies = 50,
107 .full = 40000,
108 .startup = SYNTH_START,
109 .checkval = SYNTH_CHECK,
110 .vars = vars,
111 .probe = spk_serial_synth_probe,
112 .release = spk_serial_release,
113 .synth_immediate = spk_synth_immediate,
114 .catch_up = do_catch_up,
115 .flush = spk_synth_flush,
116 .is_alive = spk_synth_is_alive_restart,
117 .synth_adjust = NULL,
118 .read_buff_add = NULL,
119 .get_index = NULL,
120 .indexing = {
121 .command = NULL,
122 .lowindex = 0,
123 .highindex = 0,
124 .currindex = 0,
125 },
126 .attributes = {
127 .attrs = synth_attrs,
128 .name = "apollo",
129 },
130 };
131
132 static void do_catch_up(struct spk_synth *synth)
133 {
134 u_char ch;
135 unsigned long flags;
136 unsigned long jiff_max;
137 struct var_t *jiffy_delta;
138 struct var_t *delay_time;
139 struct var_t *full_time;
140 int full_time_val = 0;
141 int delay_time_val = 0;
142 int jiffy_delta_val = 0;
143
144 jiffy_delta = spk_get_var(JIFFY);
145 delay_time = spk_get_var(DELAY);
146 full_time = spk_get_var(FULL);
147 spin_lock_irqsave(&speakup_info.spinlock, flags);
148 jiffy_delta_val = jiffy_delta->u.n.value;
149 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
150 jiff_max = jiffies + jiffy_delta_val;
151
152 while (!kthread_should_stop()) {
153 spin_lock_irqsave(&speakup_info.spinlock, flags);
154 jiffy_delta_val = jiffy_delta->u.n.value;
155 full_time_val = full_time->u.n.value;
156 delay_time_val = delay_time->u.n.value;
157 if (speakup_info.flushing) {
158 speakup_info.flushing = 0;
159 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
160 synth->flush(synth);
161 continue;
162 }
163 if (synth_buffer_empty()) {
164 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
165 break;
166 }
167 ch = synth_buffer_peek();
168 set_current_state(TASK_INTERRUPTIBLE);
169 full_time_val = full_time->u.n.value;
170 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
171 if (!spk_serial_out(ch)) {
172 outb(UART_MCR_DTR, speakup_info.port_tts + UART_MCR);
173 outb(UART_MCR_DTR | UART_MCR_RTS,
174 speakup_info.port_tts + UART_MCR);
175 schedule_timeout(msecs_to_jiffies(full_time_val));
176 continue;
177 }
178 if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) {
179 spin_lock_irqsave(&speakup_info.spinlock, flags);
180 jiffy_delta_val = jiffy_delta->u.n.value;
181 full_time_val = full_time->u.n.value;
182 delay_time_val = delay_time->u.n.value;
183 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
184 if (spk_serial_out(synth->procspeech))
185 schedule_timeout(msecs_to_jiffies
186 (delay_time_val));
187 else
188 schedule_timeout(msecs_to_jiffies
189 (full_time_val));
190 jiff_max = jiffies + jiffy_delta_val;
191 }
192 set_current_state(TASK_RUNNING);
193 spin_lock_irqsave(&speakup_info.spinlock, flags);
194 synth_buffer_getc();
195 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
196 }
197 spk_serial_out(PROCSPEECH);
198 }
199
200 module_param_named(ser, synth_apollo.ser, int, S_IRUGO);
201 module_param_named(start, synth_apollo.startup, short, S_IRUGO);
202
203 MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
204 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
205
206 module_spk_synth(synth_apollo);
207
208 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
209 MODULE_AUTHOR("David Borowski");
210 MODULE_DESCRIPTION("Speakup support for Apollo II synthesizer");
211 MODULE_LICENSE("GPL");
212 MODULE_VERSION(DRV_VERSION);
213
This page took 0.036202 seconds and 5 git commands to generate.