speakup_apollo.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. * this code is specifically written as a driver for the speakup screenreview
  10. * package and is 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. #include <linux/serial_reg.h> /* for UART_MCR* constants */
  17. #include "spk_priv.h"
  18. #include "speakup.h"
  19. #define DRV_VERSION "2.21"
  20. #define SYNTH_CLEAR 0x18
  21. #define PROCSPEECH '\r'
  22. static void do_catch_up(struct spk_synth *synth);
  23. enum default_vars_id {
  24. CAPS_START_ID = 0, CAPS_STOP_ID,
  25. RATE_ID, PITCH_ID,
  26. VOL_ID, VOICE_ID, LANG_ID,
  27. DIRECT_ID, V_LAST_VAR_ID,
  28. NB_ID
  29. };
  30. static struct var_t vars[NB_ID] = {
  31. [CAPS_START_ID] = { CAPS_START, .u.s = {"cap, " } },
  32. [CAPS_STOP_ID] = { CAPS_STOP, .u.s = {"" } },
  33. [RATE_ID] = { RATE, .u.n = {"@W%d", 6, 1, 9, 0, 0, NULL } },
  34. [PITCH_ID] = { PITCH, .u.n = {"@F%x", 10, 0, 15, 0, 0, NULL } },
  35. [VOL_ID] = { VOL, .u.n = {"@A%x", 10, 0, 15, 0, 0, NULL } },
  36. [VOICE_ID] = { VOICE, .u.n = {"@V%d", 1, 1, 6, 0, 0, NULL } },
  37. [LANG_ID] = { LANG, .u.n = {"@=%d,", 1, 1, 4, 0, 0, NULL } },
  38. [DIRECT_ID] = { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
  39. V_LAST_VAR
  40. };
  41. /*
  42. * These attributes will appear in /sys/accessibility/speakup/apollo.
  43. */
  44. static struct kobj_attribute caps_start_attribute =
  45. __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
  46. static struct kobj_attribute caps_stop_attribute =
  47. __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
  48. static struct kobj_attribute lang_attribute =
  49. __ATTR(lang, 0644, spk_var_show, spk_var_store);
  50. static struct kobj_attribute pitch_attribute =
  51. __ATTR(pitch, 0644, spk_var_show, spk_var_store);
  52. static struct kobj_attribute rate_attribute =
  53. __ATTR(rate, 0644, spk_var_show, spk_var_store);
  54. static struct kobj_attribute voice_attribute =
  55. __ATTR(voice, 0644, spk_var_show, spk_var_store);
  56. static struct kobj_attribute vol_attribute =
  57. __ATTR(vol, 0644, spk_var_show, spk_var_store);
  58. static struct kobj_attribute delay_time_attribute =
  59. __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
  60. static struct kobj_attribute direct_attribute =
  61. __ATTR(direct, 0644, spk_var_show, spk_var_store);
  62. static struct kobj_attribute full_time_attribute =
  63. __ATTR(full_time, 0644, spk_var_show, spk_var_store);
  64. static struct kobj_attribute jiffy_delta_attribute =
  65. __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
  66. static struct kobj_attribute trigger_time_attribute =
  67. __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
  68. /*
  69. * Create a group of attributes so that we can create and destroy them all
  70. * at once.
  71. */
  72. static struct attribute *synth_attrs[] = {
  73. &caps_start_attribute.attr,
  74. &caps_stop_attribute.attr,
  75. &lang_attribute.attr,
  76. &pitch_attribute.attr,
  77. &rate_attribute.attr,
  78. &voice_attribute.attr,
  79. &vol_attribute.attr,
  80. &delay_time_attribute.attr,
  81. &direct_attribute.attr,
  82. &full_time_attribute.attr,
  83. &jiffy_delta_attribute.attr,
  84. &trigger_time_attribute.attr,
  85. NULL, /* need to NULL terminate the list of attributes */
  86. };
  87. static struct spk_synth synth_apollo = {
  88. .name = "apollo",
  89. .version = DRV_VERSION,
  90. .long_name = "Apollo",
  91. .init = "@R3@D0@K1\r",
  92. .procspeech = PROCSPEECH,
  93. .clear = SYNTH_CLEAR,
  94. .delay = 500,
  95. .trigger = 50,
  96. .jiffies = 50,
  97. .full = 40000,
  98. .dev_name = SYNTH_DEFAULT_DEV,
  99. .startup = SYNTH_START,
  100. .checkval = SYNTH_CHECK,
  101. .vars = vars,
  102. .io_ops = &spk_ttyio_ops,
  103. .probe = spk_ttyio_synth_probe,
  104. .release = spk_ttyio_release,
  105. .synth_immediate = spk_ttyio_synth_immediate,
  106. .catch_up = do_catch_up,
  107. .flush = spk_synth_flush,
  108. .is_alive = spk_synth_is_alive_restart,
  109. .synth_adjust = NULL,
  110. .read_buff_add = NULL,
  111. .get_index = NULL,
  112. .indexing = {
  113. .command = NULL,
  114. .lowindex = 0,
  115. .highindex = 0,
  116. .currindex = 0,
  117. },
  118. .attributes = {
  119. .attrs = synth_attrs,
  120. .name = "apollo",
  121. },
  122. };
  123. static void do_catch_up(struct spk_synth *synth)
  124. {
  125. u_char ch;
  126. unsigned long flags;
  127. unsigned long jiff_max;
  128. struct var_t *jiffy_delta;
  129. struct var_t *delay_time;
  130. struct var_t *full_time;
  131. int full_time_val = 0;
  132. int delay_time_val = 0;
  133. int jiffy_delta_val = 0;
  134. jiffy_delta = spk_get_var(JIFFY);
  135. delay_time = spk_get_var(DELAY);
  136. full_time = spk_get_var(FULL);
  137. spin_lock_irqsave(&speakup_info.spinlock, flags);
  138. jiffy_delta_val = jiffy_delta->u.n.value;
  139. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  140. jiff_max = jiffies + jiffy_delta_val;
  141. while (!kthread_should_stop()) {
  142. spin_lock_irqsave(&speakup_info.spinlock, flags);
  143. jiffy_delta_val = jiffy_delta->u.n.value;
  144. full_time_val = full_time->u.n.value;
  145. delay_time_val = delay_time->u.n.value;
  146. if (speakup_info.flushing) {
  147. speakup_info.flushing = 0;
  148. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  149. synth->flush(synth);
  150. continue;
  151. }
  152. synth_buffer_skip_nonlatin1();
  153. if (synth_buffer_empty()) {
  154. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  155. break;
  156. }
  157. ch = synth_buffer_peek();
  158. set_current_state(TASK_INTERRUPTIBLE);
  159. full_time_val = full_time->u.n.value;
  160. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  161. if (!synth->io_ops->synth_out(synth, ch)) {
  162. synth->io_ops->tiocmset(synth, 0, UART_MCR_RTS);
  163. synth->io_ops->tiocmset(synth, UART_MCR_RTS, 0);
  164. schedule_timeout(msecs_to_jiffies(full_time_val));
  165. continue;
  166. }
  167. if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) {
  168. spin_lock_irqsave(&speakup_info.spinlock, flags);
  169. jiffy_delta_val = jiffy_delta->u.n.value;
  170. full_time_val = full_time->u.n.value;
  171. delay_time_val = delay_time->u.n.value;
  172. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  173. if (synth->io_ops->synth_out(synth, synth->procspeech))
  174. schedule_timeout(msecs_to_jiffies
  175. (delay_time_val));
  176. else
  177. schedule_timeout(msecs_to_jiffies
  178. (full_time_val));
  179. jiff_max = jiffies + jiffy_delta_val;
  180. }
  181. set_current_state(TASK_RUNNING);
  182. spin_lock_irqsave(&speakup_info.spinlock, flags);
  183. synth_buffer_getc();
  184. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  185. }
  186. synth->io_ops->synth_out(synth, PROCSPEECH);
  187. }
  188. module_param_named(ser, synth_apollo.ser, int, 0444);
  189. module_param_named(dev, synth_apollo.dev_name, charp, 0444);
  190. module_param_named(start, synth_apollo.startup, short, 0444);
  191. module_param_named(rate, vars[RATE_ID].u.n.default_val, int, 0444);
  192. module_param_named(pitch, vars[PITCH_ID].u.n.default_val, int, 0444);
  193. module_param_named(vol, vars[VOL_ID].u.n.default_val, int, 0444);
  194. module_param_named(voice, vars[VOICE_ID].u.n.default_val, int, 0444);
  195. module_param_named(lang, vars[LANG_ID].u.n.default_val, int, 0444);
  196. module_param_named(direct, vars[DIRECT_ID].u.n.default_val, int, 0444);
  197. MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
  198. MODULE_PARM_DESC(dev, "Set the device e.g. ttyUSB0, for the synthesizer.");
  199. MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
  200. MODULE_PARM_DESC(rate, "Set the rate variable on load.");
  201. MODULE_PARM_DESC(pitch, "Set the pitch variable on load.");
  202. MODULE_PARM_DESC(vol, "Set the vol variable on load.");
  203. MODULE_PARM_DESC(voice, "Set the voice variable on load.");
  204. MODULE_PARM_DESC(lang, "Set the lang variable on load.");
  205. MODULE_PARM_DESC(direct, "Set the direct variable on load.");
  206. module_spk_synth(synth_apollo);
  207. MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
  208. MODULE_AUTHOR("David Borowski");
  209. MODULE_DESCRIPTION("Speakup support for Apollo II synthesizer");
  210. MODULE_LICENSE("GPL");
  211. MODULE_VERSION(DRV_VERSION);