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