atakeyb.c 19 KB

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