hid-asus: asus-wmi: refactor Ally suspend/resume
Luke Jones
maintainerv3 cover hid-asus: asus-wmi: refactor Ally suspend/resume
This short series refactors the Ally suspend/resume functionality in the asus-wmi driver along with adding support for ROG Ally MCU version checking.
The version checking is then used to toggle the use of older CSEE call hacks that were initially used to combat Ally suspend/wake issues arising from the MCU not clearing a particular flag on resume. ASUS have since corrected this especially for Linux in newer firmware versions.
- hid-asus requests the MCU version and displays a warning if the version is older than the one that fixes the issue.
- hid-asus awill also toggle the CSEE hack off, and mcu_powersave to on if the version is high enough.
*Note: In review it was requested by Mario that I try strsep() for parsing the version. I did try this and a few variations but the result was much more code due to having to check more edge cases due to the input being raw bytes. In the end the cleaned up while loop proved more robust.
- Changelog:
+ V2: https://lore.kernel.org/platform-driver-x86/[email protected]/T/#t
- Adjust warning message to explicitly mention suspend issues
- Use switch/case block to set min_version
- Set min_version to 0 by default and toggle hacks off
+ V3
- Remove noise (excess pr_info)
- Use kstrtoint, not kstrtolong
- Use __free(kfree) for allocated mem and drop goto + logging
- Use print_hex_dump() to show failed data after pr_err in mcu_request_version()
- Use pr_debug in set_ally_mcu_hack() and set_ally_mcu_powersave() plus correct the message.
Luke D. Jones (2):
hid-asus: check ROG Ally MCU version and warn platform/x86: asus-wmi: Refactor Ally suspend/resume
drivers/hid/hid-asus.c | 111 +++++++++++++++++- drivers/platform/x86/asus-wmi.c | 130 ++++++++++++++------- include/linux/platform_data/x86/asus-wmi.h | 15 +++ 3 files changed, 215 insertions(+), 41 deletions(-)
Signature · 1 line
2.48.1
Luke Jones
maintainerPATCH v3 1/2 hid-asus: check ROG Ally MCU version and warn
From: "Luke D. Jones" <[email protected]>
ASUS have fixed suspend issues arising from a flag not being cleared in the MCU FW in both the ROG Ally 1 and the ROG Ally X.
Implement a check and a warning to encourage users to update the FW to a minimum supported version.
--- drivers/hid/hid-asus.c | 107 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 2 deletions(-)
drivers/hid/hid-asus.c +105 -2
@@ -52,6 +52,10 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");#define FEATURE_KBD_LED_REPORT_ID1 0x5d#define FEATURE_KBD_LED_REPORT_ID2 0x5e +#define ROG_ALLY_REPORT_SIZE 64 +#define ROG_ALLY_X_MIN_MCU 313 +#define ROG_ALLY_MIN_MCU 319 +#define SUPPORT_KBD_BACKLIGHT BIT(0)#define MAX_TOUCH_MAJOR 8
@@ -84,6 +88,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");#define QUIRK_MEDION_E1239T BIT(10)#define QUIRK_ROG_NKEY_KEYBOARD BIT(11)#define QUIRK_ROG_CLAYMORE_II_KEYBOARD BIT(12) +#define QUIRK_ROG_ALLY_XPAD BIT(13)#define I2C_KEYBOARD_QUIRKS (QUIRK_FIX_NOTEBOOK_REPORT | \ QUIRK_NO_INIT_REPORTS | \
@@ -534,9 +539,99 @@ static bool asus_kbd_wmi_led_control_present(struct hid_device *hdev)return !!(value &ASUS_WMI_DSTS_PRESENCE_BIT ); } +/* +* We don't care about any other part of the string except the version section. +* Example strings: FGA80100.RC72LA.312_T01, FGA80100.RC71LS.318_T01 +* The bytes "5a 05 03 31 00 1a 13" and possibly more come before the version +* string, and there may be additional bytes after the version string such as +* "75 00 74 00 65 00" or a postfix such as "_T01" +*/ +static int mcu_parse_version_string (const u8 *response,size_t response_size) +{ +const u8 *end = response + response_size; +const u8 *p = response; +int dots, err, version; +char buf[4 ]; + + dots =0 ; +while (p < end && dots <2 ) { +if (*p++ =='.' ) + dots++; + } + +if (dots !=2 || p >= end || (p +3 ) >= end) +return -EINVAL ; + +memcpy (buf, p,3 ); + buf[3 ] ='\0' ; + + err =kstrtoint (buf,10 , &version); +if (err || version <0 ) +return -EINVAL ; + +return version; +} + +static int mcu_request_version (struct hid_device *hdev) +{ + u8 *response __free(kfree) = kzalloc(ROG_ALLY_REPORT_SIZE, GFP_KERNEL); +const u8 request[] = {0x5a ,0x05 ,0x03 ,0x31 ,0x00 ,0x20 }; +int ret; + +if (!response) +return -ENOMEM ; + + ret =asus_kbd_set_report (hdev, request,sizeof (request)); +if (ret <0 ) +return ret; + + ret =hid_hw_raw_request (hdev,FEATURE_REPORT_ID , response, +ROG_ALLY_REPORT_SIZE ,HID_FEATURE_REPORT , +HID_REQ_GET_REPORT ); +if (ret <0 ) +return ret; + + ret =mcu_parse_version_string (response,ROG_ALLY_REPORT_SIZE ); +if (ret <0 ) { +pr_err ("Failed to parse MCU version: %d\n" , ret); +print_hex_dump (KERN_ERR ,"MCU: " ,DUMP_PREFIX_NONE , +16 ,1 , response,ROG_ALLY_REPORT_SIZE , false); + } + +return ret; +} + +static void validate_mcu_fw_version (struct hid_device *hdev,int idProduct) +{ +int min_version, version; + + version =mcu_request_version (hdev); +if (version <0 ) +return ; + +switch (idProduct) { +case USB_DEVICE_ID_ASUSTEK_ROG_NKEY_ALLY : + min_version =ROG_ALLY_MIN_MCU ; +break ; +case USB_DEVICE_ID_ASUSTEK_ROG_NKEY_ALLY_X : + min_version =ROG_ALLY_X_MIN_MCU ; +break ; +default : + min_version =0 ; + } + +if (version < min_version) { +hid_warn (hdev, +"The MCU firmware version must be %d or greater to avoid issues with suspend.\n" , + min_version); + } +} +static int asus_kbd_register_leds (struct hid_device *hdev) {struct asus_drvdata *drvdata =hid_get_drvdata (hdev); +struct usb_interface *intf; +struct usb_device *udev;unsigned char kbd_func;int ret;
@@ -560,6 +655,14 @@ static int asus_kbd_register_leds(struct hid_device *hdev)if (ret <0 )return ret; } + +if (drvdata->quirks &QUIRK_ROG_ALLY_XPAD ) { + intf =to_usb_interface (hdev->dev.parent); + udev =interface_to_usbdev (intf); +validate_mcu_fw_version (hdev, +le16_to_cpu (udev->descriptor.idProduct)); + } + }else {/* Initialize keyboard */ ret =asus_kbd_init (hdev,FEATURE_KBD_REPORT_ID );
@@ -1280,10 +1383,10 @@ static const struct hid_device_id asus_devices[] = { QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, {HID_USB_DEVICE (USB_VENDOR_ID_ASUSTEK ,USB_DEVICE_ID_ASUSTEK_ROG_NKEY_ALLY ), - QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD | QUIRK_ROG_ALLY_XPAD}, { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,USB_DEVICE_ID_ASUSTEK_ROG_NKEY_ALLY_X ), - QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD | QUIRK_ROG_ALLY_XPAD }, { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,USB_DEVICE_ID_ASUSTEK_ROG_CLAYMORE_II_KEYBOARD ), QUIRK_ROG_CLAYMORE_II_KEYBOARD },
Signature · 1 line
2.48.1
Luke Jones
maintainerPATCH v3 2/2 platform/x86: asus-wmi: Refactor Ally suspend/resume
In reply to Luke JonesFrom: "Luke D. Jones" <[email protected]>
Adjust how the CSEE direct call hack is used.
The results of months of testing combined with help from ASUS to determine the actual cause of suspend issues has resulted in this refactoring which immensely improves the reliability for devices which do not have the following minimum MCU FW version:
- ROG Ally X: 313
- ROG Ally 1: 319
For MCU FW versions that match the minimum or above the CSEE hack is disabled and mcu_powersave set to on by default as there are no negatives beyond a slightly slower device reinitialization due to the MCU being powered off.
As this is set only at module load time, it is still possible for mcu_powersave sysfs attributes to change it at runtime if so desired.
--- drivers/hid/hid-asus.c | 4 + drivers/platform/x86/asus-wmi.c | 130 ++++++++++++++------- include/linux/platform_data/x86/asus-wmi.h | 15 +++ 3 files changed, 110 insertions(+), 39 deletions(-)
drivers/hid/hid-asus.c +4 -0
@@ -624,6 +624,9 @@ static void validate_mcu_fw_version(struct hid_device *hdev, int idProduct)hid_warn (hdev,"The MCU firmware version must be %d or greater to avoid issues with suspend.\n" , min_version); + }else { +set_ally_mcu_hack (false); +set_ally_mcu_powersave (true); } }
@@ -1430,4 +1433,5 @@ static struct hid_driver asus_driver = { };module_hid_driver (asus_driver); +MODULE_IMPORT_NS ("ASUS_WMI" );MODULE_LICENSE ("GPL" );
drivers/platform/x86/asus-wmi.c +91 -39
206 lines not on this page · raw message
include/linux/platform_data/x86/asus-wmi.h +15 -0
@@ -158,8 +158,23 @@#define ASUS_WMI_DSTS_LIGHTBAR_MASK 0x0000000F#if IS_REACHABLE (CONFIG_ASUS_WMI ) +void set_ally_mcu_hack (bool enabled); +void set_ally_mcu_powersave (bool enabled); +int asus_wmi_set_devstate (u32 dev_id,u32 ctrl_param,u32 *retval);int asus_wmi_evaluate_method (u32 method_id,u32 arg0,u32 arg1,u32 *retval);#else +static inline void set_ally_mcu_hack (bool enabled) +{ +return -ENODEV ; +} +static inline void set_ally_mcu_powersave (bool enabled) +{ +return -ENODEV ; +} +static inline int asus_wmi_set_devstate (u32 dev_id,u32 ctrl_param,u32 *retval) +{ +return -ENODEV ; +}static inline int asus_wmi_evaluate_method (u32 method_id,u32 arg0,u32 arg1,u32 *retval) {
Signature · 1 line
2.48.1
kernel test robot
build botRe: [PATCH v3 2/2] platform/x86: asus-wmi: Refactor Ally suspend/resume
kernel test robot noticed the following build errors:
Hi Luke,
kernel test robot noticed the following build errors:
[auto build test ERROR on hid/for-next]
[also build test ERROR on linus/master v6.14-rc5 next-20250307] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Luke-Jones/hid-asus-check-ROG-Ally-MCU-version-and-warn/20250227-165941 base: https://git.kernel.org/pub/scm/linux/kernel/git/hid/hid.git for-next patch link: https://lore.kernel.org/r/20250227085817.1007697-3-luke%40ljones.dev patch subject: [PATCH v3 2/2] platform/x86: asus-wmi: Refactor Ally suspend/resume config: mips-allyesconfig (https://download.01.org/0day-ci/archive/20250308/[email protected]/config) compiler: mips-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250308/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from drivers/hid/hid-asus.c:29:
include/linux/platform_data/x86/asus-wmi.h: In function 'set_ally_mcu_hack':
>> include/linux/platform_data/x86/asus-wmi.h:168:16: error: 'return' with a value, in function returning void [-Wreturn-mismatch]
168 | return -ENODEV;
| ^
include/linux/platform_data/x86/asus-wmi.h:166:20: note: declared here
166 | static inline void set_ally_mcu_hack(bool enabled)
| ^~~~~~~~~~~~~~~~~
include/linux/platform_data/x86/asus-wmi.h: In function 'set_ally_mcu_powersave':
include/linux/platform_data/x86/asus-wmi.h:172:16: error: 'return' with a value, in function returning void [-Wreturn-mismatch]
172 | return -ENODEV;
| ^ include/linux/platform_data/x86/asus-wmi.h:170:20: note: declared here
170 | static inline void set_ally_mcu_powersave(bool enabled)
| ^~~~~~~~~~~~~~~~~~~~~~
vim +/return +168 include/linux/platform_data/x86/asus-wmi.h
159
160 #if IS_REACHABLE(CONFIG_ASUS_WMI)
161 void set_ally_mcu_hack(bool enabled);
162 void set_ally_mcu_powersave(bool enabled);
163 int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param, u32 *retval);
164 int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1, u32 *retval);
165 #else
166 static inline void set_ally_mcu_hack(bool enabled)
167 {
> 168 return -ENODEV;
169 }
170 static inline void set_ally_mcu_powersave(bool enabled)
171 {
172 return -ENODEV;
173 }
174 static inline int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param, u32 *retval)
175 {
176 return -ENODEV;
177 }
178 static inline int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1,
179 u32 *retval)
180 {
181 return -ENODEV;
182 }
183 #endif
184
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Luke Jones
maintainerRe: [PATCH v3 2/2] platform/x86: asus-wmi: Refactor Ally suspend/resume
Quoted 44 lines · kernel test robot
Hi Luke,
kernel test robot noticed the following build errors:
[auto build test ERROR on hid/for-next]
[also build test ERROR on linus/master v6.14-rc5 next-20250307] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url:
https://github.com/intel-lab-lkp/linux/commits/Luke-Jones/hid-asus-check-ROG-Ally-MCU-version-and-warn/20250227-165941
base: https://git.kernel.org/pub/scm/linux/kernel/git/hid/hid.git
for-next
patch link:
https://lore.kernel.org/r/20250227085817.1007697-3-luke%40ljones.dev
patch subject: [PATCH v3 2/2] platform/x86: asus-wmi: Refactor Ally suspend/resume
config: mips-allyesconfig
(https://download.01.org/0day-ci/archive/20250308/[email protected]/config)
compiler: mips-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build):
(https://download.01.org/0day-ci/archive/20250308/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes:
https://lore.kernel.org/oe-kbuild-all/[email protected]/All errors (new ones prefixed by >>):
In file included from
drivers/hid/hid-asus.c:29:
include/linux/platform_data/x86/asus-wmi.h: In function 'set_ally_mcu_hack':Quoted 1 line
Quoted 1 line
include/linux/platform_data/x86/asus-wmi.h:168:16: error: 'return' with a value, in function returning void [-Wreturn-mismatch]168 | return -ENODEV; | ^
include/linux/platform_data/x86/asus-wmi.h:166:20: note: declared
here
166 | static inline voidset_ally_mcu_hack(bool enabled)
| ^~~~~~~~~~~~~~~~~
include/linux/platform_data/x86/asus-wmi.h: In function
'set_ally_mcu_powersave':
Quoted 8 lines
include/linux/platform_data/x86/asus-wmi.h:172:16: error: 'return' with a value, in function returning void [-Wreturn-mismatch] 172 | return -ENODEV; | ^
include/linux/platform_data/x86/asus-wmi.h:170:20: note: declared
here
170 | static inline voidset_ally_mcu_powersave(bool enabled)
| ^~~~~~~~~~~~~~~~~~~~~~
*Groaning sounds*.
Ilpo/Hans, you guys want me to fix this and submit new series or can this be corrected when pulled in? There's two more of the same below this.
Quoted 37 lines
vim +/return +168
include/linux/platform_data/x86/asus-wmi.h159 160 #if IS_REACHABLE(CONFIG_ASUS_WMI) 161 void set_ally_mcu_hack(bool enabled); 162 void set_ally_mcu_powersave(bool enabled); 163 int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param, u32 *retval); 164 int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1, u32 *retval); 165 #else 166 static inline void set_ally_mcu_hack(bool enabled) 167 {Quoted 1 line
168 return
-ENODEV;169 }
170 static inline voidset_ally_mcu_powersave(bool enabled)171 { 172 return -ENODEV; 173 } 174 static inline int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param, u32 *retval) 175 { 176 return -ENODEV; 177 } 178 static inline int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1, 179 u32 *retval) 180 { 181 return -ENODEV; 182 } 183 #endif 184Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 31 lines · Luke Jones
This short series refactors the Ally suspend/resume functionality in the asus-wmi driver along with adding support for ROG Ally MCU version checking.
The version checking is then used to toggle the use of older CSEE call hacks that were initially used to combat Ally suspend/wake issues arising from the MCU not clearing a particular flag on resume. ASUS have since corrected this especially for Linux in newer firmware versions.
- hid-asus requests the MCU version and displays a warning if the version is older than the one that fixes the issue.
- hid-asus awill also toggle the CSEE hack off, andmcu_powersaveto on if the version is high enough.*Note: In review it was requested by Mario that I try
strsep()for parsing the version. I did try this and a few variations but the result was much more code due to having to check more edge cases due to the input being raw bytes. In the end the cleaned up while loop proved more robust.- Changelog:
+ V2: https://lore.kernel.org/platform-driver-x86/[email protected]/T/#t
- Adjust warning message to explicitly mention suspend issues
- Use switch/case block to setmin_version
- Setmin_versionto 0 by default and toggle hacks off
+ V3
- Remove noise (excesspr_info)
- Use kstrtoint, not kstrtolong
- Use__free(kfree)for allocated mem and drop goto + logging
- Useprint_hex_dump()to show failed data afterpr_errinmcu_request_version()
- Usepr_debuginset_ally_mcu_hack()andset_ally_mcu_powersave()plus correct the message.
Quoted 9 lines
Luke D. Jones (2):
hid-asus: check ROG Ally MCU version and warn platform/x86: asus-wmi: Refactor Ally suspend/resumedrivers/hid/hid-asus.c | 111 +++++++++++++++++- drivers/platform/x86/asus-wmi.c | 130 ++++++++++++++------- include/linux/platform_data/x86/asus-wmi.h | 15 +++ 3 files changed, 215 insertions(+), 41 deletions(-)
Jiri Kosina
maintainerQuoted 31 lines · Luke Jones
This short series refactors the Ally suspend/resume functionality in the asus-wmi driver along with adding support for ROG Ally MCU version checking.
The version checking is then used to toggle the use of older CSEE call hacks that were initially used to combat Ally suspend/wake issues arising from the MCU not clearing a particular flag on resume. ASUS have since corrected this especially for Linux in newer firmware versions.
- hid-asus requests the MCU version and displays a warning if the version is older than the one that fixes the issue.
- hid-asus awill also toggle the CSEE hack off, andmcu_powersaveto on if the version is high enough.*Note: In review it was requested by Mario that I try
strsep()for parsing the version. I did try this and a few variations but the result was much more code due to having to check more edge cases due to the input being raw bytes. In the end the cleaned up while loop proved more robust.- Changelog:
+ V2: https://lore.kernel.org/platform-driver-x86/[email protected]/T/#t
- Adjust warning message to explicitly mention suspend issues
- Use switch/case block to setmin_version
- Setmin_versionto 0 by default and toggle hacks off
+ V3
- Remove noise (excesspr_info)
- Use kstrtoint, not kstrtolong
- Use__free(kfree)for allocated mem and drop goto + logging
- Useprint_hex_dump()to show failed data afterpr_errinmcu_request_version()
- Usepr_debuginset_ally_mcu_hack()andset_ally_mcu_powersave()plus correct the message.
Quoted 8 lines
Luke D. Jones (2):
hid-asus: check ROG Ally MCU version and warn platform/x86: asus-wmi: Refactor Ally suspend/resumedrivers/hid/hid-asus.c | 111 +++++++++++++++++- drivers/platform/x86/asus-wmi.c | 130 ++++++++++++++------- include/linux/platform_data/x86/asus-wmi.h | 15 +++ 3 files changed, 215 insertions(+), 41 deletions(-)
Hans, are you OK taking both patches through your tree?
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs
Ilpo Järvinen
maintainerQuoted 37 lines · Jiri Kosina
Quoted 35 lines · Luke Jones
This short series refactors the Ally suspend/resume functionality in the asus-wmi driver along with adding support for ROG Ally MCU version checking.
The version checking is then used to toggle the use of older CSEE call hacks that were initially used to combat Ally suspend/wake issues arising from the MCU not clearing a particular flag on resume. ASUS have since corrected this especially for Linux in newer firmware versions.
- hid-asus requests the MCU version and displays a warning if the version is older than the one that fixes the issue.
- hid-asus awill also toggle the CSEE hack off, andmcu_powersaveto on if the version is high enough.*Note: In review it was requested by Mario that I try
strsep()for parsing the version. I did try this and a few variations but the result was much more code due to having to check more edge cases due to the input being raw bytes. In the end the cleaned up while loop proved more robust.- Changelog:
+ V2: https://lore.kernel.org/platform-driver-x86/[email protected]/T/#t
- Adjust warning message to explicitly mention suspend issues
- Use switch/case block to setmin_version
- Setmin_versionto 0 by default and toggle hacks off
+ V3
- Remove noise (excesspr_info)
- Use kstrtoint, not kstrtolong
- Use__free(kfree)for allocated mem and drop goto + logging
- Useprint_hex_dump()to show failed data afterpr_errinmcu_request_version()
- Usepr_debuginset_ally_mcu_hack()andset_ally_mcu_powersave()plus correct the message.Luke D. Jones (2):
hid-asus: check ROG Ally MCU version and warn platform/x86: asus-wmi: Refactor Ally suspend/resume
Quoted 6 lines
Quoted 4 lines
drivers/hid/hid-asus.c | 111 +++++++++++++++++- drivers/platform/x86/asus-wmi.c | 130 ++++++++++++++------- include/linux/platform_data/x86/asus-wmi.h | 15 +++ 3 files changed, 215 insertions(+), 41 deletions(-)Hans, are you OK taking both patches through your tree?
Yes, I can take them both.
Signature · 1 line
i.