thinkpad_acpi: Add support for controlling charge thresholds
Subsystems (2)
cover thinkpad_acpi: Add support for controlling charge thresholds
This patch series adds support for specifying charging thresholds, forcing a battery to discharge, and inhibiting charging, on ThinkPad Laptops using Sandy Bridge or newer processors.
The first two patches should be stable now, the third one does not work on my test system (but I'd appreciate if anyone with something other than an X230 tests it).
The inhibit charging part is a bit unprecise, and I can obviously not test that -1 really means permanently, but I assume it does. I don't know whether this one should be merged.
Changes since the RFC PATCH:
- Define batteries more dynamically instead of statically using large macros. Added support for up to 3 batteries, unsupported ones will not be exported.
- Added 3 more new patches with more features
Julian Andres Klode (4):
thinkpad_acpi: Add support for controlling charge thresholds
thinkpad_acpi: battery: Add force_discharge attribute
thinkpad_acpi: battery: Add force_discharge_ac_break attribute
thinkpad_acpi: battery: Add inhibit_charge_minutes attribute
Documentation/laptops/thinkpad-acpi.txt | 37 ++++ drivers/platform/x86/thinkpad_acpi.c | 300 ++++++++++++++++++++++++++++++++ 2 files changed, 337 insertions(+)
Signature · 1 line
1.8.4.2
PATCH 1/4 thinkpad_acpi: Add support for controlling charge thresholds
Add support for battery charge thresholds in new Sandy Bridge and Ivy Bridge ThinkPads. Based on the unofficial documentation in tpacpi-bat.
The threshold files support the values '0' for the controller's default, and 1-99 as percentages. Values outside of that range are rejected. The behaviour of '0' might be confusing, especially for the stop case where it basically seems to mean '100'.
--- Documentation/laptops/thinkpad-acpi.txt | 17 ++++ drivers/platform/x86/thinkpad_acpi.c | 173 ++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+)
Documentation/laptops/thinkpad-acpi.txt +17 -0
@@ -46,6 +46,7 @@ detailed description): - Fan control and monitoring: fan speed, fan enable/disable - WAN enable and disable - UWB enable and disable + - Charging control A compatibility table by model and feature is maintained on the web site, http://ibm-acpi.sf.net/. I appreciate any success or failure
@@ -1352,6 +1353,22 @@ Sysfs notes: rfkill controller switch "tpacpi_uwb_sw": refer to Documentation/rfkill.txt for details. +Charging control +---------------- +sysfs attribute groups: BAT0, BAT1, and so on, depending on how many batteries +are supported by the embedded controller. + +This feature controls the battery charging process. + +battery sysfs attribute: start_charge_thresh + + A percentage value from 1-99%, controlling when charging should start, or + 0 for the default value. + +battery sysfs attribute: stop_charge_thresh + + A percentage value from 1-99%, controlling when charging should stop, or + 0 for the default value. Multiple Commands, Module Parameters ------------------------------------
drivers/platform/x86/thinkpad_acpi.c +173 -0
191 lines not on this page · raw message
Signature · 9 lines
1.8.4.2 ------------------------------------------------------------------------------ November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
Quoted 22 lines · Julian Andres Klode
(quoted diff) +21
-0+static int __init battery_init(struct ibm_init_struct *iibm) + for (i = 0; i < BATTERY_MAX_COUNT; i++) { + int j = 0; + if (!acpi_evalf(hkey_handle, &state, "BCTG", "qdd", i + 1)) + continue; + /* If the sign bit was set, we could not get the start charge + * threshold of that battery. Let's assume that this battery + * (and all following ones) do not exist */ + if (state < 0) + break; + /* Modify BATTERY_MAX_ATTRS if you add an attribute */ + batteries[i].attributes[j++] = (struct dev_ext_attribute) { + .attr = __ATTR(start_charge_tresh, + S_IWUSR | S_IRUGO, + battery_start_charge_thresh_show, + battery_start_charge_thresh_store), + .var = (void *) (unsigned long) (i + 1) + }; + batteries[i].attributes[j++] = (struct dev_ext_attribute) { + .attr = __ATTR(stop_charge_tresh, + S_IWUSR | S_IRUGO,
Review
Quoted 10 lines
(quoted diff) +10
-0+ battery_stop_charge_thresh_show, + battery_stop_charge_thresh_store), + .var = (void *) (unsigned long) (i + 1) + }; + + strncpy(batteries[i].name, "BAT", 3); + batteries[i].name[3] = '0' + i; + batteries[i].name[4] = '\0'; + batteries[i].set = create_attr_set(j - 1, batteries[i].name); +
There's a bug here that I just noticed: It should be (j) attributes, not (j - 1) ones. The following patch fixes this. I can squash it into that patch and resubmit later on if requested.
-- >8 --
Subject: [PATCH] thinkpad_acpi: battery: Fix the size of the battery attribute sets
There are not j - 1, but j attributes.
--- drivers/platform/x86/thinkpad_acpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/thinkpad_acpi.c +1 -1
@@ -8613,7 +8613,7 @@ static int __init battery_init(struct ibm_init_struct *iibm)strncpy (batteries[i].name,"BAT" ,3 ); batteries[i].name[3 ] ='0' + i; batteries[i].name[4 ] ='\0' ; - batteries[i].set =create_attr_set (j -1 , batteries[i].name); + batteries[i].set =create_attr_set (j, batteries[i].name);for (j = j -1 ; j >=0 ; j--) add_to_attr_set(batteries[i].set,
Signature · 9 lines
1.8.4.2 -- Julian Andres Klode - Debian Developer, Ubuntu Member See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/. Please do not top-post if possible.
Quoted 7 lines · Julian Andres Klode
Add support for battery charge thresholds in new Sandy Bridge and Ivy Bridge ThinkPads. Based on the unofficial documentation in tpacpi-bat.
The threshold files support the values '0' for the controller's default, and 1-99 as percentages. Values outside of that range are rejected. The behaviour of '0' might be confusing, especially for the stop case where it basically seems to mean '100'.
Thinking more about this, it might make more sense to simply accept a 100 value and not accept a 0 value in the stop case (I tried multiple times to write 100 to a stop_charge_thresh file, because that feels more natural).
Having a 0 mean 100% is just odd. So stop_charge_thresh should simply accepts integer values in the range [1, 100] (and start_charge_thresh should continue accept [0, 99], as 0 really means 0 there).
Signature · 5 lines
Julian Andres Klode - Debian Developer, Ubuntu Member See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/. Please do not top-post if possible.
Quoted 9 lines · Julian Andres Klode
Quoted 7 lines · Julian Andres Klode
Add support for battery charge thresholds in new Sandy Bridge and Ivy Bridge ThinkPads. Based on the unofficial documentation in tpacpi-bat.
The threshold files support the values '0' for the controller's default, and 1-99 as percentages. Values outside of that range are rejected. The behaviour of '0' might be confusing, especially for the stop case where it basically seems to mean '100'.
Quoted 7 lines
Thinking more about this, it might make more sense to simply accept a 100 value and not accept a 0 value in the stop case (I tried multiple times to write 100 to a
stop_charge_threshfile, because that feels more natural).Having a 0 mean 100% is just odd. So
stop_charge_threshshould simply accepts integer values in the range [1, 100] (andstart_charge_threshshould continue accept [0, 99], as 0 really means 0 there).
Indeed. Just return EINVAL for a stop threshold of 0.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 14 lines · Henrique de Moraes Holschuh
Quoted 13 lines · Julian Andres Klode
Quoted 7 lines · Julian Andres Klode
Add support for battery charge thresholds in new Sandy Bridge and Ivy Bridge ThinkPads. Based on the unofficial documentation in tpacpi-bat.
The threshold files support the values '0' for the controller's default, and 1-99 as percentages. Values outside of that range are rejected. The behaviour of '0' might be confusing, especially for the stop case where it basically seems to mean '100'.
Thinking more about this, it might make more sense to simply accept a 100 value and not accept a 0 value in the stop case (I tried multiple times to write 100 to a
stop_charge_threshfile, because that feels more natural).
Quoted 5 lines
Quoted 3 lines
Having a 0 mean 100% is just odd. So
stop_charge_threshshould simply accepts integer values in the range [1, 100] (andstart_charge_threshshould continue accept [0, 99], as 0 really means 0 there).Indeed. Just return EINVAL for a stop threshold of 0.
Actually, a stop threshold below the current start threshold is also invalid and what happens when you try that is implementation-specific. And the kernel is not the only party who can change the thresholds, so you have to read them if you really need to know the current value.
To correct myself, stop threshold being zero is also implementation- specific. on thinkpads it is not valid.
For thinkpads, I believe the EC firmware changes the other threshold so that the boundary condition stop > start is always valid. But I never tried it with a direct EC write to validate this. If it becomes important, I can check -- but I'd still prefer to enforce sanity at the driver level just in case. Don't tempt the gremilins, for they live at boundary conditions and their sleep is light indeed.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 19 lines · Henrique de Moraes Holschuh
Quoted 18 lines · Henrique de Moraes Holschuh
Quoted 16 lines · Julian Andres Klode
Quoted 7 lines · Julian Andres Klode
Add support for battery charge thresholds in new Sandy Bridge and Ivy Bridge ThinkPads. Based on the unofficial documentation in tpacpi-bat.
The threshold files support the values '0' for the controller's default, and 1-99 as percentages. Values outside of that range are rejected. The behaviour of '0' might be confusing, especially for the stop case where it basically seems to mean '100'.
Thinking more about this, it might make more sense to simply accept a 100 value and not accept a 0 value in the stop case (I tried multiple times to write 100 to a
stop_charge_threshfile, because that feels more natural).Having a 0 mean 100% is just odd. So
stop_charge_threshshould simply accepts integer values in the range [1, 100] (andstart_charge_threshshould continue accept [0, 99], as 0 really means 0 there).
Quoted 6 lines
Quoted 1 line
Indeed. Just return EINVAL for a stop threshold of 0.
Actually, a stop threshold below the current start threshold is also invalid and what happens when you try that is implementation-specific. And the kernel is not the only party who can change the thresholds, so you have to read them if you really need to know the current value.
That's true. The problem is that if we forbid such values, the writes will need to be done in a specific order. Let's say I have a system with
start=0 stop=50 and I want to change it to start=60 stop=80
If we return -EINVAL on a case stop < start, the only way to do this is setting stop first and then start, because if we wrote start first, then we would have: start > stop (because 60 > 50). But the error message when doing it the wrong way around will not be very helpful and I think it is confusing.
We might be able to work around this by simple setting stop = start if a new write causes the stop threshold to be below the start threshold. But this also seems ugly.
Quoted 2 lines
To correct myself, stop threshold being zero is also implementation- specific. on thinkpads it is not valid.
Writing the value 0 effectively means setting the stop threshold to 100%. The EC itself does not accept the value 100. I don't know why they choose to implement it this way. So the code should not accept 0 as an input value and replace an input of 100 with 0.
The exact value returned by the ACPI call is 0x80000000, that is, a signed 0 integer with sign bit set to 1. A set sign bit indicates an error.
Quoted 7 lines
For thinkpads, I believe the EC firmware changes the other threshold so that the boundary condition stop > start is always valid. But I never tried it with a direct EC write to validate this. If it becomes important, I can check -- but I'd still prefer to enforce sanity at the driver level just in case. Don't tempt the gremilins, for they live at boundary conditions and their sleep is light indeed.
It does not seem to do this here.
Signature · 5 lines
Julian Andres Klode - Debian Developer, Ubuntu Member See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/. Please do not top-post if possible.
Quoted 3 lines · Julian Andres Klode
We might be able to work around this by simple setting stop = start if a new write causes the stop threshold to be below the start threshold. But this also seems ugly.
It is the safest way, but the correct pseudo-code would be, assuiming unsigned:
when someone changes start:
if (start > 99)
start = 99; get_current_stop_treshold(&stop); if (start > stop) stop = start + 1;
set_thresholds(start, stop);
when someone changes stop:
if (stop == 0 || stop > 100)
stop = 100; get_current_start_threshold(&start); if (start > stop) start = stop - 1;
set_thresholds(start, stop);
And write the stop threshold mod 100 at the low-level "send thresholds to the firmware" routine.
Quoted 4 lines
Writing the value 0 effectively means setting the stop threshold to 100%. The EC itself does not accept the value 100. I don't know why they choose to implement it this way. So the code should not accept 0 as an input value and replace an input of 100 with 0.
Yes. This behaviour exists since start/stop thresholds were first exported outside the EC, in the X30 or thereabouts.
Quoted 8 lines
Quoted 6 lines
For thinkpads, I believe the EC firmware changes the other threshold so that the boundary condition stop > start is always valid. But I never tried it with a direct EC write to validate this. If it becomes important, I can check -- but I'd still prefer to enforce sanity at the driver level just in case. Don't tempt the gremilins, for they live at boundary conditions and their sleep is light indeed.
It does not seem to do this here.
Then it is best if we enforce it in the driver. I've crashed thinkpad ECs before, *don't tempt the gremilins* indeed.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 5 lines · Henrique de Moraes Holschuh
Quoted 3 lines · Julian Andres Klode
We might be able to work around this by simple setting stop = start if a new write causes the stop threshold to be below the start threshold. But this also seems ugly.
Quoted 7 lines
It is the safest way, but the correct pseudo-code would be, assuiming unsigned:
when someone changes start:
if (start > 99)
start = 99;
I think we should just return -EINVAL in such cases. Allowing users to write larger percentages is a bit pointless (we don't allow them to write negative ones either). And other promiment code (the backlight drivers) seem to reject out-of-range values.
Quoted 1 line
set_thresholds(start, stop);
I think there should not be some common set_thresholds, because we also need to write things in different orders for start / stop then:
DECREASE STOP => Write new start if needed, then write stop INCREASE START => Write new stop if needed, then write start
Otherwise we might have a very very very short time in which start is greater than stop.
I'll incorporate this in real code and test it tomorrow.
Sometimes after that, I'd like to tackle the integration with power_supply. This is a bit more complicated, there even appear to be two battery drivers in ACPI, namely battery and sbs, and battery is used on my system (I don't know if that's the generic case on ThinkPads, or if is the case because battery is builtin and sbs is not). How to do extend that is probably something best discussed with ACPI maintainers, as I can't see any mechanism for this.
Signature · 5 lines
Julian Andres Klode - Debian Developer, Ubuntu Member See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/. Please do not top-post if possible.
Quoted 24 lines · Julian Andres Klode
Quoted 5 lines · Henrique de Moraes Holschuh
Quoted 3 lines · Julian Andres Klode
We might be able to work around this by simple setting stop = start if a new write causes the stop threshold to be below the start threshold. But this also seems ugly.
Quoted 7 lines
It is the safest way, but the correct pseudo-code would be, assuiming unsigned:
when someone changes start:
if (start > 99)
start = 99;I think we should just return
-EINVALin such cases. Allowing users to write larger percentages is a bit pointless (we don't allow them to write negative ones either). And other promiment code (the backlight drivers) seem to reject out-of-range values.Quoted 1 line
set_thresholds(start, stop);I think there should not be some common
set_thresholds, because we also need to write things in different orders for start / stop then:
Quoted 8 lines
DECREASE STOP => Write new start if needed, then write stop INCREASE START => Write new stop if needed, then write start
Otherwise we might have a very very very short time in which start is greater than stop.
I'll incorporate this in real code and test it tomorrow.
OK, tommorow is now, 4 months later. I was to busy with lectures. An updated patch is below that passes my small test suite.
The next step is to integrate this properly with power supply and/or acpi battery. One way would be to add additional power supply properties and then add get/set_property() pointers to the acpi battery which it can fall back to if it does not support a requested property (and we would locate the ACPI battery and set those pointers to new thinkpad_acpi functions).
Full changelog:
* Changed stop interval to 1..100
* Fixed name of attributes (tresh => thresh)
* Made sure to keep start < stop
-- >8 --
Subject: [PATCH 1/4] thinkpad_acpi: Add support for controlling charge
thresholds
Add support for battery charge thresholds in new Sandy Bridge and Ivy Bridge ThinkPads. Based on the unofficial documentation in tpacpi-bat.
--- Documentation/laptops/thinkpad-acpi.txt | 15 ++ drivers/platform/x86/thinkpad_acpi.c | 235 ++++++++++++++++++++++++++++++++ 2 files changed, 250 insertions(+)
Documentation/laptops/thinkpad-acpi.txt +15 -0
@@ -46,6 +46,7 @@ detailed description): - Fan control and monitoring: fan speed, fan enable/disable - WAN enable and disable - UWB enable and disable + - Charging control A compatibility table by model and feature is maintained on the web site, http://ibm-acpi.sf.net/. I appreciate any success or failure
@@ -1352,6 +1353,20 @@ Sysfs notes: rfkill controller switch "tpacpi_uwb_sw": refer to Documentation/rfkill.txt for details. +Charging control +---------------- +sysfs attribute groups: BAT0, BAT1, and so on, depending on how many batteries +are supported by the embedded controller. + +This feature controls the battery charging process. + +battery sysfs attribute: start_charge_thresh + + A percentage value from 0-99%, controlling when charging should start + +battery sysfs attribute: stop_charge_thresh + + A percentage value from 1-100%, controlling when charging should stop Multiple Commands, Module Parameters ------------------------------------
drivers/platform/x86/thinkpad_acpi.c +235 -0
253 lines not on this page · raw message
Signature · 10 lines
1.9.1 -- Julian Andres Klode - Debian Developer, Ubuntu Member See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/. Please do not top-post if possible.
Quoted 10 lines · Julian Andres Klode
OK, tommorow is now, 4 months later. I was to busy with lectures. An updated patch is below that passes my small test suite.
The next step is to integrate this properly with power supply and/or acpi battery. One way would be to add additional power supply properties and then add get/set_property() pointers to the acpi battery which it can fall back to if it does not support a requested property (and we would locate the ACPI battery and set those pointers to new
thinkpad_acpifunctions).
Well, when you feel it is ready enough, please send a new version of the entire changeset, with all changes (and label it v2 or something).
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
PATCH 2/4 thinkpad_acpi: battery: Add force_discharge attribute
In reply to Julian Andres KlodeThis makes it possible to forcefully discharge a battery.
--- Documentation/laptops/thinkpad-acpi.txt | 4 +++ drivers/platform/x86/thinkpad_acpi.c | 49 ++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-)
Documentation/laptops/thinkpad-acpi.txt +4 -0
@@ -1370,6 +1370,10 @@ battery sysfs attribute: stop_charge_thresh A percentage value from 1-99%, controlling when charging should stop, or 0 for the default value. +battery sysfs attribute: force_discharge + + Force discharging (0 or 1) + Multiple Commands, Module Parameters ------------------------------------
drivers/platform/x86/thinkpad_acpi.c +48 -1
67 lines not on this page · raw message
Signature · 9 lines
1.8.4.2 ------------------------------------------------------------------------------ November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
PATCH 3/4 thinkpad_acpi: battery: Add force_discharge_ac_break attribute
In reply to Julian Andres KlodeTells the EC to stop a forceful discharging if the AC is disconnected. First needs force_discharge set to 1 to be able to work. Actual functionality is untested, as that attribute is not supported on an X230.
--- Documentation/laptops/thinkpad-acpi.txt | 4 +++ drivers/platform/x86/thinkpad_acpi.c | 50 ++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-)
Documentation/laptops/thinkpad-acpi.txt +4 -0
@@ -1374,6 +1374,10 @@ battery sysfs attribute: force_discharge Force discharging (0 or 1) +battery sysfs attribute: force_discharge_ac_break + + Break the discharging when the AC disconnects (0 or 1) + Multiple Commands, Module Parameters ------------------------------------
drivers/platform/x86/thinkpad_acpi.c +49 -1
68 lines not on this page · raw message
Signature · 9 lines
1.8.4.2 ------------------------------------------------------------------------------ November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
PATCH 4/4 thinkpad_acpi: battery: Add inhibit_charge_minutes attribute
In reply to Julian Andres KlodeThis should be considered experimental. There seem to be to ways to inhibit charging, one globally using peak shift state, and one using a battery-specific inhibit charge command. The latter is implemented here. Setting a permanent timeout is not supported currently.
Reading the timeout is not supported because the ACPI call needed to read the value is not documented/reverse-engineered yet.
--- Documentation/laptops/thinkpad-acpi.txt | 12 ++++++++++++ drivers/platform/x86/thinkpad_acpi.c | 34 ++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-)
Documentation/laptops/thinkpad-acpi.txt +12 -0
@@ -1378,6 +1378,18 @@ battery sysfs attribute: force_discharge_ac_break Break the discharging when the AC disconnects (0 or 1) +battery sysfs attribute: inhibit_charge_minutes + + Inhibit charging for the specified amount of minutes. This attribute + may not be very precise, the charging may start again some seconds + earlier than requested. It's also write-only until someone figured out + how reading that value works. + + Values range: -1 to 720 + + The value -1 is supposed to mean permanently. + + Multiple Commands, Module Parameters ------------------------------------
drivers/platform/x86/thinkpad_acpi.c +33 -1
@@ -8358,7 +8358,7 @@ static struct ibm_struct fan_driver_data = {/* Modify battery_init() if you modify them */ #define BATTERY_MAX_COUNT 3 -#define BATTERY_MAX_ATTRS 4 +#define BATTERY_MAX_ATTRS 5 static struct battery { char name[3 + 1 + 1];
@@ -8518,6 +8518,31 @@ static ssize_t battery_force_discharge_ac_break_store(struct device *dev,return count; } +static ssize_t battery_inhibit_charge_minutes_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +int bat =battery_attribute_get_battery (attr); +int res = -EINVAL ; +int value; + + res =kstrtoint (buf,0 , &value); +if (res || value >720 || value <-1 ) +return res ? res : -EINVAL ; + +if (value ==-1 ) + value =1 ; +else + value = (value <<8 ) | (value &1 ); + + value |= (bat <<4 ); + +if (!hkey_handle || !acpi_evalf (hkey_handle, &res,"BICS" , +"dd" , (int ) value) || res <0 ) +return -EIO ; +return count; +} +static int __init battery_init (struct ibm_init_struct *iibm) {int res;
@@ -8577,6 +8602,13 @@ static int __init battery_init(struct ibm_init_struct *iibm) battery_force_discharge_ac_break_store), .var = (void *) (unsigned long) (i + 1) }; + batteries[i].attributes[j++] = (struct dev_ext_attribute ) { + .attr =__ATTR (inhibit_charge_minutes, +S_IWUSR , +NULL , + battery_inhibit_charge_minutes_store), + .var = (void *) (unsigned long ) (i +1 ) + };strncpy (batteries[i].name,"BAT" ,3 ); batteries[i].name[3 ] ='0' + i;
Signature · 9 lines
1.8.4.2 ------------------------------------------------------------------------------ November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
Quoted 24 lines · Julian Andres Klode
This patch series adds support for specifying charging thresholds, forcing a battery to discharge, and inhibiting charging, on ThinkPad Laptops using Sandy Bridge or newer processors.
The first two patches should be stable now, the third one does not work on my test system (but I'd appreciate if anyone with something other than an X230 tests it).
The inhibit charging part is a bit unprecise, and I can obviously not test that -1 really means permanently, but I assume it does. I don't know whether this one should be merged.
Changes since the RFC PATCH:
- Define batteries more dynamically instead of statically using large macros. Added support for up to 3 batteries, unsupported ones will not be exported.
- Added 3 more new patches with more featuresJulian Andres Klode (4):
thinkpad_acpi: Add support for controlling charge thresholds
thinkpad_acpi: battery: Addforce_dischargeattribute
thinkpad_acpi: battery: Addforce_discharge_ac_breakattribute
thinkpad_acpi: battery: Addinhibit_charge_minutesattribute
Quoted 4 lines
Documentation/laptops/thinkpad-acpi.txt | 37 ++++ drivers/platform/x86/thinkpad_acpi.c | 300 ++++++++++++++++++++++++++++++++ 2 files changed, 337 insertions(+)
I'd really like to get some comments on this series (especially by Henrique and Matthew, they're responsible); so I know what I have to fix and whether I should drop some of the later patches, and if the patch series has any chance of being accepted...
Signature · 5 lines
Julian Andres Klode - Debian Developer, Ubuntu Member See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/. Please do not top-post if possible.
Quoted 3 lines · Julian Andres Klode
This patch series adds support for specifying charging thresholds, forcing a battery to discharge, and inhibiting charging, on ThinkPad Laptops using Sandy Bridge or newer processors.
Hello again,
it's been about 1.5 months now after I submitted this patch series and I have not received any response yet.
I fixed the issues pointed out by Bjørn Mork in the previous patch except for the one with the battery names, as I have no idea how battery numbers are created or mapped. I can only say that the names are the same on my test machine, I don't have any other ones.
Henrique, it would be really great if you could take a look.
Signature · 5 lines
Julian Andres Klode - Debian Developer, Ubuntu Member See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/. Please do not top-post if possible.
Quoted 10 lines · Julian Andres Klode
Quoted 3 lines · Julian Andres Klode
This patch series adds support for specifying charging thresholds, forcing a battery to discharge, and inhibiting charging, on ThinkPad Laptops using Sandy Bridge or newer processors.
Hello again,
it's been about 1.5 months now after I submitted this patch series and I have not received any response yet.
Quoted 6 lines
I fixed the issues pointed out by Bjørn Mork in the previous patch except for the one with the battery names, as I have no idea how battery numbers are created or mapped. I can only say that the names are the same on my test machine, I don't have any other ones.
Henrique, it would be really great if you could take a look.
I did. I just did not manage to finish looking over it, it is not really okay as-is, mostly because it did not create a power-supply device and properly extended that thing in a generic way, which would be vastly preferable to adding yet another private interface.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 6 lines · Henrique de Moraes Holschuh
Quoted 5 lines · Julian Andres Klode
Quoted 3 lines · Julian Andres Klode
This patch series adds support for specifying charging thresholds, forcing a battery to discharge, and inhibiting charging, on ThinkPad Laptops using Sandy Bridge or newer processors.
[...]
Quoted 6 lines
Quoted 1 line
Henrique, it would be really great if you could take a look.
I did. I just did not manage to finish looking over it, it is not really okay as-is, mostly because it did not create a power-supply device and properly extended that thing in a generic way, which would be vastly preferable to adding yet another private interface.
Thanks for the response.
I think that a more generic approach is a good idea, but I don't think creating a new power supply device would be the right choice because this controls existing supplies rather than being a supply in itself, and I am not aware of any other kind of power supply device that allows setting things.
We could extend the existing battery devices and then get paths like
/sys/class/power_supply/BAT0/start_charge_thresh
which looks `natural'. There is one problem with that approach, though:
A ThinkPad supports multiple batteries: In my case, I could add a slice battery. But the ACPI driver only exposes a BAT0 device without a slice being attached (I assume a BAT1 will pop-up if you add a slice battery, but can't test it, as I don't own one). This means that you can only configure the slice battery when it's plugged in. I don't know if its a good idea to work like this.
Another problem is that I don't know any other systems supporting charge thresholds, and I don't want to dictate interfaces built for ThinkPads as a generic way.
Signature · 5 lines
Julian Andres Klode - Debian Developer, Ubuntu Member See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/. Please do not top-post if possible.
Quoted 2 lines · Julian Andres Klode
I think that a more generic approach is a good idea, but I don't think creating a new power supply device would be the right
...
Quoted 3 lines
We could extend the existing battery devices and then get paths like
/sys/class/power_supply/BAT0/start_charge_thresh
which looks `natural'. There is one problem with that approach, though:
I'm fine with extending battery devices, in fact I agree that it would be a better place to add these attributes to.
Quoted 3 lines
A ThinkPad supports multiple batteries: In my case, I could add a slice battery. But the ACPI driver only exposes a BAT0 device without a slice being attached (I assume a BAT1 will pop-up if you add a slice battery,
Thinkpad batteries are static, BAT1 is always BAT1 for the firmware, regardless of whether BAT0 is present or not. Their parameters can always be set as well, since they're stored in the EC and not in the battery pack uC. And the EC doesn't care whether the battery is present or not.
Quoted 3 lines
but can't test it, as I don't own one). This means that you can only configure the slice battery when it's plugged in. I don't know if its a good idea to work like this.
We could change the ACPI battery driver to optionally allow a platform driver (or a dmi table) to order it to register batteries that are not present at boot, and set that flag for thinkpads.
Quoted 3 lines
Another problem is that I don't know any other systems supporting charge thresholds, and I don't want to dictate interfaces built for ThinkPads as a generic way.
All SBS batteries support it, which means most notebooks do. Whether they expose it or not, and whether their platform drivers know about it or not in order to expose these parameters to the kernel and to userspace, is a separate issue.
Refer to: http://www.sbs-forum.org/
So yes, we can and should add these as generic *optional* parameters for generic batteries. How to best add it to the ACPI battery driver is something to think about.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Hi!
Quoted 3 lines
Another problem is that I don't know any other systems supporting charge thresholds, and I don't want to dictate interfaces built for ThinkPads as a generic way.
On systems like Sharp Zaurus, Nokia N900, charging is controlled by Linux. As charge thresholds should extend Li-ION battery life under anticipated light usage, they are probably good idea on all systems that can support them.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html