blob: d798314b81fe08199709d3927949fa85a59f71bf [file] [log] [blame]
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001/*
2 * Acer WMI Laptop Extras
3 *
Carlos Corbacho4f0175d2009-04-04 09:33:39 +01004 * Copyright (C) 2007-2009 Carlos Corbacho <carlos@strangeworlds.co.uk>
Carlos Corbacho745a5d22008-02-05 02:17:10 +00005 *
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
Lee, Chun-Yicae15702011-03-16 18:52:36 +080025#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26
Carlos Corbacho745a5d22008-02-05 02:17:10 +000027#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/init.h>
30#include <linux/types.h>
31#include <linux/dmi.h>
Carlos Corbachof2b585b2008-06-21 09:09:27 +010032#include <linux/fb.h>
Carlos Corbacho745a5d22008-02-05 02:17:10 +000033#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>
Carlos Corbacho0606e1a2008-10-08 21:40:21 +010038#include <linux/rfkill.h>
39#include <linux/workqueue.h>
Carlos Corbacho81143522008-06-21 09:09:53 +010040#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080042#include <linux/input.h>
43#include <linux/input/sparse-keymap.h>
Carlos Corbacho745a5d22008-02-05 02:17:10 +000044
45#include <acpi/acpi_drivers.h>
46
47MODULE_AUTHOR("Carlos Corbacho");
48MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
49MODULE_LICENSE("GPL");
50
Carlos Corbacho745a5d22008-02-05 02:17:10 +000051/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +000052 * Magic Number
53 * Meaning is unknown - this number is required for writing to ACPI for AMW0
54 * (it's also used in acerhk when directly accessing the BIOS)
55 */
56#define ACER_AMW0_WRITE 0x9610
57
58/*
59 * Bit masks for the AMW0 interface
60 */
61#define ACER_AMW0_WIRELESS_MASK 0x35
62#define ACER_AMW0_BLUETOOTH_MASK 0x34
63#define ACER_AMW0_MAILLED_MASK 0x31
64
65/*
66 * Method IDs for WMID interface
67 */
68#define ACER_WMID_GET_WIRELESS_METHODID 1
69#define ACER_WMID_GET_BLUETOOTH_METHODID 2
70#define ACER_WMID_GET_BRIGHTNESS_METHODID 3
71#define ACER_WMID_SET_WIRELESS_METHODID 4
72#define ACER_WMID_SET_BLUETOOTH_METHODID 5
73#define ACER_WMID_SET_BRIGHTNESS_METHODID 6
74#define ACER_WMID_GET_THREEG_METHODID 10
75#define ACER_WMID_SET_THREEG_METHODID 11
76
77/*
78 * Acer ACPI method GUIDs
79 */
80#define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
Carlos Corbacho5753dd52008-06-21 09:09:48 +010081#define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
Matthew Garrettbbb70602011-02-09 16:39:40 -050082#define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
Pali Rohár298f19b2011-03-11 12:36:43 -050083#define WMID_GUID2 "95764E09-FB56-4E83-B31A-37761F60994A"
Lee, Chun-Yib3c90922010-12-07 10:29:22 +080084#define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
Carlos Corbacho745a5d22008-02-05 02:17:10 +000085
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080086/*
87 * Acer ACPI event GUIDs
88 */
89#define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
90
Carlos Corbacho745a5d22008-02-05 02:17:10 +000091MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
Pali Rohár298f19b2011-03-11 12:36:43 -050092MODULE_ALIAS("wmi:6AF4F258-B401-42Fd-BE91-3D4AC2D7C0D3");
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080093MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
94
95enum acer_wmi_event_ids {
96 WMID_HOTKEY_EVENT = 0x1,
97};
98
99static const struct key_entry acer_wmi_keymap[] = {
100 {KE_KEY, 0x01, {KEY_WLAN} }, /* WiFi */
101 {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */
102 {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */
103 {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */
104 {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */
105 {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */
106 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
Lee, Chun-Yi89411782011-03-02 01:07:11 +0800107 {KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} }, /* Touch Pad On/Off */
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800108 {KE_END, 0}
109};
110
111static struct input_dev *acer_wmi_input_dev;
112
113struct event_return_value {
114 u8 function;
115 u8 key_num;
116 u16 device_state;
117 u32 reserved;
118} __attribute__((packed));
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000119
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000120/*
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800121 * GUID3 Get Device Status device flags
122 */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800123#define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800124#define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800125#define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800126
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500127struct lm_input_params {
128 u8 function_num; /* Function Number */
129 u16 commun_devices; /* Communication type devices default status */
130 u16 devices; /* Other type devices default status */
131 u8 lm_status; /* Launch Manager Status */
132 u16 reserved;
133} __attribute__((packed));
134
135struct lm_return_value {
136 u8 error_code; /* Error Code */
137 u8 ec_return_value; /* EC Return Value */
138 u16 reserved;
139} __attribute__((packed));
140
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800141struct wmid3_gds_input_param { /* Get Device Status input parameter */
142 u8 function_num; /* Function Number */
143 u8 hotkey_number; /* Hotkey Number */
144 u16 devices; /* Get Device */
145} __attribute__((packed));
146
147struct wmid3_gds_return_value { /* Get Device Status return value*/
148 u8 error_code; /* Error Code */
149 u8 ec_return_value; /* EC Return Value */
150 u16 devices; /* Current Device Status */
151 u32 reserved;
152} __attribute__((packed));
153
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800154struct hotkey_function_type_aa {
155 u8 type;
156 u8 length;
157 u16 handle;
158 u16 commun_func_bitmap;
159} __attribute__((packed));
160
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800161/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000162 * Interface capability flags
163 */
164#define ACER_CAP_MAILLED (1<<0)
165#define ACER_CAP_WIRELESS (1<<1)
166#define ACER_CAP_BLUETOOTH (1<<2)
167#define ACER_CAP_BRIGHTNESS (1<<3)
168#define ACER_CAP_THREEG (1<<4)
169#define ACER_CAP_ANY (0xFFFFFFFF)
170
171/*
172 * Interface type flags
173 */
174enum interface_flags {
175 ACER_AMW0,
176 ACER_AMW0_V2,
177 ACER_WMID,
178};
179
180#define ACER_DEFAULT_WIRELESS 0
181#define ACER_DEFAULT_BLUETOOTH 0
182#define ACER_DEFAULT_MAILLED 0
183#define ACER_DEFAULT_THREEG 0
184
185static int max_brightness = 0xF;
186
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000187static int mailled = -1;
188static int brightness = -1;
189static int threeg = -1;
190static int force_series;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500191static bool ec_raw_mode;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800192static bool has_type_aa;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000193
194module_param(mailled, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000195module_param(brightness, int, 0444);
196module_param(threeg, int, 0444);
197module_param(force_series, int, 0444);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500198module_param(ec_raw_mode, bool, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000199MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
200MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
201MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
202MODULE_PARM_DESC(force_series, "Force a different laptop series");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500203MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000204
205struct acer_data {
206 int mailled;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000207 int threeg;
208 int brightness;
209};
210
Carlos Corbacho81143522008-06-21 09:09:53 +0100211struct acer_debug {
212 struct dentry *root;
213 struct dentry *devices;
214 u32 wmid_devices;
215};
216
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100217static struct rfkill *wireless_rfkill;
218static struct rfkill *bluetooth_rfkill;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800219static struct rfkill *threeg_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100220
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000221/* Each low-level interface must define at least some of the following */
222struct wmi_interface {
223 /* The WMI device type */
224 u32 type;
225
226 /* The capabilities this interface provides */
227 u32 capability;
228
229 /* Private data for the current interface */
230 struct acer_data data;
Carlos Corbacho81143522008-06-21 09:09:53 +0100231
232 /* debugfs entries associated with this interface */
233 struct acer_debug debug;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000234};
235
236/* The static interface pointer, points to the currently detected interface */
237static struct wmi_interface *interface;
238
239/*
240 * Embedded Controller quirks
241 * Some laptops require us to directly access the EC to either enable or query
242 * features that are not available through WMI.
243 */
244
245struct quirk_entry {
246 u8 wireless;
247 u8 mailled;
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100248 s8 brightness;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000249 u8 bluetooth;
250};
251
252static struct quirk_entry *quirks;
253
254static void set_quirks(void)
255{
Arjan van de Ven83097ac2008-08-23 21:45:21 -0700256 if (!interface)
257 return;
258
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000259 if (quirks->mailled)
260 interface->capability |= ACER_CAP_MAILLED;
261
262 if (quirks->brightness)
263 interface->capability |= ACER_CAP_BRIGHTNESS;
264}
265
266static int dmi_matched(const struct dmi_system_id *dmi)
267{
268 quirks = dmi->driver_data;
Axel Lind53bf0f2010-06-30 13:32:16 +0800269 return 1;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000270}
271
272static struct quirk_entry quirk_unknown = {
273};
274
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100275static struct quirk_entry quirk_acer_aspire_1520 = {
276 .brightness = -1,
277};
278
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000279static struct quirk_entry quirk_acer_travelmate_2490 = {
280 .mailled = 1,
281};
282
283/* This AMW0 laptop has no bluetooth */
284static struct quirk_entry quirk_medion_md_98300 = {
285 .wireless = 1,
286};
287
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100288static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
289 .wireless = 2,
290};
291
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100292/* The Aspire One has a dummy ACPI-WMI interface - disable it */
293static struct dmi_system_id __devinitdata acer_blacklist[] = {
294 {
295 .ident = "Acer Aspire One (SSD)",
296 .matches = {
297 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
298 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
299 },
300 },
301 {
302 .ident = "Acer Aspire One (HDD)",
303 .matches = {
304 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
305 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
306 },
307 },
308 {}
309};
310
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000311static struct dmi_system_id acer_quirks[] = {
312 {
313 .callback = dmi_matched,
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100314 .ident = "Acer Aspire 1360",
315 .matches = {
316 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
317 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
318 },
319 .driver_data = &quirk_acer_aspire_1520,
320 },
321 {
322 .callback = dmi_matched,
323 .ident = "Acer Aspire 1520",
324 .matches = {
325 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
326 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
327 },
328 .driver_data = &quirk_acer_aspire_1520,
329 },
330 {
331 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000332 .ident = "Acer Aspire 3100",
333 .matches = {
334 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
335 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
336 },
337 .driver_data = &quirk_acer_travelmate_2490,
338 },
339 {
340 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000341 .ident = "Acer Aspire 3610",
342 .matches = {
343 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
344 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
345 },
346 .driver_data = &quirk_acer_travelmate_2490,
347 },
348 {
349 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000350 .ident = "Acer Aspire 5100",
351 .matches = {
352 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
353 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
354 },
355 .driver_data = &quirk_acer_travelmate_2490,
356 },
357 {
358 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000359 .ident = "Acer Aspire 5610",
360 .matches = {
361 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
362 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
363 },
364 .driver_data = &quirk_acer_travelmate_2490,
365 },
366 {
367 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000368 .ident = "Acer Aspire 5630",
369 .matches = {
370 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
371 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
372 },
373 .driver_data = &quirk_acer_travelmate_2490,
374 },
375 {
376 .callback = dmi_matched,
377 .ident = "Acer Aspire 5650",
378 .matches = {
379 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
380 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
381 },
382 .driver_data = &quirk_acer_travelmate_2490,
383 },
384 {
385 .callback = dmi_matched,
386 .ident = "Acer Aspire 5680",
387 .matches = {
388 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
389 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
390 },
391 .driver_data = &quirk_acer_travelmate_2490,
392 },
393 {
394 .callback = dmi_matched,
395 .ident = "Acer Aspire 9110",
396 .matches = {
397 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
398 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
399 },
400 .driver_data = &quirk_acer_travelmate_2490,
401 },
402 {
403 .callback = dmi_matched,
404 .ident = "Acer TravelMate 2490",
405 .matches = {
406 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
407 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
408 },
409 .driver_data = &quirk_acer_travelmate_2490,
410 },
411 {
412 .callback = dmi_matched,
Carlos Corbacho262ee352008-02-16 00:02:56 +0000413 .ident = "Acer TravelMate 4200",
414 .matches = {
415 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
416 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
417 },
418 .driver_data = &quirk_acer_travelmate_2490,
419 },
420 {
421 .callback = dmi_matched,
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100422 .ident = "Fujitsu Siemens Amilo Li 1718",
423 .matches = {
424 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
425 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
426 },
427 .driver_data = &quirk_fujitsu_amilo_li_1718,
428 },
429 {
430 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000431 .ident = "Medion MD 98300",
432 .matches = {
433 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
434 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
435 },
436 .driver_data = &quirk_medion_md_98300,
437 },
438 {}
439};
440
441/* Find which quirks are needed for a particular vendor/ model pair */
442static void find_quirks(void)
443{
444 if (!force_series) {
445 dmi_check_system(acer_quirks);
446 } else if (force_series == 2490) {
447 quirks = &quirk_acer_travelmate_2490;
448 }
449
450 if (quirks == NULL)
451 quirks = &quirk_unknown;
452
453 set_quirks();
454}
455
456/*
457 * General interface convenience methods
458 */
459
460static bool has_cap(u32 cap)
461{
462 if ((interface->capability & cap) != 0)
463 return 1;
464
465 return 0;
466}
467
468/*
469 * AMW0 (V1) interface
470 */
471struct wmab_args {
472 u32 eax;
473 u32 ebx;
474 u32 ecx;
475 u32 edx;
476};
477
478struct wmab_ret {
479 u32 eax;
480 u32 ebx;
481 u32 ecx;
482 u32 edx;
483 u32 eex;
484};
485
486static acpi_status wmab_execute(struct wmab_args *regbuf,
487struct acpi_buffer *result)
488{
489 struct acpi_buffer input;
490 acpi_status status;
491 input.length = sizeof(struct wmab_args);
492 input.pointer = (u8 *)regbuf;
493
494 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
495
496 return status;
497}
498
499static acpi_status AMW0_get_u32(u32 *value, u32 cap,
500struct wmi_interface *iface)
501{
502 int err;
503 u8 result;
504
505 switch (cap) {
506 case ACER_CAP_MAILLED:
507 switch (quirks->mailled) {
508 default:
509 err = ec_read(0xA, &result);
510 if (err)
511 return AE_ERROR;
512 *value = (result >> 7) & 0x1;
513 return AE_OK;
514 }
515 break;
516 case ACER_CAP_WIRELESS:
517 switch (quirks->wireless) {
518 case 1:
519 err = ec_read(0x7B, &result);
520 if (err)
521 return AE_ERROR;
522 *value = result & 0x1;
523 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100524 case 2:
525 err = ec_read(0x71, &result);
526 if (err)
527 return AE_ERROR;
528 *value = result & 0x1;
529 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000530 default:
531 err = ec_read(0xA, &result);
532 if (err)
533 return AE_ERROR;
534 *value = (result >> 2) & 0x1;
535 return AE_OK;
536 }
537 break;
538 case ACER_CAP_BLUETOOTH:
539 switch (quirks->bluetooth) {
540 default:
541 err = ec_read(0xA, &result);
542 if (err)
543 return AE_ERROR;
544 *value = (result >> 4) & 0x1;
545 return AE_OK;
546 }
547 break;
548 case ACER_CAP_BRIGHTNESS:
549 switch (quirks->brightness) {
550 default:
551 err = ec_read(0x83, &result);
552 if (err)
553 return AE_ERROR;
554 *value = result;
555 return AE_OK;
556 }
557 break;
558 default:
Lin Ming08237972008-08-08 11:57:11 +0800559 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000560 }
561 return AE_OK;
562}
563
564static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
565{
566 struct wmab_args args;
567
568 args.eax = ACER_AMW0_WRITE;
569 args.ebx = value ? (1<<8) : 0;
570 args.ecx = args.edx = 0;
571
572 switch (cap) {
573 case ACER_CAP_MAILLED:
574 if (value > 1)
575 return AE_BAD_PARAMETER;
576 args.ebx |= ACER_AMW0_MAILLED_MASK;
577 break;
578 case ACER_CAP_WIRELESS:
579 if (value > 1)
580 return AE_BAD_PARAMETER;
581 args.ebx |= ACER_AMW0_WIRELESS_MASK;
582 break;
583 case ACER_CAP_BLUETOOTH:
584 if (value > 1)
585 return AE_BAD_PARAMETER;
586 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
587 break;
588 case ACER_CAP_BRIGHTNESS:
589 if (value > max_brightness)
590 return AE_BAD_PARAMETER;
591 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000592 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000593 return ec_write(0x83, value);
594 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000595 }
596 default:
Lin Ming08237972008-08-08 11:57:11 +0800597 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000598 }
599
600 /* Actually do the set */
601 return wmab_execute(&args, NULL);
602}
603
604static acpi_status AMW0_find_mailled(void)
605{
606 struct wmab_args args;
607 struct wmab_ret ret;
608 acpi_status status = AE_OK;
609 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
610 union acpi_object *obj;
611
612 args.eax = 0x86;
613 args.ebx = args.ecx = args.edx = 0;
614
615 status = wmab_execute(&args, &out);
616 if (ACPI_FAILURE(status))
617 return status;
618
619 obj = (union acpi_object *) out.pointer;
620 if (obj && obj->type == ACPI_TYPE_BUFFER &&
621 obj->buffer.length == sizeof(struct wmab_ret)) {
622 ret = *((struct wmab_ret *) obj->buffer.pointer);
623 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700624 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000625 return AE_ERROR;
626 }
627
628 if (ret.eex & 0x1)
629 interface->capability |= ACER_CAP_MAILLED;
630
631 kfree(out.pointer);
632
633 return AE_OK;
634}
635
636static acpi_status AMW0_set_capabilities(void)
637{
638 struct wmab_args args;
639 struct wmab_ret ret;
Axel Lin7677fbd2010-07-20 15:19:53 -0700640 acpi_status status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000641 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
642 union acpi_object *obj;
643
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100644 /*
645 * On laptops with this strange GUID (non Acer), normal probing doesn't
646 * work.
647 */
648 if (wmi_has_guid(AMW0_GUID2)) {
649 interface->capability |= ACER_CAP_WIRELESS;
650 return AE_OK;
651 }
652
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000653 args.eax = ACER_AMW0_WRITE;
654 args.ecx = args.edx = 0;
655
656 args.ebx = 0xa2 << 8;
657 args.ebx |= ACER_AMW0_WIRELESS_MASK;
658
659 status = wmab_execute(&args, &out);
660 if (ACPI_FAILURE(status))
661 return status;
662
Axel Lin7677fbd2010-07-20 15:19:53 -0700663 obj = out.pointer;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000664 if (obj && obj->type == ACPI_TYPE_BUFFER &&
665 obj->buffer.length == sizeof(struct wmab_ret)) {
666 ret = *((struct wmab_ret *) obj->buffer.pointer);
667 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700668 status = AE_ERROR;
669 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000670 }
671
672 if (ret.eax & 0x1)
673 interface->capability |= ACER_CAP_WIRELESS;
674
675 args.ebx = 2 << 8;
676 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
677
Axel Lin7677fbd2010-07-20 15:19:53 -0700678 /*
679 * It's ok to use existing buffer for next wmab_execute call.
680 * But we need to kfree(out.pointer) if next wmab_execute fail.
681 */
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000682 status = wmab_execute(&args, &out);
683 if (ACPI_FAILURE(status))
Axel Lin7677fbd2010-07-20 15:19:53 -0700684 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000685
686 obj = (union acpi_object *) out.pointer;
687 if (obj && obj->type == ACPI_TYPE_BUFFER
688 && obj->buffer.length == sizeof(struct wmab_ret)) {
689 ret = *((struct wmab_ret *) obj->buffer.pointer);
690 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700691 status = AE_ERROR;
692 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000693 }
694
695 if (ret.eax & 0x1)
696 interface->capability |= ACER_CAP_BLUETOOTH;
697
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000698 /*
699 * This appears to be safe to enable, since all Wistron based laptops
700 * appear to use the same EC register for brightness, even if they
701 * differ for wireless, etc
702 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100703 if (quirks->brightness >= 0)
704 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000705
Axel Lin7677fbd2010-07-20 15:19:53 -0700706 status = AE_OK;
707out:
708 kfree(out.pointer);
709 return status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000710}
711
712static struct wmi_interface AMW0_interface = {
713 .type = ACER_AMW0,
714};
715
716static struct wmi_interface AMW0_V2_interface = {
717 .type = ACER_AMW0_V2,
718};
719
720/*
721 * New interface (The WMID interface)
722 */
723static acpi_status
724WMI_execute_u32(u32 method_id, u32 in, u32 *out)
725{
726 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
727 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
728 union acpi_object *obj;
729 u32 tmp;
730 acpi_status status;
731
732 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
733
734 if (ACPI_FAILURE(status))
735 return status;
736
737 obj = (union acpi_object *) result.pointer;
738 if (obj && obj->type == ACPI_TYPE_BUFFER &&
739 obj->buffer.length == sizeof(u32)) {
740 tmp = *((u32 *) obj->buffer.pointer);
741 } else {
742 tmp = 0;
743 }
744
745 if (out)
746 *out = tmp;
747
748 kfree(result.pointer);
749
750 return status;
751}
752
753static acpi_status WMID_get_u32(u32 *value, u32 cap,
754struct wmi_interface *iface)
755{
756 acpi_status status;
757 u8 tmp;
758 u32 result, method_id = 0;
759
760 switch (cap) {
761 case ACER_CAP_WIRELESS:
762 method_id = ACER_WMID_GET_WIRELESS_METHODID;
763 break;
764 case ACER_CAP_BLUETOOTH:
765 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
766 break;
767 case ACER_CAP_BRIGHTNESS:
768 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
769 break;
770 case ACER_CAP_THREEG:
771 method_id = ACER_WMID_GET_THREEG_METHODID;
772 break;
773 case ACER_CAP_MAILLED:
774 if (quirks->mailled == 1) {
775 ec_read(0x9f, &tmp);
776 *value = tmp & 0x1;
777 return 0;
778 }
779 default:
Lin Ming08237972008-08-08 11:57:11 +0800780 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000781 }
782 status = WMI_execute_u32(method_id, 0, &result);
783
784 if (ACPI_SUCCESS(status))
785 *value = (u8)result;
786
787 return status;
788}
789
790static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
791{
792 u32 method_id = 0;
793 char param;
794
795 switch (cap) {
796 case ACER_CAP_BRIGHTNESS:
797 if (value > max_brightness)
798 return AE_BAD_PARAMETER;
799 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
800 break;
801 case ACER_CAP_WIRELESS:
802 if (value > 1)
803 return AE_BAD_PARAMETER;
804 method_id = ACER_WMID_SET_WIRELESS_METHODID;
805 break;
806 case ACER_CAP_BLUETOOTH:
807 if (value > 1)
808 return AE_BAD_PARAMETER;
809 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
810 break;
811 case ACER_CAP_THREEG:
812 if (value > 1)
813 return AE_BAD_PARAMETER;
814 method_id = ACER_WMID_SET_THREEG_METHODID;
815 break;
816 case ACER_CAP_MAILLED:
817 if (value > 1)
818 return AE_BAD_PARAMETER;
819 if (quirks->mailled == 1) {
820 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700821 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000822 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700823 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000824 return 0;
825 }
826 break;
827 default:
Lin Ming08237972008-08-08 11:57:11 +0800828 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000829 }
830 return WMI_execute_u32(method_id, (u32)value, NULL);
831}
832
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800833static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
834{
835 struct hotkey_function_type_aa *type_aa;
836
837 /* We are looking for OEM-specific Type AAh */
838 if (header->type != 0xAA)
839 return;
840
841 has_type_aa = true;
842 type_aa = (struct hotkey_function_type_aa *) header;
843
Lee, Chun-Yicae15702011-03-16 18:52:36 +0800844 pr_info("Function bitmap for Communication Button: 0x%x\n",
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800845 type_aa->commun_func_bitmap);
846
847 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
848 interface->capability |= ACER_CAP_WIRELESS;
849 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
850 interface->capability |= ACER_CAP_THREEG;
851 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
852 interface->capability |= ACER_CAP_BLUETOOTH;
853}
854
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000855static acpi_status WMID_set_capabilities(void)
856{
857 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
858 union acpi_object *obj;
859 acpi_status status;
860 u32 devices;
861
862 status = wmi_query_block(WMID_GUID2, 1, &out);
863 if (ACPI_FAILURE(status))
864 return status;
865
866 obj = (union acpi_object *) out.pointer;
867 if (obj && obj->type == ACPI_TYPE_BUFFER &&
868 obj->buffer.length == sizeof(u32)) {
869 devices = *((u32 *) obj->buffer.pointer);
870 } else {
Axel Lin66904862010-07-20 15:19:52 -0700871 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000872 return AE_ERROR;
873 }
874
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800875 dmi_walk(type_aa_dmi_decode, NULL);
876 if (!has_type_aa) {
877 interface->capability |= ACER_CAP_WIRELESS;
878 interface->capability |= ACER_CAP_THREEG;
879 if (devices & 0x10)
880 interface->capability |= ACER_CAP_BLUETOOTH;
881 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000882
883 /* WMID always provides brightness methods */
884 interface->capability |= ACER_CAP_BRIGHTNESS;
885
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000886 if (!(devices & 0x20))
887 max_brightness = 0x9;
888
Axel Lin66904862010-07-20 15:19:52 -0700889 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000890 return status;
891}
892
893static struct wmi_interface wmid_interface = {
894 .type = ACER_WMID,
895};
896
897/*
898 * Generic Device (interface-independent)
899 */
900
901static acpi_status get_u32(u32 *value, u32 cap)
902{
Lin Ming08237972008-08-08 11:57:11 +0800903 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000904
905 switch (interface->type) {
906 case ACER_AMW0:
907 status = AMW0_get_u32(value, cap, interface);
908 break;
909 case ACER_AMW0_V2:
910 if (cap == ACER_CAP_MAILLED) {
911 status = AMW0_get_u32(value, cap, interface);
912 break;
913 }
914 case ACER_WMID:
915 status = WMID_get_u32(value, cap, interface);
916 break;
917 }
918
919 return status;
920}
921
922static acpi_status set_u32(u32 value, u32 cap)
923{
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100924 acpi_status status;
925
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000926 if (interface->capability & cap) {
927 switch (interface->type) {
928 case ACER_AMW0:
929 return AMW0_set_u32(value, cap, interface);
930 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100931 if (cap == ACER_CAP_MAILLED)
932 return AMW0_set_u32(value, cap, interface);
933
934 /*
935 * On some models, some WMID methods don't toggle
936 * properly. For those cases, we want to run the AMW0
937 * method afterwards to be certain we've really toggled
938 * the device state.
939 */
940 if (cap == ACER_CAP_WIRELESS ||
941 cap == ACER_CAP_BLUETOOTH) {
942 status = WMID_set_u32(value, cap, interface);
943 if (ACPI_FAILURE(status))
944 return status;
945
946 return AMW0_set_u32(value, cap, interface);
947 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000948 case ACER_WMID:
949 return WMID_set_u32(value, cap, interface);
950 default:
951 return AE_BAD_PARAMETER;
952 }
953 }
954 return AE_BAD_PARAMETER;
955}
956
957static void __init acer_commandline_init(void)
958{
959 /*
960 * These will all fail silently if the value given is invalid, or the
961 * capability isn't available on the given interface
962 */
963 set_u32(mailled, ACER_CAP_MAILLED);
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800964 if (!has_type_aa)
965 set_u32(threeg, ACER_CAP_THREEG);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000966 set_u32(brightness, ACER_CAP_BRIGHTNESS);
967}
968
969/*
970 * LED device (Mail LED only, no other LEDs known yet)
971 */
972static void mail_led_set(struct led_classdev *led_cdev,
973enum led_brightness value)
974{
975 set_u32(value, ACER_CAP_MAILLED);
976}
977
978static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +0000979 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000980 .brightness_set = mail_led_set,
981};
982
Sam Ravnborg7560e382008-02-17 13:22:54 +0100983static int __devinit acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000984{
985 return led_classdev_register(dev, &mail_led);
986}
987
988static void acer_led_exit(void)
989{
Pali Rohár9a0b74f2011-02-26 21:18:58 +0100990 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000991 led_classdev_unregister(&mail_led);
992}
993
994/*
995 * Backlight device
996 */
997static struct backlight_device *acer_backlight_device;
998
999static int read_brightness(struct backlight_device *bd)
1000{
1001 u32 value;
1002 get_u32(&value, ACER_CAP_BRIGHTNESS);
1003 return value;
1004}
1005
1006static int update_bl_status(struct backlight_device *bd)
1007{
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001008 int intensity = bd->props.brightness;
1009
1010 if (bd->props.power != FB_BLANK_UNBLANK)
1011 intensity = 0;
1012 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1013 intensity = 0;
1014
1015 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1016
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001017 return 0;
1018}
1019
Lionel Debrouxacc24722010-11-16 14:14:02 +01001020static const struct backlight_ops acer_bl_ops = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001021 .get_brightness = read_brightness,
1022 .update_status = update_bl_status,
1023};
1024
Sam Ravnborg7560e382008-02-17 13:22:54 +01001025static int __devinit acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001026{
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001027 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001028 struct backlight_device *bd;
1029
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001030 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001031 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001032 props.max_brightness = max_brightness;
1033 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1034 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001035 if (IS_ERR(bd)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001036 pr_err("Could not register Acer backlight device\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001037 acer_backlight_device = NULL;
1038 return PTR_ERR(bd);
1039 }
1040
1041 acer_backlight_device = bd;
1042
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001043 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +00001044 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001045 backlight_update_status(bd);
1046 return 0;
1047}
1048
Sam Ravnborg7560e382008-02-17 13:22:54 +01001049static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001050{
1051 backlight_device_unregister(acer_backlight_device);
1052}
1053
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001054static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1055{
1056 struct wmid3_gds_return_value return_value;
1057 acpi_status status;
1058 union acpi_object *obj;
1059 struct wmid3_gds_input_param params = {
1060 .function_num = 0x1,
1061 .hotkey_number = 0x01,
1062 .devices = device,
1063 };
1064 struct acpi_buffer input = {
1065 sizeof(struct wmid3_gds_input_param),
1066 &params
1067 };
1068 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1069
1070 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1071 if (ACPI_FAILURE(status))
1072 return status;
1073
1074 obj = output.pointer;
1075
1076 if (!obj)
1077 return AE_ERROR;
1078 else if (obj->type != ACPI_TYPE_BUFFER) {
1079 kfree(obj);
1080 return AE_ERROR;
1081 }
1082 if (obj->buffer.length != 8) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001083 pr_warning("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001084 kfree(obj);
1085 return AE_ERROR;
1086 }
1087
1088 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1089 kfree(obj);
1090
1091 if (return_value.error_code || return_value.ec_return_value)
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001092 pr_warning("Get Device Status failed: "
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001093 "0x%x - 0x%x\n", return_value.error_code,
1094 return_value.ec_return_value);
1095 else
1096 *value = !!(return_value.devices & device);
1097
1098 return status;
1099}
1100
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001101static acpi_status get_device_status(u32 *value, u32 cap)
1102{
1103 if (wmi_has_guid(WMID_GUID3)) {
1104 u16 device;
1105
1106 switch (cap) {
1107 case ACER_CAP_WIRELESS:
1108 device = ACER_WMID3_GDS_WIRELESS;
1109 break;
1110 case ACER_CAP_BLUETOOTH:
1111 device = ACER_WMID3_GDS_BLUETOOTH;
1112 break;
1113 case ACER_CAP_THREEG:
1114 device = ACER_WMID3_GDS_THREEG;
1115 break;
1116 default:
1117 return AE_ERROR;
1118 }
1119 return wmid3_get_device_status(value, device);
1120
1121 } else {
1122 return get_u32(value, cap);
1123 }
1124}
1125
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001126/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001127 * Rfkill devices
1128 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001129static void acer_rfkill_update(struct work_struct *ignored);
1130static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1131static void acer_rfkill_update(struct work_struct *ignored)
1132{
1133 u32 state;
1134 acpi_status status;
1135
1136 status = get_u32(&state, ACER_CAP_WIRELESS);
1137 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001138 rfkill_set_sw_state(wireless_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001139
1140 if (has_cap(ACER_CAP_BLUETOOTH)) {
1141 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1142 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001143 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001144 }
1145
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001146 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
1147 status = wmid3_get_device_status(&state,
1148 ACER_WMID3_GDS_THREEG);
1149 if (ACPI_SUCCESS(status))
1150 rfkill_set_sw_state(threeg_rfkill, !state);
1151 }
1152
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001153 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001154}
1155
Johannes Berg19d337d2009-06-02 13:01:37 +02001156static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001157{
1158 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +02001159 u32 cap = (unsigned long)data;
Alan Jenkinsed5c8ef2009-07-19 09:48:28 +01001160 status = set_u32(!blocked, cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001161 if (ACPI_FAILURE(status))
1162 return -ENODEV;
1163 return 0;
1164}
1165
Johannes Berg19d337d2009-06-02 13:01:37 +02001166static const struct rfkill_ops acer_rfkill_ops = {
1167 .set_block = acer_rfkill_set,
1168};
1169
1170static struct rfkill *acer_rfkill_register(struct device *dev,
1171 enum rfkill_type type,
1172 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001173{
1174 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001175 struct rfkill *rfkill_dev;
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001176 u32 state;
1177 acpi_status status;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001178
Johannes Berg19d337d2009-06-02 13:01:37 +02001179 rfkill_dev = rfkill_alloc(name, dev, type,
1180 &acer_rfkill_ops,
1181 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001182 if (!rfkill_dev)
1183 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001184
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001185 status = get_device_status(&state, cap);
1186 if (ACPI_SUCCESS(status))
1187 rfkill_init_sw_state(rfkill_dev, !state);
1188
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001189 err = rfkill_register(rfkill_dev);
1190 if (err) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001191 rfkill_destroy(rfkill_dev);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001192 return ERR_PTR(err);
1193 }
1194 return rfkill_dev;
1195}
1196
1197static int acer_rfkill_init(struct device *dev)
1198{
1199 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1200 "acer-wireless", ACER_CAP_WIRELESS);
1201 if (IS_ERR(wireless_rfkill))
1202 return PTR_ERR(wireless_rfkill);
1203
1204 if (has_cap(ACER_CAP_BLUETOOTH)) {
1205 bluetooth_rfkill = acer_rfkill_register(dev,
1206 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1207 ACER_CAP_BLUETOOTH);
1208 if (IS_ERR(bluetooth_rfkill)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001209 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001210 rfkill_destroy(wireless_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001211 return PTR_ERR(bluetooth_rfkill);
1212 }
1213 }
1214
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001215 if (has_cap(ACER_CAP_THREEG)) {
1216 threeg_rfkill = acer_rfkill_register(dev,
1217 RFKILL_TYPE_WWAN, "acer-threeg",
1218 ACER_CAP_THREEG);
1219 if (IS_ERR(threeg_rfkill)) {
1220 rfkill_unregister(wireless_rfkill);
1221 rfkill_destroy(wireless_rfkill);
1222 rfkill_unregister(bluetooth_rfkill);
1223 rfkill_destroy(bluetooth_rfkill);
1224 return PTR_ERR(threeg_rfkill);
1225 }
1226 }
1227
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001228 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001229
1230 return 0;
1231}
1232
1233static void acer_rfkill_exit(void)
1234{
1235 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001236
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001237 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001238 rfkill_destroy(wireless_rfkill);
1239
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001240 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001241 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001242 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001243 }
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001244
1245 if (has_cap(ACER_CAP_THREEG)) {
1246 rfkill_unregister(threeg_rfkill);
1247 rfkill_destroy(threeg_rfkill);
1248 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001249 return;
1250}
1251
1252/*
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001253 * sysfs interface
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001254 */
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001255static ssize_t show_bool_threeg(struct device *dev,
1256 struct device_attribute *attr, char *buf)
1257{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001258 u32 result; \
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001259 acpi_status status;
1260 if (wmi_has_guid(WMID_GUID3))
1261 status = wmid3_get_device_status(&result,
1262 ACER_WMID3_GDS_THREEG);
1263 else
1264 status = get_u32(&result, ACER_CAP_THREEG);
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001265 if (ACPI_SUCCESS(status))
1266 return sprintf(buf, "%u\n", result);
1267 return sprintf(buf, "Read error\n");
1268}
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001269
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001270static ssize_t set_bool_threeg(struct device *dev,
1271 struct device_attribute *attr, const char *buf, size_t count)
1272{
1273 u32 tmp = simple_strtoul(buf, NULL, 10);
1274 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
1275 if (ACPI_FAILURE(status))
1276 return -EINVAL;
1277 return count;
1278}
Vasiliy Kulikovb80b1682011-02-04 15:23:56 +03001279static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg,
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001280 set_bool_threeg);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001281
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001282static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1283 char *buf)
1284{
1285 switch (interface->type) {
1286 case ACER_AMW0:
1287 return sprintf(buf, "AMW0\n");
1288 case ACER_AMW0_V2:
1289 return sprintf(buf, "AMW0 v2\n");
1290 case ACER_WMID:
1291 return sprintf(buf, "WMID\n");
1292 default:
1293 return sprintf(buf, "Error!\n");
1294 }
1295}
1296
Axel Lin370525d2010-06-30 10:20:23 +08001297static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001298
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001299static void acer_wmi_notify(u32 value, void *context)
1300{
1301 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1302 union acpi_object *obj;
1303 struct event_return_value return_value;
1304 acpi_status status;
1305
1306 status = wmi_get_event_data(value, &response);
1307 if (status != AE_OK) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001308 pr_warning("bad event status 0x%x\n", status);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001309 return;
1310 }
1311
1312 obj = (union acpi_object *)response.pointer;
1313
1314 if (!obj)
1315 return;
1316 if (obj->type != ACPI_TYPE_BUFFER) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001317 pr_warning("Unknown response received %d\n", obj->type);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001318 kfree(obj);
1319 return;
1320 }
1321 if (obj->buffer.length != 8) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001322 pr_warning("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001323 kfree(obj);
1324 return;
1325 }
1326
1327 return_value = *((struct event_return_value *)obj->buffer.pointer);
1328 kfree(obj);
1329
1330 switch (return_value.function) {
1331 case WMID_HOTKEY_EVENT:
1332 if (!sparse_keymap_report_event(acer_wmi_input_dev,
1333 return_value.key_num, 1, true))
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001334 pr_warning("Unknown key number - 0x%x\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001335 return_value.key_num);
1336 break;
1337 default:
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001338 pr_warning("Unknown function number - %d - %d\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001339 return_value.function, return_value.key_num);
1340 break;
1341 }
1342}
1343
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001344static acpi_status
1345wmid3_set_lm_mode(struct lm_input_params *params,
1346 struct lm_return_value *return_value)
1347{
1348 acpi_status status;
1349 union acpi_object *obj;
1350
1351 struct acpi_buffer input = { sizeof(struct lm_input_params), params };
1352 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1353
1354 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1355 if (ACPI_FAILURE(status))
1356 return status;
1357
1358 obj = output.pointer;
1359
1360 if (!obj)
1361 return AE_ERROR;
1362 else if (obj->type != ACPI_TYPE_BUFFER) {
1363 kfree(obj);
1364 return AE_ERROR;
1365 }
1366 if (obj->buffer.length != 4) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001367 pr_warning("Unknown buffer length %d\n", obj->buffer.length);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001368 kfree(obj);
1369 return AE_ERROR;
1370 }
1371
1372 *return_value = *((struct lm_return_value *)obj->buffer.pointer);
1373 kfree(obj);
1374
1375 return status;
1376}
1377
1378static int acer_wmi_enable_ec_raw(void)
1379{
1380 struct lm_return_value return_value;
1381 acpi_status status;
1382 struct lm_input_params params = {
1383 .function_num = 0x1,
1384 .commun_devices = 0xFFFF,
1385 .devices = 0xFFFF,
1386 .lm_status = 0x00, /* Launch Manager Deactive */
1387 };
1388
1389 status = wmid3_set_lm_mode(&params, &return_value);
1390
1391 if (return_value.error_code || return_value.ec_return_value)
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001392 pr_warning("Enabling EC raw mode failed: "
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001393 "0x%x - 0x%x\n", return_value.error_code,
1394 return_value.ec_return_value);
1395 else
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001396 pr_info("Enabled EC raw mode");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001397
1398 return status;
1399}
1400
1401static int acer_wmi_enable_lm(void)
1402{
1403 struct lm_return_value return_value;
1404 acpi_status status;
1405 struct lm_input_params params = {
1406 .function_num = 0x1,
1407 .commun_devices = 0xFFFF,
1408 .devices = 0xFFFF,
1409 .lm_status = 0x01, /* Launch Manager Active */
1410 };
1411
1412 status = wmid3_set_lm_mode(&params, &return_value);
1413
1414 if (return_value.error_code || return_value.ec_return_value)
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001415 pr_warning("Enabling Launch Manager failed: "
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001416 "0x%x - 0x%x\n", return_value.error_code,
1417 return_value.ec_return_value);
1418
1419 return status;
1420}
1421
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001422static int __init acer_wmi_input_setup(void)
1423{
1424 acpi_status status;
1425 int err;
1426
1427 acer_wmi_input_dev = input_allocate_device();
1428 if (!acer_wmi_input_dev)
1429 return -ENOMEM;
1430
1431 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1432 acer_wmi_input_dev->phys = "wmi/input0";
1433 acer_wmi_input_dev->id.bustype = BUS_HOST;
1434
1435 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1436 if (err)
1437 goto err_free_dev;
1438
1439 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1440 acer_wmi_notify, NULL);
1441 if (ACPI_FAILURE(status)) {
1442 err = -EIO;
1443 goto err_free_keymap;
1444 }
1445
1446 err = input_register_device(acer_wmi_input_dev);
1447 if (err)
1448 goto err_uninstall_notifier;
1449
1450 return 0;
1451
1452err_uninstall_notifier:
1453 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1454err_free_keymap:
1455 sparse_keymap_free(acer_wmi_input_dev);
1456err_free_dev:
1457 input_free_device(acer_wmi_input_dev);
1458 return err;
1459}
1460
1461static void acer_wmi_input_destroy(void)
1462{
1463 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1464 sparse_keymap_free(acer_wmi_input_dev);
1465 input_unregister_device(acer_wmi_input_dev);
1466}
1467
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001468/*
Carlos Corbacho81143522008-06-21 09:09:53 +01001469 * debugfs functions
1470 */
1471static u32 get_wmid_devices(void)
1472{
1473 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1474 union acpi_object *obj;
1475 acpi_status status;
Axel Lin66904862010-07-20 15:19:52 -07001476 u32 devices = 0;
Carlos Corbacho81143522008-06-21 09:09:53 +01001477
1478 status = wmi_query_block(WMID_GUID2, 1, &out);
1479 if (ACPI_FAILURE(status))
1480 return 0;
1481
1482 obj = (union acpi_object *) out.pointer;
1483 if (obj && obj->type == ACPI_TYPE_BUFFER &&
1484 obj->buffer.length == sizeof(u32)) {
Axel Lin66904862010-07-20 15:19:52 -07001485 devices = *((u32 *) obj->buffer.pointer);
Carlos Corbacho81143522008-06-21 09:09:53 +01001486 }
Axel Lin66904862010-07-20 15:19:52 -07001487
1488 kfree(out.pointer);
1489 return devices;
Carlos Corbacho81143522008-06-21 09:09:53 +01001490}
1491
1492/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001493 * Platform device
1494 */
1495static int __devinit acer_platform_probe(struct platform_device *device)
1496{
1497 int err;
1498
1499 if (has_cap(ACER_CAP_MAILLED)) {
1500 err = acer_led_init(&device->dev);
1501 if (err)
1502 goto error_mailled;
1503 }
1504
1505 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1506 err = acer_backlight_init(&device->dev);
1507 if (err)
1508 goto error_brightness;
1509 }
1510
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001511 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01001512 if (err)
1513 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001514
1515 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001516
Andy Whitcroft350e3292009-04-04 09:33:34 +01001517error_rfkill:
1518 if (has_cap(ACER_CAP_BRIGHTNESS))
1519 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001520error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01001521 if (has_cap(ACER_CAP_MAILLED))
1522 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001523error_mailled:
1524 return err;
1525}
1526
1527static int acer_platform_remove(struct platform_device *device)
1528{
1529 if (has_cap(ACER_CAP_MAILLED))
1530 acer_led_exit();
1531 if (has_cap(ACER_CAP_BRIGHTNESS))
1532 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001533
1534 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001535 return 0;
1536}
1537
1538static int acer_platform_suspend(struct platform_device *dev,
1539pm_message_t state)
1540{
1541 u32 value;
1542 struct acer_data *data = &interface->data;
1543
1544 if (!data)
1545 return -ENOMEM;
1546
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001547 if (has_cap(ACER_CAP_MAILLED)) {
1548 get_u32(&value, ACER_CAP_MAILLED);
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001549 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001550 data->mailled = value;
1551 }
1552
1553 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1554 get_u32(&value, ACER_CAP_BRIGHTNESS);
1555 data->brightness = value;
1556 }
1557
1558 return 0;
1559}
1560
1561static int acer_platform_resume(struct platform_device *device)
1562{
1563 struct acer_data *data = &interface->data;
1564
1565 if (!data)
1566 return -ENOMEM;
1567
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001568 if (has_cap(ACER_CAP_MAILLED))
1569 set_u32(data->mailled, ACER_CAP_MAILLED);
1570
1571 if (has_cap(ACER_CAP_BRIGHTNESS))
1572 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
1573
1574 return 0;
1575}
1576
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001577static void acer_platform_shutdown(struct platform_device *device)
1578{
1579 struct acer_data *data = &interface->data;
1580
1581 if (!data)
1582 return;
1583
1584 if (has_cap(ACER_CAP_MAILLED))
1585 set_u32(LED_OFF, ACER_CAP_MAILLED);
1586}
1587
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001588static struct platform_driver acer_platform_driver = {
1589 .driver = {
1590 .name = "acer-wmi",
1591 .owner = THIS_MODULE,
1592 },
1593 .probe = acer_platform_probe,
1594 .remove = acer_platform_remove,
1595 .suspend = acer_platform_suspend,
1596 .resume = acer_platform_resume,
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001597 .shutdown = acer_platform_shutdown,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001598};
1599
1600static struct platform_device *acer_platform_device;
1601
1602static int remove_sysfs(struct platform_device *device)
1603{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001604 if (has_cap(ACER_CAP_THREEG))
1605 device_remove_file(&device->dev, &dev_attr_threeg);
1606
1607 device_remove_file(&device->dev, &dev_attr_interface);
1608
1609 return 0;
1610}
1611
1612static int create_sysfs(void)
1613{
1614 int retval = -ENOMEM;
1615
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001616 if (has_cap(ACER_CAP_THREEG)) {
1617 retval = device_create_file(&acer_platform_device->dev,
1618 &dev_attr_threeg);
1619 if (retval)
1620 goto error_sysfs;
1621 }
1622
1623 retval = device_create_file(&acer_platform_device->dev,
1624 &dev_attr_interface);
1625 if (retval)
1626 goto error_sysfs;
1627
1628 return 0;
1629
1630error_sysfs:
1631 remove_sysfs(acer_platform_device);
1632 return retval;
1633}
1634
Carlos Corbacho81143522008-06-21 09:09:53 +01001635static void remove_debugfs(void)
1636{
1637 debugfs_remove(interface->debug.devices);
1638 debugfs_remove(interface->debug.root);
1639}
1640
1641static int create_debugfs(void)
1642{
1643 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
1644 if (!interface->debug.root) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001645 pr_err("Failed to create debugfs directory");
Carlos Corbacho81143522008-06-21 09:09:53 +01001646 return -ENOMEM;
1647 }
1648
1649 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
1650 interface->debug.root,
1651 &interface->debug.wmid_devices);
1652 if (!interface->debug.devices)
1653 goto error_debugfs;
1654
1655 return 0;
1656
1657error_debugfs:
Russ Dill39dbbb42008-09-02 14:35:40 -07001658 remove_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01001659 return -ENOMEM;
1660}
1661
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001662static int __init acer_wmi_init(void)
1663{
1664 int err;
1665
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001666 pr_info("Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001667
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001668 if (dmi_check_system(acer_blacklist)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001669 pr_info("Blacklisted hardware detected - not loading\n");
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001670 return -ENODEV;
1671 }
1672
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01001673 find_quirks();
1674
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001675 /*
1676 * Detect which ACPI-WMI interface we're using.
1677 */
1678 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1679 interface = &AMW0_V2_interface;
1680
1681 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1682 interface = &wmid_interface;
1683
1684 if (wmi_has_guid(WMID_GUID2) && interface) {
1685 if (ACPI_FAILURE(WMID_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001686 pr_err("Unable to detect available WMID devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001687 return -ENODEV;
1688 }
1689 } else if (!wmi_has_guid(WMID_GUID2) && interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001690 pr_err("No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001691 return -ENODEV;
1692 }
1693
1694 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
1695 interface = &AMW0_interface;
1696
1697 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001698 pr_err("Unable to detect available AMW0 devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001699 return -ENODEV;
1700 }
1701 }
1702
Carlos Corbacho9b963c42008-02-24 13:34:29 +00001703 if (wmi_has_guid(AMW0_GUID1))
1704 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001705
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001706 if (!interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001707 pr_err("No or unsupported WMI interface, unable to load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001708 return -ENODEV;
1709 }
1710
Arjan van de Ven83097ac2008-08-23 21:45:21 -07001711 set_quirks();
1712
Michael Spang1ba869e2009-03-12 14:31:34 -07001713 if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS)) {
Thomas Renningerfebf2d92008-08-01 17:37:56 +02001714 interface->capability &= ~ACER_CAP_BRIGHTNESS;
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001715 pr_info("Brightness must be controlled by "
Thomas Renningerfebf2d92008-08-01 17:37:56 +02001716 "generic video driver\n");
1717 }
1718
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001719 if (wmi_has_guid(WMID_GUID3)) {
1720 if (ec_raw_mode) {
1721 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001722 pr_err("Cannot enable EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001723 return -ENODEV;
1724 }
1725 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001726 pr_err("Cannot enable Launch Manager mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001727 return -ENODEV;
1728 }
1729 } else if (ec_raw_mode) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001730 pr_info("No WMID EC raw mode enable method\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001731 }
1732
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001733 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
1734 err = acer_wmi_input_setup();
1735 if (err)
1736 return err;
1737 }
1738
Axel Lin1c796322010-06-22 16:17:38 +08001739 err = platform_driver_register(&acer_platform_driver);
1740 if (err) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001741 pr_err("Unable to register platform driver.\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001742 goto error_platform_register;
1743 }
Axel Lin1c796322010-06-22 16:17:38 +08001744
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001745 acer_platform_device = platform_device_alloc("acer-wmi", -1);
Axel Lin1c796322010-06-22 16:17:38 +08001746 if (!acer_platform_device) {
1747 err = -ENOMEM;
1748 goto error_device_alloc;
1749 }
1750
1751 err = platform_device_add(acer_platform_device);
1752 if (err)
1753 goto error_device_add;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001754
1755 err = create_sysfs();
1756 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08001757 goto error_create_sys;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001758
Carlos Corbacho81143522008-06-21 09:09:53 +01001759 if (wmi_has_guid(WMID_GUID2)) {
1760 interface->debug.wmid_devices = get_wmid_devices();
1761 err = create_debugfs();
1762 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08001763 goto error_create_debugfs;
Carlos Corbacho81143522008-06-21 09:09:53 +01001764 }
1765
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001766 /* Override any initial settings with values from the commandline */
1767 acer_commandline_init();
1768
1769 return 0;
1770
Axel Lin1c796322010-06-22 16:17:38 +08001771error_create_debugfs:
1772 remove_sysfs(acer_platform_device);
1773error_create_sys:
1774 platform_device_del(acer_platform_device);
1775error_device_add:
1776 platform_device_put(acer_platform_device);
1777error_device_alloc:
1778 platform_driver_unregister(&acer_platform_driver);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001779error_platform_register:
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001780 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1781 acer_wmi_input_destroy();
1782
Axel Lin1c796322010-06-22 16:17:38 +08001783 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001784}
1785
1786static void __exit acer_wmi_exit(void)
1787{
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001788 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1789 acer_wmi_input_destroy();
1790
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001791 remove_sysfs(acer_platform_device);
Russ Dill39dbbb42008-09-02 14:35:40 -07001792 remove_debugfs();
Axel Lin97ba0af2010-06-03 15:18:03 +08001793 platform_device_unregister(acer_platform_device);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001794 platform_driver_unregister(&acer_platform_driver);
1795
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001796 pr_info("Acer Laptop WMI Extras unloaded\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001797 return;
1798}
1799
1800module_init(acer_wmi_init);
1801module_exit(acer_wmi_exit);