]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/staging/media/atomisp/pci/atomisp2/atomisp_internal.h
7542a72f1d0fe7761396b81befb1e517da71026f
[mirror_ubuntu-bionic-kernel.git] / drivers / staging / media / atomisp / pci / atomisp2 / atomisp_internal.h
1 /*
2 * Support for Medifield PNW Camera Imaging ISP subsystem.
3 *
4 * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
5 *
6 * Copyright (c) 2010 Silicon Hive www.siliconhive.com.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 *
22 */
23 #ifndef __ATOMISP_INTERNAL_H__
24 #define __ATOMISP_INTERNAL_H__
25
26 #include "../../include/linux/atomisp_platform.h"
27 #include <linux/firmware.h>
28 #include <linux/kernel.h>
29 #include <linux/pm_qos.h>
30 #include <linux/idr.h>
31
32 #include <asm/intel-mid.h>
33 #include "../../include/asm/intel_mid_pcihelpers.h"
34
35 #include <media/media-device.h>
36 #include <media/v4l2-subdev.h>
37
38 #ifndef ISP2401
39 #include "ia_css_types.h"
40 #include "sh_css_legacy.h"
41 #else
42 /*#include "ia_css_types.h"*/
43 /*#include "sh_css_legacy.h"*/
44 #endif
45
46 #include "atomisp_csi2.h"
47 #include "atomisp_file.h"
48 #include "atomisp_subdev.h"
49 #include "atomisp_tpg.h"
50 #include "atomisp_compat.h"
51
52 #include "gp_device.h"
53 #include "irq.h"
54 #include <linux/vmalloc.h>
55
56 #define V4L2_EVENT_FRAME_END 5
57
58 #define IS_HWREVISION(isp, rev) \
59 (((isp)->media_dev.hw_revision & ATOMISP_HW_REVISION_MASK) == \
60 ((rev) << ATOMISP_HW_REVISION_SHIFT))
61
62 #define MAX_STREAM_NUM 2
63
64 #define ATOMISP_PCI_DEVICE_SOC_MASK 0xfff8
65 /* MRFLD with 0x1178: ISP freq can burst to 457MHz */
66 #define ATOMISP_PCI_DEVICE_SOC_MRFLD 0x1178
67 /* MRFLD with 0x1179: max ISP freq limited to 400MHz */
68 #define ATOMISP_PCI_DEVICE_SOC_MRFLD_1179 0x1179
69 /* MRFLD with 0x117a: max ISP freq is 400MHz and max freq at Vmin is 200MHz */
70 #define ATOMISP_PCI_DEVICE_SOC_MRFLD_117A 0x117a
71 #define ATOMISP_PCI_DEVICE_SOC_BYT 0x0f38
72 #define ATOMISP_PCI_DEVICE_SOC_ANN 0x1478
73 #define ATOMISP_PCI_DEVICE_SOC_CHT 0x22b8
74
75 #define ATOMISP_PCI_REV_MRFLD_A0_MAX 0
76 #define ATOMISP_PCI_REV_BYT_A0_MAX 4
77
78 #define ATOM_ISP_STEP_WIDTH 2
79 #define ATOM_ISP_STEP_HEIGHT 2
80
81 #define ATOM_ISP_MIN_WIDTH 4
82 #define ATOM_ISP_MIN_HEIGHT 4
83 #define ATOM_ISP_MAX_WIDTH UINT_MAX
84 #define ATOM_ISP_MAX_HEIGHT UINT_MAX
85
86 /* sub-QCIF resolution */
87 #define ATOM_RESOLUTION_SUBQCIF_WIDTH 128
88 #define ATOM_RESOLUTION_SUBQCIF_HEIGHT 96
89
90 #define ATOM_ISP_MAX_WIDTH_TMP 1280
91 #define ATOM_ISP_MAX_HEIGHT_TMP 720
92
93 #define ATOM_ISP_I2C_BUS_1 4
94 #define ATOM_ISP_I2C_BUS_2 5
95
96 #define ATOM_ISP_POWER_DOWN 0
97 #define ATOM_ISP_POWER_UP 1
98
99 #define ATOM_ISP_MAX_INPUTS 4
100
101 #define ATOMISP_SC_TYPE_SIZE 2
102
103 #define ATOMISP_ISP_TIMEOUT_DURATION (2 * HZ)
104 #define ATOMISP_EXT_ISP_TIMEOUT_DURATION (6 * HZ)
105 #define ATOMISP_ISP_FILE_TIMEOUT_DURATION (60 * HZ)
106 #define ATOMISP_WDT_KEEP_CURRENT_DELAY 0
107 #define ATOMISP_ISP_MAX_TIMEOUT_COUNT 2
108 #define ATOMISP_CSS_STOP_TIMEOUT_US 200000
109
110 #define ATOMISP_CSS_Q_DEPTH 3
111 #define ATOMISP_CSS_EVENTS_MAX 16
112 #define ATOMISP_CONT_RAW_FRAMES 15
113 #define ATOMISP_METADATA_QUEUE_DEPTH_FOR_HAL 8
114 #define ATOMISP_S3A_BUF_QUEUE_DEPTH_FOR_HAL 8
115
116 #define ATOMISP_DELAYED_INIT_NOT_QUEUED 0
117 #define ATOMISP_DELAYED_INIT_QUEUED 1
118 #define ATOMISP_DELAYED_INIT_DONE 2
119
120 #define ATOMISP_CALC_CSS_PREV_OVERLAP(lines) \
121 ((lines) * 38 / 100 & 0xfffffe)
122
123 /*
124 * Define how fast CPU should be able to serve ISP interrupts.
125 * The bigger the value, the higher risk that the ISP is not
126 * triggered sufficiently fast for it to process image during
127 * vertical blanking time, increasing risk of dropped frames.
128 * 1000 us is a reasonable value considering that the processing
129 * time is typically ~2000 us.
130 */
131 #define ATOMISP_MAX_ISR_LATENCY 1000
132
133 /* Add new YUVPP pipe for SOC sensor. */
134 #define ATOMISP_CSS_SUPPORT_YUVPP 1
135
136 #define ATOMISP_CSS_OUTPUT_SECOND_INDEX 1
137 #define ATOMISP_CSS_OUTPUT_DEFAULT_INDEX 0
138
139 /*
140 * ATOMISP_SOC_CAMERA
141 * This is to differentiate between ext-isp and soc camera in
142 * Moorefield/Baytrail platform.
143 */
144 #define ATOMISP_SOC_CAMERA(asd) \
145 (asd->isp->inputs[asd->input_curr].type == SOC_CAMERA \
146 && asd->isp->inputs[asd->input_curr].camera_caps-> \
147 sensor[asd->sensor_curr].stream_num == 1)
148
149 #define ATOMISP_USE_YUVPP(asd) \
150 (ATOMISP_SOC_CAMERA(asd) && ATOMISP_CSS_SUPPORT_YUVPP && \
151 !asd->copy_mode)
152
153 #define ATOMISP_DEPTH_SENSOR_STREAMON_COUNT 2
154
155 #define ATOMISP_DEPTH_DEFAULT_MASTER_SENSOR 0
156 #define ATOMISP_DEPTH_DEFAULT_SLAVE_SENSOR 1
157
158 #ifdef ISP2401
159 #define ATOMISP_ION_DEVICE_FD_OFFSET 16
160 #define ATOMISP_ION_SHARED_FD_MASK (0xFFFF)
161 #define ATOMISP_ION_DEVICE_FD_MASK (~ATOMISP_ION_SHARED_FD_MASK)
162 #define ION_FD_UNSET (-1)
163
164 #endif
165 #define DIV_NEAREST_STEP(n, d, step) \
166 round_down((2 * (n) + (d) * (step))/(2 * (d)), (step))
167
168 struct atomisp_input_subdev {
169 unsigned int type;
170 enum atomisp_camera_port port;
171 struct v4l2_subdev *camera;
172 struct v4l2_subdev *motor;
173 struct v4l2_frmsizeenum frame_size;
174
175 /*
176 * To show this resource is used by
177 * which stream, in ISP multiple stream mode
178 */
179 struct atomisp_sub_device *asd;
180
181 const struct atomisp_camera_caps *camera_caps;
182 int sensor_index;
183 };
184
185 enum atomisp_dfs_mode {
186 ATOMISP_DFS_MODE_AUTO = 0,
187 ATOMISP_DFS_MODE_LOW,
188 ATOMISP_DFS_MODE_MAX,
189 };
190
191 struct atomisp_regs {
192 /* PCI config space info */
193 u16 pcicmdsts;
194 u32 ispmmadr;
195 u32 msicap;
196 u32 msi_addr;
197 u16 msi_data;
198 u8 intr;
199 u32 interrupt_control;
200 u32 pmcs;
201 u32 cg_dis;
202 u32 i_control;
203
204 /* I-Unit PHY related info */
205 u32 csi_rcomp_config;
206 u32 csi_afe_dly;
207 u32 csi_control;
208
209 /* New for MRFLD */
210 u32 csi_afe_rcomp_config;
211 u32 csi_afe_hs_control;
212 u32 csi_deadline_control;
213 u32 csi_access_viol;
214 };
215
216 struct atomisp_sw_contex {
217 bool file_input;
218 int power_state;
219 int running_freq;
220 };
221
222
223 #define ATOMISP_DEVICE_STREAMING_DISABLED 0
224 #define ATOMISP_DEVICE_STREAMING_ENABLED 1
225 #define ATOMISP_DEVICE_STREAMING_STOPPING 2
226
227 /*
228 * ci device struct
229 */
230 struct atomisp_device {
231 struct pci_dev *pdev;
232 struct device *dev;
233 struct v4l2_device v4l2_dev;
234 struct media_device media_dev;
235 struct atomisp_platform_data *pdata;
236 void *mmu_l1_base;
237 struct pci_dev *pci_root;
238 const struct firmware *firmware;
239
240 struct pm_qos_request pm_qos;
241 s32 max_isr_latency;
242
243 /*
244 * ISP modules
245 * Multiple streams are represents by multiple
246 * atomisp_sub_device instances
247 */
248 struct atomisp_sub_device *asd;
249 /*
250 * this will be assiged dyanamically.
251 * For Merr/BTY(ISP2400), 2 streams are supported.
252 */
253 unsigned int num_of_streams;
254
255 struct atomisp_mipi_csi2_device csi2_port[ATOMISP_CAMERA_NR_PORTS];
256 struct atomisp_tpg_device tpg;
257 struct atomisp_file_device file_dev;
258
259 /* Purpose of mutex is to protect and serialize use of isp data
260 * structures and css API calls. */
261 struct rt_mutex mutex;
262 /*
263 * Serialise streamoff: mutex is dropped during streamoff to
264 * cancel the watchdog queue. MUST be acquired BEFORE
265 * "mutex".
266 */
267 struct mutex streamoff_mutex;
268
269 unsigned int input_cnt;
270 struct atomisp_input_subdev inputs[ATOM_ISP_MAX_INPUTS];
271 struct v4l2_subdev *flash;
272 struct v4l2_subdev *motor;
273
274 struct atomisp_regs saved_regs;
275 struct atomisp_sw_contex sw_contex;
276 struct atomisp_css_env css_env;
277
278 /* isp timeout status flag */
279 bool isp_timeout;
280 bool isp_fatal_error;
281 struct workqueue_struct *wdt_work_queue;
282 struct work_struct wdt_work;
283 #ifndef ISP2401
284 atomic_t wdt_count;
285 #endif
286 atomic_t wdt_work_queued;
287
288 spinlock_t lock; /* Just for streaming below */
289
290 bool need_gfx_throttle;
291
292 unsigned int mipi_frame_size;
293 const struct atomisp_dfs_config *dfs;
294 unsigned int hpll_freq;
295
296 bool css_initialized;
297 };
298
299 #define v4l2_dev_to_atomisp_device(dev) \
300 container_of(dev, struct atomisp_device, v4l2_dev)
301
302 extern struct device *atomisp_dev;
303
304 #define atomisp_is_wdt_running(a) timer_pending(&(a)->wdt)
305 #ifdef ISP2401
306 extern void atomisp_wdt_refresh_pipe(struct atomisp_video_pipe *pipe,
307 unsigned int delay);
308 #endif
309 extern void atomisp_wdt_refresh(struct atomisp_sub_device *asd, unsigned int delay);
310 #ifndef ISP2401
311 extern void atomisp_wdt_start(struct atomisp_sub_device *asd);
312 #else
313 extern void atomisp_wdt_start(struct atomisp_video_pipe *pipe);
314 extern void atomisp_wdt_stop_pipe(struct atomisp_video_pipe *pipe, bool sync);
315 #endif
316 extern void atomisp_wdt_stop(struct atomisp_sub_device *asd, bool sync);
317
318 #endif /* __ATOMISP_INTERNAL_H__ */