summaryrefslogtreecommitdiff
path: root/common/usb_charger.c
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2015-08-03 13:51:53 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-08-04 19:22:07 +0000
commitd804e8fdbd1e9f238317c68d235add1806dcd49f (patch)
tree4a3b0a1939043a2e1aac02c6676036aacf919502 /common/usb_charger.c
parentccc085dd9a22ce123c16fcf24a816732a3df116f (diff)
downloadchrome-ec-d804e8fdbd1e9f238317c68d235add1806dcd49f.tar.gz
usb_charger: cleanup: move setting usb 2 switches to usb_charger
Move function to set D+/D- switches from board directory to usb_charger module. BUG=none BRANCH=strago TEST=make -j buildall Change-Id: I5c5997c799cecea90448444863167af860a8f3e1 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/290421 Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'common/usb_charger.c')
-rw-r--r--common/usb_charger.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/common/usb_charger.c b/common/usb_charger.c
index 468d2c97af..de81ad0497 100644
--- a/common/usb_charger.c
+++ b/common/usb_charger.c
@@ -27,6 +27,13 @@
*/
#define USB_CHG_RESET_DELAY_MS 100
+/*
+ * Store the state of our USB data switches so that they can be restored
+ * after pericom reset.
+ */
+static int usb_switch_state[CONFIG_USB_PD_PORT_COUNT];
+static struct mutex usb_switch_lock[CONFIG_USB_PD_PORT_COUNT];
+
int usb_charger_port_is_sourcing_vbus(int port)
{
if (port == 0)
@@ -39,6 +46,19 @@ int usb_charger_port_is_sourcing_vbus(int port)
return 0;
}
+void usb_charger_set_switches(int port, enum usb_switch setting)
+{
+ /* If switch is not changing then return */
+ if (setting == usb_switch_state[port])
+ return;
+
+ mutex_lock(&usb_switch_lock[port]);
+ if (setting != USB_SWITCH_RESTORE)
+ usb_switch_state[port] = setting;
+ pi3usb9281_set_switches(port, usb_switch_state[port]);
+ mutex_unlock(&usb_switch_lock[port]);
+}
+
void usb_charger_task(void)
{
int port = (task_get_current() == TASK_ID_USB_CHG_P0 ? 0 : 1);
@@ -89,7 +109,7 @@ void usb_charger_task(void)
* Restore data switch settings - switches return to
* closed on reset until restored.
*/
- board_set_usb_switches(port, USB_SWITCH_RESTORE);
+ usb_charger_set_switches(port, USB_SWITCH_RESTORE);
/* Clear possible disconnect interrupt */
pi3usb9281_get_interrupts(port);
/* Mask attach interrupt */