MLK-20181-2: drm/mxsfb: Fix initial corrupt frame when activating display
authorLeonard Crestez <leonard.crestez@nxp.com>
Mon, 17 Sep 2018 13:42:12 +0000 (16:42 +0300)
committerLeonard Crestez <leonard.crestez@nxp.com>
Wed, 17 Apr 2019 23:51:34 +0000 (02:51 +0300)
LCDIF will repeatedly display data from CUR_BUF and set CUR_BUF to
NEXT_BUF when done. Since we are only ever writing to NEXT_BUF the
display will show an initial corrupt frame.

Fix by writing the FB paddr to both CUR_BUF and NEXT_BUF when
activating the CRTC.

Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Stefan Agner <stefan@agner.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/7cdac9c064cc2b8a3d237934f186da98cefe6cb3.1537191359.git.leonard.crestez@nxp.com
drivers/gpu/drm/mxsfb/mxsfb_crtc.c

index 224f57c..66a8717 100644 (file)
@@ -315,6 +315,21 @@ static int mxsfb_reset_block(void __iomem *reset_addr)
        return clear_poll_bit(reset_addr, MODULE_CLKGATE);
 }
 
+static dma_addr_t mxsfb_get_fb_paddr(struct mxsfb_drm_private *mxsfb)
+{
+       struct drm_framebuffer *fb = mxsfb->pipe.plane.state->fb;
+       struct drm_gem_cma_object *gem;
+
+       if (!fb)
+               return 0;
+
+       gem = drm_fb_cma_get_gem_obj(fb, 0);
+       if (!gem)
+               return 0;
+
+       return gem->paddr;
+}
+
 static void mxsfb_crtc_mode_set_nofb(struct mxsfb_drm_private *mxsfb)
 {
        struct drm_display_mode *m = &mxsfb->pipe.crtc.state->adjusted_mode;
@@ -405,6 +420,8 @@ static void mxsfb_crtc_mode_set_nofb(struct mxsfb_drm_private *mxsfb)
 
 void mxsfb_crtc_enable(struct mxsfb_drm_private *mxsfb)
 {
+       dma_addr_t paddr;
+
        if (mxsfb->enabled)
                return;
 
@@ -414,6 +431,14 @@ void mxsfb_crtc_enable(struct mxsfb_drm_private *mxsfb)
        mxsfb_enable_axi_clk(mxsfb);
        writel(0, mxsfb->base + LCDC_CTRL);
        mxsfb_crtc_mode_set_nofb(mxsfb);
+
+       /* Write cur_buf as well to avoid an initial corrupt frame */
+       paddr = mxsfb_get_fb_paddr(mxsfb);
+       if (paddr) {
+               writel(paddr, mxsfb->base + mxsfb->devdata->cur_buf);
+               writel(paddr, mxsfb->base + mxsfb->devdata->next_buf);
+       }
+
        mxsfb_enable_controller(mxsfb);
 
        mxsfb->enabled = true;
@@ -443,9 +468,7 @@ void mxsfb_plane_atomic_update(struct mxsfb_drm_private *mxsfb,
        struct drm_framebuffer *old_fb = old_state->fb;
        struct drm_pending_vblank_event *event;
        struct drm_gem_cma_object *gem;
-
-       if (!crtc)
-               return;
+       dma_addr_t paddr;
 
        spin_lock_irq(&crtc->dev->event_lock);
        event = crtc->state->event;
@@ -484,7 +507,10 @@ void mxsfb_plane_atomic_update(struct mxsfb_drm_private *mxsfb,
                mxsfb_set_pixel_fmt(mxsfb, true);
        }
 
-       mxsfb_enable_axi_clk(mxsfb);
-       writel(gem->paddr, mxsfb->base + mxsfb->devdata->next_buf);
-       mxsfb_disable_axi_clk(mxsfb);
+       paddr = mxsfb_get_fb_paddr(mxsfb);
+       if (paddr) {
+               mxsfb_enable_axi_clk(mxsfb);
+               writel(paddr, mxsfb->base + mxsfb->devdata->next_buf);
+               mxsfb_disable_axi_clk(mxsfb);
+       }
 }