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