162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
462306a36Sopenharmony_ci * this version considerably modified by David Borowski, david575@rogers.com
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Copyright (C) 1998-99  Kirk Reiser.
762306a36Sopenharmony_ci * Copyright (C) 2003 David Borowski.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * specifically written as a driver for the speakup screenreview
1062306a36Sopenharmony_ci * package it's not a general device driver.
1162306a36Sopenharmony_ci * This driver is for the RC Systems DoubleTalk PC internal synthesizer.
1262306a36Sopenharmony_ci */
1362306a36Sopenharmony_ci#include <linux/jiffies.h>
1462306a36Sopenharmony_ci#include <linux/sched.h>
1562306a36Sopenharmony_ci#include <linux/timer.h>
1662306a36Sopenharmony_ci#include <linux/kthread.h>
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#include "spk_priv.h"
1962306a36Sopenharmony_ci#include "serialio.h"
2062306a36Sopenharmony_ci#include "speakup_dtlk.h" /* local header file for DoubleTalk values */
2162306a36Sopenharmony_ci#include "speakup.h"
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci#define DRV_VERSION "2.10"
2462306a36Sopenharmony_ci#define PROCSPEECH 0x00
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_cistatic int synth_probe(struct spk_synth *synth);
2762306a36Sopenharmony_cistatic void dtlk_release(struct spk_synth *synth);
2862306a36Sopenharmony_cistatic const char *synth_immediate(struct spk_synth *synth, const char *buf);
2962306a36Sopenharmony_cistatic void do_catch_up(struct spk_synth *synth);
3062306a36Sopenharmony_cistatic void synth_flush(struct spk_synth *synth);
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_cistatic int synth_lpc;
3362306a36Sopenharmony_cistatic int port_forced;
3462306a36Sopenharmony_cistatic unsigned int synth_portlist[] = {
3562306a36Sopenharmony_ci		 0x25e, 0x29e, 0x2de, 0x31e, 0x35e, 0x39e, 0
3662306a36Sopenharmony_ci};
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_cistatic u_char synth_status;
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_cienum default_vars_id {
4162306a36Sopenharmony_ci	CAPS_START_ID = 0, CAPS_STOP_ID,
4262306a36Sopenharmony_ci	RATE_ID, PITCH_ID,
4362306a36Sopenharmony_ci	VOL_ID, TONE_ID, PUNCT_ID,
4462306a36Sopenharmony_ci	VOICE_ID, FREQUENCY_ID,
4562306a36Sopenharmony_ci	DIRECT_ID, V_LAST_VAR_ID,
4662306a36Sopenharmony_ci	NB_ID,
4762306a36Sopenharmony_ci};
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_cistatic struct var_t vars[NB_ID] = {
5162306a36Sopenharmony_ci	[CAPS_START_ID] = { CAPS_START, .u.s = {"\x01+35p" } },
5262306a36Sopenharmony_ci	[CAPS_STOP_ID] = { CAPS_STOP, .u.s = {"\x01-35p" } },
5362306a36Sopenharmony_ci	[RATE_ID] = { RATE, .u.n = {"\x01%ds", 8, 0, 9, 0, 0, NULL } },
5462306a36Sopenharmony_ci	[PITCH_ID] = { PITCH, .u.n = {"\x01%dp", 50, 0, 99, 0, 0, NULL } },
5562306a36Sopenharmony_ci	[VOL_ID] = { VOL, .u.n = {"\x01%dv", 5, 0, 9, 0, 0, NULL } },
5662306a36Sopenharmony_ci	[TONE_ID] = { TONE, .u.n = {"\x01%dx", 1, 0, 2, 0, 0, NULL } },
5762306a36Sopenharmony_ci	[PUNCT_ID] = { PUNCT, .u.n = {"\x01%db", 7, 0, 15, 0, 0, NULL } },
5862306a36Sopenharmony_ci	[VOICE_ID] = { VOICE, .u.n = {"\x01%do", 0, 0, 7, 0, 0, NULL } },
5962306a36Sopenharmony_ci	[FREQUENCY_ID] = { FREQUENCY, .u.n = {"\x01%df", 5, 0, 9, 0, 0, NULL } },
6062306a36Sopenharmony_ci	[DIRECT_ID] = { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
6162306a36Sopenharmony_ci	V_LAST_VAR
6262306a36Sopenharmony_ci};
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci/*
6562306a36Sopenharmony_ci * These attributes will appear in /sys/accessibility/speakup/dtlk.
6662306a36Sopenharmony_ci */
6762306a36Sopenharmony_cistatic struct kobj_attribute caps_start_attribute =
6862306a36Sopenharmony_ci	__ATTR(caps_start, 0644, spk_var_show, spk_var_store);
6962306a36Sopenharmony_cistatic struct kobj_attribute caps_stop_attribute =
7062306a36Sopenharmony_ci	__ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
7162306a36Sopenharmony_cistatic struct kobj_attribute freq_attribute =
7262306a36Sopenharmony_ci	__ATTR(freq, 0644, spk_var_show, spk_var_store);
7362306a36Sopenharmony_cistatic struct kobj_attribute pitch_attribute =
7462306a36Sopenharmony_ci	__ATTR(pitch, 0644, spk_var_show, spk_var_store);
7562306a36Sopenharmony_cistatic struct kobj_attribute punct_attribute =
7662306a36Sopenharmony_ci	__ATTR(punct, 0644, spk_var_show, spk_var_store);
7762306a36Sopenharmony_cistatic struct kobj_attribute rate_attribute =
7862306a36Sopenharmony_ci	__ATTR(rate, 0644, spk_var_show, spk_var_store);
7962306a36Sopenharmony_cistatic struct kobj_attribute tone_attribute =
8062306a36Sopenharmony_ci	__ATTR(tone, 0644, spk_var_show, spk_var_store);
8162306a36Sopenharmony_cistatic struct kobj_attribute voice_attribute =
8262306a36Sopenharmony_ci	__ATTR(voice, 0644, spk_var_show, spk_var_store);
8362306a36Sopenharmony_cistatic struct kobj_attribute vol_attribute =
8462306a36Sopenharmony_ci	__ATTR(vol, 0644, spk_var_show, spk_var_store);
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_cistatic struct kobj_attribute delay_time_attribute =
8762306a36Sopenharmony_ci	__ATTR(delay_time, 0644, spk_var_show, spk_var_store);
8862306a36Sopenharmony_cistatic struct kobj_attribute direct_attribute =
8962306a36Sopenharmony_ci	__ATTR(direct, 0644, spk_var_show, spk_var_store);
9062306a36Sopenharmony_cistatic struct kobj_attribute full_time_attribute =
9162306a36Sopenharmony_ci	__ATTR(full_time, 0644, spk_var_show, spk_var_store);
9262306a36Sopenharmony_cistatic struct kobj_attribute jiffy_delta_attribute =
9362306a36Sopenharmony_ci	__ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
9462306a36Sopenharmony_cistatic struct kobj_attribute trigger_time_attribute =
9562306a36Sopenharmony_ci	__ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci/*
9862306a36Sopenharmony_ci * Create a group of attributes so that we can create and destroy them all
9962306a36Sopenharmony_ci * at once.
10062306a36Sopenharmony_ci */
10162306a36Sopenharmony_cistatic struct attribute *synth_attrs[] = {
10262306a36Sopenharmony_ci	&caps_start_attribute.attr,
10362306a36Sopenharmony_ci	&caps_stop_attribute.attr,
10462306a36Sopenharmony_ci	&freq_attribute.attr,
10562306a36Sopenharmony_ci	&pitch_attribute.attr,
10662306a36Sopenharmony_ci	&punct_attribute.attr,
10762306a36Sopenharmony_ci	&rate_attribute.attr,
10862306a36Sopenharmony_ci	&tone_attribute.attr,
10962306a36Sopenharmony_ci	&voice_attribute.attr,
11062306a36Sopenharmony_ci	&vol_attribute.attr,
11162306a36Sopenharmony_ci	&delay_time_attribute.attr,
11262306a36Sopenharmony_ci	&direct_attribute.attr,
11362306a36Sopenharmony_ci	&full_time_attribute.attr,
11462306a36Sopenharmony_ci	&jiffy_delta_attribute.attr,
11562306a36Sopenharmony_ci	&trigger_time_attribute.attr,
11662306a36Sopenharmony_ci	NULL,	/* need to NULL terminate the list of attributes */
11762306a36Sopenharmony_ci};
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_cistatic struct spk_synth synth_dtlk = {
12062306a36Sopenharmony_ci	.name = "dtlk",
12162306a36Sopenharmony_ci	.version = DRV_VERSION,
12262306a36Sopenharmony_ci	.long_name = "DoubleTalk PC",
12362306a36Sopenharmony_ci	.init = "\x01@\x01\x31y",
12462306a36Sopenharmony_ci	.procspeech = PROCSPEECH,
12562306a36Sopenharmony_ci	.clear = SYNTH_CLEAR,
12662306a36Sopenharmony_ci	.delay = 500,
12762306a36Sopenharmony_ci	.trigger = 30,
12862306a36Sopenharmony_ci	.jiffies = 50,
12962306a36Sopenharmony_ci	.full = 1000,
13062306a36Sopenharmony_ci	.startup = SYNTH_START,
13162306a36Sopenharmony_ci	.checkval = SYNTH_CHECK,
13262306a36Sopenharmony_ci	.vars = vars,
13362306a36Sopenharmony_ci	.io_ops = &spk_serial_io_ops,
13462306a36Sopenharmony_ci	.probe = synth_probe,
13562306a36Sopenharmony_ci	.release = dtlk_release,
13662306a36Sopenharmony_ci	.synth_immediate = synth_immediate,
13762306a36Sopenharmony_ci	.catch_up = do_catch_up,
13862306a36Sopenharmony_ci	.flush = synth_flush,
13962306a36Sopenharmony_ci	.is_alive = spk_synth_is_alive_nop,
14062306a36Sopenharmony_ci	.synth_adjust = NULL,
14162306a36Sopenharmony_ci	.read_buff_add = NULL,
14262306a36Sopenharmony_ci	.get_index = spk_synth_get_index,
14362306a36Sopenharmony_ci	.indexing = {
14462306a36Sopenharmony_ci		.command = "\x01%di",
14562306a36Sopenharmony_ci		.lowindex = 1,
14662306a36Sopenharmony_ci		.highindex = 5,
14762306a36Sopenharmony_ci		.currindex = 1,
14862306a36Sopenharmony_ci	},
14962306a36Sopenharmony_ci	.attributes = {
15062306a36Sopenharmony_ci		.attrs = synth_attrs,
15162306a36Sopenharmony_ci		.name = "dtlk",
15262306a36Sopenharmony_ci	},
15362306a36Sopenharmony_ci};
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_cistatic inline bool synth_readable(void)
15662306a36Sopenharmony_ci{
15762306a36Sopenharmony_ci	synth_status = inb_p(speakup_info.port_tts + UART_RX);
15862306a36Sopenharmony_ci	return (synth_status & TTS_READABLE) != 0;
15962306a36Sopenharmony_ci}
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_cistatic inline bool synth_writable(void)
16262306a36Sopenharmony_ci{
16362306a36Sopenharmony_ci	synth_status = inb_p(speakup_info.port_tts + UART_RX);
16462306a36Sopenharmony_ci	return (synth_status & TTS_WRITABLE) != 0;
16562306a36Sopenharmony_ci}
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_cistatic inline bool synth_full(void)
16862306a36Sopenharmony_ci{
16962306a36Sopenharmony_ci	synth_status = inb_p(speakup_info.port_tts + UART_RX);
17062306a36Sopenharmony_ci	return (synth_status & TTS_ALMOST_FULL) != 0;
17162306a36Sopenharmony_ci}
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_cistatic void spk_out(const char ch)
17462306a36Sopenharmony_ci{
17562306a36Sopenharmony_ci	int timeout = SPK_XMITR_TIMEOUT;
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci	while (!synth_writable()) {
17862306a36Sopenharmony_ci		if (!--timeout)
17962306a36Sopenharmony_ci			break;
18062306a36Sopenharmony_ci		udelay(1);
18162306a36Sopenharmony_ci	}
18262306a36Sopenharmony_ci	outb_p(ch, speakup_info.port_tts);
18362306a36Sopenharmony_ci	timeout = SPK_XMITR_TIMEOUT;
18462306a36Sopenharmony_ci	while (synth_writable()) {
18562306a36Sopenharmony_ci		if (!--timeout)
18662306a36Sopenharmony_ci			break;
18762306a36Sopenharmony_ci		udelay(1);
18862306a36Sopenharmony_ci	}
18962306a36Sopenharmony_ci}
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_cistatic void do_catch_up(struct spk_synth *synth)
19262306a36Sopenharmony_ci{
19362306a36Sopenharmony_ci	u_char ch;
19462306a36Sopenharmony_ci	unsigned long flags;
19562306a36Sopenharmony_ci	unsigned long jiff_max;
19662306a36Sopenharmony_ci	struct var_t *jiffy_delta;
19762306a36Sopenharmony_ci	struct var_t *delay_time;
19862306a36Sopenharmony_ci	int jiffy_delta_val;
19962306a36Sopenharmony_ci	int delay_time_val;
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ci	jiffy_delta = spk_get_var(JIFFY);
20262306a36Sopenharmony_ci	delay_time = spk_get_var(DELAY);
20362306a36Sopenharmony_ci	spin_lock_irqsave(&speakup_info.spinlock, flags);
20462306a36Sopenharmony_ci	jiffy_delta_val = jiffy_delta->u.n.value;
20562306a36Sopenharmony_ci	spin_unlock_irqrestore(&speakup_info.spinlock, flags);
20662306a36Sopenharmony_ci	jiff_max = jiffies + jiffy_delta_val;
20762306a36Sopenharmony_ci	while (!kthread_should_stop()) {
20862306a36Sopenharmony_ci		spin_lock_irqsave(&speakup_info.spinlock, flags);
20962306a36Sopenharmony_ci		if (speakup_info.flushing) {
21062306a36Sopenharmony_ci			speakup_info.flushing = 0;
21162306a36Sopenharmony_ci			spin_unlock_irqrestore(&speakup_info.spinlock, flags);
21262306a36Sopenharmony_ci			synth->flush(synth);
21362306a36Sopenharmony_ci			continue;
21462306a36Sopenharmony_ci		}
21562306a36Sopenharmony_ci		synth_buffer_skip_nonlatin1();
21662306a36Sopenharmony_ci		if (synth_buffer_empty()) {
21762306a36Sopenharmony_ci			spin_unlock_irqrestore(&speakup_info.spinlock, flags);
21862306a36Sopenharmony_ci			break;
21962306a36Sopenharmony_ci		}
22062306a36Sopenharmony_ci		set_current_state(TASK_INTERRUPTIBLE);
22162306a36Sopenharmony_ci		delay_time_val = delay_time->u.n.value;
22262306a36Sopenharmony_ci		spin_unlock_irqrestore(&speakup_info.spinlock, flags);
22362306a36Sopenharmony_ci		if (synth_full()) {
22462306a36Sopenharmony_ci			schedule_timeout(msecs_to_jiffies(delay_time_val));
22562306a36Sopenharmony_ci			continue;
22662306a36Sopenharmony_ci		}
22762306a36Sopenharmony_ci		set_current_state(TASK_RUNNING);
22862306a36Sopenharmony_ci		spin_lock_irqsave(&speakup_info.spinlock, flags);
22962306a36Sopenharmony_ci		ch = synth_buffer_getc();
23062306a36Sopenharmony_ci		spin_unlock_irqrestore(&speakup_info.spinlock, flags);
23162306a36Sopenharmony_ci		if (ch == '\n')
23262306a36Sopenharmony_ci			ch = PROCSPEECH;
23362306a36Sopenharmony_ci		spk_out(ch);
23462306a36Sopenharmony_ci		if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) {
23562306a36Sopenharmony_ci			spk_out(PROCSPEECH);
23662306a36Sopenharmony_ci			spin_lock_irqsave(&speakup_info.spinlock, flags);
23762306a36Sopenharmony_ci			delay_time_val = delay_time->u.n.value;
23862306a36Sopenharmony_ci			jiffy_delta_val = jiffy_delta->u.n.value;
23962306a36Sopenharmony_ci			spin_unlock_irqrestore(&speakup_info.spinlock, flags);
24062306a36Sopenharmony_ci			schedule_timeout(msecs_to_jiffies(delay_time_val));
24162306a36Sopenharmony_ci			jiff_max = jiffies + jiffy_delta_val;
24262306a36Sopenharmony_ci		}
24362306a36Sopenharmony_ci	}
24462306a36Sopenharmony_ci	spk_out(PROCSPEECH);
24562306a36Sopenharmony_ci}
24662306a36Sopenharmony_ci
24762306a36Sopenharmony_cistatic const char *synth_immediate(struct spk_synth *synth, const char *buf)
24862306a36Sopenharmony_ci{
24962306a36Sopenharmony_ci	u_char ch;
25062306a36Sopenharmony_ci
25162306a36Sopenharmony_ci	while ((ch = (u_char)*buf)) {
25262306a36Sopenharmony_ci		if (synth_full())
25362306a36Sopenharmony_ci			return buf;
25462306a36Sopenharmony_ci		if (ch == '\n')
25562306a36Sopenharmony_ci			ch = PROCSPEECH;
25662306a36Sopenharmony_ci		spk_out(ch);
25762306a36Sopenharmony_ci		buf++;
25862306a36Sopenharmony_ci	}
25962306a36Sopenharmony_ci	return NULL;
26062306a36Sopenharmony_ci}
26162306a36Sopenharmony_ci
26262306a36Sopenharmony_cistatic void synth_flush(struct spk_synth *synth)
26362306a36Sopenharmony_ci{
26462306a36Sopenharmony_ci	outb_p(SYNTH_CLEAR, speakup_info.port_tts);
26562306a36Sopenharmony_ci	while (synth_writable())
26662306a36Sopenharmony_ci		cpu_relax();
26762306a36Sopenharmony_ci}
26862306a36Sopenharmony_ci
26962306a36Sopenharmony_cistatic char synth_read_tts(void)
27062306a36Sopenharmony_ci{
27162306a36Sopenharmony_ci	u_char ch;
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_ci	while (!synth_readable())
27462306a36Sopenharmony_ci		cpu_relax();
27562306a36Sopenharmony_ci	ch = synth_status & 0x7f;
27662306a36Sopenharmony_ci	outb_p(ch, speakup_info.port_tts);
27762306a36Sopenharmony_ci	while (synth_readable())
27862306a36Sopenharmony_ci		cpu_relax();
27962306a36Sopenharmony_ci	return (char)ch;
28062306a36Sopenharmony_ci}
28162306a36Sopenharmony_ci
28262306a36Sopenharmony_ci/* interrogate the DoubleTalk PC and return its settings */
28362306a36Sopenharmony_cistatic struct synth_settings *synth_interrogate(struct spk_synth *synth)
28462306a36Sopenharmony_ci{
28562306a36Sopenharmony_ci	u_char *t;
28662306a36Sopenharmony_ci	static char buf[sizeof(struct synth_settings) + 1];
28762306a36Sopenharmony_ci	int total, i;
28862306a36Sopenharmony_ci	static struct synth_settings status;
28962306a36Sopenharmony_ci
29062306a36Sopenharmony_ci	synth_immediate(synth, "\x18\x01?");
29162306a36Sopenharmony_ci	for (total = 0, i = 0; i < 50; i++) {
29262306a36Sopenharmony_ci		buf[total] = synth_read_tts();
29362306a36Sopenharmony_ci		if (total > 2 && buf[total] == 0x7f)
29462306a36Sopenharmony_ci			break;
29562306a36Sopenharmony_ci		if (total < sizeof(struct synth_settings))
29662306a36Sopenharmony_ci			total++;
29762306a36Sopenharmony_ci	}
29862306a36Sopenharmony_ci	t = buf;
29962306a36Sopenharmony_ci	/* serial number is little endian */
30062306a36Sopenharmony_ci	status.serial_number = t[0] + t[1] * 256;
30162306a36Sopenharmony_ci	t += 2;
30262306a36Sopenharmony_ci	for (i = 0; *t != '\r'; t++) {
30362306a36Sopenharmony_ci		status.rom_version[i] = *t;
30462306a36Sopenharmony_ci		if (i < sizeof(status.rom_version) - 1)
30562306a36Sopenharmony_ci			i++;
30662306a36Sopenharmony_ci	}
30762306a36Sopenharmony_ci	status.rom_version[i] = 0;
30862306a36Sopenharmony_ci	t++;
30962306a36Sopenharmony_ci	status.mode = *t++;
31062306a36Sopenharmony_ci	status.punc_level = *t++;
31162306a36Sopenharmony_ci	status.formant_freq = *t++;
31262306a36Sopenharmony_ci	status.pitch = *t++;
31362306a36Sopenharmony_ci	status.speed = *t++;
31462306a36Sopenharmony_ci	status.volume = *t++;
31562306a36Sopenharmony_ci	status.tone = *t++;
31662306a36Sopenharmony_ci	status.expression = *t++;
31762306a36Sopenharmony_ci	status.ext_dict_loaded = *t++;
31862306a36Sopenharmony_ci	status.ext_dict_status = *t++;
31962306a36Sopenharmony_ci	status.free_ram = *t++;
32062306a36Sopenharmony_ci	status.articulation = *t++;
32162306a36Sopenharmony_ci	status.reverb = *t++;
32262306a36Sopenharmony_ci	status.eob = *t++;
32362306a36Sopenharmony_ci	return &status;
32462306a36Sopenharmony_ci}
32562306a36Sopenharmony_ci
32662306a36Sopenharmony_cistatic int synth_probe(struct spk_synth *synth)
32762306a36Sopenharmony_ci{
32862306a36Sopenharmony_ci	unsigned int port_val = 0;
32962306a36Sopenharmony_ci	int i;
33062306a36Sopenharmony_ci	struct synth_settings *sp;
33162306a36Sopenharmony_ci
33262306a36Sopenharmony_ci	pr_info("Probing for DoubleTalk.\n");
33362306a36Sopenharmony_ci	if (port_forced) {
33462306a36Sopenharmony_ci		speakup_info.port_tts = port_forced;
33562306a36Sopenharmony_ci		pr_info("probe forced to %x by kernel command line\n",
33662306a36Sopenharmony_ci			speakup_info.port_tts);
33762306a36Sopenharmony_ci		if ((port_forced & 0xf) != 0xf)
33862306a36Sopenharmony_ci			pr_info("warning: port base should probably end with f\n");
33962306a36Sopenharmony_ci		if (synth_request_region(speakup_info.port_tts - 1,
34062306a36Sopenharmony_ci					 SYNTH_IO_EXTENT)) {
34162306a36Sopenharmony_ci			pr_warn("sorry, port already reserved\n");
34262306a36Sopenharmony_ci			return -EBUSY;
34362306a36Sopenharmony_ci		}
34462306a36Sopenharmony_ci		port_val = inw(speakup_info.port_tts - 1);
34562306a36Sopenharmony_ci		synth_lpc = speakup_info.port_tts - 1;
34662306a36Sopenharmony_ci	} else {
34762306a36Sopenharmony_ci		for (i = 0; synth_portlist[i]; i++) {
34862306a36Sopenharmony_ci			if (synth_request_region(synth_portlist[i],
34962306a36Sopenharmony_ci						 SYNTH_IO_EXTENT))
35062306a36Sopenharmony_ci				continue;
35162306a36Sopenharmony_ci			port_val = inw(synth_portlist[i]) & 0xfbff;
35262306a36Sopenharmony_ci			if (port_val == 0x107f) {
35362306a36Sopenharmony_ci				synth_lpc = synth_portlist[i];
35462306a36Sopenharmony_ci				speakup_info.port_tts = synth_lpc + 1;
35562306a36Sopenharmony_ci				break;
35662306a36Sopenharmony_ci			}
35762306a36Sopenharmony_ci			synth_release_region(synth_portlist[i],
35862306a36Sopenharmony_ci					     SYNTH_IO_EXTENT);
35962306a36Sopenharmony_ci		}
36062306a36Sopenharmony_ci	}
36162306a36Sopenharmony_ci	port_val &= 0xfbff;
36262306a36Sopenharmony_ci	if (port_val != 0x107f) {
36362306a36Sopenharmony_ci		pr_info("DoubleTalk PC: not found\n");
36462306a36Sopenharmony_ci		if (synth_lpc)
36562306a36Sopenharmony_ci			synth_release_region(synth_lpc, SYNTH_IO_EXTENT);
36662306a36Sopenharmony_ci		return -ENODEV;
36762306a36Sopenharmony_ci	}
36862306a36Sopenharmony_ci	while (inw_p(synth_lpc) != 0x147f)
36962306a36Sopenharmony_ci		cpu_relax(); /* wait until it's ready */
37062306a36Sopenharmony_ci	sp = synth_interrogate(synth);
37162306a36Sopenharmony_ci	pr_info("%s: %03x-%03x, ROM ver %s, s/n %u, driver: %s\n",
37262306a36Sopenharmony_ci		synth->long_name, synth_lpc, synth_lpc + SYNTH_IO_EXTENT - 1,
37362306a36Sopenharmony_ci		sp->rom_version, sp->serial_number, synth->version);
37462306a36Sopenharmony_ci	synth->alive = 1;
37562306a36Sopenharmony_ci	return 0;
37662306a36Sopenharmony_ci}
37762306a36Sopenharmony_ci
37862306a36Sopenharmony_cistatic void dtlk_release(struct spk_synth *synth)
37962306a36Sopenharmony_ci{
38062306a36Sopenharmony_ci	spk_stop_serial_interrupt();
38162306a36Sopenharmony_ci	if (speakup_info.port_tts)
38262306a36Sopenharmony_ci		synth_release_region(speakup_info.port_tts - 1,
38362306a36Sopenharmony_ci				     SYNTH_IO_EXTENT);
38462306a36Sopenharmony_ci	speakup_info.port_tts = 0;
38562306a36Sopenharmony_ci}
38662306a36Sopenharmony_ci
38762306a36Sopenharmony_cimodule_param_hw_named(port, port_forced, int, ioport, 0444);
38862306a36Sopenharmony_cimodule_param_named(start, synth_dtlk.startup, short, 0444);
38962306a36Sopenharmony_cimodule_param_named(rate, vars[RATE_ID].u.n.default_val, int, 0444);
39062306a36Sopenharmony_cimodule_param_named(pitch, vars[PITCH_ID].u.n.default_val, int, 0444);
39162306a36Sopenharmony_cimodule_param_named(vol, vars[VOL_ID].u.n.default_val, int, 0444);
39262306a36Sopenharmony_cimodule_param_named(tone, vars[TONE_ID].u.n.default_val, int, 0444);
39362306a36Sopenharmony_cimodule_param_named(punct, vars[PUNCT_ID].u.n.default_val, int, 0444);
39462306a36Sopenharmony_cimodule_param_named(voice, vars[VOICE_ID].u.n.default_val, int, 0444);
39562306a36Sopenharmony_cimodule_param_named(frequency, vars[FREQUENCY_ID].u.n.default_val, int, 0444);
39662306a36Sopenharmony_cimodule_param_named(direct, vars[DIRECT_ID].u.n.default_val, int, 0444);
39762306a36Sopenharmony_ci
39862306a36Sopenharmony_ci
39962306a36Sopenharmony_ciMODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
40062306a36Sopenharmony_ciMODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
40162306a36Sopenharmony_ciMODULE_PARM_DESC(rate, "Set the rate variable on load.");
40262306a36Sopenharmony_ciMODULE_PARM_DESC(pitch, "Set the pitch variable on load.");
40362306a36Sopenharmony_ciMODULE_PARM_DESC(vol, "Set the vol variable on load.");
40462306a36Sopenharmony_ciMODULE_PARM_DESC(tone, "Set the tone variable on load.");
40562306a36Sopenharmony_ciMODULE_PARM_DESC(punct, "Set the punct variable on load.");
40662306a36Sopenharmony_ciMODULE_PARM_DESC(voice, "Set the voice variable on load.");
40762306a36Sopenharmony_ciMODULE_PARM_DESC(frequency, "Set the frequency variable on load.");
40862306a36Sopenharmony_ciMODULE_PARM_DESC(direct, "Set the direct variable on load.");
40962306a36Sopenharmony_ci
41062306a36Sopenharmony_ci
41162306a36Sopenharmony_cimodule_spk_synth(synth_dtlk);
41262306a36Sopenharmony_ci
41362306a36Sopenharmony_ciMODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
41462306a36Sopenharmony_ciMODULE_AUTHOR("David Borowski");
41562306a36Sopenharmony_ciMODULE_DESCRIPTION("Speakup support for DoubleTalk PC synthesizers");
41662306a36Sopenharmony_ciMODULE_LICENSE("GPL");
41762306a36Sopenharmony_ciMODULE_VERSION(DRV_VERSION);
41862306a36Sopenharmony_ci
419