[PATCH v3 06/12] staging: typec: tcpci: support port config passed via dt

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Li Jun <jun.li@xxxxxxx>
---
 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;
 }
 
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux