Commit 8983bfd5 authored by Matan Ziv-Av's avatar Matan Ziv-Av Committed by Hans de Goede

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.
Signed-off-by: default avatarMatan Ziv-Av <matan@svgalib.org>
Link: https://lore.kernel.org/r/bd6922a412e50c2dcfb7ce24fc8687f577181d65.1629291912.git.matan@svgalib.orgReviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent dcfbd31e
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/acpi.h> #include <linux/acpi.h>
#include <linux/dmi.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/input/sparse-keymap.h> #include <linux/input/sparse-keymap.h>
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -69,6 +70,8 @@ static u32 inited; ...@@ -69,6 +70,8 @@ static u32 inited;
#define INIT_INPUT_ACPI 0x04 #define INIT_INPUT_ACPI 0x04
#define INIT_SPARSE_KEYMAP 0x80 #define INIT_SPARSE_KEYMAP 0x80
static int battery_limit_use_wmbb;
static const struct key_entry wmi_keymap[] = { static const struct key_entry wmi_keymap[] = {
{KE_KEY, 0x70, {KEY_F15} }, /* LG control panel (F1) */ {KE_KEY, 0x70, {KEY_F15} }, /* LG control panel (F1) */
{KE_KEY, 0x74, {KEY_F13} }, /* Touchpad toggle (F5) */ {KE_KEY, 0x74, {KEY_F13} }, /* Touchpad toggle (F5) */
...@@ -461,7 +464,10 @@ static ssize_t battery_care_limit_store(struct device *dev, ...@@ -461,7 +464,10 @@ static ssize_t battery_care_limit_store(struct device *dev,
if (value == 100 || value == 80) { if (value == 100 || value == 80) {
union acpi_object *r; 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) if (!r)
return -EIO; return -EIO;
...@@ -479,16 +485,29 @@ static ssize_t battery_care_limit_show(struct device *dev, ...@@ -479,16 +485,29 @@ static ssize_t battery_care_limit_show(struct device *dev,
unsigned int status; unsigned int status;
union acpi_object *r; union acpi_object *r;
r = lg_wmab(WM_BATT_LIMIT, WM_GET, 0); if (battery_limit_use_wmbb) {
if (!r) r = lg_wmbb(WMBB_BATT_LIMIT, WM_GET, 0);
return -EIO; if (!r)
return -EIO;
if (r->type != ACPI_TYPE_INTEGER) { if (r->type != ACPI_TYPE_BUFFER) {
kfree(r); kfree(r);
return -EIO; 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); kfree(r);
if (status != 80 && status != 100) if (status != 80 && status != 100)
status = 0; status = 0;
...@@ -602,6 +621,8 @@ static struct platform_driver pf_driver = { ...@@ -602,6 +621,8 @@ static struct platform_driver pf_driver = {
static int acpi_add(struct acpi_device *device) static int acpi_add(struct acpi_device *device)
{ {
int ret; int ret;
const char *product;
int year = 2017;
if (pf_device) if (pf_device)
return 0; return 0;
...@@ -619,6 +640,42 @@ static int acpi_add(struct acpi_device *device) ...@@ -619,6 +640,42 @@ static int acpi_add(struct acpi_device *device)
pr_err("unable to register platform device\n"); pr_err("unable to register platform device\n");
goto out_platform_registered; 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); ret = sysfs_create_group(&pf_device->dev.kobj, &dev_attribute_group);
if (ret) if (ret)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment