Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  atakbd.c
0004  *
0005  *  Copyright (c) 2005 Michael Schmitz
0006  *
0007  * Based on amikbd.c, which is
0008  *
0009  *  Copyright (c) 2000-2001 Vojtech Pavlik
0010  *
0011  *  Based on the work of:
0012  *  Hamish Macdonald
0013  */
0014 
0015 /*
0016  * Atari keyboard driver for Linux/m68k
0017  *
0018  * The low level init and interrupt stuff is handled in arch/mm68k/atari/atakeyb.c
0019  * (the keyboard ACIA also handles the mouse and joystick data, and the keyboard
0020  * interrupt is shared with the MIDI ACIA so MIDI data also get handled there).
0021  * This driver only deals with handing key events off to the input layer.
0022  */
0023 
0024 /*
0025  */
0026 
0027 #include <linux/module.h>
0028 #include <linux/init.h>
0029 #include <linux/input.h>
0030 #include <linux/delay.h>
0031 #include <linux/interrupt.h>
0032 
0033 #include <asm/atariints.h>
0034 #include <asm/atarihw.h>
0035 #include <asm/atarikb.h>
0036 #include <asm/irq.h>
0037 
0038 MODULE_AUTHOR("Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>");
0039 MODULE_DESCRIPTION("Atari keyboard driver");
0040 MODULE_LICENSE("GPL");
0041 
0042 /*
0043  0x47: KP_7     71
0044  0x48: KP_8     72
0045  0x49: KP_9     73
0046  0x62: KP_/     98
0047  0x4b: KP_4     75
0048  0x4c: KP_5     76
0049  0x4d: KP_6     77
0050  0x37: KP_*     55
0051  0x4f: KP_1     79
0052  0x50: KP_2     80
0053  0x51: KP_3     81
0054  0x4a: KP_-     74
0055  0x52: KP_0     82
0056  0x53: KP_.     83
0057  0x4e: KP_+     78
0058 
0059  0x67: Up       103
0060  0x6c: Down     108
0061  0x69: Left     105
0062  0x6a: Right    106
0063  */
0064 
0065 
0066 static unsigned char atakbd_keycode[0x73] = {   /* American layout */
0067     [1]  = KEY_ESC,
0068     [2]  = KEY_1,
0069     [3]  = KEY_2,
0070     [4]  = KEY_3,
0071     [5]  = KEY_4,
0072     [6]  = KEY_5,
0073     [7]  = KEY_6,
0074     [8]  = KEY_7,
0075     [9]  = KEY_8,
0076     [10]     = KEY_9,
0077     [11]     = KEY_0,
0078     [12]     = KEY_MINUS,
0079     [13]     = KEY_EQUAL,
0080     [14]     = KEY_BACKSPACE,
0081     [15]     = KEY_TAB,
0082     [16]     = KEY_Q,
0083     [17]     = KEY_W,
0084     [18]     = KEY_E,
0085     [19]     = KEY_R,
0086     [20]     = KEY_T,
0087     [21]     = KEY_Y,
0088     [22]     = KEY_U,
0089     [23]     = KEY_I,
0090     [24]     = KEY_O,
0091     [25]     = KEY_P,
0092     [26]     = KEY_LEFTBRACE,
0093     [27]     = KEY_RIGHTBRACE,
0094     [28]     = KEY_ENTER,
0095     [29]     = KEY_LEFTCTRL,
0096     [30]     = KEY_A,
0097     [31]     = KEY_S,
0098     [32]     = KEY_D,
0099     [33]     = KEY_F,
0100     [34]     = KEY_G,
0101     [35]     = KEY_H,
0102     [36]     = KEY_J,
0103     [37]     = KEY_K,
0104     [38]     = KEY_L,
0105     [39]     = KEY_SEMICOLON,
0106     [40]     = KEY_APOSTROPHE,
0107     [41]     = KEY_GRAVE,
0108     [42]     = KEY_LEFTSHIFT,
0109     [43]     = KEY_BACKSLASH,
0110     [44]     = KEY_Z,
0111     [45]     = KEY_X,
0112     [46]     = KEY_C,
0113     [47]     = KEY_V,
0114     [48]     = KEY_B,
0115     [49]     = KEY_N,
0116     [50]     = KEY_M,
0117     [51]     = KEY_COMMA,
0118     [52]     = KEY_DOT,
0119     [53]     = KEY_SLASH,
0120     [54]     = KEY_RIGHTSHIFT,
0121     [55]     = KEY_KPASTERISK,
0122     [56]     = KEY_LEFTALT,
0123     [57]     = KEY_SPACE,
0124     [58]     = KEY_CAPSLOCK,
0125     [59]     = KEY_F1,
0126     [60]     = KEY_F2,
0127     [61]     = KEY_F3,
0128     [62]     = KEY_F4,
0129     [63]     = KEY_F5,
0130     [64]     = KEY_F6,
0131     [65]     = KEY_F7,
0132     [66]     = KEY_F8,
0133     [67]     = KEY_F9,
0134     [68]     = KEY_F10,
0135     [71]     = KEY_HOME,
0136     [72]     = KEY_UP,
0137     [74]     = KEY_KPMINUS,
0138     [75]     = KEY_LEFT,
0139     [77]     = KEY_RIGHT,
0140     [78]     = KEY_KPPLUS,
0141     [80]     = KEY_DOWN,
0142     [82]     = KEY_INSERT,
0143     [83]     = KEY_DELETE,
0144     [96]     = KEY_102ND,
0145     [97]     = KEY_UNDO,
0146     [98]     = KEY_HELP,
0147     [99]     = KEY_KPLEFTPAREN,
0148     [100]    = KEY_KPRIGHTPAREN,
0149     [101]    = KEY_KPSLASH,
0150     [102]    = KEY_KPASTERISK,
0151     [103]    = KEY_KP7,
0152     [104]    = KEY_KP8,
0153     [105]    = KEY_KP9,
0154     [106]    = KEY_KP4,
0155     [107]    = KEY_KP5,
0156     [108]    = KEY_KP6,
0157     [109]    = KEY_KP1,
0158     [110]    = KEY_KP2,
0159     [111]    = KEY_KP3,
0160     [112]    = KEY_KP0,
0161     [113]    = KEY_KPDOT,
0162     [114]    = KEY_KPENTER,
0163 };
0164 
0165 static struct input_dev *atakbd_dev;
0166 
0167 static void atakbd_interrupt(unsigned char scancode, char down)
0168 {
0169 
0170     if (scancode < 0x73) {      /* scancodes < 0xf3 are keys */
0171 
0172         // report raw events here?
0173 
0174         scancode = atakbd_keycode[scancode];
0175 
0176         input_report_key(atakbd_dev, scancode, down);
0177         input_sync(atakbd_dev);
0178     } else              /* scancodes >= 0xf3 are mouse data, most likely */
0179         printk(KERN_INFO "atakbd: unhandled scancode %x\n", scancode);
0180 
0181     return;
0182 }
0183 
0184 static int __init atakbd_init(void)
0185 {
0186     int i, error;
0187 
0188     if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ST_MFP))
0189         return -ENODEV;
0190 
0191     // need to init core driver if not already done so
0192     error = atari_keyb_init();
0193     if (error)
0194         return error;
0195 
0196     atakbd_dev = input_allocate_device();
0197     if (!atakbd_dev)
0198         return -ENOMEM;
0199 
0200     atakbd_dev->name = "Atari Keyboard";
0201     atakbd_dev->phys = "atakbd/input0";
0202     atakbd_dev->id.bustype = BUS_HOST;
0203     atakbd_dev->id.vendor = 0x0001;
0204     atakbd_dev->id.product = 0x0001;
0205     atakbd_dev->id.version = 0x0100;
0206 
0207     atakbd_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
0208     atakbd_dev->keycode = atakbd_keycode;
0209     atakbd_dev->keycodesize = sizeof(unsigned char);
0210     atakbd_dev->keycodemax = ARRAY_SIZE(atakbd_keycode);
0211 
0212     for (i = 1; i < 0x72; i++) {
0213         set_bit(atakbd_keycode[i], atakbd_dev->keybit);
0214     }
0215 
0216     /* error check */
0217     error = input_register_device(atakbd_dev);
0218     if (error) {
0219         input_free_device(atakbd_dev);
0220         return error;
0221     }
0222 
0223     atari_input_keyboard_interrupt_hook = atakbd_interrupt;
0224 
0225     return 0;
0226 }
0227 
0228 static void __exit atakbd_exit(void)
0229 {
0230     atari_input_keyboard_interrupt_hook = NULL;
0231     input_unregister_device(atakbd_dev);
0232 }
0233 
0234 module_init(atakbd_init);
0235 module_exit(atakbd_exit);