summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2015-01-13 16:47:36 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-01-17 20:56:04 +0000
commit13827088583ebe46c89fd0bb4d7889ccb5f9b948 (patch)
tree0be13156103c272cc12310418f1cbe218decb54d
parent6c938998fdfd15dd2dc0466ff8fae7997333b483 (diff)
downloadchrome-ec-13827088583ebe46c89fd0bb4d7889ccb5f9b948.tar.gz
samus_pd: Restore usb data switches after pericom reset
Resetting the pericom charge detector resets all registers, so it's necessary to restore the state of the USB data switches, in case we want them to be open. BUG=chrome-os-partner:35394 TEST=Manual on Samus. Trigger data swap to UFP, verify that USB switches become open. BRANCH=Samus Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I32b1cf92a05abaab9ecd532537790e72f8f409bc Reviewed-on: https://chromium-review.googlesource.com/240538 Reviewed-by: Alec Berg <alecaberg@chromium.org>
-rw-r--r--board/samus_pd/board.c23
-rw-r--r--board/samus_pd/board.h3
-rw-r--r--board/samus_pd/usb_pd_policy.c3
3 files changed, 27 insertions, 2 deletions
diff --git a/board/samus_pd/board.c b/board/samus_pd/board.c
index 4dc471c538..c504486dfc 100644
--- a/board/samus_pd/board.c
+++ b/board/samus_pd/board.c
@@ -47,6 +47,13 @@ static int chg_is_cutoff;
static struct ec_response_pd_status pd_status;
static struct ec_response_host_event_status host_event_status;
+/*
+ * Store the state of our USB data switches so that they can be restored
+ * after pericom reset.
+ */
+static int usb_switch_state[PD_PORT_COUNT];
+static struct mutex usb_switch_lock[PD_PORT_COUNT];
+
/* PWM channels. Must be in the exact same order as in enum pwm_channel. */
const struct pwm_t pwm_channels[] = {
{STM32_TIM(15), STM32_TIM_CH(2), 0, GPIO_ILIM_ADJ_PWM, GPIO_ALT_F1},
@@ -103,6 +110,14 @@ void vbus1_evt(enum gpio_signal signal)
task_wake(TASK_ID_PD_C1);
}
+void set_usb_switches(int port, int open)
+{
+ mutex_lock(&usb_switch_lock[port]);
+ usb_switch_state[port] = open;
+ pi3usb9281_set_switches(port, open);
+ mutex_unlock(&usb_switch_lock[port]);
+}
+
/* Wait 200ms after a charger is detected to debounce pin contact order */
#define USB_CHG_DEBOUNCE_DELAY_MS 200
/*
@@ -133,6 +148,14 @@ void usb_charger_task(void)
/* Trigger chip reset to refresh detection registers */
pi3usb9281_reset(port);
+ /*
+ * Restore data switch settings - switches return to
+ * closed on reset until restored.
+ */
+ mutex_lock(&usb_switch_lock[port]);
+ if (usb_switch_state[port])
+ pi3usb9281_set_switches(port, 1);
+ mutex_unlock(&usb_switch_lock[port]);
/* Clear possible disconnect interrupt */
pi3usb9281_get_interrupts(port);
/* Mask attach interrupt */
diff --git a/board/samus_pd/board.h b/board/samus_pd/board.h
index 7b2a1d9bd6..25f202e899 100644
--- a/board/samus_pd/board.h
+++ b/board/samus_pd/board.h
@@ -132,6 +132,9 @@ int board_get_battery_soc(void);
/* Send host event to AP */
void pd_send_host_event(int mask);
+/* Update the state of the USB data switches */
+void set_usb_switches(int port, int open);
+
#endif /* !__ASSEMBLER__ */
#endif /* __BOARD_H */
diff --git a/board/samus_pd/usb_pd_policy.c b/board/samus_pd/usb_pd_policy.c
index ee2091ed31..2142a0b9bb 100644
--- a/board/samus_pd/usb_pd_policy.c
+++ b/board/samus_pd/usb_pd_policy.c
@@ -10,7 +10,6 @@
#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
-#include "pi3usb9281.h"
#include "registers.h"
#include "system.h"
#include "task.h"
@@ -141,7 +140,7 @@ int pd_check_data_swap(int port, int data_role)
void pd_execute_data_swap(int port, int data_role)
{
/* Open USB switches when taking UFP role */
- pi3usb9281_set_switches(port, (data_role == PD_ROLE_UFP));
+ set_usb_switches(port, (data_role == PD_ROLE_UFP));
}
void pd_check_pr_role(int port, int pr_role, int partner_pr_swap)