Rev 522 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
495 | giacomo | 1 | /* |
2 | * AT and PS/2 keyboard driver |
||
3 | * |
||
4 | * Copyright (c) 1999-2002 Vojtech Pavlik |
||
5 | */ |
||
6 | |||
7 | /* |
||
8 | * This program is free software; you can redistribute it and/or modify it |
||
9 | * under the terms of the GNU General Public License version 2 as published by |
||
10 | * the Free Software Foundation. |
||
11 | */ |
||
12 | |||
13 | /* |
||
14 | * This driver can handle standard AT keyboards and PS/2 keyboards in |
||
15 | * Translated and Raw Set 2 and Set 3, as well as AT keyboards on dumb |
||
16 | * input-only controllers and AT keyboards connected over a one way RS232 |
||
17 | * converter. |
||
18 | */ |
||
19 | |||
20 | #include <linuxcomp.h> |
||
21 | |||
22 | #include <linux/delay.h> |
||
23 | #include <linux/module.h> |
||
24 | #include <linux/slab.h> |
||
25 | #include <linux/interrupt.h> |
||
26 | #include <linux/init.h> |
||
27 | #include <linux/input.h> |
||
28 | #include <linux/serio.h> |
||
29 | #include <linux/workqueue.h> |
||
30 | #include <linux/timer.h> |
||
31 | |||
32 | //#define ATKBD_DEBUG |
||
33 | |||
34 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); |
||
35 | MODULE_DESCRIPTION("AT and PS/2 keyboard driver"); |
||
36 | MODULE_PARM(atkbd_set, "1i"); |
||
37 | MODULE_PARM(atkbd_reset, "1i"); |
||
38 | MODULE_PARM(atkbd_softrepeat, "1i"); |
||
39 | MODULE_LICENSE("GPL"); |
||
40 | |||
41 | static int atkbd_set = 2; |
||
42 | #if defined(__i386__) || defined (__x86_64__) |
||
43 | static int atkbd_reset; |
||
44 | #else |
||
45 | static int atkbd_reset = 1; |
||
46 | #endif |
||
47 | static int atkbd_softrepeat; |
||
48 | |||
49 | /* |
||
50 | * Scancode to keycode tables. These are just the default setting, and |
||
51 | * are loadable via an userland utility. |
||
52 | */ |
||
53 | |||
54 | static unsigned char atkbd_set2_keycode[512] = { |
||
55 | 0, 67, 65, 63, 61, 59, 60, 88, 0, 68, 66, 64, 62, 15, 41, 85, |
||
56 | 0, 56, 42,182, 29, 16, 2, 89, 0, 0, 44, 31, 30, 17, 3, 90, |
||
57 | 0, 46, 45, 32, 18, 5, 4, 91, 90, 57, 47, 33, 20, 19, 6, 0, |
||
58 | 91, 49, 48, 35, 34, 21, 7, 0, 0, 0, 50, 36, 22, 8, 9, 0, |
||
59 | 0, 51, 37, 23, 24, 11, 10, 0, 0, 52, 53, 38, 39, 25, 12, 0, |
||
60 | 122, 89, 40,120, 26, 13, 0, 0, 58, 54, 28, 27, 0, 43, 0, 0, |
||
61 | 85, 86, 90, 91, 92, 93, 14, 94, 95, 79,183, 75, 71,121, 0,123, |
||
62 | 82, 83, 80, 76, 77, 72, 1, 69, 87, 78, 81, 74, 55, 73, 70, 99, |
||
63 | 0, 0, 0, 65, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||
64 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||
65 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||
66 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||
67 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||
68 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||
69 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||
70 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,255, |
||
71 | 0, 0, 92, 90, 85, 0,137, 0, 0, 0, 0, 91, 89,144,115, 0, |
||
72 | 217,100,255, 0, 97,165,164, 0,156, 0, 0,140,115, 0, 0,125, |
||
73 | 173,114, 0,113,152,163,151,126,128,166, 0,140, 0,147, 0,127, |
||
74 | 159,167,115,160,164, 0, 0,116,158, 0,150,166, 0, 0, 0,142, |
||
75 | 157, 0,114,166,168, 0, 0,213,155, 0, 98,113, 0,163, 0,138, |
||
76 | 226, 0, 0, 0, 0, 0,153,140, 0,255, 96, 0, 0, 0,143, 0, |
||
77 | 133, 0,116, 0,143, 0,174,133, 0,107, 0,105,102, 0, 0,112, |
||
78 | 110,111,108,112,106,103, 0,119, 0,118,109, 0, 99,104,119 |
||
79 | }; |
||
80 | |||
81 | static unsigned char atkbd_set3_keycode[512] = { |
||
82 | 0, 0, 0, 0, 0, 0, 0, 59, 1,138,128,129,130, 15, 41, 60, |
||
83 | 131, 29, 42, 86, 58, 16, 2, 61,133, 56, 44, 31, 30, 17, 3, 62, |
||
84 | 134, 46, 45, 32, 18, 5, 4, 63,135, 57, 47, 33, 20, 19, 6, 64, |
||
85 | 136, 49, 48, 35, 34, 21, 7, 65,137,100, 50, 36, 22, 8, 9, 66, |
||
86 | 125, 51, 37, 23, 24, 11, 10, 67,126, 52, 53, 38, 39, 25, 12, 68, |
||
87 | 113,114, 40, 84, 26, 13, 87, 99, 97, 54, 28, 27, 43, 84, 88, 70, |
||
88 | 108,105,119,103,111,107, 14,110, 0, 79,106, 75, 71,109,102,104, |
||
89 | 82, 83, 80, 76, 77, 72, 69, 98, 0, 96, 81, 0, 78, 73, 55, 85, |
||
90 | 89, 90, 91, 92, 74,185,184,182, 0, 0, 0,125,126,127,112, 0, |
||
91 | 0,139,150,163,165,115,152,150,166,140,160,154,113,114,167,168, |
||
92 | 148,149,147,140, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||
93 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||
94 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||
95 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||
96 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||
97 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,255 |
||
98 | }; |
||
99 | |||
100 | static unsigned char atkbd_unxlate_table[128] = { |
||
101 | 0,118, 22, 30, 38, 37, 46, 54, 61, 62, 70, 69, 78, 85,102, 13, |
||
102 | 21, 29, 36, 45, 44, 53, 60, 67, 68, 77, 84, 91, 90, 20, 28, 27, |
||
103 | 35, 43, 52, 51, 59, 66, 75, 76, 82, 14, 18, 93, 26, 34, 33, 42, |
||
104 | 50, 49, 58, 65, 73, 74, 89,124, 17, 41, 88, 5, 6, 4, 12, 3, |
||
105 | 11, 2, 10, 1, 9,119,126,108,117,125,123,107,115,116,121,105, |
||
106 | 114,122,112,113,127, 96, 97,120, 7, 15, 23, 31, 39, 47, 55, 63, |
||
107 | 71, 79, 86, 94, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 87,111, |
||
108 | 19, 25, 57, 81, 83, 92, 95, 98, 99,100,101,103,104,106,109,110 |
||
109 | }; |
||
110 | |||
111 | #define ATKBD_CMD_SETLEDS 0x10ed |
||
112 | #define ATKBD_CMD_GSCANSET 0x11f0 |
||
113 | #define ATKBD_CMD_SSCANSET 0x10f0 |
||
114 | #define ATKBD_CMD_GETID 0x02f2 |
||
115 | #define ATKBD_CMD_SETREP 0x10f3 |
||
116 | #define ATKBD_CMD_ENABLE 0x00f4 |
||
117 | #define ATKBD_CMD_RESET_DIS 0x00f5 |
||
118 | #define ATKBD_CMD_SETALL_MBR 0x00fa |
||
119 | #define ATKBD_CMD_RESET_BAT 0x02ff |
||
120 | #define ATKBD_CMD_RESEND 0x00fe |
||
121 | #define ATKBD_CMD_EX_ENABLE 0x10ea |
||
122 | #define ATKBD_CMD_EX_SETLEDS 0x20eb |
||
123 | #define ATKBD_CMD_OK_GETID 0x02e8 |
||
124 | |||
125 | #define ATKBD_RET_ACK 0xfa |
||
126 | #define ATKBD_RET_NAK 0xfe |
||
127 | #define ATKBD_RET_BAT 0xaa |
||
128 | #define ATKBD_RET_EMUL0 0xe0 |
||
129 | #define ATKBD_RET_EMULX 0x80 |
||
130 | #define ATKBD_RET_EMUL1 0xe1 |
||
131 | #define ATKBD_RET_RELEASE 0xf0 |
||
132 | |||
133 | #define ATKBD_KEY_UNKNOWN 0 |
||
134 | #define ATKBD_KEY_NULL 255 |
||
135 | |||
136 | /* |
||
137 | * The atkbd control structure |
||
138 | */ |
||
139 | |||
140 | struct atkbd { |
||
141 | unsigned char keycode[512]; |
||
142 | struct input_dev dev; |
||
143 | struct serio *serio; |
||
144 | struct timer_list timer; |
||
145 | char name[64]; |
||
146 | char phys[32]; |
||
147 | unsigned char cmdbuf[4]; |
||
148 | unsigned char cmdcnt; |
||
149 | unsigned char set; |
||
150 | unsigned char release; |
||
151 | int lastkey; |
||
152 | volatile signed char ack; |
||
153 | unsigned char emul; |
||
154 | unsigned short id; |
||
155 | unsigned char write; |
||
156 | unsigned char translated; |
||
157 | unsigned char resend; |
||
158 | unsigned char bat_xl; |
||
159 | unsigned int last; |
||
160 | unsigned long time; |
||
161 | }; |
||
162 | |||
163 | /* |
||
164 | * atkbd_interrupt(). Here takes place processing of data received from |
||
165 | * the keyboard into events. |
||
166 | */ |
||
167 | |||
168 | static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data, |
||
169 | unsigned int flags, struct pt_regs *regs) |
||
170 | { |
||
171 | struct atkbd *atkbd = serio->private; |
||
172 | unsigned int code = data; |
||
173 | int value; |
||
174 | |||
175 | #ifdef ATKBD_DEBUG |
||
176 | printk(KERN_DEBUG "atkbd.c: Received %02x flags %02x\n", data, flags); |
||
177 | #endif |
||
178 | |||
179 | #if !defined(__i386__) && !defined (__x86_64__) |
||
180 | if ((flags & (SERIO_FRAME | SERIO_PARITY)) && (~flags & SERIO_TIMEOUT) && !atkbd->resend && atkbd->write) { |
||
181 | printk("atkbd.c: frame/parity error: %02x\n", flags); |
||
182 | serio_write(serio, ATKBD_CMD_RESEND); |
||
183 | atkbd->resend = 1; |
||
184 | goto out; |
||
185 | } |
||
186 | |||
187 | if (!flags && data == ATKBD_RET_ACK) |
||
188 | atkbd->resend = 0; |
||
189 | #endif |
||
190 | |||
191 | switch (code) { |
||
192 | case ATKBD_RET_ACK: |
||
193 | atkbd->ack = 1; |
||
194 | goto out; |
||
195 | case ATKBD_RET_NAK: |
||
196 | atkbd->ack = -1; |
||
197 | goto out; |
||
198 | } |
||
199 | |||
200 | if (atkbd->translated) do { |
||
201 | |||
202 | if (atkbd->emul != 1) { |
||
203 | if (code == ATKBD_RET_EMUL0 || code == ATKBD_RET_EMUL1) |
||
204 | break; |
||
205 | if (code == ATKBD_RET_BAT) { |
||
206 | if (!atkbd->bat_xl) |
||
207 | break; |
||
208 | atkbd->bat_xl = 0; |
||
209 | } |
||
210 | if (code == (ATKBD_RET_BAT & 0x7f)) |
||
211 | atkbd->bat_xl = 1; |
||
212 | } |
||
213 | |||
214 | if (code < 0x80) { |
||
215 | code = atkbd_unxlate_table[code]; |
||
216 | break; |
||
217 | } |
||
218 | |||
219 | if (atkbd->cmdcnt) |
||
220 | break; |
||
221 | |||
222 | code = atkbd_unxlate_table[code & 0x7f]; |
||
223 | atkbd->release = 1; |
||
224 | |||
225 | } while (0); |
||
226 | |||
227 | if (atkbd->cmdcnt) { |
||
228 | atkbd->cmdbuf[--atkbd->cmdcnt] = code; |
||
229 | goto out; |
||
230 | } |
||
231 | |||
232 | switch (code) { |
||
233 | case ATKBD_RET_BAT: |
||
234 | serio_rescan(atkbd->serio); |
||
235 | goto out; |
||
236 | case ATKBD_RET_EMUL0: |
||
237 | atkbd->emul = 1; |
||
238 | goto out; |
||
239 | case ATKBD_RET_EMUL1: |
||
240 | atkbd->emul = 2; |
||
241 | goto out; |
||
242 | case ATKBD_RET_RELEASE: |
||
243 | atkbd->release = 1; |
||
244 | goto out; |
||
245 | } |
||
246 | |||
247 | if (atkbd->emul) { |
||
248 | if (--atkbd->emul) |
||
249 | goto out; |
||
250 | code |= 0x100; |
||
251 | } |
||
252 | |||
253 | switch (atkbd->keycode[code]) { |
||
254 | case ATKBD_KEY_NULL: |
||
255 | break; |
||
256 | case ATKBD_KEY_UNKNOWN: |
||
257 | printk(KERN_WARNING "atkbd.c: Unknown key %s (%s set %d, code %#x, data %#x, on %s).\n", |
||
258 | atkbd->release ? "released" : "pressed", |
||
259 | atkbd->translated ? "translated" : "raw", |
||
260 | atkbd->set, code, data, serio->phys); |
||
261 | break; |
||
262 | default: |
||
263 | value = atkbd->release ? 0 : |
||
264 | (1 + (!atkbd_softrepeat && test_bit(atkbd->keycode[code], atkbd->dev.key))); |
||
265 | |||
266 | switch (value) { /* Workaround Toshiba laptop multiple keypress */ |
||
267 | case 0: |
||
268 | atkbd->last = 0; |
||
269 | break; |
||
270 | case 1: |
||
271 | atkbd->last = code; |
||
272 | atkbd->time = jiffies26 + (atkbd->dev.rep[REP_DELAY] * HZ + 500) / 1000 / 2; |
||
273 | break; |
||
274 | case 2: |
||
275 | if (!time_after(jiffies26, atkbd->time) && atkbd->last == code) |
||
276 | value = 1; |
||
277 | break; |
||
278 | } |
||
279 | |||
280 | input_regs(&atkbd->dev, regs); |
||
281 | input_event(&atkbd->dev, EV_KEY, atkbd->keycode[code], value); |
||
282 | input_sync(&atkbd->dev); |
||
283 | } |
||
284 | |||
285 | atkbd->release = 0; |
||
286 | out: |
||
287 | return IRQ_HANDLED; |
||
288 | } |
||
289 | |||
290 | /* |
||
291 | * atkbd_sendbyte() sends a byte to the keyboard, and waits for |
||
292 | * acknowledge. It doesn't handle resends according to the keyboard |
||
293 | * protocol specs, because if these are needed, the keyboard needs |
||
294 | * replacement anyway, and they only make a mess in the protocol. |
||
295 | */ |
||
296 | |||
297 | static int atkbd_sendbyte(struct atkbd *atkbd, unsigned char byte) |
||
298 | { |
||
299 | int timeout = 20000; /* 200 msec */ |
||
300 | atkbd->ack = 0; |
||
301 | |||
302 | #ifdef ATKBD_DEBUG |
||
303 | printk(KERN_DEBUG "atkbd.c: Sent: %02x\n", byte); |
||
304 | #endif |
||
305 | if (serio_write(atkbd->serio, byte)) |
||
306 | return -1; |
||
307 | |||
308 | while (!atkbd->ack && timeout--) udelay(10); |
||
309 | |||
310 | return -(atkbd->ack <= 0); |
||
311 | } |
||
312 | |||
313 | /* |
||
314 | * atkbd_command() sends a command, and its parameters to the keyboard, |
||
315 | * then waits for the response and puts it in the param array. |
||
316 | */ |
||
317 | |||
318 | static int atkbd_command(struct atkbd *atkbd, unsigned char *param, int command) |
||
319 | { |
||
320 | int timeout = 500000; /* 500 msec */ |
||
321 | int send = (command >> 12) & 0xf; |
||
322 | int receive = (command >> 8) & 0xf; |
||
323 | int i; |
||
324 | |||
325 | atkbd->cmdcnt = receive; |
||
326 | |||
327 | if (command == ATKBD_CMD_RESET_BAT) |
||
328 | timeout = 2000000; /* 2 sec */ |
||
329 | |||
330 | if (command & 0xff) |
||
331 | if (atkbd_sendbyte(atkbd, command & 0xff)) |
||
332 | return (atkbd->cmdcnt = 0) - 1; |
||
333 | |||
334 | for (i = 0; i < send; i++) |
||
335 | if (atkbd_sendbyte(atkbd, param[i])) |
||
336 | return (atkbd->cmdcnt = 0) - 1; |
||
337 | |||
338 | while (atkbd->cmdcnt && timeout--) { |
||
339 | |||
340 | if (atkbd->cmdcnt == 1 && |
||
341 | command == ATKBD_CMD_RESET_BAT && timeout > 100000) |
||
342 | timeout = 100000; |
||
343 | |||
344 | if (atkbd->cmdcnt == 1 && command == ATKBD_CMD_GETID && |
||
345 | atkbd->cmdbuf[1] != 0xab && atkbd->cmdbuf[1] != 0xac) { |
||
346 | atkbd->cmdcnt = 0; |
||
347 | break; |
||
348 | } |
||
349 | |||
350 | udelay(1); |
||
351 | } |
||
352 | |||
353 | if (param) |
||
354 | for (i = 0; i < receive; i++) |
||
355 | param[i] = atkbd->cmdbuf[(receive - 1) - i]; |
||
356 | |||
357 | if (command == ATKBD_CMD_RESET_BAT && atkbd->cmdcnt == 1) |
||
358 | atkbd->cmdcnt = 0; |
||
359 | |||
360 | if (atkbd->cmdcnt) { |
||
361 | atkbd->cmdcnt = 0; |
||
362 | return -1; |
||
363 | } |
||
364 | |||
365 | return 0; |
||
366 | } |
||
367 | |||
368 | /* |
||
369 | * Event callback from the input module. Events that change the state of |
||
370 | * the hardware are processed here. |
||
371 | */ |
||
372 | |||
373 | static int atkbd_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) |
||
374 | { |
||
375 | struct atkbd *atkbd = dev->private; |
||
376 | struct { int p; u8 v; } period[] = |
||
377 | { {30, 0x00}, {25, 0x02}, {20, 0x04}, {15, 0x08}, {10, 0x0c}, {7, 0x10}, {5, 0x14}, {0, 0x14} }; |
||
378 | struct { int d; u8 v; } delay[] = |
||
379 | { {1000, 0x60}, {750, 0x40}, {500, 0x20}, {250, 0x00}, {0, 0x00} }; |
||
380 | char param[2]; |
||
381 | int i, j; |
||
382 | |||
383 | if (!atkbd->write) |
||
384 | return -1; |
||
385 | |||
386 | switch (type) { |
||
387 | |||
388 | case EV_LED: |
||
389 | |||
390 | *param = (test_bit(LED_SCROLLL, dev->led) ? 1 : 0) |
||
391 | | (test_bit(LED_NUML, dev->led) ? 2 : 0) |
||
392 | | (test_bit(LED_CAPSL, dev->led) ? 4 : 0); |
||
393 | atkbd_command(atkbd, param, ATKBD_CMD_SETLEDS); |
||
394 | |||
395 | if (atkbd->set == 4) { |
||
396 | param[0] = 0; |
||
397 | param[1] = (test_bit(LED_COMPOSE, dev->led) ? 0x01 : 0) |
||
398 | | (test_bit(LED_SLEEP, dev->led) ? 0x02 : 0) |
||
399 | | (test_bit(LED_SUSPEND, dev->led) ? 0x04 : 0) |
||
400 | | (test_bit(LED_MISC, dev->led) ? 0x10 : 0) |
||
401 | | (test_bit(LED_MUTE, dev->led) ? 0x20 : 0); |
||
402 | atkbd_command(atkbd, param, ATKBD_CMD_EX_SETLEDS); |
||
403 | } |
||
404 | |||
405 | return 0; |
||
406 | |||
407 | |||
408 | case EV_REP: |
||
409 | |||
410 | if (atkbd_softrepeat) return 0; |
||
411 | |||
412 | i = j = 0; |
||
413 | while (period[i].p > dev->rep[REP_PERIOD]) i++; |
||
414 | while (delay[j].d > dev->rep[REP_DELAY]) j++; |
||
415 | dev->rep[REP_PERIOD] = period[i].p; |
||
416 | dev->rep[REP_DELAY] = delay[j].d; |
||
417 | param[0] = period[i].v | delay[j].v; |
||
418 | atkbd_command(atkbd, param, ATKBD_CMD_SETREP); |
||
419 | |||
420 | return 0; |
||
518 | mauro | 421 | |
422 | case EV_PWR: |
||
423 | if (code) { |
||
424 | /* Enable the keyboard to receive keystrokes. */ |
||
425 | if (atkbd_command(atkbd, NULL, ATKBD_CMD_ENABLE)) { |
||
426 | printk(KERN_ERR "atkbd.c: Failed to enable keyboard on %s\n", atkbd->serio->phys); |
||
427 | return -1; |
||
428 | } |
||
429 | } else { |
||
430 | /* Disable the keyboard to receive keystrokes. */ |
||
431 | if (atkbd_command(atkbd, NULL, ATKBD_CMD_RESET_DIS)) { |
||
432 | printk(KERN_ERR "atkbd.c: Failed to disable keyboard on %s\n", atkbd->serio->phys); |
||
433 | return -1; |
||
434 | } |
||
435 | } |
||
436 | return 0; |
||
495 | giacomo | 437 | } |
438 | |||
439 | return -1; |
||
440 | } |
||
441 | |||
442 | /* |
||
443 | * atkbd_probe() probes for an AT keyboard on a serio port. |
||
444 | */ |
||
445 | |||
446 | static int atkbd_probe(struct atkbd *atkbd) |
||
447 | { |
||
448 | unsigned char param[2]; |
||
449 | |||
450 | /* |
||
451 | * Some systems, where the bit-twiddling when testing the io-lines of the |
||
452 | * controller may confuse the keyboard need a full reset of the keyboard. On |
||
453 | * these systems the BIOS also usually doesn't do it for us. |
||
454 | */ |
||
455 | |||
456 | if (atkbd_reset) |
||
457 | if (atkbd_command(atkbd, NULL, ATKBD_CMD_RESET_BAT)) |
||
458 | printk(KERN_WARNING "atkbd.c: keyboard reset failed on %s\n", atkbd->serio->phys); |
||
459 | |||
460 | /* |
||
461 | * Then we check the keyboard ID. We should get 0xab83 under normal conditions. |
||
462 | * Some keyboards report different values, but the first byte is always 0xab or |
||
463 | * 0xac. Some old AT keyboards don't report anything. If a mouse is connected, this |
||
464 | * should make sure we don't try to set the LEDs on it. |
||
465 | */ |
||
466 | |||
467 | if (atkbd_command(atkbd, param, ATKBD_CMD_GETID)) { |
||
468 | |||
469 | /* |
||
470 | * If the get ID command failed, we check if we can at least set the LEDs on |
||
471 | * the keyboard. This should work on every keyboard out there. It also turns |
||
472 | * the LEDs off, which we want anyway. |
||
473 | */ |
||
474 | param[0] = 0; |
||
475 | if (atkbd_command(atkbd, param, ATKBD_CMD_SETLEDS)) |
||
476 | return -1; |
||
477 | atkbd->id = 0xabba; |
||
478 | return 0; |
||
479 | } |
||
480 | |||
481 | if (param[0] != 0xab && param[0] != 0xac) |
||
482 | return -1; |
||
483 | atkbd->id = (param[0] << 8) | param[1]; |
||
484 | |||
485 | |||
486 | return 0; |
||
487 | } |
||
488 | |||
489 | /* |
||
490 | * atkbd_set_3 checks if a keyboard has a working Set 3 support, and |
||
491 | * sets it into that. Unfortunately there are keyboards that can be switched |
||
492 | * to Set 3, but don't work well in that (BTC Multimedia ...) |
||
493 | */ |
||
494 | |||
495 | static int atkbd_set_3(struct atkbd *atkbd) |
||
496 | { |
||
497 | unsigned char param[2]; |
||
498 | |||
499 | /* |
||
500 | * For known special keyboards we can go ahead and set the correct set. |
||
501 | * We check for NCD PS/2 Sun, NorthGate OmniKey 101 and |
||
502 | * IBM RapidAccess / IBM EzButton / Chicony KBP-8993 keyboards. |
||
503 | */ |
||
504 | |||
505 | if (atkbd->translated) |
||
506 | return 2; |
||
507 | |||
508 | if (atkbd->id == 0xaca1) { |
||
509 | param[0] = 3; |
||
510 | atkbd_command(atkbd, param, ATKBD_CMD_SSCANSET); |
||
511 | return 3; |
||
512 | } |
||
513 | |||
514 | if (atkbd_set != 2) |
||
515 | if (!atkbd_command(atkbd, param, ATKBD_CMD_OK_GETID)) { |
||
516 | atkbd->id = param[0] << 8 | param[1]; |
||
517 | return 2; |
||
518 | } |
||
519 | |||
520 | if (atkbd_set == 4) { |
||
521 | param[0] = 0x71; |
||
522 | if (!atkbd_command(atkbd, param, ATKBD_CMD_EX_ENABLE)) |
||
523 | return 4; |
||
524 | } |
||
525 | |||
526 | if (atkbd_set != 3) |
||
527 | return 2; |
||
528 | |||
529 | param[0] = 3; |
||
530 | if (atkbd_command(atkbd, param, ATKBD_CMD_SSCANSET)) |
||
531 | return 2; |
||
532 | |||
533 | param[0] = 0; |
||
534 | if (atkbd_command(atkbd, param, ATKBD_CMD_GSCANSET)) |
||
535 | return 2; |
||
536 | |||
537 | if (param[0] != 3) { |
||
538 | param[0] = 2; |
||
539 | if (atkbd_command(atkbd, param, ATKBD_CMD_SSCANSET)) |
||
540 | return 2; |
||
541 | } |
||
542 | |||
543 | atkbd_command(atkbd, param, ATKBD_CMD_SETALL_MBR); |
||
544 | |||
545 | return 3; |
||
546 | } |
||
547 | |||
548 | static int atkbd_enable(struct atkbd *atkbd) |
||
549 | { |
||
550 | unsigned char param[1]; |
||
551 | |||
552 | /* |
||
553 | * Set the LEDs to a defined state. |
||
554 | */ |
||
555 | |||
556 | param[0] = 0; |
||
557 | if (atkbd_command(atkbd, param, ATKBD_CMD_SETLEDS)) |
||
558 | return -1; |
||
559 | |||
560 | /* |
||
561 | * Set autorepeat to fastest possible. |
||
562 | */ |
||
563 | |||
564 | param[0] = 0; |
||
565 | if (atkbd_command(atkbd, param, ATKBD_CMD_SETREP)) |
||
566 | return -1; |
||
567 | |||
568 | /* |
||
569 | * Enable the keyboard to receive keystrokes. |
||
570 | */ |
||
571 | |||
518 | mauro | 572 | /*if (atkbd_command(atkbd, NULL, ATKBD_CMD_ENABLE)) { |
495 | giacomo | 573 | printk(KERN_ERR "atkbd.c: Failed to enable keyboard on %s\n", |
574 | atkbd->serio->phys); |
||
575 | return -1; |
||
518 | mauro | 576 | }*/ |
495 | giacomo | 577 | |
578 | return 0; |
||
579 | } |
||
580 | |||
581 | /* |
||
582 | * atkbd_cleanup() restores the keyboard state so that BIOS is happy after a |
||
583 | * reboot. |
||
584 | */ |
||
585 | |||
586 | static void atkbd_cleanup(struct serio *serio) |
||
587 | { |
||
588 | struct atkbd *atkbd = serio->private; |
||
589 | atkbd_command(atkbd, NULL, ATKBD_CMD_RESET_BAT); |
||
590 | } |
||
591 | |||
592 | /* |
||
593 | * atkbd_disconnect() closes and frees. |
||
594 | */ |
||
595 | |||
596 | static void atkbd_disconnect(struct serio *serio) |
||
597 | { |
||
598 | struct atkbd *atkbd = serio->private; |
||
599 | input_unregister_device(&atkbd->dev); |
||
600 | serio_close(serio); |
||
601 | kfree(atkbd); |
||
602 | } |
||
603 | |||
604 | /* |
||
605 | * atkbd_connect() is called when the serio module finds and interface |
||
606 | * that isn't handled yet by an appropriate device driver. We check if |
||
607 | * there is an AT keyboard out there and if yes, we register ourselves |
||
608 | * to the input module. |
||
609 | */ |
||
610 | |||
611 | static void atkbd_connect(struct serio *serio, struct serio_dev *dev) |
||
612 | { |
||
613 | struct atkbd *atkbd; |
||
614 | int i; |
||
615 | |||
616 | if (!(atkbd = kmalloc(sizeof(struct atkbd), GFP_KERNEL))) |
||
617 | return; |
||
618 | memset(atkbd, 0, sizeof(struct atkbd)); |
||
619 | |||
620 | switch (serio->type & SERIO_TYPE) { |
||
621 | |||
622 | case SERIO_8042_XL: |
||
623 | atkbd->translated = 1; |
||
624 | case SERIO_8042: |
||
625 | if (serio->write) |
||
626 | atkbd->write = 1; |
||
627 | break; |
||
628 | case SERIO_RS232: |
||
629 | if ((serio->type & SERIO_PROTO) == SERIO_PS2SER) |
||
630 | break; |
||
631 | default: |
||
632 | kfree(atkbd); |
||
633 | return; |
||
634 | } |
||
635 | |||
636 | if (atkbd->write) { |
||
518 | mauro | 637 | atkbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP) | BIT(EV_PWR); |
495 | giacomo | 638 | atkbd->dev.ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL); |
639 | } else atkbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); |
||
640 | |||
641 | if (!atkbd_softrepeat) { |
||
642 | atkbd->dev.rep[REP_DELAY] = 250; |
||
643 | atkbd->dev.rep[REP_PERIOD] = 33; |
||
644 | } |
||
645 | |||
646 | atkbd->serio = serio; |
||
647 | |||
648 | init_input_dev(&atkbd->dev); |
||
649 | |||
650 | atkbd->dev.keycode = atkbd->keycode; |
||
651 | atkbd->dev.keycodesize = sizeof(unsigned char); |
||
652 | atkbd->dev.keycodemax = ARRAY_SIZE(atkbd_set2_keycode); |
||
653 | atkbd->dev.event = atkbd_event; |
||
654 | atkbd->dev.private = atkbd; |
||
655 | |||
656 | serio->private = atkbd; |
||
657 | |||
658 | if (serio_open(serio, dev)) { |
||
659 | kfree(atkbd); |
||
660 | return; |
||
661 | } |
||
662 | |||
663 | if (atkbd->write) { |
||
664 | |||
665 | if (atkbd_probe(atkbd)) { |
||
666 | serio_close(serio); |
||
667 | kfree(atkbd); |
||
668 | return; |
||
669 | } |
||
670 | |||
671 | atkbd->set = atkbd_set_3(atkbd); |
||
672 | atkbd_enable(atkbd); |
||
673 | |||
674 | } else { |
||
675 | atkbd->set = 2; |
||
676 | atkbd->id = 0xab00; |
||
677 | } |
||
678 | |||
679 | if (atkbd->set == 4) { |
||
680 | atkbd->dev.ledbit[0] |= BIT(LED_COMPOSE) | BIT(LED_SUSPEND) | BIT(LED_SLEEP) | BIT(LED_MUTE) | BIT(LED_MISC); |
||
681 | sprintf26(atkbd->name, "AT Set 2 Extended keyboard"); |
||
682 | } else |
||
683 | sprintf26(atkbd->name, "AT %s Set %d keyboard", |
||
684 | atkbd->translated ? "Translated" : "Raw", atkbd->set); |
||
685 | |||
686 | sprintf26(atkbd->phys, "%s/input0", serio->phys); |
||
687 | |||
688 | if (atkbd->set == 3) |
||
689 | memcpy(atkbd->keycode, atkbd_set3_keycode, sizeof(atkbd->keycode)); |
||
690 | else |
||
691 | memcpy(atkbd->keycode, atkbd_set2_keycode, sizeof(atkbd->keycode)); |
||
692 | |||
693 | atkbd->dev.name = atkbd->name; |
||
694 | atkbd->dev.phys = atkbd->phys; |
||
695 | atkbd->dev.id.bustype = BUS_I8042; |
||
696 | atkbd->dev.id.vendor = 0x0001; |
||
697 | atkbd->dev.id.product = atkbd->set; |
||
698 | atkbd->dev.id.version = atkbd->id; |
||
699 | |||
700 | for (i = 0; i < 512; i++) |
||
701 | if (atkbd->keycode[i] && atkbd->keycode[i] < 255) |
||
702 | set_bit(atkbd->keycode[i], atkbd->dev.keybit); |
||
703 | |||
704 | input_register_device(&atkbd->dev); |
||
705 | |||
523 | mauro | 706 | printk(KERN_INFO "input: %s on %s\n", atkbd->name, serio->phys); |
495 | giacomo | 707 | } |
708 | |||
709 | |||
710 | static struct serio_dev atkbd_dev = { |
||
711 | .interrupt = atkbd_interrupt, |
||
712 | .connect = atkbd_connect, |
||
713 | .disconnect = atkbd_disconnect, |
||
714 | .cleanup = atkbd_cleanup, |
||
715 | }; |
||
716 | |||
717 | #ifndef MODULE |
||
718 | static int __init atkbd_setup_set(char *str) |
||
719 | { |
||
720 | int ints[4]; |
||
721 | str = get_options(str, ARRAY_SIZE(ints), ints); |
||
722 | if (ints[0] > 0) atkbd_set = ints[1]; |
||
723 | return 1; |
||
724 | } |
||
725 | static int __init atkbd_setup_reset(char *str) |
||
726 | { |
||
727 | int ints[4]; |
||
728 | str = get_options(str, ARRAY_SIZE(ints), ints); |
||
729 | if (ints[0] > 0) atkbd_reset = ints[1]; |
||
730 | return 1; |
||
731 | } |
||
732 | |||
733 | __setup("atkbd_set=", atkbd_setup_set); |
||
734 | __setup("atkbd_reset", atkbd_setup_reset); |
||
735 | #endif |
||
736 | |||
737 | int __init atkbd_init(void) |
||
738 | { |
||
739 | serio_register_device(&atkbd_dev); |
||
740 | return 0; |
||
741 | } |
||
742 | |||
743 | void __exit atkbd_exit(void) |
||
744 | { |
||
745 | serio_unregister_device(&atkbd_dev); |
||
746 | } |
||
747 | |||
748 | module_init(atkbd_init); |
||
749 | module_exit(atkbd_exit); |