Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / misc / acer-wmi.c
blob1557e8cc02f7920c17946d5711ad714be8dfa65e
1 /*
2 * Acer WMI Laptop Extras
4 * Copyright (C) 2007-2008 Carlos Corbacho <carlos@strangeworlds.co.uk>
6 * Based on acer_acpi:
7 * Copyright (C) 2005-2007 E.M. Smith
8 * Copyright (C) 2007-2008 Carlos Corbacho <cathectic@gmail.com>
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.
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.
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
25 #define ACER_WMI_VERSION "0.1"
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/dmi.h>
32 #include <linux/backlight.h>
33 #include <linux/leds.h>
34 #include <linux/platform_device.h>
35 #include <linux/acpi.h>
36 #include <linux/i8042.h>
38 #include <acpi/acpi_drivers.h>
40 MODULE_AUTHOR("Carlos Corbacho");
41 MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
42 MODULE_LICENSE("GPL");
44 #define ACER_LOGPREFIX "acer-wmi: "
45 #define ACER_ERR KERN_ERR ACER_LOGPREFIX
46 #define ACER_NOTICE KERN_NOTICE ACER_LOGPREFIX
47 #define ACER_INFO KERN_INFO ACER_LOGPREFIX
50 * The following defines quirks to get some specific functions to work
51 * which are known to not be supported over ACPI-WMI (such as the mail LED
52 * on WMID based Acer's)
54 struct acer_quirks {
55 const char *vendor;
56 const char *model;
57 u16 quirks;
61 * Magic Number
62 * Meaning is unknown - this number is required for writing to ACPI for AMW0
63 * (it's also used in acerhk when directly accessing the BIOS)
65 #define ACER_AMW0_WRITE 0x9610
68 * Bit masks for the AMW0 interface
70 #define ACER_AMW0_WIRELESS_MASK 0x35
71 #define ACER_AMW0_BLUETOOTH_MASK 0x34
72 #define ACER_AMW0_MAILLED_MASK 0x31
75 * Method IDs for WMID interface
77 #define ACER_WMID_GET_WIRELESS_METHODID 1
78 #define ACER_WMID_GET_BLUETOOTH_METHODID 2
79 #define ACER_WMID_GET_BRIGHTNESS_METHODID 3
80 #define ACER_WMID_SET_WIRELESS_METHODID 4
81 #define ACER_WMID_SET_BLUETOOTH_METHODID 5
82 #define ACER_WMID_SET_BRIGHTNESS_METHODID 6
83 #define ACER_WMID_GET_THREEG_METHODID 10
84 #define ACER_WMID_SET_THREEG_METHODID 11
87 * Acer ACPI method GUIDs
89 #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
90 #define WMID_GUID1 "6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3"
91 #define WMID_GUID2 "95764E09-FB56-4e83-B31A-37761F60994A"
93 MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
94 MODULE_ALIAS("wmi:6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3");
96 /* Temporary workaround until the WMI sysfs interface goes in */
97 MODULE_ALIAS("dmi:*:*Acer*:*:");
100 * Interface capability flags
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)
110 * Interface type flags
112 enum interface_flags {
113 ACER_AMW0,
114 ACER_AMW0_V2,
115 ACER_WMID,
118 #define ACER_DEFAULT_WIRELESS 0
119 #define ACER_DEFAULT_BLUETOOTH 0
120 #define ACER_DEFAULT_MAILLED 0
121 #define ACER_DEFAULT_THREEG 0
123 static int max_brightness = 0xF;
125 static int wireless = -1;
126 static int bluetooth = -1;
127 static int mailled = -1;
128 static int brightness = -1;
129 static int threeg = -1;
130 static int force_series;
132 module_param(mailled, int, 0444);
133 module_param(wireless, int, 0444);
134 module_param(bluetooth, int, 0444);
135 module_param(brightness, int, 0444);
136 module_param(threeg, int, 0444);
137 module_param(force_series, int, 0444);
138 MODULE_PARM_DESC(wireless, "Set initial state of Wireless hardware");
139 MODULE_PARM_DESC(bluetooth, "Set initial state of Bluetooth hardware");
140 MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
141 MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
142 MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
143 MODULE_PARM_DESC(force_series, "Force a different laptop series");
145 struct acer_data {
146 int mailled;
147 int wireless;
148 int bluetooth;
149 int threeg;
150 int brightness;
153 /* Each low-level interface must define at least some of the following */
154 struct wmi_interface {
155 /* The WMI device type */
156 u32 type;
158 /* The capabilities this interface provides */
159 u32 capability;
161 /* Private data for the current interface */
162 struct acer_data data;
165 /* The static interface pointer, points to the currently detected interface */
166 static struct wmi_interface *interface;
169 * Embedded Controller quirks
170 * Some laptops require us to directly access the EC to either enable or query
171 * features that are not available through WMI.
174 struct quirk_entry {
175 u8 wireless;
176 u8 mailled;
177 u8 brightness;
178 u8 bluetooth;
181 static struct quirk_entry *quirks;
183 static void set_quirks(void)
185 if (quirks->mailled)
186 interface->capability |= ACER_CAP_MAILLED;
188 if (quirks->brightness)
189 interface->capability |= ACER_CAP_BRIGHTNESS;
192 static int dmi_matched(const struct dmi_system_id *dmi)
194 quirks = dmi->driver_data;
195 return 0;
198 static struct quirk_entry quirk_unknown = {
201 static struct quirk_entry quirk_acer_travelmate_2490 = {
202 .mailled = 1,
205 /* This AMW0 laptop has no bluetooth */
206 static struct quirk_entry quirk_medion_md_98300 = {
207 .wireless = 1,
210 static struct dmi_system_id acer_quirks[] = {
212 .callback = dmi_matched,
213 .ident = "Acer Aspire 3100",
214 .matches = {
215 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
216 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
218 .driver_data = &quirk_acer_travelmate_2490,
221 .callback = dmi_matched,
222 <<<<<<< HEAD:drivers/misc/acer-wmi.c
223 =======
224 .ident = "Acer Aspire 3610",
225 .matches = {
226 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
227 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
229 .driver_data = &quirk_acer_travelmate_2490,
232 .callback = dmi_matched,
233 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/misc/acer-wmi.c
234 .ident = "Acer Aspire 5100",
235 .matches = {
236 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
237 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
239 .driver_data = &quirk_acer_travelmate_2490,
242 .callback = dmi_matched,
243 <<<<<<< HEAD:drivers/misc/acer-wmi.c
244 =======
245 .ident = "Acer Aspire 5610",
246 .matches = {
247 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
248 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
250 .driver_data = &quirk_acer_travelmate_2490,
253 .callback = dmi_matched,
254 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/misc/acer-wmi.c
255 .ident = "Acer Aspire 5630",
256 .matches = {
257 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
258 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
260 .driver_data = &quirk_acer_travelmate_2490,
263 .callback = dmi_matched,
264 .ident = "Acer Aspire 5650",
265 .matches = {
266 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
267 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
269 .driver_data = &quirk_acer_travelmate_2490,
272 .callback = dmi_matched,
273 .ident = "Acer Aspire 5680",
274 .matches = {
275 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
276 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
278 .driver_data = &quirk_acer_travelmate_2490,
281 .callback = dmi_matched,
282 .ident = "Acer Aspire 9110",
283 .matches = {
284 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
285 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
287 .driver_data = &quirk_acer_travelmate_2490,
290 .callback = dmi_matched,
291 .ident = "Acer TravelMate 2490",
292 .matches = {
293 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
294 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
296 .driver_data = &quirk_acer_travelmate_2490,
299 .callback = dmi_matched,
300 <<<<<<< HEAD:drivers/misc/acer-wmi.c
301 =======
302 .ident = "Acer TravelMate 4200",
303 .matches = {
304 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
305 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
307 .driver_data = &quirk_acer_travelmate_2490,
310 .callback = dmi_matched,
311 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/misc/acer-wmi.c
312 .ident = "Medion MD 98300",
313 .matches = {
314 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
315 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
317 .driver_data = &quirk_medion_md_98300,
322 /* Find which quirks are needed for a particular vendor/ model pair */
323 static void find_quirks(void)
325 if (!force_series) {
326 dmi_check_system(acer_quirks);
327 } else if (force_series == 2490) {
328 quirks = &quirk_acer_travelmate_2490;
331 if (quirks == NULL)
332 quirks = &quirk_unknown;
334 set_quirks();
338 * General interface convenience methods
341 static bool has_cap(u32 cap)
343 if ((interface->capability & cap) != 0)
344 return 1;
346 return 0;
350 * AMW0 (V1) interface
352 struct wmab_args {
353 u32 eax;
354 u32 ebx;
355 u32 ecx;
356 u32 edx;
359 struct wmab_ret {
360 u32 eax;
361 u32 ebx;
362 u32 ecx;
363 u32 edx;
364 u32 eex;
367 static acpi_status wmab_execute(struct wmab_args *regbuf,
368 struct acpi_buffer *result)
370 struct acpi_buffer input;
371 acpi_status status;
372 input.length = sizeof(struct wmab_args);
373 input.pointer = (u8 *)regbuf;
375 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
377 return status;
380 static acpi_status AMW0_get_u32(u32 *value, u32 cap,
381 struct wmi_interface *iface)
383 int err;
384 u8 result;
386 switch (cap) {
387 case ACER_CAP_MAILLED:
388 switch (quirks->mailled) {
389 default:
390 err = ec_read(0xA, &result);
391 if (err)
392 return AE_ERROR;
393 *value = (result >> 7) & 0x1;
394 return AE_OK;
396 break;
397 case ACER_CAP_WIRELESS:
398 switch (quirks->wireless) {
399 case 1:
400 err = ec_read(0x7B, &result);
401 if (err)
402 return AE_ERROR;
403 *value = result & 0x1;
404 return AE_OK;
405 default:
406 err = ec_read(0xA, &result);
407 if (err)
408 return AE_ERROR;
409 *value = (result >> 2) & 0x1;
410 return AE_OK;
412 break;
413 case ACER_CAP_BLUETOOTH:
414 switch (quirks->bluetooth) {
415 default:
416 err = ec_read(0xA, &result);
417 if (err)
418 return AE_ERROR;
419 *value = (result >> 4) & 0x1;
420 return AE_OK;
422 break;
423 case ACER_CAP_BRIGHTNESS:
424 switch (quirks->brightness) {
425 default:
426 err = ec_read(0x83, &result);
427 if (err)
428 return AE_ERROR;
429 *value = result;
430 return AE_OK;
432 break;
433 default:
434 return AE_BAD_ADDRESS;
436 return AE_OK;
439 static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
441 struct wmab_args args;
443 args.eax = ACER_AMW0_WRITE;
444 args.ebx = value ? (1<<8) : 0;
445 args.ecx = args.edx = 0;
447 switch (cap) {
448 case ACER_CAP_MAILLED:
449 if (value > 1)
450 return AE_BAD_PARAMETER;
451 args.ebx |= ACER_AMW0_MAILLED_MASK;
452 break;
453 case ACER_CAP_WIRELESS:
454 if (value > 1)
455 return AE_BAD_PARAMETER;
456 args.ebx |= ACER_AMW0_WIRELESS_MASK;
457 break;
458 case ACER_CAP_BLUETOOTH:
459 if (value > 1)
460 return AE_BAD_PARAMETER;
461 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
462 break;
463 case ACER_CAP_BRIGHTNESS:
464 if (value > max_brightness)
465 return AE_BAD_PARAMETER;
466 switch (quirks->brightness) {
467 default:
468 return ec_write(0x83, value);
469 break;
471 default:
472 return AE_BAD_ADDRESS;
475 /* Actually do the set */
476 return wmab_execute(&args, NULL);
479 static acpi_status AMW0_find_mailled(void)
481 struct wmab_args args;
482 struct wmab_ret ret;
483 acpi_status status = AE_OK;
484 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
485 union acpi_object *obj;
487 args.eax = 0x86;
488 args.ebx = args.ecx = args.edx = 0;
490 status = wmab_execute(&args, &out);
491 if (ACPI_FAILURE(status))
492 return status;
494 obj = (union acpi_object *) out.pointer;
495 if (obj && obj->type == ACPI_TYPE_BUFFER &&
496 obj->buffer.length == sizeof(struct wmab_ret)) {
497 ret = *((struct wmab_ret *) obj->buffer.pointer);
498 } else {
499 return AE_ERROR;
502 if (ret.eex & 0x1)
503 interface->capability |= ACER_CAP_MAILLED;
505 kfree(out.pointer);
507 return AE_OK;
510 static acpi_status AMW0_set_capabilities(void)
512 struct wmab_args args;
513 struct wmab_ret ret;
514 acpi_status status = AE_OK;
515 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
516 union acpi_object *obj;
518 args.eax = ACER_AMW0_WRITE;
519 args.ecx = args.edx = 0;
521 args.ebx = 0xa2 << 8;
522 args.ebx |= ACER_AMW0_WIRELESS_MASK;
524 status = wmab_execute(&args, &out);
525 if (ACPI_FAILURE(status))
526 return status;
528 obj = (union acpi_object *) out.pointer;
529 if (obj && obj->type == ACPI_TYPE_BUFFER &&
530 obj->buffer.length == sizeof(struct wmab_ret)) {
531 ret = *((struct wmab_ret *) obj->buffer.pointer);
532 } else {
533 return AE_ERROR;
536 if (ret.eax & 0x1)
537 interface->capability |= ACER_CAP_WIRELESS;
539 args.ebx = 2 << 8;
540 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
542 status = wmab_execute(&args, &out);
543 if (ACPI_FAILURE(status))
544 return status;
546 obj = (union acpi_object *) out.pointer;
547 if (obj && obj->type == ACPI_TYPE_BUFFER
548 && obj->buffer.length == sizeof(struct wmab_ret)) {
549 ret = *((struct wmab_ret *) obj->buffer.pointer);
550 } else {
551 return AE_ERROR;
554 if (ret.eax & 0x1)
555 interface->capability |= ACER_CAP_BLUETOOTH;
557 kfree(out.pointer);
560 * This appears to be safe to enable, since all Wistron based laptops
561 * appear to use the same EC register for brightness, even if they
562 * differ for wireless, etc
564 interface->capability |= ACER_CAP_BRIGHTNESS;
566 return AE_OK;
569 static struct wmi_interface AMW0_interface = {
570 .type = ACER_AMW0,
573 static struct wmi_interface AMW0_V2_interface = {
574 .type = ACER_AMW0_V2,
578 * New interface (The WMID interface)
580 static acpi_status
581 WMI_execute_u32(u32 method_id, u32 in, u32 *out)
583 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
584 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
585 union acpi_object *obj;
586 u32 tmp;
587 acpi_status status;
589 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
591 if (ACPI_FAILURE(status))
592 return status;
594 obj = (union acpi_object *) result.pointer;
595 if (obj && obj->type == ACPI_TYPE_BUFFER &&
596 obj->buffer.length == sizeof(u32)) {
597 tmp = *((u32 *) obj->buffer.pointer);
598 } else {
599 tmp = 0;
602 if (out)
603 *out = tmp;
605 kfree(result.pointer);
607 return status;
610 static acpi_status WMID_get_u32(u32 *value, u32 cap,
611 struct wmi_interface *iface)
613 acpi_status status;
614 u8 tmp;
615 u32 result, method_id = 0;
617 switch (cap) {
618 case ACER_CAP_WIRELESS:
619 method_id = ACER_WMID_GET_WIRELESS_METHODID;
620 break;
621 case ACER_CAP_BLUETOOTH:
622 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
623 break;
624 case ACER_CAP_BRIGHTNESS:
625 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
626 break;
627 case ACER_CAP_THREEG:
628 method_id = ACER_WMID_GET_THREEG_METHODID;
629 break;
630 case ACER_CAP_MAILLED:
631 if (quirks->mailled == 1) {
632 ec_read(0x9f, &tmp);
633 *value = tmp & 0x1;
634 return 0;
636 default:
637 return AE_BAD_ADDRESS;
639 status = WMI_execute_u32(method_id, 0, &result);
641 if (ACPI_SUCCESS(status))
642 *value = (u8)result;
644 return status;
647 static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
649 u32 method_id = 0;
650 char param;
652 switch (cap) {
653 case ACER_CAP_BRIGHTNESS:
654 if (value > max_brightness)
655 return AE_BAD_PARAMETER;
656 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
657 break;
658 case ACER_CAP_WIRELESS:
659 if (value > 1)
660 return AE_BAD_PARAMETER;
661 method_id = ACER_WMID_SET_WIRELESS_METHODID;
662 break;
663 case ACER_CAP_BLUETOOTH:
664 if (value > 1)
665 return AE_BAD_PARAMETER;
666 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
667 break;
668 case ACER_CAP_THREEG:
669 if (value > 1)
670 return AE_BAD_PARAMETER;
671 method_id = ACER_WMID_SET_THREEG_METHODID;
672 break;
673 case ACER_CAP_MAILLED:
674 if (value > 1)
675 return AE_BAD_PARAMETER;
676 if (quirks->mailled == 1) {
677 param = value ? 0x92 : 0x93;
678 i8042_command(&param, 0x1059);
679 return 0;
681 break;
682 default:
683 return AE_BAD_ADDRESS;
685 return WMI_execute_u32(method_id, (u32)value, NULL);
688 static acpi_status WMID_set_capabilities(void)
690 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
691 union acpi_object *obj;
692 acpi_status status;
693 u32 devices;
695 status = wmi_query_block(WMID_GUID2, 1, &out);
696 if (ACPI_FAILURE(status))
697 return status;
699 obj = (union acpi_object *) out.pointer;
700 if (obj && obj->type == ACPI_TYPE_BUFFER &&
701 obj->buffer.length == sizeof(u32)) {
702 devices = *((u32 *) obj->buffer.pointer);
703 } else {
704 return AE_ERROR;
707 /* Not sure on the meaning of the relevant bits yet to detect these */
708 interface->capability |= ACER_CAP_WIRELESS;
709 interface->capability |= ACER_CAP_THREEG;
711 /* WMID always provides brightness methods */
712 interface->capability |= ACER_CAP_BRIGHTNESS;
714 if (devices & 0x10)
715 interface->capability |= ACER_CAP_BLUETOOTH;
717 if (!(devices & 0x20))
718 max_brightness = 0x9;
720 return status;
723 static struct wmi_interface wmid_interface = {
724 .type = ACER_WMID,
728 * Generic Device (interface-independent)
731 static acpi_status get_u32(u32 *value, u32 cap)
733 acpi_status status = AE_BAD_ADDRESS;
735 switch (interface->type) {
736 case ACER_AMW0:
737 status = AMW0_get_u32(value, cap, interface);
738 break;
739 case ACER_AMW0_V2:
740 if (cap == ACER_CAP_MAILLED) {
741 status = AMW0_get_u32(value, cap, interface);
742 break;
744 case ACER_WMID:
745 status = WMID_get_u32(value, cap, interface);
746 break;
749 return status;
752 static acpi_status set_u32(u32 value, u32 cap)
754 if (interface->capability & cap) {
755 switch (interface->type) {
756 case ACER_AMW0:
757 return AMW0_set_u32(value, cap, interface);
758 case ACER_AMW0_V2:
759 case ACER_WMID:
760 return WMID_set_u32(value, cap, interface);
761 default:
762 return AE_BAD_PARAMETER;
765 return AE_BAD_PARAMETER;
768 static void __init acer_commandline_init(void)
771 * These will all fail silently if the value given is invalid, or the
772 * capability isn't available on the given interface
774 set_u32(mailled, ACER_CAP_MAILLED);
775 set_u32(wireless, ACER_CAP_WIRELESS);
776 set_u32(bluetooth, ACER_CAP_BLUETOOTH);
777 set_u32(threeg, ACER_CAP_THREEG);
778 set_u32(brightness, ACER_CAP_BRIGHTNESS);
782 * LED device (Mail LED only, no other LEDs known yet)
784 static void mail_led_set(struct led_classdev *led_cdev,
785 enum led_brightness value)
787 set_u32(value, ACER_CAP_MAILLED);
790 static struct led_classdev mail_led = {
791 <<<<<<< HEAD:drivers/misc/acer-wmi.c
792 .name = "acer-mail:green",
793 =======
794 .name = "acer-wmi::mail",
795 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/misc/acer-wmi.c
796 .brightness_set = mail_led_set,
799 <<<<<<< HEAD:drivers/misc/acer-wmi.c
800 static int __init acer_led_init(struct device *dev)
801 =======
802 static int __devinit acer_led_init(struct device *dev)
803 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/misc/acer-wmi.c
805 return led_classdev_register(dev, &mail_led);
808 static void acer_led_exit(void)
810 led_classdev_unregister(&mail_led);
814 * Backlight device
816 static struct backlight_device *acer_backlight_device;
818 static int read_brightness(struct backlight_device *bd)
820 u32 value;
821 get_u32(&value, ACER_CAP_BRIGHTNESS);
822 return value;
825 static int update_bl_status(struct backlight_device *bd)
827 set_u32(bd->props.brightness, ACER_CAP_BRIGHTNESS);
828 return 0;
831 static struct backlight_ops acer_bl_ops = {
832 .get_brightness = read_brightness,
833 .update_status = update_bl_status,
836 <<<<<<< HEAD:drivers/misc/acer-wmi.c
837 static int __init acer_backlight_init(struct device *dev)
838 =======
839 static int __devinit acer_backlight_init(struct device *dev)
840 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/misc/acer-wmi.c
842 struct backlight_device *bd;
844 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops);
845 if (IS_ERR(bd)) {
846 printk(ACER_ERR "Could not register Acer backlight device\n");
847 acer_backlight_device = NULL;
848 return PTR_ERR(bd);
851 acer_backlight_device = bd;
853 bd->props.max_brightness = max_brightness;
854 bd->props.brightness = read_brightness(NULL);
855 backlight_update_status(bd);
856 return 0;
859 <<<<<<< HEAD:drivers/misc/acer-wmi.c
860 static void __exit acer_backlight_exit(void)
861 =======
862 static void acer_backlight_exit(void)
863 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/misc/acer-wmi.c
865 backlight_device_unregister(acer_backlight_device);
869 * Read/ write bool sysfs macro
871 #define show_set_bool(value, cap) \
872 static ssize_t \
873 show_bool_##value(struct device *dev, struct device_attribute *attr, \
874 char *buf) \
876 u32 result; \
877 acpi_status status = get_u32(&result, cap); \
878 if (ACPI_SUCCESS(status)) \
879 return sprintf(buf, "%u\n", result); \
880 return sprintf(buf, "Read error\n"); \
883 static ssize_t \
884 set_bool_##value(struct device *dev, struct device_attribute *attr, \
885 const char *buf, size_t count) \
887 u32 tmp = simple_strtoul(buf, NULL, 10); \
888 acpi_status status = set_u32(tmp, cap); \
889 if (ACPI_FAILURE(status)) \
890 return -EINVAL; \
891 return count; \
893 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO | S_IWUSR, \
894 show_bool_##value, set_bool_##value);
896 show_set_bool(wireless, ACER_CAP_WIRELESS);
897 show_set_bool(bluetooth, ACER_CAP_BLUETOOTH);
898 show_set_bool(threeg, ACER_CAP_THREEG);
901 * Read interface sysfs macro
903 static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
904 char *buf)
906 switch (interface->type) {
907 case ACER_AMW0:
908 return sprintf(buf, "AMW0\n");
909 case ACER_AMW0_V2:
910 return sprintf(buf, "AMW0 v2\n");
911 case ACER_WMID:
912 return sprintf(buf, "WMID\n");
913 default:
914 return sprintf(buf, "Error!\n");
918 static DEVICE_ATTR(interface, S_IWUGO | S_IRUGO | S_IWUSR,
919 show_interface, NULL);
922 * Platform device
924 static int __devinit acer_platform_probe(struct platform_device *device)
926 int err;
928 if (has_cap(ACER_CAP_MAILLED)) {
929 err = acer_led_init(&device->dev);
930 if (err)
931 goto error_mailled;
934 if (has_cap(ACER_CAP_BRIGHTNESS)) {
935 err = acer_backlight_init(&device->dev);
936 if (err)
937 goto error_brightness;
940 return 0;
942 error_brightness:
943 acer_led_exit();
944 error_mailled:
945 return err;
948 static int acer_platform_remove(struct platform_device *device)
950 if (has_cap(ACER_CAP_MAILLED))
951 acer_led_exit();
952 if (has_cap(ACER_CAP_BRIGHTNESS))
953 acer_backlight_exit();
954 return 0;
957 static int acer_platform_suspend(struct platform_device *dev,
958 pm_message_t state)
960 u32 value;
961 struct acer_data *data = &interface->data;
963 if (!data)
964 return -ENOMEM;
966 if (has_cap(ACER_CAP_WIRELESS)) {
967 get_u32(&value, ACER_CAP_WIRELESS);
968 data->wireless = value;
971 if (has_cap(ACER_CAP_BLUETOOTH)) {
972 get_u32(&value, ACER_CAP_BLUETOOTH);
973 data->bluetooth = value;
976 if (has_cap(ACER_CAP_MAILLED)) {
977 get_u32(&value, ACER_CAP_MAILLED);
978 data->mailled = value;
981 if (has_cap(ACER_CAP_BRIGHTNESS)) {
982 get_u32(&value, ACER_CAP_BRIGHTNESS);
983 data->brightness = value;
986 return 0;
989 static int acer_platform_resume(struct platform_device *device)
991 struct acer_data *data = &interface->data;
993 if (!data)
994 return -ENOMEM;
996 if (has_cap(ACER_CAP_WIRELESS))
997 set_u32(data->wireless, ACER_CAP_WIRELESS);
999 if (has_cap(ACER_CAP_BLUETOOTH))
1000 set_u32(data->bluetooth, ACER_CAP_BLUETOOTH);
1002 if (has_cap(ACER_CAP_THREEG))
1003 set_u32(data->threeg, ACER_CAP_THREEG);
1005 if (has_cap(ACER_CAP_MAILLED))
1006 set_u32(data->mailled, ACER_CAP_MAILLED);
1008 if (has_cap(ACER_CAP_BRIGHTNESS))
1009 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
1011 return 0;
1014 static struct platform_driver acer_platform_driver = {
1015 .driver = {
1016 .name = "acer-wmi",
1017 .owner = THIS_MODULE,
1019 .probe = acer_platform_probe,
1020 .remove = acer_platform_remove,
1021 .suspend = acer_platform_suspend,
1022 .resume = acer_platform_resume,
1025 static struct platform_device *acer_platform_device;
1027 static int remove_sysfs(struct platform_device *device)
1029 if (has_cap(ACER_CAP_WIRELESS))
1030 device_remove_file(&device->dev, &dev_attr_wireless);
1032 if (has_cap(ACER_CAP_BLUETOOTH))
1033 device_remove_file(&device->dev, &dev_attr_bluetooth);
1035 if (has_cap(ACER_CAP_THREEG))
1036 device_remove_file(&device->dev, &dev_attr_threeg);
1038 device_remove_file(&device->dev, &dev_attr_interface);
1040 return 0;
1043 static int create_sysfs(void)
1045 int retval = -ENOMEM;
1047 if (has_cap(ACER_CAP_WIRELESS)) {
1048 retval = device_create_file(&acer_platform_device->dev,
1049 &dev_attr_wireless);
1050 if (retval)
1051 goto error_sysfs;
1054 if (has_cap(ACER_CAP_BLUETOOTH)) {
1055 retval = device_create_file(&acer_platform_device->dev,
1056 &dev_attr_bluetooth);
1057 if (retval)
1058 goto error_sysfs;
1061 if (has_cap(ACER_CAP_THREEG)) {
1062 retval = device_create_file(&acer_platform_device->dev,
1063 &dev_attr_threeg);
1064 if (retval)
1065 goto error_sysfs;
1068 retval = device_create_file(&acer_platform_device->dev,
1069 &dev_attr_interface);
1070 if (retval)
1071 goto error_sysfs;
1073 return 0;
1075 error_sysfs:
1076 remove_sysfs(acer_platform_device);
1077 return retval;
1080 static int __init acer_wmi_init(void)
1082 int err;
1084 printk(ACER_INFO "Acer Laptop ACPI-WMI Extras version %s\n",
1085 ACER_WMI_VERSION);
1088 * Detect which ACPI-WMI interface we're using.
1090 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1091 interface = &AMW0_V2_interface;
1093 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1094 interface = &wmid_interface;
1096 if (wmi_has_guid(WMID_GUID2) && interface) {
1097 if (ACPI_FAILURE(WMID_set_capabilities())) {
1098 <<<<<<< HEAD:drivers/misc/acer-wmi.c
1099 printk(ACER_ERR "Unable to detect available devices\n");
1100 =======
1101 printk(ACER_ERR "Unable to detect available WMID "
1102 "devices\n");
1103 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/misc/acer-wmi.c
1104 return -ENODEV;
1106 } else if (!wmi_has_guid(WMID_GUID2) && interface) {
1107 <<<<<<< HEAD:drivers/misc/acer-wmi.c
1108 printk(ACER_ERR "Unable to detect available devices\n");
1109 =======
1110 printk(ACER_ERR "No WMID device detection method found\n");
1111 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/misc/acer-wmi.c
1112 return -ENODEV;
1115 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
1116 interface = &AMW0_interface;
1118 if (ACPI_FAILURE(AMW0_set_capabilities())) {
1119 <<<<<<< HEAD:drivers/misc/acer-wmi.c
1120 printk(ACER_ERR "Unable to detect available devices\n");
1121 =======
1122 printk(ACER_ERR "Unable to detect available AMW0 "
1123 "devices\n");
1124 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/misc/acer-wmi.c
1125 return -ENODEV;
1129 <<<<<<< HEAD:drivers/misc/acer-wmi.c
1130 if (wmi_has_guid(AMW0_GUID1)) {
1131 if (ACPI_FAILURE(AMW0_find_mailled()))
1132 printk(ACER_ERR "Unable to detect mail LED\n");
1134 =======
1135 if (wmi_has_guid(AMW0_GUID1))
1136 AMW0_find_mailled();
1137 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/misc/acer-wmi.c
1139 find_quirks();
1141 if (!interface) {
1142 <<<<<<< HEAD:drivers/misc/acer-wmi.c
1143 printk(ACER_ERR "No or unsupported WMI interface, unable to ");
1144 printk(KERN_CONT "load.\n");
1145 =======
1146 printk(ACER_ERR "No or unsupported WMI interface, unable to "
1147 "load\n");
1148 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/misc/acer-wmi.c
1149 return -ENODEV;
1152 if (platform_driver_register(&acer_platform_driver)) {
1153 printk(ACER_ERR "Unable to register platform driver.\n");
1154 goto error_platform_register;
1156 acer_platform_device = platform_device_alloc("acer-wmi", -1);
1157 platform_device_add(acer_platform_device);
1159 err = create_sysfs();
1160 if (err)
1161 return err;
1163 /* Override any initial settings with values from the commandline */
1164 acer_commandline_init();
1166 return 0;
1168 error_platform_register:
1169 return -ENODEV;
1172 static void __exit acer_wmi_exit(void)
1174 remove_sysfs(acer_platform_device);
1175 platform_device_del(acer_platform_device);
1176 platform_driver_unregister(&acer_platform_driver);
1178 printk(ACER_INFO "Acer Laptop WMI Extras unloaded\n");
1179 return;
1182 module_init(acer_wmi_init);
1183 module_exit(acer_wmi_exit);