xref: /OK3568_Linux_fs/kernel/drivers/media/platform/rockchip/isp/isp_stats.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2019 Fuzhou Rockchip Electronics Co., Ltd. */
3 
4 #ifndef _RKISP_ISP_STATS_H
5 #define _RKISP_ISP_STATS_H
6 
7 #include <linux/rk-isp1-config.h>
8 #include <linux/interrupt.h>
9 #include <linux/kfifo.h>
10 #include "common.h"
11 
12 #define RKISP_STATS_DDR_BUF_NUM		1
13 #define RKISP_READOUT_WORK_SIZE	\
14 	(8 * sizeof(struct rkisp_isp_readout_work))
15 
16 struct rkisp_isp_stats_vdev;
17 
18 enum rkisp_isp_readout_cmd {
19 	RKISP_ISP_READOUT_MEAS,
20 	RKISP_ISP_READOUT_META,
21 };
22 
23 struct rkisp_isp_readout_work {
24 	unsigned int frame_id;
25 	unsigned int isp_ris;
26 	unsigned int isp3a_ris;
27 	enum rkisp_isp_readout_cmd readout;
28 	unsigned long long timestamp;
29 };
30 
31 struct rkisp_isp_stats_ops {
32 	void (*isr_hdl)(struct rkisp_isp_stats_vdev *stats_vdev,
33 			u32 isp_mis, u32 isp3a_ris);
34 	void (*send_meas)(struct rkisp_isp_stats_vdev *stats_vdev,
35 			  struct rkisp_isp_readout_work *meas_work);
36 	void (*rdbk_enable)(struct rkisp_isp_stats_vdev *stats_vdev, bool en);
37 };
38 
39 /*
40  * struct rkisp_isp_stats_vdev - ISP Statistics device
41  *
42  * @irq_lock: buffer queue lock
43  * @stat: stats buffer list
44  * @readout_wq: workqueue for statistics information read
45  */
46 struct rkisp_isp_stats_vdev {
47 	struct rkisp_vdev_node vnode;
48 	struct rkisp_device *dev;
49 
50 	spinlock_t irq_lock;
51 	struct list_head stat;
52 	struct v4l2_format vdev_fmt;
53 	bool streamon;
54 
55 	spinlock_t rd_lock;
56 	struct kfifo rd_kfifo;
57 	struct tasklet_struct rd_tasklet;
58 
59 	struct rkisp_isp_stats_ops *ops;
60 	void *priv_ops;
61 	void *priv_cfg;
62 
63 	struct rkisp_dummy_buffer stats_buf[RKISP_STATS_DDR_BUF_NUM];
64 	u32 rd_buf_idx;
65 	u32 wr_buf_idx;
66 	bool rd_stats_from_ddr;
67 
68 	bool rdbk_drop;
69 	bool rdbk_mode;
70 	u32 isp_rdbk;
71 	u32 isp3a_rdbk;
72 
73 	struct rkisp_dummy_buffer tmp_statsbuf;
74 	struct rkisp_buffer *cur_buf;
75 	struct rkisp_buffer *nxt_buf;
76 
77 	bool af_meas_done_next;
78 	bool ae_meas_done_next;
79 };
80 
81 void rkisp_stats_rdbk_enable(struct rkisp_isp_stats_vdev *stats_vdev, bool en);
82 
83 void rkisp_stats_first_ddr_config(struct rkisp_isp_stats_vdev *stats_vdev);
84 void rkisp_stats_next_ddr_config(struct rkisp_isp_stats_vdev *stats_vdev);
85 
86 void rkisp_stats_isr(struct rkisp_isp_stats_vdev *stats_vdev,
87 		     u32 isp_ris, u32 isp3a_ris);
88 
89 int rkisp_register_stats_vdev(struct rkisp_isp_stats_vdev *stats_vdev,
90 			       struct v4l2_device *v4l2_dev,
91 			       struct rkisp_device *dev);
92 
93 void rkisp_unregister_stats_vdev(struct rkisp_isp_stats_vdev *stats_vdev);
94 
95 #endif /* _RKISP_ISP_STATS_H */
96