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 | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 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 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 30 | static inline void vsp1_wpf_write(struct vsp1_rwpf *wpf, u32 reg, u32 data) |
| 31 | { |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 32 | vsp1_mod_write(&wpf->entity, |
| 33 | reg + wpf->entity.index * VI6_WPF_OFFSET, data); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /* ----------------------------------------------------------------------------- |
| 37 | * V4L2 Subdevice Core Operations |
| 38 | */ |
| 39 | |
| 40 | static int wpf_s_stream(struct v4l2_subdev *subdev, int enable) |
| 41 | { |
Laurent Pinchart | 5aeb01ad | 2014-05-27 20:35:36 -0300 | [diff] [blame] | 42 | struct vsp1_pipeline *pipe = to_vsp1_pipeline(&subdev->entity); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 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 | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 45 | const struct v4l2_mbus_framefmt *source_format; |
| 46 | const struct v4l2_mbus_framefmt *sink_format; |
Laurent Pinchart | b7e5107 | 2015-11-15 19:14:22 -0200 | [diff] [blame^] | 47 | const struct v4l2_rect *crop; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 48 | unsigned int i; |
| 49 | u32 srcrpf = 0; |
| 50 | u32 outfmt = 0; |
Laurent Pinchart | 7578c20 | 2014-05-21 19:00:05 -0300 | [diff] [blame] | 51 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 52 | if (!enable) { |
| 53 | vsp1_write(vsp1, VI6_WPF_IRQ_ENB(wpf->entity.index), 0); |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 54 | vsp1_write(vsp1, wpf->entity.index * VI6_WPF_OFFSET + |
| 55 | VI6_WPF_SRCRPF, 0); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 56 | return 0; |
| 57 | } |
| 58 | |
Takanari Hayama | 5d0beee | 2014-11-26 22:25:02 -0300 | [diff] [blame] | 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. |
Laurent Pinchart | 629bb6d | 2013-07-10 18:03:46 -0300 | [diff] [blame] | 63 | */ |
Laurent Pinchart | 5aa2eb3 | 2015-12-05 20:17:10 -0200 | [diff] [blame] | 64 | for (i = 0; i < vsp1->info->rpf_count; ++i) { |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 65 | struct vsp1_rwpf *input = pipe->inputs[i]; |
| 66 | |
Laurent Pinchart | 96bfa6a | 2015-08-05 16:40:31 -0300 | [diff] [blame] | 67 | if (!input) |
| 68 | continue; |
| 69 | |
Takanari Hayama | 5d0beee | 2014-11-26 22:25:02 -0300 | [diff] [blame] | 70 | srcrpf |= (!pipe->bru && pipe->num_inputs == 1) |
Laurent Pinchart | 629bb6d | 2013-07-10 18:03:46 -0300 | [diff] [blame] | 71 | ? VI6_WPF_SRCRPF_RPF_ACT_MST(input->entity.index) |
| 72 | : VI6_WPF_SRCRPF_RPF_ACT_SUB(input->entity.index); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 73 | } |
| 74 | |
Takanari Hayama | 5d0beee | 2014-11-26 22:25:02 -0300 | [diff] [blame] | 75 | if (pipe->bru || pipe->num_inputs > 1) |
Laurent Pinchart | 629bb6d | 2013-07-10 18:03:46 -0300 | [diff] [blame] | 76 | srcrpf |= VI6_WPF_SRCRPF_VIRACT_MST; |
| 77 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 78 | vsp1_wpf_write(wpf, VI6_WPF_SRCRPF, srcrpf); |
| 79 | |
Laurent Pinchart | e5ad37b | 2013-08-24 20:49:58 -0300 | [diff] [blame] | 80 | /* Destination stride. */ |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 81 | if (!pipe->lif) { |
Laurent Pinchart | 86960ee | 2015-07-28 14:00:43 -0300 | [diff] [blame] | 82 | struct v4l2_pix_format_mplane *format = &wpf->format; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 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 | |
Laurent Pinchart | b7e5107 | 2015-11-15 19:14:22 -0200 | [diff] [blame^] | 91 | crop = vsp1_rwpf_get_crop(wpf, wpf->entity.config); |
| 92 | |
Laurent Pinchart | e5ad37b | 2013-08-24 20:49:58 -0300 | [diff] [blame] | 93 | vsp1_wpf_write(wpf, VI6_WPF_HSZCLIP, VI6_WPF_SZCLIP_EN | |
| 94 | (crop->left << VI6_WPF_SZCLIP_OFST_SHIFT) | |
| 95 | (crop->width << VI6_WPF_SZCLIP_SIZE_SHIFT)); |
| 96 | vsp1_wpf_write(wpf, VI6_WPF_VSZCLIP, VI6_WPF_SZCLIP_EN | |
| 97 | (crop->top << VI6_WPF_SZCLIP_OFST_SHIFT) | |
| 98 | (crop->height << VI6_WPF_SZCLIP_SIZE_SHIFT)); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 99 | |
| 100 | /* Format */ |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 101 | sink_format = vsp1_entity_get_pad_format(&wpf->entity, |
| 102 | wpf->entity.config, |
| 103 | RWPF_PAD_SINK); |
| 104 | source_format = vsp1_entity_get_pad_format(&wpf->entity, |
| 105 | wpf->entity.config, |
| 106 | RWPF_PAD_SOURCE); |
| 107 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 108 | if (!pipe->lif) { |
Laurent Pinchart | 86960ee | 2015-07-28 14:00:43 -0300 | [diff] [blame] | 109 | const struct vsp1_format_info *fmtinfo = wpf->fmtinfo; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 110 | |
| 111 | outfmt = fmtinfo->hwfmt << VI6_WPF_OUTFMT_WRFMT_SHIFT; |
| 112 | |
Laurent Pinchart | 7a52b6d | 2014-05-26 20:12:53 -0300 | [diff] [blame] | 113 | if (fmtinfo->alpha) |
| 114 | outfmt |= VI6_WPF_OUTFMT_PXA; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 115 | if (fmtinfo->swap_yc) |
| 116 | outfmt |= VI6_WPF_OUTFMT_SPYCS; |
| 117 | if (fmtinfo->swap_uv) |
| 118 | outfmt |= VI6_WPF_OUTFMT_SPUVS; |
| 119 | |
| 120 | vsp1_wpf_write(wpf, VI6_WPF_DSWAP, fmtinfo->swap); |
| 121 | } |
| 122 | |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 123 | if (sink_format->code != source_format->code) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 124 | outfmt |= VI6_WPF_OUTFMT_CSC; |
| 125 | |
Laurent Pinchart | bd2fdd5 | 2015-11-01 12:19:42 -0200 | [diff] [blame] | 126 | outfmt |= wpf->alpha << VI6_WPF_OUTFMT_PDV_SHIFT; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 127 | vsp1_wpf_write(wpf, VI6_WPF_OUTFMT, outfmt); |
| 128 | |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 129 | vsp1_mod_write(&wpf->entity, VI6_DPR_WPF_FPORCH(wpf->entity.index), |
| 130 | VI6_DPR_WPF_FPORCH_FP_WPFN); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 131 | |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 132 | vsp1_mod_write(&wpf->entity, VI6_WPF_WRBCK_CTRL, 0); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 133 | |
| 134 | /* Enable interrupts */ |
| 135 | vsp1_write(vsp1, VI6_WPF_IRQ_STA(wpf->entity.index), 0); |
| 136 | vsp1_write(vsp1, VI6_WPF_IRQ_ENB(wpf->entity.index), |
| 137 | VI6_WFP_IRQ_ENB_FREE); |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | /* ----------------------------------------------------------------------------- |
| 143 | * V4L2 Subdevice Operations |
| 144 | */ |
| 145 | |
| 146 | static struct v4l2_subdev_video_ops wpf_video_ops = { |
| 147 | .s_stream = wpf_s_stream, |
| 148 | }; |
| 149 | |
| 150 | static struct v4l2_subdev_pad_ops wpf_pad_ops = { |
Laurent Pinchart | 0efdf0f | 2015-11-15 20:09:08 -0200 | [diff] [blame] | 151 | .init_cfg = vsp1_entity_init_cfg, |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 152 | .enum_mbus_code = vsp1_rwpf_enum_mbus_code, |
| 153 | .enum_frame_size = vsp1_rwpf_enum_frame_size, |
| 154 | .get_fmt = vsp1_rwpf_get_format, |
| 155 | .set_fmt = vsp1_rwpf_set_format, |
Laurent Pinchart | e5ad37b | 2013-08-24 20:49:58 -0300 | [diff] [blame] | 156 | .get_selection = vsp1_rwpf_get_selection, |
| 157 | .set_selection = vsp1_rwpf_set_selection, |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | static struct v4l2_subdev_ops wpf_ops = { |
| 161 | .video = &wpf_video_ops, |
| 162 | .pad = &wpf_pad_ops, |
| 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 | |
| 176 | static void wpf_set_memory(struct vsp1_entity *entity) |
| 177 | { |
| 178 | struct vsp1_rwpf *wpf = entity_to_rwpf(entity); |
| 179 | |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 180 | vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_Y, wpf->mem.addr[0]); |
| 181 | vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_C0, wpf->mem.addr[1]); |
| 182 | vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_C1, wpf->mem.addr[2]); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 183 | } |
| 184 | |
Laurent Pinchart | 5243453 | 2015-11-17 12:23:23 -0200 | [diff] [blame] | 185 | static const struct vsp1_entity_operations wpf_entity_ops = { |
| 186 | .destroy = vsp1_wpf_destroy, |
Laurent Pinchart | b58faa9 | 2015-07-28 16:04:47 -0300 | [diff] [blame] | 187 | .set_memory = wpf_set_memory, |
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 | } |