// SPDX-License-Identifier: GPL-2.0+ /* * vsp1_entity.c -- R-Car VSP1 Base Entity * * Copyright (C) 2013-2014 Renesas Electronics Corporation * * Contact: Laurent Pinchart ([email protected]) */ #include <linux/device.h> #include <linux/gfp.h> #include <media/media-entity.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-subdev.h> #include "vsp1.h" #include "vsp1_dl.h" #include "vsp1_entity.h" #include "vsp1_pipe.h" #include "vsp1_rwpf.h" void vsp1_entity_route_setup(struct vsp1_entity *entity, struct vsp1_pipeline *pipe, struct vsp1_dl_body *dlb) { … } void vsp1_entity_configure_stream(struct vsp1_entity *entity, struct v4l2_subdev_state *state, struct vsp1_pipeline *pipe, struct vsp1_dl_list *dl, struct vsp1_dl_body *dlb) { … } void vsp1_entity_configure_frame(struct vsp1_entity *entity, struct vsp1_pipeline *pipe, struct vsp1_dl_list *dl, struct vsp1_dl_body *dlb) { … } void vsp1_entity_configure_partition(struct vsp1_entity *entity, struct vsp1_pipeline *pipe, const struct vsp1_partition *partition, struct vsp1_dl_list *dl, struct vsp1_dl_body *dlb) { … } /* ----------------------------------------------------------------------------- * V4L2 Subdevice Operations */ /** * vsp1_entity_get_state - Get the subdev state for an entity * @entity: the entity * @sd_state: the TRY state * @which: state selector (ACTIVE or TRY) * * When called with which set to V4L2_SUBDEV_FORMAT_ACTIVE the caller must hold * the entity lock to access the returned configuration. * * Return the subdev state requested by the which argument. The TRY state is * passed explicitly to the function through the sd_state argument and simply * returned when requested. The ACTIVE state comes from the entity structure. */ struct v4l2_subdev_state * vsp1_entity_get_state(struct vsp1_entity *entity, struct v4l2_subdev_state *sd_state, enum v4l2_subdev_format_whence which) { … } /* * vsp1_subdev_get_pad_format - Subdev pad get_fmt handler * @subdev: V4L2 subdevice * @sd_state: V4L2 subdev state * @fmt: V4L2 subdev format * * This function implements the subdev get_fmt pad operation. It can be used as * a direct drop-in for the operation handler. */ int vsp1_subdev_get_pad_format(struct v4l2_subdev *subdev, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *fmt) { … } /* * vsp1_subdev_enum_mbus_code - Subdev pad enum_mbus_code handler * @subdev: V4L2 subdevice * @sd_state: V4L2 subdev state * @code: Media bus code enumeration * @codes: Array of supported media bus codes * @ncodes: Number of supported media bus codes * * This function implements the subdev enum_mbus_code pad operation for entities * that do not support format conversion. It enumerates the given supported * media bus codes on the sink pad and reports a source pad format identical to * the sink pad. */ int vsp1_subdev_enum_mbus_code(struct v4l2_subdev *subdev, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code, const unsigned int *codes, unsigned int ncodes) { … } /* * vsp1_subdev_enum_frame_size - Subdev pad enum_frame_size handler * @subdev: V4L2 subdevice * @sd_state: V4L2 subdev state * @fse: Frame size enumeration * @min_width: Minimum image width * @min_height: Minimum image height * @max_width: Maximum image width * @max_height: Maximum image height * * This function implements the subdev enum_frame_size pad operation for * entities that do not support scaling or cropping. It reports the given * minimum and maximum frame width and height on the sink pad, and a fixed * source pad size identical to the sink pad. */ int vsp1_subdev_enum_frame_size(struct v4l2_subdev *subdev, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_frame_size_enum *fse, unsigned int min_width, unsigned int min_height, unsigned int max_width, unsigned int max_height) { … } /* * vsp1_subdev_set_pad_format - Subdev pad set_fmt handler * @subdev: V4L2 subdevice * @sd_state: V4L2 subdev state * @fmt: V4L2 subdev format * @codes: Array of supported media bus codes * @ncodes: Number of supported media bus codes * @min_width: Minimum image width * @min_height: Minimum image height * @max_width: Maximum image width * @max_height: Maximum image height * * This function implements the subdev set_fmt pad operation for entities that * do not support scaling or cropping. It defaults to the first supplied media * bus code if the requested code isn't supported, clamps the size to the * supplied minimum and maximum, and propagates the sink pad format to the * source pad. */ int vsp1_subdev_set_pad_format(struct v4l2_subdev *subdev, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *fmt, const unsigned int *codes, unsigned int ncodes, unsigned int min_width, unsigned int min_height, unsigned int max_width, unsigned int max_height) { … } static int vsp1_entity_init_state(struct v4l2_subdev *subdev, struct v4l2_subdev_state *sd_state) { … } static const struct v4l2_subdev_internal_ops vsp1_entity_internal_ops = …; /* ----------------------------------------------------------------------------- * Media Operations */ static inline struct vsp1_entity * media_entity_to_vsp1_entity(struct media_entity *entity) { … } static int vsp1_entity_link_setup_source(const struct media_pad *source_pad, const struct media_pad *sink_pad, u32 flags) { … } static int vsp1_entity_link_setup_sink(const struct media_pad *source_pad, const struct media_pad *sink_pad, u32 flags) { … } int vsp1_entity_link_setup(struct media_entity *entity, const struct media_pad *local, const struct media_pad *remote, u32 flags) { … } /** * vsp1_entity_remote_pad - Find the pad at the remote end of a link * @pad: Pad at the local end of the link * * Search for a remote pad connected to the given pad by iterating over all * links originating or terminating at that pad until an enabled link is found. * * Our link setup implementation guarantees that the output fan-out will not be * higher than one for the data pipelines, except for the links to the HGO and * HGT that can be enabled in addition to a regular data link. When traversing * outgoing links this function ignores HGO and HGT entities and should thus be * used in place of the generic media_pad_remote_pad_first() function to * traverse data pipelines. * * Return a pointer to the pad at the remote end of the first found enabled * link, or NULL if no enabled link has been found. */ struct media_pad *vsp1_entity_remote_pad(struct media_pad *pad) { … } /* ----------------------------------------------------------------------------- * Initialization */ #define VSP1_ENTITY_ROUTE(ent) … #define VSP1_ENTITY_ROUTE_RPF(idx) … #define VSP1_ENTITY_ROUTE_UDS(idx) … #define VSP1_ENTITY_ROUTE_UIF(idx) … #define VSP1_ENTITY_ROUTE_WPF(idx) … static const struct vsp1_route vsp1_routes[] = …; int vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity, const char *name, unsigned int num_pads, const struct v4l2_subdev_ops *ops, u32 function) { … } void vsp1_entity_destroy(struct vsp1_entity *entity) { … }