From: Matan Ziv-Av <matan@svgalib.org>
To: Platform Driver <platform-driver-x86@vger.kernel.org>
Cc: Andy Shevchenko <andy@infradead.org>
Subject: [PATCH] platform/x86: lg-laptop: Support for battery charge limit on newer models
Date: Sat, 14 Aug 2021 01:11:43 +0300 (IDT) [thread overview]
Message-ID: <9338b0b1-e76e-68f5-36de-a642745ba6ad@svgalib.org> (raw)
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..12b0257c0bdd 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_wmab(WM_BATT_LIMIT, WM_SET, value);
+ else
+ r = lg_wmbb(WMBB_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_wmab(WM_BATT_LIMIT, WM_GET, 0);
+ if (!r)
+ return -EIO;
- if (r->type != ACPI_TYPE_INTEGER) {
- kfree(r);
- return -EIO;
- }
+ if (r->type != ACPI_TYPE_INTEGER) {
+ kfree(r);
+ return -EIO;
+ }
- status = r->integer.value;
+ status = r->integer.value;
+ } else {
+ r = lg_wmbb(WMBB_BATT_LIMIT, WM_GET, 0);
+ if (!r)
+ return -EIO;
+
+ if (r->type != ACPI_TYPE_BUFFER) {
+ kfree(r);
+ return -EIO;
+ }
+
+ status = r->buffer.pointer[0x10];
+ }
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)
--
2.31.1
--
Matan.
next reply other threads:[~2021-08-13 22:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-13 22:11 Matan Ziv-Av [this message]
2021-08-18 7:33 ` [PATCH] platform/x86: lg-laptop: Support for battery charge limit on newer models Hans de Goede
2021-08-18 13:36 ` Matan Ziv-Av
2021-08-18 15:01 ` Barnabás Pőcze
2021-08-18 15:30 ` Hans de Goede
2021-08-18 15:31 ` Hans de Goede
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9338b0b1-e76e-68f5-36de-a642745ba6ad@svgalib.org \
--to=matan@svgalib.org \
--cc=andy@infradead.org \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).