lg-laptop: Support new models and correct events for FN keys
Subsystems (3)
Matan Ziv-Av
maintainerv2 cover lg-laptop: Support new models and correct events for FN keys
V2 of lg-laptop driver fixes, according to Hans de Goede's comments.
Matan Ziv-Av (3):
platform/x86: lg-laptop: Support for battery charge limit on newer
models
platform/x86: lg-laptop: Use correct event for touchpad toggle FN-key platform/x86: lg-laptop: Use correct event for keyboard backlight
FN-key
.../admin-guide/laptops/lg-laptop.rst | 4 +- drivers/platform/x86/lg-laptop.c | 107 +++++++++++++++--- 2 files changed, 90 insertions(+), 21 deletions(-)
Signature · 1 line
Matan.
Matan Ziv-Av
maintainerPATCH v2 1/3 platform/x86: lg-laptop: Support for battery charge limit on newer models
Add support for the difference between various models:
- Use dmi to detect laptop model.
- 2019 and newer models use _wmbb method to set battery charge limit.
--- drivers/platform/x86/lg-laptop.c | 75 ++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 9 deletions(-)
drivers/platform/x86/lg-laptop.c +66 -9
@@ -8,6 +8,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/acpi.h> +#include <linux/dmi.h> #include <linux/input.h> #include <linux/input/sparse-keymap.h> #include <linux/kernel.h>
@@ -69,6 +70,8 @@ static u32 inited;#define INIT_INPUT_ACPI 0x04#define INIT_SPARSE_KEYMAP 0x80 +static int battery_limit_use_wmbb; +static const struct key_entry wmi_keymap[] = { {KE_KEY ,0x70 , {KEY_F15 } },/* LG control panel (F1) */ {KE_KEY ,0x74 , {KEY_F13 } },/* Touchpad toggle (F5) */
@@ -461,7 +464,10 @@ static ssize_t battery_care_limit_store(struct device *dev,if (value ==100 || value ==80 ) {union acpi_object *r; - r =lg_wmab (WM_BATT_LIMIT ,WM_SET , value); +if (battery_limit_use_wmbb) + r =lg_wmbb (WMBB_BATT_LIMIT ,WM_SET , value); +else + r =lg_wmab (WM_BATT_LIMIT ,WM_SET , value);if (!r)return -EIO ;
@@ -479,16 +485,29 @@ static ssize_t battery_care_limit_show(struct device *dev,unsigned int status;union acpi_object *r; - r =lg_wmab (WM_BATT_LIMIT ,WM_GET ,0 ); -if (!r) -return -EIO ; +if (battery_limit_use_wmbb) { + r =lg_wmbb (WMBB_BATT_LIMIT ,WM_GET ,0 ); +if (!r) +return -EIO ; -if (r->type !=ACPI_TYPE_INTEGER ) { -kfree (r); -return -EIO ; - } +if (r->type !=ACPI_TYPE_BUFFER ) { +kfree (r); +return -EIO ; + } - status = r->integer.value; + status = r->buffer.pointer[0x10 ]; + }else { + r =lg_wmab (WM_BATT_LIMIT ,WM_GET ,0 ); +if (!r) +return -EIO ; + +if (r->type !=ACPI_TYPE_INTEGER ) { +kfree (r); +return -EIO ; + } + + status = r->integer.value; + }kfree (r);if (status !=80 && status !=100 ) status =0 ;
@@ -602,6 +621,8 @@ static struct platform_driver pf_driver = {static int acpi_add (struct acpi_device *device) {int ret; +const char *product; +int year =2017 ;if (pf_device)return 0 ;
@@ -619,6 +640,42 @@ static int acpi_add(struct acpi_device *device)pr_err ("unable to register platform device\n" ); goto out_platform_registered; } + product =dmi_get_system_info (DMI_PRODUCT_NAME ); +if (strlen (product) >4 ) +switch (product[4 ]) { +case '5' : +case '6' : + year =2016 ; +break ; +case '7' : + year =2017 ; +break ; +case '8' : + year =2018 ; +break ; +case '9' : + year =2019 ; +break ; +case '0' : +if (strlen (product) >5 ) +switch (product[5 ]) { +case 'N' : + year =2020 ; +break ; +case 'P' : + year =2021 ; +break ; +default : + year =2022 ; + } +break ; +default : + year =2019 ; + } +pr_info ("product: %s year: %d\n" , product, year); + +if (year >=2019 ) + battery_limit_use_wmbb =1 ; ret =sysfs_create_group (&pf_device->dev.kobj, &dev_attribute_group);if (ret)
Signature · 1 line
Matan.
Matan Ziv-Av
maintainerPATCH v2 2/3 platform/x86: lg-laptop: Use correct event for touchpad toggle FN-key
In reply to Matan Ziv-AvSend F21 which is the standard for this key, instead of F13.
--- Documentation/admin-guide/laptops/lg-laptop.rst | 2 +- drivers/platform/x86/lg-laptop.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Documentation/admin-guide/laptops/lg-laptop.rst +1 -1
@@ -13,7 +13,7 @@ Hotkeys The following FN keys are ignored by the kernel without this driver: - FN-F1 (LG control panel) - Generates F15 -- FN-F5 (Touchpad toggle) - Generates F13 +- FN-F5 (Touchpad toggle) - Generates F21 - FN-F6 (Airplane mode) - Generates RFKILL - FN-F8 (Keyboard backlight) - Generates F16. This key also changes keyboard backlight mode.
drivers/platform/x86/lg-laptop.c +1 -1
@@ -74,7 +74,7 @@ static int battery_limit_use_wmbb;static const struct key_entry wmi_keymap[] = { {KE_KEY ,0x70 , {KEY_F15 } },/* LG control panel (F1) */ - {KE_KEY ,0x74 , {KEY_F13 } },/* Touchpad toggle (F5) */ + {KE_KEY ,0x74 , {KEY_F21 } },/* Touchpad toggle (F5) */ {KE_KEY ,0xf020000 , {KEY_F14 } },/* Read mode (F9) */ {KE_KEY ,0x10000000 , {KEY_F16 } },/* Keyboard backlight (F8) - pressing * this key both sends an event and
Signature · 1 line
Matan.
Matan Ziv-Av
maintainerPATCH v2 3/3 platform/x86: lg-laptop: Use correct event for keyboard backlight FN-key
In reply to Matan Ziv-AvUse led_classdev_notify_brightness_hw_changed() instead of F16 key.
--- .../admin-guide/laptops/lg-laptop.rst | 2 -- drivers/platform/x86/lg-laptop.c | 30 ++++++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-)
Documentation/admin-guide/laptops/lg-laptop.rst +0 -2
@@ -15,8 +15,6 @@ The following FN keys are ignored by the kernel without this driver: - FN-F1 (LG control panel) - Generates F15 - FN-F5 (Touchpad toggle) - Generates F21 - FN-F6 (Airplane mode) - Generates RFKILL -- FN-F8 (Keyboard backlight) - Generates F16. - This key also changes keyboard backlight mode. - FN-F9 (Reader mode) - Generates F14 The rest of the FN keys work without a need for a special driver.
drivers/platform/x86/lg-laptop.c +22 -8
@@ -17,11 +17,12 @@#include <linux/platform_device.h> #include <linux/types.h> -#define LED_DEVICE (_name, max) struct led_classdev _name = { \ +#define LED_DEVICE (_name, max, flag) struct led_classdev _name = { \ .name = __stringify(_name), \ .max_brightness = max, \ .brightness_set = _name##_set, \ .brightness_get = _name##_get, \ + .flags = flag, \ }MODULE_AUTHOR ("Matan Ziv-Av" );
@@ -71,6 +72,8 @@ static u32 inited;#define INIT_SPARSE_KEYMAP 0x80static int battery_limit_use_wmbb; +static struct led_classdev kbd_backlight; +static enum led_brightness get_kbd_backlight_level (void );static const struct key_entry wmi_keymap[] = { {KE_KEY ,0x70 , {KEY_F15 } },/* LG control panel (F1) */
@@ -217,10 +220,16 @@ static void wmi_notify(u32 value, void *context)int eventcode = obj->integer.value;struct key_entry *key; - key = -sparse_keymap_entry_from_scancode (wmi_input_dev, eventcode); -if (key && key->type ==KE_KEY ) -sparse_keymap_report_entry (wmi_input_dev, key,1 , true); +if (eventcode ==0x10000000 ) { +led_classdev_notify_brightness_hw_changed ( + &kbd_backlight,get_kbd_backlight_level ()); + }else { + key =sparse_keymap_entry_from_scancode ( + wmi_input_dev, eventcode); +if (key && key->type ==KE_KEY ) +sparse_keymap_report_entry (wmi_input_dev, + key,1 , true); + } } pr_debug("Type: %i Eventcode: 0x%llx\n", obj->type,
@@ -548,7 +557,7 @@ static enum led_brightness tpad_led_get(struct led_classdev *cdev)return ggov (GOV_TLED ) >0 ?LED_ON :LED_OFF ; } -static LED_DEVICE(tpad_led, 1); +static LED_DEVICE(tpad_led, 1, 0);static void kbd_backlight_set (struct led_classdev *cdev,enum led_brightness brightness)
@@ -565,7 +574,7 @@ static void kbd_backlight_set(struct led_classdev *cdev,kfree (r); } -static enum led_brightness kbd_backlight_get (struct led_classdev *cdev) +static enum led_brightness get_kbd_backlight_level (void ) {union acpi_object *r;int val;
@@ -596,7 +605,12 @@ static enum led_brightness kbd_backlight_get(struct led_classdev *cdev)return val; } -static LED_DEVICE(kbd_backlight, 255); +static enum led_brightness kbd_backlight_get (struct led_classdev *cdev) +{ +return get_kbd_backlight_level (); +} + +static LED_DEVICE(kbd_backlight, 255, LED_BRIGHT_HW_CHANGED);static void wmi_input_destroy (void ) {
Signature · 1 line
Matan.
Hi,
Quoted 8 lines · Matan Ziv-Av
V2 of lg-laptop driver fixes, according to Hans de Goede's comments.
Matan Ziv-Av (3):
platform/x86: lg-laptop: Support for battery charge limit on newer
models
platform/x86: lg-laptop: Use correct event for touchpad toggle FN-key platform/x86: lg-laptop: Use correct event for keyboard backlight
FN-key
Thank you for your patch-series, I've applied the series to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans
Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.
Regards,
Hans
Re: [PATCH V2 1/3] platform/x86: lg-laptop: Support for battery charge limit on newer models
In reply to Matan Ziv-AvQuoted 6 lines · Matan Ziv-Av
Add support for the difference between various models:
- Use dmi to detect laptop model.
- 2019 and newer models use_wmbbmethod to set battery charge limit.Signed-off-by Matan Ziv-Av <matan@xxxxxxxxxxx>
You can add my
This works on a 2020 model Gram 17.
Peter C
--1629355715-eximdsn-1514641167--