Skip to contentSkip to conversation

staging: typec: tcpci: support port config passed via dt

PATCH New Heikki Krogerus 1 participant 1 message Mar 15, 2018 USB

lore
Share & tools
lore
#0 lore raw

PATCH v3 6/12 staging: typec: tcpci: support port config passed via dt

Quoted 78 lines · Li Jun

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

---
 drivers/staging/typec/tcpci.c | 63 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
drivers/staging/typec/tcpci.c +55 -0
index 24ad44f..ba4627f 100644
@@ -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;

drivers/staging/typec/tcpci.c static int tcpci_parse_config(struct tcpci *tcpci) · line 542

Quoted 10 lines
drivers/staging/typec/tcpci.c +8 -0
+
+	/* 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;
 }

I think everything here can be done in tcpm.c.

Since you are checking some device properties in tcpm.c in any case (in tcpm_get_snk_config() and tcpm_get_src_config()), you might as well check all these there as well.

Br,