Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Eee PC WMI hotkey driver |
| 3 | * |
| 4 | * Copyright(C) 2010 Intel Corporation. |
Corentin Chary | 57ab7da | 2011-02-26 10:20:32 +0100 | [diff] [blame] | 5 | * Copyright(C) 2010-2011 Corentin Chary <corentin.chary@gmail.com> |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 6 | * |
| 7 | * Portions based on wistron_btns.c: |
| 8 | * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz> |
| 9 | * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org> |
| 10 | * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru> |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 28 | |
| 29 | #include <linux/kernel.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/input.h> |
| 33 | #include <linux/input/sparse-keymap.h> |
| 34 | #include <linux/dmi.h> |
AceLan Kao | 6e0044b | 2012-03-20 09:53:09 +0100 | [diff] [blame] | 35 | #include <linux/fb.h> |
Lv Zheng | 8b48463 | 2013-12-03 08:49:16 +0800 | [diff] [blame] | 36 | #include <linux/acpi.h> |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 37 | |
| 38 | #include "asus-wmi.h" |
| 39 | |
| 40 | #define EEEPC_WMI_FILE "eeepc-wmi" |
| 41 | |
Corentin Chary | 5909c65 | 2012-12-17 16:00:05 -0800 | [diff] [blame] | 42 | MODULE_AUTHOR("Corentin Chary <corentin.chary@gmail.com>"); |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 43 | MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver"); |
| 44 | MODULE_LICENSE("GPL"); |
| 45 | |
| 46 | #define EEEPC_ACPI_HID "ASUS010" /* old _HID used in eeepc-laptop */ |
| 47 | |
| 48 | #define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000" |
| 49 | |
| 50 | MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID); |
| 51 | |
| 52 | static bool hotplug_wireless; |
| 53 | |
| 54 | module_param(hotplug_wireless, bool, 0444); |
| 55 | MODULE_PARM_DESC(hotplug_wireless, |
| 56 | "Enable hotplug for wireless device. " |
| 57 | "If your laptop needs that, please report to " |
| 58 | "acpi4asus-user@lists.sourceforge.net."); |
| 59 | |
Seth Forshee | 6ae8b80 | 2011-07-01 11:34:28 +0200 | [diff] [blame] | 60 | /* Values for T101MT "Home" key */ |
| 61 | #define HOME_PRESS 0xe4 |
| 62 | #define HOME_HOLD 0xea |
| 63 | #define HOME_RELEASE 0xe5 |
| 64 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 65 | static const struct key_entry eeepc_wmi_keymap[] = { |
Corentin Chary | 3ba0302 | 2012-11-29 09:12:38 +0100 | [diff] [blame] | 66 | { KE_KEY, ASUS_WMI_BRN_DOWN, { KEY_BRIGHTNESSDOWN } }, |
| 67 | { KE_KEY, ASUS_WMI_BRN_UP, { KEY_BRIGHTNESSUP } }, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 68 | /* Sleep already handled via generic ACPI code */ |
| 69 | { KE_KEY, 0x30, { KEY_VOLUMEUP } }, |
| 70 | { KE_KEY, 0x31, { KEY_VOLUMEDOWN } }, |
| 71 | { KE_KEY, 0x32, { KEY_MUTE } }, |
| 72 | { KE_KEY, 0x5c, { KEY_F15 } }, /* Power Gear key */ |
| 73 | { KE_KEY, 0x5d, { KEY_WLAN } }, |
Keng-Yu Lin | 3b3e73f | 2011-03-01 12:56:13 +0800 | [diff] [blame] | 74 | { KE_KEY, 0x6b, { KEY_TOUCHPAD_TOGGLE } }, /* Toggle Touchpad */ |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 75 | { KE_KEY, 0x82, { KEY_CAMERA } }, |
Corentin Chary | 5f85400 | 2011-02-26 10:20:43 +0100 | [diff] [blame] | 76 | { KE_KEY, 0x83, { KEY_CAMERA_ZOOMIN } }, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 77 | { KE_KEY, 0x88, { KEY_WLAN } }, |
Corentin Chary | 9481472 | 2011-03-30 16:32:33 +0200 | [diff] [blame] | 78 | { KE_KEY, 0xbd, { KEY_CAMERA } }, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 79 | { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } }, |
| 80 | { KE_KEY, 0xe0, { KEY_PROG1 } }, /* Task Manager */ |
| 81 | { KE_KEY, 0xe1, { KEY_F14 } }, /* Change Resolution */ |
Seth Forshee | 6ae8b80 | 2011-07-01 11:34:28 +0200 | [diff] [blame] | 82 | { KE_KEY, HOME_PRESS, { KEY_CONFIG } }, /* Home/Express gate key */ |
Corentin Chary | 9481472 | 2011-03-30 16:32:33 +0200 | [diff] [blame] | 83 | { KE_KEY, 0xe8, { KEY_SCREENLOCK } }, |
AceLan Kao | 272c77d | 2012-06-13 09:32:06 +0200 | [diff] [blame] | 84 | { KE_KEY, 0xe9, { KEY_DISPLAYTOGGLE } }, |
Corentin Chary | 5f85400 | 2011-02-26 10:20:43 +0100 | [diff] [blame] | 85 | { KE_KEY, 0xeb, { KEY_CAMERA_ZOOMOUT } }, |
| 86 | { KE_KEY, 0xec, { KEY_CAMERA_UP } }, |
| 87 | { KE_KEY, 0xed, { KEY_CAMERA_DOWN } }, |
| 88 | { KE_KEY, 0xee, { KEY_CAMERA_LEFT } }, |
| 89 | { KE_KEY, 0xef, { KEY_CAMERA_RIGHT } }, |
Chih-Wei Huang | eb649a8 | 2012-03-20 09:53:03 +0100 | [diff] [blame] | 90 | { KE_KEY, 0xf3, { KEY_MENU } }, |
| 91 | { KE_KEY, 0xf5, { KEY_HOMEPAGE } }, |
| 92 | { KE_KEY, 0xf6, { KEY_ESC } }, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 93 | { KE_END, 0}, |
| 94 | }; |
| 95 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 96 | static struct quirk_entry quirk_asus_unknown = { |
| 97 | }; |
| 98 | |
| 99 | static struct quirk_entry quirk_asus_1000h = { |
| 100 | .hotplug_wireless = true, |
| 101 | }; |
| 102 | |
AceLan Kao | 6e0044b | 2012-03-20 09:53:09 +0100 | [diff] [blame] | 103 | static struct quirk_entry quirk_asus_et2012_type1 = { |
| 104 | .store_backlight_power = true, |
| 105 | }; |
| 106 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 107 | static struct quirk_entry quirk_asus_et2012_type3 = { |
| 108 | .scalar_panel_brightness = true, |
AceLan Kao | 6e0044b | 2012-03-20 09:53:09 +0100 | [diff] [blame] | 109 | .store_backlight_power = true, |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 110 | }; |
| 111 | |
AceLan Kao | 272c77d | 2012-06-13 09:32:06 +0200 | [diff] [blame] | 112 | static struct quirk_entry quirk_asus_x101ch = { |
| 113 | /* We need this when ACPI function doesn't do this well */ |
| 114 | .wmi_backlight_power = true, |
| 115 | }; |
| 116 | |
Corentin Chary | c55d995 | 2012-03-20 09:53:12 +0100 | [diff] [blame] | 117 | static struct quirk_entry *quirks; |
| 118 | |
Corentin Chary | 7a61d02 | 2012-03-20 09:53:13 +0100 | [diff] [blame] | 119 | static void et2012_quirks(void) |
| 120 | { |
| 121 | const struct dmi_device *dev = NULL; |
| 122 | char oemstring[30]; |
| 123 | |
| 124 | while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) { |
| 125 | if (sscanf(dev->name, "AEMS%24c", oemstring) == 1) { |
| 126 | if (oemstring[18] == '1') |
| 127 | quirks = &quirk_asus_et2012_type1; |
| 128 | else if (oemstring[18] == '3') |
| 129 | quirks = &quirk_asus_et2012_type3; |
| 130 | break; |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 135 | static int dmi_matched(const struct dmi_system_id *dmi) |
| 136 | { |
| 137 | char *model; |
Corentin Chary | 7a61d02 | 2012-03-20 09:53:13 +0100 | [diff] [blame] | 138 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 139 | quirks = dmi->driver_data; |
| 140 | |
| 141 | model = (char *)dmi->matches[1].substr; |
Corentin Chary | 7a61d02 | 2012-03-20 09:53:13 +0100 | [diff] [blame] | 142 | if (unlikely(strncmp(model, "ET2012", 6) == 0)) |
| 143 | et2012_quirks(); |
| 144 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 145 | return 1; |
| 146 | } |
| 147 | |
| 148 | static struct dmi_system_id asus_quirks[] = { |
| 149 | { |
| 150 | .callback = dmi_matched, |
| 151 | .ident = "ASUSTeK Computer INC. 1000H", |
| 152 | .matches = { |
| 153 | DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."), |
| 154 | DMI_MATCH(DMI_PRODUCT_NAME, "1000H"), |
| 155 | }, |
| 156 | .driver_data = &quirk_asus_1000h, |
| 157 | }, |
| 158 | { |
| 159 | .callback = dmi_matched, |
| 160 | .ident = "ASUSTeK Computer INC. ET2012E/I", |
| 161 | .matches = { |
| 162 | DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."), |
| 163 | DMI_MATCH(DMI_PRODUCT_NAME, "ET2012"), |
| 164 | }, |
| 165 | .driver_data = &quirk_asus_unknown, |
| 166 | }, |
AceLan Kao | 272c77d | 2012-06-13 09:32:06 +0200 | [diff] [blame] | 167 | { |
| 168 | .callback = dmi_matched, |
| 169 | .ident = "ASUSTeK Computer INC. X101CH", |
| 170 | .matches = { |
| 171 | DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), |
| 172 | DMI_MATCH(DMI_PRODUCT_NAME, "X101CH"), |
| 173 | }, |
| 174 | .driver_data = &quirk_asus_x101ch, |
| 175 | }, |
| 176 | { |
| 177 | .callback = dmi_matched, |
| 178 | .ident = "ASUSTeK Computer INC. 1015CX", |
| 179 | .matches = { |
| 180 | DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), |
| 181 | DMI_MATCH(DMI_PRODUCT_NAME, "1015CX"), |
| 182 | }, |
| 183 | .driver_data = &quirk_asus_x101ch, |
| 184 | }, |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 185 | {}, |
| 186 | }; |
| 187 | |
Seth Forshee | 6ae8b80 | 2011-07-01 11:34:28 +0200 | [diff] [blame] | 188 | static void eeepc_wmi_key_filter(struct asus_wmi_driver *asus_wmi, int *code, |
| 189 | unsigned int *value, bool *autorelease) |
| 190 | { |
| 191 | switch (*code) { |
| 192 | case HOME_PRESS: |
| 193 | *value = 1; |
| 194 | *autorelease = 0; |
| 195 | break; |
| 196 | case HOME_HOLD: |
| 197 | *code = ASUS_WMI_KEY_IGNORE; |
| 198 | break; |
| 199 | case HOME_RELEASE: |
| 200 | *code = HOME_PRESS; |
| 201 | *value = 0; |
| 202 | *autorelease = 0; |
| 203 | break; |
| 204 | } |
| 205 | } |
| 206 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 207 | static acpi_status eeepc_wmi_parse_device(acpi_handle handle, u32 level, |
| 208 | void *context, void **retval) |
| 209 | { |
Joe Perches | 22441ff | 2011-03-29 15:21:38 -0700 | [diff] [blame] | 210 | pr_warn("Found legacy ATKD device (%s)\n", EEEPC_ACPI_HID); |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 211 | *(bool *)context = true; |
| 212 | return AE_CTRL_TERMINATE; |
| 213 | } |
| 214 | |
| 215 | static int eeepc_wmi_check_atkd(void) |
| 216 | { |
| 217 | acpi_status status; |
| 218 | bool found = false; |
| 219 | |
| 220 | status = acpi_get_devices(EEEPC_ACPI_HID, eeepc_wmi_parse_device, |
| 221 | &found, NULL); |
| 222 | |
| 223 | if (ACPI_FAILURE(status) || !found) |
| 224 | return 0; |
| 225 | return -1; |
| 226 | } |
| 227 | |
| 228 | static int eeepc_wmi_probe(struct platform_device *pdev) |
| 229 | { |
| 230 | if (eeepc_wmi_check_atkd()) { |
Joe Perches | 22441ff | 2011-03-29 15:21:38 -0700 | [diff] [blame] | 231 | pr_warn("WMI device present, but legacy ATKD device is also " |
| 232 | "present and enabled\n"); |
| 233 | pr_warn("You probably booted with acpi_osi=\"Linux\" or " |
| 234 | "acpi_osi=\"!Windows 2009\"\n"); |
| 235 | pr_warn("Can't load eeepc-wmi, use default acpi_osi " |
| 236 | "(preferred) or eeepc-laptop\n"); |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 237 | return -EBUSY; |
| 238 | } |
| 239 | return 0; |
| 240 | } |
| 241 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 242 | static void eeepc_wmi_quirks(struct asus_wmi_driver *driver) |
| 243 | { |
Corentin Chary | c55d995 | 2012-03-20 09:53:12 +0100 | [diff] [blame] | 244 | quirks = &quirk_asus_unknown; |
| 245 | quirks->hotplug_wireless = hotplug_wireless; |
| 246 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 247 | dmi_check_system(asus_quirks); |
Corentin Chary | c55d995 | 2012-03-20 09:53:12 +0100 | [diff] [blame] | 248 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 249 | driver->quirks = quirks; |
Corentin Chary | c55d995 | 2012-03-20 09:53:12 +0100 | [diff] [blame] | 250 | driver->quirks->wapf = -1; |
| 251 | driver->panel_power = FB_BLANK_UNBLANK; |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | static struct asus_wmi_driver asus_wmi_driver = { |
| 255 | .name = EEEPC_WMI_FILE, |
| 256 | .owner = THIS_MODULE, |
| 257 | .event_guid = EEEPC_WMI_EVENT_GUID, |
| 258 | .keymap = eeepc_wmi_keymap, |
| 259 | .input_name = "Eee PC WMI hotkeys", |
| 260 | .input_phys = EEEPC_WMI_FILE "/input0", |
Seth Forshee | 6ae8b80 | 2011-07-01 11:34:28 +0200 | [diff] [blame] | 261 | .key_filter = eeepc_wmi_key_filter, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 262 | .probe = eeepc_wmi_probe, |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 263 | .detect_quirks = eeepc_wmi_quirks, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | |
| 267 | static int __init eeepc_wmi_init(void) |
| 268 | { |
| 269 | return asus_wmi_register_driver(&asus_wmi_driver); |
| 270 | } |
| 271 | |
| 272 | static void __exit eeepc_wmi_exit(void) |
| 273 | { |
| 274 | asus_wmi_unregister_driver(&asus_wmi_driver); |
| 275 | } |
| 276 | |
| 277 | module_init(eeepc_wmi_init); |
| 278 | module_exit(eeepc_wmi_exit); |