summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)