blob: a1c6141f463b088730840fd697e5b82f7e762093 [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>
Carlos Corbacho745a5d22008-02-05 02:17:10 +000042
43#include <acpi/acpi_drivers.h>
44
45MODULE_AUTHOR("Carlos Corbacho");
46MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
47MODULE_LICENSE("GPL");
48
49#define ACER_LOGPREFIX "acer-wmi: "
50#define ACER_ERR KERN_ERR ACER_LOGPREFIX
51#define ACER_NOTICE KERN_NOTICE ACER_LOGPREFIX
52#define ACER_INFO KERN_INFO ACER_LOGPREFIX
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080053#define ACER_WARNING KERN_WARNING ACER_LOGPREFIX
Carlos Corbacho745a5d22008-02-05 02:17:10 +000054
55/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +000056 * Magic Number
57 * Meaning is unknown - this number is required for writing to ACPI for AMW0
58 * (it's also used in acerhk when directly accessing the BIOS)
59 */
60#define ACER_AMW0_WRITE 0x9610
61
62/*
63 * Bit masks for the AMW0 interface
64 */
65#define ACER_AMW0_WIRELESS_MASK 0x35
66#define ACER_AMW0_BLUETOOTH_MASK 0x34
67#define ACER_AMW0_MAILLED_MASK 0x31
68
69/*
70 * Method IDs for WMID interface
71 */
72#define ACER_WMID_GET_WIRELESS_METHODID 1
73#define ACER_WMID_GET_BLUETOOTH_METHODID 2
74#define ACER_WMID_GET_BRIGHTNESS_METHODID 3
75#define ACER_WMID_SET_WIRELESS_METHODID 4
76#define ACER_WMID_SET_BLUETOOTH_METHODID 5
77#define ACER_WMID_SET_BRIGHTNESS_METHODID 6
78#define ACER_WMID_GET_THREEG_METHODID 10
79#define ACER_WMID_SET_THREEG_METHODID 11
80
81/*
82 * Acer ACPI method GUIDs
83 */
84#define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
Carlos Corbacho5753dd52008-06-21 09:09:48 +010085#define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
Carlos Corbacho745a5d22008-02-05 02:17:10 +000086#define WMID_GUID1 "6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3"
87#define WMID_GUID2 "95764E09-FB56-4e83-B31A-37761F60994A"
88
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080089/*
90 * Acer ACPI event GUIDs
91 */
92#define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
93
Carlos Corbacho745a5d22008-02-05 02:17:10 +000094MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
95MODULE_ALIAS("wmi:6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3");
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080096MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
97
98enum acer_wmi_event_ids {
99 WMID_HOTKEY_EVENT = 0x1,
100};
101
102static const struct key_entry acer_wmi_keymap[] = {
103 {KE_KEY, 0x01, {KEY_WLAN} }, /* WiFi */
104 {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */
105 {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */
106 {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */
107 {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */
108 {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */
109 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
110 {KE_KEY, 0x82, {KEY_F22} }, /* Touch Pad On/Off */
111 {KE_END, 0}
112};
113
114static struct input_dev *acer_wmi_input_dev;
115
116struct event_return_value {
117 u8 function;
118 u8 key_num;
119 u16 device_state;
120 u32 reserved;
121} __attribute__((packed));
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000122
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000123/*
124 * Interface capability flags
125 */
126#define ACER_CAP_MAILLED (1<<0)
127#define ACER_CAP_WIRELESS (1<<1)
128#define ACER_CAP_BLUETOOTH (1<<2)
129#define ACER_CAP_BRIGHTNESS (1<<3)
130#define ACER_CAP_THREEG (1<<4)
131#define ACER_CAP_ANY (0xFFFFFFFF)
132
133/*
134 * Interface type flags
135 */
136enum interface_flags {
137 ACER_AMW0,
138 ACER_AMW0_V2,
139 ACER_WMID,
140};
141
142#define ACER_DEFAULT_WIRELESS 0
143#define ACER_DEFAULT_BLUETOOTH 0
144#define ACER_DEFAULT_MAILLED 0
145#define ACER_DEFAULT_THREEG 0
146
147static int max_brightness = 0xF;
148
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000149static int mailled = -1;
150static int brightness = -1;
151static int threeg = -1;
152static int force_series;
153
154module_param(mailled, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000155module_param(brightness, int, 0444);
156module_param(threeg, int, 0444);
157module_param(force_series, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000158MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
159MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
160MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
161MODULE_PARM_DESC(force_series, "Force a different laptop series");
162
163struct acer_data {
164 int mailled;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000165 int threeg;
166 int brightness;
167};
168
Carlos Corbacho81143522008-06-21 09:09:53 +0100169struct acer_debug {
170 struct dentry *root;
171 struct dentry *devices;
172 u32 wmid_devices;
173};
174
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100175static struct rfkill *wireless_rfkill;
176static struct rfkill *bluetooth_rfkill;
177
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000178/* Each low-level interface must define at least some of the following */
179struct wmi_interface {
180 /* The WMI device type */
181 u32 type;
182
183 /* The capabilities this interface provides */
184 u32 capability;
185
186 /* Private data for the current interface */
187 struct acer_data data;
Carlos Corbacho81143522008-06-21 09:09:53 +0100188
189 /* debugfs entries associated with this interface */
190 struct acer_debug debug;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000191};
192
193/* The static interface pointer, points to the currently detected interface */
194static struct wmi_interface *interface;
195
196/*
197 * Embedded Controller quirks
198 * Some laptops require us to directly access the EC to either enable or query
199 * features that are not available through WMI.
200 */
201
202struct quirk_entry {
203 u8 wireless;
204 u8 mailled;
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100205 s8 brightness;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000206 u8 bluetooth;
207};
208
209static struct quirk_entry *quirks;
210
211static void set_quirks(void)
212{
Arjan van de Ven83097ac2008-08-23 21:45:21 -0700213 if (!interface)
214 return;
215
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000216 if (quirks->mailled)
217 interface->capability |= ACER_CAP_MAILLED;
218
219 if (quirks->brightness)
220 interface->capability |= ACER_CAP_BRIGHTNESS;
221}
222
223static int dmi_matched(const struct dmi_system_id *dmi)
224{
225 quirks = dmi->driver_data;
Axel Lind53bf0f2010-06-30 13:32:16 +0800226 return 1;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000227}
228
229static struct quirk_entry quirk_unknown = {
230};
231
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100232static struct quirk_entry quirk_acer_aspire_1520 = {
233 .brightness = -1,
234};
235
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000236static struct quirk_entry quirk_acer_travelmate_2490 = {
237 .mailled = 1,
238};
239
240/* This AMW0 laptop has no bluetooth */
241static struct quirk_entry quirk_medion_md_98300 = {
242 .wireless = 1,
243};
244
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100245static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
246 .wireless = 2,
247};
248
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100249/* The Aspire One has a dummy ACPI-WMI interface - disable it */
250static struct dmi_system_id __devinitdata acer_blacklist[] = {
251 {
252 .ident = "Acer Aspire One (SSD)",
253 .matches = {
254 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
255 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
256 },
257 },
258 {
259 .ident = "Acer Aspire One (HDD)",
260 .matches = {
261 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
262 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
263 },
264 },
265 {}
266};
267
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000268static struct dmi_system_id acer_quirks[] = {
269 {
270 .callback = dmi_matched,
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100271 .ident = "Acer Aspire 1360",
272 .matches = {
273 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
274 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
275 },
276 .driver_data = &quirk_acer_aspire_1520,
277 },
278 {
279 .callback = dmi_matched,
280 .ident = "Acer Aspire 1520",
281 .matches = {
282 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
283 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
284 },
285 .driver_data = &quirk_acer_aspire_1520,
286 },
287 {
288 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000289 .ident = "Acer Aspire 3100",
290 .matches = {
291 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
292 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
293 },
294 .driver_data = &quirk_acer_travelmate_2490,
295 },
296 {
297 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000298 .ident = "Acer Aspire 3610",
299 .matches = {
300 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
301 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
302 },
303 .driver_data = &quirk_acer_travelmate_2490,
304 },
305 {
306 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000307 .ident = "Acer Aspire 5100",
308 .matches = {
309 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
310 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
311 },
312 .driver_data = &quirk_acer_travelmate_2490,
313 },
314 {
315 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000316 .ident = "Acer Aspire 5610",
317 .matches = {
318 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
319 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
320 },
321 .driver_data = &quirk_acer_travelmate_2490,
322 },
323 {
324 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000325 .ident = "Acer Aspire 5630",
326 .matches = {
327 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
328 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
329 },
330 .driver_data = &quirk_acer_travelmate_2490,
331 },
332 {
333 .callback = dmi_matched,
334 .ident = "Acer Aspire 5650",
335 .matches = {
336 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
337 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
338 },
339 .driver_data = &quirk_acer_travelmate_2490,
340 },
341 {
342 .callback = dmi_matched,
343 .ident = "Acer Aspire 5680",
344 .matches = {
345 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
346 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
347 },
348 .driver_data = &quirk_acer_travelmate_2490,
349 },
350 {
351 .callback = dmi_matched,
352 .ident = "Acer Aspire 9110",
353 .matches = {
354 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
355 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
356 },
357 .driver_data = &quirk_acer_travelmate_2490,
358 },
359 {
360 .callback = dmi_matched,
361 .ident = "Acer TravelMate 2490",
362 .matches = {
363 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
364 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
365 },
366 .driver_data = &quirk_acer_travelmate_2490,
367 },
368 {
369 .callback = dmi_matched,
Carlos Corbacho262ee352008-02-16 00:02:56 +0000370 .ident = "Acer TravelMate 4200",
371 .matches = {
372 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
373 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
374 },
375 .driver_data = &quirk_acer_travelmate_2490,
376 },
377 {
378 .callback = dmi_matched,
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100379 .ident = "Fujitsu Siemens Amilo Li 1718",
380 .matches = {
381 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
382 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
383 },
384 .driver_data = &quirk_fujitsu_amilo_li_1718,
385 },
386 {
387 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000388 .ident = "Medion MD 98300",
389 .matches = {
390 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
391 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
392 },
393 .driver_data = &quirk_medion_md_98300,
394 },
395 {}
396};
397
398/* Find which quirks are needed for a particular vendor/ model pair */
399static void find_quirks(void)
400{
401 if (!force_series) {
402 dmi_check_system(acer_quirks);
403 } else if (force_series == 2490) {
404 quirks = &quirk_acer_travelmate_2490;
405 }
406
407 if (quirks == NULL)
408 quirks = &quirk_unknown;
409
410 set_quirks();
411}
412
413/*
414 * General interface convenience methods
415 */
416
417static bool has_cap(u32 cap)
418{
419 if ((interface->capability & cap) != 0)
420 return 1;
421
422 return 0;
423}
424
425/*
426 * AMW0 (V1) interface
427 */
428struct wmab_args {
429 u32 eax;
430 u32 ebx;
431 u32 ecx;
432 u32 edx;
433};
434
435struct wmab_ret {
436 u32 eax;
437 u32 ebx;
438 u32 ecx;
439 u32 edx;
440 u32 eex;
441};
442
443static acpi_status wmab_execute(struct wmab_args *regbuf,
444struct acpi_buffer *result)
445{
446 struct acpi_buffer input;
447 acpi_status status;
448 input.length = sizeof(struct wmab_args);
449 input.pointer = (u8 *)regbuf;
450
451 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
452
453 return status;
454}
455
456static acpi_status AMW0_get_u32(u32 *value, u32 cap,
457struct wmi_interface *iface)
458{
459 int err;
460 u8 result;
461
462 switch (cap) {
463 case ACER_CAP_MAILLED:
464 switch (quirks->mailled) {
465 default:
466 err = ec_read(0xA, &result);
467 if (err)
468 return AE_ERROR;
469 *value = (result >> 7) & 0x1;
470 return AE_OK;
471 }
472 break;
473 case ACER_CAP_WIRELESS:
474 switch (quirks->wireless) {
475 case 1:
476 err = ec_read(0x7B, &result);
477 if (err)
478 return AE_ERROR;
479 *value = result & 0x1;
480 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100481 case 2:
482 err = ec_read(0x71, &result);
483 if (err)
484 return AE_ERROR;
485 *value = result & 0x1;
486 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000487 default:
488 err = ec_read(0xA, &result);
489 if (err)
490 return AE_ERROR;
491 *value = (result >> 2) & 0x1;
492 return AE_OK;
493 }
494 break;
495 case ACER_CAP_BLUETOOTH:
496 switch (quirks->bluetooth) {
497 default:
498 err = ec_read(0xA, &result);
499 if (err)
500 return AE_ERROR;
501 *value = (result >> 4) & 0x1;
502 return AE_OK;
503 }
504 break;
505 case ACER_CAP_BRIGHTNESS:
506 switch (quirks->brightness) {
507 default:
508 err = ec_read(0x83, &result);
509 if (err)
510 return AE_ERROR;
511 *value = result;
512 return AE_OK;
513 }
514 break;
515 default:
Lin Ming08237972008-08-08 11:57:11 +0800516 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000517 }
518 return AE_OK;
519}
520
521static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
522{
523 struct wmab_args args;
524
525 args.eax = ACER_AMW0_WRITE;
526 args.ebx = value ? (1<<8) : 0;
527 args.ecx = args.edx = 0;
528
529 switch (cap) {
530 case ACER_CAP_MAILLED:
531 if (value > 1)
532 return AE_BAD_PARAMETER;
533 args.ebx |= ACER_AMW0_MAILLED_MASK;
534 break;
535 case ACER_CAP_WIRELESS:
536 if (value > 1)
537 return AE_BAD_PARAMETER;
538 args.ebx |= ACER_AMW0_WIRELESS_MASK;
539 break;
540 case ACER_CAP_BLUETOOTH:
541 if (value > 1)
542 return AE_BAD_PARAMETER;
543 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
544 break;
545 case ACER_CAP_BRIGHTNESS:
546 if (value > max_brightness)
547 return AE_BAD_PARAMETER;
548 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000549 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000550 return ec_write(0x83, value);
551 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000552 }
553 default:
Lin Ming08237972008-08-08 11:57:11 +0800554 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000555 }
556
557 /* Actually do the set */
558 return wmab_execute(&args, NULL);
559}
560
561static acpi_status AMW0_find_mailled(void)
562{
563 struct wmab_args args;
564 struct wmab_ret ret;
565 acpi_status status = AE_OK;
566 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
567 union acpi_object *obj;
568
569 args.eax = 0x86;
570 args.ebx = args.ecx = args.edx = 0;
571
572 status = wmab_execute(&args, &out);
573 if (ACPI_FAILURE(status))
574 return status;
575
576 obj = (union acpi_object *) out.pointer;
577 if (obj && obj->type == ACPI_TYPE_BUFFER &&
578 obj->buffer.length == sizeof(struct wmab_ret)) {
579 ret = *((struct wmab_ret *) obj->buffer.pointer);
580 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700581 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000582 return AE_ERROR;
583 }
584
585 if (ret.eex & 0x1)
586 interface->capability |= ACER_CAP_MAILLED;
587
588 kfree(out.pointer);
589
590 return AE_OK;
591}
592
593static acpi_status AMW0_set_capabilities(void)
594{
595 struct wmab_args args;
596 struct wmab_ret ret;
Axel Lin7677fbd2010-07-20 15:19:53 -0700597 acpi_status status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000598 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
599 union acpi_object *obj;
600
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100601 /*
602 * On laptops with this strange GUID (non Acer), normal probing doesn't
603 * work.
604 */
605 if (wmi_has_guid(AMW0_GUID2)) {
606 interface->capability |= ACER_CAP_WIRELESS;
607 return AE_OK;
608 }
609
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000610 args.eax = ACER_AMW0_WRITE;
611 args.ecx = args.edx = 0;
612
613 args.ebx = 0xa2 << 8;
614 args.ebx |= ACER_AMW0_WIRELESS_MASK;
615
616 status = wmab_execute(&args, &out);
617 if (ACPI_FAILURE(status))
618 return status;
619
Axel Lin7677fbd2010-07-20 15:19:53 -0700620 obj = out.pointer;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000621 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 status = AE_ERROR;
626 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000627 }
628
629 if (ret.eax & 0x1)
630 interface->capability |= ACER_CAP_WIRELESS;
631
632 args.ebx = 2 << 8;
633 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
634
Axel Lin7677fbd2010-07-20 15:19:53 -0700635 /*
636 * It's ok to use existing buffer for next wmab_execute call.
637 * But we need to kfree(out.pointer) if next wmab_execute fail.
638 */
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000639 status = wmab_execute(&args, &out);
640 if (ACPI_FAILURE(status))
Axel Lin7677fbd2010-07-20 15:19:53 -0700641 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000642
643 obj = (union acpi_object *) out.pointer;
644 if (obj && obj->type == ACPI_TYPE_BUFFER
645 && obj->buffer.length == sizeof(struct wmab_ret)) {
646 ret = *((struct wmab_ret *) obj->buffer.pointer);
647 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700648 status = AE_ERROR;
649 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000650 }
651
652 if (ret.eax & 0x1)
653 interface->capability |= ACER_CAP_BLUETOOTH;
654
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000655 /*
656 * This appears to be safe to enable, since all Wistron based laptops
657 * appear to use the same EC register for brightness, even if they
658 * differ for wireless, etc
659 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100660 if (quirks->brightness >= 0)
661 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000662
Axel Lin7677fbd2010-07-20 15:19:53 -0700663 status = AE_OK;
664out:
665 kfree(out.pointer);
666 return status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000667}
668
669static struct wmi_interface AMW0_interface = {
670 .type = ACER_AMW0,
671};
672
673static struct wmi_interface AMW0_V2_interface = {
674 .type = ACER_AMW0_V2,
675};
676
677/*
678 * New interface (The WMID interface)
679 */
680static acpi_status
681WMI_execute_u32(u32 method_id, u32 in, u32 *out)
682{
683 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
684 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
685 union acpi_object *obj;
686 u32 tmp;
687 acpi_status status;
688
689 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
690
691 if (ACPI_FAILURE(status))
692 return status;
693
694 obj = (union acpi_object *) result.pointer;
695 if (obj && obj->type == ACPI_TYPE_BUFFER &&
696 obj->buffer.length == sizeof(u32)) {
697 tmp = *((u32 *) obj->buffer.pointer);
698 } else {
699 tmp = 0;
700 }
701
702 if (out)
703 *out = tmp;
704
705 kfree(result.pointer);
706
707 return status;
708}
709
710static acpi_status WMID_get_u32(u32 *value, u32 cap,
711struct wmi_interface *iface)
712{
713 acpi_status status;
714 u8 tmp;
715 u32 result, method_id = 0;
716
717 switch (cap) {
718 case ACER_CAP_WIRELESS:
719 method_id = ACER_WMID_GET_WIRELESS_METHODID;
720 break;
721 case ACER_CAP_BLUETOOTH:
722 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
723 break;
724 case ACER_CAP_BRIGHTNESS:
725 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
726 break;
727 case ACER_CAP_THREEG:
728 method_id = ACER_WMID_GET_THREEG_METHODID;
729 break;
730 case ACER_CAP_MAILLED:
731 if (quirks->mailled == 1) {
732 ec_read(0x9f, &tmp);
733 *value = tmp & 0x1;
734 return 0;
735 }
736 default:
Lin Ming08237972008-08-08 11:57:11 +0800737 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000738 }
739 status = WMI_execute_u32(method_id, 0, &result);
740
741 if (ACPI_SUCCESS(status))
742 *value = (u8)result;
743
744 return status;
745}
746
747static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
748{
749 u32 method_id = 0;
750 char param;
751
752 switch (cap) {
753 case ACER_CAP_BRIGHTNESS:
754 if (value > max_brightness)
755 return AE_BAD_PARAMETER;
756 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
757 break;
758 case ACER_CAP_WIRELESS:
759 if (value > 1)
760 return AE_BAD_PARAMETER;
761 method_id = ACER_WMID_SET_WIRELESS_METHODID;
762 break;
763 case ACER_CAP_BLUETOOTH:
764 if (value > 1)
765 return AE_BAD_PARAMETER;
766 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
767 break;
768 case ACER_CAP_THREEG:
769 if (value > 1)
770 return AE_BAD_PARAMETER;
771 method_id = ACER_WMID_SET_THREEG_METHODID;
772 break;
773 case ACER_CAP_MAILLED:
774 if (value > 1)
775 return AE_BAD_PARAMETER;
776 if (quirks->mailled == 1) {
777 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700778 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000779 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700780 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000781 return 0;
782 }
783 break;
784 default:
Lin Ming08237972008-08-08 11:57:11 +0800785 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000786 }
787 return WMI_execute_u32(method_id, (u32)value, NULL);
788}
789
790static acpi_status WMID_set_capabilities(void)
791{
792 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
793 union acpi_object *obj;
794 acpi_status status;
795 u32 devices;
796
797 status = wmi_query_block(WMID_GUID2, 1, &out);
798 if (ACPI_FAILURE(status))
799 return status;
800
801 obj = (union acpi_object *) out.pointer;
802 if (obj && obj->type == ACPI_TYPE_BUFFER &&
803 obj->buffer.length == sizeof(u32)) {
804 devices = *((u32 *) obj->buffer.pointer);
805 } else {
Axel Lin66904862010-07-20 15:19:52 -0700806 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000807 return AE_ERROR;
808 }
809
810 /* Not sure on the meaning of the relevant bits yet to detect these */
811 interface->capability |= ACER_CAP_WIRELESS;
812 interface->capability |= ACER_CAP_THREEG;
813
814 /* WMID always provides brightness methods */
815 interface->capability |= ACER_CAP_BRIGHTNESS;
816
817 if (devices & 0x10)
818 interface->capability |= ACER_CAP_BLUETOOTH;
819
820 if (!(devices & 0x20))
821 max_brightness = 0x9;
822
Axel Lin66904862010-07-20 15:19:52 -0700823 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000824 return status;
825}
826
827static struct wmi_interface wmid_interface = {
828 .type = ACER_WMID,
829};
830
831/*
832 * Generic Device (interface-independent)
833 */
834
835static acpi_status get_u32(u32 *value, u32 cap)
836{
Lin Ming08237972008-08-08 11:57:11 +0800837 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000838
839 switch (interface->type) {
840 case ACER_AMW0:
841 status = AMW0_get_u32(value, cap, interface);
842 break;
843 case ACER_AMW0_V2:
844 if (cap == ACER_CAP_MAILLED) {
845 status = AMW0_get_u32(value, cap, interface);
846 break;
847 }
848 case ACER_WMID:
849 status = WMID_get_u32(value, cap, interface);
850 break;
851 }
852
853 return status;
854}
855
856static acpi_status set_u32(u32 value, u32 cap)
857{
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100858 acpi_status status;
859
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000860 if (interface->capability & cap) {
861 switch (interface->type) {
862 case ACER_AMW0:
863 return AMW0_set_u32(value, cap, interface);
864 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100865 if (cap == ACER_CAP_MAILLED)
866 return AMW0_set_u32(value, cap, interface);
867
868 /*
869 * On some models, some WMID methods don't toggle
870 * properly. For those cases, we want to run the AMW0
871 * method afterwards to be certain we've really toggled
872 * the device state.
873 */
874 if (cap == ACER_CAP_WIRELESS ||
875 cap == ACER_CAP_BLUETOOTH) {
876 status = WMID_set_u32(value, cap, interface);
877 if (ACPI_FAILURE(status))
878 return status;
879
880 return AMW0_set_u32(value, cap, interface);
881 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000882 case ACER_WMID:
883 return WMID_set_u32(value, cap, interface);
884 default:
885 return AE_BAD_PARAMETER;
886 }
887 }
888 return AE_BAD_PARAMETER;
889}
890
891static void __init acer_commandline_init(void)
892{
893 /*
894 * These will all fail silently if the value given is invalid, or the
895 * capability isn't available on the given interface
896 */
897 set_u32(mailled, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000898 set_u32(threeg, ACER_CAP_THREEG);
899 set_u32(brightness, ACER_CAP_BRIGHTNESS);
900}
901
902/*
903 * LED device (Mail LED only, no other LEDs known yet)
904 */
905static void mail_led_set(struct led_classdev *led_cdev,
906enum led_brightness value)
907{
908 set_u32(value, ACER_CAP_MAILLED);
909}
910
911static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +0000912 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000913 .brightness_set = mail_led_set,
914};
915
Sam Ravnborg7560e382008-02-17 13:22:54 +0100916static int __devinit acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000917{
918 return led_classdev_register(dev, &mail_led);
919}
920
921static void acer_led_exit(void)
922{
923 led_classdev_unregister(&mail_led);
924}
925
926/*
927 * Backlight device
928 */
929static struct backlight_device *acer_backlight_device;
930
931static int read_brightness(struct backlight_device *bd)
932{
933 u32 value;
934 get_u32(&value, ACER_CAP_BRIGHTNESS);
935 return value;
936}
937
938static int update_bl_status(struct backlight_device *bd)
939{
Carlos Corbachof2b585b2008-06-21 09:09:27 +0100940 int intensity = bd->props.brightness;
941
942 if (bd->props.power != FB_BLANK_UNBLANK)
943 intensity = 0;
944 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
945 intensity = 0;
946
947 set_u32(intensity, ACER_CAP_BRIGHTNESS);
948
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000949 return 0;
950}
951
952static struct backlight_ops acer_bl_ops = {
953 .get_brightness = read_brightness,
954 .update_status = update_bl_status,
955};
956
Sam Ravnborg7560e382008-02-17 13:22:54 +0100957static int __devinit acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000958{
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500959 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000960 struct backlight_device *bd;
961
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500962 memset(&props, 0, sizeof(struct backlight_properties));
963 props.max_brightness = max_brightness;
964 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
965 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000966 if (IS_ERR(bd)) {
967 printk(ACER_ERR "Could not register Acer backlight device\n");
968 acer_backlight_device = NULL;
969 return PTR_ERR(bd);
970 }
971
972 acer_backlight_device = bd;
973
Carlos Corbachof2b585b2008-06-21 09:09:27 +0100974 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +0000975 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000976 backlight_update_status(bd);
977 return 0;
978}
979
Sam Ravnborg7560e382008-02-17 13:22:54 +0100980static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000981{
982 backlight_device_unregister(acer_backlight_device);
983}
984
985/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100986 * Rfkill devices
987 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100988static void acer_rfkill_update(struct work_struct *ignored);
989static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
990static void acer_rfkill_update(struct work_struct *ignored)
991{
992 u32 state;
993 acpi_status status;
994
995 status = get_u32(&state, ACER_CAP_WIRELESS);
996 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +0100997 rfkill_set_sw_state(wireless_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100998
999 if (has_cap(ACER_CAP_BLUETOOTH)) {
1000 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1001 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001002 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001003 }
1004
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001005 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001006}
1007
Johannes Berg19d337d2009-06-02 13:01:37 +02001008static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001009{
1010 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +02001011 u32 cap = (unsigned long)data;
Alan Jenkinsed5c8ef2009-07-19 09:48:28 +01001012 status = set_u32(!blocked, cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001013 if (ACPI_FAILURE(status))
1014 return -ENODEV;
1015 return 0;
1016}
1017
Johannes Berg19d337d2009-06-02 13:01:37 +02001018static const struct rfkill_ops acer_rfkill_ops = {
1019 .set_block = acer_rfkill_set,
1020};
1021
1022static struct rfkill *acer_rfkill_register(struct device *dev,
1023 enum rfkill_type type,
1024 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001025{
1026 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001027 struct rfkill *rfkill_dev;
1028
Johannes Berg19d337d2009-06-02 13:01:37 +02001029 rfkill_dev = rfkill_alloc(name, dev, type,
1030 &acer_rfkill_ops,
1031 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001032 if (!rfkill_dev)
1033 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001034
1035 err = rfkill_register(rfkill_dev);
1036 if (err) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001037 rfkill_destroy(rfkill_dev);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001038 return ERR_PTR(err);
1039 }
1040 return rfkill_dev;
1041}
1042
1043static int acer_rfkill_init(struct device *dev)
1044{
1045 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1046 "acer-wireless", ACER_CAP_WIRELESS);
1047 if (IS_ERR(wireless_rfkill))
1048 return PTR_ERR(wireless_rfkill);
1049
1050 if (has_cap(ACER_CAP_BLUETOOTH)) {
1051 bluetooth_rfkill = acer_rfkill_register(dev,
1052 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1053 ACER_CAP_BLUETOOTH);
1054 if (IS_ERR(bluetooth_rfkill)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001055 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001056 rfkill_destroy(wireless_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001057 return PTR_ERR(bluetooth_rfkill);
1058 }
1059 }
1060
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001061 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001062
1063 return 0;
1064}
1065
1066static void acer_rfkill_exit(void)
1067{
1068 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001069
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001070 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001071 rfkill_destroy(wireless_rfkill);
1072
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001073 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001074 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001075 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001076 }
1077 return;
1078}
1079
1080/*
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001081 * sysfs interface
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001082 */
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001083static ssize_t show_bool_threeg(struct device *dev,
1084 struct device_attribute *attr, char *buf)
1085{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001086 u32 result; \
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001087 acpi_status status = get_u32(&result, ACER_CAP_THREEG);
1088 if (ACPI_SUCCESS(status))
1089 return sprintf(buf, "%u\n", result);
1090 return sprintf(buf, "Read error\n");
1091}
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001092
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001093static ssize_t set_bool_threeg(struct device *dev,
1094 struct device_attribute *attr, const char *buf, size_t count)
1095{
1096 u32 tmp = simple_strtoul(buf, NULL, 10);
1097 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
1098 if (ACPI_FAILURE(status))
1099 return -EINVAL;
1100 return count;
1101}
1102static DEVICE_ATTR(threeg, S_IWUGO | S_IRUGO | S_IWUSR, show_bool_threeg,
1103 set_bool_threeg);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001104
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001105static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1106 char *buf)
1107{
1108 switch (interface->type) {
1109 case ACER_AMW0:
1110 return sprintf(buf, "AMW0\n");
1111 case ACER_AMW0_V2:
1112 return sprintf(buf, "AMW0 v2\n");
1113 case ACER_WMID:
1114 return sprintf(buf, "WMID\n");
1115 default:
1116 return sprintf(buf, "Error!\n");
1117 }
1118}
1119
Axel Lin370525d2010-06-30 10:20:23 +08001120static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001121
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001122static void acer_wmi_notify(u32 value, void *context)
1123{
1124 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1125 union acpi_object *obj;
1126 struct event_return_value return_value;
1127 acpi_status status;
1128
1129 status = wmi_get_event_data(value, &response);
1130 if (status != AE_OK) {
1131 printk(ACER_WARNING "bad event status 0x%x\n", status);
1132 return;
1133 }
1134
1135 obj = (union acpi_object *)response.pointer;
1136
1137 if (!obj)
1138 return;
1139 if (obj->type != ACPI_TYPE_BUFFER) {
1140 printk(ACER_WARNING "Unknown response received %d\n",
1141 obj->type);
1142 kfree(obj);
1143 return;
1144 }
1145 if (obj->buffer.length != 8) {
1146 printk(ACER_WARNING "Unknown buffer length %d\n",
1147 obj->buffer.length);
1148 kfree(obj);
1149 return;
1150 }
1151
1152 return_value = *((struct event_return_value *)obj->buffer.pointer);
1153 kfree(obj);
1154
1155 switch (return_value.function) {
1156 case WMID_HOTKEY_EVENT:
1157 if (!sparse_keymap_report_event(acer_wmi_input_dev,
1158 return_value.key_num, 1, true))
1159 printk(ACER_WARNING "Unknown key number - 0x%x\n",
1160 return_value.key_num);
1161 break;
1162 default:
1163 printk(ACER_WARNING "Unknown function number - %d - %d\n",
1164 return_value.function, return_value.key_num);
1165 break;
1166 }
1167}
1168
1169static int __init acer_wmi_input_setup(void)
1170{
1171 acpi_status status;
1172 int err;
1173
1174 acer_wmi_input_dev = input_allocate_device();
1175 if (!acer_wmi_input_dev)
1176 return -ENOMEM;
1177
1178 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1179 acer_wmi_input_dev->phys = "wmi/input0";
1180 acer_wmi_input_dev->id.bustype = BUS_HOST;
1181
1182 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1183 if (err)
1184 goto err_free_dev;
1185
1186 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1187 acer_wmi_notify, NULL);
1188 if (ACPI_FAILURE(status)) {
1189 err = -EIO;
1190 goto err_free_keymap;
1191 }
1192
1193 err = input_register_device(acer_wmi_input_dev);
1194 if (err)
1195 goto err_uninstall_notifier;
1196
1197 return 0;
1198
1199err_uninstall_notifier:
1200 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1201err_free_keymap:
1202 sparse_keymap_free(acer_wmi_input_dev);
1203err_free_dev:
1204 input_free_device(acer_wmi_input_dev);
1205 return err;
1206}
1207
1208static void acer_wmi_input_destroy(void)
1209{
1210 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1211 sparse_keymap_free(acer_wmi_input_dev);
1212 input_unregister_device(acer_wmi_input_dev);
1213}
1214
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001215/*
Carlos Corbacho81143522008-06-21 09:09:53 +01001216 * debugfs functions
1217 */
1218static u32 get_wmid_devices(void)
1219{
1220 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1221 union acpi_object *obj;
1222 acpi_status status;
Axel Lin66904862010-07-20 15:19:52 -07001223 u32 devices = 0;
Carlos Corbacho81143522008-06-21 09:09:53 +01001224
1225 status = wmi_query_block(WMID_GUID2, 1, &out);
1226 if (ACPI_FAILURE(status))
1227 return 0;
1228
1229 obj = (union acpi_object *) out.pointer;
1230 if (obj && obj->type == ACPI_TYPE_BUFFER &&
1231 obj->buffer.length == sizeof(u32)) {
Axel Lin66904862010-07-20 15:19:52 -07001232 devices = *((u32 *) obj->buffer.pointer);
Carlos Corbacho81143522008-06-21 09:09:53 +01001233 }
Axel Lin66904862010-07-20 15:19:52 -07001234
1235 kfree(out.pointer);
1236 return devices;
Carlos Corbacho81143522008-06-21 09:09:53 +01001237}
1238
1239/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001240 * Platform device
1241 */
1242static int __devinit acer_platform_probe(struct platform_device *device)
1243{
1244 int err;
1245
1246 if (has_cap(ACER_CAP_MAILLED)) {
1247 err = acer_led_init(&device->dev);
1248 if (err)
1249 goto error_mailled;
1250 }
1251
1252 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1253 err = acer_backlight_init(&device->dev);
1254 if (err)
1255 goto error_brightness;
1256 }
1257
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001258 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01001259 if (err)
1260 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001261
1262 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001263
Andy Whitcroft350e3292009-04-04 09:33:34 +01001264error_rfkill:
1265 if (has_cap(ACER_CAP_BRIGHTNESS))
1266 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001267error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01001268 if (has_cap(ACER_CAP_MAILLED))
1269 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001270error_mailled:
1271 return err;
1272}
1273
1274static int acer_platform_remove(struct platform_device *device)
1275{
1276 if (has_cap(ACER_CAP_MAILLED))
1277 acer_led_exit();
1278 if (has_cap(ACER_CAP_BRIGHTNESS))
1279 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001280
1281 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001282 return 0;
1283}
1284
1285static int acer_platform_suspend(struct platform_device *dev,
1286pm_message_t state)
1287{
1288 u32 value;
1289 struct acer_data *data = &interface->data;
1290
1291 if (!data)
1292 return -ENOMEM;
1293
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001294 if (has_cap(ACER_CAP_MAILLED)) {
1295 get_u32(&value, ACER_CAP_MAILLED);
1296 data->mailled = value;
1297 }
1298
1299 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1300 get_u32(&value, ACER_CAP_BRIGHTNESS);
1301 data->brightness = value;
1302 }
1303
1304 return 0;
1305}
1306
1307static int acer_platform_resume(struct platform_device *device)
1308{
1309 struct acer_data *data = &interface->data;
1310
1311 if (!data)
1312 return -ENOMEM;
1313
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001314 if (has_cap(ACER_CAP_MAILLED))
1315 set_u32(data->mailled, ACER_CAP_MAILLED);
1316
1317 if (has_cap(ACER_CAP_BRIGHTNESS))
1318 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
1319
1320 return 0;
1321}
1322
1323static struct platform_driver acer_platform_driver = {
1324 .driver = {
1325 .name = "acer-wmi",
1326 .owner = THIS_MODULE,
1327 },
1328 .probe = acer_platform_probe,
1329 .remove = acer_platform_remove,
1330 .suspend = acer_platform_suspend,
1331 .resume = acer_platform_resume,
1332};
1333
1334static struct platform_device *acer_platform_device;
1335
1336static int remove_sysfs(struct platform_device *device)
1337{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001338 if (has_cap(ACER_CAP_THREEG))
1339 device_remove_file(&device->dev, &dev_attr_threeg);
1340
1341 device_remove_file(&device->dev, &dev_attr_interface);
1342
1343 return 0;
1344}
1345
1346static int create_sysfs(void)
1347{
1348 int retval = -ENOMEM;
1349
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001350 if (has_cap(ACER_CAP_THREEG)) {
1351 retval = device_create_file(&acer_platform_device->dev,
1352 &dev_attr_threeg);
1353 if (retval)
1354 goto error_sysfs;
1355 }
1356
1357 retval = device_create_file(&acer_platform_device->dev,
1358 &dev_attr_interface);
1359 if (retval)
1360 goto error_sysfs;
1361
1362 return 0;
1363
1364error_sysfs:
1365 remove_sysfs(acer_platform_device);
1366 return retval;
1367}
1368
Carlos Corbacho81143522008-06-21 09:09:53 +01001369static void remove_debugfs(void)
1370{
1371 debugfs_remove(interface->debug.devices);
1372 debugfs_remove(interface->debug.root);
1373}
1374
1375static int create_debugfs(void)
1376{
1377 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
1378 if (!interface->debug.root) {
1379 printk(ACER_ERR "Failed to create debugfs directory");
1380 return -ENOMEM;
1381 }
1382
1383 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
1384 interface->debug.root,
1385 &interface->debug.wmid_devices);
1386 if (!interface->debug.devices)
1387 goto error_debugfs;
1388
1389 return 0;
1390
1391error_debugfs:
Russ Dill39dbbb42008-09-02 14:35:40 -07001392 remove_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01001393 return -ENOMEM;
1394}
1395
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001396static int __init acer_wmi_init(void)
1397{
1398 int err;
1399
Carlos Corbacho860f0c62008-06-21 09:09:58 +01001400 printk(ACER_INFO "Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001401
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001402 if (dmi_check_system(acer_blacklist)) {
1403 printk(ACER_INFO "Blacklisted hardware detected - "
1404 "not loading\n");
1405 return -ENODEV;
1406 }
1407
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01001408 find_quirks();
1409
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001410 /*
1411 * Detect which ACPI-WMI interface we're using.
1412 */
1413 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1414 interface = &AMW0_V2_interface;
1415
1416 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1417 interface = &wmid_interface;
1418
1419 if (wmi_has_guid(WMID_GUID2) && interface) {
1420 if (ACPI_FAILURE(WMID_set_capabilities())) {
Carlos Corbacho8d039bc2008-03-12 20:12:50 +00001421 printk(ACER_ERR "Unable to detect available WMID "
1422 "devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001423 return -ENODEV;
1424 }
1425 } else if (!wmi_has_guid(WMID_GUID2) && interface) {
Carlos Corbacho8d039bc2008-03-12 20:12:50 +00001426 printk(ACER_ERR "No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001427 return -ENODEV;
1428 }
1429
1430 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
1431 interface = &AMW0_interface;
1432
1433 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Carlos Corbacho8d039bc2008-03-12 20:12:50 +00001434 printk(ACER_ERR "Unable to detect available AMW0 "
1435 "devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001436 return -ENODEV;
1437 }
1438 }
1439
Carlos Corbacho9b963c42008-02-24 13:34:29 +00001440 if (wmi_has_guid(AMW0_GUID1))
1441 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001442
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001443 if (!interface) {
Pascal de Bruijnaf9902e2010-08-30 09:09:53 +02001444 printk(ACER_INFO "No or unsupported WMI interface, unable to "
Carlos Corbacho8d039bc2008-03-12 20:12:50 +00001445 "load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001446 return -ENODEV;
1447 }
1448
Arjan van de Ven83097ac2008-08-23 21:45:21 -07001449 set_quirks();
1450
Michael Spang1ba869e2009-03-12 14:31:34 -07001451 if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS)) {
Thomas Renningerfebf2d92008-08-01 17:37:56 +02001452 interface->capability &= ~ACER_CAP_BRIGHTNESS;
1453 printk(ACER_INFO "Brightness must be controlled by "
1454 "generic video driver\n");
1455 }
1456
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001457 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
1458 err = acer_wmi_input_setup();
1459 if (err)
1460 return err;
1461 }
1462
Axel Lin1c796322010-06-22 16:17:38 +08001463 err = platform_driver_register(&acer_platform_driver);
1464 if (err) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001465 printk(ACER_ERR "Unable to register platform driver.\n");
1466 goto error_platform_register;
1467 }
Axel Lin1c796322010-06-22 16:17:38 +08001468
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001469 acer_platform_device = platform_device_alloc("acer-wmi", -1);
Axel Lin1c796322010-06-22 16:17:38 +08001470 if (!acer_platform_device) {
1471 err = -ENOMEM;
1472 goto error_device_alloc;
1473 }
1474
1475 err = platform_device_add(acer_platform_device);
1476 if (err)
1477 goto error_device_add;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001478
1479 err = create_sysfs();
1480 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08001481 goto error_create_sys;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001482
Carlos Corbacho81143522008-06-21 09:09:53 +01001483 if (wmi_has_guid(WMID_GUID2)) {
1484 interface->debug.wmid_devices = get_wmid_devices();
1485 err = create_debugfs();
1486 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08001487 goto error_create_debugfs;
Carlos Corbacho81143522008-06-21 09:09:53 +01001488 }
1489
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001490 /* Override any initial settings with values from the commandline */
1491 acer_commandline_init();
1492
1493 return 0;
1494
Axel Lin1c796322010-06-22 16:17:38 +08001495error_create_debugfs:
1496 remove_sysfs(acer_platform_device);
1497error_create_sys:
1498 platform_device_del(acer_platform_device);
1499error_device_add:
1500 platform_device_put(acer_platform_device);
1501error_device_alloc:
1502 platform_driver_unregister(&acer_platform_driver);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001503error_platform_register:
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001504 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1505 acer_wmi_input_destroy();
1506
Axel Lin1c796322010-06-22 16:17:38 +08001507 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001508}
1509
1510static void __exit acer_wmi_exit(void)
1511{
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001512 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1513 acer_wmi_input_destroy();
1514
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001515 remove_sysfs(acer_platform_device);
Russ Dill39dbbb42008-09-02 14:35:40 -07001516 remove_debugfs();
Axel Lin97ba0af2010-06-03 15:18:03 +08001517 platform_device_unregister(acer_platform_device);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001518 platform_driver_unregister(&acer_platform_driver);
1519
1520 printk(ACER_INFO "Acer Laptop WMI Extras unloaded\n");
1521 return;
1522}
1523
1524module_init(acer_wmi_init);
1525module_exit(acer_wmi_exit);