.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
---|
1 | 2 | /* |
---|
2 | 3 | * rcar_du_vsp.h -- R-Car Display Unit VSP-Based Compositor |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2015 Renesas Electronics Corporation |
---|
5 | 6 | * |
---|
6 | 7 | * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License as published by |
---|
10 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
11 | | - * (at your option) any later version. |
---|
12 | 8 | */ |
---|
13 | 9 | |
---|
14 | | -#include <drm/drmP.h> |
---|
15 | 10 | #include <drm/drm_atomic_helper.h> |
---|
16 | 11 | #include <drm/drm_crtc.h> |
---|
17 | | -#include <drm/drm_crtc_helper.h> |
---|
18 | 12 | #include <drm/drm_fb_cma_helper.h> |
---|
| 13 | +#include <drm/drm_fourcc.h> |
---|
19 | 14 | #include <drm/drm_gem_cma_helper.h> |
---|
20 | 15 | #include <drm/drm_gem_framebuffer_helper.h> |
---|
| 16 | +#include <drm/drm_managed.h> |
---|
21 | 17 | #include <drm/drm_plane_helper.h> |
---|
| 18 | +#include <drm/drm_vblank.h> |
---|
22 | 19 | |
---|
23 | 20 | #include <linux/bitops.h> |
---|
24 | 21 | #include <linux/dma-mapping.h> |
---|
.. | .. |
---|
31 | 28 | #include "rcar_du_drv.h" |
---|
32 | 29 | #include "rcar_du_kms.h" |
---|
33 | 30 | #include "rcar_du_vsp.h" |
---|
| 31 | +#include "rcar_du_writeback.h" |
---|
34 | 32 | |
---|
35 | | -static void rcar_du_vsp_complete(void *private, bool completed, u32 crc) |
---|
| 33 | +static void rcar_du_vsp_complete(void *private, unsigned int status, u32 crc) |
---|
36 | 34 | { |
---|
37 | 35 | struct rcar_du_crtc *crtc = private; |
---|
38 | 36 | |
---|
39 | 37 | if (crtc->vblank_enable) |
---|
40 | 38 | drm_crtc_handle_vblank(&crtc->crtc); |
---|
41 | 39 | |
---|
42 | | - if (completed) |
---|
| 40 | + if (status & VSP1_DU_STATUS_COMPLETE) |
---|
43 | 41 | rcar_du_crtc_finish_page_flip(crtc); |
---|
| 42 | + if (status & VSP1_DU_STATUS_WRITEBACK) |
---|
| 43 | + rcar_du_writeback_complete(crtc); |
---|
44 | 44 | |
---|
45 | 45 | drm_crtc_add_crc_entry(&crtc->crtc, false, 0, &crc); |
---|
46 | 46 | } |
---|
.. | .. |
---|
48 | 48 | void rcar_du_vsp_enable(struct rcar_du_crtc *crtc) |
---|
49 | 49 | { |
---|
50 | 50 | const struct drm_display_mode *mode = &crtc->crtc.state->adjusted_mode; |
---|
51 | | - struct rcar_du_device *rcdu = crtc->group->dev; |
---|
| 51 | + struct rcar_du_device *rcdu = crtc->dev; |
---|
52 | 52 | struct vsp1_du_lif_config cfg = { |
---|
53 | 53 | .width = mode->hdisplay, |
---|
54 | 54 | .height = mode->vdisplay, |
---|
| 55 | + .interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE, |
---|
55 | 56 | .callback = rcar_du_vsp_complete, |
---|
56 | 57 | .callback_data = crtc, |
---|
57 | 58 | }; |
---|
.. | .. |
---|
111 | 112 | state = to_rcar_crtc_state(crtc->crtc.state); |
---|
112 | 113 | cfg.crc = state->crc; |
---|
113 | 114 | |
---|
| 115 | + rcar_du_writeback_setup(crtc, &cfg.writeback); |
---|
| 116 | + |
---|
114 | 117 | vsp1_du_atomic_flush(crtc->vsp->vsp, crtc->vsp_pipe, &cfg); |
---|
115 | 118 | } |
---|
116 | 119 | |
---|
117 | | -/* Keep the two tables in sync. */ |
---|
118 | | -static const u32 formats_kms[] = { |
---|
| 120 | +static const u32 rcar_du_vsp_formats[] = { |
---|
119 | 121 | DRM_FORMAT_RGB332, |
---|
120 | 122 | DRM_FORMAT_ARGB4444, |
---|
121 | 123 | DRM_FORMAT_XRGB4444, |
---|
.. | .. |
---|
129 | 131 | DRM_FORMAT_ARGB8888, |
---|
130 | 132 | DRM_FORMAT_XRGB8888, |
---|
131 | 133 | DRM_FORMAT_UYVY, |
---|
132 | | - DRM_FORMAT_VYUY, |
---|
133 | 134 | DRM_FORMAT_YUYV, |
---|
134 | 135 | DRM_FORMAT_YVYU, |
---|
135 | 136 | DRM_FORMAT_NV12, |
---|
.. | .. |
---|
144 | 145 | DRM_FORMAT_YVU444, |
---|
145 | 146 | }; |
---|
146 | 147 | |
---|
147 | | -static const u32 formats_v4l2[] = { |
---|
148 | | - V4L2_PIX_FMT_RGB332, |
---|
149 | | - V4L2_PIX_FMT_ARGB444, |
---|
150 | | - V4L2_PIX_FMT_XRGB444, |
---|
151 | | - V4L2_PIX_FMT_ARGB555, |
---|
152 | | - V4L2_PIX_FMT_XRGB555, |
---|
153 | | - V4L2_PIX_FMT_RGB565, |
---|
154 | | - V4L2_PIX_FMT_RGB24, |
---|
155 | | - V4L2_PIX_FMT_BGR24, |
---|
156 | | - V4L2_PIX_FMT_ARGB32, |
---|
157 | | - V4L2_PIX_FMT_XRGB32, |
---|
158 | | - V4L2_PIX_FMT_ABGR32, |
---|
159 | | - V4L2_PIX_FMT_XBGR32, |
---|
160 | | - V4L2_PIX_FMT_UYVY, |
---|
161 | | - V4L2_PIX_FMT_VYUY, |
---|
162 | | - V4L2_PIX_FMT_YUYV, |
---|
163 | | - V4L2_PIX_FMT_YVYU, |
---|
164 | | - V4L2_PIX_FMT_NV12M, |
---|
165 | | - V4L2_PIX_FMT_NV21M, |
---|
166 | | - V4L2_PIX_FMT_NV16M, |
---|
167 | | - V4L2_PIX_FMT_NV61M, |
---|
168 | | - V4L2_PIX_FMT_YUV420M, |
---|
169 | | - V4L2_PIX_FMT_YVU420M, |
---|
170 | | - V4L2_PIX_FMT_YUV422M, |
---|
171 | | - V4L2_PIX_FMT_YVU422M, |
---|
172 | | - V4L2_PIX_FMT_YUV444M, |
---|
173 | | - V4L2_PIX_FMT_YVU444M, |
---|
174 | | -}; |
---|
175 | | - |
---|
176 | 148 | static void rcar_du_vsp_plane_setup(struct rcar_du_vsp_plane *plane) |
---|
177 | 149 | { |
---|
178 | 150 | struct rcar_du_vsp_plane_state *state = |
---|
179 | 151 | to_rcar_vsp_plane_state(plane->plane.state); |
---|
180 | 152 | struct rcar_du_crtc *crtc = to_rcar_crtc(state->state.crtc); |
---|
181 | 153 | struct drm_framebuffer *fb = plane->plane.state->fb; |
---|
| 154 | + const struct rcar_du_format_info *format; |
---|
182 | 155 | struct vsp1_du_atomic_config cfg = { |
---|
183 | 156 | .pixelformat = 0, |
---|
184 | 157 | .pitch = fb->pitches[0], |
---|
.. | .. |
---|
201 | 174 | cfg.mem[i] = sg_dma_address(state->sg_tables[i].sgl) |
---|
202 | 175 | + fb->offsets[i]; |
---|
203 | 176 | |
---|
204 | | - for (i = 0; i < ARRAY_SIZE(formats_kms); ++i) { |
---|
205 | | - if (formats_kms[i] == state->format->fourcc) { |
---|
206 | | - cfg.pixelformat = formats_v4l2[i]; |
---|
207 | | - break; |
---|
208 | | - } |
---|
209 | | - } |
---|
| 177 | + format = rcar_du_format_info(state->format->fourcc); |
---|
| 178 | + cfg.pixelformat = format->v4l2; |
---|
210 | 179 | |
---|
211 | 180 | vsp1_du_atomic_update(plane->vsp->vsp, crtc->vsp_pipe, |
---|
212 | 181 | plane->index, &cfg); |
---|
| 182 | +} |
---|
| 183 | + |
---|
| 184 | +int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb, |
---|
| 185 | + struct sg_table sg_tables[3]) |
---|
| 186 | +{ |
---|
| 187 | + struct rcar_du_device *rcdu = vsp->dev; |
---|
| 188 | + unsigned int i; |
---|
| 189 | + int ret; |
---|
| 190 | + |
---|
| 191 | + for (i = 0; i < fb->format->num_planes; ++i) { |
---|
| 192 | + struct drm_gem_cma_object *gem = drm_fb_cma_get_gem_obj(fb, i); |
---|
| 193 | + struct sg_table *sgt = &sg_tables[i]; |
---|
| 194 | + |
---|
| 195 | + ret = dma_get_sgtable(rcdu->dev, sgt, gem->vaddr, gem->paddr, |
---|
| 196 | + gem->base.size); |
---|
| 197 | + if (ret) |
---|
| 198 | + goto fail; |
---|
| 199 | + |
---|
| 200 | + ret = vsp1_du_map_sg(vsp->vsp, sgt); |
---|
| 201 | + if (ret) { |
---|
| 202 | + sg_free_table(sgt); |
---|
| 203 | + goto fail; |
---|
| 204 | + } |
---|
| 205 | + } |
---|
| 206 | + |
---|
| 207 | + return 0; |
---|
| 208 | + |
---|
| 209 | +fail: |
---|
| 210 | + while (i--) { |
---|
| 211 | + struct sg_table *sgt = &sg_tables[i]; |
---|
| 212 | + |
---|
| 213 | + vsp1_du_unmap_sg(vsp->vsp, sgt); |
---|
| 214 | + sg_free_table(sgt); |
---|
| 215 | + } |
---|
| 216 | + |
---|
| 217 | + return ret; |
---|
213 | 218 | } |
---|
214 | 219 | |
---|
215 | 220 | static int rcar_du_vsp_plane_prepare_fb(struct drm_plane *plane, |
---|
.. | .. |
---|
217 | 222 | { |
---|
218 | 223 | struct rcar_du_vsp_plane_state *rstate = to_rcar_vsp_plane_state(state); |
---|
219 | 224 | struct rcar_du_vsp *vsp = to_rcar_vsp_plane(plane)->vsp; |
---|
220 | | - struct rcar_du_device *rcdu = vsp->dev; |
---|
221 | | - unsigned int i; |
---|
222 | 225 | int ret; |
---|
223 | 226 | |
---|
224 | 227 | /* |
---|
.. | .. |
---|
228 | 231 | if (!state->visible) |
---|
229 | 232 | return 0; |
---|
230 | 233 | |
---|
231 | | - for (i = 0; i < rstate->format->planes; ++i) { |
---|
232 | | - struct drm_gem_cma_object *gem = |
---|
233 | | - drm_fb_cma_get_gem_obj(state->fb, i); |
---|
234 | | - struct sg_table *sgt = &rstate->sg_tables[i]; |
---|
| 234 | + ret = rcar_du_vsp_map_fb(vsp, state->fb, rstate->sg_tables); |
---|
| 235 | + if (ret < 0) |
---|
| 236 | + return ret; |
---|
235 | 237 | |
---|
236 | | - ret = dma_get_sgtable(rcdu->dev, sgt, gem->vaddr, gem->paddr, |
---|
237 | | - gem->base.size); |
---|
238 | | - if (ret) |
---|
239 | | - goto fail; |
---|
| 238 | + return drm_gem_fb_prepare_fb(plane, state); |
---|
| 239 | +} |
---|
240 | 240 | |
---|
241 | | - ret = vsp1_du_map_sg(vsp->vsp, sgt); |
---|
242 | | - if (!ret) { |
---|
243 | | - sg_free_table(sgt); |
---|
244 | | - ret = -ENOMEM; |
---|
245 | | - goto fail; |
---|
246 | | - } |
---|
247 | | - } |
---|
| 241 | +void rcar_du_vsp_unmap_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb, |
---|
| 242 | + struct sg_table sg_tables[3]) |
---|
| 243 | +{ |
---|
| 244 | + unsigned int i; |
---|
248 | 245 | |
---|
249 | | - ret = drm_gem_fb_prepare_fb(plane, state); |
---|
250 | | - if (ret) |
---|
251 | | - goto fail; |
---|
252 | | - |
---|
253 | | - return 0; |
---|
254 | | - |
---|
255 | | -fail: |
---|
256 | | - while (i--) { |
---|
257 | | - struct sg_table *sgt = &rstate->sg_tables[i]; |
---|
| 246 | + for (i = 0; i < fb->format->num_planes; ++i) { |
---|
| 247 | + struct sg_table *sgt = &sg_tables[i]; |
---|
258 | 248 | |
---|
259 | 249 | vsp1_du_unmap_sg(vsp->vsp, sgt); |
---|
260 | 250 | sg_free_table(sgt); |
---|
261 | 251 | } |
---|
262 | | - |
---|
263 | | - return ret; |
---|
264 | 252 | } |
---|
265 | 253 | |
---|
266 | 254 | static void rcar_du_vsp_plane_cleanup_fb(struct drm_plane *plane, |
---|
.. | .. |
---|
268 | 256 | { |
---|
269 | 257 | struct rcar_du_vsp_plane_state *rstate = to_rcar_vsp_plane_state(state); |
---|
270 | 258 | struct rcar_du_vsp *vsp = to_rcar_vsp_plane(plane)->vsp; |
---|
271 | | - unsigned int i; |
---|
272 | 259 | |
---|
273 | 260 | if (!state->visible) |
---|
274 | 261 | return; |
---|
275 | 262 | |
---|
276 | | - for (i = 0; i < rstate->format->planes; ++i) { |
---|
277 | | - struct sg_table *sgt = &rstate->sg_tables[i]; |
---|
278 | | - |
---|
279 | | - vsp1_du_unmap_sg(vsp->vsp, sgt); |
---|
280 | | - sg_free_table(sgt); |
---|
281 | | - } |
---|
| 263 | + rcar_du_vsp_unmap_fb(vsp, state->fb, rstate->sg_tables); |
---|
282 | 264 | } |
---|
283 | 265 | |
---|
284 | 266 | static int rcar_du_vsp_plane_atomic_check(struct drm_plane *plane, |
---|
.. | .. |
---|
297 | 279 | |
---|
298 | 280 | if (plane->state->visible) |
---|
299 | 281 | rcar_du_vsp_plane_setup(rplane); |
---|
300 | | - else |
---|
| 282 | + else if (old_state->crtc) |
---|
301 | 283 | vsp1_du_atomic_update(rplane->vsp->vsp, crtc->vsp_pipe, |
---|
302 | 284 | rplane->index, NULL); |
---|
303 | 285 | } |
---|
.. | .. |
---|
346 | 328 | if (state == NULL) |
---|
347 | 329 | return; |
---|
348 | 330 | |
---|
349 | | - state->state.alpha = DRM_BLEND_ALPHA_OPAQUE; |
---|
| 331 | + __drm_atomic_helper_plane_reset(plane, &state->state); |
---|
350 | 332 | state->state.zpos = plane->type == DRM_PLANE_TYPE_PRIMARY ? 0 : 1; |
---|
351 | | - |
---|
352 | | - plane->state = &state->state; |
---|
353 | | - plane->state->plane = plane; |
---|
354 | 333 | } |
---|
355 | 334 | |
---|
356 | 335 | static const struct drm_plane_funcs rcar_du_vsp_plane_funcs = { |
---|
.. | .. |
---|
361 | 340 | .atomic_duplicate_state = rcar_du_vsp_plane_atomic_duplicate_state, |
---|
362 | 341 | .atomic_destroy_state = rcar_du_vsp_plane_atomic_destroy_state, |
---|
363 | 342 | }; |
---|
| 343 | + |
---|
| 344 | +static void rcar_du_vsp_cleanup(struct drm_device *dev, void *res) |
---|
| 345 | +{ |
---|
| 346 | + struct rcar_du_vsp *vsp = res; |
---|
| 347 | + |
---|
| 348 | + put_device(vsp->vsp); |
---|
| 349 | +} |
---|
364 | 350 | |
---|
365 | 351 | int rcar_du_vsp_init(struct rcar_du_vsp *vsp, struct device_node *np, |
---|
366 | 352 | unsigned int crtcs) |
---|
.. | .. |
---|
377 | 363 | return -ENXIO; |
---|
378 | 364 | |
---|
379 | 365 | vsp->vsp = &pdev->dev; |
---|
| 366 | + |
---|
| 367 | + ret = drmm_add_action(rcdu->ddev, rcar_du_vsp_cleanup, vsp); |
---|
| 368 | + if (ret < 0) |
---|
| 369 | + return ret; |
---|
380 | 370 | |
---|
381 | 371 | ret = vsp1_du_init(vsp->vsp); |
---|
382 | 372 | if (ret < 0) |
---|
.. | .. |
---|
404 | 394 | |
---|
405 | 395 | ret = drm_universal_plane_init(rcdu->ddev, &plane->plane, crtcs, |
---|
406 | 396 | &rcar_du_vsp_plane_funcs, |
---|
407 | | - formats_kms, |
---|
408 | | - ARRAY_SIZE(formats_kms), |
---|
| 397 | + rcar_du_vsp_formats, |
---|
| 398 | + ARRAY_SIZE(rcar_du_vsp_formats), |
---|
409 | 399 | NULL, type, NULL); |
---|
410 | 400 | if (ret < 0) |
---|
411 | 401 | return ret; |
---|
.. | .. |
---|
413 | 403 | drm_plane_helper_add(&plane->plane, |
---|
414 | 404 | &rcar_du_vsp_plane_helper_funcs); |
---|
415 | 405 | |
---|
416 | | - if (type == DRM_PLANE_TYPE_PRIMARY) |
---|
417 | | - continue; |
---|
418 | | - |
---|
419 | | - drm_plane_create_alpha_property(&plane->plane); |
---|
420 | | - drm_plane_create_zpos_property(&plane->plane, 1, 1, |
---|
421 | | - vsp->num_planes - 1); |
---|
| 406 | + if (type == DRM_PLANE_TYPE_PRIMARY) { |
---|
| 407 | + drm_plane_create_zpos_immutable_property(&plane->plane, |
---|
| 408 | + 0); |
---|
| 409 | + } else { |
---|
| 410 | + drm_plane_create_alpha_property(&plane->plane); |
---|
| 411 | + drm_plane_create_zpos_property(&plane->plane, 1, 1, |
---|
| 412 | + vsp->num_planes - 1); |
---|
| 413 | + } |
---|
422 | 414 | } |
---|
423 | 415 | |
---|
424 | 416 | return 0; |
---|