blob: a9f6de5b69d85949fdda469d9ed2e9aaafa8cdd5 [file] [log] [blame]
Sakari Ailus448de7e2011-02-12 18:05:06 -03001/*
2 * isp.c
3 *
4 * TI OMAP3 ISP - Core
5 *
6 * Copyright (C) 2006-2010 Nokia Corporation
7 * Copyright (C) 2007-2009 Texas Instruments, Inc.
8 *
9 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
10 * Sakari Ailus <sakari.ailus@iki.fi>
11 *
12 * Contributors:
13 * Laurent Pinchart <laurent.pinchart@ideasonboard.com>
14 * Sakari Ailus <sakari.ailus@iki.fi>
15 * David Cohen <dacohen@gmail.com>
16 * Stanimir Varbanov <svarbanov@mm-sol.com>
17 * Vimarsh Zutshi <vimarsh.zutshi@gmail.com>
18 * Tuukka Toivonen <tuukkat76@gmail.com>
19 * Sergio Aguirre <saaguirre@ti.com>
20 * Antti Koskipaa <akoskipa@gmail.com>
21 * Ivan T. Ivanov <iivanov@mm-sol.com>
22 * RaniSuneela <r-m@ti.com>
23 * Atanas Filipov <afilipov@mm-sol.com>
24 * Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
25 * Hiroshi DOYU <hiroshi.doyu@nokia.com>
26 * Nayden Kanchev <nkanchev@mm-sol.com>
27 * Phil Carmody <ext-phil.2.carmody@nokia.com>
28 * Artem Bityutskiy <artem.bityutskiy@nokia.com>
29 * Dominic Curran <dcurran@ti.com>
30 * Ilkka Myllyperkio <ilkka.myllyperkio@sofica.fi>
31 * Pallavi Kulkarni <p-kulkarni@ti.com>
32 * Vaibhav Hiremath <hvaibhav@ti.com>
33 * Mohit Jalori <mjalori@ti.com>
34 * Sameer Venkatraman <sameerv@ti.com>
35 * Senthilvadivu Guruswamy <svadivu@ti.com>
36 * Thara Gopinath <thara@ti.com>
37 * Toni Leinonen <toni.leinonen@nokia.com>
38 * Troy Laramy <t-laramy@ti.com>
39 *
40 * This program is free software; you can redistribute it and/or modify
41 * it under the terms of the GNU General Public License version 2 as
42 * published by the Free Software Foundation.
43 *
44 * This program is distributed in the hope that it will be useful, but
45 * WITHOUT ANY WARRANTY; without even the implied warranty of
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
47 * General Public License for more details.
48 *
49 * You should have received a copy of the GNU General Public License
50 * along with this program; if not, write to the Free Software
51 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
52 * 02110-1301 USA
53 */
54
55#include <asm/cacheflush.h>
56
57#include <linux/clk.h>
58#include <linux/delay.h>
59#include <linux/device.h>
60#include <linux/dma-mapping.h>
61#include <linux/i2c.h>
62#include <linux/interrupt.h>
63#include <linux/module.h>
Tony Lindgrenc8d35c82012-11-02 12:24:03 -070064#include <linux/omap-iommu.h>
Sakari Ailus448de7e2011-02-12 18:05:06 -030065#include <linux/platform_device.h>
66#include <linux/regulator/consumer.h>
67#include <linux/slab.h>
68#include <linux/sched.h>
69#include <linux/vmalloc.h>
70
71#include <media/v4l2-common.h>
72#include <media/v4l2-device.h>
73
Linus Torvalds0b8e74c2012-10-07 17:49:05 +090074#include <plat/cpu.h>
75
Sakari Ailus448de7e2011-02-12 18:05:06 -030076#include "isp.h"
77#include "ispreg.h"
78#include "ispccdc.h"
79#include "isppreview.h"
80#include "ispresizer.h"
81#include "ispcsi2.h"
82#include "ispccp2.h"
83#include "isph3a.h"
84#include "isphist.h"
85
86static unsigned int autoidle;
87module_param(autoidle, int, 0444);
88MODULE_PARM_DESC(autoidle, "Enable OMAP3ISP AUTOIDLE support");
89
90static void isp_save_ctx(struct isp_device *isp);
91
92static void isp_restore_ctx(struct isp_device *isp);
93
94static const struct isp_res_mapping isp_res_maps[] = {
95 {
96 .isp_rev = ISP_REVISION_2_0,
97 .map = 1 << OMAP3_ISP_IOMEM_MAIN |
98 1 << OMAP3_ISP_IOMEM_CCP2 |
99 1 << OMAP3_ISP_IOMEM_CCDC |
100 1 << OMAP3_ISP_IOMEM_HIST |
101 1 << OMAP3_ISP_IOMEM_H3A |
102 1 << OMAP3_ISP_IOMEM_PREV |
103 1 << OMAP3_ISP_IOMEM_RESZ |
104 1 << OMAP3_ISP_IOMEM_SBL |
105 1 << OMAP3_ISP_IOMEM_CSI2A_REGS1 |
Sakari Ailusc19d19e2012-10-14 07:31:48 -0300106 1 << OMAP3_ISP_IOMEM_CSIPHY2 |
107 1 << OMAP3_ISP_IOMEM_343X_CONTROL_CSIRXFE,
Sakari Ailus448de7e2011-02-12 18:05:06 -0300108 },
109 {
110 .isp_rev = ISP_REVISION_15_0,
111 .map = 1 << OMAP3_ISP_IOMEM_MAIN |
112 1 << OMAP3_ISP_IOMEM_CCP2 |
113 1 << OMAP3_ISP_IOMEM_CCDC |
114 1 << OMAP3_ISP_IOMEM_HIST |
115 1 << OMAP3_ISP_IOMEM_H3A |
116 1 << OMAP3_ISP_IOMEM_PREV |
117 1 << OMAP3_ISP_IOMEM_RESZ |
118 1 << OMAP3_ISP_IOMEM_SBL |
119 1 << OMAP3_ISP_IOMEM_CSI2A_REGS1 |
120 1 << OMAP3_ISP_IOMEM_CSIPHY2 |
121 1 << OMAP3_ISP_IOMEM_CSI2A_REGS2 |
122 1 << OMAP3_ISP_IOMEM_CSI2C_REGS1 |
123 1 << OMAP3_ISP_IOMEM_CSIPHY1 |
Sakari Ailusc19d19e2012-10-14 07:31:48 -0300124 1 << OMAP3_ISP_IOMEM_CSI2C_REGS2 |
125 1 << OMAP3_ISP_IOMEM_3630_CONTROL_CAMERA_PHY_CTRL,
Sakari Ailus448de7e2011-02-12 18:05:06 -0300126 },
127};
128
129/* Structure for saving/restoring ISP module registers */
130static struct isp_reg isp_reg_list[] = {
131 {OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG, 0},
132 {OMAP3_ISP_IOMEM_MAIN, ISP_CTRL, 0},
133 {OMAP3_ISP_IOMEM_MAIN, ISP_TCTRL_CTRL, 0},
134 {0, ISP_TOK_TERM, 0}
135};
136
137/*
138 * omap3isp_flush - Post pending L3 bus writes by doing a register readback
139 * @isp: OMAP3 ISP device
140 *
141 * In order to force posting of pending writes, we need to write and
142 * readback the same register, in this case the revision register.
143 *
144 * See this link for reference:
145 * http://www.mail-archive.com/linux-omap@vger.kernel.org/msg08149.html
146 */
147void omap3isp_flush(struct isp_device *isp)
148{
149 isp_reg_writel(isp, 0, OMAP3_ISP_IOMEM_MAIN, ISP_REVISION);
150 isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_REVISION);
151}
152
153/*
154 * isp_enable_interrupts - Enable ISP interrupts.
155 * @isp: OMAP3 ISP device
156 */
157static void isp_enable_interrupts(struct isp_device *isp)
158{
159 static const u32 irq = IRQ0ENABLE_CSIA_IRQ
160 | IRQ0ENABLE_CSIB_IRQ
161 | IRQ0ENABLE_CCDC_LSC_PREF_ERR_IRQ
162 | IRQ0ENABLE_CCDC_LSC_DONE_IRQ
163 | IRQ0ENABLE_CCDC_VD0_IRQ
164 | IRQ0ENABLE_CCDC_VD1_IRQ
165 | IRQ0ENABLE_HS_VS_IRQ
166 | IRQ0ENABLE_HIST_DONE_IRQ
167 | IRQ0ENABLE_H3A_AWB_DONE_IRQ
168 | IRQ0ENABLE_H3A_AF_DONE_IRQ
169 | IRQ0ENABLE_PRV_DONE_IRQ
170 | IRQ0ENABLE_RSZ_DONE_IRQ;
171
172 isp_reg_writel(isp, irq, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
173 isp_reg_writel(isp, irq, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0ENABLE);
174}
175
176/*
177 * isp_disable_interrupts - Disable ISP interrupts.
178 * @isp: OMAP3 ISP device
179 */
180static void isp_disable_interrupts(struct isp_device *isp)
181{
182 isp_reg_writel(isp, 0, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0ENABLE);
183}
184
185/**
186 * isp_set_xclk - Configures the specified cam_xclk to the desired frequency.
187 * @isp: OMAP3 ISP device
188 * @xclk: Desired frequency of the clock in Hz. 0 = stable low, 1 is stable high
189 * @xclksel: XCLK to configure (0 = A, 1 = B).
190 *
191 * Configures the specified MCLK divisor in the ISP timing control register
192 * (TCTRL_CTRL) to generate the desired xclk clock value.
193 *
194 * Divisor = cam_mclk_hz / xclk
195 *
196 * Returns the final frequency that is actually being generated
197 **/
198static u32 isp_set_xclk(struct isp_device *isp, u32 xclk, u8 xclksel)
199{
200 u32 divisor;
201 u32 currentxclk;
202 unsigned long mclk_hz;
203
204 if (!omap3isp_get(isp))
205 return 0;
206
207 mclk_hz = clk_get_rate(isp->clock[ISP_CLK_CAM_MCLK]);
208
209 if (xclk >= mclk_hz) {
210 divisor = ISPTCTRL_CTRL_DIV_BYPASS;
211 currentxclk = mclk_hz;
212 } else if (xclk >= 2) {
213 divisor = mclk_hz / xclk;
214 if (divisor >= ISPTCTRL_CTRL_DIV_BYPASS)
215 divisor = ISPTCTRL_CTRL_DIV_BYPASS - 1;
216 currentxclk = mclk_hz / divisor;
217 } else {
218 divisor = xclk;
219 currentxclk = 0;
220 }
221
222 switch (xclksel) {
Stanimir Varbanov7c2c8f42011-03-21 12:22:44 -0300223 case ISP_XCLK_A:
Sakari Ailus448de7e2011-02-12 18:05:06 -0300224 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_MAIN, ISP_TCTRL_CTRL,
225 ISPTCTRL_CTRL_DIVA_MASK,
226 divisor << ISPTCTRL_CTRL_DIVA_SHIFT);
227 dev_dbg(isp->dev, "isp_set_xclk(): cam_xclka set to %d Hz\n",
228 currentxclk);
229 break;
Stanimir Varbanov7c2c8f42011-03-21 12:22:44 -0300230 case ISP_XCLK_B:
Sakari Ailus448de7e2011-02-12 18:05:06 -0300231 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_MAIN, ISP_TCTRL_CTRL,
232 ISPTCTRL_CTRL_DIVB_MASK,
233 divisor << ISPTCTRL_CTRL_DIVB_SHIFT);
234 dev_dbg(isp->dev, "isp_set_xclk(): cam_xclkb set to %d Hz\n",
235 currentxclk);
236 break;
Stanimir Varbanov7c2c8f42011-03-21 12:22:44 -0300237 case ISP_XCLK_NONE:
Sakari Ailus448de7e2011-02-12 18:05:06 -0300238 default:
239 omap3isp_put(isp);
240 dev_dbg(isp->dev, "ISP_ERR: isp_set_xclk(): Invalid requested "
241 "xclk. Must be 0 (A) or 1 (B).\n");
242 return -EINVAL;
243 }
244
245 /* Do we go from stable whatever to clock? */
Stanimir Varbanov7c2c8f42011-03-21 12:22:44 -0300246 if (divisor >= 2 && isp->xclk_divisor[xclksel - 1] < 2)
Sakari Ailus448de7e2011-02-12 18:05:06 -0300247 omap3isp_get(isp);
248 /* Stopping the clock. */
Stanimir Varbanov7c2c8f42011-03-21 12:22:44 -0300249 else if (divisor < 2 && isp->xclk_divisor[xclksel - 1] >= 2)
Sakari Ailus448de7e2011-02-12 18:05:06 -0300250 omap3isp_put(isp);
251
Stanimir Varbanov7c2c8f42011-03-21 12:22:44 -0300252 isp->xclk_divisor[xclksel - 1] = divisor;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300253
254 omap3isp_put(isp);
255
256 return currentxclk;
257}
258
259/*
Laurent Pinchart96d62ae2012-05-25 09:33:00 -0300260 * isp_core_init - ISP core settings
Sakari Ailus448de7e2011-02-12 18:05:06 -0300261 * @isp: OMAP3 ISP device
262 * @idle: Consider idle state.
263 *
Laurent Pinchart96d62ae2012-05-25 09:33:00 -0300264 * Set the power settings for the ISP and SBL bus and cConfigure the HS/VS
265 * interrupt source.
266 *
267 * We need to configure the HS/VS interrupt source before interrupts get
268 * enabled, as the sensor might be free-running and the ISP default setting
269 * (HS edge) would put an unnecessary burden on the CPU.
Sakari Ailus448de7e2011-02-12 18:05:06 -0300270 */
Laurent Pinchart96d62ae2012-05-25 09:33:00 -0300271static void isp_core_init(struct isp_device *isp, int idle)
Sakari Ailus448de7e2011-02-12 18:05:06 -0300272{
273 isp_reg_writel(isp,
274 ((idle ? ISP_SYSCONFIG_MIDLEMODE_SMARTSTANDBY :
275 ISP_SYSCONFIG_MIDLEMODE_FORCESTANDBY) <<
276 ISP_SYSCONFIG_MIDLEMODE_SHIFT) |
277 ((isp->revision == ISP_REVISION_15_0) ?
278 ISP_SYSCONFIG_AUTOIDLE : 0),
279 OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG);
280
Laurent Pinchart96d62ae2012-05-25 09:33:00 -0300281 isp_reg_writel(isp,
282 (isp->autoidle ? ISPCTRL_SBL_AUTOIDLE : 0) |
283 ISPCTRL_SYNC_DETECT_VSRISE,
284 OMAP3_ISP_IOMEM_MAIN, ISP_CTRL);
Sakari Ailus448de7e2011-02-12 18:05:06 -0300285}
286
287/*
288 * Configure the bridge and lane shifter. Valid inputs are
289 *
290 * CCDC_INPUT_PARALLEL: Parallel interface
291 * CCDC_INPUT_CSI2A: CSI2a receiver
292 * CCDC_INPUT_CCP2B: CCP2b receiver
293 * CCDC_INPUT_CSI2C: CSI2c receiver
294 *
295 * The bridge and lane shifter are configured according to the selected input
296 * and the ISP platform data.
297 */
298void omap3isp_configure_bridge(struct isp_device *isp,
299 enum ccdc_input_entity input,
Michael Jonesc09af042011-03-29 05:19:09 -0300300 const struct isp_parallel_platform_data *pdata,
Laurent Pinchartc51364c2011-08-31 11:03:53 -0300301 unsigned int shift, unsigned int bridge)
Sakari Ailus448de7e2011-02-12 18:05:06 -0300302{
303 u32 ispctrl_val;
304
305 ispctrl_val = isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL);
306 ispctrl_val &= ~ISPCTRL_SHIFT_MASK;
307 ispctrl_val &= ~ISPCTRL_PAR_CLK_POL_INV;
308 ispctrl_val &= ~ISPCTRL_PAR_SER_CLK_SEL_MASK;
309 ispctrl_val &= ~ISPCTRL_PAR_BRIDGE_MASK;
Laurent Pinchartc51364c2011-08-31 11:03:53 -0300310 ispctrl_val |= bridge;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300311
312 switch (input) {
313 case CCDC_INPUT_PARALLEL:
314 ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_PARALLEL;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300315 ispctrl_val |= pdata->clk_pol << ISPCTRL_PAR_CLK_POL_SHIFT;
Michael Jonesc09af042011-03-29 05:19:09 -0300316 shift += pdata->data_lane_shift * 2;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300317 break;
318
319 case CCDC_INPUT_CSI2A:
320 ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_CSIA;
321 break;
322
323 case CCDC_INPUT_CCP2B:
324 ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_CSIB;
325 break;
326
327 case CCDC_INPUT_CSI2C:
328 ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_CSIC;
329 break;
330
331 default:
332 return;
333 }
334
Michael Jonesc09af042011-03-29 05:19:09 -0300335 ispctrl_val |= ((shift/2) << ISPCTRL_SHIFT_SHIFT) & ISPCTRL_SHIFT_MASK;
336
Sakari Ailus448de7e2011-02-12 18:05:06 -0300337 isp_reg_writel(isp, ispctrl_val, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL);
338}
339
Sakari Ailus448de7e2011-02-12 18:05:06 -0300340void omap3isp_hist_dma_done(struct isp_device *isp)
341{
342 if (omap3isp_ccdc_busy(&isp->isp_ccdc) ||
343 omap3isp_stat_pcr_busy(&isp->isp_hist)) {
344 /* Histogram cannot be enabled in this frame anymore */
345 atomic_set(&isp->isp_hist.buf_err, 1);
346 dev_dbg(isp->dev, "hist: Out of synchronization with "
347 "CCDC. Ignoring next buffer.\n");
348 }
349}
350
351static inline void isp_isr_dbg(struct isp_device *isp, u32 irqstatus)
352{
353 static const char *name[] = {
354 "CSIA_IRQ",
355 "res1",
356 "res2",
357 "CSIB_LCM_IRQ",
358 "CSIB_IRQ",
359 "res5",
360 "res6",
361 "res7",
362 "CCDC_VD0_IRQ",
363 "CCDC_VD1_IRQ",
364 "CCDC_VD2_IRQ",
365 "CCDC_ERR_IRQ",
366 "H3A_AF_DONE_IRQ",
367 "H3A_AWB_DONE_IRQ",
368 "res14",
369 "res15",
370 "HIST_DONE_IRQ",
371 "CCDC_LSC_DONE",
372 "CCDC_LSC_PREFETCH_COMPLETED",
373 "CCDC_LSC_PREFETCH_ERROR",
374 "PRV_DONE_IRQ",
375 "CBUFF_IRQ",
376 "res22",
377 "res23",
378 "RSZ_DONE_IRQ",
379 "OVF_IRQ",
380 "res26",
381 "res27",
382 "MMU_ERR_IRQ",
383 "OCP_ERR_IRQ",
384 "SEC_ERR_IRQ",
385 "HS_VS_IRQ",
386 };
387 int i;
388
Sanjeev Premi6c20c6352011-05-18 13:06:51 -0300389 dev_dbg(isp->dev, "ISP IRQ: ");
Sakari Ailus448de7e2011-02-12 18:05:06 -0300390
391 for (i = 0; i < ARRAY_SIZE(name); i++) {
392 if ((1 << i) & irqstatus)
393 printk(KERN_CONT "%s ", name[i]);
394 }
395 printk(KERN_CONT "\n");
396}
397
398static void isp_isr_sbl(struct isp_device *isp)
399{
400 struct device *dev = isp->dev;
Laurent Pinchart875e2e32011-12-07 08:34:50 -0300401 struct isp_pipeline *pipe;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300402 u32 sbl_pcr;
403
404 /*
405 * Handle shared buffer logic overflows for video buffers.
406 * ISPSBL_PCR_CCDCPRV_2_RSZ_OVF can be safely ignored.
407 */
408 sbl_pcr = isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_PCR);
409 isp_reg_writel(isp, sbl_pcr, OMAP3_ISP_IOMEM_SBL, ISPSBL_PCR);
410 sbl_pcr &= ~ISPSBL_PCR_CCDCPRV_2_RSZ_OVF;
411
412 if (sbl_pcr)
413 dev_dbg(dev, "SBL overflow (PCR = 0x%08x)\n", sbl_pcr);
414
Laurent Pinchart875e2e32011-12-07 08:34:50 -0300415 if (sbl_pcr & ISPSBL_PCR_CSIB_WBL_OVF) {
416 pipe = to_isp_pipeline(&isp->isp_ccp2.subdev.entity);
417 if (pipe != NULL)
418 pipe->error = true;
419 }
420
421 if (sbl_pcr & ISPSBL_PCR_CSIA_WBL_OVF) {
422 pipe = to_isp_pipeline(&isp->isp_csi2a.subdev.entity);
423 if (pipe != NULL)
424 pipe->error = true;
425 }
426
427 if (sbl_pcr & ISPSBL_PCR_CCDC_WBL_OVF) {
428 pipe = to_isp_pipeline(&isp->isp_ccdc.subdev.entity);
429 if (pipe != NULL)
430 pipe->error = true;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300431 }
432
433 if (sbl_pcr & ISPSBL_PCR_PRV_WBL_OVF) {
Laurent Pinchart875e2e32011-12-07 08:34:50 -0300434 pipe = to_isp_pipeline(&isp->isp_prev.subdev.entity);
435 if (pipe != NULL)
436 pipe->error = true;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300437 }
438
439 if (sbl_pcr & (ISPSBL_PCR_RSZ1_WBL_OVF
440 | ISPSBL_PCR_RSZ2_WBL_OVF
441 | ISPSBL_PCR_RSZ3_WBL_OVF
Laurent Pinchart875e2e32011-12-07 08:34:50 -0300442 | ISPSBL_PCR_RSZ4_WBL_OVF)) {
443 pipe = to_isp_pipeline(&isp->isp_res.subdev.entity);
444 if (pipe != NULL)
445 pipe->error = true;
446 }
Sakari Ailus448de7e2011-02-12 18:05:06 -0300447
448 if (sbl_pcr & ISPSBL_PCR_H3A_AF_WBL_OVF)
449 omap3isp_stat_sbl_overflow(&isp->isp_af);
450
451 if (sbl_pcr & ISPSBL_PCR_H3A_AEAWB_WBL_OVF)
452 omap3isp_stat_sbl_overflow(&isp->isp_aewb);
453}
454
455/*
456 * isp_isr - Interrupt Service Routine for Camera ISP module.
457 * @irq: Not used currently.
458 * @_isp: Pointer to the OMAP3 ISP device
459 *
460 * Handles the corresponding callback if plugged in.
461 *
462 * Returns IRQ_HANDLED when IRQ was correctly handled, or IRQ_NONE when the
463 * IRQ wasn't handled.
464 */
465static irqreturn_t isp_isr(int irq, void *_isp)
466{
467 static const u32 ccdc_events = IRQ0STATUS_CCDC_LSC_PREF_ERR_IRQ |
468 IRQ0STATUS_CCDC_LSC_DONE_IRQ |
469 IRQ0STATUS_CCDC_VD0_IRQ |
470 IRQ0STATUS_CCDC_VD1_IRQ |
471 IRQ0STATUS_HS_VS_IRQ;
472 struct isp_device *isp = _isp;
473 u32 irqstatus;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300474
475 irqstatus = isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
476 isp_reg_writel(isp, irqstatus, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
477
478 isp_isr_sbl(isp);
479
Laurent Pinchart875e2e32011-12-07 08:34:50 -0300480 if (irqstatus & IRQ0STATUS_CSIA_IRQ)
481 omap3isp_csi2_isr(&isp->isp_csi2a);
Sakari Ailus448de7e2011-02-12 18:05:06 -0300482
Laurent Pinchart875e2e32011-12-07 08:34:50 -0300483 if (irqstatus & IRQ0STATUS_CSIB_IRQ)
484 omap3isp_ccp2_isr(&isp->isp_ccp2);
Sakari Ailus448de7e2011-02-12 18:05:06 -0300485
486 if (irqstatus & IRQ0STATUS_CCDC_VD0_IRQ) {
487 if (isp->isp_ccdc.output & CCDC_OUTPUT_PREVIEW)
488 omap3isp_preview_isr_frame_sync(&isp->isp_prev);
489 if (isp->isp_ccdc.output & CCDC_OUTPUT_RESIZER)
490 omap3isp_resizer_isr_frame_sync(&isp->isp_res);
491 omap3isp_stat_isr_frame_sync(&isp->isp_aewb);
492 omap3isp_stat_isr_frame_sync(&isp->isp_af);
493 omap3isp_stat_isr_frame_sync(&isp->isp_hist);
494 }
495
496 if (irqstatus & ccdc_events)
497 omap3isp_ccdc_isr(&isp->isp_ccdc, irqstatus & ccdc_events);
498
499 if (irqstatus & IRQ0STATUS_PRV_DONE_IRQ) {
500 if (isp->isp_prev.output & PREVIEW_OUTPUT_RESIZER)
501 omap3isp_resizer_isr_frame_sync(&isp->isp_res);
502 omap3isp_preview_isr(&isp->isp_prev);
503 }
504
505 if (irqstatus & IRQ0STATUS_RSZ_DONE_IRQ)
506 omap3isp_resizer_isr(&isp->isp_res);
507
508 if (irqstatus & IRQ0STATUS_H3A_AWB_DONE_IRQ)
509 omap3isp_stat_isr(&isp->isp_aewb);
510
511 if (irqstatus & IRQ0STATUS_H3A_AF_DONE_IRQ)
512 omap3isp_stat_isr(&isp->isp_af);
513
514 if (irqstatus & IRQ0STATUS_HIST_DONE_IRQ)
515 omap3isp_stat_isr(&isp->isp_hist);
516
517 omap3isp_flush(isp);
518
519#if defined(DEBUG) && defined(ISP_ISR_DEBUG)
520 isp_isr_dbg(isp, irqstatus);
521#endif
522
523 return IRQ_HANDLED;
524}
525
526/* -----------------------------------------------------------------------------
527 * Pipeline power management
528 *
529 * Entities must be powered up when part of a pipeline that contains at least
530 * one open video device node.
531 *
532 * To achieve this use the entity use_count field to track the number of users.
533 * For entities corresponding to video device nodes the use_count field stores
534 * the users count of the node. For entities corresponding to subdevs the
535 * use_count field stores the total number of users of all video device nodes
536 * in the pipeline.
537 *
538 * The omap3isp_pipeline_pm_use() function must be called in the open() and
539 * close() handlers of video device nodes. It increments or decrements the use
540 * count of all subdev entities in the pipeline.
541 *
542 * To react to link management on powered pipelines, the link setup notification
543 * callback updates the use count of all entities in the source and sink sides
544 * of the link.
545 */
546
547/*
548 * isp_pipeline_pm_use_count - Count the number of users of a pipeline
549 * @entity: The entity
550 *
551 * Return the total number of users of all video device nodes in the pipeline.
552 */
553static int isp_pipeline_pm_use_count(struct media_entity *entity)
554{
555 struct media_entity_graph graph;
556 int use = 0;
557
558 media_entity_graph_walk_start(&graph, entity);
559
560 while ((entity = media_entity_graph_walk_next(&graph))) {
561 if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
562 use += entity->use_count;
563 }
564
565 return use;
566}
567
568/*
569 * isp_pipeline_pm_power_one - Apply power change to an entity
570 * @entity: The entity
571 * @change: Use count change
572 *
573 * Change the entity use count by @change. If the entity is a subdev update its
574 * power state by calling the core::s_power operation when the use count goes
575 * from 0 to != 0 or from != 0 to 0.
576 *
577 * Return 0 on success or a negative error code on failure.
578 */
579static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
580{
581 struct v4l2_subdev *subdev;
582 int ret;
583
584 subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
585 ? media_entity_to_v4l2_subdev(entity) : NULL;
586
587 if (entity->use_count == 0 && change > 0 && subdev != NULL) {
588 ret = v4l2_subdev_call(subdev, core, s_power, 1);
589 if (ret < 0 && ret != -ENOIOCTLCMD)
590 return ret;
591 }
592
593 entity->use_count += change;
594 WARN_ON(entity->use_count < 0);
595
596 if (entity->use_count == 0 && change < 0 && subdev != NULL)
597 v4l2_subdev_call(subdev, core, s_power, 0);
598
599 return 0;
600}
601
602/*
603 * isp_pipeline_pm_power - Apply power change to all entities in a pipeline
604 * @entity: The entity
605 * @change: Use count change
606 *
607 * Walk the pipeline to update the use count and the power state of all non-node
608 * entities.
609 *
610 * Return 0 on success or a negative error code on failure.
611 */
612static int isp_pipeline_pm_power(struct media_entity *entity, int change)
613{
614 struct media_entity_graph graph;
615 struct media_entity *first = entity;
616 int ret = 0;
617
618 if (!change)
619 return 0;
620
621 media_entity_graph_walk_start(&graph, entity);
622
623 while (!ret && (entity = media_entity_graph_walk_next(&graph)))
624 if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
625 ret = isp_pipeline_pm_power_one(entity, change);
626
627 if (!ret)
628 return 0;
629
630 media_entity_graph_walk_start(&graph, first);
631
632 while ((first = media_entity_graph_walk_next(&graph))
633 && first != entity)
634 if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
635 isp_pipeline_pm_power_one(first, -change);
636
637 return ret;
638}
639
640/*
641 * omap3isp_pipeline_pm_use - Update the use count of an entity
642 * @entity: The entity
643 * @use: Use (1) or stop using (0) the entity
644 *
645 * Update the use count of all entities in the pipeline and power entities on or
646 * off accordingly.
647 *
648 * Return 0 on success or a negative error code on failure. Powering entities
649 * off is assumed to never fail. No failure can occur when the use parameter is
650 * set to 0.
651 */
652int omap3isp_pipeline_pm_use(struct media_entity *entity, int use)
653{
654 int change = use ? 1 : -1;
655 int ret;
656
657 mutex_lock(&entity->parent->graph_mutex);
658
659 /* Apply use count to node. */
660 entity->use_count += change;
661 WARN_ON(entity->use_count < 0);
662
663 /* Apply power change to connected non-nodes. */
664 ret = isp_pipeline_pm_power(entity, change);
Laurent Pincharte2241532011-04-01 09:12:54 -0300665 if (ret < 0)
666 entity->use_count -= change;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300667
668 mutex_unlock(&entity->parent->graph_mutex);
669
670 return ret;
671}
672
673/*
674 * isp_pipeline_link_notify - Link management notification callback
675 * @source: Pad at the start of the link
676 * @sink: Pad at the end of the link
677 * @flags: New link flags that will be applied
678 *
679 * React to link management on powered pipelines by updating the use count of
680 * all entities in the source and sink sides of the link. Entities are powered
681 * on or off accordingly.
682 *
683 * Return 0 on success or a negative error code on failure. Powering entities
684 * off is assumed to never fail. This function will not fail for disconnection
685 * events.
686 */
687static int isp_pipeline_link_notify(struct media_pad *source,
688 struct media_pad *sink, u32 flags)
689{
690 int source_use = isp_pipeline_pm_use_count(source->entity);
691 int sink_use = isp_pipeline_pm_use_count(sink->entity);
692 int ret;
693
694 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
695 /* Powering off entities is assumed to never fail. */
696 isp_pipeline_pm_power(source->entity, -sink_use);
697 isp_pipeline_pm_power(sink->entity, -source_use);
698 return 0;
699 }
700
701 ret = isp_pipeline_pm_power(source->entity, sink_use);
702 if (ret < 0)
703 return ret;
704
705 ret = isp_pipeline_pm_power(sink->entity, source_use);
706 if (ret < 0)
707 isp_pipeline_pm_power(source->entity, -sink_use);
708
709 return ret;
710}
711
712/* -----------------------------------------------------------------------------
713 * Pipeline stream management
714 */
715
716/*
717 * isp_pipeline_enable - Enable streaming on a pipeline
718 * @pipe: ISP pipeline
719 * @mode: Stream mode (single shot or continuous)
720 *
721 * Walk the entities chain starting at the pipeline output video node and start
722 * all modules in the chain in the given mode.
723 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300724 * Return 0 if successful, or the return value of the failed video::s_stream
Sakari Ailus448de7e2011-02-12 18:05:06 -0300725 * operation otherwise.
726 */
727static int isp_pipeline_enable(struct isp_pipeline *pipe,
728 enum isp_pipeline_stream_state mode)
729{
730 struct isp_device *isp = pipe->output->isp;
731 struct media_entity *entity;
732 struct media_pad *pad;
733 struct v4l2_subdev *subdev;
734 unsigned long flags;
Laurent Pinchartc62e2a12011-08-13 13:09:11 -0300735 int ret;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300736
Laurent Pinchart1567bb72011-11-18 11:28:24 -0300737 /* If the preview engine crashed it might not respond to read/write
738 * operations on the L4 bus. This would result in a bus fault and a
739 * kernel oops. Refuse to start streaming in that case. This check must
740 * be performed before the loop below to avoid starting entities if the
741 * pipeline won't start anyway (those entities would then likely fail to
742 * stop, making the problem worse).
743 */
744 if ((pipe->entities & isp->crashed) &
745 (1U << isp->isp_prev.subdev.entity.id))
746 return -EIO;
747
Sakari Ailus448de7e2011-02-12 18:05:06 -0300748 spin_lock_irqsave(&pipe->lock, flags);
749 pipe->state &= ~(ISP_PIPELINE_IDLE_INPUT | ISP_PIPELINE_IDLE_OUTPUT);
750 spin_unlock_irqrestore(&pipe->lock, flags);
751
752 pipe->do_propagation = false;
753
754 entity = &pipe->output->video.entity;
755 while (1) {
756 pad = &entity->pads[0];
757 if (!(pad->flags & MEDIA_PAD_FL_SINK))
758 break;
759
760 pad = media_entity_remote_source(pad);
761 if (pad == NULL ||
762 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
763 break;
764
765 entity = pad->entity;
766 subdev = media_entity_to_v4l2_subdev(entity);
767
768 ret = v4l2_subdev_call(subdev, video, s_stream, mode);
769 if (ret < 0 && ret != -ENOIOCTLCMD)
Laurent Pinchartc62e2a12011-08-13 13:09:11 -0300770 return ret;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300771
772 if (subdev == &isp->isp_ccdc.subdev) {
773 v4l2_subdev_call(&isp->isp_aewb.subdev, video,
774 s_stream, mode);
775 v4l2_subdev_call(&isp->isp_af.subdev, video,
776 s_stream, mode);
777 v4l2_subdev_call(&isp->isp_hist.subdev, video,
778 s_stream, mode);
779 pipe->do_propagation = true;
780 }
781 }
782
Laurent Pinchartc62e2a12011-08-13 13:09:11 -0300783 return 0;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300784}
785
786static int isp_pipeline_wait_resizer(struct isp_device *isp)
787{
788 return omap3isp_resizer_busy(&isp->isp_res);
789}
790
791static int isp_pipeline_wait_preview(struct isp_device *isp)
792{
793 return omap3isp_preview_busy(&isp->isp_prev);
794}
795
796static int isp_pipeline_wait_ccdc(struct isp_device *isp)
797{
798 return omap3isp_stat_busy(&isp->isp_af)
799 || omap3isp_stat_busy(&isp->isp_aewb)
800 || omap3isp_stat_busy(&isp->isp_hist)
801 || omap3isp_ccdc_busy(&isp->isp_ccdc);
802}
803
804#define ISP_STOP_TIMEOUT msecs_to_jiffies(1000)
805
806static int isp_pipeline_wait(struct isp_device *isp,
807 int(*busy)(struct isp_device *isp))
808{
809 unsigned long timeout = jiffies + ISP_STOP_TIMEOUT;
810
811 while (!time_after(jiffies, timeout)) {
812 if (!busy(isp))
813 return 0;
814 }
815
816 return 1;
817}
818
819/*
820 * isp_pipeline_disable - Disable streaming on a pipeline
821 * @pipe: ISP pipeline
822 *
823 * Walk the entities chain starting at the pipeline output video node and stop
824 * all modules in the chain. Wait synchronously for the modules to be stopped if
825 * necessary.
826 *
827 * Return 0 if all modules have been properly stopped, or -ETIMEDOUT if a module
828 * can't be stopped (in which case a software reset of the ISP is probably
829 * necessary).
830 */
831static int isp_pipeline_disable(struct isp_pipeline *pipe)
832{
833 struct isp_device *isp = pipe->output->isp;
834 struct media_entity *entity;
835 struct media_pad *pad;
836 struct v4l2_subdev *subdev;
837 int failure = 0;
838 int ret;
839
840 /*
841 * We need to stop all the modules after CCDC first or they'll
842 * never stop since they may not get a full frame from CCDC.
843 */
844 entity = &pipe->output->video.entity;
845 while (1) {
846 pad = &entity->pads[0];
847 if (!(pad->flags & MEDIA_PAD_FL_SINK))
848 break;
849
850 pad = media_entity_remote_source(pad);
851 if (pad == NULL ||
852 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
853 break;
854
855 entity = pad->entity;
856 subdev = media_entity_to_v4l2_subdev(entity);
857
858 if (subdev == &isp->isp_ccdc.subdev) {
859 v4l2_subdev_call(&isp->isp_aewb.subdev,
860 video, s_stream, 0);
861 v4l2_subdev_call(&isp->isp_af.subdev,
862 video, s_stream, 0);
863 v4l2_subdev_call(&isp->isp_hist.subdev,
864 video, s_stream, 0);
865 }
866
867 v4l2_subdev_call(subdev, video, s_stream, 0);
868
869 if (subdev == &isp->isp_res.subdev)
870 ret = isp_pipeline_wait(isp, isp_pipeline_wait_resizer);
871 else if (subdev == &isp->isp_prev.subdev)
872 ret = isp_pipeline_wait(isp, isp_pipeline_wait_preview);
873 else if (subdev == &isp->isp_ccdc.subdev)
874 ret = isp_pipeline_wait(isp, isp_pipeline_wait_ccdc);
875 else
876 ret = 0;
877
878 if (ret) {
879 dev_info(isp->dev, "Unable to stop %s\n", subdev->name);
Laurent Pinchart1567bb72011-11-18 11:28:24 -0300880 /* If the entity failed to stopped, assume it has
881 * crashed. Mark it as such, the ISP will be reset when
882 * applications will release it.
883 */
884 isp->crashed |= 1U << subdev->entity.id;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300885 failure = -ETIMEDOUT;
886 }
887 }
888
889 return failure;
890}
891
892/*
893 * omap3isp_pipeline_set_stream - Enable/disable streaming on a pipeline
894 * @pipe: ISP pipeline
895 * @state: Stream state (stopped, single shot or continuous)
896 *
897 * Set the pipeline to the given stream state. Pipelines can be started in
898 * single-shot or continuous mode.
899 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300900 * Return 0 if successful, or the return value of the failed video::s_stream
Laurent Pinchart994d5372011-03-01 13:43:07 -0300901 * operation otherwise. The pipeline state is not updated when the operation
902 * fails, except when stopping the pipeline.
Sakari Ailus448de7e2011-02-12 18:05:06 -0300903 */
904int omap3isp_pipeline_set_stream(struct isp_pipeline *pipe,
905 enum isp_pipeline_stream_state state)
906{
907 int ret;
908
909 if (state == ISP_PIPELINE_STREAM_STOPPED)
910 ret = isp_pipeline_disable(pipe);
911 else
912 ret = isp_pipeline_enable(pipe, state);
Laurent Pinchart994d5372011-03-01 13:43:07 -0300913
914 if (ret == 0 || state == ISP_PIPELINE_STREAM_STOPPED)
915 pipe->stream_state = state;
Sakari Ailus448de7e2011-02-12 18:05:06 -0300916
917 return ret;
918}
919
920/*
921 * isp_pipeline_resume - Resume streaming on a pipeline
922 * @pipe: ISP pipeline
923 *
924 * Resume video output and input and re-enable pipeline.
925 */
926static void isp_pipeline_resume(struct isp_pipeline *pipe)
927{
928 int singleshot = pipe->stream_state == ISP_PIPELINE_STREAM_SINGLESHOT;
929
930 omap3isp_video_resume(pipe->output, !singleshot);
931 if (singleshot)
932 omap3isp_video_resume(pipe->input, 0);
933 isp_pipeline_enable(pipe, pipe->stream_state);
934}
935
936/*
937 * isp_pipeline_suspend - Suspend streaming on a pipeline
938 * @pipe: ISP pipeline
939 *
940 * Suspend pipeline.
941 */
942static void isp_pipeline_suspend(struct isp_pipeline *pipe)
943{
944 isp_pipeline_disable(pipe);
945}
946
947/*
948 * isp_pipeline_is_last - Verify if entity has an enabled link to the output
949 * video node
950 * @me: ISP module's media entity
951 *
952 * Returns 1 if the entity has an enabled link to the output video node or 0
953 * otherwise. It's true only while pipeline can have no more than one output
954 * node.
955 */
956static int isp_pipeline_is_last(struct media_entity *me)
957{
958 struct isp_pipeline *pipe;
959 struct media_pad *pad;
960
961 if (!me->pipe)
962 return 0;
963 pipe = to_isp_pipeline(me);
964 if (pipe->stream_state == ISP_PIPELINE_STREAM_STOPPED)
965 return 0;
966 pad = media_entity_remote_source(&pipe->output->pad);
967 return pad->entity == me;
968}
969
970/*
971 * isp_suspend_module_pipeline - Suspend pipeline to which belongs the module
972 * @me: ISP module's media entity
973 *
974 * Suspend the whole pipeline if module's entity has an enabled link to the
975 * output video node. It works only while pipeline can have no more than one
976 * output node.
977 */
978static void isp_suspend_module_pipeline(struct media_entity *me)
979{
980 if (isp_pipeline_is_last(me))
981 isp_pipeline_suspend(to_isp_pipeline(me));
982}
983
984/*
985 * isp_resume_module_pipeline - Resume pipeline to which belongs the module
986 * @me: ISP module's media entity
987 *
988 * Resume the whole pipeline if module's entity has an enabled link to the
989 * output video node. It works only while pipeline can have no more than one
990 * output node.
991 */
992static void isp_resume_module_pipeline(struct media_entity *me)
993{
994 if (isp_pipeline_is_last(me))
995 isp_pipeline_resume(to_isp_pipeline(me));
996}
997
998/*
999 * isp_suspend_modules - Suspend ISP submodules.
1000 * @isp: OMAP3 ISP device
1001 *
1002 * Returns 0 if suspend left in idle state all the submodules properly,
1003 * or returns 1 if a general Reset is required to suspend the submodules.
1004 */
1005static int isp_suspend_modules(struct isp_device *isp)
1006{
1007 unsigned long timeout;
1008
1009 omap3isp_stat_suspend(&isp->isp_aewb);
1010 omap3isp_stat_suspend(&isp->isp_af);
1011 omap3isp_stat_suspend(&isp->isp_hist);
1012 isp_suspend_module_pipeline(&isp->isp_res.subdev.entity);
1013 isp_suspend_module_pipeline(&isp->isp_prev.subdev.entity);
1014 isp_suspend_module_pipeline(&isp->isp_ccdc.subdev.entity);
1015 isp_suspend_module_pipeline(&isp->isp_csi2a.subdev.entity);
1016 isp_suspend_module_pipeline(&isp->isp_ccp2.subdev.entity);
1017
1018 timeout = jiffies + ISP_STOP_TIMEOUT;
1019 while (omap3isp_stat_busy(&isp->isp_af)
1020 || omap3isp_stat_busy(&isp->isp_aewb)
1021 || omap3isp_stat_busy(&isp->isp_hist)
1022 || omap3isp_preview_busy(&isp->isp_prev)
1023 || omap3isp_resizer_busy(&isp->isp_res)
1024 || omap3isp_ccdc_busy(&isp->isp_ccdc)) {
1025 if (time_after(jiffies, timeout)) {
1026 dev_info(isp->dev, "can't stop modules.\n");
1027 return 1;
1028 }
1029 msleep(1);
1030 }
1031
1032 return 0;
1033}
1034
1035/*
1036 * isp_resume_modules - Resume ISP submodules.
1037 * @isp: OMAP3 ISP device
1038 */
1039static void isp_resume_modules(struct isp_device *isp)
1040{
1041 omap3isp_stat_resume(&isp->isp_aewb);
1042 omap3isp_stat_resume(&isp->isp_af);
1043 omap3isp_stat_resume(&isp->isp_hist);
1044 isp_resume_module_pipeline(&isp->isp_res.subdev.entity);
1045 isp_resume_module_pipeline(&isp->isp_prev.subdev.entity);
1046 isp_resume_module_pipeline(&isp->isp_ccdc.subdev.entity);
1047 isp_resume_module_pipeline(&isp->isp_csi2a.subdev.entity);
1048 isp_resume_module_pipeline(&isp->isp_ccp2.subdev.entity);
1049}
1050
1051/*
1052 * isp_reset - Reset ISP with a timeout wait for idle.
1053 * @isp: OMAP3 ISP device
1054 */
1055static int isp_reset(struct isp_device *isp)
1056{
1057 unsigned long timeout = 0;
1058
1059 isp_reg_writel(isp,
1060 isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG)
1061 | ISP_SYSCONFIG_SOFTRESET,
1062 OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG);
1063 while (!(isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN,
1064 ISP_SYSSTATUS) & 0x1)) {
1065 if (timeout++ > 10000) {
1066 dev_alert(isp->dev, "cannot reset ISP\n");
1067 return -ETIMEDOUT;
1068 }
1069 udelay(1);
1070 }
1071
Laurent Pinchart1567bb72011-11-18 11:28:24 -03001072 isp->crashed = 0;
Sakari Ailus448de7e2011-02-12 18:05:06 -03001073 return 0;
1074}
1075
1076/*
1077 * isp_save_context - Saves the values of the ISP module registers.
1078 * @isp: OMAP3 ISP device
1079 * @reg_list: Structure containing pairs of register address and value to
1080 * modify on OMAP.
1081 */
1082static void
1083isp_save_context(struct isp_device *isp, struct isp_reg *reg_list)
1084{
1085 struct isp_reg *next = reg_list;
1086
1087 for (; next->reg != ISP_TOK_TERM; next++)
1088 next->val = isp_reg_readl(isp, next->mmio_range, next->reg);
1089}
1090
1091/*
1092 * isp_restore_context - Restores the values of the ISP module registers.
1093 * @isp: OMAP3 ISP device
1094 * @reg_list: Structure containing pairs of register address and value to
1095 * modify on OMAP.
1096 */
1097static void
1098isp_restore_context(struct isp_device *isp, struct isp_reg *reg_list)
1099{
1100 struct isp_reg *next = reg_list;
1101
1102 for (; next->reg != ISP_TOK_TERM; next++)
1103 isp_reg_writel(isp, next->val, next->mmio_range, next->reg);
1104}
1105
1106/*
1107 * isp_save_ctx - Saves ISP, CCDC, HIST, H3A, PREV, RESZ & MMU context.
1108 * @isp: OMAP3 ISP device
1109 *
1110 * Routine for saving the context of each module in the ISP.
1111 * CCDC, HIST, H3A, PREV, RESZ and MMU.
1112 */
1113static void isp_save_ctx(struct isp_device *isp)
1114{
1115 isp_save_context(isp, isp_reg_list);
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +02001116 omap_iommu_save_ctx(isp->dev);
Sakari Ailus448de7e2011-02-12 18:05:06 -03001117}
1118
1119/*
1120 * isp_restore_ctx - Restores ISP, CCDC, HIST, H3A, PREV, RESZ & MMU context.
1121 * @isp: OMAP3 ISP device
1122 *
1123 * Routine for restoring the context of each module in the ISP.
1124 * CCDC, HIST, H3A, PREV, RESZ and MMU.
1125 */
1126static void isp_restore_ctx(struct isp_device *isp)
1127{
1128 isp_restore_context(isp, isp_reg_list);
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +02001129 omap_iommu_restore_ctx(isp->dev);
Sakari Ailus448de7e2011-02-12 18:05:06 -03001130 omap3isp_ccdc_restore_context(isp);
1131 omap3isp_preview_restore_context(isp);
1132}
1133
1134/* -----------------------------------------------------------------------------
1135 * SBL resources management
1136 */
1137#define OMAP3_ISP_SBL_READ (OMAP3_ISP_SBL_CSI1_READ | \
1138 OMAP3_ISP_SBL_CCDC_LSC_READ | \
1139 OMAP3_ISP_SBL_PREVIEW_READ | \
1140 OMAP3_ISP_SBL_RESIZER_READ)
1141#define OMAP3_ISP_SBL_WRITE (OMAP3_ISP_SBL_CSI1_WRITE | \
1142 OMAP3_ISP_SBL_CSI2A_WRITE | \
1143 OMAP3_ISP_SBL_CSI2C_WRITE | \
1144 OMAP3_ISP_SBL_CCDC_WRITE | \
1145 OMAP3_ISP_SBL_PREVIEW_WRITE)
1146
1147void omap3isp_sbl_enable(struct isp_device *isp, enum isp_sbl_resource res)
1148{
1149 u32 sbl = 0;
1150
1151 isp->sbl_resources |= res;
1152
1153 if (isp->sbl_resources & OMAP3_ISP_SBL_CSI1_READ)
1154 sbl |= ISPCTRL_SBL_SHARED_RPORTA;
1155
1156 if (isp->sbl_resources & OMAP3_ISP_SBL_CCDC_LSC_READ)
1157 sbl |= ISPCTRL_SBL_SHARED_RPORTB;
1158
1159 if (isp->sbl_resources & OMAP3_ISP_SBL_CSI2C_WRITE)
1160 sbl |= ISPCTRL_SBL_SHARED_WPORTC;
1161
1162 if (isp->sbl_resources & OMAP3_ISP_SBL_RESIZER_WRITE)
1163 sbl |= ISPCTRL_SBL_WR0_RAM_EN;
1164
1165 if (isp->sbl_resources & OMAP3_ISP_SBL_WRITE)
1166 sbl |= ISPCTRL_SBL_WR1_RAM_EN;
1167
1168 if (isp->sbl_resources & OMAP3_ISP_SBL_READ)
1169 sbl |= ISPCTRL_SBL_RD_RAM_EN;
1170
1171 isp_reg_set(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL, sbl);
1172}
1173
1174void omap3isp_sbl_disable(struct isp_device *isp, enum isp_sbl_resource res)
1175{
1176 u32 sbl = 0;
1177
1178 isp->sbl_resources &= ~res;
1179
1180 if (!(isp->sbl_resources & OMAP3_ISP_SBL_CSI1_READ))
1181 sbl |= ISPCTRL_SBL_SHARED_RPORTA;
1182
1183 if (!(isp->sbl_resources & OMAP3_ISP_SBL_CCDC_LSC_READ))
1184 sbl |= ISPCTRL_SBL_SHARED_RPORTB;
1185
1186 if (!(isp->sbl_resources & OMAP3_ISP_SBL_CSI2C_WRITE))
1187 sbl |= ISPCTRL_SBL_SHARED_WPORTC;
1188
1189 if (!(isp->sbl_resources & OMAP3_ISP_SBL_RESIZER_WRITE))
1190 sbl |= ISPCTRL_SBL_WR0_RAM_EN;
1191
1192 if (!(isp->sbl_resources & OMAP3_ISP_SBL_WRITE))
1193 sbl |= ISPCTRL_SBL_WR1_RAM_EN;
1194
1195 if (!(isp->sbl_resources & OMAP3_ISP_SBL_READ))
1196 sbl |= ISPCTRL_SBL_RD_RAM_EN;
1197
1198 isp_reg_clr(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL, sbl);
1199}
1200
1201/*
1202 * isp_module_sync_idle - Helper to sync module with its idle state
1203 * @me: ISP submodule's media entity
1204 * @wait: ISP submodule's wait queue for streamoff/interrupt synchronization
1205 * @stopping: flag which tells module wants to stop
1206 *
1207 * This function checks if ISP submodule needs to wait for next interrupt. If
1208 * yes, makes the caller to sleep while waiting for such event.
1209 */
1210int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
1211 atomic_t *stopping)
1212{
1213 struct isp_pipeline *pipe = to_isp_pipeline(me);
1214
1215 if (pipe->stream_state == ISP_PIPELINE_STREAM_STOPPED ||
1216 (pipe->stream_state == ISP_PIPELINE_STREAM_SINGLESHOT &&
1217 !isp_pipeline_ready(pipe)))
1218 return 0;
1219
1220 /*
1221 * atomic_set() doesn't include memory barrier on ARM platform for SMP
1222 * scenario. We'll call it here to avoid race conditions.
1223 */
1224 atomic_set(stopping, 1);
1225 smp_mb();
1226
1227 /*
1228 * If module is the last one, it's writing to memory. In this case,
1229 * it's necessary to check if the module is already paused due to
1230 * DMA queue underrun or if it has to wait for next interrupt to be
1231 * idle.
1232 * If it isn't the last one, the function won't sleep but *stopping
1233 * will still be set to warn next submodule caller's interrupt the
1234 * module wants to be idle.
1235 */
1236 if (isp_pipeline_is_last(me)) {
1237 struct isp_video *video = pipe->output;
1238 unsigned long flags;
1239 spin_lock_irqsave(&video->queue->irqlock, flags);
1240 if (video->dmaqueue_flags & ISP_VIDEO_DMAQUEUE_UNDERRUN) {
1241 spin_unlock_irqrestore(&video->queue->irqlock, flags);
1242 atomic_set(stopping, 0);
1243 smp_mb();
1244 return 0;
1245 }
1246 spin_unlock_irqrestore(&video->queue->irqlock, flags);
1247 if (!wait_event_timeout(*wait, !atomic_read(stopping),
1248 msecs_to_jiffies(1000))) {
1249 atomic_set(stopping, 0);
1250 smp_mb();
1251 return -ETIMEDOUT;
1252 }
1253 }
1254
1255 return 0;
1256}
1257
1258/*
1259 * omap3isp_module_sync_is_stopped - Helper to verify if module was stopping
1260 * @wait: ISP submodule's wait queue for streamoff/interrupt synchronization
1261 * @stopping: flag which tells module wants to stop
1262 *
1263 * This function checks if ISP submodule was stopping. In case of yes, it
1264 * notices the caller by setting stopping to 0 and waking up the wait queue.
1265 * Returns 1 if it was stopping or 0 otherwise.
1266 */
1267int omap3isp_module_sync_is_stopping(wait_queue_head_t *wait,
1268 atomic_t *stopping)
1269{
1270 if (atomic_cmpxchg(stopping, 1, 0)) {
1271 wake_up(wait);
1272 return 1;
1273 }
1274
1275 return 0;
1276}
1277
1278/* --------------------------------------------------------------------------
1279 * Clock management
1280 */
1281
1282#define ISPCTRL_CLKS_MASK (ISPCTRL_H3A_CLK_EN | \
1283 ISPCTRL_HIST_CLK_EN | \
1284 ISPCTRL_RSZ_CLK_EN | \
1285 (ISPCTRL_CCDC_CLK_EN | ISPCTRL_CCDC_RAM_EN) | \
1286 (ISPCTRL_PREV_CLK_EN | ISPCTRL_PREV_RAM_EN))
1287
1288static void __isp_subclk_update(struct isp_device *isp)
1289{
1290 u32 clk = 0;
1291
Laurent Pinchartbe9a1b92012-05-25 08:35:10 -03001292 /* AEWB and AF share the same clock. */
1293 if (isp->subclk_resources &
1294 (OMAP3_ISP_SUBCLK_AEWB | OMAP3_ISP_SUBCLK_AF))
Sakari Ailus448de7e2011-02-12 18:05:06 -03001295 clk |= ISPCTRL_H3A_CLK_EN;
1296
1297 if (isp->subclk_resources & OMAP3_ISP_SUBCLK_HIST)
1298 clk |= ISPCTRL_HIST_CLK_EN;
1299
1300 if (isp->subclk_resources & OMAP3_ISP_SUBCLK_RESIZER)
1301 clk |= ISPCTRL_RSZ_CLK_EN;
1302
1303 /* NOTE: For CCDC & Preview submodules, we need to affect internal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001304 * RAM as well.
Sakari Ailus448de7e2011-02-12 18:05:06 -03001305 */
1306 if (isp->subclk_resources & OMAP3_ISP_SUBCLK_CCDC)
1307 clk |= ISPCTRL_CCDC_CLK_EN | ISPCTRL_CCDC_RAM_EN;
1308
1309 if (isp->subclk_resources & OMAP3_ISP_SUBCLK_PREVIEW)
1310 clk |= ISPCTRL_PREV_CLK_EN | ISPCTRL_PREV_RAM_EN;
1311
1312 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL,
1313 ISPCTRL_CLKS_MASK, clk);
1314}
1315
1316void omap3isp_subclk_enable(struct isp_device *isp,
1317 enum isp_subclk_resource res)
1318{
1319 isp->subclk_resources |= res;
1320
1321 __isp_subclk_update(isp);
1322}
1323
1324void omap3isp_subclk_disable(struct isp_device *isp,
1325 enum isp_subclk_resource res)
1326{
1327 isp->subclk_resources &= ~res;
1328
1329 __isp_subclk_update(isp);
1330}
1331
1332/*
1333 * isp_enable_clocks - Enable ISP clocks
1334 * @isp: OMAP3 ISP device
1335 *
Laurent Pinchartb057c3c2012-10-25 06:29:24 -03001336 * Return 0 if successful, or clk_prepare_enable return value if any of them
1337 * fails.
Sakari Ailus448de7e2011-02-12 18:05:06 -03001338 */
1339static int isp_enable_clocks(struct isp_device *isp)
1340{
1341 int r;
1342 unsigned long rate;
1343 int divisor;
1344
1345 /*
1346 * cam_mclk clock chain:
1347 * dpll4 -> dpll4_m5 -> dpll4_m5x2 -> cam_mclk
1348 *
1349 * In OMAP3630 dpll4_m5x2 != 2 x dpll4_m5 but both are
1350 * set to the same value. Hence the rate set for dpll4_m5
1351 * has to be twice of what is set on OMAP3430 to get
1352 * the required value for cam_mclk
1353 */
Laurent Pinchartd8658bc2012-09-27 10:38:18 -03001354 divisor = isp->revision == ISP_REVISION_15_0 ? 1 : 2;
Sakari Ailus448de7e2011-02-12 18:05:06 -03001355
Laurent Pinchartb057c3c2012-10-25 06:29:24 -03001356 r = clk_prepare_enable(isp->clock[ISP_CLK_CAM_ICK]);
Sakari Ailus448de7e2011-02-12 18:05:06 -03001357 if (r) {
Laurent Pinchartb057c3c2012-10-25 06:29:24 -03001358 dev_err(isp->dev, "failed to enable cam_ick clock\n");
Sakari Ailus448de7e2011-02-12 18:05:06 -03001359 goto out_clk_enable_ick;
1360 }
1361 r = clk_set_rate(isp->clock[ISP_CLK_DPLL4_M5_CK],
1362 CM_CAM_MCLK_HZ/divisor);
1363 if (r) {
1364 dev_err(isp->dev, "clk_set_rate for dpll4_m5_ck failed\n");
1365 goto out_clk_enable_mclk;
1366 }
Laurent Pinchartb057c3c2012-10-25 06:29:24 -03001367 r = clk_prepare_enable(isp->clock[ISP_CLK_CAM_MCLK]);
Sakari Ailus448de7e2011-02-12 18:05:06 -03001368 if (r) {
Laurent Pinchartb057c3c2012-10-25 06:29:24 -03001369 dev_err(isp->dev, "failed to enable cam_mclk clock\n");
Sakari Ailus448de7e2011-02-12 18:05:06 -03001370 goto out_clk_enable_mclk;
1371 }
1372 rate = clk_get_rate(isp->clock[ISP_CLK_CAM_MCLK]);
1373 if (rate != CM_CAM_MCLK_HZ)
1374 dev_warn(isp->dev, "unexpected cam_mclk rate:\n"
1375 " expected : %d\n"
1376 " actual : %ld\n", CM_CAM_MCLK_HZ, rate);
Laurent Pinchartb057c3c2012-10-25 06:29:24 -03001377 r = clk_prepare_enable(isp->clock[ISP_CLK_CSI2_FCK]);
Sakari Ailus448de7e2011-02-12 18:05:06 -03001378 if (r) {
Laurent Pinchartb057c3c2012-10-25 06:29:24 -03001379 dev_err(isp->dev, "failed to enable csi2_fck clock\n");
Sakari Ailus448de7e2011-02-12 18:05:06 -03001380 goto out_clk_enable_csi2_fclk;
1381 }
1382 return 0;
1383
1384out_clk_enable_csi2_fclk:
Laurent Pinchartb057c3c2012-10-25 06:29:24 -03001385 clk_disable_unprepare(isp->clock[ISP_CLK_CAM_MCLK]);
Sakari Ailus448de7e2011-02-12 18:05:06 -03001386out_clk_enable_mclk:
Laurent Pinchartb057c3c2012-10-25 06:29:24 -03001387 clk_disable_unprepare(isp->clock[ISP_CLK_CAM_ICK]);
Sakari Ailus448de7e2011-02-12 18:05:06 -03001388out_clk_enable_ick:
1389 return r;
1390}
1391
1392/*
1393 * isp_disable_clocks - Disable ISP clocks
1394 * @isp: OMAP3 ISP device
1395 */
1396static void isp_disable_clocks(struct isp_device *isp)
1397{
Laurent Pinchartb057c3c2012-10-25 06:29:24 -03001398 clk_disable_unprepare(isp->clock[ISP_CLK_CAM_ICK]);
1399 clk_disable_unprepare(isp->clock[ISP_CLK_CAM_MCLK]);
1400 clk_disable_unprepare(isp->clock[ISP_CLK_CSI2_FCK]);
Sakari Ailus448de7e2011-02-12 18:05:06 -03001401}
1402
1403static const char *isp_clocks[] = {
1404 "cam_ick",
1405 "cam_mclk",
1406 "dpll4_m5_ck",
1407 "csi2_96m_fck",
1408 "l3_ick",
1409};
1410
1411static void isp_put_clocks(struct isp_device *isp)
1412{
1413 unsigned int i;
1414
1415 for (i = 0; i < ARRAY_SIZE(isp_clocks); ++i) {
1416 if (isp->clock[i]) {
1417 clk_put(isp->clock[i]);
1418 isp->clock[i] = NULL;
1419 }
1420 }
1421}
1422
1423static int isp_get_clocks(struct isp_device *isp)
1424{
1425 struct clk *clk;
1426 unsigned int i;
1427
1428 for (i = 0; i < ARRAY_SIZE(isp_clocks); ++i) {
1429 clk = clk_get(isp->dev, isp_clocks[i]);
1430 if (IS_ERR(clk)) {
1431 dev_err(isp->dev, "clk_get %s failed\n", isp_clocks[i]);
1432 isp_put_clocks(isp);
1433 return PTR_ERR(clk);
1434 }
1435
1436 isp->clock[i] = clk;
1437 }
1438
1439 return 0;
1440}
1441
1442/*
1443 * omap3isp_get - Acquire the ISP resource.
1444 *
1445 * Initializes the clocks for the first acquire.
1446 *
1447 * Increment the reference count on the ISP. If the first reference is taken,
1448 * enable clocks and power-up all submodules.
1449 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001450 * Return a pointer to the ISP device structure, or NULL if an error occurred.
Sakari Ailus448de7e2011-02-12 18:05:06 -03001451 */
Laurent Pinchart96d62ae2012-05-25 09:33:00 -03001452static struct isp_device *__omap3isp_get(struct isp_device *isp, bool irq)
Sakari Ailus448de7e2011-02-12 18:05:06 -03001453{
1454 struct isp_device *__isp = isp;
1455
1456 if (isp == NULL)
1457 return NULL;
1458
1459 mutex_lock(&isp->isp_mutex);
1460 if (isp->ref_count > 0)
1461 goto out;
1462
1463 if (isp_enable_clocks(isp) < 0) {
1464 __isp = NULL;
1465 goto out;
1466 }
1467
1468 /* We don't want to restore context before saving it! */
1469 if (isp->has_context)
1470 isp_restore_ctx(isp);
Sakari Ailus448de7e2011-02-12 18:05:06 -03001471
Laurent Pinchart96d62ae2012-05-25 09:33:00 -03001472 if (irq)
1473 isp_enable_interrupts(isp);
Sakari Ailus448de7e2011-02-12 18:05:06 -03001474
1475out:
1476 if (__isp != NULL)
1477 isp->ref_count++;
1478 mutex_unlock(&isp->isp_mutex);
1479
1480 return __isp;
1481}
1482
Laurent Pinchart96d62ae2012-05-25 09:33:00 -03001483struct isp_device *omap3isp_get(struct isp_device *isp)
1484{
1485 return __omap3isp_get(isp, true);
1486}
1487
Sakari Ailus448de7e2011-02-12 18:05:06 -03001488/*
1489 * omap3isp_put - Release the ISP
1490 *
1491 * Decrement the reference count on the ISP. If the last reference is released,
1492 * power-down all submodules, disable clocks and free temporary buffers.
1493 */
1494void omap3isp_put(struct isp_device *isp)
1495{
1496 if (isp == NULL)
1497 return;
1498
1499 mutex_lock(&isp->isp_mutex);
1500 BUG_ON(isp->ref_count == 0);
1501 if (--isp->ref_count == 0) {
1502 isp_disable_interrupts(isp);
Laurent Pinchart96d62ae2012-05-25 09:33:00 -03001503 if (isp->domain) {
Sakari Ailusa32f2f92012-01-27 07:18:51 -03001504 isp_save_ctx(isp);
Laurent Pinchart96d62ae2012-05-25 09:33:00 -03001505 isp->has_context = 1;
1506 }
Laurent Pinchart1567bb72011-11-18 11:28:24 -03001507 /* Reset the ISP if an entity has failed to stop. This is the
1508 * only way to recover from such conditions.
1509 */
1510 if (isp->crashed)
Laurent Pinchart994d5372011-03-01 13:43:07 -03001511 isp_reset(isp);
Sakari Ailus448de7e2011-02-12 18:05:06 -03001512 isp_disable_clocks(isp);
1513 }
1514 mutex_unlock(&isp->isp_mutex);
1515}
1516
1517/* --------------------------------------------------------------------------
1518 * Platform device driver
1519 */
1520
1521/*
1522 * omap3isp_print_status - Prints the values of the ISP Control Module registers
1523 * @isp: OMAP3 ISP device
1524 */
1525#define ISP_PRINT_REGISTER(isp, name)\
1526 dev_dbg(isp->dev, "###ISP " #name "=0x%08x\n", \
1527 isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_##name))
1528#define SBL_PRINT_REGISTER(isp, name)\
1529 dev_dbg(isp->dev, "###SBL " #name "=0x%08x\n", \
1530 isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_##name))
1531
1532void omap3isp_print_status(struct isp_device *isp)
1533{
1534 dev_dbg(isp->dev, "-------------ISP Register dump--------------\n");
1535
1536 ISP_PRINT_REGISTER(isp, SYSCONFIG);
1537 ISP_PRINT_REGISTER(isp, SYSSTATUS);
1538 ISP_PRINT_REGISTER(isp, IRQ0ENABLE);
1539 ISP_PRINT_REGISTER(isp, IRQ0STATUS);
1540 ISP_PRINT_REGISTER(isp, TCTRL_GRESET_LENGTH);
1541 ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_REPLAY);
1542 ISP_PRINT_REGISTER(isp, CTRL);
1543 ISP_PRINT_REGISTER(isp, TCTRL_CTRL);
1544 ISP_PRINT_REGISTER(isp, TCTRL_FRAME);
1545 ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_DELAY);
1546 ISP_PRINT_REGISTER(isp, TCTRL_STRB_DELAY);
1547 ISP_PRINT_REGISTER(isp, TCTRL_SHUT_DELAY);
1548 ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_LENGTH);
1549 ISP_PRINT_REGISTER(isp, TCTRL_STRB_LENGTH);
1550 ISP_PRINT_REGISTER(isp, TCTRL_SHUT_LENGTH);
1551
1552 SBL_PRINT_REGISTER(isp, PCR);
1553 SBL_PRINT_REGISTER(isp, SDR_REQ_EXP);
1554
1555 dev_dbg(isp->dev, "--------------------------------------------\n");
1556}
1557
1558#ifdef CONFIG_PM
1559
1560/*
1561 * Power management support.
1562 *
1563 * As the ISP can't properly handle an input video stream interruption on a non
1564 * frame boundary, the ISP pipelines need to be stopped before sensors get
1565 * suspended. However, as suspending the sensors can require a running clock,
1566 * which can be provided by the ISP, the ISP can't be completely suspended
1567 * before the sensor.
1568 *
1569 * To solve this problem power management support is split into prepare/complete
1570 * and suspend/resume operations. The pipelines are stopped in prepare() and the
1571 * ISP clocks get disabled in suspend(). Similarly, the clocks are reenabled in
1572 * resume(), and the the pipelines are restarted in complete().
1573 *
1574 * TODO: PM dependencies between the ISP and sensors are not modeled explicitly
1575 * yet.
1576 */
1577static int isp_pm_prepare(struct device *dev)
1578{
1579 struct isp_device *isp = dev_get_drvdata(dev);
1580 int reset;
1581
1582 WARN_ON(mutex_is_locked(&isp->isp_mutex));
1583
1584 if (isp->ref_count == 0)
1585 return 0;
1586
1587 reset = isp_suspend_modules(isp);
1588 isp_disable_interrupts(isp);
1589 isp_save_ctx(isp);
1590 if (reset)
1591 isp_reset(isp);
1592
1593 return 0;
1594}
1595
1596static int isp_pm_suspend(struct device *dev)
1597{
1598 struct isp_device *isp = dev_get_drvdata(dev);
1599
1600 WARN_ON(mutex_is_locked(&isp->isp_mutex));
1601
1602 if (isp->ref_count)
1603 isp_disable_clocks(isp);
1604
1605 return 0;
1606}
1607
1608static int isp_pm_resume(struct device *dev)
1609{
1610 struct isp_device *isp = dev_get_drvdata(dev);
1611
1612 if (isp->ref_count == 0)
1613 return 0;
1614
1615 return isp_enable_clocks(isp);
1616}
1617
1618static void isp_pm_complete(struct device *dev)
1619{
1620 struct isp_device *isp = dev_get_drvdata(dev);
1621
1622 if (isp->ref_count == 0)
1623 return;
1624
1625 isp_restore_ctx(isp);
1626 isp_enable_interrupts(isp);
1627 isp_resume_modules(isp);
1628}
1629
1630#else
1631
1632#define isp_pm_prepare NULL
1633#define isp_pm_suspend NULL
1634#define isp_pm_resume NULL
1635#define isp_pm_complete NULL
1636
1637#endif /* CONFIG_PM */
1638
1639static void isp_unregister_entities(struct isp_device *isp)
1640{
1641 omap3isp_csi2_unregister_entities(&isp->isp_csi2a);
1642 omap3isp_ccp2_unregister_entities(&isp->isp_ccp2);
1643 omap3isp_ccdc_unregister_entities(&isp->isp_ccdc);
1644 omap3isp_preview_unregister_entities(&isp->isp_prev);
1645 omap3isp_resizer_unregister_entities(&isp->isp_res);
1646 omap3isp_stat_unregister_entities(&isp->isp_aewb);
1647 omap3isp_stat_unregister_entities(&isp->isp_af);
1648 omap3isp_stat_unregister_entities(&isp->isp_hist);
1649
1650 v4l2_device_unregister(&isp->v4l2_dev);
1651 media_device_unregister(&isp->media_dev);
1652}
1653
1654/*
1655 * isp_register_subdev_group - Register a group of subdevices
1656 * @isp: OMAP3 ISP device
1657 * @board_info: I2C subdevs board information array
1658 *
1659 * Register all I2C subdevices in the board_info array. The array must be
1660 * terminated by a NULL entry, and the first entry must be the sensor.
1661 *
1662 * Return a pointer to the sensor media entity if it has been successfully
1663 * registered, or NULL otherwise.
1664 */
1665static struct v4l2_subdev *
1666isp_register_subdev_group(struct isp_device *isp,
1667 struct isp_subdev_i2c_board_info *board_info)
1668{
1669 struct v4l2_subdev *sensor = NULL;
1670 unsigned int first;
1671
1672 if (board_info->board_info == NULL)
1673 return NULL;
1674
1675 for (first = 1; board_info->board_info; ++board_info, first = 0) {
1676 struct v4l2_subdev *subdev;
1677 struct i2c_adapter *adapter;
1678
1679 adapter = i2c_get_adapter(board_info->i2c_adapter_id);
1680 if (adapter == NULL) {
Laurent Pinchart4feca392012-10-22 08:28:51 -03001681 dev_err(isp->dev, "%s: Unable to get I2C adapter %d for "
Sakari Ailus448de7e2011-02-12 18:05:06 -03001682 "device %s\n", __func__,
1683 board_info->i2c_adapter_id,
1684 board_info->board_info->type);
1685 continue;
1686 }
1687
1688 subdev = v4l2_i2c_new_subdev_board(&isp->v4l2_dev, adapter,
1689 board_info->board_info, NULL);
1690 if (subdev == NULL) {
Laurent Pinchart4feca392012-10-22 08:28:51 -03001691 dev_err(isp->dev, "%s: Unable to register subdev %s\n",
Sakari Ailus448de7e2011-02-12 18:05:06 -03001692 __func__, board_info->board_info->type);
1693 continue;
1694 }
1695
1696 if (first)
1697 sensor = subdev;
1698 }
1699
1700 return sensor;
1701}
1702
1703static int isp_register_entities(struct isp_device *isp)
1704{
1705 struct isp_platform_data *pdata = isp->pdata;
1706 struct isp_v4l2_subdevs_group *subdevs;
1707 int ret;
1708
1709 isp->media_dev.dev = isp->dev;
1710 strlcpy(isp->media_dev.model, "TI OMAP3 ISP",
1711 sizeof(isp->media_dev.model));
Laurent Pinchart083eb072011-10-11 06:34:40 -03001712 isp->media_dev.hw_revision = isp->revision;
Sakari Ailus448de7e2011-02-12 18:05:06 -03001713 isp->media_dev.link_notify = isp_pipeline_link_notify;
1714 ret = media_device_register(&isp->media_dev);
1715 if (ret < 0) {
Laurent Pinchart4feca392012-10-22 08:28:51 -03001716 dev_err(isp->dev, "%s: Media device registration failed (%d)\n",
Sakari Ailus448de7e2011-02-12 18:05:06 -03001717 __func__, ret);
1718 return ret;
1719 }
1720
1721 isp->v4l2_dev.mdev = &isp->media_dev;
1722 ret = v4l2_device_register(isp->dev, &isp->v4l2_dev);
1723 if (ret < 0) {
Laurent Pinchart4feca392012-10-22 08:28:51 -03001724 dev_err(isp->dev, "%s: V4L2 device registration failed (%d)\n",
Sakari Ailus448de7e2011-02-12 18:05:06 -03001725 __func__, ret);
1726 goto done;
1727 }
1728
1729 /* Register internal entities */
1730 ret = omap3isp_ccp2_register_entities(&isp->isp_ccp2, &isp->v4l2_dev);
1731 if (ret < 0)
1732 goto done;
1733
1734 ret = omap3isp_csi2_register_entities(&isp->isp_csi2a, &isp->v4l2_dev);
1735 if (ret < 0)
1736 goto done;
1737
1738 ret = omap3isp_ccdc_register_entities(&isp->isp_ccdc, &isp->v4l2_dev);
1739 if (ret < 0)
1740 goto done;
1741
1742 ret = omap3isp_preview_register_entities(&isp->isp_prev,
1743 &isp->v4l2_dev);
1744 if (ret < 0)
1745 goto done;
1746
1747 ret = omap3isp_resizer_register_entities(&isp->isp_res, &isp->v4l2_dev);
1748 if (ret < 0)
1749 goto done;
1750
1751 ret = omap3isp_stat_register_entities(&isp->isp_aewb, &isp->v4l2_dev);
1752 if (ret < 0)
1753 goto done;
1754
1755 ret = omap3isp_stat_register_entities(&isp->isp_af, &isp->v4l2_dev);
1756 if (ret < 0)
1757 goto done;
1758
1759 ret = omap3isp_stat_register_entities(&isp->isp_hist, &isp->v4l2_dev);
1760 if (ret < 0)
1761 goto done;
1762
1763 /* Register external entities */
Ohad Ben-Cohenca4186f2011-06-01 13:39:46 -03001764 for (subdevs = pdata->subdevs; subdevs && subdevs->subdevs; ++subdevs) {
Sakari Ailus448de7e2011-02-12 18:05:06 -03001765 struct v4l2_subdev *sensor;
1766 struct media_entity *input;
1767 unsigned int flags;
1768 unsigned int pad;
Sakari Ailusaab84f52012-10-20 18:48:18 -03001769 unsigned int i;
Sakari Ailus448de7e2011-02-12 18:05:06 -03001770
1771 sensor = isp_register_subdev_group(isp, subdevs->subdevs);
1772 if (sensor == NULL)
1773 continue;
1774
1775 sensor->host_priv = subdevs;
1776
1777 /* Connect the sensor to the correct interface module. Parallel
1778 * sensors are connected directly to the CCDC, while serial
1779 * sensors are connected to the CSI2a, CCP2b or CSI2c receiver
1780 * through CSIPHY1 or CSIPHY2.
1781 */
1782 switch (subdevs->interface) {
1783 case ISP_INTERFACE_PARALLEL:
1784 input = &isp->isp_ccdc.subdev.entity;
1785 pad = CCDC_PAD_SINK;
1786 flags = 0;
1787 break;
1788
1789 case ISP_INTERFACE_CSI2A_PHY2:
1790 input = &isp->isp_csi2a.subdev.entity;
1791 pad = CSI2_PAD_SINK;
1792 flags = MEDIA_LNK_FL_IMMUTABLE
1793 | MEDIA_LNK_FL_ENABLED;
1794 break;
1795
1796 case ISP_INTERFACE_CCP2B_PHY1:
1797 case ISP_INTERFACE_CCP2B_PHY2:
1798 input = &isp->isp_ccp2.subdev.entity;
1799 pad = CCP2_PAD_SINK;
1800 flags = 0;
1801 break;
1802
1803 case ISP_INTERFACE_CSI2C_PHY1:
1804 input = &isp->isp_csi2c.subdev.entity;
1805 pad = CSI2_PAD_SINK;
1806 flags = MEDIA_LNK_FL_IMMUTABLE
1807 | MEDIA_LNK_FL_ENABLED;
1808 break;
1809
1810 default:
Laurent Pinchart4feca392012-10-22 08:28:51 -03001811 dev_err(isp->dev, "%s: invalid interface type %u\n",
1812 __func__, subdevs->interface);
Sakari Ailus448de7e2011-02-12 18:05:06 -03001813 ret = -EINVAL;
1814 goto done;
1815 }
1816
Sakari Ailusaab84f52012-10-20 18:48:18 -03001817 for (i = 0; i < sensor->entity.num_pads; i++) {
1818 if (sensor->entity.pads[i].flags & MEDIA_PAD_FL_SOURCE)
1819 break;
1820 }
1821 if (i == sensor->entity.num_pads) {
1822 dev_err(isp->dev,
1823 "%s: no source pad in external entity\n",
1824 __func__);
1825 ret = -EINVAL;
1826 goto done;
1827 }
1828
1829 ret = media_entity_create_link(&sensor->entity, i, input, pad,
Sakari Ailus448de7e2011-02-12 18:05:06 -03001830 flags);
1831 if (ret < 0)
1832 goto done;
1833 }
1834
1835 ret = v4l2_device_register_subdev_nodes(&isp->v4l2_dev);
1836
1837done:
1838 if (ret < 0)
1839 isp_unregister_entities(isp);
1840
1841 return ret;
1842}
1843
1844static void isp_cleanup_modules(struct isp_device *isp)
1845{
1846 omap3isp_h3a_aewb_cleanup(isp);
1847 omap3isp_h3a_af_cleanup(isp);
1848 omap3isp_hist_cleanup(isp);
1849 omap3isp_resizer_cleanup(isp);
1850 omap3isp_preview_cleanup(isp);
1851 omap3isp_ccdc_cleanup(isp);
1852 omap3isp_ccp2_cleanup(isp);
1853 omap3isp_csi2_cleanup(isp);
1854}
1855
1856static int isp_initialize_modules(struct isp_device *isp)
1857{
1858 int ret;
1859
1860 ret = omap3isp_csiphy_init(isp);
1861 if (ret < 0) {
1862 dev_err(isp->dev, "CSI PHY initialization failed\n");
1863 goto error_csiphy;
1864 }
1865
1866 ret = omap3isp_csi2_init(isp);
1867 if (ret < 0) {
1868 dev_err(isp->dev, "CSI2 initialization failed\n");
1869 goto error_csi2;
1870 }
1871
1872 ret = omap3isp_ccp2_init(isp);
1873 if (ret < 0) {
1874 dev_err(isp->dev, "CCP2 initialization failed\n");
1875 goto error_ccp2;
1876 }
1877
1878 ret = omap3isp_ccdc_init(isp);
1879 if (ret < 0) {
1880 dev_err(isp->dev, "CCDC initialization failed\n");
1881 goto error_ccdc;
1882 }
1883
1884 ret = omap3isp_preview_init(isp);
1885 if (ret < 0) {
1886 dev_err(isp->dev, "Preview initialization failed\n");
1887 goto error_preview;
1888 }
1889
1890 ret = omap3isp_resizer_init(isp);
1891 if (ret < 0) {
1892 dev_err(isp->dev, "Resizer initialization failed\n");
1893 goto error_resizer;
1894 }
1895
1896 ret = omap3isp_hist_init(isp);
1897 if (ret < 0) {
1898 dev_err(isp->dev, "Histogram initialization failed\n");
1899 goto error_hist;
1900 }
1901
1902 ret = omap3isp_h3a_aewb_init(isp);
1903 if (ret < 0) {
1904 dev_err(isp->dev, "H3A AEWB initialization failed\n");
1905 goto error_h3a_aewb;
1906 }
1907
1908 ret = omap3isp_h3a_af_init(isp);
1909 if (ret < 0) {
1910 dev_err(isp->dev, "H3A AF initialization failed\n");
1911 goto error_h3a_af;
1912 }
1913
1914 /* Connect the submodules. */
1915 ret = media_entity_create_link(
1916 &isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
1917 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
1918 if (ret < 0)
1919 goto error_link;
1920
1921 ret = media_entity_create_link(
1922 &isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
1923 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
1924 if (ret < 0)
1925 goto error_link;
1926
1927 ret = media_entity_create_link(
1928 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
1929 &isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
1930 if (ret < 0)
1931 goto error_link;
1932
1933 ret = media_entity_create_link(
1934 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
1935 &isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
1936 if (ret < 0)
1937 goto error_link;
1938
1939 ret = media_entity_create_link(
1940 &isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
1941 &isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
1942 if (ret < 0)
1943 goto error_link;
1944
1945 ret = media_entity_create_link(
1946 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
1947 &isp->isp_aewb.subdev.entity, 0,
1948 MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
1949 if (ret < 0)
1950 goto error_link;
1951
1952 ret = media_entity_create_link(
1953 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
1954 &isp->isp_af.subdev.entity, 0,
1955 MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
1956 if (ret < 0)
1957 goto error_link;
1958
1959 ret = media_entity_create_link(
1960 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
1961 &isp->isp_hist.subdev.entity, 0,
1962 MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
1963 if (ret < 0)
1964 goto error_link;
1965
1966 return 0;
1967
1968error_link:
1969 omap3isp_h3a_af_cleanup(isp);
1970error_h3a_af:
1971 omap3isp_h3a_aewb_cleanup(isp);
1972error_h3a_aewb:
1973 omap3isp_hist_cleanup(isp);
1974error_hist:
1975 omap3isp_resizer_cleanup(isp);
1976error_resizer:
1977 omap3isp_preview_cleanup(isp);
1978error_preview:
1979 omap3isp_ccdc_cleanup(isp);
1980error_ccdc:
1981 omap3isp_ccp2_cleanup(isp);
1982error_ccp2:
1983 omap3isp_csi2_cleanup(isp);
1984error_csi2:
1985error_csiphy:
1986 return ret;
1987}
1988
1989/*
1990 * isp_remove - Remove ISP platform device
1991 * @pdev: Pointer to ISP platform device
1992 *
1993 * Always returns 0.
1994 */
Laurent Pinchart79c3a072012-04-22 12:26:41 -03001995static int __devexit isp_remove(struct platform_device *pdev)
Sakari Ailus448de7e2011-02-12 18:05:06 -03001996{
1997 struct isp_device *isp = platform_get_drvdata(pdev);
1998 int i;
1999
2000 isp_unregister_entities(isp);
2001 isp_cleanup_modules(isp);
2002
Laurent Pinchart96d62ae2012-05-25 09:33:00 -03002003 __omap3isp_get(isp, false);
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +02002004 iommu_detach_device(isp->domain, &pdev->dev);
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03002005 iommu_domain_free(isp->domain);
Sakari Ailusa32f2f92012-01-27 07:18:51 -03002006 isp->domain = NULL;
Sakari Ailus448de7e2011-02-12 18:05:06 -03002007 omap3isp_put(isp);
2008
2009 free_irq(isp->irq_num, isp);
2010 isp_put_clocks(isp);
2011
2012 for (i = 0; i < OMAP3_ISP_IOMEM_LAST; i++) {
2013 if (isp->mmio_base[i]) {
2014 iounmap(isp->mmio_base[i]);
2015 isp->mmio_base[i] = NULL;
2016 }
2017
2018 if (isp->mmio_base_phys[i]) {
2019 release_mem_region(isp->mmio_base_phys[i],
2020 isp->mmio_size[i]);
2021 isp->mmio_base_phys[i] = 0;
2022 }
2023 }
2024
2025 regulator_put(isp->isp_csiphy1.vdd);
2026 regulator_put(isp->isp_csiphy2.vdd);
2027 kfree(isp);
2028
2029 return 0;
2030}
2031
2032static int isp_map_mem_resource(struct platform_device *pdev,
2033 struct isp_device *isp,
2034 enum isp_mem_resources res)
2035{
2036 struct resource *mem;
2037
2038 /* request the mem region for the camera registers */
2039
2040 mem = platform_get_resource(pdev, IORESOURCE_MEM, res);
2041 if (!mem) {
2042 dev_err(isp->dev, "no mem resource?\n");
2043 return -ENODEV;
2044 }
2045
2046 if (!request_mem_region(mem->start, resource_size(mem), pdev->name)) {
2047 dev_err(isp->dev,
2048 "cannot reserve camera register I/O region\n");
2049 return -ENODEV;
2050 }
2051 isp->mmio_base_phys[res] = mem->start;
2052 isp->mmio_size[res] = resource_size(mem);
2053
2054 /* map the region */
2055 isp->mmio_base[res] = ioremap_nocache(isp->mmio_base_phys[res],
2056 isp->mmio_size[res]);
2057 if (!isp->mmio_base[res]) {
2058 dev_err(isp->dev, "cannot map camera register I/O region\n");
2059 return -ENODEV;
2060 }
2061
2062 return 0;
2063}
2064
2065/*
2066 * isp_probe - Probe ISP platform device
2067 * @pdev: Pointer to ISP platform device
2068 *
2069 * Returns 0 if successful,
2070 * -ENOMEM if no memory available,
2071 * -ENODEV if no platform device resources found
2072 * or no space for remapping registers,
2073 * -EINVAL if couldn't install ISR,
2074 * or clk_get return error value.
2075 */
Laurent Pinchart79c3a072012-04-22 12:26:41 -03002076static int __devinit isp_probe(struct platform_device *pdev)
Sakari Ailus448de7e2011-02-12 18:05:06 -03002077{
2078 struct isp_platform_data *pdata = pdev->dev.platform_data;
2079 struct isp_device *isp;
2080 int ret;
2081 int i, m;
2082
2083 if (pdata == NULL)
2084 return -EINVAL;
2085
2086 isp = kzalloc(sizeof(*isp), GFP_KERNEL);
2087 if (!isp) {
2088 dev_err(&pdev->dev, "could not allocate memory\n");
2089 return -ENOMEM;
2090 }
2091
2092 isp->autoidle = autoidle;
2093 isp->platform_cb.set_xclk = isp_set_xclk;
Sakari Ailus448de7e2011-02-12 18:05:06 -03002094
2095 mutex_init(&isp->isp_mutex);
2096 spin_lock_init(&isp->stat_lock);
2097
2098 isp->dev = &pdev->dev;
2099 isp->pdata = pdata;
2100 isp->ref_count = 0;
2101
2102 isp->raw_dmamask = DMA_BIT_MASK(32);
2103 isp->dev->dma_mask = &isp->raw_dmamask;
2104 isp->dev->coherent_dma_mask = DMA_BIT_MASK(32);
2105
2106 platform_set_drvdata(pdev, isp);
2107
2108 /* Regulators */
2109 isp->isp_csiphy1.vdd = regulator_get(&pdev->dev, "VDD_CSIPHY1");
2110 isp->isp_csiphy2.vdd = regulator_get(&pdev->dev, "VDD_CSIPHY2");
2111
Laurent Pinchartd8658bc2012-09-27 10:38:18 -03002112 /* Clocks
2113 *
2114 * The ISP clock tree is revision-dependent. We thus need to enable ICLK
2115 * manually to read the revision before calling __omap3isp_get().
2116 */
Sakari Ailus448de7e2011-02-12 18:05:06 -03002117 ret = isp_map_mem_resource(pdev, isp, OMAP3_ISP_IOMEM_MAIN);
2118 if (ret < 0)
2119 goto error;
2120
2121 ret = isp_get_clocks(isp);
2122 if (ret < 0)
2123 goto error;
2124
Laurent Pinchartd8658bc2012-09-27 10:38:18 -03002125 ret = clk_enable(isp->clock[ISP_CLK_CAM_ICK]);
2126 if (ret < 0)
2127 goto error;
2128
2129 isp->revision = isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_REVISION);
2130 dev_info(isp->dev, "Revision %d.%d found\n",
2131 (isp->revision & 0xf0) >> 4, isp->revision & 0x0f);
2132
2133 clk_disable(isp->clock[ISP_CLK_CAM_ICK]);
2134
Peter Senna Tschudin0bd0dbe2012-09-04 13:14:25 -03002135 if (__omap3isp_get(isp, false) == NULL) {
2136 ret = -ENODEV;
Sakari Ailus448de7e2011-02-12 18:05:06 -03002137 goto error;
Peter Senna Tschudin0bd0dbe2012-09-04 13:14:25 -03002138 }
Sakari Ailus448de7e2011-02-12 18:05:06 -03002139
2140 ret = isp_reset(isp);
2141 if (ret < 0)
2142 goto error_isp;
2143
2144 /* Memory resources */
Sakari Ailus448de7e2011-02-12 18:05:06 -03002145 for (m = 0; m < ARRAY_SIZE(isp_res_maps); m++)
2146 if (isp->revision == isp_res_maps[m].isp_rev)
2147 break;
2148
2149 if (m == ARRAY_SIZE(isp_res_maps)) {
2150 dev_err(isp->dev, "No resource map found for ISP rev %d.%d\n",
2151 (isp->revision & 0xf0) >> 4, isp->revision & 0xf);
2152 ret = -ENODEV;
2153 goto error_isp;
2154 }
2155
2156 for (i = 1; i < OMAP3_ISP_IOMEM_LAST; i++) {
2157 if (isp_res_maps[m].map & 1 << i) {
2158 ret = isp_map_mem_resource(pdev, isp, i);
2159 if (ret)
2160 goto error_isp;
2161 }
2162 }
2163
Joerg Roedel905d66c2011-09-06 16:03:26 +02002164 isp->domain = iommu_domain_alloc(pdev->dev.bus);
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03002165 if (!isp->domain) {
2166 dev_err(isp->dev, "can't alloc iommu domain\n");
2167 ret = -ENOMEM;
2168 goto error_isp;
2169 }
2170
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +02002171 ret = iommu_attach_device(isp->domain, &pdev->dev);
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03002172 if (ret) {
2173 dev_err(&pdev->dev, "can't attach iommu device: %d\n", ret);
2174 goto free_domain;
2175 }
2176
Sakari Ailus448de7e2011-02-12 18:05:06 -03002177 /* Interrupt */
2178 isp->irq_num = platform_get_irq(pdev, 0);
2179 if (isp->irq_num <= 0) {
2180 dev_err(isp->dev, "No IRQ resource\n");
2181 ret = -ENODEV;
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03002182 goto detach_dev;
Sakari Ailus448de7e2011-02-12 18:05:06 -03002183 }
2184
2185 if (request_irq(isp->irq_num, isp_isr, IRQF_SHARED, "OMAP3 ISP", isp)) {
2186 dev_err(isp->dev, "Unable to request IRQ\n");
2187 ret = -EINVAL;
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03002188 goto detach_dev;
Sakari Ailus448de7e2011-02-12 18:05:06 -03002189 }
2190
2191 /* Entities */
2192 ret = isp_initialize_modules(isp);
2193 if (ret < 0)
2194 goto error_irq;
2195
2196 ret = isp_register_entities(isp);
2197 if (ret < 0)
2198 goto error_modules;
2199
Laurent Pinchart96d62ae2012-05-25 09:33:00 -03002200 isp_core_init(isp, 1);
Sakari Ailus448de7e2011-02-12 18:05:06 -03002201 omap3isp_put(isp);
2202
2203 return 0;
2204
2205error_modules:
2206 isp_cleanup_modules(isp);
2207error_irq:
2208 free_irq(isp->irq_num, isp);
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03002209detach_dev:
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +02002210 iommu_detach_device(isp->domain, &pdev->dev);
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03002211free_domain:
2212 iommu_domain_free(isp->domain);
Sakari Ailus448de7e2011-02-12 18:05:06 -03002213error_isp:
Sakari Ailus448de7e2011-02-12 18:05:06 -03002214 omap3isp_put(isp);
2215error:
2216 isp_put_clocks(isp);
2217
2218 for (i = 0; i < OMAP3_ISP_IOMEM_LAST; i++) {
2219 if (isp->mmio_base[i]) {
2220 iounmap(isp->mmio_base[i]);
2221 isp->mmio_base[i] = NULL;
2222 }
2223
2224 if (isp->mmio_base_phys[i]) {
2225 release_mem_region(isp->mmio_base_phys[i],
2226 isp->mmio_size[i]);
2227 isp->mmio_base_phys[i] = 0;
2228 }
2229 }
2230 regulator_put(isp->isp_csiphy2.vdd);
2231 regulator_put(isp->isp_csiphy1.vdd);
2232 platform_set_drvdata(pdev, NULL);
Laurent Pincharted33ac82011-09-22 17:09:26 -03002233
2234 mutex_destroy(&isp->isp_mutex);
Sakari Ailus448de7e2011-02-12 18:05:06 -03002235 kfree(isp);
2236
2237 return ret;
2238}
2239
2240static const struct dev_pm_ops omap3isp_pm_ops = {
2241 .prepare = isp_pm_prepare,
2242 .suspend = isp_pm_suspend,
2243 .resume = isp_pm_resume,
2244 .complete = isp_pm_complete,
2245};
2246
2247static struct platform_device_id omap3isp_id_table[] = {
2248 { "omap3isp", 0 },
2249 { },
2250};
2251MODULE_DEVICE_TABLE(platform, omap3isp_id_table);
2252
2253static struct platform_driver omap3isp_driver = {
2254 .probe = isp_probe,
Laurent Pinchart79c3a072012-04-22 12:26:41 -03002255 .remove = __devexit_p(isp_remove),
Sakari Ailus448de7e2011-02-12 18:05:06 -03002256 .id_table = omap3isp_id_table,
2257 .driver = {
2258 .owner = THIS_MODULE,
2259 .name = "omap3isp",
2260 .pm = &omap3isp_pm_ops,
2261 },
2262};
2263
Axel Lin1d6629b2012-01-10 03:21:49 -03002264module_platform_driver(omap3isp_driver);
Sakari Ailus448de7e2011-02-12 18:05:06 -03002265
2266MODULE_AUTHOR("Nokia Corporation");
2267MODULE_DESCRIPTION("TI OMAP3 ISP driver");
2268MODULE_LICENSE("GPL");
Mauro Carvalho Chehab64dc3c12011-06-25 11:28:37 -03002269MODULE_VERSION(ISP_VIDEO_DRIVER_VERSION);