1 /*****************************************************************************
13 * Source code of Sensor driver
16 *------------------------------------------------------------------------------
17 * Upper this line, this part is controlled by CC/CQ. DO NOT MODIFY!!
18 *============================================================================
19 ****************************************************************************/
21 #include <linux/videodev2.h>
22 #include <linux/i2c.h>
23 #include <linux/platform_device.h>
24 #include <linux/delay.h>
25 #include <linux/cdev.h>
26 #include <linux/uaccess.h>
28 #include <asm/atomic.h>
29 #include <linux/xlog.h>
30 #include <asm/system.h>
32 #include "kd_camera_hw.h"
33 #include "kd_imgsensor.h"
34 #include "kd_imgsensor_define.h"
35 #include "kd_imgsensor_errcode.h"
37 #include "ov5670mipi_Sensor.h"
39 #include "ov5670mipiraw_Camera_Sensor_para.h"
40 #include "ov5670mipiraw_CameraCustomized.h"
41 static DEFINE_SPINLOCK(ov5670mipiraw_drv_lock
);
42 static int module_id
= 0;
46 #define OV5670DB(fmt, arg...) xlog_printk(ANDROID_LOG_DEBUG, "[OV5670Raw] ", fmt, ##arg)
48 #define OV5670DB(fmt, arg...)
52 kal_uint32 OV5670_FeatureControl_PERIOD_PixelNum
=OV5670_PV_PERIOD_PIXEL_NUMS
;
53 kal_uint32 OV5670_FeatureControl_PERIOD_LineNum
=OV5670_PV_PERIOD_LINE_NUMS
;
55 UINT16 OV5670_VIDEO_MODE_TARGET_FPS
= 30;
57 MSDK_SCENARIO_ID_ENUM OV5670CurrentScenarioId
= MSDK_SCENARIO_ID_CAMERA_PREVIEW
;
58 MSDK_SENSOR_CONFIG_STRUCT OV5670SensorConfigData
;
59 static OV5670_PARA_STRUCT OV5670
;
60 kal_uint32 OV5670_FAC_SENSOR_REG
;
63 SENSOR_REG_STRUCT OV5670SensorCCT
[]=CAMERA_SENSOR_CCT_DEFAULT_VALUE
;
64 SENSOR_REG_STRUCT OV5670SensorReg
[ENGINEER_END
]=CAMERA_SENSOR_REG_DEFAULT_VALUE
;
67 #define OV5670_TEST_PATTERN_CHECKSUM 0xca3667da //0x5d8082f0 //0x75bef806 //0xa2230d9f //0xf5e2f1ce
68 kal_bool OV5670_During_testpattern
= KAL_FALSE
;
70 extern int iReadReg(u16 a_u2Addr
, u8
* a_puBuff
, u16 i2cId
);
71 extern int iWriteReg(u16 a_u2Addr
, u32 a_u4Data
, u32 a_u4Bytes
, u16 i2cId
);
73 #define OV5670_write_cmos_sensor(addr, para) iWriteReg((u16) addr , (u32) para , 1, OV5670MIPI_WRITE_ID)
75 kal_uint16
OV5670_read_cmos_sensor(kal_uint32 addr
)
77 kal_uint16 get_byte
=0;
78 iReadReg((u16
) addr
,(u8
*)&get_byte
,OV5670MIPI_WRITE_ID
);
83 void OV5670_Init_Para(void)
86 spin_lock(&ov5670mipiraw_drv_lock
);
87 OV5670
.sensorMode
= SENSOR_MODE_INIT
;
88 OV5670
.OV5670AutoFlickerMode
= KAL_FALSE
;
89 OV5670
.OV5670VideoMode
= KAL_FALSE
;
91 OV5670
.DummyPixels
= 0;
92 OV5670
.pvPclk
= (10285);
93 OV5670
.videoPclk
= (10285);
94 OV5670
.capPclk
= (10285);
96 OV5670
.shutter
= 0x4C00;
97 OV5670
.ispBaseGain
= BASEGAIN
;
98 OV5670
.sensorGlobalGain
= 0x0200;
99 spin_unlock(&ov5670mipiraw_drv_lock
);
102 #define RG_Ratio_Typical 0x264
103 #define BG_Ratio_Typical 0x236
106 int flag
; // bit[7]: info, bit[6]:wb
107 int module_integrator_id
;
110 int production_month
;
122 static void otp_i2c_write( uint32_t addr
, kal_uint16 data
)
124 OV5670_write_cmos_sensor(addr
, data
);
127 static kal_uint16
otp_i2c_read(uint32_t addr
)
130 return OV5670_read_cmos_sensor(addr
);
135 // bit[7]: 0 no otp info, 1 valid otp info
136 // bit[6]: 0 no otp wb, 1 valib otp wb
137 static int read_otp(struct otp_struct
*otp_ptr
)
139 int otp_flag
, addr
, temp
, i
;
140 //set 0x5002[3] to “0”
143 temp1
= otp_i2c_read(0x5002);
144 otp_i2c_write(0x5002, (0x00 & 0x08) | (temp1
& (~0x08)));
146 // read OTP into buffer
147 otp_i2c_write(0x3d84, 0xC0);
148 otp_i2c_write(0x3d88, 0x70); // OTP start address
149 otp_i2c_write(0x3d89, 0x10);
150 otp_i2c_write(0x3d8A, 0x70); // OTP end address
151 otp_i2c_write(0x3d8B, 0x29);
152 otp_i2c_write(0x3d81, 0x01); // load otp into buffer
156 otp_flag
= otp_i2c_read(0x7010);
159 if((otp_flag
& 0xc0) == 0x40) {
160 addr
= 0x7011; // base address of info group 1
161 } else if((otp_flag
& 0x30) == 0x10) {
162 addr
= 0x7018; // base address of info group 2
163 }else if((otp_flag
& 0x0c) == 0x04) {
164 addr
= 0x701f; // base address of info group 3
168 (*otp_ptr
).flag
= 0x80; // valid base info in OTP
169 (*otp_ptr
).module_integrator_id
= otp_i2c_read( addr
);
170 (*otp_ptr
).lens_id
= otp_i2c_read( addr
+ 1);
171 (*otp_ptr
).production_year
= otp_i2c_read( addr
+ 4);
172 (*otp_ptr
).production_month
= otp_i2c_read( addr
+ 5);
173 (*otp_ptr
).production_day
= otp_i2c_read( addr
+ 6);
175 (*otp_ptr
).flag
= 0x00; // not info in OTP
176 (*otp_ptr
).module_integrator_id
= 0;
177 (*otp_ptr
).lens_id
= 0;
178 (*otp_ptr
).production_year
= 0;
179 (*otp_ptr
).production_month
= 0;
180 (*otp_ptr
).production_day
= 0;
183 module_id
= (*otp_ptr
).module_integrator_id
;
184 // OTP WB Calibration
185 otp_flag
= otp_i2c_read(0x7026);
188 if((otp_flag
& 0xc0) == 0x40) {
189 addr
= 0x7028; // base address of WB Calibration group 1
190 }else if((otp_flag
& 0x30) == 0x10) {
191 addr
= 0x7031; // base address of WB Calibration group 2
192 }else if((otp_flag
& 0x0c) == 0x04) {
193 addr
= 0x703a; // base address of WB Calibration group 3
197 (*otp_ptr
).flag
|= 0x40;
198 (*otp_ptr
).ob_data
= otp_i2c_read(addr
-1);
200 temp
= otp_i2c_read( addr
+ 3);
201 (*otp_ptr
).rg_ratio
= (otp_i2c_read(addr
)<<2) + ((temp
>>6) & 0x03);
202 (*otp_ptr
).bg_ratio
= (otp_i2c_read( addr
+ 1)<<2) + ((temp
>>4) & 0x03);
204 temp
= otp_i2c_read(addr
+ 7);
205 (*otp_ptr
).golden_RG
= (otp_i2c_read(addr
+ 4) << 2) + ((temp
>> 6) & 0x03);
206 (*otp_ptr
).golden_BG
= (otp_i2c_read(addr
+ 5) << 2) + ((temp
>> 4) & 0x03);
207 (*otp_ptr
).golden_G
= otp_i2c_read(addr
+ 6);
209 OV5670DB("ob_data=%d rg_ratio=%d bg_ratio=%d golden_RG=%d golden_BG=%d golden_G=%d\n",
210 (*otp_ptr
).ob_data
, (*otp_ptr
).rg_ratio
, (*otp_ptr
).bg_ratio
, (*otp_ptr
).golden_RG
, (*otp_ptr
).golden_BG
, (*otp_ptr
).golden_G
);
213 (*otp_ptr
).rg_ratio
= 0;
214 (*otp_ptr
).bg_ratio
= 0;
217 for(i
=0x7010;i
<=0x7041;i
++) {
218 otp_i2c_write(i
,0); // clear OTP buffer, recommended use continuous write to accelarate
221 //set 0x5002[3] to “1”
222 temp1
= otp_i2c_read(0x5002);
223 otp_i2c_write(0x5002, (0x02 & 0x08) | (temp1
& (~0x08)));
224 return (*otp_ptr
).flag
;
227 static int apply_otp(struct otp_struct
*otp_ptr
)
229 int rg
, bg
, R_gain
, G_gain
, B_gain
, Base_gain
;
231 // apply OTP WB Calibration
232 if ((*otp_ptr
).flag
& 0x40) {
233 rg
= (*otp_ptr
). rg_ratio
;
234 bg
= (*otp_ptr
).bg_ratio
;
236 R_gain
= (RG_Ratio_Typical
*1000) / rg
;
237 B_gain
= (BG_Ratio_Typical
*1000) / bg
;
239 OV5670DB("before calibration R_gain=%d B_gain=%d G_gain=%d rg=%d bg=%d\n", R_gain
, B_gain
, G_gain
, rg
, bg
);
240 if (R_gain
< 1000 || B_gain
< 1000)
252 R_gain
= 0x400 * R_gain
/ (Base_gain
);
253 B_gain
= 0x400 * B_gain
/ (Base_gain
);
254 G_gain
= 0x400 * G_gain
/ (Base_gain
);
255 OV5670DB("after calibration R_gain=%d B_gain=%d G_gain=%d \n", R_gain
, B_gain
, G_gain
);
257 // update sensor WB gain
259 otp_i2c_write(0x5032, R_gain
>>8);
260 otp_i2c_write(0x5033, R_gain
& 0x00ff);
263 otp_i2c_write(0x5034, G_gain
>>8);
264 otp_i2c_write(0x5035, G_gain
& 0x00ff);
267 otp_i2c_write(0x5036, B_gain
>>8);
268 otp_i2c_write(0x5037, B_gain
& 0x00ff);
271 return (*otp_ptr
).flag
;
274 void ov5670_otp_config()
276 struct otp_struct otp_info
;
279 apply_otp(&otp_info
) ;
281 kal_uint32
GetOV5670LineLength(void)
283 kal_uint32 OV5670_line_length
= 0;
284 if ( SENSOR_MODE_PREVIEW
== OV5670
.sensorMode
)
286 OV5670_line_length
= OV5670_PV_PERIOD_PIXEL_NUMS
+ OV5670
.DummyPixels
;
288 else if( SENSOR_MODE_VIDEO
== OV5670
.sensorMode
)
290 OV5670_line_length
= OV5670_VIDEO_PERIOD_PIXEL_NUMS
+ OV5670
.DummyPixels
;
294 OV5670_line_length
= OV5670_FULL_PERIOD_PIXEL_NUMS
+ OV5670
.DummyPixels
;
297 return OV5670_line_length
;
302 kal_uint32
GetOV5670FrameLength(void)
304 kal_uint32 OV5670_frame_length
= 0;
306 if ( SENSOR_MODE_PREVIEW
== OV5670
.sensorMode
)
308 OV5670_frame_length
= OV5670_PV_PERIOD_LINE_NUMS
+ OV5670
.DummyLines
;
310 else if( SENSOR_MODE_VIDEO
== OV5670
.sensorMode
)
312 OV5670_frame_length
= OV5670_VIDEO_PERIOD_LINE_NUMS
+ OV5670
.DummyLines
;
316 OV5670_frame_length
= OV5670_FULL_PERIOD_LINE_NUMS
+ OV5670
.DummyLines
;
319 return OV5670_frame_length
;
323 kal_uint32
OV5670_CalcExtra_For_ShutterMargin(kal_uint32 shutter_value
,kal_uint32 shutterLimitation
)
325 kal_uint32 extra_lines
= 0;
328 if (shutter_value
<4 ){
333 if (shutter_value
> shutterLimitation
)
335 extra_lines
= shutter_value
- shutterLimitation
;
345 kal_uint32
OV5670_CalcFrameLength_For_AutoFlicker(void)
348 kal_uint32 AutoFlicker_min_framelength
= 0;
350 switch(OV5670CurrentScenarioId
)
352 case MSDK_SCENARIO_ID_CAMERA_ZSD
:
353 case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG
:
354 AutoFlicker_min_framelength
= (OV5670
.capPclk
*10000) /(OV5670_FULL_PERIOD_PIXEL_NUMS
+ OV5670
.DummyPixels
)/OV5670_AUTOFLICKER_OFFSET_25
*10 ;
356 case MSDK_SCENARIO_ID_VIDEO_PREVIEW
:
357 if(OV5670_VIDEO_MODE_TARGET_FPS
==30)
359 AutoFlicker_min_framelength
= (OV5670
.videoPclk
*10000) /(OV5670_VIDEO_PERIOD_PIXEL_NUMS
+ OV5670
.DummyPixels
)/OV5670_AUTOFLICKER_OFFSET_30
*10 ;
361 else if(OV5670_VIDEO_MODE_TARGET_FPS
==15)
363 AutoFlicker_min_framelength
= (OV5670
.videoPclk
*10000) /(OV5670_VIDEO_PERIOD_PIXEL_NUMS
+ OV5670
.DummyPixels
)/OV5670_AUTOFLICKER_OFFSET_15
*10 ;
367 AutoFlicker_min_framelength
= OV5670_VIDEO_PERIOD_LINE_NUMS
+ OV5670
.DummyLines
;
371 case MSDK_SCENARIO_ID_CAMERA_PREVIEW
:
373 AutoFlicker_min_framelength
= (OV5670
.pvPclk
*10000) /(OV5670_PV_PERIOD_PIXEL_NUMS
+ OV5670
.DummyPixels
)/OV5670_AUTOFLICKER_OFFSET_30
*10 ;
377 OV5670DB("AutoFlicker_min_framelength =%d,OV5670CurrentScenarioId =%d\n", AutoFlicker_min_framelength
,OV5670CurrentScenarioId
);
379 return AutoFlicker_min_framelength
;
384 void OV5670_write_shutter(kal_uint32 shutter
)
386 kal_uint32 min_framelength
= OV5670_PV_PERIOD_PIXEL_NUMS
, max_shutter
=0;
387 kal_uint32 line_length
= 0;
388 kal_uint32 frame_length
= 0;
392 //shutter = 0x7fc; //issue
395 line_length
= GetOV5670LineLength();
396 frame_length
= GetOV5670FrameLength();
398 max_shutter
= frame_length
-OV5670_SHUTTER_MARGIN
;
400 frame_length
= frame_length
+ OV5670_CalcExtra_For_ShutterMargin(shutter
,max_shutter
);
404 if(OV5670
.OV5670AutoFlickerMode
== KAL_TRUE
)
406 min_framelength
= OV5670_CalcFrameLength_For_AutoFlicker();
408 if(frame_length
< min_framelength
)
409 frame_length
= min_framelength
;
413 spin_lock_irqsave(&ov5670mipiraw_drv_lock
,flags
);
414 OV5670_FeatureControl_PERIOD_PixelNum
= line_length
;
415 OV5670_FeatureControl_PERIOD_LineNum
= frame_length
;
416 spin_unlock_irqrestore(&ov5670mipiraw_drv_lock
,flags
);
418 //Set total frame length //VTS
419 OV5670_write_cmos_sensor(0x380e, (frame_length
>> 8) & 0xFF);
420 OV5670_write_cmos_sensor(0x380f, frame_length
& 0xFF);
423 OV5670_write_cmos_sensor(0x3500, (shutter
>>12) & 0x0F);
424 OV5670_write_cmos_sensor(0x3501, (shutter
>>4) & 0xFF);
425 OV5670_write_cmos_sensor(0x3502, (shutter
<<4) & 0xF0); /* Don't use the fraction part. */
427 OV5670DB("ov5670 write shutter=%x, line_length=%x, frame_length=%x\n", shutter
, line_length
, frame_length
);
432 static kal_uint16
OV5670Reg2Gain(const kal_uint16 iReg
)
436 iGain
= iReg
*BASEGAIN
/OV5670_GAIN_BASE
;
441 static kal_uint16
OV5670Gain2Reg(const kal_uint16 Gain
)
443 kal_uint32 iReg
= 0x0000;
444 kal_uint32 TempGain
= BASEGAIN
;
448 if(TempGain
< BASEGAIN
){
450 //OV5670DB("###ov5670 write gain underflow### Gain =%x\n", Gain);
452 if(TempGain
> 16*BASEGAIN
){
453 TempGain
= 16*BASEGAIN
;
454 //OV5670DB("###ov5670 write gain overflow### Gain =%x\n", Gain);
457 iReg
= (TempGain
*OV5670_GAIN_BASE
)/BASEGAIN
;
459 //iReg = ((TempGain /BASEGAIN)<<7)+((TempGain % BASEGAIN)<<7/BASEGAIN);
460 iReg
= iReg
& 0xFFFF;
462 //OV5670DB("###ov5670 write Reg ### iReg =%x\n", iReg);
468 void write_OV5670_gain(kal_uint16 gain
)
471 kal_uint8 ChangeFlag
=0x01;
473 kal_uint16 read_gain
;
475 iGain
=(gain
/ OV5670_GAIN_BASE
);
492 OV5670_write_cmos_sensor(0x301d, 0xf0);
493 OV5670_write_cmos_sensor(0x3209, 0x00);
494 OV5670_write_cmos_sensor(0x320a, 0x01);
497 //group 0:delay 0x366a for one frame,then active with gain
498 OV5670_write_cmos_sensor(0x3208, 0x00);
499 OV5670_write_cmos_sensor(0x366a, ChangeFlag
);
500 OV5670_write_cmos_sensor(0x3208, 0x10);
502 //group 1:all other registers( gain)
503 OV5670_write_cmos_sensor(0x3208, 0x01);
504 OV5670_write_cmos_sensor(0x3508,(gain
>>8));
505 OV5670_write_cmos_sensor(0x3509,(gain
&0xff));
507 OV5670_write_cmos_sensor(0x3208, 0x11);
510 OV5670_write_cmos_sensor(0x320B, 0x15);
511 OV5670_write_cmos_sensor(0x3208, 0xA1);
513 //read_gain=(((OV5670_read_cmos_sensor(0x3508)&0x1F) << 8) | OV5670_read_cmos_sensor(0x3509));
514 //OV5670DB("[OV5670_SetGain]0x3508|0x3509=0x%x \n",read_gain);
515 //OV5670DB("[OV5670_SetGain]0x366a=%d \n",(OV5670_read_cmos_sensor(0x366a)));
521 void OV5670_SetGain(UINT16 iGain
)
524 spin_lock_irqsave(&ov5670mipiraw_drv_lock
,flags
);
526 OV5670DB("OV5670_SetGain iGain = %d :\n ",iGain
);
528 OV5670
.realGain
= iGain
;
529 OV5670
.sensorGlobalGain
= OV5670Gain2Reg(iGain
);
530 spin_unlock_irqrestore(&ov5670mipiraw_drv_lock
,flags
);
532 write_OV5670_gain(OV5670
.sensorGlobalGain
);
533 OV5670DB(" [OV5670_SetGain]OV5670.sensorGlobalGain=0x%x,OV5670.realGain =%d",OV5670
.sensorGlobalGain
,
537 //OV5670_write_cmos_sensor(0x4d12,0x01);
538 //OV5670DB("Temperature read_reg 0x4d13 =%x \n",OV5670_read_cmos_sensor(0x4d13));
541 kal_uint16
read_OV5670_gain(void)
543 kal_uint16 read_gain
=0;
545 read_gain
=(((OV5670_read_cmos_sensor(0x3508)&0x1F) << 8) | OV5670_read_cmos_sensor(0x3509));
547 spin_lock(&ov5670mipiraw_drv_lock
);
548 OV5670
.sensorGlobalGain
= read_gain
;
549 OV5670
.realGain
= OV5670Reg2Gain(OV5670
.sensorGlobalGain
);
550 spin_unlock(&ov5670mipiraw_drv_lock
);
552 OV5670DB("OV5670.sensorGlobalGain=0x%x,OV5670.realGain=%d\n",OV5670
.sensorGlobalGain
,OV5670
.realGain
);
554 return OV5670
.sensorGlobalGain
;
559 void OV5670_camera_para_to_sensor(void)
562 for(i
=0; 0xFFFFFFFF!=OV5670SensorReg
[i
].Addr
; i
++)
564 OV5670_write_cmos_sensor(OV5670SensorReg
[i
].Addr
, OV5670SensorReg
[i
].Para
);
566 for(i
=ENGINEER_START_ADDR
; 0xFFFFFFFF!=OV5670SensorReg
[i
].Addr
; i
++)
568 OV5670_write_cmos_sensor(OV5670SensorReg
[i
].Addr
, OV5670SensorReg
[i
].Para
);
570 for(i
=FACTORY_START_ADDR
; i
<FACTORY_END_ADDR
; i
++)
572 OV5670_write_cmos_sensor(OV5670SensorCCT
[i
].Addr
, OV5670SensorCCT
[i
].Para
);
576 void OV5670_sensor_to_camera_para(void)
578 kal_uint32 i
, temp_data
;
579 for(i
=0; 0xFFFFFFFF!=OV5670SensorReg
[i
].Addr
; i
++)
581 temp_data
= OV5670_read_cmos_sensor(OV5670SensorReg
[i
].Addr
);
582 spin_lock(&ov5670mipiraw_drv_lock
);
583 OV5670SensorReg
[i
].Para
=temp_data
;
584 spin_unlock(&ov5670mipiraw_drv_lock
);
586 for(i
=ENGINEER_START_ADDR
; 0xFFFFFFFF!=OV5670SensorReg
[i
].Addr
; i
++)
588 temp_data
= OV5670_read_cmos_sensor(OV5670SensorReg
[i
].Addr
);
589 spin_lock(&ov5670mipiraw_drv_lock
);
590 OV5670SensorReg
[i
].Para
= temp_data
;
591 spin_unlock(&ov5670mipiraw_drv_lock
);
595 kal_int32
OV5670_get_sensor_group_count(void)
597 return GROUP_TOTAL_NUMS
;
600 void OV5670_get_sensor_group_info(kal_uint16 group_idx
, kal_int8
* group_name_ptr
, kal_int32
* item_count_ptr
)
605 sprintf((char *)group_name_ptr
, "CCT");
609 sprintf((char *)group_name_ptr
, "CMMCLK Current");
612 case FRAME_RATE_LIMITATION
:
613 sprintf((char *)group_name_ptr
, "Frame Rate Limitation");
616 case REGISTER_EDITOR
:
617 sprintf((char *)group_name_ptr
, "Register Editor");
625 void OV5670_get_sensor_item_info(kal_uint16 group_idx
,kal_uint16 item_idx
, MSDK_SENSOR_ITEM_INFO_STRUCT
* info_ptr
)
627 kal_int16 temp_reg
=0;
628 kal_uint16 temp_gain
=0, temp_addr
=0, temp_para
=0;
636 sprintf((char *)info_ptr
->ItemNamePtr
,"Pregain-R");
637 temp_addr
= PRE_GAIN_R_INDEX
;
640 sprintf((char *)info_ptr
->ItemNamePtr
,"Pregain-Gr");
641 temp_addr
= PRE_GAIN_Gr_INDEX
;
644 sprintf((char *)info_ptr
->ItemNamePtr
,"Pregain-Gb");
645 temp_addr
= PRE_GAIN_Gb_INDEX
;
648 sprintf((char *)info_ptr
->ItemNamePtr
,"Pregain-B");
649 temp_addr
= PRE_GAIN_B_INDEX
;
652 sprintf((char *)info_ptr
->ItemNamePtr
,"SENSOR_BASEGAIN");
653 temp_addr
= SENSOR_BASEGAIN
;
659 temp_para
= OV5670SensorCCT
[temp_addr
].Para
;
660 //temp_gain= (temp_para/OV5670.sensorBaseGain) * 1000;
662 info_ptr
->ItemValue
=temp_gain
;
663 info_ptr
->IsTrueFalse
=KAL_FALSE
;
664 info_ptr
->IsReadOnly
=KAL_FALSE
;
665 info_ptr
->IsNeedRestart
=KAL_FALSE
;
666 info_ptr
->Min
= OV5670_MIN_ANALOG_GAIN
* 1000;
667 info_ptr
->Max
= OV5670_MAX_ANALOG_GAIN
* 1000;
673 sprintf((char *)info_ptr
->ItemNamePtr
,"Drv Cur[2,4,6,8]mA");
675 //temp_reg=MT9P017SensorReg[CMMCLK_CURRENT_INDEX].Para;
676 temp_reg
= ISP_DRIVING_2MA
;
677 if(temp_reg
==ISP_DRIVING_2MA
)
679 info_ptr
->ItemValue
=2;
681 else if(temp_reg
==ISP_DRIVING_4MA
)
683 info_ptr
->ItemValue
=4;
685 else if(temp_reg
==ISP_DRIVING_6MA
)
687 info_ptr
->ItemValue
=6;
689 else if(temp_reg
==ISP_DRIVING_8MA
)
691 info_ptr
->ItemValue
=8;
694 info_ptr
->IsTrueFalse
=KAL_FALSE
;
695 info_ptr
->IsReadOnly
=KAL_FALSE
;
696 info_ptr
->IsNeedRestart
=KAL_TRUE
;
704 case FRAME_RATE_LIMITATION
:
708 sprintf((char *)info_ptr
->ItemNamePtr
,"Max Exposure Lines");
709 info_ptr
->ItemValue
= 111;
710 info_ptr
->IsTrueFalse
=KAL_FALSE
;
711 info_ptr
->IsReadOnly
=KAL_TRUE
;
712 info_ptr
->IsNeedRestart
=KAL_FALSE
;
717 sprintf((char *)info_ptr
->ItemNamePtr
,"Min Frame Rate");
718 info_ptr
->ItemValue
=12;
719 info_ptr
->IsTrueFalse
=KAL_FALSE
;
720 info_ptr
->IsReadOnly
=KAL_TRUE
;
721 info_ptr
->IsNeedRestart
=KAL_FALSE
;
729 case REGISTER_EDITOR
:
733 sprintf((char *)info_ptr
->ItemNamePtr
,"REG Addr.");
734 info_ptr
->ItemValue
=0;
735 info_ptr
->IsTrueFalse
=KAL_FALSE
;
736 info_ptr
->IsReadOnly
=KAL_FALSE
;
737 info_ptr
->IsNeedRestart
=KAL_FALSE
;
739 info_ptr
->Max
=0xFFFF;
742 sprintf((char *)info_ptr
->ItemNamePtr
,"REG Value");
743 info_ptr
->ItemValue
=0;
744 info_ptr
->IsTrueFalse
=KAL_FALSE
;
745 info_ptr
->IsReadOnly
=KAL_FALSE
;
746 info_ptr
->IsNeedRestart
=KAL_FALSE
;
748 info_ptr
->Max
=0xFFFF;
761 kal_bool
OV5670_set_sensor_item_info(kal_uint16 group_idx
, kal_uint16 item_idx
, kal_int32 ItemValue
)
763 kal_uint16 temp_gain
=0,temp_addr
=0, temp_para
=0;
771 temp_addr
= PRE_GAIN_R_INDEX
;
774 temp_addr
= PRE_GAIN_Gr_INDEX
;
777 temp_addr
= PRE_GAIN_Gb_INDEX
;
780 temp_addr
= PRE_GAIN_B_INDEX
;
783 temp_addr
= SENSOR_BASEGAIN
;
789 temp_gain
=((ItemValue
*BASEGAIN
+500)/1000); //+500:get closed integer value
791 if(temp_gain
>=1*BASEGAIN
&& temp_gain
<=16*BASEGAIN
)
793 // temp_para=(temp_gain * OV5670.sensorBaseGain + BASEGAIN/2)/BASEGAIN;
798 spin_lock(&ov5670mipiraw_drv_lock
);
799 OV5670SensorCCT
[temp_addr
].Para
= temp_para
;
800 spin_unlock(&ov5670mipiraw_drv_lock
);
801 OV5670_write_cmos_sensor(OV5670SensorCCT
[temp_addr
].Addr
,temp_para
);
808 //no need to apply this item for driving current
814 case FRAME_RATE_LIMITATION
:
817 case REGISTER_EDITOR
:
821 spin_lock(&ov5670mipiraw_drv_lock
);
822 OV5670_FAC_SENSOR_REG
=ItemValue
;
823 spin_unlock(&ov5670mipiraw_drv_lock
);
826 OV5670_write_cmos_sensor(OV5670_FAC_SENSOR_REG
,ItemValue
);
840 static void OV5670_SetDummy( const kal_uint32 iPixels
, const kal_uint32 iLines
)
842 kal_uint32 line_length
= 0;
843 kal_uint32 frame_length
= 0;
845 if ( SENSOR_MODE_PREVIEW
== OV5670
.sensorMode
)
847 line_length
= OV5670_PV_PERIOD_PIXEL_NUMS
+ iPixels
;
848 frame_length
= OV5670_PV_PERIOD_LINE_NUMS
+ iLines
;
850 else if( SENSOR_MODE_VIDEO
== OV5670
.sensorMode
)
852 line_length
= OV5670_VIDEO_PERIOD_PIXEL_NUMS
+ iPixels
;
853 frame_length
= OV5670_VIDEO_PERIOD_LINE_NUMS
+ iLines
;
857 line_length
= OV5670_FULL_PERIOD_PIXEL_NUMS
+ iPixels
;
858 frame_length
= OV5670_FULL_PERIOD_LINE_NUMS
+ iLines
;
861 spin_lock(&ov5670mipiraw_drv_lock
);
862 OV5670_FeatureControl_PERIOD_PixelNum
= line_length
;
863 OV5670_FeatureControl_PERIOD_LineNum
= frame_length
;
864 spin_unlock(&ov5670mipiraw_drv_lock
);
866 //Set total frame length
867 OV5670_write_cmos_sensor(0x380e, (frame_length
>> 8) & 0xFF);
868 OV5670_write_cmos_sensor(0x380f, frame_length
& 0xFF);
869 //Set total line length
870 OV5670_write_cmos_sensor(0x380c, (line_length
>> 8) & 0xFF);
871 OV5670_write_cmos_sensor(0x380d, line_length
& 0xFF);
876 void OV5670PreviewSetting(void)
878 OV5670DB(" OV5670PreviewSetting_2lane enter\n");
882 //@@PV_Quarter_size_30fps_800Mbps/lane
885 //;;PCLK=HTS*VTS*fps=0x68c*0x7fd*30=1676*2045*30=102.85M
887 OV5670_write_cmos_sensor(0x0100, 0x00); //
889 OV5670_write_cmos_sensor(0x3501, 0x3d); //
890 OV5670_write_cmos_sensor(0x366e, 0x08); //
891 OV5670_write_cmos_sensor(0x370b, 0x1b); //
892 OV5670_write_cmos_sensor(0x3808, 0x05); //
893 OV5670_write_cmos_sensor(0x3809, 0x10); //
894 OV5670_write_cmos_sensor(0x380a, 0x03); //
895 OV5670_write_cmos_sensor(0x380b, 0xc0); //
896 OV5670_write_cmos_sensor(0x380c, 0x06); //
897 OV5670_write_cmos_sensor(0x380d, 0x8c); //
898 OV5670_write_cmos_sensor(0x380e, 0x07); //;03
899 OV5670_write_cmos_sensor(0x380f, 0xfd); //;e0
900 OV5670_write_cmos_sensor(0x3814, 0x03); //
901 OV5670_write_cmos_sensor(0x3820, 0x90); //
902 OV5670_write_cmos_sensor(0x3821, 0x47); //
903 OV5670_write_cmos_sensor(0x382a, 0x03); //
904 OV5670_write_cmos_sensor(0x4009, 0x05); //
905 OV5670_write_cmos_sensor(0x4502, 0x48); //
906 OV5670_write_cmos_sensor(0x4508, 0x55); //
907 OV5670_write_cmos_sensor(0x4509, 0x55); //
908 OV5670_write_cmos_sensor(0x4600, 0x00); //
909 OV5670_write_cmos_sensor(0x4601, 0x81); //
910 OV5670_write_cmos_sensor(0x4017, 0x10); //; threshold = 4LSB for Binning sum format.
911 OV5670_write_cmos_sensor(0x400a, 0x02); //;
912 OV5670_write_cmos_sensor(0x400b, 0x00); //;
914 OV5670_write_cmos_sensor(0x0100, 0x01); //
917 //@@PV_Quarter_size_30fps_800Mbps/lane_1296x972
920 //;;PCLK=HTS*VTS*fps=0x68c*0x7fd*30=1676*2045*30=102.85M
922 OV5670_write_cmos_sensor(0x0100, 0x00); //
924 OV5670_write_cmos_sensor(0x3501, 0x73); //
925 OV5670_write_cmos_sensor(0x3502, 0x00); //
926 OV5670_write_cmos_sensor(0x3508, 0x01); //
927 OV5670_write_cmos_sensor(0x3509, 0x80); //
928 OV5670_write_cmos_sensor(0x366e, 0x08); //
929 OV5670_write_cmos_sensor(0x370b, 0x1b); //
930 OV5670_write_cmos_sensor(0x3808, 0x05); //
931 OV5670_write_cmos_sensor(0x3809, 0x10); //
932 OV5670_write_cmos_sensor(0x380a, 0x03); //
933 OV5670_write_cmos_sensor(0x380b, 0xcc); //;c0
934 OV5670_write_cmos_sensor(0x380c, 0x06); //
935 OV5670_write_cmos_sensor(0x380d, 0x8c); //
936 OV5670_write_cmos_sensor(0x380e, 0x07); //;03
937 OV5670_write_cmos_sensor(0x380f, 0xfd); //;e0
938 OV5670_write_cmos_sensor(0x3814, 0x03); //
939 OV5670_write_cmos_sensor(0x3820, 0x90); //
940 OV5670_write_cmos_sensor(0x3821, 0x47); //
941 OV5670_write_cmos_sensor(0x382a, 0x03); //
942 OV5670_write_cmos_sensor(0x3845, 0x02); //
943 OV5670_write_cmos_sensor(0x4009, 0x05); //
944 OV5670_write_cmos_sensor(0x4502, 0x48); //
945 OV5670_write_cmos_sensor(0x4508, 0x55); //
946 OV5670_write_cmos_sensor(0x4509, 0x55); //
947 OV5670_write_cmos_sensor(0x4600, 0x00); //
948 OV5670_write_cmos_sensor(0x4601, 0x81); //
949 OV5670_write_cmos_sensor(0x4017, 0x10); //; threshold = 4LSB for Binning
950 OV5670_write_cmos_sensor(0x400a, 0x02); //;
951 OV5670_write_cmos_sensor(0x400b, 0x00); //;
953 OV5670_write_cmos_sensor(0x0100, 0x01); //
957 void OV5670VideoSetting(void)
959 OV5670DB(" OV5670videoSetting_2lane enter:video/preview sync\n");
961 OV5670PreviewSetting();
966 void OV5670CaptureSetting(void)
968 OV5670DB("OV5670CaptureSetting_2lane enter\n");
970 OV5670_write_cmos_sensor(0x0100, 0x00);
972 OV5670_write_cmos_sensor(0x3501, 0x5f); //long exposure
973 OV5670_write_cmos_sensor(0x3502, 0xd0); //long exposure
975 OV5670_write_cmos_sensor(0x3508, 0x03); //gain
976 OV5670_write_cmos_sensor(0x3509, 0x00); //gain
978 OV5670_write_cmos_sensor(0x366e, 0x10);
979 OV5670_write_cmos_sensor(0x370b, 0x1b);
980 OV5670_write_cmos_sensor(0x3808, 0x0a);
981 OV5670_write_cmos_sensor(0x3809, 0x20);
982 OV5670_write_cmos_sensor(0x380a, 0x07);
983 OV5670_write_cmos_sensor(0x380b, 0x98);
984 OV5670_write_cmos_sensor(0x380c, 0x07); //;06
985 OV5670_write_cmos_sensor(0x380d, 0xdc); //;8c
986 OV5670_write_cmos_sensor(0x380e, 0x07);
987 OV5670_write_cmos_sensor(0x380f, 0xfd);
988 OV5670_write_cmos_sensor(0x3814, 0x01);
989 OV5670_write_cmos_sensor(0x3820, 0x80);
990 OV5670_write_cmos_sensor(0x3821, 0x46);
991 OV5670_write_cmos_sensor(0x382a, 0x01);
993 OV5670_write_cmos_sensor(0x3845, 0x00); //v_offset for auto size mode
995 OV5670_write_cmos_sensor(0x4009, 0x0d);
996 OV5670_write_cmos_sensor(0x4502, 0x40);
997 OV5670_write_cmos_sensor(0x4508, 0xaa);
998 OV5670_write_cmos_sensor(0x4509, 0xaa);
999 OV5670_write_cmos_sensor(0x4600, 0x01);
1000 OV5670_write_cmos_sensor(0x4601, 0x03);
1001 OV5670_write_cmos_sensor(0x4017, 0x08); //threshold= 2LSB for full size
1002 OV5670_write_cmos_sensor(0x400a, 0x02); //
1003 OV5670_write_cmos_sensor(0x400b, 0x00); //
1005 OV5670_write_cmos_sensor(0x0100, 0x01);
1010 static void OV5670_Sensor_Init(void)
1012 OV5670DB("OV5670_Sensor_Init_2lane enter\n");
1014 OV5670_write_cmos_sensor(0x0103,0x01);// ; software reset
1016 OV5670_write_cmos_sensor(0x0100, 0x00);// ; software standby
1017 OV5670_write_cmos_sensor(0x0100, 0x00);
1018 OV5670_write_cmos_sensor(0x0300, 0x04);
1019 OV5670_write_cmos_sensor(0x0301, 0x00);
1020 OV5670_write_cmos_sensor(0x0302, 0x64); //;78
1021 OV5670_write_cmos_sensor(0x0303, 0x00);
1022 OV5670_write_cmos_sensor(0x0304, 0x03);
1023 OV5670_write_cmos_sensor(0x0305, 0x01);
1024 OV5670_write_cmos_sensor(0x0306, 0x01);
1025 OV5670_write_cmos_sensor(0x030a, 0x00);
1026 OV5670_write_cmos_sensor(0x030b, 0x00);
1027 OV5670_write_cmos_sensor(0x030c, 0x00);
1028 OV5670_write_cmos_sensor(0x030d, 0x1e);
1029 OV5670_write_cmos_sensor(0x030e, 0x00);
1030 OV5670_write_cmos_sensor(0x030f, 0x06);
1031 OV5670_write_cmos_sensor(0x0312, 0x01);
1032 OV5670_write_cmos_sensor(0x3000, 0x00);
1033 OV5670_write_cmos_sensor(0x3002, 0x21);
1034 OV5670_write_cmos_sensor(0x3005, 0xf0);
1035 OV5670_write_cmos_sensor(0x3007, 0x00);
1036 OV5670_write_cmos_sensor(0x3015, 0x0f);
1037 OV5670_write_cmos_sensor(0x3018, 0x32);
1038 OV5670_write_cmos_sensor(0x301a, 0xf0);
1039 OV5670_write_cmos_sensor(0x301b, 0xf0);
1040 OV5670_write_cmos_sensor(0x301c, 0xf0);
1041 OV5670_write_cmos_sensor(0x301d, 0xf0);
1042 OV5670_write_cmos_sensor(0x301e, 0xf0);
1043 OV5670_write_cmos_sensor(0x3030, 0x00);
1044 OV5670_write_cmos_sensor(0x3031, 0x0a);
1045 OV5670_write_cmos_sensor(0x303c, 0xff);
1046 OV5670_write_cmos_sensor(0x303e, 0xff);
1047 OV5670_write_cmos_sensor(0x3040, 0xf0);
1048 OV5670_write_cmos_sensor(0x3041, 0x00);
1049 OV5670_write_cmos_sensor(0x3042, 0xf0);
1050 OV5670_write_cmos_sensor(0x3106, 0x11);
1051 OV5670_write_cmos_sensor(0x3500, 0x00);
1052 OV5670_write_cmos_sensor(0x3501, 0x7b);
1053 OV5670_write_cmos_sensor(0x3502, 0x00);
1054 OV5670_write_cmos_sensor(0x3503, 0x04);
1055 OV5670_write_cmos_sensor(0x3504, 0x03);
1056 OV5670_write_cmos_sensor(0x3505, 0x83);
1057 OV5670_write_cmos_sensor(0x3508, 0x07);
1058 OV5670_write_cmos_sensor(0x3509, 0x80);
1059 OV5670_write_cmos_sensor(0x350e, 0x04);
1060 OV5670_write_cmos_sensor(0x350f, 0x00);
1061 OV5670_write_cmos_sensor(0x3510, 0x00);
1062 OV5670_write_cmos_sensor(0x3511, 0x02);
1063 OV5670_write_cmos_sensor(0x3512, 0x00);
1064 OV5670_write_cmos_sensor(0x3601, 0xc8);
1065 OV5670_write_cmos_sensor(0x3610, 0x88);
1066 OV5670_write_cmos_sensor(0x3612, 0x48);
1067 OV5670_write_cmos_sensor(0x3614, 0x5b);
1068 OV5670_write_cmos_sensor(0x3615, 0x96);
1069 OV5670_write_cmos_sensor(0x3621, 0xd0);
1070 OV5670_write_cmos_sensor(0x3622, 0x00);
1071 OV5670_write_cmos_sensor(0x3623, 0x00);
1072 OV5670_write_cmos_sensor(0x3633, 0x13);
1073 OV5670_write_cmos_sensor(0x3634, 0x13);
1074 OV5670_write_cmos_sensor(0x3635, 0x13);
1075 OV5670_write_cmos_sensor(0x3636, 0x13);
1076 OV5670_write_cmos_sensor(0x3645, 0x13);
1077 OV5670_write_cmos_sensor(0x3646, 0x82);
1078 OV5670_write_cmos_sensor(0x3650, 0x00);
1079 OV5670_write_cmos_sensor(0x3652, 0xff);
1080 OV5670_write_cmos_sensor(0x3655, 0x20);
1081 OV5670_write_cmos_sensor(0x3656, 0xff);
1082 OV5670_write_cmos_sensor(0x365a, 0xff);
1083 OV5670_write_cmos_sensor(0x365e, 0xff);
1084 OV5670_write_cmos_sensor(0x3668, 0x00);
1085 OV5670_write_cmos_sensor(0x366a, 0x07);
1086 OV5670_write_cmos_sensor(0x366e, 0x10);
1087 OV5670_write_cmos_sensor(0x366d, 0x00);
1088 OV5670_write_cmos_sensor(0x366f, 0x80);
1089 OV5670_write_cmos_sensor(0x3700, 0x28);
1090 OV5670_write_cmos_sensor(0x3701, 0x10);
1091 OV5670_write_cmos_sensor(0x3702, 0x3a);
1092 OV5670_write_cmos_sensor(0x3703, 0x19);
1093 OV5670_write_cmos_sensor(0x3704, 0x10);
1094 OV5670_write_cmos_sensor(0x3705, 0x00);
1095 OV5670_write_cmos_sensor(0x3706, 0x66);
1096 OV5670_write_cmos_sensor(0x3707, 0x08);
1097 OV5670_write_cmos_sensor(0x3708, 0x34);
1098 OV5670_write_cmos_sensor(0x3709, 0x40);
1099 OV5670_write_cmos_sensor(0x370a, 0x01);
1100 OV5670_write_cmos_sensor(0x370b, 0x1b);
1101 OV5670_write_cmos_sensor(0x3714, 0x24);
1102 OV5670_write_cmos_sensor(0x371a, 0x3e);
1103 OV5670_write_cmos_sensor(0x3733, 0x00);
1104 OV5670_write_cmos_sensor(0x3734, 0x00);
1105 OV5670_write_cmos_sensor(0x373a, 0x05);
1106 OV5670_write_cmos_sensor(0x373b, 0x06);
1107 OV5670_write_cmos_sensor(0x373c, 0x0a);
1108 OV5670_write_cmos_sensor(0x373f, 0xa0);
1109 OV5670_write_cmos_sensor(0x3755, 0x00);
1110 OV5670_write_cmos_sensor(0x3758, 0x00);
1111 OV5670_write_cmos_sensor(0x375b, 0x0e);
1112 OV5670_write_cmos_sensor(0x3766, 0x5f);
1113 OV5670_write_cmos_sensor(0x3768, 0x00);
1114 OV5670_write_cmos_sensor(0x3769, 0x22);
1115 OV5670_write_cmos_sensor(0x3773, 0x08);
1116 OV5670_write_cmos_sensor(0x3774, 0x1f);
1117 OV5670_write_cmos_sensor(0x3776, 0x06);
1118 OV5670_write_cmos_sensor(0x37a0, 0x88);
1119 OV5670_write_cmos_sensor(0x37a1, 0x5c);
1120 OV5670_write_cmos_sensor(0x37a7, 0x88);
1121 OV5670_write_cmos_sensor(0x37a8, 0x70);
1122 OV5670_write_cmos_sensor(0x37aa, 0x88);
1123 OV5670_write_cmos_sensor(0x37ab, 0x48);
1124 OV5670_write_cmos_sensor(0x37b3, 0x66);
1125 OV5670_write_cmos_sensor(0x37c2, 0x04);
1126 OV5670_write_cmos_sensor(0x37c5, 0x00);
1127 OV5670_write_cmos_sensor(0x37c8, 0x00);
1128 OV5670_write_cmos_sensor(0x3800, 0x00);
1129 OV5670_write_cmos_sensor(0x3801, 0x0c);
1130 OV5670_write_cmos_sensor(0x3802, 0x00);
1131 OV5670_write_cmos_sensor(0x3803, 0x04);
1132 OV5670_write_cmos_sensor(0x3804, 0x0a);
1133 OV5670_write_cmos_sensor(0x3805, 0x33);
1134 OV5670_write_cmos_sensor(0x3806, 0x07);
1135 OV5670_write_cmos_sensor(0x3807, 0xa3);
1136 OV5670_write_cmos_sensor(0x3808, 0x0a);
1137 OV5670_write_cmos_sensor(0x3809, 0x20);
1138 OV5670_write_cmos_sensor(0x380a, 0x07);
1139 OV5670_write_cmos_sensor(0x380b, 0x98);
1140 OV5670_write_cmos_sensor(0x380c, 0x07); // ;06
1141 OV5670_write_cmos_sensor(0x380d, 0xdc); // ;8c
1142 OV5670_write_cmos_sensor(0x380e, 0x07);
1143 OV5670_write_cmos_sensor(0x380f, 0xb8);
1144 OV5670_write_cmos_sensor(0x3811, 0x04);
1145 OV5670_write_cmos_sensor(0x3813, 0x02);
1146 OV5670_write_cmos_sensor(0x3814, 0x01);
1147 OV5670_write_cmos_sensor(0x3815, 0x01);
1148 OV5670_write_cmos_sensor(0x3816, 0x00);
1149 OV5670_write_cmos_sensor(0x3817, 0x00);
1150 OV5670_write_cmos_sensor(0x3818, 0x00);
1151 OV5670_write_cmos_sensor(0x3819, 0x00);
1152 OV5670_write_cmos_sensor(0x3820, 0x80);
1153 OV5670_write_cmos_sensor(0x3821, 0x46);
1154 OV5670_write_cmos_sensor(0x3822, 0x48);
1155 OV5670_write_cmos_sensor(0x3826, 0x00);
1156 OV5670_write_cmos_sensor(0x3827, 0x08);
1157 OV5670_write_cmos_sensor(0x382a, 0x01);
1158 OV5670_write_cmos_sensor(0x382b, 0x01);
1159 OV5670_write_cmos_sensor(0x3830, 0x08);
1160 OV5670_write_cmos_sensor(0x3836, 0x02);
1161 OV5670_write_cmos_sensor(0x3837, 0x00);
1162 OV5670_write_cmos_sensor(0x3838, 0x10);
1163 OV5670_write_cmos_sensor(0x3841, 0xff);
1164 OV5670_write_cmos_sensor(0x3846, 0x48);
1165 OV5670_write_cmos_sensor(0x3861, 0x00);
1166 OV5670_write_cmos_sensor(0x3862, 0x04);//x00);
1167 OV5670_write_cmos_sensor(0x3863, 0x06);//0x18);
1168 OV5670_write_cmos_sensor(0x3a11, 0x01);
1169 OV5670_write_cmos_sensor(0x3a12, 0x78);
1170 OV5670_write_cmos_sensor(0x3b00, 0x00);
1171 OV5670_write_cmos_sensor(0x3b02, 0x00);
1172 OV5670_write_cmos_sensor(0x3b03, 0x00);
1173 OV5670_write_cmos_sensor(0x3b04, 0x00);
1174 OV5670_write_cmos_sensor(0x3b05, 0x00);
1175 OV5670_write_cmos_sensor(0x3c00, 0x89);
1176 OV5670_write_cmos_sensor(0x3c01, 0xab);
1177 OV5670_write_cmos_sensor(0x3c02, 0x01);
1178 OV5670_write_cmos_sensor(0x3c03, 0x00);
1179 OV5670_write_cmos_sensor(0x3c04, 0x00);
1180 OV5670_write_cmos_sensor(0x3c05, 0x03);
1181 OV5670_write_cmos_sensor(0x3c06, 0x00);
1182 OV5670_write_cmos_sensor(0x3c07, 0x05);
1183 OV5670_write_cmos_sensor(0x3c0c, 0x00);
1184 OV5670_write_cmos_sensor(0x3c0d, 0x00);
1185 OV5670_write_cmos_sensor(0x3c0e, 0x00);
1186 OV5670_write_cmos_sensor(0x3c0f, 0x00);
1187 OV5670_write_cmos_sensor(0x3c40, 0x00);
1188 OV5670_write_cmos_sensor(0x3c41, 0xa3);
1189 OV5670_write_cmos_sensor(0x3c43, 0x7d);
1190 OV5670_write_cmos_sensor(0x3c45, 0xd7);
1191 OV5670_write_cmos_sensor(0x3c47, 0xfc);
1192 OV5670_write_cmos_sensor(0x3c50, 0x05);
1193 OV5670_write_cmos_sensor(0x3c52, 0xaa);
1194 OV5670_write_cmos_sensor(0x3c54, 0x71);
1195 OV5670_write_cmos_sensor(0x3c56, 0x80);
1196 OV5670_write_cmos_sensor(0x3d85, 0x17);
1197 OV5670_write_cmos_sensor(0x3f03, 0x00);
1198 OV5670_write_cmos_sensor(0x3f0a, 0x00);
1199 OV5670_write_cmos_sensor(0x3f0b, 0x00);
1200 OV5670_write_cmos_sensor(0x4001, 0x60);
1201 OV5670_write_cmos_sensor(0x4009, 0x0d);
1202 OV5670_write_cmos_sensor(0x4020, 0x00);
1203 OV5670_write_cmos_sensor(0x4021, 0x00);
1204 OV5670_write_cmos_sensor(0x4022, 0x00);
1205 OV5670_write_cmos_sensor(0x4023, 0x00);
1206 OV5670_write_cmos_sensor(0x4024, 0x00);
1207 OV5670_write_cmos_sensor(0x4025, 0x00);
1208 OV5670_write_cmos_sensor(0x4026, 0x00);
1209 OV5670_write_cmos_sensor(0x4027, 0x00);
1210 OV5670_write_cmos_sensor(0x4028, 0x00);
1211 OV5670_write_cmos_sensor(0x4029, 0x00);
1212 OV5670_write_cmos_sensor(0x402a, 0x00);
1213 OV5670_write_cmos_sensor(0x402b, 0x00);
1214 OV5670_write_cmos_sensor(0x402c, 0x00);
1215 OV5670_write_cmos_sensor(0x402d, 0x00);
1216 OV5670_write_cmos_sensor(0x402e, 0x00);
1217 OV5670_write_cmos_sensor(0x402f, 0x00);
1218 OV5670_write_cmos_sensor(0x4040, 0x00);
1219 OV5670_write_cmos_sensor(0x4041, 0x03);//0x00);
1220 OV5670_write_cmos_sensor(0x4042, 0x00);
1221 OV5670_write_cmos_sensor(0x4043, 0x7a);//0x80);
1222 OV5670_write_cmos_sensor(0x4044, 0x00);
1223 OV5670_write_cmos_sensor(0x4045, 0x7a);//0x80);
1224 OV5670_write_cmos_sensor(0x4046, 0x00);
1225 OV5670_write_cmos_sensor(0x4047, 0x7a);//0x80);
1226 OV5670_write_cmos_sensor(0x4048, 0x00);
1227 OV5670_write_cmos_sensor(0x4049, 0x7a);//0x80);
1228 OV5670_write_cmos_sensor(0x4303, 0x00);
1229 OV5670_write_cmos_sensor(0x4307, 0x30);
1230 OV5670_write_cmos_sensor(0x4500, 0x58);
1231 OV5670_write_cmos_sensor(0x4501, 0x04);
1232 OV5670_write_cmos_sensor(0x4502, 0x40);
1233 OV5670_write_cmos_sensor(0x4503, 0x10);
1234 OV5670_write_cmos_sensor(0x4508, 0xaa);
1235 OV5670_write_cmos_sensor(0x4509, 0xaa);
1236 OV5670_write_cmos_sensor(0x450a, 0x00);
1237 OV5670_write_cmos_sensor(0x450b, 0x00);
1238 OV5670_write_cmos_sensor(0x4600, 0x01);
1239 OV5670_write_cmos_sensor(0x4601, 0x03);
1240 OV5670_write_cmos_sensor(0x4700, 0xa4);
1241 OV5670_write_cmos_sensor(0x4800, 0x4c);
1242 OV5670_write_cmos_sensor(0x4816, 0x53);
1243 OV5670_write_cmos_sensor(0x481f, 0x40);
1244 OV5670_write_cmos_sensor(0x4837, 0x14); // ;11
1245 OV5670_write_cmos_sensor(0x5000, 0x56);//0x16);
1246 OV5670_write_cmos_sensor(0x5001, 0x01);
1247 OV5670_write_cmos_sensor(0x5002, 0x28);//0xa8);
1248 OV5670_write_cmos_sensor(0x5004, 0x0c);
1249 OV5670_write_cmos_sensor(0x5006, 0x0c);
1250 OV5670_write_cmos_sensor(0x5007, 0xe0);
1251 OV5670_write_cmos_sensor(0x5008, 0x01);
1252 OV5670_write_cmos_sensor(0x5009, 0xb0);
1253 OV5670_write_cmos_sensor(0x5901, 0x00);
1254 OV5670_write_cmos_sensor(0x5a01, 0x00);
1255 OV5670_write_cmos_sensor(0x5a03, 0x00);
1256 OV5670_write_cmos_sensor(0x5a04, 0x0c);
1257 OV5670_write_cmos_sensor(0x5a05, 0xe0);
1258 OV5670_write_cmos_sensor(0x5a06, 0x09);
1259 OV5670_write_cmos_sensor(0x5a07, 0xb0);
1260 OV5670_write_cmos_sensor(0x5a08, 0x06);
1261 OV5670_write_cmos_sensor(0x5e00, 0x00);
1263 OV5670_write_cmos_sensor(0x3734, 0x40);
1264 OV5670_write_cmos_sensor(0x5b00, 0x01);
1265 OV5670_write_cmos_sensor(0x5b01, 0x10);
1266 OV5670_write_cmos_sensor(0x5b02, 0x01);
1267 OV5670_write_cmos_sensor(0x5b03, 0xdb);
1268 OV5670_write_cmos_sensor(0x3d8c, 0x71);
1269 OV5670_write_cmos_sensor(0x3d8d, 0xea);
1270 OV5670_write_cmos_sensor(0x4017, 0x08);
1272 OV5670_write_cmos_sensor(0x3618, 0x2a);
1275 OV5670_write_cmos_sensor(0x3734, 0x40); // ;; Improve HFPN
1276 OV5670_write_cmos_sensor(0x5b00, 0x01); // ;; [2:0] otp start addr[10:8]
1277 OV5670_write_cmos_sensor(0x5b01, 0x10); // ;; [7:0] otp start addr[7:0]
1278 OV5670_write_cmos_sensor(0x5b02, 0x01); // ;; [2:0] otp end addr[10:8]
1279 OV5670_write_cmos_sensor(0x5b03, 0xDB); // ;; [7:0] otp end addr[7:0]
1280 OV5670_write_cmos_sensor(0x3d8c, 0x71); //; Header address high byte
1281 OV5670_write_cmos_sensor(0x3d8d, 0xEA); //; Header address low byte
1282 OV5670_write_cmos_sensor(0x4017, 0x08); // ; threshold= 2LSB for full size
1285 OV5670_write_cmos_sensor(0x5780, 0x3e);
1286 OV5670_write_cmos_sensor(0x5781, 0x0f);
1287 OV5670_write_cmos_sensor(0x5782, 0x44);
1288 OV5670_write_cmos_sensor(0x5783, 0x02);
1289 OV5670_write_cmos_sensor(0x5784, 0x01);
1290 OV5670_write_cmos_sensor(0x5785, 0x00);
1291 OV5670_write_cmos_sensor(0x5786, 0x00);
1292 OV5670_write_cmos_sensor(0x5787, 0x04);
1293 OV5670_write_cmos_sensor(0x5788, 0x02);
1294 OV5670_write_cmos_sensor(0x5789, 0x0f);
1295 OV5670_write_cmos_sensor(0x578a, 0xfd);
1296 OV5670_write_cmos_sensor(0x578b, 0xf5);
1297 OV5670_write_cmos_sensor(0x578c, 0xf5);
1298 OV5670_write_cmos_sensor(0x578d, 0x03);
1299 OV5670_write_cmos_sensor(0x578e, 0x08);
1300 OV5670_write_cmos_sensor(0x578f, 0x0c);
1301 OV5670_write_cmos_sensor(0x5790, 0x08);
1302 OV5670_write_cmos_sensor(0x5791, 0x04);
1303 OV5670_write_cmos_sensor(0x5792, 0x00);
1304 OV5670_write_cmos_sensor(0x5793, 0x52);
1305 OV5670_write_cmos_sensor(0x5794, 0xa3);
1307 OV5670_write_cmos_sensor(0x380e, 0x07); //; fps fine adjustment
1308 OV5670_write_cmos_sensor(0x380f, 0xfd); //; fps fine adjustment
1309 OV5670_write_cmos_sensor(0x3503, 0x00); //; real gain [2] gain no delay, shutter no delay
1311 OV5670_write_cmos_sensor(0x3d85, 0x17);
1312 OV5670_write_cmos_sensor(0x3655, 0x20);
1314 OV5670_write_cmos_sensor(0x0100, 0x01); //;01
1316 ov5670_otp_config();
1320 UINT32
OV5670Open(void)
1323 volatile signed int i
;
1324 kal_uint16 sensor_id
= 0;
1326 OV5670DB("OV5670 Open enter :\n ");
1327 OV5670_write_cmos_sensor(0x0103,0x01);// Reset sensor
1332 sensor_id
= (OV5670_read_cmos_sensor(0x300B)<<8)|OV5670_read_cmos_sensor(0x300C);
1333 OV5670DB("OV5670 READ ID :%x",sensor_id
);
1334 if(sensor_id
!= OV5670MIPI_SENSOR_ID
)
1336 return ERROR_SENSOR_CONNECT_FAIL
;
1341 OV5670_Sensor_Init();
1343 OV5670DB("OV5670Open exit :\n ");
1348 void OV5670GetModuleID(void)
1350 struct otp_struct otp_info
;
1352 OV5670_write_cmos_sensor(0x0100, 0x01); //stream on
1353 read_otp(&otp_info
);
1354 OV5670_write_cmos_sensor(0x0100, 0x00); //stream off
1357 UINT32
OV5670GetSensorID(UINT32
*sensorID
)
1361 OV5670DB("OV5670GetSensorID enter :\n ");
1365 *sensorID
= (OV5670_read_cmos_sensor(0x300B)<<8)|OV5670_read_cmos_sensor(0x300C);
1366 if (*sensorID
== OV5670MIPI_SENSOR_ID
)
1368 OV5670DB("Sensor ID = 0x%04x\n", *sensorID
);
1369 OV5670GetModuleID();
1372 OV5670DB("Read Sensor ID Fail = 0x%04x\n", *sensorID
);
1374 } while (retry
> 0);
1376 if (*sensorID
!= OV5670MIPI_SENSOR_ID
) {
1377 OV5670DB("Read Sensor ID Fail = 0x%04x\n", *sensorID
);
1379 *sensorID
= 0xFFFFFFFF;
1380 return ERROR_SENSOR_CONNECT_FAIL
;
1382 OV5670DB("alexadd %s module_id=%d", __func__
, module_id
);
1383 if (module_id
== 0x0c ||module_id
!= 0x44) return ERROR_NONE
;
1386 *sensorID
= 0xFFFFFFFF;
1387 return ERROR_SENSOR_CONNECT_FAIL
;
1391 void OV5670_SetShutter(kal_uint32 iShutter
)
1394 spin_lock(&ov5670mipiraw_drv_lock
);
1395 OV5670
.shutter
= iShutter
;
1396 spin_unlock(&ov5670mipiraw_drv_lock
);
1398 OV5670_write_shutter(iShutter
);
1404 UINT32
OV5670_read_shutter(void)
1407 kal_uint16 temp_reg1
, temp_reg2
,temp_reg3
;
1409 temp_reg1
= OV5670_read_cmos_sensor(0x3500); // AEC[b19~b16]
1410 temp_reg2
= OV5670_read_cmos_sensor(0x3501); // AEC[b15~b8]
1411 temp_reg3
= OV5670_read_cmos_sensor(0x3502); // AEC[b7~b0]
1413 shutter
= (temp_reg1
<<12)| (temp_reg2
<<4)|(temp_reg3
>>4);
1418 void OV5670_NightMode(kal_bool bEnable
)
1423 UINT32
OV5670Close(void)
1430 void OV5670SetFlipMirror(kal_int32 imgMirror
)
1432 kal_int16 mirror
=0,flip
=0;
1433 mirror
= OV5670_read_cmos_sensor(0x3820);
1434 flip
= OV5670_read_cmos_sensor(0x3821);
1438 case IMAGE_H_MIRROR
://IMAGE_NORMAL:
1439 OV5670_write_cmos_sensor(0x3820, (mirror
& (0xF9)));//Set normal
1440 OV5670_write_cmos_sensor(0x3821, (flip
& (0xF9))); //Set normal
1442 case IMAGE_NORMAL
://IMAGE_V_MIRROR:
1443 OV5670_write_cmos_sensor(0x3820, (mirror
& (0xF9)));//Set flip
1444 OV5670_write_cmos_sensor(0x3821, (flip
| (0x06))); //Set flip
1446 case IMAGE_HV_MIRROR
://IMAGE_H_MIRROR:
1447 OV5670_write_cmos_sensor(0x3820, (mirror
|(0x06))); //Set mirror
1448 OV5670_write_cmos_sensor(0x3821, (flip
& (0xF9))); //Set mirror
1450 case IMAGE_V_MIRROR
://IMAGE_HV_MIRROR:
1451 OV5670_write_cmos_sensor(0x3820, (mirror
|(0x06))); //Set mirror & flip
1452 OV5670_write_cmos_sensor(0x3821, (flip
|(0x06))); //Set mirror & flip
1459 UINT32
OV5670Preview(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT
*image_window
,
1460 MSDK_SENSOR_CONFIG_STRUCT
*sensor_config_data
)
1463 OV5670DB("OV5670Preview enter:");
1465 //OV5670PreviewSetting();
1466 OV5670CaptureSetting();
1467 spin_lock(&ov5670mipiraw_drv_lock
);
1468 OV5670
.sensorMode
= SENSOR_MODE_PREVIEW
;
1469 OV5670
.DummyPixels
= 0;
1470 OV5670
.DummyLines
= 0 ;
1471 OV5670_FeatureControl_PERIOD_PixelNum
=OV5670_PV_PERIOD_PIXEL_NUMS
+ OV5670
.DummyPixels
;
1472 OV5670_FeatureControl_PERIOD_LineNum
=OV5670_PV_PERIOD_LINE_NUMS
+OV5670
.DummyLines
;
1473 OV5670
.imgMirror
= sensor_config_data
->SensorImageMirror
;
1474 spin_unlock(&ov5670mipiraw_drv_lock
);
1476 //OV5670SetFlipMirror(sensor_config_data->SensorImageMirror);
1478 mdelay(20);//THIS DELAY SHOULD BE NEED BY CTS OR MONKEY
1479 OV5670DB("OV5670Preview exit:\n");
1486 UINT32
OV5670Video(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT
*image_window
,
1487 MSDK_SENSOR_CONFIG_STRUCT
*sensor_config_data
)
1490 OV5670DB("OV5670Video enter:");
1492 OV5670VideoSetting();
1494 spin_lock(&ov5670mipiraw_drv_lock
);
1495 OV5670
.sensorMode
= SENSOR_MODE_VIDEO
;
1496 OV5670_FeatureControl_PERIOD_PixelNum
=OV5670_VIDEO_PERIOD_PIXEL_NUMS
+ OV5670
.DummyPixels
;
1497 OV5670_FeatureControl_PERIOD_LineNum
=OV5670_VIDEO_PERIOD_LINE_NUMS
+OV5670
.DummyLines
;
1498 OV5670
.imgMirror
= sensor_config_data
->SensorImageMirror
;
1499 spin_unlock(&ov5670mipiraw_drv_lock
);
1501 //OV5670SetFlipMirror(sensor_config_data->SensorImageMirror);
1503 mdelay(40);//THIS DELAY SHOULD BE NEED BY CTS OR MONKEY
1504 OV5670DB("OV5670Video exit:\n");
1509 UINT32
OV5670Capture(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT
*image_window
,
1510 MSDK_SENSOR_CONFIG_STRUCT
*sensor_config_data
)
1513 //kal_uint32 shutter = OV5670.shutter;
1515 if( SENSOR_MODE_CAPTURE
== OV5670
.sensorMode
)
1517 OV5670DB("OV5670Capture BusrtShot / ZSD!!!\n");
1521 OV5670DB("OV5670Capture enter:\n");
1523 OV5670CaptureSetting();
1524 mdelay(40);//THIS DELAY SHOULD BE NEED BY CTS OR MONKEY
1526 spin_lock(&ov5670mipiraw_drv_lock
);
1527 OV5670
.sensorMode
= SENSOR_MODE_CAPTURE
;
1528 OV5670
.imgMirror
= sensor_config_data
->SensorImageMirror
;
1529 OV5670
.DummyPixels
= 0;
1530 OV5670
.DummyLines
= 0 ;
1531 OV5670_FeatureControl_PERIOD_PixelNum
= OV5670_FULL_PERIOD_PIXEL_NUMS
+ OV5670
.DummyPixels
;
1532 OV5670_FeatureControl_PERIOD_LineNum
= OV5670_FULL_PERIOD_LINE_NUMS
+ OV5670
.DummyLines
;
1533 spin_unlock(&ov5670mipiraw_drv_lock
);
1535 //OV5670SetFlipMirror(sensor_config_data->SensorImageMirror);
1537 OV5670DB("OV5670Capture exit:\n");
1540 if(OV5670_During_testpattern
== KAL_TRUE
)
1542 OV5670_write_cmos_sensor(0x4303,0x80);
1550 UINT32
OV5670GetResolution(MSDK_SENSOR_RESOLUTION_INFO_STRUCT
*pSensorResolution
)
1553 OV5670DB("OV5670GetResolution!!\n");
1555 pSensorResolution
->SensorPreviewWidth
= OV5670_IMAGE_SENSOR_FULL_WIDTH
;
1556 pSensorResolution
->SensorPreviewHeight
= OV5670_IMAGE_SENSOR_FULL_HEIGHT
;
1558 pSensorResolution
->SensorFullWidth
= OV5670_IMAGE_SENSOR_FULL_WIDTH
;
1559 pSensorResolution
->SensorFullHeight
= OV5670_IMAGE_SENSOR_FULL_HEIGHT
;
1561 pSensorResolution
->SensorVideoWidth
= OV5670_IMAGE_SENSOR_VIDEO_WIDTH
;
1562 pSensorResolution
->SensorVideoHeight
= OV5670_IMAGE_SENSOR_VIDEO_HEIGHT
;
1566 UINT32
OV5670GetInfo(MSDK_SCENARIO_ID_ENUM ScenarioId
,
1567 MSDK_SENSOR_INFO_STRUCT
*pSensorInfo
,
1568 MSDK_SENSOR_CONFIG_STRUCT
*pSensorConfigData
)
1571 spin_lock(&ov5670mipiraw_drv_lock
);
1572 OV5670
.imgMirror
= pSensorConfigData
->SensorImageMirror
;
1573 spin_unlock(&ov5670mipiraw_drv_lock
);
1575 pSensorInfo
->SensorOutputDataFormat
= SENSOR_OUTPUT_FORMAT_RAW_B
;
1577 pSensorInfo
->SensorClockPolarity
=SENSOR_CLOCK_POLARITY_LOW
;
1578 pSensorInfo
->SensorClockFallingPolarity
=SENSOR_CLOCK_POLARITY_LOW
;
1579 pSensorInfo
->SensorHsyncPolarity
= SENSOR_CLOCK_POLARITY_LOW
;
1580 pSensorInfo
->SensorVsyncPolarity
= SENSOR_CLOCK_POLARITY_LOW
;
1582 pSensorInfo
->SensroInterfaceType
=SENSOR_INTERFACE_TYPE_MIPI
;
1584 pSensorInfo
->CaptureDelayFrame
= 2;
1585 pSensorInfo
->PreviewDelayFrame
= 1;
1586 pSensorInfo
->VideoDelayFrame
= 2;
1588 pSensorInfo
->SensorDrivingCurrent
= ISP_DRIVING_8MA
;
1589 pSensorInfo
->AEShutDelayFrame
= 0;
1590 pSensorInfo
->AESensorGainDelayFrame
= 0;
1591 pSensorInfo
->AEISPGainDelayFrame
= 2;
1595 case MSDK_SCENARIO_ID_CAMERA_PREVIEW
:
1596 pSensorInfo
->SensorClockFreq
=24;
1597 pSensorInfo
->SensorClockRisingCount
= 0;
1599 pSensorInfo
->SensorGrabStartX
= OV5670_PV_X_START
;
1600 pSensorInfo
->SensorGrabStartY
= OV5670_PV_Y_START
;
1602 pSensorInfo
->SensorMIPILaneNumber
= SENSOR_MIPI_2_LANE
;
1604 pSensorInfo
->MIPIDataLowPwr2HighSpeedTermDelayCount
= 0;
1605 pSensorInfo
->MIPIDataLowPwr2HighSpeedSettleDelayCount
= 14;
1606 pSensorInfo
->MIPICLKLowPwr2HighSpeedTermDelayCount
= 0;
1607 pSensorInfo
->SensorPacketECCOrder
= 1;
1609 case MSDK_SCENARIO_ID_VIDEO_PREVIEW
:
1610 pSensorInfo
->SensorClockFreq
=24;
1611 pSensorInfo
->SensorClockRisingCount
= 0;
1613 pSensorInfo
->SensorGrabStartX
= OV5670_VIDEO_X_START
;
1614 pSensorInfo
->SensorGrabStartY
= OV5670_VIDEO_Y_START
;
1616 pSensorInfo
->SensorMIPILaneNumber
= SENSOR_MIPI_2_LANE
;
1618 pSensorInfo
->MIPIDataLowPwr2HighSpeedTermDelayCount
= 0;
1619 pSensorInfo
->MIPIDataLowPwr2HighSpeedSettleDelayCount
= 14;
1620 pSensorInfo
->MIPICLKLowPwr2HighSpeedTermDelayCount
= 0;
1621 pSensorInfo
->SensorPacketECCOrder
= 1;
1623 case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG
:
1624 case MSDK_SCENARIO_ID_CAMERA_ZSD
:
1625 pSensorInfo
->SensorClockFreq
=24;
1626 pSensorInfo
->SensorClockRisingCount
= 0;
1628 pSensorInfo
->SensorGrabStartX
= OV5670_FULL_X_START
;
1629 pSensorInfo
->SensorGrabStartY
= OV5670_FULL_Y_START
;
1631 pSensorInfo
->SensorMIPILaneNumber
= SENSOR_MIPI_2_LANE
;
1633 pSensorInfo
->MIPIDataLowPwr2HighSpeedTermDelayCount
= 0;
1634 pSensorInfo
->MIPIDataLowPwr2HighSpeedSettleDelayCount
= 14;
1635 pSensorInfo
->MIPICLKLowPwr2HighSpeedTermDelayCount
= 0;
1636 pSensorInfo
->SensorPacketECCOrder
= 1;
1639 pSensorInfo
->SensorClockFreq
=24;
1640 pSensorInfo
->SensorClockRisingCount
= 0;
1642 pSensorInfo
->SensorGrabStartX
= OV5670_PV_X_START
;
1643 pSensorInfo
->SensorGrabStartY
= OV5670_PV_Y_START
;
1645 pSensorInfo
->SensorMIPILaneNumber
= SENSOR_MIPI_2_LANE
;
1647 pSensorInfo
->MIPIDataLowPwr2HighSpeedTermDelayCount
= 0;
1648 pSensorInfo
->MIPIDataLowPwr2HighSpeedSettleDelayCount
= 14;
1649 pSensorInfo
->MIPICLKLowPwr2HighSpeedTermDelayCount
= 0;
1650 pSensorInfo
->SensorPacketECCOrder
= 1;
1654 memcpy(pSensorConfigData
, &OV5670SensorConfigData
, sizeof(MSDK_SENSOR_CONFIG_STRUCT
));
1657 } /* OV5670GetInfo() */
1661 UINT32
OV5670Control(MSDK_SCENARIO_ID_ENUM ScenarioId
, MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT
*pImageWindow
,
1662 MSDK_SENSOR_CONFIG_STRUCT
*pSensorConfigData
)
1664 spin_lock(&ov5670mipiraw_drv_lock
);
1665 OV5670CurrentScenarioId
= ScenarioId
;
1666 spin_unlock(&ov5670mipiraw_drv_lock
);
1668 OV5670DB("OV5670CurrentScenarioId=%d\n",OV5670CurrentScenarioId
);
1672 case MSDK_SCENARIO_ID_CAMERA_PREVIEW
:
1673 OV5670Preview(pImageWindow
, pSensorConfigData
);
1675 case MSDK_SCENARIO_ID_VIDEO_PREVIEW
:
1676 OV5670DB("OV5670 video_preiew sync\n");
1677 OV5670Video(pImageWindow
, pSensorConfigData
);
1679 case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG
:
1680 case MSDK_SCENARIO_ID_CAMERA_ZSD
:
1681 OV5670Capture(pImageWindow
, pSensorConfigData
);
1685 return ERROR_INVALID_SCENARIO_ID
;
1689 } /* OV5670Control() */
1693 kal_uint32
OV5670_SET_FrameLength_ByVideoMode(UINT16 Video_TargetFps
)
1695 UINT32 frameRate
= 0;
1696 kal_uint32 MIN_FrameLength
=0;
1698 if(OV5670
.OV5670AutoFlickerMode
== KAL_TRUE
)
1700 if (Video_TargetFps
==30)
1701 frameRate
= OV5670_AUTOFLICKER_OFFSET_30
;
1702 else if(Video_TargetFps
==15)
1703 frameRate
= OV5670_AUTOFLICKER_OFFSET_15
;
1705 frameRate
=Video_TargetFps
*10;
1707 MIN_FrameLength
= (OV5670
.videoPclk
*10000)/(OV5670_VIDEO_PERIOD_PIXEL_NUMS
+ OV5670
.DummyPixels
)/frameRate
*10;
1710 MIN_FrameLength
= (OV5670
.videoPclk
*10000) /(OV5670_VIDEO_PERIOD_PIXEL_NUMS
+ OV5670
.DummyPixels
)/Video_TargetFps
;
1712 return MIN_FrameLength
;
1718 UINT32
OV5670SetVideoMode(UINT16 u2FrameRate
)
1721 kal_uint32 MIN_Frame_length
=0,frameRate
=0,extralines
=0;
1722 OV5670DB("[OV5670SetVideoMode] frame rate = %d\n", u2FrameRate
);
1724 spin_lock(&ov5670mipiraw_drv_lock
);
1725 OV5670_VIDEO_MODE_TARGET_FPS
=u2FrameRate
;
1726 spin_unlock(&ov5670mipiraw_drv_lock
);
1730 OV5670DB("Disable Video Mode or dynimac fps\n");
1733 if(u2FrameRate
>30 || u2FrameRate
<5)
1734 OV5670DB("abmornal frame rate seting,pay attention~\n");
1736 if(OV5670
.sensorMode
== SENSOR_MODE_VIDEO
)//video ScenarioId recording
1739 MIN_Frame_length
= OV5670_SET_FrameLength_ByVideoMode(u2FrameRate
);
1741 if((MIN_Frame_length
<=OV5670_VIDEO_PERIOD_LINE_NUMS
))
1743 MIN_Frame_length
= OV5670_VIDEO_PERIOD_LINE_NUMS
;
1744 OV5670DB("[OV5670SetVideoMode]current fps = %d\n", (OV5670
.videoPclk
*10000) /(OV5670_VIDEO_PERIOD_PIXEL_NUMS
)/OV5670_VIDEO_PERIOD_LINE_NUMS
);
1746 OV5670DB("[OV5670SetVideoMode]current fps (10 base)= %d\n", (OV5670
.videoPclk
*10000)*10/(OV5670_VIDEO_PERIOD_PIXEL_NUMS
+ OV5670
.DummyPixels
)/MIN_Frame_length
);
1747 extralines
= MIN_Frame_length
- OV5670_VIDEO_PERIOD_LINE_NUMS
;
1749 spin_lock(&ov5670mipiraw_drv_lock
);
1750 OV5670
.DummyPixels
= 0;//define dummy pixels and lines
1751 OV5670
.DummyLines
= extralines
;
1752 spin_unlock(&ov5670mipiraw_drv_lock
);
1754 OV5670_SetDummy(OV5670
.DummyPixels
,extralines
);
1757 OV5670DB("[OV5670SetVideoMode]MIN_Frame_length=%d,OV5670.DummyLines=%d\n",MIN_Frame_length
,OV5670
.DummyLines
);
1763 UINT32
OV5670SetAutoFlickerMode(kal_bool bEnable
, UINT16 u2FrameRate
)
1767 spin_lock(&ov5670mipiraw_drv_lock
);
1768 OV5670
.OV5670AutoFlickerMode
= KAL_TRUE
;
1769 spin_unlock(&ov5670mipiraw_drv_lock
);
1770 OV5670DB("OV5670 Enable Auto flicker\n");
1772 spin_lock(&ov5670mipiraw_drv_lock
);
1773 OV5670
.OV5670AutoFlickerMode
= KAL_FALSE
;
1774 spin_unlock(&ov5670mipiraw_drv_lock
);
1775 OV5670DB("OV5670 Disable Auto flicker\n");
1782 UINT32
OV5670SetTestPatternMode(kal_bool bEnable
)
1784 OV5670DB("[OV5670SetTestPatternMode] Test pattern enable:%d\n", bEnable
);
1785 if(bEnable
== KAL_TRUE
)
1787 OV5670_During_testpattern
= KAL_TRUE
;
1789 //OV5670_write_cmos_sensor(0x5000,0x16);// ; LENC off, MWB on, BPC on, WPC on
1791 OV5670_write_cmos_sensor(0x4303,0x08);
1795 OV5670_During_testpattern
= KAL_FALSE
;
1796 //OV5670_write_cmos_sensor(0x5000,0x96);// ; LENC on, MWB on, BPC on, WPC on
1797 OV5670_write_cmos_sensor(0x4303,0x00);
1804 /*************************************************************************
1807 * INTERFACE FUNCTION, FOR USER TO SET MAX FRAMERATE;
1809 *************************************************************************/
1810 UINT32
OV5670MIPISetMaxFramerateByScenario(MSDK_SCENARIO_ID_ENUM scenarioId
, MUINT32 frameRate
) {
1812 kal_int16 dummyLine
;
1813 kal_uint16 lineLength
,frameHeight
;
1815 OV5670DB("OV5670MIPISetMaxFramerateByScenario: scenarioId = %d, frame rate = %d\n",scenarioId
,frameRate
);
1816 switch (scenarioId
) {
1817 case MSDK_SCENARIO_ID_CAMERA_PREVIEW
:
1818 pclk
= OV5670_PREVIEW_PCLK
;
1819 lineLength
= OV5670_PV_PERIOD_PIXEL_NUMS
;
1820 frameHeight
= (10 * pclk
)/frameRate
/lineLength
;
1821 dummyLine
= frameHeight
- OV5670_PV_PERIOD_LINE_NUMS
;
1824 spin_lock(&ov5670mipiraw_drv_lock
);
1825 OV5670
.sensorMode
= SENSOR_MODE_PREVIEW
;
1826 spin_unlock(&ov5670mipiraw_drv_lock
);
1827 OV5670_SetDummy(0, dummyLine
);
1829 case MSDK_SCENARIO_ID_VIDEO_PREVIEW
:
1830 pclk
= OV5670_VIDEO_PCLK
;
1831 lineLength
= OV5670_VIDEO_PERIOD_PIXEL_NUMS
;
1832 frameHeight
= (10 * pclk
)/frameRate
/lineLength
;
1833 dummyLine
= frameHeight
- OV5670_VIDEO_PERIOD_LINE_NUMS
;
1836 spin_lock(&ov5670mipiraw_drv_lock
);
1837 OV5670
.sensorMode
= SENSOR_MODE_VIDEO
;
1838 spin_unlock(&ov5670mipiraw_drv_lock
);
1839 OV5670_SetDummy(0, dummyLine
);
1842 case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG
:
1843 case MSDK_SCENARIO_ID_CAMERA_ZSD
:
1844 pclk
= OV5670_CAPTURE_PCLK
;
1845 lineLength
= OV5670_FULL_PERIOD_PIXEL_NUMS
;
1846 frameHeight
= (10 * pclk
)/frameRate
/lineLength
;
1847 dummyLine
= frameHeight
- OV5670_FULL_PERIOD_LINE_NUMS
;
1850 spin_lock(&ov5670mipiraw_drv_lock
);
1851 OV5670
.sensorMode
= SENSOR_MODE_CAPTURE
;
1852 spin_unlock(&ov5670mipiraw_drv_lock
);
1853 OV5670_SetDummy(0, dummyLine
);
1855 case MSDK_SCENARIO_ID_CAMERA_3D_PREVIEW
:
1857 case MSDK_SCENARIO_ID_CAMERA_3D_VIDEO
:
1859 case MSDK_SCENARIO_ID_CAMERA_3D_CAPTURE
:
1868 UINT32
OV5670MIPIGetDefaultFramerateByScenario(MSDK_SCENARIO_ID_ENUM scenarioId
, MUINT32
*pframeRate
)
1871 switch (scenarioId
) {
1872 case MSDK_SCENARIO_ID_CAMERA_PREVIEW
:
1873 case MSDK_SCENARIO_ID_VIDEO_PREVIEW
:
1874 *pframeRate
= OV5670_MAX_FPS_PREVIEW
;
1876 case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG
:
1877 case MSDK_SCENARIO_ID_CAMERA_ZSD
:
1878 *pframeRate
= OV5670_MAX_FPS_CAPTURE
;
1880 case MSDK_SCENARIO_ID_CAMERA_3D_PREVIEW
: //added
1881 case MSDK_SCENARIO_ID_CAMERA_3D_VIDEO
:
1882 case MSDK_SCENARIO_ID_CAMERA_3D_CAPTURE
: //added
1883 *pframeRate
= OV5670_MAX_FPS_CAPTURE
;
1892 /* Sensor output window information */
1894 /* SZ TCT xuejian.zhong add for CTS test*/
1896 static void OV5670GetAFMaxNumFocusAreas(UINT32
*pFeatureReturnPara32
)
1898 *pFeatureReturnPara32
= 0;
1899 // SENSORDB("OV5670GetAFMaxNumFocusAreas *pFeatureReturnPara32 = %d¥n", *pFeatureReturnPara32);
1902 static void OV5670GetAEMaxNumMeteringAreas(UINT32
*pFeatureReturnPara32
)
1904 *pFeatureReturnPara32
= 0;
1905 // SENSORDB("OV5670GetAEMaxNumMeteringAreas *pFeatureReturnPara32 = %d¥n", *pFeatureReturnPara32);
1908 static void OV5670GetExifInfo(UINT32 exifAddr
)
1910 SENSOR_EXIF_INFO_STRUCT
* pExifInfo
= (SENSOR_EXIF_INFO_STRUCT
*)exifAddr
;
1911 pExifInfo
->FNumber
= 28;
1912 pExifInfo
->AEISOSpeed
= AE_ISO_100
;
1913 pExifInfo
->AWBMode
= AWB_MODE_AUTO
;
1914 pExifInfo
->CapExposureTime
= 0;
1915 pExifInfo
->FlashLightTimeus
= 0;
1916 pExifInfo
->RealISOValue
= AE_ISO_100
;
1919 /* SZ TCT xuejian.zhong end */
1922 UINT32
OV5670FeatureControl(MSDK_SENSOR_FEATURE_ENUM FeatureId
,
1923 UINT8
*pFeaturePara
,UINT32
*pFeatureParaLen
)
1925 UINT16
*pFeatureReturnPara16
=(UINT16
*) pFeaturePara
;
1926 UINT16
*pFeatureData16
=(UINT16
*) pFeaturePara
;
1927 UINT32
*pFeatureReturnPara32
=(UINT32
*) pFeaturePara
;
1928 UINT32
*pFeatureData32
=(UINT32
*) pFeaturePara
;
1929 UINT32 SensorRegNumber
;
1931 PNVRAM_SENSOR_DATA_STRUCT pSensorDefaultData
=(PNVRAM_SENSOR_DATA_STRUCT
) pFeaturePara
;
1932 MSDK_SENSOR_CONFIG_STRUCT
*pSensorConfigData
=(MSDK_SENSOR_CONFIG_STRUCT
*) pFeaturePara
;
1933 MSDK_SENSOR_REG_INFO_STRUCT
*pSensorRegData
=(MSDK_SENSOR_REG_INFO_STRUCT
*) pFeaturePara
;
1934 MSDK_SENSOR_GROUP_INFO_STRUCT
*pSensorGroupInfo
=(MSDK_SENSOR_GROUP_INFO_STRUCT
*) pFeaturePara
;
1935 MSDK_SENSOR_ITEM_INFO_STRUCT
*pSensorItemInfo
=(MSDK_SENSOR_ITEM_INFO_STRUCT
*) pFeaturePara
;
1936 MSDK_SENSOR_ENG_INFO_STRUCT
*pSensorEngInfo
=(MSDK_SENSOR_ENG_INFO_STRUCT
*) pFeaturePara
;
1940 case SENSOR_FEATURE_GET_RESOLUTION
:
1941 *pFeatureReturnPara16
++= OV5670_IMAGE_SENSOR_FULL_WIDTH
;
1942 *pFeatureReturnPara16
= OV5670_IMAGE_SENSOR_FULL_HEIGHT
;
1945 case SENSOR_FEATURE_GET_PERIOD
:
1946 *pFeatureReturnPara16
++= OV5670_FeatureControl_PERIOD_PixelNum
;
1947 *pFeatureReturnPara16
= OV5670_FeatureControl_PERIOD_LineNum
;
1950 case SENSOR_FEATURE_GET_PIXEL_CLOCK_FREQ
:
1951 switch(OV5670CurrentScenarioId
)
1953 case MSDK_SCENARIO_ID_CAMERA_PREVIEW
:
1954 *pFeatureReturnPara32
= OV5670_PREVIEW_PCLK
;
1957 case MSDK_SCENARIO_ID_VIDEO_PREVIEW
:
1958 *pFeatureReturnPara32
= OV5670_VIDEO_PCLK
;
1961 case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG
:
1962 case MSDK_SCENARIO_ID_CAMERA_ZSD
:
1963 *pFeatureReturnPara32
= OV5670_CAPTURE_PCLK
;
1967 *pFeatureReturnPara32
= OV5670_PREVIEW_PCLK
;
1973 case SENSOR_FEATURE_SET_ESHUTTER
:
1974 OV5670_SetShutter(*pFeatureData16
);
1976 case SENSOR_FEATURE_SET_NIGHTMODE
:
1977 OV5670_NightMode((BOOL
) *pFeatureData16
);
1979 case SENSOR_FEATURE_SET_GAIN
:
1980 OV5670_SetGain((UINT16
) *pFeatureData16
);
1982 case SENSOR_FEATURE_SET_FLASHLIGHT
:
1984 case SENSOR_FEATURE_SET_ISP_MASTER_CLOCK_FREQ
:
1985 //OV5670_isp_master_clock=*pFeatureData32;
1987 case SENSOR_FEATURE_SET_REGISTER
:
1988 OV5670_write_cmos_sensor(pSensorRegData
->RegAddr
, pSensorRegData
->RegData
);
1990 case SENSOR_FEATURE_GET_REGISTER
:
1991 pSensorRegData
->RegData
= OV5670_read_cmos_sensor(pSensorRegData
->RegAddr
);
1993 case SENSOR_FEATURE_SET_CCT_REGISTER
:
1994 SensorRegNumber
=FACTORY_END_ADDR
;
1995 for (i
=0;i
<SensorRegNumber
;i
++)
1997 spin_lock(&ov5670mipiraw_drv_lock
);
1998 OV5670SensorCCT
[i
].Addr
=*pFeatureData32
++;
1999 OV5670SensorCCT
[i
].Para
=*pFeatureData32
++;
2000 spin_unlock(&ov5670mipiraw_drv_lock
);
2003 case SENSOR_FEATURE_GET_CCT_REGISTER
:
2004 SensorRegNumber
=FACTORY_END_ADDR
;
2005 if (*pFeatureParaLen
<(SensorRegNumber
*sizeof(SENSOR_REG_STRUCT
)+4))
2007 *pFeatureData32
++=SensorRegNumber
;
2008 for (i
=0;i
<SensorRegNumber
;i
++)
2010 *pFeatureData32
++=OV5670SensorCCT
[i
].Addr
;
2011 *pFeatureData32
++=OV5670SensorCCT
[i
].Para
;
2014 case SENSOR_FEATURE_SET_ENG_REGISTER
:
2015 SensorRegNumber
=ENGINEER_END
;
2016 for (i
=0;i
<SensorRegNumber
;i
++)
2018 spin_lock(&ov5670mipiraw_drv_lock
);
2019 OV5670SensorReg
[i
].Addr
=*pFeatureData32
++;
2020 OV5670SensorReg
[i
].Para
=*pFeatureData32
++;
2021 spin_unlock(&ov5670mipiraw_drv_lock
);
2024 case SENSOR_FEATURE_GET_ENG_REGISTER
:
2025 SensorRegNumber
=ENGINEER_END
;
2026 if (*pFeatureParaLen
<(SensorRegNumber
*sizeof(SENSOR_REG_STRUCT
)+4))
2028 *pFeatureData32
++=SensorRegNumber
;
2029 for (i
=0;i
<SensorRegNumber
;i
++)
2031 *pFeatureData32
++=OV5670SensorReg
[i
].Addr
;
2032 *pFeatureData32
++=OV5670SensorReg
[i
].Para
;
2035 case SENSOR_FEATURE_GET_REGISTER_DEFAULT
:
2036 if (*pFeatureParaLen
>=sizeof(NVRAM_SENSOR_DATA_STRUCT
))
2038 pSensorDefaultData
->Version
=NVRAM_CAMERA_SENSOR_FILE_VERSION
;
2039 pSensorDefaultData
->SensorId
=OV5670MIPI_SENSOR_ID
;
2040 memcpy(pSensorDefaultData
->SensorEngReg
, OV5670SensorReg
, sizeof(SENSOR_REG_STRUCT
)*ENGINEER_END
);
2041 memcpy(pSensorDefaultData
->SensorCCTReg
, OV5670SensorCCT
, sizeof(SENSOR_REG_STRUCT
)*FACTORY_END_ADDR
);
2045 *pFeatureParaLen
=sizeof(NVRAM_SENSOR_DATA_STRUCT
);
2047 case SENSOR_FEATURE_GET_CONFIG_PARA
:
2048 memcpy(pSensorConfigData
, &OV5670SensorConfigData
, sizeof(MSDK_SENSOR_CONFIG_STRUCT
));
2049 *pFeatureParaLen
=sizeof(MSDK_SENSOR_CONFIG_STRUCT
);
2051 case SENSOR_FEATURE_CAMERA_PARA_TO_SENSOR
:
2052 OV5670_camera_para_to_sensor();
2055 case SENSOR_FEATURE_SENSOR_TO_CAMERA_PARA
:
2056 OV5670_sensor_to_camera_para();
2058 case SENSOR_FEATURE_GET_GROUP_COUNT
:
2059 *pFeatureReturnPara32
++=OV5670_get_sensor_group_count();
2062 case SENSOR_FEATURE_GET_GROUP_INFO
:
2063 OV5670_get_sensor_group_info(pSensorGroupInfo
->GroupIdx
, pSensorGroupInfo
->GroupNamePtr
, &pSensorGroupInfo
->ItemCount
);
2064 *pFeatureParaLen
=sizeof(MSDK_SENSOR_GROUP_INFO_STRUCT
);
2066 case SENSOR_FEATURE_GET_ITEM_INFO
:
2067 OV5670_get_sensor_item_info(pSensorItemInfo
->GroupIdx
,pSensorItemInfo
->ItemIdx
, pSensorItemInfo
);
2068 *pFeatureParaLen
=sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT
);
2071 case SENSOR_FEATURE_SET_ITEM_INFO
:
2072 OV5670_set_sensor_item_info(pSensorItemInfo
->GroupIdx
, pSensorItemInfo
->ItemIdx
, pSensorItemInfo
->ItemValue
);
2073 *pFeatureParaLen
=sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT
);
2076 case SENSOR_FEATURE_GET_ENG_INFO
:
2077 pSensorEngInfo
->SensorId
= 129;
2078 pSensorEngInfo
->SensorType
= CMOS_SENSOR
;
2079 pSensorEngInfo
->SensorOutputDataFormat
=SENSOR_OUTPUT_FORMAT_RAW_B
;
2080 *pFeatureParaLen
=sizeof(MSDK_SENSOR_ENG_INFO_STRUCT
);
2082 case SENSOR_FEATURE_GET_LENS_DRIVER_ID
:
2083 // get the lens driver ID from EEPROM or just return LENS_DRIVER_ID_DO_NOT_CARE
2084 // if EEPROM does not exist in camera module.
2085 *pFeatureReturnPara32
=LENS_DRIVER_ID_DO_NOT_CARE
;
2089 case SENSOR_FEATURE_INITIALIZE_AF
:
2091 case SENSOR_FEATURE_CONSTANT_AF
:
2093 case SENSOR_FEATURE_MOVE_FOCUS_LENS
:
2095 case SENSOR_FEATURE_SET_VIDEO_MODE
:
2096 OV5670SetVideoMode(*pFeatureData16
);
2098 case SENSOR_FEATURE_CHECK_SENSOR_ID
:
2099 OV5670GetSensorID(pFeatureReturnPara32
);
2101 case SENSOR_FEATURE_SET_AUTO_FLICKER_MODE
:
2102 OV5670SetAutoFlickerMode((BOOL
)*pFeatureData16
, *(pFeatureData16
+1));
2104 case SENSOR_FEATURE_SET_MAX_FRAME_RATE_BY_SCENARIO
:
2105 OV5670MIPISetMaxFramerateByScenario((MSDK_SCENARIO_ID_ENUM
)*pFeatureData32
, *(pFeatureData32
+1));
2107 case SENSOR_FEATURE_GET_DEFAULT_FRAME_RATE_BY_SCENARIO
:
2108 OV5670MIPIGetDefaultFramerateByScenario((MSDK_SCENARIO_ID_ENUM
)*pFeatureData32
, (MUINT32
*)(*(pFeatureData32
+1)));
2110 case SENSOR_FEATURE_SET_TEST_PATTERN
:
2111 OV5670SetTestPatternMode((BOOL
)*pFeatureData16
);
2113 case SENSOR_FEATURE_GET_TEST_PATTERN_CHECKSUM_VALUE
://for factory mode auto testing
2114 *pFeatureReturnPara32
=OV5670_TEST_PATTERN_CHECKSUM
;
2117 /*SZ TCT xuejian.zhong add for CTS test */
2118 case SENSOR_FEATURE_GET_AF_MAX_NUM_FOCUS_AREAS
:
2119 OV5670GetAFMaxNumFocusAreas(pFeatureData32
);
2123 case SENSOR_FEATURE_GET_AE_MAX_NUM_METERING_AREAS
:
2124 OV5670GetAEMaxNumMeteringAreas(pFeatureData32
);
2127 case SENSOR_FEATURE_GET_EXIF_INFO
:
2128 // SENSORDB("SENSOR_FEATURE_GET_EXIF_INFO¥n");
2129 // SENSORDB("EXIF addr = 0x%x¥n",*pFeatureData32);
2131 OV5670GetExifInfo(*pFeatureData32
);
2133 /* xuejian.zhong add end */
2141 SENSOR_FUNCTION_STRUCT SensorFuncOV5670
=
2145 OV5670GetResolution
,
2146 OV5670FeatureControl
,
2151 UINT32
OV5670_MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT
*pfFunc
)
2154 *pfFunc
=&SensorFuncOV5670
;