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 | aa380ea | 2015-11-01 10:46:25 -0200 | [diff] [blame] | 24 | |
Laurent Pinchart | 7cf0f12 | 2016-03-03 20:06:22 -0300 | [diff] [blame] | 25 | static inline struct vsp1_entity * |
| 26 | media_entity_to_vsp1_entity(struct media_entity *entity) |
| 27 | { |
| 28 | return container_of(entity, struct vsp1_entity, subdev.entity); |
| 29 | } |
| 30 | |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 31 | void vsp1_entity_route_setup(struct vsp1_entity *source, |
| 32 | struct vsp1_dl_list *dl) |
Laurent Pinchart | 665b693 | 2015-08-02 18:58:31 -0300 | [diff] [blame] | 33 | { |
| 34 | struct vsp1_entity *sink; |
| 35 | |
| 36 | if (source->route->reg == 0) |
| 37 | return; |
| 38 | |
Laurent Pinchart | 7cf0f12 | 2016-03-03 20:06:22 -0300 | [diff] [blame] | 39 | sink = media_entity_to_vsp1_entity(source->sink); |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 40 | vsp1_dl_list_write(dl, source->route->reg, |
| 41 | sink->route->inputs[source->sink_pad]); |
Laurent Pinchart | 665b693 | 2015-08-02 18:58:31 -0300 | [diff] [blame] | 42 | } |
| 43 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 44 | /* ----------------------------------------------------------------------------- |
| 45 | * V4L2 Subdevice Operations |
| 46 | */ |
| 47 | |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 48 | /** |
| 49 | * vsp1_entity_get_pad_config - Get the pad configuration for an entity |
| 50 | * @entity: the entity |
| 51 | * @cfg: the TRY pad configuration |
| 52 | * @which: configuration selector (ACTIVE or TRY) |
| 53 | * |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 54 | * When called with which set to V4L2_SUBDEV_FORMAT_ACTIVE the caller must hold |
| 55 | * the entity lock to access the returned configuration. |
| 56 | * |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 57 | * Return the pad configuration requested by the which argument. The TRY |
| 58 | * configuration is passed explicitly to the function through the cfg argument |
| 59 | * and simply returned when requested. The ACTIVE configuration comes from the |
| 60 | * entity structure. |
| 61 | */ |
| 62 | struct v4l2_subdev_pad_config * |
| 63 | vsp1_entity_get_pad_config(struct vsp1_entity *entity, |
| 64 | struct v4l2_subdev_pad_config *cfg, |
| 65 | enum v4l2_subdev_format_whence which) |
| 66 | { |
| 67 | switch (which) { |
| 68 | case V4L2_SUBDEV_FORMAT_ACTIVE: |
| 69 | return entity->config; |
| 70 | case V4L2_SUBDEV_FORMAT_TRY: |
| 71 | default: |
| 72 | return cfg; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * vsp1_entity_get_pad_format - Get a pad format from storage for an entity |
| 78 | * @entity: the entity |
| 79 | * @cfg: the configuration storage |
| 80 | * @pad: the pad number |
| 81 | * |
| 82 | * Return the format stored in the given configuration for an entity's pad. The |
| 83 | * configuration can be an ACTIVE or TRY configuration. |
| 84 | */ |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 85 | struct v4l2_mbus_framefmt * |
| 86 | vsp1_entity_get_pad_format(struct vsp1_entity *entity, |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 87 | struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 88 | unsigned int pad) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 89 | { |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 90 | return v4l2_subdev_get_try_format(&entity->subdev, cfg, pad); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 91 | } |
| 92 | |
Laurent Pinchart | ccd3d95 | 2016-03-03 20:17:49 -0300 | [diff] [blame] | 93 | /** |
| 94 | * vsp1_entity_get_pad_selection - Get a pad selection from storage for entity |
| 95 | * @entity: the entity |
| 96 | * @cfg: the configuration storage |
| 97 | * @pad: the pad number |
| 98 | * @target: the selection target |
| 99 | * |
| 100 | * Return the selection rectangle stored in the given configuration for an |
| 101 | * entity's pad. The configuration can be an ACTIVE or TRY configuration. The |
| 102 | * selection target can be COMPOSE or CROP. |
| 103 | */ |
Laurent Pinchart | b7e5107 | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 104 | struct v4l2_rect * |
Laurent Pinchart | ccd3d95 | 2016-03-03 20:17:49 -0300 | [diff] [blame] | 105 | vsp1_entity_get_pad_selection(struct vsp1_entity *entity, |
| 106 | struct v4l2_subdev_pad_config *cfg, |
| 107 | unsigned int pad, unsigned int target) |
Laurent Pinchart | b7e5107 | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 108 | { |
Laurent Pinchart | ccd3d95 | 2016-03-03 20:17:49 -0300 | [diff] [blame] | 109 | switch (target) { |
| 110 | case V4L2_SEL_TGT_COMPOSE: |
| 111 | return v4l2_subdev_get_try_compose(&entity->subdev, cfg, pad); |
| 112 | case V4L2_SEL_TGT_CROP: |
| 113 | return v4l2_subdev_get_try_crop(&entity->subdev, cfg, pad); |
| 114 | default: |
| 115 | return NULL; |
| 116 | } |
Laurent Pinchart | b7e5107 | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 117 | } |
| 118 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 119 | /* |
Laurent Pinchart | 0efdf0f | 2015-11-15 20:09:08 -0200 | [diff] [blame] | 120 | * vsp1_entity_init_cfg - Initialize formats on all pads |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 121 | * @subdev: V4L2 subdevice |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 122 | * @cfg: V4L2 subdev pad configuration |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 123 | * |
Laurent Pinchart | 0efdf0f | 2015-11-15 20:09:08 -0200 | [diff] [blame] | 124 | * Initialize all pad formats with default values in the given pad config. This |
| 125 | * 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] | 126 | */ |
Laurent Pinchart | 0efdf0f | 2015-11-15 20:09:08 -0200 | [diff] [blame] | 127 | int vsp1_entity_init_cfg(struct v4l2_subdev *subdev, |
| 128 | struct v4l2_subdev_pad_config *cfg) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 129 | { |
| 130 | struct v4l2_subdev_format format; |
| 131 | unsigned int pad; |
| 132 | |
| 133 | for (pad = 0; pad < subdev->entity.num_pads - 1; ++pad) { |
| 134 | memset(&format, 0, sizeof(format)); |
| 135 | |
| 136 | format.pad = pad; |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 137 | format.which = cfg ? V4L2_SUBDEV_FORMAT_TRY |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 138 | : V4L2_SUBDEV_FORMAT_ACTIVE; |
| 139 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 140 | v4l2_subdev_call(subdev, pad, set_fmt, cfg, &format); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 141 | } |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
Laurent Pinchart | 3f55722 | 2016-02-24 21:10:13 -0300 | [diff] [blame] | 146 | /* |
| 147 | * vsp1_subdev_get_pad_format - Subdev pad get_fmt handler |
| 148 | * @subdev: V4L2 subdevice |
| 149 | * @cfg: V4L2 subdev pad configuration |
| 150 | * @fmt: V4L2 subdev format |
| 151 | * |
| 152 | * This function implements the subdev get_fmt pad operation. It can be used as |
| 153 | * a direct drop-in for the operation handler. |
| 154 | */ |
| 155 | int vsp1_subdev_get_pad_format(struct v4l2_subdev *subdev, |
| 156 | struct v4l2_subdev_pad_config *cfg, |
| 157 | struct v4l2_subdev_format *fmt) |
| 158 | { |
| 159 | struct vsp1_entity *entity = to_vsp1_entity(subdev); |
| 160 | struct v4l2_subdev_pad_config *config; |
| 161 | |
| 162 | config = vsp1_entity_get_pad_config(entity, cfg, fmt->which); |
| 163 | if (!config) |
| 164 | return -EINVAL; |
| 165 | |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 166 | mutex_lock(&entity->lock); |
Laurent Pinchart | 3f55722 | 2016-02-24 21:10:13 -0300 | [diff] [blame] | 167 | fmt->format = *vsp1_entity_get_pad_format(entity, config, fmt->pad); |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 168 | mutex_unlock(&entity->lock); |
Laurent Pinchart | 3f55722 | 2016-02-24 21:10:13 -0300 | [diff] [blame] | 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
Laurent Pinchart | 6ad9ba9 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 173 | /* |
| 174 | * vsp1_subdev_enum_mbus_code - Subdev pad enum_mbus_code handler |
| 175 | * @subdev: V4L2 subdevice |
| 176 | * @cfg: V4L2 subdev pad configuration |
| 177 | * @code: Media bus code enumeration |
| 178 | * @codes: Array of supported media bus codes |
| 179 | * @ncodes: Number of supported media bus codes |
| 180 | * |
| 181 | * This function implements the subdev enum_mbus_code pad operation for entities |
| 182 | * that do not support format conversion. It enumerates the given supported |
| 183 | * media bus codes on the sink pad and reports a source pad format identical to |
| 184 | * the sink pad. |
| 185 | */ |
| 186 | int vsp1_subdev_enum_mbus_code(struct v4l2_subdev *subdev, |
| 187 | struct v4l2_subdev_pad_config *cfg, |
| 188 | struct v4l2_subdev_mbus_code_enum *code, |
| 189 | const unsigned int *codes, unsigned int ncodes) |
| 190 | { |
| 191 | struct vsp1_entity *entity = to_vsp1_entity(subdev); |
| 192 | |
| 193 | if (code->pad == 0) { |
| 194 | if (code->index >= ncodes) |
| 195 | return -EINVAL; |
| 196 | |
| 197 | code->code = codes[code->index]; |
| 198 | } else { |
| 199 | struct v4l2_subdev_pad_config *config; |
| 200 | struct v4l2_mbus_framefmt *format; |
| 201 | |
Laurent Pinchart | 9dbed95 | 2017-02-26 10:29:50 -0300 | [diff] [blame^] | 202 | /* |
| 203 | * The entity can't perform format conversion, the sink format |
Laurent Pinchart | 6ad9ba9 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 204 | * is always identical to the source format. |
| 205 | */ |
| 206 | if (code->index) |
| 207 | return -EINVAL; |
| 208 | |
| 209 | config = vsp1_entity_get_pad_config(entity, cfg, code->which); |
| 210 | if (!config) |
| 211 | return -EINVAL; |
| 212 | |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 213 | mutex_lock(&entity->lock); |
Laurent Pinchart | 6ad9ba9 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 214 | format = vsp1_entity_get_pad_format(entity, config, 0); |
| 215 | code->code = format->code; |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 216 | mutex_unlock(&entity->lock); |
Laurent Pinchart | 6ad9ba9 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | return 0; |
| 220 | } |
| 221 | |
Laurent Pinchart | 076e834 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 222 | /* |
| 223 | * vsp1_subdev_enum_frame_size - Subdev pad enum_frame_size handler |
| 224 | * @subdev: V4L2 subdevice |
| 225 | * @cfg: V4L2 subdev pad configuration |
| 226 | * @fse: Frame size enumeration |
| 227 | * @min_width: Minimum image width |
| 228 | * @min_height: Minimum image height |
| 229 | * @max_width: Maximum image width |
| 230 | * @max_height: Maximum image height |
| 231 | * |
| 232 | * This function implements the subdev enum_frame_size pad operation for |
| 233 | * entities that do not support scaling or cropping. It reports the given |
| 234 | * minimum and maximum frame width and height on the sink pad, and a fixed |
| 235 | * source pad size identical to the sink pad. |
| 236 | */ |
| 237 | int vsp1_subdev_enum_frame_size(struct v4l2_subdev *subdev, |
| 238 | struct v4l2_subdev_pad_config *cfg, |
| 239 | struct v4l2_subdev_frame_size_enum *fse, |
| 240 | unsigned int min_width, unsigned int min_height, |
| 241 | unsigned int max_width, unsigned int max_height) |
| 242 | { |
| 243 | struct vsp1_entity *entity = to_vsp1_entity(subdev); |
| 244 | struct v4l2_subdev_pad_config *config; |
| 245 | struct v4l2_mbus_framefmt *format; |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 246 | int ret = 0; |
Laurent Pinchart | 076e834 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 247 | |
| 248 | config = vsp1_entity_get_pad_config(entity, cfg, fse->which); |
| 249 | if (!config) |
| 250 | return -EINVAL; |
| 251 | |
| 252 | format = vsp1_entity_get_pad_format(entity, config, fse->pad); |
| 253 | |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 254 | mutex_lock(&entity->lock); |
| 255 | |
| 256 | if (fse->index || fse->code != format->code) { |
| 257 | ret = -EINVAL; |
| 258 | goto done; |
| 259 | } |
Laurent Pinchart | 076e834 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 260 | |
| 261 | if (fse->pad == 0) { |
| 262 | fse->min_width = min_width; |
| 263 | fse->max_width = max_width; |
| 264 | fse->min_height = min_height; |
| 265 | fse->max_height = max_height; |
| 266 | } else { |
Laurent Pinchart | 9dbed95 | 2017-02-26 10:29:50 -0300 | [diff] [blame^] | 267 | /* |
| 268 | * The size on the source pad are fixed and always identical to |
Laurent Pinchart | 076e834 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 269 | * the size on the sink pad. |
| 270 | */ |
| 271 | fse->min_width = format->width; |
| 272 | fse->max_width = format->width; |
| 273 | fse->min_height = format->height; |
| 274 | fse->max_height = format->height; |
| 275 | } |
| 276 | |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 277 | done: |
| 278 | mutex_unlock(&entity->lock); |
| 279 | return ret; |
Laurent Pinchart | 076e834 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 280 | } |
| 281 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 282 | /* ----------------------------------------------------------------------------- |
| 283 | * Media Operations |
| 284 | */ |
| 285 | |
Laurent Pinchart | babca00 | 2015-08-05 17:14:41 -0300 | [diff] [blame] | 286 | int vsp1_entity_link_setup(struct media_entity *entity, |
| 287 | const struct media_pad *local, |
| 288 | const struct media_pad *remote, u32 flags) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 289 | { |
| 290 | struct vsp1_entity *source; |
| 291 | |
| 292 | if (!(local->flags & MEDIA_PAD_FL_SOURCE)) |
| 293 | return 0; |
| 294 | |
Laurent Pinchart | 7cf0f12 | 2016-03-03 20:06:22 -0300 | [diff] [blame] | 295 | source = media_entity_to_vsp1_entity(local->entity); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 296 | |
| 297 | if (!source->route) |
| 298 | return 0; |
| 299 | |
| 300 | if (flags & MEDIA_LNK_FL_ENABLED) { |
| 301 | if (source->sink) |
| 302 | return -EBUSY; |
| 303 | source->sink = remote->entity; |
Laurent Pinchart | d9b45ed | 2013-07-10 18:37:27 -0300 | [diff] [blame] | 304 | source->sink_pad = remote->index; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 305 | } else { |
| 306 | source->sink = NULL; |
Laurent Pinchart | d9b45ed | 2013-07-10 18:37:27 -0300 | [diff] [blame] | 307 | source->sink_pad = 0; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | return 0; |
| 311 | } |
| 312 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 313 | /* ----------------------------------------------------------------------------- |
| 314 | * Initialization |
| 315 | */ |
| 316 | |
Laurent Pinchart | 44f4619 | 2016-02-24 19:10:04 -0300 | [diff] [blame] | 317 | #define VSP1_ENTITY_ROUTE(ent) \ |
| 318 | { VSP1_ENTITY_##ent, 0, VI6_DPR_##ent##_ROUTE, \ |
| 319 | { VI6_DPR_NODE_##ent }, VI6_DPR_NODE_##ent } |
| 320 | |
| 321 | #define VSP1_ENTITY_ROUTE_RPF(idx) \ |
| 322 | { VSP1_ENTITY_RPF, idx, VI6_DPR_RPF_ROUTE(idx), \ |
| 323 | { 0, }, VI6_DPR_NODE_RPF(idx) } |
| 324 | |
| 325 | #define VSP1_ENTITY_ROUTE_UDS(idx) \ |
| 326 | { VSP1_ENTITY_UDS, idx, VI6_DPR_UDS_ROUTE(idx), \ |
| 327 | { VI6_DPR_NODE_UDS(idx) }, VI6_DPR_NODE_UDS(idx) } |
| 328 | |
| 329 | #define VSP1_ENTITY_ROUTE_WPF(idx) \ |
| 330 | { VSP1_ENTITY_WPF, idx, 0, \ |
| 331 | { VI6_DPR_NODE_WPF(idx) }, VI6_DPR_NODE_WPF(idx) } |
| 332 | |
Laurent Pinchart | d9b45ed | 2013-07-10 18:37:27 -0300 | [diff] [blame] | 333 | static const struct vsp1_route vsp1_routes[] = { |
Laurent Pinchart | 629bb6d | 2013-07-10 18:03:46 -0300 | [diff] [blame] | 334 | { VSP1_ENTITY_BRU, 0, VI6_DPR_BRU_ROUTE, |
| 335 | { VI6_DPR_NODE_BRU_IN(0), VI6_DPR_NODE_BRU_IN(1), |
Laurent Pinchart | 7f2d50f | 2015-09-07 08:05:39 -0300 | [diff] [blame] | 336 | VI6_DPR_NODE_BRU_IN(2), VI6_DPR_NODE_BRU_IN(3), |
Laurent Pinchart | 44f4619 | 2016-02-24 19:10:04 -0300 | [diff] [blame] | 337 | VI6_DPR_NODE_BRU_IN(4) }, VI6_DPR_NODE_BRU_OUT }, |
Laurent Pinchart | 1fd87bf | 2015-11-11 23:04:44 -0200 | [diff] [blame] | 338 | VSP1_ENTITY_ROUTE(CLU), |
Laurent Pinchart | 44f4619 | 2016-02-24 19:10:04 -0300 | [diff] [blame] | 339 | VSP1_ENTITY_ROUTE(HSI), |
| 340 | VSP1_ENTITY_ROUTE(HST), |
| 341 | { VSP1_ENTITY_LIF, 0, 0, { VI6_DPR_NODE_LIF, }, VI6_DPR_NODE_LIF }, |
| 342 | VSP1_ENTITY_ROUTE(LUT), |
| 343 | VSP1_ENTITY_ROUTE_RPF(0), |
| 344 | VSP1_ENTITY_ROUTE_RPF(1), |
| 345 | VSP1_ENTITY_ROUTE_RPF(2), |
| 346 | VSP1_ENTITY_ROUTE_RPF(3), |
| 347 | VSP1_ENTITY_ROUTE_RPF(4), |
| 348 | VSP1_ENTITY_ROUTE(SRU), |
| 349 | VSP1_ENTITY_ROUTE_UDS(0), |
| 350 | VSP1_ENTITY_ROUTE_UDS(1), |
| 351 | VSP1_ENTITY_ROUTE_UDS(2), |
| 352 | VSP1_ENTITY_ROUTE_WPF(0), |
| 353 | VSP1_ENTITY_ROUTE_WPF(1), |
| 354 | VSP1_ENTITY_ROUTE_WPF(2), |
| 355 | VSP1_ENTITY_ROUTE_WPF(3), |
Laurent Pinchart | d9b45ed | 2013-07-10 18:37:27 -0300 | [diff] [blame] | 356 | }; |
| 357 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 358 | int vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity, |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 359 | const char *name, unsigned int num_pads, |
Laurent Pinchart | 6a8e07b | 2016-02-15 22:10:26 -0200 | [diff] [blame] | 360 | const struct v4l2_subdev_ops *ops, u32 function) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 361 | { |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 362 | struct v4l2_subdev *subdev; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 363 | unsigned int i; |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 364 | int ret; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 365 | |
Laurent Pinchart | d9b45ed | 2013-07-10 18:37:27 -0300 | [diff] [blame] | 366 | for (i = 0; i < ARRAY_SIZE(vsp1_routes); ++i) { |
| 367 | if (vsp1_routes[i].type == entity->type && |
| 368 | vsp1_routes[i].index == entity->index) { |
| 369 | entity->route = &vsp1_routes[i]; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 370 | break; |
| 371 | } |
| 372 | } |
| 373 | |
Laurent Pinchart | d9b45ed | 2013-07-10 18:37:27 -0300 | [diff] [blame] | 374 | if (i == ARRAY_SIZE(vsp1_routes)) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 375 | return -EINVAL; |
| 376 | |
Laurent Pinchart | 34e77ed | 2016-06-26 08:09:31 -0300 | [diff] [blame] | 377 | mutex_init(&entity->lock); |
| 378 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 379 | entity->vsp1 = vsp1; |
| 380 | entity->source_pad = num_pads - 1; |
| 381 | |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 382 | /* Allocate and initialize pads. */ |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 383 | entity->pads = devm_kzalloc(vsp1->dev, num_pads * sizeof(*entity->pads), |
| 384 | GFP_KERNEL); |
| 385 | if (entity->pads == NULL) |
| 386 | return -ENOMEM; |
| 387 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 388 | for (i = 0; i < num_pads - 1; ++i) |
| 389 | entity->pads[i].flags = MEDIA_PAD_FL_SINK; |
| 390 | |
| 391 | entity->pads[num_pads - 1].flags = MEDIA_PAD_FL_SOURCE; |
| 392 | |
| 393 | /* Initialize the media entity. */ |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 394 | ret = media_entity_pads_init(&entity->subdev.entity, num_pads, |
| 395 | entity->pads); |
| 396 | if (ret < 0) |
| 397 | return ret; |
| 398 | |
| 399 | /* Initialize the V4L2 subdev. */ |
| 400 | subdev = &entity->subdev; |
| 401 | v4l2_subdev_init(subdev, ops); |
| 402 | |
Laurent Pinchart | 6a8e07b | 2016-02-15 22:10:26 -0200 | [diff] [blame] | 403 | subdev->entity.function = function; |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 404 | subdev->entity.ops = &vsp1->media_ops; |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 405 | subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; |
| 406 | |
| 407 | snprintf(subdev->name, sizeof(subdev->name), "%s %s", |
| 408 | dev_name(vsp1->dev), name); |
| 409 | |
Laurent Pinchart | 0efdf0f | 2015-11-15 20:09:08 -0200 | [diff] [blame] | 410 | vsp1_entity_init_cfg(subdev, NULL); |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 411 | |
Laurent Pinchart | 9dbed95 | 2017-02-26 10:29:50 -0300 | [diff] [blame^] | 412 | /* |
| 413 | * Allocate the pad configuration to store formats and selection |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 414 | * rectangles. |
| 415 | */ |
| 416 | entity->config = v4l2_subdev_alloc_pad_config(&entity->subdev); |
| 417 | if (entity->config == NULL) { |
| 418 | media_entity_cleanup(&entity->subdev.entity); |
| 419 | return -ENOMEM; |
| 420 | } |
| 421 | |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 422 | return 0; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | void vsp1_entity_destroy(struct vsp1_entity *entity) |
| 426 | { |
Laurent Pinchart | 5243453 | 2015-11-17 12:23:23 -0200 | [diff] [blame] | 427 | if (entity->ops && entity->ops->destroy) |
| 428 | entity->ops->destroy(entity); |
Laurent Pinchart | a626e64 | 2013-07-10 12:03:30 -0300 | [diff] [blame] | 429 | if (entity->subdev.ctrl_handler) |
| 430 | v4l2_ctrl_handler_free(entity->subdev.ctrl_handler); |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 431 | v4l2_subdev_free_pad_config(entity->config); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 432 | media_entity_cleanup(&entity->subdev.entity); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 433 | } |