summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2018-08-10 10:12:38 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-08-15 12:54:54 -0700
commitb7442b335d6b6a8549eb677058ae8f2782a82792 (patch)
treefbde87d65d8e9801d40a829c8c4104616b2f53e6
parentdb9f64097b0ca46e125ad0f4fc76b80863e9772b (diff)
downloadchrome-ec-b7442b335d6b6a8549eb677058ae8f2782a82792.tar.gz
cr50: bitbang does not need to support multiple UARTs.
The ability to support multiple UART interfaces complicates bit bang EC programming implementation without bringing any real benefits - we are not going to have to bit bang more than one UART interface in real Chrome OS hardware. In preparation in introducing bit a bang speed up patch let's change the API to not require passing the UART number to bit bang functions. To keep servod happy for now, the 'bitbang' cli command is being left unchanged and as such still requires to pass the UART number, it is just ignored. BRANCH=cr50, cr50-mp BUG=b:62539385 TEST=just verified that Cr50 still builds, the real test is done in the speed up patch. Change-Id: Icd5476ad777791ca483844cbf49316ddf58f03a3 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1171220 Reviewed-by: Mary Ruthven <mruthven@chromium.org>
-rw-r--r--board/cr50/board.c2
-rw-r--r--board/cr50/rdd.c8
-rw-r--r--board/cr50/servo_state.c3
-rw-r--r--chip/g/uart_bitbang.c90
-rw-r--r--chip/g/uart_bitbang.h33
-rw-r--r--chip/g/uartn.c12
6 files changed, 56 insertions, 92 deletions
diff --git a/board/cr50/board.c b/board/cr50/board.c
index e92dd1f62c..67ed39ab38 100644
--- a/board/cr50/board.c
+++ b/board/cr50/board.c
@@ -106,7 +106,7 @@ struct uart_bitbang_properties bitbang_config = {
void ec_tx_cr50_rx(enum gpio_signal signal)
{
- uart_bitbang_receive_char(UART_EC);
+ uart_bitbang_receive_char();
/*
* Let the USART module know that there's new bits to consume.
*
diff --git a/board/cr50/rdd.c b/board/cr50/rdd.c
index daf9e83c5c..bb4b225626 100644
--- a/board/cr50/rdd.c
+++ b/board/cr50/rdd.c
@@ -169,7 +169,7 @@ static uint32_t get_state_flags(void)
flags_now |= CCD_ENABLE_UART_EC_TX;
#ifdef CONFIG_UART_BITBANG
- if (uart_bitbang_is_enabled(UART_EC))
+ if (uart_bitbang_is_enabled())
flags_now |= CCD_ENABLE_UART_EC_BITBANG;
#endif
@@ -225,7 +225,7 @@ static void ccd_state_change_hook(void)
#ifdef CONFIG_UART_BITBANG
/* EC must be all the way on for bit-banging the EC UART */
- if (ec_is_on() && uart_bitbang_is_wanted(UART_EC))
+ if (ec_is_on() && uart_bitbang_is_wanted())
flags_want |= CCD_ENABLE_UART_EC_BITBANG;
#endif
@@ -304,7 +304,7 @@ static void ccd_state_change_hook(void)
uartn_tx_disconnect(UART_EC);
#ifdef CONFIG_UART_BITBANG
if (delta & CCD_ENABLE_UART_EC_BITBANG)
- uart_bitbang_disable(UART_EC);
+ uart_bitbang_disable();
#endif
if (delta & CCD_ENABLE_I2C)
usb_i2c_board_disable();
@@ -323,7 +323,7 @@ static void ccd_state_change_hook(void)
uartn_tx_connect(UART_EC);
#ifdef CONFIG_UART_BITBANG
if (delta & CCD_ENABLE_UART_EC_BITBANG)
- uart_bitbang_enable(UART_EC);
+ uart_bitbang_enable();
#endif
if (delta & CCD_ENABLE_I2C)
usb_i2c_board_enable();
diff --git a/board/cr50/servo_state.c b/board/cr50/servo_state.c
index 505e694142..0c99c6f317 100644
--- a/board/cr50/servo_state.c
+++ b/board/cr50/servo_state.c
@@ -71,8 +71,7 @@ static int servo_detectable(void)
* that case, the UART transmit line is directly controlled as a GPIO
* and can be high even if UART TX is disconnected.
*/
- return !(uart_tx_is_connected(UART_EC) ||
- uart_bitbang_is_enabled(UART_EC));
+ return !(uart_tx_is_connected(UART_EC) || uart_bitbang_is_enabled());
}
/**
diff --git a/chip/g/uart_bitbang.c b/chip/g/uart_bitbang.c
index 6d38626b68..610514cb47 100644
--- a/chip/g/uart_bitbang.c
+++ b/chip/g/uart_bitbang.c
@@ -57,32 +57,22 @@ static int stop_bit_discard[DISCARD_LOG];
static int stop_bit_discard_idx;
#endif /* BITBANG_DEBUG */
-static int is_uart_allowed(int uart)
+int uart_bitbang_is_enabled(void)
{
- return uart == bitbang_config.uart;
+ return bitbang_enabled;
}
-int uart_bitbang_is_enabled(int uart)
+int uart_bitbang_is_wanted(void)
{
- return (is_uart_allowed(uart) && bitbang_enabled);
+ return bitbang_wanted;
}
-int uart_bitbang_is_wanted(int uart)
-{
- return (is_uart_allowed(uart) && bitbang_wanted);
-}
-
-int uart_bitbang_config(int uart, int baud_rate, int parity)
+int uart_bitbang_config(int baud_rate, int parity)
{
/* Can't configure when enabled */
if (bitbang_enabled)
return EC_ERROR_BUSY;
- if (!is_uart_allowed(uart)) {
- CPRINTF("bit bang config not found for UART%d\n", uart);
- return EC_ERROR_INVAL;
- }
-
/* Check desired properties. */
if (!IS_BAUD_RATE_SUPPORTED(baud_rate)) {
CPRINTF("Err: invalid baud rate (%d)\n", baud_rate);
@@ -105,21 +95,16 @@ int uart_bitbang_config(int uart, int baud_rate, int parity)
return EC_SUCCESS;
}
-int uart_bitbang_enable(int uart)
+int uart_bitbang_enable(void)
{
/* We only want to bit bang 1 UART at a time */
if (bitbang_enabled)
return EC_ERROR_BUSY;
/* UART TX must be disconnected first */
- if (uart_tx_is_connected(uart))
+ if (uart_tx_is_connected(bitbang_config.uart))
return EC_ERROR_BUSY;
- if (!is_uart_allowed(uart)) {
- CPRINTS("bit bang config not found for UART%d", uart);
- return EC_ERROR_INVAL;
- }
-
/* Select the GPIOs instead of the UART block */
REG32(bitbang_config.tx_pinmux_reg) =
bitbang_config.tx_pinmux_regval;
@@ -145,9 +130,12 @@ int uart_bitbang_enable(int uart)
set_parity = bitbang_config.htp.parity;
/* Register the function pointers. */
- uartn_funcs[uart]._rx_available = _uart_bitbang_rx_available;
- uartn_funcs[uart]._write_char = _uart_bitbang_write_char;
- uartn_funcs[uart]._read_char = _uart_bitbang_read_char;
+ uartn_funcs[bitbang_config.uart]._rx_available =
+ _uart_bitbang_rx_available;
+ uartn_funcs[bitbang_config.uart]._write_char =
+ _uart_bitbang_write_char;
+ uartn_funcs[bitbang_config.uart]._read_char =
+ _uart_bitbang_read_char;
bitbang_enabled = 1;
gpio_enable_interrupt(bitbang_config.rx_gpio);
@@ -155,9 +143,9 @@ int uart_bitbang_enable(int uart)
return EC_SUCCESS;
}
-int uart_bitbang_disable(int uart)
+int uart_bitbang_disable(void)
{
- if (!uart_bitbang_is_enabled(uart))
+ if (!uart_bitbang_is_enabled())
return EC_SUCCESS;
/*
@@ -169,9 +157,9 @@ int uart_bitbang_disable(int uart)
gpio_reset(bitbang_config.rx_gpio);
/* Unregister the function pointers. */
- uartn_funcs[uart]._rx_available = _uartn_rx_available;
- uartn_funcs[uart]._write_char = _uartn_write_char;
- uartn_funcs[uart]._read_char = _uartn_read_char;
+ uartn_funcs[bitbang_config.uart]._rx_available = _uartn_rx_available;
+ uartn_funcs[bitbang_config.uart]._write_char = _uartn_write_char;
+ uartn_funcs[bitbang_config.uart]._read_char = _uartn_read_char;
/* Gate the microsecond timer since we're done with it. */
pmu_clock_dis(PERIPH_TIMEUS);
@@ -190,13 +178,13 @@ static void wait_ticks(uint32_t ticks)
;
}
-void uart_bitbang_write_char(int uart, char c)
+void uart_bitbang_write_char(char c)
{
int val;
int ones;
int i;
- if (!uart_bitbang_is_enabled(uart))
+ if (!uart_bitbang_is_enabled())
return;
interrupt_disable();
@@ -245,7 +233,7 @@ void uart_bitbang_write_char(int uart, char c)
interrupt_enable();
}
-int uart_bitbang_receive_char(int uart)
+int uart_bitbang_receive_char(void)
{
uint8_t rx_char;
int i;
@@ -347,14 +335,11 @@ int uart_bitbang_receive_char(int uart)
return EC_SUCCESS;
}
-int uart_bitbang_read_char(int uart)
+int uart_bitbang_read_char(void)
{
int c;
uint8_t head;
- if (!is_uart_allowed(uart))
- return 0;
-
head = bitbang_config.htp.head;
c = rx_buf[head];
@@ -367,35 +352,32 @@ int uart_bitbang_read_char(int uart)
return c;
}
-int uart_bitbang_is_char_available(int uart)
+int uart_bitbang_is_char_available(void)
{
- if (!is_uart_allowed(uart))
- return 0;
-
return bitbang_config.htp.head != bitbang_config.htp.tail;
}
#if BITBANG_DEBUG
-static int write_test_pattern(int uart, int pattern_idx)
+static int write_test_pattern(int pattern_idx)
{
- if (!uart_bitbang_is_enabled(uart)) {
+ if (!uart_bitbang_is_enabled()) {
ccprintf("bit banging mode not enabled for UART%d\n", uart);
return EC_ERROR_INVAL;
}
switch (pattern_idx) {
case 0:
- uartn_write_char(uart, 'a');
- uartn_write_char(uart, 'b');
- uartn_write_char(uart, 'c');
- uartn_write_char(uart, '\n');
+ uart_bitbang_write_char(uart, 'a');
+ uart_bitbang_write_char(uart, 'b');
+ uart_bitbang_write_char(uart, 'c');
+ uart_bitbang_write_char(uart, '\n');
ccprintf("wrote: 'abc\\n'\n");
break;
case 1:
- uartn_write_char(uart, 0xAA);
- uartn_write_char(uart, 0xCC);
- uartn_write_char(uart, 0x55);
+ uart_bitbang_write_char(uart, 0xAA);
+ uart_bitbang_write_char(uart, 0xCC);
+ uart_bitbang_write_char(uart, 0x55);
ccprintf("wrote: '0xAA 0xCC 0x55'\n");
break;
@@ -410,13 +392,11 @@ static int write_test_pattern(int uart, int pattern_idx)
static int command_bitbang(int argc, char **argv)
{
- int uart;
int baud_rate;
int parity;
int rv;
if (argc > 1) {
- uart = atoi(argv[1]);
if (argc == 3) {
if (!strcasecmp("disable", argv[2])) {
bitbang_wanted = 0;
@@ -429,7 +409,7 @@ static int command_bitbang(int argc, char **argv)
if (argc == 4) {
#if BITBANG_DEBUG
if (!strncasecmp("test", argv[2], 4))
- return write_test_pattern(uart, atoi(argv[3]));
+ return write_test_pattern(atoi(argv[3]));
#endif /* BITBANG_DEBUG */
baud_rate = atoi(argv[2]);
@@ -442,7 +422,7 @@ static int command_bitbang(int argc, char **argv)
else
return EC_ERROR_PARAM3;
- rv = uart_bitbang_config(uart, baud_rate, parity);
+ rv = uart_bitbang_config(baud_rate, parity);
if (rv)
return rv;
@@ -457,7 +437,7 @@ static int command_bitbang(int argc, char **argv)
return EC_ERROR_PARAM_COUNT;
}
- if (!uart_bitbang_is_enabled(bitbang_config.uart)) {
+ if (!uart_bitbang_is_enabled()) {
ccprintf("bit banging mode disabled.\n");
} else {
ccprintf("baud rate - parity\n");
diff --git a/chip/g/uart_bitbang.h b/chip/g/uart_bitbang.h
index 7a8a33e923..8ebf5635a0 100644
--- a/chip/g/uart_bitbang.h
+++ b/chip/g/uart_bitbang.h
@@ -54,51 +54,41 @@ extern struct uart_bitbang_properties bitbang_config;
*
* If configuration succeeds, then call uart_bitbang_enable() on the port.
*
- * @param uart: Index of UART to enable bit banging mode.
* @param baud_rate: desired baud rate.
* @param parity: 0: no parity, 1: odd parity, 2: even parity.
*
* @returns EC_SUCCESS on success, otherwise an error.
*/
-int uart_bitbang_config(int uart, int baud_rate, int parity);
+int uart_bitbang_config(int baud_rate, int parity);
/**
* Enable bit banging mode for a UART.
*
* The UART must have been configured first.
- *
- * @param uart: Index of UART to disable bit banging mode.
*/
-int uart_bitbang_enable(int uart);
+int uart_bitbang_enable(void);
/**
* Disable bit banging mode for a UART.
- *
- * @param uart: Index of UART to disable bit banging mode.
*/
-int uart_bitbang_disable(int uart);
+int uart_bitbang_disable(void);
/**
* Returns 1 if bit banging mode is enabled for the UART.
- *
- * @param uart: Index of UART to query.
*/
-int uart_bitbang_is_enabled(int uart);
+int uart_bitbang_is_enabled(void);
/**
* Returns 1 if bit banging mode is wanted for the UART.
- *
- * @param uart: Index of UART to query.
*/
-int uart_bitbang_is_wanted(int uart);
+int uart_bitbang_is_wanted(void);
/**
* TX a character on a UART configured for bit banging mode.
*
- * @param uart: Index of UART to use.
* @param c: Character to send out.
*/
-void uart_bitbang_write_char(int uart, char c);
+void uart_bitbang_write_char(char c);
/**
* Sample the RX line on a UART configured for bit banging mode.
@@ -107,24 +97,19 @@ void uart_bitbang_write_char(int uart, char c);
* receive a character. Incoming data with framing errors or parity errors will
* be discarded.
*
- * @param uart: Index of UART to use.
* @returns EC_SUCCESS if a character was successfully received, EC_ERROR_CRC if
* there was a framing or parity issue.
*/
-int uart_bitbang_receive_char(int uart);
+int uart_bitbang_receive_char(void);
/**
* Returns 1 if there are characters available for consumption, otherwise 0.
- *
- * @param uart: Index of UART to check.
*/
-int uart_bitbang_is_char_available(int uart);
+int uart_bitbang_is_char_available(void);
/**
* Retrieve a character from the bit bang RX buffer.
- *
- * @param uart: Index of UART to use.
*/
-int uart_bitbang_read_char(int uart);
+int uart_bitbang_read_char(void);
#endif /* __CROS_EC_CHIP_G_UART_BITBANG_H */
diff --git a/chip/g/uartn.c b/chip/g/uartn.c
index b9d08d4375..0c9b5882dd 100644
--- a/chip/g/uartn.c
+++ b/chip/g/uartn.c
@@ -151,22 +151,22 @@ int uartn_read_char(int uart)
#ifdef CONFIG_UART_BITBANG
int _uart_bitbang_rx_available(int uart)
{
- if (uart_bitbang_is_enabled(uart))
- return uart_bitbang_is_char_available(uart);
+ if (uart_bitbang_is_enabled())
+ return uart_bitbang_is_char_available();
return 0;
}
void _uart_bitbang_write_char(int uart, char c)
{
- if (uart_bitbang_is_enabled(uart))
- uart_bitbang_write_char(uart, c);
+ if (uart_bitbang_is_enabled())
+ uart_bitbang_write_char(c);
}
int _uart_bitbang_read_char(int uart)
{
- if (uart_bitbang_is_enabled(uart))
- return uart_bitbang_read_char(uart);
+ if (uart_bitbang_is_enabled())
+ return uart_bitbang_read_char();
return 0;
}