William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 1 | /* |
| 2 | * originally written by: Kirk Reiser <kirk@braille.uwo.ca> |
| 3 | * this version considerably modified by David Borowski, david575@rogers.com |
| 4 | * |
| 5 | * Copyright (C) 1998-99 Kirk Reiser. |
| 6 | * Copyright (C) 2003 David Borowski. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | * this code is specificly written as a driver for the speakup screenreview |
| 23 | * package and is not a general device driver. |
| 24 | */ |
| 25 | #include <linux/jiffies.h> |
| 26 | #include <linux/sched.h> |
| 27 | #include <linux/timer.h> |
| 28 | #include <linux/kthread.h> |
| 29 | |
| 30 | #include "spk_priv.h" |
| 31 | #include "serialio.h" |
| 32 | #include "speakup.h" |
| 33 | |
| 34 | #define DRV_VERSION "2.21" |
| 35 | #define SYNTH_CLEAR 0x18 |
| 36 | #define PROCSPEECH '\r' |
| 37 | |
| 38 | static void do_catch_up(struct spk_synth *synth); |
| 39 | |
| 40 | static struct var_t vars[] = { |
Christopher Brannon | f493144 | 2010-10-14 19:23:48 -0500 | [diff] [blame] | 41 | { CAPS_START, .u.s = {"cap, " } }, |
| 42 | { CAPS_STOP, .u.s = {"" } }, |
| 43 | { RATE, .u.n = {"@W%d", 6, 1, 9, 0, 0, NULL } }, |
| 44 | { PITCH, .u.n = {"@F%x", 10, 0, 15, 0, 0, NULL } }, |
| 45 | { VOL, .u.n = {"@A%x", 10, 0, 15, 0, 0, NULL } }, |
| 46 | { VOICE, .u.n = {"@V%d", 1, 1, 6, 0, 0, NULL } }, |
| 47 | { LANG, .u.n = {"@=%d,", 1, 1, 4, 0, 0, NULL } }, |
| 48 | { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } }, |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 49 | V_LAST_VAR |
| 50 | }; |
| 51 | |
| 52 | /* |
| 53 | * These attributes will appear in /sys/accessibility/speakup/apollo. |
| 54 | */ |
| 55 | static struct kobj_attribute caps_start_attribute = |
Rusty Russell | d901aaa | 2014-04-24 13:57:49 +0930 | [diff] [blame] | 56 | __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 57 | static struct kobj_attribute caps_stop_attribute = |
Rusty Russell | d901aaa | 2014-04-24 13:57:49 +0930 | [diff] [blame] | 58 | __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 59 | static struct kobj_attribute lang_attribute = |
Rusty Russell | d901aaa | 2014-04-24 13:57:49 +0930 | [diff] [blame] | 60 | __ATTR(lang, S_IWUSR|S_IRUGO, 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 = |
Rusty Russell | d901aaa | 2014-04-24 13:57:49 +0930 | [diff] [blame] | 62 | __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 63 | static struct kobj_attribute rate_attribute = |
Rusty Russell | d901aaa | 2014-04-24 13:57:49 +0930 | [diff] [blame] | 64 | __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 65 | static struct kobj_attribute voice_attribute = |
Rusty Russell | d901aaa | 2014-04-24 13:57:49 +0930 | [diff] [blame] | 66 | __ATTR(voice, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 67 | static struct kobj_attribute vol_attribute = |
Rusty Russell | d901aaa | 2014-04-24 13:57:49 +0930 | [diff] [blame] | 68 | __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 69 | |
| 70 | static struct kobj_attribute delay_time_attribute = |
Rusty Russell | 22c9bca | 2014-04-01 13:30:05 +1030 | [diff] [blame] | 71 | __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 72 | static struct kobj_attribute direct_attribute = |
Rusty Russell | d901aaa | 2014-04-24 13:57:49 +0930 | [diff] [blame] | 73 | __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 74 | static struct kobj_attribute full_time_attribute = |
Rusty Russell | 22c9bca | 2014-04-01 13:30:05 +1030 | [diff] [blame] | 75 | __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 76 | static struct kobj_attribute jiffy_delta_attribute = |
Rusty Russell | 22c9bca | 2014-04-01 13:30:05 +1030 | [diff] [blame] | 77 | __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 78 | static struct kobj_attribute trigger_time_attribute = |
Rusty Russell | 22c9bca | 2014-04-01 13:30:05 +1030 | [diff] [blame] | 79 | __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | * Create a group of attributes so that we can create and destroy them all |
| 83 | * at once. |
| 84 | */ |
| 85 | static struct attribute *synth_attrs[] = { |
| 86 | &caps_start_attribute.attr, |
| 87 | &caps_stop_attribute.attr, |
| 88 | &lang_attribute.attr, |
| 89 | &pitch_attribute.attr, |
| 90 | &rate_attribute.attr, |
| 91 | &voice_attribute.attr, |
| 92 | &vol_attribute.attr, |
| 93 | &delay_time_attribute.attr, |
| 94 | &direct_attribute.attr, |
| 95 | &full_time_attribute.attr, |
| 96 | &jiffy_delta_attribute.attr, |
| 97 | &trigger_time_attribute.attr, |
| 98 | NULL, /* need to NULL terminate the list of attributes */ |
| 99 | }; |
| 100 | |
| 101 | static struct spk_synth synth_apollo = { |
| 102 | .name = "apollo", |
| 103 | .version = DRV_VERSION, |
| 104 | .long_name = "Apollo", |
| 105 | .init = "@R3@D0@K1\r", |
| 106 | .procspeech = PROCSPEECH, |
| 107 | .clear = SYNTH_CLEAR, |
| 108 | .delay = 500, |
| 109 | .trigger = 50, |
| 110 | .jiffies = 50, |
| 111 | .full = 40000, |
| 112 | .startup = SYNTH_START, |
| 113 | .checkval = SYNTH_CHECK, |
| 114 | .vars = vars, |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 115 | .probe = spk_serial_synth_probe, |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 116 | .release = spk_serial_release, |
| 117 | .synth_immediate = spk_synth_immediate, |
| 118 | .catch_up = do_catch_up, |
| 119 | .flush = spk_synth_flush, |
| 120 | .is_alive = spk_synth_is_alive_restart, |
| 121 | .synth_adjust = NULL, |
| 122 | .read_buff_add = NULL, |
| 123 | .get_index = NULL, |
| 124 | .indexing = { |
| 125 | .command = NULL, |
| 126 | .lowindex = 0, |
| 127 | .highindex = 0, |
| 128 | .currindex = 0, |
| 129 | }, |
| 130 | .attributes = { |
| 131 | .attrs = synth_attrs, |
| 132 | .name = "apollo", |
| 133 | }, |
| 134 | }; |
| 135 | |
| 136 | static void do_catch_up(struct spk_synth *synth) |
| 137 | { |
| 138 | u_char ch; |
| 139 | unsigned long flags; |
| 140 | unsigned long jiff_max; |
| 141 | struct var_t *jiffy_delta; |
| 142 | struct var_t *delay_time; |
| 143 | struct var_t *full_time; |
| 144 | int full_time_val = 0; |
| 145 | int delay_time_val = 0; |
| 146 | int jiffy_delta_val = 0; |
| 147 | |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 148 | jiffy_delta = spk_get_var(JIFFY); |
| 149 | delay_time = spk_get_var(DELAY); |
| 150 | full_time = spk_get_var(FULL); |
William Hubbs | 6ca4dbe | 2013-05-13 00:03:00 -0500 | [diff] [blame] | 151 | spin_lock_irqsave(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 152 | jiffy_delta_val = jiffy_delta->u.n.value; |
William Hubbs | 6ca4dbe | 2013-05-13 00:03:00 -0500 | [diff] [blame] | 153 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 154 | jiff_max = jiffies + jiffy_delta_val; |
| 155 | |
| 156 | while (!kthread_should_stop()) { |
William Hubbs | 6ca4dbe | 2013-05-13 00:03:00 -0500 | [diff] [blame] | 157 | spin_lock_irqsave(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 158 | jiffy_delta_val = jiffy_delta->u.n.value; |
| 159 | full_time_val = full_time->u.n.value; |
| 160 | delay_time_val = delay_time->u.n.value; |
| 161 | if (speakup_info.flushing) { |
| 162 | speakup_info.flushing = 0; |
William Hubbs | 6ca4dbe | 2013-05-13 00:03:00 -0500 | [diff] [blame] | 163 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 164 | synth->flush(synth); |
| 165 | continue; |
| 166 | } |
| 167 | if (synth_buffer_empty()) { |
William Hubbs | 6ca4dbe | 2013-05-13 00:03:00 -0500 | [diff] [blame] | 168 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 169 | break; |
| 170 | } |
| 171 | ch = synth_buffer_peek(); |
| 172 | set_current_state(TASK_INTERRUPTIBLE); |
| 173 | full_time_val = full_time->u.n.value; |
William Hubbs | 6ca4dbe | 2013-05-13 00:03:00 -0500 | [diff] [blame] | 174 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 175 | if (!spk_serial_out(ch)) { |
| 176 | outb(UART_MCR_DTR, speakup_info.port_tts + UART_MCR); |
| 177 | outb(UART_MCR_DTR | UART_MCR_RTS, |
| 178 | speakup_info.port_tts + UART_MCR); |
| 179 | schedule_timeout(msecs_to_jiffies(full_time_val)); |
| 180 | continue; |
| 181 | } |
Ashvini Varatharaj | c45a9a9 | 2013-10-19 09:00:59 +0530 | [diff] [blame] | 182 | if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) { |
William Hubbs | 6ca4dbe | 2013-05-13 00:03:00 -0500 | [diff] [blame] | 183 | spin_lock_irqsave(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 184 | jiffy_delta_val = jiffy_delta->u.n.value; |
| 185 | full_time_val = full_time->u.n.value; |
| 186 | delay_time_val = delay_time->u.n.value; |
William Hubbs | 6ca4dbe | 2013-05-13 00:03:00 -0500 | [diff] [blame] | 187 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 188 | if (spk_serial_out(synth->procspeech)) |
Christopher Brannon | f493144 | 2010-10-14 19:23:48 -0500 | [diff] [blame] | 189 | schedule_timeout(msecs_to_jiffies |
| 190 | (delay_time_val)); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 191 | else |
Christopher Brannon | f493144 | 2010-10-14 19:23:48 -0500 | [diff] [blame] | 192 | schedule_timeout(msecs_to_jiffies |
| 193 | (full_time_val)); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 194 | jiff_max = jiffies + jiffy_delta_val; |
| 195 | } |
| 196 | set_current_state(TASK_RUNNING); |
William Hubbs | 6ca4dbe | 2013-05-13 00:03:00 -0500 | [diff] [blame] | 197 | spin_lock_irqsave(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 198 | synth_buffer_getc(); |
William Hubbs | 6ca4dbe | 2013-05-13 00:03:00 -0500 | [diff] [blame] | 199 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 200 | } |
| 201 | spk_serial_out(PROCSPEECH); |
| 202 | } |
| 203 | |
| 204 | module_param_named(ser, synth_apollo.ser, int, S_IRUGO); |
| 205 | module_param_named(start, synth_apollo.startup, short, S_IRUGO); |
| 206 | |
| 207 | MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based)."); |
| 208 | MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); |
| 209 | |
Vaishali Thakkar | ae89fac | 2015-03-18 23:13:10 +0530 | [diff] [blame] | 210 | module_spk_synth(synth_apollo); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 211 | |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 212 | MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>"); |
| 213 | MODULE_AUTHOR("David Borowski"); |
| 214 | MODULE_DESCRIPTION("Speakup support for Apollo II synthesizer"); |
| 215 | MODULE_LICENSE("GPL"); |
| 216 | MODULE_VERSION(DRV_VERSION); |
| 217 | |