/drivers/staging/speakup/speakup_decext.c

https://bitbucket.org/cyanogenmod/android_kernel_asus_tf300t · C · 253 lines · 200 code · 22 blank · 31 comment · 21 complexity · 28f8065ef0ddef607b257784c9ae606e MD5 · raw file

  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. * specificly written as a driver for the speakup screenreview
  23. * s 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. #include "spk_priv.h"
  30. #include "serialio.h"
  31. #include "speakup.h"
  32. #define DRV_VERSION "2.14"
  33. #define SYNTH_CLEAR 0x03
  34. #define PROCSPEECH 0x0b
  35. static unsigned char last_char;
  36. static inline u_char get_last_char(void)
  37. {
  38. u_char avail = inb_p(speakup_info.port_tts + UART_LSR) & UART_LSR_DR;
  39. if (avail)
  40. last_char = inb_p(speakup_info.port_tts + UART_RX);
  41. return last_char;
  42. }
  43. static inline bool synth_full(void)
  44. {
  45. return get_last_char() == 0x13;
  46. }
  47. static void do_catch_up(struct spk_synth *synth);
  48. static void synth_flush(struct spk_synth *synth);
  49. static int in_escape;
  50. static struct var_t vars[] = {
  51. { CAPS_START, .u.s = {"[:dv ap 222]" } },
  52. { CAPS_STOP, .u.s = {"[:dv ap 100]" } },
  53. { RATE, .u.n = {"[:ra %d]", 7, 0, 9, 150, 25, NULL } },
  54. { PITCH, .u.n = {"[:dv ap %d]", 100, 0, 100, 0, 0, NULL } },
  55. { VOL, .u.n = {"[:dv gv %d]", 13, 0, 16, 0, 5, NULL } },
  56. { PUNCT, .u.n = {"[:pu %c]", 0, 0, 2, 0, 0, "nsa" } },
  57. { VOICE, .u.n = {"[:n%c]", 0, 0, 9, 0, 0, "phfdburwkv" } },
  58. { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
  59. V_LAST_VAR
  60. };
  61. /*
  62. * These attributes will appear in /sys/accessibility/speakup/decext.
  63. */
  64. static struct kobj_attribute caps_start_attribute =
  65. __ATTR(caps_start, USER_RW, spk_var_show, spk_var_store);
  66. static struct kobj_attribute caps_stop_attribute =
  67. __ATTR(caps_stop, USER_RW, spk_var_show, spk_var_store);
  68. static struct kobj_attribute pitch_attribute =
  69. __ATTR(pitch, USER_RW, spk_var_show, spk_var_store);
  70. static struct kobj_attribute punct_attribute =
  71. __ATTR(punct, USER_RW, spk_var_show, spk_var_store);
  72. static struct kobj_attribute rate_attribute =
  73. __ATTR(rate, USER_RW, spk_var_show, spk_var_store);
  74. static struct kobj_attribute voice_attribute =
  75. __ATTR(voice, USER_RW, spk_var_show, spk_var_store);
  76. static struct kobj_attribute vol_attribute =
  77. __ATTR(vol, USER_RW, spk_var_show, spk_var_store);
  78. static struct kobj_attribute delay_time_attribute =
  79. __ATTR(delay_time, ROOT_W, spk_var_show, spk_var_store);
  80. static struct kobj_attribute direct_attribute =
  81. __ATTR(direct, USER_RW, spk_var_show, spk_var_store);
  82. static struct kobj_attribute full_time_attribute =
  83. __ATTR(full_time, ROOT_W, spk_var_show, spk_var_store);
  84. static struct kobj_attribute jiffy_delta_attribute =
  85. __ATTR(jiffy_delta, ROOT_W, spk_var_show, spk_var_store);
  86. static struct kobj_attribute trigger_time_attribute =
  87. __ATTR(trigger_time, ROOT_W, spk_var_show, spk_var_store);
  88. /*
  89. * Create a group of attributes so that we can create and destroy them all
  90. * at once.
  91. */
  92. static struct attribute *synth_attrs[] = {
  93. &caps_start_attribute.attr,
  94. &caps_stop_attribute.attr,
  95. &pitch_attribute.attr,
  96. &punct_attribute.attr,
  97. &rate_attribute.attr,
  98. &voice_attribute.attr,
  99. &vol_attribute.attr,
  100. &delay_time_attribute.attr,
  101. &direct_attribute.attr,
  102. &full_time_attribute.attr,
  103. &jiffy_delta_attribute.attr,
  104. &trigger_time_attribute.attr,
  105. NULL, /* need to NULL terminate the list of attributes */
  106. };
  107. static struct spk_synth synth_decext = {
  108. .name = "decext",
  109. .version = DRV_VERSION,
  110. .long_name = "Dectalk External",
  111. .init = "[:pe -380]",
  112. .procspeech = PROCSPEECH,
  113. .clear = SYNTH_CLEAR,
  114. .delay = 500,
  115. .trigger = 50,
  116. .jiffies = 50,
  117. .full = 40000,
  118. .flags = SF_DEC,
  119. .startup = SYNTH_START,
  120. .checkval = SYNTH_CHECK,
  121. .vars = vars,
  122. .probe = serial_synth_probe,
  123. .release = spk_serial_release,
  124. .synth_immediate = spk_synth_immediate,
  125. .catch_up = do_catch_up,
  126. .flush = synth_flush,
  127. .is_alive = spk_synth_is_alive_restart,
  128. .synth_adjust = NULL,
  129. .read_buff_add = NULL,
  130. .get_index = NULL,
  131. .indexing = {
  132. .command = NULL,
  133. .lowindex = 0,
  134. .highindex = 0,
  135. .currindex = 0,
  136. },
  137. .attributes = {
  138. .attrs = synth_attrs,
  139. .name = "decext",
  140. },
  141. };
  142. static void do_catch_up(struct spk_synth *synth)
  143. {
  144. u_char ch;
  145. static u_char last = '\0';
  146. unsigned long flags;
  147. unsigned long jiff_max;
  148. struct var_t *jiffy_delta;
  149. struct var_t *delay_time;
  150. int jiffy_delta_val = 0;
  151. int delay_time_val = 0;
  152. jiffy_delta = get_var(JIFFY);
  153. delay_time = get_var(DELAY);
  154. spk_lock(flags);
  155. jiffy_delta_val = jiffy_delta->u.n.value;
  156. spk_unlock(flags);
  157. jiff_max = jiffies + jiffy_delta_val;
  158. while (!kthread_should_stop()) {
  159. spk_lock(flags);
  160. if (speakup_info.flushing) {
  161. speakup_info.flushing = 0;
  162. spk_unlock(flags);
  163. synth->flush(synth);
  164. continue;
  165. }
  166. if (synth_buffer_empty()) {
  167. spk_unlock(flags);
  168. break;
  169. }
  170. ch = synth_buffer_peek();
  171. set_current_state(TASK_INTERRUPTIBLE);
  172. delay_time_val = delay_time->u.n.value;
  173. spk_unlock(flags);
  174. if (ch == '\n')
  175. ch = 0x0D;
  176. if (synth_full() || !spk_serial_out(ch)) {
  177. schedule_timeout(msecs_to_jiffies(delay_time_val));
  178. continue;
  179. }
  180. set_current_state(TASK_RUNNING);
  181. spk_lock(flags);
  182. synth_buffer_getc();
  183. spk_unlock(flags);
  184. if (ch == '[')
  185. in_escape = 1;
  186. else if (ch == ']')
  187. in_escape = 0;
  188. else if (ch <= SPACE) {
  189. if (!in_escape && strchr(",.!?;:", last))
  190. spk_serial_out(PROCSPEECH);
  191. if (jiffies >= jiff_max) {
  192. if (!in_escape)
  193. spk_serial_out(PROCSPEECH);
  194. spk_lock(flags);
  195. jiffy_delta_val = jiffy_delta->u.n.value;
  196. delay_time_val = delay_time->u.n.value;
  197. spk_unlock(flags);
  198. schedule_timeout(msecs_to_jiffies
  199. (delay_time_val));
  200. jiff_max = jiffies + jiffy_delta_val;
  201. }
  202. }
  203. last = ch;
  204. }
  205. if (!in_escape)
  206. spk_serial_out(PROCSPEECH);
  207. }
  208. static void synth_flush(struct spk_synth *synth)
  209. {
  210. in_escape = 0;
  211. spk_synth_immediate(synth, "\033P;10z\033\\");
  212. }
  213. module_param_named(ser, synth_decext.ser, int, S_IRUGO);
  214. module_param_named(start, synth_decext.startup, short, S_IRUGO);
  215. MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
  216. MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
  217. static int __init decext_init(void)
  218. {
  219. return synth_add(&synth_decext);
  220. }
  221. static void __exit decext_exit(void)
  222. {
  223. synth_remove(&synth_decext);
  224. }
  225. module_init(decext_init);
  226. module_exit(decext_exit);
  227. MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
  228. MODULE_AUTHOR("David Borowski");
  229. MODULE_DESCRIPTION("Speakup support for DECtalk External synthesizers");
  230. MODULE_LICENSE("GPL");
  231. MODULE_VERSION(DRV_VERSION);