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 | /* ----------------------------------------------------------------------------- |
| 40 | * V4L2 Subdevice Core Operations |
| 41 | */ |
| 42 | |
| 43 | static int wpf_s_stream(struct v4l2_subdev *subdev, int enable) |
| 44 | { |
| 45 | struct vsp1_rwpf *wpf = to_rwpf(subdev); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 46 | struct vsp1_device *vsp1 = wpf->entity.vsp1; |
Laurent Pinchart | 7578c20 | 2014-05-21 19:00:05 -0300 | [diff] [blame] | 47 | |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 48 | if (enable) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 49 | return 0; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 50 | |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 51 | /* Write to registers directly when stopping the stream as there will be |
| 52 | * no pipeline run to apply the display list. |
Laurent Pinchart | 629bb6d | 2013-07-10 18:03:46 -0300 | [diff] [blame] | 53 | */ |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 54 | vsp1_write(vsp1, VI6_WPF_IRQ_ENB(wpf->entity.index), 0); |
| 55 | vsp1_write(vsp1, wpf->entity.index * VI6_WPF_OFFSET + |
| 56 | VI6_WPF_SRCRPF, 0); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | /* ----------------------------------------------------------------------------- |
| 62 | * V4L2 Subdevice Operations |
| 63 | */ |
| 64 | |
Laurent Pinchart | eb9163d | 2016-06-17 21:11:26 -0300 | [diff] [blame] | 65 | static const struct v4l2_subdev_video_ops wpf_video_ops = { |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 66 | .s_stream = wpf_s_stream, |
| 67 | }; |
| 68 | |
Laurent Pinchart | eb9163d | 2016-06-17 21:11:26 -0300 | [diff] [blame] | 69 | static const struct v4l2_subdev_ops wpf_ops = { |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 70 | .video = &wpf_video_ops, |
Laurent Pinchart | c6c8efb | 2015-11-22 13:37:45 -0200 | [diff] [blame] | 71 | .pad = &vsp1_rwpf_pad_ops, |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | 5243453 | 2015-11-17 12:23:23 -0200 | [diff] [blame] | 75 | * VSP1 Entity Operations |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 76 | */ |
| 77 | |
Laurent Pinchart | 5243453 | 2015-11-17 12:23:23 -0200 | [diff] [blame] | 78 | static void vsp1_wpf_destroy(struct vsp1_entity *entity) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 79 | { |
Laurent Pinchart | 5243453 | 2015-11-17 12:23:23 -0200 | [diff] [blame] | 80 | struct vsp1_rwpf *wpf = entity_to_rwpf(entity); |
| 81 | |
| 82 | vsp1_dlm_destroy(wpf->dlm); |
| 83 | } |
| 84 | |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 85 | static void wpf_set_memory(struct vsp1_entity *entity, struct vsp1_dl_list *dl) |
Laurent Pinchart | 5243453 | 2015-11-17 12:23:23 -0200 | [diff] [blame] | 86 | { |
| 87 | struct vsp1_rwpf *wpf = entity_to_rwpf(entity); |
| 88 | |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 89 | vsp1_wpf_write(wpf, dl, VI6_WPF_DSTM_ADDR_Y, wpf->mem.addr[0]); |
| 90 | vsp1_wpf_write(wpf, dl, VI6_WPF_DSTM_ADDR_C0, wpf->mem.addr[1]); |
| 91 | vsp1_wpf_write(wpf, dl, VI6_WPF_DSTM_ADDR_C1, wpf->mem.addr[2]); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 92 | } |
| 93 | |
Laurent Pinchart | 83dd019 | 2016-01-14 14:17:32 -0200 | [diff] [blame] | 94 | static void wpf_configure(struct vsp1_entity *entity, |
| 95 | struct vsp1_pipeline *pipe, |
Laurent Pinchart | fc845e5 | 2016-06-11 04:07:56 -0300 | [diff] [blame] | 96 | struct vsp1_dl_list *dl, bool full) |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 97 | { |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 98 | struct vsp1_rwpf *wpf = to_rwpf(&entity->subdev); |
| 99 | struct vsp1_device *vsp1 = wpf->entity.vsp1; |
| 100 | const struct v4l2_mbus_framefmt *source_format; |
| 101 | const struct v4l2_mbus_framefmt *sink_format; |
| 102 | const struct v4l2_rect *crop; |
| 103 | unsigned int i; |
| 104 | u32 outfmt = 0; |
| 105 | u32 srcrpf = 0; |
| 106 | |
Laurent Pinchart | fc845e5 | 2016-06-11 04:07:56 -0300 | [diff] [blame] | 107 | if (!full) |
| 108 | return; |
| 109 | |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 110 | /* Cropping */ |
| 111 | crop = vsp1_rwpf_get_crop(wpf, wpf->entity.config); |
| 112 | |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 113 | vsp1_wpf_write(wpf, dl, VI6_WPF_HSZCLIP, VI6_WPF_SZCLIP_EN | |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 114 | (crop->left << VI6_WPF_SZCLIP_OFST_SHIFT) | |
| 115 | (crop->width << VI6_WPF_SZCLIP_SIZE_SHIFT)); |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 116 | vsp1_wpf_write(wpf, dl, VI6_WPF_VSZCLIP, VI6_WPF_SZCLIP_EN | |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 117 | (crop->top << VI6_WPF_SZCLIP_OFST_SHIFT) | |
| 118 | (crop->height << VI6_WPF_SZCLIP_SIZE_SHIFT)); |
| 119 | |
| 120 | /* Format */ |
| 121 | sink_format = vsp1_entity_get_pad_format(&wpf->entity, |
| 122 | wpf->entity.config, |
| 123 | RWPF_PAD_SINK); |
| 124 | source_format = vsp1_entity_get_pad_format(&wpf->entity, |
| 125 | wpf->entity.config, |
| 126 | RWPF_PAD_SOURCE); |
| 127 | |
| 128 | if (!pipe->lif) { |
| 129 | const struct v4l2_pix_format_mplane *format = &wpf->format; |
| 130 | const struct vsp1_format_info *fmtinfo = wpf->fmtinfo; |
| 131 | |
| 132 | outfmt = fmtinfo->hwfmt << VI6_WPF_OUTFMT_WRFMT_SHIFT; |
| 133 | |
| 134 | if (fmtinfo->alpha) |
| 135 | outfmt |= VI6_WPF_OUTFMT_PXA; |
| 136 | if (fmtinfo->swap_yc) |
| 137 | outfmt |= VI6_WPF_OUTFMT_SPYCS; |
| 138 | if (fmtinfo->swap_uv) |
| 139 | outfmt |= VI6_WPF_OUTFMT_SPUVS; |
| 140 | |
| 141 | /* Destination stride and byte swapping. */ |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 142 | vsp1_wpf_write(wpf, dl, VI6_WPF_DSTM_STRIDE_Y, |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 143 | format->plane_fmt[0].bytesperline); |
| 144 | if (format->num_planes > 1) |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 145 | vsp1_wpf_write(wpf, dl, VI6_WPF_DSTM_STRIDE_C, |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 146 | format->plane_fmt[1].bytesperline); |
| 147 | |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 148 | vsp1_wpf_write(wpf, dl, VI6_WPF_DSWAP, fmtinfo->swap); |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | if (sink_format->code != source_format->code) |
| 152 | outfmt |= VI6_WPF_OUTFMT_CSC; |
| 153 | |
| 154 | outfmt |= wpf->alpha << VI6_WPF_OUTFMT_PDV_SHIFT; |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 155 | vsp1_wpf_write(wpf, dl, VI6_WPF_OUTFMT, outfmt); |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 156 | |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 157 | vsp1_dl_list_write(dl, VI6_DPR_WPF_FPORCH(wpf->entity.index), |
| 158 | VI6_DPR_WPF_FPORCH_FP_WPFN); |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 159 | |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 160 | vsp1_dl_list_write(dl, VI6_WPF_WRBCK_CTRL, 0); |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 161 | |
| 162 | /* Sources. If the pipeline has a single input and BRU is not used, |
| 163 | * configure it as the master layer. Otherwise configure all |
| 164 | * inputs as sub-layers and select the virtual RPF as the master |
| 165 | * layer. |
| 166 | */ |
| 167 | for (i = 0; i < vsp1->info->rpf_count; ++i) { |
| 168 | struct vsp1_rwpf *input = pipe->inputs[i]; |
| 169 | |
| 170 | if (!input) |
| 171 | continue; |
| 172 | |
| 173 | srcrpf |= (!pipe->bru && pipe->num_inputs == 1) |
| 174 | ? VI6_WPF_SRCRPF_RPF_ACT_MST(input->entity.index) |
| 175 | : VI6_WPF_SRCRPF_RPF_ACT_SUB(input->entity.index); |
| 176 | } |
| 177 | |
| 178 | if (pipe->bru || pipe->num_inputs > 1) |
| 179 | srcrpf |= VI6_WPF_SRCRPF_VIRACT_MST; |
| 180 | |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 181 | vsp1_wpf_write(wpf, dl, VI6_WPF_SRCRPF, srcrpf); |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 182 | |
| 183 | /* Enable interrupts */ |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 184 | vsp1_dl_list_write(dl, VI6_WPF_IRQ_STA(wpf->entity.index), 0); |
| 185 | vsp1_dl_list_write(dl, VI6_WPF_IRQ_ENB(wpf->entity.index), |
| 186 | VI6_WFP_IRQ_ENB_FREE); |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 187 | } |
| 188 | |
Laurent Pinchart | 5243453 | 2015-11-17 12:23:23 -0200 | [diff] [blame] | 189 | static const struct vsp1_entity_operations wpf_entity_ops = { |
| 190 | .destroy = vsp1_wpf_destroy, |
Laurent Pinchart | b58faa9 | 2015-07-28 16:04:47 -0300 | [diff] [blame] | 191 | .set_memory = wpf_set_memory, |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 192 | .configure = wpf_configure, |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | /* ----------------------------------------------------------------------------- |
| 196 | * Initialization and Cleanup |
| 197 | */ |
| 198 | |
| 199 | struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index) |
| 200 | { |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 201 | struct vsp1_rwpf *wpf; |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 202 | char name[6]; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 203 | int ret; |
| 204 | |
| 205 | wpf = devm_kzalloc(vsp1->dev, sizeof(*wpf), GFP_KERNEL); |
| 206 | if (wpf == NULL) |
| 207 | return ERR_PTR(-ENOMEM); |
| 208 | |
Laurent Pinchart | 0d268dc | 2016-03-25 06:51:06 -0300 | [diff] [blame] | 209 | if (vsp1->info->gen == 2) { |
| 210 | wpf->max_width = WPF_GEN2_MAX_WIDTH; |
| 211 | wpf->max_height = WPF_GEN2_MAX_HEIGHT; |
| 212 | } else { |
| 213 | wpf->max_width = WPF_GEN3_MAX_WIDTH; |
| 214 | wpf->max_height = WPF_GEN3_MAX_HEIGHT; |
| 215 | } |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 216 | |
Laurent Pinchart | 5243453 | 2015-11-17 12:23:23 -0200 | [diff] [blame] | 217 | wpf->entity.ops = &wpf_entity_ops; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 218 | wpf->entity.type = VSP1_ENTITY_WPF; |
| 219 | wpf->entity.index = index; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 220 | |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 221 | sprintf(name, "wpf.%u", index); |
Laurent Pinchart | 6a8e07b | 2016-02-15 22:10:26 -0200 | [diff] [blame] | 222 | ret = vsp1_entity_init(vsp1, &wpf->entity, name, 2, &wpf_ops, |
| 223 | MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 224 | if (ret < 0) |
| 225 | return ERR_PTR(ret); |
| 226 | |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 227 | /* Initialize the display list manager. */ |
| 228 | wpf->dlm = vsp1_dlm_create(vsp1, index, 4); |
| 229 | if (!wpf->dlm) { |
| 230 | ret = -ENOMEM; |
| 231 | goto error; |
Laurent Pinchart | ef9621b | 2015-11-14 22:27:52 -0200 | [diff] [blame] | 232 | } |
| 233 | |
Laurent Pinchart | 7578c20 | 2014-05-21 19:00:05 -0300 | [diff] [blame] | 234 | /* Initialize the control handler. */ |
Laurent Pinchart | bd2fdd5 | 2015-11-01 12:19:42 -0200 | [diff] [blame] | 235 | ret = vsp1_rwpf_init_ctrls(wpf); |
| 236 | if (ret < 0) { |
Laurent Pinchart | 7578c20 | 2014-05-21 19:00:05 -0300 | [diff] [blame] | 237 | dev_err(vsp1->dev, "wpf%u: failed to initialize controls\n", |
| 238 | index); |
Laurent Pinchart | 7578c20 | 2014-05-21 19:00:05 -0300 | [diff] [blame] | 239 | goto error; |
| 240 | } |
| 241 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 242 | return wpf; |
| 243 | |
Laurent Pinchart | 1499be6 | 2014-05-28 12:49:13 -0300 | [diff] [blame] | 244 | error: |
| 245 | vsp1_entity_destroy(&wpf->entity); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 246 | return ERR_PTR(ret); |
| 247 | } |