27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29 #include <linux/kernel.h>
30 #include <linux/module.h>
32 #include <linux/types.h>
33 #include <linux/slab.h>
34 #include <linux/input.h>
39 #include <linux/rfkill.h>
40 #include <linux/pci.h>
59 #define to_platform_driver(drv) \
60 (container_of((drv), struct platform_driver, driver))
62 #define to_asus_wmi_driver(pdrv) \
63 (container_of((pdrv), struct asus_wmi_driver, platform_driver))
65 #define ASUS_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66"
67 #define NOTIFY_BRNUP_MIN 0x11
68 #define NOTIFY_BRNUP_MAX 0x1f
69 #define NOTIFY_BRNDOWN_MIN 0x20
70 #define NOTIFY_BRNDOWN_MAX 0x2e
71 #define NOTIFY_KBD_BRTUP 0xc4
72 #define NOTIFY_KBD_BRTDWN 0xc5
75 #define ASUS_WMI_METHODID_SPEC 0x43455053
76 #define ASUS_WMI_METHODID_SFBD 0x44424653
77 #define ASUS_WMI_METHODID_GLCD 0x44434C47
78 #define ASUS_WMI_METHODID_GPID 0x44495047
79 #define ASUS_WMI_METHODID_QMOD 0x444F4D51
80 #define ASUS_WMI_METHODID_SPLV 0x4C425053
81 #define ASUS_WMI_METHODID_SFUN 0x4E554653
82 #define ASUS_WMI_METHODID_SDSP 0x50534453
83 #define ASUS_WMI_METHODID_GDSP 0x50534447
84 #define ASUS_WMI_METHODID_DEVP 0x50564544
85 #define ASUS_WMI_METHODID_OSVR 0x5256534F
86 #define ASUS_WMI_METHODID_DSTS 0x53544344
87 #define ASUS_WMI_METHODID_DSTS2 0x53545344
88 #define ASUS_WMI_METHODID_BSTS 0x53545342
89 #define ASUS_WMI_METHODID_DEVS 0x53564544
90 #define ASUS_WMI_METHODID_CFVS 0x53564643
91 #define ASUS_WMI_METHODID_KBFT 0x5446424B
92 #define ASUS_WMI_METHODID_INIT 0x54494E49
93 #define ASUS_WMI_METHODID_HKEY 0x59454B48
95 #define ASUS_WMI_UNSUPPORTED_METHOD 0xFFFFFFFE
98 #define ASUS_WMI_DEVID_HW_SWITCH 0x00010001
99 #define ASUS_WMI_DEVID_WIRELESS_LED 0x00010002
100 #define ASUS_WMI_DEVID_CWAP 0x00010003
101 #define ASUS_WMI_DEVID_WLAN 0x00010011
102 #define ASUS_WMI_DEVID_WLAN_LED 0x00010012
103 #define ASUS_WMI_DEVID_BLUETOOTH 0x00010013
104 #define ASUS_WMI_DEVID_GPS 0x00010015
105 #define ASUS_WMI_DEVID_WIMAX 0x00010017
106 #define ASUS_WMI_DEVID_WWAN3G 0x00010019
107 #define ASUS_WMI_DEVID_UWB 0x00010021
111 #define ASUS_WMI_DEVID_LED1 0x00020011
112 #define ASUS_WMI_DEVID_LED2 0x00020012
113 #define ASUS_WMI_DEVID_LED3 0x00020013
114 #define ASUS_WMI_DEVID_LED4 0x00020014
115 #define ASUS_WMI_DEVID_LED5 0x00020015
116 #define ASUS_WMI_DEVID_LED6 0x00020016
119 #define ASUS_WMI_DEVID_BACKLIGHT 0x00050011
120 #define ASUS_WMI_DEVID_BRIGHTNESS 0x00050012
121 #define ASUS_WMI_DEVID_KBD_BACKLIGHT 0x00050021
122 #define ASUS_WMI_DEVID_LIGHT_SENSOR 0x00050022
125 #define ASUS_WMI_DEVID_CAMERA 0x00060013
128 #define ASUS_WMI_DEVID_CARDREADER 0x00080013
131 #define ASUS_WMI_DEVID_TOUCHPAD 0x00100011
132 #define ASUS_WMI_DEVID_TOUCHPAD_LED 0x00100012
135 #define ASUS_WMI_DEVID_THERMAL_CTRL 0x00110011
136 #define ASUS_WMI_DEVID_FAN_CTRL 0x00110012
139 #define ASUS_WMI_DEVID_PROCESSOR_STATE 0x00120012
142 #define ASUS_WMI_DEVID_LID_RESUME 0x00120031
145 #define ASUS_WMI_DSTS_STATUS_BIT 0x00000001
146 #define ASUS_WMI_DSTS_UNKNOWN_BIT 0x00000002
147 #define ASUS_WMI_DSTS_PRESENCE_BIT 0x00010000
148 #define ASUS_WMI_DSTS_USER_BIT 0x00020000
149 #define ASUS_WMI_DSTS_BIOS_BIT 0x00040000
150 #define ASUS_WMI_DSTS_BRIGHTNESS_MASK 0x000000FF
151 #define ASUS_WMI_DSTS_MAX_BRIGTH_MASK 0x0000FF00
216 static int asus_wmi_input_init(
struct asus_wmi *asus)
220 asus->
inputdev = input_allocate_device();
234 err = input_register_device(asus->
inputdev);
236 goto err_free_keymap;
247 static void asus_wmi_input_exit(
struct asus_wmi *asus)
251 input_unregister_device(asus->
inputdev);
257 static int asus_wmi_evaluate_method(
u32 method_id,
u32 arg0,
u32 arg1,
299 return asus_wmi_evaluate_method(asus->
dsts_id, dev_id, 0, retval);
302 static int asus_wmi_set_devstate(
u32 dev_id,
u32 ctrl_param,
310 static int asus_wmi_get_devstate_bits(
struct asus_wmi *asus,
316 err = asus_wmi_get_devstate(asus, dev_id, &retval);
329 return retval &
mask;
332 static int asus_wmi_get_devstate_simple(
struct asus_wmi *asus,
u32 dev_id)
334 return asus_wmi_get_devstate_bits(asus, dev_id,
369 static int read_tpd_led_state(
struct asus_wmi *asus)
380 return read_tpd_led_state(asus);
395 ctrl_param = 0x80 | (asus->
kbd_led_wk & 0x7F);
414 if (retval == 0x8000)
419 *level = retval & 0x7F;
421 *env = (retval >> 8) & 0x7F;
435 if (value > asus->
kbd_led.max_brightness)
436 value = asus->
kbd_led.max_brightness;
451 retval = kbd_led_read(asus, &value,
NULL);
459 static void asus_wmi_led_exit(
struct asus_wmi *asus)
461 if (!IS_ERR_OR_NULL(asus->
kbd_led.dev))
463 if (!IS_ERR_OR_NULL(asus->
tpd_led.dev))
469 static int asus_wmi_led_init(
struct asus_wmi *asus)
477 if (read_tpd_led_state(asus) >= 0) {
480 asus->
tpd_led.name =
"asus::touchpad";
481 asus->
tpd_led.brightness_set = tpd_led_set;
482 asus->
tpd_led.brightness_get = tpd_led_get;
483 asus->
tpd_led.max_brightness = 1;
491 if (kbd_led_read(asus,
NULL,
NULL) >= 0) {
494 asus->
kbd_led.name =
"asus::kbd_backlight";
495 asus->
kbd_led.brightness_set = kbd_led_set;
496 asus->
kbd_led.brightness_get = kbd_led_get;
497 asus->
kbd_led.max_brightness = 3;
505 asus_wmi_led_exit(asus);
514 static bool asus_wlan_rfkill_blocked(
struct asus_wmi *asus)
523 static void asus_rfkill_hotplug(
struct asus_wmi *asus)
532 blocked = asus_wlan_rfkill_blocked(asus);
537 if (asus->
wlan.rfkill)
543 pr_warn(
"Unable to find PCI bus 1?\n");
548 pr_err(
"Unable to read PCI config space?\n");
551 absent = (l == 0xffffffff);
553 if (blocked != absent) {
554 pr_warn(
"BIOS says wireless lan is %s, "
555 "but the pci device is %s\n",
556 blocked ?
"blocked" :
"unblocked",
557 absent ?
"absent" :
"present");
558 pr_warn(
"skipped wireless hotplug as probably "
559 "inappropriate for this model\n");
574 pr_err(
"Unable to hotplug wifi\n");
606 static int asus_register_rfkill_notifier(
struct asus_wmi *asus,
char *
node)
616 asus_rfkill_notify, asus);
618 pr_warn(
"Failed to register notify on %s\n", node);
625 static void asus_unregister_rfkill_notifier(
struct asus_wmi *asus,
char *node)
637 pr_err(
"Error removing rfkill notify handler %s\n",
645 struct asus_wmi *asus = hotplug_slot->private;
655 static void asus_cleanup_pci_hotplug(
struct hotplug_slot *hotplug_slot)
657 kfree(hotplug_slot->info);
663 .get_adapter_status = asus_get_adapter_status,
664 .get_power_status = asus_get_adapter_status,
667 static void asus_hotplug_work(
struct work_struct *work)
672 asus_rfkill_hotplug(asus);
675 static int asus_setup_pci_hotplug(
struct asus_wmi *asus)
681 pr_err(
"Unable to find wifi PCI bus\n");
688 goto error_workqueue;
702 asus->
hotplug_slot->release = &asus_cleanup_pci_hotplug;
709 pr_err(
"Unable to register hotplug slot - %d\n", ret);
729 static int asus_rfkill_set(
void *data,
bool blocked)
732 u32 ctrl_param = !blocked;
744 priv->
asus->driver->wlan_ctrl_by_user)
747 return asus_wmi_set_devstate(dev_id, ctrl_param,
NULL);
750 static void asus_rfkill_query(
struct rfkill *
rfkill,
void *data)
755 result = asus_wmi_get_devstate_simple(priv->
asus, priv->
dev_id);
763 static int asus_rfkill_wlan_set(
void *data,
bool blocked)
777 ret = asus_rfkill_set(data, blocked);
782 static const struct rfkill_ops asus_rfkill_wlan_ops = {
783 .set_block = asus_rfkill_wlan_set,
784 .query = asus_rfkill_query,
787 static const struct rfkill_ops asus_rfkill_ops = {
788 .set_block = asus_rfkill_set,
789 .query = asus_rfkill_query,
792 static int asus_new_rfkill(
struct asus_wmi *asus,
796 int result = asus_wmi_get_devstate_simple(asus, dev_id);
797 struct rfkill **rfkill = &arfkill->
rfkill;
803 arfkill->
asus = asus;
806 asus->
driver->quirks->hotplug_wireless)
808 &asus_rfkill_wlan_ops, arfkill);
811 &asus_rfkill_ops, arfkill);
826 static void asus_wmi_rfkill_exit(
struct asus_wmi *asus)
828 asus_unregister_rfkill_notifier(asus,
"\\_SB.PCI0.P0P5");
829 asus_unregister_rfkill_notifier(asus,
"\\_SB.PCI0.P0P6");
830 asus_unregister_rfkill_notifier(asus,
"\\_SB.PCI0.P0P7");
831 if (asus->
wlan.rfkill) {
840 asus_rfkill_hotplug(asus);
851 if (asus->
wimax.rfkill) {
856 if (asus->
wwan3g.rfkill) {
861 if (asus->
gps.rfkill) {
866 if (asus->
uwb.rfkill) {
873 static int asus_wmi_rfkill_init(
struct asus_wmi *asus)
880 result = asus_new_rfkill(asus, &asus->
wlan,
"asus-wlan",
883 if (result && result != -
ENODEV)
886 result = asus_new_rfkill(asus, &asus->
bluetooth,
890 if (result && result != -
ENODEV)
893 result = asus_new_rfkill(asus, &asus->
wimax,
"asus-wimax",
896 if (result && result != -
ENODEV)
899 result = asus_new_rfkill(asus, &asus->
wwan3g,
"asus-wwan3g",
902 if (result && result != -
ENODEV)
905 result = asus_new_rfkill(asus, &asus->
gps,
"asus-gps",
908 if (result && result != -
ENODEV)
911 result = asus_new_rfkill(asus, &asus->
uwb,
"asus-uwb",
914 if (result && result != -
ENODEV)
917 if (!asus->
driver->quirks->hotplug_wireless)
920 result = asus_setup_pci_hotplug(asus);
925 if (result == -
EBUSY)
928 asus_register_rfkill_notifier(asus,
"\\_SB.PCI0.P0P5");
929 asus_register_rfkill_notifier(asus,
"\\_SB.PCI0.P0P6");
930 asus_register_rfkill_notifier(asus,
"\\_SB.PCI0.P0P7");
935 asus_rfkill_hotplug(asus);
938 if (result && result != -
ENODEV)
939 asus_wmi_rfkill_exit(asus);
971 else if (value != 0) {
972 pr_err(
"Unknown fan speed %#x", value);
976 return sprintf(buf,
"%d\n", value);
994 return sprintf(buf,
"%d\n", value);
1003 return sprintf(buf,
"asus\n");
1007 static struct attribute *hwmon_attributes[] = {
1008 &sensor_dev_attr_pwm1.dev_attr.attr,
1009 &sensor_dev_attr_temp1_input.dev_attr.attr,
1010 &sensor_dev_attr_name.dev_attr.attr,
1019 struct asus_wmi *asus = platform_get_drvdata(pdev);
1024 if (attr == &sensor_dev_attr_pwm1.dev_attr.attr)
1026 else if (attr == &sensor_dev_attr_temp1_input.dev_attr.attr)
1030 int err = asus_wmi_get_devstate(asus, dev_id, &value);
1046 || (!asus->
sfun && !(value & ASUS_WMI_DSTS_PRESENCE_BIT)))
1054 return ok ? attr->
mode : 0;
1058 .is_visible = asus_hwmon_sysfs_is_visible,
1059 .attrs = hwmon_attributes
1062 static void asus_wmi_hwmon_exit(
struct asus_wmi *asus)
1074 static int asus_wmi_hwmon_init(
struct asus_wmi *asus)
1080 if (IS_ERR(hwmon)) {
1081 pr_err(
"Could not register asus hwmon device\n");
1082 return PTR_ERR(hwmon);
1088 asus_wmi_hwmon_exit(asus);
1095 static int read_backlight_power(
struct asus_wmi *asus)
1098 if (asus->
driver->quirks->store_backlight_power)
1099 ret = !asus->
driver->panel_power;
1101 ret = asus_wmi_get_devstate_simple(asus,
1110 static int read_brightness_max(
struct asus_wmi *asus)
1131 struct asus_wmi *asus = bl_get_data(bd);
1145 struct asus_wmi *asus = bl_get_data(bd);
1148 if ((asus->
driver->brightness < bd->
props.brightness) ||
1149 bd->
props.brightness == bd->
props.max_brightness)
1150 ctrl_param = 0x00008001;
1151 else if ((asus->
driver->brightness > bd->
props.brightness) ||
1152 bd->
props.brightness == 0)
1153 ctrl_param = 0x00008000;
1162 struct asus_wmi *asus = bl_get_data(bd);
1166 power = read_backlight_power(asus);
1167 if (power != -
ENODEV && bd->
props.power != power) {
1171 if (asus->
driver->quirks->store_backlight_power)
1176 if (asus->
driver->quirks->scalar_panel_brightness)
1180 if (asus->
driver->quirks->scalar_panel_brightness)
1181 ctrl_param = get_scalar_command(bd);
1183 ctrl_param = bd->
props.brightness;
1192 .get_brightness = read_brightness,
1193 .update_status = update_bl_status,
1196 static int asus_wmi_backlight_notify(
struct asus_wmi *asus,
int code)
1199 int old = bd->
props.brightness;
1207 bd->
props.brightness =
new;
1208 backlight_update_status(bd);
1214 static int asus_wmi_backlight_init(
struct asus_wmi *asus)
1221 max = read_brightness_max(asus);
1228 power = read_backlight_power(asus);
1237 props.max_brightness =
max;
1240 &asus_wmi_bl_ops, &props);
1242 pr_err(
"Could not register backlight device\n");
1248 if (asus->
driver->quirks->store_backlight_power)
1251 bd->
props.brightness = read_brightness(bd);
1253 backlight_update_status(bd);
1260 static void asus_wmi_backlight_exit(
struct asus_wmi *asus)
1268 static void asus_wmi_notify(
u32 value,
void *
context)
1276 unsigned int key_value = 1;
1277 bool autorelease = 1;
1280 if (status !=
AE_OK) {
1281 pr_err(
"bad event status 0x%x\n", status);
1293 if (asus->
driver->key_filter) {
1294 asus->
driver->key_filter(asus->
driver, &code, &key_value,
1308 asus_wmi_backlight_notify(asus, orig_code);
1309 }
else if (!sparse_keymap_report_event(asus->
inputdev, code,
1310 key_value, autorelease))
1311 pr_info(
"Unknown key %x pressed\n", code);
1320 static int parse_arg(
const char *buf,
unsigned long count,
int *
val)
1324 if (
sscanf(buf,
"%i", val) != 1)
1330 const char *buf,
size_t count)
1335 value = asus_wmi_get_devstate_simple(asus, devid);
1339 rv = parse_arg(buf, count, &value);
1340 err = asus_wmi_set_devstate(devid, value, &retval);
1348 static ssize_t show_sys_wmi(
struct asus_wmi *asus,
int devid,
char *buf)
1350 int value = asus_wmi_get_devstate_simple(asus, devid);
1355 return sprintf(buf,
"%d\n", value);
1358 #define ASUS_WMI_CREATE_DEVICE_ATTR(_name, _mode, _cm) \
1359 static ssize_t show_##_name(struct device *dev, \
1360 struct device_attribute *attr, \
1363 struct asus_wmi *asus = dev_get_drvdata(dev); \
1365 return show_sys_wmi(asus, _cm, buf); \
1367 static ssize_t store_##_name(struct device *dev, \
1368 struct device_attribute *attr, \
1369 const char *buf, size_t count) \
1371 struct asus_wmi *asus = dev_get_drvdata(dev); \
1373 return store_sys_wmi(asus, _cm, buf, count); \
1375 static struct device_attribute dev_attr_##_name = { \
1377 .name = __stringify(_name), \
1379 .show = show_##_name, \
1380 .store = store_##_name, \
1389 const char *buf,
size_t count)
1393 if (!count ||
sscanf(buf,
"%i", &value) != 1)
1395 if (value < 0 || value > 2)
1407 static struct attribute *platform_attributes[] = {
1408 &dev_attr_cpufv.attr,
1409 &dev_attr_camera.attr,
1410 &dev_attr_cardr.attr,
1411 &dev_attr_touchpad.attr,
1412 &dev_attr_lid_resume.attr,
1421 struct asus_wmi *asus = platform_get_drvdata(pdev);
1425 if (attr == &dev_attr_camera.attr)
1427 else if (attr == &dev_attr_cardr.attr)
1429 else if (attr == &dev_attr_touchpad.attr)
1431 else if (attr == &dev_attr_lid_resume.attr)
1435 ok = !(asus_wmi_get_devstate_simple(asus, devid) < 0);
1437 return ok ? attr->
mode : 0;
1441 .is_visible = asus_sysfs_is_visible,
1442 .attrs = platform_attributes
1458 static int asus_wmi_platform_init(
struct asus_wmi *asus)
1464 pr_info(
"Initialization: %#x", rv);
1468 pr_info(
"BIOS WMI version: %d.%d", rv >> 16, rv & 0xFF);
1479 pr_info(
"SFUN value: %#x", rv);
1497 if (asus->
driver->quirks->wapf >= 0)
1504 static void asus_wmi_platform_exit(
struct asus_wmi *asus)
1518 static int show_dsts(
struct seq_file *
m,
void *data)
1524 err = asus_wmi_get_devstate(asus, asus->
debug.dev_id, &retval);
1534 static int show_devs(
struct seq_file *
m,
void *data)
1540 err = asus_wmi_set_devstate(asus->
debug.dev_id, asus->
debug.ctrl_param,
1547 asus->
debug.ctrl_param, retval);
1552 static int show_call(
struct seq_file *m,
void *data)
1557 .arg1 = asus->
debug.ctrl_param,
1559 struct acpi_buffer input = { (acpi_size)
sizeof(args), &args };
1565 1, asus->
debug.method_id,
1579 obj ? obj->
type : -1);
1587 {
NULL,
"devs", show_devs},
1588 {
NULL,
"dsts", show_dsts},
1589 {
NULL,
"call", show_call},
1601 .open = asus_wmi_debugfs_open,
1607 static void asus_wmi_debugfs_exit(
struct asus_wmi *asus)
1612 static int asus_wmi_debugfs_init(
struct asus_wmi *asus)
1618 if (!asus->
debug.root) {
1619 pr_err(
"failed to create debugfs directory");
1638 for (i = 0; i <
ARRAY_SIZE(asus_wmi_debug_files); i++) {
1643 asus->
debug.root, node,
1644 &asus_wmi_debugfs_io_ops);
1646 pr_err(
"failed to create debug file: %s\n", node->
name);
1654 asus_wmi_debugfs_exit(asus);
1682 err = asus_wmi_platform_init(asus);
1686 err = asus_wmi_input_init(asus);
1690 err = asus_wmi_hwmon_init(asus);
1694 err = asus_wmi_led_init(asus);
1698 err = asus_wmi_rfkill_init(asus);
1702 if (asus->
driver->quirks->wmi_backlight_power)
1705 pr_info(
"Disabling ACPI video driver\n");
1707 err = asus_wmi_backlight_init(asus);
1708 if (err && err != -
ENODEV)
1709 goto fail_backlight;
1711 pr_info(
"Backlight controlled by ACPI video driver\n");
1714 asus_wmi_notify, asus);
1716 pr_err(
"Unable to register notify handler - %d\n", status);
1718 goto fail_wmi_handler;
1721 err = asus_wmi_debugfs_init(asus);
1727 asus->
driver->wlan_ctrl_by_user = 1;
1734 asus_wmi_backlight_exit(asus);
1736 asus_wmi_rfkill_exit(asus);
1738 asus_wmi_led_exit(asus);
1740 asus_wmi_hwmon_exit(asus);
1742 asus_wmi_input_exit(asus);
1744 asus_wmi_platform_exit(asus);
1754 asus = platform_get_drvdata(device);
1756 asus_wmi_backlight_exit(asus);
1757 asus_wmi_input_exit(asus);
1758 asus_wmi_hwmon_exit(asus);
1759 asus_wmi_led_exit(asus);
1760 asus_wmi_rfkill_exit(asus);
1761 asus_wmi_debugfs_exit(asus);
1762 asus_wmi_platform_exit(asus);
1775 if (asus->
wlan.rfkill) {
1790 static int asus_hotk_restore(
struct device *device)
1796 if (asus->
wlan.rfkill)
1797 asus_rfkill_hotplug(asus);
1800 bl = !asus_wmi_get_devstate_simple(asus,
1804 if (asus->
wimax.rfkill) {
1808 if (asus->
wwan3g.rfkill) {
1812 if (asus->
gps.rfkill) {
1816 if (asus->
uwb.rfkill) {
1824 static const struct dev_pm_ops asus_pm_ops = {
1825 .thaw = asus_hotk_thaw,
1826 .restore = asus_hotk_restore,
1836 pr_warn(
"Management GUID not found\n");
1841 pr_warn(
"Event GUID not found\n");
1846 ret = wdrv->
probe(pdev);
1851 return asus_wmi_add(pdev);
1865 platform_driver->
remove = asus_wmi_remove;
1868 platform_driver->
driver.pm = &asus_pm_ops;
1873 if (IS_ERR(platform_device))
1874 return PTR_ERR(platform_device);
1889 static int __init asus_wmi_init(
void)
1892 pr_info(
"Asus Management GUID not found");
1896 pr_info(
"ASUS WMI generic driver loaded");
1900 static void __exit asus_wmi_exit(
void)
1902 pr_info(
"ASUS WMI generic driver unloaded");