Bug 216983 - Laptop internal keyboard not working on LG UltraPC 17U70P
Summary: Laptop internal keyboard not working on LG UltraPC 17U70P
Status: RESOLVED CODE_FIX
Alias: None
Product: Drivers
Classification: Unclassified
Component: Input Devices (show other bugs)
Hardware: All Linux
: P1 blocking
Assignee: drivers_input-devices
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-01-31 18:09 UTC by Rubén Gómez
Modified: 2023-05-18 10:32 UTC (History)
1 user (show)

See Also:
Kernel Version: 6.1.8
Subsystem:
Regression: No
Bisected commit-id:


Attachments
Fix IRQ issues on keyboard for LG UltraPC 17U70P laptop for kernel 6.1.8 (964 bytes, patch)
2023-01-31 18:09 UTC, Rubén Gómez
Details | Diff

Description Rubén Gómez 2023-01-31 18:09:23 UTC
Created attachment 303667 [details]
Fix IRQ issues on keyboard for LG UltraPC 17U70P laptop for kernel 6.1.8

Hi,

just the same as is currently happening with other laptops, the keyboard in this laptop is not detected under any currently available version of Linux. Following the instructions by Tamim Khan in bug 216158, comment 5 (https://bugzilla.kernel.org/show_bug.cgi?id=216158#c5) I executed the following commands using an external USB keyboard:

cat /sys/firmware/acpi/tables/DSDT > dsdt.dat
iasl -d dsdt.dat
grep -A 40 PS2K dsdt.dsl | grep IRQ -A 1

Output:

IRQ (Level, ActiveLow, Exclusive, )
                    {1}

So as other people did, I followed the ideas behind the patches already available in that thread and created a patch for my laptop that fixed this issue for kernel 6.1.8, I'm attaching the patch to this bug report.

A second issue I discovered after applying the patch is the backlit function, the available FN+F8 key combination is not working besides FN keys are already working for screen brightness and touchpad control, ie. Inside the /sys directory there are already a set of entries available (in theory) for keyboard backlit control:

# ls -l /sys/class/leds/kbd_backlight/

-rw-r--r-- 1 root root 4096 ene 31 18:36 brightness
-r--r--r-- 1 root root 4096 ene 31 18:36 brightness_hw_changed
lrwxrwxrwx 1 root root    0 ene 31 18:52 device -> ../../../lg-laptop
-r--r--r-- 1 root root 4096 ene 31 18:36 max_brightness
drwxr-xr-x 2 root root    0 ene 31 18:52 power
lrwxrwxrwx 1 root root    0 ene 31 18:52 subsystem -> ../../../../../class/leds
-rw-r--r-- 1 root root    0 ene 31 18:52 trigger
-rw-r--r-- 1 root root 4096 ene 31 18:36 uevent

But until now I failed to turn on the backlit, using the FN key, using third party tools, or trying to write directly to those registers, ie:

# echo 255 > /sys/class/leds/kbd_backlight/brightness

(Being 255 the value of /sys/class/leds/kbd_backlight/max_brightness).
Comment 1 Tamim Khan 2023-02-04 18:34:11 UTC
@Rubén Gómez: Just to make sure there is no miscommunication in the other bug ticket. Did you want me to send this patch into the kernel mailing list on your behalf or were you going to do this yourself?

Tamim
Comment 2 Rubén Gómez 2023-02-05 12:38:58 UTC
(In reply to Tamim Khan from comment #1)
> @Rubén Gómez: Just to make sure there is no miscommunication in the other
> bug ticket. Did you want me to send this patch into the kernel mailing list
> on your behalf or were you going to do this yourself?

@Tamim Khan: Hi I was just waiting a little bit in case I could fix the backlit issue and submit a patch for both things at the same time. Do you think it should be better to go ahead and submit this patch now? If that's the case I'd very thankful if you could do that for me this time I'm a bit snowed under these days.
Comment 3 Tamim Khan 2023-02-05 14:29:27 UTC
@Rubén Gómez: Nope, I don’t think there is any rush. I was just making sure you were not waiting on me to submit it.

Let me know if you have any questions and I will try my best to answer.

Thanks,
Tamim
Comment 4 Rubén Gómez 2023-02-26 18:35:34 UTC
(In reply to Tamim Khan from comment #3)
> Nope, I don’t think there is any rush. I was just making sure
> you were not waiting on me to submit it. 
> Let me know if you have any questions and I will try my best to answer.

@Thamim Khan: I've been working in the keyboard backlit issue, I tried to pull all the tricks available in my hat (read every available doc, using Linux detection tools, tracing events in Windows, even reverse engineering) but I failed in a very frustrating way. Who'd image that nowadays turning on a led would be so freaking hard. There's a compatibility driver already in the kernel named lg-laptop.c but unfortunately is only designed for the LG Gram series and at first I thought it was partially working in my laptop, now I realized that is not working at all and the FN are being handled from elsewhere. ("modprobe -r lg-laptop" doesn't affect the available FN keys).

I'm stuck with this. :-\
Comment 5 Rubén Gómez 2023-02-26 21:59:52 UTC
(In reply to Tamim Khan from comment #3)
> Let me know if you have any questions and I will try my best to answer.

Finally I found the freaking keyboard codes! 0x80, 0xa4 and 0xa2 and it actually works!.
I need to properly implement this in the current driver but feels awesome.
Comment 6 Rubén Gómez 2023-02-28 16:06:47 UTC
I created for myself this patch to force the keyboard backlit to turn on, in every boot. Guess is not enough to send it as a patch for the current LG Gram wmi module. The issue I'm facing is, LG Gram and LG UltraPC are sharing some GUIDs so I can't develop an indepenent module for this laptop, and right now I have little info about the WMI specifications, just manager to get the keyboard scancodes trought DotPeek last weekend.

I'd appreciate some ideas about how to keep going on. 

Keyboard backlit patch:
```
diff --git a/drivers/platform/x86/lg-laptop.c b/drivers/platform/x86/lg-laptop.c
index 332868b140ed..6c80737d824b 100644
--- a/drivers/platform/x86/lg-laptop.c
+++ b/drivers/platform/x86/lg-laptop.c
@@ -241,6 +241,8 @@ static void wmi_notify(u32 value, void *context)
 static void wmi_input_setup(void)
 {
 	acpi_status status;
+	const char *product;
+	union acpi_object *r;
 
 	wmi_input_dev = input_allocate_device();
 	if (wmi_input_dev) {
@@ -265,6 +267,13 @@ static void wmi_input_setup(void)
 						    (void *)2);
 		if (ACPI_SUCCESS(status))
 			inited |= INIT_INPUT_WMI_2;
+
+		product = dmi_get_system_info(DMI_PRODUCT_NAME);
+		if (product && strlen(product) >= 6 && strncmp(product, "17U70P", 6) == 0) {
+			r = lg_wmab(WM_KEY_LIGHT, WM_SET, 0xA2);
+			kfree(r);
+			pr_info("Enabled keyboard backlight (level low) for LG UltraPC 17U70P");
+		}
 	} else {
 		pr_info("Cannot allocate input device");
 	}
```
Comment 7 Tamim Khan 2023-03-06 01:55:15 UTC
@Rubén Gómez: If you share GUIDs your best option might be to just adapt this module to work for your laptop rather than writing a new one. I did notice a bunch of code in the LG Gram module related to changing and setting the brightness of the keyboard: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/platform/x86/lg-laptop.c?h=v6.2.2#n631. Is it that your specific key codes are missing from the if/case statement or are you not even getting to this part due to the eventcode being completely different: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/platform/x86/lg-laptop.c?h=v6.2.2#n224?

I think at this point it might also be worthwhile to reach out to the author LG Gram module(Matan Ziv-Av <matan@svgalib.org>) and see his thoughts on your issues are. He will probably have better ideas then myself in regards to getting a more complete WMI specification for your laptop and if it makes more sense to make this into a new module or not.

Tamim
Comment 8 Rubén Gómez 2023-03-06 20:21:20 UTC
(In reply to Tamim Khan from comment #7)
@Tamim Khan: Many thanks for your answer and suggestions! I already tried to contact Matan on Feb 1st but with no luck, I already have the codes for sending the event to turn on the keyboard backlit (that's roughly implemented in the patch I dropped in this thread on Comment 6), what I'm missing now is the codes to catch the FN+F[x] key events (https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/platform/x86/lg-laptop.c?h=v6.2.2#n80) that seem different in my laptop as happens with the other codes (https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/platform/x86/lg-laptop.c?h=v6.2.2#n606).

Anyway with a bit more time I think I can reverse engineer the Windows drive and get all the information I need (I even tried to contact LG but radio silence).

But until then I'm thinking about sending the patch I already have to unlock the keyboard and have that upstream as soon as possible. I'm already in the linux-acpi mail list. Would that be the proper place to send it?
Comment 9 Tamim Khan 2023-03-07 05:02:46 UTC
@Rubén Gómez: Yup, linux-acpi would be the right place to send the keyboard not working patch.

Another question about your keyboard backlight problem. Are you not getting any output at all on this debug line: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/platform/x86/lg-laptop.c?h=v6.2.2#n236? It _seems_ like as long as the GUIDs for your device match the LG Gram the `wmi_notify` function should be called and that log outputted. You wont get the right event being emitted due to a lack of entry here: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/platform/x86/lg-laptop.c?h=v6.2.2#n79 but you should be able to get the eventcode from that output.

Tamim
Comment 10 Rubén Gómez 2023-03-17 10:28:29 UTC
@Tamim Khan: Hi thanks for the confirmation about the mail list, I'll try to send it this weekend. 

About the WMI events no I don't get any input (no wmi_notify calls at all), I already tried using a log in the first line of the function, I think that's related with the scan codes issue (GUIDs match, but FN+Fx scan codes don't).
Comment 11 Rubén Gómez 2023-04-28 09:20:27 UTC
@Tamim Khan: Hi Tamim I should have accepted your help to send the basic keyboard patch back in January, weeks have passed and never found the time to do this... I'm looking into it now, would be enough to send it against the current mainline kernel? (6.3) is a small change, any idea I should take into account? Thank you!
Comment 12 Tamim Khan 2023-04-28 11:09:49 UTC
@Rubén Gómez: I think the linux-acpi kernel mailing list generally wants patches that are against the linux-pm branch (https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git/). That usually contains a pre-release RC kernel for the next kernel version (it looks to be 6.4-rc1 right now).

As long as your patch can be applied to that and you follow the conventions for kernel commit messages (steps 2 onward on https://www.kernel.org/doc/html/v4.10/process/submitting-patches.html or using message format for the other keyboard patches), I think your patch should be good.

Tamim
Comment 13 Rubén Gómez 2023-05-18 10:32:25 UTC
Keyboard patch found it's way to the kernel v 6.4-rc! :-) Still pending proper WMI support tho. At least we now have codes to force the keyboard backlit to turn on. (See above).

Note You need to log in before you can comment on or make changes to this bug.