diff options
-rw-r--r-- | driver/ln9310.c | 26 | ||||
-rw-r--r-- | include/driver/ln9310.h | 6 |
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 |