speakup_apollo.c 6.5 KB

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