From 0b6ce9db6bacece28f89e956016ac0631a3918a1 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Wed, 9 Jan 2019 12:57:41 +0530 Subject: [PATCH] MLK-16013-43 usb: typec: tcpci: add extcon for data role switch Use extcon device for dual role switch on typec port. Acked-by: Peter Chen Signed-off-by: Li Jun Signed-off-by: Vipul Kumar --- drivers/usb/typec/tcpci.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/usb/typec/tcpci.c b/drivers/usb/typec/tcpci.c index b4761b509445..86972c8a77c8 100644 --- a/drivers/usb/typec/tcpci.c +++ b/drivers/usb/typec/tcpci.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include "tcpci.h" @@ -23,6 +25,7 @@ struct tcpci { struct device *dev; + struct extcon_dev *edev; struct tcpm_port *port; @@ -41,6 +44,11 @@ struct tcpci_chip { struct tcpci_data data; }; +static const unsigned int tcpci_extcon_cable[] = { + EXTCON_USB_HOST, + EXTCON_NONE, +}; + static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc) { return container_of(tcpc, struct tcpci, tcpc); @@ -321,6 +329,11 @@ 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_HOST, true); + else + extcon_set_state_sync(tcpci->edev, EXTCON_USB_HOST, false); + return 0; } @@ -692,6 +705,20 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data) tcpci->tcpc.set_roles = tcpci_set_roles; tcpci->tcpc.pd_transmit = tcpci_pd_transmit; + /* Allocate extcon device */ + tcpci->edev = devm_extcon_dev_allocate(dev, + tcpci_extcon_cable); + if (IS_ERR(tcpci->edev)) { + dev_err(dev, "failed to allocate extcon dev.\n"); + return -ENOMEM; + } + + err = devm_extcon_dev_register(dev, tcpci->edev); + if (err) { + dev_err(dev, "failed to register extcon dev.\n"); + return err; + } + err = tcpci_parse_config(tcpci); if (err < 0) return ERR_PTR(err); -- 2.17.1