speakup_acntpc.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*
  2. * 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. * This driver is for the Aicom Acent PC internal synthesizer.
  25. */
  26. #include <linux/jiffies.h>
  27. #include <linux/sched.h>
  28. #include <linux/timer.h>
  29. #include <linux/kthread.h>
  30. #include "spk_priv.h"
  31. #include "serialio.h"
  32. #include "speakup.h"
  33. #include "speakup_acnt.h" /* local header file for Accent values */
  34. #define DRV_VERSION "2.10"
  35. #define PROCSPEECH '\r'
  36. static int synth_probe(struct spk_synth *synth);
  37. static void accent_release(void);
  38. static const char *synth_immediate(struct spk_synth *synth, const char *buf);
  39. static void do_catch_up(struct spk_synth *synth);
  40. static void synth_flush(struct spk_synth *synth);
  41. static int synth_port_control;
  42. static int port_forced;
  43. static unsigned int synth_portlist[] = { 0x2a8, 0 };
  44. static struct var_t vars[] = {
  45. { CAPS_START, .u.s = {"\033P8" } },
  46. { CAPS_STOP, .u.s = {"\033P5" } },
  47. { RATE, .u.n = {"\033R%c", 9, 0, 17, 0, 0, "0123456789abcdefgh" } },
  48. { PITCH, .u.n = {"\033P%d", 5, 0, 9, 0, 0, NULL } },
  49. { VOL, .u.n = {"\033A%d", 5, 0, 9, 0, 0, NULL } },
  50. { TONE, .u.n = {"\033V%d", 5, 0, 9, 0, 0, NULL } },
  51. { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
  52. V_LAST_VAR
  53. };
  54. /*
  55. * These attributes will appear in /sys/accessibility/speakup/acntpc.
  56. */
  57. static struct kobj_attribute caps_start_attribute =
  58. __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
  59. static struct kobj_attribute caps_stop_attribute =
  60. __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
  61. static struct kobj_attribute pitch_attribute =
  62. __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
  63. static struct kobj_attribute rate_attribute =
  64. __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
  65. static struct kobj_attribute tone_attribute =
  66. __ATTR(tone, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
  67. static struct kobj_attribute vol_attribute =
  68. __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
  69. static struct kobj_attribute delay_time_attribute =
  70. __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
  71. static struct kobj_attribute direct_attribute =
  72. __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
  73. static struct kobj_attribute full_time_attribute =
  74. __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
  75. static struct kobj_attribute jiffy_delta_attribute =
  76. __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
  77. static struct kobj_attribute trigger_time_attribute =
  78. __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
  79. /*
  80. * Create a group of attributes so that we can create and destroy them all
  81. * at once.
  82. */
  83. static struct attribute *synth_attrs[] = {
  84. &caps_start_attribute.attr,
  85. &caps_stop_attribute.attr,
  86. &pitch_attribute.attr,
  87. &rate_attribute.attr,
  88. &tone_attribute.attr,
  89. &vol_attribute.attr,
  90. &delay_time_attribute.attr,
  91. &direct_attribute.attr,
  92. &full_time_attribute.attr,
  93. &jiffy_delta_attribute.attr,
  94. &trigger_time_attribute.attr,
  95. NULL, /* need to NULL terminate the list of attributes */
  96. };
  97. static struct spk_synth synth_acntpc = {
  98. .name = "acntpc",
  99. .version = DRV_VERSION,
  100. .long_name = "Accent PC",
  101. .init = "\033=X \033Oi\033T2\033=M\033N1\n",
  102. .procspeech = PROCSPEECH,
  103. .clear = SYNTH_CLEAR,
  104. .delay = 500,
  105. .trigger = 50,
  106. .jiffies = 50,
  107. .full = 1000,
  108. .startup = SYNTH_START,
  109. .checkval = SYNTH_CHECK,
  110. .vars = vars,
  111. .probe = synth_probe,
  112. .release = accent_release,
  113. .synth_immediate = synth_immediate,
  114. .catch_up = do_catch_up,
  115. .flush = synth_flush,
  116. .is_alive = spk_synth_is_alive_nop,
  117. .synth_adjust = NULL,
  118. .read_buff_add = NULL,
  119. .get_index = NULL,
  120. .indexing = {
  121. .command = NULL,
  122. .lowindex = 0,
  123. .highindex = 0,
  124. .currindex = 0,
  125. },
  126. .attributes = {
  127. .attrs = synth_attrs,
  128. .name = "acntpc",
  129. },
  130. };
  131. static inline bool synth_writable(void)
  132. {
  133. return inb_p(synth_port_control) & SYNTH_WRITABLE;
  134. }
  135. static inline bool synth_full(void)
  136. {
  137. return inb_p(speakup_info.port_tts + UART_RX) == 'F';
  138. }
  139. static const char *synth_immediate(struct spk_synth *synth, const char *buf)
  140. {
  141. u_char ch;
  142. while ((ch = *buf)) {
  143. int timeout = SPK_XMITR_TIMEOUT;
  144. if (ch == '\n')
  145. ch = PROCSPEECH;
  146. if (synth_full())
  147. return buf;
  148. while (synth_writable()) {
  149. if (!--timeout)
  150. return buf;
  151. udelay(1);
  152. }
  153. outb_p(ch, speakup_info.port_tts);
  154. buf++;
  155. }
  156. return NULL;
  157. }
  158. static void do_catch_up(struct spk_synth *synth)
  159. {
  160. u_char ch;
  161. unsigned long flags;
  162. unsigned long jiff_max;
  163. int timeout;
  164. int delay_time_val;
  165. int jiffy_delta_val;
  166. int full_time_val;
  167. struct var_t *delay_time;
  168. struct var_t *full_time;
  169. struct var_t *jiffy_delta;
  170. jiffy_delta = spk_get_var(JIFFY);
  171. delay_time = spk_get_var(DELAY);
  172. full_time = spk_get_var(FULL);
  173. spin_lock_irqsave(&speakup_info.spinlock, flags);
  174. jiffy_delta_val = jiffy_delta->u.n.value;
  175. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  176. jiff_max = jiffies + jiffy_delta_val;
  177. while (!kthread_should_stop()) {
  178. spin_lock_irqsave(&speakup_info.spinlock, flags);
  179. if (speakup_info.flushing) {
  180. speakup_info.flushing = 0;
  181. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  182. synth->flush(synth);
  183. continue;
  184. }
  185. if (synth_buffer_empty()) {
  186. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  187. break;
  188. }
  189. set_current_state(TASK_INTERRUPTIBLE);
  190. full_time_val = full_time->u.n.value;
  191. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  192. if (synth_full()) {
  193. schedule_timeout(msecs_to_jiffies(full_time_val));
  194. continue;
  195. }
  196. set_current_state(TASK_RUNNING);
  197. timeout = SPK_XMITR_TIMEOUT;
  198. while (synth_writable()) {
  199. if (!--timeout)
  200. break;
  201. udelay(1);
  202. }
  203. spin_lock_irqsave(&speakup_info.spinlock, flags);
  204. ch = synth_buffer_getc();
  205. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  206. if (ch == '\n')
  207. ch = PROCSPEECH;
  208. outb_p(ch, speakup_info.port_tts);
  209. if (time_after_eq(jiffies, jiff_max) && ch == SPACE) {
  210. timeout = SPK_XMITR_TIMEOUT;
  211. while (synth_writable()) {
  212. if (!--timeout)
  213. break;
  214. udelay(1);
  215. }
  216. outb_p(PROCSPEECH, speakup_info.port_tts);
  217. spin_lock_irqsave(&speakup_info.spinlock, flags);
  218. jiffy_delta_val = jiffy_delta->u.n.value;
  219. delay_time_val = delay_time->u.n.value;
  220. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  221. schedule_timeout(msecs_to_jiffies(delay_time_val));
  222. jiff_max = jiffies+jiffy_delta_val;
  223. }
  224. }
  225. timeout = SPK_XMITR_TIMEOUT;
  226. while (synth_writable()) {
  227. if (!--timeout)
  228. break;
  229. udelay(1);
  230. }
  231. outb_p(PROCSPEECH, speakup_info.port_tts);
  232. }
  233. static void synth_flush(struct spk_synth *synth)
  234. {
  235. outb_p(SYNTH_CLEAR, speakup_info.port_tts);
  236. }
  237. static int synth_probe(struct spk_synth *synth)
  238. {
  239. unsigned int port_val = 0;
  240. int i = 0;
  241. pr_info("Probing for %s.\n", synth->long_name);
  242. if (port_forced) {
  243. speakup_info.port_tts = port_forced;
  244. pr_info("probe forced to %x by kernel command line\n",
  245. speakup_info.port_tts);
  246. if (synth_request_region(speakup_info.port_tts-1,
  247. SYNTH_IO_EXTENT)) {
  248. pr_warn("sorry, port already reserved\n");
  249. return -EBUSY;
  250. }
  251. port_val = inw(speakup_info.port_tts-1);
  252. synth_port_control = speakup_info.port_tts-1;
  253. } else {
  254. for (i = 0; synth_portlist[i]; i++) {
  255. if (synth_request_region(synth_portlist[i],
  256. SYNTH_IO_EXTENT)) {
  257. pr_warn
  258. ("request_region: failed with 0x%x, %d\n",
  259. synth_portlist[i], SYNTH_IO_EXTENT);
  260. continue;
  261. }
  262. port_val = inw(synth_portlist[i]) & 0xfffc;
  263. if (port_val == 0x53fc) {
  264. /* 'S' and out&input bits */
  265. synth_port_control = synth_portlist[i];
  266. speakup_info.port_tts = synth_port_control+1;
  267. break;
  268. }
  269. }
  270. }
  271. port_val &= 0xfffc;
  272. if (port_val != 0x53fc) {
  273. /* 'S' and out&input bits */
  274. pr_info("%s: not found\n", synth->long_name);
  275. synth_release_region(synth_port_control, SYNTH_IO_EXTENT);
  276. synth_port_control = 0;
  277. return -ENODEV;
  278. }
  279. pr_info("%s: %03x-%03x, driver version %s,\n", synth->long_name,
  280. synth_port_control, synth_port_control+SYNTH_IO_EXTENT-1,
  281. synth->version);
  282. synth->alive = 1;
  283. return 0;
  284. }
  285. static void accent_release(void)
  286. {
  287. if (speakup_info.port_tts)
  288. synth_release_region(speakup_info.port_tts-1, SYNTH_IO_EXTENT);
  289. speakup_info.port_tts = 0;
  290. }
  291. module_param_named(port, port_forced, int, S_IRUGO);
  292. module_param_named(start, synth_acntpc.startup, short, S_IRUGO);
  293. MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
  294. MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
  295. module_spk_synth(synth_acntpc);
  296. MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
  297. MODULE_AUTHOR("David Borowski");
  298. MODULE_DESCRIPTION("Speakup support for Accent PC synthesizer");
  299. MODULE_LICENSE("GPL");
  300. MODULE_VERSION(DRV_VERSION);