summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Staaf <robotboy@chromium.org>2014-11-10 11:29:32 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-13 03:14:32 +0000
commit8e25d9e1fc4e23c8f379dac8bd9fbdbf09b602c3 (patch)
treead03c355f87bf929186860dc13d217901727a0de
parent079742b1ffb352cb0149d4fea232747e83dd6209 (diff)
downloadchrome-ec-8e25d9e1fc4e23c8f379dac8bd9fbdbf09b602c3.tar.gz
ryu: Add minimal Case Closed Debug support
This provides a framework for additional work. It exposes an API (ccd_set_mode) that can be used by the PD code to enable Case Closed Debug. Enabling CCD will result in the USB 2.0 lines on Ryu (proto 2) to be disconnected from the AP and for the USB peripheral to be enabled and connected to the host. The result is an enumerated device with no interfaces. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Enable CCD ryu_p2 and verify that it is enumerated by the host correctly. This requires a reworked Ryu (proto 2 with pullup). Change-Id: I1fbecdd5f94a61519cfc18c5e087892c6bd77fde Reviewed-on: https://chromium-review.googlesource.com/229139 Reviewed-by: Anton Staaf <robotboy@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org> Tested-by: Anton Staaf <robotboy@chromium.org>
-rw-r--r--board/ryu/board.c46
-rw-r--r--board/ryu/board.h28
-rw-r--r--common/build.mk1
-rw-r--r--common/case_closed_debug.c39
-rw-r--r--include/case_closed_debug.h49
-rw-r--r--include/config.h5
6 files changed, 168 insertions, 0 deletions
diff --git a/board/ryu/board.c b/board/ryu/board.c
index af660017fb..65019c4d2d 100644
--- a/board/ryu/board.c
+++ b/board/ryu/board.c
@@ -7,9 +7,11 @@
#include "adc.h"
#include "adc_chip.h"
#include "battery.h"
+#include "case_closed_debug.h"
#include "charger.h"
#include "common.h"
#include "console.h"
+#include "ec_version.h"
#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
@@ -20,9 +22,12 @@
#include "power_button.h"
#include "registers.h"
#include "task.h"
+#include "usb.h"
#include "usb_pd.h"
#include "usb_pd_config.h"
+#include "usb-stm32f3.h"
#include "util.h"
+#include "pi3usb9281.h"
void vbus_evt(enum gpio_signal signal)
{
@@ -37,6 +42,15 @@ void unhandled_evt(enum gpio_signal signal)
#include "gpio_list.h"
+const void *const usb_strings[] = {
+ [USB_STR_DESC] = usb_string_desc,
+ [USB_STR_VENDOR] = USB_STRING_DESC("Google Inc."),
+ [USB_STR_PRODUCT] = USB_STRING_DESC("Ryu - Raiden debug"),
+ [USB_STR_VERSION] = USB_STRING_DESC(CROS_EC_VERSION32),
+};
+
+BUILD_ASSERT(ARRAY_SIZE(usb_strings) == USB_STR_COUNT);
+
/* Initialize board. */
static void board_init(void)
{
@@ -151,3 +165,35 @@ int extpower_is_present(void)
{
return gpio_get_level(GPIO_CHGR_ACOK);
}
+
+/*
+ * Disconnect the USB lines from the AP, this enables manual control of the
+ * Pericom polarity switch and disconnects the USB 2.0 lines
+ */
+void ccd_board_connect(void)
+{
+ pi3usb9281_set_pins(0, 0x00);
+ pi3usb9281_set_switch_manual(0, 0);
+}
+
+/*
+ * Reconnect the USB lines to the AP re-enabling automatic switching
+ */
+void ccd_board_disconnect(void)
+{
+ pi3usb9281_set_switch_manual(0, 1);
+}
+
+void usb_board_connect(void)
+{
+ /*
+ * TODO(robotboy): Enable DP pullup for Proto 3, Proto 2 doesn't have
+ * the DP pullup, so case closed debug will only work on a Proto 2 if
+ * the board is reworked, and this function is updated.
+ */
+}
+
+void usb_board_disconnect(void)
+{
+ /* TODO(robotboy): Disable DP pullup for Proto 3 */
+}
diff --git a/board/ryu/board.h b/board/ryu/board.h
index 8e708b97c4..8c21e1b700 100644
--- a/board/ryu/board.h
+++ b/board/ryu/board.h
@@ -25,6 +25,7 @@
#define CONFIG_USB_PD_DUAL_ROLE
#define CONFIG_USB_PD_FLASH_ERASE_CHECK
#define CONFIG_USB_PD_INTERNAL_COMP
+#define CONFIG_USB_SWITCH_PI3USB9281
#define CONFIG_USBC_SS_MUX
#define CONFIG_USBC_VCONN
#define CONFIG_ADC
@@ -82,6 +83,23 @@
#define CONFIG_HOSTCMD_I2C_SLAVE_ADDR 0x3c
#endif
+/* USB Configuration */
+#define CONFIG_USB
+#define CONFIG_USB_PID 0x500f
+
+/* Prevent the USB driver from initializing at boot */
+#define CONFIG_USB_INHIBIT_INIT
+
+/* USB interface indexes (use define rather than enum to expand them) */
+#define USB_IFACE_COUNT 0
+
+/* USB endpoint indexes (use define rather than enum to expand them) */
+#define USB_EP_CONTROL 0
+#define USB_EP_COUNT 1
+
+/* Enable Case Closed Debugging */
+#define CONFIG_CASE_CLOSED_DEBUG
+
#ifndef __ASSEMBLER__
/* Timer selection */
@@ -109,6 +127,16 @@ enum adc_channel {
ADC_CH_COUNT
};
+/* USB string indexes */
+enum usb_strings {
+ USB_STR_DESC = 0,
+ USB_STR_VENDOR,
+ USB_STR_PRODUCT,
+ USB_STR_VERSION,
+
+ USB_STR_COUNT
+};
+
/* Discharge battery when on AC power for factory test. */
int board_discharge_on_ac(int enable);
diff --git a/common/build.mk b/common/build.mk
index acc650522a..e304756895 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -21,6 +21,7 @@ common-$(CONFIG_BATTERY_BQ27541)+=battery.o
common-$(CONFIG_BATTERY_SMART)+=battery.o
common-$(CONFIG_BUTTON_COUNT)+=button.o
common-$(CONFIG_CAPSENSE)+=capsense.o
+common-$(CONFIG_CASE_CLOSED_DEBUG)+=case_closed_debug.o
common-$(CONFIG_CHARGE_MANAGER)+=charge_manager.o
common-$(CONFIG_CHARGER)+=charger.o
common-$(CONFIG_CHARGER_V1)+=charge_state_v1.o
diff --git a/common/case_closed_debug.c b/common/case_closed_debug.c
new file mode 100644
index 0000000000..08e5e8411d
--- /dev/null
+++ b/common/case_closed_debug.c
@@ -0,0 +1,39 @@
+/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Case Closed Debug common implementation
+ */
+
+#include "case_closed_debug.h"
+
+#include "common.h"
+#include "usb_api.h"
+
+#if !defined(CONFIG_USB_INHIBIT_INIT)
+#error "CONFIG_USB_INHIBIT_INIT must be defined to use Case Closed Debugging"
+#endif
+
+#if !defined(CONFIG_USB)
+#error "CONFIG_USB must be defined to use Case Closed Debugging"
+#endif
+
+static enum ccd_mode current_mode = CCD_MODE_DISABLED;
+
+void ccd_set_mode(enum ccd_mode new_mode)
+{
+ if (new_mode == current_mode)
+ return;
+
+ if (current_mode != CCD_MODE_DISABLED) {
+ usb_release();
+ ccd_board_disconnect();
+ }
+
+ current_mode = new_mode;
+
+ if (new_mode != CCD_MODE_DISABLED) {
+ ccd_board_connect();
+ usb_init();
+ }
+}
diff --git a/include/case_closed_debug.h b/include/case_closed_debug.h
new file mode 100644
index 0000000000..1884e545d9
--- /dev/null
+++ b/include/case_closed_debug.h
@@ -0,0 +1,49 @@
+/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Case Closed Debug interface
+ */
+#ifndef INCLUDE_CASE_CLOSED_DEBUG_H
+#define INCLUDE_CASE_CLOSED_DEBUG_H
+
+enum ccd_mode {
+ /*
+ * The disabled mode tri-states the DP and DN lines.
+ */
+ CCD_MODE_DISABLED,
+
+ /*
+ * The partial mode allows some CCD functionality and is to be set
+ * when the device is write protected and a CCD cable is detected.
+ * This mode gives access to the APs console.
+ */
+ CCD_MODE_PARTIAL,
+
+ /*
+ * The fully enabled mode is used in factory and test lab
+ * configurations where it is acceptable to be able to reflash the
+ * device over CCD.
+ */
+ CCD_MODE_ENABLED,
+};
+
+/*
+ * Set current CCD mode, this function is idempotent.
+ */
+void ccd_set_mode(enum ccd_mode new_mode);
+
+/*
+ * Board provided function that should ensure that the debug USB port is ready
+ * for use by the case closed debug code. This could mean updating a MUX or
+ * switch to disconnect USB from the AP.
+ */
+void ccd_board_connect(void);
+
+/*
+ * Board provided function that releases the debug USB port, giving it back
+ * to the AP.
+ */
+void ccd_board_disconnect(void);
+
+#endif /* INCLUDE_CASE_CLOSED_DEBUG_H */
diff --git a/include/config.h b/include/config.h
index 324646f7e0..0cc350bd02 100644
--- a/include/config.h
+++ b/include/config.h
@@ -193,6 +193,11 @@
#undef CONFIG_BUTTON_COUNT
/*
+ * Enable case close debug (CCD) mode.
+ */
+#undef CONFIG_CASE_CLOSED_DEBUG
+
+/*
* Capsense chip has buttons, too.
*/
#undef CONFIG_CAPSENSE