import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / imgsensor / src / mt8127 / ov5647_raw / ov5647_Sensor_p1_25.c
1 /*****************************************************************************
2 *
3 * Filename:
4 * ---------
5 * sensor.c
6 *
7 * Project:
8 * --------
9 * RAW
10 *
11 * Description:
12 * ------------
13 * Source code of Sensor driver
14 *
15 *
16 * Author:
17 * -------
18 * HengJun (MTK70677)
19 *
20 *============================================================================
21 * HISTORY
22 * Below this line, this part is controlled by CC/CQ. DO NOT MODIFY!!
23 *------------------------------------------------------------------------------
24 * $Revision:$
25 * $Modtime:$
26 * $Log:$
27 *
28 * 09 07 2012 qihao.geng
29 * [ALPS00351342] [6577JB][Camera]HDR photo is black when set anti-flicker as 60HZ
30 * Correct the write shutter function, max_shutter = frame_length - 4 + vts_differ.
31 *
32 * 09 07 2012 qihao.geng
33 * [ALPS00351342] [6577JB][Camera]HDR photo is black when set anti-flicker as 60HZ
34 * Enlarge frame length before write shutter to make sure it can take effect
35 *
36 * 02 19 2012 koli.lin
37 * [ALPS00237113] [Performance][Video recording]Recording preview the screen have flash
38 * [Camera] 1. Modify the AE converge speed in the video mode.
39 * 2. Modify the isp gain delay frame with sensor exposure time and gain synchronization.
40 *
41 *------------------------------------------------------------------------------
42 * Upper this line, this part is controlled by CC/CQ. DO NOT MODIFY!!
43 *============================================================================
44 ****************************************************************************/
45 #warning "compile ov5647_Sensor_p1_25.c"
46
47 #include <linux/videodev2.h>
48 #include <linux/i2c.h>
49 #include <linux/platform_device.h>
50 #include <linux/delay.h>
51 #include <linux/cdev.h>
52 #include <linux/uaccess.h>
53 #include <linux/fs.h>
54 #include <asm/atomic.h>
55
56 #include "kd_camera_hw.h"
57 #include "kd_imgsensor.h"
58 #include "kd_imgsensor_define.h"
59 #include "kd_imgsensor_errcode.h"
60
61 #include "ov5647_Sensor_p1_25.h"
62 #include "ov5647_Camera_Sensor_para.h"
63 #include "ov5647_CameraCustomized.h"
64
65 MSDK_SCENARIO_ID_ENUM CurrentScenarioId = MSDK_SCENARIO_ID_CAMERA_PREVIEW;
66 static kal_bool OV5647AutoFlicKerMode = KAL_FALSE;
67
68 #define OV5647_TEST_PATTERN_CHECKSUM (0x53ba2977)
69 #define OV5647_DRIVER_TRACE
70 #define OV5647_DEBUG
71
72 #ifdef OV5647_DEBUG
73 #define SENSORDB printk
74 #else
75 #define SENSORDB(x,...)
76 #endif
77 //#define ACDK
78
79 static DEFINE_SPINLOCK(ov5647_drv_lock);
80
81 extern int iReadRegI2C(u8 *a_pSendData , u16 a_sizeSendData, u8 * a_pRecvData, u16 a_sizeRecvData, u16 i2cId);
82 extern int iWriteRegI2C(u8 *a_pSendData , u16 a_sizeSendData, u16 i2cId);
83 UINT32 OV5647SetMaxFrameRate(UINT16 u2FrameRate);
84
85
86 static OV5647_sensor_struct OV5647_sensor =
87 {
88 // .eng =
89 // {
90 // .reg = OV5647_CAMERA_SENSOR_REG_DEFAULT_VALUE,
91 // .cct = OV5647_CAMERA_SENSOR_CCT_DEFAULT_VALUE,
92 // },
93 .eng_info =
94 {
95 .SensorId = 128,
96 .SensorType = CMOS_SENSOR,
97 .SensorOutputDataFormat = OV5647_COLOR_FORMAT,
98 },
99 .shutter = 0x20,
100 .gain = 0x20,
101 .pclk = OV5647_PREVIEW_CLK,
102 .frame_height = OV5647_PV_PERIOD_LINE_NUMS,
103 .line_length = OV5647_PV_PERIOD_PIXEL_NUMS,
104 };
105
106
107 kal_uint16 OV5647_write_cmos_sensor(kal_uint32 addr, kal_uint32 para)
108 {
109 char puSendCmd[3] = {(char)(addr >> 8) , (char)(addr & 0xFF) ,(char)(para & 0xFF)};
110
111 iWriteRegI2C(puSendCmd , 3,OV5647_WRITE_ID);
112 return (kal_uint16)1;
113 }
114 kal_uint16 OV5647_read_cmos_sensor(kal_uint32 addr)
115 {
116 kal_uint16 get_byte=0;
117 char puSendCmd[2] = {(char)(addr >> 8) , (char)(addr & 0xFF) };
118 iReadRegI2C(puSendCmd , 2, (u8*)&get_byte,1,OV5647_WRITE_ID);
119 return get_byte;
120 }
121
122
123
124 static void OV5647_Write_Shutter(kal_uint16 iShutter)
125 {
126 kal_uint16 extra_line = 0;
127
128 /* 0x3500,0x3501, 0x3502 will increase VBLANK to get exposure larger than frame exposure */
129 /* AE doesn't update sensor gain at capture mode, thus extra exposure lines must be updated here. */
130 if (!iShutter) iShutter = 1; /* avoid 0 */
131
132 if(OV5647AutoFlicKerMode){
133 //Change frame 29.5fps ~ 29.8fps to do auto flick
134 if(OV5647_sensor.video_mode == KAL_FALSE){
135 OV5647SetMaxFrameRate(296);
136 }
137 }
138
139 if(iShutter > (OV5647_sensor.frame_height-4))
140 extra_line = iShutter - (OV5647_sensor.frame_height - 4);
141
142 // Update Extra shutter
143 OV5647_write_cmos_sensor(0x350c, (extra_line >> 8) & 0xFF);
144 OV5647_write_cmos_sensor(0x350d, (extra_line) & 0xFF);
145
146 //Update Shutter
147 OV5647_write_cmos_sensor(0x3500, (iShutter >> 12) & 0xF);
148 OV5647_write_cmos_sensor(0x3501, (iShutter >> 4) & 0xFF);
149 OV5647_write_cmos_sensor(0x3502, (iShutter << 4) & 0xFF);
150
151 } /* OV5647_Write_Shutter */
152
153 static void OV5647_Set_Dummy(const kal_uint16 iPixels, const kal_uint16 iLines)
154 {
155 kal_uint16 line_length, frame_height;
156
157 if (OV5647_sensor.pv_mode){
158 line_length = OV5647_PV_PERIOD_PIXEL_NUMS + iPixels;
159 frame_height = OV5647_PV_PERIOD_LINE_NUMS + iLines;
160 }else{
161 line_length = OV5647_FULL_PERIOD_PIXEL_NUMS + iPixels;
162 frame_height = OV5647_FULL_PERIOD_LINE_NUMS + iLines;
163 }
164
165 if ((line_length >= 0x1FFF)||(frame_height >= 0xFFF))
166 return ;
167
168 /* Add dummy pixels: */
169 /* 0x380c [0:4], 0x380d defines the PCLKs in one line of OV5647 */
170 /* Add dummy lines:*/
171 /* 0x380e [0:1], 0x380f defines total lines in one frame of OV5647 */
172 OV5647_write_cmos_sensor(0x380c, line_length >> 8);
173 OV5647_write_cmos_sensor(0x380d, line_length & 0xFF);
174 OV5647_write_cmos_sensor(0x380e, frame_height >> 8);
175 OV5647_write_cmos_sensor(0x380f, frame_height & 0xFF);
176
177 } /* OV5647_Set_Dummy */
178
179 /*Avoid Folat, frame rate =10 * u2FrameRate */
180 UINT32 OV5647SetMaxFrameRate(UINT16 u2FrameRate)
181 {
182 kal_int16 dummy_line;
183 kal_uint16 FrameHeight = OV5647_sensor.frame_height;
184 unsigned long flags;
185
186 printk("[soso][OV5647SetMaxFrameRate]u2FrameRate=%d",u2FrameRate);
187
188 //dummy_line = OV5647_sensor.pclk / u2FrameRate / OV5647_PV_PERIOD_PIXEL_NUMS - OV5647_PV_PERIOD_LINE_NUMS;
189 FrameHeight= (10 * OV5647_sensor.pclk) / u2FrameRate / OV5647_sensor.line_length;
190 //if(FrameHeight>OV5647_sensor.frame_height){
191 spin_lock_irqsave(&ov5647_drv_lock,flags);
192 OV5647_sensor.frame_height = FrameHeight;
193 spin_unlock_irqrestore(&ov5647_drv_lock,flags);
194 dummy_line = FrameHeight - OV5647_PV_PERIOD_LINE_NUMS;
195 /* to fix VSYNC, to fix frame rate */
196 OV5647_Set_Dummy(0, dummy_line); /* modify dummy_pixel must gen AE table again */
197 //}
198 return (UINT32)u2FrameRate;
199 }
200
201 /*************************************************************************
202 * FUNCTION
203 * OV5647_SetShutter
204 *
205 * DESCRIPTION
206 * This function set e-shutter of OV5647 to change exposure time.
207 *
208 * PARAMETERS
209 * iShutter : exposured lines
210 *
211 * RETURNS
212 * None
213 *
214 * GLOBALS AFFECTED
215 *
216 *************************************************************************/
217 void set_OV5647_shutter(kal_uint16 iShutter)
218 {
219 spin_lock(&ov5647_drv_lock);
220 OV5647_sensor.shutter = iShutter;
221 spin_unlock(&ov5647_drv_lock);
222 OV5647_Write_Shutter(iShutter);
223 } /* Set_OV5647_Shutter */
224
225 #if 0
226 static kal_uint16 OV5647Reg2Gain(const kal_uint8 iReg)
227 {
228 kal_uint16 iGain ;
229 /* Range: 1x to 32x */
230 iGain = (iReg >> 4) * BASEGAIN + (iReg & 0xF) * BASEGAIN / 16;
231 return iGain ;
232 }
233 #endif
234 kal_uint8 OV5647Gain2Reg(const kal_uint16 iGain)
235 {
236 kal_uint16 iReg = 0x00;
237 iReg = ((iGain / BASEGAIN) << 4) + ((iGain % BASEGAIN) * 16 / BASEGAIN);
238 iReg = iReg & 0xFF;
239 return (kal_uint8)iReg;
240 }
241
242 /*************************************************************************
243 * FUNCTION
244 * OV5647_SetGain
245 *
246 * DESCRIPTION
247 * This function is to set global gain to sensor.
248 *
249 * PARAMETERS
250 * iGain : sensor global gain(base: 0x40)
251 *
252 * RETURNS
253 * the actually gain set to sensor.
254 *
255 * GLOBALS AFFECTED
256 *
257 *************************************************************************/
258 kal_uint16 OV5647_SetGain(kal_uint16 iGain)
259 {
260 kal_uint8 iReg;
261 //V5647_sensor.gain = iGain;
262 /* 0x350a[0:1], 0x350b AGC real gain */
263 /* [0:3] = N meams N /16 X */
264 /* [4:9] = M meams M X */
265 /* Total gain = M + N /16 X */
266 iReg = OV5647Gain2Reg(iGain);
267 if (iReg < 0x10) iReg = 0x10;
268 //OV5647_write_cmos_sensor(0x350a, iReg);
269 OV5647_write_cmos_sensor(0x350b, iReg);
270 return iGain;
271 }
272 /*************************************************************************
273 * FUNCTION
274 * OV5647_NightMode
275 *
276 * DESCRIPTION
277 * This function night mode of OV5647.
278 *
279 * PARAMETERS
280 * bEnable: KAL_TRUE -> enable night mode, otherwise, disable night mode
281 *
282 * RETURNS
283 * None
284 *
285 * GLOBALS AFFECTED
286 *
287 *************************************************************************/
288 void OV5647_night_mode(kal_bool enable)
289 {
290 /*No Need to implement this function*/
291 #if 0
292 const kal_uint16 dummy_pixel = OV5647_sensor.line_length - OV5647_PV_PERIOD_PIXEL_NUMS;
293 const kal_uint16 pv_min_fps = enable ? OV5647_sensor.night_fps : OV5647_sensor.normal_fps;
294 kal_uint16 dummy_line = OV5647_sensor.frame_height - OV5647_PV_PERIOD_LINE_NUMS;
295 kal_uint16 max_exposure_lines;
296
297 printk("[soso][OV5647_night_mode]enable=%d",enable);
298 if (!OV5647_sensor.video_mode) return;
299 max_exposure_lines = OV5647_sensor.pclk * OV5647_FPS(1) / (pv_min_fps * OV5647_sensor.line_length);
300 if (max_exposure_lines > OV5647_sensor.frame_height) /* fix max frame rate, AE table will fix min frame rate */
301 // {
302 // dummy_line = max_exposure_lines - OV5647_PV_PERIOD_LINE_NUMS;
303 // OV5647_Set_Dummy(dummy_pixel, dummy_line);
304 // }
305 #endif
306 } /* OV5647_NightMode */
307
308
309 /* write camera_para to sensor register */
310 static void OV5647_camera_para_to_sensor(void)
311 {
312 kal_uint32 i;
313 #ifdef OV5647_DRIVER_TRACE
314 SENSORDB("OV5647_camera_para_to_sensor\n");
315 #endif
316 for (i = 0; 0xFFFFFFFF != OV5647_sensor.eng.reg[i].Addr; i++)
317 {
318 OV5647_write_cmos_sensor(OV5647_sensor.eng.reg[i].Addr, OV5647_sensor.eng.reg[i].Para);
319 }
320 for (i = OV5647_FACTORY_START_ADDR; 0xFFFFFFFF != OV5647_sensor.eng.reg[i].Addr; i++)
321 {
322 OV5647_write_cmos_sensor(OV5647_sensor.eng.reg[i].Addr, OV5647_sensor.eng.reg[i].Para);
323 }
324 OV5647_SetGain(OV5647_sensor.gain); /* update gain */
325 }
326
327 /* update camera_para from sensor register */
328 static void OV5647_sensor_to_camera_para(void)
329 {
330 kal_uint32 i,temp_data;
331 #ifdef OV5647_DRIVER_TRACE
332 SENSORDB("OV5647_sensor_to_camera_para\n");
333 #endif
334 for (i = 0; 0xFFFFFFFF != OV5647_sensor.eng.reg[i].Addr; i++)
335 {
336 temp_data = OV5647_read_cmos_sensor(OV5647_sensor.eng.reg[i].Addr);
337 spin_lock(&ov5647_drv_lock);
338 OV5647_sensor.eng.reg[i].Para = temp_data;
339 spin_unlock(&ov5647_drv_lock);
340 }
341 for (i = OV5647_FACTORY_START_ADDR; 0xFFFFFFFF != OV5647_sensor.eng.reg[i].Addr; i++)
342 {
343 temp_data = OV5647_read_cmos_sensor(OV5647_sensor.eng.reg[i].Addr);
344 spin_lock(&ov5647_drv_lock);
345 OV5647_sensor.eng.reg[i].Para = temp_data;
346 spin_unlock(&ov5647_drv_lock);
347 }
348 }
349
350 /* ------------------------ Engineer mode ------------------------ */
351 inline static void OV5647_get_sensor_group_count(kal_int32 *sensor_count_ptr)
352 {
353 #ifdef OV5647_DRIVER_TRACE
354 SENSORDB("OV5647_get_sensor_group_count\n");
355 #endif
356 *sensor_count_ptr = OV5647_GROUP_TOTAL_NUMS;
357 }
358
359 inline static void OV5647_get_sensor_group_info(MSDK_SENSOR_GROUP_INFO_STRUCT *para)
360 {
361 #ifdef OV5647_DRIVER_TRACE
362 SENSORDB("OV5647_get_sensor_group_info\n");
363 #endif
364 switch (para->GroupIdx)
365 {
366 case OV5647_PRE_GAIN:
367 sprintf(para->GroupNamePtr, "CCT");
368 para->ItemCount = 5;
369 break;
370 case OV5647_CMMCLK_CURRENT:
371 sprintf(para->GroupNamePtr, "CMMCLK Current");
372 para->ItemCount = 1;
373 break;
374 case OV5647_FRAME_RATE_LIMITATION:
375 sprintf(para->GroupNamePtr, "Frame Rate Limitation");
376 para->ItemCount = 2;
377 break;
378 case OV5647_REGISTER_EDITOR:
379 sprintf(para->GroupNamePtr, "Register Editor");
380 para->ItemCount = 2;
381 break;
382 default:
383 ASSERT(0);
384 }
385 }
386
387 inline static void OV5647_get_sensor_item_info(MSDK_SENSOR_ITEM_INFO_STRUCT *para)
388 {
389
390 const static kal_char *cct_item_name[] = {"SENSOR_BASEGAIN", "Pregain-R", "Pregain-Gr", "Pregain-Gb", "Pregain-B"};
391 const static kal_char *editer_item_name[] = {"REG addr", "REG value"};
392
393 #ifdef OV5647_DRIVER_TRACE
394 SENSORDB("OV5647_get_sensor_item_info\n");
395 #endif
396 switch (para->GroupIdx)
397 {
398 case OV5647_PRE_GAIN:
399 switch (para->ItemIdx)
400 {
401 case OV5647_SENSOR_BASEGAIN:
402 case OV5647_PRE_GAIN_R_INDEX:
403 case OV5647_PRE_GAIN_Gr_INDEX:
404 case OV5647_PRE_GAIN_Gb_INDEX:
405 case OV5647_PRE_GAIN_B_INDEX:
406 break;
407 default:
408 ASSERT(0);
409 }
410 sprintf(para->ItemNamePtr, cct_item_name[para->ItemIdx - OV5647_SENSOR_BASEGAIN]);
411 para->ItemValue = OV5647_sensor.eng.cct[para->ItemIdx].Para * 1000 / BASEGAIN;
412 para->IsTrueFalse = para->IsReadOnly = para->IsNeedRestart = KAL_FALSE;
413 para->Min = OV5647_MIN_ANALOG_GAIN * 1000;
414 para->Max = OV5647_MAX_ANALOG_GAIN * 1000;
415 break;
416 case OV5647_CMMCLK_CURRENT:
417 switch (para->ItemIdx)
418 {
419 case 0:
420 sprintf(para->ItemNamePtr, "Drv Cur[2,4,6,8]mA");
421 switch (OV5647_sensor.eng.reg[OV5647_CMMCLK_CURRENT_INDEX].Para)
422 {
423 case ISP_DRIVING_2MA:
424 para->ItemValue = 2;
425 break;
426 case ISP_DRIVING_4MA:
427 para->ItemValue = 4;
428 break;
429 case ISP_DRIVING_6MA:
430 para->ItemValue = 6;
431 break;
432 case ISP_DRIVING_8MA:
433 para->ItemValue = 8;
434 break;
435 default:
436 ASSERT(0);
437 }
438 para->IsTrueFalse = para->IsReadOnly = KAL_FALSE;
439 para->IsNeedRestart = KAL_TRUE;
440 para->Min = 2;
441 para->Max = 8;
442 break;
443 default:
444 ASSERT(0);
445 }
446 break;
447 case OV5647_FRAME_RATE_LIMITATION:
448 switch (para->ItemIdx)
449 {
450 case 0:
451 sprintf(para->ItemNamePtr, "Max Exposure Lines");
452 para->ItemValue = 5998;
453 break;
454 case 1:
455 sprintf(para->ItemNamePtr, "Min Frame Rate");
456 para->ItemValue = 5;
457 break;
458 default:
459 ASSERT(0);
460 }
461 para->IsTrueFalse = para->IsNeedRestart = KAL_FALSE;
462 para->IsReadOnly = KAL_TRUE;
463 para->Min = para->Max = 0;
464 break;
465 case OV5647_REGISTER_EDITOR:
466 switch (para->ItemIdx)
467 {
468 case 0:
469 case 1:
470 sprintf(para->ItemNamePtr, editer_item_name[para->ItemIdx]);
471 para->ItemValue = 0;
472 para->IsTrueFalse = para->IsReadOnly = para->IsNeedRestart = KAL_FALSE;
473 para->Min = 0;
474 para->Max = (para->ItemIdx == 0 ? 0xFFFF : 0xFF);
475 break;
476 default:
477 ASSERT(0);
478 }
479 break;
480 default:
481 ASSERT(0);
482 }
483 }
484
485 inline static kal_bool OV5647_set_sensor_item_info(MSDK_SENSOR_ITEM_INFO_STRUCT *para)
486 {
487 kal_uint16 temp_para;
488 #ifdef OV5647_DRIVER_TRACE
489 SENSORDB("OV5647_set_sensor_item_info\n");
490 #endif
491 switch (para->GroupIdx)
492 {
493 case OV5647_PRE_GAIN:
494 switch (para->ItemIdx)
495 {
496 case OV5647_SENSOR_BASEGAIN:
497 case OV5647_PRE_GAIN_R_INDEX:
498 case OV5647_PRE_GAIN_Gr_INDEX:
499 case OV5647_PRE_GAIN_Gb_INDEX:
500 case OV5647_PRE_GAIN_B_INDEX:
501 spin_lock(&ov5647_drv_lock);
502 OV5647_sensor.eng.cct[para->ItemIdx].Para = para->ItemValue * BASEGAIN / 1000;
503 spin_unlock(&ov5647_drv_lock);
504 OV5647_SetGain(OV5647_sensor.gain); /* update gain */
505 break;
506 default:
507 ASSERT(0);
508 }
509 break;
510 case OV5647_CMMCLK_CURRENT:
511 switch (para->ItemIdx)
512 {
513 case 0:
514 switch (para->ItemValue)
515 {
516 case 2:
517 temp_para = ISP_DRIVING_2MA;
518 break;
519 case 3:
520 case 4:
521 temp_para = ISP_DRIVING_4MA;
522 break;
523 case 5:
524 case 6:
525 temp_para = ISP_DRIVING_6MA;
526 break;
527 default:
528 temp_para = ISP_DRIVING_8MA;
529 break;
530 }
531 //OV5647_set_isp_driving_current(temp_para);
532 spin_lock(&ov5647_drv_lock);
533 OV5647_sensor.eng.reg[OV5647_CMMCLK_CURRENT_INDEX].Para = temp_para;
534 spin_unlock(&ov5647_drv_lock);
535 break;
536 default:
537 ASSERT(0);
538 }
539 break;
540 case OV5647_FRAME_RATE_LIMITATION:
541 ASSERT(0);
542 break;
543 case OV5647_REGISTER_EDITOR:
544 switch (para->ItemIdx)
545 {
546 static kal_uint32 fac_sensor_reg;
547 case 0:
548 if (para->ItemValue < 0 || para->ItemValue > 0xFFFF) return KAL_FALSE;
549 fac_sensor_reg = para->ItemValue;
550 break;
551 case 1:
552 if (para->ItemValue < 0 || para->ItemValue > 0xFF) return KAL_FALSE;
553 OV5647_write_cmos_sensor(fac_sensor_reg, para->ItemValue);
554 break;
555 default:
556 ASSERT(0);
557 }
558 break;
559 default:
560 ASSERT(0);
561 }
562 return KAL_TRUE;
563 }
564
565 static void OV5647_Sensor_Init(void)
566 {
567 OV5647_write_cmos_sensor(0x0100, 0x00);
568 OV5647_write_cmos_sensor(0x0103, 0x01);
569 mdelay(5);
570 OV5647_write_cmos_sensor(0x0100, 0x00);
571 OV5647_write_cmos_sensor(0x0100, 0x00);
572 OV5647_write_cmos_sensor(0x0100, 0x00);
573 OV5647_write_cmos_sensor(0x0100, 0x00);
574
575 OV5647_write_cmos_sensor(0x3011, 0x62);
576 OV5647_write_cmos_sensor(0x3013, 0x08);//0x04-->0x00-->0x08 Turn off internal LDO
577 OV5647_write_cmos_sensor(0x4708, 0x01);
578 OV5647_write_cmos_sensor(0x5000, 0x06);
579 OV5647_write_cmos_sensor(0x5003, 0x08);
580 OV5647_write_cmos_sensor(0x5a00, 0x08);
581 OV5647_write_cmos_sensor(0x3000, 0xff);
582 OV5647_write_cmos_sensor(0x3001, 0xff);
583 OV5647_write_cmos_sensor(0x3002, 0xff);
584 OV5647_write_cmos_sensor(0x3a18, 0x01);
585 OV5647_write_cmos_sensor(0x3a19, 0xe0);
586 OV5647_write_cmos_sensor(0x3c01, 0x80);
587 OV5647_write_cmos_sensor(0x3b07, 0x0c);
588 OV5647_write_cmos_sensor(0x3630, 0x2e);
589 OV5647_write_cmos_sensor(0x3632, 0xe2);
590 OV5647_write_cmos_sensor(0x3633, 0x23);
591 OV5647_write_cmos_sensor(0x3634, 0x44);
592 OV5647_write_cmos_sensor(0x3620, 0x64);
593 OV5647_write_cmos_sensor(0x3621, 0xe0);
594 OV5647_write_cmos_sensor(0x3600, 0x37);
595 OV5647_write_cmos_sensor(0x3704, 0xa0);
596 OV5647_write_cmos_sensor(0x3703, 0x5a);
597 OV5647_write_cmos_sensor(0x3715, 0x78);
598 OV5647_write_cmos_sensor(0x3717, 0x01);
599 OV5647_write_cmos_sensor(0x3731, 0x02);
600 OV5647_write_cmos_sensor(0x370b, 0x60);
601 OV5647_write_cmos_sensor(0x3705, 0x1a);
602 OV5647_write_cmos_sensor(0x3f05, 0x02);
603 OV5647_write_cmos_sensor(0x3f06, 0x10);
604 OV5647_write_cmos_sensor(0x3f01, 0x0a);
605 OV5647_write_cmos_sensor(0x3a08, 0x00);
606 OV5647_write_cmos_sensor(0x3a0a, 0x00);
607 OV5647_write_cmos_sensor(0x3a0f, 0x58);
608 OV5647_write_cmos_sensor(0x3a10, 0x50);
609 OV5647_write_cmos_sensor(0x3a1b, 0x58);
610 OV5647_write_cmos_sensor(0x3a1e, 0x50);
611 OV5647_write_cmos_sensor(0x3a11, 0x60);
612 OV5647_write_cmos_sensor(0x3a1f, 0x28);
613 OV5647_write_cmos_sensor(0x4001, 0x02);
614 OV5647_write_cmos_sensor(0x4000, 0x09);
615 OV5647_write_cmos_sensor(0x4003, 0x08);
616 // manual AWB,manual AE,close Lenc,open WBC
617 OV5647_write_cmos_sensor(0x3503, 0x07); //;manual AE
618 OV5647_write_cmos_sensor(0x3501, 0x3c);
619 OV5647_write_cmos_sensor(0x3502, 0x00);
620 OV5647_write_cmos_sensor(0x350a, 0x00);
621 OV5647_write_cmos_sensor(0x350b, 0x7f);
622 OV5647_write_cmos_sensor(0x5001, 0x01); //;manual AWB
623 OV5647_write_cmos_sensor(0x5180, 0x08);
624 OV5647_write_cmos_sensor(0x5186, 0x04);
625 OV5647_write_cmos_sensor(0x5187, 0x00);
626 OV5647_write_cmos_sensor(0x5188, 0x04);
627 OV5647_write_cmos_sensor(0x5189, 0x00);
628 OV5647_write_cmos_sensor(0x518a, 0x04);
629 OV5647_write_cmos_sensor(0x518b, 0x00);
630 OV5647_write_cmos_sensor(0x5000, 0x06); //;No lenc,WBC on
631
632 OV5647_write_cmos_sensor(0x3034, 0x1a); /* PLL ctrl0 */
633 OV5647_write_cmos_sensor(0x3035, 0x21); /* Debug mode */
634 OV5647_write_cmos_sensor(0x3036, 0x4a); /* 48.1M */
635 OV5647_write_cmos_sensor(0x3037, 0x02); /* PLL ctrl3 */
636
637 OV5647_write_cmos_sensor(0x3106, 0xf9);
638 OV5647_write_cmos_sensor(0x303c, 0x11); /* PLLS control2 0x12*/
639
640 #ifdef OV5647_TEST_PATTEM
641 OV5647_write_cmos_sensor(0x503D, 0x92);
642 #endif
643
644 OV5647_write_cmos_sensor(0x0100, 0x01);
645
646 } /* OV5647_Sensor_Init */ /* OV5647_Sensor_Init */
647
648
649 static void OV5647_Sensor_1M(void)
650 {
651 //-------------------------------------------------------------------------------
652 // PLL MY_OUTPUT clock(fclk)
653 // fclk = (0x40 - 0x300E[5:0]) x N x Bit8Div x MCLK / M, where
654 // N = 1, 1.5, 2, 3 for 0x300F[7:6] = 0~3, respectively
655 // M = 1, 1.5, 2, 3 for 0x300F[1:0] = 0~3, respectively
656 // Bit8Div = 1, 1, 4, 5 for 0x300F[5:4] = 0~3, respectively
657 // Sys Clk = fclk / Bit8Div / SenDiv
658 // Sensor MY_OUTPUT clock(DVP PCLK)
659 // DVP PCLK = ISP CLK / DVPDiv, where
660 // ISP CLK = fclk / Bit8Div / SenDiv / CLKDiv / 2, where
661 // Bit8Div = 1, 1, 4, 5 for 0x300F[5:4] = 0~3, respectively
662 // SenDiv = 1, 2 for 0x3010[4] = 0 or 1 repectively
663 // CLKDiv = (0x3011[5:0] + 1)
664 // DVPDiv = 0x304C[3:0] * (2 ^ 0x304C[4]), if 0x304C[3:0] = 0, use 16 instead
665 //
666 // Base shutter calculation
667 // 60Hz: (1/120) * ISP Clk / QXGA_MODE_WITHOUT_DUMMY_PIXELS
668 // 50Hz: (1/100) * ISP Clk / QXGA_MODE_WITHOUT_DUMMY_PIXELS
669 //-------------------------------------------------------------------------------
670 //26M MCLK 48.1M PCLK
671 OV5647_write_cmos_sensor(0x0100, 0x00);
672 //OV5647_write_cmos_sensor(0x4005, 0x18); // update BLC, Jason
673 //OV5647_write_cmos_sensor(0x4005, 0x1A); // update BLC, mtk70677
674 OV5647_write_cmos_sensor(0x4005, 0x18);//mtk70677,Upate BLC when gain changed
675 OV5647_write_cmos_sensor(0x4051, 0x8F);
676 #ifdef OV5647_DRIVER_TRACE
677 SENSORDB("Write Reg 0x4005 = 0x18");
678 #endif
679 //OV5647_write_cmos_sensor(0x350c, 0x00);
680 //OV5647_write_cmos_sensor(0x350d, 0x00);
681 //OV5647_write_cmos_sensor(0x3503, 0x03); //;manual AE
682 //OV5647_write_cmos_sensor(0x3035, 0x11); /* Debug mode */
683 //OV5647_write_cmos_sensor(0x3036, 0x46); /* PLL muitiplier */
684 OV5647_write_cmos_sensor(0x3821, 0x07); /* timing tc reg21 */
685 OV5647_write_cmos_sensor(0x3820, 0x41); /* timing tc reg20 */
686 OV5647_write_cmos_sensor(0x370c, 0x03); /* Reserved */
687 OV5647_write_cmos_sensor(0x3612, 0x09); /* Reserved */
688 OV5647_write_cmos_sensor(0x3618, 0x00); /* Reserved */
689 OV5647_write_cmos_sensor(0x380c, 0x07); /* TIMING HTS 0x065e */
690 OV5647_write_cmos_sensor(0x380d, 0x68); /* TIMING HTS 1630 */
691 OV5647_write_cmos_sensor(0x380e, 0x03); /* TIMING VTS 0x03d8 */
692 OV5647_write_cmos_sensor(0x380f, 0xd8); /* TIMING VTS 984 */
693 OV5647_write_cmos_sensor(0x3814, 0x31); /* TIMING X INC */
694 OV5647_write_cmos_sensor(0x3815, 0x31); /* TIMING Y INC */
695 OV5647_write_cmos_sensor(0x3708, 0x22); /* Reserved */
696 OV5647_write_cmos_sensor(0x3709, 0x52); /* Reserved */
697 OV5647_write_cmos_sensor(0x3815, 0x31); /* ??????? */
698 OV5647_write_cmos_sensor(0x3808, 0x05); /* TIMING X OUTPUT SIZE 0x0500 */
699 OV5647_write_cmos_sensor(0x3809, 0x10); /* TIMING X OUTPUT SIZE 1280 */
700 OV5647_write_cmos_sensor(0x380a, 0x03); /* TIMING Y OUTPUT SIZE 0x03c0 */
701 OV5647_write_cmos_sensor(0x380b, 0xcc); /* TIMING Y OUTPUT SIZE 960 */
702 OV5647_write_cmos_sensor(0x3800, 0x00); /* TIMING X ADDR START */
703 OV5647_write_cmos_sensor(0x3801, 0x08); /* TIMING X ADDR START */
704 OV5647_write_cmos_sensor(0x3802, 0x00); /* TIMING Y ADDR START */
705 OV5647_write_cmos_sensor(0x3803, 0x02); /* TIMING Y ADDR START */
706 OV5647_write_cmos_sensor(0x3804, 0x0a); /* TIMING X ADDR END */
707 OV5647_write_cmos_sensor(0x3805, 0x37); /* TIMING X ADDR END */
708 OV5647_write_cmos_sensor(0x3806, 0x07); /* TIMING Y ADDR END */
709 OV5647_write_cmos_sensor(0x3807, 0xa1); /* TIMING Y ADDR END */
710 OV5647_write_cmos_sensor(0x3a09, 0x27); /* B50 STEP */
711 OV5647_write_cmos_sensor(0x3a0b, 0xf6); /* B60 STEP */
712 OV5647_write_cmos_sensor(0x3a0d, 0x04); /* B60 MAX */
713 OV5647_write_cmos_sensor(0x3a0e, 0x03); /* B50 MAX */
714 OV5647_write_cmos_sensor(0x4004, 0x02); /* BLC CTRL04 */
715 //OV5647_write_cmos_sensor(0x3106, 0xf9);
716 OV5647_write_cmos_sensor(0x3a08, 0x01); /* B50 STEP */
717 OV5647_write_cmos_sensor(0x3a09, 0x27); /* ??????? */
718 OV5647_write_cmos_sensor(0x3a0a, 0x00); /* B60 STEP */
719 OV5647_write_cmos_sensor(0x3a0b, 0xf6); /* ??????? */
720 OV5647_write_cmos_sensor(0x3a0d, 0x04); /* ??????? */
721 OV5647_write_cmos_sensor(0x3a0e, 0x03); /* ??????? */
722 //OV5647_write_cmos_sensor(0x3503, 0x07); //;manual AE
723
724 #ifdef CAPTURE_15FPS
725 #if defined(__OV5647_48M__)
726 OV5647_write_cmos_sensor(0x3034, 0x1a); /* PLL ctrl0 */
727 OV5647_write_cmos_sensor(0x3035, 0x21); /* Debug mode */
728 OV5647_write_cmos_sensor(0x3036, 0x4a); /* 48.1M */
729 OV5647_write_cmos_sensor(0x3037, 0x02); /* PLL ctrl3 */
730
731 OV5647_write_cmos_sensor(0x3106, 0xf9);
732 OV5647_write_cmos_sensor(0x303c, 0x11); /* PLLS control2 0x12*/
733 #elif defined(__OV5647_52M__)
734 OV5647_write_cmos_sensor(0x3034, 0x1a); /* PLL ctrl0 */
735 OV5647_write_cmos_sensor(0x3035, 0x11); /* Debug mode */
736 OV5647_write_cmos_sensor(0x3036, 0x3D); /* 52.867M */
737 OV5647_write_cmos_sensor(0x3037, 0x03); /* PLL ctrl3 */
738
739 OV5647_write_cmos_sensor(0x3106, 0xf9);
740 OV5647_write_cmos_sensor(0x303c, 0x11); /* PLLS control2 0x12*/
741 #elif defined(__OV5647_54M__)
742 OV5647_write_cmos_sensor(0x3034, 0x1a); /* PLL ctrl0 */
743 OV5647_write_cmos_sensor(0x3035, 0x11); /* Debug mode */
744 OV5647_write_cmos_sensor(0x3036, 0x3F); /* 54.67M */
745 OV5647_write_cmos_sensor(0x3037, 0x03); /* PLL ctrl3 */
746
747 OV5647_write_cmos_sensor(0x3106, 0xf9);
748 OV5647_write_cmos_sensor(0x303c, 0x11); /* PLLS control2 0x12*/
749
750 #elif defined(__OV5647_56M__)
751 OV5647_write_cmos_sensor(0x3034, 0x1a); /* PLL ctrl0 */
752 OV5647_write_cmos_sensor(0x3035, 0x11); /* Debug mode */
753 OV5647_write_cmos_sensor(0x3036, 0x41); /* 56.333M */
754 OV5647_write_cmos_sensor(0x3037, 0x03); /* PLL ctrl3 */
755
756 OV5647_write_cmos_sensor(0x3106, 0xf9);
757 OV5647_write_cmos_sensor(0x303c, 0x11); /* PLLS control2 0x12*/
758 #endif
759 #endif
760 OV5647_write_cmos_sensor(0x0100, 0x01);
761 }
762
763 #if 0
764 static void OV5647_Sensor_5M(void)
765 {
766 OV5647_write_cmos_sensor(0x0100, 0x00);
767 //OV5647_write_cmos_sensor(0x350c, 0x00);
768 //OV5647_write_cmos_sensor(0x350d, 0x00);
769 //OV5647_write_cmos_sensor(0x3503, 0x03); //;manual AE
770 OV5647_write_cmos_sensor(0x3821, 0x06);
771 OV5647_write_cmos_sensor(0x3820, 0x00);
772 OV5647_write_cmos_sensor(0x370c, 0x00);
773 OV5647_write_cmos_sensor(0x3612, 0x0b);
774 OV5647_write_cmos_sensor(0x3618, 0x04);
775 //OV5647_write_cmos_sensor(0x380c, 0x0a); /* TIMING HTS 0x0a8c */
776 //OV5647_write_cmos_sensor(0x380d, 0x8c); /* TIMING HTS 2700 */
777 OV5647_write_cmos_sensor(0x380c, 0x0b); /* TIMING HTS 0x0bfe */
778 OV5647_write_cmos_sensor(0x380d, 0xef); /* TIMING HTS 3055 */
779 OV5647_write_cmos_sensor(0x380e, 0x07); /* TIMING VTS 0x07b0 */
780 OV5647_write_cmos_sensor(0x380f, 0xb0); /* TIMING VTS 1968 */
781 OV5647_write_cmos_sensor(0x3814, 0x11);
782 //OV5647_write_cmos_sensor(0x3815, 0x11); //0909 for test
783 OV5647_write_cmos_sensor(0x3708, 0x24);
784 OV5647_write_cmos_sensor(0x3709, 0x12);
785 OV5647_write_cmos_sensor(0x3815, 0x11);
786
787 OV5647_write_cmos_sensor(0x3808, 0x0a); /* TIMING X OUTPUT SIZE 0x0a20 */
788 OV5647_write_cmos_sensor(0x3809, 0x00); /* TIMING X OUTPUT SIZE 2592 */
789 OV5647_write_cmos_sensor(0x380a, 0x07); /* TIMING Y OUTPUT SIZE 0x0798*/
790 OV5647_write_cmos_sensor(0x380b, 0x80); /* TIMING Y OUTPUT SIZE 1944 */
791 OV5647_write_cmos_sensor(0x3800, 0x00); /* TIMING X ADDR START */
792 OV5647_write_cmos_sensor(0x3801, 0x20); /* TIMING X ADDR START */
793 OV5647_write_cmos_sensor(0x3802, 0x00); /* TIMING Y ADDR START */
794 OV5647_write_cmos_sensor(0x3803, 0x12); /* TIMING Y ADDR START */
795 OV5647_write_cmos_sensor(0x3804, 0x0a); /* TIMING X ADDR END */
796 OV5647_write_cmos_sensor(0x3805, 0x40); /* TIMING X ADDR END */
797 OV5647_write_cmos_sensor(0x3806, 0x07); /* TIMING Y ADDR END */
798 OV5647_write_cmos_sensor(0x3807, 0xa4); /* TIMING Y ADDR END */
799
800 OV5647_write_cmos_sensor(0x3a09, 0x27);
801 OV5647_write_cmos_sensor(0x3a0b, 0xf6);
802 OV5647_write_cmos_sensor(0x3a0d, 0x08);
803 OV5647_write_cmos_sensor(0x3a0e, 0x06);
804 OV5647_write_cmos_sensor(0x4004, 0x04);
805 OV5647_write_cmos_sensor(0x3a08, 0x00);
806 OV5647_write_cmos_sensor(0x3a09, 0x94);
807 OV5647_write_cmos_sensor(0x3a0a, 0x00);
808 OV5647_write_cmos_sensor(0x3a0b, 0x7b);
809 OV5647_write_cmos_sensor(0x3a0d, 0x10);
810 OV5647_write_cmos_sensor(0x3a0e, 0x0d);
811 //OV5647_write_cmos_sensor(0x3503, 0x07); //;manual AE
812 OV5647_write_cmos_sensor(0x0100, 0x01);
813 }
814 #endif
815 #ifdef CAPTURE_15FPS
816
817 static void OV5647_Sensor_5M_15fps(void)
818 {
819 //kal_uint8 iTemp1 = OV5647_read_cmos_sensor(0x3820) & 0x06;
820 //kal_uint8 iTemp2 = OV5647_read_cmos_sensor(0x3821) & 0x06;
821 OV5647_write_cmos_sensor( 0x0100, 0x00); //15fps
822 OV5647_write_cmos_sensor(0x4005, 0x1a); // update BLC, Jason
823
824 #ifdef OV5647_DRIVER_TRACE
825 SENSORDB("Write Reg 0x4005 = 0x1a");
826 #endif
827 OV5647_write_cmos_sensor( 0x303c, 0x11);
828 //OV5647_write_cmos_sensor( 0x3821, iTemp2);
829 //OV5647_write_cmos_sensor( 0x3820, iTemp1);
830 OV5647_write_cmos_sensor(0x3821, 0x07); /* timing tc reg21 */
831 OV5647_write_cmos_sensor(0x3820, 0x41); /* timing tc reg20 */
832 OV5647_write_cmos_sensor( 0x370c, 0x00);
833 OV5647_write_cmos_sensor( 0x3612, 0x0b);
834 OV5647_write_cmos_sensor( 0x3618, 0x04);
835 OV5647_write_cmos_sensor( 0x380c, 0x0a);
836 OV5647_write_cmos_sensor( 0x380d, 0x8c); //2700
837 OV5647_write_cmos_sensor( 0x380e, 0x07);
838 OV5647_write_cmos_sensor( 0x380f, 0xb0);//1968
839 OV5647_write_cmos_sensor( 0x3814, 0x11);
840 OV5647_write_cmos_sensor( 0x3815, 0x11);
841 OV5647_write_cmos_sensor( 0x3708, 0x24);
842 OV5647_write_cmos_sensor( 0x3709, 0x12);
843 OV5647_write_cmos_sensor( 0x3815, 0x11);
844
845 OV5647_write_cmos_sensor(0x3808, 0x0a); /* TIMING X OUTPUT SIZE 0x0a20 */
846 OV5647_write_cmos_sensor(0x3809, 0x20); /* TIMING X OUTPUT SIZE 2592 */
847 OV5647_write_cmos_sensor(0x380a, 0x07); /* TIMING Y OUTPUT SIZE 0x0798*/
848 OV5647_write_cmos_sensor(0x380b, 0x98); /* TIMING Y OUTPUT SIZE 1944 */
849 OV5647_write_cmos_sensor(0x3800, 0x00); /* TIMING X ADDR START */
850 OV5647_write_cmos_sensor(0x3801, 0x0c); /* TIMING X ADDR START */
851 OV5647_write_cmos_sensor(0x3802, 0x00); /* TIMING Y ADDR START */
852 OV5647_write_cmos_sensor(0x3803, 0x04); /* TIMING Y ADDR START */
853 OV5647_write_cmos_sensor(0x3804, 0x0a); /* TIMING X ADDR END */
854 OV5647_write_cmos_sensor(0x3805, 0x33); /* TIMING X ADDR END */
855 OV5647_write_cmos_sensor(0x3806, 0x07); /* TIMING Y ADDR END */
856 OV5647_write_cmos_sensor(0x3807, 0xa3); /* TIMING Y ADDR END */
857
858 OV5647_write_cmos_sensor( 0x3a09, 0x27);
859 OV5647_write_cmos_sensor( 0x3a0b, 0xf6);
860 OV5647_write_cmos_sensor( 0x3a0d, 0x08);
861 OV5647_write_cmos_sensor( 0x3a0e, 0x06);
862 OV5647_write_cmos_sensor( 0x4004, 0x04);
863 OV5647_write_cmos_sensor( 0x3034, 0x1a);
864 OV5647_write_cmos_sensor( 0x3035, 0x11);
865 OV5647_write_cmos_sensor( 0x3036, 0x3e);
866 OV5647_write_cmos_sensor( 0x3037, 0x02);
867 OV5647_write_cmos_sensor( 0x303c, 0x11);
868 OV5647_write_cmos_sensor( 0x3a08, 0x01);
869 OV5647_write_cmos_sensor( 0x3a09, 0x27);
870 OV5647_write_cmos_sensor( 0x3a0a, 0x00);
871 OV5647_write_cmos_sensor( 0x3a0b, 0xf6);
872 OV5647_write_cmos_sensor( 0x3a0d, 0x08);
873 OV5647_write_cmos_sensor( 0x3a0e, 0x06);
874 OV5647_write_cmos_sensor( 0x3503, 0x07);//soso
875 OV5647_write_cmos_sensor( 0x0100, 0x01);
876 }
877 #endif
878
879 /*****************************************************************************/
880 /* Windows Mobile Sensor Interface */
881 /*****************************************************************************/
882 /*************************************************************************
883 * FUNCTION
884 * OV5647Open
885 *
886 * DESCRIPTION
887 * This function initialize the registers of CMOS sensor
888 *
889 * PARAMETERS
890 * None
891 *
892 * RETURNS
893 * None
894 *
895 * GLOBALS AFFECTED
896 *
897 *************************************************************************/
898
899 UINT32 OV5647Open(void)
900 {
901 kal_uint16 sensor_id=0;
902
903 // check if sensor ID correct
904 sensor_id=((OV5647_read_cmos_sensor(0x300A) << 8) | OV5647_read_cmos_sensor(0x300B));
905 #ifdef OV5647_DRIVER_TRACE
906 SENSORDB("OV5647Open, sensor_id:%x \n",sensor_id);
907 #endif
908 if (sensor_id != OV5647_SENSOR_ID)
909 return ERROR_SENSOR_CONNECT_FAIL;
910
911 /* initail sequence write in */
912 OV5647_Sensor_Init();
913 spin_lock(&ov5647_drv_lock);
914 OV5647AutoFlicKerMode = KAL_FALSE;
915 OV5647_sensor.Prv_line_length = OV5647_PV_PERIOD_PIXEL_NUMS;//For ZSD
916 spin_unlock(&ov5647_drv_lock);
917 return ERROR_NONE;
918 } /* OV5647Open */
919
920 /*************************************************************************
921 * FUNCTION
922 * OV5642GetSensorID
923 *
924 * DESCRIPTION
925 * This function get the sensor ID
926 *
927 * PARAMETERS
928 * *sensorID : return the sensor ID
929 *
930 * RETURNS
931 * None
932 *
933 * GLOBALS AFFECTED
934 *
935 *************************************************************************/
936 UINT32 OV5642GetSensorID(UINT32 *sensorID)
937 {
938 // check if sensor ID correct
939 *sensorID=((OV5647_read_cmos_sensor(0x300A) << 8) | OV5647_read_cmos_sensor(0x300B));
940 #ifdef OV5647_DRIVER_TRACE
941 SENSORDB("OV5647Open, sensor_id:%x \n",*sensorID);
942 #endif
943 if (*sensorID != OV5647_SENSOR_ID) {
944 *sensorID = 0xFFFFFFFF;
945 return ERROR_SENSOR_CONNECT_FAIL;
946 }
947
948 return ERROR_NONE;
949 }
950
951 /*************************************************************************
952 * FUNCTION
953 * OV5647Close
954 *
955 * DESCRIPTION
956 * This function is to turn off sensor module power.
957 *
958 * PARAMETERS
959 * None
960 *
961 * RETURNS
962 * None
963 *
964 * GLOBALS AFFECTED
965 *
966 *************************************************************************/
967 UINT32 OV5647Close(void)
968 {
969 #ifdef OV5647_DRIVER_TRACE
970 SENSORDB("OV5647Close\n");
971 #endif
972 //CISModulePowerOn(FALSE);
973 // DRV_I2CClose(OV5647hDrvI2C);
974 return ERROR_NONE;
975 } /* OV5647Close */
976
977 /*************************************************************************
978 * FUNCTION
979 * OV5647Preview
980 *
981 * DESCRIPTION
982 * This function start the sensor preview.
983 *
984 * PARAMETERS
985 * *image_window : address pointer of pixel numbers in one period of HSYNC
986 * *sensor_config_data : address pointer of line numbers in one period of VSYNC
987 *
988 * RETURNS
989 * None
990 *
991 * GLOBALS AFFECTED
992 *
993 *************************************************************************/
994 UINT32 OV5647Preview(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
995 MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
996 {
997 kal_uint16 dummy_line;
998
999 OV5647_Sensor_1M();
1000 spin_lock(&ov5647_drv_lock);
1001 OV5647_sensor.pv_mode = KAL_TRUE;
1002
1003 //OV5647_set_mirror(sensor_config_data->SensorImageMirror);
1004 switch (sensor_config_data->SensorOperationMode)
1005 {
1006 case MSDK_SENSOR_OPERATION_MODE_VIDEO:
1007 OV5647_sensor.video_mode = KAL_TRUE;
1008 dummy_line = 0;
1009 default: /* ISP_PREVIEW_MODE */
1010 OV5647_sensor.video_mode = KAL_FALSE;
1011 dummy_line = 0;
1012 }
1013 OV5647_sensor.line_length = OV5647_PV_PERIOD_PIXEL_NUMS;
1014 OV5647_sensor.Prv_line_length=OV5647_sensor.line_length;//For Capture Funtion to calculate capture shutter
1015 OV5647_sensor.frame_height = OV5647_PV_PERIOD_LINE_NUMS+dummy_line;
1016
1017 #ifdef CAPTURE_15FPS
1018 OV5647_sensor.pclk = OV5647_PREVIEW_CLK;
1019 #endif
1020 spin_unlock(&ov5647_drv_lock);
1021 OV5647_Set_Dummy(0, dummy_line); /* modify dummy_pixel must gen AE table again */
1022 //OV5647_Write_Shutter(OV5647_sensor.shutter);
1023
1024 //printk("[soso][OV5647Preview]shutter=%x,shutter=%d\n",OV5647_sensor.shutter,OV5647_sensor.shutter);
1025 return ERROR_NONE;
1026 } /* OV5647Preview */
1027
1028 /*************************************************************************
1029 * FUNCTION
1030 * OV5647Capture
1031 *
1032 * DESCRIPTION
1033 * This function setup the CMOS sensor in capture MY_OUTPUT mode
1034 *
1035 * PARAMETERS
1036 *
1037 * RETURNS
1038 * None
1039 *
1040 * GLOBALS AFFECTED
1041 *
1042 *************************************************************************/
1043 UINT32 OV5647Capture(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
1044 MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
1045 {
1046 const kal_uint32 pv_line_length = (kal_uint32)OV5647_sensor.Prv_line_length;
1047 kal_uint32 shutter = (kal_uint32)OV5647_sensor.shutter;
1048 kal_uint16 cap_fps;
1049
1050 spin_lock(&ov5647_drv_lock);
1051 OV5647_sensor.video_mode = KAL_FALSE;
1052 OV5647AutoFlicKerMode = KAL_FALSE;
1053 spin_unlock(&ov5647_drv_lock);
1054 //if(OV5647_sensor.pv_mode == KAL_TRUE)
1055 {
1056 spin_lock(&ov5647_drv_lock);
1057 OV5647_sensor.pv_mode = KAL_FALSE;
1058 spin_unlock(&ov5647_drv_lock);
1059 #ifdef CAPTURE_15FPS
1060 OV5647_Sensor_5M_15fps();
1061 spin_lock(&ov5647_drv_lock);
1062 OV5647_sensor.pclk = 80600000;
1063 spin_unlock(&ov5647_drv_lock);
1064 cap_fps = OV5647_FPS(15);
1065
1066
1067 OV5647_Set_Dummy(0, 0);
1068 spin_lock(&ov5647_drv_lock);
1069 OV5647_sensor.line_length = OV5647_FULL_PERIOD_PIXEL_NUMS;
1070 OV5647_sensor.frame_height = OV5647_FULL_PERIOD_LINE_NUMS;
1071 spin_unlock(&ov5647_drv_lock);
1072 //806 is cpature PCLK 481 is preivew PCLK
1073 //shutter = shutter * pv_line_length * 806/OV5647_sensor.line_length/481;
1074 //shutter = shutter * (((kal_uint32)(pv_line_length * 806))/((kal_uint32)(OV5647_sensor.line_length * 481)));
1075 //shutter = shutter * (((kal_uint32)(pv_line_length * 806 ))/((kal_uint32)(OV5647_sensor.line_length * 481)));
1076 //shutter = (shutter * (((kal_uint32)(pv_line_length * 806 * 1000))/((kal_uint32)(OV5647_sensor.line_length * 481))))/1000 - 3;
1077 //shutter = shutter * (((kal_uint32)(pv_line_length * 806000))/((kal_uint32)(OV5647_sensor.line_length * 563333)));
1078 //shutter = shutter * (((kal_uint32)(pv_line_length * 806000))/((kal_uint32)(OV5647_sensor.line_length * 481000)));
1079 #if defined(__OV5647_48M__)
1080 shutter = (shutter * (((kal_uint32)(pv_line_length * 806 * 1000))/((kal_uint32)(OV5647_sensor.line_length * 481))))/1000;
1081 #elif defined(__OV5647_52M__)
1082 shutter = (shutter * (((kal_uint32)(pv_line_length * 806 * 1000))/((kal_uint32)(OV5647_sensor.line_length * 528667))));
1083 #elif defined(__OV5647_54M__)
1084 shutter = (shutter * (((kal_uint32)(pv_line_length * 806 * 1000))/((kal_uint32)(OV5647_sensor.line_length * 546))))/1000;
1085 #elif defined(__OV5647_56M__)
1086 shutter = (shutter * (((kal_uint32)(pv_line_length * 806 * 1000))/((kal_uint32)(OV5647_sensor.line_length * 563))))/1000;
1087 #endif
1088
1089
1090 #else
1091 OV5647_Sensor_5M();
1092 spin_lock(&ov5647_drv_lock);
1093 OV5647_sensor.pclk = OV5647_PREVIEW_CLK;
1094 spin_unlock(&ov5647_drv_lock);
1095
1096 cap_fps = OV5647_FPS(8);
1097 dummy_pixel = OV5647_sensor.pclk * OV5647_FPS(1) / (OV5647_FULL_PERIOD_LINE_NUMS * cap_fps);
1098 dummy_pixel = dummy_pixel < OV5647_FULL_PERIOD_PIXEL_NUMS ? 0 : dummy_pixel - OV5647_FULL_PERIOD_PIXEL_NUMS;
1099 OV5647_Set_Dummy(dummy_pixel, 0);
1100 spin_lock(&ov5647_drv_lock);
1101 OV5647_sensor.line_length = OV5647_FULL_PERIOD_PIXEL_NUMS+dummy_pixel;
1102 OV5647_sensor.frame_height = OV5647_FULL_PERIOD_LINE_NUMS;
1103 spin_unlock(&ov5647_drv_lock);
1104
1105 /* shutter translation */
1106 shutter = shutter * pv_line_length / OV5647_sensor.line_length;
1107 #endif
1108 printk("[soso][capture]shutter=%x",shutter);
1109 OV5647_Write_Shutter((kal_uint16)shutter);
1110 //mdelay(1000);
1111 }
1112 return ERROR_NONE;
1113 } /* OV5647_Capture() */
1114
1115 UINT32 OV5647GetResolution(MSDK_SENSOR_RESOLUTION_INFO_STRUCT *pSensorResolution)
1116 {
1117 pSensorResolution->SensorFullWidth=OV5647_IMAGE_SENSOR_FULL_WIDTH;
1118 pSensorResolution->SensorFullHeight=OV5647_IMAGE_SENSOR_FULL_HEIGHT;
1119 pSensorResolution->SensorPreviewWidth=OV5647_IMAGE_SENSOR_PV_WIDTH;
1120 pSensorResolution->SensorPreviewHeight=OV5647_IMAGE_SENSOR_PV_HEIGHT;
1121 pSensorResolution->SensorVideoWidth=OV5647_IMAGE_SENSOR_VIDEO_WIDTH;
1122 pSensorResolution->SensorVideoHeight=OV5647_IMAGE_SENSOR_VIDEO_HEIGHT;
1123 return ERROR_NONE;
1124 } /* OV5647GetResolution() */
1125
1126 UINT32 OV5647GetInfo(MSDK_SCENARIO_ID_ENUM ScenarioId,
1127 MSDK_SENSOR_INFO_STRUCT *pSensorInfo,
1128 MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData)
1129 {
1130 #if 0
1131 pSensorInfo->SensorPreviewResolutionX=OV5647_IMAGE_SENSOR_PV_WIDTH;
1132 pSensorInfo->SensorPreviewResolutionY=OV5647_IMAGE_SENSOR_PV_HEIGHT;
1133 pSensorInfo->SensorFullResolutionX=OV5647_IMAGE_SENSOR_FULL_WIDTH;
1134 pSensorInfo->SensorFullResolutionY=OV5647_IMAGE_SENSOR_FULL_HEIGHT;
1135 #endif
1136
1137 pSensorInfo->SensorCameraPreviewFrameRate=30;
1138 pSensorInfo->SensorVideoFrameRate=30;
1139 pSensorInfo->SensorStillCaptureFrameRate=10;
1140 pSensorInfo->SensorWebCamCaptureFrameRate=15;
1141 pSensorInfo->SensorResetActiveHigh=TRUE; //low active
1142 pSensorInfo->SensorResetDelayCount=5;
1143 pSensorInfo->SensorOutputDataFormat=OV5647_COLOR_FORMAT;
1144 pSensorInfo->SensorClockPolarity=SENSOR_CLOCK_POLARITY_LOW;
1145 pSensorInfo->SensorClockFallingPolarity=SENSOR_CLOCK_POLARITY_LOW;
1146 pSensorInfo->SensorHsyncPolarity = SENSOR_CLOCK_POLARITY_LOW;
1147 pSensorInfo->SensorVsyncPolarity = SENSOR_CLOCK_POLARITY_LOW;
1148
1149 pSensorInfo->CaptureDelayFrame = 2;
1150 pSensorInfo->PreviewDelayFrame = 1;
1151 pSensorInfo->VideoDelayFrame = 1;
1152
1153 pSensorInfo->SensorMasterClockSwitch = 0;
1154 pSensorInfo->SensorDrivingCurrent = ISP_DRIVING_2MA;
1155 pSensorInfo->AEShutDelayFrame = 0; /* The frame of setting shutter default 0 for TG int */
1156 pSensorInfo->AESensorGainDelayFrame = 0; /* The frame of setting sensor gain */
1157 pSensorInfo->AEISPGainDelayFrame = 2;
1158 switch (ScenarioId)
1159 {
1160 case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
1161 case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
1162 //case MSDK_SCENARIO_ID_VIDEO_CAPTURE_MPEG4:
1163 pSensorInfo->SensorClockFreq=26;
1164 pSensorInfo->SensorClockDividCount= 3;
1165 pSensorInfo->SensorClockRisingCount= 0;
1166 pSensorInfo->SensorClockFallingCount= 2;
1167 pSensorInfo->SensorPixelClockCount= 3;
1168 pSensorInfo->SensorDataLatchCount= 2;
1169 pSensorInfo->SensorGrabStartX = OV5647_PV_X_START;
1170 pSensorInfo->SensorGrabStartY = OV5647_PV_Y_START;
1171
1172 break;
1173 case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
1174 //case MSDK_SCENARIO_ID_CAMERA_CAPTURE_MEM:
1175 case MSDK_SCENARIO_ID_CAMERA_ZSD:
1176 pSensorInfo->SensorClockFreq=26;
1177 pSensorInfo->SensorClockDividCount= 3;
1178 pSensorInfo->SensorClockRisingCount=0;
1179 pSensorInfo->SensorClockFallingCount=2;
1180 pSensorInfo->SensorPixelClockCount=3;
1181 pSensorInfo->SensorDataLatchCount=2;
1182 pSensorInfo->SensorGrabStartX = OV5647_FULL_X_START;
1183 pSensorInfo->SensorGrabStartY = OV5647_FULL_Y_START;
1184 break;
1185 default:
1186 pSensorInfo->SensorClockFreq=26;
1187 pSensorInfo->SensorClockDividCount=3;
1188 pSensorInfo->SensorClockRisingCount=0;
1189 pSensorInfo->SensorClockFallingCount=2;
1190 pSensorInfo->SensorPixelClockCount=3;
1191 pSensorInfo->SensorDataLatchCount=2;
1192 pSensorInfo->SensorGrabStartX = OV5647_PV_X_START;
1193 pSensorInfo->SensorGrabStartY = OV5647_PV_Y_START;
1194 break;
1195 }
1196 #if 0
1197 OV5647PixelClockDivider=pSensorInfo->SensorPixelClockCount;
1198 memcpy(pSensorConfigData, &OV5647SensorConfigData, sizeof(MSDK_SENSOR_CONFIG_STRUCT));
1199 #endif
1200 return ERROR_NONE;
1201 } /* OV5647GetInfo() */
1202
1203
1204 UINT32 OV5647Control(MSDK_SCENARIO_ID_ENUM ScenarioId, MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *pImageWindow,
1205 MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData)
1206 {
1207 switch (ScenarioId)
1208 {
1209 case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
1210 case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
1211 //case MSDK_SCENARIO_ID_VIDEO_CAPTURE_MPEG4:
1212 OV5647Preview(pImageWindow, pSensorConfigData);
1213 break;
1214 case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
1215 //case MSDK_SCENARIO_ID_CAMERA_CAPTURE_MEM:
1216 case MSDK_SCENARIO_ID_CAMERA_ZSD:
1217 OV5647Capture(pImageWindow, pSensorConfigData);
1218 break;
1219 default:
1220 return ERROR_INVALID_SCENARIO_ID;
1221 }
1222
1223 return TRUE;
1224 } /* OV5647Control() */
1225
1226
1227
1228 UINT32 OV5647SetVideoMode(UINT16 u2FrameRate)
1229 {
1230 //printk("[soso][OV5647SetMaxFrameRate]u2FrameRate=%d",u2FrameRate);
1231 spin_lock(&ov5647_drv_lock);
1232
1233 if(u2FrameRate == 30){
1234 OV5647_sensor.NightMode = KAL_FALSE;
1235 }else if(u2FrameRate == 15){
1236 OV5647_sensor.NightMode = KAL_TRUE;
1237 }else if(u2FrameRate == 0){
1238 //For Dynamic frame rate,Nothing to do
1239 OV5647_sensor.video_mode = KAL_FALSE;
1240 spin_unlock(&ov5647_drv_lock);
1241 return TRUE;
1242 }else{
1243 // TODO:
1244 //return TRUE;
1245 }
1246
1247 OV5647_sensor.video_mode = KAL_TRUE;
1248 OV5647_sensor.FixedFps = u2FrameRate;
1249 spin_unlock(&ov5647_drv_lock);
1250
1251 if((u2FrameRate == 30)&&(OV5647AutoFlicKerMode==KAL_TRUE))
1252 u2FrameRate = 296;
1253 else
1254 u2FrameRate = 10 * u2FrameRate;
1255
1256 OV5647SetMaxFrameRate(u2FrameRate);
1257 OV5647_Write_Shutter(OV5647_sensor.shutter);//From Meimei Video issue
1258 return TRUE;
1259 }
1260
1261 UINT32 OV5647SetAutoFlickerMode(kal_bool bEnable, UINT16 u2FrameRate)
1262 {
1263
1264 if(bEnable){
1265 spin_lock(&ov5647_drv_lock);
1266 OV5647AutoFlicKerMode = KAL_TRUE;
1267 spin_unlock(&ov5647_drv_lock);
1268 /*Change frame rate 29.5fps to 29.8fps to do Auto flick*/
1269 if((OV5647_sensor.FixedFps == 30)&&(OV5647_sensor.video_mode==KAL_TRUE))
1270 OV5647SetMaxFrameRate(296);
1271 if((OV5647_sensor.FixedFps == 15)&&(OV5647_sensor.video_mode==KAL_TRUE))
1272 OV5647SetMaxFrameRate(148);
1273 }else{//Cancel Auto flick
1274 spin_lock(&ov5647_drv_lock);
1275 OV5647AutoFlicKerMode = KAL_FALSE;
1276 spin_unlock(&ov5647_drv_lock);
1277 if((OV5647_sensor.FixedFps == 30)&&(OV5647_sensor.video_mode==KAL_TRUE))
1278 OV5647SetMaxFrameRate(300);
1279 if((OV5647_sensor.FixedFps == 15)&&(OV5647_sensor.video_mode==KAL_TRUE))
1280 OV5647SetMaxFrameRate(150);
1281 }
1282 return TRUE;
1283 }
1284
1285 UINT32 OV5647SetTestPatternMode(kal_bool bEnable)
1286 {
1287 SENSORDB("[OV5647SetTestPatternMode] Test pattern enable:%d\n", bEnable);
1288 if(bEnable)
1289 {
1290 OV5647_write_cmos_sensor(0x503D,0x80);
1291 }
1292 else
1293 {
1294 OV5647_write_cmos_sensor(0x503D,0x00);
1295 }
1296
1297 return ERROR_NONE;
1298 }
1299
1300 UINT32 OV5647FeatureControl(MSDK_SENSOR_FEATURE_ENUM FeatureId,
1301 UINT8 *pFeaturePara,UINT32 *pFeatureParaLen)
1302 {
1303 UINT16 *pFeatureReturnPara16=(UINT16 *) pFeaturePara;
1304 UINT16 *pFeatureData16=(UINT16 *) pFeaturePara;
1305 UINT32 *pFeatureReturnPara32=(UINT32 *) pFeaturePara;
1306 // UINT32 *pFeatureData32=(UINT32 *) pFeaturePara;
1307 // UINT32 OV5647SensorRegNumber;
1308 // UINT32 i;
1309 //PNVRAM_SENSOR_DATA_STRUCT pSensorDefaultData=(PNVRAM_SENSOR_DATA_STRUCT) pFeaturePara;
1310 //MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData=(MSDK_SENSOR_CONFIG_STRUCT *) pFeaturePara;
1311 MSDK_SENSOR_REG_INFO_STRUCT *pSensorRegData=(MSDK_SENSOR_REG_INFO_STRUCT *) pFeaturePara;
1312 //MSDK_SENSOR_GROUP_INFO_STRUCT *pSensorGroupInfo=(MSDK_SENSOR_GROUP_INFO_STRUCT *) pFeaturePara;
1313 //MSDK_SENSOR_ITEM_INFO_STRUCT *pSensorItemInfo=(MSDK_SENSOR_ITEM_INFO_STRUCT *) pFeaturePara;
1314 //MSDK_SENSOR_ENG_INFO_STRUCT *pSensorEngInfo=(MSDK_SENSOR_ENG_INFO_STRUCT *) pFeaturePara;
1315
1316 switch (FeatureId)
1317 {
1318 case SENSOR_FEATURE_GET_RESOLUTION:
1319 *pFeatureReturnPara16++=OV5647_IMAGE_SENSOR_FULL_WIDTH;
1320 *pFeatureReturnPara16=OV5647_IMAGE_SENSOR_FULL_HEIGHT;
1321 *pFeatureParaLen=4;
1322 break;
1323 case SENSOR_FEATURE_GET_PERIOD: /* 3 */
1324 *pFeatureReturnPara16++=OV5647_sensor.line_length;
1325 *pFeatureReturnPara16=OV5647_sensor.frame_height;
1326 *pFeatureParaLen=4;
1327 break;
1328 case SENSOR_FEATURE_GET_PIXEL_CLOCK_FREQ: /* 3 */
1329 *pFeatureReturnPara32 = OV5647_sensor.pclk;
1330 *pFeatureParaLen=4;
1331 break;
1332 case SENSOR_FEATURE_SET_ESHUTTER: /* 4 */
1333 set_OV5647_shutter(*pFeatureData16);
1334 break;
1335 case SENSOR_FEATURE_SET_NIGHTMODE:
1336 OV5647_night_mode((BOOL) *pFeatureData16);
1337 break;
1338 case SENSOR_FEATURE_SET_GAIN: /* 6 */
1339 OV5647_SetGain((UINT16) *pFeatureData16);
1340 break;
1341 case SENSOR_FEATURE_SET_FLASHLIGHT:
1342 break;
1343 case SENSOR_FEATURE_SET_ISP_MASTER_CLOCK_FREQ:
1344 break;
1345 case SENSOR_FEATURE_SET_REGISTER:
1346 OV5647_write_cmos_sensor(pSensorRegData->RegAddr, pSensorRegData->RegData);
1347 break;
1348 case SENSOR_FEATURE_GET_REGISTER:
1349 pSensorRegData->RegData = OV5647_read_cmos_sensor(pSensorRegData->RegAddr);
1350 break;
1351 case SENSOR_FEATURE_SET_CCT_REGISTER:
1352 memcpy(&OV5647_sensor.eng.cct, pFeaturePara, sizeof(OV5647_sensor.eng.cct));
1353 break;
1354 break;
1355 case SENSOR_FEATURE_GET_CCT_REGISTER: /* 12 */
1356 if (*pFeatureParaLen >= sizeof(OV5647_sensor.eng.cct) + sizeof(kal_uint32))
1357 {
1358 *((kal_uint32 *)pFeaturePara++) = sizeof(OV5647_sensor.eng.cct);
1359 memcpy(pFeaturePara, &OV5647_sensor.eng.cct, sizeof(OV5647_sensor.eng.cct));
1360 }
1361 break;
1362 case SENSOR_FEATURE_SET_ENG_REGISTER:
1363 memcpy(&OV5647_sensor.eng.reg, pFeaturePara, sizeof(OV5647_sensor.eng.reg));
1364 break;
1365 case SENSOR_FEATURE_GET_ENG_REGISTER: /* 14 */
1366 if (*pFeatureParaLen >= sizeof(OV5647_sensor.eng.reg) + sizeof(kal_uint32))
1367 {
1368 *((kal_uint32 *)pFeaturePara++) = sizeof(OV5647_sensor.eng.reg);
1369 memcpy(pFeaturePara, &OV5647_sensor.eng.reg, sizeof(OV5647_sensor.eng.reg));
1370 }
1371 case SENSOR_FEATURE_GET_REGISTER_DEFAULT:
1372 ((PNVRAM_SENSOR_DATA_STRUCT)pFeaturePara)->Version = NVRAM_CAMERA_SENSOR_FILE_VERSION;
1373 ((PNVRAM_SENSOR_DATA_STRUCT)pFeaturePara)->SensorId = OV5647_SENSOR_ID;
1374 memcpy(((PNVRAM_SENSOR_DATA_STRUCT)pFeaturePara)->SensorEngReg, &OV5647_sensor.eng.reg, sizeof(OV5647_sensor.eng.reg));
1375 memcpy(((PNVRAM_SENSOR_DATA_STRUCT)pFeaturePara)->SensorCCTReg, &OV5647_sensor.eng.cct, sizeof(OV5647_sensor.eng.cct));
1376 *pFeatureParaLen = sizeof(NVRAM_SENSOR_DATA_STRUCT);
1377 break;
1378 case SENSOR_FEATURE_GET_CONFIG_PARA:
1379 memcpy(pFeaturePara, &OV5647_sensor.cfg_data, sizeof(OV5647_sensor.cfg_data));
1380 *pFeatureParaLen = sizeof(OV5647_sensor.cfg_data);
1381 break;
1382 case SENSOR_FEATURE_CAMERA_PARA_TO_SENSOR:
1383 OV5647_camera_para_to_sensor();
1384 break;
1385 case SENSOR_FEATURE_SENSOR_TO_CAMERA_PARA:
1386 OV5647_sensor_to_camera_para();
1387 break;
1388 case SENSOR_FEATURE_GET_GROUP_COUNT:
1389 OV5647_get_sensor_group_count((kal_uint32 *)pFeaturePara);
1390 *pFeatureParaLen = 4;
1391 break;
1392 OV5647_get_sensor_group_info((MSDK_SENSOR_GROUP_INFO_STRUCT *)pFeaturePara);
1393 *pFeatureParaLen = sizeof(MSDK_SENSOR_GROUP_INFO_STRUCT);
1394 break;
1395 case SENSOR_FEATURE_GET_ITEM_INFO:
1396 OV5647_get_sensor_item_info((MSDK_SENSOR_ITEM_INFO_STRUCT *)pFeaturePara);
1397 *pFeatureParaLen = sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT);
1398 break;
1399 case SENSOR_FEATURE_SET_ITEM_INFO:
1400 OV5647_set_sensor_item_info((MSDK_SENSOR_ITEM_INFO_STRUCT *)pFeaturePara);
1401 *pFeatureParaLen = sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT);
1402 break;
1403 case SENSOR_FEATURE_GET_ENG_INFO:
1404 memcpy(pFeaturePara, &OV5647_sensor.eng_info, sizeof(OV5647_sensor.eng_info));
1405 *pFeatureParaLen = sizeof(OV5647_sensor.eng_info);
1406 break;
1407 case SENSOR_FEATURE_GET_LENS_DRIVER_ID:
1408 // get the lens driver ID from EEPROM or just return LENS_DRIVER_ID_DO_NOT_CARE
1409 // if EEPROM does not exist in camera module.
1410 *pFeatureReturnPara32=LENS_DRIVER_ID_DO_NOT_CARE;
1411 *pFeatureParaLen=4;
1412 break;
1413 case SENSOR_FEATURE_SET_VIDEO_MODE:
1414 OV5647SetVideoMode(*pFeatureData16);
1415 break;
1416 case SENSOR_FEATURE_CHECK_SENSOR_ID:
1417 OV5642GetSensorID(pFeatureReturnPara32);
1418 break;
1419 case SENSOR_FEATURE_SET_AUTO_FLICKER_MODE:
1420 OV5647SetAutoFlickerMode((BOOL)*pFeatureData16,*(pFeatureData16+1));
1421 break;
1422 case SENSOR_FEATURE_SET_TEST_PATTERN:
1423 OV5647SetTestPatternMode((BOOL)*pFeatureData16);
1424 break;
1425 case SENSOR_FEATURE_GET_TEST_PATTERN_CHECKSUM_VALUE:
1426 *pFeatureReturnPara32= OV5647_TEST_PATTERN_CHECKSUM;
1427 *pFeatureParaLen=4;
1428 break;
1429 default:
1430 break;
1431 }
1432 return ERROR_NONE;
1433 } /* OV5647FeatureControl() */
1434 SENSOR_FUNCTION_STRUCT SensorFuncOV5647=
1435 {
1436 OV5647Open,
1437 OV5647GetInfo,
1438 OV5647GetResolution,
1439 OV5647FeatureControl,
1440 OV5647Control,
1441 OV5647Close
1442 };
1443
1444 UINT32 OV5647SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc)
1445 {
1446 /* To Do : Check Sensor status here */
1447 if (pfFunc!=NULL)
1448 *pfFunc=&SensorFuncOV5647;
1449
1450 return ERROR_NONE;
1451 } /* SensorInit() */