Lines Matching +full:fixed +full:- +full:links

1 // SPDX-License-Identifier: GPL-2.0+
3 * vsp1_entity.c -- R-Car VSP1 Base Entity
5 * Copyright (C) 2013-2014 Renesas Electronics Corporation
13 #include <media/media-entity.h>
14 #include <media/v4l2-ctrls.h>
15 #include <media/v4l2-subdev.h>
30 if (entity->type == VSP1_ENTITY_HGO) { in vsp1_entity_route_setup()
37 source = entity->sources[0]; in vsp1_entity_route_setup()
38 smppt = (pipe->output->entity.index << VI6_DPR_SMPPT_TGW_SHIFT) in vsp1_entity_route_setup()
39 | (source->route->output << VI6_DPR_SMPPT_PT_SHIFT); in vsp1_entity_route_setup()
43 } else if (entity->type == VSP1_ENTITY_HGT) { in vsp1_entity_route_setup()
50 source = entity->sources[0]; in vsp1_entity_route_setup()
51 smppt = (pipe->output->entity.index << VI6_DPR_SMPPT_TGW_SHIFT) in vsp1_entity_route_setup()
52 | (source->route->output << VI6_DPR_SMPPT_PT_SHIFT); in vsp1_entity_route_setup()
59 if (source->route->reg == 0) in vsp1_entity_route_setup()
62 route = source->sink->route->inputs[source->sink_pad]; in vsp1_entity_route_setup()
67 if (source->type == VSP1_ENTITY_BRS) in vsp1_entity_route_setup()
69 vsp1_dl_body_write(dlb, source->route->reg, route); in vsp1_entity_route_setup()
78 if (entity->ops->configure_stream) in vsp1_entity_configure_stream()
79 entity->ops->configure_stream(entity, state, pipe, dl, dlb); in vsp1_entity_configure_stream()
87 if (entity->ops->configure_frame) in vsp1_entity_configure_frame()
88 entity->ops->configure_frame(entity, pipe, dl, dlb); in vsp1_entity_configure_frame()
97 if (entity->ops->configure_partition) in vsp1_entity_configure_partition()
98 entity->ops->configure_partition(entity, pipe, partition, in vsp1_entity_configure_partition()
102 /* -----------------------------------------------------------------------------
107 * vsp1_entity_get_state - Get the subdev state for an entity
126 return entity->state; in vsp1_entity_get_state()
134 * vsp1_subdev_get_pad_format - Subdev pad get_fmt handler
140 * a direct drop-in for the operation handler.
149 state = vsp1_entity_get_state(entity, sd_state, fmt->which); in vsp1_subdev_get_pad_format()
151 return -EINVAL; in vsp1_subdev_get_pad_format()
153 mutex_lock(&entity->lock); in vsp1_subdev_get_pad_format()
154 fmt->format = *v4l2_subdev_state_get_format(state, fmt->pad); in vsp1_subdev_get_pad_format()
155 mutex_unlock(&entity->lock); in vsp1_subdev_get_pad_format()
161 * vsp1_subdev_enum_mbus_code - Subdev pad enum_mbus_code handler
180 if (code->pad == 0) { in vsp1_subdev_enum_mbus_code()
181 if (code->index >= ncodes) in vsp1_subdev_enum_mbus_code()
182 return -EINVAL; in vsp1_subdev_enum_mbus_code()
184 code->code = codes[code->index]; in vsp1_subdev_enum_mbus_code()
193 if (code->index) in vsp1_subdev_enum_mbus_code()
194 return -EINVAL; in vsp1_subdev_enum_mbus_code()
196 state = vsp1_entity_get_state(entity, sd_state, code->which); in vsp1_subdev_enum_mbus_code()
198 return -EINVAL; in vsp1_subdev_enum_mbus_code()
200 mutex_lock(&entity->lock); in vsp1_subdev_enum_mbus_code()
202 code->code = format->code; in vsp1_subdev_enum_mbus_code()
203 mutex_unlock(&entity->lock); in vsp1_subdev_enum_mbus_code()
210 * vsp1_subdev_enum_frame_size - Subdev pad enum_frame_size handler
221 * minimum and maximum frame width and height on the sink pad, and a fixed
235 state = vsp1_entity_get_state(entity, sd_state, fse->which); in vsp1_subdev_enum_frame_size()
237 return -EINVAL; in vsp1_subdev_enum_frame_size()
239 format = v4l2_subdev_state_get_format(state, fse->pad); in vsp1_subdev_enum_frame_size()
241 mutex_lock(&entity->lock); in vsp1_subdev_enum_frame_size()
243 if (fse->index || fse->code != format->code) { in vsp1_subdev_enum_frame_size()
244 ret = -EINVAL; in vsp1_subdev_enum_frame_size()
248 if (fse->pad == 0) { in vsp1_subdev_enum_frame_size()
249 fse->min_width = min_width; in vsp1_subdev_enum_frame_size()
250 fse->max_width = max_width; in vsp1_subdev_enum_frame_size()
251 fse->min_height = min_height; in vsp1_subdev_enum_frame_size()
252 fse->max_height = max_height; in vsp1_subdev_enum_frame_size()
255 * The size on the source pad are fixed and always identical to in vsp1_subdev_enum_frame_size()
258 fse->min_width = format->width; in vsp1_subdev_enum_frame_size()
259 fse->max_width = format->width; in vsp1_subdev_enum_frame_size()
260 fse->min_height = format->height; in vsp1_subdev_enum_frame_size()
261 fse->max_height = format->height; in vsp1_subdev_enum_frame_size()
265 mutex_unlock(&entity->lock); in vsp1_subdev_enum_frame_size()
270 * vsp1_subdev_set_pad_format - Subdev pad set_fmt handler
301 mutex_lock(&entity->lock); in vsp1_subdev_set_pad_format()
303 state = vsp1_entity_get_state(entity, sd_state, fmt->which); in vsp1_subdev_set_pad_format()
305 ret = -EINVAL; in vsp1_subdev_set_pad_format()
309 format = v4l2_subdev_state_get_format(state, fmt->pad); in vsp1_subdev_set_pad_format()
311 if (fmt->pad == entity->source_pad) { in vsp1_subdev_set_pad_format()
313 fmt->format = *format; in vsp1_subdev_set_pad_format()
322 if (fmt->format.code == codes[i]) in vsp1_subdev_set_pad_format()
326 format->code = i < ncodes ? codes[i] : codes[0]; in vsp1_subdev_set_pad_format()
327 format->width = clamp_t(unsigned int, fmt->format.width, in vsp1_subdev_set_pad_format()
329 format->height = clamp_t(unsigned int, fmt->format.height, in vsp1_subdev_set_pad_format()
331 format->field = V4L2_FIELD_NONE; in vsp1_subdev_set_pad_format()
332 format->colorspace = V4L2_COLORSPACE_SRGB; in vsp1_subdev_set_pad_format()
334 fmt->format = *format; in vsp1_subdev_set_pad_format()
337 format = v4l2_subdev_state_get_format(state, entity->source_pad); in vsp1_subdev_set_pad_format()
338 *format = fmt->format; in vsp1_subdev_set_pad_format()
341 selection = v4l2_subdev_state_get_crop(state, fmt->pad); in vsp1_subdev_set_pad_format()
342 selection->left = 0; in vsp1_subdev_set_pad_format()
343 selection->top = 0; in vsp1_subdev_set_pad_format()
344 selection->width = format->width; in vsp1_subdev_set_pad_format()
345 selection->height = format->height; in vsp1_subdev_set_pad_format()
347 selection = v4l2_subdev_state_get_compose(state, fmt->pad); in vsp1_subdev_set_pad_format()
348 selection->left = 0; in vsp1_subdev_set_pad_format()
349 selection->top = 0; in vsp1_subdev_set_pad_format()
350 selection->width = format->width; in vsp1_subdev_set_pad_format()
351 selection->height = format->height; in vsp1_subdev_set_pad_format()
354 mutex_unlock(&entity->lock); in vsp1_subdev_set_pad_format()
364 for (pad = 0; pad < subdev->entity.num_pads - 1; ++pad) { in vsp1_entity_init_state()
381 /* -----------------------------------------------------------------------------
397 source = media_entity_to_vsp1_entity(source_pad->entity); in vsp1_entity_link_setup_source()
399 if (!source->route) in vsp1_entity_link_setup_source()
404 = media_entity_to_vsp1_entity(sink_pad->entity); in vsp1_entity_link_setup_source()
407 * Fan-out is limited to one for the normal data path plus in vsp1_entity_link_setup_source()
410 if (sink->type != VSP1_ENTITY_HGO && in vsp1_entity_link_setup_source()
411 sink->type != VSP1_ENTITY_HGT) { in vsp1_entity_link_setup_source()
412 if (source->sink) in vsp1_entity_link_setup_source()
413 return -EBUSY; in vsp1_entity_link_setup_source()
414 source->sink = sink; in vsp1_entity_link_setup_source()
415 source->sink_pad = sink_pad->index; in vsp1_entity_link_setup_source()
418 source->sink = NULL; in vsp1_entity_link_setup_source()
419 source->sink_pad = 0; in vsp1_entity_link_setup_source()
432 sink = media_entity_to_vsp1_entity(sink_pad->entity); in vsp1_entity_link_setup_sink()
433 source = media_entity_to_vsp1_entity(source_pad->entity); in vsp1_entity_link_setup_sink()
436 /* Fan-in is limited to one. */ in vsp1_entity_link_setup_sink()
437 if (sink->sources[sink_pad->index]) in vsp1_entity_link_setup_sink()
438 return -EBUSY; in vsp1_entity_link_setup_sink()
440 sink->sources[sink_pad->index] = source; in vsp1_entity_link_setup_sink()
442 sink->sources[sink_pad->index] = NULL; in vsp1_entity_link_setup_sink()
452 if (local->flags & MEDIA_PAD_FL_SOURCE) in vsp1_entity_link_setup()
459 * vsp1_entity_remote_pad - Find the pad at the remote end of a link
463 * links originating or terminating at that pad until an enabled link is found.
465 * Our link setup implementation guarantees that the output fan-out will not be
466 * higher than one for the data pipelines, except for the links to the HGO and
468 * outgoing links this function ignores HGO and HGT entities and should thus be
479 list_for_each_entry(link, &pad->entity->links, list) { in vsp1_entity_remote_pad()
482 if (!(link->flags & MEDIA_LNK_FL_ENABLED)) in vsp1_entity_remote_pad()
486 if (link->sink == pad) in vsp1_entity_remote_pad()
487 return link->source; in vsp1_entity_remote_pad()
489 if (link->source != pad) in vsp1_entity_remote_pad()
493 if (!is_media_entity_v4l2_subdev(link->sink->entity)) in vsp1_entity_remote_pad()
494 return link->sink; in vsp1_entity_remote_pad()
496 entity = media_entity_to_vsp1_entity(link->sink->entity); in vsp1_entity_remote_pad()
497 if (entity->type != VSP1_ENTITY_HGO && in vsp1_entity_remote_pad()
498 entity->type != VSP1_ENTITY_HGT) in vsp1_entity_remote_pad()
499 return link->sink; in vsp1_entity_remote_pad()
506 /* -----------------------------------------------------------------------------
572 if (vsp1_routes[i].type == entity->type && in vsp1_entity_init()
573 vsp1_routes[i].index == entity->index) { in vsp1_entity_init()
574 entity->route = &vsp1_routes[i]; in vsp1_entity_init()
580 return -EINVAL; in vsp1_entity_init()
582 mutex_init(&entity->lock); in vsp1_entity_init()
584 entity->vsp1 = vsp1; in vsp1_entity_init()
585 entity->source_pad = num_pads - 1; in vsp1_entity_init()
588 entity->pads = devm_kcalloc(vsp1->dev, in vsp1_entity_init()
589 num_pads, sizeof(*entity->pads), in vsp1_entity_init()
591 if (entity->pads == NULL) in vsp1_entity_init()
592 return -ENOMEM; in vsp1_entity_init()
594 for (i = 0; i < num_pads - 1; ++i) in vsp1_entity_init()
595 entity->pads[i].flags = MEDIA_PAD_FL_SINK; in vsp1_entity_init()
597 entity->sources = devm_kcalloc(vsp1->dev, max(num_pads - 1, 1U), in vsp1_entity_init()
598 sizeof(*entity->sources), GFP_KERNEL); in vsp1_entity_init()
599 if (entity->sources == NULL) in vsp1_entity_init()
600 return -ENOMEM; in vsp1_entity_init()
602 /* Single-pad entities only have a sink. */ in vsp1_entity_init()
603 entity->pads[num_pads - 1].flags = num_pads > 1 ? MEDIA_PAD_FL_SOURCE in vsp1_entity_init()
607 ret = media_entity_pads_init(&entity->subdev.entity, num_pads, in vsp1_entity_init()
608 entity->pads); in vsp1_entity_init()
613 subdev = &entity->subdev; in vsp1_entity_init()
615 subdev->internal_ops = &vsp1_entity_internal_ops; in vsp1_entity_init()
617 subdev->entity.function = function; in vsp1_entity_init()
618 subdev->entity.ops = &vsp1->media_ops; in vsp1_entity_init()
619 subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in vsp1_entity_init()
621 snprintf(subdev->name, sizeof(subdev->name), "%s %s", in vsp1_entity_init()
622 dev_name(vsp1->dev), name); in vsp1_entity_init()
634 entity->state = __v4l2_subdev_state_alloc(&entity->subdev, in vsp1_entity_init()
635 "vsp1:state->lock", &key); in vsp1_entity_init()
636 if (IS_ERR(entity->state)) { in vsp1_entity_init()
637 media_entity_cleanup(&entity->subdev.entity); in vsp1_entity_init()
638 return PTR_ERR(entity->state); in vsp1_entity_init()
646 if (entity->ops && entity->ops->destroy) in vsp1_entity_destroy()
647 entity->ops->destroy(entity); in vsp1_entity_destroy()
648 if (entity->subdev.ctrl_handler) in vsp1_entity_destroy()
649 v4l2_ctrl_handler_free(entity->subdev.ctrl_handler); in vsp1_entity_destroy()
650 __v4l2_subdev_state_free(entity->state); in vsp1_entity_destroy()
651 media_entity_cleanup(&entity->subdev.entity); in vsp1_entity_destroy()