From 342780429c04a6c6953bbe2b6a78e30306b135df Mon Sep 17 00:00:00 2001 From: Li Jun Date: Sat, 19 Aug 2017 02:32:48 +0800 Subject: [PATCH] MLK-16013-43 staging: 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 --- drivers/staging/typec/tcpci.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c index 6c2cdd294a36..c7c8ecd3abde 100644 --- a/drivers/staging/typec/tcpci.c +++ b/drivers/staging/typec/tcpci.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "pd.h" #include "tcpci.h" @@ -32,6 +33,7 @@ struct tcpci { struct device *dev; struct i2c_client *client; + struct extcon_dev *edev; struct tcpm_port *port; @@ -44,6 +46,11 @@ struct tcpci { unsigned int irq_mask; }; +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); @@ -300,6 +307,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; } @@ -739,6 +751,20 @@ static int tcpci_probe(struct i2c_client *client, tcpci->tcpc.set_roles = tcpci_set_roles; tcpci->tcpc.pd_transmit = tcpci_pd_transmit; + /* Allocate extcon device */ + tcpci->edev = devm_extcon_dev_allocate(&client->dev, + tcpci_extcon_cable); + if (IS_ERR(tcpci->edev)) { + dev_err(&client->dev, "failed to allocate extcon dev.\n"); + return -ENOMEM; + } + + err = devm_extcon_dev_register(&client->dev, tcpci->edev); + if (err) { + dev_err(&client->dev, "failed to register extcon dev.\n"); + return err; + } + err = tcpci_parse_config(tcpci); if (err < 0) return err; -- 2.17.1