2 * Support for Medifield PNW Camera Imaging ISP subsystem.
4 * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
6 * Copyright (c) 2010 Silicon Hive www.siliconhive.com.
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.
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.
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
23 #ifndef __ATOMISP_INTERNAL_H__
24 #define __ATOMISP_INTERNAL_H__
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>
32 #include <asm/intel-mid.h>
33 #include "../../include/asm/intel_mid_pcihelpers.h"
35 #include <media/media-device.h>
36 #include <media/v4l2-subdev.h>
39 #include "ia_css_types.h"
40 #include "sh_css_legacy.h"
42 /*#include "ia_css_types.h"*/
43 /*#include "sh_css_legacy.h"*/
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"
52 #include "gp_device.h"
54 #include <linux/vmalloc.h>
56 #define V4L2_EVENT_FRAME_END 5
58 #define IS_HWREVISION(isp, rev) \
59 (((isp)->media_dev.hw_revision & ATOMISP_HW_REVISION_MASK) == \
60 ((rev) << ATOMISP_HW_REVISION_SHIFT))
62 #define MAX_STREAM_NUM 2
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
75 #define ATOMISP_PCI_REV_MRFLD_A0_MAX 0
76 #define ATOMISP_PCI_REV_BYT_A0_MAX 4
78 #define ATOM_ISP_STEP_WIDTH 2
79 #define ATOM_ISP_STEP_HEIGHT 2
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
86 /* sub-QCIF resolution */
87 #define ATOM_RESOLUTION_SUBQCIF_WIDTH 128
88 #define ATOM_RESOLUTION_SUBQCIF_HEIGHT 96
90 #define ATOM_ISP_MAX_WIDTH_TMP 1280
91 #define ATOM_ISP_MAX_HEIGHT_TMP 720
93 #define ATOM_ISP_I2C_BUS_1 4
94 #define ATOM_ISP_I2C_BUS_2 5
96 #define ATOM_ISP_POWER_DOWN 0
97 #define ATOM_ISP_POWER_UP 1
99 #define ATOM_ISP_MAX_INPUTS 4
101 #define ATOMISP_SC_TYPE_SIZE 2
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
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
116 #define ATOMISP_DELAYED_INIT_NOT_QUEUED 0
117 #define ATOMISP_DELAYED_INIT_QUEUED 1
118 #define ATOMISP_DELAYED_INIT_DONE 2
120 #define ATOMISP_CALC_CSS_PREV_OVERLAP(lines) \
121 ((lines) * 38 / 100 & 0xfffffe)
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.
131 #define ATOMISP_MAX_ISR_LATENCY 1000
133 /* Add new YUVPP pipe for SOC sensor. */
134 #define ATOMISP_CSS_SUPPORT_YUVPP 1
136 #define ATOMISP_CSS_OUTPUT_SECOND_INDEX 1
137 #define ATOMISP_CSS_OUTPUT_DEFAULT_INDEX 0
141 * This is to differentiate between ext-isp and soc camera in
142 * Moorefield/Baytrail platform.
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)
149 #define ATOMISP_USE_YUVPP(asd) \
150 (ATOMISP_SOC_CAMERA(asd) && ATOMISP_CSS_SUPPORT_YUVPP && \
153 #define ATOMISP_DEPTH_SENSOR_STREAMON_COUNT 2
155 #define ATOMISP_DEPTH_DEFAULT_MASTER_SENSOR 0
156 #define ATOMISP_DEPTH_DEFAULT_SLAVE_SENSOR 1
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)
165 #define DIV_NEAREST_STEP(n, d, step) \
166 round_down((2 * (n) + (d) * (step))/(2 * (d)), (step))
168 struct atomisp_input_subdev
{
170 enum atomisp_camera_port port
;
171 struct v4l2_subdev
*camera
;
172 struct v4l2_subdev
*motor
;
173 struct v4l2_frmsizeenum frame_size
;
176 * To show this resource is used by
177 * which stream, in ISP multiple stream mode
179 struct atomisp_sub_device
*asd
;
181 const struct atomisp_camera_caps
*camera_caps
;
185 enum atomisp_dfs_mode
{
186 ATOMISP_DFS_MODE_AUTO
= 0,
187 ATOMISP_DFS_MODE_LOW
,
188 ATOMISP_DFS_MODE_MAX
,
191 struct atomisp_regs
{
192 /* PCI config space info */
199 u32 interrupt_control
;
204 /* I-Unit PHY related info */
205 u32 csi_rcomp_config
;
210 u32 csi_afe_rcomp_config
;
211 u32 csi_afe_hs_control
;
212 u32 csi_deadline_control
;
216 struct atomisp_sw_contex
{
223 #define ATOMISP_DEVICE_STREAMING_DISABLED 0
224 #define ATOMISP_DEVICE_STREAMING_ENABLED 1
225 #define ATOMISP_DEVICE_STREAMING_STOPPING 2
230 struct atomisp_device
{
231 struct pci_dev
*pdev
;
233 struct v4l2_device v4l2_dev
;
234 struct media_device media_dev
;
235 struct atomisp_platform_data
*pdata
;
237 struct pci_dev
*pci_root
;
238 const struct firmware
*firmware
;
240 struct pm_qos_request pm_qos
;
245 * Multiple streams are represents by multiple
246 * atomisp_sub_device instances
248 struct atomisp_sub_device
*asd
;
250 * this will be assiged dyanamically.
251 * For Merr/BTY(ISP2400), 2 streams are supported.
253 unsigned int num_of_streams
;
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
;
259 /* Purpose of mutex is to protect and serialize use of isp data
260 * structures and css API calls. */
261 struct rt_mutex mutex
;
263 * Serialise streamoff: mutex is dropped during streamoff to
264 * cancel the watchdog queue. MUST be acquired BEFORE
267 struct mutex streamoff_mutex
;
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
;
274 struct atomisp_regs saved_regs
;
275 struct atomisp_sw_contex sw_contex
;
276 struct atomisp_css_env css_env
;
278 /* isp timeout status flag */
280 bool isp_fatal_error
;
281 struct workqueue_struct
*wdt_work_queue
;
282 struct work_struct wdt_work
;
286 atomic_t wdt_work_queued
;
288 spinlock_t lock
; /* Just for streaming below */
290 bool need_gfx_throttle
;
292 unsigned int mipi_frame_size
;
293 const struct atomisp_dfs_config
*dfs
;
294 unsigned int hpll_freq
;
296 bool css_initialized
;
299 #define v4l2_dev_to_atomisp_device(dev) \
300 container_of(dev, struct atomisp_device, v4l2_dev)
302 extern struct device
*atomisp_dev
;
304 #define atomisp_is_wdt_running(a) timer_pending(&(a)->wdt)
306 extern void atomisp_wdt_refresh_pipe(struct atomisp_video_pipe
*pipe
,
309 extern void atomisp_wdt_refresh(struct atomisp_sub_device
*asd
, unsigned int delay
);
311 extern void atomisp_wdt_start(struct atomisp_sub_device
*asd
);
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
);
316 extern void atomisp_wdt_stop(struct atomisp_sub_device
*asd
, bool sync
);
318 #endif /* __ATOMISP_INTERNAL_H__ */