From 62f63723f1dfd834a532de0dbc262a68c2c1093a Mon Sep 17 00:00:00 2001 From: Li Jun Date: Wed, 9 Jan 2019 14:27:23 +0530 Subject: [PATCH] MLK-16697 usb: typec: tcpci: add notfication for device attach Some usb device driver can't know the connect and disconnect to host if the vbus is always on, if use typec we can rely on cc line status to know that, so add a notification to let controller driver know device attach and detach from host. Acked-by: Peter Chen Signed-off-by: Li Jun Signed-off-by: Vipul Kumar --- drivers/usb/typec/tcpci.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/tcpci.c b/drivers/usb/typec/tcpci.c index 87eecb3fddb4..a655dd655c58 100644 --- a/drivers/usb/typec/tcpci.c +++ b/drivers/usb/typec/tcpci.c @@ -32,6 +32,7 @@ struct tcpci { struct regmap *regmap; bool controls_vbus; + bool attached; struct gpio_desc *ss_sel_gpio; struct tcpc_dev tcpc; @@ -46,6 +47,7 @@ struct tcpci_chip { static const unsigned int tcpci_extcon_cable[] = { EXTCON_USB_HOST, + EXTCON_USB, EXTCON_NONE, }; @@ -332,10 +334,19 @@ static int tcpci_set_roles(struct tcpc_dev *tcpc, bool attached, if (ret < 0) return ret; - if (data == TYPEC_HOST) + if (data == TYPEC_HOST) { + extcon_set_state_sync(tcpci->edev, EXTCON_USB, false); 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; } -- 2.17.1