atakeyb.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /*
  2. * linux/atari/atakeyb.c
  3. *
  4. * Atari Keyboard driver for 680x0 Linux
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive
  8. * for more details.
  9. */
  10. /*
  11. * Atari support by Robert de Vries
  12. * enhanced by Bjoern Brauel and Roman Hodek
  13. */
  14. #include <linux/module.h>
  15. #include <linux/sched.h>
  16. #include <linux/kernel.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/errno.h>
  19. #include <linux/keyboard.h>
  20. #include <linux/delay.h>
  21. #include <linux/timer.h>
  22. #include <linux/kd.h>
  23. #include <linux/random.h>
  24. #include <linux/init.h>
  25. #include <linux/kbd_kern.h>
  26. #include <asm/atariints.h>
  27. #include <asm/atarihw.h>
  28. #include <asm/atarikb.h>
  29. #include <asm/atari_joystick.h>
  30. #include <asm/irq.h>
  31. static void atakeyb_rep(unsigned long ignore);
  32. extern unsigned int keymap_count;
  33. /* Hook for MIDI serial driver */
  34. void (*atari_MIDI_interrupt_hook) (void);
  35. /* Hook for mouse driver */
  36. void (*atari_mouse_interrupt_hook) (char *);
  37. /* Hook for keyboard inputdev driver */
  38. void (*atari_input_keyboard_interrupt_hook) (unsigned char, char);
  39. /* Hook for mouse inputdev driver */
  40. void (*atari_input_mouse_interrupt_hook) (char *);
  41. EXPORT_SYMBOL(atari_mouse_interrupt_hook);
  42. EXPORT_SYMBOL(atari_input_keyboard_interrupt_hook);
  43. EXPORT_SYMBOL(atari_input_mouse_interrupt_hook);
  44. /* variables for IKBD self test: */
  45. /* state: 0: off; >0: in progress; >1: 0xf1 received */
  46. static volatile int ikbd_self_test;
  47. /* timestamp when last received a char */
  48. static volatile unsigned long self_test_last_rcv;
  49. /* bitmap of keys reported as broken */
  50. static unsigned long broken_keys[128/(sizeof(unsigned long)*8)] = { 0, };
  51. #define BREAK_MASK (0x80)
  52. /*
  53. * ++roman: The following changes were applied manually:
  54. *
  55. * - The Alt (= Meta) key works in combination with Shift and
  56. * Control, e.g. Alt+Shift+a sends Meta-A (0xc1), Alt+Control+A sends
  57. * Meta-Ctrl-A (0x81) ...
  58. *
  59. * - The parentheses on the keypad send '(' and ')' with all
  60. * modifiers (as would do e.g. keypad '+'), but they cannot be used as
  61. * application keys (i.e. sending Esc O c).
  62. *
  63. * - HELP and UNDO are mapped to be F21 and F24, resp, that send the
  64. * codes "\E[M" and "\E[P". (This is better than the old mapping to
  65. * F11 and F12, because these codes are on Shift+F1/2 anyway.) This
  66. * way, applications that allow their own keyboard mappings
  67. * (e.g. tcsh, X Windows) can be configured to use them in the way
  68. * the label suggests (providing help or undoing).
  69. *
  70. * - Console switching is done with Alt+Fx (consoles 1..10) and
  71. * Shift+Alt+Fx (consoles 11..20).
  72. *
  73. * - The misc. special function implemented in the kernel are mapped
  74. * to the following key combinations:
  75. *
  76. * ClrHome -> Home/Find
  77. * Shift + ClrHome -> End/Select
  78. * Shift + Up -> Page Up
  79. * Shift + Down -> Page Down
  80. * Alt + Help -> show system status
  81. * Shift + Help -> show memory info
  82. * Ctrl + Help -> show registers
  83. * Ctrl + Alt + Del -> Reboot
  84. * Alt + Undo -> switch to last console
  85. * Shift + Undo -> send interrupt
  86. * Alt + Insert -> stop/start output (same as ^S/^Q)
  87. * Alt + Up -> Scroll back console (if implemented)
  88. * Alt + Down -> Scroll forward console (if implemented)
  89. * Alt + CapsLock -> NumLock
  90. *
  91. * ++Andreas:
  92. *
  93. * - Help mapped to K_HELP
  94. * - Undo mapped to K_UNDO (= K_F246)
  95. * - Keypad Left/Right Parenthesis mapped to new K_PPAREN[LR]
  96. */
  97. static u_short ataplain_map[NR_KEYS] __initdata = {
  98. 0xf200, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
  99. 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf008, 0xf009,
  100. 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
  101. 0xfb6f, 0xfb70, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb61, 0xfb73,
  102. 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03b,
  103. 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
  104. 0xfb62, 0xfb6e, 0xfb6d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf200,
  105. 0xf703, 0xf020, 0xf207, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
  106. 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf200, 0xf200, 0xf114,
  107. 0xf603, 0xf200, 0xf30b, 0xf601, 0xf200, 0xf602, 0xf30a, 0xf200,
  108. 0xf600, 0xf200, 0xf115, 0xf07f, 0xf200, 0xf200, 0xf200, 0xf200,
  109. 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  110. 0xf200, 0xf1ff, 0xf11b, 0xf312, 0xf313, 0xf30d, 0xf30c, 0xf307,
  111. 0xf308, 0xf309, 0xf304, 0xf305, 0xf306, 0xf301, 0xf302, 0xf303,
  112. 0xf300, 0xf310, 0xf30e, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  113. 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200
  114. };
  115. typedef enum kb_state_t {
  116. KEYBOARD, AMOUSE, RMOUSE, JOYSTICK, CLOCK, RESYNC
  117. } KB_STATE_T;
  118. #define IS_SYNC_CODE(sc) ((sc) >= 0x04 && (sc) <= 0xfb)
  119. typedef struct keyboard_state {
  120. unsigned char buf[6];
  121. int len;
  122. KB_STATE_T state;
  123. } KEYBOARD_STATE;
  124. KEYBOARD_STATE kb_state;
  125. #define DEFAULT_KEYB_REP_DELAY (HZ/4)
  126. #define DEFAULT_KEYB_REP_RATE (HZ/25)
  127. /* These could be settable by some ioctl() in future... */
  128. static unsigned int key_repeat_delay = DEFAULT_KEYB_REP_DELAY;
  129. static unsigned int key_repeat_rate = DEFAULT_KEYB_REP_RATE;
  130. static unsigned char rep_scancode;
  131. static struct timer_list atakeyb_rep_timer = {
  132. .function = atakeyb_rep,
  133. };
  134. static void atakeyb_rep(unsigned long ignore)
  135. {
  136. /* Disable keyboard for the time we call handle_scancode(), else a race
  137. * in the keyboard tty queue may happen */
  138. atari_disable_irq(IRQ_MFP_ACIA);
  139. del_timer(&atakeyb_rep_timer);
  140. /* A keyboard int may have come in before we disabled the irq, so
  141. * double-check whether rep_scancode is still != 0 */
  142. if (rep_scancode) {
  143. init_timer(&atakeyb_rep_timer);
  144. atakeyb_rep_timer.expires = jiffies + key_repeat_rate;
  145. add_timer(&atakeyb_rep_timer);
  146. //handle_scancode(rep_scancode, 1);
  147. if (atari_input_keyboard_interrupt_hook)
  148. atari_input_keyboard_interrupt_hook(rep_scancode, 1);
  149. }
  150. atari_enable_irq(IRQ_MFP_ACIA);
  151. }
  152. /* ++roman: If a keyboard overrun happened, we can't tell in general how much
  153. * bytes have been lost and in which state of the packet structure we are now.
  154. * This usually causes keyboards bytes to be interpreted as mouse movements
  155. * and vice versa, which is very annoying. It seems better to throw away some
  156. * bytes (that are usually mouse bytes) than to misinterpret them. Therefor I
  157. * introduced the RESYNC state for IKBD data. In this state, the bytes up to
  158. * one that really looks like a key event (0x04..0xf2) or the start of a mouse
  159. * packet (0xf8..0xfb) are thrown away, but at most 2 bytes. This at least
  160. * speeds up the resynchronization of the event structure, even if maybe a
  161. * mouse movement is lost. However, nothing is perfect. For bytes 0x01..0x03,
  162. * it's really hard to decide whether they're mouse or keyboard bytes. Since
  163. * overruns usually occur when moving the Atari mouse rapidly, they're seen as
  164. * mouse bytes here. If this is wrong, only a make code of the keyboard gets
  165. * lost, which isn't too bad. Loosing a break code would be disastrous,
  166. * because then the keyboard repeat strikes...
  167. */
  168. static irqreturn_t atari_keyboard_interrupt(int irq, void *dummy)
  169. {
  170. u_char acia_stat;
  171. int scancode;
  172. int break_flag;
  173. repeat:
  174. if (acia.mid_ctrl & ACIA_IRQ)
  175. if (atari_MIDI_interrupt_hook)
  176. atari_MIDI_interrupt_hook();
  177. acia_stat = acia.key_ctrl;
  178. /* check out if the interrupt came from this ACIA */
  179. if (!((acia_stat | acia.mid_ctrl) & ACIA_IRQ))
  180. return IRQ_HANDLED;
  181. if (acia_stat & ACIA_OVRN) {
  182. /* a very fast typist or a slow system, give a warning */
  183. /* ...happens often if interrupts were disabled for too long */
  184. printk(KERN_DEBUG "Keyboard overrun\n");
  185. scancode = acia.key_data;
  186. /* Turn off autorepeating in case a break code has been lost */
  187. del_timer(&atakeyb_rep_timer);
  188. rep_scancode = 0;
  189. if (ikbd_self_test)
  190. /* During self test, don't do resyncing, just process the code */
  191. goto interpret_scancode;
  192. else if (IS_SYNC_CODE(scancode)) {
  193. /* This code seem already to be the start of a new packet or a
  194. * single scancode */
  195. kb_state.state = KEYBOARD;
  196. goto interpret_scancode;
  197. } else {
  198. /* Go to RESYNC state and skip this byte */
  199. kb_state.state = RESYNC;
  200. kb_state.len = 1; /* skip max. 1 another byte */
  201. goto repeat;
  202. }
  203. }
  204. if (acia_stat & ACIA_RDRF) {
  205. /* received a character */
  206. scancode = acia.key_data; /* get it or reset the ACIA, I'll get it! */
  207. tasklet_schedule(&keyboard_tasklet);
  208. interpret_scancode:
  209. switch (kb_state.state) {
  210. case KEYBOARD:
  211. switch (scancode) {
  212. case 0xF7:
  213. kb_state.state = AMOUSE;
  214. kb_state.len = 0;
  215. break;
  216. case 0xF8:
  217. case 0xF9:
  218. case 0xFA:
  219. case 0xFB:
  220. kb_state.state = RMOUSE;
  221. kb_state.len = 1;
  222. kb_state.buf[0] = scancode;
  223. break;
  224. case 0xFC:
  225. kb_state.state = CLOCK;
  226. kb_state.len = 0;
  227. break;
  228. case 0xFE:
  229. case 0xFF:
  230. kb_state.state = JOYSTICK;
  231. kb_state.len = 1;
  232. kb_state.buf[0] = scancode;
  233. break;
  234. case 0xF1:
  235. /* during self-test, note that 0xf1 received */
  236. if (ikbd_self_test) {
  237. ++ikbd_self_test;
  238. self_test_last_rcv = jiffies;
  239. break;
  240. }
  241. /* FALL THROUGH */
  242. default:
  243. break_flag = scancode & BREAK_MASK;
  244. scancode &= ~BREAK_MASK;
  245. if (ikbd_self_test) {
  246. /* Scancodes sent during the self-test stand for broken
  247. * keys (keys being down). The code *should* be a break
  248. * code, but nevertheless some AT keyboard interfaces send
  249. * make codes instead. Therefore, simply ignore
  250. * break_flag...
  251. */
  252. int keyval = plain_map[scancode], keytyp;
  253. set_bit(scancode, broken_keys);
  254. self_test_last_rcv = jiffies;
  255. keyval = plain_map[scancode];
  256. keytyp = KTYP(keyval) - 0xf0;
  257. keyval = KVAL(keyval);
  258. printk(KERN_WARNING "Key with scancode %d ", scancode);
  259. if (keytyp == KT_LATIN || keytyp == KT_LETTER) {
  260. if (keyval < ' ')
  261. printk("('^%c') ", keyval + '@');
  262. else
  263. printk("('%c') ", keyval);
  264. }
  265. printk("is broken -- will be ignored.\n");
  266. break;
  267. } else if (test_bit(scancode, broken_keys))
  268. break;
  269. #if 0 // FIXME; hangs at boot
  270. if (break_flag) {
  271. del_timer(&atakeyb_rep_timer);
  272. rep_scancode = 0;
  273. } else {
  274. del_timer(&atakeyb_rep_timer);
  275. rep_scancode = scancode;
  276. atakeyb_rep_timer.expires = jiffies + key_repeat_delay;
  277. add_timer(&atakeyb_rep_timer);
  278. }
  279. #endif
  280. // handle_scancode(scancode, !break_flag);
  281. if (atari_input_keyboard_interrupt_hook)
  282. atari_input_keyboard_interrupt_hook((unsigned char)scancode, !break_flag);
  283. break;
  284. }
  285. break;
  286. case AMOUSE:
  287. kb_state.buf[kb_state.len++] = scancode;
  288. if (kb_state.len == 5) {
  289. kb_state.state = KEYBOARD;
  290. /* not yet used */
  291. /* wake up someone waiting for this */
  292. }
  293. break;
  294. case RMOUSE:
  295. kb_state.buf[kb_state.len++] = scancode;
  296. if (kb_state.len == 3) {
  297. kb_state.state = KEYBOARD;
  298. if (atari_mouse_interrupt_hook)
  299. atari_mouse_interrupt_hook(kb_state.buf);
  300. }
  301. break;
  302. case JOYSTICK:
  303. kb_state.buf[1] = scancode;
  304. kb_state.state = KEYBOARD;
  305. #ifdef FIXED_ATARI_JOYSTICK
  306. atari_joystick_interrupt(kb_state.buf);
  307. #endif
  308. break;
  309. case CLOCK:
  310. kb_state.buf[kb_state.len++] = scancode;
  311. if (kb_state.len == 6) {
  312. kb_state.state = KEYBOARD;
  313. /* wake up someone waiting for this.
  314. But will this ever be used, as Linux keeps its own time.
  315. Perhaps for synchronization purposes? */
  316. /* wake_up_interruptible(&clock_wait); */
  317. }
  318. break;
  319. case RESYNC:
  320. if (kb_state.len <= 0 || IS_SYNC_CODE(scancode)) {
  321. kb_state.state = KEYBOARD;
  322. goto interpret_scancode;
  323. }
  324. kb_state.len--;
  325. break;
  326. }
  327. }
  328. #if 0
  329. if (acia_stat & ACIA_CTS)
  330. /* cannot happen */;
  331. #endif
  332. if (acia_stat & (ACIA_FE | ACIA_PE)) {
  333. printk("Error in keyboard communication\n");
  334. }
  335. /* handle_scancode() can take a lot of time, so check again if
  336. * some character arrived
  337. */
  338. goto repeat;
  339. }
  340. /*
  341. * I write to the keyboard without using interrupts, I poll instead.
  342. * This takes for the maximum length string allowed (7) at 7812.5 baud
  343. * 8 data 1 start 1 stop bit: 9.0 ms
  344. * If this takes too long for normal operation, interrupt driven writing
  345. * is the solution. (I made a feeble attempt in that direction but I
  346. * kept it simple for now.)
  347. */
  348. void ikbd_write(const char *str, int len)
  349. {
  350. u_char acia_stat;
  351. if ((len < 1) || (len > 7))
  352. panic("ikbd: maximum string length exceeded");
  353. while (len) {
  354. acia_stat = acia.key_ctrl;
  355. if (acia_stat & ACIA_TDRE) {
  356. acia.key_data = *str++;
  357. len--;
  358. }
  359. }
  360. }
  361. /* Reset (without touching the clock) */
  362. void ikbd_reset(void)
  363. {
  364. static const char cmd[2] = { 0x80, 0x01 };
  365. ikbd_write(cmd, 2);
  366. /*
  367. * if all's well code 0xF1 is returned, else the break codes of
  368. * all keys making contact
  369. */
  370. }
  371. /* Set mouse button action */
  372. void ikbd_mouse_button_action(int mode)
  373. {
  374. char cmd[2] = { 0x07, mode };
  375. ikbd_write(cmd, 2);
  376. }
  377. /* Set relative mouse position reporting */
  378. void ikbd_mouse_rel_pos(void)
  379. {
  380. static const char cmd[1] = { 0x08 };
  381. ikbd_write(cmd, 1);
  382. }
  383. EXPORT_SYMBOL(ikbd_mouse_rel_pos);
  384. /* Set absolute mouse position reporting */
  385. void ikbd_mouse_abs_pos(int xmax, int ymax)
  386. {
  387. char cmd[5] = { 0x09, xmax>>8, xmax&0xFF, ymax>>8, ymax&0xFF };
  388. ikbd_write(cmd, 5);
  389. }
  390. /* Set mouse keycode mode */
  391. void ikbd_mouse_kbd_mode(int dx, int dy)
  392. {
  393. char cmd[3] = { 0x0A, dx, dy };
  394. ikbd_write(cmd, 3);
  395. }
  396. /* Set mouse threshold */
  397. void ikbd_mouse_thresh(int x, int y)
  398. {
  399. char cmd[3] = { 0x0B, x, y };
  400. ikbd_write(cmd, 3);
  401. }
  402. EXPORT_SYMBOL(ikbd_mouse_thresh);
  403. /* Set mouse scale */
  404. void ikbd_mouse_scale(int x, int y)
  405. {
  406. char cmd[3] = { 0x0C, x, y };
  407. ikbd_write(cmd, 3);
  408. }
  409. /* Interrogate mouse position */
  410. void ikbd_mouse_pos_get(int *x, int *y)
  411. {
  412. static const char cmd[1] = { 0x0D };
  413. ikbd_write(cmd, 1);
  414. /* wait for returning bytes */
  415. }
  416. /* Load mouse position */
  417. void ikbd_mouse_pos_set(int x, int y)
  418. {
  419. char cmd[6] = { 0x0E, 0x00, x>>8, x&0xFF, y>>8, y&0xFF };
  420. ikbd_write(cmd, 6);
  421. }
  422. /* Set Y=0 at bottom */
  423. void ikbd_mouse_y0_bot(void)
  424. {
  425. static const char cmd[1] = { 0x0F };
  426. ikbd_write(cmd, 1);
  427. }
  428. /* Set Y=0 at top */
  429. void ikbd_mouse_y0_top(void)
  430. {
  431. static const char cmd[1] = { 0x10 };
  432. ikbd_write(cmd, 1);
  433. }
  434. EXPORT_SYMBOL(ikbd_mouse_y0_top);
  435. /* Resume */
  436. void ikbd_resume(void)
  437. {
  438. static const char cmd[1] = { 0x11 };
  439. ikbd_write(cmd, 1);
  440. }
  441. /* Disable mouse */
  442. void ikbd_mouse_disable(void)
  443. {
  444. static const char cmd[1] = { 0x12 };
  445. ikbd_write(cmd, 1);
  446. }
  447. EXPORT_SYMBOL(ikbd_mouse_disable);
  448. /* Pause output */
  449. void ikbd_pause(void)
  450. {
  451. static const char cmd[1] = { 0x13 };
  452. ikbd_write(cmd, 1);
  453. }
  454. /* Set joystick event reporting */
  455. void ikbd_joystick_event_on(void)
  456. {
  457. static const char cmd[1] = { 0x14 };
  458. ikbd_write(cmd, 1);
  459. }
  460. /* Set joystick interrogation mode */
  461. void ikbd_joystick_event_off(void)
  462. {
  463. static const char cmd[1] = { 0x15 };
  464. ikbd_write(cmd, 1);
  465. }
  466. /* Joystick interrogation */
  467. void ikbd_joystick_get_state(void)
  468. {
  469. static const char cmd[1] = { 0x16 };
  470. ikbd_write(cmd, 1);
  471. }
  472. #if 0
  473. /* This disables all other ikbd activities !!!! */
  474. /* Set joystick monitoring */
  475. void ikbd_joystick_monitor(int rate)
  476. {
  477. static const char cmd[2] = { 0x17, rate };
  478. ikbd_write(cmd, 2);
  479. kb_state.state = JOYSTICK_MONITOR;
  480. }
  481. #endif
  482. /* some joystick routines not in yet (0x18-0x19) */
  483. /* Disable joysticks */
  484. void ikbd_joystick_disable(void)
  485. {
  486. static const char cmd[1] = { 0x1A };
  487. ikbd_write(cmd, 1);
  488. }
  489. /* Time-of-day clock set */
  490. void ikbd_clock_set(int year, int month, int day, int hour, int minute, int second)
  491. {
  492. char cmd[7] = { 0x1B, year, month, day, hour, minute, second };
  493. ikbd_write(cmd, 7);
  494. }
  495. /* Interrogate time-of-day clock */
  496. void ikbd_clock_get(int *year, int *month, int *day, int *hour, int *minute, int second)
  497. {
  498. static const char cmd[1] = { 0x1C };
  499. ikbd_write(cmd, 1);
  500. }
  501. /* Memory load */
  502. void ikbd_mem_write(int address, int size, char *data)
  503. {
  504. panic("Attempt to write data into keyboard memory");
  505. }
  506. /* Memory read */
  507. void ikbd_mem_read(int address, char data[6])
  508. {
  509. char cmd[3] = { 0x21, address>>8, address&0xFF };
  510. ikbd_write(cmd, 3);
  511. /* receive data and put it in data */
  512. }
  513. /* Controller execute */
  514. void ikbd_exec(int address)
  515. {
  516. char cmd[3] = { 0x22, address>>8, address&0xFF };
  517. ikbd_write(cmd, 3);
  518. }
  519. /* Status inquiries (0x87-0x9A) not yet implemented */
  520. /* Set the state of the caps lock led. */
  521. void atari_kbd_leds(unsigned int leds)
  522. {
  523. char cmd[6] = {32, 0, 4, 1, 254 + ((leds & 4) != 0), 0};
  524. ikbd_write(cmd, 6);
  525. }
  526. /*
  527. * The original code sometimes left the interrupt line of
  528. * the ACIAs low forever. I hope, it is fixed now.
  529. *
  530. * Martin Rogge, 20 Aug 1995
  531. */
  532. static int atari_keyb_done = 0;
  533. int __init atari_keyb_init(void)
  534. {
  535. if (atari_keyb_done)
  536. return 0;
  537. /* setup key map */
  538. memcpy(key_maps[0], ataplain_map, sizeof(plain_map));
  539. kb_state.state = KEYBOARD;
  540. kb_state.len = 0;
  541. request_irq(IRQ_MFP_ACIA, atari_keyboard_interrupt, IRQ_TYPE_SLOW,
  542. "keyboard/mouse/MIDI", atari_keyboard_interrupt);
  543. atari_turnoff_irq(IRQ_MFP_ACIA);
  544. do {
  545. /* reset IKBD ACIA */
  546. acia.key_ctrl = ACIA_RESET |
  547. (atari_switches & ATARI_SWITCH_IKBD) ? ACIA_RHTID : 0;
  548. (void)acia.key_ctrl;
  549. (void)acia.key_data;
  550. /* reset MIDI ACIA */
  551. acia.mid_ctrl = ACIA_RESET |
  552. (atari_switches & ATARI_SWITCH_MIDI) ? ACIA_RHTID : 0;
  553. (void)acia.mid_ctrl;
  554. (void)acia.mid_data;
  555. /* divide 500kHz by 64 gives 7812.5 baud */
  556. /* 8 data no parity 1 start 1 stop bit */
  557. /* receive interrupt enabled */
  558. /* RTS low (except if switch selected), transmit interrupt disabled */
  559. acia.key_ctrl = (ACIA_DIV64|ACIA_D8N1S|ACIA_RIE) |
  560. ((atari_switches & ATARI_SWITCH_IKBD) ?
  561. ACIA_RHTID : ACIA_RLTID);
  562. acia.mid_ctrl = ACIA_DIV16 | ACIA_D8N1S |
  563. (atari_switches & ATARI_SWITCH_MIDI) ? ACIA_RHTID : 0;
  564. /* make sure the interrupt line is up */
  565. } while ((mfp.par_dt_reg & 0x10) == 0);
  566. /* enable ACIA Interrupts */
  567. mfp.active_edge &= ~0x10;
  568. atari_turnon_irq(IRQ_MFP_ACIA);
  569. ikbd_self_test = 1;
  570. ikbd_reset();
  571. /* wait for a period of inactivity (here: 0.25s), then assume the IKBD's
  572. * self-test is finished */
  573. self_test_last_rcv = jiffies;
  574. while (time_before(jiffies, self_test_last_rcv + HZ/4))
  575. barrier();
  576. /* if not incremented: no 0xf1 received */
  577. if (ikbd_self_test == 1)
  578. printk(KERN_ERR "WARNING: keyboard self test failed!\n");
  579. ikbd_self_test = 0;
  580. ikbd_mouse_disable();
  581. ikbd_joystick_disable();
  582. #ifdef FIXED_ATARI_JOYSTICK
  583. atari_joystick_init();
  584. #endif
  585. // flag init done
  586. atari_keyb_done = 1;
  587. return 0;
  588. }
  589. int atari_kbdrate(struct kbd_repeat *k)
  590. {
  591. if (k->delay > 0) {
  592. /* convert from msec to jiffies */
  593. key_repeat_delay = (k->delay * HZ + 500) / 1000;
  594. if (key_repeat_delay < 1)
  595. key_repeat_delay = 1;
  596. }
  597. if (k->period > 0) {
  598. key_repeat_rate = (k->period * HZ + 500) / 1000;
  599. if (key_repeat_rate < 1)
  600. key_repeat_rate = 1;
  601. }
  602. k->delay = key_repeat_delay * 1000 / HZ;
  603. k->period = key_repeat_rate * 1000 / HZ;
  604. return 0;
  605. }
  606. int atari_kbd_translate(unsigned char keycode, unsigned char *keycodep, char raw_mode)
  607. {
  608. #ifdef CONFIG_MAGIC_SYSRQ
  609. /* ALT+HELP pressed? */
  610. if ((keycode == 98) && ((shift_state & 0xff) == 8))
  611. *keycodep = 0xff;
  612. else
  613. #endif
  614. *keycodep = keycode;
  615. return 1;
  616. }