linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jun Li <jun.li@nxp.com>
To: robh+dt@kernel.org, mark.rutland@arm.com,
	gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com
Cc: a.hajda@samsung.com, jun.li@nxp.com, linux@roeck-us.net,
	yueyao@google.com, shufan_lee@richtek.com, o_leveque@orange.fr,
	linux-usb@vger.kernel.org, linux-imx@nxp.com
Subject: [v3,06/12] staging: typec: tcpci: support port config passed via dt
Date: Tue, 13 Mar 2018 17:34:32 +0800	[thread overview]
Message-ID: <1520933678-10535-7-git-send-email-jun.li@nxp.com> (raw)

User can define the typec port properties in tcpci node to setup
the port config.

Signed-off-by: Li Jun <jun.li@nxp.com>
---
 drivers/staging/typec/tcpci.c | 63 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
index 24ad44f..ba4627f 100644
--- a/drivers/staging/typec/tcpci.c
+++ b/drivers/staging/typec/tcpci.c
@@ -466,6 +466,9 @@ static const struct regmap_config tcpci_regmap_config = {
 
 static int tcpci_parse_config(struct tcpci *tcpci)
 {
+	struct tcpc_config *tcfg;
+	int ret = -EINVAL;
+
 	tcpci->controls_vbus = true; /* XXX */
 
 	tcpci->tcpc.fwnode = device_get_named_child_node(tcpci->dev,
@@ -475,6 +478,66 @@ static int tcpci_parse_config(struct tcpci *tcpci)
 		return -EINVAL;
 	}
 
+	tcpci->tcpc.config = devm_kzalloc(tcpci->dev, sizeof(*tcfg),
+					  GFP_KERNEL);
+	if (!tcpci->tcpc.config)
+		return -ENOMEM;
+
+	tcfg = tcpci->tcpc.config;
+
+	/* USB data support is optional */
+	ret = typec_get_data_type(tcpci->tcpc.fwnode);
+	if (ret < 0)
+		dev_dbg(tcpci->dev, "USB data is not supported.\n");
+	else
+		tcfg->data = ret;
+
+	/* Get port power type */
+	ret = typec_get_power_type(tcpci->tcpc.fwnode);
+	if (ret < 0) {
+		dev_err(tcpci->dev, "failed to get correct port type.\n");
+		return ret;
+	}
+	tcfg->type = ret;
+
+	if (tcfg->type == TYPEC_PORT_SNK)
+		goto sink;
+
+	tcfg->src_pdo = devm_kcalloc(tcpci->dev, PDO_MAX_OBJECTS,
+				     sizeof(*tcfg->src_pdo), GFP_KERNEL);
+	if (!tcfg->src_pdo)
+		return -ENOMEM;
+
+	/* Get source capability */
+	ret = tcpm_get_src_config(tcpci->tcpc.fwnode, tcfg);
+	if (ret < 0) {
+		dev_err(tcpci->dev, "failed to get source pdo %d\n", ret);
+		return -EINVAL;
+	}
+
+	if (tcfg->type == TYPEC_PORT_SRC)
+		return 0;
+
+	/* Get the preferred power role for DRP */
+	ret = typec_get_preferred_role(tcpci->tcpc.fwnode);
+	if (ret < 0) {
+		dev_err(tcpci->dev, "failed to get correct preferred role.\n");
+		return ret;
+	}
+	tcfg->default_role = ret;
+sink:
+	tcfg->snk_pdo = devm_kcalloc(tcpci->dev, PDO_MAX_OBJECTS,
+				     sizeof(*tcfg->snk_pdo), GFP_KERNEL);
+	if (!tcfg->snk_pdo)
+		return -ENOMEM;
+
+	/* Get power sink config */
+	ret = tcpm_get_snk_config(tcpci->tcpc.fwnode, tcfg);
+	if (ret < 0) {
+		dev_err(tcpci->dev, "failed to get sink configs %d\n", ret);
+		return -EINVAL;
+	}
+
 	return 0;
 }
 

             reply	other threads:[~2018-03-13  9:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-13  9:34 Jun Li [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-03-15 11:43 [v3,06/12] staging: typec: tcpci: support port config passed via dt Heikki Krogerus
2018-03-20  2:10 Jun Li

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=1520933678-10535-7-git-send-email-jun.li@nxp.com \
    --to=jun.li@nxp.com \
    --cc=a.hajda@samsung.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-imx@nxp.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mark.rutland@arm.com \
    --cc=o_leveque@orange.fr \
    --cc=robh+dt@kernel.org \
    --cc=shufan_lee@richtek.com \
    --cc=yueyao@google.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;
as well as URLs for NNTP newsgroup(s).