GNU Linux-libre 4.14.251-gnu1
[releases.git] / 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  * specificly written as a driver for the speakup screenreview
19  * s not a general device driver.
20  */
21 #include "spk_priv.h"
22 #include "speakup.h"
23
24 #define DRV_VERSION "2.11"
25 #define SYNTH_CLEAR 0x18 /* flush synth buffer */
26 #define PROCSPEECH '\r' /* start synth processing speech char */
27
28 static int synth_probe(struct spk_synth *synth);
29 static void synth_flush(struct spk_synth *synth);
30
31 static struct var_t vars[] = {
32         { CAPS_START, .u.s = {"\x05[f99]" } },
33         { CAPS_STOP, .u.s = {"\x05[f80]" } },
34         { RATE, .u.n = {"\x05[r%d]", 10, 0, 20, 100, -10, NULL } },
35         { PITCH, .u.n = {"\x05[f%d]", 80, 39, 4500, 0, 0, NULL } },
36         { VOL, .u.n = {"\x05[g%d]", 21, 0, 40, 0, 0, NULL } },
37         { TONE, .u.n = {"\x05[s%d]", 9, 0, 63, 0, 0, NULL } },
38         { PUNCT, .u.n = {"\x05[A%c]", 0, 0, 3, 0, 0, "nmsa" } },
39         { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
40         V_LAST_VAR
41 };
42
43 /*
44  * These attributes will appear in /sys/accessibility/speakup/audptr.
45  */
46 static struct kobj_attribute caps_start_attribute =
47         __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
48 static struct kobj_attribute caps_stop_attribute =
49         __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
50 static struct kobj_attribute pitch_attribute =
51         __ATTR(pitch, 0644, spk_var_show, spk_var_store);
52 static struct kobj_attribute punct_attribute =
53         __ATTR(punct, 0644, spk_var_show, spk_var_store);
54 static struct kobj_attribute rate_attribute =
55         __ATTR(rate, 0644, spk_var_show, spk_var_store);
56 static struct kobj_attribute tone_attribute =
57         __ATTR(tone, 0644, spk_var_show, spk_var_store);
58 static struct kobj_attribute vol_attribute =
59         __ATTR(vol, 0644, spk_var_show, spk_var_store);
60
61 static struct kobj_attribute delay_time_attribute =
62         __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
63 static struct kobj_attribute direct_attribute =
64         __ATTR(direct, 0644, spk_var_show, spk_var_store);
65 static struct kobj_attribute full_time_attribute =
66         __ATTR(full_time, 0644, spk_var_show, spk_var_store);
67 static struct kobj_attribute jiffy_delta_attribute =
68         __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
69 static struct kobj_attribute trigger_time_attribute =
70         __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
71
72 /*
73  * Create a group of attributes so that we can create and destroy them all
74  * at once.
75  */
76 static struct attribute *synth_attrs[] = {
77         &caps_start_attribute.attr,
78         &caps_stop_attribute.attr,
79         &pitch_attribute.attr,
80         &punct_attribute.attr,
81         &rate_attribute.attr,
82         &tone_attribute.attr,
83         &vol_attribute.attr,
84         &delay_time_attribute.attr,
85         &direct_attribute.attr,
86         &full_time_attribute.attr,
87         &jiffy_delta_attribute.attr,
88         &trigger_time_attribute.attr,
89         NULL,   /* need to NULL terminate the list of attributes */
90 };
91
92 static struct spk_synth synth_audptr = {
93         .name = "audptr",
94         .version = DRV_VERSION,
95         .long_name = "Audapter",
96         .init = "\x05[D1]\x05[Ol]",
97         .procspeech = PROCSPEECH,
98         .clear = SYNTH_CLEAR,
99         .delay = 400,
100         .trigger = 50,
101         .jiffies = 30,
102         .full = 18000,
103         .dev_name = SYNTH_DEFAULT_DEV,
104         .startup = SYNTH_START,
105         .checkval = SYNTH_CHECK,
106         .vars = vars,
107         .io_ops = &spk_ttyio_ops,
108         .probe = synth_probe,
109         .release = spk_ttyio_release,
110         .synth_immediate = spk_ttyio_synth_immediate,
111         .catch_up = spk_do_catch_up,
112         .flush = synth_flush,
113         .is_alive = spk_synth_is_alive_restart,
114         .synth_adjust = NULL,
115         .read_buff_add = NULL,
116         .get_index = NULL,
117         .indexing = {
118                 .command = NULL,
119                 .lowindex = 0,
120                 .highindex = 0,
121                 .currindex = 0,
122         },
123         .attributes = {
124                 .attrs = synth_attrs,
125                 .name = "audptr",
126         },
127 };
128
129 static void synth_flush(struct spk_synth *synth)
130 {
131         synth->io_ops->flush_buffer();
132         synth->io_ops->send_xchar(SYNTH_CLEAR);
133         synth->io_ops->synth_out(synth, PROCSPEECH);
134 }
135
136 static void synth_version(struct spk_synth *synth)
137 {
138         unsigned char test = 0;
139         char synth_id[40] = "";
140
141         synth->synth_immediate(synth, "\x05[Q]");
142         synth_id[test] = synth->io_ops->synth_in();
143         if (synth_id[test] == 'A') {
144                 do {
145                         /* read version string from synth */
146                         synth_id[++test] = synth->io_ops->synth_in();
147                 } while (synth_id[test] != '\n' && test < 32);
148                 synth_id[++test] = 0x00;
149         }
150         if (synth_id[0] == 'A')
151                 pr_info("%s version: %s", synth->long_name, synth_id);
152 }
153
154 static int synth_probe(struct spk_synth *synth)
155 {
156         int failed;
157
158         failed = spk_ttyio_synth_probe(synth);
159         if (failed == 0)
160                 synth_version(synth);
161         synth->alive = !failed;
162         return 0;
163 }
164
165 module_param_named(ser, synth_audptr.ser, int, 0444);
166 module_param_named(dev, synth_audptr.dev_name, charp, S_IRUGO);
167 module_param_named(start, synth_audptr.startup, short, 0444);
168
169 MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
170 MODULE_PARM_DESC(dev, "Set the device e.g. ttyUSB0, for the synthesizer.");
171 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
172
173 module_spk_synth(synth_audptr);
174
175 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
176 MODULE_AUTHOR("David Borowski");
177 MODULE_DESCRIPTION("Speakup support for Audapter synthesizer");
178 MODULE_LICENSE("GPL");
179 MODULE_VERSION(DRV_VERSION);
180