Skip to contentSkip to conversation

thinkpad_acpi: Add support for battery thresholds

PATCH Superseded Ognjen Galic 1 participant 1 message Dec 15, 2017

Subsystems (3)

v6 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 3/3 thinkpad_acpi: Add support for battery thresholds

This patch uses the new battery hooking API to add support for the ACPI battery wear control present in Lenovo ThinkPads that have >=SandyBridge processors.

thinkpad_acpi registers two new attributes for each battery:

1) Charge start threshold /sys/class/power_supply/BATN/charge_start_threshold

Valid values are [0, 99]. A value of 0 turns off the start threshold wear control.

2) Charge stop threshold /sys/class/power_supply/BATN/charge_stop_threshold

Valid values are [1, 100]. A value of 100 turns off the stop threshold wear control. This must be configured first.

This patch depends on the following patches:

"battery: Add the battery hooking API"

v2:
* Re-write the patch to make the changes in
battery.c generic as suggested by Rafael

v3:
* Fixed a bug where you could not set the stop threshold to 100% when the start threshold is 0%
* Fixed the "Not Charging" quirk to match Lenovo's BIOS Firmware specification

v4:
* Fixed a bug where you could not set the start threshold to >stop if stop was 100%

v5:
* Migrated from symbol_get to native linking,
to fix module dependencies
* Fixed a bug where unloading the module would cause a BUG inside battery
* Fixed a bug where you could unload battery before unloading thinkpad_acpi

v6:
* Fixed all the style and naming issues pointed out by Andy Shevchenko

---
 drivers/platform/x86/Kconfig         |   1 +
 drivers/platform/x86/thinkpad_acpi.c | 442 ++++++++++++++++++++++++++++++++++-
 include/linux/power_supply.h         |   2 +
 3 files changed, 444 insertions(+), 1 deletion(-)
drivers/platform/x86/Kconfig +1 -0
index 2c745e8..d705c62 100644
@@ -399,6 +399,7 @@ config SURFACE3_WMI
 config THINKPAD_ACPI
 	tristate "ThinkPad ACPI Laptop Extras"
 	depends on ACPI
+	depends on ACPI_BATTERY
 	depends on INPUT
 	depends on RFKILL || RFKILL = n
 	depends on ACPI_VIDEO || ACPI_VIDEO = n
drivers/platform/x86/thinkpad_acpi.c +441 -1

485 lines not on this page · raw message

include/linux/power_supply.h +2 -0
index 79e90b3..f0139b4 100644
@@ -371,6 +371,8 @@ devm_power_supply_register_no_ws(struct device *parent,
 extern void power_supply_unregister(struct power_supply *psy);
 extern int power_supply_powers(struct power_supply *psy, struct device *dev);
 
+#define to_power_supply(device) container_of(device, struct power_supply, dev)
+
 extern void *power_supply_get_drvdata(struct power_supply *psy);
 /* For APM emulation, think legacy userspace. */
 extern struct class *power_supply_class;
Signature · 1 line
2.7.4