hc
2023-11-22 f743a7adbd6e230d66a6206fa115b59fec2d88eb
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
/*
 *************************************************************************
 * Rockchip driver for CIF ISP 1.0
 * (Based on Intel driver for sofiaxxx)
 *
 * Copyright (C) 2015 Intel Mobile Communications GmbH
 * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd.
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *************************************************************************
 */
 
#ifndef _CIF_ISP10_ISP_H
#define _CIF_ISP10_ISP_H
 
#include <media/v4l2-common.h>
#include <media/videobuf2-core.h>
#include <media/rk-isp10-ioctl.h>
#include <media/v4l2-controls_rockchip.h>
 
/*
 * ISP device struct
 */
#define CIF_ISP10_META_INFO_NUM                2
 
enum cif_isp10_pix_fmt;
 
enum cif_isp10_pix_fmt_quantization {
   CIF_ISP10_QUANTIZATION_DEFAULT = 0,
   CIF_ISP10_QUANTIZATION_FULL_RANGE = 1,
   CIF_ISP10_QUANTIZATION_LIM_RANGE = 2
};
 
struct cif_isp10_isp_meta_info {
   unsigned int write_id;
   unsigned int read_id;
   unsigned int read_cnt;
   unsigned int read_max;
   unsigned int frame_id[CIF_ISP10_META_INFO_NUM];
   struct timeval vs_t[CIF_ISP10_META_INFO_NUM];
   struct timeval fi_t[CIF_ISP10_META_INFO_NUM];
};
 
struct cif_isp10_isp_cfgs_log {
   unsigned int s_frame_id[3];
   unsigned int new_id;
   unsigned int curr_id;
};
 
struct cif_isp10_isp_other_cfgs {
   struct cif_isp10_isp_cfgs_log log[CIFISP_MODULE_MAX];
   struct cifisp_isp_other_cfg cfgs[3];
   unsigned int module_updates;
   unsigned int module_actives;
};
 
struct cif_isp10_isp_meas_cfgs {
   struct cif_isp10_isp_cfgs_log log[CIFISP_MODULE_MAX];
   struct cifisp_isp_meas_cfg cfgs[3];
   unsigned int module_updates;
   unsigned int module_actives;
};
 
struct cif_isp10_isp_meas_stats {
   unsigned int g_frame_id;
   struct cifisp_stat_buffer stat;
};
 
struct cif_isp10_isp_dev {
   /*
    * Purpose of mutex is to protect and serialize use
    * of isp data structure and CIF API calls.
    */
   struct mutex mutex;
   /* Current ISP parameters */
   spinlock_t config_lock;
   struct cif_isp10_isp_other_cfgs other_cfgs;
   struct cif_isp10_isp_meas_cfgs meas_cfgs;
   struct cif_isp10_isp_meas_stats meas_stats;
 
   bool cif_ism_cropping;
 
   enum cif_isp10_pix_fmt_quantization quantization;
 
   /* input resolution needed for LSC param check */
   unsigned int input_width;
   unsigned int input_height;
   unsigned int active_lsc_width;
   unsigned int active_lsc_height;
 
   /* ISP statistics related */
   spinlock_t irq_lock;
   /* ISP statistics related */
   spinlock_t req_lock;
   struct list_head stat;
   void __iomem *base_addr;    /* registers base address */
 
   bool streamon;
   unsigned int v_blanking_us;
 
   unsigned int frame_id;
   unsigned int frame_id_setexp;
   unsigned int active_meas;
   unsigned int meas_send_alone;
 
   bool awb_meas_ready;
   bool afm_meas_ready;
   bool aec_meas_ready;
   bool hst_meas_ready;
 
   struct timeval vs_t;    /* updated each frame */
   struct timeval fi_t;    /* updated each frame */
   struct workqueue_struct *readout_wq;
   struct cif_isp10_isp_meta_info meta_info;
 
   unsigned int *dev_id;
 
   struct vb2_queue vb2_vidq;
};
 
enum cif_isp10_isp_readout_cmd {
   CIF_ISP10_ISP_READOUT_MEAS = 0,
   CIF_ISP10_ISP_READOUT_META = 1,
};
 
struct cif_isp10_isp_readout_work {
   struct work_struct work;
   struct cif_isp10_isp_dev *isp_dev;
 
   unsigned int frame_id;
   unsigned int active_meas;
   struct timeval vs_t;
   struct timeval fi_t;
   enum cif_isp10_isp_readout_cmd readout;
   struct vb2_buffer *vb;
   unsigned int stream_id;
   struct cifisp_isp_metadata *isp_metadata;
};
 
int register_cifisp_device(
   struct cif_isp10_isp_dev *isp_dev,
   struct video_device *vdev_cifisp,
   struct v4l2_device *v4l2_dev,
   void __iomem *cif_reg_baseaddress);
void unregister_cifisp_device(struct video_device *vdev_cifisp);
void cifisp_configure_isp(
   struct cif_isp10_isp_dev *isp_dev,
   enum cif_isp10_pix_fmt in_pix_fmt,
   enum cif_isp10_pix_fmt_quantization quantization);
void cifisp_disable_isp(struct cif_isp10_isp_dev *isp_dev);
int cifisp_isp_isr(struct cif_isp10_isp_dev *isp_dev, u32 isp_mis);
void cifisp_clr_readout_wq(struct cif_isp10_isp_dev *isp_dev);
void cifisp_v_start(struct cif_isp10_isp_dev *isp_dev,
   const struct timeval *timestamp);
void cifisp_frame_in(
   struct cif_isp10_isp_dev *isp_dev,
   const struct timeval *fi_t);
void cifisp_frame_id_reset(
   struct cif_isp10_isp_dev *isp_dev);
void cifisp_isp_readout_work(struct work_struct *work);
 
#endif