Skip to content
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

T420 battery threshold doesn't work #3

Open
chx opened this issue Sep 19, 2011 · 36 comments
Open

T420 battery threshold doesn't work #3

chx opened this issue Sep 19, 2011 · 36 comments

Comments

@chx
Copy link

chx commented Sep 19, 2011

echo 40 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
[117661.051803] smapi smapi: smapi_request: SMAPI error: SMAPI function is not available (func=2116)
[117661.051815] smapi smapi: __get_real_thresh: cannot get start_thresh of bat=0: SMAPI function is not available
@chx
Copy link
Author

chx commented Sep 19, 2011

This is essentially a duplicate of http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=628829

@evgeni
Copy link
Member

evgeni commented Sep 19, 2011

No it's not.
T420 only supports stop, not start. Bark at Lenovo for breaking the interface :)
Does https://gitorious.org/linux-test-utils/tp_charge work for start and stop for you?

@chx
Copy link
Author

chx commented Sep 19, 2011

@evgeni
Copy link
Member

evgeni commented Sep 19, 2011

Would you please try? :)

@chx
Copy link
Author

chx commented Sep 19, 2011

OK I tried:

Request IO permissions.
Get BAT0 start.
get_threshold: Function not implemented
Get BAT0 stop.
start = 255, stop = 0

@mluessi
Copy link

mluessi commented Oct 26, 2011

I have a T420s with the same problem. Is there a way to get the addresses needed for setting/getting the thresholds from the Lenovo Windows utility?

@evgeni
Copy link
Member

evgeni commented Oct 26, 2011

reverse engeneer it :)
i currently have no docs/ideas how to fix it :/

@teleshoes
Copy link

hello!
there are ACPI calls for this that work on my W520. {start/stop threshold, inhibit charge, and force-discharge-on-ac-only}. see if my perl script works for any of you:
https://github.com/teleshoes/tpbattstat-applet/blob/master/tpacpi-bat

@teleshoes
Copy link

it requires that you install acpi_call kernel module
e.g.:
git clone git://github.com/mkottman/acpi_call.git acpi_call
cd acpi_call
make
sudo insmod acpi_call.ko

@chx
Copy link
Author

chx commented Oct 30, 2011

[root@veyron2 acpi_call-git]# perl /tmp/tpacpi-bat.pl startChargeThreshold 0 40
Calling : _SB.PCI0.LPC.EC.HKEY.BCCS 0x28
Response: 0x0

Does that mean it worked? I am on a T420.

@teleshoes
Copy link

damn that was fast. it means that the ACPI interface responded with a 0, which is a very good sign but not a perfect confirmation.
try forceDischarge with the AC adapter connected and see if it starts discharging.

@chx
Copy link
Author

chx commented Oct 30, 2011

[root@veyron2 acpi_call-git]# perl /tmp/tpacpi-bat.pl forceDischarge 1 1
Calling : _SB.PCI0.LPC.EC.HKEY.BDSS 0x101
Response: 0x0
[root@veyron2 acpi_call-git]# cat /sys/class/power_supply/BAT0/status
Discharging

Looks good.

@teleshoes
Copy link

so then, yes, it means its working. im a little confused, though, about why tee isnt printing the backslash.
when i run the same thing, i get:

teleshoes:~/tpbattstat-applet$ sudo ./tpacpi-bat forceDischarge 1 1
Calling : _SB.PCI0.LPC.EC.HKEY.BDSS 0x101
Response: 0x0

@chx
Copy link
Author

chx commented Oct 30, 2011

Let me link http://www.thinkwiki.org/wiki/Maintenance#Battery_treatment this for people coming around later. You want approx 30-85 for your discharge thresholds.

@chx
Copy link
Author

chx commented Oct 30, 2011

teleshoes, what backslash, your output looks totally the same as mine?

@teleshoes
Copy link

oh, whoops, nevermind, its the github markup

@evgeni
Copy link
Member

evgeni commented Oct 30, 2011

very cool teleshoes!
as it doesn't work on my x201s, I guess it only will work on the new sandy-bridge models?

@teleshoes
Copy link

that tentatively appears to be the case. does the x201s have a crippled SMAPI interface like the t420/w520/etc?
im operating under the suspicion that they broke SMAPI, maybe by accident, because they ditched it for ACPI.

@evgeni
Copy link
Member

evgeni commented Oct 31, 2011

nope, x201s smapi works just fine (tm) with all features.
your suspiction sounds reasonable and is even welcome (now we only have to get hdaps into some standartized interface)

@schuschu
Copy link

teleshoes script works nice on my x220 too. is it possible to implement the acpi calls as fallback/workaround into tp_smapi or could somebody help me understand what exactly the problem is with the start_threshold/force_discharge? it seems they just changed the address, so checking all addresses for a known threshold should not be that difficult (although i failed ...) or is it?

@teleshoes: a nice makefile would be appreciated, since packaging is quite difficult this way.

@teleshoes
Copy link

@schuschu {long list of things, so ill number them to make responding easier}

  1. thanks! ill add x220 to the known-working list.

  2. since ACPI is actually a completely different interface, it doesnt make much sense to merge this into tp_smapi {please feel free to correct me on this!}. better would be to merge it into thinkpad_acpi. im thinking about submitting a patch to those folks fixing LEDs for newer thinkpads anyway {my mute_microphone button is controllable, and i inverted it to be black when OFF and orange when ON, like a microphone}. i may also submit a patch for charge/discharge controls, but i would need a lot of time to do so since C sucks and i have a day job.

  3. the reason force_discharge doesnt work is that the code that tpsmapi interfaces with in the embedded controller is broken in newer thinkpads. {if you could check all the SMAPI addresses at one-per-second with all possible one byte messages, it would take a solid year. we have no reason to believe that one of the addresses will magically work anyway, and one of the others could be the self-destruct address}. however, i believe the REASON its broken is that the developers abandoned the SMAPI project for the much better, as far as i can tell, ACPI interface. {its better because reading/writing inhibit_charge and force_discharge dont stop the cpu for a quarter-second in the new acpi interface, unlike smapi. also, please feel free to correct me on this; this is merely anecdotal evidence from my machine}

  4. what would you want this makefile to do? install tpacpi-bat /usr/local/bin is just about all i could think of...

  5. as for my dzen/gtk/gnome-panel GUI, tpbattstat-applet, i intend for THAT to use both tpsmapi and tpacpi-bat. it will simply see if it can read force_discharge from tpsmapi, and if it DOES fail, try to use tpacpi-bat. {anyone have a better idea than that?}

@schuschu
Copy link

Thanks for your detailed response!

regarding 2&3) I would appreciate it if you could submit a patch for thinkpad_acpi. Could you please tell me how you fixed our leds since I cant get my speaker/mic led to work (it got even worse since i changed acpi_osi="Linux", now i can't even mute the sounds for standby/resume etc. anymore). Since Lenovo broke the interface for newer models (Sandy Brindge and possibly breaks it even more for later models), would it be possible to get all the values which are currently read from ec via acpi or would you still use them together?

As for 4&5) Thanks for the info, I didn't look much into your code, so I wasn't sure it would work as standalone application.

@teleshoes
Copy link

er, this isnt really the place for LED discussions, but im not very good at not hijacking. heres the diff {emailed along with the version i patched against}.

it is NOT particularly ready for use. it simply adds a mute_mic LED and marks all LEDs as 'safe'. i plan on figuring out exactly which ones should be exposed sometime, and making this more reasonable.

171a172
>   TP_HKEY_EV_VOL_MUTE_MIC     = 0x101b, /* Microphone mute */
5060a5062,5063
>   NULL,
>   "tpacpi::mute_mic",
5062c5065
< #define TPACPI_SAFE_LEDS  0x1081U
---
> #define TPACPI_SAFE_LEDS  0xFFFFU
5276a5280,5282
>   
>   TPACPI_Q_LNV('6', 'U', 0x4087), /* T410s */
>   TPACPI_Q_LNV('8', 'B', 0xffff), /* W520 */

oh snap, i just realized you want the mute buttons to control their own LEDs. i have scripts attached to those buttons which call pulse and set the LED as i like. the important thing is that you can make the LEDs do whatever you like now...

@teleshoes
Copy link

tpacpi-bat can easily be used on its own, but i dont feel like having it in two repositories, so i stuck it in tpbattstat-applet.

tpbattstat-applet manages tpsmapi nicely, for me and a coupla other folks. it doesnt do thresholds, but it does do balancing. it also now features LED controls for, e.g.: making the battery LED flash to let you know its charging.
it will manage tpacpi-bat in the next coupla weeks, too
it requires gconf and either gtk or dzen, so it only really works in gnome.

@Impe
Copy link

Impe commented Nov 11, 2011

Hello,
just wanted to mention that tpacpi-bat works like a charm on my Thinkpad t420 4180w1j. Thanks very much teleshoes. Also I wanted to ask if the setting is permanent and if tp-smapi can mess that up? Right now it seems permanent (used tpacpi-bat only once to set start and stop thresh) and it still works after some reboots/poweroffs.

@teleshoes
Copy link

yay, youre welcome! it seems permanent to me on my W520 {i set it once a week ago and its still set}, but i have not extensively tested.

@teleshoes
Copy link

tpsmapi shouldnt be able to affect what you did in tpacpi-bat because the interface for all four things tpacpi-bat does is broken in smapi, at least for me.

this is what happens for me in my W520 in tpsmapi

writing:
start_charge_thresh: error
stop_charge_thresh: silent failure; nothing happens
inhibit_charge_minutes: silent failure; nothing happens
force_discharge: error

reading:
start_charge_thresh: error
stop_charge_thresh: shows me the val i set in tpacpi-bat
inhibit_charge_minutes: shows me the val i set in tpacpi-bat
force_discharge: error

@teleshoes
Copy link

@chx
"Note that I can't seem to be able to remove the discharge treshold any more, it doesn't charge above 69% :("
is this still the case?

@chx
Copy link
Author

chx commented Nov 28, 2011

Needs some fiddling with the thresholds but no, I am able to charge to 100% now.

@teleshoes
Copy link

ok cool. i too have some difficulties, particularly when it comes to trying to influence priority when charging my slice battery; if i inhibit charge on one of them when that one is below 80, it refuses to charge even if the one i want is really low; and so neither battery charges. not too certain the exact conditions. though, but something about it smacks of bugginess.

@linrunner
Copy link

For your convenience I just integrated tpacpi-bat into my tool TLP (0.3.7): http://linrunner.de/tlp

@CaledoniaProject
Copy link

Just FYI The startChargeThresh works in 3.6 kernel, and stopped functioning in 3.7.4

I mean, now reading /sys/devices/platform/smapi/BAT0/start_charge_thresh will get me an error "No such device or address"

@CaledoniaProject
Copy link

I'm running x220 4290JY1, Arch

@linrunner
Copy link

@CaledoniaProject: start_charge_thresh "No such device or address" is the normal behavior for tp-smapi on your hardware. tpacpi-bat w/ acpi_call kernel module works fine on the X220 with kernel 3.7 or 3.8 (Ubuntu 13.04) -> recheck your installation.

@CaledoniaProject
Copy link

Ah, that does work! Confirmed working on X220. The smapi kernel module doesn't.

@0xfu
Copy link

0xfu commented Aug 10, 2013

Just for the history record, tpacpi-bat works excellent for ThinkPad t431s, though tp-smapi doesn't seem to be alive on this machine. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants