xref: /OK3568_Linux_fs/kernel/drivers/media/platform/rockchip/isp1/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 _RKISP1_DEV_H
36 #define _RKISP1_DEV_H
37 
38 #include "capture.h"
39 #include "dmarx.h"
40 #include "rkisp1.h"
41 #include "isp_params.h"
42 #include "isp_stats.h"
43 
44 #define DRIVER_NAME "rkisp1"
45 #define ISP_VDEV_NAME DRIVER_NAME  "_ispdev"
46 #define SP_VDEV_NAME DRIVER_NAME   "_selfpath"
47 #define MP_VDEV_NAME DRIVER_NAME   "_mainpath"
48 #define DMA_VDEV_NAME DRIVER_NAME  "_dmapath"
49 #define RAW_VDEV_NAME DRIVER_NAME  "_rawpath"
50 
51 #define GRP_ID_SENSOR			BIT(0)
52 #define GRP_ID_MIPIPHY			BIT(1)
53 #define GRP_ID_ISP			BIT(2)
54 #define GRP_ID_ISP_MP			BIT(3)
55 #define GRP_ID_ISP_SP			BIT(4)
56 #define GRP_ID_ISP_DMARX		BIT(5)
57 
58 #define RKISP1_MAX_BUS_CLK	8
59 #define RKISP1_MAX_SENSOR	2
60 #define RKISP1_MAX_PIPELINE	4
61 
62 #define RKISP1_MEDIA_BUS_FMT_MASK	0xF000
63 #define RKISP1_MEDIA_BUS_FMT_BAYER	0x3000
64 
65 #define RKISP1_CONTI_ERR_MAX		50
66 
67 /* ISP_V10_1 for only support MP */
68 enum rkisp1_isp_ver {
69 	ISP_V10 = 0x00,
70 	ISP_V10_1 = 0x01,
71 	ISP_V11 = 0x10,
72 	ISP_V12 = 0x20,
73 	ISP_V13 = 0x30,
74 };
75 
76 enum rkisp1_isp_state {
77 	ISP_STOP = 0,
78 	ISP_START,
79 	ISP_ERROR
80 };
81 
82 enum rkisp1_isp_inp {
83 	INP_INVAL = 0,
84 	INP_CSI,
85 	INP_DVP,
86 	INP_DMARX_ISP,
87 };
88 
89 /*
90  * struct rkisp1_pipeline - An ISP hardware pipeline
91  *
92  * Capture device call other devices via pipeline
93  *
94  * @num_subdevs: number of linked subdevs
95  * @power_cnt: pipeline power count
96  * @stream_cnt: stream power count
97  */
98 struct rkisp1_pipeline {
99 	struct media_pipeline pipe;
100 	int num_subdevs;
101 	atomic_t power_cnt;
102 	atomic_t stream_cnt;
103 	struct v4l2_subdev *subdevs[RKISP1_MAX_PIPELINE];
104 	int (*open)(struct rkisp1_pipeline *p,
105 		    struct media_entity *me, bool prepare);
106 	int (*close)(struct rkisp1_pipeline *p);
107 	int (*set_stream)(struct rkisp1_pipeline *p, bool on);
108 };
109 
110 /*
111  * struct rkisp1_sensor_info - Sensor infomations
112  * @mbus: media bus configuration
113  */
114 struct rkisp1_sensor_info {
115 	struct v4l2_subdev *sd;
116 	struct v4l2_mbus_config mbus;
117 	struct v4l2_subdev_format fmt;
118 	struct v4l2_subdev_pad_config cfg;
119 };
120 
121 /*
122  * struct rkisp1_device - ISP platform device
123  * @base_addr: base register address
124  * @active_sensor: sensor in-use, set when streaming on
125  * @isp_sdev: ISP sub-device
126  * @rkisp1_stream: capture video device
127  * @stats_vdev: ISP statistics output device
128  * @params_vdev: ISP input parameters device
129  */
130 struct rkisp1_device {
131 	struct list_head list;
132 	struct regmap *grf;
133 	void __iomem *base_addr;
134 	int irq;
135 	struct device *dev;
136 	struct clk *clks[RKISP1_MAX_BUS_CLK];
137 	int num_clks;
138 	struct v4l2_device v4l2_dev;
139 	struct v4l2_ctrl_handler ctrl_handler;
140 	struct media_device media_dev;
141 	struct v4l2_async_notifier notifier;
142 	struct v4l2_subdev *subdevs[RKISP1_SD_MAX];
143 	struct rkisp1_sensor_info *active_sensor;
144 	struct rkisp1_sensor_info sensors[RKISP1_MAX_SENSOR];
145 	int num_sensors;
146 	struct rkisp1_isp_subdev isp_sdev;
147 	struct rkisp1_stream stream[RKISP1_MAX_STREAM];
148 	struct rkisp1_isp_stats_vdev stats_vdev;
149 	struct rkisp1_isp_params_vdev params_vdev;
150 	struct rkisp1_dmarx_device dmarx_dev;
151 	struct rkisp1_pipeline pipe;
152 	struct iommu_domain *domain;
153 	enum rkisp1_isp_ver isp_ver;
154 	const unsigned int *clk_rate_tbl;
155 	int num_clk_rate_tbl;
156 	atomic_t open_cnt;
157 	struct rkisp1_emd_data emd_data_fifo[RKISP1_EMDDATA_FIFO_MAX];
158 	unsigned int emd_data_idx;
159 	unsigned int emd_vc;
160 	unsigned int emd_dt;
161 	int vs_irq;
162 	int mipi_irq;
163 	struct gpio_desc *vs_irq_gpio;
164 	struct v4l2_subdev *hdr_sensor;
165 	enum rkisp1_isp_state isp_state;
166 	unsigned int isp_err_cnt;
167 	enum rkisp1_isp_inp isp_inp;
168 	struct mutex apilock; /* mutex to serialize the calls of stream */
169 	struct mutex iqlock; /* mutex to serialize the calls of iq */
170 	wait_queue_head_t sync_onoff;
171 };
172 
173 #endif
174