[coreboot-gerrit] New patch to review for coreboot: ec/lenovo/h8: Guard against EC bugs in the battery status logic.

Tobias Diedrich (ranma+coreboot@tdiedrich.de) gerrit at coreboot.org
Sun Feb 12 13:43:09 CET 2017


Tobias Diedrich (ranma+coreboot at tdiedrich.de) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/18349

-gerrit

commit 46dfcfcfe92aa43d6f7b662f125d97f38c1d6375
Author: Tobias Diedrich <ranma+openocd at tdiedrich.de>
Date:   Sun Feb 12 13:35:37 2017 +0100

    ec/lenovo/h8: Guard against EC bugs in the battery status logic.
    
    On my Thinkpad with an H8-compatible ENE KB9012 EC (GDHT92WW 1.52), when
    the battery is nearly full and we switch from battery to AC by plugging
    in the cable, the current rate will not drop to 0 immediately, but the
    discharging state is cleared immediately.
    
    This leads to the code trying to process an invalid rate value >0x8000,
    leading to a displayed rate of >1000W.
    
    This patch changes the logic to deal with these corner cases.
    
    Change-Id: Ideb588d00757f259792e5ae97729e371b63a096c
    Signed-off-by: Tobias Diedrich <ranma+coreboot at tdiedrich.de>
---
 src/ec/lenovo/h8/acpi/battery.asl | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/ec/lenovo/h8/acpi/battery.asl b/src/ec/lenovo/h8/acpi/battery.asl
index 629397a..111f29f 100644
--- a/src/ec/lenovo/h8/acpi/battery.asl
+++ b/src/ec/lenovo/h8/acpi/battery.asl
@@ -105,21 +105,36 @@ Method(BSTA, 4, NotSerialized)
 	Store(BAMA, Local1)
 	^BPAG(Arg0) /* Battery dynamic information */
 
+	/*
+	 * Present rate is a 16bit signed int, positive while charging
+	 * and negative while discharging.
+	 */
 	Store(BAPR, Local2)
 
-	if (Arg2) // charging
+	If (Arg2) // Charging
 	{
 		Or(2, Local0, Local0)
-
-		If (LGreaterEqual (Local2, 0x8000)) {
+	}
+	Else
+	{
+		If (Arg3) // Discharging
+		{
+			Or(1, Local0, Local0)
+			// Negate present rate
+			Subtract(0x10000, Local2, Local2)
+		}
+		Else // Full battery, force to 0
+		{
 			Store(0, Local2)
 		}
 	}
 
-	if (Arg3) // discharging
-	{
-		Or(1, Local0, Local0)
-		Subtract(0x10000, Local2, Local2)
+	/*
+	 * The present rate value must be positive now, if it is not we have an
+	 * EC bug or inconsistency and force the value to 0.
+	 */
+	If (LGreaterEqual (Local2, 0x8000)) {
+		Store(0, Local2)
 	}
 
 	Store(Local0, Index(Arg1, 0x00))



More information about the coreboot-gerrit mailing list