summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Crossley <crossley@lionsemi.corp-partner.google.com>2021-05-06 17:03:32 +0000
committerCommit Bot <commit-bot@chromium.org>2021-05-07 04:16:35 +0000
commitab745b89a9efb81aac73f8c5bcfe8a8ff60e857d (patch)
tree66d92271be5081e20203f0eff0b8fe4bb69df97f
parent13b2bbc4f99c7e21a913c439a99cd1bdb402e45b (diff)
downloadchrome-ec-ab745b89a9efb81aac73f8c5bcfe8a8ff60e857d.tar.gz
ln9310: check software workaround is in place for every power-up
Current software sets some registers only during initial powering of LN9310 (when battery is plugged in). If LN9310 was reset for any reason and then a system power on was attempted (power button press), then LN9310 would attempt a startup without the workaround (bad idea). This change adds a check before every LN9310 enable/disable event and re-initializes LN9310 if a reset has occurred . BRANCH=Trogdor BUG=b:185308433 TEST=Should not break the current boot flow, i.e. power-up and power-down (using long-press of the power button) should function Change-Id: I98c08f50bfd48e09776033eac64658f6e27fb58f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2876869 Reviewed-by: John Crossley <crossley@lionsemi.corp-partner.google.com> Reviewed-by: Wai-Hong Tam <waihong@google.com> Commit-Queue: John Crossley <crossley@lionsemi.corp-partner.google.com> Tested-by: John Crossley <crossley@lionsemi.corp-partner.google.com>
-rw-r--r--driver/ln9310.c26
-rw-r--r--include/driver/ln9310.h6
2 files changed, 31 insertions, 1 deletions
diff --git a/driver/ln9310.c b/driver/ln9310.c
index d339c228a2..d9fc5c85ca 100644
--- a/driver/ln9310.c
+++ b/driver/ln9310.c
@@ -116,6 +116,29 @@ static int is_battery_gt_10v(void)
return gt_10v;
}
+static int ln9310_reset_detected(void)
+{
+ /*
+ * Check LN9310_REG_LION_CTRL to see if it has been reset to 0x0.
+ * ln9310_init() and all other functions will set this register
+ * to a non-zero value so it should only become 0 again if LN9310
+ * is reset.
+ */
+ int val, status, reset_detected;
+
+ status = raw_read8(LN9310_REG_LION_CTRL, &val);
+ if (status) {
+ CPRINTS("LN9310 reading LN9310_REG_LION_CTRL failed");
+ /* If read fails, safest to assume reset has occurred */
+ return 1;
+ }
+ reset_detected = (val == 0x0);
+ if (reset_detected) {
+ CPRINTS("LN9310 was reset (possibly in error)");
+ }
+ return reset_detected;
+}
+
static int ln9310_update_startup_seq(void)
{
CPRINTS("LN9310 update startup sequence");
@@ -467,6 +490,9 @@ void ln9310_software_enable(int enable)
* ln9310_software_enable(0) - reset LN9310 register to state necessary
* for subsequent startups
*/
+ if (ln9310_reset_detected())
+ ln9310_init();
+
/* Dummy clear all interrupts */
status = raw_read8(LN9310_REG_INT1, &val);
if (status) {
diff --git a/include/driver/ln9310.h b/include/driver/ln9310.h
index e4bd0bc7e0..59ae888781 100644
--- a/include/driver/ln9310.h
+++ b/include/driver/ln9310.h
@@ -134,7 +134,11 @@
#define LN9310_LION_CTRL_MASK 0xFF
#define LN9310_LION_CTRL_UNLOCK_AND_EN_TM 0xAA
#define LN9310_LION_CTRL_UNLOCK 0x5B
-#define LN9310_LION_CTRL_LOCK 0x00
+/*
+ * value changed to 0x22 to distinguish from reset value of 0x00
+ * 0x22 and 0x00 are functionally equivalent within LN9310
+ */
+#define LN9310_LION_CTRL_LOCK 0x22
#define LN9310_REG_CFG_0 0x3C
#define LN9310_CFG_0_LS_HELPER_IDLE_MSK_MASK 0x20