Linux Audio

Check our new training course

Loading...
v6.13.7
   1// SPDX-License-Identifier: GPL-2.0-or-later
   2/*
   3 *  Acer WMI Laptop Extras
   4 *
   5 *  Copyright (C) 2007-2009	Carlos Corbacho <carlos@strangeworlds.co.uk>
   6 *
   7 *  Based on acer_acpi:
   8 *    Copyright (C) 2005-2007	E.M. Smith
   9 *    Copyright (C) 2007-2008	Carlos Corbacho <cathectic@gmail.com>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  10 */
  11
  12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13
  14#include <linux/kernel.h>
  15#include <linux/module.h>
  16#include <linux/init.h>
  17#include <linux/types.h>
  18#include <linux/dmi.h>
 
  19#include <linux/backlight.h>
  20#include <linux/leds.h>
  21#include <linux/platform_device.h>
  22#include <linux/platform_profile.h>
  23#include <linux/acpi.h>
  24#include <linux/i8042.h>
  25#include <linux/rfkill.h>
  26#include <linux/workqueue.h>
  27#include <linux/debugfs.h>
  28#include <linux/slab.h>
  29#include <linux/input.h>
  30#include <linux/input/sparse-keymap.h>
  31#include <acpi/video.h>
  32#include <linux/hwmon.h>
  33#include <linux/bitfield.h>
  34
  35MODULE_AUTHOR("Carlos Corbacho");
  36MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
  37MODULE_LICENSE("GPL");
  38
  39/*
  40 * Magic Number
  41 * Meaning is unknown - this number is required for writing to ACPI for AMW0
  42 * (it's also used in acerhk when directly accessing the BIOS)
  43 */
  44#define ACER_AMW0_WRITE	0x9610
  45
  46/*
  47 * Bit masks for the AMW0 interface
  48 */
  49#define ACER_AMW0_WIRELESS_MASK  0x35
  50#define ACER_AMW0_BLUETOOTH_MASK 0x34
  51#define ACER_AMW0_MAILLED_MASK   0x31
  52
  53/*
  54 * Method IDs for WMID interface
  55 */
  56#define ACER_WMID_GET_WIRELESS_METHODID		1
  57#define ACER_WMID_GET_BLUETOOTH_METHODID	2
  58#define ACER_WMID_GET_BRIGHTNESS_METHODID	3
  59#define ACER_WMID_SET_WIRELESS_METHODID		4
  60#define ACER_WMID_SET_BLUETOOTH_METHODID	5
  61#define ACER_WMID_SET_BRIGHTNESS_METHODID	6
  62#define ACER_WMID_GET_THREEG_METHODID		10
  63#define ACER_WMID_SET_THREEG_METHODID		11
  64
  65#define ACER_WMID_SET_GAMING_LED_METHODID 2
  66#define ACER_WMID_GET_GAMING_LED_METHODID 4
  67#define ACER_WMID_GET_GAMING_SYS_INFO_METHODID 5
  68#define ACER_WMID_SET_GAMING_FAN_BEHAVIOR 14
  69#define ACER_WMID_SET_GAMING_MISC_SETTING_METHODID 22
  70
  71#define ACER_PREDATOR_V4_THERMAL_PROFILE_EC_OFFSET 0x54
  72
  73#define ACER_PREDATOR_V4_FAN_SPEED_READ_BIT_MASK GENMASK(20, 8)
  74
  75/*
  76 * Acer ACPI method GUIDs
  77 */
  78#define AMW0_GUID1		"67C3371D-95A3-4C37-BB61-DD47B491DAAB"
  79#define AMW0_GUID2		"431F16ED-0C2B-444C-B267-27DEB140CF9C"
  80#define WMID_GUID1		"6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
  81#define WMID_GUID2		"95764E09-FB56-4E83-B31A-37761F60994A"
  82#define WMID_GUID3		"61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
  83#define WMID_GUID4		"7A4DDFE7-5B5D-40B4-8595-4408E0CC7F56"
  84
  85/*
  86 * Acer ACPI event GUIDs
  87 */
  88#define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
  89
  90MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
  91MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
  92MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
  93
  94enum acer_wmi_event_ids {
  95	WMID_HOTKEY_EVENT = 0x1,
  96	WMID_ACCEL_OR_KBD_DOCK_EVENT = 0x5,
  97	WMID_GAMING_TURBO_KEY_EVENT = 0x7,
  98	WMID_AC_EVENT = 0x8,
  99};
 100
 101enum acer_wmi_predator_v4_sys_info_command {
 102	ACER_WMID_CMD_GET_PREDATOR_V4_BAT_STATUS = 0x02,
 103	ACER_WMID_CMD_GET_PREDATOR_V4_CPU_FAN_SPEED = 0x0201,
 104	ACER_WMID_CMD_GET_PREDATOR_V4_GPU_FAN_SPEED = 0x0601,
 105};
 106
 107static const struct key_entry acer_wmi_keymap[] __initconst = {
 108	{KE_KEY, 0x01, {KEY_WLAN} },     /* WiFi */
 109	{KE_KEY, 0x03, {KEY_WLAN} },     /* WiFi */
 110	{KE_KEY, 0x04, {KEY_WLAN} },     /* WiFi */
 111	{KE_KEY, 0x12, {KEY_BLUETOOTH} },	/* BT */
 112	{KE_KEY, 0x21, {KEY_PROG1} },    /* Backup */
 113	{KE_KEY, 0x22, {KEY_PROG2} },    /* Arcade */
 114	{KE_KEY, 0x23, {KEY_PROG3} },    /* P_Key */
 115	{KE_KEY, 0x24, {KEY_PROG4} },    /* Social networking_Key */
 116	{KE_KEY, 0x27, {KEY_HELP} },
 117	{KE_KEY, 0x29, {KEY_PROG3} },    /* P_Key for TM8372 */
 118	{KE_IGNORE, 0x41, {KEY_MUTE} },
 119	{KE_IGNORE, 0x42, {KEY_PREVIOUSSONG} },
 120	{KE_IGNORE, 0x4d, {KEY_PREVIOUSSONG} },
 121	{KE_IGNORE, 0x43, {KEY_NEXTSONG} },
 122	{KE_IGNORE, 0x4e, {KEY_NEXTSONG} },
 123	{KE_IGNORE, 0x44, {KEY_PLAYPAUSE} },
 124	{KE_IGNORE, 0x4f, {KEY_PLAYPAUSE} },
 125	{KE_IGNORE, 0x45, {KEY_STOP} },
 126	{KE_IGNORE, 0x50, {KEY_STOP} },
 127	{KE_IGNORE, 0x48, {KEY_VOLUMEUP} },
 128	{KE_IGNORE, 0x49, {KEY_VOLUMEDOWN} },
 129	{KE_IGNORE, 0x4a, {KEY_VOLUMEDOWN} },
 130	/*
 131	 * 0x61 is KEY_SWITCHVIDEOMODE. Usually this is a duplicate input event
 132	 * with the "Video Bus" input device events. But sometimes it is not
 133	 * a dup. Map it to KEY_UNKNOWN instead of using KE_IGNORE so that
 134	 * udev/hwdb can override it on systems where it is not a dup.
 135	 */
 136	{KE_KEY, 0x61, {KEY_UNKNOWN} },
 137	{KE_IGNORE, 0x62, {KEY_BRIGHTNESSUP} },
 138	{KE_IGNORE, 0x63, {KEY_BRIGHTNESSDOWN} },
 139	{KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} },	/* Display Switch */
 140	{KE_IGNORE, 0x81, {KEY_SLEEP} },
 141	{KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} },	/* Touch Pad Toggle */
 142	{KE_IGNORE, 0x84, {KEY_KBDILLUMTOGGLE} }, /* Automatic Keyboard background light toggle */
 143	{KE_KEY, KEY_TOUCHPAD_ON, {KEY_TOUCHPAD_ON} },
 144	{KE_KEY, KEY_TOUCHPAD_OFF, {KEY_TOUCHPAD_OFF} },
 145	{KE_IGNORE, 0x83, {KEY_TOUCHPAD_TOGGLE} },
 146	{KE_KEY, 0x85, {KEY_TOUCHPAD_TOGGLE} },
 147	{KE_KEY, 0x86, {KEY_WLAN} },
 148	{KE_KEY, 0x87, {KEY_POWER} },
 149	{KE_END, 0}
 150};
 151
 152static struct input_dev *acer_wmi_input_dev;
 153static struct input_dev *acer_wmi_accel_dev;
 154
 155struct event_return_value {
 156	u8 function;
 157	u8 key_num;
 158	u16 device_state;
 159	u16 reserved1;
 160	u8 kbd_dock_state;
 161	u8 reserved2;
 162} __packed;
 163
 164/*
 165 * GUID3 Get Device Status device flags
 166 */
 167#define ACER_WMID3_GDS_WIRELESS		(1<<0)	/* WiFi */
 168#define ACER_WMID3_GDS_THREEG		(1<<6)	/* 3G */
 169#define ACER_WMID3_GDS_WIMAX		(1<<7)	/* WiMAX */
 170#define ACER_WMID3_GDS_BLUETOOTH	(1<<11)	/* BT */
 171#define ACER_WMID3_GDS_RFBTN		(1<<14)	/* RF Button */
 172
 173#define ACER_WMID3_GDS_TOUCHPAD		(1<<1)	/* Touchpad */
 174
 175/* Hotkey Customized Setting and Acer Application Status.
 176 * Set Device Default Value and Report Acer Application Status.
 177 * When Acer Application starts, it will run this method to inform
 178 * BIOS/EC that Acer Application is on.
 179 * App Status
 180 *	Bit[0]: Launch Manager Status
 181 *	Bit[1]: ePM Status
 182 *	Bit[2]: Device Control Status
 183 *	Bit[3]: Acer Power Button Utility Status
 184 *	Bit[4]: RF Button Status
 185 *	Bit[5]: ODD PM Status
 186 *	Bit[6]: Device Default Value Control
 187 *	Bit[7]: Hall Sensor Application Status
 188 */
 189struct func_input_params {
 190	u8 function_num;        /* Function Number */
 191	u16 commun_devices;     /* Communication type devices default status */
 192	u16 devices;            /* Other type devices default status */
 193	u8 app_status;          /* Acer Device Status. LM, ePM, RF Button... */
 194	u8 app_mask;		/* Bit mask to app_status */
 195	u8 reserved;
 196} __packed;
 197
 198struct func_return_value {
 199	u8 error_code;          /* Error Code */
 200	u8 ec_return_value;     /* EC Return Value */
 201	u16 reserved;
 202} __packed;
 203
 204struct wmid3_gds_set_input_param {     /* Set Device Status input parameter */
 205	u8 function_num;        /* Function Number */
 206	u8 hotkey_number;       /* Hotkey Number */
 207	u16 devices;            /* Set Device */
 208	u8 volume_value;        /* Volume Value */
 209} __packed;
 210
 211struct wmid3_gds_get_input_param {     /* Get Device Status input parameter */
 212	u8 function_num;	/* Function Number */
 213	u8 hotkey_number;	/* Hotkey Number */
 214	u16 devices;		/* Get Device */
 215} __packed;
 216
 217struct wmid3_gds_return_value {	/* Get Device Status return value*/
 218	u8 error_code;		/* Error Code */
 219	u8 ec_return_value;	/* EC Return Value */
 220	u16 devices;		/* Current Device Status */
 221	u32 reserved;
 222} __packed;
 223
 224struct hotkey_function_type_aa {
 225	u8 type;
 226	u8 length;
 227	u16 handle;
 228	u16 commun_func_bitmap;
 229	u16 application_func_bitmap;
 230	u16 media_func_bitmap;
 231	u16 display_func_bitmap;
 232	u16 others_func_bitmap;
 233	u8 commun_fn_key_number;
 234} __packed;
 235
 236/*
 237 * Interface capability flags
 238 */
 239#define ACER_CAP_MAILLED		BIT(0)
 240#define ACER_CAP_WIRELESS		BIT(1)
 241#define ACER_CAP_BLUETOOTH		BIT(2)
 242#define ACER_CAP_BRIGHTNESS		BIT(3)
 243#define ACER_CAP_THREEG			BIT(4)
 244#define ACER_CAP_SET_FUNCTION_MODE	BIT(5)
 245#define ACER_CAP_KBD_DOCK		BIT(6)
 246#define ACER_CAP_TURBO_OC		BIT(7)
 247#define ACER_CAP_TURBO_LED		BIT(8)
 248#define ACER_CAP_TURBO_FAN		BIT(9)
 249#define ACER_CAP_PLATFORM_PROFILE	BIT(10)
 250#define ACER_CAP_FAN_SPEED_READ		BIT(11)
 251
 252/*
 253 * Interface type flags
 254 */
 255enum interface_flags {
 256	ACER_AMW0,
 257	ACER_AMW0_V2,
 258	ACER_WMID,
 259	ACER_WMID_v2,
 260};
 261
 
 
 
 
 
 262static int max_brightness = 0xF;
 263
 264static int mailled = -1;
 265static int brightness = -1;
 266static int threeg = -1;
 267static int force_series;
 268static int force_caps = -1;
 269static bool ec_raw_mode;
 270static bool has_type_aa;
 271static u16 commun_func_bitmap;
 272static u8 commun_fn_key_number;
 273static bool cycle_gaming_thermal_profile = true;
 274static bool predator_v4;
 275
 276module_param(mailled, int, 0444);
 277module_param(brightness, int, 0444);
 278module_param(threeg, int, 0444);
 279module_param(force_series, int, 0444);
 280module_param(force_caps, int, 0444);
 281module_param(ec_raw_mode, bool, 0444);
 282module_param(cycle_gaming_thermal_profile, bool, 0644);
 283module_param(predator_v4, bool, 0444);
 284MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
 285MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
 286MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
 287MODULE_PARM_DESC(force_series, "Force a different laptop series");
 288MODULE_PARM_DESC(force_caps, "Force the capability bitmask to this value");
 289MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
 290MODULE_PARM_DESC(cycle_gaming_thermal_profile,
 291	"Set thermal mode key in cycle mode. Disabling it sets the mode key in turbo toggle mode");
 292MODULE_PARM_DESC(predator_v4,
 293	"Enable features for predator laptops that use predator sense v4");
 294
 295struct acer_data {
 296	int mailled;
 297	int threeg;
 298	int brightness;
 299};
 300
 301struct acer_debug {
 302	struct dentry *root;
 
 303	u32 wmid_devices;
 304};
 305
 306static struct rfkill *wireless_rfkill;
 307static struct rfkill *bluetooth_rfkill;
 308static struct rfkill *threeg_rfkill;
 309static bool rfkill_inited;
 310
 311/* Each low-level interface must define at least some of the following */
 312struct wmi_interface {
 313	/* The WMI device type */
 314	u32 type;
 315
 316	/* The capabilities this interface provides */
 317	u32 capability;
 318
 319	/* Private data for the current interface */
 320	struct acer_data data;
 321
 322	/* debugfs entries associated with this interface */
 323	struct acer_debug debug;
 324};
 325
 326/* The static interface pointer, points to the currently detected interface */
 327static struct wmi_interface *interface;
 328
 329/*
 330 * Embedded Controller quirks
 331 * Some laptops require us to directly access the EC to either enable or query
 332 * features that are not available through WMI.
 333 */
 334
 335struct quirk_entry {
 336	u8 wireless;
 337	u8 mailled;
 338	s8 brightness;
 339	u8 bluetooth;
 340	u8 turbo;
 341	u8 cpu_fans;
 342	u8 gpu_fans;
 343	u8 predator_v4;
 344};
 345
 346static struct quirk_entry *quirks;
 347
 348static void __init set_quirks(void)
 349{
 
 
 
 350	if (quirks->mailled)
 351		interface->capability |= ACER_CAP_MAILLED;
 352
 353	if (quirks->brightness)
 354		interface->capability |= ACER_CAP_BRIGHTNESS;
 355
 356	if (quirks->turbo)
 357		interface->capability |= ACER_CAP_TURBO_OC | ACER_CAP_TURBO_LED
 358					 | ACER_CAP_TURBO_FAN;
 359
 360	if (quirks->predator_v4)
 361		interface->capability |= ACER_CAP_PLATFORM_PROFILE |
 362					 ACER_CAP_FAN_SPEED_READ;
 363}
 364
 365static int __init dmi_matched(const struct dmi_system_id *dmi)
 366{
 367	quirks = dmi->driver_data;
 368	return 1;
 369}
 370
 371static int __init set_force_caps(const struct dmi_system_id *dmi)
 372{
 373	if (force_caps == -1) {
 374		force_caps = (uintptr_t)dmi->driver_data;
 375		pr_info("Found %s, set force_caps to 0x%x\n", dmi->ident, force_caps);
 376	}
 377	return 1;
 378}
 379
 380static struct quirk_entry quirk_unknown = {
 381};
 382
 383static struct quirk_entry quirk_acer_aspire_1520 = {
 384	.brightness = -1,
 385};
 386
 387static struct quirk_entry quirk_acer_travelmate_2490 = {
 388	.mailled = 1,
 389};
 390
 391static struct quirk_entry quirk_acer_predator_ph315_53 = {
 392	.turbo = 1,
 393	.cpu_fans = 1,
 394	.gpu_fans = 1,
 395};
 396
 397static struct quirk_entry quirk_acer_predator_ph16_72 = {
 398	.turbo = 1,
 399	.cpu_fans = 1,
 400	.gpu_fans = 1,
 401	.predator_v4 = 1,
 402};
 403
 404static struct quirk_entry quirk_acer_predator_pt14_51 = {
 405	.turbo = 1,
 406	.cpu_fans = 1,
 407	.gpu_fans = 1,
 408	.predator_v4 = 1,
 409};
 410
 411static struct quirk_entry quirk_acer_predator_v4 = {
 412	.predator_v4 = 1,
 413};
 414
 415/* This AMW0 laptop has no bluetooth */
 416static struct quirk_entry quirk_medion_md_98300 = {
 417	.wireless = 1,
 418};
 419
 420static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
 421	.wireless = 2,
 422};
 423
 424static struct quirk_entry quirk_lenovo_ideapad_s205 = {
 425	.wireless = 3,
 426};
 427
 428/* The Aspire One has a dummy ACPI-WMI interface - disable it */
 429static const struct dmi_system_id acer_blacklist[] __initconst = {
 430	{
 431		.ident = "Acer Aspire One (SSD)",
 432		.matches = {
 433			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 434			DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
 435		},
 436	},
 437	{
 438		.ident = "Acer Aspire One (HDD)",
 439		.matches = {
 440			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 441			DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
 442		},
 443	},
 444	{}
 445};
 446
 447static const struct dmi_system_id amw0_whitelist[] __initconst = {
 448	{
 449		.ident = "Acer",
 450		.matches = {
 451			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 452		},
 453	},
 454	{
 455		.ident = "Gateway",
 456		.matches = {
 457			DMI_MATCH(DMI_SYS_VENDOR, "Gateway"),
 458		},
 459	},
 460	{
 461		.ident = "Packard Bell",
 462		.matches = {
 463			DMI_MATCH(DMI_SYS_VENDOR, "Packard Bell"),
 464		},
 465	},
 466	{}
 467};
 468
 469/*
 470 * This quirk table is only for Acer/Gateway/Packard Bell family
 471 * that those machines are supported by acer-wmi driver.
 472 */
 473static const struct dmi_system_id acer_quirks[] __initconst = {
 474	{
 475		.callback = dmi_matched,
 476		.ident = "Acer Aspire 1360",
 477		.matches = {
 478			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 479			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
 480		},
 481		.driver_data = &quirk_acer_aspire_1520,
 482	},
 483	{
 484		.callback = dmi_matched,
 485		.ident = "Acer Aspire 1520",
 486		.matches = {
 487			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 488			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
 489		},
 490		.driver_data = &quirk_acer_aspire_1520,
 491	},
 492	{
 493		.callback = dmi_matched,
 494		.ident = "Acer Aspire 3100",
 495		.matches = {
 496			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 497			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
 498		},
 499		.driver_data = &quirk_acer_travelmate_2490,
 500	},
 501	{
 502		.callback = dmi_matched,
 503		.ident = "Acer Aspire 3610",
 504		.matches = {
 505			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 506			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
 507		},
 508		.driver_data = &quirk_acer_travelmate_2490,
 509	},
 510	{
 511		.callback = dmi_matched,
 512		.ident = "Acer Aspire 5100",
 513		.matches = {
 514			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 515			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
 516		},
 517		.driver_data = &quirk_acer_travelmate_2490,
 518	},
 519	{
 520		.callback = dmi_matched,
 521		.ident = "Acer Aspire 5610",
 522		.matches = {
 523			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 524			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
 525		},
 526		.driver_data = &quirk_acer_travelmate_2490,
 527	},
 528	{
 529		.callback = dmi_matched,
 530		.ident = "Acer Aspire 5630",
 531		.matches = {
 532			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 533			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
 534		},
 535		.driver_data = &quirk_acer_travelmate_2490,
 536	},
 537	{
 538		.callback = dmi_matched,
 539		.ident = "Acer Aspire 5650",
 540		.matches = {
 541			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 542			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
 543		},
 544		.driver_data = &quirk_acer_travelmate_2490,
 545	},
 546	{
 547		.callback = dmi_matched,
 548		.ident = "Acer Aspire 5680",
 549		.matches = {
 550			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 551			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
 552		},
 553		.driver_data = &quirk_acer_travelmate_2490,
 554	},
 555	{
 556		.callback = dmi_matched,
 557		.ident = "Acer Aspire 9110",
 558		.matches = {
 559			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 560			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
 561		},
 562		.driver_data = &quirk_acer_travelmate_2490,
 563	},
 564	{
 565		.callback = dmi_matched,
 566		.ident = "Acer TravelMate 2490",
 567		.matches = {
 568			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 569			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
 570		},
 571		.driver_data = &quirk_acer_travelmate_2490,
 572	},
 573	{
 574		.callback = dmi_matched,
 575		.ident = "Acer TravelMate 4200",
 576		.matches = {
 577			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 578			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
 579		},
 580		.driver_data = &quirk_acer_travelmate_2490,
 581	},
 582	{
 583		.callback = dmi_matched,
 584		.ident = "Acer Nitro AN515-58",
 585		.matches = {
 586			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 587			DMI_MATCH(DMI_PRODUCT_NAME, "Nitro AN515-58"),
 588		},
 589		.driver_data = &quirk_acer_predator_v4,
 590	},
 591	{
 592		.callback = dmi_matched,
 593		.ident = "Acer Predator PH315-53",
 594		.matches = {
 595			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 596			DMI_MATCH(DMI_PRODUCT_NAME, "Predator PH315-53"),
 597		},
 598		.driver_data = &quirk_acer_predator_ph315_53,
 599	},
 600	{
 601		.callback = dmi_matched,
 602		.ident = "Acer Predator PHN16-71",
 603		.matches = {
 604			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 605			DMI_MATCH(DMI_PRODUCT_NAME, "Predator PHN16-71"),
 606		},
 607		.driver_data = &quirk_acer_predator_v4,
 608	},
 609	{
 610		.callback = dmi_matched,
 611		.ident = "Acer Predator PH16-71",
 612		.matches = {
 613			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 614			DMI_MATCH(DMI_PRODUCT_NAME, "Predator PH16-71"),
 615		},
 616		.driver_data = &quirk_acer_predator_v4,
 617	},
 618	{
 619		.callback = dmi_matched,
 620		.ident = "Acer Predator PH16-72",
 621		.matches = {
 622			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 623			DMI_MATCH(DMI_PRODUCT_NAME, "Predator PH16-72"),
 624		},
 625		.driver_data = &quirk_acer_predator_ph16_72,
 626	},
 627	{
 628		.callback = dmi_matched,
 629		.ident = "Acer Predator PH18-71",
 630		.matches = {
 631			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 632			DMI_MATCH(DMI_PRODUCT_NAME, "Predator PH18-71"),
 633		},
 634		.driver_data = &quirk_acer_predator_v4,
 635	},
 636	{
 637		.callback = dmi_matched,
 638		.ident = "Acer Predator PT14-51",
 639		.matches = {
 640			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 641			DMI_MATCH(DMI_PRODUCT_NAME, "Predator PT14-51"),
 642		},
 643		.driver_data = &quirk_acer_predator_pt14_51,
 644	},
 645	{
 646		.callback = set_force_caps,
 647		.ident = "Acer Aspire Switch 10E SW3-016",
 648		.matches = {
 649			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 650			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW3-016"),
 651		},
 652		.driver_data = (void *)ACER_CAP_KBD_DOCK,
 653	},
 654	{
 655		.callback = set_force_caps,
 656		.ident = "Acer Aspire Switch 10 SW5-012",
 657		.matches = {
 658			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 659			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
 660		},
 661		.driver_data = (void *)ACER_CAP_KBD_DOCK,
 662	},
 663	{
 664		.callback = set_force_caps,
 665		.ident = "Acer Aspire Switch V 10 SW5-017",
 666		.matches = {
 667			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
 668			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SW5-017"),
 669		},
 670		.driver_data = (void *)ACER_CAP_KBD_DOCK,
 671	},
 672	{
 673		.callback = set_force_caps,
 674		.ident = "Acer One 10 (S1003)",
 675		.matches = {
 676			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
 677			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "One S1003"),
 678		},
 679		.driver_data = (void *)ACER_CAP_KBD_DOCK,
 680	},
 681	{}
 682};
 683
 684/*
 685 * This quirk list is for those non-acer machines that have AMW0_GUID1
 686 * but supported by acer-wmi in past days. Keeping this quirk list here
 687 * is only for backward compatible. Please do not add new machine to
 688 * here anymore. Those non-acer machines should be supported by
 689 * appropriate wmi drivers.
 690 */
 691static const struct dmi_system_id non_acer_quirks[] __initconst = {
 692	{
 693		.callback = dmi_matched,
 694		.ident = "Fujitsu Siemens Amilo Li 1718",
 695		.matches = {
 696			DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
 697			DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
 698		},
 699		.driver_data = &quirk_fujitsu_amilo_li_1718,
 700	},
 701	{
 702		.callback = dmi_matched,
 703		.ident = "Medion MD 98300",
 704		.matches = {
 705			DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
 706			DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
 707		},
 708		.driver_data = &quirk_medion_md_98300,
 709	},
 710	{
 711		.callback = dmi_matched,
 712		.ident = "Lenovo Ideapad S205",
 713		.matches = {
 714			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 715			DMI_MATCH(DMI_PRODUCT_NAME, "10382LG"),
 716		},
 717		.driver_data = &quirk_lenovo_ideapad_s205,
 718	},
 719	{
 720		.callback = dmi_matched,
 721		.ident = "Lenovo Ideapad S205 (Brazos)",
 722		.matches = {
 723			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 724			DMI_MATCH(DMI_PRODUCT_NAME, "Brazos"),
 725		},
 726		.driver_data = &quirk_lenovo_ideapad_s205,
 727	},
 728	{
 729		.callback = dmi_matched,
 730		.ident = "Lenovo 3000 N200",
 731		.matches = {
 732			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 733			DMI_MATCH(DMI_PRODUCT_NAME, "0687A31"),
 734		},
 735		.driver_data = &quirk_fujitsu_amilo_li_1718,
 736	},
 737	{
 738		.callback = dmi_matched,
 739		.ident = "Lenovo Ideapad S205-10382JG",
 740		.matches = {
 741			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 742			DMI_MATCH(DMI_PRODUCT_NAME, "10382JG"),
 743		},
 744		.driver_data = &quirk_lenovo_ideapad_s205,
 745	},
 746	{
 747		.callback = dmi_matched,
 748		.ident = "Lenovo Ideapad S205-1038DPG",
 749		.matches = {
 750			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 751			DMI_MATCH(DMI_PRODUCT_NAME, "1038DPG"),
 752		},
 753		.driver_data = &quirk_lenovo_ideapad_s205,
 754	},
 755	{}
 756};
 757
 758static struct platform_profile_handler platform_profile_handler;
 759static bool platform_profile_support;
 760
 761/*
 762 * The profile used before turbo mode. This variable is needed for
 763 * returning from turbo mode when the mode key is in toggle mode.
 764 */
 765static int last_non_turbo_profile;
 766
 767enum acer_predator_v4_thermal_profile_ec {
 768	ACER_PREDATOR_V4_THERMAL_PROFILE_ECO = 0x04,
 769	ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO = 0x03,
 770	ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE = 0x02,
 771	ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET = 0x01,
 772	ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED = 0x00,
 773};
 774
 775enum acer_predator_v4_thermal_profile_wmi {
 776	ACER_PREDATOR_V4_THERMAL_PROFILE_ECO_WMI = 0x060B,
 777	ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI = 0x050B,
 778	ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE_WMI = 0x040B,
 779	ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET_WMI = 0x0B,
 780	ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI = 0x010B,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 781};
 782
 783/* Find which quirks are needed for a particular vendor/ model pair */
 784static void __init find_quirks(void)
 785{
 786	if (predator_v4) {
 787		quirks = &quirk_acer_predator_v4;
 788	} else if (!force_series) {
 789		dmi_check_system(acer_quirks);
 790		dmi_check_system(non_acer_quirks);
 791	} else if (force_series == 2490) {
 792		quirks = &quirk_acer_travelmate_2490;
 793	}
 794
 795	if (quirks == NULL)
 796		quirks = &quirk_unknown;
 
 
 797}
 798
 799/*
 800 * General interface convenience methods
 801 */
 802
 803static bool has_cap(u32 cap)
 804{
 805	return interface->capability & cap;
 
 
 
 806}
 807
 808/*
 809 * AMW0 (V1) interface
 810 */
 811struct wmab_args {
 812	u32 eax;
 813	u32 ebx;
 814	u32 ecx;
 815	u32 edx;
 816};
 817
 818struct wmab_ret {
 819	u32 eax;
 820	u32 ebx;
 821	u32 ecx;
 822	u32 edx;
 823	u32 eex;
 824};
 825
 826static acpi_status wmab_execute(struct wmab_args *regbuf,
 827struct acpi_buffer *result)
 828{
 829	struct acpi_buffer input;
 830	acpi_status status;
 831	input.length = sizeof(struct wmab_args);
 832	input.pointer = (u8 *)regbuf;
 833
 834	status = wmi_evaluate_method(AMW0_GUID1, 0, 1, &input, result);
 835
 836	return status;
 837}
 838
 839static acpi_status AMW0_get_u32(u32 *value, u32 cap)
 840{
 841	int err;
 842	u8 result;
 843
 844	switch (cap) {
 845	case ACER_CAP_MAILLED:
 846		switch (quirks->mailled) {
 847		default:
 848			err = ec_read(0xA, &result);
 849			if (err)
 850				return AE_ERROR;
 851			*value = (result >> 7) & 0x1;
 852			return AE_OK;
 853		}
 854		break;
 855	case ACER_CAP_WIRELESS:
 856		switch (quirks->wireless) {
 857		case 1:
 858			err = ec_read(0x7B, &result);
 859			if (err)
 860				return AE_ERROR;
 861			*value = result & 0x1;
 862			return AE_OK;
 863		case 2:
 864			err = ec_read(0x71, &result);
 865			if (err)
 866				return AE_ERROR;
 867			*value = result & 0x1;
 868			return AE_OK;
 869		case 3:
 870			err = ec_read(0x78, &result);
 871			if (err)
 872				return AE_ERROR;
 873			*value = result & 0x1;
 874			return AE_OK;
 875		default:
 876			err = ec_read(0xA, &result);
 877			if (err)
 878				return AE_ERROR;
 879			*value = (result >> 2) & 0x1;
 880			return AE_OK;
 881		}
 882		break;
 883	case ACER_CAP_BLUETOOTH:
 884		switch (quirks->bluetooth) {
 885		default:
 886			err = ec_read(0xA, &result);
 887			if (err)
 888				return AE_ERROR;
 889			*value = (result >> 4) & 0x1;
 890			return AE_OK;
 891		}
 892		break;
 893	case ACER_CAP_BRIGHTNESS:
 894		switch (quirks->brightness) {
 895		default:
 896			err = ec_read(0x83, &result);
 897			if (err)
 898				return AE_ERROR;
 899			*value = result;
 900			return AE_OK;
 901		}
 902		break;
 903	default:
 904		return AE_ERROR;
 905	}
 906	return AE_OK;
 907}
 908
 909static acpi_status AMW0_set_u32(u32 value, u32 cap)
 910{
 911	struct wmab_args args;
 912
 913	args.eax = ACER_AMW0_WRITE;
 914	args.ebx = value ? (1<<8) : 0;
 915	args.ecx = args.edx = 0;
 916
 917	switch (cap) {
 918	case ACER_CAP_MAILLED:
 919		if (value > 1)
 920			return AE_BAD_PARAMETER;
 921		args.ebx |= ACER_AMW0_MAILLED_MASK;
 922		break;
 923	case ACER_CAP_WIRELESS:
 924		if (value > 1)
 925			return AE_BAD_PARAMETER;
 926		args.ebx |= ACER_AMW0_WIRELESS_MASK;
 927		break;
 928	case ACER_CAP_BLUETOOTH:
 929		if (value > 1)
 930			return AE_BAD_PARAMETER;
 931		args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
 932		break;
 933	case ACER_CAP_BRIGHTNESS:
 934		if (value > max_brightness)
 935			return AE_BAD_PARAMETER;
 936		switch (quirks->brightness) {
 937		default:
 938			return ec_write(0x83, value);
 
 939		}
 940	default:
 941		return AE_ERROR;
 942	}
 943
 944	/* Actually do the set */
 945	return wmab_execute(&args, NULL);
 946}
 947
 948static acpi_status __init AMW0_find_mailled(void)
 949{
 950	struct wmab_args args;
 951	struct wmab_ret ret;
 952	acpi_status status = AE_OK;
 953	struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
 954	union acpi_object *obj;
 955
 956	args.eax = 0x86;
 957	args.ebx = args.ecx = args.edx = 0;
 958
 959	status = wmab_execute(&args, &out);
 960	if (ACPI_FAILURE(status))
 961		return status;
 962
 963	obj = (union acpi_object *) out.pointer;
 964	if (obj && obj->type == ACPI_TYPE_BUFFER &&
 965	obj->buffer.length == sizeof(struct wmab_ret)) {
 966		ret = *((struct wmab_ret *) obj->buffer.pointer);
 967	} else {
 968		kfree(out.pointer);
 969		return AE_ERROR;
 970	}
 971
 972	if (ret.eex & 0x1)
 973		interface->capability |= ACER_CAP_MAILLED;
 974
 975	kfree(out.pointer);
 976
 977	return AE_OK;
 978}
 979
 980static const struct acpi_device_id norfkill_ids[] __initconst = {
 981	{ "VPC2004", 0},
 982	{ "IBM0068", 0},
 983	{ "LEN0068", 0},
 984	{ "SNY5001", 0},	/* sony-laptop in charge */
 985	{ "HPQ6601", 0},
 986	{ "", 0},
 987};
 988
 989static int __init AMW0_set_cap_acpi_check_device(void)
 990{
 991	const struct acpi_device_id *id;
 992
 993	for (id = norfkill_ids; id->id[0]; id++)
 994		if (acpi_dev_found(id->id))
 995			return true;
 996
 997	return false;
 998}
 999
1000static acpi_status __init AMW0_set_capabilities(void)
1001{
1002	struct wmab_args args;
1003	struct wmab_ret ret;
1004	acpi_status status;
1005	struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
1006	union acpi_object *obj;
1007
1008	/*
1009	 * On laptops with this strange GUID (non Acer), normal probing doesn't
1010	 * work.
1011	 */
1012	if (wmi_has_guid(AMW0_GUID2)) {
1013		if ((quirks != &quirk_unknown) ||
1014		    !AMW0_set_cap_acpi_check_device())
1015			interface->capability |= ACER_CAP_WIRELESS;
1016		return AE_OK;
1017	}
1018
1019	args.eax = ACER_AMW0_WRITE;
1020	args.ecx = args.edx = 0;
1021
1022	args.ebx = 0xa2 << 8;
1023	args.ebx |= ACER_AMW0_WIRELESS_MASK;
1024
1025	status = wmab_execute(&args, &out);
1026	if (ACPI_FAILURE(status))
1027		return status;
1028
1029	obj = out.pointer;
1030	if (obj && obj->type == ACPI_TYPE_BUFFER &&
1031	obj->buffer.length == sizeof(struct wmab_ret)) {
1032		ret = *((struct wmab_ret *) obj->buffer.pointer);
1033	} else {
1034		status = AE_ERROR;
1035		goto out;
1036	}
1037
1038	if (ret.eax & 0x1)
1039		interface->capability |= ACER_CAP_WIRELESS;
1040
1041	args.ebx = 2 << 8;
1042	args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
1043
1044	/*
1045	 * It's ok to use existing buffer for next wmab_execute call.
1046	 * But we need to kfree(out.pointer) if next wmab_execute fail.
1047	 */
1048	status = wmab_execute(&args, &out);
1049	if (ACPI_FAILURE(status))
1050		goto out;
1051
1052	obj = (union acpi_object *) out.pointer;
1053	if (obj && obj->type == ACPI_TYPE_BUFFER
1054	&& obj->buffer.length == sizeof(struct wmab_ret)) {
1055		ret = *((struct wmab_ret *) obj->buffer.pointer);
1056	} else {
1057		status = AE_ERROR;
1058		goto out;
1059	}
1060
1061	if (ret.eax & 0x1)
1062		interface->capability |= ACER_CAP_BLUETOOTH;
1063
1064	/*
1065	 * This appears to be safe to enable, since all Wistron based laptops
1066	 * appear to use the same EC register for brightness, even if they
1067	 * differ for wireless, etc
1068	 */
1069	if (quirks->brightness >= 0)
1070		interface->capability |= ACER_CAP_BRIGHTNESS;
1071
1072	status = AE_OK;
1073out:
1074	kfree(out.pointer);
1075	return status;
1076}
1077
1078static struct wmi_interface AMW0_interface = {
1079	.type = ACER_AMW0,
1080};
1081
1082static struct wmi_interface AMW0_V2_interface = {
1083	.type = ACER_AMW0_V2,
1084};
1085
1086/*
1087 * New interface (The WMID interface)
1088 */
1089static acpi_status
1090WMI_execute_u32(u32 method_id, u32 in, u32 *out)
1091{
1092	struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
1093	struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
1094	union acpi_object *obj;
1095	u32 tmp = 0;
1096	acpi_status status;
1097
1098	status = wmi_evaluate_method(WMID_GUID1, 0, method_id, &input, &result);
1099
1100	if (ACPI_FAILURE(status))
1101		return status;
1102
1103	obj = (union acpi_object *) result.pointer;
1104	if (obj) {
1105		if (obj->type == ACPI_TYPE_BUFFER &&
1106			(obj->buffer.length == sizeof(u32) ||
1107			obj->buffer.length == sizeof(u64))) {
1108			tmp = *((u32 *) obj->buffer.pointer);
1109		} else if (obj->type == ACPI_TYPE_INTEGER) {
1110			tmp = (u32) obj->integer.value;
1111		}
1112	}
1113
1114	if (out)
1115		*out = tmp;
1116
1117	kfree(result.pointer);
1118
1119	return status;
1120}
1121
1122static acpi_status WMID_get_u32(u32 *value, u32 cap)
1123{
1124	acpi_status status;
1125	u8 tmp;
1126	u32 result, method_id = 0;
1127
1128	switch (cap) {
1129	case ACER_CAP_WIRELESS:
1130		method_id = ACER_WMID_GET_WIRELESS_METHODID;
1131		break;
1132	case ACER_CAP_BLUETOOTH:
1133		method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
1134		break;
1135	case ACER_CAP_BRIGHTNESS:
1136		method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
1137		break;
1138	case ACER_CAP_THREEG:
1139		method_id = ACER_WMID_GET_THREEG_METHODID;
1140		break;
1141	case ACER_CAP_MAILLED:
1142		if (quirks->mailled == 1) {
1143			ec_read(0x9f, &tmp);
1144			*value = tmp & 0x1;
1145			return 0;
1146		}
1147		fallthrough;
1148	default:
1149		return AE_ERROR;
1150	}
1151	status = WMI_execute_u32(method_id, 0, &result);
1152
1153	if (ACPI_SUCCESS(status))
1154		*value = (u8)result;
1155
1156	return status;
1157}
1158
1159static acpi_status WMID_set_u32(u32 value, u32 cap)
1160{
1161	u32 method_id = 0;
1162	char param;
1163
1164	switch (cap) {
1165	case ACER_CAP_BRIGHTNESS:
1166		if (value > max_brightness)
1167			return AE_BAD_PARAMETER;
1168		method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
1169		break;
1170	case ACER_CAP_WIRELESS:
1171		if (value > 1)
1172			return AE_BAD_PARAMETER;
1173		method_id = ACER_WMID_SET_WIRELESS_METHODID;
1174		break;
1175	case ACER_CAP_BLUETOOTH:
1176		if (value > 1)
1177			return AE_BAD_PARAMETER;
1178		method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
1179		break;
1180	case ACER_CAP_THREEG:
1181		if (value > 1)
1182			return AE_BAD_PARAMETER;
1183		method_id = ACER_WMID_SET_THREEG_METHODID;
1184		break;
1185	case ACER_CAP_MAILLED:
1186		if (value > 1)
1187			return AE_BAD_PARAMETER;
1188		if (quirks->mailled == 1) {
1189			param = value ? 0x92 : 0x93;
1190			i8042_lock_chip();
1191			i8042_command(&param, 0x1059);
1192			i8042_unlock_chip();
1193			return 0;
1194		}
1195		break;
1196	default:
1197		return AE_ERROR;
1198	}
1199	return WMI_execute_u32(method_id, (u32)value, NULL);
1200}
1201
1202static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1203{
1204	struct wmid3_gds_return_value return_value;
1205	acpi_status status;
1206	union acpi_object *obj;
1207	struct wmid3_gds_get_input_param params = {
1208		.function_num = 0x1,
1209		.hotkey_number = commun_fn_key_number,
1210		.devices = device,
1211	};
1212	struct acpi_buffer input = {
1213		sizeof(struct wmid3_gds_get_input_param),
1214		&params
1215	};
1216	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1217
1218	status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1219	if (ACPI_FAILURE(status))
1220		return status;
1221
1222	obj = output.pointer;
1223
1224	if (!obj)
1225		return AE_ERROR;
1226	else if (obj->type != ACPI_TYPE_BUFFER) {
1227		kfree(obj);
1228		return AE_ERROR;
1229	}
1230	if (obj->buffer.length != 8) {
1231		pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1232		kfree(obj);
1233		return AE_ERROR;
1234	}
1235
1236	return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1237	kfree(obj);
1238
1239	if (return_value.error_code || return_value.ec_return_value)
1240		pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
1241			device,
1242			return_value.error_code,
1243			return_value.ec_return_value);
1244	else
1245		*value = !!(return_value.devices & device);
1246
1247	return status;
1248}
1249
1250static acpi_status wmid_v2_get_u32(u32 *value, u32 cap)
1251{
1252	u16 device;
1253
1254	switch (cap) {
1255	case ACER_CAP_WIRELESS:
1256		device = ACER_WMID3_GDS_WIRELESS;
1257		break;
1258	case ACER_CAP_BLUETOOTH:
1259		device = ACER_WMID3_GDS_BLUETOOTH;
1260		break;
1261	case ACER_CAP_THREEG:
1262		device = ACER_WMID3_GDS_THREEG;
1263		break;
1264	default:
1265		return AE_ERROR;
1266	}
1267	return wmid3_get_device_status(value, device);
1268}
1269
1270static acpi_status wmid3_set_device_status(u32 value, u16 device)
1271{
1272	struct wmid3_gds_return_value return_value;
1273	acpi_status status;
1274	union acpi_object *obj;
1275	u16 devices;
1276	struct wmid3_gds_get_input_param get_params = {
1277		.function_num = 0x1,
1278		.hotkey_number = commun_fn_key_number,
1279		.devices = commun_func_bitmap,
1280	};
1281	struct acpi_buffer get_input = {
1282		sizeof(struct wmid3_gds_get_input_param),
1283		&get_params
1284	};
1285	struct wmid3_gds_set_input_param set_params = {
1286		.function_num = 0x2,
1287		.hotkey_number = commun_fn_key_number,
1288		.devices = commun_func_bitmap,
1289	};
1290	struct acpi_buffer set_input = {
1291		sizeof(struct wmid3_gds_set_input_param),
1292		&set_params
1293	};
1294	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1295	struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
1296
1297	status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &get_input, &output);
1298	if (ACPI_FAILURE(status))
1299		return status;
1300
1301	obj = output.pointer;
1302
1303	if (!obj)
1304		return AE_ERROR;
1305	else if (obj->type != ACPI_TYPE_BUFFER) {
1306		kfree(obj);
1307		return AE_ERROR;
1308	}
1309	if (obj->buffer.length != 8) {
1310		pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1311		kfree(obj);
1312		return AE_ERROR;
1313	}
1314
1315	return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1316	kfree(obj);
1317
1318	if (return_value.error_code || return_value.ec_return_value) {
1319		pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1320			return_value.error_code,
1321			return_value.ec_return_value);
1322		return status;
1323	}
1324
1325	devices = return_value.devices;
1326	set_params.devices = (value) ? (devices | device) : (devices & ~device);
1327
1328	status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &set_input, &output2);
1329	if (ACPI_FAILURE(status))
1330		return status;
1331
1332	obj = output2.pointer;
1333
1334	if (!obj)
1335		return AE_ERROR;
1336	else if (obj->type != ACPI_TYPE_BUFFER) {
1337		kfree(obj);
1338		return AE_ERROR;
1339	}
1340	if (obj->buffer.length != 4) {
1341		pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1342		kfree(obj);
1343		return AE_ERROR;
1344	}
1345
1346	return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1347	kfree(obj);
1348
1349	if (return_value.error_code || return_value.ec_return_value)
1350		pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1351			return_value.error_code,
1352			return_value.ec_return_value);
1353
1354	return status;
1355}
1356
1357static acpi_status wmid_v2_set_u32(u32 value, u32 cap)
1358{
1359	u16 device;
1360
1361	switch (cap) {
1362	case ACER_CAP_WIRELESS:
1363		device = ACER_WMID3_GDS_WIRELESS;
1364		break;
1365	case ACER_CAP_BLUETOOTH:
1366		device = ACER_WMID3_GDS_BLUETOOTH;
1367		break;
1368	case ACER_CAP_THREEG:
1369		device = ACER_WMID3_GDS_THREEG;
1370		break;
1371	default:
1372		return AE_ERROR;
1373	}
1374	return wmid3_set_device_status(value, device);
1375}
1376
1377static void __init type_aa_dmi_decode(const struct dmi_header *header, void *d)
1378{
1379	struct hotkey_function_type_aa *type_aa;
1380
1381	/* We are looking for OEM-specific Type AAh */
1382	if (header->type != 0xAA)
1383		return;
1384
1385	has_type_aa = true;
1386	type_aa = (struct hotkey_function_type_aa *) header;
1387
1388	pr_info("Function bitmap for Communication Button: 0x%x\n",
1389		type_aa->commun_func_bitmap);
1390	commun_func_bitmap = type_aa->commun_func_bitmap;
1391
1392	if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
1393		interface->capability |= ACER_CAP_WIRELESS;
1394	if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
1395		interface->capability |= ACER_CAP_THREEG;
1396	if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
1397		interface->capability |= ACER_CAP_BLUETOOTH;
1398	if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_RFBTN)
1399		commun_func_bitmap &= ~ACER_WMID3_GDS_RFBTN;
1400
1401	commun_fn_key_number = type_aa->commun_fn_key_number;
1402}
1403
1404static acpi_status __init WMID_set_capabilities(void)
1405{
1406	struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1407	union acpi_object *obj;
1408	acpi_status status;
1409	u32 devices;
1410
1411	status = wmi_query_block(WMID_GUID2, 0, &out);
1412	if (ACPI_FAILURE(status))
1413		return status;
1414
1415	obj = (union acpi_object *) out.pointer;
1416	if (obj) {
1417		if (obj->type == ACPI_TYPE_BUFFER &&
1418			(obj->buffer.length == sizeof(u32) ||
1419			obj->buffer.length == sizeof(u64))) {
1420			devices = *((u32 *) obj->buffer.pointer);
1421		} else if (obj->type == ACPI_TYPE_INTEGER) {
1422			devices = (u32) obj->integer.value;
1423		} else {
1424			kfree(out.pointer);
1425			return AE_ERROR;
1426		}
1427	} else {
1428		kfree(out.pointer);
1429		return AE_ERROR;
1430	}
1431
1432	pr_info("Function bitmap for Communication Device: 0x%x\n", devices);
1433	if (devices & 0x07)
1434		interface->capability |= ACER_CAP_WIRELESS;
1435	if (devices & 0x40)
1436		interface->capability |= ACER_CAP_THREEG;
1437	if (devices & 0x10)
1438		interface->capability |= ACER_CAP_BLUETOOTH;
1439
1440	if (!(devices & 0x20))
1441		max_brightness = 0x9;
1442
1443	kfree(out.pointer);
1444	return status;
1445}
1446
1447static struct wmi_interface wmid_interface = {
1448	.type = ACER_WMID,
1449};
1450
1451static struct wmi_interface wmid_v2_interface = {
1452	.type = ACER_WMID_v2,
1453};
1454
1455/*
1456 * WMID Gaming interface
1457 */
1458
1459static acpi_status
1460WMI_gaming_execute_u64(u32 method_id, u64 in, u64 *out)
1461{
1462	struct acpi_buffer input = { (acpi_size) sizeof(u64), (void *)(&in) };
1463	struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
1464	union acpi_object *obj;
1465	u64 tmp = 0;
1466	acpi_status status;
1467
1468	status = wmi_evaluate_method(WMID_GUID4, 0, method_id, &input, &result);
1469
1470	if (ACPI_FAILURE(status))
1471		return status;
1472	obj = (union acpi_object *) result.pointer;
1473
1474	if (obj) {
1475		if (obj->type == ACPI_TYPE_BUFFER) {
1476			if (obj->buffer.length == sizeof(u32))
1477				tmp = *((u32 *) obj->buffer.pointer);
1478			else if (obj->buffer.length == sizeof(u64))
1479				tmp = *((u64 *) obj->buffer.pointer);
1480		} else if (obj->type == ACPI_TYPE_INTEGER) {
1481			tmp = (u64) obj->integer.value;
1482		}
1483	}
1484
1485	if (out)
1486		*out = tmp;
1487
1488	kfree(result.pointer);
1489
1490	return status;
1491}
1492
1493static acpi_status WMID_gaming_set_u64(u64 value, u32 cap)
1494{
1495	u32 method_id = 0;
1496
1497	if (!(interface->capability & cap))
1498		return AE_BAD_PARAMETER;
1499
1500	switch (cap) {
1501	case ACER_CAP_TURBO_LED:
1502		method_id = ACER_WMID_SET_GAMING_LED_METHODID;
1503		break;
1504	case ACER_CAP_TURBO_FAN:
1505		method_id = ACER_WMID_SET_GAMING_FAN_BEHAVIOR;
1506		break;
1507	case ACER_CAP_TURBO_OC:
1508		method_id = ACER_WMID_SET_GAMING_MISC_SETTING_METHODID;
1509		break;
1510	default:
1511		return AE_BAD_PARAMETER;
1512	}
1513
1514	return WMI_gaming_execute_u64(method_id, value, NULL);
1515}
1516
1517static acpi_status WMID_gaming_get_u64(u64 *value, u32 cap)
1518{
1519	acpi_status status;
1520	u64 result;
1521	u64 input;
1522	u32 method_id;
1523
1524	if (!(interface->capability & cap))
1525		return AE_BAD_PARAMETER;
1526
1527	switch (cap) {
1528	case ACER_CAP_TURBO_LED:
1529		method_id = ACER_WMID_GET_GAMING_LED_METHODID;
1530		input = 0x1;
1531		break;
1532	default:
1533		return AE_BAD_PARAMETER;
1534	}
1535	status = WMI_gaming_execute_u64(method_id, input, &result);
1536	if (ACPI_SUCCESS(status))
1537		*value = (u64) result;
1538
1539	return status;
1540}
1541
1542static void WMID_gaming_set_fan_mode(u8 fan_mode)
1543{
1544	/* fan_mode = 1 is used for auto, fan_mode = 2 used for turbo*/
1545	u64 gpu_fan_config1 = 0, gpu_fan_config2 = 0;
1546	int i;
1547
1548	if (quirks->cpu_fans > 0)
1549		gpu_fan_config2 |= 1;
1550	for (i = 0; i < (quirks->cpu_fans + quirks->gpu_fans); ++i)
1551		gpu_fan_config2 |= 1 << (i + 1);
1552	for (i = 0; i < quirks->gpu_fans; ++i)
1553		gpu_fan_config2 |= 1 << (i + 3);
1554	if (quirks->cpu_fans > 0)
1555		gpu_fan_config1 |= fan_mode;
1556	for (i = 0; i < (quirks->cpu_fans + quirks->gpu_fans); ++i)
1557		gpu_fan_config1 |= fan_mode << (2 * i + 2);
1558	for (i = 0; i < quirks->gpu_fans; ++i)
1559		gpu_fan_config1 |= fan_mode << (2 * i + 6);
1560	WMID_gaming_set_u64(gpu_fan_config2 | gpu_fan_config1 << 16, ACER_CAP_TURBO_FAN);
1561}
1562
1563/*
1564 * Generic Device (interface-independent)
1565 */
1566
1567static acpi_status get_u32(u32 *value, u32 cap)
1568{
1569	acpi_status status = AE_ERROR;
1570
1571	switch (interface->type) {
1572	case ACER_AMW0:
1573		status = AMW0_get_u32(value, cap);
1574		break;
1575	case ACER_AMW0_V2:
1576		if (cap == ACER_CAP_MAILLED) {
1577			status = AMW0_get_u32(value, cap);
1578			break;
1579		}
1580		fallthrough;
1581	case ACER_WMID:
1582		status = WMID_get_u32(value, cap);
1583		break;
1584	case ACER_WMID_v2:
1585		if (cap & (ACER_CAP_WIRELESS |
1586			   ACER_CAP_BLUETOOTH |
1587			   ACER_CAP_THREEG))
1588			status = wmid_v2_get_u32(value, cap);
1589		else if (wmi_has_guid(WMID_GUID2))
1590			status = WMID_get_u32(value, cap);
1591		break;
1592	}
1593
1594	return status;
1595}
1596
1597static acpi_status set_u32(u32 value, u32 cap)
1598{
1599	acpi_status status;
1600
1601	if (interface->capability & cap) {
1602		switch (interface->type) {
1603		case ACER_AMW0:
1604			return AMW0_set_u32(value, cap);
1605		case ACER_AMW0_V2:
1606			if (cap == ACER_CAP_MAILLED)
1607				return AMW0_set_u32(value, cap);
1608
1609			/*
1610			 * On some models, some WMID methods don't toggle
1611			 * properly. For those cases, we want to run the AMW0
1612			 * method afterwards to be certain we've really toggled
1613			 * the device state.
1614			 */
1615			if (cap == ACER_CAP_WIRELESS ||
1616				cap == ACER_CAP_BLUETOOTH) {
1617				status = WMID_set_u32(value, cap);
1618				if (ACPI_FAILURE(status))
1619					return status;
1620
1621				return AMW0_set_u32(value, cap);
1622			}
1623			fallthrough;
1624		case ACER_WMID:
1625			return WMID_set_u32(value, cap);
1626		case ACER_WMID_v2:
1627			if (cap & (ACER_CAP_WIRELESS |
1628				   ACER_CAP_BLUETOOTH |
1629				   ACER_CAP_THREEG))
1630				return wmid_v2_set_u32(value, cap);
1631			else if (wmi_has_guid(WMID_GUID2))
1632				return WMID_set_u32(value, cap);
1633			fallthrough;
1634		default:
1635			return AE_BAD_PARAMETER;
1636		}
1637	}
1638	return AE_BAD_PARAMETER;
1639}
1640
1641static void __init acer_commandline_init(void)
1642{
1643	/*
1644	 * These will all fail silently if the value given is invalid, or the
1645	 * capability isn't available on the given interface
1646	 */
1647	if (mailled >= 0)
1648		set_u32(mailled, ACER_CAP_MAILLED);
1649	if (!has_type_aa && threeg >= 0)
1650		set_u32(threeg, ACER_CAP_THREEG);
1651	if (brightness >= 0)
1652		set_u32(brightness, ACER_CAP_BRIGHTNESS);
1653}
1654
1655/*
1656 * LED device (Mail LED only, no other LEDs known yet)
1657 */
1658static void mail_led_set(struct led_classdev *led_cdev,
1659enum led_brightness value)
1660{
1661	set_u32(value, ACER_CAP_MAILLED);
1662}
1663
1664static struct led_classdev mail_led = {
1665	.name = "acer-wmi::mail",
1666	.brightness_set = mail_led_set,
1667};
1668
1669static int acer_led_init(struct device *dev)
1670{
1671	return led_classdev_register(dev, &mail_led);
1672}
1673
1674static void acer_led_exit(void)
1675{
1676	set_u32(LED_OFF, ACER_CAP_MAILLED);
1677	led_classdev_unregister(&mail_led);
1678}
1679
1680/*
1681 * Backlight device
1682 */
1683static struct backlight_device *acer_backlight_device;
1684
1685static int read_brightness(struct backlight_device *bd)
1686{
1687	u32 value;
1688	get_u32(&value, ACER_CAP_BRIGHTNESS);
1689	return value;
1690}
1691
1692static int update_bl_status(struct backlight_device *bd)
1693{
1694	int intensity = backlight_get_brightness(bd);
 
 
 
 
 
1695
1696	set_u32(intensity, ACER_CAP_BRIGHTNESS);
1697
1698	return 0;
1699}
1700
1701static const struct backlight_ops acer_bl_ops = {
1702	.get_brightness = read_brightness,
1703	.update_status = update_bl_status,
1704};
1705
1706static int acer_backlight_init(struct device *dev)
1707{
1708	struct backlight_properties props;
1709	struct backlight_device *bd;
1710
1711	memset(&props, 0, sizeof(struct backlight_properties));
1712	props.type = BACKLIGHT_PLATFORM;
1713	props.max_brightness = max_brightness;
1714	bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1715				       &props);
1716	if (IS_ERR(bd)) {
1717		pr_err("Could not register Acer backlight device\n");
1718		acer_backlight_device = NULL;
1719		return PTR_ERR(bd);
1720	}
1721
1722	acer_backlight_device = bd;
1723
1724	bd->props.power = BACKLIGHT_POWER_ON;
1725	bd->props.brightness = read_brightness(bd);
1726	backlight_update_status(bd);
1727	return 0;
1728}
1729
1730static void acer_backlight_exit(void)
1731{
1732	backlight_device_unregister(acer_backlight_device);
1733}
1734
1735/*
1736 * Accelerometer device
1737 */
1738static acpi_handle gsensor_handle;
1739
1740static int acer_gsensor_init(void)
1741{
1742	acpi_status status;
1743	struct acpi_buffer output;
1744	union acpi_object out_obj;
1745
1746	output.length = sizeof(out_obj);
1747	output.pointer = &out_obj;
1748	status = acpi_evaluate_object(gsensor_handle, "_INI", NULL, &output);
1749	if (ACPI_FAILURE(status))
1750		return -1;
1751
1752	return 0;
1753}
1754
1755static int acer_gsensor_open(struct input_dev *input)
1756{
1757	return acer_gsensor_init();
1758}
1759
1760static int acer_gsensor_event(void)
1761{
1762	acpi_status status;
1763	struct acpi_buffer output;
1764	union acpi_object out_obj[5];
1765
1766	if (!acer_wmi_accel_dev)
1767		return -1;
1768
1769	output.length = sizeof(out_obj);
1770	output.pointer = out_obj;
1771
1772	status = acpi_evaluate_object(gsensor_handle, "RDVL", NULL, &output);
1773	if (ACPI_FAILURE(status))
1774		return -1;
1775
1776	if (out_obj->package.count != 4)
1777		return -1;
1778
1779	input_report_abs(acer_wmi_accel_dev, ABS_X,
1780		(s16)out_obj->package.elements[0].integer.value);
1781	input_report_abs(acer_wmi_accel_dev, ABS_Y,
1782		(s16)out_obj->package.elements[1].integer.value);
1783	input_report_abs(acer_wmi_accel_dev, ABS_Z,
1784		(s16)out_obj->package.elements[2].integer.value);
1785	input_sync(acer_wmi_accel_dev);
1786	return 0;
1787}
1788
1789static int acer_get_fan_speed(int fan)
1790{
1791	if (quirks->predator_v4) {
1792		acpi_status status;
1793		u64 fanspeed;
1794
1795		status = WMI_gaming_execute_u64(
1796			ACER_WMID_GET_GAMING_SYS_INFO_METHODID,
1797			fan == 0 ? ACER_WMID_CMD_GET_PREDATOR_V4_CPU_FAN_SPEED :
1798				   ACER_WMID_CMD_GET_PREDATOR_V4_GPU_FAN_SPEED,
1799			&fanspeed);
1800
1801		if (ACPI_FAILURE(status))
1802			return -EIO;
1803
1804		return FIELD_GET(ACER_PREDATOR_V4_FAN_SPEED_READ_BIT_MASK, fanspeed);
1805	}
1806	return -EOPNOTSUPP;
1807}
1808
1809/*
1810 *  Predator series turbo button
1811 */
1812static int acer_toggle_turbo(void)
1813{
1814	u64 turbo_led_state;
1815
1816	/* Get current state from turbo button */
1817	if (ACPI_FAILURE(WMID_gaming_get_u64(&turbo_led_state, ACER_CAP_TURBO_LED)))
1818		return -1;
1819
1820	if (turbo_led_state) {
1821		/* Turn off turbo led */
1822		WMID_gaming_set_u64(0x1, ACER_CAP_TURBO_LED);
1823
1824		/* Set FAN mode to auto */
1825		WMID_gaming_set_fan_mode(0x1);
1826
1827		/* Set OC to normal */
1828		WMID_gaming_set_u64(0x5, ACER_CAP_TURBO_OC);
1829		WMID_gaming_set_u64(0x7, ACER_CAP_TURBO_OC);
1830	} else {
1831		/* Turn on turbo led */
1832		WMID_gaming_set_u64(0x10001, ACER_CAP_TURBO_LED);
1833
1834		/* Set FAN mode to turbo */
1835		WMID_gaming_set_fan_mode(0x2);
1836
1837		/* Set OC to turbo mode */
1838		WMID_gaming_set_u64(0x205, ACER_CAP_TURBO_OC);
1839		WMID_gaming_set_u64(0x207, ACER_CAP_TURBO_OC);
1840	}
1841	return turbo_led_state;
1842}
1843
1844static int
1845acer_predator_v4_platform_profile_get(struct platform_profile_handler *pprof,
1846				      enum platform_profile_option *profile)
1847{
1848	u8 tp;
1849	int err;
1850
1851	err = ec_read(ACER_PREDATOR_V4_THERMAL_PROFILE_EC_OFFSET, &tp);
1852
1853	if (err < 0)
1854		return err;
1855
1856	switch (tp) {
1857	case ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO:
1858		*profile = PLATFORM_PROFILE_PERFORMANCE;
1859		break;
1860	case ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE:
1861		*profile = PLATFORM_PROFILE_BALANCED_PERFORMANCE;
1862		break;
1863	case ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED:
1864		*profile = PLATFORM_PROFILE_BALANCED;
1865		break;
1866	case ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET:
1867		*profile = PLATFORM_PROFILE_QUIET;
1868		break;
1869	case ACER_PREDATOR_V4_THERMAL_PROFILE_ECO:
1870		*profile = PLATFORM_PROFILE_LOW_POWER;
1871		break;
1872	default:
1873		return -EOPNOTSUPP;
1874	}
1875
1876	return 0;
1877}
1878
1879static int
1880acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof,
1881				      enum platform_profile_option profile)
1882{
1883	int tp;
1884	acpi_status status;
1885
1886	switch (profile) {
1887	case PLATFORM_PROFILE_PERFORMANCE:
1888		tp = ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI;
1889		break;
1890	case PLATFORM_PROFILE_BALANCED_PERFORMANCE:
1891		tp = ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE_WMI;
1892		break;
1893	case PLATFORM_PROFILE_BALANCED:
1894		tp = ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI;
1895		break;
1896	case PLATFORM_PROFILE_QUIET:
1897		tp = ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET_WMI;
1898		break;
1899	case PLATFORM_PROFILE_LOW_POWER:
1900		tp = ACER_PREDATOR_V4_THERMAL_PROFILE_ECO_WMI;
1901		break;
1902	default:
1903		return -EOPNOTSUPP;
1904	}
1905
1906	status = WMI_gaming_execute_u64(
1907		ACER_WMID_SET_GAMING_MISC_SETTING_METHODID, tp, NULL);
1908
1909	if (ACPI_FAILURE(status))
1910		return -EIO;
1911
1912	if (tp != ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI)
1913		last_non_turbo_profile = tp;
1914
1915	return 0;
1916}
1917
1918static int acer_platform_profile_setup(void)
1919{
1920	if (quirks->predator_v4) {
1921		int err;
1922
1923		platform_profile_handler.profile_get =
1924			acer_predator_v4_platform_profile_get;
1925		platform_profile_handler.profile_set =
1926			acer_predator_v4_platform_profile_set;
1927
1928		set_bit(PLATFORM_PROFILE_PERFORMANCE,
1929			platform_profile_handler.choices);
1930		set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE,
1931			platform_profile_handler.choices);
1932		set_bit(PLATFORM_PROFILE_BALANCED,
1933			platform_profile_handler.choices);
1934		set_bit(PLATFORM_PROFILE_QUIET,
1935			platform_profile_handler.choices);
1936		set_bit(PLATFORM_PROFILE_LOW_POWER,
1937			platform_profile_handler.choices);
1938
1939		err = platform_profile_register(&platform_profile_handler);
1940		if (err)
1941			return err;
1942
1943		platform_profile_support = true;
1944
1945		/* Set default non-turbo profile  */
1946		last_non_turbo_profile =
1947			ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI;
1948	}
1949	return 0;
1950}
1951
1952static int acer_thermal_profile_change(void)
1953{
1954	/*
1955	 * This mode key can rotate each mode or toggle turbo mode.
1956	 * On battery, only ECO and BALANCED mode are available.
1957	 */
1958	if (quirks->predator_v4) {
1959		u8 current_tp;
1960		int tp, err;
1961		u64 on_AC;
1962		acpi_status status;
1963
1964		err = ec_read(ACER_PREDATOR_V4_THERMAL_PROFILE_EC_OFFSET,
1965			      &current_tp);
1966
1967		if (err < 0)
1968			return err;
1969
1970		/* Check power source */
1971		status = WMI_gaming_execute_u64(
1972			ACER_WMID_GET_GAMING_SYS_INFO_METHODID,
1973			ACER_WMID_CMD_GET_PREDATOR_V4_BAT_STATUS, &on_AC);
1974
1975		if (ACPI_FAILURE(status))
1976			return -EIO;
1977
1978		switch (current_tp) {
1979		case ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO:
1980			if (!on_AC)
1981				tp = ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI;
1982			else if (cycle_gaming_thermal_profile)
1983				tp = ACER_PREDATOR_V4_THERMAL_PROFILE_ECO_WMI;
1984			else
1985				tp = last_non_turbo_profile;
1986			break;
1987		case ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE:
1988			if (!on_AC)
1989				tp = ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI;
1990			else
1991				tp = ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI;
1992			break;
1993		case ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED:
1994			if (!on_AC)
1995				tp = ACER_PREDATOR_V4_THERMAL_PROFILE_ECO_WMI;
1996			else if (cycle_gaming_thermal_profile)
1997				tp = ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE_WMI;
1998			else
1999				tp = ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI;
2000			break;
2001		case ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET:
2002			if (!on_AC)
2003				tp = ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI;
2004			else if (cycle_gaming_thermal_profile)
2005				tp = ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI;
2006			else
2007				tp = ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI;
2008			break;
2009		case ACER_PREDATOR_V4_THERMAL_PROFILE_ECO:
2010			if (!on_AC)
2011				tp = ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI;
2012			else if (cycle_gaming_thermal_profile)
2013				tp = ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET_WMI;
2014			else
2015				tp = ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI;
2016			break;
2017		default:
2018			return -EOPNOTSUPP;
2019		}
2020
2021		status = WMI_gaming_execute_u64(
2022			ACER_WMID_SET_GAMING_MISC_SETTING_METHODID, tp, NULL);
2023
2024		if (ACPI_FAILURE(status))
2025			return -EIO;
2026
2027		/* Store non-turbo profile for turbo mode toggle*/
2028		if (tp != ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI)
2029			last_non_turbo_profile = tp;
2030
2031		platform_profile_notify();
2032	}
2033
2034	return 0;
2035}
2036
2037/*
2038 * Switch series keyboard dock status
2039 */
2040static int acer_kbd_dock_state_to_sw_tablet_mode(u8 kbd_dock_state)
2041{
2042	switch (kbd_dock_state) {
2043	case 0x01: /* Docked, traditional clamshell laptop mode */
2044		return 0;
2045	case 0x04: /* Stand-alone tablet */
2046	case 0x40: /* Docked, tent mode, keyboard not usable */
2047		return 1;
2048	default:
2049		pr_warn("Unknown kbd_dock_state 0x%02x\n", kbd_dock_state);
2050	}
2051
2052	return 0;
2053}
2054
2055static void acer_kbd_dock_get_initial_state(void)
2056{
2057	u8 *output, input[8] = { 0x05, 0x00, };
2058	struct acpi_buffer input_buf = { sizeof(input), input };
2059	struct acpi_buffer output_buf = { ACPI_ALLOCATE_BUFFER, NULL };
2060	union acpi_object *obj;
2061	acpi_status status;
2062	int sw_tablet_mode;
2063
2064	status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input_buf, &output_buf);
2065	if (ACPI_FAILURE(status)) {
2066		pr_err("Error getting keyboard-dock initial status: %s\n",
2067		       acpi_format_exception(status));
2068		return;
2069	}
2070
2071	obj = output_buf.pointer;
2072	if (!obj || obj->type != ACPI_TYPE_BUFFER || obj->buffer.length != 8) {
2073		pr_err("Unexpected output format getting keyboard-dock initial status\n");
2074		goto out_free_obj;
2075	}
2076
2077	output = obj->buffer.pointer;
2078	if (output[0] != 0x00 || (output[3] != 0x05 && output[3] != 0x45)) {
2079		pr_err("Unexpected output [0]=0x%02x [3]=0x%02x getting keyboard-dock initial status\n",
2080		       output[0], output[3]);
2081		goto out_free_obj;
2082	}
2083
2084	sw_tablet_mode = acer_kbd_dock_state_to_sw_tablet_mode(output[4]);
2085	input_report_switch(acer_wmi_input_dev, SW_TABLET_MODE, sw_tablet_mode);
2086
2087out_free_obj:
2088	kfree(obj);
2089}
2090
2091static void acer_kbd_dock_event(const struct event_return_value *event)
2092{
2093	int sw_tablet_mode;
2094
2095	if (!has_cap(ACER_CAP_KBD_DOCK))
2096		return;
2097
2098	sw_tablet_mode = acer_kbd_dock_state_to_sw_tablet_mode(event->kbd_dock_state);
2099	input_report_switch(acer_wmi_input_dev, SW_TABLET_MODE, sw_tablet_mode);
2100	input_sync(acer_wmi_input_dev);
2101}
2102
2103/*
2104 * Rfkill devices
2105 */
2106static void acer_rfkill_update(struct work_struct *ignored);
2107static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
2108static void acer_rfkill_update(struct work_struct *ignored)
2109{
2110	u32 state;
2111	acpi_status status;
2112
2113	if (has_cap(ACER_CAP_WIRELESS)) {
2114		status = get_u32(&state, ACER_CAP_WIRELESS);
2115		if (ACPI_SUCCESS(status)) {
2116			if (quirks->wireless == 3)
2117				rfkill_set_hw_state(wireless_rfkill, !state);
2118			else
2119				rfkill_set_sw_state(wireless_rfkill, !state);
2120		}
2121	}
2122
2123	if (has_cap(ACER_CAP_BLUETOOTH)) {
2124		status = get_u32(&state, ACER_CAP_BLUETOOTH);
2125		if (ACPI_SUCCESS(status))
2126			rfkill_set_sw_state(bluetooth_rfkill, !state);
2127	}
2128
2129	if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
2130		status = get_u32(&state, ACER_WMID3_GDS_THREEG);
2131		if (ACPI_SUCCESS(status))
2132			rfkill_set_sw_state(threeg_rfkill, !state);
2133	}
2134
2135	schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
2136}
2137
2138static int acer_rfkill_set(void *data, bool blocked)
2139{
2140	acpi_status status;
2141	u32 cap = (unsigned long)data;
2142
2143	if (rfkill_inited) {
2144		status = set_u32(!blocked, cap);
2145		if (ACPI_FAILURE(status))
2146			return -ENODEV;
2147	}
2148
2149	return 0;
2150}
2151
2152static const struct rfkill_ops acer_rfkill_ops = {
2153	.set_block = acer_rfkill_set,
2154};
2155
2156static struct rfkill *acer_rfkill_register(struct device *dev,
2157					   enum rfkill_type type,
2158					   char *name, u32 cap)
2159{
2160	int err;
2161	struct rfkill *rfkill_dev;
2162	u32 state;
2163	acpi_status status;
2164
2165	rfkill_dev = rfkill_alloc(name, dev, type,
2166				  &acer_rfkill_ops,
2167				  (void *)(unsigned long)cap);
2168	if (!rfkill_dev)
2169		return ERR_PTR(-ENOMEM);
2170
2171	status = get_u32(&state, cap);
2172
2173	err = rfkill_register(rfkill_dev);
2174	if (err) {
2175		rfkill_destroy(rfkill_dev);
2176		return ERR_PTR(err);
2177	}
2178
2179	if (ACPI_SUCCESS(status))
2180		rfkill_set_sw_state(rfkill_dev, !state);
2181
2182	return rfkill_dev;
2183}
2184
2185static int acer_rfkill_init(struct device *dev)
2186{
2187	int err;
2188
2189	if (has_cap(ACER_CAP_WIRELESS)) {
2190		wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
2191			"acer-wireless", ACER_CAP_WIRELESS);
2192		if (IS_ERR(wireless_rfkill)) {
2193			err = PTR_ERR(wireless_rfkill);
2194			goto error_wireless;
2195		}
2196	}
2197
2198	if (has_cap(ACER_CAP_BLUETOOTH)) {
2199		bluetooth_rfkill = acer_rfkill_register(dev,
2200			RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
2201			ACER_CAP_BLUETOOTH);
2202		if (IS_ERR(bluetooth_rfkill)) {
2203			err = PTR_ERR(bluetooth_rfkill);
2204			goto error_bluetooth;
2205		}
2206	}
2207
2208	if (has_cap(ACER_CAP_THREEG)) {
2209		threeg_rfkill = acer_rfkill_register(dev,
2210			RFKILL_TYPE_WWAN, "acer-threeg",
2211			ACER_CAP_THREEG);
2212		if (IS_ERR(threeg_rfkill)) {
2213			err = PTR_ERR(threeg_rfkill);
2214			goto error_threeg;
2215		}
2216	}
2217
2218	rfkill_inited = true;
2219
2220	if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
2221	    has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
2222		schedule_delayed_work(&acer_rfkill_work,
2223			round_jiffies_relative(HZ));
2224
2225	return 0;
2226
2227error_threeg:
2228	if (has_cap(ACER_CAP_BLUETOOTH)) {
2229		rfkill_unregister(bluetooth_rfkill);
2230		rfkill_destroy(bluetooth_rfkill);
2231	}
2232error_bluetooth:
2233	if (has_cap(ACER_CAP_WIRELESS)) {
2234		rfkill_unregister(wireless_rfkill);
2235		rfkill_destroy(wireless_rfkill);
2236	}
2237error_wireless:
2238	return err;
2239}
2240
2241static void acer_rfkill_exit(void)
2242{
2243	if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
2244	    has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
2245		cancel_delayed_work_sync(&acer_rfkill_work);
2246
2247	if (has_cap(ACER_CAP_WIRELESS)) {
2248		rfkill_unregister(wireless_rfkill);
2249		rfkill_destroy(wireless_rfkill);
2250	}
2251
2252	if (has_cap(ACER_CAP_BLUETOOTH)) {
2253		rfkill_unregister(bluetooth_rfkill);
2254		rfkill_destroy(bluetooth_rfkill);
2255	}
2256
2257	if (has_cap(ACER_CAP_THREEG)) {
2258		rfkill_unregister(threeg_rfkill);
2259		rfkill_destroy(threeg_rfkill);
2260	}
 
2261}
2262
2263static void acer_wmi_notify(union acpi_object *obj, void *context)
2264{
 
 
2265	struct event_return_value return_value;
 
2266	u16 device_state;
2267	const struct key_entry *key;
2268	u32 scancode;
2269
 
 
 
 
 
 
 
 
2270	if (!obj)
2271		return;
2272	if (obj->type != ACPI_TYPE_BUFFER) {
2273		pr_warn("Unknown response received %d\n", obj->type);
 
2274		return;
2275	}
2276	if (obj->buffer.length != 8) {
2277		pr_warn("Unknown buffer length %d\n", obj->buffer.length);
 
2278		return;
2279	}
2280
2281	return_value = *((struct event_return_value *)obj->buffer.pointer);
 
2282
2283	switch (return_value.function) {
2284	case WMID_HOTKEY_EVENT:
2285		device_state = return_value.device_state;
2286		pr_debug("device state: 0x%x\n", device_state);
2287
2288		key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
2289							return_value.key_num);
2290		if (!key) {
2291			pr_warn("Unknown key number - 0x%x\n",
2292				return_value.key_num);
2293		} else {
2294			scancode = return_value.key_num;
2295			switch (key->keycode) {
2296			case KEY_WLAN:
2297			case KEY_BLUETOOTH:
2298				if (has_cap(ACER_CAP_WIRELESS))
2299					rfkill_set_sw_state(wireless_rfkill,
2300						!(device_state & ACER_WMID3_GDS_WIRELESS));
2301				if (has_cap(ACER_CAP_THREEG))
2302					rfkill_set_sw_state(threeg_rfkill,
2303						!(device_state & ACER_WMID3_GDS_THREEG));
2304				if (has_cap(ACER_CAP_BLUETOOTH))
2305					rfkill_set_sw_state(bluetooth_rfkill,
2306						!(device_state & ACER_WMID3_GDS_BLUETOOTH));
2307				break;
2308			case KEY_TOUCHPAD_TOGGLE:
2309				scancode = (device_state & ACER_WMID3_GDS_TOUCHPAD) ?
2310						KEY_TOUCHPAD_ON : KEY_TOUCHPAD_OFF;
2311			}
2312			sparse_keymap_report_event(acer_wmi_input_dev, scancode, 1, true);
2313		}
2314		break;
2315	case WMID_ACCEL_OR_KBD_DOCK_EVENT:
2316		acer_gsensor_event();
2317		acer_kbd_dock_event(&return_value);
2318		break;
2319	case WMID_GAMING_TURBO_KEY_EVENT:
2320		if (return_value.key_num == 0x4)
2321			acer_toggle_turbo();
2322		if (return_value.key_num == 0x5 && has_cap(ACER_CAP_PLATFORM_PROFILE))
2323			acer_thermal_profile_change();
2324		break;
2325	case WMID_AC_EVENT:
2326		/* We ignore AC events here */
2327		break;
2328	default:
2329		pr_warn("Unknown function number - %d - %d\n",
2330			return_value.function, return_value.key_num);
2331		break;
2332	}
2333}
2334
2335static acpi_status __init
2336wmid3_set_function_mode(struct func_input_params *params,
2337			struct func_return_value *return_value)
2338{
2339	acpi_status status;
2340	union acpi_object *obj;
2341
2342	struct acpi_buffer input = { sizeof(struct func_input_params), params };
2343	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
2344
2345	status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
2346	if (ACPI_FAILURE(status))
2347		return status;
2348
2349	obj = output.pointer;
2350
2351	if (!obj)
2352		return AE_ERROR;
2353	else if (obj->type != ACPI_TYPE_BUFFER) {
2354		kfree(obj);
2355		return AE_ERROR;
2356	}
2357	if (obj->buffer.length != 4) {
2358		pr_warn("Unknown buffer length %d\n", obj->buffer.length);
2359		kfree(obj);
2360		return AE_ERROR;
2361	}
2362
2363	*return_value = *((struct func_return_value *)obj->buffer.pointer);
2364	kfree(obj);
2365
2366	return status;
2367}
2368
2369static int __init acer_wmi_enable_ec_raw(void)
2370{
2371	struct func_return_value return_value;
2372	acpi_status status;
2373	struct func_input_params params = {
2374		.function_num = 0x1,
2375		.commun_devices = 0xFFFF,
2376		.devices = 0xFFFF,
2377		.app_status = 0x00,		/* Launch Manager Deactive */
2378		.app_mask = 0x01,
2379	};
2380
2381	status = wmid3_set_function_mode(&params, &return_value);
2382
2383	if (return_value.error_code || return_value.ec_return_value)
2384		pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
2385			return_value.error_code,
2386			return_value.ec_return_value);
2387	else
2388		pr_info("Enabled EC raw mode\n");
2389
2390	return status;
2391}
2392
2393static int __init acer_wmi_enable_lm(void)
2394{
2395	struct func_return_value return_value;
2396	acpi_status status;
2397	struct func_input_params params = {
2398		.function_num = 0x1,
2399		.commun_devices = 0xFFFF,
2400		.devices = 0xFFFF,
2401		.app_status = 0x01,            /* Launch Manager Active */
2402		.app_mask = 0x01,
2403	};
2404
2405	status = wmid3_set_function_mode(&params, &return_value);
2406
2407	if (return_value.error_code || return_value.ec_return_value)
2408		pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
2409			return_value.error_code,
2410			return_value.ec_return_value);
2411
2412	return status;
2413}
2414
2415static int __init acer_wmi_enable_rf_button(void)
 
 
 
 
 
 
 
 
2416{
2417	struct func_return_value return_value;
2418	acpi_status status;
2419	struct func_input_params params = {
2420		.function_num = 0x1,
2421		.commun_devices = 0xFFFF,
2422		.devices = 0xFFFF,
2423		.app_status = 0x10,            /* RF Button Active */
2424		.app_mask = 0x10,
2425	};
2426
2427	status = wmid3_set_function_mode(&params, &return_value);
2428
2429	if (return_value.error_code || return_value.ec_return_value)
2430		pr_warn("Enabling RF Button failed: 0x%x - 0x%x\n",
2431			return_value.error_code,
2432			return_value.ec_return_value);
2433
2434	return status;
 
 
 
 
 
2435}
2436
2437static int __init acer_wmi_accel_setup(void)
2438{
2439	struct acpi_device *adev;
2440	int err;
2441
2442	adev = acpi_dev_get_first_match_dev("BST0001", NULL, -1);
2443	if (!adev)
2444		return -ENODEV;
2445
2446	gsensor_handle = acpi_device_handle(adev);
2447	acpi_dev_put(adev);
2448
2449	acer_wmi_accel_dev = input_allocate_device();
2450	if (!acer_wmi_accel_dev)
2451		return -ENOMEM;
2452
2453	acer_wmi_accel_dev->open = acer_gsensor_open;
2454
2455	acer_wmi_accel_dev->name = "Acer BMA150 accelerometer";
2456	acer_wmi_accel_dev->phys = "wmi/input1";
2457	acer_wmi_accel_dev->id.bustype = BUS_HOST;
2458	acer_wmi_accel_dev->evbit[0] = BIT_MASK(EV_ABS);
2459	input_set_abs_params(acer_wmi_accel_dev, ABS_X, -16384, 16384, 0, 0);
2460	input_set_abs_params(acer_wmi_accel_dev, ABS_Y, -16384, 16384, 0, 0);
2461	input_set_abs_params(acer_wmi_accel_dev, ABS_Z, -16384, 16384, 0, 0);
2462
2463	err = input_register_device(acer_wmi_accel_dev);
2464	if (err)
2465		goto err_free_dev;
2466
2467	return 0;
2468
2469err_free_dev:
2470	input_free_device(acer_wmi_accel_dev);
2471	return err;
2472}
2473
 
 
 
 
 
2474static int __init acer_wmi_input_setup(void)
2475{
2476	acpi_status status;
2477	int err;
2478
2479	acer_wmi_input_dev = input_allocate_device();
2480	if (!acer_wmi_input_dev)
2481		return -ENOMEM;
2482
2483	acer_wmi_input_dev->name = "Acer WMI hotkeys";
2484	acer_wmi_input_dev->phys = "wmi/input0";
2485	acer_wmi_input_dev->id.bustype = BUS_HOST;
2486
2487	err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
2488	if (err)
2489		goto err_free_dev;
2490
2491	if (has_cap(ACER_CAP_KBD_DOCK))
2492		input_set_capability(acer_wmi_input_dev, EV_SW, SW_TABLET_MODE);
2493
2494	status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
2495						acer_wmi_notify, NULL);
2496	if (ACPI_FAILURE(status)) {
2497		err = -EIO;
2498		goto err_free_dev;
2499	}
2500
2501	if (has_cap(ACER_CAP_KBD_DOCK))
2502		acer_kbd_dock_get_initial_state();
2503
2504	err = input_register_device(acer_wmi_input_dev);
2505	if (err)
2506		goto err_uninstall_notifier;
2507
2508	return 0;
2509
2510err_uninstall_notifier:
2511	wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
 
 
2512err_free_dev:
2513	input_free_device(acer_wmi_input_dev);
2514	return err;
2515}
2516
2517static void acer_wmi_input_destroy(void)
2518{
2519	wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
 
2520	input_unregister_device(acer_wmi_input_dev);
2521}
2522
2523/*
2524 * debugfs functions
2525 */
2526static u32 get_wmid_devices(void)
2527{
2528	struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
2529	union acpi_object *obj;
2530	acpi_status status;
2531	u32 devices = 0;
2532
2533	status = wmi_query_block(WMID_GUID2, 0, &out);
2534	if (ACPI_FAILURE(status))
2535		return 0;
2536
2537	obj = (union acpi_object *) out.pointer;
2538	if (obj) {
2539		if (obj->type == ACPI_TYPE_BUFFER &&
2540			(obj->buffer.length == sizeof(u32) ||
2541			obj->buffer.length == sizeof(u64))) {
2542			devices = *((u32 *) obj->buffer.pointer);
2543		} else if (obj->type == ACPI_TYPE_INTEGER) {
2544			devices = (u32) obj->integer.value;
2545		}
2546	}
2547
2548	kfree(out.pointer);
2549	return devices;
2550}
2551
2552static int acer_wmi_hwmon_init(void);
2553
2554/*
2555 * Platform device
2556 */
2557static int acer_platform_probe(struct platform_device *device)
2558{
2559	int err;
2560
2561	if (has_cap(ACER_CAP_MAILLED)) {
2562		err = acer_led_init(&device->dev);
2563		if (err)
2564			goto error_mailled;
2565	}
2566
2567	if (has_cap(ACER_CAP_BRIGHTNESS)) {
2568		err = acer_backlight_init(&device->dev);
2569		if (err)
2570			goto error_brightness;
2571	}
2572
2573	err = acer_rfkill_init(&device->dev);
2574	if (err)
2575		goto error_rfkill;
2576
2577	if (has_cap(ACER_CAP_PLATFORM_PROFILE)) {
2578		err = acer_platform_profile_setup();
2579		if (err)
2580			goto error_platform_profile;
2581	}
2582
2583	if (has_cap(ACER_CAP_FAN_SPEED_READ)) {
2584		err = acer_wmi_hwmon_init();
2585		if (err)
2586			goto error_hwmon;
2587	}
2588
2589	return 0;
2590
2591error_hwmon:
2592	if (platform_profile_support)
2593		platform_profile_remove();
2594error_platform_profile:
2595	acer_rfkill_exit();
2596error_rfkill:
2597	if (has_cap(ACER_CAP_BRIGHTNESS))
2598		acer_backlight_exit();
2599error_brightness:
2600	if (has_cap(ACER_CAP_MAILLED))
2601		acer_led_exit();
2602error_mailled:
2603	return err;
2604}
2605
2606static void acer_platform_remove(struct platform_device *device)
2607{
2608	if (has_cap(ACER_CAP_MAILLED))
2609		acer_led_exit();
2610	if (has_cap(ACER_CAP_BRIGHTNESS))
2611		acer_backlight_exit();
2612
2613	acer_rfkill_exit();
2614
2615	if (platform_profile_support)
2616		platform_profile_remove();
2617}
2618
2619#ifdef CONFIG_PM_SLEEP
2620static int acer_suspend(struct device *dev)
2621{
2622	u32 value;
2623	struct acer_data *data = &interface->data;
2624
2625	if (!data)
2626		return -ENOMEM;
2627
2628	if (has_cap(ACER_CAP_MAILLED)) {
2629		get_u32(&value, ACER_CAP_MAILLED);
2630		set_u32(LED_OFF, ACER_CAP_MAILLED);
2631		data->mailled = value;
2632	}
2633
2634	if (has_cap(ACER_CAP_BRIGHTNESS)) {
2635		get_u32(&value, ACER_CAP_BRIGHTNESS);
2636		data->brightness = value;
2637	}
2638
2639	return 0;
2640}
2641
2642static int acer_resume(struct device *dev)
2643{
2644	struct acer_data *data = &interface->data;
2645
2646	if (!data)
2647		return -ENOMEM;
2648
2649	if (has_cap(ACER_CAP_MAILLED))
2650		set_u32(data->mailled, ACER_CAP_MAILLED);
2651
2652	if (has_cap(ACER_CAP_BRIGHTNESS))
2653		set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
2654
2655	if (acer_wmi_accel_dev)
2656		acer_gsensor_init();
2657
2658	return 0;
2659}
2660#else
2661#define acer_suspend	NULL
2662#define acer_resume	NULL
2663#endif
2664
2665static SIMPLE_DEV_PM_OPS(acer_pm, acer_suspend, acer_resume);
2666
2667static void acer_platform_shutdown(struct platform_device *device)
2668{
2669	struct acer_data *data = &interface->data;
2670
2671	if (!data)
2672		return;
2673
2674	if (has_cap(ACER_CAP_MAILLED))
2675		set_u32(LED_OFF, ACER_CAP_MAILLED);
2676}
2677
2678static struct platform_driver acer_platform_driver = {
2679	.driver = {
2680		.name = "acer-wmi",
2681		.pm = &acer_pm,
2682	},
2683	.probe = acer_platform_probe,
2684	.remove = acer_platform_remove,
2685	.shutdown = acer_platform_shutdown,
2686};
2687
2688static struct platform_device *acer_platform_device;
2689
2690static void remove_debugfs(void)
2691{
2692	debugfs_remove_recursive(interface->debug.root);
 
2693}
2694
2695static void __init create_debugfs(void)
2696{
2697	interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
2698
2699	debugfs_create_u32("devices", S_IRUGO, interface->debug.root,
2700			   &interface->debug.wmid_devices);
2701}
2702
2703static umode_t acer_wmi_hwmon_is_visible(const void *data,
2704					 enum hwmon_sensor_types type, u32 attr,
2705					 int channel)
2706{
2707	switch (type) {
2708	case hwmon_fan:
2709		if (acer_get_fan_speed(channel) >= 0)
2710			return 0444;
2711		break;
2712	default:
2713		return 0;
2714	}
2715
2716	return 0;
2717}
2718
2719static int acer_wmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
2720			       u32 attr, int channel, long *val)
2721{
2722	int ret;
2723
2724	switch (type) {
2725	case hwmon_fan:
2726		ret = acer_get_fan_speed(channel);
2727		if (ret < 0)
2728			return ret;
2729		*val = ret;
2730		break;
2731	default:
2732		return -EOPNOTSUPP;
2733	}
2734
2735	return 0;
2736}
2737
2738static const struct hwmon_channel_info *const acer_wmi_hwmon_info[] = {
2739	HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT, HWMON_F_INPUT), NULL
2740};
2741
2742static const struct hwmon_ops acer_wmi_hwmon_ops = {
2743	.read = acer_wmi_hwmon_read,
2744	.is_visible = acer_wmi_hwmon_is_visible,
2745};
2746
2747static const struct hwmon_chip_info acer_wmi_hwmon_chip_info = {
2748	.ops = &acer_wmi_hwmon_ops,
2749	.info = acer_wmi_hwmon_info,
2750};
2751
2752static int acer_wmi_hwmon_init(void)
2753{
2754	struct device *dev = &acer_platform_device->dev;
2755	struct device *hwmon;
2756
2757	hwmon = devm_hwmon_device_register_with_info(dev, "acer",
2758						     &acer_platform_driver,
2759						     &acer_wmi_hwmon_chip_info,
2760						     NULL);
2761
2762	if (IS_ERR(hwmon)) {
2763		dev_err(dev, "Could not register acer hwmon device\n");
2764		return PTR_ERR(hwmon);
2765	}
2766
2767	return 0;
2768}
2769
2770static int __init acer_wmi_init(void)
2771{
2772	int err;
2773
2774	pr_info("Acer Laptop ACPI-WMI Extras\n");
2775
2776	if (dmi_check_system(acer_blacklist)) {
2777		pr_info("Blacklisted hardware detected - not loading\n");
2778		return -ENODEV;
2779	}
2780
2781	find_quirks();
2782
2783	/*
2784	 * The AMW0_GUID1 wmi is not only found on Acer family but also other
2785	 * machines like Lenovo, Fujitsu and Medion. In the past days,
2786	 * acer-wmi driver handled those non-Acer machines by quirks list.
2787	 * But actually acer-wmi driver was loaded on any machines that have
2788	 * AMW0_GUID1. This behavior is strange because those machines should
2789	 * be supported by appropriate wmi drivers. e.g. fujitsu-laptop,
2790	 * ideapad-laptop. So, here checks the machine that has AMW0_GUID1
2791	 * should be in Acer/Gateway/Packard Bell white list, or it's already
2792	 * in the past quirk list.
2793	 */
2794	if (wmi_has_guid(AMW0_GUID1) &&
2795	    !dmi_check_system(amw0_whitelist) &&
2796	    quirks == &quirk_unknown) {
2797		pr_debug("Unsupported machine has AMW0_GUID1, unable to load\n");
2798		return -ENODEV;
2799	}
2800
2801	/*
2802	 * Detect which ACPI-WMI interface we're using.
2803	 */
2804	if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2805		interface = &AMW0_V2_interface;
2806
2807	if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2808		interface = &wmid_interface;
2809
2810	if (wmi_has_guid(WMID_GUID3))
2811		interface = &wmid_v2_interface;
2812
2813	if (interface)
2814		dmi_walk(type_aa_dmi_decode, NULL);
2815
2816	if (wmi_has_guid(WMID_GUID2) && interface) {
2817		if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) {
2818			pr_err("Unable to detect available WMID devices\n");
2819			return -ENODEV;
2820		}
2821		/* WMID always provides brightness methods */
2822		interface->capability |= ACER_CAP_BRIGHTNESS;
2823	} else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa && force_caps == -1) {
2824		pr_err("No WMID device detection method found\n");
2825		return -ENODEV;
2826	}
2827
2828	if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
2829		interface = &AMW0_interface;
2830
2831		if (ACPI_FAILURE(AMW0_set_capabilities())) {
2832			pr_err("Unable to detect available AMW0 devices\n");
2833			return -ENODEV;
2834		}
2835	}
2836
2837	if (wmi_has_guid(AMW0_GUID1))
2838		AMW0_find_mailled();
2839
2840	if (!interface) {
2841		pr_err("No or unsupported WMI interface, unable to load\n");
2842		return -ENODEV;
2843	}
2844
2845	set_quirks();
2846
 
 
 
2847	if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
2848		interface->capability &= ~ACER_CAP_BRIGHTNESS;
2849
2850	if (wmi_has_guid(WMID_GUID3))
2851		interface->capability |= ACER_CAP_SET_FUNCTION_MODE;
2852
2853	if (force_caps != -1)
2854		interface->capability = force_caps;
2855
2856	if (wmi_has_guid(WMID_GUID3) &&
2857	    (interface->capability & ACER_CAP_SET_FUNCTION_MODE)) {
2858		if (ACPI_FAILURE(acer_wmi_enable_rf_button()))
2859			pr_warn("Cannot enable RF Button Driver\n");
2860
2861		if (ec_raw_mode) {
2862			if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
2863				pr_err("Cannot enable EC raw mode\n");
2864				return -ENODEV;
2865			}
2866		} else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
2867			pr_err("Cannot enable Launch Manager mode\n");
2868			return -ENODEV;
2869		}
2870	} else if (ec_raw_mode) {
2871		pr_info("No WMID EC raw mode enable method\n");
2872	}
2873
2874	if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
2875		err = acer_wmi_input_setup();
2876		if (err)
2877			return err;
2878		err = acer_wmi_accel_setup();
2879		if (err && err != -ENODEV)
2880			pr_warn("Cannot enable accelerometer\n");
2881	}
2882
 
 
2883	err = platform_driver_register(&acer_platform_driver);
2884	if (err) {
2885		pr_err("Unable to register platform driver\n");
2886		goto error_platform_register;
2887	}
2888
2889	acer_platform_device = platform_device_alloc("acer-wmi", PLATFORM_DEVID_NONE);
2890	if (!acer_platform_device) {
2891		err = -ENOMEM;
2892		goto error_device_alloc;
2893	}
2894
2895	err = platform_device_add(acer_platform_device);
2896	if (err)
2897		goto error_device_add;
2898
2899	if (wmi_has_guid(WMID_GUID2)) {
2900		interface->debug.wmid_devices = get_wmid_devices();
2901		create_debugfs();
 
 
2902	}
2903
2904	/* Override any initial settings with values from the commandline */
2905	acer_commandline_init();
2906
2907	return 0;
2908
 
 
2909error_device_add:
2910	platform_device_put(acer_platform_device);
2911error_device_alloc:
2912	platform_driver_unregister(&acer_platform_driver);
2913error_platform_register:
2914	if (wmi_has_guid(ACERWMID_EVENT_GUID))
2915		acer_wmi_input_destroy();
2916	if (acer_wmi_accel_dev)
2917		input_unregister_device(acer_wmi_accel_dev);
2918
2919	return err;
2920}
2921
2922static void __exit acer_wmi_exit(void)
2923{
2924	if (wmi_has_guid(ACERWMID_EVENT_GUID))
2925		acer_wmi_input_destroy();
2926
2927	if (acer_wmi_accel_dev)
2928		input_unregister_device(acer_wmi_accel_dev);
2929
2930	remove_debugfs();
2931	platform_device_unregister(acer_platform_device);
2932	platform_driver_unregister(&acer_platform_driver);
2933
2934	pr_info("Acer Laptop WMI Extras unloaded\n");
 
2935}
2936
2937module_init(acer_wmi_init);
2938module_exit(acer_wmi_exit);
v4.10.11
 
   1/*
   2 *  Acer WMI Laptop Extras
   3 *
   4 *  Copyright (C) 2007-2009	Carlos Corbacho <carlos@strangeworlds.co.uk>
   5 *
   6 *  Based on acer_acpi:
   7 *    Copyright (C) 2005-2007	E.M. Smith
   8 *    Copyright (C) 2007-2008	Carlos Corbacho <cathectic@gmail.com>
   9 *
  10 *  This program is free software; you can redistribute it and/or modify
  11 *  it under the terms of the GNU General Public License as published by
  12 *  the Free Software Foundation; either version 2 of the License, or
  13 *  (at your option) any later version.
  14 *
  15 *  This program is distributed in the hope that it will be useful,
  16 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18 *  GNU General Public License for more details.
  19 *
  20 *  You should have received a copy of the GNU General Public License
  21 *  along with this program; if not, write to the Free Software
  22 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23 */
  24
  25#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  26
  27#include <linux/kernel.h>
  28#include <linux/module.h>
  29#include <linux/init.h>
  30#include <linux/types.h>
  31#include <linux/dmi.h>
  32#include <linux/fb.h>
  33#include <linux/backlight.h>
  34#include <linux/leds.h>
  35#include <linux/platform_device.h>
 
  36#include <linux/acpi.h>
  37#include <linux/i8042.h>
  38#include <linux/rfkill.h>
  39#include <linux/workqueue.h>
  40#include <linux/debugfs.h>
  41#include <linux/slab.h>
  42#include <linux/input.h>
  43#include <linux/input/sparse-keymap.h>
  44#include <acpi/video.h>
 
 
  45
  46MODULE_AUTHOR("Carlos Corbacho");
  47MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
  48MODULE_LICENSE("GPL");
  49
  50/*
  51 * Magic Number
  52 * Meaning is unknown - this number is required for writing to ACPI for AMW0
  53 * (it's also used in acerhk when directly accessing the BIOS)
  54 */
  55#define ACER_AMW0_WRITE	0x9610
  56
  57/*
  58 * Bit masks for the AMW0 interface
  59 */
  60#define ACER_AMW0_WIRELESS_MASK  0x35
  61#define ACER_AMW0_BLUETOOTH_MASK 0x34
  62#define ACER_AMW0_MAILLED_MASK   0x31
  63
  64/*
  65 * Method IDs for WMID interface
  66 */
  67#define ACER_WMID_GET_WIRELESS_METHODID		1
  68#define ACER_WMID_GET_BLUETOOTH_METHODID	2
  69#define ACER_WMID_GET_BRIGHTNESS_METHODID	3
  70#define ACER_WMID_SET_WIRELESS_METHODID		4
  71#define ACER_WMID_SET_BLUETOOTH_METHODID	5
  72#define ACER_WMID_SET_BRIGHTNESS_METHODID	6
  73#define ACER_WMID_GET_THREEG_METHODID		10
  74#define ACER_WMID_SET_THREEG_METHODID		11
  75
 
 
 
 
 
 
 
 
 
 
  76/*
  77 * Acer ACPI method GUIDs
  78 */
  79#define AMW0_GUID1		"67C3371D-95A3-4C37-BB61-DD47B491DAAB"
  80#define AMW0_GUID2		"431F16ED-0C2B-444C-B267-27DEB140CF9C"
  81#define WMID_GUID1		"6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
  82#define WMID_GUID2		"95764E09-FB56-4E83-B31A-37761F60994A"
  83#define WMID_GUID3		"61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
 
  84
  85/*
  86 * Acer ACPI event GUIDs
  87 */
  88#define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
  89
  90MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
  91MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
  92MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
  93
  94enum acer_wmi_event_ids {
  95	WMID_HOTKEY_EVENT = 0x1,
  96	WMID_ACCEL_EVENT = 0x5,
 
 
 
 
 
 
 
 
  97};
  98
  99static const struct key_entry acer_wmi_keymap[] __initconst = {
 100	{KE_KEY, 0x01, {KEY_WLAN} },     /* WiFi */
 101	{KE_KEY, 0x03, {KEY_WLAN} },     /* WiFi */
 102	{KE_KEY, 0x04, {KEY_WLAN} },     /* WiFi */
 103	{KE_KEY, 0x12, {KEY_BLUETOOTH} },	/* BT */
 104	{KE_KEY, 0x21, {KEY_PROG1} },    /* Backup */
 105	{KE_KEY, 0x22, {KEY_PROG2} },    /* Arcade */
 106	{KE_KEY, 0x23, {KEY_PROG3} },    /* P_Key */
 107	{KE_KEY, 0x24, {KEY_PROG4} },    /* Social networking_Key */
 
 108	{KE_KEY, 0x29, {KEY_PROG3} },    /* P_Key for TM8372 */
 109	{KE_IGNORE, 0x41, {KEY_MUTE} },
 110	{KE_IGNORE, 0x42, {KEY_PREVIOUSSONG} },
 111	{KE_IGNORE, 0x4d, {KEY_PREVIOUSSONG} },
 112	{KE_IGNORE, 0x43, {KEY_NEXTSONG} },
 113	{KE_IGNORE, 0x4e, {KEY_NEXTSONG} },
 114	{KE_IGNORE, 0x44, {KEY_PLAYPAUSE} },
 115	{KE_IGNORE, 0x4f, {KEY_PLAYPAUSE} },
 116	{KE_IGNORE, 0x45, {KEY_STOP} },
 117	{KE_IGNORE, 0x50, {KEY_STOP} },
 118	{KE_IGNORE, 0x48, {KEY_VOLUMEUP} },
 119	{KE_IGNORE, 0x49, {KEY_VOLUMEDOWN} },
 120	{KE_IGNORE, 0x4a, {KEY_VOLUMEDOWN} },
 121	{KE_IGNORE, 0x61, {KEY_SWITCHVIDEOMODE} },
 
 
 
 
 
 
 122	{KE_IGNORE, 0x62, {KEY_BRIGHTNESSUP} },
 123	{KE_IGNORE, 0x63, {KEY_BRIGHTNESSDOWN} },
 124	{KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} },	/* Display Switch */
 125	{KE_IGNORE, 0x81, {KEY_SLEEP} },
 126	{KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} },	/* Touch Pad Toggle */
 
 127	{KE_KEY, KEY_TOUCHPAD_ON, {KEY_TOUCHPAD_ON} },
 128	{KE_KEY, KEY_TOUCHPAD_OFF, {KEY_TOUCHPAD_OFF} },
 129	{KE_IGNORE, 0x83, {KEY_TOUCHPAD_TOGGLE} },
 130	{KE_KEY, 0x85, {KEY_TOUCHPAD_TOGGLE} },
 
 
 131	{KE_END, 0}
 132};
 133
 134static struct input_dev *acer_wmi_input_dev;
 135static struct input_dev *acer_wmi_accel_dev;
 136
 137struct event_return_value {
 138	u8 function;
 139	u8 key_num;
 140	u16 device_state;
 141	u32 reserved;
 142} __attribute__((packed));
 
 
 143
 144/*
 145 * GUID3 Get Device Status device flags
 146 */
 147#define ACER_WMID3_GDS_WIRELESS		(1<<0)	/* WiFi */
 148#define ACER_WMID3_GDS_THREEG		(1<<6)	/* 3G */
 149#define ACER_WMID3_GDS_WIMAX		(1<<7)	/* WiMAX */
 150#define ACER_WMID3_GDS_BLUETOOTH	(1<<11)	/* BT */
 
 
 151#define ACER_WMID3_GDS_TOUCHPAD		(1<<1)	/* Touchpad */
 152
 153struct lm_input_params {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 154	u8 function_num;        /* Function Number */
 155	u16 commun_devices;     /* Communication type devices default status */
 156	u16 devices;            /* Other type devices default status */
 157	u8 lm_status;           /* Launch Manager Status */
 158	u16 reserved;
 159} __attribute__((packed));
 
 160
 161struct lm_return_value {
 162	u8 error_code;          /* Error Code */
 163	u8 ec_return_value;     /* EC Return Value */
 164	u16 reserved;
 165} __attribute__((packed));
 166
 167struct wmid3_gds_set_input_param {     /* Set Device Status input parameter */
 168	u8 function_num;        /* Function Number */
 169	u8 hotkey_number;       /* Hotkey Number */
 170	u16 devices;            /* Set Device */
 171	u8 volume_value;        /* Volume Value */
 172} __attribute__((packed));
 173
 174struct wmid3_gds_get_input_param {     /* Get Device Status input parameter */
 175	u8 function_num;	/* Function Number */
 176	u8 hotkey_number;	/* Hotkey Number */
 177	u16 devices;		/* Get Device */
 178} __attribute__((packed));
 179
 180struct wmid3_gds_return_value {	/* Get Device Status return value*/
 181	u8 error_code;		/* Error Code */
 182	u8 ec_return_value;	/* EC Return Value */
 183	u16 devices;		/* Current Device Status */
 184	u32 reserved;
 185} __attribute__((packed));
 186
 187struct hotkey_function_type_aa {
 188	u8 type;
 189	u8 length;
 190	u16 handle;
 191	u16 commun_func_bitmap;
 192	u16 application_func_bitmap;
 193	u16 media_func_bitmap;
 194	u16 display_func_bitmap;
 195	u16 others_func_bitmap;
 196	u8 commun_fn_key_number;
 197} __attribute__((packed));
 198
 199/*
 200 * Interface capability flags
 201 */
 202#define ACER_CAP_MAILLED		(1<<0)
 203#define ACER_CAP_WIRELESS		(1<<1)
 204#define ACER_CAP_BLUETOOTH		(1<<2)
 205#define ACER_CAP_BRIGHTNESS		(1<<3)
 206#define ACER_CAP_THREEG			(1<<4)
 207#define ACER_CAP_ACCEL			(1<<5)
 208#define ACER_CAP_ANY			(0xFFFFFFFF)
 
 
 
 
 
 209
 210/*
 211 * Interface type flags
 212 */
 213enum interface_flags {
 214	ACER_AMW0,
 215	ACER_AMW0_V2,
 216	ACER_WMID,
 217	ACER_WMID_v2,
 218};
 219
 220#define ACER_DEFAULT_WIRELESS  0
 221#define ACER_DEFAULT_BLUETOOTH 0
 222#define ACER_DEFAULT_MAILLED   0
 223#define ACER_DEFAULT_THREEG    0
 224
 225static int max_brightness = 0xF;
 226
 227static int mailled = -1;
 228static int brightness = -1;
 229static int threeg = -1;
 230static int force_series;
 
 231static bool ec_raw_mode;
 232static bool has_type_aa;
 233static u16 commun_func_bitmap;
 234static u8 commun_fn_key_number;
 
 
 235
 236module_param(mailled, int, 0444);
 237module_param(brightness, int, 0444);
 238module_param(threeg, int, 0444);
 239module_param(force_series, int, 0444);
 
 240module_param(ec_raw_mode, bool, 0444);
 
 
 241MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
 242MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
 243MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
 244MODULE_PARM_DESC(force_series, "Force a different laptop series");
 
 245MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
 
 
 
 
 246
 247struct acer_data {
 248	int mailled;
 249	int threeg;
 250	int brightness;
 251};
 252
 253struct acer_debug {
 254	struct dentry *root;
 255	struct dentry *devices;
 256	u32 wmid_devices;
 257};
 258
 259static struct rfkill *wireless_rfkill;
 260static struct rfkill *bluetooth_rfkill;
 261static struct rfkill *threeg_rfkill;
 262static bool rfkill_inited;
 263
 264/* Each low-level interface must define at least some of the following */
 265struct wmi_interface {
 266	/* The WMI device type */
 267	u32 type;
 268
 269	/* The capabilities this interface provides */
 270	u32 capability;
 271
 272	/* Private data for the current interface */
 273	struct acer_data data;
 274
 275	/* debugfs entries associated with this interface */
 276	struct acer_debug debug;
 277};
 278
 279/* The static interface pointer, points to the currently detected interface */
 280static struct wmi_interface *interface;
 281
 282/*
 283 * Embedded Controller quirks
 284 * Some laptops require us to directly access the EC to either enable or query
 285 * features that are not available through WMI.
 286 */
 287
 288struct quirk_entry {
 289	u8 wireless;
 290	u8 mailled;
 291	s8 brightness;
 292	u8 bluetooth;
 
 
 
 
 293};
 294
 295static struct quirk_entry *quirks;
 296
 297static void __init set_quirks(void)
 298{
 299	if (!interface)
 300		return;
 301
 302	if (quirks->mailled)
 303		interface->capability |= ACER_CAP_MAILLED;
 304
 305	if (quirks->brightness)
 306		interface->capability |= ACER_CAP_BRIGHTNESS;
 
 
 
 
 
 
 
 
 307}
 308
 309static int __init dmi_matched(const struct dmi_system_id *dmi)
 310{
 311	quirks = dmi->driver_data;
 312	return 1;
 313}
 314
 
 
 
 
 
 
 
 
 
 315static struct quirk_entry quirk_unknown = {
 316};
 317
 318static struct quirk_entry quirk_acer_aspire_1520 = {
 319	.brightness = -1,
 320};
 321
 322static struct quirk_entry quirk_acer_travelmate_2490 = {
 323	.mailled = 1,
 324};
 325
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 326/* This AMW0 laptop has no bluetooth */
 327static struct quirk_entry quirk_medion_md_98300 = {
 328	.wireless = 1,
 329};
 330
 331static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
 332	.wireless = 2,
 333};
 334
 335static struct quirk_entry quirk_lenovo_ideapad_s205 = {
 336	.wireless = 3,
 337};
 338
 339/* The Aspire One has a dummy ACPI-WMI interface - disable it */
 340static const struct dmi_system_id acer_blacklist[] __initconst = {
 341	{
 342		.ident = "Acer Aspire One (SSD)",
 343		.matches = {
 344			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 345			DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
 346		},
 347	},
 348	{
 349		.ident = "Acer Aspire One (HDD)",
 350		.matches = {
 351			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 352			DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
 353		},
 354	},
 355	{}
 356};
 357
 358static const struct dmi_system_id amw0_whitelist[] __initconst = {
 359	{
 360		.ident = "Acer",
 361		.matches = {
 362			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 363		},
 364	},
 365	{
 366		.ident = "Gateway",
 367		.matches = {
 368			DMI_MATCH(DMI_SYS_VENDOR, "Gateway"),
 369		},
 370	},
 371	{
 372		.ident = "Packard Bell",
 373		.matches = {
 374			DMI_MATCH(DMI_SYS_VENDOR, "Packard Bell"),
 375		},
 376	},
 377	{}
 378};
 379
 380/*
 381 * This quirk table is only for Acer/Gateway/Packard Bell family
 382 * that those machines are supported by acer-wmi driver.
 383 */
 384static const struct dmi_system_id acer_quirks[] __initconst = {
 385	{
 386		.callback = dmi_matched,
 387		.ident = "Acer Aspire 1360",
 388		.matches = {
 389			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 390			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
 391		},
 392		.driver_data = &quirk_acer_aspire_1520,
 393	},
 394	{
 395		.callback = dmi_matched,
 396		.ident = "Acer Aspire 1520",
 397		.matches = {
 398			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 399			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
 400		},
 401		.driver_data = &quirk_acer_aspire_1520,
 402	},
 403	{
 404		.callback = dmi_matched,
 405		.ident = "Acer Aspire 3100",
 406		.matches = {
 407			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 408			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
 409		},
 410		.driver_data = &quirk_acer_travelmate_2490,
 411	},
 412	{
 413		.callback = dmi_matched,
 414		.ident = "Acer Aspire 3610",
 415		.matches = {
 416			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 417			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
 418		},
 419		.driver_data = &quirk_acer_travelmate_2490,
 420	},
 421	{
 422		.callback = dmi_matched,
 423		.ident = "Acer Aspire 5100",
 424		.matches = {
 425			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 426			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
 427		},
 428		.driver_data = &quirk_acer_travelmate_2490,
 429	},
 430	{
 431		.callback = dmi_matched,
 432		.ident = "Acer Aspire 5610",
 433		.matches = {
 434			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 435			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
 436		},
 437		.driver_data = &quirk_acer_travelmate_2490,
 438	},
 439	{
 440		.callback = dmi_matched,
 441		.ident = "Acer Aspire 5630",
 442		.matches = {
 443			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 444			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
 445		},
 446		.driver_data = &quirk_acer_travelmate_2490,
 447	},
 448	{
 449		.callback = dmi_matched,
 450		.ident = "Acer Aspire 5650",
 451		.matches = {
 452			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 453			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
 454		},
 455		.driver_data = &quirk_acer_travelmate_2490,
 456	},
 457	{
 458		.callback = dmi_matched,
 459		.ident = "Acer Aspire 5680",
 460		.matches = {
 461			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 462			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
 463		},
 464		.driver_data = &quirk_acer_travelmate_2490,
 465	},
 466	{
 467		.callback = dmi_matched,
 468		.ident = "Acer Aspire 9110",
 469		.matches = {
 470			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 471			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
 472		},
 473		.driver_data = &quirk_acer_travelmate_2490,
 474	},
 475	{
 476		.callback = dmi_matched,
 477		.ident = "Acer TravelMate 2490",
 478		.matches = {
 479			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 480			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
 481		},
 482		.driver_data = &quirk_acer_travelmate_2490,
 483	},
 484	{
 485		.callback = dmi_matched,
 486		.ident = "Acer TravelMate 4200",
 487		.matches = {
 488			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 489			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
 490		},
 491		.driver_data = &quirk_acer_travelmate_2490,
 492	},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 493	{}
 494};
 495
 496/*
 497 * This quirk list is for those non-acer machines that have AMW0_GUID1
 498 * but supported by acer-wmi in past days. Keeping this quirk list here
 499 * is only for backward compatible. Please do not add new machine to
 500 * here anymore. Those non-acer machines should be supported by
 501 * appropriate wmi drivers.
 502 */
 503static const struct dmi_system_id non_acer_quirks[] __initconst = {
 504	{
 505		.callback = dmi_matched,
 506		.ident = "Fujitsu Siemens Amilo Li 1718",
 507		.matches = {
 508			DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
 509			DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
 510		},
 511		.driver_data = &quirk_fujitsu_amilo_li_1718,
 512	},
 513	{
 514		.callback = dmi_matched,
 515		.ident = "Medion MD 98300",
 516		.matches = {
 517			DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
 518			DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
 519		},
 520		.driver_data = &quirk_medion_md_98300,
 521	},
 522	{
 523		.callback = dmi_matched,
 524		.ident = "Lenovo Ideapad S205",
 525		.matches = {
 526			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 527			DMI_MATCH(DMI_PRODUCT_NAME, "10382LG"),
 528		},
 529		.driver_data = &quirk_lenovo_ideapad_s205,
 530	},
 531	{
 532		.callback = dmi_matched,
 533		.ident = "Lenovo Ideapad S205 (Brazos)",
 534		.matches = {
 535			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 536			DMI_MATCH(DMI_PRODUCT_NAME, "Brazos"),
 537		},
 538		.driver_data = &quirk_lenovo_ideapad_s205,
 539	},
 540	{
 541		.callback = dmi_matched,
 542		.ident = "Lenovo 3000 N200",
 543		.matches = {
 544			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 545			DMI_MATCH(DMI_PRODUCT_NAME, "0687A31"),
 546		},
 547		.driver_data = &quirk_fujitsu_amilo_li_1718,
 548	},
 549	{
 550		.callback = dmi_matched,
 551		.ident = "Lenovo Ideapad S205-10382JG",
 552		.matches = {
 553			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 554			DMI_MATCH(DMI_PRODUCT_NAME, "10382JG"),
 555		},
 556		.driver_data = &quirk_lenovo_ideapad_s205,
 557	},
 558	{
 559		.callback = dmi_matched,
 560		.ident = "Lenovo Ideapad S205-1038DPG",
 561		.matches = {
 562			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 563			DMI_MATCH(DMI_PRODUCT_NAME, "1038DPG"),
 564		},
 565		.driver_data = &quirk_lenovo_ideapad_s205,
 566	},
 567	{}
 568};
 569
 570static int __init
 571video_set_backlight_video_vendor(const struct dmi_system_id *d)
 572{
 573	interface->capability &= ~ACER_CAP_BRIGHTNESS;
 574	pr_info("Brightness must be controlled by generic video driver\n");
 575	return 0;
 576}
 
 
 
 
 
 
 
 
 
 577
 578static const struct dmi_system_id video_vendor_dmi_table[] __initconst = {
 579	{
 580		.callback = video_set_backlight_video_vendor,
 581		.ident = "Acer TravelMate 4750",
 582		.matches = {
 583			DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
 584			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"),
 585		},
 586	},
 587	{
 588		.callback = video_set_backlight_video_vendor,
 589		.ident = "Acer Extensa 5235",
 590		.matches = {
 591			DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
 592			DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"),
 593		},
 594	},
 595	{
 596		.callback = video_set_backlight_video_vendor,
 597		.ident = "Acer TravelMate 5760",
 598		.matches = {
 599			DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
 600			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"),
 601		},
 602	},
 603	{
 604		.callback = video_set_backlight_video_vendor,
 605		.ident = "Acer Aspire 5750",
 606		.matches = {
 607			DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
 608			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"),
 609		},
 610	},
 611	{
 612		.callback = video_set_backlight_video_vendor,
 613		.ident = "Acer Aspire 5741",
 614		.matches = {
 615			DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
 616			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5741"),
 617		},
 618	},
 619	{
 620		/*
 621		 * Note no video_set_backlight_video_vendor, we must use the
 622		 * acer interface, as there is no native backlight interface.
 623		 */
 624		.ident = "Acer KAV80",
 625		.matches = {
 626			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 627			DMI_MATCH(DMI_PRODUCT_NAME, "KAV80"),
 628		},
 629	},
 630	{}
 631};
 632
 633/* Find which quirks are needed for a particular vendor/ model pair */
 634static void __init find_quirks(void)
 635{
 636	if (!force_series) {
 
 
 637		dmi_check_system(acer_quirks);
 638		dmi_check_system(non_acer_quirks);
 639	} else if (force_series == 2490) {
 640		quirks = &quirk_acer_travelmate_2490;
 641	}
 642
 643	if (quirks == NULL)
 644		quirks = &quirk_unknown;
 645
 646	set_quirks();
 647}
 648
 649/*
 650 * General interface convenience methods
 651 */
 652
 653static bool has_cap(u32 cap)
 654{
 655	if ((interface->capability & cap) != 0)
 656		return 1;
 657
 658	return 0;
 659}
 660
 661/*
 662 * AMW0 (V1) interface
 663 */
 664struct wmab_args {
 665	u32 eax;
 666	u32 ebx;
 667	u32 ecx;
 668	u32 edx;
 669};
 670
 671struct wmab_ret {
 672	u32 eax;
 673	u32 ebx;
 674	u32 ecx;
 675	u32 edx;
 676	u32 eex;
 677};
 678
 679static acpi_status wmab_execute(struct wmab_args *regbuf,
 680struct acpi_buffer *result)
 681{
 682	struct acpi_buffer input;
 683	acpi_status status;
 684	input.length = sizeof(struct wmab_args);
 685	input.pointer = (u8 *)regbuf;
 686
 687	status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
 688
 689	return status;
 690}
 691
 692static acpi_status AMW0_get_u32(u32 *value, u32 cap)
 693{
 694	int err;
 695	u8 result;
 696
 697	switch (cap) {
 698	case ACER_CAP_MAILLED:
 699		switch (quirks->mailled) {
 700		default:
 701			err = ec_read(0xA, &result);
 702			if (err)
 703				return AE_ERROR;
 704			*value = (result >> 7) & 0x1;
 705			return AE_OK;
 706		}
 707		break;
 708	case ACER_CAP_WIRELESS:
 709		switch (quirks->wireless) {
 710		case 1:
 711			err = ec_read(0x7B, &result);
 712			if (err)
 713				return AE_ERROR;
 714			*value = result & 0x1;
 715			return AE_OK;
 716		case 2:
 717			err = ec_read(0x71, &result);
 718			if (err)
 719				return AE_ERROR;
 720			*value = result & 0x1;
 721			return AE_OK;
 722		case 3:
 723			err = ec_read(0x78, &result);
 724			if (err)
 725				return AE_ERROR;
 726			*value = result & 0x1;
 727			return AE_OK;
 728		default:
 729			err = ec_read(0xA, &result);
 730			if (err)
 731				return AE_ERROR;
 732			*value = (result >> 2) & 0x1;
 733			return AE_OK;
 734		}
 735		break;
 736	case ACER_CAP_BLUETOOTH:
 737		switch (quirks->bluetooth) {
 738		default:
 739			err = ec_read(0xA, &result);
 740			if (err)
 741				return AE_ERROR;
 742			*value = (result >> 4) & 0x1;
 743			return AE_OK;
 744		}
 745		break;
 746	case ACER_CAP_BRIGHTNESS:
 747		switch (quirks->brightness) {
 748		default:
 749			err = ec_read(0x83, &result);
 750			if (err)
 751				return AE_ERROR;
 752			*value = result;
 753			return AE_OK;
 754		}
 755		break;
 756	default:
 757		return AE_ERROR;
 758	}
 759	return AE_OK;
 760}
 761
 762static acpi_status AMW0_set_u32(u32 value, u32 cap)
 763{
 764	struct wmab_args args;
 765
 766	args.eax = ACER_AMW0_WRITE;
 767	args.ebx = value ? (1<<8) : 0;
 768	args.ecx = args.edx = 0;
 769
 770	switch (cap) {
 771	case ACER_CAP_MAILLED:
 772		if (value > 1)
 773			return AE_BAD_PARAMETER;
 774		args.ebx |= ACER_AMW0_MAILLED_MASK;
 775		break;
 776	case ACER_CAP_WIRELESS:
 777		if (value > 1)
 778			return AE_BAD_PARAMETER;
 779		args.ebx |= ACER_AMW0_WIRELESS_MASK;
 780		break;
 781	case ACER_CAP_BLUETOOTH:
 782		if (value > 1)
 783			return AE_BAD_PARAMETER;
 784		args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
 785		break;
 786	case ACER_CAP_BRIGHTNESS:
 787		if (value > max_brightness)
 788			return AE_BAD_PARAMETER;
 789		switch (quirks->brightness) {
 790		default:
 791			return ec_write(0x83, value);
 792			break;
 793		}
 794	default:
 795		return AE_ERROR;
 796	}
 797
 798	/* Actually do the set */
 799	return wmab_execute(&args, NULL);
 800}
 801
 802static acpi_status __init AMW0_find_mailled(void)
 803{
 804	struct wmab_args args;
 805	struct wmab_ret ret;
 806	acpi_status status = AE_OK;
 807	struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
 808	union acpi_object *obj;
 809
 810	args.eax = 0x86;
 811	args.ebx = args.ecx = args.edx = 0;
 812
 813	status = wmab_execute(&args, &out);
 814	if (ACPI_FAILURE(status))
 815		return status;
 816
 817	obj = (union acpi_object *) out.pointer;
 818	if (obj && obj->type == ACPI_TYPE_BUFFER &&
 819	obj->buffer.length == sizeof(struct wmab_ret)) {
 820		ret = *((struct wmab_ret *) obj->buffer.pointer);
 821	} else {
 822		kfree(out.pointer);
 823		return AE_ERROR;
 824	}
 825
 826	if (ret.eex & 0x1)
 827		interface->capability |= ACER_CAP_MAILLED;
 828
 829	kfree(out.pointer);
 830
 831	return AE_OK;
 832}
 833
 834static const struct acpi_device_id norfkill_ids[] __initconst = {
 835	{ "VPC2004", 0},
 836	{ "IBM0068", 0},
 837	{ "LEN0068", 0},
 838	{ "SNY5001", 0},	/* sony-laptop in charge */
 839	{ "HPQ6601", 0},
 840	{ "", 0},
 841};
 842
 843static int __init AMW0_set_cap_acpi_check_device(void)
 844{
 845	const struct acpi_device_id *id;
 846
 847	for (id = norfkill_ids; id->id[0]; id++)
 848		if (acpi_dev_found(id->id))
 849			return true;
 850
 851	return false;
 852}
 853
 854static acpi_status __init AMW0_set_capabilities(void)
 855{
 856	struct wmab_args args;
 857	struct wmab_ret ret;
 858	acpi_status status;
 859	struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
 860	union acpi_object *obj;
 861
 862	/*
 863	 * On laptops with this strange GUID (non Acer), normal probing doesn't
 864	 * work.
 865	 */
 866	if (wmi_has_guid(AMW0_GUID2)) {
 867		if ((quirks != &quirk_unknown) ||
 868		    !AMW0_set_cap_acpi_check_device())
 869			interface->capability |= ACER_CAP_WIRELESS;
 870		return AE_OK;
 871	}
 872
 873	args.eax = ACER_AMW0_WRITE;
 874	args.ecx = args.edx = 0;
 875
 876	args.ebx = 0xa2 << 8;
 877	args.ebx |= ACER_AMW0_WIRELESS_MASK;
 878
 879	status = wmab_execute(&args, &out);
 880	if (ACPI_FAILURE(status))
 881		return status;
 882
 883	obj = out.pointer;
 884	if (obj && obj->type == ACPI_TYPE_BUFFER &&
 885	obj->buffer.length == sizeof(struct wmab_ret)) {
 886		ret = *((struct wmab_ret *) obj->buffer.pointer);
 887	} else {
 888		status = AE_ERROR;
 889		goto out;
 890	}
 891
 892	if (ret.eax & 0x1)
 893		interface->capability |= ACER_CAP_WIRELESS;
 894
 895	args.ebx = 2 << 8;
 896	args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
 897
 898	/*
 899	 * It's ok to use existing buffer for next wmab_execute call.
 900	 * But we need to kfree(out.pointer) if next wmab_execute fail.
 901	 */
 902	status = wmab_execute(&args, &out);
 903	if (ACPI_FAILURE(status))
 904		goto out;
 905
 906	obj = (union acpi_object *) out.pointer;
 907	if (obj && obj->type == ACPI_TYPE_BUFFER
 908	&& obj->buffer.length == sizeof(struct wmab_ret)) {
 909		ret = *((struct wmab_ret *) obj->buffer.pointer);
 910	} else {
 911		status = AE_ERROR;
 912		goto out;
 913	}
 914
 915	if (ret.eax & 0x1)
 916		interface->capability |= ACER_CAP_BLUETOOTH;
 917
 918	/*
 919	 * This appears to be safe to enable, since all Wistron based laptops
 920	 * appear to use the same EC register for brightness, even if they
 921	 * differ for wireless, etc
 922	 */
 923	if (quirks->brightness >= 0)
 924		interface->capability |= ACER_CAP_BRIGHTNESS;
 925
 926	status = AE_OK;
 927out:
 928	kfree(out.pointer);
 929	return status;
 930}
 931
 932static struct wmi_interface AMW0_interface = {
 933	.type = ACER_AMW0,
 934};
 935
 936static struct wmi_interface AMW0_V2_interface = {
 937	.type = ACER_AMW0_V2,
 938};
 939
 940/*
 941 * New interface (The WMID interface)
 942 */
 943static acpi_status
 944WMI_execute_u32(u32 method_id, u32 in, u32 *out)
 945{
 946	struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
 947	struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
 948	union acpi_object *obj;
 949	u32 tmp = 0;
 950	acpi_status status;
 951
 952	status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
 953
 954	if (ACPI_FAILURE(status))
 955		return status;
 956
 957	obj = (union acpi_object *) result.pointer;
 958	if (obj) {
 959		if (obj->type == ACPI_TYPE_BUFFER &&
 960			(obj->buffer.length == sizeof(u32) ||
 961			obj->buffer.length == sizeof(u64))) {
 962			tmp = *((u32 *) obj->buffer.pointer);
 963		} else if (obj->type == ACPI_TYPE_INTEGER) {
 964			tmp = (u32) obj->integer.value;
 965		}
 966	}
 967
 968	if (out)
 969		*out = tmp;
 970
 971	kfree(result.pointer);
 972
 973	return status;
 974}
 975
 976static acpi_status WMID_get_u32(u32 *value, u32 cap)
 977{
 978	acpi_status status;
 979	u8 tmp;
 980	u32 result, method_id = 0;
 981
 982	switch (cap) {
 983	case ACER_CAP_WIRELESS:
 984		method_id = ACER_WMID_GET_WIRELESS_METHODID;
 985		break;
 986	case ACER_CAP_BLUETOOTH:
 987		method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
 988		break;
 989	case ACER_CAP_BRIGHTNESS:
 990		method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
 991		break;
 992	case ACER_CAP_THREEG:
 993		method_id = ACER_WMID_GET_THREEG_METHODID;
 994		break;
 995	case ACER_CAP_MAILLED:
 996		if (quirks->mailled == 1) {
 997			ec_read(0x9f, &tmp);
 998			*value = tmp & 0x1;
 999			return 0;
1000		}
 
1001	default:
1002		return AE_ERROR;
1003	}
1004	status = WMI_execute_u32(method_id, 0, &result);
1005
1006	if (ACPI_SUCCESS(status))
1007		*value = (u8)result;
1008
1009	return status;
1010}
1011
1012static acpi_status WMID_set_u32(u32 value, u32 cap)
1013{
1014	u32 method_id = 0;
1015	char param;
1016
1017	switch (cap) {
1018	case ACER_CAP_BRIGHTNESS:
1019		if (value > max_brightness)
1020			return AE_BAD_PARAMETER;
1021		method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
1022		break;
1023	case ACER_CAP_WIRELESS:
1024		if (value > 1)
1025			return AE_BAD_PARAMETER;
1026		method_id = ACER_WMID_SET_WIRELESS_METHODID;
1027		break;
1028	case ACER_CAP_BLUETOOTH:
1029		if (value > 1)
1030			return AE_BAD_PARAMETER;
1031		method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
1032		break;
1033	case ACER_CAP_THREEG:
1034		if (value > 1)
1035			return AE_BAD_PARAMETER;
1036		method_id = ACER_WMID_SET_THREEG_METHODID;
1037		break;
1038	case ACER_CAP_MAILLED:
1039		if (value > 1)
1040			return AE_BAD_PARAMETER;
1041		if (quirks->mailled == 1) {
1042			param = value ? 0x92 : 0x93;
1043			i8042_lock_chip();
1044			i8042_command(&param, 0x1059);
1045			i8042_unlock_chip();
1046			return 0;
1047		}
1048		break;
1049	default:
1050		return AE_ERROR;
1051	}
1052	return WMI_execute_u32(method_id, (u32)value, NULL);
1053}
1054
1055static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1056{
1057	struct wmid3_gds_return_value return_value;
1058	acpi_status status;
1059	union acpi_object *obj;
1060	struct wmid3_gds_get_input_param params = {
1061		.function_num = 0x1,
1062		.hotkey_number = commun_fn_key_number,
1063		.devices = device,
1064	};
1065	struct acpi_buffer input = {
1066		sizeof(struct wmid3_gds_get_input_param),
1067		&params
1068	};
1069	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1070
1071	status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1072	if (ACPI_FAILURE(status))
1073		return status;
1074
1075	obj = output.pointer;
1076
1077	if (!obj)
1078		return AE_ERROR;
1079	else if (obj->type != ACPI_TYPE_BUFFER) {
1080		kfree(obj);
1081		return AE_ERROR;
1082	}
1083	if (obj->buffer.length != 8) {
1084		pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1085		kfree(obj);
1086		return AE_ERROR;
1087	}
1088
1089	return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1090	kfree(obj);
1091
1092	if (return_value.error_code || return_value.ec_return_value)
1093		pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
1094			device,
1095			return_value.error_code,
1096			return_value.ec_return_value);
1097	else
1098		*value = !!(return_value.devices & device);
1099
1100	return status;
1101}
1102
1103static acpi_status wmid_v2_get_u32(u32 *value, u32 cap)
1104{
1105	u16 device;
1106
1107	switch (cap) {
1108	case ACER_CAP_WIRELESS:
1109		device = ACER_WMID3_GDS_WIRELESS;
1110		break;
1111	case ACER_CAP_BLUETOOTH:
1112		device = ACER_WMID3_GDS_BLUETOOTH;
1113		break;
1114	case ACER_CAP_THREEG:
1115		device = ACER_WMID3_GDS_THREEG;
1116		break;
1117	default:
1118		return AE_ERROR;
1119	}
1120	return wmid3_get_device_status(value, device);
1121}
1122
1123static acpi_status wmid3_set_device_status(u32 value, u16 device)
1124{
1125	struct wmid3_gds_return_value return_value;
1126	acpi_status status;
1127	union acpi_object *obj;
1128	u16 devices;
1129	struct wmid3_gds_get_input_param get_params = {
1130		.function_num = 0x1,
1131		.hotkey_number = commun_fn_key_number,
1132		.devices = commun_func_bitmap,
1133	};
1134	struct acpi_buffer get_input = {
1135		sizeof(struct wmid3_gds_get_input_param),
1136		&get_params
1137	};
1138	struct wmid3_gds_set_input_param set_params = {
1139		.function_num = 0x2,
1140		.hotkey_number = commun_fn_key_number,
1141		.devices = commun_func_bitmap,
1142	};
1143	struct acpi_buffer set_input = {
1144		sizeof(struct wmid3_gds_set_input_param),
1145		&set_params
1146	};
1147	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1148	struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
1149
1150	status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &get_input, &output);
1151	if (ACPI_FAILURE(status))
1152		return status;
1153
1154	obj = output.pointer;
1155
1156	if (!obj)
1157		return AE_ERROR;
1158	else if (obj->type != ACPI_TYPE_BUFFER) {
1159		kfree(obj);
1160		return AE_ERROR;
1161	}
1162	if (obj->buffer.length != 8) {
1163		pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1164		kfree(obj);
1165		return AE_ERROR;
1166	}
1167
1168	return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1169	kfree(obj);
1170
1171	if (return_value.error_code || return_value.ec_return_value) {
1172		pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1173			return_value.error_code,
1174			return_value.ec_return_value);
1175		return status;
1176	}
1177
1178	devices = return_value.devices;
1179	set_params.devices = (value) ? (devices | device) : (devices & ~device);
1180
1181	status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &set_input, &output2);
1182	if (ACPI_FAILURE(status))
1183		return status;
1184
1185	obj = output2.pointer;
1186
1187	if (!obj)
1188		return AE_ERROR;
1189	else if (obj->type != ACPI_TYPE_BUFFER) {
1190		kfree(obj);
1191		return AE_ERROR;
1192	}
1193	if (obj->buffer.length != 4) {
1194		pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1195		kfree(obj);
1196		return AE_ERROR;
1197	}
1198
1199	return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1200	kfree(obj);
1201
1202	if (return_value.error_code || return_value.ec_return_value)
1203		pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1204			return_value.error_code,
1205			return_value.ec_return_value);
1206
1207	return status;
1208}
1209
1210static acpi_status wmid_v2_set_u32(u32 value, u32 cap)
1211{
1212	u16 device;
1213
1214	switch (cap) {
1215	case ACER_CAP_WIRELESS:
1216		device = ACER_WMID3_GDS_WIRELESS;
1217		break;
1218	case ACER_CAP_BLUETOOTH:
1219		device = ACER_WMID3_GDS_BLUETOOTH;
1220		break;
1221	case ACER_CAP_THREEG:
1222		device = ACER_WMID3_GDS_THREEG;
1223		break;
1224	default:
1225		return AE_ERROR;
1226	}
1227	return wmid3_set_device_status(value, device);
1228}
1229
1230static void __init type_aa_dmi_decode(const struct dmi_header *header, void *d)
1231{
1232	struct hotkey_function_type_aa *type_aa;
1233
1234	/* We are looking for OEM-specific Type AAh */
1235	if (header->type != 0xAA)
1236		return;
1237
1238	has_type_aa = true;
1239	type_aa = (struct hotkey_function_type_aa *) header;
1240
1241	pr_info("Function bitmap for Communication Button: 0x%x\n",
1242		type_aa->commun_func_bitmap);
1243	commun_func_bitmap = type_aa->commun_func_bitmap;
1244
1245	if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
1246		interface->capability |= ACER_CAP_WIRELESS;
1247	if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
1248		interface->capability |= ACER_CAP_THREEG;
1249	if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
1250		interface->capability |= ACER_CAP_BLUETOOTH;
 
 
1251
1252	commun_fn_key_number = type_aa->commun_fn_key_number;
1253}
1254
1255static acpi_status __init WMID_set_capabilities(void)
1256{
1257	struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1258	union acpi_object *obj;
1259	acpi_status status;
1260	u32 devices;
1261
1262	status = wmi_query_block(WMID_GUID2, 1, &out);
1263	if (ACPI_FAILURE(status))
1264		return status;
1265
1266	obj = (union acpi_object *) out.pointer;
1267	if (obj) {
1268		if (obj->type == ACPI_TYPE_BUFFER &&
1269			(obj->buffer.length == sizeof(u32) ||
1270			obj->buffer.length == sizeof(u64))) {
1271			devices = *((u32 *) obj->buffer.pointer);
1272		} else if (obj->type == ACPI_TYPE_INTEGER) {
1273			devices = (u32) obj->integer.value;
1274		} else {
1275			kfree(out.pointer);
1276			return AE_ERROR;
1277		}
1278	} else {
1279		kfree(out.pointer);
1280		return AE_ERROR;
1281	}
1282
1283	pr_info("Function bitmap for Communication Device: 0x%x\n", devices);
1284	if (devices & 0x07)
1285		interface->capability |= ACER_CAP_WIRELESS;
1286	if (devices & 0x40)
1287		interface->capability |= ACER_CAP_THREEG;
1288	if (devices & 0x10)
1289		interface->capability |= ACER_CAP_BLUETOOTH;
1290
1291	if (!(devices & 0x20))
1292		max_brightness = 0x9;
1293
1294	kfree(out.pointer);
1295	return status;
1296}
1297
1298static struct wmi_interface wmid_interface = {
1299	.type = ACER_WMID,
1300};
1301
1302static struct wmi_interface wmid_v2_interface = {
1303	.type = ACER_WMID_v2,
1304};
1305
1306/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1307 * Generic Device (interface-independent)
1308 */
1309
1310static acpi_status get_u32(u32 *value, u32 cap)
1311{
1312	acpi_status status = AE_ERROR;
1313
1314	switch (interface->type) {
1315	case ACER_AMW0:
1316		status = AMW0_get_u32(value, cap);
1317		break;
1318	case ACER_AMW0_V2:
1319		if (cap == ACER_CAP_MAILLED) {
1320			status = AMW0_get_u32(value, cap);
1321			break;
1322		}
 
1323	case ACER_WMID:
1324		status = WMID_get_u32(value, cap);
1325		break;
1326	case ACER_WMID_v2:
1327		if (cap & (ACER_CAP_WIRELESS |
1328			   ACER_CAP_BLUETOOTH |
1329			   ACER_CAP_THREEG))
1330			status = wmid_v2_get_u32(value, cap);
1331		else if (wmi_has_guid(WMID_GUID2))
1332			status = WMID_get_u32(value, cap);
1333		break;
1334	}
1335
1336	return status;
1337}
1338
1339static acpi_status set_u32(u32 value, u32 cap)
1340{
1341	acpi_status status;
1342
1343	if (interface->capability & cap) {
1344		switch (interface->type) {
1345		case ACER_AMW0:
1346			return AMW0_set_u32(value, cap);
1347		case ACER_AMW0_V2:
1348			if (cap == ACER_CAP_MAILLED)
1349				return AMW0_set_u32(value, cap);
1350
1351			/*
1352			 * On some models, some WMID methods don't toggle
1353			 * properly. For those cases, we want to run the AMW0
1354			 * method afterwards to be certain we've really toggled
1355			 * the device state.
1356			 */
1357			if (cap == ACER_CAP_WIRELESS ||
1358				cap == ACER_CAP_BLUETOOTH) {
1359				status = WMID_set_u32(value, cap);
1360				if (ACPI_FAILURE(status))
1361					return status;
1362
1363				return AMW0_set_u32(value, cap);
1364			}
 
1365		case ACER_WMID:
1366			return WMID_set_u32(value, cap);
1367		case ACER_WMID_v2:
1368			if (cap & (ACER_CAP_WIRELESS |
1369				   ACER_CAP_BLUETOOTH |
1370				   ACER_CAP_THREEG))
1371				return wmid_v2_set_u32(value, cap);
1372			else if (wmi_has_guid(WMID_GUID2))
1373				return WMID_set_u32(value, cap);
 
1374		default:
1375			return AE_BAD_PARAMETER;
1376		}
1377	}
1378	return AE_BAD_PARAMETER;
1379}
1380
1381static void __init acer_commandline_init(void)
1382{
1383	/*
1384	 * These will all fail silently if the value given is invalid, or the
1385	 * capability isn't available on the given interface
1386	 */
1387	if (mailled >= 0)
1388		set_u32(mailled, ACER_CAP_MAILLED);
1389	if (!has_type_aa && threeg >= 0)
1390		set_u32(threeg, ACER_CAP_THREEG);
1391	if (brightness >= 0)
1392		set_u32(brightness, ACER_CAP_BRIGHTNESS);
1393}
1394
1395/*
1396 * LED device (Mail LED only, no other LEDs known yet)
1397 */
1398static void mail_led_set(struct led_classdev *led_cdev,
1399enum led_brightness value)
1400{
1401	set_u32(value, ACER_CAP_MAILLED);
1402}
1403
1404static struct led_classdev mail_led = {
1405	.name = "acer-wmi::mail",
1406	.brightness_set = mail_led_set,
1407};
1408
1409static int acer_led_init(struct device *dev)
1410{
1411	return led_classdev_register(dev, &mail_led);
1412}
1413
1414static void acer_led_exit(void)
1415{
1416	set_u32(LED_OFF, ACER_CAP_MAILLED);
1417	led_classdev_unregister(&mail_led);
1418}
1419
1420/*
1421 * Backlight device
1422 */
1423static struct backlight_device *acer_backlight_device;
1424
1425static int read_brightness(struct backlight_device *bd)
1426{
1427	u32 value;
1428	get_u32(&value, ACER_CAP_BRIGHTNESS);
1429	return value;
1430}
1431
1432static int update_bl_status(struct backlight_device *bd)
1433{
1434	int intensity = bd->props.brightness;
1435
1436	if (bd->props.power != FB_BLANK_UNBLANK)
1437		intensity = 0;
1438	if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1439		intensity = 0;
1440
1441	set_u32(intensity, ACER_CAP_BRIGHTNESS);
1442
1443	return 0;
1444}
1445
1446static const struct backlight_ops acer_bl_ops = {
1447	.get_brightness = read_brightness,
1448	.update_status = update_bl_status,
1449};
1450
1451static int acer_backlight_init(struct device *dev)
1452{
1453	struct backlight_properties props;
1454	struct backlight_device *bd;
1455
1456	memset(&props, 0, sizeof(struct backlight_properties));
1457	props.type = BACKLIGHT_PLATFORM;
1458	props.max_brightness = max_brightness;
1459	bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1460				       &props);
1461	if (IS_ERR(bd)) {
1462		pr_err("Could not register Acer backlight device\n");
1463		acer_backlight_device = NULL;
1464		return PTR_ERR(bd);
1465	}
1466
1467	acer_backlight_device = bd;
1468
1469	bd->props.power = FB_BLANK_UNBLANK;
1470	bd->props.brightness = read_brightness(bd);
1471	backlight_update_status(bd);
1472	return 0;
1473}
1474
1475static void acer_backlight_exit(void)
1476{
1477	backlight_device_unregister(acer_backlight_device);
1478}
1479
1480/*
1481 * Accelerometer device
1482 */
1483static acpi_handle gsensor_handle;
1484
1485static int acer_gsensor_init(void)
1486{
1487	acpi_status status;
1488	struct acpi_buffer output;
1489	union acpi_object out_obj;
1490
1491	output.length = sizeof(out_obj);
1492	output.pointer = &out_obj;
1493	status = acpi_evaluate_object(gsensor_handle, "_INI", NULL, &output);
1494	if (ACPI_FAILURE(status))
1495		return -1;
1496
1497	return 0;
1498}
1499
1500static int acer_gsensor_open(struct input_dev *input)
1501{
1502	return acer_gsensor_init();
1503}
1504
1505static int acer_gsensor_event(void)
1506{
1507	acpi_status status;
1508	struct acpi_buffer output;
1509	union acpi_object out_obj[5];
1510
1511	if (!has_cap(ACER_CAP_ACCEL))
1512		return -1;
1513
1514	output.length = sizeof(out_obj);
1515	output.pointer = out_obj;
1516
1517	status = acpi_evaluate_object(gsensor_handle, "RDVL", NULL, &output);
1518	if (ACPI_FAILURE(status))
1519		return -1;
1520
1521	if (out_obj->package.count != 4)
1522		return -1;
1523
1524	input_report_abs(acer_wmi_accel_dev, ABS_X,
1525		(s16)out_obj->package.elements[0].integer.value);
1526	input_report_abs(acer_wmi_accel_dev, ABS_Y,
1527		(s16)out_obj->package.elements[1].integer.value);
1528	input_report_abs(acer_wmi_accel_dev, ABS_Z,
1529		(s16)out_obj->package.elements[2].integer.value);
1530	input_sync(acer_wmi_accel_dev);
1531	return 0;
1532}
1533
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1534/*
1535 * Rfkill devices
1536 */
1537static void acer_rfkill_update(struct work_struct *ignored);
1538static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1539static void acer_rfkill_update(struct work_struct *ignored)
1540{
1541	u32 state;
1542	acpi_status status;
1543
1544	if (has_cap(ACER_CAP_WIRELESS)) {
1545		status = get_u32(&state, ACER_CAP_WIRELESS);
1546		if (ACPI_SUCCESS(status)) {
1547			if (quirks->wireless == 3)
1548				rfkill_set_hw_state(wireless_rfkill, !state);
1549			else
1550				rfkill_set_sw_state(wireless_rfkill, !state);
1551		}
1552	}
1553
1554	if (has_cap(ACER_CAP_BLUETOOTH)) {
1555		status = get_u32(&state, ACER_CAP_BLUETOOTH);
1556		if (ACPI_SUCCESS(status))
1557			rfkill_set_sw_state(bluetooth_rfkill, !state);
1558	}
1559
1560	if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
1561		status = get_u32(&state, ACER_WMID3_GDS_THREEG);
1562		if (ACPI_SUCCESS(status))
1563			rfkill_set_sw_state(threeg_rfkill, !state);
1564	}
1565
1566	schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
1567}
1568
1569static int acer_rfkill_set(void *data, bool blocked)
1570{
1571	acpi_status status;
1572	u32 cap = (unsigned long)data;
1573
1574	if (rfkill_inited) {
1575		status = set_u32(!blocked, cap);
1576		if (ACPI_FAILURE(status))
1577			return -ENODEV;
1578	}
1579
1580	return 0;
1581}
1582
1583static const struct rfkill_ops acer_rfkill_ops = {
1584	.set_block = acer_rfkill_set,
1585};
1586
1587static struct rfkill *acer_rfkill_register(struct device *dev,
1588					   enum rfkill_type type,
1589					   char *name, u32 cap)
1590{
1591	int err;
1592	struct rfkill *rfkill_dev;
1593	u32 state;
1594	acpi_status status;
1595
1596	rfkill_dev = rfkill_alloc(name, dev, type,
1597				  &acer_rfkill_ops,
1598				  (void *)(unsigned long)cap);
1599	if (!rfkill_dev)
1600		return ERR_PTR(-ENOMEM);
1601
1602	status = get_u32(&state, cap);
1603
1604	err = rfkill_register(rfkill_dev);
1605	if (err) {
1606		rfkill_destroy(rfkill_dev);
1607		return ERR_PTR(err);
1608	}
1609
1610	if (ACPI_SUCCESS(status))
1611		rfkill_set_sw_state(rfkill_dev, !state);
1612
1613	return rfkill_dev;
1614}
1615
1616static int acer_rfkill_init(struct device *dev)
1617{
1618	int err;
1619
1620	if (has_cap(ACER_CAP_WIRELESS)) {
1621		wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1622			"acer-wireless", ACER_CAP_WIRELESS);
1623		if (IS_ERR(wireless_rfkill)) {
1624			err = PTR_ERR(wireless_rfkill);
1625			goto error_wireless;
1626		}
1627	}
1628
1629	if (has_cap(ACER_CAP_BLUETOOTH)) {
1630		bluetooth_rfkill = acer_rfkill_register(dev,
1631			RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1632			ACER_CAP_BLUETOOTH);
1633		if (IS_ERR(bluetooth_rfkill)) {
1634			err = PTR_ERR(bluetooth_rfkill);
1635			goto error_bluetooth;
1636		}
1637	}
1638
1639	if (has_cap(ACER_CAP_THREEG)) {
1640		threeg_rfkill = acer_rfkill_register(dev,
1641			RFKILL_TYPE_WWAN, "acer-threeg",
1642			ACER_CAP_THREEG);
1643		if (IS_ERR(threeg_rfkill)) {
1644			err = PTR_ERR(threeg_rfkill);
1645			goto error_threeg;
1646		}
1647	}
1648
1649	rfkill_inited = true;
1650
1651	if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1652	    has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
1653		schedule_delayed_work(&acer_rfkill_work,
1654			round_jiffies_relative(HZ));
1655
1656	return 0;
1657
1658error_threeg:
1659	if (has_cap(ACER_CAP_BLUETOOTH)) {
1660		rfkill_unregister(bluetooth_rfkill);
1661		rfkill_destroy(bluetooth_rfkill);
1662	}
1663error_bluetooth:
1664	if (has_cap(ACER_CAP_WIRELESS)) {
1665		rfkill_unregister(wireless_rfkill);
1666		rfkill_destroy(wireless_rfkill);
1667	}
1668error_wireless:
1669	return err;
1670}
1671
1672static void acer_rfkill_exit(void)
1673{
1674	if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1675	    has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
1676		cancel_delayed_work_sync(&acer_rfkill_work);
1677
1678	if (has_cap(ACER_CAP_WIRELESS)) {
1679		rfkill_unregister(wireless_rfkill);
1680		rfkill_destroy(wireless_rfkill);
1681	}
1682
1683	if (has_cap(ACER_CAP_BLUETOOTH)) {
1684		rfkill_unregister(bluetooth_rfkill);
1685		rfkill_destroy(bluetooth_rfkill);
1686	}
1687
1688	if (has_cap(ACER_CAP_THREEG)) {
1689		rfkill_unregister(threeg_rfkill);
1690		rfkill_destroy(threeg_rfkill);
1691	}
1692	return;
1693}
1694
1695static void acer_wmi_notify(u32 value, void *context)
1696{
1697	struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1698	union acpi_object *obj;
1699	struct event_return_value return_value;
1700	acpi_status status;
1701	u16 device_state;
1702	const struct key_entry *key;
1703	u32 scancode;
1704
1705	status = wmi_get_event_data(value, &response);
1706	if (status != AE_OK) {
1707		pr_warn("bad event status 0x%x\n", status);
1708		return;
1709	}
1710
1711	obj = (union acpi_object *)response.pointer;
1712
1713	if (!obj)
1714		return;
1715	if (obj->type != ACPI_TYPE_BUFFER) {
1716		pr_warn("Unknown response received %d\n", obj->type);
1717		kfree(obj);
1718		return;
1719	}
1720	if (obj->buffer.length != 8) {
1721		pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1722		kfree(obj);
1723		return;
1724	}
1725
1726	return_value = *((struct event_return_value *)obj->buffer.pointer);
1727	kfree(obj);
1728
1729	switch (return_value.function) {
1730	case WMID_HOTKEY_EVENT:
1731		device_state = return_value.device_state;
1732		pr_debug("device state: 0x%x\n", device_state);
1733
1734		key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
1735							return_value.key_num);
1736		if (!key) {
1737			pr_warn("Unknown key number - 0x%x\n",
1738				return_value.key_num);
1739		} else {
1740			scancode = return_value.key_num;
1741			switch (key->keycode) {
1742			case KEY_WLAN:
1743			case KEY_BLUETOOTH:
1744				if (has_cap(ACER_CAP_WIRELESS))
1745					rfkill_set_sw_state(wireless_rfkill,
1746						!(device_state & ACER_WMID3_GDS_WIRELESS));
1747				if (has_cap(ACER_CAP_THREEG))
1748					rfkill_set_sw_state(threeg_rfkill,
1749						!(device_state & ACER_WMID3_GDS_THREEG));
1750				if (has_cap(ACER_CAP_BLUETOOTH))
1751					rfkill_set_sw_state(bluetooth_rfkill,
1752						!(device_state & ACER_WMID3_GDS_BLUETOOTH));
1753				break;
1754			case KEY_TOUCHPAD_TOGGLE:
1755				scancode = (device_state & ACER_WMID3_GDS_TOUCHPAD) ?
1756						KEY_TOUCHPAD_ON : KEY_TOUCHPAD_OFF;
1757			}
1758			sparse_keymap_report_event(acer_wmi_input_dev, scancode, 1, true);
1759		}
1760		break;
1761	case WMID_ACCEL_EVENT:
1762		acer_gsensor_event();
 
 
 
 
 
 
 
 
 
 
1763		break;
1764	default:
1765		pr_warn("Unknown function number - %d - %d\n",
1766			return_value.function, return_value.key_num);
1767		break;
1768	}
1769}
1770
1771static acpi_status __init
1772wmid3_set_lm_mode(struct lm_input_params *params,
1773		  struct lm_return_value *return_value)
1774{
1775	acpi_status status;
1776	union acpi_object *obj;
1777
1778	struct acpi_buffer input = { sizeof(struct lm_input_params), params };
1779	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1780
1781	status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1782	if (ACPI_FAILURE(status))
1783		return status;
1784
1785	obj = output.pointer;
1786
1787	if (!obj)
1788		return AE_ERROR;
1789	else if (obj->type != ACPI_TYPE_BUFFER) {
1790		kfree(obj);
1791		return AE_ERROR;
1792	}
1793	if (obj->buffer.length != 4) {
1794		pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1795		kfree(obj);
1796		return AE_ERROR;
1797	}
1798
1799	*return_value = *((struct lm_return_value *)obj->buffer.pointer);
1800	kfree(obj);
1801
1802	return status;
1803}
1804
1805static int __init acer_wmi_enable_ec_raw(void)
1806{
1807	struct lm_return_value return_value;
1808	acpi_status status;
1809	struct lm_input_params params = {
1810		.function_num = 0x1,
1811		.commun_devices = 0xFFFF,
1812		.devices = 0xFFFF,
1813		.lm_status = 0x00,            /* Launch Manager Deactive */
 
1814	};
1815
1816	status = wmid3_set_lm_mode(&params, &return_value);
1817
1818	if (return_value.error_code || return_value.ec_return_value)
1819		pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1820			return_value.error_code,
1821			return_value.ec_return_value);
1822	else
1823		pr_info("Enabled EC raw mode\n");
1824
1825	return status;
1826}
1827
1828static int __init acer_wmi_enable_lm(void)
1829{
1830	struct lm_return_value return_value;
1831	acpi_status status;
1832	struct lm_input_params params = {
1833		.function_num = 0x1,
1834		.commun_devices = 0xFFFF,
1835		.devices = 0xFFFF,
1836		.lm_status = 0x01,            /* Launch Manager Active */
 
1837	};
1838
1839	status = wmid3_set_lm_mode(&params, &return_value);
1840
1841	if (return_value.error_code || return_value.ec_return_value)
1842		pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1843			return_value.error_code,
1844			return_value.ec_return_value);
1845
1846	return status;
1847}
1848
1849static acpi_status __init acer_wmi_get_handle_cb(acpi_handle ah, u32 level,
1850						void *ctx, void **retval)
1851{
1852	*(acpi_handle *)retval = ah;
1853	return AE_OK;
1854}
1855
1856static int __init acer_wmi_get_handle(const char *name, const char *prop,
1857					acpi_handle *ah)
1858{
 
1859	acpi_status status;
1860	acpi_handle handle;
 
 
 
 
 
 
1861
1862	BUG_ON(!name || !ah);
1863
1864	handle = NULL;
1865	status = acpi_get_devices(prop, acer_wmi_get_handle_cb,
1866					(void *)name, &handle);
 
1867
1868	if (ACPI_SUCCESS(status)) {
1869		*ah = handle;
1870		return 0;
1871	} else {
1872		return -ENODEV;
1873	}
1874}
1875
1876static int __init acer_wmi_accel_setup(void)
1877{
 
1878	int err;
1879
1880	err = acer_wmi_get_handle("SENR", "BST0001", &gsensor_handle);
1881	if (err)
1882		return err;
1883
1884	interface->capability |= ACER_CAP_ACCEL;
 
1885
1886	acer_wmi_accel_dev = input_allocate_device();
1887	if (!acer_wmi_accel_dev)
1888		return -ENOMEM;
1889
1890	acer_wmi_accel_dev->open = acer_gsensor_open;
1891
1892	acer_wmi_accel_dev->name = "Acer BMA150 accelerometer";
1893	acer_wmi_accel_dev->phys = "wmi/input1";
1894	acer_wmi_accel_dev->id.bustype = BUS_HOST;
1895	acer_wmi_accel_dev->evbit[0] = BIT_MASK(EV_ABS);
1896	input_set_abs_params(acer_wmi_accel_dev, ABS_X, -16384, 16384, 0, 0);
1897	input_set_abs_params(acer_wmi_accel_dev, ABS_Y, -16384, 16384, 0, 0);
1898	input_set_abs_params(acer_wmi_accel_dev, ABS_Z, -16384, 16384, 0, 0);
1899
1900	err = input_register_device(acer_wmi_accel_dev);
1901	if (err)
1902		goto err_free_dev;
1903
1904	return 0;
1905
1906err_free_dev:
1907	input_free_device(acer_wmi_accel_dev);
1908	return err;
1909}
1910
1911static void acer_wmi_accel_destroy(void)
1912{
1913	input_unregister_device(acer_wmi_accel_dev);
1914}
1915
1916static int __init acer_wmi_input_setup(void)
1917{
1918	acpi_status status;
1919	int err;
1920
1921	acer_wmi_input_dev = input_allocate_device();
1922	if (!acer_wmi_input_dev)
1923		return -ENOMEM;
1924
1925	acer_wmi_input_dev->name = "Acer WMI hotkeys";
1926	acer_wmi_input_dev->phys = "wmi/input0";
1927	acer_wmi_input_dev->id.bustype = BUS_HOST;
1928
1929	err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1930	if (err)
1931		goto err_free_dev;
1932
 
 
 
1933	status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1934						acer_wmi_notify, NULL);
1935	if (ACPI_FAILURE(status)) {
1936		err = -EIO;
1937		goto err_free_keymap;
1938	}
1939
 
 
 
1940	err = input_register_device(acer_wmi_input_dev);
1941	if (err)
1942		goto err_uninstall_notifier;
1943
1944	return 0;
1945
1946err_uninstall_notifier:
1947	wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1948err_free_keymap:
1949	sparse_keymap_free(acer_wmi_input_dev);
1950err_free_dev:
1951	input_free_device(acer_wmi_input_dev);
1952	return err;
1953}
1954
1955static void acer_wmi_input_destroy(void)
1956{
1957	wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1958	sparse_keymap_free(acer_wmi_input_dev);
1959	input_unregister_device(acer_wmi_input_dev);
1960}
1961
1962/*
1963 * debugfs functions
1964 */
1965static u32 get_wmid_devices(void)
1966{
1967	struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1968	union acpi_object *obj;
1969	acpi_status status;
1970	u32 devices = 0;
1971
1972	status = wmi_query_block(WMID_GUID2, 1, &out);
1973	if (ACPI_FAILURE(status))
1974		return 0;
1975
1976	obj = (union acpi_object *) out.pointer;
1977	if (obj) {
1978		if (obj->type == ACPI_TYPE_BUFFER &&
1979			(obj->buffer.length == sizeof(u32) ||
1980			obj->buffer.length == sizeof(u64))) {
1981			devices = *((u32 *) obj->buffer.pointer);
1982		} else if (obj->type == ACPI_TYPE_INTEGER) {
1983			devices = (u32) obj->integer.value;
1984		}
1985	}
1986
1987	kfree(out.pointer);
1988	return devices;
1989}
1990
 
 
1991/*
1992 * Platform device
1993 */
1994static int acer_platform_probe(struct platform_device *device)
1995{
1996	int err;
1997
1998	if (has_cap(ACER_CAP_MAILLED)) {
1999		err = acer_led_init(&device->dev);
2000		if (err)
2001			goto error_mailled;
2002	}
2003
2004	if (has_cap(ACER_CAP_BRIGHTNESS)) {
2005		err = acer_backlight_init(&device->dev);
2006		if (err)
2007			goto error_brightness;
2008	}
2009
2010	err = acer_rfkill_init(&device->dev);
2011	if (err)
2012		goto error_rfkill;
2013
2014	return err;
 
 
 
 
 
 
 
 
 
 
 
 
2015
 
 
 
 
 
2016error_rfkill:
2017	if (has_cap(ACER_CAP_BRIGHTNESS))
2018		acer_backlight_exit();
2019error_brightness:
2020	if (has_cap(ACER_CAP_MAILLED))
2021		acer_led_exit();
2022error_mailled:
2023	return err;
2024}
2025
2026static int acer_platform_remove(struct platform_device *device)
2027{
2028	if (has_cap(ACER_CAP_MAILLED))
2029		acer_led_exit();
2030	if (has_cap(ACER_CAP_BRIGHTNESS))
2031		acer_backlight_exit();
2032
2033	acer_rfkill_exit();
2034	return 0;
 
 
2035}
2036
2037#ifdef CONFIG_PM_SLEEP
2038static int acer_suspend(struct device *dev)
2039{
2040	u32 value;
2041	struct acer_data *data = &interface->data;
2042
2043	if (!data)
2044		return -ENOMEM;
2045
2046	if (has_cap(ACER_CAP_MAILLED)) {
2047		get_u32(&value, ACER_CAP_MAILLED);
2048		set_u32(LED_OFF, ACER_CAP_MAILLED);
2049		data->mailled = value;
2050	}
2051
2052	if (has_cap(ACER_CAP_BRIGHTNESS)) {
2053		get_u32(&value, ACER_CAP_BRIGHTNESS);
2054		data->brightness = value;
2055	}
2056
2057	return 0;
2058}
2059
2060static int acer_resume(struct device *dev)
2061{
2062	struct acer_data *data = &interface->data;
2063
2064	if (!data)
2065		return -ENOMEM;
2066
2067	if (has_cap(ACER_CAP_MAILLED))
2068		set_u32(data->mailled, ACER_CAP_MAILLED);
2069
2070	if (has_cap(ACER_CAP_BRIGHTNESS))
2071		set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
2072
2073	if (has_cap(ACER_CAP_ACCEL))
2074		acer_gsensor_init();
2075
2076	return 0;
2077}
2078#else
2079#define acer_suspend	NULL
2080#define acer_resume	NULL
2081#endif
2082
2083static SIMPLE_DEV_PM_OPS(acer_pm, acer_suspend, acer_resume);
2084
2085static void acer_platform_shutdown(struct platform_device *device)
2086{
2087	struct acer_data *data = &interface->data;
2088
2089	if (!data)
2090		return;
2091
2092	if (has_cap(ACER_CAP_MAILLED))
2093		set_u32(LED_OFF, ACER_CAP_MAILLED);
2094}
2095
2096static struct platform_driver acer_platform_driver = {
2097	.driver = {
2098		.name = "acer-wmi",
2099		.pm = &acer_pm,
2100	},
2101	.probe = acer_platform_probe,
2102	.remove = acer_platform_remove,
2103	.shutdown = acer_platform_shutdown,
2104};
2105
2106static struct platform_device *acer_platform_device;
2107
2108static void remove_debugfs(void)
2109{
2110	debugfs_remove(interface->debug.devices);
2111	debugfs_remove(interface->debug.root);
2112}
2113
2114static int __init create_debugfs(void)
2115{
2116	interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
2117	if (!interface->debug.root) {
2118		pr_err("Failed to create debugfs directory");
2119		return -ENOMEM;
 
 
 
 
 
 
 
 
 
 
 
 
 
2120	}
2121
2122	interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
2123					interface->debug.root,
2124					&interface->debug.wmid_devices);
2125	if (!interface->debug.devices)
2126		goto error_debugfs;
 
 
 
 
 
 
 
 
 
 
 
 
 
2127
2128	return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2129
2130error_debugfs:
2131	remove_debugfs();
2132	return -ENOMEM;
 
 
 
 
 
 
 
 
2133}
2134
2135static int __init acer_wmi_init(void)
2136{
2137	int err;
2138
2139	pr_info("Acer Laptop ACPI-WMI Extras\n");
2140
2141	if (dmi_check_system(acer_blacklist)) {
2142		pr_info("Blacklisted hardware detected - not loading\n");
2143		return -ENODEV;
2144	}
2145
2146	find_quirks();
2147
2148	/*
2149	 * The AMW0_GUID1 wmi is not only found on Acer family but also other
2150	 * machines like Lenovo, Fujitsu and Medion. In the past days,
2151	 * acer-wmi driver handled those non-Acer machines by quirks list.
2152	 * But actually acer-wmi driver was loaded on any machines that have
2153	 * AMW0_GUID1. This behavior is strange because those machines should
2154	 * be supported by appropriate wmi drivers. e.g. fujitsu-laptop,
2155	 * ideapad-laptop. So, here checks the machine that has AMW0_GUID1
2156	 * should be in Acer/Gateway/Packard Bell white list, or it's already
2157	 * in the past quirk list.
2158	 */
2159	if (wmi_has_guid(AMW0_GUID1) &&
2160	    !dmi_check_system(amw0_whitelist) &&
2161	    quirks == &quirk_unknown) {
2162		pr_err("Unsupported machine has AMW0_GUID1, unable to load\n");
2163		return -ENODEV;
2164	}
2165
2166	/*
2167	 * Detect which ACPI-WMI interface we're using.
2168	 */
2169	if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2170		interface = &AMW0_V2_interface;
2171
2172	if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2173		interface = &wmid_interface;
2174
2175	if (wmi_has_guid(WMID_GUID3))
2176		interface = &wmid_v2_interface;
2177
2178	if (interface)
2179		dmi_walk(type_aa_dmi_decode, NULL);
2180
2181	if (wmi_has_guid(WMID_GUID2) && interface) {
2182		if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) {
2183			pr_err("Unable to detect available WMID devices\n");
2184			return -ENODEV;
2185		}
2186		/* WMID always provides brightness methods */
2187		interface->capability |= ACER_CAP_BRIGHTNESS;
2188	} else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa) {
2189		pr_err("No WMID device detection method found\n");
2190		return -ENODEV;
2191	}
2192
2193	if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
2194		interface = &AMW0_interface;
2195
2196		if (ACPI_FAILURE(AMW0_set_capabilities())) {
2197			pr_err("Unable to detect available AMW0 devices\n");
2198			return -ENODEV;
2199		}
2200	}
2201
2202	if (wmi_has_guid(AMW0_GUID1))
2203		AMW0_find_mailled();
2204
2205	if (!interface) {
2206		pr_err("No or unsupported WMI interface, unable to load\n");
2207		return -ENODEV;
2208	}
2209
2210	set_quirks();
2211
2212	if (dmi_check_system(video_vendor_dmi_table))
2213		acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
2214
2215	if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
2216		interface->capability &= ~ACER_CAP_BRIGHTNESS;
2217
2218	if (wmi_has_guid(WMID_GUID3)) {
 
 
 
 
 
 
 
 
 
 
2219		if (ec_raw_mode) {
2220			if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
2221				pr_err("Cannot enable EC raw mode\n");
2222				return -ENODEV;
2223			}
2224		} else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
2225			pr_err("Cannot enable Launch Manager mode\n");
2226			return -ENODEV;
2227		}
2228	} else if (ec_raw_mode) {
2229		pr_info("No WMID EC raw mode enable method\n");
2230	}
2231
2232	if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
2233		err = acer_wmi_input_setup();
2234		if (err)
2235			return err;
 
 
 
2236	}
2237
2238	acer_wmi_accel_setup();
2239
2240	err = platform_driver_register(&acer_platform_driver);
2241	if (err) {
2242		pr_err("Unable to register platform driver\n");
2243		goto error_platform_register;
2244	}
2245
2246	acer_platform_device = platform_device_alloc("acer-wmi", -1);
2247	if (!acer_platform_device) {
2248		err = -ENOMEM;
2249		goto error_device_alloc;
2250	}
2251
2252	err = platform_device_add(acer_platform_device);
2253	if (err)
2254		goto error_device_add;
2255
2256	if (wmi_has_guid(WMID_GUID2)) {
2257		interface->debug.wmid_devices = get_wmid_devices();
2258		err = create_debugfs();
2259		if (err)
2260			goto error_create_debugfs;
2261	}
2262
2263	/* Override any initial settings with values from the commandline */
2264	acer_commandline_init();
2265
2266	return 0;
2267
2268error_create_debugfs:
2269	platform_device_del(acer_platform_device);
2270error_device_add:
2271	platform_device_put(acer_platform_device);
2272error_device_alloc:
2273	platform_driver_unregister(&acer_platform_driver);
2274error_platform_register:
2275	if (wmi_has_guid(ACERWMID_EVENT_GUID))
2276		acer_wmi_input_destroy();
2277	if (has_cap(ACER_CAP_ACCEL))
2278		acer_wmi_accel_destroy();
2279
2280	return err;
2281}
2282
2283static void __exit acer_wmi_exit(void)
2284{
2285	if (wmi_has_guid(ACERWMID_EVENT_GUID))
2286		acer_wmi_input_destroy();
2287
2288	if (has_cap(ACER_CAP_ACCEL))
2289		acer_wmi_accel_destroy();
2290
2291	remove_debugfs();
2292	platform_device_unregister(acer_platform_device);
2293	platform_driver_unregister(&acer_platform_driver);
2294
2295	pr_info("Acer Laptop WMI Extras unloaded\n");
2296	return;
2297}
2298
2299module_init(acer_wmi_init);
2300module_exit(acer_wmi_exit);