summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Wang <matt_wang@compal.corp-partner.google.com>2022-10-26 15:37:00 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-11-09 02:49:01 +0000
commit7063dd20c35b905248bd76bf84310d64625f54fd (patch)
tree4db5013e390c3258959ea2dcfe0bbb1099f74bfc
parentc0b5a7d0405289beae2af1cd6edde3a0b86cec17 (diff)
downloadchrome-ec-7063dd20c35b905248bd76bf84310d64625f54fd.tar.gz
winterhold: fix battery cannot be charged
After battery is over-drained, EC_BATT_PRES_ODL will be always high cause EC won't wake battery. BUG=b:249438144 BRANCH=none TEST=zmake build winterhold successfully TEST=winterhold can boot up to OS from battery cut off TEST=use the battery cell voltage less than 2.5V can boot to OS LOW_COVERAGE_REASON=Skyrim board not create the battery hw present function Signed-off-by: Matt Wang <matt_wang@compal.corp-partner.google.com> Change-Id: I02a7da58d51693595fc7bb18d01e8e12a5f42908 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3980937 Reviewed-by: Diana Z <dzigterman@chromium.org> Reviewed-by: Elthan Huang <elthan_huang@compal.corp-partner.google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r--zephyr/program/skyrim/CMakeLists.txt1
-rw-r--r--zephyr/program/skyrim/gpio.dts2
-rw-r--r--zephyr/program/skyrim/prj.conf1
-rw-r--r--zephyr/program/skyrim/prj_frostflow.conf3
-rw-r--r--zephyr/program/skyrim/prj_morthal.conf3
-rw-r--r--zephyr/program/skyrim/prj_skyrim.conf3
-rw-r--r--zephyr/program/skyrim/prj_winterhold.conf3
-rw-r--r--zephyr/program/skyrim/src/winterhold/battery_present.c81
8 files changed, 95 insertions, 2 deletions
diff --git a/zephyr/program/skyrim/CMakeLists.txt b/zephyr/program/skyrim/CMakeLists.txt
index cfa4a22a0b..cf357a4a0a 100644
--- a/zephyr/program/skyrim/CMakeLists.txt
+++ b/zephyr/program/skyrim/CMakeLists.txt
@@ -46,6 +46,7 @@ if(DEFINED CONFIG_BOARD_WINTERHOLD)
"src/winterhold/kb_backlight.c"
"src/winterhold/keyboard.c"
"src/winterhold/sensor.c"
+ "src/winterhold/battery_present.c"
)
endif()
diff --git a/zephyr/program/skyrim/gpio.dts b/zephyr/program/skyrim/gpio.dts
index 57abcc846d..2b79bad222 100644
--- a/zephyr/program/skyrim/gpio.dts
+++ b/zephyr/program/skyrim/gpio.dts
@@ -118,7 +118,7 @@
gpios = <&gpio0 2 GPIO_INPUT>;
enum-name = "GPIO_LID_OPEN";
};
- ec_batt_pres_odl {
+ gpio_ec_batt_pres_odl: ec_batt_pres_odl {
gpios = <&gpio9 4 GPIO_INPUT>;
enum-name = "GPIO_BATT_PRES_ODL";
};
diff --git a/zephyr/program/skyrim/prj.conf b/zephyr/program/skyrim/prj.conf
index a0085258e4..760f1f3275 100644
--- a/zephyr/program/skyrim/prj.conf
+++ b/zephyr/program/skyrim/prj.conf
@@ -85,7 +85,6 @@ CONFIG_PLATFORM_EC_BATTERY=y
CONFIG_PLATFORM_EC_BATTERY_SMART=y
CONFIG_PLATFORM_EC_BATTERY_FUEL_GAUGE=y
CONFIG_PLATFORM_EC_BATTERY_CUT_OFF=y
-CONFIG_PLATFORM_EC_BATTERY_PRESENT_GPIO=y
CONFIG_PLATFORM_EC_BATTERY_REVIVE_DISCONNECT=y
# Charger
diff --git a/zephyr/program/skyrim/prj_frostflow.conf b/zephyr/program/skyrim/prj_frostflow.conf
index 29931de4d4..d347d3e435 100644
--- a/zephyr/program/skyrim/prj_frostflow.conf
+++ b/zephyr/program/skyrim/prj_frostflow.conf
@@ -28,3 +28,6 @@ CONFIG_PLATFORM_EC_KEYBOARD_CUSTOMIZATION=y
# Frostflow not have the USB HUB
CONFIG_BOARD_USB_HUB_RESET=n
+
+# Battery
+CONFIG_PLATFORM_EC_BATTERY_PRESENT_GPIO=y
diff --git a/zephyr/program/skyrim/prj_morthal.conf b/zephyr/program/skyrim/prj_morthal.conf
index 3d2b3fddb7..f0833418ca 100644
--- a/zephyr/program/skyrim/prj_morthal.conf
+++ b/zephyr/program/skyrim/prj_morthal.conf
@@ -21,3 +21,6 @@ CONFIG_PLATFORM_EC_PD_MAX_VOLTAGE_MV=20000
CONFIG_PLATFORM_EC_TEMP_SENSOR_PCT2075=y
CONFIG_PLATFORM_EC_USBC_RETIMER_ANX7483=y
+
+# Battery
+CONFIG_PLATFORM_EC_BATTERY_PRESENT_GPIO=y
diff --git a/zephyr/program/skyrim/prj_skyrim.conf b/zephyr/program/skyrim/prj_skyrim.conf
index 2752854c8b..0ebd1e91fa 100644
--- a/zephyr/program/skyrim/prj_skyrim.conf
+++ b/zephyr/program/skyrim/prj_skyrim.conf
@@ -24,3 +24,6 @@ CONFIG_PLATFORM_EC_USBC_RETIMER_ANX7483=y
# Enable alternative charger chip
CONFIG_PLATFORM_EC_CHARGER_RUNTIME_CONFIG=y
CONFIG_PLATFORM_EC_CHARGER_ISL9238C=y
+
+# Battery
+CONFIG_PLATFORM_EC_BATTERY_PRESENT_GPIO=y
diff --git a/zephyr/program/skyrim/prj_winterhold.conf b/zephyr/program/skyrim/prj_winterhold.conf
index 81fd9f367e..4501e0e6ff 100644
--- a/zephyr/program/skyrim/prj_winterhold.conf
+++ b/zephyr/program/skyrim/prj_winterhold.conf
@@ -39,3 +39,6 @@ CONFIG_PLATFORM_EC_LID_ANGLE_UPDATE=n
CONFIG_PLATFORM_EC_TABLET_MODE=n
CONFIG_PLATFORM_EC_TABLET_MODE_SWITCH=n
CONFIG_PLATFORM_EC_GMR_TABLET_MODE=n
+
+# Battery
+CONFIG_PLATFORM_EC_BATTERY_HW_PRESENT_CUSTOM=y
diff --git a/zephyr/program/skyrim/src/winterhold/battery_present.c b/zephyr/program/skyrim/src/winterhold/battery_present.c
new file mode 100644
index 0000000000..eb5a5bba90
--- /dev/null
+++ b/zephyr/program/skyrim/src/winterhold/battery_present.c
@@ -0,0 +1,81 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include <zephyr/drivers/gpio.h>
+
+#include "battery.h"
+#include "battery_smart.h"
+#include "common.h"
+
+static enum battery_present batt_pres_prev = BP_NOT_SURE;
+
+__overridable bool board_battery_is_initialized(void)
+{
+ int batt_status;
+
+ return battery_status(&batt_status) != EC_SUCCESS ?
+ false :
+ !!(batt_status & STATUS_INITIALIZED);
+}
+
+/*
+ * Physical detection of battery.
+ */
+static enum battery_present battery_check_present_status(void)
+{
+ enum battery_present batt_pres;
+
+ if (battery_is_cut_off())
+ return BP_NO;
+
+ /* Get the physical hardware status */
+ batt_pres = battery_hw_present();
+
+ /*
+ * If the battery is not physically connected, then no need to perform
+ * any more checks.
+ */
+ if (batt_pres == BP_NO)
+ return BP_NO;
+
+ /*
+ * If the battery is present now and was present last time we checked,
+ * return early.
+ */
+ if ((batt_pres == BP_YES) && (batt_pres == batt_pres_prev))
+ return BP_YES;
+
+ /*
+ * Check battery initialization. If the battery is not initialized,
+ * then return BP_NOT_SURE. Battery could be in ship
+ * mode and might require pre-charge current to wake it up. BP_NO is not
+ * returned here because charger state machine will not provide
+ * pre-charge current assuming that battery is not present.
+ */
+ if (!board_battery_is_initialized())
+ return BP_NOT_SURE;
+
+ return BP_YES;
+}
+
+enum battery_present battery_is_present(void)
+{
+ batt_pres_prev = battery_check_present_status();
+ return batt_pres_prev;
+}
+
+enum battery_present battery_hw_present(void)
+{
+ const struct gpio_dt_spec *batt_pres;
+
+ batt_pres = GPIO_DT_FROM_NODELABEL(gpio_ec_batt_pres_odl);
+
+ /*
+ * The GPIO is low when the battery is physically present.
+ * But if battery cell voltage < 2.5V, it will not able to
+ * pull down EC_BATT_PRES_ODL. So we need to set pre-charge
+ * current even EC_BATT_PRES_ODL is high.
+ */
+ return gpio_pin_get_dt(batt_pres) ? BP_NOT_SURE : BP_YES;
+}