HID: asus: Add Fn+F5 fan control key support for ROG laptops
Subsystems (2)
v3 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 with proper build guards
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 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 | 80 +++++++++++++++++++++- include/linux/platform_data/x86/asus-wmi.h | 1 + 2 files changed, 80 insertions(+), 1 deletion(-)
--
2.52.0
PATCH v3 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
@@ -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
PATCH v3 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
@@ -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
PATCH v3 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 with proper conditional compilation guards for when asus-wmi is not available
--- drivers/hid/hid-asus.c | 31 ++++++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 1 + 2 files changed, 32 insertions(+)
drivers/hid/hid-asus.c +31 -0
@@ -23,6 +23,7 @@/* */ +#include <linux/acpi.h> #include <linux/dmi.h> #include <linux/hid.h> #include <linux/module.h>
@@ -321,6 +322,36 @@ 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 +*/ +#if IS_REACHABLE (CONFIG_ASUS_WMI ) +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 ; +} +#else +static inline int asus_wmi_send_event (struct asus_drvdata *drvdata,u8 code) +{ +return -ENODEV ; +} +#endif +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
@@ -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
PATCH v3 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
@@ -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
@@ -386,12 +389,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
Re: [PATCH v3 3/4] HID: asus: Add WMI communication infrastructure
In reply to Ionut Nechita (Sunlight Linux)Quoted 30 lines · 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:
- DefineASUS_WMI_METHODID_NOTIFmethod ID inasus-wmi.h
- Implementasus_wmi_send_event()function with proper conditional compilation guards for when asus-wmi is not availableReviewed-by Denis Benato <[email protected]>Signed-off-by Ionut Nechita <[email protected]>--- drivers/hid/hid-asus.c | 31 ++++++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 1 + 2 files changed, 32 insertions(+)drivers/hid/hid-asus.c +1
-0@@ -23,6 +23,7 @@/* */ +#include <linux/acpi.h> #include <linux/dmi.h> #include <linux/hid.h> #include <linux/module.h>
drivers/hid/hid-asus.c static int asus_e1239t_event(struct asus_drvdata *drvdat, u8 *data, int size) · line 328
Quoted 7 lines
drivers/hid/hid-asus.c +4
-0@@ -321,6 +322,36 @@ 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 +*/ +#if IS_REACHABLE (CONFIG_ASUS_WMI )
I think this specific IS_REACHABLE isn't needed.
asus_wmi_evaluate_method() will return -ENODEV in that case already.
I think the warning you have below is actually helpful too because it will be obvious to a user they forgot to enable asus-wmi in their kernel config.
Quoted 41 lines
drivers/hid/hid-asus.c +26
-0+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 ; +} +#else +static inline int asus_wmi_send_event (struct asus_drvdata *drvdata,u8 code) +{ +return -ENODEV ; +} +#endif +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@@ -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