speakup_acntpc.c 8.8 KB

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