mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: cy_huang <u0084500@gmail.com>
To: Guenter Roeck <linux@roeck-us.net>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: cy_huang <cy_huang@richtek.com>,
	gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, gene_chen@richtek.com,
	shufan_lee@richtek.com
Subject: [PATCH] From: cy_huang <cy_huang@richtek.com> Subject: usb: add more vendor defined ops in tcpci
Date: Thu, 15 Aug 2019 12:19:13 +0800	[thread overview]
Message-ID: <1565842753-14245-1-git-send-email-u0084500@gmail.com> (raw)

From: cy_huang <cy_huang@richtek.com>

In real case, not all TCPCs support the tcpc PP control command.
Sometimes, charger/OTG/CurrentLimit functions will need to externally
control via power_supply/regulator/BC1.2(extcon). This patch add the ops
set_vbus/get_current_limit/set_current_limit for vendors.

Signed-off-by: cy_huang <cy_huang@richtek.com>
---
 drivers/usb/typec/tcpm/tcpci.c | 34 ++++++++++++++++++++++++++++++++++
 drivers/usb/typec/tcpm/tcpci.h |  5 +++++
 2 files changed, 39 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
index c1f7073..22dfcd8 100644
--- a/drivers/usb/typec/tcpm/tcpci.c
+++ b/drivers/usb/typec/tcpm/tcpci.c
@@ -279,6 +279,13 @@ static int tcpci_set_vbus(struct tcpc_dev *tcpc, bool source, bool sink)
 	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
 	int ret;
 
+	/* Handle vendor set vbus */
+	if (tcpci->data->set_vbus) {
+		ret = tcpci->data->set_vbus(tcpci, tcpci->data, source, sink);
+		if (ret < 0)
+			return ret;
+	}
+
 	/* Disable both source and sink first before enabling anything */
 
 	if (!source) {
@@ -346,6 +353,30 @@ static int tcpci_pd_transmit(struct tcpc_dev *tcpc,
 	return 0;
 }
 
+static int tcpci_get_current_limit(struct tcpc_dev *tcpc)
+{
+	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+
+	/* Handle vendor get current limit */
+	if (tcpci->data->get_current_limit)
+		return tcpci->data->get_current_limit(tcpci, tcpci->data);
+
+	return 0;
+}
+
+static int tcpci_set_current_limit(struct tcpc_dev *tcpc, u32 max_ma, u32 mv)
+{
+	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+
+	/* Handle vendor set current limit */
+	if (tcpci->data->set_current_limit) {
+		return tcpci->data->set_current_limit(tcpci,
+						      tcpci->data, max_ma, mv);
+	}
+
+	return 0;
+}
+
 static int tcpci_init(struct tcpc_dev *tcpc)
 {
 	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
@@ -521,6 +552,9 @@ 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;
 
+	tcpci->tcpc.get_current_limit = tcpci_get_current_limit;
+	tcpci->tcpc.set_current_limit = tcpci_set_current_limit;
+
 	err = tcpci_parse_config(tcpci);
 	if (err < 0)
 		return ERR_PTR(err);
diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h
index 303ebde..a6754fb 100644
--- a/drivers/usb/typec/tcpm/tcpci.h
+++ b/drivers/usb/typec/tcpm/tcpci.h
@@ -130,6 +130,11 @@ struct tcpci_data {
 			 bool enable);
 	int (*start_drp_toggling)(struct tcpci *tcpci, struct tcpci_data *data,
 				  enum typec_cc_status cc);
+	int (*set_vbus)(struct tcpci *tcpci,
+			struct tcpci_data *data, bool source, bool sink);
+	int (*get_current_limit)(struct tcpci *tcpci, struct tcpci_data *data);
+	int (*set_current_limit)(struct tcpci *tcpci,
+				 struct tcpci_data *data, u32 max_ma, u32 mv);
 };
 
 struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data);
-- 
2.7.4


             reply	other threads:[~2019-08-15  4:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-15  4:19 cy_huang [this message]
2019-08-15  7:08 ` Greg KH
2019-08-15  7:14 ` Greg KH
2019-08-15  8:04   ` 啟原黃

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=1565842753-14245-1-git-send-email-u0084500@gmail.com \
    --to=u0084500@gmail.com \
    --cc=cy_huang@richtek.com \
    --cc=gene_chen@richtek.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=shufan_lee@richtek.com \
    /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

all inboxes | Powered by JetHome®