All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm: mxsfb: Use bus_format from the nearest bridge if present
@ 2021-06-20 22:49 Marek Vasut
  2021-06-21 12:13 ` Lucas Stach
  2021-06-21 13:20 ` Laurent Pinchart
  0 siblings, 2 replies; 3+ messages in thread
From: Marek Vasut @ 2021-06-20 22:49 UTC (permalink / raw)
  To: dri-devel; +Cc: Marek Vasut, ch, Emil Velikov, Daniel Abrecht, Laurent Pinchart

In case there is a bridge connected to the LCDIF, use bus_format
from the bridge, otherwise behave as before and use bus_format
from the connector. This way, even if there are multiple bridges
in the display pipeline, the LCDIF will use the correct format.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Daniel Abrecht <public@danielabrecht.ch>
Cc: Emil Velikov <emil.l.velikov@gmail.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Stefan Agner <stefan@agner.ch>
---
 drivers/gpu/drm/mxsfb/mxsfb_kms.c | 33 +++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/mxsfb/mxsfb_kms.c b/drivers/gpu/drm/mxsfb/mxsfb_kms.c
index 5bcc06c1ac0b..98d8ba0bae84 100644
--- a/drivers/gpu/drm/mxsfb/mxsfb_kms.c
+++ b/drivers/gpu/drm/mxsfb/mxsfb_kms.c
@@ -47,16 +47,13 @@ static u32 set_hsync_pulse_width(struct mxsfb_drm_private *mxsfb, u32 val)
  * Setup the MXSFB registers for decoding the pixels out of the framebuffer and
  * outputting them on the bus.
  */
-static void mxsfb_set_formats(struct mxsfb_drm_private *mxsfb)
+static void mxsfb_set_formats(struct mxsfb_drm_private *mxsfb,
+			      const u32 bus_format)
 {
 	struct drm_device *drm = mxsfb->drm;
 	const u32 format = mxsfb->crtc.primary->state->fb->format->format;
-	u32 bus_format = MEDIA_BUS_FMT_RGB888_1X24;
 	u32 ctrl, ctrl1;
 
-	if (mxsfb->connector->display_info.num_bus_formats)
-		bus_format = mxsfb->connector->display_info.bus_formats[0];
-
 	DRM_DEV_DEBUG_DRIVER(drm->dev, "Using bus_format: 0x%08X\n",
 			     bus_format);
 
@@ -222,7 +219,8 @@ static dma_addr_t mxsfb_get_fb_paddr(struct drm_plane *plane)
 	return gem->paddr;
 }
 
-static void mxsfb_crtc_mode_set_nofb(struct mxsfb_drm_private *mxsfb)
+static void mxsfb_crtc_mode_set_nofb(struct mxsfb_drm_private *mxsfb,
+				     const u32 bus_format)
 {
 	struct drm_device *drm = mxsfb->crtc.dev;
 	struct drm_display_mode *m = &mxsfb->crtc.state->adjusted_mode;
@@ -247,7 +245,7 @@ static void mxsfb_crtc_mode_set_nofb(struct mxsfb_drm_private *mxsfb)
 	if (mxsfb->devdata->has_overlay)
 		writel(0, mxsfb->base + LCDC_AS_CTRL);
 
-	mxsfb_set_formats(mxsfb);
+	mxsfb_set_formats(mxsfb, bus_format);
 
 	clk_set_rate(mxsfb->clk, m->crtc_clock * 1000);
 
@@ -345,7 +343,9 @@ static void mxsfb_crtc_atomic_enable(struct drm_crtc *crtc,
 				     struct drm_atomic_state *state)
 {
 	struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(crtc->dev);
+	struct drm_bridge_state *bridge_state;
 	struct drm_device *drm = mxsfb->drm;
+	u32 bus_format = 0;
 	dma_addr_t paddr;
 
 	pm_runtime_get_sync(drm->dev);
@@ -353,7 +353,24 @@ static void mxsfb_crtc_atomic_enable(struct drm_crtc *crtc,
 
 	drm_crtc_vblank_on(crtc);
 
-	mxsfb_crtc_mode_set_nofb(mxsfb);
+	/* If there is a bridge attached to the LCDIF, use its bus format */
+	if (mxsfb->bridge && state) {
+		bridge_state =
+			drm_atomic_get_new_bridge_state(state,
+							mxsfb->bridge);
+		if (bridge_state)
+			bus_format = bridge_state->input_bus_cfg.format;
+	}
+
+	/* If there is no bridge, use bus format from connector */
+	if (!bus_format && mxsfb->connector->display_info.num_bus_formats)
+		bus_format = mxsfb->connector->display_info.bus_formats[0];
+
+	/* If all else fails, default to RGB888_1X24 */
+	if (!bus_format)
+		bus_format = MEDIA_BUS_FMT_RGB888_1X24;
+
+	mxsfb_crtc_mode_set_nofb(mxsfb, bus_format);
 
 	/* Write cur_buf as well to avoid an initial corrupt frame */
 	paddr = mxsfb_get_fb_paddr(crtc->primary);
-- 
2.30.2


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

* Re: [PATCH] drm: mxsfb: Use bus_format from the nearest bridge if present
  2021-06-20 22:49 [PATCH] drm: mxsfb: Use bus_format from the nearest bridge if present Marek Vasut
@ 2021-06-21 12:13 ` Lucas Stach
  2021-06-21 13:20 ` Laurent Pinchart
  1 sibling, 0 replies; 3+ messages in thread
From: Lucas Stach @ 2021-06-21 12:13 UTC (permalink / raw)
  To: Marek Vasut, dri-devel; +Cc: Daniel Abrecht, Emil Velikov, ch, Laurent Pinchart

Am Montag, dem 21.06.2021 um 00:49 +0200 schrieb Marek Vasut:
> In case there is a bridge connected to the LCDIF, use bus_format
> from the bridge, otherwise behave as before and use bus_format
> from the connector. This way, even if there are multiple bridges
> in the display pipeline, the LCDIF will use the correct format.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>

Reviewed-by: Lucas Stach <l.stach@pengutronix.de>

> Cc: Daniel Abrecht <public@danielabrecht.ch>
> Cc: Emil Velikov <emil.l.velikov@gmail.com>
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Lucas Stach <l.stach@pengutronix.de>
> Cc: Stefan Agner <stefan@agner.ch>
> ---
>  drivers/gpu/drm/mxsfb/mxsfb_kms.c | 33 +++++++++++++++++++++++--------
>  1 file changed, 25 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mxsfb/mxsfb_kms.c b/drivers/gpu/drm/mxsfb/mxsfb_kms.c
> index 5bcc06c1ac0b..98d8ba0bae84 100644
> --- a/drivers/gpu/drm/mxsfb/mxsfb_kms.c
> +++ b/drivers/gpu/drm/mxsfb/mxsfb_kms.c
> @@ -47,16 +47,13 @@ static u32 set_hsync_pulse_width(struct mxsfb_drm_private *mxsfb, u32 val)
>   * Setup the MXSFB registers for decoding the pixels out of the framebuffer and
>   * outputting them on the bus.
>   */
> -static void mxsfb_set_formats(struct mxsfb_drm_private *mxsfb)
> +static void mxsfb_set_formats(struct mxsfb_drm_private *mxsfb,
> +			      const u32 bus_format)
>  {
>  	struct drm_device *drm = mxsfb->drm;
>  	const u32 format = mxsfb->crtc.primary->state->fb->format->format;
> -	u32 bus_format = MEDIA_BUS_FMT_RGB888_1X24;
>  	u32 ctrl, ctrl1;
>  
> -	if (mxsfb->connector->display_info.num_bus_formats)
> -		bus_format = mxsfb->connector->display_info.bus_formats[0];
> -
>  	DRM_DEV_DEBUG_DRIVER(drm->dev, "Using bus_format: 0x%08X\n",
>  			     bus_format);
>  
> @@ -222,7 +219,8 @@ static dma_addr_t mxsfb_get_fb_paddr(struct drm_plane *plane)
>  	return gem->paddr;
>  }
>  
> -static void mxsfb_crtc_mode_set_nofb(struct mxsfb_drm_private *mxsfb)
> +static void mxsfb_crtc_mode_set_nofb(struct mxsfb_drm_private *mxsfb,
> +				     const u32 bus_format)
>  {
>  	struct drm_device *drm = mxsfb->crtc.dev;
>  	struct drm_display_mode *m = &mxsfb->crtc.state->adjusted_mode;
> @@ -247,7 +245,7 @@ static void mxsfb_crtc_mode_set_nofb(struct mxsfb_drm_private *mxsfb)
>  	if (mxsfb->devdata->has_overlay)
>  		writel(0, mxsfb->base + LCDC_AS_CTRL);
>  
> -	mxsfb_set_formats(mxsfb);
> +	mxsfb_set_formats(mxsfb, bus_format);
>  
>  	clk_set_rate(mxsfb->clk, m->crtc_clock * 1000);
>  
> @@ -345,7 +343,9 @@ static void mxsfb_crtc_atomic_enable(struct drm_crtc *crtc,
>  				     struct drm_atomic_state *state)
>  {
>  	struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(crtc->dev);
> +	struct drm_bridge_state *bridge_state;
>  	struct drm_device *drm = mxsfb->drm;
> +	u32 bus_format = 0;
>  	dma_addr_t paddr;
>  
>  	pm_runtime_get_sync(drm->dev);
> @@ -353,7 +353,24 @@ static void mxsfb_crtc_atomic_enable(struct drm_crtc *crtc,
>  
>  	drm_crtc_vblank_on(crtc);
>  
> -	mxsfb_crtc_mode_set_nofb(mxsfb);
> +	/* If there is a bridge attached to the LCDIF, use its bus format */
> +	if (mxsfb->bridge && state) {
> +		bridge_state =
> +			drm_atomic_get_new_bridge_state(state,
> +							mxsfb->bridge);
> +		if (bridge_state)
> +			bus_format = bridge_state->input_bus_cfg.format;
> +	}
> +
> +	/* If there is no bridge, use bus format from connector */
> +	if (!bus_format && mxsfb->connector->display_info.num_bus_formats)
> +		bus_format = mxsfb->connector->display_info.bus_formats[0];
> +
> +	/* If all else fails, default to RGB888_1X24 */
> +	if (!bus_format)
> +		bus_format = MEDIA_BUS_FMT_RGB888_1X24;
> +
> +	mxsfb_crtc_mode_set_nofb(mxsfb, bus_format);
>  
>  	/* Write cur_buf as well to avoid an initial corrupt frame */
>  	paddr = mxsfb_get_fb_paddr(crtc->primary);



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

* Re: [PATCH] drm: mxsfb: Use bus_format from the nearest bridge if present
  2021-06-20 22:49 [PATCH] drm: mxsfb: Use bus_format from the nearest bridge if present Marek Vasut
  2021-06-21 12:13 ` Lucas Stach
@ 2021-06-21 13:20 ` Laurent Pinchart
  1 sibling, 0 replies; 3+ messages in thread
From: Laurent Pinchart @ 2021-06-21 13:20 UTC (permalink / raw)
  To: Marek Vasut; +Cc: ch, Emil Velikov, Daniel Abrecht, dri-devel

Hi Marek,

Thank you for the patch.

On Mon, Jun 21, 2021 at 12:49:18AM +0200, Marek Vasut wrote:
> In case there is a bridge connected to the LCDIF, use bus_format
> from the bridge, otherwise behave as before and use bus_format
> from the connector. This way, even if there are multiple bridges
> in the display pipeline, the LCDIF will use the correct format.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Daniel Abrecht <public@danielabrecht.ch>
> Cc: Emil Velikov <emil.l.velikov@gmail.com>
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Lucas Stach <l.stach@pengutronix.de>
> Cc: Stefan Agner <stefan@agner.ch>
> ---
>  drivers/gpu/drm/mxsfb/mxsfb_kms.c | 33 +++++++++++++++++++++++--------
>  1 file changed, 25 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mxsfb/mxsfb_kms.c b/drivers/gpu/drm/mxsfb/mxsfb_kms.c
> index 5bcc06c1ac0b..98d8ba0bae84 100644
> --- a/drivers/gpu/drm/mxsfb/mxsfb_kms.c
> +++ b/drivers/gpu/drm/mxsfb/mxsfb_kms.c
> @@ -47,16 +47,13 @@ static u32 set_hsync_pulse_width(struct mxsfb_drm_private *mxsfb, u32 val)
>   * Setup the MXSFB registers for decoding the pixels out of the framebuffer and
>   * outputting them on the bus.
>   */
> -static void mxsfb_set_formats(struct mxsfb_drm_private *mxsfb)
> +static void mxsfb_set_formats(struct mxsfb_drm_private *mxsfb,
> +			      const u32 bus_format)
>  {
>  	struct drm_device *drm = mxsfb->drm;
>  	const u32 format = mxsfb->crtc.primary->state->fb->format->format;
> -	u32 bus_format = MEDIA_BUS_FMT_RGB888_1X24;
>  	u32 ctrl, ctrl1;
>  
> -	if (mxsfb->connector->display_info.num_bus_formats)
> -		bus_format = mxsfb->connector->display_info.bus_formats[0];
> -
>  	DRM_DEV_DEBUG_DRIVER(drm->dev, "Using bus_format: 0x%08X\n",
>  			     bus_format);
>  
> @@ -222,7 +219,8 @@ static dma_addr_t mxsfb_get_fb_paddr(struct drm_plane *plane)
>  	return gem->paddr;
>  }
>  
> -static void mxsfb_crtc_mode_set_nofb(struct mxsfb_drm_private *mxsfb)
> +static void mxsfb_crtc_mode_set_nofb(struct mxsfb_drm_private *mxsfb,
> +				     const u32 bus_format)
>  {
>  	struct drm_device *drm = mxsfb->crtc.dev;
>  	struct drm_display_mode *m = &mxsfb->crtc.state->adjusted_mode;
> @@ -247,7 +245,7 @@ static void mxsfb_crtc_mode_set_nofb(struct mxsfb_drm_private *mxsfb)
>  	if (mxsfb->devdata->has_overlay)
>  		writel(0, mxsfb->base + LCDC_AS_CTRL);
>  
> -	mxsfb_set_formats(mxsfb);
> +	mxsfb_set_formats(mxsfb, bus_format);
>  
>  	clk_set_rate(mxsfb->clk, m->crtc_clock * 1000);
>  
> @@ -345,7 +343,9 @@ static void mxsfb_crtc_atomic_enable(struct drm_crtc *crtc,
>  				     struct drm_atomic_state *state)
>  {
>  	struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(crtc->dev);
> +	struct drm_bridge_state *bridge_state;
>  	struct drm_device *drm = mxsfb->drm;
> +	u32 bus_format = 0;
>  	dma_addr_t paddr;
>  
>  	pm_runtime_get_sync(drm->dev);
> @@ -353,7 +353,24 @@ static void mxsfb_crtc_atomic_enable(struct drm_crtc *crtc,
>  
>  	drm_crtc_vblank_on(crtc);
>  
> -	mxsfb_crtc_mode_set_nofb(mxsfb);
> +	/* If there is a bridge attached to the LCDIF, use its bus format */
> +	if (mxsfb->bridge && state) {

I *think* state will always be non-null here.

> +		bridge_state =
> +			drm_atomic_get_new_bridge_state(state,
> +							mxsfb->bridge);
> +		if (bridge_state)

This should be guaranteed to be non-null too.

> +			bus_format = bridge_state->input_bus_cfg.format;
> +	}
> +
> +	/* If there is no bridge, use bus format from connector */
> +	if (!bus_format && mxsfb->connector->display_info.num_bus_formats)
> +		bus_format = mxsfb->connector->display_info.bus_formats[0];
> +
> +	/* If all else fails, default to RGB888_1X24 */
> +	if (!bus_format)
> +		bus_format = MEDIA_BUS_FMT_RGB888_1X24;

	/* And if that fails too... */
	if (!bus_format)
		panic("Gone farming tomatoes in Portugal");

:-)

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +
> +	mxsfb_crtc_mode_set_nofb(mxsfb, bus_format);
>  
>  	/* Write cur_buf as well to avoid an initial corrupt frame */
>  	paddr = mxsfb_get_fb_paddr(crtc->primary);

-- 
Regards,

Laurent Pinchart

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

end of thread, other threads:[~2021-06-21 13:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-20 22:49 [PATCH] drm: mxsfb: Use bus_format from the nearest bridge if present Marek Vasut
2021-06-21 12:13 ` Lucas Stach
2021-06-21 13:20 ` Laurent Pinchart

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.