[PATCH 2/8] drm/mxsfb/lcdif: don't unnecessarily loop over ports

Luca Ceresoli posted 8 patches 2 weeks ago
There is a newer version of this series
[PATCH 2/8] drm/mxsfb/lcdif: don't unnecessarily loop over ports
Posted by Luca Ceresoli 2 weeks ago
According to the bindings [0] there can be only one port. The in-tree board
device trees also don't contain multiple ports (searched thos matching
'fsl,imx(23|28|6sx|8mp|93)-lcdif').

Avoid an unnecessary loop around multipltle ports. This allows to greatly
simplify the code.

[0] Documentation/devicetree/bindings/display/fsl,lcdif.yaml

Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>

---

Viewing this patch with '--ignore-all-space' is recommended
---
 drivers/gpu/drm/mxsfb/lcdif_drv.c | 77 ++++++++++++++-------------------------
 1 file changed, 27 insertions(+), 50 deletions(-)

diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c b/drivers/gpu/drm/mxsfb/lcdif_drv.c
index 756ca96373c8..83e134c04882 100644
--- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
+++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
@@ -48,61 +48,38 @@ static const struct drm_encoder_funcs lcdif_encoder_funcs = {
 static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
 {
 	struct device *dev = lcdif->drm->dev;
-	struct device_node *ep;
+	struct drm_encoder *encoder;
 	struct drm_bridge *bridge;
 	int ret;
 
-	for_each_endpoint_of_node(dev->of_node, ep) {
-		struct device_node *remote __free(drm_bridge_put) =
-			of_graph_get_remote_port_parent(ep);
-		struct of_endpoint of_ep;
-		struct drm_encoder *encoder;
-
-		if (!of_device_is_available(remote))
-			continue;
-
-		ret = of_graph_parse_endpoint(ep, &of_ep);
-		if (ret < 0) {
-			dev_err(dev, "Failed to parse endpoint %pOF\n", ep);
-			of_node_put(ep);
-			return ret;
-		}
-
-		bridge = devm_drm_of_get_bridge(dev, dev->of_node, 0, of_ep.id);
-		if (IS_ERR(bridge)) {
-			of_node_put(ep);
-			return dev_err_probe(dev, PTR_ERR(bridge),
-					     "Failed to get bridge for endpoint%u\n",
-					     of_ep.id);
-		}
-
-		encoder = devm_kzalloc(dev, sizeof(*encoder), GFP_KERNEL);
-		if (!encoder) {
-			dev_err(dev, "Failed to allocate encoder for endpoint%u\n",
-				of_ep.id);
-			of_node_put(ep);
-			return -ENOMEM;
-		}
-
-		encoder->possible_crtcs = drm_crtc_mask(&lcdif->crtc);
-		ret = drm_encoder_init(lcdif->drm, encoder, &lcdif_encoder_funcs,
-				       DRM_MODE_ENCODER_NONE, NULL);
-		if (ret) {
-			dev_err(dev, "Failed to initialize encoder for endpoint%u: %d\n",
-				of_ep.id, ret);
-			of_node_put(ep);
-			return ret;
-		}
-
-		ret = drm_bridge_attach(encoder, bridge, NULL, 0);
-		if (ret) {
-			of_node_put(ep);
-			return dev_err_probe(dev, ret,
-					     "Failed to attach bridge for endpoint%u\n",
-					     of_ep.id);
-		}
+	struct device_node *remote __free(device_node) =
+		of_graph_get_remote_node(dev->of_node, 0, -1);
+
+	if (!of_device_is_available(remote))
+		return 0;
+
+	bridge = devm_drm_of_get_bridge(dev, dev->of_node, 0, -1);
+	if (IS_ERR(bridge))
+		return dev_err_probe(dev, PTR_ERR(bridge), "Failed to get bridge\n");
+
+	encoder = devm_kzalloc(dev, sizeof(*encoder), GFP_KERNEL);
+	if (!encoder) {
+		dev_err(dev, "Failed to allocate encoder\n");
+		return -ENOMEM;
 	}
 
+	encoder->possible_crtcs = drm_crtc_mask(&lcdif->crtc);
+	ret = drm_encoder_init(lcdif->drm, encoder, &lcdif_encoder_funcs,
+			       DRM_MODE_ENCODER_NONE, NULL);
+	if (ret) {
+		dev_err(dev, "Failed to initialize encoder: %d\n", ret);
+		return ret;
+	}
+
+	ret = drm_bridge_attach(encoder, bridge, NULL, 0);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to attach bridge\n");
+
 	return 0;
 }
 

-- 
2.53.0
Re: [PATCH 2/8] drm/mxsfb/lcdif: don't unnecessarily loop over ports
Posted by Liu Ying 1 week, 2 days ago
Hi Luca,

On Fri, Mar 20, 2026 at 11:46:13AM +0100, Luca Ceresoli wrote:
> According to the bindings [0] there can be only one port. The in-tree board
> device trees also don't contain multiple ports (searched thos matching

s/thos/those/

> 'fsl,imx(23|28|6sx|8mp|93)-lcdif').
> 
> Avoid an unnecessary loop around multipltle ports. This allows to greatly

s/multipltle/multiple/

> simplify the code.
> 
> [0] Documentation/devicetree/bindings/display/fsl,lcdif.yaml
> 
> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
> 
> ---
> 
> Viewing this patch with '--ignore-all-space' is recommended
> ---
>  drivers/gpu/drm/mxsfb/lcdif_drv.c | 77 ++++++++++++++-------------------------
>  1 file changed, 27 insertions(+), 50 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c b/drivers/gpu/drm/mxsfb/lcdif_drv.c
> index 756ca96373c8..83e134c04882 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
> @@ -48,61 +48,38 @@ static const struct drm_encoder_funcs lcdif_encoder_funcs = {
>  static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
>  {
>  	struct device *dev = lcdif->drm->dev;
> -	struct device_node *ep;
> +	struct drm_encoder *encoder;
>  	struct drm_bridge *bridge;
>  	int ret;
>  
> -	for_each_endpoint_of_node(dev->of_node, ep) {

The single i.MX93 LCDIF may connect with a DPI/LVDS/MIPI DSI encoder.
Each encoder maps to an endpoint in a port, hence 3 endpoints in all.
See lcdif node in imx91_93_common.dtsi and imx93.dtsi in linux-next/master.

-- 
Regards,
Liu Ying
Re: [PATCH 2/8] drm/mxsfb/lcdif: don't unnecessarily loop over ports
Posted by Luca Ceresoli 1 week ago
Hello Liu,

thanks for the careful and timely review of this series!

On Thu Mar 26, 2026 at 7:59 AM CET, Liu Ying wrote:
> Hi Luca,
>
> On Fri, Mar 20, 2026 at 11:46:13AM +0100, Luca Ceresoli wrote:
>> According to the bindings [0] there can be only one port. The in-tree board
>> device trees also don't contain multiple ports (searched thos matching
>
> s/thos/those/
>
>> 'fsl,imx(23|28|6sx|8mp|93)-lcdif').
>>
>> Avoid an unnecessary loop around multipltle ports. This allows to greatly
>
> s/multipltle/multiple/
>
>> simplify the code.
>>
>> [0] Documentation/devicetree/bindings/display/fsl,lcdif.yaml
>>
>> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
>>
>> ---
>>
>> Viewing this patch with '--ignore-all-space' is recommended
>> ---
>>  drivers/gpu/drm/mxsfb/lcdif_drv.c | 77 ++++++++++++++-------------------------
>>  1 file changed, 27 insertions(+), 50 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c b/drivers/gpu/drm/mxsfb/lcdif_drv.c
>> index 756ca96373c8..83e134c04882 100644
>> --- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
>> +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
>> @@ -48,61 +48,38 @@ static const struct drm_encoder_funcs lcdif_encoder_funcs = {
>>  static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
>>  {
>>  	struct device *dev = lcdif->drm->dev;
>> -	struct device_node *ep;
>> +	struct drm_encoder *encoder;
>>  	struct drm_bridge *bridge;
>>  	int ret;
>>
>> -	for_each_endpoint_of_node(dev->of_node, ep) {
>
> The single i.MX93 LCDIF may connect with a DPI/LVDS/MIPI DSI encoder.
> Each encoder maps to an endpoint in a port, hence 3 endpoints in all.
> See lcdif node in imx91_93_common.dtsi and imx93.dtsi in linux-next/master.

My bad, I hadn't realized that, perhaps because it was not yet on
drm-misc-next when I did my research. Thanks for noticing.

Luckily the fundamental reason for which I thought I needed this changed
has vanished even before I sent this v1, so I'll just drop this patch and
adapt the follwing ones as needed.

Luca

--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com