Skip to contentSkip to conversation

asus-wmi: Expand support of GPU fan to read RPM and label

PATCH In review Luke D. Jones 3 participants 4 messages Sep 16, 2022 – Sep 20, 2022

Subsystems (3)
lore
Share & tools
lore

Luke D. Jones

author maintainer
#0 lore raw

PATCH 1/1 asus-wmi: Expand support of GPU fan to read RPM and label

The previously added patch to add support for pwm change for TUF laptops also is usuable for more than TUF. The same method 0x00110014 is used to read the fan RPM.

Add two extra attributes for reading fan2 plus fan2 label.

---
 drivers/platform/x86/asus-wmi.c | 36 +++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)
drivers/platform/x86/asus-wmi.c +34 -2
index ae46af731de9..7fe6ce25da0a 100644
@@ -72,6 +72,7 @@ module_param(fnlock_default, bool, 0444);
 
 #define ASUS_WMI_FNLOCK_BIOS_DISABLED	BIT(0)
 
+#define ASUS_GPU_FAN_DESC		"gpu_fan"
 #define ASUS_FAN_DESC			"cpu_fan"
 #define ASUS_FAN_MFUN			0x13
 #define ASUS_FAN_SFUN_READ		0x06
@@ -2078,6 +2079,30 @@ static ssize_t asus_hwmon_temp1(struct device *dev,
 }
 
 /* GPU fan on modern ROG laptops */
+static ssize_t fan2_input_show(struct device *dev,
+					struct device_attribute *attr,
+					char *buf)
+{
+	struct asus_wmi *asus = dev_get_drvdata(dev);
+	int value;
+	int ret;
+
+	ret = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_GPU_FAN_CTRL, &value);
+	if (ret < 0)
+		return ret;
+
+	value &= 0xffff;
+
+	return sysfs_emit(buf, "%d\n", value < 0 ? -1 : value * 100);
+}
+
+static ssize_t fan2_label_show(struct device *dev,
+					  struct device_attribute *attr,
+					  char *buf)
+{
+	return sprintf(buf, "%s\n", ASUS_GPU_FAN_DESC);
+}
+
 static ssize_t pwm2_enable_show(struct device *dev,
 				struct device_attribute *attr,
 				char *buf)
@@ -2127,9 +2152,12 @@ static ssize_t pwm2_enable_store(struct device *dev,
 /* Fan1 */
 static DEVICE_ATTR_RW(pwm1);
 static DEVICE_ATTR_RW(pwm1_enable);
-static DEVICE_ATTR_RW(pwm2_enable);
 static DEVICE_ATTR_RO(fan1_input);
 static DEVICE_ATTR_RO(fan1_label);
+/* Fan2 - GPU fan */
+static DEVICE_ATTR_RW(pwm2_enable);
+static DEVICE_ATTR_RO(fan2_input);
+static DEVICE_ATTR_RO(fan2_label);
 
 /* Temperature */
 static DEVICE_ATTR(temp1_input, S_IRUGO, asus_hwmon_temp1, NULL);
@@ -2140,6 +2168,8 @@ static struct attribute *hwmon_attributes[] = {
 	&dev_attr_pwm2_enable.attr,
 	&dev_attr_fan1_input.attr,
 	&dev_attr_fan1_label.attr,
+	&dev_attr_fan2_input.attr,
+	&dev_attr_fan2_label.attr,
 
 	&dev_attr_temp1_input.attr,
 	NULL
@@ -2160,7 +2190,9 @@ static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj,
 	    || attr == &dev_attr_pwm1_enable.attr) {
 		if (asus->fan_type == FAN_TYPE_NONE)
 			return 0;
-	} else if (attr == &dev_attr_pwm2_enable.attr) {
+	} else if (attr == &dev_attr_fan2_input.attr
+	    || attr == &dev_attr_fan2_label.attr
+	    || attr == &dev_attr_pwm2_enable.attr) {
 		if (asus->gpu_fan_type == FAN_TYPE_NONE)
 			return 0;
 	} else if (attr == &dev_attr_temp1_input.attr) {
Signature · 1 line
2.37.3
#1 lore raw

Hi

2022. szeptember 16., péntek 2:46 keltezéssel, Luke D. Jones írta:

Quoted 22 lines

The previously added patch to add support for pwm change for TUF laptops also is usuable for more than TUF. The same method 0x00110014 is used to read the fan RPM.

Add two extra attributes for reading fan2 plus fan2 label.

---
 drivers/platform/x86/asus-wmi.c | 36 +++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)
drivers/platform/x86/asus-wmi.c +5 -0
index ae46af731de9..7fe6ce25da0a 100644
@@ -72,6 +72,7 @@ module_param(fnlock_default, bool, 0444);
[...]
+static ssize_t fan2_input_show(struct device *dev,
+					struct device_attribute *attr,
+					char *buf)
+{
+	struct asus_wmi *asus = dev_get_drvdata(dev);

drivers/platform/x86/asus-wmi.c module_param(fnlock_default, bool, 0444); · line 2096

Quoted 10 lines
drivers/platform/x86/asus-wmi.c +10 -0
+	int value;
+	int ret;
+
+	ret = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_GPU_FAN_CTRL, &value);
+	if (ret < 0)
+		return ret;
+
+	value &= 0xffff;
+
+	return sysfs_emit(buf, "%d\n", value < 0 ? -1 : value * 100);

Can value can be negative here? I am not sure because of the value &= 0xffff part. And maybe it would be better to return -ENODATA or something similar instead of printing "-1".

Quoted 2 lines

+}
[...]

Regards,
Barnabás Pőcze

#2 lore raw
In reply to Luke D. Jones

Hi Luke,

Quoted 32 lines · Luke D. Jones

The previously added patch to add support for pwm change for TUF laptops also is usuable for more than TUF. The same method 0x00110014 is used to read the fan RPM.

Add two extra attributes for reading fan2 plus fan2 label.

---
 drivers/platform/x86/asus-wmi.c | 36 +++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)
drivers/platform/x86/asus-wmi.c +6 -0
index ae46af731de9..7fe6ce25da0a 100644
@@ -72,6 +72,7 @@ module_param(fnlock_default, bool, 0444);
 
 #define ASUS_WMI_FNLOCK_BIOS_DISABLED	BIT(0)
 
+#define ASUS_GPU_FAN_DESC		"gpu_fan"
 #define ASUS_FAN_DESC			"cpu_fan"
 #define ASUS_FAN_MFUN			0x13
 #define ASUS_FAN_SFUN_READ		0x06
@@ -2078,6 +2079,30 @@ static ssize_t asus_hwmon_temp1(struct device *dev,
 }
 
 /* GPU fan on modern ROG laptops */
+static ssize_t fan2_input_show(struct device *dev,
+					struct device_attribute *attr,
+					char *buf)
+{
+	struct asus_wmi *asus = dev_get_drvdata(dev);

drivers/platform/x86/asus-wmi.c static ssize_t asus_hwmon_temp1(struct device *dev, · line 2096

Quoted 10 lines
drivers/platform/x86/asus-wmi.c +10 -0
+	int value;
+	int ret;
+
+	ret = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_GPU_FAN_CTRL, &value);
+	if (ret < 0)
+		return ret;
+
+	value &= 0xffff;
+
+	return sysfs_emit(buf, "%d\n", value < 0 ? -1 : value * 100);

As already mentioned since you & with 0xffff above the sign bit can never be set, so the value is never less then < 0, so I have simplified this to:

	return sysfs_emit(buf, "%d\n", value * 100);

while merging.

drivers/platform/x86/asus-wmi.c static ssize_t asus_hwmon_temp1(struct device *dev, · line 2104

Quoted 8 lines
drivers/platform/x86/asus-wmi.c +8 -0
+}
+
+static ssize_t fan2_label_show(struct device *dev,
+					  struct device_attribute *attr,
+					  char *buf)
+{
+	return sprintf(buf, "%s\n", ASUS_GPU_FAN_DESC);
+}

And here I have done s/sprintf/sysfs_emit/ with those changes I've applied this patch 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

Quoted 38 lines
drivers/platform/x86/asus-wmi.c +10 -2
+
 static ssize_t pwm2_enable_show(struct device *dev,
 				struct device_attribute *attr,
 				char *buf)
@@ -2127,9 +2152,12 @@ static ssize_t pwm2_enable_store(struct device *dev,
 /* Fan1 */
 static DEVICE_ATTR_RW(pwm1);
 static DEVICE_ATTR_RW(pwm1_enable);
-static DEVICE_ATTR_RW(pwm2_enable);
 static DEVICE_ATTR_RO(fan1_input);
 static DEVICE_ATTR_RO(fan1_label);
+/* Fan2 - GPU fan */
+static DEVICE_ATTR_RW(pwm2_enable);
+static DEVICE_ATTR_RO(fan2_input);
+static DEVICE_ATTR_RO(fan2_label);
 
 /* Temperature */
 static DEVICE_ATTR(temp1_input, S_IRUGO, asus_hwmon_temp1, NULL);
@@ -2140,6 +2168,8 @@ static struct attribute *hwmon_attributes[] = {
 	&dev_attr_pwm2_enable.attr,
 	&dev_attr_fan1_input.attr,
 	&dev_attr_fan1_label.attr,
+	&dev_attr_fan2_input.attr,
+	&dev_attr_fan2_label.attr,
 
 	&dev_attr_temp1_input.attr,
 	NULL
@@ -2160,7 +2190,9 @@ static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj,
 	    || attr == &dev_attr_pwm1_enable.attr) {
 		if (asus->fan_type == FAN_TYPE_NONE)
 			return 0;
-	} else if (attr == &dev_attr_pwm2_enable.attr) {
+	} else if (attr == &dev_attr_fan2_input.attr
+	    || attr == &dev_attr_fan2_label.attr
+	    || attr == &dev_attr_pwm2_enable.attr) {
 		if (asus->gpu_fan_type == FAN_TYPE_NONE)
 			return 0;
 	} else if (attr == &dev_attr_temp1_input.attr) {
author maintainer
#3 lore raw
Quoted 58 lines · Hans de Goede

Hi Luke,

Quoted 48 lines · Luke D. Jones

The previously added patch to add support for pwm change for TUF laptops
also is usuable for more than TUF. The same method 0x00110014 is used to read the fan RPM.

Add two extra attributes for reading fan2 plus fan2 label.

---
 drivers/platform/x86/asus-wmi.c | 36
+++++++++++++++++++++++++++++++--

 1 file changed, 34 insertions(+), 2 deletions(-)
drivers/platform/x86/asus-wmi.c +0 -0
index ae46af731de9..7fe6ce25da0a 100644
@@ -72,6 +72,7 @@ module_param(fnlock_default, bool, 0444);


 #define ASUS_WMI_FNLOCK_BIOS_DISABLED  BIT(0)

+#define ASUS_GPU_FAN_DESC              "gpu_fan"
 #define ASUS_FAN_DESC                  "cpu_fan"
 #define ASUS_FAN_MFUN                  0x13
 #define ASUS_FAN_SFUN_READ             0x06

drivers/platform/x86/asus-wmi.c +0 -0
@@ -2078,6 +2079,30 @@ static ssize_t asus_hwmon_temp1(struct
 device *dev,
  }


 /* GPU fan on modern ROG laptops */
+static ssize_t fan2_input_show(struct device *dev,
+                                       struct device_attribute *attr,
+                                       char *buf)

drivers/platform/x86/asus-wmi.c +6 -0
+{
+       struct asus_wmi *asus = dev_get_drvdata(dev);
+       int value;
+       int ret;
+
+       ret = asus_wmi_get_devstate(asus,

ASUS_WMI_DEVID_GPU_FAN_CTRL, &value);
+       if (ret < 0)
+               return ret;

drivers/platform/x86/asus-wmi.c +4 -0
+
+       value &= 0xffff;
+
+       return sysfs_emit(buf, "%d\n", value < 0 ? -1 : value *
Quoted 1 line

100);

As already mentioned since you & with 0xffff above the sign bit can never be
set, so the value is never less then < 0, so I have simplified this to:

Quoted 3 lines

        return sysfs_emit(buf, "%d\n", value * 100);

while merging.

Thanks Hans really appreciate it, sorry i missed that. My workload is a bit too large at the moment :)

Cheers,
Luke.

Quoted 71 lines

drivers/platform/x86/asus-wmi.c static ssize_t asus_hwmon_temp1(struct device *dev, · line 2104

Quoted 10 lines
drivers/platform/x86/asus-wmi.c +4 -0
+}
+
+static ssize_t fan2_label_show(struct device *dev,
+                                         struct device_attribute

*attr,
+                                         char *buf)

drivers/platform/x86/asus-wmi.c +3 -0
+{
+       return sprintf(buf, "%s\n", ASUS_GPU_FAN_DESC);
+}

And here I have done s/sprintf/sysfs_emit/ with those changes I've applied this patch 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

Quoted 41 lines

+
 static ssize_t pwm2_enable_show(struct device *dev, struct device_attribute *attr, char *buf)

drivers/platform/x86/asus-wmi.c +4 -1
@@ -2127,9 +2152,12 @@ static ssize_t pwm2_enable_store(struct
 device *dev,
  /* Fan1 */
  static DEVICE_ATTR_RW(pwm1);
  static DEVICE_ATTR_RW(pwm1_enable);
-static DEVICE_ATTR_RW(pwm2_enable);
  static DEVICE_ATTR_RO(fan1_input);
  static DEVICE_ATTR_RO(fan1_label);
+/* Fan2 - GPU fan */
+static DEVICE_ATTR_RW(pwm2_enable);
+static DEVICE_ATTR_RO(fan2_input);
+static DEVICE_ATTR_RO(fan2_label);


 /* Temperature */
 static DEVICE_ATTR(temp1_input, S_IRUGO, asus_hwmon_temp1, NULL);

drivers/platform/x86/asus-wmi.c +2 -0
@@ -2140,6 +2168,8 @@ static struct attribute *hwmon_attributes[] =
 {
         &dev_attr_pwm2_enable.attr,
         &dev_attr_fan1_input.attr,
         &dev_attr_fan1_label.attr,
+       &dev_attr_fan2_input.attr,
+       &dev_attr_fan2_label.attr,


        &dev_attr_temp1_input.attr,
        NULL

drivers/platform/x86/asus-wmi.c +3 -1
@@ -2160,7 +2190,9 @@ static umode_t
 asus_hwmon_sysfs_is_visible(struct kobject *kobj,
             || attr == &dev_attr_pwm1_enable.attr) {
                 if (asus->fan_type == FAN_TYPE_NONE)
                         return 0;
-       } else if (attr == &dev_attr_pwm2_enable.attr) {
+       } else if (attr == &dev_attr_fan2_input.attr
+           || attr == &dev_attr_fan2_label.attr
+           || attr == &dev_attr_pwm2_enable.attr) {
                 if (asus->gpu_fan_type == FAN_TYPE_NONE)
                         return 0;

        } else if (attr == &dev_attr_temp1_input.attr) {