1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
4 * this version considerably modified by David Borowski, david575@rogers.com
5 *
6 * Copyright (C) 1998-99  Kirk Reiser.
7 * Copyright (C) 2003 David Borowski.
8 *
9 * specificly written as a driver for the speakup screenreview
10 * s not a general device driver.
11 */
12#include "spk_priv.h"
13#include "speakup.h"
14
15#define DRV_VERSION "2.11"
16#define SYNTH_CLEAR 0x18
17#define PROCSPEECH '\r'
18
19static void synth_flush(struct spk_synth *synth);
20
21static struct var_t vars[] = {
22	{ CAPS_START, .u.s = {"\x05P+" } },
23	{ CAPS_STOP, .u.s = {"\x05P-" } },
24	{ RATE, .u.n = {"\x05R%d", 7, 0, 9, 0, 0, NULL } },
25	{ PITCH, .u.n = {"\x05P%d", 3, 0, 9, 0, 0, NULL } },
26	{ VOL, .u.n = {"\x05V%d", 9, 0, 9, 0, 0, NULL } },
27	{ TONE, .u.n = {"\x05T%c", 8, 0, 25, 65, 0, NULL } },
28	{ PUNCT, .u.n = {"\x05M%c", 0, 0, 3, 0, 0, "nsma" } },
29	{ DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
30	V_LAST_VAR
31};
32
33/* These attributes will appear in /sys/accessibility/speakup/spkout. */
34
35static struct kobj_attribute caps_start_attribute =
36	__ATTR(caps_start, 0644, spk_var_show, spk_var_store);
37static struct kobj_attribute caps_stop_attribute =
38	__ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
39static struct kobj_attribute pitch_attribute =
40	__ATTR(pitch, 0644, spk_var_show, spk_var_store);
41static struct kobj_attribute punct_attribute =
42	__ATTR(punct, 0644, spk_var_show, spk_var_store);
43static struct kobj_attribute rate_attribute =
44	__ATTR(rate, 0644, spk_var_show, spk_var_store);
45static struct kobj_attribute tone_attribute =
46	__ATTR(tone, 0644, spk_var_show, spk_var_store);
47static struct kobj_attribute vol_attribute =
48	__ATTR(vol, 0644, spk_var_show, spk_var_store);
49
50static struct kobj_attribute delay_time_attribute =
51	__ATTR(delay_time, 0644, spk_var_show, spk_var_store);
52static struct kobj_attribute direct_attribute =
53	__ATTR(direct, 0644, spk_var_show, spk_var_store);
54static struct kobj_attribute full_time_attribute =
55	__ATTR(full_time, 0644, spk_var_show, spk_var_store);
56static struct kobj_attribute jiffy_delta_attribute =
57	__ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
58static struct kobj_attribute trigger_time_attribute =
59	__ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
60
61/*
62 * Create a group of attributes so that we can create and destroy them all
63 * at once.
64 */
65static struct attribute *synth_attrs[] = {
66	&caps_start_attribute.attr,
67	&caps_stop_attribute.attr,
68	&pitch_attribute.attr,
69	&punct_attribute.attr,
70	&rate_attribute.attr,
71	&tone_attribute.attr,
72	&vol_attribute.attr,
73	&delay_time_attribute.attr,
74	&direct_attribute.attr,
75	&full_time_attribute.attr,
76	&jiffy_delta_attribute.attr,
77	&trigger_time_attribute.attr,
78	NULL,	/* need to NULL terminate the list of attributes */
79};
80
81static struct spk_synth synth_spkout = {
82	.name = "spkout",
83	.version = DRV_VERSION,
84	.long_name = "Speakout",
85	.init = "\005W1\005I2\005C3",
86	.procspeech = PROCSPEECH,
87	.clear = SYNTH_CLEAR,
88	.delay = 500,
89	.trigger = 50,
90	.jiffies = 50,
91	.full = 40000,
92	.dev_name = SYNTH_DEFAULT_DEV,
93	.startup = SYNTH_START,
94	.checkval = SYNTH_CHECK,
95	.vars = vars,
96	.io_ops = &spk_ttyio_ops,
97	.probe = spk_ttyio_synth_probe,
98	.release = spk_ttyio_release,
99	.synth_immediate = spk_ttyio_synth_immediate,
100	.catch_up = spk_do_catch_up,
101	.flush = synth_flush,
102	.is_alive = spk_synth_is_alive_restart,
103	.synth_adjust = NULL,
104	.read_buff_add = NULL,
105	.get_index = spk_synth_get_index,
106	.indexing = {
107		.command = "\x05[%c",
108		.lowindex = 1,
109		.highindex = 5,
110		.currindex = 1,
111	},
112	.attributes = {
113		.attrs = synth_attrs,
114		.name = "spkout",
115	},
116};
117
118static void synth_flush(struct spk_synth *synth)
119{
120	synth->io_ops->flush_buffer();
121	synth->io_ops->send_xchar(SYNTH_CLEAR);
122}
123
124module_param_named(ser, synth_spkout.ser, int, 0444);
125module_param_named(dev, synth_spkout.dev_name, charp, 0444);
126module_param_named(start, synth_spkout.startup, short, 0444);
127
128MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
129MODULE_PARM_DESC(dev, "Set the device e.g. ttyUSB0, for the synthesizer.");
130MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
131
132module_spk_synth(synth_spkout);
133
134MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
135MODULE_AUTHOR("David Borowski");
136MODULE_DESCRIPTION("Speakup support for Speak Out synthesizers");
137MODULE_LICENSE("GPL");
138MODULE_VERSION(DRV_VERSION);
139
140