All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Stein <alexander.stein@ew.tq-group.com>
To: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Liu Ying <victor.liu@nxp.com>
Cc: marex@denx.de, stefan@agner.ch, airlied@gmail.com,
	daniel@ffwll.ch, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, shawnguo@kernel.org,
	s.hauer@pengutronix.de, kernel@pengutronix.de,
	festevam@gmail.com, linux-imx@nxp.com,
	krzysztof.kozlowski@linaro.org, LW@karo-electronics.de
Subject: Re: [PATCH v3 5/6] drm: lcdif: Add multiple encoders and first bridges support
Date: Wed, 15 Feb 2023 08:54:50 +0100	[thread overview]
Message-ID: <1893357.taCxCBeP46@steina-w> (raw)
In-Reply-To: <20230213085612.1026538-6-victor.liu@nxp.com>

Hi Liu,

thanks for the update.

Am Montag, 13. Februar 2023, 09:56:11 CET schrieb Liu Ying:
> The single LCDIF embedded in i.MX93 SoC may drive multiple displays
> simultaneously.  Look at LCDIF output port's remote port parents to
> find all enabled first bridges.  Add an encoder for each found bridge
> and attach the bridge to the encoder.  This is a preparation for
> adding i.MX93 LCDIF support.
> 
> Signed-off-by: Liu Ying <victor.liu@nxp.com>
> ---
> v2->v3:
> * No change.
> 
> v1->v2:
> * Split from patch 2/2 in v1. (Marek, Alexander)
> * Drop '!remote ||' from lcdif_attach_bridge(). (Lothar)
> * Drop unneeded 'bridges' member from lcdif_drm_private structure.
> 
>  drivers/gpu/drm/mxsfb/lcdif_drv.c | 68 +++++++++++++++++++++++++++----
>  drivers/gpu/drm/mxsfb/lcdif_drv.h |  4 +-
>  drivers/gpu/drm/mxsfb/lcdif_kms.c | 21 ++--------
>  3 files changed, 66 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> b/drivers/gpu/drm/mxsfb/lcdif_drv.c index b5b9a8e273c6..eb6c265fa2fe 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
> @@ -9,13 +9,16 @@
>  #include <linux/dma-mapping.h>
>  #include <linux/io.h>
>  #include <linux/module.h>
> +#include <linux/of.h>
>  #include <linux/of_device.h>
> +#include <linux/of_graph.h>
>  #include <linux/platform_device.h>
>  #include <linux/pm_runtime.h>
> 
>  #include <drm/drm_atomic_helper.h>
>  #include <drm/drm_bridge.h>
>  #include <drm/drm_drv.h>
> +#include <drm/drm_encoder.h>
>  #include <drm/drm_fbdev_generic.h>
>  #include <drm/drm_gem_dma_helper.h>
>  #include <drm/drm_gem_framebuffer_helper.h>
> @@ -38,19 +41,68 @@ static const struct drm_mode_config_helper_funcs
> lcdif_mode_config_helpers = { .atomic_commit_tail =
> drm_atomic_helper_commit_tail_rpm,
>  };
> 
> +static const struct drm_encoder_funcs lcdif_encoder_funcs = {
> +	.destroy = drm_encoder_cleanup,
> +};
> +
>  static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
>  {
> -	struct drm_device *drm = lcdif->drm;
> +	struct device *dev = lcdif->drm->dev;
> +	struct device_node *ep;
>  	struct drm_bridge *bridge;
>  	int ret;
> 
> -	bridge = devm_drm_of_get_bridge(drm->dev, drm->dev->of_node, 0, 0);
> -	if (IS_ERR(bridge))
> -		return PTR_ERR(bridge);
> -
> -	ret = drm_bridge_attach(&lcdif->encoder, bridge, NULL, 0);
> -	if (ret)
> -		return dev_err_probe(drm->dev, ret, "Failed to attach 
bridge\n");
> +	for_each_endpoint_of_node(dev->of_node, ep) {
> +		struct device_node *remote;
> +		struct of_endpoint of_ep;
> +		struct drm_encoder *encoder;
> +
> +		remote = of_graph_get_remote_port_parent(ep);

Is it possible for remote to be NULL?

> +		if (!of_device_is_available(remote)) {
> +			of_node_put(remote);
> +			continue;
> +		}
> +		of_node_put(remote);
> +
> +		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;
> +		}
> +
> +		if (of_ep.id >= MAX_DISPLAYS) {
> +			dev_warn(dev, "invalid endpoint id %u\n", 
of_ep.id);

I would write
dev_warn(dev, "ignoring invalid endpoint id %u\n", of_ep.id);
just because the parsing continues but this one is skipped.

> +			continue;
> +		}
> +
> +		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 = &lcdif->encoders[of_ep.id];
> +		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);
> +		}

Admittedly I'm not used to the drm API, but do we need to some manual cleanup/
revert if some endpoints is e.g. deferred, but previous endpoints already have 
been successfully added? e.g. endpoint 0 is added, but adding endpoint 1 
fails.

Best regards,
Alexander

> +	}
> 
>  	return 0;
>  }
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.h
> b/drivers/gpu/drm/mxsfb/lcdif_drv.h index aa6d099a1897..c7400bd9bbd9 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_drv.h
> +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.h
> @@ -14,6 +14,8 @@
>  #include <drm/drm_encoder.h>
>  #include <drm/drm_plane.h>
> 
> +#define MAX_DISPLAYS	3
> +
>  struct clk;
> 
>  struct lcdif_drm_private {
> @@ -30,7 +32,7 @@ struct lcdif_drm_private {
>  		/* i.MXRT does support overlay planes, add them here. */
>  	} planes;
>  	struct drm_crtc			crtc;
> -	struct drm_encoder		encoder;
> +	struct drm_encoder		encoders[MAX_DISPLAYS];
>  };
> 
>  static inline struct lcdif_drm_private *
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> b/drivers/gpu/drm/mxsfb/lcdif_kms.c index 4ea3d2b2cf61..5f34d01e133e 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> +++ b/drivers/gpu/drm/mxsfb/lcdif_kms.c
> @@ -654,14 +654,6 @@ static const struct drm_crtc_funcs lcdif_crtc_funcs = {
> .disable_vblank = lcdif_crtc_disable_vblank,
>  };
> 
> -/*
> ---------------------------------------------------------------------------
> -- - * Encoder
> - */
> -
> -static const struct drm_encoder_funcs lcdif_encoder_funcs = {
> -	.destroy = drm_encoder_cleanup,
> -};
> -
>  /*
> ---------------------------------------------------------------------------
> -- * Planes
>   */
> @@ -754,7 +746,6 @@ int lcdif_kms_init(struct lcdif_drm_private *lcdif)
>  					BIT(DRM_COLOR_YCBCR_BT2020);
>  	const u32 supported_ranges = BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
>  				     BIT(DRM_COLOR_YCBCR_FULL_RANGE);
> -	struct drm_encoder *encoder = &lcdif->encoder;
>  	struct drm_crtc *crtc = &lcdif->crtc;
>  	int ret;
> 
> @@ -778,13 +769,7 @@ int lcdif_kms_init(struct lcdif_drm_private *lcdif)
>  		return ret;
> 
>  	drm_crtc_helper_add(crtc, &lcdif_crtc_helper_funcs);
> -	ret = drm_crtc_init_with_planes(lcdif->drm, crtc,
> -					&lcdif->planes.primary, 
NULL,
> -					&lcdif_crtc_funcs, NULL);
> -	if (ret)
> -		return ret;
> -
> -	encoder->possible_crtcs = drm_crtc_mask(crtc);
> -	return drm_encoder_init(lcdif->drm, encoder, &lcdif_encoder_funcs,
> -				DRM_MODE_ENCODER_NONE, NULL);
> +	return drm_crtc_init_with_planes(lcdif->drm, crtc,
> +					 &lcdif->planes.primary, 
NULL,
> +					 &lcdif_crtc_funcs, NULL);
>  }


-- 
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Alexander Stein <alexander.stein@ew.tq-group.com>
To: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Liu Ying <victor.liu@nxp.com>
Cc: marex@denx.de, stefan@agner.ch, airlied@gmail.com,
	daniel@ffwll.ch, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, shawnguo@kernel.org,
	s.hauer@pengutronix.de, kernel@pengutronix.de,
	festevam@gmail.com, linux-imx@nxp.com,
	krzysztof.kozlowski@linaro.org, LW@karo-electronics.de
Subject: Re: [PATCH v3 5/6] drm: lcdif: Add multiple encoders and first bridges support
Date: Wed, 15 Feb 2023 08:54:50 +0100	[thread overview]
Message-ID: <1893357.taCxCBeP46@steina-w> (raw)
In-Reply-To: <20230213085612.1026538-6-victor.liu@nxp.com>

Hi Liu,

thanks for the update.

Am Montag, 13. Februar 2023, 09:56:11 CET schrieb Liu Ying:
> The single LCDIF embedded in i.MX93 SoC may drive multiple displays
> simultaneously.  Look at LCDIF output port's remote port parents to
> find all enabled first bridges.  Add an encoder for each found bridge
> and attach the bridge to the encoder.  This is a preparation for
> adding i.MX93 LCDIF support.
> 
> Signed-off-by: Liu Ying <victor.liu@nxp.com>
> ---
> v2->v3:
> * No change.
> 
> v1->v2:
> * Split from patch 2/2 in v1. (Marek, Alexander)
> * Drop '!remote ||' from lcdif_attach_bridge(). (Lothar)
> * Drop unneeded 'bridges' member from lcdif_drm_private structure.
> 
>  drivers/gpu/drm/mxsfb/lcdif_drv.c | 68 +++++++++++++++++++++++++++----
>  drivers/gpu/drm/mxsfb/lcdif_drv.h |  4 +-
>  drivers/gpu/drm/mxsfb/lcdif_kms.c | 21 ++--------
>  3 files changed, 66 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> b/drivers/gpu/drm/mxsfb/lcdif_drv.c index b5b9a8e273c6..eb6c265fa2fe 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
> @@ -9,13 +9,16 @@
>  #include <linux/dma-mapping.h>
>  #include <linux/io.h>
>  #include <linux/module.h>
> +#include <linux/of.h>
>  #include <linux/of_device.h>
> +#include <linux/of_graph.h>
>  #include <linux/platform_device.h>
>  #include <linux/pm_runtime.h>
> 
>  #include <drm/drm_atomic_helper.h>
>  #include <drm/drm_bridge.h>
>  #include <drm/drm_drv.h>
> +#include <drm/drm_encoder.h>
>  #include <drm/drm_fbdev_generic.h>
>  #include <drm/drm_gem_dma_helper.h>
>  #include <drm/drm_gem_framebuffer_helper.h>
> @@ -38,19 +41,68 @@ static const struct drm_mode_config_helper_funcs
> lcdif_mode_config_helpers = { .atomic_commit_tail =
> drm_atomic_helper_commit_tail_rpm,
>  };
> 
> +static const struct drm_encoder_funcs lcdif_encoder_funcs = {
> +	.destroy = drm_encoder_cleanup,
> +};
> +
>  static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
>  {
> -	struct drm_device *drm = lcdif->drm;
> +	struct device *dev = lcdif->drm->dev;
> +	struct device_node *ep;
>  	struct drm_bridge *bridge;
>  	int ret;
> 
> -	bridge = devm_drm_of_get_bridge(drm->dev, drm->dev->of_node, 0, 0);
> -	if (IS_ERR(bridge))
> -		return PTR_ERR(bridge);
> -
> -	ret = drm_bridge_attach(&lcdif->encoder, bridge, NULL, 0);
> -	if (ret)
> -		return dev_err_probe(drm->dev, ret, "Failed to attach 
bridge\n");
> +	for_each_endpoint_of_node(dev->of_node, ep) {
> +		struct device_node *remote;
> +		struct of_endpoint of_ep;
> +		struct drm_encoder *encoder;
> +
> +		remote = of_graph_get_remote_port_parent(ep);

Is it possible for remote to be NULL?

> +		if (!of_device_is_available(remote)) {
> +			of_node_put(remote);
> +			continue;
> +		}
> +		of_node_put(remote);
> +
> +		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;
> +		}
> +
> +		if (of_ep.id >= MAX_DISPLAYS) {
> +			dev_warn(dev, "invalid endpoint id %u\n", 
of_ep.id);

I would write
dev_warn(dev, "ignoring invalid endpoint id %u\n", of_ep.id);
just because the parsing continues but this one is skipped.

> +			continue;
> +		}
> +
> +		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 = &lcdif->encoders[of_ep.id];
> +		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);
> +		}

Admittedly I'm not used to the drm API, but do we need to some manual cleanup/
revert if some endpoints is e.g. deferred, but previous endpoints already have 
been successfully added? e.g. endpoint 0 is added, but adding endpoint 1 
fails.

Best regards,
Alexander

> +	}
> 
>  	return 0;
>  }
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.h
> b/drivers/gpu/drm/mxsfb/lcdif_drv.h index aa6d099a1897..c7400bd9bbd9 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_drv.h
> +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.h
> @@ -14,6 +14,8 @@
>  #include <drm/drm_encoder.h>
>  #include <drm/drm_plane.h>
> 
> +#define MAX_DISPLAYS	3
> +
>  struct clk;
> 
>  struct lcdif_drm_private {
> @@ -30,7 +32,7 @@ struct lcdif_drm_private {
>  		/* i.MXRT does support overlay planes, add them here. */
>  	} planes;
>  	struct drm_crtc			crtc;
> -	struct drm_encoder		encoder;
> +	struct drm_encoder		encoders[MAX_DISPLAYS];
>  };
> 
>  static inline struct lcdif_drm_private *
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> b/drivers/gpu/drm/mxsfb/lcdif_kms.c index 4ea3d2b2cf61..5f34d01e133e 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> +++ b/drivers/gpu/drm/mxsfb/lcdif_kms.c
> @@ -654,14 +654,6 @@ static const struct drm_crtc_funcs lcdif_crtc_funcs = {
> .disable_vblank = lcdif_crtc_disable_vblank,
>  };
> 
> -/*
> ---------------------------------------------------------------------------
> -- - * Encoder
> - */
> -
> -static const struct drm_encoder_funcs lcdif_encoder_funcs = {
> -	.destroy = drm_encoder_cleanup,
> -};
> -
>  /*
> ---------------------------------------------------------------------------
> -- * Planes
>   */
> @@ -754,7 +746,6 @@ int lcdif_kms_init(struct lcdif_drm_private *lcdif)
>  					BIT(DRM_COLOR_YCBCR_BT2020);
>  	const u32 supported_ranges = BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
>  				     BIT(DRM_COLOR_YCBCR_FULL_RANGE);
> -	struct drm_encoder *encoder = &lcdif->encoder;
>  	struct drm_crtc *crtc = &lcdif->crtc;
>  	int ret;
> 
> @@ -778,13 +769,7 @@ int lcdif_kms_init(struct lcdif_drm_private *lcdif)
>  		return ret;
> 
>  	drm_crtc_helper_add(crtc, &lcdif_crtc_helper_funcs);
> -	ret = drm_crtc_init_with_planes(lcdif->drm, crtc,
> -					&lcdif->planes.primary, 
NULL,
> -					&lcdif_crtc_funcs, NULL);
> -	if (ret)
> -		return ret;
> -
> -	encoder->possible_crtcs = drm_crtc_mask(crtc);
> -	return drm_encoder_init(lcdif->drm, encoder, &lcdif_encoder_funcs,
> -				DRM_MODE_ENCODER_NONE, NULL);
> +	return drm_crtc_init_with_planes(lcdif->drm, crtc,
> +					 &lcdif->planes.primary, 
NULL,
> +					 &lcdif_crtc_funcs, NULL);
>  }


-- 
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/



WARNING: multiple messages have this Message-ID (diff)
From: Alexander Stein <alexander.stein@ew.tq-group.com>
To: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Liu Ying <victor.liu@nxp.com>
Cc: marex@denx.de, shawnguo@kernel.org, s.hauer@pengutronix.de,
	krzysztof.kozlowski@linaro.org, robh+dt@kernel.org,
	linux-imx@nxp.com, krzysztof.kozlowski+dt@linaro.org,
	kernel@pengutronix.de, LW@karo-electronics.de
Subject: Re: [PATCH v3 5/6] drm: lcdif: Add multiple encoders and first bridges support
Date: Wed, 15 Feb 2023 08:54:50 +0100	[thread overview]
Message-ID: <1893357.taCxCBeP46@steina-w> (raw)
In-Reply-To: <20230213085612.1026538-6-victor.liu@nxp.com>

Hi Liu,

thanks for the update.

Am Montag, 13. Februar 2023, 09:56:11 CET schrieb Liu Ying:
> The single LCDIF embedded in i.MX93 SoC may drive multiple displays
> simultaneously.  Look at LCDIF output port's remote port parents to
> find all enabled first bridges.  Add an encoder for each found bridge
> and attach the bridge to the encoder.  This is a preparation for
> adding i.MX93 LCDIF support.
> 
> Signed-off-by: Liu Ying <victor.liu@nxp.com>
> ---
> v2->v3:
> * No change.
> 
> v1->v2:
> * Split from patch 2/2 in v1. (Marek, Alexander)
> * Drop '!remote ||' from lcdif_attach_bridge(). (Lothar)
> * Drop unneeded 'bridges' member from lcdif_drm_private structure.
> 
>  drivers/gpu/drm/mxsfb/lcdif_drv.c | 68 +++++++++++++++++++++++++++----
>  drivers/gpu/drm/mxsfb/lcdif_drv.h |  4 +-
>  drivers/gpu/drm/mxsfb/lcdif_kms.c | 21 ++--------
>  3 files changed, 66 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> b/drivers/gpu/drm/mxsfb/lcdif_drv.c index b5b9a8e273c6..eb6c265fa2fe 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
> @@ -9,13 +9,16 @@
>  #include <linux/dma-mapping.h>
>  #include <linux/io.h>
>  #include <linux/module.h>
> +#include <linux/of.h>
>  #include <linux/of_device.h>
> +#include <linux/of_graph.h>
>  #include <linux/platform_device.h>
>  #include <linux/pm_runtime.h>
> 
>  #include <drm/drm_atomic_helper.h>
>  #include <drm/drm_bridge.h>
>  #include <drm/drm_drv.h>
> +#include <drm/drm_encoder.h>
>  #include <drm/drm_fbdev_generic.h>
>  #include <drm/drm_gem_dma_helper.h>
>  #include <drm/drm_gem_framebuffer_helper.h>
> @@ -38,19 +41,68 @@ static const struct drm_mode_config_helper_funcs
> lcdif_mode_config_helpers = { .atomic_commit_tail =
> drm_atomic_helper_commit_tail_rpm,
>  };
> 
> +static const struct drm_encoder_funcs lcdif_encoder_funcs = {
> +	.destroy = drm_encoder_cleanup,
> +};
> +
>  static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
>  {
> -	struct drm_device *drm = lcdif->drm;
> +	struct device *dev = lcdif->drm->dev;
> +	struct device_node *ep;
>  	struct drm_bridge *bridge;
>  	int ret;
> 
> -	bridge = devm_drm_of_get_bridge(drm->dev, drm->dev->of_node, 0, 0);
> -	if (IS_ERR(bridge))
> -		return PTR_ERR(bridge);
> -
> -	ret = drm_bridge_attach(&lcdif->encoder, bridge, NULL, 0);
> -	if (ret)
> -		return dev_err_probe(drm->dev, ret, "Failed to attach 
bridge\n");
> +	for_each_endpoint_of_node(dev->of_node, ep) {
> +		struct device_node *remote;
> +		struct of_endpoint of_ep;
> +		struct drm_encoder *encoder;
> +
> +		remote = of_graph_get_remote_port_parent(ep);

Is it possible for remote to be NULL?

> +		if (!of_device_is_available(remote)) {
> +			of_node_put(remote);
> +			continue;
> +		}
> +		of_node_put(remote);
> +
> +		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;
> +		}
> +
> +		if (of_ep.id >= MAX_DISPLAYS) {
> +			dev_warn(dev, "invalid endpoint id %u\n", 
of_ep.id);

I would write
dev_warn(dev, "ignoring invalid endpoint id %u\n", of_ep.id);
just because the parsing continues but this one is skipped.

> +			continue;
> +		}
> +
> +		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 = &lcdif->encoders[of_ep.id];
> +		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);
> +		}

Admittedly I'm not used to the drm API, but do we need to some manual cleanup/
revert if some endpoints is e.g. deferred, but previous endpoints already have 
been successfully added? e.g. endpoint 0 is added, but adding endpoint 1 
fails.

Best regards,
Alexander

> +	}
> 
>  	return 0;
>  }
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.h
> b/drivers/gpu/drm/mxsfb/lcdif_drv.h index aa6d099a1897..c7400bd9bbd9 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_drv.h
> +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.h
> @@ -14,6 +14,8 @@
>  #include <drm/drm_encoder.h>
>  #include <drm/drm_plane.h>
> 
> +#define MAX_DISPLAYS	3
> +
>  struct clk;
> 
>  struct lcdif_drm_private {
> @@ -30,7 +32,7 @@ struct lcdif_drm_private {
>  		/* i.MXRT does support overlay planes, add them here. */
>  	} planes;
>  	struct drm_crtc			crtc;
> -	struct drm_encoder		encoder;
> +	struct drm_encoder		encoders[MAX_DISPLAYS];
>  };
> 
>  static inline struct lcdif_drm_private *
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> b/drivers/gpu/drm/mxsfb/lcdif_kms.c index 4ea3d2b2cf61..5f34d01e133e 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> +++ b/drivers/gpu/drm/mxsfb/lcdif_kms.c
> @@ -654,14 +654,6 @@ static const struct drm_crtc_funcs lcdif_crtc_funcs = {
> .disable_vblank = lcdif_crtc_disable_vblank,
>  };
> 
> -/*
> ---------------------------------------------------------------------------
> -- - * Encoder
> - */
> -
> -static const struct drm_encoder_funcs lcdif_encoder_funcs = {
> -	.destroy = drm_encoder_cleanup,
> -};
> -
>  /*
> ---------------------------------------------------------------------------
> -- * Planes
>   */
> @@ -754,7 +746,6 @@ int lcdif_kms_init(struct lcdif_drm_private *lcdif)
>  					BIT(DRM_COLOR_YCBCR_BT2020);
>  	const u32 supported_ranges = BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
>  				     BIT(DRM_COLOR_YCBCR_FULL_RANGE);
> -	struct drm_encoder *encoder = &lcdif->encoder;
>  	struct drm_crtc *crtc = &lcdif->crtc;
>  	int ret;
> 
> @@ -778,13 +769,7 @@ int lcdif_kms_init(struct lcdif_drm_private *lcdif)
>  		return ret;
> 
>  	drm_crtc_helper_add(crtc, &lcdif_crtc_helper_funcs);
> -	ret = drm_crtc_init_with_planes(lcdif->drm, crtc,
> -					&lcdif->planes.primary, 
NULL,
> -					&lcdif_crtc_funcs, NULL);
> -	if (ret)
> -		return ret;
> -
> -	encoder->possible_crtcs = drm_crtc_mask(crtc);
> -	return drm_encoder_init(lcdif->drm, encoder, &lcdif_encoder_funcs,
> -				DRM_MODE_ENCODER_NONE, NULL);
> +	return drm_crtc_init_with_planes(lcdif->drm, crtc,
> +					 &lcdif->planes.primary, 
NULL,
> +					 &lcdif_crtc_funcs, NULL);
>  }


-- 
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/



  reply	other threads:[~2023-02-15  7:55 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-13  8:56 [PATCH v3 0/6] drm: lcdif: Add i.MX93 LCDIF support Liu Ying
2023-02-13  8:56 ` Liu Ying
2023-02-13  8:56 ` Liu Ying
2023-02-13  8:56 ` [PATCH v3 1/6] dt-bindings: " Liu Ying
2023-02-13  8:56   ` Liu Ying
2023-02-13  8:56   ` Liu Ying
2023-02-15  7:26   ` Alexander Stein
2023-02-15  7:26     ` Alexander Stein
2023-02-15  7:26     ` Alexander Stein
2023-02-15  7:49     ` Liu Ying
2023-02-15  7:49       ` Liu Ying
2023-02-15  7:49       ` Liu Ying
2023-02-15  8:44       ` Alexander Stein
2023-02-15  8:44         ` Alexander Stein
2023-02-15  8:44         ` Alexander Stein
2023-02-13  8:56 ` [PATCH v3 2/6] drm: lcdif: Drop unnecessary NULL pointer check on lcdif->bridge Liu Ying
2023-02-13  8:56   ` Liu Ying
2023-02-13  8:56   ` Liu Ying
2023-02-14 13:42   ` Alexander Stein
2023-02-14 13:42     ` Alexander Stein
2023-02-14 13:42     ` Alexander Stein
2023-02-13  8:56 ` [PATCH v3 3/6] drm: lcdif: Determine bus format and flags in ->atomic_check() Liu Ying
2023-02-13  8:56   ` Liu Ying
2023-02-13  8:56   ` Liu Ying
2023-02-14 14:12   ` Alexander Stein
2023-02-14 14:12     ` Alexander Stein
2023-02-14 14:12     ` Alexander Stein
2023-02-14 14:16     ` Ville Syrjälä
2023-02-14 14:16       ` Ville Syrjälä
2023-02-14 14:16       ` Ville Syrjälä
2023-02-15  3:44     ` Liu Ying
2023-02-15  3:44       ` Liu Ying
2023-02-15  3:44       ` Liu Ying
2023-02-15  8:27       ` Alexander Stein
2023-02-15  8:27         ` Alexander Stein
2023-02-15  8:27         ` Alexander Stein
2023-02-13  8:56 ` [PATCH v3 4/6] drm: lcdif: Check consistent bus format and flags across first bridges Liu Ying
2023-02-13  8:56   ` Liu Ying
2023-02-13  8:56   ` Liu Ying
2023-02-15  7:55   ` Alexander Stein
2023-02-15  7:55     ` Alexander Stein
2023-02-15  7:55     ` Alexander Stein
2023-02-15  8:40     ` Liu Ying
2023-02-15  8:40       ` Liu Ying
2023-02-15  8:40       ` Liu Ying
2023-02-13  8:56 ` [PATCH v3 5/6] drm: lcdif: Add multiple encoders and first bridges support Liu Ying
2023-02-13  8:56   ` Liu Ying
2023-02-13  8:56   ` Liu Ying
2023-02-15  7:54   ` Alexander Stein [this message]
2023-02-15  7:54     ` Alexander Stein
2023-02-15  7:54     ` Alexander Stein
2023-02-15  8:52     ` Liu Ying
2023-02-15  8:52       ` Liu Ying
2023-02-15  8:52       ` Liu Ying
2023-02-13  8:56 ` [PATCH v3 6/6] drm: lcdif: Add i.MX93 LCDIF compatible string Liu Ying
2023-02-13  8:56   ` Liu Ying
2023-02-13  8:56   ` Liu Ying
2023-02-15  7:55   ` Alexander Stein
2023-02-15  7:55     ` Alexander Stein
2023-02-15  7:55     ` Alexander Stein

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=1893357.taCxCBeP46@steina-w \
    --to=alexander.stein@ew.tq-group.com \
    --cc=LW@karo-electronics.de \
    --cc=airlied@gmail.com \
    --cc=daniel@ffwll.ch \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=festevam@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marex@denx.de \
    --cc=robh+dt@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=stefan@agner.ch \
    --cc=victor.liu@nxp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.