1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef __ATOMISP_INTERNAL_H__
20#define __ATOMISP_INTERNAL_H__
21
22#include "../../include/linux/atomisp_platform.h"
23#include <linux/firmware.h>
24#include <linux/kernel.h>
25#include <linux/pm_qos.h>
26#include <linux/idr.h>
27
28#include <media/media-device.h>
29#include <media/v4l2-subdev.h>
30
31#ifndef ISP2401
32#include "ia_css_types.h"
33#include "sh_css_legacy.h"
34#else
35
36
37#endif
38
39#include "atomisp_csi2.h"
40#include "atomisp_file.h"
41#include "atomisp_subdev.h"
42#include "atomisp_tpg.h"
43#include "atomisp_compat.h"
44
45#include "gp_device.h"
46#include "irq.h"
47#include <linux/vmalloc.h>
48
49#define V4L2_EVENT_FRAME_END 5
50
51#define IS_HWREVISION(isp, rev) \
52 (((isp)->media_dev.hw_revision & ATOMISP_HW_REVISION_MASK) == \
53 ((rev) << ATOMISP_HW_REVISION_SHIFT))
54
55#define MAX_STREAM_NUM 2
56
57#define ATOMISP_PCI_DEVICE_SOC_MASK 0xfff8
58
59#define ATOMISP_PCI_DEVICE_SOC_MRFLD 0x1178
60
61#define ATOMISP_PCI_DEVICE_SOC_MRFLD_1179 0x1179
62
63#define ATOMISP_PCI_DEVICE_SOC_MRFLD_117A 0x117a
64#define ATOMISP_PCI_DEVICE_SOC_BYT 0x0f38
65#define ATOMISP_PCI_DEVICE_SOC_ANN 0x1478
66#define ATOMISP_PCI_DEVICE_SOC_CHT 0x22b8
67
68#define ATOMISP_PCI_REV_MRFLD_A0_MAX 0
69#define ATOMISP_PCI_REV_BYT_A0_MAX 4
70
71#define ATOM_ISP_STEP_WIDTH 2
72#define ATOM_ISP_STEP_HEIGHT 2
73
74#define ATOM_ISP_MIN_WIDTH 4
75#define ATOM_ISP_MIN_HEIGHT 4
76#define ATOM_ISP_MAX_WIDTH UINT_MAX
77#define ATOM_ISP_MAX_HEIGHT UINT_MAX
78
79
80#define ATOM_RESOLUTION_SUBQCIF_WIDTH 128
81#define ATOM_RESOLUTION_SUBQCIF_HEIGHT 96
82
83#define ATOM_ISP_MAX_WIDTH_TMP 1280
84#define ATOM_ISP_MAX_HEIGHT_TMP 720
85
86#define ATOM_ISP_I2C_BUS_1 4
87#define ATOM_ISP_I2C_BUS_2 5
88
89#define ATOM_ISP_POWER_DOWN 0
90#define ATOM_ISP_POWER_UP 1
91
92#define ATOM_ISP_MAX_INPUTS 4
93
94#define ATOMISP_SC_TYPE_SIZE 2
95
96#define ATOMISP_ISP_TIMEOUT_DURATION (2 * HZ)
97#define ATOMISP_EXT_ISP_TIMEOUT_DURATION (6 * HZ)
98#define ATOMISP_ISP_FILE_TIMEOUT_DURATION (60 * HZ)
99#define ATOMISP_WDT_KEEP_CURRENT_DELAY 0
100#define ATOMISP_ISP_MAX_TIMEOUT_COUNT 2
101#define ATOMISP_CSS_STOP_TIMEOUT_US 200000
102
103#define ATOMISP_CSS_Q_DEPTH 3
104#define ATOMISP_CSS_EVENTS_MAX 16
105#define ATOMISP_CONT_RAW_FRAMES 15
106#define ATOMISP_METADATA_QUEUE_DEPTH_FOR_HAL 8
107#define ATOMISP_S3A_BUF_QUEUE_DEPTH_FOR_HAL 8
108
109#define ATOMISP_DELAYED_INIT_NOT_QUEUED 0
110#define ATOMISP_DELAYED_INIT_QUEUED 1
111#define ATOMISP_DELAYED_INIT_DONE 2
112
113#define ATOMISP_CALC_CSS_PREV_OVERLAP(lines) \
114 ((lines) * 38 / 100 & 0xfffffe)
115
116
117
118
119
120
121
122
123
124#define ATOMISP_MAX_ISR_LATENCY 1000
125
126
127#define ATOMISP_CSS_SUPPORT_YUVPP 1
128
129#define ATOMISP_CSS_OUTPUT_SECOND_INDEX 1
130#define ATOMISP_CSS_OUTPUT_DEFAULT_INDEX 0
131
132
133
134
135
136
137#define ATOMISP_SOC_CAMERA(asd) \
138 (asd->isp->inputs[asd->input_curr].type == SOC_CAMERA \
139 && asd->isp->inputs[asd->input_curr].camera_caps-> \
140 sensor[asd->sensor_curr].stream_num == 1)
141
142#define ATOMISP_USE_YUVPP(asd) \
143 (ATOMISP_SOC_CAMERA(asd) && ATOMISP_CSS_SUPPORT_YUVPP && \
144 !asd->copy_mode)
145
146#define ATOMISP_DEPTH_SENSOR_STREAMON_COUNT 2
147
148#define ATOMISP_DEPTH_DEFAULT_MASTER_SENSOR 0
149#define ATOMISP_DEPTH_DEFAULT_SLAVE_SENSOR 1
150
151#ifdef ISP2401
152#define ATOMISP_ION_DEVICE_FD_OFFSET 16
153#define ATOMISP_ION_SHARED_FD_MASK (0xFFFF)
154#define ATOMISP_ION_DEVICE_FD_MASK (~ATOMISP_ION_SHARED_FD_MASK)
155#define ION_FD_UNSET (-1)
156
157#endif
158#define DIV_NEAREST_STEP(n, d, step) \
159 round_down((2 * (n) + (d) * (step))/(2 * (d)), (step))
160
161struct atomisp_input_subdev {
162 unsigned int type;
163 enum atomisp_camera_port port;
164 struct v4l2_subdev *camera;
165 struct v4l2_subdev *motor;
166 struct v4l2_frmsizeenum frame_size;
167
168
169
170
171
172 struct atomisp_sub_device *asd;
173
174 const struct atomisp_camera_caps *camera_caps;
175 int sensor_index;
176};
177
178enum atomisp_dfs_mode {
179 ATOMISP_DFS_MODE_AUTO = 0,
180 ATOMISP_DFS_MODE_LOW,
181 ATOMISP_DFS_MODE_MAX,
182};
183
184struct atomisp_regs {
185
186 u16 pcicmdsts;
187 u32 ispmmadr;
188 u32 msicap;
189 u32 msi_addr;
190 u16 msi_data;
191 u8 intr;
192 u32 interrupt_control;
193 u32 pmcs;
194 u32 cg_dis;
195 u32 i_control;
196
197
198 u32 csi_rcomp_config;
199 u32 csi_afe_dly;
200 u32 csi_control;
201
202
203 u32 csi_afe_rcomp_config;
204 u32 csi_afe_hs_control;
205 u32 csi_deadline_control;
206 u32 csi_access_viol;
207};
208
209struct atomisp_sw_contex {
210 bool file_input;
211 int power_state;
212 int running_freq;
213};
214
215
216#define ATOMISP_DEVICE_STREAMING_DISABLED 0
217#define ATOMISP_DEVICE_STREAMING_ENABLED 1
218#define ATOMISP_DEVICE_STREAMING_STOPPING 2
219
220
221
222
223struct atomisp_device {
224 struct pci_dev *pdev;
225 struct device *dev;
226 struct v4l2_device v4l2_dev;
227 struct media_device media_dev;
228 struct atomisp_platform_data *pdata;
229 void *mmu_l1_base;
230 struct pci_dev *pci_root;
231 const struct firmware *firmware;
232
233 struct pm_qos_request pm_qos;
234 s32 max_isr_latency;
235
236
237
238
239
240
241 struct atomisp_sub_device *asd;
242
243
244
245
246 unsigned int num_of_streams;
247
248 struct atomisp_mipi_csi2_device csi2_port[ATOMISP_CAMERA_NR_PORTS];
249 struct atomisp_tpg_device tpg;
250 struct atomisp_file_device file_dev;
251
252
253
254 struct rt_mutex mutex;
255
256
257
258
259
260 struct mutex streamoff_mutex;
261
262 unsigned int input_cnt;
263 struct atomisp_input_subdev inputs[ATOM_ISP_MAX_INPUTS];
264 struct v4l2_subdev *flash;
265 struct v4l2_subdev *motor;
266
267 struct atomisp_regs saved_regs;
268 struct atomisp_sw_contex sw_contex;
269 struct atomisp_css_env css_env;
270
271
272 bool isp_timeout;
273 bool isp_fatal_error;
274 struct workqueue_struct *wdt_work_queue;
275 struct work_struct wdt_work;
276#ifndef ISP2401
277 atomic_t wdt_count;
278#endif
279 atomic_t wdt_work_queued;
280
281 spinlock_t lock;
282
283 bool need_gfx_throttle;
284
285 unsigned int mipi_frame_size;
286 const struct atomisp_dfs_config *dfs;
287 unsigned int hpll_freq;
288
289 bool css_initialized;
290};
291
292#define v4l2_dev_to_atomisp_device(dev) \
293 container_of(dev, struct atomisp_device, v4l2_dev)
294
295extern struct device *atomisp_dev;
296
297#define atomisp_is_wdt_running(a) timer_pending(&(a)->wdt)
298#ifdef ISP2401
299extern void atomisp_wdt_refresh_pipe(struct atomisp_video_pipe *pipe,
300 unsigned int delay);
301#endif
302extern void atomisp_wdt_refresh(struct atomisp_sub_device *asd, unsigned int delay);
303#ifndef ISP2401
304extern void atomisp_wdt_start(struct atomisp_sub_device *asd);
305#else
306extern void atomisp_wdt_start(struct atomisp_video_pipe *pipe);
307extern void atomisp_wdt_stop_pipe(struct atomisp_video_pipe *pipe, bool sync);
308#endif
309extern void atomisp_wdt_stop(struct atomisp_sub_device *asd, bool sync);
310
311#endif
312