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