1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 3 * vsp1_entity.h -- R-Car VSP1 Base Entity 4 * 5 * Copyright (C) 2013-2014 Renesas Electronics Corporation 6 * 7 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) 8 */ 9 #ifndef __VSP1_ENTITY_H__ 10 #define __VSP1_ENTITY_H__ 11 12 #include <linux/list.h> 13 #include <linux/mutex.h> 14 15 #include <media/v4l2-subdev.h> 16 17 struct vsp1_device; 18 struct vsp1_dl_body; 19 struct vsp1_dl_list; 20 struct vsp1_pipeline; 21 struct vsp1_partition; 22 23 enum vsp1_entity_type { 24 VSP1_ENTITY_BRS, 25 VSP1_ENTITY_BRU, 26 VSP1_ENTITY_CLU, 27 VSP1_ENTITY_HGO, 28 VSP1_ENTITY_HGT, 29 VSP1_ENTITY_HSI, 30 VSP1_ENTITY_HST, 31 VSP1_ENTITY_LIF, 32 VSP1_ENTITY_LUT, 33 VSP1_ENTITY_RPF, 34 VSP1_ENTITY_SRU, 35 VSP1_ENTITY_UDS, 36 VSP1_ENTITY_UIF, 37 VSP1_ENTITY_WPF, 38 }; 39 40 #define VSP1_ENTITY_MAX_INPUTS 5 /* For the BRU */ 41 42 /* 43 * struct vsp1_route - Entity routing configuration 44 * @type: Entity type this routing entry is associated with 45 * @index: Entity index this routing entry is associated with 46 * @reg: Output routing configuration register 47 * @inputs: Target node value for each input 48 * @output: Target node value for entity output 49 * 50 * Each $vsp1_route entry describes routing configuration for the entity 51 * specified by the entry's @type and @index. @reg indicates the register that 52 * holds output routing configuration for the entity, and the @inputs array 53 * store the target node value for each input of the entity. The @output field 54 * stores the target node value of the entity output when used as a source for 55 * histogram generation. 56 */ 57 struct vsp1_route { 58 enum vsp1_entity_type type; 59 unsigned int index; 60 unsigned int reg; 61 unsigned int inputs[VSP1_ENTITY_MAX_INPUTS]; 62 unsigned int output; 63 }; 64 65 /** 66 * struct vsp1_entity_operations - Entity operations 67 * @destroy: Destroy the entity. 68 * @configure_stream: Setup the hardware parameters for the stream which do 69 * not vary between frames (pipeline, formats). Note that 70 * the vsp1_dl_list argument is only valid for display 71 * pipeline and will be NULL for mem-to-mem pipelines. 72 * @configure_frame: Configure the runtime parameters for each frame. 73 * @configure_partition: Configure partition specific parameters. 74 * @max_width: Return the max supported width of data that the entity can 75 * process in a single operation. 76 * @partition: Process the partition construction based on this entity's 77 * configuration. 78 */ 79 struct vsp1_entity_operations { 80 void (*destroy)(struct vsp1_entity *entity); 81 void (*configure_stream)(struct vsp1_entity *entity, 82 struct v4l2_subdev_state *state, 83 struct vsp1_pipeline *pipe, 84 struct vsp1_dl_list *dl, 85 struct vsp1_dl_body *dlb); 86 void (*configure_frame)(struct vsp1_entity *entity, 87 struct vsp1_pipeline *pipe, 88 struct vsp1_dl_list *dl, 89 struct vsp1_dl_body *dlb); 90 void (*configure_partition)(struct vsp1_entity *entity, 91 struct vsp1_pipeline *pipe, 92 const struct vsp1_partition *partition, 93 struct vsp1_dl_list *dl, 94 struct vsp1_dl_body *dlb); 95 unsigned int (*max_width)(struct vsp1_entity *entity, 96 struct v4l2_subdev_state *state, 97 struct vsp1_pipeline *pipe); 98 void (*partition)(struct vsp1_entity *entity, 99 struct v4l2_subdev_state *state, 100 struct vsp1_pipeline *pipe, 101 struct vsp1_partition *partition, 102 unsigned int index, 103 struct v4l2_rect *window); 104 }; 105 106 struct vsp1_entity { 107 struct vsp1_device *vsp1; 108 109 const struct vsp1_entity_operations *ops; 110 111 enum vsp1_entity_type type; 112 unsigned int index; 113 const struct vsp1_route *route; 114 115 struct vsp1_pipeline *pipe; 116 117 struct list_head list_dev; 118 struct list_head list_pipe; 119 120 struct media_pad *pads; 121 unsigned int source_pad; 122 123 struct vsp1_entity **sources; 124 struct vsp1_entity *sink; 125 unsigned int sink_pad; 126 127 struct v4l2_subdev subdev; 128 struct v4l2_subdev_state *state; 129 130 struct mutex lock; /* Protects the state */ 131 }; 132 133 static inline struct vsp1_entity *to_vsp1_entity(struct v4l2_subdev *subdev) 134 { 135 return container_of(subdev, struct vsp1_entity, subdev); 136 } 137 138 int vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity, 139 const char *name, unsigned int num_pads, 140 const struct v4l2_subdev_ops *ops, u32 function); 141 void vsp1_entity_destroy(struct vsp1_entity *entity); 142 143 int vsp1_entity_link_setup(struct media_entity *entity, 144 const struct media_pad *local, 145 const struct media_pad *remote, u32 flags); 146 147 struct v4l2_subdev_state * 148 vsp1_entity_get_state(struct vsp1_entity *entity, 149 struct v4l2_subdev_state *sd_state, 150 enum v4l2_subdev_format_whence which); 151 152 void vsp1_entity_route_setup(struct vsp1_entity *entity, 153 struct vsp1_pipeline *pipe, 154 struct vsp1_dl_body *dlb); 155 156 void vsp1_entity_configure_stream(struct vsp1_entity *entity, 157 struct v4l2_subdev_state *state, 158 struct vsp1_pipeline *pipe, 159 struct vsp1_dl_list *dl, 160 struct vsp1_dl_body *dlb); 161 162 void vsp1_entity_configure_frame(struct vsp1_entity *entity, 163 struct vsp1_pipeline *pipe, 164 struct vsp1_dl_list *dl, 165 struct vsp1_dl_body *dlb); 166 167 void vsp1_entity_configure_partition(struct vsp1_entity *entity, 168 struct vsp1_pipeline *pipe, 169 const struct vsp1_partition *partition, 170 struct vsp1_dl_list *dl, 171 struct vsp1_dl_body *dlb); 172 173 struct media_pad *vsp1_entity_remote_pad(struct media_pad *pad); 174 175 int vsp1_subdev_get_pad_format(struct v4l2_subdev *subdev, 176 struct v4l2_subdev_state *sd_state, 177 struct v4l2_subdev_format *fmt); 178 int vsp1_subdev_set_pad_format(struct v4l2_subdev *subdev, 179 struct v4l2_subdev_state *sd_state, 180 struct v4l2_subdev_format *fmt, 181 const unsigned int *codes, unsigned int ncodes, 182 unsigned int min_width, unsigned int min_height, 183 unsigned int max_width, unsigned int max_height); 184 int vsp1_subdev_enum_mbus_code(struct v4l2_subdev *subdev, 185 struct v4l2_subdev_state *sd_state, 186 struct v4l2_subdev_mbus_code_enum *code, 187 const unsigned int *codes, unsigned int ncodes); 188 int vsp1_subdev_enum_frame_size(struct v4l2_subdev *subdev, 189 struct v4l2_subdev_state *sd_state, 190 struct v4l2_subdev_frame_size_enum *fse, 191 unsigned int min_w, unsigned int min_h, 192 unsigned int max_w, unsigned int max_h); 193 194 #endif /* __VSP1_ENTITY_H__ */ 195