GNU Linux-libre 4.14.251-gnu1
[releases.git] / drivers / staging / speakup / speakup_ltlk.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 "speakup.h"
22 #include "spk_priv.h"
23 #include "speakup_dtlk.h" /* local header file for LiteTalk values */
24
25 #define DRV_VERSION "2.11"
26 #define PROCSPEECH 0x0d
27
28 static int synth_probe(struct spk_synth *synth);
29
30 static struct var_t vars[] = {
31         { CAPS_START, .u.s = {"\x01+35p" } },
32         { CAPS_STOP, .u.s = {"\x01-35p" } },
33         { RATE, .u.n = {"\x01%ds", 8, 0, 9, 0, 0, NULL } },
34         { PITCH, .u.n = {"\x01%dp", 50, 0, 99, 0, 0, NULL } },
35         { VOL, .u.n = {"\x01%dv", 5, 0, 9, 0, 0, NULL } },
36         { TONE, .u.n = {"\x01%dx", 1, 0, 2, 0, 0, NULL } },
37         { PUNCT, .u.n = {"\x01%db", 7, 0, 15, 0, 0, NULL } },
38         { VOICE, .u.n = {"\x01%do", 0, 0, 7, 0, 0, NULL } },
39         { FREQUENCY, .u.n = {"\x01%df", 5, 0, 9, 0, 0, NULL } },
40         { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
41         V_LAST_VAR
42 };
43
44 /*
45  * These attributes will appear in /sys/accessibility/speakup/ltlk.
46  */
47 static struct kobj_attribute caps_start_attribute =
48         __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
49 static struct kobj_attribute caps_stop_attribute =
50         __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
51 static struct kobj_attribute freq_attribute =
52         __ATTR(freq, 0644, spk_var_show, spk_var_store);
53 static struct kobj_attribute pitch_attribute =
54         __ATTR(pitch, 0644, spk_var_show, spk_var_store);
55 static struct kobj_attribute punct_attribute =
56         __ATTR(punct, 0644, spk_var_show, spk_var_store);
57 static struct kobj_attribute rate_attribute =
58         __ATTR(rate, 0644, spk_var_show, spk_var_store);
59 static struct kobj_attribute tone_attribute =
60         __ATTR(tone, 0644, spk_var_show, spk_var_store);
61 static struct kobj_attribute voice_attribute =
62         __ATTR(voice, 0644, spk_var_show, spk_var_store);
63 static struct kobj_attribute vol_attribute =
64         __ATTR(vol, 0644, spk_var_show, spk_var_store);
65
66 static struct kobj_attribute delay_time_attribute =
67         __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
68 static struct kobj_attribute direct_attribute =
69         __ATTR(direct, 0644, spk_var_show, spk_var_store);
70 static struct kobj_attribute full_time_attribute =
71         __ATTR(full_time, 0644, spk_var_show, spk_var_store);
72 static struct kobj_attribute jiffy_delta_attribute =
73         __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
74 static struct kobj_attribute trigger_time_attribute =
75         __ATTR(trigger_time, 0644, 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         &freq_attribute.attr,
85         &pitch_attribute.attr,
86         &punct_attribute.attr,
87         &rate_attribute.attr,
88         &tone_attribute.attr,
89         &voice_attribute.attr,
90         &vol_attribute.attr,
91         &delay_time_attribute.attr,
92         &direct_attribute.attr,
93         &full_time_attribute.attr,
94         &jiffy_delta_attribute.attr,
95         &trigger_time_attribute.attr,
96         NULL,   /* need to NULL terminate the list of attributes */
97 };
98
99 static struct spk_synth synth_ltlk = {
100         .name = "ltlk",
101         .version = DRV_VERSION,
102         .long_name = "LiteTalk",
103         .init = "\01@\x01\x31y\n\0",
104         .procspeech = PROCSPEECH,
105         .clear = SYNTH_CLEAR,
106         .delay = 500,
107         .trigger = 50,
108         .jiffies = 50,
109         .full = 40000,
110         .dev_name = SYNTH_DEFAULT_DEV,
111         .startup = SYNTH_START,
112         .checkval = SYNTH_CHECK,
113         .vars = vars,
114         .io_ops = &spk_ttyio_ops,
115         .probe = synth_probe,
116         .release = spk_ttyio_release,
117         .synth_immediate = spk_ttyio_synth_immediate,
118         .catch_up = spk_do_catch_up,
119         .flush = spk_synth_flush,
120         .is_alive = spk_synth_is_alive_restart,
121         .synth_adjust = NULL,
122         .read_buff_add = NULL,
123         .get_index = spk_synth_get_index,
124         .indexing = {
125                 .command = "\x01%di",
126                 .lowindex = 1,
127                 .highindex = 5,
128                 .currindex = 1,
129         },
130         .attributes = {
131                 .attrs = synth_attrs,
132                 .name = "ltlk",
133         },
134 };
135
136 /* interrogate the LiteTalk and print its settings */
137 static void synth_interrogate(struct spk_synth *synth)
138 {
139         unsigned char *t, i;
140         unsigned char buf[50], rom_v[20];
141
142         synth->synth_immediate(synth, "\x18\x01?");
143         for (i = 0; i < 50; i++) {
144                 buf[i] = synth->io_ops->synth_in();
145                 if (i > 2 && buf[i] == 0x7f)
146                         break;
147         }
148         t = buf + 2;
149         for (i = 0; *t != '\r'; t++) {
150                 rom_v[i] = *t;
151                 if (++i >= 19)
152                         break;
153         }
154         rom_v[i] = 0;
155         pr_info("%s: ROM version: %s\n", synth->long_name, rom_v);
156 }
157
158 static int synth_probe(struct spk_synth *synth)
159 {
160         int failed = 0;
161
162         failed = spk_ttyio_synth_probe(synth);
163         if (failed == 0)
164                 synth_interrogate(synth);
165         synth->alive = !failed;
166         return failed;
167 }
168
169 module_param_named(ser, synth_ltlk.ser, int, 0444);
170 module_param_named(dev, synth_ltlk.dev_name, charp, S_IRUGO);
171 module_param_named(start, synth_ltlk.startup, short, 0444);
172
173 MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
174 MODULE_PARM_DESC(dev, "Set the device e.g. ttyUSB0, for the synthesizer.");
175 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
176
177 module_spk_synth(synth_ltlk);
178
179 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
180 MODULE_AUTHOR("David Borowski");
181 MODULE_DESCRIPTION("Speakup support for DoubleTalk LT/LiteTalk synthesizers");
182 MODULE_LICENSE("GPL");
183 MODULE_VERSION(DRV_VERSION);
184