blob: 583565a8bbce8e2010bdc36e16921984854a2b67 [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
Carlos Corbacho745a5d22008-02-05 02:17:10 +000025#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/init.h>
28#include <linux/types.h>
29#include <linux/dmi.h>
Carlos Corbachof2b585b2008-06-21 09:09:27 +010030#include <linux/fb.h>
Carlos Corbacho745a5d22008-02-05 02:17:10 +000031#include <linux/backlight.h>
32#include <linux/leds.h>
33#include <linux/platform_device.h>
34#include <linux/acpi.h>
35#include <linux/i8042.h>
Carlos Corbacho0606e1a2008-10-08 21:40:21 +010036#include <linux/rfkill.h>
37#include <linux/workqueue.h>
Carlos Corbacho81143522008-06-21 09:09:53 +010038#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090039#include <linux/slab.h>
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080040#include <linux/input.h>
41#include <linux/input/sparse-keymap.h>
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +080042#include <linux/dmi.h>
Carlos Corbacho745a5d22008-02-05 02:17:10 +000043
44#include <acpi/acpi_drivers.h>
45
46MODULE_AUTHOR("Carlos Corbacho");
47MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
48MODULE_LICENSE("GPL");
49
50#define ACER_LOGPREFIX "acer-wmi: "
51#define ACER_ERR KERN_ERR ACER_LOGPREFIX
52#define ACER_NOTICE KERN_NOTICE ACER_LOGPREFIX
53#define ACER_INFO KERN_INFO ACER_LOGPREFIX
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080054#define ACER_WARNING KERN_WARNING ACER_LOGPREFIX
Carlos Corbacho745a5d22008-02-05 02:17:10 +000055
56/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +000057 * Magic Number
58 * Meaning is unknown - this number is required for writing to ACPI for AMW0
59 * (it's also used in acerhk when directly accessing the BIOS)
60 */
61#define ACER_AMW0_WRITE 0x9610
62
63/*
64 * Bit masks for the AMW0 interface
65 */
66#define ACER_AMW0_WIRELESS_MASK 0x35
67#define ACER_AMW0_BLUETOOTH_MASK 0x34
68#define ACER_AMW0_MAILLED_MASK 0x31
69
70/*
71 * Method IDs for WMID interface
72 */
73#define ACER_WMID_GET_WIRELESS_METHODID 1
74#define ACER_WMID_GET_BLUETOOTH_METHODID 2
75#define ACER_WMID_GET_BRIGHTNESS_METHODID 3
76#define ACER_WMID_SET_WIRELESS_METHODID 4
77#define ACER_WMID_SET_BLUETOOTH_METHODID 5
78#define ACER_WMID_SET_BRIGHTNESS_METHODID 6
79#define ACER_WMID_GET_THREEG_METHODID 10
80#define ACER_WMID_SET_THREEG_METHODID 11
81
82/*
83 * Acer ACPI method GUIDs
84 */
85#define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
Carlos Corbacho5753dd52008-06-21 09:09:48 +010086#define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
Carlos Corbacho745a5d22008-02-05 02:17:10 +000087#define WMID_GUID1 "6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3"
88#define WMID_GUID2 "95764E09-FB56-4e83-B31A-37761F60994A"
Lee, Chun-Yib3c90922010-12-07 10:29:22 +080089#define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
Carlos Corbacho745a5d22008-02-05 02:17:10 +000090
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080091/*
92 * Acer ACPI event GUIDs
93 */
94#define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
95
Carlos Corbacho745a5d22008-02-05 02:17:10 +000096MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
97MODULE_ALIAS("wmi:6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3");
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080098MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
99
100enum acer_wmi_event_ids {
101 WMID_HOTKEY_EVENT = 0x1,
102};
103
104static const struct key_entry acer_wmi_keymap[] = {
105 {KE_KEY, 0x01, {KEY_WLAN} }, /* WiFi */
106 {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */
107 {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */
108 {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */
109 {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */
110 {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */
111 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
112 {KE_KEY, 0x82, {KEY_F22} }, /* Touch Pad On/Off */
113 {KE_END, 0}
114};
115
116static struct input_dev *acer_wmi_input_dev;
117
118struct event_return_value {
119 u8 function;
120 u8 key_num;
121 u16 device_state;
122 u32 reserved;
123} __attribute__((packed));
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000124
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000125/*
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800126 * GUID3 Get Device Status device flags
127 */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800128#define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800129#define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800130#define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800131
132struct wmid3_gds_input_param { /* Get Device Status input parameter */
133 u8 function_num; /* Function Number */
134 u8 hotkey_number; /* Hotkey Number */
135 u16 devices; /* Get Device */
136} __attribute__((packed));
137
138struct wmid3_gds_return_value { /* Get Device Status return value*/
139 u8 error_code; /* Error Code */
140 u8 ec_return_value; /* EC Return Value */
141 u16 devices; /* Current Device Status */
142 u32 reserved;
143} __attribute__((packed));
144
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800145struct hotkey_function_type_aa {
146 u8 type;
147 u8 length;
148 u16 handle;
149 u16 commun_func_bitmap;
150} __attribute__((packed));
151
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800152/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000153 * Interface capability flags
154 */
155#define ACER_CAP_MAILLED (1<<0)
156#define ACER_CAP_WIRELESS (1<<1)
157#define ACER_CAP_BLUETOOTH (1<<2)
158#define ACER_CAP_BRIGHTNESS (1<<3)
159#define ACER_CAP_THREEG (1<<4)
160#define ACER_CAP_ANY (0xFFFFFFFF)
161
162/*
163 * Interface type flags
164 */
165enum interface_flags {
166 ACER_AMW0,
167 ACER_AMW0_V2,
168 ACER_WMID,
169};
170
171#define ACER_DEFAULT_WIRELESS 0
172#define ACER_DEFAULT_BLUETOOTH 0
173#define ACER_DEFAULT_MAILLED 0
174#define ACER_DEFAULT_THREEG 0
175
176static int max_brightness = 0xF;
177
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000178static int mailled = -1;
179static int brightness = -1;
180static int threeg = -1;
181static int force_series;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800182static bool has_type_aa;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000183
184module_param(mailled, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000185module_param(brightness, int, 0444);
186module_param(threeg, int, 0444);
187module_param(force_series, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000188MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
189MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
190MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
191MODULE_PARM_DESC(force_series, "Force a different laptop series");
192
193struct acer_data {
194 int mailled;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000195 int threeg;
196 int brightness;
197};
198
Carlos Corbacho81143522008-06-21 09:09:53 +0100199struct acer_debug {
200 struct dentry *root;
201 struct dentry *devices;
202 u32 wmid_devices;
203};
204
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100205static struct rfkill *wireless_rfkill;
206static struct rfkill *bluetooth_rfkill;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800207static struct rfkill *threeg_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100208
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000209/* Each low-level interface must define at least some of the following */
210struct wmi_interface {
211 /* The WMI device type */
212 u32 type;
213
214 /* The capabilities this interface provides */
215 u32 capability;
216
217 /* Private data for the current interface */
218 struct acer_data data;
Carlos Corbacho81143522008-06-21 09:09:53 +0100219
220 /* debugfs entries associated with this interface */
221 struct acer_debug debug;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000222};
223
224/* The static interface pointer, points to the currently detected interface */
225static struct wmi_interface *interface;
226
227/*
228 * Embedded Controller quirks
229 * Some laptops require us to directly access the EC to either enable or query
230 * features that are not available through WMI.
231 */
232
233struct quirk_entry {
234 u8 wireless;
235 u8 mailled;
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100236 s8 brightness;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000237 u8 bluetooth;
238};
239
240static struct quirk_entry *quirks;
241
242static void set_quirks(void)
243{
Arjan van de Ven83097ac2008-08-23 21:45:21 -0700244 if (!interface)
245 return;
246
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000247 if (quirks->mailled)
248 interface->capability |= ACER_CAP_MAILLED;
249
250 if (quirks->brightness)
251 interface->capability |= ACER_CAP_BRIGHTNESS;
252}
253
254static int dmi_matched(const struct dmi_system_id *dmi)
255{
256 quirks = dmi->driver_data;
Axel Lind53bf0f2010-06-30 13:32:16 +0800257 return 1;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000258}
259
260static struct quirk_entry quirk_unknown = {
261};
262
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100263static struct quirk_entry quirk_acer_aspire_1520 = {
264 .brightness = -1,
265};
266
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000267static struct quirk_entry quirk_acer_travelmate_2490 = {
268 .mailled = 1,
269};
270
271/* This AMW0 laptop has no bluetooth */
272static struct quirk_entry quirk_medion_md_98300 = {
273 .wireless = 1,
274};
275
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100276static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
277 .wireless = 2,
278};
279
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100280/* The Aspire One has a dummy ACPI-WMI interface - disable it */
281static struct dmi_system_id __devinitdata acer_blacklist[] = {
282 {
283 .ident = "Acer Aspire One (SSD)",
284 .matches = {
285 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
286 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
287 },
288 },
289 {
290 .ident = "Acer Aspire One (HDD)",
291 .matches = {
292 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
293 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
294 },
295 },
296 {}
297};
298
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000299static struct dmi_system_id acer_quirks[] = {
300 {
301 .callback = dmi_matched,
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100302 .ident = "Acer Aspire 1360",
303 .matches = {
304 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
305 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
306 },
307 .driver_data = &quirk_acer_aspire_1520,
308 },
309 {
310 .callback = dmi_matched,
311 .ident = "Acer Aspire 1520",
312 .matches = {
313 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
314 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
315 },
316 .driver_data = &quirk_acer_aspire_1520,
317 },
318 {
319 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000320 .ident = "Acer Aspire 3100",
321 .matches = {
322 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
323 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
324 },
325 .driver_data = &quirk_acer_travelmate_2490,
326 },
327 {
328 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000329 .ident = "Acer Aspire 3610",
330 .matches = {
331 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
332 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
333 },
334 .driver_data = &quirk_acer_travelmate_2490,
335 },
336 {
337 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000338 .ident = "Acer Aspire 5100",
339 .matches = {
340 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
341 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
342 },
343 .driver_data = &quirk_acer_travelmate_2490,
344 },
345 {
346 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000347 .ident = "Acer Aspire 5610",
348 .matches = {
349 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
350 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
351 },
352 .driver_data = &quirk_acer_travelmate_2490,
353 },
354 {
355 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000356 .ident = "Acer Aspire 5630",
357 .matches = {
358 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
359 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
360 },
361 .driver_data = &quirk_acer_travelmate_2490,
362 },
363 {
364 .callback = dmi_matched,
365 .ident = "Acer Aspire 5650",
366 .matches = {
367 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
368 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
369 },
370 .driver_data = &quirk_acer_travelmate_2490,
371 },
372 {
373 .callback = dmi_matched,
374 .ident = "Acer Aspire 5680",
375 .matches = {
376 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
377 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
378 },
379 .driver_data = &quirk_acer_travelmate_2490,
380 },
381 {
382 .callback = dmi_matched,
383 .ident = "Acer Aspire 9110",
384 .matches = {
385 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
386 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
387 },
388 .driver_data = &quirk_acer_travelmate_2490,
389 },
390 {
391 .callback = dmi_matched,
392 .ident = "Acer TravelMate 2490",
393 .matches = {
394 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
395 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
396 },
397 .driver_data = &quirk_acer_travelmate_2490,
398 },
399 {
400 .callback = dmi_matched,
Carlos Corbacho262ee352008-02-16 00:02:56 +0000401 .ident = "Acer TravelMate 4200",
402 .matches = {
403 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
404 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
405 },
406 .driver_data = &quirk_acer_travelmate_2490,
407 },
408 {
409 .callback = dmi_matched,
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100410 .ident = "Fujitsu Siemens Amilo Li 1718",
411 .matches = {
412 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
413 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
414 },
415 .driver_data = &quirk_fujitsu_amilo_li_1718,
416 },
417 {
418 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000419 .ident = "Medion MD 98300",
420 .matches = {
421 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
422 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
423 },
424 .driver_data = &quirk_medion_md_98300,
425 },
426 {}
427};
428
429/* Find which quirks are needed for a particular vendor/ model pair */
430static void find_quirks(void)
431{
432 if (!force_series) {
433 dmi_check_system(acer_quirks);
434 } else if (force_series == 2490) {
435 quirks = &quirk_acer_travelmate_2490;
436 }
437
438 if (quirks == NULL)
439 quirks = &quirk_unknown;
440
441 set_quirks();
442}
443
444/*
445 * General interface convenience methods
446 */
447
448static bool has_cap(u32 cap)
449{
450 if ((interface->capability & cap) != 0)
451 return 1;
452
453 return 0;
454}
455
456/*
457 * AMW0 (V1) interface
458 */
459struct wmab_args {
460 u32 eax;
461 u32 ebx;
462 u32 ecx;
463 u32 edx;
464};
465
466struct wmab_ret {
467 u32 eax;
468 u32 ebx;
469 u32 ecx;
470 u32 edx;
471 u32 eex;
472};
473
474static acpi_status wmab_execute(struct wmab_args *regbuf,
475struct acpi_buffer *result)
476{
477 struct acpi_buffer input;
478 acpi_status status;
479 input.length = sizeof(struct wmab_args);
480 input.pointer = (u8 *)regbuf;
481
482 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
483
484 return status;
485}
486
487static acpi_status AMW0_get_u32(u32 *value, u32 cap,
488struct wmi_interface *iface)
489{
490 int err;
491 u8 result;
492
493 switch (cap) {
494 case ACER_CAP_MAILLED:
495 switch (quirks->mailled) {
496 default:
497 err = ec_read(0xA, &result);
498 if (err)
499 return AE_ERROR;
500 *value = (result >> 7) & 0x1;
501 return AE_OK;
502 }
503 break;
504 case ACER_CAP_WIRELESS:
505 switch (quirks->wireless) {
506 case 1:
507 err = ec_read(0x7B, &result);
508 if (err)
509 return AE_ERROR;
510 *value = result & 0x1;
511 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100512 case 2:
513 err = ec_read(0x71, &result);
514 if (err)
515 return AE_ERROR;
516 *value = result & 0x1;
517 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000518 default:
519 err = ec_read(0xA, &result);
520 if (err)
521 return AE_ERROR;
522 *value = (result >> 2) & 0x1;
523 return AE_OK;
524 }
525 break;
526 case ACER_CAP_BLUETOOTH:
527 switch (quirks->bluetooth) {
528 default:
529 err = ec_read(0xA, &result);
530 if (err)
531 return AE_ERROR;
532 *value = (result >> 4) & 0x1;
533 return AE_OK;
534 }
535 break;
536 case ACER_CAP_BRIGHTNESS:
537 switch (quirks->brightness) {
538 default:
539 err = ec_read(0x83, &result);
540 if (err)
541 return AE_ERROR;
542 *value = result;
543 return AE_OK;
544 }
545 break;
546 default:
Lin Ming08237972008-08-08 11:57:11 +0800547 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000548 }
549 return AE_OK;
550}
551
552static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
553{
554 struct wmab_args args;
555
556 args.eax = ACER_AMW0_WRITE;
557 args.ebx = value ? (1<<8) : 0;
558 args.ecx = args.edx = 0;
559
560 switch (cap) {
561 case ACER_CAP_MAILLED:
562 if (value > 1)
563 return AE_BAD_PARAMETER;
564 args.ebx |= ACER_AMW0_MAILLED_MASK;
565 break;
566 case ACER_CAP_WIRELESS:
567 if (value > 1)
568 return AE_BAD_PARAMETER;
569 args.ebx |= ACER_AMW0_WIRELESS_MASK;
570 break;
571 case ACER_CAP_BLUETOOTH:
572 if (value > 1)
573 return AE_BAD_PARAMETER;
574 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
575 break;
576 case ACER_CAP_BRIGHTNESS:
577 if (value > max_brightness)
578 return AE_BAD_PARAMETER;
579 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000580 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000581 return ec_write(0x83, value);
582 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000583 }
584 default:
Lin Ming08237972008-08-08 11:57:11 +0800585 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000586 }
587
588 /* Actually do the set */
589 return wmab_execute(&args, NULL);
590}
591
592static acpi_status AMW0_find_mailled(void)
593{
594 struct wmab_args args;
595 struct wmab_ret ret;
596 acpi_status status = AE_OK;
597 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
598 union acpi_object *obj;
599
600 args.eax = 0x86;
601 args.ebx = args.ecx = args.edx = 0;
602
603 status = wmab_execute(&args, &out);
604 if (ACPI_FAILURE(status))
605 return status;
606
607 obj = (union acpi_object *) out.pointer;
608 if (obj && obj->type == ACPI_TYPE_BUFFER &&
609 obj->buffer.length == sizeof(struct wmab_ret)) {
610 ret = *((struct wmab_ret *) obj->buffer.pointer);
611 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700612 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000613 return AE_ERROR;
614 }
615
616 if (ret.eex & 0x1)
617 interface->capability |= ACER_CAP_MAILLED;
618
619 kfree(out.pointer);
620
621 return AE_OK;
622}
623
624static acpi_status AMW0_set_capabilities(void)
625{
626 struct wmab_args args;
627 struct wmab_ret ret;
Axel Lin7677fbd2010-07-20 15:19:53 -0700628 acpi_status status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000629 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
630 union acpi_object *obj;
631
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100632 /*
633 * On laptops with this strange GUID (non Acer), normal probing doesn't
634 * work.
635 */
636 if (wmi_has_guid(AMW0_GUID2)) {
637 interface->capability |= ACER_CAP_WIRELESS;
638 return AE_OK;
639 }
640
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000641 args.eax = ACER_AMW0_WRITE;
642 args.ecx = args.edx = 0;
643
644 args.ebx = 0xa2 << 8;
645 args.ebx |= ACER_AMW0_WIRELESS_MASK;
646
647 status = wmab_execute(&args, &out);
648 if (ACPI_FAILURE(status))
649 return status;
650
Axel Lin7677fbd2010-07-20 15:19:53 -0700651 obj = out.pointer;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000652 if (obj && obj->type == ACPI_TYPE_BUFFER &&
653 obj->buffer.length == sizeof(struct wmab_ret)) {
654 ret = *((struct wmab_ret *) obj->buffer.pointer);
655 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700656 status = AE_ERROR;
657 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000658 }
659
660 if (ret.eax & 0x1)
661 interface->capability |= ACER_CAP_WIRELESS;
662
663 args.ebx = 2 << 8;
664 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
665
Axel Lin7677fbd2010-07-20 15:19:53 -0700666 /*
667 * It's ok to use existing buffer for next wmab_execute call.
668 * But we need to kfree(out.pointer) if next wmab_execute fail.
669 */
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000670 status = wmab_execute(&args, &out);
671 if (ACPI_FAILURE(status))
Axel Lin7677fbd2010-07-20 15:19:53 -0700672 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000673
674 obj = (union acpi_object *) out.pointer;
675 if (obj && obj->type == ACPI_TYPE_BUFFER
676 && obj->buffer.length == sizeof(struct wmab_ret)) {
677 ret = *((struct wmab_ret *) obj->buffer.pointer);
678 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700679 status = AE_ERROR;
680 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000681 }
682
683 if (ret.eax & 0x1)
684 interface->capability |= ACER_CAP_BLUETOOTH;
685
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000686 /*
687 * This appears to be safe to enable, since all Wistron based laptops
688 * appear to use the same EC register for brightness, even if they
689 * differ for wireless, etc
690 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100691 if (quirks->brightness >= 0)
692 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000693
Axel Lin7677fbd2010-07-20 15:19:53 -0700694 status = AE_OK;
695out:
696 kfree(out.pointer);
697 return status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000698}
699
700static struct wmi_interface AMW0_interface = {
701 .type = ACER_AMW0,
702};
703
704static struct wmi_interface AMW0_V2_interface = {
705 .type = ACER_AMW0_V2,
706};
707
708/*
709 * New interface (The WMID interface)
710 */
711static acpi_status
712WMI_execute_u32(u32 method_id, u32 in, u32 *out)
713{
714 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
715 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
716 union acpi_object *obj;
717 u32 tmp;
718 acpi_status status;
719
720 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
721
722 if (ACPI_FAILURE(status))
723 return status;
724
725 obj = (union acpi_object *) result.pointer;
726 if (obj && obj->type == ACPI_TYPE_BUFFER &&
727 obj->buffer.length == sizeof(u32)) {
728 tmp = *((u32 *) obj->buffer.pointer);
729 } else {
730 tmp = 0;
731 }
732
733 if (out)
734 *out = tmp;
735
736 kfree(result.pointer);
737
738 return status;
739}
740
741static acpi_status WMID_get_u32(u32 *value, u32 cap,
742struct wmi_interface *iface)
743{
744 acpi_status status;
745 u8 tmp;
746 u32 result, method_id = 0;
747
748 switch (cap) {
749 case ACER_CAP_WIRELESS:
750 method_id = ACER_WMID_GET_WIRELESS_METHODID;
751 break;
752 case ACER_CAP_BLUETOOTH:
753 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
754 break;
755 case ACER_CAP_BRIGHTNESS:
756 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
757 break;
758 case ACER_CAP_THREEG:
759 method_id = ACER_WMID_GET_THREEG_METHODID;
760 break;
761 case ACER_CAP_MAILLED:
762 if (quirks->mailled == 1) {
763 ec_read(0x9f, &tmp);
764 *value = tmp & 0x1;
765 return 0;
766 }
767 default:
Lin Ming08237972008-08-08 11:57:11 +0800768 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000769 }
770 status = WMI_execute_u32(method_id, 0, &result);
771
772 if (ACPI_SUCCESS(status))
773 *value = (u8)result;
774
775 return status;
776}
777
778static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
779{
780 u32 method_id = 0;
781 char param;
782
783 switch (cap) {
784 case ACER_CAP_BRIGHTNESS:
785 if (value > max_brightness)
786 return AE_BAD_PARAMETER;
787 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
788 break;
789 case ACER_CAP_WIRELESS:
790 if (value > 1)
791 return AE_BAD_PARAMETER;
792 method_id = ACER_WMID_SET_WIRELESS_METHODID;
793 break;
794 case ACER_CAP_BLUETOOTH:
795 if (value > 1)
796 return AE_BAD_PARAMETER;
797 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
798 break;
799 case ACER_CAP_THREEG:
800 if (value > 1)
801 return AE_BAD_PARAMETER;
802 method_id = ACER_WMID_SET_THREEG_METHODID;
803 break;
804 case ACER_CAP_MAILLED:
805 if (value > 1)
806 return AE_BAD_PARAMETER;
807 if (quirks->mailled == 1) {
808 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700809 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000810 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700811 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000812 return 0;
813 }
814 break;
815 default:
Lin Ming08237972008-08-08 11:57:11 +0800816 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000817 }
818 return WMI_execute_u32(method_id, (u32)value, NULL);
819}
820
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800821static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
822{
823 struct hotkey_function_type_aa *type_aa;
824
825 /* We are looking for OEM-specific Type AAh */
826 if (header->type != 0xAA)
827 return;
828
829 has_type_aa = true;
830 type_aa = (struct hotkey_function_type_aa *) header;
831
832 printk(ACER_INFO "Function bitmap for Communication Button: 0x%x\n",
833 type_aa->commun_func_bitmap);
834
835 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
836 interface->capability |= ACER_CAP_WIRELESS;
837 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
838 interface->capability |= ACER_CAP_THREEG;
839 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
840 interface->capability |= ACER_CAP_BLUETOOTH;
841}
842
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000843static acpi_status WMID_set_capabilities(void)
844{
845 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
846 union acpi_object *obj;
847 acpi_status status;
848 u32 devices;
849
850 status = wmi_query_block(WMID_GUID2, 1, &out);
851 if (ACPI_FAILURE(status))
852 return status;
853
854 obj = (union acpi_object *) out.pointer;
855 if (obj && obj->type == ACPI_TYPE_BUFFER &&
856 obj->buffer.length == sizeof(u32)) {
857 devices = *((u32 *) obj->buffer.pointer);
858 } else {
Axel Lin66904862010-07-20 15:19:52 -0700859 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000860 return AE_ERROR;
861 }
862
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800863 dmi_walk(type_aa_dmi_decode, NULL);
864 if (!has_type_aa) {
865 interface->capability |= ACER_CAP_WIRELESS;
866 interface->capability |= ACER_CAP_THREEG;
867 if (devices & 0x10)
868 interface->capability |= ACER_CAP_BLUETOOTH;
869 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000870
871 /* WMID always provides brightness methods */
872 interface->capability |= ACER_CAP_BRIGHTNESS;
873
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000874 if (!(devices & 0x20))
875 max_brightness = 0x9;
876
Axel Lin66904862010-07-20 15:19:52 -0700877 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000878 return status;
879}
880
881static struct wmi_interface wmid_interface = {
882 .type = ACER_WMID,
883};
884
885/*
886 * Generic Device (interface-independent)
887 */
888
889static acpi_status get_u32(u32 *value, u32 cap)
890{
Lin Ming08237972008-08-08 11:57:11 +0800891 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000892
893 switch (interface->type) {
894 case ACER_AMW0:
895 status = AMW0_get_u32(value, cap, interface);
896 break;
897 case ACER_AMW0_V2:
898 if (cap == ACER_CAP_MAILLED) {
899 status = AMW0_get_u32(value, cap, interface);
900 break;
901 }
902 case ACER_WMID:
903 status = WMID_get_u32(value, cap, interface);
904 break;
905 }
906
907 return status;
908}
909
910static acpi_status set_u32(u32 value, u32 cap)
911{
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100912 acpi_status status;
913
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000914 if (interface->capability & cap) {
915 switch (interface->type) {
916 case ACER_AMW0:
917 return AMW0_set_u32(value, cap, interface);
918 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100919 if (cap == ACER_CAP_MAILLED)
920 return AMW0_set_u32(value, cap, interface);
921
922 /*
923 * On some models, some WMID methods don't toggle
924 * properly. For those cases, we want to run the AMW0
925 * method afterwards to be certain we've really toggled
926 * the device state.
927 */
928 if (cap == ACER_CAP_WIRELESS ||
929 cap == ACER_CAP_BLUETOOTH) {
930 status = WMID_set_u32(value, cap, interface);
931 if (ACPI_FAILURE(status))
932 return status;
933
934 return AMW0_set_u32(value, cap, interface);
935 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000936 case ACER_WMID:
937 return WMID_set_u32(value, cap, interface);
938 default:
939 return AE_BAD_PARAMETER;
940 }
941 }
942 return AE_BAD_PARAMETER;
943}
944
945static void __init acer_commandline_init(void)
946{
947 /*
948 * These will all fail silently if the value given is invalid, or the
949 * capability isn't available on the given interface
950 */
951 set_u32(mailled, ACER_CAP_MAILLED);
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800952 if (!has_type_aa)
953 set_u32(threeg, ACER_CAP_THREEG);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000954 set_u32(brightness, ACER_CAP_BRIGHTNESS);
955}
956
957/*
958 * LED device (Mail LED only, no other LEDs known yet)
959 */
960static void mail_led_set(struct led_classdev *led_cdev,
961enum led_brightness value)
962{
963 set_u32(value, ACER_CAP_MAILLED);
964}
965
966static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +0000967 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000968 .brightness_set = mail_led_set,
969};
970
Sam Ravnborg7560e382008-02-17 13:22:54 +0100971static int __devinit acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000972{
973 return led_classdev_register(dev, &mail_led);
974}
975
976static void acer_led_exit(void)
977{
978 led_classdev_unregister(&mail_led);
979}
980
981/*
982 * Backlight device
983 */
984static struct backlight_device *acer_backlight_device;
985
986static int read_brightness(struct backlight_device *bd)
987{
988 u32 value;
989 get_u32(&value, ACER_CAP_BRIGHTNESS);
990 return value;
991}
992
993static int update_bl_status(struct backlight_device *bd)
994{
Carlos Corbachof2b585b2008-06-21 09:09:27 +0100995 int intensity = bd->props.brightness;
996
997 if (bd->props.power != FB_BLANK_UNBLANK)
998 intensity = 0;
999 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1000 intensity = 0;
1001
1002 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1003
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001004 return 0;
1005}
1006
1007static struct backlight_ops acer_bl_ops = {
1008 .get_brightness = read_brightness,
1009 .update_status = update_bl_status,
1010};
1011
Sam Ravnborg7560e382008-02-17 13:22:54 +01001012static int __devinit acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001013{
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001014 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001015 struct backlight_device *bd;
1016
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001017 memset(&props, 0, sizeof(struct backlight_properties));
1018 props.max_brightness = max_brightness;
1019 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1020 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001021 if (IS_ERR(bd)) {
1022 printk(ACER_ERR "Could not register Acer backlight device\n");
1023 acer_backlight_device = NULL;
1024 return PTR_ERR(bd);
1025 }
1026
1027 acer_backlight_device = bd;
1028
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001029 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +00001030 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001031 backlight_update_status(bd);
1032 return 0;
1033}
1034
Sam Ravnborg7560e382008-02-17 13:22:54 +01001035static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001036{
1037 backlight_device_unregister(acer_backlight_device);
1038}
1039
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001040static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1041{
1042 struct wmid3_gds_return_value return_value;
1043 acpi_status status;
1044 union acpi_object *obj;
1045 struct wmid3_gds_input_param params = {
1046 .function_num = 0x1,
1047 .hotkey_number = 0x01,
1048 .devices = device,
1049 };
1050 struct acpi_buffer input = {
1051 sizeof(struct wmid3_gds_input_param),
1052 &params
1053 };
1054 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1055
1056 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1057 if (ACPI_FAILURE(status))
1058 return status;
1059
1060 obj = output.pointer;
1061
1062 if (!obj)
1063 return AE_ERROR;
1064 else if (obj->type != ACPI_TYPE_BUFFER) {
1065 kfree(obj);
1066 return AE_ERROR;
1067 }
1068 if (obj->buffer.length != 8) {
1069 printk(ACER_WARNING "Unknown buffer length %d\n",
1070 obj->buffer.length);
1071 kfree(obj);
1072 return AE_ERROR;
1073 }
1074
1075 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1076 kfree(obj);
1077
1078 if (return_value.error_code || return_value.ec_return_value)
1079 printk(ACER_WARNING "Get Device Status failed: "
1080 "0x%x - 0x%x\n", return_value.error_code,
1081 return_value.ec_return_value);
1082 else
1083 *value = !!(return_value.devices & device);
1084
1085 return status;
1086}
1087
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001088/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001089 * Rfkill devices
1090 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001091static void acer_rfkill_update(struct work_struct *ignored);
1092static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1093static void acer_rfkill_update(struct work_struct *ignored)
1094{
1095 u32 state;
1096 acpi_status status;
1097
1098 status = get_u32(&state, ACER_CAP_WIRELESS);
1099 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001100 rfkill_set_sw_state(wireless_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001101
1102 if (has_cap(ACER_CAP_BLUETOOTH)) {
1103 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1104 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001105 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001106 }
1107
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001108 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
1109 status = wmid3_get_device_status(&state,
1110 ACER_WMID3_GDS_THREEG);
1111 if (ACPI_SUCCESS(status))
1112 rfkill_set_sw_state(threeg_rfkill, !state);
1113 }
1114
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001115 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001116}
1117
Johannes Berg19d337d2009-06-02 13:01:37 +02001118static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001119{
1120 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +02001121 u32 cap = (unsigned long)data;
Alan Jenkinsed5c8ef2009-07-19 09:48:28 +01001122 status = set_u32(!blocked, cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001123 if (ACPI_FAILURE(status))
1124 return -ENODEV;
1125 return 0;
1126}
1127
Johannes Berg19d337d2009-06-02 13:01:37 +02001128static const struct rfkill_ops acer_rfkill_ops = {
1129 .set_block = acer_rfkill_set,
1130};
1131
1132static struct rfkill *acer_rfkill_register(struct device *dev,
1133 enum rfkill_type type,
1134 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001135{
1136 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001137 struct rfkill *rfkill_dev;
1138
Johannes Berg19d337d2009-06-02 13:01:37 +02001139 rfkill_dev = rfkill_alloc(name, dev, type,
1140 &acer_rfkill_ops,
1141 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001142 if (!rfkill_dev)
1143 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001144
1145 err = rfkill_register(rfkill_dev);
1146 if (err) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001147 rfkill_destroy(rfkill_dev);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001148 return ERR_PTR(err);
1149 }
1150 return rfkill_dev;
1151}
1152
1153static int acer_rfkill_init(struct device *dev)
1154{
1155 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1156 "acer-wireless", ACER_CAP_WIRELESS);
1157 if (IS_ERR(wireless_rfkill))
1158 return PTR_ERR(wireless_rfkill);
1159
1160 if (has_cap(ACER_CAP_BLUETOOTH)) {
1161 bluetooth_rfkill = acer_rfkill_register(dev,
1162 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1163 ACER_CAP_BLUETOOTH);
1164 if (IS_ERR(bluetooth_rfkill)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001165 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001166 rfkill_destroy(wireless_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001167 return PTR_ERR(bluetooth_rfkill);
1168 }
1169 }
1170
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001171 if (has_cap(ACER_CAP_THREEG)) {
1172 threeg_rfkill = acer_rfkill_register(dev,
1173 RFKILL_TYPE_WWAN, "acer-threeg",
1174 ACER_CAP_THREEG);
1175 if (IS_ERR(threeg_rfkill)) {
1176 rfkill_unregister(wireless_rfkill);
1177 rfkill_destroy(wireless_rfkill);
1178 rfkill_unregister(bluetooth_rfkill);
1179 rfkill_destroy(bluetooth_rfkill);
1180 return PTR_ERR(threeg_rfkill);
1181 }
1182 }
1183
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001184 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001185
1186 return 0;
1187}
1188
1189static void acer_rfkill_exit(void)
1190{
1191 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001192
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001193 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001194 rfkill_destroy(wireless_rfkill);
1195
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001196 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001197 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001198 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001199 }
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001200
1201 if (has_cap(ACER_CAP_THREEG)) {
1202 rfkill_unregister(threeg_rfkill);
1203 rfkill_destroy(threeg_rfkill);
1204 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001205 return;
1206}
1207
1208/*
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001209 * sysfs interface
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001210 */
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001211static ssize_t show_bool_threeg(struct device *dev,
1212 struct device_attribute *attr, char *buf)
1213{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001214 u32 result; \
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001215 acpi_status status;
1216 if (wmi_has_guid(WMID_GUID3))
1217 status = wmid3_get_device_status(&result,
1218 ACER_WMID3_GDS_THREEG);
1219 else
1220 status = get_u32(&result, ACER_CAP_THREEG);
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001221 if (ACPI_SUCCESS(status))
1222 return sprintf(buf, "%u\n", result);
1223 return sprintf(buf, "Read error\n");
1224}
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001225
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001226static ssize_t set_bool_threeg(struct device *dev,
1227 struct device_attribute *attr, const char *buf, size_t count)
1228{
1229 u32 tmp = simple_strtoul(buf, NULL, 10);
1230 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
1231 if (ACPI_FAILURE(status))
1232 return -EINVAL;
1233 return count;
1234}
1235static DEVICE_ATTR(threeg, S_IWUGO | S_IRUGO | S_IWUSR, show_bool_threeg,
1236 set_bool_threeg);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001237
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001238static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1239 char *buf)
1240{
1241 switch (interface->type) {
1242 case ACER_AMW0:
1243 return sprintf(buf, "AMW0\n");
1244 case ACER_AMW0_V2:
1245 return sprintf(buf, "AMW0 v2\n");
1246 case ACER_WMID:
1247 return sprintf(buf, "WMID\n");
1248 default:
1249 return sprintf(buf, "Error!\n");
1250 }
1251}
1252
Axel Lin370525d2010-06-30 10:20:23 +08001253static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001254
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001255static void acer_wmi_notify(u32 value, void *context)
1256{
1257 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1258 union acpi_object *obj;
1259 struct event_return_value return_value;
1260 acpi_status status;
1261
1262 status = wmi_get_event_data(value, &response);
1263 if (status != AE_OK) {
1264 printk(ACER_WARNING "bad event status 0x%x\n", status);
1265 return;
1266 }
1267
1268 obj = (union acpi_object *)response.pointer;
1269
1270 if (!obj)
1271 return;
1272 if (obj->type != ACPI_TYPE_BUFFER) {
1273 printk(ACER_WARNING "Unknown response received %d\n",
1274 obj->type);
1275 kfree(obj);
1276 return;
1277 }
1278 if (obj->buffer.length != 8) {
1279 printk(ACER_WARNING "Unknown buffer length %d\n",
1280 obj->buffer.length);
1281 kfree(obj);
1282 return;
1283 }
1284
1285 return_value = *((struct event_return_value *)obj->buffer.pointer);
1286 kfree(obj);
1287
1288 switch (return_value.function) {
1289 case WMID_HOTKEY_EVENT:
1290 if (!sparse_keymap_report_event(acer_wmi_input_dev,
1291 return_value.key_num, 1, true))
1292 printk(ACER_WARNING "Unknown key number - 0x%x\n",
1293 return_value.key_num);
1294 break;
1295 default:
1296 printk(ACER_WARNING "Unknown function number - %d - %d\n",
1297 return_value.function, return_value.key_num);
1298 break;
1299 }
1300}
1301
1302static int __init acer_wmi_input_setup(void)
1303{
1304 acpi_status status;
1305 int err;
1306
1307 acer_wmi_input_dev = input_allocate_device();
1308 if (!acer_wmi_input_dev)
1309 return -ENOMEM;
1310
1311 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1312 acer_wmi_input_dev->phys = "wmi/input0";
1313 acer_wmi_input_dev->id.bustype = BUS_HOST;
1314
1315 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1316 if (err)
1317 goto err_free_dev;
1318
1319 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1320 acer_wmi_notify, NULL);
1321 if (ACPI_FAILURE(status)) {
1322 err = -EIO;
1323 goto err_free_keymap;
1324 }
1325
1326 err = input_register_device(acer_wmi_input_dev);
1327 if (err)
1328 goto err_uninstall_notifier;
1329
1330 return 0;
1331
1332err_uninstall_notifier:
1333 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1334err_free_keymap:
1335 sparse_keymap_free(acer_wmi_input_dev);
1336err_free_dev:
1337 input_free_device(acer_wmi_input_dev);
1338 return err;
1339}
1340
1341static void acer_wmi_input_destroy(void)
1342{
1343 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1344 sparse_keymap_free(acer_wmi_input_dev);
1345 input_unregister_device(acer_wmi_input_dev);
1346}
1347
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001348/*
Carlos Corbacho81143522008-06-21 09:09:53 +01001349 * debugfs functions
1350 */
1351static u32 get_wmid_devices(void)
1352{
1353 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1354 union acpi_object *obj;
1355 acpi_status status;
Axel Lin66904862010-07-20 15:19:52 -07001356 u32 devices = 0;
Carlos Corbacho81143522008-06-21 09:09:53 +01001357
1358 status = wmi_query_block(WMID_GUID2, 1, &out);
1359 if (ACPI_FAILURE(status))
1360 return 0;
1361
1362 obj = (union acpi_object *) out.pointer;
1363 if (obj && obj->type == ACPI_TYPE_BUFFER &&
1364 obj->buffer.length == sizeof(u32)) {
Axel Lin66904862010-07-20 15:19:52 -07001365 devices = *((u32 *) obj->buffer.pointer);
Carlos Corbacho81143522008-06-21 09:09:53 +01001366 }
Axel Lin66904862010-07-20 15:19:52 -07001367
1368 kfree(out.pointer);
1369 return devices;
Carlos Corbacho81143522008-06-21 09:09:53 +01001370}
1371
1372/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001373 * Platform device
1374 */
1375static int __devinit acer_platform_probe(struct platform_device *device)
1376{
1377 int err;
1378
1379 if (has_cap(ACER_CAP_MAILLED)) {
1380 err = acer_led_init(&device->dev);
1381 if (err)
1382 goto error_mailled;
1383 }
1384
1385 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1386 err = acer_backlight_init(&device->dev);
1387 if (err)
1388 goto error_brightness;
1389 }
1390
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001391 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01001392 if (err)
1393 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001394
1395 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001396
Andy Whitcroft350e3292009-04-04 09:33:34 +01001397error_rfkill:
1398 if (has_cap(ACER_CAP_BRIGHTNESS))
1399 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001400error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01001401 if (has_cap(ACER_CAP_MAILLED))
1402 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001403error_mailled:
1404 return err;
1405}
1406
1407static int acer_platform_remove(struct platform_device *device)
1408{
1409 if (has_cap(ACER_CAP_MAILLED))
1410 acer_led_exit();
1411 if (has_cap(ACER_CAP_BRIGHTNESS))
1412 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001413
1414 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001415 return 0;
1416}
1417
1418static int acer_platform_suspend(struct platform_device *dev,
1419pm_message_t state)
1420{
1421 u32 value;
1422 struct acer_data *data = &interface->data;
1423
1424 if (!data)
1425 return -ENOMEM;
1426
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001427 if (has_cap(ACER_CAP_MAILLED)) {
1428 get_u32(&value, ACER_CAP_MAILLED);
1429 data->mailled = value;
1430 }
1431
1432 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1433 get_u32(&value, ACER_CAP_BRIGHTNESS);
1434 data->brightness = value;
1435 }
1436
1437 return 0;
1438}
1439
1440static int acer_platform_resume(struct platform_device *device)
1441{
1442 struct acer_data *data = &interface->data;
1443
1444 if (!data)
1445 return -ENOMEM;
1446
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001447 if (has_cap(ACER_CAP_MAILLED))
1448 set_u32(data->mailled, ACER_CAP_MAILLED);
1449
1450 if (has_cap(ACER_CAP_BRIGHTNESS))
1451 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
1452
1453 return 0;
1454}
1455
1456static struct platform_driver acer_platform_driver = {
1457 .driver = {
1458 .name = "acer-wmi",
1459 .owner = THIS_MODULE,
1460 },
1461 .probe = acer_platform_probe,
1462 .remove = acer_platform_remove,
1463 .suspend = acer_platform_suspend,
1464 .resume = acer_platform_resume,
1465};
1466
1467static struct platform_device *acer_platform_device;
1468
1469static int remove_sysfs(struct platform_device *device)
1470{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001471 if (has_cap(ACER_CAP_THREEG))
1472 device_remove_file(&device->dev, &dev_attr_threeg);
1473
1474 device_remove_file(&device->dev, &dev_attr_interface);
1475
1476 return 0;
1477}
1478
1479static int create_sysfs(void)
1480{
1481 int retval = -ENOMEM;
1482
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001483 if (has_cap(ACER_CAP_THREEG)) {
1484 retval = device_create_file(&acer_platform_device->dev,
1485 &dev_attr_threeg);
1486 if (retval)
1487 goto error_sysfs;
1488 }
1489
1490 retval = device_create_file(&acer_platform_device->dev,
1491 &dev_attr_interface);
1492 if (retval)
1493 goto error_sysfs;
1494
1495 return 0;
1496
1497error_sysfs:
1498 remove_sysfs(acer_platform_device);
1499 return retval;
1500}
1501
Carlos Corbacho81143522008-06-21 09:09:53 +01001502static void remove_debugfs(void)
1503{
1504 debugfs_remove(interface->debug.devices);
1505 debugfs_remove(interface->debug.root);
1506}
1507
1508static int create_debugfs(void)
1509{
1510 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
1511 if (!interface->debug.root) {
1512 printk(ACER_ERR "Failed to create debugfs directory");
1513 return -ENOMEM;
1514 }
1515
1516 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
1517 interface->debug.root,
1518 &interface->debug.wmid_devices);
1519 if (!interface->debug.devices)
1520 goto error_debugfs;
1521
1522 return 0;
1523
1524error_debugfs:
Russ Dill39dbbb42008-09-02 14:35:40 -07001525 remove_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01001526 return -ENOMEM;
1527}
1528
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001529static int __init acer_wmi_init(void)
1530{
1531 int err;
1532
Carlos Corbacho860f0c62008-06-21 09:09:58 +01001533 printk(ACER_INFO "Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001534
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001535 if (dmi_check_system(acer_blacklist)) {
1536 printk(ACER_INFO "Blacklisted hardware detected - "
1537 "not loading\n");
1538 return -ENODEV;
1539 }
1540
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01001541 find_quirks();
1542
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001543 /*
1544 * Detect which ACPI-WMI interface we're using.
1545 */
1546 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1547 interface = &AMW0_V2_interface;
1548
1549 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1550 interface = &wmid_interface;
1551
1552 if (wmi_has_guid(WMID_GUID2) && interface) {
1553 if (ACPI_FAILURE(WMID_set_capabilities())) {
Carlos Corbacho8d039bc2008-03-12 20:12:50 +00001554 printk(ACER_ERR "Unable to detect available WMID "
1555 "devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001556 return -ENODEV;
1557 }
1558 } else if (!wmi_has_guid(WMID_GUID2) && interface) {
Carlos Corbacho8d039bc2008-03-12 20:12:50 +00001559 printk(ACER_ERR "No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001560 return -ENODEV;
1561 }
1562
1563 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
1564 interface = &AMW0_interface;
1565
1566 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Carlos Corbacho8d039bc2008-03-12 20:12:50 +00001567 printk(ACER_ERR "Unable to detect available AMW0 "
1568 "devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001569 return -ENODEV;
1570 }
1571 }
1572
Carlos Corbacho9b963c42008-02-24 13:34:29 +00001573 if (wmi_has_guid(AMW0_GUID1))
1574 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001575
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001576 if (!interface) {
Pascal de Bruijnaf9902e2010-08-30 09:09:53 +02001577 printk(ACER_INFO "No or unsupported WMI interface, unable to "
Carlos Corbacho8d039bc2008-03-12 20:12:50 +00001578 "load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001579 return -ENODEV;
1580 }
1581
Arjan van de Ven83097ac2008-08-23 21:45:21 -07001582 set_quirks();
1583
Michael Spang1ba869e2009-03-12 14:31:34 -07001584 if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS)) {
Thomas Renningerfebf2d92008-08-01 17:37:56 +02001585 interface->capability &= ~ACER_CAP_BRIGHTNESS;
1586 printk(ACER_INFO "Brightness must be controlled by "
1587 "generic video driver\n");
1588 }
1589
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001590 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
1591 err = acer_wmi_input_setup();
1592 if (err)
1593 return err;
1594 }
1595
Axel Lin1c796322010-06-22 16:17:38 +08001596 err = platform_driver_register(&acer_platform_driver);
1597 if (err) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001598 printk(ACER_ERR "Unable to register platform driver.\n");
1599 goto error_platform_register;
1600 }
Axel Lin1c796322010-06-22 16:17:38 +08001601
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001602 acer_platform_device = platform_device_alloc("acer-wmi", -1);
Axel Lin1c796322010-06-22 16:17:38 +08001603 if (!acer_platform_device) {
1604 err = -ENOMEM;
1605 goto error_device_alloc;
1606 }
1607
1608 err = platform_device_add(acer_platform_device);
1609 if (err)
1610 goto error_device_add;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001611
1612 err = create_sysfs();
1613 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08001614 goto error_create_sys;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001615
Carlos Corbacho81143522008-06-21 09:09:53 +01001616 if (wmi_has_guid(WMID_GUID2)) {
1617 interface->debug.wmid_devices = get_wmid_devices();
1618 err = create_debugfs();
1619 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08001620 goto error_create_debugfs;
Carlos Corbacho81143522008-06-21 09:09:53 +01001621 }
1622
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001623 /* Override any initial settings with values from the commandline */
1624 acer_commandline_init();
1625
1626 return 0;
1627
Axel Lin1c796322010-06-22 16:17:38 +08001628error_create_debugfs:
1629 remove_sysfs(acer_platform_device);
1630error_create_sys:
1631 platform_device_del(acer_platform_device);
1632error_device_add:
1633 platform_device_put(acer_platform_device);
1634error_device_alloc:
1635 platform_driver_unregister(&acer_platform_driver);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001636error_platform_register:
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001637 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1638 acer_wmi_input_destroy();
1639
Axel Lin1c796322010-06-22 16:17:38 +08001640 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001641}
1642
1643static void __exit acer_wmi_exit(void)
1644{
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001645 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1646 acer_wmi_input_destroy();
1647
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001648 remove_sysfs(acer_platform_device);
Russ Dill39dbbb42008-09-02 14:35:40 -07001649 remove_debugfs();
Axel Lin97ba0af2010-06-03 15:18:03 +08001650 platform_device_unregister(acer_platform_device);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001651 platform_driver_unregister(&acer_platform_driver);
1652
1653 printk(ACER_INFO "Acer Laptop WMI Extras unloaded\n");
1654 return;
1655}
1656
1657module_init(acer_wmi_init);
1658module_exit(acer_wmi_exit);