1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Asus PC WMI hotkey driver
5 * Copyright(C) 2010 Intel Corporation.
6 * Copyright(C) 2010-2011 Corentin Chary <corentin.chary@gmail.com>
8 * Portions based on wistron_btns.c:
9 * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
10 * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
11 * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/types.h>
20 #include <linux/slab.h>
21 #include <linux/input.h>
22 #include <linux/input/sparse-keymap.h>
24 #include <linux/backlight.h>
25 #include <linux/leds.h>
26 #include <linux/rfkill.h>
27 #include <linux/pci.h>
28 #include <linux/pci_hotplug.h>
29 #include <linux/hwmon.h>
30 #include <linux/hwmon-sysfs.h>
31 #include <linux/debugfs.h>
32 #include <linux/seq_file.h>
33 #include <linux/platform_data/x86/asus-wmi.h>
34 #include <linux/platform_device.h>
35 #include <linux/thermal.h>
36 #include <linux/acpi.h>
37 #include <linux/dmi.h>
38 #include <acpi/video.h>
42 MODULE_AUTHOR("Corentin Chary <corentin.chary@gmail.com>, "
43 "Yong Wang <yong.y.wang@intel.com>");
44 MODULE_DESCRIPTION("Asus Generic WMI Driver");
45 MODULE_LICENSE("GPL");
47 #define to_asus_wmi_driver(pdrv) \
48 (container_of((pdrv), struct asus_wmi_driver, platform_driver))
50 #define ASUS_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66"
52 #define NOTIFY_BRNUP_MIN 0x11
53 #define NOTIFY_BRNUP_MAX 0x1f
54 #define NOTIFY_BRNDOWN_MIN 0x20
55 #define NOTIFY_BRNDOWN_MAX 0x2e
56 #define NOTIFY_FNLOCK_TOGGLE 0x4e
57 #define NOTIFY_KBD_BRTUP 0xc4
58 #define NOTIFY_KBD_BRTDWN 0xc5
59 #define NOTIFY_KBD_BRTTOGGLE 0xc7
60 #define NOTIFY_KBD_FBM 0x99
62 #define ASUS_WMI_FNLOCK_BIOS_DISABLED BIT(0)
64 #define ASUS_FAN_DESC "cpu_fan"
65 #define ASUS_FAN_MFUN 0x13
66 #define ASUS_FAN_SFUN_READ 0x06
67 #define ASUS_FAN_SFUN_WRITE 0x07
68 #define ASUS_FAN_CTRL_MANUAL 1
69 #define ASUS_FAN_CTRL_AUTO 2
71 #define ASUS_FAN_MODE_NORMAL 0
72 #define ASUS_FAN_MODE_OVERBOOST 1
73 #define ASUS_FAN_MODE_OVERBOOST_MASK 0x01
74 #define ASUS_FAN_MODE_SILENT 2
75 #define ASUS_FAN_MODE_SILENT_MASK 0x02
76 #define ASUS_FAN_MODES_MASK 0x03
78 #define USB_INTEL_XUSB2PR 0xD0
79 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
81 #define ASUS_ACPI_UID_ASUSWMI "ASUSWMI"
82 #define ASUS_ACPI_UID_ATK "ATK"
84 #define WMI_EVENT_QUEUE_SIZE 0x10
85 #define WMI_EVENT_QUEUE_END 0x1
86 #define WMI_EVENT_MASK 0xFFFF
87 /* The WMI hotkey event value is always the same. */
88 #define WMI_EVENT_VALUE_ATK 0xFF
90 #define WMI_EVENT_MASK 0xFFFF
92 static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL };
94 static bool ashs_present(void)
98 if (acpi_dev_found(ashs_ids[i++]))
107 u32 arg2; /* At least TUF Gaming series uses 3 dword input buffer. */
111 * Struct that's used for all methods called via AGFN. Naming is
112 * identically to the AML code.
115 u16 mfun; /* probably "Multi-function" to be called */
116 u16 sfun; /* probably "Sub-function" to be called */
117 u16 len; /* size of the hole struct, including subfunction fields */
118 u8 stas; /* not used by now */
119 u8 err; /* zero on success */
122 /* struct used for calling fan read and write methods */
124 struct agfn_args agfn; /* common fields */
125 u8 fan; /* fan number: 0: set auto mode 1: 1st fan */
126 u32 speed; /* read: RPM/100 - write: 0-255 */
130 * <platform>/ - debugfs root directory
131 * dev_id - current dev_id
132 * ctrl_param - current ctrl_param
133 * method_id - current method_id
134 * devs - call DEVS(dev_id, ctrl_param) and print result
135 * dsts - call DSTS(dev_id) and print result
136 * call - call method_id(dev_id, ctrl_param) and print result
138 struct asus_wmi_debug {
146 struct asus_wmi *asus;
147 struct rfkill *rfkill;
155 bool wmi_event_queue;
157 struct input_dev *inputdev;
158 struct backlight_device *backlight_device;
159 struct platform_device *platform_device;
161 struct led_classdev wlan_led;
163 struct led_classdev tpd_led;
165 struct led_classdev kbd_led;
167 struct led_classdev lightbar_led;
169 struct workqueue_struct *led_workqueue;
170 struct work_struct tpd_led_work;
171 struct work_struct wlan_led_work;
172 struct work_struct lightbar_led_work;
174 struct asus_rfkill wlan;
175 struct asus_rfkill bluetooth;
176 struct asus_rfkill wimax;
177 struct asus_rfkill wwan3g;
178 struct asus_rfkill gps;
179 struct asus_rfkill uwb;
181 bool asus_hwmon_fan_manual_mode;
182 int asus_hwmon_num_fans;
185 bool fan_mode_available;
189 struct hotplug_slot hotplug_slot;
190 struct mutex hotplug_lock;
191 struct mutex wmi_lock;
192 struct workqueue_struct *hotplug_workqueue;
193 struct work_struct hotplug_work;
197 struct asus_wmi_debug debug;
199 struct asus_wmi_driver *driver;
202 /* Input **********************************************************************/
204 static int asus_wmi_input_init(struct asus_wmi *asus)
208 asus->inputdev = input_allocate_device();
212 asus->inputdev->name = asus->driver->input_name;
213 asus->inputdev->phys = asus->driver->input_phys;
214 asus->inputdev->id.bustype = BUS_HOST;
215 asus->inputdev->dev.parent = &asus->platform_device->dev;
216 set_bit(EV_REP, asus->inputdev->evbit);
218 err = sparse_keymap_setup(asus->inputdev, asus->driver->keymap, NULL);
222 err = input_register_device(asus->inputdev);
229 input_free_device(asus->inputdev);
233 static void asus_wmi_input_exit(struct asus_wmi *asus)
236 input_unregister_device(asus->inputdev);
238 asus->inputdev = NULL;
241 /* WMI ************************************************************************/
243 static int asus_wmi_evaluate_method3(u32 method_id,
244 u32 arg0, u32 arg1, u32 arg2, u32 *retval)
246 struct bios_args args = {
251 struct acpi_buffer input = { (acpi_size) sizeof(args), &args };
252 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
254 union acpi_object *obj;
257 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID, 0, method_id,
260 if (ACPI_FAILURE(status))
263 obj = (union acpi_object *)output.pointer;
264 if (obj && obj->type == ACPI_TYPE_INTEGER)
265 tmp = (u32) obj->integer.value;
272 if (tmp == ASUS_WMI_UNSUPPORTED_METHOD)
278 int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1, u32 *retval)
280 return asus_wmi_evaluate_method3(method_id, arg0, arg1, 0, retval);
282 EXPORT_SYMBOL_GPL(asus_wmi_evaluate_method);
284 static int asus_wmi_evaluate_method_agfn(const struct acpi_buffer args)
286 struct acpi_buffer input;
292 * Copy to dma capable address otherwise memory corruption occurs as
293 * bios has to be able to access it.
295 input.pointer = kzalloc(args.length, GFP_DMA | GFP_KERNEL);
296 input.length = args.length;
299 phys_addr = virt_to_phys(input.pointer);
300 memcpy(input.pointer, args.pointer, args.length);
302 status = asus_wmi_evaluate_method(ASUS_WMI_METHODID_AGFN,
303 phys_addr, 0, &retval);
305 memcpy(args.pointer, input.pointer, args.length);
307 kfree(input.pointer);
314 static int asus_wmi_get_devstate(struct asus_wmi *asus, u32 dev_id, u32 *retval)
316 return asus_wmi_evaluate_method(asus->dsts_id, dev_id, 0, retval);
319 static int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param,
322 return asus_wmi_evaluate_method(ASUS_WMI_METHODID_DEVS, dev_id,
326 /* Helper for special devices with magic return codes */
327 static int asus_wmi_get_devstate_bits(struct asus_wmi *asus,
328 u32 dev_id, u32 mask)
333 err = asus_wmi_get_devstate(asus, dev_id, &retval);
338 if (!(retval & ASUS_WMI_DSTS_PRESENCE_BIT))
341 if (mask == ASUS_WMI_DSTS_STATUS_BIT) {
342 if (retval & ASUS_WMI_DSTS_UNKNOWN_BIT)
346 return retval & mask;
349 static int asus_wmi_get_devstate_simple(struct asus_wmi *asus, u32 dev_id)
351 return asus_wmi_get_devstate_bits(asus, dev_id,
352 ASUS_WMI_DSTS_STATUS_BIT);
355 /* LEDs ***********************************************************************/
358 * These functions actually update the LED's, and are called from a
359 * workqueue. By doing this as separate work rather than when the LED
360 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
361 * potentially bad time, such as a timer interrupt.
363 static void tpd_led_update(struct work_struct *work)
366 struct asus_wmi *asus;
368 asus = container_of(work, struct asus_wmi, tpd_led_work);
370 ctrl_param = asus->tpd_led_wk;
371 asus_wmi_set_devstate(ASUS_WMI_DEVID_TOUCHPAD_LED, ctrl_param, NULL);
374 static void tpd_led_set(struct led_classdev *led_cdev,
375 enum led_brightness value)
377 struct asus_wmi *asus;
379 asus = container_of(led_cdev, struct asus_wmi, tpd_led);
381 asus->tpd_led_wk = !!value;
382 queue_work(asus->led_workqueue, &asus->tpd_led_work);
385 static int read_tpd_led_state(struct asus_wmi *asus)
387 return asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_TOUCHPAD_LED);
390 static enum led_brightness tpd_led_get(struct led_classdev *led_cdev)
392 struct asus_wmi *asus;
394 asus = container_of(led_cdev, struct asus_wmi, tpd_led);
396 return read_tpd_led_state(asus);
399 static void kbd_led_update(struct asus_wmi *asus)
405 * bit 7: light on/off
407 if (asus->kbd_led_wk > 0)
408 ctrl_param = 0x80 | (asus->kbd_led_wk & 0x7F);
410 asus_wmi_set_devstate(ASUS_WMI_DEVID_KBD_BACKLIGHT, ctrl_param, NULL);
413 static int kbd_led_read(struct asus_wmi *asus, int *level, int *env)
419 * bit 7: light on/off
420 * bit 8-10: environment (0: dark, 1: normal, 2: light)
421 * bit 17: status unknown
423 retval = asus_wmi_get_devstate_bits(asus, ASUS_WMI_DEVID_KBD_BACKLIGHT,
426 /* Unknown status is considered as off */
427 if (retval == 0x8000)
432 *level = retval & 0x7F;
434 *env = (retval >> 8) & 0x7F;
441 static void do_kbd_led_set(struct led_classdev *led_cdev, int value)
443 struct asus_wmi *asus;
446 asus = container_of(led_cdev, struct asus_wmi, kbd_led);
447 max_level = asus->kbd_led.max_brightness;
449 if (value > max_level)
454 asus->kbd_led_wk = value;
455 kbd_led_update(asus);
458 static void kbd_led_set(struct led_classdev *led_cdev,
459 enum led_brightness value)
461 /* Prevent disabling keyboard backlight on module unregister */
462 if (led_cdev->flags & LED_UNREGISTERING)
465 do_kbd_led_set(led_cdev, value);
468 static void kbd_led_set_by_kbd(struct asus_wmi *asus, enum led_brightness value)
470 struct led_classdev *led_cdev = &asus->kbd_led;
472 do_kbd_led_set(led_cdev, value);
473 led_classdev_notify_brightness_hw_changed(led_cdev, asus->kbd_led_wk);
476 static enum led_brightness kbd_led_get(struct led_classdev *led_cdev)
478 struct asus_wmi *asus;
481 asus = container_of(led_cdev, struct asus_wmi, kbd_led);
483 retval = kbd_led_read(asus, &value, NULL);
491 static int wlan_led_unknown_state(struct asus_wmi *asus)
495 asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WIRELESS_LED, &result);
497 return result & ASUS_WMI_DSTS_UNKNOWN_BIT;
500 static int wlan_led_presence(struct asus_wmi *asus)
504 asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WIRELESS_LED, &result);
506 return result & ASUS_WMI_DSTS_PRESENCE_BIT;
509 static void wlan_led_update(struct work_struct *work)
512 struct asus_wmi *asus;
514 asus = container_of(work, struct asus_wmi, wlan_led_work);
516 ctrl_param = asus->wlan_led_wk;
517 asus_wmi_set_devstate(ASUS_WMI_DEVID_WIRELESS_LED, ctrl_param, NULL);
520 static void wlan_led_set(struct led_classdev *led_cdev,
521 enum led_brightness value)
523 struct asus_wmi *asus;
525 asus = container_of(led_cdev, struct asus_wmi, wlan_led);
527 asus->wlan_led_wk = !!value;
528 queue_work(asus->led_workqueue, &asus->wlan_led_work);
531 static enum led_brightness wlan_led_get(struct led_classdev *led_cdev)
533 struct asus_wmi *asus;
536 asus = container_of(led_cdev, struct asus_wmi, wlan_led);
537 asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WIRELESS_LED, &result);
539 return result & ASUS_WMI_DSTS_BRIGHTNESS_MASK;
542 static void lightbar_led_update(struct work_struct *work)
544 struct asus_wmi *asus;
547 asus = container_of(work, struct asus_wmi, lightbar_led_work);
549 ctrl_param = asus->lightbar_led_wk;
550 asus_wmi_set_devstate(ASUS_WMI_DEVID_LIGHTBAR, ctrl_param, NULL);
553 static void lightbar_led_set(struct led_classdev *led_cdev,
554 enum led_brightness value)
556 struct asus_wmi *asus;
558 asus = container_of(led_cdev, struct asus_wmi, lightbar_led);
560 asus->lightbar_led_wk = !!value;
561 queue_work(asus->led_workqueue, &asus->lightbar_led_work);
564 static enum led_brightness lightbar_led_get(struct led_classdev *led_cdev)
566 struct asus_wmi *asus;
569 asus = container_of(led_cdev, struct asus_wmi, lightbar_led);
570 asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_LIGHTBAR, &result);
572 return result & ASUS_WMI_DSTS_LIGHTBAR_MASK;
575 static int lightbar_led_presence(struct asus_wmi *asus)
579 asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_LIGHTBAR, &result);
581 return result & ASUS_WMI_DSTS_PRESENCE_BIT;
584 static void asus_wmi_led_exit(struct asus_wmi *asus)
586 if (!IS_ERR_OR_NULL(asus->kbd_led.dev))
587 led_classdev_unregister(&asus->kbd_led);
588 if (!IS_ERR_OR_NULL(asus->tpd_led.dev))
589 led_classdev_unregister(&asus->tpd_led);
590 if (!IS_ERR_OR_NULL(asus->wlan_led.dev))
591 led_classdev_unregister(&asus->wlan_led);
592 if (!IS_ERR_OR_NULL(asus->lightbar_led.dev))
593 led_classdev_unregister(&asus->lightbar_led);
594 if (asus->led_workqueue)
595 destroy_workqueue(asus->led_workqueue);
598 static int asus_wmi_led_init(struct asus_wmi *asus)
602 asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
603 if (!asus->led_workqueue)
606 if (read_tpd_led_state(asus) >= 0) {
607 INIT_WORK(&asus->tpd_led_work, tpd_led_update);
609 asus->tpd_led.name = "asus::touchpad";
610 asus->tpd_led.brightness_set = tpd_led_set;
611 asus->tpd_led.brightness_get = tpd_led_get;
612 asus->tpd_led.max_brightness = 1;
614 rv = led_classdev_register(&asus->platform_device->dev,
620 if (!kbd_led_read(asus, &led_val, NULL)) {
621 asus->kbd_led_wk = led_val;
622 asus->kbd_led.name = "asus::kbd_backlight";
623 asus->kbd_led.flags = LED_BRIGHT_HW_CHANGED;
624 asus->kbd_led.brightness_set = kbd_led_set;
625 asus->kbd_led.brightness_get = kbd_led_get;
626 asus->kbd_led.max_brightness = 3;
628 rv = led_classdev_register(&asus->platform_device->dev,
634 if (wlan_led_presence(asus) && (asus->driver->quirks->wapf > 0)) {
635 INIT_WORK(&asus->wlan_led_work, wlan_led_update);
637 asus->wlan_led.name = "asus::wlan";
638 asus->wlan_led.brightness_set = wlan_led_set;
639 if (!wlan_led_unknown_state(asus))
640 asus->wlan_led.brightness_get = wlan_led_get;
641 asus->wlan_led.flags = LED_CORE_SUSPENDRESUME;
642 asus->wlan_led.max_brightness = 1;
643 asus->wlan_led.default_trigger = "asus-wlan";
645 rv = led_classdev_register(&asus->platform_device->dev,
651 if (lightbar_led_presence(asus)) {
652 INIT_WORK(&asus->lightbar_led_work, lightbar_led_update);
654 asus->lightbar_led.name = "asus::lightbar";
655 asus->lightbar_led.brightness_set = lightbar_led_set;
656 asus->lightbar_led.brightness_get = lightbar_led_get;
657 asus->lightbar_led.max_brightness = 1;
659 rv = led_classdev_register(&asus->platform_device->dev,
660 &asus->lightbar_led);
665 asus_wmi_led_exit(asus);
670 /* RF *************************************************************************/
673 * PCI hotplug (for wlan rfkill)
675 static bool asus_wlan_rfkill_blocked(struct asus_wmi *asus)
677 int result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WLAN);
684 static void asus_rfkill_hotplug(struct asus_wmi *asus)
692 mutex_lock(&asus->wmi_lock);
693 blocked = asus_wlan_rfkill_blocked(asus);
694 mutex_unlock(&asus->wmi_lock);
696 mutex_lock(&asus->hotplug_lock);
697 pci_lock_rescan_remove();
699 if (asus->wlan.rfkill)
700 rfkill_set_sw_state(asus->wlan.rfkill, blocked);
702 if (asus->hotplug_slot.ops) {
703 bus = pci_find_bus(0, 1);
705 pr_warn("Unable to find PCI bus 1?\n");
709 if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) {
710 pr_err("Unable to read PCI config space?\n");
713 absent = (l == 0xffffffff);
715 if (blocked != absent) {
716 pr_warn("BIOS says wireless lan is %s, "
717 "but the pci device is %s\n",
718 blocked ? "blocked" : "unblocked",
719 absent ? "absent" : "present");
720 pr_warn("skipped wireless hotplug as probably "
721 "inappropriate for this model\n");
726 dev = pci_get_slot(bus, 0);
728 /* Device already present */
732 dev = pci_scan_single_device(bus, 0);
734 pci_bus_assign_resources(bus);
735 pci_bus_add_device(dev);
738 dev = pci_get_slot(bus, 0);
740 pci_stop_and_remove_bus_device(dev);
747 pci_unlock_rescan_remove();
748 mutex_unlock(&asus->hotplug_lock);
751 static void asus_rfkill_notify(acpi_handle handle, u32 event, void *data)
753 struct asus_wmi *asus = data;
755 if (event != ACPI_NOTIFY_BUS_CHECK)
759 * We can't call directly asus_rfkill_hotplug because most
760 * of the time WMBC is still being executed and not reetrant.
761 * There is currently no way to tell ACPICA that we want this
762 * method to be serialized, we schedule a asus_rfkill_hotplug
763 * call later, in a safer context.
765 queue_work(asus->hotplug_workqueue, &asus->hotplug_work);
768 static int asus_register_rfkill_notifier(struct asus_wmi *asus, char *node)
773 status = acpi_get_handle(NULL, node, &handle);
775 if (ACPI_SUCCESS(status)) {
776 status = acpi_install_notify_handler(handle,
778 asus_rfkill_notify, asus);
779 if (ACPI_FAILURE(status))
780 pr_warn("Failed to register notify on %s\n", node);
787 static void asus_unregister_rfkill_notifier(struct asus_wmi *asus, char *node)
789 acpi_status status = AE_OK;
792 status = acpi_get_handle(NULL, node, &handle);
794 if (ACPI_SUCCESS(status)) {
795 status = acpi_remove_notify_handler(handle,
798 if (ACPI_FAILURE(status))
799 pr_err("Error removing rfkill notify handler %s\n",
804 static int asus_get_adapter_status(struct hotplug_slot *hotplug_slot,
807 struct asus_wmi *asus = container_of(hotplug_slot,
808 struct asus_wmi, hotplug_slot);
809 int result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WLAN);
818 static const struct hotplug_slot_ops asus_hotplug_slot_ops = {
819 .get_adapter_status = asus_get_adapter_status,
820 .get_power_status = asus_get_adapter_status,
823 static void asus_hotplug_work(struct work_struct *work)
825 struct asus_wmi *asus;
827 asus = container_of(work, struct asus_wmi, hotplug_work);
828 asus_rfkill_hotplug(asus);
831 static int asus_setup_pci_hotplug(struct asus_wmi *asus)
834 struct pci_bus *bus = pci_find_bus(0, 1);
837 pr_err("Unable to find wifi PCI bus\n");
841 asus->hotplug_workqueue =
842 create_singlethread_workqueue("hotplug_workqueue");
843 if (!asus->hotplug_workqueue)
844 goto error_workqueue;
846 INIT_WORK(&asus->hotplug_work, asus_hotplug_work);
848 asus->hotplug_slot.ops = &asus_hotplug_slot_ops;
850 ret = pci_hp_register(&asus->hotplug_slot, bus, 0, "asus-wifi");
852 pr_err("Unable to register hotplug slot - %d\n", ret);
859 asus->hotplug_slot.ops = NULL;
860 destroy_workqueue(asus->hotplug_workqueue);
868 static int asus_rfkill_set(void *data, bool blocked)
870 struct asus_rfkill *priv = data;
871 u32 ctrl_param = !blocked;
872 u32 dev_id = priv->dev_id;
875 * If the user bit is set, BIOS can't set and record the wlan status,
876 * it will report the value read from id ASUS_WMI_DEVID_WLAN_LED
877 * while we query the wlan status through WMI(ASUS_WMI_DEVID_WLAN).
878 * So, we have to record wlan status in id ASUS_WMI_DEVID_WLAN_LED
879 * while setting the wlan status through WMI.
880 * This is also the behavior that windows app will do.
882 if ((dev_id == ASUS_WMI_DEVID_WLAN) &&
883 priv->asus->driver->wlan_ctrl_by_user)
884 dev_id = ASUS_WMI_DEVID_WLAN_LED;
886 return asus_wmi_set_devstate(dev_id, ctrl_param, NULL);
889 static void asus_rfkill_query(struct rfkill *rfkill, void *data)
891 struct asus_rfkill *priv = data;
894 result = asus_wmi_get_devstate_simple(priv->asus, priv->dev_id);
899 rfkill_set_sw_state(priv->rfkill, !result);
902 static int asus_rfkill_wlan_set(void *data, bool blocked)
904 struct asus_rfkill *priv = data;
905 struct asus_wmi *asus = priv->asus;
909 * This handler is enabled only if hotplug is enabled.
910 * In this case, the asus_wmi_set_devstate() will
911 * trigger a wmi notification and we need to wait
912 * this call to finish before being able to call
915 mutex_lock(&asus->wmi_lock);
916 ret = asus_rfkill_set(data, blocked);
917 mutex_unlock(&asus->wmi_lock);
921 static const struct rfkill_ops asus_rfkill_wlan_ops = {
922 .set_block = asus_rfkill_wlan_set,
923 .query = asus_rfkill_query,
926 static const struct rfkill_ops asus_rfkill_ops = {
927 .set_block = asus_rfkill_set,
928 .query = asus_rfkill_query,
931 static int asus_new_rfkill(struct asus_wmi *asus,
932 struct asus_rfkill *arfkill,
933 const char *name, enum rfkill_type type, int dev_id)
935 int result = asus_wmi_get_devstate_simple(asus, dev_id);
936 struct rfkill **rfkill = &arfkill->rfkill;
941 arfkill->dev_id = dev_id;
942 arfkill->asus = asus;
944 if (dev_id == ASUS_WMI_DEVID_WLAN &&
945 asus->driver->quirks->hotplug_wireless)
946 *rfkill = rfkill_alloc(name, &asus->platform_device->dev, type,
947 &asus_rfkill_wlan_ops, arfkill);
949 *rfkill = rfkill_alloc(name, &asus->platform_device->dev, type,
950 &asus_rfkill_ops, arfkill);
955 if ((dev_id == ASUS_WMI_DEVID_WLAN) &&
956 (asus->driver->quirks->wapf > 0))
957 rfkill_set_led_trigger_name(*rfkill, "asus-wlan");
959 rfkill_init_sw_state(*rfkill, !result);
960 result = rfkill_register(*rfkill);
962 rfkill_destroy(*rfkill);
969 static void asus_wmi_rfkill_exit(struct asus_wmi *asus)
971 if (asus->driver->wlan_ctrl_by_user && ashs_present())
974 asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P5");
975 asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P6");
976 asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P7");
977 if (asus->wlan.rfkill) {
978 rfkill_unregister(asus->wlan.rfkill);
979 rfkill_destroy(asus->wlan.rfkill);
980 asus->wlan.rfkill = NULL;
983 * Refresh pci hotplug in case the rfkill state was changed after
984 * asus_unregister_rfkill_notifier()
986 asus_rfkill_hotplug(asus);
987 if (asus->hotplug_slot.ops)
988 pci_hp_deregister(&asus->hotplug_slot);
989 if (asus->hotplug_workqueue)
990 destroy_workqueue(asus->hotplug_workqueue);
992 if (asus->bluetooth.rfkill) {
993 rfkill_unregister(asus->bluetooth.rfkill);
994 rfkill_destroy(asus->bluetooth.rfkill);
995 asus->bluetooth.rfkill = NULL;
997 if (asus->wimax.rfkill) {
998 rfkill_unregister(asus->wimax.rfkill);
999 rfkill_destroy(asus->wimax.rfkill);
1000 asus->wimax.rfkill = NULL;
1002 if (asus->wwan3g.rfkill) {
1003 rfkill_unregister(asus->wwan3g.rfkill);
1004 rfkill_destroy(asus->wwan3g.rfkill);
1005 asus->wwan3g.rfkill = NULL;
1007 if (asus->gps.rfkill) {
1008 rfkill_unregister(asus->gps.rfkill);
1009 rfkill_destroy(asus->gps.rfkill);
1010 asus->gps.rfkill = NULL;
1012 if (asus->uwb.rfkill) {
1013 rfkill_unregister(asus->uwb.rfkill);
1014 rfkill_destroy(asus->uwb.rfkill);
1015 asus->uwb.rfkill = NULL;
1019 static int asus_wmi_rfkill_init(struct asus_wmi *asus)
1023 mutex_init(&asus->hotplug_lock);
1024 mutex_init(&asus->wmi_lock);
1026 result = asus_new_rfkill(asus, &asus->wlan, "asus-wlan",
1027 RFKILL_TYPE_WLAN, ASUS_WMI_DEVID_WLAN);
1029 if (result && result != -ENODEV)
1032 result = asus_new_rfkill(asus, &asus->bluetooth,
1033 "asus-bluetooth", RFKILL_TYPE_BLUETOOTH,
1034 ASUS_WMI_DEVID_BLUETOOTH);
1036 if (result && result != -ENODEV)
1039 result = asus_new_rfkill(asus, &asus->wimax, "asus-wimax",
1040 RFKILL_TYPE_WIMAX, ASUS_WMI_DEVID_WIMAX);
1042 if (result && result != -ENODEV)
1045 result = asus_new_rfkill(asus, &asus->wwan3g, "asus-wwan3g",
1046 RFKILL_TYPE_WWAN, ASUS_WMI_DEVID_WWAN3G);
1048 if (result && result != -ENODEV)
1051 result = asus_new_rfkill(asus, &asus->gps, "asus-gps",
1052 RFKILL_TYPE_GPS, ASUS_WMI_DEVID_GPS);
1054 if (result && result != -ENODEV)
1057 result = asus_new_rfkill(asus, &asus->uwb, "asus-uwb",
1058 RFKILL_TYPE_UWB, ASUS_WMI_DEVID_UWB);
1060 if (result && result != -ENODEV)
1063 if (!asus->driver->quirks->hotplug_wireless)
1066 result = asus_setup_pci_hotplug(asus);
1068 * If we get -EBUSY then something else is handling the PCI hotplug -
1069 * don't fail in this case
1071 if (result == -EBUSY)
1074 asus_register_rfkill_notifier(asus, "\\_SB.PCI0.P0P5");
1075 asus_register_rfkill_notifier(asus, "\\_SB.PCI0.P0P6");
1076 asus_register_rfkill_notifier(asus, "\\_SB.PCI0.P0P7");
1078 * Refresh pci hotplug in case the rfkill state was changed during
1081 asus_rfkill_hotplug(asus);
1084 if (result && result != -ENODEV)
1085 asus_wmi_rfkill_exit(asus);
1087 if (result == -ENODEV)
1093 /* Quirks *********************************************************************/
1095 static void asus_wmi_set_xusb2pr(struct asus_wmi *asus)
1097 struct pci_dev *xhci_pdev;
1098 u32 orig_ports_available;
1099 u32 ports_available = asus->driver->quirks->xusb2pr;
1101 xhci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
1102 PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI,
1108 pci_read_config_dword(xhci_pdev, USB_INTEL_XUSB2PR,
1109 &orig_ports_available);
1111 pci_write_config_dword(xhci_pdev, USB_INTEL_XUSB2PR,
1112 cpu_to_le32(ports_available));
1114 pr_info("set USB_INTEL_XUSB2PR old: 0x%04x, new: 0x%04x\n",
1115 orig_ports_available, ports_available);
1119 * Some devices dont support or have borcken get_als method
1120 * but still support set method.
1122 static void asus_wmi_set_als(void)
1124 asus_wmi_set_devstate(ASUS_WMI_DEVID_ALS_ENABLE, 1, NULL);
1127 /* Hwmon device ***************************************************************/
1129 static int asus_hwmon_agfn_fan_speed_read(struct asus_wmi *asus, int fan,
1132 struct fan_args args = {
1133 .agfn.len = sizeof(args),
1134 .agfn.mfun = ASUS_FAN_MFUN,
1135 .agfn.sfun = ASUS_FAN_SFUN_READ,
1139 struct acpi_buffer input = { (acpi_size) sizeof(args), &args };
1145 status = asus_wmi_evaluate_method_agfn(input);
1147 if (status || args.agfn.err)
1151 *speed = args.speed;
1156 static int asus_hwmon_agfn_fan_speed_write(struct asus_wmi *asus, int fan,
1159 struct fan_args args = {
1160 .agfn.len = sizeof(args),
1161 .agfn.mfun = ASUS_FAN_MFUN,
1162 .agfn.sfun = ASUS_FAN_SFUN_WRITE,
1164 .speed = speed ? *speed : 0,
1166 struct acpi_buffer input = { (acpi_size) sizeof(args), &args };
1169 /* 1: for setting 1st fan's speed 0: setting auto mode */
1170 if (fan != 1 && fan != 0)
1173 status = asus_wmi_evaluate_method_agfn(input);
1175 if (status || args.agfn.err)
1178 if (speed && fan == 1)
1179 asus->asus_hwmon_pwm = *speed;
1185 * Check if we can read the speed of one fan. If true we assume we can also
1188 static int asus_hwmon_get_fan_number(struct asus_wmi *asus, int *num_fans)
1195 status = asus_hwmon_agfn_fan_speed_read(asus, 1, &speed);
1202 static int asus_hwmon_fan_set_auto(struct asus_wmi *asus)
1206 status = asus_hwmon_agfn_fan_speed_write(asus, 0, NULL);
1210 asus->asus_hwmon_fan_manual_mode = false;
1215 static int asus_hwmon_fan_rpm_show(struct device *dev, int fan)
1217 struct asus_wmi *asus = dev_get_drvdata(dev);
1221 /* no speed readable on manual mode */
1222 if (asus->asus_hwmon_fan_manual_mode)
1225 ret = asus_hwmon_agfn_fan_speed_read(asus, fan+1, &value);
1227 pr_warn("reading fan speed failed: %d\n", ret);
1234 static void asus_hwmon_pwm_show(struct asus_wmi *asus, int fan, int *value)
1238 if (asus->asus_hwmon_pwm >= 0) {
1239 *value = asus->asus_hwmon_pwm;
1243 err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FAN_CTRL, value);
1249 if (*value == 1) /* Low Speed */
1251 else if (*value == 2)
1253 else if (*value == 3)
1256 pr_err("Unknown fan speed %#x\n", *value);
1261 static ssize_t pwm1_show(struct device *dev,
1262 struct device_attribute *attr,
1265 struct asus_wmi *asus = dev_get_drvdata(dev);
1268 asus_hwmon_pwm_show(asus, 0, &value);
1270 return sprintf(buf, "%d\n", value);
1273 static ssize_t pwm1_store(struct device *dev,
1274 struct device_attribute *attr,
1275 const char *buf, size_t count) {
1276 struct asus_wmi *asus = dev_get_drvdata(dev);
1281 ret = kstrtouint(buf, 10, &value);
1286 value = clamp(value, 0, 255);
1288 state = asus_hwmon_agfn_fan_speed_write(asus, 1, &value);
1290 pr_warn("Setting fan speed failed: %d\n", state);
1292 asus->asus_hwmon_fan_manual_mode = true;
1297 static ssize_t fan1_input_show(struct device *dev,
1298 struct device_attribute *attr,
1301 int value = asus_hwmon_fan_rpm_show(dev, 0);
1303 return sprintf(buf, "%d\n", value < 0 ? -1 : value*100);
1307 static ssize_t pwm1_enable_show(struct device *dev,
1308 struct device_attribute *attr,
1311 struct asus_wmi *asus = dev_get_drvdata(dev);
1313 if (asus->asus_hwmon_fan_manual_mode)
1314 return sprintf(buf, "%d\n", ASUS_FAN_CTRL_MANUAL);
1316 return sprintf(buf, "%d\n", ASUS_FAN_CTRL_AUTO);
1319 static ssize_t pwm1_enable_store(struct device *dev,
1320 struct device_attribute *attr,
1321 const char *buf, size_t count)
1323 struct asus_wmi *asus = dev_get_drvdata(dev);
1328 ret = kstrtouint(buf, 10, &state);
1333 if (state == ASUS_FAN_CTRL_MANUAL)
1334 asus->asus_hwmon_fan_manual_mode = true;
1336 status = asus_hwmon_fan_set_auto(asus);
1344 static ssize_t fan1_label_show(struct device *dev,
1345 struct device_attribute *attr,
1348 return sprintf(buf, "%s\n", ASUS_FAN_DESC);
1351 static ssize_t asus_hwmon_temp1(struct device *dev,
1352 struct device_attribute *attr,
1355 struct asus_wmi *asus = dev_get_drvdata(dev);
1359 err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_THERMAL_CTRL, &value);
1364 value = DECI_KELVIN_TO_CELSIUS((value & 0xFFFF)) * 1000;
1366 return sprintf(buf, "%d\n", value);
1370 static DEVICE_ATTR_RW(pwm1);
1371 static DEVICE_ATTR_RW(pwm1_enable);
1372 static DEVICE_ATTR_RO(fan1_input);
1373 static DEVICE_ATTR_RO(fan1_label);
1376 static DEVICE_ATTR(temp1_input, S_IRUGO, asus_hwmon_temp1, NULL);
1378 static struct attribute *hwmon_attributes[] = {
1379 &dev_attr_pwm1.attr,
1380 &dev_attr_pwm1_enable.attr,
1381 &dev_attr_fan1_input.attr,
1382 &dev_attr_fan1_label.attr,
1384 &dev_attr_temp1_input.attr,
1388 static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj,
1389 struct attribute *attr, int idx)
1391 struct device *dev = container_of(kobj, struct device, kobj);
1392 struct asus_wmi *asus = dev_get_drvdata(dev->parent);
1395 u32 value = ASUS_WMI_UNSUPPORTED_METHOD;
1398 if (attr == &dev_attr_pwm1.attr)
1399 dev_id = ASUS_WMI_DEVID_FAN_CTRL;
1400 else if (attr == &dev_attr_temp1_input.attr)
1401 dev_id = ASUS_WMI_DEVID_THERMAL_CTRL;
1404 if (attr == &dev_attr_fan1_input.attr
1405 || attr == &dev_attr_fan1_label.attr
1406 || attr == &dev_attr_pwm1.attr
1407 || attr == &dev_attr_pwm1_enable.attr) {
1412 int err = asus_wmi_get_devstate(asus, dev_id, &value);
1414 if (err < 0 && fan_attr == -1)
1415 return 0; /* can't return negative here */
1418 if (dev_id == ASUS_WMI_DEVID_FAN_CTRL) {
1420 * We need to find a better way, probably using sfun,
1422 * Currently we disable it if:
1423 * - ASUS_WMI_UNSUPPORTED_METHOD is returned
1424 * - reverved bits are non-zero
1425 * - sfun and presence bit are not set
1427 if (value == ASUS_WMI_UNSUPPORTED_METHOD || value & 0xFFF80000
1428 || (!asus->sfun && !(value & ASUS_WMI_DSTS_PRESENCE_BIT)))
1431 ok = fan_attr <= asus->asus_hwmon_num_fans;
1432 } else if (dev_id == ASUS_WMI_DEVID_THERMAL_CTRL) {
1434 * If the temperature value in deci-Kelvin is near the absolute
1435 * zero temperature, something is clearly wrong
1437 if (value == 0 || value == 1)
1439 } else if (fan_attr <= asus->asus_hwmon_num_fans && fan_attr != -1) {
1445 return ok ? attr->mode : 0;
1448 static const struct attribute_group hwmon_attribute_group = {
1449 .is_visible = asus_hwmon_sysfs_is_visible,
1450 .attrs = hwmon_attributes
1452 __ATTRIBUTE_GROUPS(hwmon_attribute);
1454 static int asus_wmi_hwmon_init(struct asus_wmi *asus)
1456 struct device *dev = &asus->platform_device->dev;
1457 struct device *hwmon;
1459 hwmon = devm_hwmon_device_register_with_groups(dev, "asus", asus,
1460 hwmon_attribute_groups);
1462 if (IS_ERR(hwmon)) {
1463 pr_err("Could not register asus hwmon device\n");
1464 return PTR_ERR(hwmon);
1469 static int asus_wmi_fan_init(struct asus_wmi *asus)
1473 asus->asus_hwmon_pwm = -1;
1474 asus->asus_hwmon_num_fans = -1;
1475 asus->asus_hwmon_fan_manual_mode = false;
1477 status = asus_hwmon_get_fan_number(asus, &asus->asus_hwmon_num_fans);
1479 asus->asus_hwmon_num_fans = 0;
1480 pr_warn("Could not determine number of fans: %d\n", status);
1484 pr_info("Number of fans: %d\n", asus->asus_hwmon_num_fans);
1488 /* Fan mode *******************************************************************/
1490 static int fan_mode_check_present(struct asus_wmi *asus)
1495 asus->fan_mode_available = false;
1497 err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FAN_MODE, &result);
1505 if ((result & ASUS_WMI_DSTS_PRESENCE_BIT) &&
1506 (result & ASUS_FAN_MODES_MASK)) {
1507 asus->fan_mode_available = true;
1508 asus->fan_mode_mask = result & ASUS_FAN_MODES_MASK;
1514 static int fan_mode_write(struct asus_wmi *asus)
1520 value = asus->fan_mode;
1522 pr_info("Set fan mode: %u\n", value);
1523 err = asus_wmi_set_devstate(ASUS_WMI_DEVID_FAN_MODE, value, &retval);
1526 pr_warn("Failed to set fan mode: %d\n", err);
1531 pr_warn("Failed to set fan mode (retval): 0x%x\n", retval);
1538 static int fan_mode_switch_next(struct asus_wmi *asus)
1540 if (asus->fan_mode == ASUS_FAN_MODE_NORMAL) {
1541 if (asus->fan_mode_mask & ASUS_FAN_MODE_OVERBOOST_MASK)
1542 asus->fan_mode = ASUS_FAN_MODE_OVERBOOST;
1543 else if (asus->fan_mode_mask & ASUS_FAN_MODE_SILENT_MASK)
1544 asus->fan_mode = ASUS_FAN_MODE_SILENT;
1545 } else if (asus->fan_mode == ASUS_FAN_MODE_OVERBOOST) {
1546 if (asus->fan_mode_mask & ASUS_FAN_MODE_SILENT_MASK)
1547 asus->fan_mode = ASUS_FAN_MODE_SILENT;
1549 asus->fan_mode = ASUS_FAN_MODE_NORMAL;
1551 asus->fan_mode = ASUS_FAN_MODE_NORMAL;
1554 return fan_mode_write(asus);
1557 static ssize_t fan_mode_show(struct device *dev,
1558 struct device_attribute *attr, char *buf)
1560 struct asus_wmi *asus = dev_get_drvdata(dev);
1562 return scnprintf(buf, PAGE_SIZE, "%d\n", asus->fan_mode);
1565 static ssize_t fan_mode_store(struct device *dev, struct device_attribute *attr,
1566 const char *buf, size_t count)
1571 struct asus_wmi *asus = dev_get_drvdata(dev);
1573 result = kstrtou8(buf, 10, &new_mode);
1575 pr_warn("Trying to store invalid value\n");
1579 if (new_mode == ASUS_FAN_MODE_OVERBOOST) {
1580 if (!(asus->fan_mode_mask & ASUS_FAN_MODE_OVERBOOST_MASK))
1582 } else if (new_mode == ASUS_FAN_MODE_SILENT) {
1583 if (!(asus->fan_mode_mask & ASUS_FAN_MODE_SILENT_MASK))
1585 } else if (new_mode != ASUS_FAN_MODE_NORMAL) {
1589 asus->fan_mode = new_mode;
1590 fan_mode_write(asus);
1595 // Fan mode: 0 - normal, 1 - overboost, 2 - silent
1596 static DEVICE_ATTR_RW(fan_mode);
1598 /* Backlight ******************************************************************/
1600 static int read_backlight_power(struct asus_wmi *asus)
1603 if (asus->driver->quirks->store_backlight_power)
1604 ret = !asus->driver->panel_power;
1606 ret = asus_wmi_get_devstate_simple(asus,
1607 ASUS_WMI_DEVID_BACKLIGHT);
1612 return ret ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
1615 static int read_brightness_max(struct asus_wmi *asus)
1620 err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_BRIGHTNESS, &retval);
1625 retval = retval & ASUS_WMI_DSTS_MAX_BRIGTH_MASK;
1634 static int read_brightness(struct backlight_device *bd)
1636 struct asus_wmi *asus = bl_get_data(bd);
1640 err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_BRIGHTNESS, &retval);
1645 return retval & ASUS_WMI_DSTS_BRIGHTNESS_MASK;
1648 static u32 get_scalar_command(struct backlight_device *bd)
1650 struct asus_wmi *asus = bl_get_data(bd);
1653 if ((asus->driver->brightness < bd->props.brightness) ||
1654 bd->props.brightness == bd->props.max_brightness)
1655 ctrl_param = 0x00008001;
1656 else if ((asus->driver->brightness > bd->props.brightness) ||
1657 bd->props.brightness == 0)
1658 ctrl_param = 0x00008000;
1660 asus->driver->brightness = bd->props.brightness;
1665 static int update_bl_status(struct backlight_device *bd)
1667 struct asus_wmi *asus = bl_get_data(bd);
1671 power = read_backlight_power(asus);
1672 if (power != -ENODEV && bd->props.power != power) {
1673 ctrl_param = !!(bd->props.power == FB_BLANK_UNBLANK);
1674 err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BACKLIGHT,
1676 if (asus->driver->quirks->store_backlight_power)
1677 asus->driver->panel_power = bd->props.power;
1679 /* When using scalar brightness, updating the brightness
1680 * will mess with the backlight power */
1681 if (asus->driver->quirks->scalar_panel_brightness)
1685 if (asus->driver->quirks->scalar_panel_brightness)
1686 ctrl_param = get_scalar_command(bd);
1688 ctrl_param = bd->props.brightness;
1690 err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BRIGHTNESS,
1696 static const struct backlight_ops asus_wmi_bl_ops = {
1697 .get_brightness = read_brightness,
1698 .update_status = update_bl_status,
1701 static int asus_wmi_backlight_notify(struct asus_wmi *asus, int code)
1703 struct backlight_device *bd = asus->backlight_device;
1704 int old = bd->props.brightness;
1707 if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
1708 new = code - NOTIFY_BRNUP_MIN + 1;
1709 else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX)
1710 new = code - NOTIFY_BRNDOWN_MIN;
1712 bd->props.brightness = new;
1713 backlight_update_status(bd);
1714 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
1719 static int asus_wmi_backlight_init(struct asus_wmi *asus)
1721 struct backlight_device *bd;
1722 struct backlight_properties props;
1726 max = read_brightness_max(asus);
1730 power = read_backlight_power(asus);
1732 if (power == -ENODEV)
1733 power = FB_BLANK_UNBLANK;
1737 memset(&props, 0, sizeof(struct backlight_properties));
1738 props.type = BACKLIGHT_PLATFORM;
1739 props.max_brightness = max;
1740 bd = backlight_device_register(asus->driver->name,
1741 &asus->platform_device->dev, asus,
1742 &asus_wmi_bl_ops, &props);
1744 pr_err("Could not register backlight device\n");
1748 asus->backlight_device = bd;
1750 if (asus->driver->quirks->store_backlight_power)
1751 asus->driver->panel_power = power;
1753 bd->props.brightness = read_brightness(bd);
1754 bd->props.power = power;
1755 backlight_update_status(bd);
1757 asus->driver->brightness = bd->props.brightness;
1762 static void asus_wmi_backlight_exit(struct asus_wmi *asus)
1764 backlight_device_unregister(asus->backlight_device);
1766 asus->backlight_device = NULL;
1769 static int is_display_toggle(int code)
1771 /* display toggle keys */
1772 if ((code >= 0x61 && code <= 0x67) ||
1773 (code >= 0x8c && code <= 0x93) ||
1774 (code >= 0xa0 && code <= 0xa7) ||
1775 (code >= 0xd0 && code <= 0xd5))
1781 /* Fn-lock ********************************************************************/
1783 static bool asus_wmi_has_fnlock_key(struct asus_wmi *asus)
1787 asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FNLOCK, &result);
1789 return (result & ASUS_WMI_DSTS_PRESENCE_BIT) &&
1790 !(result & ASUS_WMI_FNLOCK_BIOS_DISABLED);
1793 static void asus_wmi_fnlock_update(struct asus_wmi *asus)
1795 int mode = asus->fnlock_locked;
1797 asus_wmi_set_devstate(ASUS_WMI_DEVID_FNLOCK, mode, NULL);
1800 /* WMI events *****************************************************************/
1802 static int asus_wmi_get_event_code(u32 value)
1804 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1805 union acpi_object *obj;
1809 status = wmi_get_event_data(value, &response);
1810 if (ACPI_FAILURE(status)) {
1811 pr_warn("Failed to get WMI notify code: %s\n",
1812 acpi_format_exception(status));
1816 obj = (union acpi_object *)response.pointer;
1818 if (obj && obj->type == ACPI_TYPE_INTEGER)
1819 code = (int)(obj->integer.value & WMI_EVENT_MASK);
1827 static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
1830 unsigned int key_value = 1;
1831 bool autorelease = 1;
1835 if (asus->driver->key_filter) {
1836 asus->driver->key_filter(asus->driver, &code, &key_value,
1838 if (code == ASUS_WMI_KEY_IGNORE)
1842 if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
1843 code = ASUS_WMI_BRN_UP;
1844 else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX)
1845 code = ASUS_WMI_BRN_DOWN;
1847 if (code == ASUS_WMI_BRN_DOWN || code == ASUS_WMI_BRN_UP) {
1848 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
1849 asus_wmi_backlight_notify(asus, orig_code);
1854 if (code == NOTIFY_KBD_BRTUP) {
1855 kbd_led_set_by_kbd(asus, asus->kbd_led_wk + 1);
1858 if (code == NOTIFY_KBD_BRTDWN) {
1859 kbd_led_set_by_kbd(asus, asus->kbd_led_wk - 1);
1862 if (code == NOTIFY_KBD_BRTTOGGLE) {
1863 if (asus->kbd_led_wk == asus->kbd_led.max_brightness)
1864 kbd_led_set_by_kbd(asus, 0);
1866 kbd_led_set_by_kbd(asus, asus->kbd_led_wk + 1);
1870 if (code == NOTIFY_FNLOCK_TOGGLE) {
1871 asus->fnlock_locked = !asus->fnlock_locked;
1872 asus_wmi_fnlock_update(asus);
1876 if (asus->fan_mode_available && code == NOTIFY_KBD_FBM) {
1877 fan_mode_switch_next(asus);
1881 if (is_display_toggle(code) && asus->driver->quirks->no_display_toggle)
1884 if (!sparse_keymap_report_event(asus->inputdev, code,
1885 key_value, autorelease))
1886 pr_info("Unknown key %x pressed\n", code);
1889 static void asus_wmi_notify(u32 value, void *context)
1891 struct asus_wmi *asus = context;
1895 for (i = 0; i < WMI_EVENT_QUEUE_SIZE + 1; i++) {
1896 code = asus_wmi_get_event_code(value);
1899 pr_warn("Failed to get notify code: %d\n", code);
1903 if (code == WMI_EVENT_QUEUE_END || code == WMI_EVENT_MASK)
1906 asus_wmi_handle_event_code(code, asus);
1909 * Double check that queue is present:
1910 * ATK (with queue) uses 0xff, ASUSWMI (without) 0xd2.
1912 if (!asus->wmi_event_queue || value != WMI_EVENT_VALUE_ATK)
1916 pr_warn("Failed to process event queue, last code: 0x%x\n", code);
1919 static int asus_wmi_notify_queue_flush(struct asus_wmi *asus)
1924 for (i = 0; i < WMI_EVENT_QUEUE_SIZE + 1; i++) {
1925 code = asus_wmi_get_event_code(WMI_EVENT_VALUE_ATK);
1928 pr_warn("Failed to get event during flush: %d\n", code);
1932 if (code == WMI_EVENT_QUEUE_END || code == WMI_EVENT_MASK)
1936 pr_warn("Failed to flush event queue\n");
1940 /* Sysfs **********************************************************************/
1942 static int parse_arg(const char *buf, unsigned long count, int *val)
1946 if (sscanf(buf, "%i", val) != 1)
1951 static ssize_t store_sys_wmi(struct asus_wmi *asus, int devid,
1952 const char *buf, size_t count)
1957 value = asus_wmi_get_devstate_simple(asus, devid);
1961 rv = parse_arg(buf, count, &value);
1962 err = asus_wmi_set_devstate(devid, value, &retval);
1970 static ssize_t show_sys_wmi(struct asus_wmi *asus, int devid, char *buf)
1972 int value = asus_wmi_get_devstate_simple(asus, devid);
1977 return sprintf(buf, "%d\n", value);
1980 #define ASUS_WMI_CREATE_DEVICE_ATTR(_name, _mode, _cm) \
1981 static ssize_t show_##_name(struct device *dev, \
1982 struct device_attribute *attr, \
1985 struct asus_wmi *asus = dev_get_drvdata(dev); \
1987 return show_sys_wmi(asus, _cm, buf); \
1989 static ssize_t store_##_name(struct device *dev, \
1990 struct device_attribute *attr, \
1991 const char *buf, size_t count) \
1993 struct asus_wmi *asus = dev_get_drvdata(dev); \
1995 return store_sys_wmi(asus, _cm, buf, count); \
1997 static struct device_attribute dev_attr_##_name = { \
1999 .name = __stringify(_name), \
2001 .show = show_##_name, \
2002 .store = store_##_name, \
2005 ASUS_WMI_CREATE_DEVICE_ATTR(touchpad, 0644, ASUS_WMI_DEVID_TOUCHPAD);
2006 ASUS_WMI_CREATE_DEVICE_ATTR(camera, 0644, ASUS_WMI_DEVID_CAMERA);
2007 ASUS_WMI_CREATE_DEVICE_ATTR(cardr, 0644, ASUS_WMI_DEVID_CARDREADER);
2008 ASUS_WMI_CREATE_DEVICE_ATTR(lid_resume, 0644, ASUS_WMI_DEVID_LID_RESUME);
2009 ASUS_WMI_CREATE_DEVICE_ATTR(als_enable, 0644, ASUS_WMI_DEVID_ALS_ENABLE);
2011 static ssize_t cpufv_store(struct device *dev, struct device_attribute *attr,
2012 const char *buf, size_t count)
2016 if (!count || sscanf(buf, "%i", &value) != 1)
2018 if (value < 0 || value > 2)
2021 rv = asus_wmi_evaluate_method(ASUS_WMI_METHODID_CFVS, value, 0, NULL);
2028 static DEVICE_ATTR_WO(cpufv);
2030 static struct attribute *platform_attributes[] = {
2031 &dev_attr_cpufv.attr,
2032 &dev_attr_camera.attr,
2033 &dev_attr_cardr.attr,
2034 &dev_attr_touchpad.attr,
2035 &dev_attr_lid_resume.attr,
2036 &dev_attr_als_enable.attr,
2037 &dev_attr_fan_mode.attr,
2041 static umode_t asus_sysfs_is_visible(struct kobject *kobj,
2042 struct attribute *attr, int idx)
2044 struct device *dev = container_of(kobj, struct device, kobj);
2045 struct asus_wmi *asus = dev_get_drvdata(dev);
2049 if (attr == &dev_attr_camera.attr)
2050 devid = ASUS_WMI_DEVID_CAMERA;
2051 else if (attr == &dev_attr_cardr.attr)
2052 devid = ASUS_WMI_DEVID_CARDREADER;
2053 else if (attr == &dev_attr_touchpad.attr)
2054 devid = ASUS_WMI_DEVID_TOUCHPAD;
2055 else if (attr == &dev_attr_lid_resume.attr)
2056 devid = ASUS_WMI_DEVID_LID_RESUME;
2057 else if (attr == &dev_attr_als_enable.attr)
2058 devid = ASUS_WMI_DEVID_ALS_ENABLE;
2059 else if (attr == &dev_attr_fan_mode.attr)
2060 ok = asus->fan_mode_available;
2063 ok = !(asus_wmi_get_devstate_simple(asus, devid) < 0);
2065 return ok ? attr->mode : 0;
2068 static const struct attribute_group platform_attribute_group = {
2069 .is_visible = asus_sysfs_is_visible,
2070 .attrs = platform_attributes
2073 static void asus_wmi_sysfs_exit(struct platform_device *device)
2075 sysfs_remove_group(&device->dev.kobj, &platform_attribute_group);
2078 static int asus_wmi_sysfs_init(struct platform_device *device)
2080 return sysfs_create_group(&device->dev.kobj, &platform_attribute_group);
2083 /* Platform device ************************************************************/
2085 static int asus_wmi_platform_init(struct asus_wmi *asus)
2087 struct device *dev = &asus->platform_device->dev;
2091 /* INIT enable hotkeys on some models */
2092 if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_INIT, 0, 0, &rv))
2093 pr_info("Initialization: %#x\n", rv);
2095 /* We don't know yet what to do with this version... */
2096 if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_SPEC, 0, 0x9, &rv)) {
2097 pr_info("BIOS WMI version: %d.%d\n", rv >> 16, rv & 0xFF);
2102 * The SFUN method probably allows the original driver to get the list
2103 * of features supported by a given model. For now, 0x0100 or 0x0800
2104 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
2105 * The significance of others is yet to be found.
2107 if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_SFUN, 0, 0, &rv)) {
2108 pr_info("SFUN value: %#x\n", rv);
2113 * Eee PC and Notebooks seems to have different method_id for DSTS,
2114 * but it may also be related to the BIOS's SPEC.
2115 * Note, on most Eeepc, there is no way to check if a method exist
2116 * or note, while on notebooks, they returns 0xFFFFFFFE on failure,
2117 * but once again, SPEC may probably be used for that kind of things.
2119 * Additionally at least TUF Gaming series laptops return nothing for
2120 * unknown methods, so the detection in this way is not possible.
2122 * There is strong indication that only ACPI WMI devices that have _UID
2123 * equal to "ASUSWMI" use DCTS whereas those with "ATK" use DSTS.
2125 wmi_uid = wmi_get_acpi_device_uid(ASUS_WMI_MGMT_GUID);
2129 if (!strcmp(wmi_uid, ASUS_ACPI_UID_ASUSWMI)) {
2130 dev_info(dev, "Detected ASUSWMI, use DCTS\n");
2131 asus->dsts_id = ASUS_WMI_METHODID_DCTS;
2133 dev_info(dev, "Detected %s, not ASUSWMI, use DSTS\n", wmi_uid);
2134 asus->dsts_id = ASUS_WMI_METHODID_DSTS;
2138 * Some devices can have multiple event codes stored in a queue before
2139 * the module load if it was unloaded intermittently after calling
2140 * the INIT method (enables event handling). The WMI notify handler is
2141 * expected to retrieve all event codes until a retrieved code equals
2142 * queue end marker (One or Ones). Old codes are flushed from the queue
2143 * upon module load. Not enabling this when it should be has minimal
2144 * visible impact so fall back if anything goes wrong.
2146 wmi_uid = wmi_get_acpi_device_uid(asus->driver->event_guid);
2147 if (wmi_uid && !strcmp(wmi_uid, ASUS_ACPI_UID_ATK)) {
2148 dev_info(dev, "Detected ATK, enable event queue\n");
2150 if (!asus_wmi_notify_queue_flush(asus))
2151 asus->wmi_event_queue = true;
2154 /* CWAP allow to define the behavior of the Fn+F2 key,
2155 * this method doesn't seems to be present on Eee PCs */
2156 if (asus->driver->quirks->wapf >= 0)
2157 asus_wmi_set_devstate(ASUS_WMI_DEVID_CWAP,
2158 asus->driver->quirks->wapf, NULL);
2163 /* debugfs ********************************************************************/
2165 struct asus_wmi_debugfs_node {
2166 struct asus_wmi *asus;
2168 int (*show) (struct seq_file *m, void *data);
2171 static int show_dsts(struct seq_file *m, void *data)
2173 struct asus_wmi *asus = m->private;
2177 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
2182 seq_printf(m, "DSTS(%#x) = %#x\n", asus->debug.dev_id, retval);
2187 static int show_devs(struct seq_file *m, void *data)
2189 struct asus_wmi *asus = m->private;
2193 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
2199 seq_printf(m, "DEVS(%#x, %#x) = %#x\n", asus->debug.dev_id,
2200 asus->debug.ctrl_param, retval);
2205 static int show_call(struct seq_file *m, void *data)
2207 struct asus_wmi *asus = m->private;
2208 struct bios_args args = {
2209 .arg0 = asus->debug.dev_id,
2210 .arg1 = asus->debug.ctrl_param,
2212 struct acpi_buffer input = { (acpi_size) sizeof(args), &args };
2213 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
2214 union acpi_object *obj;
2217 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
2218 0, asus->debug.method_id,
2221 if (ACPI_FAILURE(status))
2224 obj = (union acpi_object *)output.pointer;
2225 if (obj && obj->type == ACPI_TYPE_INTEGER)
2226 seq_printf(m, "%#x(%#x, %#x) = %#x\n", asus->debug.method_id,
2227 asus->debug.dev_id, asus->debug.ctrl_param,
2228 (u32) obj->integer.value);
2230 seq_printf(m, "%#x(%#x, %#x) = t:%d\n", asus->debug.method_id,
2231 asus->debug.dev_id, asus->debug.ctrl_param,
2232 obj ? obj->type : -1);
2239 static struct asus_wmi_debugfs_node asus_wmi_debug_files[] = {
2240 {NULL, "devs", show_devs},
2241 {NULL, "dsts", show_dsts},
2242 {NULL, "call", show_call},
2245 static int asus_wmi_debugfs_open(struct inode *inode, struct file *file)
2247 struct asus_wmi_debugfs_node *node = inode->i_private;
2249 return single_open(file, node->show, node->asus);
2252 static const struct file_operations asus_wmi_debugfs_io_ops = {
2253 .owner = THIS_MODULE,
2254 .open = asus_wmi_debugfs_open,
2256 .llseek = seq_lseek,
2257 .release = single_release,
2260 static void asus_wmi_debugfs_exit(struct asus_wmi *asus)
2262 debugfs_remove_recursive(asus->debug.root);
2265 static void asus_wmi_debugfs_init(struct asus_wmi *asus)
2269 asus->debug.root = debugfs_create_dir(asus->driver->name, NULL);
2271 debugfs_create_x32("method_id", S_IRUGO | S_IWUSR, asus->debug.root,
2272 &asus->debug.method_id);
2274 debugfs_create_x32("dev_id", S_IRUGO | S_IWUSR, asus->debug.root,
2275 &asus->debug.dev_id);
2277 debugfs_create_x32("ctrl_param", S_IRUGO | S_IWUSR, asus->debug.root,
2278 &asus->debug.ctrl_param);
2280 for (i = 0; i < ARRAY_SIZE(asus_wmi_debug_files); i++) {
2281 struct asus_wmi_debugfs_node *node = &asus_wmi_debug_files[i];
2284 debugfs_create_file(node->name, S_IFREG | S_IRUGO,
2285 asus->debug.root, node,
2286 &asus_wmi_debugfs_io_ops);
2290 /* Init / exit ****************************************************************/
2292 static int asus_wmi_add(struct platform_device *pdev)
2294 struct platform_driver *pdrv = to_platform_driver(pdev->dev.driver);
2295 struct asus_wmi_driver *wdrv = to_asus_wmi_driver(pdrv);
2296 struct asus_wmi *asus;
2297 const char *chassis_type;
2302 asus = kzalloc(sizeof(struct asus_wmi), GFP_KERNEL);
2306 asus->driver = wdrv;
2307 asus->platform_device = pdev;
2308 wdrv->platform_device = pdev;
2309 platform_set_drvdata(asus->platform_device, asus);
2311 if (wdrv->detect_quirks)
2312 wdrv->detect_quirks(asus->driver);
2314 err = asus_wmi_platform_init(asus);
2318 err = fan_mode_check_present(asus);
2322 err = asus_wmi_sysfs_init(asus->platform_device);
2326 err = asus_wmi_input_init(asus);
2330 err = asus_wmi_fan_init(asus); /* probably no problems on error */
2331 asus_hwmon_fan_set_auto(asus);
2333 err = asus_wmi_hwmon_init(asus);
2337 err = asus_wmi_led_init(asus);
2341 asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WLAN, &result);
2342 if (result & (ASUS_WMI_DSTS_PRESENCE_BIT | ASUS_WMI_DSTS_USER_BIT))
2343 asus->driver->wlan_ctrl_by_user = 1;
2345 if (!(asus->driver->wlan_ctrl_by_user && ashs_present())) {
2346 err = asus_wmi_rfkill_init(asus);
2351 if (asus->driver->quirks->wmi_force_als_set)
2354 /* Some Asus desktop boards export an acpi-video backlight interface,
2355 stop this from showing up */
2356 chassis_type = dmi_get_system_info(DMI_CHASSIS_TYPE);
2357 if (chassis_type && !strcmp(chassis_type, "3"))
2358 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
2360 if (asus->driver->quirks->wmi_backlight_power)
2361 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
2363 if (asus->driver->quirks->wmi_backlight_native)
2364 acpi_video_set_dmi_backlight_type(acpi_backlight_native);
2366 if (asus->driver->quirks->xusb2pr)
2367 asus_wmi_set_xusb2pr(asus);
2369 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
2370 err = asus_wmi_backlight_init(asus);
2371 if (err && err != -ENODEV)
2372 goto fail_backlight;
2373 } else if (asus->driver->quirks->wmi_backlight_set_devstate)
2374 err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BACKLIGHT, 2, NULL);
2376 if (asus_wmi_has_fnlock_key(asus)) {
2377 asus->fnlock_locked = true;
2378 asus_wmi_fnlock_update(asus);
2381 status = wmi_install_notify_handler(asus->driver->event_guid,
2382 asus_wmi_notify, asus);
2383 if (ACPI_FAILURE(status)) {
2384 pr_err("Unable to register notify handler - %d\n", status);
2386 goto fail_wmi_handler;
2389 asus_wmi_debugfs_init(asus);
2394 asus_wmi_backlight_exit(asus);
2396 asus_wmi_rfkill_exit(asus);
2398 asus_wmi_led_exit(asus);
2401 asus_wmi_input_exit(asus);
2403 asus_wmi_sysfs_exit(asus->platform_device);
2411 static int asus_wmi_remove(struct platform_device *device)
2413 struct asus_wmi *asus;
2415 asus = platform_get_drvdata(device);
2416 wmi_remove_notify_handler(asus->driver->event_guid);
2417 asus_wmi_backlight_exit(asus);
2418 asus_wmi_input_exit(asus);
2419 asus_wmi_led_exit(asus);
2420 asus_wmi_rfkill_exit(asus);
2421 asus_wmi_debugfs_exit(asus);
2422 asus_wmi_sysfs_exit(asus->platform_device);
2423 asus_hwmon_fan_set_auto(asus);
2429 /* Platform driver - hibernate/resume callbacks *******************************/
2431 static int asus_hotk_thaw(struct device *device)
2433 struct asus_wmi *asus = dev_get_drvdata(device);
2435 if (asus->wlan.rfkill) {
2439 * Work around bios bug - acpi _PTS turns off the wireless led
2440 * during suspend. Normally it restores it on resume, but
2441 * we should kick it ourselves in case hibernation is aborted.
2443 wlan = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WLAN);
2444 asus_wmi_set_devstate(ASUS_WMI_DEVID_WLAN, wlan, NULL);
2450 static int asus_hotk_resume(struct device *device)
2452 struct asus_wmi *asus = dev_get_drvdata(device);
2454 if (!IS_ERR_OR_NULL(asus->kbd_led.dev))
2455 kbd_led_update(asus);
2457 if (asus_wmi_has_fnlock_key(asus))
2458 asus_wmi_fnlock_update(asus);
2462 static int asus_hotk_restore(struct device *device)
2464 struct asus_wmi *asus = dev_get_drvdata(device);
2467 /* Refresh both wlan rfkill state and pci hotplug */
2468 if (asus->wlan.rfkill)
2469 asus_rfkill_hotplug(asus);
2471 if (asus->bluetooth.rfkill) {
2472 bl = !asus_wmi_get_devstate_simple(asus,
2473 ASUS_WMI_DEVID_BLUETOOTH);
2474 rfkill_set_sw_state(asus->bluetooth.rfkill, bl);
2476 if (asus->wimax.rfkill) {
2477 bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WIMAX);
2478 rfkill_set_sw_state(asus->wimax.rfkill, bl);
2480 if (asus->wwan3g.rfkill) {
2481 bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WWAN3G);
2482 rfkill_set_sw_state(asus->wwan3g.rfkill, bl);
2484 if (asus->gps.rfkill) {
2485 bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_GPS);
2486 rfkill_set_sw_state(asus->gps.rfkill, bl);
2488 if (asus->uwb.rfkill) {
2489 bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_UWB);
2490 rfkill_set_sw_state(asus->uwb.rfkill, bl);
2492 if (!IS_ERR_OR_NULL(asus->kbd_led.dev))
2493 kbd_led_update(asus);
2495 if (asus_wmi_has_fnlock_key(asus))
2496 asus_wmi_fnlock_update(asus);
2500 static const struct dev_pm_ops asus_pm_ops = {
2501 .thaw = asus_hotk_thaw,
2502 .restore = asus_hotk_restore,
2503 .resume = asus_hotk_resume,
2506 /* Registration ***************************************************************/
2508 static int asus_wmi_probe(struct platform_device *pdev)
2510 struct platform_driver *pdrv = to_platform_driver(pdev->dev.driver);
2511 struct asus_wmi_driver *wdrv = to_asus_wmi_driver(pdrv);
2514 if (!wmi_has_guid(ASUS_WMI_MGMT_GUID)) {
2515 pr_warn("ASUS Management GUID not found\n");
2519 if (wdrv->event_guid && !wmi_has_guid(wdrv->event_guid)) {
2520 pr_warn("ASUS Event GUID not found\n");
2525 ret = wdrv->probe(pdev);
2530 return asus_wmi_add(pdev);
2535 int __init_or_module asus_wmi_register_driver(struct asus_wmi_driver *driver)
2537 struct platform_driver *platform_driver;
2538 struct platform_device *platform_device;
2543 platform_driver = &driver->platform_driver;
2544 platform_driver->remove = asus_wmi_remove;
2545 platform_driver->driver.owner = driver->owner;
2546 platform_driver->driver.name = driver->name;
2547 platform_driver->driver.pm = &asus_pm_ops;
2549 platform_device = platform_create_bundle(platform_driver,
2552 if (IS_ERR(platform_device))
2553 return PTR_ERR(platform_device);
2558 EXPORT_SYMBOL_GPL(asus_wmi_register_driver);
2560 void asus_wmi_unregister_driver(struct asus_wmi_driver *driver)
2562 platform_device_unregister(driver->platform_device);
2563 platform_driver_unregister(&driver->platform_driver);
2566 EXPORT_SYMBOL_GPL(asus_wmi_unregister_driver);
2568 static int __init asus_wmi_init(void)
2570 pr_info("ASUS WMI generic driver loaded\n");
2574 static void __exit asus_wmi_exit(void)
2576 pr_info("ASUS WMI generic driver unloaded\n");
2579 module_init(asus_wmi_init);
2580 module_exit(asus_wmi_exit);