From 88549e6d2bf0f951d58b9a714033a08a72372df3 Mon Sep 17 00:00:00 2001 From: Namyoon Woo Date: Tue, 21 Jan 2020 14:59:09 -0800 Subject: revise the uart tx connect/disconnect functions This patch reduces redundant condition checking in connecting or disconnecting UART TX. BUG=none BRANCH=cr50 TEST=manually checked ccd state with/without servo connection and/or ccd connection. [AFTER] > ccdstate AP: on AP UART: on EC: on Rdd: connected Servo: connected CCD EXT: enabled State flags: UARTAP UARTEC CCD ports blocked: (none) > ccdstate AP: on AP UART: on EC: on Rdd: disconnected Servo: connected CCD EXT: disabled State flags: CCD ports blocked: (none) > ccdstate AP: on AP UART: on EC: on Rdd: connected Servo: undetectable CCD EXT: enabled State flags: UARTAP+TX UARTEC+TX I2C SPI CCD ports blocked: (none) > ccdstate AP: off AP UART: off EC: on Rdd: connected Servo: undetectable CCD EXT: enabled State flags: UARTEC+TX I2C SPI CCD ports blocked: (none) > ccdstate AP: on AP UART: on EC: on Rdd: connected Servo: disconnected CCD EXT: enabled State flags: UARTAP+TX I2C SPI CCD ports blocked: EC > ccdstate AP: on AP UART: on EC: on Rdd: connected Servo: disconnected CCD EXT: enabled State flags: I2C SPI CCD ports blocked: AP EC > ccdstate AP: on AP UART: on EC: on Rdd: connected Servo: ignored CCD EXT: enabled State flags: UARTAP+TX UARTEC+TX I2C SPI CCD ports blocked: IGNORE_SERVO WARNING: enabling UART while servo is connected may damage hardware Change-Id: Icea2978b15e15bbf7cea8e48fd2bf4fdecc78f46 Signed-off-by: Namyoon Woo Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2013823 Reviewed-by: Mary Ruthven --- board/cr50/rdd.c | 50 +++++++++++--------------------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) (limited to 'board') diff --git a/board/cr50/rdd.c b/board/cr50/rdd.c index 2d1403ec02..21d1357df8 100644 --- a/board/cr50/rdd.c +++ b/board/cr50/rdd.c @@ -78,60 +78,32 @@ int uart_tx_is_connected(int uart) return !uart_bitbang_is_enabled() && GREAD(PINMUX, DIOB5_SEL); } -/** - * Connect the UART pin to the given signal - * - * @param uart the uart peripheral number - * @param signal the pinmux selector value for the gpio or peripheral - * function. 0 to disable the output. - */ -static void uart_select_tx(int uart, int signal) +static void uartn_tx_connect(int uart) { + /* Connect the TX pin to UART peripheral */ if (uart == UART_AP) { - GWRITE(PINMUX, DIOA7_SEL, signal); + GWRITE(PINMUX, DIOA7_SEL, GC_PINMUX_UART1_TX_SEL); } else { - GWRITE(PINMUX, DIOB5_SEL, signal); + GWRITE(PINMUX, DIOB5_SEL, GC_PINMUX_UART2_TX_SEL); /* Remove the pulldown when we are driving the signal */ - GWRITE_FIELD(PINMUX, DIOB5_CTL, PD, signal ? 0 : 1); + GWRITE_FIELD(PINMUX, DIOB5_CTL, PD, 0); } } -void uartn_tx_connect(int uart) +static void uartn_tx_disconnect(int uart) { - /* - * Don't drive TX unless the debug cable is connected (we have - * something to transmit) and servo is disconnected (we won't be - * drive-fighting with servo). - */ - if (servo_is_connected() || !ccd_ext_is_enabled()) - return; - + /* Disconnect the TX pin from UART peripheral */ if (uart == UART_AP) { - if (!ccd_is_cap_enabled(CCD_CAP_GSC_TX_AP_RX)) - return; - - if (!ap_uart_is_on()) - return; - - uart_select_tx(UART_AP, GC_PINMUX_UART1_TX_SEL); + GWRITE(PINMUX, DIOA7_SEL, 0); } else { - if (!ccd_is_cap_enabled(CCD_CAP_GSC_TX_EC_RX)) - return; + GWRITE(PINMUX, DIOB5_SEL, 0); - if (!ec_is_on()) - return; - - uart_select_tx(UART_EC, GC_PINMUX_UART2_TX_SEL); + /* Set up the pulldown */ + GWRITE_FIELD(PINMUX, DIOB5_CTL, PD, 1); } } -void uartn_tx_disconnect(int uart) -{ - /* Disconnect the TX pin from UART peripheral */ - uart_select_tx(uart, 0); -} - /* * Flags for the current CCD device state. This is used for determining what * hardware devices we've enabled now, and which we want enabled. -- cgit v1.2.1