MLK-19199 drm/imx: lcdif: replace FB width usage for cropping
authorFancy Fang <chen.fang@nxp.com>
Fri, 10 Aug 2018 04:22:18 +0000 (12:22 +0800)
committerLeonard Crestez <leonard.crestez@nxp.com>
Wed, 17 Apr 2019 23:51:34 +0000 (02:51 +0300)
According to the comments of 'struct drm_framebuffer', its
'width' field refers to the logical width of the visible
area of the framebuffer. This may be unequal to the total
pixels number of a line. So use the 'pitches' field to
replace 'width' for the horizontal cropping feature.

Signed-off-by: Fancy Fang <chen.fang@nxp.com>
(cherry picked from commit 9a2bbbf971ed79b32ae1c7da2d62b8a72f3ccffd)
(cherry picked from commit 0649fa3e27916edf43dcb9f1edc965e2cf1175e1)

drivers/gpu/drm/imx/lcdif/lcdif-plane.c

index 8b5988e..8ec5b00 100644 (file)
@@ -90,12 +90,12 @@ static int lcdif_plane_atomic_check(struct drm_plane *plane,
        if (!plane_state->visible)
                return -EINVAL;
 
-       /* force 'mode_changed' when fb width changed, since
+       /* force 'mode_changed' when fb pitches changed, since
         * the pitch related registers configuration of LCDIF
         * can not be done when LCDIF is running.
         */
        if (old_fb && likely(!crtc_state->mode_changed)) {
-               if (old_fb->width != fb->width)
+               if (old_fb->pitches[0] != fb->pitches[0])
                        crtc_state->mode_changed = true;
        }
 
@@ -110,7 +110,7 @@ static void lcdif_plane_atomic_update(struct drm_plane *plane,
        struct drm_plane_state *state = plane->state;
        struct drm_framebuffer *fb = state->fb;
        struct drm_gem_cma_object *gem_obj = NULL;
-       u32 fb_addr, src_off, src_w, fb_idx;
+       u32 fb_addr, src_off, src_w, fb_idx, cpp, stride;
        bool crop;
 
        /* plane and crtc is disabling */
@@ -142,11 +142,14 @@ static void lcdif_plane_atomic_update(struct drm_plane *plane,
 
        /* config horizontal cropping if crtc needs modeset */
        if (unlikely(drm_atomic_crtc_needs_modeset(state->crtc->state))) {
+               cpp = fb->format->cpp[0];
+               stride = DIV_ROUND_UP(fb->pitches[0], cpp);
+
                src_w = state->src_w >> 16;
                WARN_ON(src_w > fb->width);
 
-               crop  = src_w != fb->width ? true : false;
-               lcdif_set_fb_hcrop(lcdif, src_w, fb->width, crop);
+               crop  = src_w != stride ? true : false;
+               lcdif_set_fb_hcrop(lcdif, src_w, stride, crop);
        }
 
        lcdif_enable_controller(lcdif);