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