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>
This commit is contained in:
parent
cdf36fc865
commit
36450e7db0
|
@ -229,9 +229,7 @@ struct asus_wmi {
|
||||||
u8 fan_boost_mode_mask;
|
u8 fan_boost_mode_mask;
|
||||||
u8 fan_boost_mode;
|
u8 fan_boost_mode;
|
||||||
|
|
||||||
bool egpu_enable_available; // 0 = enable
|
bool egpu_enable_available;
|
||||||
bool egpu_enable;
|
|
||||||
|
|
||||||
bool dgpu_disable_available;
|
bool dgpu_disable_available;
|
||||||
|
|
||||||
bool throttle_thermal_policy_available;
|
bool throttle_thermal_policy_available;
|
||||||
|
@ -625,48 +623,10 @@ static DEVICE_ATTR_RW(dgpu_disable);
|
||||||
/* eGPU ********************************************************************/
|
/* eGPU ********************************************************************/
|
||||||
static int egpu_enable_check_present(struct asus_wmi *asus)
|
static int egpu_enable_check_present(struct asus_wmi *asus)
|
||||||
{
|
{
|
||||||
u32 result;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
asus->egpu_enable_available = false;
|
asus->egpu_enable_available = false;
|
||||||
|
|
||||||
err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_EGPU, &result);
|
if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_EGPU))
|
||||||
if (err) {
|
|
||||||
if (err == -ENODEV)
|
|
||||||
return 0;
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result & ASUS_WMI_DSTS_PRESENCE_BIT) {
|
|
||||||
asus->egpu_enable_available = true;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -675,9 +635,13 @@ static ssize_t egpu_enable_show(struct device *dev,
|
||||||
struct device_attribute *attr, char *buf)
|
struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
struct asus_wmi *asus = dev_get_drvdata(dev);
|
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 */
|
/* 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,
|
struct device_attribute *attr,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
bool enable;
|
int result, err;
|
||||||
int result;
|
u32 enable;
|
||||||
|
|
||||||
struct asus_wmi *asus = dev_get_drvdata(dev);
|
struct asus_wmi *asus = dev_get_drvdata(dev);
|
||||||
|
|
||||||
result = kstrtobool(buf, &enable);
|
err = kstrtou32(buf, 10, &enable);
|
||||||
if (result)
|
if (err)
|
||||||
return result;
|
return err;
|
||||||
|
|
||||||
asus->egpu_enable = enable;
|
if (enable > 1)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
result = egpu_enable_write(asus);
|
err = asus_wmi_set_devstate(ASUS_WMI_DEVID_EGPU, enable, &result);
|
||||||
if (result)
|
if (err) {
|
||||||
return result;
|
pr_warn("Failed to set egpu disable: %d\n", err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
/* Ensure that the kernel status of dgpu is updated */
|
if (result > 1) {
|
||||||
result = dgpu_disable_check_present(asus);
|
pr_warn("Failed to set egpu disable (retval): 0x%x\n", result);
|
||||||
if (result)
|
return -EIO;
|
||||||
return result;
|
}
|
||||||
|
|
||||||
|
sysfs_notify(&asus->platform_device->dev.kobj, NULL, "egpu_enable");
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DEVICE_ATTR_RW(egpu_enable);
|
static DEVICE_ATTR_RW(egpu_enable);
|
||||||
|
|
||||||
/* Battery ********************************************************************/
|
/* Battery ********************************************************************/
|
||||||
|
|
Loading…
Reference in New Issue