Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 1 | /* |
| 2 | * vsp1_entity.c -- R-Car VSP1 Base Entity |
| 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 | #include <linux/gfp.h> |
| 16 | |
| 17 | #include <media/media-entity.h> |
Laurent Pinchart | a626e64 | 2013-07-10 12:03:30 -0300 | [diff] [blame] | 18 | #include <media/v4l2-ctrls.h> |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 19 | #include <media/v4l2-subdev.h> |
| 20 | |
| 21 | #include "vsp1.h" |
Laurent Pinchart | aa380ea | 2015-11-01 10:46:25 -0200 | [diff] [blame] | 22 | #include "vsp1_dl.h" |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 23 | #include "vsp1_entity.h" |
Laurent Pinchart | c8663c8 | 2016-09-07 09:09:53 -0300 | [diff] [blame] | 24 | #include "vsp1_pipe.h" |
| 25 | #include "vsp1_rwpf.h" |
Laurent Pinchart | aa380ea | 2015-11-01 10:46:25 -0200 | [diff] [blame] | 26 | |
Laurent Pinchart | 7cf0f12 | 2016-03-03 20:06:22 -0300 | [diff] [blame] | 27 | static inline struct vsp1_entity * |
| 28 | media_entity_to_vsp1_entity(struct media_entity *entity) |
| 29 | { |
| 30 | return container_of(entity, struct vsp1_entity, subdev.entity); |
| 31 | } |
| 32 | |
Laurent Pinchart | c8663c8 | 2016-09-07 09:09:53 -0300 | [diff] [blame] | 33 | void vsp1_entity_route_setup(struct vsp1_entity *entity, |
| 34 | struct vsp1_pipeline *pipe, |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 35 | struct vsp1_dl_list *dl) |
Laurent Pinchart | 665b693 | 2015-08-02 18:58:31 -0300 | [diff] [blame] | 36 | { |
Laurent Pinchart | c8663c8 | 2016-09-07 09:09:53 -0300 | [diff] [blame] | 37 | struct vsp1_entity *source; |
Laurent Pinchart | 665b693 | 2015-08-02 18:58:31 -0300 | [diff] [blame] | 38 | struct vsp1_entity *sink; |
| 39 | |
Laurent Pinchart | f242152 | 2016-02-24 20:40:22 -0300 | [diff] [blame^] | 40 | if (entity->type == VSP1_ENTITY_HGO) { |
| 41 | u32 smppt; |
| 42 | |
| 43 | /* |
| 44 | * The HGO is a special case, its routing is configured on the |
| 45 | * sink pad. |
| 46 | */ |
| 47 | source = media_entity_to_vsp1_entity(entity->sources[0]); |
| 48 | smppt = (pipe->output->entity.index << VI6_DPR_SMPPT_TGW_SHIFT) |
| 49 | | (source->route->output << VI6_DPR_SMPPT_PT_SHIFT); |
| 50 | |
| 51 | vsp1_dl_list_write(dl, VI6_DPR_HGO_SMPPT, smppt); |
| 52 | return; |
| 53 | } |
| 54 | |
Laurent Pinchart | c8663c8 | 2016-09-07 09:09:53 -0300 | [diff] [blame] | 55 | source = entity; |
Laurent Pinchart | 665b693 | 2015-08-02 18:58:31 -0300 | [diff] [blame] | 56 | if (source->route->reg == 0) |
| 57 | return; |
| 58 | |
Laurent Pinchart | 7cf0f12 | 2016-03-03 20:06:22 -0300 | [diff] [blame] | 59 | sink = media_entity_to_vsp1_entity(source->sink); |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 60 | vsp1_dl_list_write(dl, source->route->reg, |
| 61 | sink->route->inputs[source->sink_pad]); |
Laurent Pinchart | 665b693 | 2015-08-02 18:58:31 -0300 | [diff] [blame] | 62 | } |
| 63 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 64 | /* ----------------------------------------------------------------------------- |
| 65 | * V4L2 Subdevice Operations |
| 66 | */ |
| 67 | |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 68 | /** |
| 69 | * vsp1_entity_get_pad_config - Get the pad configuration for an entity |
| 70 | * @entity: the entity |
| 71 | * @cfg: the TRY pad configuration |
| 72 | * @which: configuration selector (ACTIVE or TRY) |
| 73 | * |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 74 | * When called with which set to V4L2_SUBDEV_FORMAT_ACTIVE the caller must hold |
| 75 | * the entity lock to access the returned configuration. |
| 76 | * |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 77 | * Return the pad configuration requested by the which argument. The TRY |
| 78 | * configuration is passed explicitly to the function through the cfg argument |
| 79 | * and simply returned when requested. The ACTIVE configuration comes from the |
| 80 | * entity structure. |
| 81 | */ |
| 82 | struct v4l2_subdev_pad_config * |
| 83 | vsp1_entity_get_pad_config(struct vsp1_entity *entity, |
| 84 | struct v4l2_subdev_pad_config *cfg, |
| 85 | enum v4l2_subdev_format_whence which) |
| 86 | { |
| 87 | switch (which) { |
| 88 | case V4L2_SUBDEV_FORMAT_ACTIVE: |
| 89 | return entity->config; |
| 90 | case V4L2_SUBDEV_FORMAT_TRY: |
| 91 | default: |
| 92 | return cfg; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * vsp1_entity_get_pad_format - Get a pad format from storage for an entity |
| 98 | * @entity: the entity |
| 99 | * @cfg: the configuration storage |
| 100 | * @pad: the pad number |
| 101 | * |
| 102 | * Return the format stored in the given configuration for an entity's pad. The |
| 103 | * configuration can be an ACTIVE or TRY configuration. |
| 104 | */ |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 105 | struct v4l2_mbus_framefmt * |
| 106 | vsp1_entity_get_pad_format(struct vsp1_entity *entity, |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 107 | struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 108 | unsigned int pad) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 109 | { |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 110 | return v4l2_subdev_get_try_format(&entity->subdev, cfg, pad); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 111 | } |
| 112 | |
Laurent Pinchart | ccd3d95 | 2016-03-03 20:17:49 -0300 | [diff] [blame] | 113 | /** |
| 114 | * vsp1_entity_get_pad_selection - Get a pad selection from storage for entity |
| 115 | * @entity: the entity |
| 116 | * @cfg: the configuration storage |
| 117 | * @pad: the pad number |
| 118 | * @target: the selection target |
| 119 | * |
| 120 | * Return the selection rectangle stored in the given configuration for an |
| 121 | * entity's pad. The configuration can be an ACTIVE or TRY configuration. The |
| 122 | * selection target can be COMPOSE or CROP. |
| 123 | */ |
Laurent Pinchart | b7e5107 | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 124 | struct v4l2_rect * |
Laurent Pinchart | ccd3d95 | 2016-03-03 20:17:49 -0300 | [diff] [blame] | 125 | vsp1_entity_get_pad_selection(struct vsp1_entity *entity, |
| 126 | struct v4l2_subdev_pad_config *cfg, |
| 127 | unsigned int pad, unsigned int target) |
Laurent Pinchart | b7e5107 | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 128 | { |
Laurent Pinchart | ccd3d95 | 2016-03-03 20:17:49 -0300 | [diff] [blame] | 129 | switch (target) { |
| 130 | case V4L2_SEL_TGT_COMPOSE: |
| 131 | return v4l2_subdev_get_try_compose(&entity->subdev, cfg, pad); |
| 132 | case V4L2_SEL_TGT_CROP: |
| 133 | return v4l2_subdev_get_try_crop(&entity->subdev, cfg, pad); |
| 134 | default: |
| 135 | return NULL; |
| 136 | } |
Laurent Pinchart | b7e5107 | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 137 | } |
| 138 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 139 | /* |
Laurent Pinchart | 0efdf0f | 2015-11-15 20:09:08 -0200 | [diff] [blame] | 140 | * vsp1_entity_init_cfg - Initialize formats on all pads |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 141 | * @subdev: V4L2 subdevice |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 142 | * @cfg: V4L2 subdev pad configuration |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 143 | * |
Laurent Pinchart | 0efdf0f | 2015-11-15 20:09:08 -0200 | [diff] [blame] | 144 | * Initialize all pad formats with default values in the given pad config. This |
| 145 | * function can be used as a handler for the subdev pad::init_cfg operation. |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 146 | */ |
Laurent Pinchart | 0efdf0f | 2015-11-15 20:09:08 -0200 | [diff] [blame] | 147 | int vsp1_entity_init_cfg(struct v4l2_subdev *subdev, |
| 148 | struct v4l2_subdev_pad_config *cfg) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 149 | { |
| 150 | struct v4l2_subdev_format format; |
| 151 | unsigned int pad; |
| 152 | |
| 153 | for (pad = 0; pad < subdev->entity.num_pads - 1; ++pad) { |
| 154 | memset(&format, 0, sizeof(format)); |
| 155 | |
| 156 | format.pad = pad; |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 157 | format.which = cfg ? V4L2_SUBDEV_FORMAT_TRY |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 158 | : V4L2_SUBDEV_FORMAT_ACTIVE; |
| 159 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 160 | v4l2_subdev_call(subdev, pad, set_fmt, cfg, &format); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 161 | } |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
Laurent Pinchart | 3f55722 | 2016-02-24 21:10:13 -0300 | [diff] [blame] | 166 | /* |
| 167 | * vsp1_subdev_get_pad_format - Subdev pad get_fmt handler |
| 168 | * @subdev: V4L2 subdevice |
| 169 | * @cfg: V4L2 subdev pad configuration |
| 170 | * @fmt: V4L2 subdev format |
| 171 | * |
| 172 | * This function implements the subdev get_fmt pad operation. It can be used as |
| 173 | * a direct drop-in for the operation handler. |
| 174 | */ |
| 175 | int vsp1_subdev_get_pad_format(struct v4l2_subdev *subdev, |
| 176 | struct v4l2_subdev_pad_config *cfg, |
| 177 | struct v4l2_subdev_format *fmt) |
| 178 | { |
| 179 | struct vsp1_entity *entity = to_vsp1_entity(subdev); |
| 180 | struct v4l2_subdev_pad_config *config; |
| 181 | |
| 182 | config = vsp1_entity_get_pad_config(entity, cfg, fmt->which); |
| 183 | if (!config) |
| 184 | return -EINVAL; |
| 185 | |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 186 | mutex_lock(&entity->lock); |
Laurent Pinchart | 3f55722 | 2016-02-24 21:10:13 -0300 | [diff] [blame] | 187 | fmt->format = *vsp1_entity_get_pad_format(entity, config, fmt->pad); |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 188 | mutex_unlock(&entity->lock); |
Laurent Pinchart | 3f55722 | 2016-02-24 21:10:13 -0300 | [diff] [blame] | 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | |
Laurent Pinchart | 6ad9ba9 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 193 | /* |
| 194 | * vsp1_subdev_enum_mbus_code - Subdev pad enum_mbus_code handler |
| 195 | * @subdev: V4L2 subdevice |
| 196 | * @cfg: V4L2 subdev pad configuration |
| 197 | * @code: Media bus code enumeration |
| 198 | * @codes: Array of supported media bus codes |
| 199 | * @ncodes: Number of supported media bus codes |
| 200 | * |
| 201 | * This function implements the subdev enum_mbus_code pad operation for entities |
| 202 | * that do not support format conversion. It enumerates the given supported |
| 203 | * media bus codes on the sink pad and reports a source pad format identical to |
| 204 | * the sink pad. |
| 205 | */ |
| 206 | int vsp1_subdev_enum_mbus_code(struct v4l2_subdev *subdev, |
| 207 | struct v4l2_subdev_pad_config *cfg, |
| 208 | struct v4l2_subdev_mbus_code_enum *code, |
| 209 | const unsigned int *codes, unsigned int ncodes) |
| 210 | { |
| 211 | struct vsp1_entity *entity = to_vsp1_entity(subdev); |
| 212 | |
| 213 | if (code->pad == 0) { |
| 214 | if (code->index >= ncodes) |
| 215 | return -EINVAL; |
| 216 | |
| 217 | code->code = codes[code->index]; |
| 218 | } else { |
| 219 | struct v4l2_subdev_pad_config *config; |
| 220 | struct v4l2_mbus_framefmt *format; |
| 221 | |
Laurent Pinchart | 9dbed95 | 2017-02-26 10:29:50 -0300 | [diff] [blame] | 222 | /* |
| 223 | * The entity can't perform format conversion, the sink format |
Laurent Pinchart | 6ad9ba9 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 224 | * is always identical to the source format. |
| 225 | */ |
| 226 | if (code->index) |
| 227 | return -EINVAL; |
| 228 | |
| 229 | config = vsp1_entity_get_pad_config(entity, cfg, code->which); |
| 230 | if (!config) |
| 231 | return -EINVAL; |
| 232 | |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 233 | mutex_lock(&entity->lock); |
Laurent Pinchart | 6ad9ba9 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 234 | format = vsp1_entity_get_pad_format(entity, config, 0); |
| 235 | code->code = format->code; |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 236 | mutex_unlock(&entity->lock); |
Laurent Pinchart | 6ad9ba9 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | |
Laurent Pinchart | 076e834 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 242 | /* |
| 243 | * vsp1_subdev_enum_frame_size - Subdev pad enum_frame_size handler |
| 244 | * @subdev: V4L2 subdevice |
| 245 | * @cfg: V4L2 subdev pad configuration |
| 246 | * @fse: Frame size enumeration |
| 247 | * @min_width: Minimum image width |
| 248 | * @min_height: Minimum image height |
| 249 | * @max_width: Maximum image width |
| 250 | * @max_height: Maximum image height |
| 251 | * |
| 252 | * This function implements the subdev enum_frame_size pad operation for |
| 253 | * entities that do not support scaling or cropping. It reports the given |
| 254 | * minimum and maximum frame width and height on the sink pad, and a fixed |
| 255 | * source pad size identical to the sink pad. |
| 256 | */ |
| 257 | int vsp1_subdev_enum_frame_size(struct v4l2_subdev *subdev, |
| 258 | struct v4l2_subdev_pad_config *cfg, |
| 259 | struct v4l2_subdev_frame_size_enum *fse, |
| 260 | unsigned int min_width, unsigned int min_height, |
| 261 | unsigned int max_width, unsigned int max_height) |
| 262 | { |
| 263 | struct vsp1_entity *entity = to_vsp1_entity(subdev); |
| 264 | struct v4l2_subdev_pad_config *config; |
| 265 | struct v4l2_mbus_framefmt *format; |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 266 | int ret = 0; |
Laurent Pinchart | 076e834 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 267 | |
| 268 | config = vsp1_entity_get_pad_config(entity, cfg, fse->which); |
| 269 | if (!config) |
| 270 | return -EINVAL; |
| 271 | |
| 272 | format = vsp1_entity_get_pad_format(entity, config, fse->pad); |
| 273 | |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 274 | mutex_lock(&entity->lock); |
| 275 | |
| 276 | if (fse->index || fse->code != format->code) { |
| 277 | ret = -EINVAL; |
| 278 | goto done; |
| 279 | } |
Laurent Pinchart | 076e834 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 280 | |
| 281 | if (fse->pad == 0) { |
| 282 | fse->min_width = min_width; |
| 283 | fse->max_width = max_width; |
| 284 | fse->min_height = min_height; |
| 285 | fse->max_height = max_height; |
| 286 | } else { |
Laurent Pinchart | 9dbed95 | 2017-02-26 10:29:50 -0300 | [diff] [blame] | 287 | /* |
| 288 | * The size on the source pad are fixed and always identical to |
Laurent Pinchart | 076e834 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 289 | * the size on the sink pad. |
| 290 | */ |
| 291 | fse->min_width = format->width; |
| 292 | fse->max_width = format->width; |
| 293 | fse->min_height = format->height; |
| 294 | fse->max_height = format->height; |
| 295 | } |
| 296 | |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 297 | done: |
| 298 | mutex_unlock(&entity->lock); |
| 299 | return ret; |
Laurent Pinchart | 076e834 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 300 | } |
| 301 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 302 | /* ----------------------------------------------------------------------------- |
| 303 | * Media Operations |
| 304 | */ |
| 305 | |
Laurent Pinchart | c8663c8 | 2016-09-07 09:09:53 -0300 | [diff] [blame] | 306 | static int vsp1_entity_link_setup_source(const struct media_pad *source_pad, |
| 307 | const struct media_pad *sink_pad, |
| 308 | u32 flags) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 309 | { |
| 310 | struct vsp1_entity *source; |
| 311 | |
Laurent Pinchart | c8663c8 | 2016-09-07 09:09:53 -0300 | [diff] [blame] | 312 | source = media_entity_to_vsp1_entity(source_pad->entity); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 313 | |
| 314 | if (!source->route) |
| 315 | return 0; |
| 316 | |
| 317 | if (flags & MEDIA_LNK_FL_ENABLED) { |
Laurent Pinchart | c8663c8 | 2016-09-07 09:09:53 -0300 | [diff] [blame] | 318 | struct vsp1_entity *sink |
| 319 | = media_entity_to_vsp1_entity(sink_pad->entity); |
| 320 | |
| 321 | /* |
| 322 | * Fan-out is limited to one for the normal data path plus |
| 323 | * optional HGO and HGT. We ignore the HGO and HGT here. |
| 324 | */ |
| 325 | if (sink->type != VSP1_ENTITY_HGO && |
| 326 | sink->type != VSP1_ENTITY_HGT) { |
| 327 | if (source->sink) |
| 328 | return -EBUSY; |
| 329 | source->sink = sink_pad->entity; |
| 330 | source->sink_pad = sink_pad->index; |
| 331 | } |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 332 | } else { |
| 333 | source->sink = NULL; |
Laurent Pinchart | d9b45ed | 2013-07-10 18:37:27 -0300 | [diff] [blame] | 334 | source->sink_pad = 0; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | return 0; |
| 338 | } |
| 339 | |
Laurent Pinchart | c8663c8 | 2016-09-07 09:09:53 -0300 | [diff] [blame] | 340 | static int vsp1_entity_link_setup_sink(const struct media_pad *source_pad, |
| 341 | const struct media_pad *sink_pad, |
| 342 | u32 flags) |
| 343 | { |
| 344 | struct vsp1_entity *sink; |
| 345 | |
| 346 | sink = media_entity_to_vsp1_entity(sink_pad->entity); |
| 347 | |
| 348 | if (flags & MEDIA_LNK_FL_ENABLED) { |
| 349 | /* Fan-in is limited to one. */ |
| 350 | if (sink->sources[sink_pad->index]) |
| 351 | return -EBUSY; |
| 352 | |
| 353 | sink->sources[sink_pad->index] = source_pad->entity; |
| 354 | } else { |
| 355 | sink->sources[sink_pad->index] = NULL; |
| 356 | } |
| 357 | |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | int vsp1_entity_link_setup(struct media_entity *entity, |
| 362 | const struct media_pad *local, |
| 363 | const struct media_pad *remote, u32 flags) |
| 364 | { |
| 365 | if (local->flags & MEDIA_PAD_FL_SOURCE) |
| 366 | return vsp1_entity_link_setup_source(local, remote, flags); |
| 367 | else |
| 368 | return vsp1_entity_link_setup_sink(remote, local, flags); |
| 369 | } |
| 370 | |
| 371 | /** |
| 372 | * vsp1_entity_remote_pad - Find the pad at the remote end of a link |
| 373 | * @pad: Pad at the local end of the link |
| 374 | * |
| 375 | * Search for a remote pad connected to the given pad by iterating over all |
| 376 | * links originating or terminating at that pad until an enabled link is found. |
| 377 | * |
| 378 | * Our link setup implementation guarantees that the output fan-out will not be |
| 379 | * higher than one for the data pipelines, except for the links to the HGO and |
| 380 | * HGT that can be enabled in addition to a regular data link. When traversing |
| 381 | * outgoing links this function ignores HGO and HGT entities and should thus be |
| 382 | * used in place of the generic media_entity_remote_pad() function to traverse |
| 383 | * data pipelines. |
| 384 | * |
| 385 | * Return a pointer to the pad at the remote end of the first found enabled |
| 386 | * link, or NULL if no enabled link has been found. |
| 387 | */ |
| 388 | struct media_pad *vsp1_entity_remote_pad(struct media_pad *pad) |
| 389 | { |
| 390 | struct media_link *link; |
| 391 | |
| 392 | list_for_each_entry(link, &pad->entity->links, list) { |
| 393 | struct vsp1_entity *entity; |
| 394 | |
| 395 | if (!(link->flags & MEDIA_LNK_FL_ENABLED)) |
| 396 | continue; |
| 397 | |
| 398 | /* If we're the sink the source will never be an HGO or HGT. */ |
| 399 | if (link->sink == pad) |
| 400 | return link->source; |
| 401 | |
| 402 | if (link->source != pad) |
| 403 | continue; |
| 404 | |
| 405 | /* If the sink isn't a subdevice it can't be an HGO or HGT. */ |
| 406 | if (!is_media_entity_v4l2_subdev(link->sink->entity)) |
| 407 | return link->sink; |
| 408 | |
| 409 | entity = media_entity_to_vsp1_entity(link->sink->entity); |
| 410 | if (entity->type != VSP1_ENTITY_HGO && |
| 411 | entity->type != VSP1_ENTITY_HGT) |
| 412 | return link->sink; |
| 413 | } |
| 414 | |
| 415 | return NULL; |
| 416 | |
| 417 | } |
| 418 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 419 | /* ----------------------------------------------------------------------------- |
| 420 | * Initialization |
| 421 | */ |
| 422 | |
Laurent Pinchart | 44f4619 | 2016-02-24 19:10:04 -0300 | [diff] [blame] | 423 | #define VSP1_ENTITY_ROUTE(ent) \ |
| 424 | { VSP1_ENTITY_##ent, 0, VI6_DPR_##ent##_ROUTE, \ |
| 425 | { VI6_DPR_NODE_##ent }, VI6_DPR_NODE_##ent } |
| 426 | |
| 427 | #define VSP1_ENTITY_ROUTE_RPF(idx) \ |
| 428 | { VSP1_ENTITY_RPF, idx, VI6_DPR_RPF_ROUTE(idx), \ |
| 429 | { 0, }, VI6_DPR_NODE_RPF(idx) } |
| 430 | |
| 431 | #define VSP1_ENTITY_ROUTE_UDS(idx) \ |
| 432 | { VSP1_ENTITY_UDS, idx, VI6_DPR_UDS_ROUTE(idx), \ |
| 433 | { VI6_DPR_NODE_UDS(idx) }, VI6_DPR_NODE_UDS(idx) } |
| 434 | |
| 435 | #define VSP1_ENTITY_ROUTE_WPF(idx) \ |
| 436 | { VSP1_ENTITY_WPF, idx, 0, \ |
| 437 | { VI6_DPR_NODE_WPF(idx) }, VI6_DPR_NODE_WPF(idx) } |
| 438 | |
Laurent Pinchart | d9b45ed | 2013-07-10 18:37:27 -0300 | [diff] [blame] | 439 | static const struct vsp1_route vsp1_routes[] = { |
Laurent Pinchart | 629bb6d | 2013-07-10 18:03:46 -0300 | [diff] [blame] | 440 | { VSP1_ENTITY_BRU, 0, VI6_DPR_BRU_ROUTE, |
| 441 | { VI6_DPR_NODE_BRU_IN(0), VI6_DPR_NODE_BRU_IN(1), |
Laurent Pinchart | 7f2d50f | 2015-09-07 08:05:39 -0300 | [diff] [blame] | 442 | VI6_DPR_NODE_BRU_IN(2), VI6_DPR_NODE_BRU_IN(3), |
Laurent Pinchart | 44f4619 | 2016-02-24 19:10:04 -0300 | [diff] [blame] | 443 | VI6_DPR_NODE_BRU_IN(4) }, VI6_DPR_NODE_BRU_OUT }, |
Laurent Pinchart | 1fd87bf | 2015-11-11 23:04:44 -0200 | [diff] [blame] | 444 | VSP1_ENTITY_ROUTE(CLU), |
Laurent Pinchart | f242152 | 2016-02-24 20:40:22 -0300 | [diff] [blame^] | 445 | { VSP1_ENTITY_HGO, 0, 0, { 0, }, 0 }, |
Laurent Pinchart | 44f4619 | 2016-02-24 19:10:04 -0300 | [diff] [blame] | 446 | VSP1_ENTITY_ROUTE(HSI), |
| 447 | VSP1_ENTITY_ROUTE(HST), |
| 448 | { VSP1_ENTITY_LIF, 0, 0, { VI6_DPR_NODE_LIF, }, VI6_DPR_NODE_LIF }, |
| 449 | VSP1_ENTITY_ROUTE(LUT), |
| 450 | VSP1_ENTITY_ROUTE_RPF(0), |
| 451 | VSP1_ENTITY_ROUTE_RPF(1), |
| 452 | VSP1_ENTITY_ROUTE_RPF(2), |
| 453 | VSP1_ENTITY_ROUTE_RPF(3), |
| 454 | VSP1_ENTITY_ROUTE_RPF(4), |
| 455 | VSP1_ENTITY_ROUTE(SRU), |
| 456 | VSP1_ENTITY_ROUTE_UDS(0), |
| 457 | VSP1_ENTITY_ROUTE_UDS(1), |
| 458 | VSP1_ENTITY_ROUTE_UDS(2), |
| 459 | VSP1_ENTITY_ROUTE_WPF(0), |
| 460 | VSP1_ENTITY_ROUTE_WPF(1), |
| 461 | VSP1_ENTITY_ROUTE_WPF(2), |
| 462 | VSP1_ENTITY_ROUTE_WPF(3), |
Laurent Pinchart | d9b45ed | 2013-07-10 18:37:27 -0300 | [diff] [blame] | 463 | }; |
| 464 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 465 | int vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity, |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 466 | const char *name, unsigned int num_pads, |
Laurent Pinchart | 6a8e07b | 2016-02-15 22:10:26 -0200 | [diff] [blame] | 467 | const struct v4l2_subdev_ops *ops, u32 function) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 468 | { |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 469 | struct v4l2_subdev *subdev; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 470 | unsigned int i; |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 471 | int ret; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 472 | |
Laurent Pinchart | d9b45ed | 2013-07-10 18:37:27 -0300 | [diff] [blame] | 473 | for (i = 0; i < ARRAY_SIZE(vsp1_routes); ++i) { |
| 474 | if (vsp1_routes[i].type == entity->type && |
| 475 | vsp1_routes[i].index == entity->index) { |
| 476 | entity->route = &vsp1_routes[i]; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 477 | break; |
| 478 | } |
| 479 | } |
| 480 | |
Laurent Pinchart | d9b45ed | 2013-07-10 18:37:27 -0300 | [diff] [blame] | 481 | if (i == ARRAY_SIZE(vsp1_routes)) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 482 | return -EINVAL; |
| 483 | |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 484 | mutex_init(&entity->lock); |
| 485 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 486 | entity->vsp1 = vsp1; |
| 487 | entity->source_pad = num_pads - 1; |
| 488 | |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 489 | /* Allocate and initialize pads. */ |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 490 | entity->pads = devm_kzalloc(vsp1->dev, num_pads * sizeof(*entity->pads), |
| 491 | GFP_KERNEL); |
| 492 | if (entity->pads == NULL) |
| 493 | return -ENOMEM; |
| 494 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 495 | for (i = 0; i < num_pads - 1; ++i) |
| 496 | entity->pads[i].flags = MEDIA_PAD_FL_SINK; |
| 497 | |
Laurent Pinchart | c8663c8 | 2016-09-07 09:09:53 -0300 | [diff] [blame] | 498 | entity->sources = devm_kcalloc(vsp1->dev, max(num_pads - 1, 1U), |
| 499 | sizeof(*entity->sources), GFP_KERNEL); |
| 500 | if (entity->sources == NULL) |
| 501 | return -ENOMEM; |
| 502 | |
| 503 | /* Single-pad entities only have a sink. */ |
| 504 | entity->pads[num_pads - 1].flags = num_pads > 1 ? MEDIA_PAD_FL_SOURCE |
| 505 | : MEDIA_PAD_FL_SINK; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 506 | |
| 507 | /* Initialize the media entity. */ |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 508 | ret = media_entity_pads_init(&entity->subdev.entity, num_pads, |
| 509 | entity->pads); |
| 510 | if (ret < 0) |
| 511 | return ret; |
| 512 | |
| 513 | /* Initialize the V4L2 subdev. */ |
| 514 | subdev = &entity->subdev; |
| 515 | v4l2_subdev_init(subdev, ops); |
| 516 | |
Laurent Pinchart | 6a8e07b | 2016-02-15 22:10:26 -0200 | [diff] [blame] | 517 | subdev->entity.function = function; |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 518 | subdev->entity.ops = &vsp1->media_ops; |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 519 | subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; |
| 520 | |
| 521 | snprintf(subdev->name, sizeof(subdev->name), "%s %s", |
| 522 | dev_name(vsp1->dev), name); |
| 523 | |
Laurent Pinchart | 0efdf0f | 2015-11-15 20:09:08 -0200 | [diff] [blame] | 524 | vsp1_entity_init_cfg(subdev, NULL); |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 525 | |
Laurent Pinchart | 9dbed95 | 2017-02-26 10:29:50 -0300 | [diff] [blame] | 526 | /* |
| 527 | * Allocate the pad configuration to store formats and selection |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 528 | * rectangles. |
| 529 | */ |
| 530 | entity->config = v4l2_subdev_alloc_pad_config(&entity->subdev); |
| 531 | if (entity->config == NULL) { |
| 532 | media_entity_cleanup(&entity->subdev.entity); |
| 533 | return -ENOMEM; |
| 534 | } |
| 535 | |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 536 | return 0; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | void vsp1_entity_destroy(struct vsp1_entity *entity) |
| 540 | { |
Laurent Pinchart | 5243453 | 2015-11-17 12:23:23 -0200 | [diff] [blame] | 541 | if (entity->ops && entity->ops->destroy) |
| 542 | entity->ops->destroy(entity); |
Laurent Pinchart | a626e64 | 2013-07-10 12:03:30 -0300 | [diff] [blame] | 543 | if (entity->subdev.ctrl_handler) |
| 544 | v4l2_ctrl_handler_free(entity->subdev.ctrl_handler); |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 545 | v4l2_subdev_free_pad_config(entity->config); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 546 | media_entity_cleanup(&entity->subdev.entity); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 547 | } |