• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2019 Fuzhou Rockchip Electronics Co., Ltd. */
3 
4 #ifndef _RKISPP_STREAM_H
5 #define _RKISPP_STREAM_H
6 
7 #include "common.h"
8 #include "params.h"
9 
10 struct rkispp_stream;
11 
12 /*
13  * STREAM_II: input image data
14  * STREAM_MB: module bypass output, no scale
15  * STREAM_S0: scale0 output
16  * STREAM_S1: scale1 output
17  * STREAM_S2: scale2 output
18  * STREAM_VIR: virtual output for debug
19  */
20 enum rkispp_stream_id {
21 	STREAM_II = 0,
22 	STREAM_MB,
23 	STREAM_VIR,
24 	STREAM_S0,
25 	STREAM_S1,
26 	STREAM_S2,
27 	STREAM_MAX
28 };
29 
30 /*
31  * fourcc: pixel format
32  * cplanes: number of colour planes
33  * mplanes: number of stored memory planes
34  * wr_fmt: defines format for reg
35  * bpp: bits per pixel
36  */
37 struct capture_fmt {
38 	u32 fourcc;
39 	u8 cplanes;
40 	u8 mplanes;
41 	u8 wr_fmt;
42 	u8 bpp[VIDEO_MAX_PLANES];
43 };
44 
45 /* Different config for stream */
46 struct stream_config {
47 	const struct capture_fmt *fmts;
48 	unsigned int fmt_size;
49 	u32 frame_end_id;
50 	/* registers */
51 	struct {
52 		u32 ctrl;
53 		u32 factor;
54 		u32 cur_y_base;
55 		u32 cur_uv_base;
56 		u32 cur_vir_stride;
57 		u32 cur_y_base_shd;
58 		u32 cur_uv_base_shd;
59 	} reg;
60 };
61 
62 /* Different reg ops for stream */
63 struct streams_ops {
64 	int (*config)(struct rkispp_stream *stream);
65 	void (*update)(struct rkispp_stream *stream);
66 	void (*stop)(struct rkispp_stream *stream);
67 	int (*start)(struct rkispp_stream *stream);
68 	int (*is_stopped)(struct rkispp_stream *stream);
69 	int (*limit_check)(struct rkispp_stream *stream,
70 			   struct v4l2_pix_format_mplane *try_fmt);
71 };
72 
73 /* stream input/out flag */
74 enum stream_type {
75 	STREAM_INPUT,
76 	STREAM_OUTPUT,
77 };
78 
79 /* internal using buf */
80 
81 struct in_tnr_buf {
82 	struct rkispp_dummy_buffer iir;
83 	struct rkispp_dummy_buffer gain_kg;
84 	struct rkispp_dummy_buffer wr[RKISPP_BUF_MAX][GROUP_BUF_MAX];
85 };
86 
87 struct in_nr_buf {
88 	struct rkispp_dummy_buffer tmp_yuv;
89 	struct rkispp_dummy_buffer wr[RKISPP_BUF_MAX];
90 };
91 
92 struct tnr_module {
93 	struct in_tnr_buf buf;
94 	struct list_head list_rd;
95 	struct list_head list_wr;
96 	struct list_head list_rpt;
97 	spinlock_t buf_lock;
98 	struct rkisp_ispp_buf *cur_rd;
99 	struct rkisp_ispp_buf *nxt_rd;
100 	struct rkisp_ispp_buf *cur_wr;
101 	struct rkisp_ispp_reg *reg_buf;
102 	struct frame_debug_info dbg;
103 	u32 uv_offset;
104 	bool is_end;
105 	bool is_3to1;
106 	bool is_but_init;
107 	bool is_trigger;
108 };
109 
110 struct nr_module {
111 	struct in_nr_buf buf;
112 	struct list_head list_rd;
113 	struct list_head list_wr;
114 	spinlock_t buf_lock;
115 	struct rkisp_ispp_buf *cur_rd;
116 	struct rkispp_dummy_buffer *cur_wr;
117 	struct rkisp_ispp_reg *reg_buf;
118 	struct frame_debug_info dbg;
119 	u32 uv_offset;
120 	bool is_end;
121 };
122 
123 struct fec_module {
124 	struct list_head list_rd;
125 	struct list_head list_wr;
126 	struct rkisp_ispp_buf *cur_rd;
127 	struct rkispp_dummy_buffer *dummy_cur_rd;
128 	struct rkisp_ispp_reg *reg_buf;
129 	struct frame_debug_info dbg;
130 	spinlock_t buf_lock;
131 	u32 uv_offset;
132 	bool is_end;
133 };
134 
135 /* struct rkispp_stream - ISPP stream video device
136  * id: stream video identify
137  * buf_queue: queued buffer list
138  * curr_buf: the buffer used for current frame
139  * next_buf: the buffer used for next frame
140  * done: wait frame end event queue
141  * vbq_lock: lock to protect buf_queue
142  * out_cap_fmt: the output of ispp
143  * out_fmt: the output of v4l2 pix format
144  * last_module: last function module
145  * streaming: stream start flag
146  * stopping: stream stop flag
147  * linked: link enable flag
148  */
149 struct rkispp_stream {
150 	enum rkispp_stream_id id;
151 	struct rkispp_device *isppdev;
152 	struct rkispp_vdev_node vnode;
153 
154 	struct list_head buf_queue;
155 	struct rkispp_buffer *curr_buf;
156 	wait_queue_head_t done;
157 	spinlock_t vbq_lock;
158 
159 	enum stream_type type;
160 	struct streams_ops *ops;
161 	struct stream_config *config;
162 	struct capture_fmt out_cap_fmt;
163 	struct v4l2_pix_format_mplane out_fmt;
164 	struct frame_debug_info dbg;
165 
166 	u8 last_module;
167 	u8 conn_id;
168 	bool streaming;
169 	bool stopping;
170 	bool linked;
171 	bool is_upd;
172 	bool is_cfg;
173 	bool is_end;
174 	bool is_reg_withstream;
175 };
176 
177 enum {
178 	MONITOR_OFF = 0,
179 	MONITOR_TNR = BIT(0),
180 	MONITOR_NR = BIT(1),
181 	MONITOR_FEC = BIT(2),
182 };
183 
184 struct module_monitor {
185 	struct rkispp_device *dev;
186 	struct work_struct work;
187 	struct completion cmpl;
188 	u16 time;
189 	u8 module;
190 	bool is_err;
191 };
192 
193 struct rkispp_monitor {
194 	struct module_monitor tnr;
195 	struct module_monitor nr;
196 	struct module_monitor fec;
197 	struct completion cmpl;
198 	spinlock_t lock;
199 	u8 monitoring_module;
200 	u8 restart_module;
201 	u8 retry;
202 	bool is_restart;
203 	bool is_en;
204 };
205 
206 
207 struct rkispp_stream_ops {
208 	int (*config_modules)(struct rkispp_device *dev);
209 	void (*destroy_buf)(struct rkispp_stream *stream);
210 	void (*fec_work_event)(struct rkispp_device *dev, void *buf_rd,
211 			       bool is_isr, bool is_quick);
212 	int (*start_isp)(struct rkispp_device *dev);
213 	void (*check_to_force_update)(struct rkispp_device *dev, u32 mis_val);
214 	void (*update_mi)(struct rkispp_stream *stream);
215 	enum hrtimer_restart (*rkispp_frame_done_early)(struct hrtimer *timer);
216 	void (*rkispp_module_work_event)(struct rkispp_device *dev,
217 					 void *buf_rd, void *buf_wr,
218 					 u32 module, bool is_isr);
219 };
220 
221 struct rkispp_vir_cpy {
222 	struct work_struct work;
223 	struct completion cmpl;
224 	struct list_head queue;
225 	struct rkispp_stream *stream;
226 };
227 
228 /* rkispp stream device */
229 struct rkispp_stream_vdev {
230 	struct rkispp_stream stream[STREAM_MAX];
231 	struct rkispp_isp_buf_pool pool[RKISPP_BUF_POOL_MAX];
232 	struct tnr_module tnr;
233 	struct nr_module nr;
234 	struct fec_module fec;
235 	struct frame_debug_info dbg;
236 	struct rkispp_monitor monitor;
237 	struct rkispp_stream_ops *stream_ops;
238 	struct rkispp_vir_cpy vir_cpy;
239 	struct rkisp_ispp_buf input[VIDEO_MAX_FRAME];
240 	struct hrtimer fec_qst;
241 	struct hrtimer frame_qst;
242 	atomic_t refcnt;
243 	u32 module_ens;
244 	u32 irq_ends;
245 	u32 wait_line;
246 	bool is_done_early;
247 };
248 
249 int rkispp_get_tnrbuf_fd(struct rkispp_device *dev, struct rkispp_buf_idxfd *idxfd);
250 void rkispp_sendbuf_to_nr(struct rkispp_device *dev,
251 			  struct rkispp_tnr_inf *tnr_inf);
252 void rkispp_set_trigger_mode(struct rkispp_device *dev,
253 			     struct rkispp_trigger_mode *mode);
254 void rkispp_isr(u32 mis_val, struct rkispp_device *dev);
255 void rkispp_unregister_stream_vdevs(struct rkispp_device *dev);
256 int rkispp_register_stream_vdevs(struct rkispp_device *dev);
257 void *get_pool_buf(struct rkispp_device *dev, struct rkisp_ispp_buf *dbufs);
258 void *dbuf_to_dummy(struct dma_buf *dbuf, struct rkispp_dummy_buffer *pool, int num);
259 void *get_list_buf(struct list_head *list, bool is_isp_ispp);
260 void get_stream_buf(struct rkispp_stream *stream);
261 void secure_config_mb(struct rkispp_stream *stream);
262 
263 #if IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_ISPP_VERSION_V10)
264 void rkispp_stream_init_ops_v10(struct rkispp_stream_vdev *stream_vdev);
265 void rkispp_params_init_ops_v10(struct rkispp_params_vdev *params_vdev);
266 #else
rkispp_stream_init_ops_v10(struct rkispp_stream_vdev * stream_vdev)267 static inline void rkispp_stream_init_ops_v10(struct rkispp_stream_vdev *stream_vdev) {}
rkispp_params_init_ops_v10(struct rkispp_params_vdev * params_vdev)268 static inline void rkispp_params_init_ops_v10(struct rkispp_params_vdev *params_vdev) {}
269 #endif
270 
271 #if IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_ISPP_VERSION_V20)
272 void rkispp_stream_init_ops_v20(struct rkispp_stream_vdev *stream_vdev);
273 void rkispp_params_init_ops_v20(struct rkispp_params_vdev *params_vdev);
274 #else
rkispp_stream_init_ops_v20(struct rkispp_stream_vdev * stream_vdev)275 static inline void rkispp_stream_init_ops_v20(struct rkispp_stream_vdev *stream_vdev) {}
rkispp_params_init_ops_v20(struct rkispp_params_vdev * params_vdev)276 static inline void rkispp_params_init_ops_v20(struct rkispp_params_vdev *params_vdev) {}
277 #endif
278 int rkispp_frame_end(struct rkispp_stream *stream, u32 state);
279 void rkispp_start_3a_run(struct rkispp_device *dev);
280 #endif
281