blob: 49b7f71ac96897487d6c873c834c48d8760f7616 [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
Sakari Ailus17d3d402015-12-16 11:32:30 -020020#include <media/media-entity.h>
Sakari Ailusda7f3842015-03-25 19:57:38 -030021#include <media/v4l2-async.h>
Sakari Ailus448de7e2011-02-12 18:05:06 -030022#include <media/v4l2-device.h>
Laurent Pinchart9b28ee32012-10-22 10:43:00 -030023#include <linux/clk-provider.h>
Sakari Ailus448de7e2011-02-12 18:05:06 -030024#include <linux/device.h>
25#include <linux/io.h>
Tony Lindgrenc8d35c82012-11-02 12:24:03 -070026#include <linux/iommu.h>
Sakari Ailus448de7e2011-02-12 18:05:06 -030027#include <linux/platform_device.h>
28#include <linux/wait.h>
Sakari Ailus448de7e2011-02-12 18:05:06 -030029
Laurent Pinchart78c66fb2015-05-20 04:08:30 -030030#include "omap3isp.h"
Sakari Ailus448de7e2011-02-12 18:05:06 -030031#include "ispstat.h"
32#include "ispccdc.h"
33#include "ispreg.h"
34#include "ispresizer.h"
35#include "isppreview.h"
36#include "ispcsiphy.h"
37#include "ispcsi2.h"
38#include "ispccp2.h"
39
Sakari Ailus448de7e2011-02-12 18:05:06 -030040#define ISP_TOK_TERM 0xFFFFFFFF /*
41 * terminating token for ISP
42 * modules reg list
43 */
44#define to_isp_device(ptr_module) \
45 container_of(ptr_module, struct isp_device, isp_##ptr_module)
46#define to_device(ptr_module) \
47 (to_isp_device(ptr_module)->dev)
48
49enum isp_mem_resources {
50 OMAP3_ISP_IOMEM_MAIN,
51 OMAP3_ISP_IOMEM_CCP2,
52 OMAP3_ISP_IOMEM_CCDC,
53 OMAP3_ISP_IOMEM_HIST,
54 OMAP3_ISP_IOMEM_H3A,
55 OMAP3_ISP_IOMEM_PREV,
56 OMAP3_ISP_IOMEM_RESZ,
57 OMAP3_ISP_IOMEM_SBL,
58 OMAP3_ISP_IOMEM_CSI2A_REGS1,
59 OMAP3_ISP_IOMEM_CSIPHY2,
60 OMAP3_ISP_IOMEM_CSI2A_REGS2,
61 OMAP3_ISP_IOMEM_CSI2C_REGS1,
62 OMAP3_ISP_IOMEM_CSIPHY1,
63 OMAP3_ISP_IOMEM_CSI2C_REGS2,
64 OMAP3_ISP_IOMEM_LAST
65};
66
67enum isp_sbl_resource {
68 OMAP3_ISP_SBL_CSI1_READ = 0x1,
69 OMAP3_ISP_SBL_CSI1_WRITE = 0x2,
70 OMAP3_ISP_SBL_CSI2A_WRITE = 0x4,
71 OMAP3_ISP_SBL_CSI2C_WRITE = 0x8,
72 OMAP3_ISP_SBL_CCDC_LSC_READ = 0x10,
73 OMAP3_ISP_SBL_CCDC_WRITE = 0x20,
74 OMAP3_ISP_SBL_PREVIEW_READ = 0x40,
75 OMAP3_ISP_SBL_PREVIEW_WRITE = 0x80,
76 OMAP3_ISP_SBL_RESIZER_READ = 0x100,
77 OMAP3_ISP_SBL_RESIZER_WRITE = 0x200,
78};
79
80enum isp_subclk_resource {
81 OMAP3_ISP_SUBCLK_CCDC = (1 << 0),
Laurent Pinchartbe9a1b92012-05-25 08:35:10 -030082 OMAP3_ISP_SUBCLK_AEWB = (1 << 1),
83 OMAP3_ISP_SUBCLK_AF = (1 << 2),
84 OMAP3_ISP_SUBCLK_HIST = (1 << 3),
85 OMAP3_ISP_SUBCLK_PREVIEW = (1 << 4),
86 OMAP3_ISP_SUBCLK_RESIZER = (1 << 5),
Sakari Ailus448de7e2011-02-12 18:05:06 -030087};
88
Sakari Ailus448de7e2011-02-12 18:05:06 -030089/* ISP: OMAP 34xx ES 1.0 */
90#define ISP_REVISION_1_0 0x10
91/* ISP2: OMAP 34xx ES 2.0, 2.1 and 3.0 */
92#define ISP_REVISION_2_0 0x20
93/* ISP2P: OMAP 36xx */
94#define ISP_REVISION_15_0 0xF0
95
Sakari Ailus503596a2015-03-25 19:57:34 -030096#define ISP_PHY_TYPE_3430 0
97#define ISP_PHY_TYPE_3630 1
98
99struct regmap;
100
Sakari Ailus448de7e2011-02-12 18:05:06 -0300101/*
102 * struct isp_res_mapping - Map ISP io resources to ISP revision.
103 * @isp_rev: ISP_REVISION_x_x
Sakari Ailus8644cdf2015-03-25 19:57:35 -0300104 * @offset: register offsets of various ISP sub-blocks
Sakari Ailus503596a2015-03-25 19:57:34 -0300105 * @phy_type: ISP_PHY_TYPE_{3430,3630}
Sakari Ailus448de7e2011-02-12 18:05:06 -0300106 */
107struct isp_res_mapping {
108 u32 isp_rev;
Sakari Ailus8644cdf2015-03-25 19:57:35 -0300109 u32 offset[OMAP3_ISP_IOMEM_LAST];
Sakari Ailus503596a2015-03-25 19:57:34 -0300110 u32 phy_type;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300111};
112
113/*
114 * struct isp_reg - Structure for ISP register values.
115 * @reg: 32-bit Register address.
116 * @val: 32-bit Register value.
117 */
118struct isp_reg {
119 enum isp_mem_resources mmio_range;
120 u32 reg;
121 u32 val;
122};
123
Laurent Pinchart9b28ee32012-10-22 10:43:00 -0300124enum isp_xclk_id {
125 ISP_XCLK_A,
126 ISP_XCLK_B,
127};
128
129struct isp_xclk {
130 struct isp_device *isp;
131 struct clk_hw hw;
Sylwester Nawrockif8e2ff22013-12-04 14:12:03 -0300132 struct clk *clk;
Laurent Pinchart9b28ee32012-10-22 10:43:00 -0300133 enum isp_xclk_id id;
134
135 spinlock_t lock; /* Protects enabled and divider */
136 bool enabled;
137 unsigned int divider;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300138};
139
140/*
141 * struct isp_device - ISP device structure.
142 * @dev: Device pointer specific to the OMAP3 ISP.
143 * @revision: Stores current ISP module revision.
144 * @irq_num: Currently used IRQ number.
145 * @mmio_base: Array with kernel base addresses for ioremapped ISP register
146 * regions.
Sakari Ailus4fcfeca2015-03-25 19:57:33 -0300147 * @mmio_hist_base_phys: Physical L4 bus address for ISP hist block register
148 * region.
Sakari Ailus503596a2015-03-25 19:57:34 -0300149 * @syscon: Regmap for the syscon register space
150 * @syscon_offset: Offset of the CSIPHY control register in syscon
151 * @phy_type: ISP_PHY_TYPE_{3430,3630}
Laurent Pinchart2a0a5472014-01-02 20:06:08 -0300152 * @mapping: IOMMU mapping
Sakari Ailus448de7e2011-02-12 18:05:06 -0300153 * @stat_lock: Spinlock for handling statistics
154 * @isp_mutex: Mutex for serializing requests to ISP.
Laurent Pinchart112eee02013-12-15 23:49:42 -0300155 * @stop_failure: Indicates that an entity failed to stop.
Sakari Ailus17d3d402015-12-16 11:32:30 -0200156 * @crashed: Crashed ent_enum
Sakari Ailus448de7e2011-02-12 18:05:06 -0300157 * @has_context: Context has been saved at least once and can be restored.
158 * @ref_count: Reference count for handling multiple ISP requests.
159 * @cam_ick: Pointer to camera interface clock structure.
160 * @cam_mclk: Pointer to camera functional clock structure.
Sakari Ailus448de7e2011-02-12 18:05:06 -0300161 * @csi2_fck: Pointer to camera CSI2 complexIO clock structure.
162 * @l3_ick: Pointer to OMAP3 L3 bus interface clock.
Laurent Pinchart9b28ee32012-10-22 10:43:00 -0300163 * @xclks: External clocks provided by the ISP
Sakari Ailus448de7e2011-02-12 18:05:06 -0300164 * @irq: Currently attached ISP ISR callbacks information structure.
165 * @isp_af: Pointer to current settings for ISP AutoFocus SCM.
166 * @isp_hist: Pointer to current settings for ISP Histogram SCM.
167 * @isp_h3a: Pointer to current settings for ISP Auto Exposure and
168 * White Balance SCM.
169 * @isp_res: Pointer to current settings for ISP Resizer.
170 * @isp_prev: Pointer to current settings for ISP Preview.
171 * @isp_ccdc: Pointer to current settings for ISP CCDC.
Sakari Ailus448de7e2011-02-12 18:05:06 -0300172 * @platform_cb: ISP driver callback function pointers for platform code
173 *
174 * This structure is used to store the OMAP ISP Information.
175 */
176struct isp_device {
177 struct v4l2_device v4l2_dev;
Sakari Ailusda7f3842015-03-25 19:57:38 -0300178 struct v4l2_async_notifier notifier;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300179 struct media_device media_dev;
Sakari Ailus28461452015-12-16 11:32:24 -0200180 struct media_entity_graph pm_count_graph;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300181 struct device *dev;
182 u32 revision;
183
184 /* platform HW resources */
Sakari Ailus448de7e2011-02-12 18:05:06 -0300185 unsigned int irq_num;
186
187 void __iomem *mmio_base[OMAP3_ISP_IOMEM_LAST];
Sakari Ailus4fcfeca2015-03-25 19:57:33 -0300188 unsigned long mmio_hist_base_phys;
Sakari Ailus503596a2015-03-25 19:57:34 -0300189 struct regmap *syscon;
190 u32 syscon_offset;
191 u32 phy_type;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300192
Laurent Pinchart2a0a5472014-01-02 20:06:08 -0300193 struct dma_iommu_mapping *mapping;
194
Sakari Ailus448de7e2011-02-12 18:05:06 -0300195 /* ISP Obj */
196 spinlock_t stat_lock; /* common lock for statistic drivers */
197 struct mutex isp_mutex; /* For handling ref_count field */
Laurent Pinchart112eee02013-12-15 23:49:42 -0300198 bool stop_failure;
Sakari Ailus17d3d402015-12-16 11:32:30 -0200199 struct media_entity_enum crashed;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300200 int has_context;
201 int ref_count;
202 unsigned int autoidle;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300203#define ISP_CLK_CAM_ICK 0
204#define ISP_CLK_CAM_MCLK 1
Laurent Pinchart6d1aa022012-11-10 12:06:25 +0100205#define ISP_CLK_CSI2_FCK 2
206#define ISP_CLK_L3_ICK 3
207 struct clk *clock[4];
Laurent Pinchart9b28ee32012-10-22 10:43:00 -0300208 struct isp_xclk xclks[2];
Sakari Ailus448de7e2011-02-12 18:05:06 -0300209
210 /* ISP modules */
211 struct ispstat isp_af;
212 struct ispstat isp_aewb;
213 struct ispstat isp_hist;
214 struct isp_res_device isp_res;
215 struct isp_prev_device isp_prev;
216 struct isp_ccdc_device isp_ccdc;
217 struct isp_csi2_device isp_csi2a;
218 struct isp_csi2_device isp_csi2c;
219 struct isp_ccp2_device isp_ccp2;
220 struct isp_csiphy isp_csiphy1;
221 struct isp_csiphy isp_csiphy2;
222
223 unsigned int sbl_resources;
224 unsigned int subclk_resources;
Sakari Ailusda7f3842015-03-25 19:57:38 -0300225
226#define ISP_MAX_SUBDEVS 8
227 struct v4l2_subdev *subdevs[ISP_MAX_SUBDEVS];
228};
229
230struct isp_async_subdev {
231 struct v4l2_subdev *sd;
232 struct isp_bus_cfg bus;
233 struct v4l2_async_subdev asd;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300234};
235
236#define v4l2_dev_to_isp_device(dev) \
237 container_of(dev, struct isp_device, v4l2_dev)
238
239void omap3isp_hist_dma_done(struct isp_device *isp);
240
241void omap3isp_flush(struct isp_device *isp);
242
243int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
244 atomic_t *stopping);
245
246int omap3isp_module_sync_is_stopping(wait_queue_head_t *wait,
247 atomic_t *stopping);
248
249int omap3isp_pipeline_set_stream(struct isp_pipeline *pipe,
250 enum isp_pipeline_stream_state state);
Laurent Pinchart661112c2013-12-09 11:36:51 -0300251void omap3isp_pipeline_cancel_stream(struct isp_pipeline *pipe);
Sakari Ailus448de7e2011-02-12 18:05:06 -0300252void omap3isp_configure_bridge(struct isp_device *isp,
253 enum ccdc_input_entity input,
Sakari Ailus689087472015-03-25 19:57:30 -0300254 const struct isp_parallel_cfg *buscfg,
Laurent Pinchartc51364c2011-08-31 11:03:53 -0300255 unsigned int shift, unsigned int bridge);
Sakari Ailus448de7e2011-02-12 18:05:06 -0300256
Sakari Ailus448de7e2011-02-12 18:05:06 -0300257struct isp_device *omap3isp_get(struct isp_device *isp);
258void omap3isp_put(struct isp_device *isp);
259
260void omap3isp_print_status(struct isp_device *isp);
261
262void omap3isp_sbl_enable(struct isp_device *isp, enum isp_sbl_resource res);
263void omap3isp_sbl_disable(struct isp_device *isp, enum isp_sbl_resource res);
264
265void omap3isp_subclk_enable(struct isp_device *isp,
266 enum isp_subclk_resource res);
267void omap3isp_subclk_disable(struct isp_device *isp,
268 enum isp_subclk_resource res);
269
Sakari Ailus28461452015-12-16 11:32:24 -0200270int omap3isp_pipeline_pm_use(struct media_entity *entity, int use,
271 struct media_entity_graph *graph);
Sakari Ailus448de7e2011-02-12 18:05:06 -0300272
273int omap3isp_register_entities(struct platform_device *pdev,
274 struct v4l2_device *v4l2_dev);
275void omap3isp_unregister_entities(struct platform_device *pdev);
276
277/*
278 * isp_reg_readl - Read value of an OMAP3 ISP register
Lad, Prabhakar872aba52014-02-21 09:07:23 -0300279 * @isp: Device pointer specific to the OMAP3 ISP.
Sakari Ailus448de7e2011-02-12 18:05:06 -0300280 * @isp_mmio_range: Range to which the register offset refers to.
281 * @reg_offset: Register offset to read from.
282 *
283 * Returns an unsigned 32 bit value with the required register contents.
284 */
285static inline
286u32 isp_reg_readl(struct isp_device *isp, enum isp_mem_resources isp_mmio_range,
287 u32 reg_offset)
288{
289 return __raw_readl(isp->mmio_base[isp_mmio_range] + reg_offset);
290}
291
292/*
293 * isp_reg_writel - Write value to an OMAP3 ISP register
Lad, Prabhakar872aba52014-02-21 09:07:23 -0300294 * @isp: Device pointer specific to the OMAP3 ISP.
Sakari Ailus448de7e2011-02-12 18:05:06 -0300295 * @reg_value: 32 bit value to write to the register.
296 * @isp_mmio_range: Range to which the register offset refers to.
297 * @reg_offset: Register offset to write into.
298 */
299static inline
300void isp_reg_writel(struct isp_device *isp, u32 reg_value,
301 enum isp_mem_resources isp_mmio_range, u32 reg_offset)
302{
303 __raw_writel(reg_value, isp->mmio_base[isp_mmio_range] + reg_offset);
304}
305
306/*
Lad, Prabhakar872aba52014-02-21 09:07:23 -0300307 * isp_reg_clr - Clear individual bits in an OMAP3 ISP register
308 * @isp: Device pointer specific to the OMAP3 ISP.
Sakari Ailus448de7e2011-02-12 18:05:06 -0300309 * @mmio_range: Range to which the register offset refers to.
310 * @reg: Register offset to work on.
311 * @clr_bits: 32 bit value which would be cleared in the register.
312 */
313static inline
314void isp_reg_clr(struct isp_device *isp, enum isp_mem_resources mmio_range,
315 u32 reg, u32 clr_bits)
316{
317 u32 v = isp_reg_readl(isp, mmio_range, reg);
318
319 isp_reg_writel(isp, v & ~clr_bits, mmio_range, reg);
320}
321
322/*
323 * isp_reg_set - Set individual bits in an OMAP3 ISP register
Lad, Prabhakar872aba52014-02-21 09:07:23 -0300324 * @isp: Device pointer specific to the OMAP3 ISP.
Sakari Ailus448de7e2011-02-12 18:05:06 -0300325 * @mmio_range: Range to which the register offset refers to.
326 * @reg: Register offset to work on.
327 * @set_bits: 32 bit value which would be set in the register.
328 */
329static inline
330void isp_reg_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
331 u32 reg, u32 set_bits)
332{
333 u32 v = isp_reg_readl(isp, mmio_range, reg);
334
335 isp_reg_writel(isp, v | set_bits, mmio_range, reg);
336}
337
338/*
339 * isp_reg_clr_set - Clear and set invidial bits in an OMAP3 ISP register
Lad, Prabhakar872aba52014-02-21 09:07:23 -0300340 * @isp: Device pointer specific to the OMAP3 ISP.
Sakari Ailus448de7e2011-02-12 18:05:06 -0300341 * @mmio_range: Range to which the register offset refers to.
342 * @reg: Register offset to work on.
343 * @clr_bits: 32 bit value which would be cleared in the register.
344 * @set_bits: 32 bit value which would be set in the register.
345 *
346 * The clear operation is done first, and then the set operation.
347 */
348static inline
349void isp_reg_clr_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
350 u32 reg, u32 clr_bits, u32 set_bits)
351{
352 u32 v = isp_reg_readl(isp, mmio_range, reg);
353
354 isp_reg_writel(isp, (v & ~clr_bits) | set_bits, mmio_range, reg);
355}
356
357static inline enum v4l2_buf_type
358isp_pad_buffer_type(const struct v4l2_subdev *subdev, int pad)
359{
360 if (pad >= subdev->entity.num_pads)
361 return 0;
362
363 if (subdev->entity.pads[pad].flags & MEDIA_PAD_FL_SINK)
364 return V4L2_BUF_TYPE_VIDEO_OUTPUT;
365 else
366 return V4L2_BUF_TYPE_VIDEO_CAPTURE;
367}
368
369#endif /* OMAP3_ISP_CORE_H */