drm: Add aspect ratio parsing in DRM layer
authorShashank Sharma <shashank.sharma@intel.com>
Mon, 17 Oct 2016 12:04:38 +0000 (17:34 +0530)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Mon, 17 Oct 2016 12:23:29 +0000 (14:23 +0200)
Current DRM layer functions don't parse aspect ratio information
while converting a user mode->kernel mode or vice versa. This
causes modeset to pick mode with wrong aspect ratio, eventually
causing failures in HDMI compliance test cases, due to wrong VIC.

This patch adds aspect ratio information in DRM's mode conversion
and mode comparision functions, to make sure kernel picks mode
with right aspect ratio (as per the VIC).

V2: Addressed review comments from Sean:
- Fix spellings/typo
- No need to handle aspect ratio none
- Add a break, for default case too
V3: Rebase
V4: Added r-b from Jose

Signed-off-by: Shashank Sharma <shashank.sharma@intel.com>
Signed-off-by: Lin, Jia <lin.a.jia@intel.com>
Signed-off-by: Akashdeep Sharma <akashdeep.sharma@intel.com>
Reviewed-by: Jim Bride <jim.bride@linux.intel.com>
Reviewed-by: Jose Abreu <Jose.Abreu@synopsys.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1476705880-15600-3-git-send-email-shashank.sharma@intel.com
drivers/gpu/drm/drm_modes.c

index 53f07ac7c1749d20e7aa904eaabc33adbc4abbc8..fde927a6cc5db27db805deba75a647e80b8ca76d 100644 (file)
@@ -997,6 +997,7 @@ bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
            mode1->vsync_end == mode2->vsync_end &&
            mode1->vtotal == mode2->vtotal &&
            mode1->vscan == mode2->vscan &&
+           mode1->picture_aspect_ratio == mode2->picture_aspect_ratio &&
            (mode1->flags & ~DRM_MODE_FLAG_3D_MASK) ==
             (mode2->flags & ~DRM_MODE_FLAG_3D_MASK))
                return true;
@@ -1499,6 +1500,21 @@ void drm_mode_convert_to_umode(struct drm_mode_modeinfo *out,
        out->vrefresh = in->vrefresh;
        out->flags = in->flags;
        out->type = in->type;
+       out->flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
+
+       switch (in->picture_aspect_ratio) {
+       case HDMI_PICTURE_ASPECT_4_3:
+               out->flags |= DRM_MODE_FLAG_PIC_AR_4_3;
+               break;
+       case HDMI_PICTURE_ASPECT_16_9:
+               out->flags |= DRM_MODE_FLAG_PIC_AR_16_9;
+               break;
+       case HDMI_PICTURE_ASPECT_RESERVED:
+       default:
+               out->flags |= DRM_MODE_FLAG_PIC_AR_NONE;
+               break;
+       }
+
        strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
        out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
 }
@@ -1544,6 +1560,21 @@ int drm_mode_convert_umode(struct drm_display_mode *out,
        strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
        out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
 
+       /* Clearing picture aspect ratio bits from out flags */
+       out->flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
+
+       switch (in->flags & DRM_MODE_FLAG_PIC_AR_MASK) {
+       case DRM_MODE_FLAG_PIC_AR_4_3:
+               out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_4_3;
+               break;
+       case DRM_MODE_FLAG_PIC_AR_16_9:
+               out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_16_9;
+               break;
+       default:
+               out->picture_aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
+               break;
+       }
+
        out->status = drm_mode_validate_basic(out);
        if (out->status != MODE_OK)
                goto out;