From 0f982a35e978febfc1bab45d1afc048e0c78968a Mon Sep 17 00:00:00 2001 From: Ruibin Chang Date: Tue, 21 Jul 2020 14:32:35 +0800 Subject: chip/it8320, it81202: Implement fast role swap function Implement fast role swap function from initial SNK to new SRC for chip it8320 and it81202. BUG=none BRANCH=none TEST=1.When we detect FRS cc low signal, we can output properly GPIO signal. 2.FRS false-positives test: PD traffic(ex.power nego, data and power swap, soft and hard reset) on the CC line after FRS is enabled. Change-Id: I3a7bc6a684e57fb19e50c41305751b2fca1ffe2d Signed-off-by: Ruibin Chang Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1786462 Reviewed-by: Diana Z --- driver/tcpm/it8xxx2.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'driver/tcpm/it8xxx2.c') diff --git a/driver/tcpm/it8xxx2.c b/driver/tcpm/it8xxx2.c index 82a903a272..10ca883c10 100644 --- a/driver/tcpm/it8xxx2.c +++ b/driver/tcpm/it8xxx2.c @@ -585,6 +585,48 @@ static int it83xx_tcpm_get_chip_info(int port, int live, return EC_SUCCESS; } +#ifdef CONFIG_USB_PD_FRS_TCPC +static int it83xx_tcpm_set_frs_enable(int port, int enable) +{ + uint8_t mask = (USBPD_REG_FAST_SWAP_REQUEST_ENABLE | + USBPD_REG_FAST_SWAP_DETECT_ENABLE); + + if (enable) { + /* + * Disable HW auto turn off FRS requestion and detection + * when we receive soft or hard reset. + */ + IT83XX_USBPD_PDMSR(port) &= ~USBPD_REG_MASK_AUTO_FRS_DISABLE; + /* W/C status */ + IT83XX_USBPD_IFS(port) = 0x33; + /* Enable FRS detection (cc to GND) interrupt */ + IT83XX_USBPD_MIFS(port) &= ~(USBPD_REG_MASK_FAST_SWAP_ISR | + USBPD_REG_MASK_FAST_SWAP_DETECT_ISR); + /* Enable FRS detection (cc to GND) */ + IT83XX_USBPD_PDFSCR(port) = (IT83XX_USBPD_PDFSCR(port) & ~mask) + | USBPD_REG_FAST_SWAP_DETECT_ENABLE; + /* + * TODO(b/160210457): Enable HW auto trigger + * GPH3(port0)/GPH4(port1) output H/L after we detect FRS cc + * low signal. + */ + } else { + /* Disable FRS detection (cc to GND) interrupt */ + IT83XX_USBPD_MIFS(port) |= (USBPD_REG_MASK_FAST_SWAP_ISR | + USBPD_REG_MASK_FAST_SWAP_DETECT_ISR); + /* Disable FRS detection and requestion */ + IT83XX_USBPD_PDFSCR(port) &= ~mask; + /* + * TODO(b/160210457): Disable HW auto trigger + * GPH3(port0)/GPH4(port1) output H/L after we detect FRS cc + * low signal. + */ + } + + return EC_SUCCESS; +} +#endif + static void it83xx_init(enum usbpd_port port, int role) { uint8_t cc_config = (port == USBPD_PORT_C ? @@ -675,4 +717,7 @@ const struct tcpm_drv it83xx_tcpm_drv = { .get_message_raw = &it83xx_tcpm_get_message_raw, .transmit = &it83xx_tcpm_transmit, .get_chip_info = &it83xx_tcpm_get_chip_info, +#ifdef CONFIG_USB_PD_FRS_TCPC + .set_frs_enable = &it83xx_tcpm_set_frs_enable, +#endif }; -- cgit v1.2.1