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