Skip to contentSkip to conversation

HID: asus: Add Fn+F5 fan control key support for ROG laptops

PATCH In review Ionut Nechita (Sunlight Linux) 2 participants 7 messages Jan 7 – Jan 8

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v5 cover HID: asus: Add Fn+F5 fan control key support for ROG laptops

From: Ionut Nechita <[email protected]>

This series adds support for the Fn+F5 fan control key on Asus ROG laptops and addresses spurious HID vendor codes that cause kernel log spam on these devices.

The series introduces:
1. Code cleanup by replacing a magic number with an existing constant
2. Filtering of spurious HID vendor usage codes on ROG laptops
3. Infrastructure for HID-to-WMI communication
4. Fn+F5 fan control key handler with userspace fallback support

The Fn+F5 key handler attempts to forward events to asus-wmi when available. If asus-wmi is unavailable or fails, the event is passed to userspace via evdev, allowing userspace fan control implementations.

Tested on Asus ROG series laptops.

Changes in v5:
- Removed IS_REACHABLE(CONFIG_ASUS_WMI) guards from patch 3 as asus_wmi_evaluate_method() already returns -ENODEV when asus-wmi is not available, and the warning is helpful for users (Mario's feedback)
- Updated commit message for patch 3 to reflect the removal of conditional compilation guards

Changes in v4:
- Added Reviewed-by tag from Mario Limonciello (AMD) to all patches

Changes in v3:
- Added IS_REACHABLE(CONFIG_ASUS_WMI) conditional compilation guards to prevent build failures when asus-wmi is not compiled (patch 3)
- Modified Fn+F5 handler to pass events to userspace when asus-wmi is unavailable or fails, enabling userspace fan control (patch 4)
- Updated comments and commit message to reflect that spurious codes affect all ROG laptops, not just G14/G15, and occur during normal operation, not just on keypresses (patch 2)
- Simplified commit message for WMI infrastructure patch (patch 3)
- Added Reviewed-by tag from Denis Benato
- Removed Change-Id tags

Changes in v2:
- Split the original patch into a logical series of 4 patches
- Improved code organization and commit messages

Ionut Nechita (4):
HID: asus: Replace magic number with HID_UP_ASUSVENDOR constant
HID: asus: Filter spurious HID vendor codes on ROG laptops
HID: asus: Add WMI communication infrastructure
HID: asus: Implement Fn+F5 fan control key handler

 drivers/hid/hid-asus.c                     | 73 +++++++++++++++++++++-
 include/linux/platform_data/x86/asus-wmi.h |  1 +
 2 files changed, 73 insertions(+), 1 deletion(-)

--
2.52.0

#1 lore raw

PATCH v5 1/4 HID: asus: Replace magic number with HID_UP_ASUSVENDOR constant

From: Ionut Nechita <[email protected]>

Use the existing HID_UP_ASUSVENDOR constant instead of the magic number 0xff310000 for better code clarity and maintainability.

---
 drivers/hid/hid-asus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-asus.c +1 -1
index 472bca54642b9..eb14b9d13823b 100644
@@ -317,7 +317,7 @@ static int asus_e1239t_event(struct asus_drvdata *drvdat, u8 *data, int size)
 static int asus_event(struct hid_device *hdev, struct hid_field *field,
 		      struct hid_usage *usage, __s32 value)
 {
-	if ((usage->hid & HID_USAGE_PAGE) == 0xff310000 &&
+	if ((usage->hid & HID_USAGE_PAGE) == HID_UP_ASUSVENDOR &&
 	    (usage->hid & HID_USAGE) != 0x00 &&
 	    (usage->hid & HID_USAGE) != 0xff && !usage->type) {
 		hid_warn(hdev, "Unmapped Asus vendor usagepage code 0x%02x\n",
Signature · 1 line
2.52.0
#2 lore raw

PATCH v5 2/4 HID: asus: Filter spurious HID vendor codes on ROG laptops

In reply to Ionut Nechita (Sunlight Linux)

From: Ionut Nechita <[email protected]>

On Asus ROG laptops, several HID vendor usage codes (0xea, 0xec, 0x02, 0x8a, 0x9e) are sent during normal operation without a clear purpose, generating unwanted "Unmapped Asus vendor usagepage code" warnings in dmesg.

Add definitions for these codes and filter them out in asus_raw_event() to prevent kernel log spam.

Tested on Asus ROG series laptops.

---
 drivers/hid/hid-asus.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/hid/hid-asus.c +22 -0
index eb14b9d13823b..15c24d5812763 100644
@@ -57,6 +57,13 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
 #define ROG_ALLY_X_MIN_MCU 313
 #define ROG_ALLY_MIN_MCU 319
 
+/* Spurious HID codes sent by QUIRK_ROG_NKEY_KEYBOARD devices */
+#define ASUS_SPURIOUS_CODE_0XEA 0xea
+#define ASUS_SPURIOUS_CODE_0XEC 0xec
+#define ASUS_SPURIOUS_CODE_0X02 0x02
+#define ASUS_SPURIOUS_CODE_0X8A 0x8a
+#define ASUS_SPURIOUS_CODE_0X9E 0x9e
+
 #define SUPPORT_KBD_BACKLIGHT BIT(0)
 
 #define MAX_TOUCH_MAJOR 8
@@ -348,6 +355,21 @@ static int asus_raw_event(struct hid_device *hdev,
 	if (report->id == FEATURE_KBD_LED_REPORT_ID1 || report->id == FEATURE_KBD_LED_REPORT_ID2)
 		return -1;
 	if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD) {
+		/*
+		 * ASUS ROG laptops send these codes during normal operation
+		 * with no discernable reason. Filter them out to avoid
+		 * unmapped warning messages.
+		 */
+		if (report->id == FEATURE_KBD_REPORT_ID) {
+			if (data[1] == ASUS_SPURIOUS_CODE_0XEA ||
+			    data[1] == ASUS_SPURIOUS_CODE_0XEC ||
+			    data[1] == ASUS_SPURIOUS_CODE_0X02 ||
+			    data[1] == ASUS_SPURIOUS_CODE_0X8A ||
+			    data[1] == ASUS_SPURIOUS_CODE_0X9E) {
+				return -1;
+			}
+		}
+
 		/*
 		 * G713 and G733 send these codes on some keypresses, depending on
 		 * the key pressed it can trigger a shutdown event if not caught.
Signature · 1 line
2.52.0
#3 lore raw

PATCH v5 3/4 HID: asus: Add WMI communication infrastructure

In reply to Ionut Nechita (Sunlight Linux)

From: Ionut Nechita <[email protected]>

Add infrastructure for the HID driver to communicate with the asus-wmi driver for handling special keys that require WMI communication.

This includes:
- Define ASUS_WMI_METHODID_NOTIF method ID in asus-wmi.h
- Implement asus_wmi_send_event() function to send events to asus-wmi

---
 drivers/hid/hid-asus.c                     | 24 ++++++++++++++++++++++
 include/linux/platform_data/x86/asus-wmi.h |  1 +
 2 files changed, 25 insertions(+)
drivers/hid/hid-asus.c +24 -0
index 15c24d5812763..6fcd3213857cf 100644
@@ -23,6 +23,7 @@
 /*
  */
 
+#include <linux/acpi.h>
 #include <linux/dmi.h>
 #include <linux/hid.h>
 #include <linux/module.h>
@@ -321,6 +322,29 @@ static int asus_e1239t_event(struct asus_drvdata *drvdat, u8 *data, int size)
 	return 0;
 }
 
+/*
+ * Send events to asus-wmi driver for handling special keys
+ */
+static int asus_wmi_send_event(struct asus_drvdata *drvdata, u8 code)
+{
+	int err;
+	u32 retval;
+
+	err = asus_wmi_evaluate_method(ASUS_WMI_METHODID_DEVS,
+				       ASUS_WMI_METHODID_NOTIF, code, &retval);
+	if (err) {
+		pr_warn("Failed to notify asus-wmi: %d\n", err);
+		return err;
+	}
+
+	if (retval != 0) {
+		pr_warn("Failed to notify asus-wmi (retval): 0x%x\n", retval);
+		return -EIO;
+	}
+
+	return 0;
+}
+
 static int asus_event(struct hid_device *hdev, struct hid_field *field,
 		      struct hid_usage *usage, __s32 value)
 {
include/linux/platform_data/x86/asus-wmi.h +1 -0
index 419491d4abca1..516538b5a527e 100644
@@ -29,6 +29,7 @@
 #define ASUS_WMI_METHODID_KBFT		0x5446424B /* KeyBoard FilTer */
 #define ASUS_WMI_METHODID_INIT		0x54494E49 /* INITialize */
 #define ASUS_WMI_METHODID_HKEY		0x59454B48 /* Hot KEY ?? */
+#define ASUS_WMI_METHODID_NOTIF		0x00100021 /* Notify method */
 
 #define ASUS_WMI_UNSUPPORTED_METHOD	0xFFFFFFFE
 
Signature · 1 line
2.52.0
#4 lore raw

PATCH v5 4/4 HID: asus: Implement Fn+F5 fan control key handler

In reply to Ionut Nechita (Sunlight Linux)

From: Ionut Nechita <[email protected]>

On Asus ROG laptops, the Fn+F5 key (HID code 0xae) is used to cycle through fan modes. This key press needs to be forwarded to the asus-wmi driver to actually change the fan mode.

Add ASUS_FAN_CTRL_KEY_CODE define and implement the handler in asus_raw_event() to send WMI events when this key is pressed.

When asus-wmi successfully handles the event, it is blocked from reaching userspace. If asus-wmi is unavailable or fails, the event is passed to userspace via evdev, allowing userspace implementations of fan control.

Tested on Asus ROG G14/G15 series laptops.

---
 drivers/hid/hid-asus.c | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)
drivers/hid/hid-asus.c +30 -5
index 6fcd3213857cf..06f32a39c0cf7 100644
@@ -65,6 +65,9 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
 #define ASUS_SPURIOUS_CODE_0X8A 0x8a
 #define ASUS_SPURIOUS_CODE_0X9E 0x9e
 
+/* Special key codes */
+#define ASUS_FAN_CTRL_KEY_CODE 0xae
+
 #define SUPPORT_KBD_BACKLIGHT BIT(0)
 
 #define MAX_TOUCH_MAJOR 8
@@ -379,12 +382,34 @@ static int asus_raw_event(struct hid_device *hdev,
 	if (report->id == FEATURE_KBD_LED_REPORT_ID1 || report->id == FEATURE_KBD_LED_REPORT_ID2)
 		return -1;
 	if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD) {
-		/*
-		 * ASUS ROG laptops send these codes during normal operation
-		 * with no discernable reason. Filter them out to avoid
-		 * unmapped warning messages.
-		 */
 		if (report->id == FEATURE_KBD_REPORT_ID) {
+			/*
+			 * Fn+F5 fan control key - try to send WMI event to toggle fan mode.
+			 * If successful, block the event from reaching userspace.
+			 * If asus-wmi is unavailable or the call fails, let the event
+			 * pass to userspace so it can implement its own fan control.
+			 */
+			if (data[1] == ASUS_FAN_CTRL_KEY_CODE) {
+				int ret = asus_wmi_send_event(drvdata, ASUS_FAN_CTRL_KEY_CODE);
+
+				if (ret == 0) {
+					/* Successfully handled by asus-wmi, block event */
+					return -1;
+				}
+
+				/*
+				 * Warn if asus-wmi failed (but not if it's unavailable).
+				 * Let the event reach userspace in all failure cases.
+				 */
+				if (ret != -ENODEV)
+					hid_warn(hdev, "Failed to notify asus-wmi: %d\n", ret);
+			}
+
+			/*
+			 * ASUS ROG laptops send these codes during normal operation
+			 * with no discernable reason. Filter them out to avoid
+			 * unmapped warning messages.
+			 */
 			if (data[1] == ASUS_SPURIOUS_CODE_0XEA ||
 			    data[1] == ASUS_SPURIOUS_CODE_0XEC ||
 			    data[1] == ASUS_SPURIOUS_CODE_0X02 ||
Signature · 1 line
2.52.0
#5 lore raw
In reply to Ionut Nechita (Sunlight Linux)

Hello,

I hope this email finds you well. I wanted to follow up on my v5 patch series for Fn+F5 fan control key support on Asus ROG laptops, which I submitted on January 7th.

The series has received Reviewed-by tags from both Mario Limonciello (AMD) and Denis Benato, and I've addressed all the feedback from previous versions, including the removal of IS_REACHABLE guards as suggested by Mario.

I wanted to check if there are any additional changes or improvements you'd like me to make before this series can be considered for merging into mainline. I'm happy to address any further feedback.

Also, if you could let me know what the next steps are in the process, I would appreciate it.

Thank you for your time and guidance.

Best regards,
Ionut

maintainer
#6 lore raw
Quoted 9 lines · Ionut Nechita (Sunlight Linux)

I hope this email finds you well. I wanted to follow up on my v5 patch series for Fn+F5 fan control key support on Asus ROG laptops, which I submitted on January 7th.

The series has received Reviewed-by tags from both Mario Limonciello (AMD) and Denis Benato, and I've addressed all the feedback from previous versions, including the removal of IS_REACHABLE guards as suggested by Mario.

Quoted 6 lines

I wanted to check if there are any additional changes or improvements you'd like me to make before this series can be considered for merging into mainline. I'm happy to address any further feedback.

Also, if you could let me know what the next steps are in the process, I would appreciate it.

It took me some time to go through the iterations, feedback and review the patch, now applied to hid.git#for-6.20/asus, thanks.

Signature · 2 lines
Jiri Kosina
SUSE Labs