1 From 4ede5cbb2dffb6c2d5a29a1da8daa851b8351c55 Mon Sep 17 00:00:00 2001
2 From: Boris Brezillon <boris.brezillon@bootlin.com>
3 Date: Thu, 6 Dec 2018 15:24:38 +0100
4 Subject: [PATCH 719/725] drm/vc4: Take margin setup into account when updating
7 Commit 666e73587f90f42d90385c1bea1009a650bf73f4 upstream.
9 Applyin margins is just a matter of scaling all planes appropriately
10 and adjusting the CRTC X/Y offset to account for the
11 left/right/top/bottom borders.
13 Create a vc4_plane_margins_adj() function doing that and call it from
14 vc4_plane_setup_clipping_and_scaling() so that we are ready to attach
15 margins properties to the HDMI connector.
17 Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
18 Reviewed-by: Eric Anholt <eric@anholt.net>
19 Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
20 Link: https://patchwork.freedesktop.org/patch/msgid/20181206142439.10441-5-boris.brezillon@bootlin.com
22 drivers/gpu/drm/vc4/vc4_crtc.c | 43 +++++++++++++++++++++++++++
23 drivers/gpu/drm/vc4/vc4_drv.h | 3 ++
24 drivers/gpu/drm/vc4/vc4_plane.c | 51 +++++++++++++++++++++++++++++++++
25 3 files changed, 97 insertions(+)
27 --- a/drivers/gpu/drm/vc4/vc4_crtc.c
28 +++ b/drivers/gpu/drm/vc4/vc4_crtc.c
29 @@ -48,6 +48,13 @@ struct vc4_crtc_state {
30 struct drm_mm_node mm;
38 + unsigned int bottom;
42 static inline struct vc4_crtc_state *
43 @@ -623,6 +630,37 @@ static enum drm_mode_status vc4_crtc_mod
47 +void vc4_crtc_get_margins(struct drm_crtc_state *state,
48 + unsigned int *left, unsigned int *right,
49 + unsigned int *top, unsigned int *bottom)
51 + struct vc4_crtc_state *vc4_state = to_vc4_crtc_state(state);
52 + struct drm_connector_state *conn_state;
53 + struct drm_connector *conn;
56 + *left = vc4_state->margins.left;
57 + *right = vc4_state->margins.right;
58 + *top = vc4_state->margins.top;
59 + *bottom = vc4_state->margins.bottom;
61 + /* We have to interate over all new connector states because
62 + * vc4_crtc_get_margins() might be called before
63 + * vc4_crtc_atomic_check() which means margins info in vc4_crtc_state
64 + * might be outdated.
66 + for_each_new_connector_in_state(state->state, conn, conn_state, i) {
67 + if (conn_state->crtc != state->crtc)
70 + *left = conn_state->tv.margins.left;
71 + *right = conn_state->tv.margins.right;
72 + *top = conn_state->tv.margins.top;
73 + *bottom = conn_state->tv.margins.bottom;
78 static int vc4_crtc_atomic_check(struct drm_crtc *crtc,
79 struct drm_crtc_state *state)
81 @@ -670,6 +708,10 @@ static int vc4_crtc_atomic_check(struct
82 vc4_state->feed_txp = false;
85 + vc4_state->margins.left = conn_state->tv.margins.left;
86 + vc4_state->margins.right = conn_state->tv.margins.right;
87 + vc4_state->margins.top = conn_state->tv.margins.top;
88 + vc4_state->margins.bottom = conn_state->tv.margins.bottom;
92 @@ -971,6 +1013,7 @@ static struct drm_crtc_state *vc4_crtc_d
94 old_vc4_state = to_vc4_crtc_state(crtc->state);
95 vc4_state->feed_txp = old_vc4_state->feed_txp;
96 + vc4_state->margins = old_vc4_state->margins;
98 __drm_atomic_helper_crtc_duplicate_state(crtc, &vc4_state->base);
99 return &vc4_state->base;
100 --- a/drivers/gpu/drm/vc4/vc4_drv.h
101 +++ b/drivers/gpu/drm/vc4/vc4_drv.h
102 @@ -705,6 +705,9 @@ bool vc4_crtc_get_scanoutpos(struct drm_
103 const struct drm_display_mode *mode);
104 void vc4_crtc_handle_vblank(struct vc4_crtc *crtc);
105 void vc4_crtc_txp_armed(struct drm_crtc_state *state);
106 +void vc4_crtc_get_margins(struct drm_crtc_state *state,
107 + unsigned int *right, unsigned int *left,
108 + unsigned int *top, unsigned int *bottom);
111 int vc4_debugfs_init(struct drm_minor *minor);
112 --- a/drivers/gpu/drm/vc4/vc4_plane.c
113 +++ b/drivers/gpu/drm/vc4/vc4_plane.c
114 @@ -258,6 +258,52 @@ static u32 vc4_get_scl_field(struct drm_
118 +static int vc4_plane_margins_adj(struct drm_plane_state *pstate)
120 + struct vc4_plane_state *vc4_pstate = to_vc4_plane_state(pstate);
121 + unsigned int left, right, top, bottom, adjhdisplay, adjvdisplay;
122 + struct drm_crtc_state *crtc_state;
124 + crtc_state = drm_atomic_get_new_crtc_state(pstate->state,
127 + vc4_crtc_get_margins(crtc_state, &left, &right, &top, &bottom);
128 + if (!left && !right && !top && !bottom)
131 + if (left + right >= crtc_state->mode.hdisplay ||
132 + top + bottom >= crtc_state->mode.vdisplay)
135 + adjhdisplay = crtc_state->mode.hdisplay - (left + right);
136 + vc4_pstate->crtc_x = DIV_ROUND_CLOSEST(vc4_pstate->crtc_x *
138 + crtc_state->mode.hdisplay);
139 + vc4_pstate->crtc_x += left;
140 + if (vc4_pstate->crtc_x > crtc_state->mode.hdisplay - left)
141 + vc4_pstate->crtc_x = crtc_state->mode.hdisplay - left;
143 + adjvdisplay = crtc_state->mode.vdisplay - (top + bottom);
144 + vc4_pstate->crtc_y = DIV_ROUND_CLOSEST(vc4_pstate->crtc_y *
146 + crtc_state->mode.vdisplay);
147 + vc4_pstate->crtc_y += top;
148 + if (vc4_pstate->crtc_y > crtc_state->mode.vdisplay - top)
149 + vc4_pstate->crtc_y = crtc_state->mode.vdisplay - top;
151 + vc4_pstate->crtc_w = DIV_ROUND_CLOSEST(vc4_pstate->crtc_w *
153 + crtc_state->mode.hdisplay);
154 + vc4_pstate->crtc_h = DIV_ROUND_CLOSEST(vc4_pstate->crtc_h *
156 + crtc_state->mode.vdisplay);
158 + if (!vc4_pstate->crtc_w || !vc4_pstate->crtc_h)
164 static int vc4_plane_setup_clipping_and_scaling(struct drm_plane_state *state)
166 struct drm_plane *plane = state->plane;
167 @@ -269,6 +315,7 @@ static int vc4_plane_setup_clipping_and_
168 int num_planes = fb->format->num_planes;
174 for (i = 0; i < num_planes; i++)
175 @@ -292,6 +339,10 @@ static int vc4_plane_setup_clipping_and_
176 vc4_state->crtc_w = state->crtc_w;
177 vc4_state->crtc_h = state->crtc_h;
179 + ret = vc4_plane_margins_adj(state);
183 vc4_state->x_scaling[0] = vc4_get_scaling_mode(vc4_state->src_w[0],
185 vc4_state->y_scaling[0] = vc4_get_scaling_mode(vc4_state->src_h[0],