siv121dyuv_Sensor.c (custom\common\kernel\imgsensor\siv121d_yuv)

#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include

#include "kd_camera_hw.h"
#include "kd_imgsensor.h"
#include "kd_imgsensor_define.h"
#include "kd_imgsensor_errcode.h"
#include "kd_camera_feature.h"

#include "siv121dyuv_Sensor.h"
#include "siv121dyuv_Camera_Sensor_para.h"
#include "siv121dyuv_CameraCustomized.h"

#define SIV121DYUV_DEBUG

#ifdef SIV121DYUV_DEBUG
#define SENSORDB printk
#else
#define SENSORDB(x,...)
#endif

typedef struct
{
kal_uint8 iSensorVersion;
kal_boolbNightMode;
kal_uint16iWB;
kal_uint16iAE;
kal_uint16 iEffect;
kal_uint16 iEV;
kal_uint16 iBanding;
kal_boolbFixFrameRate;
kal_uint8 iMirror;
kal_uint16iDummyPixel;/* dummy pixel for user customization */
kal_boolbVideoMode;
kal_uint8iPclk;
kal_uint16MinFpsNormal;
kal_uint16MinFpsNight;
/* Sensor regester backup*/
kal_uint8iCurrentPage;
kal_uint8iControl;
kal_uint16iHblank; /* dummy pixel for calculating shutter step*/
kal_uint16iVblank; /* dummy line calculated by cal_fps*/
kal_uint8iShutterStep;
kal_uint8iFrameCount;
} SIV121DStatus;

#define Sleep(ms) mdelay(ms)

/* Global Valuable */
SIV121DStatus SIV121DCurrentStatus;
MSDK_SENSOR_CONFIG_STRUCT SIV121DSensorConfigData;

extern int iReadRegI2C(u8 *a_pSendData , u16 a_sizeSendData, u8 * a_pRecvData, u16 a_sizeRecvData, u16 i2cId);
extern int iWriteRegI2C(u8 *a_pSendData , u16 a_sizeSendData, u16 i2cId);

kal_uint16 SIV121DWriteCmosSensor(kal_uint32 addr, kal_uint32 para)
{
char puSendCmd[2] = {(char)(addr & 0xFF) ,(char)(para & 0xFF)};

iWriteRegI2C(puSendCmd , 2,SIV121D_WRITE_ID);
}

kal_uint16 SIV121DReadCmosSensor(kal_uint32 addr)
{
char puGetByte=0;
char puSendCmd = (char)(addr & 0xFF);
iReadRegI2C(&puSendCmd , 1, &puGetByte,1,SIV121D_WRITE_ID);
return puGetByte;
}

static void SIV121DSetPage(kal_uint8 iPage)
{

if(SIV121DCurrentStatus.iCurrentPage == iPage)
return ;

SIV121DCurrentStatus.iCurrentPage = iPage;
SIV121DWriteCmosSensor(0x00,iPage);
}

static void SIV121DInitialPara(void)
{
SIV121DCurrentStatus.bNightMode = KAL_FALSE;
SIV121DCurrentStatus.iWB = AWB_MODE_AUTO;
SIV121DCurrentStatus.iAE = AE_MODE_AUTO;
SIV121DCurrentStatus.iEffect = MEFFECT_OFF;
SIV121DCurrentStatus.iBanding = SIV121D_NUM_50HZ;
SIV121DCurrentStatus.iEV = AE_EV_COMP_00;
SIV121DCurrentStatus.bFixFrameRate = KAL_FALSE;
SIV121DCurrentStatus.iMirror = IMAGE_NORMAL;
SIV121DCurrentStatus.iDummyPixel = 0x1D;
SIV121DCurrentStatus.bVideoMode = KAL_FALSE;
SIV121DCurrentStatus.iPclk = 26;

SIV121DCurrentStatus.iCurrentPage = 0;
SIV121DCurrentStatus.iControl = 0x00;
SIV121DCurrentStatus.iHblank = 0x00;
SIV121DCurrentStatus.iVblank = 0x00;
SIV121DCurrentStatus.iShutterStep = 0x00;
SIV121DCurrentStatus.iFrameCount = 0x0A;

SIV121DCurrentStatus.MinFpsNormal = SIV121D_FPS(10);
SIV121DCurrentStatus.MinFpsNight = SIV121DCurrentStatus.MinFpsNormal >> 1;
}

static void SIV121DInitialSetting(void)
{
SIV121DWriteCmosSensor(0x00, 0x00);
SIV121DWriteCmosSensor(0x03, 0x04);
SIV121DWriteCmosSensor(0x10, 0x85);
SIV121DWriteCmosSensor(0x11, 0x11);

SIV121DWriteCmosSensor(0x00, 0x01);
SIV121DWriteCmosSensor(0x04, 0x04);
SIV121DWriteCmosSensor(0x06, 0x04);

SIV121DWriteCmosSensor(0x10, 0x46);
SIV121DWriteCmosSensor(0x11, 0x23);
SIV121DWriteCmosSensor(0x12, 0x21);

SIV121DWriteCmosSensor(0x17, 0x86); //ABS 1.74V
SIV121DWriteCmosSensor(0x18, 0x00);

SIV121DWriteCmosSensor(0x20, 0x00);
SIV121DWriteCmosSensor(0x21, 0x05);
SIV121DWriteCmosSensor(0x22, 0x01);
SIV121DWriteCmosSensor(0x23, 0x69);

SIV121DWriteCmosSensor(0x40, 0x0F);
SIV121DWriteCmosSensor(0x41, 0x90);//0x90
SIV121DWriteCmosSensor(0x42, 0xd2);//0xd2
SIV121DWriteCmosSensor(0x43, 0x00);

// AE
SIV121DWriteCmosSensor(0x00, 0x02);
SIV121DWriteCmosSensor(0x10, 0x80);
SIV121DWriteCmosSensor(0x11, 0x0c);
SIV121DWriteCmosSensor(0x12, 0x60); // D65 target
SIV121DWriteCmosSensor(0x14, 0x5c); // A target
SIV121DWriteCmosSensor(0x16, 0x00);
SIV121DWriteCmosSensor(0x19, 0xca);
SIV121DWriteCmosSensor(0x1a, 0x02);
SIV121DWriteCmosSensor(0x34, 0x96);
SIV121DWriteCmosSensor(0x40, 0x48); // Max x6
SIV121DWriteCmosSensor(0x5f, 0x01);
SIV121DWriteCmosSensor(0x90, 0x80);
SIV121DWriteCmosSensor(0x91, 0x80);

// AWB
SIV121DWriteCmosSensor(0x00, 0x03);
SIV121DWriteCmosSensor(0x10, 0xd0);
SIV121DWriteCmosSensor(0x11, 0xc1);
SIV121DWriteCmosSensor(0x13, 0x7e); //Cr target
SIV121DWriteCmosSensor(0x14, 0x7d); //Cb target
SIV121DWriteCmosSensor(0x15, 0xe0); // R gain Top
SIV121DWriteCmosSensor(0x16, 0x8c); // R gain bottom
SIV121DWriteCmosSensor(0x17, 0xe0); // B gain Top
SIV121DWriteCmosSensor(0x18, 0x88); // B gain bottom 0x80
SIV121DWriteCmosSensor(0x19, 0x8c); // Cr top value 0x90
SIV121DWriteCmosSensor(0x1a, 0x64); // Cr bottom value 0x70
SIV121DWriteCmosSensor(0x1b, 0x98); // Cb top value 0x90
SIV121DWriteCmosSensor(0x1c, 0x6c); // Cb bottom value 0x70
SIV121DWriteCmosSensor(0x1d, 0x94); // 0xa0
SIV121DWriteCmosSensor(0x1e, 0x6c); // 0x60
SIV121DWriteCmosSensor(0x20, 0xe8); // AWB luminous top value
SIV121DWriteCmosSensor(0x21, 0x30); // AWB luminous bottom value 0x20
SIV121DWriteCmosSensor(0x22, 0xb8);
SIV121DWriteCmosSensor(0x23, 0x10);
SIV121DWriteCmosSensor(0x25, 0x08);
SIV121DWriteCmosSensor(0x26, 0x20);
SIV121DWriteCmosSensor(0x27, 0x08); // BRTSRT
SIV121DWriteCmosSensor(0x28, 0x0f); // BRTEND
SIV121DWriteCmosSensor(0x29, 0xba); // BRTRGNBOT
SIV121DWriteCmosSensor(0x2a, 0xa0); // BRTBGNTOP

SIV121DWriteCmosSensor(0x40, 0x01);
SIV121DWriteCmosSensor(0x41, 0x03);
SIV121DWriteCmosSensor(0x42, 0x08);
SIV121DWriteCmosSensor(0x43, 0x10);
SIV121DWriteCmosSensor(0x44, 0x13);
SIV121DWriteCmosSensor(0x45, 0x8f);
SIV121DWriteCmosSensor(0x46, 0xfc);

SIV121DWriteCmosSensor(0x62, 0x84); // R D30 to D20
SIV121DWriteCmosSensor(0x63, 0x90); // R D30 to D20
SIV121DWriteCmosSensor(0x64, 0xd0); // B D30 to D20
SIV121DWriteCmosSensor(0x65, 0x98); // R D20 to D30
SIV121DWriteCmosSensor(0x66, 0xd0); // B D20 to D30

// IDP
SIV121DWriteCmosSensor(0x00, 0x04);
SIV121DWriteCmosSensor(0x10, 0xff);
SIV121DWriteCmosSensor(0x11, 0x1d);
SIV121DWriteCmosSensor(0x12, 0x2d);//fd
SIV121DWriteCmosSensor(0x14, 0x00);//fd
// DPCBNR
SIV121DWriteCmosSensor(0x18, 0xfe);// DPCNRCTRL
SIV121DWriteCmosSensor(0x19, 0x04);// DPCTHV
SIV121DWriteCmosSensor(0x1A, 0x01);// DPCTHVSLP
SIV121DWriteCmosSensor(0x1B, 0x08);// DPCTHVDIFSRT
SIV121DWriteCmosSensor(0x1C, 0x08);// DPCTHVDIFSLP
SIV121DWriteCmosSensor(0x1d, 0xFF);// DPCTHVMAX

SIV121DWriteCmosSensor(0x1E, 0x04);// BNRTHV 0c
SIV121DWriteCmosSensor(0x1F, 0x04);// BNRTHVSLPN 10
SIV121DWriteCmosSensor(0x20, 0x10);// BNRTHVSLPD
SIV121DWriteCmosSensor(0x21, 0x00);// BNRNEICNT
SIV121DWriteCmosSensor(0x22, 0x10);// STRTNOR
SIV121DWriteCmosSensor(0x23, 0x40);// STRTDRK

// Gamma
SIV121DWriteCmosSensor(0x31, 0x08); //0x08
SIV121DWriteCmosSensor(0x32, 0x12); //0x10
SIV121DWriteCmosSensor(0x33, 0x24); //0x1B
SIV121DWriteCmosSensor(0x34, 0x47); //0x37
SIV121DWriteCmosSensor(0x35, 0x64); //0x4D
SIV121DWriteCmosSensor(0x36, 0x7c); //0x60
SIV121DWriteCmosSensor(0x37, 0x8f); //0x72
SIV121DWriteCmosSensor(0x38, 0x9f); //0x82
SIV121DWriteCmosSensor(0x39, 0xAd); //0x91
SIV121DWriteCmosSensor(0x3a, 0xba); //0xA0
SIV121DWriteCmosSensor(0x3b, 0xcf); //0xBA
SIV121DWriteCmosSensor(0x3c, 0xe2); //0xD3
SIV121DWriteCmosSensor(0x3d, 0xf0); //0xEA

// Shading Register Setting
SIV121DWriteCmosSensor(0x40, 0x06);
SIV121DWriteCmosSensor(0x41, 0x44);
SIV121DWriteCmosSensor(0x42, 0x43);
SIV121DWriteCmosSensor(0x43, 0x20);
SIV121DWriteCmosSensor(0x44, 0x22); // left R gain[7:4], right R gain[3:0]
SIV121DWriteCmosSensor(0x45, 0x22); // top R gain[7:4], bottom R gain[3:0]
SIV121DWriteCmosSensor(0x46, 0x00); // left G gain[7:4], right G gain[3:0]
SIV121DWriteCmosSensor(0x47, 0x11); // top G gain[7:4], bottom G gain[3:0]
SIV121DWriteCmosSensor(0x48, 0x00); // left B gain[7:4], right B gain[3:0]
SIV121DWriteCmosSensor(0x49, 0x00); // top B gain[7:4], bottom B gain[3:0]
SIV121DWriteCmosSensor(0x4a, 0x04); // X-axis center high[3:2], Y-axis center high[1:0]
SIV121DWriteCmosSensor(0x4b, 0x48); // X-axis center low[7:0]
SIV121DWriteCmosSensor(0x4c, 0xe8); // Y-axis center low[7:0]
SIV121DWriteCmosSensor(0x4d, 0x80); // Shading Center Gain
SIV121DWriteCmosSensor(0x4e, 0x00); // Shading R Offset
SIV121DWriteCmosSensor(0x4f, 0x00); // Shading Gr Offset
SIV121DWriteCmosSensor(0x50, 0x00); // Shading B Offset

// Interpolation
SIV121DWriteCmosSensor(0x60, 0x7f);
SIV121DWriteCmosSensor(0x61, 0x08);// INTCTRL outdoor

// Color matrix (D65) - Daylight
SIV121DWriteCmosSensor(0x71, 0x34);
SIV121DWriteCmosSensor(0x72, 0xCe);
SIV121DWriteCmosSensor(0x73, 0xFe);
SIV121DWriteCmosSensor(0x74, 0x13);
SIV121DWriteCmosSensor(0x75, 0x25);
SIV121DWriteCmosSensor(0x76, 0x08);
SIV121DWriteCmosSensor(0x77, 0xec);
SIV121DWriteCmosSensor(0x78, 0xCd);
SIV121DWriteCmosSensor(0x79, 0x47);

// Color matrix (D20) - A
SIV121DWriteCmosSensor(0x83, 0x38); //0x3c
SIV121DWriteCmosSensor(0x84, 0xd1); //0xc6
SIV121DWriteCmosSensor(0x85, 0xf7); //0xff
SIV121DWriteCmosSensor(0x86, 0x12); //0x12
SIV121DWriteCmosSensor(0x87, 0x25); //0x24
SIV121DWriteCmosSensor(0x88, 0x09); //0x0a
SIV121DWriteCmosSensor(0x89, 0xed); //0xed
SIV121DWriteCmosSensor(0x8a, 0xbb); //0xc2
SIV121DWriteCmosSensor(0x8b, 0x58); //0x51

SIV121DWriteCmosSensor(0x8c, 0x10); //CMA select

//G Edge
SIV121DWriteCmosSensor(0x90, 0x18); //Upper gain
SIV121DWriteCmosSensor(0x91, 0x28); //down gain
SIV121DWriteCmosSensor(0x92, 0x55); //[7:4] upper coring [3:0] down coring
SIV121DWriteCmosSensor(0x9c, 0x30); //edge suppress start
SIV121DWriteCmosSensor(0x9d, 0x30); //edge suppress slope

SIV121DWriteCmosSensor(0xa9, 0x11);
SIV121DWriteCmosSensor(0xaa, 0x11);

SIV121DWriteCmosSensor(0xb9, 0x30); // nightmode 38 at gain 0x48 5fps
SIV121DWriteCmosSensor(0xba, 0x44); // nightmode 80 at gain 0x48 5fps

SIV121DWriteCmosSensor(0xc0, 0x24);
SIV121DWriteCmosSensor(0xc1, 0x00);
SIV121DWriteCmosSensor(0xc2, 0x80);
SIV121DWriteCmosSensor(0xc3, 0x00);
SIV121DWriteCmosSensor(0xc4, 0xe0);

SIV121DWriteCmosSensor(0xde, 0x80);

SIV121DWriteCmosSensor(0xe5, 0x15); //MEMSPDA
SIV121DWriteCmosSensor(0xe6, 0x02); //MEMSPDB
SIV121DWriteCmosSensor(0xe7, 0x04); //MEMSPDC

//Sensor On
SIV121DWriteCmosSensor(0x00, 0x01);
SIV121DWriteCmosSensor(0x03, 0x01); // SNR Enable
} /* SIV121DInitialSetting */ /* SIV121DInitialSetting */


/*************************************************************************
* FUNCTION
* SIV121DHalfAdjust
*
* DESCRIPTION
* This function dividend / divisor and use round-up.
*
* PARAMETERS
* dividend
* divisor
*
* RETURNS
* [dividend / divisor]
*
* LOCAL AFFECTED
*
*************************************************************************/
__inline static kal_uint32 SIV121DHalfAdjust(kal_uint32 dividend, kal_uint32 divisor)
{
return (dividend * 2 + divisor) / (divisor * 2); /* that is [dividend / divisor + 0.5]*/
}

/*************************************************************************
* FUNCTION
* SIV121DSetShutterStep
*
* DESCRIPTION
* This function is to calculate & set shutter step register .
*
*************************************************************************/
static void SIV121DSetShutterStep(void)
{
const kal_uint8 banding = SIV121DCurrentStatus.iBanding == AE_FLICKER_MODE_50HZ ? SIV121D_NUM_50HZ : SIV121D_NUM_60HZ;
const kal_uint16 shutter_step = SIV121DHalfAdjust(SIV121DCurrentStatus.iPclk * SIV121D_CLK_1MHZ / 2, (SIV121DCurrentStatus.iHblank + SIV121D_PERIOD_PIXEL_NUMS) * banding);

if(SIV121DCurrentStatus.iShutterStep == shutter_step)
return ;

SIV121DCurrentStatus.iShutterStep = shutter_step;
ASSERT(shutter_step <= 0xFF);
/* Block 1:0x34 shutter step*/
SIV121DSetPage(2);
SIV121DWriteCmosSensor(0x34,shutter_step);

SENSORDB("Set Shutter Step:%x\n",shutter_step);
}/* SIV121DSetShutterStep */

/*************************************************************************
* FUNCTION
* SIV121DSetFrameCount
*
* DESCRIPTION
* This function is to set frame count register .
*
*************************************************************************/
static void SIV121DSetFrameCount(void)
{
kal_uint16 Frame_Count,min_fps = 100;
kal_uint8 banding = SIV121DCurrentStatus.iBanding == AE_FLICKER_MODE_50HZ ? SIV121D_NUM_50HZ : SIV121D_NUM_60HZ;

min_fps = SIV121DCurrentStatus.bNightMode ? SIV121DCurrentStatus.MinFpsNight : SIV121DCurrentStatus.MinFpsNormal;
Frame_Count = banding * SIV121D_FRAME_RATE_UNIT / min_fps;

if(SIV121DCurrentStatus.iFrameCount == Frame_Count)
return ;

SIV121DCurrentStatus.iFrameCount = Frame_Count;

SENSORDB("min_fps:%d,Frame_Count:%x\n",min_fps/SIV121D_FRAME_RATE_UNIT,Frame_Count);
/*Block 01: 0x11 Max shutter step,for Min frame rate */
SIV121DSetPage(2);
SIV121DWriteCmosSensor(0x11,Frame_Count&0xFF);
}/* SIV121DSetFrameCount */

/*************************************************************************
* FUNCTION
* SIV121DConfigBlank
*
* DESCRIPTION
* This function is to set Blank size for Preview mode .
*
* PARAMETERS
* iBlank: target HBlank size
* iHz: banding frequency
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
static void SIV121DConfigBlank(kal_uint16 hblank,kal_uint16 vblank)
{
SENSORDB("hblank:%x,vblank:%x\n",hblank,vblank);
/********************************************
* Register :0x20 - 0x22
* Block 00
* 0x20 [7:4]:HBANK[9:8]; 0x20 [3:0]:VBANK[9:8]
* 0x21 HBANK[7:0]
* 0x23 VBANK[7:0]
********************************************/
if((SIV121DCurrentStatus.iHblank == hblank) && (SIV121DCurrentStatus.iVblank == vblank) )
return ;

SIV121DCurrentStatus.iHblank = hblank;
SIV121DCurrentStatus.iVblank = vblank;
ASSERT(hblank <= SIV121D_BLANK_REGISTER_LIMITATION && vblank <= SIV121D_BLANK_REGISTER_LIMITATION);
SIV121DSetPage(1);
SIV121DWriteCmosSensor(0x20,((hblank>>4)&0xF0)|((vblank>>8)&0x0F));
SIV121DWriteCmosSensor(0x21,hblank & 0xFF);
SIV121DWriteCmosSensor(0x22,vblank & 0xFF);
SIV121DSetShutterStep();
} /* SIV121DConfigBlank */

/*************************************************************************
* FUNCTION
* SIV121DCalFps
*
* DESCRIPTION
* This function calculate & set frame rate and fix frame rate when video mode
* MUST BE INVOKED AFTER SIM120C_preview() !!!
*
* PARAMETERS
* None
*
* RETURNS
* None
*
* LOCAL AFFECTED
*
*************************************************************************/
static void SIV121DCalFps(void)
{
kal_uint16 Line_length,Dummy_Line,Dummy_Pixel;
kal_uint16 max_fps = 300;

Line_length = SIV121DCurrentStatus.iDummyPixel + SIV121D_PERIOD_PIXEL_NUMS;

if (SIV121DCurrentStatus.bVideoMode == KAL_TRUE)
{
max_fps = SIV121DCurrentStatus.bNightMode ? SIV121DCurrentStatus.MinFpsNight: SIV121DCurrentStatus.MinFpsNormal;
}
else
{
max_fps = SIV121D_FPS(30);
}

Dummy_Line = SIV121DCurrentStatus.iPclk * SIV121D_CLK_1MHZ * SIV121D_FRAME_RATE_UNIT / (2 * Line_length * max_fps) - SIV121D_PERIOD_LINE_NUMS;
if(Dummy_Line > SIV121D_BLANK_REGISTER_LIMITATION)
{
Dummy_Line = SIV121D_BLANK_REGISTER_LIMITATION;
Line_length = SIV121DCurrentStatus.iPclk * SIV121D_CLK_1MHZ * SIV121D_FRAME_RATE_UNIT / (2 * (Dummy_Line + SIV121D_PERIOD_LINE_NUMS) * max_fps);
}
Dummy_Pixel = Line_length - SIV121D_PERIOD_PIXEL_NUMS;

SENSORDB("max_fps:%d\n",max_fps/SIV121D_FRAME_RATE_UNIT);
SENSORDB("Dummy Pixel:%x,Hblank:%x,Vblank:%x\n",SIV121DCurrentStatus.iDummyPixel,Dummy_Pixel,Dummy_Line);
SIV121DConfigBlank((Dummy_Pixel > 0) ? Dummy_Pixel : 0, (Dummy_Line > 0) ? Dummy_Line : 0);
SIV121DSetShutterStep();
}


/*************************************************************************
* FUNCTION
* SIV121DFixFrameRate
*
* DESCRIPTION
* This function fix the frame rate of image sensor.
*
*************************************************************************/
static void SIV121DFixFrameRate(kal_bool bEnable)
{
if(SIV121DCurrentStatus.bFixFrameRate == bEnable)
return ;

SIV121DCurrentStatus.bFixFrameRate = bEnable;
if(bEnable == KAL_TRUE)
{ //fix frame rate
SIV121DCurrentStatus.iControl |= 0xC0;
}
else
{
SIV121DCurrentStatus.iControl &= 0x3F;
}
SIV121DSetPage(1);
SIV121DWriteCmosSensor(0x04,SIV121DCurrentStatus.iControl);
} /* SIV121DFixFrameRate */

/*************************************************************************
* FUNCTION
* SIV121DHVmirror
*
* DESCRIPTION
* This function config the HVmirror of image sensor.
*
*************************************************************************/
static void SIV121DHVmirror(kal_uint8 HVmirrorType)
{
if(SIV121DCurrentStatus.iMirror == HVmirrorType)
return ;

SIV121DCurrentStatus.iMirror = HVmirrorType;
SIV121DCurrentStatus.iControl = SIV121DCurrentStatus.iControl & 0xFC;
switch (HVmirrorType)
{
case IMAGE_H_MIRROR:
SIV121DCurrentStatus.iControl |= 0x01;
break;

case IMAGE_V_MIRROR:
SIV121DCurrentStatus.iControl |= 0x02;
break;

case IMAGE_HV_MIRROR:
SIV121DCurrentStatus.iControl |= 0x03;
break;
case IMAGE_NORMAL:
default:
SIV121DCurrentStatus.iControl |= 0x00;
}
SIV121DSetPage(1);
SIV121DWriteCmosSensor(0x04,SIV121DCurrentStatus.iControl);
} /* SIV121DHVmirror */

/*************************************************************************
* FUNCTION
*SIV121DNightMode
*
* DESCRIPTION
*This function night mode of SIV121D.
*
* PARAMETERS
*none
*
* RETURNS
*None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void SIV121DNightMode(kal_bool enable)
{
SENSORDB("NightMode %d",enable);

SIV121DCurrentStatus.bNightMode = enable;

if ( SIV121DCurrentStatus.bVideoMode == KAL_FALSE)// camera mode
{
SIV121DSetPage(2);
SIV121DWriteCmosSensor(0x40,0x64);//Max Analog Gain Value @ Shutter step = Max Shutter step 0x7D
if (SIV121DCurrentStatus.bNightMode == KAL_TRUE)
{ /* camera night mode */
SENSORDB("camera night mode\n");
SIV121DSetPage(2);
SIV121DWriteCmosSensor(0x40,0x6C); //Max Analog Gain Value @ Shutter step = Max Shutter step 0x7D
SIV121DWriteCmosSensor(0x11,0x18); junfeng for EV Target Max Analog Gain Value @ Shutter step = Max Shutter step 0x7D
SIV121DSetPage(4);
SIV121DWriteCmosSensor(0xAB,0x18); //Brightness Control 0x11
//SIV121DWriteCmosSensor(0xB9,0x18); //Color Suppression Change Start State 0x18
//SIV121DWriteCmosSensor(0xBA,0x20); //Slope
}
else
{ /* camera normal mode */
SENSORDB("camera normal mode\n");
SIV121DSetPage(2);
SIV121DWriteCmosSensor(0x40,0x6C);// 0x7F
SIV121DWriteCmosSensor(0x11,0x14); //Max Analog Gain Value @ Shutter step = Max Shutter step 0x7D
SIV121DSetPage(4);
SIV121DWriteCmosSensor(0xAB,0x98); //0x04
//SIV121DWriteCmosSensor(0xB9,0x18);
//SIV121DWriteCmosSensor(0xBA,0x20); //Slope
}
SIV121DSetFrameCount();
}

}/* SIV121DNightMode */

/*************************************************************************
* FUNCTION
*SIV121DOpen
*
* DESCRIPTION
*This function initialize the registers of CMOS sensor
*
* PARAMETERS
*None
*
* RETURNS
*None
*
* GLOBALS AFFECTED
*
*************************************************************************/
UINT32 SIV121DOpen(void)
{
volatile signed char i;
kal_uint16 sensor_id=0;


// Read sensor ID to adjust I2C is OK?
SIV121DWriteCmosSensor(0x00,0x00);
sensor_id = SIV121DReadCmosSensor(0x01);
SENSORDB("IV120D Sensor Read ID %x\n",sensor_id);
if (sensor_id != SIV121D_SENSOR_ID)
{
return ERROR_SENSOR_CONNECT_FAIL;
}
SIV121DCurrentStatus.iSensorVersion = SIV121DReadCmosSensor(0x02);
SENSORDB("IV120D Sensor Version %x\n",SIV121DCurrentStatus.iSensorVersion);
//SIV121D_set_isp_driving_current(3);
SIV121DInitialPara();
//if (SIV121DCurrentStatus.iSensorVersion == SIV120B_SENSOR_VERSION)
//{
//SIV120BInitialSetting();
//}
//else
{
SIV121DInitialSetting();
}
SIV121DCalFps();

return ERROR_NONE;
}/* SIV121DOpen() */

/*************************************************************************
* FUNCTION
*SIV121DClose
*
* DESCRIPTION
*This function is to turn off sensor module power.
*
* PARAMETERS
*None
*
* RETURNS
*None
*
* GLOBALS AFFECTED
*
*************************************************************************/
UINT32 SIV121DClose(void)
{
//CISModulePowerOn(FALSE);
return ERROR_NONE;
}/* SIV121DClose() */

/*************************************************************************
* FUNCTION
*SIV121DPreview
*
* DESCRIPTION
*This function start the sensor preview.
*
* PARAMETERS
**image_window : address pointer of pixel numbers in one period of HSYNC
* *sensor_config_data : address pointer of line numbers in one period of VSYNC
*
* RETURNS
*None
*
* GLOBALS AFFECTED
*
*************************************************************************/
UINT32 SIV121DPreview(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
{

SENSORDB("SIV121DPreview\r\n");
/* ==Camera Preview, MT6516 use 26MHz PCLK, 30fps == */
SENSORDB("Camera preview\r\n");
//4 <1> preview of capture PICTURE
SIV121DFixFrameRate(KAL_FALSE);
SIV121DCurrentStatus.MinFpsNormal = SIV121D_FPS(10);
SIV121DCurrentStatus.MinFpsNight = SIV121DCurrentStatus.MinFpsNormal >> 1;
SIV121DCurrentStatus.bVideoMode = KAL_FALSE;

//4 <2> set mirror and flip
SIV121DHVmirror(sensor_config_data->SensorImageMirror);

//4 <3> set dummy pixel, dummy line will calculate from frame rate
/* SIV121DCurrentStatus.iDummyPixel = 0x1d; */

// copy sensor_config_data
memcpy(&SIV121DSensorConfigData, sensor_config_data, sizeof(MSDK_SENSOR_CONFIG_STRUCT));
return ERROR_NONE;
}/* SIV121DPreview() */

UINT32 SIV121DGetResolution(MSDK_SENSOR_RESOLUTION_INFO_STRUCT *pSensorResolution)
{
pSensorResolution->SensorFullWidth = SIV121D_IMAGE_SENSOR_PV_WIDTH+2; //add workaround for VGA sensor
pSensorResolution->SensorFullHeight = SIV121D_IMAGE_SENSOR_PV_HEIGHT;
pSensorResolution->SensorPreviewWidth = SIV121D_IMAGE_SENSOR_PV_WIDTH;
pSensorResolution->SensorPreviewHeight = SIV121D_IMAGE_SENSOR_PV_HEIGHT;

return ERROR_NONE;
}/* SIV121DGetResolution() */

UINT32 SIV121DGetInfo(MSDK_SCENARIO_ID_ENUM ScenarioId,
MSDK_SENSOR_INFO_STRUCT *pSensorInfo,
MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData)
{
pSensorInfo->SensorPreviewResolutionX = SIV121D_IMAGE_SENSOR_PV_WIDTH;
pSensorInfo->SensorPreviewResolutionY = SIV121D_IMAGE_SENSOR_PV_HEIGHT;
pSensorInfo->SensorFullResolutionX = SIV121D_IMAGE_SENSOR_PV_WIDTH;
pSensorInfo->SensorFullResolutionY = SIV121D_IMAGE_SENSOR_PV_HEIGHT;

pSensorInfo->SensorCameraPreviewFrameRate=30;
pSensorInfo->SensorVideoFrameRate=30;
pSensorInfo->SensorStillCaptureFrameRate=30;
pSensorInfo->SensorWebCamCaptureFrameRate=30;
pSensorInfo->SensorResetActiveHigh=FALSE;
pSensorInfo->SensorResetDelayCount=1;
pSensorInfo->SensorOutputDataFormat=SENSOR_OUTPUT_FORMAT_YVYU;
pSensorInfo->SensorClockPolarity=SENSOR_CLOCK_POLARITY_LOW;
pSensorInfo->SensorClockFallingPolarity=SENSOR_CLOCK_POLARITY_LOW;
pSensorInfo->SensorHsyncPolarity = SENSOR_CLOCK_POLARITY_LOW;
pSensorInfo->SensorVsyncPolarity = SENSOR_CLOCK_POLARITY_LOW;
pSensorInfo->SensorInterruptDelayLines = 1;
pSensorInfo->SensroInterfaceType=SENSOR_INTERFACE_TYPE_PARALLEL;
pSensorInfo->SensorMasterClockSwitch = 0;
pSensorInfo->SensorDrivingCurrent = ISP_DRIVING_4MA;

switch (ScenarioId)
{
case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
case MSDK_SCENARIO_ID_VIDEO_CAPTURE_MPEG4:
case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
case MSDK_SCENARIO_ID_CAMERA_CAPTURE_MEM:
default:
pSensorInfo->SensorClockFreq=26;
pSensorInfo->SensorClockDividCount=3;
pSensorInfo->SensorClockRisingCount= 0;
pSensorInfo->SensorClockFallingCount= 2;
pSensorInfo->SensorPixelClockCount= 3;
pSensorInfo->SensorDataLatchCount= 2;
pSensorInfo->SensorGrabStartX = 1;
pSensorInfo->SensorGrabStartY = 1;
break;
}
memcpy(pSensorConfigData, &SIV121DSensorConfigData, sizeof(MSDK_SENSOR_CONFIG_STRUCT));
return ERROR_NONE;
}/* SIV121DGetInfo() */

UINT32 SIV121DControl(MSDK_SCENARIO_ID_ENUM ScenarioId, MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *pImageWindow,
MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData)
{
switch (ScenarioId)
{
case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
case MSDK_SCENARIO_ID_VIDEO_CAPTURE_MPEG4:
case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
case MSDK_SCENARIO_ID_CAMERA_CAPTURE_MEM:
default:
SIV121DPreview(pImageWindow, pSensorConfigData);
break;
}
return TRUE;
}/* SIV121DControl() */

BOOL SIV121DSetParamWB(UINT16 para)
{
SENSORDB("WB %d\n",para);
if(SIV121DCurrentStatus.iWB== para)
return ;

SIV121DCurrentStatus.iWB = para;
SIV121DSetPage(3);
switch (para)
{
case AWB_MODE_OFF:
SIV121DWriteCmosSensor(0x10, 0x00);
break;

case AWB_MODE_AUTO:
SIV121DWriteCmosSensor(0x10, 0xD3);
break;

case AWB_MODE_CLOUDY_DAYLIGHT: //cloudy
SIV121DWriteCmosSensor(0x10, 0x00);
SIV121DWriteCmosSensor(0x60, 0xD0);
SIV121DWriteCmosSensor(0x61, 0x88);
break;

case AWB_MODE_DAYLIGHT: //sunny
SIV121DWriteCmosSensor(0x10, 0x00);
SIV121DWriteCmosSensor(0x60, 0xC2);
SIV121DWriteCmosSensor(0x61, 0x9E);
break;

case AWB_MODE_INCANDESCENT: //office
SIV121DWriteCmosSensor(0x10, 0x00);
SIV121DWriteCmosSensor(0x60, 0x98);
SIV121DWriteCmosSensor(0x61, 0xC8);
break;

case AWB_MODE_TUNGSTEN: //home
SIV121DWriteCmosSensor(0x10, 0x00);
SIV121DWriteCmosSensor(0x60, 0x90);
SIV121DWriteCmosSensor(0x61, 0xC0);
break;

case AWB_MODE_FLUORESCENT:
SIV121DWriteCmosSensor(0x10, 0x00);
SIV121DWriteCmosSensor(0x60, 0xAA);
SIV121DWriteCmosSensor(0x61, 0xBE);
break;

default:
return FALSE;
}

return TRUE;
} /* SIV121DSetParamWB */

BOOL SIV121DSetParamAE(UINT16 para)
{
SENSORDB("AE %d\n",para);
if(SIV121DCurrentStatus.iAE== para)
return ;

SIV121DCurrentStatus.iAE = para;
SIV121DSetPage(2);
if(KAL_TRUE == para)
SIV121DWriteCmosSensor(0x10,0x80);
else
SIV121DWriteCmosSensor(0x10,0x00);

return TRUE;
} /* SIV121DSetParamAE */

BOOL SIV121DSetParamEffect(UINT16 para)
{
SENSORDB("Effect %d\n",para);
if(SIV121DCurrentStatus.iEffect== para)
return ;

SIV121DCurrentStatus.iEffect = para;
SIV121DSetPage(4);
switch (para)
{
case MEFFECT_OFF:
SIV121DWriteCmosSensor(0xB6, 0x00);
break;

case MEFFECT_SEPIA:
SIV121DWriteCmosSensor(0xB6, 0x80);
SIV121DWriteCmosSensor(0xB7, 0x60);
SIV121DWriteCmosSensor(0xB8, 0xA0);
break;

case MEFFECT_NEGATIVE:
SIV121DWriteCmosSensor(0xB6, 0x20);
break;

case MEFFECT_SEPIAGREEN:
SIV121DWriteCmosSensor(0xB6, 0x80);
SIV121DWriteCmosSensor(0xB7, 0x50);
SIV121DWriteCmosSensor(0xB8, 0x50);
break;

case MEFFECT_SEPIABLUE:
SIV121DWriteCmosSensor(0xB6, 0x80);
SIV121DWriteCmosSensor(0xB7, 0xC0);
SIV121DWriteCmosSensor(0xB8, 0x60);
break;

case MEFFECT_MONO: //B&W
SIV121DWriteCmosSensor(0xB6, 0x40);
break;
default:
return FALSE;
}
return TRUE;

} /* SIV121DSetParamEffect */

BOOL SIV121DSetParamBanding(UINT16 para)
{

SENSORDB("Banding %d\n",para);
if(SIV121DCurrentStatus.iBanding== para)
return TRUE;

SIV121DCurrentStatus.iBanding = para;
SIV121DSetShutterStep();
SIV121DSetFrameCount();
return TRUE;
} /* SIV121DSetParamBanding */

BOOL SIV121DSetParamEV(UINT16 para)
{
SENSORDB("Exporsure %d\n",para);
if(SIV121DCurrentStatus.iEV== para)
return ;

SIV121DCurrentStatus.iEV = para;

SIV121DSetPage(4);
switch (para)
{
case AE_EV_COMP_n13:
SIV121DWriteCmosSensor(0xAB,0xE0);
break;

case AE_EV_COMP_n10:
SIV121DWriteCmosSensor(0xAB,0xD0);
break;

case AE_EV_COMP_n07:
SIV121DWriteCmosSensor(0xAB,0xC0);
break;

case AE_EV_COMP_n03:
SIV121DWriteCmosSensor(0xAB,0xB0);
break;

case AE_EV_COMP_00:
SIV121DWriteCmosSensor(0xAB,0x00);
break;

case AE_EV_COMP_03:
SIV121DWriteCmosSensor(0xAB,0x08);
break;

case AE_EV_COMP_07:
SIV121DWriteCmosSensor(0xAB,0x10);
break;

case AE_EV_COMP_10:
SIV121DWriteCmosSensor(0xAB,0x20);
break;

case AE_EV_COMP_13:
SIV121DWriteCmosSensor(0xAB,0x30);
break;

default:
return FALSE;
}
return TRUE;
} /* SIV121DSetParamEV */

UINT32 SIV121DYUVSensorSetting(FEATURE_ID iCmd, UINT32 iPara)
{
switch (iCmd) {
case FID_SCENE_MODE:
if (iPara == SCENE_MODE_OFF)
{
SIV121DNightMode(FALSE);
}
else if (iPara == SCENE_MODE_NIGHTSCENE)
{
SIV121DNightMode(TRUE);
}
break;

case FID_AWB_MODE:
SIV121DSetParamWB(iPara);
break;

case FID_COLOR_EFFECT:
SIV121DSetParamEffect(iPara);
break;

case FID_AE_EV:
SIV121DSetParamEV(iPara);
break;

case FID_AE_FLICKER:
SIV121DSetParamBanding(iPara);
break;

case FID_AE_SCENE_MODE:
SIV121DSetParamAE(iPara);
break;

default:
break;
}
return TRUE;
} /* SIV121DYUVSensorSetting */

UINT32 SIV121DYUVSetVideoMode(UINT16 u2FrameRate)
{
SENSORDB("SetVideoMode %d\n",u2FrameRate);

SIV121DFixFrameRate(KAL_TRUE);
SIV121DCurrentStatus.bVideoMode = KAL_TRUE;
SIV121DCurrentStatus.MinFpsNormal = SIV121D_FPS(30);
SIV121DCurrentStatus.MinFpsNight = SIV121DCurrentStatus.MinFpsNormal >> 1;
if (u2FrameRate == 30)
{
SIV121DCurrentStatus.bNightMode = KAL_FALSE;
}
else if (u2FrameRate == 15)
{
SIV121DCurrentStatus.bNightMode = KAL_TRUE;
}
else
{
printk("Wrong frame rate setting \n");
return FALSE;
}
SIV121DSetPage(2);
SIV121DWriteCmosSensor(0x40,0x58);//Max Analog Gain Value @ Shutter step = Max Shutter step0x7D
SIV121DCalFps();
SIV121DSetFrameCount();
return TRUE;
}

UINT32 SIV121DFeatureControl(MSDK_SENSOR_FEATURE_ENUM FeatureId,
UINT8 *pFeaturePara,UINT32 *pFeatureParaLen)
{
UINT16 *pFeatureReturnPara16=(UINT16 *) pFeaturePara;
UINT16 *pFeatureData16=(UINT16 *) pFeaturePara;
UINT32 *pFeatureReturnPara32=(UINT32 *) pFeaturePara;
UINT32 *pFeatureData32=(UINT32 *) pFeaturePara;
MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData=(MSDK_SENSOR_CONFIG_STRUCT *) pFeaturePara;
MSDK_SENSOR_REG_INFO_STRUCT *pSensorRegData=(MSDK_SENSOR_REG_INFO_STRUCT *) pFeaturePara;

switch (FeatureId)
{
case SENSOR_FEATURE_GET_RESOLUTION:
*pFeatureReturnPara16++=SIV121D_IMAGE_SENSOR_PV_WIDTH;
*pFeatureReturnPara16=SIV121D_IMAGE_SENSOR_PV_HEIGHT;
*pFeatureParaLen=4;
break;
case SENSOR_FEATURE_GET_PERIOD:
*pFeatureReturnPara16++=SIV121D_PERIOD_PIXEL_NUMS+SIV121DCurrentStatus.iHblank;
*pFeatureReturnPara16=SIV121D_PERIOD_LINE_NUMS+SIV121DCurrentStatus.iVblank;
*pFeatureParaLen=4;
break;
case SENSOR_FEATURE_GET_PIXEL_CLOCK_FREQ:
*pFeatureReturnPara32 = SIV121DCurrentStatus.iPclk;
*pFeatureParaLen=4;
break;
case SENSOR_FEATURE_SET_ESHUTTER:
break;
case SENSOR_FEATURE_SET_NIGHTMODE:
SIV121DNightMode((BOOL) *pFeatureData16);
break;
case SENSOR_FEATURE_SET_GAIN:
case SENSOR_FEATURE_SET_FLASHLIGHT:
break;
case SENSOR_FEATURE_SET_ISP_MASTER_CLOCK_FREQ:
break;
case SENSOR_FEATURE_SET_REGISTER:
SIV121DWriteCmosSensor(pSensorRegData->RegAddr, pSensorRegData->RegData);
break;
case SENSOR_FEATURE_GET_REGISTER:
pSensorRegData->RegData = SIV121DReadCmosSensor(pSensorRegData->RegAddr);
break;
case SENSOR_FEATURE_GET_CONFIG_PARA:
memcpy(pSensorConfigData, &SIV121DSensorConfigData, sizeof(MSDK_SENSOR_CONFIG_STRUCT));
*pFeatureParaLen=sizeof(MSDK_SENSOR_CONFIG_STRUCT);
break;
case SENSOR_FEATURE_SET_CCT_REGISTER:
case SENSOR_FEATURE_GET_CCT_REGISTER:
case SENSOR_FEATURE_SET_ENG_REGISTER:
case SENSOR_FEATURE_GET_ENG_REGISTER:
case SENSOR_FEATURE_GET_REGISTER_DEFAULT:

case SENSOR_FEATURE_CAMERA_PARA_TO_SENSOR:
case SENSOR_FEATURE_SENSOR_TO_CAMERA_PARA:
case SENSOR_FEATURE_GET_GROUP_COUNT:
case SENSOR_FEATURE_GET_GROUP_INFO:
case SENSOR_FEATURE_GET_ITEM_INFO:
case SENSOR_FEATURE_SET_ITEM_INFO:
case SENSOR_FEATURE_GET_ENG_INFO:
break;
case SENSOR_FEATURE_GET_LENS_DRIVER_ID:
// get the lens driver ID from EEPROM or just return LENS_DRIVER_ID_DO_NOT_CARE
// if EEPROM does not exist in camera module.
*pFeatureReturnPara32=LENS_DRIVER_ID_DO_NOT_CARE;
*pFeatureParaLen=4;
break;
case SENSOR_FEATURE_SET_YUV_CMD:
// printk("SIV121D YUV sensor Setting:%d, %d \n", *pFeatureData32, *(pFeatureData32+1));
SIV121DYUVSensorSetting((FEATURE_ID)*pFeatureData32, *(pFeatureData32+1));
break;
case SENSOR_FEATURE_SET_VIDEO_MODE:
SIV121DYUVSetVideoMode(*pFeatureData16);
break;
default:
break;
}
return ERROR_NONE;
}/* SIV121DFeatureControl() */

SENSOR_FUNCTION_STRUCTSensorFuncSIV121D=
{
SIV121DOpen,
SIV121DGetInfo,
SIV121DGetResolution,
SIV121DFeatureControl,
SIV121DControl,
SIV121DClose
};

UINT32 SIV121D_YUV_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc)
{
/* To Do : Check Sensor status here */
if (pfFunc!=NULL)
*pfFunc=&SensorFuncSIV121D;

return ERROR_NONE;
}/* SensorInit() */

你可能感兴趣的:(siv121dyuv_Sensor.c (custom\common\kernel\imgsensor\siv121d_yuv))