From b83dbc319990eda37f7eb6fd6516e70640ab3ac6 Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Tue, 10 Nov 2015 11:25:46 -0800 Subject: [PATCH] usb_charger: disconnect usb switch until connection is debounced Re-order logic in BC1.2 detection task so that we open the USB switches immediately upon detecting a connection, then debounce the connection, then reset the pericom and determine BC1.2 charger type. This fixes two problems: - Problem where host could enumerate dut, detect disconnect, and then re-enumerate. - Problem where sometimes dut would detect a host workstation as a proprietary charger because we weren't delaying long enough after opening USB switches before triggering pericom reset. BUG=chrome-os-partner:47219 BRANCH=smaug TEST=tested by connecting workstation to ryu (tested both pluggin in A side first and C side first). Without this patch, my workstation often see's disconnect and reconnect. With this change we only get one connect. Change-Id: I07cc3473ff32953fad3cc6d1db01b86b44969c4e Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/311804 Reviewed-by: Shawn N --- common/usb_charger.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/common/usb_charger.c b/common/usb_charger.c index b22e8dc99d..713db048cf 100644 --- a/common/usb_charger.c +++ b/common/usb_charger.c @@ -113,15 +113,18 @@ static void usb_charger_bc12_detect(int port) /* Debounce pin plug order if we detect a charger */ if (device_type || PI3USB9281_CHG_STATUS_ANY(charger_status)) { - msleep(USB_CHG_DEBOUNCE_DELAY_MS); - /* next operation might trigger a detach interrupt */ pi3usb9281_disable_interrupts(port); - /* Ensure D+/D- are open before resetting */ + /* + * Ensure D+/D- are open before resetting + * Note: we can't simply call pi3usb9281_set_switches() because + * another task might override it and set the switches closed. + */ pi3usb9281_set_switch_manual(port, 1); pi3usb9281_set_pins(port, 0); - /* Let D+/D- relax to their idle state */ - msleep(40); + + /* Delay to debounce pin attach order */ + msleep(USB_CHG_DEBOUNCE_DELAY_MS); /* * Trigger chip reset to refresh detection registers.