Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / staging / speakup / speakup_audptr.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  * 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  * specificly written as a driver for the speakup screenreview
23  * s not a general device driver.
24  */
25 #include "spk_priv.h"
26 #include "speakup.h"
27 #include "serialio.h"
28
29 #define DRV_VERSION "2.11"
30 #define SYNTH_CLEAR 0x18 /* flush synth buffer */
31 #define PROCSPEECH '\r' /* start synth processing speech char */
32
33 static int synth_probe(struct spk_synth *synth);
34 static void synth_flush(struct spk_synth *synth);
35
36 static struct var_t vars[] = {
37         { CAPS_START, .u.s = {"\x05[f99]" } },
38         { CAPS_STOP, .u.s = {"\x05[f80]" } },
39         { RATE, .u.n = {"\x05[r%d]", 10, 0, 20, 100, -10, NULL } },
40         { PITCH, .u.n = {"\x05[f%d]", 80, 39, 4500, 0, 0, NULL } },
41         { VOL, .u.n = {"\x05[g%d]", 21, 0, 40, 0, 0, NULL } },
42         { TONE, .u.n = {"\x05[s%d]", 9, 0, 63, 0, 0, NULL } },
43         { PUNCT, .u.n = {"\x05[A%c]", 0, 0, 3, 0, 0, "nmsa" } },
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/audptr.
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 pitch_attribute =
56         __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
57 static struct kobj_attribute punct_attribute =
58         __ATTR(punct, 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 tone_attribute =
62         __ATTR(tone, 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         &pitch_attribute.attr,
85         &punct_attribute.attr,
86         &rate_attribute.attr,
87         &tone_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_audptr = {
98         .name = "audptr",
99         .version = DRV_VERSION,
100         .long_name = "Audapter",
101         .init = "\x05[D1]\x05[Ol]",
102         .procspeech = PROCSPEECH,
103         .clear = SYNTH_CLEAR,
104         .delay = 400,
105         .trigger = 50,
106         .jiffies = 30,
107         .full = 18000,
108         .startup = SYNTH_START,
109         .checkval = SYNTH_CHECK,
110         .vars = vars,
111         .probe = synth_probe,
112         .release = spk_serial_release,
113         .synth_immediate = spk_synth_immediate,
114         .catch_up = spk_do_catch_up,
115         .flush = 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 = "audptr",
129         },
130 };
131
132 static void synth_flush(struct spk_synth *synth)
133 {
134         int timeout = SPK_XMITR_TIMEOUT;
135
136         while (spk_serial_tx_busy()) {
137                 if (!--timeout)
138                         break;
139                 udelay(1);
140         }
141         outb(SYNTH_CLEAR, speakup_info.port_tts);
142         spk_serial_out(PROCSPEECH);
143 }
144
145 static void synth_version(struct spk_synth *synth)
146 {
147         unsigned char test = 0;
148         char synth_id[40] = "";
149
150         spk_synth_immediate(synth, "\x05[Q]");
151         synth_id[test] = spk_serial_in();
152         if (synth_id[test] == 'A') {
153                 do {
154                         /* read version string from synth */
155                         synth_id[++test] = spk_serial_in();
156                 } while (synth_id[test] != '\n' && test < 32);
157                 synth_id[++test] = 0x00;
158         }
159         if (synth_id[0] == 'A')
160                 pr_info("%s version: %s", synth->long_name, synth_id);
161 }
162
163 static int synth_probe(struct spk_synth *synth)
164 {
165         int failed = 0;
166
167         failed = spk_serial_synth_probe(synth);
168         if (failed == 0)
169                 synth_version(synth);
170         synth->alive = !failed;
171         return 0;
172 }
173
174 module_param_named(ser, synth_audptr.ser, int, S_IRUGO);
175 module_param_named(start, synth_audptr.startup, short, S_IRUGO);
176
177 MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
178 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
179
180 module_spk_synth(synth_audptr);
181
182 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
183 MODULE_AUTHOR("David Borowski");
184 MODULE_DESCRIPTION("Speakup support for Audapter synthesizer");
185 MODULE_LICENSE("GPL");
186 MODULE_VERSION(DRV_VERSION);
187