xref: /OK3568_Linux_fs/kernel/drivers/media/platform/rockchip/isp/dev.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Rockchip isp1 driver
3  *
4  * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
5  *
6  * This software is available to you under a choice of one of two
7  * licenses.  You may choose to be licensed under the terms of the GNU
8  * General Public License (GPL) Version 2, available from the file
9  * COPYING in the main directory of this source tree, or the
10  * OpenIB.org BSD license below:
11  *
12  *     Redistribution and use in source and binary forms, with or
13  *     without modification, are permitted provided that the following
14  *     conditions are met:
15  *
16  *      - Redistributions of source code must retain the above
17  *        copyright notice, this list of conditions and the following
18  *        disclaimer.
19  *
20  *      - Redistributions in binary form must reproduce the above
21  *        copyright notice, this list of conditions and the following
22  *        disclaimer in the documentation and/or other materials
23  *        provided with the distribution.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32  * SOFTWARE.
33  */
34 
35 #ifndef _RKISP_DEV_H
36 #define _RKISP_DEV_H
37 
38 #include "capture.h"
39 #include "csi.h"
40 #include "dmarx.h"
41 #include "bridge.h"
42 #include "hw.h"
43 #include "rkisp.h"
44 #include "isp_params.h"
45 #include "isp_stats.h"
46 #include "isp_mipi_luma.h"
47 #include "procfs.h"
48 #include "isp_external.h"
49 #include "version.h"
50 
51 #define DRIVER_NAME "rkisp"
52 #define ISP_VDEV_NAME DRIVER_NAME  "_ispdev"
53 
54 #define GRP_ID_SENSOR			BIT(0)
55 #define GRP_ID_MIPIPHY			BIT(1)
56 #define GRP_ID_ISP			BIT(2)
57 #define GRP_ID_ISP_MP			BIT(3)
58 #define GRP_ID_ISP_SP			BIT(4)
59 #define GRP_ID_ISP_DMARX		BIT(5)
60 #define GRP_ID_ISP_BRIDGE		BIT(6)
61 #define GRP_ID_CSI			BIT(7)
62 
63 #define RKISP_MAX_SENSOR		4
64 #define RKISP_MAX_PIPELINE		8
65 
66 #define RKISP_MEDIA_BUS_FMT_MASK	0xF000
67 #define RKISP_MEDIA_BUS_FMT_BAYER	0x3000
68 
69 #define RKISP_CONTI_ERR_MAX		50
70 
71 enum rkisp_isp_state {
72 	ISP_FRAME_END = BIT(0),
73 	ISP_FRAME_IN = BIT(1),
74 	ISP_FRAME_VS = BIT(2),
75 	ISP_FRAME_MP = BIT(3),
76 	ISP_FRAME_SP = BIT(4),
77 	ISP_FRAME_MPFBC = BIT(5),
78 	ISP_FRAME_BP = BIT(6),
79 
80 	ISP_STOP = BIT(8),
81 	ISP_START = BIT(9),
82 	ISP_ERROR = BIT(10),
83 	ISP_MIPI_ERROR = BIT(11),
84 };
85 
86 enum rkisp_isp_inp {
87 	INP_INVAL = 0,
88 	INP_RAWRD0 = BIT(0),
89 	INP_RAWRD1 = BIT(1),
90 	INP_RAWRD2 = BIT(2),
91 	INP_CSI = BIT(4),
92 	INP_DVP = BIT(5),
93 	INP_DMARX_ISP = BIT(6),
94 	INP_LVDS = BIT(7),
95 	INP_CIF = BIT(8),
96 };
97 
98 enum rkisp_rdbk_filt {
99 	RDBK_F_VS,
100 	RDBK_F_RD0,
101 	RDBK_F_RD1,
102 	RDBK_F_RD2,
103 	RDBK_F_MAX
104 };
105 
106 /*
107  * struct rkisp_pipeline - An ISP hardware pipeline
108  *
109  * Capture device call other devices via pipeline
110  *
111  * @num_subdevs: number of linked subdevs
112  * @power_cnt: pipeline power count
113  * @stream_cnt: stream power count
114  */
115 struct rkisp_pipeline {
116 	struct media_pipeline pipe;
117 	int num_subdevs;
118 	atomic_t power_cnt;
119 	atomic_t stream_cnt;
120 	struct v4l2_subdev *subdevs[RKISP_MAX_PIPELINE];
121 	int (*open)(struct rkisp_pipeline *p,
122 		    struct media_entity *me, bool prepare);
123 	int (*close)(struct rkisp_pipeline *p);
124 	int (*set_stream)(struct rkisp_pipeline *p, bool on);
125 };
126 
127 /*
128  * struct rkisp_sensor_info - Sensor infomations
129  * @mbus: media bus configuration
130  */
131 struct rkisp_sensor_info {
132 	struct v4l2_subdev *sd;
133 	struct v4l2_mbus_config mbus;
134 	struct v4l2_subdev_frame_interval fi;
135 	struct v4l2_subdev_format fmt[CSI_PAD_MAX - 1];
136 	struct v4l2_subdev_pad_config cfg;
137 };
138 
139 /* struct rkisp_hdr - hdr configured
140  * @op_mode: hdr optional mode
141  * @esp_mode: hdr especial mode
142  * @index: hdr dma index
143  * @refcnt: open counter
144  * @q_tx: dmatx buf list
145  * @q_rx: dmarx buf list
146  * @rx_cur_buf: rawrd current buf
147  * @dummy_buf: hdr dma internal buf
148  */
149 struct rkisp_hdr {
150 	u8 op_mode;
151 	u8 esp_mode;
152 	u8 compr_bit;
153 	u8 index[HDR_DMA_MAX];
154 	atomic_t refcnt;
155 	struct v4l2_subdev *sensor;
156 	struct list_head q_tx[HDR_DMA_MAX];
157 	struct list_head q_rx[HDR_DMA_MAX];
158 	struct rkisp_dummy_buffer *rx_cur_buf[HDR_DMA_MAX];
159 	struct rkisp_dummy_buffer dummy_buf[HDR_DMA_MAX][HDR_MAX_DUMMY_BUF];
160 };
161 
162 /*
163  * struct rkisp_device - ISP platform device
164  * @base_addr: base register address
165  * @active_sensor: sensor in-use, set when streaming on
166  * @isp_sdev: ISP sub-device
167  * @cap_dev: image capture device
168  * @stats_vdev: ISP statistics output device
169  * @params_vdev: ISP input parameters device
170  * @dmarx_dev: image input device
171  * @csi_dev: mipi csi device
172  * @br_dev: bridge of isp and ispp device
173  */
174 struct rkisp_device {
175 	struct list_head list;
176 	void __iomem *base_addr;
177 	struct device *dev;
178 	char name[128];
179 	void *sw_base_addr;
180 	struct rkisp_hw_dev *hw_dev;
181 	struct v4l2_device v4l2_dev;
182 	struct v4l2_ctrl_handler ctrl_handler;
183 	struct media_device media_dev;
184 	struct v4l2_async_notifier notifier;
185 	struct rkisp_sensor_info *active_sensor;
186 	struct rkisp_sensor_info sensors[RKISP_MAX_SENSOR];
187 	int num_sensors;
188 	struct rkisp_isp_subdev isp_sdev;
189 	struct rkisp_capture_device cap_dev;
190 	struct rkisp_isp_stats_vdev stats_vdev;
191 	struct rkisp_isp_params_vdev params_vdev;
192 	struct rkisp_dmarx_device dmarx_dev;
193 	struct rkisp_csi_device csi_dev;
194 	struct rkisp_bridge_device br_dev;
195 	struct rkisp_luma_vdev luma_vdev;
196 	struct rkisp_procfs procfs;
197 	struct rkisp_pipeline pipe;
198 	enum rkisp_isp_ver isp_ver;
199 	struct rkisp_emd_data emd_data_fifo[RKISP_EMDDATA_FIFO_MAX];
200 	unsigned int emd_data_idx;
201 	unsigned int emd_vc;
202 	unsigned int emd_dt;
203 	int vs_irq;
204 	struct gpio_desc *vs_irq_gpio;
205 	struct rkisp_hdr hdr;
206 	unsigned int isp_state;
207 	unsigned int isp_err_cnt;
208 	unsigned int isp_isr_cnt;
209 	unsigned int isp_inp;
210 	struct mutex apilock; /* mutex to serialize the calls of stream */
211 	struct mutex iqlock; /* mutex to serialize the calls of iq */
212 	wait_queue_head_t sync_onoff;
213 
214 	dma_addr_t resmem_addr;
215 	phys_addr_t resmem_pa;
216 	size_t resmem_size;
217 	struct rkisp_thunderboot_resmem_head tb_head;
218 	bool is_thunderboot;
219 	struct rkisp_tb_stream_info tb_stream_info;
220 	unsigned int tb_addr_idx;
221 
222 	int dev_id;
223 	unsigned int skip_frame;
224 	unsigned int irq_ends;
225 	unsigned int irq_ends_mask;
226 	bool send_fbcgain;
227 	struct rkisp_ispp_buf *cur_fbcgain;
228 	struct rkisp_buffer *cur_spbuf;
229 
230 	struct work_struct rdbk_work;
231 	struct kfifo rdbk_kfifo;
232 	spinlock_t rdbk_lock;
233 	int rdbk_cnt;
234 	int rdbk_cnt_x1;
235 	int rdbk_cnt_x2;
236 	int rdbk_cnt_x3;
237 	u32 rd_mode;
238 	int sw_rd_cnt;
239 
240 	struct rkisp_rx_buf_pool pv_pool[RKISP_RX_BUF_POOL_MAX];
241 
242 	struct mutex buf_lock;
243 	spinlock_t cmsk_lock;
244 	struct rkisp_cmsk_cfg cmsk_cfg;
245 	bool is_cmsk_upd;
246 	bool is_hw_link;
247 	bool is_bigmode;
248 	bool is_rdbk_auto;
249 	bool is_pre_on;
250 	bool is_first_double;
251 	bool is_probe_end;
252 
253 	struct rkisp_vicap_input vicap_in;
254 
255 	u8 multi_mode;
256 	u8 multi_index;
257 	u8 rawaf_irq_cnt;
258 };
259 #endif
260