Lines Matching +full:isp +full:- +full:0

1 // SPDX-License-Identifier: GPL-2.0-only
5 * TI OMAP3 ISP driver - Preview module
20 #include "isp.h"
26 { /* RGB-RGB Matrix */
27 {0x01E2, 0x0F30, 0x0FEE},
28 {0x0F9B, 0x01AC, 0x0FB9},
29 {0x0FE0, 0x0EC0, 0x0260}
31 {0x0000, 0x0000, 0x0000}
38 {-38, -75, 112},
39 {112, -94 , -18}
41 {0x0, 0x0, 0x0}
45 #define FLR_CFA_GRADTHRS_HORZ 0x28
46 #define FLR_CFA_GRADTHRS_VERT 0x28
49 #define FLR_CSUP_GAIN 0x0D
50 #define FLR_CSUP_THRES 0xEB
53 #define FLR_NF_STRGTH 0x03
56 #define FLR_WBAL_DGAIN 0x100
57 #define FLR_WBAL_COEF 0x20
60 #define FLR_BLKADJ_BLUE 0x0
61 #define FLR_BLKADJ_GREEN 0x0
62 #define FLR_BLKADJ_RED 0x0
64 #define DEF_DETECT_CORRECT_VAL 0xe
85 * -------------------------------------------------------------
105 #define PREV_MIN_OUT_WIDTH 0
106 #define PREV_MIN_OUT_HEIGHT 0
125 * Default Gamma Correction Table - All components
146 * preview_config_luma_enhancement - Configure the Luminance Enhancement table
152 struct isp_device *isp = to_isp_device(prev); in preview_config_luma_enhancement() local
153 const struct omap3isp_prev_luma *yt = &params->luma; in preview_config_luma_enhancement()
156 isp_reg_writel(isp, ISPPRV_YENH_TABLE_ADDR, in preview_config_luma_enhancement()
158 for (i = 0; i < OMAP3ISP_PREV_YENH_TBL_SIZE; i++) { in preview_config_luma_enhancement()
159 isp_reg_writel(isp, yt->table[i], in preview_config_luma_enhancement()
165 * preview_enable_luma_enhancement - Enable/disable Luminance Enhancement
170 struct isp_device *isp = to_isp_device(prev); in preview_enable_luma_enhancement() local
173 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_luma_enhancement()
176 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_luma_enhancement()
181 * preview_enable_invalaw - Enable/disable Inverse A-Law decompression
185 struct isp_device *isp = to_isp_device(prev); in preview_enable_invalaw() local
188 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_invalaw()
191 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_invalaw()
196 * preview_config_hmed - Configure the Horizontal Median Filter
201 struct isp_device *isp = to_isp_device(prev); in preview_config_hmed() local
202 const struct omap3isp_prev_hmed *hmed = &params->hmed; in preview_config_hmed()
204 isp_reg_writel(isp, (hmed->odddist == 1 ? 0 : ISPPRV_HMED_ODDDIST) | in preview_config_hmed()
205 (hmed->evendist == 1 ? 0 : ISPPRV_HMED_EVENDIST) | in preview_config_hmed()
206 (hmed->thres << ISPPRV_HMED_THRESHOLD_SHIFT), in preview_config_hmed()
211 * preview_enable_hmed - Enable/disable the Horizontal Median Filter
215 struct isp_device *isp = to_isp_device(prev); in preview_enable_hmed() local
218 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_hmed()
221 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_hmed()
226 * preview_config_cfa - Configure CFA Interpolation for Bayer formats
231 * reordered to support non-GRBG Bayer patterns.
237 { 0, 1, 2, 3 }, /* GRBG */ in preview_config_cfa()
238 { 1, 0, 3, 2 }, /* RGGB */ in preview_config_cfa()
239 { 2, 3, 0, 1 }, /* BGGR */ in preview_config_cfa()
240 { 3, 2, 1, 0 }, /* GBRG */ in preview_config_cfa()
242 const unsigned int *order = cfa_coef_order[prev->params.cfa_order]; in preview_config_cfa()
243 const struct omap3isp_prev_cfa *cfa = &params->cfa; in preview_config_cfa()
244 struct isp_device *isp = to_isp_device(prev); in preview_config_cfa() local
248 isp_reg_writel(isp, in preview_config_cfa()
249 (cfa->gradthrs_vert << ISPPRV_CFA_GRADTH_VER_SHIFT) | in preview_config_cfa()
250 (cfa->gradthrs_horz << ISPPRV_CFA_GRADTH_HOR_SHIFT), in preview_config_cfa()
253 isp_reg_writel(isp, ISPPRV_CFA_TABLE_ADDR, in preview_config_cfa()
256 for (i = 0; i < 4; ++i) { in preview_config_cfa()
257 const __u32 *block = cfa->table[order[i]]; in preview_config_cfa()
259 for (j = 0; j < OMAP3ISP_PREV_CFA_BLK_SIZE; ++j) in preview_config_cfa()
260 isp_reg_writel(isp, block[j], OMAP3_ISP_IOMEM_PREV, in preview_config_cfa()
266 * preview_config_chroma_suppression - Configure Chroma Suppression
272 struct isp_device *isp = to_isp_device(prev); in preview_config_chroma_suppression() local
273 const struct omap3isp_prev_csup *cs = &params->csup; in preview_config_chroma_suppression()
275 isp_reg_writel(isp, in preview_config_chroma_suppression()
276 cs->gain | (cs->thres << ISPPRV_CSUP_THRES_SHIFT) | in preview_config_chroma_suppression()
277 (cs->hypf_en << ISPPRV_CSUP_HPYF_SHIFT), in preview_config_chroma_suppression()
282 * preview_enable_chroma_suppression - Enable/disable Chrominance Suppression
287 struct isp_device *isp = to_isp_device(prev); in preview_enable_chroma_suppression() local
290 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_chroma_suppression()
293 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_chroma_suppression()
298 * preview_config_whitebalance - Configure White Balance parameters
306 struct isp_device *isp = to_isp_device(prev); in preview_config_whitebalance() local
307 const struct omap3isp_prev_wbal *wbal = &params->wbal; in preview_config_whitebalance()
310 isp_reg_writel(isp, wbal->dgain, OMAP3_ISP_IOMEM_PREV, ISPPRV_WB_DGAIN); in preview_config_whitebalance()
312 val = wbal->coef0 << ISPPRV_WBGAIN_COEF0_SHIFT; in preview_config_whitebalance()
313 val |= wbal->coef1 << ISPPRV_WBGAIN_COEF1_SHIFT; in preview_config_whitebalance()
314 val |= wbal->coef2 << ISPPRV_WBGAIN_COEF2_SHIFT; in preview_config_whitebalance()
315 val |= wbal->coef3 << ISPPRV_WBGAIN_COEF3_SHIFT; in preview_config_whitebalance()
316 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_WBGAIN); in preview_config_whitebalance()
318 isp_reg_writel(isp, in preview_config_whitebalance()
339 * preview_config_blkadj - Configure Black Adjustment
345 struct isp_device *isp = to_isp_device(prev); in preview_config_blkadj() local
346 const struct omap3isp_prev_blkadj *blkadj = &params->blkadj; in preview_config_blkadj()
348 isp_reg_writel(isp, (blkadj->blue << ISPPRV_BLKADJOFF_B_SHIFT) | in preview_config_blkadj()
349 (blkadj->green << ISPPRV_BLKADJOFF_G_SHIFT) | in preview_config_blkadj()
350 (blkadj->red << ISPPRV_BLKADJOFF_R_SHIFT), in preview_config_blkadj()
355 * preview_config_rgb_blending - Configure RGB-RGB Blending
361 struct isp_device *isp = to_isp_device(prev); in preview_config_rgb_blending() local
362 const struct omap3isp_prev_rgbtorgb *rgbrgb = &params->rgb2rgb; in preview_config_rgb_blending()
365 val = (rgbrgb->matrix[0][0] & 0xfff) << ISPPRV_RGB_MAT1_MTX_RR_SHIFT; in preview_config_rgb_blending()
366 val |= (rgbrgb->matrix[0][1] & 0xfff) << ISPPRV_RGB_MAT1_MTX_GR_SHIFT; in preview_config_rgb_blending()
367 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_MAT1); in preview_config_rgb_blending()
369 val = (rgbrgb->matrix[0][2] & 0xfff) << ISPPRV_RGB_MAT2_MTX_BR_SHIFT; in preview_config_rgb_blending()
370 val |= (rgbrgb->matrix[1][0] & 0xfff) << ISPPRV_RGB_MAT2_MTX_RG_SHIFT; in preview_config_rgb_blending()
371 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_MAT2); in preview_config_rgb_blending()
373 val = (rgbrgb->matrix[1][1] & 0xfff) << ISPPRV_RGB_MAT3_MTX_GG_SHIFT; in preview_config_rgb_blending()
374 val |= (rgbrgb->matrix[1][2] & 0xfff) << ISPPRV_RGB_MAT3_MTX_BG_SHIFT; in preview_config_rgb_blending()
375 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_MAT3); in preview_config_rgb_blending()
377 val = (rgbrgb->matrix[2][0] & 0xfff) << ISPPRV_RGB_MAT4_MTX_RB_SHIFT; in preview_config_rgb_blending()
378 val |= (rgbrgb->matrix[2][1] & 0xfff) << ISPPRV_RGB_MAT4_MTX_GB_SHIFT; in preview_config_rgb_blending()
379 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_MAT4); in preview_config_rgb_blending()
381 val = (rgbrgb->matrix[2][2] & 0xfff) << ISPPRV_RGB_MAT5_MTX_BB_SHIFT; in preview_config_rgb_blending()
382 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_MAT5); in preview_config_rgb_blending()
384 val = (rgbrgb->offset[0] & 0x3ff) << ISPPRV_RGB_OFF1_MTX_OFFR_SHIFT; in preview_config_rgb_blending()
385 val |= (rgbrgb->offset[1] & 0x3ff) << ISPPRV_RGB_OFF1_MTX_OFFG_SHIFT; in preview_config_rgb_blending()
386 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_OFF1); in preview_config_rgb_blending()
388 val = (rgbrgb->offset[2] & 0x3ff) << ISPPRV_RGB_OFF2_MTX_OFFB_SHIFT; in preview_config_rgb_blending()
389 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_OFF2); in preview_config_rgb_blending()
393 * preview_config_csc - Configure Color Space Conversion (RGB to YCbYCr)
399 struct isp_device *isp = to_isp_device(prev); in preview_config_csc() local
400 const struct omap3isp_prev_csc *csc = &params->csc; in preview_config_csc()
403 val = (csc->matrix[0][0] & 0x3ff) << ISPPRV_CSC0_RY_SHIFT; in preview_config_csc()
404 val |= (csc->matrix[0][1] & 0x3ff) << ISPPRV_CSC0_GY_SHIFT; in preview_config_csc()
405 val |= (csc->matrix[0][2] & 0x3ff) << ISPPRV_CSC0_BY_SHIFT; in preview_config_csc()
406 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_CSC0); in preview_config_csc()
408 val = (csc->matrix[1][0] & 0x3ff) << ISPPRV_CSC1_RCB_SHIFT; in preview_config_csc()
409 val |= (csc->matrix[1][1] & 0x3ff) << ISPPRV_CSC1_GCB_SHIFT; in preview_config_csc()
410 val |= (csc->matrix[1][2] & 0x3ff) << ISPPRV_CSC1_BCB_SHIFT; in preview_config_csc()
411 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_CSC1); in preview_config_csc()
413 val = (csc->matrix[2][0] & 0x3ff) << ISPPRV_CSC2_RCR_SHIFT; in preview_config_csc()
414 val |= (csc->matrix[2][1] & 0x3ff) << ISPPRV_CSC2_GCR_SHIFT; in preview_config_csc()
415 val |= (csc->matrix[2][2] & 0x3ff) << ISPPRV_CSC2_BCR_SHIFT; in preview_config_csc()
416 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_CSC2); in preview_config_csc()
418 val = (csc->offset[0] & 0xff) << ISPPRV_CSC_OFFSET_Y_SHIFT; in preview_config_csc()
419 val |= (csc->offset[1] & 0xff) << ISPPRV_CSC_OFFSET_CB_SHIFT; in preview_config_csc()
420 val |= (csc->offset[2] & 0xff) << ISPPRV_CSC_OFFSET_CR_SHIFT; in preview_config_csc()
421 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_CSC_OFFSET); in preview_config_csc()
425 * preview_config_yc_range - Configure the max and min Y and C values
431 struct isp_device *isp = to_isp_device(prev); in preview_config_yc_range() local
432 const struct omap3isp_prev_yclimit *yc = &params->yclimit; in preview_config_yc_range()
434 isp_reg_writel(isp, in preview_config_yc_range()
435 yc->maxC << ISPPRV_SETUP_YC_MAXC_SHIFT | in preview_config_yc_range()
436 yc->maxY << ISPPRV_SETUP_YC_MAXY_SHIFT | in preview_config_yc_range()
437 yc->minC << ISPPRV_SETUP_YC_MINC_SHIFT | in preview_config_yc_range()
438 yc->minY << ISPPRV_SETUP_YC_MINY_SHIFT, in preview_config_yc_range()
443 * preview_config_dcor - Configure Couplet Defect Correction
449 struct isp_device *isp = to_isp_device(prev); in preview_config_dcor() local
450 const struct omap3isp_prev_dcor *dcor = &params->dcor; in preview_config_dcor()
452 isp_reg_writel(isp, dcor->detect_correct[0], in preview_config_dcor()
454 isp_reg_writel(isp, dcor->detect_correct[1], in preview_config_dcor()
456 isp_reg_writel(isp, dcor->detect_correct[2], in preview_config_dcor()
458 isp_reg_writel(isp, dcor->detect_correct[3], in preview_config_dcor()
460 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_config_dcor()
462 dcor->couplet_mode_en ? ISPPRV_PCR_DCCOUP : 0); in preview_config_dcor()
466 * preview_enable_dcor - Enable/disable Couplet Defect Correction
470 struct isp_device *isp = to_isp_device(prev); in preview_enable_dcor() local
473 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_dcor()
476 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_dcor()
481 * preview_enable_drkframe_capture - Enable/disable Dark Frame Capture
486 struct isp_device *isp = to_isp_device(prev); in preview_enable_drkframe_capture() local
489 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_drkframe_capture()
492 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_drkframe_capture()
497 * preview_enable_drkframe - Enable/disable Dark Frame Subtraction
501 struct isp_device *isp = to_isp_device(prev); in preview_enable_drkframe() local
504 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_drkframe()
507 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_drkframe()
512 * preview_config_noisefilter - Configure the Noise Filter
518 struct isp_device *isp = to_isp_device(prev); in preview_config_noisefilter() local
519 const struct omap3isp_prev_nf *nf = &params->nf; in preview_config_noisefilter()
522 isp_reg_writel(isp, nf->spread, OMAP3_ISP_IOMEM_PREV, ISPPRV_NF); in preview_config_noisefilter()
523 isp_reg_writel(isp, ISPPRV_NF_TABLE_ADDR, in preview_config_noisefilter()
525 for (i = 0; i < OMAP3ISP_PREV_NF_TBL_SIZE; i++) { in preview_config_noisefilter()
526 isp_reg_writel(isp, nf->table[i], in preview_config_noisefilter()
532 * preview_enable_noisefilter - Enable/disable the Noise Filter
537 struct isp_device *isp = to_isp_device(prev); in preview_enable_noisefilter() local
540 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_noisefilter()
543 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_noisefilter()
548 * preview_config_gammacorrn - Configure the Gamma Correction tables
554 struct isp_device *isp = to_isp_device(prev); in preview_config_gammacorrn() local
555 const struct omap3isp_prev_gtables *gt = &params->gamma; in preview_config_gammacorrn()
558 isp_reg_writel(isp, ISPPRV_REDGAMMA_TABLE_ADDR, in preview_config_gammacorrn()
560 for (i = 0; i < OMAP3ISP_PREV_GAMMA_TBL_SIZE; i++) in preview_config_gammacorrn()
561 isp_reg_writel(isp, gt->red[i], OMAP3_ISP_IOMEM_PREV, in preview_config_gammacorrn()
564 isp_reg_writel(isp, ISPPRV_GREENGAMMA_TABLE_ADDR, in preview_config_gammacorrn()
566 for (i = 0; i < OMAP3ISP_PREV_GAMMA_TBL_SIZE; i++) in preview_config_gammacorrn()
567 isp_reg_writel(isp, gt->green[i], OMAP3_ISP_IOMEM_PREV, in preview_config_gammacorrn()
570 isp_reg_writel(isp, ISPPRV_BLUEGAMMA_TABLE_ADDR, in preview_config_gammacorrn()
572 for (i = 0; i < OMAP3ISP_PREV_GAMMA_TBL_SIZE; i++) in preview_config_gammacorrn()
573 isp_reg_writel(isp, gt->blue[i], OMAP3_ISP_IOMEM_PREV, in preview_config_gammacorrn()
578 * preview_enable_gammacorrn - Enable/disable Gamma Correction
581 * the 8 MSB of the 10-bit input .
586 struct isp_device *isp = to_isp_device(prev); in preview_enable_gammacorrn() local
589 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_gammacorrn()
592 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_gammacorrn()
597 * preview_config_contrast - Configure the Contrast
605 struct isp_device *isp = to_isp_device(prev); in preview_config_contrast() local
607 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_CNT_BRT, in preview_config_contrast()
608 0xff << ISPPRV_CNT_BRT_CNT_SHIFT, in preview_config_contrast()
609 params->contrast << ISPPRV_CNT_BRT_CNT_SHIFT); in preview_config_contrast()
613 * preview_config_brightness - Configure the Brightness
619 struct isp_device *isp = to_isp_device(prev); in preview_config_brightness() local
621 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_CNT_BRT, in preview_config_brightness()
622 0xff << ISPPRV_CNT_BRT_BRT_SHIFT, in preview_config_brightness()
623 params->brightness << ISPPRV_CNT_BRT_BRT_SHIFT); in preview_config_brightness()
627 * preview_update_contrast - Updates the contrast.
638 spin_lock_irqsave(&prev->params.lock, flags); in preview_update_contrast()
639 params = (prev->params.active & OMAP3ISP_PREV_CONTRAST) in preview_update_contrast()
640 ? &prev->params.params[0] : &prev->params.params[1]; in preview_update_contrast()
642 if (params->contrast != (contrast * ISPPRV_CONTRAST_UNITS)) { in preview_update_contrast()
643 params->contrast = contrast * ISPPRV_CONTRAST_UNITS; in preview_update_contrast()
644 params->update |= OMAP3ISP_PREV_CONTRAST; in preview_update_contrast()
646 spin_unlock_irqrestore(&prev->params.lock, flags); in preview_update_contrast()
650 * preview_update_brightness - Updates the brightness in preview module.
660 spin_lock_irqsave(&prev->params.lock, flags); in preview_update_brightness()
661 params = (prev->params.active & OMAP3ISP_PREV_BRIGHTNESS) in preview_update_brightness()
662 ? &prev->params.params[0] : &prev->params.params[1]; in preview_update_brightness()
664 if (params->brightness != (brightness * ISPPRV_BRIGHT_UNITS)) { in preview_update_brightness()
665 params->brightness = brightness * ISPPRV_BRIGHT_UNITS; in preview_update_brightness()
666 params->update |= OMAP3ISP_PREV_BRIGHTNESS; in preview_update_brightness()
668 spin_unlock_irqrestore(&prev->params.lock, flags); in preview_update_brightness()
674 u32 active = prev->params.active; in preview_params_lock()
678 prev->params.params[0].busy |= ~active & update; in preview_params_lock()
679 prev->params.params[1].busy |= active & update; in preview_params_lock()
682 update = (prev->params.params[0].update & active) in preview_params_lock()
683 | (prev->params.params[1].update & ~active); in preview_params_lock()
685 prev->params.params[0].busy |= active & update; in preview_params_lock()
686 prev->params.params[1].busy |= ~active & update; in preview_params_lock()
695 u32 active = prev->params.active; in preview_params_unlock()
701 prev->params.params[0].update |= (~active & update); in preview_params_unlock()
702 prev->params.params[1].update |= (active & update); in preview_params_unlock()
703 prev->params.params[0].busy &= active; in preview_params_unlock()
704 prev->params.params[1].busy &= ~active; in preview_params_unlock()
709 prev->params.params[0].update &= ~(active & update); in preview_params_unlock()
710 prev->params.params[1].update &= ~(~active & update); in preview_params_unlock()
711 prev->params.params[0].busy &= ~active; in preview_params_unlock()
712 prev->params.params[1].busy &= active; in preview_params_unlock()
724 to_switch = (prev->params.params[0].update & ~prev->params.active) in preview_params_switch()
725 | (prev->params.params[1].update & prev->params.active); in preview_params_switch()
726 to_switch &= ~(prev->params.params[0].busy | in preview_params_switch()
727 prev->params.params[1].busy); in preview_params_switch()
728 if (to_switch == 0) in preview_params_switch()
731 prev->params.active ^= to_switch; in preview_params_switch()
736 prev->params.params[0].update &= ~(~prev->params.active & to_switch); in preview_params_switch()
737 prev->params.params[1].update &= ~(prev->params.active & to_switch); in preview_params_switch()
842 0, 0, 0, true,
846 0, 0, 0, true,
851 * preview_config - Copy and update local structure with userspace preview
853 * @prev: ISP preview engine
856 * Return zero if success or -EFAULT if the configuration can't be copied from
864 int rval = 0; in preview_config()
868 if (cfg->update == 0) in preview_config()
869 return 0; in preview_config()
872 spin_lock_irqsave(&prev->params.lock, flags); in preview_config()
873 preview_params_lock(prev, cfg->update, true); in preview_config()
874 active = prev->params.active; in preview_config()
875 spin_unlock_irqrestore(&prev->params.lock, flags); in preview_config()
877 update = 0; in preview_config()
879 for (i = 0; i < ARRAY_SIZE(update_attrs); i++) { in preview_config()
884 if (attr->skip || !(cfg->update & bit)) in preview_config()
887 params = &prev->params.params[!!(active & bit)]; in preview_config()
889 if (cfg->flag & bit) { in preview_config()
891 ((void *)cfg + attr->config_offset); in preview_config()
892 void *to = (void *)params + attr->param_offset; in preview_config()
893 size_t size = attr->param_size; in preview_config()
897 rval = -EFAULT; in preview_config()
901 params->features |= bit; in preview_config()
903 params->features &= ~bit; in preview_config()
909 spin_lock_irqsave(&prev->params.lock, flags); in preview_config()
912 spin_unlock_irqrestore(&prev->params.lock, flags); in preview_config()
918 * preview_setup_hw - Setup preview registers and/or internal memory
921 * @active: Bitmask of parameters active in set 0
930 if (update == 0) in preview_setup_hw()
933 for (i = 0; i < ARRAY_SIZE(update_attrs); i++) { in preview_setup_hw()
941 params = &prev->params.params[!(active & bit)]; in preview_setup_hw()
943 if (params->features & bit) { in preview_setup_hw()
944 if (attr->config) in preview_setup_hw()
945 attr->config(prev, params); in preview_setup_hw()
946 if (attr->enable) in preview_setup_hw()
947 attr->enable(prev, true); in preview_setup_hw()
949 if (attr->enable) in preview_setup_hw()
950 attr->enable(prev, false); in preview_setup_hw()
956 * preview_config_ycpos - Configure byte layout of YUV image.
962 struct isp_device *isp = to_isp_device(prev); in preview_config_ycpos() local
976 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_config_ycpos()
982 * preview_config_averager - Enable / disable / configure averager
987 struct isp_device *isp = to_isp_device(prev); in preview_config_averager() local
989 isp_reg_writel(isp, ISPPRV_AVE_EVENDIST_2 << ISPPRV_AVE_EVENDIST_SHIFT | in preview_config_averager()
996 * preview_config_input_format - Configure the input format
1006 * reordered to support non-GRBG Bayer patterns.
1011 struct isp_device *isp = to_isp_device(prev); in preview_config_input_format() local
1014 if (info->width == 8) in preview_config_input_format()
1015 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_config_input_format()
1018 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_config_input_format()
1021 switch (info->flavor) { in preview_config_input_format()
1023 prev->params.cfa_order = 0; in preview_config_input_format()
1026 prev->params.cfa_order = 1; in preview_config_input_format()
1029 prev->params.cfa_order = 2; in preview_config_input_format()
1032 prev->params.cfa_order = 3; in preview_config_input_format()
1035 /* Disable CFA for non-Bayer formats. */ in preview_config_input_format()
1036 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_config_input_format()
1041 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, ISPPRV_PCR_CFAEN); in preview_config_input_format()
1042 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_config_input_format()
1045 params = (prev->params.active & OMAP3ISP_PREV_CFA) in preview_config_input_format()
1046 ? &prev->params.params[0] : &prev->params.params[1]; in preview_config_input_format()
1052 * preview_config_input_size - Configure the input frame size
1064 const struct v4l2_mbus_framefmt *format = &prev->formats[PREV_PAD_SINK]; in preview_config_input_size()
1065 struct isp_device *isp = to_isp_device(prev); in preview_config_input_size() local
1066 unsigned int sph = prev->crop.left; in preview_config_input_size()
1067 unsigned int eph = prev->crop.left + prev->crop.width - 1; in preview_config_input_size()
1068 unsigned int slv = prev->crop.top; in preview_config_input_size()
1069 unsigned int elv = prev->crop.top + prev->crop.height - 1; in preview_config_input_size()
1072 if (format->code != MEDIA_BUS_FMT_Y8_1X8 && in preview_config_input_size()
1073 format->code != MEDIA_BUS_FMT_Y10_1X10) { in preview_config_input_size()
1074 sph -= 2; in preview_config_input_size()
1076 slv -= 2; in preview_config_input_size()
1080 features = (prev->params.params[0].features & active) in preview_config_input_size()
1081 | (prev->params.params[1].features & ~active); in preview_config_input_size()
1084 sph -= 2; in preview_config_input_size()
1086 slv -= 2; in preview_config_input_size()
1090 sph -= 2; in preview_config_input_size()
1094 sph -= 2; in preview_config_input_size()
1096 isp_reg_writel(isp, (sph << ISPPRV_HORZ_INFO_SPH_SHIFT) | eph, in preview_config_input_size()
1098 isp_reg_writel(isp, (slv << ISPPRV_VERT_INFO_SLV_SHIFT) | elv, in preview_config_input_size()
1103 * preview_config_inlineoffset - Configures the Read address line offset.
1115 struct isp_device *isp = to_isp_device(prev); in preview_config_inlineoffset() local
1117 isp_reg_writel(isp, offset & 0xffff, OMAP3_ISP_IOMEM_PREV, in preview_config_inlineoffset()
1122 * preview_set_inaddr - Sets memory address of input frame.
1129 struct isp_device *isp = to_isp_device(prev); in preview_set_inaddr() local
1131 isp_reg_writel(isp, addr, OMAP3_ISP_IOMEM_PREV, ISPPRV_RSDR_ADDR); in preview_set_inaddr()
1135 * preview_config_outlineoffset - Configures the Write address line offset.
1143 struct isp_device *isp = to_isp_device(prev); in preview_config_outlineoffset() local
1145 isp_reg_writel(isp, offset & 0xffff, OMAP3_ISP_IOMEM_PREV, in preview_config_outlineoffset()
1150 * preview_set_outaddr - Sets the memory address to store output frame
1157 struct isp_device *isp = to_isp_device(prev); in preview_set_outaddr() local
1159 isp_reg_writel(isp, addr, OMAP3_ISP_IOMEM_PREV, ISPPRV_WSDR_ADDR); in preview_set_outaddr()
1164 struct isp_pipeline *pipe = to_isp_pipeline(&prev->subdev.entity); in preview_adjust_bandwidth()
1165 struct isp_device *isp = to_isp_device(prev); in preview_adjust_bandwidth() local
1166 const struct v4l2_mbus_framefmt *ifmt = &prev->formats[PREV_PAD_SINK]; in preview_adjust_bandwidth()
1167 unsigned long l3_ick = pipe->l3_ick; in preview_adjust_bandwidth()
1176 if (prev->input != PREVIEW_INPUT_MEMORY) { in preview_adjust_bandwidth()
1177 isp_reg_clr(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_SDR_REQ_EXP, in preview_adjust_bandwidth()
1186 cycles_per_request = div_u64((u64)l3_ick / 2 * 256 + pipe->max_rate - 1, in preview_adjust_bandwidth()
1187 pipe->max_rate); in preview_adjust_bandwidth()
1195 timeperframe = &pipe->max_timeperframe; in preview_adjust_bandwidth()
1197 requests_per_frame = DIV_ROUND_UP(ifmt->width * 2, 256) * ifmt->height; in preview_adjust_bandwidth()
1198 cycles_per_frame = div_u64((u64)l3_ick * timeperframe->numerator, in preview_adjust_bandwidth()
1199 timeperframe->denominator); in preview_adjust_bandwidth()
1206 dev_dbg(isp->dev, "%s: cycles per request = %u\n", __func__, value); in preview_adjust_bandwidth()
1207 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_SDR_REQ_EXP, in preview_adjust_bandwidth()
1213 * omap3isp_preview_busy - Gets busy state of preview module.
1217 struct isp_device *isp = to_isp_device(prev); in omap3isp_preview_busy() local
1219 return isp_reg_readl(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR) in omap3isp_preview_busy()
1224 * omap3isp_preview_restore_context - Restores the values of preview registers
1226 void omap3isp_preview_restore_context(struct isp_device *isp) in omap3isp_preview_restore_context() argument
1228 struct isp_prev_device *prev = &isp->isp_prev; in omap3isp_preview_restore_context()
1229 const u32 update = OMAP3ISP_PREV_FEATURES_END - 1; in omap3isp_preview_restore_context()
1231 prev->params.params[0].update = prev->params.active & update; in omap3isp_preview_restore_context()
1232 prev->params.params[1].update = ~prev->params.active & update; in omap3isp_preview_restore_context()
1234 preview_setup_hw(prev, update, prev->params.active); in omap3isp_preview_restore_context()
1236 prev->params.params[0].update = 0; in omap3isp_preview_restore_context()
1237 prev->params.params[1].update = 0; in omap3isp_preview_restore_context()
1241 * preview_print_status - Dump preview module registers to the kernel log
1243 #define PREV_PRINT_REGISTER(isp, name)\ argument
1244 dev_dbg(isp->dev, "###PRV " #name "=0x%08x\n", \
1245 isp_reg_readl(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_##name))
1249 struct isp_device *isp = to_isp_device(prev); in preview_print_status() local
1251 dev_dbg(isp->dev, "-------------Preview Register dump----------\n"); in preview_print_status()
1253 PREV_PRINT_REGISTER(isp, PCR); in preview_print_status()
1254 PREV_PRINT_REGISTER(isp, HORZ_INFO); in preview_print_status()
1255 PREV_PRINT_REGISTER(isp, VERT_INFO); in preview_print_status()
1256 PREV_PRINT_REGISTER(isp, RSDR_ADDR); in preview_print_status()
1257 PREV_PRINT_REGISTER(isp, RADR_OFFSET); in preview_print_status()
1258 PREV_PRINT_REGISTER(isp, DSDR_ADDR); in preview_print_status()
1259 PREV_PRINT_REGISTER(isp, DRKF_OFFSET); in preview_print_status()
1260 PREV_PRINT_REGISTER(isp, WSDR_ADDR); in preview_print_status()
1261 PREV_PRINT_REGISTER(isp, WADD_OFFSET); in preview_print_status()
1262 PREV_PRINT_REGISTER(isp, AVE); in preview_print_status()
1263 PREV_PRINT_REGISTER(isp, HMED); in preview_print_status()
1264 PREV_PRINT_REGISTER(isp, NF); in preview_print_status()
1265 PREV_PRINT_REGISTER(isp, WB_DGAIN); in preview_print_status()
1266 PREV_PRINT_REGISTER(isp, WBGAIN); in preview_print_status()
1267 PREV_PRINT_REGISTER(isp, WBSEL); in preview_print_status()
1268 PREV_PRINT_REGISTER(isp, CFA); in preview_print_status()
1269 PREV_PRINT_REGISTER(isp, BLKADJOFF); in preview_print_status()
1270 PREV_PRINT_REGISTER(isp, RGB_MAT1); in preview_print_status()
1271 PREV_PRINT_REGISTER(isp, RGB_MAT2); in preview_print_status()
1272 PREV_PRINT_REGISTER(isp, RGB_MAT3); in preview_print_status()
1273 PREV_PRINT_REGISTER(isp, RGB_MAT4); in preview_print_status()
1274 PREV_PRINT_REGISTER(isp, RGB_MAT5); in preview_print_status()
1275 PREV_PRINT_REGISTER(isp, RGB_OFF1); in preview_print_status()
1276 PREV_PRINT_REGISTER(isp, RGB_OFF2); in preview_print_status()
1277 PREV_PRINT_REGISTER(isp, CSC0); in preview_print_status()
1278 PREV_PRINT_REGISTER(isp, CSC1); in preview_print_status()
1279 PREV_PRINT_REGISTER(isp, CSC2); in preview_print_status()
1280 PREV_PRINT_REGISTER(isp, CSC_OFFSET); in preview_print_status()
1281 PREV_PRINT_REGISTER(isp, CNT_BRT); in preview_print_status()
1282 PREV_PRINT_REGISTER(isp, CSUP); in preview_print_status()
1283 PREV_PRINT_REGISTER(isp, SETUP_YC); in preview_print_status()
1284 PREV_PRINT_REGISTER(isp, SET_TBL_ADDR); in preview_print_status()
1285 PREV_PRINT_REGISTER(isp, CDC_THR0); in preview_print_status()
1286 PREV_PRINT_REGISTER(isp, CDC_THR1); in preview_print_status()
1287 PREV_PRINT_REGISTER(isp, CDC_THR2); in preview_print_status()
1288 PREV_PRINT_REGISTER(isp, CDC_THR3); in preview_print_status()
1290 dev_dbg(isp->dev, "--------------------------------------------\n"); in preview_print_status()
1294 * preview_init_params - init image processing parameters.
1302 spin_lock_init(&prev->params.lock); in preview_init_params()
1304 prev->params.active = ~0; in preview_init_params()
1305 prev->params.params[0].busy = 0; in preview_init_params()
1306 prev->params.params[0].update = OMAP3ISP_PREV_FEATURES_END - 1; in preview_init_params()
1307 prev->params.params[1].busy = 0; in preview_init_params()
1308 prev->params.params[1].update = 0; in preview_init_params()
1310 params = &prev->params.params[0]; in preview_init_params()
1313 params->contrast = ISPPRV_CONTRAST_DEF * ISPPRV_CONTRAST_UNITS; in preview_init_params()
1314 params->brightness = ISPPRV_BRIGHT_DEF * ISPPRV_BRIGHT_UNITS; in preview_init_params()
1315 params->cfa.format = OMAP3ISP_CFAFMT_BAYER; in preview_init_params()
1316 memcpy(params->cfa.table, cfa_coef_table, in preview_init_params()
1317 sizeof(params->cfa.table)); in preview_init_params()
1318 params->cfa.gradthrs_horz = FLR_CFA_GRADTHRS_HORZ; in preview_init_params()
1319 params->cfa.gradthrs_vert = FLR_CFA_GRADTHRS_VERT; in preview_init_params()
1320 params->csup.gain = FLR_CSUP_GAIN; in preview_init_params()
1321 params->csup.thres = FLR_CSUP_THRES; in preview_init_params()
1322 params->csup.hypf_en = 0; in preview_init_params()
1323 memcpy(params->luma.table, luma_enhance_table, in preview_init_params()
1324 sizeof(params->luma.table)); in preview_init_params()
1325 params->nf.spread = FLR_NF_STRGTH; in preview_init_params()
1326 memcpy(params->nf.table, noise_filter_table, sizeof(params->nf.table)); in preview_init_params()
1327 params->dcor.couplet_mode_en = 1; in preview_init_params()
1328 for (i = 0; i < OMAP3ISP_PREV_DETECT_CORRECT_CHANNELS; i++) in preview_init_params()
1329 params->dcor.detect_correct[i] = DEF_DETECT_CORRECT_VAL; in preview_init_params()
1330 memcpy(params->gamma.blue, gamma_table, sizeof(params->gamma.blue)); in preview_init_params()
1331 memcpy(params->gamma.green, gamma_table, sizeof(params->gamma.green)); in preview_init_params()
1332 memcpy(params->gamma.red, gamma_table, sizeof(params->gamma.red)); in preview_init_params()
1333 params->wbal.dgain = FLR_WBAL_DGAIN; in preview_init_params()
1334 params->wbal.coef0 = FLR_WBAL_COEF; in preview_init_params()
1335 params->wbal.coef1 = FLR_WBAL_COEF; in preview_init_params()
1336 params->wbal.coef2 = FLR_WBAL_COEF; in preview_init_params()
1337 params->wbal.coef3 = FLR_WBAL_COEF; in preview_init_params()
1338 params->blkadj.red = FLR_BLKADJ_RED; in preview_init_params()
1339 params->blkadj.green = FLR_BLKADJ_GREEN; in preview_init_params()
1340 params->blkadj.blue = FLR_BLKADJ_BLUE; in preview_init_params()
1341 params->rgb2rgb = flr_rgb2rgb; in preview_init_params()
1342 params->csc = flr_prev_csc; in preview_init_params()
1343 params->yclimit.minC = ISPPRV_YC_MIN; in preview_init_params()
1344 params->yclimit.maxC = ISPPRV_YC_MAX; in preview_init_params()
1345 params->yclimit.minY = ISPPRV_YC_MIN; in preview_init_params()
1346 params->yclimit.maxY = ISPPRV_YC_MAX; in preview_init_params()
1348 params->features = OMAP3ISP_PREV_CFA | OMAP3ISP_PREV_DEFECT_COR in preview_init_params()
1357 * preview_max_out_width - Handle previewer hardware output limitations
1359 * returns maximum width output for current isp revision
1363 struct isp_device *isp = to_isp_device(prev); in preview_max_out_width() local
1365 switch (isp->revision) { in preview_max_out_width()
1380 struct isp_device *isp = to_isp_device(prev); in preview_configure() local
1387 spin_lock_irqsave(&prev->params.lock, flags); in preview_configure()
1389 update = preview_params_lock(prev, 0, false); in preview_configure()
1390 active = prev->params.active; in preview_configure()
1391 spin_unlock_irqrestore(&prev->params.lock, flags); in preview_configure()
1394 format = &prev->formats[PREV_PAD_SINK]; in preview_configure()
1395 info = omap3isp_video_format_info(format->code); in preview_configure()
1402 if (prev->input == PREVIEW_INPUT_CCDC) in preview_configure()
1403 preview_config_inlineoffset(prev, 0); in preview_configure()
1405 preview_config_inlineoffset(prev, ALIGN(format->width, 0x20) * in preview_configure()
1406 info->bpp); in preview_configure()
1411 format = &prev->formats[PREV_PAD_SOURCE]; in preview_configure()
1413 if (prev->output & PREVIEW_OUTPUT_MEMORY) in preview_configure()
1414 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_configure()
1417 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_configure()
1420 if (prev->output & PREVIEW_OUTPUT_RESIZER) in preview_configure()
1421 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_configure()
1424 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_configure()
1427 if (prev->output & PREVIEW_OUTPUT_MEMORY) in preview_configure()
1429 ALIGN(format->width, 0x10) * 2); in preview_configure()
1431 preview_config_averager(prev, 0); in preview_configure()
1432 preview_config_ycpos(prev, format->code); in preview_configure()
1434 spin_lock_irqsave(&prev->params.lock, flags); in preview_configure()
1436 spin_unlock_irqrestore(&prev->params.lock, flags); in preview_configure()
1439 /* -----------------------------------------------------------------------------
1445 struct isp_device *isp = to_isp_device(prev); in preview_enable_oneshot() local
1447 /* The PCR.SOURCE bit is automatically reset to 0 when the PCR.ENABLE in preview_enable_oneshot()
1448 * bit is set. As the preview engine is used in single-shot mode, we in preview_enable_oneshot()
1451 if (prev->input == PREVIEW_INPUT_MEMORY) in preview_enable_oneshot()
1452 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_oneshot()
1455 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR, in preview_enable_oneshot()
1467 if (prev->state == ISP_PIPELINE_STREAM_CONTINUOUS && in omap3isp_preview_isr_frame_sync()
1468 prev->video_out.dmaqueue_flags & ISP_VIDEO_DMAQUEUE_QUEUED) { in omap3isp_preview_isr_frame_sync()
1470 isp_video_dmaqueue_flags_clr(&prev->video_out); in omap3isp_preview_isr_frame_sync()
1476 struct isp_pipeline *pipe = to_isp_pipeline(&prev->subdev.entity); in preview_isr_buffer()
1478 int restart = 0; in preview_isr_buffer()
1480 if (prev->output & PREVIEW_OUTPUT_MEMORY) { in preview_isr_buffer()
1481 buffer = omap3isp_video_buffer_next(&prev->video_out); in preview_isr_buffer()
1483 preview_set_outaddr(prev, buffer->dma); in preview_isr_buffer()
1486 pipe->state |= ISP_PIPELINE_IDLE_OUTPUT; in preview_isr_buffer()
1489 if (prev->input == PREVIEW_INPUT_MEMORY) { in preview_isr_buffer()
1490 buffer = omap3isp_video_buffer_next(&prev->video_in); in preview_isr_buffer()
1492 preview_set_inaddr(prev, buffer->dma); in preview_isr_buffer()
1493 pipe->state |= ISP_PIPELINE_IDLE_INPUT; in preview_isr_buffer()
1496 switch (prev->state) { in preview_isr_buffer()
1518 * omap3isp_preview_isr - ISP preview engine interrupt handler
1528 if (omap3isp_module_sync_is_stopping(&prev->wait, &prev->stopping)) in omap3isp_preview_isr()
1531 spin_lock_irqsave(&prev->params.lock, flags); in omap3isp_preview_isr()
1533 update = preview_params_lock(prev, 0, false); in omap3isp_preview_isr()
1534 active = prev->params.active; in omap3isp_preview_isr()
1535 spin_unlock_irqrestore(&prev->params.lock, flags); in omap3isp_preview_isr()
1540 if (prev->input == PREVIEW_INPUT_MEMORY || in omap3isp_preview_isr()
1541 prev->output & PREVIEW_OUTPUT_MEMORY) in omap3isp_preview_isr()
1543 else if (prev->state == ISP_PIPELINE_STREAM_CONTINUOUS) in omap3isp_preview_isr()
1546 spin_lock_irqsave(&prev->params.lock, flags); in omap3isp_preview_isr()
1548 spin_unlock_irqrestore(&prev->params.lock, flags); in omap3isp_preview_isr()
1551 /* -----------------------------------------------------------------------------
1552 * ISP video operations
1558 struct isp_prev_device *prev = &video->isp->isp_prev; in preview_video_queue()
1560 if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) in preview_video_queue()
1561 preview_set_inaddr(prev, buffer->dma); in preview_video_queue()
1563 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) in preview_video_queue()
1564 preview_set_outaddr(prev, buffer->dma); in preview_video_queue()
1566 return 0; in preview_video_queue()
1573 /* -----------------------------------------------------------------------------
1578 * preview_s_ctrl - Handle set control subdev method
1584 container_of(ctrl->handler, struct isp_prev_device, ctrls); in preview_s_ctrl()
1586 switch (ctrl->id) { in preview_s_ctrl()
1588 preview_update_brightness(prev, ctrl->val); in preview_s_ctrl()
1591 preview_update_contrast(prev, ctrl->val); in preview_s_ctrl()
1595 return 0; in preview_s_ctrl()
1603 * preview_ioctl - Handle preview module private ioctl's
1607 * return -EINVAL or zero on success
1618 return -ENOIOCTLCMD; in preview_ioctl()
1623 * preview_set_stream - Enable/Disable streaming on preview subdev
1625 * @enable: 1 == Enable, 0 == Disable
1626 * return -EINVAL or zero on success
1631 struct isp_video *video_out = &prev->video_out; in preview_set_stream()
1632 struct isp_device *isp = to_isp_device(prev); in preview_set_stream() local
1635 if (prev->state == ISP_PIPELINE_STREAM_STOPPED) { in preview_set_stream()
1637 return 0; in preview_set_stream()
1639 omap3isp_subclk_enable(isp, OMAP3_ISP_SUBCLK_PREVIEW); in preview_set_stream()
1641 atomic_set(&prev->stopping, 0); in preview_set_stream()
1647 if (prev->output & PREVIEW_OUTPUT_MEMORY) in preview_set_stream()
1648 omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_PREVIEW_WRITE); in preview_set_stream()
1650 if (video_out->dmaqueue_flags & ISP_VIDEO_DMAQUEUE_QUEUED || in preview_set_stream()
1651 !(prev->output & PREVIEW_OUTPUT_MEMORY)) in preview_set_stream()
1658 if (prev->input == PREVIEW_INPUT_MEMORY) in preview_set_stream()
1659 omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_PREVIEW_READ); in preview_set_stream()
1660 if (prev->output & PREVIEW_OUTPUT_MEMORY) in preview_set_stream()
1661 omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_PREVIEW_WRITE); in preview_set_stream()
1667 if (omap3isp_module_sync_idle(&sd->entity, &prev->wait, in preview_set_stream()
1668 &prev->stopping)) in preview_set_stream()
1669 dev_dbg(dev, "%s: stop timeout.\n", sd->name); in preview_set_stream()
1670 omap3isp_sbl_disable(isp, OMAP3_ISP_SBL_PREVIEW_READ); in preview_set_stream()
1671 omap3isp_sbl_disable(isp, OMAP3_ISP_SBL_PREVIEW_WRITE); in preview_set_stream()
1672 omap3isp_subclk_disable(isp, OMAP3_ISP_SUBCLK_PREVIEW); in preview_set_stream()
1677 prev->state = enable; in preview_set_stream()
1678 return 0; in preview_set_stream()
1689 return &prev->formats[pad]; in __preview_get_format()
1700 return &prev->crop; in __preview_get_crop()
1723 * preview_try_format - Validate a format
1724 * @prev: ISP preview engine
1747 * as-is. in preview_try_format()
1754 if (prev->input == PREVIEW_INPUT_MEMORY) { in preview_try_format()
1755 fmt->width = clamp_t(u32, fmt->width, PREV_MIN_IN_WIDTH, in preview_try_format()
1757 fmt->height = clamp_t(u32, fmt->height, in preview_try_format()
1762 fmt->colorspace = V4L2_COLORSPACE_SRGB; in preview_try_format()
1764 for (i = 0; i < ARRAY_SIZE(preview_input_fmts); i++) { in preview_try_format()
1765 if (fmt->code == preview_input_fmts[i]) in preview_try_format()
1771 fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; in preview_try_format()
1775 pixelcode = fmt->code; in preview_try_format()
1782 fmt->code = pixelcode; in preview_try_format()
1786 fmt->code = MEDIA_BUS_FMT_YUYV8_1X16; in preview_try_format()
1796 fmt->width = crop->width; in preview_try_format()
1797 fmt->height = crop->height; in preview_try_format()
1799 fmt->colorspace = V4L2_COLORSPACE_JPEG; in preview_try_format()
1803 fmt->field = V4L2_FIELD_NONE; in preview_try_format()
1807 * preview_try_crop - Validate a crop rectangle
1808 * @prev: ISP preview engine
1823 unsigned int right = sink->width - PREV_MARGIN_RIGHT; in preview_try_crop()
1825 unsigned int bottom = sink->height - PREV_MARGIN_BOTTOM; in preview_try_crop()
1827 /* When processing data on-the-fly from the CCDC, at least 2 pixels must in preview_try_crop()
1832 if (prev->input == PREVIEW_INPUT_CCDC) { in preview_try_crop()
1834 right -= 2; in preview_try_crop()
1841 if (sink->code != MEDIA_BUS_FMT_Y8_1X8 && in preview_try_crop()
1842 sink->code != MEDIA_BUS_FMT_Y10_1X10) { in preview_try_crop()
1844 right -= 2; in preview_try_crop()
1846 bottom -= 2; in preview_try_crop()
1850 crop->left &= ~1; in preview_try_crop()
1851 crop->top &= ~1; in preview_try_crop()
1853 crop->left = clamp_t(u32, crop->left, left, right - PREV_MIN_OUT_WIDTH); in preview_try_crop()
1854 crop->top = clamp_t(u32, crop->top, top, bottom - PREV_MIN_OUT_HEIGHT); in preview_try_crop()
1855 crop->width = clamp_t(u32, crop->width, PREV_MIN_OUT_WIDTH, in preview_try_crop()
1856 right - crop->left); in preview_try_crop()
1857 crop->height = clamp_t(u32, crop->height, PREV_MIN_OUT_HEIGHT, in preview_try_crop()
1858 bottom - crop->top); in preview_try_crop()
1862 * preview_enum_mbus_code - Handle pixel format enumeration
1866 * return -EINVAL or zero on success
1872 switch (code->pad) { in preview_enum_mbus_code()
1874 if (code->index >= ARRAY_SIZE(preview_input_fmts)) in preview_enum_mbus_code()
1875 return -EINVAL; in preview_enum_mbus_code()
1877 code->code = preview_input_fmts[code->index]; in preview_enum_mbus_code()
1880 if (code->index >= ARRAY_SIZE(preview_output_fmts)) in preview_enum_mbus_code()
1881 return -EINVAL; in preview_enum_mbus_code()
1883 code->code = preview_output_fmts[code->index]; in preview_enum_mbus_code()
1886 return -EINVAL; in preview_enum_mbus_code()
1889 return 0; in preview_enum_mbus_code()
1899 if (fse->index != 0) in preview_enum_frame_size()
1900 return -EINVAL; in preview_enum_frame_size()
1902 format.code = fse->code; in preview_enum_frame_size()
1905 preview_try_format(prev, sd_state, fse->pad, &format, fse->which); in preview_enum_frame_size()
1906 fse->min_width = format.width; in preview_enum_frame_size()
1907 fse->min_height = format.height; in preview_enum_frame_size()
1909 if (format.code != fse->code) in preview_enum_frame_size()
1910 return -EINVAL; in preview_enum_frame_size()
1912 format.code = fse->code; in preview_enum_frame_size()
1913 format.width = -1; in preview_enum_frame_size()
1914 format.height = -1; in preview_enum_frame_size()
1915 preview_try_format(prev, sd_state, fse->pad, &format, fse->which); in preview_enum_frame_size()
1916 fse->max_width = format.width; in preview_enum_frame_size()
1917 fse->max_height = format.height; in preview_enum_frame_size()
1919 return 0; in preview_enum_frame_size()
1923 * preview_get_selection - Retrieve a selection rectangle on a pad
1924 * @sd: ISP preview V4L2 subdevice
1930 * Return 0 on success or a negative error code otherwise.
1939 if (sel->pad != PREV_PAD_SINK) in preview_get_selection()
1940 return -EINVAL; in preview_get_selection()
1942 switch (sel->target) { in preview_get_selection()
1944 sel->r.left = 0; in preview_get_selection()
1945 sel->r.top = 0; in preview_get_selection()
1946 sel->r.width = INT_MAX; in preview_get_selection()
1947 sel->r.height = INT_MAX; in preview_get_selection()
1950 sel->which); in preview_get_selection()
1951 preview_try_crop(prev, format, &sel->r); in preview_get_selection()
1955 sel->r = *__preview_get_crop(prev, sd_state, sel->which); in preview_get_selection()
1959 return -EINVAL; in preview_get_selection()
1962 return 0; in preview_get_selection()
1966 * preview_set_selection - Set a selection rectangle on a pad
1967 * @sd: ISP preview V4L2 subdevice
1973 * Return 0 on success or a negative error code otherwise.
1982 if (sel->target != V4L2_SEL_TGT_CROP || in preview_set_selection()
1983 sel->pad != PREV_PAD_SINK) in preview_set_selection()
1984 return -EINVAL; in preview_set_selection()
1987 if (prev->state != ISP_PIPELINE_STREAM_STOPPED) in preview_set_selection()
1988 return -EBUSY; in preview_set_selection()
1994 if (sel->flags & V4L2_SEL_FLAG_KEEP_CONFIG) { in preview_set_selection()
1995 sel->r = *__preview_get_crop(prev, sd_state, sel->which); in preview_set_selection()
1996 return 0; in preview_set_selection()
2000 sel->which); in preview_set_selection()
2001 preview_try_crop(prev, format, &sel->r); in preview_set_selection()
2002 *__preview_get_crop(prev, sd_state, sel->which) = sel->r; in preview_set_selection()
2006 sel->which); in preview_set_selection()
2008 sel->which); in preview_set_selection()
2010 return 0; in preview_set_selection()
2014 * preview_get_format - Handle get format by pads subdev method
2018 * return -EINVAL or zero on success
2027 format = __preview_get_format(prev, sd_state, fmt->pad, fmt->which); in preview_get_format()
2029 return -EINVAL; in preview_get_format()
2031 fmt->format = *format; in preview_get_format()
2032 return 0; in preview_get_format()
2036 * preview_set_format - Handle set format by pads subdev method
2040 * return -EINVAL or zero on success
2050 format = __preview_get_format(prev, sd_state, fmt->pad, fmt->which); in preview_set_format()
2052 return -EINVAL; in preview_set_format()
2054 preview_try_format(prev, sd_state, fmt->pad, &fmt->format, fmt->which); in preview_set_format()
2055 *format = fmt->format; in preview_set_format()
2058 if (fmt->pad == PREV_PAD_SINK) { in preview_set_format()
2060 crop = __preview_get_crop(prev, sd_state, fmt->which); in preview_set_format()
2061 crop->left = 0; in preview_set_format()
2062 crop->top = 0; in preview_set_format()
2063 crop->width = fmt->format.width; in preview_set_format()
2064 crop->height = fmt->format.height; in preview_set_format()
2066 preview_try_crop(prev, &fmt->format, crop); in preview_set_format()
2070 fmt->which); in preview_set_format()
2072 fmt->which); in preview_set_format()
2075 return 0; in preview_set_format()
2079 * preview_init_formats - Initialize formats on all pads
2080 * @sd: ISP preview V4L2 subdevice
2092 memset(&format, 0, sizeof(format)); in preview_init_formats()
2098 preview_set_format(sd, fh ? fh->state : NULL, &format); in preview_init_formats()
2100 return 0; in preview_init_formats()
2135 /* -----------------------------------------------------------------------------
2140 * preview_link_setup - Setup previewer connections.
2145 * return -EINVAL or zero on success
2153 unsigned int index = local->index; in preview_link_setup()
2156 if (is_media_entity_v4l2_subdev(remote->entity)) in preview_link_setup()
2163 if (prev->input == PREVIEW_INPUT_CCDC) in preview_link_setup()
2164 return -EBUSY; in preview_link_setup()
2165 prev->input = PREVIEW_INPUT_MEMORY; in preview_link_setup()
2167 if (prev->input == PREVIEW_INPUT_MEMORY) in preview_link_setup()
2168 prev->input = PREVIEW_INPUT_NONE; in preview_link_setup()
2175 if (prev->input == PREVIEW_INPUT_MEMORY) in preview_link_setup()
2176 return -EBUSY; in preview_link_setup()
2177 prev->input = PREVIEW_INPUT_CCDC; in preview_link_setup()
2179 if (prev->input == PREVIEW_INPUT_CCDC) in preview_link_setup()
2180 prev->input = PREVIEW_INPUT_NONE; in preview_link_setup()
2185 * The ISP core doesn't support pipelines with multiple video outputs. in preview_link_setup()
2186 * Revisit this when it will be implemented, and return -EBUSY for now. in preview_link_setup()
2192 if (prev->output & ~PREVIEW_OUTPUT_MEMORY) in preview_link_setup()
2193 return -EBUSY; in preview_link_setup()
2194 prev->output |= PREVIEW_OUTPUT_MEMORY; in preview_link_setup()
2196 prev->output &= ~PREVIEW_OUTPUT_MEMORY; in preview_link_setup()
2203 if (prev->output & ~PREVIEW_OUTPUT_RESIZER) in preview_link_setup()
2204 return -EBUSY; in preview_link_setup()
2205 prev->output |= PREVIEW_OUTPUT_RESIZER; in preview_link_setup()
2207 prev->output &= ~PREVIEW_OUTPUT_RESIZER; in preview_link_setup()
2212 return -EINVAL; in preview_link_setup()
2215 return 0; in preview_link_setup()
2226 v4l2_device_unregister_subdev(&prev->subdev); in omap3isp_preview_unregister_entities()
2227 omap3isp_video_unregister(&prev->video_in); in omap3isp_preview_unregister_entities()
2228 omap3isp_video_unregister(&prev->video_out); in omap3isp_preview_unregister_entities()
2237 prev->subdev.dev = vdev->mdev->dev; in omap3isp_preview_register_entities()
2238 ret = v4l2_device_register_subdev(vdev, &prev->subdev); in omap3isp_preview_register_entities()
2239 if (ret < 0) in omap3isp_preview_register_entities()
2242 ret = omap3isp_video_register(&prev->video_in, vdev); in omap3isp_preview_register_entities()
2243 if (ret < 0) in omap3isp_preview_register_entities()
2246 ret = omap3isp_video_register(&prev->video_out, vdev); in omap3isp_preview_register_entities()
2247 if (ret < 0) in omap3isp_preview_register_entities()
2250 return 0; in omap3isp_preview_register_entities()
2257 /* -----------------------------------------------------------------------------
2258 * ISP previewer initialisation and cleanup
2262 * preview_init_entities - Initialize subdev and media entity.
2264 * return -ENOMEM or zero on success
2268 struct v4l2_subdev *sd = &prev->subdev; in preview_init_entities()
2269 struct media_pad *pads = prev->pads; in preview_init_entities()
2270 struct media_entity *me = &sd->entity; in preview_init_entities()
2273 prev->input = PREVIEW_INPUT_NONE; in preview_init_entities()
2276 sd->internal_ops = &preview_v4l2_internal_ops; in preview_init_entities()
2277 strscpy(sd->name, "OMAP3 ISP preview", sizeof(sd->name)); in preview_init_entities()
2278 sd->grp_id = 1 << 16; /* group ID for isp subdevs */ in preview_init_entities()
2280 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in preview_init_entities()
2282 v4l2_ctrl_handler_init(&prev->ctrls, 2); in preview_init_entities()
2283 v4l2_ctrl_new_std(&prev->ctrls, &preview_ctrl_ops, V4L2_CID_BRIGHTNESS, in preview_init_entities()
2286 v4l2_ctrl_new_std(&prev->ctrls, &preview_ctrl_ops, V4L2_CID_CONTRAST, in preview_init_entities()
2289 v4l2_ctrl_handler_setup(&prev->ctrls); in preview_init_entities()
2290 sd->ctrl_handler = &prev->ctrls; in preview_init_entities()
2296 me->ops = &preview_media_ops; in preview_init_entities()
2298 if (ret < 0) in preview_init_entities()
2307 prev->video_in.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; in preview_init_entities()
2308 prev->video_in.ops = &preview_video_ops; in preview_init_entities()
2309 prev->video_in.isp = to_isp_device(prev); in preview_init_entities()
2310 prev->video_in.capture_mem = PAGE_ALIGN(4096 * 4096) * 2 * 3; in preview_init_entities()
2311 prev->video_in.bpl_alignment = 64; in preview_init_entities()
2312 prev->video_out.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in preview_init_entities()
2313 prev->video_out.ops = &preview_video_ops; in preview_init_entities()
2314 prev->video_out.isp = to_isp_device(prev); in preview_init_entities()
2315 prev->video_out.capture_mem = PAGE_ALIGN(4096 * 4096) * 2 * 3; in preview_init_entities()
2316 prev->video_out.bpl_alignment = 32; in preview_init_entities()
2318 ret = omap3isp_video_init(&prev->video_in, "preview"); in preview_init_entities()
2319 if (ret < 0) in preview_init_entities()
2322 ret = omap3isp_video_init(&prev->video_out, "preview"); in preview_init_entities()
2323 if (ret < 0) in preview_init_entities()
2326 return 0; in preview_init_entities()
2329 omap3isp_video_cleanup(&prev->video_in); in preview_init_entities()
2331 media_entity_cleanup(&prev->subdev.entity); in preview_init_entities()
2333 v4l2_ctrl_handler_free(&prev->ctrls); in preview_init_entities()
2338 * omap3isp_preview_init - Previewer initialization.
2339 * @isp : Pointer to ISP device
2340 * return -ENOMEM or zero on success
2342 int omap3isp_preview_init(struct isp_device *isp) in omap3isp_preview_init() argument
2344 struct isp_prev_device *prev = &isp->isp_prev; in omap3isp_preview_init()
2346 init_waitqueue_head(&prev->wait); in omap3isp_preview_init()
2353 void omap3isp_preview_cleanup(struct isp_device *isp) in omap3isp_preview_cleanup() argument
2355 struct isp_prev_device *prev = &isp->isp_prev; in omap3isp_preview_cleanup()
2357 v4l2_ctrl_handler_free(&prev->ctrls); in omap3isp_preview_cleanup()
2358 omap3isp_video_cleanup(&prev->video_in); in omap3isp_preview_cleanup()
2359 omap3isp_video_cleanup(&prev->video_out); in omap3isp_preview_cleanup()
2360 media_entity_cleanup(&prev->subdev.entity); in omap3isp_preview_cleanup()