amikbd.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * Copyright (c) 2000-2001 Vojtech Pavlik
  3. *
  4. * Based on the work of:
  5. * Hamish Macdonald
  6. */
  7. /*
  8. * Amiga keyboard driver for Linux/m68k
  9. */
  10. /*
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. *
  25. * Should you need to contact me, the author, you can do so either by
  26. * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  27. * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
  28. */
  29. #include <linux/module.h>
  30. #include <linux/init.h>
  31. #include <linux/input.h>
  32. #include <linux/delay.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/keyboard.h>
  35. #include <asm/amigaints.h>
  36. #include <asm/amigahw.h>
  37. #include <asm/irq.h>
  38. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  39. MODULE_DESCRIPTION("Amiga keyboard driver");
  40. MODULE_LICENSE("GPL");
  41. static unsigned char amikbd_keycode[0x78] __initdata = {
  42. [0] = KEY_GRAVE,
  43. [1] = KEY_1,
  44. [2] = KEY_2,
  45. [3] = KEY_3,
  46. [4] = KEY_4,
  47. [5] = KEY_5,
  48. [6] = KEY_6,
  49. [7] = KEY_7,
  50. [8] = KEY_8,
  51. [9] = KEY_9,
  52. [10] = KEY_0,
  53. [11] = KEY_MINUS,
  54. [12] = KEY_EQUAL,
  55. [13] = KEY_BACKSLASH,
  56. [15] = KEY_KP0,
  57. [16] = KEY_Q,
  58. [17] = KEY_W,
  59. [18] = KEY_E,
  60. [19] = KEY_R,
  61. [20] = KEY_T,
  62. [21] = KEY_Y,
  63. [22] = KEY_U,
  64. [23] = KEY_I,
  65. [24] = KEY_O,
  66. [25] = KEY_P,
  67. [26] = KEY_LEFTBRACE,
  68. [27] = KEY_RIGHTBRACE,
  69. [29] = KEY_KP1,
  70. [30] = KEY_KP2,
  71. [31] = KEY_KP3,
  72. [32] = KEY_A,
  73. [33] = KEY_S,
  74. [34] = KEY_D,
  75. [35] = KEY_F,
  76. [36] = KEY_G,
  77. [37] = KEY_H,
  78. [38] = KEY_J,
  79. [39] = KEY_K,
  80. [40] = KEY_L,
  81. [41] = KEY_SEMICOLON,
  82. [42] = KEY_APOSTROPHE,
  83. [43] = KEY_BACKSLASH,
  84. [45] = KEY_KP4,
  85. [46] = KEY_KP5,
  86. [47] = KEY_KP6,
  87. [48] = KEY_102ND,
  88. [49] = KEY_Z,
  89. [50] = KEY_X,
  90. [51] = KEY_C,
  91. [52] = KEY_V,
  92. [53] = KEY_B,
  93. [54] = KEY_N,
  94. [55] = KEY_M,
  95. [56] = KEY_COMMA,
  96. [57] = KEY_DOT,
  97. [58] = KEY_SLASH,
  98. [60] = KEY_KPDOT,
  99. [61] = KEY_KP7,
  100. [62] = KEY_KP8,
  101. [63] = KEY_KP9,
  102. [64] = KEY_SPACE,
  103. [65] = KEY_BACKSPACE,
  104. [66] = KEY_TAB,
  105. [67] = KEY_KPENTER,
  106. [68] = KEY_ENTER,
  107. [69] = KEY_ESC,
  108. [70] = KEY_DELETE,
  109. [74] = KEY_KPMINUS,
  110. [76] = KEY_UP,
  111. [77] = KEY_DOWN,
  112. [78] = KEY_RIGHT,
  113. [79] = KEY_LEFT,
  114. [80] = KEY_F1,
  115. [81] = KEY_F2,
  116. [82] = KEY_F3,
  117. [83] = KEY_F4,
  118. [84] = KEY_F5,
  119. [85] = KEY_F6,
  120. [86] = KEY_F7,
  121. [87] = KEY_F8,
  122. [88] = KEY_F9,
  123. [89] = KEY_F10,
  124. [90] = KEY_KPLEFTPAREN,
  125. [91] = KEY_KPRIGHTPAREN,
  126. [92] = KEY_KPSLASH,
  127. [93] = KEY_KPASTERISK,
  128. [94] = KEY_KPPLUS,
  129. [95] = KEY_HELP,
  130. [96] = KEY_LEFTSHIFT,
  131. [97] = KEY_RIGHTSHIFT,
  132. [98] = KEY_CAPSLOCK,
  133. [99] = KEY_LEFTCTRL,
  134. [100] = KEY_LEFTALT,
  135. [101] = KEY_RIGHTALT,
  136. [102] = KEY_LEFTMETA,
  137. [103] = KEY_RIGHTMETA
  138. };
  139. static const char *amikbd_messages[8] = {
  140. [0] = KERN_ALERT "amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
  141. [1] = KERN_WARNING "amikbd: keyboard lost sync\n",
  142. [2] = KERN_WARNING "amikbd: keyboard buffer overflow\n",
  143. [3] = KERN_WARNING "amikbd: keyboard controller failure\n",
  144. [4] = KERN_ERR "amikbd: keyboard selftest failure\n",
  145. [5] = KERN_INFO "amikbd: initiate power-up key stream\n",
  146. [6] = KERN_INFO "amikbd: terminate power-up key stream\n",
  147. [7] = KERN_WARNING "amikbd: keyboard interrupt\n"
  148. };
  149. static struct input_dev *amikbd_dev;
  150. static irqreturn_t amikbd_interrupt(int irq, void *dummy)
  151. {
  152. unsigned char scancode, down;
  153. scancode = ~ciaa.sdr; /* get and invert scancode (keyboard is active low) */
  154. ciaa.cra |= 0x40; /* switch SP pin to output for handshake */
  155. udelay(85); /* wait until 85 us have expired */
  156. ciaa.cra &= ~0x40; /* switch CIA serial port to input mode */
  157. down = !(scancode & 1); /* lowest bit is release bit */
  158. scancode >>= 1;
  159. if (scancode < 0x78) { /* scancodes < 0x78 are keys */
  160. if (scancode == 98) { /* CapsLock is a toggle switch key on Amiga */
  161. input_report_key(amikbd_dev, scancode, 1);
  162. input_report_key(amikbd_dev, scancode, 0);
  163. } else {
  164. input_report_key(amikbd_dev, scancode, down);
  165. }
  166. input_sync(amikbd_dev);
  167. } else /* scancodes >= 0x78 are error codes */
  168. printk(amikbd_messages[scancode - 0x78]);
  169. return IRQ_HANDLED;
  170. }
  171. static int __init amikbd_init(void)
  172. {
  173. int i, j, err;
  174. if (!AMIGAHW_PRESENT(AMI_KEYBOARD))
  175. return -ENODEV;
  176. if (!request_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100, "amikeyb"))
  177. return -EBUSY;
  178. amikbd_dev = input_allocate_device();
  179. if (!amikbd_dev) {
  180. printk(KERN_ERR "amikbd: not enough memory for input device\n");
  181. err = -ENOMEM;
  182. goto fail1;
  183. }
  184. amikbd_dev->name = "Amiga Keyboard";
  185. amikbd_dev->phys = "amikbd/input0";
  186. amikbd_dev->id.bustype = BUS_AMIGA;
  187. amikbd_dev->id.vendor = 0x0001;
  188. amikbd_dev->id.product = 0x0001;
  189. amikbd_dev->id.version = 0x0100;
  190. amikbd_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
  191. for (i = 0; i < 0x78; i++)
  192. set_bit(i, amikbd_dev->keybit);
  193. for (i = 0; i < MAX_NR_KEYMAPS; i++) {
  194. static u_short temp_map[NR_KEYS] __initdata;
  195. if (!key_maps[i])
  196. continue;
  197. memset(temp_map, 0, sizeof(temp_map));
  198. for (j = 0; j < 0x78; j++) {
  199. if (!amikbd_keycode[j])
  200. continue;
  201. temp_map[j] = key_maps[i][amikbd_keycode[j]];
  202. }
  203. for (j = 0; j < NR_KEYS; j++) {
  204. if (!temp_map[j])
  205. temp_map[j] = 0xf200;
  206. }
  207. memcpy(key_maps[i], temp_map, sizeof(temp_map));
  208. }
  209. ciaa.cra &= ~0x41; /* serial data in, turn off TA */
  210. if (request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd",
  211. amikbd_interrupt)) {
  212. err = -EBUSY;
  213. goto fail2;
  214. }
  215. err = input_register_device(amikbd_dev);
  216. if (err)
  217. goto fail3;
  218. return 0;
  219. fail3: free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt);
  220. fail2: input_free_device(amikbd_dev);
  221. fail1: release_mem_region(CIAA_PHYSADDR - 1 + 0xb00, 0x100);
  222. return err;
  223. }
  224. static void __exit amikbd_exit(void)
  225. {
  226. free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt);
  227. input_unregister_device(amikbd_dev);
  228. release_mem_region(CIAA_PHYSADDR - 1 + 0xb00, 0x100);
  229. }
  230. module_init(amikbd_init);
  231. module_exit(amikbd_exit);