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