dadd23f6d1daf74b4ba5ef053cc2c7e71ad1f152
[openwrt/staging/blogic.git] /
1 From 461711465ee64817a2c3bfc47d3f670c20a5a972 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 716/782] drm/vc4: Take margin setup into account when updating
5 planes
6
7 Commit 666e73587f90f42d90385c1bea1009a650bf73f4 upstream.
8
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.
12
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.
16
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
21 ---
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(+)
26
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;
31 bool feed_txp;
32 bool txp_armed;
33 +
34 + struct {
35 + unsigned int left;
36 + unsigned int right;
37 + unsigned int top;
38 + unsigned int bottom;
39 + } margins;
40 };
41
42 static inline struct vc4_crtc_state *
43 @@ -623,6 +630,37 @@ static enum drm_mode_status vc4_crtc_mod
44 return MODE_OK;
45 }
46
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)
50 +{
51 + struct vc4_crtc_state *vc4_state = to_vc4_crtc_state(state);
52 + struct drm_connector_state *conn_state;
53 + struct drm_connector *conn;
54 + int i;
55 +
56 + *left = vc4_state->margins.left;
57 + *right = vc4_state->margins.right;
58 + *top = vc4_state->margins.top;
59 + *bottom = vc4_state->margins.bottom;
60 +
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.
65 + */
66 + for_each_new_connector_in_state(state->state, conn, conn_state, i) {
67 + if (conn_state->crtc != state->crtc)
68 + continue;
69 +
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;
74 + break;
75 + }
76 +}
77 +
78 static int vc4_crtc_atomic_check(struct drm_crtc *crtc,
79 struct drm_crtc_state *state)
80 {
81 @@ -670,6 +708,10 @@ static int vc4_crtc_atomic_check(struct
82 vc4_state->feed_txp = false;
83 }
84
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;
89 break;
90 }
91
92 @@ -971,6 +1013,7 @@ static struct drm_crtc_state *vc4_crtc_d
93
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;
97
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);
109
110 /* vc4_debugfs.c */
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_
115 }
116 }
117
118 +static int vc4_plane_margins_adj(struct drm_plane_state *pstate)
119 +{
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;
123 +
124 + crtc_state = drm_atomic_get_new_crtc_state(pstate->state,
125 + pstate->crtc);
126 +
127 + vc4_crtc_get_margins(crtc_state, &left, &right, &top, &bottom);
128 + if (!left && !right && !top && !bottom)
129 + return 0;
130 +
131 + if (left + right >= crtc_state->mode.hdisplay ||
132 + top + bottom >= crtc_state->mode.vdisplay)
133 + return -EINVAL;
134 +
135 + adjhdisplay = crtc_state->mode.hdisplay - (left + right);
136 + vc4_pstate->crtc_x = DIV_ROUND_CLOSEST(vc4_pstate->crtc_x *
137 + adjhdisplay,
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;
142 +
143 + adjvdisplay = crtc_state->mode.vdisplay - (top + bottom);
144 + vc4_pstate->crtc_y = DIV_ROUND_CLOSEST(vc4_pstate->crtc_y *
145 + adjvdisplay,
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;
150 +
151 + vc4_pstate->crtc_w = DIV_ROUND_CLOSEST(vc4_pstate->crtc_w *
152 + adjhdisplay,
153 + crtc_state->mode.hdisplay);
154 + vc4_pstate->crtc_h = DIV_ROUND_CLOSEST(vc4_pstate->crtc_h *
155 + adjvdisplay,
156 + crtc_state->mode.vdisplay);
157 +
158 + if (!vc4_pstate->crtc_w || !vc4_pstate->crtc_h)
159 + return -EINVAL;
160 +
161 + return 0;
162 +}
163 +
164 static int vc4_plane_setup_clipping_and_scaling(struct drm_plane_state *state)
165 {
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;
169 u32 h_subsample = 1;
170 u32 v_subsample = 1;
171 + int ret;
172 int i;
173
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;
178
179 + ret = vc4_plane_margins_adj(state);
180 + if (ret)
181 + return ret;
182 +
183 vc4_state->x_scaling[0] = vc4_get_scaling_mode(vc4_state->src_w[0],
184 vc4_state->crtc_w);
185 vc4_state->y_scaling[0] = vc4_get_scaling_mode(vc4_state->src_h[0],