1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#ifndef OMAP3_ISP_CORE_H
28#define OMAP3_ISP_CORE_H
29
30#include <media/omap3isp.h>
31#include <media/v4l2-device.h>
32#include <linux/clk-provider.h>
33#include <linux/device.h>
34#include <linux/io.h>
35#include <linux/iommu.h>
36#include <linux/platform_device.h>
37#include <linux/wait.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
52
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_343X_CONTROL_CSIRXFE,
75 OMAP3_ISP_IOMEM_3630_CONTROL_CAMERA_PHY_CTRL,
76 OMAP3_ISP_IOMEM_LAST
77};
78
79enum isp_sbl_resource {
80 OMAP3_ISP_SBL_CSI1_READ = 0x1,
81 OMAP3_ISP_SBL_CSI1_WRITE = 0x2,
82 OMAP3_ISP_SBL_CSI2A_WRITE = 0x4,
83 OMAP3_ISP_SBL_CSI2C_WRITE = 0x8,
84 OMAP3_ISP_SBL_CCDC_LSC_READ = 0x10,
85 OMAP3_ISP_SBL_CCDC_WRITE = 0x20,
86 OMAP3_ISP_SBL_PREVIEW_READ = 0x40,
87 OMAP3_ISP_SBL_PREVIEW_WRITE = 0x80,
88 OMAP3_ISP_SBL_RESIZER_READ = 0x100,
89 OMAP3_ISP_SBL_RESIZER_WRITE = 0x200,
90};
91
92enum isp_subclk_resource {
93 OMAP3_ISP_SUBCLK_CCDC = (1 << 0),
94 OMAP3_ISP_SUBCLK_AEWB = (1 << 1),
95 OMAP3_ISP_SUBCLK_AF = (1 << 2),
96 OMAP3_ISP_SUBCLK_HIST = (1 << 3),
97 OMAP3_ISP_SUBCLK_PREVIEW = (1 << 4),
98 OMAP3_ISP_SUBCLK_RESIZER = (1 << 5),
99};
100
101
102#define ISP_REVISION_1_0 0x10
103
104#define ISP_REVISION_2_0 0x20
105
106#define ISP_REVISION_15_0 0xF0
107
108
109
110
111
112
113struct isp_res_mapping {
114 u32 isp_rev;
115 u32 map;
116};
117
118
119
120
121
122
123struct isp_reg {
124 enum isp_mem_resources mmio_range;
125 u32 reg;
126 u32 val;
127};
128
129enum isp_xclk_id {
130 ISP_XCLK_A,
131 ISP_XCLK_B,
132};
133
134struct isp_xclk {
135 struct isp_device *isp;
136 struct clk_hw hw;
137 struct clk_lookup *lookup;
138 enum isp_xclk_id id;
139
140 spinlock_t lock;
141 bool enabled;
142 unsigned int divider;
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
175
176
177
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
186 struct isp_platform_data *pdata;
187 unsigned int irq_num;
188
189 void __iomem *mmio_base[OMAP3_ISP_IOMEM_LAST];
190 unsigned long mmio_base_phys[OMAP3_ISP_IOMEM_LAST];
191 resource_size_t mmio_size[OMAP3_ISP_IOMEM_LAST];
192
193 u64 raw_dmamask;
194
195
196 spinlock_t stat_lock;
197 struct mutex isp_mutex;
198 u32 crashed;
199 int has_context;
200 int ref_count;
201 unsigned int autoidle;
202#define ISP_CLK_CAM_ICK 0
203#define ISP_CLK_CAM_MCLK 1
204#define ISP_CLK_CSI2_FCK 2
205#define ISP_CLK_L3_ICK 3
206 struct clk *clock[4];
207 struct isp_xclk xclks[2];
208
209
210 struct ispstat isp_af;
211 struct ispstat isp_aewb;
212 struct ispstat isp_hist;
213 struct isp_res_device isp_res;
214 struct isp_prev_device isp_prev;
215 struct isp_ccdc_device isp_ccdc;
216 struct isp_csi2_device isp_csi2a;
217 struct isp_csi2_device isp_csi2c;
218 struct isp_ccp2_device isp_ccp2;
219 struct isp_csiphy isp_csiphy1;
220 struct isp_csiphy isp_csiphy2;
221
222 unsigned int sbl_resources;
223 unsigned int subclk_resources;
224
225 struct iommu_domain *domain;
226};
227
228#define v4l2_dev_to_isp_device(dev) \
229 container_of(dev, struct isp_device, v4l2_dev)
230
231void omap3isp_hist_dma_done(struct isp_device *isp);
232
233void omap3isp_flush(struct isp_device *isp);
234
235int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
236 atomic_t *stopping);
237
238int omap3isp_module_sync_is_stopping(wait_queue_head_t *wait,
239 atomic_t *stopping);
240
241int omap3isp_pipeline_set_stream(struct isp_pipeline *pipe,
242 enum isp_pipeline_stream_state state);
243void omap3isp_configure_bridge(struct isp_device *isp,
244 enum ccdc_input_entity input,
245 const struct isp_parallel_platform_data *pdata,
246 unsigned int shift, unsigned int bridge);
247
248struct isp_device *omap3isp_get(struct isp_device *isp);
249void omap3isp_put(struct isp_device *isp);
250
251void omap3isp_print_status(struct isp_device *isp);
252
253void omap3isp_sbl_enable(struct isp_device *isp, enum isp_sbl_resource res);
254void omap3isp_sbl_disable(struct isp_device *isp, enum isp_sbl_resource res);
255
256void omap3isp_subclk_enable(struct isp_device *isp,
257 enum isp_subclk_resource res);
258void omap3isp_subclk_disable(struct isp_device *isp,
259 enum isp_subclk_resource res);
260
261int omap3isp_pipeline_pm_use(struct media_entity *entity, int use);
262
263int omap3isp_register_entities(struct platform_device *pdev,
264 struct v4l2_device *v4l2_dev);
265void omap3isp_unregister_entities(struct platform_device *pdev);
266
267
268
269
270
271
272
273
274
275static inline
276u32 isp_reg_readl(struct isp_device *isp, enum isp_mem_resources isp_mmio_range,
277 u32 reg_offset)
278{
279 return __raw_readl(isp->mmio_base[isp_mmio_range] + reg_offset);
280}
281
282
283
284
285
286
287
288
289static inline
290void isp_reg_writel(struct isp_device *isp, u32 reg_value,
291 enum isp_mem_resources isp_mmio_range, u32 reg_offset)
292{
293 __raw_writel(reg_value, isp->mmio_base[isp_mmio_range] + reg_offset);
294}
295
296
297
298
299
300
301
302
303static inline
304void isp_reg_clr(struct isp_device *isp, enum isp_mem_resources mmio_range,
305 u32 reg, u32 clr_bits)
306{
307 u32 v = isp_reg_readl(isp, mmio_range, reg);
308
309 isp_reg_writel(isp, v & ~clr_bits, mmio_range, reg);
310}
311
312
313
314
315
316
317
318
319static inline
320void isp_reg_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
321 u32 reg, u32 set_bits)
322{
323 u32 v = isp_reg_readl(isp, mmio_range, reg);
324
325 isp_reg_writel(isp, v | set_bits, mmio_range, reg);
326}
327
328
329
330
331
332
333
334
335
336
337
338static inline
339void isp_reg_clr_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
340 u32 reg, u32 clr_bits, u32 set_bits)
341{
342 u32 v = isp_reg_readl(isp, mmio_range, reg);
343
344 isp_reg_writel(isp, (v & ~clr_bits) | set_bits, mmio_range, reg);
345}
346
347static inline enum v4l2_buf_type
348isp_pad_buffer_type(const struct v4l2_subdev *subdev, int pad)
349{
350 if (pad >= subdev->entity.num_pads)
351 return 0;
352
353 if (subdev->entity.pads[pad].flags & MEDIA_PAD_FL_SINK)
354 return V4L2_BUF_TYPE_VIDEO_OUTPUT;
355 else
356 return V4L2_BUF_TYPE_VIDEO_CAPTURE;
357}
358
359#endif
360