-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0001-HID-asus-Expose-WMI-RGB-state-control-via-sysfs.patch
More file actions
100 lines (92 loc) · 3.42 KB
/
0001-HID-asus-Expose-WMI-RGB-state-control-via-sysfs.patch
File metadata and controls
100 lines (92 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
From fde742b9209e9b03bc147c4b4a9ca1a608c34018 Mon Sep 17 00:00:00 2001
From: Mike Lothian <mike@fireburn.co.uk>
Date: Sat, 20 Dec 2025 11:59:31 +0000
Subject: [PATCH] HID: asus: Expose WMI RGB state control via sysfs
Some ASUS ROG and TUF laptops use the hid-asus driver for keyboard backlight brightness control but rely on the ACPI WMI interface for configuring RGB specific states (such as behavior during boot, sleep, or awake).
Previously, these controls were only available if asus-wmi managed the backlight. This patch adds the kbd_rgb_state sysfs attribute to the asus::kbd_backlight LED class device managed by hid-asus. This bridges the gap, allowing userspace to configure RGB flags (cmd, boot, awake, sleep, keyboard) via WMI even when the backlight brightness is managed via HID.
The implementation:
Adds kbd_rgb_state_store which mirrors the logic found in drivers/platform/x86/asus-wmi.c.
Checks for the presence of ASUS_WMI_DEVID_TUF_RGB_STATE using the WMI DSTS method.
Conditionally attaches the attribute group to the LED class device if the WMI method is present.
Signed-off-by: Mike Lothian <mike@fireburn.co.uk>
---
drivers/hid/hid-asus.c | 60 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c
index 472bca54642b..c95f024d83e6 100644
--- a/drivers/hid/hid-asus.c
+++ b/drivers/hid/hid-asus.c
@@ -631,6 +631,58 @@ static void validate_mcu_fw_version(struct hid_device *hdev, int idProduct)
}
}
+static ssize_t kbd_rgb_state_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ u32 flags, cmd, boot, awake, sleep, keyboard;
+ int err;
+
+ if (sscanf(buf, "%d %d %d %d %d", &cmd, &boot, &awake, &sleep, &keyboard) != 5)
+ return -EINVAL;
+
+ if (cmd)
+ cmd = BIT(2);
+
+ flags = 0;
+ if (boot)
+ flags |= BIT(1);
+ if (awake)
+ flags |= BIT(3);
+ if (sleep)
+ flags |= BIT(5);
+ if (keyboard)
+ flags |= BIT(7);
+
+ /* 0xbd is the required default arg0 for the method. Nothing happens otherwise */
+ err = asus_wmi_evaluate_method(ASUS_WMI_METHODID_DEVS,
+ ASUS_WMI_DEVID_TUF_RGB_STATE,
+ 0xbd | cmd << 8 | (flags << 16), NULL);
+ if (err)
+ return err;
+
+ return count;
+}
+static DEVICE_ATTR_WO(kbd_rgb_state);
+
+static DEVICE_STRING_ATTR_RO(kbd_rgb_state_index, 0444,
+ "cmd boot awake sleep keyboard");
+
+static struct attribute *kbd_rgb_state_attrs[] = {
+ &dev_attr_kbd_rgb_state.attr,
+ &dev_attr_kbd_rgb_state_index.attr.attr,
+ NULL,
+};
+
+static const struct attribute_group kbd_rgb_state_group = {
+ .attrs = kbd_rgb_state_attrs,
+};
+
+static const struct attribute_group *asus_kbd_rgb_groups[] = {
+ &kbd_rgb_state_group,
+ NULL,
+};
+
static int asus_kbd_register_leds(struct hid_device *hdev)
{
struct asus_drvdata *drvdata = hid_get_drvdata(hdev);
@@ -699,6 +751,14 @@ static int asus_kbd_register_leds(struct hid_device *hdev)
INIT_WORK(&drvdata->kbd_backlight->work, asus_kbd_backlight_work);
spin_lock_init(&drvdata->kbd_backlight->lock);
+ if (IS_ENABLED(CONFIG_ASUS_WMI)) {
+ u32 value;
+ int ret = asus_wmi_evaluate_method(ASUS_WMI_METHODID_DSTS,
+ ASUS_WMI_DEVID_TUF_RGB_STATE, 0, &value);
+ if (ret == 0 && (value & ASUS_WMI_DSTS_PRESENCE_BIT))
+ drvdata->kbd_backlight->cdev.groups = asus_kbd_rgb_groups;
+ }
+
ret = devm_led_classdev_register(&hdev->dev, &drvdata->kbd_backlight->cdev);
if (ret < 0) {
/* No need to have this still around */
--
2.52.0