~ubuntu-branches/ubuntu/precise/linux-lowlatency/precise

« back to all changes in this revision

Viewing changes to drivers/media/video/omap3isp/isp.h

  • Committer: Package Import Robot
  • Author(s): Alessio Igor Bogani
  • Date: 2011-10-26 11:13:05 UTC
  • Revision ID: package-import@ubuntu.com-20111026111305-tz023xykf0i6eosh
Tags: upstream-3.2.0
ImportĀ upstreamĀ versionĀ 3.2.0

Show diffs side-by-side

added added

removed removed

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