eeepc-wmi.c 7.0 KB
Newer Older
1 2 3 4
/*
 * Eee PC WMI hotkey driver
 *
 * Copyright(C) 2010 Intel Corporation.
C
Corentin Chary 已提交
5
 * Copyright(C) 2010-2011 Corentin Chary <corentin.chary@gmail.com>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
 *
 * Portions based on wistron_btns.c:
 * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
 * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
 * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/input.h>
#include <linux/input/sparse-keymap.h>
#include <linux/dmi.h>
35
#include <linux/fb.h>
36
#include <linux/acpi.h>
37 38 39 40 41

#include "asus-wmi.h"

#define	EEEPC_WMI_FILE	"eeepc-wmi"

C
Corentin Chary 已提交
42
MODULE_AUTHOR("Corentin Chary <corentin.chary@gmail.com>");
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver");
MODULE_LICENSE("GPL");

#define EEEPC_ACPI_HID		"ASUS010" /* old _HID used in eeepc-laptop */

#define EEEPC_WMI_EVENT_GUID	"ABBC0F72-8EA1-11D1-00A0-C90629100000"

MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID);

static bool hotplug_wireless;

module_param(hotplug_wireless, bool, 0444);
MODULE_PARM_DESC(hotplug_wireless,
		 "Enable hotplug for wireless device. "
		 "If your laptop needs that, please report to "
		 "acpi4asus-user@lists.sourceforge.net.");

60 61 62 63 64
/* Values for T101MT "Home" key */
#define HOME_PRESS	0xe4
#define HOME_HOLD	0xea
#define HOME_RELEASE	0xe5

65
static const struct key_entry eeepc_wmi_keymap[] = {
66 67
	{ KE_KEY, ASUS_WMI_BRN_DOWN, { KEY_BRIGHTNESSDOWN } },
	{ KE_KEY, ASUS_WMI_BRN_UP, { KEY_BRIGHTNESSUP } },
68 69 70 71 72 73
	/* Sleep already handled via generic ACPI code */
	{ KE_KEY, 0x30, { KEY_VOLUMEUP } },
	{ KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
	{ KE_KEY, 0x32, { KEY_MUTE } },
	{ KE_KEY, 0x5c, { KEY_F15 } }, /* Power Gear key */
	{ KE_KEY, 0x5d, { KEY_WLAN } },
74
	{ KE_KEY, 0x6b, { KEY_TOUCHPAD_TOGGLE } }, /* Toggle Touchpad */
75
	{ KE_KEY, 0x82, { KEY_CAMERA } },
76
	{ KE_KEY, 0x83, { KEY_CAMERA_ZOOMIN } },
77
	{ KE_KEY, 0x88, { KEY_WLAN } },
78
	{ KE_KEY, 0xbd, { KEY_CAMERA } },
79 80 81
	{ KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } },
	{ KE_KEY, 0xe0, { KEY_PROG1 } }, /* Task Manager */
	{ KE_KEY, 0xe1, { KEY_F14 } }, /* Change Resolution */
82
	{ KE_KEY, HOME_PRESS, { KEY_CONFIG } }, /* Home/Express gate key */
83
	{ KE_KEY, 0xe8, { KEY_SCREENLOCK } },
84
	{ KE_KEY, 0xe9, { KEY_DISPLAYTOGGLE } },
85 86 87 88 89
	{ KE_KEY, 0xeb, { KEY_CAMERA_ZOOMOUT } },
	{ KE_KEY, 0xec, { KEY_CAMERA_UP } },
	{ KE_KEY, 0xed, { KEY_CAMERA_DOWN } },
	{ KE_KEY, 0xee, { KEY_CAMERA_LEFT } },
	{ KE_KEY, 0xef, { KEY_CAMERA_RIGHT } },
90 91 92
	{ KE_KEY, 0xf3, { KEY_MENU } },
	{ KE_KEY, 0xf5, { KEY_HOMEPAGE } },
	{ KE_KEY, 0xf6, { KEY_ESC } },
93 94 95
	{ KE_END, 0},
};

96 97 98 99 100 101 102
static struct quirk_entry quirk_asus_unknown = {
};

static struct quirk_entry quirk_asus_1000h = {
	.hotplug_wireless = true,
};

103 104 105 106
static struct quirk_entry quirk_asus_et2012_type1 = {
	.store_backlight_power = true,
};

107 108
static struct quirk_entry quirk_asus_et2012_type3 = {
	.scalar_panel_brightness = true,
109
	.store_backlight_power = true,
110 111
};

112 113 114 115 116
static struct quirk_entry quirk_asus_x101ch = {
	/* We need this when ACPI function doesn't do this well */
	.wmi_backlight_power = true,
};

117 118
static struct quirk_entry *quirks;

119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
static void et2012_quirks(void)
{
	const struct dmi_device *dev = NULL;
	char oemstring[30];

	while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
		if (sscanf(dev->name, "AEMS%24c", oemstring) == 1) {
			if (oemstring[18] == '1')
				quirks = &quirk_asus_et2012_type1;
			else if (oemstring[18] == '3')
				quirks = &quirk_asus_et2012_type3;
			break;
		}
	}
}

135 136 137
static int dmi_matched(const struct dmi_system_id *dmi)
{
	char *model;
138

139 140 141
	quirks = dmi->driver_data;

	model = (char *)dmi->matches[1].substr;
142 143 144
	if (unlikely(strncmp(model, "ET2012", 6) == 0))
		et2012_quirks();

145 146 147
	return 1;
}

148
static const struct dmi_system_id asus_quirks[] = {
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
	{
		.callback = dmi_matched,
		.ident = "ASUSTeK Computer INC. 1000H",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
			DMI_MATCH(DMI_PRODUCT_NAME, "1000H"),
		},
		.driver_data = &quirk_asus_1000h,
	},
	{
		.callback = dmi_matched,
		.ident = "ASUSTeK Computer INC. ET2012E/I",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
			DMI_MATCH(DMI_PRODUCT_NAME, "ET2012"),
		},
		.driver_data = &quirk_asus_unknown,
	},
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
	{
		.callback = dmi_matched,
		.ident = "ASUSTeK Computer INC. X101CH",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
			DMI_MATCH(DMI_PRODUCT_NAME, "X101CH"),
		},
		.driver_data = &quirk_asus_x101ch,
	},
	{
		.callback = dmi_matched,
		.ident = "ASUSTeK Computer INC. 1015CX",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
			DMI_MATCH(DMI_PRODUCT_NAME, "1015CX"),
		},
		.driver_data = &quirk_asus_x101ch,
	},
185 186 187
	{},
};

188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
static void eeepc_wmi_key_filter(struct asus_wmi_driver *asus_wmi, int *code,
				 unsigned int *value, bool *autorelease)
{
	switch (*code) {
	case HOME_PRESS:
		*value = 1;
		*autorelease = 0;
		break;
	case HOME_HOLD:
		*code = ASUS_WMI_KEY_IGNORE;
		break;
	case HOME_RELEASE:
		*code = HOME_PRESS;
		*value = 0;
		*autorelease = 0;
		break;
	}
}

207 208
static int eeepc_wmi_probe(struct platform_device *pdev)
{
L
Lukas Wunner 已提交
209 210
	if (acpi_dev_found(EEEPC_ACPI_HID)) {
		pr_warn("Found legacy ATKD device (%s)\n", EEEPC_ACPI_HID);
J
Joe Perches 已提交
211 212 213 214 215 216
		pr_warn("WMI device present, but legacy ATKD device is also "
			"present and enabled\n");
		pr_warn("You probably booted with acpi_osi=\"Linux\" or "
			"acpi_osi=\"!Windows 2009\"\n");
		pr_warn("Can't load eeepc-wmi, use default acpi_osi "
			"(preferred) or eeepc-laptop\n");
217 218 219 220 221 222 223
		return -EBUSY;
	}
	return 0;
}

static void eeepc_wmi_quirks(struct asus_wmi_driver *driver)
{
224 225 226
	quirks = &quirk_asus_unknown;
	quirks->hotplug_wireless = hotplug_wireless;

227
	dmi_check_system(asus_quirks);
228

229
	driver->quirks = quirks;
230 231
	driver->quirks->wapf = -1;
	driver->panel_power = FB_BLANK_UNBLANK;
232 233 234 235 236 237 238 239 240
}

static struct asus_wmi_driver asus_wmi_driver = {
	.name = EEEPC_WMI_FILE,
	.owner = THIS_MODULE,
	.event_guid = EEEPC_WMI_EVENT_GUID,
	.keymap = eeepc_wmi_keymap,
	.input_name = "Eee PC WMI hotkeys",
	.input_phys = EEEPC_WMI_FILE "/input0",
241
	.key_filter = eeepc_wmi_key_filter,
242
	.probe = eeepc_wmi_probe,
243
	.detect_quirks = eeepc_wmi_quirks,
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
};


static int __init eeepc_wmi_init(void)
{
	return asus_wmi_register_driver(&asus_wmi_driver);
}

static void __exit eeepc_wmi_exit(void)
{
	asus_wmi_unregister_driver(&asus_wmi_driver);
}

module_init(eeepc_wmi_init);
module_exit(eeepc_wmi_exit);