summaryrefslogtreecommitdiff
path: root/board/cheza
diff options
context:
space:
mode:
Diffstat (limited to 'board/cheza')
-rw-r--r--board/cheza/gpio.inc2
-rw-r--r--board/cheza/usb_pd_policy.c34
2 files changed, 33 insertions, 3 deletions
diff --git a/board/cheza/gpio.inc b/board/cheza/gpio.inc
index c721f94b73..72cd70ab0f 100644
--- a/board/cheza/gpio.inc
+++ b/board/cheza/gpio.inc
@@ -102,8 +102,6 @@ GPIO(CHG_LED_W_C1, PIN(C, 0), GPIO_OUT_LOW) /* EC_CHG_LED_W_C1 */
* +------- C1_MUX:D2
* | |
* AP --- USB_HUB
- *
- * TODO(waihong): Support auto-detection and switching.
*/
/* Switch both port-0 and port-1 to the hub, which matches the SS path. */
GPIO(USB_C0_HS_MUX_OE_L, PIN(A, 4), GPIO_OUT_LOW)
diff --git a/board/cheza/usb_pd_policy.c b/board/cheza/usb_pd_policy.c
index 5f5e707819..bbc44a746e 100644
--- a/board/cheza/usb_pd_policy.c
+++ b/board/cheza/usb_pd_policy.c
@@ -6,6 +6,7 @@
#include "charge_manager.h"
#include "console.h"
#include "gpio.h"
+#include "pi3usb9281.h"
#include "system.h"
#include "usb_mux.h"
#include "usbc_ppc.h"
@@ -93,7 +94,38 @@ int pd_check_vconn_swap(int port)
void pd_execute_data_swap(int port, int data_role)
{
- /* Do nothing */
+ int enable = (data_role == PD_ROLE_UFP);
+ int type;
+
+ /*
+ * Exclude the PD charger, in which the "USB Communications Capable"
+ * bit is unset in the Fixed Supply PDO.
+ */
+ if (pd_capable(port))
+ enable = enable && pd_get_partner_usb_comm_capable(port);
+
+ /*
+ * The hub behind the BC1.2 chip may advertise a BC1.2 type. So
+ * disconnect the switch when getting the charger type to ensure
+ * the detected type is from external.
+ */
+ usb_charger_set_switches(port, USB_SWITCH_DISCONNECT);
+ type = pi3usb9281_get_device_type(port);
+ usb_charger_set_switches(port, USB_SWITCH_RESTORE);
+
+ /* Exclude the BC1.2 charger, which is not detected as CDP or SDP. */
+ enable = enable && (type & (PI3USB9281_TYPE_CDP | PI3USB9281_TYPE_SDP));
+
+ /* Only mux one port to AP. If already muxed, return. */
+ if (enable && (!gpio_get_level(GPIO_USB_C0_HS_MUX_SEL) ||
+ gpio_get_level(GPIO_USB_C1_HS_MUX_SEL)))
+ return;
+
+ /* Port-0 and port-1 have different polarities. */
+ if (port == 0)
+ gpio_set_level(GPIO_USB_C0_HS_MUX_SEL, enable ? 0 : 1);
+ else if (port == 1)
+ gpio_set_level(GPIO_USB_C1_HS_MUX_SEL, enable ? 1 : 0);
}
int pd_is_valid_input_voltage(int mv)