blob: 5ea6c3477d17da4f17f3f07059329fdff1212da3 [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;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +0800220static bool rfkill_inited;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100221
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000222/* Each low-level interface must define at least some of the following */
223struct wmi_interface {
224 /* The WMI device type */
225 u32 type;
226
227 /* The capabilities this interface provides */
228 u32 capability;
229
230 /* Private data for the current interface */
231 struct acer_data data;
Carlos Corbacho81143522008-06-21 09:09:53 +0100232
233 /* debugfs entries associated with this interface */
234 struct acer_debug debug;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000235};
236
237/* The static interface pointer, points to the currently detected interface */
238static struct wmi_interface *interface;
239
240/*
241 * Embedded Controller quirks
242 * Some laptops require us to directly access the EC to either enable or query
243 * features that are not available through WMI.
244 */
245
246struct quirk_entry {
247 u8 wireless;
248 u8 mailled;
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100249 s8 brightness;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000250 u8 bluetooth;
251};
252
253static struct quirk_entry *quirks;
254
255static void set_quirks(void)
256{
Arjan van de Ven83097ac2008-08-23 21:45:21 -0700257 if (!interface)
258 return;
259
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000260 if (quirks->mailled)
261 interface->capability |= ACER_CAP_MAILLED;
262
263 if (quirks->brightness)
264 interface->capability |= ACER_CAP_BRIGHTNESS;
265}
266
267static int dmi_matched(const struct dmi_system_id *dmi)
268{
269 quirks = dmi->driver_data;
Axel Lind53bf0f2010-06-30 13:32:16 +0800270 return 1;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000271}
272
273static struct quirk_entry quirk_unknown = {
274};
275
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100276static struct quirk_entry quirk_acer_aspire_1520 = {
277 .brightness = -1,
278};
279
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000280static struct quirk_entry quirk_acer_travelmate_2490 = {
281 .mailled = 1,
282};
283
284/* This AMW0 laptop has no bluetooth */
285static struct quirk_entry quirk_medion_md_98300 = {
286 .wireless = 1,
287};
288
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100289static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
290 .wireless = 2,
291};
292
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100293/* The Aspire One has a dummy ACPI-WMI interface - disable it */
294static struct dmi_system_id __devinitdata acer_blacklist[] = {
295 {
296 .ident = "Acer Aspire One (SSD)",
297 .matches = {
298 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
299 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
300 },
301 },
302 {
303 .ident = "Acer Aspire One (HDD)",
304 .matches = {
305 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
306 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
307 },
308 },
309 {}
310};
311
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000312static struct dmi_system_id acer_quirks[] = {
313 {
314 .callback = dmi_matched,
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100315 .ident = "Acer Aspire 1360",
316 .matches = {
317 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
318 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
319 },
320 .driver_data = &quirk_acer_aspire_1520,
321 },
322 {
323 .callback = dmi_matched,
324 .ident = "Acer Aspire 1520",
325 .matches = {
326 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
327 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
328 },
329 .driver_data = &quirk_acer_aspire_1520,
330 },
331 {
332 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000333 .ident = "Acer Aspire 3100",
334 .matches = {
335 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
336 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
337 },
338 .driver_data = &quirk_acer_travelmate_2490,
339 },
340 {
341 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000342 .ident = "Acer Aspire 3610",
343 .matches = {
344 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
345 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
346 },
347 .driver_data = &quirk_acer_travelmate_2490,
348 },
349 {
350 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000351 .ident = "Acer Aspire 5100",
352 .matches = {
353 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
354 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
355 },
356 .driver_data = &quirk_acer_travelmate_2490,
357 },
358 {
359 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000360 .ident = "Acer Aspire 5610",
361 .matches = {
362 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
363 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
364 },
365 .driver_data = &quirk_acer_travelmate_2490,
366 },
367 {
368 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000369 .ident = "Acer Aspire 5630",
370 .matches = {
371 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
372 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
373 },
374 .driver_data = &quirk_acer_travelmate_2490,
375 },
376 {
377 .callback = dmi_matched,
378 .ident = "Acer Aspire 5650",
379 .matches = {
380 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
381 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
382 },
383 .driver_data = &quirk_acer_travelmate_2490,
384 },
385 {
386 .callback = dmi_matched,
387 .ident = "Acer Aspire 5680",
388 .matches = {
389 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
390 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
391 },
392 .driver_data = &quirk_acer_travelmate_2490,
393 },
394 {
395 .callback = dmi_matched,
396 .ident = "Acer Aspire 9110",
397 .matches = {
398 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
399 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
400 },
401 .driver_data = &quirk_acer_travelmate_2490,
402 },
403 {
404 .callback = dmi_matched,
405 .ident = "Acer TravelMate 2490",
406 .matches = {
407 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
408 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
409 },
410 .driver_data = &quirk_acer_travelmate_2490,
411 },
412 {
413 .callback = dmi_matched,
Carlos Corbacho262ee352008-02-16 00:02:56 +0000414 .ident = "Acer TravelMate 4200",
415 .matches = {
416 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
417 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
418 },
419 .driver_data = &quirk_acer_travelmate_2490,
420 },
421 {
422 .callback = dmi_matched,
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100423 .ident = "Fujitsu Siemens Amilo Li 1718",
424 .matches = {
425 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
426 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
427 },
428 .driver_data = &quirk_fujitsu_amilo_li_1718,
429 },
430 {
431 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000432 .ident = "Medion MD 98300",
433 .matches = {
434 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
435 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
436 },
437 .driver_data = &quirk_medion_md_98300,
438 },
439 {}
440};
441
442/* Find which quirks are needed for a particular vendor/ model pair */
443static void find_quirks(void)
444{
445 if (!force_series) {
446 dmi_check_system(acer_quirks);
447 } else if (force_series == 2490) {
448 quirks = &quirk_acer_travelmate_2490;
449 }
450
451 if (quirks == NULL)
452 quirks = &quirk_unknown;
453
454 set_quirks();
455}
456
457/*
458 * General interface convenience methods
459 */
460
461static bool has_cap(u32 cap)
462{
463 if ((interface->capability & cap) != 0)
464 return 1;
465
466 return 0;
467}
468
469/*
470 * AMW0 (V1) interface
471 */
472struct wmab_args {
473 u32 eax;
474 u32 ebx;
475 u32 ecx;
476 u32 edx;
477};
478
479struct wmab_ret {
480 u32 eax;
481 u32 ebx;
482 u32 ecx;
483 u32 edx;
484 u32 eex;
485};
486
487static acpi_status wmab_execute(struct wmab_args *regbuf,
488struct acpi_buffer *result)
489{
490 struct acpi_buffer input;
491 acpi_status status;
492 input.length = sizeof(struct wmab_args);
493 input.pointer = (u8 *)regbuf;
494
495 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
496
497 return status;
498}
499
500static acpi_status AMW0_get_u32(u32 *value, u32 cap,
501struct wmi_interface *iface)
502{
503 int err;
504 u8 result;
505
506 switch (cap) {
507 case ACER_CAP_MAILLED:
508 switch (quirks->mailled) {
509 default:
510 err = ec_read(0xA, &result);
511 if (err)
512 return AE_ERROR;
513 *value = (result >> 7) & 0x1;
514 return AE_OK;
515 }
516 break;
517 case ACER_CAP_WIRELESS:
518 switch (quirks->wireless) {
519 case 1:
520 err = ec_read(0x7B, &result);
521 if (err)
522 return AE_ERROR;
523 *value = result & 0x1;
524 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100525 case 2:
526 err = ec_read(0x71, &result);
527 if (err)
528 return AE_ERROR;
529 *value = result & 0x1;
530 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000531 default:
532 err = ec_read(0xA, &result);
533 if (err)
534 return AE_ERROR;
535 *value = (result >> 2) & 0x1;
536 return AE_OK;
537 }
538 break;
539 case ACER_CAP_BLUETOOTH:
540 switch (quirks->bluetooth) {
541 default:
542 err = ec_read(0xA, &result);
543 if (err)
544 return AE_ERROR;
545 *value = (result >> 4) & 0x1;
546 return AE_OK;
547 }
548 break;
549 case ACER_CAP_BRIGHTNESS:
550 switch (quirks->brightness) {
551 default:
552 err = ec_read(0x83, &result);
553 if (err)
554 return AE_ERROR;
555 *value = result;
556 return AE_OK;
557 }
558 break;
559 default:
Lin Ming08237972008-08-08 11:57:11 +0800560 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000561 }
562 return AE_OK;
563}
564
565static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
566{
567 struct wmab_args args;
568
569 args.eax = ACER_AMW0_WRITE;
570 args.ebx = value ? (1<<8) : 0;
571 args.ecx = args.edx = 0;
572
573 switch (cap) {
574 case ACER_CAP_MAILLED:
575 if (value > 1)
576 return AE_BAD_PARAMETER;
577 args.ebx |= ACER_AMW0_MAILLED_MASK;
578 break;
579 case ACER_CAP_WIRELESS:
580 if (value > 1)
581 return AE_BAD_PARAMETER;
582 args.ebx |= ACER_AMW0_WIRELESS_MASK;
583 break;
584 case ACER_CAP_BLUETOOTH:
585 if (value > 1)
586 return AE_BAD_PARAMETER;
587 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
588 break;
589 case ACER_CAP_BRIGHTNESS:
590 if (value > max_brightness)
591 return AE_BAD_PARAMETER;
592 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000593 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000594 return ec_write(0x83, value);
595 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000596 }
597 default:
Lin Ming08237972008-08-08 11:57:11 +0800598 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000599 }
600
601 /* Actually do the set */
602 return wmab_execute(&args, NULL);
603}
604
605static acpi_status AMW0_find_mailled(void)
606{
607 struct wmab_args args;
608 struct wmab_ret ret;
609 acpi_status status = AE_OK;
610 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
611 union acpi_object *obj;
612
613 args.eax = 0x86;
614 args.ebx = args.ecx = args.edx = 0;
615
616 status = wmab_execute(&args, &out);
617 if (ACPI_FAILURE(status))
618 return status;
619
620 obj = (union acpi_object *) out.pointer;
621 if (obj && obj->type == ACPI_TYPE_BUFFER &&
622 obj->buffer.length == sizeof(struct wmab_ret)) {
623 ret = *((struct wmab_ret *) obj->buffer.pointer);
624 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700625 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000626 return AE_ERROR;
627 }
628
629 if (ret.eex & 0x1)
630 interface->capability |= ACER_CAP_MAILLED;
631
632 kfree(out.pointer);
633
634 return AE_OK;
635}
636
637static acpi_status AMW0_set_capabilities(void)
638{
639 struct wmab_args args;
640 struct wmab_ret ret;
Axel Lin7677fbd2010-07-20 15:19:53 -0700641 acpi_status status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000642 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
643 union acpi_object *obj;
644
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100645 /*
646 * On laptops with this strange GUID (non Acer), normal probing doesn't
647 * work.
648 */
649 if (wmi_has_guid(AMW0_GUID2)) {
650 interface->capability |= ACER_CAP_WIRELESS;
651 return AE_OK;
652 }
653
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000654 args.eax = ACER_AMW0_WRITE;
655 args.ecx = args.edx = 0;
656
657 args.ebx = 0xa2 << 8;
658 args.ebx |= ACER_AMW0_WIRELESS_MASK;
659
660 status = wmab_execute(&args, &out);
661 if (ACPI_FAILURE(status))
662 return status;
663
Axel Lin7677fbd2010-07-20 15:19:53 -0700664 obj = out.pointer;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000665 if (obj && obj->type == ACPI_TYPE_BUFFER &&
666 obj->buffer.length == sizeof(struct wmab_ret)) {
667 ret = *((struct wmab_ret *) obj->buffer.pointer);
668 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700669 status = AE_ERROR;
670 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000671 }
672
673 if (ret.eax & 0x1)
674 interface->capability |= ACER_CAP_WIRELESS;
675
676 args.ebx = 2 << 8;
677 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
678
Axel Lin7677fbd2010-07-20 15:19:53 -0700679 /*
680 * It's ok to use existing buffer for next wmab_execute call.
681 * But we need to kfree(out.pointer) if next wmab_execute fail.
682 */
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000683 status = wmab_execute(&args, &out);
684 if (ACPI_FAILURE(status))
Axel Lin7677fbd2010-07-20 15:19:53 -0700685 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000686
687 obj = (union acpi_object *) out.pointer;
688 if (obj && obj->type == ACPI_TYPE_BUFFER
689 && obj->buffer.length == sizeof(struct wmab_ret)) {
690 ret = *((struct wmab_ret *) obj->buffer.pointer);
691 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700692 status = AE_ERROR;
693 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000694 }
695
696 if (ret.eax & 0x1)
697 interface->capability |= ACER_CAP_BLUETOOTH;
698
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000699 /*
700 * This appears to be safe to enable, since all Wistron based laptops
701 * appear to use the same EC register for brightness, even if they
702 * differ for wireless, etc
703 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100704 if (quirks->brightness >= 0)
705 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000706
Axel Lin7677fbd2010-07-20 15:19:53 -0700707 status = AE_OK;
708out:
709 kfree(out.pointer);
710 return status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000711}
712
713static struct wmi_interface AMW0_interface = {
714 .type = ACER_AMW0,
715};
716
717static struct wmi_interface AMW0_V2_interface = {
718 .type = ACER_AMW0_V2,
719};
720
721/*
722 * New interface (The WMID interface)
723 */
724static acpi_status
725WMI_execute_u32(u32 method_id, u32 in, u32 *out)
726{
727 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
728 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
729 union acpi_object *obj;
730 u32 tmp;
731 acpi_status status;
732
733 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
734
735 if (ACPI_FAILURE(status))
736 return status;
737
738 obj = (union acpi_object *) result.pointer;
739 if (obj && obj->type == ACPI_TYPE_BUFFER &&
740 obj->buffer.length == sizeof(u32)) {
741 tmp = *((u32 *) obj->buffer.pointer);
742 } else {
743 tmp = 0;
744 }
745
746 if (out)
747 *out = tmp;
748
749 kfree(result.pointer);
750
751 return status;
752}
753
754static acpi_status WMID_get_u32(u32 *value, u32 cap,
755struct wmi_interface *iface)
756{
757 acpi_status status;
758 u8 tmp;
759 u32 result, method_id = 0;
760
761 switch (cap) {
762 case ACER_CAP_WIRELESS:
763 method_id = ACER_WMID_GET_WIRELESS_METHODID;
764 break;
765 case ACER_CAP_BLUETOOTH:
766 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
767 break;
768 case ACER_CAP_BRIGHTNESS:
769 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
770 break;
771 case ACER_CAP_THREEG:
772 method_id = ACER_WMID_GET_THREEG_METHODID;
773 break;
774 case ACER_CAP_MAILLED:
775 if (quirks->mailled == 1) {
776 ec_read(0x9f, &tmp);
777 *value = tmp & 0x1;
778 return 0;
779 }
780 default:
Lin Ming08237972008-08-08 11:57:11 +0800781 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000782 }
783 status = WMI_execute_u32(method_id, 0, &result);
784
785 if (ACPI_SUCCESS(status))
786 *value = (u8)result;
787
788 return status;
789}
790
791static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
792{
793 u32 method_id = 0;
794 char param;
795
796 switch (cap) {
797 case ACER_CAP_BRIGHTNESS:
798 if (value > max_brightness)
799 return AE_BAD_PARAMETER;
800 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
801 break;
802 case ACER_CAP_WIRELESS:
803 if (value > 1)
804 return AE_BAD_PARAMETER;
805 method_id = ACER_WMID_SET_WIRELESS_METHODID;
806 break;
807 case ACER_CAP_BLUETOOTH:
808 if (value > 1)
809 return AE_BAD_PARAMETER;
810 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
811 break;
812 case ACER_CAP_THREEG:
813 if (value > 1)
814 return AE_BAD_PARAMETER;
815 method_id = ACER_WMID_SET_THREEG_METHODID;
816 break;
817 case ACER_CAP_MAILLED:
818 if (value > 1)
819 return AE_BAD_PARAMETER;
820 if (quirks->mailled == 1) {
821 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700822 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000823 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700824 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000825 return 0;
826 }
827 break;
828 default:
Lin Ming08237972008-08-08 11:57:11 +0800829 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000830 }
831 return WMI_execute_u32(method_id, (u32)value, NULL);
832}
833
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800834static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
835{
836 struct hotkey_function_type_aa *type_aa;
837
838 /* We are looking for OEM-specific Type AAh */
839 if (header->type != 0xAA)
840 return;
841
842 has_type_aa = true;
843 type_aa = (struct hotkey_function_type_aa *) header;
844
Lee, Chun-Yicae15702011-03-16 18:52:36 +0800845 pr_info("Function bitmap for Communication Button: 0x%x\n",
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800846 type_aa->commun_func_bitmap);
847
848 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
849 interface->capability |= ACER_CAP_WIRELESS;
850 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
851 interface->capability |= ACER_CAP_THREEG;
852 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
853 interface->capability |= ACER_CAP_BLUETOOTH;
854}
855
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000856static acpi_status WMID_set_capabilities(void)
857{
858 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
859 union acpi_object *obj;
860 acpi_status status;
861 u32 devices;
862
863 status = wmi_query_block(WMID_GUID2, 1, &out);
864 if (ACPI_FAILURE(status))
865 return status;
866
867 obj = (union acpi_object *) out.pointer;
868 if (obj && obj->type == ACPI_TYPE_BUFFER &&
869 obj->buffer.length == sizeof(u32)) {
870 devices = *((u32 *) obj->buffer.pointer);
871 } else {
Axel Lin66904862010-07-20 15:19:52 -0700872 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000873 return AE_ERROR;
874 }
875
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800876 dmi_walk(type_aa_dmi_decode, NULL);
877 if (!has_type_aa) {
878 interface->capability |= ACER_CAP_WIRELESS;
879 interface->capability |= ACER_CAP_THREEG;
880 if (devices & 0x10)
881 interface->capability |= ACER_CAP_BLUETOOTH;
882 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000883
884 /* WMID always provides brightness methods */
885 interface->capability |= ACER_CAP_BRIGHTNESS;
886
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000887 if (!(devices & 0x20))
888 max_brightness = 0x9;
889
Axel Lin66904862010-07-20 15:19:52 -0700890 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000891 return status;
892}
893
894static struct wmi_interface wmid_interface = {
895 .type = ACER_WMID,
896};
897
898/*
899 * Generic Device (interface-independent)
900 */
901
902static acpi_status get_u32(u32 *value, u32 cap)
903{
Lin Ming08237972008-08-08 11:57:11 +0800904 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000905
906 switch (interface->type) {
907 case ACER_AMW0:
908 status = AMW0_get_u32(value, cap, interface);
909 break;
910 case ACER_AMW0_V2:
911 if (cap == ACER_CAP_MAILLED) {
912 status = AMW0_get_u32(value, cap, interface);
913 break;
914 }
915 case ACER_WMID:
916 status = WMID_get_u32(value, cap, interface);
917 break;
918 }
919
920 return status;
921}
922
923static acpi_status set_u32(u32 value, u32 cap)
924{
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100925 acpi_status status;
926
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000927 if (interface->capability & cap) {
928 switch (interface->type) {
929 case ACER_AMW0:
930 return AMW0_set_u32(value, cap, interface);
931 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100932 if (cap == ACER_CAP_MAILLED)
933 return AMW0_set_u32(value, cap, interface);
934
935 /*
936 * On some models, some WMID methods don't toggle
937 * properly. For those cases, we want to run the AMW0
938 * method afterwards to be certain we've really toggled
939 * the device state.
940 */
941 if (cap == ACER_CAP_WIRELESS ||
942 cap == ACER_CAP_BLUETOOTH) {
943 status = WMID_set_u32(value, cap, interface);
944 if (ACPI_FAILURE(status))
945 return status;
946
947 return AMW0_set_u32(value, cap, interface);
948 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000949 case ACER_WMID:
950 return WMID_set_u32(value, cap, interface);
951 default:
952 return AE_BAD_PARAMETER;
953 }
954 }
955 return AE_BAD_PARAMETER;
956}
957
958static void __init acer_commandline_init(void)
959{
960 /*
961 * These will all fail silently if the value given is invalid, or the
962 * capability isn't available on the given interface
963 */
964 set_u32(mailled, ACER_CAP_MAILLED);
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800965 if (!has_type_aa)
966 set_u32(threeg, ACER_CAP_THREEG);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000967 set_u32(brightness, ACER_CAP_BRIGHTNESS);
968}
969
970/*
971 * LED device (Mail LED only, no other LEDs known yet)
972 */
973static void mail_led_set(struct led_classdev *led_cdev,
974enum led_brightness value)
975{
976 set_u32(value, ACER_CAP_MAILLED);
977}
978
979static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +0000980 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000981 .brightness_set = mail_led_set,
982};
983
Sam Ravnborg7560e382008-02-17 13:22:54 +0100984static int __devinit acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000985{
986 return led_classdev_register(dev, &mail_led);
987}
988
989static void acer_led_exit(void)
990{
Pali Rohár9a0b74f2011-02-26 21:18:58 +0100991 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000992 led_classdev_unregister(&mail_led);
993}
994
995/*
996 * Backlight device
997 */
998static struct backlight_device *acer_backlight_device;
999
1000static int read_brightness(struct backlight_device *bd)
1001{
1002 u32 value;
1003 get_u32(&value, ACER_CAP_BRIGHTNESS);
1004 return value;
1005}
1006
1007static int update_bl_status(struct backlight_device *bd)
1008{
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001009 int intensity = bd->props.brightness;
1010
1011 if (bd->props.power != FB_BLANK_UNBLANK)
1012 intensity = 0;
1013 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1014 intensity = 0;
1015
1016 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1017
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001018 return 0;
1019}
1020
Lionel Debrouxacc24722010-11-16 14:14:02 +01001021static const struct backlight_ops acer_bl_ops = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001022 .get_brightness = read_brightness,
1023 .update_status = update_bl_status,
1024};
1025
Sam Ravnborg7560e382008-02-17 13:22:54 +01001026static int __devinit acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001027{
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001028 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001029 struct backlight_device *bd;
1030
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001031 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001032 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001033 props.max_brightness = max_brightness;
1034 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1035 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001036 if (IS_ERR(bd)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001037 pr_err("Could not register Acer backlight device\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001038 acer_backlight_device = NULL;
1039 return PTR_ERR(bd);
1040 }
1041
1042 acer_backlight_device = bd;
1043
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001044 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +00001045 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001046 backlight_update_status(bd);
1047 return 0;
1048}
1049
Sam Ravnborg7560e382008-02-17 13:22:54 +01001050static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001051{
1052 backlight_device_unregister(acer_backlight_device);
1053}
1054
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001055static 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_input_param params = {
1061 .function_num = 0x1,
1062 .hotkey_number = 0x01,
1063 .devices = device,
1064 };
1065 struct acpi_buffer input = {
1066 sizeof(struct wmid3_gds_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) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001084 pr_warning("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001085 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)
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001093 pr_warning("Get Device Status failed: "
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001094 "0x%x - 0x%x\n", return_value.error_code,
1095 return_value.ec_return_value);
1096 else
1097 *value = !!(return_value.devices & device);
1098
1099 return status;
1100}
1101
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001102static acpi_status get_device_status(u32 *value, u32 cap)
1103{
1104 if (wmi_has_guid(WMID_GUID3)) {
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 } else {
1123 return get_u32(value, cap);
1124 }
1125}
1126
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001127/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001128 * Rfkill devices
1129 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001130static void acer_rfkill_update(struct work_struct *ignored);
1131static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1132static void acer_rfkill_update(struct work_struct *ignored)
1133{
1134 u32 state;
1135 acpi_status status;
1136
1137 status = get_u32(&state, ACER_CAP_WIRELESS);
1138 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001139 rfkill_set_sw_state(wireless_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001140
1141 if (has_cap(ACER_CAP_BLUETOOTH)) {
1142 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1143 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001144 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001145 }
1146
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001147 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
1148 status = wmid3_get_device_status(&state,
1149 ACER_WMID3_GDS_THREEG);
1150 if (ACPI_SUCCESS(status))
1151 rfkill_set_sw_state(threeg_rfkill, !state);
1152 }
1153
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001154 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001155}
1156
Johannes Berg19d337d2009-06-02 13:01:37 +02001157static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001158{
1159 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +02001160 u32 cap = (unsigned long)data;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001161
1162 if (rfkill_inited) {
1163 status = set_u32(!blocked, cap);
1164 if (ACPI_FAILURE(status))
1165 return -ENODEV;
1166 }
1167
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001168 return 0;
1169}
1170
Johannes Berg19d337d2009-06-02 13:01:37 +02001171static const struct rfkill_ops acer_rfkill_ops = {
1172 .set_block = acer_rfkill_set,
1173};
1174
1175static struct rfkill *acer_rfkill_register(struct device *dev,
1176 enum rfkill_type type,
1177 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001178{
1179 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001180 struct rfkill *rfkill_dev;
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001181 u32 state;
1182 acpi_status status;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001183
Johannes Berg19d337d2009-06-02 13:01:37 +02001184 rfkill_dev = rfkill_alloc(name, dev, type,
1185 &acer_rfkill_ops,
1186 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001187 if (!rfkill_dev)
1188 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001189
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001190 status = get_device_status(&state, cap);
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001191
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001192 err = rfkill_register(rfkill_dev);
1193 if (err) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001194 rfkill_destroy(rfkill_dev);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001195 return ERR_PTR(err);
1196 }
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001197
1198 if (ACPI_SUCCESS(status))
1199 rfkill_set_sw_state(rfkill_dev, !state);
1200
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001201 return rfkill_dev;
1202}
1203
1204static int acer_rfkill_init(struct device *dev)
1205{
1206 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1207 "acer-wireless", ACER_CAP_WIRELESS);
1208 if (IS_ERR(wireless_rfkill))
1209 return PTR_ERR(wireless_rfkill);
1210
1211 if (has_cap(ACER_CAP_BLUETOOTH)) {
1212 bluetooth_rfkill = acer_rfkill_register(dev,
1213 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1214 ACER_CAP_BLUETOOTH);
1215 if (IS_ERR(bluetooth_rfkill)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001216 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001217 rfkill_destroy(wireless_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001218 return PTR_ERR(bluetooth_rfkill);
1219 }
1220 }
1221
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001222 if (has_cap(ACER_CAP_THREEG)) {
1223 threeg_rfkill = acer_rfkill_register(dev,
1224 RFKILL_TYPE_WWAN, "acer-threeg",
1225 ACER_CAP_THREEG);
1226 if (IS_ERR(threeg_rfkill)) {
1227 rfkill_unregister(wireless_rfkill);
1228 rfkill_destroy(wireless_rfkill);
1229 rfkill_unregister(bluetooth_rfkill);
1230 rfkill_destroy(bluetooth_rfkill);
1231 return PTR_ERR(threeg_rfkill);
1232 }
1233 }
1234
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001235 rfkill_inited = true;
1236
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001237 if (ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID))
1238 schedule_delayed_work(&acer_rfkill_work,
1239 round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001240
1241 return 0;
1242}
1243
1244static void acer_rfkill_exit(void)
1245{
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001246 if (ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID))
1247 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001248
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001249 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001250 rfkill_destroy(wireless_rfkill);
1251
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001252 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001253 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001254 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001255 }
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001256
1257 if (has_cap(ACER_CAP_THREEG)) {
1258 rfkill_unregister(threeg_rfkill);
1259 rfkill_destroy(threeg_rfkill);
1260 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001261 return;
1262}
1263
1264/*
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001265 * sysfs interface
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001266 */
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001267static ssize_t show_bool_threeg(struct device *dev,
1268 struct device_attribute *attr, char *buf)
1269{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001270 u32 result; \
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001271 acpi_status status;
1272 if (wmi_has_guid(WMID_GUID3))
1273 status = wmid3_get_device_status(&result,
1274 ACER_WMID3_GDS_THREEG);
1275 else
1276 status = get_u32(&result, ACER_CAP_THREEG);
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001277 if (ACPI_SUCCESS(status))
1278 return sprintf(buf, "%u\n", result);
1279 return sprintf(buf, "Read error\n");
1280}
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001281
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001282static ssize_t set_bool_threeg(struct device *dev,
1283 struct device_attribute *attr, const char *buf, size_t count)
1284{
1285 u32 tmp = simple_strtoul(buf, NULL, 10);
1286 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
1287 if (ACPI_FAILURE(status))
1288 return -EINVAL;
1289 return count;
1290}
Vasiliy Kulikovb80b1682011-02-04 15:23:56 +03001291static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg,
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001292 set_bool_threeg);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001293
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001294static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1295 char *buf)
1296{
1297 switch (interface->type) {
1298 case ACER_AMW0:
1299 return sprintf(buf, "AMW0\n");
1300 case ACER_AMW0_V2:
1301 return sprintf(buf, "AMW0 v2\n");
1302 case ACER_WMID:
1303 return sprintf(buf, "WMID\n");
1304 default:
1305 return sprintf(buf, "Error!\n");
1306 }
1307}
1308
Axel Lin370525d2010-06-30 10:20:23 +08001309static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001310
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001311static void acer_wmi_notify(u32 value, void *context)
1312{
1313 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1314 union acpi_object *obj;
1315 struct event_return_value return_value;
1316 acpi_status status;
1317
1318 status = wmi_get_event_data(value, &response);
1319 if (status != AE_OK) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001320 pr_warning("bad event status 0x%x\n", status);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001321 return;
1322 }
1323
1324 obj = (union acpi_object *)response.pointer;
1325
1326 if (!obj)
1327 return;
1328 if (obj->type != ACPI_TYPE_BUFFER) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001329 pr_warning("Unknown response received %d\n", obj->type);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001330 kfree(obj);
1331 return;
1332 }
1333 if (obj->buffer.length != 8) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001334 pr_warning("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001335 kfree(obj);
1336 return;
1337 }
1338
1339 return_value = *((struct event_return_value *)obj->buffer.pointer);
1340 kfree(obj);
1341
1342 switch (return_value.function) {
1343 case WMID_HOTKEY_EVENT:
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001344 if (return_value.device_state) {
1345 u16 device_state = return_value.device_state;
1346 pr_debug("deivces states: 0x%x\n", device_state);
1347 if (has_cap(ACER_CAP_WIRELESS))
1348 rfkill_set_sw_state(wireless_rfkill,
1349 !(device_state & ACER_WMID3_GDS_WIRELESS));
1350 if (has_cap(ACER_CAP_BLUETOOTH))
1351 rfkill_set_sw_state(bluetooth_rfkill,
1352 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1353 if (has_cap(ACER_CAP_THREEG))
1354 rfkill_set_sw_state(threeg_rfkill,
1355 !(device_state & ACER_WMID3_GDS_THREEG));
1356 }
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001357 if (!sparse_keymap_report_event(acer_wmi_input_dev,
1358 return_value.key_num, 1, true))
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001359 pr_warning("Unknown key number - 0x%x\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001360 return_value.key_num);
1361 break;
1362 default:
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001363 pr_warning("Unknown function number - %d - %d\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001364 return_value.function, return_value.key_num);
1365 break;
1366 }
1367}
1368
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001369static acpi_status
1370wmid3_set_lm_mode(struct lm_input_params *params,
1371 struct lm_return_value *return_value)
1372{
1373 acpi_status status;
1374 union acpi_object *obj;
1375
1376 struct acpi_buffer input = { sizeof(struct lm_input_params), params };
1377 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1378
1379 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1380 if (ACPI_FAILURE(status))
1381 return status;
1382
1383 obj = output.pointer;
1384
1385 if (!obj)
1386 return AE_ERROR;
1387 else if (obj->type != ACPI_TYPE_BUFFER) {
1388 kfree(obj);
1389 return AE_ERROR;
1390 }
1391 if (obj->buffer.length != 4) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001392 pr_warning("Unknown buffer length %d\n", obj->buffer.length);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001393 kfree(obj);
1394 return AE_ERROR;
1395 }
1396
1397 *return_value = *((struct lm_return_value *)obj->buffer.pointer);
1398 kfree(obj);
1399
1400 return status;
1401}
1402
1403static int acer_wmi_enable_ec_raw(void)
1404{
1405 struct lm_return_value return_value;
1406 acpi_status status;
1407 struct lm_input_params params = {
1408 .function_num = 0x1,
1409 .commun_devices = 0xFFFF,
1410 .devices = 0xFFFF,
1411 .lm_status = 0x00, /* Launch Manager Deactive */
1412 };
1413
1414 status = wmid3_set_lm_mode(&params, &return_value);
1415
1416 if (return_value.error_code || return_value.ec_return_value)
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001417 pr_warning("Enabling EC raw mode failed: "
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001418 "0x%x - 0x%x\n", return_value.error_code,
1419 return_value.ec_return_value);
1420 else
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001421 pr_info("Enabled EC raw mode");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001422
1423 return status;
1424}
1425
1426static int acer_wmi_enable_lm(void)
1427{
1428 struct lm_return_value return_value;
1429 acpi_status status;
1430 struct lm_input_params params = {
1431 .function_num = 0x1,
1432 .commun_devices = 0xFFFF,
1433 .devices = 0xFFFF,
1434 .lm_status = 0x01, /* Launch Manager Active */
1435 };
1436
1437 status = wmid3_set_lm_mode(&params, &return_value);
1438
1439 if (return_value.error_code || return_value.ec_return_value)
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001440 pr_warning("Enabling Launch Manager failed: "
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001441 "0x%x - 0x%x\n", return_value.error_code,
1442 return_value.ec_return_value);
1443
1444 return status;
1445}
1446
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001447static int __init acer_wmi_input_setup(void)
1448{
1449 acpi_status status;
1450 int err;
1451
1452 acer_wmi_input_dev = input_allocate_device();
1453 if (!acer_wmi_input_dev)
1454 return -ENOMEM;
1455
1456 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1457 acer_wmi_input_dev->phys = "wmi/input0";
1458 acer_wmi_input_dev->id.bustype = BUS_HOST;
1459
1460 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1461 if (err)
1462 goto err_free_dev;
1463
1464 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1465 acer_wmi_notify, NULL);
1466 if (ACPI_FAILURE(status)) {
1467 err = -EIO;
1468 goto err_free_keymap;
1469 }
1470
1471 err = input_register_device(acer_wmi_input_dev);
1472 if (err)
1473 goto err_uninstall_notifier;
1474
1475 return 0;
1476
1477err_uninstall_notifier:
1478 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1479err_free_keymap:
1480 sparse_keymap_free(acer_wmi_input_dev);
1481err_free_dev:
1482 input_free_device(acer_wmi_input_dev);
1483 return err;
1484}
1485
1486static void acer_wmi_input_destroy(void)
1487{
1488 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1489 sparse_keymap_free(acer_wmi_input_dev);
1490 input_unregister_device(acer_wmi_input_dev);
1491}
1492
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001493/*
Carlos Corbacho81143522008-06-21 09:09:53 +01001494 * debugfs functions
1495 */
1496static u32 get_wmid_devices(void)
1497{
1498 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1499 union acpi_object *obj;
1500 acpi_status status;
Axel Lin66904862010-07-20 15:19:52 -07001501 u32 devices = 0;
Carlos Corbacho81143522008-06-21 09:09:53 +01001502
1503 status = wmi_query_block(WMID_GUID2, 1, &out);
1504 if (ACPI_FAILURE(status))
1505 return 0;
1506
1507 obj = (union acpi_object *) out.pointer;
1508 if (obj && obj->type == ACPI_TYPE_BUFFER &&
1509 obj->buffer.length == sizeof(u32)) {
Axel Lin66904862010-07-20 15:19:52 -07001510 devices = *((u32 *) obj->buffer.pointer);
Carlos Corbacho81143522008-06-21 09:09:53 +01001511 }
Axel Lin66904862010-07-20 15:19:52 -07001512
1513 kfree(out.pointer);
1514 return devices;
Carlos Corbacho81143522008-06-21 09:09:53 +01001515}
1516
1517/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001518 * Platform device
1519 */
1520static int __devinit acer_platform_probe(struct platform_device *device)
1521{
1522 int err;
1523
1524 if (has_cap(ACER_CAP_MAILLED)) {
1525 err = acer_led_init(&device->dev);
1526 if (err)
1527 goto error_mailled;
1528 }
1529
1530 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1531 err = acer_backlight_init(&device->dev);
1532 if (err)
1533 goto error_brightness;
1534 }
1535
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001536 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01001537 if (err)
1538 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001539
1540 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001541
Andy Whitcroft350e3292009-04-04 09:33:34 +01001542error_rfkill:
1543 if (has_cap(ACER_CAP_BRIGHTNESS))
1544 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001545error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01001546 if (has_cap(ACER_CAP_MAILLED))
1547 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001548error_mailled:
1549 return err;
1550}
1551
1552static int acer_platform_remove(struct platform_device *device)
1553{
1554 if (has_cap(ACER_CAP_MAILLED))
1555 acer_led_exit();
1556 if (has_cap(ACER_CAP_BRIGHTNESS))
1557 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001558
1559 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001560 return 0;
1561}
1562
1563static int acer_platform_suspend(struct platform_device *dev,
1564pm_message_t state)
1565{
1566 u32 value;
1567 struct acer_data *data = &interface->data;
1568
1569 if (!data)
1570 return -ENOMEM;
1571
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001572 if (has_cap(ACER_CAP_MAILLED)) {
1573 get_u32(&value, ACER_CAP_MAILLED);
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001574 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001575 data->mailled = value;
1576 }
1577
1578 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1579 get_u32(&value, ACER_CAP_BRIGHTNESS);
1580 data->brightness = value;
1581 }
1582
1583 return 0;
1584}
1585
1586static int acer_platform_resume(struct platform_device *device)
1587{
1588 struct acer_data *data = &interface->data;
1589
1590 if (!data)
1591 return -ENOMEM;
1592
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001593 if (has_cap(ACER_CAP_MAILLED))
1594 set_u32(data->mailled, ACER_CAP_MAILLED);
1595
1596 if (has_cap(ACER_CAP_BRIGHTNESS))
1597 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
1598
1599 return 0;
1600}
1601
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001602static void acer_platform_shutdown(struct platform_device *device)
1603{
1604 struct acer_data *data = &interface->data;
1605
1606 if (!data)
1607 return;
1608
1609 if (has_cap(ACER_CAP_MAILLED))
1610 set_u32(LED_OFF, ACER_CAP_MAILLED);
1611}
1612
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001613static struct platform_driver acer_platform_driver = {
1614 .driver = {
1615 .name = "acer-wmi",
1616 .owner = THIS_MODULE,
1617 },
1618 .probe = acer_platform_probe,
1619 .remove = acer_platform_remove,
1620 .suspend = acer_platform_suspend,
1621 .resume = acer_platform_resume,
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001622 .shutdown = acer_platform_shutdown,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001623};
1624
1625static struct platform_device *acer_platform_device;
1626
1627static int remove_sysfs(struct platform_device *device)
1628{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001629 if (has_cap(ACER_CAP_THREEG))
1630 device_remove_file(&device->dev, &dev_attr_threeg);
1631
1632 device_remove_file(&device->dev, &dev_attr_interface);
1633
1634 return 0;
1635}
1636
1637static int create_sysfs(void)
1638{
1639 int retval = -ENOMEM;
1640
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001641 if (has_cap(ACER_CAP_THREEG)) {
1642 retval = device_create_file(&acer_platform_device->dev,
1643 &dev_attr_threeg);
1644 if (retval)
1645 goto error_sysfs;
1646 }
1647
1648 retval = device_create_file(&acer_platform_device->dev,
1649 &dev_attr_interface);
1650 if (retval)
1651 goto error_sysfs;
1652
1653 return 0;
1654
1655error_sysfs:
1656 remove_sysfs(acer_platform_device);
1657 return retval;
1658}
1659
Carlos Corbacho81143522008-06-21 09:09:53 +01001660static void remove_debugfs(void)
1661{
1662 debugfs_remove(interface->debug.devices);
1663 debugfs_remove(interface->debug.root);
1664}
1665
1666static int create_debugfs(void)
1667{
1668 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
1669 if (!interface->debug.root) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001670 pr_err("Failed to create debugfs directory");
Carlos Corbacho81143522008-06-21 09:09:53 +01001671 return -ENOMEM;
1672 }
1673
1674 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
1675 interface->debug.root,
1676 &interface->debug.wmid_devices);
1677 if (!interface->debug.devices)
1678 goto error_debugfs;
1679
1680 return 0;
1681
1682error_debugfs:
Russ Dill39dbbb42008-09-02 14:35:40 -07001683 remove_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01001684 return -ENOMEM;
1685}
1686
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001687static int __init acer_wmi_init(void)
1688{
1689 int err;
1690
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001691 pr_info("Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001692
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001693 if (dmi_check_system(acer_blacklist)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001694 pr_info("Blacklisted hardware detected - not loading\n");
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001695 return -ENODEV;
1696 }
1697
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01001698 find_quirks();
1699
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001700 /*
1701 * Detect which ACPI-WMI interface we're using.
1702 */
1703 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1704 interface = &AMW0_V2_interface;
1705
1706 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1707 interface = &wmid_interface;
1708
1709 if (wmi_has_guid(WMID_GUID2) && interface) {
1710 if (ACPI_FAILURE(WMID_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001711 pr_err("Unable to detect available WMID devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001712 return -ENODEV;
1713 }
1714 } else if (!wmi_has_guid(WMID_GUID2) && interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001715 pr_err("No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001716 return -ENODEV;
1717 }
1718
1719 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
1720 interface = &AMW0_interface;
1721
1722 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001723 pr_err("Unable to detect available AMW0 devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001724 return -ENODEV;
1725 }
1726 }
1727
Carlos Corbacho9b963c42008-02-24 13:34:29 +00001728 if (wmi_has_guid(AMW0_GUID1))
1729 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001730
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001731 if (!interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001732 pr_err("No or unsupported WMI interface, unable to load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001733 return -ENODEV;
1734 }
1735
Arjan van de Ven83097ac2008-08-23 21:45:21 -07001736 set_quirks();
1737
Michael Spang1ba869e2009-03-12 14:31:34 -07001738 if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS)) {
Thomas Renningerfebf2d92008-08-01 17:37:56 +02001739 interface->capability &= ~ACER_CAP_BRIGHTNESS;
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001740 pr_info("Brightness must be controlled by "
Thomas Renningerfebf2d92008-08-01 17:37:56 +02001741 "generic video driver\n");
1742 }
1743
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001744 if (wmi_has_guid(WMID_GUID3)) {
1745 if (ec_raw_mode) {
1746 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001747 pr_err("Cannot enable EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001748 return -ENODEV;
1749 }
1750 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001751 pr_err("Cannot enable Launch Manager mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001752 return -ENODEV;
1753 }
1754 } else if (ec_raw_mode) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001755 pr_info("No WMID EC raw mode enable method\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001756 }
1757
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001758 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
1759 err = acer_wmi_input_setup();
1760 if (err)
1761 return err;
1762 }
1763
Axel Lin1c796322010-06-22 16:17:38 +08001764 err = platform_driver_register(&acer_platform_driver);
1765 if (err) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001766 pr_err("Unable to register platform driver.\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001767 goto error_platform_register;
1768 }
Axel Lin1c796322010-06-22 16:17:38 +08001769
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001770 acer_platform_device = platform_device_alloc("acer-wmi", -1);
Axel Lin1c796322010-06-22 16:17:38 +08001771 if (!acer_platform_device) {
1772 err = -ENOMEM;
1773 goto error_device_alloc;
1774 }
1775
1776 err = platform_device_add(acer_platform_device);
1777 if (err)
1778 goto error_device_add;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001779
1780 err = create_sysfs();
1781 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08001782 goto error_create_sys;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001783
Carlos Corbacho81143522008-06-21 09:09:53 +01001784 if (wmi_has_guid(WMID_GUID2)) {
1785 interface->debug.wmid_devices = get_wmid_devices();
1786 err = create_debugfs();
1787 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08001788 goto error_create_debugfs;
Carlos Corbacho81143522008-06-21 09:09:53 +01001789 }
1790
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001791 /* Override any initial settings with values from the commandline */
1792 acer_commandline_init();
1793
1794 return 0;
1795
Axel Lin1c796322010-06-22 16:17:38 +08001796error_create_debugfs:
1797 remove_sysfs(acer_platform_device);
1798error_create_sys:
1799 platform_device_del(acer_platform_device);
1800error_device_add:
1801 platform_device_put(acer_platform_device);
1802error_device_alloc:
1803 platform_driver_unregister(&acer_platform_driver);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001804error_platform_register:
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001805 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1806 acer_wmi_input_destroy();
1807
Axel Lin1c796322010-06-22 16:17:38 +08001808 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001809}
1810
1811static void __exit acer_wmi_exit(void)
1812{
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001813 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1814 acer_wmi_input_destroy();
1815
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001816 remove_sysfs(acer_platform_device);
Russ Dill39dbbb42008-09-02 14:35:40 -07001817 remove_debugfs();
Axel Lin97ba0af2010-06-03 15:18:03 +08001818 platform_device_unregister(acer_platform_device);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001819 platform_driver_unregister(&acer_platform_driver);
1820
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001821 pr_info("Acer Laptop WMI Extras unloaded\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001822 return;
1823}
1824
1825module_init(acer_wmi_init);
1826module_exit(acer_wmi_exit);