diff options
-rw-r--r-- | board/cr50/board.c | 7 | ||||
-rw-r--r-- | board/cr50/rdd.c | 25 | ||||
-rw-r--r-- | chip/g/rdd.c | 7 | ||||
-rw-r--r-- | common/case_closed_debug.c | 8 | ||||
-rw-r--r-- | include/case_closed_debug.h | 4 | ||||
-rw-r--r-- | include/system.h | 2 |
6 files changed, 46 insertions, 7 deletions
diff --git a/board/cr50/board.c b/board/cr50/board.c index a271f0009a..008e9372b0 100644 --- a/board/cr50/board.c +++ b/board/cr50/board.c @@ -532,14 +532,17 @@ static void detect_slave_config(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) { + if (!properties || system_get_reset_flags() & RESET_FLAG_HARD) { /* Read DIOA1 strap pin */ if (gpio_get_level(GPIO_STRAP0)) /* Strap is pulled high -> Kevin SPI TPM option */ properties |= BOARD_SLAVE_CONFIG_SPI; - else + else { /* Strap is low -> Reef I2C TPM option */ properties |= BOARD_SLAVE_CONFIG_I2C; + /* One PHY is connected to the AP */ + properties |= BOARD_USB_AP; + } /* * Now save the properties value for future use. diff --git a/board/cr50/rdd.c b/board/cr50/rdd.c index 4d0fa942e8..0d46ec141d 100644 --- a/board/cr50/rdd.c +++ b/board/cr50/rdd.c @@ -9,6 +9,7 @@ #include "gpio.h" #include "rdd.h" #include "registers.h" +#include "system.h" #include "uartn.h" #include "usb_api.h" @@ -123,6 +124,30 @@ void rdd_detached(void) ccd_set_mode(CCD_MODE_DISABLED); } +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. + */ + uint32_t which_phy = enable_ccd ? USB_SEL_PHY1 : USB_SEL_PHY0; + + /* + * TODO: if both PHYs are connected to the external port select the + * PHY based on the detected polarity + */ + usb_select_phy(which_phy); + + /* + * 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 + * enabled. + */ + if ((properties & BOARD_USB_AP) || enable_ccd) + usb_init(); +} + static int command_ccd(int argc, char **argv) { int val; diff --git a/chip/g/rdd.c b/chip/g/rdd.c index 3ef9bf14c6..06dbe383b1 100644 --- a/chip/g/rdd.c +++ b/chip/g/rdd.c @@ -33,14 +33,13 @@ int debug_cable_is_attached(void) void rdd_interrupt(void) { - int is_debug, current_map; + int is_debug; delay_sleep_by(1 * SECOND); - current_map = 0xffff & GREAD(RDD, PROG_DEBUG_STATE_MAP); is_debug = debug_cable_is_attached(); - if (is_debug && (current_map == DETECT_DEBUG)) { + if (is_debug) { disable_sleep(SLEEP_MASK_RDD); CPRINTS("Debug Accessory connected"); @@ -49,7 +48,7 @@ void rdd_interrupt(void) GWRITE(RDD, PROG_DEBUG_STATE_MAP, DETECT_DISCONNECT); rdd_attached(); - } else if (!is_debug && (current_map == DETECT_DISCONNECT)) { + } else if (!is_debug) { CPRINTS("Debug Accessory disconnected"); /* Detect when debug cable is connected */ diff --git a/common/case_closed_debug.c b/common/case_closed_debug.c index 0b81547ca4..52a6c98e27 100644 --- a/common/case_closed_debug.c +++ b/common/case_closed_debug.c @@ -28,14 +28,16 @@ USB_SPI_CONFIG(ccd_usb_spi, USB_IFACE_SPI, USB_EP_SPI); #endif -static enum ccd_mode current_mode = CCD_MODE_DISABLED; +static enum ccd_mode current_mode = CCD_MODE_COUNT; void ccd_set_mode(enum ccd_mode new_mode) { if (new_mode == current_mode) return; +#ifndef CONFIG_USB_SELECT_PHY if (current_mode != CCD_MODE_DISABLED) +#endif usb_release(); current_mode = new_mode; @@ -51,6 +53,10 @@ void ccd_set_mode(enum ccd_mode new_mode) usb_spi_enable(&ccd_usb_spi, new_mode == CCD_MODE_ENABLED); #endif +#ifdef CONFIG_USB_SELECT_PHY + ccd_phy_init(new_mode != CCD_MODE_DISABLED); +#else if (new_mode != CCD_MODE_DISABLED) usb_init(); +#endif } diff --git a/include/case_closed_debug.h b/include/case_closed_debug.h index 82c9c9548f..ed2f13d099 100644 --- a/include/case_closed_debug.h +++ b/include/case_closed_debug.h @@ -26,6 +26,8 @@ enum ccd_mode { * device over CCD. */ CCD_MODE_ENABLED, + + CCD_MODE_COUNT, }; /* @@ -33,4 +35,6 @@ enum ccd_mode { */ void ccd_set_mode(enum ccd_mode new_mode); +/* Initialize the PHY based on CCD state */ +void ccd_phy_init(int enable_ccd); #endif /* __CROS_EC_CASE_CLOSED_DEBUG_H */ diff --git a/include/system.h b/include/system.h index 55b841facd..4b558cade8 100644 --- a/include/system.h +++ b/include/system.h @@ -465,6 +465,8 @@ int system_process_retry_counter(void); /* Board properties options */ #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 */ /** * Get board properites * |