diff --git a/board/cr50/board.c b/board/cr50/board.c index 3146b9edb1..956d7283c1 100644 --- a/board/cr50/board.c +++ b/board/cr50/board.c @@ -80,6 +80,43 @@ uint32_t nvmem_user_sizes[NVMEM_NUM_USERS] = { static uint32_t board_properties; static uint8_t reboot_request_posted; +/* + * Bit assignments of the LONG_LIFE_SCRATCH1 register. This register survives + * all kinds of resets, it is cleared only on the Power ON event. + */ +#define BOARD_SLAVE_CONFIG_SPI (1 << 0) /* TPM uses SPI interface */ +#define BOARD_SLAVE_CONFIG_I2C (1 << 1) /* TPM uses I2C interface */ +#define BOARD_USB_AP (1 << 2) /* One of the USB PHYs is */ + /* connected to the AP */ + +/* TODO(crosbug.com/p/56945): Remove when sys_rst_l has an external pullup */ +#define BOARD_NEEDS_SYS_RST_PULL_UP (1 << 5) /* Add a pullup to sys_rst_l */ +#define BOARD_USE_PLT_RESET (1 << 6) /* Platform reset exists */ +int board_has_ap_usb(void) +{ + return !!(board_properties & BOARD_USB_AP); +} + +int board_has_plt_rst(void) +{ + return !!(board_properties & BOARD_USE_PLT_RESET); +} + +int board_rst_pullup_needed(void) +{ + return !!(board_properties & BOARD_NEEDS_SYS_RST_PULL_UP); +} + +int board_tpm_uses_i2c(void) +{ + return !!(board_properties & BOARD_SLAVE_CONFIG_I2C); +} + +int board_tpm_uses_spi(void) +{ + return !!(board_properties & BOARD_SLAVE_CONFIG_SPI); +} + /* I2C Port definition */ const struct i2c_port_t i2c_ports[] = { {"master", I2C_PORT_MASTER, 100, @@ -210,7 +247,7 @@ void board_configure_deep_sleep_wakepins(void) * If the board includes plt_rst_l, configure Cr50 to resume on the * rising edge of this signal. */ - if (system_get_board_properties() & BOARD_USE_PLT_RESET) { + if (board_has_plt_rst()) { /* Disable sys_rst_l as a wake pin */ GWRITE_FIELD(PINMUX, EXITEN0, DIOM3, 0); /* Reconfigure and reenable it. */ @@ -239,11 +276,11 @@ static void init_interrupts(void) static void configure_board_specific_gpios(void) { /* Add a pullup to sys_rst_l */ - if (system_get_board_properties() & BOARD_NEEDS_SYS_RST_PULL_UP) + if (board_rst_pullup_needed()) GWRITE_FIELD(PINMUX, DIOM0_CTL, PU, 1); /* Connect PLT_RST_L signal to the pinmux */ - if (system_get_board_properties() & BOARD_USE_PLT_RESET) { + if (board_has_plt_rst()) { /* Signal using GPIO1 pin 10 for DIOA13 */ GWRITE(PINMUX, GPIO1_GPIO10_SEL, GC_PINMUX_DIOM3_SEL); /* Enbale the input */ @@ -648,7 +685,7 @@ void enable_int_ap_l(void) } DECLARE_HOOK(HOOK_CHIPSET_RESUME, enable_int_ap_l, HOOK_PRIO_DEFAULT); -void system_init_board_properties(void) +static void init_board_properties(void) { uint32_t properties; @@ -658,7 +695,7 @@ void system_init_board_properties(void) * This must be a power on reset or maybe restart due to a software * update from a version not setting the register. */ - if (!properties || system_get_reset_flags() & RESET_FLAG_HARD) { + if (!properties || (system_get_reset_flags() & RESET_FLAG_HARD)) { /* * Reset the properties, because after a hard reset the register * won't be cleared. @@ -702,11 +739,7 @@ void system_init_board_properties(void) /* Save this configuration setting */ board_properties = properties; } - -uint32_t system_board_properties_callback(void) -{ - return board_properties; -} +DECLARE_HOOK(HOOK_INIT, init_board_properties, HOOK_PRIO_FIRST); void i2cs_set_pinmux(void) { diff --git a/board/cr50/board.h b/board/cr50/board.h index 8f718e13c0..7780efd45b 100644 --- a/board/cr50/board.h +++ b/board/cr50/board.h @@ -166,6 +166,12 @@ void assert_ec_rst(void); void deassert_ec_rst(void); int is_ec_rst_asserted(void); +int board_has_ap_usb(void); +int board_has_plt_rst(void); +int board_rst_pullup_needed(void); +int board_tpm_uses_i2c(void); +int board_tpm_uses_spi(void); + #endif /* !__ASSEMBLER__ */ /* USB interface indexes (use define rather than enum to expand them) */ diff --git a/board/cr50/rdd.c b/board/cr50/rdd.c index 1275b0dcde..e294d42d5e 100644 --- a/board/cr50/rdd.c +++ b/board/cr50/rdd.c @@ -137,7 +137,6 @@ void rdd_detached(void) void ccd_phy_init(int enable_ccd) { - uint32_t properties = system_get_board_properties(); /* * For boards that have one phy connected to the AP and one to the * external port PHY0 is for the AP and PHY1 is for CCD. @@ -161,10 +160,10 @@ void ccd_phy_init(int enable_ccd) /* * If the board has the non-ccd phy connected to the AP initialize the - * phy no matter what. Otherwise only initialized the phy if ccd is + * phy no matter what. Otherwise only initialize the phy if ccd is * enabled. */ - if ((properties & BOARD_USB_AP) || enable_ccd) { + if (board_has_ap_usb() || enable_ccd) { usb_init(); usb_is_initialized = 1; } @@ -172,8 +171,7 @@ void ccd_phy_init(int enable_ccd) void disable_ap_usb(void) { - if ((system_get_board_properties() & BOARD_USB_AP) && - !ccd_is_enabled() && usb_is_initialized) { + if (board_has_ap_usb() && !ccd_is_enabled() && usb_is_initialized) { usb_release(); usb_is_initialized = 0; } @@ -182,8 +180,7 @@ DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, disable_ap_usb, HOOK_PRIO_DEFAULT); void enable_ap_usb(void) { - if ((system_get_board_properties() & BOARD_USB_AP) && - !ccd_is_enabled() && !usb_is_initialized) { + if (board_has_ap_usb() && !ccd_is_enabled() && !usb_is_initialized) { usb_is_initialized = 1; usb_init(); } diff --git a/chip/g/i2cs.c b/chip/g/i2cs.c index 5096aae761..6efc891bdd 100644 --- a/chip/g/i2cs.c +++ b/chip/g/i2cs.c @@ -100,7 +100,7 @@ static void i2cs_init(void) { /* First decide if i2c is even needed for this platform. */ /* if (i2cs is not needed) return; */ - if (!(system_get_board_properties() & BOARD_SLAVE_CONFIG_I2C)) + if (!board_tpm_uses_i2c()) return; pmu_clock_en(PERIPH_I2CS); diff --git a/chip/g/sps.c b/chip/g/sps.c index 98f4fb54ae..2496f7ed27 100644 --- a/chip/g/sps.c +++ b/chip/g/sps.c @@ -231,7 +231,7 @@ static void sps_init(void) * Check to see if slave SPI interface is required by the board before * initializing it. If SPI option is not set, then just return. */ - if (!(system_get_board_properties() & BOARD_SLAVE_CONFIG_SPI)) + if (!board_tpm_uses_spi()) return; pmu_clock_en(PERIPH_SPS); diff --git a/chip/g/sps_tpm.c b/chip/g/sps_tpm.c index 8658ffc041..b5aba8500c 100644 --- a/chip/g/sps_tpm.c +++ b/chip/g/sps_tpm.c @@ -275,7 +275,7 @@ static void sps_tpm_enable(void) static void sps_if_register(void) { - if (!(system_get_board_properties() & BOARD_SLAVE_CONFIG_SPI)) + if (!board_tpm_uses_spi()) return; tpm_register_interface(sps_tpm_enable); diff --git a/chip/g/system.c b/chip/g/system.c index 85fcf63774..5ab69abda1 100644 --- a/chip/g/system.c +++ b/chip/g/system.c @@ -83,10 +83,6 @@ void system_pre_init(void) * no effect. */ GREG32(GLOBALSEC, FLASH_REGION0_CTRL_CFG_EN) = 0; - -#ifdef BOARD_CR50 - system_init_board_properties(); -#endif } void system_reset(int flags) @@ -403,16 +399,6 @@ int system_rolling_reboot_suspected(void) } #endif -uint32_t system_get_board_properties(void) -{ - uint32_t properties = 0; - -#ifdef BOARD_CR50 - properties = system_board_properties_callback(); -#endif - return properties; -} - /* Prepend header version to the current image's build info. */ const char *system_get_build_info(void) { diff --git a/common/i2cs_tpm.c b/common/i2cs_tpm.c index 274e6b6ba0..104671a302 100644 --- a/common/i2cs_tpm.c +++ b/common/i2cs_tpm.c @@ -218,7 +218,7 @@ static void i2cs_tpm_enable(void) static void i2cs_if_register(void) { - if (!(system_get_board_properties() & BOARD_SLAVE_CONFIG_I2C)) + if (!board_tpm_uses_i2c()) return; tpm_register_interface(i2cs_tpm_enable); diff --git a/include/system.h b/include/system.h index fa16846303..c8b7c8ee97 100644 --- a/include/system.h +++ b/include/system.h @@ -480,36 +480,6 @@ int system_process_retry_counter(void); */ void system_clear_retry_counter(void); - -/* Board properties options. A gap is left for backwards compatibility. */ -#define BOARD_SLAVE_CONFIG_SPI (1 << 0) /* Slave SPI interface */ -#define BOARD_SLAVE_CONFIG_I2C (1 << 1) /* Slave I2C interface */ -#define BOARD_USB_AP (1 << 2) /* One of the PHYs is */ - /* connected to the AP */ -/* TODO(crosbug.com/p/56945): Remove when sys_rst_l has an external pullup */ -#define BOARD_NEEDS_SYS_RST_PULL_UP (1 << 5) /* Add a pullup to sys_rst_l */ -#define BOARD_USE_PLT_RESET (1 << 6) /* Platform reset exists */ - -/** - * Get board properites - * - * - * @return uint32_t bit field where a set bit indicates option exists - */ -uint32_t system_get_board_properties(void); - -/* Board specific function used to initialize the system board properties. */ -void system_init_board_properties(void); - -/** - * API for board specific version of system_get_board_properties - * - * This function must be in the board's board.c file - * - * @return uint32_t bit field where a set bit indicates option exists - */ -uint32_t system_board_properties_callback(void); - /** * A function provided by some platforms to hint that something is going * wrong.