From 0888fe2d3e01b379ca8024d09f24fd89b3d49acf Mon Sep 17 00:00:00 2001 From: "reno.wang" Date: Wed, 1 Sep 2021 00:45:10 +0800 Subject: taeko: Improvement: Disable tcpc1 if no ps8815 db for early board It improve ec keep sensing ps8815 if no db is plugged. It's olny used for early board (board id = 0). 1. Add DB detection policy for board w/o plugging DB. It can make sure system can power on and won't be blocked by TCPC1. 2. Add draft PS8815 reset timing. The others should check b/194618663. 3. Follow CL:3095438, mux HPD interface change, to update BUG=b:197585292 BRANCH=None TEST=make -j BOARD=taeko; test dut can power on w/ and w/o TCPC1 DB Signed-off-by: reno.wang Change-Id: I7fd115baa95d455b282e4ee5bfdf8ee25524e140 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3133463 Reviewed-by: Boris Mittelberg Reviewed-by: caveh jalali Commit-Queue: caveh jalali --- board/taeko/usbc_config.c | 126 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 114 insertions(+), 12 deletions(-) diff --git a/board/taeko/usbc_config.c b/board/taeko/usbc_config.c index 6219b8cd56..c8e02581be 100644 --- a/board/taeko/usbc_config.c +++ b/board/taeko/usbc_config.c @@ -36,6 +36,15 @@ #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) +#if 0 +/* Debug only! */ +#define CPRINTSUSB(format, args...) cprints(CC_USBPD, format, ## args) +#define CPRINTFUSB(format, args...) cprintf(CC_USBPD, format, ## args) +#else +#define CPRINTSUSB(format, args...) +#define CPRINTFUSB(format, args...) +#endif + /* USBC TCPC configuration */ const struct tcpc_config_t tcpc_config[] = { [USBC_PORT_C0] = { @@ -147,10 +156,78 @@ void config_usb_db_type(void) /* * TODO(b/194515356): implement multiple DB types */ - CPRINTS("Configured USB DB type number is %d", db_type); } +static void ps8815_reset(void) +{ + int val; + + CPRINTS("%s: patching ps8815 registers", __func__); + + if (i2c_read8(I2C_PORT_USB_C1_TCPC, + PS8751_I2C_ADDR1_FLAGS, 0x0f, &val) == EC_SUCCESS) + CPRINTS("ps8815: reg 0x0f was %02x", val); + + if (i2c_write8(I2C_PORT_USB_C1_TCPC, + PS8751_I2C_ADDR1_FLAGS, 0x0f, 0x31) == EC_SUCCESS) + CPRINTS("ps8815: reg 0x0f set to 0x31"); + + if (i2c_read8(I2C_PORT_USB_C1_TCPC, + PS8751_I2C_ADDR1_FLAGS, 0x0f, &val) == EC_SUCCESS) + CPRINTS("ps8815: reg 0x0f now %02x", val); +} + +/** + * b/197585292 + * It's used for early board to check if usb_db is plugged or not. + * That's used to avoid TCPC1 initialization abnormal if db isn't + * plugged into system. + */ +enum usb_db_present { + DB_USB_NOT_PRESENT = 0, + DB_USB_PRESENT = 1, +}; +static enum usb_db_present db_usb_hw_pres; + +/** + * Init hw ps8815 detection and keep it in db_usb_hw_press. + * Then, we don't need to keep query ps8815 mcu. + */ +static void board_init_ps8815_detection(void) +{ + int rv, val; + + CPRINTSUSB("%s", __func__); + + rv = i2c_read8(I2C_PORT_USB_C1_TCPC, + PS8751_I2C_ADDR1_FLAGS, 0x00, &val); + + db_usb_hw_pres = (rv == EC_SUCCESS)?DB_USB_PRESENT:DB_USB_NOT_PRESENT; + + if (db_usb_hw_pres == DB_USB_NOT_PRESENT) + CPRINTS("DB isn't plugged or something went wrong!"); +} + +/** + * @return true if ps8815_db is plugged, false if it isn't plugged. + */ +static bool board_detect_ps8815_db(void) +{ + CPRINTSUSB("%s", __func__); + + /* All dut should plug ps8815 db if board id > 0 */ + if (get_board_id() > 0) + return true; + + if (ec_cfg_usb_db_type() == DB_USB3_PS8815 && + db_usb_hw_pres == DB_USB_PRESENT) + return true; + + CPRINTSUSB("No PS8815 DB"); + return false; +} + void board_reset_pd_mcu(void) { /* @@ -163,21 +240,30 @@ void board_reset_pd_mcu(void) /* * delay for power-on to reset-off and min. assertion time */ - - msleep(20); + msleep(GENERIC_MAX(PS8XXX_RESET_DELAY_MS, + PS8815_PWR_H_RST_H_DELAY_MS)); gpio_set_level(GPIO_USB_C0_TCPC_RST_ODL, 1); gpio_set_level(GPIO_USB_C1_RT_RST_R_ODL, 1); /* wait for chips to come up */ + msleep(PS8815_FW_INIT_DELAY_MS); + ps8815_reset(); - msleep(50); + /* + * board_init_ps8815_detection should be called before + * board_get_usb_pd_port_count(). usb_mux_hpd_update can check + * pd port count. + */ + board_init_ps8815_detection(); + usb_mux_hpd_update(USBC_PORT_C1, USB_PD_MUX_HPD_LVL_DEASSERTED | + USB_PD_MUX_HPD_IRQ_DEASSERTED); } - - static void board_tcpc_init(void) { + CPRINTSUSB("%s: board id = %d", __func__, get_board_id()); + /* Don't reset TCPCs after initial reset */ if (!system_jumped_late()) { board_reset_pd_mcu(); @@ -190,17 +276,22 @@ static void board_tcpc_init(void) ioex_init(0); } + CPRINTSUSB("Enable GPIO INT"); + /* Enable PPC interrupts. */ gpio_enable_interrupt(GPIO_USB_C0_PPC_INT_ODL); - gpio_enable_interrupt(GPIO_USB_C1_PPC_INT_ODL); + if (board_detect_ps8815_db()) + gpio_enable_interrupt(GPIO_USB_C1_PPC_INT_ODL); /* Enable TCPC interrupts. */ gpio_enable_interrupt(GPIO_USB_C0_TCPC_INT_ODL); - gpio_enable_interrupt(GPIO_USB_C1_TCPC_INT_ODL); + if (board_detect_ps8815_db()) + gpio_enable_interrupt(GPIO_USB_C1_TCPC_INT_ODL); /* Enable BC1.2 interrupts. */ gpio_enable_interrupt(GPIO_USB_C0_BC12_INT_ODL); - gpio_enable_interrupt(GPIO_USB_C1_BC12_INT_ODL); + if (board_detect_ps8815_db()) + gpio_enable_interrupt(GPIO_USB_C1_BC12_INT_ODL); } DECLARE_HOOK(HOOK_INIT, board_tcpc_init, HOOK_PRIO_INIT_CHIPSET); @@ -209,7 +300,7 @@ uint16_t tcpc_get_alert_status(void) uint16_t status = 0; if (gpio_get_level(GPIO_USB_C0_TCPC_INT_ODL) == 0) - status |= PD_STATUS_TCPC_ALERT_0 | PD_STATUS_TCPC_ALERT_2; + status |= PD_STATUS_TCPC_ALERT_0; if (gpio_get_level(GPIO_USB_C1_TCPC_INT_ODL) == 0) status |= PD_STATUS_TCPC_ALERT_1; @@ -221,8 +312,10 @@ int ppc_get_alert_status(int port) { if (port == USBC_PORT_C0) return gpio_get_level(GPIO_USB_C0_PPC_INT_ODL) == 0; - else if (port == USBC_PORT_C1) + + if (port == USBC_PORT_C1) return gpio_get_level(GPIO_USB_C1_PPC_INT_ODL) == 0; + return 0; } @@ -263,7 +356,6 @@ void ppc_interrupt(enum gpio_signal signal) case GPIO_USB_C1_PPC_INT_ODL: nx20p348x_interrupt(USBC_PORT_C1); break; - default: break; } @@ -273,3 +365,13 @@ __override bool board_is_dts_port(int port) { return port == USBC_PORT_C0; } + +__override uint8_t board_get_usb_pd_port_count(void) +{ + CPRINTSUSB("%s is called by task_id:%d", __func__, task_get_current()); + + if (board_detect_ps8815_db()) + return CONFIG_USB_PD_PORT_MAX_COUNT; + + return CONFIG_USB_PD_PORT_MAX_COUNT - 1; +} -- cgit v1.2.1