Commit 98829e84 authored by Luke D. Jones's avatar Luke D. Jones Committed by Hans de Goede

asus-wmi: Add dgpu disable method

In Windows the ASUS Armory Crate program can enable or disable the
dGPU via a WMI call. This functions much the same as various Linux
methods in software where the dGPU is removed from the device tree.

However the WMI call saves the state of dGPU (enabled or not) and
this then changes the dGPU visibility in Linux with no way for
Linux users to re-enable it. We expose the WMI method so users can
see and change the dGPU ACPI state.
Signed-off-by: default avatarLuke D. Jones <luke@ljones.dev>
Link: https://lore.kernel.org/r/20210807023656.25020-3-luke@ljones.devReviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent ca91ea34
...@@ -210,6 +210,9 @@ struct asus_wmi { ...@@ -210,6 +210,9 @@ struct asus_wmi {
u8 fan_boost_mode_mask; u8 fan_boost_mode_mask;
u8 fan_boost_mode; u8 fan_boost_mode;
bool dgpu_disable_available;
bool dgpu_disable;
bool throttle_thermal_policy_available; bool throttle_thermal_policy_available;
u8 throttle_thermal_policy_mode; u8 throttle_thermal_policy_mode;
...@@ -427,6 +430,93 @@ static void lid_flip_tablet_mode_get_state(struct asus_wmi *asus) ...@@ -427,6 +430,93 @@ static void lid_flip_tablet_mode_get_state(struct asus_wmi *asus)
} }
} }
/* dGPU ********************************************************************/
static int dgpu_disable_check_present(struct asus_wmi *asus)
{
u32 result;
int err;
asus->dgpu_disable_available = false;
err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_DGPU, &result);
if (err) {
if (err == -ENODEV)
return 0;
return err;
}
if (result & ASUS_WMI_DSTS_PRESENCE_BIT) {
asus->dgpu_disable_available = true;
asus->dgpu_disable = result & ASUS_WMI_DSTS_STATUS_BIT;
}
return 0;
}
static int dgpu_disable_write(struct asus_wmi *asus)
{
u32 retval;
u8 value;
int err;
/* Don't rely on type conversion */
value = asus->dgpu_disable ? 1 : 0;
err = asus_wmi_set_devstate(ASUS_WMI_DEVID_DGPU, value, &retval);
if (err) {
pr_warn("Failed to set dgpu disable: %d\n", err);
return err;
}
if (retval > 1 || retval < 0) {
pr_warn("Failed to set dgpu disable (retval): 0x%x\n", retval);
return -EIO;
}
sysfs_notify(&asus->platform_device->dev.kobj, NULL, "dgpu_disable");
return 0;
}
static ssize_t dgpu_disable_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct asus_wmi *asus = dev_get_drvdata(dev);
u8 mode = asus->dgpu_disable;
return sysfs_emit(buf, "%d\n", mode);
}
/*
* A user may be required to store the value twice, typcial store first, then
* rescan PCI bus to activate power, then store a second time to save correctly.
* The reason for this is that an extra code path in the ACPI is enabled when
* the device and bus are powered.
*/
static ssize_t dgpu_disable_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
bool disable;
int result;
struct asus_wmi *asus = dev_get_drvdata(dev);
result = kstrtobool(buf, &disable);
if (result)
return result;
asus->dgpu_disable = disable;
result = dgpu_disable_write(asus);
if (result)
return result;
return count;
}
static DEVICE_ATTR_RW(dgpu_disable);
/* Battery ********************************************************************/ /* Battery ********************************************************************/
/* The battery maximum charging percentage */ /* The battery maximum charging percentage */
...@@ -2412,6 +2502,7 @@ static struct attribute *platform_attributes[] = { ...@@ -2412,6 +2502,7 @@ static struct attribute *platform_attributes[] = {
&dev_attr_camera.attr, &dev_attr_camera.attr,
&dev_attr_cardr.attr, &dev_attr_cardr.attr,
&dev_attr_touchpad.attr, &dev_attr_touchpad.attr,
&dev_attr_dgpu_disable.attr,
&dev_attr_lid_resume.attr, &dev_attr_lid_resume.attr,
&dev_attr_als_enable.attr, &dev_attr_als_enable.attr,
&dev_attr_fan_boost_mode.attr, &dev_attr_fan_boost_mode.attr,
...@@ -2438,6 +2529,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, ...@@ -2438,6 +2529,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj,
devid = ASUS_WMI_DEVID_LID_RESUME; devid = ASUS_WMI_DEVID_LID_RESUME;
else if (attr == &dev_attr_als_enable.attr) else if (attr == &dev_attr_als_enable.attr)
devid = ASUS_WMI_DEVID_ALS_ENABLE; devid = ASUS_WMI_DEVID_ALS_ENABLE;
else if (attr == &dev_attr_dgpu_disable.attr)
ok = asus->dgpu_disable_available;
else if (attr == &dev_attr_fan_boost_mode.attr) else if (attr == &dev_attr_fan_boost_mode.attr)
ok = asus->fan_boost_mode_available; ok = asus->fan_boost_mode_available;
else if (attr == &dev_attr_throttle_thermal_policy.attr) else if (attr == &dev_attr_throttle_thermal_policy.attr)
...@@ -2699,6 +2792,10 @@ static int asus_wmi_add(struct platform_device *pdev) ...@@ -2699,6 +2792,10 @@ static int asus_wmi_add(struct platform_device *pdev)
if (err) if (err)
goto fail_platform; goto fail_platform;
err = dgpu_disable_check_present(asus);
if (err)
goto fail_dgpu_disable;
err = fan_boost_mode_check_present(asus); err = fan_boost_mode_check_present(asus);
if (err) if (err)
goto fail_fan_boost_mode; goto fail_fan_boost_mode;
...@@ -2799,6 +2896,7 @@ static int asus_wmi_add(struct platform_device *pdev) ...@@ -2799,6 +2896,7 @@ static int asus_wmi_add(struct platform_device *pdev)
fail_sysfs: fail_sysfs:
fail_throttle_thermal_policy: fail_throttle_thermal_policy:
fail_fan_boost_mode: fail_fan_boost_mode:
fail_dgpu_disable:
fail_platform: fail_platform:
fail_panel_od: fail_panel_od:
kfree(asus); kfree(asus);
......
...@@ -90,6 +90,9 @@ ...@@ -90,6 +90,9 @@
/* Keyboard dock */ /* Keyboard dock */
#define ASUS_WMI_DEVID_KBD_DOCK 0x00120063 #define ASUS_WMI_DEVID_KBD_DOCK 0x00120063
/* dgpu on/off */
#define ASUS_WMI_DEVID_DGPU 0x00090020
/* DSTS masks */ /* DSTS masks */
#define ASUS_WMI_DSTS_STATUS_BIT 0x00000001 #define ASUS_WMI_DSTS_STATUS_BIT 0x00000001
#define ASUS_WMI_DSTS_UNKNOWN_BIT 0x00000002 #define ASUS_WMI_DSTS_UNKNOWN_BIT 0x00000002
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment