summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2017-08-31 13:40:54 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-09-01 19:01:32 -0700
commit686e0d05adc778e0335fe5b5ec8e5673293b2b5d (patch)
tree1bef335fc21647352f5c192c5380097d89f636dc
parentac1ce379e08505d807eaf5ee2bbb9e1ec1d0b72a (diff)
downloadchrome-ec-686e0d05adc778e0335fe5b5ec8e5673293b2b5d.tar.gz
cr50: Use own CCD EXT state machine
The state machine in common/case_closed_debug.c only handles a subset of what we need to do for Cr50 external case closed debugging, and also supports a 'partial' CCD state that doesn't exist for Cr50. Move the few lines of code from that we actually need into our file. BUG=none BRANCH=cr50 TEST=manual Assert CCD_MODE_L See 'CCD EXT enable' Confirm Cr50 console appears as a RW /dev/ttyUSBn endpoint Confirm firmware update over USB works Deassert CCD_MODE_L See 'CCD EXT disable' Confirm Cr50 console appears as a RW /dev/ttyUSBn endpoint Confirm firmware update over USB does not work (can't find device) Change-Id: Id96f2770632839a9690740ece54bc2eb71d39a38 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/647909 Reviewed-by: Mary Ruthven <mruthven@chromium.org>
-rw-r--r--board/cr50/board.h1
-rw-r--r--board/cr50/rdd.c66
2 files changed, 45 insertions, 22 deletions
diff --git a/board/cr50/board.h b/board/cr50/board.h
index ad0dae24bb..a82c63720c 100644
--- a/board/cr50/board.h
+++ b/board/cr50/board.h
@@ -97,7 +97,6 @@
#define CONFIG_STREAM_USART2
/* Enable Case Closed Debugging */
-#define CONFIG_CASE_CLOSED_DEBUG
#define CONFIG_CASE_CLOSED_DEBUG_V1
#define CONFIG_PHYSICAL_PRESENCE
diff --git a/board/cr50/rdd.c b/board/cr50/rdd.c
index 85b27ad0eb..e55737387d 100644
--- a/board/cr50/rdd.c
+++ b/board/cr50/rdd.c
@@ -14,10 +14,22 @@
#include "system.h"
#include "uartn.h"
#include "usb_api.h"
+#include "usb_console.h"
#include "usb_i2c.h"
+#include "usb_spi.h"
+
+/* Include the dazzlingly complex macro to instantiate the USB SPI config */
+USB_SPI_CONFIG(ccd_usb_spi, USB_IFACE_SPI, USB_EP_SPI);
#define CPRINTS(format, args...) cprints(CC_USB, format, ## args)
+static enum device_state state = DEVICE_STATE_INIT;
+
+int ccd_ext_is_enabled(void)
+{
+ return state == DEVICE_STATE_CONNECTED;
+}
+
/* If the UART TX is connected the pinmux select will have a non-zero value */
int uart_tx_is_connected(int uart)
{
@@ -80,14 +92,34 @@ void uartn_tx_disconnect(int uart)
uart_select_tx(uart, 0);
}
-static void configure_ccd(int enable)
+static void rdd_check_pin(void)
{
- if (enable) {
- if (ccd_ext_is_enabled())
- return;
+ /* The CCD mode pin is active low. */
+ int enable = !gpio_get_level(GPIO_CCD_MODE_L);
- /* Enable CCD */
- ccd_set_mode(CCD_MODE_ENABLED);
+ if (enable == ccd_ext_is_enabled())
+ return;
+
+ if (enable) {
+ /*
+ * If we're not disconnected, release USB to ensure it's in a
+ * good state before we usb_init(). This matches what
+ * common/case_closed_debug.c does.
+ *
+ * Not sure exactly why this is necessary. It could be because
+ * that also has CCD_MODE_PARTIAL, and the only way to go
+ * cleanly between ENABLED and PARTIAL is to disable things and
+ * then re-enable only what's needed?
+ */
+ if (state != DEVICE_STATE_DISCONNECTED)
+ usb_release();
+
+ CPRINTS("CCD EXT enable");
+ state = DEVICE_STATE_CONNECTED;
+
+ usb_console_enable(1, 0);
+ usb_spi_enable(&ccd_usb_spi, 1);
+ usb_init();
/* Attempt to connect UART TX */
uartn_tx_connect(UART_AP);
@@ -96,28 +128,20 @@ static void configure_ccd(int enable)
/* Turn on 3.3V rail used for INAs and initialize I2CM module */
usb_i2c_board_enable();
} else {
+ CPRINTS("CCD EXT disable");
+ state = DEVICE_STATE_DISCONNECTED;
+
+ usb_release();
+ usb_console_enable(0, 0);
+ usb_spi_enable(&ccd_usb_spi, 0);
+
/* Disconnect from AP and EC UART TX peripheral from gpios */
uartn_tx_disconnect(UART_EC);
uartn_tx_disconnect(UART_AP);
- /* Disable CCD */
- ccd_set_mode(CCD_MODE_DISABLED);
-
/* Turn off 3.3V rail to INAs and disconnect I2CM module */
usb_i2c_board_disable();
}
- CPRINTS("CCD is now %sabled.", enable ? "en" : "dis");
-}
-
-static void rdd_check_pin(void)
-{
- /* The CCD mode pin is active low. */
- int enable = !gpio_get_level(GPIO_CCD_MODE_L);
-
- if (enable == ccd_ext_is_enabled())
- return;
-
- configure_ccd(enable);
}
DECLARE_HOOK(HOOK_SECOND, rdd_check_pin, HOOK_PRIO_DEFAULT);