diff options
author | Jett Rink <jettrink@chromium.org> | 2018-04-30 10:31:57 -0600 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-05-01 02:13:29 -0700 |
commit | a5695793ba99a4b2af8f95e31a3a8ba23df4d567 (patch) | |
tree | 00d0804ff40277a3b993a3e101eee06d7ffd2e9f | |
parent | bbb5edb220834dc563893311fc371526087af708 (diff) | |
download | chrome-ec-a5695793ba99a4b2af8f95e31a3a8ba23df4d567.tar.gz |
anx7447: convert automatic OCM erase into command
We do not want to erase the OCM flash automatically so we
can ensure that we fix our supply chain issues. Add a command
that will erase the OCM if needed.
BRANCH=none
BUG=b:77658388
TEST=verified command works on yorp
Change-Id: Iaf6ada3b1e223d15ae0d9624bdcc54b90cb33b64
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1035428
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
-rw-r--r-- | board/nami/board.h | 2 | ||||
-rw-r--r-- | board/yorp/board.h | 2 | ||||
-rw-r--r-- | driver/tcpm/anx7447.c | 61 | ||||
-rw-r--r-- | driver/tcpm/anx7447.h | 4 | ||||
-rw-r--r-- | include/config.h | 8 |
5 files changed, 49 insertions, 28 deletions
diff --git a/board/nami/board.h b/board/nami/board.h index e7ed9e3a44..c15295ff21 100644 --- a/board/nami/board.h +++ b/board/nami/board.h @@ -156,7 +156,7 @@ #define CONFIG_USB_PD_TCPM_MUX #define CONFIG_USB_PD_TCPM_TCPCI #define CONFIG_USB_PD_TCPM_ANX7447 -#define CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE +#define CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE_COMMAND #define CONFIG_USB_PD_TCPM_PS8751 #define CONFIG_USB_PD_TRY_SRC #define CONFIG_USB_POWER_DELIVERY diff --git a/board/yorp/board.h b/board/yorp/board.h index ccf9efcdf0..b25269e003 100644 --- a/board/yorp/board.h +++ b/board/yorp/board.h @@ -84,7 +84,7 @@ #undef CONFIG_USB_PD_TCPC_LOW_POWER #undef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE #define CONFIG_USB_PD_TCPM_ANX7447 /* C0 TCPC: ANX7447QN */ -#define CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE +#define CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE_COMMAND #define CONFIG_USB_PD_TCPM_PS8751 /* C1 TCPC: PS8751 */ #define CONFIG_USB_PD_TCPM_MUX #define CONFIG_USB_PD_TCPM_TCPCI diff --git a/driver/tcpm/anx7447.c b/driver/tcpm/anx7447.c index 9b7fb8dafa..cb4e4522fa 100644 --- a/driver/tcpm/anx7447.c +++ b/driver/tcpm/anx7447.c @@ -36,9 +36,6 @@ struct anx_state { int i2c_slave_addr; int mux_state; -#ifdef CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE - int flash_checked_once; -#endif }; static struct anx_state anx[CONFIG_USB_PD_PORT_COUNT]; @@ -114,7 +111,7 @@ void anx7447_set_hpd_level(int port, int hpd_lvl) anx7447_reg_write(port, ANX7447_REG_HPD_CTRL_0, reg); } -#ifdef CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE +#ifdef CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE_COMMAND static inline void anx7447_reg_write_and(int port, int reg, int v_and) { int val; @@ -182,8 +179,11 @@ static void anx7447_flash_check(int port) tcpc_read(port, TCPC_REG_COMMAND, &r); usleep(ANX7447_DELAY_IN_US); - if (anx7447_flash_is_empty(port) == 1) + if (anx7447_flash_is_empty(port) == 1) { + ccprintf("C%d: Nothing to erase!\n", port); return; + } + ccprintf("C%d: Erasing ANX7447 OCM flash...\n", port); anx7447_flash_op_init(port); @@ -197,9 +197,37 @@ static void anx7447_flash_check(int port) do { anx7447_reg_read(port, ANX7447_REG_R_RAM_CTRL, &r); } while (!(r & ANX7447_R_RAM_CTRL_FLASH_DONE)); +} + +/* Add console command to erase OCM flash if needed. */ +static int command_anx_ocm(int argc, char **argv) +{ + char *e = NULL; + int port; + + if (argc < 2) + return EC_ERROR_PARAM_COUNT; + + /* Get port number from first parameter */ + port = strtoi(argv[1], &e, 0); + if (*e) + return EC_ERROR_PARAM1; + + if (argc > 2) { + if (!strcasecmp(argv[2], "erase")) + anx7447_flash_check(port); + else + return EC_ERROR_PARAM2; + } - ccprintf("anx7447: OCM flash checked and erased\n"); + ccprintf("C%d: OCM flash is %sempty.\n", + port, anx7447_flash_is_empty(port) ? "" : "not "); + + return EC_SUCCESS; } +DECLARE_CONSOLE_COMMAND(anx_ocm, command_anx_ocm, + "port [erase]", + "Print OCM status or erases OCM for a given port."); #endif static int anx7447_init(int port) @@ -226,24 +254,17 @@ static int anx7447_init(int port) return EC_ERROR_UNKNOWN; } -#ifdef CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE - /* - * The ANX7447 has an on chip microcontroller (OCM) that can provide USB - * PD functionality. If the OCM is active, then it can interfere with - * getting alerts from the TCPC when PD messages are received. Check to - * see if the flash is not erased, and if not, then erase the OCM - * flash. This status is saved in a static variable so this check only - * happens once per EC reboot. - */ - if (anx[port].flash_checked_once == 0) { - anx7447_flash_check(port); - anx[port].flash_checked_once = 1; - } -#endif + rv = tcpci_tcpm_init(port); if (rv) return rv; +#ifdef CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE_COMMAND + /* Check and print OCM status to console. */ + ccprintf("C%d: OCM flash is %sempty.\n", + port, anx7447_flash_is_empty(port) ? "" : "not "); +#endif + /* * 7447 has a physical pin to detect the presence of VBUS, VBUS_SENSE * , and 7447 has a VBUS current protection mechanism through another diff --git a/driver/tcpm/anx7447.h b/driver/tcpm/anx7447.h index eac4057967..6998723f7b 100644 --- a/driver/tcpm/anx7447.h +++ b/driver/tcpm/anx7447.h @@ -33,7 +33,7 @@ /* * This section of defines are only required to support the config option - * CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE. + * CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE_COMMAND. */ /* SPI registers used for OCM flash operations */ #define ANX7447_DELAY_IN_US (20*1000) @@ -70,7 +70,7 @@ /* ADDR_GPIO_CTRL_0 bit definitions */ #define ANX7447_ADDR_GPIO_CTRL_0_SPI_WP (1<<7) #define ANX7447_ADDR_GPIO_CTRL_0_SPI_CLK_ENABLE (1<<6) -/* End of defines used for CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE */ +/* End of defines used for CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE_COMMAND */ struct anx7447_i2c_addr { int tcpc_slave_addr; diff --git a/include/config.h b/include/config.h index 03d03b1799..eb619b7cc9 100644 --- a/include/config.h +++ b/include/config.h @@ -2881,11 +2881,11 @@ #undef CONFIG_USB_PD_TCPM_PS8805 /* - * Check the ANX7447 OCM flash at initialization time. If not erased, will then - * erase the OCM flash. (note this is intended to be a temporary option and - * won't be needed when ANX7447 are put on boards with OCM already erased) + * Adds an EC console command to erase the ANX7447 OCM flash. + * Note: this is intended to be a temporary option and + * won't be needed when ANX7447 are put on boards with OCM already erased */ -#undef CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE +#undef CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE_COMMAND /* * Use this option if the TCPC port controller supports the optional register |