2 * vsp1_wpf.c -- R-Car VSP1 Write Pixel Formatter
4 * Copyright (C) 2013-2014 Renesas Electronics Corporation
6 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
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.
14 #include <linux/device.h>
16 #include <media/v4l2-subdev.h>
20 #include "vsp1_rwpf.h"
21 #include "vsp1_video.h"
23 #define WPF_MAX_WIDTH 2048
24 #define WPF_MAX_HEIGHT 2048
26 /* -----------------------------------------------------------------------------
30 static inline void vsp1_wpf_write(struct vsp1_rwpf *wpf, u32 reg, u32 data)
32 vsp1_mod_write(&wpf->entity,
33 reg + wpf->entity.index * VI6_WPF_OFFSET, data);
36 /* -----------------------------------------------------------------------------
37 * V4L2 Subdevice Core Operations
40 static int wpf_s_stream(struct v4l2_subdev *subdev, int enable)
42 struct vsp1_pipeline *pipe = to_vsp1_pipeline(&subdev->entity);
43 struct vsp1_rwpf *wpf = to_rwpf(subdev);
44 struct vsp1_device *vsp1 = wpf->entity.vsp1;
45 const struct v4l2_rect *crop = &wpf->crop;
51 vsp1_write(vsp1, VI6_WPF_IRQ_ENB(wpf->entity.index), 0);
52 vsp1_write(vsp1, wpf->entity.index * VI6_WPF_OFFSET +
57 /* Sources. If the pipeline has a single input and BRU is not used,
58 * configure it as the master layer. Otherwise configure all
59 * inputs as sub-layers and select the virtual RPF as the master
62 for (i = 0; i < vsp1->info->rpf_count; ++i) {
63 struct vsp1_rwpf *input = pipe->inputs[i];
68 srcrpf |= (!pipe->bru && pipe->num_inputs == 1)
69 ? VI6_WPF_SRCRPF_RPF_ACT_MST(input->entity.index)
70 : VI6_WPF_SRCRPF_RPF_ACT_SUB(input->entity.index);
73 if (pipe->bru || pipe->num_inputs > 1)
74 srcrpf |= VI6_WPF_SRCRPF_VIRACT_MST;
76 vsp1_wpf_write(wpf, VI6_WPF_SRCRPF, srcrpf);
78 /* Destination stride. */
80 struct v4l2_pix_format_mplane *format = &wpf->format;
82 vsp1_wpf_write(wpf, VI6_WPF_DSTM_STRIDE_Y,
83 format->plane_fmt[0].bytesperline);
84 if (format->num_planes > 1)
85 vsp1_wpf_write(wpf, VI6_WPF_DSTM_STRIDE_C,
86 format->plane_fmt[1].bytesperline);
89 vsp1_wpf_write(wpf, VI6_WPF_HSZCLIP, VI6_WPF_SZCLIP_EN |
90 (crop->left << VI6_WPF_SZCLIP_OFST_SHIFT) |
91 (crop->width << VI6_WPF_SZCLIP_SIZE_SHIFT));
92 vsp1_wpf_write(wpf, VI6_WPF_VSZCLIP, VI6_WPF_SZCLIP_EN |
93 (crop->top << VI6_WPF_SZCLIP_OFST_SHIFT) |
94 (crop->height << VI6_WPF_SZCLIP_SIZE_SHIFT));
98 const struct vsp1_format_info *fmtinfo = wpf->fmtinfo;
100 outfmt = fmtinfo->hwfmt << VI6_WPF_OUTFMT_WRFMT_SHIFT;
103 outfmt |= VI6_WPF_OUTFMT_PXA;
104 if (fmtinfo->swap_yc)
105 outfmt |= VI6_WPF_OUTFMT_SPYCS;
106 if (fmtinfo->swap_uv)
107 outfmt |= VI6_WPF_OUTFMT_SPUVS;
109 vsp1_wpf_write(wpf, VI6_WPF_DSWAP, fmtinfo->swap);
112 if (wpf->entity.formats[RWPF_PAD_SINK].code !=
113 wpf->entity.formats[RWPF_PAD_SOURCE].code)
114 outfmt |= VI6_WPF_OUTFMT_CSC;
116 outfmt |= wpf->alpha << VI6_WPF_OUTFMT_PDV_SHIFT;
117 vsp1_wpf_write(wpf, VI6_WPF_OUTFMT, outfmt);
119 vsp1_mod_write(&wpf->entity, VI6_DPR_WPF_FPORCH(wpf->entity.index),
120 VI6_DPR_WPF_FPORCH_FP_WPFN);
122 vsp1_mod_write(&wpf->entity, VI6_WPF_WRBCK_CTRL, 0);
124 /* Enable interrupts */
125 vsp1_write(vsp1, VI6_WPF_IRQ_STA(wpf->entity.index), 0);
126 vsp1_write(vsp1, VI6_WPF_IRQ_ENB(wpf->entity.index),
127 VI6_WFP_IRQ_ENB_FREE);
132 /* -----------------------------------------------------------------------------
133 * V4L2 Subdevice Operations
136 static struct v4l2_subdev_video_ops wpf_video_ops = {
137 .s_stream = wpf_s_stream,
140 static struct v4l2_subdev_pad_ops wpf_pad_ops = {
141 .enum_mbus_code = vsp1_rwpf_enum_mbus_code,
142 .enum_frame_size = vsp1_rwpf_enum_frame_size,
143 .get_fmt = vsp1_rwpf_get_format,
144 .set_fmt = vsp1_rwpf_set_format,
145 .get_selection = vsp1_rwpf_get_selection,
146 .set_selection = vsp1_rwpf_set_selection,
149 static struct v4l2_subdev_ops wpf_ops = {
150 .video = &wpf_video_ops,
154 /* -----------------------------------------------------------------------------
155 * Video Device Operations
158 static void wpf_set_memory(struct vsp1_rwpf *wpf)
160 vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_Y, wpf->buf_addr[0]);
161 vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_C0, wpf->buf_addr[1]);
162 vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_C1, wpf->buf_addr[2]);
165 static const struct vsp1_rwpf_operations wpf_vdev_ops = {
166 .set_memory = wpf_set_memory,
169 /* -----------------------------------------------------------------------------
170 * Initialization and Cleanup
173 static void vsp1_wpf_destroy(struct vsp1_entity *entity)
175 struct vsp1_rwpf *wpf = container_of(entity, struct vsp1_rwpf, entity);
177 vsp1_dlm_destroy(wpf->dlm);
180 struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index)
182 struct v4l2_subdev *subdev;
183 struct vsp1_rwpf *wpf;
186 wpf = devm_kzalloc(vsp1->dev, sizeof(*wpf), GFP_KERNEL);
188 return ERR_PTR(-ENOMEM);
190 wpf->ops = &wpf_vdev_ops;
192 wpf->max_width = WPF_MAX_WIDTH;
193 wpf->max_height = WPF_MAX_HEIGHT;
195 wpf->entity.destroy = vsp1_wpf_destroy;
196 wpf->entity.type = VSP1_ENTITY_WPF;
197 wpf->entity.index = index;
199 ret = vsp1_entity_init(vsp1, &wpf->entity, 2);
203 /* Initialize the display list manager if the WPF is used for display */
204 if ((vsp1->info->features & VSP1_HAS_LIF) && index == 0) {
205 wpf->dlm = vsp1_dlm_create(vsp1, index, 4);
212 /* Initialize the V4L2 subdev. */
213 subdev = &wpf->entity.subdev;
214 v4l2_subdev_init(subdev, &wpf_ops);
216 subdev->entity.ops = &vsp1->media_ops;
217 subdev->internal_ops = &vsp1_subdev_internal_ops;
218 snprintf(subdev->name, sizeof(subdev->name), "%s wpf.%u",
219 dev_name(vsp1->dev), index);
220 v4l2_set_subdevdata(subdev, wpf);
221 subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
223 vsp1_entity_init_formats(subdev, NULL);
225 /* Initialize the control handler. */
226 ret = vsp1_rwpf_init_ctrls(wpf);
228 dev_err(vsp1->dev, "wpf%u: failed to initialize controls\n",
236 vsp1_entity_destroy(&wpf->entity);