diff options
author | Luke D. Jones <luke@ljones.dev> | 2022-08-13 00:25:08 +0200 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2022-08-25 16:23:53 +0200 |
commit | 36450e7db0fe55c338f32059382a2d8342cbc9a1 (patch) | |
tree | a82cba5da9c04dfa01d282ceeabbc5e24e1146c0 /drivers/platform/x86/asus-wmi.c | |
parent | platform/x86: asus-wmi: Refactor disable_gpu attribute (diff) | |
download | linux-36450e7db0fe55c338f32059382a2d8342cbc9a1.tar.xz linux-36450e7db0fe55c338f32059382a2d8342cbc9a1.zip |
platform/x86: asus-wmi: Refactor egpu_enable attribute
The settings for these attributes can be read from the device, this
is now done instead of reading a stored value from module. The stored
value is also removed.
This means the simpler asus_wmi_dev_is_present() can be used in
*_check_present() - it is not an error for these methods to be
missing.
The _write() functions have their bodies shifted in to *_store()
which simplifies things further.
Signed-off-by: Luke D. Jones <luke@ljones.dev>
Link: https://lore.kernel.org/r/20220812222509.292692-6-luke@ljones.dev
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'drivers/platform/x86/asus-wmi.c')
-rw-r--r-- | drivers/platform/x86/asus-wmi.c | 84 |
1 files changed, 26 insertions, 58 deletions
diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index f58cbda862d2..c82e7b128444 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -229,9 +229,7 @@ struct asus_wmi { u8 fan_boost_mode_mask; u8 fan_boost_mode; - bool egpu_enable_available; // 0 = enable - bool egpu_enable; - + bool egpu_enable_available; bool dgpu_disable_available; bool throttle_thermal_policy_available; @@ -625,48 +623,10 @@ static DEVICE_ATTR_RW(dgpu_disable); /* eGPU ********************************************************************/ static int egpu_enable_check_present(struct asus_wmi *asus) { - u32 result; - int err; - asus->egpu_enable_available = false; - err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_EGPU, &result); - if (err) { - if (err == -ENODEV) - return 0; - return err; - } - - if (result & ASUS_WMI_DSTS_PRESENCE_BIT) { + if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_EGPU)) asus->egpu_enable_available = true; - asus->egpu_enable = result & ASUS_WMI_DSTS_STATUS_BIT; - } - - return 0; -} - -static int egpu_enable_write(struct asus_wmi *asus) -{ - u32 retval; - u8 value; - int err; - - /* Don't rely on type conversion */ - value = asus->egpu_enable ? 1 : 0; - - err = asus_wmi_set_devstate(ASUS_WMI_DEVID_EGPU, value, &retval); - - if (err) { - pr_warn("Failed to set egpu disable: %d\n", err); - return err; - } - - if (retval > 1) { - pr_warn("Failed to set egpu disable (retval): 0x%x\n", retval); - return -EIO; - } - - sysfs_notify(&asus->platform_device->dev.kobj, NULL, "egpu_enable"); return 0; } @@ -675,9 +635,13 @@ static ssize_t egpu_enable_show(struct device *dev, struct device_attribute *attr, char *buf) { struct asus_wmi *asus = dev_get_drvdata(dev); - bool mode = asus->egpu_enable; + int result; - return sysfs_emit(buf, "%d\n", mode); + result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_EGPU); + if (result < 0) + return result; + + return sysfs_emit(buf, "%d\n", result); } /* The ACPI call to enable the eGPU also disables the internal dGPU */ @@ -685,29 +649,33 @@ static ssize_t egpu_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - bool enable; - int result; + int result, err; + u32 enable; struct asus_wmi *asus = dev_get_drvdata(dev); - result = kstrtobool(buf, &enable); - if (result) - return result; + err = kstrtou32(buf, 10, &enable); + if (err) + return err; - asus->egpu_enable = enable; + if (enable > 1) + return -EINVAL; - result = egpu_enable_write(asus); - if (result) - return result; + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_EGPU, enable, &result); + if (err) { + pr_warn("Failed to set egpu disable: %d\n", err); + return err; + } - /* Ensure that the kernel status of dgpu is updated */ - result = dgpu_disable_check_present(asus); - if (result) - return result; + if (result > 1) { + pr_warn("Failed to set egpu disable (retval): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "egpu_enable"); return count; } - static DEVICE_ATTR_RW(egpu_enable); /* Battery ********************************************************************/ |