2023-11-17 01:17:02

by Luke Jones

[permalink] [raw]
Subject: [PATCH 0/2] 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(-)

--
2.42.1


2023-11-17 01:17:34

by Luke Jones

[permalink] [raw]
Subject: [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.

Signed-off-by: Denis Benato <[email protected]>
---
drivers/hid/hid-asus.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c
index fd61dba88233..b70673a929a1 100644
--- a/drivers/hid/hid-asus.c
+++ b/drivers/hid/hid-asus.c
@@ -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,
--
2.42.1

2023-11-17 01:17:47

by Luke Jones

[permalink] [raw]
Subject: [PATCH 2/2] hid-asus: reset the backlight brightness level on resume

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.

Signed-off-by: Denis Benato <[email protected]>
---
drivers/hid/hid-asus.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)

diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c
index b70673a929a1..78cdfb8b9a7a 100644
--- a/drivers/hid/hid-asus.c
+++ b/drivers/hid/hid-asus.c
@@ -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
--
2.42.1

2023-11-17 19:52:26

by Denis Benato

[permalink] [raw]
Subject: Re: [PATCH 0/2] hid-asus: reset the backlight brightness level on resume

> 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.


2023-11-21 08:52:29

by Jiri Kosina

[permalink] [raw]
Subject: Re: [PATCH 0/2] hid-asus: reset the backlight brightness level on resume

On Fri, 17 Nov 2023, Denis Benato wrote:

> > 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,

--
Jiri Kosina
SUSE Labs

2023-11-21 19:36:57

by Luke Jones

[permalink] [raw]
Subject: Re: [PATCH 0/2] hid-asus: reset the backlight brightness level on resume



On Tue, Nov 21 2023 at 09:52:11 AM +01:00:00, Jiri Kosina
<[email protected]> wrote:
> On Fri, 17 Nov 2023, Denis Benato wrote:
>
>> > 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?

Signed-off-by: Luke D. Jones <[email protected]>


2023-11-22 10:30:10

by Jiri Kosina

[permalink] [raw]
Subject: Re: [PATCH 0/2] hid-asus: reset the backlight brightness level on resume

On Wed, 22 Nov 2023, Luke Jones wrote:

> >> 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?
>
> Signed-off-by: Luke D. Jones <[email protected]>

Applied, thanks.

--
Jiri Kosina
SUSE Labs