• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * vin.h for all v4l2 subdev manage
3  *
4  * Copyright (c) 2017 by Allwinnertech Co., Ltd.  http://www.allwinnertech.com
5  *
6  * Authors:  Zhao Wei <zhaowei@allwinnertech.com>
7  *	Yang Feng <yangfeng@allwinnertech.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13 
14 #ifndef _VIN_H_
15 #define _VIN_H_
16 
17 #include <media/media-device.h>
18 #include <media/media-entity.h>
19 #include <linux/reset.h>
20 
21 #include "vin-video/vin_video.h"
22 #include "vin-video/vin_core.h"
23 #include "vin-csi/sunxi_csi.h"
24 #include "vin-isp/sunxi_isp.h"
25 #include "vin-vipp/sunxi_scaler.h"
26 #include "vin-mipi/sunxi_mipi.h"
27 #include "vin-tdm/vin_tdm.h"
28 #include "platform/platform_cfg.h"
29 #include "top_reg.h"
30 
31 enum {
32 	VIN_TOP_CLK = 0,
33 	VIN_TOP_CLK_SRC,
34 	VIN_MAX_CLK,
35 };
36 
37 enum {
38 	VIN_MIPI_CLK = 0,
39 	VIN_MIPI_CLK_SRC,
40 	VIN_MIPI_MAX_CLK,
41 };
42 
43 enum {
44 	VIN_ISP_CLK = 0,
45 	VIN_ISP_CLK_SRC,
46 	VIN_ISP_MAX_CLK,
47 };
48 
49 enum {
50 	VIN_CSI_RET = 0,
51 	VIN_ISP_RET,
52 	VIN_MAX_RET,
53 };
54 
55 enum {
56 	VIN_CSI_BUS_CLK = 0,
57 	VIN_CSI_MBUS_CLK,
58 	VIN_ISP_MBUS_CLK,
59 	VIN_MAX_BUS_CLK,
60 };
61 
62 #define VIN_CLK_RATE (432*1000*1000)
63 #define ISP_CLK_RATE (300*1000*1000)
64 
65 #define NO_VALID_SENSOR (-1)
66 
67 struct vin_valid_sensor {
68 	struct v4l2_subdev *sd;
69 	char *name;
70 };
71 
72 struct vin_csi_info {
73 	struct v4l2_subdev *sd;
74 	int id;
75 };
76 
77 struct vin_mipi_info {
78 	struct v4l2_subdev *sd;
79 	int id;
80 };
81 
82 struct vin_cci_info {
83 	struct v4l2_subdev *sd;
84 	int id;
85 };
86 
87 struct vin_isp_info {
88 	struct v4l2_subdev *sd;
89 	int id;
90 };
91 
92 struct vin_tdm_rx_info{
93 	struct v4l2_subdev *sd;
94 	int id;
95 };
96 
97 struct vin_tdm_info {
98 	struct vin_tdm_rx_info tdm_rx[TDM_RX_NUM];
99 	int id;
100 };
101 
102 struct vin_stat_info {
103 	struct v4l2_subdev *sd;
104 	int id;
105 };
106 
107 struct vin_scaler_info {
108 	struct v4l2_subdev *sd;
109 	int id;
110 };
111 
112 struct vin_clk_info {
113 	struct clk *clock;
114 	int use_count;
115 	unsigned long frequency;
116 };
117 
118 struct vin_mclk_info {
119 	struct clk *mclk;
120 	struct clk *clk_24m;
121 	struct clk *clk_pll;
122 	struct pinctrl *pin;
123 	int use_count;
124 	unsigned long frequency;
125 };
126 
127 enum vin_sub_device_regulator {
128 	ENUM_IOVDD,
129 	ENUM_AVDD,
130 	ENUM_DVDD,
131 	ENUM_AFVDD,
132 	ENUM_FLVDD,
133 	ENUM_CAMERAVDD,
134 	ENUM_MAX_REGU,
135 };
136 
137 struct vin_power {
138 	struct regulator *pmic;
139 	int power_vol;
140 	char power_str[32];
141 };
142 struct sensor_instance {
143 	char cam_name[I2C_NAME_SIZE];
144 	int cam_addr;
145 	int cam_type;
146 	int is_isp_used;
147 	int is_bayer_raw;
148 	int vflip;
149 	int hflip;
150 	int act_addr;
151 	int act_used;
152 	char act_name[I2C_NAME_SIZE];
153 	char isp_cfg_name[I2C_NAME_SIZE];
154 };
155 
156 struct sensor_list {
157 	int use_sensor_list;
158 	int used;
159 	int csi_sel;
160 	int device_sel;
161 	int mclk_id;
162 	int sensor_bus_sel;
163 	int sensor_bus_type;
164 	int act_bus_sel;
165 	int act_bus_type;
166 	int act_separate;
167 	int power_set;
168 	int detect_num;
169 	char sensor_pos[32];
170 	int valid_idx;
171 	struct vin_power power[ENUM_MAX_REGU];
172 	int gpio[MAX_GPIO_NUM];
173 	struct sensor_instance inst[MAX_DETECT_NUM];
174 };
175 
176 enum module_type {
177 	VIN_MODULE_TYPE_I2C,
178 	VIN_MODULE_TYPE_CCI,
179 	VIN_MODULE_TYPE_SPI,
180 	VIN_MODULE_TYPE_GPIO,
181 	VIN_MODULE_TYPE_MAX,
182 };
183 
184 struct vin_act_info {
185 	struct v4l2_subdev *sd;
186 	enum module_type type;
187 	int id;
188 };
189 
190 struct vin_flash_info {
191 	struct v4l2_subdev *sd;
192 	enum module_type type;
193 	int id;
194 };
195 
196 struct vin_sensor_info {
197 	struct v4l2_subdev *sd;
198 	enum module_type type;
199 	int id;
200 };
201 
202 struct vin_module_info {
203 	struct vin_act_info act[MAX_DETECT_NUM];
204 	struct vin_flash_info flash;
205 	struct vin_sensor_info sensor[MAX_DETECT_NUM];
206 	int id;
207 };
208 
209 struct modules_config {
210 	struct vin_module_info modules;
211 	struct sensor_list sensors;
212 	int flash_used;
213 	int act_used;
214 };
215 
216 struct vin_md {
217 	struct vin_csi_info csi[VIN_MAX_CSI];
218 	struct vin_mipi_info mipi[VIN_MAX_MIPI];
219 	struct vin_cci_info cci[VIN_MAX_CCI];
220 	struct vin_isp_info isp[VIN_MAX_ISP];
221 	struct vin_tdm_info tdm[VIN_MAX_TDM];
222 	struct vin_stat_info stat[VIN_MAX_ISP];
223 	struct vin_scaler_info scaler[VIN_MAX_SCALER];
224 	struct vin_core *vinc[VIN_MAX_DEV];
225 	struct vin_clk_info clk[VIN_MAX_CLK];
226 	struct vin_clk_info mipi_clk[VIN_MIPI_MAX_CLK];
227 	struct vin_mclk_info mclk[VIN_MAX_CCI];
228 	struct vin_clk_info isp_clk[VIN_ISP_MAX_CLK];
229 	struct reset_control *clk_reset[VIN_MAX_RET];
230 	struct clk *bus_clk[VIN_MAX_BUS_CLK];
231 	struct modules_config modules[VIN_MAX_DEV];
232 	struct csic_feature_list csic_fl;
233 	struct csic_version csic_ver;
234 	unsigned int isp_ver_major;
235 	unsigned int isp_ver_minor;
236 	unsigned int is_empty;
237 	unsigned int id;
238 	unsigned int irq;
239 	int use_count;
240 	void __iomem *base;
241 	void __iomem *ccu_base;
242 	void __iomem *cmb_top_base;
243 	struct media_device media_dev;
244 	struct v4l2_device v4l2_dev;
245 	struct platform_device *pdev;
246 	bool user_subdev_api;
247 	spinlock_t slock;
248 	unsigned int isp_bd_tatol;
249 	unsigned int csi_bd_tatol;
250 
251 };
252 
entity_to_vin_mdev(struct media_entity * me)253 static inline struct vin_md *entity_to_vin_mdev(struct media_entity *me)
254 {
255 	return me->graph_obj.mdev == NULL ? NULL :
256 		container_of(me->graph_obj.mdev, struct vin_md, media_dev);
257 }
258 
259 /*
260  * Media pipeline operations to be called from within the video
261  * node when it is the last entity of the pipeline. Implemented
262  * by corresponding media device driver.
263  */
264 
265 struct vin_pipeline_ops {
266 	int (*open)(struct vin_pipeline *p, struct media_entity *me,
267 			  bool resume);
268 	int (*close)(struct vin_pipeline *p);
269 	int (*set_stream)(struct vin_pipeline *p, int state);
270 };
271 
272 #define vin_pipeline_call(f, op, p, args...)				\
273 	(((f)->pipeline_ops && (f)->pipeline_ops->op) ? \
274 			    (f)->pipeline_ops->op((p), ##args) : -ENOIOCTLCMD)
275 
276 
277 #endif /*_VIN_H_*/
278