blob: 5838332ea5bd2f67c6e0f5c875a459027b8032e9 [file] [log] [blame]
Corentin Charye12e6d92011-02-26 10:20:31 +01001/*
2 * Eee PC WMI hotkey driver
3 *
4 * Copyright(C) 2010 Intel Corporation.
Corentin Chary57ab7da2011-02-26 10:20:32 +01005 * Copyright(C) 2010-2011 Corentin Chary <corentin.chary@gmail.com>
Corentin Charye12e6d92011-02-26 10:20:31 +01006 *
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 Kao6e0044b2012-03-20 09:53:09 +010035#include <linux/fb.h>
Corentin Charye12e6d92011-02-26 10:20:31 +010036#include <acpi/acpi_bus.h>
37
38#include "asus-wmi.h"
39
40#define EEEPC_WMI_FILE "eeepc-wmi"
41
42MODULE_AUTHOR("Corentin Chary <corentincj@iksaif.net>");
43MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver");
44MODULE_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
50MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID);
51
52static bool hotplug_wireless;
53
54module_param(hotplug_wireless, bool, 0444);
55MODULE_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 Forshee6ae8b802011-07-01 11:34:28 +020060/* Values for T101MT "Home" key */
61#define HOME_PRESS 0xe4
62#define HOME_HOLD 0xea
63#define HOME_RELEASE 0xe5
64
Corentin Charye12e6d92011-02-26 10:20:31 +010065static const struct key_entry eeepc_wmi_keymap[] = {
66 /* Sleep already handled via generic ACPI code */
67 { KE_KEY, 0x30, { KEY_VOLUMEUP } },
68 { KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
69 { KE_KEY, 0x32, { KEY_MUTE } },
70 { KE_KEY, 0x5c, { KEY_F15 } }, /* Power Gear key */
71 { KE_KEY, 0x5d, { KEY_WLAN } },
Keng-Yu Lin3b3e73f2011-03-01 12:56:13 +080072 { KE_KEY, 0x6b, { KEY_TOUCHPAD_TOGGLE } }, /* Toggle Touchpad */
Corentin Charye12e6d92011-02-26 10:20:31 +010073 { KE_KEY, 0x82, { KEY_CAMERA } },
Corentin Chary5f854002011-02-26 10:20:43 +010074 { KE_KEY, 0x83, { KEY_CAMERA_ZOOMIN } },
Corentin Charye12e6d92011-02-26 10:20:31 +010075 { KE_KEY, 0x88, { KEY_WLAN } },
Corentin Chary94814722011-03-30 16:32:33 +020076 { KE_KEY, 0xbd, { KEY_CAMERA } },
Corentin Charye12e6d92011-02-26 10:20:31 +010077 { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } },
78 { KE_KEY, 0xe0, { KEY_PROG1 } }, /* Task Manager */
79 { KE_KEY, 0xe1, { KEY_F14 } }, /* Change Resolution */
Seth Forshee6ae8b802011-07-01 11:34:28 +020080 { KE_KEY, HOME_PRESS, { KEY_CONFIG } }, /* Home/Express gate key */
Corentin Chary94814722011-03-30 16:32:33 +020081 { KE_KEY, 0xe8, { KEY_SCREENLOCK } },
AceLan Kao272c77d2012-06-13 09:32:06 +020082 { KE_KEY, 0xe9, { KEY_DISPLAYTOGGLE } },
Corentin Chary5f854002011-02-26 10:20:43 +010083 { KE_KEY, 0xeb, { KEY_CAMERA_ZOOMOUT } },
84 { KE_KEY, 0xec, { KEY_CAMERA_UP } },
85 { KE_KEY, 0xed, { KEY_CAMERA_DOWN } },
86 { KE_KEY, 0xee, { KEY_CAMERA_LEFT } },
87 { KE_KEY, 0xef, { KEY_CAMERA_RIGHT } },
Chih-Wei Huangeb649a82012-03-20 09:53:03 +010088 { KE_KEY, 0xf3, { KEY_MENU } },
89 { KE_KEY, 0xf5, { KEY_HOMEPAGE } },
90 { KE_KEY, 0xf6, { KEY_ESC } },
Corentin Charye12e6d92011-02-26 10:20:31 +010091 { KE_END, 0},
92};
93
AceLan Kaoc87992d2012-03-20 09:53:08 +010094static struct quirk_entry quirk_asus_unknown = {
95};
96
97static struct quirk_entry quirk_asus_1000h = {
98 .hotplug_wireless = true,
99};
100
AceLan Kao6e0044b2012-03-20 09:53:09 +0100101static struct quirk_entry quirk_asus_et2012_type1 = {
102 .store_backlight_power = true,
103};
104
AceLan Kaoc87992d2012-03-20 09:53:08 +0100105static struct quirk_entry quirk_asus_et2012_type3 = {
106 .scalar_panel_brightness = true,
AceLan Kao6e0044b2012-03-20 09:53:09 +0100107 .store_backlight_power = true,
AceLan Kaoc87992d2012-03-20 09:53:08 +0100108};
109
AceLan Kao272c77d2012-06-13 09:32:06 +0200110static struct quirk_entry quirk_asus_x101ch = {
111 /* We need this when ACPI function doesn't do this well */
112 .wmi_backlight_power = true,
113};
114
Corentin Charyc55d9952012-03-20 09:53:12 +0100115static struct quirk_entry *quirks;
116
Corentin Chary7a61d022012-03-20 09:53:13 +0100117static void et2012_quirks(void)
118{
119 const struct dmi_device *dev = NULL;
120 char oemstring[30];
121
122 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
123 if (sscanf(dev->name, "AEMS%24c", oemstring) == 1) {
124 if (oemstring[18] == '1')
125 quirks = &quirk_asus_et2012_type1;
126 else if (oemstring[18] == '3')
127 quirks = &quirk_asus_et2012_type3;
128 break;
129 }
130 }
131}
132
AceLan Kaoc87992d2012-03-20 09:53:08 +0100133static int dmi_matched(const struct dmi_system_id *dmi)
134{
135 char *model;
Corentin Chary7a61d022012-03-20 09:53:13 +0100136
AceLan Kaoc87992d2012-03-20 09:53:08 +0100137 quirks = dmi->driver_data;
138
139 model = (char *)dmi->matches[1].substr;
Corentin Chary7a61d022012-03-20 09:53:13 +0100140 if (unlikely(strncmp(model, "ET2012", 6) == 0))
141 et2012_quirks();
142
AceLan Kaoc87992d2012-03-20 09:53:08 +0100143 return 1;
144}
145
146static struct dmi_system_id asus_quirks[] = {
147 {
148 .callback = dmi_matched,
149 .ident = "ASUSTeK Computer INC. 1000H",
150 .matches = {
151 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
152 DMI_MATCH(DMI_PRODUCT_NAME, "1000H"),
153 },
154 .driver_data = &quirk_asus_1000h,
155 },
156 {
157 .callback = dmi_matched,
158 .ident = "ASUSTeK Computer INC. ET2012E/I",
159 .matches = {
160 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
161 DMI_MATCH(DMI_PRODUCT_NAME, "ET2012"),
162 },
163 .driver_data = &quirk_asus_unknown,
164 },
AceLan Kao272c77d2012-06-13 09:32:06 +0200165 {
166 .callback = dmi_matched,
167 .ident = "ASUSTeK Computer INC. X101CH",
168 .matches = {
169 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
170 DMI_MATCH(DMI_PRODUCT_NAME, "X101CH"),
171 },
172 .driver_data = &quirk_asus_x101ch,
173 },
174 {
175 .callback = dmi_matched,
176 .ident = "ASUSTeK Computer INC. 1015CX",
177 .matches = {
178 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
179 DMI_MATCH(DMI_PRODUCT_NAME, "1015CX"),
180 },
181 .driver_data = &quirk_asus_x101ch,
182 },
AceLan Kaoc87992d2012-03-20 09:53:08 +0100183 {},
184};
185
Seth Forshee6ae8b802011-07-01 11:34:28 +0200186static void eeepc_wmi_key_filter(struct asus_wmi_driver *asus_wmi, int *code,
187 unsigned int *value, bool *autorelease)
188{
189 switch (*code) {
190 case HOME_PRESS:
191 *value = 1;
192 *autorelease = 0;
193 break;
194 case HOME_HOLD:
195 *code = ASUS_WMI_KEY_IGNORE;
196 break;
197 case HOME_RELEASE:
198 *code = HOME_PRESS;
199 *value = 0;
200 *autorelease = 0;
201 break;
202 }
203}
204
Corentin Charye12e6d92011-02-26 10:20:31 +0100205static acpi_status eeepc_wmi_parse_device(acpi_handle handle, u32 level,
206 void *context, void **retval)
207{
Joe Perches22441ff2011-03-29 15:21:38 -0700208 pr_warn("Found legacy ATKD device (%s)\n", EEEPC_ACPI_HID);
Corentin Charye12e6d92011-02-26 10:20:31 +0100209 *(bool *)context = true;
210 return AE_CTRL_TERMINATE;
211}
212
213static int eeepc_wmi_check_atkd(void)
214{
215 acpi_status status;
216 bool found = false;
217
218 status = acpi_get_devices(EEEPC_ACPI_HID, eeepc_wmi_parse_device,
219 &found, NULL);
220
221 if (ACPI_FAILURE(status) || !found)
222 return 0;
223 return -1;
224}
225
226static int eeepc_wmi_probe(struct platform_device *pdev)
227{
228 if (eeepc_wmi_check_atkd()) {
Joe Perches22441ff2011-03-29 15:21:38 -0700229 pr_warn("WMI device present, but legacy ATKD device is also "
230 "present and enabled\n");
231 pr_warn("You probably booted with acpi_osi=\"Linux\" or "
232 "acpi_osi=\"!Windows 2009\"\n");
233 pr_warn("Can't load eeepc-wmi, use default acpi_osi "
234 "(preferred) or eeepc-laptop\n");
Corentin Charye12e6d92011-02-26 10:20:31 +0100235 return -EBUSY;
236 }
237 return 0;
238}
239
Corentin Charye12e6d92011-02-26 10:20:31 +0100240static void eeepc_wmi_quirks(struct asus_wmi_driver *driver)
241{
Corentin Charyc55d9952012-03-20 09:53:12 +0100242 quirks = &quirk_asus_unknown;
243 quirks->hotplug_wireless = hotplug_wireless;
244
AceLan Kaoc87992d2012-03-20 09:53:08 +0100245 dmi_check_system(asus_quirks);
Corentin Charyc55d9952012-03-20 09:53:12 +0100246
AceLan Kaoc87992d2012-03-20 09:53:08 +0100247 driver->quirks = quirks;
Corentin Charyc55d9952012-03-20 09:53:12 +0100248 driver->quirks->wapf = -1;
249 driver->panel_power = FB_BLANK_UNBLANK;
Corentin Charye12e6d92011-02-26 10:20:31 +0100250}
251
252static struct asus_wmi_driver asus_wmi_driver = {
253 .name = EEEPC_WMI_FILE,
254 .owner = THIS_MODULE,
255 .event_guid = EEEPC_WMI_EVENT_GUID,
256 .keymap = eeepc_wmi_keymap,
257 .input_name = "Eee PC WMI hotkeys",
258 .input_phys = EEEPC_WMI_FILE "/input0",
Seth Forshee6ae8b802011-07-01 11:34:28 +0200259 .key_filter = eeepc_wmi_key_filter,
Corentin Charye12e6d92011-02-26 10:20:31 +0100260 .probe = eeepc_wmi_probe,
AceLan Kaoc87992d2012-03-20 09:53:08 +0100261 .detect_quirks = eeepc_wmi_quirks,
Corentin Charye12e6d92011-02-26 10:20:31 +0100262};
263
264
265static int __init eeepc_wmi_init(void)
266{
267 return asus_wmi_register_driver(&asus_wmi_driver);
268}
269
270static void __exit eeepc_wmi_exit(void)
271{
272 asus_wmi_unregister_driver(&asus_wmi_driver);
273}
274
275module_init(eeepc_wmi_init);
276module_exit(eeepc_wmi_exit);