2022-08-12 22:59:45

by Luke Jones

[permalink] [raw]
Subject: [PATCH 0/6] asus-wmi: cleanup dgpu_disable, egpu_enable, panel_od

This patch series does two things for previously added features:
- dgpu_disable
- egpu_enable
- panel_od

The fixes add missing documentation, and the refactors vastly clean up how
the features work, including reading the values from WMI methods on *_show()
and checking the result correctly (these methods return 1 on success).

Luke D. Jones (6):
Fixes 98829e84dc67 ("asus-wmi: Add dgpu disable method")
Fixes: 382b91db8044 ("asus-wmi: Add egpu enable method")
Fixes: ca91ea34778f ("asus-wmi: Add panel overdrive functionality")
asus-wmi: Refactor disable_gpu attribute
asus-wmi: Refactor egpu_enable attribute
asus-wmi: Refactor panel_od attribute

.../ABI/testing/sysfs-platform-asus-wmi | 28 +++
drivers/platform/x86/asus-wmi.c | 231 ++++++------------
2 files changed, 103 insertions(+), 156 deletions(-)

--
2.37.1


2022-08-12 22:59:59

by Luke Jones

[permalink] [raw]
Subject: [PATCH 6/6] asus-wmi: Refactor panel_od 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 <[email protected]>
---
drivers/platform/x86/asus-wmi.c | 74 +++++++++++----------------------
1 file changed, 25 insertions(+), 49 deletions(-)

diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index 87b042fac1ce..b2595a2d1b0a 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -245,7 +245,6 @@ struct asus_wmi {
bool battery_rsoc_available;

bool panel_overdrive_available;
- bool panel_overdrive;

struct hotplug_slot hotplug_slot;
struct mutex hotplug_lock;
@@ -1475,48 +1474,10 @@ static int asus_wmi_rfkill_init(struct asus_wmi *asus)
/* Panel Overdrive ************************************************************/
static int panel_od_check_present(struct asus_wmi *asus)
{
- u32 result;
- int err;
-
asus->panel_overdrive_available = false;

- err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_PANEL_OD, &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_PANEL_OD))
asus->panel_overdrive_available = true;
- asus->panel_overdrive = result & ASUS_WMI_DSTS_STATUS_BIT;
- }
-
- return 0;
-}
-
-static int panel_od_write(struct asus_wmi *asus)
-{
- u32 retval;
- u8 value;
- int err;
-
- /* Don't rely on type conversion */
- value = asus->panel_overdrive ? 1 : 0;
-
- err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PANEL_OD, value, &retval);
-
- if (err) {
- pr_warn("Failed to set panel overdrive: %d\n", err);
- return err;
- }
-
- if (retval > 1) {
- pr_warn("Failed to set panel overdrive (retval): 0x%x\n", retval);
- return -EIO;
- }
-
- sysfs_notify(&asus->platform_device->dev.kobj, NULL, "panel_od");

return 0;
}
@@ -1525,32 +1486,47 @@ static ssize_t panel_od_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct asus_wmi *asus = dev_get_drvdata(dev);
+ int result;

- return sysfs_emit(buf, "%d\n", asus->panel_overdrive);
+ result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_PANEL_OD);
+ if (result < 0)
+ return result;
+
+ return sysfs_emit(buf, "%d\n", result);
}

static ssize_t panel_od_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
- bool overdrive;
- int result;
+ int result, err;
+ u32 overdrive;

struct asus_wmi *asus = dev_get_drvdata(dev);

- result = kstrtobool(buf, &overdrive);
+ result = kstrtou32(buf, 10, &overdrive);
if (result)
return result;

- asus->panel_overdrive = overdrive;
- result = panel_od_write(asus);
+ if (overdrive > 1)
+ return -EINVAL;

- if (result)
- return result;
+ err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PANEL_OD, overdrive, &result);
+
+ if (err) {
+ pr_warn("Failed to set panel overdrive: %d\n", err);
+ return err;
+ }
+
+ if (result > 1) {
+ pr_warn("Failed to set panel overdrive (result): 0x%x\n", result);
+ return -EIO;
+ }
+
+ sysfs_notify(&asus->platform_device->dev.kobj, NULL, "panel_od");

return count;
}
-
static DEVICE_ATTR_RW(panel_od);

/* Quirks *********************************************************************/
--
2.37.1

2022-08-12 23:00:01

by Luke Jones

[permalink] [raw]
Subject: [PATCH 5/6] 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 <[email protected]>
---
drivers/platform/x86/asus-wmi.c | 84 ++++++++++-----------------------
1 file changed, 26 insertions(+), 58 deletions(-)

diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index a72ecc4e33b7..87b042fac1ce 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -228,9 +228,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;
@@ -624,48 +622,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;
}
@@ -674,9 +634,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;
+
+ result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_EGPU);
+ if (result < 0)
+ return result;

- return sysfs_emit(buf, "%d\n", mode);
+ return sysfs_emit(buf, "%d\n", result);
}

/* The ACPI call to enable the eGPU also disables the internal dGPU */
@@ -684,29 +648,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 ********************************************************************/
--
2.37.1

2022-08-15 15:13:14

by Hans de Goede

[permalink] [raw]
Subject: Re: [PATCH 0/6] asus-wmi: cleanup dgpu_disable, egpu_enable, panel_od

Hi,

On 8/13/22 00:25, Luke D. Jones wrote:
> This patch series does two things for previously added features:
> - dgpu_disable
> - egpu_enable
> - panel_od
>
> The fixes add missing documentation, and the refactors vastly clean up how
> the features work, including reading the values from WMI methods on *_show()
> and checking the result correctly (these methods return 1 on success).

Thank you for your patch-series, I've applied the series to my
review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my
local branch there, which might take a while.

Once I've run some tests on this branch the patches there will be
added to the platform-drivers-x86/for-next branch and eventually
will be included in the pdx86 pull-request to Linus for the next
merge-window.

Regards,

Hans


>
> Luke D. Jones (6):
> Fixes 98829e84dc67 ("asus-wmi: Add dgpu disable method")
> Fixes: 382b91db8044 ("asus-wmi: Add egpu enable method")
> Fixes: ca91ea34778f ("asus-wmi: Add panel overdrive functionality")
> asus-wmi: Refactor disable_gpu attribute
> asus-wmi: Refactor egpu_enable attribute
> asus-wmi: Refactor panel_od attribute
>
> .../ABI/testing/sysfs-platform-asus-wmi | 28 +++
> drivers/platform/x86/asus-wmi.c | 231 ++++++------------
> 2 files changed, 103 insertions(+), 156 deletions(-)
>