d68c90d45232851a04cf526258e280c82b97861e
[deliverable/linux.git] / drivers / media / platform / vsp1 / vsp1_wpf.c
1 /*
2 * vsp1_wpf.c -- R-Car VSP1 Write Pixel Formatter
3 *
4 * Copyright (C) 2013-2014 Renesas Electronics Corporation
5 *
6 * 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 */
13
14 #include <linux/device.h>
15
16 #include <media/v4l2-subdev.h>
17
18 #include "vsp1.h"
19 #include "vsp1_dl.h"
20 #include "vsp1_rwpf.h"
21 #include "vsp1_video.h"
22
23 #define WPF_MAX_WIDTH 2048
24 #define WPF_MAX_HEIGHT 2048
25
26 /* -----------------------------------------------------------------------------
27 * Device Access
28 */
29
30 static inline void vsp1_wpf_write(struct vsp1_rwpf *wpf, u32 reg, u32 data)
31 {
32 vsp1_mod_write(&wpf->entity,
33 reg + wpf->entity.index * VI6_WPF_OFFSET, data);
34 }
35
36 /* -----------------------------------------------------------------------------
37 * V4L2 Subdevice Core Operations
38 */
39
40 static int wpf_s_stream(struct v4l2_subdev *subdev, int enable)
41 {
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;
46 unsigned int i;
47 u32 srcrpf = 0;
48 u32 outfmt = 0;
49
50 vsp1_entity_set_streaming(&wpf->entity, enable);
51
52 if (!enable) {
53 vsp1_write(vsp1, VI6_WPF_IRQ_ENB(wpf->entity.index), 0);
54 vsp1_write(vsp1, wpf->entity.index * VI6_WPF_OFFSET +
55 VI6_WPF_SRCRPF, 0);
56 return 0;
57 }
58
59 /* Sources. If the pipeline has a single input and BRU is not used,
60 * configure it as the master layer. Otherwise configure all
61 * inputs as sub-layers and select the virtual RPF as the master
62 * layer.
63 */
64 for (i = 0; i < vsp1->info->rpf_count; ++i) {
65 struct vsp1_rwpf *input = pipe->inputs[i];
66
67 if (!input)
68 continue;
69
70 srcrpf |= (!pipe->bru && pipe->num_inputs == 1)
71 ? VI6_WPF_SRCRPF_RPF_ACT_MST(input->entity.index)
72 : VI6_WPF_SRCRPF_RPF_ACT_SUB(input->entity.index);
73 }
74
75 if (pipe->bru || pipe->num_inputs > 1)
76 srcrpf |= VI6_WPF_SRCRPF_VIRACT_MST;
77
78 vsp1_wpf_write(wpf, VI6_WPF_SRCRPF, srcrpf);
79
80 /* Destination stride. */
81 if (!pipe->lif) {
82 struct v4l2_pix_format_mplane *format = &wpf->format;
83
84 vsp1_wpf_write(wpf, VI6_WPF_DSTM_STRIDE_Y,
85 format->plane_fmt[0].bytesperline);
86 if (format->num_planes > 1)
87 vsp1_wpf_write(wpf, VI6_WPF_DSTM_STRIDE_C,
88 format->plane_fmt[1].bytesperline);
89 }
90
91 vsp1_wpf_write(wpf, VI6_WPF_HSZCLIP, VI6_WPF_SZCLIP_EN |
92 (crop->left << VI6_WPF_SZCLIP_OFST_SHIFT) |
93 (crop->width << VI6_WPF_SZCLIP_SIZE_SHIFT));
94 vsp1_wpf_write(wpf, VI6_WPF_VSZCLIP, VI6_WPF_SZCLIP_EN |
95 (crop->top << VI6_WPF_SZCLIP_OFST_SHIFT) |
96 (crop->height << VI6_WPF_SZCLIP_SIZE_SHIFT));
97
98 /* Format */
99 if (!pipe->lif) {
100 const struct vsp1_format_info *fmtinfo = wpf->fmtinfo;
101
102 outfmt = fmtinfo->hwfmt << VI6_WPF_OUTFMT_WRFMT_SHIFT;
103
104 if (fmtinfo->alpha)
105 outfmt |= VI6_WPF_OUTFMT_PXA;
106 if (fmtinfo->swap_yc)
107 outfmt |= VI6_WPF_OUTFMT_SPYCS;
108 if (fmtinfo->swap_uv)
109 outfmt |= VI6_WPF_OUTFMT_SPUVS;
110
111 vsp1_wpf_write(wpf, VI6_WPF_DSWAP, fmtinfo->swap);
112 }
113
114 if (wpf->entity.formats[RWPF_PAD_SINK].code !=
115 wpf->entity.formats[RWPF_PAD_SOURCE].code)
116 outfmt |= VI6_WPF_OUTFMT_CSC;
117
118 outfmt |= wpf->alpha << VI6_WPF_OUTFMT_PDV_SHIFT;
119 vsp1_wpf_write(wpf, VI6_WPF_OUTFMT, outfmt);
120
121 vsp1_mod_write(&wpf->entity, VI6_DPR_WPF_FPORCH(wpf->entity.index),
122 VI6_DPR_WPF_FPORCH_FP_WPFN);
123
124 vsp1_mod_write(&wpf->entity, VI6_WPF_WRBCK_CTRL, 0);
125
126 /* Enable interrupts */
127 vsp1_write(vsp1, VI6_WPF_IRQ_STA(wpf->entity.index), 0);
128 vsp1_write(vsp1, VI6_WPF_IRQ_ENB(wpf->entity.index),
129 VI6_WFP_IRQ_ENB_FREE);
130
131 return 0;
132 }
133
134 /* -----------------------------------------------------------------------------
135 * V4L2 Subdevice Operations
136 */
137
138 static struct v4l2_subdev_video_ops wpf_video_ops = {
139 .s_stream = wpf_s_stream,
140 };
141
142 static struct v4l2_subdev_pad_ops wpf_pad_ops = {
143 .enum_mbus_code = vsp1_rwpf_enum_mbus_code,
144 .enum_frame_size = vsp1_rwpf_enum_frame_size,
145 .get_fmt = vsp1_rwpf_get_format,
146 .set_fmt = vsp1_rwpf_set_format,
147 .get_selection = vsp1_rwpf_get_selection,
148 .set_selection = vsp1_rwpf_set_selection,
149 };
150
151 static struct v4l2_subdev_ops wpf_ops = {
152 .video = &wpf_video_ops,
153 .pad = &wpf_pad_ops,
154 };
155
156 /* -----------------------------------------------------------------------------
157 * Video Device Operations
158 */
159
160 static void wpf_set_memory(struct vsp1_rwpf *wpf, struct vsp1_rwpf_memory *mem)
161 {
162 vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_Y, mem->addr[0]);
163 if (mem->num_planes > 1)
164 vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_C0, mem->addr[1]);
165 if (mem->num_planes > 2)
166 vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_C1, mem->addr[2]);
167 }
168
169 static const struct vsp1_rwpf_operations wpf_vdev_ops = {
170 .set_memory = wpf_set_memory,
171 };
172
173 /* -----------------------------------------------------------------------------
174 * Initialization and Cleanup
175 */
176
177 static void vsp1_wpf_destroy(struct vsp1_entity *entity)
178 {
179 struct vsp1_rwpf *wpf = container_of(entity, struct vsp1_rwpf, entity);
180
181 vsp1_dlm_destroy(wpf->dlm);
182 }
183
184 struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index)
185 {
186 struct v4l2_subdev *subdev;
187 struct vsp1_rwpf *wpf;
188 int ret;
189
190 wpf = devm_kzalloc(vsp1->dev, sizeof(*wpf), GFP_KERNEL);
191 if (wpf == NULL)
192 return ERR_PTR(-ENOMEM);
193
194 wpf->ops = &wpf_vdev_ops;
195
196 wpf->max_width = WPF_MAX_WIDTH;
197 wpf->max_height = WPF_MAX_HEIGHT;
198
199 wpf->entity.destroy = vsp1_wpf_destroy;
200 wpf->entity.type = VSP1_ENTITY_WPF;
201 wpf->entity.index = index;
202
203 ret = vsp1_entity_init(vsp1, &wpf->entity, 2);
204 if (ret < 0)
205 return ERR_PTR(ret);
206
207 /* Initialize the display list manager if the WPF is used for display */
208 if ((vsp1->info->features & VSP1_HAS_LIF) && index == 0) {
209 wpf->dlm = vsp1_dlm_create(vsp1, 4);
210 if (!wpf->dlm) {
211 ret = -ENOMEM;
212 goto error;
213 }
214 }
215
216 /* Initialize the V4L2 subdev. */
217 subdev = &wpf->entity.subdev;
218 v4l2_subdev_init(subdev, &wpf_ops);
219
220 subdev->entity.ops = &vsp1->media_ops;
221 subdev->internal_ops = &vsp1_subdev_internal_ops;
222 snprintf(subdev->name, sizeof(subdev->name), "%s wpf.%u",
223 dev_name(vsp1->dev), index);
224 v4l2_set_subdevdata(subdev, wpf);
225 subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
226
227 vsp1_entity_init_formats(subdev, NULL);
228
229 /* Initialize the control handler. */
230 ret = vsp1_rwpf_init_ctrls(wpf);
231 if (ret < 0) {
232 dev_err(vsp1->dev, "wpf%u: failed to initialize controls\n",
233 index);
234 goto error;
235 }
236
237 return wpf;
238
239 error:
240 vsp1_entity_destroy(&wpf->entity);
241 return ERR_PTR(ret);
242 }
This page took 0.04897 seconds and 4 git commands to generate.