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