xref: /openbmc/linux/drivers/input/keyboard/atakbd.c (revision 2d09ac95)
11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2c04cb856SMichael Schmitz /*
3c04cb856SMichael Schmitz  *  atakbd.c
4c04cb856SMichael Schmitz  *
5c04cb856SMichael Schmitz  *  Copyright (c) 2005 Michael Schmitz
6c04cb856SMichael Schmitz  *
7c04cb856SMichael Schmitz  * Based on amikbd.c, which is
8c04cb856SMichael Schmitz  *
9c04cb856SMichael Schmitz  *  Copyright (c) 2000-2001 Vojtech Pavlik
10c04cb856SMichael Schmitz  *
11c04cb856SMichael Schmitz  *  Based on the work of:
12c04cb856SMichael Schmitz  *	Hamish Macdonald
13c04cb856SMichael Schmitz  */
14c04cb856SMichael Schmitz 
15c04cb856SMichael Schmitz /*
16c04cb856SMichael Schmitz  * Atari keyboard driver for Linux/m68k
17c04cb856SMichael Schmitz  *
18c04cb856SMichael Schmitz  * The low level init and interrupt stuff is handled in arch/mm68k/atari/atakeyb.c
19c04cb856SMichael Schmitz  * (the keyboard ACIA also handles the mouse and joystick data, and the keyboard
20c04cb856SMichael Schmitz  * interrupt is shared with the MIDI ACIA so MIDI data also get handled there).
21c04cb856SMichael Schmitz  * This driver only deals with handing key events off to the input layer.
22c04cb856SMichael Schmitz  */
23c04cb856SMichael Schmitz 
24c04cb856SMichael Schmitz #include <linux/module.h>
25c04cb856SMichael Schmitz #include <linux/init.h>
26c04cb856SMichael Schmitz #include <linux/input.h>
27c04cb856SMichael Schmitz #include <linux/delay.h>
28c04cb856SMichael Schmitz #include <linux/interrupt.h>
29c04cb856SMichael Schmitz 
30c04cb856SMichael Schmitz #include <asm/atariints.h>
31c04cb856SMichael Schmitz #include <asm/atarihw.h>
32c04cb856SMichael Schmitz #include <asm/atarikb.h>
33c04cb856SMichael Schmitz #include <asm/irq.h>
34c04cb856SMichael Schmitz 
35c04cb856SMichael Schmitz MODULE_AUTHOR("Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>");
36c04cb856SMichael Schmitz MODULE_DESCRIPTION("Atari keyboard driver");
37c04cb856SMichael Schmitz MODULE_LICENSE("GPL");
38c04cb856SMichael Schmitz 
396615c5b2SGeert Uytterhoeven /*
406615c5b2SGeert Uytterhoeven  0x47: KP_7     71
416615c5b2SGeert Uytterhoeven  0x48: KP_8     72
426615c5b2SGeert Uytterhoeven  0x49: KP_9     73
436615c5b2SGeert Uytterhoeven  0x62: KP_/     98
446615c5b2SGeert Uytterhoeven  0x4b: KP_4     75
456615c5b2SGeert Uytterhoeven  0x4c: KP_5     76
466615c5b2SGeert Uytterhoeven  0x4d: KP_6     77
476615c5b2SGeert Uytterhoeven  0x37: KP_*     55
486615c5b2SGeert Uytterhoeven  0x4f: KP_1     79
496615c5b2SGeert Uytterhoeven  0x50: KP_2     80
506615c5b2SGeert Uytterhoeven  0x51: KP_3     81
516615c5b2SGeert Uytterhoeven  0x4a: KP_-     74
526615c5b2SGeert Uytterhoeven  0x52: KP_0     82
536615c5b2SGeert Uytterhoeven  0x53: KP_.     83
546615c5b2SGeert Uytterhoeven  0x4e: KP_+     78
556615c5b2SGeert Uytterhoeven 
566615c5b2SGeert Uytterhoeven  0x67: Up       103
576615c5b2SGeert Uytterhoeven  0x6c: Down     108
586615c5b2SGeert Uytterhoeven  0x69: Left     105
596615c5b2SGeert Uytterhoeven  0x6a: Right    106
606615c5b2SGeert Uytterhoeven  */
616615c5b2SGeert Uytterhoeven 
626615c5b2SGeert Uytterhoeven 
639e62df51SAndreas Schwab static unsigned char atakbd_keycode[0x73] = {	/* American layout */
646615c5b2SGeert Uytterhoeven 	[1]	 = KEY_ESC,
656615c5b2SGeert Uytterhoeven 	[2]	 = KEY_1,
666615c5b2SGeert Uytterhoeven 	[3]	 = KEY_2,
676615c5b2SGeert Uytterhoeven 	[4]	 = KEY_3,
686615c5b2SGeert Uytterhoeven 	[5]	 = KEY_4,
696615c5b2SGeert Uytterhoeven 	[6]	 = KEY_5,
706615c5b2SGeert Uytterhoeven 	[7]	 = KEY_6,
716615c5b2SGeert Uytterhoeven 	[8]	 = KEY_7,
726615c5b2SGeert Uytterhoeven 	[9]	 = KEY_8,
736615c5b2SGeert Uytterhoeven 	[10]	 = KEY_9,
746615c5b2SGeert Uytterhoeven 	[11]	 = KEY_0,
756615c5b2SGeert Uytterhoeven 	[12]	 = KEY_MINUS,
766615c5b2SGeert Uytterhoeven 	[13]	 = KEY_EQUAL,
776615c5b2SGeert Uytterhoeven 	[14]	 = KEY_BACKSPACE,
786615c5b2SGeert Uytterhoeven 	[15]	 = KEY_TAB,
796615c5b2SGeert Uytterhoeven 	[16]	 = KEY_Q,
806615c5b2SGeert Uytterhoeven 	[17]	 = KEY_W,
816615c5b2SGeert Uytterhoeven 	[18]	 = KEY_E,
826615c5b2SGeert Uytterhoeven 	[19]	 = KEY_R,
836615c5b2SGeert Uytterhoeven 	[20]	 = KEY_T,
846615c5b2SGeert Uytterhoeven 	[21]	 = KEY_Y,
856615c5b2SGeert Uytterhoeven 	[22]	 = KEY_U,
866615c5b2SGeert Uytterhoeven 	[23]	 = KEY_I,
876615c5b2SGeert Uytterhoeven 	[24]	 = KEY_O,
886615c5b2SGeert Uytterhoeven 	[25]	 = KEY_P,
896615c5b2SGeert Uytterhoeven 	[26]	 = KEY_LEFTBRACE,
906615c5b2SGeert Uytterhoeven 	[27]	 = KEY_RIGHTBRACE,
916615c5b2SGeert Uytterhoeven 	[28]	 = KEY_ENTER,
926615c5b2SGeert Uytterhoeven 	[29]	 = KEY_LEFTCTRL,
936615c5b2SGeert Uytterhoeven 	[30]	 = KEY_A,
946615c5b2SGeert Uytterhoeven 	[31]	 = KEY_S,
956615c5b2SGeert Uytterhoeven 	[32]	 = KEY_D,
966615c5b2SGeert Uytterhoeven 	[33]	 = KEY_F,
976615c5b2SGeert Uytterhoeven 	[34]	 = KEY_G,
986615c5b2SGeert Uytterhoeven 	[35]	 = KEY_H,
996615c5b2SGeert Uytterhoeven 	[36]	 = KEY_J,
1006615c5b2SGeert Uytterhoeven 	[37]	 = KEY_K,
1016615c5b2SGeert Uytterhoeven 	[38]	 = KEY_L,
1026615c5b2SGeert Uytterhoeven 	[39]	 = KEY_SEMICOLON,
1036615c5b2SGeert Uytterhoeven 	[40]	 = KEY_APOSTROPHE,
1049e62df51SAndreas Schwab 	[41]	 = KEY_GRAVE,
1056615c5b2SGeert Uytterhoeven 	[42]	 = KEY_LEFTSHIFT,
1069e62df51SAndreas Schwab 	[43]	 = KEY_BACKSLASH,
1076615c5b2SGeert Uytterhoeven 	[44]	 = KEY_Z,
1086615c5b2SGeert Uytterhoeven 	[45]	 = KEY_X,
1096615c5b2SGeert Uytterhoeven 	[46]	 = KEY_C,
1106615c5b2SGeert Uytterhoeven 	[47]	 = KEY_V,
1116615c5b2SGeert Uytterhoeven 	[48]	 = KEY_B,
1126615c5b2SGeert Uytterhoeven 	[49]	 = KEY_N,
1136615c5b2SGeert Uytterhoeven 	[50]	 = KEY_M,
1146615c5b2SGeert Uytterhoeven 	[51]	 = KEY_COMMA,
1156615c5b2SGeert Uytterhoeven 	[52]	 = KEY_DOT,
1166615c5b2SGeert Uytterhoeven 	[53]	 = KEY_SLASH,
1176615c5b2SGeert Uytterhoeven 	[54]	 = KEY_RIGHTSHIFT,
1186615c5b2SGeert Uytterhoeven 	[55]	 = KEY_KPASTERISK,
1196615c5b2SGeert Uytterhoeven 	[56]	 = KEY_LEFTALT,
1206615c5b2SGeert Uytterhoeven 	[57]	 = KEY_SPACE,
1216615c5b2SGeert Uytterhoeven 	[58]	 = KEY_CAPSLOCK,
1226615c5b2SGeert Uytterhoeven 	[59]	 = KEY_F1,
1236615c5b2SGeert Uytterhoeven 	[60]	 = KEY_F2,
1246615c5b2SGeert Uytterhoeven 	[61]	 = KEY_F3,
1256615c5b2SGeert Uytterhoeven 	[62]	 = KEY_F4,
1266615c5b2SGeert Uytterhoeven 	[63]	 = KEY_F5,
1276615c5b2SGeert Uytterhoeven 	[64]	 = KEY_F6,
1286615c5b2SGeert Uytterhoeven 	[65]	 = KEY_F7,
1296615c5b2SGeert Uytterhoeven 	[66]	 = KEY_F8,
1306615c5b2SGeert Uytterhoeven 	[67]	 = KEY_F9,
1316615c5b2SGeert Uytterhoeven 	[68]	 = KEY_F10,
1329e62df51SAndreas Schwab 	[71]	 = KEY_HOME,
1339e62df51SAndreas Schwab 	[72]	 = KEY_UP,
1346615c5b2SGeert Uytterhoeven 	[74]	 = KEY_KPMINUS,
1359e62df51SAndreas Schwab 	[75]	 = KEY_LEFT,
1369e62df51SAndreas Schwab 	[77]	 = KEY_RIGHT,
1376615c5b2SGeert Uytterhoeven 	[78]	 = KEY_KPPLUS,
1389e62df51SAndreas Schwab 	[80]	 = KEY_DOWN,
1399e62df51SAndreas Schwab 	[82]	 = KEY_INSERT,
1409e62df51SAndreas Schwab 	[83]	 = KEY_DELETE,
1419923d858SMichael Karcher 	[96]	 = KEY_102ND,
1429e62df51SAndreas Schwab 	[97]	 = KEY_UNDO,
1439e62df51SAndreas Schwab 	[98]	 = KEY_HELP,
1446615c5b2SGeert Uytterhoeven 	[99]	 = KEY_KPLEFTPAREN,
1456615c5b2SGeert Uytterhoeven 	[100]	 = KEY_KPRIGHTPAREN,
1466615c5b2SGeert Uytterhoeven 	[101]	 = KEY_KPSLASH,
1476615c5b2SGeert Uytterhoeven 	[102]	 = KEY_KPASTERISK,
1489e62df51SAndreas Schwab 	[103]	 = KEY_KP7,
1499e62df51SAndreas Schwab 	[104]	 = KEY_KP8,
1509e62df51SAndreas Schwab 	[105]	 = KEY_KP9,
1519e62df51SAndreas Schwab 	[106]	 = KEY_KP4,
1529e62df51SAndreas Schwab 	[107]	 = KEY_KP5,
1539e62df51SAndreas Schwab 	[108]	 = KEY_KP6,
1549e62df51SAndreas Schwab 	[109]	 = KEY_KP1,
1559e62df51SAndreas Schwab 	[110]	 = KEY_KP2,
1569e62df51SAndreas Schwab 	[111]	 = KEY_KP3,
1579e62df51SAndreas Schwab 	[112]	 = KEY_KP0,
1589e62df51SAndreas Schwab 	[113]	 = KEY_KPDOT,
1599e62df51SAndreas Schwab 	[114]	 = KEY_KPENTER,
1606615c5b2SGeert Uytterhoeven };
161c04cb856SMichael Schmitz 
162c04cb856SMichael Schmitz static struct input_dev *atakbd_dev;
163c04cb856SMichael Schmitz 
atakbd_interrupt(unsigned char scancode,char down)164c04cb856SMichael Schmitz static void atakbd_interrupt(unsigned char scancode, char down)
165c04cb856SMichael Schmitz {
166c04cb856SMichael Schmitz 
1679e62df51SAndreas Schwab 	if (scancode < 0x73) {		/* scancodes < 0xf3 are keys */
168c04cb856SMichael Schmitz 
169c04cb856SMichael Schmitz 		// report raw events here?
170c04cb856SMichael Schmitz 
171c04cb856SMichael Schmitz 		scancode = atakbd_keycode[scancode];
172c04cb856SMichael Schmitz 
173c04cb856SMichael Schmitz 		input_report_key(atakbd_dev, scancode, down);
174c04cb856SMichael Schmitz 		input_sync(atakbd_dev);
1759e62df51SAndreas Schwab 	} else				/* scancodes >= 0xf3 are mouse data, most likely */
176c04cb856SMichael Schmitz 		printk(KERN_INFO "atakbd: unhandled scancode %x\n", scancode);
177c04cb856SMichael Schmitz 
178c04cb856SMichael Schmitz 	return;
179c04cb856SMichael Schmitz }
180c04cb856SMichael Schmitz 
atakbd_init(void)181c04cb856SMichael Schmitz static int __init atakbd_init(void)
182c04cb856SMichael Schmitz {
18363bd8c48SGeert Uytterhoeven 	int i, error;
184c04cb856SMichael Schmitz 
1856615c5b2SGeert Uytterhoeven 	if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ST_MFP))
186e945b568SGeert Uytterhoeven 		return -ENODEV;
187c04cb856SMichael Schmitz 
188c04cb856SMichael Schmitz 	// need to init core driver if not already done so
189186f200aSMichael Schmitz 	error = atari_keyb_init();
190186f200aSMichael Schmitz 	if (error)
191186f200aSMichael Schmitz 		return error;
192c04cb856SMichael Schmitz 
1936615c5b2SGeert Uytterhoeven 	atakbd_dev = input_allocate_device();
1946615c5b2SGeert Uytterhoeven 	if (!atakbd_dev)
1956615c5b2SGeert Uytterhoeven 		return -ENOMEM;
1966615c5b2SGeert Uytterhoeven 
197c04cb856SMichael Schmitz 	atakbd_dev->name = "Atari Keyboard";
198c04cb856SMichael Schmitz 	atakbd_dev->phys = "atakbd/input0";
1996615c5b2SGeert Uytterhoeven 	atakbd_dev->id.bustype = BUS_HOST;
200c04cb856SMichael Schmitz 	atakbd_dev->id.vendor = 0x0001;
201c04cb856SMichael Schmitz 	atakbd_dev->id.product = 0x0001;
202c04cb856SMichael Schmitz 	atakbd_dev->id.version = 0x0100;
203c04cb856SMichael Schmitz 
2047b19ada2SJiri Slaby 	atakbd_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
205c04cb856SMichael Schmitz 	atakbd_dev->keycode = atakbd_keycode;
206c04cb856SMichael Schmitz 	atakbd_dev->keycodesize = sizeof(unsigned char);
207c04cb856SMichael Schmitz 	atakbd_dev->keycodemax = ARRAY_SIZE(atakbd_keycode);
208c04cb856SMichael Schmitz 
209c04cb856SMichael Schmitz 	for (i = 1; i < 0x72; i++) {
210c04cb856SMichael Schmitz 		set_bit(atakbd_keycode[i], atakbd_dev->keybit);
211c04cb856SMichael Schmitz 	}
212c04cb856SMichael Schmitz 
2136615c5b2SGeert Uytterhoeven 	/* error check */
21463bd8c48SGeert Uytterhoeven 	error = input_register_device(atakbd_dev);
21563bd8c48SGeert Uytterhoeven 	if (error) {
2166615c5b2SGeert Uytterhoeven 		input_free_device(atakbd_dev);
21763bd8c48SGeert Uytterhoeven 		return error;
2186615c5b2SGeert Uytterhoeven 	}
219c04cb856SMichael Schmitz 
220c04cb856SMichael Schmitz 	atari_input_keyboard_interrupt_hook = atakbd_interrupt;
221c04cb856SMichael Schmitz 
222c04cb856SMichael Schmitz 	return 0;
223c04cb856SMichael Schmitz }
224c04cb856SMichael Schmitz 
atakbd_exit(void)225c04cb856SMichael Schmitz static void __exit atakbd_exit(void)
226c04cb856SMichael Schmitz {
227c04cb856SMichael Schmitz 	atari_input_keyboard_interrupt_hook = NULL;
228c04cb856SMichael Schmitz 	input_unregister_device(atakbd_dev);
229c04cb856SMichael Schmitz }
230c04cb856SMichael Schmitz 
231c04cb856SMichael Schmitz module_init(atakbd_init);
232c04cb856SMichael Schmitz module_exit(atakbd_exit);
233