blob: 6caee807cafabf6955053ee817c30f70571d3ef5 [file] [log] [blame]
Michael Schmitzc04cb852007-05-01 22:32:38 +02001/*
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
Michael Schmitzc04cb852007-05-01 22:32:38 +020037 */
38
39#include <linux/module.h>
40#include <linux/init.h>
41#include <linux/input.h>
42#include <linux/delay.h>
43#include <linux/interrupt.h>
44
45#include <asm/atariints.h>
46#include <asm/atarihw.h>
47#include <asm/atarikb.h>
48#include <asm/irq.h>
49
50MODULE_AUTHOR("Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>");
51MODULE_DESCRIPTION("Atari keyboard driver");
52MODULE_LICENSE("GPL");
53
Geert Uytterhoeven6615c5b2007-10-13 14:31:24 +020054/*
55 0x47: KP_7 71
56 0x48: KP_8 72
57 0x49: KP_9 73
58 0x62: KP_/ 98
59 0x4b: KP_4 75
60 0x4c: KP_5 76
61 0x4d: KP_6 77
62 0x37: KP_* 55
63 0x4f: KP_1 79
64 0x50: KP_2 80
65 0x51: KP_3 81
66 0x4a: KP_- 74
67 0x52: KP_0 82
68 0x53: KP_. 83
69 0x4e: KP_+ 78
70
71 0x67: Up 103
72 0x6c: Down 108
73 0x69: Left 105
74 0x6a: Right 106
75 */
76
77
Andreas Schwab9e62df52018-09-17 12:43:34 -070078static unsigned char atakbd_keycode[0x73] = { /* American layout */
Geert Uytterhoeven6615c5b2007-10-13 14:31:24 +020079 [1] = KEY_ESC,
80 [2] = KEY_1,
81 [3] = KEY_2,
82 [4] = KEY_3,
83 [5] = KEY_4,
84 [6] = KEY_5,
85 [7] = KEY_6,
86 [8] = KEY_7,
87 [9] = KEY_8,
88 [10] = KEY_9,
89 [11] = KEY_0,
90 [12] = KEY_MINUS,
91 [13] = KEY_EQUAL,
92 [14] = KEY_BACKSPACE,
93 [15] = KEY_TAB,
94 [16] = KEY_Q,
95 [17] = KEY_W,
96 [18] = KEY_E,
97 [19] = KEY_R,
98 [20] = KEY_T,
99 [21] = KEY_Y,
100 [22] = KEY_U,
101 [23] = KEY_I,
102 [24] = KEY_O,
103 [25] = KEY_P,
104 [26] = KEY_LEFTBRACE,
105 [27] = KEY_RIGHTBRACE,
106 [28] = KEY_ENTER,
107 [29] = KEY_LEFTCTRL,
108 [30] = KEY_A,
109 [31] = KEY_S,
110 [32] = KEY_D,
111 [33] = KEY_F,
112 [34] = KEY_G,
113 [35] = KEY_H,
114 [36] = KEY_J,
115 [37] = KEY_K,
116 [38] = KEY_L,
117 [39] = KEY_SEMICOLON,
118 [40] = KEY_APOSTROPHE,
Andreas Schwab9e62df52018-09-17 12:43:34 -0700119 [41] = KEY_GRAVE,
Geert Uytterhoeven6615c5b2007-10-13 14:31:24 +0200120 [42] = KEY_LEFTSHIFT,
Andreas Schwab9e62df52018-09-17 12:43:34 -0700121 [43] = KEY_BACKSLASH,
Geert Uytterhoeven6615c5b2007-10-13 14:31:24 +0200122 [44] = KEY_Z,
123 [45] = KEY_X,
124 [46] = KEY_C,
125 [47] = KEY_V,
126 [48] = KEY_B,
127 [49] = KEY_N,
128 [50] = KEY_M,
129 [51] = KEY_COMMA,
130 [52] = KEY_DOT,
131 [53] = KEY_SLASH,
132 [54] = KEY_RIGHTSHIFT,
133 [55] = KEY_KPASTERISK,
134 [56] = KEY_LEFTALT,
135 [57] = KEY_SPACE,
136 [58] = KEY_CAPSLOCK,
137 [59] = KEY_F1,
138 [60] = KEY_F2,
139 [61] = KEY_F3,
140 [62] = KEY_F4,
141 [63] = KEY_F5,
142 [64] = KEY_F6,
143 [65] = KEY_F7,
144 [66] = KEY_F8,
145 [67] = KEY_F9,
146 [68] = KEY_F10,
Andreas Schwab9e62df52018-09-17 12:43:34 -0700147 [71] = KEY_HOME,
148 [72] = KEY_UP,
Geert Uytterhoeven6615c5b2007-10-13 14:31:24 +0200149 [74] = KEY_KPMINUS,
Andreas Schwab9e62df52018-09-17 12:43:34 -0700150 [75] = KEY_LEFT,
151 [77] = KEY_RIGHT,
Geert Uytterhoeven6615c5b2007-10-13 14:31:24 +0200152 [78] = KEY_KPPLUS,
Andreas Schwab9e62df52018-09-17 12:43:34 -0700153 [80] = KEY_DOWN,
154 [82] = KEY_INSERT,
155 [83] = KEY_DELETE,
Michael Karcher9923d852015-01-17 14:11:45 -0800156 [96] = KEY_102ND,
Andreas Schwab9e62df52018-09-17 12:43:34 -0700157 [97] = KEY_UNDO,
158 [98] = KEY_HELP,
Geert Uytterhoeven6615c5b2007-10-13 14:31:24 +0200159 [99] = KEY_KPLEFTPAREN,
160 [100] = KEY_KPRIGHTPAREN,
161 [101] = KEY_KPSLASH,
162 [102] = KEY_KPASTERISK,
Andreas Schwab9e62df52018-09-17 12:43:34 -0700163 [103] = KEY_KP7,
164 [104] = KEY_KP8,
165 [105] = KEY_KP9,
166 [106] = KEY_KP4,
167 [107] = KEY_KP5,
168 [108] = KEY_KP6,
169 [109] = KEY_KP1,
170 [110] = KEY_KP2,
171 [111] = KEY_KP3,
172 [112] = KEY_KP0,
173 [113] = KEY_KPDOT,
174 [114] = KEY_KPENTER,
Geert Uytterhoeven6615c5b2007-10-13 14:31:24 +0200175};
Michael Schmitzc04cb852007-05-01 22:32:38 +0200176
177static struct input_dev *atakbd_dev;
178
179static void atakbd_interrupt(unsigned char scancode, char down)
180{
181
Andreas Schwab9e62df52018-09-17 12:43:34 -0700182 if (scancode < 0x73) { /* scancodes < 0xf3 are keys */
Michael Schmitzc04cb852007-05-01 22:32:38 +0200183
184 // report raw events here?
185
186 scancode = atakbd_keycode[scancode];
187
Michael Schmitz52d2c7b2018-09-17 15:27:49 -0700188 input_report_key(atakbd_dev, scancode, down);
189 input_sync(atakbd_dev);
Andreas Schwab9e62df52018-09-17 12:43:34 -0700190 } else /* scancodes >= 0xf3 are mouse data, most likely */
Michael Schmitzc04cb852007-05-01 22:32:38 +0200191 printk(KERN_INFO "atakbd: unhandled scancode %x\n", scancode);
192
193 return;
194}
195
196static int __init atakbd_init(void)
197{
Geert Uytterhoeven63bd8c42007-10-15 21:51:10 +0200198 int i, error;
Michael Schmitzc04cb852007-05-01 22:32:38 +0200199
Geert Uytterhoeven6615c5b2007-10-13 14:31:24 +0200200 if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ST_MFP))
Geert Uytterhoevene945b562008-07-17 21:16:10 +0200201 return -ENODEV;
Michael Schmitzc04cb852007-05-01 22:32:38 +0200202
Michael Schmitzc04cb852007-05-01 22:32:38 +0200203 // need to init core driver if not already done so
Michael Schmitz186f2002008-12-28 23:00:45 +0100204 error = atari_keyb_init();
205 if (error)
206 return error;
Michael Schmitzc04cb852007-05-01 22:32:38 +0200207
Geert Uytterhoeven6615c5b2007-10-13 14:31:24 +0200208 atakbd_dev = input_allocate_device();
209 if (!atakbd_dev)
210 return -ENOMEM;
211
Michael Schmitzc04cb852007-05-01 22:32:38 +0200212 atakbd_dev->name = "Atari Keyboard";
213 atakbd_dev->phys = "atakbd/input0";
Geert Uytterhoeven6615c5b2007-10-13 14:31:24 +0200214 atakbd_dev->id.bustype = BUS_HOST;
Michael Schmitzc04cb852007-05-01 22:32:38 +0200215 atakbd_dev->id.vendor = 0x0001;
216 atakbd_dev->id.product = 0x0001;
217 atakbd_dev->id.version = 0x0100;
218
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700219 atakbd_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
Michael Schmitzc04cb852007-05-01 22:32:38 +0200220 atakbd_dev->keycode = atakbd_keycode;
221 atakbd_dev->keycodesize = sizeof(unsigned char);
222 atakbd_dev->keycodemax = ARRAY_SIZE(atakbd_keycode);
223
224 for (i = 1; i < 0x72; i++) {
Michael Schmitzc04cb852007-05-01 22:32:38 +0200225 set_bit(atakbd_keycode[i], atakbd_dev->keybit);
226 }
227
Geert Uytterhoeven6615c5b2007-10-13 14:31:24 +0200228 /* error check */
Geert Uytterhoeven63bd8c42007-10-15 21:51:10 +0200229 error = input_register_device(atakbd_dev);
230 if (error) {
Geert Uytterhoeven6615c5b2007-10-13 14:31:24 +0200231 input_free_device(atakbd_dev);
Geert Uytterhoeven63bd8c42007-10-15 21:51:10 +0200232 return error;
Geert Uytterhoeven6615c5b2007-10-13 14:31:24 +0200233 }
Michael Schmitzc04cb852007-05-01 22:32:38 +0200234
235 atari_input_keyboard_interrupt_hook = atakbd_interrupt;
236
Michael Schmitzc04cb852007-05-01 22:32:38 +0200237 return 0;
238}
239
240static void __exit atakbd_exit(void)
241{
242 atari_input_keyboard_interrupt_hook = NULL;
243 input_unregister_device(atakbd_dev);
244}
245
246module_init(atakbd_init);
247module_exit(atakbd_exit);