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