Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 1 | /* |
| 2 | * vsp1_wpf.c -- R-Car VSP1 Write Pixel Formatter |
| 3 | * |
Laurent Pinchart | 8a1edc5 | 2014-02-06 14:42:31 -0300 | [diff] [blame] | 4 | * Copyright (C) 2013-2014 Renesas Electronics Corporation |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 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" |
Laurent Pinchart | ef9621b | 2015-11-14 22:27:52 -0200 | [diff] [blame] | 19 | #include "vsp1_dl.h" |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 20 | #include "vsp1_pipe.h" |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 21 | #include "vsp1_rwpf.h" |
| 22 | #include "vsp1_video.h" |
| 23 | |
Laurent Pinchart | 0d268dc | 2016-03-25 06:51:06 -0300 | [diff] [blame] | 24 | #define WPF_GEN2_MAX_WIDTH 2048U |
| 25 | #define WPF_GEN2_MAX_HEIGHT 2048U |
| 26 | #define WPF_GEN3_MAX_WIDTH 8190U |
| 27 | #define WPF_GEN3_MAX_HEIGHT 8190U |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 28 | |
| 29 | /* ----------------------------------------------------------------------------- |
| 30 | * Device Access |
| 31 | */ |
| 32 | |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 33 | static inline void vsp1_wpf_write(struct vsp1_rwpf *wpf, |
| 34 | struct vsp1_dl_list *dl, u32 reg, u32 data) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 35 | { |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 36 | vsp1_dl_list_write(dl, reg + wpf->entity.index * VI6_WPF_OFFSET, data); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | 894dde5 | 2016-05-26 05:14:22 -0300 | [diff] [blame] | 40 | * Controls |
| 41 | */ |
| 42 | |
| 43 | enum wpf_flip_ctrl { |
| 44 | WPF_CTRL_VFLIP = 0, |
| 45 | WPF_CTRL_HFLIP = 1, |
| 46 | WPF_CTRL_MAX, |
| 47 | }; |
| 48 | |
| 49 | static int vsp1_wpf_s_ctrl(struct v4l2_ctrl *ctrl) |
| 50 | { |
| 51 | struct vsp1_rwpf *wpf = |
| 52 | container_of(ctrl->handler, struct vsp1_rwpf, ctrls); |
| 53 | unsigned int i; |
| 54 | u32 flip = 0; |
| 55 | |
| 56 | switch (ctrl->id) { |
| 57 | case V4L2_CID_HFLIP: |
| 58 | case V4L2_CID_VFLIP: |
| 59 | for (i = 0; i < WPF_CTRL_MAX; ++i) { |
| 60 | if (wpf->flip.ctrls[i]) |
| 61 | flip |= wpf->flip.ctrls[i]->val ? BIT(i) : 0; |
| 62 | } |
| 63 | |
| 64 | spin_lock_irq(&wpf->flip.lock); |
| 65 | wpf->flip.pending = flip; |
| 66 | spin_unlock_irq(&wpf->flip.lock); |
| 67 | break; |
| 68 | |
| 69 | default: |
| 70 | return -EINVAL; |
| 71 | } |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | static const struct v4l2_ctrl_ops vsp1_wpf_ctrl_ops = { |
| 77 | .s_ctrl = vsp1_wpf_s_ctrl, |
| 78 | }; |
| 79 | |
| 80 | static int wpf_init_controls(struct vsp1_rwpf *wpf) |
| 81 | { |
| 82 | struct vsp1_device *vsp1 = wpf->entity.vsp1; |
| 83 | unsigned int num_flip_ctrls; |
| 84 | |
| 85 | spin_lock_init(&wpf->flip.lock); |
| 86 | |
| 87 | if (wpf->entity.index != 0) { |
| 88 | /* Only WPF0 supports flipping. */ |
| 89 | num_flip_ctrls = 0; |
| 90 | } else if (vsp1->info->features & VSP1_HAS_WPF_HFLIP) { |
| 91 | /* When horizontal flip is supported the WPF implements two |
| 92 | * controls (horizontal flip and vertical flip). |
| 93 | */ |
| 94 | num_flip_ctrls = 2; |
| 95 | } else if (vsp1->info->features & VSP1_HAS_WPF_VFLIP) { |
| 96 | /* When only vertical flip is supported the WPF implements a |
| 97 | * single control (vertical flip). |
| 98 | */ |
| 99 | num_flip_ctrls = 1; |
| 100 | } else { |
| 101 | /* Otherwise flipping is not supported. */ |
| 102 | num_flip_ctrls = 0; |
| 103 | } |
| 104 | |
| 105 | vsp1_rwpf_init_ctrls(wpf, num_flip_ctrls); |
| 106 | |
| 107 | if (num_flip_ctrls >= 1) { |
| 108 | wpf->flip.ctrls[WPF_CTRL_VFLIP] = |
| 109 | v4l2_ctrl_new_std(&wpf->ctrls, &vsp1_wpf_ctrl_ops, |
| 110 | V4L2_CID_VFLIP, 0, 1, 1, 0); |
| 111 | } |
| 112 | |
| 113 | if (num_flip_ctrls == 2) { |
| 114 | wpf->flip.ctrls[WPF_CTRL_HFLIP] = |
| 115 | v4l2_ctrl_new_std(&wpf->ctrls, &vsp1_wpf_ctrl_ops, |
| 116 | V4L2_CID_HFLIP, 0, 1, 1, 0); |
| 117 | |
| 118 | v4l2_ctrl_cluster(2, wpf->flip.ctrls); |
| 119 | } |
| 120 | |
| 121 | if (wpf->ctrls.error) { |
| 122 | dev_err(vsp1->dev, "wpf%u: failed to initialize controls\n", |
| 123 | wpf->entity.index); |
| 124 | return wpf->ctrls.error; |
| 125 | } |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 131 | * V4L2 Subdevice Core Operations |
| 132 | */ |
| 133 | |
| 134 | static int wpf_s_stream(struct v4l2_subdev *subdev, int enable) |
| 135 | { |
| 136 | struct vsp1_rwpf *wpf = to_rwpf(subdev); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 137 | struct vsp1_device *vsp1 = wpf->entity.vsp1; |
Laurent Pinchart | 7578c20 | 2014-05-21 19:00:05 -0300 | [diff] [blame] | 138 | |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 139 | if (enable) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 140 | return 0; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 141 | |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 142 | /* Write to registers directly when stopping the stream as there will be |
| 143 | * no pipeline run to apply the display list. |
Laurent Pinchart | 629bb6d | 2013-07-10 18:03:46 -0300 | [diff] [blame] | 144 | */ |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 145 | vsp1_write(vsp1, VI6_WPF_IRQ_ENB(wpf->entity.index), 0); |
| 146 | vsp1_write(vsp1, wpf->entity.index * VI6_WPF_OFFSET + |
| 147 | VI6_WPF_SRCRPF, 0); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | /* ----------------------------------------------------------------------------- |
| 153 | * V4L2 Subdevice Operations |
| 154 | */ |
| 155 | |
Laurent Pinchart | eb9163d | 2016-06-17 21:11:26 -0300 | [diff] [blame] | 156 | static const struct v4l2_subdev_video_ops wpf_video_ops = { |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 157 | .s_stream = wpf_s_stream, |
| 158 | }; |
| 159 | |
Laurent Pinchart | eb9163d | 2016-06-17 21:11:26 -0300 | [diff] [blame] | 160 | static const struct v4l2_subdev_ops wpf_ops = { |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 161 | .video = &wpf_video_ops, |
Laurent Pinchart | c6c8efb | 2015-11-22 13:37:45 -0200 | [diff] [blame] | 162 | .pad = &vsp1_rwpf_pad_ops, |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | 5243453 | 2015-11-17 12:23:23 -0200 | [diff] [blame] | 166 | * VSP1 Entity Operations |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 167 | */ |
| 168 | |
Laurent Pinchart | 5243453 | 2015-11-17 12:23:23 -0200 | [diff] [blame] | 169 | static void vsp1_wpf_destroy(struct vsp1_entity *entity) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 170 | { |
Laurent Pinchart | 5243453 | 2015-11-17 12:23:23 -0200 | [diff] [blame] | 171 | struct vsp1_rwpf *wpf = entity_to_rwpf(entity); |
| 172 | |
| 173 | vsp1_dlm_destroy(wpf->dlm); |
| 174 | } |
| 175 | |
Laurent Pinchart | 83dd019 | 2016-01-14 14:17:32 -0200 | [diff] [blame] | 176 | static void wpf_configure(struct vsp1_entity *entity, |
| 177 | struct vsp1_pipeline *pipe, |
Laurent Pinchart | d21fbbb | 2016-09-11 19:39:30 -0300 | [diff] [blame] | 178 | struct vsp1_dl_list *dl, |
| 179 | enum vsp1_entity_params params) |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 180 | { |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 181 | struct vsp1_rwpf *wpf = to_rwpf(&entity->subdev); |
| 182 | struct vsp1_device *vsp1 = wpf->entity.vsp1; |
| 183 | const struct v4l2_mbus_framefmt *source_format; |
| 184 | const struct v4l2_mbus_framefmt *sink_format; |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 185 | unsigned int i; |
| 186 | u32 outfmt = 0; |
| 187 | u32 srcrpf = 0; |
| 188 | |
Laurent Pinchart | d21fbbb | 2016-09-11 19:39:30 -0300 | [diff] [blame] | 189 | if (params == VSP1_ENTITY_PARAMS_RUNTIME) { |
Laurent Pinchart | 894dde5 | 2016-05-26 05:14:22 -0300 | [diff] [blame] | 190 | const unsigned int mask = BIT(WPF_CTRL_VFLIP) |
| 191 | | BIT(WPF_CTRL_HFLIP); |
Laurent Pinchart | 225c292 | 2016-09-13 20:19:29 -0300 | [diff] [blame] | 192 | unsigned long flags; |
Laurent Pinchart | 894dde5 | 2016-05-26 05:14:22 -0300 | [diff] [blame] | 193 | |
Laurent Pinchart | 225c292 | 2016-09-13 20:19:29 -0300 | [diff] [blame] | 194 | spin_lock_irqsave(&wpf->flip.lock, flags); |
Laurent Pinchart | 894dde5 | 2016-05-26 05:14:22 -0300 | [diff] [blame] | 195 | wpf->flip.active = (wpf->flip.active & ~mask) |
| 196 | | (wpf->flip.pending & mask); |
Laurent Pinchart | 225c292 | 2016-09-13 20:19:29 -0300 | [diff] [blame] | 197 | spin_unlock_irqrestore(&wpf->flip.lock, flags); |
Laurent Pinchart | 894dde5 | 2016-05-26 05:14:22 -0300 | [diff] [blame] | 198 | |
| 199 | outfmt = (wpf->alpha << VI6_WPF_OUTFMT_PDV_SHIFT) | wpf->outfmt; |
| 200 | |
| 201 | if (wpf->flip.active & BIT(WPF_CTRL_VFLIP)) |
| 202 | outfmt |= VI6_WPF_OUTFMT_FLP; |
| 203 | if (wpf->flip.active & BIT(WPF_CTRL_HFLIP)) |
| 204 | outfmt |= VI6_WPF_OUTFMT_HFLP; |
| 205 | |
| 206 | vsp1_wpf_write(wpf, dl, VI6_WPF_OUTFMT, outfmt); |
Laurent Pinchart | fc845e5 | 2016-06-11 04:07:56 -0300 | [diff] [blame] | 207 | return; |
Laurent Pinchart | d05a331 | 2016-06-20 05:04:38 -0300 | [diff] [blame] | 208 | } |
Laurent Pinchart | fc845e5 | 2016-06-11 04:07:56 -0300 | [diff] [blame] | 209 | |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 210 | sink_format = vsp1_entity_get_pad_format(&wpf->entity, |
| 211 | wpf->entity.config, |
| 212 | RWPF_PAD_SINK); |
| 213 | source_format = vsp1_entity_get_pad_format(&wpf->entity, |
| 214 | wpf->entity.config, |
| 215 | RWPF_PAD_SOURCE); |
| 216 | |
Laurent Pinchart | 8ddf378 | 2016-09-12 09:50:13 -0300 | [diff] [blame] | 217 | if (params == VSP1_ENTITY_PARAMS_PARTITION) { |
| 218 | const struct v4l2_pix_format_mplane *format = &wpf->format; |
Laurent Pinchart | 3425382 | 2017-02-12 20:58:20 -0200 | [diff] [blame] | 219 | const struct vsp1_format_info *fmtinfo = wpf->fmtinfo; |
Laurent Pinchart | 8ddf378 | 2016-09-12 09:50:13 -0300 | [diff] [blame] | 220 | struct vsp1_rwpf_memory mem = wpf->mem; |
| 221 | unsigned int flip = wpf->flip.active; |
| 222 | unsigned int width = source_format->width; |
| 223 | unsigned int height = source_format->height; |
| 224 | unsigned int offset; |
Laurent Pinchart | b61bead | 2016-09-11 22:41:06 -0300 | [diff] [blame] | 225 | |
Mauro Carvalho Chehab | b618739 | 2016-09-19 15:18:01 -0300 | [diff] [blame] | 226 | /* |
| 227 | * Cropping. The partition algorithm can split the image into |
Laurent Pinchart | 8ddf378 | 2016-09-12 09:50:13 -0300 | [diff] [blame] | 228 | * multiple slices. |
| 229 | */ |
Kieran Bingham | fc6e514 | 2016-09-11 23:26:35 -0300 | [diff] [blame] | 230 | if (pipe->partitions > 1) |
| 231 | width = pipe->partition.width; |
| 232 | |
Laurent Pinchart | 8ddf378 | 2016-09-12 09:50:13 -0300 | [diff] [blame] | 233 | vsp1_wpf_write(wpf, dl, VI6_WPF_HSZCLIP, VI6_WPF_SZCLIP_EN | |
| 234 | (0 << VI6_WPF_SZCLIP_OFST_SHIFT) | |
| 235 | (width << VI6_WPF_SZCLIP_SIZE_SHIFT)); |
| 236 | vsp1_wpf_write(wpf, dl, VI6_WPF_VSZCLIP, VI6_WPF_SZCLIP_EN | |
| 237 | (0 << VI6_WPF_SZCLIP_OFST_SHIFT) | |
| 238 | (height << VI6_WPF_SZCLIP_SIZE_SHIFT)); |
| 239 | |
| 240 | if (pipe->lif) |
| 241 | return; |
| 242 | |
Mauro Carvalho Chehab | b618739 | 2016-09-19 15:18:01 -0300 | [diff] [blame] | 243 | /* |
| 244 | * Update the memory offsets based on flipping configuration. |
Laurent Pinchart | 8ddf378 | 2016-09-12 09:50:13 -0300 | [diff] [blame] | 245 | * The destination addresses point to the locations where the |
| 246 | * VSP starts writing to memory, which can be different corners |
Kieran Bingham | fc6e514 | 2016-09-11 23:26:35 -0300 | [diff] [blame] | 247 | * of the image depending on vertical flipping. |
Laurent Pinchart | 8ddf378 | 2016-09-12 09:50:13 -0300 | [diff] [blame] | 248 | */ |
Kieran Bingham | fc6e514 | 2016-09-11 23:26:35 -0300 | [diff] [blame] | 249 | if (pipe->partitions > 1) { |
| 250 | const struct vsp1_format_info *fmtinfo = wpf->fmtinfo; |
| 251 | |
Mauro Carvalho Chehab | b618739 | 2016-09-19 15:18:01 -0300 | [diff] [blame] | 252 | /* |
| 253 | * Horizontal flipping is handled through a line buffer |
Kieran Bingham | fc6e514 | 2016-09-11 23:26:35 -0300 | [diff] [blame] | 254 | * and doesn't modify the start address, but still needs |
| 255 | * to be handled when image partitioning is in effect to |
| 256 | * order the partitions correctly. |
| 257 | */ |
| 258 | if (flip & BIT(WPF_CTRL_HFLIP)) |
| 259 | offset = format->width - pipe->partition.left |
| 260 | - pipe->partition.width; |
| 261 | else |
| 262 | offset = pipe->partition.left; |
| 263 | |
| 264 | mem.addr[0] += offset * fmtinfo->bpp[0] / 8; |
| 265 | if (format->num_planes > 1) { |
| 266 | mem.addr[1] += offset / fmtinfo->hsub |
| 267 | * fmtinfo->bpp[1] / 8; |
| 268 | mem.addr[2] += offset / fmtinfo->hsub |
| 269 | * fmtinfo->bpp[2] / 8; |
| 270 | } |
| 271 | } |
| 272 | |
Laurent Pinchart | 8ddf378 | 2016-09-12 09:50:13 -0300 | [diff] [blame] | 273 | if (flip & BIT(WPF_CTRL_VFLIP)) { |
| 274 | mem.addr[0] += (format->height - 1) |
| 275 | * format->plane_fmt[0].bytesperline; |
| 276 | |
| 277 | if (format->num_planes > 1) { |
| 278 | offset = (format->height / wpf->fmtinfo->vsub - 1) |
| 279 | * format->plane_fmt[1].bytesperline; |
| 280 | mem.addr[1] += offset; |
| 281 | mem.addr[2] += offset; |
| 282 | } |
| 283 | } |
| 284 | |
Laurent Pinchart | 3425382 | 2017-02-12 20:58:20 -0200 | [diff] [blame] | 285 | /* |
| 286 | * On Gen3 hardware the SPUVS bit has no effect on 3-planar |
| 287 | * formats. Swap the U and V planes manually in that case. |
| 288 | */ |
| 289 | if (vsp1->info->gen == 3 && format->num_planes == 3 && |
| 290 | fmtinfo->swap_uv) |
| 291 | swap(mem.addr[1], mem.addr[2]); |
| 292 | |
Laurent Pinchart | 8ddf378 | 2016-09-12 09:50:13 -0300 | [diff] [blame] | 293 | vsp1_wpf_write(wpf, dl, VI6_WPF_DSTM_ADDR_Y, mem.addr[0]); |
| 294 | vsp1_wpf_write(wpf, dl, VI6_WPF_DSTM_ADDR_C0, mem.addr[1]); |
| 295 | vsp1_wpf_write(wpf, dl, VI6_WPF_DSTM_ADDR_C1, mem.addr[2]); |
| 296 | return; |
| 297 | } |
| 298 | |
| 299 | /* Format */ |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 300 | if (!pipe->lif) { |
| 301 | const struct v4l2_pix_format_mplane *format = &wpf->format; |
| 302 | const struct vsp1_format_info *fmtinfo = wpf->fmtinfo; |
| 303 | |
| 304 | outfmt = fmtinfo->hwfmt << VI6_WPF_OUTFMT_WRFMT_SHIFT; |
| 305 | |
| 306 | if (fmtinfo->alpha) |
| 307 | outfmt |= VI6_WPF_OUTFMT_PXA; |
| 308 | if (fmtinfo->swap_yc) |
| 309 | outfmt |= VI6_WPF_OUTFMT_SPYCS; |
| 310 | if (fmtinfo->swap_uv) |
| 311 | outfmt |= VI6_WPF_OUTFMT_SPUVS; |
| 312 | |
| 313 | /* Destination stride and byte swapping. */ |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 314 | vsp1_wpf_write(wpf, dl, VI6_WPF_DSTM_STRIDE_Y, |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 315 | format->plane_fmt[0].bytesperline); |
| 316 | if (format->num_planes > 1) |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 317 | vsp1_wpf_write(wpf, dl, VI6_WPF_DSTM_STRIDE_C, |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 318 | format->plane_fmt[1].bytesperline); |
| 319 | |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 320 | vsp1_wpf_write(wpf, dl, VI6_WPF_DSWAP, fmtinfo->swap); |
Laurent Pinchart | 894dde5 | 2016-05-26 05:14:22 -0300 | [diff] [blame] | 321 | |
| 322 | if (vsp1->info->features & VSP1_HAS_WPF_HFLIP && |
| 323 | wpf->entity.index == 0) |
| 324 | vsp1_wpf_write(wpf, dl, VI6_WPF_ROT_CTRL, |
| 325 | VI6_WPF_ROT_CTRL_LN16 | |
| 326 | (256 << VI6_WPF_ROT_CTRL_LMEM_WD_SHIFT)); |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | if (sink_format->code != source_format->code) |
| 330 | outfmt |= VI6_WPF_OUTFMT_CSC; |
| 331 | |
Laurent Pinchart | d05a331 | 2016-06-20 05:04:38 -0300 | [diff] [blame] | 332 | wpf->outfmt = outfmt; |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 333 | |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 334 | vsp1_dl_list_write(dl, VI6_DPR_WPF_FPORCH(wpf->entity.index), |
| 335 | VI6_DPR_WPF_FPORCH_FP_WPFN); |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 336 | |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 337 | vsp1_dl_list_write(dl, VI6_WPF_WRBCK_CTRL, 0); |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 338 | |
| 339 | /* Sources. If the pipeline has a single input and BRU is not used, |
| 340 | * configure it as the master layer. Otherwise configure all |
| 341 | * inputs as sub-layers and select the virtual RPF as the master |
| 342 | * layer. |
| 343 | */ |
| 344 | for (i = 0; i < vsp1->info->rpf_count; ++i) { |
| 345 | struct vsp1_rwpf *input = pipe->inputs[i]; |
| 346 | |
| 347 | if (!input) |
| 348 | continue; |
| 349 | |
| 350 | srcrpf |= (!pipe->bru && pipe->num_inputs == 1) |
| 351 | ? VI6_WPF_SRCRPF_RPF_ACT_MST(input->entity.index) |
| 352 | : VI6_WPF_SRCRPF_RPF_ACT_SUB(input->entity.index); |
| 353 | } |
| 354 | |
| 355 | if (pipe->bru || pipe->num_inputs > 1) |
| 356 | srcrpf |= VI6_WPF_SRCRPF_VIRACT_MST; |
| 357 | |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 358 | vsp1_wpf_write(wpf, dl, VI6_WPF_SRCRPF, srcrpf); |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 359 | |
| 360 | /* Enable interrupts */ |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 361 | vsp1_dl_list_write(dl, VI6_WPF_IRQ_STA(wpf->entity.index), 0); |
| 362 | vsp1_dl_list_write(dl, VI6_WPF_IRQ_ENB(wpf->entity.index), |
Kieran Bingham | 4c4b57b | 2016-09-06 06:55:02 -0300 | [diff] [blame] | 363 | VI6_WFP_IRQ_ENB_DFEE); |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 364 | } |
| 365 | |
Laurent Pinchart | 5243453 | 2015-11-17 12:23:23 -0200 | [diff] [blame] | 366 | static const struct vsp1_entity_operations wpf_entity_ops = { |
| 367 | .destroy = vsp1_wpf_destroy, |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 368 | .configure = wpf_configure, |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 369 | }; |
| 370 | |
| 371 | /* ----------------------------------------------------------------------------- |
| 372 | * Initialization and Cleanup |
| 373 | */ |
| 374 | |
| 375 | struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index) |
| 376 | { |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 377 | struct vsp1_rwpf *wpf; |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 378 | char name[6]; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 379 | int ret; |
| 380 | |
| 381 | wpf = devm_kzalloc(vsp1->dev, sizeof(*wpf), GFP_KERNEL); |
| 382 | if (wpf == NULL) |
| 383 | return ERR_PTR(-ENOMEM); |
| 384 | |
Laurent Pinchart | 0d268dc | 2016-03-25 06:51:06 -0300 | [diff] [blame] | 385 | if (vsp1->info->gen == 2) { |
| 386 | wpf->max_width = WPF_GEN2_MAX_WIDTH; |
| 387 | wpf->max_height = WPF_GEN2_MAX_HEIGHT; |
| 388 | } else { |
| 389 | wpf->max_width = WPF_GEN3_MAX_WIDTH; |
| 390 | wpf->max_height = WPF_GEN3_MAX_HEIGHT; |
| 391 | } |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 392 | |
Laurent Pinchart | 5243453 | 2015-11-17 12:23:23 -0200 | [diff] [blame] | 393 | wpf->entity.ops = &wpf_entity_ops; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 394 | wpf->entity.type = VSP1_ENTITY_WPF; |
| 395 | wpf->entity.index = index; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 396 | |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 397 | sprintf(name, "wpf.%u", index); |
Laurent Pinchart | 6a8e07b | 2016-02-15 22:10:26 -0200 | [diff] [blame] | 398 | ret = vsp1_entity_init(vsp1, &wpf->entity, name, 2, &wpf_ops, |
| 399 | MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 400 | if (ret < 0) |
| 401 | return ERR_PTR(ret); |
| 402 | |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 403 | /* Initialize the display list manager. */ |
Kieran Bingham | 76e4889 | 2016-07-12 13:49:46 -0300 | [diff] [blame] | 404 | wpf->dlm = vsp1_dlm_create(vsp1, index, 64); |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 405 | if (!wpf->dlm) { |
| 406 | ret = -ENOMEM; |
| 407 | goto error; |
Laurent Pinchart | ef9621b | 2015-11-14 22:27:52 -0200 | [diff] [blame] | 408 | } |
| 409 | |
Laurent Pinchart | 7578c20 | 2014-05-21 19:00:05 -0300 | [diff] [blame] | 410 | /* Initialize the control handler. */ |
Laurent Pinchart | 894dde5 | 2016-05-26 05:14:22 -0300 | [diff] [blame] | 411 | ret = wpf_init_controls(wpf); |
Laurent Pinchart | bd2fdd5 | 2015-11-01 12:19:42 -0200 | [diff] [blame] | 412 | if (ret < 0) { |
Laurent Pinchart | 7578c20 | 2014-05-21 19:00:05 -0300 | [diff] [blame] | 413 | dev_err(vsp1->dev, "wpf%u: failed to initialize controls\n", |
| 414 | index); |
Laurent Pinchart | 7578c20 | 2014-05-21 19:00:05 -0300 | [diff] [blame] | 415 | goto error; |
| 416 | } |
| 417 | |
Laurent Pinchart | d05a331 | 2016-06-20 05:04:38 -0300 | [diff] [blame] | 418 | v4l2_ctrl_handler_setup(&wpf->ctrls); |
| 419 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 420 | return wpf; |
| 421 | |
Laurent Pinchart | 1499be6 | 2014-05-28 12:49:13 -0300 | [diff] [blame] | 422 | error: |
| 423 | vsp1_entity_destroy(&wpf->entity); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 424 | return ERR_PTR(ret); |
| 425 | } |