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