speakup_apollo.c 7.0 KB

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