lists.zerezo.com



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 9/15] OMAP3 camera driver: Add ISP Modules.



From: Sergio Aguirre <saaguirre@xxxxxx>

OMAP: CAM: Add ISP Modules

This adds the OMAP ISP modules to the kernel. Includes:
* ISP Core Driver
* ISP CCDC Driver
* ISP Autofocus Driver
* ISP H3A Driver
* ISP Histogram Driver
* ISP MMU Driver
* ISP Preview Driver
* ISP Resizer Driver

Signed-off-by: Sergio Aguirre <saaguirre@xxxxxx>
---
 arch/arm/plat-omap/include/mach/isp_user.h |  617 ++++++++
 drivers/media/video/isp/Kconfig            |    9
 drivers/media/video/isp/Makefile           |   19
 drivers/media/video/isp/isp.c              | 2228 +++++++++++++++++++++++++++++
 drivers/media/video/isp/isp.h              |  348 ++++
 drivers/media/video/isp/isp_af.c           |  812 ++++++++++
 drivers/media/video/isp/isp_af.h           |  139 +
 drivers/media/video/isp/ispccdc.c          | 1491 +++++++++++++++++++
 drivers/media/video/isp/ispccdc.h          |  210 ++
 drivers/media/video/isp/isph3a.c           |  915 +++++++++++
 drivers/media/video/isp/isph3a.h           |  139 +
 drivers/media/video/isp/isphist.c          |  644 ++++++++
 drivers/media/video/isp/isphist.h          |   97 +
 drivers/media/video/isp/ispmmu.c           |  735 +++++++++
 drivers/media/video/isp/ispmmu.h           |  117 +
 drivers/media/video/isp/isppreview.c       | 1868 ++++++++++++++++++++++++
 drivers/media/video/isp/isppreview.h       |  349 ++++
 drivers/media/video/isp/ispreg.h           | 1281 ++++++++++++++++
 drivers/media/video/isp/ispresizer.c       |  866 +++++++++++
 drivers/media/video/isp/ispresizer.h       |  153 +
 20 files changed, 13037 insertions(+)

Index: linux-omap-2.6/arch/arm/plat-omap/include/mach/isp_user.h
===================================================================
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ linux-omap-2.6/arch/arm/plat-omap/include/mach/isp_user.h   2008-08-28 19:08:43.000000000 -0500
@@ -0,0 +1,617 @@
+/*
+ * include/asm-arm/arch-omap/isp_user.h
+ *
+ * Include file for OMAP ISP module in TI's OMAP3430.
+ *
+ * Copyright (C) 2008 Texas Instruments, Inc.
+ *
+ * Contributors:
+ *     Mohit Jalori <mjalori@xxxxxx>
+ *
+ * This package is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifndef OMAP_ISP_USER_H
+#define OMAP_ISP_USER_H
+
+/* AE/AWB related structures and flags*/
+
+/* Flags for update field */
+#define REQUEST_STATISTICS     (1 << 0)
+#define SET_COLOR_GAINS                (1 << 1)
+#define SET_DIGITAL_GAIN       (1 << 2)
+#define SET_EXPOSURE           (1 << 3)
+#define SET_ANALOG_GAIN                (1 << 4)
+
+#define MAX_FRAME_COUNT                0x0FFF
+#define MAX_FUTURE_FRAMES      10
+
+/**
+ * struct isph3a_aewb_config - AE AWB configuration reset values.
+ * saturation_limit: Saturation limit.
+ * @win_height: Window Height. Range 2 - 256, even values only.
+ * @win_width: Window Width. Range 6 - 256, even values only.
+ * @ver_win_count: Vertical Window Count. Range 1 - 128.
+ * @hor_win_count: Horizontal Window Count. Range 1 - 36.
+ * @ver_win_start: Vertical Window Start. Range 0 - 4095.
+ * @hor_win_start: Horizontal Window Start. Range 0 - 4095.
+ * @blk_ver_win_start: Black Vertical Windows Start. Range 0 - 4095.
+ * @blk_win_height: Black Window Height. Range 2 - 256, even values only.
+ * @subsample_ver_inc: Subsample Vertical points increment Range 2 - 32, even
+ *                     values only.
+ * @subsample_hor_inc: Subsample Horizontal points increment Range 2 - 32, even
+ *                     values only.
+ * @alaw_enable: AEW ALAW EN flag.
+ * @aewb_enable: AE AWB stats generation EN flag.
+ */
+struct isph3a_aewb_config {
+       u16 saturation_limit;
+       u16 win_height;
+       u16 win_width;
+       u16 ver_win_count;
+       u16 hor_win_count;
+       u16 ver_win_start;
+       u16 hor_win_start;
+       u16 blk_ver_win_start;
+       u16 blk_win_height;
+       u16 subsample_ver_inc;
+       u16 subsample_hor_inc;
+       u8 alaw_enable;
+       u8 aewb_enable;
+};
+
+/**
+ * struct isph3a_aewb_data - Structure of data sent to or received from user
+ * @h3a_aewb_statistics_buf: Pointer to pass to user.
+ * @shutter: Shutter speed.
+ * @gain: Sensor analog Gain.
+ * @shutter_cap: Shutter speed for capture.
+ * @gain_cap: Sensor Gain for capture.
+ * @dgain: White balance digital gain.
+ * @wb_gain_b: White balance color gain blue.
+ * @wb_gain_r: White balance color gain red.
+ * @wb_gain_gb: White balance color gain green blue.
+ * @wb_gain_gr: White balance color gain green red.
+ * @frame_number: Frame number of requested stats.
+ * @curr_frame: Current frame number being processed.
+ * @update: Bitwise flags to update parameters.
+ * @ts: Timestamp of returned framestats.
+ * @field_count: Sequence number of returned framestats.
+ */
+struct isph3a_aewb_data {
+       void *h3a_aewb_statistics_buf;
+       u32 shutter;
+       u16 gain;
+       u32 shutter_cap;
+       u16 gain_cap;
+       u16 dgain;
+       u16 wb_gain_b;
+       u16 wb_gain_r;
+       u16 wb_gain_gb;
+       u16 wb_gain_gr;
+       u16 frame_number;
+       u16 curr_frame;
+       u8 update;
+       struct timeval ts;
+       unsigned long field_count;
+};
+
+
+/* Histogram related structs */
+/* Flags for number of bins */
+#define BINS_32                        0x0
+#define BINS_64                        0x1
+#define BINS_128               0x2
+#define BINS_256               0x3
+
+struct isp_hist_config {
+       u8 hist_source;         /* CCDC or Memory */
+       u8 input_bit_width;     /* Needed o know the size per pixel */
+       u8 hist_frames;         /* Num of frames to be processed and
+                                * accumulated
+                                */
+       u8 hist_h_v_info;       /* frame-input width and height if source is
+                                * memory
+                                */
+       u16 hist_radd;          /* frame-input address in memory */
+       u16 hist_radd_off;      /* line-offset for frame-input */
+       u16 hist_bins;          /* number of bins: 32, 64, 128, or 256 */
+       u16 wb_gain_R;          /* White Balance Field-to-Pattern Assignments */
+       u16 wb_gain_RG;         /* White Balance Field-to-Pattern Assignments */
+       u16 wb_gain_B;          /* White Balance Field-to-Pattern Assignments */
+       u16 wb_gain_BG;         /* White Balance Field-to-Pattern Assignments */
+       u8 num_regions;         /* number of regions to be configured */
+       u16 reg0_hor;           /* Region 0 size and position */
+       u16 reg0_ver;           /* Region 0 size and position */
+       u16 reg1_hor;           /* Region 1 size and position */
+       u16 reg1_ver;           /* Region 1 size and position */
+       u16 reg2_hor;           /* Region 2 size and position */
+       u16 reg2_ver;           /* Region 2 size and position */
+       u16 reg3_hor;           /* Region 3 size and position */
+       u16 reg3_ver;           /* Region 3 size and position */
+};
+
+struct isp_hist_data {
+       u32 *hist_statistics_buf;       /* Pointer to pass to user */
+};
+
+/* Auto Focus related structs */
+
+#define AF_NUMBER_OF_COEF              11
+
+/* Flags for update field */
+#define REQUEST_STATISTICS             (1 << 0)
+#define LENS_DESIRED_POSITION  (1 << 1)
+#define LENS_CURRENT_POSITION  (1 << 2)
+
+/**
+ * struct isp_af_xtrastats - Extra statistics related to AF generated stats.
+ * @ts: Timestamp when the frame gets delivered to the user.
+ * @field_count: Field count of the frame delivered to the user.
+ * @lens_position: Lens position when the stats are being generated.
+ */
+struct isp_af_xtrastats {
+       struct timeval ts;
+       unsigned long field_count;
+       __u16 lens_position;
+};
+
+/**
+ * struct isp_af_data - AF statistics data to transfer between driver and user.
+ * @af_statistics_buf: Pointer to pass to user.
+ * @lens_current_position: Read value of lens absolute position.
+ * @desired_lens_direction: Lens desired location.
+ * @update: Bitwise flags to update parameters.
+ * @frame_number: Data for which frame is desired/given.
+ * @curr_frame: Current frame number being processed by AF module.
+ * @xtrastats: Extra statistics structure.
+ */
+struct isp_af_data {
+       void *af_statistics_buf;
+       __u16 lens_current_position;
+       __u16 desired_lens_direction;
+       __u16 update;
+       __u16 frame_number;
+       __u16 curr_frame;
+       struct isp_af_xtrastats xtrastats;
+};
+
+/* enum used for status of specific feature */
+enum af_alaw_enable {
+       H3A_AF_ALAW_DISABLE = 0,
+       H3A_AF_ALAW_ENABLE = 1
+};
+
+enum af_hmf_enable {
+       H3A_AF_HMF_DISABLE = 0,
+       H3A_AF_HMF_ENABLE = 1
+};
+
+enum af_config_flag {
+       H3A_AF_CFG_DISABLE = 0,
+       H3A_AF_CFG_ENABLE = 1
+};
+
+enum af_mode {
+       ACCUMULATOR_SUMMED = 0,
+       ACCUMULATOR_PEAK = 1
+};
+
+/* Red, Green, and blue pixel location in the AF windows */
+enum rgbpos {
+       GR_GB_BAYER = 0,        /* GR and GB as Bayer pattern */
+       RG_GB_BAYER = 1,        /* RG and GB as Bayer pattern */
+       GR_BG_BAYER = 2,        /* GR and BG as Bayer pattern */
+       RG_BG_BAYER = 3,        /* RG and BG as Bayer pattern */
+       GG_RB_CUSTOM = 4,       /* GG and RB as custom pattern */
+       RB_GG_CUSTOM = 5        /* RB and GG as custom pattern */
+};
+
+/* Contains the information regarding the Horizontal Median Filter */
+struct af_hmf {
+       enum af_hmf_enable enable;      /* Status of Horizontal Median Filter */
+       unsigned int threshold; /* Threshhold Value for Horizontal Median
+                                * Filter
+                                */
+};
+
+/* Contains the information regarding the IIR Filters */
+struct af_iir {
+       unsigned int hz_start_pos;      /* IIR Start Register Value */
+       int coeff_set0[AF_NUMBER_OF_COEF];      /*
+                                                * IIR Filter Coefficient for
+                                                * Set 0
+                                                */
+       int coeff_set1[AF_NUMBER_OF_COEF];      /*
+                                                * IIR Filter Coefficient for
+                                                * Set 1
+                                                */
+};
+
+/* Contains the information regarding the Paxels Structure in AF Engine */
+struct af_paxel {
+       unsigned int width;     /* Width of the Paxel */
+       unsigned int height;    /* Height of the Paxel */
+       unsigned int hz_start;  /* Horizontal Start Position */
+       unsigned int vt_start;  /* Vertical Start Position */
+       unsigned int hz_cnt;    /* Horizontal Count */
+       unsigned int vt_cnt;    /* vertical Count */
+       unsigned int line_incr; /* Line Increment */
+};
+/* Contains the parameters required for hardware set up of AF Engine */
+struct af_configuration {
+       enum af_alaw_enable alaw_enable;        /*ALWAW status */
+       struct af_hmf hmf_config;       /*HMF configurations */
+       enum rgbpos rgb_pos;            /*RGB Positions */
+       struct af_iir iir_config;       /*IIR filter configurations */
+       struct af_paxel paxel_config;   /*Paxel parameters */
+       enum af_mode mode;              /*Accumulator mode */
+       enum af_config_flag af_config; /*Flag indicates Engine is configured */
+};
+
+/* ISP CCDC structs */
+
+/* Abstraction layer CCDC configurations */
+#define ISP_ABS_CCDC_ALAW              (1 << 0)
+#define ISP_ABS_CCDC_LPF               (1 << 1)
+#define ISP_ABS_CCDC_BLCLAMP           (1 << 2)
+#define ISP_ABS_CCDC_BCOMP             (1 << 3)
+#define ISP_ABS_CCDC_FPC               (1 << 4)
+#define ISP_ABS_CCDC_CULL              (1 << 5)
+#define ISP_ABS_CCDC_COLPTN            (1 << 6)
+#define ISP_ABS_CCDC_CONFIG_LSC                (1 << 7)
+#define ISP_ABS_TBL_LSC                        (1 << 8)
+
+#define RGB_MAX                                3
+
+/* Enumeration constants for Alaw input width */
+enum alaw_ipwidth {
+       ALAW_BIT12_3 = 0x3,
+       ALAW_BIT11_2 = 0x4,
+       ALAW_BIT10_1 = 0x5,
+       ALAW_BIT9_0 = 0x6
+};
+
+/* Enumeration constants for Video Port */
+enum vpin {
+       BIT12_3 = 3,
+       BIT11_2 = 4,
+       BIT10_1 = 5,
+       BIT9_0 = 6
+};
+
+enum vpif_freq {
+       PIXCLKBY2,
+       PIXCLKBY3_5,
+       PIXCLKBY4_5,
+       PIXCLKBY5_5,
+       PIXCLKBY6_5
+};
+
+/**
+ * struct ispccdc_lsc_config - Structure for LSC configuration.
+ * @offset: Table Offset of the gain table.
+ * @gain_mode_n: Vertical dimension of a paxel in LSC configuration.
+ * @gain_mode_m: Horizontal dimension of a paxel in LSC configuration.
+ * @gain_format: Gain table format.
+ * @fmtsph: Start pixel horizontal from start of the HS sync pulse.
+ * @fmtlnh: Number of pixels in horizontal direction to use for the data
+ *          reformatter.
+ * @fmtslv: Start line from start of VS sync pulse for the data reformatter.
+ * @fmtlnv: Number of lines in vertical direction for the data reformatter.
+ * @initial_x: X position, in pixels, of the first active pixel in reference
+ *             to the first active paxel. Must be an even number.
+ * @initial_y: Y position, in pixels, of the first active pixel in reference
+ *             to the first active paxel. Must be an even number.
+ * @size: Size of LSC gain table. Filled when loaded from userspace.
+ */
+struct ispccdc_lsc_config {
+       u8 offset;
+       u8 gain_mode_n;
+       u8 gain_mode_m;
+       u8 gain_format;
+       u16 fmtsph;
+       u16 fmtlnh;
+       u16 fmtslv;
+       u16 fmtlnv;
+       u8 initial_x;
+       u8 initial_y;
+       u32 size;
+};
+
+/**
+ * struct ispccdc_bclamp - Structure for Optical & Digital black clamp subtract
+ * @obgain: Optical black average gain.
+ * @obstpixel: Start Pixel w.r.t. HS pulse in Optical black sample.
+ * @oblines: Optical Black Sample lines.
+ * @oblen: Optical Black Sample Length.
+ * @dcsubval: Digital Black Clamp subtract value.
+ */
+struct ispccdc_bclamp {
+       u8 obgain;
+       u8 obstpixel;
+       u8 oblines;
+       u8 oblen;
+       u16 dcsubval;
+};
+
+/**
+ * ispccdc_fpc - Structure for FPC
+ * @fpnum: Number of faulty pixels to be corrected in the frame.
+ * @fpcaddr: Memory address of the FPC Table
+ */
+struct ispccdc_fpc {
+       u16 fpnum;
+       u32 fpcaddr;
+};
+
+/**
+ * ispccdc_blcomp - Structure for Black Level Compensation parameters.
+ * @b_mg: B/Mg pixels. 2's complement. -128 to +127.
+ * @gb_g: Gb/G pixels. 2's complement. -128 to +127.
+ * @gr_cy: Gr/Cy pixels. 2's complement. -128 to +127.
+ * @r_ye: R/Ye pixels. 2's complement. -128 to +127.
+ */
+struct ispccdc_blcomp {
+       u8 b_mg;
+       u8 gb_g;
+       u8 gr_cy;
+       u8 r_ye;
+};
+
+/**
+ * struct ispccdc_vp - Structure for Video Port parameters
+ * @bitshift_sel: Video port input select. 3 - bits 12-3, 4 - bits 11-2,
+ *                5 - bits 10-1, 6 - bits 9-0.
+ * @freq_sel: Video port data ready frequency. 1 - 1/3.5, 2 - 1/4.5,
+ *            3 - 1/5.5, 4 - 1/6.5.
+ */
+struct ispccdc_vp {
+       enum vpin bitshift_sel;
+       enum vpif_freq freq_sel;
+};
+
+/**
+ * ispccdc_culling - Structure for Culling parameters.
+ * @v_pattern: Vertical culling pattern.
+ * @h_odd: Horizontal Culling pattern for odd lines.
+ * @h_even: Horizontal Culling pattern for even lines.
+ */
+struct ispccdc_culling {
+       u8 v_pattern;
+       u16 h_odd;
+       u16 h_even;
+};
+
+/**
+ * ispccdc_update_config - Structure for CCDC configuration.
+ * @update: Specifies which CCDC registers should be updated.
+ * @flag: Specifies which CCDC functions should be enabled.
+ * @alawip: Enable/Disable A-Law compression.
+ * @bclamp: Black clamp control register.
+ * @blcomp: Black level compensation value for RGrGbB Pixels. 2's complement.
+ * @fpc: Number of faulty pixels corrected in the frame, address of FPC table.
+ * @cull: Cull control register.
+ * @colptn: Color pattern of the sensor.
+ * @lsc: Pointer to LSC gain table.
+ */
+struct ispccdc_update_config {
+       u16 update;
+       u16 flag;
+       enum alaw_ipwidth alawip;
+       struct ispccdc_bclamp *bclamp;
+       struct ispccdc_blcomp *blcomp;
+       struct ispccdc_fpc *fpc;
+       struct ispccdc_lsc_config *lsc_cfg;
+       struct ispccdc_culling *cull;
+       u32 colptn;
+       u8 *lsc;
+};
+
+/* Preview configuration */
+
+/*Abstraction layer preview configurations*/
+#define ISP_ABS_PREV_LUMAENH           (1 << 0)
+#define ISP_ABS_PREV_INVALAW           (1 << 1)
+#define ISP_ABS_PREV_HRZ_MED           (1 << 2)
+#define ISP_ABS_PREV_CFA               (1 << 3)
+#define ISP_ABS_PREV_CHROMA_SUPP       (1 << 4)
+#define ISP_ABS_PREV_WB                        (1 << 5)
+#define ISP_ABS_PREV_BLKADJ            (1 << 6)
+#define ISP_ABS_PREV_RGB2RGB           (1 << 7)
+#define ISP_ABS_PREV_COLOR_CONV                (1 << 8)
+#define ISP_ABS_PREV_YC_LIMIT          (1 << 9)
+#define ISP_ABS_PREV_DEFECT_COR                (1 << 10)
+#define ISP_ABS_PREV_GAMMABYPASS       (1 << 11)
+#define ISP_ABS_TBL_NF                         (1 << 12)
+#define ISP_ABS_TBL_REDGAMMA           (1 << 13)
+#define ISP_ABS_TBL_GREENGAMMA         (1 << 14)
+#define ISP_ABS_TBL_BLUEGAMMA          (1 << 15)
+
+/**
+ * struct ispprev_hmed - Structure for Horizontal Median Filter.
+ * @odddist: Distance between consecutive pixels of same color in the odd line.
+ * @evendist: Distance between consecutive pixels of same color in the even
+ *            line.
+ * @thres: Horizontal median filter threshold.
+ */
+struct ispprev_hmed {
+       u8 odddist;
+       u8 evendist;
+       u8 thres;
+};
+
+/*
+ * Enumeration for CFA Formats supported by preview
+ */
+enum cfa_fmt {
+       CFAFMT_BAYER, CFAFMT_SONYVGA, CFAFMT_RGBFOVEON,
+       CFAFMT_DNSPL, CFAFMT_HONEYCOMB, CFAFMT_RRGGBBFOVEON
+};
+
+/**
+ * struct ispprev_cfa - Structure for CFA Inpterpolation.
+ * @cfafmt: CFA Format Enum value supported by preview.
+ * @cfa_gradthrs_vert: CFA Gradient Threshold - Vertical.
+ * @cfa_gradthrs_horz: CFA Gradient Threshold - Horizontal.
+ * @cfa_table: Pointer to the CFA table.
+ */
+struct ispprev_cfa {
+       enum cfa_fmt cfafmt;
+       u8 cfa_gradthrs_vert;
+       u8 cfa_gradthrs_horz;
+       u32 *cfa_table;
+};
+
+/**
+ * struct ispprev_csup - Structure for Chrominance Suppression.
+ * @gain: Gain.
+ * @thres: Threshold.
+ * @hypf_en: Flag to enable/disable the High Pass Filter.
+ */
+struct ispprev_csup {
+       u8 gain;
+       u8 thres;
+       u8 hypf_en;
+};
+
+/**
+ * struct ispprev_wbal - Structure for White Balance.
+ * @dgain: Digital gain (U10Q8).
+ * @coef3: White balance gain - COEF 3 (U8Q5).
+ * @coef2: White balance gain - COEF 2 (U8Q5).
+ * @coef1: White balance gain - COEF 1 (U8Q5).
+ * @coef0: White balance gain - COEF 0 (U8Q5).
+ */
+struct ispprev_wbal {
+       u16 dgain;
+       u8 coef3;
+       u8 coef2;
+       u8 coef1;
+       u8 coef0;
+};
+
+/**
+ * struct ispprev_blkadj - Structure for Black Adjustment.
+ * @red: Black level offset adjustment for Red in 2's complement format
+ * @green: Black level offset adjustment for Green in 2's complement format
+ * @blue: Black level offset adjustment for Blue in 2's complement format
+ */
+struct ispprev_blkadj {
+       /*Black level offset adjustment for Red in 2's complement format */
+       u8 red;
+       /*Black level offset adjustment for Green in 2's complement format */
+       u8 green;
+       /* Black level offset adjustment for Blue in 2's complement format */
+       u8 blue;
+};
+
+/**
+ * struct ispprev_rgbtorgb - Structure for RGB to RGB Blending.
+ * @matrix: Blending values(S12Q8 format)
+ *              [RR] [GR] [BR]
+ *              [RG] [GG] [BG]
+ *              [RB] [GB] [BB]
+ * @offset: Blending offset value for R,G,B in 2's complement integer format.
+ */
+struct ispprev_rgbtorgb {
+       u16 matrix[3][3];
+       u16 offset[3];
+};
+
+/**
+ * struct ispprev_csc - Structure for Color Space Conversion from RGB-YCbYCr
+ * @matrix: Color space conversion coefficients(S10Q8)
+ *              [CSCRY]  [CSCGY]  [CSCBY]
+ *              [CSCRCB] [CSCGCB] [CSCBCB]
+ *              [CSCRCR] [CSCGCR] [CSCBCR]
+ * @offset: CSC offset values for Y offset, CB offset and CR offset respectively
+ */
+struct ispprev_csc {
+       u16 matrix[RGB_MAX][RGB_MAX];
+       s16 offset[RGB_MAX];
+};
+
+/**
+ * struct ispprev_yclimit - Structure for Y, C Value Limit.
+ * @minC: Minimum C value
+ * @maxC: Maximum C value
+ * @minY: Minimum Y value
+ * @maxY: Maximum Y value
+ */
+struct ispprev_yclimit {
+       u8 minC;
+       u8 maxC;
+       u8 minY;
+       u8 maxY;
+};
+
+/**
+ * struct ispprev_dcor - Structure for Defect correction.
+ * @couplet_mode_en: Flag to enable or disable the couplet dc Correction in NF
+ * @detect_correct: Thresholds for correction bit 0:10 detect 16:25 correct
+ */
+struct ispprev_dcor {
+       u8 couplet_mode_en;
+       u32 detect_correct[4];
+};
+
+/**
+ * struct ispprev_nf - Structure for Noise Filter
+ * @spread: Spread value to be used in Noise Filter
+ * @table: Pointer to the Noise Filter table
+ */
+struct ispprev_nf {
+       u8 spread;
+       u32 table[64];
+};
+
+/**
+ * struct ispprv_update_config - Structure for Preview Configuration (user).
+ * @update: Specifies which ISP Preview registers should be updated.
+ * @flag: Specifies which ISP Preview functions should be enabled.
+ * @yen: Pointer to luma enhancement table.
+ * @shading_shift: 3bit value of shift used in shading compensation.
+ * @prev_hmed: Pointer to structure containing the odd and even distance.
+ *             between the pixels in the image along with the filter threshold.
+ * @prev_cfa: Pointer to structure containing the CFA interpolation table, CFA.
+ *            format in the image, vertical and horizontal gradient threshold.
+ * @csup: Pointer to Structure for Chrominance Suppression coefficients.
+ * @prev_wbal: Pointer to structure for White Balance.
+ * @prev_blkadj: Pointer to structure for Black Adjustment.
+ * @rgb2rgb: Pointer to structure for RGB to RGB Blending.
+ * @prev_csc: Pointer to structure for Color Space Conversion from RGB-YCbYCr.
+ * @yclimit: Pointer to structure for Y, C Value Limit.
+ * @prev_dcor: Pointer to structure for defect correction.
+ * @prev_nf: Pointer to structure for Noise Filter
+ * @red_gamma: Pointer to red gamma correction table.
+ * @green_gamma: Pointer to green gamma correction table.
+ * @blue_gamma: Pointer to blue gamma correction table.
+ */
+struct ispprv_update_config {
+       u16 update;
+       u16 flag;
+       void *yen;
+       u32 shading_shift;
+       struct ispprev_hmed *prev_hmed;
+       struct ispprev_cfa *prev_cfa;
+       struct ispprev_csup *csup;
+       struct ispprev_wbal *prev_wbal;
+       struct ispprev_blkadj *prev_blkadj;
+       struct ispprev_rgbtorgb *rgb2rgb;
+       struct ispprev_csc *prev_csc;
+       struct ispprev_yclimit *yclimit;
+       struct ispprev_dcor *prev_dcor;
+       struct ispprev_nf *prev_nf;
+       u32 *red_gamma;
+       u32 *green_gamma;
+       u32 *blue_gamma;
+};
+
+#endif /* OMAP_ISP_USER_H */
Index: linux-omap-2.6/drivers/media/video/isp/Kconfig
===================================================================
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ linux-omap-2.6/drivers/media/video/isp/Kconfig      2008-08-28 19:08:43.000000000 -0500
@@ -0,0 +1,9 @@
+# Kconfig for OMAP3 ISP driver
+
+config VIDEO_OMAP34XX_ISP_PREVIEWER
+       tristate "OMAP ISP Previewer"
+       depends on !ARCH_OMAP3410
+
+config VIDEO_OMAP34XX_ISP_RESIZER
+       tristate "OMAP ISP Resizer"
+       depends on !ARCH_OMAP3410
Index: linux-omap-2.6/drivers/media/video/isp/Makefile
===================================================================
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ linux-omap-2.6/drivers/media/video/isp/Makefile     2008-08-28 19:08:43.000000000 -0500
@@ -0,0 +1,19 @@
+# Makefile for OMAP3 ISP driver
+
+ifdef CONFIG_ARCH_OMAP3410
+isp-mod-objs += \
+       isp.o ispccdc.o ispmmu.o
+else
+isp-mod-objs += \
+       isp.o ispccdc.o ispmmu.o \
+       isppreview.o ispresizer.o isph3a.o isphist.o isp_af.o
+
+obj-$(CONFIG_VIDEO_OMAP34XX_ISP_PREVIEWER) += \
+       omap_previewer.o
+
+obj-$(CONFIG_VIDEO_OMAP34XX_ISP_RESIZER) += \
+       omap_resizer.o
+
+endif
+
+obj-$(CONFIG_VIDEO_OMAP3) += isp-mod.o
Index: linux-omap-2.6/drivers/media/video/isp/isp.c
===================================================================
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ linux-omap-2.6/drivers/media/video/isp/isp.c        2008-08-28 19:08:43.000000000 -0500
@@ -0,0 +1,2228 @@
+/*
+ * drivers/media/video/isp/isp.c
+ *
+ * Driver Library for ISP Control module in TI's OMAP3430 Camera ISP
+ * ISP interface and IRQ related APIs are defined here.
+ *
+ * Copyright (C) 2008 Texas Instruments.
+ * Copyright (C) 2008 Nokia.
+ *
+ * Contributors:
+ *     Sameer Venkatraman <sameerv@xxxxxx>
+ *     Mohit Jalori <mjalori@xxxxxx>
+ *     Sakari Ailus <sakari.ailus@xxxxxxxxx>
+ *     Tuukka Toivonen <tuukka.o.toivonen@xxxxxxxxx>
+ *     Toni Leinonen <toni.leinonen@xxxxxxxxx>
+ *
+ * This package is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/clk.h>
+#include <asm/irq.h>
+#include <linux/bitops.h>
+#include <linux/scatterlist.h>
+#include <asm/mach-types.h>
+#include <mach/clock.h>
+#include <mach/io.h>
+#include <linux/device.h>
+#include <linux/videodev2.h>
+
+#include "isp.h"
+#include "ispmmu.h"
+#include "ispreg.h"
+#include "ispccdc.h"
+#include "isph3a.h"
+#include "isphist.h"
+#include "isp_af.h"
+#include "isppreview.h"
+#include "ispresizer.h"
+
+/* List of image formats supported via OMAP ISP */
+const static struct v4l2_fmtdesc isp_formats[] = {
+       {
+               .description = "UYVY, packed",
+               .pixelformat = V4L2_PIX_FMT_UYVY,
+       },
+       {
+               .description = "YUYV (YUV 4:2:2), packed",
+               .pixelformat = V4L2_PIX_FMT_YUYV,
+       },
+       {
+               .description = "Bayer10 (GrR/BGb)",
+               .pixelformat = V4L2_PIX_FMT_SGRBG10,
+       },
+};
+
+/* ISP Crop capabilities */
+static struct v4l2_rect ispcroprect;
+static struct v4l2_rect cur_rect;
+
+/**
+ * struct vcontrol - Video control structure.
+ * @qc: V4L2 Query control structure.
+ * @current_value: Current value of the control.
+ */
+static struct vcontrol {
+       struct v4l2_queryctrl qc;
+       int current_value;
+} video_control[] = {
+       {
+               {
+                       .id = V4L2_CID_BRIGHTNESS,
+                       .type = V4L2_CTRL_TYPE_INTEGER,
+                       .name = "Brightness",
+                       .minimum = ISPPRV_BRIGHT_LOW,
+                       .maximum = ISPPRV_BRIGHT_HIGH,
+                       .step = ISPPRV_BRIGHT_STEP,
+                       .default_value = ISPPRV_BRIGHT_DEF,
+               },
+               .current_value = ISPPRV_BRIGHT_DEF,
+       },
+       {
+               {
+                       .id = V4L2_CID_CONTRAST,
+                       .type = V4L2_CTRL_TYPE_INTEGER,
+                       .name = "Contrast",
+                       .minimum = ISPPRV_CONTRAST_LOW,
+                       .maximum = ISPPRV_CONTRAST_HIGH,
+                       .step = ISPPRV_CONTRAST_STEP,
+                       .default_value = ISPPRV_CONTRAST_DEF,
+               },
+               .current_value = ISPPRV_CONTRAST_DEF,
+       },
+       {
+               {
+                       .id = V4L2_CID_PRIVATE_ISP_COLOR_FX,
+                       .type = V4L2_CTRL_TYPE_INTEGER,
+                       .name = "Color Effects",
+                       .minimum = PREV_DEFAULT_COLOR,
+                       .maximum = PREV_SEPIA_COLOR,
+                       .step = 1,
+                       .default_value = PREV_DEFAULT_COLOR,
+               },
+               .current_value = PREV_DEFAULT_COLOR,
+       }
+};
+
+
+/**
+ * struct ispirq - Structure for containing callbacks to be called in ISP ISR.
+ * @isp_callbk: Array which stores callback functions, indexed by the type of
+ *              callback (8 possible types).
+ * @isp_callbk_arg1: Pointer to array containing pointers to the first argument
+ *                   to be passed to the requested callback function.
+ * @isp_callbk_arg2: Pointer to array containing pointers to the second
+ *                   argument to be passed to the requested callback function.
+ *
+ * This structure is used to contain all the callback functions related for
+ * each callback type (CBK_CCDC_VD0, CBK_CCDC_VD1, CBK_PREV_DONE,
+ * CBK_RESZ_DONE, CBK_MMU_ERR, CBK_H3A_AWB_DONE, CBK_HIST_DONE, CBK_HS_VS,
+ * CBK_LSC_ISR).
+ */
+static struct ispirq {
+       isp_callback_t isp_callbk[CBK_END];
+       isp_vbq_callback_ptr isp_callbk_arg1[CBK_END];
+       void *isp_callbk_arg2[CBK_END];
+} ispirq_obj;
+
+/**
+ * struct isp - Structure for storing ISP Control module information
+ * @lock: Spinlock to sync between isr and processes.
+ * @isp_temp_buf_lock: Temporary spinlock for buffer control.
+ * @isp_mutex: Semaphore used to get access to the ISP.
+ * @if_status: Type of interface used in ISP.
+ * @interfacetype: (Not used).
+ * @ref_count: Reference counter.
+ * @cam_ick: Pointer to ISP Interface clock.
+ * @cam_fck: Pointer to ISP Functional clock.
+ *
+ * This structure is used to store the OMAP ISP Control Information.
+ */
+static struct isp {
+       spinlock_t lock;        /* For handling registered ISP callbacks */
+       spinlock_t isp_temp_buf_lock;   /* For handling isp buffers state */
+       struct mutex isp_mutex; /* For handling ref_count field */
+       u8 if_status;
+       u8 interfacetype;
+       int ref_count;
+       struct clk *cam_ick;
+       struct clk *cam_mclk;
+} isp_obj;
+
+struct isp_sgdma ispsg;
+
+/**
+ * struct ispmodule - Structure for storing ISP sub-module information.
+ * @isp_pipeline: Bit mask for submodules enabled within the ISP.
+ * @isp_temp_state: State of current buffers.
+ * @applyCrop: Flag to do a crop operation when video buffer queue ISR is done
+ * @pix: Structure containing the format and layout of the output image.
+ * @ccdc_input_width: ISP CCDC module input image width.
+ * @ccdc_input_height: ISP CCDC module input image height.
+ * @ccdc_output_width: ISP CCDC module output image width.
+ * @ccdc_output_height: ISP CCDC module output image height.
+ * @preview_input_width: ISP Preview module input image width.
+ * @preview_input_height: ISP Preview module input image height.
+ * @preview_output_width: ISP Preview module output image width.
+ * @preview_output_height: ISP Preview module output image height.
+ * @resizer_input_width: ISP Resizer module input image width.
+ * @resizer_input_height: ISP Resizer module input image height.
+ * @resizer_output_width: ISP Resizer module output image width.
+ * @resizer_output_height: ISP Resizer module output image height.
+ */
+struct ispmodule {
+       unsigned int isp_pipeline;
+       int isp_temp_state;
+       int applyCrop;
+       struct v4l2_pix_format pix;
+       unsigned int ccdc_input_width;
+       unsigned int ccdc_input_height;
+       unsigned int ccdc_output_width;
+       unsigned int ccdc_output_height;
+       unsigned int preview_input_width;
+       unsigned int preview_input_height;
+       unsigned int preview_output_width;
+       unsigned int preview_output_height;
+       unsigned int resizer_input_width;
+       unsigned int resizer_input_height;
+       unsigned int resizer_output_width;
+       unsigned int resizer_output_height;
+};
+
+static struct ispmodule ispmodule_obj = {
+       .isp_pipeline = OMAP_ISP_CCDC,
+       .isp_temp_state = ISP_BUF_INIT,
+       .applyCrop = 0,
+       .pix = {
+               .width = ISP_OUTPUT_WIDTH_DEFAULT,
+               .height = ISP_OUTPUT_HEIGHT_DEFAULT,
+               .pixelformat = V4L2_PIX_FMT_UYVY,
+               .field = V4L2_FIELD_NONE,
+               .bytesperline = ISP_OUTPUT_WIDTH_DEFAULT * ISP_BYTES_PER_PIXEL,
+               .colorspace = V4L2_COLORSPACE_JPEG,
+               .priv = 0,
+       },
+};
+
+/* Structure for saving/restoring ISP module registers */
+static struct isp_reg isp_reg_list[] = {
+       {ISP_SYSCONFIG, 0},
+       {ISP_IRQ0ENABLE, 0},
+       {ISP_IRQ1ENABLE, 0},
+       {ISP_TCTRL_GRESET_LENGTH, 0},
+       {ISP_TCTRL_PSTRB_REPLAY, 0},
+       {ISP_CTRL, 0},
+       {ISP_TCTRL_CTRL, 0},
+       {ISP_TCTRL_FRAME, 0},
+       {ISP_TCTRL_PSTRB_DELAY, 0},
+       {ISP_TCTRL_STRB_DELAY, 0},
+       {ISP_TCTRL_SHUT_DELAY, 0},
+       {ISP_TCTRL_PSTRB_LENGTH, 0},
+       {ISP_TCTRL_STRB_LENGTH, 0},
+       {ISP_TCTRL_SHUT_LENGTH, 0},
+       {ISP_CBUFF_SYSCONFIG, 0},
+       {ISP_CBUFF_IRQENABLE, 0},
+       {ISP_CBUFF0_CTRL, 0},
+       {ISP_CBUFF1_CTRL, 0},
+       {ISP_CBUFF0_START, 0},
+       {ISP_CBUFF1_START, 0},
+       {ISP_CBUFF0_END, 0},
+       {ISP_CBUFF1_END, 0},
+       {ISP_CBUFF0_WINDOWSIZE, 0},
+       {ISP_CBUFF1_WINDOWSIZE, 0},
+       {ISP_CBUFF0_THRESHOLD, 0},
+       {ISP_CBUFF1_THRESHOLD, 0},
+       {ISP_TOK_TERM, 0}
+};
+
+/*
+ *
+ * V4L2 Handling
+ *
+ */
+
+/**
+ * find_vctrl - Returns the index of the ctrl array of the requested ctrl ID.
+ * @id: Requested control ID.
+ *
+ * Returns 0 if successful, -EINVAL if not found, or -EDOM if its out of
+ * domain.
+ **/
+static int find_vctrl(int id)
+{
+       int i;
+
+       if (id < V4L2_CID_BASE)
+               return -EDOM;
+
+       for (i = (ARRAY_SIZE(video_control) - 1); i >= 0; i--)
+               if (video_control[i].qc.id == id)
+                       break;
+
+       if (i < 0)
+               i = -EINVAL;
+
+       return i;
+}
+
+/**
+ * isp_open - Reserve ISP submodules for operation
+ **/
+void isp_open(void)
+{
+       ispccdc_request();
+       isppreview_request();
+       ispresizer_request();
+       return;
+}
+EXPORT_SYMBOL(isp_set_pipeline);
+
+/**
+ * isp_close - Free ISP submodules
+ **/
+void isp_close(void)
+{
+       ispccdc_free();
+       isppreview_free();
+       ispresizer_free();
+       return;
+}
+EXPORT_SYMBOL(omapisp_unset_callback);
+
+/* Flag to check first time of isp_get */
+static int off_mode;
+
+/**
+ * isp_set_sgdma_callback - Set Scatter-Gather DMA Callback.
+ * @sgdma_state: Pointer to structure with the SGDMA state for each videobuffer
+ * @func_ptr: Callback function pointer for SG-DMA management
+ **/
+static int isp_set_sgdma_callback(struct isp_sgdma_state *sgdma_state,
+                                               isp_vbq_callback_ptr func_ptr)
+{
+       if ((ispmodule_obj.isp_pipeline & OMAP_ISP_RESIZER) &&
+                                               is_ispresizer_enabled()) {
+               isp_set_callback(CBK_RESZ_DONE, sgdma_state->callback,
+                                               func_ptr, sgdma_state->arg);
+       }
+
+       if ((ispmodule_obj.isp_pipeline & OMAP_ISP_PREVIEW) &&
+                                               is_isppreview_enabled()) {
+                       isp_set_callback(CBK_PREV_DONE, sgdma_state->callback,
+                                               func_ptr, sgdma_state->arg);
+       }
+
+       if (ispmodule_obj.isp_pipeline & OMAP_ISP_CCDC) {
+               isp_set_callback(CBK_CCDC_VD0, sgdma_state->callback, func_ptr,
+                                                       sgdma_state->arg);
+               isp_set_callback(CBK_CCDC_VD1, sgdma_state->callback, func_ptr,
+                                                       sgdma_state->arg);
+               isp_set_callback(CBK_LSC_ISR, NULL, NULL, NULL);
+       }
+
+       isp_set_callback(CBK_HS_VS, sgdma_state->callback, func_ptr,
+                                                       sgdma_state->arg);
+       return 0;
+}
+
+/**
+ * isp_set_callback - Sets the callback for the ISP module done events.
+ * @type: Type of the event for which callback is requested.
+ * @callback: Method to be called as callback in the ISR context.
+ * @arg1: First argument to be passed when callback is called in ISR.
+ * @arg2: Second argument to be passed when callback is called in ISR.
+ *
+ * This function sets a callback function for a done event in the ISP
+ * module, and enables the corresponding interrupt.
+ **/
+int isp_set_callback(enum isp_callback_type type, isp_callback_t callback,
+                                               isp_vbq_callback_ptr arg1,
+                                               void *arg2)
+{
+       unsigned long irqflags = 0;
+
+       if (callback == NULL) {
+               DPRINTK_ISPCTRL("ISP_ERR : Null Callback\n");
+               return -EINVAL;
+       }
+
+       spin_lock_irqsave(&isp_obj.lock, irqflags);
+       ispirq_obj.isp_callbk[type] = callback;
+       ispirq_obj.isp_callbk_arg1[type] = arg1;
+       ispirq_obj.isp_callbk_arg2[type] = arg2;
+       spin_unlock_irqrestore(&isp_obj.lock, irqflags);
+
+       switch (type) {
+       case CBK_HS_VS:
+               omap_writel(IRQ0ENABLE_HS_VS_IRQ, ISP_IRQ0STATUS);
+               omap_writel(omap_readl(ISP_IRQ0ENABLE) | IRQ0ENABLE_HS_VS_IRQ,
+                                                       ISP_IRQ0ENABLE);
+               break;
+       case CBK_PREV_DONE:
+               omap_writel(IRQ0ENABLE_PRV_DONE_IRQ, ISP_IRQ0STATUS);
+               omap_writel(omap_readl(ISP_IRQ0ENABLE) |
+                                       IRQ0ENABLE_PRV_DONE_IRQ,
+                                       ISP_IRQ0ENABLE);
+               break;
+       case CBK_RESZ_DONE:
+               omap_writel(IRQ0ENABLE_RSZ_DONE_IRQ, ISP_IRQ0STATUS);
+               omap_writel(omap_readl(ISP_IRQ0ENABLE) |
+                                       IRQ0ENABLE_RSZ_DONE_IRQ,
+                                       ISP_IRQ0ENABLE);
+               break;
+       case CBK_MMU_ERR:
+               omap_writel(omap_readl(ISP_IRQ0ENABLE) |
+                                       IRQ0ENABLE_MMU_ERR_IRQ,
+                                       ISP_IRQ0ENABLE);
+
+               omap_writel(omap_readl(ISPMMU_IRQENABLE) |
+                                       IRQENABLE_MULTIHITFAULT |
+                                       IRQENABLE_TWFAULT |
+                                       IRQENABLE_EMUMISS |
+                                       IRQENABLE_TRANSLNFAULT |
+                                       IRQENABLE_TLBMISS,
+                                       ISPMMU_IRQENABLE);
+               break;
+       case CBK_H3A_AWB_DONE:
+               omap_writel(IRQ0ENABLE_H3A_AWB_DONE_IRQ, ISP_IRQ0STATUS);
+               omap_writel(omap_readl(ISP_IRQ0ENABLE) |
+                                       IRQ0ENABLE_H3A_AWB_DONE_IRQ,
+                                       ISP_IRQ0ENABLE);
+               break;
+       case CBK_H3A_AF_DONE:
+               omap_writel(IRQ0ENABLE_H3A_AF_DONE_IRQ, ISP_IRQ0STATUS);
+               omap_writel(omap_readl(ISP_IRQ0ENABLE)|
+                               IRQ0ENABLE_H3A_AF_DONE_IRQ,
+                               ISP_IRQ0ENABLE);
+               break;
+       case CBK_HIST_DONE:
+               omap_writel(IRQ0ENABLE_HIST_DONE_IRQ, ISP_IRQ0STATUS);
+               omap_writel(omap_readl(ISP_IRQ0ENABLE) |
+                                       IRQ0ENABLE_HIST_DONE_IRQ,
+                                       ISP_IRQ0ENABLE);
+               break;
+       case CBK_LSC_ISR:
+               omap_writel(IRQ0ENABLE_CCDC_LSC_DONE_IRQ |
+                                       IRQ0ENABLE_CCDC_LSC_PREF_COMP_IRQ |
+                                       IRQ0ENABLE_CCDC_LSC_PREF_ERR_IRQ,
+                                       ISP_IRQ0STATUS);
+               omap_writel(omap_readl(ISP_IRQ0ENABLE) |
+                                       IRQ0ENABLE_CCDC_LSC_DONE_IRQ |
+                                       IRQ0ENABLE_CCDC_LSC_PREF_COMP_IRQ |
+                                       IRQ0ENABLE_CCDC_LSC_PREF_ERR_IRQ,
+                                       ISP_IRQ0ENABLE);
+               break;
+       default:
+               break;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL(isp_set_callback);
+
+/**
+ * isp_unset_callback - Clears the callback for the ISP module done events.
+ * @type: Type of the event for which callback to be cleared.
+ *
+ * This function clears a callback function for a done event in the ISP
+ * module, and disables the corresponding interrupt.
+ **/
+int isp_unset_callback(enum isp_callback_type type)
+{
+       unsigned long irqflags = 0;
+
+       spin_lock_irqsave(&isp_obj.lock, irqflags);
+       ispirq_obj.isp_callbk[type] = NULL;
+       ispirq_obj.isp_callbk_arg1[type] = NULL;
+       ispirq_obj.isp_callbk_arg2[type] = NULL;
+       spin_unlock_irqrestore(&isp_obj.lock, irqflags);
+
+       switch (type) {
+       case CBK_CCDC_VD0:
+               omap_writel((omap_readl(ISP_IRQ0ENABLE)) &
+                                               ~IRQ0ENABLE_CCDC_VD0_IRQ,
+                                               ISP_IRQ0ENABLE);
+               break;
+       case CBK_CCDC_VD1:
+               omap_writel((omap_readl(ISP_IRQ0ENABLE)) &
+                                               ~IRQ0ENABLE_CCDC_VD1_IRQ,
+                                               ISP_IRQ0ENABLE);
+               break;
+       case CBK_PREV_DONE:
+               omap_writel((omap_readl(ISP_IRQ0ENABLE)) &
+                                               ~IRQ0ENABLE_PRV_DONE_IRQ,
+                                               ISP_IRQ0ENABLE);
+               break;
+       case CBK_RESZ_DONE:
+               omap_writel((omap_readl(ISP_IRQ0ENABLE)) &
+                                               ~IRQ0ENABLE_RSZ_DONE_IRQ,
+                                               ISP_IRQ0ENABLE);
+               break;
+       case CBK_MMU_ERR:
+               omap_writel(omap_readl(ISPMMU_IRQENABLE) &
+                                               ~(IRQENABLE_MULTIHITFAULT |
+                                               IRQENABLE_TWFAULT |
+                                               IRQENABLE_EMUMISS |
+                                               IRQENABLE_TRANSLNFAULT |
+                                               IRQENABLE_TLBMISS),
+                                               ISPMMU_IRQENABLE);
+               break;
+       case CBK_H3A_AWB_DONE:
+               omap_writel((omap_readl(ISP_IRQ0ENABLE)) &
+                                               ~IRQ0ENABLE_H3A_AWB_DONE_IRQ,
+                                               ISP_IRQ0ENABLE);
+               break;
+       case CBK_H3A_AF_DONE:
+               omap_writel((omap_readl(ISP_IRQ0ENABLE))&
+                               (~IRQ0ENABLE_H3A_AF_DONE_IRQ), ISP_IRQ0ENABLE);
+               break;
+       case CBK_HIST_DONE:
+               omap_writel((omap_readl(ISP_IRQ0ENABLE)) &
+                                               ~IRQ0ENABLE_HIST_DONE_IRQ,
+                                               ISP_IRQ0ENABLE);
+               break;
+       case CBK_HS_VS:
+               omap_writel((omap_readl(ISP_IRQ0ENABLE)) &
+                                               ~IRQ0ENABLE_HS_VS_IRQ,
+                                               ISP_IRQ0ENABLE);
+               break;
+       case CBK_LSC_ISR:
+               omap_writel(omap_readl(ISP_IRQ0ENABLE) &
+                                       ~(IRQ0ENABLE_CCDC_LSC_DONE_IRQ |
+                                       IRQ0ENABLE_CCDC_LSC_PREF_COMP_IRQ |
+                                       IRQ0ENABLE_CCDC_LSC_PREF_ERR_IRQ),
+                                       ISP_IRQ0ENABLE);
+               break;
+       default:
+               break;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL(isp_unset_callback);
+
+/**
+ * isp_request_interface - Requests an ISP interface type (parallel or serial).
+ * @if_t: Type of requested ISP interface (parallel or serial).
+ *
+ * This function requests for allocation of an ISP interface type.
+ **/
+int isp_request_interface(enum isp_interface_type if_t)
+{
+       if (isp_obj.if_status & if_t) {
+               DPRINTK_ISPCTRL("ISP_ERR : Requested Interface already \
+                       allocated\n");
+               goto err_ebusy;
+       }
+       if ((isp_obj.if_status == (ISP_PARLL | ISP_CSIA))
+                       || isp_obj.if_status == (ISP_CSIA | ISP_CSIB)) {
+               DPRINTK_ISPCTRL("ISP_ERR : No Free interface now\n");
+               goto err_ebusy;
+       }
+
+       if (((isp_obj.if_status == ISP_PARLL) && (if_t == ISP_CSIA)) ||
+                               ((isp_obj.if_status == ISP_CSIA) &&
+                               (if_t == ISP_PARLL)) ||
+                               ((isp_obj.if_status == ISP_CSIA) &&
+                               (if_t == ISP_CSIB)) ||
+                               ((isp_obj.if_status == ISP_CSIB) &&
+                               (if_t == ISP_CSIA)) ||
+                               (isp_obj.if_status == 0)) {
+               isp_obj.if_status |= if_t;
+               return 0;
+       } else {
+               DPRINTK_ISPCTRL("ISP_ERR : Invalid Combination Serial- \
+                       Parallel interface\n");
+               return -EINVAL;
+       }
+
+err_ebusy:
+       return -EBUSY;
+}
+EXPORT_SYMBOL(isp_request_interface);
+
+/**
+ * isp_free_interface - Frees an ISP interface type (parallel or serial).
+ * @if_t: Type of ISP interface to be freed (parallel or serial).
+ *
+ * This function frees the allocation of an ISP interface type.
+ **/
+int isp_free_interface(enum isp_interface_type if_t)
+{
+       isp_obj.if_status &= ~if_t;
+       return 0;
+}
+EXPORT_SYMBOL(isp_free_interface);
+
+/**
+ * isp_set_xclk - Configures the specified cam_xclk to the desired frequency.
+ * @xclk: Desired frequency of the clock in Hz.
+ * @xclksel: XCLK to configure (0 = A, 1 = B).
+ *
+ * Configures the specified MCLK divisor in the ISP timing control register
+ * (TCTRL_CTRL) to generate the desired xclk clock value.
+ *
+ * Divisor = CM_CAM_MCLK_HZ / xclk
+ *
+ * Returns the final frequency that is actually being generated
+ **/
+u32 isp_set_xclk(u32 xclk, u8 xclksel)
+{
+       u32 divisor;
+       u32 currentxclk;
+
+       if (xclk >= CM_CAM_MCLK_HZ) {
+               divisor = ISPTCTRL_CTRL_DIV_BYPASS;
+               currentxclk = CM_CAM_MCLK_HZ;
+       } else if (xclk >= 2) {
+               divisor = CM_CAM_MCLK_HZ / xclk;
+               if (divisor >= ISPTCTRL_CTRL_DIV_BYPASS)
+                       divisor = ISPTCTRL_CTRL_DIV_BYPASS - 1;
+               currentxclk = CM_CAM_MCLK_HZ / divisor;
+       } else {
+               divisor = xclk;
+               currentxclk = 0;
+       }
+
+       switch (xclksel) {
+       case 0:
+               omap_writel((omap_readl(ISP_TCTRL_CTRL) &
+                               ~ISPTCTRL_CTRL_DIVA_MASK) |
+                               (divisor << ISPTCTRL_CTRL_DIVA_SHIFT),
+                               ISP_TCTRL_CTRL);
+               DPRINTK_ISPCTRL("isp_set_xclk(): cam_xclka set to %d Hz\n",
+                                                               currentxclk);
+               break;
+       case 1:
+               omap_writel((omap_readl(ISP_TCTRL_CTRL) &
+                               ~ISPTCTRL_CTRL_DIVB_MASK) |
+                               (divisor << ISPTCTRL_CTRL_DIVB_SHIFT),
+                               ISP_TCTRL_CTRL);
+               DPRINTK_ISPCTRL("isp_set_xclk(): cam_xclkb set to %d Hz\n",
+                                                               currentxclk);
+               break;
+       default:
+               DPRINTK_ISPCTRL("ISP_ERR: isp_set_xclk(): Invalid requested "
+                                               "xclk. Must be 0 (A) or 1 (B)."
+                                               "\n");
+               return -EINVAL;
+       }
+
+       return currentxclk;
+}
+EXPORT_SYMBOL(isp_set_xclk);
+
+/**
+ * isp_get_xclk - Returns the frequency in Hz of the desired cam_xclk.
+ * @xclksel: XCLK to retrieve (0 = A, 1 = B).
+ *
+ * This function returns the External Clock (XCLKA or XCLKB) value generated
+ * by the ISP.
+ **/
+u32 isp_get_xclk(u8 xclksel)
+{
+       u32 xclkdiv;
+       u32 xclk;
+
+       switch (xclksel) {
+       case 0:
+               xclkdiv = omap_readl(ISP_TCTRL_CTRL) & ISPTCTRL_CTRL_DIVA_MASK;
+               xclkdiv = xclkdiv >> ISPTCTRL_CTRL_DIVA_SHIFT;
+               break;
+       case 1:
+               xclkdiv = omap_readl(ISP_TCTRL_CTRL) & ISPTCTRL_CTRL_DIVB_MASK;
+               xclkdiv = xclkdiv >> ISPTCTRL_CTRL_DIVB_SHIFT;
+               break;
+       default:
+               DPRINTK_ISPCTRL("ISP_ERR: isp_get_xclk(): Invalid requested "
+                                               "xclk. Must be 0 (A) or 1 (B)."
+                                               "\n");
+               return -EINVAL;
+       }
+
+       switch (xclkdiv) {
+       case 0:
+       case 1:
+               xclk = 0;
+               break;
+       case 0x1f:
+               xclk = CM_CAM_MCLK_HZ;
+               break;
+       default:
+               xclk = CM_CAM_MCLK_HZ / xclkdiv;
+               break;
+       }
+
+       return xclk;
+}
+EXPORT_SYMBOL(isp_get_xclk);
+
+/**
+ * isp_power_settings - Sysconfig settings, for Power Management.
+ * @isp_sysconfig: Structure containing the power settings for ISP to configure
+ *
+ * Sets the power settings for the ISP, and SBL bus.
+ **/
+void isp_power_settings(struct isp_sysc isp_sysconfig)
+{
+       if (isp_sysconfig.idle_mode) {
+               omap_writel(ISP_SYSCONFIG_AUTOIDLE |
+                               (ISP_SYSCONFIG_MIDLEMODE_SMARTSTANDBY <<
+                               ISP_SYSCONFIG_MIDLEMODE_SHIFT),
+                               ISP_SYSCONFIG);
+
+               omap_writel(ISPMMU_AUTOIDLE | (ISPMMU_SIDLEMODE_SMARTIDLE <<
+                                               ISPMMU_SIDLEMODE_SHIFT),
+                                               ISPMMU_SYSCONFIG);
+               if (is_sil_rev_equal_to(OMAP3430_REV_ES1_0)) {
+                       omap_writel(ISPCSI1_AUTOIDLE |
+                                       (ISPCSI1_MIDLEMODE_SMARTSTANDBY <<
+                                       ISPCSI1_MIDLEMODE_SHIFT),
+                                       ISP_CSIA_SYSCONFIG);
+                       omap_writel(ISPCSI1_AUTOIDLE |
+                                       (ISPCSI1_MIDLEMODE_SMARTSTANDBY <<
+                                       ISPCSI1_MIDLEMODE_SHIFT),
+                                       ISP_CSIB_SYSCONFIG);
+               }
+               omap_writel(ISPCTRL_SBL_AUTOIDLE, ISP_CTRL);
+
+       } else {
+               omap_writel(ISP_SYSCONFIG_AUTOIDLE |
+                               (ISP_SYSCONFIG_MIDLEMODE_FORCESTANDBY <<
+                               ISP_SYSCONFIG_MIDLEMODE_SHIFT),
+                               ISP_SYSCONFIG);
+
+               omap_writel(ISPMMU_AUTOIDLE |
+                       (ISPMMU_SIDLEMODE_NOIDLE << ISPMMU_SIDLEMODE_SHIFT),
+                                                       ISPMMU_SYSCONFIG);
+               if (is_sil_rev_equal_to(OMAP3430_REV_ES1_0)) {
+                       omap_writel(ISPCSI1_AUTOIDLE |
+                                       (ISPCSI1_MIDLEMODE_FORCESTANDBY <<
+                                       ISPCSI1_MIDLEMODE_SHIFT),
+                                       ISP_CSIA_SYSCONFIG);
+
+                       omap_writel(ISPCSI1_AUTOIDLE |
+                                       (ISPCSI1_MIDLEMODE_FORCESTANDBY <<
+                                       ISPCSI1_MIDLEMODE_SHIFT),
+                                       ISP_CSIB_SYSCONFIG);
+               }
+
+               omap_writel(ISPCTRL_SBL_AUTOIDLE, ISP_CTRL);
+       }
+}
+EXPORT_SYMBOL(isp_power_settings);
+
+#define BIT_SET(var, shift, mask, val)         \
+       do {                                    \
+               var = (var & ~(mask << shift))  \
+                       | (val << shift);       \
+       } while (0)
+
+static int isp_init_csi(struct isp_interface_config *config)
+{
+       u32 i = 0, val, reg;
+       int format;
+
+       switch (config->u.csi.format) {
+       case V4L2_PIX_FMT_SGRBG10:
+               format = 0x16;          /* RAW10+VP */
+               break;
+       case V4L2_PIX_FMT_SGRBG10DPCM8:
+               format = 0x12;          /* RAW8+DPCM10+VP */
+               break;
+       default:
+               printk(KERN_ERR "isp_init_csi: bad csi format\n");
+               return -EINVAL;
+       }
+
+       /* Reset the CSI and wait for reset to complete */
+       omap_writel(omap_readl(ISPCSI1_SYSCONFIG) | BIT(1), ISPCSI1_SYSCONFIG);
+       while (!(omap_readl(ISPCSI1_SYSSTATUS) & BIT(0))) {
+               udelay(10);
+               if (i++ > 10)
+                       break;
+       }
+       if (!(omap_readl(ISPCSI1_SYSSTATUS) & BIT(0))) {
+               printk(KERN_WARNING
+                       "omap3_isp: timeout waiting for csi reset\n");
+       }
+
+       /* CONTROL_CSIRXFE */
+       omap_writel(
+               /* CSIb receiver data/clock or data/strobe mode */
+               (config->u.csi.signalling << 10)
+               | BIT(12)       /* Enable differential transceiver */
+               | BIT(13)       /* Disable reset */
+#ifdef TERM_RESISTOR
+               | BIT(8)        /* Enable internal CSIb resistor (no effect) */
+#endif
+/*             | BIT(7) */     /* Strobe/clock inversion (no effect) */
+       , CONTROL_CSIRXFE);
+
+#ifdef TERM_RESISTOR
+       /* Set CONTROL_CSI */
+       val = omap_readl(CONTROL_CSI);
+       val &= ~(0x1F<<16);
+       val |= BIT(31) | (TERM_RESISTOR<<16);
+       omap_writel(val, CONTROL_CSI);
+#endif
+
+       /* ISPCSI1_CTRL */
+       val = omap_readl(ISPCSI1_CTRL);
+       val &= ~BIT(11);        /* Enable VP only off ->
+                               extract embedded data to interconnect */
+       BIT_SET(val, 8, 0x3, config->u.csi.vpclk);      /* Video port clock */
+/*     val |= BIT(3);  */      /* Wait for FEC before disabling interface */
+       val |= BIT(2);          /* I/O cell output is parallel
+                               (no effect, but errata says should be enabled
+                               for class 1/2) */
+       val |= BIT(12);         /* VP clock polarity to falling edge
+                               (needed or bad picture!) */
+
+       /* Data/strobe physical layer */
+       BIT_SET(val, 1, 1, config->u.csi.signalling);
+       BIT_SET(val, 10, 1, config->u.csi.strobe_clock_inv);
+       val |= BIT(4);          /* Magic bit to enable CSI1 and strobe mode */
+       omap_writel(val, ISPCSI1_CTRL);
+
+       /* ISPCSI1_LCx_CTRL logical channel #0 */
+       reg = ISPCSI1_LCx_CTRL(0);      /* reg = ISPCSI1_CTRL1; */
+       val = omap_readl(reg);
+       /* Format = RAW10+VP or RAW8+DPCM10+VP*/
+       BIT_SET(val, 3, 0x1f, format);
+       /* Enable setting of frame regions of interest */
+       BIT_SET(val, 1, 1, 1);
+       BIT_SET(val, 2, 1, config->u.csi.crc);
+       omap_writel(val, reg);
+
+       /* ISPCSI1_DAT_START for logical channel #0 */
+       reg = ISPCSI1_LCx_DAT_START(0);         /* reg = ISPCSI1_DAT_START; */
+       val = omap_readl(reg);
+       BIT_SET(val, 16, 0xfff, config->u.csi.data_start);
+       omap_writel(val, reg);
+
+       /* ISPCSI1_DAT_SIZE for logical channel #0 */
+       reg = ISPCSI1_LCx_DAT_SIZE(0);          /* reg = ISPCSI1_DAT_SIZE; */
+       val = omap_readl(reg);
+       BIT_SET(val, 16, 0xfff, config->u.csi.data_size);
+       omap_writel(val, reg);
+
+       /* Clear status bits for logical channel #0 */
+       omap_writel(0xFFF & ~BIT(6), ISPCSI1_LC01_IRQSTATUS);
+
+       /* Enable CSI1 */
+       val = omap_readl(ISPCSI1_CTRL);
+       val |=  BIT(0) | BIT(4);
+       omap_writel(val, ISPCSI1_CTRL);
+
+       if (!(omap_readl(ISPCSI1_CTRL) & BIT(4))) {
+               printk(KERN_WARNING "OMAP3 CSI1 bus not available\n");
+               if (config->u.csi.signalling)   /* Strobe mode requires CSI1 */
+                       return -EIO;
+       }
+
+       return 0;
+}
+
+/**
+ * isp_configure_interface - Configures ISP Control I/F related parameters.
+ * @config: Pointer to structure containing the desired configuration for the
+ *     ISP.
+ *
+ * Configures ISP control register (ISP_CTRL) with the values specified inside
+ * the config structure. Controls:
+ * - Selection of parallel or serial input to the preview hardware.
+ * - Data lane shifter.
+ * - Pixel clock polarity.
+ * - 8 to 16-bit bridge at the input of CCDC module.
+ * - HS or VS synchronization signal detection
+ **/
+int isp_configure_interface(struct isp_interface_config *config)
+{
+       u32 ispctrl_val = omap_readl(ISP_CTRL);
+       u32 ispccdc_vdint_val;
+       int r;
+
+       ispctrl_val &= ISPCTRL_SHIFT_MASK;
+       ispctrl_val |= (config->dataline_shift << ISPCTRL_SHIFT_SHIFT);
+       ispctrl_val &= ~ISPCTRL_PAR_CLK_POL_INV;
+
+       ispctrl_val &= (ISPCTRL_PAR_SER_CLK_SEL_MASK);
+       switch (config->ccdc_par_ser) {
+       case ISP_PARLL:
+               ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_PARALLEL;
+               ispctrl_val |= (config->u.par.par_clk_pol
+                                               << ISPCTRL_PAR_CLK_POL_SHIFT);
+               ispctrl_val &= ~ISPCTRL_PAR_BRIDGE_BENDIAN;
+               ispctrl_val |= (config->u.par.par_bridge
+                                               << ISPCTRL_PAR_BRIDGE_SHIFT);
+               break;
+       case ISP_CSIB:
+               ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_CSIB;
+               r = isp_init_csi(config);
+               if (r)
+                       return r;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       ispctrl_val &= ~(ISPCTRL_SYNC_DETECT_VSRISE);
+       ispctrl_val |= (config->hsvs_syncdetect);
+
+       omap_writel(ispctrl_val, ISP_CTRL);
+
+       ispccdc_vdint_val = omap_readl(ISPCCDC_VDINT);
+       ispccdc_vdint_val &= ~(ISPCCDC_VDINT_0_MASK << ISPCCDC_VDINT_0_SHIFT);
+       ispccdc_vdint_val &= ~(ISPCCDC_VDINT_1_MASK << ISPCCDC_VDINT_1_SHIFT);
+       omap_writel((config->vdint0_timing << ISPCCDC_VDINT_0_SHIFT) |
+                                               (config->vdint1_timing <<
+                                               ISPCCDC_VDINT_1_SHIFT),
+                                               ISPCCDC_VDINT);
+
+       return 0;
+}
+EXPORT_SYMBOL(isp_configure_interface);
+
+/**
+ * isp_CCDC_VD01_enable - Enables VD0 and VD1 IRQs.
+ *
+ * Sets VD0 and VD1 bits in IRQ0STATUS to reset the flag, and sets them in
+ * IRQ0ENABLE to enable the corresponding IRQs.
+ **/
+void isp_CCDC_VD01_enable(void)
+{
+       omap_writel(IRQ0STATUS_CCDC_VD0_IRQ | IRQ0STATUS_CCDC_VD1_IRQ,
+                                                       ISP_IRQ0STATUS);
+       omap_writel(omap_readl(ISP_IRQ0ENABLE) | IRQ0ENABLE_CCDC_VD0_IRQ |
+                                               IRQ0ENABLE_CCDC_VD1_IRQ,
+                                               ISP_IRQ0ENABLE);
+}
+
+/**
+ * isp_CCDC_VD01_disable - Disables VD0 and VD1 IRQs.
+ *
+ * Clears VD0 and VD1 bits in IRQ0ENABLE register.
+ **/
+void isp_CCDC_VD01_disable(void)
+{
+       omap_writel(omap_readl(ISP_IRQ0ENABLE) & ~(IRQ0ENABLE_CCDC_VD0_IRQ |
+                                               IRQ0ENABLE_CCDC_VD1_IRQ),
+                                               ISP_IRQ0ENABLE);
+}
+
+/**
+ * omap34xx_isp_isr - Interrupt Service Routine for Camera ISP module.
+ * @irq: Not used currently.
+ * @ispirq_disp: Pointer to the object that is passed while request_irq is
+ *               called. This is the ispirq_obj object containing info on the
+ *               callback.
+ *
+ * Handles the corresponding callback if plugged in.
+ *
+ * Returns IRQ_HANDLED when IRQ was correctly handled, or IRQ_NONE when the
+ * IRQ wasn't handled.
+ **/
+static irqreturn_t omap34xx_isp_isr(int irq, void *ispirq_disp)
+{
+       struct ispirq *irqdis = (struct ispirq *)ispirq_disp;
+       u32 irqstatus = 0;
+       unsigned long irqflags = 0;
+       u8 is_irqhandled = 0;
+
+       irqstatus = omap_readl(ISP_IRQ0STATUS);
+
+       spin_lock_irqsave(&isp_obj.lock, irqflags);
+
+       if (irqdis->isp_callbk[CBK_CATCHALL])
+               irqdis->isp_callbk[CBK_CATCHALL](
+                       irqstatus,
+                       irqdis->isp_callbk_arg1[CBK_CATCHALL],
+                       irqdis->isp_callbk_arg2[CBK_CATCHALL]);
+
+       if ((irqstatus & MMU_ERR) == MMU_ERR) {
+               if (irqdis->isp_callbk[CBK_MMU_ERR])
+                       irqdis->isp_callbk[CBK_MMU_ERR](irqstatus,
+                               irqdis->isp_callbk_arg1[CBK_MMU_ERR],
+                               irqdis->isp_callbk_arg2[CBK_MMU_ERR]);
+               is_irqhandled = 1;
+               goto out;
+       }
+
+       if ((irqstatus & CCDC_VD1) == CCDC_VD1) {
+               if (irqdis->isp_callbk[CBK_CCDC_VD1])
+                               irqdis->isp_callbk[CBK_CCDC_VD1](CCDC_VD1,
+                               irqdis->isp_callbk_arg1[CBK_CCDC_VD1],
+                               irqdis->isp_callbk_arg2[CBK_CCDC_VD1]);
+               is_irqhandled = 1;
+       }
+
+       if ((irqstatus & CCDC_VD0) == CCDC_VD0) {
+               if (irqdis->isp_callbk[CBK_CCDC_VD0])
+                       irqdis->isp_callbk[CBK_CCDC_VD0](CCDC_VD0,
+                               irqdis->isp_callbk_arg1[CBK_CCDC_VD0],
+                               irqdis->isp_callbk_arg2[CBK_CCDC_VD0]);
+               is_irqhandled = 1;
+       }
+
+       if ((irqstatus & PREV_DONE) == PREV_DONE) {
+               if (irqdis->isp_callbk[CBK_PREV_DONE])
+                       irqdis->isp_callbk[CBK_PREV_DONE](PREV_DONE,
+                               irqdis->isp_callbk_arg1[CBK_PREV_DONE],
+                               irqdis->isp_callbk_arg2[CBK_PREV_DONE]);
+               is_irqhandled = 1;
+       }
+
+       if ((irqstatus & RESZ_DONE) == RESZ_DONE) {
+               if (irqdis->isp_callbk[CBK_RESZ_DONE])
+                       irqdis->isp_callbk[CBK_RESZ_DONE](RESZ_DONE,
+                               irqdis->isp_callbk_arg1[CBK_RESZ_DONE],
+                               irqdis->isp_callbk_arg2[CBK_RESZ_DONE]);
+               is_irqhandled = 1;
+       }
+
+       if ((irqstatus & H3A_AWB_DONE) == H3A_AWB_DONE) {
+               if (irqdis->isp_callbk[CBK_H3A_AWB_DONE])
+                       irqdis->isp_callbk[CBK_H3A_AWB_DONE](H3A_AWB_DONE,
+                               irqdis->isp_callbk_arg1[CBK_H3A_AWB_DONE],
+                               irqdis->isp_callbk_arg2[CBK_H3A_AWB_DONE]);
+               is_irqhandled = 1;
+       }
+
+       if ((irqstatus & HIST_DONE) == HIST_DONE) {
+               if (irqdis->isp_callbk[CBK_HIST_DONE])
+                       irqdis->isp_callbk[CBK_HIST_DONE](HIST_DONE,
+                               irqdis->isp_callbk_arg1[CBK_HIST_DONE],
+                               irqdis->isp_callbk_arg2[CBK_HIST_DONE]);
+               is_irqhandled = 1;
+       }
+
+       if ((irqstatus & HS_VS) == HS_VS) {
+               if (irqdis->isp_callbk[CBK_HS_VS])
+                       irqdis->isp_callbk[CBK_HS_VS](HS_VS,
+                               irqdis->isp_callbk_arg1[CBK_HS_VS],
+                               irqdis->isp_callbk_arg2[CBK_HS_VS]);
+               is_irqhandled = 1;
+       }
+
+       if ((irqstatus & H3A_AF_DONE) == H3A_AF_DONE) {
+               if (irqdis->isp_callbk[CBK_H3A_AF_DONE])
+                       irqdis->isp_callbk[CBK_H3A_AF_DONE](H3A_AF_DONE,
+                               irqdis->isp_callbk_arg1[CBK_H3A_AF_DONE],
+                               irqdis->isp_callbk_arg2[CBK_H3A_AF_DONE]);
+               is_irqhandled = 1;
+       }
+
+       if (irqstatus & LSC_PRE_ERR) {
+               printk(KERN_ERR "isp_sr: LSC_PRE_ERR \n");
+               omap_writel(irqstatus, ISP_IRQ0STATUS);
+               ispccdc_enable_lsc(0);
+               ispccdc_enable_lsc(1);
+               spin_unlock_irqrestore(&isp_obj.lock, irqflags);
+               return IRQ_HANDLED;
+       }
+
+       if (irqstatus & IRQ0STATUS_CSIB_IRQ) {
+               u32 ispcsi1_irqstatus;
+
+               ispcsi1_irqstatus = omap_readl(ISPCSI1_LC01_IRQSTATUS);
+               DPRINTK_ISPCTRL("%x\n", ispcsi1_irqstatus);
+       }
+
+out:
+       omap_writel(irqstatus, ISP_IRQ0STATUS);
+       spin_unlock_irqrestore(&isp_obj.lock, irqflags);
+
+       if (is_irqhandled)
+               return IRQ_HANDLED;
+       else
+               return IRQ_NONE;
+}
+/* Device name, needed for resource tracking layer */
+struct device_driver camera_drv = {
+       .name = "camera"
+};
+
+struct device camera_dev = {
+       .driver = &camera_drv,
+};
+
+/**
+ * isp_set_pipeline - Set bit mask for submodules enabled within the ISP.
+ * @soc_type: Sensor to use: 1 - Smart sensor, 0 - Raw sensor.
+ *
+ * Sets Previewer and Resizer in the bit mask only if its a Raw sensor.
+ **/
+void isp_set_pipeline(int soc_type)
+{
+       ispmodule_obj.isp_pipeline |= OMAP_ISP_CCDC;
+
+       if (!soc_type)
+               ispmodule_obj.isp_pipeline |= (OMAP_ISP_PREVIEW |
+                                                       OMAP_ISP_RESIZER);
+
+       return;
+}
+EXPORT_SYMBOL(isp_open);
+
+/**
+ * omapisp_unset_callback - Unsets all the callbacks associated with ISP module
+ **/
+void omapisp_unset_callback()
+{
+       isp_unset_callback(CBK_HS_VS);
+
+       if ((ispmodule_obj.isp_pipeline & OMAP_ISP_RESIZER) &&
+                                               is_ispresizer_enabled())
+               isp_unset_callback(CBK_RESZ_DONE);
+
+       if ((ispmodule_obj.isp_pipeline & OMAP_ISP_PREVIEW) &&
+                                               is_isppreview_enabled())
+               isp_unset_callback(CBK_PREV_DONE);
+
+       if (ispmodule_obj.isp_pipeline & OMAP_ISP_CCDC) {
+               isp_unset_callback(CBK_CCDC_VD0);
+               isp_unset_callback(CBK_CCDC_VD1);
+               isp_unset_callback(CBK_LSC_ISR);
+       }
+       omap_writel(omap_readl(ISP_IRQ0STATUS) | ISP_INT_CLR, ISP_IRQ0STATUS);
+}
+EXPORT_SYMBOL(isp_close);
+
+/**
+ * isp_start - Starts ISP submodule
+ *
+ * Start the needed isp components assuming these components
+ * are configured correctly.
+ **/
+void isp_start(void)
+{
+       if ((ispmodule_obj.isp_pipeline & OMAP_ISP_PREVIEW) &&
+                                               is_isppreview_enabled())
+               isppreview_enable(1);
+
+       return;
+}
+EXPORT_SYMBOL(isp_start);
+
+/**
+ * isp_stop - Stops isp submodules
+ **/
+void isp_stop()
+{
+       int timeout;
+
+       spin_lock(&isp_obj.isp_temp_buf_lock);
+       ispmodule_obj.isp_temp_state = ISP_FREE_RUNNING;
+       spin_unlock(&isp_obj.isp_temp_buf_lock);
+       omapisp_unset_callback();
+
+       if ((ispmodule_obj.isp_pipeline & OMAP_ISP_RESIZER) &&
+                                               is_ispresizer_enabled()) {
+               ispresizer_enable(0);
+               timeout = 0;
+               while (ispresizer_busy() && (timeout < 20)) {
+                       timeout++;
+                       mdelay(10);
+               }
+       }
+
+       if ((ispmodule_obj.isp_pipeline & OMAP_ISP_PREVIEW) &&
+                                               is_isppreview_enabled()) {
+               isppreview_enable(0);
+               timeout = 0;
+               while (isppreview_busy() && (timeout < 20)) {
+                       timeout++;
+                       mdelay(10);
+               }
+       }
+
+       if (ispmodule_obj.isp_pipeline & OMAP_ISP_CCDC) {
+               ispccdc_enable_lsc(0);
+               ispccdc_enable(0);
+               timeout = 0;
+               while (ispccdc_busy() && (timeout < 20)) {
+                       timeout++;
+                       mdelay(10);
+               }
+       }
+       if (ispccdc_busy() || isppreview_busy() || ispresizer_busy()) {
+               isp_save_ctx();
+               omap_writel(omap_readl(ISP_SYSCONFIG) |
+                       ISP_SYSCONFIG_SOFTRESET, ISP_SYSCONFIG);
+               timeout = 0;
+               while ((!(omap_readl(ISP_SYSSTATUS) & 0x1)) && timeout < 20) {
+                       timeout++;
+                       mdelay(1);
+               }
+       isp_restore_ctx();
+       }
+}
+
+/**
+ * isp_set_buf - Sets output address for submodules.
+ * @sgdma_state: Pointer to structure with the SGDMA state for each videobuffer
+ **/
+void isp_set_buf(struct isp_sgdma_state *sgdma_state)
+{
+       if ((ispmodule_obj.isp_pipeline & OMAP_ISP_RESIZER) &&
+                                               is_ispresizer_enabled())
+               ispresizer_set_outaddr(sgdma_state->isp_addr);
+       else if ((ispmodule_obj.isp_pipeline & OMAP_ISP_PREVIEW) &&
+                                               is_isppreview_enabled())
+               isppreview_set_outaddr(sgdma_state->isp_addr);
+       else if (ispmodule_obj.isp_pipeline & OMAP_ISP_CCDC)
+               ispccdc_set_outaddr(sgdma_state->isp_addr);
+
+}
+
+/**
+ * isp_calc_pipeline - Sets pipeline depending of input and output pixel format
+ * @pix_input: Pointer to V4L2 pixel format structure for input image.
+ * @pix_output: Pointer to V4L2 pixel format structure for output image.
+ **/
+void isp_calc_pipeline(struct v4l2_pix_format *pix_input,
+                                       struct v4l2_pix_format *pix_output)
+{
+       ispmodule_obj.isp_pipeline = OMAP_ISP_CCDC;
+       if ((pix_input->pixelformat == V4L2_PIX_FMT_SGRBG10) &&
+               (pix_output->pixelformat != V4L2_PIX_FMT_SGRBG10)) {
+               ispmodule_obj.isp_pipeline |= (OMAP_ISP_PREVIEW |
+                                                       OMAP_ISP_RESIZER);
+               ispccdc_config_datapath(CCDC_RAW, CCDC_OTHERS_VP);
+               isppreview_config_datapath(PRV_RAW_CCDC, PREVIEW_RSZ);
+               ispresizer_config_datapath(RSZ_OTFLY_YUV);
+       } else {
+               if (pix_input->pixelformat == V4L2_PIX_FMT_SGRBG10)
+                       ispccdc_config_datapath(CCDC_RAW, CCDC_OTHERS_MEM);
+               else
+                       ispccdc_config_datapath(CCDC_YUV_SYNC,
+                                                       CCDC_OTHERS_MEM);
+       }
+       return;
+}
+
+/**
+ * isp_config_pipeline - Configures the image size and ycpos for ISP submodules
+ * @pix_input: Pointer to V4L2 pixel format structure for input image.
+ * @pix_output: Pointer to V4L2 pixel format structure for output image.
+ *
+ * The configuration of ycpos depends on the output pixel format for both the
+ * Preview and Resizer submodules.
+ **/
+void isp_config_pipeline(struct v4l2_pix_format *pix_input,
+                                       struct v4l2_pix_format *pix_output)
+{
+       ispccdc_config_size(ispmodule_obj.ccdc_input_width,
+                       ispmodule_obj.ccdc_input_height,
+                       ispmodule_obj.ccdc_output_width,
+                       ispmodule_obj.ccdc_output_height);
+
+       if (ispmodule_obj.isp_pipeline & OMAP_ISP_PREVIEW)
+               isppreview_config_size(ispmodule_obj.preview_input_width,
+                       ispmodule_obj.preview_input_height,
+                       ispmodule_obj.preview_output_width,
+                       ispmodule_obj.preview_output_height);
+
+       if (ispmodule_obj.isp_pipeline & OMAP_ISP_RESIZER)
+               ispresizer_config_size(ispmodule_obj.resizer_input_width,
+                       ispmodule_obj.resizer_input_height,
+                       ispmodule_obj.resizer_output_width,
+                       ispmodule_obj.resizer_output_height);
+
+       if (pix_output->pixelformat == V4L2_PIX_FMT_UYVY) {
+               isppreview_config_ycpos(YCPOS_YCrYCb);
+               if (is_ispresizer_enabled())
+                       ispresizer_config_ycpos(0);
+       } else {
+               isppreview_config_ycpos(YCPOS_CrYCbY);
+               if (is_ispresizer_enabled())
+                       ispresizer_config_ycpos(1);
+       }
+
+       return;
+}
+
+/**
+ * isp_vbq_done - Callback for interrupt completion
+ * @status: IRQ0STATUS register value. Passed by the ISR, or the caller.
+ * @arg1: Pointer to callback function for SG-DMA management.
+ * @arg2: Pointer to videobuffer structure managed by ISP.
+ **/
+void isp_vbq_done(unsigned long status, isp_vbq_callback_ptr arg1, void *arg2)
+{
+       struct videobuf_buffer *vb = (struct videobuf_buffer *) arg2;
+       int notify = 0;
+       int rval = 0;
+       unsigned long flags;
+
+       switch (status) {
+       case CCDC_VD0:
+               ispccdc_config_shadow_registers();
+               if ((ispmodule_obj.isp_pipeline & OMAP_ISP_RESIZER) ||
+                       (ispmodule_obj.isp_pipeline & OMAP_ISP_PREVIEW))
+                       return;
+               else {
+                       spin_lock(&isp_obj.isp_temp_buf_lock);
+                       if (ispmodule_obj.isp_temp_state != ISP_BUF_INIT) {
+                               spin_unlock(&isp_obj.isp_temp_buf_lock);
+                               return;
+
+                       } else {
+                               spin_unlock(&isp_obj.isp_temp_buf_lock);
+                               break;
+                       }
+               }
+               break;
+       case CCDC_VD1:
+               if ((ispmodule_obj.isp_pipeline & OMAP_ISP_RESIZER) ||
+                       (ispmodule_obj.isp_pipeline & OMAP_ISP_PREVIEW))
+                       return;
+               spin_lock(&isp_obj.isp_temp_buf_lock);
+               if (ispmodule_obj.isp_temp_state == ISP_BUF_INIT) {
+                       spin_unlock(&isp_obj.isp_temp_buf_lock);
+                       ispccdc_enable(0);
+                       return;
+               }
+               spin_unlock(&isp_obj.isp_temp_buf_lock);
+               return;
+               break;
+       case PREV_DONE:
+               if (is_isppreview_enabled()) {
+                       if (ispmodule_obj.isp_pipeline & OMAP_ISP_RESIZER) {
+                               if (!ispmodule_obj.applyCrop && (ispmodule_obj.
+                                                       isp_temp_state ==
+                                                       ISP_BUF_INIT))
+                                       ispresizer_enable(1);
+                               if (ispmodule_obj.applyCrop &&
+                                                       !ispresizer_busy()) {
+                                       ispresizer_enable(0);
+                                       ispresizer_applycrop();
+                                       ispmodule_obj.applyCrop = 0;
+                               }
+                       }
+                       isppreview_config_shadow_registers();
+                       isph3a_update_wb();
+                       if (ispmodule_obj.isp_pipeline & OMAP_ISP_RESIZER)
+                               return;
+               }
+               break;
+       case RESZ_DONE:
+               if (is_ispresizer_enabled()) {
+                       ispresizer_config_shadow_registers();
+                       spin_lock(&isp_obj.isp_temp_buf_lock);
+                       if (ispmodule_obj.isp_temp_state != ISP_BUF_INIT) {
+                               spin_unlock(&isp_obj.isp_temp_buf_lock);
+                               return;
+                       }
+                       spin_unlock(&isp_obj.isp_temp_buf_lock);
+               }
+               break;
+       case HS_VS:
+               spin_lock(&isp_obj.isp_temp_buf_lock);
+               if (ispmodule_obj.isp_temp_state == ISP_BUF_TRAN) {
+                       isp_CCDC_VD01_enable();
+                       ispmodule_obj.isp_temp_state = ISP_BUF_INIT;
+               }
+               spin_unlock(&isp_obj.isp_temp_buf_lock);
+               return;
+       default:
+               break;
+       }
+
+       spin_lock_irqsave(&ispsg.lock, flags);
+       ispsg.free_sgdma++;
+       if (ispsg.free_sgdma > NUM_SG_DMA)
+               ispsg.free_sgdma = NUM_SG_DMA;
+       spin_unlock_irqrestore(&ispsg.lock, flags);
+
+       rval = arg1(vb);
+
+       if (rval)
+               isp_sgdma_process(&ispsg, 1, &notify, arg1);
+
+       return;
+}
+
+/**
+ * isp_sgdma_init - Initializes Scatter Gather DMA status and operations.
+ **/
+void isp_sgdma_init()
+{
+       int sg;
+
+       ispsg.free_sgdma = NUM_SG_DMA;
+       ispsg.next_sgdma = 0;
+       for (sg = 0; sg < NUM_SG_DMA; sg++) {
+               ispsg.sg_state[sg].status = 0;
+               ispsg.sg_state[sg].callback = NULL;
+               ispsg.sg_state[sg].arg = NULL;
+       }
+}
+EXPORT_SYMBOL(isp_stop);
+
+/**
+ * isp_sgdma_process - Sets operations and config for specified SG DMA
+ * @sgdma: SG-DMA function to work on.
+ * @irq: Flag to specify if an IRQ is associated with the DMA completion.
+ * @dma_notify: Pointer to flag that says when the ISP has to be started.
+ * @func_ptr: Callback function pointer for SG-DMA setup.
+ **/
+void isp_sgdma_process(struct isp_sgdma *sgdma, int irq, int *dma_notify,
+                                               isp_vbq_callback_ptr func_ptr)
+{
+       struct isp_sgdma_state *sgdma_state;
+       unsigned long flags;
+       spin_lock_irqsave(&sgdma->lock, flags);
+
+       if (NUM_SG_DMA > sgdma->free_sgdma) {
+               sgdma_state = sgdma->sg_state +
+                       (sgdma->next_sgdma + sgdma->free_sgdma) % NUM_SG_DMA;
+               if (!irq) {
+                       if (*dma_notify) {
+                               isp_set_sgdma_callback(sgdma_state, func_ptr);
+                               isp_set_buf(sgdma_state);
+                               ispccdc_enable(1);
+                               isp_start();
+                               *dma_notify = 0;
+                               ispmodule_obj.isp_temp_state = ISP_BUF_TRAN;
+                       } else {
+                               if (ispmodule_obj.isp_temp_state ==
+                                                       ISP_FREE_RUNNING) {
+                                       isp_set_sgdma_callback(sgdma_state,
+                                                               func_ptr);
+                                       isp_set_buf(sgdma_state);
+                                       ispccdc_enable(1);
+                                       ispmodule_obj.isp_temp_state =
+                                                               ISP_BUF_TRAN;
+                               }
+                       }
+               } else {
+                       isp_set_sgdma_callback(sgdma_state, func_ptr);
+                       isp_set_buf(sgdma_state);
+                       ispccdc_enable(1);
+                       ispmodule_obj.isp_temp_state = ISP_BUF_INIT;
+
+                       if (*dma_notify) {
+                               isp_start();
+                               *dma_notify = 0;
+                       }
+               }
+       } else {
+               spin_lock(&isp_obj.isp_temp_buf_lock);
+               isp_CCDC_VD01_disable();
+               ispmodule_obj.isp_temp_state = ISP_FREE_RUNNING;
+               spin_unlock(&isp_obj.isp_temp_buf_lock);
+       }
+       spin_unlock_irqrestore(&sgdma->lock, flags);
+       return;
+}
+
+/**
+ * isp_sgdma_queue - Queues a Scatter-Gather DMA videobuffer.
+ * @vdma: Pointer to structure containing the desired DMA video buffer
+ *        transfer parameters.
+ * @vb: Pointer to structure containing the target videobuffer.
+ * @irq: Flag to specify if an IRQ is associated with the DMA completion.
+ * @dma_notify: Pointer to flag that says when the ISP has to be started.
+ * @func_ptr: Callback function pointer for SG-DMA setup.
+ *
+ * Returns 0 if successful, -EINVAL if invalid SG linked list setup, or -EBUSY
+ * if the ISP SG-DMA is not free.
+ **/
+int isp_sgdma_queue(struct videobuf_dmabuf *vdma, struct videobuf_buffer *vb,
+                                               int irq, int *dma_notify,
+                                               isp_vbq_callback_ptr func_ptr)
+{
+       unsigned long flags;
+       struct isp_sgdma_state *sg_state;
+       const struct scatterlist *sglist = vdma->sglist;
+       int sglen = vdma->sglen;
+
+       if ((sglen < 0) || ((sglen > 0) & !sglist))
+               return -EINVAL;
+
+       spin_lock_irqsave(&ispsg.lock, flags);
+
+       if (!ispsg.free_sgdma) {
+               spin_unlock_irqrestore(&ispsg.lock, flags);
+               return -EBUSY;
+       }
+
+       sg_state = ispsg.sg_state + ispsg.next_sgdma;
+       sg_state->isp_addr = ispsg.isp_addr_capture[vb->i];
+       sg_state->status = 0;
+       sg_state->callback = isp_vbq_done;
+       sg_state->arg = vb;
+
+       ispsg.next_sgdma = (ispsg.next_sgdma + 1) % NUM_SG_DMA;
+       ispsg.free_sgdma--;
+
+       spin_unlock_irqrestore(&ispsg.lock, flags);
+
+       isp_sgdma_process(&ispsg, irq, dma_notify, func_ptr);
+
+       return 0;
+}
+EXPORT_SYMBOL(isp_sgdma_queue);
+
+/**
+ * isp_vbq_prepare - Videobuffer queue prepare.
+ * @vbq: Pointer to videobuf_queue structure.
+ * @vb: Pointer to videobuf_buffer structure.
+ * @field: Requested Field order for the videobuffer.
+ *
+ * Returns 0 if successful, or -EIO if the ispmmu was unable to map a
+ * scatter-gather linked list data space.
+ **/
+int isp_vbq_prepare(struct videobuf_queue *vbq, struct videobuf_buffer *vb,
+                                                       enum v4l2_field field)
+{
+       unsigned int isp_addr;
+       struct videobuf_dmabuf  *vdma;
+
+       int err = 0;
+
+       vdma = videobuf_to_dma(vb);
+
+       isp_addr = ispmmu_map_sg(vdma->sglist, vdma->sglen);
+
+       if (!isp_addr)
+               err = -EIO;
+       else
+               ispsg.isp_addr_capture[vb->i] = isp_addr;
+
+       return err;
+}
+EXPORT_SYMBOL(isp_vbq_prepare);
+
+/**
+ * isp_vbq_release - Videobuffer queue release.
+ * @vbq: Pointer to videobuf_queue structure.
+ * @vb: Pointer to videobuf_buffer structure.
+ **/
+void isp_vbq_release(struct videobuf_queue *vbq, struct videobuf_buffer *vb)
+{
+       ispmmu_unmap(ispsg.isp_addr_capture[vb->i]);
+       ispsg.isp_addr_capture[vb->i] = (dma_addr_t) NULL;
+       return;
+}
+EXPORT_SYMBOL(isp_vbq_release);
+
+/**
+ * isp_queryctrl - Query V4L2 control from existing controls in ISP.
+ * @a: Pointer to v4l2_queryctrl structure. It only needs the id field filled.
+ *
+ * Returns 0 if successful, or -EINVAL if not found in ISP.
+ **/
+int isp_queryctrl(struct v4l2_queryctrl *a)
+{
+       int i;
+
+       i = find_vctrl(a->id);
+       if (i == -EINVAL)
+               a->flags = V4L2_CTRL_FLAG_DISABLED;
+
+       if (i < 0)
+               return -EINVAL;
+
+       *a = video_control[i].qc;
+       return 0;
+}
+EXPORT_SYMBOL(isp_queryctrl);
+
+/**
+ * isp_g_ctrl - Gets value of the desired V4L2 control.
+ * @a: V4L2 control to read actual value from.
+ *
+ * Return 0 if successful, or -EINVAL if chosen control is not found.
+ **/
+int isp_g_ctrl(struct v4l2_control *a)
+{
+       u8 current_value;
+       int rval = 0;
+
+       switch (a->id) {
+       case V4L2_CID_BRIGHTNESS:
+               isppreview_query_brightness(&current_value);
+               a->value = current_value / ISPPRV_BRIGHT_UNITS;
+               break;
+       case V4L2_CID_CONTRAST:
+               isppreview_query_contrast(&current_value);
+               a->value = current_value / ISPPRV_CONTRAST_UNITS;
+               break;
+       case V4L2_CID_PRIVATE_ISP_COLOR_FX:
+               isppreview_get_color(&current_value);
+               a->value = current_value;
+               break;
+       default:
+               rval = -EINVAL;
+               break;
+       }
+
+       return rval;
+}
+EXPORT_SYMBOL(isp_g_ctrl);
+
+/**
+ * isp_s_ctrl - Sets value of the desired V4L2 control.
+ * @a: V4L2 control to read actual value from.
+ *
+ * Return 0 if successful, -EINVAL if chosen control is not found or value
+ * is out of bounds, -EFAULT if copy_from_user or copy_to_user operation fails
+ * from camera abstraction layer related controls or the transfered user space
+ * pointer via the value field is not set properly.
+ **/
+int isp_s_ctrl(struct v4l2_control *a)
+{
+       int rval = 0;
+       u8 new_value = a->value;
+
+       switch (a->id) {
+       case V4L2_CID_BRIGHTNESS:
+               if (new_value > ISPPRV_BRIGHT_HIGH)
+                       rval = -EINVAL;
+               else
+                       isppreview_update_brightness(&new_value);
+               break;
+       case V4L2_CID_CONTRAST:
+               if (new_value > ISPPRV_CONTRAST_HIGH)
+                       rval = -EINVAL;
+               else
+                       isppreview_update_contrast(&new_value);
+               break;
+       case V4L2_CID_PRIVATE_ISP_COLOR_FX:
+               if (new_value > PREV_SEPIA_COLOR)
+                       rval = -EINVAL;
+               else
+                       isppreview_set_color(&new_value);
+               break;
+       default:
+               rval = -EINVAL;
+               break;
+       }
+
+       return rval;
+}
+EXPORT_SYMBOL(isp_s_ctrl);
+
+/**
+ * isp_handle_private - Handle all private ioctls for isp module.
+ * @cmd: ioctl cmd value
+ * @arg: ioctl arg value
+ *
+ * Return 0 if successful, -EINVAL if chosen cmd value is not handled or value
+ * is out of bounds, -EFAULT if ioctl arg value is not valid.
+ * Function simply routes the input ioctl cmd id to the appropriate handler in
+ * the isp module.
+ **/
+int isp_handle_private(int cmd, void *arg)
+{
+       int rval = 0;
+
+       switch (cmd) {
+       case VIDIOC_PRIVATE_ISP_CCDC_CFG:
+               rval = omap34xx_isp_ccdc_config(arg);
+               break;
+       case VIDIOC_PRIVATE_ISP_PRV_CFG:
+               rval = omap34xx_isp_preview_config(arg);
+               break;
+       case VIDIOC_PRIVATE_ISP_AEWB_CFG: {
+               struct isph3a_aewb_config *params;
+               params = (struct isph3a_aewb_config *) arg;
+               rval = isph3a_aewb_configure(params);
+               }
+               break;
+       case VIDIOC_PRIVATE_ISP_AEWB_REQ: {
+               struct isph3a_aewb_data *data;
+               data = (struct isph3a_aewb_data *) arg;
+               rval = isph3a_aewb_request_statistics(data);
+               }
+               break;
+       case VIDIOC_PRIVATE_ISP_HIST_CFG: {
+               struct isp_hist_config *params;
+               params = (struct isp_hist_config *) arg;
+               rval = isp_hist_configure(params);
+               }
+               break;
+       case VIDIOC_PRIVATE_ISP_HIST_REQ: {
+               struct isp_hist_data *data;
+               data = (struct isp_hist_data *) arg;
+               rval = isp_hist_request_statistics(data);
+               }
+               break;
+       case VIDIOC_PRIVATE_ISP_AF_CFG: {
+               struct af_configuration *params;
+               params = (struct af_configuration *) arg;
+               rval = isp_af_configure(params);
+               }
+       break;
+       case VIDIOC_PRIVATE_ISP_AF_REQ: {
+               struct isp_af_data *data;
+               data = (struct isp_af_data *) arg;
+               rval = isp_af_request_statistics(data);
+               }
+       break;
+       default:
+               rval = -EINVAL;
+               break;
+       }
+       return rval;
+}
+EXPORT_SYMBOL(isp_handle_private);
+
+/**
+ * isp_enum_fmt_cap - Gets more information of chosen format index and type
+ * @f: Pointer to structure containing index and type of format to read from.
+ *
+ * Returns 0 if successful, or -EINVAL if format index or format type is
+ * invalid.
+ **/
+int isp_enum_fmt_cap(struct v4l2_fmtdesc *f)
+{
+       int index = f->index;
+       enum v4l2_buf_type type = f->type;
+       int rval = -EINVAL;
+
+       if (index >= NUM_ISP_CAPTURE_FORMATS)
+               goto err;
+
+       memset(f, 0, sizeof(*f));
+       f->index = index;
+       f->type = type;
+
+       switch (f->type) {
+       case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+               rval = 0;
+               break;
+       default:
+               goto err;
+       }
+
+       f->flags = isp_formats[index].flags;
+       strncpy(f->description, isp_formats[index].description,
+                                               sizeof(f->description));
+       f->pixelformat = isp_formats[index].pixelformat;
+err:
+       return rval;
+}
+EXPORT_SYMBOL(isp_enum_fmt_cap);
+
+/**
+ * isp_g_fmt_cap - Gets current output image format.
+ * @f: Pointer to V4L2 format structure to be filled with current output format
+ **/
+void isp_g_fmt_cap(struct v4l2_pix_format *pix)
+{
+       *pix = ispmodule_obj.pix;
+       return;
+}
+EXPORT_SYMBOL(isp_g_fmt_cap);
+
+/**
+ * isp_s_fmt_cap - Sets I/O formats and crop and configures pipeline in ISP
+ * @f: Pointer to V4L2 format structure to be filled with current output format
+ *
+ * Returns 0 if successful, or return value of either isp_try_size or
+ * isp_try_fmt if there is an error.
+ **/
+int isp_s_fmt_cap(struct v4l2_pix_format *pix_input,
+                                       struct v4l2_pix_format *pix_output)
+{
+       int crop_scaling_w, crop_scaling_h = 0;
+       int rval = 0;
+
+       isp_calc_pipeline(pix_input, pix_output);
+       rval = isp_try_size(pix_input, pix_output);
+
+       if (rval)
+               goto out;
+
+       rval = isp_try_fmt(pix_input, pix_output);
+       if (rval)
+               goto out;
+
+       if (ispcroprect.width != pix_output->width) {
+               crop_scaling_w = 1;
+               ispcroprect.left = 0;
+               ispcroprect.width = pix_output->width;
+       }
+
+       if (ispcroprect.height != pix_output->height) {
+               crop_scaling_h = 1;
+               ispcroprect.top = 0;
+               ispcroprect.height = pix_output->height;
+       }
+
+       isp_config_pipeline(pix_input, pix_output);
+
+       if (crop_scaling_h || crop_scaling_w)
+               isp_config_crop(pix_output);
+
+out:
+       return rval;
+}
+EXPORT_SYMBOL(isp_s_fmt_cap);
+
+/**
+ * isp_config_crop - Configures crop parameters in isp resizer.
+ * @croppix: Pointer to V4L2 pixel format structure containing crop parameters
+ **/
+void isp_config_crop(struct v4l2_pix_format *croppix)
+{
+       u8 crop_scaling_w;
+       u8 crop_scaling_h;
+       struct v4l2_pix_format *pix = croppix;
+
+       crop_scaling_w = (ispmodule_obj.preview_output_width * 10) /
+                                                               pix->width;
+       crop_scaling_h = (ispmodule_obj.preview_output_height * 10) /
+                                                               pix->height;
+
+       cur_rect.left = (ispcroprect.left * crop_scaling_w) / 10;
+       cur_rect.top = (ispcroprect.top * crop_scaling_h) / 10;
+       cur_rect.width = (ispcroprect.width * crop_scaling_w) / 10;
+       cur_rect.height = (ispcroprect.height * crop_scaling_h) / 10;
+
+       ispresizer_trycrop(cur_rect.left, cur_rect.top, cur_rect.width,
+                                       cur_rect.height,
+                                       ispmodule_obj.resizer_output_width,
+                                       ispmodule_obj.resizer_output_height);
+
+       return;
+}
+EXPORT_SYMBOL(isp_config_crop);
+
+/**
+ * isp_g_crop - Gets crop rectangle size and position.
+ * @a: Pointer to V4L2 crop structure to be filled.
+ *
+ * Always returns 0.
+ **/
+int isp_g_crop(struct v4l2_crop *a)
+{
+       struct v4l2_crop *crop = a;
+
+       crop->c = ispcroprect;
+       return 0;
+}
+EXPORT_SYMBOL(isp_g_crop);
+
+/**
+ * isp_s_crop - Sets crop rectangle size and position and queues crop operation
+ * @a: Pointer to V4L2 crop structure with desired parameters.
+ * @pix: Pointer to V4L2 pixel format structure with desired parameters.
+ *
+ * Returns 0 if successful, or -EINVAL if crop parameters are out of bounds.
+ **/
+int isp_s_crop(struct v4l2_crop *a, struct v4l2_pix_format *pix)
+{
+       struct v4l2_crop *crop = a;
+       int rval = 0;
+
+       if ((crop->c.left + crop->c.width) > pix->width) {
+               rval = -EINVAL;
+               goto out;
+       }
+
+       if ((crop->c.top + crop->c.height) > pix->height) {
+               rval = -EINVAL;
+               goto out;
+       }
+
+       ispcroprect.left = crop->c.left;
+       ispcroprect.top = crop->c.top;
+       ispcroprect.width = crop->c.width;
+       ispcroprect.height = crop->c.height;
+
+       isp_config_crop(pix);
+
+       ispmodule_obj.applyCrop = 1;
+out:
+       return rval;
+}
+EXPORT_SYMBOL(isp_s_crop);
+
+/**
+ * isp_try_fmt_cap - Tries desired input/output image formats
+ * @pix_input: Pointer to V4L2 pixel format structure for input image.
+ * @pix_output: Pointer to V4L2 pixel format structure for output image.
+ *
+ * Returns 0 if successful, or return value of either isp_try_size or
+ * isp_try_fmt if there is an error.
+ **/
+int isp_try_fmt_cap(struct v4l2_pix_format *pix_input,
+                                       struct v4l2_pix_format *pix_output)
+{
+       int rval = 0;
+
+       isp_calc_pipeline(pix_input, pix_output);
+       rval = isp_try_size(pix_input, pix_output);
+
+       if (rval)
+               goto out;
+
+       rval = isp_try_fmt(pix_input, pix_output);
+
+       if (rval)
+               goto out;
+
+out:
+       return rval;
+}
+EXPORT_SYMBOL(isp_try_fmt_cap);
+
+/**
+ * isp_try_size - Tries size configuration for I/O images of each ISP submodule
+ * @pix_input: Pointer to V4L2 pixel format structure for input image.
+ * @pix_output: Pointer to V4L2 pixel format structure for output image.
+ *
+ * Returns 0 if successful, or return value of ispccdc_try_size,
+ * isppreview_try_size, or ispresizer_try_size (depending on the pipeline
+ * configuration) if there is an error.
+ **/
+int isp_try_size(struct v4l2_pix_format *pix_input,
+                                       struct v4l2_pix_format *pix_output)
+{
+       int rval = 0;
+       ispmodule_obj.ccdc_input_width = pix_input->width;
+       ispmodule_obj.ccdc_input_height = pix_input->height;
+       ispmodule_obj.resizer_output_width = pix_output->width;
+       ispmodule_obj.resizer_output_height = pix_output->height;
+
+       if (ispmodule_obj.isp_pipeline & OMAP_ISP_CCDC) {
+               rval = ispccdc_try_size(ispmodule_obj.ccdc_input_width,
+                                       ispmodule_obj.ccdc_input_height,
+                                       &ispmodule_obj.ccdc_output_width,
+                                       &ispmodule_obj.ccdc_output_height);
+               pix_output->width = ispmodule_obj.ccdc_output_width;
+               pix_output->height = ispmodule_obj.ccdc_output_height;
+       }
+
+       if (ispmodule_obj.isp_pipeline & OMAP_ISP_PREVIEW) {
+               ispmodule_obj.preview_input_width =
+                                       ispmodule_obj.ccdc_output_width;
+               ispmodule_obj.preview_input_height =
+                                       ispmodule_obj.ccdc_output_height;
+               rval = isppreview_try_size(ispmodule_obj.preview_input_width,
+                                       ispmodule_obj.preview_input_height,
+                                       &ispmodule_obj.preview_output_width,
+                                       &ispmodule_obj.preview_output_height);
+               pix_output->width = ispmodule_obj.preview_output_width;
+               pix_output->height = ispmodule_obj.preview_output_height;
+       }
+
+       if (ispmodule_obj.isp_pipeline & OMAP_ISP_RESIZER) {
+               ispmodule_obj.resizer_input_width =
+                                       ispmodule_obj.preview_output_width;
+               ispmodule_obj.resizer_input_height =
+                                       ispmodule_obj.preview_output_height;
+               rval = ispresizer_try_size(&ispmodule_obj.resizer_input_width,
+                                       &ispmodule_obj.resizer_input_height,
+                                       &ispmodule_obj.resizer_output_width,
+                                       &ispmodule_obj.resizer_output_height);
+               pix_output->width = ispmodule_obj.resizer_output_width;
+               pix_output->height = ispmodule_obj.resizer_output_height;
+       }
+
+       return rval;
+}
+EXPORT_SYMBOL(isp_try_size);
+
+/**
+ * isp_try_fmt - Validates input/output format parameters.
+ * @pix_input: Pointer to V4L2 pixel format structure for input image.
+ * @pix_output: Pointer to V4L2 pixel format structure for output image.
+ *
+ * Always returns 0.
+ **/
+int isp_try_fmt(struct v4l2_pix_format *pix_input,
+                                       struct v4l2_pix_format *pix_output)
+{
+       int ifmt;
+
+       for (ifmt = 0; ifmt < NUM_ISP_CAPTURE_FORMATS; ifmt++) {
+               if (pix_output->pixelformat == isp_formats[ifmt].pixelformat)
+                       break;
+       }
+       if (ifmt == NUM_ISP_CAPTURE_FORMATS)
+               ifmt = 1;
+       pix_output->pixelformat = isp_formats[ifmt].pixelformat;
+       pix_output->field = V4L2_FIELD_NONE;
+       pix_output->bytesperline = pix_output->width * ISP_BYTES_PER_PIXEL;
+       pix_output->sizeimage =
+               PAGE_ALIGN(pix_output->bytesperline * pix_output->height);
+       pix_output->priv = 0;
+       switch (pix_output->pixelformat) {
+       case V4L2_PIX_FMT_YUYV:
+       case V4L2_PIX_FMT_UYVY:
+               pix_output->colorspace = V4L2_COLORSPACE_JPEG;
+               break;
+       default:
+               pix_output->colorspace = V4L2_COLORSPACE_SRGB;
+               break;
+       }
+
+       ispmodule_obj.pix.pixelformat = pix_output->pixelformat;
+       ispmodule_obj.pix.width = pix_output->width;
+       ispmodule_obj.pix.height = pix_output->height;
+       ispmodule_obj.pix.field = pix_output->field;
+       ispmodule_obj.pix.bytesperline = pix_output->bytesperline;
+       ispmodule_obj.pix.sizeimage = pix_output->sizeimage;
+       ispmodule_obj.pix.priv = pix_output->priv;
+       ispmodule_obj.pix.colorspace = pix_output->colorspace;
+
+       return 0;
+}
+EXPORT_SYMBOL(isp_try_fmt);
+
+/**
+ * isp_save_ctx - Saves ISP, CCDC, HIST, H3A, PREV, RESZ & MMU context.
+ *
+ * Routine for saving the context of each module in the ISP.
+ * CCDC, HIST, H3A, PREV, RESZ and MMU.
+ **/
+void isp_save_ctx(void)
+{
+       isp_save_context(isp_reg_list);
+       ispccdc_save_context();
+       ispmmu_save_context();
+       isphist_save_context();
+       isph3a_save_context();
+       isppreview_save_context();
+       ispresizer_save_context();
+}
+EXPORT_SYMBOL(isp_save_ctx);
+
+/**
+ * isp_restore_ctx - Restores ISP, CCDC, HIST, H3A, PREV, RESZ & MMU context.
+ *
+ * Routine for restoring the context of each module in the ISP.
+ * CCDC, HIST, H3A, PREV, RESZ and MMU.
+ **/
+void isp_restore_ctx(void)
+{
+       isp_restore_context(isp_reg_list);
+       ispccdc_restore_context();
+       ispmmu_restore_context();
+       isphist_restore_context();
+       isph3a_restore_context();
+       isppreview_restore_context();
+       ispresizer_restore_context();
+}
+EXPORT_SYMBOL(isp_restore_ctx);
+
+/**
+ * isp_get - Adquires the ISP resource.
+ *
+ * Initializes the clocks for the first acquire.
+ **/
+int isp_get(void)
+{
+       int ret_err = 0;
+       DPRINTK_ISPCTRL("isp_get: old %d\n", isp_obj.ref_count);
+       mutex_lock(&(isp_obj.isp_mutex));
+       if (isp_obj.ref_count == 0) {
+               isp_obj.cam_ick = clk_get(&camera_dev, "cam_ick");
+               if (IS_ERR(isp_obj.cam_ick)) {
+                       DPRINTK_ISPCTRL("ISP_ERR: clk_get for "
+                                                       "cam_ick failed\n");
+                       ret_err = PTR_ERR(isp_obj.cam_ick);
+                       goto out_clk_get_ick;
+               }
+               isp_obj.cam_mclk = clk_get(&camera_dev, "cam_mclk");
+               if (IS_ERR(isp_obj.cam_mclk)) {
+                       DPRINTK_ISPCTRL("ISP_ERR: clk_get for "
+                                                       "cam_mclk failed\n");
+                       ret_err = PTR_ERR(isp_obj.cam_mclk);
+                       goto out_clk_get_mclk;
+               }
+               ret_err = clk_enable(isp_obj.cam_ick);
+               if (ret_err) {
+                       DPRINTK_ISPCTRL("ISP_ERR: clk_en for ick failed\n");
+                       goto out_clk_enable_ick;
+               }
+               ret_err = clk_enable(isp_obj.cam_mclk);
+               if (ret_err) {
+                       DPRINTK_ISPCTRL("ISP_ERR: clk_en for mclk failed\n");
+                       goto out_clk_enable_mclk;
+               }
+               if (off_mode == 1)
+                       isp_restore_ctx();
+       }
+       isp_obj.ref_count++;
+       mutex_unlock(&(isp_obj.isp_mutex));
+
+
+       DPRINTK_ISPCTRL("isp_get: new %d\n", isp_obj.ref_count);
+       return isp_obj.ref_count;
+
+out_clk_enable_mclk:
+       clk_disable(isp_obj.cam_ick);
+out_clk_enable_ick:
+       clk_put(isp_obj.cam_mclk);
+out_clk_get_mclk:
+       clk_put(isp_obj.cam_ick);
+out_clk_get_ick:
+
+       mutex_unlock(&(isp_obj.isp_mutex));
+
+       return ret_err;
+}
+EXPORT_SYMBOL(isp_get);
+
+/**
+ * isp_put - Releases the ISP resource.
+ *
+ * Releases the clocks also for the last release.
+ **/
+int isp_put(void)
+{
+       DPRINTK_ISPCTRL("isp_put: old %d\n", isp_obj.ref_count);
+       mutex_lock(&(isp_obj.isp_mutex));
+       if (isp_obj.ref_count)
+               if (--isp_obj.ref_count == 0) {
+                       isp_save_ctx();
+                       off_mode = 1;
+
+                       clk_disable(isp_obj.cam_ick);
+                       clk_disable(isp_obj.cam_mclk);
+                       clk_put(isp_obj.cam_ick);
+                       clk_put(isp_obj.cam_mclk);
+               }
+       mutex_unlock(&(isp_obj.isp_mutex));
+       DPRINTK_ISPCTRL("isp_put: new %d\n", isp_obj.ref_count);
+       return isp_obj.ref_count;
+}
+EXPORT_SYMBOL(isp_put);
+
+/**
+ * isp_save_context - Saves the values of the ISP module registers.
+ * @reg_list: Structure containing pairs of register address and value to
+ *            modify on OMAP.
+ **/
+void isp_save_context(struct isp_reg *reg_list)
+{
+       struct isp_reg *next = reg_list;
+
+       for (; next->reg != ISP_TOK_TERM; next++)
+               next->val = omap_readl(next->reg);
+}
+EXPORT_SYMBOL(isp_save_context);
+
+/**
+ * isp_restore_context - Restores the values of the ISP module registers.
+ * @reg_list: Structure containing pairs of register address and value to
+ *            modify on OMAP.
+ **/
+void isp_restore_context(struct isp_reg *reg_list)
+{
+       struct isp_reg *next = reg_list;
+
+       for (; next->reg != ISP_TOK_TERM; next++)
+               omap_writel(next->val, next->reg);
+}
+EXPORT_SYMBOL(isp_restore_context);
+
+/**
+ * isp_init - ISP module initialization.
+ **/
+static int __init isp_init(void)
+{
+       DPRINTK_ISPCTRL("+isp_init for Omap 3430 Camera ISP\n");
+       isp_obj.ref_count = 0;
+
+       mutex_init(&(isp_obj.isp_mutex));
+       spin_lock_init(&isp_obj.isp_temp_buf_lock);
+       spin_lock_init(&isp_obj.lock);
+
+       if (request_irq(INT_34XX_CAM_IRQ, omap34xx_isp_isr, IRQF_SHARED,
+                               "Omap 34xx Camera ISP", &ispirq_obj)) {
+               DPRINTK_ISPCTRL("Could not install ISR\n");
+               return -EINVAL;
+       }
+
+       isp_ccdc_init();
+       isp_hist_init();
+       isph3a_aewb_init();
+       ispmmu_init();
+       isp_preview_init();
+       isp_resizer_init();
+       isp_af_init();
+
+       DPRINTK_ISPCTRL("-isp_init for Omap 3430 Camera ISP\n");
+       return 0;
+}
+EXPORT_SYMBOL(isp_sgdma_init);
+
+/**
+ * isp_cleanup - ISP module cleanup.
+ **/
+static void __exit isp_cleanup(void)
+{
+       isp_af_exit();
+       isp_resizer_cleanup();
+       isp_preview_cleanup();
+       ispmmu_cleanup();
+       isph3a_aewb_cleanup();
+       isp_hist_cleanup();
+       isp_ccdc_cleanup();
+       free_irq(INT_34XX_CAM_IRQ, &ispirq_obj);
+}
+
+/**
+ * isp_print_status - Prints the values of the ISP Control Module registers
+ *
+ * Also prints other debug information stored in the ISP module structure.
+ **/
+void isp_print_status(void)
+{
+       if (!is_ispctrl_debug_enabled())
+               return;
+
+       DPRINTK_ISPCTRL("###CM_FCLKEN_CAM=0x%x\n", omap_readl(CM_FCLKEN_CAM));
+       DPRINTK_ISPCTRL("###CM_ICLKEN_CAM=0x%x\n", omap_readl(CM_ICLKEN_CAM));
+       DPRINTK_ISPCTRL("###CM_CLKSEL_CAM=0x%x\n", omap_readl(CM_CLKSEL_CAM));
+       DPRINTK_ISPCTRL("###CM_AUTOIDLE_CAM=0x%x\n",
+                                               omap_readl(CM_AUTOIDLE_CAM));
+       DPRINTK_ISPCTRL("###CM_CLKEN_PLL[18:16] should be 0x7, = 0x%x\n",
+                                               omap_readl(CM_CLKEN_PLL));
+       DPRINTK_ISPCTRL("###CM_CLKSEL2_PLL[18:8] should be 0x2D, [6:0] should "
+                               "be 1 = 0x%x\n", omap_readl(CM_CLKSEL2_PLL));
+       DPRINTK_ISPCTRL("###CTRL_PADCONF_CAM_HS=0x%x\n",
+                                       omap_readl(CTRL_PADCONF_CAM_HS));
+       DPRINTK_ISPCTRL("###CTRL_PADCONF_CAM_XCLKA=0x%x\n",
+                                       omap_readl(CTRL_PADCONF_CAM_XCLKA));
+       DPRINTK_ISPCTRL("###CTRL_PADCONF_CAM_D1=0x%x\n",
+                                       omap_readl(CTRL_PADCONF_CAM_D1));
+       DPRINTK_ISPCTRL("###CTRL_PADCONF_CAM_D3=0x%x\n",
+                                       omap_readl(CTRL_PADCONF_CAM_D3));
+       DPRINTK_ISPCTRL("###CTRL_PADCONF_CAM_D5=0x%x\n",
+                                       omap_readl(CTRL_PADCONF_CAM_D5));
+       DPRINTK_ISPCTRL("###CTRL_PADCONF_CAM_D7=0x%x\n",
+                                       omap_readl(CTRL_PADCONF_CAM_D7));
+       DPRINTK_ISPCTRL("###CTRL_PADCONF_CAM_D9=0x%x\n",
+                                       omap_readl(CTRL_PADCONF_CAM_D9));
+       DPRINTK_ISPCTRL("###CTRL_PADCONF_CAM_D11=0x%x\n",
+                                       omap_readl(CTRL_PADCONF_CAM_D11));
+}
+EXPORT_SYMBOL(isp_print_status);
+
+module_init(isp_init);
+module_exit(isp_cleanup);
+
+MODULE_AUTHOR("Texas Instruments");
+MODULE_DESCRIPTION("ISP Control Module Library");
+MODULE_LICENSE("GPL");
Index: linux-omap-2.6/drivers/media/video/isp/isp.h
===================================================================
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ linux-omap-2.6/drivers/media/video/isp/isp.h        2008-08-28 19:08:43.000000000 -0500
@@ -0,0 +1,348 @@
+/*
+ * drivers/media/video/isp/isp.h
+ *
+ * Top level public header file for ISP Control module in
+ * TI's OMAP3430 Camera ISP
+ *
+ * Copyright (C) 2008 Texas Instruments.
+ * Copyright (C) 2008 Nokia.
+ *
+ * Contributors:
+ *     Sameer Venkatraman <sameerv@xxxxxx>
+ *     Mohit Jalori <mjalori@xxxxxx>
+ *     Sakari Ailus <sakari.ailus@xxxxxxxxx>
+ *     Tuukka Toivonen <tuukka.o.toivonen@xxxxxxxxx>
+ *
+ * This package is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifndef OMAP_ISP_TOP_H
+#define OMAP_ISP_TOP_H
+#include <media/videobuf-dma-sg.h>
+#include <linux/videodev2.h>
+#define OMAP_ISP_CCDC          (1 << 0)
+#define OMAP_ISP_PREVIEW       (1 << 1)
+#define OMAP_ISP_RESIZER       (1 << 2)
+#define OMAP_ISP_AEWB          (1 << 3)
+#define OMAP_ISP_AF            (1 << 4)
+#define OMAP_ISP_HIST          (1 << 5)
+
+/* Our ISP specific controls */
+#define V4L2_CID_PRIVATE_ISP_COLOR_FX          (V4L2_CID_PRIVATE_BASE + 0)
+
+/* ISP Private IOCTLs */
+#define VIDIOC_PRIVATE_ISP_CCDC_CFG    \
+       _IOWR('V', BASE_VIDIOC_PRIVATE + 1, struct ispccdc_update_config)
+#define VIDIOC_PRIVATE_ISP_PRV_CFG \
+       _IOWR('V', BASE_VIDIOC_PRIVATE + 2, struct ispprv_update_config)
+#define VIDIOC_PRIVATE_ISP_AEWB_CFG \
+       _IOWR('V', BASE_VIDIOC_PRIVATE + 4, struct isph3a_aewb_config)
+#define VIDIOC_PRIVATE_ISP_AEWB_REQ \
+       _IOWR('V', BASE_VIDIOC_PRIVATE + 5, struct isph3a_aewb_data)
+#define VIDIOC_PRIVATE_ISP_HIST_CFG \
+       _IOWR('V', BASE_VIDIOC_PRIVATE + 6, struct isp_hist_config)
+#define VIDIOC_PRIVATE_ISP_HIST_REQ \
+       _IOWR('V', BASE_VIDIOC_PRIVATE + 7, struct isp_hist_data)
+#define VIDIOC_PRIVATE_ISP_AF_CFG \
+       _IOWR('V', BASE_VIDIOC_PRIVATE + 8, struct af_configuration)
+#define VIDIOC_PRIVATE_ISP_AF_REQ \
+       _IOWR('V', BASE_VIDIOC_PRIVATE + 9, struct isp_af_data)
+
+#define ISP_TOK_TERM           0xFFFFFFFF      /*
+                                                * terminating token for ISP
+                                                * modules reg list
+                                                */
+#define NUM_SG_DMA             (VIDEO_MAX_FRAME + 2)
+
+#define ISP_BUF_INIT           0
+#define ISP_FREE_RUNNING       1
+#define ISP_BUF_TRAN           2
+
+#ifndef CONFIG_ARCH_OMAP3410
+#define USE_ISP_PREVIEW
+#define USE_ISP_RESZ
+#define is_isppreview_enabled()                1
+#define is_ispresizer_enabled()                1
+#else
+#define is_isppreview_enabled()                0
+#define is_ispresizer_enabled()                0
+#endif
+
+#ifdef OMAP_ISPCTRL_DEBUG
+#define is_ispctrl_debug_enabled()             1
+#else
+#define is_ispctrl_debug_enabled()             0
+#endif
+
+#define ISP_XCLKA_DEFAULT              0x12
+#define ISP_OUTPUT_WIDTH_DEFAULT       176
+#define ISP_OUTPUT_HEIGHT_DEFAULT      144
+#define ISP_BYTES_PER_PIXEL            2
+#define NUM_ISP_CAPTURE_FORMATS        (sizeof(isp_formats) /\
+                                                       sizeof(isp_formats[0]))
+
+typedef int (*isp_vbq_callback_ptr) (struct videobuf_buffer *vb);
+typedef void (*isp_callback_t) (unsigned long status,
+                                       isp_vbq_callback_ptr arg1, void *arg2);
+
+enum isp_interface_type {
+       ISP_PARLL = 1,
+       ISP_CSIA = 2,
+       ISP_CSIB = 4
+};
+
+enum isp_irqevents {
+       CCDC_VD0 = 0x100,
+       CCDC_VD1 = 0x200,
+       CCDC_VD2 = 0x400,
+       CCDC_ERR = 0x800,
+       H3A_AWB_DONE = 0x2000,
+       H3A_AF_DONE = 0x1000,
+       HIST_DONE = 0x10000,
+       PREV_DONE = 0x100000,
+       LSC_DONE = 0x20000,
+       LSC_PRE_COMP = 0x40000,
+       LSC_PRE_ERR = 0x80000,
+       RESZ_DONE = 0x1000000,
+       SBL_OVF = 0x2000000,
+       MMU_ERR = 0x10000000,
+       OCP_ERR = 0x20000000,
+       HS_VS = 0x80000000
+};
+
+enum isp_callback_type {
+       CBK_CCDC_VD0,
+       CBK_CCDC_VD1,
+       CBK_PREV_DONE,
+       CBK_RESZ_DONE,
+       CBK_MMU_ERR,
+       CBK_H3A_AWB_DONE,
+       CBK_HIST_DONE,
+       CBK_HS_VS,
+       CBK_LSC_ISR,
+       CBK_H3A_AF_DONE,
+       CBK_CATCHALL,
+       CBK_END,
+};
+
+/**
+ * struct isp_reg - Structure for ISP register values.
+ * @reg: 32-bit Register address.
+ * @val: 32-bit Register value.
+ */
+struct isp_reg {
+       u32 reg;
+       u32 val;
+};
+
+/**
+ * struct isp_sgdma_state - SG-DMA state for each videobuffer + 2 overlays
+ * @isp_addr: ISP space address mapped by ISP MMU.
+ * @status: DMA return code mapped by ISP MMU.
+ * @callback: Pointer to ISP callback function.
+ * @arg: Pointer to argument passed to the specified callback function.
+ */
+struct isp_sgdma_state {
+       dma_addr_t isp_addr;
+       u32 status;
+       isp_callback_t callback;
+       void *arg;
+};
+
+/**
+ * struct isp_sgdma - ISP Scatter Gather DMA status.
+ * @isp_addr_capture: Array of ISP space addresses mapped by the ISP MMU.
+ * @lock: Spinlock used to check free_sgdma field.
+ * @free_sgdma: Number of free SG-DMA slots.
+ * @next_sgdma: Index of next SG-DMA slot to use.
+ */
+struct isp_sgdma {
+       dma_addr_t isp_addr_capture[VIDEO_MAX_FRAME];
+       spinlock_t lock;        /* For handling current buffer */
+       int free_sgdma;
+       int next_sgdma;
+       struct isp_sgdma_state sg_state[NUM_SG_DMA];
+};
+
+/**
+ * struct isp_interface_config - ISP interface configuration.
+ * @ccdc_par_ser: ISP interface type. 0 - Parallel, 1 - CSIA, 2 - CSIB to CCDC.
+ * @par_bridge: CCDC Bridge input control. Parallel interface.
+ *                  0 - Disable, 1 - Enable, first byte->cam_d(bits 7 to 0)
+ *                  2 - Enable, first byte -> cam_d(bits 15 to 8)
+ * @par_clk_pol: Pixel clock polarity on the parallel interface.
+ *                    0 - Non Inverted, 1 - Inverted
+ * @dataline_shift: Data lane shifter.
+ *                      0 - No Shift, 1 - CAMEXT[13 to 2]->CAM[11 to 0]
+ *                      2 - CAMEXT[13 to 4]->CAM[9 to 0]
+ *                      3 - CAMEXT[13 to 6]->CAM[7 to 0]
+ * @hsvs_syncdetect: HS or VS synchronization signal detection.
+ *                       0 - HS Falling, 1 - HS rising
+ *                       2 - VS falling, 3 - VS rising
+ * @vdint0_timing: VD0 Interrupt timing.
+ * @vdint1_timing: VD1 Interrupt timing.
+ * @strobe: Strobe related parameter.
+ * @prestrobe: PreStrobe related parameter.
+ * @shutter: Shutter related parameter.
+ */
+struct isp_interface_config {
+       enum isp_interface_type ccdc_par_ser;
+       u8 dataline_shift;
+       u32 hsvs_syncdetect;
+       u16 vdint0_timing;
+       u16 vdint1_timing;
+       int strobe;
+       int prestrobe;
+       int shutter;
+       union {
+               struct par {
+                       unsigned par_bridge:2;
+                       unsigned par_clk_pol:1;
+               } par;
+               struct csi {
+                       unsigned crc:1;
+                       unsigned mode:1;
+                       unsigned edge:1;
+                       unsigned signalling:1;
+                       unsigned strobe_clock_inv:1;
+                       unsigned vs_edge:1;
+                       unsigned channel:3;
+                       unsigned vpclk:2;       /* Video port output clock */
+                       unsigned int data_start;
+                       unsigned int data_size;
+                       u32 format;             /* V4L2_PIX_FMT_* */
+               } csi;
+       } u;
+};
+
+/**
+ * struct isp_sysc - ISP Power switches to set.
+ * @reset: Flag for setting ISP reset.
+ * @idle_mode: Flag for setting ISP idle mode.
+ */
+struct isp_sysc {
+       char reset;
+       char idle_mode;
+};
+
+void isp_open(void);
+
+void isp_close(void);
+
+void isp_start(void);
+
+void isp_stop(void);
+
+void isp_sgdma_init(void);
+
+void isp_vbq_done(unsigned long status, isp_vbq_callback_ptr arg1, void *arg2);
+
+void isp_sgdma_process(struct isp_sgdma *sgdma, int irq, int *dma_notify,
+                                               isp_vbq_callback_ptr func_ptr);
+
+int isp_sgdma_queue(struct videobuf_dmabuf *vdma, struct videobuf_buffer *vb,
+                                               int irq, int *dma_notify,
+                                               isp_vbq_callback_ptr func_ptr);
+
+int isp_vbq_prepare(struct videobuf_queue *vbq, struct videobuf_buffer *vb,
+                                                       enum v4l2_field field);
+
+void isp_vbq_release(struct videobuf_queue *vbq, struct videobuf_buffer *vb);
+
+int isp_set_callback(enum isp_callback_type type, isp_callback_t callback,
+                                       isp_vbq_callback_ptr arg1, void *arg2);
+
+void omapisp_unset_callback(void);
+
+int isp_unset_callback(enum isp_callback_type type);
+
+u32 isp_set_xclk(u32 xclk, u8 xclksel);
+
+u32 isp_get_xclk(u8 xclksel);
+
+int isp_request_interface(enum isp_interface_type if_t);
+
+int isp_free_interface(enum isp_interface_type if_t);
+
+void isp_power_settings(struct isp_sysc);
+
+int isp_configure_interface(struct isp_interface_config *config);
+
+void isp_CCDC_VD01_disable(void);
+
+void isp_CCDC_VD01_enable(void);
+
+int isp_get(void);
+
+int isp_put(void);
+
+void isp_set_pipeline(int soc_type);
+
+void isp_config_pipeline(struct v4l2_pix_format *pix_input,
+                                       struct v4l2_pix_format *pix_output);
+
+int isp_queryctrl(struct v4l2_queryctrl *a);
+
+int isp_g_ctrl(struct v4l2_control *a);
+
+int isp_s_ctrl(struct v4l2_control *a);
+
+int isp_enum_fmt_cap(struct v4l2_fmtdesc *f);
+
+int isp_try_fmt_cap(struct v4l2_pix_format *pix_input,
+                                       struct v4l2_pix_format *pix_output);
+
+void isp_g_fmt_cap(struct v4l2_pix_format *pix);
+
+int isp_s_fmt_cap(struct v4l2_pix_format *pix_input,
+                                       struct v4l2_pix_format *pix_output);
+
+int isp_g_crop(struct v4l2_crop *a);
+
+int isp_s_crop(struct v4l2_crop *a, struct v4l2_pix_format *pix);
+
+void isp_config_crop(struct v4l2_pix_format *pix);
+
+int isp_try_size(struct v4l2_pix_format *pix_input,
+                                       struct v4l2_pix_format *pix_output);
+
+int isp_try_fmt(struct v4l2_pix_format *pix_input,
+                                       struct v4l2_pix_format *pix_output);
+
+int isp_handle_private(int cmd, void *arg);
+
+void isp_save_context(struct isp_reg *);
+
+void isp_restore_context(struct isp_reg *);
+
+void isp_save_ctx(void);
+
+void isp_restore_ctx(void);
+
+void isp_print_status(void);
+
+
+int __init isp_ccdc_init(void);
+int __init isp_hist_init(void);
+int __init isph3a_aewb_init(void);
+int __init ispmmu_init(void);
+int __init isp_preview_init(void);
+int __init isp_resizer_init(void);
+int __init isp_af_init(void);
+
+void __exit isp_ccdc_cleanup(void);
+void __exit isp_hist_cleanup(void);
+void __exit isph3a_aewb_cleanup(void);
+void __exit ispmmu_cleanup(void);
+void __exit isp_preview_cleanup(void);
+void __exit isp_hist_cleanup(void);
+void __exit isp_resizer_cleanup(void);
+void __exit isp_af_exit(void);
+
+#endif /* OMAP_ISP_TOP_H */
Index: linux-omap-2.6/drivers/media/video/isp/isp_af.c
===================================================================
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ linux-omap-2.6/drivers/media/video/isp/isp_af.c     2008-08-28 19:08:43.000000000 -0500
@@ -0,0 +1,812 @@
+/*
+ * drivers/media/video/isp/isp_af.c
+ *
+ * AF module for TI's OMAP3430 Camera ISP
+ *
+ * Copyright (C) 2008 Texas Instruments.
+ *
+ * This package is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+/* Linux specific include files */
+#include <linux/cdev.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/fs.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <asm/cacheflush.h>
+#include <linux/uaccess.h>
+#include <linux/io.h>
+
+#include <linux/mman.h>
+#include <linux/syscalls.h>
+#include <linux/errno.h>
+#include <linux/types.h>
+#include <linux/dma-mapping.h>
+
+#include <media/v4l2-int-device.h>
+#include "isp.h"
+#include "ispreg.h"
+#include "isph3a.h"
+#include "isp_af.h"
+#include "ispmmu.h"
+
+/**
+ * struct isp_af_buffer - AF frame stats buffer.
+ * @virt_addr: Virtual address to mmap the buffer.
+ * @phy_addr: Physical address of the buffer.
+ * @addr_align: Virtual Address 32 bytes aligned.
+ * @ispmmu_addr: Address of the buffer mapped by the ISPMMU.
+ * @mmap_addr: Mapped memory area of buffer. For userspace access.
+ * @locked: 1 - Buffer locked from write. 0 - Buffer can be overwritten.
+ * @frame_num: Frame number from which the statistics are taken.
+ * @lens_position: Lens position currently set in the DW9710 Coil motor driver.
+ * @next: Pointer to link next buffer.
+ */
+struct isp_af_buffer {
+       unsigned long virt_addr;
+       unsigned long phy_addr;
+       unsigned long addr_align;
+       unsigned long ispmmu_addr;
+       unsigned long mmap_addr;
+
+       u8 locked;
+       u16 frame_num;
+       struct isp_af_xtrastats xtrastats;
+       struct isp_af_buffer *next;
+};
+
+/**
+ * struct isp_af_status - AF status.
+ * @initialized: 1 - Buffers initialized.
+ * @update: 1 - Update registers.
+ * @stats_req: 1 - Future stats requested.
+ * @stats_done: 1 - Stats ready for user.
+ * @frame_req: Number of frame requested for statistics.
+ * @af_buff: Array of statistics buffers to access.
+ * @stats_buf_size: Statistics buffer size.
+ * @min_buf_size: Minimum statisitics buffer size.
+ * @frame_count: Frame Count.
+ * @stats_wait: Wait primitive for locking/unlocking the stats request.
+ * @buffer_lock: Spinlock for statistics buffers access.
+ */
+static struct isp_af_status {
+       u8 initialized;
+       u8 update;
+       u8 stats_req;
+       u8 stats_done;
+       u16 frame_req;
+
+       struct isp_af_buffer af_buff[H3A_MAX_BUFF];
+       unsigned int stats_buf_size;
+       unsigned int min_buf_size;
+
+       u32 frame_count;
+       wait_queue_head_t stats_wait;
+       spinlock_t buffer_lock;         /* For stats buffers read/write sync */
+} afstat;
+
+struct af_device *af_dev_configptr;
+static struct isp_af_buffer *active_buff;
+static int af_major = -1;
+static int camnotify;
+
+
+/**
+ * isp_af_setxtrastats - Receives extra statistics from prior frames.
+ * @xtrastats: Pointer to structure containing extra statistics fields like
+ *             field count and timestamp of frame.
+ *
+ * Called from update_vbq in camera driver
+ **/
+void isp_af_setxtrastats(struct isp_af_xtrastats *xtrastats, u8 updateflag)
+{
+       int i, past_i;
+
+       if (active_buff == NULL)
+               return;
+
+       for (i = 0; i < H3A_MAX_BUFF; i++) {
+               if (afstat.af_buff[i].frame_num == active_buff->frame_num)
+                       break;
+       }
+
+       if (i == H3A_MAX_BUFF)
+               return;
+
+       if (i == 0) {
+               if (afstat.af_buff[H3A_MAX_BUFF - 1].locked == 0)
+                       past_i = H3A_MAX_BUFF - 1;
+               else
+                       past_i = H3A_MAX_BUFF - 2;
+       } else if (i == 1) {
+               if (afstat.af_buff[0].locked == 0)
+                       past_i = 0;
+               else
+                       past_i = H3A_MAX_BUFF - 1;
+       } else {
+               if (afstat.af_buff[i - 1].locked == 0)
+                       past_i = i - 1;
+               else
+                       past_i = i - 2;
+       }
+
+       if (updateflag & AF_UPDATEXS_TS)
+               afstat.af_buff[past_i].xtrastats.ts = xtrastats->ts;
+
+       if (updateflag & AF_UPDATEXS_FIELDCOUNT)
+               afstat.af_buff[past_i].xtrastats.field_count =
+                                                       xtrastats->field_count;
+}
+EXPORT_SYMBOL(isp_af_setxtrastats);
+
+/*
+ * Helper function to update buffer cache pages
+ */
+static void isp_af_update_req_buffer(struct isp_af_buffer *buffer)
+{
+       int size = afstat.stats_buf_size;
+
+       size = PAGE_ALIGN(size);
+       /* Update the kernel pages of the requested buffer */
+       dmac_inv_range((void *)buffer->addr_align, (void *)buffer->addr_align +
+                                                                       size);
+}
+
+/* Function to check paxel parameters */
+int isp_af_check_paxel(void)
+{
+       /* Check horizontal Count */
+       if ((af_dev_configptr->config->paxel_config.hz_cnt
+            < AF_PAXEL_HORIZONTAL_COUNT_MIN)
+           || (af_dev_configptr->config->paxel_config.hz_cnt
+               > AF_PAXEL_HORIZONTAL_COUNT_MAX)) {
+               DPRINTK_ISPH3A("Error : Horizontal Count is incorrect");
+               return -AF_ERR_HZ_COUNT;
+       }
+
+       /*Check Vertical Count */
+       if ((af_dev_configptr->config->paxel_config.vt_cnt
+            < AF_PAXEL_VERTICAL_COUNT_MIN)
+           || (af_dev_configptr->config->paxel_config.vt_cnt
+               > AF_PAXEL_VERTICAL_COUNT_MAX)) {
+               DPRINTK_ISPH3A("Error : Vertical Count is incorrect");
+               return -AF_ERR_VT_COUNT;
+       }
+
+       /*Check Height */
+       if ((af_dev_configptr->config->paxel_config.height
+            < AF_PAXEL_HEIGHT_MIN)
+           || (af_dev_configptr->config->paxel_config.height
+               > AF_PAXEL_HEIGHT_MAX)) {
+               DPRINTK_ISPH3A("