Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 2 | /* |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3 | * Asus PC WMI hotkey driver |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 4 | * |
| 5 | * Copyright(C) 2010 Intel Corporation. |
Corentin Chary | 57ab7da | 2011-02-26 10:20:32 +0100 | [diff] [blame] | 6 | * Copyright(C) 2010-2011 Corentin Chary <corentin.chary@gmail.com> |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 7 | * |
| 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> |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 12 | */ |
| 13 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 15 | |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 16 | #include <linux/kernel.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/types.h> |
Tejun Heo | a32f392 | 2010-04-05 11:37:59 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 21 | #include <linux/input.h> |
| 22 | #include <linux/input/sparse-keymap.h> |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 23 | #include <linux/fb.h> |
| 24 | #include <linux/backlight.h> |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 25 | #include <linux/leds.h> |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 26 | #include <linux/rfkill.h> |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 27 | #include <linux/pci.h> |
| 28 | #include <linux/pci_hotplug.h> |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 29 | #include <linux/hwmon.h> |
| 30 | #include <linux/hwmon-sysfs.h> |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 31 | #include <linux/debugfs.h> |
| 32 | #include <linux/seq_file.h> |
Daniel Drake | ffb6ce7 | 2018-10-09 14:40:55 +0800 | [diff] [blame] | 33 | #include <linux/platform_data/x86/asus-wmi.h> |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 34 | #include <linux/platform_device.h> |
Corentin Chary | 6118b8a | 2011-07-01 11:34:36 +0200 | [diff] [blame] | 35 | #include <linux/thermal.h> |
Lv Zheng | 8b48463 | 2013-12-03 08:49:16 +0800 | [diff] [blame] | 36 | #include <linux/acpi.h> |
Hans de Goede | d8c66f6 | 2014-07-08 10:47:21 +0200 | [diff] [blame] | 37 | #include <linux/dmi.h> |
AceLan Kao | 272c77d | 2012-06-13 09:32:06 +0200 | [diff] [blame] | 38 | #include <acpi/video.h> |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 39 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 40 | #include "asus-wmi.h" |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 41 | |
Corentin Chary | 5909c65 | 2012-12-17 16:00:05 -0800 | [diff] [blame] | 42 | MODULE_AUTHOR("Corentin Chary <corentin.chary@gmail.com>, " |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 43 | "Yong Wang <yong.y.wang@intel.com>"); |
| 44 | MODULE_DESCRIPTION("Asus Generic WMI Driver"); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 45 | MODULE_LICENSE("GPL"); |
| 46 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 47 | #define to_asus_wmi_driver(pdrv) \ |
| 48 | (container_of((pdrv), struct asus_wmi_driver, platform_driver)) |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 49 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 50 | #define ASUS_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66" |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 51 | |
Corentin Chary | 33e0e6f | 2011-02-06 13:28:34 +0100 | [diff] [blame] | 52 | #define NOTIFY_BRNUP_MIN 0x11 |
| 53 | #define NOTIFY_BRNUP_MAX 0x1f |
| 54 | #define NOTIFY_BRNDOWN_MIN 0x20 |
| 55 | #define NOTIFY_BRNDOWN_MAX 0x2e |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 56 | #define NOTIFY_FNLOCK_TOGGLE 0x4e |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 57 | #define NOTIFY_KBD_BRTUP 0xc4 |
| 58 | #define NOTIFY_KBD_BRTDWN 0xc5 |
Chris Chiu | ed99d29 | 2018-06-20 22:46:45 +0800 | [diff] [blame] | 59 | #define NOTIFY_KBD_BRTTOGGLE 0xc7 |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 60 | #define NOTIFY_KBD_FBM 0x99 |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 61 | |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 62 | #define ASUS_WMI_FNLOCK_BIOS_DISABLED BIT(0) |
| 63 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 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 |
| 70 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 71 | #define ASUS_FAN_BOOST_MODE_NORMAL 0 |
| 72 | #define ASUS_FAN_BOOST_MODE_OVERBOOST 1 |
| 73 | #define ASUS_FAN_BOOST_MODE_OVERBOOST_MASK 0x01 |
| 74 | #define ASUS_FAN_BOOST_MODE_SILENT 2 |
| 75 | #define ASUS_FAN_BOOST_MODE_SILENT_MASK 0x02 |
| 76 | #define ASUS_FAN_BOOST_MODES_MASK 0x03 |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 77 | |
Kai-Chuan Hsieh | 8023eff | 2016-09-01 23:55:55 +0800 | [diff] [blame] | 78 | #define USB_INTEL_XUSB2PR 0xD0 |
| 79 | #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 |
| 80 | |
Yurii Pavlovskyi | e0668f2 | 2019-05-14 21:00:31 +0200 | [diff] [blame] | 81 | #define ASUS_ACPI_UID_ASUSWMI "ASUSWMI" |
Yurii Pavlovskyi | 1a373d1 | 2019-05-14 21:02:09 +0200 | [diff] [blame] | 82 | #define ASUS_ACPI_UID_ATK "ATK" |
| 83 | |
| 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 |
Yurii Pavlovskyi | e0668f2 | 2019-05-14 21:00:31 +0200 | [diff] [blame] | 89 | |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 90 | #define WMI_EVENT_MASK 0xFFFF |
| 91 | |
João Paulo Rechi Vita | 71050ae | 2017-02-20 14:50:22 -0500 | [diff] [blame] | 92 | static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL }; |
| 93 | |
João Paulo Rechi Vita | cf48bf9 | 2018-05-22 14:30:15 -0700 | [diff] [blame] | 94 | static bool ashs_present(void) |
| 95 | { |
| 96 | int i = 0; |
| 97 | while (ashs_ids[i]) { |
| 98 | if (acpi_dev_found(ashs_ids[i++])) |
| 99 | return true; |
| 100 | } |
| 101 | return false; |
| 102 | } |
| 103 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 104 | struct bios_args { |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 105 | u32 arg0; |
| 106 | u32 arg1; |
Yurii Pavlovskyi | 98e865a | 2019-05-14 20:54:50 +0200 | [diff] [blame] | 107 | u32 arg2; /* At least TUF Gaming series uses 3 dword input buffer. */ |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 108 | } __packed; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 109 | |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 110 | /* |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 111 | * Struct that's used for all methods called via AGFN. Naming is |
| 112 | * identically to the AML code. |
| 113 | */ |
| 114 | struct agfn_args { |
| 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 */ |
| 120 | } __packed; |
| 121 | |
| 122 | /* struct used for calling fan read and write methods */ |
| 123 | struct fan_args { |
| 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 */ |
| 127 | } __packed; |
| 128 | |
| 129 | /* |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 130 | * <platform>/ - debugfs root directory |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 131 | * dev_id - current dev_id |
| 132 | * ctrl_param - current ctrl_param |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 133 | * method_id - current method_id |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 134 | * devs - call DEVS(dev_id, ctrl_param) and print result |
| 135 | * dsts - call DSTS(dev_id) and print result |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 136 | * call - call method_id(dev_id, ctrl_param) and print result |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 137 | */ |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 138 | struct asus_wmi_debug { |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 139 | struct dentry *root; |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 140 | u32 method_id; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 141 | u32 dev_id; |
| 142 | u32 ctrl_param; |
| 143 | }; |
| 144 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 145 | struct asus_rfkill { |
| 146 | struct asus_wmi *asus; |
| 147 | struct rfkill *rfkill; |
| 148 | u32 dev_id; |
| 149 | }; |
| 150 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 151 | struct asus_wmi { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 152 | int dsts_id; |
Corentin Chary | 46dbca8 | 2011-02-26 10:20:38 +0100 | [diff] [blame] | 153 | int spec; |
| 154 | int sfun; |
Yurii Pavlovskyi | 1a373d1 | 2019-05-14 21:02:09 +0200 | [diff] [blame] | 155 | bool wmi_event_queue; |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 156 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 157 | struct input_dev *inputdev; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 158 | struct backlight_device *backlight_device; |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 159 | struct platform_device *platform_device; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 160 | |
AceLan Kao | 6cae06e | 2012-07-27 16:51:59 +0800 | [diff] [blame] | 161 | struct led_classdev wlan_led; |
| 162 | int wlan_led_wk; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 163 | struct led_classdev tpd_led; |
| 164 | int tpd_led_wk; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 165 | struct led_classdev kbd_led; |
| 166 | int kbd_led_wk; |
Maxime Bellengé | 4c05984 | 2017-09-23 18:23:37 +0200 | [diff] [blame] | 167 | struct led_classdev lightbar_led; |
| 168 | int lightbar_led_wk; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 169 | struct workqueue_struct *led_workqueue; |
| 170 | struct work_struct tpd_led_work; |
AceLan Kao | 6cae06e | 2012-07-27 16:51:59 +0800 | [diff] [blame] | 171 | struct work_struct wlan_led_work; |
Maxime Bellengé | 4c05984 | 2017-09-23 18:23:37 +0200 | [diff] [blame] | 172 | struct work_struct lightbar_led_work; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 173 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 174 | struct asus_rfkill wlan; |
| 175 | struct asus_rfkill bluetooth; |
| 176 | struct asus_rfkill wimax; |
| 177 | struct asus_rfkill wwan3g; |
Corentin Chary | 43be8bd | 2011-07-01 11:34:40 +0200 | [diff] [blame] | 178 | struct asus_rfkill gps; |
Corentin Chary | a912d32 | 2011-07-01 11:34:41 +0200 | [diff] [blame] | 179 | struct asus_rfkill uwb; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 180 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 181 | bool asus_hwmon_fan_manual_mode; |
| 182 | int asus_hwmon_num_fans; |
| 183 | int asus_hwmon_pwm; |
| 184 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 185 | bool fan_boost_mode_available; |
| 186 | u8 fan_boost_mode_mask; |
| 187 | u8 fan_boost_mode; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 188 | |
Lukas Wunner | 125450f | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 189 | struct hotplug_slot hotplug_slot; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 190 | struct mutex hotplug_lock; |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 191 | struct mutex wmi_lock; |
| 192 | struct workqueue_struct *hotplug_workqueue; |
| 193 | struct work_struct hotplug_work; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 194 | |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 195 | bool fnlock_locked; |
| 196 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 197 | struct asus_wmi_debug debug; |
| 198 | |
| 199 | struct asus_wmi_driver *driver; |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 200 | }; |
| 201 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 202 | /* Input **********************************************************************/ |
| 203 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 204 | static int asus_wmi_input_init(struct asus_wmi *asus) |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 205 | { |
| 206 | int err; |
| 207 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 208 | asus->inputdev = input_allocate_device(); |
| 209 | if (!asus->inputdev) |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 210 | return -ENOMEM; |
| 211 | |
Corentin Chary | 58a9f39 | 2011-03-30 16:32:32 +0200 | [diff] [blame] | 212 | asus->inputdev->name = asus->driver->input_name; |
| 213 | asus->inputdev->phys = asus->driver->input_phys; |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 214 | asus->inputdev->id.bustype = BUS_HOST; |
| 215 | asus->inputdev->dev.parent = &asus->platform_device->dev; |
Seth Forshee | 39bbde0 | 2011-07-04 09:49:20 +0200 | [diff] [blame] | 216 | set_bit(EV_REP, asus->inputdev->evbit); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 217 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 218 | err = sparse_keymap_setup(asus->inputdev, asus->driver->keymap, NULL); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 219 | if (err) |
| 220 | goto err_free_dev; |
| 221 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 222 | err = input_register_device(asus->inputdev); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 223 | if (err) |
Michał Kępień | c2ef3a1 | 2017-03-09 13:11:39 +0100 | [diff] [blame] | 224 | goto err_free_dev; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 225 | |
| 226 | return 0; |
| 227 | |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 228 | err_free_dev: |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 229 | input_free_device(asus->inputdev); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 230 | return err; |
| 231 | } |
| 232 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 233 | static void asus_wmi_input_exit(struct asus_wmi *asus) |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 234 | { |
Michał Kępień | c2ef3a1 | 2017-03-09 13:11:39 +0100 | [diff] [blame] | 235 | if (asus->inputdev) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 236 | input_unregister_device(asus->inputdev); |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 237 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 238 | asus->inputdev = NULL; |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 239 | } |
| 240 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 241 | /* WMI ************************************************************************/ |
| 242 | |
Yurii Pavlovskyi | 98e865a | 2019-05-14 20:54:50 +0200 | [diff] [blame] | 243 | static int asus_wmi_evaluate_method3(u32 method_id, |
| 244 | u32 arg0, u32 arg1, u32 arg2, u32 *retval) |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 245 | { |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 246 | struct bios_args args = { |
| 247 | .arg0 = arg0, |
| 248 | .arg1 = arg1, |
Yurii Pavlovskyi | 98e865a | 2019-05-14 20:54:50 +0200 | [diff] [blame] | 249 | .arg2 = arg2, |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 250 | }; |
| 251 | struct acpi_buffer input = { (acpi_size) sizeof(args), &args }; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 252 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 253 | acpi_status status; |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 254 | union acpi_object *obj; |
Rickard Strandqvist | 8ad3be1 | 2014-06-01 14:58:52 +0200 | [diff] [blame] | 255 | u32 tmp = 0; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 256 | |
Pali Rohár | 0fe5726 | 2017-08-12 09:44:16 +0200 | [diff] [blame] | 257 | status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID, 0, method_id, |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 258 | &input, &output); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 259 | |
| 260 | if (ACPI_FAILURE(status)) |
Yurii Pavlovskyi | 1827f3f | 2019-05-14 21:03:50 +0200 | [diff] [blame] | 261 | return -EIO; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 262 | |
| 263 | obj = (union acpi_object *)output.pointer; |
| 264 | if (obj && obj->type == ACPI_TYPE_INTEGER) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 265 | tmp = (u32) obj->integer.value; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 266 | |
Corentin Chary | 2a3f006 | 2010-11-29 08:14:10 +0100 | [diff] [blame] | 267 | if (retval) |
| 268 | *retval = tmp; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 269 | |
| 270 | kfree(obj); |
| 271 | |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 272 | if (tmp == ASUS_WMI_UNSUPPORTED_METHOD) |
| 273 | return -ENODEV; |
| 274 | |
| 275 | return 0; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 276 | } |
Yurii Pavlovskyi | 98e865a | 2019-05-14 20:54:50 +0200 | [diff] [blame] | 277 | |
| 278 | int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1, u32 *retval) |
| 279 | { |
| 280 | return asus_wmi_evaluate_method3(method_id, arg0, arg1, 0, retval); |
| 281 | } |
Daniel Drake | ffb6ce7 | 2018-10-09 14:40:55 +0800 | [diff] [blame] | 282 | EXPORT_SYMBOL_GPL(asus_wmi_evaluate_method); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 283 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 284 | static int asus_wmi_evaluate_method_agfn(const struct acpi_buffer args) |
| 285 | { |
| 286 | struct acpi_buffer input; |
| 287 | u64 phys_addr; |
| 288 | u32 retval; |
| 289 | u32 status = -1; |
| 290 | |
| 291 | /* |
| 292 | * Copy to dma capable address otherwise memory corruption occurs as |
| 293 | * bios has to be able to access it. |
| 294 | */ |
| 295 | input.pointer = kzalloc(args.length, GFP_DMA | GFP_KERNEL); |
| 296 | input.length = args.length; |
| 297 | if (!input.pointer) |
| 298 | return -ENOMEM; |
| 299 | phys_addr = virt_to_phys(input.pointer); |
| 300 | memcpy(input.pointer, args.pointer, args.length); |
| 301 | |
| 302 | status = asus_wmi_evaluate_method(ASUS_WMI_METHODID_AGFN, |
| 303 | phys_addr, 0, &retval); |
| 304 | if (!status) |
| 305 | memcpy(args.pointer, input.pointer, args.length); |
| 306 | |
| 307 | kfree(input.pointer); |
| 308 | if (status) |
| 309 | return -ENXIO; |
| 310 | |
| 311 | return retval; |
| 312 | } |
| 313 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 314 | static int asus_wmi_get_devstate(struct asus_wmi *asus, u32 dev_id, u32 *retval) |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 315 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 316 | return asus_wmi_evaluate_method(asus->dsts_id, dev_id, 0, retval); |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | static int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param, |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 320 | u32 *retval) |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 321 | { |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 322 | return asus_wmi_evaluate_method(ASUS_WMI_METHODID_DEVS, dev_id, |
| 323 | ctrl_param, retval); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 324 | } |
| 325 | |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 326 | /* Helper for special devices with magic return codes */ |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 327 | static int asus_wmi_get_devstate_bits(struct asus_wmi *asus, |
| 328 | u32 dev_id, u32 mask) |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 329 | { |
| 330 | u32 retval = 0; |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 331 | int err; |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 332 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 333 | err = asus_wmi_get_devstate(asus, dev_id, &retval); |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 334 | |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 335 | if (err < 0) |
| 336 | return err; |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 337 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 338 | if (!(retval & ASUS_WMI_DSTS_PRESENCE_BIT)) |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 339 | return -ENODEV; |
| 340 | |
Corentin Chary | a75fe0d | 2011-02-26 10:20:34 +0100 | [diff] [blame] | 341 | if (mask == ASUS_WMI_DSTS_STATUS_BIT) { |
| 342 | if (retval & ASUS_WMI_DSTS_UNKNOWN_BIT) |
| 343 | return -ENODEV; |
| 344 | } |
| 345 | |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 346 | return retval & mask; |
| 347 | } |
| 348 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 349 | static int asus_wmi_get_devstate_simple(struct asus_wmi *asus, u32 dev_id) |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 350 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 351 | return asus_wmi_get_devstate_bits(asus, dev_id, |
| 352 | ASUS_WMI_DSTS_STATUS_BIT); |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 353 | } |
| 354 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 355 | /* LEDs ***********************************************************************/ |
| 356 | |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 357 | /* |
| 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 |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 360 | * subsystem asks, we avoid messing with the Asus ACPI stuff during a |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 361 | * potentially bad time, such as a timer interrupt. |
| 362 | */ |
| 363 | static void tpd_led_update(struct work_struct *work) |
| 364 | { |
| 365 | int ctrl_param; |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 366 | struct asus_wmi *asus; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 367 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 368 | asus = container_of(work, struct asus_wmi, tpd_led_work); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 369 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 370 | ctrl_param = asus->tpd_led_wk; |
| 371 | asus_wmi_set_devstate(ASUS_WMI_DEVID_TOUCHPAD_LED, ctrl_param, NULL); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | static void tpd_led_set(struct led_classdev *led_cdev, |
| 375 | enum led_brightness value) |
| 376 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 377 | struct asus_wmi *asus; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 378 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 379 | asus = container_of(led_cdev, struct asus_wmi, tpd_led); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 380 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 381 | asus->tpd_led_wk = !!value; |
| 382 | queue_work(asus->led_workqueue, &asus->tpd_led_work); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 383 | } |
| 384 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 385 | static int read_tpd_led_state(struct asus_wmi *asus) |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 386 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 387 | return asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_TOUCHPAD_LED); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | static enum led_brightness tpd_led_get(struct led_classdev *led_cdev) |
| 391 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 392 | struct asus_wmi *asus; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 393 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 394 | asus = container_of(led_cdev, struct asus_wmi, tpd_led); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 395 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 396 | return read_tpd_led_state(asus); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 397 | } |
| 398 | |
Jian-Hong Pan | 9fe44fc | 2018-09-27 16:50:09 +0800 | [diff] [blame] | 399 | static void kbd_led_update(struct asus_wmi *asus) |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 400 | { |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 401 | int ctrl_param = 0; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 402 | |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 403 | /* |
| 404 | * bits 0-2: level |
| 405 | * bit 7: light on/off |
| 406 | */ |
| 407 | if (asus->kbd_led_wk > 0) |
| 408 | ctrl_param = 0x80 | (asus->kbd_led_wk & 0x7F); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 409 | |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 410 | asus_wmi_set_devstate(ASUS_WMI_DEVID_KBD_BACKLIGHT, ctrl_param, NULL); |
| 411 | } |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 412 | |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 413 | static int kbd_led_read(struct asus_wmi *asus, int *level, int *env) |
| 414 | { |
| 415 | int retval; |
| 416 | |
| 417 | /* |
| 418 | * bits 0-2: level |
| 419 | * bit 7: light on/off |
| 420 | * bit 8-10: environment (0: dark, 1: normal, 2: light) |
| 421 | * bit 17: status unknown |
| 422 | */ |
| 423 | retval = asus_wmi_get_devstate_bits(asus, ASUS_WMI_DEVID_KBD_BACKLIGHT, |
| 424 | 0xFFFF); |
| 425 | |
Corentin Chary | af965e9 | 2011-07-01 11:34:34 +0200 | [diff] [blame] | 426 | /* Unknown status is considered as off */ |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 427 | if (retval == 0x8000) |
Corentin Chary | af965e9 | 2011-07-01 11:34:34 +0200 | [diff] [blame] | 428 | retval = 0; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 429 | |
| 430 | if (retval >= 0) { |
| 431 | if (level) |
Corentin Chary | c09b223 | 2012-03-20 09:53:04 +0100 | [diff] [blame] | 432 | *level = retval & 0x7F; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 433 | if (env) |
| 434 | *env = (retval >> 8) & 0x7F; |
| 435 | retval = 0; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 436 | } |
| 437 | |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 438 | return retval; |
| 439 | } |
| 440 | |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 441 | static void do_kbd_led_set(struct led_classdev *led_cdev, int value) |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 442 | { |
| 443 | struct asus_wmi *asus; |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 444 | int max_level; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 445 | |
| 446 | asus = container_of(led_cdev, struct asus_wmi, kbd_led); |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 447 | max_level = asus->kbd_led.max_brightness; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 448 | |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 449 | if (value > max_level) |
| 450 | value = max_level; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 451 | else if (value < 0) |
| 452 | value = 0; |
| 453 | |
| 454 | asus->kbd_led_wk = value; |
Jian-Hong Pan | 9fe44fc | 2018-09-27 16:50:09 +0800 | [diff] [blame] | 455 | kbd_led_update(asus); |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 456 | } |
| 457 | |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 458 | static void kbd_led_set(struct led_classdev *led_cdev, |
| 459 | enum led_brightness value) |
| 460 | { |
Yurii Pavlovskyi | 3e58167 | 2019-05-14 21:07:46 +0200 | [diff] [blame] | 461 | /* Prevent disabling keyboard backlight on module unregister */ |
| 462 | if (led_cdev->flags & LED_UNREGISTERING) |
| 463 | return; |
| 464 | |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 465 | do_kbd_led_set(led_cdev, value); |
| 466 | } |
| 467 | |
Jian-Hong Pan | 29f6eb5 | 2018-10-22 18:00:04 +0800 | [diff] [blame] | 468 | static void kbd_led_set_by_kbd(struct asus_wmi *asus, enum led_brightness value) |
| 469 | { |
| 470 | struct led_classdev *led_cdev = &asus->kbd_led; |
| 471 | |
| 472 | do_kbd_led_set(led_cdev, value); |
| 473 | led_classdev_notify_brightness_hw_changed(led_cdev, asus->kbd_led_wk); |
| 474 | } |
| 475 | |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 476 | static enum led_brightness kbd_led_get(struct led_classdev *led_cdev) |
| 477 | { |
| 478 | struct asus_wmi *asus; |
| 479 | int retval, value; |
| 480 | |
| 481 | asus = container_of(led_cdev, struct asus_wmi, kbd_led); |
| 482 | |
| 483 | retval = kbd_led_read(asus, &value, NULL); |
| 484 | |
| 485 | if (retval < 0) |
| 486 | return retval; |
| 487 | |
| 488 | return value; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 489 | } |
| 490 | |
AceLan Kao | 6cae06e | 2012-07-27 16:51:59 +0800 | [diff] [blame] | 491 | static int wlan_led_unknown_state(struct asus_wmi *asus) |
| 492 | { |
| 493 | u32 result; |
| 494 | |
| 495 | asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WIRELESS_LED, &result); |
| 496 | |
| 497 | return result & ASUS_WMI_DSTS_UNKNOWN_BIT; |
| 498 | } |
| 499 | |
| 500 | static int wlan_led_presence(struct asus_wmi *asus) |
| 501 | { |
| 502 | u32 result; |
| 503 | |
| 504 | asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WIRELESS_LED, &result); |
| 505 | |
| 506 | return result & ASUS_WMI_DSTS_PRESENCE_BIT; |
| 507 | } |
| 508 | |
| 509 | static void wlan_led_update(struct work_struct *work) |
| 510 | { |
| 511 | int ctrl_param; |
| 512 | struct asus_wmi *asus; |
| 513 | |
| 514 | asus = container_of(work, struct asus_wmi, wlan_led_work); |
| 515 | |
| 516 | ctrl_param = asus->wlan_led_wk; |
| 517 | asus_wmi_set_devstate(ASUS_WMI_DEVID_WIRELESS_LED, ctrl_param, NULL); |
| 518 | } |
| 519 | |
| 520 | static void wlan_led_set(struct led_classdev *led_cdev, |
| 521 | enum led_brightness value) |
| 522 | { |
| 523 | struct asus_wmi *asus; |
| 524 | |
| 525 | asus = container_of(led_cdev, struct asus_wmi, wlan_led); |
| 526 | |
| 527 | asus->wlan_led_wk = !!value; |
| 528 | queue_work(asus->led_workqueue, &asus->wlan_led_work); |
| 529 | } |
| 530 | |
| 531 | static enum led_brightness wlan_led_get(struct led_classdev *led_cdev) |
| 532 | { |
| 533 | struct asus_wmi *asus; |
| 534 | u32 result; |
| 535 | |
| 536 | asus = container_of(led_cdev, struct asus_wmi, wlan_led); |
| 537 | asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WIRELESS_LED, &result); |
| 538 | |
| 539 | return result & ASUS_WMI_DSTS_BRIGHTNESS_MASK; |
| 540 | } |
| 541 | |
Maxime Bellengé | 4c05984 | 2017-09-23 18:23:37 +0200 | [diff] [blame] | 542 | static void lightbar_led_update(struct work_struct *work) |
| 543 | { |
| 544 | struct asus_wmi *asus; |
| 545 | int ctrl_param; |
| 546 | |
| 547 | asus = container_of(work, struct asus_wmi, lightbar_led_work); |
| 548 | |
| 549 | ctrl_param = asus->lightbar_led_wk; |
| 550 | asus_wmi_set_devstate(ASUS_WMI_DEVID_LIGHTBAR, ctrl_param, NULL); |
| 551 | } |
| 552 | |
| 553 | static void lightbar_led_set(struct led_classdev *led_cdev, |
| 554 | enum led_brightness value) |
| 555 | { |
| 556 | struct asus_wmi *asus; |
| 557 | |
| 558 | asus = container_of(led_cdev, struct asus_wmi, lightbar_led); |
| 559 | |
| 560 | asus->lightbar_led_wk = !!value; |
| 561 | queue_work(asus->led_workqueue, &asus->lightbar_led_work); |
| 562 | } |
| 563 | |
| 564 | static enum led_brightness lightbar_led_get(struct led_classdev *led_cdev) |
| 565 | { |
| 566 | struct asus_wmi *asus; |
| 567 | u32 result; |
| 568 | |
| 569 | asus = container_of(led_cdev, struct asus_wmi, lightbar_led); |
| 570 | asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_LIGHTBAR, &result); |
| 571 | |
| 572 | return result & ASUS_WMI_DSTS_LIGHTBAR_MASK; |
| 573 | } |
| 574 | |
| 575 | static int lightbar_led_presence(struct asus_wmi *asus) |
| 576 | { |
| 577 | u32 result; |
| 578 | |
| 579 | asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_LIGHTBAR, &result); |
| 580 | |
| 581 | return result & ASUS_WMI_DSTS_PRESENCE_BIT; |
| 582 | } |
| 583 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 584 | static void asus_wmi_led_exit(struct asus_wmi *asus) |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 585 | { |
Axel Lin | e929802 | 2011-08-08 17:16:01 +0800 | [diff] [blame] | 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)) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 589 | led_classdev_unregister(&asus->tpd_led); |
AceLan Kao | 6cae06e | 2012-07-27 16:51:59 +0800 | [diff] [blame] | 590 | if (!IS_ERR_OR_NULL(asus->wlan_led.dev)) |
| 591 | led_classdev_unregister(&asus->wlan_led); |
Maxime Bellengé | 4c05984 | 2017-09-23 18:23:37 +0200 | [diff] [blame] | 592 | if (!IS_ERR_OR_NULL(asus->lightbar_led.dev)) |
| 593 | led_classdev_unregister(&asus->lightbar_led); |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 594 | if (asus->led_workqueue) |
| 595 | destroy_workqueue(asus->led_workqueue); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 596 | } |
| 597 | |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 598 | static int asus_wmi_led_init(struct asus_wmi *asus) |
| 599 | { |
Oleksij Rempel | 3073404 | 2015-09-14 11:16:30 +0200 | [diff] [blame] | 600 | int rv = 0, led_val; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 601 | |
| 602 | asus->led_workqueue = create_singlethread_workqueue("led_workqueue"); |
| 603 | if (!asus->led_workqueue) |
| 604 | return -ENOMEM; |
| 605 | |
| 606 | if (read_tpd_led_state(asus) >= 0) { |
| 607 | INIT_WORK(&asus->tpd_led_work, tpd_led_update); |
| 608 | |
| 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; |
| 613 | |
| 614 | rv = led_classdev_register(&asus->platform_device->dev, |
| 615 | &asus->tpd_led); |
| 616 | if (rv) |
| 617 | goto error; |
| 618 | } |
| 619 | |
Yurii Pavlovskyi | 8853a2f | 2019-05-14 20:51:25 +0200 | [diff] [blame] | 620 | if (!kbd_led_read(asus, &led_val, NULL)) { |
Oleksij Rempel | 3073404 | 2015-09-14 11:16:30 +0200 | [diff] [blame] | 621 | asus->kbd_led_wk = led_val; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 622 | asus->kbd_led.name = "asus::kbd_backlight"; |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 623 | asus->kbd_led.flags = LED_BRIGHT_HW_CHANGED; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 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; |
| 627 | |
| 628 | rv = led_classdev_register(&asus->platform_device->dev, |
| 629 | &asus->kbd_led); |
AceLan Kao | 6cae06e | 2012-07-27 16:51:59 +0800 | [diff] [blame] | 630 | if (rv) |
| 631 | goto error; |
| 632 | } |
| 633 | |
AceLan Kao | f515623 | 2014-07-09 16:18:18 +0800 | [diff] [blame] | 634 | if (wlan_led_presence(asus) && (asus->driver->quirks->wapf > 0)) { |
AceLan Kao | 6cae06e | 2012-07-27 16:51:59 +0800 | [diff] [blame] | 635 | INIT_WORK(&asus->wlan_led_work, wlan_led_update); |
| 636 | |
| 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"; |
| 644 | |
| 645 | rv = led_classdev_register(&asus->platform_device->dev, |
| 646 | &asus->wlan_led); |
Maxime Bellengé | 4c05984 | 2017-09-23 18:23:37 +0200 | [diff] [blame] | 647 | if (rv) |
| 648 | goto error; |
| 649 | } |
| 650 | |
| 651 | if (lightbar_led_presence(asus)) { |
| 652 | INIT_WORK(&asus->lightbar_led_work, lightbar_led_update); |
| 653 | |
| 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; |
| 658 | |
| 659 | rv = led_classdev_register(&asus->platform_device->dev, |
| 660 | &asus->lightbar_led); |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | error: |
| 664 | if (rv) |
| 665 | asus_wmi_led_exit(asus); |
| 666 | |
| 667 | return rv; |
| 668 | } |
| 669 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 670 | /* RF *************************************************************************/ |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 671 | |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 672 | /* |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 673 | * PCI hotplug (for wlan rfkill) |
| 674 | */ |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 675 | static bool asus_wlan_rfkill_blocked(struct asus_wmi *asus) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 676 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 677 | int result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WLAN); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 678 | |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 679 | if (result < 0) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 680 | return false; |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 681 | return !result; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 682 | } |
| 683 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 684 | static void asus_rfkill_hotplug(struct asus_wmi *asus) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 685 | { |
| 686 | struct pci_dev *dev; |
| 687 | struct pci_bus *bus; |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 688 | bool blocked; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 689 | bool absent; |
| 690 | u32 l; |
| 691 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 692 | mutex_lock(&asus->wmi_lock); |
| 693 | blocked = asus_wlan_rfkill_blocked(asus); |
| 694 | mutex_unlock(&asus->wmi_lock); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 695 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 696 | mutex_lock(&asus->hotplug_lock); |
Rafael J. Wysocki | 8b9ec1d | 2014-01-10 15:27:08 +0100 | [diff] [blame] | 697 | pci_lock_rescan_remove(); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 698 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 699 | if (asus->wlan.rfkill) |
| 700 | rfkill_set_sw_state(asus->wlan.rfkill, blocked); |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 701 | |
Lukas Wunner | 125450f | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 702 | if (asus->hotplug_slot.ops) { |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 703 | bus = pci_find_bus(0, 1); |
| 704 | if (!bus) { |
Joe Perches | 5ad77dc | 2011-03-29 15:21:35 -0700 | [diff] [blame] | 705 | pr_warn("Unable to find PCI bus 1?\n"); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 706 | goto out_unlock; |
| 707 | } |
| 708 | |
| 709 | if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) { |
| 710 | pr_err("Unable to read PCI config space?\n"); |
| 711 | goto out_unlock; |
| 712 | } |
| 713 | absent = (l == 0xffffffff); |
| 714 | |
| 715 | if (blocked != absent) { |
Joe Perches | 5ad77dc | 2011-03-29 15:21:35 -0700 | [diff] [blame] | 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"); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 722 | goto out_unlock; |
| 723 | } |
| 724 | |
| 725 | if (!blocked) { |
| 726 | dev = pci_get_slot(bus, 0); |
| 727 | if (dev) { |
| 728 | /* Device already present */ |
| 729 | pci_dev_put(dev); |
| 730 | goto out_unlock; |
| 731 | } |
| 732 | dev = pci_scan_single_device(bus, 0); |
| 733 | if (dev) { |
| 734 | pci_bus_assign_resources(bus); |
Yijing Wang | c893d13 | 2014-05-30 11:01:03 +0800 | [diff] [blame] | 735 | pci_bus_add_device(dev); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 736 | } |
| 737 | } else { |
| 738 | dev = pci_get_slot(bus, 0); |
| 739 | if (dev) { |
Yinghai Lu | 210647a | 2012-02-25 13:54:20 -0800 | [diff] [blame] | 740 | pci_stop_and_remove_bus_device(dev); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 741 | pci_dev_put(dev); |
| 742 | } |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | out_unlock: |
Rafael J. Wysocki | 8b9ec1d | 2014-01-10 15:27:08 +0100 | [diff] [blame] | 747 | pci_unlock_rescan_remove(); |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 748 | mutex_unlock(&asus->hotplug_lock); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 749 | } |
| 750 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 751 | static void asus_rfkill_notify(acpi_handle handle, u32 event, void *data) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 752 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 753 | struct asus_wmi *asus = data; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 754 | |
| 755 | if (event != ACPI_NOTIFY_BUS_CHECK) |
| 756 | return; |
| 757 | |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 758 | /* |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 759 | * We can't call directly asus_rfkill_hotplug because most |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 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 |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 762 | * method to be serialized, we schedule a asus_rfkill_hotplug |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 763 | * call later, in a safer context. |
| 764 | */ |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 765 | queue_work(asus->hotplug_workqueue, &asus->hotplug_work); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 766 | } |
| 767 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 768 | static int asus_register_rfkill_notifier(struct asus_wmi *asus, char *node) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 769 | { |
| 770 | acpi_status status; |
| 771 | acpi_handle handle; |
| 772 | |
| 773 | status = acpi_get_handle(NULL, node, &handle); |
| 774 | |
| 775 | if (ACPI_SUCCESS(status)) { |
| 776 | status = acpi_install_notify_handler(handle, |
| 777 | ACPI_SYSTEM_NOTIFY, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 778 | asus_rfkill_notify, asus); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 779 | if (ACPI_FAILURE(status)) |
Joe Perches | 5ad77dc | 2011-03-29 15:21:35 -0700 | [diff] [blame] | 780 | pr_warn("Failed to register notify on %s\n", node); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 781 | } else |
| 782 | return -ENODEV; |
| 783 | |
| 784 | return 0; |
| 785 | } |
| 786 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 787 | static void asus_unregister_rfkill_notifier(struct asus_wmi *asus, char *node) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 788 | { |
| 789 | acpi_status status = AE_OK; |
| 790 | acpi_handle handle; |
| 791 | |
| 792 | status = acpi_get_handle(NULL, node, &handle); |
| 793 | |
| 794 | if (ACPI_SUCCESS(status)) { |
| 795 | status = acpi_remove_notify_handler(handle, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 796 | ACPI_SYSTEM_NOTIFY, |
| 797 | asus_rfkill_notify); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 798 | if (ACPI_FAILURE(status)) |
| 799 | pr_err("Error removing rfkill notify handler %s\n", |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 800 | node); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 804 | static int asus_get_adapter_status(struct hotplug_slot *hotplug_slot, |
| 805 | u8 *value) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 806 | { |
Lukas Wunner | 125450f | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 807 | struct asus_wmi *asus = container_of(hotplug_slot, |
| 808 | struct asus_wmi, hotplug_slot); |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 809 | int result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WLAN); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 810 | |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 811 | if (result < 0) |
| 812 | return result; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 813 | |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 814 | *value = !!result; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 815 | return 0; |
| 816 | } |
| 817 | |
Lukas Wunner | 81c4b5b | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 818 | static const struct hotplug_slot_ops asus_hotplug_slot_ops = { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 819 | .get_adapter_status = asus_get_adapter_status, |
| 820 | .get_power_status = asus_get_adapter_status, |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 821 | }; |
| 822 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 823 | static void asus_hotplug_work(struct work_struct *work) |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 824 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 825 | struct asus_wmi *asus; |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 826 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 827 | asus = container_of(work, struct asus_wmi, hotplug_work); |
| 828 | asus_rfkill_hotplug(asus); |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 829 | } |
| 830 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 831 | static int asus_setup_pci_hotplug(struct asus_wmi *asus) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 832 | { |
| 833 | int ret = -ENOMEM; |
| 834 | struct pci_bus *bus = pci_find_bus(0, 1); |
| 835 | |
| 836 | if (!bus) { |
| 837 | pr_err("Unable to find wifi PCI bus\n"); |
| 838 | return -ENODEV; |
| 839 | } |
| 840 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 841 | asus->hotplug_workqueue = |
| 842 | create_singlethread_workqueue("hotplug_workqueue"); |
| 843 | if (!asus->hotplug_workqueue) |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 844 | goto error_workqueue; |
| 845 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 846 | INIT_WORK(&asus->hotplug_work, asus_hotplug_work); |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 847 | |
Lukas Wunner | 125450f | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 848 | asus->hotplug_slot.ops = &asus_hotplug_slot_ops; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 849 | |
Lukas Wunner | 125450f | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 850 | ret = pci_hp_register(&asus->hotplug_slot, bus, 0, "asus-wifi"); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 851 | if (ret) { |
| 852 | pr_err("Unable to register hotplug slot - %d\n", ret); |
| 853 | goto error_register; |
| 854 | } |
| 855 | |
| 856 | return 0; |
| 857 | |
| 858 | error_register: |
Lukas Wunner | 125450f | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 859 | asus->hotplug_slot.ops = NULL; |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 860 | destroy_workqueue(asus->hotplug_workqueue); |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 861 | error_workqueue: |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 862 | return ret; |
| 863 | } |
| 864 | |
| 865 | /* |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 866 | * Rfkill devices |
| 867 | */ |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 868 | static int asus_rfkill_set(void *data, bool blocked) |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 869 | { |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 870 | struct asus_rfkill *priv = data; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 871 | u32 ctrl_param = !blocked; |
AceLan Kao | a50bd12 | 2012-07-26 17:13:31 +0800 | [diff] [blame] | 872 | u32 dev_id = priv->dev_id; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 873 | |
AceLan Kao | a50bd12 | 2012-07-26 17:13:31 +0800 | [diff] [blame] | 874 | /* |
| 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. |
| 881 | */ |
| 882 | if ((dev_id == ASUS_WMI_DEVID_WLAN) && |
| 883 | priv->asus->driver->wlan_ctrl_by_user) |
| 884 | dev_id = ASUS_WMI_DEVID_WLAN_LED; |
| 885 | |
| 886 | return asus_wmi_set_devstate(dev_id, ctrl_param, NULL); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 887 | } |
| 888 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 889 | static void asus_rfkill_query(struct rfkill *rfkill, void *data) |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 890 | { |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 891 | struct asus_rfkill *priv = data; |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 892 | int result; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 893 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 894 | result = asus_wmi_get_devstate_simple(priv->asus, priv->dev_id); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 895 | |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 896 | if (result < 0) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 897 | return; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 898 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 899 | rfkill_set_sw_state(priv->rfkill, !result); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 900 | } |
| 901 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 902 | static int asus_rfkill_wlan_set(void *data, bool blocked) |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 903 | { |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 904 | struct asus_rfkill *priv = data; |
| 905 | struct asus_wmi *asus = priv->asus; |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 906 | int ret; |
| 907 | |
| 908 | /* |
| 909 | * This handler is enabled only if hotplug is enabled. |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 910 | * In this case, the asus_wmi_set_devstate() will |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 911 | * trigger a wmi notification and we need to wait |
| 912 | * this call to finish before being able to call |
| 913 | * any wmi method |
| 914 | */ |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 915 | mutex_lock(&asus->wmi_lock); |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 916 | ret = asus_rfkill_set(data, blocked); |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 917 | mutex_unlock(&asus->wmi_lock); |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 918 | return ret; |
| 919 | } |
| 920 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 921 | static const struct rfkill_ops asus_rfkill_wlan_ops = { |
| 922 | .set_block = asus_rfkill_wlan_set, |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 923 | .query = asus_rfkill_query, |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 924 | }; |
| 925 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 926 | static const struct rfkill_ops asus_rfkill_ops = { |
| 927 | .set_block = asus_rfkill_set, |
| 928 | .query = asus_rfkill_query, |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 929 | }; |
| 930 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 931 | static int asus_new_rfkill(struct asus_wmi *asus, |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 932 | struct asus_rfkill *arfkill, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 933 | const char *name, enum rfkill_type type, int dev_id) |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 934 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 935 | int result = asus_wmi_get_devstate_simple(asus, dev_id); |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 936 | struct rfkill **rfkill = &arfkill->rfkill; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 937 | |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 938 | if (result < 0) |
| 939 | return result; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 940 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 941 | arfkill->dev_id = dev_id; |
| 942 | arfkill->asus = asus; |
| 943 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 944 | if (dev_id == ASUS_WMI_DEVID_WLAN && |
| 945 | asus->driver->quirks->hotplug_wireless) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 946 | *rfkill = rfkill_alloc(name, &asus->platform_device->dev, type, |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 947 | &asus_rfkill_wlan_ops, arfkill); |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 948 | else |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 949 | *rfkill = rfkill_alloc(name, &asus->platform_device->dev, type, |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 950 | &asus_rfkill_ops, arfkill); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 951 | |
| 952 | if (!*rfkill) |
| 953 | return -EINVAL; |
| 954 | |
AceLan Kao | e8f56c8 | 2013-05-30 10:31:50 +0800 | [diff] [blame] | 955 | if ((dev_id == ASUS_WMI_DEVID_WLAN) && |
AceLan Kao | f515623 | 2014-07-09 16:18:18 +0800 | [diff] [blame] | 956 | (asus->driver->quirks->wapf > 0)) |
AceLan Kao | 6cae06e | 2012-07-27 16:51:59 +0800 | [diff] [blame] | 957 | rfkill_set_led_trigger_name(*rfkill, "asus-wlan"); |
| 958 | |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 959 | rfkill_init_sw_state(*rfkill, !result); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 960 | result = rfkill_register(*rfkill); |
| 961 | if (result) { |
| 962 | rfkill_destroy(*rfkill); |
| 963 | *rfkill = NULL; |
| 964 | return result; |
| 965 | } |
| 966 | return 0; |
| 967 | } |
| 968 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 969 | static void asus_wmi_rfkill_exit(struct asus_wmi *asus) |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 970 | { |
João Paulo Rechi Vita | cf48bf9 | 2018-05-22 14:30:15 -0700 | [diff] [blame] | 971 | if (asus->driver->wlan_ctrl_by_user && ashs_present()) |
| 972 | return; |
| 973 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 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"); |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 977 | if (asus->wlan.rfkill) { |
| 978 | rfkill_unregister(asus->wlan.rfkill); |
| 979 | rfkill_destroy(asus->wlan.rfkill); |
| 980 | asus->wlan.rfkill = NULL; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 981 | } |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 982 | /* |
| 983 | * Refresh pci hotplug in case the rfkill state was changed after |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 984 | * asus_unregister_rfkill_notifier() |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 985 | */ |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 986 | asus_rfkill_hotplug(asus); |
Lukas Wunner | 125450f | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 987 | if (asus->hotplug_slot.ops) |
| 988 | pci_hp_deregister(&asus->hotplug_slot); |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 989 | if (asus->hotplug_workqueue) |
| 990 | destroy_workqueue(asus->hotplug_workqueue); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 991 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 992 | if (asus->bluetooth.rfkill) { |
| 993 | rfkill_unregister(asus->bluetooth.rfkill); |
| 994 | rfkill_destroy(asus->bluetooth.rfkill); |
| 995 | asus->bluetooth.rfkill = NULL; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 996 | } |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 997 | if (asus->wimax.rfkill) { |
| 998 | rfkill_unregister(asus->wimax.rfkill); |
| 999 | rfkill_destroy(asus->wimax.rfkill); |
| 1000 | asus->wimax.rfkill = NULL; |
Corentin Chary | 2e9e159 | 2011-02-06 13:28:37 +0100 | [diff] [blame] | 1001 | } |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1002 | if (asus->wwan3g.rfkill) { |
| 1003 | rfkill_unregister(asus->wwan3g.rfkill); |
| 1004 | rfkill_destroy(asus->wwan3g.rfkill); |
| 1005 | asus->wwan3g.rfkill = NULL; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1006 | } |
Corentin Chary | 43be8bd | 2011-07-01 11:34:40 +0200 | [diff] [blame] | 1007 | if (asus->gps.rfkill) { |
| 1008 | rfkill_unregister(asus->gps.rfkill); |
| 1009 | rfkill_destroy(asus->gps.rfkill); |
| 1010 | asus->gps.rfkill = NULL; |
| 1011 | } |
Corentin Chary | a912d32 | 2011-07-01 11:34:41 +0200 | [diff] [blame] | 1012 | if (asus->uwb.rfkill) { |
| 1013 | rfkill_unregister(asus->uwb.rfkill); |
| 1014 | rfkill_destroy(asus->uwb.rfkill); |
| 1015 | asus->uwb.rfkill = NULL; |
| 1016 | } |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1017 | } |
| 1018 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1019 | static int asus_wmi_rfkill_init(struct asus_wmi *asus) |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1020 | { |
| 1021 | int result = 0; |
| 1022 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1023 | mutex_init(&asus->hotplug_lock); |
| 1024 | mutex_init(&asus->wmi_lock); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1025 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1026 | result = asus_new_rfkill(asus, &asus->wlan, "asus-wlan", |
| 1027 | RFKILL_TYPE_WLAN, ASUS_WMI_DEVID_WLAN); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1028 | |
| 1029 | if (result && result != -ENODEV) |
| 1030 | goto exit; |
| 1031 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1032 | result = asus_new_rfkill(asus, &asus->bluetooth, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1033 | "asus-bluetooth", RFKILL_TYPE_BLUETOOTH, |
| 1034 | ASUS_WMI_DEVID_BLUETOOTH); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1035 | |
| 1036 | if (result && result != -ENODEV) |
| 1037 | goto exit; |
| 1038 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1039 | result = asus_new_rfkill(asus, &asus->wimax, "asus-wimax", |
| 1040 | RFKILL_TYPE_WIMAX, ASUS_WMI_DEVID_WIMAX); |
Corentin Chary | 2e9e159 | 2011-02-06 13:28:37 +0100 | [diff] [blame] | 1041 | |
| 1042 | if (result && result != -ENODEV) |
| 1043 | goto exit; |
| 1044 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1045 | result = asus_new_rfkill(asus, &asus->wwan3g, "asus-wwan3g", |
| 1046 | RFKILL_TYPE_WWAN, ASUS_WMI_DEVID_WWAN3G); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1047 | |
| 1048 | if (result && result != -ENODEV) |
| 1049 | goto exit; |
| 1050 | |
Corentin Chary | 43be8bd | 2011-07-01 11:34:40 +0200 | [diff] [blame] | 1051 | result = asus_new_rfkill(asus, &asus->gps, "asus-gps", |
| 1052 | RFKILL_TYPE_GPS, ASUS_WMI_DEVID_GPS); |
| 1053 | |
| 1054 | if (result && result != -ENODEV) |
| 1055 | goto exit; |
| 1056 | |
Corentin Chary | a912d32 | 2011-07-01 11:34:41 +0200 | [diff] [blame] | 1057 | result = asus_new_rfkill(asus, &asus->uwb, "asus-uwb", |
| 1058 | RFKILL_TYPE_UWB, ASUS_WMI_DEVID_UWB); |
| 1059 | |
| 1060 | if (result && result != -ENODEV) |
| 1061 | goto exit; |
| 1062 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 1063 | if (!asus->driver->quirks->hotplug_wireless) |
Corentin Chary | c14d4b8 | 2011-02-06 13:28:40 +0100 | [diff] [blame] | 1064 | goto exit; |
| 1065 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1066 | result = asus_setup_pci_hotplug(asus); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1067 | /* |
| 1068 | * If we get -EBUSY then something else is handling the PCI hotplug - |
| 1069 | * don't fail in this case |
| 1070 | */ |
| 1071 | if (result == -EBUSY) |
| 1072 | result = 0; |
| 1073 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 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"); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1077 | /* |
| 1078 | * Refresh pci hotplug in case the rfkill state was changed during |
| 1079 | * setup. |
| 1080 | */ |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1081 | asus_rfkill_hotplug(asus); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1082 | |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1083 | exit: |
| 1084 | if (result && result != -ENODEV) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1085 | asus_wmi_rfkill_exit(asus); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1086 | |
| 1087 | if (result == -ENODEV) |
| 1088 | result = 0; |
| 1089 | |
| 1090 | return result; |
| 1091 | } |
| 1092 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 1093 | /* Quirks *********************************************************************/ |
| 1094 | |
Kai-Chuan Hsieh | 8023eff | 2016-09-01 23:55:55 +0800 | [diff] [blame] | 1095 | static void asus_wmi_set_xusb2pr(struct asus_wmi *asus) |
| 1096 | { |
| 1097 | struct pci_dev *xhci_pdev; |
| 1098 | u32 orig_ports_available; |
| 1099 | u32 ports_available = asus->driver->quirks->xusb2pr; |
| 1100 | |
| 1101 | xhci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 1102 | PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI, |
| 1103 | NULL); |
| 1104 | |
| 1105 | if (!xhci_pdev) |
| 1106 | return; |
| 1107 | |
| 1108 | pci_read_config_dword(xhci_pdev, USB_INTEL_XUSB2PR, |
| 1109 | &orig_ports_available); |
| 1110 | |
| 1111 | pci_write_config_dword(xhci_pdev, USB_INTEL_XUSB2PR, |
| 1112 | cpu_to_le32(ports_available)); |
| 1113 | |
| 1114 | pr_info("set USB_INTEL_XUSB2PR old: 0x%04x, new: 0x%04x\n", |
| 1115 | orig_ports_available, ports_available); |
| 1116 | } |
| 1117 | |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1118 | /* |
Oleksij Rempel | e9b6151 | 2017-04-28 16:19:49 +0200 | [diff] [blame] | 1119 | * Some devices dont support or have borcken get_als method |
| 1120 | * but still support set method. |
| 1121 | */ |
| 1122 | static void asus_wmi_set_als(void) |
| 1123 | { |
| 1124 | asus_wmi_set_devstate(ASUS_WMI_DEVID_ALS_ENABLE, 1, NULL); |
| 1125 | } |
| 1126 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 1127 | /* Hwmon device ***************************************************************/ |
| 1128 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1129 | static int asus_hwmon_agfn_fan_speed_read(struct asus_wmi *asus, int fan, |
| 1130 | int *speed) |
| 1131 | { |
| 1132 | struct fan_args args = { |
| 1133 | .agfn.len = sizeof(args), |
| 1134 | .agfn.mfun = ASUS_FAN_MFUN, |
| 1135 | .agfn.sfun = ASUS_FAN_SFUN_READ, |
| 1136 | .fan = fan, |
| 1137 | .speed = 0, |
| 1138 | }; |
| 1139 | struct acpi_buffer input = { (acpi_size) sizeof(args), &args }; |
| 1140 | int status; |
| 1141 | |
| 1142 | if (fan != 1) |
| 1143 | return -EINVAL; |
| 1144 | |
| 1145 | status = asus_wmi_evaluate_method_agfn(input); |
| 1146 | |
| 1147 | if (status || args.agfn.err) |
| 1148 | return -ENXIO; |
| 1149 | |
| 1150 | if (speed) |
| 1151 | *speed = args.speed; |
| 1152 | |
| 1153 | return 0; |
| 1154 | } |
| 1155 | |
| 1156 | static int asus_hwmon_agfn_fan_speed_write(struct asus_wmi *asus, int fan, |
| 1157 | int *speed) |
| 1158 | { |
| 1159 | struct fan_args args = { |
| 1160 | .agfn.len = sizeof(args), |
| 1161 | .agfn.mfun = ASUS_FAN_MFUN, |
| 1162 | .agfn.sfun = ASUS_FAN_SFUN_WRITE, |
| 1163 | .fan = fan, |
| 1164 | .speed = speed ? *speed : 0, |
| 1165 | }; |
| 1166 | struct acpi_buffer input = { (acpi_size) sizeof(args), &args }; |
| 1167 | int status; |
| 1168 | |
| 1169 | /* 1: for setting 1st fan's speed 0: setting auto mode */ |
| 1170 | if (fan != 1 && fan != 0) |
| 1171 | return -EINVAL; |
| 1172 | |
| 1173 | status = asus_wmi_evaluate_method_agfn(input); |
| 1174 | |
| 1175 | if (status || args.agfn.err) |
| 1176 | return -ENXIO; |
| 1177 | |
| 1178 | if (speed && fan == 1) |
| 1179 | asus->asus_hwmon_pwm = *speed; |
| 1180 | |
| 1181 | return 0; |
| 1182 | } |
| 1183 | |
| 1184 | /* |
| 1185 | * Check if we can read the speed of one fan. If true we assume we can also |
| 1186 | * control it. |
| 1187 | */ |
| 1188 | static int asus_hwmon_get_fan_number(struct asus_wmi *asus, int *num_fans) |
| 1189 | { |
| 1190 | int status; |
| 1191 | int speed = 0; |
| 1192 | |
| 1193 | *num_fans = 0; |
| 1194 | |
| 1195 | status = asus_hwmon_agfn_fan_speed_read(asus, 1, &speed); |
| 1196 | if (!status) |
| 1197 | *num_fans = 1; |
| 1198 | |
| 1199 | return 0; |
| 1200 | } |
| 1201 | |
| 1202 | static int asus_hwmon_fan_set_auto(struct asus_wmi *asus) |
| 1203 | { |
| 1204 | int status; |
| 1205 | |
| 1206 | status = asus_hwmon_agfn_fan_speed_write(asus, 0, NULL); |
| 1207 | if (status) |
| 1208 | return -ENXIO; |
| 1209 | |
| 1210 | asus->asus_hwmon_fan_manual_mode = false; |
| 1211 | |
| 1212 | return 0; |
| 1213 | } |
| 1214 | |
| 1215 | static int asus_hwmon_fan_rpm_show(struct device *dev, int fan) |
| 1216 | { |
| 1217 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 1218 | int value; |
| 1219 | int ret; |
| 1220 | |
| 1221 | /* no speed readable on manual mode */ |
| 1222 | if (asus->asus_hwmon_fan_manual_mode) |
| 1223 | return -ENXIO; |
| 1224 | |
| 1225 | ret = asus_hwmon_agfn_fan_speed_read(asus, fan+1, &value); |
| 1226 | if (ret) { |
| 1227 | pr_warn("reading fan speed failed: %d\n", ret); |
| 1228 | return -ENXIO; |
| 1229 | } |
| 1230 | |
| 1231 | return value; |
| 1232 | } |
| 1233 | |
| 1234 | static void asus_hwmon_pwm_show(struct asus_wmi *asus, int fan, int *value) |
| 1235 | { |
| 1236 | int err; |
| 1237 | |
| 1238 | if (asus->asus_hwmon_pwm >= 0) { |
| 1239 | *value = asus->asus_hwmon_pwm; |
| 1240 | return; |
| 1241 | } |
| 1242 | |
| 1243 | err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FAN_CTRL, value); |
| 1244 | if (err < 0) |
| 1245 | return; |
| 1246 | |
| 1247 | *value &= 0xFF; |
| 1248 | |
| 1249 | if (*value == 1) /* Low Speed */ |
| 1250 | *value = 85; |
| 1251 | else if (*value == 2) |
| 1252 | *value = 170; |
| 1253 | else if (*value == 3) |
| 1254 | *value = 255; |
| 1255 | else if (*value) { |
| 1256 | pr_err("Unknown fan speed %#x\n", *value); |
| 1257 | *value = -1; |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | static ssize_t pwm1_show(struct device *dev, |
Corentin Chary | 49979d0 | 2011-07-01 11:34:26 +0200 | [diff] [blame] | 1262 | struct device_attribute *attr, |
| 1263 | char *buf) |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1264 | { |
| 1265 | struct asus_wmi *asus = dev_get_drvdata(dev); |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1266 | int value; |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1267 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1268 | asus_hwmon_pwm_show(asus, 0, &value); |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1269 | |
| 1270 | return sprintf(buf, "%d\n", value); |
| 1271 | } |
| 1272 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 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); |
| 1277 | int value; |
| 1278 | int state; |
| 1279 | int ret; |
| 1280 | |
| 1281 | ret = kstrtouint(buf, 10, &value); |
| 1282 | |
| 1283 | if (ret) |
| 1284 | return ret; |
| 1285 | |
| 1286 | value = clamp(value, 0, 255); |
| 1287 | |
| 1288 | state = asus_hwmon_agfn_fan_speed_write(asus, 1, &value); |
| 1289 | if (state) |
| 1290 | pr_warn("Setting fan speed failed: %d\n", state); |
| 1291 | else |
| 1292 | asus->asus_hwmon_fan_manual_mode = true; |
| 1293 | |
| 1294 | return count; |
| 1295 | } |
| 1296 | |
| 1297 | static ssize_t fan1_input_show(struct device *dev, |
| 1298 | struct device_attribute *attr, |
| 1299 | char *buf) |
| 1300 | { |
| 1301 | int value = asus_hwmon_fan_rpm_show(dev, 0); |
| 1302 | |
| 1303 | return sprintf(buf, "%d\n", value < 0 ? -1 : value*100); |
| 1304 | |
| 1305 | } |
| 1306 | |
| 1307 | static ssize_t pwm1_enable_show(struct device *dev, |
| 1308 | struct device_attribute *attr, |
| 1309 | char *buf) |
| 1310 | { |
| 1311 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 1312 | |
| 1313 | if (asus->asus_hwmon_fan_manual_mode) |
| 1314 | return sprintf(buf, "%d\n", ASUS_FAN_CTRL_MANUAL); |
| 1315 | |
| 1316 | return sprintf(buf, "%d\n", ASUS_FAN_CTRL_AUTO); |
| 1317 | } |
| 1318 | |
| 1319 | static ssize_t pwm1_enable_store(struct device *dev, |
| 1320 | struct device_attribute *attr, |
| 1321 | const char *buf, size_t count) |
| 1322 | { |
| 1323 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 1324 | int status = 0; |
| 1325 | int state; |
| 1326 | int ret; |
| 1327 | |
| 1328 | ret = kstrtouint(buf, 10, &state); |
| 1329 | |
| 1330 | if (ret) |
| 1331 | return ret; |
| 1332 | |
| 1333 | if (state == ASUS_FAN_CTRL_MANUAL) |
| 1334 | asus->asus_hwmon_fan_manual_mode = true; |
| 1335 | else |
| 1336 | status = asus_hwmon_fan_set_auto(asus); |
| 1337 | |
| 1338 | if (status) |
| 1339 | return status; |
| 1340 | |
| 1341 | return count; |
| 1342 | } |
| 1343 | |
| 1344 | static ssize_t fan1_label_show(struct device *dev, |
| 1345 | struct device_attribute *attr, |
| 1346 | char *buf) |
| 1347 | { |
| 1348 | return sprintf(buf, "%s\n", ASUS_FAN_DESC); |
| 1349 | } |
| 1350 | |
Corentin Chary | 6118b8a | 2011-07-01 11:34:36 +0200 | [diff] [blame] | 1351 | static ssize_t asus_hwmon_temp1(struct device *dev, |
| 1352 | struct device_attribute *attr, |
| 1353 | char *buf) |
| 1354 | { |
| 1355 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 1356 | u32 value; |
| 1357 | int err; |
| 1358 | |
| 1359 | err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_THERMAL_CTRL, &value); |
| 1360 | |
| 1361 | if (err < 0) |
| 1362 | return err; |
| 1363 | |
Rasmus Villemoes | e866a2e | 2015-10-01 23:45:31 +0200 | [diff] [blame] | 1364 | value = DECI_KELVIN_TO_CELSIUS((value & 0xFFFF)) * 1000; |
Corentin Chary | 6118b8a | 2011-07-01 11:34:36 +0200 | [diff] [blame] | 1365 | |
| 1366 | return sprintf(buf, "%d\n", value); |
| 1367 | } |
| 1368 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1369 | /* Fan1 */ |
| 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); |
| 1374 | |
| 1375 | /* Temperature */ |
Guenter Roeck | 50a639f | 2013-11-23 11:03:17 -0800 | [diff] [blame] | 1376 | static DEVICE_ATTR(temp1_input, S_IRUGO, asus_hwmon_temp1, NULL); |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1377 | |
| 1378 | static struct attribute *hwmon_attributes[] = { |
Guenter Roeck | 50a639f | 2013-11-23 11:03:17 -0800 | [diff] [blame] | 1379 | &dev_attr_pwm1.attr, |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1380 | &dev_attr_pwm1_enable.attr, |
| 1381 | &dev_attr_fan1_input.attr, |
| 1382 | &dev_attr_fan1_label.attr, |
| 1383 | |
Guenter Roeck | 50a639f | 2013-11-23 11:03:17 -0800 | [diff] [blame] | 1384 | &dev_attr_temp1_input.attr, |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1385 | NULL |
| 1386 | }; |
| 1387 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 1388 | static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj, |
Corentin Chary | e02431d | 2011-07-01 11:34:37 +0200 | [diff] [blame] | 1389 | struct attribute *attr, int idx) |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1390 | { |
| 1391 | struct device *dev = container_of(kobj, struct device, kobj); |
Fuqian Huang | 8e8fe44 | 2019-07-01 11:24:26 +0800 | [diff] [blame] | 1392 | struct asus_wmi *asus = dev_get_drvdata(dev->parent); |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1393 | int dev_id = -1; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1394 | int fan_attr = -1; |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1395 | u32 value = ASUS_WMI_UNSUPPORTED_METHOD; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1396 | bool ok = true; |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1397 | |
Guenter Roeck | 50a639f | 2013-11-23 11:03:17 -0800 | [diff] [blame] | 1398 | if (attr == &dev_attr_pwm1.attr) |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1399 | dev_id = ASUS_WMI_DEVID_FAN_CTRL; |
Guenter Roeck | 50a639f | 2013-11-23 11:03:17 -0800 | [diff] [blame] | 1400 | else if (attr == &dev_attr_temp1_input.attr) |
Corentin Chary | e02431d | 2011-07-01 11:34:37 +0200 | [diff] [blame] | 1401 | dev_id = ASUS_WMI_DEVID_THERMAL_CTRL; |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1402 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1403 | |
| 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) { |
| 1408 | fan_attr = 1; |
| 1409 | } |
| 1410 | |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1411 | if (dev_id != -1) { |
| 1412 | int err = asus_wmi_get_devstate(asus, dev_id, &value); |
| 1413 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1414 | if (err < 0 && fan_attr == -1) |
Al Viro | e772aed | 2011-07-23 20:59:40 -0400 | [diff] [blame] | 1415 | return 0; /* can't return negative here */ |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | if (dev_id == ASUS_WMI_DEVID_FAN_CTRL) { |
| 1419 | /* |
| 1420 | * We need to find a better way, probably using sfun, |
| 1421 | * bits or spec ... |
| 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 |
| 1426 | */ |
Corentin Chary | 49979d0 | 2011-07-01 11:34:26 +0200 | [diff] [blame] | 1427 | if (value == ASUS_WMI_UNSUPPORTED_METHOD || value & 0xFFF80000 |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1428 | || (!asus->sfun && !(value & ASUS_WMI_DSTS_PRESENCE_BIT))) |
| 1429 | ok = false; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1430 | else |
| 1431 | ok = fan_attr <= asus->asus_hwmon_num_fans; |
Corentin Chary | e02431d | 2011-07-01 11:34:37 +0200 | [diff] [blame] | 1432 | } else if (dev_id == ASUS_WMI_DEVID_THERMAL_CTRL) { |
Yurii Pavlovskyi | 4fd1982 | 2019-05-14 21:05:46 +0200 | [diff] [blame] | 1433 | /* |
| 1434 | * If the temperature value in deci-Kelvin is near the absolute |
| 1435 | * zero temperature, something is clearly wrong |
| 1436 | */ |
| 1437 | if (value == 0 || value == 1) |
Corentin Chary | e02431d | 2011-07-01 11:34:37 +0200 | [diff] [blame] | 1438 | ok = false; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1439 | } else if (fan_attr <= asus->asus_hwmon_num_fans && fan_attr != -1) { |
| 1440 | ok = true; |
| 1441 | } else { |
| 1442 | ok = false; |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | return ok ? attr->mode : 0; |
| 1446 | } |
| 1447 | |
Arvind Yadav | e90d9ba | 2017-07-11 16:18:19 +0530 | [diff] [blame] | 1448 | static const struct attribute_group hwmon_attribute_group = { |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1449 | .is_visible = asus_hwmon_sysfs_is_visible, |
| 1450 | .attrs = hwmon_attributes |
| 1451 | }; |
Guenter Roeck | 50a639f | 2013-11-23 11:03:17 -0800 | [diff] [blame] | 1452 | __ATTRIBUTE_GROUPS(hwmon_attribute); |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1453 | |
| 1454 | static int asus_wmi_hwmon_init(struct asus_wmi *asus) |
| 1455 | { |
Yurii Pavlovskyi | cd10ee0 | 2019-05-14 20:50:30 +0200 | [diff] [blame] | 1456 | struct device *dev = &asus->platform_device->dev; |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1457 | struct device *hwmon; |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1458 | |
Yurii Pavlovskyi | cd10ee0 | 2019-05-14 20:50:30 +0200 | [diff] [blame] | 1459 | hwmon = devm_hwmon_device_register_with_groups(dev, "asus", asus, |
| 1460 | hwmon_attribute_groups); |
| 1461 | |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1462 | if (IS_ERR(hwmon)) { |
| 1463 | pr_err("Could not register asus hwmon device\n"); |
| 1464 | return PTR_ERR(hwmon); |
| 1465 | } |
Guenter Roeck | 50a639f | 2013-11-23 11:03:17 -0800 | [diff] [blame] | 1466 | return 0; |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1467 | } |
| 1468 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 1469 | static int asus_wmi_fan_init(struct asus_wmi *asus) |
| 1470 | { |
| 1471 | int status; |
| 1472 | |
| 1473 | asus->asus_hwmon_pwm = -1; |
| 1474 | asus->asus_hwmon_num_fans = -1; |
| 1475 | asus->asus_hwmon_fan_manual_mode = false; |
| 1476 | |
| 1477 | status = asus_hwmon_get_fan_number(asus, &asus->asus_hwmon_num_fans); |
| 1478 | if (status) { |
| 1479 | asus->asus_hwmon_num_fans = 0; |
| 1480 | pr_warn("Could not determine number of fans: %d\n", status); |
| 1481 | return -ENXIO; |
| 1482 | } |
| 1483 | |
| 1484 | pr_info("Number of fans: %d\n", asus->asus_hwmon_num_fans); |
| 1485 | return 0; |
| 1486 | } |
| 1487 | |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1488 | /* Fan mode *******************************************************************/ |
| 1489 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1490 | static int fan_boost_mode_check_present(struct asus_wmi *asus) |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1491 | { |
| 1492 | u32 result; |
| 1493 | int err; |
| 1494 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1495 | asus->fan_boost_mode_available = false; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1496 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1497 | err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FAN_BOOST_MODE, |
| 1498 | &result); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1499 | if (err) { |
| 1500 | if (err == -ENODEV) |
| 1501 | return 0; |
| 1502 | else |
| 1503 | return err; |
| 1504 | } |
| 1505 | |
| 1506 | if ((result & ASUS_WMI_DSTS_PRESENCE_BIT) && |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1507 | (result & ASUS_FAN_BOOST_MODES_MASK)) { |
| 1508 | asus->fan_boost_mode_available = true; |
| 1509 | asus->fan_boost_mode_mask = result & ASUS_FAN_BOOST_MODES_MASK; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1510 | } |
| 1511 | |
| 1512 | return 0; |
| 1513 | } |
| 1514 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1515 | static int fan_boost_mode_write(struct asus_wmi *asus) |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1516 | { |
| 1517 | int err; |
| 1518 | u8 value; |
| 1519 | u32 retval; |
| 1520 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1521 | value = asus->fan_boost_mode; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1522 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1523 | pr_info("Set fan boost mode: %u\n", value); |
| 1524 | err = asus_wmi_set_devstate(ASUS_WMI_DEVID_FAN_BOOST_MODE, value, |
| 1525 | &retval); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1526 | |
| 1527 | if (err) { |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1528 | pr_warn("Failed to set fan boost mode: %d\n", err); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1529 | return err; |
| 1530 | } |
| 1531 | |
| 1532 | if (retval != 1) { |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1533 | pr_warn("Failed to set fan boost mode (retval): 0x%x\n", |
| 1534 | retval); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1535 | return -EIO; |
| 1536 | } |
| 1537 | |
| 1538 | return 0; |
| 1539 | } |
| 1540 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1541 | static int fan_boost_mode_switch_next(struct asus_wmi *asus) |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1542 | { |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1543 | u8 mask = asus->fan_boost_mode_mask; |
| 1544 | |
| 1545 | if (asus->fan_boost_mode == ASUS_FAN_BOOST_MODE_NORMAL) { |
| 1546 | if (mask & ASUS_FAN_BOOST_MODE_OVERBOOST_MASK) |
| 1547 | asus->fan_boost_mode = ASUS_FAN_BOOST_MODE_OVERBOOST; |
| 1548 | else if (mask & ASUS_FAN_BOOST_MODE_SILENT_MASK) |
| 1549 | asus->fan_boost_mode = ASUS_FAN_BOOST_MODE_SILENT; |
| 1550 | } else if (asus->fan_boost_mode == ASUS_FAN_BOOST_MODE_OVERBOOST) { |
| 1551 | if (mask & ASUS_FAN_BOOST_MODE_SILENT_MASK) |
| 1552 | asus->fan_boost_mode = ASUS_FAN_BOOST_MODE_SILENT; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1553 | else |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1554 | asus->fan_boost_mode = ASUS_FAN_BOOST_MODE_NORMAL; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1555 | } else { |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1556 | asus->fan_boost_mode = ASUS_FAN_BOOST_MODE_NORMAL; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1557 | } |
| 1558 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1559 | return fan_boost_mode_write(asus); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1560 | } |
| 1561 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1562 | static ssize_t fan_boost_mode_show(struct device *dev, |
| 1563 | struct device_attribute *attr, char *buf) |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1564 | { |
| 1565 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 1566 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1567 | return scnprintf(buf, PAGE_SIZE, "%d\n", asus->fan_boost_mode); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1568 | } |
| 1569 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1570 | static ssize_t fan_boost_mode_store(struct device *dev, |
| 1571 | struct device_attribute *attr, |
| 1572 | const char *buf, size_t count) |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1573 | { |
| 1574 | int result; |
| 1575 | u8 new_mode; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1576 | struct asus_wmi *asus = dev_get_drvdata(dev); |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1577 | u8 mask = asus->fan_boost_mode_mask; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1578 | |
| 1579 | result = kstrtou8(buf, 10, &new_mode); |
| 1580 | if (result < 0) { |
| 1581 | pr_warn("Trying to store invalid value\n"); |
| 1582 | return result; |
| 1583 | } |
| 1584 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1585 | if (new_mode == ASUS_FAN_BOOST_MODE_OVERBOOST) { |
| 1586 | if (!(mask & ASUS_FAN_BOOST_MODE_OVERBOOST_MASK)) |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1587 | return -EINVAL; |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1588 | } else if (new_mode == ASUS_FAN_BOOST_MODE_SILENT) { |
| 1589 | if (!(mask & ASUS_FAN_BOOST_MODE_SILENT_MASK)) |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1590 | return -EINVAL; |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1591 | } else if (new_mode != ASUS_FAN_BOOST_MODE_NORMAL) { |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1592 | return -EINVAL; |
| 1593 | } |
| 1594 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1595 | asus->fan_boost_mode = new_mode; |
| 1596 | fan_boost_mode_write(asus); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1597 | |
| 1598 | return result; |
| 1599 | } |
| 1600 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1601 | // Fan boost mode: 0 - normal, 1 - overboost, 2 - silent |
| 1602 | static DEVICE_ATTR_RW(fan_boost_mode); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1603 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 1604 | /* Backlight ******************************************************************/ |
| 1605 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 1606 | static int read_backlight_power(struct asus_wmi *asus) |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 1607 | { |
AceLan Kao | 6e0044b | 2012-03-20 09:53:09 +0100 | [diff] [blame] | 1608 | int ret; |
| 1609 | if (asus->driver->quirks->store_backlight_power) |
| 1610 | ret = !asus->driver->panel_power; |
| 1611 | else |
| 1612 | ret = asus_wmi_get_devstate_simple(asus, |
| 1613 | ASUS_WMI_DEVID_BACKLIGHT); |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 1614 | |
| 1615 | if (ret < 0) |
| 1616 | return ret; |
| 1617 | |
| 1618 | return ret ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; |
| 1619 | } |
| 1620 | |
Corentin Chary | 8fbea01 | 2011-02-26 10:20:37 +0100 | [diff] [blame] | 1621 | static int read_brightness_max(struct asus_wmi *asus) |
| 1622 | { |
| 1623 | u32 retval; |
| 1624 | int err; |
| 1625 | |
| 1626 | err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_BRIGHTNESS, &retval); |
| 1627 | |
| 1628 | if (err < 0) |
| 1629 | return err; |
| 1630 | |
| 1631 | retval = retval & ASUS_WMI_DSTS_MAX_BRIGTH_MASK; |
| 1632 | retval >>= 8; |
| 1633 | |
| 1634 | if (!retval) |
| 1635 | return -ENODEV; |
| 1636 | |
| 1637 | return retval; |
| 1638 | } |
| 1639 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1640 | static int read_brightness(struct backlight_device *bd) |
| 1641 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 1642 | struct asus_wmi *asus = bl_get_data(bd); |
Dan Carpenter | 0986f25 | 2011-03-15 10:06:23 +0300 | [diff] [blame] | 1643 | u32 retval; |
| 1644 | int err; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1645 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 1646 | err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_BRIGHTNESS, &retval); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1647 | |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 1648 | if (err < 0) |
| 1649 | return err; |
| 1650 | |
| 1651 | return retval & ASUS_WMI_DSTS_BRIGHTNESS_MASK; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1652 | } |
| 1653 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 1654 | static u32 get_scalar_command(struct backlight_device *bd) |
| 1655 | { |
| 1656 | struct asus_wmi *asus = bl_get_data(bd); |
| 1657 | u32 ctrl_param = 0; |
| 1658 | |
| 1659 | if ((asus->driver->brightness < bd->props.brightness) || |
| 1660 | bd->props.brightness == bd->props.max_brightness) |
| 1661 | ctrl_param = 0x00008001; |
| 1662 | else if ((asus->driver->brightness > bd->props.brightness) || |
| 1663 | bd->props.brightness == 0) |
| 1664 | ctrl_param = 0x00008000; |
| 1665 | |
| 1666 | asus->driver->brightness = bd->props.brightness; |
| 1667 | |
| 1668 | return ctrl_param; |
| 1669 | } |
| 1670 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1671 | static int update_bl_status(struct backlight_device *bd) |
| 1672 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 1673 | struct asus_wmi *asus = bl_get_data(bd); |
Corentin Chary | dfed65d | 2010-11-29 08:14:12 +0100 | [diff] [blame] | 1674 | u32 ctrl_param; |
AceLan Kao | 6e0044b | 2012-03-20 09:53:09 +0100 | [diff] [blame] | 1675 | int power, err = 0; |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 1676 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 1677 | power = read_backlight_power(asus); |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 1678 | if (power != -ENODEV && bd->props.power != power) { |
| 1679 | ctrl_param = !!(bd->props.power == FB_BLANK_UNBLANK); |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 1680 | err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BACKLIGHT, |
| 1681 | ctrl_param, NULL); |
AceLan Kao | 6e0044b | 2012-03-20 09:53:09 +0100 | [diff] [blame] | 1682 | if (asus->driver->quirks->store_backlight_power) |
| 1683 | asus->driver->panel_power = bd->props.power; |
AceLan Kao | 6e0044b | 2012-03-20 09:53:09 +0100 | [diff] [blame] | 1684 | |
Corentin Chary | ade28ab | 2012-03-20 09:53:14 +0100 | [diff] [blame] | 1685 | /* When using scalar brightness, updating the brightness |
| 1686 | * will mess with the backlight power */ |
| 1687 | if (asus->driver->quirks->scalar_panel_brightness) |
| 1688 | return err; |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 1689 | } |
Corentin Chary | ade28ab | 2012-03-20 09:53:14 +0100 | [diff] [blame] | 1690 | |
| 1691 | if (asus->driver->quirks->scalar_panel_brightness) |
| 1692 | ctrl_param = get_scalar_command(bd); |
| 1693 | else |
| 1694 | ctrl_param = bd->props.brightness; |
| 1695 | |
| 1696 | err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BRIGHTNESS, |
| 1697 | ctrl_param, NULL); |
| 1698 | |
Corentin Chary | 8fbea01 | 2011-02-26 10:20:37 +0100 | [diff] [blame] | 1699 | return err; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1700 | } |
| 1701 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1702 | static const struct backlight_ops asus_wmi_bl_ops = { |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1703 | .get_brightness = read_brightness, |
| 1704 | .update_status = update_bl_status, |
| 1705 | }; |
| 1706 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1707 | static int asus_wmi_backlight_notify(struct asus_wmi *asus, int code) |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1708 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1709 | struct backlight_device *bd = asus->backlight_device; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1710 | int old = bd->props.brightness; |
Daniel Mack | b7670ed | 2010-05-19 12:37:01 +0200 | [diff] [blame] | 1711 | int new = old; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1712 | |
| 1713 | if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) |
| 1714 | new = code - NOTIFY_BRNUP_MIN + 1; |
| 1715 | else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX) |
| 1716 | new = code - NOTIFY_BRNDOWN_MIN; |
| 1717 | |
| 1718 | bd->props.brightness = new; |
| 1719 | backlight_update_status(bd); |
| 1720 | backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY); |
| 1721 | |
| 1722 | return old; |
| 1723 | } |
| 1724 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1725 | static int asus_wmi_backlight_init(struct asus_wmi *asus) |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1726 | { |
| 1727 | struct backlight_device *bd; |
| 1728 | struct backlight_properties props; |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 1729 | int max; |
| 1730 | int power; |
| 1731 | |
Corentin Chary | 8fbea01 | 2011-02-26 10:20:37 +0100 | [diff] [blame] | 1732 | max = read_brightness_max(asus); |
Hans de Goede | 86ac2735 | 2014-07-08 10:47:22 +0200 | [diff] [blame] | 1733 | if (max < 0) |
Corentin Chary | 8fbea01 | 2011-02-26 10:20:37 +0100 | [diff] [blame] | 1734 | return max; |
| 1735 | |
| 1736 | power = read_backlight_power(asus); |
| 1737 | |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 1738 | if (power == -ENODEV) |
| 1739 | power = FB_BLANK_UNBLANK; |
Corentin Chary | 8fbea01 | 2011-02-26 10:20:37 +0100 | [diff] [blame] | 1740 | else if (power < 0) |
| 1741 | return power; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1742 | |
| 1743 | memset(&props, 0, sizeof(struct backlight_properties)); |
Axel Lin | 60cfa09 | 2011-06-29 11:43:30 +0800 | [diff] [blame] | 1744 | props.type = BACKLIGHT_PLATFORM; |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 1745 | props.max_brightness = max; |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1746 | bd = backlight_device_register(asus->driver->name, |
| 1747 | &asus->platform_device->dev, asus, |
| 1748 | &asus_wmi_bl_ops, &props); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1749 | if (IS_ERR(bd)) { |
| 1750 | pr_err("Could not register backlight device\n"); |
| 1751 | return PTR_ERR(bd); |
| 1752 | } |
| 1753 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1754 | asus->backlight_device = bd; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1755 | |
AceLan Kao | 6e0044b | 2012-03-20 09:53:09 +0100 | [diff] [blame] | 1756 | if (asus->driver->quirks->store_backlight_power) |
| 1757 | asus->driver->panel_power = power; |
| 1758 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1759 | bd->props.brightness = read_brightness(bd); |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 1760 | bd->props.power = power; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1761 | backlight_update_status(bd); |
| 1762 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 1763 | asus->driver->brightness = bd->props.brightness; |
| 1764 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1765 | return 0; |
| 1766 | } |
| 1767 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1768 | static void asus_wmi_backlight_exit(struct asus_wmi *asus) |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1769 | { |
Markus Elfring | 0098181 | 2014-11-24 20:30:29 +0100 | [diff] [blame] | 1770 | backlight_device_unregister(asus->backlight_device); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1771 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1772 | asus->backlight_device = NULL; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1773 | } |
| 1774 | |
AceLan Kao | a2a96f0 | 2012-10-03 11:26:31 +0200 | [diff] [blame] | 1775 | static int is_display_toggle(int code) |
| 1776 | { |
| 1777 | /* display toggle keys */ |
| 1778 | if ((code >= 0x61 && code <= 0x67) || |
| 1779 | (code >= 0x8c && code <= 0x93) || |
| 1780 | (code >= 0xa0 && code <= 0xa7) || |
| 1781 | (code >= 0xd0 && code <= 0xd5)) |
| 1782 | return 1; |
| 1783 | |
| 1784 | return 0; |
| 1785 | } |
| 1786 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 1787 | /* Fn-lock ********************************************************************/ |
| 1788 | |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 1789 | static bool asus_wmi_has_fnlock_key(struct asus_wmi *asus) |
| 1790 | { |
| 1791 | u32 result; |
| 1792 | |
| 1793 | asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FNLOCK, &result); |
| 1794 | |
| 1795 | return (result & ASUS_WMI_DSTS_PRESENCE_BIT) && |
| 1796 | !(result & ASUS_WMI_FNLOCK_BIOS_DISABLED); |
| 1797 | } |
| 1798 | |
| 1799 | static void asus_wmi_fnlock_update(struct asus_wmi *asus) |
| 1800 | { |
| 1801 | int mode = asus->fnlock_locked; |
| 1802 | |
| 1803 | asus_wmi_set_devstate(ASUS_WMI_DEVID_FNLOCK, mode, NULL); |
| 1804 | } |
| 1805 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 1806 | /* WMI events *****************************************************************/ |
| 1807 | |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 1808 | static int asus_wmi_get_event_code(u32 value) |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1809 | { |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1810 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 1811 | union acpi_object *obj; |
| 1812 | acpi_status status; |
| 1813 | int code; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1814 | |
| 1815 | status = wmi_get_event_data(value, &response); |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 1816 | if (ACPI_FAILURE(status)) { |
| 1817 | pr_warn("Failed to get WMI notify code: %s\n", |
| 1818 | acpi_format_exception(status)); |
| 1819 | return -EIO; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | obj = (union acpi_object *)response.pointer; |
| 1823 | |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 1824 | if (obj && obj->type == ACPI_TYPE_INTEGER) |
| 1825 | code = (int)(obj->integer.value & WMI_EVENT_MASK); |
| 1826 | else |
| 1827 | code = -EIO; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1828 | |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 1829 | kfree(obj); |
| 1830 | return code; |
| 1831 | } |
| 1832 | |
| 1833 | static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus) |
| 1834 | { |
| 1835 | int orig_code; |
| 1836 | unsigned int key_value = 1; |
| 1837 | bool autorelease = 1; |
| 1838 | |
Corentin Chary | 57ab7da | 2011-02-26 10:20:32 +0100 | [diff] [blame] | 1839 | orig_code = code; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1840 | |
Seth Forshee | c4453f6 | 2011-07-01 11:34:27 +0200 | [diff] [blame] | 1841 | if (asus->driver->key_filter) { |
| 1842 | asus->driver->key_filter(asus->driver, &code, &key_value, |
| 1843 | &autorelease); |
| 1844 | if (code == ASUS_WMI_KEY_IGNORE) |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 1845 | return; |
Seth Forshee | c4453f6 | 2011-07-01 11:34:27 +0200 | [diff] [blame] | 1846 | } |
| 1847 | |
Corentin Chary | 57ab7da | 2011-02-26 10:20:32 +0100 | [diff] [blame] | 1848 | if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) |
Corentin Chary | 3ba0302 | 2012-11-29 09:12:38 +0100 | [diff] [blame] | 1849 | code = ASUS_WMI_BRN_UP; |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 1850 | else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX) |
Corentin Chary | 3ba0302 | 2012-11-29 09:12:38 +0100 | [diff] [blame] | 1851 | code = ASUS_WMI_BRN_DOWN; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1852 | |
Corentin Chary | 3ba0302 | 2012-11-29 09:12:38 +0100 | [diff] [blame] | 1853 | if (code == ASUS_WMI_BRN_DOWN || code == ASUS_WMI_BRN_UP) { |
Hans de Goede | 62c4aa1 | 2015-06-16 16:27:58 +0200 | [diff] [blame] | 1854 | if (acpi_video_get_backlight_type() == acpi_backlight_vendor) { |
Corentin Chary | 57ab7da | 2011-02-26 10:20:32 +0100 | [diff] [blame] | 1855 | asus_wmi_backlight_notify(asus, orig_code); |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 1856 | return; |
AceLan Kao | a2a96f0 | 2012-10-03 11:26:31 +0200 | [diff] [blame] | 1857 | } |
AceLan Kao | a2a96f0 | 2012-10-03 11:26:31 +0200 | [diff] [blame] | 1858 | } |
| 1859 | |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 1860 | if (code == NOTIFY_KBD_BRTUP) { |
Jian-Hong Pan | 29f6eb5 | 2018-10-22 18:00:04 +0800 | [diff] [blame] | 1861 | kbd_led_set_by_kbd(asus, asus->kbd_led_wk + 1); |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 1862 | return; |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 1863 | } |
| 1864 | if (code == NOTIFY_KBD_BRTDWN) { |
Jian-Hong Pan | 29f6eb5 | 2018-10-22 18:00:04 +0800 | [diff] [blame] | 1865 | kbd_led_set_by_kbd(asus, asus->kbd_led_wk - 1); |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 1866 | return; |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 1867 | } |
Chris Chiu | ed99d29 | 2018-06-20 22:46:45 +0800 | [diff] [blame] | 1868 | if (code == NOTIFY_KBD_BRTTOGGLE) { |
| 1869 | if (asus->kbd_led_wk == asus->kbd_led.max_brightness) |
Jian-Hong Pan | 29f6eb5 | 2018-10-22 18:00:04 +0800 | [diff] [blame] | 1870 | kbd_led_set_by_kbd(asus, 0); |
Chris Chiu | ed99d29 | 2018-06-20 22:46:45 +0800 | [diff] [blame] | 1871 | else |
Jian-Hong Pan | 29f6eb5 | 2018-10-22 18:00:04 +0800 | [diff] [blame] | 1872 | kbd_led_set_by_kbd(asus, asus->kbd_led_wk + 1); |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 1873 | return; |
Chris Chiu | ed99d29 | 2018-06-20 22:46:45 +0800 | [diff] [blame] | 1874 | } |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 1875 | |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 1876 | if (code == NOTIFY_FNLOCK_TOGGLE) { |
| 1877 | asus->fnlock_locked = !asus->fnlock_locked; |
| 1878 | asus_wmi_fnlock_update(asus); |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 1879 | return; |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 1880 | } |
| 1881 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 1882 | if (asus->fan_boost_mode_available && code == NOTIFY_KBD_FBM) { |
| 1883 | fan_boost_mode_switch_next(asus); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1884 | return; |
| 1885 | } |
| 1886 | |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 1887 | if (is_display_toggle(code) && asus->driver->quirks->no_display_toggle) |
| 1888 | return; |
AceLan Kao | a2a96f0 | 2012-10-03 11:26:31 +0200 | [diff] [blame] | 1889 | |
| 1890 | if (!sparse_keymap_report_event(asus->inputdev, code, |
| 1891 | key_value, autorelease)) |
Corentin Chary | 57ab7da | 2011-02-26 10:20:32 +0100 | [diff] [blame] | 1892 | pr_info("Unknown key %x pressed\n", code); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 1893 | } |
| 1894 | |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 1895 | static void asus_wmi_notify(u32 value, void *context) |
| 1896 | { |
| 1897 | struct asus_wmi *asus = context; |
Yurii Pavlovskyi | 1a373d1 | 2019-05-14 21:02:09 +0200 | [diff] [blame] | 1898 | int code; |
| 1899 | int i; |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 1900 | |
Yurii Pavlovskyi | 1a373d1 | 2019-05-14 21:02:09 +0200 | [diff] [blame] | 1901 | for (i = 0; i < WMI_EVENT_QUEUE_SIZE + 1; i++) { |
| 1902 | code = asus_wmi_get_event_code(value); |
| 1903 | |
| 1904 | if (code < 0) { |
| 1905 | pr_warn("Failed to get notify code: %d\n", code); |
| 1906 | return; |
| 1907 | } |
| 1908 | |
| 1909 | if (code == WMI_EVENT_QUEUE_END || code == WMI_EVENT_MASK) |
| 1910 | return; |
| 1911 | |
| 1912 | asus_wmi_handle_event_code(code, asus); |
| 1913 | |
| 1914 | /* |
| 1915 | * Double check that queue is present: |
| 1916 | * ATK (with queue) uses 0xff, ASUSWMI (without) 0xd2. |
| 1917 | */ |
| 1918 | if (!asus->wmi_event_queue || value != WMI_EVENT_VALUE_ATK) |
| 1919 | return; |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 1920 | } |
| 1921 | |
Yurii Pavlovskyi | 1a373d1 | 2019-05-14 21:02:09 +0200 | [diff] [blame] | 1922 | pr_warn("Failed to process event queue, last code: 0x%x\n", code); |
| 1923 | } |
| 1924 | |
| 1925 | static int asus_wmi_notify_queue_flush(struct asus_wmi *asus) |
| 1926 | { |
| 1927 | int code; |
| 1928 | int i; |
| 1929 | |
| 1930 | for (i = 0; i < WMI_EVENT_QUEUE_SIZE + 1; i++) { |
| 1931 | code = asus_wmi_get_event_code(WMI_EVENT_VALUE_ATK); |
| 1932 | |
| 1933 | if (code < 0) { |
| 1934 | pr_warn("Failed to get event during flush: %d\n", code); |
| 1935 | return code; |
| 1936 | } |
| 1937 | |
| 1938 | if (code == WMI_EVENT_QUEUE_END || code == WMI_EVENT_MASK) |
| 1939 | return 0; |
| 1940 | } |
| 1941 | |
| 1942 | pr_warn("Failed to flush event queue\n"); |
| 1943 | return -EIO; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 1944 | } |
| 1945 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 1946 | /* Sysfs **********************************************************************/ |
| 1947 | |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 1948 | static int parse_arg(const char *buf, unsigned long count, int *val) |
| 1949 | { |
| 1950 | if (!count) |
| 1951 | return 0; |
| 1952 | if (sscanf(buf, "%i", val) != 1) |
| 1953 | return -EINVAL; |
| 1954 | return count; |
| 1955 | } |
| 1956 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 1957 | static ssize_t store_sys_wmi(struct asus_wmi *asus, int devid, |
| 1958 | const char *buf, size_t count) |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 1959 | { |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 1960 | u32 retval; |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 1961 | int rv, err, value; |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 1962 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 1963 | value = asus_wmi_get_devstate_simple(asus, devid); |
Dan Carpenter | b829834 | 2015-11-11 01:18:16 +0300 | [diff] [blame] | 1964 | if (value < 0) |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 1965 | return value; |
| 1966 | |
| 1967 | rv = parse_arg(buf, count, &value); |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 1968 | err = asus_wmi_set_devstate(devid, value, &retval); |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 1969 | |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 1970 | if (err < 0) |
| 1971 | return err; |
| 1972 | |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 1973 | return rv; |
| 1974 | } |
| 1975 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 1976 | static ssize_t show_sys_wmi(struct asus_wmi *asus, int devid, char *buf) |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 1977 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 1978 | int value = asus_wmi_get_devstate_simple(asus, devid); |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 1979 | |
| 1980 | if (value < 0) |
| 1981 | return value; |
| 1982 | |
| 1983 | return sprintf(buf, "%d\n", value); |
| 1984 | } |
| 1985 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1986 | #define ASUS_WMI_CREATE_DEVICE_ATTR(_name, _mode, _cm) \ |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 1987 | static ssize_t show_##_name(struct device *dev, \ |
| 1988 | struct device_attribute *attr, \ |
| 1989 | char *buf) \ |
| 1990 | { \ |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 1991 | struct asus_wmi *asus = dev_get_drvdata(dev); \ |
| 1992 | \ |
| 1993 | return show_sys_wmi(asus, _cm, buf); \ |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 1994 | } \ |
| 1995 | static ssize_t store_##_name(struct device *dev, \ |
| 1996 | struct device_attribute *attr, \ |
| 1997 | const char *buf, size_t count) \ |
| 1998 | { \ |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 1999 | struct asus_wmi *asus = dev_get_drvdata(dev); \ |
| 2000 | \ |
| 2001 | return store_sys_wmi(asus, _cm, buf, count); \ |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2002 | } \ |
| 2003 | static struct device_attribute dev_attr_##_name = { \ |
| 2004 | .attr = { \ |
| 2005 | .name = __stringify(_name), \ |
| 2006 | .mode = _mode }, \ |
| 2007 | .show = show_##_name, \ |
| 2008 | .store = store_##_name, \ |
| 2009 | } |
| 2010 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2011 | ASUS_WMI_CREATE_DEVICE_ATTR(touchpad, 0644, ASUS_WMI_DEVID_TOUCHPAD); |
| 2012 | ASUS_WMI_CREATE_DEVICE_ATTR(camera, 0644, ASUS_WMI_DEVID_CAMERA); |
| 2013 | ASUS_WMI_CREATE_DEVICE_ATTR(cardr, 0644, ASUS_WMI_DEVID_CARDREADER); |
AceLan Kao | c0b91b6 | 2012-06-13 09:32:07 +0200 | [diff] [blame] | 2014 | ASUS_WMI_CREATE_DEVICE_ATTR(lid_resume, 0644, ASUS_WMI_DEVID_LID_RESUME); |
Oleksij Rempel | aca234f | 2016-04-01 13:35:21 +0200 | [diff] [blame] | 2015 | ASUS_WMI_CREATE_DEVICE_ATTR(als_enable, 0644, ASUS_WMI_DEVID_ALS_ENABLE); |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2016 | |
Jérémy Lefaure | a8fe342 | 2017-04-21 22:19:45 -0400 | [diff] [blame] | 2017 | static ssize_t cpufv_store(struct device *dev, struct device_attribute *attr, |
Dmitry Torokhov | 67fa38e | 2010-11-03 11:14:01 -0700 | [diff] [blame] | 2018 | const char *buf, size_t count) |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2019 | { |
Corentin Chary | 3df5fda | 2011-07-01 11:34:38 +0200 | [diff] [blame] | 2020 | int value, rv; |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2021 | |
| 2022 | if (!count || sscanf(buf, "%i", &value) != 1) |
| 2023 | return -EINVAL; |
| 2024 | if (value < 0 || value > 2) |
| 2025 | return -EINVAL; |
| 2026 | |
Corentin Chary | 3df5fda | 2011-07-01 11:34:38 +0200 | [diff] [blame] | 2027 | rv = asus_wmi_evaluate_method(ASUS_WMI_METHODID_CFVS, value, 0, NULL); |
| 2028 | if (rv < 0) |
| 2029 | return rv; |
| 2030 | |
| 2031 | return count; |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2032 | } |
| 2033 | |
Jérémy Lefaure | a8fe342 | 2017-04-21 22:19:45 -0400 | [diff] [blame] | 2034 | static DEVICE_ATTR_WO(cpufv); |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2035 | |
Corentin Chary | 4e37b42 | 2010-11-29 08:14:08 +0100 | [diff] [blame] | 2036 | static struct attribute *platform_attributes[] = { |
| 2037 | &dev_attr_cpufv.attr, |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2038 | &dev_attr_camera.attr, |
| 2039 | &dev_attr_cardr.attr, |
Corentin Chary | 4615bb6 | 2011-02-06 13:28:42 +0100 | [diff] [blame] | 2040 | &dev_attr_touchpad.attr, |
AceLan Kao | c0b91b6 | 2012-06-13 09:32:07 +0200 | [diff] [blame] | 2041 | &dev_attr_lid_resume.attr, |
Oleksij Rempel | aca234f | 2016-04-01 13:35:21 +0200 | [diff] [blame] | 2042 | &dev_attr_als_enable.attr, |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 2043 | &dev_attr_fan_boost_mode.attr, |
Corentin Chary | 4e37b42 | 2010-11-29 08:14:08 +0100 | [diff] [blame] | 2044 | NULL |
| 2045 | }; |
| 2046 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 2047 | static umode_t asus_sysfs_is_visible(struct kobject *kobj, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2048 | struct attribute *attr, int idx) |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2049 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2050 | struct device *dev = container_of(kobj, struct device, kobj); |
Wolfram Sang | d605ca2 | 2018-04-19 16:06:10 +0200 | [diff] [blame] | 2051 | struct asus_wmi *asus = dev_get_drvdata(dev); |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2052 | bool ok = true; |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2053 | int devid = -1; |
| 2054 | |
| 2055 | if (attr == &dev_attr_camera.attr) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2056 | devid = ASUS_WMI_DEVID_CAMERA; |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2057 | else if (attr == &dev_attr_cardr.attr) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2058 | devid = ASUS_WMI_DEVID_CARDREADER; |
Corentin Chary | 4615bb6 | 2011-02-06 13:28:42 +0100 | [diff] [blame] | 2059 | else if (attr == &dev_attr_touchpad.attr) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2060 | devid = ASUS_WMI_DEVID_TOUCHPAD; |
AceLan Kao | c0b91b6 | 2012-06-13 09:32:07 +0200 | [diff] [blame] | 2061 | else if (attr == &dev_attr_lid_resume.attr) |
| 2062 | devid = ASUS_WMI_DEVID_LID_RESUME; |
Oleksij Rempel | aca234f | 2016-04-01 13:35:21 +0200 | [diff] [blame] | 2063 | else if (attr == &dev_attr_als_enable.attr) |
| 2064 | devid = ASUS_WMI_DEVID_ALS_ENABLE; |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 2065 | else if (attr == &dev_attr_fan_boost_mode.attr) |
| 2066 | ok = asus->fan_boost_mode_available; |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2067 | |
| 2068 | if (devid != -1) |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2069 | ok = !(asus_wmi_get_devstate_simple(asus, devid) < 0); |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2070 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2071 | return ok ? attr->mode : 0; |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2072 | } |
| 2073 | |
Arvind Yadav | e90d9ba | 2017-07-11 16:18:19 +0530 | [diff] [blame] | 2074 | static const struct attribute_group platform_attribute_group = { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2075 | .is_visible = asus_sysfs_is_visible, |
| 2076 | .attrs = platform_attributes |
Corentin Chary | 4e37b42 | 2010-11-29 08:14:08 +0100 | [diff] [blame] | 2077 | }; |
| 2078 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2079 | static void asus_wmi_sysfs_exit(struct platform_device *device) |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2080 | { |
Corentin Chary | 4e37b42 | 2010-11-29 08:14:08 +0100 | [diff] [blame] | 2081 | sysfs_remove_group(&device->dev.kobj, &platform_attribute_group); |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2082 | } |
| 2083 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2084 | static int asus_wmi_sysfs_init(struct platform_device *device) |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2085 | { |
Corentin Chary | 4e37b42 | 2010-11-29 08:14:08 +0100 | [diff] [blame] | 2086 | return sysfs_create_group(&device->dev.kobj, &platform_attribute_group); |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2087 | } |
| 2088 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 2089 | /* Platform device ************************************************************/ |
| 2090 | |
Joe Perches | 39ddf3b | 2011-03-29 15:21:32 -0700 | [diff] [blame] | 2091 | static int asus_wmi_platform_init(struct asus_wmi *asus) |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2092 | { |
Yurii Pavlovskyi | e0668f2 | 2019-05-14 21:00:31 +0200 | [diff] [blame] | 2093 | struct device *dev = &asus->platform_device->dev; |
| 2094 | char *wmi_uid; |
Corentin Chary | 46dbca8 | 2011-02-26 10:20:38 +0100 | [diff] [blame] | 2095 | int rv; |
| 2096 | |
| 2097 | /* INIT enable hotkeys on some models */ |
| 2098 | if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_INIT, 0, 0, &rv)) |
vic | 0ed6065 | 2013-05-22 21:32:10 +0300 | [diff] [blame] | 2099 | pr_info("Initialization: %#x\n", rv); |
Corentin Chary | 46dbca8 | 2011-02-26 10:20:38 +0100 | [diff] [blame] | 2100 | |
| 2101 | /* We don't know yet what to do with this version... */ |
| 2102 | if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_SPEC, 0, 0x9, &rv)) { |
vic | 0ed6065 | 2013-05-22 21:32:10 +0300 | [diff] [blame] | 2103 | pr_info("BIOS WMI version: %d.%d\n", rv >> 16, rv & 0xFF); |
Corentin Chary | 46dbca8 | 2011-02-26 10:20:38 +0100 | [diff] [blame] | 2104 | asus->spec = rv; |
| 2105 | } |
| 2106 | |
| 2107 | /* |
| 2108 | * The SFUN method probably allows the original driver to get the list |
| 2109 | * of features supported by a given model. For now, 0x0100 or 0x0800 |
| 2110 | * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card. |
| 2111 | * The significance of others is yet to be found. |
| 2112 | */ |
| 2113 | if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_SFUN, 0, 0, &rv)) { |
vic | 0ed6065 | 2013-05-22 21:32:10 +0300 | [diff] [blame] | 2114 | pr_info("SFUN value: %#x\n", rv); |
Corentin Chary | 46dbca8 | 2011-02-26 10:20:38 +0100 | [diff] [blame] | 2115 | asus->sfun = rv; |
| 2116 | } |
| 2117 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2118 | /* |
| 2119 | * Eee PC and Notebooks seems to have different method_id for DSTS, |
| 2120 | * but it may also be related to the BIOS's SPEC. |
| 2121 | * Note, on most Eeepc, there is no way to check if a method exist |
| 2122 | * or note, while on notebooks, they returns 0xFFFFFFFE on failure, |
| 2123 | * but once again, SPEC may probably be used for that kind of things. |
Yurii Pavlovskyi | e0668f2 | 2019-05-14 21:00:31 +0200 | [diff] [blame] | 2124 | * |
| 2125 | * Additionally at least TUF Gaming series laptops return nothing for |
| 2126 | * unknown methods, so the detection in this way is not possible. |
| 2127 | * |
| 2128 | * There is strong indication that only ACPI WMI devices that have _UID |
| 2129 | * equal to "ASUSWMI" use DCTS whereas those with "ATK" use DSTS. |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2130 | */ |
Yurii Pavlovskyi | e0668f2 | 2019-05-14 21:00:31 +0200 | [diff] [blame] | 2131 | wmi_uid = wmi_get_acpi_device_uid(ASUS_WMI_MGMT_GUID); |
| 2132 | if (!wmi_uid) |
| 2133 | return -ENODEV; |
| 2134 | |
| 2135 | if (!strcmp(wmi_uid, ASUS_ACPI_UID_ASUSWMI)) { |
| 2136 | dev_info(dev, "Detected ASUSWMI, use DCTS\n"); |
| 2137 | asus->dsts_id = ASUS_WMI_METHODID_DCTS; |
| 2138 | } else { |
| 2139 | dev_info(dev, "Detected %s, not ASUSWMI, use DSTS\n", wmi_uid); |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2140 | asus->dsts_id = ASUS_WMI_METHODID_DSTS; |
Yurii Pavlovskyi | e0668f2 | 2019-05-14 21:00:31 +0200 | [diff] [blame] | 2141 | } |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2142 | |
Yurii Pavlovskyi | 1a373d1 | 2019-05-14 21:02:09 +0200 | [diff] [blame] | 2143 | /* |
| 2144 | * Some devices can have multiple event codes stored in a queue before |
| 2145 | * the module load if it was unloaded intermittently after calling |
| 2146 | * the INIT method (enables event handling). The WMI notify handler is |
| 2147 | * expected to retrieve all event codes until a retrieved code equals |
| 2148 | * queue end marker (One or Ones). Old codes are flushed from the queue |
| 2149 | * upon module load. Not enabling this when it should be has minimal |
| 2150 | * visible impact so fall back if anything goes wrong. |
| 2151 | */ |
| 2152 | wmi_uid = wmi_get_acpi_device_uid(asus->driver->event_guid); |
| 2153 | if (wmi_uid && !strcmp(wmi_uid, ASUS_ACPI_UID_ATK)) { |
| 2154 | dev_info(dev, "Detected ATK, enable event queue\n"); |
| 2155 | |
| 2156 | if (!asus_wmi_notify_queue_flush(asus)) |
| 2157 | asus->wmi_event_queue = true; |
| 2158 | } |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2159 | |
Corentin Chary | fddbfed | 2011-07-01 11:34:39 +0200 | [diff] [blame] | 2160 | /* CWAP allow to define the behavior of the Fn+F2 key, |
| 2161 | * this method doesn't seems to be present on Eee PCs */ |
Corentin Chary | 6a2bccc | 2012-03-20 09:53:10 +0100 | [diff] [blame] | 2162 | if (asus->driver->quirks->wapf >= 0) |
Corentin Chary | fddbfed | 2011-07-01 11:34:39 +0200 | [diff] [blame] | 2163 | asus_wmi_set_devstate(ASUS_WMI_DEVID_CWAP, |
Corentin Chary | 6a2bccc | 2012-03-20 09:53:10 +0100 | [diff] [blame] | 2164 | asus->driver->quirks->wapf, NULL); |
Corentin Chary | fddbfed | 2011-07-01 11:34:39 +0200 | [diff] [blame] | 2165 | |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2166 | return 0; |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2167 | } |
| 2168 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 2169 | /* debugfs ********************************************************************/ |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2170 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2171 | struct asus_wmi_debugfs_node { |
| 2172 | struct asus_wmi *asus; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2173 | char *name; |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2174 | int (*show) (struct seq_file *m, void *data); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2175 | }; |
| 2176 | |
| 2177 | static int show_dsts(struct seq_file *m, void *data) |
| 2178 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2179 | struct asus_wmi *asus = m->private; |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 2180 | int err; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2181 | u32 retval = -1; |
| 2182 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2183 | err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2184 | |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 2185 | if (err < 0) |
| 2186 | return err; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2187 | |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 2188 | seq_printf(m, "DSTS(%#x) = %#x\n", asus->debug.dev_id, retval); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2189 | |
| 2190 | return 0; |
| 2191 | } |
| 2192 | |
| 2193 | static int show_devs(struct seq_file *m, void *data) |
| 2194 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2195 | struct asus_wmi *asus = m->private; |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 2196 | int err; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2197 | u32 retval = -1; |
| 2198 | |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 2199 | err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param, |
| 2200 | &retval); |
| 2201 | |
| 2202 | if (err < 0) |
| 2203 | return err; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2204 | |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 2205 | seq_printf(m, "DEVS(%#x, %#x) = %#x\n", asus->debug.dev_id, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2206 | asus->debug.ctrl_param, retval); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2207 | |
| 2208 | return 0; |
| 2209 | } |
| 2210 | |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 2211 | static int show_call(struct seq_file *m, void *data) |
| 2212 | { |
| 2213 | struct asus_wmi *asus = m->private; |
| 2214 | struct bios_args args = { |
| 2215 | .arg0 = asus->debug.dev_id, |
| 2216 | .arg1 = asus->debug.ctrl_param, |
| 2217 | }; |
| 2218 | struct acpi_buffer input = { (acpi_size) sizeof(args), &args }; |
| 2219 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 2220 | union acpi_object *obj; |
| 2221 | acpi_status status; |
| 2222 | |
| 2223 | status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID, |
Pali Rohár | 0fe5726 | 2017-08-12 09:44:16 +0200 | [diff] [blame] | 2224 | 0, asus->debug.method_id, |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 2225 | &input, &output); |
| 2226 | |
| 2227 | if (ACPI_FAILURE(status)) |
| 2228 | return -EIO; |
| 2229 | |
| 2230 | obj = (union acpi_object *)output.pointer; |
| 2231 | if (obj && obj->type == ACPI_TYPE_INTEGER) |
| 2232 | seq_printf(m, "%#x(%#x, %#x) = %#x\n", asus->debug.method_id, |
| 2233 | asus->debug.dev_id, asus->debug.ctrl_param, |
| 2234 | (u32) obj->integer.value); |
| 2235 | else |
| 2236 | seq_printf(m, "%#x(%#x, %#x) = t:%d\n", asus->debug.method_id, |
| 2237 | asus->debug.dev_id, asus->debug.ctrl_param, |
Dan Carpenter | a1d6086 | 2011-03-15 10:07:37 +0300 | [diff] [blame] | 2238 | obj ? obj->type : -1); |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 2239 | |
| 2240 | kfree(obj); |
| 2241 | |
| 2242 | return 0; |
| 2243 | } |
| 2244 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2245 | static struct asus_wmi_debugfs_node asus_wmi_debug_files[] = { |
| 2246 | {NULL, "devs", show_devs}, |
| 2247 | {NULL, "dsts", show_dsts}, |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 2248 | {NULL, "call", show_call}, |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2249 | }; |
| 2250 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2251 | static int asus_wmi_debugfs_open(struct inode *inode, struct file *file) |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2252 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2253 | struct asus_wmi_debugfs_node *node = inode->i_private; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2254 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2255 | return single_open(file, node->show, node->asus); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2256 | } |
| 2257 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2258 | static const struct file_operations asus_wmi_debugfs_io_ops = { |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2259 | .owner = THIS_MODULE, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2260 | .open = asus_wmi_debugfs_open, |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2261 | .read = seq_read, |
| 2262 | .llseek = seq_lseek, |
| 2263 | .release = single_release, |
| 2264 | }; |
| 2265 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2266 | static void asus_wmi_debugfs_exit(struct asus_wmi *asus) |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2267 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2268 | debugfs_remove_recursive(asus->debug.root); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2269 | } |
| 2270 | |
Greg Kroah-Hartman | d2785d3 | 2019-06-12 14:12:52 +0200 | [diff] [blame] | 2271 | static void asus_wmi_debugfs_init(struct asus_wmi *asus) |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2272 | { |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2273 | int i; |
| 2274 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2275 | asus->debug.root = debugfs_create_dir(asus->driver->name, NULL); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2276 | |
Greg Kroah-Hartman | d2785d3 | 2019-06-12 14:12:52 +0200 | [diff] [blame] | 2277 | debugfs_create_x32("method_id", S_IRUGO | S_IWUSR, asus->debug.root, |
| 2278 | &asus->debug.method_id); |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 2279 | |
Greg Kroah-Hartman | d2785d3 | 2019-06-12 14:12:52 +0200 | [diff] [blame] | 2280 | debugfs_create_x32("dev_id", S_IRUGO | S_IWUSR, asus->debug.root, |
| 2281 | &asus->debug.dev_id); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2282 | |
Greg Kroah-Hartman | d2785d3 | 2019-06-12 14:12:52 +0200 | [diff] [blame] | 2283 | debugfs_create_x32("ctrl_param", S_IRUGO | S_IWUSR, asus->debug.root, |
| 2284 | &asus->debug.ctrl_param); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2285 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2286 | for (i = 0; i < ARRAY_SIZE(asus_wmi_debug_files); i++) { |
| 2287 | struct asus_wmi_debugfs_node *node = &asus_wmi_debug_files[i]; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2288 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2289 | node->asus = asus; |
Greg Kroah-Hartman | d2785d3 | 2019-06-12 14:12:52 +0200 | [diff] [blame] | 2290 | debugfs_create_file(node->name, S_IFREG | S_IRUGO, |
| 2291 | asus->debug.root, node, |
| 2292 | &asus_wmi_debugfs_io_ops); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2293 | } |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2294 | } |
| 2295 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 2296 | /* Init / exit ****************************************************************/ |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 2297 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2298 | static int asus_wmi_add(struct platform_device *pdev) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 2299 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2300 | struct platform_driver *pdrv = to_platform_driver(pdev->dev.driver); |
| 2301 | struct asus_wmi_driver *wdrv = to_asus_wmi_driver(pdrv); |
| 2302 | struct asus_wmi *asus; |
Hans de Goede | d8c66f6 | 2014-07-08 10:47:21 +0200 | [diff] [blame] | 2303 | const char *chassis_type; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 2304 | acpi_status status; |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2305 | int err; |
AceLan Kao | a50bd12 | 2012-07-26 17:13:31 +0800 | [diff] [blame] | 2306 | u32 result; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 2307 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2308 | asus = kzalloc(sizeof(struct asus_wmi), GFP_KERNEL); |
| 2309 | if (!asus) |
Corentin Chary | a04ce29 | 2011-02-06 13:28:33 +0100 | [diff] [blame] | 2310 | return -ENOMEM; |
| 2311 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2312 | asus->driver = wdrv; |
| 2313 | asus->platform_device = pdev; |
| 2314 | wdrv->platform_device = pdev; |
| 2315 | platform_set_drvdata(asus->platform_device, asus); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2316 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 2317 | if (wdrv->detect_quirks) |
| 2318 | wdrv->detect_quirks(asus->driver); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 2319 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2320 | err = asus_wmi_platform_init(asus); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2321 | if (err) |
| 2322 | goto fail_platform; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 2323 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 2324 | err = fan_boost_mode_check_present(asus); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2325 | if (err) |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 2326 | goto fail_fan_boost_mode; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2327 | |
| 2328 | err = asus_wmi_sysfs_init(asus->platform_device); |
| 2329 | if (err) |
| 2330 | goto fail_sysfs; |
| 2331 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2332 | err = asus_wmi_input_init(asus); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 2333 | if (err) |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2334 | goto fail_input; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2335 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 2336 | err = asus_wmi_fan_init(asus); /* probably no problems on error */ |
| 2337 | asus_hwmon_fan_set_auto(asus); |
| 2338 | |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 2339 | err = asus_wmi_hwmon_init(asus); |
| 2340 | if (err) |
| 2341 | goto fail_hwmon; |
| 2342 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2343 | err = asus_wmi_led_init(asus); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 2344 | if (err) |
| 2345 | goto fail_leds; |
| 2346 | |
João Paulo Rechi Vita | 71050ae | 2017-02-20 14:50:22 -0500 | [diff] [blame] | 2347 | asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WLAN, &result); |
| 2348 | if (result & (ASUS_WMI_DSTS_PRESENCE_BIT | ASUS_WMI_DSTS_USER_BIT)) |
| 2349 | asus->driver->wlan_ctrl_by_user = 1; |
| 2350 | |
João Paulo Rechi Vita | d1c4e9b | 2017-02-20 14:50:23 -0500 | [diff] [blame] | 2351 | if (!(asus->driver->wlan_ctrl_by_user && ashs_present())) { |
João Paulo Rechi Vita | a977e59 | 2016-06-13 16:57:31 -0400 | [diff] [blame] | 2352 | err = asus_wmi_rfkill_init(asus); |
| 2353 | if (err) |
| 2354 | goto fail_rfkill; |
| 2355 | } |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 2356 | |
Oleksij Rempel | e9b6151 | 2017-04-28 16:19:49 +0200 | [diff] [blame] | 2357 | if (asus->driver->quirks->wmi_force_als_set) |
| 2358 | asus_wmi_set_als(); |
| 2359 | |
Hans de Goede | d8c66f6 | 2014-07-08 10:47:21 +0200 | [diff] [blame] | 2360 | /* Some Asus desktop boards export an acpi-video backlight interface, |
| 2361 | stop this from showing up */ |
| 2362 | chassis_type = dmi_get_system_info(DMI_CHASSIS_TYPE); |
| 2363 | if (chassis_type && !strcmp(chassis_type, "3")) |
Hans de Goede | 62c4aa1 | 2015-06-16 16:27:58 +0200 | [diff] [blame] | 2364 | acpi_video_set_dmi_backlight_type(acpi_backlight_vendor); |
| 2365 | |
AceLan Kao | 272c77d | 2012-06-13 09:32:06 +0200 | [diff] [blame] | 2366 | if (asus->driver->quirks->wmi_backlight_power) |
Hans de Goede | 62c4aa1 | 2015-06-16 16:27:58 +0200 | [diff] [blame] | 2367 | acpi_video_set_dmi_backlight_type(acpi_backlight_vendor); |
| 2368 | |
zino lin | 999d437 | 2016-08-28 16:12:06 +0800 | [diff] [blame] | 2369 | if (asus->driver->quirks->wmi_backlight_native) |
| 2370 | acpi_video_set_dmi_backlight_type(acpi_backlight_native); |
| 2371 | |
Kai-Chuan Hsieh | 8023eff | 2016-09-01 23:55:55 +0800 | [diff] [blame] | 2372 | if (asus->driver->quirks->xusb2pr) |
| 2373 | asus_wmi_set_xusb2pr(asus); |
| 2374 | |
Hans de Goede | 62c4aa1 | 2015-06-16 16:27:58 +0200 | [diff] [blame] | 2375 | if (acpi_video_get_backlight_type() == acpi_backlight_vendor) { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2376 | err = asus_wmi_backlight_init(asus); |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 2377 | if (err && err != -ENODEV) |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2378 | goto fail_backlight; |
Hans de Goede | 401fee8 | 2019-06-12 09:02:02 +0200 | [diff] [blame] | 2379 | } else if (asus->driver->quirks->wmi_backlight_set_devstate) |
João Paulo Rechi Vita | 78f3ac7 | 2018-10-31 17:21:26 -0700 | [diff] [blame] | 2380 | err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BACKLIGHT, 2, NULL); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 2381 | |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 2382 | if (asus_wmi_has_fnlock_key(asus)) { |
| 2383 | asus->fnlock_locked = true; |
| 2384 | asus_wmi_fnlock_update(asus); |
| 2385 | } |
| 2386 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2387 | status = wmi_install_notify_handler(asus->driver->event_guid, |
| 2388 | asus_wmi_notify, asus); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 2389 | if (ACPI_FAILURE(status)) { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2390 | pr_err("Unable to register notify handler - %d\n", status); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 2391 | err = -ENODEV; |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2392 | goto fail_wmi_handler; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 2393 | } |
| 2394 | |
Greg Kroah-Hartman | d2785d3 | 2019-06-12 14:12:52 +0200 | [diff] [blame] | 2395 | asus_wmi_debugfs_init(asus); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2396 | |
Corentin Chary | a04ce29 | 2011-02-06 13:28:33 +0100 | [diff] [blame] | 2397 | return 0; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 2398 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2399 | fail_wmi_handler: |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2400 | asus_wmi_backlight_exit(asus); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2401 | fail_backlight: |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2402 | asus_wmi_rfkill_exit(asus); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 2403 | fail_rfkill: |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2404 | asus_wmi_led_exit(asus); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 2405 | fail_leds: |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 2406 | fail_hwmon: |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2407 | asus_wmi_input_exit(asus); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2408 | fail_input: |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2409 | asus_wmi_sysfs_exit(asus->platform_device); |
| 2410 | fail_sysfs: |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame^] | 2411 | fail_fan_boost_mode: |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2412 | fail_platform: |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2413 | kfree(asus); |
Corentin Chary | a04ce29 | 2011-02-06 13:28:33 +0100 | [diff] [blame] | 2414 | return err; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 2415 | } |
| 2416 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2417 | static int asus_wmi_remove(struct platform_device *device) |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 2418 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2419 | struct asus_wmi *asus; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 2420 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2421 | asus = platform_get_drvdata(device); |
| 2422 | wmi_remove_notify_handler(asus->driver->event_guid); |
| 2423 | asus_wmi_backlight_exit(asus); |
| 2424 | asus_wmi_input_exit(asus); |
| 2425 | asus_wmi_led_exit(asus); |
| 2426 | asus_wmi_rfkill_exit(asus); |
| 2427 | asus_wmi_debugfs_exit(asus); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2428 | asus_wmi_sysfs_exit(asus->platform_device); |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 2429 | asus_hwmon_fan_set_auto(asus); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 2430 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2431 | kfree(asus); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 2432 | return 0; |
| 2433 | } |
| 2434 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 2435 | /* Platform driver - hibernate/resume callbacks *******************************/ |
| 2436 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2437 | static int asus_hotk_thaw(struct device *device) |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 2438 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2439 | struct asus_wmi *asus = dev_get_drvdata(device); |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 2440 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 2441 | if (asus->wlan.rfkill) { |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 2442 | bool wlan; |
| 2443 | |
| 2444 | /* |
| 2445 | * Work around bios bug - acpi _PTS turns off the wireless led |
| 2446 | * during suspend. Normally it restores it on resume, but |
| 2447 | * we should kick it ourselves in case hibernation is aborted. |
| 2448 | */ |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2449 | wlan = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WLAN); |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2450 | asus_wmi_set_devstate(ASUS_WMI_DEVID_WLAN, wlan, NULL); |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | return 0; |
| 2454 | } |
| 2455 | |
Oleksij Rempel | 3073404 | 2015-09-14 11:16:30 +0200 | [diff] [blame] | 2456 | static int asus_hotk_resume(struct device *device) |
| 2457 | { |
| 2458 | struct asus_wmi *asus = dev_get_drvdata(device); |
| 2459 | |
| 2460 | if (!IS_ERR_OR_NULL(asus->kbd_led.dev)) |
Jian-Hong Pan | 9fe44fc | 2018-09-27 16:50:09 +0800 | [diff] [blame] | 2461 | kbd_led_update(asus); |
Oleksij Rempel | 3073404 | 2015-09-14 11:16:30 +0200 | [diff] [blame] | 2462 | |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 2463 | if (asus_wmi_has_fnlock_key(asus)) |
| 2464 | asus_wmi_fnlock_update(asus); |
Oleksij Rempel | 3073404 | 2015-09-14 11:16:30 +0200 | [diff] [blame] | 2465 | return 0; |
| 2466 | } |
| 2467 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2468 | static int asus_hotk_restore(struct device *device) |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 2469 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2470 | struct asus_wmi *asus = dev_get_drvdata(device); |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 2471 | int bl; |
| 2472 | |
| 2473 | /* Refresh both wlan rfkill state and pci hotplug */ |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 2474 | if (asus->wlan.rfkill) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2475 | asus_rfkill_hotplug(asus); |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 2476 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 2477 | if (asus->bluetooth.rfkill) { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2478 | bl = !asus_wmi_get_devstate_simple(asus, |
| 2479 | ASUS_WMI_DEVID_BLUETOOTH); |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 2480 | rfkill_set_sw_state(asus->bluetooth.rfkill, bl); |
Corentin Chary | 2e9e159 | 2011-02-06 13:28:37 +0100 | [diff] [blame] | 2481 | } |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 2482 | if (asus->wimax.rfkill) { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2483 | bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WIMAX); |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 2484 | rfkill_set_sw_state(asus->wimax.rfkill, bl); |
Corentin Chary | 2e9e159 | 2011-02-06 13:28:37 +0100 | [diff] [blame] | 2485 | } |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 2486 | if (asus->wwan3g.rfkill) { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2487 | bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WWAN3G); |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 2488 | rfkill_set_sw_state(asus->wwan3g.rfkill, bl); |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 2489 | } |
Corentin Chary | 43be8bd | 2011-07-01 11:34:40 +0200 | [diff] [blame] | 2490 | if (asus->gps.rfkill) { |
| 2491 | bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_GPS); |
| 2492 | rfkill_set_sw_state(asus->gps.rfkill, bl); |
| 2493 | } |
Corentin Chary | a912d32 | 2011-07-01 11:34:41 +0200 | [diff] [blame] | 2494 | if (asus->uwb.rfkill) { |
| 2495 | bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_UWB); |
| 2496 | rfkill_set_sw_state(asus->uwb.rfkill, bl); |
| 2497 | } |
Oleksij Rempel | 3073404 | 2015-09-14 11:16:30 +0200 | [diff] [blame] | 2498 | if (!IS_ERR_OR_NULL(asus->kbd_led.dev)) |
Jian-Hong Pan | 9fe44fc | 2018-09-27 16:50:09 +0800 | [diff] [blame] | 2499 | kbd_led_update(asus); |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 2500 | |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 2501 | if (asus_wmi_has_fnlock_key(asus)) |
| 2502 | asus_wmi_fnlock_update(asus); |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 2503 | return 0; |
| 2504 | } |
| 2505 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2506 | static const struct dev_pm_ops asus_pm_ops = { |
| 2507 | .thaw = asus_hotk_thaw, |
| 2508 | .restore = asus_hotk_restore, |
Oleksij Rempel | 3073404 | 2015-09-14 11:16:30 +0200 | [diff] [blame] | 2509 | .resume = asus_hotk_resume, |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 2510 | }; |
| 2511 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 2512 | /* Registration ***************************************************************/ |
| 2513 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2514 | static int asus_wmi_probe(struct platform_device *pdev) |
Corentin Chary | d358cb5 | 2010-11-29 08:14:14 +0100 | [diff] [blame] | 2515 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2516 | struct platform_driver *pdrv = to_platform_driver(pdev->dev.driver); |
| 2517 | struct asus_wmi_driver *wdrv = to_asus_wmi_driver(pdrv); |
| 2518 | int ret; |
Corentin Chary | d358cb5 | 2010-11-29 08:14:14 +0100 | [diff] [blame] | 2519 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2520 | if (!wmi_has_guid(ASUS_WMI_MGMT_GUID)) { |
Hans de Goede | c994611 | 2019-01-21 14:24:36 +0100 | [diff] [blame] | 2521 | pr_warn("ASUS Management GUID not found\n"); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 2522 | return -ENODEV; |
| 2523 | } |
| 2524 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2525 | if (wdrv->event_guid && !wmi_has_guid(wdrv->event_guid)) { |
Hans de Goede | c994611 | 2019-01-21 14:24:36 +0100 | [diff] [blame] | 2526 | pr_warn("ASUS Event GUID not found\n"); |
Corentin Chary | d358cb5 | 2010-11-29 08:14:14 +0100 | [diff] [blame] | 2527 | return -ENODEV; |
| 2528 | } |
| 2529 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2530 | if (wdrv->probe) { |
| 2531 | ret = wdrv->probe(pdev); |
| 2532 | if (ret) |
| 2533 | return ret; |
| 2534 | } |
| 2535 | |
| 2536 | return asus_wmi_add(pdev); |
Corentin Chary | a04ce29 | 2011-02-06 13:28:33 +0100 | [diff] [blame] | 2537 | } |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 2538 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2539 | static bool used; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 2540 | |
Corentin Chary | 8fe8c25 | 2011-07-01 11:34:32 +0200 | [diff] [blame] | 2541 | int __init_or_module asus_wmi_register_driver(struct asus_wmi_driver *driver) |
Corentin Chary | a04ce29 | 2011-02-06 13:28:33 +0100 | [diff] [blame] | 2542 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2543 | struct platform_driver *platform_driver; |
| 2544 | struct platform_device *platform_device; |
| 2545 | |
| 2546 | if (used) |
| 2547 | return -EBUSY; |
| 2548 | |
| 2549 | platform_driver = &driver->platform_driver; |
| 2550 | platform_driver->remove = asus_wmi_remove; |
| 2551 | platform_driver->driver.owner = driver->owner; |
| 2552 | platform_driver->driver.name = driver->name; |
| 2553 | platform_driver->driver.pm = &asus_pm_ops; |
| 2554 | |
| 2555 | platform_device = platform_create_bundle(platform_driver, |
| 2556 | asus_wmi_probe, |
Corentin Chary | a04ce29 | 2011-02-06 13:28:33 +0100 | [diff] [blame] | 2557 | NULL, 0, NULL, 0); |
| 2558 | if (IS_ERR(platform_device)) |
| 2559 | return PTR_ERR(platform_device); |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2560 | |
| 2561 | used = true; |
| 2562 | return 0; |
| 2563 | } |
| 2564 | EXPORT_SYMBOL_GPL(asus_wmi_register_driver); |
| 2565 | |
| 2566 | void asus_wmi_unregister_driver(struct asus_wmi_driver *driver) |
| 2567 | { |
| 2568 | platform_device_unregister(driver->platform_device); |
| 2569 | platform_driver_unregister(&driver->platform_driver); |
| 2570 | used = false; |
| 2571 | } |
| 2572 | EXPORT_SYMBOL_GPL(asus_wmi_unregister_driver); |
| 2573 | |
| 2574 | static int __init asus_wmi_init(void) |
| 2575 | { |
vic | 0ed6065 | 2013-05-22 21:32:10 +0300 | [diff] [blame] | 2576 | pr_info("ASUS WMI generic driver loaded\n"); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 2577 | return 0; |
| 2578 | } |
| 2579 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2580 | static void __exit asus_wmi_exit(void) |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 2581 | { |
vic | 0ed6065 | 2013-05-22 21:32:10 +0300 | [diff] [blame] | 2582 | pr_info("ASUS WMI generic driver unloaded\n"); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 2583 | } |
| 2584 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2585 | module_init(asus_wmi_init); |
| 2586 | module_exit(asus_wmi_exit); |