atakbd.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. #include <linux/module.h>
  37. #include <linux/init.h>
  38. #include <linux/input.h>
  39. #include <linux/delay.h>
  40. #include <linux/interrupt.h>
  41. #include <asm/atariints.h>
  42. #include <asm/atarihw.h>
  43. #include <asm/atarikb.h>
  44. #include <asm/irq.h>
  45. MODULE_AUTHOR("Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>");
  46. MODULE_DESCRIPTION("Atari keyboard driver");
  47. MODULE_LICENSE("GPL");
  48. /*
  49. 0x47: KP_7 71
  50. 0x48: KP_8 72
  51. 0x49: KP_9 73
  52. 0x62: KP_/ 98
  53. 0x4b: KP_4 75
  54. 0x4c: KP_5 76
  55. 0x4d: KP_6 77
  56. 0x37: KP_* 55
  57. 0x4f: KP_1 79
  58. 0x50: KP_2 80
  59. 0x51: KP_3 81
  60. 0x4a: KP_- 74
  61. 0x52: KP_0 82
  62. 0x53: KP_. 83
  63. 0x4e: KP_+ 78
  64. 0x67: Up 103
  65. 0x6c: Down 108
  66. 0x69: Left 105
  67. 0x6a: Right 106
  68. */
  69. static unsigned char atakbd_keycode[0x73] = { /* American layout */
  70. [1] = KEY_ESC,
  71. [2] = KEY_1,
  72. [3] = KEY_2,
  73. [4] = KEY_3,
  74. [5] = KEY_4,
  75. [6] = KEY_5,
  76. [7] = KEY_6,
  77. [8] = KEY_7,
  78. [9] = KEY_8,
  79. [10] = KEY_9,
  80. [11] = KEY_0,
  81. [12] = KEY_MINUS,
  82. [13] = KEY_EQUAL,
  83. [14] = KEY_BACKSPACE,
  84. [15] = KEY_TAB,
  85. [16] = KEY_Q,
  86. [17] = KEY_W,
  87. [18] = KEY_E,
  88. [19] = KEY_R,
  89. [20] = KEY_T,
  90. [21] = KEY_Y,
  91. [22] = KEY_U,
  92. [23] = KEY_I,
  93. [24] = KEY_O,
  94. [25] = KEY_P,
  95. [26] = KEY_LEFTBRACE,
  96. [27] = KEY_RIGHTBRACE,
  97. [28] = KEY_ENTER,
  98. [29] = KEY_LEFTCTRL,
  99. [30] = KEY_A,
  100. [31] = KEY_S,
  101. [32] = KEY_D,
  102. [33] = KEY_F,
  103. [34] = KEY_G,
  104. [35] = KEY_H,
  105. [36] = KEY_J,
  106. [37] = KEY_K,
  107. [38] = KEY_L,
  108. [39] = KEY_SEMICOLON,
  109. [40] = KEY_APOSTROPHE,
  110. [41] = KEY_GRAVE,
  111. [42] = KEY_LEFTSHIFT,
  112. [43] = KEY_BACKSLASH,
  113. [44] = KEY_Z,
  114. [45] = KEY_X,
  115. [46] = KEY_C,
  116. [47] = KEY_V,
  117. [48] = KEY_B,
  118. [49] = KEY_N,
  119. [50] = KEY_M,
  120. [51] = KEY_COMMA,
  121. [52] = KEY_DOT,
  122. [53] = KEY_SLASH,
  123. [54] = KEY_RIGHTSHIFT,
  124. [55] = KEY_KPASTERISK,
  125. [56] = KEY_LEFTALT,
  126. [57] = KEY_SPACE,
  127. [58] = KEY_CAPSLOCK,
  128. [59] = KEY_F1,
  129. [60] = KEY_F2,
  130. [61] = KEY_F3,
  131. [62] = KEY_F4,
  132. [63] = KEY_F5,
  133. [64] = KEY_F6,
  134. [65] = KEY_F7,
  135. [66] = KEY_F8,
  136. [67] = KEY_F9,
  137. [68] = KEY_F10,
  138. [71] = KEY_HOME,
  139. [72] = KEY_UP,
  140. [74] = KEY_KPMINUS,
  141. [75] = KEY_LEFT,
  142. [77] = KEY_RIGHT,
  143. [78] = KEY_KPPLUS,
  144. [80] = KEY_DOWN,
  145. [82] = KEY_INSERT,
  146. [83] = KEY_DELETE,
  147. [96] = KEY_102ND,
  148. [97] = KEY_UNDO,
  149. [98] = KEY_HELP,
  150. [99] = KEY_KPLEFTPAREN,
  151. [100] = KEY_KPRIGHTPAREN,
  152. [101] = KEY_KPSLASH,
  153. [102] = KEY_KPASTERISK,
  154. [103] = KEY_KP7,
  155. [104] = KEY_KP8,
  156. [105] = KEY_KP9,
  157. [106] = KEY_KP4,
  158. [107] = KEY_KP5,
  159. [108] = KEY_KP6,
  160. [109] = KEY_KP1,
  161. [110] = KEY_KP2,
  162. [111] = KEY_KP3,
  163. [112] = KEY_KP0,
  164. [113] = KEY_KPDOT,
  165. [114] = KEY_KPENTER,
  166. };
  167. static struct input_dev *atakbd_dev;
  168. static void atakbd_interrupt(unsigned char scancode, char down)
  169. {
  170. if (scancode < 0x73) { /* scancodes < 0xf3 are keys */
  171. // report raw events here?
  172. scancode = atakbd_keycode[scancode];
  173. input_report_key(atakbd_dev, scancode, down);
  174. input_sync(atakbd_dev);
  175. } else /* scancodes >= 0xf3 are mouse data, most likely */
  176. printk(KERN_INFO "atakbd: unhandled scancode %x\n", scancode);
  177. return;
  178. }
  179. static int __init atakbd_init(void)
  180. {
  181. int i, error;
  182. if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ST_MFP))
  183. return -ENODEV;
  184. // need to init core driver if not already done so
  185. error = atari_keyb_init();
  186. if (error)
  187. return error;
  188. atakbd_dev = input_allocate_device();
  189. if (!atakbd_dev)
  190. return -ENOMEM;
  191. atakbd_dev->name = "Atari Keyboard";
  192. atakbd_dev->phys = "atakbd/input0";
  193. atakbd_dev->id.bustype = BUS_HOST;
  194. atakbd_dev->id.vendor = 0x0001;
  195. atakbd_dev->id.product = 0x0001;
  196. atakbd_dev->id.version = 0x0100;
  197. atakbd_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
  198. atakbd_dev->keycode = atakbd_keycode;
  199. atakbd_dev->keycodesize = sizeof(unsigned char);
  200. atakbd_dev->keycodemax = ARRAY_SIZE(atakbd_keycode);
  201. for (i = 1; i < 0x72; i++) {
  202. set_bit(atakbd_keycode[i], atakbd_dev->keybit);
  203. }
  204. /* error check */
  205. error = input_register_device(atakbd_dev);
  206. if (error) {
  207. input_free_device(atakbd_dev);
  208. return error;
  209. }
  210. atari_input_keyboard_interrupt_hook = atakbd_interrupt;
  211. return 0;
  212. }
  213. static void __exit atakbd_exit(void)
  214. {
  215. atari_input_keyboard_interrupt_hook = NULL;
  216. input_unregister_device(atakbd_dev);
  217. }
  218. module_init(atakbd_init);
  219. module_exit(atakbd_exit);