summaryrefslogtreecommitdiff
path: root/baseboard/octopus
diff options
context:
space:
mode:
authorEdward Hill <ecgh@chromium.org>2018-06-12 14:55:14 -0600
committerchrome-bot <chrome-bot@chromium.org>2018-06-14 05:38:34 -0700
commitb4f69d8a0cf5c4bc55880befe7cd995b1ddd2926 (patch)
treec09f25cd7935819fad2c0ed970af399a218a562f /baseboard/octopus
parent2b0918db5c3c4181410bc97e98a27db20fd622d9 (diff)
downloadchrome-ec-b4f69d8a0cf5c4bc55880befe7cd995b1ddd2926.tar.gz
battery: Move presence checks out of common
Undo some of CL:1072637 so that battery_is_present() and battery_hw_present() move back to baseboard. battery_fuel_gauge.c now only includes code which is directly involved with the fuel gauge. BUG=b:109894491,b:80299100 BRANCH=none TEST=make -j buildall Change-Id: I8fc5be3856564601019d94514dcfc8ffb3071c2e Signed-off-by: Edward Hill <ecgh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1097954 Commit-Ready: Devin Lu <Devin.Lu@quantatw.com> Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'baseboard/octopus')
-rw-r--r--baseboard/octopus/battery.c69
-rw-r--r--baseboard/octopus/build.mk1
2 files changed, 70 insertions, 0 deletions
diff --git a/baseboard/octopus/battery.c b/baseboard/octopus/battery.c
new file mode 100644
index 0000000000..835132366b
--- /dev/null
+++ b/baseboard/octopus/battery.c
@@ -0,0 +1,69 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Battery pack vendor provided charging profile
+ */
+
+#include "battery.h"
+#include "battery_smart.h"
+#include "gpio.h"
+
+static enum battery_present batt_pres_prev = BP_NOT_SURE;
+
+enum battery_present battery_hw_present(void)
+{
+ /* The GPIO is low when the battery is physically present */
+ return gpio_get_level(GPIO_EC_BATT_PRES_L) ? BP_NO : BP_YES;
+}
+
+static int battery_init(void)
+{
+ int batt_status;
+
+ return battery_status(&batt_status) ? 0 :
+ !!(batt_status & STATUS_INITIALIZED);
+}
+
+/*
+ * Physical detection of battery.
+ */
+static enum battery_present battery_check_present_status(void)
+{
+ enum battery_present batt_pres;
+
+ /* 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_YES)
+ return batt_pres;
+
+ /*
+ * If the battery is present now and was present last time we checked,
+ * return early.
+ */
+ if (batt_pres == batt_pres_prev)
+ return batt_pres;
+
+ /*
+ * Ensure that battery is:
+ * 1. Not in cutoff
+ * 2. Initialized
+ */
+ if (battery_is_cut_off() != BATTERY_CUTOFF_STATE_NORMAL ||
+ battery_init() == 0) {
+ batt_pres = BP_NO;
+ }
+
+ return batt_pres;
+}
+
+enum battery_present battery_is_present(void)
+{
+ batt_pres_prev = battery_check_present_status();
+ return batt_pres_prev;
+}
diff --git a/baseboard/octopus/build.mk b/baseboard/octopus/build.mk
index 2bf9b7b83d..3189d7cb07 100644
--- a/baseboard/octopus/build.mk
+++ b/baseboard/octopus/build.mk
@@ -7,6 +7,7 @@
#
baseboard-y=baseboard.o
+baseboard-$(CONFIG_BATTERY_SMART)+=battery.o
baseboard-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o
baseboard-$(VARIANT_OCTOPUS_EC_NPCX796FB)+=variant_ec_npcx796fb.o
baseboard-$(VARIANT_OCTOPUS_EC_ITE8320)+=variant_ec_ite8320.o