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