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, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
54static struct kobj_attribute caps_stop_attribute =
55	__ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
56static struct kobj_attribute freq_attribute =
57	__ATTR(freq, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
58static struct kobj_attribute pitch_attribute =
59	__ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
60static struct kobj_attribute punct_attribute =
61	__ATTR(punct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
62static struct kobj_attribute rate_attribute =
63	__ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
64static struct kobj_attribute tone_attribute =
65	__ATTR(tone, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
66static struct kobj_attribute voice_attribute =
67	__ATTR(voice, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
68static struct kobj_attribute vol_attribute =
69	__ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
70
71static struct kobj_attribute delay_time_attribute =
72	__ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
73static struct kobj_attribute direct_attribute =
74	__ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
75static struct kobj_attribute full_time_attribute =
76	__ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
77static struct kobj_attribute jiffy_delta_attribute =
78	__ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
79static struct kobj_attribute trigger_time_attribute =
80	__ATTR(trigger_time, S_IWUSR|S_IRUGO, 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
145	spk_synth_immediate(synth, "\x18\x01?");
146	for (i = 0; i < 50; i++) {
147		buf[i] = spk_serial_in();
148		if (i > 2 && buf[i] == 0x7f)
149			break;
150	}
151	t = buf+2;
152	for (i = 0; *t != '\r'; t++) {
153		rom_v[i] = *t;
154		if (++i >= 19)
155			break;
156	}
157	rom_v[i] = 0;
158	pr_info("%s: ROM version: %s\n", synth->long_name, rom_v);
159}
160
161static int synth_probe(struct spk_synth *synth)
162{
163	int failed = 0;
164
165	failed = spk_serial_synth_probe(synth);
166	if (failed == 0)
167		synth_interrogate(synth);
168	synth->alive = !failed;
169	return failed;
170}
171
172module_param_named(ser, synth_ltlk.ser, int, S_IRUGO);
173module_param_named(start, synth_ltlk.startup, short, S_IRUGO);
174
175MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
176MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
177
178module_spk_synth(synth_ltlk);
179
180MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
181MODULE_AUTHOR("David Borowski");
182MODULE_DESCRIPTION("Speakup support for DoubleTalk LT/LiteTalk synthesizers");
183MODULE_LICENSE("GPL");
184MODULE_VERSION(DRV_VERSION);
185
186