asus-wmi.c (79bd127f9662ead1ceea7970ef36fbe985a6d7ab) asus-wmi.c (f81d13df1aa8b02fa8c6ac4b396dcda92fdfdac0)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Asus PC WMI hotkey driver
4 *
5 * Copyright(C) 2010 Intel Corporation.
6 * Copyright(C) 2010-2011 Corentin Chary <corentin.chary@gmail.com>
7 *
8 * Portions based on wistron_btns.c:

--- 112 unchanged lines hidden (view full) ---

121#define NVIDIA_BOOST_MAX 25
122#define NVIDIA_TEMP_MIN 75
123#define NVIDIA_TEMP_MAX 87
124
125#define ASUS_SCREENPAD_BRIGHT_MIN 20
126#define ASUS_SCREENPAD_BRIGHT_MAX 255
127#define ASUS_SCREENPAD_BRIGHT_DEFAULT 60
128
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Asus PC WMI hotkey driver
4 *
5 * Copyright(C) 2010 Intel Corporation.
6 * Copyright(C) 2010-2011 Corentin Chary <corentin.chary@gmail.com>
7 *
8 * Portions based on wistron_btns.c:

--- 112 unchanged lines hidden (view full) ---

121#define NVIDIA_BOOST_MAX 25
122#define NVIDIA_TEMP_MIN 75
123#define NVIDIA_TEMP_MAX 87
124
125#define ASUS_SCREENPAD_BRIGHT_MIN 20
126#define ASUS_SCREENPAD_BRIGHT_MAX 255
127#define ASUS_SCREENPAD_BRIGHT_DEFAULT 60
128
129#define ASUS_MINI_LED_MODE_MASK 0x03
130/* Standard modes for devices with only on/off */
131#define ASUS_MINI_LED_OFF 0x00
132#define ASUS_MINI_LED_ON 0x01
133/* New mode on some devices, define here to clarify remapping later */
134#define ASUS_MINI_LED_STRONG_MODE 0x02
135/* New modes for devices with 3 mini-led mode types */
136#define ASUS_MINI_LED_2024_WEAK 0x00
137#define ASUS_MINI_LED_2024_STRONG 0x01
138#define ASUS_MINI_LED_2024_OFF 0x02
139
129/* Controls the power state of the USB0 hub on ROG Ally which input is on */
130#define ASUS_USB0_PWR_EC0_CSEE "\\_SB.PCI0.SBRG.EC0.CSEE"
131/* 300ms so far seems to produce a reliable result on AC and battery */
132#define ASUS_USB0_PWR_EC0_CSEE_WAIT 300
133
134static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL };
135
136static int throttle_thermal_policy_write(struct asus_wmi *);

--- 146 unchanged lines hidden (view full) ---

283
284 struct platform_profile_handler platform_profile_handler;
285 bool platform_profile_support;
286
287 // The RSOC controls the maximum charging percentage.
288 bool battery_rsoc_available;
289
290 bool panel_overdrive_available;
140/* Controls the power state of the USB0 hub on ROG Ally which input is on */
141#define ASUS_USB0_PWR_EC0_CSEE "\\_SB.PCI0.SBRG.EC0.CSEE"
142/* 300ms so far seems to produce a reliable result on AC and battery */
143#define ASUS_USB0_PWR_EC0_CSEE_WAIT 300
144
145static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL };
146
147static int throttle_thermal_policy_write(struct asus_wmi *);

--- 146 unchanged lines hidden (view full) ---

294
295 struct platform_profile_handler platform_profile_handler;
296 bool platform_profile_support;
297
298 // The RSOC controls the maximum charging percentage.
299 bool battery_rsoc_available;
300
301 bool panel_overdrive_available;
291 bool mini_led_mode_available;
302 u32 mini_led_dev_id;
292
293 struct hotplug_slot hotplug_slot;
294 struct mutex hotplug_lock;
295 struct mutex wmi_lock;
296 struct workqueue_struct *hotplug_workqueue;
297 struct work_struct hotplug_work;
298
299 bool fnlock_locked;

--- 1803 unchanged lines hidden (view full) ---

2103}
2104static DEVICE_ATTR_RW(panel_od);
2105
2106/* Mini-LED mode **************************************************************/
2107static ssize_t mini_led_mode_show(struct device *dev,
2108 struct device_attribute *attr, char *buf)
2109{
2110 struct asus_wmi *asus = dev_get_drvdata(dev);
303
304 struct hotplug_slot hotplug_slot;
305 struct mutex hotplug_lock;
306 struct mutex wmi_lock;
307 struct workqueue_struct *hotplug_workqueue;
308 struct work_struct hotplug_work;
309
310 bool fnlock_locked;

--- 1803 unchanged lines hidden (view full) ---

2114}
2115static DEVICE_ATTR_RW(panel_od);
2116
2117/* Mini-LED mode **************************************************************/
2118static ssize_t mini_led_mode_show(struct device *dev,
2119 struct device_attribute *attr, char *buf)
2120{
2121 struct asus_wmi *asus = dev_get_drvdata(dev);
2111 int result;
2122 u32 value;
2123 int err;
2112
2124
2113 result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_MINI_LED_MODE);
2114 if (result < 0)
2115 return result;
2125 err = asus_wmi_get_devstate(asus, asus->mini_led_dev_id, &value);
2126 if (err < 0)
2127 return err;
2128 value = value & ASUS_MINI_LED_MODE_MASK;
2116
2129
2117 return sysfs_emit(buf, "%d\n", result);
2130 /*
2131 * Remap the mode values to match previous generation mini-led. The last gen
2132 * WMI 0 == off, while on this version WMI 2 ==off (flipped).
2133 */
2134 if (asus->mini_led_dev_id == ASUS_WMI_DEVID_MINI_LED_MODE2) {
2135 switch (value) {
2136 case ASUS_MINI_LED_2024_WEAK:
2137 value = ASUS_MINI_LED_ON;
2138 break;
2139 case ASUS_MINI_LED_2024_STRONG:
2140 value = ASUS_MINI_LED_STRONG_MODE;
2141 break;
2142 case ASUS_MINI_LED_2024_OFF:
2143 value = ASUS_MINI_LED_OFF;
2144 break;
2145 }
2146 }
2147
2148 return sysfs_emit(buf, "%d\n", value);
2118}
2119
2120static ssize_t mini_led_mode_store(struct device *dev,
2121 struct device_attribute *attr,
2122 const char *buf, size_t count)
2123{
2124 int result, err;
2125 u32 mode;
2126
2127 struct asus_wmi *asus = dev_get_drvdata(dev);
2128
2129 result = kstrtou32(buf, 10, &mode);
2130 if (result)
2131 return result;
2132
2149}
2150
2151static ssize_t mini_led_mode_store(struct device *dev,
2152 struct device_attribute *attr,
2153 const char *buf, size_t count)
2154{
2155 int result, err;
2156 u32 mode;
2157
2158 struct asus_wmi *asus = dev_get_drvdata(dev);
2159
2160 result = kstrtou32(buf, 10, &mode);
2161 if (result)
2162 return result;
2163
2133 if (mode > 1)
2164 if (asus->mini_led_dev_id == ASUS_WMI_DEVID_MINI_LED_MODE &&
2165 mode > ASUS_MINI_LED_ON)
2134 return -EINVAL;
2166 return -EINVAL;
2167 if (asus->mini_led_dev_id == ASUS_WMI_DEVID_MINI_LED_MODE2 &&
2168 mode > ASUS_MINI_LED_STRONG_MODE)
2169 return -EINVAL;
2135
2170
2136 err = asus_wmi_set_devstate(ASUS_WMI_DEVID_MINI_LED_MODE, mode, &result);
2171 /*
2172 * Remap the mode values so expected behaviour is the same as the last
2173 * generation of mini-LED with 0 == off, 1 == on.
2174 */
2175 if (asus->mini_led_dev_id == ASUS_WMI_DEVID_MINI_LED_MODE2) {
2176 switch (mode) {
2177 case ASUS_MINI_LED_OFF:
2178 mode = ASUS_MINI_LED_2024_OFF;
2179 break;
2180 case ASUS_MINI_LED_ON:
2181 mode = ASUS_MINI_LED_2024_WEAK;
2182 break;
2183 case ASUS_MINI_LED_STRONG_MODE:
2184 mode = ASUS_MINI_LED_2024_STRONG;
2185 break;
2186 }
2187 }
2137
2188
2189 err = asus_wmi_set_devstate(asus->mini_led_dev_id, mode, &result);
2138 if (err) {
2139 pr_warn("Failed to set mini-LED: %d\n", err);
2140 return err;
2141 }
2142
2143 if (result > 1) {
2144 pr_warn("Failed to set mini-LED mode (result): 0x%x\n", result);
2145 return -EIO;
2146 }
2147
2148 sysfs_notify(&asus->platform_device->dev.kobj, NULL, "mini_led_mode");
2149
2150 return count;
2151}
2152static DEVICE_ATTR_RW(mini_led_mode);
2153
2190 if (err) {
2191 pr_warn("Failed to set mini-LED: %d\n", err);
2192 return err;
2193 }
2194
2195 if (result > 1) {
2196 pr_warn("Failed to set mini-LED mode (result): 0x%x\n", result);
2197 return -EIO;
2198 }
2199
2200 sysfs_notify(&asus->platform_device->dev.kobj, NULL, "mini_led_mode");
2201
2202 return count;
2203}
2204static DEVICE_ATTR_RW(mini_led_mode);
2205
2206static ssize_t available_mini_led_mode_show(struct device *dev,
2207 struct device_attribute *attr, char *buf)
2208{
2209 struct asus_wmi *asus = dev_get_drvdata(dev);
2210
2211 switch (asus->mini_led_dev_id) {
2212 case ASUS_WMI_DEVID_MINI_LED_MODE:
2213 return sysfs_emit(buf, "0 1\n");
2214 case ASUS_WMI_DEVID_MINI_LED_MODE2:
2215 return sysfs_emit(buf, "0 1 2\n");
2216 }
2217
2218 return sysfs_emit(buf, "0\n");
2219}
2220
2221static DEVICE_ATTR_RO(available_mini_led_mode);
2222
2154/* Quirks *********************************************************************/
2155
2156static void asus_wmi_set_xusb2pr(struct asus_wmi *asus)
2157{
2158 struct pci_dev *xhci_pdev;
2159 u32 orig_ports_available;
2160 u32 ports_available = asus->driver->quirks->xusb2pr;
2161

--- 1972 unchanged lines hidden (view full) ---

4134 &dev_attr_ppt_pl1_spl.attr,
4135 &dev_attr_ppt_fppt.attr,
4136 &dev_attr_ppt_apu_sppt.attr,
4137 &dev_attr_ppt_platform_sppt.attr,
4138 &dev_attr_nv_dynamic_boost.attr,
4139 &dev_attr_nv_temp_target.attr,
4140 &dev_attr_panel_od.attr,
4141 &dev_attr_mini_led_mode.attr,
2223/* Quirks *********************************************************************/
2224
2225static void asus_wmi_set_xusb2pr(struct asus_wmi *asus)
2226{
2227 struct pci_dev *xhci_pdev;
2228 u32 orig_ports_available;
2229 u32 ports_available = asus->driver->quirks->xusb2pr;
2230

--- 1972 unchanged lines hidden (view full) ---

4203 &dev_attr_ppt_pl1_spl.attr,
4204 &dev_attr_ppt_fppt.attr,
4205 &dev_attr_ppt_apu_sppt.attr,
4206 &dev_attr_ppt_platform_sppt.attr,
4207 &dev_attr_nv_dynamic_boost.attr,
4208 &dev_attr_nv_temp_target.attr,
4209 &dev_attr_panel_od.attr,
4210 &dev_attr_mini_led_mode.attr,
4211 &dev_attr_available_mini_led_mode.attr,
4142 NULL
4143};
4144
4145static umode_t asus_sysfs_is_visible(struct kobject *kobj,
4146 struct attribute *attr, int idx)
4147{
4148 struct device *dev = kobj_to_dev(kobj);
4149 struct asus_wmi *asus = dev_get_drvdata(dev);

--- 36 unchanged lines hidden (view full) ---

4186 ok = asus->ppt_plat_sppt_available;
4187 else if (attr == &dev_attr_nv_dynamic_boost.attr)
4188 ok = asus->nv_dyn_boost_available;
4189 else if (attr == &dev_attr_nv_temp_target.attr)
4190 ok = asus->nv_temp_tgt_available;
4191 else if (attr == &dev_attr_panel_od.attr)
4192 ok = asus->panel_overdrive_available;
4193 else if (attr == &dev_attr_mini_led_mode.attr)
4212 NULL
4213};
4214
4215static umode_t asus_sysfs_is_visible(struct kobject *kobj,
4216 struct attribute *attr, int idx)
4217{
4218 struct device *dev = kobj_to_dev(kobj);
4219 struct asus_wmi *asus = dev_get_drvdata(dev);

--- 36 unchanged lines hidden (view full) ---

4256 ok = asus->ppt_plat_sppt_available;
4257 else if (attr == &dev_attr_nv_dynamic_boost.attr)
4258 ok = asus->nv_dyn_boost_available;
4259 else if (attr == &dev_attr_nv_temp_target.attr)
4260 ok = asus->nv_temp_tgt_available;
4261 else if (attr == &dev_attr_panel_od.attr)
4262 ok = asus->panel_overdrive_available;
4263 else if (attr == &dev_attr_mini_led_mode.attr)
4194 ok = asus->mini_led_mode_available;
4264 ok = asus->mini_led_dev_id != 0;
4265 else if (attr == &dev_attr_available_mini_led_mode.attr)
4266 ok = asus->mini_led_dev_id != 0;
4195
4196 if (devid != -1)
4197 ok = !(asus_wmi_get_devstate_simple(asus, devid) < 0);
4198
4199 return ok ? attr->mode : 0;
4200}
4201
4202static const struct attribute_group platform_attribute_group = {

--- 236 unchanged lines hidden (view full) ---

4439 asus->ppt_pl2_sppt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_PL2_SPPT);
4440 asus->ppt_pl1_spl_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_PL1_SPL);
4441 asus->ppt_fppt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_FPPT);
4442 asus->ppt_apu_sppt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_APU_SPPT);
4443 asus->ppt_plat_sppt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_PLAT_SPPT);
4444 asus->nv_dyn_boost_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_NV_DYN_BOOST);
4445 asus->nv_temp_tgt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_NV_THERM_TARGET);
4446 asus->panel_overdrive_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PANEL_OD);
4267
4268 if (devid != -1)
4269 ok = !(asus_wmi_get_devstate_simple(asus, devid) < 0);
4270
4271 return ok ? attr->mode : 0;
4272}
4273
4274static const struct attribute_group platform_attribute_group = {

--- 236 unchanged lines hidden (view full) ---

4511 asus->ppt_pl2_sppt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_PL2_SPPT);
4512 asus->ppt_pl1_spl_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_PL1_SPL);
4513 asus->ppt_fppt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_FPPT);
4514 asus->ppt_apu_sppt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_APU_SPPT);
4515 asus->ppt_plat_sppt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_PLAT_SPPT);
4516 asus->nv_dyn_boost_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_NV_DYN_BOOST);
4517 asus->nv_temp_tgt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_NV_THERM_TARGET);
4518 asus->panel_overdrive_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PANEL_OD);
4447 asus->mini_led_mode_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_MINI_LED_MODE);
4448 asus->ally_mcu_usb_switch = acpi_has_method(NULL, ASUS_USB0_PWR_EC0_CSEE)
4449 && dmi_match(DMI_BOARD_NAME, "RC71L");
4450
4519 asus->ally_mcu_usb_switch = acpi_has_method(NULL, ASUS_USB0_PWR_EC0_CSEE)
4520 && dmi_match(DMI_BOARD_NAME, "RC71L");
4521
4522 if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_MINI_LED_MODE))
4523 asus->mini_led_dev_id = ASUS_WMI_DEVID_MINI_LED_MODE;
4524 else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_MINI_LED_MODE2))
4525 asus->mini_led_dev_id = ASUS_WMI_DEVID_MINI_LED_MODE2;
4526
4451 err = fan_boost_mode_check_present(asus);
4452 if (err)
4453 goto fail_fan_boost_mode;
4454
4455 err = throttle_thermal_policy_check_present(asus);
4456 if (err)
4457 goto fail_throttle_thermal_policy;
4458 else

--- 327 unchanged lines hidden ---
4527 err = fan_boost_mode_check_present(asus);
4528 if (err)
4529 goto fail_fan_boost_mode;
4530
4531 err = throttle_thermal_policy_check_present(asus);
4532 if (err)
4533 goto fail_throttle_thermal_policy;
4534 else

--- 327 unchanged lines hidden ---