blob: 521db0ce367d9eaf5c94cab21feb7808e17ba96e [file] [log] [blame]
Sakari Ailus448de7e2011-02-12 18:05:06 -03001/*
2 * isp.h
3 *
4 * TI OMAP3 ISP - Core
5 *
6 * Copyright (C) 2009-2010 Nokia Corporation
7 * Copyright (C) 2009 Texas Instruments, Inc.
8 *
9 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
10 * Sakari Ailus <sakari.ailus@iki.fi>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 * 02110-1301 USA
25 */
26
27#ifndef OMAP3_ISP_CORE_H
28#define OMAP3_ISP_CORE_H
29
Laurent Pinchartb98d32f2011-08-12 19:09:34 +020030#include <media/omap3isp.h>
Sakari Ailus448de7e2011-02-12 18:05:06 -030031#include <media/v4l2-device.h>
32#include <linux/device.h>
33#include <linux/io.h>
34#include <linux/platform_device.h>
35#include <linux/wait.h>
36#include <plat/iommu.h>
37#include <plat/iovmm.h>
38
39#include "ispstat.h"
40#include "ispccdc.h"
41#include "ispreg.h"
42#include "ispresizer.h"
43#include "isppreview.h"
44#include "ispcsiphy.h"
45#include "ispcsi2.h"
46#include "ispccp2.h"
47
48#define IOMMU_FLAG (IOVMF_ENDIAN_LITTLE | IOVMF_ELSZ_8)
49
50#define ISP_TOK_TERM 0xFFFFFFFF /*
51 * terminating token for ISP
52 * modules reg list
53 */
54#define to_isp_device(ptr_module) \
55 container_of(ptr_module, struct isp_device, isp_##ptr_module)
56#define to_device(ptr_module) \
57 (to_isp_device(ptr_module)->dev)
58
59enum isp_mem_resources {
60 OMAP3_ISP_IOMEM_MAIN,
61 OMAP3_ISP_IOMEM_CCP2,
62 OMAP3_ISP_IOMEM_CCDC,
63 OMAP3_ISP_IOMEM_HIST,
64 OMAP3_ISP_IOMEM_H3A,
65 OMAP3_ISP_IOMEM_PREV,
66 OMAP3_ISP_IOMEM_RESZ,
67 OMAP3_ISP_IOMEM_SBL,
68 OMAP3_ISP_IOMEM_CSI2A_REGS1,
69 OMAP3_ISP_IOMEM_CSIPHY2,
70 OMAP3_ISP_IOMEM_CSI2A_REGS2,
71 OMAP3_ISP_IOMEM_CSI2C_REGS1,
72 OMAP3_ISP_IOMEM_CSIPHY1,
73 OMAP3_ISP_IOMEM_CSI2C_REGS2,
74 OMAP3_ISP_IOMEM_LAST
75};
76
77enum isp_sbl_resource {
78 OMAP3_ISP_SBL_CSI1_READ = 0x1,
79 OMAP3_ISP_SBL_CSI1_WRITE = 0x2,
80 OMAP3_ISP_SBL_CSI2A_WRITE = 0x4,
81 OMAP3_ISP_SBL_CSI2C_WRITE = 0x8,
82 OMAP3_ISP_SBL_CCDC_LSC_READ = 0x10,
83 OMAP3_ISP_SBL_CCDC_WRITE = 0x20,
84 OMAP3_ISP_SBL_PREVIEW_READ = 0x40,
85 OMAP3_ISP_SBL_PREVIEW_WRITE = 0x80,
86 OMAP3_ISP_SBL_RESIZER_READ = 0x100,
87 OMAP3_ISP_SBL_RESIZER_WRITE = 0x200,
88};
89
90enum isp_subclk_resource {
91 OMAP3_ISP_SUBCLK_CCDC = (1 << 0),
92 OMAP3_ISP_SUBCLK_H3A = (1 << 1),
93 OMAP3_ISP_SUBCLK_HIST = (1 << 2),
94 OMAP3_ISP_SUBCLK_PREVIEW = (1 << 3),
95 OMAP3_ISP_SUBCLK_RESIZER = (1 << 4),
96};
97
Sakari Ailus448de7e2011-02-12 18:05:06 -030098/* ISP: OMAP 34xx ES 1.0 */
99#define ISP_REVISION_1_0 0x10
100/* ISP2: OMAP 34xx ES 2.0, 2.1 and 3.0 */
101#define ISP_REVISION_2_0 0x20
102/* ISP2P: OMAP 36xx */
103#define ISP_REVISION_15_0 0xF0
104
105/*
106 * struct isp_res_mapping - Map ISP io resources to ISP revision.
107 * @isp_rev: ISP_REVISION_x_x
108 * @map: bitmap for enum isp_mem_resources
109 */
110struct isp_res_mapping {
111 u32 isp_rev;
112 u32 map;
113};
114
115/*
116 * struct isp_reg - Structure for ISP register values.
117 * @reg: 32-bit Register address.
118 * @val: 32-bit Register value.
119 */
120struct isp_reg {
121 enum isp_mem_resources mmio_range;
122 u32 reg;
123 u32 val;
124};
125
Sakari Ailus448de7e2011-02-12 18:05:06 -0300126struct isp_platform_callback {
127 u32 (*set_xclk)(struct isp_device *isp, u32 xclk, u8 xclksel);
128 int (*csiphy_config)(struct isp_csiphy *phy,
129 struct isp_csiphy_dphy_cfg *dphy,
130 struct isp_csiphy_lanes_cfg *lanes);
131 void (*set_pixel_clock)(struct isp_device *isp, unsigned int pixelclk);
132};
133
134/*
135 * struct isp_device - ISP device structure.
136 * @dev: Device pointer specific to the OMAP3 ISP.
137 * @revision: Stores current ISP module revision.
138 * @irq_num: Currently used IRQ number.
139 * @mmio_base: Array with kernel base addresses for ioremapped ISP register
140 * regions.
141 * @mmio_base_phys: Array with physical L4 bus addresses for ISP register
142 * regions.
143 * @mmio_size: Array with ISP register regions size in bytes.
144 * @raw_dmamask: Raw DMA mask
145 * @stat_lock: Spinlock for handling statistics
146 * @isp_mutex: Mutex for serializing requests to ISP.
147 * @has_context: Context has been saved at least once and can be restored.
148 * @ref_count: Reference count for handling multiple ISP requests.
149 * @cam_ick: Pointer to camera interface clock structure.
150 * @cam_mclk: Pointer to camera functional clock structure.
151 * @dpll4_m5_ck: Pointer to DPLL4 M5 clock structure.
152 * @csi2_fck: Pointer to camera CSI2 complexIO clock structure.
153 * @l3_ick: Pointer to OMAP3 L3 bus interface clock.
154 * @irq: Currently attached ISP ISR callbacks information structure.
155 * @isp_af: Pointer to current settings for ISP AutoFocus SCM.
156 * @isp_hist: Pointer to current settings for ISP Histogram SCM.
157 * @isp_h3a: Pointer to current settings for ISP Auto Exposure and
158 * White Balance SCM.
159 * @isp_res: Pointer to current settings for ISP Resizer.
160 * @isp_prev: Pointer to current settings for ISP Preview.
161 * @isp_ccdc: Pointer to current settings for ISP CCDC.
162 * @iommu: Pointer to requested IOMMU instance for ISP.
163 * @platform_cb: ISP driver callback function pointers for platform code
164 *
165 * This structure is used to store the OMAP ISP Information.
166 */
167struct isp_device {
168 struct v4l2_device v4l2_dev;
169 struct media_device media_dev;
170 struct device *dev;
171 u32 revision;
172
173 /* platform HW resources */
174 struct isp_platform_data *pdata;
175 unsigned int irq_num;
176
177 void __iomem *mmio_base[OMAP3_ISP_IOMEM_LAST];
178 unsigned long mmio_base_phys[OMAP3_ISP_IOMEM_LAST];
179 resource_size_t mmio_size[OMAP3_ISP_IOMEM_LAST];
180
181 u64 raw_dmamask;
182
183 /* ISP Obj */
184 spinlock_t stat_lock; /* common lock for statistic drivers */
185 struct mutex isp_mutex; /* For handling ref_count field */
Laurent Pinchart994d5372011-03-01 13:43:07 -0300186 bool needs_reset;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300187 int has_context;
188 int ref_count;
189 unsigned int autoidle;
190 u32 xclk_divisor[2]; /* Two clocks, a and b. */
191#define ISP_CLK_CAM_ICK 0
192#define ISP_CLK_CAM_MCLK 1
193#define ISP_CLK_DPLL4_M5_CK 2
194#define ISP_CLK_CSI2_FCK 3
195#define ISP_CLK_L3_ICK 4
196 struct clk *clock[5];
197
198 /* ISP modules */
199 struct ispstat isp_af;
200 struct ispstat isp_aewb;
201 struct ispstat isp_hist;
202 struct isp_res_device isp_res;
203 struct isp_prev_device isp_prev;
204 struct isp_ccdc_device isp_ccdc;
205 struct isp_csi2_device isp_csi2a;
206 struct isp_csi2_device isp_csi2c;
207 struct isp_ccp2_device isp_ccp2;
208 struct isp_csiphy isp_csiphy1;
209 struct isp_csiphy isp_csiphy2;
210
211 unsigned int sbl_resources;
212 unsigned int subclk_resources;
213
214 struct iommu *iommu;
215
216 struct isp_platform_callback platform_cb;
217};
218
219#define v4l2_dev_to_isp_device(dev) \
220 container_of(dev, struct isp_device, v4l2_dev)
221
222void omap3isp_hist_dma_done(struct isp_device *isp);
223
224void omap3isp_flush(struct isp_device *isp);
225
226int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
227 atomic_t *stopping);
228
229int omap3isp_module_sync_is_stopping(wait_queue_head_t *wait,
230 atomic_t *stopping);
231
232int omap3isp_pipeline_set_stream(struct isp_pipeline *pipe,
233 enum isp_pipeline_stream_state state);
234void omap3isp_configure_bridge(struct isp_device *isp,
235 enum ccdc_input_entity input,
Michael Jonesc09af042011-03-29 05:19:09 -0300236 const struct isp_parallel_platform_data *pdata,
237 unsigned int shift);
Sakari Ailus448de7e2011-02-12 18:05:06 -0300238
Stanimir Varbanov7c2c8f42011-03-21 12:22:44 -0300239#define ISP_XCLK_NONE 0
240#define ISP_XCLK_A 1
241#define ISP_XCLK_B 2
Sakari Ailus448de7e2011-02-12 18:05:06 -0300242
243struct isp_device *omap3isp_get(struct isp_device *isp);
244void omap3isp_put(struct isp_device *isp);
245
246void omap3isp_print_status(struct isp_device *isp);
247
248void omap3isp_sbl_enable(struct isp_device *isp, enum isp_sbl_resource res);
249void omap3isp_sbl_disable(struct isp_device *isp, enum isp_sbl_resource res);
250
251void omap3isp_subclk_enable(struct isp_device *isp,
252 enum isp_subclk_resource res);
253void omap3isp_subclk_disable(struct isp_device *isp,
254 enum isp_subclk_resource res);
255
256int omap3isp_pipeline_pm_use(struct media_entity *entity, int use);
257
258int omap3isp_register_entities(struct platform_device *pdev,
259 struct v4l2_device *v4l2_dev);
260void omap3isp_unregister_entities(struct platform_device *pdev);
261
262/*
263 * isp_reg_readl - Read value of an OMAP3 ISP register
264 * @dev: Device pointer specific to the OMAP3 ISP.
265 * @isp_mmio_range: Range to which the register offset refers to.
266 * @reg_offset: Register offset to read from.
267 *
268 * Returns an unsigned 32 bit value with the required register contents.
269 */
270static inline
271u32 isp_reg_readl(struct isp_device *isp, enum isp_mem_resources isp_mmio_range,
272 u32 reg_offset)
273{
274 return __raw_readl(isp->mmio_base[isp_mmio_range] + reg_offset);
275}
276
277/*
278 * isp_reg_writel - Write value to an OMAP3 ISP register
279 * @dev: Device pointer specific to the OMAP3 ISP.
280 * @reg_value: 32 bit value to write to the register.
281 * @isp_mmio_range: Range to which the register offset refers to.
282 * @reg_offset: Register offset to write into.
283 */
284static inline
285void isp_reg_writel(struct isp_device *isp, u32 reg_value,
286 enum isp_mem_resources isp_mmio_range, u32 reg_offset)
287{
288 __raw_writel(reg_value, isp->mmio_base[isp_mmio_range] + reg_offset);
289}
290
291/*
292 * isp_reg_and - Clear individual bits in an OMAP3 ISP register
293 * @dev: Device pointer specific to the OMAP3 ISP.
294 * @mmio_range: Range to which the register offset refers to.
295 * @reg: Register offset to work on.
296 * @clr_bits: 32 bit value which would be cleared in the register.
297 */
298static inline
299void isp_reg_clr(struct isp_device *isp, enum isp_mem_resources mmio_range,
300 u32 reg, u32 clr_bits)
301{
302 u32 v = isp_reg_readl(isp, mmio_range, reg);
303
304 isp_reg_writel(isp, v & ~clr_bits, mmio_range, reg);
305}
306
307/*
308 * isp_reg_set - Set individual bits in an OMAP3 ISP register
309 * @dev: Device pointer specific to the OMAP3 ISP.
310 * @mmio_range: Range to which the register offset refers to.
311 * @reg: Register offset to work on.
312 * @set_bits: 32 bit value which would be set in the register.
313 */
314static inline
315void isp_reg_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
316 u32 reg, u32 set_bits)
317{
318 u32 v = isp_reg_readl(isp, mmio_range, reg);
319
320 isp_reg_writel(isp, v | set_bits, mmio_range, reg);
321}
322
323/*
324 * isp_reg_clr_set - Clear and set invidial bits in an OMAP3 ISP register
325 * @dev: Device pointer specific to the OMAP3 ISP.
326 * @mmio_range: Range to which the register offset refers to.
327 * @reg: Register offset to work on.
328 * @clr_bits: 32 bit value which would be cleared in the register.
329 * @set_bits: 32 bit value which would be set in the register.
330 *
331 * The clear operation is done first, and then the set operation.
332 */
333static inline
334void isp_reg_clr_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
335 u32 reg, u32 clr_bits, u32 set_bits)
336{
337 u32 v = isp_reg_readl(isp, mmio_range, reg);
338
339 isp_reg_writel(isp, (v & ~clr_bits) | set_bits, mmio_range, reg);
340}
341
342static inline enum v4l2_buf_type
343isp_pad_buffer_type(const struct v4l2_subdev *subdev, int pad)
344{
345 if (pad >= subdev->entity.num_pads)
346 return 0;
347
348 if (subdev->entity.pads[pad].flags & MEDIA_PAD_FL_SINK)
349 return V4L2_BUF_TYPE_VIDEO_OUTPUT;
350 else
351 return V4L2_BUF_TYPE_VIDEO_CAPTURE;
352}
353
354#endif /* OMAP3_ISP_CORE_H */