18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
48c2ecf20Sopenharmony_ci * this version considerably modified by David Borowski, david575@rogers.com
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 1998-99  Kirk Reiser.
78c2ecf20Sopenharmony_ci * Copyright (C) 2003 David Borowski.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * specificly written as a driver for the speakup screenreview
108c2ecf20Sopenharmony_ci * s not a general device driver.
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci#include "spk_priv.h"
138c2ecf20Sopenharmony_ci#include "speakup.h"
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#define DRV_VERSION "2.11"
168c2ecf20Sopenharmony_ci#define SYNTH_CLEAR 0x18 /* flush synth buffer */
178c2ecf20Sopenharmony_ci#define PROCSPEECH '\r' /* start synth processing speech char */
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistatic int synth_probe(struct spk_synth *synth);
208c2ecf20Sopenharmony_cistatic void synth_flush(struct spk_synth *synth);
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistatic struct var_t vars[] = {
238c2ecf20Sopenharmony_ci	{ CAPS_START, .u.s = {"\x05[f99]" } },
248c2ecf20Sopenharmony_ci	{ CAPS_STOP, .u.s = {"\x05[f80]" } },
258c2ecf20Sopenharmony_ci	{ RATE, .u.n = {"\x05[r%d]", 10, 0, 20, 100, -10, NULL } },
268c2ecf20Sopenharmony_ci	{ PITCH, .u.n = {"\x05[f%d]", 80, 39, 4500, 0, 0, NULL } },
278c2ecf20Sopenharmony_ci	{ VOL, .u.n = {"\x05[g%d]", 21, 0, 40, 0, 0, NULL } },
288c2ecf20Sopenharmony_ci	{ TONE, .u.n = {"\x05[s%d]", 9, 0, 63, 0, 0, NULL } },
298c2ecf20Sopenharmony_ci	{ PUNCT, .u.n = {"\x05[A%c]", 0, 0, 3, 0, 0, "nmsa" } },
308c2ecf20Sopenharmony_ci	{ DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
318c2ecf20Sopenharmony_ci	V_LAST_VAR
328c2ecf20Sopenharmony_ci};
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/*
358c2ecf20Sopenharmony_ci * These attributes will appear in /sys/accessibility/speakup/audptr.
368c2ecf20Sopenharmony_ci */
378c2ecf20Sopenharmony_cistatic struct kobj_attribute caps_start_attribute =
388c2ecf20Sopenharmony_ci	__ATTR(caps_start, 0644, spk_var_show, spk_var_store);
398c2ecf20Sopenharmony_cistatic struct kobj_attribute caps_stop_attribute =
408c2ecf20Sopenharmony_ci	__ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
418c2ecf20Sopenharmony_cistatic struct kobj_attribute pitch_attribute =
428c2ecf20Sopenharmony_ci	__ATTR(pitch, 0644, spk_var_show, spk_var_store);
438c2ecf20Sopenharmony_cistatic struct kobj_attribute punct_attribute =
448c2ecf20Sopenharmony_ci	__ATTR(punct, 0644, spk_var_show, spk_var_store);
458c2ecf20Sopenharmony_cistatic struct kobj_attribute rate_attribute =
468c2ecf20Sopenharmony_ci	__ATTR(rate, 0644, spk_var_show, spk_var_store);
478c2ecf20Sopenharmony_cistatic struct kobj_attribute tone_attribute =
488c2ecf20Sopenharmony_ci	__ATTR(tone, 0644, spk_var_show, spk_var_store);
498c2ecf20Sopenharmony_cistatic struct kobj_attribute vol_attribute =
508c2ecf20Sopenharmony_ci	__ATTR(vol, 0644, spk_var_show, spk_var_store);
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cistatic struct kobj_attribute delay_time_attribute =
538c2ecf20Sopenharmony_ci	__ATTR(delay_time, 0644, spk_var_show, spk_var_store);
548c2ecf20Sopenharmony_cistatic struct kobj_attribute direct_attribute =
558c2ecf20Sopenharmony_ci	__ATTR(direct, 0644, spk_var_show, spk_var_store);
568c2ecf20Sopenharmony_cistatic struct kobj_attribute full_time_attribute =
578c2ecf20Sopenharmony_ci	__ATTR(full_time, 0644, spk_var_show, spk_var_store);
588c2ecf20Sopenharmony_cistatic struct kobj_attribute jiffy_delta_attribute =
598c2ecf20Sopenharmony_ci	__ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
608c2ecf20Sopenharmony_cistatic struct kobj_attribute trigger_time_attribute =
618c2ecf20Sopenharmony_ci	__ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/*
648c2ecf20Sopenharmony_ci * Create a group of attributes so that we can create and destroy them all
658c2ecf20Sopenharmony_ci * at once.
668c2ecf20Sopenharmony_ci */
678c2ecf20Sopenharmony_cistatic struct attribute *synth_attrs[] = {
688c2ecf20Sopenharmony_ci	&caps_start_attribute.attr,
698c2ecf20Sopenharmony_ci	&caps_stop_attribute.attr,
708c2ecf20Sopenharmony_ci	&pitch_attribute.attr,
718c2ecf20Sopenharmony_ci	&punct_attribute.attr,
728c2ecf20Sopenharmony_ci	&rate_attribute.attr,
738c2ecf20Sopenharmony_ci	&tone_attribute.attr,
748c2ecf20Sopenharmony_ci	&vol_attribute.attr,
758c2ecf20Sopenharmony_ci	&delay_time_attribute.attr,
768c2ecf20Sopenharmony_ci	&direct_attribute.attr,
778c2ecf20Sopenharmony_ci	&full_time_attribute.attr,
788c2ecf20Sopenharmony_ci	&jiffy_delta_attribute.attr,
798c2ecf20Sopenharmony_ci	&trigger_time_attribute.attr,
808c2ecf20Sopenharmony_ci	NULL,	/* need to NULL terminate the list of attributes */
818c2ecf20Sopenharmony_ci};
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_cistatic struct spk_synth synth_audptr = {
848c2ecf20Sopenharmony_ci	.name = "audptr",
858c2ecf20Sopenharmony_ci	.version = DRV_VERSION,
868c2ecf20Sopenharmony_ci	.long_name = "Audapter",
878c2ecf20Sopenharmony_ci	.init = "\x05[D1]\x05[Ol]",
888c2ecf20Sopenharmony_ci	.procspeech = PROCSPEECH,
898c2ecf20Sopenharmony_ci	.clear = SYNTH_CLEAR,
908c2ecf20Sopenharmony_ci	.delay = 400,
918c2ecf20Sopenharmony_ci	.trigger = 50,
928c2ecf20Sopenharmony_ci	.jiffies = 30,
938c2ecf20Sopenharmony_ci	.full = 18000,
948c2ecf20Sopenharmony_ci	.dev_name = SYNTH_DEFAULT_DEV,
958c2ecf20Sopenharmony_ci	.startup = SYNTH_START,
968c2ecf20Sopenharmony_ci	.checkval = SYNTH_CHECK,
978c2ecf20Sopenharmony_ci	.vars = vars,
988c2ecf20Sopenharmony_ci	.io_ops = &spk_ttyio_ops,
998c2ecf20Sopenharmony_ci	.probe = synth_probe,
1008c2ecf20Sopenharmony_ci	.release = spk_ttyio_release,
1018c2ecf20Sopenharmony_ci	.synth_immediate = spk_ttyio_synth_immediate,
1028c2ecf20Sopenharmony_ci	.catch_up = spk_do_catch_up,
1038c2ecf20Sopenharmony_ci	.flush = synth_flush,
1048c2ecf20Sopenharmony_ci	.is_alive = spk_synth_is_alive_restart,
1058c2ecf20Sopenharmony_ci	.synth_adjust = NULL,
1068c2ecf20Sopenharmony_ci	.read_buff_add = NULL,
1078c2ecf20Sopenharmony_ci	.get_index = NULL,
1088c2ecf20Sopenharmony_ci	.indexing = {
1098c2ecf20Sopenharmony_ci		.command = NULL,
1108c2ecf20Sopenharmony_ci		.lowindex = 0,
1118c2ecf20Sopenharmony_ci		.highindex = 0,
1128c2ecf20Sopenharmony_ci		.currindex = 0,
1138c2ecf20Sopenharmony_ci	},
1148c2ecf20Sopenharmony_ci	.attributes = {
1158c2ecf20Sopenharmony_ci		.attrs = synth_attrs,
1168c2ecf20Sopenharmony_ci		.name = "audptr",
1178c2ecf20Sopenharmony_ci	},
1188c2ecf20Sopenharmony_ci};
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_cistatic void synth_flush(struct spk_synth *synth)
1218c2ecf20Sopenharmony_ci{
1228c2ecf20Sopenharmony_ci	synth->io_ops->flush_buffer();
1238c2ecf20Sopenharmony_ci	synth->io_ops->send_xchar(SYNTH_CLEAR);
1248c2ecf20Sopenharmony_ci	synth->io_ops->synth_out(synth, PROCSPEECH);
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cistatic void synth_version(struct spk_synth *synth)
1288c2ecf20Sopenharmony_ci{
1298c2ecf20Sopenharmony_ci	unsigned char test = 0;
1308c2ecf20Sopenharmony_ci	char synth_id[40] = "";
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	synth->synth_immediate(synth, "\x05[Q]");
1338c2ecf20Sopenharmony_ci	synth_id[test] = synth->io_ops->synth_in();
1348c2ecf20Sopenharmony_ci	if (synth_id[test] == 'A') {
1358c2ecf20Sopenharmony_ci		do {
1368c2ecf20Sopenharmony_ci			/* read version string from synth */
1378c2ecf20Sopenharmony_ci			synth_id[++test] = synth->io_ops->synth_in();
1388c2ecf20Sopenharmony_ci		} while (synth_id[test] != '\n' && test < 32);
1398c2ecf20Sopenharmony_ci		synth_id[++test] = 0x00;
1408c2ecf20Sopenharmony_ci	}
1418c2ecf20Sopenharmony_ci	if (synth_id[0] == 'A')
1428c2ecf20Sopenharmony_ci		pr_info("%s version: %s", synth->long_name, synth_id);
1438c2ecf20Sopenharmony_ci}
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistatic int synth_probe(struct spk_synth *synth)
1468c2ecf20Sopenharmony_ci{
1478c2ecf20Sopenharmony_ci	int failed;
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci	failed = spk_ttyio_synth_probe(synth);
1508c2ecf20Sopenharmony_ci	if (failed == 0)
1518c2ecf20Sopenharmony_ci		synth_version(synth);
1528c2ecf20Sopenharmony_ci	synth->alive = !failed;
1538c2ecf20Sopenharmony_ci	return 0;
1548c2ecf20Sopenharmony_ci}
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_cimodule_param_named(ser, synth_audptr.ser, int, 0444);
1578c2ecf20Sopenharmony_cimodule_param_named(dev, synth_audptr.dev_name, charp, 0444);
1588c2ecf20Sopenharmony_cimodule_param_named(start, synth_audptr.startup, short, 0444);
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ciMODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
1618c2ecf20Sopenharmony_ciMODULE_PARM_DESC(dev, "Set the device e.g. ttyUSB0, for the synthesizer.");
1628c2ecf20Sopenharmony_ciMODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_cimodule_spk_synth(synth_audptr);
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ciMODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
1678c2ecf20Sopenharmony_ciMODULE_AUTHOR("David Borowski");
1688c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Speakup support for Audapter synthesizer");
1698c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
1708c2ecf20Sopenharmony_ciMODULE_VERSION(DRV_VERSION);
1718c2ecf20Sopenharmony_ci
172