atakbd.c 4.7 KB

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