2 * TI OMAP4 ISS V4L2 Driver
4 * Copyright (C) 2012 Texas Instruments.
6 * Author: Sergio Aguirre <sergio.a.aguirre@gmail.com>
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.
17 #include <media/v4l2-device.h>
18 #include <linux/device.h>
20 #include <linux/platform_device.h>
21 #include <linux/wait.h>
23 #include <linux/platform_data/media/omap4iss.h>
26 #include "iss_csiphy.h"
28 #include "iss_ipipeif.h"
29 #include "iss_ipipe.h"
30 #include "iss_resizer.h"
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)
39 enum iss_mem_resources {
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,
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,
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),
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),
72 * struct iss_reg - Structure for ISS register values.
73 * @reg: 32-bit Register address.
74 * @val: 32-bit Register value.
77 enum iss_mem_resources mmio_range;
83 * struct iss_device - ISS device structure.
84 * @syscon: Regmap for the syscon register space
85 * @crashed: Crashed entities
88 struct v4l2_device v4l2_dev;
89 struct media_device media_dev;
90 struct media_entity_graph pm_count_graph;
94 /* platform HW resources */
95 struct iss_platform_data *pdata;
98 struct resource *res[OMAP4_ISS_MEM_LAST];
99 void __iomem *regs[OMAP4_ISS_MEM_LAST];
100 struct regmap *syscon;
104 struct mutex iss_mutex; /* For handling ref_count field */
105 struct media_entity_enum crashed;
110 struct clk *iss_ctrlclk;
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;
121 unsigned int subclk_resources;
122 unsigned int isp_subclk_resources;
125 #define v4l2_dev_to_iss_device(dev) \
126 container_of(dev, struct iss_device, v4l2_dev)
128 int omap4iss_get_external_info(struct iss_pipeline *pipe,
129 struct media_link *link);
131 int omap4iss_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
134 int omap4iss_module_sync_is_stopping(wait_queue_head_t *wait,
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);
141 void omap4iss_configure_bridge(struct iss_device *iss,
142 enum ipipeif_input_entity input);
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);
155 int omap4iss_pipeline_pm_use(struct media_entity *entity, int use,
156 struct media_entity_graph *graph);
158 int omap4iss_register_entities(struct platform_device *pdev,
159 struct v4l2_device *v4l2_dev);
160 void omap4iss_unregister_entities(struct platform_device *pdev);
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
168 * Return the register value.
171 u32 iss_reg_read(struct iss_device *iss, enum iss_mem_resources res,
174 return readl(iss->regs[res] + offset);
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
185 void iss_reg_write(struct iss_device *iss, enum iss_mem_resources res,
186 u32 offset, u32 value)
188 writel(value, iss->regs[res] + offset);
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
199 void iss_reg_clr(struct iss_device *iss, enum iss_mem_resources res,
202 u32 v = iss_reg_read(iss, res, offset);
204 iss_reg_write(iss, res, offset, v & ~clr);
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
215 void iss_reg_set(struct iss_device *iss, enum iss_mem_resources res,
218 u32 v = iss_reg_read(iss, res, offset);
220 iss_reg_write(iss, res, offset, v | set);
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
231 * Clear the clr mask first and then set the set mask.
234 void iss_reg_update(struct iss_device *iss, enum iss_mem_resources res,
235 u32 offset, u32 clr, u32 set)
237 u32 v = iss_reg_read(iss, res, offset);
239 iss_reg_write(iss, res, offset, (v & ~clr) | set);
242 #define iss_poll_condition_timeout(cond, timeout, min_ival, max_ival) \
244 unsigned long __timeout = jiffies + usecs_to_jiffies(timeout); \
245 unsigned int __min_ival = (min_ival); \
246 unsigned int __max_ival = (max_ival); \
248 while (!(__cond = (cond))) { \
249 if (time_after(jiffies, __timeout)) \
251 usleep_range(__min_ival, __max_ival); \
256 #endif /* _OMAP4_ISS_H_ */