From 68ad3ed09773011ab15e9dd50f9ec2bbf817ef3f Mon Sep 17 00:00:00 2001 From: Lucien Mueller Date: Wed, 9 Jun 2021 14:52:15 +0200 Subject: [PATCH] hw23: add shutdown on power-up when ignition is down. BugzID: 73163 Signed-off-by: Lucien Mueller --- board/netmodule/imx8_nmhw23/imx8_nmhw23.c | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/board/netmodule/imx8_nmhw23/imx8_nmhw23.c b/board/netmodule/imx8_nmhw23/imx8_nmhw23.c index 80bb935791..06fd934876 100644 --- a/board/netmodule/imx8_nmhw23/imx8_nmhw23.c +++ b/board/netmodule/imx8_nmhw23/imx8_nmhw23.c @@ -559,6 +559,51 @@ int board_mmc_get_env_dev(int devno) return devno; } +static void powerdown(void) +{ + /* Final call, will not return */ + (void)da9063_set_reg(PMIC_REG_CONTROL_A, 0x00); + + puts("ERROR: PMIC power down failed\n"); + for (;;) {} +} + +static void stop_if_ignition_is_off(void) +{ + uint8_t state = 0x00; + int ret; + + ret = da9063_get_reg(PMIC_REG_STATUS_A, &state); + if (ret == 0) { + if ((state & PMIC_REG_STATUS_A_COMP1V2_MASK) == PMIC_REG_STATUS_A_COMP1V2_MASK) { + puts("Ignition : On\n"); + } + else { + puts("Ignition : Off\n"); + /* + * Ignition is off, if this is a power-on start, power down + * as this is considered an unwanted system start. + */ + + /* + * There is a chance for a race condition, when ignition is enabled + * between the check above and here. In this case we should just reset + * not power down. + * Although the risk is minimal here due to the very short time interval + * we do the check. The same logic will have to be added in other + * components. + */ + ret = da9063_get_reg(PMIC_REG_EVENT_B, &state); + if ((ret == 0) && ((state & PMIC_REG_EVENT_COMP1V2_MASK) == 0)) { + powerdown(); + } + else { + reset_cpu(0); + } + } + } +} + static void check_reset_reason(uint64_t reset_reason_shm_location) { volatile struct reset_registers* reset_regs = (struct reset_registers*)reset_reason_shm_location; @@ -695,6 +740,10 @@ static void check_reset_reason(uint64_t reset_reason_shm_location) rr_start_reason_to_str(reset_regs->sr_events, strbuf, sizeof(strbuf)); printf("\nStart Events: %s\n", strbuf); + + if (sys_start_event & SR_POR) { + stop_if_ignition_is_off(); + } } static int _bd_init(void)