Greg Kroah-Hartman | 6496922 | 2018-01-11 11:08:40 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 2 | /* |
| 3 | * originally written by: Kirk Reiser <kirk@braille.uwo.ca> |
Arushi Singhal | 4d0bdcb | 2017-02-12 16:15:58 +0530 | [diff] [blame] | 4 | * this version considerably modified by David Borowski, david575@rogers.com |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 5 | * |
| 6 | * Copyright (C) 1998-99 Kirk Reiser. |
| 7 | * Copyright (C) 2003 David Borowski. |
| 8 | * |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 9 | * specificly written as a driver for the speakup screenreview |
| 10 | * s not a general device driver. |
| 11 | */ |
| 12 | #include <linux/jiffies.h> |
| 13 | #include <linux/sched.h> |
| 14 | #include <linux/timer.h> |
| 15 | #include <linux/kthread.h> |
| 16 | |
| 17 | #include "spk_priv.h" |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 18 | #include "speakup.h" |
| 19 | |
| 20 | #define DRV_VERSION "2.14" |
| 21 | #define SYNTH_CLEAR 0x03 |
| 22 | #define PROCSPEECH 0x0b |
Okash Khawaja | 470790e | 2017-05-15 18:45:36 +0100 | [diff] [blame] | 23 | |
Okash Khawaja | ca693dc | 2017-04-29 20:52:58 +0100 | [diff] [blame] | 24 | static volatile unsigned char last_char; |
Christopher Brannon | 3d4f7ea | 2010-10-14 19:23:51 -0500 | [diff] [blame] | 25 | |
Okash Khawaja | ca693dc | 2017-04-29 20:52:58 +0100 | [diff] [blame] | 26 | static void read_buff_add(u_char ch) |
Christopher Brannon | 3d4f7ea | 2010-10-14 19:23:51 -0500 | [diff] [blame] | 27 | { |
Okash Khawaja | ca693dc | 2017-04-29 20:52:58 +0100 | [diff] [blame] | 28 | last_char = ch; |
Christopher Brannon | 3d4f7ea | 2010-10-14 19:23:51 -0500 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static inline bool synth_full(void) |
| 32 | { |
Okash Khawaja | ca693dc | 2017-04-29 20:52:58 +0100 | [diff] [blame] | 33 | return last_char == 0x13; |
Christopher Brannon | 3d4f7ea | 2010-10-14 19:23:51 -0500 | [diff] [blame] | 34 | } |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 35 | |
| 36 | static void do_catch_up(struct spk_synth *synth); |
| 37 | static void synth_flush(struct spk_synth *synth); |
| 38 | |
| 39 | static int in_escape; |
| 40 | |
| 41 | static struct var_t vars[] = { |
Christopher Brannon | 3d4f7ea | 2010-10-14 19:23:51 -0500 | [diff] [blame] | 42 | { CAPS_START, .u.s = {"[:dv ap 222]" } }, |
| 43 | { CAPS_STOP, .u.s = {"[:dv ap 100]" } }, |
| 44 | { RATE, .u.n = {"[:ra %d]", 7, 0, 9, 150, 25, NULL } }, |
| 45 | { PITCH, .u.n = {"[:dv ap %d]", 100, 0, 100, 0, 0, NULL } }, |
Samuel Thibault | d97a9d7 | 2020-04-25 21:32:26 +0200 | [diff] [blame] | 46 | { INFLECTION, .u.n = {"[:dv pr %d] ", 100, 0, 10000, 0, 0, NULL } }, |
Christopher Brannon | 3d4f7ea | 2010-10-14 19:23:51 -0500 | [diff] [blame] | 47 | { VOL, .u.n = {"[:dv gv %d]", 13, 0, 16, 0, 5, NULL } }, |
| 48 | { PUNCT, .u.n = {"[:pu %c]", 0, 0, 2, 0, 0, "nsa" } }, |
| 49 | { VOICE, .u.n = {"[:n%c]", 0, 0, 9, 0, 0, "phfdburwkv" } }, |
| 50 | { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } }, |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 51 | V_LAST_VAR |
| 52 | }; |
| 53 | |
| 54 | /* |
| 55 | * These attributes will appear in /sys/accessibility/speakup/decext. |
| 56 | */ |
| 57 | static struct kobj_attribute caps_start_attribute = |
Derek Robson | 73c3700 | 2017-01-28 19:35:01 +1300 | [diff] [blame] | 58 | __ATTR(caps_start, 0644, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 59 | static struct kobj_attribute caps_stop_attribute = |
Derek Robson | 73c3700 | 2017-01-28 19:35:01 +1300 | [diff] [blame] | 60 | __ATTR(caps_stop, 0644, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 61 | static struct kobj_attribute pitch_attribute = |
Derek Robson | 73c3700 | 2017-01-28 19:35:01 +1300 | [diff] [blame] | 62 | __ATTR(pitch, 0644, spk_var_show, spk_var_store); |
Samuel Thibault | d97a9d7 | 2020-04-25 21:32:26 +0200 | [diff] [blame] | 63 | static struct kobj_attribute inflection_attribute = |
| 64 | __ATTR(inflection, 0644, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 65 | static struct kobj_attribute punct_attribute = |
Derek Robson | 73c3700 | 2017-01-28 19:35:01 +1300 | [diff] [blame] | 66 | __ATTR(punct, 0644, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 67 | static struct kobj_attribute rate_attribute = |
Derek Robson | 73c3700 | 2017-01-28 19:35:01 +1300 | [diff] [blame] | 68 | __ATTR(rate, 0644, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 69 | static struct kobj_attribute voice_attribute = |
Derek Robson | 73c3700 | 2017-01-28 19:35:01 +1300 | [diff] [blame] | 70 | __ATTR(voice, 0644, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 71 | static struct kobj_attribute vol_attribute = |
Derek Robson | 73c3700 | 2017-01-28 19:35:01 +1300 | [diff] [blame] | 72 | __ATTR(vol, 0644, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 73 | |
| 74 | static struct kobj_attribute delay_time_attribute = |
Derek Robson | 73c3700 | 2017-01-28 19:35:01 +1300 | [diff] [blame] | 75 | __ATTR(delay_time, 0644, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 76 | static struct kobj_attribute direct_attribute = |
Derek Robson | 73c3700 | 2017-01-28 19:35:01 +1300 | [diff] [blame] | 77 | __ATTR(direct, 0644, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 78 | static struct kobj_attribute full_time_attribute = |
Derek Robson | 73c3700 | 2017-01-28 19:35:01 +1300 | [diff] [blame] | 79 | __ATTR(full_time, 0644, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 80 | static struct kobj_attribute jiffy_delta_attribute = |
Derek Robson | 73c3700 | 2017-01-28 19:35:01 +1300 | [diff] [blame] | 81 | __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 82 | static struct kobj_attribute trigger_time_attribute = |
Derek Robson | 73c3700 | 2017-01-28 19:35:01 +1300 | [diff] [blame] | 83 | __ATTR(trigger_time, 0644, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 84 | |
| 85 | /* |
| 86 | * Create a group of attributes so that we can create and destroy them all |
| 87 | * at once. |
| 88 | */ |
| 89 | static struct attribute *synth_attrs[] = { |
| 90 | &caps_start_attribute.attr, |
| 91 | &caps_stop_attribute.attr, |
| 92 | &pitch_attribute.attr, |
Samuel Thibault | d97a9d7 | 2020-04-25 21:32:26 +0200 | [diff] [blame] | 93 | &inflection_attribute.attr, |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 94 | &punct_attribute.attr, |
| 95 | &rate_attribute.attr, |
| 96 | &voice_attribute.attr, |
| 97 | &vol_attribute.attr, |
| 98 | &delay_time_attribute.attr, |
| 99 | &direct_attribute.attr, |
| 100 | &full_time_attribute.attr, |
| 101 | &jiffy_delta_attribute.attr, |
| 102 | &trigger_time_attribute.attr, |
| 103 | NULL, /* need to NULL terminate the list of attributes */ |
| 104 | }; |
| 105 | |
| 106 | static struct spk_synth synth_decext = { |
| 107 | .name = "decext", |
| 108 | .version = DRV_VERSION, |
| 109 | .long_name = "Dectalk External", |
| 110 | .init = "[:pe -380]", |
| 111 | .procspeech = PROCSPEECH, |
| 112 | .clear = SYNTH_CLEAR, |
| 113 | .delay = 500, |
| 114 | .trigger = 50, |
| 115 | .jiffies = 50, |
| 116 | .full = 40000, |
| 117 | .flags = SF_DEC, |
Okash Khawaja | 8a21ff7 | 2017-06-25 19:40:02 +0100 | [diff] [blame] | 118 | .dev_name = SYNTH_DEFAULT_DEV, |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 119 | .startup = SYNTH_START, |
| 120 | .checkval = SYNTH_CHECK, |
| 121 | .vars = vars, |
Okash Khawaja | 470790e | 2017-05-15 18:45:36 +0100 | [diff] [blame] | 122 | .io_ops = &spk_ttyio_ops, |
| 123 | .probe = spk_ttyio_synth_probe, |
| 124 | .release = spk_ttyio_release, |
| 125 | .synth_immediate = spk_ttyio_synth_immediate, |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 126 | .catch_up = do_catch_up, |
| 127 | .flush = synth_flush, |
| 128 | .is_alive = spk_synth_is_alive_restart, |
| 129 | .synth_adjust = NULL, |
Okash Khawaja | ca693dc | 2017-04-29 20:52:58 +0100 | [diff] [blame] | 130 | .read_buff_add = read_buff_add, |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 131 | .get_index = NULL, |
| 132 | .indexing = { |
| 133 | .command = NULL, |
| 134 | .lowindex = 0, |
| 135 | .highindex = 0, |
| 136 | .currindex = 0, |
| 137 | }, |
| 138 | .attributes = { |
| 139 | .attrs = synth_attrs, |
| 140 | .name = "decext", |
| 141 | }, |
| 142 | }; |
| 143 | |
| 144 | static void do_catch_up(struct spk_synth *synth) |
| 145 | { |
| 146 | u_char ch; |
| 147 | static u_char last = '\0'; |
| 148 | unsigned long flags; |
| 149 | unsigned long jiff_max; |
| 150 | struct var_t *jiffy_delta; |
| 151 | struct var_t *delay_time; |
| 152 | int jiffy_delta_val = 0; |
| 153 | int delay_time_val = 0; |
| 154 | |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 155 | jiffy_delta = spk_get_var(JIFFY); |
| 156 | delay_time = spk_get_var(DELAY); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 157 | |
William Hubbs | b4b93e3 | 2013-05-13 00:03:01 -0500 | [diff] [blame] | 158 | spin_lock_irqsave(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 159 | jiffy_delta_val = jiffy_delta->u.n.value; |
William Hubbs | b4b93e3 | 2013-05-13 00:03:01 -0500 | [diff] [blame] | 160 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 161 | jiff_max = jiffies + jiffy_delta_val; |
| 162 | |
| 163 | while (!kthread_should_stop()) { |
William Hubbs | b4b93e3 | 2013-05-13 00:03:01 -0500 | [diff] [blame] | 164 | spin_lock_irqsave(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 165 | if (speakup_info.flushing) { |
| 166 | speakup_info.flushing = 0; |
William Hubbs | b4b93e3 | 2013-05-13 00:03:01 -0500 | [diff] [blame] | 167 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 168 | synth->flush(synth); |
| 169 | continue; |
| 170 | } |
Samuel Thibault | 89fc2ae | 2017-03-04 15:01:55 +0100 | [diff] [blame] | 171 | synth_buffer_skip_nonlatin1(); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 172 | if (synth_buffer_empty()) { |
William Hubbs | b4b93e3 | 2013-05-13 00:03:01 -0500 | [diff] [blame] | 173 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 174 | break; |
| 175 | } |
| 176 | ch = synth_buffer_peek(); |
| 177 | set_current_state(TASK_INTERRUPTIBLE); |
| 178 | delay_time_val = delay_time->u.n.value; |
William Hubbs | b4b93e3 | 2013-05-13 00:03:01 -0500 | [diff] [blame] | 179 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 180 | if (ch == '\n') |
| 181 | ch = 0x0D; |
Okash Khawaja | 1e44159 | 2017-03-14 13:41:53 +0000 | [diff] [blame] | 182 | if (synth_full() || !synth->io_ops->synth_out(synth, ch)) { |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 183 | schedule_timeout(msecs_to_jiffies(delay_time_val)); |
| 184 | continue; |
| 185 | } |
| 186 | set_current_state(TASK_RUNNING); |
William Hubbs | b4b93e3 | 2013-05-13 00:03:01 -0500 | [diff] [blame] | 187 | spin_lock_irqsave(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 188 | synth_buffer_getc(); |
William Hubbs | b4b93e3 | 2013-05-13 00:03:01 -0500 | [diff] [blame] | 189 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
Arushi Singhal | 0dcb212 | 2017-03-21 17:12:28 +0530 | [diff] [blame] | 190 | if (ch == '[') { |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 191 | in_escape = 1; |
Arushi Singhal | 0dcb212 | 2017-03-21 17:12:28 +0530 | [diff] [blame] | 192 | } else if (ch == ']') { |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 193 | in_escape = 0; |
Arushi Singhal | 0dcb212 | 2017-03-21 17:12:28 +0530 | [diff] [blame] | 194 | } else if (ch <= SPACE) { |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 195 | if (!in_escape && strchr(",.!?;:", last)) |
Okash Khawaja | 1e44159 | 2017-03-14 13:41:53 +0000 | [diff] [blame] | 196 | synth->io_ops->synth_out(synth, PROCSPEECH); |
Tapasweni Pathak | 89021ec | 2014-09-21 19:22:51 +0530 | [diff] [blame] | 197 | if (time_after_eq(jiffies, jiff_max)) { |
Christopher Brannon | 3d4f7ea | 2010-10-14 19:23:51 -0500 | [diff] [blame] | 198 | if (!in_escape) |
Bhagyashri Dighole | e2d5501 | 2019-02-28 17:59:04 +0530 | [diff] [blame] | 199 | synth->io_ops->synth_out(synth, |
| 200 | PROCSPEECH); |
Shirish Gajera | 63b8ebe | 2015-03-28 13:21:39 -0700 | [diff] [blame] | 201 | spin_lock_irqsave(&speakup_info.spinlock, |
Arushi Singhal | f239d3d | 2017-03-24 16:47:27 +0530 | [diff] [blame] | 202 | flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 203 | jiffy_delta_val = jiffy_delta->u.n.value; |
| 204 | delay_time_val = delay_time->u.n.value; |
Shirish Gajera | 63b8ebe | 2015-03-28 13:21:39 -0700 | [diff] [blame] | 205 | spin_unlock_irqrestore(&speakup_info.spinlock, |
Arushi Singhal | f239d3d | 2017-03-24 16:47:27 +0530 | [diff] [blame] | 206 | flags); |
Christopher Brannon | 3d4f7ea | 2010-10-14 19:23:51 -0500 | [diff] [blame] | 207 | schedule_timeout(msecs_to_jiffies |
| 208 | (delay_time_val)); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 209 | jiff_max = jiffies + jiffy_delta_val; |
| 210 | } |
| 211 | } |
| 212 | last = ch; |
| 213 | } |
| 214 | if (!in_escape) |
Okash Khawaja | 1e44159 | 2017-03-14 13:41:53 +0000 | [diff] [blame] | 215 | synth->io_ops->synth_out(synth, PROCSPEECH); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static void synth_flush(struct spk_synth *synth) |
| 219 | { |
| 220 | in_escape = 0; |
Samuel Thibault | 1941ab1 | 2021-01-26 23:21:44 +0100 | [diff] [blame] | 221 | synth->io_ops->flush_buffer(synth); |
Okash Khawaja | 98c1fda | 2017-03-16 08:10:17 +0000 | [diff] [blame] | 222 | synth->synth_immediate(synth, "\033P;10z\033\\"); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 223 | } |
| 224 | |
Derek Robson | 73c3700 | 2017-01-28 19:35:01 +1300 | [diff] [blame] | 225 | module_param_named(ser, synth_decext.ser, int, 0444); |
Mihaela Muraru | b5a603d | 2017-09-24 11:49:41 +0300 | [diff] [blame] | 226 | module_param_named(dev, synth_decext.dev_name, charp, 0444); |
Derek Robson | 73c3700 | 2017-01-28 19:35:01 +1300 | [diff] [blame] | 227 | module_param_named(start, synth_decext.startup, short, 0444); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 228 | |
| 229 | MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based)."); |
Okash Khawaja | 8a21ff7 | 2017-06-25 19:40:02 +0100 | [diff] [blame] | 230 | MODULE_PARM_DESC(dev, "Set the device e.g. ttyUSB0, for the synthesizer."); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 231 | MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); |
| 232 | |
Vaishali Thakkar | ae89fac | 2015-03-18 23:13:10 +0530 | [diff] [blame] | 233 | module_spk_synth(synth_decext); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 234 | |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 235 | MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>"); |
| 236 | MODULE_AUTHOR("David Borowski"); |
| 237 | MODULE_DESCRIPTION("Speakup support for DECtalk External synthesizers"); |
| 238 | MODULE_LICENSE("GPL"); |
| 239 | MODULE_VERSION(DRV_VERSION); |
| 240 | |