devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: cy_huang <u0084500@gmail.com>
To: linux@roeck-us.net, heikki.krogerus@linux.intel.com,
	matthias.bgg@gmail.com, robh+dt@kernel.org
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
	cy_huang@richtek.com, gene_chen@richtek.com,
	devicetree@vger.kernel.org
Subject: [PATCH 1/2] usb typec: tcpci: mt6360: Add vsafe0v support and external vbus supply control
Date: Fri, 15 Jan 2021 22:13:20 +0800	[thread overview]
Message-ID: <1610720001-15300-1-git-send-email-u0084500@gmail.com> (raw)

From: ChiYuan Huang <cy_huang@richtek.com>

MT6360 not support for TCPC command to control source and sink.
Uses external 5V vbus regulator as the vbus source control.

Also adds the capability to report vsafe0v.

Signed-off-by: ChiYuan Huang <cy_huang@richtek.com>
---
 drivers/usb/typec/tcpm/tcpci_mt6360.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpci_mt6360.c b/drivers/usb/typec/tcpm/tcpci_mt6360.c
index f1bd9e0..0edf4b6 100644
--- a/drivers/usb/typec/tcpm/tcpci_mt6360.c
+++ b/drivers/usb/typec/tcpm/tcpci_mt6360.c
@@ -11,6 +11,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
 #include <linux/usb/tcpm.h>
 
 #include "tcpci.h"
@@ -36,6 +37,7 @@ struct mt6360_tcpc_info {
 	struct tcpci_data tdata;
 	struct tcpci *tcpci;
 	struct device *dev;
+	struct regulator *vbus;
 	int irq;
 };
 
@@ -51,6 +53,27 @@ static inline int mt6360_tcpc_write16(struct regmap *regmap,
 	return regmap_raw_write(regmap, reg, &val, sizeof(u16));
 }
 
+static int mt6360_tcpc_set_vbus(struct tcpci *tcpci, struct tcpci_data *data, bool src, bool snk)
+{
+	struct mt6360_tcpc_info *mti = container_of(data, struct mt6360_tcpc_info, tdata);
+	int ret;
+
+	/* To correctly handle the already enabled vbus and disable its supply first */
+	if (regulator_is_enabled(mti->vbus)) {
+		ret = regulator_disable(mti->vbus);
+		if (ret)
+			return ret;
+	}
+
+	if (src) {
+		ret = regulator_enable(mti->vbus);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int mt6360_tcpc_init(struct tcpci *tcpci, struct tcpci_data *tdata)
 {
 	struct regmap *regmap = tdata->regmap;
@@ -138,7 +161,13 @@ static int mt6360_tcpc_probe(struct platform_device *pdev)
 	if (mti->irq < 0)
 		return mti->irq;
 
+	mti->vbus = devm_regulator_get(&pdev->dev, "vbus");
+	if (IS_ERR(mti->vbus))
+		return PTR_ERR(mti->vbus);
+
 	mti->tdata.init = mt6360_tcpc_init;
+	mti->tdata.set_vbus = mt6360_tcpc_set_vbus;
+	mti->tdata.vbus_vsafe0v = 1;
 	mti->tcpci = tcpci_register_port(&pdev->dev, &mti->tdata);
 	if (IS_ERR(mti->tcpci)) {
 		dev_err(&pdev->dev, "Failed to register tcpci port\n");
-- 
2.7.4


             reply	other threads:[~2021-01-15 14:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-15 14:13 cy_huang [this message]
2021-01-15 14:13 ` [PATCH 2/2] usb typec: tcpci: mt6360: Add vbus supply into dt-binding description cy_huang
2021-01-17 15:45   ` Rob Herring
2021-01-18  8:33     ` ChiYuan Huang
2021-01-19 23:10   ` Rob Herring
2021-01-20  1:50     ` ChiYuan Huang
2021-01-17 17:43 ` [PATCH 1/2] usb typec: tcpci: mt6360: Add vsafe0v support and external vbus supply control Guenter Roeck
2021-01-18  8:28   ` ChiYuan Huang
2021-01-19  7:37     ` Chunfeng Yun
2021-01-19  8:23       ` ChiYuan Huang
2021-03-29 14:12         ` ChiYuan Huang
2021-01-19  7:33   ` Chunfeng Yun
2021-01-19  8:21     ` ChiYuan Huang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1610720001-15300-1-git-send-email-u0084500@gmail.com \
    --to=u0084500@gmail.com \
    --cc=cy_huang@richtek.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gene_chen@richtek.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=matthias.bgg@gmail.com \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).