1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef OMAP3_ISP_CORE_H
18#define OMAP3_ISP_CORE_H
19
20#include <media/media-entity.h>
21#include <media/v4l2-async.h>
22#include <media/v4l2-device.h>
23#include <linux/clk-provider.h>
24#include <linux/device.h>
25#include <linux/io.h>
26#include <linux/platform_device.h>
27#include <linux/wait.h>
28
29#include "omap3isp.h"
30#include "ispstat.h"
31#include "ispccdc.h"
32#include "ispreg.h"
33#include "ispresizer.h"
34#include "isppreview.h"
35#include "ispcsiphy.h"
36#include "ispcsi2.h"
37#include "ispccp2.h"
38
39#define ISP_TOK_TERM 0xFFFFFFFF
40
41
42
43#define to_isp_device(ptr_module) \
44 container_of(ptr_module, struct isp_device, isp_##ptr_module)
45#define to_device(ptr_module) \
46 (to_isp_device(ptr_module)->dev)
47
48enum isp_mem_resources {
49 OMAP3_ISP_IOMEM_MAIN,
50 OMAP3_ISP_IOMEM_CCP2,
51 OMAP3_ISP_IOMEM_CCDC,
52 OMAP3_ISP_IOMEM_HIST,
53 OMAP3_ISP_IOMEM_H3A,
54 OMAP3_ISP_IOMEM_PREV,
55 OMAP3_ISP_IOMEM_RESZ,
56 OMAP3_ISP_IOMEM_SBL,
57 OMAP3_ISP_IOMEM_CSI2A_REGS1,
58 OMAP3_ISP_IOMEM_CSIPHY2,
59 OMAP3_ISP_IOMEM_CSI2A_REGS2,
60 OMAP3_ISP_IOMEM_CSI2C_REGS1,
61 OMAP3_ISP_IOMEM_CSIPHY1,
62 OMAP3_ISP_IOMEM_CSI2C_REGS2,
63 OMAP3_ISP_IOMEM_LAST
64};
65
66enum isp_sbl_resource {
67 OMAP3_ISP_SBL_CSI1_READ = 0x1,
68 OMAP3_ISP_SBL_CSI1_WRITE = 0x2,
69 OMAP3_ISP_SBL_CSI2A_WRITE = 0x4,
70 OMAP3_ISP_SBL_CSI2C_WRITE = 0x8,
71 OMAP3_ISP_SBL_CCDC_LSC_READ = 0x10,
72 OMAP3_ISP_SBL_CCDC_WRITE = 0x20,
73 OMAP3_ISP_SBL_PREVIEW_READ = 0x40,
74 OMAP3_ISP_SBL_PREVIEW_WRITE = 0x80,
75 OMAP3_ISP_SBL_RESIZER_READ = 0x100,
76 OMAP3_ISP_SBL_RESIZER_WRITE = 0x200,
77};
78
79enum isp_subclk_resource {
80 OMAP3_ISP_SUBCLK_CCDC = (1 << 0),
81 OMAP3_ISP_SUBCLK_AEWB = (1 << 1),
82 OMAP3_ISP_SUBCLK_AF = (1 << 2),
83 OMAP3_ISP_SUBCLK_HIST = (1 << 3),
84 OMAP3_ISP_SUBCLK_PREVIEW = (1 << 4),
85 OMAP3_ISP_SUBCLK_RESIZER = (1 << 5),
86};
87
88
89#define ISP_REVISION_1_0 0x10
90
91#define ISP_REVISION_2_0 0x20
92
93#define ISP_REVISION_15_0 0xF0
94
95#define ISP_PHY_TYPE_3430 0
96#define ISP_PHY_TYPE_3630 1
97
98struct regmap;
99
100
101
102
103
104
105
106struct isp_res_mapping {
107 u32 isp_rev;
108 u32 offset[OMAP3_ISP_IOMEM_LAST];
109 u32 phy_type;
110};
111
112
113
114
115
116
117struct isp_reg {
118 enum isp_mem_resources mmio_range;
119 u32 reg;
120 u32 val;
121};
122
123enum isp_xclk_id {
124 ISP_XCLK_A,
125 ISP_XCLK_B,
126};
127
128struct isp_xclk {
129 struct isp_device *isp;
130 struct clk_hw hw;
131 struct clk *clk;
132 enum isp_xclk_id id;
133
134 spinlock_t lock;
135 bool enabled;
136 unsigned int divider;
137};
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175struct isp_device {
176 struct v4l2_device v4l2_dev;
177 struct v4l2_async_notifier notifier;
178 struct media_device media_dev;
179 struct device *dev;
180 u32 revision;
181
182
183 unsigned int irq_num;
184
185 void __iomem *mmio_base[OMAP3_ISP_IOMEM_LAST];
186 unsigned long mmio_hist_base_phys;
187 struct regmap *syscon;
188 u32 syscon_offset;
189 u32 phy_type;
190
191 struct dma_iommu_mapping *mapping;
192
193
194 spinlock_t stat_lock;
195 struct mutex isp_mutex;
196 bool stop_failure;
197 struct media_entity_enum crashed;
198 int has_context;
199 int ref_count;
200 unsigned int autoidle;
201#define ISP_CLK_CAM_ICK 0
202#define ISP_CLK_CAM_MCLK 1
203#define ISP_CLK_CSI2_FCK 2
204#define ISP_CLK_L3_ICK 3
205 struct clk *clock[4];
206 struct isp_xclk xclks[2];
207
208
209 struct ispstat isp_af;
210 struct ispstat isp_aewb;
211 struct ispstat isp_hist;
212 struct isp_res_device isp_res;
213 struct isp_prev_device isp_prev;
214 struct isp_ccdc_device isp_ccdc;
215 struct isp_csi2_device isp_csi2a;
216 struct isp_csi2_device isp_csi2c;
217 struct isp_ccp2_device isp_ccp2;
218 struct isp_csiphy isp_csiphy1;
219 struct isp_csiphy isp_csiphy2;
220
221 unsigned int sbl_resources;
222 unsigned int subclk_resources;
223};
224
225struct isp_async_subdev {
226 struct v4l2_async_subdev asd;
227 struct isp_bus_cfg bus;
228};
229
230#define v4l2_subdev_to_bus_cfg(sd) \
231 (&container_of((sd)->asd, struct isp_async_subdev, asd)->bus)
232
233#define v4l2_dev_to_isp_device(dev) \
234 container_of(dev, struct isp_device, v4l2_dev)
235
236void omap3isp_hist_dma_done(struct isp_device *isp);
237
238void omap3isp_flush(struct isp_device *isp);
239
240int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
241 atomic_t *stopping);
242
243int omap3isp_module_sync_is_stopping(wait_queue_head_t *wait,
244 atomic_t *stopping);
245
246int omap3isp_pipeline_set_stream(struct isp_pipeline *pipe,
247 enum isp_pipeline_stream_state state);
248void omap3isp_pipeline_cancel_stream(struct isp_pipeline *pipe);
249void omap3isp_configure_bridge(struct isp_device *isp,
250 enum ccdc_input_entity input,
251 const struct isp_parallel_cfg *buscfg,
252 unsigned int shift, unsigned int bridge);
253
254struct isp_device *omap3isp_get(struct isp_device *isp);
255void omap3isp_put(struct isp_device *isp);
256
257void omap3isp_print_status(struct isp_device *isp);
258
259void omap3isp_sbl_enable(struct isp_device *isp, enum isp_sbl_resource res);
260void omap3isp_sbl_disable(struct isp_device *isp, enum isp_sbl_resource res);
261
262void omap3isp_subclk_enable(struct isp_device *isp,
263 enum isp_subclk_resource res);
264void omap3isp_subclk_disable(struct isp_device *isp,
265 enum isp_subclk_resource res);
266
267int omap3isp_register_entities(struct platform_device *pdev,
268 struct v4l2_device *v4l2_dev);
269void omap3isp_unregister_entities(struct platform_device *pdev);
270
271
272
273
274
275
276
277
278
279static inline
280u32 isp_reg_readl(struct isp_device *isp, enum isp_mem_resources isp_mmio_range,
281 u32 reg_offset)
282{
283 return __raw_readl(isp->mmio_base[isp_mmio_range] + reg_offset);
284}
285
286
287
288
289
290
291
292
293static inline
294void isp_reg_writel(struct isp_device *isp, u32 reg_value,
295 enum isp_mem_resources isp_mmio_range, u32 reg_offset)
296{
297 __raw_writel(reg_value, isp->mmio_base[isp_mmio_range] + reg_offset);
298}
299
300
301
302
303
304
305
306
307static inline
308void isp_reg_clr(struct isp_device *isp, enum isp_mem_resources mmio_range,
309 u32 reg, u32 clr_bits)
310{
311 u32 v = isp_reg_readl(isp, mmio_range, reg);
312
313 isp_reg_writel(isp, v & ~clr_bits, mmio_range, reg);
314}
315
316
317
318
319
320
321
322
323static inline
324void isp_reg_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
325 u32 reg, u32 set_bits)
326{
327 u32 v = isp_reg_readl(isp, mmio_range, reg);
328
329 isp_reg_writel(isp, v | set_bits, mmio_range, reg);
330}
331
332
333
334
335
336
337
338
339
340
341
342static inline
343void isp_reg_clr_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
344 u32 reg, u32 clr_bits, u32 set_bits)
345{
346 u32 v = isp_reg_readl(isp, mmio_range, reg);
347
348 isp_reg_writel(isp, (v & ~clr_bits) | set_bits, mmio_range, reg);
349}
350
351static inline enum v4l2_buf_type
352isp_pad_buffer_type(const struct v4l2_subdev *subdev, int pad)
353{
354 if (pad >= subdev->entity.num_pads)
355 return 0;
356
357 if (subdev->entity.pads[pad].flags & MEDIA_PAD_FL_SINK)
358 return V4L2_BUF_TYPE_VIDEO_OUTPUT;
359 else
360 return V4L2_BUF_TYPE_VIDEO_CAPTURE;
361}
362
363#endif
364