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> |
Luke D. Jones | c63d44a | 2021-08-19 07:07:31 +1200 | [diff] [blame] | 29 | #include <linux/platform_profile.h> |
Kristian Klausen | 7973353 | 2019-09-09 19:31:28 +0200 | [diff] [blame] | 30 | #include <linux/power_supply.h> |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 31 | #include <linux/hwmon.h> |
| 32 | #include <linux/hwmon-sysfs.h> |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 33 | #include <linux/debugfs.h> |
| 34 | #include <linux/seq_file.h> |
Daniel Drake | ffb6ce7 | 2018-10-09 14:40:55 +0800 | [diff] [blame] | 35 | #include <linux/platform_data/x86/asus-wmi.h> |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 36 | #include <linux/platform_device.h> |
Lv Zheng | 8b48463 | 2013-12-03 08:49:16 +0800 | [diff] [blame] | 37 | #include <linux/acpi.h> |
Hans de Goede | d8c66f6 | 2014-07-08 10:47:21 +0200 | [diff] [blame] | 38 | #include <linux/dmi.h> |
Akinobu Mita | f07b9fd | 2020-01-30 22:15:37 -0800 | [diff] [blame] | 39 | #include <linux/units.h> |
Kristian Klausen | 7973353 | 2019-09-09 19:31:28 +0200 | [diff] [blame] | 40 | |
| 41 | #include <acpi/battery.h> |
AceLan Kao | 272c77d | 2012-06-13 09:32:06 +0200 | [diff] [blame] | 42 | #include <acpi/video.h> |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 43 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 44 | #include "asus-wmi.h" |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 45 | |
Corentin Chary | 5909c65 | 2012-12-17 16:00:05 -0800 | [diff] [blame] | 46 | MODULE_AUTHOR("Corentin Chary <corentin.chary@gmail.com>, " |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 47 | "Yong Wang <yong.y.wang@intel.com>"); |
| 48 | MODULE_DESCRIPTION("Asus Generic WMI Driver"); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 49 | MODULE_LICENSE("GPL"); |
| 50 | |
Luca Stefani | ce357fd | 2021-03-23 22:01:26 +0100 | [diff] [blame] | 51 | static bool fnlock_default = true; |
| 52 | module_param(fnlock_default, bool, 0444); |
| 53 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 54 | #define to_asus_wmi_driver(pdrv) \ |
| 55 | (container_of((pdrv), struct asus_wmi_driver, platform_driver)) |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 56 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 57 | #define ASUS_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66" |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 58 | |
Corentin Chary | 33e0e6f | 2011-02-06 13:28:34 +0100 | [diff] [blame] | 59 | #define NOTIFY_BRNUP_MIN 0x11 |
| 60 | #define NOTIFY_BRNUP_MAX 0x1f |
| 61 | #define NOTIFY_BRNDOWN_MIN 0x20 |
| 62 | #define NOTIFY_BRNDOWN_MAX 0x2e |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 63 | #define NOTIFY_FNLOCK_TOGGLE 0x4e |
Hans de Goede | b0dbd97 | 2020-05-10 14:24:31 +0200 | [diff] [blame] | 64 | #define NOTIFY_KBD_DOCK_CHANGE 0x75 |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 65 | #define NOTIFY_KBD_BRTUP 0xc4 |
| 66 | #define NOTIFY_KBD_BRTDWN 0xc5 |
Chris Chiu | ed99d29 | 2018-06-20 22:46:45 +0800 | [diff] [blame] | 67 | #define NOTIFY_KBD_BRTTOGGLE 0xc7 |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 68 | #define NOTIFY_KBD_FBM 0x99 |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 69 | #define NOTIFY_KBD_TTP 0xae |
Samuel Čavoj | ea856ec | 2020-10-21 00:09:44 +0200 | [diff] [blame] | 70 | #define NOTIFY_LID_FLIP 0xfa |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 71 | |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 72 | #define ASUS_WMI_FNLOCK_BIOS_DISABLED BIT(0) |
| 73 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 74 | #define ASUS_FAN_DESC "cpu_fan" |
| 75 | #define ASUS_FAN_MFUN 0x13 |
| 76 | #define ASUS_FAN_SFUN_READ 0x06 |
| 77 | #define ASUS_FAN_SFUN_WRITE 0x07 |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 78 | |
| 79 | /* Based on standard hwmon pwmX_enable values */ |
Daniel Drake | e3168b8 | 2019-07-29 16:27:39 +0800 | [diff] [blame] | 80 | #define ASUS_FAN_CTRL_FULLSPEED 0 |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 81 | #define ASUS_FAN_CTRL_MANUAL 1 |
| 82 | #define ASUS_FAN_CTRL_AUTO 2 |
| 83 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 84 | #define ASUS_FAN_BOOST_MODE_NORMAL 0 |
| 85 | #define ASUS_FAN_BOOST_MODE_OVERBOOST 1 |
| 86 | #define ASUS_FAN_BOOST_MODE_OVERBOOST_MASK 0x01 |
| 87 | #define ASUS_FAN_BOOST_MODE_SILENT 2 |
| 88 | #define ASUS_FAN_BOOST_MODE_SILENT_MASK 0x02 |
| 89 | #define ASUS_FAN_BOOST_MODES_MASK 0x03 |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 90 | |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 91 | #define ASUS_THROTTLE_THERMAL_POLICY_DEFAULT 0 |
| 92 | #define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST 1 |
| 93 | #define ASUS_THROTTLE_THERMAL_POLICY_SILENT 2 |
| 94 | |
Kai-Chuan Hsieh | 8023eff | 2016-09-01 23:55:55 +0800 | [diff] [blame] | 95 | #define USB_INTEL_XUSB2PR 0xD0 |
| 96 | #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 |
| 97 | |
Yurii Pavlovskyi | e0668f2 | 2019-05-14 21:00:31 +0200 | [diff] [blame] | 98 | #define ASUS_ACPI_UID_ASUSWMI "ASUSWMI" |
Yurii Pavlovskyi | 1a373d1 | 2019-05-14 21:02:09 +0200 | [diff] [blame] | 99 | #define ASUS_ACPI_UID_ATK "ATK" |
| 100 | |
| 101 | #define WMI_EVENT_QUEUE_SIZE 0x10 |
| 102 | #define WMI_EVENT_QUEUE_END 0x1 |
| 103 | #define WMI_EVENT_MASK 0xFFFF |
| 104 | /* The WMI hotkey event value is always the same. */ |
| 105 | #define WMI_EVENT_VALUE_ATK 0xFF |
Yurii Pavlovskyi | e0668f2 | 2019-05-14 21:00:31 +0200 | [diff] [blame] | 106 | |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 107 | #define WMI_EVENT_MASK 0xFFFF |
| 108 | |
João Paulo Rechi Vita | 71050ae | 2017-02-20 14:50:22 -0500 | [diff] [blame] | 109 | static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL }; |
| 110 | |
João Paulo Rechi Vita | cf48bf9 | 2018-05-22 14:30:15 -0700 | [diff] [blame] | 111 | static bool ashs_present(void) |
| 112 | { |
| 113 | int i = 0; |
| 114 | while (ashs_ids[i]) { |
| 115 | if (acpi_dev_found(ashs_ids[i++])) |
| 116 | return true; |
| 117 | } |
| 118 | return false; |
| 119 | } |
| 120 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 121 | struct bios_args { |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 122 | u32 arg0; |
| 123 | u32 arg1; |
Yurii Pavlovskyi | 98e865a | 2019-05-14 20:54:50 +0200 | [diff] [blame] | 124 | u32 arg2; /* At least TUF Gaming series uses 3 dword input buffer. */ |
Chris Chiu | 7b91f15 | 2020-05-22 15:44:24 +0800 | [diff] [blame] | 125 | u32 arg4; |
| 126 | u32 arg5; |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 127 | } __packed; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 128 | |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 129 | /* |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 130 | * Struct that's used for all methods called via AGFN. Naming is |
| 131 | * identically to the AML code. |
| 132 | */ |
| 133 | struct agfn_args { |
| 134 | u16 mfun; /* probably "Multi-function" to be called */ |
| 135 | u16 sfun; /* probably "Sub-function" to be called */ |
| 136 | u16 len; /* size of the hole struct, including subfunction fields */ |
| 137 | u8 stas; /* not used by now */ |
| 138 | u8 err; /* zero on success */ |
| 139 | } __packed; |
| 140 | |
| 141 | /* struct used for calling fan read and write methods */ |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 142 | struct agfn_fan_args { |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 143 | struct agfn_args agfn; /* common fields */ |
| 144 | u8 fan; /* fan number: 0: set auto mode 1: 1st fan */ |
| 145 | u32 speed; /* read: RPM/100 - write: 0-255 */ |
| 146 | } __packed; |
| 147 | |
| 148 | /* |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 149 | * <platform>/ - debugfs root directory |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 150 | * dev_id - current dev_id |
| 151 | * ctrl_param - current ctrl_param |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 152 | * method_id - current method_id |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 153 | * devs - call DEVS(dev_id, ctrl_param) and print result |
| 154 | * dsts - call DSTS(dev_id) and print result |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 155 | * call - call method_id(dev_id, ctrl_param) and print result |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 156 | */ |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 157 | struct asus_wmi_debug { |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 158 | struct dentry *root; |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 159 | u32 method_id; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 160 | u32 dev_id; |
| 161 | u32 ctrl_param; |
| 162 | }; |
| 163 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 164 | struct asus_rfkill { |
| 165 | struct asus_wmi *asus; |
| 166 | struct rfkill *rfkill; |
| 167 | u32 dev_id; |
| 168 | }; |
| 169 | |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 170 | enum fan_type { |
| 171 | FAN_TYPE_NONE = 0, |
| 172 | FAN_TYPE_AGFN, /* deprecated on newer platforms */ |
Daniel Drake | e3168b8 | 2019-07-29 16:27:39 +0800 | [diff] [blame] | 173 | FAN_TYPE_SPEC83, /* starting in Spec 8.3, use CPU_FAN_CTRL */ |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 174 | }; |
| 175 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 176 | struct asus_wmi { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 177 | int dsts_id; |
Corentin Chary | 46dbca8 | 2011-02-26 10:20:38 +0100 | [diff] [blame] | 178 | int spec; |
| 179 | int sfun; |
Yurii Pavlovskyi | 1a373d1 | 2019-05-14 21:02:09 +0200 | [diff] [blame] | 180 | bool wmi_event_queue; |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 181 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 182 | struct input_dev *inputdev; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 183 | struct backlight_device *backlight_device; |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 184 | struct platform_device *platform_device; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 185 | |
AceLan Kao | 6cae06e | 2012-07-27 16:51:59 +0800 | [diff] [blame] | 186 | struct led_classdev wlan_led; |
| 187 | int wlan_led_wk; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 188 | struct led_classdev tpd_led; |
| 189 | int tpd_led_wk; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 190 | struct led_classdev kbd_led; |
| 191 | int kbd_led_wk; |
Maxime Bellengé | 4c05984 | 2017-09-23 18:23:37 +0200 | [diff] [blame] | 192 | struct led_classdev lightbar_led; |
| 193 | int lightbar_led_wk; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 194 | struct workqueue_struct *led_workqueue; |
| 195 | struct work_struct tpd_led_work; |
AceLan Kao | 6cae06e | 2012-07-27 16:51:59 +0800 | [diff] [blame] | 196 | struct work_struct wlan_led_work; |
Maxime Bellengé | 4c05984 | 2017-09-23 18:23:37 +0200 | [diff] [blame] | 197 | struct work_struct lightbar_led_work; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 198 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 199 | struct asus_rfkill wlan; |
| 200 | struct asus_rfkill bluetooth; |
| 201 | struct asus_rfkill wimax; |
| 202 | struct asus_rfkill wwan3g; |
Corentin Chary | 43be8bd | 2011-07-01 11:34:40 +0200 | [diff] [blame] | 203 | struct asus_rfkill gps; |
Corentin Chary | a912d32 | 2011-07-01 11:34:41 +0200 | [diff] [blame] | 204 | struct asus_rfkill uwb; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 205 | |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 206 | enum fan_type fan_type; |
| 207 | int fan_pwm_mode; |
| 208 | int agfn_pwm; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 209 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 210 | bool fan_boost_mode_available; |
| 211 | u8 fan_boost_mode_mask; |
| 212 | u8 fan_boost_mode; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 213 | |
Luke D. Jones | 382b91d | 2021-08-07 14:36:56 +1200 | [diff] [blame] | 214 | bool egpu_enable_available; // 0 = enable |
| 215 | bool egpu_enable; |
| 216 | |
Luke D. Jones | 98829e8 | 2021-08-07 14:36:55 +1200 | [diff] [blame] | 217 | bool dgpu_disable_available; |
| 218 | bool dgpu_disable; |
| 219 | |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 220 | bool throttle_thermal_policy_available; |
| 221 | u8 throttle_thermal_policy_mode; |
| 222 | |
Luke D. Jones | c63d44a | 2021-08-19 07:07:31 +1200 | [diff] [blame] | 223 | struct platform_profile_handler platform_profile_handler; |
| 224 | bool platform_profile_support; |
| 225 | |
Kristian Klausen | 7973353 | 2019-09-09 19:31:28 +0200 | [diff] [blame] | 226 | // The RSOC controls the maximum charging percentage. |
| 227 | bool battery_rsoc_available; |
Kristian Klausen | d507a54 | 2019-08-05 21:23:05 +0200 | [diff] [blame] | 228 | |
Luke D. Jones | ca91ea34 | 2021-08-07 14:36:54 +1200 | [diff] [blame] | 229 | bool panel_overdrive_available; |
| 230 | bool panel_overdrive; |
| 231 | |
Lukas Wunner | 125450f | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 232 | struct hotplug_slot hotplug_slot; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 233 | struct mutex hotplug_lock; |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 234 | struct mutex wmi_lock; |
| 235 | struct workqueue_struct *hotplug_workqueue; |
| 236 | struct work_struct hotplug_work; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 237 | |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 238 | bool fnlock_locked; |
| 239 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 240 | struct asus_wmi_debug debug; |
| 241 | |
| 242 | struct asus_wmi_driver *driver; |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 243 | }; |
| 244 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 245 | /* WMI ************************************************************************/ |
| 246 | |
Yurii Pavlovskyi | 98e865a | 2019-05-14 20:54:50 +0200 | [diff] [blame] | 247 | static int asus_wmi_evaluate_method3(u32 method_id, |
| 248 | u32 arg0, u32 arg1, u32 arg2, u32 *retval) |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 249 | { |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 250 | struct bios_args args = { |
| 251 | .arg0 = arg0, |
| 252 | .arg1 = arg1, |
Yurii Pavlovskyi | 98e865a | 2019-05-14 20:54:50 +0200 | [diff] [blame] | 253 | .arg2 = arg2, |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 254 | }; |
| 255 | struct acpi_buffer input = { (acpi_size) sizeof(args), &args }; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 256 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 257 | acpi_status status; |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 258 | union acpi_object *obj; |
Rickard Strandqvist | 8ad3be1 | 2014-06-01 14:58:52 +0200 | [diff] [blame] | 259 | u32 tmp = 0; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 260 | |
Pali Rohár | 0fe5726 | 2017-08-12 09:44:16 +0200 | [diff] [blame] | 261 | status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID, 0, method_id, |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 262 | &input, &output); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 263 | |
| 264 | if (ACPI_FAILURE(status)) |
Yurii Pavlovskyi | 1827f3f | 2019-05-14 21:03:50 +0200 | [diff] [blame] | 265 | return -EIO; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 266 | |
| 267 | obj = (union acpi_object *)output.pointer; |
| 268 | if (obj && obj->type == ACPI_TYPE_INTEGER) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 269 | tmp = (u32) obj->integer.value; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 270 | |
Corentin Chary | 2a3f006 | 2010-11-29 08:14:10 +0100 | [diff] [blame] | 271 | if (retval) |
| 272 | *retval = tmp; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 273 | |
| 274 | kfree(obj); |
| 275 | |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 276 | if (tmp == ASUS_WMI_UNSUPPORTED_METHOD) |
| 277 | return -ENODEV; |
| 278 | |
| 279 | return 0; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 280 | } |
Yurii Pavlovskyi | 98e865a | 2019-05-14 20:54:50 +0200 | [diff] [blame] | 281 | |
| 282 | int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1, u32 *retval) |
| 283 | { |
| 284 | return asus_wmi_evaluate_method3(method_id, arg0, arg1, 0, retval); |
| 285 | } |
Daniel Drake | ffb6ce7 | 2018-10-09 14:40:55 +0800 | [diff] [blame] | 286 | EXPORT_SYMBOL_GPL(asus_wmi_evaluate_method); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 287 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 288 | static int asus_wmi_evaluate_method_agfn(const struct acpi_buffer args) |
| 289 | { |
| 290 | struct acpi_buffer input; |
| 291 | u64 phys_addr; |
| 292 | u32 retval; |
Colin Ian King | 6568d0c | 2020-05-07 23:04:55 +0100 | [diff] [blame] | 293 | u32 status; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 294 | |
| 295 | /* |
| 296 | * Copy to dma capable address otherwise memory corruption occurs as |
| 297 | * bios has to be able to access it. |
| 298 | */ |
Fuqian Huang | 340f25f | 2019-07-04 00:29:51 +0800 | [diff] [blame] | 299 | input.pointer = kmemdup(args.pointer, args.length, GFP_DMA | GFP_KERNEL); |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 300 | input.length = args.length; |
| 301 | if (!input.pointer) |
| 302 | return -ENOMEM; |
| 303 | phys_addr = virt_to_phys(input.pointer); |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 304 | |
| 305 | status = asus_wmi_evaluate_method(ASUS_WMI_METHODID_AGFN, |
| 306 | phys_addr, 0, &retval); |
| 307 | if (!status) |
| 308 | memcpy(args.pointer, input.pointer, args.length); |
| 309 | |
| 310 | kfree(input.pointer); |
| 311 | if (status) |
| 312 | return -ENXIO; |
| 313 | |
| 314 | return retval; |
| 315 | } |
| 316 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 317 | 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] | 318 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 319 | return asus_wmi_evaluate_method(asus->dsts_id, dev_id, 0, retval); |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | static int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param, |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 323 | u32 *retval) |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 324 | { |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 325 | return asus_wmi_evaluate_method(ASUS_WMI_METHODID_DEVS, dev_id, |
| 326 | ctrl_param, retval); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 327 | } |
| 328 | |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 329 | /* Helper for special devices with magic return codes */ |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 330 | static int asus_wmi_get_devstate_bits(struct asus_wmi *asus, |
| 331 | u32 dev_id, u32 mask) |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 332 | { |
| 333 | u32 retval = 0; |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 334 | int err; |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 335 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 336 | err = asus_wmi_get_devstate(asus, dev_id, &retval); |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 337 | if (err < 0) |
| 338 | return err; |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 339 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 340 | if (!(retval & ASUS_WMI_DSTS_PRESENCE_BIT)) |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 341 | return -ENODEV; |
| 342 | |
Corentin Chary | a75fe0d | 2011-02-26 10:20:34 +0100 | [diff] [blame] | 343 | if (mask == ASUS_WMI_DSTS_STATUS_BIT) { |
| 344 | if (retval & ASUS_WMI_DSTS_UNKNOWN_BIT) |
| 345 | return -ENODEV; |
| 346 | } |
| 347 | |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 348 | return retval & mask; |
| 349 | } |
| 350 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 351 | 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] | 352 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 353 | return asus_wmi_get_devstate_bits(asus, dev_id, |
| 354 | ASUS_WMI_DSTS_STATUS_BIT); |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 355 | } |
| 356 | |
Daniel Drake | f1fc032 | 2019-07-29 16:27:38 +0800 | [diff] [blame] | 357 | static bool asus_wmi_dev_is_present(struct asus_wmi *asus, u32 dev_id) |
| 358 | { |
| 359 | u32 retval; |
| 360 | int status = asus_wmi_get_devstate(asus, dev_id, &retval); |
| 361 | |
| 362 | return status == 0 && (retval & ASUS_WMI_DSTS_PRESENCE_BIT); |
| 363 | } |
| 364 | |
Hans de Goede | fed5003 | 2020-05-10 14:24:30 +0200 | [diff] [blame] | 365 | /* Input **********************************************************************/ |
| 366 | |
| 367 | static int asus_wmi_input_init(struct asus_wmi *asus) |
| 368 | { |
Hans de Goede | b0dbd97 | 2020-05-10 14:24:31 +0200 | [diff] [blame] | 369 | int err, result; |
Hans de Goede | fed5003 | 2020-05-10 14:24:30 +0200 | [diff] [blame] | 370 | |
| 371 | asus->inputdev = input_allocate_device(); |
| 372 | if (!asus->inputdev) |
| 373 | return -ENOMEM; |
| 374 | |
| 375 | asus->inputdev->name = asus->driver->input_name; |
| 376 | asus->inputdev->phys = asus->driver->input_phys; |
| 377 | asus->inputdev->id.bustype = BUS_HOST; |
| 378 | asus->inputdev->dev.parent = &asus->platform_device->dev; |
| 379 | set_bit(EV_REP, asus->inputdev->evbit); |
| 380 | |
| 381 | err = sparse_keymap_setup(asus->inputdev, asus->driver->keymap, NULL); |
| 382 | if (err) |
| 383 | goto err_free_dev; |
| 384 | |
Hans de Goede | 1797d58 | 2020-09-16 16:14:39 +0200 | [diff] [blame] | 385 | if (asus->driver->quirks->use_kbd_dock_devid) { |
| 386 | result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_KBD_DOCK); |
| 387 | if (result >= 0) { |
| 388 | input_set_capability(asus->inputdev, EV_SW, SW_TABLET_MODE); |
| 389 | input_report_switch(asus->inputdev, SW_TABLET_MODE, !result); |
| 390 | } else if (result != -ENODEV) { |
| 391 | pr_err("Error checking for keyboard-dock: %d\n", result); |
| 392 | } |
Hans de Goede | b0dbd97 | 2020-05-10 14:24:31 +0200 | [diff] [blame] | 393 | } |
| 394 | |
Samuel Čavoj | ea856ec | 2020-10-21 00:09:44 +0200 | [diff] [blame] | 395 | if (asus->driver->quirks->use_lid_flip_devid) { |
| 396 | result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_LID_FLIP); |
| 397 | if (result < 0) |
| 398 | asus->driver->quirks->use_lid_flip_devid = 0; |
| 399 | if (result >= 0) { |
| 400 | input_set_capability(asus->inputdev, EV_SW, SW_TABLET_MODE); |
| 401 | input_report_switch(asus->inputdev, SW_TABLET_MODE, result); |
| 402 | } else if (result == -ENODEV) { |
| 403 | pr_err("This device has lid_flip quirk but got ENODEV checking it. This is a bug."); |
| 404 | } else { |
| 405 | pr_err("Error checking for lid-flip: %d\n", result); |
| 406 | } |
| 407 | } |
| 408 | |
Hans de Goede | fed5003 | 2020-05-10 14:24:30 +0200 | [diff] [blame] | 409 | err = input_register_device(asus->inputdev); |
| 410 | if (err) |
| 411 | goto err_free_dev; |
| 412 | |
| 413 | return 0; |
| 414 | |
| 415 | err_free_dev: |
| 416 | input_free_device(asus->inputdev); |
| 417 | return err; |
| 418 | } |
| 419 | |
| 420 | static void asus_wmi_input_exit(struct asus_wmi *asus) |
| 421 | { |
| 422 | if (asus->inputdev) |
| 423 | input_unregister_device(asus->inputdev); |
| 424 | |
| 425 | asus->inputdev = NULL; |
| 426 | } |
| 427 | |
Samuel Čavoj | ea856ec | 2020-10-21 00:09:44 +0200 | [diff] [blame] | 428 | /* Tablet mode ****************************************************************/ |
| 429 | |
| 430 | static void lid_flip_tablet_mode_get_state(struct asus_wmi *asus) |
| 431 | { |
| 432 | int result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_LID_FLIP); |
| 433 | |
| 434 | if (result >= 0) { |
| 435 | input_report_switch(asus->inputdev, SW_TABLET_MODE, result); |
| 436 | input_sync(asus->inputdev); |
| 437 | } |
| 438 | } |
| 439 | |
Luke D. Jones | 98829e8 | 2021-08-07 14:36:55 +1200 | [diff] [blame] | 440 | /* dGPU ********************************************************************/ |
| 441 | static int dgpu_disable_check_present(struct asus_wmi *asus) |
| 442 | { |
| 443 | u32 result; |
| 444 | int err; |
| 445 | |
| 446 | asus->dgpu_disable_available = false; |
| 447 | |
| 448 | err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_DGPU, &result); |
| 449 | if (err) { |
| 450 | if (err == -ENODEV) |
| 451 | return 0; |
| 452 | return err; |
| 453 | } |
| 454 | |
| 455 | if (result & ASUS_WMI_DSTS_PRESENCE_BIT) { |
| 456 | asus->dgpu_disable_available = true; |
| 457 | asus->dgpu_disable = result & ASUS_WMI_DSTS_STATUS_BIT; |
| 458 | } |
| 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | static int dgpu_disable_write(struct asus_wmi *asus) |
| 464 | { |
| 465 | u32 retval; |
| 466 | u8 value; |
| 467 | int err; |
| 468 | |
| 469 | /* Don't rely on type conversion */ |
| 470 | value = asus->dgpu_disable ? 1 : 0; |
| 471 | |
| 472 | err = asus_wmi_set_devstate(ASUS_WMI_DEVID_DGPU, value, &retval); |
| 473 | if (err) { |
| 474 | pr_warn("Failed to set dgpu disable: %d\n", err); |
| 475 | return err; |
| 476 | } |
| 477 | |
Jiapeng Chong | 828857f | 2021-08-25 18:37:02 +0800 | [diff] [blame] | 478 | if (retval > 1) { |
Luke D. Jones | 98829e8 | 2021-08-07 14:36:55 +1200 | [diff] [blame] | 479 | pr_warn("Failed to set dgpu disable (retval): 0x%x\n", retval); |
| 480 | return -EIO; |
| 481 | } |
| 482 | |
| 483 | sysfs_notify(&asus->platform_device->dev.kobj, NULL, "dgpu_disable"); |
| 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | static ssize_t dgpu_disable_show(struct device *dev, |
| 489 | struct device_attribute *attr, char *buf) |
| 490 | { |
| 491 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 492 | u8 mode = asus->dgpu_disable; |
| 493 | |
| 494 | return sysfs_emit(buf, "%d\n", mode); |
| 495 | } |
| 496 | |
| 497 | /* |
| 498 | * A user may be required to store the value twice, typcial store first, then |
| 499 | * rescan PCI bus to activate power, then store a second time to save correctly. |
| 500 | * The reason for this is that an extra code path in the ACPI is enabled when |
| 501 | * the device and bus are powered. |
| 502 | */ |
| 503 | static ssize_t dgpu_disable_store(struct device *dev, |
| 504 | struct device_attribute *attr, |
| 505 | const char *buf, size_t count) |
| 506 | { |
| 507 | bool disable; |
| 508 | int result; |
| 509 | |
| 510 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 511 | |
| 512 | result = kstrtobool(buf, &disable); |
| 513 | if (result) |
| 514 | return result; |
| 515 | |
| 516 | asus->dgpu_disable = disable; |
| 517 | |
| 518 | result = dgpu_disable_write(asus); |
| 519 | if (result) |
| 520 | return result; |
| 521 | |
| 522 | return count; |
| 523 | } |
| 524 | |
| 525 | static DEVICE_ATTR_RW(dgpu_disable); |
| 526 | |
Luke D. Jones | 382b91d | 2021-08-07 14:36:56 +1200 | [diff] [blame] | 527 | /* eGPU ********************************************************************/ |
| 528 | static int egpu_enable_check_present(struct asus_wmi *asus) |
| 529 | { |
| 530 | u32 result; |
| 531 | int err; |
| 532 | |
| 533 | asus->egpu_enable_available = false; |
| 534 | |
| 535 | err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_EGPU, &result); |
| 536 | if (err) { |
| 537 | if (err == -ENODEV) |
| 538 | return 0; |
| 539 | return err; |
| 540 | } |
| 541 | |
| 542 | if (result & ASUS_WMI_DSTS_PRESENCE_BIT) { |
| 543 | asus->egpu_enable_available = true; |
| 544 | asus->egpu_enable = result & ASUS_WMI_DSTS_STATUS_BIT; |
| 545 | } |
| 546 | |
| 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | static int egpu_enable_write(struct asus_wmi *asus) |
| 551 | { |
| 552 | u32 retval; |
| 553 | u8 value; |
| 554 | int err; |
| 555 | |
| 556 | /* Don't rely on type conversion */ |
| 557 | value = asus->egpu_enable ? 1 : 0; |
| 558 | |
| 559 | err = asus_wmi_set_devstate(ASUS_WMI_DEVID_EGPU, value, &retval); |
| 560 | |
| 561 | if (err) { |
| 562 | pr_warn("Failed to set egpu disable: %d\n", err); |
| 563 | return err; |
| 564 | } |
| 565 | |
Jiapeng Chong | 828857f | 2021-08-25 18:37:02 +0800 | [diff] [blame] | 566 | if (retval > 1) { |
Luke D. Jones | 382b91d | 2021-08-07 14:36:56 +1200 | [diff] [blame] | 567 | pr_warn("Failed to set egpu disable (retval): 0x%x\n", retval); |
| 568 | return -EIO; |
| 569 | } |
| 570 | |
| 571 | sysfs_notify(&asus->platform_device->dev.kobj, NULL, "egpu_enable"); |
| 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | |
| 576 | static ssize_t egpu_enable_show(struct device *dev, |
| 577 | struct device_attribute *attr, char *buf) |
| 578 | { |
| 579 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 580 | bool mode = asus->egpu_enable; |
| 581 | |
| 582 | return sysfs_emit(buf, "%d\n", mode); |
| 583 | } |
| 584 | |
| 585 | /* The ACPI call to enable the eGPU also disables the internal dGPU */ |
| 586 | static ssize_t egpu_enable_store(struct device *dev, |
| 587 | struct device_attribute *attr, |
| 588 | const char *buf, size_t count) |
| 589 | { |
| 590 | bool enable; |
| 591 | int result; |
| 592 | |
| 593 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 594 | |
| 595 | result = kstrtobool(buf, &enable); |
| 596 | if (result) |
| 597 | return result; |
| 598 | |
| 599 | asus->egpu_enable = enable; |
| 600 | |
| 601 | result = egpu_enable_write(asus); |
| 602 | if (result) |
| 603 | return result; |
| 604 | |
| 605 | /* Ensure that the kernel status of dgpu is updated */ |
| 606 | result = dgpu_disable_check_present(asus); |
| 607 | if (result) |
| 608 | return result; |
| 609 | |
| 610 | return count; |
| 611 | } |
| 612 | |
| 613 | static DEVICE_ATTR_RW(egpu_enable); |
| 614 | |
Kristian Klausen | 7973353 | 2019-09-09 19:31:28 +0200 | [diff] [blame] | 615 | /* Battery ********************************************************************/ |
| 616 | |
| 617 | /* The battery maximum charging percentage */ |
| 618 | static int charge_end_threshold; |
| 619 | |
| 620 | static ssize_t charge_control_end_threshold_store(struct device *dev, |
| 621 | struct device_attribute *attr, |
| 622 | const char *buf, size_t count) |
| 623 | { |
| 624 | int value, ret, rv; |
| 625 | |
| 626 | ret = kstrtouint(buf, 10, &value); |
| 627 | if (ret) |
| 628 | return ret; |
| 629 | |
| 630 | if (value < 0 || value > 100) |
| 631 | return -EINVAL; |
| 632 | |
| 633 | ret = asus_wmi_set_devstate(ASUS_WMI_DEVID_RSOC, value, &rv); |
| 634 | if (ret) |
| 635 | return ret; |
| 636 | |
| 637 | if (rv != 1) |
| 638 | return -EIO; |
| 639 | |
| 640 | /* There isn't any method in the DSDT to read the threshold, so we |
| 641 | * save the threshold. |
| 642 | */ |
| 643 | charge_end_threshold = value; |
| 644 | return count; |
| 645 | } |
| 646 | |
| 647 | static ssize_t charge_control_end_threshold_show(struct device *device, |
| 648 | struct device_attribute *attr, |
| 649 | char *buf) |
| 650 | { |
| 651 | return sprintf(buf, "%d\n", charge_end_threshold); |
| 652 | } |
| 653 | |
| 654 | static DEVICE_ATTR_RW(charge_control_end_threshold); |
| 655 | |
| 656 | static int asus_wmi_battery_add(struct power_supply *battery) |
| 657 | { |
| 658 | /* The WMI method does not provide a way to specific a battery, so we |
| 659 | * just assume it is the first battery. |
Kristian Klausen | 6b3586d | 2020-03-03 19:02:15 +0100 | [diff] [blame] | 660 | * Note: On some newer ASUS laptops (Zenbook UM431DA), the primary/first |
| 661 | * battery is named BATT. |
Kristian Klausen | 7973353 | 2019-09-09 19:31:28 +0200 | [diff] [blame] | 662 | */ |
Kristian Klausen | 6b3586d | 2020-03-03 19:02:15 +0100 | [diff] [blame] | 663 | if (strcmp(battery->desc->name, "BAT0") != 0 && |
Vasiliy Kupriakov | 9a33e37 | 2020-06-30 20:56:01 +0300 | [diff] [blame] | 664 | strcmp(battery->desc->name, "BAT1") != 0 && |
Marius Iacob | 1d2dd37 | 2020-08-31 15:58:01 +0300 | [diff] [blame] | 665 | strcmp(battery->desc->name, "BATC") != 0 && |
Kristian Klausen | 6b3586d | 2020-03-03 19:02:15 +0100 | [diff] [blame] | 666 | strcmp(battery->desc->name, "BATT") != 0) |
Kristian Klausen | 7973353 | 2019-09-09 19:31:28 +0200 | [diff] [blame] | 667 | return -ENODEV; |
| 668 | |
| 669 | if (device_create_file(&battery->dev, |
| 670 | &dev_attr_charge_control_end_threshold)) |
| 671 | return -ENODEV; |
| 672 | |
| 673 | /* The charge threshold is only reset when the system is power cycled, |
| 674 | * and we can't get the current threshold so let set it to 100% when |
| 675 | * a battery is added. |
| 676 | */ |
| 677 | asus_wmi_set_devstate(ASUS_WMI_DEVID_RSOC, 100, NULL); |
| 678 | charge_end_threshold = 100; |
| 679 | |
| 680 | return 0; |
| 681 | } |
| 682 | |
| 683 | static int asus_wmi_battery_remove(struct power_supply *battery) |
| 684 | { |
| 685 | device_remove_file(&battery->dev, |
| 686 | &dev_attr_charge_control_end_threshold); |
| 687 | return 0; |
| 688 | } |
| 689 | |
| 690 | static struct acpi_battery_hook battery_hook = { |
| 691 | .add_battery = asus_wmi_battery_add, |
| 692 | .remove_battery = asus_wmi_battery_remove, |
| 693 | .name = "ASUS Battery Extension", |
| 694 | }; |
| 695 | |
| 696 | static void asus_wmi_battery_init(struct asus_wmi *asus) |
| 697 | { |
| 698 | asus->battery_rsoc_available = false; |
| 699 | if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_RSOC)) { |
| 700 | asus->battery_rsoc_available = true; |
| 701 | battery_hook_register(&battery_hook); |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | static void asus_wmi_battery_exit(struct asus_wmi *asus) |
| 706 | { |
| 707 | if (asus->battery_rsoc_available) |
| 708 | battery_hook_unregister(&battery_hook); |
| 709 | } |
| 710 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 711 | /* LEDs ***********************************************************************/ |
| 712 | |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 713 | /* |
| 714 | * These functions actually update the LED's, and are called from a |
| 715 | * workqueue. By doing this as separate work rather than when the LED |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 716 | * subsystem asks, we avoid messing with the Asus ACPI stuff during a |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 717 | * potentially bad time, such as a timer interrupt. |
| 718 | */ |
| 719 | static void tpd_led_update(struct work_struct *work) |
| 720 | { |
| 721 | int ctrl_param; |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 722 | struct asus_wmi *asus; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 723 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 724 | asus = container_of(work, struct asus_wmi, tpd_led_work); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 725 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 726 | ctrl_param = asus->tpd_led_wk; |
| 727 | asus_wmi_set_devstate(ASUS_WMI_DEVID_TOUCHPAD_LED, ctrl_param, NULL); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | static void tpd_led_set(struct led_classdev *led_cdev, |
| 731 | enum led_brightness value) |
| 732 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 733 | struct asus_wmi *asus; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 734 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 735 | asus = container_of(led_cdev, struct asus_wmi, tpd_led); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 736 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 737 | asus->tpd_led_wk = !!value; |
| 738 | queue_work(asus->led_workqueue, &asus->tpd_led_work); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 739 | } |
| 740 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 741 | static int read_tpd_led_state(struct asus_wmi *asus) |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 742 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 743 | return asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_TOUCHPAD_LED); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | static enum led_brightness tpd_led_get(struct led_classdev *led_cdev) |
| 747 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 748 | struct asus_wmi *asus; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 749 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 750 | asus = container_of(led_cdev, struct asus_wmi, tpd_led); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 751 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 752 | return read_tpd_led_state(asus); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 753 | } |
| 754 | |
Jian-Hong Pan | 9fe44fc | 2018-09-27 16:50:09 +0800 | [diff] [blame] | 755 | static void kbd_led_update(struct asus_wmi *asus) |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 756 | { |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 757 | int ctrl_param = 0; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 758 | |
Jian-Hong Pan | 26e66a0 | 2019-12-30 16:30:45 +0800 | [diff] [blame] | 759 | ctrl_param = 0x80 | (asus->kbd_led_wk & 0x7F); |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 760 | asus_wmi_set_devstate(ASUS_WMI_DEVID_KBD_BACKLIGHT, ctrl_param, NULL); |
| 761 | } |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 762 | |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 763 | static int kbd_led_read(struct asus_wmi *asus, int *level, int *env) |
| 764 | { |
| 765 | int retval; |
| 766 | |
| 767 | /* |
| 768 | * bits 0-2: level |
| 769 | * bit 7: light on/off |
| 770 | * bit 8-10: environment (0: dark, 1: normal, 2: light) |
| 771 | * bit 17: status unknown |
| 772 | */ |
| 773 | retval = asus_wmi_get_devstate_bits(asus, ASUS_WMI_DEVID_KBD_BACKLIGHT, |
| 774 | 0xFFFF); |
| 775 | |
Corentin Chary | af965e9 | 2011-07-01 11:34:34 +0200 | [diff] [blame] | 776 | /* Unknown status is considered as off */ |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 777 | if (retval == 0x8000) |
Corentin Chary | af965e9 | 2011-07-01 11:34:34 +0200 | [diff] [blame] | 778 | retval = 0; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 779 | |
Andy Shevchenko | 127e1df | 2019-08-16 14:07:17 +0300 | [diff] [blame] | 780 | if (retval < 0) |
| 781 | return retval; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 782 | |
Andy Shevchenko | 127e1df | 2019-08-16 14:07:17 +0300 | [diff] [blame] | 783 | if (level) |
| 784 | *level = retval & 0x7F; |
| 785 | if (env) |
| 786 | *env = (retval >> 8) & 0x7F; |
| 787 | return 0; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 788 | } |
| 789 | |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 790 | 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] | 791 | { |
| 792 | struct asus_wmi *asus; |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 793 | int max_level; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 794 | |
| 795 | asus = container_of(led_cdev, struct asus_wmi, kbd_led); |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 796 | max_level = asus->kbd_led.max_brightness; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 797 | |
Andy Shevchenko | 2275752 | 2019-08-16 14:10:03 +0300 | [diff] [blame] | 798 | asus->kbd_led_wk = clamp_val(value, 0, max_level); |
Jian-Hong Pan | 9fe44fc | 2018-09-27 16:50:09 +0800 | [diff] [blame] | 799 | kbd_led_update(asus); |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 800 | } |
| 801 | |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 802 | static void kbd_led_set(struct led_classdev *led_cdev, |
| 803 | enum led_brightness value) |
| 804 | { |
Yurii Pavlovskyi | 3e58167 | 2019-05-14 21:07:46 +0200 | [diff] [blame] | 805 | /* Prevent disabling keyboard backlight on module unregister */ |
| 806 | if (led_cdev->flags & LED_UNREGISTERING) |
| 807 | return; |
| 808 | |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 809 | do_kbd_led_set(led_cdev, value); |
| 810 | } |
| 811 | |
Jian-Hong Pan | 29f6eb5 | 2018-10-22 18:00:04 +0800 | [diff] [blame] | 812 | static void kbd_led_set_by_kbd(struct asus_wmi *asus, enum led_brightness value) |
| 813 | { |
| 814 | struct led_classdev *led_cdev = &asus->kbd_led; |
| 815 | |
| 816 | do_kbd_led_set(led_cdev, value); |
| 817 | led_classdev_notify_brightness_hw_changed(led_cdev, asus->kbd_led_wk); |
| 818 | } |
| 819 | |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 820 | static enum led_brightness kbd_led_get(struct led_classdev *led_cdev) |
| 821 | { |
| 822 | struct asus_wmi *asus; |
| 823 | int retval, value; |
| 824 | |
| 825 | asus = container_of(led_cdev, struct asus_wmi, kbd_led); |
| 826 | |
| 827 | retval = kbd_led_read(asus, &value, NULL); |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 828 | if (retval < 0) |
| 829 | return retval; |
| 830 | |
| 831 | return value; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 832 | } |
| 833 | |
AceLan Kao | 6cae06e | 2012-07-27 16:51:59 +0800 | [diff] [blame] | 834 | static int wlan_led_unknown_state(struct asus_wmi *asus) |
| 835 | { |
| 836 | u32 result; |
| 837 | |
| 838 | asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WIRELESS_LED, &result); |
| 839 | |
| 840 | return result & ASUS_WMI_DSTS_UNKNOWN_BIT; |
| 841 | } |
| 842 | |
AceLan Kao | 6cae06e | 2012-07-27 16:51:59 +0800 | [diff] [blame] | 843 | static void wlan_led_update(struct work_struct *work) |
| 844 | { |
| 845 | int ctrl_param; |
| 846 | struct asus_wmi *asus; |
| 847 | |
| 848 | asus = container_of(work, struct asus_wmi, wlan_led_work); |
| 849 | |
| 850 | ctrl_param = asus->wlan_led_wk; |
| 851 | asus_wmi_set_devstate(ASUS_WMI_DEVID_WIRELESS_LED, ctrl_param, NULL); |
| 852 | } |
| 853 | |
| 854 | static void wlan_led_set(struct led_classdev *led_cdev, |
| 855 | enum led_brightness value) |
| 856 | { |
| 857 | struct asus_wmi *asus; |
| 858 | |
| 859 | asus = container_of(led_cdev, struct asus_wmi, wlan_led); |
| 860 | |
| 861 | asus->wlan_led_wk = !!value; |
| 862 | queue_work(asus->led_workqueue, &asus->wlan_led_work); |
| 863 | } |
| 864 | |
| 865 | static enum led_brightness wlan_led_get(struct led_classdev *led_cdev) |
| 866 | { |
| 867 | struct asus_wmi *asus; |
| 868 | u32 result; |
| 869 | |
| 870 | asus = container_of(led_cdev, struct asus_wmi, wlan_led); |
| 871 | asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WIRELESS_LED, &result); |
| 872 | |
| 873 | return result & ASUS_WMI_DSTS_BRIGHTNESS_MASK; |
| 874 | } |
| 875 | |
Maxime Bellengé | 4c05984 | 2017-09-23 18:23:37 +0200 | [diff] [blame] | 876 | static void lightbar_led_update(struct work_struct *work) |
| 877 | { |
| 878 | struct asus_wmi *asus; |
| 879 | int ctrl_param; |
| 880 | |
| 881 | asus = container_of(work, struct asus_wmi, lightbar_led_work); |
| 882 | |
| 883 | ctrl_param = asus->lightbar_led_wk; |
| 884 | asus_wmi_set_devstate(ASUS_WMI_DEVID_LIGHTBAR, ctrl_param, NULL); |
| 885 | } |
| 886 | |
| 887 | static void lightbar_led_set(struct led_classdev *led_cdev, |
| 888 | enum led_brightness value) |
| 889 | { |
| 890 | struct asus_wmi *asus; |
| 891 | |
| 892 | asus = container_of(led_cdev, struct asus_wmi, lightbar_led); |
| 893 | |
| 894 | asus->lightbar_led_wk = !!value; |
| 895 | queue_work(asus->led_workqueue, &asus->lightbar_led_work); |
| 896 | } |
| 897 | |
| 898 | static enum led_brightness lightbar_led_get(struct led_classdev *led_cdev) |
| 899 | { |
| 900 | struct asus_wmi *asus; |
| 901 | u32 result; |
| 902 | |
| 903 | asus = container_of(led_cdev, struct asus_wmi, lightbar_led); |
| 904 | asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_LIGHTBAR, &result); |
| 905 | |
| 906 | return result & ASUS_WMI_DSTS_LIGHTBAR_MASK; |
| 907 | } |
| 908 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 909 | static void asus_wmi_led_exit(struct asus_wmi *asus) |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 910 | { |
Andy Shevchenko | 2225dba | 2020-05-07 19:37:23 +0300 | [diff] [blame] | 911 | led_classdev_unregister(&asus->kbd_led); |
| 912 | led_classdev_unregister(&asus->tpd_led); |
| 913 | led_classdev_unregister(&asus->wlan_led); |
| 914 | led_classdev_unregister(&asus->lightbar_led); |
| 915 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 916 | if (asus->led_workqueue) |
| 917 | destroy_workqueue(asus->led_workqueue); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 918 | } |
| 919 | |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 920 | static int asus_wmi_led_init(struct asus_wmi *asus) |
| 921 | { |
Oleksij Rempel | 3073404 | 2015-09-14 11:16:30 +0200 | [diff] [blame] | 922 | int rv = 0, led_val; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 923 | |
| 924 | asus->led_workqueue = create_singlethread_workqueue("led_workqueue"); |
| 925 | if (!asus->led_workqueue) |
| 926 | return -ENOMEM; |
| 927 | |
| 928 | if (read_tpd_led_state(asus) >= 0) { |
| 929 | INIT_WORK(&asus->tpd_led_work, tpd_led_update); |
| 930 | |
| 931 | asus->tpd_led.name = "asus::touchpad"; |
| 932 | asus->tpd_led.brightness_set = tpd_led_set; |
| 933 | asus->tpd_led.brightness_get = tpd_led_get; |
| 934 | asus->tpd_led.max_brightness = 1; |
| 935 | |
| 936 | rv = led_classdev_register(&asus->platform_device->dev, |
| 937 | &asus->tpd_led); |
| 938 | if (rv) |
| 939 | goto error; |
| 940 | } |
| 941 | |
Yurii Pavlovskyi | 8853a2f | 2019-05-14 20:51:25 +0200 | [diff] [blame] | 942 | if (!kbd_led_read(asus, &led_val, NULL)) { |
Oleksij Rempel | 3073404 | 2015-09-14 11:16:30 +0200 | [diff] [blame] | 943 | asus->kbd_led_wk = led_val; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 944 | asus->kbd_led.name = "asus::kbd_backlight"; |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 945 | asus->kbd_led.flags = LED_BRIGHT_HW_CHANGED; |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 946 | asus->kbd_led.brightness_set = kbd_led_set; |
| 947 | asus->kbd_led.brightness_get = kbd_led_get; |
| 948 | asus->kbd_led.max_brightness = 3; |
| 949 | |
| 950 | rv = led_classdev_register(&asus->platform_device->dev, |
| 951 | &asus->kbd_led); |
AceLan Kao | 6cae06e | 2012-07-27 16:51:59 +0800 | [diff] [blame] | 952 | if (rv) |
| 953 | goto error; |
| 954 | } |
| 955 | |
Daniel Drake | f1fc032 | 2019-07-29 16:27:38 +0800 | [diff] [blame] | 956 | if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_WIRELESS_LED) |
| 957 | && (asus->driver->quirks->wapf > 0)) { |
AceLan Kao | 6cae06e | 2012-07-27 16:51:59 +0800 | [diff] [blame] | 958 | INIT_WORK(&asus->wlan_led_work, wlan_led_update); |
| 959 | |
| 960 | asus->wlan_led.name = "asus::wlan"; |
| 961 | asus->wlan_led.brightness_set = wlan_led_set; |
| 962 | if (!wlan_led_unknown_state(asus)) |
| 963 | asus->wlan_led.brightness_get = wlan_led_get; |
| 964 | asus->wlan_led.flags = LED_CORE_SUSPENDRESUME; |
| 965 | asus->wlan_led.max_brightness = 1; |
| 966 | asus->wlan_led.default_trigger = "asus-wlan"; |
| 967 | |
| 968 | rv = led_classdev_register(&asus->platform_device->dev, |
| 969 | &asus->wlan_led); |
Maxime Bellengé | 4c05984 | 2017-09-23 18:23:37 +0200 | [diff] [blame] | 970 | if (rv) |
| 971 | goto error; |
| 972 | } |
| 973 | |
Daniel Drake | f1fc032 | 2019-07-29 16:27:38 +0800 | [diff] [blame] | 974 | if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_LIGHTBAR)) { |
Maxime Bellengé | 4c05984 | 2017-09-23 18:23:37 +0200 | [diff] [blame] | 975 | INIT_WORK(&asus->lightbar_led_work, lightbar_led_update); |
| 976 | |
| 977 | asus->lightbar_led.name = "asus::lightbar"; |
| 978 | asus->lightbar_led.brightness_set = lightbar_led_set; |
| 979 | asus->lightbar_led.brightness_get = lightbar_led_get; |
| 980 | asus->lightbar_led.max_brightness = 1; |
| 981 | |
| 982 | rv = led_classdev_register(&asus->platform_device->dev, |
| 983 | &asus->lightbar_led); |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | error: |
| 987 | if (rv) |
| 988 | asus_wmi_led_exit(asus); |
| 989 | |
| 990 | return rv; |
| 991 | } |
| 992 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 993 | /* RF *************************************************************************/ |
Corentin Chary | e9809c0 | 2011-07-01 11:34:31 +0200 | [diff] [blame] | 994 | |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 995 | /* |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 996 | * PCI hotplug (for wlan rfkill) |
| 997 | */ |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 998 | static bool asus_wlan_rfkill_blocked(struct asus_wmi *asus) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 999 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 1000 | int result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WLAN); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1001 | |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 1002 | if (result < 0) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1003 | return false; |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 1004 | return !result; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1005 | } |
| 1006 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1007 | static void asus_rfkill_hotplug(struct asus_wmi *asus) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1008 | { |
| 1009 | struct pci_dev *dev; |
| 1010 | struct pci_bus *bus; |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1011 | bool blocked; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1012 | bool absent; |
| 1013 | u32 l; |
| 1014 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1015 | mutex_lock(&asus->wmi_lock); |
| 1016 | blocked = asus_wlan_rfkill_blocked(asus); |
| 1017 | mutex_unlock(&asus->wmi_lock); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1018 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1019 | mutex_lock(&asus->hotplug_lock); |
Rafael J. Wysocki | 8b9ec1d | 2014-01-10 15:27:08 +0100 | [diff] [blame] | 1020 | pci_lock_rescan_remove(); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1021 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1022 | if (asus->wlan.rfkill) |
| 1023 | rfkill_set_sw_state(asus->wlan.rfkill, blocked); |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1024 | |
Lukas Wunner | 125450f | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 1025 | if (asus->hotplug_slot.ops) { |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1026 | bus = pci_find_bus(0, 1); |
| 1027 | if (!bus) { |
Joe Perches | 5ad77dc | 2011-03-29 15:21:35 -0700 | [diff] [blame] | 1028 | pr_warn("Unable to find PCI bus 1?\n"); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1029 | goto out_unlock; |
| 1030 | } |
| 1031 | |
| 1032 | if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) { |
| 1033 | pr_err("Unable to read PCI config space?\n"); |
| 1034 | goto out_unlock; |
| 1035 | } |
| 1036 | absent = (l == 0xffffffff); |
| 1037 | |
| 1038 | if (blocked != absent) { |
Joe Perches | 5ad77dc | 2011-03-29 15:21:35 -0700 | [diff] [blame] | 1039 | pr_warn("BIOS says wireless lan is %s, " |
| 1040 | "but the pci device is %s\n", |
| 1041 | blocked ? "blocked" : "unblocked", |
| 1042 | absent ? "absent" : "present"); |
| 1043 | pr_warn("skipped wireless hotplug as probably " |
| 1044 | "inappropriate for this model\n"); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1045 | goto out_unlock; |
| 1046 | } |
| 1047 | |
| 1048 | if (!blocked) { |
| 1049 | dev = pci_get_slot(bus, 0); |
| 1050 | if (dev) { |
| 1051 | /* Device already present */ |
| 1052 | pci_dev_put(dev); |
| 1053 | goto out_unlock; |
| 1054 | } |
| 1055 | dev = pci_scan_single_device(bus, 0); |
| 1056 | if (dev) { |
| 1057 | pci_bus_assign_resources(bus); |
Yijing Wang | c893d13 | 2014-05-30 11:01:03 +0800 | [diff] [blame] | 1058 | pci_bus_add_device(dev); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1059 | } |
| 1060 | } else { |
| 1061 | dev = pci_get_slot(bus, 0); |
| 1062 | if (dev) { |
Yinghai Lu | 210647a | 2012-02-25 13:54:20 -0800 | [diff] [blame] | 1063 | pci_stop_and_remove_bus_device(dev); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1064 | pci_dev_put(dev); |
| 1065 | } |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | out_unlock: |
Rafael J. Wysocki | 8b9ec1d | 2014-01-10 15:27:08 +0100 | [diff] [blame] | 1070 | pci_unlock_rescan_remove(); |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1071 | mutex_unlock(&asus->hotplug_lock); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1072 | } |
| 1073 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1074 | static void asus_rfkill_notify(acpi_handle handle, u32 event, void *data) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1075 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1076 | struct asus_wmi *asus = data; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1077 | |
| 1078 | if (event != ACPI_NOTIFY_BUS_CHECK) |
| 1079 | return; |
| 1080 | |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1081 | /* |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1082 | * We can't call directly asus_rfkill_hotplug because most |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1083 | * of the time WMBC is still being executed and not reetrant. |
| 1084 | * There is currently no way to tell ACPICA that we want this |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1085 | * method to be serialized, we schedule a asus_rfkill_hotplug |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1086 | * call later, in a safer context. |
| 1087 | */ |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1088 | queue_work(asus->hotplug_workqueue, &asus->hotplug_work); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1089 | } |
| 1090 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1091 | static int asus_register_rfkill_notifier(struct asus_wmi *asus, char *node) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1092 | { |
| 1093 | acpi_status status; |
| 1094 | acpi_handle handle; |
| 1095 | |
| 1096 | status = acpi_get_handle(NULL, node, &handle); |
Andy Shevchenko | 127e1df | 2019-08-16 14:07:17 +0300 | [diff] [blame] | 1097 | if (ACPI_FAILURE(status)) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1098 | return -ENODEV; |
| 1099 | |
Andy Shevchenko | 127e1df | 2019-08-16 14:07:17 +0300 | [diff] [blame] | 1100 | status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, |
| 1101 | asus_rfkill_notify, asus); |
| 1102 | if (ACPI_FAILURE(status)) |
| 1103 | pr_warn("Failed to register notify on %s\n", node); |
| 1104 | |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1105 | return 0; |
| 1106 | } |
| 1107 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1108 | static void asus_unregister_rfkill_notifier(struct asus_wmi *asus, char *node) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1109 | { |
| 1110 | acpi_status status = AE_OK; |
| 1111 | acpi_handle handle; |
| 1112 | |
| 1113 | status = acpi_get_handle(NULL, node, &handle); |
Andy Shevchenko | 127e1df | 2019-08-16 14:07:17 +0300 | [diff] [blame] | 1114 | if (ACPI_FAILURE(status)) |
| 1115 | return; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1116 | |
Andy Shevchenko | 127e1df | 2019-08-16 14:07:17 +0300 | [diff] [blame] | 1117 | status = acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY, |
| 1118 | asus_rfkill_notify); |
| 1119 | if (ACPI_FAILURE(status)) |
| 1120 | pr_err("Error removing rfkill notify handler %s\n", node); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1121 | } |
| 1122 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1123 | static int asus_get_adapter_status(struct hotplug_slot *hotplug_slot, |
| 1124 | u8 *value) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1125 | { |
Lukas Wunner | 125450f | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 1126 | struct asus_wmi *asus = container_of(hotplug_slot, |
| 1127 | struct asus_wmi, hotplug_slot); |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 1128 | int result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WLAN); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1129 | |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 1130 | if (result < 0) |
| 1131 | return result; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1132 | |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 1133 | *value = !!result; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1134 | return 0; |
| 1135 | } |
| 1136 | |
Lukas Wunner | 81c4b5b | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 1137 | static const struct hotplug_slot_ops asus_hotplug_slot_ops = { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1138 | .get_adapter_status = asus_get_adapter_status, |
| 1139 | .get_power_status = asus_get_adapter_status, |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1140 | }; |
| 1141 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1142 | static void asus_hotplug_work(struct work_struct *work) |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1143 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1144 | struct asus_wmi *asus; |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1145 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1146 | asus = container_of(work, struct asus_wmi, hotplug_work); |
| 1147 | asus_rfkill_hotplug(asus); |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1148 | } |
| 1149 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1150 | static int asus_setup_pci_hotplug(struct asus_wmi *asus) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1151 | { |
| 1152 | int ret = -ENOMEM; |
| 1153 | struct pci_bus *bus = pci_find_bus(0, 1); |
| 1154 | |
| 1155 | if (!bus) { |
| 1156 | pr_err("Unable to find wifi PCI bus\n"); |
| 1157 | return -ENODEV; |
| 1158 | } |
| 1159 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1160 | asus->hotplug_workqueue = |
| 1161 | create_singlethread_workqueue("hotplug_workqueue"); |
| 1162 | if (!asus->hotplug_workqueue) |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1163 | goto error_workqueue; |
| 1164 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1165 | INIT_WORK(&asus->hotplug_work, asus_hotplug_work); |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1166 | |
Lukas Wunner | 125450f | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 1167 | asus->hotplug_slot.ops = &asus_hotplug_slot_ops; |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1168 | |
Lukas Wunner | 125450f | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 1169 | ret = pci_hp_register(&asus->hotplug_slot, bus, 0, "asus-wifi"); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1170 | if (ret) { |
| 1171 | pr_err("Unable to register hotplug slot - %d\n", ret); |
| 1172 | goto error_register; |
| 1173 | } |
| 1174 | |
| 1175 | return 0; |
| 1176 | |
| 1177 | error_register: |
Lukas Wunner | 125450f | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 1178 | asus->hotplug_slot.ops = NULL; |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1179 | destroy_workqueue(asus->hotplug_workqueue); |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1180 | error_workqueue: |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1181 | return ret; |
| 1182 | } |
| 1183 | |
| 1184 | /* |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1185 | * Rfkill devices |
| 1186 | */ |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1187 | static int asus_rfkill_set(void *data, bool blocked) |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1188 | { |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1189 | struct asus_rfkill *priv = data; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1190 | u32 ctrl_param = !blocked; |
AceLan Kao | a50bd12 | 2012-07-26 17:13:31 +0800 | [diff] [blame] | 1191 | u32 dev_id = priv->dev_id; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1192 | |
AceLan Kao | a50bd12 | 2012-07-26 17:13:31 +0800 | [diff] [blame] | 1193 | /* |
| 1194 | * If the user bit is set, BIOS can't set and record the wlan status, |
| 1195 | * it will report the value read from id ASUS_WMI_DEVID_WLAN_LED |
| 1196 | * while we query the wlan status through WMI(ASUS_WMI_DEVID_WLAN). |
| 1197 | * So, we have to record wlan status in id ASUS_WMI_DEVID_WLAN_LED |
| 1198 | * while setting the wlan status through WMI. |
| 1199 | * This is also the behavior that windows app will do. |
| 1200 | */ |
| 1201 | if ((dev_id == ASUS_WMI_DEVID_WLAN) && |
| 1202 | priv->asus->driver->wlan_ctrl_by_user) |
| 1203 | dev_id = ASUS_WMI_DEVID_WLAN_LED; |
| 1204 | |
| 1205 | return asus_wmi_set_devstate(dev_id, ctrl_param, NULL); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1206 | } |
| 1207 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1208 | static void asus_rfkill_query(struct rfkill *rfkill, void *data) |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1209 | { |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1210 | struct asus_rfkill *priv = data; |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 1211 | int result; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1212 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 1213 | result = asus_wmi_get_devstate_simple(priv->asus, priv->dev_id); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1214 | |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 1215 | if (result < 0) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1216 | return; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1217 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1218 | rfkill_set_sw_state(priv->rfkill, !result); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1219 | } |
| 1220 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1221 | static int asus_rfkill_wlan_set(void *data, bool blocked) |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1222 | { |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1223 | struct asus_rfkill *priv = data; |
| 1224 | struct asus_wmi *asus = priv->asus; |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1225 | int ret; |
| 1226 | |
| 1227 | /* |
| 1228 | * This handler is enabled only if hotplug is enabled. |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1229 | * In this case, the asus_wmi_set_devstate() will |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1230 | * trigger a wmi notification and we need to wait |
| 1231 | * this call to finish before being able to call |
| 1232 | * any wmi method |
| 1233 | */ |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1234 | mutex_lock(&asus->wmi_lock); |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1235 | ret = asus_rfkill_set(data, blocked); |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1236 | mutex_unlock(&asus->wmi_lock); |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1237 | return ret; |
| 1238 | } |
| 1239 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1240 | static const struct rfkill_ops asus_rfkill_wlan_ops = { |
| 1241 | .set_block = asus_rfkill_wlan_set, |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1242 | .query = asus_rfkill_query, |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1243 | }; |
| 1244 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1245 | static const struct rfkill_ops asus_rfkill_ops = { |
| 1246 | .set_block = asus_rfkill_set, |
| 1247 | .query = asus_rfkill_query, |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1248 | }; |
| 1249 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1250 | static int asus_new_rfkill(struct asus_wmi *asus, |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1251 | struct asus_rfkill *arfkill, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1252 | const char *name, enum rfkill_type type, int dev_id) |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1253 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 1254 | int result = asus_wmi_get_devstate_simple(asus, dev_id); |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1255 | struct rfkill **rfkill = &arfkill->rfkill; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1256 | |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 1257 | if (result < 0) |
| 1258 | return result; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1259 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1260 | arfkill->dev_id = dev_id; |
| 1261 | arfkill->asus = asus; |
| 1262 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 1263 | if (dev_id == ASUS_WMI_DEVID_WLAN && |
| 1264 | asus->driver->quirks->hotplug_wireless) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1265 | *rfkill = rfkill_alloc(name, &asus->platform_device->dev, type, |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1266 | &asus_rfkill_wlan_ops, arfkill); |
Corentin Chary | 279f8f9 | 2011-02-06 13:28:29 +0100 | [diff] [blame] | 1267 | else |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1268 | *rfkill = rfkill_alloc(name, &asus->platform_device->dev, type, |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1269 | &asus_rfkill_ops, arfkill); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1270 | |
| 1271 | if (!*rfkill) |
| 1272 | return -EINVAL; |
| 1273 | |
AceLan Kao | e8f56c8 | 2013-05-30 10:31:50 +0800 | [diff] [blame] | 1274 | if ((dev_id == ASUS_WMI_DEVID_WLAN) && |
AceLan Kao | f515623 | 2014-07-09 16:18:18 +0800 | [diff] [blame] | 1275 | (asus->driver->quirks->wapf > 0)) |
AceLan Kao | 6cae06e | 2012-07-27 16:51:59 +0800 | [diff] [blame] | 1276 | rfkill_set_led_trigger_name(*rfkill, "asus-wlan"); |
| 1277 | |
Corentin Chary | 5c95638 | 2011-02-06 13:28:31 +0100 | [diff] [blame] | 1278 | rfkill_init_sw_state(*rfkill, !result); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1279 | result = rfkill_register(*rfkill); |
| 1280 | if (result) { |
| 1281 | rfkill_destroy(*rfkill); |
| 1282 | *rfkill = NULL; |
| 1283 | return result; |
| 1284 | } |
| 1285 | return 0; |
| 1286 | } |
| 1287 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1288 | static void asus_wmi_rfkill_exit(struct asus_wmi *asus) |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1289 | { |
João Paulo Rechi Vita | cf48bf9 | 2018-05-22 14:30:15 -0700 | [diff] [blame] | 1290 | if (asus->driver->wlan_ctrl_by_user && ashs_present()) |
| 1291 | return; |
| 1292 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1293 | asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P5"); |
| 1294 | asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P6"); |
| 1295 | asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P7"); |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1296 | if (asus->wlan.rfkill) { |
| 1297 | rfkill_unregister(asus->wlan.rfkill); |
| 1298 | rfkill_destroy(asus->wlan.rfkill); |
| 1299 | asus->wlan.rfkill = NULL; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1300 | } |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1301 | /* |
| 1302 | * Refresh pci hotplug in case the rfkill state was changed after |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1303 | * asus_unregister_rfkill_notifier() |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1304 | */ |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1305 | asus_rfkill_hotplug(asus); |
Lukas Wunner | 125450f | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 1306 | if (asus->hotplug_slot.ops) |
| 1307 | pci_hp_deregister(&asus->hotplug_slot); |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1308 | if (asus->hotplug_workqueue) |
| 1309 | destroy_workqueue(asus->hotplug_workqueue); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1310 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1311 | if (asus->bluetooth.rfkill) { |
| 1312 | rfkill_unregister(asus->bluetooth.rfkill); |
| 1313 | rfkill_destroy(asus->bluetooth.rfkill); |
| 1314 | asus->bluetooth.rfkill = NULL; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1315 | } |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1316 | if (asus->wimax.rfkill) { |
| 1317 | rfkill_unregister(asus->wimax.rfkill); |
| 1318 | rfkill_destroy(asus->wimax.rfkill); |
| 1319 | asus->wimax.rfkill = NULL; |
Corentin Chary | 2e9e159 | 2011-02-06 13:28:37 +0100 | [diff] [blame] | 1320 | } |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1321 | if (asus->wwan3g.rfkill) { |
| 1322 | rfkill_unregister(asus->wwan3g.rfkill); |
| 1323 | rfkill_destroy(asus->wwan3g.rfkill); |
| 1324 | asus->wwan3g.rfkill = NULL; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1325 | } |
Corentin Chary | 43be8bd | 2011-07-01 11:34:40 +0200 | [diff] [blame] | 1326 | if (asus->gps.rfkill) { |
| 1327 | rfkill_unregister(asus->gps.rfkill); |
| 1328 | rfkill_destroy(asus->gps.rfkill); |
| 1329 | asus->gps.rfkill = NULL; |
| 1330 | } |
Corentin Chary | a912d32 | 2011-07-01 11:34:41 +0200 | [diff] [blame] | 1331 | if (asus->uwb.rfkill) { |
| 1332 | rfkill_unregister(asus->uwb.rfkill); |
| 1333 | rfkill_destroy(asus->uwb.rfkill); |
| 1334 | asus->uwb.rfkill = NULL; |
| 1335 | } |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1336 | } |
| 1337 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1338 | static int asus_wmi_rfkill_init(struct asus_wmi *asus) |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1339 | { |
| 1340 | int result = 0; |
| 1341 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1342 | mutex_init(&asus->hotplug_lock); |
| 1343 | mutex_init(&asus->wmi_lock); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1344 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1345 | result = asus_new_rfkill(asus, &asus->wlan, "asus-wlan", |
| 1346 | RFKILL_TYPE_WLAN, ASUS_WMI_DEVID_WLAN); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1347 | |
| 1348 | if (result && result != -ENODEV) |
| 1349 | goto exit; |
| 1350 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1351 | result = asus_new_rfkill(asus, &asus->bluetooth, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1352 | "asus-bluetooth", RFKILL_TYPE_BLUETOOTH, |
| 1353 | ASUS_WMI_DEVID_BLUETOOTH); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1354 | |
| 1355 | if (result && result != -ENODEV) |
| 1356 | goto exit; |
| 1357 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1358 | result = asus_new_rfkill(asus, &asus->wimax, "asus-wimax", |
| 1359 | RFKILL_TYPE_WIMAX, ASUS_WMI_DEVID_WIMAX); |
Corentin Chary | 2e9e159 | 2011-02-06 13:28:37 +0100 | [diff] [blame] | 1360 | |
| 1361 | if (result && result != -ENODEV) |
| 1362 | goto exit; |
| 1363 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 1364 | result = asus_new_rfkill(asus, &asus->wwan3g, "asus-wwan3g", |
| 1365 | RFKILL_TYPE_WWAN, ASUS_WMI_DEVID_WWAN3G); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1366 | |
| 1367 | if (result && result != -ENODEV) |
| 1368 | goto exit; |
| 1369 | |
Corentin Chary | 43be8bd | 2011-07-01 11:34:40 +0200 | [diff] [blame] | 1370 | result = asus_new_rfkill(asus, &asus->gps, "asus-gps", |
| 1371 | RFKILL_TYPE_GPS, ASUS_WMI_DEVID_GPS); |
| 1372 | |
| 1373 | if (result && result != -ENODEV) |
| 1374 | goto exit; |
| 1375 | |
Corentin Chary | a912d32 | 2011-07-01 11:34:41 +0200 | [diff] [blame] | 1376 | result = asus_new_rfkill(asus, &asus->uwb, "asus-uwb", |
| 1377 | RFKILL_TYPE_UWB, ASUS_WMI_DEVID_UWB); |
| 1378 | |
| 1379 | if (result && result != -ENODEV) |
| 1380 | goto exit; |
| 1381 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 1382 | if (!asus->driver->quirks->hotplug_wireless) |
Corentin Chary | c14d4b8 | 2011-02-06 13:28:40 +0100 | [diff] [blame] | 1383 | goto exit; |
| 1384 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1385 | result = asus_setup_pci_hotplug(asus); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1386 | /* |
| 1387 | * If we get -EBUSY then something else is handling the PCI hotplug - |
| 1388 | * don't fail in this case |
| 1389 | */ |
| 1390 | if (result == -EBUSY) |
| 1391 | result = 0; |
| 1392 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1393 | asus_register_rfkill_notifier(asus, "\\_SB.PCI0.P0P5"); |
| 1394 | asus_register_rfkill_notifier(asus, "\\_SB.PCI0.P0P6"); |
| 1395 | asus_register_rfkill_notifier(asus, "\\_SB.PCI0.P0P7"); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1396 | /* |
| 1397 | * Refresh pci hotplug in case the rfkill state was changed during |
| 1398 | * setup. |
| 1399 | */ |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1400 | asus_rfkill_hotplug(asus); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 1401 | |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1402 | exit: |
| 1403 | if (result && result != -ENODEV) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 1404 | asus_wmi_rfkill_exit(asus); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1405 | |
| 1406 | if (result == -ENODEV) |
| 1407 | result = 0; |
| 1408 | |
| 1409 | return result; |
| 1410 | } |
| 1411 | |
Luke D. Jones | ca91ea34 | 2021-08-07 14:36:54 +1200 | [diff] [blame] | 1412 | /* Panel Overdrive ************************************************************/ |
| 1413 | static int panel_od_check_present(struct asus_wmi *asus) |
| 1414 | { |
| 1415 | u32 result; |
| 1416 | int err; |
| 1417 | |
| 1418 | asus->panel_overdrive_available = false; |
| 1419 | |
| 1420 | err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_PANEL_OD, &result); |
| 1421 | if (err) { |
| 1422 | if (err == -ENODEV) |
| 1423 | return 0; |
| 1424 | return err; |
| 1425 | } |
| 1426 | |
| 1427 | if (result & ASUS_WMI_DSTS_PRESENCE_BIT) { |
| 1428 | asus->panel_overdrive_available = true; |
| 1429 | asus->panel_overdrive = result & ASUS_WMI_DSTS_STATUS_BIT; |
| 1430 | } |
| 1431 | |
| 1432 | return 0; |
| 1433 | } |
| 1434 | |
| 1435 | static int panel_od_write(struct asus_wmi *asus) |
| 1436 | { |
| 1437 | u32 retval; |
| 1438 | u8 value; |
| 1439 | int err; |
| 1440 | |
| 1441 | /* Don't rely on type conversion */ |
| 1442 | value = asus->panel_overdrive ? 1 : 0; |
| 1443 | |
| 1444 | err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PANEL_OD, value, &retval); |
| 1445 | |
| 1446 | if (err) { |
| 1447 | pr_warn("Failed to set panel overdrive: %d\n", err); |
| 1448 | return err; |
| 1449 | } |
| 1450 | |
Jiapeng Chong | 828857f | 2021-08-25 18:37:02 +0800 | [diff] [blame] | 1451 | if (retval > 1) { |
Luke D. Jones | ca91ea34 | 2021-08-07 14:36:54 +1200 | [diff] [blame] | 1452 | pr_warn("Failed to set panel overdrive (retval): 0x%x\n", retval); |
| 1453 | return -EIO; |
| 1454 | } |
| 1455 | |
| 1456 | sysfs_notify(&asus->platform_device->dev.kobj, NULL, "panel_od"); |
| 1457 | |
| 1458 | return 0; |
| 1459 | } |
| 1460 | |
| 1461 | static ssize_t panel_od_show(struct device *dev, |
| 1462 | struct device_attribute *attr, char *buf) |
| 1463 | { |
| 1464 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 1465 | |
| 1466 | return sysfs_emit(buf, "%d\n", asus->panel_overdrive); |
| 1467 | } |
| 1468 | |
| 1469 | static ssize_t panel_od_store(struct device *dev, |
| 1470 | struct device_attribute *attr, |
| 1471 | const char *buf, size_t count) |
| 1472 | { |
| 1473 | bool overdrive; |
| 1474 | int result; |
| 1475 | |
| 1476 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 1477 | |
| 1478 | result = kstrtobool(buf, &overdrive); |
| 1479 | if (result) |
| 1480 | return result; |
| 1481 | |
| 1482 | asus->panel_overdrive = overdrive; |
| 1483 | result = panel_od_write(asus); |
| 1484 | |
| 1485 | if (result) |
| 1486 | return result; |
| 1487 | |
| 1488 | return count; |
| 1489 | } |
| 1490 | |
| 1491 | static DEVICE_ATTR_RW(panel_od); |
| 1492 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 1493 | /* Quirks *********************************************************************/ |
| 1494 | |
Kai-Chuan Hsieh | 8023eff | 2016-09-01 23:55:55 +0800 | [diff] [blame] | 1495 | static void asus_wmi_set_xusb2pr(struct asus_wmi *asus) |
| 1496 | { |
| 1497 | struct pci_dev *xhci_pdev; |
| 1498 | u32 orig_ports_available; |
| 1499 | u32 ports_available = asus->driver->quirks->xusb2pr; |
| 1500 | |
| 1501 | xhci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 1502 | PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI, |
| 1503 | NULL); |
| 1504 | |
| 1505 | if (!xhci_pdev) |
| 1506 | return; |
| 1507 | |
| 1508 | pci_read_config_dword(xhci_pdev, USB_INTEL_XUSB2PR, |
| 1509 | &orig_ports_available); |
| 1510 | |
| 1511 | pci_write_config_dword(xhci_pdev, USB_INTEL_XUSB2PR, |
| 1512 | cpu_to_le32(ports_available)); |
| 1513 | |
| 1514 | pr_info("set USB_INTEL_XUSB2PR old: 0x%04x, new: 0x%04x\n", |
| 1515 | orig_ports_available, ports_available); |
| 1516 | } |
| 1517 | |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 1518 | /* |
Oleksij Rempel | e9b6151 | 2017-04-28 16:19:49 +0200 | [diff] [blame] | 1519 | * Some devices dont support or have borcken get_als method |
| 1520 | * but still support set method. |
| 1521 | */ |
| 1522 | static void asus_wmi_set_als(void) |
| 1523 | { |
| 1524 | asus_wmi_set_devstate(ASUS_WMI_DEVID_ALS_ENABLE, 1, NULL); |
| 1525 | } |
| 1526 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 1527 | /* Hwmon device ***************************************************************/ |
| 1528 | |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1529 | static int asus_agfn_fan_speed_read(struct asus_wmi *asus, int fan, |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1530 | int *speed) |
| 1531 | { |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1532 | struct agfn_fan_args args = { |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1533 | .agfn.len = sizeof(args), |
| 1534 | .agfn.mfun = ASUS_FAN_MFUN, |
| 1535 | .agfn.sfun = ASUS_FAN_SFUN_READ, |
| 1536 | .fan = fan, |
| 1537 | .speed = 0, |
| 1538 | }; |
| 1539 | struct acpi_buffer input = { (acpi_size) sizeof(args), &args }; |
| 1540 | int status; |
| 1541 | |
| 1542 | if (fan != 1) |
| 1543 | return -EINVAL; |
| 1544 | |
| 1545 | status = asus_wmi_evaluate_method_agfn(input); |
| 1546 | |
| 1547 | if (status || args.agfn.err) |
| 1548 | return -ENXIO; |
| 1549 | |
| 1550 | if (speed) |
| 1551 | *speed = args.speed; |
| 1552 | |
| 1553 | return 0; |
| 1554 | } |
| 1555 | |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1556 | static int asus_agfn_fan_speed_write(struct asus_wmi *asus, int fan, |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1557 | int *speed) |
| 1558 | { |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1559 | struct agfn_fan_args args = { |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1560 | .agfn.len = sizeof(args), |
| 1561 | .agfn.mfun = ASUS_FAN_MFUN, |
| 1562 | .agfn.sfun = ASUS_FAN_SFUN_WRITE, |
| 1563 | .fan = fan, |
| 1564 | .speed = speed ? *speed : 0, |
| 1565 | }; |
| 1566 | struct acpi_buffer input = { (acpi_size) sizeof(args), &args }; |
| 1567 | int status; |
| 1568 | |
| 1569 | /* 1: for setting 1st fan's speed 0: setting auto mode */ |
| 1570 | if (fan != 1 && fan != 0) |
| 1571 | return -EINVAL; |
| 1572 | |
| 1573 | status = asus_wmi_evaluate_method_agfn(input); |
| 1574 | |
| 1575 | if (status || args.agfn.err) |
| 1576 | return -ENXIO; |
| 1577 | |
| 1578 | if (speed && fan == 1) |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1579 | asus->agfn_pwm = *speed; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1580 | |
| 1581 | return 0; |
| 1582 | } |
| 1583 | |
| 1584 | /* |
| 1585 | * Check if we can read the speed of one fan. If true we assume we can also |
| 1586 | * control it. |
| 1587 | */ |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1588 | static bool asus_wmi_has_agfn_fan(struct asus_wmi *asus) |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1589 | { |
| 1590 | int status; |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1591 | int speed; |
| 1592 | u32 value; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1593 | |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1594 | status = asus_agfn_fan_speed_read(asus, 1, &speed); |
| 1595 | if (status != 0) |
| 1596 | return false; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1597 | |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1598 | status = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FAN_CTRL, &value); |
| 1599 | if (status != 0) |
| 1600 | return false; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1601 | |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1602 | /* |
| 1603 | * We need to find a better way, probably using sfun, |
| 1604 | * bits or spec ... |
| 1605 | * Currently we disable it if: |
| 1606 | * - ASUS_WMI_UNSUPPORTED_METHOD is returned |
| 1607 | * - reverved bits are non-zero |
| 1608 | * - sfun and presence bit are not set |
| 1609 | */ |
| 1610 | return !(value == ASUS_WMI_UNSUPPORTED_METHOD || value & 0xFFF80000 |
| 1611 | || (!asus->sfun && !(value & ASUS_WMI_DSTS_PRESENCE_BIT))); |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1612 | } |
| 1613 | |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1614 | static int asus_fan_set_auto(struct asus_wmi *asus) |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1615 | { |
| 1616 | int status; |
Daniel Drake | e3168b8 | 2019-07-29 16:27:39 +0800 | [diff] [blame] | 1617 | u32 retval; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1618 | |
Daniel Drake | e3168b8 | 2019-07-29 16:27:39 +0800 | [diff] [blame] | 1619 | switch (asus->fan_type) { |
| 1620 | case FAN_TYPE_SPEC83: |
| 1621 | status = asus_wmi_set_devstate(ASUS_WMI_DEVID_CPU_FAN_CTRL, |
| 1622 | 0, &retval); |
| 1623 | if (status) |
| 1624 | return status; |
| 1625 | |
| 1626 | if (retval != 1) |
| 1627 | return -EIO; |
| 1628 | break; |
| 1629 | |
| 1630 | case FAN_TYPE_AGFN: |
| 1631 | status = asus_agfn_fan_speed_write(asus, 0, NULL); |
| 1632 | if (status) |
| 1633 | return -ENXIO; |
| 1634 | break; |
| 1635 | |
| 1636 | default: |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1637 | return -ENXIO; |
Daniel Drake | e3168b8 | 2019-07-29 16:27:39 +0800 | [diff] [blame] | 1638 | } |
| 1639 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1640 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1641 | return 0; |
| 1642 | } |
| 1643 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1644 | static ssize_t pwm1_show(struct device *dev, |
Corentin Chary | 49979d0 | 2011-07-01 11:34:26 +0200 | [diff] [blame] | 1645 | struct device_attribute *attr, |
| 1646 | char *buf) |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1647 | { |
| 1648 | struct asus_wmi *asus = dev_get_drvdata(dev); |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1649 | int err; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1650 | int value; |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1651 | |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1652 | /* If we already set a value then just return it */ |
| 1653 | if (asus->agfn_pwm >= 0) |
| 1654 | return sprintf(buf, "%d\n", asus->agfn_pwm); |
| 1655 | |
| 1656 | /* |
| 1657 | * If we haven't set already set a value through the AGFN interface, |
| 1658 | * we read a current value through the (now-deprecated) FAN_CTRL device. |
| 1659 | */ |
| 1660 | err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FAN_CTRL, &value); |
| 1661 | if (err < 0) |
| 1662 | return err; |
| 1663 | |
| 1664 | value &= 0xFF; |
| 1665 | |
| 1666 | if (value == 1) /* Low Speed */ |
| 1667 | value = 85; |
| 1668 | else if (value == 2) |
| 1669 | value = 170; |
| 1670 | else if (value == 3) |
| 1671 | value = 255; |
| 1672 | else if (value) { |
| 1673 | pr_err("Unknown fan speed %#x\n", value); |
| 1674 | value = -1; |
| 1675 | } |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1676 | |
| 1677 | return sprintf(buf, "%d\n", value); |
| 1678 | } |
| 1679 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1680 | static ssize_t pwm1_store(struct device *dev, |
| 1681 | struct device_attribute *attr, |
| 1682 | const char *buf, size_t count) { |
| 1683 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 1684 | int value; |
| 1685 | int state; |
| 1686 | int ret; |
| 1687 | |
| 1688 | ret = kstrtouint(buf, 10, &value); |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1689 | if (ret) |
| 1690 | return ret; |
| 1691 | |
| 1692 | value = clamp(value, 0, 255); |
| 1693 | |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1694 | state = asus_agfn_fan_speed_write(asus, 1, &value); |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1695 | if (state) |
| 1696 | pr_warn("Setting fan speed failed: %d\n", state); |
| 1697 | else |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1698 | asus->fan_pwm_mode = ASUS_FAN_CTRL_MANUAL; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1699 | |
| 1700 | return count; |
| 1701 | } |
| 1702 | |
| 1703 | static ssize_t fan1_input_show(struct device *dev, |
| 1704 | struct device_attribute *attr, |
| 1705 | char *buf) |
| 1706 | { |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1707 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 1708 | int value; |
| 1709 | int ret; |
| 1710 | |
Daniel Drake | e3168b8 | 2019-07-29 16:27:39 +0800 | [diff] [blame] | 1711 | switch (asus->fan_type) { |
| 1712 | case FAN_TYPE_SPEC83: |
| 1713 | ret = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_CPU_FAN_CTRL, |
| 1714 | &value); |
| 1715 | if (ret < 0) |
| 1716 | return ret; |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1717 | |
Daniel Drake | e3168b8 | 2019-07-29 16:27:39 +0800 | [diff] [blame] | 1718 | value &= 0xffff; |
| 1719 | break; |
| 1720 | |
| 1721 | case FAN_TYPE_AGFN: |
| 1722 | /* no speed readable on manual mode */ |
| 1723 | if (asus->fan_pwm_mode == ASUS_FAN_CTRL_MANUAL) |
| 1724 | return -ENXIO; |
| 1725 | |
| 1726 | ret = asus_agfn_fan_speed_read(asus, 1, &value); |
| 1727 | if (ret) { |
| 1728 | pr_warn("reading fan speed failed: %d\n", ret); |
| 1729 | return -ENXIO; |
| 1730 | } |
| 1731 | break; |
| 1732 | |
| 1733 | default: |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1734 | return -ENXIO; |
| 1735 | } |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1736 | |
| 1737 | return sprintf(buf, "%d\n", value < 0 ? -1 : value*100); |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | static ssize_t pwm1_enable_show(struct device *dev, |
| 1741 | struct device_attribute *attr, |
| 1742 | char *buf) |
| 1743 | { |
| 1744 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 1745 | |
Daniel Drake | e3168b8 | 2019-07-29 16:27:39 +0800 | [diff] [blame] | 1746 | /* |
| 1747 | * Just read back the cached pwm mode. |
| 1748 | * |
| 1749 | * For the CPU_FAN device, the spec indicates that we should be |
| 1750 | * able to read the device status and consult bit 19 to see if we |
| 1751 | * are in Full On or Automatic mode. However, this does not work |
| 1752 | * in practice on X532FL at least (the bit is always 0) and there's |
| 1753 | * also nothing in the DSDT to indicate that this behaviour exists. |
| 1754 | */ |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1755 | return sprintf(buf, "%d\n", asus->fan_pwm_mode); |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | static ssize_t pwm1_enable_store(struct device *dev, |
| 1759 | struct device_attribute *attr, |
| 1760 | const char *buf, size_t count) |
| 1761 | { |
| 1762 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 1763 | int status = 0; |
| 1764 | int state; |
Daniel Drake | e3168b8 | 2019-07-29 16:27:39 +0800 | [diff] [blame] | 1765 | int value; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1766 | int ret; |
Daniel Drake | e3168b8 | 2019-07-29 16:27:39 +0800 | [diff] [blame] | 1767 | u32 retval; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1768 | |
| 1769 | ret = kstrtouint(buf, 10, &state); |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1770 | if (ret) |
| 1771 | return ret; |
| 1772 | |
Daniel Drake | e3168b8 | 2019-07-29 16:27:39 +0800 | [diff] [blame] | 1773 | if (asus->fan_type == FAN_TYPE_SPEC83) { |
| 1774 | switch (state) { /* standard documented hwmon values */ |
| 1775 | case ASUS_FAN_CTRL_FULLSPEED: |
| 1776 | value = 1; |
| 1777 | break; |
| 1778 | case ASUS_FAN_CTRL_AUTO: |
| 1779 | value = 0; |
| 1780 | break; |
| 1781 | default: |
| 1782 | return -EINVAL; |
| 1783 | } |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1784 | |
Daniel Drake | e3168b8 | 2019-07-29 16:27:39 +0800 | [diff] [blame] | 1785 | ret = asus_wmi_set_devstate(ASUS_WMI_DEVID_CPU_FAN_CTRL, |
| 1786 | value, &retval); |
| 1787 | if (ret) |
| 1788 | return ret; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1789 | |
Daniel Drake | e3168b8 | 2019-07-29 16:27:39 +0800 | [diff] [blame] | 1790 | if (retval != 1) |
| 1791 | return -EIO; |
| 1792 | } else if (asus->fan_type == FAN_TYPE_AGFN) { |
| 1793 | switch (state) { |
| 1794 | case ASUS_FAN_CTRL_MANUAL: |
| 1795 | break; |
| 1796 | |
| 1797 | case ASUS_FAN_CTRL_AUTO: |
| 1798 | status = asus_fan_set_auto(asus); |
| 1799 | if (status) |
| 1800 | return status; |
| 1801 | break; |
| 1802 | |
| 1803 | default: |
| 1804 | return -EINVAL; |
| 1805 | } |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | asus->fan_pwm_mode = state; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1809 | return count; |
| 1810 | } |
| 1811 | |
| 1812 | static ssize_t fan1_label_show(struct device *dev, |
| 1813 | struct device_attribute *attr, |
| 1814 | char *buf) |
| 1815 | { |
| 1816 | return sprintf(buf, "%s\n", ASUS_FAN_DESC); |
| 1817 | } |
| 1818 | |
Corentin Chary | 6118b8a | 2011-07-01 11:34:36 +0200 | [diff] [blame] | 1819 | static ssize_t asus_hwmon_temp1(struct device *dev, |
| 1820 | struct device_attribute *attr, |
| 1821 | char *buf) |
| 1822 | { |
| 1823 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 1824 | u32 value; |
| 1825 | int err; |
| 1826 | |
| 1827 | err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_THERMAL_CTRL, &value); |
Corentin Chary | 6118b8a | 2011-07-01 11:34:36 +0200 | [diff] [blame] | 1828 | if (err < 0) |
| 1829 | return err; |
| 1830 | |
Akinobu Mita | f07b9fd | 2020-01-30 22:15:37 -0800 | [diff] [blame] | 1831 | return sprintf(buf, "%ld\n", |
| 1832 | deci_kelvin_to_millicelsius(value & 0xFFFF)); |
Corentin Chary | 6118b8a | 2011-07-01 11:34:36 +0200 | [diff] [blame] | 1833 | } |
| 1834 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1835 | /* Fan1 */ |
| 1836 | static DEVICE_ATTR_RW(pwm1); |
| 1837 | static DEVICE_ATTR_RW(pwm1_enable); |
| 1838 | static DEVICE_ATTR_RO(fan1_input); |
| 1839 | static DEVICE_ATTR_RO(fan1_label); |
| 1840 | |
| 1841 | /* Temperature */ |
Guenter Roeck | 50a639f | 2013-11-23 11:03:17 -0800 | [diff] [blame] | 1842 | static DEVICE_ATTR(temp1_input, S_IRUGO, asus_hwmon_temp1, NULL); |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1843 | |
| 1844 | static struct attribute *hwmon_attributes[] = { |
Guenter Roeck | 50a639f | 2013-11-23 11:03:17 -0800 | [diff] [blame] | 1845 | &dev_attr_pwm1.attr, |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1846 | &dev_attr_pwm1_enable.attr, |
| 1847 | &dev_attr_fan1_input.attr, |
| 1848 | &dev_attr_fan1_label.attr, |
| 1849 | |
Guenter Roeck | 50a639f | 2013-11-23 11:03:17 -0800 | [diff] [blame] | 1850 | &dev_attr_temp1_input.attr, |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1851 | NULL |
| 1852 | }; |
| 1853 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 1854 | static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj, |
Corentin Chary | e02431d | 2011-07-01 11:34:37 +0200 | [diff] [blame] | 1855 | struct attribute *attr, int idx) |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1856 | { |
| 1857 | struct device *dev = container_of(kobj, struct device, kobj); |
Fuqian Huang | 8e8fe44 | 2019-07-01 11:24:26 +0800 | [diff] [blame] | 1858 | struct asus_wmi *asus = dev_get_drvdata(dev->parent); |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1859 | u32 value = ASUS_WMI_UNSUPPORTED_METHOD; |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1860 | |
Daniel Drake | e3168b8 | 2019-07-29 16:27:39 +0800 | [diff] [blame] | 1861 | if (attr == &dev_attr_pwm1.attr) { |
| 1862 | if (asus->fan_type != FAN_TYPE_AGFN) |
| 1863 | return 0; |
| 1864 | } else if (attr == &dev_attr_fan1_input.attr |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1865 | || attr == &dev_attr_fan1_label.attr |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1866 | || attr == &dev_attr_pwm1_enable.attr) { |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1867 | if (asus->fan_type == FAN_TYPE_NONE) |
| 1868 | return 0; |
| 1869 | } else if (attr == &dev_attr_temp1_input.attr) { |
| 1870 | int err = asus_wmi_get_devstate(asus, |
| 1871 | ASUS_WMI_DEVID_THERMAL_CTRL, |
| 1872 | &value); |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 1873 | |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1874 | if (err < 0) |
Al Viro | e772aed | 2011-07-23 20:59:40 -0400 | [diff] [blame] | 1875 | return 0; /* can't return negative here */ |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1876 | |
Yurii Pavlovskyi | 4fd1982 | 2019-05-14 21:05:46 +0200 | [diff] [blame] | 1877 | /* |
| 1878 | * If the temperature value in deci-Kelvin is near the absolute |
| 1879 | * zero temperature, something is clearly wrong |
| 1880 | */ |
| 1881 | if (value == 0 || value == 1) |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1882 | return 0; |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1883 | } |
| 1884 | |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1885 | return attr->mode; |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1886 | } |
| 1887 | |
Arvind Yadav | e90d9ba | 2017-07-11 16:18:19 +0530 | [diff] [blame] | 1888 | static const struct attribute_group hwmon_attribute_group = { |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1889 | .is_visible = asus_hwmon_sysfs_is_visible, |
| 1890 | .attrs = hwmon_attributes |
| 1891 | }; |
Guenter Roeck | 50a639f | 2013-11-23 11:03:17 -0800 | [diff] [blame] | 1892 | __ATTRIBUTE_GROUPS(hwmon_attribute); |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1893 | |
| 1894 | static int asus_wmi_hwmon_init(struct asus_wmi *asus) |
| 1895 | { |
Yurii Pavlovskyi | cd10ee0 | 2019-05-14 20:50:30 +0200 | [diff] [blame] | 1896 | struct device *dev = &asus->platform_device->dev; |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1897 | struct device *hwmon; |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1898 | |
Yurii Pavlovskyi | cd10ee0 | 2019-05-14 20:50:30 +0200 | [diff] [blame] | 1899 | hwmon = devm_hwmon_device_register_with_groups(dev, "asus", asus, |
| 1900 | hwmon_attribute_groups); |
| 1901 | |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1902 | if (IS_ERR(hwmon)) { |
| 1903 | pr_err("Could not register asus hwmon device\n"); |
| 1904 | return PTR_ERR(hwmon); |
| 1905 | } |
Guenter Roeck | 50a639f | 2013-11-23 11:03:17 -0800 | [diff] [blame] | 1906 | return 0; |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 1907 | } |
| 1908 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 1909 | static int asus_wmi_fan_init(struct asus_wmi *asus) |
| 1910 | { |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1911 | asus->fan_type = FAN_TYPE_NONE; |
| 1912 | asus->agfn_pwm = -1; |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 1913 | |
Daniel Drake | e3168b8 | 2019-07-29 16:27:39 +0800 | [diff] [blame] | 1914 | if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_CPU_FAN_CTRL)) |
| 1915 | asus->fan_type = FAN_TYPE_SPEC83; |
| 1916 | else if (asus_wmi_has_agfn_fan(asus)) |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 1917 | asus->fan_type = FAN_TYPE_AGFN; |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 1918 | |
Daniel Drake | e3168b8 | 2019-07-29 16:27:39 +0800 | [diff] [blame] | 1919 | if (asus->fan_type == FAN_TYPE_NONE) |
| 1920 | return -ENODEV; |
| 1921 | |
| 1922 | asus_fan_set_auto(asus); |
| 1923 | asus->fan_pwm_mode = ASUS_FAN_CTRL_AUTO; |
| 1924 | return 0; |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 1925 | } |
| 1926 | |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1927 | /* Fan mode *******************************************************************/ |
| 1928 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 1929 | static int fan_boost_mode_check_present(struct asus_wmi *asus) |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1930 | { |
| 1931 | u32 result; |
| 1932 | int err; |
| 1933 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 1934 | asus->fan_boost_mode_available = false; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1935 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 1936 | err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FAN_BOOST_MODE, |
| 1937 | &result); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1938 | if (err) { |
| 1939 | if (err == -ENODEV) |
| 1940 | return 0; |
| 1941 | else |
| 1942 | return err; |
| 1943 | } |
| 1944 | |
| 1945 | if ((result & ASUS_WMI_DSTS_PRESENCE_BIT) && |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 1946 | (result & ASUS_FAN_BOOST_MODES_MASK)) { |
| 1947 | asus->fan_boost_mode_available = true; |
| 1948 | asus->fan_boost_mode_mask = result & ASUS_FAN_BOOST_MODES_MASK; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | return 0; |
| 1952 | } |
| 1953 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 1954 | static int fan_boost_mode_write(struct asus_wmi *asus) |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1955 | { |
| 1956 | int err; |
| 1957 | u8 value; |
| 1958 | u32 retval; |
| 1959 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 1960 | value = asus->fan_boost_mode; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1961 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 1962 | pr_info("Set fan boost mode: %u\n", value); |
| 1963 | err = asus_wmi_set_devstate(ASUS_WMI_DEVID_FAN_BOOST_MODE, value, |
| 1964 | &retval); |
Vasiliy Kupriakov | 72ceec5 | 2020-08-29 00:49:30 +0300 | [diff] [blame] | 1965 | |
| 1966 | sysfs_notify(&asus->platform_device->dev.kobj, NULL, |
| 1967 | "fan_boost_mode"); |
| 1968 | |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1969 | if (err) { |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 1970 | pr_warn("Failed to set fan boost mode: %d\n", err); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1971 | return err; |
| 1972 | } |
| 1973 | |
| 1974 | if (retval != 1) { |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 1975 | pr_warn("Failed to set fan boost mode (retval): 0x%x\n", |
| 1976 | retval); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1977 | return -EIO; |
| 1978 | } |
| 1979 | |
| 1980 | return 0; |
| 1981 | } |
| 1982 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 1983 | static int fan_boost_mode_switch_next(struct asus_wmi *asus) |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1984 | { |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 1985 | u8 mask = asus->fan_boost_mode_mask; |
| 1986 | |
| 1987 | if (asus->fan_boost_mode == ASUS_FAN_BOOST_MODE_NORMAL) { |
| 1988 | if (mask & ASUS_FAN_BOOST_MODE_OVERBOOST_MASK) |
| 1989 | asus->fan_boost_mode = ASUS_FAN_BOOST_MODE_OVERBOOST; |
| 1990 | else if (mask & ASUS_FAN_BOOST_MODE_SILENT_MASK) |
| 1991 | asus->fan_boost_mode = ASUS_FAN_BOOST_MODE_SILENT; |
| 1992 | } else if (asus->fan_boost_mode == ASUS_FAN_BOOST_MODE_OVERBOOST) { |
| 1993 | if (mask & ASUS_FAN_BOOST_MODE_SILENT_MASK) |
| 1994 | asus->fan_boost_mode = ASUS_FAN_BOOST_MODE_SILENT; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1995 | else |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 1996 | asus->fan_boost_mode = ASUS_FAN_BOOST_MODE_NORMAL; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1997 | } else { |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 1998 | asus->fan_boost_mode = ASUS_FAN_BOOST_MODE_NORMAL; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 1999 | } |
| 2000 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 2001 | return fan_boost_mode_write(asus); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2002 | } |
| 2003 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 2004 | static ssize_t fan_boost_mode_show(struct device *dev, |
| 2005 | struct device_attribute *attr, char *buf) |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2006 | { |
| 2007 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 2008 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 2009 | return scnprintf(buf, PAGE_SIZE, "%d\n", asus->fan_boost_mode); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2010 | } |
| 2011 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 2012 | static ssize_t fan_boost_mode_store(struct device *dev, |
| 2013 | struct device_attribute *attr, |
| 2014 | const char *buf, size_t count) |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2015 | { |
| 2016 | int result; |
| 2017 | u8 new_mode; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2018 | struct asus_wmi *asus = dev_get_drvdata(dev); |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 2019 | u8 mask = asus->fan_boost_mode_mask; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2020 | |
| 2021 | result = kstrtou8(buf, 10, &new_mode); |
| 2022 | if (result < 0) { |
| 2023 | pr_warn("Trying to store invalid value\n"); |
| 2024 | return result; |
| 2025 | } |
| 2026 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 2027 | if (new_mode == ASUS_FAN_BOOST_MODE_OVERBOOST) { |
| 2028 | if (!(mask & ASUS_FAN_BOOST_MODE_OVERBOOST_MASK)) |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2029 | return -EINVAL; |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 2030 | } else if (new_mode == ASUS_FAN_BOOST_MODE_SILENT) { |
| 2031 | if (!(mask & ASUS_FAN_BOOST_MODE_SILENT_MASK)) |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2032 | return -EINVAL; |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 2033 | } else if (new_mode != ASUS_FAN_BOOST_MODE_NORMAL) { |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2034 | return -EINVAL; |
| 2035 | } |
| 2036 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 2037 | asus->fan_boost_mode = new_mode; |
| 2038 | fan_boost_mode_write(asus); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2039 | |
Leonid Maksymchuk | edeee34 | 2020-03-04 13:38:11 +0200 | [diff] [blame] | 2040 | return count; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2041 | } |
| 2042 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 2043 | // Fan boost mode: 0 - normal, 1 - overboost, 2 - silent |
| 2044 | static DEVICE_ATTR_RW(fan_boost_mode); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2045 | |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 2046 | /* Throttle thermal policy ****************************************************/ |
| 2047 | |
| 2048 | static int throttle_thermal_policy_check_present(struct asus_wmi *asus) |
| 2049 | { |
| 2050 | u32 result; |
| 2051 | int err; |
| 2052 | |
| 2053 | asus->throttle_thermal_policy_available = false; |
| 2054 | |
| 2055 | err = asus_wmi_get_devstate(asus, |
| 2056 | ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY, |
| 2057 | &result); |
| 2058 | if (err) { |
| 2059 | if (err == -ENODEV) |
| 2060 | return 0; |
| 2061 | return err; |
| 2062 | } |
| 2063 | |
| 2064 | if (result & ASUS_WMI_DSTS_PRESENCE_BIT) |
| 2065 | asus->throttle_thermal_policy_available = true; |
| 2066 | |
| 2067 | return 0; |
| 2068 | } |
| 2069 | |
| 2070 | static int throttle_thermal_policy_write(struct asus_wmi *asus) |
| 2071 | { |
| 2072 | int err; |
| 2073 | u8 value; |
| 2074 | u32 retval; |
| 2075 | |
| 2076 | value = asus->throttle_thermal_policy_mode; |
| 2077 | |
| 2078 | err = asus_wmi_set_devstate(ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY, |
| 2079 | value, &retval); |
Vasiliy Kupriakov | 72ceec5 | 2020-08-29 00:49:30 +0300 | [diff] [blame] | 2080 | |
| 2081 | sysfs_notify(&asus->platform_device->dev.kobj, NULL, |
| 2082 | "throttle_thermal_policy"); |
| 2083 | |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 2084 | if (err) { |
| 2085 | pr_warn("Failed to set throttle thermal policy: %d\n", err); |
| 2086 | return err; |
| 2087 | } |
| 2088 | |
| 2089 | if (retval != 1) { |
| 2090 | pr_warn("Failed to set throttle thermal policy (retval): 0x%x\n", |
| 2091 | retval); |
| 2092 | return -EIO; |
| 2093 | } |
| 2094 | |
| 2095 | return 0; |
| 2096 | } |
| 2097 | |
Leonid Maksymchuk | a282158 | 2019-12-15 16:27:24 +0200 | [diff] [blame] | 2098 | static int throttle_thermal_policy_set_default(struct asus_wmi *asus) |
| 2099 | { |
| 2100 | if (!asus->throttle_thermal_policy_available) |
| 2101 | return 0; |
| 2102 | |
| 2103 | asus->throttle_thermal_policy_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT; |
| 2104 | return throttle_thermal_policy_write(asus); |
| 2105 | } |
| 2106 | |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 2107 | static int throttle_thermal_policy_switch_next(struct asus_wmi *asus) |
| 2108 | { |
| 2109 | u8 new_mode = asus->throttle_thermal_policy_mode + 1; |
Luke D. Jones | c63d44a | 2021-08-19 07:07:31 +1200 | [diff] [blame] | 2110 | int err; |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 2111 | |
| 2112 | if (new_mode > ASUS_THROTTLE_THERMAL_POLICY_SILENT) |
| 2113 | new_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT; |
| 2114 | |
| 2115 | asus->throttle_thermal_policy_mode = new_mode; |
Luke D. Jones | c63d44a | 2021-08-19 07:07:31 +1200 | [diff] [blame] | 2116 | err = throttle_thermal_policy_write(asus); |
| 2117 | if (err) |
| 2118 | return err; |
| 2119 | |
| 2120 | /* |
| 2121 | * Ensure that platform_profile updates userspace with the change to ensure |
| 2122 | * that platform_profile and throttle_thermal_policy_mode are in sync. |
| 2123 | */ |
| 2124 | platform_profile_notify(); |
| 2125 | |
| 2126 | return 0; |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 2127 | } |
| 2128 | |
| 2129 | static ssize_t throttle_thermal_policy_show(struct device *dev, |
| 2130 | struct device_attribute *attr, char *buf) |
| 2131 | { |
| 2132 | struct asus_wmi *asus = dev_get_drvdata(dev); |
| 2133 | u8 mode = asus->throttle_thermal_policy_mode; |
| 2134 | |
| 2135 | return scnprintf(buf, PAGE_SIZE, "%d\n", mode); |
| 2136 | } |
| 2137 | |
| 2138 | static ssize_t throttle_thermal_policy_store(struct device *dev, |
| 2139 | struct device_attribute *attr, |
| 2140 | const char *buf, size_t count) |
| 2141 | { |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 2142 | struct asus_wmi *asus = dev_get_drvdata(dev); |
Luke D. Jones | c63d44a | 2021-08-19 07:07:31 +1200 | [diff] [blame] | 2143 | u8 new_mode; |
| 2144 | int result; |
| 2145 | int err; |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 2146 | |
| 2147 | result = kstrtou8(buf, 10, &new_mode); |
| 2148 | if (result < 0) |
| 2149 | return result; |
| 2150 | |
| 2151 | if (new_mode > ASUS_THROTTLE_THERMAL_POLICY_SILENT) |
| 2152 | return -EINVAL; |
| 2153 | |
| 2154 | asus->throttle_thermal_policy_mode = new_mode; |
Luke D. Jones | c63d44a | 2021-08-19 07:07:31 +1200 | [diff] [blame] | 2155 | err = throttle_thermal_policy_write(asus); |
| 2156 | if (err) |
| 2157 | return err; |
| 2158 | |
| 2159 | /* |
| 2160 | * Ensure that platform_profile updates userspace with the change to ensure |
| 2161 | * that platform_profile and throttle_thermal_policy_mode are in sync. |
| 2162 | */ |
| 2163 | platform_profile_notify(); |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 2164 | |
| 2165 | return count; |
| 2166 | } |
| 2167 | |
| 2168 | // Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent |
| 2169 | static DEVICE_ATTR_RW(throttle_thermal_policy); |
| 2170 | |
Luke D. Jones | c63d44a | 2021-08-19 07:07:31 +1200 | [diff] [blame] | 2171 | /* Platform profile ***********************************************************/ |
| 2172 | static int platform_profile_get(struct platform_profile_handler *pprof, |
| 2173 | enum platform_profile_option *profile) |
| 2174 | { |
| 2175 | struct asus_wmi *asus; |
| 2176 | int tp; |
| 2177 | |
| 2178 | asus = container_of(pprof, struct asus_wmi, platform_profile_handler); |
| 2179 | |
| 2180 | tp = asus->throttle_thermal_policy_mode; |
| 2181 | |
Luke D. Jones | c63d44a | 2021-08-19 07:07:31 +1200 | [diff] [blame] | 2182 | switch (tp) { |
| 2183 | case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT: |
| 2184 | *profile = PLATFORM_PROFILE_BALANCED; |
| 2185 | break; |
| 2186 | case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST: |
| 2187 | *profile = PLATFORM_PROFILE_PERFORMANCE; |
| 2188 | break; |
| 2189 | case ASUS_THROTTLE_THERMAL_POLICY_SILENT: |
| 2190 | *profile = PLATFORM_PROFILE_QUIET; |
| 2191 | break; |
| 2192 | default: |
| 2193 | return -EINVAL; |
| 2194 | } |
| 2195 | |
| 2196 | return 0; |
| 2197 | } |
| 2198 | |
| 2199 | static int platform_profile_set(struct platform_profile_handler *pprof, |
| 2200 | enum platform_profile_option profile) |
| 2201 | { |
| 2202 | struct asus_wmi *asus; |
| 2203 | int tp; |
| 2204 | |
| 2205 | asus = container_of(pprof, struct asus_wmi, platform_profile_handler); |
| 2206 | |
| 2207 | switch (profile) { |
| 2208 | case PLATFORM_PROFILE_PERFORMANCE: |
| 2209 | tp = ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST; |
| 2210 | break; |
| 2211 | case PLATFORM_PROFILE_BALANCED: |
| 2212 | tp = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT; |
| 2213 | break; |
| 2214 | case PLATFORM_PROFILE_QUIET: |
| 2215 | tp = ASUS_THROTTLE_THERMAL_POLICY_SILENT; |
| 2216 | break; |
| 2217 | default: |
| 2218 | return -EOPNOTSUPP; |
| 2219 | } |
| 2220 | |
| 2221 | asus->throttle_thermal_policy_mode = tp; |
| 2222 | return throttle_thermal_policy_write(asus); |
| 2223 | } |
| 2224 | |
| 2225 | static int platform_profile_setup(struct asus_wmi *asus) |
| 2226 | { |
| 2227 | struct device *dev = &asus->platform_device->dev; |
| 2228 | int err; |
| 2229 | |
| 2230 | /* |
| 2231 | * Not an error if a component platform_profile relies on is unavailable |
| 2232 | * so early return, skipping the setup of platform_profile. |
| 2233 | */ |
| 2234 | if (!asus->throttle_thermal_policy_available) |
| 2235 | return 0; |
| 2236 | |
| 2237 | dev_info(dev, "Using throttle_thermal_policy for platform_profile support\n"); |
| 2238 | |
| 2239 | asus->platform_profile_handler.profile_get = platform_profile_get; |
| 2240 | asus->platform_profile_handler.profile_set = platform_profile_set; |
| 2241 | |
| 2242 | set_bit(PLATFORM_PROFILE_QUIET, asus->platform_profile_handler.choices); |
| 2243 | set_bit(PLATFORM_PROFILE_BALANCED, |
| 2244 | asus->platform_profile_handler.choices); |
| 2245 | set_bit(PLATFORM_PROFILE_PERFORMANCE, |
| 2246 | asus->platform_profile_handler.choices); |
| 2247 | |
| 2248 | err = platform_profile_register(&asus->platform_profile_handler); |
| 2249 | if (err) |
| 2250 | return err; |
| 2251 | |
| 2252 | asus->platform_profile_support = true; |
| 2253 | return 0; |
| 2254 | } |
| 2255 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 2256 | /* Backlight ******************************************************************/ |
| 2257 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2258 | static int read_backlight_power(struct asus_wmi *asus) |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 2259 | { |
AceLan Kao | 6e0044b | 2012-03-20 09:53:09 +0100 | [diff] [blame] | 2260 | int ret; |
Andy Shevchenko | 109e8ad | 2019-08-16 14:17:34 +0300 | [diff] [blame] | 2261 | |
AceLan Kao | 6e0044b | 2012-03-20 09:53:09 +0100 | [diff] [blame] | 2262 | if (asus->driver->quirks->store_backlight_power) |
| 2263 | ret = !asus->driver->panel_power; |
| 2264 | else |
| 2265 | ret = asus_wmi_get_devstate_simple(asus, |
| 2266 | ASUS_WMI_DEVID_BACKLIGHT); |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 2267 | |
| 2268 | if (ret < 0) |
| 2269 | return ret; |
| 2270 | |
| 2271 | return ret ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; |
| 2272 | } |
| 2273 | |
Corentin Chary | 8fbea01 | 2011-02-26 10:20:37 +0100 | [diff] [blame] | 2274 | static int read_brightness_max(struct asus_wmi *asus) |
| 2275 | { |
| 2276 | u32 retval; |
| 2277 | int err; |
| 2278 | |
| 2279 | err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_BRIGHTNESS, &retval); |
Corentin Chary | 8fbea01 | 2011-02-26 10:20:37 +0100 | [diff] [blame] | 2280 | if (err < 0) |
| 2281 | return err; |
| 2282 | |
| 2283 | retval = retval & ASUS_WMI_DSTS_MAX_BRIGTH_MASK; |
| 2284 | retval >>= 8; |
| 2285 | |
| 2286 | if (!retval) |
| 2287 | return -ENODEV; |
| 2288 | |
| 2289 | return retval; |
| 2290 | } |
| 2291 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2292 | static int read_brightness(struct backlight_device *bd) |
| 2293 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2294 | struct asus_wmi *asus = bl_get_data(bd); |
Dan Carpenter | 0986f25 | 2011-03-15 10:06:23 +0300 | [diff] [blame] | 2295 | u32 retval; |
| 2296 | int err; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2297 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2298 | err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_BRIGHTNESS, &retval); |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 2299 | if (err < 0) |
| 2300 | return err; |
| 2301 | |
| 2302 | return retval & ASUS_WMI_DSTS_BRIGHTNESS_MASK; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2303 | } |
| 2304 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 2305 | static u32 get_scalar_command(struct backlight_device *bd) |
| 2306 | { |
| 2307 | struct asus_wmi *asus = bl_get_data(bd); |
| 2308 | u32 ctrl_param = 0; |
| 2309 | |
| 2310 | if ((asus->driver->brightness < bd->props.brightness) || |
| 2311 | bd->props.brightness == bd->props.max_brightness) |
| 2312 | ctrl_param = 0x00008001; |
| 2313 | else if ((asus->driver->brightness > bd->props.brightness) || |
| 2314 | bd->props.brightness == 0) |
| 2315 | ctrl_param = 0x00008000; |
| 2316 | |
| 2317 | asus->driver->brightness = bd->props.brightness; |
| 2318 | |
| 2319 | return ctrl_param; |
| 2320 | } |
| 2321 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2322 | static int update_bl_status(struct backlight_device *bd) |
| 2323 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2324 | struct asus_wmi *asus = bl_get_data(bd); |
Corentin Chary | dfed65d | 2010-11-29 08:14:12 +0100 | [diff] [blame] | 2325 | u32 ctrl_param; |
AceLan Kao | 6e0044b | 2012-03-20 09:53:09 +0100 | [diff] [blame] | 2326 | int power, err = 0; |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 2327 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2328 | power = read_backlight_power(asus); |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 2329 | if (power != -ENODEV && bd->props.power != power) { |
| 2330 | ctrl_param = !!(bd->props.power == FB_BLANK_UNBLANK); |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 2331 | err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BACKLIGHT, |
| 2332 | ctrl_param, NULL); |
AceLan Kao | 6e0044b | 2012-03-20 09:53:09 +0100 | [diff] [blame] | 2333 | if (asus->driver->quirks->store_backlight_power) |
| 2334 | asus->driver->panel_power = bd->props.power; |
AceLan Kao | 6e0044b | 2012-03-20 09:53:09 +0100 | [diff] [blame] | 2335 | |
Corentin Chary | ade28ab | 2012-03-20 09:53:14 +0100 | [diff] [blame] | 2336 | /* When using scalar brightness, updating the brightness |
| 2337 | * will mess with the backlight power */ |
| 2338 | if (asus->driver->quirks->scalar_panel_brightness) |
| 2339 | return err; |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 2340 | } |
Corentin Chary | ade28ab | 2012-03-20 09:53:14 +0100 | [diff] [blame] | 2341 | |
| 2342 | if (asus->driver->quirks->scalar_panel_brightness) |
| 2343 | ctrl_param = get_scalar_command(bd); |
| 2344 | else |
| 2345 | ctrl_param = bd->props.brightness; |
| 2346 | |
| 2347 | err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BRIGHTNESS, |
| 2348 | ctrl_param, NULL); |
| 2349 | |
Corentin Chary | 8fbea01 | 2011-02-26 10:20:37 +0100 | [diff] [blame] | 2350 | return err; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2351 | } |
| 2352 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2353 | static const struct backlight_ops asus_wmi_bl_ops = { |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2354 | .get_brightness = read_brightness, |
| 2355 | .update_status = update_bl_status, |
| 2356 | }; |
| 2357 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2358 | static int asus_wmi_backlight_notify(struct asus_wmi *asus, int code) |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2359 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2360 | struct backlight_device *bd = asus->backlight_device; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2361 | int old = bd->props.brightness; |
Daniel Mack | b7670ed | 2010-05-19 12:37:01 +0200 | [diff] [blame] | 2362 | int new = old; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2363 | |
| 2364 | if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) |
| 2365 | new = code - NOTIFY_BRNUP_MIN + 1; |
| 2366 | else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX) |
| 2367 | new = code - NOTIFY_BRNDOWN_MIN; |
| 2368 | |
| 2369 | bd->props.brightness = new; |
| 2370 | backlight_update_status(bd); |
| 2371 | backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY); |
| 2372 | |
| 2373 | return old; |
| 2374 | } |
| 2375 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2376 | static int asus_wmi_backlight_init(struct asus_wmi *asus) |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2377 | { |
| 2378 | struct backlight_device *bd; |
| 2379 | struct backlight_properties props; |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 2380 | int max; |
| 2381 | int power; |
| 2382 | |
Corentin Chary | 8fbea01 | 2011-02-26 10:20:37 +0100 | [diff] [blame] | 2383 | max = read_brightness_max(asus); |
Hans de Goede | 86ac2735 | 2014-07-08 10:47:22 +0200 | [diff] [blame] | 2384 | if (max < 0) |
Corentin Chary | 8fbea01 | 2011-02-26 10:20:37 +0100 | [diff] [blame] | 2385 | return max; |
| 2386 | |
| 2387 | power = read_backlight_power(asus); |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 2388 | if (power == -ENODEV) |
| 2389 | power = FB_BLANK_UNBLANK; |
Corentin Chary | 8fbea01 | 2011-02-26 10:20:37 +0100 | [diff] [blame] | 2390 | else if (power < 0) |
| 2391 | return power; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2392 | |
| 2393 | memset(&props, 0, sizeof(struct backlight_properties)); |
Axel Lin | 60cfa09 | 2011-06-29 11:43:30 +0800 | [diff] [blame] | 2394 | props.type = BACKLIGHT_PLATFORM; |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 2395 | props.max_brightness = max; |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2396 | bd = backlight_device_register(asus->driver->name, |
| 2397 | &asus->platform_device->dev, asus, |
| 2398 | &asus_wmi_bl_ops, &props); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2399 | if (IS_ERR(bd)) { |
| 2400 | pr_err("Could not register backlight device\n"); |
| 2401 | return PTR_ERR(bd); |
| 2402 | } |
| 2403 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2404 | asus->backlight_device = bd; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2405 | |
AceLan Kao | 6e0044b | 2012-03-20 09:53:09 +0100 | [diff] [blame] | 2406 | if (asus->driver->quirks->store_backlight_power) |
| 2407 | asus->driver->panel_power = power; |
| 2408 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2409 | bd->props.brightness = read_brightness(bd); |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 2410 | bd->props.power = power; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2411 | backlight_update_status(bd); |
| 2412 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 2413 | asus->driver->brightness = bd->props.brightness; |
| 2414 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2415 | return 0; |
| 2416 | } |
| 2417 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2418 | static void asus_wmi_backlight_exit(struct asus_wmi *asus) |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2419 | { |
Markus Elfring | 0098181 | 2014-11-24 20:30:29 +0100 | [diff] [blame] | 2420 | backlight_device_unregister(asus->backlight_device); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2421 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2422 | asus->backlight_device = NULL; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2423 | } |
| 2424 | |
AceLan Kao | a2a96f0 | 2012-10-03 11:26:31 +0200 | [diff] [blame] | 2425 | static int is_display_toggle(int code) |
| 2426 | { |
| 2427 | /* display toggle keys */ |
| 2428 | if ((code >= 0x61 && code <= 0x67) || |
| 2429 | (code >= 0x8c && code <= 0x93) || |
| 2430 | (code >= 0xa0 && code <= 0xa7) || |
| 2431 | (code >= 0xd0 && code <= 0xd5)) |
| 2432 | return 1; |
| 2433 | |
| 2434 | return 0; |
| 2435 | } |
| 2436 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 2437 | /* Fn-lock ********************************************************************/ |
| 2438 | |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 2439 | static bool asus_wmi_has_fnlock_key(struct asus_wmi *asus) |
| 2440 | { |
| 2441 | u32 result; |
| 2442 | |
| 2443 | asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FNLOCK, &result); |
| 2444 | |
| 2445 | return (result & ASUS_WMI_DSTS_PRESENCE_BIT) && |
| 2446 | !(result & ASUS_WMI_FNLOCK_BIOS_DISABLED); |
| 2447 | } |
| 2448 | |
| 2449 | static void asus_wmi_fnlock_update(struct asus_wmi *asus) |
| 2450 | { |
| 2451 | int mode = asus->fnlock_locked; |
| 2452 | |
| 2453 | asus_wmi_set_devstate(ASUS_WMI_DEVID_FNLOCK, mode, NULL); |
| 2454 | } |
| 2455 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 2456 | /* WMI events *****************************************************************/ |
| 2457 | |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2458 | static int asus_wmi_get_event_code(u32 value) |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2459 | { |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2460 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 2461 | union acpi_object *obj; |
| 2462 | acpi_status status; |
| 2463 | int code; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2464 | |
| 2465 | status = wmi_get_event_data(value, &response); |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2466 | if (ACPI_FAILURE(status)) { |
| 2467 | pr_warn("Failed to get WMI notify code: %s\n", |
| 2468 | acpi_format_exception(status)); |
| 2469 | return -EIO; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2470 | } |
| 2471 | |
| 2472 | obj = (union acpi_object *)response.pointer; |
| 2473 | |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2474 | if (obj && obj->type == ACPI_TYPE_INTEGER) |
| 2475 | code = (int)(obj->integer.value & WMI_EVENT_MASK); |
| 2476 | else |
| 2477 | code = -EIO; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2478 | |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2479 | kfree(obj); |
| 2480 | return code; |
| 2481 | } |
| 2482 | |
| 2483 | static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus) |
| 2484 | { |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2485 | unsigned int key_value = 1; |
| 2486 | bool autorelease = 1; |
Hans de Goede | b0dbd97 | 2020-05-10 14:24:31 +0200 | [diff] [blame] | 2487 | int result, orig_code; |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2488 | |
Corentin Chary | 57ab7da | 2011-02-26 10:20:32 +0100 | [diff] [blame] | 2489 | orig_code = code; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2490 | |
Seth Forshee | c4453f6 | 2011-07-01 11:34:27 +0200 | [diff] [blame] | 2491 | if (asus->driver->key_filter) { |
| 2492 | asus->driver->key_filter(asus->driver, &code, &key_value, |
| 2493 | &autorelease); |
| 2494 | if (code == ASUS_WMI_KEY_IGNORE) |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2495 | return; |
Seth Forshee | c4453f6 | 2011-07-01 11:34:27 +0200 | [diff] [blame] | 2496 | } |
| 2497 | |
Corentin Chary | 57ab7da | 2011-02-26 10:20:32 +0100 | [diff] [blame] | 2498 | if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) |
Corentin Chary | 3ba0302 | 2012-11-29 09:12:38 +0100 | [diff] [blame] | 2499 | code = ASUS_WMI_BRN_UP; |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2500 | else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX) |
Corentin Chary | 3ba0302 | 2012-11-29 09:12:38 +0100 | [diff] [blame] | 2501 | code = ASUS_WMI_BRN_DOWN; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2502 | |
Corentin Chary | 3ba0302 | 2012-11-29 09:12:38 +0100 | [diff] [blame] | 2503 | if (code == ASUS_WMI_BRN_DOWN || code == ASUS_WMI_BRN_UP) { |
Hans de Goede | 62c4aa1 | 2015-06-16 16:27:58 +0200 | [diff] [blame] | 2504 | if (acpi_video_get_backlight_type() == acpi_backlight_vendor) { |
Corentin Chary | 57ab7da | 2011-02-26 10:20:32 +0100 | [diff] [blame] | 2505 | asus_wmi_backlight_notify(asus, orig_code); |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2506 | return; |
AceLan Kao | a2a96f0 | 2012-10-03 11:26:31 +0200 | [diff] [blame] | 2507 | } |
AceLan Kao | a2a96f0 | 2012-10-03 11:26:31 +0200 | [diff] [blame] | 2508 | } |
| 2509 | |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 2510 | if (code == NOTIFY_KBD_BRTUP) { |
Jian-Hong Pan | 29f6eb5 | 2018-10-22 18:00:04 +0800 | [diff] [blame] | 2511 | kbd_led_set_by_kbd(asus, asus->kbd_led_wk + 1); |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2512 | return; |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 2513 | } |
| 2514 | if (code == NOTIFY_KBD_BRTDWN) { |
Jian-Hong Pan | 29f6eb5 | 2018-10-22 18:00:04 +0800 | [diff] [blame] | 2515 | kbd_led_set_by_kbd(asus, asus->kbd_led_wk - 1); |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2516 | return; |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 2517 | } |
Chris Chiu | ed99d29 | 2018-06-20 22:46:45 +0800 | [diff] [blame] | 2518 | if (code == NOTIFY_KBD_BRTTOGGLE) { |
| 2519 | if (asus->kbd_led_wk == asus->kbd_led.max_brightness) |
Jian-Hong Pan | 29f6eb5 | 2018-10-22 18:00:04 +0800 | [diff] [blame] | 2520 | kbd_led_set_by_kbd(asus, 0); |
Chris Chiu | ed99d29 | 2018-06-20 22:46:45 +0800 | [diff] [blame] | 2521 | else |
Jian-Hong Pan | 29f6eb5 | 2018-10-22 18:00:04 +0800 | [diff] [blame] | 2522 | kbd_led_set_by_kbd(asus, asus->kbd_led_wk + 1); |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2523 | return; |
Chris Chiu | ed99d29 | 2018-06-20 22:46:45 +0800 | [diff] [blame] | 2524 | } |
Chris Chiu | dbb3d78 | 2018-06-20 22:46:44 +0800 | [diff] [blame] | 2525 | |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 2526 | if (code == NOTIFY_FNLOCK_TOGGLE) { |
| 2527 | asus->fnlock_locked = !asus->fnlock_locked; |
| 2528 | asus_wmi_fnlock_update(asus); |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2529 | return; |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 2530 | } |
| 2531 | |
Hans de Goede | 1797d58 | 2020-09-16 16:14:39 +0200 | [diff] [blame] | 2532 | if (asus->driver->quirks->use_kbd_dock_devid && code == NOTIFY_KBD_DOCK_CHANGE) { |
Hans de Goede | b0dbd97 | 2020-05-10 14:24:31 +0200 | [diff] [blame] | 2533 | result = asus_wmi_get_devstate_simple(asus, |
| 2534 | ASUS_WMI_DEVID_KBD_DOCK); |
| 2535 | if (result >= 0) { |
| 2536 | input_report_switch(asus->inputdev, SW_TABLET_MODE, |
| 2537 | !result); |
| 2538 | input_sync(asus->inputdev); |
| 2539 | } |
| 2540 | return; |
| 2541 | } |
| 2542 | |
Samuel Čavoj | ea856ec | 2020-10-21 00:09:44 +0200 | [diff] [blame] | 2543 | if (asus->driver->quirks->use_lid_flip_devid && code == NOTIFY_LID_FLIP) { |
| 2544 | lid_flip_tablet_mode_get_state(asus); |
| 2545 | return; |
| 2546 | } |
| 2547 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 2548 | if (asus->fan_boost_mode_available && code == NOTIFY_KBD_FBM) { |
| 2549 | fan_boost_mode_switch_next(asus); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2550 | return; |
| 2551 | } |
| 2552 | |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 2553 | if (asus->throttle_thermal_policy_available && code == NOTIFY_KBD_TTP) { |
| 2554 | throttle_thermal_policy_switch_next(asus); |
| 2555 | return; |
| 2556 | } |
| 2557 | |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2558 | if (is_display_toggle(code) && asus->driver->quirks->no_display_toggle) |
| 2559 | return; |
AceLan Kao | a2a96f0 | 2012-10-03 11:26:31 +0200 | [diff] [blame] | 2560 | |
| 2561 | if (!sparse_keymap_report_event(asus->inputdev, code, |
| 2562 | key_value, autorelease)) |
Corentin Chary | 57ab7da | 2011-02-26 10:20:32 +0100 | [diff] [blame] | 2563 | pr_info("Unknown key %x pressed\n", code); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 2564 | } |
| 2565 | |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2566 | static void asus_wmi_notify(u32 value, void *context) |
| 2567 | { |
| 2568 | struct asus_wmi *asus = context; |
Yurii Pavlovskyi | 1a373d1 | 2019-05-14 21:02:09 +0200 | [diff] [blame] | 2569 | int code; |
| 2570 | int i; |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2571 | |
Yurii Pavlovskyi | 1a373d1 | 2019-05-14 21:02:09 +0200 | [diff] [blame] | 2572 | for (i = 0; i < WMI_EVENT_QUEUE_SIZE + 1; i++) { |
| 2573 | code = asus_wmi_get_event_code(value); |
Yurii Pavlovskyi | 1a373d1 | 2019-05-14 21:02:09 +0200 | [diff] [blame] | 2574 | if (code < 0) { |
| 2575 | pr_warn("Failed to get notify code: %d\n", code); |
| 2576 | return; |
| 2577 | } |
| 2578 | |
| 2579 | if (code == WMI_EVENT_QUEUE_END || code == WMI_EVENT_MASK) |
| 2580 | return; |
| 2581 | |
| 2582 | asus_wmi_handle_event_code(code, asus); |
| 2583 | |
| 2584 | /* |
| 2585 | * Double check that queue is present: |
| 2586 | * ATK (with queue) uses 0xff, ASUSWMI (without) 0xd2. |
| 2587 | */ |
| 2588 | if (!asus->wmi_event_queue || value != WMI_EVENT_VALUE_ATK) |
| 2589 | return; |
Yurii Pavlovskyi | 8abd752b | 2019-05-14 21:01:24 +0200 | [diff] [blame] | 2590 | } |
| 2591 | |
Yurii Pavlovskyi | 1a373d1 | 2019-05-14 21:02:09 +0200 | [diff] [blame] | 2592 | pr_warn("Failed to process event queue, last code: 0x%x\n", code); |
| 2593 | } |
| 2594 | |
| 2595 | static int asus_wmi_notify_queue_flush(struct asus_wmi *asus) |
| 2596 | { |
| 2597 | int code; |
| 2598 | int i; |
| 2599 | |
| 2600 | for (i = 0; i < WMI_EVENT_QUEUE_SIZE + 1; i++) { |
| 2601 | code = asus_wmi_get_event_code(WMI_EVENT_VALUE_ATK); |
Yurii Pavlovskyi | 1a373d1 | 2019-05-14 21:02:09 +0200 | [diff] [blame] | 2602 | if (code < 0) { |
| 2603 | pr_warn("Failed to get event during flush: %d\n", code); |
| 2604 | return code; |
| 2605 | } |
| 2606 | |
| 2607 | if (code == WMI_EVENT_QUEUE_END || code == WMI_EVENT_MASK) |
| 2608 | return 0; |
| 2609 | } |
| 2610 | |
| 2611 | pr_warn("Failed to flush event queue\n"); |
| 2612 | return -EIO; |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 2613 | } |
| 2614 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 2615 | /* Sysfs **********************************************************************/ |
| 2616 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2617 | static ssize_t store_sys_wmi(struct asus_wmi *asus, int devid, |
| 2618 | const char *buf, size_t count) |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2619 | { |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2620 | u32 retval; |
Andy Shevchenko | a5556fa | 2019-08-16 14:15:55 +0300 | [diff] [blame] | 2621 | int err, value; |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2622 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2623 | value = asus_wmi_get_devstate_simple(asus, devid); |
Dan Carpenter | b829834 | 2015-11-11 01:18:16 +0300 | [diff] [blame] | 2624 | if (value < 0) |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2625 | return value; |
| 2626 | |
Andy Shevchenko | a5556fa | 2019-08-16 14:15:55 +0300 | [diff] [blame] | 2627 | err = kstrtoint(buf, 0, &value); |
| 2628 | if (err) |
| 2629 | return err; |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2630 | |
Andy Shevchenko | a5556fa | 2019-08-16 14:15:55 +0300 | [diff] [blame] | 2631 | err = asus_wmi_set_devstate(devid, value, &retval); |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 2632 | if (err < 0) |
| 2633 | return err; |
| 2634 | |
Andy Shevchenko | a5556fa | 2019-08-16 14:15:55 +0300 | [diff] [blame] | 2635 | return count; |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2636 | } |
| 2637 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2638 | 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] | 2639 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2640 | int value = asus_wmi_get_devstate_simple(asus, devid); |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2641 | |
| 2642 | if (value < 0) |
| 2643 | return value; |
| 2644 | |
| 2645 | return sprintf(buf, "%d\n", value); |
| 2646 | } |
| 2647 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2648 | #define ASUS_WMI_CREATE_DEVICE_ATTR(_name, _mode, _cm) \ |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2649 | static ssize_t show_##_name(struct device *dev, \ |
| 2650 | struct device_attribute *attr, \ |
| 2651 | char *buf) \ |
| 2652 | { \ |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2653 | struct asus_wmi *asus = dev_get_drvdata(dev); \ |
| 2654 | \ |
| 2655 | return show_sys_wmi(asus, _cm, buf); \ |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2656 | } \ |
| 2657 | static ssize_t store_##_name(struct device *dev, \ |
| 2658 | struct device_attribute *attr, \ |
| 2659 | const char *buf, size_t count) \ |
| 2660 | { \ |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2661 | struct asus_wmi *asus = dev_get_drvdata(dev); \ |
| 2662 | \ |
| 2663 | return store_sys_wmi(asus, _cm, buf, count); \ |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2664 | } \ |
| 2665 | static struct device_attribute dev_attr_##_name = { \ |
| 2666 | .attr = { \ |
| 2667 | .name = __stringify(_name), \ |
| 2668 | .mode = _mode }, \ |
| 2669 | .show = show_##_name, \ |
| 2670 | .store = store_##_name, \ |
| 2671 | } |
| 2672 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2673 | ASUS_WMI_CREATE_DEVICE_ATTR(touchpad, 0644, ASUS_WMI_DEVID_TOUCHPAD); |
| 2674 | ASUS_WMI_CREATE_DEVICE_ATTR(camera, 0644, ASUS_WMI_DEVID_CAMERA); |
| 2675 | ASUS_WMI_CREATE_DEVICE_ATTR(cardr, 0644, ASUS_WMI_DEVID_CARDREADER); |
AceLan Kao | c0b91b6 | 2012-06-13 09:32:07 +0200 | [diff] [blame] | 2676 | 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] | 2677 | 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] | 2678 | |
Jérémy Lefaure | a8fe342 | 2017-04-21 22:19:45 -0400 | [diff] [blame] | 2679 | static ssize_t cpufv_store(struct device *dev, struct device_attribute *attr, |
Dmitry Torokhov | 67fa38e | 2010-11-03 11:14:01 -0700 | [diff] [blame] | 2680 | const char *buf, size_t count) |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2681 | { |
Corentin Chary | 3df5fda | 2011-07-01 11:34:38 +0200 | [diff] [blame] | 2682 | int value, rv; |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2683 | |
Andy Shevchenko | a5556fa | 2019-08-16 14:15:55 +0300 | [diff] [blame] | 2684 | rv = kstrtoint(buf, 0, &value); |
| 2685 | if (rv) |
| 2686 | return rv; |
| 2687 | |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2688 | if (value < 0 || value > 2) |
| 2689 | return -EINVAL; |
| 2690 | |
Corentin Chary | 3df5fda | 2011-07-01 11:34:38 +0200 | [diff] [blame] | 2691 | rv = asus_wmi_evaluate_method(ASUS_WMI_METHODID_CFVS, value, 0, NULL); |
| 2692 | if (rv < 0) |
| 2693 | return rv; |
| 2694 | |
| 2695 | return count; |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2696 | } |
| 2697 | |
Jérémy Lefaure | a8fe342 | 2017-04-21 22:19:45 -0400 | [diff] [blame] | 2698 | static DEVICE_ATTR_WO(cpufv); |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2699 | |
Corentin Chary | 4e37b42 | 2010-11-29 08:14:08 +0100 | [diff] [blame] | 2700 | static struct attribute *platform_attributes[] = { |
| 2701 | &dev_attr_cpufv.attr, |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2702 | &dev_attr_camera.attr, |
| 2703 | &dev_attr_cardr.attr, |
Corentin Chary | 4615bb6 | 2011-02-06 13:28:42 +0100 | [diff] [blame] | 2704 | &dev_attr_touchpad.attr, |
Luke D. Jones | 382b91d | 2021-08-07 14:36:56 +1200 | [diff] [blame] | 2705 | &dev_attr_egpu_enable.attr, |
Luke D. Jones | 98829e8 | 2021-08-07 14:36:55 +1200 | [diff] [blame] | 2706 | &dev_attr_dgpu_disable.attr, |
AceLan Kao | c0b91b6 | 2012-06-13 09:32:07 +0200 | [diff] [blame] | 2707 | &dev_attr_lid_resume.attr, |
Oleksij Rempel | aca234f | 2016-04-01 13:35:21 +0200 | [diff] [blame] | 2708 | &dev_attr_als_enable.attr, |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 2709 | &dev_attr_fan_boost_mode.attr, |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 2710 | &dev_attr_throttle_thermal_policy.attr, |
Luke D. Jones | ca91ea34 | 2021-08-07 14:36:54 +1200 | [diff] [blame] | 2711 | &dev_attr_panel_od.attr, |
Corentin Chary | 4e37b42 | 2010-11-29 08:14:08 +0100 | [diff] [blame] | 2712 | NULL |
| 2713 | }; |
| 2714 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 2715 | static umode_t asus_sysfs_is_visible(struct kobject *kobj, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2716 | struct attribute *attr, int idx) |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2717 | { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2718 | struct device *dev = container_of(kobj, struct device, kobj); |
Wolfram Sang | d605ca2 | 2018-04-19 16:06:10 +0200 | [diff] [blame] | 2719 | struct asus_wmi *asus = dev_get_drvdata(dev); |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2720 | bool ok = true; |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2721 | int devid = -1; |
| 2722 | |
| 2723 | if (attr == &dev_attr_camera.attr) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2724 | devid = ASUS_WMI_DEVID_CAMERA; |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2725 | else if (attr == &dev_attr_cardr.attr) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2726 | devid = ASUS_WMI_DEVID_CARDREADER; |
Corentin Chary | 4615bb6 | 2011-02-06 13:28:42 +0100 | [diff] [blame] | 2727 | else if (attr == &dev_attr_touchpad.attr) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2728 | devid = ASUS_WMI_DEVID_TOUCHPAD; |
AceLan Kao | c0b91b6 | 2012-06-13 09:32:07 +0200 | [diff] [blame] | 2729 | else if (attr == &dev_attr_lid_resume.attr) |
| 2730 | devid = ASUS_WMI_DEVID_LID_RESUME; |
Oleksij Rempel | aca234f | 2016-04-01 13:35:21 +0200 | [diff] [blame] | 2731 | else if (attr == &dev_attr_als_enable.attr) |
| 2732 | devid = ASUS_WMI_DEVID_ALS_ENABLE; |
Luke D. Jones | 382b91d | 2021-08-07 14:36:56 +1200 | [diff] [blame] | 2733 | else if (attr == &dev_attr_egpu_enable.attr) |
| 2734 | ok = asus->egpu_enable_available; |
Luke D. Jones | 98829e8 | 2021-08-07 14:36:55 +1200 | [diff] [blame] | 2735 | else if (attr == &dev_attr_dgpu_disable.attr) |
| 2736 | ok = asus->dgpu_disable_available; |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 2737 | else if (attr == &dev_attr_fan_boost_mode.attr) |
| 2738 | ok = asus->fan_boost_mode_available; |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 2739 | else if (attr == &dev_attr_throttle_thermal_policy.attr) |
| 2740 | ok = asus->throttle_thermal_policy_available; |
Luke D. Jones | ca91ea34 | 2021-08-07 14:36:54 +1200 | [diff] [blame] | 2741 | else if (attr == &dev_attr_panel_od.attr) |
| 2742 | ok = asus->panel_overdrive_available; |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2743 | |
| 2744 | if (devid != -1) |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2745 | ok = !(asus_wmi_get_devstate_simple(asus, devid) < 0); |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2746 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2747 | return ok ? attr->mode : 0; |
Corentin Chary | 9e1565b | 2011-02-06 13:28:36 +0100 | [diff] [blame] | 2748 | } |
| 2749 | |
Arvind Yadav | e90d9ba | 2017-07-11 16:18:19 +0530 | [diff] [blame] | 2750 | static const struct attribute_group platform_attribute_group = { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2751 | .is_visible = asus_sysfs_is_visible, |
| 2752 | .attrs = platform_attributes |
Corentin Chary | 4e37b42 | 2010-11-29 08:14:08 +0100 | [diff] [blame] | 2753 | }; |
| 2754 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2755 | static void asus_wmi_sysfs_exit(struct platform_device *device) |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2756 | { |
Corentin Chary | 4e37b42 | 2010-11-29 08:14:08 +0100 | [diff] [blame] | 2757 | sysfs_remove_group(&device->dev.kobj, &platform_attribute_group); |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2758 | } |
| 2759 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2760 | static int asus_wmi_sysfs_init(struct platform_device *device) |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2761 | { |
Corentin Chary | 4e37b42 | 2010-11-29 08:14:08 +0100 | [diff] [blame] | 2762 | return sysfs_create_group(&device->dev.kobj, &platform_attribute_group); |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 2763 | } |
| 2764 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 2765 | /* Platform device ************************************************************/ |
| 2766 | |
Joe Perches | 39ddf3b | 2011-03-29 15:21:32 -0700 | [diff] [blame] | 2767 | static int asus_wmi_platform_init(struct asus_wmi *asus) |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2768 | { |
Yurii Pavlovskyi | e0668f2 | 2019-05-14 21:00:31 +0200 | [diff] [blame] | 2769 | struct device *dev = &asus->platform_device->dev; |
| 2770 | char *wmi_uid; |
Corentin Chary | 46dbca8 | 2011-02-26 10:20:38 +0100 | [diff] [blame] | 2771 | int rv; |
| 2772 | |
| 2773 | /* INIT enable hotkeys on some models */ |
| 2774 | if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_INIT, 0, 0, &rv)) |
vic | 0ed6065 | 2013-05-22 21:32:10 +0300 | [diff] [blame] | 2775 | pr_info("Initialization: %#x\n", rv); |
Corentin Chary | 46dbca8 | 2011-02-26 10:20:38 +0100 | [diff] [blame] | 2776 | |
| 2777 | /* We don't know yet what to do with this version... */ |
| 2778 | if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_SPEC, 0, 0x9, &rv)) { |
vic | 0ed6065 | 2013-05-22 21:32:10 +0300 | [diff] [blame] | 2779 | pr_info("BIOS WMI version: %d.%d\n", rv >> 16, rv & 0xFF); |
Corentin Chary | 46dbca8 | 2011-02-26 10:20:38 +0100 | [diff] [blame] | 2780 | asus->spec = rv; |
| 2781 | } |
| 2782 | |
| 2783 | /* |
| 2784 | * The SFUN method probably allows the original driver to get the list |
| 2785 | * of features supported by a given model. For now, 0x0100 or 0x0800 |
| 2786 | * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card. |
| 2787 | * The significance of others is yet to be found. |
| 2788 | */ |
| 2789 | if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_SFUN, 0, 0, &rv)) { |
vic | 0ed6065 | 2013-05-22 21:32:10 +0300 | [diff] [blame] | 2790 | pr_info("SFUN value: %#x\n", rv); |
Corentin Chary | 46dbca8 | 2011-02-26 10:20:38 +0100 | [diff] [blame] | 2791 | asus->sfun = rv; |
| 2792 | } |
| 2793 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2794 | /* |
| 2795 | * Eee PC and Notebooks seems to have different method_id for DSTS, |
| 2796 | * but it may also be related to the BIOS's SPEC. |
| 2797 | * Note, on most Eeepc, there is no way to check if a method exist |
| 2798 | * or note, while on notebooks, they returns 0xFFFFFFFE on failure, |
| 2799 | * 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] | 2800 | * |
| 2801 | * Additionally at least TUF Gaming series laptops return nothing for |
| 2802 | * unknown methods, so the detection in this way is not possible. |
| 2803 | * |
| 2804 | * There is strong indication that only ACPI WMI devices that have _UID |
| 2805 | * equal to "ASUSWMI" use DCTS whereas those with "ATK" use DSTS. |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2806 | */ |
Yurii Pavlovskyi | e0668f2 | 2019-05-14 21:00:31 +0200 | [diff] [blame] | 2807 | wmi_uid = wmi_get_acpi_device_uid(ASUS_WMI_MGMT_GUID); |
| 2808 | if (!wmi_uid) |
| 2809 | return -ENODEV; |
| 2810 | |
| 2811 | if (!strcmp(wmi_uid, ASUS_ACPI_UID_ASUSWMI)) { |
| 2812 | dev_info(dev, "Detected ASUSWMI, use DCTS\n"); |
| 2813 | asus->dsts_id = ASUS_WMI_METHODID_DCTS; |
| 2814 | } else { |
| 2815 | dev_info(dev, "Detected %s, not ASUSWMI, use DSTS\n", wmi_uid); |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2816 | asus->dsts_id = ASUS_WMI_METHODID_DSTS; |
Yurii Pavlovskyi | e0668f2 | 2019-05-14 21:00:31 +0200 | [diff] [blame] | 2817 | } |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2818 | |
Yurii Pavlovskyi | 1a373d1 | 2019-05-14 21:02:09 +0200 | [diff] [blame] | 2819 | /* |
| 2820 | * Some devices can have multiple event codes stored in a queue before |
| 2821 | * the module load if it was unloaded intermittently after calling |
| 2822 | * the INIT method (enables event handling). The WMI notify handler is |
| 2823 | * expected to retrieve all event codes until a retrieved code equals |
| 2824 | * queue end marker (One or Ones). Old codes are flushed from the queue |
| 2825 | * upon module load. Not enabling this when it should be has minimal |
| 2826 | * visible impact so fall back if anything goes wrong. |
| 2827 | */ |
| 2828 | wmi_uid = wmi_get_acpi_device_uid(asus->driver->event_guid); |
| 2829 | if (wmi_uid && !strcmp(wmi_uid, ASUS_ACPI_UID_ATK)) { |
| 2830 | dev_info(dev, "Detected ATK, enable event queue\n"); |
| 2831 | |
| 2832 | if (!asus_wmi_notify_queue_flush(asus)) |
| 2833 | asus->wmi_event_queue = true; |
| 2834 | } |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2835 | |
Corentin Chary | fddbfed | 2011-07-01 11:34:39 +0200 | [diff] [blame] | 2836 | /* CWAP allow to define the behavior of the Fn+F2 key, |
| 2837 | * this method doesn't seems to be present on Eee PCs */ |
Corentin Chary | 6a2bccc | 2012-03-20 09:53:10 +0100 | [diff] [blame] | 2838 | if (asus->driver->quirks->wapf >= 0) |
Corentin Chary | fddbfed | 2011-07-01 11:34:39 +0200 | [diff] [blame] | 2839 | asus_wmi_set_devstate(ASUS_WMI_DEVID_CWAP, |
Corentin Chary | 6a2bccc | 2012-03-20 09:53:10 +0100 | [diff] [blame] | 2840 | asus->driver->quirks->wapf, NULL); |
Corentin Chary | fddbfed | 2011-07-01 11:34:39 +0200 | [diff] [blame] | 2841 | |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 2842 | return 0; |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2843 | } |
| 2844 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 2845 | /* debugfs ********************************************************************/ |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2846 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2847 | struct asus_wmi_debugfs_node { |
| 2848 | struct asus_wmi *asus; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2849 | char *name; |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2850 | int (*show) (struct seq_file *m, void *data); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2851 | }; |
| 2852 | |
| 2853 | static int show_dsts(struct seq_file *m, void *data) |
| 2854 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2855 | struct asus_wmi *asus = m->private; |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 2856 | int err; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2857 | u32 retval = -1; |
| 2858 | |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 2859 | err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval); |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 2860 | if (err < 0) |
| 2861 | return err; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2862 | |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 2863 | seq_printf(m, "DSTS(%#x) = %#x\n", asus->debug.dev_id, retval); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2864 | |
| 2865 | return 0; |
| 2866 | } |
| 2867 | |
| 2868 | static int show_devs(struct seq_file *m, void *data) |
| 2869 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2870 | struct asus_wmi *asus = m->private; |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 2871 | int err; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2872 | u32 retval = -1; |
| 2873 | |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 2874 | err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param, |
| 2875 | &retval); |
Corentin Chary | d33da3b | 2011-02-26 10:20:35 +0100 | [diff] [blame] | 2876 | if (err < 0) |
| 2877 | return err; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2878 | |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 2879 | seq_printf(m, "DEVS(%#x, %#x) = %#x\n", asus->debug.dev_id, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2880 | asus->debug.ctrl_param, retval); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2881 | |
| 2882 | return 0; |
| 2883 | } |
| 2884 | |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 2885 | static int show_call(struct seq_file *m, void *data) |
| 2886 | { |
| 2887 | struct asus_wmi *asus = m->private; |
| 2888 | struct bios_args args = { |
| 2889 | .arg0 = asus->debug.dev_id, |
| 2890 | .arg1 = asus->debug.ctrl_param, |
| 2891 | }; |
| 2892 | struct acpi_buffer input = { (acpi_size) sizeof(args), &args }; |
| 2893 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 2894 | union acpi_object *obj; |
| 2895 | acpi_status status; |
| 2896 | |
| 2897 | status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID, |
Pali Rohár | 0fe5726 | 2017-08-12 09:44:16 +0200 | [diff] [blame] | 2898 | 0, asus->debug.method_id, |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 2899 | &input, &output); |
| 2900 | |
| 2901 | if (ACPI_FAILURE(status)) |
| 2902 | return -EIO; |
| 2903 | |
| 2904 | obj = (union acpi_object *)output.pointer; |
| 2905 | if (obj && obj->type == ACPI_TYPE_INTEGER) |
| 2906 | seq_printf(m, "%#x(%#x, %#x) = %#x\n", asus->debug.method_id, |
| 2907 | asus->debug.dev_id, asus->debug.ctrl_param, |
| 2908 | (u32) obj->integer.value); |
| 2909 | else |
| 2910 | seq_printf(m, "%#x(%#x, %#x) = t:%d\n", asus->debug.method_id, |
| 2911 | asus->debug.dev_id, asus->debug.ctrl_param, |
Dan Carpenter | a1d6086 | 2011-03-15 10:07:37 +0300 | [diff] [blame] | 2912 | obj ? obj->type : -1); |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 2913 | |
| 2914 | kfree(obj); |
| 2915 | |
| 2916 | return 0; |
| 2917 | } |
| 2918 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2919 | static struct asus_wmi_debugfs_node asus_wmi_debug_files[] = { |
| 2920 | {NULL, "devs", show_devs}, |
| 2921 | {NULL, "dsts", show_dsts}, |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 2922 | {NULL, "call", show_call}, |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2923 | }; |
| 2924 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2925 | static int asus_wmi_debugfs_open(struct inode *inode, struct file *file) |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2926 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2927 | struct asus_wmi_debugfs_node *node = inode->i_private; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2928 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2929 | return single_open(file, node->show, node->asus); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2930 | } |
| 2931 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2932 | static const struct file_operations asus_wmi_debugfs_io_ops = { |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2933 | .owner = THIS_MODULE, |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2934 | .open = asus_wmi_debugfs_open, |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2935 | .read = seq_read, |
| 2936 | .llseek = seq_lseek, |
| 2937 | .release = single_release, |
| 2938 | }; |
| 2939 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2940 | static void asus_wmi_debugfs_exit(struct asus_wmi *asus) |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2941 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2942 | debugfs_remove_recursive(asus->debug.root); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2943 | } |
| 2944 | |
Greg Kroah-Hartman | d2785d3 | 2019-06-12 14:12:52 +0200 | [diff] [blame] | 2945 | static void asus_wmi_debugfs_init(struct asus_wmi *asus) |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2946 | { |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2947 | int i; |
| 2948 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2949 | asus->debug.root = debugfs_create_dir(asus->driver->name, NULL); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2950 | |
Greg Kroah-Hartman | d2785d3 | 2019-06-12 14:12:52 +0200 | [diff] [blame] | 2951 | debugfs_create_x32("method_id", S_IRUGO | S_IWUSR, asus->debug.root, |
| 2952 | &asus->debug.method_id); |
Corentin Chary | ef34349 | 2011-02-26 10:20:39 +0100 | [diff] [blame] | 2953 | |
Greg Kroah-Hartman | d2785d3 | 2019-06-12 14:12:52 +0200 | [diff] [blame] | 2954 | debugfs_create_x32("dev_id", S_IRUGO | S_IWUSR, asus->debug.root, |
| 2955 | &asus->debug.dev_id); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2956 | |
Greg Kroah-Hartman | d2785d3 | 2019-06-12 14:12:52 +0200 | [diff] [blame] | 2957 | debugfs_create_x32("ctrl_param", S_IRUGO | S_IWUSR, asus->debug.root, |
| 2958 | &asus->debug.ctrl_param); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2959 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2960 | for (i = 0; i < ARRAY_SIZE(asus_wmi_debug_files); i++) { |
| 2961 | struct asus_wmi_debugfs_node *node = &asus_wmi_debug_files[i]; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2962 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2963 | node->asus = asus; |
Greg Kroah-Hartman | d2785d3 | 2019-06-12 14:12:52 +0200 | [diff] [blame] | 2964 | debugfs_create_file(node->name, S_IFREG | S_IRUGO, |
| 2965 | asus->debug.root, node, |
| 2966 | &asus_wmi_debugfs_io_ops); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2967 | } |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 2968 | } |
| 2969 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 2970 | /* Init / exit ****************************************************************/ |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 2971 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2972 | static int asus_wmi_add(struct platform_device *pdev) |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 2973 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2974 | struct platform_driver *pdrv = to_platform_driver(pdev->dev.driver); |
| 2975 | struct asus_wmi_driver *wdrv = to_asus_wmi_driver(pdrv); |
| 2976 | struct asus_wmi *asus; |
Hans de Goede | d8c66f6 | 2014-07-08 10:47:21 +0200 | [diff] [blame] | 2977 | const char *chassis_type; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 2978 | acpi_status status; |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2979 | int err; |
AceLan Kao | a50bd12 | 2012-07-26 17:13:31 +0800 | [diff] [blame] | 2980 | u32 result; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 2981 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2982 | asus = kzalloc(sizeof(struct asus_wmi), GFP_KERNEL); |
| 2983 | if (!asus) |
Corentin Chary | a04ce29 | 2011-02-06 13:28:33 +0100 | [diff] [blame] | 2984 | return -ENOMEM; |
| 2985 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2986 | asus->driver = wdrv; |
| 2987 | asus->platform_device = pdev; |
| 2988 | wdrv->platform_device = pdev; |
| 2989 | platform_set_drvdata(asus->platform_device, asus); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2990 | |
AceLan Kao | c87992d | 2012-03-20 09:53:08 +0100 | [diff] [blame] | 2991 | if (wdrv->detect_quirks) |
| 2992 | wdrv->detect_quirks(asus->driver); |
Corentin Chary | afa7c88 | 2011-02-06 13:28:28 +0100 | [diff] [blame] | 2993 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 2994 | err = asus_wmi_platform_init(asus); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 2995 | if (err) |
| 2996 | goto fail_platform; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 2997 | |
Luke D. Jones | 382b91d | 2021-08-07 14:36:56 +1200 | [diff] [blame] | 2998 | err = egpu_enable_check_present(asus); |
| 2999 | if (err) |
| 3000 | goto fail_egpu_enable; |
| 3001 | |
Luke D. Jones | 98829e8 | 2021-08-07 14:36:55 +1200 | [diff] [blame] | 3002 | err = dgpu_disable_check_present(asus); |
| 3003 | if (err) |
| 3004 | goto fail_dgpu_disable; |
| 3005 | |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 3006 | err = fan_boost_mode_check_present(asus); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 3007 | if (err) |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 3008 | goto fail_fan_boost_mode; |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 3009 | |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 3010 | err = throttle_thermal_policy_check_present(asus); |
| 3011 | if (err) |
| 3012 | goto fail_throttle_thermal_policy; |
Leonid Maksymchuk | a282158 | 2019-12-15 16:27:24 +0200 | [diff] [blame] | 3013 | else |
| 3014 | throttle_thermal_policy_set_default(asus); |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 3015 | |
Luke D. Jones | c63d44a | 2021-08-19 07:07:31 +1200 | [diff] [blame] | 3016 | err = platform_profile_setup(asus); |
| 3017 | if (err) |
| 3018 | goto fail_platform_profile_setup; |
| 3019 | |
Luke D. Jones | ca91ea34 | 2021-08-07 14:36:54 +1200 | [diff] [blame] | 3020 | err = panel_od_check_present(asus); |
| 3021 | if (err) |
| 3022 | goto fail_panel_od; |
| 3023 | |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 3024 | err = asus_wmi_sysfs_init(asus->platform_device); |
| 3025 | if (err) |
| 3026 | goto fail_sysfs; |
| 3027 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3028 | err = asus_wmi_input_init(asus); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 3029 | if (err) |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 3030 | goto fail_input; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 3031 | |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 3032 | err = asus_wmi_fan_init(asus); /* probably no problems on error */ |
Kast Bernd | 53e755c | 2015-05-13 16:24:16 +0200 | [diff] [blame] | 3033 | |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 3034 | err = asus_wmi_hwmon_init(asus); |
| 3035 | if (err) |
| 3036 | goto fail_hwmon; |
| 3037 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3038 | err = asus_wmi_led_init(asus); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 3039 | if (err) |
| 3040 | goto fail_leds; |
| 3041 | |
João Paulo Rechi Vita | 71050ae | 2017-02-20 14:50:22 -0500 | [diff] [blame] | 3042 | asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WLAN, &result); |
| 3043 | if (result & (ASUS_WMI_DSTS_PRESENCE_BIT | ASUS_WMI_DSTS_USER_BIT)) |
| 3044 | asus->driver->wlan_ctrl_by_user = 1; |
| 3045 | |
João Paulo Rechi Vita | d1c4e9b | 2017-02-20 14:50:23 -0500 | [diff] [blame] | 3046 | if (!(asus->driver->wlan_ctrl_by_user && ashs_present())) { |
João Paulo Rechi Vita | a977e59 | 2016-06-13 16:57:31 -0400 | [diff] [blame] | 3047 | err = asus_wmi_rfkill_init(asus); |
| 3048 | if (err) |
| 3049 | goto fail_rfkill; |
| 3050 | } |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 3051 | |
Oleksij Rempel | e9b6151 | 2017-04-28 16:19:49 +0200 | [diff] [blame] | 3052 | if (asus->driver->quirks->wmi_force_als_set) |
| 3053 | asus_wmi_set_als(); |
| 3054 | |
Hans de Goede | d8c66f6 | 2014-07-08 10:47:21 +0200 | [diff] [blame] | 3055 | /* Some Asus desktop boards export an acpi-video backlight interface, |
| 3056 | stop this from showing up */ |
| 3057 | chassis_type = dmi_get_system_info(DMI_CHASSIS_TYPE); |
| 3058 | if (chassis_type && !strcmp(chassis_type, "3")) |
Hans de Goede | 62c4aa1 | 2015-06-16 16:27:58 +0200 | [diff] [blame] | 3059 | acpi_video_set_dmi_backlight_type(acpi_backlight_vendor); |
| 3060 | |
AceLan Kao | 272c77d | 2012-06-13 09:32:06 +0200 | [diff] [blame] | 3061 | if (asus->driver->quirks->wmi_backlight_power) |
Hans de Goede | 62c4aa1 | 2015-06-16 16:27:58 +0200 | [diff] [blame] | 3062 | acpi_video_set_dmi_backlight_type(acpi_backlight_vendor); |
| 3063 | |
zino lin | 999d437 | 2016-08-28 16:12:06 +0800 | [diff] [blame] | 3064 | if (asus->driver->quirks->wmi_backlight_native) |
| 3065 | acpi_video_set_dmi_backlight_type(acpi_backlight_native); |
| 3066 | |
Kai-Chuan Hsieh | 8023eff | 2016-09-01 23:55:55 +0800 | [diff] [blame] | 3067 | if (asus->driver->quirks->xusb2pr) |
| 3068 | asus_wmi_set_xusb2pr(asus); |
| 3069 | |
Hans de Goede | 62c4aa1 | 2015-06-16 16:27:58 +0200 | [diff] [blame] | 3070 | if (acpi_video_get_backlight_type() == acpi_backlight_vendor) { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3071 | err = asus_wmi_backlight_init(asus); |
Corentin Chary | b718726 | 2011-02-06 13:28:39 +0100 | [diff] [blame] | 3072 | if (err && err != -ENODEV) |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 3073 | goto fail_backlight; |
Hans de Goede | 401fee8 | 2019-06-12 09:02:02 +0200 | [diff] [blame] | 3074 | } else if (asus->driver->quirks->wmi_backlight_set_devstate) |
João Paulo Rechi Vita | 78f3ac7 | 2018-10-31 17:21:26 -0700 | [diff] [blame] | 3075 | err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BACKLIGHT, 2, NULL); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 3076 | |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 3077 | if (asus_wmi_has_fnlock_key(asus)) { |
Luca Stefani | ce357fd | 2021-03-23 22:01:26 +0100 | [diff] [blame] | 3078 | asus->fnlock_locked = fnlock_default; |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 3079 | asus_wmi_fnlock_update(asus); |
| 3080 | } |
| 3081 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3082 | status = wmi_install_notify_handler(asus->driver->event_guid, |
| 3083 | asus_wmi_notify, asus); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 3084 | if (ACPI_FAILURE(status)) { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3085 | pr_err("Unable to register notify handler - %d\n", status); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 3086 | err = -ENODEV; |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 3087 | goto fail_wmi_handler; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 3088 | } |
| 3089 | |
Kristian Klausen | 7973353 | 2019-09-09 19:31:28 +0200 | [diff] [blame] | 3090 | asus_wmi_battery_init(asus); |
| 3091 | |
Greg Kroah-Hartman | d2785d3 | 2019-06-12 14:12:52 +0200 | [diff] [blame] | 3092 | asus_wmi_debugfs_init(asus); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame] | 3093 | |
Corentin Chary | a04ce29 | 2011-02-06 13:28:33 +0100 | [diff] [blame] | 3094 | return 0; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 3095 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 3096 | fail_wmi_handler: |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3097 | asus_wmi_backlight_exit(asus); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 3098 | fail_backlight: |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3099 | asus_wmi_rfkill_exit(asus); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 3100 | fail_rfkill: |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3101 | asus_wmi_led_exit(asus); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 3102 | fail_leds: |
Corentin Chary | e07babd | 2011-02-26 10:20:42 +0100 | [diff] [blame] | 3103 | fail_hwmon: |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3104 | asus_wmi_input_exit(asus); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 3105 | fail_input: |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 3106 | asus_wmi_sysfs_exit(asus->platform_device); |
| 3107 | fail_sysfs: |
Leonid Maksymchuk | 2daa86e | 2019-12-15 16:26:34 +0200 | [diff] [blame] | 3108 | fail_throttle_thermal_policy: |
Luke D. Jones | c63d44a | 2021-08-19 07:07:31 +1200 | [diff] [blame] | 3109 | fail_platform_profile_setup: |
| 3110 | if (asus->platform_profile_support) |
| 3111 | platform_profile_remove(); |
Daniel Drake | 9af93db | 2019-07-17 13:10:58 +0800 | [diff] [blame] | 3112 | fail_fan_boost_mode: |
Luke D. Jones | 382b91d | 2021-08-07 14:36:56 +1200 | [diff] [blame] | 3113 | fail_egpu_enable: |
Luke D. Jones | 98829e8 | 2021-08-07 14:36:55 +1200 | [diff] [blame] | 3114 | fail_dgpu_disable: |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 3115 | fail_platform: |
Luke D. Jones | ca91ea34 | 2021-08-07 14:36:54 +1200 | [diff] [blame] | 3116 | fail_panel_od: |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3117 | kfree(asus); |
Corentin Chary | a04ce29 | 2011-02-06 13:28:33 +0100 | [diff] [blame] | 3118 | return err; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 3119 | } |
| 3120 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3121 | static int asus_wmi_remove(struct platform_device *device) |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 3122 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3123 | struct asus_wmi *asus; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 3124 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3125 | asus = platform_get_drvdata(device); |
| 3126 | wmi_remove_notify_handler(asus->driver->event_guid); |
| 3127 | asus_wmi_backlight_exit(asus); |
| 3128 | asus_wmi_input_exit(asus); |
| 3129 | asus_wmi_led_exit(asus); |
| 3130 | asus_wmi_rfkill_exit(asus); |
| 3131 | asus_wmi_debugfs_exit(asus); |
Yurii Pavlovskyi | b096f62 | 2019-05-14 21:07:05 +0200 | [diff] [blame] | 3132 | asus_wmi_sysfs_exit(asus->platform_device); |
Daniel Drake | 2889ffc | 2019-07-29 16:27:37 +0800 | [diff] [blame] | 3133 | asus_fan_set_auto(asus); |
Kristian Klausen | 7973353 | 2019-09-09 19:31:28 +0200 | [diff] [blame] | 3134 | asus_wmi_battery_exit(asus); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 3135 | |
Luke D. Jones | c63d44a | 2021-08-19 07:07:31 +1200 | [diff] [blame] | 3136 | if (asus->platform_profile_support) |
| 3137 | platform_profile_remove(); |
| 3138 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3139 | kfree(asus); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 3140 | return 0; |
| 3141 | } |
| 3142 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 3143 | /* Platform driver - hibernate/resume callbacks *******************************/ |
| 3144 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3145 | static int asus_hotk_thaw(struct device *device) |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 3146 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3147 | struct asus_wmi *asus = dev_get_drvdata(device); |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 3148 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 3149 | if (asus->wlan.rfkill) { |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 3150 | bool wlan; |
| 3151 | |
| 3152 | /* |
| 3153 | * Work around bios bug - acpi _PTS turns off the wireless led |
| 3154 | * during suspend. Normally it restores it on resume, but |
| 3155 | * we should kick it ourselves in case hibernation is aborted. |
| 3156 | */ |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 3157 | wlan = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WLAN); |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3158 | asus_wmi_set_devstate(ASUS_WMI_DEVID_WLAN, wlan, NULL); |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 3159 | } |
| 3160 | |
| 3161 | return 0; |
| 3162 | } |
| 3163 | |
Oleksij Rempel | 3073404 | 2015-09-14 11:16:30 +0200 | [diff] [blame] | 3164 | static int asus_hotk_resume(struct device *device) |
| 3165 | { |
| 3166 | struct asus_wmi *asus = dev_get_drvdata(device); |
| 3167 | |
| 3168 | if (!IS_ERR_OR_NULL(asus->kbd_led.dev)) |
Jian-Hong Pan | 9fe44fc | 2018-09-27 16:50:09 +0800 | [diff] [blame] | 3169 | kbd_led_update(asus); |
Oleksij Rempel | 3073404 | 2015-09-14 11:16:30 +0200 | [diff] [blame] | 3170 | |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 3171 | if (asus_wmi_has_fnlock_key(asus)) |
| 3172 | asus_wmi_fnlock_update(asus); |
Samuel Čavoj | ea856ec | 2020-10-21 00:09:44 +0200 | [diff] [blame] | 3173 | |
| 3174 | if (asus->driver->quirks->use_lid_flip_devid) |
| 3175 | lid_flip_tablet_mode_get_state(asus); |
| 3176 | |
Oleksij Rempel | 3073404 | 2015-09-14 11:16:30 +0200 | [diff] [blame] | 3177 | return 0; |
| 3178 | } |
| 3179 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3180 | static int asus_hotk_restore(struct device *device) |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 3181 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3182 | struct asus_wmi *asus = dev_get_drvdata(device); |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 3183 | int bl; |
| 3184 | |
| 3185 | /* Refresh both wlan rfkill state and pci hotplug */ |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 3186 | if (asus->wlan.rfkill) |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3187 | asus_rfkill_hotplug(asus); |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 3188 | |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 3189 | if (asus->bluetooth.rfkill) { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 3190 | bl = !asus_wmi_get_devstate_simple(asus, |
| 3191 | ASUS_WMI_DEVID_BLUETOOTH); |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 3192 | rfkill_set_sw_state(asus->bluetooth.rfkill, bl); |
Corentin Chary | 2e9e159 | 2011-02-06 13:28:37 +0100 | [diff] [blame] | 3193 | } |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 3194 | if (asus->wimax.rfkill) { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 3195 | bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WIMAX); |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 3196 | rfkill_set_sw_state(asus->wimax.rfkill, bl); |
Corentin Chary | 2e9e159 | 2011-02-06 13:28:37 +0100 | [diff] [blame] | 3197 | } |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 3198 | if (asus->wwan3g.rfkill) { |
Corentin Chary | 1d070f8 | 2011-02-26 10:20:36 +0100 | [diff] [blame] | 3199 | bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WWAN3G); |
Corentin Chary | a7ce3f0 | 2011-02-26 10:20:33 +0100 | [diff] [blame] | 3200 | rfkill_set_sw_state(asus->wwan3g.rfkill, bl); |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 3201 | } |
Corentin Chary | 43be8bd | 2011-07-01 11:34:40 +0200 | [diff] [blame] | 3202 | if (asus->gps.rfkill) { |
| 3203 | bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_GPS); |
| 3204 | rfkill_set_sw_state(asus->gps.rfkill, bl); |
| 3205 | } |
Corentin Chary | a912d32 | 2011-07-01 11:34:41 +0200 | [diff] [blame] | 3206 | if (asus->uwb.rfkill) { |
| 3207 | bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_UWB); |
| 3208 | rfkill_set_sw_state(asus->uwb.rfkill, bl); |
| 3209 | } |
Oleksij Rempel | 3073404 | 2015-09-14 11:16:30 +0200 | [diff] [blame] | 3210 | if (!IS_ERR_OR_NULL(asus->kbd_led.dev)) |
Jian-Hong Pan | 9fe44fc | 2018-09-27 16:50:09 +0800 | [diff] [blame] | 3211 | kbd_led_update(asus); |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 3212 | |
Chris Chiu | 487579b | 2019-04-18 14:46:48 +0800 | [diff] [blame] | 3213 | if (asus_wmi_has_fnlock_key(asus)) |
| 3214 | asus_wmi_fnlock_update(asus); |
Samuel Čavoj | ea856ec | 2020-10-21 00:09:44 +0200 | [diff] [blame] | 3215 | |
| 3216 | if (asus->driver->quirks->use_lid_flip_devid) |
| 3217 | lid_flip_tablet_mode_get_state(asus); |
| 3218 | |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 3219 | return 0; |
| 3220 | } |
| 3221 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3222 | static const struct dev_pm_ops asus_pm_ops = { |
| 3223 | .thaw = asus_hotk_thaw, |
| 3224 | .restore = asus_hotk_restore, |
Oleksij Rempel | 3073404 | 2015-09-14 11:16:30 +0200 | [diff] [blame] | 3225 | .resume = asus_hotk_resume, |
Corentin Chary | 0773d7f | 2011-02-06 13:28:32 +0100 | [diff] [blame] | 3226 | }; |
| 3227 | |
Yurii Pavlovskyi | 54a3121 | 2019-05-14 21:04:48 +0200 | [diff] [blame] | 3228 | /* Registration ***************************************************************/ |
| 3229 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3230 | static int asus_wmi_probe(struct platform_device *pdev) |
Corentin Chary | d358cb5 | 2010-11-29 08:14:14 +0100 | [diff] [blame] | 3231 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3232 | struct platform_driver *pdrv = to_platform_driver(pdev->dev.driver); |
| 3233 | struct asus_wmi_driver *wdrv = to_asus_wmi_driver(pdrv); |
| 3234 | int ret; |
Corentin Chary | d358cb5 | 2010-11-29 08:14:14 +0100 | [diff] [blame] | 3235 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3236 | if (!wmi_has_guid(ASUS_WMI_MGMT_GUID)) { |
Hans de Goede | c994611 | 2019-01-21 14:24:36 +0100 | [diff] [blame] | 3237 | pr_warn("ASUS Management GUID not found\n"); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 3238 | return -ENODEV; |
| 3239 | } |
| 3240 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3241 | if (wdrv->event_guid && !wmi_has_guid(wdrv->event_guid)) { |
Hans de Goede | c994611 | 2019-01-21 14:24:36 +0100 | [diff] [blame] | 3242 | pr_warn("ASUS Event GUID not found\n"); |
Corentin Chary | d358cb5 | 2010-11-29 08:14:14 +0100 | [diff] [blame] | 3243 | return -ENODEV; |
| 3244 | } |
| 3245 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3246 | if (wdrv->probe) { |
| 3247 | ret = wdrv->probe(pdev); |
| 3248 | if (ret) |
| 3249 | return ret; |
| 3250 | } |
| 3251 | |
| 3252 | return asus_wmi_add(pdev); |
Corentin Chary | a04ce29 | 2011-02-06 13:28:33 +0100 | [diff] [blame] | 3253 | } |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 3254 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3255 | static bool used; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 3256 | |
Corentin Chary | 8fe8c25 | 2011-07-01 11:34:32 +0200 | [diff] [blame] | 3257 | 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] | 3258 | { |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3259 | struct platform_driver *platform_driver; |
| 3260 | struct platform_device *platform_device; |
| 3261 | |
| 3262 | if (used) |
| 3263 | return -EBUSY; |
| 3264 | |
| 3265 | platform_driver = &driver->platform_driver; |
| 3266 | platform_driver->remove = asus_wmi_remove; |
| 3267 | platform_driver->driver.owner = driver->owner; |
| 3268 | platform_driver->driver.name = driver->name; |
| 3269 | platform_driver->driver.pm = &asus_pm_ops; |
| 3270 | |
| 3271 | platform_device = platform_create_bundle(platform_driver, |
| 3272 | asus_wmi_probe, |
Corentin Chary | a04ce29 | 2011-02-06 13:28:33 +0100 | [diff] [blame] | 3273 | NULL, 0, NULL, 0); |
| 3274 | if (IS_ERR(platform_device)) |
| 3275 | return PTR_ERR(platform_device); |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3276 | |
| 3277 | used = true; |
| 3278 | return 0; |
| 3279 | } |
| 3280 | EXPORT_SYMBOL_GPL(asus_wmi_register_driver); |
| 3281 | |
| 3282 | void asus_wmi_unregister_driver(struct asus_wmi_driver *driver) |
| 3283 | { |
| 3284 | platform_device_unregister(driver->platform_device); |
| 3285 | platform_driver_unregister(&driver->platform_driver); |
| 3286 | used = false; |
| 3287 | } |
| 3288 | EXPORT_SYMBOL_GPL(asus_wmi_unregister_driver); |
| 3289 | |
| 3290 | static int __init asus_wmi_init(void) |
| 3291 | { |
vic | 0ed6065 | 2013-05-22 21:32:10 +0300 | [diff] [blame] | 3292 | pr_info("ASUS WMI generic driver loaded\n"); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 3293 | return 0; |
| 3294 | } |
| 3295 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3296 | static void __exit asus_wmi_exit(void) |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 3297 | { |
vic | 0ed6065 | 2013-05-22 21:32:10 +0300 | [diff] [blame] | 3298 | pr_info("ASUS WMI generic driver unloaded\n"); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 3299 | } |
| 3300 | |
Corentin Chary | e12e6d9 | 2011-02-26 10:20:31 +0100 | [diff] [blame] | 3301 | module_init(asus_wmi_init); |
| 3302 | module_exit(asus_wmi_exit); |