Commit 07f5ed0e authored by Matan Ziv-Av's avatar Matan Ziv-Av Committed by Hans de Goede

lg-laptop: Move setting of battery charge limit to common location

For now leave also the driver specific location,
with deprecated warning in documentation.
Signed-off-by: default avatarMatan Ziv-Av <matan@svgalib.org>
Link: https://lore.kernel.org/r/eca2fa354f60b8a6e5a5c9c8e244fea56616970a.1645278914.git.matan@svgalib.orgReviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent 4b1be2fe
...@@ -17,6 +17,7 @@ Date: October 2018 ...@@ -17,6 +17,7 @@ Date: October 2018
KernelVersion: 4.20 KernelVersion: 4.20
Contact: "Matan Ziv-Av <matan@svgalib.org> Contact: "Matan Ziv-Av <matan@svgalib.org>
Description: Description:
Deprecated use /sys/class/power_supply/CMB0/charge_control_end_threshold
Maximal battery charge level. Accepted values are 80 or 100. Maximal battery charge level. Accepted values are 80 or 100.
What: /sys/devices/platform/lg-laptop/fan_mode What: /sys/devices/platform/lg-laptop/fan_mode
......
...@@ -38,7 +38,7 @@ FN lock. ...@@ -38,7 +38,7 @@ FN lock.
Battery care limit Battery care limit
------------------ ------------------
Writing 80/100 to /sys/devices/platform/lg-laptop/battery_care_limit Writing 80/100 to /sys/class/power_supply/CMB0/charge_control_end_threshold
sets the maximum capacity to charge the battery. Limiting the charge sets the maximum capacity to charge the battery. Limiting the charge
reduces battery capacity loss over time. reduces battery capacity loss over time.
......
...@@ -915,6 +915,7 @@ config COMPAL_LAPTOP ...@@ -915,6 +915,7 @@ config COMPAL_LAPTOP
config LG_LAPTOP config LG_LAPTOP
tristate "LG Laptop Extras" tristate "LG Laptop Extras"
depends on ACPI depends on ACPI
depends on ACPI_BATTERY
depends on ACPI_WMI depends on ACPI_WMI
depends on INPUT depends on INPUT
select INPUT_SPARSEKMAP select INPUT_SPARSEKMAP
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/types.h> #include <linux/types.h>
#include <acpi/battery.h>
#define LED_DEVICE(_name, max, flag) struct led_classdev _name = { \ #define LED_DEVICE(_name, max, flag) struct led_classdev _name = { \
.name = __stringify(_name), \ .name = __stringify(_name), \
.max_brightness = max, \ .max_brightness = max, \
...@@ -458,14 +460,14 @@ static ssize_t fn_lock_show(struct device *dev, ...@@ -458,14 +460,14 @@ static ssize_t fn_lock_show(struct device *dev,
return sysfs_emit(buffer, "%d\n", status); return sysfs_emit(buffer, "%d\n", status);
} }
static ssize_t battery_care_limit_store(struct device *dev, static ssize_t charge_control_end_threshold_store(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buffer, size_t count) const char *buf, size_t count)
{ {
unsigned long value; unsigned long value;
int ret; int ret;
ret = kstrtoul(buffer, 10, &value); ret = kstrtoul(buf, 10, &value);
if (ret) if (ret)
return ret; return ret;
...@@ -486,9 +488,9 @@ static ssize_t battery_care_limit_store(struct device *dev, ...@@ -486,9 +488,9 @@ static ssize_t battery_care_limit_store(struct device *dev,
return -EINVAL; return -EINVAL;
} }
static ssize_t battery_care_limit_show(struct device *dev, static ssize_t charge_control_end_threshold_show(struct device *device,
struct device_attribute *attr, struct device_attribute *attr,
char *buffer) char *buf)
{ {
unsigned int status; unsigned int status;
union acpi_object *r; union acpi_object *r;
...@@ -520,15 +522,52 @@ static ssize_t battery_care_limit_show(struct device *dev, ...@@ -520,15 +522,52 @@ static ssize_t battery_care_limit_show(struct device *dev,
if (status != 80 && status != 100) if (status != 80 && status != 100)
status = 0; status = 0;
return sysfs_emit(buffer, "%d\n", status); return sysfs_emit(buf, "%d\n", status);
}
static ssize_t battery_care_limit_show(struct device *dev,
struct device_attribute *attr,
char *buffer)
{
return charge_control_end_threshold_show(dev, attr, buffer);
}
static ssize_t battery_care_limit_store(struct device *dev,
struct device_attribute *attr,
const char *buffer, size_t count)
{
return charge_control_end_threshold_store(dev, attr, buffer, count);
} }
static DEVICE_ATTR_RW(fan_mode); static DEVICE_ATTR_RW(fan_mode);
static DEVICE_ATTR_RW(usb_charge); static DEVICE_ATTR_RW(usb_charge);
static DEVICE_ATTR_RW(reader_mode); static DEVICE_ATTR_RW(reader_mode);
static DEVICE_ATTR_RW(fn_lock); static DEVICE_ATTR_RW(fn_lock);
static DEVICE_ATTR_RW(charge_control_end_threshold);
static DEVICE_ATTR_RW(battery_care_limit); static DEVICE_ATTR_RW(battery_care_limit);
static int lg_battery_add(struct power_supply *battery)
{
if (device_create_file(&battery->dev,
&dev_attr_charge_control_end_threshold))
return -ENODEV;
return 0;
}
static int lg_battery_remove(struct power_supply *battery)
{
device_remove_file(&battery->dev,
&dev_attr_charge_control_end_threshold);
return 0;
}
static struct acpi_battery_hook battery_hook = {
.add_battery = lg_battery_add,
.remove_battery = lg_battery_remove,
.name = "LG Battery Extension",
};
static struct attribute *dev_attributes[] = { static struct attribute *dev_attributes[] = {
&dev_attr_fan_mode.attr, &dev_attr_fan_mode.attr,
&dev_attr_usb_charge.attr, &dev_attr_usb_charge.attr,
...@@ -711,6 +750,7 @@ static int acpi_add(struct acpi_device *device) ...@@ -711,6 +750,7 @@ static int acpi_add(struct acpi_device *device)
led_classdev_register(&pf_device->dev, &tpad_led); led_classdev_register(&pf_device->dev, &tpad_led);
wmi_input_setup(); wmi_input_setup();
battery_hook_register(&battery_hook);
return 0; return 0;
...@@ -728,6 +768,7 @@ static int acpi_remove(struct acpi_device *device) ...@@ -728,6 +768,7 @@ static int acpi_remove(struct acpi_device *device)
led_classdev_unregister(&tpad_led); led_classdev_unregister(&tpad_led);
led_classdev_unregister(&kbd_backlight); led_classdev_unregister(&kbd_backlight);
battery_hook_unregister(&battery_hook);
wmi_input_destroy(); wmi_input_destroy();
platform_device_unregister(pf_device); platform_device_unregister(pf_device);
pf_device = NULL; pf_device = NULL;
......
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