Skip to contentSkip to conversation

drm: of: Add drm_of_get_data_lanes and drm_of_get_data_lanes_ep

PATCH Superseded Marek Vasut 3 participants 16 messages May 19, 2022 – May 23, 2022

Subsystems (8)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/11 drm: of: Add drm_of_get_data_lanes and drm_of_get_data_lanes_ep

Add helper function to count and sanitize DT "data-lanes" property and return either error or the data-lanes count. This is useful for both DSI and (e)DP "data-lanes" property. The later version of the function is an extra wrapper which handles the endpoint look up by regs, that's what majority of the drivers duplicate too, but not all of them.

Cc Andrzej Hajda <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>

To: [email protected]

---
 drivers/gpu/drm/drm_of.c | 61 ++++++++++++++++++++++++++++++++++++++++
 include/drm/drm_of.h     | 20 +++++++++++++
 2 files changed, 81 insertions(+)
drivers/gpu/drm/drm_of.c +61 -0
index 9a2cfab3a177f..2186f966d2820 100644
@@ -430,3 +430,64 @@ int drm_of_lvds_get_data_mapping(const struct device_node *port)
 	return -EINVAL;
 }
 EXPORT_SYMBOL_GPL(drm_of_lvds_get_data_mapping);
+
+/**
+ * drm_of_get_data_lanes - Get DSI/(e)DP data lane count
+ * @endpoint: DT endpoint node of the DSI/(e)DP source or sink
+ * @min: minimum supported number of data lanes
+ * @max: maximum supported number of data lanes
+ *
+ * Count DT "data-lanes" property elements and check for validity.
+ *
+ * Return:
+ * * min..max - positive integer count of "data-lanes" elements
+ * * -ve - the "data-lanes" property is missing or invalid
+ * * -EINVAL - the "data-lanes" property is unsupported
+ */
+int drm_of_get_data_lanes(const struct device_node *endpoint,
+			  const unsigned int min, const unsigned int max)
+{
+	int ret;
+
+	ret = of_property_count_u32_elems(endpoint, "data-lanes");
+	if (ret < 0)
+		return ret;
+
+	if (ret < min || ret > max)
+		return -EINVAL;
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(drm_of_get_data_lanes);
+
+/**
+ * drm_of_get_data_lanes_ep - Get DSI/(e)DP data lane count by endpoint
+ * @port: DT port node of the DSI/(e)DP source or sink
+ * @port_reg: identifier (value of reg property) of the parent port node
+ * @reg: identifier (value of reg property) of the endpoint node
+ * @min: minimum supported number of data lanes
+ * @max: maximum supported number of data lanes
+ *
+ * Count DT "data-lanes" property elements and check for validity.
+ * This variant uses endpoint specifier.
+ *
+ * Return:
+ * * min..max - positive integer count of "data-lanes" elements
+ * * -EINVAL - the "data-mapping" property is unsupported
+ * * -ENODEV - the "data-mapping" property is missing
+ */
+int drm_of_get_data_lanes_ep(const struct device_node *port,
+			     int port_reg, int reg,
+			     const unsigned int min,
+			     const unsigned int max)
+{
+	struct device_node *endpoint;
+	int ret;
+
+	endpoint = of_graph_get_endpoint_by_regs(port, port_reg, reg);
+	ret = drm_of_get_data_lanes(endpoint, min, max);
+	of_node_put(endpoint);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(drm_of_get_data_lanes_ep);
include/drm/drm_of.h +20 -0
index 99f79ac8b4cd7..b559c53756196 100644
@@ -50,6 +50,12 @@ int drm_of_find_panel_or_bridge(const struct device_node *np,
 int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
 					  const struct device_node *port2);
 int drm_of_lvds_get_data_mapping(const struct device_node *port);
+int drm_of_get_data_lanes(const struct device_node *endpoint,
+			  const unsigned int min, const unsigned int max);
+int drm_of_get_data_lanes_ep(const struct device_node *port,
+			     int port_reg, int reg,
+			     const unsigned int min,
+			     const unsigned int max);
 #else
 static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
 					  struct device_node *port)
@@ -105,6 +111,20 @@ drm_of_lvds_get_data_mapping(const struct device_node *port)
 {
 	return -EINVAL;
 }
+
+int drm_of_get_data_lanes(const struct device_node *endpoint,
+			  const unsigned int min, const unsigned int max)
+{
+	return -EINVAL;
+}
+
+int drm_of_get_data_lanes_ep(const struct device_node *port,
+			     int port_reg, int reg
+			     const unsigned int min,
+			     const unsigned int max)
+{
+	return -EINVAL;
+}
 #endif
 
 /*
Signature · 1 line
2.35.1
#1 lore raw

PATCH 2/11 drm/bridge: anx7625: Convert to drm_of_get_data_lanes

Convert driver to use this new helper to standardize OF "data-lanes" parsing.

Cc Andrzej Hajda <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Xin Ji <[email protected]>

To: [email protected]

---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/bridge/analogix/anx7625.c +4 -4
index e92eb4a407452..87d7658b92fac 100644
@@ -1637,16 +1637,16 @@ static int anx7625_parse_dt(struct device *dev,
 		if (of_property_read_u32(ep0, "bus-type", &bus_type))
 			bus_type = 0;
 
-		mipi_lanes = of_property_count_u32_elems(ep0, "data-lanes");
+		mipi_lanes = drm_of_get_data_lanes(ep0, 1, MAX_LANES_SUPPORT);
 		of_node_put(ep0);
 	}
 
 	if (bus_type == V4L2_FWNODE_BUS_TYPE_PARALLEL) /* bus type is Parallel(DSI) */
 		pdata->is_dpi = 0;
 
-	pdata->mipi_lanes = mipi_lanes;
-	if (pdata->mipi_lanes > MAX_LANES_SUPPORT || pdata->mipi_lanes <= 0)
-		pdata->mipi_lanes = MAX_LANES_SUPPORT;
+	pdata->mipi_lanes = MAX_LANES_SUPPORT;
+	if (mipi_lanes > 0)
+		pdata->mipi_lanes = mipi_lanes;
 
 	if (pdata->is_dpi)
 		DRM_DEV_DEBUG_DRIVER(dev, "found MIPI DPI host node.\n");
Signature · 1 line
2.35.1
#3 lore raw

PATCH 3/11 drm/bridge: icn6211: Convert to drm_of_get_data_lanes_ep

In reply to Marek Vasut

Convert driver to use this new helper to standardize OF "data-lanes" parsing.

Cc Andrzej Hajda <[email protected]>
Cc Jagan Teki <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>

To: [email protected]

---
 drivers/gpu/drm/bridge/chipone-icn6211.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/gpu/drm/bridge/chipone-icn6211.c +4 -7
index 45bb89ac3fff7..e53a19f721c8c 100644
@@ -496,21 +496,18 @@ static int chipone_dsi_attach(struct chipone *icn)
 {
 	struct mipi_dsi_device *dsi = icn->dsi;
 	struct device *dev = icn->dev;
-	struct device_node *endpoint;
 	int dsi_lanes, ret;
 
-	endpoint = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0);
-	dsi_lanes = of_property_count_u32_elems(endpoint, "data-lanes");
-	of_node_put(endpoint);
+	dsi_lanes = drm_of_get_data_lanes_ep(dev->of_node, 0, 0, 1, 4);
 
 	/*
 	 * If the 'data-lanes' property does not exist in DT or is invalid,
 	 * default to previously hard-coded behavior, which was 4 data lanes.
 	 */
-	if (dsi_lanes >= 1 && dsi_lanes <= 4)
-		icn->dsi->lanes = dsi_lanes;
-	else
+	if (dsi_lanes < 0)
 		icn->dsi->lanes = 4;
+	else
+		icn->dsi->lanes = dsi_lanes;
 
 	dsi->format = MIPI_DSI_FMT_RGB888;
 	dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |
Signature · 1 line
2.35.1
#7 lore raw

PATCH 6/11 drm/bridge: tc358767: Convert to drm_of_get_data_lanes

In reply to Marek Vasut

Convert driver to use this new helper to standardize OF "data-lanes" parsing.

Cc Andrzej Hajda <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>

To: [email protected]

---
 drivers/gpu/drm/bridge/tc358767.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/bridge/tc358767.c +4 -4
index 8e210b1176906..a6990a8c08a8b 100644
@@ -1892,18 +1892,18 @@ static int tc_mipi_dsi_host_attach(struct tc_data *tc)
 	int dsi_lanes, ret;
 
 	endpoint = of_graph_get_endpoint_by_regs(dev->of_node, 0, -1);
-	dsi_lanes = of_property_count_u32_elems(endpoint, "data-lanes");
+	dsi_lanes = drm_of_get_data_lanes(endpoint, 1, 4);
 	host_node = of_graph_get_remote_port_parent(endpoint);
 	host = of_find_mipi_dsi_host_by_node(host_node);
 	of_node_put(host_node);
 	of_node_put(endpoint);
 
-	if (dsi_lanes <= 0 || dsi_lanes > 4)
-		return -EINVAL;
-
 	if (!host)
 		return -EPROBE_DEFER;
 
+	if (dsi_lanes < 0)
+		return dsi_lanes;
+
 	dsi = mipi_dsi_device_register_full(host, &info);
 	if (IS_ERR(dsi))
 		return dev_err_probe(dev, PTR_ERR(dsi),
Signature · 1 line
2.35.1
#11 lore raw

PATCH 10/11 drm/bridge: msm: Convert to drm_of_get_data_lanes

In reply to Marek Vasut

Convert driver to use this new helper to standardize OF "data-lanes" parsing.

Cc Abhinav Kumar <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Dmitry Baryshkov <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Rob Clark <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Sean Paul <[email protected]>

To: [email protected]

---
 drivers/gpu/drm/msm/dp/dp_parser.c | 6 ++----
 drivers/gpu/drm/msm/dsi/dsi_host.c | 7 +++----
 2 files changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/dp/dp_parser.c +2 -4
index 8f9fed9fdafc4..6ef919cda0f5c 100644
@@ -102,11 +102,9 @@ static int dp_parser_ctrl_res(struct dp_parser *parser)
 static int dp_parser_misc(struct dp_parser *parser)
 {
 	struct device_node *of_node = parser->pdev->dev.of_node;
-	int len = 0;
-	const char *data_lane_property = "data-lanes";
+	int len;
 
-	len = of_property_count_elems_of_size(of_node,
-			 data_lane_property, sizeof(u32));
+	len = drm_of_get_data_lanes(of_node, 1, DP_MAX_NUM_DP_LANES);
 	if (len < 0) {
 		DRM_WARN("Invalid property %s, default max DP lanes = %d\n",
 				data_lane_property, DP_MAX_NUM_DP_LANES);
drivers/gpu/drm/msm/dsi/dsi_host.c +3 -4
index a95d5df52653c..a0c7d23cd4939 100644
@@ -1779,11 +1779,10 @@ static int dsi_host_parse_lane_data(struct msm_dsi_host *msm_host,
 		return 0;
 	}
 
-	num_lanes = len / sizeof(u32);
-
-	if (num_lanes < 1 || num_lanes > 4) {
+	num_lanes = drm_of_get_data_lanes(ep, 1, 4);
+	if (num_lanes < 0) {
 		DRM_DEV_ERROR(dev, "bad number of data lanes\n");
-		return -EINVAL;
+		return num_lanes;
 	}
 
 	msm_host->num_data_lanes = num_lanes;
Signature · 1 line
2.35.1
#8 lore raw

PATCH 7/11 drm/bridge: tc358775: Convert to drm_of_get_data_lanes_ep

In reply to Marek Vasut

Convert driver to use this new helper to standardize OF "data-lanes" parsing.

Cc Andrzej Hajda <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>

To: [email protected]

---
 drivers/gpu/drm/bridge/tc358775.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)
drivers/gpu/drm/bridge/tc358775.c +5 -15
index 62a7ef352daa5..7abb8ae3df2ff 100644
@@ -530,7 +530,7 @@ static int tc358775_parse_dt(struct device_node *np, struct tc_data *tc)
 	struct device_node *parent;
 	struct device_node *remote;
 	struct property *prop;
-	int len = 0;
+	int dsi_lanes, len = 0;
 
 	/*
 	 * To get the data-lanes of dsi, we need to access the dsi0_out of port1
@@ -544,25 +544,15 @@ static int tc358775_parse_dt(struct device_node *np, struct tc_data *tc)
 		of_node_put(endpoint);
 		if (parent) {
 			/* dsi0 port 1 */
-			endpoint = of_graph_get_endpoint_by_regs(parent, 1, -1);
+			dsi_lanes = drm_of_get_data_lanes_ep(parent, 1, -1, 1, 4);
 			of_node_put(parent);
-			if (endpoint) {
-				prop = of_find_property(endpoint, "data-lanes",
-							&len);
-				of_node_put(endpoint);
-				if (!prop) {
-					dev_err(tc->dev,
-						"failed to find data lane\n");
-					return -EPROBE_DEFER;
-				}
-			}
 		}
 	}
 
-	tc->num_dsi_lanes = len / sizeof(u32);
+	if (dsi_lanes < 0)
+		return dsi_lanes;
 
-	if (tc->num_dsi_lanes < 1 || tc->num_dsi_lanes > 4)
-		return -EINVAL;
+	tc->num_dsi_lanes = dsi_lanes;
 
 	tc->host_node = of_graph_get_remote_node(np, 0, 0);
 	if (!tc->host_node)
Signature · 1 line
2.35.1
#10 lore raw

PATCH 9/11 drm/bridge: ti-sn65dsi86: Convert to drm_of_get_data_lanes

In reply to Marek Vasut

Convert driver to use this new helper to standardize OF "data-lanes" parsing.

Cc Andrzej Hajda <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>

To: [email protected]

---
 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/bridge/ti-sn65dsi86.c +2 -2
index 8cad662de9bb5..44a330a48d385 100644
@@ -1142,8 +1142,8 @@ static void ti_sn_bridge_parse_lanes(struct ti_sn65dsi86 *pdata,
 	 * mappings that the hardware supports.
 	 */
 	endpoint = of_graph_get_endpoint_by_regs(np, 1, -1);
-	dp_lanes = of_property_count_u32_elems(endpoint, "data-lanes");
-	if (dp_lanes > 0 && dp_lanes <= SN_MAX_DP_LANES) {
+	dp_lanes = drm_of_get_data_lanes(endpoint, 1, SN_MAX_DP_LANES);
+	if (dp_lanes > 0) {
 		of_property_read_u32_array(endpoint, "data-lanes",
 					   lane_assignments, dp_lanes);
 		of_property_read_u32_array(endpoint, "lane-polarities",
Signature · 1 line
2.35.1
#5 lore raw

PATCH 4/11 drm/bridge: lt8912: Convert to drm_of_get_data_lanes_ep

In reply to Marek Vasut

Convert driver to use this new helper to standardize OF "data-lanes" parsing.

Cc Adrien Grassein <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>

To: [email protected]

---
 drivers/gpu/drm/bridge/lontium-lt8912b.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/gpu/drm/bridge/lontium-lt8912b.c +2 -7
index c642d1e02b2f8..b9741de70d584 100644
@@ -607,7 +607,6 @@ static int lt8912_parse_dt(struct lt8912 *lt)
 	int ret;
 	int data_lanes;
 	struct device_node *port_node;
-	struct device_node *endpoint;
 
 	gp_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
 	if (IS_ERR(gp_reset)) {
@@ -618,16 +617,12 @@ static int lt8912_parse_dt(struct lt8912 *lt)
 	}
 	lt->gp_reset = gp_reset;
 
-	endpoint = of_graph_get_endpoint_by_regs(dev->of_node, 0, -1);
-	if (!endpoint)
-		return -ENODEV;
-
-	data_lanes = of_property_count_u32_elems(endpoint, "data-lanes");
-	of_node_put(endpoint);
+	data_lanes = drm_of_get_data_lanes_ep(dev->of_node, 0, -1, 1, 4);
 	if (data_lanes < 0) {
 		dev_err(lt->dev, "%s: Bad data-lanes property\n", __func__);
 		return data_lanes;
 	}
+
 	lt->data_lanes = data_lanes;
 
 	lt->host_node = of_graph_get_remote_node(dev->of_node, 0, -1);
Signature · 1 line
2.35.1
#9 lore raw

PATCH 8/11 drm/bridge: ti-sn65dsi83: Convert to drm_of_get_data_lanes

In reply to Marek Vasut

Convert driver to use this new helper to standardize OF "data-lanes" parsing.

Cc Andrzej Hajda <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>

To: [email protected]

---
 drivers/gpu/drm/bridge/ti-sn65dsi83.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/ti-sn65dsi83.c +1 -1
index f5c1819857665..e3d87e5905c00 100644
@@ -628,7 +628,7 @@ static int sn65dsi83_host_attach(struct sn65dsi83 *ctx)
 	int dsi_lanes, ret;
 
 	endpoint = of_graph_get_endpoint_by_regs(dev->of_node, 0, -1);
-	dsi_lanes = of_property_count_u32_elems(endpoint, "data-lanes");
+	dsi_lanes = drm_of_get_data_lanes(endpoint, 1, 4);
 	host_node = of_graph_get_remote_port_parent(endpoint);
 	host = of_find_mipi_dsi_host_by_node(host_node);
 	of_node_put(host_node);
Signature · 1 line
2.35.1
#14 lore raw

PATCH 11/11 drm/bridge: rcar: Convert to drm_of_get_data_lanes_ep

In reply to Marek Vasut

Convert driver to use this new helper to standardize OF "data-lanes" parsing.

Cc Andrzej Hajda <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>

To: [email protected]

---
 drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c +2 -11
index 891bb956fd61b..915c74c0a37fd 100644
@@ -683,19 +683,10 @@ static int rcar_mipi_dsi_parse_dt(struct rcar_mipi_dsi *dsi)
 	u32 data_lanes[4];
 	int ret;
 
-	ep = of_graph_get_endpoint_by_regs(dsi->dev->of_node, 1, 0);
-	if (!ep) {
-		dev_dbg(dsi->dev, "unconnected port@1\n");
-		return -ENODEV;
-	}
-
-	ret = of_property_read_variable_u32_array(ep, "data-lanes", data_lanes,
-						  1, 4);
-	of_node_put(ep);
-
+	ret = drm_of_get_data_lanes_ep(dsi->dev->of_node, 1, 0, 1, 4);
 	if (ret < 0) {
 		dev_err(dsi->dev, "missing or invalid data-lanes property\n");
-		return -ENODEV;
+		return ret;
 	}
 
 	dsi->num_data_lanes = ret;
Signature · 1 line
2.35.1
#6 lore raw

PATCH 5/11 drm/bridge: lt9211: Convert to drm_of_get_data_lanes

In reply to Marek Vasut

Convert driver to use this new helper to standardize OF "data-lanes" parsing.

Cc Andrzej Hajda <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>

To: [email protected]

---
 drivers/gpu/drm/bridge/lontium-lt9211.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/bridge/lontium-lt9211.c +3 -3
index e92821fbc6393..3e158689f6696 100644
@@ -686,7 +686,7 @@ static int lt9211_host_attach(struct lt9211 *ctx)
 	int ret;
 
 	endpoint = of_graph_get_endpoint_by_regs(dev->of_node, 0, -1);
-	dsi_lanes = of_property_count_u32_elems(endpoint, "data-lanes");
+	dsi_lanes = drm_of_get_data_lanes(endpoint, 1, 4);
 	host_node = of_graph_get_remote_port_parent(endpoint);
 	host = of_find_mipi_dsi_host_by_node(host_node);
 	of_node_put(host_node);
@@ -695,8 +695,8 @@ static int lt9211_host_attach(struct lt9211 *ctx)
 	if (!host)
 		return -EPROBE_DEFER;
 
-	if (dsi_lanes < 0 || dsi_lanes > 4)
-		return -EINVAL;
+	if (dsi_lanes < 0)
+		return dsi_lanes;
 
 	dsi = devm_mipi_dsi_device_register_full(dev, host, &info);
 	if (IS_ERR(dsi))
Signature · 1 line
2.35.1
Reviewed-by on v1 10/11
#12 lore raw

Re: [PATCH 10/11] drm/bridge: msm: Convert to drm_of_get_data_lanes

In reply to Marek Vasut
Quoted 2 lines · Marek Vasut

Convert driver to use this new helper to standardize OF "data-lanes" parsing.

Minor nit, if you resend this series for any reason: could you please follow the usual subject prefix for the msm driver: 'drm/msm: ....'

Quoted 55 lines
Cc Abhinav Kumar <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Dmitry Baryshkov <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Rob Clark <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Sean Paul <[email protected]>

To: [email protected]

---
  drivers/gpu/drm/msm/dp/dp_parser.c | 6 ++----
  drivers/gpu/drm/msm/dsi/dsi_host.c | 7 +++----
  2 files changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/dp/dp_parser.c +2 -4
index 8f9fed9fdafc4..6ef919cda0f5c 100644
@@ -102,11 +102,9 @@ static int dp_parser_ctrl_res(struct dp_parser *parser)
  static int dp_parser_misc(struct dp_parser *parser)
  {
  	struct device_node *of_node = parser->pdev->dev.of_node;
-	int len = 0;
-	const char *data_lane_property = "data-lanes";
+	int len;
 
-	len = of_property_count_elems_of_size(of_node,
-			 data_lane_property, sizeof(u32));
+	len = drm_of_get_data_lanes(of_node, 1, DP_MAX_NUM_DP_LANES);
  	if (len < 0) {
  		DRM_WARN("Invalid property %s, default max DP lanes = %d\n",
  				data_lane_property, DP_MAX_NUM_DP_LANES);
drivers/gpu/drm/msm/dsi/dsi_host.c +3 -4
index a95d5df52653c..a0c7d23cd4939 100644
@@ -1779,11 +1779,10 @@ static int dsi_host_parse_lane_data(struct msm_dsi_host *msm_host,
  		return 0;
  	}
 
-	num_lanes = len / sizeof(u32);
-
-	if (num_lanes < 1 || num_lanes > 4) {
+	num_lanes = drm_of_get_data_lanes(ep, 1, 4);
+	if (num_lanes < 0) {
  		DRM_DEV_ERROR(dev, "bad number of data lanes\n");
-		return -EINVAL;
+		return num_lanes;
  	}
 
  	msm_host->num_data_lanes = num_lanes;
Signature · 2 lines
With best wishes
Dmitry
#13 lore raw

Re: [PATCH 10/11] drm/bridge: msm: Convert to drm_of_get_data_lanes

Quoted 5 lines · Dmitry Baryshkov
Quoted 2 lines · Marek Vasut

Convert driver to use this new helper to standardize OF "data-lanes" parsing.

Can you please also test it, that it does not break anything ?

Quoted 1 line

Minor nit, if you resend this series for any reason: could you please follow the usual subject prefix for the msm driver: 'drm/msm: ....'

Will do

maintainer Reviewed-by on v1 1/11
#15 lore raw
In reply to Marek Vasut
Quoted 34 lines · Marek Vasut

Add helper function to count and sanitize DT "data-lanes" property and return either error or the data-lanes count. This is useful for both DSI and (e)DP "data-lanes" property. The later version of the function is an extra wrapper which handles the endpoint look up by regs, that's what majority of the drivers duplicate too, but not all of them.

Cc Andrzej Hajda <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>

To: [email protected]

---
  drivers/gpu/drm/drm_of.c | 61 ++++++++++++++++++++++++++++++++++++++++
  include/drm/drm_of.h     | 20 +++++++++++++
  2 files changed, 81 insertions(+)
drivers/gpu/drm/drm_of.c +6 -0
index 9a2cfab3a177f..2186f966d2820 100644
@@ -430,3 +430,64 @@ int drm_of_lvds_get_data_mapping(const struct device_node *port)
  	return -EINVAL;
  }
  EXPORT_SYMBOL_GPL(drm_of_lvds_get_data_mapping);
+
+/**
+ * drm_of_get_data_lanes - Get DSI/(e)DP data lane count
+ * @endpoint: DT endpoint node of the DSI/(e)DP source or sink
+ * @min: minimum supported number of data lanes
+ * @max: maximum supported number of data lanes

drivers/gpu/drm/drm_of.c int drm_of_lvds_get_data_mapping(const struct device_node *port) · line 448

Quoted 10 lines
drivers/gpu/drm/drm_of.c +10 -0
+ *
+ * Count DT "data-lanes" property elements and check for validity.
+ *
+ * Return:
+ * * min..max - positive integer count of "data-lanes" elements
+ * * -ve - the "data-lanes" property is missing or invalid
+ * * -EINVAL - the "data-lanes" property is unsupported
+ */
+int drm_of_get_data_lanes(const struct device_node *endpoint,
+			  const unsigned int min, const unsigned int max)

Adding count to the name would be more accurate,  for example drm_of_get_data_lanes_count ? Up to you.

Regards
Andrzej

Quoted 83 lines
drivers/gpu/drm/drm_of.c +45 -0
+{
+	int ret;
+
+	ret = of_property_count_u32_elems(endpoint, "data-lanes");
+	if (ret < 0)
+		return ret;
+
+	if (ret < min || ret > max)
+		return -EINVAL;
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(drm_of_get_data_lanes);
+
+/**
+ * drm_of_get_data_lanes_ep - Get DSI/(e)DP data lane count by endpoint
+ * @port: DT port node of the DSI/(e)DP source or sink
+ * @port_reg: identifier (value of reg property) of the parent port node
+ * @reg: identifier (value of reg property) of the endpoint node
+ * @min: minimum supported number of data lanes
+ * @max: maximum supported number of data lanes
+ *
+ * Count DT "data-lanes" property elements and check for validity.
+ * This variant uses endpoint specifier.
+ *
+ * Return:
+ * * min..max - positive integer count of "data-lanes" elements
+ * * -EINVAL - the "data-mapping" property is unsupported
+ * * -ENODEV - the "data-mapping" property is missing
+ */
+int drm_of_get_data_lanes_ep(const struct device_node *port,
+			     int port_reg, int reg,
+			     const unsigned int min,
+			     const unsigned int max)
+{
+	struct device_node *endpoint;
+	int ret;
+
+	endpoint = of_graph_get_endpoint_by_regs(port, port_reg, reg);
+	ret = drm_of_get_data_lanes(endpoint, min, max);
+	of_node_put(endpoint);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(drm_of_get_data_lanes_ep);
include/drm/drm_of.h +20 -0
index 99f79ac8b4cd7..b559c53756196 100644
@@ -50,6 +50,12 @@ int drm_of_find_panel_or_bridge(const struct device_node *np,
  int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
  					  const struct device_node *port2);
  int drm_of_lvds_get_data_mapping(const struct device_node *port);
+int drm_of_get_data_lanes(const struct device_node *endpoint,
+			  const unsigned int min, const unsigned int max);
+int drm_of_get_data_lanes_ep(const struct device_node *port,
+			     int port_reg, int reg,
+			     const unsigned int min,
+			     const unsigned int max);
  #else
  static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
  					  struct device_node *port)
@@ -105,6 +111,20 @@ drm_of_lvds_get_data_mapping(const struct device_node *port)
  {
  	return -EINVAL;
  }
+
+int drm_of_get_data_lanes(const struct device_node *endpoint,
+			  const unsigned int min, const unsigned int max)
+{
+	return -EINVAL;
+}
+
+int drm_of_get_data_lanes_ep(const struct device_node *port,
+			     int port_reg, int reg
+			     const unsigned int min,
+			     const unsigned int max)
+{
+	return -EINVAL;
+}
  #endif
 
  /*
maintainer Reviewed-by on v1 2/11
#2 lore raw

Re: [PATCH 02/11] drm/bridge: anx7625: Convert to drm_of_get_data_lanes

In reply to Marek Vasut
Quoted 28 lines · Marek Vasut

Convert driver to use this new helper to standardize OF "data-lanes" parsing.

Cc Andrzej Hajda <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Xin Ji <[email protected]>

To: [email protected]

---
  drivers/gpu/drm/bridge/analogix/anx7625.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/bridge/analogix/anx7625.c +1 -1
index e92eb4a407452..87d7658b92fac 100644
@@ -1637,16 +1637,16 @@ static int anx7625_parse_dt(struct device *dev,
  		if (of_property_read_u32(ep0, "bus-type", &bus_type))
  			bus_type = 0;
 
-		mipi_lanes = of_property_count_u32_elems(ep0, "data-lanes");
+		mipi_lanes = drm_of_get_data_lanes(ep0, 1, MAX_LANES_SUPPORT);
  		of_node_put(ep0);
  	}

drivers/gpu/drm/bridge/analogix/anx7625.c static int anx7625_parse_dt(struct device *dev, · line 1649

Quoted 10 lines
drivers/gpu/drm/bridge/analogix/anx7625.c +3 -3
 
  	if (bus_type == V4L2_FWNODE_BUS_TYPE_PARALLEL) /* bus type is Parallel(DSI) */
  		pdata->is_dpi = 0;
 
-	pdata->mipi_lanes = mipi_lanes;
-	if (pdata->mipi_lanes > MAX_LANES_SUPPORT || pdata->mipi_lanes <= 0)
-		pdata->mipi_lanes = MAX_LANES_SUPPORT;
+	pdata->mipi_lanes = MAX_LANES_SUPPORT;
+	if (mipi_lanes > 0)
+		pdata->mipi_lanes = mipi_lanes;

Regards
Andrzej

Quoted 3 lines
drivers/gpu/drm/bridge/analogix/anx7625.c +0 -0
  	if (pdata->is_dpi)
  		DRM_DEV_DEBUG_DRIVER(dev, "found MIPI DPI host node.\n");
maintainer Reviewed-by on v1 3/11
#4 lore raw

Re: [PATCH 03/11] drm/bridge: icn6211: Convert to drm_of_get_data_lanes_ep

In reply to Marek Vasut
Quoted 11 lines · Marek Vasut

Convert driver to use this new helper to standardize OF "data-lanes" parsing.

Cc Andrzej Hajda <[email protected]>
Cc Jagan Teki <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>
Quoted 4 lines

To: [email protected]

---
  drivers/gpu/drm/bridge/chipone-icn6211.c | 11 ++++-------
  1 file changed, 4 insertions(+), 7 deletions(-)

For this and the rest:

Regards
Andrzej

Quoted 31 lines
drivers/gpu/drm/bridge/chipone-icn6211.c +4 -7
index 45bb89ac3fff7..e53a19f721c8c 100644
@@ -496,21 +496,18 @@ static int chipone_dsi_attach(struct chipone *icn)
  {
  	struct mipi_dsi_device *dsi = icn->dsi;
  	struct device *dev = icn->dev;
-	struct device_node *endpoint;
  	int dsi_lanes, ret;
 
-	endpoint = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0);
-	dsi_lanes = of_property_count_u32_elems(endpoint, "data-lanes");
-	of_node_put(endpoint);
+	dsi_lanes = drm_of_get_data_lanes_ep(dev->of_node, 0, 0, 1, 4);
 
  	/*
  	 * If the 'data-lanes' property does not exist in DT or is invalid,
  	 * default to previously hard-coded behavior, which was 4 data lanes.
  	 */
-	if (dsi_lanes >= 1 && dsi_lanes <= 4)
-		icn->dsi->lanes = dsi_lanes;
-	else
+	if (dsi_lanes < 0)
  		icn->dsi->lanes = 4;
+	else
+		icn->dsi->lanes = dsi_lanes;
 
  	dsi->format = MIPI_DSI_FMT_RGB888;
  	dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |