2 * Eee PC WMI hotkey driver
4 * Copyright(C) 2010 Intel Corporation.
5 * Copyright(C) 2010 Corentin Chary <corentin.chary@gmail.com>
7 * Portions based on wistron_btns.c:
8 * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
9 * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
10 * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/types.h>
33 #include <linux/slab.h>
34 #include <linux/input.h>
35 #include <linux/input/sparse-keymap.h>
37 #include <linux/backlight.h>
38 #include <linux/leds.h>
39 #include <linux/rfkill.h>
40 #include <linux/pci.h>
41 #include <linux/pci_hotplug.h>
42 #include <linux/debugfs.h>
43 #include <linux/seq_file.h>
44 #include <linux/platform_device.h>
45 #include <linux/dmi.h>
46 #include <acpi/acpi_bus.h>
47 #include <acpi/acpi_drivers.h>
49 #define EEEPC_WMI_FILE "eeepc-wmi"
51 MODULE_AUTHOR("Yong Wang <yong.y.wang@intel.com>");
52 MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver");
53 MODULE_LICENSE("GPL");
55 #define EEEPC_ACPI_HID "ASUS010" /* old _HID used in eeepc-laptop */
57 #define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000"
58 #define EEEPC_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66"
60 MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID);
61 MODULE_ALIAS("wmi:"EEEPC_WMI_MGMT_GUID);
63 #define NOTIFY_BRNUP_MIN 0x11
64 #define NOTIFY_BRNUP_MAX 0x1f
65 #define NOTIFY_BRNDOWN_MIN 0x20
66 #define NOTIFY_BRNDOWN_MAX 0x2e
68 #define EEEPC_WMI_METHODID_DEVS 0x53564544
69 #define EEEPC_WMI_METHODID_DSTS 0x53544344
70 #define EEEPC_WMI_METHODID_CFVS 0x53564643
72 #define EEEPC_WMI_DEVID_BACKLIGHT 0x00050012
73 #define EEEPC_WMI_DEVID_TPDLED 0x00100011
74 #define EEEPC_WMI_DEVID_WLAN 0x00010011
75 #define EEEPC_WMI_DEVID_BLUETOOTH 0x00010013
76 #define EEEPC_WMI_DEVID_WWAN3G 0x00010019
78 static bool hotplug_wireless;
80 module_param(hotplug_wireless, bool, 0444);
81 MODULE_PARM_DESC(hotplug_wireless,
82 "Enable hotplug for wireless device. "
83 "If your laptop needs that, please report to "
84 "acpi4asus-user@lists.sourceforge.net.");
86 static const struct key_entry eeepc_wmi_keymap[] = {
87 /* Sleep already handled via generic ACPI code */
88 { KE_IGNORE, NOTIFY_BRNDOWN_MIN, { KEY_BRIGHTNESSDOWN } },
89 { KE_IGNORE, NOTIFY_BRNUP_MIN, { KEY_BRIGHTNESSUP } },
90 { KE_KEY, 0x30, { KEY_VOLUMEUP } },
91 { KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
92 { KE_KEY, 0x32, { KEY_MUTE } },
93 { KE_KEY, 0x5c, { KEY_F15 } },
94 { KE_KEY, 0x5d, { KEY_WLAN } },
95 { KE_KEY, 0x6b, { KEY_F13 } }, /* Disable Touchpad */
96 { KE_KEY, 0x88, { KEY_WLAN } },
97 { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } },
98 { KE_KEY, 0xe0, { KEY_PROG1 } },
99 { KE_KEY, 0xe1, { KEY_F14 } },
100 { KE_KEY, 0xe9, { KEY_DISPLAY_OFF } },
110 * eeepc-wmi/ - debugfs root directory
111 * dev_id - current dev_id
112 * ctrl_param - current ctrl_param
113 * devs - call DEVS(dev_id, ctrl_param) and print result
114 * dsts - call DSTS(dev_id) and print result
116 struct eeepc_wmi_debug {
123 bool hotplug_wireless;
125 struct input_dev *inputdev;
126 struct backlight_device *backlight_device;
127 struct platform_device *platform_device;
129 struct led_classdev tpd_led;
131 struct workqueue_struct *led_workqueue;
132 struct work_struct tpd_led_work;
134 struct rfkill *wlan_rfkill;
135 struct rfkill *bluetooth_rfkill;
136 struct rfkill *wwan3g_rfkill;
138 struct hotplug_slot *hotplug_slot;
139 struct mutex hotplug_lock;
140 struct mutex wmi_lock;
141 struct workqueue_struct *hotplug_workqueue;
142 struct work_struct hotplug_work;
144 struct eeepc_wmi_debug debug;
147 /* Only used in eeepc_wmi_init() and eeepc_wmi_exit() */
148 static struct platform_device *platform_device;
150 static int eeepc_wmi_input_init(struct eeepc_wmi *eeepc)
154 eeepc->inputdev = input_allocate_device();
155 if (!eeepc->inputdev)
158 eeepc->inputdev->name = "Eee PC WMI hotkeys";
159 eeepc->inputdev->phys = EEEPC_WMI_FILE "/input0";
160 eeepc->inputdev->id.bustype = BUS_HOST;
161 eeepc->inputdev->dev.parent = &eeepc->platform_device->dev;
163 err = sparse_keymap_setup(eeepc->inputdev, eeepc_wmi_keymap, NULL);
167 err = input_register_device(eeepc->inputdev);
169 goto err_free_keymap;
174 sparse_keymap_free(eeepc->inputdev);
176 input_free_device(eeepc->inputdev);
180 static void eeepc_wmi_input_exit(struct eeepc_wmi *eeepc)
182 if (eeepc->inputdev) {
183 sparse_keymap_free(eeepc->inputdev);
184 input_unregister_device(eeepc->inputdev);
187 eeepc->inputdev = NULL;
190 static acpi_status eeepc_wmi_get_devstate(u32 dev_id, u32 *retval)
192 struct acpi_buffer input = { (acpi_size)sizeof(u32), &dev_id };
193 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
194 union acpi_object *obj;
198 status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID,
199 1, EEEPC_WMI_METHODID_DSTS,
202 if (ACPI_FAILURE(status))
205 obj = (union acpi_object *)output.pointer;
206 if (obj && obj->type == ACPI_TYPE_INTEGER)
207 tmp = (u32)obj->integer.value;
220 static acpi_status eeepc_wmi_set_devstate(u32 dev_id, u32 ctrl_param,
223 struct bios_args args = {
225 .ctrl_param = ctrl_param,
227 struct acpi_buffer input = { (acpi_size)sizeof(args), &args };
231 status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, 1,
232 EEEPC_WMI_METHODID_DEVS,
235 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
236 union acpi_object *obj;
239 status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, 1,
240 EEEPC_WMI_METHODID_DEVS,
243 if (ACPI_FAILURE(status))
246 obj = (union acpi_object *)output.pointer;
247 if (obj && obj->type == ACPI_TYPE_INTEGER)
248 tmp = (u32)obj->integer.value;
260 /* Helper for special devices with magic return codes */
261 static int eeepc_wmi_get_devstate_simple(u32 dev_id)
266 status = eeepc_wmi_get_devstate(dev_id, &retval);
268 if (ACPI_FAILURE(status))
271 /* If the device is present, DSTS will always set some bits
272 * 0x00070000 - 1110000000000000000 - device supported
273 * 0x00060000 - 1100000000000000000 - not supported
274 * 0x00020000 - 0100000000000000000 - device supported
275 * 0x00010000 - 0010000000000000000 - not supported / special mode ?
277 if (!retval || retval == 0x00060000)
287 * These functions actually update the LED's, and are called from a
288 * workqueue. By doing this as separate work rather than when the LED
289 * subsystem asks, we avoid messing with the Eeepc ACPI stuff during a
290 * potentially bad time, such as a timer interrupt.
292 static void tpd_led_update(struct work_struct *work)
295 struct eeepc_wmi *eeepc;
297 eeepc = container_of(work, struct eeepc_wmi, tpd_led_work);
299 ctrl_param = eeepc->tpd_led_wk;
300 eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_TPDLED, ctrl_param, NULL);
303 static void tpd_led_set(struct led_classdev *led_cdev,
304 enum led_brightness value)
306 struct eeepc_wmi *eeepc;
308 eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led);
310 eeepc->tpd_led_wk = !!value;
311 queue_work(eeepc->led_workqueue, &eeepc->tpd_led_work);
314 static int read_tpd_state(struct eeepc_wmi *eeepc)
316 return eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_TPDLED);
319 static enum led_brightness tpd_led_get(struct led_classdev *led_cdev)
321 struct eeepc_wmi *eeepc;
323 eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led);
325 return read_tpd_state(eeepc);
328 static int eeepc_wmi_led_init(struct eeepc_wmi *eeepc)
332 if (read_tpd_state(eeepc) < 0)
335 eeepc->led_workqueue = create_singlethread_workqueue("led_workqueue");
336 if (!eeepc->led_workqueue)
338 INIT_WORK(&eeepc->tpd_led_work, tpd_led_update);
340 eeepc->tpd_led.name = "eeepc::touchpad";
341 eeepc->tpd_led.brightness_set = tpd_led_set;
342 eeepc->tpd_led.brightness_get = tpd_led_get;
343 eeepc->tpd_led.max_brightness = 1;
345 rv = led_classdev_register(&eeepc->platform_device->dev,
348 destroy_workqueue(eeepc->led_workqueue);
355 static void eeepc_wmi_led_exit(struct eeepc_wmi *eeepc)
357 if (eeepc->tpd_led.dev)
358 led_classdev_unregister(&eeepc->tpd_led);
359 if (eeepc->led_workqueue)
360 destroy_workqueue(eeepc->led_workqueue);
364 * PCI hotplug (for wlan rfkill)
366 static bool eeepc_wlan_rfkill_blocked(struct eeepc_wmi *eeepc)
368 int result = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WLAN);
375 static void eeepc_rfkill_hotplug(struct eeepc_wmi *eeepc)
383 mutex_lock(&eeepc->wmi_lock);
384 blocked = eeepc_wlan_rfkill_blocked(eeepc);
385 mutex_unlock(&eeepc->wmi_lock);
387 mutex_lock(&eeepc->hotplug_lock);
389 if (eeepc->wlan_rfkill)
390 rfkill_set_sw_state(eeepc->wlan_rfkill, blocked);
392 if (eeepc->hotplug_slot) {
393 bus = pci_find_bus(0, 1);
395 pr_warning("Unable to find PCI bus 1?\n");
399 if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) {
400 pr_err("Unable to read PCI config space?\n");
403 absent = (l == 0xffffffff);
405 if (blocked != absent) {
406 pr_warning("BIOS says wireless lan is %s, "
407 "but the pci device is %s\n",
408 blocked ? "blocked" : "unblocked",
409 absent ? "absent" : "present");
410 pr_warning("skipped wireless hotplug as probably "
411 "inappropriate for this model\n");
416 dev = pci_get_slot(bus, 0);
418 /* Device already present */
422 dev = pci_scan_single_device(bus, 0);
424 pci_bus_assign_resources(bus);
425 if (pci_bus_add_device(dev))
426 pr_err("Unable to hotplug wifi\n");
429 dev = pci_get_slot(bus, 0);
431 pci_remove_bus_device(dev);
438 mutex_unlock(&eeepc->hotplug_lock);
441 static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
443 struct eeepc_wmi *eeepc = data;
445 if (event != ACPI_NOTIFY_BUS_CHECK)
449 * We can't call directly eeepc_rfkill_hotplug because most
450 * of the time WMBC is still being executed and not reetrant.
451 * There is currently no way to tell ACPICA that we want this
452 * method to be serialized, we schedule a eeepc_rfkill_hotplug
453 * call later, in a safer context.
455 queue_work(eeepc->hotplug_workqueue, &eeepc->hotplug_work);
458 static int eeepc_register_rfkill_notifier(struct eeepc_wmi *eeepc,
464 status = acpi_get_handle(NULL, node, &handle);
466 if (ACPI_SUCCESS(status)) {
467 status = acpi_install_notify_handler(handle,
471 if (ACPI_FAILURE(status))
472 pr_warning("Failed to register notify on %s\n", node);
479 static void eeepc_unregister_rfkill_notifier(struct eeepc_wmi *eeepc,
482 acpi_status status = AE_OK;
485 status = acpi_get_handle(NULL, node, &handle);
487 if (ACPI_SUCCESS(status)) {
488 status = acpi_remove_notify_handler(handle,
490 eeepc_rfkill_notify);
491 if (ACPI_FAILURE(status))
492 pr_err("Error removing rfkill notify handler %s\n",
497 static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot,
500 int result = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WLAN);
509 static void eeepc_cleanup_pci_hotplug(struct hotplug_slot *hotplug_slot)
511 kfree(hotplug_slot->info);
515 static struct hotplug_slot_ops eeepc_hotplug_slot_ops = {
516 .owner = THIS_MODULE,
517 .get_adapter_status = eeepc_get_adapter_status,
518 .get_power_status = eeepc_get_adapter_status,
521 static void eeepc_hotplug_work(struct work_struct *work)
523 struct eeepc_wmi *eeepc;
525 eeepc = container_of(work, struct eeepc_wmi, hotplug_work);
526 eeepc_rfkill_hotplug(eeepc);
529 static int eeepc_setup_pci_hotplug(struct eeepc_wmi *eeepc)
532 struct pci_bus *bus = pci_find_bus(0, 1);
535 pr_err("Unable to find wifi PCI bus\n");
539 eeepc->hotplug_workqueue =
540 create_singlethread_workqueue("hotplug_workqueue");
541 if (!eeepc->hotplug_workqueue)
542 goto error_workqueue;
544 INIT_WORK(&eeepc->hotplug_work, eeepc_hotplug_work);
546 eeepc->hotplug_slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
547 if (!eeepc->hotplug_slot)
550 eeepc->hotplug_slot->info = kzalloc(sizeof(struct hotplug_slot_info),
552 if (!eeepc->hotplug_slot->info)
555 eeepc->hotplug_slot->private = eeepc;
556 eeepc->hotplug_slot->release = &eeepc_cleanup_pci_hotplug;
557 eeepc->hotplug_slot->ops = &eeepc_hotplug_slot_ops;
558 eeepc_get_adapter_status(eeepc->hotplug_slot,
559 &eeepc->hotplug_slot->info->adapter_status);
561 ret = pci_hp_register(eeepc->hotplug_slot, bus, 0, "eeepc-wifi");
563 pr_err("Unable to register hotplug slot - %d\n", ret);
570 kfree(eeepc->hotplug_slot->info);
572 kfree(eeepc->hotplug_slot);
573 eeepc->hotplug_slot = NULL;
575 destroy_workqueue(eeepc->hotplug_workqueue);
583 static int eeepc_rfkill_set(void *data, bool blocked)
585 int dev_id = (unsigned long)data;
586 u32 ctrl_param = !blocked;
589 status = eeepc_wmi_set_devstate(dev_id, ctrl_param, NULL);
591 if (ACPI_FAILURE(status))
597 static void eeepc_rfkill_query(struct rfkill *rfkill, void *data)
599 int dev_id = (unsigned long)data;
602 result = eeepc_wmi_get_devstate_simple(dev_id);
607 rfkill_set_sw_state(rfkill, !result);
610 static int eeepc_rfkill_wlan_set(void *data, bool blocked)
612 struct eeepc_wmi *eeepc = data;
616 * This handler is enabled only if hotplug is enabled.
617 * In this case, the eeepc_wmi_set_devstate() will
618 * trigger a wmi notification and we need to wait
619 * this call to finish before being able to call
622 mutex_lock(&eeepc->wmi_lock);
623 ret = eeepc_rfkill_set((void *)(long)EEEPC_WMI_DEVID_WLAN, blocked);
624 mutex_unlock(&eeepc->wmi_lock);
628 static void eeepc_rfkill_wlan_query(struct rfkill *rfkill, void *data)
630 eeepc_rfkill_query(rfkill, (void *)(long)EEEPC_WMI_DEVID_WLAN);
633 static const struct rfkill_ops eeepc_rfkill_wlan_ops = {
634 .set_block = eeepc_rfkill_wlan_set,
635 .query = eeepc_rfkill_wlan_query,
638 static const struct rfkill_ops eeepc_rfkill_ops = {
639 .set_block = eeepc_rfkill_set,
640 .query = eeepc_rfkill_query,
643 static int eeepc_new_rfkill(struct eeepc_wmi *eeepc,
644 struct rfkill **rfkill,
646 enum rfkill_type type, int dev_id)
648 int result = eeepc_wmi_get_devstate_simple(dev_id);
653 if (dev_id == EEEPC_WMI_DEVID_WLAN && eeepc->hotplug_wireless)
654 *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type,
655 &eeepc_rfkill_wlan_ops, eeepc);
657 *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type,
658 &eeepc_rfkill_ops, (void *)(long)dev_id);
663 rfkill_init_sw_state(*rfkill, !result);
664 result = rfkill_register(*rfkill);
666 rfkill_destroy(*rfkill);
673 static void eeepc_wmi_rfkill_exit(struct eeepc_wmi *eeepc)
675 eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5");
676 eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6");
677 eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7");
678 if (eeepc->wlan_rfkill) {
679 rfkill_unregister(eeepc->wlan_rfkill);
680 rfkill_destroy(eeepc->wlan_rfkill);
681 eeepc->wlan_rfkill = NULL;
684 * Refresh pci hotplug in case the rfkill state was changed after
685 * eeepc_unregister_rfkill_notifier()
687 eeepc_rfkill_hotplug(eeepc);
688 if (eeepc->hotplug_slot)
689 pci_hp_deregister(eeepc->hotplug_slot);
690 if (eeepc->hotplug_workqueue)
691 destroy_workqueue(eeepc->hotplug_workqueue);
693 if (eeepc->bluetooth_rfkill) {
694 rfkill_unregister(eeepc->bluetooth_rfkill);
695 rfkill_destroy(eeepc->bluetooth_rfkill);
696 eeepc->bluetooth_rfkill = NULL;
698 if (eeepc->wwan3g_rfkill) {
699 rfkill_unregister(eeepc->wwan3g_rfkill);
700 rfkill_destroy(eeepc->wwan3g_rfkill);
701 eeepc->wwan3g_rfkill = NULL;
705 static int eeepc_wmi_rfkill_init(struct eeepc_wmi *eeepc)
709 mutex_init(&eeepc->hotplug_lock);
710 mutex_init(&eeepc->wmi_lock);
712 result = eeepc_new_rfkill(eeepc, &eeepc->wlan_rfkill,
713 "eeepc-wlan", RFKILL_TYPE_WLAN,
714 EEEPC_WMI_DEVID_WLAN);
716 if (result && result != -ENODEV)
719 result = eeepc_new_rfkill(eeepc, &eeepc->bluetooth_rfkill,
720 "eeepc-bluetooth", RFKILL_TYPE_BLUETOOTH,
721 EEEPC_WMI_DEVID_BLUETOOTH);
723 if (result && result != -ENODEV)
726 result = eeepc_new_rfkill(eeepc, &eeepc->wwan3g_rfkill,
727 "eeepc-wwan3g", RFKILL_TYPE_WWAN,
728 EEEPC_WMI_DEVID_WWAN3G);
730 if (result && result != -ENODEV)
733 result = eeepc_setup_pci_hotplug(eeepc);
735 * If we get -EBUSY then something else is handling the PCI hotplug -
736 * don't fail in this case
738 if (result == -EBUSY)
741 eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5");
742 eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6");
743 eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7");
745 * Refresh pci hotplug in case the rfkill state was changed during
748 eeepc_rfkill_hotplug(eeepc);
751 if (result && result != -ENODEV)
752 eeepc_wmi_rfkill_exit(eeepc);
754 if (result == -ENODEV)
763 static int read_brightness(struct backlight_device *bd)
768 status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_BACKLIGHT, &retval);
770 if (ACPI_FAILURE(status))
773 return retval & 0xFF;
776 static int update_bl_status(struct backlight_device *bd)
782 ctrl_param = bd->props.brightness;
784 status = eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_BACKLIGHT,
787 if (ACPI_FAILURE(status))
793 static const struct backlight_ops eeepc_wmi_bl_ops = {
794 .get_brightness = read_brightness,
795 .update_status = update_bl_status,
798 static int eeepc_wmi_backlight_notify(struct eeepc_wmi *eeepc, int code)
800 struct backlight_device *bd = eeepc->backlight_device;
801 int old = bd->props.brightness;
804 if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
805 new = code - NOTIFY_BRNUP_MIN + 1;
806 else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX)
807 new = code - NOTIFY_BRNDOWN_MIN;
809 bd->props.brightness = new;
810 backlight_update_status(bd);
811 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
816 static int eeepc_wmi_backlight_init(struct eeepc_wmi *eeepc)
818 struct backlight_device *bd;
819 struct backlight_properties props;
821 memset(&props, 0, sizeof(struct backlight_properties));
822 props.max_brightness = 15;
823 bd = backlight_device_register(EEEPC_WMI_FILE,
824 &eeepc->platform_device->dev, eeepc,
825 &eeepc_wmi_bl_ops, &props);
827 pr_err("Could not register backlight device\n");
831 eeepc->backlight_device = bd;
833 bd->props.brightness = read_brightness(bd);
834 bd->props.power = FB_BLANK_UNBLANK;
835 backlight_update_status(bd);
840 static void eeepc_wmi_backlight_exit(struct eeepc_wmi *eeepc)
842 if (eeepc->backlight_device)
843 backlight_device_unregister(eeepc->backlight_device);
845 eeepc->backlight_device = NULL;
848 static void eeepc_wmi_notify(u32 value, void *context)
850 struct eeepc_wmi *eeepc = context;
851 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
852 union acpi_object *obj;
857 status = wmi_get_event_data(value, &response);
858 if (status != AE_OK) {
859 pr_err("bad event status 0x%x\n", status);
863 obj = (union acpi_object *)response.pointer;
865 if (obj && obj->type == ACPI_TYPE_INTEGER) {
866 code = obj->integer.value;
869 if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
870 code = NOTIFY_BRNUP_MIN;
871 else if (code >= NOTIFY_BRNDOWN_MIN &&
872 code <= NOTIFY_BRNDOWN_MAX)
873 code = NOTIFY_BRNDOWN_MIN;
875 if (code == NOTIFY_BRNUP_MIN || code == NOTIFY_BRNDOWN_MIN) {
876 if (!acpi_video_backlight_support())
877 eeepc_wmi_backlight_notify(eeepc, orig_code);
880 if (!sparse_keymap_report_event(eeepc->inputdev,
882 pr_info("Unknown key %x pressed\n", code);
888 static ssize_t store_cpufv(struct device *dev, struct device_attribute *attr,
889 const char *buf, size_t count)
892 struct acpi_buffer input = { (acpi_size)sizeof(value), &value };
895 if (!count || sscanf(buf, "%i", &value) != 1)
897 if (value < 0 || value > 2)
900 status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID,
901 1, EEEPC_WMI_METHODID_CFVS, &input, NULL);
903 if (ACPI_FAILURE(status))
909 static DEVICE_ATTR(cpufv, S_IRUGO | S_IWUSR, NULL, store_cpufv);
911 static struct attribute *platform_attributes[] = {
912 &dev_attr_cpufv.attr,
916 static struct attribute_group platform_attribute_group = {
917 .attrs = platform_attributes
920 static void eeepc_wmi_sysfs_exit(struct platform_device *device)
922 sysfs_remove_group(&device->dev.kobj, &platform_attribute_group);
925 static int eeepc_wmi_sysfs_init(struct platform_device *device)
927 return sysfs_create_group(&device->dev.kobj, &platform_attribute_group);
933 static int __init eeepc_wmi_platform_init(struct eeepc_wmi *eeepc)
937 eeepc->platform_device = platform_device_alloc(EEEPC_WMI_FILE, -1);
938 if (!eeepc->platform_device)
940 platform_set_drvdata(eeepc->platform_device, eeepc);
942 err = platform_device_add(eeepc->platform_device);
944 goto fail_platform_device;
946 err = eeepc_wmi_sysfs_init(eeepc->platform_device);
952 platform_device_del(eeepc->platform_device);
953 fail_platform_device:
954 platform_device_put(eeepc->platform_device);
958 static void eeepc_wmi_platform_exit(struct eeepc_wmi *eeepc)
960 eeepc_wmi_sysfs_exit(eeepc->platform_device);
961 platform_device_unregister(eeepc->platform_device);
967 struct eeepc_wmi_debugfs_node {
968 struct eeepc_wmi *eeepc;
970 int (*show)(struct seq_file *m, void *data);
973 static int show_dsts(struct seq_file *m, void *data)
975 struct eeepc_wmi *eeepc = m->private;
979 status = eeepc_wmi_get_devstate(eeepc->debug.dev_id, &retval);
981 if (ACPI_FAILURE(status))
984 seq_printf(m, "DSTS(%x) = %x\n", eeepc->debug.dev_id, retval);
989 static int show_devs(struct seq_file *m, void *data)
991 struct eeepc_wmi *eeepc = m->private;
995 status = eeepc_wmi_set_devstate(eeepc->debug.dev_id,
996 eeepc->debug.ctrl_param, &retval);
997 if (ACPI_FAILURE(status))
1000 seq_printf(m, "DEVS(%x, %x) = %x\n", eeepc->debug.dev_id,
1001 eeepc->debug.ctrl_param, retval);
1006 static struct eeepc_wmi_debugfs_node eeepc_wmi_debug_files[] = {
1007 { NULL, "devs", show_devs },
1008 { NULL, "dsts", show_dsts },
1011 static int eeepc_wmi_debugfs_open(struct inode *inode, struct file *file)
1013 struct eeepc_wmi_debugfs_node *node = inode->i_private;
1015 return single_open(file, node->show, node->eeepc);
1018 static const struct file_operations eeepc_wmi_debugfs_io_ops = {
1019 .owner = THIS_MODULE,
1020 .open = eeepc_wmi_debugfs_open,
1022 .llseek = seq_lseek,
1023 .release = single_release,
1026 static void eeepc_wmi_debugfs_exit(struct eeepc_wmi *eeepc)
1028 debugfs_remove_recursive(eeepc->debug.root);
1031 static int eeepc_wmi_debugfs_init(struct eeepc_wmi *eeepc)
1033 struct dentry *dent;
1036 eeepc->debug.root = debugfs_create_dir(EEEPC_WMI_FILE, NULL);
1037 if (!eeepc->debug.root) {
1038 pr_err("failed to create debugfs directory");
1042 dent = debugfs_create_x32("dev_id", S_IRUGO|S_IWUSR,
1043 eeepc->debug.root, &eeepc->debug.dev_id);
1047 dent = debugfs_create_x32("ctrl_param", S_IRUGO|S_IWUSR,
1048 eeepc->debug.root, &eeepc->debug.ctrl_param);
1052 for (i = 0; i < ARRAY_SIZE(eeepc_wmi_debug_files); i++) {
1053 struct eeepc_wmi_debugfs_node *node = &eeepc_wmi_debug_files[i];
1055 node->eeepc = eeepc;
1056 dent = debugfs_create_file(node->name, S_IFREG | S_IRUGO,
1057 eeepc->debug.root, node,
1058 &eeepc_wmi_debugfs_io_ops);
1060 pr_err("failed to create debug file: %s\n", node->name);
1068 eeepc_wmi_debugfs_exit(eeepc);
1075 static void eeepc_dmi_check(struct eeepc_wmi *eeepc)
1079 model = dmi_get_system_info(DMI_PRODUCT_NAME);
1084 * Whitelist for wlan hotplug
1086 * Eeepc 1000H needs the current hotplug code to handle
1087 * Fn+F2 correctly. We may add other Eeepc here later, but
1088 * it seems that most of the laptops supported by eeepc-wmi
1089 * don't need to be on this list
1091 if (strcmp(model, "1000H") == 0) {
1092 eeepc->hotplug_wireless = true;
1093 pr_info("wlan hotplug enabled\n");
1097 static struct platform_device * __init eeepc_wmi_add(void)
1099 struct eeepc_wmi *eeepc;
1103 eeepc = kzalloc(sizeof(struct eeepc_wmi), GFP_KERNEL);
1105 return ERR_PTR(-ENOMEM);
1107 eeepc->hotplug_wireless = hotplug_wireless;
1108 eeepc_dmi_check(eeepc);
1111 * Register the platform device first. It is used as a parent for the
1112 * sub-devices below.
1114 err = eeepc_wmi_platform_init(eeepc);
1118 err = eeepc_wmi_input_init(eeepc);
1122 err = eeepc_wmi_led_init(eeepc);
1126 err = eeepc_wmi_rfkill_init(eeepc);
1130 if (!acpi_video_backlight_support()) {
1131 err = eeepc_wmi_backlight_init(eeepc);
1133 goto fail_backlight;
1135 pr_info("Backlight controlled by ACPI video driver\n");
1137 status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID,
1138 eeepc_wmi_notify, eeepc);
1139 if (ACPI_FAILURE(status)) {
1140 pr_err("Unable to register notify handler - %d\n",
1143 goto fail_wmi_handler;
1146 err = eeepc_wmi_debugfs_init(eeepc);
1150 return eeepc->platform_device;
1153 wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID);
1155 eeepc_wmi_backlight_exit(eeepc);
1157 eeepc_wmi_rfkill_exit(eeepc);
1159 eeepc_wmi_led_exit(eeepc);
1161 eeepc_wmi_input_exit(eeepc);
1163 eeepc_wmi_platform_exit(eeepc);
1166 return ERR_PTR(err);
1169 static int eeepc_wmi_remove(struct platform_device *device)
1171 struct eeepc_wmi *eeepc;
1173 eeepc = platform_get_drvdata(device);
1174 wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID);
1175 eeepc_wmi_backlight_exit(eeepc);
1176 eeepc_wmi_input_exit(eeepc);
1177 eeepc_wmi_led_exit(eeepc);
1178 eeepc_wmi_rfkill_exit(eeepc);
1179 eeepc_wmi_debugfs_exit(eeepc);
1180 eeepc_wmi_platform_exit(eeepc);
1186 static struct platform_driver platform_driver = {
1188 .name = EEEPC_WMI_FILE,
1189 .owner = THIS_MODULE,
1193 static acpi_status __init eeepc_wmi_parse_device(acpi_handle handle, u32 level,
1194 void *context, void **retval)
1196 pr_warning("Found legacy ATKD device (%s)", EEEPC_ACPI_HID);
1197 *(bool *)context = true;
1198 return AE_CTRL_TERMINATE;
1201 static int __init eeepc_wmi_check_atkd(void)
1206 status = acpi_get_devices(EEEPC_ACPI_HID, eeepc_wmi_parse_device,
1209 if (ACPI_FAILURE(status) || !found)
1214 static int __init eeepc_wmi_init(void)
1218 if (!wmi_has_guid(EEEPC_WMI_EVENT_GUID) ||
1219 !wmi_has_guid(EEEPC_WMI_MGMT_GUID)) {
1220 pr_warning("No known WMI GUID found\n");
1224 if (eeepc_wmi_check_atkd()) {
1225 pr_warning("WMI device present, but legacy ATKD device is also "
1226 "present and enabled.");
1227 pr_warning("You probably booted with acpi_osi=\"Linux\" or "
1228 "acpi_osi=\"!Windows 2009\"");
1229 pr_warning("Can't load eeepc-wmi, use default acpi_osi "
1230 "(preferred) or eeepc-laptop");
1234 platform_device = eeepc_wmi_add();
1235 if (IS_ERR(platform_device)) {
1236 err = PTR_ERR(platform_device);
1237 goto fail_eeepc_wmi;
1240 err = platform_driver_register(&platform_driver);
1242 pr_warning("Unable to register platform driver\n");
1243 goto fail_platform_driver;
1248 fail_platform_driver:
1249 eeepc_wmi_remove(platform_device);
1254 static void __exit eeepc_wmi_exit(void)
1256 eeepc_wmi_remove(platform_device);
1257 platform_driver_unregister(&platform_driver);
1260 module_init(eeepc_wmi_init);
1261 module_exit(eeepc_wmi_exit);