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