18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * vsp1_entity.h  --  R-Car VSP1 Base Entity
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2013-2014 Renesas Electronics Corporation
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#ifndef __VSP1_ENTITY_H__
108c2ecf20Sopenharmony_ci#define __VSP1_ENTITY_H__
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/list.h>
138c2ecf20Sopenharmony_ci#include <linux/mutex.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <media/v4l2-subdev.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistruct vsp1_device;
188c2ecf20Sopenharmony_cistruct vsp1_dl_body;
198c2ecf20Sopenharmony_cistruct vsp1_dl_list;
208c2ecf20Sopenharmony_cistruct vsp1_pipeline;
218c2ecf20Sopenharmony_cistruct vsp1_partition;
228c2ecf20Sopenharmony_cistruct vsp1_partition_window;
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cienum vsp1_entity_type {
258c2ecf20Sopenharmony_ci	VSP1_ENTITY_BRS,
268c2ecf20Sopenharmony_ci	VSP1_ENTITY_BRU,
278c2ecf20Sopenharmony_ci	VSP1_ENTITY_CLU,
288c2ecf20Sopenharmony_ci	VSP1_ENTITY_HGO,
298c2ecf20Sopenharmony_ci	VSP1_ENTITY_HGT,
308c2ecf20Sopenharmony_ci	VSP1_ENTITY_HSI,
318c2ecf20Sopenharmony_ci	VSP1_ENTITY_HST,
328c2ecf20Sopenharmony_ci	VSP1_ENTITY_LIF,
338c2ecf20Sopenharmony_ci	VSP1_ENTITY_LUT,
348c2ecf20Sopenharmony_ci	VSP1_ENTITY_RPF,
358c2ecf20Sopenharmony_ci	VSP1_ENTITY_SRU,
368c2ecf20Sopenharmony_ci	VSP1_ENTITY_UDS,
378c2ecf20Sopenharmony_ci	VSP1_ENTITY_UIF,
388c2ecf20Sopenharmony_ci	VSP1_ENTITY_WPF,
398c2ecf20Sopenharmony_ci};
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#define VSP1_ENTITY_MAX_INPUTS		5	/* For the BRU */
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci/*
448c2ecf20Sopenharmony_ci * struct vsp1_route - Entity routing configuration
458c2ecf20Sopenharmony_ci * @type: Entity type this routing entry is associated with
468c2ecf20Sopenharmony_ci * @index: Entity index this routing entry is associated with
478c2ecf20Sopenharmony_ci * @reg: Output routing configuration register
488c2ecf20Sopenharmony_ci * @inputs: Target node value for each input
498c2ecf20Sopenharmony_ci * @output: Target node value for entity output
508c2ecf20Sopenharmony_ci *
518c2ecf20Sopenharmony_ci * Each $vsp1_route entry describes routing configuration for the entity
528c2ecf20Sopenharmony_ci * specified by the entry's @type and @index. @reg indicates the register that
538c2ecf20Sopenharmony_ci * holds output routing configuration for the entity, and the @inputs array
548c2ecf20Sopenharmony_ci * store the target node value for each input of the entity. The @output field
558c2ecf20Sopenharmony_ci * stores the target node value of the entity output when used as a source for
568c2ecf20Sopenharmony_ci * histogram generation.
578c2ecf20Sopenharmony_ci */
588c2ecf20Sopenharmony_cistruct vsp1_route {
598c2ecf20Sopenharmony_ci	enum vsp1_entity_type type;
608c2ecf20Sopenharmony_ci	unsigned int index;
618c2ecf20Sopenharmony_ci	unsigned int reg;
628c2ecf20Sopenharmony_ci	unsigned int inputs[VSP1_ENTITY_MAX_INPUTS];
638c2ecf20Sopenharmony_ci	unsigned int output;
648c2ecf20Sopenharmony_ci};
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci/**
678c2ecf20Sopenharmony_ci * struct vsp1_entity_operations - Entity operations
688c2ecf20Sopenharmony_ci * @destroy:	Destroy the entity.
698c2ecf20Sopenharmony_ci * @configure_stream:	Setup the hardware parameters for the stream which do
708c2ecf20Sopenharmony_ci *			not vary between frames (pipeline, formats). Note that
718c2ecf20Sopenharmony_ci *			the vsp1_dl_list argument is only valid for display
728c2ecf20Sopenharmony_ci *			pipeline and will be NULL for mem-to-mem pipelines.
738c2ecf20Sopenharmony_ci * @configure_frame:	Configure the runtime parameters for each frame.
748c2ecf20Sopenharmony_ci * @configure_partition: Configure partition specific parameters.
758c2ecf20Sopenharmony_ci * @max_width:	Return the max supported width of data that the entity can
768c2ecf20Sopenharmony_ci *		process in a single operation.
778c2ecf20Sopenharmony_ci * @partition:	Process the partition construction based on this entity's
788c2ecf20Sopenharmony_ci *		configuration.
798c2ecf20Sopenharmony_ci */
808c2ecf20Sopenharmony_cistruct vsp1_entity_operations {
818c2ecf20Sopenharmony_ci	void (*destroy)(struct vsp1_entity *);
828c2ecf20Sopenharmony_ci	void (*configure_stream)(struct vsp1_entity *, struct vsp1_pipeline *,
838c2ecf20Sopenharmony_ci				 struct vsp1_dl_list *, struct vsp1_dl_body *);
848c2ecf20Sopenharmony_ci	void (*configure_frame)(struct vsp1_entity *, struct vsp1_pipeline *,
858c2ecf20Sopenharmony_ci				struct vsp1_dl_list *, struct vsp1_dl_body *);
868c2ecf20Sopenharmony_ci	void (*configure_partition)(struct vsp1_entity *,
878c2ecf20Sopenharmony_ci				    struct vsp1_pipeline *,
888c2ecf20Sopenharmony_ci				    struct vsp1_dl_list *,
898c2ecf20Sopenharmony_ci				    struct vsp1_dl_body *);
908c2ecf20Sopenharmony_ci	unsigned int (*max_width)(struct vsp1_entity *, struct vsp1_pipeline *);
918c2ecf20Sopenharmony_ci	void (*partition)(struct vsp1_entity *, struct vsp1_pipeline *,
928c2ecf20Sopenharmony_ci			  struct vsp1_partition *, unsigned int,
938c2ecf20Sopenharmony_ci			  struct vsp1_partition_window *);
948c2ecf20Sopenharmony_ci};
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_cistruct vsp1_entity {
978c2ecf20Sopenharmony_ci	struct vsp1_device *vsp1;
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	const struct vsp1_entity_operations *ops;
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	enum vsp1_entity_type type;
1028c2ecf20Sopenharmony_ci	unsigned int index;
1038c2ecf20Sopenharmony_ci	const struct vsp1_route *route;
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	struct vsp1_pipeline *pipe;
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	struct list_head list_dev;
1088c2ecf20Sopenharmony_ci	struct list_head list_pipe;
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	struct media_pad *pads;
1118c2ecf20Sopenharmony_ci	unsigned int source_pad;
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	struct vsp1_entity **sources;
1148c2ecf20Sopenharmony_ci	struct vsp1_entity *sink;
1158c2ecf20Sopenharmony_ci	unsigned int sink_pad;
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci	struct v4l2_subdev subdev;
1188c2ecf20Sopenharmony_ci	struct v4l2_subdev_pad_config *config;
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	struct mutex lock;	/* Protects the pad config */
1218c2ecf20Sopenharmony_ci};
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_cistatic inline struct vsp1_entity *to_vsp1_entity(struct v4l2_subdev *subdev)
1248c2ecf20Sopenharmony_ci{
1258c2ecf20Sopenharmony_ci	return container_of(subdev, struct vsp1_entity, subdev);
1268c2ecf20Sopenharmony_ci}
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ciint vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity,
1298c2ecf20Sopenharmony_ci		     const char *name, unsigned int num_pads,
1308c2ecf20Sopenharmony_ci		     const struct v4l2_subdev_ops *ops, u32 function);
1318c2ecf20Sopenharmony_civoid vsp1_entity_destroy(struct vsp1_entity *entity);
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ciextern const struct v4l2_subdev_internal_ops vsp1_subdev_internal_ops;
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ciint vsp1_entity_link_setup(struct media_entity *entity,
1368c2ecf20Sopenharmony_ci			   const struct media_pad *local,
1378c2ecf20Sopenharmony_ci			   const struct media_pad *remote, u32 flags);
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_cistruct v4l2_subdev_pad_config *
1408c2ecf20Sopenharmony_civsp1_entity_get_pad_config(struct vsp1_entity *entity,
1418c2ecf20Sopenharmony_ci			   struct v4l2_subdev_pad_config *cfg,
1428c2ecf20Sopenharmony_ci			   enum v4l2_subdev_format_whence which);
1438c2ecf20Sopenharmony_cistruct v4l2_mbus_framefmt *
1448c2ecf20Sopenharmony_civsp1_entity_get_pad_format(struct vsp1_entity *entity,
1458c2ecf20Sopenharmony_ci			   struct v4l2_subdev_pad_config *cfg,
1468c2ecf20Sopenharmony_ci			   unsigned int pad);
1478c2ecf20Sopenharmony_cistruct v4l2_rect *
1488c2ecf20Sopenharmony_civsp1_entity_get_pad_selection(struct vsp1_entity *entity,
1498c2ecf20Sopenharmony_ci			      struct v4l2_subdev_pad_config *cfg,
1508c2ecf20Sopenharmony_ci			      unsigned int pad, unsigned int target);
1518c2ecf20Sopenharmony_ciint vsp1_entity_init_cfg(struct v4l2_subdev *subdev,
1528c2ecf20Sopenharmony_ci			 struct v4l2_subdev_pad_config *cfg);
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_civoid vsp1_entity_route_setup(struct vsp1_entity *entity,
1558c2ecf20Sopenharmony_ci			     struct vsp1_pipeline *pipe,
1568c2ecf20Sopenharmony_ci			     struct vsp1_dl_body *dlb);
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_civoid vsp1_entity_configure_stream(struct vsp1_entity *entity,
1598c2ecf20Sopenharmony_ci				  struct vsp1_pipeline *pipe,
1608c2ecf20Sopenharmony_ci				  struct vsp1_dl_list *dl,
1618c2ecf20Sopenharmony_ci				  struct vsp1_dl_body *dlb);
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_civoid vsp1_entity_configure_frame(struct vsp1_entity *entity,
1648c2ecf20Sopenharmony_ci				 struct vsp1_pipeline *pipe,
1658c2ecf20Sopenharmony_ci				 struct vsp1_dl_list *dl,
1668c2ecf20Sopenharmony_ci				 struct vsp1_dl_body *dlb);
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_civoid vsp1_entity_configure_partition(struct vsp1_entity *entity,
1698c2ecf20Sopenharmony_ci				     struct vsp1_pipeline *pipe,
1708c2ecf20Sopenharmony_ci				     struct vsp1_dl_list *dl,
1718c2ecf20Sopenharmony_ci				     struct vsp1_dl_body *dlb);
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_cistruct media_pad *vsp1_entity_remote_pad(struct media_pad *pad);
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ciint vsp1_subdev_get_pad_format(struct v4l2_subdev *subdev,
1768c2ecf20Sopenharmony_ci			       struct v4l2_subdev_pad_config *cfg,
1778c2ecf20Sopenharmony_ci			       struct v4l2_subdev_format *fmt);
1788c2ecf20Sopenharmony_ciint vsp1_subdev_set_pad_format(struct v4l2_subdev *subdev,
1798c2ecf20Sopenharmony_ci			       struct v4l2_subdev_pad_config *cfg,
1808c2ecf20Sopenharmony_ci			       struct v4l2_subdev_format *fmt,
1818c2ecf20Sopenharmony_ci			       const unsigned int *codes, unsigned int ncodes,
1828c2ecf20Sopenharmony_ci			       unsigned int min_width, unsigned int min_height,
1838c2ecf20Sopenharmony_ci			       unsigned int max_width, unsigned int max_height);
1848c2ecf20Sopenharmony_ciint vsp1_subdev_enum_mbus_code(struct v4l2_subdev *subdev,
1858c2ecf20Sopenharmony_ci			       struct v4l2_subdev_pad_config *cfg,
1868c2ecf20Sopenharmony_ci			       struct v4l2_subdev_mbus_code_enum *code,
1878c2ecf20Sopenharmony_ci			       const unsigned int *codes, unsigned int ncodes);
1888c2ecf20Sopenharmony_ciint vsp1_subdev_enum_frame_size(struct v4l2_subdev *subdev,
1898c2ecf20Sopenharmony_ci				struct v4l2_subdev_pad_config *cfg,
1908c2ecf20Sopenharmony_ci				struct v4l2_subdev_frame_size_enum *fse,
1918c2ecf20Sopenharmony_ci				unsigned int min_w, unsigned int min_h,
1928c2ecf20Sopenharmony_ci				unsigned int max_w, unsigned int max_h);
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci#endif /* __VSP1_ENTITY_H__ */
195