Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1 | /* |
| 2 | * ispccdc.c |
| 3 | * |
| 4 | * TI OMAP3 ISP - CCDC module |
| 5 | * |
| 6 | * Copyright (C) 2009-2010 Nokia Corporation |
| 7 | * Copyright (C) 2009 Texas Instruments, Inc. |
| 8 | * |
| 9 | * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com> |
| 10 | * Sakari Ailus <sakari.ailus@iki.fi> |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License version 2 as |
| 14 | * published by the Free Software Foundation. |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/uaccess.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/device.h> |
| 21 | #include <linux/dma-mapping.h> |
| 22 | #include <linux/mm.h> |
| 23 | #include <linux/sched.h> |
Joerg Roedel | e74d83a | 2011-09-06 11:02:15 -0300 | [diff] [blame] | 24 | #include <linux/slab.h> |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 25 | #include <media/v4l2-event.h> |
| 26 | |
| 27 | #include "isp.h" |
| 28 | #include "ispreg.h" |
| 29 | #include "ispccdc.h" |
| 30 | |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 31 | #define CCDC_MIN_WIDTH 32 |
| 32 | #define CCDC_MIN_HEIGHT 32 |
| 33 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 34 | static struct v4l2_mbus_framefmt * |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 35 | __ccdc_get_format(struct isp_ccdc_device *ccdc, struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 36 | unsigned int pad, enum v4l2_subdev_format_whence which); |
| 37 | |
| 38 | static const unsigned int ccdc_fmts[] = { |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 39 | MEDIA_BUS_FMT_Y8_1X8, |
| 40 | MEDIA_BUS_FMT_Y10_1X10, |
| 41 | MEDIA_BUS_FMT_Y12_1X12, |
| 42 | MEDIA_BUS_FMT_SGRBG8_1X8, |
| 43 | MEDIA_BUS_FMT_SRGGB8_1X8, |
| 44 | MEDIA_BUS_FMT_SBGGR8_1X8, |
| 45 | MEDIA_BUS_FMT_SGBRG8_1X8, |
| 46 | MEDIA_BUS_FMT_SGRBG10_1X10, |
| 47 | MEDIA_BUS_FMT_SRGGB10_1X10, |
| 48 | MEDIA_BUS_FMT_SBGGR10_1X10, |
| 49 | MEDIA_BUS_FMT_SGBRG10_1X10, |
| 50 | MEDIA_BUS_FMT_SGRBG12_1X12, |
| 51 | MEDIA_BUS_FMT_SRGGB12_1X12, |
| 52 | MEDIA_BUS_FMT_SBGGR12_1X12, |
| 53 | MEDIA_BUS_FMT_SGBRG12_1X12, |
| 54 | MEDIA_BUS_FMT_YUYV8_2X8, |
| 55 | MEDIA_BUS_FMT_UYVY8_2X8, |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | /* |
| 59 | * ccdc_print_status - Print current CCDC Module register values. |
| 60 | * @ccdc: Pointer to ISP CCDC device. |
| 61 | * |
| 62 | * Also prints other debug information stored in the CCDC module. |
| 63 | */ |
| 64 | #define CCDC_PRINT_REGISTER(isp, name)\ |
| 65 | dev_dbg(isp->dev, "###CCDC " #name "=0x%08x\n", \ |
| 66 | isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_##name)) |
| 67 | |
| 68 | static void ccdc_print_status(struct isp_ccdc_device *ccdc) |
| 69 | { |
| 70 | struct isp_device *isp = to_isp_device(ccdc); |
| 71 | |
| 72 | dev_dbg(isp->dev, "-------------CCDC Register dump-------------\n"); |
| 73 | |
| 74 | CCDC_PRINT_REGISTER(isp, PCR); |
| 75 | CCDC_PRINT_REGISTER(isp, SYN_MODE); |
| 76 | CCDC_PRINT_REGISTER(isp, HD_VD_WID); |
| 77 | CCDC_PRINT_REGISTER(isp, PIX_LINES); |
| 78 | CCDC_PRINT_REGISTER(isp, HORZ_INFO); |
| 79 | CCDC_PRINT_REGISTER(isp, VERT_START); |
| 80 | CCDC_PRINT_REGISTER(isp, VERT_LINES); |
| 81 | CCDC_PRINT_REGISTER(isp, CULLING); |
| 82 | CCDC_PRINT_REGISTER(isp, HSIZE_OFF); |
| 83 | CCDC_PRINT_REGISTER(isp, SDOFST); |
| 84 | CCDC_PRINT_REGISTER(isp, SDR_ADDR); |
| 85 | CCDC_PRINT_REGISTER(isp, CLAMP); |
| 86 | CCDC_PRINT_REGISTER(isp, DCSUB); |
| 87 | CCDC_PRINT_REGISTER(isp, COLPTN); |
| 88 | CCDC_PRINT_REGISTER(isp, BLKCMP); |
| 89 | CCDC_PRINT_REGISTER(isp, FPC); |
| 90 | CCDC_PRINT_REGISTER(isp, FPC_ADDR); |
| 91 | CCDC_PRINT_REGISTER(isp, VDINT); |
| 92 | CCDC_PRINT_REGISTER(isp, ALAW); |
| 93 | CCDC_PRINT_REGISTER(isp, REC656IF); |
| 94 | CCDC_PRINT_REGISTER(isp, CFG); |
| 95 | CCDC_PRINT_REGISTER(isp, FMTCFG); |
| 96 | CCDC_PRINT_REGISTER(isp, FMT_HORZ); |
| 97 | CCDC_PRINT_REGISTER(isp, FMT_VERT); |
| 98 | CCDC_PRINT_REGISTER(isp, PRGEVEN0); |
| 99 | CCDC_PRINT_REGISTER(isp, PRGEVEN1); |
| 100 | CCDC_PRINT_REGISTER(isp, PRGODD0); |
| 101 | CCDC_PRINT_REGISTER(isp, PRGODD1); |
| 102 | CCDC_PRINT_REGISTER(isp, VP_OUT); |
| 103 | CCDC_PRINT_REGISTER(isp, LSC_CONFIG); |
| 104 | CCDC_PRINT_REGISTER(isp, LSC_INITIAL); |
| 105 | CCDC_PRINT_REGISTER(isp, LSC_TABLE_BASE); |
| 106 | CCDC_PRINT_REGISTER(isp, LSC_TABLE_OFFSET); |
| 107 | |
| 108 | dev_dbg(isp->dev, "--------------------------------------------\n"); |
| 109 | } |
| 110 | |
| 111 | /* |
| 112 | * omap3isp_ccdc_busy - Get busy state of the CCDC. |
| 113 | * @ccdc: Pointer to ISP CCDC device. |
| 114 | */ |
| 115 | int omap3isp_ccdc_busy(struct isp_ccdc_device *ccdc) |
| 116 | { |
| 117 | struct isp_device *isp = to_isp_device(ccdc); |
| 118 | |
| 119 | return isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_PCR) & |
| 120 | ISPCCDC_PCR_BUSY; |
| 121 | } |
| 122 | |
| 123 | /* ----------------------------------------------------------------------------- |
| 124 | * Lens Shading Compensation |
| 125 | */ |
| 126 | |
| 127 | /* |
| 128 | * ccdc_lsc_validate_config - Check that LSC configuration is valid. |
| 129 | * @ccdc: Pointer to ISP CCDC device. |
| 130 | * @lsc_cfg: the LSC configuration to check. |
| 131 | * |
| 132 | * Returns 0 if the LSC configuration is valid, or -EINVAL if invalid. |
| 133 | */ |
| 134 | static int ccdc_lsc_validate_config(struct isp_ccdc_device *ccdc, |
| 135 | struct omap3isp_ccdc_lsc_config *lsc_cfg) |
| 136 | { |
| 137 | struct isp_device *isp = to_isp_device(ccdc); |
| 138 | struct v4l2_mbus_framefmt *format; |
| 139 | unsigned int paxel_width, paxel_height; |
| 140 | unsigned int paxel_shift_x, paxel_shift_y; |
| 141 | unsigned int min_width, min_height, min_size; |
| 142 | unsigned int input_width, input_height; |
| 143 | |
| 144 | paxel_shift_x = lsc_cfg->gain_mode_m; |
| 145 | paxel_shift_y = lsc_cfg->gain_mode_n; |
| 146 | |
| 147 | if ((paxel_shift_x < 2) || (paxel_shift_x > 6) || |
| 148 | (paxel_shift_y < 2) || (paxel_shift_y > 6)) { |
| 149 | dev_dbg(isp->dev, "CCDC: LSC: Invalid paxel size\n"); |
| 150 | return -EINVAL; |
| 151 | } |
| 152 | |
| 153 | if (lsc_cfg->offset & 3) { |
Mauro Carvalho Chehab | d26da99 | 2016-10-18 17:44:10 -0200 | [diff] [blame] | 154 | dev_dbg(isp->dev, |
| 155 | "CCDC: LSC: Offset must be a multiple of 4\n"); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 156 | return -EINVAL; |
| 157 | } |
| 158 | |
| 159 | if ((lsc_cfg->initial_x & 1) || (lsc_cfg->initial_y & 1)) { |
| 160 | dev_dbg(isp->dev, "CCDC: LSC: initial_x and y must be even\n"); |
| 161 | return -EINVAL; |
| 162 | } |
| 163 | |
| 164 | format = __ccdc_get_format(ccdc, NULL, CCDC_PAD_SINK, |
| 165 | V4L2_SUBDEV_FORMAT_ACTIVE); |
| 166 | input_width = format->width; |
| 167 | input_height = format->height; |
| 168 | |
| 169 | /* Calculate minimum bytesize for validation */ |
| 170 | paxel_width = 1 << paxel_shift_x; |
| 171 | min_width = ((input_width + lsc_cfg->initial_x + paxel_width - 1) |
| 172 | >> paxel_shift_x) + 1; |
| 173 | |
| 174 | paxel_height = 1 << paxel_shift_y; |
| 175 | min_height = ((input_height + lsc_cfg->initial_y + paxel_height - 1) |
| 176 | >> paxel_shift_y) + 1; |
| 177 | |
| 178 | min_size = 4 * min_width * min_height; |
| 179 | if (min_size > lsc_cfg->size) { |
| 180 | dev_dbg(isp->dev, "CCDC: LSC: too small table\n"); |
| 181 | return -EINVAL; |
| 182 | } |
| 183 | if (lsc_cfg->offset < (min_width * 4)) { |
| 184 | dev_dbg(isp->dev, "CCDC: LSC: Offset is too small\n"); |
| 185 | return -EINVAL; |
| 186 | } |
| 187 | if ((lsc_cfg->size / lsc_cfg->offset) < min_height) { |
| 188 | dev_dbg(isp->dev, "CCDC: LSC: Wrong size/offset combination\n"); |
| 189 | return -EINVAL; |
| 190 | } |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | /* |
| 195 | * ccdc_lsc_program_table - Program Lens Shading Compensation table address. |
| 196 | * @ccdc: Pointer to ISP CCDC device. |
| 197 | */ |
Laurent Pinchart | d33186d | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 198 | static void ccdc_lsc_program_table(struct isp_ccdc_device *ccdc, |
| 199 | dma_addr_t addr) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 200 | { |
| 201 | isp_reg_writel(to_isp_device(ccdc), addr, |
| 202 | OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_TABLE_BASE); |
| 203 | } |
| 204 | |
| 205 | /* |
| 206 | * ccdc_lsc_setup_regs - Configures the lens shading compensation module |
| 207 | * @ccdc: Pointer to ISP CCDC device. |
| 208 | */ |
| 209 | static void ccdc_lsc_setup_regs(struct isp_ccdc_device *ccdc, |
| 210 | struct omap3isp_ccdc_lsc_config *cfg) |
| 211 | { |
| 212 | struct isp_device *isp = to_isp_device(ccdc); |
| 213 | int reg; |
| 214 | |
| 215 | isp_reg_writel(isp, cfg->offset, OMAP3_ISP_IOMEM_CCDC, |
| 216 | ISPCCDC_LSC_TABLE_OFFSET); |
| 217 | |
| 218 | reg = 0; |
| 219 | reg |= cfg->gain_mode_n << ISPCCDC_LSC_GAIN_MODE_N_SHIFT; |
| 220 | reg |= cfg->gain_mode_m << ISPCCDC_LSC_GAIN_MODE_M_SHIFT; |
| 221 | reg |= cfg->gain_format << ISPCCDC_LSC_GAIN_FORMAT_SHIFT; |
| 222 | isp_reg_writel(isp, reg, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_CONFIG); |
| 223 | |
| 224 | reg = 0; |
| 225 | reg &= ~ISPCCDC_LSC_INITIAL_X_MASK; |
| 226 | reg |= cfg->initial_x << ISPCCDC_LSC_INITIAL_X_SHIFT; |
| 227 | reg &= ~ISPCCDC_LSC_INITIAL_Y_MASK; |
| 228 | reg |= cfg->initial_y << ISPCCDC_LSC_INITIAL_Y_SHIFT; |
| 229 | isp_reg_writel(isp, reg, OMAP3_ISP_IOMEM_CCDC, |
| 230 | ISPCCDC_LSC_INITIAL); |
| 231 | } |
| 232 | |
| 233 | static int ccdc_lsc_wait_prefetch(struct isp_ccdc_device *ccdc) |
| 234 | { |
| 235 | struct isp_device *isp = to_isp_device(ccdc); |
| 236 | unsigned int wait; |
| 237 | |
| 238 | isp_reg_writel(isp, IRQ0STATUS_CCDC_LSC_PREF_COMP_IRQ, |
| 239 | OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS); |
| 240 | |
| 241 | /* timeout 1 ms */ |
| 242 | for (wait = 0; wait < 1000; wait++) { |
| 243 | if (isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS) & |
| 244 | IRQ0STATUS_CCDC_LSC_PREF_COMP_IRQ) { |
| 245 | isp_reg_writel(isp, IRQ0STATUS_CCDC_LSC_PREF_COMP_IRQ, |
| 246 | OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS); |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | rmb(); |
| 251 | udelay(1); |
| 252 | } |
| 253 | |
| 254 | return -ETIMEDOUT; |
| 255 | } |
| 256 | |
| 257 | /* |
| 258 | * __ccdc_lsc_enable - Enables/Disables the Lens Shading Compensation module. |
| 259 | * @ccdc: Pointer to ISP CCDC device. |
| 260 | * @enable: 0 Disables LSC, 1 Enables LSC. |
| 261 | */ |
| 262 | static int __ccdc_lsc_enable(struct isp_ccdc_device *ccdc, int enable) |
| 263 | { |
| 264 | struct isp_device *isp = to_isp_device(ccdc); |
| 265 | const struct v4l2_mbus_framefmt *format = |
| 266 | __ccdc_get_format(ccdc, NULL, CCDC_PAD_SINK, |
| 267 | V4L2_SUBDEV_FORMAT_ACTIVE); |
| 268 | |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 269 | if ((format->code != MEDIA_BUS_FMT_SGRBG10_1X10) && |
| 270 | (format->code != MEDIA_BUS_FMT_SRGGB10_1X10) && |
| 271 | (format->code != MEDIA_BUS_FMT_SBGGR10_1X10) && |
| 272 | (format->code != MEDIA_BUS_FMT_SGBRG10_1X10)) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 273 | return -EINVAL; |
| 274 | |
| 275 | if (enable) |
| 276 | omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CCDC_LSC_READ); |
| 277 | |
| 278 | isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_CONFIG, |
| 279 | ISPCCDC_LSC_ENABLE, enable ? ISPCCDC_LSC_ENABLE : 0); |
| 280 | |
| 281 | if (enable) { |
| 282 | if (ccdc_lsc_wait_prefetch(ccdc) < 0) { |
| 283 | isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, |
| 284 | ISPCCDC_LSC_CONFIG, ISPCCDC_LSC_ENABLE); |
| 285 | ccdc->lsc.state = LSC_STATE_STOPPED; |
Lad, Prabhakar | 25aeb41 | 2014-02-21 09:07:21 -0300 | [diff] [blame] | 286 | dev_warn(to_device(ccdc), "LSC prefetch timeout\n"); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 287 | return -ETIMEDOUT; |
| 288 | } |
| 289 | ccdc->lsc.state = LSC_STATE_RUNNING; |
| 290 | } else { |
| 291 | ccdc->lsc.state = LSC_STATE_STOPPING; |
| 292 | } |
| 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | static int ccdc_lsc_busy(struct isp_ccdc_device *ccdc) |
| 298 | { |
| 299 | struct isp_device *isp = to_isp_device(ccdc); |
| 300 | |
| 301 | return isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_CONFIG) & |
| 302 | ISPCCDC_LSC_BUSY; |
| 303 | } |
| 304 | |
| 305 | /* __ccdc_lsc_configure - Apply a new configuration to the LSC engine |
| 306 | * @ccdc: Pointer to ISP CCDC device |
| 307 | * @req: New configuration request |
| 308 | * |
| 309 | * context: in_interrupt() |
| 310 | */ |
| 311 | static int __ccdc_lsc_configure(struct isp_ccdc_device *ccdc, |
| 312 | struct ispccdc_lsc_config_req *req) |
| 313 | { |
| 314 | if (!req->enable) |
| 315 | return -EINVAL; |
| 316 | |
| 317 | if (ccdc_lsc_validate_config(ccdc, &req->config) < 0) { |
| 318 | dev_dbg(to_device(ccdc), "Discard LSC configuration\n"); |
| 319 | return -EINVAL; |
| 320 | } |
| 321 | |
| 322 | if (ccdc_lsc_busy(ccdc)) |
| 323 | return -EBUSY; |
| 324 | |
| 325 | ccdc_lsc_setup_regs(ccdc, &req->config); |
Laurent Pinchart | d33186d | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 326 | ccdc_lsc_program_table(ccdc, req->table.dma); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | * ccdc_lsc_error_handler - Handle LSC prefetch error scenario. |
| 332 | * @ccdc: Pointer to ISP CCDC device. |
| 333 | * |
| 334 | * Disables LSC, and defers enablement to shadow registers update time. |
| 335 | */ |
| 336 | static void ccdc_lsc_error_handler(struct isp_ccdc_device *ccdc) |
| 337 | { |
| 338 | struct isp_device *isp = to_isp_device(ccdc); |
| 339 | /* |
| 340 | * From OMAP3 TRM: When this event is pending, the module |
| 341 | * goes into transparent mode (output =input). Normal |
| 342 | * operation can be resumed at the start of the next frame |
| 343 | * after: |
| 344 | * 1) Clearing this event |
| 345 | * 2) Disabling the LSC module |
| 346 | * 3) Enabling it |
| 347 | */ |
| 348 | isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_CONFIG, |
| 349 | ISPCCDC_LSC_ENABLE); |
| 350 | ccdc->lsc.state = LSC_STATE_STOPPED; |
| 351 | } |
| 352 | |
| 353 | static void ccdc_lsc_free_request(struct isp_ccdc_device *ccdc, |
| 354 | struct ispccdc_lsc_config_req *req) |
| 355 | { |
| 356 | struct isp_device *isp = to_isp_device(ccdc); |
| 357 | |
| 358 | if (req == NULL) |
| 359 | return; |
| 360 | |
Laurent Pinchart | d33186d | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 361 | if (req->table.addr) { |
| 362 | sg_free_table(&req->table.sgt); |
| 363 | dma_free_coherent(isp->dev, req->config.size, req->table.addr, |
| 364 | req->table.dma); |
| 365 | } |
| 366 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 367 | kfree(req); |
| 368 | } |
| 369 | |
| 370 | static void ccdc_lsc_free_queue(struct isp_ccdc_device *ccdc, |
| 371 | struct list_head *queue) |
| 372 | { |
| 373 | struct ispccdc_lsc_config_req *req, *n; |
| 374 | unsigned long flags; |
| 375 | |
| 376 | spin_lock_irqsave(&ccdc->lsc.req_lock, flags); |
| 377 | list_for_each_entry_safe(req, n, queue, list) { |
| 378 | list_del(&req->list); |
| 379 | spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags); |
| 380 | ccdc_lsc_free_request(ccdc, req); |
| 381 | spin_lock_irqsave(&ccdc->lsc.req_lock, flags); |
| 382 | } |
| 383 | spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags); |
| 384 | } |
| 385 | |
| 386 | static void ccdc_lsc_free_table_work(struct work_struct *work) |
| 387 | { |
| 388 | struct isp_ccdc_device *ccdc; |
| 389 | struct ispccdc_lsc *lsc; |
| 390 | |
| 391 | lsc = container_of(work, struct ispccdc_lsc, table_work); |
| 392 | ccdc = container_of(lsc, struct isp_ccdc_device, lsc); |
| 393 | |
| 394 | ccdc_lsc_free_queue(ccdc, &lsc->free_queue); |
| 395 | } |
| 396 | |
| 397 | /* |
| 398 | * ccdc_lsc_config - Configure the LSC module from a userspace request |
| 399 | * |
| 400 | * Store the request LSC configuration in the LSC engine request pointer. The |
| 401 | * configuration will be applied to the hardware when the CCDC will be enabled, |
| 402 | * or at the next LSC interrupt if the CCDC is already running. |
| 403 | */ |
| 404 | static int ccdc_lsc_config(struct isp_ccdc_device *ccdc, |
| 405 | struct omap3isp_ccdc_update_config *config) |
| 406 | { |
| 407 | struct isp_device *isp = to_isp_device(ccdc); |
| 408 | struct ispccdc_lsc_config_req *req; |
| 409 | unsigned long flags; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 410 | u16 update; |
| 411 | int ret; |
| 412 | |
| 413 | update = config->update & |
| 414 | (OMAP3ISP_CCDC_CONFIG_LSC | OMAP3ISP_CCDC_TBL_LSC); |
| 415 | if (!update) |
| 416 | return 0; |
| 417 | |
| 418 | if (update != (OMAP3ISP_CCDC_CONFIG_LSC | OMAP3ISP_CCDC_TBL_LSC)) { |
Mauro Carvalho Chehab | d26da99 | 2016-10-18 17:44:10 -0200 | [diff] [blame] | 419 | dev_dbg(to_device(ccdc), |
| 420 | "%s: Both LSC configuration and table need to be supplied\n", |
| 421 | __func__); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 422 | return -EINVAL; |
| 423 | } |
| 424 | |
| 425 | req = kzalloc(sizeof(*req), GFP_KERNEL); |
| 426 | if (req == NULL) |
| 427 | return -ENOMEM; |
| 428 | |
| 429 | if (config->flag & OMAP3ISP_CCDC_CONFIG_LSC) { |
| 430 | if (copy_from_user(&req->config, config->lsc_cfg, |
| 431 | sizeof(req->config))) { |
| 432 | ret = -EFAULT; |
| 433 | goto done; |
| 434 | } |
| 435 | |
| 436 | req->enable = 1; |
| 437 | |
Laurent Pinchart | d33186d | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 438 | req->table.addr = dma_alloc_coherent(isp->dev, req->config.size, |
| 439 | &req->table.dma, |
| 440 | GFP_KERNEL); |
| 441 | if (req->table.addr == NULL) { |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 442 | ret = -ENOMEM; |
| 443 | goto done; |
| 444 | } |
| 445 | |
Laurent Pinchart | d33186d | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 446 | ret = dma_get_sgtable(isp->dev, &req->table.sgt, |
| 447 | req->table.addr, req->table.dma, |
| 448 | req->config.size); |
| 449 | if (ret < 0) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 450 | goto done; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 451 | |
Laurent Pinchart | d33186d | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 452 | dma_sync_sg_for_cpu(isp->dev, req->table.sgt.sgl, |
| 453 | req->table.sgt.nents, DMA_TO_DEVICE); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 454 | |
Laurent Pinchart | d33186d | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 455 | if (copy_from_user(req->table.addr, config->lsc, |
| 456 | req->config.size)) { |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 457 | ret = -EFAULT; |
| 458 | goto done; |
| 459 | } |
| 460 | |
Laurent Pinchart | d33186d | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 461 | dma_sync_sg_for_device(isp->dev, req->table.sgt.sgl, |
| 462 | req->table.sgt.nents, DMA_TO_DEVICE); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | spin_lock_irqsave(&ccdc->lsc.req_lock, flags); |
| 466 | if (ccdc->lsc.request) { |
| 467 | list_add_tail(&ccdc->lsc.request->list, &ccdc->lsc.free_queue); |
| 468 | schedule_work(&ccdc->lsc.table_work); |
| 469 | } |
| 470 | ccdc->lsc.request = req; |
| 471 | spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags); |
| 472 | |
| 473 | ret = 0; |
| 474 | |
| 475 | done: |
| 476 | if (ret < 0) |
| 477 | ccdc_lsc_free_request(ccdc, req); |
| 478 | |
| 479 | return ret; |
| 480 | } |
| 481 | |
| 482 | static inline int ccdc_lsc_is_configured(struct isp_ccdc_device *ccdc) |
| 483 | { |
| 484 | unsigned long flags; |
Laurent Pinchart | 1c74817 | 2014-06-10 06:15:33 -0300 | [diff] [blame] | 485 | int ret; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 486 | |
| 487 | spin_lock_irqsave(&ccdc->lsc.req_lock, flags); |
Laurent Pinchart | 1c74817 | 2014-06-10 06:15:33 -0300 | [diff] [blame] | 488 | ret = ccdc->lsc.active != NULL; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 489 | spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags); |
Laurent Pinchart | 1c74817 | 2014-06-10 06:15:33 -0300 | [diff] [blame] | 490 | |
| 491 | return ret; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | static int ccdc_lsc_enable(struct isp_ccdc_device *ccdc) |
| 495 | { |
| 496 | struct ispccdc_lsc *lsc = &ccdc->lsc; |
| 497 | |
| 498 | if (lsc->state != LSC_STATE_STOPPED) |
| 499 | return -EINVAL; |
| 500 | |
| 501 | if (lsc->active) { |
| 502 | list_add_tail(&lsc->active->list, &lsc->free_queue); |
| 503 | lsc->active = NULL; |
| 504 | } |
| 505 | |
| 506 | if (__ccdc_lsc_configure(ccdc, lsc->request) < 0) { |
| 507 | omap3isp_sbl_disable(to_isp_device(ccdc), |
| 508 | OMAP3_ISP_SBL_CCDC_LSC_READ); |
| 509 | list_add_tail(&lsc->request->list, &lsc->free_queue); |
| 510 | lsc->request = NULL; |
| 511 | goto done; |
| 512 | } |
| 513 | |
| 514 | lsc->active = lsc->request; |
| 515 | lsc->request = NULL; |
| 516 | __ccdc_lsc_enable(ccdc, 1); |
| 517 | |
| 518 | done: |
| 519 | if (!list_empty(&lsc->free_queue)) |
| 520 | schedule_work(&lsc->table_work); |
| 521 | |
| 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | /* ----------------------------------------------------------------------------- |
| 526 | * Parameters configuration |
| 527 | */ |
| 528 | |
| 529 | /* |
| 530 | * ccdc_configure_clamp - Configure optical-black or digital clamping |
| 531 | * @ccdc: Pointer to ISP CCDC device. |
| 532 | * |
| 533 | * The CCDC performs either optical-black or digital clamp. Configure and enable |
| 534 | * the selected clamp method. |
| 535 | */ |
| 536 | static void ccdc_configure_clamp(struct isp_ccdc_device *ccdc) |
| 537 | { |
| 538 | struct isp_device *isp = to_isp_device(ccdc); |
| 539 | u32 clamp; |
| 540 | |
| 541 | if (ccdc->obclamp) { |
| 542 | clamp = ccdc->clamp.obgain << ISPCCDC_CLAMP_OBGAIN_SHIFT; |
| 543 | clamp |= ccdc->clamp.oblen << ISPCCDC_CLAMP_OBSLEN_SHIFT; |
| 544 | clamp |= ccdc->clamp.oblines << ISPCCDC_CLAMP_OBSLN_SHIFT; |
| 545 | clamp |= ccdc->clamp.obstpixel << ISPCCDC_CLAMP_OBST_SHIFT; |
| 546 | isp_reg_writel(isp, clamp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CLAMP); |
| 547 | } else { |
| 548 | isp_reg_writel(isp, ccdc->clamp.dcsubval, |
| 549 | OMAP3_ISP_IOMEM_CCDC, ISPCCDC_DCSUB); |
| 550 | } |
| 551 | |
| 552 | isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CLAMP, |
| 553 | ISPCCDC_CLAMP_CLAMPEN, |
| 554 | ccdc->obclamp ? ISPCCDC_CLAMP_CLAMPEN : 0); |
| 555 | } |
| 556 | |
| 557 | /* |
| 558 | * ccdc_configure_fpc - Configure Faulty Pixel Correction |
| 559 | * @ccdc: Pointer to ISP CCDC device. |
| 560 | */ |
| 561 | static void ccdc_configure_fpc(struct isp_ccdc_device *ccdc) |
| 562 | { |
| 563 | struct isp_device *isp = to_isp_device(ccdc); |
| 564 | |
| 565 | isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FPC, ISPCCDC_FPC_FPCEN); |
| 566 | |
| 567 | if (!ccdc->fpc_en) |
| 568 | return; |
| 569 | |
Laurent Pinchart | c60e153 | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 570 | isp_reg_writel(isp, ccdc->fpc.dma, OMAP3_ISP_IOMEM_CCDC, |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 571 | ISPCCDC_FPC_ADDR); |
| 572 | /* The FPNUM field must be set before enabling FPC. */ |
| 573 | isp_reg_writel(isp, (ccdc->fpc.fpnum << ISPCCDC_FPC_FPNUM_SHIFT), |
| 574 | OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FPC); |
| 575 | isp_reg_writel(isp, (ccdc->fpc.fpnum << ISPCCDC_FPC_FPNUM_SHIFT) | |
| 576 | ISPCCDC_FPC_FPCEN, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FPC); |
| 577 | } |
| 578 | |
| 579 | /* |
| 580 | * ccdc_configure_black_comp - Configure Black Level Compensation. |
| 581 | * @ccdc: Pointer to ISP CCDC device. |
| 582 | */ |
| 583 | static void ccdc_configure_black_comp(struct isp_ccdc_device *ccdc) |
| 584 | { |
| 585 | struct isp_device *isp = to_isp_device(ccdc); |
| 586 | u32 blcomp; |
| 587 | |
| 588 | blcomp = ccdc->blcomp.b_mg << ISPCCDC_BLKCMP_B_MG_SHIFT; |
| 589 | blcomp |= ccdc->blcomp.gb_g << ISPCCDC_BLKCMP_GB_G_SHIFT; |
| 590 | blcomp |= ccdc->blcomp.gr_cy << ISPCCDC_BLKCMP_GR_CY_SHIFT; |
| 591 | blcomp |= ccdc->blcomp.r_ye << ISPCCDC_BLKCMP_R_YE_SHIFT; |
| 592 | |
| 593 | isp_reg_writel(isp, blcomp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_BLKCMP); |
| 594 | } |
| 595 | |
| 596 | /* |
| 597 | * ccdc_configure_lpf - Configure Low-Pass Filter (LPF). |
| 598 | * @ccdc: Pointer to ISP CCDC device. |
| 599 | */ |
| 600 | static void ccdc_configure_lpf(struct isp_ccdc_device *ccdc) |
| 601 | { |
| 602 | struct isp_device *isp = to_isp_device(ccdc); |
| 603 | |
| 604 | isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE, |
| 605 | ISPCCDC_SYN_MODE_LPF, |
| 606 | ccdc->lpf ? ISPCCDC_SYN_MODE_LPF : 0); |
| 607 | } |
| 608 | |
| 609 | /* |
| 610 | * ccdc_configure_alaw - Configure A-law compression. |
| 611 | * @ccdc: Pointer to ISP CCDC device. |
| 612 | */ |
| 613 | static void ccdc_configure_alaw(struct isp_ccdc_device *ccdc) |
| 614 | { |
| 615 | struct isp_device *isp = to_isp_device(ccdc); |
Laurent Pinchart | 73ea57e | 2011-08-31 10:53:41 -0300 | [diff] [blame] | 616 | const struct isp_format_info *info; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 617 | u32 alaw = 0; |
| 618 | |
Laurent Pinchart | 73ea57e | 2011-08-31 10:53:41 -0300 | [diff] [blame] | 619 | info = omap3isp_video_format_info(ccdc->formats[CCDC_PAD_SINK].code); |
| 620 | |
| 621 | switch (info->width) { |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 622 | case 8: |
| 623 | return; |
| 624 | |
| 625 | case 10: |
| 626 | alaw = ISPCCDC_ALAW_GWDI_9_0; |
| 627 | break; |
| 628 | case 11: |
| 629 | alaw = ISPCCDC_ALAW_GWDI_10_1; |
| 630 | break; |
| 631 | case 12: |
| 632 | alaw = ISPCCDC_ALAW_GWDI_11_2; |
| 633 | break; |
| 634 | case 13: |
| 635 | alaw = ISPCCDC_ALAW_GWDI_12_3; |
| 636 | break; |
| 637 | } |
| 638 | |
| 639 | if (ccdc->alaw) |
| 640 | alaw |= ISPCCDC_ALAW_CCDTBL; |
| 641 | |
| 642 | isp_reg_writel(isp, alaw, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_ALAW); |
| 643 | } |
| 644 | |
| 645 | /* |
| 646 | * ccdc_config_imgattr - Configure sensor image specific attributes. |
| 647 | * @ccdc: Pointer to ISP CCDC device. |
| 648 | * @colptn: Color pattern of the sensor. |
| 649 | */ |
| 650 | static void ccdc_config_imgattr(struct isp_ccdc_device *ccdc, u32 colptn) |
| 651 | { |
| 652 | struct isp_device *isp = to_isp_device(ccdc); |
| 653 | |
| 654 | isp_reg_writel(isp, colptn, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_COLPTN); |
| 655 | } |
| 656 | |
| 657 | /* |
| 658 | * ccdc_config - Set CCDC configuration from userspace |
| 659 | * @ccdc: Pointer to ISP CCDC device. |
Lad, Prabhakar | 872aba5 | 2014-02-21 09:07:23 -0300 | [diff] [blame] | 660 | * @ccdc_struct: Structure containing CCDC configuration sent from userspace. |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 661 | * |
| 662 | * Returns 0 if successful, -EINVAL if the pointer to the configuration |
| 663 | * structure is null, or the copy_from_user function fails to copy user space |
| 664 | * memory to kernel space memory. |
| 665 | */ |
| 666 | static int ccdc_config(struct isp_ccdc_device *ccdc, |
| 667 | struct omap3isp_ccdc_update_config *ccdc_struct) |
| 668 | { |
| 669 | struct isp_device *isp = to_isp_device(ccdc); |
| 670 | unsigned long flags; |
| 671 | |
| 672 | spin_lock_irqsave(&ccdc->lock, flags); |
| 673 | ccdc->shadow_update = 1; |
| 674 | spin_unlock_irqrestore(&ccdc->lock, flags); |
| 675 | |
| 676 | if (OMAP3ISP_CCDC_ALAW & ccdc_struct->update) { |
| 677 | ccdc->alaw = !!(OMAP3ISP_CCDC_ALAW & ccdc_struct->flag); |
| 678 | ccdc->update |= OMAP3ISP_CCDC_ALAW; |
| 679 | } |
| 680 | |
| 681 | if (OMAP3ISP_CCDC_LPF & ccdc_struct->update) { |
| 682 | ccdc->lpf = !!(OMAP3ISP_CCDC_LPF & ccdc_struct->flag); |
| 683 | ccdc->update |= OMAP3ISP_CCDC_LPF; |
| 684 | } |
| 685 | |
| 686 | if (OMAP3ISP_CCDC_BLCLAMP & ccdc_struct->update) { |
| 687 | if (copy_from_user(&ccdc->clamp, ccdc_struct->bclamp, |
| 688 | sizeof(ccdc->clamp))) { |
| 689 | ccdc->shadow_update = 0; |
| 690 | return -EFAULT; |
| 691 | } |
| 692 | |
| 693 | ccdc->obclamp = !!(OMAP3ISP_CCDC_BLCLAMP & ccdc_struct->flag); |
| 694 | ccdc->update |= OMAP3ISP_CCDC_BLCLAMP; |
| 695 | } |
| 696 | |
| 697 | if (OMAP3ISP_CCDC_BCOMP & ccdc_struct->update) { |
| 698 | if (copy_from_user(&ccdc->blcomp, ccdc_struct->blcomp, |
| 699 | sizeof(ccdc->blcomp))) { |
| 700 | ccdc->shadow_update = 0; |
| 701 | return -EFAULT; |
| 702 | } |
| 703 | |
| 704 | ccdc->update |= OMAP3ISP_CCDC_BCOMP; |
| 705 | } |
| 706 | |
| 707 | ccdc->shadow_update = 0; |
| 708 | |
| 709 | if (OMAP3ISP_CCDC_FPC & ccdc_struct->update) { |
Laurent Pinchart | c60e153 | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 710 | struct omap3isp_ccdc_fpc fpc; |
| 711 | struct ispccdc_fpc fpc_old = { .addr = NULL, }; |
| 712 | struct ispccdc_fpc fpc_new; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 713 | u32 size; |
| 714 | |
| 715 | if (ccdc->state != ISP_PIPELINE_STREAM_STOPPED) |
| 716 | return -EBUSY; |
| 717 | |
| 718 | ccdc->fpc_en = !!(OMAP3ISP_CCDC_FPC & ccdc_struct->flag); |
| 719 | |
| 720 | if (ccdc->fpc_en) { |
Laurent Pinchart | c60e153 | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 721 | if (copy_from_user(&fpc, ccdc_struct->fpc, sizeof(fpc))) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 722 | return -EFAULT; |
| 723 | |
Laurent Pinchart | c60e153 | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 724 | size = fpc.fpnum * 4; |
| 725 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 726 | /* |
Laurent Pinchart | c60e153 | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 727 | * The table address must be 64-bytes aligned, which is |
| 728 | * guaranteed by dma_alloc_coherent(). |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 729 | */ |
Laurent Pinchart | c60e153 | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 730 | fpc_new.fpnum = fpc.fpnum; |
| 731 | fpc_new.addr = dma_alloc_coherent(isp->dev, size, |
| 732 | &fpc_new.dma, |
| 733 | GFP_KERNEL); |
| 734 | if (fpc_new.addr == NULL) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 735 | return -ENOMEM; |
| 736 | |
Laurent Pinchart | c60e153 | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 737 | if (copy_from_user(fpc_new.addr, |
| 738 | (__force void __user *)fpc.fpcaddr, |
| 739 | size)) { |
| 740 | dma_free_coherent(isp->dev, size, fpc_new.addr, |
| 741 | fpc_new.dma); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 742 | return -EFAULT; |
| 743 | } |
| 744 | |
Laurent Pinchart | c60e153 | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 745 | fpc_old = ccdc->fpc; |
| 746 | ccdc->fpc = fpc_new; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | ccdc_configure_fpc(ccdc); |
Laurent Pinchart | c60e153 | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 750 | |
| 751 | if (fpc_old.addr != NULL) |
| 752 | dma_free_coherent(isp->dev, fpc_old.fpnum * 4, |
| 753 | fpc_old.addr, fpc_old.dma); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | return ccdc_lsc_config(ccdc, ccdc_struct); |
| 757 | } |
| 758 | |
| 759 | static void ccdc_apply_controls(struct isp_ccdc_device *ccdc) |
| 760 | { |
| 761 | if (ccdc->update & OMAP3ISP_CCDC_ALAW) { |
| 762 | ccdc_configure_alaw(ccdc); |
| 763 | ccdc->update &= ~OMAP3ISP_CCDC_ALAW; |
| 764 | } |
| 765 | |
| 766 | if (ccdc->update & OMAP3ISP_CCDC_LPF) { |
| 767 | ccdc_configure_lpf(ccdc); |
| 768 | ccdc->update &= ~OMAP3ISP_CCDC_LPF; |
| 769 | } |
| 770 | |
| 771 | if (ccdc->update & OMAP3ISP_CCDC_BLCLAMP) { |
| 772 | ccdc_configure_clamp(ccdc); |
| 773 | ccdc->update &= ~OMAP3ISP_CCDC_BLCLAMP; |
| 774 | } |
| 775 | |
| 776 | if (ccdc->update & OMAP3ISP_CCDC_BCOMP) { |
| 777 | ccdc_configure_black_comp(ccdc); |
| 778 | ccdc->update &= ~OMAP3ISP_CCDC_BCOMP; |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | /* |
| 783 | * omap3isp_ccdc_restore_context - Restore values of the CCDC module registers |
Lad, Prabhakar | 872aba5 | 2014-02-21 09:07:23 -0300 | [diff] [blame] | 784 | * @isp: Pointer to ISP device |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 785 | */ |
| 786 | void omap3isp_ccdc_restore_context(struct isp_device *isp) |
| 787 | { |
| 788 | struct isp_ccdc_device *ccdc = &isp->isp_ccdc; |
| 789 | |
| 790 | isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG, ISPCCDC_CFG_VDLC); |
| 791 | |
| 792 | ccdc->update = OMAP3ISP_CCDC_ALAW | OMAP3ISP_CCDC_LPF |
| 793 | | OMAP3ISP_CCDC_BLCLAMP | OMAP3ISP_CCDC_BCOMP; |
| 794 | ccdc_apply_controls(ccdc); |
| 795 | ccdc_configure_fpc(ccdc); |
| 796 | } |
| 797 | |
| 798 | /* ----------------------------------------------------------------------------- |
| 799 | * Format- and pipeline-related configuration helpers |
| 800 | */ |
| 801 | |
| 802 | /* |
| 803 | * ccdc_config_vp - Configure the Video Port. |
| 804 | * @ccdc: Pointer to ISP CCDC device. |
| 805 | */ |
| 806 | static void ccdc_config_vp(struct isp_ccdc_device *ccdc) |
| 807 | { |
| 808 | struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity); |
| 809 | struct isp_device *isp = to_isp_device(ccdc); |
Laurent Pinchart | 73ea57e | 2011-08-31 10:53:41 -0300 | [diff] [blame] | 810 | const struct isp_format_info *info; |
Laurent Pinchart | aec2de0 | 2014-06-10 11:51:34 -0300 | [diff] [blame] | 811 | struct v4l2_mbus_framefmt *format; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 812 | unsigned long l3_ick = pipe->l3_ick; |
| 813 | unsigned int max_div = isp->revision == ISP_REVISION_15_0 ? 64 : 8; |
| 814 | unsigned int div = 0; |
Laurent Pinchart | aec2de0 | 2014-06-10 11:51:34 -0300 | [diff] [blame] | 815 | u32 fmtcfg = ISPCCDC_FMTCFG_VPEN; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 816 | |
Laurent Pinchart | aec2de0 | 2014-06-10 11:51:34 -0300 | [diff] [blame] | 817 | format = &ccdc->formats[CCDC_PAD_SOURCE_VP]; |
| 818 | |
| 819 | if (!format->code) { |
| 820 | /* Disable the video port when the input format isn't supported. |
| 821 | * This is indicated by a pixel code set to 0. |
| 822 | */ |
| 823 | isp_reg_writel(isp, 0, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMTCFG); |
| 824 | return; |
| 825 | } |
| 826 | |
| 827 | isp_reg_writel(isp, (0 << ISPCCDC_FMT_HORZ_FMTSPH_SHIFT) | |
| 828 | (format->width << ISPCCDC_FMT_HORZ_FMTLNH_SHIFT), |
| 829 | OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMT_HORZ); |
| 830 | isp_reg_writel(isp, (0 << ISPCCDC_FMT_VERT_FMTSLV_SHIFT) | |
| 831 | ((format->height + 1) << ISPCCDC_FMT_VERT_FMTLNV_SHIFT), |
| 832 | OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMT_VERT); |
| 833 | |
| 834 | isp_reg_writel(isp, (format->width << ISPCCDC_VP_OUT_HORZ_NUM_SHIFT) | |
| 835 | (format->height << ISPCCDC_VP_OUT_VERT_NUM_SHIFT), |
| 836 | OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VP_OUT); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 837 | |
Laurent Pinchart | 73ea57e | 2011-08-31 10:53:41 -0300 | [diff] [blame] | 838 | info = omap3isp_video_format_info(ccdc->formats[CCDC_PAD_SINK].code); |
| 839 | |
| 840 | switch (info->width) { |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 841 | case 8: |
| 842 | case 10: |
Laurent Pinchart | aec2de0 | 2014-06-10 11:51:34 -0300 | [diff] [blame] | 843 | fmtcfg |= ISPCCDC_FMTCFG_VPIN_9_0; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 844 | break; |
| 845 | case 11: |
Laurent Pinchart | aec2de0 | 2014-06-10 11:51:34 -0300 | [diff] [blame] | 846 | fmtcfg |= ISPCCDC_FMTCFG_VPIN_10_1; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 847 | break; |
| 848 | case 12: |
Laurent Pinchart | aec2de0 | 2014-06-10 11:51:34 -0300 | [diff] [blame] | 849 | fmtcfg |= ISPCCDC_FMTCFG_VPIN_11_2; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 850 | break; |
| 851 | case 13: |
Laurent Pinchart | aec2de0 | 2014-06-10 11:51:34 -0300 | [diff] [blame] | 852 | fmtcfg |= ISPCCDC_FMTCFG_VPIN_12_3; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 853 | break; |
Peter Meerwald | 13eaaa7 | 2012-06-21 13:46:05 -0300 | [diff] [blame] | 854 | } |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 855 | |
| 856 | if (pipe->input) |
| 857 | div = DIV_ROUND_UP(l3_ick, pipe->max_rate); |
Sakari Ailus | c6c01f9 | 2012-02-25 21:13:41 -0300 | [diff] [blame] | 858 | else if (pipe->external_rate) |
| 859 | div = l3_ick / pipe->external_rate; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 860 | |
| 861 | div = clamp(div, 2U, max_div); |
Laurent Pinchart | aec2de0 | 2014-06-10 11:51:34 -0300 | [diff] [blame] | 862 | fmtcfg |= (div - 2) << ISPCCDC_FMTCFG_VPIF_FRQ_SHIFT; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 863 | |
Laurent Pinchart | aec2de0 | 2014-06-10 11:51:34 -0300 | [diff] [blame] | 864 | isp_reg_writel(isp, fmtcfg, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMTCFG); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | /* |
| 868 | * ccdc_config_outlineoffset - Configure memory saving output line offset |
| 869 | * @ccdc: Pointer to ISP CCDC device. |
Laurent Pinchart | bcb4e0e | 2014-05-19 19:40:04 -0300 | [diff] [blame] | 870 | * @bpl: Number of bytes per line when stored in memory. |
| 871 | * @field: Field order when storing interlaced formats in memory. |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 872 | * |
Laurent Pinchart | bcb4e0e | 2014-05-19 19:40:04 -0300 | [diff] [blame] | 873 | * Configure the offsets for the line output control: |
| 874 | * |
| 875 | * - The horizontal line offset is defined as the number of bytes between the |
| 876 | * start of two consecutive lines in memory. Set it to the given bytes per |
| 877 | * line value. |
| 878 | * |
| 879 | * - The field offset value is defined as the number of lines to offset the |
| 880 | * start of the field identified by FID = 1. Set it to one. |
| 881 | * |
| 882 | * - The line offset values are defined as the number of lines (as defined by |
| 883 | * the horizontal line offset) between the start of two consecutive lines for |
| 884 | * all combinations of odd/even lines in odd/even fields. When interleaving |
| 885 | * fields set them all to two lines, and to one line otherwise. |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 886 | */ |
| 887 | static void ccdc_config_outlineoffset(struct isp_ccdc_device *ccdc, |
Laurent Pinchart | bcb4e0e | 2014-05-19 19:40:04 -0300 | [diff] [blame] | 888 | unsigned int bpl, |
| 889 | enum v4l2_field field) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 890 | { |
| 891 | struct isp_device *isp = to_isp_device(ccdc); |
Laurent Pinchart | bcb4e0e | 2014-05-19 19:40:04 -0300 | [diff] [blame] | 892 | u32 sdofst = 0; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 893 | |
Laurent Pinchart | bcb4e0e | 2014-05-19 19:40:04 -0300 | [diff] [blame] | 894 | isp_reg_writel(isp, bpl & 0xffff, OMAP3_ISP_IOMEM_CCDC, |
| 895 | ISPCCDC_HSIZE_OFF); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 896 | |
Laurent Pinchart | bcb4e0e | 2014-05-19 19:40:04 -0300 | [diff] [blame] | 897 | switch (field) { |
| 898 | case V4L2_FIELD_INTERLACED_TB: |
| 899 | case V4L2_FIELD_INTERLACED_BT: |
| 900 | /* When interleaving fields in memory offset field one by one |
| 901 | * line and set the line offset to two lines. |
| 902 | */ |
| 903 | sdofst |= (1 << ISPCCDC_SDOFST_LOFST0_SHIFT) |
| 904 | | (1 << ISPCCDC_SDOFST_LOFST1_SHIFT) |
| 905 | | (1 << ISPCCDC_SDOFST_LOFST2_SHIFT) |
| 906 | | (1 << ISPCCDC_SDOFST_LOFST3_SHIFT); |
| 907 | break; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 908 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 909 | default: |
Laurent Pinchart | bcb4e0e | 2014-05-19 19:40:04 -0300 | [diff] [blame] | 910 | /* In all other cases set the line offsets to one line. */ |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 911 | break; |
| 912 | } |
Laurent Pinchart | bcb4e0e | 2014-05-19 19:40:04 -0300 | [diff] [blame] | 913 | |
| 914 | isp_reg_writel(isp, sdofst, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDOFST); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | /* |
| 918 | * ccdc_set_outaddr - Set memory address to save output image |
| 919 | * @ccdc: Pointer to ISP CCDC device. |
| 920 | * @addr: ISP MMU Mapped 32-bit memory address aligned on 32 byte boundary. |
| 921 | * |
| 922 | * Sets the memory address where the output will be saved. |
| 923 | */ |
| 924 | static void ccdc_set_outaddr(struct isp_ccdc_device *ccdc, u32 addr) |
| 925 | { |
| 926 | struct isp_device *isp = to_isp_device(ccdc); |
| 927 | |
| 928 | isp_reg_writel(isp, addr, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDR_ADDR); |
| 929 | } |
| 930 | |
| 931 | /* |
| 932 | * omap3isp_ccdc_max_rate - Calculate maximum input data rate based on the input |
| 933 | * @ccdc: Pointer to ISP CCDC device. |
| 934 | * @max_rate: Maximum calculated data rate. |
| 935 | * |
| 936 | * Returns in *max_rate less value between calculated and passed |
| 937 | */ |
| 938 | void omap3isp_ccdc_max_rate(struct isp_ccdc_device *ccdc, |
| 939 | unsigned int *max_rate) |
| 940 | { |
| 941 | struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity); |
| 942 | unsigned int rate; |
| 943 | |
| 944 | if (pipe == NULL) |
| 945 | return; |
| 946 | |
| 947 | /* |
| 948 | * TRM says that for parallel sensors the maximum data rate |
| 949 | * should be 90% form L3/2 clock, otherwise just L3/2. |
| 950 | */ |
| 951 | if (ccdc->input == CCDC_INPUT_PARALLEL) |
| 952 | rate = pipe->l3_ick / 2 * 9 / 10; |
| 953 | else |
| 954 | rate = pipe->l3_ick / 2; |
| 955 | |
| 956 | *max_rate = min(*max_rate, rate); |
| 957 | } |
| 958 | |
| 959 | /* |
| 960 | * ccdc_config_sync_if - Set CCDC sync interface configuration |
| 961 | * @ccdc: Pointer to ISP CCDC device. |
Sakari Ailus | 68908747 | 2015-03-25 19:57:30 -0300 | [diff] [blame] | 962 | * @parcfg: Parallel interface platform data (may be NULL) |
Laurent Pinchart | 73ea57e | 2011-08-31 10:53:41 -0300 | [diff] [blame] | 963 | * @data_size: Data size |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 964 | */ |
| 965 | static void ccdc_config_sync_if(struct isp_ccdc_device *ccdc, |
Sakari Ailus | 68908747 | 2015-03-25 19:57:30 -0300 | [diff] [blame] | 966 | struct isp_parallel_cfg *parcfg, |
Laurent Pinchart | 73ea57e | 2011-08-31 10:53:41 -0300 | [diff] [blame] | 967 | unsigned int data_size) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 968 | { |
| 969 | struct isp_device *isp = to_isp_device(ccdc); |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 970 | const struct v4l2_mbus_framefmt *format; |
Laurent Pinchart | cf7a3d9 | 2011-08-31 10:42:17 -0300 | [diff] [blame] | 971 | u32 syn_mode = ISPCCDC_SYN_MODE_VDHDEN; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 972 | |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 973 | format = &ccdc->formats[CCDC_PAD_SINK]; |
| 974 | |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 975 | if (format->code == MEDIA_BUS_FMT_YUYV8_2X8 || |
| 976 | format->code == MEDIA_BUS_FMT_UYVY8_2X8) { |
Laurent Pinchart | 9de7af4 | 2014-05-20 14:18:53 -0300 | [diff] [blame] | 977 | /* According to the OMAP3 TRM the input mode only affects SYNC |
| 978 | * mode, enabling BT.656 mode should take precedence. However, |
| 979 | * in practice setting the input mode to YCbCr data on 8 bits |
| 980 | * seems to be required in BT.656 mode. In SYNC mode set it to |
| 981 | * YCbCr on 16 bits as the bridge is enabled in that case. |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 982 | */ |
Laurent Pinchart | 9de7af4 | 2014-05-20 14:18:53 -0300 | [diff] [blame] | 983 | if (ccdc->bt656) |
| 984 | syn_mode |= ISPCCDC_SYN_MODE_INPMOD_YCBCR8; |
| 985 | else |
| 986 | syn_mode |= ISPCCDC_SYN_MODE_INPMOD_YCBCR16; |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 987 | } |
| 988 | |
Laurent Pinchart | 73ea57e | 2011-08-31 10:53:41 -0300 | [diff] [blame] | 989 | switch (data_size) { |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 990 | case 8: |
| 991 | syn_mode |= ISPCCDC_SYN_MODE_DATSIZ_8; |
| 992 | break; |
| 993 | case 10: |
| 994 | syn_mode |= ISPCCDC_SYN_MODE_DATSIZ_10; |
| 995 | break; |
| 996 | case 11: |
| 997 | syn_mode |= ISPCCDC_SYN_MODE_DATSIZ_11; |
| 998 | break; |
| 999 | case 12: |
| 1000 | syn_mode |= ISPCCDC_SYN_MODE_DATSIZ_12; |
| 1001 | break; |
Peter Meerwald | 13eaaa7 | 2012-06-21 13:46:05 -0300 | [diff] [blame] | 1002 | } |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1003 | |
Sakari Ailus | 68908747 | 2015-03-25 19:57:30 -0300 | [diff] [blame] | 1004 | if (parcfg && parcfg->data_pol) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1005 | syn_mode |= ISPCCDC_SYN_MODE_DATAPOL; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1006 | |
Sakari Ailus | 68908747 | 2015-03-25 19:57:30 -0300 | [diff] [blame] | 1007 | if (parcfg && parcfg->hs_pol) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1008 | syn_mode |= ISPCCDC_SYN_MODE_HDPOL; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1009 | |
Laurent Pinchart | 9de7af4 | 2014-05-20 14:18:53 -0300 | [diff] [blame] | 1010 | /* The polarity of the vertical sync signal output by the BT.656 |
| 1011 | * decoder is not documented and seems to be active low. |
| 1012 | */ |
Sakari Ailus | 68908747 | 2015-03-25 19:57:30 -0300 | [diff] [blame] | 1013 | if ((parcfg && parcfg->vs_pol) || ccdc->bt656) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1014 | syn_mode |= ISPCCDC_SYN_MODE_VDPOL; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1015 | |
Sakari Ailus | 68908747 | 2015-03-25 19:57:30 -0300 | [diff] [blame] | 1016 | if (parcfg && parcfg->fld_pol) |
Laurent Pinchart | 9a36d8e | 2014-05-19 16:37:38 -0300 | [diff] [blame] | 1017 | syn_mode |= ISPCCDC_SYN_MODE_FLDPOL; |
| 1018 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1019 | isp_reg_writel(isp, syn_mode, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE); |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 1020 | |
| 1021 | /* The CCDC_CFG.Y8POS bit is used in YCbCr8 input mode only. The |
| 1022 | * hardware seems to ignore it in all other input modes. |
| 1023 | */ |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 1024 | if (format->code == MEDIA_BUS_FMT_UYVY8_2X8) |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 1025 | isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG, |
| 1026 | ISPCCDC_CFG_Y8POS); |
| 1027 | else |
| 1028 | isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG, |
| 1029 | ISPCCDC_CFG_Y8POS); |
| 1030 | |
Laurent Pinchart | 9de7af4 | 2014-05-20 14:18:53 -0300 | [diff] [blame] | 1031 | /* Enable or disable BT.656 mode, including error correction for the |
| 1032 | * synchronization codes. |
| 1033 | */ |
| 1034 | if (ccdc->bt656) |
| 1035 | isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_REC656IF, |
| 1036 | ISPCCDC_REC656IF_R656ON | ISPCCDC_REC656IF_ECCFVH); |
| 1037 | else |
| 1038 | isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_REC656IF, |
| 1039 | ISPCCDC_REC656IF_R656ON | ISPCCDC_REC656IF_ECCFVH); |
| 1040 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | /* CCDC formats descriptions */ |
| 1044 | static const u32 ccdc_sgrbg_pattern = |
| 1045 | ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP0PLC0_SHIFT | |
| 1046 | ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP0PLC1_SHIFT | |
| 1047 | ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP0PLC2_SHIFT | |
| 1048 | ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP0PLC3_SHIFT | |
| 1049 | ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP1PLC0_SHIFT | |
| 1050 | ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP1PLC1_SHIFT | |
| 1051 | ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP1PLC2_SHIFT | |
| 1052 | ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP1PLC3_SHIFT | |
| 1053 | ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP2PLC0_SHIFT | |
| 1054 | ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP2PLC1_SHIFT | |
| 1055 | ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP2PLC2_SHIFT | |
| 1056 | ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP2PLC3_SHIFT | |
| 1057 | ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP3PLC0_SHIFT | |
| 1058 | ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP3PLC1_SHIFT | |
| 1059 | ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP3PLC2_SHIFT | |
| 1060 | ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP3PLC3_SHIFT; |
| 1061 | |
| 1062 | static const u32 ccdc_srggb_pattern = |
| 1063 | ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP0PLC0_SHIFT | |
| 1064 | ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP0PLC1_SHIFT | |
| 1065 | ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP0PLC2_SHIFT | |
| 1066 | ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP0PLC3_SHIFT | |
| 1067 | ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP1PLC0_SHIFT | |
| 1068 | ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP1PLC1_SHIFT | |
| 1069 | ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP1PLC2_SHIFT | |
| 1070 | ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP1PLC3_SHIFT | |
| 1071 | ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP2PLC0_SHIFT | |
| 1072 | ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP2PLC1_SHIFT | |
| 1073 | ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP2PLC2_SHIFT | |
| 1074 | ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP2PLC3_SHIFT | |
| 1075 | ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP3PLC0_SHIFT | |
| 1076 | ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP3PLC1_SHIFT | |
| 1077 | ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP3PLC2_SHIFT | |
| 1078 | ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP3PLC3_SHIFT; |
| 1079 | |
| 1080 | static const u32 ccdc_sbggr_pattern = |
| 1081 | ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP0PLC0_SHIFT | |
| 1082 | ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP0PLC1_SHIFT | |
| 1083 | ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP0PLC2_SHIFT | |
| 1084 | ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP0PLC3_SHIFT | |
| 1085 | ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP1PLC0_SHIFT | |
| 1086 | ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP1PLC1_SHIFT | |
| 1087 | ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP1PLC2_SHIFT | |
| 1088 | ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP1PLC3_SHIFT | |
| 1089 | ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP2PLC0_SHIFT | |
| 1090 | ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP2PLC1_SHIFT | |
| 1091 | ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP2PLC2_SHIFT | |
| 1092 | ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP2PLC3_SHIFT | |
| 1093 | ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP3PLC0_SHIFT | |
| 1094 | ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP3PLC1_SHIFT | |
| 1095 | ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP3PLC2_SHIFT | |
| 1096 | ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP3PLC3_SHIFT; |
| 1097 | |
| 1098 | static const u32 ccdc_sgbrg_pattern = |
| 1099 | ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP0PLC0_SHIFT | |
| 1100 | ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP0PLC1_SHIFT | |
| 1101 | ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP0PLC2_SHIFT | |
| 1102 | ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP0PLC3_SHIFT | |
| 1103 | ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP1PLC0_SHIFT | |
| 1104 | ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP1PLC1_SHIFT | |
| 1105 | ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP1PLC2_SHIFT | |
| 1106 | ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP1PLC3_SHIFT | |
| 1107 | ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP2PLC0_SHIFT | |
| 1108 | ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP2PLC1_SHIFT | |
| 1109 | ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP2PLC2_SHIFT | |
| 1110 | ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP2PLC3_SHIFT | |
| 1111 | ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP3PLC0_SHIFT | |
| 1112 | ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP3PLC1_SHIFT | |
| 1113 | ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP3PLC2_SHIFT | |
| 1114 | ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP3PLC3_SHIFT; |
| 1115 | |
| 1116 | static void ccdc_configure(struct isp_ccdc_device *ccdc) |
| 1117 | { |
| 1118 | struct isp_device *isp = to_isp_device(ccdc); |
Sakari Ailus | 68908747 | 2015-03-25 19:57:30 -0300 | [diff] [blame] | 1119 | struct isp_parallel_cfg *parcfg = NULL; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1120 | struct v4l2_subdev *sensor; |
| 1121 | struct v4l2_mbus_framefmt *format; |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 1122 | const struct v4l2_rect *crop; |
Michael Jones | c09af04 | 2011-03-29 05:19:09 -0300 | [diff] [blame] | 1123 | const struct isp_format_info *fmt_info; |
| 1124 | struct v4l2_subdev_format fmt_src; |
| 1125 | unsigned int depth_out; |
| 1126 | unsigned int depth_in = 0; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1127 | struct media_pad *pad; |
| 1128 | unsigned long flags; |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 1129 | unsigned int bridge; |
Michael Jones | c09af04 | 2011-03-29 05:19:09 -0300 | [diff] [blame] | 1130 | unsigned int shift; |
Laurent Pinchart | 9de7af4 | 2014-05-20 14:18:53 -0300 | [diff] [blame] | 1131 | unsigned int nph; |
| 1132 | unsigned int sph; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1133 | u32 syn_mode; |
| 1134 | u32 ccdc_pattern; |
| 1135 | |
Laurent Pinchart | 9de7af4 | 2014-05-20 14:18:53 -0300 | [diff] [blame] | 1136 | ccdc->bt656 = false; |
Laurent Pinchart | 93d7bad | 2014-06-07 20:57:07 -0300 | [diff] [blame] | 1137 | ccdc->fields = 0; |
Laurent Pinchart | 9de7af4 | 2014-05-20 14:18:53 -0300 | [diff] [blame] | 1138 | |
Andrzej Hajda | 1bddf1b | 2013-06-03 05:16:13 -0300 | [diff] [blame] | 1139 | pad = media_entity_remote_pad(&ccdc->pads[CCDC_PAD_SINK]); |
Michael Jones | c09af04 | 2011-03-29 05:19:09 -0300 | [diff] [blame] | 1140 | sensor = media_entity_to_v4l2_subdev(pad->entity); |
Laurent Pinchart | 9de7af4 | 2014-05-20 14:18:53 -0300 | [diff] [blame] | 1141 | if (ccdc->input == CCDC_INPUT_PARALLEL) { |
Sakari Ailus | 68908747 | 2015-03-25 19:57:30 -0300 | [diff] [blame] | 1142 | parcfg = &((struct isp_bus_cfg *)sensor->host_priv) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1143 | ->bus.parallel; |
Laurent Pinchart | c8dbe31 | 2017-07-18 11:51:35 -0400 | [diff] [blame^] | 1144 | ccdc->bt656 = parcfg->bt656; |
Laurent Pinchart | 9de7af4 | 2014-05-20 14:18:53 -0300 | [diff] [blame] | 1145 | } |
Michael Jones | c09af04 | 2011-03-29 05:19:09 -0300 | [diff] [blame] | 1146 | |
Laurent Pinchart | 2e8f017 | 2014-05-19 15:05:51 -0300 | [diff] [blame] | 1147 | /* CCDC_PAD_SINK */ |
| 1148 | format = &ccdc->formats[CCDC_PAD_SINK]; |
| 1149 | |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 1150 | /* Compute the lane shifter shift value and enable the bridge when the |
Laurent Pinchart | 9de7af4 | 2014-05-20 14:18:53 -0300 | [diff] [blame] | 1151 | * input format is a non-BT.656 YUV variant. |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 1152 | */ |
Michael Jones | c09af04 | 2011-03-29 05:19:09 -0300 | [diff] [blame] | 1153 | fmt_src.pad = pad->index; |
| 1154 | fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE; |
| 1155 | if (!v4l2_subdev_call(sensor, pad, get_fmt, NULL, &fmt_src)) { |
| 1156 | fmt_info = omap3isp_video_format_info(fmt_src.format.code); |
Laurent Pinchart | 1697e49 | 2011-08-31 11:57:12 -0300 | [diff] [blame] | 1157 | depth_in = fmt_info->width; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1158 | } |
| 1159 | |
Laurent Pinchart | 2e8f017 | 2014-05-19 15:05:51 -0300 | [diff] [blame] | 1160 | fmt_info = omap3isp_video_format_info(format->code); |
Laurent Pinchart | 1697e49 | 2011-08-31 11:57:12 -0300 | [diff] [blame] | 1161 | depth_out = fmt_info->width; |
Michael Jones | c09af04 | 2011-03-29 05:19:09 -0300 | [diff] [blame] | 1162 | shift = depth_in - depth_out; |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 1163 | |
Laurent Pinchart | 9de7af4 | 2014-05-20 14:18:53 -0300 | [diff] [blame] | 1164 | if (ccdc->bt656) |
| 1165 | bridge = ISPCTRL_PAR_BRIDGE_DISABLE; |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 1166 | else if (fmt_info->code == MEDIA_BUS_FMT_YUYV8_2X8) |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 1167 | bridge = ISPCTRL_PAR_BRIDGE_LENDIAN; |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 1168 | else if (fmt_info->code == MEDIA_BUS_FMT_UYVY8_2X8) |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 1169 | bridge = ISPCTRL_PAR_BRIDGE_BENDIAN; |
| 1170 | else |
| 1171 | bridge = ISPCTRL_PAR_BRIDGE_DISABLE; |
| 1172 | |
Sakari Ailus | 68908747 | 2015-03-25 19:57:30 -0300 | [diff] [blame] | 1173 | omap3isp_configure_bridge(isp, ccdc->input, parcfg, shift, bridge); |
Michael Jones | c09af04 | 2011-03-29 05:19:09 -0300 | [diff] [blame] | 1174 | |
Laurent Pinchart | 9a36d8e | 2014-05-19 16:37:38 -0300 | [diff] [blame] | 1175 | /* Configure the sync interface. */ |
Sakari Ailus | 68908747 | 2015-03-25 19:57:30 -0300 | [diff] [blame] | 1176 | ccdc_config_sync_if(ccdc, parcfg, depth_out); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1177 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1178 | syn_mode = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE); |
| 1179 | |
| 1180 | /* Use the raw, unprocessed data when writing to memory. The H3A and |
| 1181 | * histogram modules are still fed with lens shading corrected data. |
| 1182 | */ |
| 1183 | syn_mode &= ~ISPCCDC_SYN_MODE_VP2SDR; |
| 1184 | |
| 1185 | if (ccdc->output & CCDC_OUTPUT_MEMORY) |
| 1186 | syn_mode |= ISPCCDC_SYN_MODE_WEN; |
| 1187 | else |
| 1188 | syn_mode &= ~ISPCCDC_SYN_MODE_WEN; |
| 1189 | |
| 1190 | if (ccdc->output & CCDC_OUTPUT_RESIZER) |
| 1191 | syn_mode |= ISPCCDC_SYN_MODE_SDR2RSZ; |
| 1192 | else |
| 1193 | syn_mode &= ~ISPCCDC_SYN_MODE_SDR2RSZ; |
| 1194 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1195 | /* Mosaic filter */ |
| 1196 | switch (format->code) { |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 1197 | case MEDIA_BUS_FMT_SRGGB10_1X10: |
| 1198 | case MEDIA_BUS_FMT_SRGGB12_1X12: |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1199 | ccdc_pattern = ccdc_srggb_pattern; |
| 1200 | break; |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 1201 | case MEDIA_BUS_FMT_SBGGR10_1X10: |
| 1202 | case MEDIA_BUS_FMT_SBGGR12_1X12: |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1203 | ccdc_pattern = ccdc_sbggr_pattern; |
| 1204 | break; |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 1205 | case MEDIA_BUS_FMT_SGBRG10_1X10: |
| 1206 | case MEDIA_BUS_FMT_SGBRG12_1X12: |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1207 | ccdc_pattern = ccdc_sgbrg_pattern; |
| 1208 | break; |
| 1209 | default: |
| 1210 | /* Use GRBG */ |
| 1211 | ccdc_pattern = ccdc_sgrbg_pattern; |
| 1212 | break; |
| 1213 | } |
| 1214 | ccdc_config_imgattr(ccdc, ccdc_pattern); |
| 1215 | |
| 1216 | /* Generate VD0 on the last line of the image and VD1 on the |
| 1217 | * 2/3 height line. |
| 1218 | */ |
| 1219 | isp_reg_writel(isp, ((format->height - 2) << ISPCCDC_VDINT_0_SHIFT) | |
| 1220 | ((format->height * 2 / 3) << ISPCCDC_VDINT_1_SHIFT), |
| 1221 | OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VDINT); |
| 1222 | |
| 1223 | /* CCDC_PAD_SOURCE_OF */ |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 1224 | format = &ccdc->formats[CCDC_PAD_SOURCE_OF]; |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 1225 | crop = &ccdc->crop; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1226 | |
Laurent Pinchart | 9de7af4 | 2014-05-20 14:18:53 -0300 | [diff] [blame] | 1227 | /* The horizontal coordinates are expressed in pixel clock cycles. We |
| 1228 | * need two cycles per pixel in BT.656 mode, and one cycle per pixel in |
| 1229 | * SYNC mode regardless of the format as the bridge is enabled for YUV |
| 1230 | * formats in that case. |
| 1231 | */ |
| 1232 | if (ccdc->bt656) { |
| 1233 | sph = crop->left * 2; |
| 1234 | nph = crop->width * 2 - 1; |
| 1235 | } else { |
| 1236 | sph = crop->left; |
| 1237 | nph = crop->width - 1; |
| 1238 | } |
| 1239 | |
| 1240 | isp_reg_writel(isp, (sph << ISPCCDC_HORZ_INFO_SPH_SHIFT) | |
| 1241 | (nph << ISPCCDC_HORZ_INFO_NPH_SHIFT), |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1242 | OMAP3_ISP_IOMEM_CCDC, ISPCCDC_HORZ_INFO); |
Laurent Pinchart | 9de7af4 | 2014-05-20 14:18:53 -0300 | [diff] [blame] | 1243 | isp_reg_writel(isp, (crop->top << ISPCCDC_VERT_START_SLV0_SHIFT) | |
| 1244 | (crop->top << ISPCCDC_VERT_START_SLV1_SHIFT), |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1245 | OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VERT_START); |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 1246 | isp_reg_writel(isp, (crop->height - 1) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1247 | << ISPCCDC_VERT_LINES_NLV_SHIFT, |
| 1248 | OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VERT_LINES); |
| 1249 | |
Laurent Pinchart | bcb4e0e | 2014-05-19 19:40:04 -0300 | [diff] [blame] | 1250 | ccdc_config_outlineoffset(ccdc, ccdc->video_out.bpl_value, |
| 1251 | format->field); |
| 1252 | |
| 1253 | /* When interleaving fields enable processing of the field input signal. |
| 1254 | * This will cause the line output control module to apply the field |
| 1255 | * offset to field 1. |
| 1256 | */ |
| 1257 | if (ccdc->formats[CCDC_PAD_SINK].field == V4L2_FIELD_ALTERNATE && |
| 1258 | (format->field == V4L2_FIELD_INTERLACED_TB || |
| 1259 | format->field == V4L2_FIELD_INTERLACED_BT)) |
| 1260 | syn_mode |= ISPCCDC_SYN_MODE_FLDMODE; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1261 | |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 1262 | /* The CCDC outputs data in UYVY order by default. Swap bytes to get |
| 1263 | * YUYV. |
| 1264 | */ |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 1265 | if (format->code == MEDIA_BUS_FMT_YUYV8_1X16) |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 1266 | isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG, |
| 1267 | ISPCCDC_CFG_BSWD); |
| 1268 | else |
| 1269 | isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG, |
| 1270 | ISPCCDC_CFG_BSWD); |
| 1271 | |
Laurent Pinchart | 9de7af4 | 2014-05-20 14:18:53 -0300 | [diff] [blame] | 1272 | /* Use PACK8 mode for 1byte per pixel formats. Check for BT.656 mode |
| 1273 | * explicitly as the driver reports 1X16 instead of 2X8 at the OF pad |
| 1274 | * for simplicity. |
| 1275 | */ |
| 1276 | if (omap3isp_video_format_info(format->code)->width <= 8 || ccdc->bt656) |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 1277 | syn_mode |= ISPCCDC_SYN_MODE_PACK8; |
| 1278 | else |
| 1279 | syn_mode &= ~ISPCCDC_SYN_MODE_PACK8; |
| 1280 | |
| 1281 | isp_reg_writel(isp, syn_mode, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE); |
| 1282 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1283 | /* CCDC_PAD_SOURCE_VP */ |
Laurent Pinchart | aec2de0 | 2014-06-10 11:51:34 -0300 | [diff] [blame] | 1284 | ccdc_config_vp(ccdc); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1285 | |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 1286 | /* Lens shading correction. */ |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1287 | spin_lock_irqsave(&ccdc->lsc.req_lock, flags); |
| 1288 | if (ccdc->lsc.request == NULL) |
| 1289 | goto unlock; |
| 1290 | |
| 1291 | WARN_ON(ccdc->lsc.active); |
| 1292 | |
| 1293 | /* Get last good LSC configuration. If it is not supported for |
| 1294 | * the current active resolution discard it. |
| 1295 | */ |
| 1296 | if (ccdc->lsc.active == NULL && |
| 1297 | __ccdc_lsc_configure(ccdc, ccdc->lsc.request) == 0) { |
| 1298 | ccdc->lsc.active = ccdc->lsc.request; |
| 1299 | } else { |
| 1300 | list_add_tail(&ccdc->lsc.request->list, &ccdc->lsc.free_queue); |
| 1301 | schedule_work(&ccdc->lsc.table_work); |
| 1302 | } |
| 1303 | |
| 1304 | ccdc->lsc.request = NULL; |
| 1305 | |
| 1306 | unlock: |
| 1307 | spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags); |
| 1308 | |
| 1309 | ccdc_apply_controls(ccdc); |
| 1310 | } |
| 1311 | |
| 1312 | static void __ccdc_enable(struct isp_ccdc_device *ccdc, int enable) |
| 1313 | { |
| 1314 | struct isp_device *isp = to_isp_device(ccdc); |
| 1315 | |
| 1316 | isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_PCR, |
| 1317 | ISPCCDC_PCR_EN, enable ? ISPCCDC_PCR_EN : 0); |
Laurent Pinchart | 0b3fcd5 | 2014-06-10 10:26:28 -0300 | [diff] [blame] | 1318 | |
| 1319 | ccdc->running = enable; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | static int ccdc_disable(struct isp_ccdc_device *ccdc) |
| 1323 | { |
| 1324 | unsigned long flags; |
| 1325 | int ret = 0; |
| 1326 | |
| 1327 | spin_lock_irqsave(&ccdc->lock, flags); |
| 1328 | if (ccdc->state == ISP_PIPELINE_STREAM_CONTINUOUS) |
| 1329 | ccdc->stopping = CCDC_STOP_REQUEST; |
Laurent Pinchart | 0b3fcd5 | 2014-06-10 10:26:28 -0300 | [diff] [blame] | 1330 | if (!ccdc->running) |
| 1331 | ccdc->stopping = CCDC_STOP_FINISHED; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1332 | spin_unlock_irqrestore(&ccdc->lock, flags); |
| 1333 | |
| 1334 | ret = wait_event_timeout(ccdc->wait, |
| 1335 | ccdc->stopping == CCDC_STOP_FINISHED, |
| 1336 | msecs_to_jiffies(2000)); |
| 1337 | if (ret == 0) { |
| 1338 | ret = -ETIMEDOUT; |
| 1339 | dev_warn(to_device(ccdc), "CCDC stop timeout!\n"); |
| 1340 | } |
| 1341 | |
| 1342 | omap3isp_sbl_disable(to_isp_device(ccdc), OMAP3_ISP_SBL_CCDC_LSC_READ); |
| 1343 | |
| 1344 | mutex_lock(&ccdc->ioctl_lock); |
| 1345 | ccdc_lsc_free_request(ccdc, ccdc->lsc.request); |
| 1346 | ccdc->lsc.request = ccdc->lsc.active; |
| 1347 | ccdc->lsc.active = NULL; |
| 1348 | cancel_work_sync(&ccdc->lsc.table_work); |
| 1349 | ccdc_lsc_free_queue(ccdc, &ccdc->lsc.free_queue); |
| 1350 | mutex_unlock(&ccdc->ioctl_lock); |
| 1351 | |
| 1352 | ccdc->stopping = CCDC_STOP_NOT_REQUESTED; |
| 1353 | |
| 1354 | return ret > 0 ? 0 : ret; |
| 1355 | } |
| 1356 | |
| 1357 | static void ccdc_enable(struct isp_ccdc_device *ccdc) |
| 1358 | { |
| 1359 | if (ccdc_lsc_is_configured(ccdc)) |
| 1360 | __ccdc_lsc_enable(ccdc, 1); |
| 1361 | __ccdc_enable(ccdc, 1); |
| 1362 | } |
| 1363 | |
| 1364 | /* ----------------------------------------------------------------------------- |
| 1365 | * Interrupt handling |
| 1366 | */ |
| 1367 | |
| 1368 | /* |
| 1369 | * ccdc_sbl_busy - Poll idle state of CCDC and related SBL memory write bits |
| 1370 | * @ccdc: Pointer to ISP CCDC device. |
| 1371 | * |
| 1372 | * Returns zero if the CCDC is idle and the image has been written to |
| 1373 | * memory, too. |
| 1374 | */ |
| 1375 | static int ccdc_sbl_busy(struct isp_ccdc_device *ccdc) |
| 1376 | { |
| 1377 | struct isp_device *isp = to_isp_device(ccdc); |
| 1378 | |
| 1379 | return omap3isp_ccdc_busy(ccdc) |
| 1380 | | (isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_CCDC_WR_0) & |
| 1381 | ISPSBL_CCDC_WR_0_DATA_READY) |
| 1382 | | (isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_CCDC_WR_1) & |
| 1383 | ISPSBL_CCDC_WR_0_DATA_READY) |
| 1384 | | (isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_CCDC_WR_2) & |
| 1385 | ISPSBL_CCDC_WR_0_DATA_READY) |
| 1386 | | (isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_CCDC_WR_3) & |
| 1387 | ISPSBL_CCDC_WR_0_DATA_READY); |
| 1388 | } |
| 1389 | |
| 1390 | /* |
| 1391 | * ccdc_sbl_wait_idle - Wait until the CCDC and related SBL are idle |
| 1392 | * @ccdc: Pointer to ISP CCDC device. |
| 1393 | * @max_wait: Max retry count in us for wait for idle/busy transition. |
| 1394 | */ |
| 1395 | static int ccdc_sbl_wait_idle(struct isp_ccdc_device *ccdc, |
| 1396 | unsigned int max_wait) |
| 1397 | { |
| 1398 | unsigned int wait = 0; |
| 1399 | |
| 1400 | if (max_wait == 0) |
| 1401 | max_wait = 10000; /* 10 ms */ |
| 1402 | |
| 1403 | for (wait = 0; wait <= max_wait; wait++) { |
| 1404 | if (!ccdc_sbl_busy(ccdc)) |
| 1405 | return 0; |
| 1406 | |
| 1407 | rmb(); |
| 1408 | udelay(1); |
| 1409 | } |
| 1410 | |
| 1411 | return -EBUSY; |
| 1412 | } |
| 1413 | |
Laurent Pinchart | 8815392 | 2014-06-07 20:57:07 -0300 | [diff] [blame] | 1414 | /* ccdc_handle_stopping - Handle CCDC and/or LSC stopping sequence |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1415 | * @ccdc: Pointer to ISP CCDC device. |
| 1416 | * @event: Pointing which event trigger handler |
| 1417 | * |
Michael Jones | 2d4e9d1 | 2011-02-28 08:29:03 -0300 | [diff] [blame] | 1418 | * Return 1 when the event and stopping request combination is satisfied, |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1419 | * zero otherwise. |
| 1420 | */ |
Laurent Pinchart | 8815392 | 2014-06-07 20:57:07 -0300 | [diff] [blame] | 1421 | static int ccdc_handle_stopping(struct isp_ccdc_device *ccdc, u32 event) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1422 | { |
| 1423 | int rval = 0; |
| 1424 | |
| 1425 | switch ((ccdc->stopping & 3) | event) { |
| 1426 | case CCDC_STOP_REQUEST | CCDC_EVENT_VD1: |
| 1427 | if (ccdc->lsc.state != LSC_STATE_STOPPED) |
| 1428 | __ccdc_lsc_enable(ccdc, 0); |
| 1429 | __ccdc_enable(ccdc, 0); |
| 1430 | ccdc->stopping = CCDC_STOP_EXECUTED; |
| 1431 | return 1; |
| 1432 | |
| 1433 | case CCDC_STOP_EXECUTED | CCDC_EVENT_VD0: |
| 1434 | ccdc->stopping |= CCDC_STOP_CCDC_FINISHED; |
| 1435 | if (ccdc->lsc.state == LSC_STATE_STOPPED) |
| 1436 | ccdc->stopping |= CCDC_STOP_LSC_FINISHED; |
| 1437 | rval = 1; |
| 1438 | break; |
| 1439 | |
| 1440 | case CCDC_STOP_EXECUTED | CCDC_EVENT_LSC_DONE: |
| 1441 | ccdc->stopping |= CCDC_STOP_LSC_FINISHED; |
| 1442 | rval = 1; |
| 1443 | break; |
| 1444 | |
| 1445 | case CCDC_STOP_EXECUTED | CCDC_EVENT_VD1: |
| 1446 | return 1; |
| 1447 | } |
| 1448 | |
| 1449 | if (ccdc->stopping == CCDC_STOP_FINISHED) { |
| 1450 | wake_up(&ccdc->wait); |
| 1451 | rval = 1; |
| 1452 | } |
| 1453 | |
| 1454 | return rval; |
| 1455 | } |
| 1456 | |
| 1457 | static void ccdc_hs_vs_isr(struct isp_ccdc_device *ccdc) |
| 1458 | { |
Laurent Pinchart | bd0f2e6 | 2011-11-11 11:22:20 -0300 | [diff] [blame] | 1459 | struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity); |
Laurent Pinchart | 63ae37e | 2011-11-16 10:54:02 -0300 | [diff] [blame] | 1460 | struct video_device *vdev = ccdc->subdev.devnode; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1461 | struct v4l2_event event; |
| 1462 | |
Laurent Pinchart | b43883d | 2012-02-09 13:00:45 -0300 | [diff] [blame] | 1463 | /* Frame number propagation */ |
| 1464 | atomic_inc(&pipe->frame_number); |
| 1465 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1466 | memset(&event, 0, sizeof(event)); |
Sakari Ailus | 69d232a | 2011-06-15 15:58:48 -0300 | [diff] [blame] | 1467 | event.type = V4L2_EVENT_FRAME_SYNC; |
| 1468 | event.u.frame_sync.frame_sequence = atomic_read(&pipe->frame_number); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1469 | |
| 1470 | v4l2_event_queue(vdev, &event); |
| 1471 | } |
| 1472 | |
| 1473 | /* |
| 1474 | * ccdc_lsc_isr - Handle LSC events |
| 1475 | * @ccdc: Pointer to ISP CCDC device. |
| 1476 | * @events: LSC events |
| 1477 | */ |
| 1478 | static void ccdc_lsc_isr(struct isp_ccdc_device *ccdc, u32 events) |
| 1479 | { |
| 1480 | unsigned long flags; |
| 1481 | |
| 1482 | if (events & IRQ0STATUS_CCDC_LSC_PREF_ERR_IRQ) { |
Laurent Pinchart | 875e2e3 | 2011-12-07 08:34:50 -0300 | [diff] [blame] | 1483 | struct isp_pipeline *pipe = |
| 1484 | to_isp_pipeline(&ccdc->subdev.entity); |
| 1485 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1486 | ccdc_lsc_error_handler(ccdc); |
Laurent Pinchart | 875e2e3 | 2011-12-07 08:34:50 -0300 | [diff] [blame] | 1487 | pipe->error = true; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1488 | dev_dbg(to_device(ccdc), "lsc prefetch error\n"); |
| 1489 | } |
| 1490 | |
| 1491 | if (!(events & IRQ0STATUS_CCDC_LSC_DONE_IRQ)) |
| 1492 | return; |
| 1493 | |
| 1494 | /* LSC_DONE interrupt occur, there are two cases |
| 1495 | * 1. stopping for reconfiguration |
| 1496 | * 2. stopping because of STREAM OFF command |
| 1497 | */ |
| 1498 | spin_lock_irqsave(&ccdc->lsc.req_lock, flags); |
| 1499 | |
| 1500 | if (ccdc->lsc.state == LSC_STATE_STOPPING) |
| 1501 | ccdc->lsc.state = LSC_STATE_STOPPED; |
| 1502 | |
Laurent Pinchart | 8815392 | 2014-06-07 20:57:07 -0300 | [diff] [blame] | 1503 | if (ccdc_handle_stopping(ccdc, CCDC_EVENT_LSC_DONE)) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1504 | goto done; |
| 1505 | |
| 1506 | if (ccdc->lsc.state != LSC_STATE_RECONFIG) |
| 1507 | goto done; |
| 1508 | |
| 1509 | /* LSC is in STOPPING state, change to the new state */ |
| 1510 | ccdc->lsc.state = LSC_STATE_STOPPED; |
| 1511 | |
| 1512 | /* This is an exception. Start of frame and LSC_DONE interrupt |
| 1513 | * have been received on the same time. Skip this event and wait |
| 1514 | * for better times. |
| 1515 | */ |
| 1516 | if (events & IRQ0STATUS_HS_VS_IRQ) |
| 1517 | goto done; |
| 1518 | |
| 1519 | /* The LSC engine is stopped at this point. Enable it if there's a |
| 1520 | * pending request. |
| 1521 | */ |
| 1522 | if (ccdc->lsc.request == NULL) |
| 1523 | goto done; |
| 1524 | |
| 1525 | ccdc_lsc_enable(ccdc); |
| 1526 | |
| 1527 | done: |
| 1528 | spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags); |
| 1529 | } |
| 1530 | |
Laurent Pinchart | 93d7bad | 2014-06-07 20:57:07 -0300 | [diff] [blame] | 1531 | /* |
| 1532 | * Check whether the CCDC has captured all fields necessary to complete the |
| 1533 | * buffer. |
| 1534 | */ |
| 1535 | static bool ccdc_has_all_fields(struct isp_ccdc_device *ccdc) |
| 1536 | { |
| 1537 | struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity); |
| 1538 | struct isp_device *isp = to_isp_device(ccdc); |
| 1539 | enum v4l2_field of_field = ccdc->formats[CCDC_PAD_SOURCE_OF].field; |
| 1540 | enum v4l2_field field; |
| 1541 | |
| 1542 | /* When the input is progressive fields don't matter. */ |
| 1543 | if (of_field == V4L2_FIELD_NONE) |
| 1544 | return true; |
| 1545 | |
| 1546 | /* Read the current field identifier. */ |
| 1547 | field = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE) |
| 1548 | & ISPCCDC_SYN_MODE_FLDSTAT |
| 1549 | ? V4L2_FIELD_BOTTOM : V4L2_FIELD_TOP; |
| 1550 | |
| 1551 | /* When capturing fields in alternate order just store the current field |
| 1552 | * identifier in the pipeline. |
| 1553 | */ |
| 1554 | if (of_field == V4L2_FIELD_ALTERNATE) { |
| 1555 | pipe->field = field; |
| 1556 | return true; |
| 1557 | } |
| 1558 | |
| 1559 | /* The format is interlaced. Make sure we've captured both fields. */ |
| 1560 | ccdc->fields |= field == V4L2_FIELD_BOTTOM |
| 1561 | ? CCDC_FIELD_BOTTOM : CCDC_FIELD_TOP; |
| 1562 | |
| 1563 | if (ccdc->fields != CCDC_FIELD_BOTH) |
| 1564 | return false; |
| 1565 | |
| 1566 | /* Verify that the field just captured corresponds to the last field |
| 1567 | * needed based on the desired field order. |
| 1568 | */ |
| 1569 | if ((of_field == V4L2_FIELD_INTERLACED_TB && field == V4L2_FIELD_TOP) || |
| 1570 | (of_field == V4L2_FIELD_INTERLACED_BT && field == V4L2_FIELD_BOTTOM)) |
| 1571 | return false; |
| 1572 | |
| 1573 | /* The buffer can be completed, reset the fields for the next buffer. */ |
| 1574 | ccdc->fields = 0; |
| 1575 | |
| 1576 | return true; |
| 1577 | } |
| 1578 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1579 | static int ccdc_isr_buffer(struct isp_ccdc_device *ccdc) |
| 1580 | { |
| 1581 | struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity); |
| 1582 | struct isp_device *isp = to_isp_device(ccdc); |
| 1583 | struct isp_buffer *buffer; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1584 | |
| 1585 | /* The CCDC generates VD0 interrupts even when disabled (the datasheet |
| 1586 | * doesn't explicitly state if that's supposed to happen or not, so it |
| 1587 | * can be considered as a hardware bug or as a feature, but we have to |
| 1588 | * deal with it anyway). Disabling the CCDC when no buffer is available |
| 1589 | * would thus not be enough, we need to handle the situation explicitly. |
| 1590 | */ |
| 1591 | if (list_empty(&ccdc->video_out.dmaqueue)) |
Laurent Pinchart | 0a7b1a0 | 2014-05-19 21:46:33 -0300 | [diff] [blame] | 1592 | return 0; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1593 | |
| 1594 | /* We're in continuous mode, and memory writes were disabled due to a |
| 1595 | * buffer underrun. Reenable them now that we have a buffer. The buffer |
| 1596 | * address has been set in ccdc_video_queue. |
| 1597 | */ |
| 1598 | if (ccdc->state == ISP_PIPELINE_STREAM_CONTINUOUS && ccdc->underrun) { |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1599 | ccdc->underrun = 0; |
Laurent Pinchart | 0a7b1a0 | 2014-05-19 21:46:33 -0300 | [diff] [blame] | 1600 | return 1; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1601 | } |
| 1602 | |
Laurent Pinchart | bcb4e0e | 2014-05-19 19:40:04 -0300 | [diff] [blame] | 1603 | /* Wait for the CCDC to become idle. */ |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1604 | if (ccdc_sbl_wait_idle(ccdc, 1000)) { |
| 1605 | dev_info(isp->dev, "CCDC won't become idle!\n"); |
Sakari Ailus | 17d3d40 | 2015-12-16 11:32:30 -0200 | [diff] [blame] | 1606 | media_entity_enum_set(&isp->crashed, &ccdc->subdev.entity); |
Laurent Pinchart | 9554b7d | 2013-12-09 11:13:13 -0300 | [diff] [blame] | 1607 | omap3isp_pipeline_cancel_stream(pipe); |
Laurent Pinchart | 0a7b1a0 | 2014-05-19 21:46:33 -0300 | [diff] [blame] | 1608 | return 0; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1609 | } |
| 1610 | |
Laurent Pinchart | 93d7bad | 2014-06-07 20:57:07 -0300 | [diff] [blame] | 1611 | if (!ccdc_has_all_fields(ccdc)) |
| 1612 | return 1; |
Laurent Pinchart | bcb4e0e | 2014-05-19 19:40:04 -0300 | [diff] [blame] | 1613 | |
Laurent Pinchart | 875e2e3 | 2011-12-07 08:34:50 -0300 | [diff] [blame] | 1614 | buffer = omap3isp_video_buffer_next(&ccdc->video_out); |
Laurent Pinchart | 0a7b1a0 | 2014-05-19 21:46:33 -0300 | [diff] [blame] | 1615 | if (buffer != NULL) |
Laurent Pinchart | 21d8582 | 2014-03-09 20:17:12 -0300 | [diff] [blame] | 1616 | ccdc_set_outaddr(ccdc, buffer->dma); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1617 | |
| 1618 | pipe->state |= ISP_PIPELINE_IDLE_OUTPUT; |
| 1619 | |
| 1620 | if (ccdc->state == ISP_PIPELINE_STREAM_SINGLESHOT && |
| 1621 | isp_pipeline_ready(pipe)) |
| 1622 | omap3isp_pipeline_set_stream(pipe, |
| 1623 | ISP_PIPELINE_STREAM_SINGLESHOT); |
| 1624 | |
Laurent Pinchart | 0a7b1a0 | 2014-05-19 21:46:33 -0300 | [diff] [blame] | 1625 | return buffer != NULL; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | /* |
| 1629 | * ccdc_vd0_isr - Handle VD0 event |
| 1630 | * @ccdc: Pointer to ISP CCDC device. |
| 1631 | * |
| 1632 | * Executes LSC deferred enablement before next frame starts. |
| 1633 | */ |
| 1634 | static void ccdc_vd0_isr(struct isp_ccdc_device *ccdc) |
| 1635 | { |
| 1636 | unsigned long flags; |
| 1637 | int restart = 0; |
| 1638 | |
Laurent Pinchart | fd93c10 | 2014-06-10 09:16:08 -0300 | [diff] [blame] | 1639 | /* In BT.656 mode the CCDC doesn't generate an HS/VS interrupt. We thus |
| 1640 | * need to increment the frame counter here. |
| 1641 | */ |
| 1642 | if (ccdc->bt656) { |
| 1643 | struct isp_pipeline *pipe = |
| 1644 | to_isp_pipeline(&ccdc->subdev.entity); |
| 1645 | |
| 1646 | atomic_inc(&pipe->frame_number); |
| 1647 | } |
| 1648 | |
Laurent Pinchart | 9345652 | 2014-06-10 09:41:57 -0300 | [diff] [blame] | 1649 | /* Emulate a VD1 interrupt for BT.656 mode, as we can't stop the CCDC in |
| 1650 | * the VD1 interrupt handler in that mode without risking a CCDC stall |
| 1651 | * if a short frame is received. |
| 1652 | */ |
| 1653 | if (ccdc->bt656) { |
| 1654 | spin_lock_irqsave(&ccdc->lock, flags); |
| 1655 | if (ccdc->state == ISP_PIPELINE_STREAM_CONTINUOUS && |
| 1656 | ccdc->output & CCDC_OUTPUT_MEMORY) { |
| 1657 | if (ccdc->lsc.state != LSC_STATE_STOPPED) |
| 1658 | __ccdc_lsc_enable(ccdc, 0); |
| 1659 | __ccdc_enable(ccdc, 0); |
| 1660 | } |
| 1661 | ccdc_handle_stopping(ccdc, CCDC_EVENT_VD1); |
| 1662 | spin_unlock_irqrestore(&ccdc->lock, flags); |
| 1663 | } |
| 1664 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1665 | if (ccdc->output & CCDC_OUTPUT_MEMORY) |
| 1666 | restart = ccdc_isr_buffer(ccdc); |
| 1667 | |
| 1668 | spin_lock_irqsave(&ccdc->lock, flags); |
Laurent Pinchart | 9345652 | 2014-06-10 09:41:57 -0300 | [diff] [blame] | 1669 | |
Laurent Pinchart | 8815392 | 2014-06-07 20:57:07 -0300 | [diff] [blame] | 1670 | if (ccdc_handle_stopping(ccdc, CCDC_EVENT_VD0)) { |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1671 | spin_unlock_irqrestore(&ccdc->lock, flags); |
| 1672 | return; |
| 1673 | } |
| 1674 | |
| 1675 | if (!ccdc->shadow_update) |
| 1676 | ccdc_apply_controls(ccdc); |
| 1677 | spin_unlock_irqrestore(&ccdc->lock, flags); |
| 1678 | |
| 1679 | if (restart) |
| 1680 | ccdc_enable(ccdc); |
| 1681 | } |
| 1682 | |
| 1683 | /* |
| 1684 | * ccdc_vd1_isr - Handle VD1 event |
| 1685 | * @ccdc: Pointer to ISP CCDC device. |
| 1686 | */ |
| 1687 | static void ccdc_vd1_isr(struct isp_ccdc_device *ccdc) |
| 1688 | { |
| 1689 | unsigned long flags; |
| 1690 | |
Laurent Pinchart | 9345652 | 2014-06-10 09:41:57 -0300 | [diff] [blame] | 1691 | /* In BT.656 mode the synchronization signals are generated by the CCDC |
| 1692 | * from the embedded sync codes. The VD0 and VD1 interrupts are thus |
| 1693 | * only triggered when the CCDC is enabled, unlike external sync mode |
| 1694 | * where the line counter runs even when the CCDC is stopped. We can't |
| 1695 | * disable the CCDC at VD1 time, as no VD0 interrupt would be generated |
| 1696 | * for a short frame, which would result in the CCDC being stopped and |
| 1697 | * no VD interrupt generated anymore. The CCDC is stopped from the VD0 |
| 1698 | * interrupt handler instead for BT.656. |
| 1699 | */ |
| 1700 | if (ccdc->bt656) |
| 1701 | return; |
| 1702 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1703 | spin_lock_irqsave(&ccdc->lsc.req_lock, flags); |
| 1704 | |
| 1705 | /* |
| 1706 | * Depending on the CCDC pipeline state, CCDC stopping should be |
| 1707 | * handled differently. In SINGLESHOT we emulate an internal CCDC |
| 1708 | * stopping because the CCDC hw works only in continuous mode. |
| 1709 | * When CONTINUOUS pipeline state is used and the CCDC writes it's |
| 1710 | * data to memory the CCDC and LSC are stopped immediately but |
| 1711 | * without change the CCDC stopping state machine. The CCDC |
| 1712 | * stopping state machine should be used only when user request |
| 1713 | * for stopping is received (SINGLESHOT is an exeption). |
| 1714 | */ |
| 1715 | switch (ccdc->state) { |
| 1716 | case ISP_PIPELINE_STREAM_SINGLESHOT: |
| 1717 | ccdc->stopping = CCDC_STOP_REQUEST; |
| 1718 | break; |
| 1719 | |
| 1720 | case ISP_PIPELINE_STREAM_CONTINUOUS: |
| 1721 | if (ccdc->output & CCDC_OUTPUT_MEMORY) { |
| 1722 | if (ccdc->lsc.state != LSC_STATE_STOPPED) |
| 1723 | __ccdc_lsc_enable(ccdc, 0); |
| 1724 | __ccdc_enable(ccdc, 0); |
| 1725 | } |
| 1726 | break; |
| 1727 | |
| 1728 | case ISP_PIPELINE_STREAM_STOPPED: |
| 1729 | break; |
| 1730 | } |
| 1731 | |
Laurent Pinchart | 8815392 | 2014-06-07 20:57:07 -0300 | [diff] [blame] | 1732 | if (ccdc_handle_stopping(ccdc, CCDC_EVENT_VD1)) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1733 | goto done; |
| 1734 | |
| 1735 | if (ccdc->lsc.request == NULL) |
| 1736 | goto done; |
| 1737 | |
| 1738 | /* |
| 1739 | * LSC need to be reconfigured. Stop it here and on next LSC_DONE IRQ |
| 1740 | * do the appropriate changes in registers |
| 1741 | */ |
| 1742 | if (ccdc->lsc.state == LSC_STATE_RUNNING) { |
| 1743 | __ccdc_lsc_enable(ccdc, 0); |
| 1744 | ccdc->lsc.state = LSC_STATE_RECONFIG; |
| 1745 | goto done; |
| 1746 | } |
| 1747 | |
| 1748 | /* LSC has been in STOPPED state, enable it */ |
| 1749 | if (ccdc->lsc.state == LSC_STATE_STOPPED) |
| 1750 | ccdc_lsc_enable(ccdc); |
| 1751 | |
| 1752 | done: |
| 1753 | spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags); |
| 1754 | } |
| 1755 | |
| 1756 | /* |
| 1757 | * omap3isp_ccdc_isr - Configure CCDC during interframe time. |
| 1758 | * @ccdc: Pointer to ISP CCDC device. |
| 1759 | * @events: CCDC events |
| 1760 | */ |
| 1761 | int omap3isp_ccdc_isr(struct isp_ccdc_device *ccdc, u32 events) |
| 1762 | { |
| 1763 | if (ccdc->state == ISP_PIPELINE_STREAM_STOPPED) |
| 1764 | return 0; |
| 1765 | |
| 1766 | if (events & IRQ0STATUS_CCDC_VD1_IRQ) |
| 1767 | ccdc_vd1_isr(ccdc); |
| 1768 | |
| 1769 | ccdc_lsc_isr(ccdc, events); |
| 1770 | |
| 1771 | if (events & IRQ0STATUS_CCDC_VD0_IRQ) |
| 1772 | ccdc_vd0_isr(ccdc); |
| 1773 | |
| 1774 | if (events & IRQ0STATUS_HS_VS_IRQ) |
| 1775 | ccdc_hs_vs_isr(ccdc); |
| 1776 | |
| 1777 | return 0; |
| 1778 | } |
| 1779 | |
| 1780 | /* ----------------------------------------------------------------------------- |
| 1781 | * ISP video operations |
| 1782 | */ |
| 1783 | |
| 1784 | static int ccdc_video_queue(struct isp_video *video, struct isp_buffer *buffer) |
| 1785 | { |
| 1786 | struct isp_ccdc_device *ccdc = &video->isp->isp_ccdc; |
Laurent Pinchart | ca84ea4 | 2014-06-10 10:28:48 -0300 | [diff] [blame] | 1787 | unsigned long flags; |
| 1788 | bool restart = false; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1789 | |
| 1790 | if (!(ccdc->output & CCDC_OUTPUT_MEMORY)) |
| 1791 | return -ENODEV; |
| 1792 | |
Laurent Pinchart | 21d8582 | 2014-03-09 20:17:12 -0300 | [diff] [blame] | 1793 | ccdc_set_outaddr(ccdc, buffer->dma); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1794 | |
Michael Jones | 2d4e9d1 | 2011-02-28 08:29:03 -0300 | [diff] [blame] | 1795 | /* We now have a buffer queued on the output, restart the pipeline |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1796 | * on the next CCDC interrupt if running in continuous mode (or when |
Laurent Pinchart | ca84ea4 | 2014-06-10 10:28:48 -0300 | [diff] [blame] | 1797 | * starting the stream) in external sync mode, or immediately in BT.656 |
| 1798 | * sync mode as no CCDC interrupt is generated when the CCDC is stopped |
| 1799 | * in that case. |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1800 | */ |
Laurent Pinchart | ca84ea4 | 2014-06-10 10:28:48 -0300 | [diff] [blame] | 1801 | spin_lock_irqsave(&ccdc->lock, flags); |
| 1802 | if (ccdc->state == ISP_PIPELINE_STREAM_CONTINUOUS && !ccdc->running && |
| 1803 | ccdc->bt656) |
Mauro Carvalho Chehab | 11b4c17 | 2014-09-03 15:48:14 -0300 | [diff] [blame] | 1804 | restart = true; |
Laurent Pinchart | ca84ea4 | 2014-06-10 10:28:48 -0300 | [diff] [blame] | 1805 | else |
| 1806 | ccdc->underrun = 1; |
| 1807 | spin_unlock_irqrestore(&ccdc->lock, flags); |
| 1808 | |
| 1809 | if (restart) |
| 1810 | ccdc_enable(ccdc); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1811 | |
| 1812 | return 0; |
| 1813 | } |
| 1814 | |
| 1815 | static const struct isp_video_operations ccdc_video_ops = { |
| 1816 | .queue = ccdc_video_queue, |
| 1817 | }; |
| 1818 | |
| 1819 | /* ----------------------------------------------------------------------------- |
| 1820 | * V4L2 subdev operations |
| 1821 | */ |
| 1822 | |
| 1823 | /* |
| 1824 | * ccdc_ioctl - CCDC module private ioctl's |
| 1825 | * @sd: ISP CCDC V4L2 subdevice |
| 1826 | * @cmd: ioctl command |
| 1827 | * @arg: ioctl argument |
| 1828 | * |
| 1829 | * Return 0 on success or a negative error code otherwise. |
| 1830 | */ |
| 1831 | static long ccdc_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) |
| 1832 | { |
| 1833 | struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd); |
| 1834 | int ret; |
| 1835 | |
| 1836 | switch (cmd) { |
| 1837 | case VIDIOC_OMAP3ISP_CCDC_CFG: |
| 1838 | mutex_lock(&ccdc->ioctl_lock); |
| 1839 | ret = ccdc_config(ccdc, arg); |
| 1840 | mutex_unlock(&ccdc->ioctl_lock); |
| 1841 | break; |
| 1842 | |
| 1843 | default: |
| 1844 | return -ENOIOCTLCMD; |
| 1845 | } |
| 1846 | |
| 1847 | return ret; |
| 1848 | } |
| 1849 | |
| 1850 | static int ccdc_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh, |
Laurent Pinchart | 55c8504 | 2012-10-12 11:20:10 -0300 | [diff] [blame] | 1851 | struct v4l2_event_subscription *sub) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1852 | { |
Sakari Ailus | 69d232a | 2011-06-15 15:58:48 -0300 | [diff] [blame] | 1853 | if (sub->type != V4L2_EVENT_FRAME_SYNC) |
| 1854 | return -EINVAL; |
| 1855 | |
| 1856 | /* line number is zero at frame start */ |
| 1857 | if (sub->id != 0) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1858 | return -EINVAL; |
| 1859 | |
Hans de Goede | c53c254 | 2012-04-08 12:59:46 -0300 | [diff] [blame] | 1860 | return v4l2_event_subscribe(fh, sub, OMAP3ISP_CCDC_NEVENTS, NULL); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | static int ccdc_unsubscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh, |
Laurent Pinchart | 55c8504 | 2012-10-12 11:20:10 -0300 | [diff] [blame] | 1864 | struct v4l2_event_subscription *sub) |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1865 | { |
| 1866 | return v4l2_event_unsubscribe(fh, sub); |
| 1867 | } |
| 1868 | |
| 1869 | /* |
| 1870 | * ccdc_set_stream - Enable/Disable streaming on the CCDC module |
| 1871 | * @sd: ISP CCDC V4L2 subdevice |
| 1872 | * @enable: Enable/disable stream |
| 1873 | * |
| 1874 | * When writing to memory, the CCDC hardware can't be enabled without a memory |
| 1875 | * buffer to write to. As the s_stream operation is called in response to a |
| 1876 | * STREAMON call without any buffer queued yet, just update the enabled field |
| 1877 | * and return immediately. The CCDC will be enabled in ccdc_isr_buffer(). |
| 1878 | * |
| 1879 | * When not writing to memory enable the CCDC immediately. |
| 1880 | */ |
| 1881 | static int ccdc_set_stream(struct v4l2_subdev *sd, int enable) |
| 1882 | { |
| 1883 | struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd); |
| 1884 | struct isp_device *isp = to_isp_device(ccdc); |
| 1885 | int ret = 0; |
| 1886 | |
| 1887 | if (ccdc->state == ISP_PIPELINE_STREAM_STOPPED) { |
| 1888 | if (enable == ISP_PIPELINE_STREAM_STOPPED) |
| 1889 | return 0; |
| 1890 | |
| 1891 | omap3isp_subclk_enable(isp, OMAP3_ISP_SUBCLK_CCDC); |
| 1892 | isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG, |
| 1893 | ISPCCDC_CFG_VDLC); |
| 1894 | |
| 1895 | ccdc_configure(ccdc); |
| 1896 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1897 | ccdc_print_status(ccdc); |
| 1898 | } |
| 1899 | |
| 1900 | switch (enable) { |
| 1901 | case ISP_PIPELINE_STREAM_CONTINUOUS: |
| 1902 | if (ccdc->output & CCDC_OUTPUT_MEMORY) |
| 1903 | omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CCDC_WRITE); |
| 1904 | |
| 1905 | if (ccdc->underrun || !(ccdc->output & CCDC_OUTPUT_MEMORY)) |
| 1906 | ccdc_enable(ccdc); |
| 1907 | |
| 1908 | ccdc->underrun = 0; |
| 1909 | break; |
| 1910 | |
| 1911 | case ISP_PIPELINE_STREAM_SINGLESHOT: |
| 1912 | if (ccdc->output & CCDC_OUTPUT_MEMORY && |
| 1913 | ccdc->state != ISP_PIPELINE_STREAM_SINGLESHOT) |
| 1914 | omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CCDC_WRITE); |
| 1915 | |
| 1916 | ccdc_enable(ccdc); |
| 1917 | break; |
| 1918 | |
| 1919 | case ISP_PIPELINE_STREAM_STOPPED: |
| 1920 | ret = ccdc_disable(ccdc); |
| 1921 | if (ccdc->output & CCDC_OUTPUT_MEMORY) |
| 1922 | omap3isp_sbl_disable(isp, OMAP3_ISP_SBL_CCDC_WRITE); |
| 1923 | omap3isp_subclk_disable(isp, OMAP3_ISP_SUBCLK_CCDC); |
| 1924 | ccdc->underrun = 0; |
| 1925 | break; |
| 1926 | } |
| 1927 | |
| 1928 | ccdc->state = enable; |
| 1929 | return ret; |
| 1930 | } |
| 1931 | |
| 1932 | static struct v4l2_mbus_framefmt * |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 1933 | __ccdc_get_format(struct isp_ccdc_device *ccdc, struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1934 | unsigned int pad, enum v4l2_subdev_format_whence which) |
| 1935 | { |
| 1936 | if (which == V4L2_SUBDEV_FORMAT_TRY) |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 1937 | return v4l2_subdev_get_try_format(&ccdc->subdev, cfg, pad); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1938 | else |
| 1939 | return &ccdc->formats[pad]; |
| 1940 | } |
| 1941 | |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 1942 | static struct v4l2_rect * |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 1943 | __ccdc_get_crop(struct isp_ccdc_device *ccdc, struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 1944 | enum v4l2_subdev_format_whence which) |
| 1945 | { |
| 1946 | if (which == V4L2_SUBDEV_FORMAT_TRY) |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 1947 | return v4l2_subdev_get_try_crop(&ccdc->subdev, cfg, CCDC_PAD_SOURCE_OF); |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 1948 | else |
| 1949 | return &ccdc->crop; |
| 1950 | } |
| 1951 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1952 | /* |
| 1953 | * ccdc_try_format - Try video format on a pad |
| 1954 | * @ccdc: ISP CCDC device |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 1955 | * @cfg : V4L2 subdev pad configuration |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1956 | * @pad: Pad number |
| 1957 | * @fmt: Format |
| 1958 | */ |
| 1959 | static void |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 1960 | ccdc_try_format(struct isp_ccdc_device *ccdc, struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1961 | unsigned int pad, struct v4l2_mbus_framefmt *fmt, |
| 1962 | enum v4l2_subdev_format_whence which) |
| 1963 | { |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1964 | const struct isp_format_info *info; |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 1965 | u32 pixelcode; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1966 | unsigned int width = fmt->width; |
| 1967 | unsigned int height = fmt->height; |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 1968 | struct v4l2_rect *crop; |
Laurent Pinchart | bcb4e0e | 2014-05-19 19:40:04 -0300 | [diff] [blame] | 1969 | enum v4l2_field field; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1970 | unsigned int i; |
| 1971 | |
| 1972 | switch (pad) { |
| 1973 | case CCDC_PAD_SINK: |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1974 | for (i = 0; i < ARRAY_SIZE(ccdc_fmts); i++) { |
| 1975 | if (fmt->code == ccdc_fmts[i]) |
| 1976 | break; |
| 1977 | } |
| 1978 | |
| 1979 | /* If not found, use SGRBG10 as default */ |
| 1980 | if (i >= ARRAY_SIZE(ccdc_fmts)) |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 1981 | fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1982 | |
| 1983 | /* Clamp the input size. */ |
| 1984 | fmt->width = clamp_t(u32, width, 32, 4096); |
| 1985 | fmt->height = clamp_t(u32, height, 32, 4096); |
Laurent Pinchart | 9a36d8e | 2014-05-19 16:37:38 -0300 | [diff] [blame] | 1986 | |
| 1987 | /* Default to progressive field order. */ |
| 1988 | if (fmt->field == V4L2_FIELD_ANY) |
| 1989 | fmt->field = V4L2_FIELD_NONE; |
| 1990 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 1991 | break; |
| 1992 | |
| 1993 | case CCDC_PAD_SOURCE_OF: |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 1994 | pixelcode = fmt->code; |
Laurent Pinchart | bcb4e0e | 2014-05-19 19:40:04 -0300 | [diff] [blame] | 1995 | field = fmt->field; |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 1996 | *fmt = *__ccdc_get_format(ccdc, cfg, CCDC_PAD_SINK, which); |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 1997 | |
Laurent Pinchart | 9de7af4 | 2014-05-20 14:18:53 -0300 | [diff] [blame] | 1998 | /* In SYNC mode the bridge converts YUV formats from 2X8 to |
| 1999 | * 1X16. In BT.656 no such conversion occurs. As we don't know |
| 2000 | * at this point whether the source will use SYNC or BT.656 mode |
| 2001 | * let's pretend the conversion always occurs. The CCDC will be |
| 2002 | * configured to pack bytes in BT.656, hiding the inaccuracy. |
| 2003 | * In all cases bytes can be swapped. |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 2004 | */ |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 2005 | if (fmt->code == MEDIA_BUS_FMT_YUYV8_2X8 || |
| 2006 | fmt->code == MEDIA_BUS_FMT_UYVY8_2X8) { |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 2007 | /* Use the user requested format if YUV. */ |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 2008 | if (pixelcode == MEDIA_BUS_FMT_YUYV8_2X8 || |
| 2009 | pixelcode == MEDIA_BUS_FMT_UYVY8_2X8 || |
| 2010 | pixelcode == MEDIA_BUS_FMT_YUYV8_1X16 || |
| 2011 | pixelcode == MEDIA_BUS_FMT_UYVY8_1X16) |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 2012 | fmt->code = pixelcode; |
| 2013 | |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 2014 | if (fmt->code == MEDIA_BUS_FMT_YUYV8_2X8) |
| 2015 | fmt->code = MEDIA_BUS_FMT_YUYV8_1X16; |
| 2016 | else if (fmt->code == MEDIA_BUS_FMT_UYVY8_2X8) |
| 2017 | fmt->code = MEDIA_BUS_FMT_UYVY8_1X16; |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 2018 | } |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2019 | |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2020 | /* Hardcode the output size to the crop rectangle size. */ |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2021 | crop = __ccdc_get_crop(ccdc, cfg, which); |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2022 | fmt->width = crop->width; |
| 2023 | fmt->height = crop->height; |
Laurent Pinchart | bcb4e0e | 2014-05-19 19:40:04 -0300 | [diff] [blame] | 2024 | |
| 2025 | /* When input format is interlaced with alternating fields the |
| 2026 | * CCDC can interleave the fields. |
| 2027 | */ |
| 2028 | if (fmt->field == V4L2_FIELD_ALTERNATE && |
| 2029 | (field == V4L2_FIELD_INTERLACED_TB || |
| 2030 | field == V4L2_FIELD_INTERLACED_BT)) { |
| 2031 | fmt->field = field; |
| 2032 | fmt->height *= 2; |
| 2033 | } |
| 2034 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2035 | break; |
| 2036 | |
| 2037 | case CCDC_PAD_SOURCE_VP: |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2038 | *fmt = *__ccdc_get_format(ccdc, cfg, CCDC_PAD_SINK, which); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2039 | |
| 2040 | /* The video port interface truncates the data to 10 bits. */ |
| 2041 | info = omap3isp_video_format_info(fmt->code); |
| 2042 | fmt->code = info->truncated; |
| 2043 | |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 2044 | /* YUV formats are not supported by the video port. */ |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 2045 | if (fmt->code == MEDIA_BUS_FMT_YUYV8_2X8 || |
| 2046 | fmt->code == MEDIA_BUS_FMT_UYVY8_2X8) |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 2047 | fmt->code = 0; |
| 2048 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2049 | /* The number of lines that can be clocked out from the video |
| 2050 | * port output must be at least one line less than the number |
| 2051 | * of input lines. |
| 2052 | */ |
| 2053 | fmt->width = clamp_t(u32, width, 32, fmt->width); |
| 2054 | fmt->height = clamp_t(u32, height, 32, fmt->height - 1); |
| 2055 | break; |
| 2056 | } |
| 2057 | |
| 2058 | /* Data is written to memory unpacked, each 10-bit or 12-bit pixel is |
| 2059 | * stored on 2 bytes. |
| 2060 | */ |
| 2061 | fmt->colorspace = V4L2_COLORSPACE_SRGB; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | /* |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2065 | * ccdc_try_crop - Validate a crop rectangle |
| 2066 | * @ccdc: ISP CCDC device |
| 2067 | * @sink: format on the sink pad |
| 2068 | * @crop: crop rectangle to be validated |
| 2069 | */ |
| 2070 | static void ccdc_try_crop(struct isp_ccdc_device *ccdc, |
| 2071 | const struct v4l2_mbus_framefmt *sink, |
| 2072 | struct v4l2_rect *crop) |
| 2073 | { |
| 2074 | const struct isp_format_info *info; |
| 2075 | unsigned int max_width; |
| 2076 | |
| 2077 | /* For Bayer formats, restrict left/top and width/height to even values |
| 2078 | * to keep the Bayer pattern. |
| 2079 | */ |
| 2080 | info = omap3isp_video_format_info(sink->code); |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 2081 | if (info->flavor != MEDIA_BUS_FMT_Y8_1X8) { |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2082 | crop->left &= ~1; |
| 2083 | crop->top &= ~1; |
| 2084 | } |
| 2085 | |
| 2086 | crop->left = clamp_t(u32, crop->left, 0, sink->width - CCDC_MIN_WIDTH); |
| 2087 | crop->top = clamp_t(u32, crop->top, 0, sink->height - CCDC_MIN_HEIGHT); |
| 2088 | |
| 2089 | /* The data formatter truncates the number of horizontal output pixels |
| 2090 | * to a multiple of 16. To avoid clipping data, allow callers to request |
| 2091 | * an output size bigger than the input size up to the nearest multiple |
| 2092 | * of 16. |
| 2093 | */ |
| 2094 | max_width = (sink->width - crop->left + 15) & ~15; |
| 2095 | crop->width = clamp_t(u32, crop->width, CCDC_MIN_WIDTH, max_width) |
| 2096 | & ~15; |
| 2097 | crop->height = clamp_t(u32, crop->height, CCDC_MIN_HEIGHT, |
| 2098 | sink->height - crop->top); |
| 2099 | |
| 2100 | /* Odd width/height values don't make sense for Bayer formats. */ |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 2101 | if (info->flavor != MEDIA_BUS_FMT_Y8_1X8) { |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2102 | crop->width &= ~1; |
| 2103 | crop->height &= ~1; |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | /* |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2108 | * ccdc_enum_mbus_code - Handle pixel format enumeration |
| 2109 | * @sd : pointer to v4l2 subdev structure |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2110 | * @cfg : V4L2 subdev pad configuration |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2111 | * @code : pointer to v4l2_subdev_mbus_code_enum structure |
| 2112 | * return -EINVAL or zero on success |
| 2113 | */ |
| 2114 | static int ccdc_enum_mbus_code(struct v4l2_subdev *sd, |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2115 | struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2116 | struct v4l2_subdev_mbus_code_enum *code) |
| 2117 | { |
| 2118 | struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd); |
| 2119 | struct v4l2_mbus_framefmt *format; |
| 2120 | |
| 2121 | switch (code->pad) { |
| 2122 | case CCDC_PAD_SINK: |
| 2123 | if (code->index >= ARRAY_SIZE(ccdc_fmts)) |
| 2124 | return -EINVAL; |
| 2125 | |
| 2126 | code->code = ccdc_fmts[code->index]; |
| 2127 | break; |
| 2128 | |
| 2129 | case CCDC_PAD_SOURCE_OF: |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2130 | format = __ccdc_get_format(ccdc, cfg, code->pad, |
Hans Verkuil | 3f1ccf1 | 2015-03-04 01:47:57 -0800 | [diff] [blame] | 2131 | code->which); |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 2132 | |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 2133 | if (format->code == MEDIA_BUS_FMT_YUYV8_2X8 || |
| 2134 | format->code == MEDIA_BUS_FMT_UYVY8_2X8) { |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 2135 | /* In YUV mode the CCDC can swap bytes. */ |
| 2136 | if (code->index == 0) |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 2137 | code->code = MEDIA_BUS_FMT_YUYV8_1X16; |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 2138 | else if (code->index == 1) |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 2139 | code->code = MEDIA_BUS_FMT_UYVY8_1X16; |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 2140 | else |
| 2141 | return -EINVAL; |
| 2142 | } else { |
| 2143 | /* In raw mode, no configurable format confversion is |
| 2144 | * available. |
| 2145 | */ |
| 2146 | if (code->index == 0) |
| 2147 | code->code = format->code; |
| 2148 | else |
| 2149 | return -EINVAL; |
| 2150 | } |
| 2151 | break; |
| 2152 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2153 | case CCDC_PAD_SOURCE_VP: |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 2154 | /* The CCDC supports no configurable format conversion |
| 2155 | * compatible with the video port. Enumerate a single output |
| 2156 | * format code. |
| 2157 | */ |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2158 | if (code->index != 0) |
| 2159 | return -EINVAL; |
| 2160 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2161 | format = __ccdc_get_format(ccdc, cfg, code->pad, |
Hans Verkuil | 3f1ccf1 | 2015-03-04 01:47:57 -0800 | [diff] [blame] | 2162 | code->which); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2163 | |
Laurent Pinchart | c51364c | 2011-08-31 11:03:53 -0300 | [diff] [blame] | 2164 | /* A pixel code equal to 0 means that the video port doesn't |
| 2165 | * support the input format. Don't enumerate any pixel code. |
| 2166 | */ |
| 2167 | if (format->code == 0) |
| 2168 | return -EINVAL; |
| 2169 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2170 | code->code = format->code; |
| 2171 | break; |
| 2172 | |
| 2173 | default: |
| 2174 | return -EINVAL; |
| 2175 | } |
| 2176 | |
| 2177 | return 0; |
| 2178 | } |
| 2179 | |
| 2180 | static int ccdc_enum_frame_size(struct v4l2_subdev *sd, |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2181 | struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2182 | struct v4l2_subdev_frame_size_enum *fse) |
| 2183 | { |
| 2184 | struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd); |
| 2185 | struct v4l2_mbus_framefmt format; |
| 2186 | |
| 2187 | if (fse->index != 0) |
| 2188 | return -EINVAL; |
| 2189 | |
| 2190 | format.code = fse->code; |
| 2191 | format.width = 1; |
| 2192 | format.height = 1; |
Hans Verkuil | 5778e74 | 2015-03-04 01:47:58 -0800 | [diff] [blame] | 2193 | ccdc_try_format(ccdc, cfg, fse->pad, &format, fse->which); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2194 | fse->min_width = format.width; |
| 2195 | fse->min_height = format.height; |
| 2196 | |
| 2197 | if (format.code != fse->code) |
| 2198 | return -EINVAL; |
| 2199 | |
| 2200 | format.code = fse->code; |
| 2201 | format.width = -1; |
| 2202 | format.height = -1; |
Hans Verkuil | 5778e74 | 2015-03-04 01:47:58 -0800 | [diff] [blame] | 2203 | ccdc_try_format(ccdc, cfg, fse->pad, &format, fse->which); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2204 | fse->max_width = format.width; |
| 2205 | fse->max_height = format.height; |
| 2206 | |
| 2207 | return 0; |
| 2208 | } |
| 2209 | |
| 2210 | /* |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2211 | * ccdc_get_selection - Retrieve a selection rectangle on a pad |
| 2212 | * @sd: ISP CCDC V4L2 subdevice |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2213 | * @cfg: V4L2 subdev pad configuration |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2214 | * @sel: Selection rectangle |
| 2215 | * |
| 2216 | * The only supported rectangles are the crop rectangles on the output formatter |
| 2217 | * source pad. |
| 2218 | * |
| 2219 | * Return 0 on success or a negative error code otherwise. |
| 2220 | */ |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2221 | static int ccdc_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2222 | struct v4l2_subdev_selection *sel) |
| 2223 | { |
| 2224 | struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd); |
| 2225 | struct v4l2_mbus_framefmt *format; |
| 2226 | |
| 2227 | if (sel->pad != CCDC_PAD_SOURCE_OF) |
| 2228 | return -EINVAL; |
| 2229 | |
| 2230 | switch (sel->target) { |
Sakari Ailus | 5689b28 | 2012-05-18 09:31:18 -0300 | [diff] [blame] | 2231 | case V4L2_SEL_TGT_CROP_BOUNDS: |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2232 | sel->r.left = 0; |
| 2233 | sel->r.top = 0; |
| 2234 | sel->r.width = INT_MAX; |
| 2235 | sel->r.height = INT_MAX; |
| 2236 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2237 | format = __ccdc_get_format(ccdc, cfg, CCDC_PAD_SINK, sel->which); |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2238 | ccdc_try_crop(ccdc, format, &sel->r); |
| 2239 | break; |
| 2240 | |
Sakari Ailus | 5689b28 | 2012-05-18 09:31:18 -0300 | [diff] [blame] | 2241 | case V4L2_SEL_TGT_CROP: |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2242 | sel->r = *__ccdc_get_crop(ccdc, cfg, sel->which); |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2243 | break; |
| 2244 | |
| 2245 | default: |
| 2246 | return -EINVAL; |
| 2247 | } |
| 2248 | |
| 2249 | return 0; |
| 2250 | } |
| 2251 | |
| 2252 | /* |
| 2253 | * ccdc_set_selection - Set a selection rectangle on a pad |
| 2254 | * @sd: ISP CCDC V4L2 subdevice |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2255 | * @cfg: V4L2 subdev pad configuration |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2256 | * @sel: Selection rectangle |
| 2257 | * |
| 2258 | * The only supported rectangle is the actual crop rectangle on the output |
| 2259 | * formatter source pad. |
| 2260 | * |
| 2261 | * Return 0 on success or a negative error code otherwise. |
| 2262 | */ |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2263 | static int ccdc_set_selection(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2264 | struct v4l2_subdev_selection *sel) |
| 2265 | { |
| 2266 | struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd); |
| 2267 | struct v4l2_mbus_framefmt *format; |
| 2268 | |
Sakari Ailus | 5689b28 | 2012-05-18 09:31:18 -0300 | [diff] [blame] | 2269 | if (sel->target != V4L2_SEL_TGT_CROP || |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2270 | sel->pad != CCDC_PAD_SOURCE_OF) |
| 2271 | return -EINVAL; |
| 2272 | |
| 2273 | /* The crop rectangle can't be changed while streaming. */ |
| 2274 | if (ccdc->state != ISP_PIPELINE_STREAM_STOPPED) |
| 2275 | return -EBUSY; |
| 2276 | |
| 2277 | /* Modifying the crop rectangle always changes the format on the source |
| 2278 | * pad. If the KEEP_CONFIG flag is set, just return the current crop |
| 2279 | * rectangle. |
| 2280 | */ |
Sakari Ailus | 563df3d | 2012-06-13 16:01:10 -0300 | [diff] [blame] | 2281 | if (sel->flags & V4L2_SEL_FLAG_KEEP_CONFIG) { |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2282 | sel->r = *__ccdc_get_crop(ccdc, cfg, sel->which); |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2283 | return 0; |
| 2284 | } |
| 2285 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2286 | format = __ccdc_get_format(ccdc, cfg, CCDC_PAD_SINK, sel->which); |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2287 | ccdc_try_crop(ccdc, format, &sel->r); |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2288 | *__ccdc_get_crop(ccdc, cfg, sel->which) = sel->r; |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2289 | |
| 2290 | /* Update the source format. */ |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2291 | format = __ccdc_get_format(ccdc, cfg, CCDC_PAD_SOURCE_OF, sel->which); |
| 2292 | ccdc_try_format(ccdc, cfg, CCDC_PAD_SOURCE_OF, format, sel->which); |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2293 | |
| 2294 | return 0; |
| 2295 | } |
| 2296 | |
| 2297 | /* |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2298 | * ccdc_get_format - Retrieve the video format on a pad |
| 2299 | * @sd : ISP CCDC V4L2 subdevice |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2300 | * @cfg: V4L2 subdev pad configuration |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2301 | * @fmt: Format |
| 2302 | * |
| 2303 | * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond |
| 2304 | * to the format type. |
| 2305 | */ |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2306 | static int ccdc_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2307 | struct v4l2_subdev_format *fmt) |
| 2308 | { |
| 2309 | struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd); |
| 2310 | struct v4l2_mbus_framefmt *format; |
| 2311 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2312 | format = __ccdc_get_format(ccdc, cfg, fmt->pad, fmt->which); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2313 | if (format == NULL) |
| 2314 | return -EINVAL; |
| 2315 | |
| 2316 | fmt->format = *format; |
| 2317 | return 0; |
| 2318 | } |
| 2319 | |
| 2320 | /* |
| 2321 | * ccdc_set_format - Set the video format on a pad |
| 2322 | * @sd : ISP CCDC V4L2 subdevice |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2323 | * @cfg: V4L2 subdev pad configuration |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2324 | * @fmt: Format |
| 2325 | * |
| 2326 | * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond |
| 2327 | * to the format type. |
| 2328 | */ |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2329 | static int ccdc_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2330 | struct v4l2_subdev_format *fmt) |
| 2331 | { |
| 2332 | struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd); |
| 2333 | struct v4l2_mbus_framefmt *format; |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2334 | struct v4l2_rect *crop; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2335 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2336 | format = __ccdc_get_format(ccdc, cfg, fmt->pad, fmt->which); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2337 | if (format == NULL) |
| 2338 | return -EINVAL; |
| 2339 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2340 | ccdc_try_format(ccdc, cfg, fmt->pad, &fmt->format, fmt->which); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2341 | *format = fmt->format; |
| 2342 | |
| 2343 | /* Propagate the format from sink to source */ |
| 2344 | if (fmt->pad == CCDC_PAD_SINK) { |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2345 | /* Reset the crop rectangle. */ |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2346 | crop = __ccdc_get_crop(ccdc, cfg, fmt->which); |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2347 | crop->left = 0; |
| 2348 | crop->top = 0; |
| 2349 | crop->width = fmt->format.width; |
| 2350 | crop->height = fmt->format.height; |
| 2351 | |
| 2352 | ccdc_try_crop(ccdc, &fmt->format, crop); |
| 2353 | |
| 2354 | /* Update the source formats. */ |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2355 | format = __ccdc_get_format(ccdc, cfg, CCDC_PAD_SOURCE_OF, |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2356 | fmt->which); |
| 2357 | *format = fmt->format; |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2358 | ccdc_try_format(ccdc, cfg, CCDC_PAD_SOURCE_OF, format, |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2359 | fmt->which); |
| 2360 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2361 | format = __ccdc_get_format(ccdc, cfg, CCDC_PAD_SOURCE_VP, |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2362 | fmt->which); |
| 2363 | *format = fmt->format; |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2364 | ccdc_try_format(ccdc, cfg, CCDC_PAD_SOURCE_VP, format, |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2365 | fmt->which); |
| 2366 | } |
| 2367 | |
| 2368 | return 0; |
| 2369 | } |
| 2370 | |
| 2371 | /* |
Sakari Ailus | a6d7a62 | 2012-02-25 20:42:07 -0300 | [diff] [blame] | 2372 | * Decide whether desired output pixel code can be obtained with |
| 2373 | * the lane shifter by shifting the input pixel code. |
| 2374 | * @in: input pixelcode to shifter |
| 2375 | * @out: output pixelcode from shifter |
| 2376 | * @additional_shift: # of bits the sensor's LSB is offset from CAMEXT[0] |
| 2377 | * |
| 2378 | * return true if the combination is possible |
| 2379 | * return false otherwise |
| 2380 | */ |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 2381 | static bool ccdc_is_shiftable(u32 in, u32 out, unsigned int additional_shift) |
Sakari Ailus | a6d7a62 | 2012-02-25 20:42:07 -0300 | [diff] [blame] | 2382 | { |
| 2383 | const struct isp_format_info *in_info, *out_info; |
| 2384 | |
| 2385 | if (in == out) |
| 2386 | return true; |
| 2387 | |
| 2388 | in_info = omap3isp_video_format_info(in); |
| 2389 | out_info = omap3isp_video_format_info(out); |
| 2390 | |
| 2391 | if ((in_info->flavor == 0) || (out_info->flavor == 0)) |
| 2392 | return false; |
| 2393 | |
| 2394 | if (in_info->flavor != out_info->flavor) |
| 2395 | return false; |
| 2396 | |
Laurent Pinchart | 1697e49 | 2011-08-31 11:57:12 -0300 | [diff] [blame] | 2397 | return in_info->width - out_info->width + additional_shift <= 6; |
Sakari Ailus | a6d7a62 | 2012-02-25 20:42:07 -0300 | [diff] [blame] | 2398 | } |
| 2399 | |
| 2400 | static int ccdc_link_validate(struct v4l2_subdev *sd, |
| 2401 | struct media_link *link, |
| 2402 | struct v4l2_subdev_format *source_fmt, |
| 2403 | struct v4l2_subdev_format *sink_fmt) |
| 2404 | { |
| 2405 | struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd); |
| 2406 | unsigned long parallel_shift; |
| 2407 | |
| 2408 | /* Check if the two ends match */ |
| 2409 | if (source_fmt->format.width != sink_fmt->format.width || |
| 2410 | source_fmt->format.height != sink_fmt->format.height) |
| 2411 | return -EPIPE; |
| 2412 | |
| 2413 | /* We've got a parallel sensor here. */ |
| 2414 | if (ccdc->input == CCDC_INPUT_PARALLEL) { |
Sakari Ailus | 68908747 | 2015-03-25 19:57:30 -0300 | [diff] [blame] | 2415 | struct isp_parallel_cfg *parcfg = |
| 2416 | &((struct isp_bus_cfg *) |
Sakari Ailus | a6d7a62 | 2012-02-25 20:42:07 -0300 | [diff] [blame] | 2417 | media_entity_to_v4l2_subdev(link->source->entity) |
| 2418 | ->host_priv)->bus.parallel; |
Laurent Pinchart | 74d1e7c | 2015-12-29 12:03:19 -0200 | [diff] [blame] | 2419 | parallel_shift = parcfg->data_lane_shift; |
Sakari Ailus | a6d7a62 | 2012-02-25 20:42:07 -0300 | [diff] [blame] | 2420 | } else { |
| 2421 | parallel_shift = 0; |
| 2422 | } |
| 2423 | |
| 2424 | /* Lane shifter may be used to drop bits on CCDC sink pad */ |
| 2425 | if (!ccdc_is_shiftable(source_fmt->format.code, |
| 2426 | sink_fmt->format.code, parallel_shift)) |
| 2427 | return -EPIPE; |
| 2428 | |
| 2429 | return 0; |
| 2430 | } |
| 2431 | |
| 2432 | /* |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2433 | * ccdc_init_formats - Initialize formats on all pads |
| 2434 | * @sd: ISP CCDC V4L2 subdevice |
| 2435 | * @fh: V4L2 subdev file handle |
| 2436 | * |
| 2437 | * Initialize all pad formats with default values. If fh is not NULL, try |
| 2438 | * formats are initialized on the file handle. Otherwise active formats are |
| 2439 | * initialized on the device. |
| 2440 | */ |
| 2441 | static int ccdc_init_formats(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) |
| 2442 | { |
| 2443 | struct v4l2_subdev_format format; |
| 2444 | |
| 2445 | memset(&format, 0, sizeof(format)); |
| 2446 | format.pad = CCDC_PAD_SINK; |
| 2447 | format.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE; |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 2448 | format.format.code = MEDIA_BUS_FMT_SGRBG10_1X10; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2449 | format.format.width = 4096; |
| 2450 | format.format.height = 4096; |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 2451 | ccdc_set_format(sd, fh ? fh->pad : NULL, &format); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2452 | |
| 2453 | return 0; |
| 2454 | } |
| 2455 | |
| 2456 | /* V4L2 subdev core operations */ |
| 2457 | static const struct v4l2_subdev_core_ops ccdc_v4l2_core_ops = { |
| 2458 | .ioctl = ccdc_ioctl, |
| 2459 | .subscribe_event = ccdc_subscribe_event, |
| 2460 | .unsubscribe_event = ccdc_unsubscribe_event, |
| 2461 | }; |
| 2462 | |
| 2463 | /* V4L2 subdev video operations */ |
| 2464 | static const struct v4l2_subdev_video_ops ccdc_v4l2_video_ops = { |
| 2465 | .s_stream = ccdc_set_stream, |
| 2466 | }; |
| 2467 | |
| 2468 | /* V4L2 subdev pad operations */ |
| 2469 | static const struct v4l2_subdev_pad_ops ccdc_v4l2_pad_ops = { |
| 2470 | .enum_mbus_code = ccdc_enum_mbus_code, |
| 2471 | .enum_frame_size = ccdc_enum_frame_size, |
| 2472 | .get_fmt = ccdc_get_format, |
| 2473 | .set_fmt = ccdc_set_format, |
Laurent Pinchart | a64909b | 2012-04-20 05:47:49 -0300 | [diff] [blame] | 2474 | .get_selection = ccdc_get_selection, |
| 2475 | .set_selection = ccdc_set_selection, |
Sakari Ailus | a6d7a62 | 2012-02-25 20:42:07 -0300 | [diff] [blame] | 2476 | .link_validate = ccdc_link_validate, |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2477 | }; |
| 2478 | |
| 2479 | /* V4L2 subdev operations */ |
| 2480 | static const struct v4l2_subdev_ops ccdc_v4l2_ops = { |
| 2481 | .core = &ccdc_v4l2_core_ops, |
| 2482 | .video = &ccdc_v4l2_video_ops, |
| 2483 | .pad = &ccdc_v4l2_pad_ops, |
| 2484 | }; |
| 2485 | |
| 2486 | /* V4L2 subdev internal operations */ |
| 2487 | static const struct v4l2_subdev_internal_ops ccdc_v4l2_internal_ops = { |
| 2488 | .open = ccdc_init_formats, |
| 2489 | }; |
| 2490 | |
| 2491 | /* ----------------------------------------------------------------------------- |
| 2492 | * Media entity operations |
| 2493 | */ |
| 2494 | |
| 2495 | /* |
| 2496 | * ccdc_link_setup - Setup CCDC connections |
| 2497 | * @entity: CCDC media entity |
| 2498 | * @local: Pad at the local end of the link |
| 2499 | * @remote: Pad at the remote end of the link |
| 2500 | * @flags: Link flags |
| 2501 | * |
| 2502 | * return -EINVAL or zero on success |
| 2503 | */ |
| 2504 | static int ccdc_link_setup(struct media_entity *entity, |
| 2505 | const struct media_pad *local, |
| 2506 | const struct media_pad *remote, u32 flags) |
| 2507 | { |
| 2508 | struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity); |
| 2509 | struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd); |
| 2510 | struct isp_device *isp = to_isp_device(ccdc); |
Mauro Carvalho Chehab | 829de29 | 2015-12-11 12:23:23 -0200 | [diff] [blame] | 2511 | unsigned int index = local->index; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2512 | |
Mauro Carvalho Chehab | 59ecd59 | 2015-05-07 22:12:33 -0300 | [diff] [blame] | 2513 | /* FIXME: this is actually a hack! */ |
| 2514 | if (is_media_entity_v4l2_subdev(remote->entity)) |
| 2515 | index |= 2 << 16; |
| 2516 | |
| 2517 | switch (index) { |
| 2518 | case CCDC_PAD_SINK | 2 << 16: |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2519 | /* Read from the sensor (parallel interface), CCP2, CSI2a or |
| 2520 | * CSI2c. |
| 2521 | */ |
| 2522 | if (!(flags & MEDIA_LNK_FL_ENABLED)) { |
| 2523 | ccdc->input = CCDC_INPUT_NONE; |
| 2524 | break; |
| 2525 | } |
| 2526 | |
| 2527 | if (ccdc->input != CCDC_INPUT_NONE) |
| 2528 | return -EBUSY; |
| 2529 | |
| 2530 | if (remote->entity == &isp->isp_ccp2.subdev.entity) |
| 2531 | ccdc->input = CCDC_INPUT_CCP2B; |
| 2532 | else if (remote->entity == &isp->isp_csi2a.subdev.entity) |
| 2533 | ccdc->input = CCDC_INPUT_CSI2A; |
| 2534 | else if (remote->entity == &isp->isp_csi2c.subdev.entity) |
| 2535 | ccdc->input = CCDC_INPUT_CSI2C; |
| 2536 | else |
| 2537 | ccdc->input = CCDC_INPUT_PARALLEL; |
| 2538 | |
| 2539 | break; |
| 2540 | |
| 2541 | /* |
| 2542 | * The ISP core doesn't support pipelines with multiple video outputs. |
| 2543 | * Revisit this when it will be implemented, and return -EBUSY for now. |
| 2544 | */ |
| 2545 | |
Mauro Carvalho Chehab | 59ecd59 | 2015-05-07 22:12:33 -0300 | [diff] [blame] | 2546 | case CCDC_PAD_SOURCE_VP | 2 << 16: |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2547 | /* Write to preview engine, histogram and H3A. When none of |
| 2548 | * those links are active, the video port can be disabled. |
| 2549 | */ |
| 2550 | if (flags & MEDIA_LNK_FL_ENABLED) { |
| 2551 | if (ccdc->output & ~CCDC_OUTPUT_PREVIEW) |
| 2552 | return -EBUSY; |
| 2553 | ccdc->output |= CCDC_OUTPUT_PREVIEW; |
| 2554 | } else { |
| 2555 | ccdc->output &= ~CCDC_OUTPUT_PREVIEW; |
| 2556 | } |
| 2557 | break; |
| 2558 | |
Mauro Carvalho Chehab | 59ecd59 | 2015-05-07 22:12:33 -0300 | [diff] [blame] | 2559 | case CCDC_PAD_SOURCE_OF: |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2560 | /* Write to memory */ |
| 2561 | if (flags & MEDIA_LNK_FL_ENABLED) { |
| 2562 | if (ccdc->output & ~CCDC_OUTPUT_MEMORY) |
| 2563 | return -EBUSY; |
| 2564 | ccdc->output |= CCDC_OUTPUT_MEMORY; |
| 2565 | } else { |
| 2566 | ccdc->output &= ~CCDC_OUTPUT_MEMORY; |
| 2567 | } |
| 2568 | break; |
| 2569 | |
Mauro Carvalho Chehab | 59ecd59 | 2015-05-07 22:12:33 -0300 | [diff] [blame] | 2570 | case CCDC_PAD_SOURCE_OF | 2 << 16: |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2571 | /* Write to resizer */ |
| 2572 | if (flags & MEDIA_LNK_FL_ENABLED) { |
| 2573 | if (ccdc->output & ~CCDC_OUTPUT_RESIZER) |
| 2574 | return -EBUSY; |
| 2575 | ccdc->output |= CCDC_OUTPUT_RESIZER; |
| 2576 | } else { |
| 2577 | ccdc->output &= ~CCDC_OUTPUT_RESIZER; |
| 2578 | } |
| 2579 | break; |
| 2580 | |
| 2581 | default: |
| 2582 | return -EINVAL; |
| 2583 | } |
| 2584 | |
| 2585 | return 0; |
| 2586 | } |
| 2587 | |
| 2588 | /* media operations */ |
| 2589 | static const struct media_entity_operations ccdc_media_ops = { |
| 2590 | .link_setup = ccdc_link_setup, |
Sakari Ailus | a6d7a62 | 2012-02-25 20:42:07 -0300 | [diff] [blame] | 2591 | .link_validate = v4l2_subdev_link_validate, |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2592 | }; |
| 2593 | |
Laurent Pinchart | 39099d0 | 2011-09-22 16:59:26 -0300 | [diff] [blame] | 2594 | void omap3isp_ccdc_unregister_entities(struct isp_ccdc_device *ccdc) |
| 2595 | { |
| 2596 | v4l2_device_unregister_subdev(&ccdc->subdev); |
| 2597 | omap3isp_video_unregister(&ccdc->video_out); |
| 2598 | } |
| 2599 | |
| 2600 | int omap3isp_ccdc_register_entities(struct isp_ccdc_device *ccdc, |
| 2601 | struct v4l2_device *vdev) |
| 2602 | { |
| 2603 | int ret; |
| 2604 | |
| 2605 | /* Register the subdev and video node. */ |
| 2606 | ret = v4l2_device_register_subdev(vdev, &ccdc->subdev); |
| 2607 | if (ret < 0) |
| 2608 | goto error; |
| 2609 | |
| 2610 | ret = omap3isp_video_register(&ccdc->video_out, vdev); |
| 2611 | if (ret < 0) |
| 2612 | goto error; |
| 2613 | |
| 2614 | return 0; |
| 2615 | |
| 2616 | error: |
| 2617 | omap3isp_ccdc_unregister_entities(ccdc); |
| 2618 | return ret; |
| 2619 | } |
| 2620 | |
| 2621 | /* ----------------------------------------------------------------------------- |
| 2622 | * ISP CCDC initialisation and cleanup |
| 2623 | */ |
| 2624 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2625 | /* |
| 2626 | * ccdc_init_entities - Initialize V4L2 subdev and media entity |
| 2627 | * @ccdc: ISP CCDC module |
| 2628 | * |
| 2629 | * Return 0 on success and a negative error code on failure. |
| 2630 | */ |
| 2631 | static int ccdc_init_entities(struct isp_ccdc_device *ccdc) |
| 2632 | { |
| 2633 | struct v4l2_subdev *sd = &ccdc->subdev; |
| 2634 | struct media_pad *pads = ccdc->pads; |
| 2635 | struct media_entity *me = &sd->entity; |
| 2636 | int ret; |
| 2637 | |
| 2638 | ccdc->input = CCDC_INPUT_NONE; |
| 2639 | |
| 2640 | v4l2_subdev_init(sd, &ccdc_v4l2_ops); |
| 2641 | sd->internal_ops = &ccdc_v4l2_internal_ops; |
| 2642 | strlcpy(sd->name, "OMAP3 ISP CCDC", sizeof(sd->name)); |
| 2643 | sd->grp_id = 1 << 16; /* group ID for isp subdevs */ |
| 2644 | v4l2_set_subdevdata(sd, ccdc); |
| 2645 | sd->flags |= V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_HAS_DEVNODE; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2646 | |
Sakari Ailus | 8dad936 | 2013-10-02 20:17:52 -0300 | [diff] [blame] | 2647 | pads[CCDC_PAD_SINK].flags = MEDIA_PAD_FL_SINK |
| 2648 | | MEDIA_PAD_FL_MUST_CONNECT; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2649 | pads[CCDC_PAD_SOURCE_VP].flags = MEDIA_PAD_FL_SOURCE; |
| 2650 | pads[CCDC_PAD_SOURCE_OF].flags = MEDIA_PAD_FL_SOURCE; |
| 2651 | |
| 2652 | me->ops = &ccdc_media_ops; |
Mauro Carvalho Chehab | ab22e77 | 2015-12-11 07:44:40 -0200 | [diff] [blame] | 2653 | ret = media_entity_pads_init(me, CCDC_PADS_NUM, pads); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2654 | if (ret < 0) |
| 2655 | return ret; |
| 2656 | |
| 2657 | ccdc_init_formats(sd, NULL); |
| 2658 | |
| 2659 | ccdc->video_out.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 2660 | ccdc->video_out.ops = &ccdc_video_ops; |
| 2661 | ccdc->video_out.isp = to_isp_device(ccdc); |
| 2662 | ccdc->video_out.capture_mem = PAGE_ALIGN(4096 * 4096) * 3; |
| 2663 | ccdc->video_out.bpl_alignment = 32; |
| 2664 | |
| 2665 | ret = omap3isp_video_init(&ccdc->video_out, "CCDC"); |
| 2666 | if (ret < 0) |
Javier Martinez Canillas | a64860e | 2015-12-11 15:16:29 -0200 | [diff] [blame] | 2667 | goto error; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2668 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2669 | return 0; |
Laurent Pinchart | 9b6390b | 2011-09-22 17:10:30 -0300 | [diff] [blame] | 2670 | |
Javier Martinez Canillas | a64860e | 2015-12-11 15:16:29 -0200 | [diff] [blame] | 2671 | error: |
Laurent Pinchart | 9b6390b | 2011-09-22 17:10:30 -0300 | [diff] [blame] | 2672 | media_entity_cleanup(me); |
| 2673 | return ret; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2674 | } |
| 2675 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2676 | /* |
| 2677 | * omap3isp_ccdc_init - CCDC module initialization. |
Lad, Prabhakar | 872aba5 | 2014-02-21 09:07:23 -0300 | [diff] [blame] | 2678 | * @isp: Device pointer specific to the OMAP3 ISP. |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2679 | * |
| 2680 | * TODO: Get the initialisation values from platform data. |
| 2681 | * |
| 2682 | * Return 0 on success or a negative error code otherwise. |
| 2683 | */ |
| 2684 | int omap3isp_ccdc_init(struct isp_device *isp) |
| 2685 | { |
| 2686 | struct isp_ccdc_device *ccdc = &isp->isp_ccdc; |
Laurent Pinchart | 9b6390b | 2011-09-22 17:10:30 -0300 | [diff] [blame] | 2687 | int ret; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2688 | |
| 2689 | spin_lock_init(&ccdc->lock); |
| 2690 | init_waitqueue_head(&ccdc->wait); |
| 2691 | mutex_init(&ccdc->ioctl_lock); |
| 2692 | |
| 2693 | ccdc->stopping = CCDC_STOP_NOT_REQUESTED; |
| 2694 | |
| 2695 | INIT_WORK(&ccdc->lsc.table_work, ccdc_lsc_free_table_work); |
| 2696 | ccdc->lsc.state = LSC_STATE_STOPPED; |
| 2697 | INIT_LIST_HEAD(&ccdc->lsc.free_queue); |
| 2698 | spin_lock_init(&ccdc->lsc.req_lock); |
| 2699 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2700 | ccdc->clamp.oblen = 0; |
| 2701 | ccdc->clamp.dcsubval = 0; |
| 2702 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2703 | ccdc->update = OMAP3ISP_CCDC_BLCLAMP; |
| 2704 | ccdc_apply_controls(ccdc); |
| 2705 | |
Laurent Pinchart | 9b6390b | 2011-09-22 17:10:30 -0300 | [diff] [blame] | 2706 | ret = ccdc_init_entities(ccdc); |
| 2707 | if (ret < 0) { |
| 2708 | mutex_destroy(&ccdc->ioctl_lock); |
| 2709 | return ret; |
| 2710 | } |
| 2711 | |
| 2712 | return 0; |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | /* |
| 2716 | * omap3isp_ccdc_cleanup - CCDC module cleanup. |
Lad, Prabhakar | 872aba5 | 2014-02-21 09:07:23 -0300 | [diff] [blame] | 2717 | * @isp: Device pointer specific to the OMAP3 ISP. |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2718 | */ |
| 2719 | void omap3isp_ccdc_cleanup(struct isp_device *isp) |
| 2720 | { |
| 2721 | struct isp_ccdc_device *ccdc = &isp->isp_ccdc; |
| 2722 | |
Laurent Pinchart | 63b4ca2 | 2011-09-22 16:54:34 -0300 | [diff] [blame] | 2723 | omap3isp_video_cleanup(&ccdc->video_out); |
| 2724 | media_entity_cleanup(&ccdc->subdev.entity); |
| 2725 | |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2726 | /* Free LSC requests. As the CCDC is stopped there's no active request, |
| 2727 | * so only the pending request and the free queue need to be handled. |
| 2728 | */ |
| 2729 | ccdc_lsc_free_request(ccdc, ccdc->lsc.request); |
| 2730 | cancel_work_sync(&ccdc->lsc.table_work); |
| 2731 | ccdc_lsc_free_queue(ccdc, &ccdc->lsc.free_queue); |
| 2732 | |
Laurent Pinchart | c60e153 | 2014-01-02 20:06:08 -0300 | [diff] [blame] | 2733 | if (ccdc->fpc.addr != NULL) |
| 2734 | dma_free_coherent(isp->dev, ccdc->fpc.fpnum * 4, ccdc->fpc.addr, |
| 2735 | ccdc->fpc.dma); |
Laurent Pinchart | ed33ac8 | 2011-09-22 17:09:26 -0300 | [diff] [blame] | 2736 | |
| 2737 | mutex_destroy(&ccdc->ioctl_lock); |
Laurent Pinchart | de1135d | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 2738 | } |