thinkad_acpi: Support the battery wear control
Subsystems (3)
PATCH v2 1/1 thinkad_acpi: Support the battery wear control
Add support for the ACPI batteries on newer thinkpad models (>Sandy Bridge) that support the setting of start and stop thresholds.
The actual interface to the driver is a extension for the existing ACPI battery driver. This was done so that users can write transparently to the interface of the ACPI battery driver and dont have to use some private interface (for ex. /sys/devices/platform/thinkpad_acpi/).
Two new interfaces are created:
/sys/class/power_supply/BAT{0,1}/charge_start_threshold /sys/class/power_supply/BAT{0,1}/charge_stop_threshold
The ACPI battery driver won't expose the interface unless DMI says that the machine is a Lenovo ThinkPad. This was done so that distributions that distribute thinkpad_acpi don't expose the API on non-ThinkPad laptops.
v2: Forgot to signoff, fixed that
--- Documentation/laptops/thinkpad-acpi.txt | 16 ++ drivers/acpi/battery.c | 227 +++++++++++++++++++ drivers/platform/x86/Kconfig | 11 + drivers/platform/x86/thinkpad_acpi.c | 376 ++++++++++++++++++++++++++++++++ include/linux/thinkpad_acpi.h | 16 ++ 5 files changed, 646 insertions(+)
Documentation/laptops/thinkpad-acpi.txt +16 -0
@@ -46,6 +46,7 @@ detailed description): - Fan control and monitoring: fan speed, fan enable/disable - WAN enable and disable - UWB enable and disable + - Battery Wear Control (BWC) A compatibility table by model and feature is maintained on the web site, http://ibm-acpi.sf.net/. I appreciate any success or failure
@@ -1376,6 +1377,21 @@ For more details about which buttons will appear depending on the mode, please review the laptop's user guide: http://www.lenovo.com/shop/americas/content/user_guides/x1carbon_2_ug_en.pdf +Battey Wear Control (BWC) +------------------------- + +The driver supports control for the embedded controller ACPI battery configuration. +This means that you can set start and stop charge thresholds for batteries in +ThinkPads that have a processor newer than Sandy Bridge. + +The actual sysfs interface is an extension of the standard ACPI battery interface. +The interface is usually in: + +Start thresholds: /sys/class/power_supply/BATN/charge_start_threshold +Stop threshold: /sys/class/power_supply/BATN/charge_stop_threshold + +These attributes support reading and writing. + Multiple Commands, Module Parameters ------------------------------------
drivers/acpi/battery.c +227 -0
269 lines not on this page · raw message
drivers/platform/x86/Kconfig +11 -0
@@ -532,6 +532,17 @@ config THINKPAD_ACPI_HOTKEY_POLL If you are not sure, say Y here. The driver enables polling only if it is strictly necessary to do so. +config THINKPAD_ACPI_BWC + bool "Support for the ThinkPad Battery Wear Control (BWC)" + depends on THINKPAD_ACPI + depends on ACPI_BATTERY + default y + ---help--- + Most ThinkPad models have support for the wear leveling system + designed by Lenovo. This system enables battery recalibration + and setting of the start and stop charge thresholds. This add + attributes under /sys/class/power_supply/BAT*. + config SENSORS_HDAPS tristate "Thinkpad Hard Drive Active Protection System (hdaps)" depends on INPUT
drivers/platform/x86/thinkpad_acpi.c +376 -0
394 lines not on this page · raw message
include/linux/thinkpad_acpi.h +16 -0
@@ -11,6 +11,22 @@ enum { TPACPI_LED_MAX, }; +#ifdef CONFIG_THINKPAD_ACPI_BWC + +enum { +TPACPI_BATTERY_ANY =0 , +TPACPI_BATTERY_PRIMARY =1 , +TPACPI_BATTERY_SECONDARY =2 +}; + +int tpacpi_battery_get_functionality (void ); +int tpacpi_get_start_threshold (int battery,int * res); +int tpacpi_get_stop_threshold (int battery,int * res); +int tpacpi_set_start_threshold (int battery,int value); +int tpacpi_set_stop_threshold (int battery,int value); + +#endif +int tpacpi_led_set (int whichled,bool on);#endif
Signature · 1 line
2.7.4
Quoted 86 lines · CET Ognjen Galic
Add support for the ACPI batteries on newer thinkpad models (>Sandy Bridge) that support the setting of start and stop thresholds.
The actual interface to the driver is a extension for the existing ACPI battery driver. This was done so that users can write transparently to the interface of the ACPI battery driver and dont have to use some private interface (for ex.
/sys/devices/platform/thinkpad_acpi/).Two new interfaces are created:
/sys/class/power_supply/BAT{0,1}/charge_start_threshold/sys/class/power_supply/BAT{0,1}/charge_stop_thresholdThe ACPI battery driver won't expose the interface unless DMI says that the machine is a Lenovo ThinkPad. This was done so that distributions that distribute
thinkpad_acpidon't expose the API on non-ThinkPad laptops.v2: Forgot to signoff, fixed that
Signed-off-by Ognjen Galic <[email protected]>--- Documentation/laptops/thinkpad-acpi.txt | 16 ++ drivers/acpi/battery.c | 227 +++++++++++++++++++ drivers/platform/x86/Kconfig | 11 + drivers/platform/x86/thinkpad_acpi.c | 376 ++++++++++++++++++++++++++++++++ include/linux/thinkpad_acpi.h | 16 ++ 5 files changed, 646 insertions(+)Documentation/laptops/thinkpad-acpi.txt +16
-0@@ -46,6 +46,7 @@ detailed description): - Fan control and monitoring: fan speed, fan enable/disable - WAN enable and disable - UWB enable and disable + - Battery Wear Control (BWC) A compatibility table by model and feature is maintained on the web site, http://ibm-acpi.sf.net/. I appreciate any success or failure@@ -1376,6 +1377,21 @@ For more details about which buttons will appear depending on the mode, please review the laptop's user guide: http://www.lenovo.com/shop/americas/content/user_guides/x1carbon_2_ug_en.pdf +Battey Wear Control (BWC) +------------------------- + +The driver supports control for the embedded controller ACPI battery configuration. +This means that you can set start and stop charge thresholds for batteries in +ThinkPads that have a processor newer than Sandy Bridge. + +The actual sysfs interface is an extension of the standard ACPI battery interface. +The interface is usually in: + +Start thresholds: /sys/class/power_supply/BATN/charge_start_threshold +Stop threshold: /sys/class/power_supply/BATN/charge_stop_threshold + +These attributes support reading and writing. + Multiple Commands, Module Parameters ------------------------------------drivers/acpi/battery.c +2
-0@@ -41,6 +41,7 @@#include <linux/acpi.h> #include <linux/power_supply.h> +#include <linux/thinkpad_acpi.h> #include "battery.h" @@ -70,6 +71,7 @@ static async_cookie_t async_cookie;static bool battery_driver_registered;static int battery_bix_broken_package;static int battery_notification_delay_ms; +static int has_thinkpad_extension =0 ;static unsigned int cache_time =1000 ;module_param (cache_time, uint,0644 );MODULE_PARM_DESC (cache_time,"cache time in milliseconds" );
drivers/acpi/battery.c static const struct device_attribute alarm_attr = { · line 635
Quoted 8 lines
drivers/acpi/battery.c +5
-0@@ -626,6 +628,189 @@ static const struct device_attribute alarm_attr = { .store = acpi_battery_alarm_store, }; +/* -------------------------------------------------------------------------- +ThinkPad Battery Wear Control ACPI Extension +-------------------------------------------------------------------------- */ + +#ifdef CONFIG_THINKPAD_ACPI_BWC
Not really.
This is generic code, so no thinkpad_acpi-specific stuff in this file, please, even under #ifdefs.
Quoted 4 lines
drivers/acpi/battery.c +4
-0+ +/* +* Because the thinkpad_acpi module usually is loaded right after +* the disk is mounted, we will lazy-load it on demand when any of the
drivers/acpi/battery.c static const struct device_attribute alarm_attr = { · line 649
Quoted 10 lines
drivers/acpi/battery.c +10
-0+* sysfs methods is read or written if it is not loaded. +*/ +static int thinkpad_acpi_lazyload (void ) +{ +void * func; + + func =symbol_get (tpacpi_battery_get_functionality); + +if (func) { +// thinkpad_acpi is loaded
Please clean up these comments (they should be in C format and formatted as described in the coding style doc).
drivers/acpi/battery.c static const struct device_attribute alarm_attr = { · line 651
Quoted 2 lines
drivers/acpi/battery.c +2
-0+return 0 ; + }
Thanks,
Rafael
Re: [PATCH v2] thinkpad_acpi: Support the battery wear control
Quoted 5 lines · Rafael J. Wysocki
Not really.
This is generic code, so no thinkpad_acpi-specific stuff in this file, please, even under #ifdefs.
I have some ideas, and I want your confirmation if that would be acceptable.
Can I do this:
Expose a new API from battery.c for platform specific hooks:
struct battery_hook {
int (*add_battery)(struct acpi_battery* battery);
int (*remove_battery)(struct acpi_battery *battery);
};battery_hook_register(struct battery_hook *hook) battery_hook_unregister(struct battery_hook *hook)
When that hook is invoked from some other module, battery.c calls the add_battery method for each battery that is added and remove_battery for each battery that is removed.
battery.c would keep a list of the battery_hook structs and invoke the add_battery and remove_battery methods as batteries get added and removed.
With this API, we can add more hooks for battery features in the future, not just the ThinkPad hooks.
I hope you like the proposal :)
Re: [PATCH v2] thinkpad_acpi: Support the battery wear control
Hi!
In newer series (I can't find it at the moment, sorry) you return "NOT_CHARGING" status when not charging because of wear control.
Maybe we should have separate status "not charging due to wear control"?
Thanks,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH v2] thinkpad_acpi: Support the battery wear control
Quoted 1 line · Pavel Machek
In newer series (I can't find it at the moment, sorry)
The new series is a 3-patch patchset that obsoletes this patch. It is in the testing stage and will be pushed to the mailing lists and maintainers in a few days.
Quoted 2 lines
Maybe we should have separate status "not charging due to wear control"?
No, because the ACPI battery driver is a extension to the generic power supply driver, that does not understand the battery wear control. Also, Rafael specifically noted NOT to include any thinkpad_acpi-specific behavior to the generic drivers.
That behavior you are describing can be implemented in the userspace.
Thanks for the time!
Ognjen
Re: [PATCH v2] thinkpad_acpi: Support the battery wear control
Quoted 7 lines · Ognjen Galić
Quoted 1 line · Pavel Machek
In newer series (I can't find it at the moment, sorry)
The new series is a 3-patch patchset that obsoletes this patch. It is in the testing stage and will be pushed to the mailing lists and maintainers in a few days.
Quoted 7 lines
Quoted 2 lines
Maybe we should have separate status "not charging due to wear control"?
No, because the ACPI battery driver is a extension to the generic power supply driver, that does not understand the battery wear control. Also, Rafael specifically noted NOT to include any thinkpad_acpi-specific behavior to the generic drivers.
Yeah, what I'm saying is that maybe we need to extend generic power supply driver.
On small devices, we usually have enough control over hardware to be able to implement "wear control" in kernel. Nokia N900 is an example. "Wear control" is certainly not thinkpad-specific concept.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH v2] thinkpad_acpi: Support the battery wear control
Quoted 2 lines · Pavel Machek
Yeah, what I'm saying is that maybe we need to extend generic power supply driver.
I don't know about that, you would have to ask the maintainers if that is appropriate.
Thanks for the time!
Ognjen
Quoted 10 lines · Ognjen Galic
Add support for the ACPI batteries on newer thinkpad models (>Sandy Bridge) that support the setting of start and stop thresholds.
The actual interface to the driver is a extension for the existing ACPI battery driver. This was done so that users can write transparently to the interface of the ACPI battery driver and dont have to use some private interface (for ex.
/sys/devices/platform/thinkpad_acpi/).
Quoted 4 lines
Two new interfaces are created:
/sys/class/power_supply/BAT{0,1}/charge_start_threshold/sys/class/power_supply/BAT{0,1}/charge_stop_threshold
Just tried this on my X1 Carbon (i7-3667U Ivy Lake):
# cat /sys/class/power_supply/BAT0/charge_stop_threshold 100 # cat /sys/class/power_supply/BAT0/charge_start_threshold 100
That doesn't seem to make any sense. Is my battery somehow reporting false values here? Any way to cross check these values?
--
Regards,
Christoph
Quoted 18 lines · Christoph Böhmwalder
Quoted 10 lines · Ognjen Galic
Add support for the ACPI batteries on newer thinkpad models (>Sandy Bridge) that support the setting of start and stop thresholds.
The actual interface to the driver is a extension for the existing ACPI battery driver. This was done so that users can write transparently to the interface of the ACPI battery driver and dont have to use some private interface (for ex.
/sys/devices/platform/thinkpad_acpi/).Quoted 4 lines
Two new interfaces are created:
/sys/class/power_supply/BAT{0,1}/charge_start_threshold/sys/class/power_supply/BAT{0,1}/charge_stop_thresholdJust tried this on my X1 Carbon (i7-3667U Ivy Lake):
Quoted 7 lines
# cat /sys/class/power_supply/BAT0/charge_stop_threshold 100 # cat /sys/class/power_supply/BAT0/charge_start_threshold 100That doesn't seem to make any sense. Is my battery somehow reporting false values here? Any way to cross check these values?
It means that both values are 0 (default). The first one is wrongly mapped to 100, but should probably be reported as 0.
Also, the values are not mangled correctly when writing: 100 as a stop threshold should be written as 0, and and 100 as a start threshold should be illegal, giving you:
start = [0, 99] stop = [1, 100]
Which is what my patch series a few years ago implemented. I never got to integrate that with the acpi battery driver, though.
Signature · 2 lines
debian developer - deb.li/jak | jak-linux.org - free software dev ubuntu core developer i speak de, en