blob: cbca40aa400612f7a61b8a7267e4efbec51c6bdd [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>
Carlos Corbacho745a5d22008-02-05 02:17:10 +000039
40#include <acpi/acpi_drivers.h>
41
42MODULE_AUTHOR("Carlos Corbacho");
43MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
44MODULE_LICENSE("GPL");
45
46#define ACER_LOGPREFIX "acer-wmi: "
47#define ACER_ERR KERN_ERR ACER_LOGPREFIX
48#define ACER_NOTICE KERN_NOTICE ACER_LOGPREFIX
49#define ACER_INFO KERN_INFO ACER_LOGPREFIX
50
51/*
52 * The following defines quirks to get some specific functions to work
53 * which are known to not be supported over ACPI-WMI (such as the mail LED
54 * on WMID based Acer's)
55 */
56struct acer_quirks {
57 const char *vendor;
58 const char *model;
59 u16 quirks;
60};
61
62/*
63 * Magic Number
64 * Meaning is unknown - this number is required for writing to ACPI for AMW0
65 * (it's also used in acerhk when directly accessing the BIOS)
66 */
67#define ACER_AMW0_WRITE 0x9610
68
69/*
70 * Bit masks for the AMW0 interface
71 */
72#define ACER_AMW0_WIRELESS_MASK 0x35
73#define ACER_AMW0_BLUETOOTH_MASK 0x34
74#define ACER_AMW0_MAILLED_MASK 0x31
75
76/*
77 * Method IDs for WMID interface
78 */
79#define ACER_WMID_GET_WIRELESS_METHODID 1
80#define ACER_WMID_GET_BLUETOOTH_METHODID 2
81#define ACER_WMID_GET_BRIGHTNESS_METHODID 3
82#define ACER_WMID_SET_WIRELESS_METHODID 4
83#define ACER_WMID_SET_BLUETOOTH_METHODID 5
84#define ACER_WMID_SET_BRIGHTNESS_METHODID 6
85#define ACER_WMID_GET_THREEG_METHODID 10
86#define ACER_WMID_SET_THREEG_METHODID 11
87
88/*
89 * Acer ACPI method GUIDs
90 */
91#define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
Carlos Corbacho5753dd52008-06-21 09:09:48 +010092#define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
Carlos Corbacho745a5d22008-02-05 02:17:10 +000093#define WMID_GUID1 "6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3"
94#define WMID_GUID2 "95764E09-FB56-4e83-B31A-37761F60994A"
95
96MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
97MODULE_ALIAS("wmi:6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3");
98
Carlos Corbacho745a5d22008-02-05 02:17:10 +000099/*
100 * Interface capability flags
101 */
102#define ACER_CAP_MAILLED (1<<0)
103#define ACER_CAP_WIRELESS (1<<1)
104#define ACER_CAP_BLUETOOTH (1<<2)
105#define ACER_CAP_BRIGHTNESS (1<<3)
106#define ACER_CAP_THREEG (1<<4)
107#define ACER_CAP_ANY (0xFFFFFFFF)
108
109/*
110 * Interface type flags
111 */
112enum interface_flags {
113 ACER_AMW0,
114 ACER_AMW0_V2,
115 ACER_WMID,
116};
117
118#define ACER_DEFAULT_WIRELESS 0
119#define ACER_DEFAULT_BLUETOOTH 0
120#define ACER_DEFAULT_MAILLED 0
121#define ACER_DEFAULT_THREEG 0
122
123static int max_brightness = 0xF;
124
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000125static int mailled = -1;
126static int brightness = -1;
127static int threeg = -1;
128static int force_series;
129
130module_param(mailled, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000131module_param(brightness, int, 0444);
132module_param(threeg, int, 0444);
133module_param(force_series, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000134MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
135MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
136MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
137MODULE_PARM_DESC(force_series, "Force a different laptop series");
138
139struct acer_data {
140 int mailled;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000141 int threeg;
142 int brightness;
143};
144
Carlos Corbacho81143522008-06-21 09:09:53 +0100145struct acer_debug {
146 struct dentry *root;
147 struct dentry *devices;
148 u32 wmid_devices;
149};
150
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100151static struct rfkill *wireless_rfkill;
152static struct rfkill *bluetooth_rfkill;
153
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000154/* Each low-level interface must define at least some of the following */
155struct wmi_interface {
156 /* The WMI device type */
157 u32 type;
158
159 /* The capabilities this interface provides */
160 u32 capability;
161
162 /* Private data for the current interface */
163 struct acer_data data;
Carlos Corbacho81143522008-06-21 09:09:53 +0100164
165 /* debugfs entries associated with this interface */
166 struct acer_debug debug;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000167};
168
169/* The static interface pointer, points to the currently detected interface */
170static struct wmi_interface *interface;
171
172/*
173 * Embedded Controller quirks
174 * Some laptops require us to directly access the EC to either enable or query
175 * features that are not available through WMI.
176 */
177
178struct quirk_entry {
179 u8 wireless;
180 u8 mailled;
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100181 s8 brightness;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000182 u8 bluetooth;
183};
184
185static struct quirk_entry *quirks;
186
187static void set_quirks(void)
188{
Arjan van de Ven83097ac2008-08-23 21:45:21 -0700189 if (!interface)
190 return;
191
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000192 if (quirks->mailled)
193 interface->capability |= ACER_CAP_MAILLED;
194
195 if (quirks->brightness)
196 interface->capability |= ACER_CAP_BRIGHTNESS;
197}
198
199static int dmi_matched(const struct dmi_system_id *dmi)
200{
201 quirks = dmi->driver_data;
202 return 0;
203}
204
205static struct quirk_entry quirk_unknown = {
206};
207
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100208static struct quirk_entry quirk_acer_aspire_1520 = {
209 .brightness = -1,
210};
211
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000212static struct quirk_entry quirk_acer_travelmate_2490 = {
213 .mailled = 1,
214};
215
216/* This AMW0 laptop has no bluetooth */
217static struct quirk_entry quirk_medion_md_98300 = {
218 .wireless = 1,
219};
220
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100221static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
222 .wireless = 2,
223};
224
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100225/* The Aspire One has a dummy ACPI-WMI interface - disable it */
226static struct dmi_system_id __devinitdata acer_blacklist[] = {
227 {
228 .ident = "Acer Aspire One (SSD)",
229 .matches = {
230 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
231 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
232 },
233 },
234 {
235 .ident = "Acer Aspire One (HDD)",
236 .matches = {
237 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
238 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
239 },
240 },
241 {}
242};
243
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000244static struct dmi_system_id acer_quirks[] = {
245 {
246 .callback = dmi_matched,
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100247 .ident = "Acer Aspire 1360",
248 .matches = {
249 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
250 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
251 },
252 .driver_data = &quirk_acer_aspire_1520,
253 },
254 {
255 .callback = dmi_matched,
256 .ident = "Acer Aspire 1520",
257 .matches = {
258 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
259 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
260 },
261 .driver_data = &quirk_acer_aspire_1520,
262 },
263 {
264 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000265 .ident = "Acer Aspire 3100",
266 .matches = {
267 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
268 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
269 },
270 .driver_data = &quirk_acer_travelmate_2490,
271 },
272 {
273 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000274 .ident = "Acer Aspire 3610",
275 .matches = {
276 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
277 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
278 },
279 .driver_data = &quirk_acer_travelmate_2490,
280 },
281 {
282 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000283 .ident = "Acer Aspire 5100",
284 .matches = {
285 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
286 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
287 },
288 .driver_data = &quirk_acer_travelmate_2490,
289 },
290 {
291 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000292 .ident = "Acer Aspire 5610",
293 .matches = {
294 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
295 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
296 },
297 .driver_data = &quirk_acer_travelmate_2490,
298 },
299 {
300 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000301 .ident = "Acer Aspire 5630",
302 .matches = {
303 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
304 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
305 },
306 .driver_data = &quirk_acer_travelmate_2490,
307 },
308 {
309 .callback = dmi_matched,
310 .ident = "Acer Aspire 5650",
311 .matches = {
312 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
313 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
314 },
315 .driver_data = &quirk_acer_travelmate_2490,
316 },
317 {
318 .callback = dmi_matched,
319 .ident = "Acer Aspire 5680",
320 .matches = {
321 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
322 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
323 },
324 .driver_data = &quirk_acer_travelmate_2490,
325 },
326 {
327 .callback = dmi_matched,
328 .ident = "Acer Aspire 9110",
329 .matches = {
330 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
331 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
332 },
333 .driver_data = &quirk_acer_travelmate_2490,
334 },
335 {
336 .callback = dmi_matched,
337 .ident = "Acer TravelMate 2490",
338 .matches = {
339 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
340 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
341 },
342 .driver_data = &quirk_acer_travelmate_2490,
343 },
344 {
345 .callback = dmi_matched,
Carlos Corbacho262ee352008-02-16 00:02:56 +0000346 .ident = "Acer TravelMate 4200",
347 .matches = {
348 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
349 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
350 },
351 .driver_data = &quirk_acer_travelmate_2490,
352 },
353 {
354 .callback = dmi_matched,
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100355 .ident = "Fujitsu Siemens Amilo Li 1718",
356 .matches = {
357 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
358 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
359 },
360 .driver_data = &quirk_fujitsu_amilo_li_1718,
361 },
362 {
363 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000364 .ident = "Medion MD 98300",
365 .matches = {
366 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
367 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
368 },
369 .driver_data = &quirk_medion_md_98300,
370 },
371 {}
372};
373
374/* Find which quirks are needed for a particular vendor/ model pair */
375static void find_quirks(void)
376{
377 if (!force_series) {
378 dmi_check_system(acer_quirks);
379 } else if (force_series == 2490) {
380 quirks = &quirk_acer_travelmate_2490;
381 }
382
383 if (quirks == NULL)
384 quirks = &quirk_unknown;
385
386 set_quirks();
387}
388
389/*
390 * General interface convenience methods
391 */
392
393static bool has_cap(u32 cap)
394{
395 if ((interface->capability & cap) != 0)
396 return 1;
397
398 return 0;
399}
400
401/*
402 * AMW0 (V1) interface
403 */
404struct wmab_args {
405 u32 eax;
406 u32 ebx;
407 u32 ecx;
408 u32 edx;
409};
410
411struct wmab_ret {
412 u32 eax;
413 u32 ebx;
414 u32 ecx;
415 u32 edx;
416 u32 eex;
417};
418
419static acpi_status wmab_execute(struct wmab_args *regbuf,
420struct acpi_buffer *result)
421{
422 struct acpi_buffer input;
423 acpi_status status;
424 input.length = sizeof(struct wmab_args);
425 input.pointer = (u8 *)regbuf;
426
427 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
428
429 return status;
430}
431
432static acpi_status AMW0_get_u32(u32 *value, u32 cap,
433struct wmi_interface *iface)
434{
435 int err;
436 u8 result;
437
438 switch (cap) {
439 case ACER_CAP_MAILLED:
440 switch (quirks->mailled) {
441 default:
442 err = ec_read(0xA, &result);
443 if (err)
444 return AE_ERROR;
445 *value = (result >> 7) & 0x1;
446 return AE_OK;
447 }
448 break;
449 case ACER_CAP_WIRELESS:
450 switch (quirks->wireless) {
451 case 1:
452 err = ec_read(0x7B, &result);
453 if (err)
454 return AE_ERROR;
455 *value = result & 0x1;
456 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100457 case 2:
458 err = ec_read(0x71, &result);
459 if (err)
460 return AE_ERROR;
461 *value = result & 0x1;
462 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000463 default:
464 err = ec_read(0xA, &result);
465 if (err)
466 return AE_ERROR;
467 *value = (result >> 2) & 0x1;
468 return AE_OK;
469 }
470 break;
471 case ACER_CAP_BLUETOOTH:
472 switch (quirks->bluetooth) {
473 default:
474 err = ec_read(0xA, &result);
475 if (err)
476 return AE_ERROR;
477 *value = (result >> 4) & 0x1;
478 return AE_OK;
479 }
480 break;
481 case ACER_CAP_BRIGHTNESS:
482 switch (quirks->brightness) {
483 default:
484 err = ec_read(0x83, &result);
485 if (err)
486 return AE_ERROR;
487 *value = result;
488 return AE_OK;
489 }
490 break;
491 default:
Lin Ming08237972008-08-08 11:57:11 +0800492 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000493 }
494 return AE_OK;
495}
496
497static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
498{
499 struct wmab_args args;
500
501 args.eax = ACER_AMW0_WRITE;
502 args.ebx = value ? (1<<8) : 0;
503 args.ecx = args.edx = 0;
504
505 switch (cap) {
506 case ACER_CAP_MAILLED:
507 if (value > 1)
508 return AE_BAD_PARAMETER;
509 args.ebx |= ACER_AMW0_MAILLED_MASK;
510 break;
511 case ACER_CAP_WIRELESS:
512 if (value > 1)
513 return AE_BAD_PARAMETER;
514 args.ebx |= ACER_AMW0_WIRELESS_MASK;
515 break;
516 case ACER_CAP_BLUETOOTH:
517 if (value > 1)
518 return AE_BAD_PARAMETER;
519 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
520 break;
521 case ACER_CAP_BRIGHTNESS:
522 if (value > max_brightness)
523 return AE_BAD_PARAMETER;
524 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000525 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000526 return ec_write(0x83, value);
527 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000528 }
529 default:
Lin Ming08237972008-08-08 11:57:11 +0800530 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000531 }
532
533 /* Actually do the set */
534 return wmab_execute(&args, NULL);
535}
536
537static acpi_status AMW0_find_mailled(void)
538{
539 struct wmab_args args;
540 struct wmab_ret ret;
541 acpi_status status = AE_OK;
542 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
543 union acpi_object *obj;
544
545 args.eax = 0x86;
546 args.ebx = args.ecx = args.edx = 0;
547
548 status = wmab_execute(&args, &out);
549 if (ACPI_FAILURE(status))
550 return status;
551
552 obj = (union acpi_object *) out.pointer;
553 if (obj && obj->type == ACPI_TYPE_BUFFER &&
554 obj->buffer.length == sizeof(struct wmab_ret)) {
555 ret = *((struct wmab_ret *) obj->buffer.pointer);
556 } else {
557 return AE_ERROR;
558 }
559
560 if (ret.eex & 0x1)
561 interface->capability |= ACER_CAP_MAILLED;
562
563 kfree(out.pointer);
564
565 return AE_OK;
566}
567
568static acpi_status AMW0_set_capabilities(void)
569{
570 struct wmab_args args;
571 struct wmab_ret ret;
572 acpi_status status = AE_OK;
573 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
574 union acpi_object *obj;
575
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100576 /*
577 * On laptops with this strange GUID (non Acer), normal probing doesn't
578 * work.
579 */
580 if (wmi_has_guid(AMW0_GUID2)) {
581 interface->capability |= ACER_CAP_WIRELESS;
582 return AE_OK;
583 }
584
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000585 args.eax = ACER_AMW0_WRITE;
586 args.ecx = args.edx = 0;
587
588 args.ebx = 0xa2 << 8;
589 args.ebx |= ACER_AMW0_WIRELESS_MASK;
590
591 status = wmab_execute(&args, &out);
592 if (ACPI_FAILURE(status))
593 return status;
594
595 obj = (union acpi_object *) out.pointer;
596 if (obj && obj->type == ACPI_TYPE_BUFFER &&
597 obj->buffer.length == sizeof(struct wmab_ret)) {
598 ret = *((struct wmab_ret *) obj->buffer.pointer);
599 } else {
600 return AE_ERROR;
601 }
602
603 if (ret.eax & 0x1)
604 interface->capability |= ACER_CAP_WIRELESS;
605
606 args.ebx = 2 << 8;
607 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
608
609 status = wmab_execute(&args, &out);
610 if (ACPI_FAILURE(status))
611 return status;
612
613 obj = (union acpi_object *) out.pointer;
614 if (obj && obj->type == ACPI_TYPE_BUFFER
615 && obj->buffer.length == sizeof(struct wmab_ret)) {
616 ret = *((struct wmab_ret *) obj->buffer.pointer);
617 } else {
618 return AE_ERROR;
619 }
620
621 if (ret.eax & 0x1)
622 interface->capability |= ACER_CAP_BLUETOOTH;
623
624 kfree(out.pointer);
625
626 /*
627 * This appears to be safe to enable, since all Wistron based laptops
628 * appear to use the same EC register for brightness, even if they
629 * differ for wireless, etc
630 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100631 if (quirks->brightness >= 0)
632 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000633
634 return AE_OK;
635}
636
637static struct wmi_interface AMW0_interface = {
638 .type = ACER_AMW0,
639};
640
641static struct wmi_interface AMW0_V2_interface = {
642 .type = ACER_AMW0_V2,
643};
644
645/*
646 * New interface (The WMID interface)
647 */
648static acpi_status
649WMI_execute_u32(u32 method_id, u32 in, u32 *out)
650{
651 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
652 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
653 union acpi_object *obj;
654 u32 tmp;
655 acpi_status status;
656
657 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
658
659 if (ACPI_FAILURE(status))
660 return status;
661
662 obj = (union acpi_object *) result.pointer;
663 if (obj && obj->type == ACPI_TYPE_BUFFER &&
664 obj->buffer.length == sizeof(u32)) {
665 tmp = *((u32 *) obj->buffer.pointer);
666 } else {
667 tmp = 0;
668 }
669
670 if (out)
671 *out = tmp;
672
673 kfree(result.pointer);
674
675 return status;
676}
677
678static acpi_status WMID_get_u32(u32 *value, u32 cap,
679struct wmi_interface *iface)
680{
681 acpi_status status;
682 u8 tmp;
683 u32 result, method_id = 0;
684
685 switch (cap) {
686 case ACER_CAP_WIRELESS:
687 method_id = ACER_WMID_GET_WIRELESS_METHODID;
688 break;
689 case ACER_CAP_BLUETOOTH:
690 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
691 break;
692 case ACER_CAP_BRIGHTNESS:
693 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
694 break;
695 case ACER_CAP_THREEG:
696 method_id = ACER_WMID_GET_THREEG_METHODID;
697 break;
698 case ACER_CAP_MAILLED:
699 if (quirks->mailled == 1) {
700 ec_read(0x9f, &tmp);
701 *value = tmp & 0x1;
702 return 0;
703 }
704 default:
Lin Ming08237972008-08-08 11:57:11 +0800705 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000706 }
707 status = WMI_execute_u32(method_id, 0, &result);
708
709 if (ACPI_SUCCESS(status))
710 *value = (u8)result;
711
712 return status;
713}
714
715static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
716{
717 u32 method_id = 0;
718 char param;
719
720 switch (cap) {
721 case ACER_CAP_BRIGHTNESS:
722 if (value > max_brightness)
723 return AE_BAD_PARAMETER;
724 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
725 break;
726 case ACER_CAP_WIRELESS:
727 if (value > 1)
728 return AE_BAD_PARAMETER;
729 method_id = ACER_WMID_SET_WIRELESS_METHODID;
730 break;
731 case ACER_CAP_BLUETOOTH:
732 if (value > 1)
733 return AE_BAD_PARAMETER;
734 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
735 break;
736 case ACER_CAP_THREEG:
737 if (value > 1)
738 return AE_BAD_PARAMETER;
739 method_id = ACER_WMID_SET_THREEG_METHODID;
740 break;
741 case ACER_CAP_MAILLED:
742 if (value > 1)
743 return AE_BAD_PARAMETER;
744 if (quirks->mailled == 1) {
745 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700746 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000747 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700748 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000749 return 0;
750 }
751 break;
752 default:
Lin Ming08237972008-08-08 11:57:11 +0800753 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000754 }
755 return WMI_execute_u32(method_id, (u32)value, NULL);
756}
757
758static acpi_status WMID_set_capabilities(void)
759{
760 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
761 union acpi_object *obj;
762 acpi_status status;
763 u32 devices;
764
765 status = wmi_query_block(WMID_GUID2, 1, &out);
766 if (ACPI_FAILURE(status))
767 return status;
768
769 obj = (union acpi_object *) out.pointer;
770 if (obj && obj->type == ACPI_TYPE_BUFFER &&
771 obj->buffer.length == sizeof(u32)) {
772 devices = *((u32 *) obj->buffer.pointer);
773 } else {
774 return AE_ERROR;
775 }
776
777 /* Not sure on the meaning of the relevant bits yet to detect these */
778 interface->capability |= ACER_CAP_WIRELESS;
779 interface->capability |= ACER_CAP_THREEG;
780
781 /* WMID always provides brightness methods */
782 interface->capability |= ACER_CAP_BRIGHTNESS;
783
784 if (devices & 0x10)
785 interface->capability |= ACER_CAP_BLUETOOTH;
786
787 if (!(devices & 0x20))
788 max_brightness = 0x9;
789
790 return status;
791}
792
793static struct wmi_interface wmid_interface = {
794 .type = ACER_WMID,
795};
796
797/*
798 * Generic Device (interface-independent)
799 */
800
801static acpi_status get_u32(u32 *value, u32 cap)
802{
Lin Ming08237972008-08-08 11:57:11 +0800803 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000804
805 switch (interface->type) {
806 case ACER_AMW0:
807 status = AMW0_get_u32(value, cap, interface);
808 break;
809 case ACER_AMW0_V2:
810 if (cap == ACER_CAP_MAILLED) {
811 status = AMW0_get_u32(value, cap, interface);
812 break;
813 }
814 case ACER_WMID:
815 status = WMID_get_u32(value, cap, interface);
816 break;
817 }
818
819 return status;
820}
821
822static acpi_status set_u32(u32 value, u32 cap)
823{
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100824 acpi_status status;
825
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000826 if (interface->capability & cap) {
827 switch (interface->type) {
828 case ACER_AMW0:
829 return AMW0_set_u32(value, cap, interface);
830 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100831 if (cap == ACER_CAP_MAILLED)
832 return AMW0_set_u32(value, cap, interface);
833
834 /*
835 * On some models, some WMID methods don't toggle
836 * properly. For those cases, we want to run the AMW0
837 * method afterwards to be certain we've really toggled
838 * the device state.
839 */
840 if (cap == ACER_CAP_WIRELESS ||
841 cap == ACER_CAP_BLUETOOTH) {
842 status = WMID_set_u32(value, cap, interface);
843 if (ACPI_FAILURE(status))
844 return status;
845
846 return AMW0_set_u32(value, cap, interface);
847 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000848 case ACER_WMID:
849 return WMID_set_u32(value, cap, interface);
850 default:
851 return AE_BAD_PARAMETER;
852 }
853 }
854 return AE_BAD_PARAMETER;
855}
856
857static void __init acer_commandline_init(void)
858{
859 /*
860 * These will all fail silently if the value given is invalid, or the
861 * capability isn't available on the given interface
862 */
863 set_u32(mailled, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000864 set_u32(threeg, ACER_CAP_THREEG);
865 set_u32(brightness, ACER_CAP_BRIGHTNESS);
866}
867
868/*
869 * LED device (Mail LED only, no other LEDs known yet)
870 */
871static void mail_led_set(struct led_classdev *led_cdev,
872enum led_brightness value)
873{
874 set_u32(value, ACER_CAP_MAILLED);
875}
876
877static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +0000878 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000879 .brightness_set = mail_led_set,
880};
881
Sam Ravnborg7560e382008-02-17 13:22:54 +0100882static int __devinit acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000883{
884 return led_classdev_register(dev, &mail_led);
885}
886
887static void acer_led_exit(void)
888{
889 led_classdev_unregister(&mail_led);
890}
891
892/*
893 * Backlight device
894 */
895static struct backlight_device *acer_backlight_device;
896
897static int read_brightness(struct backlight_device *bd)
898{
899 u32 value;
900 get_u32(&value, ACER_CAP_BRIGHTNESS);
901 return value;
902}
903
904static int update_bl_status(struct backlight_device *bd)
905{
Carlos Corbachof2b585b2008-06-21 09:09:27 +0100906 int intensity = bd->props.brightness;
907
908 if (bd->props.power != FB_BLANK_UNBLANK)
909 intensity = 0;
910 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
911 intensity = 0;
912
913 set_u32(intensity, ACER_CAP_BRIGHTNESS);
914
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000915 return 0;
916}
917
918static struct backlight_ops acer_bl_ops = {
919 .get_brightness = read_brightness,
920 .update_status = update_bl_status,
921};
922
Sam Ravnborg7560e382008-02-17 13:22:54 +0100923static int __devinit acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000924{
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500925 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000926 struct backlight_device *bd;
927
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500928 memset(&props, 0, sizeof(struct backlight_properties));
929 props.max_brightness = max_brightness;
930 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
931 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000932 if (IS_ERR(bd)) {
933 printk(ACER_ERR "Could not register Acer backlight device\n");
934 acer_backlight_device = NULL;
935 return PTR_ERR(bd);
936 }
937
938 acer_backlight_device = bd;
939
Carlos Corbachof2b585b2008-06-21 09:09:27 +0100940 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +0000941 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000942 backlight_update_status(bd);
943 return 0;
944}
945
Sam Ravnborg7560e382008-02-17 13:22:54 +0100946static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000947{
948 backlight_device_unregister(acer_backlight_device);
949}
950
951/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100952 * Rfkill devices
953 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100954static void acer_rfkill_update(struct work_struct *ignored);
955static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
956static void acer_rfkill_update(struct work_struct *ignored)
957{
958 u32 state;
959 acpi_status status;
960
961 status = get_u32(&state, ACER_CAP_WIRELESS);
962 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +0100963 rfkill_set_sw_state(wireless_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100964
965 if (has_cap(ACER_CAP_BLUETOOTH)) {
966 status = get_u32(&state, ACER_CAP_BLUETOOTH);
967 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +0100968 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100969 }
970
Carlos Corbachoae3a1b42008-10-10 17:33:35 +0100971 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100972}
973
Johannes Berg19d337d2009-06-02 13:01:37 +0200974static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100975{
976 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +0200977 u32 cap = (unsigned long)data;
Alan Jenkinsed5c8ef2009-07-19 09:48:28 +0100978 status = set_u32(!blocked, cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100979 if (ACPI_FAILURE(status))
980 return -ENODEV;
981 return 0;
982}
983
Johannes Berg19d337d2009-06-02 13:01:37 +0200984static const struct rfkill_ops acer_rfkill_ops = {
985 .set_block = acer_rfkill_set,
986};
987
988static struct rfkill *acer_rfkill_register(struct device *dev,
989 enum rfkill_type type,
990 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100991{
992 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100993 struct rfkill *rfkill_dev;
994
Johannes Berg19d337d2009-06-02 13:01:37 +0200995 rfkill_dev = rfkill_alloc(name, dev, type,
996 &acer_rfkill_ops,
997 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100998 if (!rfkill_dev)
999 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001000
1001 err = rfkill_register(rfkill_dev);
1002 if (err) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001003 rfkill_destroy(rfkill_dev);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001004 return ERR_PTR(err);
1005 }
1006 return rfkill_dev;
1007}
1008
1009static int acer_rfkill_init(struct device *dev)
1010{
1011 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1012 "acer-wireless", ACER_CAP_WIRELESS);
1013 if (IS_ERR(wireless_rfkill))
1014 return PTR_ERR(wireless_rfkill);
1015
1016 if (has_cap(ACER_CAP_BLUETOOTH)) {
1017 bluetooth_rfkill = acer_rfkill_register(dev,
1018 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1019 ACER_CAP_BLUETOOTH);
1020 if (IS_ERR(bluetooth_rfkill)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001021 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001022 rfkill_destroy(wireless_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001023 return PTR_ERR(bluetooth_rfkill);
1024 }
1025 }
1026
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001027 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001028
1029 return 0;
1030}
1031
1032static void acer_rfkill_exit(void)
1033{
1034 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001035
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001036 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001037 rfkill_destroy(wireless_rfkill);
1038
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001039 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001040 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001041 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001042 }
1043 return;
1044}
1045
1046/*
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001047 * sysfs interface
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001048 */
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001049static ssize_t show_bool_threeg(struct device *dev,
1050 struct device_attribute *attr, char *buf)
1051{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001052 u32 result; \
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001053 acpi_status status = get_u32(&result, ACER_CAP_THREEG);
1054 if (ACPI_SUCCESS(status))
1055 return sprintf(buf, "%u\n", result);
1056 return sprintf(buf, "Read error\n");
1057}
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001058
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001059static ssize_t set_bool_threeg(struct device *dev,
1060 struct device_attribute *attr, const char *buf, size_t count)
1061{
1062 u32 tmp = simple_strtoul(buf, NULL, 10);
1063 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
1064 if (ACPI_FAILURE(status))
1065 return -EINVAL;
1066 return count;
1067}
1068static DEVICE_ATTR(threeg, S_IWUGO | S_IRUGO | S_IWUSR, show_bool_threeg,
1069 set_bool_threeg);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001070
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001071static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1072 char *buf)
1073{
1074 switch (interface->type) {
1075 case ACER_AMW0:
1076 return sprintf(buf, "AMW0\n");
1077 case ACER_AMW0_V2:
1078 return sprintf(buf, "AMW0 v2\n");
1079 case ACER_WMID:
1080 return sprintf(buf, "WMID\n");
1081 default:
1082 return sprintf(buf, "Error!\n");
1083 }
1084}
1085
1086static DEVICE_ATTR(interface, S_IWUGO | S_IRUGO | S_IWUSR,
1087 show_interface, NULL);
1088
1089/*
Carlos Corbacho81143522008-06-21 09:09:53 +01001090 * debugfs functions
1091 */
1092static u32 get_wmid_devices(void)
1093{
1094 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1095 union acpi_object *obj;
1096 acpi_status status;
1097
1098 status = wmi_query_block(WMID_GUID2, 1, &out);
1099 if (ACPI_FAILURE(status))
1100 return 0;
1101
1102 obj = (union acpi_object *) out.pointer;
1103 if (obj && obj->type == ACPI_TYPE_BUFFER &&
1104 obj->buffer.length == sizeof(u32)) {
1105 return *((u32 *) obj->buffer.pointer);
1106 } else {
1107 return 0;
1108 }
1109}
1110
1111/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001112 * Platform device
1113 */
1114static int __devinit acer_platform_probe(struct platform_device *device)
1115{
1116 int err;
1117
1118 if (has_cap(ACER_CAP_MAILLED)) {
1119 err = acer_led_init(&device->dev);
1120 if (err)
1121 goto error_mailled;
1122 }
1123
1124 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1125 err = acer_backlight_init(&device->dev);
1126 if (err)
1127 goto error_brightness;
1128 }
1129
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001130 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01001131 if (err)
1132 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001133
1134 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001135
Andy Whitcroft350e3292009-04-04 09:33:34 +01001136error_rfkill:
1137 if (has_cap(ACER_CAP_BRIGHTNESS))
1138 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001139error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01001140 if (has_cap(ACER_CAP_MAILLED))
1141 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001142error_mailled:
1143 return err;
1144}
1145
1146static int acer_platform_remove(struct platform_device *device)
1147{
1148 if (has_cap(ACER_CAP_MAILLED))
1149 acer_led_exit();
1150 if (has_cap(ACER_CAP_BRIGHTNESS))
1151 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001152
1153 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001154 return 0;
1155}
1156
1157static int acer_platform_suspend(struct platform_device *dev,
1158pm_message_t state)
1159{
1160 u32 value;
1161 struct acer_data *data = &interface->data;
1162
1163 if (!data)
1164 return -ENOMEM;
1165
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001166 if (has_cap(ACER_CAP_MAILLED)) {
1167 get_u32(&value, ACER_CAP_MAILLED);
1168 data->mailled = value;
1169 }
1170
1171 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1172 get_u32(&value, ACER_CAP_BRIGHTNESS);
1173 data->brightness = value;
1174 }
1175
1176 return 0;
1177}
1178
1179static int acer_platform_resume(struct platform_device *device)
1180{
1181 struct acer_data *data = &interface->data;
1182
1183 if (!data)
1184 return -ENOMEM;
1185
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001186 if (has_cap(ACER_CAP_MAILLED))
1187 set_u32(data->mailled, ACER_CAP_MAILLED);
1188
1189 if (has_cap(ACER_CAP_BRIGHTNESS))
1190 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
1191
1192 return 0;
1193}
1194
1195static struct platform_driver acer_platform_driver = {
1196 .driver = {
1197 .name = "acer-wmi",
1198 .owner = THIS_MODULE,
1199 },
1200 .probe = acer_platform_probe,
1201 .remove = acer_platform_remove,
1202 .suspend = acer_platform_suspend,
1203 .resume = acer_platform_resume,
1204};
1205
1206static struct platform_device *acer_platform_device;
1207
1208static int remove_sysfs(struct platform_device *device)
1209{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001210 if (has_cap(ACER_CAP_THREEG))
1211 device_remove_file(&device->dev, &dev_attr_threeg);
1212
1213 device_remove_file(&device->dev, &dev_attr_interface);
1214
1215 return 0;
1216}
1217
1218static int create_sysfs(void)
1219{
1220 int retval = -ENOMEM;
1221
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001222 if (has_cap(ACER_CAP_THREEG)) {
1223 retval = device_create_file(&acer_platform_device->dev,
1224 &dev_attr_threeg);
1225 if (retval)
1226 goto error_sysfs;
1227 }
1228
1229 retval = device_create_file(&acer_platform_device->dev,
1230 &dev_attr_interface);
1231 if (retval)
1232 goto error_sysfs;
1233
1234 return 0;
1235
1236error_sysfs:
1237 remove_sysfs(acer_platform_device);
1238 return retval;
1239}
1240
Carlos Corbacho81143522008-06-21 09:09:53 +01001241static void remove_debugfs(void)
1242{
1243 debugfs_remove(interface->debug.devices);
1244 debugfs_remove(interface->debug.root);
1245}
1246
1247static int create_debugfs(void)
1248{
1249 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
1250 if (!interface->debug.root) {
1251 printk(ACER_ERR "Failed to create debugfs directory");
1252 return -ENOMEM;
1253 }
1254
1255 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
1256 interface->debug.root,
1257 &interface->debug.wmid_devices);
1258 if (!interface->debug.devices)
1259 goto error_debugfs;
1260
1261 return 0;
1262
1263error_debugfs:
Russ Dill39dbbb42008-09-02 14:35:40 -07001264 remove_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01001265 return -ENOMEM;
1266}
1267
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001268static int __init acer_wmi_init(void)
1269{
1270 int err;
1271
Carlos Corbacho860f0c62008-06-21 09:09:58 +01001272 printk(ACER_INFO "Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001273
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001274 if (dmi_check_system(acer_blacklist)) {
1275 printk(ACER_INFO "Blacklisted hardware detected - "
1276 "not loading\n");
1277 return -ENODEV;
1278 }
1279
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01001280 find_quirks();
1281
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001282 /*
1283 * Detect which ACPI-WMI interface we're using.
1284 */
1285 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1286 interface = &AMW0_V2_interface;
1287
1288 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1289 interface = &wmid_interface;
1290
1291 if (wmi_has_guid(WMID_GUID2) && interface) {
1292 if (ACPI_FAILURE(WMID_set_capabilities())) {
Carlos Corbacho8d039bc2008-03-12 20:12:50 +00001293 printk(ACER_ERR "Unable to detect available WMID "
1294 "devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001295 return -ENODEV;
1296 }
1297 } else if (!wmi_has_guid(WMID_GUID2) && interface) {
Carlos Corbacho8d039bc2008-03-12 20:12:50 +00001298 printk(ACER_ERR "No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001299 return -ENODEV;
1300 }
1301
1302 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
1303 interface = &AMW0_interface;
1304
1305 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Carlos Corbacho8d039bc2008-03-12 20:12:50 +00001306 printk(ACER_ERR "Unable to detect available AMW0 "
1307 "devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001308 return -ENODEV;
1309 }
1310 }
1311
Carlos Corbacho9b963c42008-02-24 13:34:29 +00001312 if (wmi_has_guid(AMW0_GUID1))
1313 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001314
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001315 if (!interface) {
Carlos Corbacho8d039bc2008-03-12 20:12:50 +00001316 printk(ACER_ERR "No or unsupported WMI interface, unable to "
1317 "load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001318 return -ENODEV;
1319 }
1320
Arjan van de Ven83097ac2008-08-23 21:45:21 -07001321 set_quirks();
1322
Michael Spang1ba869e2009-03-12 14:31:34 -07001323 if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS)) {
Thomas Renningerfebf2d92008-08-01 17:37:56 +02001324 interface->capability &= ~ACER_CAP_BRIGHTNESS;
1325 printk(ACER_INFO "Brightness must be controlled by "
1326 "generic video driver\n");
1327 }
1328
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001329 if (platform_driver_register(&acer_platform_driver)) {
1330 printk(ACER_ERR "Unable to register platform driver.\n");
1331 goto error_platform_register;
1332 }
1333 acer_platform_device = platform_device_alloc("acer-wmi", -1);
1334 platform_device_add(acer_platform_device);
1335
1336 err = create_sysfs();
1337 if (err)
1338 return err;
1339
Carlos Corbacho81143522008-06-21 09:09:53 +01001340 if (wmi_has_guid(WMID_GUID2)) {
1341 interface->debug.wmid_devices = get_wmid_devices();
1342 err = create_debugfs();
1343 if (err)
1344 return err;
1345 }
1346
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001347 /* Override any initial settings with values from the commandline */
1348 acer_commandline_init();
1349
1350 return 0;
1351
1352error_platform_register:
1353 return -ENODEV;
1354}
1355
1356static void __exit acer_wmi_exit(void)
1357{
1358 remove_sysfs(acer_platform_device);
Russ Dill39dbbb42008-09-02 14:35:40 -07001359 remove_debugfs();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001360 platform_device_del(acer_platform_device);
1361 platform_driver_unregister(&acer_platform_driver);
1362
1363 printk(ACER_INFO "Acer Laptop WMI Extras unloaded\n");
1364 return;
1365}
1366
1367module_init(acer_wmi_init);
1368module_exit(acer_wmi_exit);