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