blob: 03d21298c1f5483f1a3f715c0c26924d07f26d25 [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.
Sakari Ailus448de7e2011-02-12 18:05:06 -030015 */
16
17#ifndef OMAP3_ISP_CORE_H
18#define OMAP3_ISP_CORE_H
19
Laurent Pinchartb98d32f2011-08-12 19:09:34 +020020#include <media/omap3isp.h>
Sakari Ailus448de7e2011-02-12 18:05:06 -030021#include <media/v4l2-device.h>
Laurent Pinchart9b28ee32012-10-22 10:43:00 -030022#include <linux/clk-provider.h>
Sakari Ailus448de7e2011-02-12 18:05:06 -030023#include <linux/device.h>
24#include <linux/io.h>
Tony Lindgrenc8d35c82012-11-02 12:24:03 -070025#include <linux/iommu.h>
Sakari Ailus448de7e2011-02-12 18:05:06 -030026#include <linux/platform_device.h>
27#include <linux/wait.h>
Sakari Ailus448de7e2011-02-12 18:05:06 -030028
29#include "ispstat.h"
30#include "ispccdc.h"
31#include "ispreg.h"
32#include "ispresizer.h"
33#include "isppreview.h"
34#include "ispcsiphy.h"
35#include "ispcsi2.h"
36#include "ispccp2.h"
37
Sakari Ailus448de7e2011-02-12 18:05:06 -030038#define ISP_TOK_TERM 0xFFFFFFFF /*
39 * terminating token for ISP
40 * modules reg list
41 */
42#define to_isp_device(ptr_module) \
43 container_of(ptr_module, struct isp_device, isp_##ptr_module)
44#define to_device(ptr_module) \
45 (to_isp_device(ptr_module)->dev)
46
47enum isp_mem_resources {
48 OMAP3_ISP_IOMEM_MAIN,
49 OMAP3_ISP_IOMEM_CCP2,
50 OMAP3_ISP_IOMEM_CCDC,
51 OMAP3_ISP_IOMEM_HIST,
52 OMAP3_ISP_IOMEM_H3A,
53 OMAP3_ISP_IOMEM_PREV,
54 OMAP3_ISP_IOMEM_RESZ,
55 OMAP3_ISP_IOMEM_SBL,
56 OMAP3_ISP_IOMEM_CSI2A_REGS1,
57 OMAP3_ISP_IOMEM_CSIPHY2,
58 OMAP3_ISP_IOMEM_CSI2A_REGS2,
59 OMAP3_ISP_IOMEM_CSI2C_REGS1,
60 OMAP3_ISP_IOMEM_CSIPHY1,
61 OMAP3_ISP_IOMEM_CSI2C_REGS2,
62 OMAP3_ISP_IOMEM_LAST
63};
64
65enum isp_sbl_resource {
66 OMAP3_ISP_SBL_CSI1_READ = 0x1,
67 OMAP3_ISP_SBL_CSI1_WRITE = 0x2,
68 OMAP3_ISP_SBL_CSI2A_WRITE = 0x4,
69 OMAP3_ISP_SBL_CSI2C_WRITE = 0x8,
70 OMAP3_ISP_SBL_CCDC_LSC_READ = 0x10,
71 OMAP3_ISP_SBL_CCDC_WRITE = 0x20,
72 OMAP3_ISP_SBL_PREVIEW_READ = 0x40,
73 OMAP3_ISP_SBL_PREVIEW_WRITE = 0x80,
74 OMAP3_ISP_SBL_RESIZER_READ = 0x100,
75 OMAP3_ISP_SBL_RESIZER_WRITE = 0x200,
76};
77
78enum isp_subclk_resource {
79 OMAP3_ISP_SUBCLK_CCDC = (1 << 0),
Laurent Pinchartbe9a1b92012-05-25 08:35:10 -030080 OMAP3_ISP_SUBCLK_AEWB = (1 << 1),
81 OMAP3_ISP_SUBCLK_AF = (1 << 2),
82 OMAP3_ISP_SUBCLK_HIST = (1 << 3),
83 OMAP3_ISP_SUBCLK_PREVIEW = (1 << 4),
84 OMAP3_ISP_SUBCLK_RESIZER = (1 << 5),
Sakari Ailus448de7e2011-02-12 18:05:06 -030085};
86
Sakari Ailus448de7e2011-02-12 18:05:06 -030087/* ISP: OMAP 34xx ES 1.0 */
88#define ISP_REVISION_1_0 0x10
89/* ISP2: OMAP 34xx ES 2.0, 2.1 and 3.0 */
90#define ISP_REVISION_2_0 0x20
91/* ISP2P: OMAP 36xx */
92#define ISP_REVISION_15_0 0xF0
93
Sakari Ailus503596a2015-03-25 19:57:34 -030094#define ISP_PHY_TYPE_3430 0
95#define ISP_PHY_TYPE_3630 1
96
97struct regmap;
98
Sakari Ailus448de7e2011-02-12 18:05:06 -030099/*
100 * struct isp_res_mapping - Map ISP io resources to ISP revision.
101 * @isp_rev: ISP_REVISION_x_x
102 * @map: bitmap for enum isp_mem_resources
Sakari Ailus503596a2015-03-25 19:57:34 -0300103 * @syscon_offset: offset of the syscon register for 343x / 3630
104 * (CONTROL_CSIRXFE / CONTROL_CAMERA_PHY_CTRL, respectively)
105 * from the syscon base address
106 * @phy_type: ISP_PHY_TYPE_{3430,3630}
Sakari Ailus448de7e2011-02-12 18:05:06 -0300107 */
108struct isp_res_mapping {
109 u32 isp_rev;
110 u32 map;
Sakari Ailus503596a2015-03-25 19:57:34 -0300111 u32 syscon_offset;
112 u32 phy_type;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300113};
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
Laurent Pinchart9b28ee32012-10-22 10:43:00 -0300126enum isp_xclk_id {
127 ISP_XCLK_A,
128 ISP_XCLK_B,
129};
130
131struct isp_xclk {
132 struct isp_device *isp;
133 struct clk_hw hw;
134 struct clk_lookup *lookup;
Sylwester Nawrockif8e2ff22013-12-04 14:12:03 -0300135 struct clk *clk;
Laurent Pinchart9b28ee32012-10-22 10:43:00 -0300136 enum isp_xclk_id id;
137
138 spinlock_t lock; /* Protects enabled and divider */
139 bool enabled;
140 unsigned int divider;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300141};
142
143/*
144 * struct isp_device - ISP device structure.
145 * @dev: Device pointer specific to the OMAP3 ISP.
146 * @revision: Stores current ISP module revision.
147 * @irq_num: Currently used IRQ number.
148 * @mmio_base: Array with kernel base addresses for ioremapped ISP register
149 * regions.
Sakari Ailus4fcfeca2015-03-25 19:57:33 -0300150 * @mmio_hist_base_phys: Physical L4 bus address for ISP hist block register
151 * region.
Sakari Ailus503596a2015-03-25 19:57:34 -0300152 * @syscon: Regmap for the syscon register space
153 * @syscon_offset: Offset of the CSIPHY control register in syscon
154 * @phy_type: ISP_PHY_TYPE_{3430,3630}
Laurent Pinchart2a0a5472014-01-02 20:06:08 -0300155 * @mapping: IOMMU mapping
Sakari Ailus448de7e2011-02-12 18:05:06 -0300156 * @stat_lock: Spinlock for handling statistics
157 * @isp_mutex: Mutex for serializing requests to ISP.
Laurent Pinchart112eee02013-12-15 23:49:42 -0300158 * @stop_failure: Indicates that an entity failed to stop.
Laurent Pinchart1567bb72011-11-18 11:28:24 -0300159 * @crashed: Bitmask of crashed entities (indexed by entity ID)
Sakari Ailus448de7e2011-02-12 18:05:06 -0300160 * @has_context: Context has been saved at least once and can be restored.
161 * @ref_count: Reference count for handling multiple ISP requests.
162 * @cam_ick: Pointer to camera interface clock structure.
163 * @cam_mclk: Pointer to camera functional clock structure.
Sakari Ailus448de7e2011-02-12 18:05:06 -0300164 * @csi2_fck: Pointer to camera CSI2 complexIO clock structure.
165 * @l3_ick: Pointer to OMAP3 L3 bus interface clock.
Laurent Pinchart9b28ee32012-10-22 10:43:00 -0300166 * @xclks: External clocks provided by the ISP
Sakari Ailus448de7e2011-02-12 18:05:06 -0300167 * @irq: Currently attached ISP ISR callbacks information structure.
168 * @isp_af: Pointer to current settings for ISP AutoFocus SCM.
169 * @isp_hist: Pointer to current settings for ISP Histogram SCM.
170 * @isp_h3a: Pointer to current settings for ISP Auto Exposure and
171 * White Balance SCM.
172 * @isp_res: Pointer to current settings for ISP Resizer.
173 * @isp_prev: Pointer to current settings for ISP Preview.
174 * @isp_ccdc: Pointer to current settings for ISP CCDC.
Sakari Ailus448de7e2011-02-12 18:05:06 -0300175 * @platform_cb: ISP driver callback function pointers for platform code
176 *
177 * This structure is used to store the OMAP ISP Information.
178 */
179struct isp_device {
180 struct v4l2_device v4l2_dev;
181 struct media_device media_dev;
182 struct device *dev;
183 u32 revision;
184
185 /* platform HW resources */
186 struct isp_platform_data *pdata;
187 unsigned int irq_num;
188
189 void __iomem *mmio_base[OMAP3_ISP_IOMEM_LAST];
Sakari Ailus4fcfeca2015-03-25 19:57:33 -0300190 unsigned long mmio_hist_base_phys;
Sakari Ailus503596a2015-03-25 19:57:34 -0300191 struct regmap *syscon;
192 u32 syscon_offset;
193 u32 phy_type;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300194
Laurent Pinchart2a0a5472014-01-02 20:06:08 -0300195 struct dma_iommu_mapping *mapping;
196
Sakari Ailus448de7e2011-02-12 18:05:06 -0300197 /* ISP Obj */
198 spinlock_t stat_lock; /* common lock for statistic drivers */
199 struct mutex isp_mutex; /* For handling ref_count field */
Laurent Pinchart112eee02013-12-15 23:49:42 -0300200 bool stop_failure;
Laurent Pinchart1567bb72011-11-18 11:28:24 -0300201 u32 crashed;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300202 int has_context;
203 int ref_count;
204 unsigned int autoidle;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300205#define ISP_CLK_CAM_ICK 0
206#define ISP_CLK_CAM_MCLK 1
Laurent Pinchart6d1aa022012-11-10 12:06:25 +0100207#define ISP_CLK_CSI2_FCK 2
208#define ISP_CLK_L3_ICK 3
209 struct clk *clock[4];
Laurent Pinchart9b28ee32012-10-22 10:43:00 -0300210 struct isp_xclk xclks[2];
Sakari Ailus448de7e2011-02-12 18:05:06 -0300211
212 /* ISP modules */
213 struct ispstat isp_af;
214 struct ispstat isp_aewb;
215 struct ispstat isp_hist;
216 struct isp_res_device isp_res;
217 struct isp_prev_device isp_prev;
218 struct isp_ccdc_device isp_ccdc;
219 struct isp_csi2_device isp_csi2a;
220 struct isp_csi2_device isp_csi2c;
221 struct isp_ccp2_device isp_ccp2;
222 struct isp_csiphy isp_csiphy1;
223 struct isp_csiphy isp_csiphy2;
224
225 unsigned int sbl_resources;
226 unsigned int subclk_resources;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300227};
228
229#define v4l2_dev_to_isp_device(dev) \
230 container_of(dev, struct isp_device, v4l2_dev)
231
232void omap3isp_hist_dma_done(struct isp_device *isp);
233
234void omap3isp_flush(struct isp_device *isp);
235
236int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
237 atomic_t *stopping);
238
239int omap3isp_module_sync_is_stopping(wait_queue_head_t *wait,
240 atomic_t *stopping);
241
242int omap3isp_pipeline_set_stream(struct isp_pipeline *pipe,
243 enum isp_pipeline_stream_state state);
Laurent Pinchart661112c2013-12-09 11:36:51 -0300244void omap3isp_pipeline_cancel_stream(struct isp_pipeline *pipe);
Sakari Ailus448de7e2011-02-12 18:05:06 -0300245void omap3isp_configure_bridge(struct isp_device *isp,
246 enum ccdc_input_entity input,
Sakari Ailus689087472015-03-25 19:57:30 -0300247 const struct isp_parallel_cfg *buscfg,
Laurent Pinchartc51364c2011-08-31 11:03:53 -0300248 unsigned int shift, unsigned int bridge);
Sakari Ailus448de7e2011-02-12 18:05:06 -0300249
Sakari Ailus448de7e2011-02-12 18:05:06 -0300250struct isp_device *omap3isp_get(struct isp_device *isp);
251void omap3isp_put(struct isp_device *isp);
252
253void omap3isp_print_status(struct isp_device *isp);
254
255void omap3isp_sbl_enable(struct isp_device *isp, enum isp_sbl_resource res);
256void omap3isp_sbl_disable(struct isp_device *isp, enum isp_sbl_resource res);
257
258void omap3isp_subclk_enable(struct isp_device *isp,
259 enum isp_subclk_resource res);
260void omap3isp_subclk_disable(struct isp_device *isp,
261 enum isp_subclk_resource res);
262
263int omap3isp_pipeline_pm_use(struct media_entity *entity, int use);
264
265int omap3isp_register_entities(struct platform_device *pdev,
266 struct v4l2_device *v4l2_dev);
267void omap3isp_unregister_entities(struct platform_device *pdev);
268
269/*
270 * isp_reg_readl - Read value of an OMAP3 ISP register
Lad, Prabhakar872aba52014-02-21 09:07:23 -0300271 * @isp: Device pointer specific to the OMAP3 ISP.
Sakari Ailus448de7e2011-02-12 18:05:06 -0300272 * @isp_mmio_range: Range to which the register offset refers to.
273 * @reg_offset: Register offset to read from.
274 *
275 * Returns an unsigned 32 bit value with the required register contents.
276 */
277static inline
278u32 isp_reg_readl(struct isp_device *isp, enum isp_mem_resources isp_mmio_range,
279 u32 reg_offset)
280{
281 return __raw_readl(isp->mmio_base[isp_mmio_range] + reg_offset);
282}
283
284/*
285 * isp_reg_writel - Write value to an OMAP3 ISP register
Lad, Prabhakar872aba52014-02-21 09:07:23 -0300286 * @isp: Device pointer specific to the OMAP3 ISP.
Sakari Ailus448de7e2011-02-12 18:05:06 -0300287 * @reg_value: 32 bit value to write to the register.
288 * @isp_mmio_range: Range to which the register offset refers to.
289 * @reg_offset: Register offset to write into.
290 */
291static inline
292void isp_reg_writel(struct isp_device *isp, u32 reg_value,
293 enum isp_mem_resources isp_mmio_range, u32 reg_offset)
294{
295 __raw_writel(reg_value, isp->mmio_base[isp_mmio_range] + reg_offset);
296}
297
298/*
Lad, Prabhakar872aba52014-02-21 09:07:23 -0300299 * isp_reg_clr - Clear individual bits in an OMAP3 ISP register
300 * @isp: Device pointer specific to the OMAP3 ISP.
Sakari Ailus448de7e2011-02-12 18:05:06 -0300301 * @mmio_range: Range to which the register offset refers to.
302 * @reg: Register offset to work on.
303 * @clr_bits: 32 bit value which would be cleared in the register.
304 */
305static inline
306void isp_reg_clr(struct isp_device *isp, enum isp_mem_resources mmio_range,
307 u32 reg, u32 clr_bits)
308{
309 u32 v = isp_reg_readl(isp, mmio_range, reg);
310
311 isp_reg_writel(isp, v & ~clr_bits, mmio_range, reg);
312}
313
314/*
315 * isp_reg_set - Set individual bits in an OMAP3 ISP register
Lad, Prabhakar872aba52014-02-21 09:07:23 -0300316 * @isp: Device pointer specific to the OMAP3 ISP.
Sakari Ailus448de7e2011-02-12 18:05:06 -0300317 * @mmio_range: Range to which the register offset refers to.
318 * @reg: Register offset to work on.
319 * @set_bits: 32 bit value which would be set in the register.
320 */
321static inline
322void isp_reg_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
323 u32 reg, u32 set_bits)
324{
325 u32 v = isp_reg_readl(isp, mmio_range, reg);
326
327 isp_reg_writel(isp, v | set_bits, mmio_range, reg);
328}
329
330/*
331 * isp_reg_clr_set - Clear and set invidial bits in an OMAP3 ISP register
Lad, Prabhakar872aba52014-02-21 09:07:23 -0300332 * @isp: Device pointer specific to the OMAP3 ISP.
Sakari Ailus448de7e2011-02-12 18:05:06 -0300333 * @mmio_range: Range to which the register offset refers to.
334 * @reg: Register offset to work on.
335 * @clr_bits: 32 bit value which would be cleared in the register.
336 * @set_bits: 32 bit value which would be set in the register.
337 *
338 * The clear operation is done first, and then the set operation.
339 */
340static inline
341void isp_reg_clr_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
342 u32 reg, u32 clr_bits, u32 set_bits)
343{
344 u32 v = isp_reg_readl(isp, mmio_range, reg);
345
346 isp_reg_writel(isp, (v & ~clr_bits) | set_bits, mmio_range, reg);
347}
348
349static inline enum v4l2_buf_type
350isp_pad_buffer_type(const struct v4l2_subdev *subdev, int pad)
351{
352 if (pad >= subdev->entity.num_pads)
353 return 0;
354
355 if (subdev->entity.pads[pad].flags & MEDIA_PAD_FL_SINK)
356 return V4L2_BUF_TYPE_VIDEO_OUTPUT;
357 else
358 return V4L2_BUF_TYPE_VIDEO_CAPTURE;
359}
360
361#endif /* OMAP3_ISP_CORE_H */