import PULS_20180308
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / imgsensor / src / mt8127 / gc2355_mipi_raw / gc2355mipi_Sensor.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 * Leo Lee
19 *
20 *============================================================================
21 * HISTORY
22 *------------------------------------------------------------------------------
23 * $Revision:$
24 * $Modtime:$
25 * $Log:$
26 *
27 * 04 10 2013
28 * First release MT6589 GC2355MIPI driver Version 1.0
29 *
30 *------------------------------------------------------------------------------
31 *============================================================================
32 ****************************************************************************/
33
34 #include <linux/videodev2.h>
35 #include <linux/i2c.h>
36 #include <linux/platform_device.h>
37 #include <linux/delay.h>
38 #include <linux/cdev.h>
39 #include <linux/uaccess.h>
40 #include <linux/fs.h>
41 #include <asm/atomic.h>
42
43 #include "kd_camera_hw.h"
44 #include "kd_imgsensor.h"
45 #include "kd_imgsensor_define.h"
46 #include "kd_imgsensor_errcode.h"
47
48 #include "gc2355mipi_Sensor.h"
49 #include "gc2355mipi_Camera_Sensor_para.h"
50 #include "gc2355mipi_CameraCustomized.h"
51
52 #ifdef GC2355MIPI_DEBUG
53 #define SENSORDB printk
54 #else
55 #define SENSORDB(x,...)
56 #endif
57
58 #define GC2355MIPI_2Lane //MIPI Lane NUM
59
60 #if defined(MT6577)||defined(MT6589)
61 static DEFINE_SPINLOCK(gc2355mipi_drv_lock);
62 #endif
63 //static kal_uint16 Half_iShutter=0;
64 static kal_bool b_Enable_Half = false;
65 extern int iReadRegI2C(u8 *a_pSendData , u16 a_sizeSendData, u8 * a_pRecvData, u16 a_sizeRecvData, u16 i2cId);
66 extern int iWriteRegI2C(u8 *a_pSendData , u16 a_sizeSendData, u16 i2cId);
67
68 /* SZ TCT xuejian.zhong add for CTS test*/
69 static void GC2355GetAFMaxNumFocusAreas(UINT32 *pFeatureReturnPara32)
70 {
71 *pFeatureReturnPara32 = 0;
72 // SENSORDB("OV2680GetAFMaxNumFocusAreas *pFeatureReturnPara32 = %d¥n", *pFeatureReturnPara32);
73 }
74
75 static void GC2355GetAEMaxNumMeteringAreas(UINT32 *pFeatureReturnPara32)
76 {
77 *pFeatureReturnPara32 = 0;
78 // SENSORDB("OV2680GetAEMaxNumMeteringAreas *pFeatureReturnPara32 = %d¥n", *pFeatureReturnPara32);
79 }
80
81 static void GC2355GetExifInfo(UINT32 exifAddr)
82 {
83 SENSOR_EXIF_INFO_STRUCT* pExifInfo = (SENSOR_EXIF_INFO_STRUCT*)exifAddr;
84 pExifInfo->FNumber = 28;
85 pExifInfo->AEISOSpeed = AE_ISO_100;
86 pExifInfo->AWBMode = AWB_MODE_AUTO;
87 pExifInfo->CapExposureTime = 0;
88 pExifInfo->FlashLightTimeus = 0;
89 pExifInfo->RealISOValue = AE_ISO_100;
90 }
91
92 /* SZ TCT xuejian.zhong end */
93
94
95
96 static GC2355MIPI_sensor_struct GC2355MIPI_sensor =
97 {
98 .eng_info =
99 {
100 .SensorId = 128,
101 .SensorType = CMOS_SENSOR,
102 .SensorOutputDataFormat = GC2355MIPI_COLOR_FORMAT,
103 },
104 .Mirror = GC2355MIPI_IMAGE_H_MIRROR,
105 .shutter = 0x20,
106 .gain = 0x20,
107 .pclk = GC2355MIPI_PREVIEW_CLK,
108 .frame_height = GC2355MIPI_PV_PERIOD_LINE_NUMS,
109 .line_length = GC2355MIPI_PV_PERIOD_PIXEL_NUMS,
110 };
111
112
113 /*************************************************************************
114 * FUNCTION
115 * GC2355MIPI_write_cmos_sensor
116 *
117 * DESCRIPTION
118 * This function wirte data to CMOS sensor through I2C
119 *
120 * PARAMETERS
121 * addr: the 16bit address of register
122 * para: the 8bit value of register
123 *
124 * RETURNS
125 * None
126 *
127 * LOCAL AFFECTED
128 *
129 *************************************************************************/
130 static void GC2355MIPI_write_cmos_sensor(kal_uint8 addr, kal_uint8 para)
131 {
132 kal_uint8 out_buff[2];
133
134 out_buff[0] = addr;
135 out_buff[1] = para;
136
137 iWriteRegI2C((u8*)out_buff , (u16)sizeof(out_buff), GC2355MIPI_WRITE_ID);
138 }
139
140 /*************************************************************************
141 * FUNCTION
142 * GC2035_read_cmos_sensor
143 *
144 * DESCRIPTION
145 * This function read data from CMOS sensor through I2C.
146 *
147 * PARAMETERS
148 * addr: the 16bit address of register
149 *
150 * RETURNS
151 * 8bit data read through I2C
152 *
153 * LOCAL AFFECTED
154 *
155 *************************************************************************/
156 static kal_uint8 GC2355MIPI_read_cmos_sensor(kal_uint8 addr)
157 {
158 kal_uint8 in_buff[1] = {0xFF};
159 kal_uint8 out_buff[1];
160
161 out_buff[0] = addr;
162
163 if (0 != iReadRegI2C((u8*)out_buff , (u16) sizeof(out_buff), (u8*)in_buff, (u16) sizeof(in_buff), GC2355MIPI_WRITE_ID)) {
164 SENSORDB("ERROR: GC2355MIPI_read_cmos_sensor \n");
165 }
166 return in_buff[0];
167 }
168
169 /*************************************************************************
170 * FUNCTION
171 * GC2355MIPI_SetShutter
172 *
173 * DESCRIPTION
174 * This function set e-shutter of GC2355MIPI to change exposure time.
175 *
176 * PARAMETERS
177 * iShutter : exposured lines
178 *
179 * RETURNS
180 * None
181 *
182 * GLOBALS AFFECTED
183 *
184 *************************************************************************/
185 void GC2355MIPI_set_shutter(kal_uint16 iShutter)
186 {
187 #if defined(MT6577)||defined(MT6589)
188 spin_lock(&gc2355mipi_drv_lock);
189 #endif
190 GC2355MIPI_sensor.shutter = iShutter;
191 #if defined(MT6577)||defined(MT6589)
192 spin_unlock(&gc2355mipi_drv_lock);
193 #endif
194
195 if (!iShutter) iShutter = 1; /* avoid 0 */
196
197 #ifdef GC2355MIPI_DRIVER_TRACE
198 SENSORDB("GC2355MIPI_set_shutter iShutter = %d \n",iShutter);
199 #endif
200 if(iShutter < 7) iShutter = 7;
201 if(iShutter > 16383) iShutter = 16383;//2^14
202 //Update Shutter
203 GC2355MIPI_write_cmos_sensor(0x04, (iShutter) & 0xFF);
204 GC2355MIPI_write_cmos_sensor(0x03, (iShutter >> 8) & 0x3F);
205 } /* Set_GC2355MIPI_Shutter */
206
207 /*************************************************************************
208 * FUNCTION
209 * GC2355MIPI_SetGain
210 *
211 * DESCRIPTION
212 * This function is to set global gain to sensor.
213 *
214 * PARAMETERS
215 * iGain : sensor global gain(base: 0x40)
216 *
217 * RETURNS
218 * the actually gain set to sensor.
219 *
220 * GLOBALS AFFECTED
221 *
222 *************************************************************************/
223 #define ANALOG_GAIN_1 64 // 1.00x
224 #define ANALOG_GAIN_2 88 // 1.375x
225 #define ANALOG_GAIN_3 122 // 1.90x
226 #define ANALOG_GAIN_4 168 // 2.625x
227 #define ANALOG_GAIN_5 239 // 3.738x
228 #define ANALOG_GAIN_6 330 // 5.163x
229 #define ANALOG_GAIN_7 470 // 7.350x
230
231 kal_uint16 GC2355MIPI_SetGain(kal_uint16 iGain)
232 {
233 kal_uint16 iReg,temp,temp1,luma_value;
234
235 #ifdef GC2355MIPI_DRIVER_TRACE
236 SENSORDB("GC2355MIPI_SetGain iGain = %d \n",iGain);
237 #endif
238 GC2355MIPI_write_cmos_sensor(0xb1, 0x01);
239 GC2355MIPI_write_cmos_sensor(0xb2, 0x00);
240
241 iReg = iGain;
242 if(iReg < 0x40)
243 iReg = 0x40;
244 if((ANALOG_GAIN_1<= iReg)&&(iReg < ANALOG_GAIN_2))
245 {
246 //analog gain
247 GC2355MIPI_write_cmos_sensor(0xb6, 0x00);//
248 temp = iReg;
249 GC2355MIPI_write_cmos_sensor(0xb1, temp>>6);
250 GC2355MIPI_write_cmos_sensor(0xb2, (temp<<2)&0xfc);
251 //SENSORDB("GC2355 analogic gain 1x , add pregain = %d\n",temp);
252
253 }
254 else if((ANALOG_GAIN_2<= iReg)&&(iReg < ANALOG_GAIN_3))
255 {
256 //analog gain
257 GC2355MIPI_write_cmos_sensor(0xb6, 0x01);//
258 temp = 64*iReg/ANALOG_GAIN_2;
259 GC2355MIPI_write_cmos_sensor(0xb1, temp>>6);
260 GC2355MIPI_write_cmos_sensor(0xb2, (temp<<2)&0xfc);
261 //SENSORDB("GC2355 analogic gain 1.375x , add pregain = %d\n",temp);
262 }
263
264 else if((ANALOG_GAIN_3<= iReg)&&(iReg < ANALOG_GAIN_4))
265 {
266 //analog gain
267 GC2355MIPI_write_cmos_sensor(0xb6, 0x02);//
268 temp = 64*iReg/ANALOG_GAIN_3;
269 GC2355MIPI_write_cmos_sensor(0xb1, temp>>6);
270 GC2355MIPI_write_cmos_sensor(0xb2, (temp<<2)&0xfc);
271 //SENSORDB("GC2355 analogic gain 1.90x , add pregain = %d\n",temp);
272 }
273
274 else if(ANALOG_GAIN_4<= iReg)
275 {
276 //analog gain
277 GC2355MIPI_write_cmos_sensor(0xb6, 0x03);//
278 temp = 64*iReg/ANALOG_GAIN_4;
279 GC2355MIPI_write_cmos_sensor(0xb1, temp>>6);
280 GC2355MIPI_write_cmos_sensor(0xb2, (temp<<2)&0xfc);
281 //SENSORDB("GC2355 analogic gain 2.625x" , add pregain = %d\n",temp);
282 }
283 /* else if((ANALOG_GAIN_4<= iReg)&&(iReg < ANALOG_GAIN_5))
284 {
285 //analog gain
286 GC2355MIPI_write_cmos_sensor(0xb6, 0x03);//
287 temp = 64*iReg/ANALOG_GAIN_4;
288 GC2355MIPI_write_cmos_sensor(0xb1, temp>>6);
289 GC2355MIPI_write_cmos_sensor(0xb2, (temp<<2)&0xfc);
290 //SENSORDB("GC2355 analogic gain 2.625x , add pregain = %d\n",temp);
291 }
292
293 else if((ANALOG_GAIN_5<= iReg)&&(iReg)&&(iReg < ANALOG_GAIN_6))
294 {
295 //analog gain
296 GC2355MIPI_write_cmos_sensor(0xb6, 0x04);//
297 temp = 64*iReg/ANALOG_GAIN_5;
298 GC2355MIPI_write_cmos_sensor(0xb1, temp>>6);
299 GC2355MIPI_write_cmos_sensor(0xb2, (temp<<2)&0xfc);
300 //SENSORDB("GC2355 analogic gain 3.738x , add pregain = %d\n",temp);
301 }
302
303 else if((ANALOG_GAIN_6<= iReg)&&(iReg < ANALOG_GAIN_7))
304 {
305 //analog gain
306 GC2355MIPI_write_cmos_sensor(0xb6, 0x05);//
307 temp = 64*iReg/ANALOG_GAIN_6;
308 GC2355MIPI_write_cmos_sensor(0xb1, temp>>6);
309 GC2355MIPI_write_cmos_sensor(0xb2, (temp<<2)&0xfc);
310 //SENSORDB("GC2355 analogic gain 5.163x , add pregain = %d\n",temp);
311 }
312 else if(ANALOG_GAIN_7<= iReg)
313 {
314 //analog gain
315 GC2355MIPI_write_cmos_sensor(0xb6, 0x06);//
316 temp = 64*iReg/ANALOG_GAIN_7;
317 GC2355MIPI_write_cmos_sensor(0xb1, temp>>6);
318 GC2355MIPI_write_cmos_sensor(0xb2, (temp<<2)&0xfc);
319 //SENSORDB("GC2355 analogic gain 7.350x" , add pregain = %d\n",temp);
320 }
321 #endif*/
322
323 return iGain;
324 }
325 /*************************************************************************
326 * FUNCTION
327 * GC2355MIPI_NightMode
328 *
329 * DESCRIPTION
330 * This function night mode of GC2355MIPI.
331 *
332 * PARAMETERS
333 * bEnable: KAL_TRUE -> enable night mode, otherwise, disable night mode
334 *
335 * RETURNS
336 * None
337 *
338 * GLOBALS AFFECTED
339 *
340 *************************************************************************/
341 void GC2355MIPI_night_mode(kal_bool enable)
342 {
343 /*No Need to implement this function*/
344 #if 0
345 const kal_uint16 dummy_pixel = GC2355MIPI_sensor.line_length - GC2355MIPI_PV_PERIOD_PIXEL_NUMS;
346 const kal_uint16 pv_min_fps = enable ? GC2355MIPI_sensor.night_fps : GC2355MIPI_sensor.normal_fps;
347 kal_uint16 dummy_line = GC2355MIPI_sensor.frame_height - GC2355MIPI_PV_PERIOD_LINE_NUMS;
348 kal_uint16 max_exposure_lines;
349
350 printk("[GC2355MIPI_night_mode]enable=%d",enable);
351 if (!GC2355MIPI_sensor.video_mode) return;
352 max_exposure_lines = GC2355MIPI_sensor.pclk * GC2355MIPI_FPS(1) / (pv_min_fps * GC2355MIPI_sensor.line_length);
353 if (max_exposure_lines > GC2355MIPI_sensor.frame_height) /* fix max frame rate, AE table will fix min frame rate */
354 // {
355 // dummy_line = max_exposure_lines - GC2355MIPI_PV_PERIOD_LINE_NUMS;
356 // }
357 #endif
358 } /* GC2355MIPI_NightMode */
359
360
361 /* write camera_para to sensor register */
362 static void GC2355MIPI_camera_para_to_sensor(void)
363 {
364 kal_uint32 i;
365 #ifdef GC2355MIPI_DRIVER_TRACE
366 SENSORDB("GC2355MIPI_camera_para_to_sensor\n");
367 #endif
368 for (i = 0; 0xFFFFFFFF != GC2355MIPI_sensor.eng.reg[i].Addr; i++)
369 {
370 GC2355MIPI_write_cmos_sensor(GC2355MIPI_sensor.eng.reg[i].Addr, GC2355MIPI_sensor.eng.reg[i].Para);
371 }
372 for (i = GC2355MIPI_FACTORY_START_ADDR; 0xFFFFFFFF != GC2355MIPI_sensor.eng.reg[i].Addr; i++)
373 {
374 GC2355MIPI_write_cmos_sensor(GC2355MIPI_sensor.eng.reg[i].Addr, GC2355MIPI_sensor.eng.reg[i].Para);
375 }
376 GC2355MIPI_SetGain(GC2355MIPI_sensor.gain); /* update gain */
377 }
378
379 /* update camera_para from sensor register */
380 static void GC2355MIPI_sensor_to_camera_para(void)
381 {
382 kal_uint32 i,temp_data;
383 #ifdef GC2355MIPI_DRIVER_TRACE
384 SENSORDB("GC2355MIPI_sensor_to_camera_para\n");
385 #endif
386 for (i = 0; 0xFFFFFFFF != GC2355MIPI_sensor.eng.reg[i].Addr; i++)
387 {
388 temp_data = GC2355MIPI_read_cmos_sensor(GC2355MIPI_sensor.eng.reg[i].Addr);
389 #if defined(MT6577)||defined(MT6589)
390 spin_lock(&gc2355mipi_drv_lock);
391 #endif
392 GC2355MIPI_sensor.eng.reg[i].Para = temp_data;
393 #if defined(MT6577)||defined(MT6589)
394 spin_unlock(&gc2355mipi_drv_lock);
395 #endif
396 }
397 for (i = GC2355MIPI_FACTORY_START_ADDR; 0xFFFFFFFF != GC2355MIPI_sensor.eng.reg[i].Addr; i++)
398 {
399 temp_data = GC2355MIPI_read_cmos_sensor(GC2355MIPI_sensor.eng.reg[i].Addr);
400 #if defined(MT6577)||defined(MT6589)
401 spin_lock(&gc2355mipi_drv_lock);
402 #endif
403 GC2355MIPI_sensor.eng.reg[i].Para = temp_data;
404 #if defined(MT6577)||defined(MT6589)
405 spin_unlock(&gc2355mipi_drv_lock);
406 #endif
407 }
408 }
409
410 /* ------------------------ Engineer mode ------------------------ */
411 inline static void GC2355MIPI_get_sensor_group_count(kal_int32 *sensor_count_ptr)
412 {
413 #ifdef GC2355MIPI_DRIVER_TRACE
414 SENSORDB("GC2355MIPI_get_sensor_group_count\n");
415 #endif
416 *sensor_count_ptr = GC2355MIPI_GROUP_TOTAL_NUMS;
417 }
418
419 inline static void GC2355MIPI_get_sensor_group_info(MSDK_SENSOR_GROUP_INFO_STRUCT *para)
420 {
421 #ifdef GC2355MIPI_DRIVER_TRACE
422 SENSORDB("GC2355MIPI_get_sensor_group_info\n");
423 #endif
424 switch (para->GroupIdx)
425 {
426 case GC2355MIPI_PRE_GAIN:
427 sprintf(para->GroupNamePtr, "CCT");
428 para->ItemCount = 5;
429 break;
430 case GC2355MIPI_CMMCLK_CURRENT:
431 sprintf(para->GroupNamePtr, "CMMCLK Current");
432 para->ItemCount = 1;
433 break;
434 case GC2355MIPI_FRAME_RATE_LIMITATION:
435 sprintf(para->GroupNamePtr, "Frame Rate Limitation");
436 para->ItemCount = 2;
437 break;
438 case GC2355MIPI_REGISTER_EDITOR:
439 sprintf(para->GroupNamePtr, "Register Editor");
440 para->ItemCount = 2;
441 break;
442 default:
443 ASSERT(0);
444 }
445 }
446
447 inline static void GC2355MIPI_get_sensor_item_info(MSDK_SENSOR_ITEM_INFO_STRUCT *para)
448 {
449
450 const static kal_char *cct_item_name[] = {"SENSOR_BASEGAIN", "Pregain-R", "Pregain-Gr", "Pregain-Gb", "Pregain-B"};
451 const static kal_char *editer_item_name[] = {"REG addr", "REG value"};
452
453 #ifdef GC2355MIPI_DRIVER_TRACE
454 SENSORDB("GC2355MIPI_get_sensor_item_info\n");
455 #endif
456 switch (para->GroupIdx)
457 {
458 case GC2355MIPI_PRE_GAIN:
459 switch (para->ItemIdx)
460 {
461 case GC2355MIPI_SENSOR_BASEGAIN:
462 case GC2355MIPI_PRE_GAIN_R_INDEX:
463 case GC2355MIPI_PRE_GAIN_Gr_INDEX:
464 case GC2355MIPI_PRE_GAIN_Gb_INDEX:
465 case GC2355MIPI_PRE_GAIN_B_INDEX:
466 break;
467 default:
468 ASSERT(0);
469 }
470 sprintf(para->ItemNamePtr, cct_item_name[para->ItemIdx - GC2355MIPI_SENSOR_BASEGAIN]);
471 para->ItemValue = GC2355MIPI_sensor.eng.cct[para->ItemIdx].Para * 1000 / BASEGAIN;
472 para->IsTrueFalse = para->IsReadOnly = para->IsNeedRestart = KAL_FALSE;
473 para->Min = GC2355MIPI_MIN_ANALOG_GAIN * 1000;
474 para->Max = GC2355MIPI_MAX_ANALOG_GAIN * 1000;
475 break;
476 case GC2355MIPI_CMMCLK_CURRENT:
477 switch (para->ItemIdx)
478 {
479 case 0:
480 sprintf(para->ItemNamePtr, "Drv Cur[2,4,6,8]mA");
481 switch (GC2355MIPI_sensor.eng.reg[GC2355MIPI_CMMCLK_CURRENT_INDEX].Para)
482 {
483 case ISP_DRIVING_2MA:
484 para->ItemValue = 2;
485 break;
486 case ISP_DRIVING_4MA:
487 para->ItemValue = 4;
488 break;
489 case ISP_DRIVING_6MA:
490 para->ItemValue = 6;
491 break;
492 case ISP_DRIVING_8MA:
493 para->ItemValue = 8;
494 break;
495 default:
496 ASSERT(0);
497 }
498 para->IsTrueFalse = para->IsReadOnly = KAL_FALSE;
499 para->IsNeedRestart = KAL_TRUE;
500 para->Min = 2;
501 para->Max = 8;
502 break;
503 default:
504 ASSERT(0);
505 }
506 break;
507 case GC2355MIPI_FRAME_RATE_LIMITATION:
508 switch (para->ItemIdx)
509 {
510 case 0:
511 sprintf(para->ItemNamePtr, "Max Exposure Lines");
512 para->ItemValue = 5998;
513 break;
514 case 1:
515 sprintf(para->ItemNamePtr, "Min Frame Rate");
516 para->ItemValue = 5;
517 break;
518 default:
519 ASSERT(0);
520 }
521 para->IsTrueFalse = para->IsNeedRestart = KAL_FALSE;
522 para->IsReadOnly = KAL_TRUE;
523 para->Min = para->Max = 0;
524 break;
525 case GC2355MIPI_REGISTER_EDITOR:
526 switch (para->ItemIdx)
527 {
528 case 0:
529 case 1:
530 sprintf(para->ItemNamePtr, editer_item_name[para->ItemIdx]);
531 para->ItemValue = 0;
532 para->IsTrueFalse = para->IsReadOnly = para->IsNeedRestart = KAL_FALSE;
533 para->Min = 0;
534 para->Max = (para->ItemIdx == 0 ? 0xFFFF : 0xFF);
535 break;
536 default:
537 ASSERT(0);
538 }
539 break;
540 default:
541 ASSERT(0);
542 }
543 }
544
545 inline static kal_bool GC2355MIPI_set_sensor_item_info(MSDK_SENSOR_ITEM_INFO_STRUCT *para)
546 {
547 kal_uint16 temp_para;
548 #ifdef GC2355MIPI_DRIVER_TRACE
549 SENSORDB("GC2355MIPI_set_sensor_item_info\n");
550 #endif
551 switch (para->GroupIdx)
552 {
553 case GC2355MIPI_PRE_GAIN:
554 switch (para->ItemIdx)
555 {
556 case GC2355MIPI_SENSOR_BASEGAIN:
557 case GC2355MIPI_PRE_GAIN_R_INDEX:
558 case GC2355MIPI_PRE_GAIN_Gr_INDEX:
559 case GC2355MIPI_PRE_GAIN_Gb_INDEX:
560 case GC2355MIPI_PRE_GAIN_B_INDEX:
561 #if defined(MT6577)||defined(MT6589)
562 spin_lock(&gc2355mipi_drv_lock);
563 #endif
564 GC2355MIPI_sensor.eng.cct[para->ItemIdx].Para = para->ItemValue * BASEGAIN / 1000;
565 #if defined(MT6577)||defined(MT6589)
566 spin_unlock(&gc2355mipi_drv_lock);
567 #endif
568 GC2355MIPI_SetGain(GC2355MIPI_sensor.gain); /* update gain */
569 break;
570 default:
571 ASSERT(0);
572 }
573 break;
574 case GC2355MIPI_CMMCLK_CURRENT:
575 switch (para->ItemIdx)
576 {
577 case 0:
578 switch (para->ItemValue)
579 {
580 case 2:
581 temp_para = ISP_DRIVING_2MA;
582 break;
583 case 3:
584 case 4:
585 temp_para = ISP_DRIVING_4MA;
586 break;
587 case 5:
588 case 6:
589 temp_para = ISP_DRIVING_6MA;
590 break;
591 default:
592 temp_para = ISP_DRIVING_8MA;
593 break;
594 }
595 //GC2355MIPI_set_isp_driving_current(temp_para);
596 #if defined(MT6577)||defined(MT6589)
597 spin_lock(&gc2355mipi_drv_lock);
598 #endif
599 GC2355MIPI_sensor.eng.reg[GC2355MIPI_CMMCLK_CURRENT_INDEX].Para = temp_para;
600 #if defined(MT6577)||defined(MT6589)
601 spin_unlock(&gc2355mipi_drv_lock);
602 #endif
603 break;
604 default:
605 ASSERT(0);
606 }
607 break;
608 case GC2355MIPI_FRAME_RATE_LIMITATION:
609 ASSERT(0);
610 break;
611 case GC2355MIPI_REGISTER_EDITOR:
612 switch (para->ItemIdx)
613 {
614 static kal_uint32 fac_sensor_reg;
615 case 0:
616 if (para->ItemValue < 0 || para->ItemValue > 0xFFFF) return KAL_FALSE;
617 fac_sensor_reg = para->ItemValue;
618 break;
619 case 1:
620 if (para->ItemValue < 0 || para->ItemValue > 0xFF) return KAL_FALSE;
621 GC2355MIPI_write_cmos_sensor(fac_sensor_reg, para->ItemValue);
622 break;
623 default:
624 ASSERT(0);
625 }
626 break;
627 default:
628 ASSERT(0);
629 }
630 return KAL_TRUE;
631 }
632
633 void GC2355MIPI_SetMirrorFlip(GC2355MIPI_IMAGE_MIRROR Mirror)
634 {
635 /* switch(Mirror)
636 {
637 case GC2355MIPI_IMAGE_NORMAL://IMAGE_NORMAL:
638 GC2355MIPI_write_cmos_sensor(0x17,0x14);
639 GC2355MIPI_write_cmos_sensor(0x92,0x01);
640 GC2355MIPI_write_cmos_sensor(0x94,0x01);
641 break;
642 case GC2355MIPI_IMAGE_H_MIRROR://IMAGE_H_MIRROR:
643 GC2355MIPI_write_cmos_sensor(0x17,0x15);
644 GC2355MIPI_write_cmos_sensor(0x92,0x01);
645 GC2355MIPI_write_cmos_sensor(0x94,0x00);
646 break;
647 case GC2355MIPI_IMAGE_V_MIRROR://IMAGE_V_MIRROR:
648 GC2355MIPI_write_cmos_sensor(0x17,0x16);
649 GC2355MIPI_write_cmos_sensor(0x92,0x02);
650 GC2355MIPI_write_cmos_sensor(0x94,0x01);
651 break;
652 case GC2355MIPI_IMAGE_HV_MIRROR://IMAGE_HV_MIRROR:
653 GC2355MIPI_write_cmos_sensor(0x17,0x17);
654 GC2355MIPI_write_cmos_sensor(0x92,0x02);
655 GC2355MIPI_write_cmos_sensor(0x94,0x00);
656 break;
657 }*/
658 }
659
660 static void GC2355MIPI_Sensor_Init(void)
661 {
662 /////////////////////////////////////////////////////
663 ////////////////////// SYS //////////////////////
664 /////////////////////////////////////////////////////
665 GC2355MIPI_write_cmos_sensor(0xfe,0x80);
666 GC2355MIPI_write_cmos_sensor(0xfe,0x80);
667 GC2355MIPI_write_cmos_sensor(0xfe,0x80);
668 GC2355MIPI_write_cmos_sensor(0xf2,0x00);
669 GC2355MIPI_write_cmos_sensor(0xf6,0x00);
670 #if defined(GC2355MIPI_2Lane)
671 GC2355MIPI_write_cmos_sensor(0xf7,0x31);
672 #else
673 GC2355MIPI_write_cmos_sensor(0xf7,0x19);
674 #endif
675 GC2355MIPI_write_cmos_sensor(0xf8,0x06);
676 GC2355MIPI_write_cmos_sensor(0xf9,0x0e);
677 GC2355MIPI_write_cmos_sensor(0xfa,0x00);
678 GC2355MIPI_write_cmos_sensor(0xfc,0x06);
679 GC2355MIPI_write_cmos_sensor(0xfe,0x00);
680
681 /////////////////////////////////////////////////////
682 /////////////// ANALOG & CISCTL ///////////////
683 /////////////////////////////////////////////////////
684 GC2355MIPI_write_cmos_sensor(0x03,0x07);
685 GC2355MIPI_write_cmos_sensor(0x04,0xd0);
686 GC2355MIPI_write_cmos_sensor(0x05,0x03);
687 GC2355MIPI_write_cmos_sensor(0x06,0x4c);
688 GC2355MIPI_write_cmos_sensor(0x07,0x00);
689 GC2355MIPI_write_cmos_sensor(0x08,0x12);
690 GC2355MIPI_write_cmos_sensor(0x0a,0x00);
691 GC2355MIPI_write_cmos_sensor(0x0c,0x04);
692 GC2355MIPI_write_cmos_sensor(0x0d,0x04);
693 GC2355MIPI_write_cmos_sensor(0x0e,0xc0);
694 GC2355MIPI_write_cmos_sensor(0x0f,0x06);
695 GC2355MIPI_write_cmos_sensor(0x10,0x50);
696 GC2355MIPI_write_cmos_sensor(0x17,0x17);
697 GC2355MIPI_write_cmos_sensor(0x19,0x0b);
698 GC2355MIPI_write_cmos_sensor(0x1b,0x48);
699 GC2355MIPI_write_cmos_sensor(0x1c,0x12);
700 GC2355MIPI_write_cmos_sensor(0x1d,0x10);
701 GC2355MIPI_write_cmos_sensor(0x1e,0xbc);
702 GC2355MIPI_write_cmos_sensor(0x1f,0xc9);
703 GC2355MIPI_write_cmos_sensor(0x20,0x71);
704 GC2355MIPI_write_cmos_sensor(0x21,0x20);
705 GC2355MIPI_write_cmos_sensor(0x22,0xa0);
706 GC2355MIPI_write_cmos_sensor(0x23,0x51);
707 GC2355MIPI_write_cmos_sensor(0x24,0x19);
708 GC2355MIPI_write_cmos_sensor(0x27,0x20);
709 GC2355MIPI_write_cmos_sensor(0x28,0x00);
710 GC2355MIPI_write_cmos_sensor(0x2b,0x80);// 0x81 20140926
711 GC2355MIPI_write_cmos_sensor(0x2c,0x38);
712 GC2355MIPI_write_cmos_sensor(0x2e,0x16);
713 GC2355MIPI_write_cmos_sensor(0x2f,0x14);
714 GC2355MIPI_write_cmos_sensor(0x30,0x00);
715 GC2355MIPI_write_cmos_sensor(0x31,0x01);
716 GC2355MIPI_write_cmos_sensor(0x32,0x02);
717 GC2355MIPI_write_cmos_sensor(0x33,0x03);
718 GC2355MIPI_write_cmos_sensor(0x34,0x07);
719 GC2355MIPI_write_cmos_sensor(0x35,0x0b);
720 GC2355MIPI_write_cmos_sensor(0x36,0x0f);
721
722 /////////////////////////////////////////////////////
723 ////////////////////// MIPI /////////////////////
724 /////////////////////////////////////////////////////
725 GC2355MIPI_write_cmos_sensor(0xfe, 0x03);
726 #if defined(GC2355MIPI_2Lane)
727 GC2355MIPI_write_cmos_sensor(0x10, 0x81);
728 GC2355MIPI_write_cmos_sensor(0x01, 0x87);
729 GC2355MIPI_write_cmos_sensor(0x22, 0x03);
730 GC2355MIPI_write_cmos_sensor(0x23, 0x20);
731 GC2355MIPI_write_cmos_sensor(0x25, 0x10);
732 GC2355MIPI_write_cmos_sensor(0x29, 0x02);
733 #else
734 GC2355MIPI_write_cmos_sensor(0x10, 0x80);
735 GC2355MIPI_write_cmos_sensor(0x01, 0x83);
736 GC2355MIPI_write_cmos_sensor(0x22, 0x05);
737 GC2355MIPI_write_cmos_sensor(0x23, 0x30);
738 GC2355MIPI_write_cmos_sensor(0x25, 0x15);
739 GC2355MIPI_write_cmos_sensor(0x29, 0x06);
740 #endif
741 GC2355MIPI_write_cmos_sensor(0x02, 0x00);
742 GC2355MIPI_write_cmos_sensor(0x03, 0x90);
743 GC2355MIPI_write_cmos_sensor(0x04, 0x01);
744 GC2355MIPI_write_cmos_sensor(0x05, 0x00);
745 GC2355MIPI_write_cmos_sensor(0x06, 0xa2);
746 GC2355MIPI_write_cmos_sensor(0x11, 0x2b);
747 GC2355MIPI_write_cmos_sensor(0x12, 0xd0);
748 GC2355MIPI_write_cmos_sensor(0x13, 0x07);
749 GC2355MIPI_write_cmos_sensor(0x15, 0x60);
750
751 GC2355MIPI_write_cmos_sensor(0x21, 0x10);
752 GC2355MIPI_write_cmos_sensor(0x24, 0x02);
753 GC2355MIPI_write_cmos_sensor(0x26, 0x08);
754 GC2355MIPI_write_cmos_sensor(0x27, 0x06);
755 GC2355MIPI_write_cmos_sensor(0x2a, 0x0a);
756 GC2355MIPI_write_cmos_sensor(0x2b, 0x08);
757
758 GC2355MIPI_write_cmos_sensor(0x40, 0x00);
759 GC2355MIPI_write_cmos_sensor(0x41, 0x00);
760 GC2355MIPI_write_cmos_sensor(0x42, 0x40);
761 GC2355MIPI_write_cmos_sensor(0x43, 0x06);
762 GC2355MIPI_write_cmos_sensor(0xfe, 0x00);
763
764 /////////////////////////////////////////////////////
765 ////////////////////// gain /////////////////////
766 /////////////////////////////////////////////////////
767 GC2355MIPI_write_cmos_sensor(0xb0,0x50);
768 GC2355MIPI_write_cmos_sensor(0xb1,0x01);
769 GC2355MIPI_write_cmos_sensor(0xb2,0x00);
770 GC2355MIPI_write_cmos_sensor(0xb3,0x40);
771 GC2355MIPI_write_cmos_sensor(0xb4,0x40);
772 GC2355MIPI_write_cmos_sensor(0xb5,0x40);
773 GC2355MIPI_write_cmos_sensor(0xb6,0x00);
774
775 /////////////////////////////////////////////////////
776 ////////////////////// crop /////////////////////
777 /////////////////////////////////////////////////////
778 GC2355MIPI_write_cmos_sensor(0x92,0x02);
779 GC2355MIPI_write_cmos_sensor(0x94,0x00);
780 GC2355MIPI_write_cmos_sensor(0x95,0x04);
781 GC2355MIPI_write_cmos_sensor(0x96,0xb0);
782 GC2355MIPI_write_cmos_sensor(0x97,0x06);
783 GC2355MIPI_write_cmos_sensor(0x98,0x40);
784
785 /////////////////////////////////////////////////////
786 ////////////////////// BLK /////////////////////
787 /////////////////////////////////////////////////////
788 GC2355MIPI_write_cmos_sensor(0x18,0x02);
789 GC2355MIPI_write_cmos_sensor(0x1a,0x01);
790 GC2355MIPI_write_cmos_sensor(0x40,0x42);
791 GC2355MIPI_write_cmos_sensor(0x41,0x00);
792 GC2355MIPI_write_cmos_sensor(0x44,0x00);
793 GC2355MIPI_write_cmos_sensor(0x45,0x00);
794 GC2355MIPI_write_cmos_sensor(0x46,0x00);
795 GC2355MIPI_write_cmos_sensor(0x47,0x00);
796 GC2355MIPI_write_cmos_sensor(0x48,0x00);
797 GC2355MIPI_write_cmos_sensor(0x49,0x00);
798 GC2355MIPI_write_cmos_sensor(0x4a,0x00);
799 GC2355MIPI_write_cmos_sensor(0x4b,0x00);
800 GC2355MIPI_write_cmos_sensor(0x4e,0x3c);
801 GC2355MIPI_write_cmos_sensor(0x4f,0x00);
802 GC2355MIPI_write_cmos_sensor(0x5e,0x00);
803 GC2355MIPI_write_cmos_sensor(0x66,0x20);
804 GC2355MIPI_write_cmos_sensor(0x6a,0x02);
805 GC2355MIPI_write_cmos_sensor(0x6b,0x02);
806 GC2355MIPI_write_cmos_sensor(0x6c,0x02);
807 GC2355MIPI_write_cmos_sensor(0x6d,0x02);
808 GC2355MIPI_write_cmos_sensor(0x6e,0x02);
809 GC2355MIPI_write_cmos_sensor(0x6f,0x02);
810 GC2355MIPI_write_cmos_sensor(0x70,0x02);
811 GC2355MIPI_write_cmos_sensor(0x71,0x02);
812
813 /////////////////////////////////////////////////////
814 //////////////////// dark sun /////////////////////
815 /////////////////////////////////////////////////////
816 GC2355MIPI_write_cmos_sensor(0x87,0x03);
817 GC2355MIPI_write_cmos_sensor(0xe0,0xe7);
818 GC2355MIPI_write_cmos_sensor(0xe3,0xc0);
819
820 /////////////////////////////////////////////////////
821 ////////////////////// MIPI /////////////////////
822 /////////////////////////////////////////////////////
823 GC2355MIPI_write_cmos_sensor(0xfe, 0x03);
824 #if defined(GC2355MIPI_2Lane)
825 GC2355MIPI_write_cmos_sensor(0x10, 0x91);
826 #else
827 GC2355MIPI_write_cmos_sensor(0x10, 0x90);
828 #endif
829 GC2355MIPI_write_cmos_sensor(0xfe, 0x00);
830
831 } /* GC2355MIPI_Sensor_Init */
832
833 /*****************************************************************************/
834 /* Windows Mobile Sensor Interface */
835 /*****************************************************************************/
836 /*************************************************************************
837 * FUNCTION
838 * GC2355MIPIOpen
839 *
840 * DESCRIPTION
841 * This function initialize the registers of CMOS sensor
842 *
843 * PARAMETERS
844 * None
845 *
846 * RETURNS
847 * None
848 *
849 * GLOBALS AFFECTED
850 *
851 *************************************************************************/
852
853 UINT32 GC2355MIPIOpen(void)
854 {
855 kal_uint16 sensor_id=0;
856
857 // check if sensor ID correct
858 sensor_id=((GC2355MIPI_read_cmos_sensor(0xf0) << 8) | GC2355MIPI_read_cmos_sensor(0xf1));
859 #ifdef GC2355MIPI_DRIVER_TRACE
860 SENSORDB("GC2355MIPIOpen, sensor_id:%x \n",sensor_id);
861 #endif
862 if (sensor_id != GC2355MIPI_SENSOR_ID)
863 return ERROR_SENSOR_CONNECT_FAIL;
864
865 /* initail sequence write in */
866 GC2355MIPI_Sensor_Init();
867
868 // GC2355MIPI_SetMirrorFlip(GC2355MIPI_sensor.Mirror);
869
870 return ERROR_NONE;
871 } /* GC2355MIPIOpen */
872
873 /*************************************************************************
874 * FUNCTION
875 * GC2355MIPIGetSensorID
876 *
877 * DESCRIPTION
878 * This function get the sensor ID
879 *
880 * PARAMETERS
881 * *sensorID : return the sensor ID
882 *
883 * RETURNS
884 * None
885 *
886 * GLOBALS AFFECTED
887 *
888 *************************************************************************/
889 UINT32 GC2355MIPIGetSensorID(UINT32 *sensorID)
890 {
891 // check if sensor ID correct
892 *sensorID=((GC2355MIPI_read_cmos_sensor(0xf0) << 8) | GC2355MIPI_read_cmos_sensor(0xf1));
893 #ifdef GC2355MIPI_DRIVER_TRACE
894 SENSORDB("GC2355MIPIGetSensorID:%x \n",*sensorID);
895 #endif
896 if (*sensorID != GC2355MIPI_SENSOR_ID) {
897 *sensorID = 0xFFFFFFFF;
898 return ERROR_SENSOR_CONNECT_FAIL;
899 }
900 return ERROR_NONE;
901 }
902
903 /*************************************************************************
904 * FUNCTION
905 * GC2355MIPIClose
906 *
907 * DESCRIPTION
908 * This function is to turn off sensor module power.
909 *
910 * PARAMETERS
911 * None
912 *
913 * RETURNS
914 * None
915 *
916 * GLOBALS AFFECTED
917 *
918 *************************************************************************/
919 UINT32 GC2355MIPIClose(void)
920 {
921 #ifdef GC2355MIPI_DRIVER_TRACE
922 SENSORDB("GC2355MIPIClose\n");
923 #endif
924 //kdCISModulePowerOn(SensorIdx,currSensorName,0,mode_name);
925 // DRV_I2CClose(GC2355MIPIhDrvI2C);
926 return ERROR_NONE;
927 } /* GC2355MIPIClose */
928
929 /*************************************************************************
930 * FUNCTION
931 * GC2355MIPIPreview
932 *
933 * DESCRIPTION
934 * This function start the sensor preview.
935 *
936 * PARAMETERS
937 * *image_window : address pointer of pixel numbers in one period of HSYNC
938 * *sensor_config_data : address pointer of line numbers in one period of VSYNC
939 *
940 * RETURNS
941 * None
942 *
943 * GLOBALS AFFECTED
944 *
945 *************************************************************************/
946 UINT32 GC2355MIPIPreview(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
947 MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
948 {
949
950 #if defined(MT6577)||defined(MT6589)
951 spin_lock(&gc2355mipi_drv_lock);
952 #endif
953 GC2355MIPI_sensor.pv_mode = KAL_TRUE;
954
955 //GC2355MIPI_set_mirror(sensor_config_data->SensorImageMirror);
956 switch (sensor_config_data->SensorOperationMode)
957 {
958 case MSDK_SENSOR_OPERATION_MODE_VIDEO:
959 GC2355MIPI_sensor.video_mode = KAL_TRUE;
960 default: /* ISP_PREVIEW_MODE */
961 GC2355MIPI_sensor.video_mode = KAL_FALSE;
962 }
963 GC2355MIPI_sensor.line_length = GC2355MIPI_PV_PERIOD_PIXEL_NUMS;
964 GC2355MIPI_sensor.frame_height = GC2355MIPI_PV_PERIOD_LINE_NUMS;
965 GC2355MIPI_sensor.pclk = GC2355MIPI_PREVIEW_CLK;
966 #if defined(MT6577)||defined(MT6589)
967 spin_unlock(&gc2355mipi_drv_lock);
968 #endif
969 //GC2355MIPI_Write_Shutter(GC2355MIPI_sensor.shutter);
970 return ERROR_NONE;
971 } /* GC2355MIPIPreview */
972
973 /*************************************************************************
974 * FUNCTION
975 * GC2355MIPICapture
976 *
977 * DESCRIPTION
978 * This function setup the CMOS sensor in capture MY_OUTPUT mode
979 *
980 * PARAMETERS
981 *
982 * RETURNS
983 * None
984 *
985 * GLOBALS AFFECTED
986 *
987 *************************************************************************/
988 UINT32 GC2355MIPICapture(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
989 MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
990 {
991 kal_uint32 shutter = (kal_uint32)GC2355MIPI_sensor.shutter;
992 #if defined(MT6577)||defined(MT6589)
993 spin_lock(&gc2355mipi_drv_lock);
994 #endif
995 GC2355MIPI_sensor.video_mode = KAL_FALSE;
996 GC2355MIPI_sensor.pv_mode = KAL_FALSE;
997 #if defined(MT6577)||defined(MT6589)
998 spin_unlock(&gc2355mipi_drv_lock);
999 #endif
1000 return ERROR_NONE;
1001 } /* GC2355MIPI_Capture() */
1002
1003 UINT32 GC2355MIPIGetResolution(MSDK_SENSOR_RESOLUTION_INFO_STRUCT *pSensorResolution)
1004 {
1005 pSensorResolution->SensorFullWidth=GC2355MIPI_IMAGE_SENSOR_FULL_WIDTH;
1006 pSensorResolution->SensorFullHeight=GC2355MIPI_IMAGE_SENSOR_FULL_HEIGHT;
1007 pSensorResolution->SensorPreviewWidth=GC2355MIPI_IMAGE_SENSOR_PV_WIDTH;
1008 pSensorResolution->SensorPreviewHeight=GC2355MIPI_IMAGE_SENSOR_PV_HEIGHT;
1009 pSensorResolution->SensorVideoWidth=GC2355MIPI_IMAGE_SENSOR_VIDEO_WIDTH;
1010 pSensorResolution->SensorVideoHeight=GC2355MIPI_IMAGE_SENSOR_VIDEO_HEIGHT;
1011 return ERROR_NONE;
1012 } /* GC2355MIPIGetResolution() */
1013
1014 UINT32 GC2355MIPIGetInfo(MSDK_SCENARIO_ID_ENUM ScenarioId,
1015 MSDK_SENSOR_INFO_STRUCT *pSensorInfo,
1016 MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData)
1017 {
1018 pSensorInfo->SensorPreviewResolutionX=GC2355MIPI_IMAGE_SENSOR_PV_WIDTH;
1019 pSensorInfo->SensorPreviewResolutionY=GC2355MIPI_IMAGE_SENSOR_PV_HEIGHT;
1020 pSensorInfo->SensorFullResolutionX=GC2355MIPI_IMAGE_SENSOR_FULL_WIDTH;
1021 pSensorInfo->SensorFullResolutionY=GC2355MIPI_IMAGE_SENSOR_FULL_HEIGHT;
1022
1023 pSensorInfo->SensorCameraPreviewFrameRate=30;
1024 pSensorInfo->SensorVideoFrameRate=30;
1025 pSensorInfo->SensorStillCaptureFrameRate=10;
1026 pSensorInfo->SensorWebCamCaptureFrameRate=15;
1027 pSensorInfo->SensorResetActiveHigh=TRUE; //low active
1028 pSensorInfo->SensorResetDelayCount=5;
1029 pSensorInfo->SensorOutputDataFormat=GC2355MIPI_COLOR_FORMAT;
1030 pSensorInfo->SensorClockPolarity=SENSOR_CLOCK_POLARITY_LOW;
1031 pSensorInfo->SensorClockFallingPolarity=SENSOR_CLOCK_POLARITY_LOW;
1032 pSensorInfo->SensorHsyncPolarity = SENSOR_CLOCK_POLARITY_LOW;
1033 pSensorInfo->SensorVsyncPolarity = SENSOR_CLOCK_POLARITY_LOW;
1034
1035
1036 pSensorInfo->CaptureDelayFrame = 2;
1037 pSensorInfo->PreviewDelayFrame = 1;
1038 pSensorInfo->VideoDelayFrame = 1;
1039
1040 pSensorInfo->SensorMasterClockSwitch = 0;
1041 pSensorInfo->SensorDrivingCurrent = ISP_DRIVING_8MA;
1042 pSensorInfo->AEShutDelayFrame =0; /* The frame of setting shutter default 0 for TG int */
1043 pSensorInfo->AESensorGainDelayFrame = 0; /* The frame of setting sensor gain */
1044 pSensorInfo->AEISPGainDelayFrame = 2;
1045
1046 pSensorInfo->SensroInterfaceType=SENSOR_INTERFACE_TYPE_MIPI;
1047 #if defined(GC2355MIPI_2Lane)
1048 pSensorInfo->SensorMIPILaneNumber = SENSOR_MIPI_2_LANE;
1049 //pSensorInfo->SensorRawType = RAW_TYPE_10BIT;
1050 #else
1051 pSensorInfo->SensorMIPILaneNumber = SENSOR_MIPI_1_LANE;
1052 #endif
1053
1054 pSensorInfo->MIPIDataLowPwr2HighSpeedTermDelayCount = 0;
1055 pSensorInfo->MIPIDataLowPwr2HighSpeedSettleDelayCount = 14;
1056 pSensorInfo->MIPICLKLowPwr2HighSpeedTermDelayCount = 0;
1057 pSensorInfo->SensorWidthSampling = 0;
1058 pSensorInfo->SensorHightSampling = 0;
1059 pSensorInfo->SensorPacketECCOrder = 1;
1060 switch (ScenarioId)
1061 {
1062 case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
1063 pSensorInfo->SensorClockFreq=24;
1064 pSensorInfo->SensorClockDividCount=3;
1065 pSensorInfo->SensorClockRisingCount= 0;
1066 pSensorInfo->SensorClockFallingCount= 2;
1067 pSensorInfo->SensorPixelClockCount= 3;
1068 pSensorInfo->SensorDataLatchCount= 2;
1069 pSensorInfo->SensorGrabStartX = GC2355MIPI_PV_X_START;
1070 pSensorInfo->SensorGrabStartY = GC2355MIPI_PV_Y_START;
1071
1072 break;
1073 case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
1074 pSensorInfo->SensorClockFreq=24;
1075 pSensorInfo->SensorClockDividCount=3;
1076 pSensorInfo->SensorClockRisingCount= 0;
1077 pSensorInfo->SensorClockFallingCount= 2;
1078 pSensorInfo->SensorPixelClockCount= 3;
1079 pSensorInfo->SensorDataLatchCount= 2;
1080 pSensorInfo->SensorGrabStartX = GC2355MIPI_VIDEO_X_START;
1081 pSensorInfo->SensorGrabStartY = GC2355MIPI_VIDEO_Y_START;
1082
1083 break;
1084 case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
1085 case MSDK_SCENARIO_ID_CAMERA_ZSD:
1086 pSensorInfo->SensorClockFreq=24;
1087 pSensorInfo->SensorClockDividCount= 3;
1088 pSensorInfo->SensorClockRisingCount=0;
1089 pSensorInfo->SensorClockFallingCount=2;
1090 pSensorInfo->SensorPixelClockCount=3;
1091 pSensorInfo->SensorDataLatchCount=2;
1092 pSensorInfo->SensorGrabStartX = GC2355MIPI_FULL_X_START;
1093 pSensorInfo->SensorGrabStartY = GC2355MIPI_FULL_Y_START;
1094 break;
1095 default:
1096 pSensorInfo->SensorClockFreq=24;
1097 pSensorInfo->SensorClockDividCount=3;
1098 pSensorInfo->SensorClockRisingCount=0;
1099 pSensorInfo->SensorClockFallingCount=2;
1100 pSensorInfo->SensorPixelClockCount=3;
1101 pSensorInfo->SensorDataLatchCount=2;
1102 pSensorInfo->SensorGrabStartX = GC2355MIPI_PV_X_START;
1103 pSensorInfo->SensorGrabStartY = GC2355MIPI_PV_Y_START;
1104 break;
1105 }
1106 memcpy(pSensorConfigData, &GC2355MIPI_sensor.cfg_data, sizeof(MSDK_SENSOR_CONFIG_STRUCT));
1107 return ERROR_NONE;
1108 } /* GC2355MIPIGetInfo() */
1109
1110
1111 UINT32 GC2355MIPIControl(MSDK_SCENARIO_ID_ENUM ScenarioId, MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *pImageWindow,
1112 MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData)
1113 {
1114
1115 #ifdef GC2355_DRIVER_TRACE
1116 SENSORDB("GC2355MIPIControl ScenarioId = %d \n",ScenarioId);
1117 #endif
1118 switch (ScenarioId)
1119 {
1120 case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
1121 case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
1122 GC2355MIPIPreview(pImageWindow, pSensorConfigData);
1123 break;
1124 case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
1125 case MSDK_SCENARIO_ID_CAMERA_ZSD:
1126 GC2355MIPICapture(pImageWindow, pSensorConfigData);
1127 break;
1128 default:
1129 return ERROR_INVALID_SCENARIO_ID;
1130 }
1131 return ERROR_NONE;
1132 } /* GC2355MIPIControl() */
1133
1134
1135
1136 UINT32 GC2355MIPISetVideoMode(UINT16 u2FrameRate)
1137 {};
1138
1139 UINT32 GC2355MIPIFeatureControl(MSDK_SENSOR_FEATURE_ENUM FeatureId,
1140 UINT8 *pFeaturePara,UINT32 *pFeatureParaLen)
1141 {
1142 UINT16 *pFeatureReturnPara16=(UINT16 *) pFeaturePara;
1143 UINT16 *pFeatureData16=(UINT16 *) pFeaturePara;
1144 UINT32 *pFeatureReturnPara32=(UINT32 *) pFeaturePara;
1145 //UINT32 *pFeatureData32=(UINT32 *) pFeaturePara;
1146 //UINT32 GC2355MIPISensorRegNumber;
1147 //UINT32 i;
1148 //PNVRAM_SENSOR_DATA_STRUCT pSensorDefaultData=(PNVRAM_SENSOR_DATA_STRUCT) pFeaturePara;
1149 //MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData=(MSDK_SENSOR_CONFIG_STRUCT *) pFeaturePara;
1150 MSDK_SENSOR_REG_INFO_STRUCT *pSensorRegData=(MSDK_SENSOR_REG_INFO_STRUCT *) pFeaturePara;
1151 //MSDK_SENSOR_GROUP_INFO_STRUCT *pSensorGroupInfo=(MSDK_SENSOR_GROUP_INFO_STRUCT *) pFeaturePara;
1152 //MSDK_SENSOR_ITEM_INFO_STRUCT *pSensorItemInfo=(MSDK_SENSOR_ITEM_INFO_STRUCT *) pFeaturePara;
1153 //MSDK_SENSOR_ENG_INFO_STRUCT *pSensorEngInfo=(MSDK_SENSOR_ENG_INFO_STRUCT *) pFeaturePara;
1154
1155 switch (FeatureId)
1156 {
1157 case SENSOR_FEATURE_GET_RESOLUTION:
1158 *pFeatureReturnPara16++=GC2355MIPI_IMAGE_SENSOR_FULL_WIDTH;
1159 *pFeatureReturnPara16=GC2355MIPI_IMAGE_SENSOR_FULL_HEIGHT;
1160 *pFeatureParaLen=4;
1161 break;
1162 case SENSOR_FEATURE_GET_PERIOD: /* 3 */
1163 *pFeatureReturnPara16++=GC2355MIPI_sensor.line_length;
1164 *pFeatureReturnPara16=GC2355MIPI_sensor.frame_height;
1165 *pFeatureParaLen=4;
1166 break;
1167 case SENSOR_FEATURE_GET_PIXEL_CLOCK_FREQ: /* 3 */
1168 *pFeatureReturnPara32 = GC2355MIPI_sensor.pclk;
1169 *pFeatureParaLen=4;
1170 break;
1171 case SENSOR_FEATURE_SET_ESHUTTER: /* 4 */
1172 GC2355MIPI_set_shutter(*pFeatureData16);
1173 break;
1174 case SENSOR_FEATURE_SET_NIGHTMODE:
1175 GC2355MIPI_night_mode((BOOL) *pFeatureData16);
1176 break;
1177 case SENSOR_FEATURE_SET_GAIN: /* 6 */
1178 GC2355MIPI_SetGain((UINT16) *pFeatureData16);
1179 break;
1180 case SENSOR_FEATURE_SET_FLASHLIGHT:
1181 break;
1182 case SENSOR_FEATURE_SET_ISP_MASTER_CLOCK_FREQ:
1183 break;
1184 case SENSOR_FEATURE_SET_REGISTER:
1185 GC2355MIPI_write_cmos_sensor(pSensorRegData->RegAddr, pSensorRegData->RegData);
1186 break;
1187 case SENSOR_FEATURE_GET_REGISTER:
1188 pSensorRegData->RegData = GC2355MIPI_read_cmos_sensor(pSensorRegData->RegAddr);
1189 break;
1190 case SENSOR_FEATURE_SET_CCT_REGISTER:
1191 memcpy(&GC2355MIPI_sensor.eng.cct, pFeaturePara, sizeof(GC2355MIPI_sensor.eng.cct));
1192 break;
1193 break;
1194 case SENSOR_FEATURE_GET_CCT_REGISTER: /* 12 */
1195 if (*pFeatureParaLen >= sizeof(GC2355MIPI_sensor.eng.cct) + sizeof(kal_uint32))
1196 {
1197 *((kal_uint32 *)pFeaturePara++) = sizeof(GC2355MIPI_sensor.eng.cct);
1198 memcpy(pFeaturePara, &GC2355MIPI_sensor.eng.cct, sizeof(GC2355MIPI_sensor.eng.cct));
1199 }
1200 break;
1201 case SENSOR_FEATURE_SET_ENG_REGISTER:
1202 memcpy(&GC2355MIPI_sensor.eng.reg, pFeaturePara, sizeof(GC2355MIPI_sensor.eng.reg));
1203 break;
1204 case SENSOR_FEATURE_GET_ENG_REGISTER: /* 14 */
1205 if (*pFeatureParaLen >= sizeof(GC2355MIPI_sensor.eng.reg) + sizeof(kal_uint32))
1206 {
1207 *((kal_uint32 *)pFeaturePara++) = sizeof(GC2355MIPI_sensor.eng.reg);
1208 memcpy(pFeaturePara, &GC2355MIPI_sensor.eng.reg, sizeof(GC2355MIPI_sensor.eng.reg));
1209 }
1210 case SENSOR_FEATURE_GET_REGISTER_DEFAULT:
1211 ((PNVRAM_SENSOR_DATA_STRUCT)pFeaturePara)->Version = NVRAM_CAMERA_SENSOR_FILE_VERSION;
1212 ((PNVRAM_SENSOR_DATA_STRUCT)pFeaturePara)->SensorId = GC2355MIPI_SENSOR_ID;
1213 memcpy(((PNVRAM_SENSOR_DATA_STRUCT)pFeaturePara)->SensorEngReg, &GC2355MIPI_sensor.eng.reg, sizeof(GC2355MIPI_sensor.eng.reg));
1214 memcpy(((PNVRAM_SENSOR_DATA_STRUCT)pFeaturePara)->SensorCCTReg, &GC2355MIPI_sensor.eng.cct, sizeof(GC2355MIPI_sensor.eng.cct));
1215 *pFeatureParaLen = sizeof(NVRAM_SENSOR_DATA_STRUCT);
1216 break;
1217 case SENSOR_FEATURE_GET_CONFIG_PARA:
1218 memcpy(pFeaturePara, &GC2355MIPI_sensor.cfg_data, sizeof(GC2355MIPI_sensor.cfg_data));
1219 *pFeatureParaLen = sizeof(GC2355MIPI_sensor.cfg_data);
1220 break;
1221 case SENSOR_FEATURE_CAMERA_PARA_TO_SENSOR:
1222 GC2355MIPI_camera_para_to_sensor();
1223 break;
1224 case SENSOR_FEATURE_SENSOR_TO_CAMERA_PARA:
1225 GC2355MIPI_sensor_to_camera_para();
1226 break;
1227 case SENSOR_FEATURE_GET_GROUP_COUNT:
1228 GC2355MIPI_get_sensor_group_count((kal_uint32 *)pFeaturePara);
1229 *pFeatureParaLen = 4;
1230 break;
1231 case SENSOR_FEATURE_GET_GROUP_INFO:
1232 GC2355MIPI_get_sensor_group_info((MSDK_SENSOR_GROUP_INFO_STRUCT *)pFeaturePara);
1233 *pFeatureParaLen = sizeof(MSDK_SENSOR_GROUP_INFO_STRUCT);
1234 break;
1235 case SENSOR_FEATURE_GET_ITEM_INFO:
1236 GC2355MIPI_get_sensor_item_info((MSDK_SENSOR_ITEM_INFO_STRUCT *)pFeaturePara);
1237 *pFeatureParaLen = sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT);
1238 break;
1239 case SENSOR_FEATURE_SET_ITEM_INFO:
1240 GC2355MIPI_set_sensor_item_info((MSDK_SENSOR_ITEM_INFO_STRUCT *)pFeaturePara);
1241 *pFeatureParaLen = sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT);
1242 break;
1243 case SENSOR_FEATURE_GET_ENG_INFO:
1244 memcpy(pFeaturePara, &GC2355MIPI_sensor.eng_info, sizeof(GC2355MIPI_sensor.eng_info));
1245 *pFeatureParaLen = sizeof(GC2355MIPI_sensor.eng_info);
1246 break;
1247 case SENSOR_FEATURE_GET_LENS_DRIVER_ID:
1248 // get the lens driver ID from EEPROM or just return LENS_DRIVER_ID_DO_NOT_CARE
1249 // if EEPROM does not exist in camera module.
1250 *pFeatureReturnPara32=LENS_DRIVER_ID_DO_NOT_CARE;
1251 *pFeatureParaLen=4;
1252 break;
1253 case SENSOR_FEATURE_SET_VIDEO_MODE:
1254 //GC2355MIPISetVideoMode(*pFeatureData16);
1255 break;
1256 case SENSOR_FEATURE_CHECK_SENSOR_ID:
1257 GC2355MIPIGetSensorID(pFeatureReturnPara32);
1258 break;
1259 case SENSOR_FEATURE_SET_AUTO_FLICKER_MODE:
1260 break;
1261
1262 /*SZ TCT xuejian.zhong add for CTS test */
1263 case SENSOR_FEATURE_GET_AF_MAX_NUM_FOCUS_AREAS:
1264 GC2355GetAFMaxNumFocusAreas(pFeatureReturnPara32);
1265
1266 *pFeatureParaLen=4;
1267 break;
1268
1269 case SENSOR_FEATURE_GET_AE_MAX_NUM_METERING_AREAS:
1270 GC2355GetAEMaxNumMeteringAreas(pFeatureReturnPara32);
1271
1272 *pFeatureParaLen=4;
1273 break;
1274 case SENSOR_FEATURE_GET_EXIF_INFO:
1275
1276 GC2355GetExifInfo(*pFeatureReturnPara32);
1277 break;
1278 /* xuejian.zhong add end */
1279
1280
1281
1282 default:
1283 break;
1284 }
1285 return ERROR_NONE;
1286 } /* GC2355MIPIFeatureControl() */
1287 SENSOR_FUNCTION_STRUCT SensorFuncGC2355MIPI=
1288 {
1289 GC2355MIPIOpen,
1290 GC2355MIPIGetInfo,
1291 GC2355MIPIGetResolution,
1292 GC2355MIPIFeatureControl,
1293 GC2355MIPIControl,
1294 GC2355MIPIClose
1295 };
1296
1297 UINT32 GC2355MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc)
1298 {
1299 /* To Do : Check Sensor status here */
1300 if (pfFunc!=NULL)
1301 *pfFunc=&SensorFuncGC2355MIPI;
1302
1303 return ERROR_NONE;
1304 } /* SensorInit() */