aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>2016-04-23 18:08:59 -0400
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2016-06-17 07:16:16 -0400
commitc6b013ab517b0ae09036d50f6b1684d9dbedf596 (patch)
treede8cd068c7b1bbdfdbad6f0c6b3c81e83f400270
parent0c1a41b50805464f397a334a6b2dd95ca6415f32 (diff)
[media] v4l: vsp1: Group DRM RPF parameters in a structure
The vsp1_du_atomic_update_ext() function takes 7 RPF configuration parameters, and more will likely be added later. This makes the code difficult to read and error-prone as multiple parameters have the same type. Make the API safer and easier to extend in the future by grouping all parameters in a structure. Use macro magic to ease the transition to the new function by allowing the old and new functions to be called using the same name. The macros and static inline wrapper will be removed as soon as the caller is updated. Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
-rw-r--r--drivers/media/platform/vsp1/vsp1_drm.c68
-rw-r--r--include/media/vsp1.h47
2 files changed, 64 insertions, 51 deletions
diff --git a/drivers/media/platform/vsp1/vsp1_drm.c b/drivers/media/platform/vsp1/vsp1_drm.c
index fc4bbc401e67..fef53ecefe25 100644
--- a/drivers/media/platform/vsp1/vsp1_drm.c
+++ b/drivers/media/platform/vsp1/vsp1_drm.c
@@ -230,42 +230,33 @@ EXPORT_SYMBOL_GPL(vsp1_du_atomic_begin);
230 * vsp1_du_atomic_update - Setup one RPF input of the VSP pipeline 230 * vsp1_du_atomic_update - Setup one RPF input of the VSP pipeline
231 * @dev: the VSP device 231 * @dev: the VSP device
232 * @rpf_index: index of the RPF to setup (0-based) 232 * @rpf_index: index of the RPF to setup (0-based)
233 * @pixelformat: V4L2 pixel format for the RPF memory input 233 * @cfg: the RPF configuration
234 * @pitch: number of bytes per line in the image stored in memory
235 * @mem: DMA addresses of the memory buffers (one per plane)
236 * @src: the source crop rectangle for the RPF
237 * @dst: the destination compose rectangle for the BRU input
238 * @alpha: global alpha value for the input
239 * @zpos: the Z-order position of the input
240 * 234 *
241 * Configure the VSP to perform composition of the image referenced by @mem 235 * Configure the VSP to perform image composition through RPF @rpf_index as
242 * through RPF @rpf_index, using the @src crop rectangle and the @dst 236 * described by the @cfg configuration. The image to compose is referenced by
237 * @cfg.mem and composed using the @cfg.src crop rectangle and the @cfg.dst
243 * composition rectangle. The Z-order is configurable with higher @zpos values 238 * composition rectangle. The Z-order is configurable with higher @zpos values
244 * displayed on top. 239 * displayed on top.
245 * 240 *
246 * Image format as stored in memory is expressed as a V4L2 @pixelformat value. 241 * If the @cfg configuration is NULL, the RPF will be disabled. Calling the
247 * As a special case, setting the pixel format to 0 will disable the RPF. The
248 * @pitch, @mem, @src and @dst parameters are ignored in that case. Calling the
249 * function on a disabled RPF is allowed. 242 * function on a disabled RPF is allowed.
250 * 243 *
251 * The memory pitch is configurable to allow for padding at end of lines, or 244 * Image format as stored in memory is expressed as a V4L2 @cfg.pixelformat
252 * simple for images that extend beyond the crop rectangle boundaries. The 245 * value. The memory pitch is configurable to allow for padding at end of lines,
253 * @pitch value is expressed in bytes and applies to all planes for multiplanar 246 * or simply for images that extend beyond the crop rectangle boundaries. The
254 * formats. 247 * @cfg.pitch value is expressed in bytes and applies to all planes for
248 * multiplanar formats.
255 * 249 *
256 * The source memory buffer is referenced by the DMA address of its planes in 250 * The source memory buffer is referenced by the DMA address of its planes in
257 * the @mem array. Up to two planes are supported. The second plane DMA address 251 * the @cfg.mem array. Up to two planes are supported. The second plane DMA
258 * is ignored for formats using a single plane. 252 * address is ignored for formats using a single plane.
259 * 253 *
260 * This function isn't reentrant, the caller needs to serialize calls. 254 * This function isn't reentrant, the caller needs to serialize calls.
261 * 255 *
262 * Return 0 on success or a negative error code on failure. 256 * Return 0 on success or a negative error code on failure.
263 */ 257 */
264int vsp1_du_atomic_update_ext(struct device *dev, unsigned int rpf_index, 258int __vsp1_du_atomic_update(struct device *dev, unsigned int rpf_index,
265 u32 pixelformat, unsigned int pitch, 259 const struct vsp1_du_atomic_config *cfg)
266 dma_addr_t mem[2], const struct v4l2_rect *src,
267 const struct v4l2_rect *dst, unsigned int alpha,
268 unsigned int zpos)
269{ 260{
270 struct vsp1_device *vsp1 = dev_get_drvdata(dev); 261 struct vsp1_device *vsp1 = dev_get_drvdata(dev);
271 const struct vsp1_format_info *fmtinfo; 262 const struct vsp1_format_info *fmtinfo;
@@ -276,7 +267,7 @@ int vsp1_du_atomic_update_ext(struct device *dev, unsigned int rpf_index,
276 267
277 rpf = vsp1->rpf[rpf_index]; 268 rpf = vsp1->rpf[rpf_index];
278 269
279 if (pixelformat == 0) { 270 if (!cfg) {
280 dev_dbg(vsp1->dev, "%s: RPF%u: disable requested\n", __func__, 271 dev_dbg(vsp1->dev, "%s: RPF%u: disable requested\n", __func__,
281 rpf_index); 272 rpf_index);
282 273
@@ -287,38 +278,39 @@ int vsp1_du_atomic_update_ext(struct device *dev, unsigned int rpf_index,
287 dev_dbg(vsp1->dev, 278 dev_dbg(vsp1->dev,
288 "%s: RPF%u: (%u,%u)/%ux%u -> (%u,%u)/%ux%u (%08x), pitch %u dma { %pad, %pad } zpos %u\n", 279 "%s: RPF%u: (%u,%u)/%ux%u -> (%u,%u)/%ux%u (%08x), pitch %u dma { %pad, %pad } zpos %u\n",
289 __func__, rpf_index, 280 __func__, rpf_index,
290 src->left, src->top, src->width, src->height, 281 cfg->src.left, cfg->src.top, cfg->src.width, cfg->src.height,
291 dst->left, dst->top, dst->width, dst->height, 282 cfg->dst.left, cfg->dst.top, cfg->dst.width, cfg->dst.height,
292 pixelformat, pitch, &mem[0], &mem[1], zpos); 283 cfg->pixelformat, cfg->pitch, &cfg->mem[0], &cfg->mem[1],
284 cfg->zpos);
293 285
294 /* Store the format, stride, memory buffer address, crop and compose 286 /* Store the format, stride, memory buffer address, crop and compose
295 * rectangles and Z-order position and for the input. 287 * rectangles and Z-order position and for the input.
296 */ 288 */
297 fmtinfo = vsp1_get_format_info(pixelformat); 289 fmtinfo = vsp1_get_format_info(cfg->pixelformat);
298 if (!fmtinfo) { 290 if (!fmtinfo) {
299 dev_dbg(vsp1->dev, "Unsupport pixel format %08x for RPF\n", 291 dev_dbg(vsp1->dev, "Unsupport pixel format %08x for RPF\n",
300 pixelformat); 292 cfg->pixelformat);
301 return -EINVAL; 293 return -EINVAL;
302 } 294 }
303 295
304 rpf->fmtinfo = fmtinfo; 296 rpf->fmtinfo = fmtinfo;
305 rpf->format.num_planes = fmtinfo->planes; 297 rpf->format.num_planes = fmtinfo->planes;
306 rpf->format.plane_fmt[0].bytesperline = pitch; 298 rpf->format.plane_fmt[0].bytesperline = cfg->pitch;
307 rpf->format.plane_fmt[1].bytesperline = pitch; 299 rpf->format.plane_fmt[1].bytesperline = cfg->pitch;
308 rpf->alpha = alpha; 300 rpf->alpha = cfg->alpha;
309 301
310 rpf->mem.addr[0] = mem[0]; 302 rpf->mem.addr[0] = cfg->mem[0];
311 rpf->mem.addr[1] = mem[1]; 303 rpf->mem.addr[1] = cfg->mem[1];
312 rpf->mem.addr[2] = 0; 304 rpf->mem.addr[2] = 0;
313 305
314 vsp1->drm->inputs[rpf_index].crop = *src; 306 vsp1->drm->inputs[rpf_index].crop = cfg->src;
315 vsp1->drm->inputs[rpf_index].compose = *dst; 307 vsp1->drm->inputs[rpf_index].compose = cfg->dst;
316 vsp1->drm->inputs[rpf_index].zpos = zpos; 308 vsp1->drm->inputs[rpf_index].zpos = cfg->zpos;
317 vsp1->drm->inputs[rpf_index].enabled = true; 309 vsp1->drm->inputs[rpf_index].enabled = true;
318 310
319 return 0; 311 return 0;
320} 312}
321EXPORT_SYMBOL_GPL(vsp1_du_atomic_update_ext); 313EXPORT_SYMBOL_GPL(__vsp1_du_atomic_update);
322 314
323static int vsp1_du_setup_rpf_pipe(struct vsp1_device *vsp1, 315static int vsp1_du_setup_rpf_pipe(struct vsp1_device *vsp1,
324 struct vsp1_rwpf *rpf, unsigned int bru_input) 316 struct vsp1_rwpf *rpf, unsigned int bru_input)
diff --git a/include/media/vsp1.h b/include/media/vsp1.h
index 3e654a0455bd..ea8ad7537057 100644
--- a/include/media/vsp1.h
+++ b/include/media/vsp1.h
@@ -14,31 +14,52 @@
14#define __MEDIA_VSP1_H__ 14#define __MEDIA_VSP1_H__
15 15
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/videodev2.h>
17 18
18struct device; 19struct device;
19struct v4l2_rect;
20 20
21int vsp1_du_init(struct device *dev); 21int vsp1_du_init(struct device *dev);
22 22
23int vsp1_du_setup_lif(struct device *dev, unsigned int width, 23int vsp1_du_setup_lif(struct device *dev, unsigned int width,
24 unsigned int height); 24 unsigned int height);
25 25
26struct vsp1_du_atomic_config {
27 u32 pixelformat;
28 unsigned int pitch;
29 dma_addr_t mem[2];
30 struct v4l2_rect src;
31 struct v4l2_rect dst;
32 unsigned int alpha;
33 unsigned int zpos;
34};
35
26void vsp1_du_atomic_begin(struct device *dev); 36void vsp1_du_atomic_begin(struct device *dev);
27int vsp1_du_atomic_update_ext(struct device *dev, unsigned int rpf, 37int __vsp1_du_atomic_update(struct device *dev, unsigned int rpf,
28 u32 pixelformat, unsigned int pitch, 38 const struct vsp1_du_atomic_config *cfg);
29 dma_addr_t mem[2], const struct v4l2_rect *src,
30 const struct v4l2_rect *dst, unsigned int alpha,
31 unsigned int zpos);
32void vsp1_du_atomic_flush(struct device *dev); 39void vsp1_du_atomic_flush(struct device *dev);
33 40
34static inline int vsp1_du_atomic_update(struct device *dev, 41static inline int vsp1_du_atomic_update_old(struct device *dev,
35 unsigned int rpf_index, u32 pixelformat, 42 unsigned int rpf, u32 pixelformat, unsigned int pitch,
36 unsigned int pitch, dma_addr_t mem[2], 43 dma_addr_t mem[2], const struct v4l2_rect *src,
37 const struct v4l2_rect *src, 44 const struct v4l2_rect *dst)
38 const struct v4l2_rect *dst)
39{ 45{
40 return vsp1_du_atomic_update_ext(dev, rpf_index, pixelformat, pitch, 46 struct vsp1_du_atomic_config cfg = {
41 mem, src, dst, 255, 0); 47 .pixelformat = pixelformat,
48 .pitch = pitch,
49 .mem[0] = mem[0],
50 .mem[1] = mem[1],
51 .src = *src,
52 .dst = *dst,
53 .alpha = 255,
54 .zpos = 0,
55 };
56
57 return __vsp1_du_atomic_update(dev, rpf, &cfg);
42} 58}
43 59
60#define _vsp1_du_atomic_update(_1, _2, _3, _4, _5, _6, _7, f, ...) f
61#define vsp1_du_atomic_update(...) \
62 _vsp1_du_atomic_update(__VA_ARGS__, vsp1_du_atomic_update_old, 0, 0, \
63 0, __vsp1_du_atomic_update)(__VA_ARGS__)
64
44#endif /* __MEDIA_VSP1_H__ */ 65#endif /* __MEDIA_VSP1_H__ */