From a4e75ab0cd7895d9b9b8d1219da75021ce2ebf36 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Fri, 18 Sep 2020 13:37:15 -0600 Subject: [PATCH] ec/system76/ec: Add battery charging thresholds System76 EC firmware supports setting charging thresholds for a single battery. Change-Id: I3d656291c096f320d469274677e9fe6c74819d25 Signed-off-by: Tim Crawford Reviewed-on: https://review.coreboot.org/c/coreboot/+/45532 Reviewed-by: Jeremy Soller Tested-by: build bot (Jenkins) --- src/ec/system76/ec/Kconfig | 5 ++ .../system76/ec/acpi/battery_thresholds.asl | 46 +++++++++++++++++++ src/ec/system76/ec/acpi/ec.asl | 4 ++ 3 files changed, 55 insertions(+) create mode 100644 src/ec/system76/ec/acpi/battery_thresholds.asl diff --git a/src/ec/system76/ec/Kconfig b/src/ec/system76/ec/Kconfig index fea4743593..8c9030e599 100644 --- a/src/ec/system76/ec/Kconfig +++ b/src/ec/system76/ec/Kconfig @@ -3,6 +3,11 @@ config EC_SYSTEM76_EC help System76 EC +config EC_SYSTEM76_EC_BAT_THRESHOLDS + depends on EC_SYSTEM76_EC + bool + default n + config EC_SYSTEM76_EC_COLOR_KEYBOARD depends on EC_SYSTEM76_EC bool diff --git a/src/ec/system76/ec/acpi/battery_thresholds.asl b/src/ec/system76/ec/acpi/battery_thresholds.asl new file mode 100644 index 0000000000..3bb1330fbf --- /dev/null +++ b/src/ec/system76/ec/acpi/battery_thresholds.asl @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +Field (ERAM, ByteAcc, Lock, Preserve) +{ + Offset (0xBC), + BTL0, 8, /* BAT0 charging start threshold */ + BTH0, 8, /* BAT0 charging end threshold */ +} + +/* + * Get battery charging threshold + * + * Arg0: 0: Start threshold + * 1: Stop threshold + */ +Method (GBCT, 1, NotSerialized) +{ + If (Arg0 == 0) { + Return (BTL0) + } + + If (Arg0 == 1) { + Return (BTH0) + } + + Return (0xFF) +} + +/* + * Set battery charging threshold + * + * Arg0: 0: Start threshold + * 1: Stop threshold + * Arg1: Percentage + */ +Method (SBCT, 2, NotSerialized) +{ + If (Arg1 <= 100) { + If (Arg0 == 0) { + BTL0 = Arg1 + } + If (Arg0 == 1) { + BTH0 = Arg1 + } + } +} diff --git a/src/ec/system76/ec/acpi/ec.asl b/src/ec/system76/ec/acpi/ec.asl index 98abc66e9e..128bd56304 100644 --- a/src/ec/system76/ec/acpi/ec.asl +++ b/src/ec/system76/ec/acpi/ec.asl @@ -227,4 +227,8 @@ Device (\_SB.PCI0.LPCB.EC0) Debug = Concatenate("EC: Other: ", ToHexString(Local0)) } } + + #if CONFIG(EC_SYSTEM76_EC_BAT_THRESHOLDS) + #include "battery_thresholds.asl" + #endif }