Re: [PATCH v2] thinkad_acpi: Support the battery wear control
On Tue, Dec 05, 2017 at 03:22:28PM +0100, Christoph Böhmwalder wrote: > On Sun, Dec 03, 2017 at 11:56:40PM +0100, Ognjen Galic wrote: > > 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 > > 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? 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. -- debian developer - deb.li/jak | jak-linux.org - free software dev ubuntu core developer i speak de, en
Re: [PATCH v2] thinkad_acpi: Support the battery wear control
On Tue, Dec 05, 2017 at 03:22:28PM +0100, Christoph Böhmwalder wrote: > On Sun, Dec 03, 2017 at 11:56:40PM +0100, Ognjen Galic wrote: > > 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 > > 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? 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. -- debian developer - deb.li/jak | jak-linux.org - free software dev ubuntu core developer i speak de, en
Re: [PATCH v2] thinkad_acpi: Support the battery wear control
On Sun, Dec 03, 2017 at 11:56:40PM +0100, Ognjen Galic wrote: > 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 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
Re: [PATCH v2] thinkad_acpi: Support the battery wear control
On Sun, Dec 03, 2017 at 11:56:40PM +0100, Ognjen Galic wrote: > 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 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
Re: [PATCH v2] thinkad_acpi: Support the battery wear control
On Sunday, December 3, 2017 11:56:40 PM CET Ognjen Galic wrote: > 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 > > Signed-off-by: Ognjen Galic> --- > 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(+) > > diff --git a/Documentation/laptops/thinkpad-acpi.txt > b/Documentation/laptops/thinkpad-acpi.txt > index 00b6dfe..9aca62d 100644 > --- a/Documentation/laptops/thinkpad-acpi.txt > +++ b/Documentation/laptops/thinkpad-acpi.txt > @@ -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 > > > diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c > index 13e7b56..4852a76 100644 > --- a/drivers/acpi/battery.c > +++ b/drivers/acpi/battery.c > @@ -41,6 +41,7 @@ > > #include > #include > +#include > > #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"); > @@ -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. > + > +/* > + * 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 > + * 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). > + return 0; > +} Thanks, Rafael
Re: [PATCH v2] thinkad_acpi: Support the battery wear control
On Sunday, December 3, 2017 11:56:40 PM CET Ognjen Galic wrote: > 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 > > Signed-off-by: Ognjen Galic > --- > 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(+) > > diff --git a/Documentation/laptops/thinkpad-acpi.txt > b/Documentation/laptops/thinkpad-acpi.txt > index 00b6dfe..9aca62d 100644 > --- a/Documentation/laptops/thinkpad-acpi.txt > +++ b/Documentation/laptops/thinkpad-acpi.txt > @@ -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 > > > diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c > index 13e7b56..4852a76 100644 > --- a/drivers/acpi/battery.c > +++ b/drivers/acpi/battery.c > @@ -41,6 +41,7 @@ > > #include > #include > +#include > > #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"); > @@ -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. > + > +/* > + * 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 > + * 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). > + return 0; > +} Thanks, Rafael
[PATCH v2] 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 Signed-off-by: Ognjen Galic--- 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(+) diff --git a/Documentation/laptops/thinkpad-acpi.txt b/Documentation/laptops/thinkpad-acpi.txt index 00b6dfe..9aca62d 100644 --- a/Documentation/laptops/thinkpad-acpi.txt +++ b/Documentation/laptops/thinkpad-acpi.txt @@ -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 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 13e7b56..4852a76 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -41,6 +41,7 @@ #include #include +#include #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"); @@ -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 + +/* + * 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 + * 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 + return 0; +} + +pr_warning("battery: Lazy-loading thinkpad_acpi"); + +// thinkpad_acpi is not loaded, do lazy load +if (request_module("thinkpad_acpi")) { + return 1; +} + +return 0; +} + +static int battery_thinkpad_get_id(struct device *dev) +{ +struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev)); +const char *battery_name = acpi_device_bid(battery->device); + +// Which battery are we configuring? +if (strcmp(battery_name, "BAT0") == 0) { + return TPACPI_BATTERY_PRIMARY; +} else if (strcmp(battery_name, "BAT1") == 0) { + return TPACPI_BATTERY_SECONDARY; +} else { + // the primary nor secondary battery were not found, + // but it's safe to assume the primary battery for + // most calls + return TPACPI_BATTERY_PRIMARY; +} + +} + +static ssize_t battery_thinkpad_start_charge_show(struct device *dev, +
[PATCH v2] 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 Signed-off-by: Ognjen Galic --- 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(+) diff --git a/Documentation/laptops/thinkpad-acpi.txt b/Documentation/laptops/thinkpad-acpi.txt index 00b6dfe..9aca62d 100644 --- a/Documentation/laptops/thinkpad-acpi.txt +++ b/Documentation/laptops/thinkpad-acpi.txt @@ -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 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 13e7b56..4852a76 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -41,6 +41,7 @@ #include #include +#include #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"); @@ -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 + +/* + * 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 + * 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 + return 0; +} + +pr_warning("battery: Lazy-loading thinkpad_acpi"); + +// thinkpad_acpi is not loaded, do lazy load +if (request_module("thinkpad_acpi")) { + return 1; +} + +return 0; +} + +static int battery_thinkpad_get_id(struct device *dev) +{ +struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev)); +const char *battery_name = acpi_device_bid(battery->device); + +// Which battery are we configuring? +if (strcmp(battery_name, "BAT0") == 0) { + return TPACPI_BATTERY_PRIMARY; +} else if (strcmp(battery_name, "BAT1") == 0) { + return TPACPI_BATTERY_SECONDARY; +} else { + // the primary nor secondary battery were not found, + // but it's safe to assume the primary battery for + // most calls + return TPACPI_BATTERY_PRIMARY; +} + +} + +static ssize_t battery_thinkpad_start_charge_show(struct device *dev, + struct device_attribute