GNU Linux-libre 4.9.309-gnu1
[releases.git] / drivers / media / platform / omap3isp / isp.c
1 /*
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
45 #include <asm/cacheflush.h>
46
47 #include <linux/clk.h>
48 #include <linux/clkdev.h>
49 #include <linux/delay.h>
50 #include <linux/device.h>
51 #include <linux/dma-mapping.h>
52 #include <linux/i2c.h>
53 #include <linux/interrupt.h>
54 #include <linux/mfd/syscon.h>
55 #include <linux/module.h>
56 #include <linux/omap-iommu.h>
57 #include <linux/platform_device.h>
58 #include <linux/regulator/consumer.h>
59 #include <linux/slab.h>
60 #include <linux/sched.h>
61 #include <linux/vmalloc.h>
62
63 #include <asm/dma-iommu.h>
64
65 #include <media/v4l2-common.h>
66 #include <media/v4l2-device.h>
67 #include <media/v4l2-mc.h>
68 #include <media/v4l2-of.h>
69
70 #include "isp.h"
71 #include "ispreg.h"
72 #include "ispccdc.h"
73 #include "isppreview.h"
74 #include "ispresizer.h"
75 #include "ispcsi2.h"
76 #include "ispccp2.h"
77 #include "isph3a.h"
78 #include "isphist.h"
79
80 static unsigned int autoidle;
81 module_param(autoidle, int, 0444);
82 MODULE_PARM_DESC(autoidle, "Enable OMAP3ISP AUTOIDLE support");
83
84 static void isp_save_ctx(struct isp_device *isp);
85
86 static void isp_restore_ctx(struct isp_device *isp);
87
88 static const struct isp_res_mapping isp_res_maps[] = {
89         {
90                 .isp_rev = ISP_REVISION_2_0,
91                 .offset = {
92                         /* first MMIO area */
93                         0x0000, /* base, len 0x0070 */
94                         0x0400, /* ccp2, len 0x01f0 */
95                         0x0600, /* ccdc, len 0x00a8 */
96                         0x0a00, /* hist, len 0x0048 */
97                         0x0c00, /* h3a, len 0x0060 */
98                         0x0e00, /* preview, len 0x00a0 */
99                         0x1000, /* resizer, len 0x00ac */
100                         0x1200, /* sbl, len 0x00fc */
101                         /* second MMIO area */
102                         0x0000, /* csi2a, len 0x0170 */
103                         0x0170, /* csiphy2, len 0x000c */
104                 },
105                 .phy_type = ISP_PHY_TYPE_3430,
106         },
107         {
108                 .isp_rev = ISP_REVISION_15_0,
109                 .offset = {
110                         /* first MMIO area */
111                         0x0000, /* base, len 0x0070 */
112                         0x0400, /* ccp2, len 0x01f0 */
113                         0x0600, /* ccdc, len 0x00a8 */
114                         0x0a00, /* hist, len 0x0048 */
115                         0x0c00, /* h3a, len 0x0060 */
116                         0x0e00, /* preview, len 0x00a0 */
117                         0x1000, /* resizer, len 0x00ac */
118                         0x1200, /* sbl, len 0x00fc */
119                         /* second MMIO area */
120                         0x0000, /* csi2a, len 0x0170 (1st area) */
121                         0x0170, /* csiphy2, len 0x000c */
122                         0x01c0, /* csi2a, len 0x0040 (2nd area) */
123                         0x0400, /* csi2c, len 0x0170 (1st area) */
124                         0x0570, /* csiphy1, len 0x000c */
125                         0x05c0, /* csi2c, len 0x0040 (2nd area) */
126                 },
127                 .phy_type = ISP_PHY_TYPE_3630,
128         },
129 };
130
131 /* Structure for saving/restoring ISP module registers */
132 static struct isp_reg isp_reg_list[] = {
133         {OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG, 0},
134         {OMAP3_ISP_IOMEM_MAIN, ISP_CTRL, 0},
135         {OMAP3_ISP_IOMEM_MAIN, ISP_TCTRL_CTRL, 0},
136         {0, ISP_TOK_TERM, 0}
137 };
138
139 /*
140  * omap3isp_flush - Post pending L3 bus writes by doing a register readback
141  * @isp: OMAP3 ISP device
142  *
143  * In order to force posting of pending writes, we need to write and
144  * readback the same register, in this case the revision register.
145  *
146  * See this link for reference:
147  *   http://www.mail-archive.com/linux-omap@vger.kernel.org/msg08149.html
148  */
149 void omap3isp_flush(struct isp_device *isp)
150 {
151         isp_reg_writel(isp, 0, OMAP3_ISP_IOMEM_MAIN, ISP_REVISION);
152         isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_REVISION);
153 }
154
155 /* -----------------------------------------------------------------------------
156  * XCLK
157  */
158
159 #define to_isp_xclk(_hw)        container_of(_hw, struct isp_xclk, hw)
160
161 static void isp_xclk_update(struct isp_xclk *xclk, u32 divider)
162 {
163         switch (xclk->id) {
164         case ISP_XCLK_A:
165                 isp_reg_clr_set(xclk->isp, OMAP3_ISP_IOMEM_MAIN, ISP_TCTRL_CTRL,
166                                 ISPTCTRL_CTRL_DIVA_MASK,
167                                 divider << ISPTCTRL_CTRL_DIVA_SHIFT);
168                 break;
169         case ISP_XCLK_B:
170                 isp_reg_clr_set(xclk->isp, OMAP3_ISP_IOMEM_MAIN, ISP_TCTRL_CTRL,
171                                 ISPTCTRL_CTRL_DIVB_MASK,
172                                 divider << ISPTCTRL_CTRL_DIVB_SHIFT);
173                 break;
174         }
175 }
176
177 static int isp_xclk_prepare(struct clk_hw *hw)
178 {
179         struct isp_xclk *xclk = to_isp_xclk(hw);
180
181         omap3isp_get(xclk->isp);
182
183         return 0;
184 }
185
186 static void isp_xclk_unprepare(struct clk_hw *hw)
187 {
188         struct isp_xclk *xclk = to_isp_xclk(hw);
189
190         omap3isp_put(xclk->isp);
191 }
192
193 static int isp_xclk_enable(struct clk_hw *hw)
194 {
195         struct isp_xclk *xclk = to_isp_xclk(hw);
196         unsigned long flags;
197
198         spin_lock_irqsave(&xclk->lock, flags);
199         isp_xclk_update(xclk, xclk->divider);
200         xclk->enabled = true;
201         spin_unlock_irqrestore(&xclk->lock, flags);
202
203         return 0;
204 }
205
206 static void isp_xclk_disable(struct clk_hw *hw)
207 {
208         struct isp_xclk *xclk = to_isp_xclk(hw);
209         unsigned long flags;
210
211         spin_lock_irqsave(&xclk->lock, flags);
212         isp_xclk_update(xclk, 0);
213         xclk->enabled = false;
214         spin_unlock_irqrestore(&xclk->lock, flags);
215 }
216
217 static unsigned long isp_xclk_recalc_rate(struct clk_hw *hw,
218                                           unsigned long parent_rate)
219 {
220         struct isp_xclk *xclk = to_isp_xclk(hw);
221
222         return parent_rate / xclk->divider;
223 }
224
225 static u32 isp_xclk_calc_divider(unsigned long *rate, unsigned long parent_rate)
226 {
227         u32 divider;
228
229         if (*rate >= parent_rate) {
230                 *rate = parent_rate;
231                 return ISPTCTRL_CTRL_DIV_BYPASS;
232         }
233
234         if (*rate == 0)
235                 *rate = 1;
236
237         divider = DIV_ROUND_CLOSEST(parent_rate, *rate);
238         if (divider >= ISPTCTRL_CTRL_DIV_BYPASS)
239                 divider = ISPTCTRL_CTRL_DIV_BYPASS - 1;
240
241         *rate = parent_rate / divider;
242         return divider;
243 }
244
245 static long isp_xclk_round_rate(struct clk_hw *hw, unsigned long rate,
246                                 unsigned long *parent_rate)
247 {
248         isp_xclk_calc_divider(&rate, *parent_rate);
249         return rate;
250 }
251
252 static int isp_xclk_set_rate(struct clk_hw *hw, unsigned long rate,
253                              unsigned long parent_rate)
254 {
255         struct isp_xclk *xclk = to_isp_xclk(hw);
256         unsigned long flags;
257         u32 divider;
258
259         divider = isp_xclk_calc_divider(&rate, parent_rate);
260
261         spin_lock_irqsave(&xclk->lock, flags);
262
263         xclk->divider = divider;
264         if (xclk->enabled)
265                 isp_xclk_update(xclk, divider);
266
267         spin_unlock_irqrestore(&xclk->lock, flags);
268
269         dev_dbg(xclk->isp->dev, "%s: cam_xclk%c set to %lu Hz (div %u)\n",
270                 __func__, xclk->id == ISP_XCLK_A ? 'a' : 'b', rate, divider);
271         return 0;
272 }
273
274 static const struct clk_ops isp_xclk_ops = {
275         .prepare = isp_xclk_prepare,
276         .unprepare = isp_xclk_unprepare,
277         .enable = isp_xclk_enable,
278         .disable = isp_xclk_disable,
279         .recalc_rate = isp_xclk_recalc_rate,
280         .round_rate = isp_xclk_round_rate,
281         .set_rate = isp_xclk_set_rate,
282 };
283
284 static const char *isp_xclk_parent_name = "cam_mclk";
285
286 static const struct clk_init_data isp_xclk_init_data = {
287         .name = "cam_xclk",
288         .ops = &isp_xclk_ops,
289         .parent_names = &isp_xclk_parent_name,
290         .num_parents = 1,
291 };
292
293 static struct clk *isp_xclk_src_get(struct of_phandle_args *clkspec, void *data)
294 {
295         unsigned int idx = clkspec->args[0];
296         struct isp_device *isp = data;
297
298         if (idx >= ARRAY_SIZE(isp->xclks))
299                 return ERR_PTR(-ENOENT);
300
301         return isp->xclks[idx].clk;
302 }
303
304 static int isp_xclk_init(struct isp_device *isp)
305 {
306         struct device_node *np = isp->dev->of_node;
307         struct clk_init_data init = { 0 };
308         unsigned int i;
309
310         for (i = 0; i < ARRAY_SIZE(isp->xclks); ++i)
311                 isp->xclks[i].clk = ERR_PTR(-EINVAL);
312
313         for (i = 0; i < ARRAY_SIZE(isp->xclks); ++i) {
314                 struct isp_xclk *xclk = &isp->xclks[i];
315
316                 xclk->isp = isp;
317                 xclk->id = i == 0 ? ISP_XCLK_A : ISP_XCLK_B;
318                 xclk->divider = 1;
319                 spin_lock_init(&xclk->lock);
320
321                 init.name = i == 0 ? "cam_xclka" : "cam_xclkb";
322                 init.ops = &isp_xclk_ops;
323                 init.parent_names = &isp_xclk_parent_name;
324                 init.num_parents = 1;
325
326                 xclk->hw.init = &init;
327                 /*
328                  * The first argument is NULL in order to avoid circular
329                  * reference, as this driver takes reference on the
330                  * sensor subdevice modules and the sensors would take
331                  * reference on this module through clk_get().
332                  */
333                 xclk->clk = clk_register(NULL, &xclk->hw);
334                 if (IS_ERR(xclk->clk))
335                         return PTR_ERR(xclk->clk);
336         }
337
338         if (np)
339                 of_clk_add_provider(np, isp_xclk_src_get, isp);
340
341         return 0;
342 }
343
344 static void isp_xclk_cleanup(struct isp_device *isp)
345 {
346         struct device_node *np = isp->dev->of_node;
347         unsigned int i;
348
349         if (np)
350                 of_clk_del_provider(np);
351
352         for (i = 0; i < ARRAY_SIZE(isp->xclks); ++i) {
353                 struct isp_xclk *xclk = &isp->xclks[i];
354
355                 if (!IS_ERR(xclk->clk))
356                         clk_unregister(xclk->clk);
357         }
358 }
359
360 /* -----------------------------------------------------------------------------
361  * Interrupts
362  */
363
364 /*
365  * isp_enable_interrupts - Enable ISP interrupts.
366  * @isp: OMAP3 ISP device
367  */
368 static void isp_enable_interrupts(struct isp_device *isp)
369 {
370         static const u32 irq = IRQ0ENABLE_CSIA_IRQ
371                              | IRQ0ENABLE_CSIB_IRQ
372                              | IRQ0ENABLE_CCDC_LSC_PREF_ERR_IRQ
373                              | IRQ0ENABLE_CCDC_LSC_DONE_IRQ
374                              | IRQ0ENABLE_CCDC_VD0_IRQ
375                              | IRQ0ENABLE_CCDC_VD1_IRQ
376                              | IRQ0ENABLE_HS_VS_IRQ
377                              | IRQ0ENABLE_HIST_DONE_IRQ
378                              | IRQ0ENABLE_H3A_AWB_DONE_IRQ
379                              | IRQ0ENABLE_H3A_AF_DONE_IRQ
380                              | IRQ0ENABLE_PRV_DONE_IRQ
381                              | IRQ0ENABLE_RSZ_DONE_IRQ;
382
383         isp_reg_writel(isp, irq, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
384         isp_reg_writel(isp, irq, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0ENABLE);
385 }
386
387 /*
388  * isp_disable_interrupts - Disable ISP interrupts.
389  * @isp: OMAP3 ISP device
390  */
391 static void isp_disable_interrupts(struct isp_device *isp)
392 {
393         isp_reg_writel(isp, 0, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0ENABLE);
394 }
395
396 /*
397  * isp_core_init - ISP core settings
398  * @isp: OMAP3 ISP device
399  * @idle: Consider idle state.
400  *
401  * Set the power settings for the ISP and SBL bus and configure the HS/VS
402  * interrupt source.
403  *
404  * We need to configure the HS/VS interrupt source before interrupts get
405  * enabled, as the sensor might be free-running and the ISP default setting
406  * (HS edge) would put an unnecessary burden on the CPU.
407  */
408 static void isp_core_init(struct isp_device *isp, int idle)
409 {
410         isp_reg_writel(isp,
411                        ((idle ? ISP_SYSCONFIG_MIDLEMODE_SMARTSTANDBY :
412                                 ISP_SYSCONFIG_MIDLEMODE_FORCESTANDBY) <<
413                         ISP_SYSCONFIG_MIDLEMODE_SHIFT) |
414                         ((isp->revision == ISP_REVISION_15_0) ?
415                           ISP_SYSCONFIG_AUTOIDLE : 0),
416                        OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG);
417
418         isp_reg_writel(isp,
419                        (isp->autoidle ? ISPCTRL_SBL_AUTOIDLE : 0) |
420                        ISPCTRL_SYNC_DETECT_VSRISE,
421                        OMAP3_ISP_IOMEM_MAIN, ISP_CTRL);
422 }
423
424 /*
425  * Configure the bridge and lane shifter. Valid inputs are
426  *
427  * CCDC_INPUT_PARALLEL: Parallel interface
428  * CCDC_INPUT_CSI2A: CSI2a receiver
429  * CCDC_INPUT_CCP2B: CCP2b receiver
430  * CCDC_INPUT_CSI2C: CSI2c receiver
431  *
432  * The bridge and lane shifter are configured according to the selected input
433  * and the ISP platform data.
434  */
435 void omap3isp_configure_bridge(struct isp_device *isp,
436                                enum ccdc_input_entity input,
437                                const struct isp_parallel_cfg *parcfg,
438                                unsigned int shift, unsigned int bridge)
439 {
440         u32 ispctrl_val;
441
442         ispctrl_val  = isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL);
443         ispctrl_val &= ~ISPCTRL_SHIFT_MASK;
444         ispctrl_val &= ~ISPCTRL_PAR_CLK_POL_INV;
445         ispctrl_val &= ~ISPCTRL_PAR_SER_CLK_SEL_MASK;
446         ispctrl_val &= ~ISPCTRL_PAR_BRIDGE_MASK;
447         ispctrl_val |= bridge;
448
449         switch (input) {
450         case CCDC_INPUT_PARALLEL:
451                 ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_PARALLEL;
452                 ispctrl_val |= parcfg->clk_pol << ISPCTRL_PAR_CLK_POL_SHIFT;
453                 shift += parcfg->data_lane_shift;
454                 break;
455
456         case CCDC_INPUT_CSI2A:
457                 ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_CSIA;
458                 break;
459
460         case CCDC_INPUT_CCP2B:
461                 ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_CSIB;
462                 break;
463
464         case CCDC_INPUT_CSI2C:
465                 ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_CSIC;
466                 break;
467
468         default:
469                 return;
470         }
471
472         ispctrl_val |= ((shift/2) << ISPCTRL_SHIFT_SHIFT) & ISPCTRL_SHIFT_MASK;
473
474         isp_reg_writel(isp, ispctrl_val, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL);
475 }
476
477 void omap3isp_hist_dma_done(struct isp_device *isp)
478 {
479         if (omap3isp_ccdc_busy(&isp->isp_ccdc) ||
480             omap3isp_stat_pcr_busy(&isp->isp_hist)) {
481                 /* Histogram cannot be enabled in this frame anymore */
482                 atomic_set(&isp->isp_hist.buf_err, 1);
483                 dev_dbg(isp->dev, "hist: Out of synchronization with "
484                                   "CCDC. Ignoring next buffer.\n");
485         }
486 }
487
488 static inline void isp_isr_dbg(struct isp_device *isp, u32 irqstatus)
489 {
490         static const char *name[] = {
491                 "CSIA_IRQ",
492                 "res1",
493                 "res2",
494                 "CSIB_LCM_IRQ",
495                 "CSIB_IRQ",
496                 "res5",
497                 "res6",
498                 "res7",
499                 "CCDC_VD0_IRQ",
500                 "CCDC_VD1_IRQ",
501                 "CCDC_VD2_IRQ",
502                 "CCDC_ERR_IRQ",
503                 "H3A_AF_DONE_IRQ",
504                 "H3A_AWB_DONE_IRQ",
505                 "res14",
506                 "res15",
507                 "HIST_DONE_IRQ",
508                 "CCDC_LSC_DONE",
509                 "CCDC_LSC_PREFETCH_COMPLETED",
510                 "CCDC_LSC_PREFETCH_ERROR",
511                 "PRV_DONE_IRQ",
512                 "CBUFF_IRQ",
513                 "res22",
514                 "res23",
515                 "RSZ_DONE_IRQ",
516                 "OVF_IRQ",
517                 "res26",
518                 "res27",
519                 "MMU_ERR_IRQ",
520                 "OCP_ERR_IRQ",
521                 "SEC_ERR_IRQ",
522                 "HS_VS_IRQ",
523         };
524         int i;
525
526         dev_dbg(isp->dev, "ISP IRQ: ");
527
528         for (i = 0; i < ARRAY_SIZE(name); i++) {
529                 if ((1 << i) & irqstatus)
530                         printk(KERN_CONT "%s ", name[i]);
531         }
532         printk(KERN_CONT "\n");
533 }
534
535 static void isp_isr_sbl(struct isp_device *isp)
536 {
537         struct device *dev = isp->dev;
538         struct isp_pipeline *pipe;
539         u32 sbl_pcr;
540
541         /*
542          * Handle shared buffer logic overflows for video buffers.
543          * ISPSBL_PCR_CCDCPRV_2_RSZ_OVF can be safely ignored.
544          */
545         sbl_pcr = isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_PCR);
546         isp_reg_writel(isp, sbl_pcr, OMAP3_ISP_IOMEM_SBL, ISPSBL_PCR);
547         sbl_pcr &= ~ISPSBL_PCR_CCDCPRV_2_RSZ_OVF;
548
549         if (sbl_pcr)
550                 dev_dbg(dev, "SBL overflow (PCR = 0x%08x)\n", sbl_pcr);
551
552         if (sbl_pcr & ISPSBL_PCR_CSIB_WBL_OVF) {
553                 pipe = to_isp_pipeline(&isp->isp_ccp2.subdev.entity);
554                 if (pipe != NULL)
555                         pipe->error = true;
556         }
557
558         if (sbl_pcr & ISPSBL_PCR_CSIA_WBL_OVF) {
559                 pipe = to_isp_pipeline(&isp->isp_csi2a.subdev.entity);
560                 if (pipe != NULL)
561                         pipe->error = true;
562         }
563
564         if (sbl_pcr & ISPSBL_PCR_CCDC_WBL_OVF) {
565                 pipe = to_isp_pipeline(&isp->isp_ccdc.subdev.entity);
566                 if (pipe != NULL)
567                         pipe->error = true;
568         }
569
570         if (sbl_pcr & ISPSBL_PCR_PRV_WBL_OVF) {
571                 pipe = to_isp_pipeline(&isp->isp_prev.subdev.entity);
572                 if (pipe != NULL)
573                         pipe->error = true;
574         }
575
576         if (sbl_pcr & (ISPSBL_PCR_RSZ1_WBL_OVF
577                        | ISPSBL_PCR_RSZ2_WBL_OVF
578                        | ISPSBL_PCR_RSZ3_WBL_OVF
579                        | ISPSBL_PCR_RSZ4_WBL_OVF)) {
580                 pipe = to_isp_pipeline(&isp->isp_res.subdev.entity);
581                 if (pipe != NULL)
582                         pipe->error = true;
583         }
584
585         if (sbl_pcr & ISPSBL_PCR_H3A_AF_WBL_OVF)
586                 omap3isp_stat_sbl_overflow(&isp->isp_af);
587
588         if (sbl_pcr & ISPSBL_PCR_H3A_AEAWB_WBL_OVF)
589                 omap3isp_stat_sbl_overflow(&isp->isp_aewb);
590 }
591
592 /*
593  * isp_isr - Interrupt Service Routine for Camera ISP module.
594  * @irq: Not used currently.
595  * @_isp: Pointer to the OMAP3 ISP device
596  *
597  * Handles the corresponding callback if plugged in.
598  */
599 static irqreturn_t isp_isr(int irq, void *_isp)
600 {
601         static const u32 ccdc_events = IRQ0STATUS_CCDC_LSC_PREF_ERR_IRQ |
602                                        IRQ0STATUS_CCDC_LSC_DONE_IRQ |
603                                        IRQ0STATUS_CCDC_VD0_IRQ |
604                                        IRQ0STATUS_CCDC_VD1_IRQ |
605                                        IRQ0STATUS_HS_VS_IRQ;
606         struct isp_device *isp = _isp;
607         u32 irqstatus;
608
609         irqstatus = isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
610         isp_reg_writel(isp, irqstatus, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
611
612         isp_isr_sbl(isp);
613
614         if (irqstatus & IRQ0STATUS_CSIA_IRQ)
615                 omap3isp_csi2_isr(&isp->isp_csi2a);
616
617         if (irqstatus & IRQ0STATUS_CSIB_IRQ)
618                 omap3isp_ccp2_isr(&isp->isp_ccp2);
619
620         if (irqstatus & IRQ0STATUS_CCDC_VD0_IRQ) {
621                 if (isp->isp_ccdc.output & CCDC_OUTPUT_PREVIEW)
622                         omap3isp_preview_isr_frame_sync(&isp->isp_prev);
623                 if (isp->isp_ccdc.output & CCDC_OUTPUT_RESIZER)
624                         omap3isp_resizer_isr_frame_sync(&isp->isp_res);
625                 omap3isp_stat_isr_frame_sync(&isp->isp_aewb);
626                 omap3isp_stat_isr_frame_sync(&isp->isp_af);
627                 omap3isp_stat_isr_frame_sync(&isp->isp_hist);
628         }
629
630         if (irqstatus & ccdc_events)
631                 omap3isp_ccdc_isr(&isp->isp_ccdc, irqstatus & ccdc_events);
632
633         if (irqstatus & IRQ0STATUS_PRV_DONE_IRQ) {
634                 if (isp->isp_prev.output & PREVIEW_OUTPUT_RESIZER)
635                         omap3isp_resizer_isr_frame_sync(&isp->isp_res);
636                 omap3isp_preview_isr(&isp->isp_prev);
637         }
638
639         if (irqstatus & IRQ0STATUS_RSZ_DONE_IRQ)
640                 omap3isp_resizer_isr(&isp->isp_res);
641
642         if (irqstatus & IRQ0STATUS_H3A_AWB_DONE_IRQ)
643                 omap3isp_stat_isr(&isp->isp_aewb);
644
645         if (irqstatus & IRQ0STATUS_H3A_AF_DONE_IRQ)
646                 omap3isp_stat_isr(&isp->isp_af);
647
648         if (irqstatus & IRQ0STATUS_HIST_DONE_IRQ)
649                 omap3isp_stat_isr(&isp->isp_hist);
650
651         omap3isp_flush(isp);
652
653 #if defined(DEBUG) && defined(ISP_ISR_DEBUG)
654         isp_isr_dbg(isp, irqstatus);
655 #endif
656
657         return IRQ_HANDLED;
658 }
659
660 static const struct media_device_ops isp_media_ops = {
661         .link_notify = v4l2_pipeline_link_notify,
662 };
663
664 /* -----------------------------------------------------------------------------
665  * Pipeline stream management
666  */
667
668 /*
669  * isp_pipeline_enable - Enable streaming on a pipeline
670  * @pipe: ISP pipeline
671  * @mode: Stream mode (single shot or continuous)
672  *
673  * Walk the entities chain starting at the pipeline output video node and start
674  * all modules in the chain in the given mode.
675  *
676  * Return 0 if successful, or the return value of the failed video::s_stream
677  * operation otherwise.
678  */
679 static int isp_pipeline_enable(struct isp_pipeline *pipe,
680                                enum isp_pipeline_stream_state mode)
681 {
682         struct isp_device *isp = pipe->output->isp;
683         struct media_entity *entity;
684         struct media_pad *pad;
685         struct v4l2_subdev *subdev;
686         unsigned long flags;
687         int ret;
688
689         /* Refuse to start streaming if an entity included in the pipeline has
690          * crashed. This check must be performed before the loop below to avoid
691          * starting entities if the pipeline won't start anyway (those entities
692          * would then likely fail to stop, making the problem worse).
693          */
694         if (media_entity_enum_intersects(&pipe->ent_enum, &isp->crashed))
695                 return -EIO;
696
697         spin_lock_irqsave(&pipe->lock, flags);
698         pipe->state &= ~(ISP_PIPELINE_IDLE_INPUT | ISP_PIPELINE_IDLE_OUTPUT);
699         spin_unlock_irqrestore(&pipe->lock, flags);
700
701         pipe->do_propagation = false;
702
703         entity = &pipe->output->video.entity;
704         while (1) {
705                 pad = &entity->pads[0];
706                 if (!(pad->flags & MEDIA_PAD_FL_SINK))
707                         break;
708
709                 pad = media_entity_remote_pad(pad);
710                 if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
711                         break;
712
713                 entity = pad->entity;
714                 subdev = media_entity_to_v4l2_subdev(entity);
715
716                 ret = v4l2_subdev_call(subdev, video, s_stream, mode);
717                 if (ret < 0 && ret != -ENOIOCTLCMD)
718                         return ret;
719
720                 if (subdev == &isp->isp_ccdc.subdev) {
721                         v4l2_subdev_call(&isp->isp_aewb.subdev, video,
722                                         s_stream, mode);
723                         v4l2_subdev_call(&isp->isp_af.subdev, video,
724                                         s_stream, mode);
725                         v4l2_subdev_call(&isp->isp_hist.subdev, video,
726                                         s_stream, mode);
727                         pipe->do_propagation = true;
728                 }
729
730                 /* Stop at the first external sub-device. */
731                 if (subdev->dev != isp->dev)
732                         break;
733         }
734
735         return 0;
736 }
737
738 static int isp_pipeline_wait_resizer(struct isp_device *isp)
739 {
740         return omap3isp_resizer_busy(&isp->isp_res);
741 }
742
743 static int isp_pipeline_wait_preview(struct isp_device *isp)
744 {
745         return omap3isp_preview_busy(&isp->isp_prev);
746 }
747
748 static int isp_pipeline_wait_ccdc(struct isp_device *isp)
749 {
750         return omap3isp_stat_busy(&isp->isp_af)
751             || omap3isp_stat_busy(&isp->isp_aewb)
752             || omap3isp_stat_busy(&isp->isp_hist)
753             || omap3isp_ccdc_busy(&isp->isp_ccdc);
754 }
755
756 #define ISP_STOP_TIMEOUT        msecs_to_jiffies(1000)
757
758 static int isp_pipeline_wait(struct isp_device *isp,
759                              int(*busy)(struct isp_device *isp))
760 {
761         unsigned long timeout = jiffies + ISP_STOP_TIMEOUT;
762
763         while (!time_after(jiffies, timeout)) {
764                 if (!busy(isp))
765                         return 0;
766         }
767
768         return 1;
769 }
770
771 /*
772  * isp_pipeline_disable - Disable streaming on a pipeline
773  * @pipe: ISP pipeline
774  *
775  * Walk the entities chain starting at the pipeline output video node and stop
776  * all modules in the chain. Wait synchronously for the modules to be stopped if
777  * necessary.
778  *
779  * Return 0 if all modules have been properly stopped, or -ETIMEDOUT if a module
780  * can't be stopped (in which case a software reset of the ISP is probably
781  * necessary).
782  */
783 static int isp_pipeline_disable(struct isp_pipeline *pipe)
784 {
785         struct isp_device *isp = pipe->output->isp;
786         struct media_entity *entity;
787         struct media_pad *pad;
788         struct v4l2_subdev *subdev;
789         int failure = 0;
790         int ret;
791
792         /*
793          * We need to stop all the modules after CCDC first or they'll
794          * never stop since they may not get a full frame from CCDC.
795          */
796         entity = &pipe->output->video.entity;
797         while (1) {
798                 pad = &entity->pads[0];
799                 if (!(pad->flags & MEDIA_PAD_FL_SINK))
800                         break;
801
802                 pad = media_entity_remote_pad(pad);
803                 if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
804                         break;
805
806                 entity = pad->entity;
807                 subdev = media_entity_to_v4l2_subdev(entity);
808
809                 if (subdev == &isp->isp_ccdc.subdev) {
810                         v4l2_subdev_call(&isp->isp_aewb.subdev,
811                                          video, s_stream, 0);
812                         v4l2_subdev_call(&isp->isp_af.subdev,
813                                          video, s_stream, 0);
814                         v4l2_subdev_call(&isp->isp_hist.subdev,
815                                          video, s_stream, 0);
816                 }
817
818                 ret = v4l2_subdev_call(subdev, video, s_stream, 0);
819
820                 if (subdev == &isp->isp_res.subdev)
821                         ret |= isp_pipeline_wait(isp, isp_pipeline_wait_resizer);
822                 else if (subdev == &isp->isp_prev.subdev)
823                         ret |= isp_pipeline_wait(isp, isp_pipeline_wait_preview);
824                 else if (subdev == &isp->isp_ccdc.subdev)
825                         ret |= isp_pipeline_wait(isp, isp_pipeline_wait_ccdc);
826
827                 /* Handle stop failures. An entity that fails to stop can
828                  * usually just be restarted. Flag the stop failure nonetheless
829                  * to trigger an ISP reset the next time the device is released,
830                  * just in case.
831                  *
832                  * The preview engine is a special case. A failure to stop can
833                  * mean a hardware crash. When that happens the preview engine
834                  * won't respond to read/write operations on the L4 bus anymore,
835                  * resulting in a bus fault and a kernel oops next time it gets
836                  * accessed. Mark it as crashed to prevent pipelines including
837                  * it from being started.
838                  */
839                 if (ret) {
840                         dev_info(isp->dev, "Unable to stop %s\n", subdev->name);
841                         isp->stop_failure = true;
842                         if (subdev == &isp->isp_prev.subdev)
843                                 media_entity_enum_set(&isp->crashed,
844                                                       &subdev->entity);
845                         failure = -ETIMEDOUT;
846                 }
847
848                 /* Stop at the first external sub-device. */
849                 if (subdev->dev != isp->dev)
850                         break;
851         }
852
853         return failure;
854 }
855
856 /*
857  * omap3isp_pipeline_set_stream - Enable/disable streaming on a pipeline
858  * @pipe: ISP pipeline
859  * @state: Stream state (stopped, single shot or continuous)
860  *
861  * Set the pipeline to the given stream state. Pipelines can be started in
862  * single-shot or continuous mode.
863  *
864  * Return 0 if successful, or the return value of the failed video::s_stream
865  * operation otherwise. The pipeline state is not updated when the operation
866  * fails, except when stopping the pipeline.
867  */
868 int omap3isp_pipeline_set_stream(struct isp_pipeline *pipe,
869                                  enum isp_pipeline_stream_state state)
870 {
871         int ret;
872
873         if (state == ISP_PIPELINE_STREAM_STOPPED)
874                 ret = isp_pipeline_disable(pipe);
875         else
876                 ret = isp_pipeline_enable(pipe, state);
877
878         if (ret == 0 || state == ISP_PIPELINE_STREAM_STOPPED)
879                 pipe->stream_state = state;
880
881         return ret;
882 }
883
884 /*
885  * omap3isp_pipeline_cancel_stream - Cancel stream on a pipeline
886  * @pipe: ISP pipeline
887  *
888  * Cancelling a stream mark all buffers on all video nodes in the pipeline as
889  * erroneous and makes sure no new buffer can be queued. This function is called
890  * when a fatal error that prevents any further operation on the pipeline
891  * occurs.
892  */
893 void omap3isp_pipeline_cancel_stream(struct isp_pipeline *pipe)
894 {
895         if (pipe->input)
896                 omap3isp_video_cancel_stream(pipe->input);
897         if (pipe->output)
898                 omap3isp_video_cancel_stream(pipe->output);
899 }
900
901 /*
902  * isp_pipeline_resume - Resume streaming on a pipeline
903  * @pipe: ISP pipeline
904  *
905  * Resume video output and input and re-enable pipeline.
906  */
907 static void isp_pipeline_resume(struct isp_pipeline *pipe)
908 {
909         int singleshot = pipe->stream_state == ISP_PIPELINE_STREAM_SINGLESHOT;
910
911         omap3isp_video_resume(pipe->output, !singleshot);
912         if (singleshot)
913                 omap3isp_video_resume(pipe->input, 0);
914         isp_pipeline_enable(pipe, pipe->stream_state);
915 }
916
917 /*
918  * isp_pipeline_suspend - Suspend streaming on a pipeline
919  * @pipe: ISP pipeline
920  *
921  * Suspend pipeline.
922  */
923 static void isp_pipeline_suspend(struct isp_pipeline *pipe)
924 {
925         isp_pipeline_disable(pipe);
926 }
927
928 /*
929  * isp_pipeline_is_last - Verify if entity has an enabled link to the output
930  *                        video node
931  * @me: ISP module's media entity
932  *
933  * Returns 1 if the entity has an enabled link to the output video node or 0
934  * otherwise. It's true only while pipeline can have no more than one output
935  * node.
936  */
937 static int isp_pipeline_is_last(struct media_entity *me)
938 {
939         struct isp_pipeline *pipe;
940         struct media_pad *pad;
941
942         if (!me->pipe)
943                 return 0;
944         pipe = to_isp_pipeline(me);
945         if (pipe->stream_state == ISP_PIPELINE_STREAM_STOPPED)
946                 return 0;
947         pad = media_entity_remote_pad(&pipe->output->pad);
948         return pad->entity == me;
949 }
950
951 /*
952  * isp_suspend_module_pipeline - Suspend pipeline to which belongs the module
953  * @me: ISP module's media entity
954  *
955  * Suspend the whole pipeline if module's entity has an enabled link to the
956  * output video node. It works only while pipeline can have no more than one
957  * output node.
958  */
959 static void isp_suspend_module_pipeline(struct media_entity *me)
960 {
961         if (isp_pipeline_is_last(me))
962                 isp_pipeline_suspend(to_isp_pipeline(me));
963 }
964
965 /*
966  * isp_resume_module_pipeline - Resume pipeline to which belongs the module
967  * @me: ISP module's media entity
968  *
969  * Resume the whole pipeline if module's entity has an enabled link to the
970  * output video node. It works only while pipeline can have no more than one
971  * output node.
972  */
973 static void isp_resume_module_pipeline(struct media_entity *me)
974 {
975         if (isp_pipeline_is_last(me))
976                 isp_pipeline_resume(to_isp_pipeline(me));
977 }
978
979 /*
980  * isp_suspend_modules - Suspend ISP submodules.
981  * @isp: OMAP3 ISP device
982  *
983  * Returns 0 if suspend left in idle state all the submodules properly,
984  * or returns 1 if a general Reset is required to suspend the submodules.
985  */
986 static int isp_suspend_modules(struct isp_device *isp)
987 {
988         unsigned long timeout;
989
990         omap3isp_stat_suspend(&isp->isp_aewb);
991         omap3isp_stat_suspend(&isp->isp_af);
992         omap3isp_stat_suspend(&isp->isp_hist);
993         isp_suspend_module_pipeline(&isp->isp_res.subdev.entity);
994         isp_suspend_module_pipeline(&isp->isp_prev.subdev.entity);
995         isp_suspend_module_pipeline(&isp->isp_ccdc.subdev.entity);
996         isp_suspend_module_pipeline(&isp->isp_csi2a.subdev.entity);
997         isp_suspend_module_pipeline(&isp->isp_ccp2.subdev.entity);
998
999         timeout = jiffies + ISP_STOP_TIMEOUT;
1000         while (omap3isp_stat_busy(&isp->isp_af)
1001             || omap3isp_stat_busy(&isp->isp_aewb)
1002             || omap3isp_stat_busy(&isp->isp_hist)
1003             || omap3isp_preview_busy(&isp->isp_prev)
1004             || omap3isp_resizer_busy(&isp->isp_res)
1005             || omap3isp_ccdc_busy(&isp->isp_ccdc)) {
1006                 if (time_after(jiffies, timeout)) {
1007                         dev_info(isp->dev, "can't stop modules.\n");
1008                         return 1;
1009                 }
1010                 msleep(1);
1011         }
1012
1013         return 0;
1014 }
1015
1016 /*
1017  * isp_resume_modules - Resume ISP submodules.
1018  * @isp: OMAP3 ISP device
1019  */
1020 static void isp_resume_modules(struct isp_device *isp)
1021 {
1022         omap3isp_stat_resume(&isp->isp_aewb);
1023         omap3isp_stat_resume(&isp->isp_af);
1024         omap3isp_stat_resume(&isp->isp_hist);
1025         isp_resume_module_pipeline(&isp->isp_res.subdev.entity);
1026         isp_resume_module_pipeline(&isp->isp_prev.subdev.entity);
1027         isp_resume_module_pipeline(&isp->isp_ccdc.subdev.entity);
1028         isp_resume_module_pipeline(&isp->isp_csi2a.subdev.entity);
1029         isp_resume_module_pipeline(&isp->isp_ccp2.subdev.entity);
1030 }
1031
1032 /*
1033  * isp_reset - Reset ISP with a timeout wait for idle.
1034  * @isp: OMAP3 ISP device
1035  */
1036 static int isp_reset(struct isp_device *isp)
1037 {
1038         unsigned long timeout = 0;
1039
1040         isp_reg_writel(isp,
1041                        isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG)
1042                        | ISP_SYSCONFIG_SOFTRESET,
1043                        OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG);
1044         while (!(isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN,
1045                                ISP_SYSSTATUS) & 0x1)) {
1046                 if (timeout++ > 10000) {
1047                         dev_alert(isp->dev, "cannot reset ISP\n");
1048                         return -ETIMEDOUT;
1049                 }
1050                 udelay(1);
1051         }
1052
1053         isp->stop_failure = false;
1054         media_entity_enum_zero(&isp->crashed);
1055         return 0;
1056 }
1057
1058 /*
1059  * isp_save_context - Saves the values of the ISP module registers.
1060  * @isp: OMAP3 ISP device
1061  * @reg_list: Structure containing pairs of register address and value to
1062  *            modify on OMAP.
1063  */
1064 static void
1065 isp_save_context(struct isp_device *isp, struct isp_reg *reg_list)
1066 {
1067         struct isp_reg *next = reg_list;
1068
1069         for (; next->reg != ISP_TOK_TERM; next++)
1070                 next->val = isp_reg_readl(isp, next->mmio_range, next->reg);
1071 }
1072
1073 /*
1074  * isp_restore_context - Restores the values of the ISP module registers.
1075  * @isp: OMAP3 ISP device
1076  * @reg_list: Structure containing pairs of register address and value to
1077  *            modify on OMAP.
1078  */
1079 static void
1080 isp_restore_context(struct isp_device *isp, struct isp_reg *reg_list)
1081 {
1082         struct isp_reg *next = reg_list;
1083
1084         for (; next->reg != ISP_TOK_TERM; next++)
1085                 isp_reg_writel(isp, next->val, next->mmio_range, next->reg);
1086 }
1087
1088 /*
1089  * isp_save_ctx - Saves ISP, CCDC, HIST, H3A, PREV, RESZ & MMU context.
1090  * @isp: OMAP3 ISP device
1091  *
1092  * Routine for saving the context of each module in the ISP.
1093  * CCDC, HIST, H3A, PREV, RESZ and MMU.
1094  */
1095 static void isp_save_ctx(struct isp_device *isp)
1096 {
1097         isp_save_context(isp, isp_reg_list);
1098         omap_iommu_save_ctx(isp->dev);
1099 }
1100
1101 /*
1102  * isp_restore_ctx - Restores ISP, CCDC, HIST, H3A, PREV, RESZ & MMU context.
1103  * @isp: OMAP3 ISP device
1104  *
1105  * Routine for restoring the context of each module in the ISP.
1106  * CCDC, HIST, H3A, PREV, RESZ and MMU.
1107  */
1108 static void isp_restore_ctx(struct isp_device *isp)
1109 {
1110         isp_restore_context(isp, isp_reg_list);
1111         omap_iommu_restore_ctx(isp->dev);
1112         omap3isp_ccdc_restore_context(isp);
1113         omap3isp_preview_restore_context(isp);
1114 }
1115
1116 /* -----------------------------------------------------------------------------
1117  * SBL resources management
1118  */
1119 #define OMAP3_ISP_SBL_READ      (OMAP3_ISP_SBL_CSI1_READ | \
1120                                  OMAP3_ISP_SBL_CCDC_LSC_READ | \
1121                                  OMAP3_ISP_SBL_PREVIEW_READ | \
1122                                  OMAP3_ISP_SBL_RESIZER_READ)
1123 #define OMAP3_ISP_SBL_WRITE     (OMAP3_ISP_SBL_CSI1_WRITE | \
1124                                  OMAP3_ISP_SBL_CSI2A_WRITE | \
1125                                  OMAP3_ISP_SBL_CSI2C_WRITE | \
1126                                  OMAP3_ISP_SBL_CCDC_WRITE | \
1127                                  OMAP3_ISP_SBL_PREVIEW_WRITE)
1128
1129 void omap3isp_sbl_enable(struct isp_device *isp, enum isp_sbl_resource res)
1130 {
1131         u32 sbl = 0;
1132
1133         isp->sbl_resources |= res;
1134
1135         if (isp->sbl_resources & OMAP3_ISP_SBL_CSI1_READ)
1136                 sbl |= ISPCTRL_SBL_SHARED_RPORTA;
1137
1138         if (isp->sbl_resources & OMAP3_ISP_SBL_CCDC_LSC_READ)
1139                 sbl |= ISPCTRL_SBL_SHARED_RPORTB;
1140
1141         if (isp->sbl_resources & OMAP3_ISP_SBL_CSI2C_WRITE)
1142                 sbl |= ISPCTRL_SBL_SHARED_WPORTC;
1143
1144         if (isp->sbl_resources & OMAP3_ISP_SBL_RESIZER_WRITE)
1145                 sbl |= ISPCTRL_SBL_WR0_RAM_EN;
1146
1147         if (isp->sbl_resources & OMAP3_ISP_SBL_WRITE)
1148                 sbl |= ISPCTRL_SBL_WR1_RAM_EN;
1149
1150         if (isp->sbl_resources & OMAP3_ISP_SBL_READ)
1151                 sbl |= ISPCTRL_SBL_RD_RAM_EN;
1152
1153         isp_reg_set(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL, sbl);
1154 }
1155
1156 void omap3isp_sbl_disable(struct isp_device *isp, enum isp_sbl_resource res)
1157 {
1158         u32 sbl = 0;
1159
1160         isp->sbl_resources &= ~res;
1161
1162         if (!(isp->sbl_resources & OMAP3_ISP_SBL_CSI1_READ))
1163                 sbl |= ISPCTRL_SBL_SHARED_RPORTA;
1164
1165         if (!(isp->sbl_resources & OMAP3_ISP_SBL_CCDC_LSC_READ))
1166                 sbl |= ISPCTRL_SBL_SHARED_RPORTB;
1167
1168         if (!(isp->sbl_resources & OMAP3_ISP_SBL_CSI2C_WRITE))
1169                 sbl |= ISPCTRL_SBL_SHARED_WPORTC;
1170
1171         if (!(isp->sbl_resources & OMAP3_ISP_SBL_RESIZER_WRITE))
1172                 sbl |= ISPCTRL_SBL_WR0_RAM_EN;
1173
1174         if (!(isp->sbl_resources & OMAP3_ISP_SBL_WRITE))
1175                 sbl |= ISPCTRL_SBL_WR1_RAM_EN;
1176
1177         if (!(isp->sbl_resources & OMAP3_ISP_SBL_READ))
1178                 sbl |= ISPCTRL_SBL_RD_RAM_EN;
1179
1180         isp_reg_clr(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL, sbl);
1181 }
1182
1183 /*
1184  * isp_module_sync_idle - Helper to sync module with its idle state
1185  * @me: ISP submodule's media entity
1186  * @wait: ISP submodule's wait queue for streamoff/interrupt synchronization
1187  * @stopping: flag which tells module wants to stop
1188  *
1189  * This function checks if ISP submodule needs to wait for next interrupt. If
1190  * yes, makes the caller to sleep while waiting for such event.
1191  */
1192 int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
1193                               atomic_t *stopping)
1194 {
1195         struct isp_pipeline *pipe = to_isp_pipeline(me);
1196
1197         if (pipe->stream_state == ISP_PIPELINE_STREAM_STOPPED ||
1198             (pipe->stream_state == ISP_PIPELINE_STREAM_SINGLESHOT &&
1199              !isp_pipeline_ready(pipe)))
1200                 return 0;
1201
1202         /*
1203          * atomic_set() doesn't include memory barrier on ARM platform for SMP
1204          * scenario. We'll call it here to avoid race conditions.
1205          */
1206         atomic_set(stopping, 1);
1207         smp_mb();
1208
1209         /*
1210          * If module is the last one, it's writing to memory. In this case,
1211          * it's necessary to check if the module is already paused due to
1212          * DMA queue underrun or if it has to wait for next interrupt to be
1213          * idle.
1214          * If it isn't the last one, the function won't sleep but *stopping
1215          * will still be set to warn next submodule caller's interrupt the
1216          * module wants to be idle.
1217          */
1218         if (isp_pipeline_is_last(me)) {
1219                 struct isp_video *video = pipe->output;
1220                 unsigned long flags;
1221                 spin_lock_irqsave(&video->irqlock, flags);
1222                 if (video->dmaqueue_flags & ISP_VIDEO_DMAQUEUE_UNDERRUN) {
1223                         spin_unlock_irqrestore(&video->irqlock, flags);
1224                         atomic_set(stopping, 0);
1225                         smp_mb();
1226                         return 0;
1227                 }
1228                 spin_unlock_irqrestore(&video->irqlock, flags);
1229                 if (!wait_event_timeout(*wait, !atomic_read(stopping),
1230                                         msecs_to_jiffies(1000))) {
1231                         atomic_set(stopping, 0);
1232                         smp_mb();
1233                         return -ETIMEDOUT;
1234                 }
1235         }
1236
1237         return 0;
1238 }
1239
1240 /*
1241  * omap3isp_module_sync_is_stopping - Helper to verify if module was stopping
1242  * @wait: ISP submodule's wait queue for streamoff/interrupt synchronization
1243  * @stopping: flag which tells module wants to stop
1244  *
1245  * This function checks if ISP submodule was stopping. In case of yes, it
1246  * notices the caller by setting stopping to 0 and waking up the wait queue.
1247  * Returns 1 if it was stopping or 0 otherwise.
1248  */
1249 int omap3isp_module_sync_is_stopping(wait_queue_head_t *wait,
1250                                      atomic_t *stopping)
1251 {
1252         if (atomic_cmpxchg(stopping, 1, 0)) {
1253                 wake_up(wait);
1254                 return 1;
1255         }
1256
1257         return 0;
1258 }
1259
1260 /* --------------------------------------------------------------------------
1261  * Clock management
1262  */
1263
1264 #define ISPCTRL_CLKS_MASK       (ISPCTRL_H3A_CLK_EN | \
1265                                  ISPCTRL_HIST_CLK_EN | \
1266                                  ISPCTRL_RSZ_CLK_EN | \
1267                                  (ISPCTRL_CCDC_CLK_EN | ISPCTRL_CCDC_RAM_EN) | \
1268                                  (ISPCTRL_PREV_CLK_EN | ISPCTRL_PREV_RAM_EN))
1269
1270 static void __isp_subclk_update(struct isp_device *isp)
1271 {
1272         u32 clk = 0;
1273
1274         /* AEWB and AF share the same clock. */
1275         if (isp->subclk_resources &
1276             (OMAP3_ISP_SUBCLK_AEWB | OMAP3_ISP_SUBCLK_AF))
1277                 clk |= ISPCTRL_H3A_CLK_EN;
1278
1279         if (isp->subclk_resources & OMAP3_ISP_SUBCLK_HIST)
1280                 clk |= ISPCTRL_HIST_CLK_EN;
1281
1282         if (isp->subclk_resources & OMAP3_ISP_SUBCLK_RESIZER)
1283                 clk |= ISPCTRL_RSZ_CLK_EN;
1284
1285         /* NOTE: For CCDC & Preview submodules, we need to affect internal
1286          *       RAM as well.
1287          */
1288         if (isp->subclk_resources & OMAP3_ISP_SUBCLK_CCDC)
1289                 clk |= ISPCTRL_CCDC_CLK_EN | ISPCTRL_CCDC_RAM_EN;
1290
1291         if (isp->subclk_resources & OMAP3_ISP_SUBCLK_PREVIEW)
1292                 clk |= ISPCTRL_PREV_CLK_EN | ISPCTRL_PREV_RAM_EN;
1293
1294         isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL,
1295                         ISPCTRL_CLKS_MASK, clk);
1296 }
1297
1298 void omap3isp_subclk_enable(struct isp_device *isp,
1299                             enum isp_subclk_resource res)
1300 {
1301         isp->subclk_resources |= res;
1302
1303         __isp_subclk_update(isp);
1304 }
1305
1306 void omap3isp_subclk_disable(struct isp_device *isp,
1307                              enum isp_subclk_resource res)
1308 {
1309         isp->subclk_resources &= ~res;
1310
1311         __isp_subclk_update(isp);
1312 }
1313
1314 /*
1315  * isp_enable_clocks - Enable ISP clocks
1316  * @isp: OMAP3 ISP device
1317  *
1318  * Return 0 if successful, or clk_prepare_enable return value if any of them
1319  * fails.
1320  */
1321 static int isp_enable_clocks(struct isp_device *isp)
1322 {
1323         int r;
1324         unsigned long rate;
1325
1326         r = clk_prepare_enable(isp->clock[ISP_CLK_CAM_ICK]);
1327         if (r) {
1328                 dev_err(isp->dev, "failed to enable cam_ick clock\n");
1329                 goto out_clk_enable_ick;
1330         }
1331         r = clk_set_rate(isp->clock[ISP_CLK_CAM_MCLK], CM_CAM_MCLK_HZ);
1332         if (r) {
1333                 dev_err(isp->dev, "clk_set_rate for cam_mclk failed\n");
1334                 goto out_clk_enable_mclk;
1335         }
1336         r = clk_prepare_enable(isp->clock[ISP_CLK_CAM_MCLK]);
1337         if (r) {
1338                 dev_err(isp->dev, "failed to enable cam_mclk clock\n");
1339                 goto out_clk_enable_mclk;
1340         }
1341         rate = clk_get_rate(isp->clock[ISP_CLK_CAM_MCLK]);
1342         if (rate != CM_CAM_MCLK_HZ)
1343                 dev_warn(isp->dev, "unexpected cam_mclk rate:\n"
1344                                    " expected : %d\n"
1345                                    " actual   : %ld\n", CM_CAM_MCLK_HZ, rate);
1346         r = clk_prepare_enable(isp->clock[ISP_CLK_CSI2_FCK]);
1347         if (r) {
1348                 dev_err(isp->dev, "failed to enable csi2_fck clock\n");
1349                 goto out_clk_enable_csi2_fclk;
1350         }
1351         return 0;
1352
1353 out_clk_enable_csi2_fclk:
1354         clk_disable_unprepare(isp->clock[ISP_CLK_CAM_MCLK]);
1355 out_clk_enable_mclk:
1356         clk_disable_unprepare(isp->clock[ISP_CLK_CAM_ICK]);
1357 out_clk_enable_ick:
1358         return r;
1359 }
1360
1361 /*
1362  * isp_disable_clocks - Disable ISP clocks
1363  * @isp: OMAP3 ISP device
1364  */
1365 static void isp_disable_clocks(struct isp_device *isp)
1366 {
1367         clk_disable_unprepare(isp->clock[ISP_CLK_CAM_ICK]);
1368         clk_disable_unprepare(isp->clock[ISP_CLK_CAM_MCLK]);
1369         clk_disable_unprepare(isp->clock[ISP_CLK_CSI2_FCK]);
1370 }
1371
1372 static const char *isp_clocks[] = {
1373         "cam_ick",
1374         "cam_mclk",
1375         "csi2_96m_fck",
1376         "l3_ick",
1377 };
1378
1379 static int isp_get_clocks(struct isp_device *isp)
1380 {
1381         struct clk *clk;
1382         unsigned int i;
1383
1384         for (i = 0; i < ARRAY_SIZE(isp_clocks); ++i) {
1385                 clk = devm_clk_get(isp->dev, isp_clocks[i]);
1386                 if (IS_ERR(clk)) {
1387                         dev_err(isp->dev, "clk_get %s failed\n", isp_clocks[i]);
1388                         return PTR_ERR(clk);
1389                 }
1390
1391                 isp->clock[i] = clk;
1392         }
1393
1394         return 0;
1395 }
1396
1397 /*
1398  * omap3isp_get - Acquire the ISP resource.
1399  *
1400  * Initializes the clocks for the first acquire.
1401  *
1402  * Increment the reference count on the ISP. If the first reference is taken,
1403  * enable clocks and power-up all submodules.
1404  *
1405  * Return a pointer to the ISP device structure, or NULL if an error occurred.
1406  */
1407 static struct isp_device *__omap3isp_get(struct isp_device *isp, bool irq)
1408 {
1409         struct isp_device *__isp = isp;
1410
1411         if (isp == NULL)
1412                 return NULL;
1413
1414         mutex_lock(&isp->isp_mutex);
1415         if (isp->ref_count > 0)
1416                 goto out;
1417
1418         if (isp_enable_clocks(isp) < 0) {
1419                 __isp = NULL;
1420                 goto out;
1421         }
1422
1423         /* We don't want to restore context before saving it! */
1424         if (isp->has_context)
1425                 isp_restore_ctx(isp);
1426
1427         if (irq)
1428                 isp_enable_interrupts(isp);
1429
1430 out:
1431         if (__isp != NULL)
1432                 isp->ref_count++;
1433         mutex_unlock(&isp->isp_mutex);
1434
1435         return __isp;
1436 }
1437
1438 struct isp_device *omap3isp_get(struct isp_device *isp)
1439 {
1440         return __omap3isp_get(isp, true);
1441 }
1442
1443 /*
1444  * omap3isp_put - Release the ISP
1445  *
1446  * Decrement the reference count on the ISP. If the last reference is released,
1447  * power-down all submodules, disable clocks and free temporary buffers.
1448  */
1449 static void __omap3isp_put(struct isp_device *isp, bool save_ctx)
1450 {
1451         if (isp == NULL)
1452                 return;
1453
1454         mutex_lock(&isp->isp_mutex);
1455         BUG_ON(isp->ref_count == 0);
1456         if (--isp->ref_count == 0) {
1457                 isp_disable_interrupts(isp);
1458                 if (save_ctx) {
1459                         isp_save_ctx(isp);
1460                         isp->has_context = 1;
1461                 }
1462                 /* Reset the ISP if an entity has failed to stop. This is the
1463                  * only way to recover from such conditions.
1464                  */
1465                 if (!media_entity_enum_empty(&isp->crashed) ||
1466                     isp->stop_failure)
1467                         isp_reset(isp);
1468                 isp_disable_clocks(isp);
1469         }
1470         mutex_unlock(&isp->isp_mutex);
1471 }
1472
1473 void omap3isp_put(struct isp_device *isp)
1474 {
1475         __omap3isp_put(isp, true);
1476 }
1477
1478 /* --------------------------------------------------------------------------
1479  * Platform device driver
1480  */
1481
1482 /*
1483  * omap3isp_print_status - Prints the values of the ISP Control Module registers
1484  * @isp: OMAP3 ISP device
1485  */
1486 #define ISP_PRINT_REGISTER(isp, name)\
1487         dev_dbg(isp->dev, "###ISP " #name "=0x%08x\n", \
1488                 isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_##name))
1489 #define SBL_PRINT_REGISTER(isp, name)\
1490         dev_dbg(isp->dev, "###SBL " #name "=0x%08x\n", \
1491                 isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_##name))
1492
1493 void omap3isp_print_status(struct isp_device *isp)
1494 {
1495         dev_dbg(isp->dev, "-------------ISP Register dump--------------\n");
1496
1497         ISP_PRINT_REGISTER(isp, SYSCONFIG);
1498         ISP_PRINT_REGISTER(isp, SYSSTATUS);
1499         ISP_PRINT_REGISTER(isp, IRQ0ENABLE);
1500         ISP_PRINT_REGISTER(isp, IRQ0STATUS);
1501         ISP_PRINT_REGISTER(isp, TCTRL_GRESET_LENGTH);
1502         ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_REPLAY);
1503         ISP_PRINT_REGISTER(isp, CTRL);
1504         ISP_PRINT_REGISTER(isp, TCTRL_CTRL);
1505         ISP_PRINT_REGISTER(isp, TCTRL_FRAME);
1506         ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_DELAY);
1507         ISP_PRINT_REGISTER(isp, TCTRL_STRB_DELAY);
1508         ISP_PRINT_REGISTER(isp, TCTRL_SHUT_DELAY);
1509         ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_LENGTH);
1510         ISP_PRINT_REGISTER(isp, TCTRL_STRB_LENGTH);
1511         ISP_PRINT_REGISTER(isp, TCTRL_SHUT_LENGTH);
1512
1513         SBL_PRINT_REGISTER(isp, PCR);
1514         SBL_PRINT_REGISTER(isp, SDR_REQ_EXP);
1515
1516         dev_dbg(isp->dev, "--------------------------------------------\n");
1517 }
1518
1519 #ifdef CONFIG_PM
1520
1521 /*
1522  * Power management support.
1523  *
1524  * As the ISP can't properly handle an input video stream interruption on a non
1525  * frame boundary, the ISP pipelines need to be stopped before sensors get
1526  * suspended. However, as suspending the sensors can require a running clock,
1527  * which can be provided by the ISP, the ISP can't be completely suspended
1528  * before the sensor.
1529  *
1530  * To solve this problem power management support is split into prepare/complete
1531  * and suspend/resume operations. The pipelines are stopped in prepare() and the
1532  * ISP clocks get disabled in suspend(). Similarly, the clocks are reenabled in
1533  * resume(), and the the pipelines are restarted in complete().
1534  *
1535  * TODO: PM dependencies between the ISP and sensors are not modelled explicitly
1536  * yet.
1537  */
1538 static int isp_pm_prepare(struct device *dev)
1539 {
1540         struct isp_device *isp = dev_get_drvdata(dev);
1541         int reset;
1542
1543         WARN_ON(mutex_is_locked(&isp->isp_mutex));
1544
1545         if (isp->ref_count == 0)
1546                 return 0;
1547
1548         reset = isp_suspend_modules(isp);
1549         isp_disable_interrupts(isp);
1550         isp_save_ctx(isp);
1551         if (reset)
1552                 isp_reset(isp);
1553
1554         return 0;
1555 }
1556
1557 static int isp_pm_suspend(struct device *dev)
1558 {
1559         struct isp_device *isp = dev_get_drvdata(dev);
1560
1561         WARN_ON(mutex_is_locked(&isp->isp_mutex));
1562
1563         if (isp->ref_count)
1564                 isp_disable_clocks(isp);
1565
1566         return 0;
1567 }
1568
1569 static int isp_pm_resume(struct device *dev)
1570 {
1571         struct isp_device *isp = dev_get_drvdata(dev);
1572
1573         if (isp->ref_count == 0)
1574                 return 0;
1575
1576         return isp_enable_clocks(isp);
1577 }
1578
1579 static void isp_pm_complete(struct device *dev)
1580 {
1581         struct isp_device *isp = dev_get_drvdata(dev);
1582
1583         if (isp->ref_count == 0)
1584                 return;
1585
1586         isp_restore_ctx(isp);
1587         isp_enable_interrupts(isp);
1588         isp_resume_modules(isp);
1589 }
1590
1591 #else
1592
1593 #define isp_pm_prepare  NULL
1594 #define isp_pm_suspend  NULL
1595 #define isp_pm_resume   NULL
1596 #define isp_pm_complete NULL
1597
1598 #endif /* CONFIG_PM */
1599
1600 static void isp_unregister_entities(struct isp_device *isp)
1601 {
1602         media_device_unregister(&isp->media_dev);
1603
1604         omap3isp_csi2_unregister_entities(&isp->isp_csi2a);
1605         omap3isp_ccp2_unregister_entities(&isp->isp_ccp2);
1606         omap3isp_ccdc_unregister_entities(&isp->isp_ccdc);
1607         omap3isp_preview_unregister_entities(&isp->isp_prev);
1608         omap3isp_resizer_unregister_entities(&isp->isp_res);
1609         omap3isp_stat_unregister_entities(&isp->isp_aewb);
1610         omap3isp_stat_unregister_entities(&isp->isp_af);
1611         omap3isp_stat_unregister_entities(&isp->isp_hist);
1612
1613         v4l2_device_unregister(&isp->v4l2_dev);
1614         media_device_cleanup(&isp->media_dev);
1615 }
1616
1617 static int isp_link_entity(
1618         struct isp_device *isp, struct media_entity *entity,
1619         enum isp_interface_type interface)
1620 {
1621         struct media_entity *input;
1622         unsigned int flags;
1623         unsigned int pad;
1624         unsigned int i;
1625
1626         /* Connect the sensor to the correct interface module.
1627          * Parallel sensors are connected directly to the CCDC, while
1628          * serial sensors are connected to the CSI2a, CCP2b or CSI2c
1629          * receiver through CSIPHY1 or CSIPHY2.
1630          */
1631         switch (interface) {
1632         case ISP_INTERFACE_PARALLEL:
1633                 input = &isp->isp_ccdc.subdev.entity;
1634                 pad = CCDC_PAD_SINK;
1635                 flags = 0;
1636                 break;
1637
1638         case ISP_INTERFACE_CSI2A_PHY2:
1639                 input = &isp->isp_csi2a.subdev.entity;
1640                 pad = CSI2_PAD_SINK;
1641                 flags = MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED;
1642                 break;
1643
1644         case ISP_INTERFACE_CCP2B_PHY1:
1645         case ISP_INTERFACE_CCP2B_PHY2:
1646                 input = &isp->isp_ccp2.subdev.entity;
1647                 pad = CCP2_PAD_SINK;
1648                 flags = 0;
1649                 break;
1650
1651         case ISP_INTERFACE_CSI2C_PHY1:
1652                 input = &isp->isp_csi2c.subdev.entity;
1653                 pad = CSI2_PAD_SINK;
1654                 flags = MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED;
1655                 break;
1656
1657         default:
1658                 dev_err(isp->dev, "%s: invalid interface type %u\n", __func__,
1659                         interface);
1660                 return -EINVAL;
1661         }
1662
1663         /*
1664          * Not all interfaces are available on all revisions of the
1665          * ISP. The sub-devices of those interfaces aren't initialised
1666          * in such a case. Check this by ensuring the num_pads is
1667          * non-zero.
1668          */
1669         if (!input->num_pads) {
1670                 dev_err(isp->dev, "%s: invalid input %u\n", entity->name,
1671                         interface);
1672                 return -EINVAL;
1673         }
1674
1675         for (i = 0; i < entity->num_pads; i++) {
1676                 if (entity->pads[i].flags & MEDIA_PAD_FL_SOURCE)
1677                         break;
1678         }
1679         if (i == entity->num_pads) {
1680                 dev_err(isp->dev, "%s: no source pad in external entity\n",
1681                         __func__);
1682                 return -EINVAL;
1683         }
1684
1685         return media_create_pad_link(entity, i, input, pad, flags);
1686 }
1687
1688 static int isp_register_entities(struct isp_device *isp)
1689 {
1690         int ret;
1691
1692         isp->media_dev.dev = isp->dev;
1693         strlcpy(isp->media_dev.model, "TI OMAP3 ISP",
1694                 sizeof(isp->media_dev.model));
1695         isp->media_dev.hw_revision = isp->revision;
1696         isp->media_dev.ops = &isp_media_ops;
1697         media_device_init(&isp->media_dev);
1698
1699         isp->v4l2_dev.mdev = &isp->media_dev;
1700         ret = v4l2_device_register(isp->dev, &isp->v4l2_dev);
1701         if (ret < 0) {
1702                 dev_err(isp->dev, "%s: V4L2 device registration failed (%d)\n",
1703                         __func__, ret);
1704                 goto done;
1705         }
1706
1707         /* Register internal entities */
1708         ret = omap3isp_ccp2_register_entities(&isp->isp_ccp2, &isp->v4l2_dev);
1709         if (ret < 0)
1710                 goto done;
1711
1712         ret = omap3isp_csi2_register_entities(&isp->isp_csi2a, &isp->v4l2_dev);
1713         if (ret < 0)
1714                 goto done;
1715
1716         ret = omap3isp_ccdc_register_entities(&isp->isp_ccdc, &isp->v4l2_dev);
1717         if (ret < 0)
1718                 goto done;
1719
1720         ret = omap3isp_preview_register_entities(&isp->isp_prev,
1721                                                  &isp->v4l2_dev);
1722         if (ret < 0)
1723                 goto done;
1724
1725         ret = omap3isp_resizer_register_entities(&isp->isp_res, &isp->v4l2_dev);
1726         if (ret < 0)
1727                 goto done;
1728
1729         ret = omap3isp_stat_register_entities(&isp->isp_aewb, &isp->v4l2_dev);
1730         if (ret < 0)
1731                 goto done;
1732
1733         ret = omap3isp_stat_register_entities(&isp->isp_af, &isp->v4l2_dev);
1734         if (ret < 0)
1735                 goto done;
1736
1737         ret = omap3isp_stat_register_entities(&isp->isp_hist, &isp->v4l2_dev);
1738         if (ret < 0)
1739                 goto done;
1740
1741 done:
1742         if (ret < 0)
1743                 isp_unregister_entities(isp);
1744
1745         return ret;
1746 }
1747
1748 /*
1749  * isp_create_links() - Create links for internal and external ISP entities
1750  * @isp : Pointer to ISP device
1751  *
1752  * This function creates all links between ISP internal and external entities.
1753  *
1754  * Return: A negative error code on failure or zero on success. Possible error
1755  * codes are those returned by media_create_pad_link().
1756  */
1757 static int isp_create_links(struct isp_device *isp)
1758 {
1759         int ret;
1760
1761         /* Create links between entities and video nodes. */
1762         ret = media_create_pad_link(
1763                         &isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
1764                         &isp->isp_csi2a.video_out.video.entity, 0, 0);
1765         if (ret < 0)
1766                 return ret;
1767
1768         ret = media_create_pad_link(
1769                         &isp->isp_ccp2.video_in.video.entity, 0,
1770                         &isp->isp_ccp2.subdev.entity, CCP2_PAD_SINK, 0);
1771         if (ret < 0)
1772                 return ret;
1773
1774         ret = media_create_pad_link(
1775                         &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
1776                         &isp->isp_ccdc.video_out.video.entity, 0, 0);
1777         if (ret < 0)
1778                 return ret;
1779
1780         ret = media_create_pad_link(
1781                         &isp->isp_prev.video_in.video.entity, 0,
1782                         &isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
1783         if (ret < 0)
1784                 return ret;
1785
1786         ret = media_create_pad_link(
1787                         &isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
1788                         &isp->isp_prev.video_out.video.entity, 0, 0);
1789         if (ret < 0)
1790                 return ret;
1791
1792         ret = media_create_pad_link(
1793                         &isp->isp_res.video_in.video.entity, 0,
1794                         &isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
1795         if (ret < 0)
1796                 return ret;
1797
1798         ret = media_create_pad_link(
1799                         &isp->isp_res.subdev.entity, RESZ_PAD_SOURCE,
1800                         &isp->isp_res.video_out.video.entity, 0, 0);
1801
1802         if (ret < 0)
1803                 return ret;
1804
1805         /* Create links between entities. */
1806         ret = media_create_pad_link(
1807                         &isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
1808                         &isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
1809         if (ret < 0)
1810                 return ret;
1811
1812         ret = media_create_pad_link(
1813                         &isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
1814                         &isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
1815         if (ret < 0)
1816                 return ret;
1817
1818         ret = media_create_pad_link(
1819                         &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
1820                         &isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
1821         if (ret < 0)
1822                 return ret;
1823
1824         ret = media_create_pad_link(
1825                         &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
1826                         &isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
1827         if (ret < 0)
1828                 return ret;
1829
1830         ret = media_create_pad_link(
1831                         &isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
1832                         &isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
1833         if (ret < 0)
1834                 return ret;
1835
1836         ret = media_create_pad_link(
1837                         &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
1838                         &isp->isp_aewb.subdev.entity, 0,
1839                         MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
1840         if (ret < 0)
1841                 return ret;
1842
1843         ret = media_create_pad_link(
1844                         &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
1845                         &isp->isp_af.subdev.entity, 0,
1846                         MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
1847         if (ret < 0)
1848                 return ret;
1849
1850         ret = media_create_pad_link(
1851                         &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
1852                         &isp->isp_hist.subdev.entity, 0,
1853                         MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
1854         if (ret < 0)
1855                 return ret;
1856
1857         return 0;
1858 }
1859
1860 static void isp_cleanup_modules(struct isp_device *isp)
1861 {
1862         omap3isp_h3a_aewb_cleanup(isp);
1863         omap3isp_h3a_af_cleanup(isp);
1864         omap3isp_hist_cleanup(isp);
1865         omap3isp_resizer_cleanup(isp);
1866         omap3isp_preview_cleanup(isp);
1867         omap3isp_ccdc_cleanup(isp);
1868         omap3isp_ccp2_cleanup(isp);
1869         omap3isp_csi2_cleanup(isp);
1870 }
1871
1872 static int isp_initialize_modules(struct isp_device *isp)
1873 {
1874         int ret;
1875
1876         ret = omap3isp_csiphy_init(isp);
1877         if (ret < 0) {
1878                 dev_err(isp->dev, "CSI PHY initialization failed\n");
1879                 goto error_csiphy;
1880         }
1881
1882         ret = omap3isp_csi2_init(isp);
1883         if (ret < 0) {
1884                 dev_err(isp->dev, "CSI2 initialization failed\n");
1885                 goto error_csi2;
1886         }
1887
1888         ret = omap3isp_ccp2_init(isp);
1889         if (ret < 0) {
1890                 dev_err(isp->dev, "CCP2 initialization failed\n");
1891                 goto error_ccp2;
1892         }
1893
1894         ret = omap3isp_ccdc_init(isp);
1895         if (ret < 0) {
1896                 dev_err(isp->dev, "CCDC initialization failed\n");
1897                 goto error_ccdc;
1898         }
1899
1900         ret = omap3isp_preview_init(isp);
1901         if (ret < 0) {
1902                 dev_err(isp->dev, "Preview initialization failed\n");
1903                 goto error_preview;
1904         }
1905
1906         ret = omap3isp_resizer_init(isp);
1907         if (ret < 0) {
1908                 dev_err(isp->dev, "Resizer initialization failed\n");
1909                 goto error_resizer;
1910         }
1911
1912         ret = omap3isp_hist_init(isp);
1913         if (ret < 0) {
1914                 dev_err(isp->dev, "Histogram initialization failed\n");
1915                 goto error_hist;
1916         }
1917
1918         ret = omap3isp_h3a_aewb_init(isp);
1919         if (ret < 0) {
1920                 dev_err(isp->dev, "H3A AEWB initialization failed\n");
1921                 goto error_h3a_aewb;
1922         }
1923
1924         ret = omap3isp_h3a_af_init(isp);
1925         if (ret < 0) {
1926                 dev_err(isp->dev, "H3A AF initialization failed\n");
1927                 goto error_h3a_af;
1928         }
1929
1930         return 0;
1931
1932 error_h3a_af:
1933         omap3isp_h3a_aewb_cleanup(isp);
1934 error_h3a_aewb:
1935         omap3isp_hist_cleanup(isp);
1936 error_hist:
1937         omap3isp_resizer_cleanup(isp);
1938 error_resizer:
1939         omap3isp_preview_cleanup(isp);
1940 error_preview:
1941         omap3isp_ccdc_cleanup(isp);
1942 error_ccdc:
1943         omap3isp_ccp2_cleanup(isp);
1944 error_ccp2:
1945         omap3isp_csi2_cleanup(isp);
1946 error_csi2:
1947 error_csiphy:
1948         return ret;
1949 }
1950
1951 static void isp_detach_iommu(struct isp_device *isp)
1952 {
1953         arm_iommu_detach_device(isp->dev);
1954         arm_iommu_release_mapping(isp->mapping);
1955         isp->mapping = NULL;
1956         iommu_group_remove_device(isp->dev);
1957 }
1958
1959 static int isp_attach_iommu(struct isp_device *isp)
1960 {
1961         struct dma_iommu_mapping *mapping;
1962         struct iommu_group *group;
1963         int ret;
1964
1965         /* Create a device group and add the device to it. */
1966         group = iommu_group_alloc();
1967         if (IS_ERR(group)) {
1968                 dev_err(isp->dev, "failed to allocate IOMMU group\n");
1969                 return PTR_ERR(group);
1970         }
1971
1972         ret = iommu_group_add_device(group, isp->dev);
1973         iommu_group_put(group);
1974
1975         if (ret < 0) {
1976                 dev_err(isp->dev, "failed to add device to IPMMU group\n");
1977                 return ret;
1978         }
1979
1980         /*
1981          * Create the ARM mapping, used by the ARM DMA mapping core to allocate
1982          * VAs. This will allocate a corresponding IOMMU domain.
1983          */
1984         mapping = arm_iommu_create_mapping(&platform_bus_type, SZ_1G, SZ_2G);
1985         if (IS_ERR(mapping)) {
1986                 dev_err(isp->dev, "failed to create ARM IOMMU mapping\n");
1987                 return PTR_ERR(mapping);
1988         }
1989
1990         isp->mapping = mapping;
1991
1992         /* Attach the ARM VA mapping to the device. */
1993         ret = arm_iommu_attach_device(isp->dev, mapping);
1994         if (ret < 0) {
1995                 dev_err(isp->dev, "failed to attach device to VA mapping\n");
1996                 goto error;
1997         }
1998
1999         return 0;
2000
2001 error:
2002         arm_iommu_release_mapping(isp->mapping);
2003         isp->mapping = NULL;
2004         return ret;
2005 }
2006
2007 /*
2008  * isp_remove - Remove ISP platform device
2009  * @pdev: Pointer to ISP platform device
2010  *
2011  * Always returns 0.
2012  */
2013 static int isp_remove(struct platform_device *pdev)
2014 {
2015         struct isp_device *isp = platform_get_drvdata(pdev);
2016
2017         v4l2_async_notifier_unregister(&isp->notifier);
2018         isp_unregister_entities(isp);
2019         isp_cleanup_modules(isp);
2020         isp_xclk_cleanup(isp);
2021
2022         __omap3isp_get(isp, false);
2023         isp_detach_iommu(isp);
2024         __omap3isp_put(isp, false);
2025
2026         media_entity_enum_cleanup(&isp->crashed);
2027
2028         return 0;
2029 }
2030
2031 enum isp_of_phy {
2032         ISP_OF_PHY_PARALLEL = 0,
2033         ISP_OF_PHY_CSIPHY1,
2034         ISP_OF_PHY_CSIPHY2,
2035 };
2036
2037 static int isp_of_parse_node(struct device *dev, struct device_node *node,
2038                              struct isp_async_subdev *isd)
2039 {
2040         struct isp_bus_cfg *buscfg = &isd->bus;
2041         struct v4l2_of_endpoint vep;
2042         unsigned int i;
2043         int ret;
2044
2045         ret = v4l2_of_parse_endpoint(node, &vep);
2046         if (ret)
2047                 return ret;
2048
2049         dev_dbg(dev, "parsing endpoint %s, interface %u\n", node->full_name,
2050                 vep.base.port);
2051
2052         switch (vep.base.port) {
2053         case ISP_OF_PHY_PARALLEL:
2054                 buscfg->interface = ISP_INTERFACE_PARALLEL;
2055                 buscfg->bus.parallel.data_lane_shift =
2056                         vep.bus.parallel.data_shift;
2057                 buscfg->bus.parallel.clk_pol =
2058                         !!(vep.bus.parallel.flags
2059                            & V4L2_MBUS_PCLK_SAMPLE_FALLING);
2060                 buscfg->bus.parallel.hs_pol =
2061                         !!(vep.bus.parallel.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW);
2062                 buscfg->bus.parallel.vs_pol =
2063                         !!(vep.bus.parallel.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW);
2064                 buscfg->bus.parallel.fld_pol =
2065                         !!(vep.bus.parallel.flags & V4L2_MBUS_FIELD_EVEN_LOW);
2066                 buscfg->bus.parallel.data_pol =
2067                         !!(vep.bus.parallel.flags & V4L2_MBUS_DATA_ACTIVE_LOW);
2068                 break;
2069
2070         case ISP_OF_PHY_CSIPHY1:
2071         case ISP_OF_PHY_CSIPHY2:
2072                 /* FIXME: always assume CSI-2 for now. */
2073                 switch (vep.base.port) {
2074                 case ISP_OF_PHY_CSIPHY1:
2075                         buscfg->interface = ISP_INTERFACE_CSI2C_PHY1;
2076                         break;
2077                 case ISP_OF_PHY_CSIPHY2:
2078                         buscfg->interface = ISP_INTERFACE_CSI2A_PHY2;
2079                         break;
2080                 }
2081                 buscfg->bus.csi2.lanecfg.clk.pos = vep.bus.mipi_csi2.clock_lane;
2082                 buscfg->bus.csi2.lanecfg.clk.pol =
2083                         vep.bus.mipi_csi2.lane_polarities[0];
2084                 dev_dbg(dev, "clock lane polarity %u, pos %u\n",
2085                         buscfg->bus.csi2.lanecfg.clk.pol,
2086                         buscfg->bus.csi2.lanecfg.clk.pos);
2087
2088                 for (i = 0; i < ISP_CSIPHY2_NUM_DATA_LANES; i++) {
2089                         buscfg->bus.csi2.lanecfg.data[i].pos =
2090                                 vep.bus.mipi_csi2.data_lanes[i];
2091                         buscfg->bus.csi2.lanecfg.data[i].pol =
2092                                 vep.bus.mipi_csi2.lane_polarities[i + 1];
2093                         dev_dbg(dev, "data lane %u polarity %u, pos %u\n", i,
2094                                 buscfg->bus.csi2.lanecfg.data[i].pol,
2095                                 buscfg->bus.csi2.lanecfg.data[i].pos);
2096                 }
2097
2098                 /*
2099                  * FIXME: now we assume the CRC is always there.
2100                  * Implement a way to obtain this information from the
2101                  * sensor. Frame descriptors, perhaps?
2102                  */
2103                 buscfg->bus.csi2.crc = 1;
2104                 break;
2105
2106         default:
2107                 dev_warn(dev, "%s: invalid interface %u\n", node->full_name,
2108                          vep.base.port);
2109                 break;
2110         }
2111
2112         return 0;
2113 }
2114
2115 static int isp_of_parse_nodes(struct device *dev,
2116                               struct v4l2_async_notifier *notifier)
2117 {
2118         struct device_node *node = NULL;
2119
2120         notifier->subdevs = devm_kcalloc(
2121                 dev, ISP_MAX_SUBDEVS, sizeof(*notifier->subdevs), GFP_KERNEL);
2122         if (!notifier->subdevs)
2123                 return -ENOMEM;
2124
2125         while (notifier->num_subdevs < ISP_MAX_SUBDEVS &&
2126                (node = of_graph_get_next_endpoint(dev->of_node, node))) {
2127                 struct isp_async_subdev *isd;
2128
2129                 isd = devm_kzalloc(dev, sizeof(*isd), GFP_KERNEL);
2130                 if (!isd) {
2131                         of_node_put(node);
2132                         return -ENOMEM;
2133                 }
2134
2135                 notifier->subdevs[notifier->num_subdevs] = &isd->asd;
2136
2137                 if (isp_of_parse_node(dev, node, isd)) {
2138                         of_node_put(node);
2139                         return -EINVAL;
2140                 }
2141
2142                 isd->asd.match.of.node = of_graph_get_remote_port_parent(node);
2143                 of_node_put(node);
2144                 if (!isd->asd.match.of.node) {
2145                         dev_warn(dev, "bad remote port parent\n");
2146                         return -EINVAL;
2147                 }
2148
2149                 isd->asd.match_type = V4L2_ASYNC_MATCH_OF;
2150                 notifier->num_subdevs++;
2151         }
2152
2153         return notifier->num_subdevs;
2154 }
2155
2156 static int isp_subdev_notifier_bound(struct v4l2_async_notifier *async,
2157                                      struct v4l2_subdev *subdev,
2158                                      struct v4l2_async_subdev *asd)
2159 {
2160         struct isp_async_subdev *isd =
2161                 container_of(asd, struct isp_async_subdev, asd);
2162
2163         isd->sd = subdev;
2164         isd->sd->host_priv = &isd->bus;
2165
2166         return 0;
2167 }
2168
2169 static int isp_subdev_notifier_complete(struct v4l2_async_notifier *async)
2170 {
2171         struct isp_device *isp = container_of(async, struct isp_device,
2172                                               notifier);
2173         struct v4l2_device *v4l2_dev = &isp->v4l2_dev;
2174         struct v4l2_subdev *sd;
2175         struct isp_bus_cfg *bus;
2176         int ret;
2177
2178         ret = media_entity_enum_init(&isp->crashed, &isp->media_dev);
2179         if (ret)
2180                 return ret;
2181
2182         list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
2183                 /* Only try to link entities whose interface was set on bound */
2184                 if (sd->host_priv) {
2185                         bus = (struct isp_bus_cfg *)sd->host_priv;
2186                         ret = isp_link_entity(isp, &sd->entity, bus->interface);
2187                         if (ret < 0)
2188                                 return ret;
2189                 }
2190         }
2191
2192         ret = v4l2_device_register_subdev_nodes(&isp->v4l2_dev);
2193         if (ret < 0)
2194                 return ret;
2195
2196         return media_device_register(&isp->media_dev);
2197 }
2198
2199 /*
2200  * isp_probe - Probe ISP platform device
2201  * @pdev: Pointer to ISP platform device
2202  *
2203  * Returns 0 if successful,
2204  *   -ENOMEM if no memory available,
2205  *   -ENODEV if no platform device resources found
2206  *     or no space for remapping registers,
2207  *   -EINVAL if couldn't install ISR,
2208  *   or clk_get return error value.
2209  */
2210 static int isp_probe(struct platform_device *pdev)
2211 {
2212         struct isp_device *isp;
2213         struct resource *mem;
2214         int ret;
2215         int i, m;
2216
2217         isp = devm_kzalloc(&pdev->dev, sizeof(*isp), GFP_KERNEL);
2218         if (!isp) {
2219                 dev_err(&pdev->dev, "could not allocate memory\n");
2220                 return -ENOMEM;
2221         }
2222
2223         ret = of_property_read_u32(pdev->dev.of_node, "ti,phy-type",
2224                                    &isp->phy_type);
2225         if (ret)
2226                 return ret;
2227
2228         isp->syscon = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
2229                                                       "syscon");
2230         if (IS_ERR(isp->syscon))
2231                 return PTR_ERR(isp->syscon);
2232
2233         ret = of_property_read_u32_index(pdev->dev.of_node, "syscon", 1,
2234                                          &isp->syscon_offset);
2235         if (ret)
2236                 return ret;
2237
2238         ret = isp_of_parse_nodes(&pdev->dev, &isp->notifier);
2239         if (ret < 0)
2240                 return ret;
2241
2242         isp->autoidle = autoidle;
2243
2244         mutex_init(&isp->isp_mutex);
2245         spin_lock_init(&isp->stat_lock);
2246
2247         isp->dev = &pdev->dev;
2248         isp->ref_count = 0;
2249
2250         ret = dma_coerce_mask_and_coherent(isp->dev, DMA_BIT_MASK(32));
2251         if (ret)
2252                 goto error;
2253
2254         platform_set_drvdata(pdev, isp);
2255
2256         /* Regulators */
2257         isp->isp_csiphy1.vdd = devm_regulator_get(&pdev->dev, "vdd-csiphy1");
2258         isp->isp_csiphy2.vdd = devm_regulator_get(&pdev->dev, "vdd-csiphy2");
2259
2260         /* Clocks
2261          *
2262          * The ISP clock tree is revision-dependent. We thus need to enable ICLK
2263          * manually to read the revision before calling __omap3isp_get().
2264          *
2265          * Start by mapping the ISP MMIO area, which is in two pieces.
2266          * The ISP IOMMU is in between. Map both now, and fill in the
2267          * ISP revision specific portions a little later in the
2268          * function.
2269          */
2270         for (i = 0; i < 2; i++) {
2271                 unsigned int map_idx = i ? OMAP3_ISP_IOMEM_CSI2A_REGS1 : 0;
2272
2273                 mem = platform_get_resource(pdev, IORESOURCE_MEM, i);
2274                 isp->mmio_base[map_idx] =
2275                         devm_ioremap_resource(isp->dev, mem);
2276                 if (IS_ERR(isp->mmio_base[map_idx])) {
2277                         ret = PTR_ERR(isp->mmio_base[map_idx]);
2278                         goto error;
2279                 }
2280         }
2281
2282         ret = isp_get_clocks(isp);
2283         if (ret < 0)
2284                 goto error;
2285
2286         ret = clk_enable(isp->clock[ISP_CLK_CAM_ICK]);
2287         if (ret < 0)
2288                 goto error;
2289
2290         isp->revision = isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_REVISION);
2291         dev_info(isp->dev, "Revision %d.%d found\n",
2292                  (isp->revision & 0xf0) >> 4, isp->revision & 0x0f);
2293
2294         clk_disable(isp->clock[ISP_CLK_CAM_ICK]);
2295
2296         if (__omap3isp_get(isp, false) == NULL) {
2297                 ret = -ENODEV;
2298                 goto error;
2299         }
2300
2301         ret = isp_reset(isp);
2302         if (ret < 0)
2303                 goto error_isp;
2304
2305         ret = isp_xclk_init(isp);
2306         if (ret < 0)
2307                 goto error_isp;
2308
2309         /* Memory resources */
2310         for (m = 0; m < ARRAY_SIZE(isp_res_maps); m++)
2311                 if (isp->revision == isp_res_maps[m].isp_rev)
2312                         break;
2313
2314         if (m == ARRAY_SIZE(isp_res_maps)) {
2315                 dev_err(isp->dev, "No resource map found for ISP rev %d.%d\n",
2316                         (isp->revision & 0xf0) >> 4, isp->revision & 0xf);
2317                 ret = -ENODEV;
2318                 goto error_isp;
2319         }
2320
2321         for (i = 1; i < OMAP3_ISP_IOMEM_CSI2A_REGS1; i++)
2322                 isp->mmio_base[i] =
2323                         isp->mmio_base[0] + isp_res_maps[m].offset[i];
2324
2325         for (i = OMAP3_ISP_IOMEM_CSIPHY2; i < OMAP3_ISP_IOMEM_LAST; i++)
2326                 isp->mmio_base[i] =
2327                         isp->mmio_base[OMAP3_ISP_IOMEM_CSI2A_REGS1]
2328                         + isp_res_maps[m].offset[i];
2329
2330         isp->mmio_hist_base_phys =
2331                 mem->start + isp_res_maps[m].offset[OMAP3_ISP_IOMEM_HIST];
2332
2333         /* IOMMU */
2334         ret = isp_attach_iommu(isp);
2335         if (ret < 0) {
2336                 dev_err(&pdev->dev, "unable to attach to IOMMU\n");
2337                 goto error_isp;
2338         }
2339
2340         /* Interrupt */
2341         ret = platform_get_irq(pdev, 0);
2342         if (ret <= 0) {
2343                 dev_err(isp->dev, "No IRQ resource\n");
2344                 ret = -ENODEV;
2345                 goto error_iommu;
2346         }
2347         isp->irq_num = ret;
2348
2349         if (devm_request_irq(isp->dev, isp->irq_num, isp_isr, IRQF_SHARED,
2350                              "OMAP3 ISP", isp)) {
2351                 dev_err(isp->dev, "Unable to request IRQ\n");
2352                 ret = -EINVAL;
2353                 goto error_iommu;
2354         }
2355
2356         /* Entities */
2357         ret = isp_initialize_modules(isp);
2358         if (ret < 0)
2359                 goto error_iommu;
2360
2361         ret = isp_register_entities(isp);
2362         if (ret < 0)
2363                 goto error_modules;
2364
2365         ret = isp_create_links(isp);
2366         if (ret < 0)
2367                 goto error_register_entities;
2368
2369         isp->notifier.bound = isp_subdev_notifier_bound;
2370         isp->notifier.complete = isp_subdev_notifier_complete;
2371
2372         ret = v4l2_async_notifier_register(&isp->v4l2_dev, &isp->notifier);
2373         if (ret)
2374                 goto error_register_entities;
2375
2376         isp_core_init(isp, 1);
2377         omap3isp_put(isp);
2378
2379         return 0;
2380
2381 error_register_entities:
2382         isp_unregister_entities(isp);
2383 error_modules:
2384         isp_cleanup_modules(isp);
2385 error_iommu:
2386         isp_detach_iommu(isp);
2387 error_isp:
2388         isp_xclk_cleanup(isp);
2389         __omap3isp_put(isp, false);
2390 error:
2391         mutex_destroy(&isp->isp_mutex);
2392
2393         return ret;
2394 }
2395
2396 static const struct dev_pm_ops omap3isp_pm_ops = {
2397         .prepare = isp_pm_prepare,
2398         .suspend = isp_pm_suspend,
2399         .resume = isp_pm_resume,
2400         .complete = isp_pm_complete,
2401 };
2402
2403 static struct platform_device_id omap3isp_id_table[] = {
2404         { "omap3isp", 0 },
2405         { },
2406 };
2407 MODULE_DEVICE_TABLE(platform, omap3isp_id_table);
2408
2409 static const struct of_device_id omap3isp_of_table[] = {
2410         { .compatible = "ti,omap3-isp" },
2411         { },
2412 };
2413 MODULE_DEVICE_TABLE(of, omap3isp_of_table);
2414
2415 static struct platform_driver omap3isp_driver = {
2416         .probe = isp_probe,
2417         .remove = isp_remove,
2418         .id_table = omap3isp_id_table,
2419         .driver = {
2420                 .name = "omap3isp",
2421                 .pm     = &omap3isp_pm_ops,
2422                 .of_match_table = omap3isp_of_table,
2423         },
2424 };
2425
2426 module_platform_driver(omap3isp_driver);
2427
2428 MODULE_AUTHOR("Nokia Corporation");
2429 MODULE_DESCRIPTION("TI OMAP3 ISP driver");
2430 MODULE_LICENSE("GPL");
2431 MODULE_VERSION(ISP_VIDEO_DRIVER_VERSION);