amikbd.c 6.4 KB

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