xref: /OK3568_Linux_fs/kernel/drivers/media/platform/rockchip/isp/rkisp.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_H
36 #define _RKISP_H
37 
38 #include <linux/interrupt.h>
39 #include <linux/kfifo.h>
40 #include <linux/platform_device.h>
41 #include <linux/rk-camera-module.h>
42 #include <media/v4l2-fwnode.h>
43 #include "common.h"
44 #include "isp_ispp.h"
45 
46 #define CIF_ISP_INPUT_W_MAX		4416
47 #define CIF_ISP_INPUT_H_MAX		3312
48 #define CIF_ISP_INPUT_W_MAX_V12		3264
49 #define CIF_ISP_INPUT_H_MAX_V12		2448
50 #define CIF_ISP_INPUT_W_MAX_V13		1920
51 #define CIF_ISP_INPUT_H_MAX_V13		1080
52 #define CIF_ISP_INPUT_W_MAX_V21		4096
53 #define CIF_ISP_INPUT_H_MAX_V21		3072
54 #define CIF_ISP_INPUT_W_MAX_V30		4672
55 #define CIF_ISP_INPUT_H_MAX_V30		3504
56 #define CIF_ISP_INPUT_W_MAX_V30_UNITE	8192
57 #define CIF_ISP_INPUT_H_MAX_V30_UNITE	6144
58 #define CIF_ISP_INPUT_W_MAX_V32		3072
59 #define CIF_ISP_INPUT_H_MAX_V32		1728
60 #define CIF_ISP_INPUT_W_MAX_V32_L	4224
61 #define CIF_ISP_INPUT_H_MAX_V32_L	3136
62 #define CIF_ISP_INPUT_W_MIN		272
63 #define CIF_ISP_INPUT_H_MIN		256
64 #define CIF_ISP_OUTPUT_W_MAX		CIF_ISP_INPUT_W_MAX
65 #define CIF_ISP_OUTPUT_H_MAX		CIF_ISP_INPUT_H_MAX
66 #define CIF_ISP_OUTPUT_W_MIN		CIF_ISP_INPUT_W_MIN
67 #define CIF_ISP_OUTPUT_H_MIN		CIF_ISP_INPUT_H_MIN
68 #define CIF_ISP_ADD_DATA_VC_MAX		3
69 
70 struct rkisp_stream;
71 
72 /*
73  * struct ispsd_in_fmt - ISP intput-pad format
74  *
75  * Translate mbus_code to hardware format values
76  *
77  * @bus_width: used for parallel
78  */
79 struct ispsd_in_fmt {
80 	u32 mbus_code;
81 	u8 name[16];
82 	u8 fmt_type;
83 	u32 mipi_dt;
84 	u32 yuv_seq;
85 	enum rkisp_fmt_raw_pat_type bayer_pat;
86 	u8 bus_width;
87 };
88 
89 struct ispsd_out_fmt {
90 	u32 mbus_code;
91 	u8 fmt_type;
92 };
93 
94 struct rkisp_ie_config {
95 	unsigned int effect;
96 };
97 
98 enum rkisp_isp_pad {
99 	RKISP_ISP_PAD_SINK,
100 	RKISP_ISP_PAD_SINK_PARAMS,
101 	RKISP_ISP_PAD_SOURCE_PATH,
102 	RKISP_ISP_PAD_SOURCE_STATS,
103 	RKISP_ISP_PAD_MAX
104 };
105 
106 /*
107  * struct rkisp_isp_subdev - ISP sub-device
108  *
109  * See Cropping regions of ISP in rkisp.c for details
110  * @in_frm: input size, equal to sensor size
111  * @in_fmt: intput format
112  * @in_crop: crop for sink pad
113  * @out_fmt: output format
114  * @out_crop: output size
115  *
116  * @dphy_errctrl_disabled: if dphy errctrl is disabled(avoid endless interrupt)
117  * @frm_sync_seq: frame sequence, to sync frame_id between video devices.
118  * @quantization: output quantization
119  */
120 struct rkisp_isp_subdev {
121 	struct v4l2_subdev sd;
122 	struct media_pad pads[RKISP_ISP_PAD_MAX];
123 	struct v4l2_ctrl_handler ctrl_handler;
124 	struct v4l2_mbus_framefmt in_frm;
125 	struct ispsd_in_fmt in_fmt;
126 	struct v4l2_rect in_crop;
127 	struct ispsd_out_fmt out_fmt;
128 	struct v4l2_rect out_crop;
129 	bool dphy_errctrl_disabled;
130 	atomic_t frm_sync_seq;
131 	enum v4l2_quantization quantization;
132 	enum v4l2_colorspace colorspace;
133 	u64 frm_timestamp;
134 	struct frame_debug_info dbg;
135 };
136 
137 struct rkisp_emd_data {
138 	struct kfifo mipi_kfifo;
139 	unsigned int data_len;
140 	unsigned int frame_id;
141 };
142 
143 int rkisp_register_isp_subdev(struct rkisp_device *isp_dev,
144 			       struct v4l2_device *v4l2_dev);
145 
146 void rkisp_unregister_isp_subdev(struct rkisp_device *isp_dev);
147 
148 #ifdef CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP
149 void rkisp_chk_tb_over(struct rkisp_device *isp_dev);
150 #else
rkisp_chk_tb_over(struct rkisp_device * isp_dev)151 static inline void rkisp_chk_tb_over(struct rkisp_device *isp_dev) {}
152 #endif
153 
154 void rkisp_mipi_isr(unsigned int mipi_mis, struct rkisp_device *dev);
155 
156 void rkisp_mipi_v13_isr(unsigned int err1, unsigned int err2,
157 			       unsigned int err3, struct rkisp_device *dev);
158 
159 void rkisp_isp_isr(unsigned int isp_mis, unsigned int isp3a_mis,
160 		   struct rkisp_device *dev);
161 
162 irqreturn_t rkisp_vs_isr_handler(int irq, void *ctx);
163 
164 int rkisp_align_sensor_resolution(struct rkisp_device *dev,
165 				  struct v4l2_rect *crop, bool user);
166 
167 struct media_pad *rkisp_media_entity_remote_pad(struct media_pad *pad);
168 
169 int rkisp_update_sensor_info(struct rkisp_device *dev);
170 
171 u32 rkisp_mbus_pixelcode_to_v4l2(u32 pixelcode);
172 
173 void rkisp_isp_queue_event_sof(struct rkisp_isp_subdev *isp);
174 
175 void rkisp_check_idle(struct rkisp_device *dev, u32 irq);
176 
177 void rkisp_trigger_read_back(struct rkisp_device *dev, u8 dma2frm, u32 mode, bool is_try);
178 
179 int rkisp_rdbk_trigger_event(struct rkisp_device *dev, u32 cmd, void *arg);
180 
181 void rkisp_rx_buf_pool_free(struct rkisp_device *dev);
182 
183 int rkisp_expander_config(struct rkisp_device *dev,
184 			  struct rkmodule_hdr_cfg *cfg, bool on);
185 
186 static inline
rkisp_get_ispsd_out_fmt(struct rkisp_isp_subdev * isp_sdev)187 struct ispsd_out_fmt *rkisp_get_ispsd_out_fmt(struct rkisp_isp_subdev *isp_sdev)
188 {
189 	return &isp_sdev->out_fmt;
190 }
191 
192 static inline
rkisp_get_ispsd_in_fmt(struct rkisp_isp_subdev * isp_sdev)193 struct ispsd_in_fmt *rkisp_get_ispsd_in_fmt(struct rkisp_isp_subdev *isp_sdev)
194 {
195 	return &isp_sdev->in_fmt;
196 }
197 
198 static inline
rkisp_get_isp_sd_win(struct rkisp_isp_subdev * isp_sdev)199 struct v4l2_rect *rkisp_get_isp_sd_win(struct rkisp_isp_subdev *isp_sdev)
200 {
201 	return &isp_sdev->out_crop;
202 }
203 
204 #endif /* _RKISP_H */
205