linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/stm: ltdc: check number of endpoints
@ 2020-01-21 10:14 Yannick Fertre
  2020-01-23  9:51 ` Philippe CORNU
  0 siblings, 1 reply; 5+ messages in thread
From: Yannick Fertre @ 2020-01-21 10:14 UTC (permalink / raw)
  To: Yannick Fertre, Philippe Cornu, Benjamin Gaignard, David Airlie,
	Daniel Vetter, Maxime Coquelin, Alexandre Torgue, dri-devel,
	linux-stm32, linux-arm-kernel, linux-kernel

Number of endpoints could exceed the fix value MAX_ENDPOINTS(2).
Instead of increase simply this value, the number of endpoint
could be read from device tree. Load sequence has been a little
rework to take care of several panel or bridge which can be
connected/disconnected or enable/disable.

Signed-off-by: Yannick Fertré <yannick.fertre@st.com>
---
 drivers/gpu/drm/stm/ltdc.c | 104 ++++++++++++++++++++++-----------------------
 1 file changed, 52 insertions(+), 52 deletions(-)

diff --git a/drivers/gpu/drm/stm/ltdc.c b/drivers/gpu/drm/stm/ltdc.c
index c2815e8..dba8e7f 100644
--- a/drivers/gpu/drm/stm/ltdc.c
+++ b/drivers/gpu/drm/stm/ltdc.c
@@ -42,8 +42,6 @@
 
 #define MAX_IRQ 4
 
-#define MAX_ENDPOINTS 2
-
 #define HWVER_10200 0x010200
 #define HWVER_10300 0x010300
 #define HWVER_20101 0x020101
@@ -1190,36 +1188,20 @@ int ltdc_load(struct drm_device *ddev)
 	struct ltdc_device *ldev = ddev->dev_private;
 	struct device *dev = ddev->dev;
 	struct device_node *np = dev->of_node;
-	struct drm_bridge *bridge[MAX_ENDPOINTS] = {NULL};
-	struct drm_panel *panel[MAX_ENDPOINTS] = {NULL};
+	struct drm_bridge *bridge;
+	struct drm_panel *panel;
 	struct drm_crtc *crtc;
 	struct reset_control *rstc;
 	struct resource *res;
-	int irq, ret, i, endpoint_not_ready = -ENODEV;
+	int irq, i, nb_endpoints;
+	int ret = -ENODEV;
 
 	DRM_DEBUG_DRIVER("\n");
 
-	/* Get endpoints if any */
-	for (i = 0; i < MAX_ENDPOINTS; i++) {
-		ret = drm_of_find_panel_or_bridge(np, 0, i, &panel[i],
-						  &bridge[i]);
-
-		/*
-		 * If at least one endpoint is -EPROBE_DEFER, defer probing,
-		 * else if at least one endpoint is ready, continue probing.
-		 */
-		if (ret == -EPROBE_DEFER)
-			return ret;
-		else if (!ret)
-			endpoint_not_ready = 0;
-	}
-
-	if (endpoint_not_ready)
-		return endpoint_not_ready;
-
-	rstc = devm_reset_control_get_exclusive(dev, NULL);
-
-	mutex_init(&ldev->err_lock);
+	/* Get number of endpoints */
+	nb_endpoints = of_graph_get_endpoint_count(np);
+	if (!nb_endpoints)
+		return -ENODEV;
 
 	ldev->pixel_clk = devm_clk_get(dev, "lcd");
 	if (IS_ERR(ldev->pixel_clk)) {
@@ -1233,6 +1215,43 @@ int ltdc_load(struct drm_device *ddev)
 		return -ENODEV;
 	}
 
+	/* Get endpoints if any */
+	for (i = 0; i < nb_endpoints; i++) {
+		ret = drm_of_find_panel_or_bridge(np, 0, i, &panel, &bridge);
+
+		/*
+		 * If at least one endpoint is -ENODEV, continue probing,
+		 * else if at least one endpoint returned an error
+		 * (ie -EPROBE_DEFER) then stop probing.
+		 */
+		if (ret == -ENODEV)
+			continue;
+		else if (ret)
+			goto err;
+
+		if (panel) {
+			bridge = drm_panel_bridge_add_typed(panel,
+							    DRM_MODE_CONNECTOR_DPI);
+			if (IS_ERR(bridge)) {
+				DRM_ERROR("panel-bridge endpoint %d\n", i);
+				ret = PTR_ERR(bridge);
+				goto err;
+			}
+		}
+
+		if (bridge) {
+			ret = ltdc_encoder_init(ddev, bridge);
+			if (ret) {
+				DRM_ERROR("init encoder endpoint %d\n", i);
+				goto err;
+			}
+		}
+	}
+
+	rstc = devm_reset_control_get_exclusive(dev, NULL);
+
+	mutex_init(&ldev->err_lock);
+
 	if (!IS_ERR(rstc)) {
 		reset_control_assert(rstc);
 		usleep_range(10, 20);
@@ -1268,7 +1287,6 @@ int ltdc_load(struct drm_device *ddev)
 		}
 	}
 
-
 	ret = ltdc_get_caps(ddev);
 	if (ret) {
 		DRM_ERROR("hardware identifier (0x%08x) not supported!\n",
@@ -1278,27 +1296,6 @@ int ltdc_load(struct drm_device *ddev)
 
 	DRM_DEBUG_DRIVER("ltdc hw version 0x%08x\n", ldev->caps.hw_version);
 
-	/* Add endpoints panels or bridges if any */
-	for (i = 0; i < MAX_ENDPOINTS; i++) {
-		if (panel[i]) {
-			bridge[i] = drm_panel_bridge_add_typed(panel[i],
-							       DRM_MODE_CONNECTOR_DPI);
-			if (IS_ERR(bridge[i])) {
-				DRM_ERROR("panel-bridge endpoint %d\n", i);
-				ret = PTR_ERR(bridge[i]);
-				goto err;
-			}
-		}
-
-		if (bridge[i]) {
-			ret = ltdc_encoder_init(ddev, bridge[i]);
-			if (ret) {
-				DRM_ERROR("init encoder endpoint %d\n", i);
-				goto err;
-			}
-		}
-	}
-
 	crtc = devm_kzalloc(dev, sizeof(*crtc), GFP_KERNEL);
 	if (!crtc) {
 		DRM_ERROR("Failed to allocate crtc\n");
@@ -1331,8 +1328,8 @@ int ltdc_load(struct drm_device *ddev)
 
 	return 0;
 err:
-	for (i = 0; i < MAX_ENDPOINTS; i++)
-		drm_panel_bridge_remove(bridge[i]);
+	for (i = 0; i < nb_endpoints; i++)
+		drm_of_panel_bridge_remove(ddev->dev->of_node, 0, i);
 
 	clk_disable_unprepare(ldev->pixel_clk);
 
@@ -1341,11 +1338,14 @@ int ltdc_load(struct drm_device *ddev)
 
 void ltdc_unload(struct drm_device *ddev)
 {
-	int i;
+	struct device *dev = ddev->dev;
+	int nb_endpoints, i;
 
 	DRM_DEBUG_DRIVER("\n");
 
-	for (i = 0; i < MAX_ENDPOINTS; i++)
+	nb_endpoints = of_graph_get_endpoint_count(dev->of_node);
+
+	for (i = 0; i < nb_endpoints; i++)
 		drm_of_panel_bridge_remove(ddev->dev->of_node, 0, i);
 
 	pm_runtime_disable(ddev->dev);
-- 
2.7.4


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/stm: ltdc: check number of endpoints
  2020-01-21 10:14 [PATCH] drm/stm: ltdc: check number of endpoints Yannick Fertre
@ 2020-01-23  9:51 ` Philippe CORNU
  2020-02-04 11:01   ` Benjamin Gaignard
  0 siblings, 1 reply; 5+ messages in thread
From: Philippe CORNU @ 2020-01-23  9:51 UTC (permalink / raw)
  To: Yannick FERTRE, Benjamin GAIGNARD, David Airlie, Daniel Vetter,
	Maxime Coquelin, Alexandre TORGUE, dri-devel, linux-stm32,
	linux-arm-kernel, linux-kernel

Dear Yannick,
Thank you for your patch,

Acked-by: Philippe Cornu <philippe.cornu@st.com>

Philippe :-)

On 1/21/20 11:14 AM, Yannick Fertre wrote:
> Number of endpoints could exceed the fix value MAX_ENDPOINTS(2).
> Instead of increase simply this value, the number of endpoint
> could be read from device tree. Load sequence has been a little
> rework to take care of several panel or bridge which can be
> connected/disconnected or enable/disable.
> 
> Signed-off-by: Yannick Fertré <yannick.fertre@st.com>
> ---
>   drivers/gpu/drm/stm/ltdc.c | 104 ++++++++++++++++++++++-----------------------
>   1 file changed, 52 insertions(+), 52 deletions(-)
> 
> diff --git a/drivers/gpu/drm/stm/ltdc.c b/drivers/gpu/drm/stm/ltdc.c
> index c2815e8..dba8e7f 100644
> --- a/drivers/gpu/drm/stm/ltdc.c
> +++ b/drivers/gpu/drm/stm/ltdc.c
> @@ -42,8 +42,6 @@
>   
>   #define MAX_IRQ 4
>   
> -#define MAX_ENDPOINTS 2
> -
>   #define HWVER_10200 0x010200
>   #define HWVER_10300 0x010300
>   #define HWVER_20101 0x020101
> @@ -1190,36 +1188,20 @@ int ltdc_load(struct drm_device *ddev)
>   	struct ltdc_device *ldev = ddev->dev_private;
>   	struct device *dev = ddev->dev;
>   	struct device_node *np = dev->of_node;
> -	struct drm_bridge *bridge[MAX_ENDPOINTS] = {NULL};
> -	struct drm_panel *panel[MAX_ENDPOINTS] = {NULL};
> +	struct drm_bridge *bridge;
> +	struct drm_panel *panel;
>   	struct drm_crtc *crtc;
>   	struct reset_control *rstc;
>   	struct resource *res;
> -	int irq, ret, i, endpoint_not_ready = -ENODEV;
> +	int irq, i, nb_endpoints;
> +	int ret = -ENODEV;
>   
>   	DRM_DEBUG_DRIVER("\n");
>   
> -	/* Get endpoints if any */
> -	for (i = 0; i < MAX_ENDPOINTS; i++) {
> -		ret = drm_of_find_panel_or_bridge(np, 0, i, &panel[i],
> -						  &bridge[i]);
> -
> -		/*
> -		 * If at least one endpoint is -EPROBE_DEFER, defer probing,
> -		 * else if at least one endpoint is ready, continue probing.
> -		 */
> -		if (ret == -EPROBE_DEFER)
> -			return ret;
> -		else if (!ret)
> -			endpoint_not_ready = 0;
> -	}
> -
> -	if (endpoint_not_ready)
> -		return endpoint_not_ready;
> -
> -	rstc = devm_reset_control_get_exclusive(dev, NULL);
> -
> -	mutex_init(&ldev->err_lock);
> +	/* Get number of endpoints */
> +	nb_endpoints = of_graph_get_endpoint_count(np);
> +	if (!nb_endpoints)
> +		return -ENODEV;
>   
>   	ldev->pixel_clk = devm_clk_get(dev, "lcd");
>   	if (IS_ERR(ldev->pixel_clk)) {
> @@ -1233,6 +1215,43 @@ int ltdc_load(struct drm_device *ddev)
>   		return -ENODEV;
>   	}
>   
> +	/* Get endpoints if any */
> +	for (i = 0; i < nb_endpoints; i++) {
> +		ret = drm_of_find_panel_or_bridge(np, 0, i, &panel, &bridge);
> +
> +		/*
> +		 * If at least one endpoint is -ENODEV, continue probing,
> +		 * else if at least one endpoint returned an error
> +		 * (ie -EPROBE_DEFER) then stop probing.
> +		 */
> +		if (ret == -ENODEV)
> +			continue;
> +		else if (ret)
> +			goto err;
> +
> +		if (panel) {
> +			bridge = drm_panel_bridge_add_typed(panel,
> +							    DRM_MODE_CONNECTOR_DPI);
> +			if (IS_ERR(bridge)) {
> +				DRM_ERROR("panel-bridge endpoint %d\n", i);
> +				ret = PTR_ERR(bridge);
> +				goto err;
> +			}
> +		}
> +
> +		if (bridge) {
> +			ret = ltdc_encoder_init(ddev, bridge);
> +			if (ret) {
> +				DRM_ERROR("init encoder endpoint %d\n", i);
> +				goto err;
> +			}
> +		}
> +	}
> +
> +	rstc = devm_reset_control_get_exclusive(dev, NULL);
> +
> +	mutex_init(&ldev->err_lock);
> +
>   	if (!IS_ERR(rstc)) {
>   		reset_control_assert(rstc);
>   		usleep_range(10, 20);
> @@ -1268,7 +1287,6 @@ int ltdc_load(struct drm_device *ddev)
>   		}
>   	}
>   
> -
>   	ret = ltdc_get_caps(ddev);
>   	if (ret) {
>   		DRM_ERROR("hardware identifier (0x%08x) not supported!\n",
> @@ -1278,27 +1296,6 @@ int ltdc_load(struct drm_device *ddev)
>   
>   	DRM_DEBUG_DRIVER("ltdc hw version 0x%08x\n", ldev->caps.hw_version);
>   
> -	/* Add endpoints panels or bridges if any */
> -	for (i = 0; i < MAX_ENDPOINTS; i++) {
> -		if (panel[i]) {
> -			bridge[i] = drm_panel_bridge_add_typed(panel[i],
> -							       DRM_MODE_CONNECTOR_DPI);
> -			if (IS_ERR(bridge[i])) {
> -				DRM_ERROR("panel-bridge endpoint %d\n", i);
> -				ret = PTR_ERR(bridge[i]);
> -				goto err;
> -			}
> -		}
> -
> -		if (bridge[i]) {
> -			ret = ltdc_encoder_init(ddev, bridge[i]);
> -			if (ret) {
> -				DRM_ERROR("init encoder endpoint %d\n", i);
> -				goto err;
> -			}
> -		}
> -	}
> -
>   	crtc = devm_kzalloc(dev, sizeof(*crtc), GFP_KERNEL);
>   	if (!crtc) {
>   		DRM_ERROR("Failed to allocate crtc\n");
> @@ -1331,8 +1328,8 @@ int ltdc_load(struct drm_device *ddev)
>   
>   	return 0;
>   err:
> -	for (i = 0; i < MAX_ENDPOINTS; i++)
> -		drm_panel_bridge_remove(bridge[i]);
> +	for (i = 0; i < nb_endpoints; i++)
> +		drm_of_panel_bridge_remove(ddev->dev->of_node, 0, i);
>   
>   	clk_disable_unprepare(ldev->pixel_clk);
>   
> @@ -1341,11 +1338,14 @@ int ltdc_load(struct drm_device *ddev)
>   
>   void ltdc_unload(struct drm_device *ddev)
>   {
> -	int i;
> +	struct device *dev = ddev->dev;
> +	int nb_endpoints, i;
>   
>   	DRM_DEBUG_DRIVER("\n");
>   
> -	for (i = 0; i < MAX_ENDPOINTS; i++)
> +	nb_endpoints = of_graph_get_endpoint_count(dev->of_node);
> +
> +	for (i = 0; i < nb_endpoints; i++)
>   		drm_of_panel_bridge_remove(ddev->dev->of_node, 0, i);
>   
>   	pm_runtime_disable(ddev->dev);
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/stm: ltdc: check number of endpoints
  2020-01-23  9:51 ` Philippe CORNU
@ 2020-02-04 11:01   ` Benjamin Gaignard
  0 siblings, 0 replies; 5+ messages in thread
From: Benjamin Gaignard @ 2020-02-04 11:01 UTC (permalink / raw)
  To: Philippe CORNU
  Cc: Yannick FERTRE, Benjamin GAIGNARD, David Airlie, Daniel Vetter,
	Maxime Coquelin, Alexandre TORGUE, dri-devel, linux-stm32,
	linux-arm-kernel, linux-kernel

Le jeu. 23 janv. 2020 à 10:51, Philippe CORNU <philippe.cornu@st.com> a écrit :
>
> Dear Yannick,
> Thank you for your patch,
>
> Acked-by: Philippe Cornu <philippe.cornu@st.com>
>
> Philippe :-)
>
> On 1/21/20 11:14 AM, Yannick Fertre wrote:
> > Number of endpoints could exceed the fix value MAX_ENDPOINTS(2).
> > Instead of increase simply this value, the number of endpoint
> > could be read from device tree. Load sequence has been a little
> > rework to take care of several panel or bridge which can be
> > connected/disconnected or enable/disable.

This patch doesn't apply on drm-misc-next.
Yannick could you rebase is on top of drm-misc-next and resend it ?
Thanks,

Benjamin
> >
> > Signed-off-by: Yannick Fertré <yannick.fertre@st.com>
> > ---
> >   drivers/gpu/drm/stm/ltdc.c | 104 ++++++++++++++++++++++-----------------------
> >   1 file changed, 52 insertions(+), 52 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/stm/ltdc.c b/drivers/gpu/drm/stm/ltdc.c
> > index c2815e8..dba8e7f 100644
> > --- a/drivers/gpu/drm/stm/ltdc.c
> > +++ b/drivers/gpu/drm/stm/ltdc.c
> > @@ -42,8 +42,6 @@
> >
> >   #define MAX_IRQ 4
> >
> > -#define MAX_ENDPOINTS 2
> > -
> >   #define HWVER_10200 0x010200
> >   #define HWVER_10300 0x010300
> >   #define HWVER_20101 0x020101
> > @@ -1190,36 +1188,20 @@ int ltdc_load(struct drm_device *ddev)
> >       struct ltdc_device *ldev = ddev->dev_private;
> >       struct device *dev = ddev->dev;
> >       struct device_node *np = dev->of_node;
> > -     struct drm_bridge *bridge[MAX_ENDPOINTS] = {NULL};
> > -     struct drm_panel *panel[MAX_ENDPOINTS] = {NULL};
> > +     struct drm_bridge *bridge;
> > +     struct drm_panel *panel;
> >       struct drm_crtc *crtc;
> >       struct reset_control *rstc;
> >       struct resource *res;
> > -     int irq, ret, i, endpoint_not_ready = -ENODEV;
> > +     int irq, i, nb_endpoints;
> > +     int ret = -ENODEV;
> >
> >       DRM_DEBUG_DRIVER("\n");
> >
> > -     /* Get endpoints if any */
> > -     for (i = 0; i < MAX_ENDPOINTS; i++) {
> > -             ret = drm_of_find_panel_or_bridge(np, 0, i, &panel[i],
> > -                                               &bridge[i]);
> > -
> > -             /*
> > -              * If at least one endpoint is -EPROBE_DEFER, defer probing,
> > -              * else if at least one endpoint is ready, continue probing.
> > -              */
> > -             if (ret == -EPROBE_DEFER)
> > -                     return ret;
> > -             else if (!ret)
> > -                     endpoint_not_ready = 0;
> > -     }
> > -
> > -     if (endpoint_not_ready)
> > -             return endpoint_not_ready;
> > -
> > -     rstc = devm_reset_control_get_exclusive(dev, NULL);
> > -
> > -     mutex_init(&ldev->err_lock);
> > +     /* Get number of endpoints */
> > +     nb_endpoints = of_graph_get_endpoint_count(np);
> > +     if (!nb_endpoints)
> > +             return -ENODEV;
> >
> >       ldev->pixel_clk = devm_clk_get(dev, "lcd");
> >       if (IS_ERR(ldev->pixel_clk)) {
> > @@ -1233,6 +1215,43 @@ int ltdc_load(struct drm_device *ddev)
> >               return -ENODEV;
> >       }
> >
> > +     /* Get endpoints if any */
> > +     for (i = 0; i < nb_endpoints; i++) {
> > +             ret = drm_of_find_panel_or_bridge(np, 0, i, &panel, &bridge);
> > +
> > +             /*
> > +              * If at least one endpoint is -ENODEV, continue probing,
> > +              * else if at least one endpoint returned an error
> > +              * (ie -EPROBE_DEFER) then stop probing.
> > +              */
> > +             if (ret == -ENODEV)
> > +                     continue;
> > +             else if (ret)
> > +                     goto err;
> > +
> > +             if (panel) {
> > +                     bridge = drm_panel_bridge_add_typed(panel,
> > +                                                         DRM_MODE_CONNECTOR_DPI);
> > +                     if (IS_ERR(bridge)) {
> > +                             DRM_ERROR("panel-bridge endpoint %d\n", i);
> > +                             ret = PTR_ERR(bridge);
> > +                             goto err;
> > +                     }
> > +             }
> > +
> > +             if (bridge) {
> > +                     ret = ltdc_encoder_init(ddev, bridge);
> > +                     if (ret) {
> > +                             DRM_ERROR("init encoder endpoint %d\n", i);
> > +                             goto err;
> > +                     }
> > +             }
> > +     }
> > +
> > +     rstc = devm_reset_control_get_exclusive(dev, NULL);
> > +
> > +     mutex_init(&ldev->err_lock);
> > +
> >       if (!IS_ERR(rstc)) {
> >               reset_control_assert(rstc);
> >               usleep_range(10, 20);
> > @@ -1268,7 +1287,6 @@ int ltdc_load(struct drm_device *ddev)
> >               }
> >       }
> >
> > -
> >       ret = ltdc_get_caps(ddev);
> >       if (ret) {
> >               DRM_ERROR("hardware identifier (0x%08x) not supported!\n",
> > @@ -1278,27 +1296,6 @@ int ltdc_load(struct drm_device *ddev)
> >
> >       DRM_DEBUG_DRIVER("ltdc hw version 0x%08x\n", ldev->caps.hw_version);
> >
> > -     /* Add endpoints panels or bridges if any */
> > -     for (i = 0; i < MAX_ENDPOINTS; i++) {
> > -             if (panel[i]) {
> > -                     bridge[i] = drm_panel_bridge_add_typed(panel[i],
> > -                                                            DRM_MODE_CONNECTOR_DPI);
> > -                     if (IS_ERR(bridge[i])) {
> > -                             DRM_ERROR("panel-bridge endpoint %d\n", i);
> > -                             ret = PTR_ERR(bridge[i]);
> > -                             goto err;
> > -                     }
> > -             }
> > -
> > -             if (bridge[i]) {
> > -                     ret = ltdc_encoder_init(ddev, bridge[i]);
> > -                     if (ret) {
> > -                             DRM_ERROR("init encoder endpoint %d\n", i);
> > -                             goto err;
> > -                     }
> > -             }
> > -     }
> > -
> >       crtc = devm_kzalloc(dev, sizeof(*crtc), GFP_KERNEL);
> >       if (!crtc) {
> >               DRM_ERROR("Failed to allocate crtc\n");
> > @@ -1331,8 +1328,8 @@ int ltdc_load(struct drm_device *ddev)
> >
> >       return 0;
> >   err:
> > -     for (i = 0; i < MAX_ENDPOINTS; i++)
> > -             drm_panel_bridge_remove(bridge[i]);
> > +     for (i = 0; i < nb_endpoints; i++)
> > +             drm_of_panel_bridge_remove(ddev->dev->of_node, 0, i);
> >
> >       clk_disable_unprepare(ldev->pixel_clk);
> >
> > @@ -1341,11 +1338,14 @@ int ltdc_load(struct drm_device *ddev)
> >
> >   void ltdc_unload(struct drm_device *ddev)
> >   {
> > -     int i;
> > +     struct device *dev = ddev->dev;
> > +     int nb_endpoints, i;
> >
> >       DRM_DEBUG_DRIVER("\n");
> >
> > -     for (i = 0; i < MAX_ENDPOINTS; i++)
> > +     nb_endpoints = of_graph_get_endpoint_count(dev->of_node);
> > +
> > +     for (i = 0; i < nb_endpoints; i++)
> >               drm_of_panel_bridge_remove(ddev->dev->of_node, 0, i);
> >
> >       pm_runtime_disable(ddev->dev);
> >
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] drm/stm: ltdc: check number of endpoints
  2020-02-28  8:07 Yannick Fertre
@ 2020-03-30 13:40 ` Philippe CORNU
  0 siblings, 0 replies; 5+ messages in thread
From: Philippe CORNU @ 2020-03-30 13:40 UTC (permalink / raw)
  To: Yannick FERTRE, Benjamin GAIGNARD, David Airlie, Daniel Vetter,
	Maxime Coquelin, Alexandre TORGUE, dri-devel, linux-stm32,
	linux-arm-kernel, linux-kernel

Dear Yannick,
Thank you for your patch,
Acked-by: Philippe Cornu <philippe.cornu@st.com>
(sorry for the email format)
Philippe :-)

-----Original Message-----
From: Yannick FERTRE <yannick.fertre@st.com> 
Sent: Friday, February 28, 2020 09:08
To: Yannick FERTRE <yannick.fertre@st.com>; Philippe CORNU <philippe.cornu@st.com>; Benjamin GAIGNARD <benjamin.gaignard@st.com>; David Airlie <airlied@linux.ie>; Daniel Vetter <daniel@ffwll.ch>; Maxime Coquelin <mcoquelin.stm32@gmail.com>; Alexandre TORGUE <alexandre.torgue@st.com>; dri-devel@lists.freedesktop.org; linux-stm32@st-md-mailman.stormreply.com; linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org
Subject: [PATCH] drm/stm: ltdc: check number of endpoints

Number of endpoints could exceed the fix value MAX_ENDPOINTS(2).
Instead of increase simply this value, the number of endpoint could be read from device tree. Load sequence has been a little rework to take care of several panel or bridge which can be connected/disconnected or enable/disable.

Signed-off-by: Yannick Fertre <yannick.fertre@st.com>
---
 drivers/gpu/drm/stm/ltdc.c | 102 +++++++++++++++++++++++----------------------
 1 file changed, 52 insertions(+), 50 deletions(-)

diff --git a/drivers/gpu/drm/stm/ltdc.c b/drivers/gpu/drm/stm/ltdc.c index df585fe..f894968 100644
--- a/drivers/gpu/drm/stm/ltdc.c
+++ b/drivers/gpu/drm/stm/ltdc.c
@@ -42,8 +42,6 @@

 #define MAX_IRQ 4

-#define MAX_ENDPOINTS 2
-
 #define HWVER_10200 0x010200
 #define HWVER_10300 0x010300
 #define HWVER_20101 0x020101
@@ -1201,36 +1199,20 @@ int ltdc_load(struct drm_device *ddev)
 	struct ltdc_device *ldev = ddev->dev_private;
 	struct device *dev = ddev->dev;
 	struct device_node *np = dev->of_node;
-	struct drm_bridge *bridge[MAX_ENDPOINTS] = {NULL};
-	struct drm_panel *panel[MAX_ENDPOINTS] = {NULL};
+	struct drm_bridge *bridge;
+	struct drm_panel *panel;
 	struct drm_crtc *crtc;
 	struct reset_control *rstc;
 	struct resource *res;
-	int irq, ret, i, endpoint_not_ready = -ENODEV;
+	int irq, i, nb_endpoints;
+	int ret = -ENODEV;

 	DRM_DEBUG_DRIVER("\n");

-	/* Get endpoints if any */
-	for (i = 0; i < MAX_ENDPOINTS; i++) {
-		ret = drm_of_find_panel_or_bridge(np, 0, i, &panel[i],
-						  &bridge[i]);
-
-		/*
-		 * If at least one endpoint is -EPROBE_DEFER, defer probing,
-		 * else if at least one endpoint is ready, continue probing.
-		 */
-		if (ret == -EPROBE_DEFER)
-			return ret;
-		else if (!ret)
-			endpoint_not_ready = 0;
-	}
-
-	if (endpoint_not_ready)
-		return endpoint_not_ready;
-
-	rstc = devm_reset_control_get_exclusive(dev, NULL);
-
-	mutex_init(&ldev->err_lock);
+	/* Get number of endpoints */
+	nb_endpoints = of_graph_get_endpoint_count(np);
+	if (!nb_endpoints)
+		return -ENODEV;

 	ldev->pixel_clk = devm_clk_get(dev, "lcd");
 	if (IS_ERR(ldev->pixel_clk)) {
@@ -1244,6 +1226,43 @@ int ltdc_load(struct drm_device *ddev)
 		return -ENODEV;
 	}

+	/* Get endpoints if any */
+	for (i = 0; i < nb_endpoints; i++) {
+		ret = drm_of_find_panel_or_bridge(np, 0, i, &panel, &bridge);
+
+		/*
+		 * If at least one endpoint is -ENODEV, continue probing,
+		 * else if at least one endpoint returned an error
+		 * (ie -EPROBE_DEFER) then stop probing.
+		 */
+		if (ret == -ENODEV)
+			continue;
+		else if (ret)
+			goto err;
+
+		if (panel) {
+			bridge = drm_panel_bridge_add_typed(panel,
+							    DRM_MODE_CONNECTOR_DPI);
+			if (IS_ERR(bridge)) {
+				DRM_ERROR("panel-bridge endpoint %d\n", i);
+				ret = PTR_ERR(bridge);
+				goto err;
+			}
+		}
+
+		if (bridge) {
+			ret = ltdc_encoder_init(ddev, bridge);
+			if (ret) {
+				DRM_ERROR("init encoder endpoint %d\n", i);
+				goto err;
+			}
+		}
+	}
+
+	rstc = devm_reset_control_get_exclusive(dev, NULL);
+
+	mutex_init(&ldev->err_lock);
+
 	if (!IS_ERR(rstc)) {
 		reset_control_assert(rstc);
 		usleep_range(10, 20);
@@ -1285,27 +1304,7 @@ int ltdc_load(struct drm_device *ddev)
 			DRM_ERROR("Failed to register LTDC interrupt\n");
 			goto err;
 		}
-	}

-	/* Add endpoints panels or bridges if any */
-	for (i = 0; i < MAX_ENDPOINTS; i++) {
-		if (panel[i]) {
-			bridge[i] = drm_panel_bridge_add_typed(panel[i],
-							       DRM_MODE_CONNECTOR_DPI);
-			if (IS_ERR(bridge[i])) {
-				DRM_ERROR("panel-bridge endpoint %d\n", i);
-				ret = PTR_ERR(bridge[i]);
-				goto err;
-			}
-		}
-
-		if (bridge[i]) {
-			ret = ltdc_encoder_init(ddev, bridge[i]);
-			if (ret) {
-				DRM_ERROR("init encoder endpoint %d\n", i);
-				goto err;
-			}
-		}
 	}

 	crtc = devm_kzalloc(dev, sizeof(*crtc), GFP_KERNEL); @@ -1340,8 +1339,8 @@ int ltdc_load(struct drm_device *ddev)

 	return 0;
 err:
-	for (i = 0; i < MAX_ENDPOINTS; i++)
-		drm_panel_bridge_remove(bridge[i]);
+	for (i = 0; i < nb_endpoints; i++)
+		drm_of_panel_bridge_remove(ddev->dev->of_node, 0, i);

 	clk_disable_unprepare(ldev->pixel_clk);

@@ -1350,11 +1349,14 @@ int ltdc_load(struct drm_device *ddev)

 void ltdc_unload(struct drm_device *ddev)  {
-	int i;
+	struct device *dev = ddev->dev;
+	int nb_endpoints, i;

 	DRM_DEBUG_DRIVER("\n");

-	for (i = 0; i < MAX_ENDPOINTS; i++)
+	nb_endpoints = of_graph_get_endpoint_count(dev->of_node);
+
+	for (i = 0; i < nb_endpoints; i++)
 		drm_of_panel_bridge_remove(ddev->dev->of_node, 0, i);

 	pm_runtime_disable(ddev->dev);
--
2.7.4


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] drm/stm: ltdc: check number of endpoints
@ 2020-02-28  8:07 Yannick Fertre
  2020-03-30 13:40 ` Philippe CORNU
  0 siblings, 1 reply; 5+ messages in thread
From: Yannick Fertre @ 2020-02-28  8:07 UTC (permalink / raw)
  To: Yannick Fertre, Philippe Cornu, Benjamin Gaignard, David Airlie,
	Daniel Vetter, Maxime Coquelin, Alexandre Torgue, dri-devel,
	linux-stm32, linux-arm-kernel, linux-kernel

Number of endpoints could exceed the fix value MAX_ENDPOINTS(2).
Instead of increase simply this value, the number of endpoint
could be read from device tree. Load sequence has been a little
rework to take care of several panel or bridge which can be
connected/disconnected or enable/disable.

Signed-off-by: Yannick Fertre <yannick.fertre@st.com>
---
 drivers/gpu/drm/stm/ltdc.c | 102 +++++++++++++++++++++++----------------------
 1 file changed, 52 insertions(+), 50 deletions(-)

diff --git a/drivers/gpu/drm/stm/ltdc.c b/drivers/gpu/drm/stm/ltdc.c
index df585fe..f894968 100644
--- a/drivers/gpu/drm/stm/ltdc.c
+++ b/drivers/gpu/drm/stm/ltdc.c
@@ -42,8 +42,6 @@

 #define MAX_IRQ 4

-#define MAX_ENDPOINTS 2
-
 #define HWVER_10200 0x010200
 #define HWVER_10300 0x010300
 #define HWVER_20101 0x020101
@@ -1201,36 +1199,20 @@ int ltdc_load(struct drm_device *ddev)
 	struct ltdc_device *ldev = ddev->dev_private;
 	struct device *dev = ddev->dev;
 	struct device_node *np = dev->of_node;
-	struct drm_bridge *bridge[MAX_ENDPOINTS] = {NULL};
-	struct drm_panel *panel[MAX_ENDPOINTS] = {NULL};
+	struct drm_bridge *bridge;
+	struct drm_panel *panel;
 	struct drm_crtc *crtc;
 	struct reset_control *rstc;
 	struct resource *res;
-	int irq, ret, i, endpoint_not_ready = -ENODEV;
+	int irq, i, nb_endpoints;
+	int ret = -ENODEV;

 	DRM_DEBUG_DRIVER("\n");

-	/* Get endpoints if any */
-	for (i = 0; i < MAX_ENDPOINTS; i++) {
-		ret = drm_of_find_panel_or_bridge(np, 0, i, &panel[i],
-						  &bridge[i]);
-
-		/*
-		 * If at least one endpoint is -EPROBE_DEFER, defer probing,
-		 * else if at least one endpoint is ready, continue probing.
-		 */
-		if (ret == -EPROBE_DEFER)
-			return ret;
-		else if (!ret)
-			endpoint_not_ready = 0;
-	}
-
-	if (endpoint_not_ready)
-		return endpoint_not_ready;
-
-	rstc = devm_reset_control_get_exclusive(dev, NULL);
-
-	mutex_init(&ldev->err_lock);
+	/* Get number of endpoints */
+	nb_endpoints = of_graph_get_endpoint_count(np);
+	if (!nb_endpoints)
+		return -ENODEV;

 	ldev->pixel_clk = devm_clk_get(dev, "lcd");
 	if (IS_ERR(ldev->pixel_clk)) {
@@ -1244,6 +1226,43 @@ int ltdc_load(struct drm_device *ddev)
 		return -ENODEV;
 	}

+	/* Get endpoints if any */
+	for (i = 0; i < nb_endpoints; i++) {
+		ret = drm_of_find_panel_or_bridge(np, 0, i, &panel, &bridge);
+
+		/*
+		 * If at least one endpoint is -ENODEV, continue probing,
+		 * else if at least one endpoint returned an error
+		 * (ie -EPROBE_DEFER) then stop probing.
+		 */
+		if (ret == -ENODEV)
+			continue;
+		else if (ret)
+			goto err;
+
+		if (panel) {
+			bridge = drm_panel_bridge_add_typed(panel,
+							    DRM_MODE_CONNECTOR_DPI);
+			if (IS_ERR(bridge)) {
+				DRM_ERROR("panel-bridge endpoint %d\n", i);
+				ret = PTR_ERR(bridge);
+				goto err;
+			}
+		}
+
+		if (bridge) {
+			ret = ltdc_encoder_init(ddev, bridge);
+			if (ret) {
+				DRM_ERROR("init encoder endpoint %d\n", i);
+				goto err;
+			}
+		}
+	}
+
+	rstc = devm_reset_control_get_exclusive(dev, NULL);
+
+	mutex_init(&ldev->err_lock);
+
 	if (!IS_ERR(rstc)) {
 		reset_control_assert(rstc);
 		usleep_range(10, 20);
@@ -1285,27 +1304,7 @@ int ltdc_load(struct drm_device *ddev)
 			DRM_ERROR("Failed to register LTDC interrupt\n");
 			goto err;
 		}
-	}

-	/* Add endpoints panels or bridges if any */
-	for (i = 0; i < MAX_ENDPOINTS; i++) {
-		if (panel[i]) {
-			bridge[i] = drm_panel_bridge_add_typed(panel[i],
-							       DRM_MODE_CONNECTOR_DPI);
-			if (IS_ERR(bridge[i])) {
-				DRM_ERROR("panel-bridge endpoint %d\n", i);
-				ret = PTR_ERR(bridge[i]);
-				goto err;
-			}
-		}
-
-		if (bridge[i]) {
-			ret = ltdc_encoder_init(ddev, bridge[i]);
-			if (ret) {
-				DRM_ERROR("init encoder endpoint %d\n", i);
-				goto err;
-			}
-		}
 	}

 	crtc = devm_kzalloc(dev, sizeof(*crtc), GFP_KERNEL);
@@ -1340,8 +1339,8 @@ int ltdc_load(struct drm_device *ddev)

 	return 0;
 err:
-	for (i = 0; i < MAX_ENDPOINTS; i++)
-		drm_panel_bridge_remove(bridge[i]);
+	for (i = 0; i < nb_endpoints; i++)
+		drm_of_panel_bridge_remove(ddev->dev->of_node, 0, i);

 	clk_disable_unprepare(ldev->pixel_clk);

@@ -1350,11 +1349,14 @@ int ltdc_load(struct drm_device *ddev)

 void ltdc_unload(struct drm_device *ddev)
 {
-	int i;
+	struct device *dev = ddev->dev;
+	int nb_endpoints, i;

 	DRM_DEBUG_DRIVER("\n");

-	for (i = 0; i < MAX_ENDPOINTS; i++)
+	nb_endpoints = of_graph_get_endpoint_count(dev->of_node);
+
+	for (i = 0; i < nb_endpoints; i++)
 		drm_of_panel_bridge_remove(ddev->dev->of_node, 0, i);

 	pm_runtime_disable(ddev->dev);
--
2.7.4


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-03-30 13:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-21 10:14 [PATCH] drm/stm: ltdc: check number of endpoints Yannick Fertre
2020-01-23  9:51 ` Philippe CORNU
2020-02-04 11:01   ` Benjamin Gaignard
2020-02-28  8:07 Yannick Fertre
2020-03-30 13:40 ` Philippe CORNU

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).