Created attachment 200506 [details]
Use consistent driver name
Support ThinkPad battery charge start/stop control using new sysctls:
Informed by the Linux driver: https://lore.kernel.org/patchwork/patch/858076/
And this driver: https://github.com/teleshoes/tpacpi-bat/blob/master/battery_asl
Two patches are attached:
- First one uses a consistent driver name in the source code and man pages "ThinkPad ACPI Extras" instead of references to IBM
- Second one contains the majority of the change
Created attachment 200507 [details]
Support ThinkPad battery charge start/stop control
Is anybody able to take a look?
(In reply to Kevin Zheng from comment #2)
Submitting this on Christmas probably didn't help to get it noticed. Even though I have long wanted the ability to control charging, I totally missed it. A little explanation of why stopping and starting charging is desirable would probably be a desirable, as well.
Not sure about the naming convention change as I believe that this module is appropriate to more Lenovo models than just the Thinkpad. Maybe it is time to just bite the bullet and go to "Lenovo". Not that many IBM units around any more.
That said, any change might cause confusion for current users when acpi_ibm no longer loads.Is that worse than for newer users who no longer think of IBM and Thinkpad as related.
(In reply to rkoberman from comment #3)
Perhaps "Lenovo" is better than "ThinkPad" and "IBM". Note that this patch does not change the name of the module, so it is still "acpi_ibm" and loading "acpi_ibm" will still continue to work.
Controlling battery charge thresholds could be useful for prolonging battery life in machines that are used mostly on AC power. On Windows, battery charging thresholds can be controlled using the Lenovo Power Manager. This patch exposes the same functionality through the sysctl interface.
(In reply to Kevin Zheng from comment #0)
I've applied the patch on a FreeBSD 12.0p10 running on a Thinkpad T450. The sysctls appear but how can i test that the patch actually works as intended?
(In reply to Manuel Stühn from comment #5)
Set those sysctls to a non-zero number between 0-100.
If you start with a full battery, set start_thresh to something like 80; discharge your battery to 85%, plug in, battery shouldn't charge. Discharge to 75%, battery will charge until stop_thresh.
(In reply to Kevin Zheng from comment #6)
I've tried the following:
# sysctl hw.acpi.battery
# sysctl dev.acpi_ibm.0 | grep charge
If i plug in the laptop then, it seems to charge anyway:
# sysctl hw.acpi.battery
(In reply to Manuel Stühn from comment #7)
Per Google (https://askubuntu.com/questions/34452/how-can-i-limit-battery-charging-to-80-capacity), this method might have stopped working in the T440s.
I've tested on T430s and T410, and this patch works on both.
I'm using it on my T520 and it is working fine.
I read the old IBM whitepaper on this and they recommend keeping hte btter at or below 85% when a ystm is usually plugged in. Not sure just what they implemented, but the paper proposed that the percentage of time on battery be tracked and if the battery percentage was below a threshold, the maximum charge be reduced to 85%. If the charge dropped below come low value (20%?), the maximum charge would reset to 100% for some time. Statistics were to be retained across boots.
It's at least 20 years, so my memory of details is fuzzy, but I'm thinking of writing something to implement at least a bit of this scheme, but I have done little coding since kernels and drivers were written in assembly, so I'm hardly the ideal person for the job.
I just hit a minor nit. I can't set dev.acpi_ibm.0.bat0_charge_stop to 100. I get "sysctl: dev.acpi_ibm.0.bat0_charge_stop=100: Invalid argument". 99 works fine. Since the range is really 1-100, perhaps you should subtract 0ne from the input value to pass the 09-99 value to ACPI.
I also have noted the values are sticky, lasting through reboots and even power cycles, so are being stored in the BIOS configuration.
Still working well for me. I keep it at 85 when I'm home and bump it to 99 when traveling as I am more frequently not on AC and the extra 15% is very useful. It's really like to get this into the system, but I'd like to know more about it on newer systems. The Tx20s are over 8 years old and I expect to be upgrading mine before too much longer.
(In reply to rkoberman from comment #10)
Thanks for the comments.
The range is actually 0-99, where 0 means "battery controller default", and 1-99 is a custom setting.
The values are sticky, but they are not stored in the BIOS configuration. I believe the values are actually persisted on the battery controller chip in the battery pack and are reset when the battery pack is detached. Notice that if you set a value, shut down the computer, remove and reattach the battery, the values get reset.
I agree; it'd be great to figure out how to get this working on newer ThinkPads. Until I get one, however, I have no incentive to write a patch :)