Skip to content

Commit

Permalink
Remember whether we cut power to ourselves, and re-check during boot
Browse files Browse the repository at this point in the history
On the hx20 (and presumably hx30,) a design issue prevents us from
hibernating the EC properly. Therefore, every time we bring the machine
down we cut power instead of hibernating. That results in the next boot
being a complete reset.

There is code in lfw that checks whether the current boot is due to a
watchdog reset or a power-on reset and if it is, clears the image type
back to EC_IMAGE_UNKNOWN. Due to that design issue, the hx20 EC is
*always* in POR/VTR or WDT on startup.

By storing whether the last shutdown was graceful/intended and checking
it before resetting the image type, we can work around this issue.
  • Loading branch information
DHowett committed Jan 23, 2023
1 parent 7f78c55 commit 4ed2983
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions board/hx20/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ static void board_power_off_deferred(void)
charger_psys_enable(0);
charge_gate_onoff(0);

MCHP_VBAT_RAM(MCHP_IMAGETYPE_IDX) |= 0x80;

/* Disable interrupts */
interrupt_disable();
for (i = 0; i < MCHP_IRQ_MAX; ++i) {
Expand Down
14 changes: 13 additions & 1 deletion chip/mchp/lfw/ec_lfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,26 @@ void system_init(void)
uint32_t wdt_sts = MCHP_VBAT_STS & MCHP_VBAT_STS_ANY_RST;
uint32_t rst_sts = MCHP_PCR_PWR_RST_STS &
MCHP_PWR_RST_STS_VTR;
/*
* **HX20**: We can't hibernate the EC without also keeping
* 5v3v ALW on, so we cut power entirely. Unfortunately,
* that means that one of rst_sts or wdt_sts will always be
* on... and that precludes the use of the RW firmware.
* However, if we store a bit in IMAGETYPE to indicate that
* we cut power to ourselves, we can use it at the next boot
* to determine whether this poweroff was EC-origin or not.
*/
bool wacked = (MCHP_VBAT_RAM(MCHP_IMAGETYPE_IDX) & 0x80) != 0;

trace12(0, LFW, 0,
"VBAT_STS = 0x%08x PCR_PWR_RST_STS = 0x%08x",
wdt_sts, rst_sts);

if (rst_sts || wdt_sts)
if ((rst_sts || wdt_sts) && !wacked)
MCHP_VBAT_RAM(MCHP_IMAGETYPE_IDX)
= EC_IMAGE_UNKNOWN;

MCHP_VBAT_RAM(MCHP_IMAGETYPE_IDX) &= 0x7F;
}

enum ec_image system_get_image_copy(void)
Expand Down

0 comments on commit 4ed2983

Please sign in to comment.