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