summaryrefslogtreecommitdiff
path: root/chip
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2017-08-09 16:19:47 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2017-09-07 22:34:52 +0000
commit0ebe39fc29a85cbf3fa25346d427c6fe5fa2f5e5 (patch)
tree4e98c72772e370d57e7bdc1a61acd4e1fb9afbdb /chip
parent930e7036473f4094a2a4c22cab2fae69f35877cf (diff)
downloadchrome-ec-0ebe39fc29a85cbf3fa25346d427c6fe5fa2f5e5.tar.gz
cr50: Consolidate CCD device enable
Currently, the Cr50 state machines (EC, AP, RDD, bitbang, etc.) manage their own enabling and disabling of the ports (UART, SPI, etc.) This is tricky because the rules for when ports should be enabled are non-trivial and must be applied in the correct order. In additionl the changes all need to be serialized, so that the hardware ends up in the correct state even if multiple state machines are changing simultaneously. Consolidate all of that into chip/g/rdd.c. The debug command for it is now 'ccdstate', which just prints the state machines. This will allow subsequent renaming of the 'ccdopen', etc. commands to 'ccd open', etc. Also include UART bit-banging into that state which must be consistent. Previously, it was possible for bit-banging to leave UART TX connected, instead of returning it to the previous state. Use better names for CCD config fields for UART. I'd had them backwards. BUG=b:62537474 BRANCH=cr50 TEST=manual, with a CR50_DEV=1 image 1) No servo or CCD Pull SERVO_DETECT low (disconnected) Pull CCD_MODE_L high (disabled) Pull EC_DETECT and AP_DETECT high (on) Reboot. RX is enabled even if cables are disconnected so we buffer. ccdstate -> UARTAP UARTEC Pull EC_DETECT low. ccdstate -> UARTAP Pull EC_DETECT high and AP_DETECT low. ccdstate -> UARTEC Pull AP_DETECT high. ccdstate -> UARTAP UARTEC 2) Servo only still allows UART RX Pull SERVO_DETECT high (connected). ccdstate -> UARTAP UARTEC 3) Both servo and CCD prioritizes servo. Pull CCD_MODE_L low (enabled). ccdstate -> UARTAP UARTEC Reboot, to make sure servo wins at boot time. ccdstate -> UARTAP UARTEC Bit-banging doesn't work when servo is connected. bitbang 2 9600 even -> superseded by servo bitbang -> disabled ccdstate -> UARTAP UARTEC 4) CCD only allows more ports and remembers we wanted to bit-bang Pull SERVO_DETECT low. ccdstate --> UARTAP+TX UARTEC+BB I2C SPI bitbang 2 disable ccdstate --> UARTAP+TX UARTEC+TX I2C SPI Reboot and see we don't take over servo ports until we're sure servo isn't present. ccdstate --> UARTAP UARTEC (for first second) ccdstate --> UARTAP+TX UARTEC+TX I2C SPI (after that) 5) Bit-banging takes over ECTX bitbang 2 9600 even bitbang -> baud rate 9600, parity even ccdstate -> UARTAP+TX UARTEC+BB I2C SPI bitbang 2 disable ccdstate -> UARTAP+TX UARTEC+TX I2C SPI 6) Permissions work. Allow easy access to full console and ccdopen: ccdset OpenNoTPMWipe always ccdset OpenNoLongPP always ccdset GscFullConsole always Default when locked is full AP UART EC RO, no I2C or SPI ccdlock ccdstate -> UARTAP+TX UARTEC No EC transmit permission means no bit-banging bitbang 2 9600 even bitbang -> disabled ccdstate -> UARTAP+TX UARTEC But it remembers that we wanted to ccdopen ccdstate -> UARTAP+TX UARTEC+BB I2C SPI bitbang 2 disable ccdstate -> UARTAP+TX UARTEC+TX I2C SPI Try turning on/off permissions ccdset UartGscTxECRx always ccdlock ccdstate -> UARTAP+TX UARTEC+TX No read means no write either ccdset UartGscRxECTx ifopened ccdlock ccdstate -> UARTAP+TX ccdopen ccdset UartGscRXAPTx ifopened ccdlock ccdstate -> (nothing) Check AP transmit permissions too ccdopen ccdset UartGscRxAPTx always ccdset UartGscTxAPRx ifopened ccdlock ccdstate -> UARTAP Check I2C ccdopen ccdset I2C always ccdlock ccdstate -> UARTAP I2C SPI port is enabled if either EC or AP flash is allowed ccdopen ccdset flashap always ccdlock ccdstate -> UARTAP I2C SPI ccdopen ccdset flashec always ccdset flashap ifopened ccdlock ccdstate -> UARTAP I2C SPI Back to defaults ccdoops Change-Id: I641f7ab2354570812e3fb37b470de32e5bd10db7 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/615928 Reviewed-by: Mary Ruthven <mruthven@chromium.org> (cherry picked from commit a285acd36f898a394b82b8cb865bf60922f7ae2c) Reviewed-on: https://chromium-review.googlesource.com/656425 Commit-Queue: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'chip')
-rw-r--r--chip/g/uart_bitbang.c69
-rw-r--r--chip/g/uart_bitbang.h22
2 files changed, 73 insertions, 18 deletions
diff --git a/chip/g/uart_bitbang.c b/chip/g/uart_bitbang.c
index b1afb6504c..6d38626b68 100644
--- a/chip/g/uart_bitbang.c
+++ b/chip/g/uart_bitbang.c
@@ -32,6 +32,9 @@
/* Flag indicating whether bit banging is enabled or not. */
static uint8_t bitbang_enabled;
+/* Flag indicating bit banging is desired. Allows async enable/disable. */
+static uint8_t bitbang_wanted;
+
static int rx_buf[RX_BUF_SIZE];
/* Current bitbang context */
@@ -61,23 +64,28 @@ static int is_uart_allowed(int uart)
int uart_bitbang_is_enabled(int uart)
{
- return (is_uart_allowed(uart) && !!bitbang_enabled);
+ return (is_uart_allowed(uart) && bitbang_enabled);
+}
+
+int uart_bitbang_is_wanted(int uart)
+{
+ return (is_uart_allowed(uart) && bitbang_wanted);
}
-int uart_bitbang_enable(int uart, int baud_rate, int parity)
+int uart_bitbang_config(int uart, int baud_rate, int parity)
{
- /* We only want to bit bang 1 UART at a time. */
+ /* 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", 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)", baud_rate);
+ CPRINTF("Err: invalid baud rate (%d)\n", baud_rate);
return EC_ERROR_INVAL;
}
bitbang_config.baud_rate = baud_rate;
@@ -89,13 +97,30 @@ int uart_bitbang_enable(int uart, int baud_rate, int parity)
break;
default:
- CPRINTF("Err: invalid parity '%d'. (0:N, 1:O, 2:E)", parity);
+ CPRINTF("Err: invalid parity '%d'. (0:N, 1:O, 2:E)\n", parity);
return EC_ERROR_INVAL;
};
bitbang_config.htp.parity = parity;
- /* Select the GPIOs instead of the UART block. */
- uartn_tx_disconnect(bitbang_config.uart);
+ return EC_SUCCESS;
+}
+
+int uart_bitbang_enable(int uart)
+{
+ /* 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))
+ 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;
gpio_set_flags(bitbang_config.tx_gpio, GPIO_OUT_HIGH);
@@ -126,7 +151,7 @@ int uart_bitbang_enable(int uart, int baud_rate, int parity)
bitbang_enabled = 1;
gpio_enable_interrupt(bitbang_config.rx_gpio);
- ccprintf("successfully enabled\n");
+ CPRINTS("Bit bang enabled");
return EC_SUCCESS;
}
@@ -151,9 +176,9 @@ int uart_bitbang_disable(int uart)
/* Gate the microsecond timer since we're done with it. */
pmu_clock_dis(PERIPH_TIMEUS);
- /* Reconnect the GPIO to the UART block. */
+ /* Don't need to watch RX */
gpio_disable_interrupt(bitbang_config.rx_gpio);
- uartn_tx_connect(uart);
+ CPRINTS("Bit bang disabled");
return EC_SUCCESS;
}
@@ -388,14 +413,17 @@ 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]))
- return uart_bitbang_disable(uart);
- else
- return EC_ERROR_PARAM2;
+ if (!strcasecmp("disable", argv[2])) {
+ bitbang_wanted = 0;
+ ccd_update_state();
+ return EC_SUCCESS;
+ }
+ return EC_ERROR_PARAM2;
}
if (argc == 4) {
@@ -414,7 +442,16 @@ static int command_bitbang(int argc, char **argv)
else
return EC_ERROR_PARAM3;
- return uart_bitbang_enable(uart, baud_rate, parity);
+ rv = uart_bitbang_config(uart, baud_rate, parity);
+ if (rv)
+ return rv;
+
+ if (servo_is_connected())
+ ccprintf("Bit banging superseded by servo\n");
+
+ bitbang_wanted = 1;
+ ccd_update_state();
+ return EC_SUCCESS;
}
return EC_ERROR_PARAM_COUNT;
diff --git a/chip/g/uart_bitbang.h b/chip/g/uart_bitbang.h
index f29c35dd34..7a8a33e923 100644
--- a/chip/g/uart_bitbang.h
+++ b/chip/g/uart_bitbang.h
@@ -50,7 +50,9 @@ struct uart_bitbang_properties {
extern struct uart_bitbang_properties bitbang_config;
/**
- * Enable bit banging mode for a UART.
+ * Configure bit banging mode for a UART.
+ *
+ * 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.
@@ -58,7 +60,16 @@ extern struct uart_bitbang_properties bitbang_config;
*
* @returns EC_SUCCESS on success, otherwise an error.
*/
-int uart_bitbang_enable(int uart, int baud_rate, int parity);
+int uart_bitbang_config(int uart, 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);
/**
* Disable bit banging mode for a UART.
@@ -75,6 +86,13 @@ int uart_bitbang_disable(int uart);
int uart_bitbang_is_enabled(int uart);
/**
+ * 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);
+
+/**
* TX a character on a UART configured for bit banging mode.
*
* @param uart: Index of UART to use.