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