From 8132778f0677ed58d8fa9e21d88577dbe9691f10 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Wed, 9 Jan 2019 14:32:42 +0530 Subject: [PATCH] MLK-16776 usb: typec: tcpci: use vbus from partner for EXTCON_USB Change to use the vbus from partner to notify EXTCON_USB. This is to work around the case of source only typec port connecting to Host PC via a Rp fixed cable. Acked-by: Peter Chen Signed-off-by: Li Jun Signed-off-by: Vipul Kumar --- drivers/usb/typec/tcpci.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/drivers/usb/typec/tcpci.c b/drivers/usb/typec/tcpci.c index a655dd655c58..65846130bf25 100644 --- a/drivers/usb/typec/tcpci.c +++ b/drivers/usb/typec/tcpci.c @@ -32,7 +32,7 @@ struct tcpci { struct regmap *regmap; bool controls_vbus; - bool attached; + bool drive_vbus; struct gpio_desc *ss_sel_gpio; struct tcpc_dev tcpc; @@ -334,19 +334,10 @@ static int tcpci_set_roles(struct tcpc_dev *tcpc, bool attached, if (ret < 0) return ret; - if (data == TYPEC_HOST) { - extcon_set_state_sync(tcpci->edev, EXTCON_USB, false); + if (data == TYPEC_HOST) extcon_set_state_sync(tcpci->edev, EXTCON_USB_HOST, true); - } else { + else extcon_set_state_sync(tcpci->edev, EXTCON_USB_HOST, false); - /* - * Instead of use 'attached' input, we need - * the real HW connection status to notify - * USB device controller driver the attach - * and dettach event to host. - */ - extcon_set_state_sync(tcpci->edev, EXTCON_USB, tcpci->attached); - } return 0; } @@ -376,7 +367,19 @@ static int tcpci_get_vbus(struct tcpc_dev *tcpc) if (ret < 0) return ret; - return !!(reg & TCPC_POWER_STATUS_VBUS_PRES); + ret = !!(reg & TCPC_POWER_STATUS_VBUS_PRES); + + /* + * If the vbus is not from itself for source, we + * assume the vbus is from the port partner, this + * is to work around the case of connect to legacy + * Host like PC via a fixed Rp pull up cable, so + * we notify the possible EXTCON_USB connection. + */ + if (!tcpci->drive_vbus) + extcon_set_state_sync(tcpci->edev, EXTCON_USB, ret); + + return ret; } static unsigned int tcpci_get_vbus_vol(struct tcpc_dev *tcpc) @@ -407,6 +410,7 @@ static int tcpci_set_vbus(struct tcpc_dev *tcpc, bool source, bool sink) if (ret < 0) return ret; + tcpci->drive_vbus = false; /* Enable force discharge */ tcpci_vbus_force_discharge(tcpc, true); } @@ -423,6 +427,7 @@ static int tcpci_set_vbus(struct tcpc_dev *tcpc, bool source, bool sink) TCPC_CMD_SRC_VBUS_DEFAULT); if (ret < 0) return ret; + tcpci->drive_vbus = true; } if (sink) { -- 2.17.1