11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * AT and PS/2 keyboard driver 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (c) 1999-2002 Vojtech Pavlik 51da177e4SLinus Torvalds */ 61da177e4SLinus Torvalds 71da177e4SLinus Torvalds /* 81da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify it 91da177e4SLinus Torvalds * under the terms of the GNU General Public License version 2 as published by 101da177e4SLinus Torvalds * the Free Software Foundation. 111da177e4SLinus Torvalds */ 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds /* 141da177e4SLinus Torvalds * This driver can handle standard AT keyboards and PS/2 keyboards in 151da177e4SLinus Torvalds * Translated and Raw Set 2 and Set 3, as well as AT keyboards on dumb 161da177e4SLinus Torvalds * input-only controllers and AT keyboards connected over a one way RS232 171da177e4SLinus Torvalds * converter. 181da177e4SLinus Torvalds */ 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds #include <linux/delay.h> 211da177e4SLinus Torvalds #include <linux/module.h> 221da177e4SLinus Torvalds #include <linux/slab.h> 231da177e4SLinus Torvalds #include <linux/interrupt.h> 241da177e4SLinus Torvalds #include <linux/init.h> 251da177e4SLinus Torvalds #include <linux/input.h> 261da177e4SLinus Torvalds #include <linux/serio.h> 271da177e4SLinus Torvalds #include <linux/workqueue.h> 281da177e4SLinus Torvalds #include <linux/libps2.h> 2933d3f07aSIngo Molnar #include <linux/mutex.h> 30554101e3SGiel de Nijs #include <linux/dmi.h> 311da177e4SLinus Torvalds 321da177e4SLinus Torvalds #define DRIVER_DESC "AT and PS/2 keyboard driver" 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); 351da177e4SLinus Torvalds MODULE_DESCRIPTION(DRIVER_DESC); 361da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds static int atkbd_set = 2; 391da177e4SLinus Torvalds module_param_named(set, atkbd_set, int, 0); 401da177e4SLinus Torvalds MODULE_PARM_DESC(set, "Select keyboard code set (2 = default, 3 = PS/2 native)"); 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds #if defined(__i386__) || defined(__x86_64__) || defined(__hppa__) 43a9a1f9c3SDmitry Torokhov static bool atkbd_reset; 441da177e4SLinus Torvalds #else 45a9a1f9c3SDmitry Torokhov static bool atkbd_reset = true; 461da177e4SLinus Torvalds #endif 471da177e4SLinus Torvalds module_param_named(reset, atkbd_reset, bool, 0); 481da177e4SLinus Torvalds MODULE_PARM_DESC(reset, "Reset keyboard during initialization"); 491da177e4SLinus Torvalds 50a9a1f9c3SDmitry Torokhov static bool atkbd_softrepeat; 511da177e4SLinus Torvalds module_param_named(softrepeat, atkbd_softrepeat, bool, 0); 521da177e4SLinus Torvalds MODULE_PARM_DESC(softrepeat, "Use software keyboard repeat"); 531da177e4SLinus Torvalds 54a9a1f9c3SDmitry Torokhov static bool atkbd_softraw = true; 551da177e4SLinus Torvalds module_param_named(softraw, atkbd_softraw, bool, 0); 561da177e4SLinus Torvalds MODULE_PARM_DESC(softraw, "Use software generated rawmode"); 571da177e4SLinus Torvalds 58a9a1f9c3SDmitry Torokhov static bool atkbd_scroll; 591da177e4SLinus Torvalds module_param_named(scroll, atkbd_scroll, bool, 0); 601da177e4SLinus Torvalds MODULE_PARM_DESC(scroll, "Enable scroll-wheel on MS Office and similar keyboards"); 611da177e4SLinus Torvalds 62a9a1f9c3SDmitry Torokhov static bool atkbd_extra; 631da177e4SLinus Torvalds module_param_named(extra, atkbd_extra, bool, 0); 641da177e4SLinus Torvalds MODULE_PARM_DESC(extra, "Enable extra LEDs and keys on IBM RapidAcces, EzKey and similar keyboards"); 651da177e4SLinus Torvalds 668c5188b6SBenjamin LaHaise static bool atkbd_terminal; 678c5188b6SBenjamin LaHaise module_param_named(terminal, atkbd_terminal, bool, 0); 688c5188b6SBenjamin LaHaise MODULE_PARM_DESC(terminal, "Enable break codes on an IBM Terminal keyboard connected via AT/PS2"); 698c5188b6SBenjamin LaHaise 701da177e4SLinus Torvalds /* 711da177e4SLinus Torvalds * Scancode to keycode tables. These are just the default setting, and 720211a9c8SFrederik Schwarzer * are loadable via a userland utility. 731da177e4SLinus Torvalds */ 741da177e4SLinus Torvalds 751ba36e11SDmitry Torokhov #define ATKBD_KEYMAP_SIZE 512 761ba36e11SDmitry Torokhov 771ba36e11SDmitry Torokhov static const unsigned short atkbd_set2_keycode[ATKBD_KEYMAP_SIZE] = { 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds #ifdef CONFIG_KEYBOARD_ATKBD_HP_KEYCODES 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds /* XXX: need a more general approach */ 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds #include "hpps2atkbd.h" /* include the keyboard scancodes */ 841da177e4SLinus Torvalds 851da177e4SLinus Torvalds #else 861da177e4SLinus Torvalds 0, 67, 65, 63, 61, 59, 60, 88, 0, 68, 66, 64, 62, 15, 41,117, 871da177e4SLinus Torvalds 0, 56, 42, 93, 29, 16, 2, 0, 0, 0, 44, 31, 30, 17, 3, 0, 881da177e4SLinus Torvalds 0, 46, 45, 32, 18, 5, 4, 95, 0, 57, 47, 33, 20, 19, 6,183, 891da177e4SLinus Torvalds 0, 49, 48, 35, 34, 21, 7,184, 0, 0, 50, 36, 22, 8, 9,185, 901da177e4SLinus Torvalds 0, 51, 37, 23, 24, 11, 10, 0, 0, 52, 53, 38, 39, 25, 12, 0, 911da177e4SLinus Torvalds 0, 89, 40, 0, 26, 13, 0, 0, 58, 54, 28, 27, 0, 43, 0, 85, 921da177e4SLinus Torvalds 0, 86, 91, 90, 92, 0, 14, 94, 0, 79,124, 75, 71,121, 0, 0, 931da177e4SLinus Torvalds 82, 83, 80, 76, 77, 72, 1, 69, 87, 78, 81, 74, 55, 73, 70, 99, 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 961da177e4SLinus Torvalds 217,100,255, 0, 97,165, 0, 0,156, 0, 0, 0, 0, 0, 0,125, 971da177e4SLinus Torvalds 173,114, 0,113, 0, 0, 0,126,128, 0, 0,140, 0, 0, 0,127, 9872a42f24SHans de Goede 159, 0,115, 0,164, 0, 0,116,158, 0,172,166, 0, 0, 0,142, 991da177e4SLinus Torvalds 157, 0, 0, 0, 0, 0, 0, 0,155, 0, 98, 0, 0,163, 0, 0, 1001da177e4SLinus Torvalds 226, 0, 0, 0, 0, 0, 0, 0, 0,255, 96, 0, 0, 0,143, 0, 1011da177e4SLinus Torvalds 0, 0, 0, 0, 0, 0, 0, 0, 0,107, 0,105,102, 0, 0,112, 1021da177e4SLinus Torvalds 110,111,108,112,106,103, 0,119, 0,118,109, 0, 99,104,119, 0, 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds 0, 0, 0, 65, 99, 1051da177e4SLinus Torvalds #endif 1061da177e4SLinus Torvalds }; 1071da177e4SLinus Torvalds 1081ba36e11SDmitry Torokhov static const unsigned short atkbd_set3_keycode[ATKBD_KEYMAP_SIZE] = { 1091da177e4SLinus Torvalds 1101da177e4SLinus Torvalds 0, 0, 0, 0, 0, 0, 0, 59, 1,138,128,129,130, 15, 41, 60, 1111da177e4SLinus Torvalds 131, 29, 42, 86, 58, 16, 2, 61,133, 56, 44, 31, 30, 17, 3, 62, 1121da177e4SLinus Torvalds 134, 46, 45, 32, 18, 5, 4, 63,135, 57, 47, 33, 20, 19, 6, 64, 1131da177e4SLinus Torvalds 136, 49, 48, 35, 34, 21, 7, 65,137,100, 50, 36, 22, 8, 9, 66, 1141da177e4SLinus Torvalds 125, 51, 37, 23, 24, 11, 10, 67,126, 52, 53, 38, 39, 25, 12, 68, 1151da177e4SLinus Torvalds 113,114, 40, 43, 26, 13, 87, 99, 97, 54, 28, 27, 43, 43, 88, 70, 1161da177e4SLinus Torvalds 108,105,119,103,111,107, 14,110, 0, 79,106, 75, 71,109,102,104, 1171da177e4SLinus Torvalds 82, 83, 80, 76, 77, 72, 69, 98, 0, 96, 81, 0, 78, 73, 55,183, 1181da177e4SLinus Torvalds 1191da177e4SLinus Torvalds 184,185,186,187, 74, 94, 92, 93, 0, 0, 0,125,126,127,112, 0, 12072a42f24SHans de Goede 0,139,172,163,165,115,152,172,166,140,160,154,113,114,167,168, 1211da177e4SLinus Torvalds 148,149,147,140 1221da177e4SLinus Torvalds }; 1231da177e4SLinus Torvalds 124f6d65610SDmitry Torokhov static const unsigned short atkbd_unxlate_table[128] = { 1251da177e4SLinus Torvalds 0,118, 22, 30, 38, 37, 46, 54, 61, 62, 70, 69, 78, 85,102, 13, 1261da177e4SLinus Torvalds 21, 29, 36, 45, 44, 53, 60, 67, 68, 77, 84, 91, 90, 20, 28, 27, 1271da177e4SLinus Torvalds 35, 43, 52, 51, 59, 66, 75, 76, 82, 14, 18, 93, 26, 34, 33, 42, 1281da177e4SLinus Torvalds 50, 49, 58, 65, 73, 74, 89,124, 17, 41, 88, 5, 6, 4, 12, 3, 1291da177e4SLinus Torvalds 11, 2, 10, 1, 9,119,126,108,117,125,123,107,115,116,121,105, 1301da177e4SLinus Torvalds 114,122,112,113,127, 96, 97,120, 7, 15, 23, 31, 39, 47, 55, 63, 1311da177e4SLinus Torvalds 71, 79, 86, 94, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 87,111, 1321da177e4SLinus Torvalds 19, 25, 57, 81, 83, 92, 95, 98, 99,100,101,103,104,106,109,110 1331da177e4SLinus Torvalds }; 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds #define ATKBD_CMD_SETLEDS 0x10ed 1361da177e4SLinus Torvalds #define ATKBD_CMD_GSCANSET 0x11f0 1371da177e4SLinus Torvalds #define ATKBD_CMD_SSCANSET 0x10f0 1381da177e4SLinus Torvalds #define ATKBD_CMD_GETID 0x02f2 1391da177e4SLinus Torvalds #define ATKBD_CMD_SETREP 0x10f3 1401da177e4SLinus Torvalds #define ATKBD_CMD_ENABLE 0x00f4 1414a299bf5SDmitry Torokhov #define ATKBD_CMD_RESET_DIS 0x00f5 /* Reset to defaults and disable */ 1424a299bf5SDmitry Torokhov #define ATKBD_CMD_RESET_DEF 0x00f6 /* Reset to defaults */ 1438c5188b6SBenjamin LaHaise #define ATKBD_CMD_SETALL_MB 0x00f8 /* Set all keys to give break codes */ 1448c5188b6SBenjamin LaHaise #define ATKBD_CMD_SETALL_MBR 0x00fa /* ... and repeat */ 1451da177e4SLinus Torvalds #define ATKBD_CMD_RESET_BAT 0x02ff 1461da177e4SLinus Torvalds #define ATKBD_CMD_RESEND 0x00fe 1471da177e4SLinus Torvalds #define ATKBD_CMD_EX_ENABLE 0x10ea 1481da177e4SLinus Torvalds #define ATKBD_CMD_EX_SETLEDS 0x20eb 1491da177e4SLinus Torvalds #define ATKBD_CMD_OK_GETID 0x02e8 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds #define ATKBD_RET_ACK 0xfa 1521da177e4SLinus Torvalds #define ATKBD_RET_NAK 0xfe 1531da177e4SLinus Torvalds #define ATKBD_RET_BAT 0xaa 1541da177e4SLinus Torvalds #define ATKBD_RET_EMUL0 0xe0 1551da177e4SLinus Torvalds #define ATKBD_RET_EMUL1 0xe1 1561da177e4SLinus Torvalds #define ATKBD_RET_RELEASE 0xf0 1570ae051a1SDmitry Torokhov #define ATKBD_RET_HANJA 0xf1 1580ae051a1SDmitry Torokhov #define ATKBD_RET_HANGEUL 0xf2 1591da177e4SLinus Torvalds #define ATKBD_RET_ERR 0xff 1601da177e4SLinus Torvalds 1611da177e4SLinus Torvalds #define ATKBD_KEY_UNKNOWN 0 1621da177e4SLinus Torvalds #define ATKBD_KEY_NULL 255 1631da177e4SLinus Torvalds 1644b70858bSDmitry Torokhov #define ATKBD_SCR_1 0xfffe 1654b70858bSDmitry Torokhov #define ATKBD_SCR_2 0xfffd 1664b70858bSDmitry Torokhov #define ATKBD_SCR_4 0xfffc 1674b70858bSDmitry Torokhov #define ATKBD_SCR_8 0xfffb 1684b70858bSDmitry Torokhov #define ATKBD_SCR_CLICK 0xfffa 1694b70858bSDmitry Torokhov #define ATKBD_SCR_LEFT 0xfff9 1704b70858bSDmitry Torokhov #define ATKBD_SCR_RIGHT 0xfff8 1711da177e4SLinus Torvalds 172f6d65610SDmitry Torokhov #define ATKBD_SPECIAL ATKBD_SCR_RIGHT 1731da177e4SLinus Torvalds 1740d4c8597SDmitry Torokhov #define ATKBD_LED_EVENT_BIT 0 1750d4c8597SDmitry Torokhov #define ATKBD_REP_EVENT_BIT 1 1760d4c8597SDmitry Torokhov 1770ae051a1SDmitry Torokhov #define ATKBD_XL_ERR 0x01 1780ae051a1SDmitry Torokhov #define ATKBD_XL_BAT 0x02 1790ae051a1SDmitry Torokhov #define ATKBD_XL_ACK 0x04 1800ae051a1SDmitry Torokhov #define ATKBD_XL_NAK 0x08 1810ae051a1SDmitry Torokhov #define ATKBD_XL_HANGEUL 0x10 1820ae051a1SDmitry Torokhov #define ATKBD_XL_HANJA 0x20 1830ae051a1SDmitry Torokhov 184f6d65610SDmitry Torokhov static const struct { 1854b70858bSDmitry Torokhov unsigned short keycode; 1861da177e4SLinus Torvalds unsigned char set2; 1871da177e4SLinus Torvalds } atkbd_scroll_keys[] = { 1881da177e4SLinus Torvalds { ATKBD_SCR_1, 0xc5 }, 1895212dd58SVojtech Pavlik { ATKBD_SCR_2, 0x9d }, 1905212dd58SVojtech Pavlik { ATKBD_SCR_4, 0xa4 }, 1915212dd58SVojtech Pavlik { ATKBD_SCR_8, 0x9b }, 1921da177e4SLinus Torvalds { ATKBD_SCR_CLICK, 0xe0 }, 1931da177e4SLinus Torvalds { ATKBD_SCR_LEFT, 0xcb }, 1941da177e4SLinus Torvalds { ATKBD_SCR_RIGHT, 0xd2 }, 1951da177e4SLinus Torvalds }; 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds /* 1981da177e4SLinus Torvalds * The atkbd control structure 1991da177e4SLinus Torvalds */ 2001da177e4SLinus Torvalds 2011da177e4SLinus Torvalds struct atkbd { 2021da177e4SLinus Torvalds 2031da177e4SLinus Torvalds struct ps2dev ps2dev; 2043c42f0c3SDmitry Torokhov struct input_dev *dev; 2051da177e4SLinus Torvalds 2061da177e4SLinus Torvalds /* Written only during init */ 2071da177e4SLinus Torvalds char name[64]; 2081da177e4SLinus Torvalds char phys[32]; 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvalds unsigned short id; 2111ba36e11SDmitry Torokhov unsigned short keycode[ATKBD_KEYMAP_SIZE]; 2121ba36e11SDmitry Torokhov DECLARE_BITMAP(force_release_mask, ATKBD_KEYMAP_SIZE); 2131da177e4SLinus Torvalds unsigned char set; 214a9a1f9c3SDmitry Torokhov bool translated; 215a9a1f9c3SDmitry Torokhov bool extra; 216a9a1f9c3SDmitry Torokhov bool write; 217a9a1f9c3SDmitry Torokhov bool softrepeat; 218a9a1f9c3SDmitry Torokhov bool softraw; 219a9a1f9c3SDmitry Torokhov bool scroll; 220a9a1f9c3SDmitry Torokhov bool enabled; 2211da177e4SLinus Torvalds 2221da177e4SLinus Torvalds /* Accessed only from interrupt */ 2231da177e4SLinus Torvalds unsigned char emul; 224a9a1f9c3SDmitry Torokhov bool resend; 225a9a1f9c3SDmitry Torokhov bool release; 2260ae051a1SDmitry Torokhov unsigned long xl_bit; 2271da177e4SLinus Torvalds unsigned int last; 2281da177e4SLinus Torvalds unsigned long time; 22986255d9dSDmitry Torokhov unsigned long err_count; 2300d4c8597SDmitry Torokhov 231da4249c9SDmitry Torokhov struct delayed_work event_work; 232da4249c9SDmitry Torokhov unsigned long event_jiffies; 2330d4c8597SDmitry Torokhov unsigned long event_mask; 23459b01513SEric W. Biederman 23559b01513SEric W. Biederman /* Serializes reconnect(), attr->set() and event work */ 23659b01513SEric W. Biederman struct mutex mutex; 2371da177e4SLinus Torvalds }; 2381da177e4SLinus Torvalds 239554101e3SGiel de Nijs /* 24036726dd9SThadeu Lima de Souza Cascardo * System-specific keymap fixup routine 241554101e3SGiel de Nijs */ 24239191698SDaniel Mierswa static void (*atkbd_platform_fixup)(struct atkbd *, const void *data); 24339191698SDaniel Mierswa static void *atkbd_platform_fixup_data; 244e5713069SJamie Lentin static unsigned int (*atkbd_platform_scancode_fixup)(struct atkbd *, unsigned int); 245554101e3SGiel de Nijs 2461da177e4SLinus Torvalds static ssize_t atkbd_attr_show_helper(struct device *dev, char *buf, 2471da177e4SLinus Torvalds ssize_t (*handler)(struct atkbd *, char *)); 2481da177e4SLinus Torvalds static ssize_t atkbd_attr_set_helper(struct device *dev, const char *buf, size_t count, 2491da177e4SLinus Torvalds ssize_t (*handler)(struct atkbd *, const char *, size_t)); 2501da177e4SLinus Torvalds #define ATKBD_DEFINE_ATTR(_name) \ 2511da177e4SLinus Torvalds static ssize_t atkbd_show_##_name(struct atkbd *, char *); \ 2521da177e4SLinus Torvalds static ssize_t atkbd_set_##_name(struct atkbd *, const char *, size_t); \ 25386255d9dSDmitry Torokhov static ssize_t atkbd_do_show_##_name(struct device *d, \ 25486255d9dSDmitry Torokhov struct device_attribute *attr, char *b) \ 2551da177e4SLinus Torvalds { \ 2561da177e4SLinus Torvalds return atkbd_attr_show_helper(d, b, atkbd_show_##_name); \ 2571da177e4SLinus Torvalds } \ 25886255d9dSDmitry Torokhov static ssize_t atkbd_do_set_##_name(struct device *d, \ 25986255d9dSDmitry Torokhov struct device_attribute *attr, const char *b, size_t s) \ 2601da177e4SLinus Torvalds { \ 2611da177e4SLinus Torvalds return atkbd_attr_set_helper(d, b, s, atkbd_set_##_name); \ 2621da177e4SLinus Torvalds } \ 2631da177e4SLinus Torvalds static struct device_attribute atkbd_attr_##_name = \ 2641da177e4SLinus Torvalds __ATTR(_name, S_IWUSR | S_IRUGO, atkbd_do_show_##_name, atkbd_do_set_##_name); 2651da177e4SLinus Torvalds 2661da177e4SLinus Torvalds ATKBD_DEFINE_ATTR(extra); 2671ba36e11SDmitry Torokhov ATKBD_DEFINE_ATTR(force_release); 2681da177e4SLinus Torvalds ATKBD_DEFINE_ATTR(scroll); 2691da177e4SLinus Torvalds ATKBD_DEFINE_ATTR(set); 2701da177e4SLinus Torvalds ATKBD_DEFINE_ATTR(softrepeat); 2711da177e4SLinus Torvalds ATKBD_DEFINE_ATTR(softraw); 2721da177e4SLinus Torvalds 27386255d9dSDmitry Torokhov #define ATKBD_DEFINE_RO_ATTR(_name) \ 27486255d9dSDmitry Torokhov static ssize_t atkbd_show_##_name(struct atkbd *, char *); \ 27586255d9dSDmitry Torokhov static ssize_t atkbd_do_show_##_name(struct device *d, \ 27686255d9dSDmitry Torokhov struct device_attribute *attr, char *b) \ 27786255d9dSDmitry Torokhov { \ 27886255d9dSDmitry Torokhov return atkbd_attr_show_helper(d, b, atkbd_show_##_name); \ 27986255d9dSDmitry Torokhov } \ 28086255d9dSDmitry Torokhov static struct device_attribute atkbd_attr_##_name = \ 28186255d9dSDmitry Torokhov __ATTR(_name, S_IRUGO, atkbd_do_show_##_name, NULL); 28286255d9dSDmitry Torokhov 28386255d9dSDmitry Torokhov ATKBD_DEFINE_RO_ATTR(err_count); 28486255d9dSDmitry Torokhov 28586255d9dSDmitry Torokhov static struct attribute *atkbd_attributes[] = { 28686255d9dSDmitry Torokhov &atkbd_attr_extra.attr, 2871ba36e11SDmitry Torokhov &atkbd_attr_force_release.attr, 28886255d9dSDmitry Torokhov &atkbd_attr_scroll.attr, 28986255d9dSDmitry Torokhov &atkbd_attr_set.attr, 29086255d9dSDmitry Torokhov &atkbd_attr_softrepeat.attr, 29186255d9dSDmitry Torokhov &atkbd_attr_softraw.attr, 29286255d9dSDmitry Torokhov &atkbd_attr_err_count.attr, 29386255d9dSDmitry Torokhov NULL 29486255d9dSDmitry Torokhov }; 29586255d9dSDmitry Torokhov 29686255d9dSDmitry Torokhov static struct attribute_group atkbd_attribute_group = { 29786255d9dSDmitry Torokhov .attrs = atkbd_attributes, 29886255d9dSDmitry Torokhov }; 29986255d9dSDmitry Torokhov 3000ae051a1SDmitry Torokhov static const unsigned int xl_table[] = { 3010ae051a1SDmitry Torokhov ATKBD_RET_BAT, ATKBD_RET_ERR, ATKBD_RET_ACK, 3020ae051a1SDmitry Torokhov ATKBD_RET_NAK, ATKBD_RET_HANJA, ATKBD_RET_HANGEUL, 3030ae051a1SDmitry Torokhov }; 3041da177e4SLinus Torvalds 3050ae051a1SDmitry Torokhov /* 3060ae051a1SDmitry Torokhov * Checks if we should mangle the scancode to extract 'release' bit 3070ae051a1SDmitry Torokhov * in translated mode. 3080ae051a1SDmitry Torokhov */ 309a9a1f9c3SDmitry Torokhov static bool atkbd_need_xlate(unsigned long xl_bit, unsigned char code) 3101da177e4SLinus Torvalds { 3110ae051a1SDmitry Torokhov int i; 3120ae051a1SDmitry Torokhov 3130ae051a1SDmitry Torokhov if (code == ATKBD_RET_EMUL0 || code == ATKBD_RET_EMUL1) 314a9a1f9c3SDmitry Torokhov return false; 3150ae051a1SDmitry Torokhov 3160ae051a1SDmitry Torokhov for (i = 0; i < ARRAY_SIZE(xl_table); i++) 3170ae051a1SDmitry Torokhov if (code == xl_table[i]) 3180ae051a1SDmitry Torokhov return test_bit(i, &xl_bit); 3190ae051a1SDmitry Torokhov 320a9a1f9c3SDmitry Torokhov return true; 3210ae051a1SDmitry Torokhov } 3220ae051a1SDmitry Torokhov 3230ae051a1SDmitry Torokhov /* 3240ae051a1SDmitry Torokhov * Calculates new value of xl_bit so the driver can distinguish 3250ae051a1SDmitry Torokhov * between make/break pair of scancodes for select keys and PS/2 3260ae051a1SDmitry Torokhov * protocol responses. 3270ae051a1SDmitry Torokhov */ 3280ae051a1SDmitry Torokhov static void atkbd_calculate_xl_bit(struct atkbd *atkbd, unsigned char code) 3290ae051a1SDmitry Torokhov { 3300ae051a1SDmitry Torokhov int i; 3310ae051a1SDmitry Torokhov 3320ae051a1SDmitry Torokhov for (i = 0; i < ARRAY_SIZE(xl_table); i++) { 3330ae051a1SDmitry Torokhov if (!((code ^ xl_table[i]) & 0x7f)) { 3340ae051a1SDmitry Torokhov if (code & 0x80) 3350ae051a1SDmitry Torokhov __clear_bit(i, &atkbd->xl_bit); 3360ae051a1SDmitry Torokhov else 3370ae051a1SDmitry Torokhov __set_bit(i, &atkbd->xl_bit); 3380ae051a1SDmitry Torokhov break; 3390ae051a1SDmitry Torokhov } 3400ae051a1SDmitry Torokhov } 3410ae051a1SDmitry Torokhov } 3420ae051a1SDmitry Torokhov 3430ae051a1SDmitry Torokhov /* 3440ae051a1SDmitry Torokhov * Encode the scancode, 0xe0 prefix, and high bit into a single integer, 3450ae051a1SDmitry Torokhov * keeping kernel 2.4 compatibility for set 2 3460ae051a1SDmitry Torokhov */ 3470ae051a1SDmitry Torokhov static unsigned int atkbd_compat_scancode(struct atkbd *atkbd, unsigned int code) 3480ae051a1SDmitry Torokhov { 3490ae051a1SDmitry Torokhov if (atkbd->set == 3) { 3500ae051a1SDmitry Torokhov if (atkbd->emul == 1) 3510ae051a1SDmitry Torokhov code |= 0x100; 3520ae051a1SDmitry Torokhov } else { 3530ae051a1SDmitry Torokhov code = (code & 0x7f) | ((code & 0x80) << 1); 3540ae051a1SDmitry Torokhov if (atkbd->emul == 1) 3550ae051a1SDmitry Torokhov code |= 0x80; 3560ae051a1SDmitry Torokhov } 3570ae051a1SDmitry Torokhov 3580ae051a1SDmitry Torokhov return code; 3591da177e4SLinus Torvalds } 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds /* 3621da177e4SLinus Torvalds * atkbd_interrupt(). Here takes place processing of data received from 3631da177e4SLinus Torvalds * the keyboard into events. 3641da177e4SLinus Torvalds */ 3651da177e4SLinus Torvalds 3661da177e4SLinus Torvalds static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data, 3677d12e780SDavid Howells unsigned int flags) 3681da177e4SLinus Torvalds { 3691da177e4SLinus Torvalds struct atkbd *atkbd = serio_get_drvdata(serio); 3700ae051a1SDmitry Torokhov struct input_dev *dev = atkbd->dev; 3711da177e4SLinus Torvalds unsigned int code = data; 372554101e3SGiel de Nijs int scroll = 0, hscroll = 0, click = -1; 3731da177e4SLinus Torvalds int value; 374f6d65610SDmitry Torokhov unsigned short keycode; 3751da177e4SLinus Torvalds 376a9a1f9c3SDmitry Torokhov dev_dbg(&serio->dev, "Received %02x flags %02x\n", data, flags); 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds #if !defined(__i386__) && !defined (__x86_64__) 3791da177e4SLinus Torvalds if ((flags & (SERIO_FRAME | SERIO_PARITY)) && (~flags & SERIO_TIMEOUT) && !atkbd->resend && atkbd->write) { 380a9a1f9c3SDmitry Torokhov dev_warn(&serio->dev, "Frame/parity error: %02x\n", flags); 3811da177e4SLinus Torvalds serio_write(serio, ATKBD_CMD_RESEND); 382a9a1f9c3SDmitry Torokhov atkbd->resend = true; 3831da177e4SLinus Torvalds goto out; 3841da177e4SLinus Torvalds } 3851da177e4SLinus Torvalds 3861da177e4SLinus Torvalds if (!flags && data == ATKBD_RET_ACK) 387a9a1f9c3SDmitry Torokhov atkbd->resend = false; 3881da177e4SLinus Torvalds #endif 3891da177e4SLinus Torvalds 3901da177e4SLinus Torvalds if (unlikely(atkbd->ps2dev.flags & PS2_FLAG_ACK)) 3911da177e4SLinus Torvalds if (ps2_handle_ack(&atkbd->ps2dev, data)) 3921da177e4SLinus Torvalds goto out; 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvalds if (unlikely(atkbd->ps2dev.flags & PS2_FLAG_CMD)) 3951da177e4SLinus Torvalds if (ps2_handle_response(&atkbd->ps2dev, data)) 3961da177e4SLinus Torvalds goto out; 3971da177e4SLinus Torvalds 3981da177e4SLinus Torvalds if (!atkbd->enabled) 3991da177e4SLinus Torvalds goto out; 4001da177e4SLinus Torvalds 4010ae051a1SDmitry Torokhov input_event(dev, EV_MSC, MSC_RAW, code); 4021da177e4SLinus Torvalds 403e5713069SJamie Lentin if (atkbd_platform_scancode_fixup) 404e5713069SJamie Lentin code = atkbd_platform_scancode_fixup(atkbd, code); 405e5713069SJamie Lentin 4061da177e4SLinus Torvalds if (atkbd->translated) { 4071da177e4SLinus Torvalds 4080ae051a1SDmitry Torokhov if (atkbd->emul || atkbd_need_xlate(atkbd->xl_bit, code)) { 4091da177e4SLinus Torvalds atkbd->release = code >> 7; 4101da177e4SLinus Torvalds code &= 0x7f; 4111da177e4SLinus Torvalds } 4121da177e4SLinus Torvalds 4130ae051a1SDmitry Torokhov if (!atkbd->emul) 4140ae051a1SDmitry Torokhov atkbd_calculate_xl_bit(atkbd, data); 4151da177e4SLinus Torvalds } 4161da177e4SLinus Torvalds 4171da177e4SLinus Torvalds switch (code) { 4181da177e4SLinus Torvalds case ATKBD_RET_BAT: 419a9a1f9c3SDmitry Torokhov atkbd->enabled = false; 420dbc26344SDmitry Torokhov serio_reconnect(atkbd->ps2dev.serio); 4211da177e4SLinus Torvalds goto out; 4221da177e4SLinus Torvalds case ATKBD_RET_EMUL0: 4231da177e4SLinus Torvalds atkbd->emul = 1; 4241da177e4SLinus Torvalds goto out; 4251da177e4SLinus Torvalds case ATKBD_RET_EMUL1: 4261da177e4SLinus Torvalds atkbd->emul = 2; 4271da177e4SLinus Torvalds goto out; 4281da177e4SLinus Torvalds case ATKBD_RET_RELEASE: 429a9a1f9c3SDmitry Torokhov atkbd->release = true; 4301da177e4SLinus Torvalds goto out; 4310ae051a1SDmitry Torokhov case ATKBD_RET_ACK: 4320ae051a1SDmitry Torokhov case ATKBD_RET_NAK: 4339f7a60d6SQi Yong if (printk_ratelimit()) 434a9a1f9c3SDmitry Torokhov dev_warn(&serio->dev, 435a9a1f9c3SDmitry Torokhov "Spurious %s on %s. " 436f57fe78eSJesper Juhl "Some program might be trying to access hardware directly.\n", 4370ae051a1SDmitry Torokhov data == ATKBD_RET_ACK ? "ACK" : "NAK", serio->phys); 4380ae051a1SDmitry Torokhov goto out; 4391da177e4SLinus Torvalds case ATKBD_RET_ERR: 44086255d9dSDmitry Torokhov atkbd->err_count++; 441a9a1f9c3SDmitry Torokhov dev_dbg(&serio->dev, "Keyboard on %s reports too many keys pressed.\n", 442a9a1f9c3SDmitry Torokhov serio->phys); 4431da177e4SLinus Torvalds goto out; 4441da177e4SLinus Torvalds } 4451da177e4SLinus Torvalds 4460ae051a1SDmitry Torokhov code = atkbd_compat_scancode(atkbd, code); 4470ae051a1SDmitry Torokhov 4480ae051a1SDmitry Torokhov if (atkbd->emul && --atkbd->emul) 4491da177e4SLinus Torvalds goto out; 4501da177e4SLinus Torvalds 4510ae051a1SDmitry Torokhov keycode = atkbd->keycode[code]; 4521da177e4SLinus Torvalds 4530ae051a1SDmitry Torokhov if (keycode != ATKBD_KEY_NULL) 4540ae051a1SDmitry Torokhov input_event(dev, EV_MSC, MSC_SCAN, code); 4550ae051a1SDmitry Torokhov 4560ae051a1SDmitry Torokhov switch (keycode) { 4571da177e4SLinus Torvalds case ATKBD_KEY_NULL: 4581da177e4SLinus Torvalds break; 4591da177e4SLinus Torvalds case ATKBD_KEY_UNKNOWN: 460a9a1f9c3SDmitry Torokhov dev_warn(&serio->dev, 461a9a1f9c3SDmitry Torokhov "Unknown key %s (%s set %d, code %#x on %s).\n", 4621da177e4SLinus Torvalds atkbd->release ? "released" : "pressed", 4631da177e4SLinus Torvalds atkbd->translated ? "translated" : "raw", 4641da177e4SLinus Torvalds atkbd->set, code, serio->phys); 465a9a1f9c3SDmitry Torokhov dev_warn(&serio->dev, 466a9a1f9c3SDmitry Torokhov "Use 'setkeycodes %s%02x <keycode>' to make it known.\n", 4671da177e4SLinus Torvalds code & 0x80 ? "e0" : "", code & 0x7f); 4680ae051a1SDmitry Torokhov input_sync(dev); 4691da177e4SLinus Torvalds break; 4701da177e4SLinus Torvalds case ATKBD_SCR_1: 471a9a1f9c3SDmitry Torokhov scroll = 1; 4721da177e4SLinus Torvalds break; 4731da177e4SLinus Torvalds case ATKBD_SCR_2: 474a9a1f9c3SDmitry Torokhov scroll = 2; 4751da177e4SLinus Torvalds break; 4761da177e4SLinus Torvalds case ATKBD_SCR_4: 477a9a1f9c3SDmitry Torokhov scroll = 4; 4781da177e4SLinus Torvalds break; 4791da177e4SLinus Torvalds case ATKBD_SCR_8: 480a9a1f9c3SDmitry Torokhov scroll = 8; 4811da177e4SLinus Torvalds break; 4821da177e4SLinus Torvalds case ATKBD_SCR_CLICK: 4831da177e4SLinus Torvalds click = !atkbd->release; 4841da177e4SLinus Torvalds break; 4851da177e4SLinus Torvalds case ATKBD_SCR_LEFT: 4861da177e4SLinus Torvalds hscroll = -1; 4871da177e4SLinus Torvalds break; 4881da177e4SLinus Torvalds case ATKBD_SCR_RIGHT: 4891da177e4SLinus Torvalds hscroll = 1; 4901da177e4SLinus Torvalds break; 4911da177e4SLinus Torvalds default: 4920ae051a1SDmitry Torokhov if (atkbd->release) { 4930ae051a1SDmitry Torokhov value = 0; 4941da177e4SLinus Torvalds atkbd->last = 0; 4950ae051a1SDmitry Torokhov } else if (!atkbd->softrepeat && test_bit(keycode, dev->key)) { 4960ae051a1SDmitry Torokhov /* Workaround Toshiba laptop multiple keypress */ 4970ae051a1SDmitry Torokhov value = time_before(jiffies, atkbd->time) && atkbd->last == code ? 1 : 2; 4980ae051a1SDmitry Torokhov } else { 4991da177e4SLinus Torvalds value = 1; 5000ae051a1SDmitry Torokhov atkbd->last = code; 5010ae051a1SDmitry Torokhov atkbd->time = jiffies + msecs_to_jiffies(dev->rep[REP_DELAY]) / 2; 5021da177e4SLinus Torvalds } 5031da177e4SLinus Torvalds 504f8b4c46cSDmitry Torokhov input_event(dev, EV_KEY, keycode, value); 5050ae051a1SDmitry Torokhov input_sync(dev); 5060ae051a1SDmitry Torokhov 507554101e3SGiel de Nijs if (value && test_bit(code, atkbd->force_release_mask)) { 5080ae051a1SDmitry Torokhov input_report_key(dev, keycode, 0); 5090ae051a1SDmitry Torokhov input_sync(dev); 5100ae051a1SDmitry Torokhov } 5111da177e4SLinus Torvalds } 5121da177e4SLinus Torvalds 5131da177e4SLinus Torvalds if (atkbd->scroll) { 5141da177e4SLinus Torvalds if (click != -1) 5150ae051a1SDmitry Torokhov input_report_key(dev, BTN_MIDDLE, click); 516a9a1f9c3SDmitry Torokhov input_report_rel(dev, REL_WHEEL, 517a9a1f9c3SDmitry Torokhov atkbd->release ? -scroll : scroll); 5180ae051a1SDmitry Torokhov input_report_rel(dev, REL_HWHEEL, hscroll); 5190ae051a1SDmitry Torokhov input_sync(dev); 5201da177e4SLinus Torvalds } 5211da177e4SLinus Torvalds 522a9a1f9c3SDmitry Torokhov atkbd->release = false; 5231da177e4SLinus Torvalds out: 5241da177e4SLinus Torvalds return IRQ_HANDLED; 5251da177e4SLinus Torvalds } 5261da177e4SLinus Torvalds 5273d0f0fa0SDmitry Torokhov static int atkbd_set_repeat_rate(struct atkbd *atkbd) 5281da177e4SLinus Torvalds { 5291da177e4SLinus Torvalds const short period[32] = 5301da177e4SLinus Torvalds { 33, 37, 42, 46, 50, 54, 58, 63, 67, 75, 83, 92, 100, 109, 116, 125, 5311da177e4SLinus Torvalds 133, 149, 167, 182, 200, 217, 232, 250, 270, 303, 333, 370, 400, 435, 470, 500 }; 5321da177e4SLinus Torvalds const short delay[4] = 5331da177e4SLinus Torvalds { 250, 500, 750, 1000 }; 5340d4c8597SDmitry Torokhov 5353d0f0fa0SDmitry Torokhov struct input_dev *dev = atkbd->dev; 5363d0f0fa0SDmitry Torokhov unsigned char param; 5373d0f0fa0SDmitry Torokhov int i = 0, j = 0; 5383d0f0fa0SDmitry Torokhov 5393d0f0fa0SDmitry Torokhov while (i < ARRAY_SIZE(period) - 1 && period[i] < dev->rep[REP_PERIOD]) 5403d0f0fa0SDmitry Torokhov i++; 5413d0f0fa0SDmitry Torokhov dev->rep[REP_PERIOD] = period[i]; 5423d0f0fa0SDmitry Torokhov 5438ea371fbSFlorin Malita while (j < ARRAY_SIZE(delay) - 1 && delay[j] < dev->rep[REP_DELAY]) 5443d0f0fa0SDmitry Torokhov j++; 5453d0f0fa0SDmitry Torokhov dev->rep[REP_DELAY] = delay[j]; 5463d0f0fa0SDmitry Torokhov 5473d0f0fa0SDmitry Torokhov param = i | (j << 5); 5483d0f0fa0SDmitry Torokhov return ps2_command(&atkbd->ps2dev, ¶m, ATKBD_CMD_SETREP); 5493d0f0fa0SDmitry Torokhov } 5503d0f0fa0SDmitry Torokhov 5513d0f0fa0SDmitry Torokhov static int atkbd_set_leds(struct atkbd *atkbd) 5523d0f0fa0SDmitry Torokhov { 5530d4c8597SDmitry Torokhov struct input_dev *dev = atkbd->dev; 5541da177e4SLinus Torvalds unsigned char param[2]; 5551da177e4SLinus Torvalds 5561da177e4SLinus Torvalds param[0] = (test_bit(LED_SCROLLL, dev->led) ? 1 : 0) 5571da177e4SLinus Torvalds | (test_bit(LED_NUML, dev->led) ? 2 : 0) 5581da177e4SLinus Torvalds | (test_bit(LED_CAPSL, dev->led) ? 4 : 0); 5593d0f0fa0SDmitry Torokhov if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETLEDS)) 5603d0f0fa0SDmitry Torokhov return -1; 5611da177e4SLinus Torvalds 5621da177e4SLinus Torvalds if (atkbd->extra) { 5631da177e4SLinus Torvalds param[0] = 0; 5641da177e4SLinus Torvalds param[1] = (test_bit(LED_COMPOSE, dev->led) ? 0x01 : 0) 5651da177e4SLinus Torvalds | (test_bit(LED_SLEEP, dev->led) ? 0x02 : 0) 5661da177e4SLinus Torvalds | (test_bit(LED_SUSPEND, dev->led) ? 0x04 : 0) 5671da177e4SLinus Torvalds | (test_bit(LED_MISC, dev->led) ? 0x10 : 0) 5681da177e4SLinus Torvalds | (test_bit(LED_MUTE, dev->led) ? 0x20 : 0); 5693d0f0fa0SDmitry Torokhov if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_EX_SETLEDS)) 5703d0f0fa0SDmitry Torokhov return -1; 5711da177e4SLinus Torvalds } 5721da177e4SLinus Torvalds 5733d0f0fa0SDmitry Torokhov return 0; 5740d4c8597SDmitry Torokhov } 5750d4c8597SDmitry Torokhov 5763d0f0fa0SDmitry Torokhov /* 5773d0f0fa0SDmitry Torokhov * atkbd_event_work() is used to complete processing of events that 5783d0f0fa0SDmitry Torokhov * can not be processed by input_event() which is often called from 5793d0f0fa0SDmitry Torokhov * interrupt context. 5803d0f0fa0SDmitry Torokhov */ 5813d0f0fa0SDmitry Torokhov 58265f27f38SDavid Howells static void atkbd_event_work(struct work_struct *work) 5833d0f0fa0SDmitry Torokhov { 584da4249c9SDmitry Torokhov struct atkbd *atkbd = container_of(work, struct atkbd, event_work.work); 5853d0f0fa0SDmitry Torokhov 58659b01513SEric W. Biederman mutex_lock(&atkbd->mutex); 5873d0f0fa0SDmitry Torokhov 58894dfb0d6SDmitry Torokhov if (!atkbd->enabled) { 58994dfb0d6SDmitry Torokhov /* 59094dfb0d6SDmitry Torokhov * Serio ports are resumed asynchronously so while driver core 59194dfb0d6SDmitry Torokhov * thinks that device is already fully operational in reality 59294dfb0d6SDmitry Torokhov * it may not be ready yet. In this case we need to keep 59394dfb0d6SDmitry Torokhov * rescheduling till reconnect completes. 59494dfb0d6SDmitry Torokhov */ 59594dfb0d6SDmitry Torokhov schedule_delayed_work(&atkbd->event_work, 59694dfb0d6SDmitry Torokhov msecs_to_jiffies(100)); 59794dfb0d6SDmitry Torokhov } else { 5983d0f0fa0SDmitry Torokhov if (test_and_clear_bit(ATKBD_LED_EVENT_BIT, &atkbd->event_mask)) 5993d0f0fa0SDmitry Torokhov atkbd_set_leds(atkbd); 6003d0f0fa0SDmitry Torokhov 6013d0f0fa0SDmitry Torokhov if (test_and_clear_bit(ATKBD_REP_EVENT_BIT, &atkbd->event_mask)) 6023d0f0fa0SDmitry Torokhov atkbd_set_repeat_rate(atkbd); 60394dfb0d6SDmitry Torokhov } 6043d0f0fa0SDmitry Torokhov 60559b01513SEric W. Biederman mutex_unlock(&atkbd->mutex); 6060d4c8597SDmitry Torokhov } 6070d4c8597SDmitry Torokhov 6080d4c8597SDmitry Torokhov /* 609da4249c9SDmitry Torokhov * Schedule switch for execution. We need to throttle requests, 610da4249c9SDmitry Torokhov * otherwise keyboard may become unresponsive. 611da4249c9SDmitry Torokhov */ 612da4249c9SDmitry Torokhov static void atkbd_schedule_event_work(struct atkbd *atkbd, int event_bit) 613da4249c9SDmitry Torokhov { 614da4249c9SDmitry Torokhov unsigned long delay = msecs_to_jiffies(50); 615da4249c9SDmitry Torokhov 616da4249c9SDmitry Torokhov if (time_after(jiffies, atkbd->event_jiffies + delay)) 617da4249c9SDmitry Torokhov delay = 0; 618da4249c9SDmitry Torokhov 619da4249c9SDmitry Torokhov atkbd->event_jiffies = jiffies; 620da4249c9SDmitry Torokhov set_bit(event_bit, &atkbd->event_mask); 62159b01513SEric W. Biederman mb(); 622da4249c9SDmitry Torokhov schedule_delayed_work(&atkbd->event_work, delay); 623da4249c9SDmitry Torokhov } 624da4249c9SDmitry Torokhov 625da4249c9SDmitry Torokhov /* 6260d4c8597SDmitry Torokhov * Event callback from the input module. Events that change the state of 6270d4c8597SDmitry Torokhov * the hardware are processed here. If action can not be performed in 6280d4c8597SDmitry Torokhov * interrupt context it is offloaded to atkbd_event_work. 6290d4c8597SDmitry Torokhov */ 6300d4c8597SDmitry Torokhov 631da4249c9SDmitry Torokhov static int atkbd_event(struct input_dev *dev, 632da4249c9SDmitry Torokhov unsigned int type, unsigned int code, int value) 6330d4c8597SDmitry Torokhov { 634b356872fSDmitry Torokhov struct atkbd *atkbd = input_get_drvdata(dev); 6350d4c8597SDmitry Torokhov 6360d4c8597SDmitry Torokhov if (!atkbd->write) 6370d4c8597SDmitry Torokhov return -1; 6380d4c8597SDmitry Torokhov 6390d4c8597SDmitry Torokhov switch (type) { 6400d4c8597SDmitry Torokhov 6410d4c8597SDmitry Torokhov case EV_LED: 642da4249c9SDmitry Torokhov atkbd_schedule_event_work(atkbd, ATKBD_LED_EVENT_BIT); 6430d4c8597SDmitry Torokhov return 0; 6440d4c8597SDmitry Torokhov 6450d4c8597SDmitry Torokhov case EV_REP: 646da4249c9SDmitry Torokhov if (!atkbd->softrepeat) 647da4249c9SDmitry Torokhov atkbd_schedule_event_work(atkbd, ATKBD_REP_EVENT_BIT); 6481da177e4SLinus Torvalds return 0; 6491da177e4SLinus Torvalds 650a9a1f9c3SDmitry Torokhov default: 6511da177e4SLinus Torvalds return -1; 6521da177e4SLinus Torvalds } 653a9a1f9c3SDmitry Torokhov } 6541da177e4SLinus Torvalds 6551da177e4SLinus Torvalds /* 6561da177e4SLinus Torvalds * atkbd_enable() signals that interrupt handler is allowed to 6571da177e4SLinus Torvalds * generate input events. 6581da177e4SLinus Torvalds */ 6591da177e4SLinus Torvalds 6601da177e4SLinus Torvalds static inline void atkbd_enable(struct atkbd *atkbd) 6611da177e4SLinus Torvalds { 6621da177e4SLinus Torvalds serio_pause_rx(atkbd->ps2dev.serio); 663a9a1f9c3SDmitry Torokhov atkbd->enabled = true; 6641da177e4SLinus Torvalds serio_continue_rx(atkbd->ps2dev.serio); 6651da177e4SLinus Torvalds } 6661da177e4SLinus Torvalds 6671da177e4SLinus Torvalds /* 6681da177e4SLinus Torvalds * atkbd_disable() tells input handler that all incoming data except 6691da177e4SLinus Torvalds * for ACKs and command response should be dropped. 6701da177e4SLinus Torvalds */ 6711da177e4SLinus Torvalds 6721da177e4SLinus Torvalds static inline void atkbd_disable(struct atkbd *atkbd) 6731da177e4SLinus Torvalds { 6741da177e4SLinus Torvalds serio_pause_rx(atkbd->ps2dev.serio); 675a9a1f9c3SDmitry Torokhov atkbd->enabled = false; 6761da177e4SLinus Torvalds serio_continue_rx(atkbd->ps2dev.serio); 6771da177e4SLinus Torvalds } 6781da177e4SLinus Torvalds 679*be2d7e42SShawn Nematbakhsh static int atkbd_activate(struct atkbd *atkbd) 680*be2d7e42SShawn Nematbakhsh { 681*be2d7e42SShawn Nematbakhsh struct ps2dev *ps2dev = &atkbd->ps2dev; 682*be2d7e42SShawn Nematbakhsh 683*be2d7e42SShawn Nematbakhsh /* 684*be2d7e42SShawn Nematbakhsh * Enable the keyboard to receive keystrokes. 685*be2d7e42SShawn Nematbakhsh */ 686*be2d7e42SShawn Nematbakhsh 687*be2d7e42SShawn Nematbakhsh if (ps2_command(ps2dev, NULL, ATKBD_CMD_ENABLE)) { 688*be2d7e42SShawn Nematbakhsh dev_err(&ps2dev->serio->dev, 689*be2d7e42SShawn Nematbakhsh "Failed to enable keyboard on %s\n", 690*be2d7e42SShawn Nematbakhsh ps2dev->serio->phys); 691*be2d7e42SShawn Nematbakhsh return -1; 692*be2d7e42SShawn Nematbakhsh } 693*be2d7e42SShawn Nematbakhsh 694*be2d7e42SShawn Nematbakhsh return 0; 695*be2d7e42SShawn Nematbakhsh } 696*be2d7e42SShawn Nematbakhsh 697*be2d7e42SShawn Nematbakhsh /* 698*be2d7e42SShawn Nematbakhsh * atkbd_deactivate() resets and disables the keyboard from sending 699*be2d7e42SShawn Nematbakhsh * keystrokes. 700*be2d7e42SShawn Nematbakhsh */ 701*be2d7e42SShawn Nematbakhsh 702*be2d7e42SShawn Nematbakhsh static void atkbd_deactivate(struct atkbd *atkbd) 703*be2d7e42SShawn Nematbakhsh { 704*be2d7e42SShawn Nematbakhsh struct ps2dev *ps2dev = &atkbd->ps2dev; 705*be2d7e42SShawn Nematbakhsh 706*be2d7e42SShawn Nematbakhsh if (ps2_command(ps2dev, NULL, ATKBD_CMD_RESET_DIS)) 707*be2d7e42SShawn Nematbakhsh dev_err(&ps2dev->serio->dev, 708*be2d7e42SShawn Nematbakhsh "Failed to deactivate keyboard on %s\n", 709*be2d7e42SShawn Nematbakhsh ps2dev->serio->phys); 710*be2d7e42SShawn Nematbakhsh } 711*be2d7e42SShawn Nematbakhsh 7121da177e4SLinus Torvalds /* 7131da177e4SLinus Torvalds * atkbd_probe() probes for an AT keyboard on a serio port. 7141da177e4SLinus Torvalds */ 7151da177e4SLinus Torvalds 7161da177e4SLinus Torvalds static int atkbd_probe(struct atkbd *atkbd) 7171da177e4SLinus Torvalds { 7181da177e4SLinus Torvalds struct ps2dev *ps2dev = &atkbd->ps2dev; 7191da177e4SLinus Torvalds unsigned char param[2]; 7201da177e4SLinus Torvalds 7211da177e4SLinus Torvalds /* 7221da177e4SLinus Torvalds * Some systems, where the bit-twiddling when testing the io-lines of the 7231da177e4SLinus Torvalds * controller may confuse the keyboard need a full reset of the keyboard. On 7241da177e4SLinus Torvalds * these systems the BIOS also usually doesn't do it for us. 7251da177e4SLinus Torvalds */ 7261da177e4SLinus Torvalds 7271da177e4SLinus Torvalds if (atkbd_reset) 7281da177e4SLinus Torvalds if (ps2_command(ps2dev, NULL, ATKBD_CMD_RESET_BAT)) 729a9a1f9c3SDmitry Torokhov dev_warn(&ps2dev->serio->dev, 730a9a1f9c3SDmitry Torokhov "keyboard reset failed on %s\n", 731a9a1f9c3SDmitry Torokhov ps2dev->serio->phys); 7321da177e4SLinus Torvalds 7331da177e4SLinus Torvalds /* 7341da177e4SLinus Torvalds * Then we check the keyboard ID. We should get 0xab83 under normal conditions. 7351da177e4SLinus Torvalds * Some keyboards report different values, but the first byte is always 0xab or 7361da177e4SLinus Torvalds * 0xac. Some old AT keyboards don't report anything. If a mouse is connected, this 7371da177e4SLinus Torvalds * should make sure we don't try to set the LEDs on it. 7381da177e4SLinus Torvalds */ 7391da177e4SLinus Torvalds 7401da177e4SLinus Torvalds param[0] = param[1] = 0xa5; /* initialize with invalid values */ 7411da177e4SLinus Torvalds if (ps2_command(ps2dev, param, ATKBD_CMD_GETID)) { 7421da177e4SLinus Torvalds 7431da177e4SLinus Torvalds /* 7441da177e4SLinus Torvalds * If the get ID command failed, we check if we can at least set the LEDs on 7451da177e4SLinus Torvalds * the keyboard. This should work on every keyboard out there. It also turns 7461da177e4SLinus Torvalds * the LEDs off, which we want anyway. 7471da177e4SLinus Torvalds */ 7481da177e4SLinus Torvalds param[0] = 0; 7491da177e4SLinus Torvalds if (ps2_command(ps2dev, param, ATKBD_CMD_SETLEDS)) 7501da177e4SLinus Torvalds return -1; 7511da177e4SLinus Torvalds atkbd->id = 0xabba; 7521da177e4SLinus Torvalds return 0; 7531da177e4SLinus Torvalds } 7541da177e4SLinus Torvalds 7559807879bSDmitry Torokhov if (!ps2_is_keyboard_id(param[0])) 7561da177e4SLinus Torvalds return -1; 7571da177e4SLinus Torvalds 7581da177e4SLinus Torvalds atkbd->id = (param[0] << 8) | param[1]; 7591da177e4SLinus Torvalds 7601da177e4SLinus Torvalds if (atkbd->id == 0xaca1 && atkbd->translated) { 761a9a1f9c3SDmitry Torokhov dev_err(&ps2dev->serio->dev, 762236d6a77SDmitry Torokhov "NCD terminal keyboards are only supported on non-translating controllers. " 763a9a1f9c3SDmitry Torokhov "Use i8042.direct=1 to disable translation.\n"); 7641da177e4SLinus Torvalds return -1; 7651da177e4SLinus Torvalds } 7661da177e4SLinus Torvalds 767*be2d7e42SShawn Nematbakhsh /* 768*be2d7e42SShawn Nematbakhsh * Make sure nothing is coming from the keyboard and disturbs our 769*be2d7e42SShawn Nematbakhsh * internal state. 770*be2d7e42SShawn Nematbakhsh */ 771*be2d7e42SShawn Nematbakhsh atkbd_deactivate(atkbd); 772*be2d7e42SShawn Nematbakhsh 7731da177e4SLinus Torvalds return 0; 7741da177e4SLinus Torvalds } 7751da177e4SLinus Torvalds 7761da177e4SLinus Torvalds /* 7771da177e4SLinus Torvalds * atkbd_select_set checks if a keyboard has a working Set 3 support, and 7781da177e4SLinus Torvalds * sets it into that. Unfortunately there are keyboards that can be switched 7791da177e4SLinus Torvalds * to Set 3, but don't work well in that (BTC Multimedia ...) 7801da177e4SLinus Torvalds */ 7811da177e4SLinus Torvalds 7821da177e4SLinus Torvalds static int atkbd_select_set(struct atkbd *atkbd, int target_set, int allow_extra) 7831da177e4SLinus Torvalds { 7841da177e4SLinus Torvalds struct ps2dev *ps2dev = &atkbd->ps2dev; 7851da177e4SLinus Torvalds unsigned char param[2]; 7861da177e4SLinus Torvalds 787a9a1f9c3SDmitry Torokhov atkbd->extra = false; 7881da177e4SLinus Torvalds /* 7891da177e4SLinus Torvalds * For known special keyboards we can go ahead and set the correct set. 7901da177e4SLinus Torvalds * We check for NCD PS/2 Sun, NorthGate OmniKey 101 and 7911da177e4SLinus Torvalds * IBM RapidAccess / IBM EzButton / Chicony KBP-8993 keyboards. 7921da177e4SLinus Torvalds */ 7931da177e4SLinus Torvalds 7941da177e4SLinus Torvalds if (atkbd->translated) 7951da177e4SLinus Torvalds return 2; 7961da177e4SLinus Torvalds 7971da177e4SLinus Torvalds if (atkbd->id == 0xaca1) { 7981da177e4SLinus Torvalds param[0] = 3; 7991da177e4SLinus Torvalds ps2_command(ps2dev, param, ATKBD_CMD_SSCANSET); 8001da177e4SLinus Torvalds return 3; 8011da177e4SLinus Torvalds } 8021da177e4SLinus Torvalds 8031da177e4SLinus Torvalds if (allow_extra) { 8041da177e4SLinus Torvalds param[0] = 0x71; 8051da177e4SLinus Torvalds if (!ps2_command(ps2dev, param, ATKBD_CMD_EX_ENABLE)) { 806a9a1f9c3SDmitry Torokhov atkbd->extra = true; 8071da177e4SLinus Torvalds return 2; 8081da177e4SLinus Torvalds } 8091da177e4SLinus Torvalds } 8101da177e4SLinus Torvalds 8118c5188b6SBenjamin LaHaise if (atkbd_terminal) { 8128c5188b6SBenjamin LaHaise ps2_command(ps2dev, param, ATKBD_CMD_SETALL_MB); 8138c5188b6SBenjamin LaHaise return 3; 8148c5188b6SBenjamin LaHaise } 8158c5188b6SBenjamin LaHaise 8161da177e4SLinus Torvalds if (target_set != 3) 8171da177e4SLinus Torvalds return 2; 8181da177e4SLinus Torvalds 8191da177e4SLinus Torvalds if (!ps2_command(ps2dev, param, ATKBD_CMD_OK_GETID)) { 8201da177e4SLinus Torvalds atkbd->id = param[0] << 8 | param[1]; 8211da177e4SLinus Torvalds return 2; 8221da177e4SLinus Torvalds } 8231da177e4SLinus Torvalds 8241da177e4SLinus Torvalds param[0] = 3; 8251da177e4SLinus Torvalds if (ps2_command(ps2dev, param, ATKBD_CMD_SSCANSET)) 8261da177e4SLinus Torvalds return 2; 8271da177e4SLinus Torvalds 8281da177e4SLinus Torvalds param[0] = 0; 8291da177e4SLinus Torvalds if (ps2_command(ps2dev, param, ATKBD_CMD_GSCANSET)) 8301da177e4SLinus Torvalds return 2; 8311da177e4SLinus Torvalds 8321da177e4SLinus Torvalds if (param[0] != 3) { 8331da177e4SLinus Torvalds param[0] = 2; 8341da177e4SLinus Torvalds if (ps2_command(ps2dev, param, ATKBD_CMD_SSCANSET)) 8351da177e4SLinus Torvalds return 2; 8361da177e4SLinus Torvalds } 8371da177e4SLinus Torvalds 8381da177e4SLinus Torvalds ps2_command(ps2dev, param, ATKBD_CMD_SETALL_MBR); 8391da177e4SLinus Torvalds 8401da177e4SLinus Torvalds return 3; 8411da177e4SLinus Torvalds } 8421da177e4SLinus Torvalds 843fc0eb28cSDmitry Torokhov static int atkbd_reset_state(struct atkbd *atkbd) 844fc0eb28cSDmitry Torokhov { 845fc0eb28cSDmitry Torokhov struct ps2dev *ps2dev = &atkbd->ps2dev; 846fc0eb28cSDmitry Torokhov unsigned char param[1]; 847fc0eb28cSDmitry Torokhov 848fc0eb28cSDmitry Torokhov /* 849fc0eb28cSDmitry Torokhov * Set the LEDs to a predefined state (all off). 850fc0eb28cSDmitry Torokhov */ 851fc0eb28cSDmitry Torokhov 852fc0eb28cSDmitry Torokhov param[0] = 0; 853fc0eb28cSDmitry Torokhov if (ps2_command(ps2dev, param, ATKBD_CMD_SETLEDS)) 854fc0eb28cSDmitry Torokhov return -1; 855fc0eb28cSDmitry Torokhov 856fc0eb28cSDmitry Torokhov /* 857fc0eb28cSDmitry Torokhov * Set autorepeat to fastest possible. 858fc0eb28cSDmitry Torokhov */ 859fc0eb28cSDmitry Torokhov 860fc0eb28cSDmitry Torokhov param[0] = 0; 861fc0eb28cSDmitry Torokhov if (ps2_command(ps2dev, param, ATKBD_CMD_SETREP)) 862fc0eb28cSDmitry Torokhov return -1; 863fc0eb28cSDmitry Torokhov 864fc0eb28cSDmitry Torokhov return 0; 865fc0eb28cSDmitry Torokhov } 866fc0eb28cSDmitry Torokhov 8671da177e4SLinus Torvalds /* 8681da177e4SLinus Torvalds * atkbd_cleanup() restores the keyboard state so that BIOS is happy after a 8691da177e4SLinus Torvalds * reboot. 8701da177e4SLinus Torvalds */ 8711da177e4SLinus Torvalds 8721da177e4SLinus Torvalds static void atkbd_cleanup(struct serio *serio) 8731da177e4SLinus Torvalds { 8741da177e4SLinus Torvalds struct atkbd *atkbd = serio_get_drvdata(serio); 87557f5b159SDmitry Torokhov 87657f5b159SDmitry Torokhov atkbd_disable(atkbd); 8774a299bf5SDmitry Torokhov ps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_DEF); 8781da177e4SLinus Torvalds } 8791da177e4SLinus Torvalds 8801da177e4SLinus Torvalds 8811da177e4SLinus Torvalds /* 8821da177e4SLinus Torvalds * atkbd_disconnect() closes and frees. 8831da177e4SLinus Torvalds */ 8841da177e4SLinus Torvalds 8851da177e4SLinus Torvalds static void atkbd_disconnect(struct serio *serio) 8861da177e4SLinus Torvalds { 8871da177e4SLinus Torvalds struct atkbd *atkbd = serio_get_drvdata(serio); 8881da177e4SLinus Torvalds 88959b01513SEric W. Biederman sysfs_remove_group(&serio->dev.kobj, &atkbd_attribute_group); 89059b01513SEric W. Biederman 8911da177e4SLinus Torvalds atkbd_disable(atkbd); 8921da177e4SLinus Torvalds 8930ef7a26aSDmitry Torokhov input_unregister_device(atkbd->dev); 8940ef7a26aSDmitry Torokhov 8950ef7a26aSDmitry Torokhov /* 8960ef7a26aSDmitry Torokhov * Make sure we don't have a command in flight. 8970ef7a26aSDmitry Torokhov * Note that since atkbd->enabled is false event work will keep 8980ef7a26aSDmitry Torokhov * rescheduling itself until it gets canceled and will not try 8990ef7a26aSDmitry Torokhov * accessing freed input device or serio port. 9000ef7a26aSDmitry Torokhov */ 901d6d79a78SJiri Pirko cancel_delayed_work_sync(&atkbd->event_work); 9021da177e4SLinus Torvalds 9031da177e4SLinus Torvalds serio_close(serio); 9041da177e4SLinus Torvalds serio_set_drvdata(serio, NULL); 9051da177e4SLinus Torvalds kfree(atkbd); 9061da177e4SLinus Torvalds } 9071da177e4SLinus Torvalds 908554101e3SGiel de Nijs /* 90939191698SDaniel Mierswa * generate release events for the keycodes given in data 91039191698SDaniel Mierswa */ 91139191698SDaniel Mierswa static void atkbd_apply_forced_release_keylist(struct atkbd* atkbd, 91239191698SDaniel Mierswa const void *data) 91339191698SDaniel Mierswa { 91439191698SDaniel Mierswa const unsigned int *keys = data; 91539191698SDaniel Mierswa unsigned int i; 91639191698SDaniel Mierswa 91739191698SDaniel Mierswa if (atkbd->set == 2) 91839191698SDaniel Mierswa for (i = 0; keys[i] != -1U; i++) 91939191698SDaniel Mierswa __set_bit(keys[i], atkbd->force_release_mask); 92039191698SDaniel Mierswa } 92139191698SDaniel Mierswa 92239191698SDaniel Mierswa /* 92361579ba8SMatthew Garrett * Most special keys (Fn+F?) on Dell laptops do not generate release 924554101e3SGiel de Nijs * events so we have to do it ourselves. 925554101e3SGiel de Nijs */ 92639191698SDaniel Mierswa static unsigned int atkbd_dell_laptop_forced_release_keys[] = { 92739191698SDaniel Mierswa 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8f, 0x93, -1U 928554101e3SGiel de Nijs }; 9291da177e4SLinus Torvalds 9301da177e4SLinus Torvalds /* 9315a54c011SJiri Kosina * Perform fixup for HP system that doesn't generate release 9325a54c011SJiri Kosina * for its video switch 9335a54c011SJiri Kosina */ 93439191698SDaniel Mierswa static unsigned int atkbd_hp_forced_release_keys[] = { 93539191698SDaniel Mierswa 0x94, -1U 9365a54c011SJiri Kosina }; 9375a54c011SJiri Kosina 9385a54c011SJiri Kosina /* 939e04126c7SBarry Carroll * Samsung NC10,NC20 with Fn+F? key release not working 9404200844bSStuart Hopkins */ 94139191698SDaniel Mierswa static unsigned int atkbd_samsung_forced_release_keys[] = { 94239191698SDaniel Mierswa 0x82, 0x83, 0x84, 0x86, 0x88, 0x89, 0xb3, 0xf7, 0xf9, -1U 9434200844bSStuart Hopkins }; 9444200844bSStuart Hopkins 9454200844bSStuart Hopkins /* 946f0a14de2SSimon Davie * Amilo Pi 3525 key release for Fn+Volume keys not working 947f0a14de2SSimon Davie */ 948f0a14de2SSimon Davie static unsigned int atkbd_amilo_pi3525_forced_release_keys[] = { 949f0a14de2SSimon Davie 0x20, 0xa0, 0x2e, 0xae, 0x30, 0xb0, -1U 950f0a14de2SSimon Davie }; 951f0a14de2SSimon Davie 952f0a14de2SSimon Davie /* 9539166d0f6SAdrian Batzill * Amilo Xi 3650 key release for light touch bar not working 9549166d0f6SAdrian Batzill */ 9559166d0f6SAdrian Batzill static unsigned int atkbd_amilo_xi3650_forced_release_keys[] = { 9569166d0f6SAdrian Batzill 0x67, 0xed, 0x90, 0xa2, 0x99, 0xa4, 0xae, 0xb0, -1U 9579166d0f6SAdrian Batzill }; 9589166d0f6SAdrian Batzill 9599166d0f6SAdrian Batzill /* 960032e46cbSJerone Young * Soltech TA12 system with broken key release on volume keys and mute key 961032e46cbSJerone Young */ 962032e46cbSJerone Young static unsigned int atkdb_soltech_ta12_forced_release_keys[] = { 963032e46cbSJerone Young 0xa0, 0xae, 0xb0, -1U 964032e46cbSJerone Young }; 965032e46cbSJerone Young 966032e46cbSJerone Young /* 967000c2a35SHerton Ronaldo Krzesinski * Many notebooks don't send key release event for volume up/down 968000c2a35SHerton Ronaldo Krzesinski * keys, with key list below common among them 969000c2a35SHerton Ronaldo Krzesinski */ 970000c2a35SHerton Ronaldo Krzesinski static unsigned int atkbd_volume_forced_release_keys[] = { 971000c2a35SHerton Ronaldo Krzesinski 0xae, 0xb0, -1U 972000c2a35SHerton Ronaldo Krzesinski }; 973000c2a35SHerton Ronaldo Krzesinski 974000c2a35SHerton Ronaldo Krzesinski /* 975e5713069SJamie Lentin * OQO 01+ multimedia keys (64--66) generate e0 6x upon release whereas 976e5713069SJamie Lentin * they should be generating e4-e6 (0x80 | code). 977e5713069SJamie Lentin */ 978e5713069SJamie Lentin static unsigned int atkbd_oqo_01plus_scancode_fixup(struct atkbd *atkbd, 979e5713069SJamie Lentin unsigned int code) 980e5713069SJamie Lentin { 981e5713069SJamie Lentin if (atkbd->translated && atkbd->emul == 1 && 982e5713069SJamie Lentin (code == 0x64 || code == 0x65 || code == 0x66)) { 983e5713069SJamie Lentin atkbd->emul = 0; 984e5713069SJamie Lentin code |= 0x80; 985e5713069SJamie Lentin } 986e5713069SJamie Lentin 987e5713069SJamie Lentin return code; 988e5713069SJamie Lentin } 989e5713069SJamie Lentin 990e5713069SJamie Lentin /* 9913c42f0c3SDmitry Torokhov * atkbd_set_keycode_table() initializes keyboard's keycode table 9921da177e4SLinus Torvalds * according to the selected scancode set 9931da177e4SLinus Torvalds */ 9941da177e4SLinus Torvalds 9951da177e4SLinus Torvalds static void atkbd_set_keycode_table(struct atkbd *atkbd) 9961da177e4SLinus Torvalds { 997554101e3SGiel de Nijs unsigned int scancode; 9981da177e4SLinus Torvalds int i, j; 9991da177e4SLinus Torvalds 10001da177e4SLinus Torvalds memset(atkbd->keycode, 0, sizeof(atkbd->keycode)); 10011ba36e11SDmitry Torokhov bitmap_zero(atkbd->force_release_mask, ATKBD_KEYMAP_SIZE); 10021da177e4SLinus Torvalds 10031da177e4SLinus Torvalds if (atkbd->translated) { 10041da177e4SLinus Torvalds for (i = 0; i < 128; i++) { 1005554101e3SGiel de Nijs scancode = atkbd_unxlate_table[i]; 1006554101e3SGiel de Nijs atkbd->keycode[i] = atkbd_set2_keycode[scancode]; 1007554101e3SGiel de Nijs atkbd->keycode[i | 0x80] = atkbd_set2_keycode[scancode | 0x80]; 10081da177e4SLinus Torvalds if (atkbd->scroll) 10091da177e4SLinus Torvalds for (j = 0; j < ARRAY_SIZE(atkbd_scroll_keys); j++) 1010554101e3SGiel de Nijs if ((scancode | 0x80) == atkbd_scroll_keys[j].set2) 10111da177e4SLinus Torvalds atkbd->keycode[i | 0x80] = atkbd_scroll_keys[j].keycode; 10121da177e4SLinus Torvalds } 10131da177e4SLinus Torvalds } else if (atkbd->set == 3) { 10141da177e4SLinus Torvalds memcpy(atkbd->keycode, atkbd_set3_keycode, sizeof(atkbd->keycode)); 10151da177e4SLinus Torvalds } else { 10161da177e4SLinus Torvalds memcpy(atkbd->keycode, atkbd_set2_keycode, sizeof(atkbd->keycode)); 10171da177e4SLinus Torvalds 10181da177e4SLinus Torvalds if (atkbd->scroll) 1019554101e3SGiel de Nijs for (i = 0; i < ARRAY_SIZE(atkbd_scroll_keys); i++) { 1020554101e3SGiel de Nijs scancode = atkbd_scroll_keys[i].set2; 1021554101e3SGiel de Nijs atkbd->keycode[scancode] = atkbd_scroll_keys[i].keycode; 1022554101e3SGiel de Nijs } 10231da177e4SLinus Torvalds } 10240ae051a1SDmitry Torokhov 1025554101e3SGiel de Nijs /* 1026554101e3SGiel de Nijs * HANGEUL and HANJA keys do not send release events so we need to 1027554101e3SGiel de Nijs * generate such events ourselves 1028554101e3SGiel de Nijs */ 1029554101e3SGiel de Nijs scancode = atkbd_compat_scancode(atkbd, ATKBD_RET_HANGEUL); 1030554101e3SGiel de Nijs atkbd->keycode[scancode] = KEY_HANGEUL; 1031554101e3SGiel de Nijs __set_bit(scancode, atkbd->force_release_mask); 1032554101e3SGiel de Nijs 1033554101e3SGiel de Nijs scancode = atkbd_compat_scancode(atkbd, ATKBD_RET_HANJA); 1034554101e3SGiel de Nijs atkbd->keycode[scancode] = KEY_HANJA; 1035554101e3SGiel de Nijs __set_bit(scancode, atkbd->force_release_mask); 1036554101e3SGiel de Nijs 1037554101e3SGiel de Nijs /* 1038554101e3SGiel de Nijs * Perform additional fixups 1039554101e3SGiel de Nijs */ 1040554101e3SGiel de Nijs if (atkbd_platform_fixup) 104139191698SDaniel Mierswa atkbd_platform_fixup(atkbd, atkbd_platform_fixup_data); 10421da177e4SLinus Torvalds } 10431da177e4SLinus Torvalds 10441da177e4SLinus Torvalds /* 10451da177e4SLinus Torvalds * atkbd_set_device_attrs() sets up keyboard's input device structure 10461da177e4SLinus Torvalds */ 10471da177e4SLinus Torvalds 10481da177e4SLinus Torvalds static void atkbd_set_device_attrs(struct atkbd *atkbd) 10491da177e4SLinus Torvalds { 10503c42f0c3SDmitry Torokhov struct input_dev *input_dev = atkbd->dev; 10511da177e4SLinus Torvalds int i; 10521da177e4SLinus Torvalds 10533c42f0c3SDmitry Torokhov if (atkbd->extra) 1054ea08c6faSDmitry Torokhov snprintf(atkbd->name, sizeof(atkbd->name), 1055ea08c6faSDmitry Torokhov "AT Set 2 Extra keyboard"); 10563c42f0c3SDmitry Torokhov else 1057ea08c6faSDmitry Torokhov snprintf(atkbd->name, sizeof(atkbd->name), 1058ea08c6faSDmitry Torokhov "AT %s Set %d keyboard", 10593c42f0c3SDmitry Torokhov atkbd->translated ? "Translated" : "Raw", atkbd->set); 10601da177e4SLinus Torvalds 1061ea08c6faSDmitry Torokhov snprintf(atkbd->phys, sizeof(atkbd->phys), 1062ea08c6faSDmitry Torokhov "%s/input0", atkbd->ps2dev.serio->phys); 10631da177e4SLinus Torvalds 10643c42f0c3SDmitry Torokhov input_dev->name = atkbd->name; 10653c42f0c3SDmitry Torokhov input_dev->phys = atkbd->phys; 10663c42f0c3SDmitry Torokhov input_dev->id.bustype = BUS_I8042; 10673c42f0c3SDmitry Torokhov input_dev->id.vendor = 0x0001; 10683c42f0c3SDmitry Torokhov input_dev->id.product = atkbd->translated ? 1 : atkbd->set; 10693c42f0c3SDmitry Torokhov input_dev->id.version = atkbd->id; 10703c42f0c3SDmitry Torokhov input_dev->event = atkbd_event; 1071469ba4dfSDmitry Torokhov input_dev->dev.parent = &atkbd->ps2dev.serio->dev; 10721da177e4SLinus Torvalds 1073b356872fSDmitry Torokhov input_set_drvdata(input_dev, atkbd); 1074b356872fSDmitry Torokhov 10757b19ada2SJiri Slaby input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | 10767b19ada2SJiri Slaby BIT_MASK(EV_MSC); 10771da177e4SLinus Torvalds 10781da177e4SLinus Torvalds if (atkbd->write) { 10797b19ada2SJiri Slaby input_dev->evbit[0] |= BIT_MASK(EV_LED); 10807b19ada2SJiri Slaby input_dev->ledbit[0] = BIT_MASK(LED_NUML) | 10817b19ada2SJiri Slaby BIT_MASK(LED_CAPSL) | BIT_MASK(LED_SCROLLL); 10821da177e4SLinus Torvalds } 10831da177e4SLinus Torvalds 10841da177e4SLinus Torvalds if (atkbd->extra) 10857b19ada2SJiri Slaby input_dev->ledbit[0] |= BIT_MASK(LED_COMPOSE) | 10867b19ada2SJiri Slaby BIT_MASK(LED_SUSPEND) | BIT_MASK(LED_SLEEP) | 10877b19ada2SJiri Slaby BIT_MASK(LED_MUTE) | BIT_MASK(LED_MISC); 10881da177e4SLinus Torvalds 10891da177e4SLinus Torvalds if (!atkbd->softrepeat) { 10903c42f0c3SDmitry Torokhov input_dev->rep[REP_DELAY] = 250; 10913c42f0c3SDmitry Torokhov input_dev->rep[REP_PERIOD] = 33; 10921da177e4SLinus Torvalds } 10931da177e4SLinus Torvalds 10947b19ada2SJiri Slaby input_dev->mscbit[0] = atkbd->softraw ? BIT_MASK(MSC_SCAN) : 10957b19ada2SJiri Slaby BIT_MASK(MSC_RAW) | BIT_MASK(MSC_SCAN); 10961da177e4SLinus Torvalds 10971da177e4SLinus Torvalds if (atkbd->scroll) { 10987b19ada2SJiri Slaby input_dev->evbit[0] |= BIT_MASK(EV_REL); 10997b19ada2SJiri Slaby input_dev->relbit[0] = BIT_MASK(REL_WHEEL) | 11007b19ada2SJiri Slaby BIT_MASK(REL_HWHEEL); 1101f6d65610SDmitry Torokhov __set_bit(BTN_MIDDLE, input_dev->keybit); 11021da177e4SLinus Torvalds } 11031da177e4SLinus Torvalds 11043c42f0c3SDmitry Torokhov input_dev->keycode = atkbd->keycode; 1105f6d65610SDmitry Torokhov input_dev->keycodesize = sizeof(unsigned short); 11063c42f0c3SDmitry Torokhov input_dev->keycodemax = ARRAY_SIZE(atkbd_set2_keycode); 11071da177e4SLinus Torvalds 11084b70858bSDmitry Torokhov for (i = 0; i < ATKBD_KEYMAP_SIZE; i++) { 11094b70858bSDmitry Torokhov if (atkbd->keycode[i] != KEY_RESERVED && 11104b70858bSDmitry Torokhov atkbd->keycode[i] != ATKBD_KEY_NULL && 11114b70858bSDmitry Torokhov atkbd->keycode[i] < ATKBD_SPECIAL) { 1112f6d65610SDmitry Torokhov __set_bit(atkbd->keycode[i], input_dev->keybit); 11131da177e4SLinus Torvalds } 11144b70858bSDmitry Torokhov } 11154b70858bSDmitry Torokhov } 11161da177e4SLinus Torvalds 11171da177e4SLinus Torvalds /* 11181da177e4SLinus Torvalds * atkbd_connect() is called when the serio module finds an interface 11191da177e4SLinus Torvalds * that isn't handled yet by an appropriate device driver. We check if 11201da177e4SLinus Torvalds * there is an AT keyboard out there and if yes, we register ourselves 11211da177e4SLinus Torvalds * to the input module. 11221da177e4SLinus Torvalds */ 11231da177e4SLinus Torvalds 11241da177e4SLinus Torvalds static int atkbd_connect(struct serio *serio, struct serio_driver *drv) 11251da177e4SLinus Torvalds { 11261da177e4SLinus Torvalds struct atkbd *atkbd; 11273c42f0c3SDmitry Torokhov struct input_dev *dev; 11283c42f0c3SDmitry Torokhov int err = -ENOMEM; 11291da177e4SLinus Torvalds 11303c42f0c3SDmitry Torokhov atkbd = kzalloc(sizeof(struct atkbd), GFP_KERNEL); 11313c42f0c3SDmitry Torokhov dev = input_allocate_device(); 11323c42f0c3SDmitry Torokhov if (!atkbd || !dev) 11332b03b60eSDmitry Torokhov goto fail1; 11341da177e4SLinus Torvalds 11353c42f0c3SDmitry Torokhov atkbd->dev = dev; 11361da177e4SLinus Torvalds ps2_init(&atkbd->ps2dev, serio); 1137da4249c9SDmitry Torokhov INIT_DELAYED_WORK(&atkbd->event_work, atkbd_event_work); 113859b01513SEric W. Biederman mutex_init(&atkbd->mutex); 11391da177e4SLinus Torvalds 11401da177e4SLinus Torvalds switch (serio->id.type) { 11411da177e4SLinus Torvalds 11421da177e4SLinus Torvalds case SERIO_8042_XL: 1143a9a1f9c3SDmitry Torokhov atkbd->translated = true; 1144a9a1f9c3SDmitry Torokhov /* Fall through */ 1145a9a1f9c3SDmitry Torokhov 11461da177e4SLinus Torvalds case SERIO_8042: 11471da177e4SLinus Torvalds if (serio->write) 1148a9a1f9c3SDmitry Torokhov atkbd->write = true; 11491da177e4SLinus Torvalds break; 11501da177e4SLinus Torvalds } 11511da177e4SLinus Torvalds 11521da177e4SLinus Torvalds atkbd->softraw = atkbd_softraw; 11531da177e4SLinus Torvalds atkbd->softrepeat = atkbd_softrepeat; 11541da177e4SLinus Torvalds atkbd->scroll = atkbd_scroll; 11551da177e4SLinus Torvalds 11561da177e4SLinus Torvalds if (atkbd->softrepeat) 1157a9a1f9c3SDmitry Torokhov atkbd->softraw = true; 11581da177e4SLinus Torvalds 11591da177e4SLinus Torvalds serio_set_drvdata(serio, atkbd); 11601da177e4SLinus Torvalds 11611da177e4SLinus Torvalds err = serio_open(serio, drv); 11623c42f0c3SDmitry Torokhov if (err) 11632b03b60eSDmitry Torokhov goto fail2; 11641da177e4SLinus Torvalds 11651da177e4SLinus Torvalds if (atkbd->write) { 11661da177e4SLinus Torvalds 11671da177e4SLinus Torvalds if (atkbd_probe(atkbd)) { 11683c42f0c3SDmitry Torokhov err = -ENODEV; 11692b03b60eSDmitry Torokhov goto fail3; 11701da177e4SLinus Torvalds } 11711da177e4SLinus Torvalds 11721da177e4SLinus Torvalds atkbd->set = atkbd_select_set(atkbd, atkbd_set, atkbd_extra); 1173fc0eb28cSDmitry Torokhov atkbd_reset_state(atkbd); 11741da177e4SLinus Torvalds 11751da177e4SLinus Torvalds } else { 11761da177e4SLinus Torvalds atkbd->set = 2; 11771da177e4SLinus Torvalds atkbd->id = 0xab00; 11781da177e4SLinus Torvalds } 11791da177e4SLinus Torvalds 11801da177e4SLinus Torvalds atkbd_set_keycode_table(atkbd); 11811da177e4SLinus Torvalds atkbd_set_device_attrs(atkbd); 11821da177e4SLinus Torvalds 11832b03b60eSDmitry Torokhov err = sysfs_create_group(&serio->dev.kobj, &atkbd_attribute_group); 11842b03b60eSDmitry Torokhov if (err) 11852b03b60eSDmitry Torokhov goto fail3; 11861da177e4SLinus Torvalds 11871da177e4SLinus Torvalds atkbd_enable(atkbd); 1188*be2d7e42SShawn Nematbakhsh if (serio->write) 1189*be2d7e42SShawn Nematbakhsh atkbd_activate(atkbd); 11901da177e4SLinus Torvalds 11912b03b60eSDmitry Torokhov err = input_register_device(atkbd->dev); 11922b03b60eSDmitry Torokhov if (err) 11932b03b60eSDmitry Torokhov goto fail4; 11941da177e4SLinus Torvalds 11951da177e4SLinus Torvalds return 0; 11963c42f0c3SDmitry Torokhov 11972b03b60eSDmitry Torokhov fail4: sysfs_remove_group(&serio->dev.kobj, &atkbd_attribute_group); 11982b03b60eSDmitry Torokhov fail3: serio_close(serio); 11992b03b60eSDmitry Torokhov fail2: serio_set_drvdata(serio, NULL); 12002b03b60eSDmitry Torokhov fail1: input_free_device(dev); 12013c42f0c3SDmitry Torokhov kfree(atkbd); 12023c42f0c3SDmitry Torokhov return err; 12031da177e4SLinus Torvalds } 12041da177e4SLinus Torvalds 12051da177e4SLinus Torvalds /* 12061da177e4SLinus Torvalds * atkbd_reconnect() tries to restore keyboard into a sane state and is 12071da177e4SLinus Torvalds * most likely called on resume. 12081da177e4SLinus Torvalds */ 12091da177e4SLinus Torvalds 12101da177e4SLinus Torvalds static int atkbd_reconnect(struct serio *serio) 12111da177e4SLinus Torvalds { 12121da177e4SLinus Torvalds struct atkbd *atkbd = serio_get_drvdata(serio); 12131da177e4SLinus Torvalds struct serio_driver *drv = serio->drv; 121459b01513SEric W. Biederman int retval = -1; 12151da177e4SLinus Torvalds 12161da177e4SLinus Torvalds if (!atkbd || !drv) { 1217a9a1f9c3SDmitry Torokhov dev_dbg(&serio->dev, 1218a9a1f9c3SDmitry Torokhov "reconnect request, but serio is disconnected, ignoring...\n"); 12191da177e4SLinus Torvalds return -1; 12201da177e4SLinus Torvalds } 12211da177e4SLinus Torvalds 122259b01513SEric W. Biederman mutex_lock(&atkbd->mutex); 122359b01513SEric W. Biederman 12241da177e4SLinus Torvalds atkbd_disable(atkbd); 12251da177e4SLinus Torvalds 12261da177e4SLinus Torvalds if (atkbd->write) { 12271da177e4SLinus Torvalds if (atkbd_probe(atkbd)) 122859b01513SEric W. Biederman goto out; 122959b01513SEric W. Biederman 12301da177e4SLinus Torvalds if (atkbd->set != atkbd_select_set(atkbd, atkbd->set, atkbd->extra)) 123159b01513SEric W. Biederman goto out; 12321da177e4SLinus Torvalds 1233d4119bdaSDmitry Torokhov /* 1234d4119bdaSDmitry Torokhov * Restore LED state and repeat rate. While input core 1235d4119bdaSDmitry Torokhov * will do this for us at resume time reconnect may happen 1236d4119bdaSDmitry Torokhov * because user requested it via sysfs or simply because 1237d4119bdaSDmitry Torokhov * keyboard was unplugged and plugged in again so we need 1238d4119bdaSDmitry Torokhov * to do it ourselves here. 1239d4119bdaSDmitry Torokhov */ 1240d4119bdaSDmitry Torokhov atkbd_set_leds(atkbd); 1241d4119bdaSDmitry Torokhov if (!atkbd->softrepeat) 1242d4119bdaSDmitry Torokhov atkbd_set_repeat_rate(atkbd); 1243d4119bdaSDmitry Torokhov 12441da177e4SLinus Torvalds } 12451da177e4SLinus Torvalds 1246*be2d7e42SShawn Nematbakhsh /* 1247*be2d7e42SShawn Nematbakhsh * Reset our state machine in case reconnect happened in the middle 1248*be2d7e42SShawn Nematbakhsh * of multi-byte scancode. 1249*be2d7e42SShawn Nematbakhsh */ 1250*be2d7e42SShawn Nematbakhsh atkbd->xl_bit = 0; 1251*be2d7e42SShawn Nematbakhsh atkbd->emul = 0; 1252*be2d7e42SShawn Nematbakhsh 12531da177e4SLinus Torvalds atkbd_enable(atkbd); 1254*be2d7e42SShawn Nematbakhsh if (atkbd->write) 1255*be2d7e42SShawn Nematbakhsh atkbd_activate(atkbd); 1256*be2d7e42SShawn Nematbakhsh 125759b01513SEric W. Biederman retval = 0; 12581da177e4SLinus Torvalds 125959b01513SEric W. Biederman out: 126059b01513SEric W. Biederman mutex_unlock(&atkbd->mutex); 126159b01513SEric W. Biederman return retval; 12621da177e4SLinus Torvalds } 12631da177e4SLinus Torvalds 12641da177e4SLinus Torvalds static struct serio_device_id atkbd_serio_ids[] = { 12651da177e4SLinus Torvalds { 12661da177e4SLinus Torvalds .type = SERIO_8042, 12671da177e4SLinus Torvalds .proto = SERIO_ANY, 12681da177e4SLinus Torvalds .id = SERIO_ANY, 12691da177e4SLinus Torvalds .extra = SERIO_ANY, 12701da177e4SLinus Torvalds }, 12711da177e4SLinus Torvalds { 12721da177e4SLinus Torvalds .type = SERIO_8042_XL, 12731da177e4SLinus Torvalds .proto = SERIO_ANY, 12741da177e4SLinus Torvalds .id = SERIO_ANY, 12751da177e4SLinus Torvalds .extra = SERIO_ANY, 12761da177e4SLinus Torvalds }, 12771da177e4SLinus Torvalds { 12781da177e4SLinus Torvalds .type = SERIO_RS232, 12791da177e4SLinus Torvalds .proto = SERIO_PS2SER, 12801da177e4SLinus Torvalds .id = SERIO_ANY, 12811da177e4SLinus Torvalds .extra = SERIO_ANY, 12821da177e4SLinus Torvalds }, 12831da177e4SLinus Torvalds { 0 } 12841da177e4SLinus Torvalds }; 12851da177e4SLinus Torvalds 12861da177e4SLinus Torvalds MODULE_DEVICE_TABLE(serio, atkbd_serio_ids); 12871da177e4SLinus Torvalds 12881da177e4SLinus Torvalds static struct serio_driver atkbd_drv = { 12891da177e4SLinus Torvalds .driver = { 12901da177e4SLinus Torvalds .name = "atkbd", 12911da177e4SLinus Torvalds }, 12921da177e4SLinus Torvalds .description = DRIVER_DESC, 12931da177e4SLinus Torvalds .id_table = atkbd_serio_ids, 12941da177e4SLinus Torvalds .interrupt = atkbd_interrupt, 12951da177e4SLinus Torvalds .connect = atkbd_connect, 12961da177e4SLinus Torvalds .reconnect = atkbd_reconnect, 12971da177e4SLinus Torvalds .disconnect = atkbd_disconnect, 12981da177e4SLinus Torvalds .cleanup = atkbd_cleanup, 12991da177e4SLinus Torvalds }; 13001da177e4SLinus Torvalds 13011da177e4SLinus Torvalds static ssize_t atkbd_attr_show_helper(struct device *dev, char *buf, 13021da177e4SLinus Torvalds ssize_t (*handler)(struct atkbd *, char *)) 13031da177e4SLinus Torvalds { 13041da177e4SLinus Torvalds struct serio *serio = to_serio_port(dev); 130559b01513SEric W. Biederman struct atkbd *atkbd = serio_get_drvdata(serio); 13061da177e4SLinus Torvalds 130759b01513SEric W. Biederman return handler(atkbd, buf); 13081da177e4SLinus Torvalds } 13091da177e4SLinus Torvalds 13101da177e4SLinus Torvalds static ssize_t atkbd_attr_set_helper(struct device *dev, const char *buf, size_t count, 13111da177e4SLinus Torvalds ssize_t (*handler)(struct atkbd *, const char *, size_t)) 13121da177e4SLinus Torvalds { 13131da177e4SLinus Torvalds struct serio *serio = to_serio_port(dev); 131459b01513SEric W. Biederman struct atkbd *atkbd = serio_get_drvdata(serio); 13151da177e4SLinus Torvalds int retval; 13161da177e4SLinus Torvalds 131759b01513SEric W. Biederman retval = mutex_lock_interruptible(&atkbd->mutex); 13181da177e4SLinus Torvalds if (retval) 13191da177e4SLinus Torvalds return retval; 13201da177e4SLinus Torvalds 13211da177e4SLinus Torvalds atkbd_disable(atkbd); 13221da177e4SLinus Torvalds retval = handler(atkbd, buf, count); 13231da177e4SLinus Torvalds atkbd_enable(atkbd); 13241da177e4SLinus Torvalds 132559b01513SEric W. Biederman mutex_unlock(&atkbd->mutex); 132659b01513SEric W. Biederman 13271da177e4SLinus Torvalds return retval; 13281da177e4SLinus Torvalds } 13291da177e4SLinus Torvalds 13301da177e4SLinus Torvalds static ssize_t atkbd_show_extra(struct atkbd *atkbd, char *buf) 13311da177e4SLinus Torvalds { 13321da177e4SLinus Torvalds return sprintf(buf, "%d\n", atkbd->extra ? 1 : 0); 13331da177e4SLinus Torvalds } 13341da177e4SLinus Torvalds 13351da177e4SLinus Torvalds static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t count) 13361da177e4SLinus Torvalds { 13372b03b60eSDmitry Torokhov struct input_dev *old_dev, *new_dev; 133876496e7aSJJ Ding unsigned int value; 13392b03b60eSDmitry Torokhov int err; 1340a9a1f9c3SDmitry Torokhov bool old_extra; 1341a9a1f9c3SDmitry Torokhov unsigned char old_set; 13421da177e4SLinus Torvalds 13431da177e4SLinus Torvalds if (!atkbd->write) 13441da177e4SLinus Torvalds return -EIO; 13451da177e4SLinus Torvalds 134676496e7aSJJ Ding err = kstrtouint(buf, 10, &value); 134776496e7aSJJ Ding if (err) 134876496e7aSJJ Ding return err; 134976496e7aSJJ Ding 135076496e7aSJJ Ding if (value > 1) 13511da177e4SLinus Torvalds return -EINVAL; 13521da177e4SLinus Torvalds 13531da177e4SLinus Torvalds if (atkbd->extra != value) { 13543c42f0c3SDmitry Torokhov /* 13553c42f0c3SDmitry Torokhov * Since device's properties will change we need to 13562b03b60eSDmitry Torokhov * unregister old device. But allocate and register 13572b03b60eSDmitry Torokhov * new one first to make sure we have it. 13583c42f0c3SDmitry Torokhov */ 13592b03b60eSDmitry Torokhov old_dev = atkbd->dev; 13602b03b60eSDmitry Torokhov old_extra = atkbd->extra; 13612b03b60eSDmitry Torokhov old_set = atkbd->set; 13622b03b60eSDmitry Torokhov 13632b03b60eSDmitry Torokhov new_dev = input_allocate_device(); 13642b03b60eSDmitry Torokhov if (!new_dev) 13653c42f0c3SDmitry Torokhov return -ENOMEM; 13662b03b60eSDmitry Torokhov 13673c42f0c3SDmitry Torokhov atkbd->dev = new_dev; 13681da177e4SLinus Torvalds atkbd->set = atkbd_select_set(atkbd, atkbd->set, value); 1369fc0eb28cSDmitry Torokhov atkbd_reset_state(atkbd); 13701da177e4SLinus Torvalds atkbd_activate(atkbd); 13712b03b60eSDmitry Torokhov atkbd_set_keycode_table(atkbd); 13721da177e4SLinus Torvalds atkbd_set_device_attrs(atkbd); 13732b03b60eSDmitry Torokhov 13742b03b60eSDmitry Torokhov err = input_register_device(atkbd->dev); 13752b03b60eSDmitry Torokhov if (err) { 13762b03b60eSDmitry Torokhov input_free_device(new_dev); 13772b03b60eSDmitry Torokhov 13782b03b60eSDmitry Torokhov atkbd->dev = old_dev; 13792b03b60eSDmitry Torokhov atkbd->set = atkbd_select_set(atkbd, old_set, old_extra); 13802b03b60eSDmitry Torokhov atkbd_set_keycode_table(atkbd); 13812b03b60eSDmitry Torokhov atkbd_set_device_attrs(atkbd); 13822b03b60eSDmitry Torokhov 13832b03b60eSDmitry Torokhov return err; 13842b03b60eSDmitry Torokhov } 13852b03b60eSDmitry Torokhov input_unregister_device(old_dev); 13862b03b60eSDmitry Torokhov 13871da177e4SLinus Torvalds } 13881da177e4SLinus Torvalds return count; 13891da177e4SLinus Torvalds } 13901da177e4SLinus Torvalds 13911ba36e11SDmitry Torokhov static ssize_t atkbd_show_force_release(struct atkbd *atkbd, char *buf) 13921ba36e11SDmitry Torokhov { 13931ba36e11SDmitry Torokhov size_t len = bitmap_scnlistprintf(buf, PAGE_SIZE - 2, 13941ba36e11SDmitry Torokhov atkbd->force_release_mask, ATKBD_KEYMAP_SIZE); 13951ba36e11SDmitry Torokhov 13961ba36e11SDmitry Torokhov buf[len++] = '\n'; 13971ba36e11SDmitry Torokhov buf[len] = '\0'; 13981ba36e11SDmitry Torokhov 13991ba36e11SDmitry Torokhov return len; 14001ba36e11SDmitry Torokhov } 14011ba36e11SDmitry Torokhov 14021ba36e11SDmitry Torokhov static ssize_t atkbd_set_force_release(struct atkbd *atkbd, 14031ba36e11SDmitry Torokhov const char *buf, size_t count) 14041ba36e11SDmitry Torokhov { 14051ba36e11SDmitry Torokhov /* 64 bytes on stack should be acceptable */ 14061ba36e11SDmitry Torokhov DECLARE_BITMAP(new_mask, ATKBD_KEYMAP_SIZE); 14071ba36e11SDmitry Torokhov int err; 14081ba36e11SDmitry Torokhov 14091ba36e11SDmitry Torokhov err = bitmap_parselist(buf, new_mask, ATKBD_KEYMAP_SIZE); 14101ba36e11SDmitry Torokhov if (err) 14111ba36e11SDmitry Torokhov return err; 14121ba36e11SDmitry Torokhov 14131ba36e11SDmitry Torokhov memcpy(atkbd->force_release_mask, new_mask, sizeof(atkbd->force_release_mask)); 14141ba36e11SDmitry Torokhov return count; 14151ba36e11SDmitry Torokhov } 14161ba36e11SDmitry Torokhov 14171ba36e11SDmitry Torokhov 14181da177e4SLinus Torvalds static ssize_t atkbd_show_scroll(struct atkbd *atkbd, char *buf) 14191da177e4SLinus Torvalds { 14201da177e4SLinus Torvalds return sprintf(buf, "%d\n", atkbd->scroll ? 1 : 0); 14211da177e4SLinus Torvalds } 14221da177e4SLinus Torvalds 14231da177e4SLinus Torvalds static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t count) 14241da177e4SLinus Torvalds { 14252b03b60eSDmitry Torokhov struct input_dev *old_dev, *new_dev; 142676496e7aSJJ Ding unsigned int value; 14272b03b60eSDmitry Torokhov int err; 1428a9a1f9c3SDmitry Torokhov bool old_scroll; 14291da177e4SLinus Torvalds 143076496e7aSJJ Ding err = kstrtouint(buf, 10, &value); 143176496e7aSJJ Ding if (err) 143276496e7aSJJ Ding return err; 143376496e7aSJJ Ding 143476496e7aSJJ Ding if (value > 1) 14351da177e4SLinus Torvalds return -EINVAL; 14361da177e4SLinus Torvalds 14371da177e4SLinus Torvalds if (atkbd->scroll != value) { 14382b03b60eSDmitry Torokhov old_dev = atkbd->dev; 14392b03b60eSDmitry Torokhov old_scroll = atkbd->scroll; 14402b03b60eSDmitry Torokhov 14412b03b60eSDmitry Torokhov new_dev = input_allocate_device(); 14422b03b60eSDmitry Torokhov if (!new_dev) 14433c42f0c3SDmitry Torokhov return -ENOMEM; 14442b03b60eSDmitry Torokhov 14453c42f0c3SDmitry Torokhov atkbd->dev = new_dev; 14461da177e4SLinus Torvalds atkbd->scroll = value; 14471da177e4SLinus Torvalds atkbd_set_keycode_table(atkbd); 14481da177e4SLinus Torvalds atkbd_set_device_attrs(atkbd); 14492b03b60eSDmitry Torokhov 14502b03b60eSDmitry Torokhov err = input_register_device(atkbd->dev); 14512b03b60eSDmitry Torokhov if (err) { 14522b03b60eSDmitry Torokhov input_free_device(new_dev); 14532b03b60eSDmitry Torokhov 14542b03b60eSDmitry Torokhov atkbd->scroll = old_scroll; 14552b03b60eSDmitry Torokhov atkbd->dev = old_dev; 14562b03b60eSDmitry Torokhov atkbd_set_keycode_table(atkbd); 14572b03b60eSDmitry Torokhov atkbd_set_device_attrs(atkbd); 14582b03b60eSDmitry Torokhov 14592b03b60eSDmitry Torokhov return err; 14602b03b60eSDmitry Torokhov } 14612b03b60eSDmitry Torokhov input_unregister_device(old_dev); 14621da177e4SLinus Torvalds } 14631da177e4SLinus Torvalds return count; 14641da177e4SLinus Torvalds } 14651da177e4SLinus Torvalds 14661da177e4SLinus Torvalds static ssize_t atkbd_show_set(struct atkbd *atkbd, char *buf) 14671da177e4SLinus Torvalds { 14681da177e4SLinus Torvalds return sprintf(buf, "%d\n", atkbd->set); 14691da177e4SLinus Torvalds } 14701da177e4SLinus Torvalds 14711da177e4SLinus Torvalds static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count) 14721da177e4SLinus Torvalds { 14732b03b60eSDmitry Torokhov struct input_dev *old_dev, *new_dev; 147476496e7aSJJ Ding unsigned int value; 14752b03b60eSDmitry Torokhov int err; 1476a9a1f9c3SDmitry Torokhov unsigned char old_set; 1477a9a1f9c3SDmitry Torokhov bool old_extra; 14781da177e4SLinus Torvalds 14791da177e4SLinus Torvalds if (!atkbd->write) 14801da177e4SLinus Torvalds return -EIO; 14811da177e4SLinus Torvalds 148276496e7aSJJ Ding err = kstrtouint(buf, 10, &value); 148376496e7aSJJ Ding if (err) 148476496e7aSJJ Ding return err; 148576496e7aSJJ Ding 148676496e7aSJJ Ding if (value != 2 && value != 3) 14871da177e4SLinus Torvalds return -EINVAL; 14881da177e4SLinus Torvalds 14891da177e4SLinus Torvalds if (atkbd->set != value) { 14902b03b60eSDmitry Torokhov old_dev = atkbd->dev; 14912b03b60eSDmitry Torokhov old_extra = atkbd->extra; 14922b03b60eSDmitry Torokhov old_set = atkbd->set; 14932b03b60eSDmitry Torokhov 14942b03b60eSDmitry Torokhov new_dev = input_allocate_device(); 14952b03b60eSDmitry Torokhov if (!new_dev) 14963c42f0c3SDmitry Torokhov return -ENOMEM; 14972b03b60eSDmitry Torokhov 14983c42f0c3SDmitry Torokhov atkbd->dev = new_dev; 14991da177e4SLinus Torvalds atkbd->set = atkbd_select_set(atkbd, value, atkbd->extra); 1500d4119bdaSDmitry Torokhov atkbd_reset_state(atkbd); 15011da177e4SLinus Torvalds atkbd_activate(atkbd); 15021da177e4SLinus Torvalds atkbd_set_keycode_table(atkbd); 15031da177e4SLinus Torvalds atkbd_set_device_attrs(atkbd); 15042b03b60eSDmitry Torokhov 15052b03b60eSDmitry Torokhov err = input_register_device(atkbd->dev); 15062b03b60eSDmitry Torokhov if (err) { 15072b03b60eSDmitry Torokhov input_free_device(new_dev); 15082b03b60eSDmitry Torokhov 15092b03b60eSDmitry Torokhov atkbd->dev = old_dev; 15102b03b60eSDmitry Torokhov atkbd->set = atkbd_select_set(atkbd, old_set, old_extra); 15112b03b60eSDmitry Torokhov atkbd_set_keycode_table(atkbd); 15122b03b60eSDmitry Torokhov atkbd_set_device_attrs(atkbd); 15132b03b60eSDmitry Torokhov 15142b03b60eSDmitry Torokhov return err; 15152b03b60eSDmitry Torokhov } 15162b03b60eSDmitry Torokhov input_unregister_device(old_dev); 15171da177e4SLinus Torvalds } 15181da177e4SLinus Torvalds return count; 15191da177e4SLinus Torvalds } 15201da177e4SLinus Torvalds 15211da177e4SLinus Torvalds static ssize_t atkbd_show_softrepeat(struct atkbd *atkbd, char *buf) 15221da177e4SLinus Torvalds { 15231da177e4SLinus Torvalds return sprintf(buf, "%d\n", atkbd->softrepeat ? 1 : 0); 15241da177e4SLinus Torvalds } 15251da177e4SLinus Torvalds 15261da177e4SLinus Torvalds static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t count) 15271da177e4SLinus Torvalds { 15282b03b60eSDmitry Torokhov struct input_dev *old_dev, *new_dev; 152976496e7aSJJ Ding unsigned int value; 15302b03b60eSDmitry Torokhov int err; 1531a9a1f9c3SDmitry Torokhov bool old_softrepeat, old_softraw; 15321da177e4SLinus Torvalds 15331da177e4SLinus Torvalds if (!atkbd->write) 15341da177e4SLinus Torvalds return -EIO; 15351da177e4SLinus Torvalds 153676496e7aSJJ Ding err = kstrtouint(buf, 10, &value); 153776496e7aSJJ Ding if (err) 153876496e7aSJJ Ding return err; 153976496e7aSJJ Ding 154076496e7aSJJ Ding if (value > 1) 15411da177e4SLinus Torvalds return -EINVAL; 15421da177e4SLinus Torvalds 15431da177e4SLinus Torvalds if (atkbd->softrepeat != value) { 15442b03b60eSDmitry Torokhov old_dev = atkbd->dev; 15452b03b60eSDmitry Torokhov old_softrepeat = atkbd->softrepeat; 15462b03b60eSDmitry Torokhov old_softraw = atkbd->softraw; 15472b03b60eSDmitry Torokhov 15482b03b60eSDmitry Torokhov new_dev = input_allocate_device(); 15492b03b60eSDmitry Torokhov if (!new_dev) 15503c42f0c3SDmitry Torokhov return -ENOMEM; 15512b03b60eSDmitry Torokhov 15523c42f0c3SDmitry Torokhov atkbd->dev = new_dev; 15531da177e4SLinus Torvalds atkbd->softrepeat = value; 15541da177e4SLinus Torvalds if (atkbd->softrepeat) 1555a9a1f9c3SDmitry Torokhov atkbd->softraw = true; 15561da177e4SLinus Torvalds atkbd_set_device_attrs(atkbd); 15572b03b60eSDmitry Torokhov 15582b03b60eSDmitry Torokhov err = input_register_device(atkbd->dev); 15592b03b60eSDmitry Torokhov if (err) { 15602b03b60eSDmitry Torokhov input_free_device(new_dev); 15612b03b60eSDmitry Torokhov 15622b03b60eSDmitry Torokhov atkbd->dev = old_dev; 15632b03b60eSDmitry Torokhov atkbd->softrepeat = old_softrepeat; 15642b03b60eSDmitry Torokhov atkbd->softraw = old_softraw; 15652b03b60eSDmitry Torokhov atkbd_set_device_attrs(atkbd); 15662b03b60eSDmitry Torokhov 15672b03b60eSDmitry Torokhov return err; 15682b03b60eSDmitry Torokhov } 15692b03b60eSDmitry Torokhov input_unregister_device(old_dev); 15701da177e4SLinus Torvalds } 15711da177e4SLinus Torvalds return count; 15721da177e4SLinus Torvalds } 15731da177e4SLinus Torvalds 15741da177e4SLinus Torvalds 15751da177e4SLinus Torvalds static ssize_t atkbd_show_softraw(struct atkbd *atkbd, char *buf) 15761da177e4SLinus Torvalds { 15771da177e4SLinus Torvalds return sprintf(buf, "%d\n", atkbd->softraw ? 1 : 0); 15781da177e4SLinus Torvalds } 15791da177e4SLinus Torvalds 15801da177e4SLinus Torvalds static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t count) 15811da177e4SLinus Torvalds { 15822b03b60eSDmitry Torokhov struct input_dev *old_dev, *new_dev; 158376496e7aSJJ Ding unsigned int value; 15842b03b60eSDmitry Torokhov int err; 1585a9a1f9c3SDmitry Torokhov bool old_softraw; 15861da177e4SLinus Torvalds 158776496e7aSJJ Ding err = kstrtouint(buf, 10, &value); 158876496e7aSJJ Ding if (err) 158976496e7aSJJ Ding return err; 159076496e7aSJJ Ding 159176496e7aSJJ Ding if (value > 1) 15921da177e4SLinus Torvalds return -EINVAL; 15931da177e4SLinus Torvalds 15941da177e4SLinus Torvalds if (atkbd->softraw != value) { 15952b03b60eSDmitry Torokhov old_dev = atkbd->dev; 15962b03b60eSDmitry Torokhov old_softraw = atkbd->softraw; 15972b03b60eSDmitry Torokhov 15982b03b60eSDmitry Torokhov new_dev = input_allocate_device(); 15992b03b60eSDmitry Torokhov if (!new_dev) 16003c42f0c3SDmitry Torokhov return -ENOMEM; 16012b03b60eSDmitry Torokhov 16023c42f0c3SDmitry Torokhov atkbd->dev = new_dev; 16031da177e4SLinus Torvalds atkbd->softraw = value; 16041da177e4SLinus Torvalds atkbd_set_device_attrs(atkbd); 16052b03b60eSDmitry Torokhov 16062b03b60eSDmitry Torokhov err = input_register_device(atkbd->dev); 16072b03b60eSDmitry Torokhov if (err) { 16082b03b60eSDmitry Torokhov input_free_device(new_dev); 16092b03b60eSDmitry Torokhov 16102b03b60eSDmitry Torokhov atkbd->dev = old_dev; 16112b03b60eSDmitry Torokhov atkbd->softraw = old_softraw; 16122b03b60eSDmitry Torokhov atkbd_set_device_attrs(atkbd); 16132b03b60eSDmitry Torokhov 16142b03b60eSDmitry Torokhov return err; 16152b03b60eSDmitry Torokhov } 16162b03b60eSDmitry Torokhov input_unregister_device(old_dev); 16171da177e4SLinus Torvalds } 16181da177e4SLinus Torvalds return count; 16191da177e4SLinus Torvalds } 16201da177e4SLinus Torvalds 162186255d9dSDmitry Torokhov static ssize_t atkbd_show_err_count(struct atkbd *atkbd, char *buf) 162286255d9dSDmitry Torokhov { 162386255d9dSDmitry Torokhov return sprintf(buf, "%lu\n", atkbd->err_count); 162486255d9dSDmitry Torokhov } 162586255d9dSDmitry Torokhov 162639191698SDaniel Mierswa static int __init atkbd_setup_forced_release(const struct dmi_system_id *id) 1627554101e3SGiel de Nijs { 162839191698SDaniel Mierswa atkbd_platform_fixup = atkbd_apply_forced_release_keylist; 162939191698SDaniel Mierswa atkbd_platform_fixup_data = id->driver_data; 163039191698SDaniel Mierswa 1631c388b2c6SAxel Lin return 1; 1632554101e3SGiel de Nijs } 1633554101e3SGiel de Nijs 1634e5713069SJamie Lentin static int __init atkbd_setup_scancode_fixup(const struct dmi_system_id *id) 1635e5713069SJamie Lentin { 1636e5713069SJamie Lentin atkbd_platform_scancode_fixup = id->driver_data; 1637e5713069SJamie Lentin 1638c388b2c6SAxel Lin return 1; 1639e5713069SJamie Lentin } 1640e5713069SJamie Lentin 1641c45fc81eSDmitry Torokhov static const struct dmi_system_id atkbd_dmi_quirk_table[] __initconst = { 1642554101e3SGiel de Nijs { 1643554101e3SGiel de Nijs .matches = { 1644554101e3SGiel de Nijs DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 164561579ba8SMatthew Garrett DMI_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */ 1646554101e3SGiel de Nijs }, 164739191698SDaniel Mierswa .callback = atkbd_setup_forced_release, 164839191698SDaniel Mierswa .driver_data = atkbd_dell_laptop_forced_release_keys, 1649554101e3SGiel de Nijs }, 16505a54c011SJiri Kosina { 16512a3ec326SMatthew Garrett .matches = { 16522a3ec326SMatthew Garrett DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), 16532a3ec326SMatthew Garrett DMI_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */ 16542a3ec326SMatthew Garrett }, 165539191698SDaniel Mierswa .callback = atkbd_setup_forced_release, 165639191698SDaniel Mierswa .driver_data = atkbd_dell_laptop_forced_release_keys, 16572a3ec326SMatthew Garrett }, 16582a3ec326SMatthew Garrett { 16595a54c011SJiri Kosina .matches = { 16605a54c011SJiri Kosina DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), 16615a54c011SJiri Kosina DMI_MATCH(DMI_PRODUCT_NAME, "HP 2133"), 16625a54c011SJiri Kosina }, 166339191698SDaniel Mierswa .callback = atkbd_setup_forced_release, 166439191698SDaniel Mierswa .driver_data = atkbd_hp_forced_release_keys, 16655a54c011SJiri Kosina }, 1666a8215b81SMatthew Garrett { 1667181f6382SRikard Ljungstrand .matches = { 1668181f6382SRikard Ljungstrand DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), 1669181f6382SRikard Ljungstrand DMI_MATCH(DMI_PRODUCT_NAME, "Pavilion ZV6100"), 1670181f6382SRikard Ljungstrand }, 167139191698SDaniel Mierswa .callback = atkbd_setup_forced_release, 1672000c2a35SHerton Ronaldo Krzesinski .driver_data = atkbd_volume_forced_release_keys, 1673181f6382SRikard Ljungstrand }, 1674181f6382SRikard Ljungstrand { 16752bcaa6a4SDave Andrews .matches = { 16762bcaa6a4SDave Andrews DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), 16772bcaa6a4SDave Andrews DMI_MATCH(DMI_PRODUCT_NAME, "Presario R4000"), 16782bcaa6a4SDave Andrews }, 16792bcaa6a4SDave Andrews .callback = atkbd_setup_forced_release, 1680000c2a35SHerton Ronaldo Krzesinski .driver_data = atkbd_volume_forced_release_keys, 16812bcaa6a4SDave Andrews }, 16822bcaa6a4SDave Andrews { 16832bcaa6a4SDave Andrews .matches = { 16842bcaa6a4SDave Andrews DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), 16852bcaa6a4SDave Andrews DMI_MATCH(DMI_PRODUCT_NAME, "Presario R4100"), 16862bcaa6a4SDave Andrews }, 16872bcaa6a4SDave Andrews .callback = atkbd_setup_forced_release, 1688000c2a35SHerton Ronaldo Krzesinski .driver_data = atkbd_volume_forced_release_keys, 16892bcaa6a4SDave Andrews }, 16902bcaa6a4SDave Andrews { 16912bcaa6a4SDave Andrews .matches = { 16922bcaa6a4SDave Andrews DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), 16932bcaa6a4SDave Andrews DMI_MATCH(DMI_PRODUCT_NAME, "Presario R4200"), 16942bcaa6a4SDave Andrews }, 16952bcaa6a4SDave Andrews .callback = atkbd_setup_forced_release, 1696000c2a35SHerton Ronaldo Krzesinski .driver_data = atkbd_volume_forced_release_keys, 16972bcaa6a4SDave Andrews }, 16982bcaa6a4SDave Andrews { 1699c45fc81eSDmitry Torokhov /* Inventec Symphony */ 1700a8215b81SMatthew Garrett .matches = { 1701a8215b81SMatthew Garrett DMI_MATCH(DMI_SYS_VENDOR, "INVENTEC"), 1702a8215b81SMatthew Garrett DMI_MATCH(DMI_PRODUCT_NAME, "SYMPHONY 6.0/7.0"), 1703a8215b81SMatthew Garrett }, 170439191698SDaniel Mierswa .callback = atkbd_setup_forced_release, 1705000c2a35SHerton Ronaldo Krzesinski .driver_data = atkbd_volume_forced_release_keys, 1706a8215b81SMatthew Garrett }, 17074200844bSStuart Hopkins { 1708c45fc81eSDmitry Torokhov /* Samsung NC10 */ 17094200844bSStuart Hopkins .matches = { 17104200844bSStuart Hopkins DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), 17114200844bSStuart Hopkins DMI_MATCH(DMI_PRODUCT_NAME, "NC10"), 17124200844bSStuart Hopkins }, 171339191698SDaniel Mierswa .callback = atkbd_setup_forced_release, 171439191698SDaniel Mierswa .driver_data = atkbd_samsung_forced_release_keys, 17154200844bSStuart Hopkins }, 1716adcb523eSDaniel Mierswa { 1717c45fc81eSDmitry Torokhov /* Samsung NC20 */ 1718e04126c7SBarry Carroll .matches = { 1719e04126c7SBarry Carroll DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), 1720e04126c7SBarry Carroll DMI_MATCH(DMI_PRODUCT_NAME, "NC20"), 1721e04126c7SBarry Carroll }, 1722e04126c7SBarry Carroll .callback = atkbd_setup_forced_release, 1723e04126c7SBarry Carroll .driver_data = atkbd_samsung_forced_release_keys, 1724e04126c7SBarry Carroll }, 1725e04126c7SBarry Carroll { 1726c45fc81eSDmitry Torokhov /* Samsung SQ45S70S */ 1727157f3a3eSDmitry Torokhov .matches = { 1728157f3a3eSDmitry Torokhov DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), 1729157f3a3eSDmitry Torokhov DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"), 1730157f3a3eSDmitry Torokhov }, 1731157f3a3eSDmitry Torokhov .callback = atkbd_setup_forced_release, 1732157f3a3eSDmitry Torokhov .driver_data = atkbd_samsung_forced_release_keys, 1733157f3a3eSDmitry Torokhov }, 1734157f3a3eSDmitry Torokhov { 1735c45fc81eSDmitry Torokhov /* Fujitsu Amilo PA 1510 */ 1736adcb523eSDaniel Mierswa .matches = { 1737adcb523eSDaniel Mierswa DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), 1738adcb523eSDaniel Mierswa DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pa 1510"), 1739adcb523eSDaniel Mierswa }, 1740adcb523eSDaniel Mierswa .callback = atkbd_setup_forced_release, 1741000c2a35SHerton Ronaldo Krzesinski .driver_data = atkbd_volume_forced_release_keys, 1742adcb523eSDaniel Mierswa }, 17439166d0f6SAdrian Batzill { 1744c45fc81eSDmitry Torokhov /* Fujitsu Amilo Pi 3525 */ 1745f0a14de2SSimon Davie .matches = { 1746f0a14de2SSimon Davie DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), 1747f0a14de2SSimon Davie DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pi 3525"), 1748f0a14de2SSimon Davie }, 1749f0a14de2SSimon Davie .callback = atkbd_setup_forced_release, 1750f0a14de2SSimon Davie .driver_data = atkbd_amilo_pi3525_forced_release_keys, 1751f0a14de2SSimon Davie }, 1752f0a14de2SSimon Davie { 1753c45fc81eSDmitry Torokhov /* Fujitsu Amilo Xi 3650 */ 17549166d0f6SAdrian Batzill .matches = { 17559166d0f6SAdrian Batzill DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), 17569166d0f6SAdrian Batzill DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Xi 3650"), 17579166d0f6SAdrian Batzill }, 17589166d0f6SAdrian Batzill .callback = atkbd_setup_forced_release, 17599166d0f6SAdrian Batzill .driver_data = atkbd_amilo_xi3650_forced_release_keys, 17609166d0f6SAdrian Batzill }, 1761032e46cbSJerone Young { 1762032e46cbSJerone Young .matches = { 1763032e46cbSJerone Young DMI_MATCH(DMI_SYS_VENDOR, "Soltech Corporation"), 1764032e46cbSJerone Young DMI_MATCH(DMI_PRODUCT_NAME, "TA12"), 1765032e46cbSJerone Young }, 1766032e46cbSJerone Young .callback = atkbd_setup_forced_release, 1767032e46cbSJerone Young .driver_data = atkdb_soltech_ta12_forced_release_keys, 1768032e46cbSJerone Young }, 1769e5713069SJamie Lentin { 1770c45fc81eSDmitry Torokhov /* OQO Model 01+ */ 1771e5713069SJamie Lentin .matches = { 1772e5713069SJamie Lentin DMI_MATCH(DMI_SYS_VENDOR, "OQO"), 1773e5713069SJamie Lentin DMI_MATCH(DMI_PRODUCT_NAME, "ZEPTO"), 1774e5713069SJamie Lentin }, 1775e5713069SJamie Lentin .callback = atkbd_setup_scancode_fixup, 1776e5713069SJamie Lentin .driver_data = atkbd_oqo_01plus_scancode_fixup, 1777e5713069SJamie Lentin }, 1778554101e3SGiel de Nijs { } 1779554101e3SGiel de Nijs }; 17801da177e4SLinus Torvalds 17811da177e4SLinus Torvalds static int __init atkbd_init(void) 17821da177e4SLinus Torvalds { 1783554101e3SGiel de Nijs dmi_check_system(atkbd_dmi_quirk_table); 1784554101e3SGiel de Nijs 1785153a9df0SAkinobu Mita return serio_register_driver(&atkbd_drv); 17861da177e4SLinus Torvalds } 17871da177e4SLinus Torvalds 17881da177e4SLinus Torvalds static void __exit atkbd_exit(void) 17891da177e4SLinus Torvalds { 17901da177e4SLinus Torvalds serio_unregister_driver(&atkbd_drv); 17911da177e4SLinus Torvalds } 17921da177e4SLinus Torvalds 17931da177e4SLinus Torvalds module_init(atkbd_init); 17941da177e4SLinus Torvalds module_exit(atkbd_exit); 1795