From 17bb02cc7484f9e420d6a9aa93d2db0c3bc94e9c Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Fri, 11 Feb 2022 01:36:08 +0000 Subject: CTN730: Enter download mode for FW corruption When there is FW corruption, CTN730 switch from normal mode to download mode. The chip sends a reset event with WLC_HOST_CTRL_RESET_EVT_DOWNLOAD_MODE. We currently handle it as a reset event without switching to download mode. A reset event handler in normal mode resets the chip to normal mode, thus, causing a reset loop. This patche makes the reset event handler switch the internal state to PCHG_MODE_DOWNLOAD if WLC_HOST_CTRL_RESET_EVT_DOWNLOAD_MODE is found. This will allow the PCHG state machine to avoid an infinite reset loop and stay in PCHG_STATE_DOWNLOAD. BUG=b:210796767, b:207479211 BRANCH=None TEST=Redrix Change-Id: I71c5e3ceb05d735b5465f4f00ac371bae7db34b1 Signed-off-by: Daisuke Nojiri Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3454216 Tested-by: Devin Lu Reviewed-by: caveh jalali --- driver/nfc/ctn730.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/driver/nfc/ctn730.c b/driver/nfc/ctn730.c index 6f711c509e..775149e659 100644 --- a/driver/nfc/ctn730.c +++ b/driver/nfc/ctn730.c @@ -390,6 +390,17 @@ static int _process_payload_event(struct pchg *ctx, struct ctn730_msg *res) CPRINTS("Download Mode (%s)", _text_reset_reason(buf[1])); ctx->event = PCHG_EVENT_RESET; + /* + * CTN730 sends a reset event to notify us it entered + * download mode unintentionally (e.g. corrupted FW). + * In such cases, we stay in download mode to avoid an + * infinite loop. + * + * If it's intended, we leave alone the mode, respecting + * the mode set by the PCHG task. + */ + if (buf[1] != WLC_HOST_CTRL_RESET_REASON_INTENDED) + ctx->mode = PCHG_MODE_DOWNLOAD; } else { return EC_ERROR_INVAL; } -- cgit v1.2.1