drm: add helper to get crtc timings (v5)
authorGustavo Padovan <gustavo.padovan@collabora.co.uk>
Mon, 1 Dec 2014 23:40:09 +0000 (15:40 -0800)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Fri, 5 Dec 2014 20:20:25 +0000 (21:20 +0100)
We need to get hdisplay and vdisplay in a few places so create a
helper to make our job easier.

Note that drm_crtc_check_viewport() and intel_modeset_pipe_config() were
previously making adjustments for doublescan modes and vscan > 1 modes,
which was incorrect.  Using our new helper fixes this mistake.

v2 (by Matt): Use new stereo doubling function (suggested by Ville)

v3 (by Matt):
 - Add missing kerneldoc (Daniel)
 - Use drm_mode_copy() (Jani)

v4 (by Matt):
 - Drop stereo doubling function again; add 'stereo only' flag
   to drm_mode_set_crtcinfo() instead (Ville)

v5 (by Matt):
 - Note behavioral change in drm_crtc_check_viewport() and
   intel_modeset_pipe_config(). (Ander)
 - Describe new adjustment flags in drm_mode_set_crtcinfo()'s
   kerneldoc. (Ander)

Cc: dri-devel@lists.freedesktop.org
Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
Acked-by: Dave Airlie <airlied@gmail.com>
Reviewed-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
drivers/gpu/drm/drm_crtc.c
drivers/gpu/drm/drm_modes.c
drivers/gpu/drm/i915/intel_display.c
include/drm/drm_crtc.h
include/drm/drm_modes.h

index de79283eaea720ba0dc49cab73060a8dfee3d3ca..2985e3ff364f47c04edbf966102da9f32ad41d95 100644 (file)
@@ -2549,6 +2549,27 @@ int drm_mode_set_config_internal(struct drm_mode_set *set)
 }
 EXPORT_SYMBOL(drm_mode_set_config_internal);
 
+/**
+ * drm_crtc_get_hv_timing - Fetches hdisplay/vdisplay for given mode
+ * @mode: mode to query
+ * @hdisplay: hdisplay value to fill in
+ * @vdisplay: vdisplay value to fill in
+ *
+ * The vdisplay value will be doubled if the specified mode is a stereo mode of
+ * the appropriate layout.
+ */
+void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
+                           int *hdisplay, int *vdisplay)
+{
+       struct drm_display_mode adjusted;
+
+       drm_mode_copy(&adjusted, mode);
+       drm_mode_set_crtcinfo(&adjusted, CRTC_STEREO_DOUBLE_ONLY);
+       *hdisplay = adjusted.crtc_hdisplay;
+       *vdisplay = adjusted.crtc_vdisplay;
+}
+EXPORT_SYMBOL(drm_crtc_get_hv_timing);
+
 /**
  * drm_crtc_check_viewport - Checks that a framebuffer is big enough for the
  *     CRTC viewport
@@ -2566,16 +2587,7 @@ int drm_crtc_check_viewport(const struct drm_crtc *crtc,
 {
        int hdisplay, vdisplay;
 
-       hdisplay = mode->hdisplay;
-       vdisplay = mode->vdisplay;
-
-       if (drm_mode_is_stereo(mode)) {
-               struct drm_display_mode adjusted = *mode;
-
-               drm_mode_set_crtcinfo(&adjusted, CRTC_STEREO_DOUBLE);
-               hdisplay = adjusted.crtc_hdisplay;
-               vdisplay = adjusted.crtc_vdisplay;
-       }
+       drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay);
 
        if (crtc->invert_dimensions)
                swap(hdisplay, vdisplay);
index 6d8b941c8200414f1bf3b193cbdc395c27e8622d..7689c14f2f09b2f9064f4067f1752c69d7c1e16a 100644 (file)
@@ -739,6 +739,8 @@ EXPORT_SYMBOL(drm_mode_vrefresh);
  * - The CRTC_STEREO_DOUBLE flag can be used to compute the timings for
  *   buffers containing two eyes (only adjust the timings when needed, eg. for
  *   "frame packing" or "side by side full").
+ * - The CRTC_NO_DBLSCAN and CRTC_NO_VSCAN flags request that adjustment *not*
+ *   be performed for doublescan and vscan > 1 modes respectively.
  */
 void drm_mode_set_crtcinfo(struct drm_display_mode *p, int adjust_flags)
 {
@@ -765,18 +767,22 @@ void drm_mode_set_crtcinfo(struct drm_display_mode *p, int adjust_flags)
                }
        }
 
-       if (p->flags & DRM_MODE_FLAG_DBLSCAN) {
-               p->crtc_vdisplay *= 2;
-               p->crtc_vsync_start *= 2;
-               p->crtc_vsync_end *= 2;
-               p->crtc_vtotal *= 2;
+       if (!(adjust_flags & CRTC_NO_DBLSCAN)) {
+               if (p->flags & DRM_MODE_FLAG_DBLSCAN) {
+                       p->crtc_vdisplay *= 2;
+                       p->crtc_vsync_start *= 2;
+                       p->crtc_vsync_end *= 2;
+                       p->crtc_vtotal *= 2;
+               }
        }
 
-       if (p->vscan > 1) {
-               p->crtc_vdisplay *= p->vscan;
-               p->crtc_vsync_start *= p->vscan;
-               p->crtc_vsync_end *= p->vscan;
-               p->crtc_vtotal *= p->vscan;
+       if (!(adjust_flags & CRTC_NO_VSCAN)) {
+               if (p->vscan > 1) {
+                       p->crtc_vdisplay *= p->vscan;
+                       p->crtc_vsync_start *= p->vscan;
+                       p->crtc_vsync_end *= p->vscan;
+                       p->crtc_vtotal *= p->vscan;
+               }
        }
 
        if (adjust_flags & CRTC_STEREO_DOUBLE) {
index 3a088c03d7b9ae988ede013f9ef7eb1b1fcf3cfa..9eee2c950ab3d4ed8bcd5d1f4f398802aa1ac9b6 100644 (file)
@@ -10322,9 +10322,9 @@ intel_modeset_pipe_config(struct drm_crtc *crtc,
         * computation to clearly distinguish it from the adjusted mode, which
         * can be changed by the connectors in the below retry loop.
         */
-       drm_mode_set_crtcinfo(&pipe_config->requested_mode, CRTC_STEREO_DOUBLE);
-       pipe_config->pipe_src_w = pipe_config->requested_mode.crtc_hdisplay;
-       pipe_config->pipe_src_h = pipe_config->requested_mode.crtc_vdisplay;
+       drm_crtc_get_hv_timing(&pipe_config->requested_mode,
+                              &pipe_config->pipe_src_w,
+                              &pipe_config->pipe_src_h);
 
 encoder_retry:
        /* Ensure the port clock defaults are reset when retrying. */
index dd2c16e4333312194151cf47b946507871d2027d..969da0f1ded8ec260ad57c5c84bf57bea0c8e272 100644 (file)
@@ -1161,6 +1161,8 @@ extern int drm_plane_init(struct drm_device *dev,
 extern void drm_plane_cleanup(struct drm_plane *plane);
 extern unsigned int drm_plane_index(struct drm_plane *plane);
 extern void drm_plane_force_disable(struct drm_plane *plane);
+extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
+                                  int *hdisplay, int *vdisplay);
 extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
                                   int x, int y,
                                   const struct drm_display_mode *mode,
index 91d0582f924e3e90539f0373b4daaaa2b20ae9cb..8f17811d27f50560214044c0f7356f604f1a91f4 100644 (file)
@@ -90,6 +90,9 @@ enum drm_mode_status {
 
 #define CRTC_INTERLACE_HALVE_V (1 << 0) /* halve V values for interlacing */
 #define CRTC_STEREO_DOUBLE     (1 << 1) /* adjust timings for stereo modes */
+#define CRTC_NO_DBLSCAN                (1 << 2) /* don't adjust doublescan */
+#define CRTC_NO_VSCAN          (1 << 3) /* don't adjust doublescan */
+#define CRTC_STEREO_DOUBLE_ONLY        (CRTC_NO_DBLSCAN | CRTC_NO_VSCAN)
 
 #define DRM_MODE_FLAG_3D_MAX   DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF