Skip to content

Commit ecb7e16

Browse files
Gustavo Padovandanvet
authored andcommitted
drm: add helper to get crtc timings (v5)
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>
1 parent 93dc1b6 commit ecb7e16

File tree

5 files changed

+46
-23
lines changed

5 files changed

+46
-23
lines changed

drivers/gpu/drm/drm_crtc.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,6 +2549,27 @@ int drm_mode_set_config_internal(struct drm_mode_set *set)
25492549
}
25502550
EXPORT_SYMBOL(drm_mode_set_config_internal);
25512551

2552+
/**
2553+
* drm_crtc_get_hv_timing - Fetches hdisplay/vdisplay for given mode
2554+
* @mode: mode to query
2555+
* @hdisplay: hdisplay value to fill in
2556+
* @vdisplay: vdisplay value to fill in
2557+
*
2558+
* The vdisplay value will be doubled if the specified mode is a stereo mode of
2559+
* the appropriate layout.
2560+
*/
2561+
void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2562+
int *hdisplay, int *vdisplay)
2563+
{
2564+
struct drm_display_mode adjusted;
2565+
2566+
drm_mode_copy(&adjusted, mode);
2567+
drm_mode_set_crtcinfo(&adjusted, CRTC_STEREO_DOUBLE_ONLY);
2568+
*hdisplay = adjusted.crtc_hdisplay;
2569+
*vdisplay = adjusted.crtc_vdisplay;
2570+
}
2571+
EXPORT_SYMBOL(drm_crtc_get_hv_timing);
2572+
25522573
/**
25532574
* drm_crtc_check_viewport - Checks that a framebuffer is big enough for the
25542575
* CRTC viewport
@@ -2566,16 +2587,7 @@ int drm_crtc_check_viewport(const struct drm_crtc *crtc,
25662587
{
25672588
int hdisplay, vdisplay;
25682589

2569-
hdisplay = mode->hdisplay;
2570-
vdisplay = mode->vdisplay;
2571-
2572-
if (drm_mode_is_stereo(mode)) {
2573-
struct drm_display_mode adjusted = *mode;
2574-
2575-
drm_mode_set_crtcinfo(&adjusted, CRTC_STEREO_DOUBLE);
2576-
hdisplay = adjusted.crtc_hdisplay;
2577-
vdisplay = adjusted.crtc_vdisplay;
2578-
}
2590+
drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay);
25792591

25802592
if (crtc->invert_dimensions)
25812593
swap(hdisplay, vdisplay);

drivers/gpu/drm/drm_modes.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,8 @@ EXPORT_SYMBOL(drm_mode_vrefresh);
739739
* - The CRTC_STEREO_DOUBLE flag can be used to compute the timings for
740740
* buffers containing two eyes (only adjust the timings when needed, eg. for
741741
* "frame packing" or "side by side full").
742+
* - The CRTC_NO_DBLSCAN and CRTC_NO_VSCAN flags request that adjustment *not*
743+
* be performed for doublescan and vscan > 1 modes respectively.
742744
*/
743745
void drm_mode_set_crtcinfo(struct drm_display_mode *p, int adjust_flags)
744746
{
@@ -765,18 +767,22 @@ void drm_mode_set_crtcinfo(struct drm_display_mode *p, int adjust_flags)
765767
}
766768
}
767769

768-
if (p->flags & DRM_MODE_FLAG_DBLSCAN) {
769-
p->crtc_vdisplay *= 2;
770-
p->crtc_vsync_start *= 2;
771-
p->crtc_vsync_end *= 2;
772-
p->crtc_vtotal *= 2;
770+
if (!(adjust_flags & CRTC_NO_DBLSCAN)) {
771+
if (p->flags & DRM_MODE_FLAG_DBLSCAN) {
772+
p->crtc_vdisplay *= 2;
773+
p->crtc_vsync_start *= 2;
774+
p->crtc_vsync_end *= 2;
775+
p->crtc_vtotal *= 2;
776+
}
773777
}
774778

775-
if (p->vscan > 1) {
776-
p->crtc_vdisplay *= p->vscan;
777-
p->crtc_vsync_start *= p->vscan;
778-
p->crtc_vsync_end *= p->vscan;
779-
p->crtc_vtotal *= p->vscan;
779+
if (!(adjust_flags & CRTC_NO_VSCAN)) {
780+
if (p->vscan > 1) {
781+
p->crtc_vdisplay *= p->vscan;
782+
p->crtc_vsync_start *= p->vscan;
783+
p->crtc_vsync_end *= p->vscan;
784+
p->crtc_vtotal *= p->vscan;
785+
}
780786
}
781787

782788
if (adjust_flags & CRTC_STEREO_DOUBLE) {

drivers/gpu/drm/i915/intel_display.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10322,9 +10322,9 @@ intel_modeset_pipe_config(struct drm_crtc *crtc,
1032210322
* computation to clearly distinguish it from the adjusted mode, which
1032310323
* can be changed by the connectors in the below retry loop.
1032410324
*/
10325-
drm_mode_set_crtcinfo(&pipe_config->requested_mode, CRTC_STEREO_DOUBLE);
10326-
pipe_config->pipe_src_w = pipe_config->requested_mode.crtc_hdisplay;
10327-
pipe_config->pipe_src_h = pipe_config->requested_mode.crtc_vdisplay;
10325+
drm_crtc_get_hv_timing(&pipe_config->requested_mode,
10326+
&pipe_config->pipe_src_w,
10327+
&pipe_config->pipe_src_h);
1032810328

1032910329
encoder_retry:
1033010330
/* Ensure the port clock defaults are reset when retrying. */

include/drm/drm_crtc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,8 @@ extern int drm_plane_init(struct drm_device *dev,
11611161
extern void drm_plane_cleanup(struct drm_plane *plane);
11621162
extern unsigned int drm_plane_index(struct drm_plane *plane);
11631163
extern void drm_plane_force_disable(struct drm_plane *plane);
1164+
extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
1165+
int *hdisplay, int *vdisplay);
11641166
extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
11651167
int x, int y,
11661168
const struct drm_display_mode *mode,

include/drm/drm_modes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ enum drm_mode_status {
9090

9191
#define CRTC_INTERLACE_HALVE_V (1 << 0) /* halve V values for interlacing */
9292
#define CRTC_STEREO_DOUBLE (1 << 1) /* adjust timings for stereo modes */
93+
#define CRTC_NO_DBLSCAN (1 << 2) /* don't adjust doublescan */
94+
#define CRTC_NO_VSCAN (1 << 3) /* don't adjust doublescan */
95+
#define CRTC_STEREO_DOUBLE_ONLY (CRTC_NO_DBLSCAN | CRTC_NO_VSCAN)
9396

9497
#define DRM_MODE_FLAG_3D_MAX DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
9598

0 commit comments

Comments
 (0)