summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2015-05-04 17:30:07 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-05-06 04:40:15 +0000
commitcee77a8be793720101c6ae90980a76e00e5beed9 (patch)
treea0b2dac31aff32a32319201e9bd69913cb5df52b
parentb9222ae92452a1983e92ee4f73607ea68e4fe6dc (diff)
downloadchrome-ec-cee77a8be793720101c6ae90980a76e00e5beed9.tar.gz
ryu: add control of switch for USB D+/D-
Add setting the Pericom D+/D- switch state to board_set_usb_mux(). This is useful on Ryu because we have to fully debounce the type-C CC lines before setting the SS muxes, ~100ms, and we don't want the host to give up on enumerating SS while we are debouncing. So, instead, we keep the D+/D- lines disconnected until after we debounce and right before setting type-C muxes for SS. BUG=none BRANCH=none TEST=make -j buildall Change-Id: Ifb7c06d82e35c312ebfce871bff0056a83b4887a Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/269250 Commit-Queue: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--board/ryu/board.c26
-rw-r--r--board/ryu_p4p5/board.c34
2 files changed, 58 insertions, 2 deletions
diff --git a/board/ryu/board.c b/board/ryu/board.c
index b34d50d3db..a5b5346e93 100644
--- a/board/ryu/board.c
+++ b/board/ryu/board.c
@@ -49,6 +49,12 @@
static int charge_current_limit;
+/*
+ * Store the state of our USB data switches so that they can be restored
+ * after pericom reset.
+ */
+static int usb_switch_state;
+
static void vbus_log(void)
{
CPRINTS("VBUS %d", gpio_get_level(GPIO_CHGR_ACOK));
@@ -104,6 +110,13 @@ void usb_charger_task(void)
/* Trigger chip reset to refresh detection registers */
pi3usb9281_reset(0);
+ /*
+ * Restore data switch settings - switches return to
+ * closed on reset until restored.
+ */
+ if (usb_switch_state)
+ pi3usb9281_set_switches(0, 1);
+
/* Clear possible disconnect interrupt */
pi3usb9281_get_interrupts(0);
/* Mask attach interrupt */
@@ -369,6 +382,16 @@ const struct i2c_port_t i2c_ports[] = {
};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
+static void board_set_usb_switches(int port, int open)
+{
+ /* If switch is not changing, then return */
+ if (open == usb_switch_state)
+ return;
+
+ usb_switch_state = open;
+ pi3usb9281_set_switches(port, open);
+}
+
void board_set_usb_mux(int port, enum typec_mux mux,
enum usb_switch usb, int polarity)
{
@@ -377,6 +400,9 @@ void board_set_usb_mux(int port, enum typec_mux mux,
gpio_set_level(GPIO_USBC_MUX_CONF1, 0);
gpio_set_level(GPIO_USBC_MUX_CONF2, 0);
+ /* Set D+/D- switch to appropriate level */
+ board_set_usb_switches(port, usb);
+
if (mux == TYPEC_MUX_NONE)
/* everything is already disabled, we can return */
return;
diff --git a/board/ryu_p4p5/board.c b/board/ryu_p4p5/board.c
index 19daf6c587..e00dec962d 100644
--- a/board/ryu_p4p5/board.c
+++ b/board/ryu_p4p5/board.c
@@ -49,6 +49,12 @@
static int charge_current_limit;
+/*
+ * Store the state of our USB data switches so that they can be restored
+ * after pericom reset.
+ */
+static int usb_switch_state;
+
static void vbus_log(void)
{
CPRINTS("VBUS %d", gpio_get_level(GPIO_CHGR_ACOK));
@@ -104,6 +110,13 @@ void usb_charger_task(void)
/* Trigger chip reset to refresh detection registers */
pi3usb9281_reset(0);
+ /*
+ * Restore data switch settings - switches return to
+ * closed on reset until restored.
+ */
+ if (usb_switch_state)
+ pi3usb9281_set_switches(0, 1);
+
/* Clear possible disconnect interrupt */
pi3usb9281_get_interrupts(0);
/* Mask attach interrupt */
@@ -372,12 +385,23 @@ const struct i2c_port_t i2c_ports[] = {
};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
+static void board_set_usb_switches(int port, int open)
+{
+ /* If switch is not changing, then return */
+ if (open == usb_switch_state)
+ return;
+
+ usb_switch_state = open;
+ pi3usb9281_set_switches(port, open);
+}
+
/* TODO(crosbug.com/p/38333) remove me */
#define GPIO_USBC_SS1_USB_MODE_L GPIO_USBC_MUX_CONF0
#define GPIO_USBC_SS2_USB_MODE_L GPIO_USBC_MUX_CONF1
#define GPIO_USBC_SS_EN_L GPIO_USBC_MUX_CONF2
-void p4_board_set_usb_mux(int port, enum typec_mux mux, int polarity)
+void p4_board_set_usb_mux(int port, enum typec_mux mux,
+ enum usb_switch usb, int polarity)
{
/* reset everything */
gpio_set_level(GPIO_USBC_SS_EN_L, 1);
@@ -386,6 +410,9 @@ void p4_board_set_usb_mux(int port, enum typec_mux mux, int polarity)
gpio_set_level(GPIO_USBC_SS1_USB_MODE_L, 1);
gpio_set_level(GPIO_USBC_SS2_USB_MODE_L, 1);
+ /* Set D+/D- switch to appropriate level */
+ board_set_usb_switches(port, usb);
+
if (mux == TYPEC_MUX_NONE)
/* everything is already disabled, we can return */
return;
@@ -411,7 +438,7 @@ void board_set_usb_mux(int port, enum typec_mux mux,
if (board_get_version() < 5) {
/* P4/EVT or older boards */
/* TODO(crosbug.com/p/38333) remove this */
- p4_board_set_usb_mux(port, mux, polarity);
+ p4_board_set_usb_mux(port, mux, usb, polarity);
return;
}
@@ -420,6 +447,9 @@ void board_set_usb_mux(int port, enum typec_mux mux,
gpio_set_level(GPIO_USBC_MUX_CONF1, 0);
gpio_set_level(GPIO_USBC_MUX_CONF2, 0);
+ /* Set D+/D- switch to appropriate level */
+ board_set_usb_switches(port, usb);
+
if (mux == TYPEC_MUX_NONE)
/* everything is already disabled, we can return */
return;