On ASUS Zephyrus GA402X, make enabling auto-suspend on the keyboard optional

- On kernels before 6.9.x, default to disabling auto-suspend
- On more-recent kernels, default to enabling auto-suspend
This commit is contained in:
mexisme 2024-07-30 16:54:07 +12:00 committed by mergify[bot]
parent dfe45103b6
commit ddebede974

View file

@ -5,7 +5,11 @@
}:
let
inherit (lib) mkDefault mkIf mkMerge version versionOlder;
inherit (lib) mkDefault mkEnableOption mkIf mkMerge version versionAtLeast versionOlder;
cfg = config.hardware.asus.zephyrus.ga402x;
defaultAutosuspendEnable = if (versionAtLeast version "6.9") then true else false;
in {
imports = [
@ -18,6 +22,16 @@ in {
../../../common/pc/ssd
];
options.hardware.asus.zephyrus.ga402x = {
# Kernels earlier than 6.9 (possibly even earlier) tend to take 1-2 key-presses
# to wake-up the internal keyboard after suspending (the ASUS N-KEY USB Device).
#
# Therefore, this option disables suspend for the keyboard by default, but
# enables it for kernel 6.9.x onwards.
keyboard.autosuspend.enable = (mkEnableOption "Enable auto-suspend on the internal USB keyboard (ASUS N-KEY Device) on Zephyrus GA402X"
) // { default = defaultAutosuspendEnable; };
};
config = mkMerge [
{
# Configure basic system settings:
@ -43,15 +57,20 @@ in {
evdev:name:*:dmi:bvn*:bvr*:bd*:svnASUS*:pn*:*
KEYBOARD_KEY_ff31007c=f20
'';
extraRules = ''
# Disable auto-suspend for the ASUS N-KEY Device, i.e. USB Keyboard
# Otherwise, it will tend to take 1-2 key-presses to wake-up after suspending
ACTION=="add", SUBSYSTEM=="usb", TEST=="power/autosuspend", ATTR{idVendor}=="0b05", ATTR{idProduct}=="19b6", ATTR{power/autosuspend}="-1"
'';
};
};
}
(mkIf (! cfg.keyboard.autosuspend.enable) {
services.udev = {
extraRules = ''
# Disable auto-suspend for the ASUS N-KEY Device, i.e. USB Keyboard
# Otherwise on certain kernel-versions, it will tend to take 1-2 key-presses to wake-up after suspending
ACTION=="add", SUBSYSTEM=="usb", TEST=="power/autosuspend", ATTR{idVendor}=="0b05", ATTR{idProduct}=="19b6", ATTR{power/autosuspend}="-1"
'';
};
})
(mkIf (versionOlder version "23.11") {
# See https://asus-linux.org/wiki/nixos/ for info about some problems
# detecting the dGPU: