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