New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: battery charging thresholds on thinkpads #3851

Closed
taradiddles opened this Issue Apr 24, 2018 · 5 comments

Comments

Projects
None yet
4 participants
@taradiddles

taradiddles commented Apr 24, 2018

Qubes OS version:

up to 4.0

Enhancement

Rationale: When properly set, battery charging thresholds can significantly extend battery life. Unfortunately Qubes OS doesn't ship the acpi_call kernel module required to use such feature on Thinkpads, which are popular laptops amongst qubes users. People who want to use that functionality have to boot a customized live distro (eg. Fedora on USB with persistent storage with the required kernel module + user space scripts) in order to set the thresholds. That's cumbersome and not secure.

Proposal: include the acpi_call module in dom0's kernel (maybe shipped by default or as a rpm add-on). On other distros TLP is usually used to set thresholds from user-space but it should be easy to extract the threshold functionality from TLP's bash scripts (I could do that if this enhancement is accepted). I don't think including and using the module would increase dom0's attack surface, but I'm not a security expert. For info the acpi_call module is only 332 sloc.

Related hardware: Thinkpads with Sandy Bridge and newer models (X220/T420, X230/T430 et al.)

edit: I posted this idea some time ago on qubes-devel but didn't get a reply except a +1 from another user

@rustybird

This comment has been minimized.

Show comment
Hide comment
@rustybird

rustybird Apr 25, 2018

ectool from the coreboot project could be an alternative, it talks directly to the embedded controller and doesn't need any kernel patch. Theoretically, this should work for stock BIOS too?

You have to look up the right command line arguments for your notebook model, e.g. for an x230.

ectool from the coreboot project could be an alternative, it talks directly to the embedded controller and doesn't need any kernel patch. Theoretically, this should work for stock BIOS too?

You have to look up the right command line arguments for your notebook model, e.g. for an x230.

@taradiddles

This comment has been minimized.

Show comment
Hide comment
@taradiddles

taradiddles Apr 25, 2018

I didn't know about ectool - just compiled it, it seems to work. Thanks a lot !

I'll play with it a bit more and I'll write a doc in the Qubes-Community project since it's not really specific to Qubes.

Closing the issue then ...

I didn't know about ectool - just compiled it, it seems to work. Thanks a lot !

I'll play with it a bit more and I'll write a doc in the Qubes-Community project since it's not really specific to Qubes.

Closing the issue then ...

@jharveyb

This comment has been minimized.

Show comment
Hide comment
@jharveyb

jharveyb May 25, 2018

@taradiddles Which machine did it work on for you? I have a T460 here & the X230 positions have no effect - could not find documentation for the correct locations in EC RAM. tp_smapi also doesn't support T430's and newer so curious as to your setup.

@taradiddles Which machine did it work on for you? I have a T460 here & the X230 positions have no effect - could not find documentation for the correct locations in EC RAM. tp_smapi also doesn't support T430's and newer so curious as to your setup.

@taradiddles

This comment has been minimized.

Show comment
Hide comment
@taradiddles

taradiddles May 25, 2018

I have a T450s with 2 batteries: an integrated one and a removable one.

Here's the output of ectool for the 0xb0 - 0xbf addresses

b0: 28 50 28 50 00 00 00 00 00 00 2d 05 00 96 01 00

The first four values are the battery charing thresholds for the 2 batteries:

  • b0: start charge for bat1 0x28 = 40 (%)
  • b1: stop charge for bat1 0x50 = 80 (%)
  • b2: start charge for bat2
  • b3: stop charge for bat2

No idea if those addresses are the same for a T460 though :(
I too tried to find the EC documentation but it seems that a bit of reverse engineering is needed (the only thing I found was the chipset low-level doc). You'll likely have to dump the EC registers with ectool, set the charging threshold to different values with tlp and the acpi_call module, dump the EC registers again and then compare/diff with the first dump.

[edit: updated comment after hitting "comment" by mistake]

taradiddles commented May 25, 2018

I have a T450s with 2 batteries: an integrated one and a removable one.

Here's the output of ectool for the 0xb0 - 0xbf addresses

b0: 28 50 28 50 00 00 00 00 00 00 2d 05 00 96 01 00

The first four values are the battery charing thresholds for the 2 batteries:

  • b0: start charge for bat1 0x28 = 40 (%)
  • b1: stop charge for bat1 0x50 = 80 (%)
  • b2: start charge for bat2
  • b3: stop charge for bat2

No idea if those addresses are the same for a T460 though :(
I too tried to find the EC documentation but it seems that a bit of reverse engineering is needed (the only thing I found was the chipset low-level doc). You'll likely have to dump the EC registers with ectool, set the charging threshold to different values with tlp and the acpi_call module, dump the EC registers again and then compare/diff with the first dump.

[edit: updated comment after hitting "comment" by mistake]

@jharveyb

This comment has been minimized.

Show comment
Hide comment
@jharveyb

jharveyb May 26, 2018

Those same addresses seem to work for me!

I only had b0 & b1 written before, started testing with the internal battery above start threshold and AC attached; no charging, as expected.
After adding an external battery without writing to b2 or b3, it began charging. Writing the same thresholds to b2 & b3 and reintroducing AC didn't cause either battery to charge (though upower and the xfce-power-manager still thought they were).
Discharging the internal battery below its start threshold and reintroducing AC caused it to charge up to the stop threshold - tl;dr it works perfectly, thank you for the help!

Those same addresses seem to work for me!

I only had b0 & b1 written before, started testing with the internal battery above start threshold and AC attached; no charging, as expected.
After adding an external battery without writing to b2 or b3, it began charging. Writing the same thresholds to b2 & b3 and reintroducing AC didn't cause either battery to charge (though upower and the xfce-power-manager still thought they were).
Discharging the internal battery below its start threshold and reintroducing AC caused it to charge up to the stop threshold - tl;dr it works perfectly, thank you for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment