xref: /linux/drivers/media/platform/qcom/camss/camss-vfe.h (revision d7aa60d966461ca6114dc348e97889dc8850ff7f)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * camss-vfe.h
4  *
5  * Qualcomm MSM Camera Subsystem - VFE (Video Front End) Module
6  *
7  * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
8  * Copyright (C) 2015-2018 Linaro Ltd.
9  */
10 #ifndef QC_MSM_CAMSS_VFE_H
11 #define QC_MSM_CAMSS_VFE_H
12 
13 #include <linux/clk.h>
14 #include <linux/spinlock_types.h>
15 #include <media/media-entity.h>
16 #include <media/v4l2-device.h>
17 #include <media/v4l2-subdev.h>
18 
19 #include "camss-video.h"
20 #include "camss-vfe-gen1.h"
21 
22 #define MSM_VFE_PAD_SINK 0
23 #define MSM_VFE_PAD_SRC 1
24 #define MSM_VFE_PADS_NUM 2
25 
26 #define MSM_VFE_IMAGE_MASTERS_NUM 7
27 #define MSM_VFE_COMPOSITE_IRQ_NUM 4
28 
29 /* VFE halt timeout */
30 #define VFE_HALT_TIMEOUT_MS 100
31 /* Frame drop value. VAL + UPDATES - 1 should not exceed 31 */
32 #define VFE_FRAME_DROP_VAL 30
33 
34 #define vfe_line_array(ptr_line)	\
35 	((const struct vfe_line (*)[]) &(ptr_line)[-(ptr_line)->id])
36 
37 #define to_vfe(ptr_line)	\
38 	container_of(vfe_line_array(ptr_line), struct vfe_device, line)
39 
40 enum vfe_output_state {
41 	VFE_OUTPUT_OFF,
42 	VFE_OUTPUT_RESERVED,
43 	VFE_OUTPUT_SINGLE,
44 	VFE_OUTPUT_CONTINUOUS,
45 	VFE_OUTPUT_IDLE,
46 	VFE_OUTPUT_STOPPING,
47 	VFE_OUTPUT_ON,
48 };
49 
50 enum vfe_line_id {
51 	VFE_LINE_NONE = -1,
52 	VFE_LINE_RDI0 = 0,
53 	VFE_LINE_RDI1 = 1,
54 	VFE_LINE_RDI2 = 2,
55 	VFE_LINE_PIX = 3,
56 	VFE_LINE_NUM_MAX = 4
57 };
58 
59 struct vfe_output {
60 	u8 wm_num;
61 	u8 wm_idx[3];
62 
63 	struct camss_buffer *buf[2];
64 	struct camss_buffer *last_buffer;
65 	struct list_head pending_bufs;
66 
67 	unsigned int drop_update_idx;
68 
69 	union {
70 		struct {
71 			int active_buf;
72 			int wait_sof;
73 		} gen1;
74 		struct {
75 			int active_num;
76 		} gen2;
77 	};
78 	enum vfe_output_state state;
79 	unsigned int sequence;
80 
81 	int wait_reg_update;
82 	struct completion sof;
83 	struct completion reg_update;
84 };
85 
86 struct vfe_line {
87 	enum vfe_line_id id;
88 	struct v4l2_subdev subdev;
89 	struct media_pad pads[MSM_VFE_PADS_NUM];
90 	struct v4l2_mbus_framefmt fmt[MSM_VFE_PADS_NUM];
91 	struct v4l2_rect compose;
92 	struct v4l2_rect crop;
93 	struct camss_video video_out;
94 	struct vfe_output output;
95 	const struct camss_format_info *formats;
96 	unsigned int nformats;
97 };
98 
99 struct vfe_device;
100 
101 struct vfe_hw_ops {
102 	void (*enable_irq)(struct vfe_device *vfe);
103 	void (*global_reset)(struct vfe_device *vfe);
104 	u32 (*hw_version)(struct vfe_device *vfe);
105 	irqreturn_t (*isr)(int irq, void *dev);
106 	void (*isr_read)(struct vfe_device *vfe, u32 *value0, u32 *value1);
107 	void (*pm_domain_off)(struct vfe_device *vfe);
108 	int (*pm_domain_on)(struct vfe_device *vfe);
109 	void (*reg_update)(struct vfe_device *vfe, enum vfe_line_id line_id);
110 	void (*reg_update_clear)(struct vfe_device *vfe,
111 				 enum vfe_line_id line_id);
112 	void (*subdev_init)(struct device *dev, struct vfe_device *vfe);
113 	int (*vfe_disable)(struct vfe_line *line);
114 	int (*vfe_enable)(struct vfe_line *line);
115 	int (*vfe_halt)(struct vfe_device *vfe);
116 	void (*violation_read)(struct vfe_device *vfe);
117 	void (*vfe_wm_start)(struct vfe_device *vfe, u8 wm,
118 			     struct vfe_line *line);
119 	void (*vfe_wm_stop)(struct vfe_device *vfe, u8 wm);
120 	void (*vfe_buf_done)(struct vfe_device *vfe, int port_id);
121 	void (*vfe_wm_update)(struct vfe_device *vfe, u8 wm, u32 addr,
122 			      struct vfe_line *line);
123 };
124 
125 struct vfe_isr_ops {
126 	void (*reset_ack)(struct vfe_device *vfe);
127 	void (*halt_ack)(struct vfe_device *vfe);
128 	void (*reg_update)(struct vfe_device *vfe, enum vfe_line_id line_id);
129 	void (*sof)(struct vfe_device *vfe, enum vfe_line_id line_id);
130 	void (*comp_done)(struct vfe_device *vfe, u8 comp);
131 	void (*wm_done)(struct vfe_device *vfe, u8 wm);
132 };
133 
134 struct vfe_subdev_resources {
135 	bool is_lite;
136 	u8 line_num;
137 	bool has_pd;
138 	char *pd_name;
139 	bool has_vbif;
140 	char *vbif_name;
141 	const struct vfe_hw_ops *hw_ops;
142 	const struct camss_formats *formats_rdi;
143 	const struct camss_formats *formats_pix;
144 };
145 
146 struct vfe_device {
147 	struct camss *camss;
148 	u8 id;
149 	void __iomem *base;
150 	void __iomem *vbif_base;
151 	u32 irq;
152 	char irq_name[30];
153 	struct camss_clock *clock;
154 	int nclocks;
155 	struct completion reset_complete;
156 	struct completion halt_complete;
157 	struct mutex power_lock;
158 	int power_count;
159 	struct mutex stream_lock;
160 	int stream_count;
161 	spinlock_t output_lock;
162 	enum vfe_line_id wm_output_map[MSM_VFE_IMAGE_MASTERS_NUM];
163 	struct vfe_line line[VFE_LINE_NUM_MAX];
164 	u32 reg_update;
165 	u8 was_streaming;
166 	const struct vfe_subdev_resources *res;
167 	const struct vfe_hw_ops_gen1 *ops_gen1;
168 	struct vfe_isr_ops isr_ops;
169 	struct camss_video_ops video_ops;
170 	struct device *genpd;
171 	struct device_link *genpd_link;
172 };
173 
174 struct camss_subdev_resources;
175 
176 int msm_vfe_subdev_init(struct camss *camss, struct vfe_device *vfe,
177 			const struct camss_subdev_resources *res, u8 id);
178 
179 void msm_vfe_genpd_cleanup(struct vfe_device *vfe);
180 
181 int msm_vfe_register_entities(struct vfe_device *vfe,
182 			      struct v4l2_device *v4l2_dev);
183 
184 void msm_vfe_unregister_entities(struct vfe_device *vfe);
185 
186 /*
187  * vfe_buf_add_pending - Add output buffer to list of pending
188  * @output: VFE output
189  * @buffer: Video buffer
190  */
191 void vfe_buf_add_pending(struct vfe_output *output, struct camss_buffer *buffer);
192 
193 struct camss_buffer *vfe_buf_get_pending(struct vfe_output *output);
194 
195 int vfe_flush_buffers(struct camss_video *vid, enum vb2_buffer_state state);
196 
197 /*
198  * vfe_isr_comp_done - Process composite image done interrupt
199  * @vfe: VFE Device
200  * @comp: Composite image id
201  */
202 void vfe_isr_comp_done(struct vfe_device *vfe, u8 comp);
203 
204 void vfe_isr_reset_ack(struct vfe_device *vfe);
205 int vfe_put_output(struct vfe_line *line);
206 int vfe_release_wm(struct vfe_device *vfe, u8 wm);
207 int vfe_reserve_wm(struct vfe_device *vfe, enum vfe_line_id line_id);
208 
209 /*
210  * vfe_reset - Trigger reset on VFE module and wait to complete
211  * @vfe: VFE device
212  *
213  * Return 0 on success or a negative error code otherwise
214  */
215 int vfe_reset(struct vfe_device *vfe);
216 
217 /*
218  * vfe_disable - Disable streaming on VFE line
219  * @line: VFE line
220  *
221  * Return 0 on success or a negative error code otherwise
222  */
223 int vfe_disable(struct vfe_line *line);
224 
225 /*
226  * vfe_pm_domain_off - Disable power domains specific to this VFE.
227  * @vfe: VFE Device
228  */
229 void vfe_pm_domain_off(struct vfe_device *vfe);
230 
231 /*
232  * vfe_pm_domain_on - Enable power domains specific to this VFE.
233  * @vfe: VFE Device
234  */
235 int vfe_pm_domain_on(struct vfe_device *vfe);
236 
237 extern const struct camss_formats vfe_formats_rdi_8x16;
238 extern const struct camss_formats vfe_formats_pix_8x16;
239 extern const struct camss_formats vfe_formats_rdi_8x96;
240 extern const struct camss_formats vfe_formats_pix_8x96;
241 extern const struct camss_formats vfe_formats_rdi_845;
242 extern const struct camss_formats vfe_formats_pix_845;
243 
244 extern const struct vfe_hw_ops vfe_ops_4_1;
245 extern const struct vfe_hw_ops vfe_ops_4_7;
246 extern const struct vfe_hw_ops vfe_ops_4_8;
247 extern const struct vfe_hw_ops vfe_ops_170;
248 extern const struct vfe_hw_ops vfe_ops_340;
249 extern const struct vfe_hw_ops vfe_ops_480;
250 extern const struct vfe_hw_ops vfe_ops_680;
251 extern const struct vfe_hw_ops vfe_ops_gen3;
252 
253 int vfe_get(struct vfe_device *vfe);
254 void vfe_put(struct vfe_device *vfe);
255 
256 /*
257  * vfe_is_lite - Return if VFE is VFE lite.
258  * @vfe: VFE Device
259  *
260  * Some VFE lites have a different register layout.
261  *
262  * Return whether VFE is VFE lite
263  */
264 bool vfe_is_lite(struct vfe_device *vfe);
265 
266 /*
267  * vfe_hw_version - Process write master done interrupt
268  * @vfe: VFE Device
269  *
270  * Return vfe hw version
271  */
272 u32 vfe_hw_version(struct vfe_device *vfe);
273 /*
274  * vfe_enable - Enable streaming on VFE line
275  * @line: VFE line
276  *
277  * Return 0 on success or a negative error code otherwise
278  */
279 int vfe_enable_v2(struct vfe_line *line);
280 
281 /*
282  * vfe_buf_done - Process write master done interrupt
283  * @vfe: VFE Device
284  * @wm: Write master id
285  */
286 void vfe_buf_done(struct vfe_device *vfe, int wm);
287 
288 /*
289  * vfe_get_output_v2 - Get vfe output line
290  * line: VFE line
291  *
292  * Return 0 on success or a negative error code otherwise
293  */
294 int vfe_get_output_v2(struct vfe_line *line);
295 
296 /*
297  * vfe_enable_output_v2 - Enable vfe output line
298  * line: VFE line
299  *
300  * Return 0 on success or a negative error code otherwise
301  */
302 int vfe_enable_output_v2(struct vfe_line *line);
303 
304 /*
305  * vfe_queue_buffer_v2 - Add empty buffer
306  * @vid: Video device structure
307  * @buf: Buffer to be enqueued
308  *
309  * Add an empty buffer - depending on the current number of buffers it will be
310  * put in pending buffer queue or directly given to the hardware to be filled.
311  *
312  * Return 0 on success or a negative error code otherwise
313  */
314 int vfe_queue_buffer_v2(struct camss_video *vid,
315 			struct camss_buffer *buf);
316 
317 #endif /* QC_MSM_CAMSS_VFE_H */
318