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