Skip to contentSkip to conversation

hid-asus: reset the backlight brightness level on resume

PATCH Applied Luke D. Jones 3 participants 7 messages Nov 17, 2023 – Nov 22, 2023 HID

lore
Share & tools
lore
#0 lore raw

cover hid-asus: reset the backlight brightness level on resume

From: Denis Benato <[email protected]>

I have noticed that in my Asus device RC71L the keyboard backlight is LEDs brightness of two RGB rings around two joysticks of this handheld device.

The firmware on this device (and other devices from the same manufacturer) restores a default brightness level (that is full brightness for my device and off for some others) after resuming from sleep; that means sysfs will report a wrong brightness level and requires human intervention to restore the desired brightness.

I have fixed aforementioned problems with this patch I am submitting.

This patch (composed of two distinct patches) compiles without warnings on both gcc and clang and also improves a function signature and constant-correctness of the kernel driver.

Denis Benato (2):
hid-asus: add const to read-only outgoing usb buffer
hid-asus: reset the backlight brightness level on resume

 drivers/hid/hid-asus.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)
Signature · 1 line
2.42.1
#1 lore raw

PATCH 1/2 hid-asus: add const to read-only outgoing usb buffer

From: Denis Benato <[email protected]>

In the function asus_kbd_set_report the parameter buf is read-only as it gets copied in a memory portion suitable for USB transfer, but the parameter is not marked as const: add the missing const and mark const immutable buffers passed to that function.

---
 drivers/hid/hid-asus.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/hid/hid-asus.c +4 -4
index fd61dba88233..b70673a929a1 100644
@@ -381,7 +381,7 @@ static int asus_raw_event(struct hid_device *hdev,
 	return 0;
 }
 
-static int asus_kbd_set_report(struct hid_device *hdev, u8 *buf, size_t buf_size)
+static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t buf_size)
 {
 	unsigned char *dmabuf;
 	int ret;
@@ -404,7 +404,7 @@ static int asus_kbd_set_report(struct hid_device *hdev, u8 *buf, size_t buf_size
 
 static int asus_kbd_init(struct hid_device *hdev)
 {
-	u8 buf[] = { FEATURE_KBD_REPORT_ID, 0x41, 0x53, 0x55, 0x53, 0x20, 0x54,
+	const u8 buf[] = { FEATURE_KBD_REPORT_ID, 0x41, 0x53, 0x55, 0x53, 0x20, 0x54,
 		     0x65, 0x63, 0x68, 0x2e, 0x49, 0x6e, 0x63, 0x2e, 0x00 };
 	int ret;
 
@@ -418,7 +418,7 @@ static int asus_kbd_init(struct hid_device *hdev)
 static int asus_kbd_get_functions(struct hid_device *hdev,
 				  unsigned char *kbd_func)
 {
-	u8 buf[] = { FEATURE_KBD_REPORT_ID, 0x05, 0x20, 0x31, 0x00, 0x08 };
+	const u8 buf[] = { FEATURE_KBD_REPORT_ID, 0x05, 0x20, 0x31, 0x00, 0x08 };
 	u8 *readbuf;
 	int ret;
 
@@ -449,7 +449,7 @@ static int asus_kbd_get_functions(struct hid_device *hdev,
 
 static int rog_nkey_led_init(struct hid_device *hdev)
 {
-	u8 buf_init_start[] = { FEATURE_KBD_LED_REPORT_ID1, 0xB9 };
+	const u8 buf_init_start[] = { FEATURE_KBD_LED_REPORT_ID1, 0xB9 };
 	u8 buf_init2[] = { FEATURE_KBD_LED_REPORT_ID1, 0x41, 0x53, 0x55, 0x53, 0x20,
 				0x54, 0x65, 0x63, 0x68, 0x2e, 0x49, 0x6e, 0x63, 0x2e, 0x00 };
 	u8 buf_init3[] = { FEATURE_KBD_LED_REPORT_ID1,
Signature · 1 line
2.42.1
#2 lore raw

PATCH 2/2 hid-asus: reset the backlight brightness level on resume

In reply to Luke D. Jones

From: Denis Benato <[email protected]>

Some devices managed by this driver automatically set brightness to 0 before entering a suspended state and reset it back to a default brightness level after the resume:
this has the effect of having the kernel report wrong brightness status after a sleep, and on some devices (like the Asus RC71L) that brightness is the intensity of LEDs directly facing the user.

Fix the above issue by setting back brightness to the level it had before entering a sleep state.

---
 drivers/hid/hid-asus.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/hid/hid-asus.c +19 -0
index b70673a929a1..78cdfb8b9a7a 100644
@@ -1000,6 +1000,24 @@ static int asus_start_multitouch(struct hid_device *hdev)
 	return 0;
 }
 
+static int __maybe_unused asus_resume(struct hid_device *hdev) {
+	struct asus_drvdata *drvdata = hid_get_drvdata(hdev);
+	int ret = 0;
+
+	if (drvdata->kbd_backlight) {
+		const u8 buf[] = { FEATURE_KBD_REPORT_ID, 0xba, 0xc5, 0xc4,
+				drvdata->kbd_backlight->cdev.brightness };
+		ret = asus_kbd_set_report(hdev, buf, sizeof(buf));
+		if (ret < 0) {
+			hid_err(hdev, "Asus failed to set keyboard backlight: %d\n", ret);
+			goto asus_resume_err;
+		}
+	}
+
+asus_resume_err:
+	return ret;
+}
+
 static int __maybe_unused asus_reset_resume(struct hid_device *hdev)
 {
 	struct asus_drvdata *drvdata = hid_get_drvdata(hdev);
@@ -1294,6 +1312,7 @@ static struct hid_driver asus_driver = {
 	.input_configured       = asus_input_configured,
 #ifdef CONFIG_PM
 	.reset_resume           = asus_reset_resume,
+	.resume					= asus_resume,
 #endif
 	.event			= asus_event,
 	.raw_event		= asus_raw_event
Signature · 1 line
2.42.1
maintainer
#4 lore raw
Quoted 6 lines · Denis Benato
Quoted 1 line

From: Denis Benato <[email protected]>

I want to express my gratitude toward Luke for his guidance and his help in submitting this fix.

I confirm those patches were sent in my behalf.

Luke, as you were in the supply chain of the patches, could you please provide Signed-off-by: tags so that I can add them into the chain?

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
author
#5 lore raw
Quoted 4 lines · Jiri Kosina
Quoted 2 lines · Denis Benato
Quoted 1 line

From: Denis Benato <[email protected]>

Quoted 8 lines
Quoted 5 lines

I want to express my gratitude toward Luke for his guidance and his
help
in submitting this fix.

I confirm those patches were sent in my behalf.

Luke, as you were in the supply chain of the patches, could you please provide Signed-off-by: tags so that I can add them into the chain?

maintainer Applied
#6 lore raw
Quoted 9 lines · Luke Jones
Quoted 7 lines
Quoted 4 lines

I want to express my gratitude toward Luke for his guidance and his help
in submitting this fix.

I confirm those patches were sent in my behalf.

Luke, as you were in the supply chain of the patches, could you please provide Signed-off-by: tags so that I can add them into the chain?

Applied, thanks.

Signature · 2 lines
Jiri Kosina
SUSE Labs