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