xref: /OK3568_Linux_fs/kernel/drivers/accessibility/speakup/speakup_dtlk.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0+
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
4*4882a593Smuzhiyun  * this version considerably modified by David Borowski, david575@rogers.com
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) 1998-99  Kirk Reiser.
7*4882a593Smuzhiyun  * Copyright (C) 2003 David Borowski.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * specificly written as a driver for the speakup screenreview
10*4882a593Smuzhiyun  * package it's not a general device driver.
11*4882a593Smuzhiyun  * This driver is for the RC Systems DoubleTalk PC internal synthesizer.
12*4882a593Smuzhiyun  */
13*4882a593Smuzhiyun #include <linux/jiffies.h>
14*4882a593Smuzhiyun #include <linux/sched.h>
15*4882a593Smuzhiyun #include <linux/timer.h>
16*4882a593Smuzhiyun #include <linux/kthread.h>
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #include "spk_priv.h"
19*4882a593Smuzhiyun #include "serialio.h"
20*4882a593Smuzhiyun #include "speakup_dtlk.h" /* local header file for DoubleTalk values */
21*4882a593Smuzhiyun #include "speakup.h"
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #define DRV_VERSION "2.10"
24*4882a593Smuzhiyun #define PROCSPEECH 0x00
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun static int synth_probe(struct spk_synth *synth);
27*4882a593Smuzhiyun static void dtlk_release(void);
28*4882a593Smuzhiyun static const char *synth_immediate(struct spk_synth *synth, const char *buf);
29*4882a593Smuzhiyun static void do_catch_up(struct spk_synth *synth);
30*4882a593Smuzhiyun static void synth_flush(struct spk_synth *synth);
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun static int synth_lpc;
33*4882a593Smuzhiyun static int port_forced;
34*4882a593Smuzhiyun static unsigned int synth_portlist[] = {
35*4882a593Smuzhiyun 		 0x25e, 0x29e, 0x2de, 0x31e, 0x35e, 0x39e, 0
36*4882a593Smuzhiyun };
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun static u_char synth_status;
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun static struct var_t vars[] = {
41*4882a593Smuzhiyun 	{ CAPS_START, .u.s = {"\x01+35p" } },
42*4882a593Smuzhiyun 	{ CAPS_STOP, .u.s = {"\x01-35p" } },
43*4882a593Smuzhiyun 	{ RATE, .u.n = {"\x01%ds", 8, 0, 9, 0, 0, NULL } },
44*4882a593Smuzhiyun 	{ PITCH, .u.n = {"\x01%dp", 50, 0, 99, 0, 0, NULL } },
45*4882a593Smuzhiyun 	{ VOL, .u.n = {"\x01%dv", 5, 0, 9, 0, 0, NULL } },
46*4882a593Smuzhiyun 	{ TONE, .u.n = {"\x01%dx", 1, 0, 2, 0, 0, NULL } },
47*4882a593Smuzhiyun 	{ PUNCT, .u.n = {"\x01%db", 7, 0, 15, 0, 0, NULL } },
48*4882a593Smuzhiyun 	{ VOICE, .u.n = {"\x01%do", 0, 0, 7, 0, 0, NULL } },
49*4882a593Smuzhiyun 	{ FREQUENCY, .u.n = {"\x01%df", 5, 0, 9, 0, 0, NULL } },
50*4882a593Smuzhiyun 	{ DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
51*4882a593Smuzhiyun 	V_LAST_VAR
52*4882a593Smuzhiyun };
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun /*
55*4882a593Smuzhiyun  * These attributes will appear in /sys/accessibility/speakup/dtlk.
56*4882a593Smuzhiyun  */
57*4882a593Smuzhiyun static struct kobj_attribute caps_start_attribute =
58*4882a593Smuzhiyun 	__ATTR(caps_start, 0644, spk_var_show, spk_var_store);
59*4882a593Smuzhiyun static struct kobj_attribute caps_stop_attribute =
60*4882a593Smuzhiyun 	__ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
61*4882a593Smuzhiyun static struct kobj_attribute freq_attribute =
62*4882a593Smuzhiyun 	__ATTR(freq, 0644, spk_var_show, spk_var_store);
63*4882a593Smuzhiyun static struct kobj_attribute pitch_attribute =
64*4882a593Smuzhiyun 	__ATTR(pitch, 0644, spk_var_show, spk_var_store);
65*4882a593Smuzhiyun static struct kobj_attribute punct_attribute =
66*4882a593Smuzhiyun 	__ATTR(punct, 0644, spk_var_show, spk_var_store);
67*4882a593Smuzhiyun static struct kobj_attribute rate_attribute =
68*4882a593Smuzhiyun 	__ATTR(rate, 0644, spk_var_show, spk_var_store);
69*4882a593Smuzhiyun static struct kobj_attribute tone_attribute =
70*4882a593Smuzhiyun 	__ATTR(tone, 0644, spk_var_show, spk_var_store);
71*4882a593Smuzhiyun static struct kobj_attribute voice_attribute =
72*4882a593Smuzhiyun 	__ATTR(voice, 0644, spk_var_show, spk_var_store);
73*4882a593Smuzhiyun static struct kobj_attribute vol_attribute =
74*4882a593Smuzhiyun 	__ATTR(vol, 0644, spk_var_show, spk_var_store);
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun static struct kobj_attribute delay_time_attribute =
77*4882a593Smuzhiyun 	__ATTR(delay_time, 0644, spk_var_show, spk_var_store);
78*4882a593Smuzhiyun static struct kobj_attribute direct_attribute =
79*4882a593Smuzhiyun 	__ATTR(direct, 0644, spk_var_show, spk_var_store);
80*4882a593Smuzhiyun static struct kobj_attribute full_time_attribute =
81*4882a593Smuzhiyun 	__ATTR(full_time, 0644, spk_var_show, spk_var_store);
82*4882a593Smuzhiyun static struct kobj_attribute jiffy_delta_attribute =
83*4882a593Smuzhiyun 	__ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
84*4882a593Smuzhiyun static struct kobj_attribute trigger_time_attribute =
85*4882a593Smuzhiyun 	__ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun /*
88*4882a593Smuzhiyun  * Create a group of attributes so that we can create and destroy them all
89*4882a593Smuzhiyun  * at once.
90*4882a593Smuzhiyun  */
91*4882a593Smuzhiyun static struct attribute *synth_attrs[] = {
92*4882a593Smuzhiyun 	&caps_start_attribute.attr,
93*4882a593Smuzhiyun 	&caps_stop_attribute.attr,
94*4882a593Smuzhiyun 	&freq_attribute.attr,
95*4882a593Smuzhiyun 	&pitch_attribute.attr,
96*4882a593Smuzhiyun 	&punct_attribute.attr,
97*4882a593Smuzhiyun 	&rate_attribute.attr,
98*4882a593Smuzhiyun 	&tone_attribute.attr,
99*4882a593Smuzhiyun 	&voice_attribute.attr,
100*4882a593Smuzhiyun 	&vol_attribute.attr,
101*4882a593Smuzhiyun 	&delay_time_attribute.attr,
102*4882a593Smuzhiyun 	&direct_attribute.attr,
103*4882a593Smuzhiyun 	&full_time_attribute.attr,
104*4882a593Smuzhiyun 	&jiffy_delta_attribute.attr,
105*4882a593Smuzhiyun 	&trigger_time_attribute.attr,
106*4882a593Smuzhiyun 	NULL,	/* need to NULL terminate the list of attributes */
107*4882a593Smuzhiyun };
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun static struct spk_synth synth_dtlk = {
110*4882a593Smuzhiyun 	.name = "dtlk",
111*4882a593Smuzhiyun 	.version = DRV_VERSION,
112*4882a593Smuzhiyun 	.long_name = "DoubleTalk PC",
113*4882a593Smuzhiyun 	.init = "\x01@\x01\x31y",
114*4882a593Smuzhiyun 	.procspeech = PROCSPEECH,
115*4882a593Smuzhiyun 	.clear = SYNTH_CLEAR,
116*4882a593Smuzhiyun 	.delay = 500,
117*4882a593Smuzhiyun 	.trigger = 30,
118*4882a593Smuzhiyun 	.jiffies = 50,
119*4882a593Smuzhiyun 	.full = 1000,
120*4882a593Smuzhiyun 	.startup = SYNTH_START,
121*4882a593Smuzhiyun 	.checkval = SYNTH_CHECK,
122*4882a593Smuzhiyun 	.vars = vars,
123*4882a593Smuzhiyun 	.io_ops = &spk_serial_io_ops,
124*4882a593Smuzhiyun 	.probe = synth_probe,
125*4882a593Smuzhiyun 	.release = dtlk_release,
126*4882a593Smuzhiyun 	.synth_immediate = synth_immediate,
127*4882a593Smuzhiyun 	.catch_up = do_catch_up,
128*4882a593Smuzhiyun 	.flush = synth_flush,
129*4882a593Smuzhiyun 	.is_alive = spk_synth_is_alive_nop,
130*4882a593Smuzhiyun 	.synth_adjust = NULL,
131*4882a593Smuzhiyun 	.read_buff_add = NULL,
132*4882a593Smuzhiyun 	.get_index = spk_synth_get_index,
133*4882a593Smuzhiyun 	.indexing = {
134*4882a593Smuzhiyun 		.command = "\x01%di",
135*4882a593Smuzhiyun 		.lowindex = 1,
136*4882a593Smuzhiyun 		.highindex = 5,
137*4882a593Smuzhiyun 		.currindex = 1,
138*4882a593Smuzhiyun 	},
139*4882a593Smuzhiyun 	.attributes = {
140*4882a593Smuzhiyun 		.attrs = synth_attrs,
141*4882a593Smuzhiyun 		.name = "dtlk",
142*4882a593Smuzhiyun 	},
143*4882a593Smuzhiyun };
144*4882a593Smuzhiyun 
synth_readable(void)145*4882a593Smuzhiyun static inline bool synth_readable(void)
146*4882a593Smuzhiyun {
147*4882a593Smuzhiyun 	synth_status = inb_p(speakup_info.port_tts + UART_RX);
148*4882a593Smuzhiyun 	return (synth_status & TTS_READABLE) != 0;
149*4882a593Smuzhiyun }
150*4882a593Smuzhiyun 
synth_writable(void)151*4882a593Smuzhiyun static inline bool synth_writable(void)
152*4882a593Smuzhiyun {
153*4882a593Smuzhiyun 	synth_status = inb_p(speakup_info.port_tts + UART_RX);
154*4882a593Smuzhiyun 	return (synth_status & TTS_WRITABLE) != 0;
155*4882a593Smuzhiyun }
156*4882a593Smuzhiyun 
synth_full(void)157*4882a593Smuzhiyun static inline bool synth_full(void)
158*4882a593Smuzhiyun {
159*4882a593Smuzhiyun 	synth_status = inb_p(speakup_info.port_tts + UART_RX);
160*4882a593Smuzhiyun 	return (synth_status & TTS_ALMOST_FULL) != 0;
161*4882a593Smuzhiyun }
162*4882a593Smuzhiyun 
spk_out(const char ch)163*4882a593Smuzhiyun static void spk_out(const char ch)
164*4882a593Smuzhiyun {
165*4882a593Smuzhiyun 	int timeout = SPK_XMITR_TIMEOUT;
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun 	while (!synth_writable()) {
168*4882a593Smuzhiyun 		if (!--timeout)
169*4882a593Smuzhiyun 			break;
170*4882a593Smuzhiyun 		udelay(1);
171*4882a593Smuzhiyun 	}
172*4882a593Smuzhiyun 	outb_p(ch, speakup_info.port_tts);
173*4882a593Smuzhiyun 	timeout = SPK_XMITR_TIMEOUT;
174*4882a593Smuzhiyun 	while (synth_writable()) {
175*4882a593Smuzhiyun 		if (!--timeout)
176*4882a593Smuzhiyun 			break;
177*4882a593Smuzhiyun 		udelay(1);
178*4882a593Smuzhiyun 	}
179*4882a593Smuzhiyun }
180*4882a593Smuzhiyun 
do_catch_up(struct spk_synth * synth)181*4882a593Smuzhiyun static void do_catch_up(struct spk_synth *synth)
182*4882a593Smuzhiyun {
183*4882a593Smuzhiyun 	u_char ch;
184*4882a593Smuzhiyun 	unsigned long flags;
185*4882a593Smuzhiyun 	unsigned long jiff_max;
186*4882a593Smuzhiyun 	struct var_t *jiffy_delta;
187*4882a593Smuzhiyun 	struct var_t *delay_time;
188*4882a593Smuzhiyun 	int jiffy_delta_val;
189*4882a593Smuzhiyun 	int delay_time_val;
190*4882a593Smuzhiyun 
191*4882a593Smuzhiyun 	jiffy_delta = spk_get_var(JIFFY);
192*4882a593Smuzhiyun 	delay_time = spk_get_var(DELAY);
193*4882a593Smuzhiyun 	spin_lock_irqsave(&speakup_info.spinlock, flags);
194*4882a593Smuzhiyun 	jiffy_delta_val = jiffy_delta->u.n.value;
195*4882a593Smuzhiyun 	spin_unlock_irqrestore(&speakup_info.spinlock, flags);
196*4882a593Smuzhiyun 	jiff_max = jiffies + jiffy_delta_val;
197*4882a593Smuzhiyun 	while (!kthread_should_stop()) {
198*4882a593Smuzhiyun 		spin_lock_irqsave(&speakup_info.spinlock, flags);
199*4882a593Smuzhiyun 		if (speakup_info.flushing) {
200*4882a593Smuzhiyun 			speakup_info.flushing = 0;
201*4882a593Smuzhiyun 			spin_unlock_irqrestore(&speakup_info.spinlock, flags);
202*4882a593Smuzhiyun 			synth->flush(synth);
203*4882a593Smuzhiyun 			continue;
204*4882a593Smuzhiyun 		}
205*4882a593Smuzhiyun 		synth_buffer_skip_nonlatin1();
206*4882a593Smuzhiyun 		if (synth_buffer_empty()) {
207*4882a593Smuzhiyun 			spin_unlock_irqrestore(&speakup_info.spinlock, flags);
208*4882a593Smuzhiyun 			break;
209*4882a593Smuzhiyun 		}
210*4882a593Smuzhiyun 		set_current_state(TASK_INTERRUPTIBLE);
211*4882a593Smuzhiyun 		delay_time_val = delay_time->u.n.value;
212*4882a593Smuzhiyun 		spin_unlock_irqrestore(&speakup_info.spinlock, flags);
213*4882a593Smuzhiyun 		if (synth_full()) {
214*4882a593Smuzhiyun 			schedule_timeout(msecs_to_jiffies(delay_time_val));
215*4882a593Smuzhiyun 			continue;
216*4882a593Smuzhiyun 		}
217*4882a593Smuzhiyun 		set_current_state(TASK_RUNNING);
218*4882a593Smuzhiyun 		spin_lock_irqsave(&speakup_info.spinlock, flags);
219*4882a593Smuzhiyun 		ch = synth_buffer_getc();
220*4882a593Smuzhiyun 		spin_unlock_irqrestore(&speakup_info.spinlock, flags);
221*4882a593Smuzhiyun 		if (ch == '\n')
222*4882a593Smuzhiyun 			ch = PROCSPEECH;
223*4882a593Smuzhiyun 		spk_out(ch);
224*4882a593Smuzhiyun 		if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) {
225*4882a593Smuzhiyun 			spk_out(PROCSPEECH);
226*4882a593Smuzhiyun 			spin_lock_irqsave(&speakup_info.spinlock, flags);
227*4882a593Smuzhiyun 			delay_time_val = delay_time->u.n.value;
228*4882a593Smuzhiyun 			jiffy_delta_val = jiffy_delta->u.n.value;
229*4882a593Smuzhiyun 			spin_unlock_irqrestore(&speakup_info.spinlock, flags);
230*4882a593Smuzhiyun 			schedule_timeout(msecs_to_jiffies(delay_time_val));
231*4882a593Smuzhiyun 			jiff_max = jiffies + jiffy_delta_val;
232*4882a593Smuzhiyun 		}
233*4882a593Smuzhiyun 	}
234*4882a593Smuzhiyun 	spk_out(PROCSPEECH);
235*4882a593Smuzhiyun }
236*4882a593Smuzhiyun 
synth_immediate(struct spk_synth * synth,const char * buf)237*4882a593Smuzhiyun static const char *synth_immediate(struct spk_synth *synth, const char *buf)
238*4882a593Smuzhiyun {
239*4882a593Smuzhiyun 	u_char ch;
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun 	while ((ch = (u_char)*buf)) {
242*4882a593Smuzhiyun 		if (synth_full())
243*4882a593Smuzhiyun 			return buf;
244*4882a593Smuzhiyun 		if (ch == '\n')
245*4882a593Smuzhiyun 			ch = PROCSPEECH;
246*4882a593Smuzhiyun 		spk_out(ch);
247*4882a593Smuzhiyun 		buf++;
248*4882a593Smuzhiyun 	}
249*4882a593Smuzhiyun 	return NULL;
250*4882a593Smuzhiyun }
251*4882a593Smuzhiyun 
synth_flush(struct spk_synth * synth)252*4882a593Smuzhiyun static void synth_flush(struct spk_synth *synth)
253*4882a593Smuzhiyun {
254*4882a593Smuzhiyun 	outb_p(SYNTH_CLEAR, speakup_info.port_tts);
255*4882a593Smuzhiyun 	while (synth_writable())
256*4882a593Smuzhiyun 		cpu_relax();
257*4882a593Smuzhiyun }
258*4882a593Smuzhiyun 
synth_read_tts(void)259*4882a593Smuzhiyun static char synth_read_tts(void)
260*4882a593Smuzhiyun {
261*4882a593Smuzhiyun 	u_char ch;
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun 	while (!synth_readable())
264*4882a593Smuzhiyun 		cpu_relax();
265*4882a593Smuzhiyun 	ch = synth_status & 0x7f;
266*4882a593Smuzhiyun 	outb_p(ch, speakup_info.port_tts);
267*4882a593Smuzhiyun 	while (synth_readable())
268*4882a593Smuzhiyun 		cpu_relax();
269*4882a593Smuzhiyun 	return (char)ch;
270*4882a593Smuzhiyun }
271*4882a593Smuzhiyun 
272*4882a593Smuzhiyun /* interrogate the DoubleTalk PC and return its settings */
synth_interrogate(struct spk_synth * synth)273*4882a593Smuzhiyun static struct synth_settings *synth_interrogate(struct spk_synth *synth)
274*4882a593Smuzhiyun {
275*4882a593Smuzhiyun 	u_char *t;
276*4882a593Smuzhiyun 	static char buf[sizeof(struct synth_settings) + 1];
277*4882a593Smuzhiyun 	int total, i;
278*4882a593Smuzhiyun 	static struct synth_settings status;
279*4882a593Smuzhiyun 
280*4882a593Smuzhiyun 	synth_immediate(synth, "\x18\x01?");
281*4882a593Smuzhiyun 	for (total = 0, i = 0; i < 50; i++) {
282*4882a593Smuzhiyun 		buf[total] = synth_read_tts();
283*4882a593Smuzhiyun 		if (total > 2 && buf[total] == 0x7f)
284*4882a593Smuzhiyun 			break;
285*4882a593Smuzhiyun 		if (total < sizeof(struct synth_settings))
286*4882a593Smuzhiyun 			total++;
287*4882a593Smuzhiyun 	}
288*4882a593Smuzhiyun 	t = buf;
289*4882a593Smuzhiyun 	/* serial number is little endian */
290*4882a593Smuzhiyun 	status.serial_number = t[0] + t[1] * 256;
291*4882a593Smuzhiyun 	t += 2;
292*4882a593Smuzhiyun 	for (i = 0; *t != '\r'; t++) {
293*4882a593Smuzhiyun 		status.rom_version[i] = *t;
294*4882a593Smuzhiyun 		if (i < sizeof(status.rom_version) - 1)
295*4882a593Smuzhiyun 			i++;
296*4882a593Smuzhiyun 	}
297*4882a593Smuzhiyun 	status.rom_version[i] = 0;
298*4882a593Smuzhiyun 	t++;
299*4882a593Smuzhiyun 	status.mode = *t++;
300*4882a593Smuzhiyun 	status.punc_level = *t++;
301*4882a593Smuzhiyun 	status.formant_freq = *t++;
302*4882a593Smuzhiyun 	status.pitch = *t++;
303*4882a593Smuzhiyun 	status.speed = *t++;
304*4882a593Smuzhiyun 	status.volume = *t++;
305*4882a593Smuzhiyun 	status.tone = *t++;
306*4882a593Smuzhiyun 	status.expression = *t++;
307*4882a593Smuzhiyun 	status.ext_dict_loaded = *t++;
308*4882a593Smuzhiyun 	status.ext_dict_status = *t++;
309*4882a593Smuzhiyun 	status.free_ram = *t++;
310*4882a593Smuzhiyun 	status.articulation = *t++;
311*4882a593Smuzhiyun 	status.reverb = *t++;
312*4882a593Smuzhiyun 	status.eob = *t++;
313*4882a593Smuzhiyun 	return &status;
314*4882a593Smuzhiyun }
315*4882a593Smuzhiyun 
synth_probe(struct spk_synth * synth)316*4882a593Smuzhiyun static int synth_probe(struct spk_synth *synth)
317*4882a593Smuzhiyun {
318*4882a593Smuzhiyun 	unsigned int port_val = 0;
319*4882a593Smuzhiyun 	int i = 0;
320*4882a593Smuzhiyun 	struct synth_settings *sp;
321*4882a593Smuzhiyun 
322*4882a593Smuzhiyun 	pr_info("Probing for DoubleTalk.\n");
323*4882a593Smuzhiyun 	if (port_forced) {
324*4882a593Smuzhiyun 		speakup_info.port_tts = port_forced;
325*4882a593Smuzhiyun 		pr_info("probe forced to %x by kernel command line\n",
326*4882a593Smuzhiyun 			speakup_info.port_tts);
327*4882a593Smuzhiyun 		if ((port_forced & 0xf) != 0xf)
328*4882a593Smuzhiyun 			pr_info("warning: port base should probably end with f\n");
329*4882a593Smuzhiyun 		if (synth_request_region(speakup_info.port_tts - 1,
330*4882a593Smuzhiyun 					 SYNTH_IO_EXTENT)) {
331*4882a593Smuzhiyun 			pr_warn("sorry, port already reserved\n");
332*4882a593Smuzhiyun 			return -EBUSY;
333*4882a593Smuzhiyun 		}
334*4882a593Smuzhiyun 		port_val = inw(speakup_info.port_tts - 1);
335*4882a593Smuzhiyun 		synth_lpc = speakup_info.port_tts - 1;
336*4882a593Smuzhiyun 	} else {
337*4882a593Smuzhiyun 		for (i = 0; synth_portlist[i]; i++) {
338*4882a593Smuzhiyun 			if (synth_request_region(synth_portlist[i],
339*4882a593Smuzhiyun 						 SYNTH_IO_EXTENT))
340*4882a593Smuzhiyun 				continue;
341*4882a593Smuzhiyun 			port_val = inw(synth_portlist[i]) & 0xfbff;
342*4882a593Smuzhiyun 			if (port_val == 0x107f) {
343*4882a593Smuzhiyun 				synth_lpc = synth_portlist[i];
344*4882a593Smuzhiyun 				speakup_info.port_tts = synth_lpc + 1;
345*4882a593Smuzhiyun 				break;
346*4882a593Smuzhiyun 			}
347*4882a593Smuzhiyun 			synth_release_region(synth_portlist[i],
348*4882a593Smuzhiyun 					     SYNTH_IO_EXTENT);
349*4882a593Smuzhiyun 		}
350*4882a593Smuzhiyun 	}
351*4882a593Smuzhiyun 	port_val &= 0xfbff;
352*4882a593Smuzhiyun 	if (port_val != 0x107f) {
353*4882a593Smuzhiyun 		pr_info("DoubleTalk PC: not found\n");
354*4882a593Smuzhiyun 		if (synth_lpc)
355*4882a593Smuzhiyun 			synth_release_region(synth_lpc, SYNTH_IO_EXTENT);
356*4882a593Smuzhiyun 		return -ENODEV;
357*4882a593Smuzhiyun 	}
358*4882a593Smuzhiyun 	while (inw_p(synth_lpc) != 0x147f)
359*4882a593Smuzhiyun 		cpu_relax(); /* wait until it's ready */
360*4882a593Smuzhiyun 	sp = synth_interrogate(synth);
361*4882a593Smuzhiyun 	pr_info("%s: %03x-%03x, ROM ver %s, s/n %u, driver: %s\n",
362*4882a593Smuzhiyun 		synth->long_name, synth_lpc, synth_lpc + SYNTH_IO_EXTENT - 1,
363*4882a593Smuzhiyun 		sp->rom_version, sp->serial_number, synth->version);
364*4882a593Smuzhiyun 	synth->alive = 1;
365*4882a593Smuzhiyun 	return 0;
366*4882a593Smuzhiyun }
367*4882a593Smuzhiyun 
dtlk_release(void)368*4882a593Smuzhiyun static void dtlk_release(void)
369*4882a593Smuzhiyun {
370*4882a593Smuzhiyun 	spk_stop_serial_interrupt();
371*4882a593Smuzhiyun 	if (speakup_info.port_tts)
372*4882a593Smuzhiyun 		synth_release_region(speakup_info.port_tts - 1,
373*4882a593Smuzhiyun 				     SYNTH_IO_EXTENT);
374*4882a593Smuzhiyun 	speakup_info.port_tts = 0;
375*4882a593Smuzhiyun }
376*4882a593Smuzhiyun 
377*4882a593Smuzhiyun module_param_hw_named(port, port_forced, int, ioport, 0444);
378*4882a593Smuzhiyun module_param_named(start, synth_dtlk.startup, short, 0444);
379*4882a593Smuzhiyun 
380*4882a593Smuzhiyun MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
381*4882a593Smuzhiyun MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
382*4882a593Smuzhiyun 
383*4882a593Smuzhiyun module_spk_synth(synth_dtlk);
384*4882a593Smuzhiyun 
385*4882a593Smuzhiyun MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
386*4882a593Smuzhiyun MODULE_AUTHOR("David Borowski");
387*4882a593Smuzhiyun MODULE_DESCRIPTION("Speakup support for DoubleTalk PC synthesizers");
388*4882a593Smuzhiyun MODULE_LICENSE("GPL");
389*4882a593Smuzhiyun MODULE_VERSION(DRV_VERSION);
390*4882a593Smuzhiyun 
391