platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 1/3] platform/x86: lg-laptop: Support for battery charge limit on newer models
  2021-08-18 13:05 [PATCH V2 0/3] lg-laptop: Support new models and correct events for FN keys Matan Ziv-Av
@ 2021-08-18  9:25 ` Matan Ziv-Av
  2021-08-18  9:34 ` [PATCH V2 2/3] platform/x86: lg-laptop: Use correct event for touchpad toggle FN-key Matan Ziv-Av
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Matan Ziv-Av @ 2021-08-18  9:25 UTC (permalink / raw)
  To: Platform Driver; +Cc: Hans de Goede

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.

Signed-off-by: Matan Ziv-Av <matan@svgalib.org>
---
 drivers/platform/x86/lg-laptop.c | 75 ++++++++++++++++++++++++++++----
 1 file changed, 66 insertions(+), 9 deletions(-)

diff --git a/drivers/platform/x86/lg-laptop.c b/drivers/platform/x86/lg-laptop.c
index 20145b539335..c78efeee1c19 100644
--- a/drivers/platform/x86/lg-laptop.c
+++ b/drivers/platform/x86/lg-laptop.c
@@ -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)
-- 
Matan.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH V2 2/3] platform/x86: lg-laptop: Use correct event for touchpad toggle FN-key
  2021-08-18 13:05 [PATCH V2 0/3] lg-laptop: Support new models and correct events for FN keys Matan Ziv-Av
  2021-08-18  9:25 ` [PATCH V2 1/3] platform/x86: lg-laptop: Support for battery charge limit on newer models Matan Ziv-Av
@ 2021-08-18  9:34 ` Matan Ziv-Av
  2021-08-18 12:47 ` [PATCH V2 3/3] platform/x86: lg-laptop: Use correct event for keyboard backlight FN-key Matan Ziv-Av
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Matan Ziv-Av @ 2021-08-18  9:34 UTC (permalink / raw)
  To: Platform Driver; +Cc: Hans de Goede

Send F21 which is the standard for this key, instead of F13.

Signed-off-by: Matan Ziv-Av <matan@svgalib.org>
---
 Documentation/admin-guide/laptops/lg-laptop.rst | 2 +-
 drivers/platform/x86/lg-laptop.c                | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/admin-guide/laptops/lg-laptop.rst b/Documentation/admin-guide/laptops/lg-laptop.rst
index ce9b14671cb9..13d7ec427e76 100644
--- a/Documentation/admin-guide/laptops/lg-laptop.rst
+++ b/Documentation/admin-guide/laptops/lg-laptop.rst
@@ -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.
diff --git a/drivers/platform/x86/lg-laptop.c b/drivers/platform/x86/lg-laptop.c
index c78efeee1c19..12b497a11c6f 100644
--- a/drivers/platform/x86/lg-laptop.c
+++ b/drivers/platform/x86/lg-laptop.c
@@ -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
-- 
Matan.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH V2 3/3] platform/x86: lg-laptop: Use correct event for keyboard backlight FN-key
  2021-08-18 13:05 [PATCH V2 0/3] lg-laptop: Support new models and correct events for FN keys Matan Ziv-Av
  2021-08-18  9:25 ` [PATCH V2 1/3] platform/x86: lg-laptop: Support for battery charge limit on newer models Matan Ziv-Av
  2021-08-18  9:34 ` [PATCH V2 2/3] platform/x86: lg-laptop: Use correct event for touchpad toggle FN-key Matan Ziv-Av
@ 2021-08-18 12:47 ` Matan Ziv-Av
  2021-08-18 15:34 ` [PATCH V2 0/3] lg-laptop: Support new models and correct events for FN keys Hans de Goede
  2021-08-19  6:49 ` [PATCH V2 1/3] platform/x86: lg-laptop: Support for battery charge limit on newer models peter
  4 siblings, 0 replies; 6+ messages in thread
From: Matan Ziv-Av @ 2021-08-18 12:47 UTC (permalink / raw)
  To: Platform Driver; +Cc: Hans de Goede

Use led_classdev_notify_brightness_hw_changed() instead of F16 key.

Signed-off-by: Matan Ziv-Av <matan@svgalib.org>
---
 .../admin-guide/laptops/lg-laptop.rst         |  2 --
 drivers/platform/x86/lg-laptop.c              | 30 ++++++++++++++-----
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/Documentation/admin-guide/laptops/lg-laptop.rst b/Documentation/admin-guide/laptops/lg-laptop.rst
index 13d7ec427e76..6fbe165dcd27 100644
--- a/Documentation/admin-guide/laptops/lg-laptop.rst
+++ b/Documentation/admin-guide/laptops/lg-laptop.rst
@@ -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.
diff --git a/drivers/platform/x86/lg-laptop.c b/drivers/platform/x86/lg-laptop.c
index 12b497a11c6f..3e520d5bca07 100644
--- a/drivers/platform/x86/lg-laptop.c
+++ b/drivers/platform/x86/lg-laptop.c
@@ -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      0x80
 
 static 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)
 {
-- 
Matan.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH V2 0/3] lg-laptop: Support new models and correct events for FN keys
@ 2021-08-18 13:05 Matan Ziv-Av
  2021-08-18  9:25 ` [PATCH V2 1/3] platform/x86: lg-laptop: Support for battery charge limit on newer models Matan Ziv-Av
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Matan Ziv-Av @ 2021-08-18 13:05 UTC (permalink / raw)
  To: Platform Driver; +Cc: Hans de Goede

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(-)

-- 
Matan.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V2 0/3] lg-laptop: Support new models and correct events for FN keys
  2021-08-18 13:05 [PATCH V2 0/3] lg-laptop: Support new models and correct events for FN keys Matan Ziv-Av
                   ` (2 preceding siblings ...)
  2021-08-18 12:47 ` [PATCH V2 3/3] platform/x86: lg-laptop: Use correct event for keyboard backlight FN-key Matan Ziv-Av
@ 2021-08-18 15:34 ` Hans de Goede
  2021-08-19  6:49 ` [PATCH V2 1/3] platform/x86: lg-laptop: Support for battery charge limit on newer models peter
  4 siblings, 0 replies; 6+ messages in thread
From: Hans de Goede @ 2021-08-18 15:34 UTC (permalink / raw)
  To: Matan Ziv-Av, Platform Driver

Hi,

On 8/18/21 3:05 PM, Matan Ziv-Av wrote:
> 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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V2 1/3] platform/x86: lg-laptop: Support for battery charge limit on newer models
  2021-08-18 13:05 [PATCH V2 0/3] lg-laptop: Support new models and correct events for FN keys Matan Ziv-Av
                   ` (3 preceding siblings ...)
  2021-08-18 15:34 ` [PATCH V2 0/3] lg-laptop: Support new models and correct events for FN keys Hans de Goede
@ 2021-08-19  6:49 ` peter
  4 siblings, 0 replies; 6+ messages in thread
From: peter @ 2021-08-19  6:49 UTC (permalink / raw)
  To: Matan Ziv-Av; +Cc: platform-driver-x86

On 18th Aug, 2021, Matan Ziv-Av wrote:
> 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.

> Signed-off-by: Matan Ziv-Av <matan@xxxxxxxxxxx>

You can add my
Tested-By: Peter Chubb <peter@chubb.wattle.id.au>


This works on a 2020 model Gram 17.

Peter C

--1629355715-eximdsn-1514641167--

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-08-19  7:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18 13:05 [PATCH V2 0/3] lg-laptop: Support new models and correct events for FN keys Matan Ziv-Av
2021-08-18  9:25 ` [PATCH V2 1/3] platform/x86: lg-laptop: Support for battery charge limit on newer models Matan Ziv-Av
2021-08-18  9:34 ` [PATCH V2 2/3] platform/x86: lg-laptop: Use correct event for touchpad toggle FN-key Matan Ziv-Av
2021-08-18 12:47 ` [PATCH V2 3/3] platform/x86: lg-laptop: Use correct event for keyboard backlight FN-key Matan Ziv-Av
2021-08-18 15:34 ` [PATCH V2 0/3] lg-laptop: Support new models and correct events for FN keys Hans de Goede
2021-08-19  6:49 ` [PATCH V2 1/3] platform/x86: lg-laptop: Support for battery charge limit on newer models peter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).