• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_MIN		208
59 #define CIF_ISP_INPUT_H_MIN		128
60 #define CIF_ISP_OUTPUT_W_MAX		CIF_ISP_INPUT_W_MAX
61 #define CIF_ISP_OUTPUT_H_MAX		CIF_ISP_INPUT_H_MAX
62 #define CIF_ISP_OUTPUT_W_MIN		CIF_ISP_INPUT_W_MIN
63 #define CIF_ISP_OUTPUT_H_MIN		CIF_ISP_INPUT_H_MIN
64 #define CIF_ISP_ADD_DATA_VC_MAX		3
65 
66 struct rkisp_stream;
67 
68 /*
69  * struct ispsd_in_fmt - ISP intput-pad format
70  *
71  * Translate mbus_code to hardware format values
72  *
73  * @bus_width: used for parallel
74  */
75 struct ispsd_in_fmt {
76 	u32 mbus_code;
77 	u8 name[16];
78 	u8 fmt_type;
79 	u32 mipi_dt;
80 	u32 yuv_seq;
81 	enum rkisp_fmt_raw_pat_type bayer_pat;
82 	u8 bus_width;
83 };
84 
85 struct ispsd_out_fmt {
86 	u32 mbus_code;
87 	u8 fmt_type;
88 };
89 
90 struct rkisp_ie_config {
91 	unsigned int effect;
92 };
93 
94 enum rkisp_isp_pad {
95 	RKISP_ISP_PAD_SINK,
96 	RKISP_ISP_PAD_SINK_PARAMS,
97 	RKISP_ISP_PAD_SOURCE_PATH,
98 	RKISP_ISP_PAD_SOURCE_STATS,
99 	RKISP_ISP_PAD_MAX
100 };
101 
102 /*
103  * struct rkisp_isp_subdev - ISP sub-device
104  *
105  * See Cropping regions of ISP in rkisp.c for details
106  * @in_frm: input size, equal to sensor size
107  * @in_fmt: intput format
108  * @in_crop: crop for sink pad
109  * @out_fmt: output format
110  * @out_crop: output size
111  *
112  * @dphy_errctrl_disabled: if dphy errctrl is disabled(avoid endless interrupt)
113  * @frm_sync_seq: frame sequence, to sync frame_id between video devices.
114  * @quantization: output quantization
115  */
116 struct rkisp_isp_subdev {
117 	struct v4l2_subdev sd;
118 	struct media_pad pads[RKISP_ISP_PAD_MAX];
119 	struct v4l2_ctrl_handler ctrl_handler;
120 	struct v4l2_mbus_framefmt in_frm;
121 	struct ispsd_in_fmt in_fmt;
122 	struct v4l2_rect in_crop;
123 	struct ispsd_out_fmt out_fmt;
124 	struct v4l2_rect out_crop;
125 	bool dphy_errctrl_disabled;
126 	atomic_t frm_sync_seq;
127 	enum v4l2_quantization quantization;
128 	enum v4l2_colorspace colorspace;
129 	u64 frm_timestamp;
130 	struct frame_debug_info dbg;
131 };
132 
133 struct rkisp_emd_data {
134 	struct kfifo mipi_kfifo;
135 	unsigned int data_len;
136 	unsigned int frame_id;
137 };
138 
139 int rkisp_register_isp_subdev(struct rkisp_device *isp_dev,
140 			       struct v4l2_device *v4l2_dev);
141 
142 void rkisp_unregister_isp_subdev(struct rkisp_device *isp_dev);
143 
144 #ifdef CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP
145 void rkisp_chk_tb_over(struct rkisp_device *isp_dev);
146 #else
rkisp_chk_tb_over(struct rkisp_device * isp_dev)147 static inline void rkisp_chk_tb_over(struct rkisp_device *isp_dev) {}
148 #endif
149 
150 void rkisp_mipi_isr(unsigned int mipi_mis, struct rkisp_device *dev);
151 
152 void rkisp_mipi_v13_isr(unsigned int err1, unsigned int err2,
153 			       unsigned int err3, struct rkisp_device *dev);
154 
155 void rkisp_isp_isr(unsigned int isp_mis, unsigned int isp3a_mis,
156 		   struct rkisp_device *dev);
157 
158 irqreturn_t rkisp_vs_isr_handler(int irq, void *ctx);
159 
160 int rkisp_align_sensor_resolution(struct rkisp_device *dev,
161 				  struct v4l2_rect *crop, bool user);
162 
163 struct media_pad *rkisp_media_entity_remote_pad(struct media_pad *pad);
164 
165 int rkisp_update_sensor_info(struct rkisp_device *dev);
166 
167 u32 rkisp_mbus_pixelcode_to_v4l2(u32 pixelcode);
168 
169 void rkisp_isp_queue_event_sof(struct rkisp_isp_subdev *isp);
170 
171 void rkisp_check_idle(struct rkisp_device *dev, u32 irq);
172 
173 void rkisp_trigger_read_back(struct rkisp_device *dev, u8 dma2frm, u32 mode, bool is_try);
174 
175 int rkisp_rdbk_trigger_event(struct rkisp_device *dev, u32 cmd, void *arg);
176 
177 void rkisp_rx_buf_pool_free(struct rkisp_device *dev);
178 
179 static inline
rkisp_get_ispsd_out_fmt(struct rkisp_isp_subdev * isp_sdev)180 struct ispsd_out_fmt *rkisp_get_ispsd_out_fmt(struct rkisp_isp_subdev *isp_sdev)
181 {
182 	return &isp_sdev->out_fmt;
183 }
184 
185 static inline
rkisp_get_ispsd_in_fmt(struct rkisp_isp_subdev * isp_sdev)186 struct ispsd_in_fmt *rkisp_get_ispsd_in_fmt(struct rkisp_isp_subdev *isp_sdev)
187 {
188 	return &isp_sdev->in_fmt;
189 }
190 
191 static inline
rkisp_get_isp_sd_win(struct rkisp_isp_subdev * isp_sdev)192 struct v4l2_rect *rkisp_get_isp_sd_win(struct rkisp_isp_subdev *isp_sdev)
193 {
194 	return &isp_sdev->out_crop;
195 }
196 
197 #endif /* _RKISP_H */
198