xref: /OK3568_Linux_fs/kernel/drivers/media/platform/rockchip/isp1/rkisp1.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 _RKISP1_H
36 #define _RKISP1_H
37 
38 #include <linux/kfifo.h>
39 #include <linux/platform_device.h>
40 #include <linux/interrupt.h>
41 #include <media/v4l2-fwnode.h>
42 #include "common.h"
43 
44 #define CIF_ISP_INPUT_W_MAX		4416
45 #define CIF_ISP_INPUT_H_MAX		3312
46 #define CIF_ISP_INPUT_W_MAX_V12		3264
47 #define CIF_ISP_INPUT_H_MAX_V12		2448
48 #define CIF_ISP_INPUT_W_MAX_V13		1920
49 #define CIF_ISP_INPUT_H_MAX_V13		1080
50 #define CIF_ISP_INPUT_W_MIN		32
51 #define CIF_ISP_INPUT_H_MIN		16
52 #define CIF_ISP_OUTPUT_W_MAX		CIF_ISP_INPUT_W_MAX
53 #define CIF_ISP_OUTPUT_H_MAX		CIF_ISP_INPUT_H_MAX
54 #define CIF_ISP_OUTPUT_W_MIN		CIF_ISP_INPUT_W_MIN
55 #define CIF_ISP_OUTPUT_H_MIN		CIF_ISP_INPUT_H_MIN
56 #define CIF_ISP_ADD_DATA_VC_MAX		3
57 
58 struct rkisp1_stream;
59 
60 /*
61  * struct ispsd_in_fmt - ISP intput-pad format
62  *
63  * Translate mbus_code to hardware format values
64  *
65  * @bus_width: used for parallel
66  */
67 struct ispsd_in_fmt {
68 	u32 mbus_code;
69 	u8 fmt_type;
70 	u32 mipi_dt;
71 	u32 yuv_seq;
72 	enum rkisp1_fmt_raw_pat_type bayer_pat;
73 	u8 bus_width;
74 };
75 
76 struct ispsd_out_fmt {
77 	u32 mbus_code;
78 	u8 fmt_type;
79 };
80 
81 struct rkisp1_ie_config {
82 	unsigned int effect;
83 };
84 
85 enum rkisp1_isp_pad {
86 	RKISP1_ISP_PAD_SINK,
87 	RKISP1_ISP_PAD_SINK_PARAMS,
88 	RKISP1_ISP_PAD_SOURCE_PATH,
89 	RKISP1_ISP_PAD_SOURCE_STATS,
90 	RKISP1_ISP_PAD_MAX
91 };
92 
93 /*
94  * struct rkisp1_isp_subdev - ISP sub-device
95  *
96  * See Cropping regions of ISP in rkisp1.c for details
97  * @in_frm: input size, don't have to be equal to sensor size
98  * @in_fmt: intput format
99  * @in_crop: crop for sink pad
100  * @out_fmt: output format
101  * @out_crop: output size
102  *
103  * @dphy_errctrl_disabled: if dphy errctrl is disabled(avoid endless interrupt)
104  * @frm_sync_seq: frame sequence, to sync frame_id between video devices.
105  * @quantization: output quantization
106  */
107 struct rkisp1_isp_subdev {
108 	struct v4l2_subdev sd;
109 	struct media_pad pads[RKISP1_ISP_PAD_MAX];
110 	struct v4l2_ctrl_handler ctrl_handler;
111 	struct v4l2_mbus_framefmt in_frm;
112 	struct ispsd_in_fmt in_fmt;
113 	struct v4l2_rect in_crop;
114 	struct ispsd_out_fmt out_fmt;
115 	struct v4l2_rect out_crop;
116 	bool dphy_errctrl_disabled;
117 	atomic_t frm_sync_seq;
118 	enum v4l2_quantization quantization;
119 };
120 
121 struct rkisp1_emd_data {
122 	struct kfifo mipi_kfifo;
123 	unsigned int data_len;
124 	unsigned int frame_id;
125 };
126 
127 int rkisp1_register_isp_subdev(struct rkisp1_device *isp_dev,
128 			       struct v4l2_device *v4l2_dev);
129 
130 void rkisp1_unregister_isp_subdev(struct rkisp1_device *isp_dev);
131 
132 void rkisp1_mipi_isr(unsigned int mipi_mis, struct rkisp1_device *dev);
133 
134 void rkisp1_mipi_v13_isr(unsigned int err1, unsigned int err2,
135 			       unsigned int err3, struct rkisp1_device *dev);
136 
137 void rkisp1_isp_isr(unsigned int isp_mis, struct rkisp1_device *dev);
138 
139 irqreturn_t rkisp1_vs_isr_handler(int irq, void *ctx);
140 
141 int rkisp1_update_sensor_info(struct rkisp1_device *dev);
142 
143 u32 rkisp1_mbus_pixelcode_to_v4l2(u32 pixelcode);
144 
145 static inline
rkisp1_get_ispsd_out_fmt(struct rkisp1_isp_subdev * isp_sdev)146 struct ispsd_out_fmt *rkisp1_get_ispsd_out_fmt(struct rkisp1_isp_subdev *isp_sdev)
147 {
148 	return &isp_sdev->out_fmt;
149 }
150 
151 static inline
rkisp1_get_ispsd_in_fmt(struct rkisp1_isp_subdev * isp_sdev)152 struct ispsd_in_fmt *rkisp1_get_ispsd_in_fmt(struct rkisp1_isp_subdev *isp_sdev)
153 {
154 	return &isp_sdev->in_fmt;
155 }
156 
157 static inline
rkisp1_get_isp_sd_win(struct rkisp1_isp_subdev * isp_sdev)158 struct v4l2_rect *rkisp1_get_isp_sd_win(struct rkisp1_isp_subdev *isp_sdev)
159 {
160 	return &isp_sdev->out_crop;
161 }
162 
163 #endif /* _RKISP1_H */
164