From f2b3aa47a6e2b11ef1888219284ef0f727944ef2 Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Tue, 15 Aug 2017 17:36:10 -0700 Subject: [PATCH] cr50: Add helper functions for device-is-enabled A subsequent CL will massively refactor the device state machines. Add the helper functions which will be used by that CL, so that the refactoring touches fewer files. No change in functionality. BUG=none BRANCH=cr50 TEST=make buildall; boot cr50 with a CR50_DEV=1 image Change-Id: I3499d45e93fa15b6de9c04ce398d1c5bfbbc01e9 Signed-off-by: Randall Spangler Reviewed-on: https://chromium-review.googlesource.com/616300 Commit-Ready: Vadim Bendebury Tested-by: Vadim Bendebury Reviewed-by: Vadim Bendebury Reviewed-by: Mary Ruthven --- board/cr50/board.c | 10 ++++++++++ board/cr50/board.h | 5 +++++ board/cr50/rdd.c | 14 +++++++------- board/cr50/u2f.c | 4 +--- board/cr50/usb_i2c.c | 7 +++---- common/tpm_registers.c | 3 +-- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/board/cr50/board.c b/board/cr50/board.c index 3d4f84d1cb..44e263d784 100644 --- a/board/cr50/board.c +++ b/board/cr50/board.c @@ -514,6 +514,16 @@ static void init_interrupts(void) static void deferred_tpm_rst_isr(void); DECLARE_DEFERRED(deferred_tpm_rst_isr); +int ap_is_on(void) +{ + return device_get_state(DEVICE_AP) == DEVICE_STATE_ON; +} + +int ec_is_on(void) +{ + return device_get_state(DEVICE_EC) == DEVICE_STATE_ON; +} + static void configure_board_specific_gpios(void) { /* Add a pullup to sys_rst_l */ diff --git a/board/cr50/board.h b/board/cr50/board.h index 456a8c9877..f62a8fa692 100644 --- a/board/cr50/board.h +++ b/board/cr50/board.h @@ -219,6 +219,11 @@ void board_reboot_ap(void); int board_wipe_tpm(void); int board_is_first_factory_boot(void); +int ap_is_on(void); +int ec_is_on(void); +int rdd_is_connected(void); +int servo_is_connected(void); + /* Returns True if chip is brought up in a factory test harness. */ int chip_factory_mode(void); diff --git a/board/cr50/rdd.c b/board/cr50/rdd.c index be5bf3417d..38af5d3999 100644 --- a/board/cr50/rdd.c +++ b/board/cr50/rdd.c @@ -33,7 +33,7 @@ static struct uart_config uarts[] = { [UART_EC] = {"EC", DEVICE_EC, GC_PINMUX_UART2_TX_SEL}, }; -static int ccd_is_enabled(void) +int rdd_is_connected(void) { return ccd_get_mode() == CCD_MODE_ENABLED; } @@ -71,7 +71,7 @@ static void uart_select_tx(int uart, int signal) } } -static int servo_is_connected(void) +int servo_is_connected(void) { return device_get_state(DEVICE_SERVO) == DEVICE_STATE_ON; } @@ -84,7 +84,7 @@ void uartn_tx_connect(int uart) if (uart == UART_EC && !ccd_is_cap_enabled(CCD_CAP_EC_RX_CR50_TX)) return; - if (!ccd_is_enabled()) + if (!rdd_is_connected()) return; if (servo_is_connected()) { @@ -108,7 +108,7 @@ void uartn_tx_disconnect(int uart) static void configure_ccd(int enable) { if (enable) { - if (ccd_is_enabled()) + if (rdd_is_connected()) return; /* Enable CCD */ @@ -170,7 +170,7 @@ static void rdd_check_pin(void) if (keep_ccd_enabled) enable = 1; - if (enable == ccd_is_enabled()) + if (enable == rdd_is_connected()) return; configure_ccd(enable); @@ -228,7 +228,7 @@ static int command_ccd(int argc, char **argv) } else if (!strcasecmp("keepalive", argv[1])) { if (val) { /* Make sure ccd is enabled */ - if (!ccd_is_enabled()) + if (!rdd_is_connected()) rdd_attached(); keep_ccd_enabled = 1; @@ -253,7 +253,7 @@ static int command_ccd(int argc, char **argv) ccprintf("CCD: %s\n", keep_ccd_enabled ? "forced enable" : - ccd_is_enabled() ? "enabled" : "disabled"); + rdd_is_connected() ? "enabled" : "disabled"); ccprintf("AP UART: %s\n", uartn_is_enabled(UART_AP) ? uart_tx_is_connected(UART_AP) ? "RX+TX" : "RX" : "disabled"); diff --git a/board/cr50/u2f.c b/board/cr50/u2f.c index 633b9f60d3..f379e66566 100644 --- a/board/cr50/u2f.c +++ b/board/cr50/u2f.c @@ -7,7 +7,6 @@ #include "console.h" #include "dcrypto.h" -#include "device_state.h" #include "extension.h" #include "nvmem_vars.h" #include "rbox.h" @@ -30,8 +29,7 @@ static timestamp_t last_press; void power_button_record(void) { - if (device_get_state(DEVICE_AP) == DEVICE_STATE_ON && - rbox_powerbtn_is_pressed()) + if (ap_is_on() && rbox_powerbtn_is_pressed()) last_press = get_time(); } diff --git a/board/cr50/usb_i2c.c b/board/cr50/usb_i2c.c index 0bc5b3f215..4c5750de49 100644 --- a/board/cr50/usb_i2c.c +++ b/board/cr50/usb_i2c.c @@ -5,7 +5,6 @@ #include "case_closed_debug.h" #include "console.h" -#include "device_state.h" #include "gpio.h" #include "hooks.h" #include "i2c.h" @@ -73,13 +72,13 @@ void usb_i2c_board_disable(void) int usb_i2c_board_enable(void) { - if (device_get_state(DEVICE_SERVO) == DEVICE_STATE_ON) { - CPRINTS("Servo is attached I2C cannot be enabled"); + if (servo_is_connected()) { + CPRINTS("Servo attached; cannot enable I2C"); usb_i2c_board_disable(); return EC_ERROR_BUSY; } - if (ccd_get_mode() != CCD_MODE_ENABLED) + if (!rdd_is_connected()) return EC_ERROR_BUSY; if (!ccd_is_cap_enabled(CCD_CAP_I2C)) diff --git a/common/tpm_registers.c b/common/tpm_registers.c index 1fb0baef0b..b8d522a460 100644 --- a/common/tpm_registers.c +++ b/common/tpm_registers.c @@ -11,7 +11,6 @@ #include "byteorder.h" #include "console.h" -#include "device_state.h" #include "extension.h" #include "link_defs.h" #include "nvmem.h" @@ -829,7 +828,7 @@ void tpm_task(void) * up. No need to worry about the AP state in chip factory * mode of course. */ - while (device_get_state(DEVICE_AP) != DEVICE_STATE_ON) { + while (!ap_is_on()) { /* * The only event we should expect at this point would * be the reset request.