goldfish: Fix build error of missing ioremap on UM
[linux-2.6-block.git] / drivers / staging / media / omap4iss / iss.h
1 /*
2  * TI OMAP4 ISS V4L2 Driver
3  *
4  * Copyright (C) 2012 Texas Instruments.
5  *
6  * Author: Sergio Aguirre <sergio.a.aguirre@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  */
13
14 #ifndef _OMAP4_ISS_H_
15 #define _OMAP4_ISS_H_
16
17 #include <media/v4l2-device.h>
18 #include <linux/device.h>
19 #include <linux/io.h>
20 #include <linux/platform_device.h>
21 #include <linux/wait.h>
22
23 #include <linux/platform_data/media/omap4iss.h>
24
25 #include "iss_regs.h"
26 #include "iss_csiphy.h"
27 #include "iss_csi2.h"
28 #include "iss_ipipeif.h"
29 #include "iss_ipipe.h"
30 #include "iss_resizer.h"
31
32 struct regmap;
33
34 #define to_iss_device(ptr_module)                               \
35         container_of(ptr_module, struct iss_device, ptr_module)
36 #define to_device(ptr_module)                                           \
37         (to_iss_device(ptr_module)->dev)
38
39 enum iss_mem_resources {
40         OMAP4_ISS_MEM_TOP,
41         OMAP4_ISS_MEM_CSI2_A_REGS1,
42         OMAP4_ISS_MEM_CAMERARX_CORE1,
43         OMAP4_ISS_MEM_CSI2_B_REGS1,
44         OMAP4_ISS_MEM_CAMERARX_CORE2,
45         OMAP4_ISS_MEM_BTE,
46         OMAP4_ISS_MEM_ISP_SYS1,
47         OMAP4_ISS_MEM_ISP_RESIZER,
48         OMAP4_ISS_MEM_ISP_IPIPE,
49         OMAP4_ISS_MEM_ISP_ISIF,
50         OMAP4_ISS_MEM_ISP_IPIPEIF,
51         OMAP4_ISS_MEM_LAST,
52 };
53
54 enum iss_subclk_resource {
55         OMAP4_ISS_SUBCLK_SIMCOP         = (1 << 0),
56         OMAP4_ISS_SUBCLK_ISP            = (1 << 1),
57         OMAP4_ISS_SUBCLK_CSI2_A         = (1 << 2),
58         OMAP4_ISS_SUBCLK_CSI2_B         = (1 << 3),
59         OMAP4_ISS_SUBCLK_CCP2           = (1 << 4),
60 };
61
62 enum iss_isp_subclk_resource {
63         OMAP4_ISS_ISP_SUBCLK_BL         = (1 << 0),
64         OMAP4_ISS_ISP_SUBCLK_ISIF       = (1 << 1),
65         OMAP4_ISS_ISP_SUBCLK_H3A        = (1 << 2),
66         OMAP4_ISS_ISP_SUBCLK_RSZ        = (1 << 3),
67         OMAP4_ISS_ISP_SUBCLK_IPIPE      = (1 << 4),
68         OMAP4_ISS_ISP_SUBCLK_IPIPEIF    = (1 << 5),
69 };
70
71 /*
72  * struct iss_reg - Structure for ISS register values.
73  * @reg: 32-bit Register address.
74  * @val: 32-bit Register value.
75  */
76 struct iss_reg {
77         enum iss_mem_resources mmio_range;
78         u32 reg;
79         u32 val;
80 };
81
82 /*
83  * struct iss_device - ISS device structure.
84  * @syscon: Regmap for the syscon register space
85  * @crashed: Crashed entities
86  */
87 struct iss_device {
88         struct v4l2_device v4l2_dev;
89         struct media_device media_dev;
90         struct media_entity_graph pm_count_graph;
91         struct device *dev;
92         u32 revision;
93
94         /* platform HW resources */
95         struct iss_platform_data *pdata;
96         unsigned int irq_num;
97
98         struct resource *res[OMAP4_ISS_MEM_LAST];
99         void __iomem *regs[OMAP4_ISS_MEM_LAST];
100         struct regmap *syscon;
101
102         u64 raw_dmamask;
103
104         struct mutex iss_mutex; /* For handling ref_count field */
105         struct media_entity_enum crashed;
106         int has_context;
107         int ref_count;
108
109         struct clk *iss_fck;
110         struct clk *iss_ctrlclk;
111
112         /* ISS modules */
113         struct iss_csi2_device csi2a;
114         struct iss_csi2_device csi2b;
115         struct iss_csiphy csiphy1;
116         struct iss_csiphy csiphy2;
117         struct iss_ipipeif_device ipipeif;
118         struct iss_ipipe_device ipipe;
119         struct iss_resizer_device resizer;
120
121         unsigned int subclk_resources;
122         unsigned int isp_subclk_resources;
123 };
124
125 #define v4l2_dev_to_iss_device(dev) \
126         container_of(dev, struct iss_device, v4l2_dev)
127
128 int omap4iss_get_external_info(struct iss_pipeline *pipe,
129                                struct media_link *link);
130
131 int omap4iss_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
132                               atomic_t *stopping);
133
134 int omap4iss_module_sync_is_stopping(wait_queue_head_t *wait,
135                                      atomic_t *stopping);
136
137 int omap4iss_pipeline_set_stream(struct iss_pipeline *pipe,
138                                  enum iss_pipeline_stream_state state);
139 void omap4iss_pipeline_cancel_stream(struct iss_pipeline *pipe);
140
141 void omap4iss_configure_bridge(struct iss_device *iss,
142                                enum ipipeif_input_entity input);
143
144 struct iss_device *omap4iss_get(struct iss_device *iss);
145 void omap4iss_put(struct iss_device *iss);
146 int omap4iss_subclk_enable(struct iss_device *iss,
147                            enum iss_subclk_resource res);
148 int omap4iss_subclk_disable(struct iss_device *iss,
149                             enum iss_subclk_resource res);
150 void omap4iss_isp_subclk_enable(struct iss_device *iss,
151                                 enum iss_isp_subclk_resource res);
152 void omap4iss_isp_subclk_disable(struct iss_device *iss,
153                                  enum iss_isp_subclk_resource res);
154
155 int omap4iss_pipeline_pm_use(struct media_entity *entity, int use,
156                              struct media_entity_graph *graph);
157
158 int omap4iss_register_entities(struct platform_device *pdev,
159                                struct v4l2_device *v4l2_dev);
160 void omap4iss_unregister_entities(struct platform_device *pdev);
161
162 /*
163  * iss_reg_read - Read the value of an OMAP4 ISS register
164  * @iss: the ISS device
165  * @res: memory resource in which the register is located
166  * @offset: register offset in the memory resource
167  *
168  * Return the register value.
169  */
170 static inline
171 u32 iss_reg_read(struct iss_device *iss, enum iss_mem_resources res,
172                  u32 offset)
173 {
174         return readl(iss->regs[res] + offset);
175 }
176
177 /*
178  * iss_reg_write - Write a value to an OMAP4 ISS register
179  * @iss: the ISS device
180  * @res: memory resource in which the register is located
181  * @offset: register offset in the memory resource
182  * @value: value to be written
183  */
184 static inline
185 void iss_reg_write(struct iss_device *iss, enum iss_mem_resources res,
186                    u32 offset, u32 value)
187 {
188         writel(value, iss->regs[res] + offset);
189 }
190
191 /*
192  * iss_reg_clr - Clear bits in an OMAP4 ISS register
193  * @iss: the ISS device
194  * @res: memory resource in which the register is located
195  * @offset: register offset in the memory resource
196  * @clr: bit mask to be cleared
197  */
198 static inline
199 void iss_reg_clr(struct iss_device *iss, enum iss_mem_resources res,
200                  u32 offset, u32 clr)
201 {
202         u32 v = iss_reg_read(iss, res, offset);
203
204         iss_reg_write(iss, res, offset, v & ~clr);
205 }
206
207 /*
208  * iss_reg_set - Set bits in an OMAP4 ISS register
209  * @iss: the ISS device
210  * @res: memory resource in which the register is located
211  * @offset: register offset in the memory resource
212  * @set: bit mask to be set
213  */
214 static inline
215 void iss_reg_set(struct iss_device *iss, enum iss_mem_resources res,
216                  u32 offset, u32 set)
217 {
218         u32 v = iss_reg_read(iss, res, offset);
219
220         iss_reg_write(iss, res, offset, v | set);
221 }
222
223 /*
224  * iss_reg_update - Clear and set bits in an OMAP4 ISS register
225  * @iss: the ISS device
226  * @res: memory resource in which the register is located
227  * @offset: register offset in the memory resource
228  * @clr: bit mask to be cleared
229  * @set: bit mask to be set
230  *
231  * Clear the clr mask first and then set the set mask.
232  */
233 static inline
234 void iss_reg_update(struct iss_device *iss, enum iss_mem_resources res,
235                     u32 offset, u32 clr, u32 set)
236 {
237         u32 v = iss_reg_read(iss, res, offset);
238
239         iss_reg_write(iss, res, offset, (v & ~clr) | set);
240 }
241
242 #define iss_poll_condition_timeout(cond, timeout, min_ival, max_ival)   \
243 ({                                                                      \
244         unsigned long __timeout = jiffies + usecs_to_jiffies(timeout);  \
245         unsigned int __min_ival = (min_ival);                           \
246         unsigned int __max_ival = (max_ival);                           \
247         bool __cond;                                                    \
248         while (!(__cond = (cond))) {                                    \
249                 if (time_after(jiffies, __timeout))                     \
250                         break;                                          \
251                 usleep_range(__min_ival, __max_ival);                   \
252         }                                                               \
253         !__cond;                                                        \
254 })
255
256 #endif /* _OMAP4_ISS_H_ */