atakbd.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * atakbd.c
  3. *
  4. * Copyright (c) 2005 Michael Schmitz
  5. *
  6. * Based on amikbd.c, which is
  7. *
  8. * Copyright (c) 2000-2001 Vojtech Pavlik
  9. *
  10. * Based on the work of:
  11. * Hamish Macdonald
  12. */
  13. /*
  14. * Atari keyboard driver for Linux/m68k
  15. *
  16. * The low level init and interrupt stuff is handled in arch/mm68k/atari/atakeyb.c
  17. * (the keyboard ACIA also handles the mouse and joystick data, and the keyboard
  18. * interrupt is shared with the MIDI ACIA so MIDI data also get handled there).
  19. * This driver only deals with handing key events off to the input layer.
  20. */
  21. /*
  22. * This program is free software; you can redistribute it and/or modify
  23. * it under the terms of the GNU General Public License as published by
  24. * the Free Software Foundation; either version 2 of the License, or
  25. * (at your option) any later version.
  26. *
  27. * This program is distributed in the hope that it will be useful,
  28. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. * GNU General Public License for more details.
  31. *
  32. * You should have received a copy of the GNU General Public License
  33. * along with this program; if not, write to the Free Software
  34. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  35. *
  36. * Should you need to contact me, the author, you can do so either by
  37. * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  38. * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
  39. */
  40. #include <linux/module.h>
  41. #include <linux/init.h>
  42. #include <linux/input.h>
  43. #include <linux/delay.h>
  44. #include <linux/interrupt.h>
  45. #include <asm/atariints.h>
  46. #include <asm/atarihw.h>
  47. #include <asm/atarikb.h>
  48. #include <asm/irq.h>
  49. MODULE_AUTHOR("Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>");
  50. MODULE_DESCRIPTION("Atari keyboard driver");
  51. MODULE_LICENSE("GPL");
  52. /*
  53. 0x47: KP_7 71
  54. 0x48: KP_8 72
  55. 0x49: KP_9 73
  56. 0x62: KP_/ 98
  57. 0x4b: KP_4 75
  58. 0x4c: KP_5 76
  59. 0x4d: KP_6 77
  60. 0x37: KP_* 55
  61. 0x4f: KP_1 79
  62. 0x50: KP_2 80
  63. 0x51: KP_3 81
  64. 0x4a: KP_- 74
  65. 0x52: KP_0 82
  66. 0x53: KP_. 83
  67. 0x4e: KP_+ 78
  68. 0x67: Up 103
  69. 0x6c: Down 108
  70. 0x69: Left 105
  71. 0x6a: Right 106
  72. */
  73. static unsigned char atakbd_keycode[0x73] = { /* American layout */
  74. [1] = KEY_ESC,
  75. [2] = KEY_1,
  76. [3] = KEY_2,
  77. [4] = KEY_3,
  78. [5] = KEY_4,
  79. [6] = KEY_5,
  80. [7] = KEY_6,
  81. [8] = KEY_7,
  82. [9] = KEY_8,
  83. [10] = KEY_9,
  84. [11] = KEY_0,
  85. [12] = KEY_MINUS,
  86. [13] = KEY_EQUAL,
  87. [14] = KEY_BACKSPACE,
  88. [15] = KEY_TAB,
  89. [16] = KEY_Q,
  90. [17] = KEY_W,
  91. [18] = KEY_E,
  92. [19] = KEY_R,
  93. [20] = KEY_T,
  94. [21] = KEY_Y,
  95. [22] = KEY_U,
  96. [23] = KEY_I,
  97. [24] = KEY_O,
  98. [25] = KEY_P,
  99. [26] = KEY_LEFTBRACE,
  100. [27] = KEY_RIGHTBRACE,
  101. [28] = KEY_ENTER,
  102. [29] = KEY_LEFTCTRL,
  103. [30] = KEY_A,
  104. [31] = KEY_S,
  105. [32] = KEY_D,
  106. [33] = KEY_F,
  107. [34] = KEY_G,
  108. [35] = KEY_H,
  109. [36] = KEY_J,
  110. [37] = KEY_K,
  111. [38] = KEY_L,
  112. [39] = KEY_SEMICOLON,
  113. [40] = KEY_APOSTROPHE,
  114. [41] = KEY_GRAVE,
  115. [42] = KEY_LEFTSHIFT,
  116. [43] = KEY_BACKSLASH,
  117. [44] = KEY_Z,
  118. [45] = KEY_X,
  119. [46] = KEY_C,
  120. [47] = KEY_V,
  121. [48] = KEY_B,
  122. [49] = KEY_N,
  123. [50] = KEY_M,
  124. [51] = KEY_COMMA,
  125. [52] = KEY_DOT,
  126. [53] = KEY_SLASH,
  127. [54] = KEY_RIGHTSHIFT,
  128. [55] = KEY_KPASTERISK,
  129. [56] = KEY_LEFTALT,
  130. [57] = KEY_SPACE,
  131. [58] = KEY_CAPSLOCK,
  132. [59] = KEY_F1,
  133. [60] = KEY_F2,
  134. [61] = KEY_F3,
  135. [62] = KEY_F4,
  136. [63] = KEY_F5,
  137. [64] = KEY_F6,
  138. [65] = KEY_F7,
  139. [66] = KEY_F8,
  140. [67] = KEY_F9,
  141. [68] = KEY_F10,
  142. [71] = KEY_HOME,
  143. [72] = KEY_UP,
  144. [74] = KEY_KPMINUS,
  145. [75] = KEY_LEFT,
  146. [77] = KEY_RIGHT,
  147. [78] = KEY_KPPLUS,
  148. [80] = KEY_DOWN,
  149. [82] = KEY_INSERT,
  150. [83] = KEY_DELETE,
  151. [96] = KEY_102ND,
  152. [97] = KEY_UNDO,
  153. [98] = KEY_HELP,
  154. [99] = KEY_KPLEFTPAREN,
  155. [100] = KEY_KPRIGHTPAREN,
  156. [101] = KEY_KPSLASH,
  157. [102] = KEY_KPASTERISK,
  158. [103] = KEY_KP7,
  159. [104] = KEY_KP8,
  160. [105] = KEY_KP9,
  161. [106] = KEY_KP4,
  162. [107] = KEY_KP5,
  163. [108] = KEY_KP6,
  164. [109] = KEY_KP1,
  165. [110] = KEY_KP2,
  166. [111] = KEY_KP3,
  167. [112] = KEY_KP0,
  168. [113] = KEY_KPDOT,
  169. [114] = KEY_KPENTER,
  170. };
  171. static struct input_dev *atakbd_dev;
  172. static void atakbd_interrupt(unsigned char scancode, char down)
  173. {
  174. if (scancode < 0x73) { /* scancodes < 0xf3 are keys */
  175. // report raw events here?
  176. scancode = atakbd_keycode[scancode];
  177. input_report_key(atakbd_dev, scancode, down);
  178. input_sync(atakbd_dev);
  179. } else /* scancodes >= 0xf3 are mouse data, most likely */
  180. printk(KERN_INFO "atakbd: unhandled scancode %x\n", scancode);
  181. return;
  182. }
  183. static int __init atakbd_init(void)
  184. {
  185. int i, error;
  186. if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ST_MFP))
  187. return -ENODEV;
  188. // need to init core driver if not already done so
  189. error = atari_keyb_init();
  190. if (error)
  191. return error;
  192. atakbd_dev = input_allocate_device();
  193. if (!atakbd_dev)
  194. return -ENOMEM;
  195. atakbd_dev->name = "Atari Keyboard";
  196. atakbd_dev->phys = "atakbd/input0";
  197. atakbd_dev->id.bustype = BUS_HOST;
  198. atakbd_dev->id.vendor = 0x0001;
  199. atakbd_dev->id.product = 0x0001;
  200. atakbd_dev->id.version = 0x0100;
  201. atakbd_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
  202. atakbd_dev->keycode = atakbd_keycode;
  203. atakbd_dev->keycodesize = sizeof(unsigned char);
  204. atakbd_dev->keycodemax = ARRAY_SIZE(atakbd_keycode);
  205. for (i = 1; i < 0x72; i++) {
  206. set_bit(atakbd_keycode[i], atakbd_dev->keybit);
  207. }
  208. /* error check */
  209. error = input_register_device(atakbd_dev);
  210. if (error) {
  211. input_free_device(atakbd_dev);
  212. return error;
  213. }
  214. atari_input_keyboard_interrupt_hook = atakbd_interrupt;
  215. return 0;
  216. }
  217. static void __exit atakbd_exit(void)
  218. {
  219. atari_input_keyboard_interrupt_hook = NULL;
  220. input_unregister_device(atakbd_dev);
  221. }
  222. module_init(atakbd_init);
  223. module_exit(atakbd_exit);