1 // SPDX-License-Identifier: GPL-2.0-only
3 * AT and PS/2 keyboard driver
5 * Copyright (c) 1999-2002 Vojtech Pavlik
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
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>
29 #define DRIVER_DESC "AT and PS/2 keyboard driver"
31 MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
32 MODULE_DESCRIPTION(DRIVER_DESC);
33 MODULE_LICENSE("GPL");
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)");
39 #if defined(__i386__) || defined(__x86_64__) || defined(__hppa__)
40 static bool atkbd_reset;
42 static bool atkbd_reset = true;
44 module_param_named(reset, atkbd_reset, bool, 0);
45 MODULE_PARM_DESC(reset, "Reset keyboard during initialization");
47 static bool atkbd_softrepeat;
48 module_param_named(softrepeat, atkbd_softrepeat, bool, 0);
49 MODULE_PARM_DESC(softrepeat, "Use software keyboard repeat");
51 static bool atkbd_softraw = true;
52 module_param_named(softraw, atkbd_softraw, bool, 0);
53 MODULE_PARM_DESC(softraw, "Use software generated rawmode");
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");
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");
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");
67 #define MAX_FUNCTION_ROW_KEYS 24
69 #define SCANCODE(keymap) ((keymap >> 16) & 0xFFFF)
70 #define KEYCODE(keymap) (keymap & 0xFFFF)
73 * Scancode to keycode tables. These are just the default setting, and
74 * are loadable via a userland utility.
77 #define ATKBD_KEYMAP_SIZE 512
79 static const unsigned short atkbd_set2_keycode[ATKBD_KEYMAP_SIZE] = {
81 #ifdef CONFIG_KEYBOARD_ATKBD_HP_KEYCODES
83 /* XXX: need a more general approach */
85 #include "hpps2atkbd.h" /* include the keyboard scancodes */
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,
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,
110 static const unsigned short atkbd_set3_keycode[ATKBD_KEYMAP_SIZE] = {
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,
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,
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
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
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
163 #define ATKBD_KEY_UNKNOWN 0
164 #define ATKBD_KEY_NULL 255
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
174 #define ATKBD_SPECIAL ATKBD_SCR_RIGHT
176 #define ATKBD_LED_EVENT_BIT 0
177 #define ATKBD_REP_EVENT_BIT 1
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
186 static const struct {
187 unsigned short keycode;
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 },
200 * The atkbd control structure
205 struct ps2dev ps2dev;
206 struct input_dev *dev;
208 /* Written only during init */
213 unsigned short keycode[ATKBD_KEYMAP_SIZE];
214 DECLARE_BITMAP(force_release_mask, ATKBD_KEYMAP_SIZE);
224 /* Accessed only from interrupt */
228 unsigned long xl_bit;
231 unsigned long err_count;
233 struct delayed_work event_work;
234 unsigned long event_jiffies;
235 unsigned long event_mask;
237 /* Serializes reconnect(), attr->set() and event work */
240 u32 function_row_physmap[MAX_FUNCTION_ROW_KEYS];
241 int num_function_row_keys;
245 * System-specific keymap fixup routine
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);
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.
255 static bool atkbd_skip_deactivate;
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) \
267 return atkbd_attr_show_helper(d, b, atkbd_show_##_name); \
269 static ssize_t atkbd_do_set_##_name(struct device *d, \
270 struct device_attribute *attr, const char *b, size_t s) \
272 return atkbd_attr_set_helper(d, b, s, atkbd_set_##_name); \
274 static struct device_attribute atkbd_attr_##_name = \
275 __ATTR(_name, S_IWUSR | S_IRUGO, atkbd_do_show_##_name, atkbd_do_set_##_name);
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);
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) \
289 return atkbd_attr_show_helper(d, b, atkbd_show_##_name); \
291 static struct device_attribute atkbd_attr_##_name = \
292 __ATTR(_name, S_IRUGO, atkbd_do_show_##_name, NULL);
294 ATKBD_DEFINE_RO_ATTR(err_count);
295 ATKBD_DEFINE_RO_ATTR(function_row_physmap);
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,
309 static ssize_t atkbd_show_function_row_physmap(struct atkbd *atkbd, char *buf)
314 if (!atkbd->num_function_row_keys)
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");
324 static umode_t atkbd_attr_is_visible(struct kobject *kobj,
325 struct attribute *attr, int i)
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);
331 if (attr == &atkbd_attr_function_row_physmap.attr &&
332 !atkbd->num_function_row_keys)
338 static struct attribute_group atkbd_attribute_group = {
339 .attrs = atkbd_attributes,
340 .is_visible = atkbd_attr_is_visible,
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,
349 * Checks if we should mangle the scancode to extract 'release' bit
350 * in translated mode.
352 static bool atkbd_need_xlate(unsigned long xl_bit, unsigned char code)
356 if (code == ATKBD_RET_EMUL0 || code == ATKBD_RET_EMUL1)
359 for (i = 0; i < ARRAY_SIZE(xl_table); i++)
360 if (code == xl_table[i])
361 return test_bit(i, &xl_bit);
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.
371 static void atkbd_calculate_xl_bit(struct atkbd *atkbd, unsigned char code)
375 for (i = 0; i < ARRAY_SIZE(xl_table); i++) {
376 if (!((code ^ xl_table[i]) & 0x7f)) {
378 __clear_bit(i, &atkbd->xl_bit);
380 __set_bit(i, &atkbd->xl_bit);
387 * Encode the scancode, 0xe0 prefix, and high bit into a single integer,
388 * keeping kernel 2.4 compatibility for set 2
390 static unsigned int atkbd_compat_scancode(struct atkbd *atkbd, unsigned int code)
392 if (atkbd->set == 3) {
393 if (atkbd->emul == 1)
396 code = (code & 0x7f) | ((code & 0x80) << 1);
397 if (atkbd->emul == 1)
405 * atkbd_interrupt(). Here takes place processing of data received from
406 * the keyboard into events.
409 static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
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;
417 unsigned short keycode;
419 dev_dbg(&serio->dev, "Received %02x flags %02x\n", data, flags);
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;
429 if (!flags && data == ATKBD_RET_ACK)
430 atkbd->resend = false;
433 if (unlikely(atkbd->ps2dev.flags & PS2_FLAG_ACK))
434 if (ps2_handle_ack(&atkbd->ps2dev, data))
437 if (unlikely(atkbd->ps2dev.flags & PS2_FLAG_CMD))
438 if (ps2_handle_response(&atkbd->ps2dev, data))
441 pm_wakeup_event(&serio->dev, 0);
446 input_event(dev, EV_MSC, MSC_RAW, code);
448 if (atkbd_platform_scancode_fixup)
449 code = atkbd_platform_scancode_fixup(atkbd, code);
451 if (atkbd->translated) {
453 if (atkbd->emul || atkbd_need_xlate(atkbd->xl_bit, code)) {
454 atkbd->release = code >> 7;
459 atkbd_calculate_xl_bit(atkbd, data);
464 atkbd->enabled = false;
465 serio_reconnect(atkbd->ps2dev.serio);
467 case ATKBD_RET_EMUL0:
470 case ATKBD_RET_EMUL1:
473 case ATKBD_RET_RELEASE:
474 atkbd->release = true;
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);
486 dev_dbg(&serio->dev, "Keyboard on %s reports too many keys pressed.\n",
491 code = atkbd_compat_scancode(atkbd, code);
493 if (atkbd->emul && --atkbd->emul)
496 keycode = atkbd->keycode[code];
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);
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);
528 case ATKBD_SCR_CLICK:
529 click = !atkbd->release;
534 case ATKBD_SCR_RIGHT:
538 if (atkbd->release) {
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;
547 atkbd->time = jiffies + msecs_to_jiffies(dev->rep[REP_DELAY]) / 2;
550 input_event(dev, EV_KEY, keycode, value);
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);
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);
569 atkbd->release = false;
574 static int atkbd_set_repeat_rate(struct atkbd *atkbd)
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 };
582 struct input_dev *dev = atkbd->dev;
586 while (i < ARRAY_SIZE(period) - 1 && period[i] < dev->rep[REP_PERIOD])
588 dev->rep[REP_PERIOD] = period[i];
590 while (j < ARRAY_SIZE(delay) - 1 && delay[j] < dev->rep[REP_DELAY])
592 dev->rep[REP_DELAY] = delay[j];
594 param = i | (j << 5);
595 return ps2_command(&atkbd->ps2dev, ¶m, ATKBD_CMD_SETREP);
598 static int atkbd_set_leds(struct atkbd *atkbd)
600 struct input_dev *dev = atkbd->dev;
601 unsigned char param[2];
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))
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))
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
629 static void atkbd_event_work(struct work_struct *work)
631 struct atkbd *atkbd = container_of(work, struct atkbd, event_work.work);
633 mutex_lock(&atkbd->mutex);
635 if (!atkbd->enabled) {
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.
642 schedule_delayed_work(&atkbd->event_work,
643 msecs_to_jiffies(100));
645 if (test_and_clear_bit(ATKBD_LED_EVENT_BIT, &atkbd->event_mask))
646 atkbd_set_leds(atkbd);
648 if (test_and_clear_bit(ATKBD_REP_EVENT_BIT, &atkbd->event_mask))
649 atkbd_set_repeat_rate(atkbd);
652 mutex_unlock(&atkbd->mutex);
656 * Schedule switch for execution. We need to throttle requests,
657 * otherwise keyboard may become unresponsive.
659 static void atkbd_schedule_event_work(struct atkbd *atkbd, int event_bit)
661 unsigned long delay = msecs_to_jiffies(50);
663 if (time_after(jiffies, atkbd->event_jiffies + delay))
666 atkbd->event_jiffies = jiffies;
667 set_bit(event_bit, &atkbd->event_mask);
669 schedule_delayed_work(&atkbd->event_work, delay);
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.
678 static int atkbd_event(struct input_dev *dev,
679 unsigned int type, unsigned int code, int value)
681 struct atkbd *atkbd = input_get_drvdata(dev);
689 atkbd_schedule_event_work(atkbd, ATKBD_LED_EVENT_BIT);
693 if (!atkbd->softrepeat)
694 atkbd_schedule_event_work(atkbd, ATKBD_REP_EVENT_BIT);
703 * atkbd_enable() signals that interrupt handler is allowed to
704 * generate input events.
707 static inline void atkbd_enable(struct atkbd *atkbd)
709 serio_pause_rx(atkbd->ps2dev.serio);
710 atkbd->enabled = true;
711 serio_continue_rx(atkbd->ps2dev.serio);
715 * atkbd_disable() tells input handler that all incoming data except
716 * for ACKs and command response should be dropped.
719 static inline void atkbd_disable(struct atkbd *atkbd)
721 serio_pause_rx(atkbd->ps2dev.serio);
722 atkbd->enabled = false;
723 serio_continue_rx(atkbd->ps2dev.serio);
726 static int atkbd_activate(struct atkbd *atkbd)
728 struct ps2dev *ps2dev = &atkbd->ps2dev;
731 * Enable the keyboard to receive keystrokes.
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);
745 * atkbd_deactivate() resets and disables the keyboard from sending
749 static void atkbd_deactivate(struct atkbd *atkbd)
751 struct ps2dev *ps2dev = &atkbd->ps2dev;
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);
760 * atkbd_probe() probes for an AT keyboard on a serio port.
763 static int atkbd_probe(struct atkbd *atkbd)
765 struct ps2dev *ps2dev = &atkbd->ps2dev;
766 unsigned char param[2];
769 * Some systems, where the bit-twiddling when testing the io-lines of the
770 * controller may confuse the keyboard need a full reset of the keyboard. On
771 * these systems the BIOS also usually doesn't do it for us.
775 if (ps2_command(ps2dev, NULL, ATKBD_CMD_RESET_BAT))
776 dev_warn(&ps2dev->serio->dev,
777 "keyboard reset failed on %s\n",
778 ps2dev->serio->phys);
781 * Then we check the keyboard ID. We should get 0xab83 under normal conditions.
782 * Some keyboards report different values, but the first byte is always 0xab or
783 * 0xac. Some old AT keyboards don't report anything. If a mouse is connected, this
784 * should make sure we don't try to set the LEDs on it.
787 param[0] = param[1] = 0xa5; /* initialize with invalid values */
788 if (ps2_command(ps2dev, param, ATKBD_CMD_GETID)) {
791 * If the get ID command failed, we check if we can at least set the LEDs on
792 * the keyboard. This should work on every keyboard out there. It also turns
793 * the LEDs off, which we want anyway.
796 if (ps2_command(ps2dev, param, ATKBD_CMD_SETLEDS))
802 if (!ps2_is_keyboard_id(param[0]))
805 atkbd->id = (param[0] << 8) | param[1];
807 if (atkbd->id == 0xaca1 && atkbd->translated) {
808 dev_err(&ps2dev->serio->dev,
809 "NCD terminal keyboards are only supported on non-translating controllers. "
810 "Use i8042.direct=1 to disable translation.\n");
815 * Make sure nothing is coming from the keyboard and disturbs our
818 if (!atkbd_skip_deactivate)
819 atkbd_deactivate(atkbd);
825 * atkbd_select_set checks if a keyboard has a working Set 3 support, and
826 * sets it into that. Unfortunately there are keyboards that can be switched
827 * to Set 3, but don't work well in that (BTC Multimedia ...)
830 static int atkbd_select_set(struct atkbd *atkbd, int target_set, int allow_extra)
832 struct ps2dev *ps2dev = &atkbd->ps2dev;
833 unsigned char param[2];
835 atkbd->extra = false;
837 * For known special keyboards we can go ahead and set the correct set.
838 * We check for NCD PS/2 Sun, NorthGate OmniKey 101 and
839 * IBM RapidAccess / IBM EzButton / Chicony KBP-8993 keyboards.
842 if (atkbd->translated)
845 if (atkbd->id == 0xaca1) {
847 ps2_command(ps2dev, param, ATKBD_CMD_SSCANSET);
853 if (!ps2_command(ps2dev, param, ATKBD_CMD_EX_ENABLE)) {
859 if (atkbd_terminal) {
860 ps2_command(ps2dev, param, ATKBD_CMD_SETALL_MB);
867 if (!ps2_command(ps2dev, param, ATKBD_CMD_OK_GETID)) {
868 atkbd->id = param[0] << 8 | param[1];
873 if (ps2_command(ps2dev, param, ATKBD_CMD_SSCANSET))
877 if (ps2_command(ps2dev, param, ATKBD_CMD_GSCANSET))
882 if (ps2_command(ps2dev, param, ATKBD_CMD_SSCANSET))
886 ps2_command(ps2dev, param, ATKBD_CMD_SETALL_MBR);
891 static int atkbd_reset_state(struct atkbd *atkbd)
893 struct ps2dev *ps2dev = &atkbd->ps2dev;
894 unsigned char param[1];
897 * Set the LEDs to a predefined state (all off).
901 if (ps2_command(ps2dev, param, ATKBD_CMD_SETLEDS))
905 * Set autorepeat to fastest possible.
909 if (ps2_command(ps2dev, param, ATKBD_CMD_SETREP))
916 * atkbd_cleanup() restores the keyboard state so that BIOS is happy after a
920 static void atkbd_cleanup(struct serio *serio)
922 struct atkbd *atkbd = serio_get_drvdata(serio);
924 atkbd_disable(atkbd);
925 ps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_DEF);
930 * atkbd_disconnect() closes and frees.
933 static void atkbd_disconnect(struct serio *serio)
935 struct atkbd *atkbd = serio_get_drvdata(serio);
937 sysfs_remove_group(&serio->dev.kobj, &atkbd_attribute_group);
939 atkbd_disable(atkbd);
941 input_unregister_device(atkbd->dev);
944 * Make sure we don't have a command in flight.
945 * Note that since atkbd->enabled is false event work will keep
946 * rescheduling itself until it gets canceled and will not try
947 * accessing freed input device or serio port.
949 cancel_delayed_work_sync(&atkbd->event_work);
952 serio_set_drvdata(serio, NULL);
957 * generate release events for the keycodes given in data
959 static void atkbd_apply_forced_release_keylist(struct atkbd* atkbd,
962 const unsigned int *keys = data;
966 for (i = 0; keys[i] != -1U; i++)
967 __set_bit(keys[i], atkbd->force_release_mask);
971 * Most special keys (Fn+F?) on Dell laptops do not generate release
972 * events so we have to do it ourselves.
974 static unsigned int atkbd_dell_laptop_forced_release_keys[] = {
975 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8f, 0x93, -1U
979 * Perform fixup for HP system that doesn't generate release
980 * for its video switch
982 static unsigned int atkbd_hp_forced_release_keys[] = {
987 * Samsung NC10,NC20 with Fn+F? key release not working
989 static unsigned int atkbd_samsung_forced_release_keys[] = {
990 0x82, 0x83, 0x84, 0x86, 0x88, 0x89, 0xb3, 0xf7, 0xf9, -1U
994 * Amilo Pi 3525 key release for Fn+Volume keys not working
996 static unsigned int atkbd_amilo_pi3525_forced_release_keys[] = {
997 0x20, 0xa0, 0x2e, 0xae, 0x30, 0xb0, -1U
1001 * Amilo Xi 3650 key release for light touch bar not working
1003 static unsigned int atkbd_amilo_xi3650_forced_release_keys[] = {
1004 0x67, 0xed, 0x90, 0xa2, 0x99, 0xa4, 0xae, 0xb0, -1U
1008 * Soltech TA12 system with broken key release on volume keys and mute key
1010 static unsigned int atkdb_soltech_ta12_forced_release_keys[] = {
1011 0xa0, 0xae, 0xb0, -1U
1015 * Many notebooks don't send key release event for volume up/down
1016 * keys, with key list below common among them
1018 static unsigned int atkbd_volume_forced_release_keys[] = {
1023 * OQO 01+ multimedia keys (64--66) generate e0 6x upon release whereas
1024 * they should be generating e4-e6 (0x80 | code).
1026 static unsigned int atkbd_oqo_01plus_scancode_fixup(struct atkbd *atkbd,
1029 if (atkbd->translated && atkbd->emul == 1 &&
1030 (code == 0x64 || code == 0x65 || code == 0x66)) {
1038 static int atkbd_get_keymap_from_fwnode(struct atkbd *atkbd)
1040 struct device *dev = &atkbd->ps2dev.serio->dev;
1043 u16 scancode, keycode;
1045 /* Parse "linux,keymap" property */
1046 n = device_property_count_u32(dev, "linux,keymap");
1047 if (n <= 0 || n > ATKBD_KEYMAP_SIZE)
1050 ptr = kcalloc(n, sizeof(u32), GFP_KERNEL);
1054 if (device_property_read_u32_array(dev, "linux,keymap", ptr, n)) {
1055 dev_err(dev, "problem parsing FW keymap property\n");
1060 memset(atkbd->keycode, 0, sizeof(atkbd->keycode));
1061 for (i = 0; i < n; i++) {
1062 scancode = SCANCODE(ptr[i]);
1063 keycode = KEYCODE(ptr[i]);
1064 atkbd->keycode[scancode] = keycode;
1072 * atkbd_set_keycode_table() initializes keyboard's keycode table
1073 * according to the selected scancode set
1076 static void atkbd_set_keycode_table(struct atkbd *atkbd)
1078 struct device *dev = &atkbd->ps2dev.serio->dev;
1079 unsigned int scancode;
1082 memset(atkbd->keycode, 0, sizeof(atkbd->keycode));
1083 bitmap_zero(atkbd->force_release_mask, ATKBD_KEYMAP_SIZE);
1085 if (!atkbd_get_keymap_from_fwnode(atkbd)) {
1086 dev_dbg(dev, "Using FW keymap\n");
1087 } else if (atkbd->translated) {
1088 for (i = 0; i < 128; i++) {
1089 scancode = atkbd_unxlate_table[i];
1090 atkbd->keycode[i] = atkbd_set2_keycode[scancode];
1091 atkbd->keycode[i | 0x80] = atkbd_set2_keycode[scancode | 0x80];
1093 for (j = 0; j < ARRAY_SIZE(atkbd_scroll_keys); j++)
1094 if ((scancode | 0x80) == atkbd_scroll_keys[j].set2)
1095 atkbd->keycode[i | 0x80] = atkbd_scroll_keys[j].keycode;
1097 } else if (atkbd->set == 3) {
1098 memcpy(atkbd->keycode, atkbd_set3_keycode, sizeof(atkbd->keycode));
1100 memcpy(atkbd->keycode, atkbd_set2_keycode, sizeof(atkbd->keycode));
1103 for (i = 0; i < ARRAY_SIZE(atkbd_scroll_keys); i++) {
1104 scancode = atkbd_scroll_keys[i].set2;
1105 atkbd->keycode[scancode] = atkbd_scroll_keys[i].keycode;
1110 * HANGEUL and HANJA keys do not send release events so we need to
1111 * generate such events ourselves
1113 scancode = atkbd_compat_scancode(atkbd, ATKBD_RET_HANGEUL);
1114 atkbd->keycode[scancode] = KEY_HANGEUL;
1115 __set_bit(scancode, atkbd->force_release_mask);
1117 scancode = atkbd_compat_scancode(atkbd, ATKBD_RET_HANJA);
1118 atkbd->keycode[scancode] = KEY_HANJA;
1119 __set_bit(scancode, atkbd->force_release_mask);
1122 * Perform additional fixups
1124 if (atkbd_platform_fixup)
1125 atkbd_platform_fixup(atkbd, atkbd_platform_fixup_data);
1129 * atkbd_set_device_attrs() sets up keyboard's input device structure
1132 static void atkbd_set_device_attrs(struct atkbd *atkbd)
1134 struct input_dev *input_dev = atkbd->dev;
1138 snprintf(atkbd->name, sizeof(atkbd->name),
1139 "AT Set 2 Extra keyboard");
1141 snprintf(atkbd->name, sizeof(atkbd->name),
1142 "AT %s Set %d keyboard",
1143 atkbd->translated ? "Translated" : "Raw", atkbd->set);
1145 snprintf(atkbd->phys, sizeof(atkbd->phys),
1146 "%s/input0", atkbd->ps2dev.serio->phys);
1148 input_dev->name = atkbd->name;
1149 input_dev->phys = atkbd->phys;
1150 input_dev->id.bustype = BUS_I8042;
1151 input_dev->id.vendor = 0x0001;
1152 input_dev->id.product = atkbd->translated ? 1 : atkbd->set;
1153 input_dev->id.version = atkbd->id;
1154 input_dev->event = atkbd_event;
1155 input_dev->dev.parent = &atkbd->ps2dev.serio->dev;
1157 input_set_drvdata(input_dev, atkbd);
1159 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) |
1163 input_dev->evbit[0] |= BIT_MASK(EV_LED);
1164 input_dev->ledbit[0] = BIT_MASK(LED_NUML) |
1165 BIT_MASK(LED_CAPSL) | BIT_MASK(LED_SCROLLL);
1169 input_dev->ledbit[0] |= BIT_MASK(LED_COMPOSE) |
1170 BIT_MASK(LED_SUSPEND) | BIT_MASK(LED_SLEEP) |
1171 BIT_MASK(LED_MUTE) | BIT_MASK(LED_MISC);
1173 if (!atkbd->softrepeat) {
1174 input_dev->rep[REP_DELAY] = 250;
1175 input_dev->rep[REP_PERIOD] = 33;
1178 input_dev->mscbit[0] = atkbd->softraw ? BIT_MASK(MSC_SCAN) :
1179 BIT_MASK(MSC_RAW) | BIT_MASK(MSC_SCAN);
1181 if (atkbd->scroll) {
1182 input_dev->evbit[0] |= BIT_MASK(EV_REL);
1183 input_dev->relbit[0] = BIT_MASK(REL_WHEEL) |
1184 BIT_MASK(REL_HWHEEL);
1185 __set_bit(BTN_MIDDLE, input_dev->keybit);
1188 input_dev->keycode = atkbd->keycode;
1189 input_dev->keycodesize = sizeof(unsigned short);
1190 input_dev->keycodemax = ARRAY_SIZE(atkbd_set2_keycode);
1192 for (i = 0; i < ATKBD_KEYMAP_SIZE; i++) {
1193 if (atkbd->keycode[i] != KEY_RESERVED &&
1194 atkbd->keycode[i] != ATKBD_KEY_NULL &&
1195 atkbd->keycode[i] < ATKBD_SPECIAL) {
1196 __set_bit(atkbd->keycode[i], input_dev->keybit);
1201 static void atkbd_parse_fwnode_data(struct serio *serio)
1203 struct atkbd *atkbd = serio_get_drvdata(serio);
1204 struct device *dev = &serio->dev;
1207 /* Parse "function-row-physmap" property */
1208 n = device_property_count_u32(dev, "function-row-physmap");
1209 if (n > 0 && n <= MAX_FUNCTION_ROW_KEYS &&
1210 !device_property_read_u32_array(dev, "function-row-physmap",
1211 atkbd->function_row_physmap, n)) {
1212 atkbd->num_function_row_keys = n;
1213 dev_dbg(dev, "FW reported %d function-row key locations\n", n);
1218 * atkbd_connect() is called when the serio module finds an interface
1219 * that isn't handled yet by an appropriate device driver. We check if
1220 * there is an AT keyboard out there and if yes, we register ourselves
1221 * to the input module.
1224 static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
1226 struct atkbd *atkbd;
1227 struct input_dev *dev;
1230 atkbd = kzalloc(sizeof(struct atkbd), GFP_KERNEL);
1231 dev = input_allocate_device();
1236 ps2_init(&atkbd->ps2dev, serio);
1237 INIT_DELAYED_WORK(&atkbd->event_work, atkbd_event_work);
1238 mutex_init(&atkbd->mutex);
1240 switch (serio->id.type) {
1243 atkbd->translated = true;
1248 atkbd->write = true;
1252 atkbd->softraw = atkbd_softraw;
1253 atkbd->softrepeat = atkbd_softrepeat;
1254 atkbd->scroll = atkbd_scroll;
1256 if (atkbd->softrepeat)
1257 atkbd->softraw = true;
1259 serio_set_drvdata(serio, atkbd);
1261 err = serio_open(serio, drv);
1267 if (atkbd_probe(atkbd)) {
1272 atkbd->set = atkbd_select_set(atkbd, atkbd_set, atkbd_extra);
1273 atkbd_reset_state(atkbd);
1280 atkbd_parse_fwnode_data(serio);
1282 atkbd_set_keycode_table(atkbd);
1283 atkbd_set_device_attrs(atkbd);
1285 err = sysfs_create_group(&serio->dev.kobj, &atkbd_attribute_group);
1289 atkbd_enable(atkbd);
1291 atkbd_activate(atkbd);
1293 err = input_register_device(atkbd->dev);
1299 fail4: sysfs_remove_group(&serio->dev.kobj, &atkbd_attribute_group);
1300 fail3: serio_close(serio);
1301 fail2: serio_set_drvdata(serio, NULL);
1302 fail1: input_free_device(dev);
1308 * atkbd_reconnect() tries to restore keyboard into a sane state and is
1309 * most likely called on resume.
1312 static int atkbd_reconnect(struct serio *serio)
1314 struct atkbd *atkbd = serio_get_drvdata(serio);
1315 struct serio_driver *drv = serio->drv;
1318 if (!atkbd || !drv) {
1319 dev_dbg(&serio->dev,
1320 "reconnect request, but serio is disconnected, ignoring...\n");
1324 mutex_lock(&atkbd->mutex);
1326 atkbd_disable(atkbd);
1329 if (atkbd_probe(atkbd))
1332 if (atkbd->set != atkbd_select_set(atkbd, atkbd->set, atkbd->extra))
1336 * Restore LED state and repeat rate. While input core
1337 * will do this for us at resume time reconnect may happen
1338 * because user requested it via sysfs or simply because
1339 * keyboard was unplugged and plugged in again so we need
1340 * to do it ourselves here.
1342 atkbd_set_leds(atkbd);
1343 if (!atkbd->softrepeat)
1344 atkbd_set_repeat_rate(atkbd);
1349 * Reset our state machine in case reconnect happened in the middle
1350 * of multi-byte scancode.
1355 atkbd_enable(atkbd);
1357 atkbd_activate(atkbd);
1362 mutex_unlock(&atkbd->mutex);
1366 static const struct serio_device_id atkbd_serio_ids[] = {
1374 .type = SERIO_8042_XL,
1380 .type = SERIO_RS232,
1381 .proto = SERIO_PS2SER,
1388 MODULE_DEVICE_TABLE(serio, atkbd_serio_ids);
1390 static struct serio_driver atkbd_drv = {
1394 .description = DRIVER_DESC,
1395 .id_table = atkbd_serio_ids,
1396 .interrupt = atkbd_interrupt,
1397 .connect = atkbd_connect,
1398 .reconnect = atkbd_reconnect,
1399 .disconnect = atkbd_disconnect,
1400 .cleanup = atkbd_cleanup,
1403 static ssize_t atkbd_attr_show_helper(struct device *dev, char *buf,
1404 ssize_t (*handler)(struct atkbd *, char *))
1406 struct serio *serio = to_serio_port(dev);
1407 struct atkbd *atkbd = serio_get_drvdata(serio);
1409 return handler(atkbd, buf);
1412 static ssize_t atkbd_attr_set_helper(struct device *dev, const char *buf, size_t count,
1413 ssize_t (*handler)(struct atkbd *, const char *, size_t))
1415 struct serio *serio = to_serio_port(dev);
1416 struct atkbd *atkbd = serio_get_drvdata(serio);
1419 retval = mutex_lock_interruptible(&atkbd->mutex);
1423 atkbd_disable(atkbd);
1424 retval = handler(atkbd, buf, count);
1425 atkbd_enable(atkbd);
1427 mutex_unlock(&atkbd->mutex);
1432 static ssize_t atkbd_show_extra(struct atkbd *atkbd, char *buf)
1434 return sprintf(buf, "%d\n", atkbd->extra ? 1 : 0);
1437 static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t count)
1439 struct input_dev *old_dev, *new_dev;
1443 unsigned char old_set;
1448 err = kstrtouint(buf, 10, &value);
1455 if (atkbd->extra != value) {
1457 * Since device's properties will change we need to
1458 * unregister old device. But allocate and register
1459 * new one first to make sure we have it.
1461 old_dev = atkbd->dev;
1462 old_extra = atkbd->extra;
1463 old_set = atkbd->set;
1465 new_dev = input_allocate_device();
1469 atkbd->dev = new_dev;
1470 atkbd->set = atkbd_select_set(atkbd, atkbd->set, value);
1471 atkbd_reset_state(atkbd);
1472 atkbd_activate(atkbd);
1473 atkbd_set_keycode_table(atkbd);
1474 atkbd_set_device_attrs(atkbd);
1476 err = input_register_device(atkbd->dev);
1478 input_free_device(new_dev);
1480 atkbd->dev = old_dev;
1481 atkbd->set = atkbd_select_set(atkbd, old_set, old_extra);
1482 atkbd_set_keycode_table(atkbd);
1483 atkbd_set_device_attrs(atkbd);
1487 input_unregister_device(old_dev);
1493 static ssize_t atkbd_show_force_release(struct atkbd *atkbd, char *buf)
1495 size_t len = scnprintf(buf, PAGE_SIZE - 1, "%*pbl",
1496 ATKBD_KEYMAP_SIZE, atkbd->force_release_mask);
1504 static ssize_t atkbd_set_force_release(struct atkbd *atkbd,
1505 const char *buf, size_t count)
1507 /* 64 bytes on stack should be acceptable */
1508 DECLARE_BITMAP(new_mask, ATKBD_KEYMAP_SIZE);
1511 err = bitmap_parselist(buf, new_mask, ATKBD_KEYMAP_SIZE);
1515 memcpy(atkbd->force_release_mask, new_mask, sizeof(atkbd->force_release_mask));
1520 static ssize_t atkbd_show_scroll(struct atkbd *atkbd, char *buf)
1522 return sprintf(buf, "%d\n", atkbd->scroll ? 1 : 0);
1525 static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t count)
1527 struct input_dev *old_dev, *new_dev;
1532 err = kstrtouint(buf, 10, &value);
1539 if (atkbd->scroll != value) {
1540 old_dev = atkbd->dev;
1541 old_scroll = atkbd->scroll;
1543 new_dev = input_allocate_device();
1547 atkbd->dev = new_dev;
1548 atkbd->scroll = value;
1549 atkbd_set_keycode_table(atkbd);
1550 atkbd_set_device_attrs(atkbd);
1552 err = input_register_device(atkbd->dev);
1554 input_free_device(new_dev);
1556 atkbd->scroll = old_scroll;
1557 atkbd->dev = old_dev;
1558 atkbd_set_keycode_table(atkbd);
1559 atkbd_set_device_attrs(atkbd);
1563 input_unregister_device(old_dev);
1568 static ssize_t atkbd_show_set(struct atkbd *atkbd, char *buf)
1570 return sprintf(buf, "%d\n", atkbd->set);
1573 static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
1575 struct input_dev *old_dev, *new_dev;
1578 unsigned char old_set;
1584 err = kstrtouint(buf, 10, &value);
1588 if (value != 2 && value != 3)
1591 if (atkbd->set != value) {
1592 old_dev = atkbd->dev;
1593 old_extra = atkbd->extra;
1594 old_set = atkbd->set;
1596 new_dev = input_allocate_device();
1600 atkbd->dev = new_dev;
1601 atkbd->set = atkbd_select_set(atkbd, value, atkbd->extra);
1602 atkbd_reset_state(atkbd);
1603 atkbd_activate(atkbd);
1604 atkbd_set_keycode_table(atkbd);
1605 atkbd_set_device_attrs(atkbd);
1607 err = input_register_device(atkbd->dev);
1609 input_free_device(new_dev);
1611 atkbd->dev = old_dev;
1612 atkbd->set = atkbd_select_set(atkbd, old_set, old_extra);
1613 atkbd_set_keycode_table(atkbd);
1614 atkbd_set_device_attrs(atkbd);
1618 input_unregister_device(old_dev);
1623 static ssize_t atkbd_show_softrepeat(struct atkbd *atkbd, char *buf)
1625 return sprintf(buf, "%d\n", atkbd->softrepeat ? 1 : 0);
1628 static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t count)
1630 struct input_dev *old_dev, *new_dev;
1633 bool old_softrepeat, old_softraw;
1638 err = kstrtouint(buf, 10, &value);
1645 if (atkbd->softrepeat != value) {
1646 old_dev = atkbd->dev;
1647 old_softrepeat = atkbd->softrepeat;
1648 old_softraw = atkbd->softraw;
1650 new_dev = input_allocate_device();
1654 atkbd->dev = new_dev;
1655 atkbd->softrepeat = value;
1656 if (atkbd->softrepeat)
1657 atkbd->softraw = true;
1658 atkbd_set_device_attrs(atkbd);
1660 err = input_register_device(atkbd->dev);
1662 input_free_device(new_dev);
1664 atkbd->dev = old_dev;
1665 atkbd->softrepeat = old_softrepeat;
1666 atkbd->softraw = old_softraw;
1667 atkbd_set_device_attrs(atkbd);
1671 input_unregister_device(old_dev);
1677 static ssize_t atkbd_show_softraw(struct atkbd *atkbd, char *buf)
1679 return sprintf(buf, "%d\n", atkbd->softraw ? 1 : 0);
1682 static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t count)
1684 struct input_dev *old_dev, *new_dev;
1689 err = kstrtouint(buf, 10, &value);
1696 if (atkbd->softraw != value) {
1697 old_dev = atkbd->dev;
1698 old_softraw = atkbd->softraw;
1700 new_dev = input_allocate_device();
1704 atkbd->dev = new_dev;
1705 atkbd->softraw = value;
1706 atkbd_set_device_attrs(atkbd);
1708 err = input_register_device(atkbd->dev);
1710 input_free_device(new_dev);
1712 atkbd->dev = old_dev;
1713 atkbd->softraw = old_softraw;
1714 atkbd_set_device_attrs(atkbd);
1718 input_unregister_device(old_dev);
1723 static ssize_t atkbd_show_err_count(struct atkbd *atkbd, char *buf)
1725 return sprintf(buf, "%lu\n", atkbd->err_count);
1728 static int __init atkbd_setup_forced_release(const struct dmi_system_id *id)
1730 atkbd_platform_fixup = atkbd_apply_forced_release_keylist;
1731 atkbd_platform_fixup_data = id->driver_data;
1736 static int __init atkbd_setup_scancode_fixup(const struct dmi_system_id *id)
1738 atkbd_platform_scancode_fixup = id->driver_data;
1743 static int __init atkbd_deactivate_fixup(const struct dmi_system_id *id)
1745 atkbd_skip_deactivate = true;
1750 * NOTE: do not add any more "force release" quirks to this table. The
1751 * task of adjusting list of keys that should be "released" automatically
1752 * by the driver is now delegated to userspace tools, such as udev, so
1753 * submit such quirks there.
1755 static const struct dmi_system_id atkbd_dmi_quirk_table[] __initconst = {
1758 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1759 DMI_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
1761 .callback = atkbd_setup_forced_release,
1762 .driver_data = atkbd_dell_laptop_forced_release_keys,
1766 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
1767 DMI_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
1769 .callback = atkbd_setup_forced_release,
1770 .driver_data = atkbd_dell_laptop_forced_release_keys,
1774 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1775 DMI_MATCH(DMI_PRODUCT_NAME, "HP 2133"),
1777 .callback = atkbd_setup_forced_release,
1778 .driver_data = atkbd_hp_forced_release_keys,
1782 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1783 DMI_MATCH(DMI_PRODUCT_NAME, "Pavilion ZV6100"),
1785 .callback = atkbd_setup_forced_release,
1786 .driver_data = atkbd_volume_forced_release_keys,
1790 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1791 DMI_MATCH(DMI_PRODUCT_NAME, "Presario R4000"),
1793 .callback = atkbd_setup_forced_release,
1794 .driver_data = atkbd_volume_forced_release_keys,
1798 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1799 DMI_MATCH(DMI_PRODUCT_NAME, "Presario R4100"),
1801 .callback = atkbd_setup_forced_release,
1802 .driver_data = atkbd_volume_forced_release_keys,
1806 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1807 DMI_MATCH(DMI_PRODUCT_NAME, "Presario R4200"),
1809 .callback = atkbd_setup_forced_release,
1810 .driver_data = atkbd_volume_forced_release_keys,
1813 /* Inventec Symphony */
1815 DMI_MATCH(DMI_SYS_VENDOR, "INVENTEC"),
1816 DMI_MATCH(DMI_PRODUCT_NAME, "SYMPHONY 6.0/7.0"),
1818 .callback = atkbd_setup_forced_release,
1819 .driver_data = atkbd_volume_forced_release_keys,
1824 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1825 DMI_MATCH(DMI_PRODUCT_NAME, "NC10"),
1827 .callback = atkbd_setup_forced_release,
1828 .driver_data = atkbd_samsung_forced_release_keys,
1833 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1834 DMI_MATCH(DMI_PRODUCT_NAME, "NC20"),
1836 .callback = atkbd_setup_forced_release,
1837 .driver_data = atkbd_samsung_forced_release_keys,
1840 /* Samsung SQ45S70S */
1842 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1843 DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
1845 .callback = atkbd_setup_forced_release,
1846 .driver_data = atkbd_samsung_forced_release_keys,
1849 /* Fujitsu Amilo PA 1510 */
1851 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1852 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pa 1510"),
1854 .callback = atkbd_setup_forced_release,
1855 .driver_data = atkbd_volume_forced_release_keys,
1858 /* Fujitsu Amilo Pi 3525 */
1860 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1861 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pi 3525"),
1863 .callback = atkbd_setup_forced_release,
1864 .driver_data = atkbd_amilo_pi3525_forced_release_keys,
1867 /* Fujitsu Amilo Xi 3650 */
1869 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1870 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Xi 3650"),
1872 .callback = atkbd_setup_forced_release,
1873 .driver_data = atkbd_amilo_xi3650_forced_release_keys,
1877 DMI_MATCH(DMI_SYS_VENDOR, "Soltech Corporation"),
1878 DMI_MATCH(DMI_PRODUCT_NAME, "TA12"),
1880 .callback = atkbd_setup_forced_release,
1881 .driver_data = atkdb_soltech_ta12_forced_release_keys,
1886 DMI_MATCH(DMI_SYS_VENDOR, "OQO"),
1887 DMI_MATCH(DMI_PRODUCT_NAME, "ZEPTO"),
1889 .callback = atkbd_setup_scancode_fixup,
1890 .driver_data = atkbd_oqo_01plus_scancode_fixup,
1894 DMI_MATCH(DMI_SYS_VENDOR, "LG Electronics"),
1896 .callback = atkbd_deactivate_fixup,
1901 static int __init atkbd_init(void)
1903 dmi_check_system(atkbd_dmi_quirk_table);
1905 return serio_register_driver(&atkbd_drv);
1908 static void __exit atkbd_exit(void)
1910 serio_unregister_driver(&atkbd_drv);
1913 module_init(atkbd_init);
1914 module_exit(atkbd_exit);