1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * AT and PS/2 keyboard driver
4 *
5 * Copyright (c) 1999-2002 Vojtech Pavlik
6 */
7
8
9 /*
10 * This driver can handle standard AT keyboards and PS/2 keyboards in
11 * Translated and Raw Set 2 and Set 3, as well as AT keyboards on dumb
12 * input-only controllers and AT keyboards connected over a one way RS232
13 * converter.
14 */
15
16 #include <linux/delay.h>
17 #include <linux/module.h>
18 #include <linux/slab.h>
19 #include <linux/interrupt.h>
20 #include <linux/init.h>
21 #include <linux/input.h>
22 #include <linux/serio.h>
23 #include <linux/workqueue.h>
24 #include <linux/libps2.h>
25 #include <linux/mutex.h>
26 #include <linux/dmi.h>
27 #include <linux/property.h>
28
29 #define DRIVER_DESC "AT and PS/2 keyboard driver"
30
31 MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
32 MODULE_DESCRIPTION(DRIVER_DESC);
33 MODULE_LICENSE("GPL");
34
35 static int atkbd_set = 2;
36 module_param_named(set, atkbd_set, int, 0);
37 MODULE_PARM_DESC(set, "Select keyboard code set (2 = default, 3 = PS/2 native)");
38
39 #if defined(__i386__) || defined(__x86_64__) || defined(__hppa__)
40 static bool atkbd_reset;
41 #else
42 static bool atkbd_reset = true;
43 #endif
44 module_param_named(reset, atkbd_reset, bool, 0);
45 MODULE_PARM_DESC(reset, "Reset keyboard during initialization");
46
47 static bool atkbd_softrepeat;
48 module_param_named(softrepeat, atkbd_softrepeat, bool, 0);
49 MODULE_PARM_DESC(softrepeat, "Use software keyboard repeat");
50
51 static bool atkbd_softraw = true;
52 module_param_named(softraw, atkbd_softraw, bool, 0);
53 MODULE_PARM_DESC(softraw, "Use software generated rawmode");
54
55 static bool atkbd_scroll;
56 module_param_named(scroll, atkbd_scroll, bool, 0);
57 MODULE_PARM_DESC(scroll, "Enable scroll-wheel on MS Office and similar keyboards");
58
59 static bool atkbd_extra;
60 module_param_named(extra, atkbd_extra, bool, 0);
61 MODULE_PARM_DESC(extra, "Enable extra LEDs and keys on IBM RapidAcces, EzKey and similar keyboards");
62
63 static bool atkbd_terminal;
64 module_param_named(terminal, atkbd_terminal, bool, 0);
65 MODULE_PARM_DESC(terminal, "Enable break codes on an IBM Terminal keyboard connected via AT/PS2");
66
67 #define MAX_FUNCTION_ROW_KEYS 24
68
69 #define SCANCODE(keymap) ((keymap >> 16) & 0xFFFF)
70 #define KEYCODE(keymap) (keymap & 0xFFFF)
71
72 /*
73 * Scancode to keycode tables. These are just the default setting, and
74 * are loadable via a userland utility.
75 */
76
77 #define ATKBD_KEYMAP_SIZE 512
78
79 static const unsigned short atkbd_set2_keycode[ATKBD_KEYMAP_SIZE] = {
80
81 #ifdef CONFIG_KEYBOARD_ATKBD_HP_KEYCODES
82
83 /* XXX: need a more general approach */
84
85 #include "hpps2atkbd.h" /* include the keyboard scancodes */
86
87 #else
88 0, 67, 65, 63, 61, 59, 60, 88, 0, 68, 66, 64, 62, 15, 41,117,
89 0, 56, 42, 93, 29, 16, 2, 0, 0, 0, 44, 31, 30, 17, 3, 0,
90 0, 46, 45, 32, 18, 5, 4, 95, 0, 57, 47, 33, 20, 19, 6,183,
91 0, 49, 48, 35, 34, 21, 7,184, 0, 0, 50, 36, 22, 8, 9,185,
92 0, 51, 37, 23, 24, 11, 10, 0, 0, 52, 53, 38, 39, 25, 12, 0,
93 0, 89, 40, 0, 26, 13, 0, 0, 58, 54, 28, 27, 0, 43, 0, 85,
94 0, 86, 91, 90, 92, 0, 14, 94, 0, 79,124, 75, 71,121, 0, 0,
95 82, 83, 80, 76, 77, 72, 1, 69, 87, 78, 81, 74, 55, 73, 70, 99,
96
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98 217,100,255, 0, 97,165, 0, 0,156, 0, 0, 0, 0, 0, 0,125,
99 173,114, 0,113, 0, 0, 0,126,128, 0, 0,140, 0, 0, 0,127,
100 159, 0,115, 0,164, 0, 0,116,158, 0,172,166, 0, 0, 0,142,
101 157, 0, 0, 0, 0, 0, 0, 0,155, 0, 98, 0, 0,163, 0, 0,
102 226, 0, 0, 0, 0, 0, 0, 0, 0,255, 96, 0, 0, 0,143, 0,
103 0, 0, 0, 0, 0, 0, 0, 0, 0,107, 0,105,102, 0, 0,112,
104 110,111,108,112,106,103, 0,119, 0,118,109, 0, 99,104,119, 0,
105
106 0, 0, 0, 65, 99,
107 #endif
108 };
109
110 static const unsigned short atkbd_set3_keycode[ATKBD_KEYMAP_SIZE] = {
111
112 0, 0, 0, 0, 0, 0, 0, 59, 1,138,128,129,130, 15, 41, 60,
113 131, 29, 42, 86, 58, 16, 2, 61,133, 56, 44, 31, 30, 17, 3, 62,
114 134, 46, 45, 32, 18, 5, 4, 63,135, 57, 47, 33, 20, 19, 6, 64,
115 136, 49, 48, 35, 34, 21, 7, 65,137,100, 50, 36, 22, 8, 9, 66,
116 125, 51, 37, 23, 24, 11, 10, 67,126, 52, 53, 38, 39, 25, 12, 68,
117 113,114, 40, 43, 26, 13, 87, 99, 97, 54, 28, 27, 43, 43, 88, 70,
118 108,105,119,103,111,107, 14,110, 0, 79,106, 75, 71,109,102,104,
119 82, 83, 80, 76, 77, 72, 69, 98, 0, 96, 81, 0, 78, 73, 55,183,
120
121 184,185,186,187, 74, 94, 92, 93, 0, 0, 0,125,126,127,112, 0,
122 0,139,172,163,165,115,152,172,166,140,160,154,113,114,167,168,
123 148,149,147,140
124 };
125
126 static const unsigned short atkbd_unxlate_table[128] = {
127 0,118, 22, 30, 38, 37, 46, 54, 61, 62, 70, 69, 78, 85,102, 13,
128 21, 29, 36, 45, 44, 53, 60, 67, 68, 77, 84, 91, 90, 20, 28, 27,
129 35, 43, 52, 51, 59, 66, 75, 76, 82, 14, 18, 93, 26, 34, 33, 42,
130 50, 49, 58, 65, 73, 74, 89,124, 17, 41, 88, 5, 6, 4, 12, 3,
131 11, 2, 10, 1, 9,119,126,108,117,125,123,107,115,116,121,105,
132 114,122,112,113,127, 96, 97,120, 7, 15, 23, 31, 39, 47, 55, 63,
133 71, 79, 86, 94, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 87,111,
134 19, 25, 57, 81, 83, 92, 95, 98, 99,100,101,103,104,106,109,110
135 };
136
137 #define ATKBD_CMD_SETLEDS 0x10ed
138 #define ATKBD_CMD_GSCANSET 0x11f0
139 #define ATKBD_CMD_SSCANSET 0x10f0
140 #define ATKBD_CMD_GETID 0x02f2
141 #define ATKBD_CMD_SETREP 0x10f3
142 #define ATKBD_CMD_ENABLE 0x00f4
143 #define ATKBD_CMD_RESET_DIS 0x00f5 /* Reset to defaults and disable */
144 #define ATKBD_CMD_RESET_DEF 0x00f6 /* Reset to defaults */
145 #define ATKBD_CMD_SETALL_MB 0x00f8 /* Set all keys to give break codes */
146 #define ATKBD_CMD_SETALL_MBR 0x00fa /* ... and repeat */
147 #define ATKBD_CMD_RESET_BAT 0x02ff
148 #define ATKBD_CMD_RESEND 0x00fe
149 #define ATKBD_CMD_EX_ENABLE 0x10ea
150 #define ATKBD_CMD_EX_SETLEDS 0x20eb
151 #define ATKBD_CMD_OK_GETID 0x02e8
152
153 #define ATKBD_RET_ACK 0xfa
154 #define ATKBD_RET_NAK 0xfe
155 #define ATKBD_RET_BAT 0xaa
156 #define ATKBD_RET_EMUL0 0xe0
157 #define ATKBD_RET_EMUL1 0xe1
158 #define ATKBD_RET_RELEASE 0xf0
159 #define ATKBD_RET_HANJA 0xf1
160 #define ATKBD_RET_HANGEUL 0xf2
161 #define ATKBD_RET_ERR 0xff
162
163 #define ATKBD_KEY_UNKNOWN 0
164 #define ATKBD_KEY_NULL 255
165
166 #define ATKBD_SCR_1 0xfffe
167 #define ATKBD_SCR_2 0xfffd
168 #define ATKBD_SCR_4 0xfffc
169 #define ATKBD_SCR_8 0xfffb
170 #define ATKBD_SCR_CLICK 0xfffa
171 #define ATKBD_SCR_LEFT 0xfff9
172 #define ATKBD_SCR_RIGHT 0xfff8
173
174 #define ATKBD_SPECIAL ATKBD_SCR_RIGHT
175
176 #define ATKBD_LED_EVENT_BIT 0
177 #define ATKBD_REP_EVENT_BIT 1
178
179 #define ATKBD_XL_ERR 0x01
180 #define ATKBD_XL_BAT 0x02
181 #define ATKBD_XL_ACK 0x04
182 #define ATKBD_XL_NAK 0x08
183 #define ATKBD_XL_HANGEUL 0x10
184 #define ATKBD_XL_HANJA 0x20
185
186 static const struct {
187 unsigned short keycode;
188 unsigned char set2;
189 } atkbd_scroll_keys[] = {
190 { ATKBD_SCR_1, 0xc5 },
191 { ATKBD_SCR_2, 0x9d },
192 { ATKBD_SCR_4, 0xa4 },
193 { ATKBD_SCR_8, 0x9b },
194 { ATKBD_SCR_CLICK, 0xe0 },
195 { ATKBD_SCR_LEFT, 0xcb },
196 { ATKBD_SCR_RIGHT, 0xd2 },
197 };
198
199 /*
200 * The atkbd control structure
201 */
202
203 struct atkbd {
204
205 struct ps2dev ps2dev;
206 struct input_dev *dev;
207
208 /* Written only during init */
209 char name[64];
210 char phys[32];
211
212 unsigned short id;
213 unsigned short keycode[ATKBD_KEYMAP_SIZE];
214 DECLARE_BITMAP(force_release_mask, ATKBD_KEYMAP_SIZE);
215 unsigned char set;
216 bool translated;
217 bool extra;
218 bool write;
219 bool softrepeat;
220 bool softraw;
221 bool scroll;
222 bool enabled;
223
224 /* Accessed only from interrupt */
225 unsigned char emul;
226 bool resend;
227 bool release;
228 unsigned long xl_bit;
229 unsigned int last;
230 unsigned long time;
231 unsigned long err_count;
232
233 struct delayed_work event_work;
234 unsigned long event_jiffies;
235 unsigned long event_mask;
236
237 /* Serializes reconnect(), attr->set() and event work */
238 struct mutex mutex;
239
240 u32 function_row_physmap[MAX_FUNCTION_ROW_KEYS];
241 int num_function_row_keys;
242 };
243
244 /*
245 * System-specific keymap fixup routine
246 */
247 static void (*atkbd_platform_fixup)(struct atkbd *, const void *data);
248 static void *atkbd_platform_fixup_data;
249 static unsigned int (*atkbd_platform_scancode_fixup)(struct atkbd *, unsigned int);
250
251 /*
252 * Certain keyboards to not like ATKBD_CMD_RESET_DIS and stop responding
253 * to many commands until full reset (ATKBD_CMD_RESET_BAT) is performed.
254 */
255 static bool atkbd_skip_deactivate;
256
257 static ssize_t atkbd_attr_show_helper(struct device *dev, char *buf,
258 ssize_t (*handler)(struct atkbd *, char *));
259 static ssize_t atkbd_attr_set_helper(struct device *dev, const char *buf, size_t count,
260 ssize_t (*handler)(struct atkbd *, const char *, size_t));
261 #define ATKBD_DEFINE_ATTR(_name) \
262 static ssize_t atkbd_show_##_name(struct atkbd *, char *); \
263 static ssize_t atkbd_set_##_name(struct atkbd *, const char *, size_t); \
264 static ssize_t atkbd_do_show_##_name(struct device *d, \
265 struct device_attribute *attr, char *b) \
266 { \
267 return atkbd_attr_show_helper(d, b, atkbd_show_##_name); \
268 } \
269 static ssize_t atkbd_do_set_##_name(struct device *d, \
270 struct device_attribute *attr, const char *b, size_t s) \
271 { \
272 return atkbd_attr_set_helper(d, b, s, atkbd_set_##_name); \
273 } \
274 static struct device_attribute atkbd_attr_##_name = \
275 __ATTR(_name, S_IWUSR | S_IRUGO, atkbd_do_show_##_name, atkbd_do_set_##_name);
276
277 ATKBD_DEFINE_ATTR(extra);
278 ATKBD_DEFINE_ATTR(force_release);
279 ATKBD_DEFINE_ATTR(scroll);
280 ATKBD_DEFINE_ATTR(set);
281 ATKBD_DEFINE_ATTR(softrepeat);
282 ATKBD_DEFINE_ATTR(softraw);
283
284 #define ATKBD_DEFINE_RO_ATTR(_name) \
285 static ssize_t atkbd_show_##_name(struct atkbd *, char *); \
286 static ssize_t atkbd_do_show_##_name(struct device *d, \
287 struct device_attribute *attr, char *b) \
288 { \
289 return atkbd_attr_show_helper(d, b, atkbd_show_##_name); \
290 } \
291 static struct device_attribute atkbd_attr_##_name = \
292 __ATTR(_name, S_IRUGO, atkbd_do_show_##_name, NULL);
293
294 ATKBD_DEFINE_RO_ATTR(err_count);
295 ATKBD_DEFINE_RO_ATTR(function_row_physmap);
296
297 static struct attribute *atkbd_attributes[] = {
298 &atkbd_attr_extra.attr,
299 &atkbd_attr_force_release.attr,
300 &atkbd_attr_scroll.attr,
301 &atkbd_attr_set.attr,
302 &atkbd_attr_softrepeat.attr,
303 &atkbd_attr_softraw.attr,
304 &atkbd_attr_err_count.attr,
305 &atkbd_attr_function_row_physmap.attr,
306 NULL
307 };
308
atkbd_show_function_row_physmap(struct atkbd * atkbd,char * buf)309 static ssize_t atkbd_show_function_row_physmap(struct atkbd *atkbd, char *buf)
310 {
311 ssize_t size = 0;
312 int i;
313
314 if (!atkbd->num_function_row_keys)
315 return 0;
316
317 for (i = 0; i < atkbd->num_function_row_keys; i++)
318 size += scnprintf(buf + size, PAGE_SIZE - size, "%02X ",
319 atkbd->function_row_physmap[i]);
320 size += scnprintf(buf + size, PAGE_SIZE - size, "\n");
321 return size;
322 }
323
atkbd_attr_is_visible(struct kobject * kobj,struct attribute * attr,int i)324 static umode_t atkbd_attr_is_visible(struct kobject *kobj,
325 struct attribute *attr, int i)
326 {
327 struct device *dev = container_of(kobj, struct device, kobj);
328 struct serio *serio = to_serio_port(dev);
329 struct atkbd *atkbd = serio_get_drvdata(serio);
330
331 if (attr == &atkbd_attr_function_row_physmap.attr &&
332 !atkbd->num_function_row_keys)
333 return 0;
334
335 return attr->mode;
336 }
337
338 static struct attribute_group atkbd_attribute_group = {
339 .attrs = atkbd_attributes,
340 .is_visible = atkbd_attr_is_visible,
341 };
342
343 static const unsigned int xl_table[] = {
344 ATKBD_RET_BAT, ATKBD_RET_ERR, ATKBD_RET_ACK,
345 ATKBD_RET_NAK, ATKBD_RET_HANJA, ATKBD_RET_HANGEUL,
346 };
347
348 /*
349 * Checks if we should mangle the scancode to extract 'release' bit
350 * in translated mode.
351 */
atkbd_need_xlate(unsigned long xl_bit,unsigned char code)352 static bool atkbd_need_xlate(unsigned long xl_bit, unsigned char code)
353 {
354 int i;
355
356 if (code == ATKBD_RET_EMUL0 || code == ATKBD_RET_EMUL1)
357 return false;
358
359 for (i = 0; i < ARRAY_SIZE(xl_table); i++)
360 if (code == xl_table[i])
361 return test_bit(i, &xl_bit);
362
363 return true;
364 }
365
366 /*
367 * Calculates new value of xl_bit so the driver can distinguish
368 * between make/break pair of scancodes for select keys and PS/2
369 * protocol responses.
370 */
atkbd_calculate_xl_bit(struct atkbd * atkbd,unsigned char code)371 static void atkbd_calculate_xl_bit(struct atkbd *atkbd, unsigned char code)
372 {
373 int i;
374
375 for (i = 0; i < ARRAY_SIZE(xl_table); i++) {
376 if (!((code ^ xl_table[i]) & 0x7f)) {
377 if (code & 0x80)
378 __clear_bit(i, &atkbd->xl_bit);
379 else
380 __set_bit(i, &atkbd->xl_bit);
381 break;
382 }
383 }
384 }
385
386 /*
387 * Encode the scancode, 0xe0 prefix, and high bit into a single integer,
388 * keeping kernel 2.4 compatibility for set 2
389 */
atkbd_compat_scancode(struct atkbd * atkbd,unsigned int code)390 static unsigned int atkbd_compat_scancode(struct atkbd *atkbd, unsigned int code)
391 {
392 if (atkbd->set == 3) {
393 if (atkbd->emul == 1)
394 code |= 0x100;
395 } else {
396 code = (code & 0x7f) | ((code & 0x80) << 1);
397 if (atkbd->emul == 1)
398 code |= 0x80;
399 }
400
401 return code;
402 }
403
404 /*
405 * atkbd_interrupt(). Here takes place processing of data received from
406 * the keyboard into events.
407 */
408
atkbd_interrupt(struct serio * serio,unsigned char data,unsigned int flags)409 static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
410 unsigned int flags)
411 {
412 struct atkbd *atkbd = serio_get_drvdata(serio);
413 struct input_dev *dev = atkbd->dev;
414 unsigned int code = data;
415 int scroll = 0, hscroll = 0, click = -1;
416 int value;
417 unsigned short keycode;
418
419 dev_dbg(&serio->dev, "Received %02x flags %02x\n", data, flags);
420
421 #if !defined(__i386__) && !defined (__x86_64__)
422 if ((flags & (SERIO_FRAME | SERIO_PARITY)) && (~flags & SERIO_TIMEOUT) && !atkbd->resend && atkbd->write) {
423 dev_warn(&serio->dev, "Frame/parity error: %02x\n", flags);
424 serio_write(serio, ATKBD_CMD_RESEND);
425 atkbd->resend = true;
426 goto out;
427 }
428
429 if (!flags && data == ATKBD_RET_ACK)
430 atkbd->resend = false;
431 #endif
432
433 if (unlikely(atkbd->ps2dev.flags & PS2_FLAG_ACK))
434 if (ps2_handle_ack(&atkbd->ps2dev, data))
435 goto out;
436
437 if (unlikely(atkbd->ps2dev.flags & PS2_FLAG_CMD))
438 if (ps2_handle_response(&atkbd->ps2dev, data))
439 goto out;
440
441 pm_wakeup_event(&serio->dev, 0);
442
443 if (!atkbd->enabled)
444 goto out;
445
446 input_event(dev, EV_MSC, MSC_RAW, code);
447
448 if (atkbd_platform_scancode_fixup)
449 code = atkbd_platform_scancode_fixup(atkbd, code);
450
451 if (atkbd->translated) {
452
453 if (atkbd->emul || atkbd_need_xlate(atkbd->xl_bit, code)) {
454 atkbd->release = code >> 7;
455 code &= 0x7f;
456 }
457
458 if (!atkbd->emul)
459 atkbd_calculate_xl_bit(atkbd, data);
460 }
461
462 switch (code) {
463 case ATKBD_RET_BAT:
464 atkbd->enabled = false;
465 serio_reconnect(atkbd->ps2dev.serio);
466 goto out;
467 case ATKBD_RET_EMUL0:
468 atkbd->emul = 1;
469 goto out;
470 case ATKBD_RET_EMUL1:
471 atkbd->emul = 2;
472 goto out;
473 case ATKBD_RET_RELEASE:
474 atkbd->release = true;
475 goto out;
476 case ATKBD_RET_ACK:
477 case ATKBD_RET_NAK:
478 if (printk_ratelimit())
479 dev_warn(&serio->dev,
480 "Spurious %s on %s. "
481 "Some program might be trying to access hardware directly.\n",
482 data == ATKBD_RET_ACK ? "ACK" : "NAK", serio->phys);
483 goto out;
484 case ATKBD_RET_ERR:
485 atkbd->err_count++;
486 dev_dbg(&serio->dev, "Keyboard on %s reports too many keys pressed.\n",
487 serio->phys);
488 goto out;
489 }
490
491 code = atkbd_compat_scancode(atkbd, code);
492
493 if (atkbd->emul && --atkbd->emul)
494 goto out;
495
496 keycode = atkbd->keycode[code];
497
498 if (!(atkbd->release && test_bit(code, atkbd->force_release_mask)))
499 if (keycode != ATKBD_KEY_NULL)
500 input_event(dev, EV_MSC, MSC_SCAN, code);
501
502 switch (keycode) {
503 case ATKBD_KEY_NULL:
504 break;
505 case ATKBD_KEY_UNKNOWN:
506 dev_warn(&serio->dev,
507 "Unknown key %s (%s set %d, code %#x on %s).\n",
508 atkbd->release ? "released" : "pressed",
509 atkbd->translated ? "translated" : "raw",
510 atkbd->set, code, serio->phys);
511 dev_warn(&serio->dev,
512 "Use 'setkeycodes %s%02x <keycode>' to make it known.\n",
513 code & 0x80 ? "e0" : "", code & 0x7f);
514 input_sync(dev);
515 break;
516 case ATKBD_SCR_1:
517 scroll = 1;
518 break;
519 case ATKBD_SCR_2:
520 scroll = 2;
521 break;
522 case ATKBD_SCR_4:
523 scroll = 4;
524 break;
525 case ATKBD_SCR_8:
526 scroll = 8;
527 break;
528 case ATKBD_SCR_CLICK:
529 click = !atkbd->release;
530 break;
531 case ATKBD_SCR_LEFT:
532 hscroll = -1;
533 break;
534 case ATKBD_SCR_RIGHT:
535 hscroll = 1;
536 break;
537 default:
538 if (atkbd->release) {
539 value = 0;
540 atkbd->last = 0;
541 } else if (!atkbd->softrepeat && test_bit(keycode, dev->key)) {
542 /* Workaround Toshiba laptop multiple keypress */
543 value = time_before(jiffies, atkbd->time) && atkbd->last == code ? 1 : 2;
544 } else {
545 value = 1;
546 atkbd->last = code;
547 atkbd->time = jiffies + msecs_to_jiffies(dev->rep[REP_DELAY]) / 2;
548 }
549
550 input_event(dev, EV_KEY, keycode, value);
551 input_sync(dev);
552
553 if (value && test_bit(code, atkbd->force_release_mask)) {
554 input_event(dev, EV_MSC, MSC_SCAN, code);
555 input_report_key(dev, keycode, 0);
556 input_sync(dev);
557 }
558 }
559
560 if (atkbd->scroll) {
561 if (click != -1)
562 input_report_key(dev, BTN_MIDDLE, click);
563 input_report_rel(dev, REL_WHEEL,
564 atkbd->release ? -scroll : scroll);
565 input_report_rel(dev, REL_HWHEEL, hscroll);
566 input_sync(dev);
567 }
568
569 atkbd->release = false;
570 out:
571 return IRQ_HANDLED;
572 }
573
atkbd_set_repeat_rate(struct atkbd * atkbd)574 static int atkbd_set_repeat_rate(struct atkbd *atkbd)
575 {
576 const short period[32] =
577 { 33, 37, 42, 46, 50, 54, 58, 63, 67, 75, 83, 92, 100, 109, 116, 125,
578 133, 149, 167, 182, 200, 217, 232, 250, 270, 303, 333, 370, 400, 435, 470, 500 };
579 const short delay[4] =
580 { 250, 500, 750, 1000 };
581
582 struct input_dev *dev = atkbd->dev;
583 unsigned char param;
584 int i = 0, j = 0;
585
586 while (i < ARRAY_SIZE(period) - 1 && period[i] < dev->rep[REP_PERIOD])
587 i++;
588 dev->rep[REP_PERIOD] = period[i];
589
590 while (j < ARRAY_SIZE(delay) - 1 && delay[j] < dev->rep[REP_DELAY])
591 j++;
592 dev->rep[REP_DELAY] = delay[j];
593
594 param = i | (j << 5);
595 return ps2_command(&atkbd->ps2dev, ¶m, ATKBD_CMD_SETREP);
596 }
597
atkbd_set_leds(struct atkbd * atkbd)598 static int atkbd_set_leds(struct atkbd *atkbd)
599 {
600 struct input_dev *dev = atkbd->dev;
601 unsigned char param[2];
602
603 param[0] = (test_bit(LED_SCROLLL, dev->led) ? 1 : 0)
604 | (test_bit(LED_NUML, dev->led) ? 2 : 0)
605 | (test_bit(LED_CAPSL, dev->led) ? 4 : 0);
606 if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETLEDS))
607 return -1;
608
609 if (atkbd->extra) {
610 param[0] = 0;
611 param[1] = (test_bit(LED_COMPOSE, dev->led) ? 0x01 : 0)
612 | (test_bit(LED_SLEEP, dev->led) ? 0x02 : 0)
613 | (test_bit(LED_SUSPEND, dev->led) ? 0x04 : 0)
614 | (test_bit(LED_MISC, dev->led) ? 0x10 : 0)
615 | (test_bit(LED_MUTE, dev->led) ? 0x20 : 0);
616 if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_EX_SETLEDS))
617 return -1;
618 }
619
620 return 0;
621 }
622
623 /*
624 * atkbd_event_work() is used to complete processing of events that
625 * can not be processed by input_event() which is often called from
626 * interrupt context.
627 */
628
atkbd_event_work(struct work_struct * work)629 static void atkbd_event_work(struct work_struct *work)
630 {
631 struct atkbd *atkbd = container_of(work, struct atkbd, event_work.work);
632
633 mutex_lock(&atkbd->mutex);
634
635 if (!atkbd->enabled) {
636 /*
637 * Serio ports are resumed asynchronously so while driver core
638 * thinks that device is already fully operational in reality
639 * it may not be ready yet. In this case we need to keep
640 * rescheduling till reconnect completes.
641 */
642 schedule_delayed_work(&atkbd->event_work,
643 msecs_to_jiffies(100));
644 } else {
645 if (test_and_clear_bit(ATKBD_LED_EVENT_BIT, &atkbd->event_mask))
646 atkbd_set_leds(atkbd);
647
648 if (test_and_clear_bit(ATKBD_REP_EVENT_BIT, &atkbd->event_mask))
649 atkbd_set_repeat_rate(atkbd);
650 }
651
652 mutex_unlock(&atkbd->mutex);
653 }
654
655 /*
656 * Schedule switch for execution. We need to throttle requests,
657 * otherwise keyboard may become unresponsive.
658 */
atkbd_schedule_event_work(struct atkbd * atkbd,int event_bit)659 static void atkbd_schedule_event_work(struct atkbd *atkbd, int event_bit)
660 {
661 unsigned long delay = msecs_to_jiffies(50);
662
663 if (time_after(jiffies, atkbd->event_jiffies + delay))
664 delay = 0;
665
666 atkbd->event_jiffies = jiffies;
667 set_bit(event_bit, &atkbd->event_mask);
668 mb();
669 schedule_delayed_work(&atkbd->event_work, delay);
670 }
671
672 /*
673 * Event callback from the input module. Events that change the state of
674 * the hardware are processed here. If action can not be performed in
675 * interrupt context it is offloaded to atkbd_event_work.
676 */
677
atkbd_event(struct input_dev * dev,unsigned int type,unsigned int code,int value)678 static int atkbd_event(struct input_dev *dev,
679 unsigned int type, unsigned int code, int value)
680 {
681 struct atkbd *atkbd = input_get_drvdata(dev);
682
683 if (!atkbd->write)
684 return -1;
685
686 switch (type) {
687
688 case EV_LED:
689 atkbd_schedule_event_work(atkbd, ATKBD_LED_EVENT_BIT);
690 return 0;
691
692 case EV_REP:
693 if (!atkbd->softrepeat)
694 atkbd_schedule_event_work(atkbd, ATKBD_REP_EVENT_BIT);
695 return 0;
696
697 default:
698 return -1;
699 }
700 }
701
702 /*
703 * atkbd_enable() signals that interrupt handler is allowed to
704 * generate input events.
705 */
706
atkbd_enable(struct atkbd * atkbd)707 static inline void atkbd_enable(struct atkbd *atkbd)
708 {
709 serio_pause_rx(atkbd->ps2dev.serio);
710 atkbd->enabled = true;
711 serio_continue_rx(atkbd->ps2dev.serio);
712 }
713
714 /*
715 * atkbd_disable() tells input handler that all incoming data except
716 * for ACKs and command response should be dropped.
717 */
718
atkbd_disable(struct atkbd * atkbd)719 static inline void atkbd_disable(struct atkbd *atkbd)
720 {
721 serio_pause_rx(atkbd->ps2dev.serio);
722 atkbd->enabled = false;
723 serio_continue_rx(atkbd->ps2dev.serio);
724 }
725
atkbd_activate(struct atkbd * atkbd)726 static int atkbd_activate(struct atkbd *atkbd)
727 {
728 struct ps2dev *ps2dev = &atkbd->ps2dev;
729
730 /*
731 * Enable the keyboard to receive keystrokes.
732 */
733
734 if (ps2_command(ps2dev, NULL, ATKBD_CMD_ENABLE)) {
735 dev_err(&ps2dev->serio->dev,
736 "Failed to enable keyboard on %s\n",
737 ps2dev->serio->phys);
738 return -1;
739 }
740
741 return 0;
742 }
743
744 /*
745 * atkbd_deactivate() resets and disables the keyboard from sending
746 * keystrokes.
747 */
748
atkbd_deactivate(struct atkbd * atkbd)749 static void atkbd_deactivate(struct atkbd *atkbd)
750 {
751 struct ps2dev *ps2dev = &atkbd->ps2dev;
752
753 if (ps2_command(ps2dev, NULL, ATKBD_CMD_RESET_DIS))
754 dev_err(&ps2dev->serio->dev,
755 "Failed to deactivate keyboard on %s\n",
756 ps2dev->serio->phys);
757 }
758
759 #ifdef CONFIG_X86
atkbd_is_portable_device(void)760 static bool atkbd_is_portable_device(void)
761 {
762 static const char * const chassis_types[] = {
763 "8", /* Portable */
764 "9", /* Laptop */
765 "10", /* Notebook */
766 "14", /* Sub-Notebook */
767 "31", /* Convertible */
768 "32", /* Detachable */
769 };
770 int i;
771
772 for (i = 0; i < ARRAY_SIZE(chassis_types); i++)
773 if (dmi_match(DMI_CHASSIS_TYPE, chassis_types[i]))
774 return true;
775
776 return false;
777 }
778
779 /*
780 * On many modern laptops ATKBD_CMD_GETID may cause problems, on these laptops
781 * the controller is always in translated mode. In this mode mice/touchpads will
782 * not work. So in this case simply assume a keyboard is connected to avoid
783 * confusing some laptop keyboards.
784 *
785 * Skipping ATKBD_CMD_GETID ends up using a fake keyboard id. Using a fake id is
786 * ok in translated mode, only atkbd_select_set() checks atkbd->id and in
787 * translated mode that is a no-op.
788 */
atkbd_skip_getid(struct atkbd * atkbd)789 static bool atkbd_skip_getid(struct atkbd *atkbd)
790 {
791 return atkbd->translated && atkbd_is_portable_device();
792 }
793 #else
atkbd_skip_getid(struct atkbd * atkbd)794 static inline bool atkbd_skip_getid(struct atkbd *atkbd) { return false; }
795 #endif
796
797 /*
798 * atkbd_probe() probes for an AT keyboard on a serio port.
799 */
800
atkbd_probe(struct atkbd * atkbd)801 static int atkbd_probe(struct atkbd *atkbd)
802 {
803 struct ps2dev *ps2dev = &atkbd->ps2dev;
804 unsigned char param[2];
805
806 /*
807 * Some systems, where the bit-twiddling when testing the io-lines of the
808 * controller may confuse the keyboard need a full reset of the keyboard. On
809 * these systems the BIOS also usually doesn't do it for us.
810 */
811
812 if (atkbd_reset)
813 if (ps2_command(ps2dev, NULL, ATKBD_CMD_RESET_BAT))
814 dev_warn(&ps2dev->serio->dev,
815 "keyboard reset failed on %s\n",
816 ps2dev->serio->phys);
817
818 /*
819 * Then we check the keyboard ID. We should get 0xab83 under normal conditions.
820 * Some keyboards report different values, but the first byte is always 0xab or
821 * 0xac. Some old AT keyboards don't report anything. If a mouse is connected, this
822 * should make sure we don't try to set the LEDs on it.
823 */
824
825 param[0] = param[1] = 0xa5; /* initialize with invalid values */
826 if (atkbd_skip_getid(atkbd) || ps2_command(ps2dev, param, ATKBD_CMD_GETID)) {
827
828 /*
829 * If the get ID command was skipped or failed, we check if we can at least set
830 * the LEDs on the keyboard. This should work on every keyboard out there.
831 * It also turns the LEDs off, which we want anyway.
832 */
833 param[0] = 0;
834 if (ps2_command(ps2dev, param, ATKBD_CMD_SETLEDS))
835 return -1;
836 atkbd->id = 0xabba;
837 return 0;
838 }
839
840 if (!ps2_is_keyboard_id(param[0]))
841 return -1;
842
843 atkbd->id = (param[0] << 8) | param[1];
844
845 if (atkbd->id == 0xaca1 && atkbd->translated) {
846 dev_err(&ps2dev->serio->dev,
847 "NCD terminal keyboards are only supported on non-translating controllers. "
848 "Use i8042.direct=1 to disable translation.\n");
849 return -1;
850 }
851
852 /*
853 * Make sure nothing is coming from the keyboard and disturbs our
854 * internal state.
855 */
856 if (!atkbd_skip_deactivate)
857 atkbd_deactivate(atkbd);
858
859 return 0;
860 }
861
862 /*
863 * atkbd_select_set checks if a keyboard has a working Set 3 support, and
864 * sets it into that. Unfortunately there are keyboards that can be switched
865 * to Set 3, but don't work well in that (BTC Multimedia ...)
866 */
867
atkbd_select_set(struct atkbd * atkbd,int target_set,int allow_extra)868 static int atkbd_select_set(struct atkbd *atkbd, int target_set, int allow_extra)
869 {
870 struct ps2dev *ps2dev = &atkbd->ps2dev;
871 unsigned char param[2];
872
873 atkbd->extra = false;
874 /*
875 * For known special keyboards we can go ahead and set the correct set.
876 * We check for NCD PS/2 Sun, NorthGate OmniKey 101 and
877 * IBM RapidAccess / IBM EzButton / Chicony KBP-8993 keyboards.
878 */
879
880 if (atkbd->translated)
881 return 2;
882
883 if (atkbd->id == 0xaca1) {
884 param[0] = 3;
885 ps2_command(ps2dev, param, ATKBD_CMD_SSCANSET);
886 return 3;
887 }
888
889 if (allow_extra) {
890 param[0] = 0x71;
891 if (!ps2_command(ps2dev, param, ATKBD_CMD_EX_ENABLE)) {
892 atkbd->extra = true;
893 return 2;
894 }
895 }
896
897 if (atkbd_terminal) {
898 ps2_command(ps2dev, param, ATKBD_CMD_SETALL_MB);
899 return 3;
900 }
901
902 if (target_set != 3)
903 return 2;
904
905 if (!ps2_command(ps2dev, param, ATKBD_CMD_OK_GETID)) {
906 atkbd->id = param[0] << 8 | param[1];
907 return 2;
908 }
909
910 param[0] = 3;
911 if (ps2_command(ps2dev, param, ATKBD_CMD_SSCANSET))
912 return 2;
913
914 param[0] = 0;
915 if (ps2_command(ps2dev, param, ATKBD_CMD_GSCANSET))
916 return 2;
917
918 if (param[0] != 3) {
919 param[0] = 2;
920 if (ps2_command(ps2dev, param, ATKBD_CMD_SSCANSET))
921 return 2;
922 }
923
924 ps2_command(ps2dev, param, ATKBD_CMD_SETALL_MBR);
925
926 return 3;
927 }
928
atkbd_reset_state(struct atkbd * atkbd)929 static int atkbd_reset_state(struct atkbd *atkbd)
930 {
931 struct ps2dev *ps2dev = &atkbd->ps2dev;
932 unsigned char param[1];
933
934 /*
935 * Set the LEDs to a predefined state (all off).
936 */
937
938 param[0] = 0;
939 if (ps2_command(ps2dev, param, ATKBD_CMD_SETLEDS))
940 return -1;
941
942 /*
943 * Set autorepeat to fastest possible.
944 */
945
946 param[0] = 0;
947 if (ps2_command(ps2dev, param, ATKBD_CMD_SETREP))
948 return -1;
949
950 return 0;
951 }
952
953 /*
954 * atkbd_cleanup() restores the keyboard state so that BIOS is happy after a
955 * reboot.
956 */
957
atkbd_cleanup(struct serio * serio)958 static void atkbd_cleanup(struct serio *serio)
959 {
960 struct atkbd *atkbd = serio_get_drvdata(serio);
961
962 atkbd_disable(atkbd);
963 ps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_DEF);
964 }
965
966
967 /*
968 * atkbd_disconnect() closes and frees.
969 */
970
atkbd_disconnect(struct serio * serio)971 static void atkbd_disconnect(struct serio *serio)
972 {
973 struct atkbd *atkbd = serio_get_drvdata(serio);
974
975 sysfs_remove_group(&serio->dev.kobj, &atkbd_attribute_group);
976
977 atkbd_disable(atkbd);
978
979 input_unregister_device(atkbd->dev);
980
981 /*
982 * Make sure we don't have a command in flight.
983 * Note that since atkbd->enabled is false event work will keep
984 * rescheduling itself until it gets canceled and will not try
985 * accessing freed input device or serio port.
986 */
987 cancel_delayed_work_sync(&atkbd->event_work);
988
989 serio_close(serio);
990 serio_set_drvdata(serio, NULL);
991 kfree(atkbd);
992 }
993
994 /*
995 * generate release events for the keycodes given in data
996 */
atkbd_apply_forced_release_keylist(struct atkbd * atkbd,const void * data)997 static void atkbd_apply_forced_release_keylist(struct atkbd* atkbd,
998 const void *data)
999 {
1000 const unsigned int *keys = data;
1001 unsigned int i;
1002
1003 if (atkbd->set == 2)
1004 for (i = 0; keys[i] != -1U; i++)
1005 __set_bit(keys[i], atkbd->force_release_mask);
1006 }
1007
1008 /*
1009 * Most special keys (Fn+F?) on Dell laptops do not generate release
1010 * events so we have to do it ourselves.
1011 */
1012 static unsigned int atkbd_dell_laptop_forced_release_keys[] = {
1013 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8f, 0x93, -1U
1014 };
1015
1016 /*
1017 * Perform fixup for HP system that doesn't generate release
1018 * for its video switch
1019 */
1020 static unsigned int atkbd_hp_forced_release_keys[] = {
1021 0x94, -1U
1022 };
1023
1024 /*
1025 * Samsung NC10,NC20 with Fn+F? key release not working
1026 */
1027 static unsigned int atkbd_samsung_forced_release_keys[] = {
1028 0x82, 0x83, 0x84, 0x86, 0x88, 0x89, 0xb3, 0xf7, 0xf9, -1U
1029 };
1030
1031 /*
1032 * Amilo Pi 3525 key release for Fn+Volume keys not working
1033 */
1034 static unsigned int atkbd_amilo_pi3525_forced_release_keys[] = {
1035 0x20, 0xa0, 0x2e, 0xae, 0x30, 0xb0, -1U
1036 };
1037
1038 /*
1039 * Amilo Xi 3650 key release for light touch bar not working
1040 */
1041 static unsigned int atkbd_amilo_xi3650_forced_release_keys[] = {
1042 0x67, 0xed, 0x90, 0xa2, 0x99, 0xa4, 0xae, 0xb0, -1U
1043 };
1044
1045 /*
1046 * Soltech TA12 system with broken key release on volume keys and mute key
1047 */
1048 static unsigned int atkdb_soltech_ta12_forced_release_keys[] = {
1049 0xa0, 0xae, 0xb0, -1U
1050 };
1051
1052 /*
1053 * Many notebooks don't send key release event for volume up/down
1054 * keys, with key list below common among them
1055 */
1056 static unsigned int atkbd_volume_forced_release_keys[] = {
1057 0xae, 0xb0, -1U
1058 };
1059
1060 /*
1061 * OQO 01+ multimedia keys (64--66) generate e0 6x upon release whereas
1062 * they should be generating e4-e6 (0x80 | code).
1063 */
atkbd_oqo_01plus_scancode_fixup(struct atkbd * atkbd,unsigned int code)1064 static unsigned int atkbd_oqo_01plus_scancode_fixup(struct atkbd *atkbd,
1065 unsigned int code)
1066 {
1067 if (atkbd->translated && atkbd->emul == 1 &&
1068 (code == 0x64 || code == 0x65 || code == 0x66)) {
1069 atkbd->emul = 0;
1070 code |= 0x80;
1071 }
1072
1073 return code;
1074 }
1075
atkbd_get_keymap_from_fwnode(struct atkbd * atkbd)1076 static int atkbd_get_keymap_from_fwnode(struct atkbd *atkbd)
1077 {
1078 struct device *dev = &atkbd->ps2dev.serio->dev;
1079 int i, n;
1080 u32 *ptr;
1081 u16 scancode, keycode;
1082
1083 /* Parse "linux,keymap" property */
1084 n = device_property_count_u32(dev, "linux,keymap");
1085 if (n <= 0 || n > ATKBD_KEYMAP_SIZE)
1086 return -ENXIO;
1087
1088 ptr = kcalloc(n, sizeof(u32), GFP_KERNEL);
1089 if (!ptr)
1090 return -ENOMEM;
1091
1092 if (device_property_read_u32_array(dev, "linux,keymap", ptr, n)) {
1093 dev_err(dev, "problem parsing FW keymap property\n");
1094 kfree(ptr);
1095 return -EINVAL;
1096 }
1097
1098 memset(atkbd->keycode, 0, sizeof(atkbd->keycode));
1099 for (i = 0; i < n; i++) {
1100 scancode = SCANCODE(ptr[i]);
1101 keycode = KEYCODE(ptr[i]);
1102 atkbd->keycode[scancode] = keycode;
1103 }
1104
1105 kfree(ptr);
1106 return 0;
1107 }
1108
1109 /*
1110 * atkbd_set_keycode_table() initializes keyboard's keycode table
1111 * according to the selected scancode set
1112 */
1113
atkbd_set_keycode_table(struct atkbd * atkbd)1114 static void atkbd_set_keycode_table(struct atkbd *atkbd)
1115 {
1116 struct device *dev = &atkbd->ps2dev.serio->dev;
1117 unsigned int scancode;
1118 int i, j;
1119
1120 memset(atkbd->keycode, 0, sizeof(atkbd->keycode));
1121 bitmap_zero(atkbd->force_release_mask, ATKBD_KEYMAP_SIZE);
1122
1123 if (!atkbd_get_keymap_from_fwnode(atkbd)) {
1124 dev_dbg(dev, "Using FW keymap\n");
1125 } else if (atkbd->translated) {
1126 for (i = 0; i < 128; i++) {
1127 scancode = atkbd_unxlate_table[i];
1128 atkbd->keycode[i] = atkbd_set2_keycode[scancode];
1129 atkbd->keycode[i | 0x80] = atkbd_set2_keycode[scancode | 0x80];
1130 if (atkbd->scroll)
1131 for (j = 0; j < ARRAY_SIZE(atkbd_scroll_keys); j++)
1132 if ((scancode | 0x80) == atkbd_scroll_keys[j].set2)
1133 atkbd->keycode[i | 0x80] = atkbd_scroll_keys[j].keycode;
1134 }
1135 } else if (atkbd->set == 3) {
1136 memcpy(atkbd->keycode, atkbd_set3_keycode, sizeof(atkbd->keycode));
1137 } else {
1138 memcpy(atkbd->keycode, atkbd_set2_keycode, sizeof(atkbd->keycode));
1139
1140 if (atkbd->scroll)
1141 for (i = 0; i < ARRAY_SIZE(atkbd_scroll_keys); i++) {
1142 scancode = atkbd_scroll_keys[i].set2;
1143 atkbd->keycode[scancode] = atkbd_scroll_keys[i].keycode;
1144 }
1145 }
1146
1147 /*
1148 * HANGEUL and HANJA keys do not send release events so we need to
1149 * generate such events ourselves
1150 */
1151 scancode = atkbd_compat_scancode(atkbd, ATKBD_RET_HANGEUL);
1152 atkbd->keycode[scancode] = KEY_HANGEUL;
1153 __set_bit(scancode, atkbd->force_release_mask);
1154
1155 scancode = atkbd_compat_scancode(atkbd, ATKBD_RET_HANJA);
1156 atkbd->keycode[scancode] = KEY_HANJA;
1157 __set_bit(scancode, atkbd->force_release_mask);
1158
1159 /*
1160 * Perform additional fixups
1161 */
1162 if (atkbd_platform_fixup)
1163 atkbd_platform_fixup(atkbd, atkbd_platform_fixup_data);
1164 }
1165
1166 /*
1167 * atkbd_set_device_attrs() sets up keyboard's input device structure
1168 */
1169
atkbd_set_device_attrs(struct atkbd * atkbd)1170 static void atkbd_set_device_attrs(struct atkbd *atkbd)
1171 {
1172 struct input_dev *input_dev = atkbd->dev;
1173 int i;
1174
1175 if (atkbd->extra)
1176 snprintf(atkbd->name, sizeof(atkbd->name),
1177 "AT Set 2 Extra keyboard");
1178 else
1179 snprintf(atkbd->name, sizeof(atkbd->name),
1180 "AT %s Set %d keyboard",
1181 atkbd->translated ? "Translated" : "Raw", atkbd->set);
1182
1183 snprintf(atkbd->phys, sizeof(atkbd->phys),
1184 "%s/input0", atkbd->ps2dev.serio->phys);
1185
1186 input_dev->name = atkbd->name;
1187 input_dev->phys = atkbd->phys;
1188 input_dev->id.bustype = BUS_I8042;
1189 input_dev->id.vendor = 0x0001;
1190 input_dev->id.product = atkbd->translated ? 1 : atkbd->set;
1191 input_dev->id.version = atkbd->id;
1192 input_dev->event = atkbd_event;
1193 input_dev->dev.parent = &atkbd->ps2dev.serio->dev;
1194
1195 input_set_drvdata(input_dev, atkbd);
1196
1197 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) |
1198 BIT_MASK(EV_MSC);
1199
1200 if (atkbd->write) {
1201 input_dev->evbit[0] |= BIT_MASK(EV_LED);
1202 input_dev->ledbit[0] = BIT_MASK(LED_NUML) |
1203 BIT_MASK(LED_CAPSL) | BIT_MASK(LED_SCROLLL);
1204 }
1205
1206 if (atkbd->extra)
1207 input_dev->ledbit[0] |= BIT_MASK(LED_COMPOSE) |
1208 BIT_MASK(LED_SUSPEND) | BIT_MASK(LED_SLEEP) |
1209 BIT_MASK(LED_MUTE) | BIT_MASK(LED_MISC);
1210
1211 if (!atkbd->softrepeat) {
1212 input_dev->rep[REP_DELAY] = 250;
1213 input_dev->rep[REP_PERIOD] = 33;
1214 }
1215
1216 input_dev->mscbit[0] = atkbd->softraw ? BIT_MASK(MSC_SCAN) :
1217 BIT_MASK(MSC_RAW) | BIT_MASK(MSC_SCAN);
1218
1219 if (atkbd->scroll) {
1220 input_dev->evbit[0] |= BIT_MASK(EV_REL);
1221 input_dev->relbit[0] = BIT_MASK(REL_WHEEL) |
1222 BIT_MASK(REL_HWHEEL);
1223 __set_bit(BTN_MIDDLE, input_dev->keybit);
1224 }
1225
1226 input_dev->keycode = atkbd->keycode;
1227 input_dev->keycodesize = sizeof(unsigned short);
1228 input_dev->keycodemax = ARRAY_SIZE(atkbd_set2_keycode);
1229
1230 for (i = 0; i < ATKBD_KEYMAP_SIZE; i++) {
1231 if (atkbd->keycode[i] != KEY_RESERVED &&
1232 atkbd->keycode[i] != ATKBD_KEY_NULL &&
1233 atkbd->keycode[i] < ATKBD_SPECIAL) {
1234 __set_bit(atkbd->keycode[i], input_dev->keybit);
1235 }
1236 }
1237 }
1238
atkbd_parse_fwnode_data(struct serio * serio)1239 static void atkbd_parse_fwnode_data(struct serio *serio)
1240 {
1241 struct atkbd *atkbd = serio_get_drvdata(serio);
1242 struct device *dev = &serio->dev;
1243 int n;
1244
1245 /* Parse "function-row-physmap" property */
1246 n = device_property_count_u32(dev, "function-row-physmap");
1247 if (n > 0 && n <= MAX_FUNCTION_ROW_KEYS &&
1248 !device_property_read_u32_array(dev, "function-row-physmap",
1249 atkbd->function_row_physmap, n)) {
1250 atkbd->num_function_row_keys = n;
1251 dev_dbg(dev, "FW reported %d function-row key locations\n", n);
1252 }
1253 }
1254
1255 /*
1256 * atkbd_connect() is called when the serio module finds an interface
1257 * that isn't handled yet by an appropriate device driver. We check if
1258 * there is an AT keyboard out there and if yes, we register ourselves
1259 * to the input module.
1260 */
1261
atkbd_connect(struct serio * serio,struct serio_driver * drv)1262 static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
1263 {
1264 struct atkbd *atkbd;
1265 struct input_dev *dev;
1266 int err = -ENOMEM;
1267
1268 atkbd = kzalloc(sizeof(struct atkbd), GFP_KERNEL);
1269 dev = input_allocate_device();
1270 if (!atkbd || !dev)
1271 goto fail1;
1272
1273 atkbd->dev = dev;
1274 ps2_init(&atkbd->ps2dev, serio);
1275 INIT_DELAYED_WORK(&atkbd->event_work, atkbd_event_work);
1276 mutex_init(&atkbd->mutex);
1277
1278 switch (serio->id.type) {
1279
1280 case SERIO_8042_XL:
1281 atkbd->translated = true;
1282 fallthrough;
1283
1284 case SERIO_8042:
1285 if (serio->write)
1286 atkbd->write = true;
1287 break;
1288 }
1289
1290 atkbd->softraw = atkbd_softraw;
1291 atkbd->softrepeat = atkbd_softrepeat;
1292 atkbd->scroll = atkbd_scroll;
1293
1294 if (atkbd->softrepeat)
1295 atkbd->softraw = true;
1296
1297 serio_set_drvdata(serio, atkbd);
1298
1299 err = serio_open(serio, drv);
1300 if (err)
1301 goto fail2;
1302
1303 if (atkbd->write) {
1304
1305 if (atkbd_probe(atkbd)) {
1306 err = -ENODEV;
1307 goto fail3;
1308 }
1309
1310 atkbd->set = atkbd_select_set(atkbd, atkbd_set, atkbd_extra);
1311 atkbd_reset_state(atkbd);
1312
1313 } else {
1314 atkbd->set = 2;
1315 atkbd->id = 0xab00;
1316 }
1317
1318 atkbd_parse_fwnode_data(serio);
1319
1320 atkbd_set_keycode_table(atkbd);
1321 atkbd_set_device_attrs(atkbd);
1322
1323 err = sysfs_create_group(&serio->dev.kobj, &atkbd_attribute_group);
1324 if (err)
1325 goto fail3;
1326
1327 atkbd_enable(atkbd);
1328 if (serio->write)
1329 atkbd_activate(atkbd);
1330
1331 err = input_register_device(atkbd->dev);
1332 if (err)
1333 goto fail4;
1334
1335 return 0;
1336
1337 fail4: sysfs_remove_group(&serio->dev.kobj, &atkbd_attribute_group);
1338 fail3: serio_close(serio);
1339 fail2: serio_set_drvdata(serio, NULL);
1340 fail1: input_free_device(dev);
1341 kfree(atkbd);
1342 return err;
1343 }
1344
1345 /*
1346 * atkbd_reconnect() tries to restore keyboard into a sane state and is
1347 * most likely called on resume.
1348 */
1349
atkbd_reconnect(struct serio * serio)1350 static int atkbd_reconnect(struct serio *serio)
1351 {
1352 struct atkbd *atkbd = serio_get_drvdata(serio);
1353 struct serio_driver *drv = serio->drv;
1354 int retval = -1;
1355
1356 if (!atkbd || !drv) {
1357 dev_dbg(&serio->dev,
1358 "reconnect request, but serio is disconnected, ignoring...\n");
1359 return -1;
1360 }
1361
1362 mutex_lock(&atkbd->mutex);
1363
1364 atkbd_disable(atkbd);
1365
1366 if (atkbd->write) {
1367 if (atkbd_probe(atkbd))
1368 goto out;
1369
1370 if (atkbd->set != atkbd_select_set(atkbd, atkbd->set, atkbd->extra))
1371 goto out;
1372
1373 /*
1374 * Restore LED state and repeat rate. While input core
1375 * will do this for us at resume time reconnect may happen
1376 * because user requested it via sysfs or simply because
1377 * keyboard was unplugged and plugged in again so we need
1378 * to do it ourselves here.
1379 */
1380 atkbd_set_leds(atkbd);
1381 if (!atkbd->softrepeat)
1382 atkbd_set_repeat_rate(atkbd);
1383
1384 }
1385
1386 /*
1387 * Reset our state machine in case reconnect happened in the middle
1388 * of multi-byte scancode.
1389 */
1390 atkbd->xl_bit = 0;
1391 atkbd->emul = 0;
1392
1393 atkbd_enable(atkbd);
1394 if (atkbd->write)
1395 atkbd_activate(atkbd);
1396
1397 retval = 0;
1398
1399 out:
1400 mutex_unlock(&atkbd->mutex);
1401 return retval;
1402 }
1403
1404 static const struct serio_device_id atkbd_serio_ids[] = {
1405 {
1406 .type = SERIO_8042,
1407 .proto = SERIO_ANY,
1408 .id = SERIO_ANY,
1409 .extra = SERIO_ANY,
1410 },
1411 {
1412 .type = SERIO_8042_XL,
1413 .proto = SERIO_ANY,
1414 .id = SERIO_ANY,
1415 .extra = SERIO_ANY,
1416 },
1417 {
1418 .type = SERIO_RS232,
1419 .proto = SERIO_PS2SER,
1420 .id = SERIO_ANY,
1421 .extra = SERIO_ANY,
1422 },
1423 { 0 }
1424 };
1425
1426 MODULE_DEVICE_TABLE(serio, atkbd_serio_ids);
1427
1428 static struct serio_driver atkbd_drv = {
1429 .driver = {
1430 .name = "atkbd",
1431 },
1432 .description = DRIVER_DESC,
1433 .id_table = atkbd_serio_ids,
1434 .interrupt = atkbd_interrupt,
1435 .connect = atkbd_connect,
1436 .reconnect = atkbd_reconnect,
1437 .disconnect = atkbd_disconnect,
1438 .cleanup = atkbd_cleanup,
1439 };
1440
atkbd_attr_show_helper(struct device * dev,char * buf,ssize_t (* handler)(struct atkbd *,char *))1441 static ssize_t atkbd_attr_show_helper(struct device *dev, char *buf,
1442 ssize_t (*handler)(struct atkbd *, char *))
1443 {
1444 struct serio *serio = to_serio_port(dev);
1445 struct atkbd *atkbd = serio_get_drvdata(serio);
1446
1447 return handler(atkbd, buf);
1448 }
1449
atkbd_attr_set_helper(struct device * dev,const char * buf,size_t count,ssize_t (* handler)(struct atkbd *,const char *,size_t))1450 static ssize_t atkbd_attr_set_helper(struct device *dev, const char *buf, size_t count,
1451 ssize_t (*handler)(struct atkbd *, const char *, size_t))
1452 {
1453 struct serio *serio = to_serio_port(dev);
1454 struct atkbd *atkbd = serio_get_drvdata(serio);
1455 int retval;
1456
1457 retval = mutex_lock_interruptible(&atkbd->mutex);
1458 if (retval)
1459 return retval;
1460
1461 atkbd_disable(atkbd);
1462 retval = handler(atkbd, buf, count);
1463 atkbd_enable(atkbd);
1464
1465 mutex_unlock(&atkbd->mutex);
1466
1467 return retval;
1468 }
1469
atkbd_show_extra(struct atkbd * atkbd,char * buf)1470 static ssize_t atkbd_show_extra(struct atkbd *atkbd, char *buf)
1471 {
1472 return sprintf(buf, "%d\n", atkbd->extra ? 1 : 0);
1473 }
1474
atkbd_set_extra(struct atkbd * atkbd,const char * buf,size_t count)1475 static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t count)
1476 {
1477 struct input_dev *old_dev, *new_dev;
1478 unsigned int value;
1479 int err;
1480 bool old_extra;
1481 unsigned char old_set;
1482
1483 if (!atkbd->write)
1484 return -EIO;
1485
1486 err = kstrtouint(buf, 10, &value);
1487 if (err)
1488 return err;
1489
1490 if (value > 1)
1491 return -EINVAL;
1492
1493 if (atkbd->extra != value) {
1494 /*
1495 * Since device's properties will change we need to
1496 * unregister old device. But allocate and register
1497 * new one first to make sure we have it.
1498 */
1499 old_dev = atkbd->dev;
1500 old_extra = atkbd->extra;
1501 old_set = atkbd->set;
1502
1503 new_dev = input_allocate_device();
1504 if (!new_dev)
1505 return -ENOMEM;
1506
1507 atkbd->dev = new_dev;
1508 atkbd->set = atkbd_select_set(atkbd, atkbd->set, value);
1509 atkbd_reset_state(atkbd);
1510 atkbd_activate(atkbd);
1511 atkbd_set_keycode_table(atkbd);
1512 atkbd_set_device_attrs(atkbd);
1513
1514 err = input_register_device(atkbd->dev);
1515 if (err) {
1516 input_free_device(new_dev);
1517
1518 atkbd->dev = old_dev;
1519 atkbd->set = atkbd_select_set(atkbd, old_set, old_extra);
1520 atkbd_set_keycode_table(atkbd);
1521 atkbd_set_device_attrs(atkbd);
1522
1523 return err;
1524 }
1525 input_unregister_device(old_dev);
1526
1527 }
1528 return count;
1529 }
1530
atkbd_show_force_release(struct atkbd * atkbd,char * buf)1531 static ssize_t atkbd_show_force_release(struct atkbd *atkbd, char *buf)
1532 {
1533 size_t len = scnprintf(buf, PAGE_SIZE - 1, "%*pbl",
1534 ATKBD_KEYMAP_SIZE, atkbd->force_release_mask);
1535
1536 buf[len++] = '\n';
1537 buf[len] = '\0';
1538
1539 return len;
1540 }
1541
atkbd_set_force_release(struct atkbd * atkbd,const char * buf,size_t count)1542 static ssize_t atkbd_set_force_release(struct atkbd *atkbd,
1543 const char *buf, size_t count)
1544 {
1545 /* 64 bytes on stack should be acceptable */
1546 DECLARE_BITMAP(new_mask, ATKBD_KEYMAP_SIZE);
1547 int err;
1548
1549 err = bitmap_parselist(buf, new_mask, ATKBD_KEYMAP_SIZE);
1550 if (err)
1551 return err;
1552
1553 memcpy(atkbd->force_release_mask, new_mask, sizeof(atkbd->force_release_mask));
1554 return count;
1555 }
1556
1557
atkbd_show_scroll(struct atkbd * atkbd,char * buf)1558 static ssize_t atkbd_show_scroll(struct atkbd *atkbd, char *buf)
1559 {
1560 return sprintf(buf, "%d\n", atkbd->scroll ? 1 : 0);
1561 }
1562
atkbd_set_scroll(struct atkbd * atkbd,const char * buf,size_t count)1563 static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t count)
1564 {
1565 struct input_dev *old_dev, *new_dev;
1566 unsigned int value;
1567 int err;
1568 bool old_scroll;
1569
1570 err = kstrtouint(buf, 10, &value);
1571 if (err)
1572 return err;
1573
1574 if (value > 1)
1575 return -EINVAL;
1576
1577 if (atkbd->scroll != value) {
1578 old_dev = atkbd->dev;
1579 old_scroll = atkbd->scroll;
1580
1581 new_dev = input_allocate_device();
1582 if (!new_dev)
1583 return -ENOMEM;
1584
1585 atkbd->dev = new_dev;
1586 atkbd->scroll = value;
1587 atkbd_set_keycode_table(atkbd);
1588 atkbd_set_device_attrs(atkbd);
1589
1590 err = input_register_device(atkbd->dev);
1591 if (err) {
1592 input_free_device(new_dev);
1593
1594 atkbd->scroll = old_scroll;
1595 atkbd->dev = old_dev;
1596 atkbd_set_keycode_table(atkbd);
1597 atkbd_set_device_attrs(atkbd);
1598
1599 return err;
1600 }
1601 input_unregister_device(old_dev);
1602 }
1603 return count;
1604 }
1605
atkbd_show_set(struct atkbd * atkbd,char * buf)1606 static ssize_t atkbd_show_set(struct atkbd *atkbd, char *buf)
1607 {
1608 return sprintf(buf, "%d\n", atkbd->set);
1609 }
1610
atkbd_set_set(struct atkbd * atkbd,const char * buf,size_t count)1611 static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
1612 {
1613 struct input_dev *old_dev, *new_dev;
1614 unsigned int value;
1615 int err;
1616 unsigned char old_set;
1617 bool old_extra;
1618
1619 if (!atkbd->write)
1620 return -EIO;
1621
1622 err = kstrtouint(buf, 10, &value);
1623 if (err)
1624 return err;
1625
1626 if (value != 2 && value != 3)
1627 return -EINVAL;
1628
1629 if (atkbd->set != value) {
1630 old_dev = atkbd->dev;
1631 old_extra = atkbd->extra;
1632 old_set = atkbd->set;
1633
1634 new_dev = input_allocate_device();
1635 if (!new_dev)
1636 return -ENOMEM;
1637
1638 atkbd->dev = new_dev;
1639 atkbd->set = atkbd_select_set(atkbd, value, atkbd->extra);
1640 atkbd_reset_state(atkbd);
1641 atkbd_activate(atkbd);
1642 atkbd_set_keycode_table(atkbd);
1643 atkbd_set_device_attrs(atkbd);
1644
1645 err = input_register_device(atkbd->dev);
1646 if (err) {
1647 input_free_device(new_dev);
1648
1649 atkbd->dev = old_dev;
1650 atkbd->set = atkbd_select_set(atkbd, old_set, old_extra);
1651 atkbd_set_keycode_table(atkbd);
1652 atkbd_set_device_attrs(atkbd);
1653
1654 return err;
1655 }
1656 input_unregister_device(old_dev);
1657 }
1658 return count;
1659 }
1660
atkbd_show_softrepeat(struct atkbd * atkbd,char * buf)1661 static ssize_t atkbd_show_softrepeat(struct atkbd *atkbd, char *buf)
1662 {
1663 return sprintf(buf, "%d\n", atkbd->softrepeat ? 1 : 0);
1664 }
1665
atkbd_set_softrepeat(struct atkbd * atkbd,const char * buf,size_t count)1666 static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t count)
1667 {
1668 struct input_dev *old_dev, *new_dev;
1669 unsigned int value;
1670 int err;
1671 bool old_softrepeat, old_softraw;
1672
1673 if (!atkbd->write)
1674 return -EIO;
1675
1676 err = kstrtouint(buf, 10, &value);
1677 if (err)
1678 return err;
1679
1680 if (value > 1)
1681 return -EINVAL;
1682
1683 if (atkbd->softrepeat != value) {
1684 old_dev = atkbd->dev;
1685 old_softrepeat = atkbd->softrepeat;
1686 old_softraw = atkbd->softraw;
1687
1688 new_dev = input_allocate_device();
1689 if (!new_dev)
1690 return -ENOMEM;
1691
1692 atkbd->dev = new_dev;
1693 atkbd->softrepeat = value;
1694 if (atkbd->softrepeat)
1695 atkbd->softraw = true;
1696 atkbd_set_device_attrs(atkbd);
1697
1698 err = input_register_device(atkbd->dev);
1699 if (err) {
1700 input_free_device(new_dev);
1701
1702 atkbd->dev = old_dev;
1703 atkbd->softrepeat = old_softrepeat;
1704 atkbd->softraw = old_softraw;
1705 atkbd_set_device_attrs(atkbd);
1706
1707 return err;
1708 }
1709 input_unregister_device(old_dev);
1710 }
1711 return count;
1712 }
1713
1714
atkbd_show_softraw(struct atkbd * atkbd,char * buf)1715 static ssize_t atkbd_show_softraw(struct atkbd *atkbd, char *buf)
1716 {
1717 return sprintf(buf, "%d\n", atkbd->softraw ? 1 : 0);
1718 }
1719
atkbd_set_softraw(struct atkbd * atkbd,const char * buf,size_t count)1720 static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t count)
1721 {
1722 struct input_dev *old_dev, *new_dev;
1723 unsigned int value;
1724 int err;
1725 bool old_softraw;
1726
1727 err = kstrtouint(buf, 10, &value);
1728 if (err)
1729 return err;
1730
1731 if (value > 1)
1732 return -EINVAL;
1733
1734 if (atkbd->softraw != value) {
1735 old_dev = atkbd->dev;
1736 old_softraw = atkbd->softraw;
1737
1738 new_dev = input_allocate_device();
1739 if (!new_dev)
1740 return -ENOMEM;
1741
1742 atkbd->dev = new_dev;
1743 atkbd->softraw = value;
1744 atkbd_set_device_attrs(atkbd);
1745
1746 err = input_register_device(atkbd->dev);
1747 if (err) {
1748 input_free_device(new_dev);
1749
1750 atkbd->dev = old_dev;
1751 atkbd->softraw = old_softraw;
1752 atkbd_set_device_attrs(atkbd);
1753
1754 return err;
1755 }
1756 input_unregister_device(old_dev);
1757 }
1758 return count;
1759 }
1760
atkbd_show_err_count(struct atkbd * atkbd,char * buf)1761 static ssize_t atkbd_show_err_count(struct atkbd *atkbd, char *buf)
1762 {
1763 return sprintf(buf, "%lu\n", atkbd->err_count);
1764 }
1765
atkbd_setup_forced_release(const struct dmi_system_id * id)1766 static int __init atkbd_setup_forced_release(const struct dmi_system_id *id)
1767 {
1768 atkbd_platform_fixup = atkbd_apply_forced_release_keylist;
1769 atkbd_platform_fixup_data = id->driver_data;
1770
1771 return 1;
1772 }
1773
atkbd_setup_scancode_fixup(const struct dmi_system_id * id)1774 static int __init atkbd_setup_scancode_fixup(const struct dmi_system_id *id)
1775 {
1776 atkbd_platform_scancode_fixup = id->driver_data;
1777
1778 return 1;
1779 }
1780
atkbd_deactivate_fixup(const struct dmi_system_id * id)1781 static int __init atkbd_deactivate_fixup(const struct dmi_system_id *id)
1782 {
1783 atkbd_skip_deactivate = true;
1784 return 1;
1785 }
1786
1787 /*
1788 * NOTE: do not add any more "force release" quirks to this table. The
1789 * task of adjusting list of keys that should be "released" automatically
1790 * by the driver is now delegated to userspace tools, such as udev, so
1791 * submit such quirks there.
1792 */
1793 static const struct dmi_system_id atkbd_dmi_quirk_table[] __initconst = {
1794 {
1795 .matches = {
1796 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1797 DMI_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
1798 },
1799 .callback = atkbd_setup_forced_release,
1800 .driver_data = atkbd_dell_laptop_forced_release_keys,
1801 },
1802 {
1803 .matches = {
1804 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
1805 DMI_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
1806 },
1807 .callback = atkbd_setup_forced_release,
1808 .driver_data = atkbd_dell_laptop_forced_release_keys,
1809 },
1810 {
1811 .matches = {
1812 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1813 DMI_MATCH(DMI_PRODUCT_NAME, "HP 2133"),
1814 },
1815 .callback = atkbd_setup_forced_release,
1816 .driver_data = atkbd_hp_forced_release_keys,
1817 },
1818 {
1819 .matches = {
1820 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1821 DMI_MATCH(DMI_PRODUCT_NAME, "Pavilion ZV6100"),
1822 },
1823 .callback = atkbd_setup_forced_release,
1824 .driver_data = atkbd_volume_forced_release_keys,
1825 },
1826 {
1827 .matches = {
1828 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1829 DMI_MATCH(DMI_PRODUCT_NAME, "Presario R4000"),
1830 },
1831 .callback = atkbd_setup_forced_release,
1832 .driver_data = atkbd_volume_forced_release_keys,
1833 },
1834 {
1835 .matches = {
1836 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1837 DMI_MATCH(DMI_PRODUCT_NAME, "Presario R4100"),
1838 },
1839 .callback = atkbd_setup_forced_release,
1840 .driver_data = atkbd_volume_forced_release_keys,
1841 },
1842 {
1843 .matches = {
1844 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1845 DMI_MATCH(DMI_PRODUCT_NAME, "Presario R4200"),
1846 },
1847 .callback = atkbd_setup_forced_release,
1848 .driver_data = atkbd_volume_forced_release_keys,
1849 },
1850 {
1851 /* Inventec Symphony */
1852 .matches = {
1853 DMI_MATCH(DMI_SYS_VENDOR, "INVENTEC"),
1854 DMI_MATCH(DMI_PRODUCT_NAME, "SYMPHONY 6.0/7.0"),
1855 },
1856 .callback = atkbd_setup_forced_release,
1857 .driver_data = atkbd_volume_forced_release_keys,
1858 },
1859 {
1860 /* Samsung NC10 */
1861 .matches = {
1862 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1863 DMI_MATCH(DMI_PRODUCT_NAME, "NC10"),
1864 },
1865 .callback = atkbd_setup_forced_release,
1866 .driver_data = atkbd_samsung_forced_release_keys,
1867 },
1868 {
1869 /* Samsung NC20 */
1870 .matches = {
1871 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1872 DMI_MATCH(DMI_PRODUCT_NAME, "NC20"),
1873 },
1874 .callback = atkbd_setup_forced_release,
1875 .driver_data = atkbd_samsung_forced_release_keys,
1876 },
1877 {
1878 /* Samsung SQ45S70S */
1879 .matches = {
1880 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1881 DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
1882 },
1883 .callback = atkbd_setup_forced_release,
1884 .driver_data = atkbd_samsung_forced_release_keys,
1885 },
1886 {
1887 /* Fujitsu Amilo PA 1510 */
1888 .matches = {
1889 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1890 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pa 1510"),
1891 },
1892 .callback = atkbd_setup_forced_release,
1893 .driver_data = atkbd_volume_forced_release_keys,
1894 },
1895 {
1896 /* Fujitsu Amilo Pi 3525 */
1897 .matches = {
1898 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1899 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pi 3525"),
1900 },
1901 .callback = atkbd_setup_forced_release,
1902 .driver_data = atkbd_amilo_pi3525_forced_release_keys,
1903 },
1904 {
1905 /* Fujitsu Amilo Xi 3650 */
1906 .matches = {
1907 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1908 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Xi 3650"),
1909 },
1910 .callback = atkbd_setup_forced_release,
1911 .driver_data = atkbd_amilo_xi3650_forced_release_keys,
1912 },
1913 {
1914 .matches = {
1915 DMI_MATCH(DMI_SYS_VENDOR, "Soltech Corporation"),
1916 DMI_MATCH(DMI_PRODUCT_NAME, "TA12"),
1917 },
1918 .callback = atkbd_setup_forced_release,
1919 .driver_data = atkdb_soltech_ta12_forced_release_keys,
1920 },
1921 {
1922 /* OQO Model 01+ */
1923 .matches = {
1924 DMI_MATCH(DMI_SYS_VENDOR, "OQO"),
1925 DMI_MATCH(DMI_PRODUCT_NAME, "ZEPTO"),
1926 },
1927 .callback = atkbd_setup_scancode_fixup,
1928 .driver_data = atkbd_oqo_01plus_scancode_fixup,
1929 },
1930 {
1931 .matches = {
1932 DMI_MATCH(DMI_SYS_VENDOR, "LG Electronics"),
1933 },
1934 .callback = atkbd_deactivate_fixup,
1935 },
1936 { }
1937 };
1938
atkbd_init(void)1939 static int __init atkbd_init(void)
1940 {
1941 dmi_check_system(atkbd_dmi_quirk_table);
1942
1943 return serio_register_driver(&atkbd_drv);
1944 }
1945
atkbd_exit(void)1946 static void __exit atkbd_exit(void)
1947 {
1948 serio_unregister_driver(&atkbd_drv);
1949 }
1950
1951 module_init(atkbd_init);
1952 module_exit(atkbd_exit);
1953