import PULS_20180308
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / imgsensor / src / mt8127 / ov2680_raw / ov2680mipiraw_Sensor.c
CommitLineData
6fa3eb70
S
1/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2005
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/*****************************************************************************
37 *
38 * Filename:
39 * ---------
40 * Sensor.c
41 *
42 * Project:
43 * --------
44 * DUMA
45 *
46 * Description:
47 * ------------
48 * Image sensor driver function
49 *
50 *------------------------------------------------------------------------------
51 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
52 *============================================================================
53 ****************************************************************************/
54#include <linux/videodev2.h>
55#include <linux/i2c.h>
56#include <linux/platform_device.h>
57#include <linux/delay.h>
58#include <linux/cdev.h>
59#include <linux/uaccess.h>
60#include <linux/fs.h>
61#include <asm/atomic.h>
62#include <linux/xlog.h>
63#include <asm/system.h>
64#include <linux/proc_fs.h>
65#include <linux/dma-mapping.h>
66#include <linux/kernel.h>
67
68
69#include "kd_camera_hw.h"
70#include "kd_imgsensor.h"
71#include "kd_imgsensor_define.h"
72#include "kd_imgsensor_errcode.h"
73
74#include "ov2680mipiraw_Sensor.h"
75#include "ov2680mipiraw_Camera_Sensor_para.h"
76#include "ov2680mipiraw_CameraCustomized.h"
77
78#define OV2680_DEBUG
79#define OV2680_DRIVER_TRACE
80#define LOG_TAG "[OV2680MIPIRaw]"
81#ifdef OV2680_DEBUG
82#define SENSORDB(fmt,arg...) printk(LOG_TAG "%s: " fmt "\n", __FUNCTION__ ,##arg)
83#else
84#define SENSORDB(fmt,arg...)
85#endif
86//#define OV2680_TEST_PATTERN_CHECKSUM 0x17870f14
87#define OV2680_TEST_PATTERN_CHECKSUM 0x86da3e5a
88
89//kal_bool OV2680_during_testpattern = KAL_FALSE;
90
91
92//#define ACDK
93extern int iReadRegI2C(u8 *a_pSendData , u16 a_sizeSendData, u8 * a_pRecvData, u16 a_sizeRecvData, u16 i2cId);
94extern int iWriteRegI2C(u8 *a_pSendData , u16 a_sizeSendData, u16 i2cId);
95extern int iMultiWriteReg(u8 *pData, u16 lens, u16 i2cId);
96
97//#define USE_I2C_MULTIWRITE
98#define Ov2680_multi_write_cmos_sensor(pData, lens) iMultiWriteReg((u8*) pData, (u16) lens, OV2680_SLAVE_WRITE_ID_1)
99
100
101MSDK_SCENARIO_ID_ENUM ov2680CurrentScenarioId = MSDK_SCENARIO_ID_CAMERA_PREVIEW;
4b9e9796
S
102
103/* SZ TCT xuejian.zhong add for CTS test*/
104static void OV2680GetAFMaxNumFocusAreas(UINT32 *pFeatureReturnPara32)
105{
106 *pFeatureReturnPara32 = 0;
107 SENSORDB("OV2680GetAFMaxNumFocusAreas *pFeatureReturnPara32 = %d\n", *pFeatureReturnPara32);
108}
109
110static void OV2680GetAEMaxNumMeteringAreas(UINT32 *pFeatureReturnPara32)
111{
112 *pFeatureReturnPara32 = 0;
113 SENSORDB("OV2680GetAEMaxNumMeteringAreas *pFeatureReturnPara32 = %d\n", *pFeatureReturnPara32);
114}
115
116static void OV2680GetExifInfo(UINT32 exifAddr)
117{
118 SENSOR_EXIF_INFO_STRUCT* pExifInfo = (SENSOR_EXIF_INFO_STRUCT*)exifAddr;
119 pExifInfo->FNumber = 28;
120 pExifInfo->AEISOSpeed = AE_ISO_100;
121 pExifInfo->AWBMode = AWB_MODE_AUTO;
122 pExifInfo->CapExposureTime = 0;
123 pExifInfo->FlashLightTimeus = 0;
124 pExifInfo->RealISOValue = AE_ISO_100;
125}
126
127/* SZ TCT xuejian.zhong end */
128
129
130
6fa3eb70
S
131static OV2680_sensor_struct OV2680_sensor =
132{
133 .eng =
134 {
135 .reg = OV2680_CAMERA_SENSOR_REG_DEFAULT_VALUE,
136 .cct = OV2680_CAMERA_SENSOR_CCT_DEFAULT_VALUE,
137 },
138 .eng_info =
139 {
140 .SensorId = OV2680MIPI_SENSOR_ID,
141 .SensorType = CMOS_SENSOR,
142 .SensorOutputDataFormat = OV2680_COLOR_FORMAT,
143 },
144 .shutter = 0x20,
145 .gain = 0x20,
146 .pv_pclk = OV2680_PREVIEW_CLK,
147 .cap_pclk = OV2680_CAPTURE_CLK,
148 .pclk = OV2680_PREVIEW_CLK,
149 .frame_height = OV2680_PV_PERIOD_LINE_NUMS,
150 .line_length = OV2680_PV_PERIOD_PIXEL_NUMS,
151 .is_zsd = KAL_FALSE, //for zsd
152 .dummy_pixels = 0,
153 .dummy_lines = 0, //for zsd
154 .is_autofliker = KAL_FALSE,
155};
156
157static DEFINE_SPINLOCK(OV2680_drv_lock);
158
159kal_uint16 OV2680_read_cmos_sensor(kal_uint32 addr)
160{
161 kal_uint16 get_byte=0;
162 char puSendCmd[2] = {(char)(addr >> 8) , (char)(addr & 0xFF) };
163 iReadRegI2C(puSendCmd , 2, (u8*)&get_byte,1,OV2680_sensor.write_id);
164#ifdef OV2680_DRIVER_TRACE
165 //SENSORDB("OV2680_read_cmos_sensor, addr:%x;get_byte:%x \n",addr,get_byte);
166#endif
167 return get_byte;
168}
169
170kal_uint16 OV2680_write_cmos_sensor(kal_uint32 addr, kal_uint32 para)
171{
172 //kal_uint16 reg_tmp;
173
174 char puSendCmd[3] = {(char)(addr >> 8) , (char)(addr & 0xFF) ,(char)(para & 0xFF)};
175
176 iWriteRegI2C(puSendCmd , 3,OV2680_sensor.write_id);
177 return ERROR_NONE;
178}
179
180/***************************** OTP Feature **********************************/
181//#define OV2680_USE_OTP
182
183
184
185/***************************** OTP Feature End**********************************/
186
187void OV2680_Write_Shutter(kal_uint16 ishutter)
188{
189
190 kal_uint16 extra_shutter = 0;
191 kal_uint16 realtime_fp = 0;
192 kal_uint16 frame_height = 0;
193 kal_uint16 line_length = 0;
194
195 unsigned long flags;
196#ifdef OV2680_DRIVER_TRACE
197 SENSORDB("OV2680_write_shutter:%x \n",ishutter);
198#endif
199 if (!ishutter) ishutter = 1; /* avoid 0 */
200 //if(ishutter > 0xfff)
201
202 frame_height = OV2680_PV_PERIOD_LINE_NUMS + OV2680_sensor.dummy_lines;
203
204 if(ishutter > (frame_height -4))
205 {
206 extra_shutter = ishutter - frame_height + 4;
207 SENSORDB("[shutter > frame_height] frame_height:%x extra_shutter:%x \n",frame_height,extra_shutter);
208 }
209 else
210 {
211 extra_shutter = 0;
212 }
213 frame_height += extra_shutter;
214 OV2680_sensor.frame_height = frame_height;
215 SENSORDB("OV2680_sensor.is_autofliker:%x, OV2680_sensor.frame_height: %x \n",OV2680_sensor.is_autofliker,OV2680_sensor.frame_height);
216 #if 1
217 if(OV2680_sensor.is_autofliker == KAL_TRUE)
218 {
219 realtime_fp = OV2680_sensor.pclk *10 / ((OV2680_sensor.line_length/OV2680_MIPI_LANE_NUM) * OV2680_sensor.frame_height);
220 SENSORDB("[OV2680_Write_Shutter]pv_clk:%d\n",OV2680_sensor.pclk);
221 SENSORDB("[OV2680_Write_Shutter]line_length/4:%d\n",(OV2680_sensor.line_length/OV2680_MIPI_LANE_NUM));
222 SENSORDB("[OV2680_Write_Shutter]frame_height:%d\n",OV2680_sensor.frame_height);
223 SENSORDB("[OV2680_Write_Shutter]framerate(10base):%d\n",realtime_fp);
224
225 if((realtime_fp >= 297)&&(realtime_fp <= 303))
226 {
227 realtime_fp = 296;
228 spin_lock_irqsave(&OV2680_drv_lock,flags);
229 OV2680_sensor.frame_height = OV2680_sensor.pclk *10 / ((OV2680_sensor.line_length/OV2680_MIPI_LANE_NUM) * realtime_fp);
230 spin_unlock_irqrestore(&OV2680_drv_lock,flags);
231
232 SENSORDB("[autofliker realtime_fp=30,extern heights slowdown to 29.6fps][height:%d]",OV2680_sensor.frame_height);
233 }
234 else if((realtime_fp >= 147)&&(realtime_fp <= 153))
235 {
236 realtime_fp = 146;
237 spin_lock_irqsave(&OV2680_drv_lock,flags);
238 OV2680_sensor.frame_height = OV2680_sensor.pclk *10 / ((OV2680_sensor.line_length/OV2680_MIPI_LANE_NUM) * realtime_fp);
239 spin_unlock_irqrestore(&OV2680_drv_lock,flags);
240 SENSORDB("[autofliker realtime_fp=15,extern heights slowdown to 14.6fps][height:%d]",OV2680_sensor.frame_height);
241 }
242 //OV2680_sensor.frame_height = OV2680_sensor.frame_height +(OV2680_sensor.frame_height>>7);
243
244 }
245 #endif
246 OV2680_write_cmos_sensor(0x380e, (OV2680_sensor.frame_height>>8)&0xFF);
247 OV2680_write_cmos_sensor(0x380f, (OV2680_sensor.frame_height)&0xFF);
248
249 OV2680_write_cmos_sensor(0x3500, (ishutter >> 12) & 0xF);
250 OV2680_write_cmos_sensor(0x3501, (ishutter >> 4) & 0xFF);
251 OV2680_write_cmos_sensor(0x3502, (ishutter << 4) & 0xFF);
252
253}
254
255
256/*************************************************************************
257* FUNCTION
258* OV2680_Set_Dummy
259*
260* DESCRIPTION
261* This function set dummy pixel or dummy line of OV2680
262*
263* PARAMETERS
264* iPixels : dummy pixel
265* iLines : dummy linel
266* RETURNS
267* None
268*
269* GLOBALS AFFECTED
270*
271*************************************************************************/
272
273static void OV2680_Set_Dummy(const kal_uint16 iPixels, const kal_uint16 iLines)
274{
275 kal_uint16 line_length, frame_height;
276#ifdef OV2680_DRIVER_TRACE
277 SENSORDB("OV2680_Set_Dummy:iPixels:%x; iLines:%x \n",iPixels,iLines);
278#endif
279
280
281 OV2680_sensor.dummy_lines = iLines;
282 OV2680_sensor.dummy_pixels = iPixels;
283
284 line_length = OV2680_PV_PERIOD_PIXEL_NUMS + iPixels;
285 frame_height = OV2680_PV_PERIOD_LINE_NUMS + iLines;
286
287#ifdef OV2680_DRIVER_TRACE
288 SENSORDB("line_length:%x; frame_height:%x \n",line_length,frame_height);
289#endif
290
291 if ((line_length >= 0xFFFF)||(frame_height >= 0xFFFF)) // need check
292 {
293 #ifdef OV2680_DRIVER_TRACE
294 SENSORDB("ERROR: line length or frame height is overflow!!!!!!!! \n");
295 #endif
296 return ERROR_NONE;
297 }
298// if((line_length == OV2680_sensor.line_length)&&(frame_height == OV2680_sensor.frame_height))
299// return ;
300 spin_lock(&OV2680_drv_lock);
301 OV2680_sensor.line_length = line_length;
302 OV2680_sensor.frame_height = frame_height;
303 spin_unlock(&OV2680_drv_lock);
304
305 SENSORDB("line_length:%x; frame_height:%x \n",line_length,frame_height);
306 SENSORDB("write to register line_length/4:%x; frame_height:%x \n",(line_length/4),frame_height);
307
308 /* Add dummy pixels: */
309 /* 0x380c [0:4], 0x380d defines the PCLKs in one line of OV2680 */
310 /* Add dummy lines:*/
311 /* 0x380e [0:1], 0x380f defines total lines in one frame of OV2680 */
312 OV2680_write_cmos_sensor(0x380c, (line_length/OV2680_MIPI_LANE_NUM) >> 8);
313 OV2680_write_cmos_sensor(0x380d, (line_length/OV2680_MIPI_LANE_NUM) & 0xFF);
314 OV2680_write_cmos_sensor(0x380e, frame_height >> 8);
315 OV2680_write_cmos_sensor(0x380f, frame_height & 0xFF);
316 return ERROR_NONE;
317} /* OV2680_Set_Dummy */
318
319
320/*************************************************************************
321* FUNCTION
322* OV2680_SetShutter
323*
324* DESCRIPTION
325* This function set e-shutter of OV2680 to change exposure time.
326*
327* PARAMETERS
328* iShutter : exposured lines
329*
330* RETURNS
331* None
332*
333* GLOBALS AFFECTED
334*
335*************************************************************************/
336
337
338void set_OV2680_shutter(kal_uint16 iShutter)
339{
340
341 unsigned long flags;
342#ifdef OV2680_DRIVER_TRACE
343 SENSORDB("set_OV2680_shutter:%x \n",iShutter);
344#endif
345
346 spin_lock_irqsave(&OV2680_drv_lock,flags);
347 OV2680_sensor.shutter = iShutter;
348 spin_unlock_irqrestore(&OV2680_drv_lock,flags);
349
350 OV2680_Write_Shutter(iShutter);
351
352} /* Set_OV2680_Shutter */
353
354 kal_uint16 OV2680Gain2Reg(const kal_uint16 iGain)
355{
356 kal_uint16 iReg = 0x00;
357
358 //iReg = ((iGain / BASEGAIN) << 4) + ((iGain % BASEGAIN) * 16 / BASEGAIN);
359 iReg = iGain *16 / BASEGAIN;
360
361 iReg = iReg & 0xFF;
362#ifdef OV2680_DRIVER_TRACE
363 SENSORDB("OV2680Gain2Reg:iGain:%x; iReg:%x \n",iGain,iReg);
364#endif
365 return iReg;
366}
367
368
369kal_uint16 OV2680_SetGain(kal_uint16 iGain)
370{
371 kal_uint16 i;
372 kal_uint16 gain_reg = 0;
373#ifdef OV2680_DRIVER_TRACE
374 SENSORDB("OV2680_SetGain:iGain = %x;\n",iGain);
375 SENSORDB("OV2680_SetGain:gain_reg 0 = %x;\n",gain_reg);
376
377#endif
378
379 if(!iGain) {
380 SENSORDB("OV2680_SetGain[ERROR]:gain is zero, iGain = %x;\n",iGain);
381 iGain = 64; // 1x base
382 }
383 gain_reg = iGain/4; //sensor gain base 1x= 16, IReg = iGain/64*16;
384 gain_reg &= 0x3ff;
385
386 OV2680_write_cmos_sensor(0x350b, (gain_reg&0xff));
387 OV2680_write_cmos_sensor(0x3508, (gain_reg>>8));
388 return ERROR_NONE;
389}
390
391
392
393
394/*************************************************************************
395* FUNCTION
396* OV2680_SetGain
397*
398* DESCRIPTION
399* This function is to set global gain to sensor.
400*
401* PARAMETERS
402* iGain : sensor global gain(base: 0x40)
403*
404* RETURNS
405* the actually gain set to sensor.
406*
407* GLOBALS AFFECTED
408*
409*************************************************************************/
410
411#if 0
412void OV2680_set_isp_driving_current(kal_uint16 current)
413{
414#ifdef OV2680_DRIVER_TRACE
415 SENSORDB("OV2680_set_isp_driving_current:current:%x;\n",current);
416#endif
417 //iowrite32((0x2 << 12)|(0<<28)|(0x8880888), 0xF0001500);
418}
419#endif
420
421/*************************************************************************
422* FUNCTION
423* OV2680_NightMode
424*
425* DESCRIPTION
426* This function night mode of OV2680.
427*
428* PARAMETERS
429* bEnable: KAL_TRUE -> enable night mode, otherwise, disable night mode
430*
431* RETURNS
432* None
433*
434* GLOBALS AFFECTED
435*
436*************************************************************************/
437void OV2680_night_mode(kal_bool enable)
438{
439} /* OV2680_NightMode */
440
441
442/* write camera_para to sensor register */
443static void OV2680_camera_para_to_sensor(void)
444{
445 kal_uint32 i;
446#ifdef OV2680_DRIVER_TRACE
447 SENSORDB("OV2680_camera_para_to_sensor\n");
448#endif
449 for (i = 0; 0xFFFFFFFF != OV2680_sensor.eng.reg[i].Addr; i++)
450 {
451 OV2680_write_cmos_sensor(OV2680_sensor.eng.reg[i].Addr, OV2680_sensor.eng.reg[i].Para);
452 }
453 for (i = OV2680_FACTORY_START_ADDR; 0xFFFFFFFF != OV2680_sensor.eng.reg[i].Addr; i++)
454 {
455 OV2680_write_cmos_sensor(OV2680_sensor.eng.reg[i].Addr, OV2680_sensor.eng.reg[i].Para);
456 }
457 OV2680_SetGain(OV2680_sensor.gain); /* update gain */
458}
459
460/* update camera_para from sensor register */
461static void OV2680_sensor_to_camera_para(void)
462{
463 kal_uint32 i;
464 kal_uint32 temp_data;
465
466#ifdef OV2680_DRIVER_TRACE
467 SENSORDB("OV2680_sensor_to_camera_para\n");
468#endif
469 for (i = 0; 0xFFFFFFFF != OV2680_sensor.eng.reg[i].Addr; i++)
470 {
471 temp_data = OV2680_read_cmos_sensor(OV2680_sensor.eng.reg[i].Addr);
472
473 spin_lock(&OV2680_drv_lock);
474 OV2680_sensor.eng.reg[i].Para = temp_data;
475 spin_unlock(&OV2680_drv_lock);
476
477 }
478 for (i = OV2680_FACTORY_START_ADDR; 0xFFFFFFFF != OV2680_sensor.eng.reg[i].Addr; i++)
479 {
480 temp_data = OV2680_read_cmos_sensor(OV2680_sensor.eng.reg[i].Addr);
481
482 spin_lock(&OV2680_drv_lock);
483 OV2680_sensor.eng.reg[i].Para = temp_data;
484 spin_unlock(&OV2680_drv_lock);
485 }
486}
487
488/* ------------------------ Engineer mode ------------------------ */
489inline static void OV2680_get_sensor_group_count(kal_int32 *sensor_count_ptr)
490{
491#ifdef OV2680_DRIVER_TRACE
492 SENSORDB("OV2680_get_sensor_group_count\n");
493#endif
494 *sensor_count_ptr = OV2680_GROUP_TOTAL_NUMS;
495}
496
497inline static void OV2680_get_sensor_group_info(MSDK_SENSOR_GROUP_INFO_STRUCT *para)
498{
499#ifdef OV2680_DRIVER_TRACE
500 SENSORDB("OV2680_get_sensor_group_info\n");
501#endif
502 switch (para->GroupIdx)
503 {
504 case OV2680_PRE_GAIN:
505 sprintf(para->GroupNamePtr, "CCT");
506 para->ItemCount = 5;
507 break;
508 case OV2680_CMMCLK_CURRENT:
509 sprintf(para->GroupNamePtr, "CMMCLK Current");
510 para->ItemCount = 1;
511 break;
512 case OV2680_FRAME_RATE_LIMITATION:
513 sprintf(para->GroupNamePtr, "Frame Rate Limitation");
514 para->ItemCount = 2;
515 break;
516 case OV2680_REGISTER_EDITOR:
517 sprintf(para->GroupNamePtr, "Register Editor");
518 para->ItemCount = 2;
519 break;
520 default:
521 ASSERT(0);
522 }
523}
524
525inline static void OV2680_get_sensor_item_info(MSDK_SENSOR_ITEM_INFO_STRUCT *para)
526{
527
528 const static kal_char *cct_item_name[] = {"SENSOR_BASEGAIN", "Pregain-R", "Pregain-Gr", "Pregain-Gb", "Pregain-B"};
529 const static kal_char *editer_item_name[] = {"REG addr", "REG value"};
530
531#ifdef OV2680_DRIVER_TRACE
532 SENSORDB("OV2680_get_sensor_item_info\n");
533#endif
534 switch (para->GroupIdx)
535 {
536 case OV2680_PRE_GAIN:
537 switch (para->ItemIdx)
538 {
539 case OV2680_SENSOR_BASEGAIN:
540 case OV2680_PRE_GAIN_R_INDEX:
541 case OV2680_PRE_GAIN_Gr_INDEX:
542 case OV2680_PRE_GAIN_Gb_INDEX:
543 case OV2680_PRE_GAIN_B_INDEX:
544 break;
545 default:
546 ASSERT(0);
547 }
548 sprintf(para->ItemNamePtr, cct_item_name[para->ItemIdx - OV2680_SENSOR_BASEGAIN]);
549 para->ItemValue = OV2680_sensor.eng.cct[para->ItemIdx].Para * 1000 / BASEGAIN;
550 para->IsTrueFalse = para->IsReadOnly = para->IsNeedRestart = KAL_FALSE;
551 para->Min = OV2680_MIN_ANALOG_GAIN * 1000;
552 para->Max = OV2680_MAX_ANALOG_GAIN * 1000;
553 break;
554 case OV2680_CMMCLK_CURRENT:
555 switch (para->ItemIdx)
556 {
557 case 0:
558 sprintf(para->ItemNamePtr, "Drv Cur[2,4,6,8]mA");
559 switch (OV2680_sensor.eng.reg[OV2680_CMMCLK_CURRENT_INDEX].Para)
560 {
561 case ISP_DRIVING_2MA:
562 para->ItemValue = 2;
563 break;
564 case ISP_DRIVING_4MA:
565 para->ItemValue = 4;
566 break;
567 case ISP_DRIVING_6MA:
568 para->ItemValue = 6;
569 break;
570 case ISP_DRIVING_8MA:
571 para->ItemValue = 8;
572 break;
573 default:
574 ASSERT(0);
575 }
576 para->IsTrueFalse = para->IsReadOnly = KAL_FALSE;
577 para->IsNeedRestart = KAL_TRUE;
578 para->Min = 2;
579 para->Max = 8;
580 break;
581 default:
582 ASSERT(0);
583 }
584 break;
585 case OV2680_FRAME_RATE_LIMITATION:
586 switch (para->ItemIdx)
587 {
588 case 0:
589 sprintf(para->ItemNamePtr, "Max Exposure Lines");
590 para->ItemValue = 5998;
591 break;
592 case 1:
593 sprintf(para->ItemNamePtr, "Min Frame Rate");
594 para->ItemValue = 5;
595 break;
596 default:
597 ASSERT(0);
598 }
599 para->IsTrueFalse = para->IsNeedRestart = KAL_FALSE;
600 para->IsReadOnly = KAL_TRUE;
601 para->Min = para->Max = 0;
602 break;
603 case OV2680_REGISTER_EDITOR:
604 switch (para->ItemIdx)
605 {
606 case 0:
607 case 1:
608 sprintf(para->ItemNamePtr, editer_item_name[para->ItemIdx]);
609 para->ItemValue = 0;
610 para->IsTrueFalse = para->IsReadOnly = para->IsNeedRestart = KAL_FALSE;
611 para->Min = 0;
612 para->Max = (para->ItemIdx == 0 ? 0xFFFF : 0xFF);
613 break;
614 default:
615 ASSERT(0);
616 }
617 break;
618 default:
619 ASSERT(0);
620 }
621}
622
623inline static kal_bool OV2680_set_sensor_item_info(MSDK_SENSOR_ITEM_INFO_STRUCT *para)
624{
625 kal_uint16 temp_para;
626#ifdef OV2680_DRIVER_TRACE
627 SENSORDB("OV2680_set_sensor_item_info\n");
628#endif
629 switch (para->GroupIdx)
630 {
631 case OV2680_PRE_GAIN:
632 switch (para->ItemIdx)
633 {
634 case OV2680_SENSOR_BASEGAIN:
635 case OV2680_PRE_GAIN_R_INDEX:
636 case OV2680_PRE_GAIN_Gr_INDEX:
637 case OV2680_PRE_GAIN_Gb_INDEX:
638 case OV2680_PRE_GAIN_B_INDEX:
639 spin_lock(&OV2680_drv_lock);
640 OV2680_sensor.eng.cct[para->ItemIdx].Para = para->ItemValue * BASEGAIN / 1000;
641 spin_unlock(&OV2680_drv_lock);
642
643 OV2680_SetGain(OV2680_sensor.gain); /* update gain */
644 break;
645 default:
646 ASSERT(0);
647 }
648 break;
649 case OV2680_CMMCLK_CURRENT:
650 switch (para->ItemIdx)
651 {
652 case 0:
653 switch (para->ItemValue)
654 {
655 case 2:
656 temp_para = ISP_DRIVING_2MA;
657 break;
658 case 3:
659 case 4:
660 temp_para = ISP_DRIVING_4MA;
661 break;
662 case 5:
663 case 6:
664 temp_para = ISP_DRIVING_6MA;
665 break;
666 default:
667 temp_para = ISP_DRIVING_8MA;
668 break;
669 }
670 //OV2680_set_isp_driving_current((kal_uint16)temp_para);
671 spin_lock(&OV2680_drv_lock);
672 OV2680_sensor.eng.reg[OV2680_CMMCLK_CURRENT_INDEX].Para = temp_para;
673 spin_unlock(&OV2680_drv_lock);
674 break;
675 default:
676 ASSERT(0);
677 }
678 break;
679 case OV2680_FRAME_RATE_LIMITATION:
680 ASSERT(0);
681 break;
682 case OV2680_REGISTER_EDITOR:
683 switch (para->ItemIdx)
684 {
685 static kal_uint32 fac_sensor_reg;
686 case 0:
687 if (para->ItemValue < 0 || para->ItemValue > 0xFFFF) return KAL_FALSE;
688 fac_sensor_reg = para->ItemValue;
689 break;
690 case 1:
691 if (para->ItemValue < 0 || para->ItemValue > 0xFF) return KAL_FALSE;
692 OV2680_write_cmos_sensor(fac_sensor_reg, para->ItemValue);
693 break;
694 default:
695 ASSERT(0);
696 }
697 break;
698 default:
699 ASSERT(0);
700 }
701 return KAL_TRUE;
702}
703
704
705
706#ifdef USE_I2C_MULTIWRITE
707static kal_uint8 OV2680_init[]={
708
709 //0x01, 0x03, 0x01,
710 0x30, 0x02, 0x00,
711 0x30, 0x16, 0x1c,
712 0x30, 0x18, 0x44,
713 0x30, 0x20, 0x00,
714 0x30, 0x80, 0x02,
715 0x30, 0x82, 0x37,
716 0x30, 0x84, 0x09,
717 0x30, 0x85, 0x04,
718 0x30, 0x86, 0x01,
719 0x35, 0x01, 0x26,
720 0x35, 0x02, 0x40,
721 0x35, 0x03, 0x03,
722 0x35, 0x0b, 0x36,
723 0x36, 0x00, 0xb4,
724 0x36, 0x03, 0x39,
725 0x36, 0x04, 0x24,
726 0x36, 0x05, 0x00,
727 0x36, 0x20, 0x26,
728 0x36, 0x21, 0x37,
729 0x36, 0x22, 0x04,
730 0x36, 0x28, 0x00,
731 0x37, 0x05, 0x3c,
732 0x37, 0x0c, 0x50,
733 0x37, 0x0d, 0xc0,
734 0x37, 0x18, 0x88,
735 0x37, 0x20, 0x00,
736 0x37, 0x21, 0x00,
737 0x37, 0x22, 0x00,
738 0x37, 0x23, 0x00,
739 0x37, 0x38, 0x00,
740 0x37, 0x0a, 0x23,
741 0x37, 0x17, 0x58,
742 0x37, 0x81, 0x80,
743 0x37, 0x89, 0x60,
744 0x38, 0x00, 0x00,
745 0x38, 0x01, 0x00,
746 0x38, 0x02, 0x00,
747 0x38, 0x03, 0x00,
748 0x38, 0x04, 0x06,
749 0x38, 0x05, 0x4f,
750 0x38, 0x06, 0x04,
751 0x38, 0x07, 0xbf,
752 0x38, 0x08, 0x03,
753 0x38, 0x09, 0x20,
754 0x38, 0x0a, 0x02,
755 0x38, 0x0b, 0x58,
756 0x38, 0x0c, 0x06,
757 0x38, 0x0d, 0xac,
758 0x38, 0x0e, 0x02,
759 0x38, 0x0f, 0x84,
760 0x38, 0x10, 0x00,
761 0x38, 0x11, 0x04,
762 0x38, 0x12, 0x00,
763 0x38, 0x13, 0x04,
764 0x38, 0x14, 0x31,
765 0x38, 0x15, 0x31,
766 0x38, 0x19, 0x04,
767 0x38, 0x20, 0xc2,
768 0x38, 0x21, 0x01,
769 0x40, 0x00, 0x81,
770 0x40, 0x01, 0x40,
771 0x40, 0x08, 0x00,
772 0x40, 0x09, 0x03,
773 0x46, 0x02, 0x02,
774 0x48, 0x1f, 0x36,
775 0x48, 0x25, 0x36,
776 0x48, 0x37, 0x30,
777 0x50, 0x02, 0x30,
778 0x50, 0x80, 0x00,
779 0x50, 0x81, 0x41,
780 0x01, 0x00, 0x01,
781
782};
783
784static kal_uint8 OV2680_preview[]={
785 0x01, 0x00, 0x00,
786 0x30, 0x86, 0x00,
787 0x35, 0x01, 0x4e,
788 0x35, 0x02, 0xe0,
789 0x36, 0x20, 0x26,
790 0x36, 0x21, 0x37,
791 0x36, 0x22, 0x04,
792 0x37, 0x0a, 0x21,
793 0x37, 0x0d, 0xc0,
794 0x37, 0x18, 0x88,
795 0x37, 0x21, 0x00,
796 0x37, 0x22, 0x00,
797 0x37, 0x23, 0x00,
798 0x37, 0x38, 0x00,
799 0x38, 0x03, 0x00,
800 0x38, 0x07, 0xbf,
801 0x38, 0x08, 0x06,
802 0x38, 0x09, 0x40,
803 0x38, 0x0a, 0x04,
804 0x38, 0x0b, 0xb0,
805 0x38, 0x0c, 0x06,
806 0x38, 0x0d, 0xa4,
807 0x38, 0x0e, 0x05,
808 0x38, 0x0f, 0x0e,
809 0x38, 0x11, 0x08,
810 0x38, 0x13, 0x08,
811 0x38, 0x14, 0x11,
812 0x38, 0x15, 0x11,
813 0x38, 0x20, 0xc0,
814 0x38, 0x21, 0x00,
815 0x40, 0x08, 0x02,
816 0x40, 0x09, 0x09,
817 0x48, 0x37, 0x18,
818 0x01, 0x00, 0x01,
819
820};
821
822static kal_uint8 OV2680_fullsize_15fps[]={
823 0x01, 0x00, 0x00,
824 0x30, 0x86, 0x01,
825 0x35, 0x01, 0x4e,
826 0x35, 0x02, 0xe0,
827 0x36, 0x20, 0x24,
828 0x36, 0x21, 0x34,
829 0x36, 0x22, 0x03,
830 0x37, 0x0a, 0x21,
831 0x37, 0x0d, 0x00,
832 0x37, 0x18, 0x80,
833 0x37, 0x21, 0x09,
834 0x37, 0x22, 0x0b,
835 0x37, 0x23, 0x48,
836 0x37, 0x38, 0x99,
837 0x38, 0x03, 0x00,
838 0x38, 0x07, 0xbf,
839 0x38, 0x08, 0x06,
840 0x38, 0x09, 0x40,
841 0x38, 0x0a, 0x04,
842 0x38, 0x0b, 0xb0,
843 0x38, 0x0c, 0x06,
844 0x38, 0x0d, 0xa4,
845 0x38, 0x0e, 0x05,
846 0x38, 0x0f, 0x0e,
847 0x38, 0x11, 0x08,
848 0x38, 0x13, 0x08,
849 0x38, 0x14, 0x11,
850 0x38, 0x15, 0x11,
851 0x38, 0x20, 0xc0,
852 0x38, 0x21, 0x00,
853 0x40, 0x08, 0x02,
854 0x40, 0x09, 0x09,
855 0x48, 0x37, 0x30,
856 0x01, 0x00, 0x01,
857
858};
859
860//static kal_uint8 OV2680_capture[]={
861// };
862
863#else
864static void OV2680MIPI_Sensor_Init(void)
865{
866 /*
867 @@Initial - MIPI 4-Lane 4608x3456 10-bit 15fps_640Mbps_lane
868 100 99 4608 3456
869 100 98 1 1
870 102 81 0 ffff
871 102 84 1 ffff
872 102 3601 5dc
873 102 3f00 da2
874 102 910 31
875 */
876
877 //;Reset
878 OV2680_write_cmos_sensor(0x0103, 0x01);
879 mdelay(50);
880 OV2680_write_cmos_sensor(0x3002, 0x00);
881 OV2680_write_cmos_sensor(0x3016, 0x1c);
882 OV2680_write_cmos_sensor(0x3018, 0x44);
883 OV2680_write_cmos_sensor(0x3020, 0x00);
884 OV2680_write_cmos_sensor(0x3080, 0x02);
885 OV2680_write_cmos_sensor(0x3082, 0x37);
886 OV2680_write_cmos_sensor(0x3084, 0x09);
887 OV2680_write_cmos_sensor(0x3085, 0x04);
888 OV2680_write_cmos_sensor(0x3086, 0x01);
889 OV2680_write_cmos_sensor(0x3501, 0x26);
890 OV2680_write_cmos_sensor(0x3502, 0x40);
891 OV2680_write_cmos_sensor(0x3503, 0x03);
892 OV2680_write_cmos_sensor(0x350b, 0x36);
893 OV2680_write_cmos_sensor(0x3600, 0xb4);
894 OV2680_write_cmos_sensor(0x3603, 0x39);
895 OV2680_write_cmos_sensor(0x3604, 0x24);
896 OV2680_write_cmos_sensor(0x3605, 0x00);
897 OV2680_write_cmos_sensor(0x3620, 0x26);
898 OV2680_write_cmos_sensor(0x3621, 0x37);
899 OV2680_write_cmos_sensor(0x3622, 0x04);
900 OV2680_write_cmos_sensor(0x3628, 0x00);
901 OV2680_write_cmos_sensor(0x3705, 0x3c);
902 OV2680_write_cmos_sensor(0x370c, 0x50);
903 OV2680_write_cmos_sensor(0x370d, 0xc0);
904 OV2680_write_cmos_sensor(0x3718, 0x88);
905 OV2680_write_cmos_sensor(0x3720, 0x00);
906 OV2680_write_cmos_sensor(0x3721, 0x00);
907 OV2680_write_cmos_sensor(0x3722, 0x00);
908 OV2680_write_cmos_sensor(0x3723, 0x00);
909 OV2680_write_cmos_sensor(0x3738, 0x00);
910 OV2680_write_cmos_sensor(0x370a, 0x23);
911 OV2680_write_cmos_sensor(0x3717, 0x58);
912 OV2680_write_cmos_sensor(0x3781, 0x80);
913 OV2680_write_cmos_sensor(0x3784, 0x0c); //
914 OV2680_write_cmos_sensor(0x3789, 0x60);
915 OV2680_write_cmos_sensor(0x3800, 0x00);
916 OV2680_write_cmos_sensor(0x3801, 0x00);
917 OV2680_write_cmos_sensor(0x3802, 0x00);
918 OV2680_write_cmos_sensor(0x3803, 0x00);
919 OV2680_write_cmos_sensor(0x3804, 0x06);
920 OV2680_write_cmos_sensor(0x3805, 0x4f);
921 OV2680_write_cmos_sensor(0x3806, 0x04);
922 OV2680_write_cmos_sensor(0x3807, 0xbf);
923 OV2680_write_cmos_sensor(0x3808, 0x03);
924 OV2680_write_cmos_sensor(0x3809, 0x20);
925 OV2680_write_cmos_sensor(0x380a, 0x02);
926 OV2680_write_cmos_sensor(0x380b, 0x58);
927 OV2680_write_cmos_sensor(0x380c, 0x06);
928 OV2680_write_cmos_sensor(0x380d, 0xac);
929 OV2680_write_cmos_sensor(0x380e, 0x02);
930 OV2680_write_cmos_sensor(0x380f, 0x84);
931 OV2680_write_cmos_sensor(0x3810, 0x00);
932 OV2680_write_cmos_sensor(0x3811, 0x04);
933 OV2680_write_cmos_sensor(0x3812, 0x00);
934 OV2680_write_cmos_sensor(0x3813, 0x04);
935 OV2680_write_cmos_sensor(0x3814, 0x31);
936 OV2680_write_cmos_sensor(0x3815, 0x31);
937 OV2680_write_cmos_sensor(0x3819, 0x04);
938 OV2680_write_cmos_sensor(0x3820, 0xc2);
939 OV2680_write_cmos_sensor(0x3821, 0x01);
940 OV2680_write_cmos_sensor(0x4000, 0x81);
941 OV2680_write_cmos_sensor(0x4001, 0x40);
942 OV2680_write_cmos_sensor(0x4008, 0x00);
943 OV2680_write_cmos_sensor(0x4009, 0x03);
944 OV2680_write_cmos_sensor(0x4602, 0x02);
945 OV2680_write_cmos_sensor(0x481f, 0x36);
946 OV2680_write_cmos_sensor(0x4825, 0x36);
947 OV2680_write_cmos_sensor(0x4837, 0x30);
948 OV2680_write_cmos_sensor(0x5002, 0x30);
949 OV2680_write_cmos_sensor(0x5080, 0x00);
950 OV2680_write_cmos_sensor(0x5081, 0x41);
951 OV2680_write_cmos_sensor(0x3021, 0x23);
952 OV2680_write_cmos_sensor(0x0100, 0x01);
953
954
955 mdelay(40);
956
957
958} /* OV2680MIPI_Sensor_Init */ /* OV2680MIPI_Sensor_Init */
959
960static void OV2680MIPI_Sensor_preview(void)
961{
962 //-------------------------------------------------------------------------------
963
964
965 SENSORDB("OV2680MIPIPreview Setting \n");
966
967 OV2680_write_cmos_sensor(0x0100, 0x00);
968 OV2680_write_cmos_sensor(0x3086, 0x00);
969 OV2680_write_cmos_sensor(0x3501, 0x4e);
970 OV2680_write_cmos_sensor(0x3502, 0xe0);
971 OV2680_write_cmos_sensor(0x3620, 0x26);
972 OV2680_write_cmos_sensor(0x3621, 0x37);
973 OV2680_write_cmos_sensor(0x3622, 0x04);
974 OV2680_write_cmos_sensor(0x370a, 0x21);
975 OV2680_write_cmos_sensor(0x370d, 0xc0);
976 OV2680_write_cmos_sensor(0x3718, 0x88);
977 OV2680_write_cmos_sensor(0x3721, 0x00);
978 OV2680_write_cmos_sensor(0x3722, 0x00);
979 OV2680_write_cmos_sensor(0x3723, 0x00);
980 OV2680_write_cmos_sensor(0x3738, 0x00);
981 OV2680_write_cmos_sensor(0x3803, 0x00);
982 OV2680_write_cmos_sensor(0x3807, 0xbf);
983 OV2680_write_cmos_sensor(0x3808, 0x06);
984 OV2680_write_cmos_sensor(0x3809, 0x40);
985 OV2680_write_cmos_sensor(0x380a, 0x04);
986 OV2680_write_cmos_sensor(0x380b, 0xb0);
987 OV2680_write_cmos_sensor(0x380c, 0x06);
988 OV2680_write_cmos_sensor(0x380d, 0xa4);
989 OV2680_write_cmos_sensor(0x380e, 0x05);
990 OV2680_write_cmos_sensor(0x380f, 0x0e);
991 OV2680_write_cmos_sensor(0x3811, 0x08);
992 OV2680_write_cmos_sensor(0x3813, 0x08);
993 OV2680_write_cmos_sensor(0x3814, 0x11);
994 OV2680_write_cmos_sensor(0x3815, 0x11);
4b9e9796
S
995 OV2680_write_cmos_sensor(0x3820, 0xc0);
996 OV2680_write_cmos_sensor(0x3821, 0x00);
6fa3eb70
S
997 OV2680_write_cmos_sensor(0x4008, 0x02);
998 OV2680_write_cmos_sensor(0x4009, 0x09);
999 OV2680_write_cmos_sensor(0x4837, 0x18);
1000 OV2680_write_cmos_sensor(0x0100, 0x01);
1001 mdelay(60);
1002
1003}
1004static void OV2680MIPI_Sensor_2M_15fps(void)
1005{
1006 //-------------------------------------------------------------------------------
1007
1008
1009 SENSORDB("OV2680MIPIPreview Setting \n");
1010
1011 OV2680_write_cmos_sensor(0x0100, 0x00);
1012 OV2680_write_cmos_sensor(0x3086, 0x01);
1013 OV2680_write_cmos_sensor(0x3501, 0x4e);
1014 OV2680_write_cmos_sensor(0x3502, 0xe0);
1015 OV2680_write_cmos_sensor(0x3620, 0x24);
1016 OV2680_write_cmos_sensor(0x3621, 0x34);
1017 OV2680_write_cmos_sensor(0x3622, 0x03);
1018 OV2680_write_cmos_sensor(0x370a, 0x21);
1019 OV2680_write_cmos_sensor(0x370d, 0x00);
1020 OV2680_write_cmos_sensor(0x3718, 0x80);
1021 OV2680_write_cmos_sensor(0x3721, 0x09);
1022 OV2680_write_cmos_sensor(0x3722, 0x0b);
1023 OV2680_write_cmos_sensor(0x3723, 0x48);
1024 OV2680_write_cmos_sensor(0x3738, 0x99);
1025 OV2680_write_cmos_sensor(0x3803, 0x00);
1026 OV2680_write_cmos_sensor(0x3807, 0xbf);
1027 OV2680_write_cmos_sensor(0x3808, 0x06);
1028 OV2680_write_cmos_sensor(0x3809, 0x40);
1029 OV2680_write_cmos_sensor(0x380a, 0x04);
1030 OV2680_write_cmos_sensor(0x380b, 0xb0);
1031 OV2680_write_cmos_sensor(0x380c, 0x06);
1032 OV2680_write_cmos_sensor(0x380d, 0xa4);
1033 OV2680_write_cmos_sensor(0x380e, 0x05);
1034 OV2680_write_cmos_sensor(0x380f, 0x0e);
1035 OV2680_write_cmos_sensor(0x3811, 0x08);
1036 OV2680_write_cmos_sensor(0x3813, 0x08);
1037 OV2680_write_cmos_sensor(0x3814, 0x11);
1038 OV2680_write_cmos_sensor(0x3815, 0x11);
4b9e9796
S
1039 OV2680_write_cmos_sensor(0x3820, 0xc0);//0xc4
1040 OV2680_write_cmos_sensor(0x3821, 0x00);//0x04
6fa3eb70
S
1041 OV2680_write_cmos_sensor(0x4008, 0x02);
1042 OV2680_write_cmos_sensor(0x4009, 0x09);
1043 OV2680_write_cmos_sensor(0x4837, 0x30);
1044 OV2680_write_cmos_sensor(0x0100, 0x01);
1045 mdelay(60);
1046
1047}
1048
1049
1050#endif
1051#ifdef USE_I2C_MULTIWRITE
1052static UINT32 OV2680MultiWrite(kal_uint8* pData, int iLen)
1053{
1054 int totalCnt = 0, len = 0;
1055 int transfer_len, transac_len=3;
1056 kal_uint8* pBuf=NULL;
1057 dma_addr_t dmaHandle;
1058 pBuf = (kal_uint8*)kmalloc(1024, GFP_KERNEL);
1059
1060 totalCnt = iLen;
1061 transfer_len = totalCnt / transac_len;
1062 len = (transfer_len<<8)|transac_len;
1063
1064 SENSORDB("Total Count = %d, Len = 0x%x\n", totalCnt,len);
1065 memcpy(pBuf, pData, totalCnt );
1066 dmaHandle = dma_map_single(NULL, pBuf, 1024, DMA_TO_DEVICE);
1067 Ov2680_multi_write_cmos_sensor(dmaHandle, len);
1068 dma_unmap_single(NULL, dmaHandle, 1024, DMA_TO_DEVICE);
1069
1070 SENSORDB("OV2680MultiWrite exit :\n ");
1071
1072}
1073#endif
1074
1075UINT32 OV2680Open(void)
1076{
1077 kal_uint16 sensor_id=0;
1078 int i, iLen;
1079 const kal_uint16 sccb_writeid[] = {OV2680_SLAVE_WRITE_ID_1,OV2680_SLAVE_WRITE_ID_2};
1080 SENSORDB("OV2680Open\n");
1081
1082
1083 spin_lock(&OV2680_drv_lock);
1084 OV2680_sensor.is_zsd = KAL_FALSE; //for zsd full size preview
1085 OV2680_sensor.is_zsd_cap = KAL_FALSE;
1086 OV2680_sensor.is_autofliker = KAL_FALSE; //for autofliker.
1087 OV2680_sensor.pv_mode = KAL_FALSE;
1088 OV2680_sensor.pclk = OV2680_PREVIEW_CLK;
1089 spin_unlock(&OV2680_drv_lock);
1090
1091 for(i = 0; i <(sizeof(sccb_writeid)/sizeof(sccb_writeid[0])); i++)
1092 {
1093 spin_lock(&OV2680_drv_lock);
1094 OV2680_sensor.write_id = sccb_writeid[i];
1095 OV2680_sensor.read_id = (sccb_writeid[i]|0x01);
1096 spin_unlock(&OV2680_drv_lock);
1097
1098 sensor_id=((OV2680_read_cmos_sensor(0x300A) << 8) | OV2680_read_cmos_sensor(0x300B));
1099
1100#ifdef OV2680_DRIVER_TRACE
1101 SENSORDB("OV2680Open, sensor_id:%x \n",sensor_id);
1102#endif
1103 if(OV2680MIPI_SENSOR_ID == sensor_id)
1104 {
1105 SENSORDB("OV2680 slave write id:%x \n",OV2680_sensor.write_id);
1106 break;
1107 }
1108 }
1109
1110 // check if sensor ID correct
1111 if (sensor_id != OV2680MIPI_SENSOR_ID)
1112 {
1113 SENSORDB("OV2680 Check ID fails! \n");
1114
1115 SENSORDB("[Warning]OV2680GetSensorID, sensor_id:%x \n",sensor_id);
1116 //sensor_id = OV2680_SENSOR_ID;
1117 sensor_id = 0xFFFFFFFF;
1118 return ERROR_SENSOR_CONNECT_FAIL;
1119 }
1120
1121 //OV2680_global_setting();
1122 #ifdef USE_I2C_MULTIWRITE
1123 OV2680_write_cmos_sensor(0x0103, 0x01);
1124 mdelay(30);
1125 iLen = ARRAY_SIZE(OV2680_init);
1126 OV2680MultiWrite(OV2680_init, iLen);
1127 mdelay(40);
1128
1129 iLen = ARRAY_SIZE(OV2680_preview);
1130 OV2680MultiWrite(OV2680_preview, iLen);
1131 mdelay(60);
1132
1133 #else
1134 OV2680MIPI_Sensor_Init();
1135 OV2680MIPI_Sensor_preview();
1136
1137 #endif
1138
1139 spin_lock(&OV2680_drv_lock);
1140 OV2680_sensor.dummy_pixels = 0;
1141 OV2680_sensor.dummy_lines = 0;
1142 OV2680_sensor.line_length = OV2680_PV_PERIOD_PIXEL_NUMS;
1143 OV2680_sensor.frame_height = OV2680_PV_PERIOD_LINE_NUMS;
1144 OV2680_sensor.pclk = OV2680_PREVIEW_CLK;
1145 spin_unlock(&OV2680_drv_lock);
1146
1147 OV2680_Set_Dummy(0, 0); /* modify dummy_pixel must gen AE table again */
1148
1149 SENSORDB("open End \n");
1150
1151 return ERROR_NONE;
1152} /* OV2680Open */
1153
1154/*************************************************************************
1155* FUNCTION
1156* OV5642GetSensorID
1157*
1158* DESCRIPTION
1159* This function get the sensor ID
1160*
1161* PARAMETERS
1162* *sensorID : return the sensor ID
1163*
1164* RETURNS
1165* None
1166*
1167* GLOBALS AFFECTED
1168*
1169*************************************************************************/
1170UINT32 OV2680GetSensorID(UINT32 *sensorID)
1171{
1172 //added by mandrave
1173 int i;
1174 const kal_uint16 sccb_writeid[] = {OV2680_SLAVE_WRITE_ID_1, OV2680_SLAVE_WRITE_ID_2};
1175
1176 printk("alphaxiang OV2680GetSensorID enter,\n");
1177 for(i = 0; i <(sizeof(sccb_writeid)/sizeof(sccb_writeid[0])); i++)
1178 {
1179 spin_lock(&OV2680_drv_lock);
1180 OV2680_sensor.write_id = sccb_writeid[i];
1181 OV2680_sensor.read_id = (sccb_writeid[i]|0x01);
1182 spin_unlock(&OV2680_drv_lock);
1183
1184 *sensorID=((OV2680_read_cmos_sensor(0x300A) << 8) | OV2680_read_cmos_sensor(0x300B));
1185
1186
1187 printk("alphaxiang OV2680GetSensorID, sensor_id:%x \n",*sensorID);
1188
1189 if(OV2680MIPI_SENSOR_ID == *sensorID)
1190 {
1191 SENSORDB("OV2680 slave write id:%x \n",OV2680_sensor.write_id);
1192 break;
1193 }
1194 }
1195
1196 // check if sensor ID correct
1197 if (*sensorID != OV2680MIPI_SENSOR_ID)
1198 {
1199 SENSORDB("[Warning]OV2680GetSensorID, sensor_id:%x \n",*sensorID);
1200 *sensorID = 0xFFFFFFFF;
1201 return ERROR_SENSOR_CONNECT_FAIL;
1202 }
1203 SENSORDB("OV2680GetSensorID exit,\n");
1204 return ERROR_NONE;
1205}
1206
1207/*************************************************************************
1208* FUNCTION
1209* OV2680Close
1210*
1211* DESCRIPTION
1212* This function is to turn off sensor module power.
1213*
1214* PARAMETERS
1215* None
1216*
1217* RETURNS
1218* None
1219*
1220* GLOBALS AFFECTED
1221*
1222*************************************************************************/
1223UINT32 OV2680Close(void)
1224{
1225#ifdef OV2680_DRIVER_TRACE
1226 SENSORDB("OV2680Close\n");
1227#endif
1228
1229 return ERROR_NONE;
1230} /* OV2680Close */
1231
1232/*************************************************************************
1233* FUNCTION
1234* OV2680Preview
1235*
1236* DESCRIPTION
1237* This function start the sensor preview.
1238*
1239* PARAMETERS
1240* *image_window : address pointer of pixel numbers in one period of HSYNC
1241* *sensor_config_data : address pointer of line numbers in one period of VSYNC
1242*
1243* RETURNS
1244* None
1245*
1246* GLOBALS AFFECTED
1247*
1248*************************************************************************/
1249UINT32 OV2680Preview(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
1250 MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
1251{
1252 kal_uint16 dummy_line;
1253 int iLen;
1254#ifdef OV2680_DRIVER_TRACE
1255 SENSORDB("OV2680Preview \n");
1256#endif
1257 spin_lock(&OV2680_drv_lock);
1258 OV2680_sensor.pv_mode = KAL_TRUE;
1259 OV2680_sensor.is_zsd = KAL_FALSE;
1260 spin_unlock(&OV2680_drv_lock);
1261
1262 spin_lock(&OV2680_drv_lock);
1263 OV2680_sensor.video_mode = KAL_FALSE;
1264 spin_unlock(&OV2680_drv_lock);
1265 dummy_line = 0;
1266 //OV2680_sensor.frame_height = OV2680_PV_PERIOD_LINE_NUMS;
1267 OV2680_sensor.dummy_pixels = 0;
1268 OV2680_sensor.dummy_lines = 0;
1269 OV2680_sensor.line_length = OV2680_PV_PERIOD_PIXEL_NUMS;
1270 OV2680_sensor.frame_height = OV2680_PV_PERIOD_LINE_NUMS + dummy_line;
1271 OV2680_sensor.pclk = OV2680_PREVIEW_CLK;
1272
1273 OV2680_Set_Dummy(0, dummy_line); /* modify dummy_pixel must gen AE table again */
1274
1275 return ERROR_NONE;
1276
1277} /* OV2680Preview */
1278
1279
1280/*************************************************************************
1281* FUNCTION
1282* OV2680VIDEO
1283*
1284* DESCRIPTION
1285* This function start the sensor Video preview.
1286*
1287* PARAMETERS
1288* *image_window : address pointer of pixel numbers in one period of HSYNC
1289* *sensor_config_data : address pointer of line numbers in one period of VSYNC
1290*
1291* RETURNS
1292* None
1293*
1294* GLOBALS AFFECTED
1295*
1296*************************************************************************/
1297
1298UINT32 OV2680VIDEO(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
1299 MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
1300{
1301 kal_uint16 dummy_line;
1302 kal_uint16 ret;
1303 int iLen;
1304#ifdef OV2680_DRIVER_TRACE
1305 SENSORDB("OV2680VIDEO \n");
1306#endif
1307 spin_lock(&OV2680_drv_lock);
1308 OV2680_sensor.pv_mode = KAL_FALSE;
1309 OV2680_sensor.is_zsd = KAL_FALSE;
1310 spin_unlock(&OV2680_drv_lock);
1311
1312 spin_lock(&OV2680_drv_lock);
1313 OV2680_sensor.video_mode = KAL_TRUE;
1314 spin_unlock(&OV2680_drv_lock);
1315 dummy_line = 0;
1316
1317 //OV2680_sensor.frame_height = OV2680_PV_PERIOD_LINE_NUMS;
1318 OV2680_sensor.dummy_pixels = 0;
1319 OV2680_sensor.dummy_lines = 0;
1320 OV2680_sensor.line_length = OV2680_PV_PERIOD_PIXEL_NUMS;
1321 OV2680_sensor.frame_height = OV2680_PV_PERIOD_LINE_NUMS + dummy_line;
1322 OV2680_sensor.pclk = OV2680_PREVIEW_CLK;
1323
1324 OV2680_Set_Dummy(0, dummy_line); /* modify dummy_pixel must gen AE table again */
1325
1326 return ERROR_NONE;
1327
1328} /* OV2680VIDEO */
1329
1330
1331/*************************************************************************
1332* FUNCTION
1333* OV2680ZsdPreview
1334*
1335* DESCRIPTION
1336* This function setup the CMOS sensor in Full Size output mode
1337*
1338* PARAMETERS
1339*
1340* RETURNS
1341* None
1342*
1343* GLOBALS AFFECTED
1344*
1345*************************************************************************/
1346UINT32 OV2680ZsdPreview(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
1347 MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
1348
1349{
1350 kal_uint16 dummy_pixel = 0;
1351 kal_uint16 dummy_line = 0;
1352 kal_uint16 ret;
1353 int iLen;
1354#ifdef OV2680_DRIVER_TRACE
1355 SENSORDB("OV2680ZsdPreview \n");
1356#endif
1357
1358 spin_lock(&OV2680_drv_lock);
1359 OV2680_sensor.pv_mode = KAL_FALSE;
1360 OV2680_sensor.is_zsd = KAL_TRUE;
1361 spin_unlock(&OV2680_drv_lock);
1362
1363 spin_lock(&OV2680_drv_lock);
1364 OV2680_sensor.video_mode = KAL_FALSE;
1365 spin_unlock(&OV2680_drv_lock);
1366 dummy_line = 0;
1367 //OV2680_sensor.frame_height = OV2680_PV_PERIOD_LINE_NUMS;
1368 OV2680_sensor.dummy_pixels = 0;
1369 OV2680_sensor.dummy_lines = 0;
1370 OV2680_sensor.line_length = OV2680_PV_PERIOD_PIXEL_NUMS;
1371 OV2680_sensor.frame_height = OV2680_PV_PERIOD_LINE_NUMS + dummy_line;
1372 OV2680_sensor.pclk = OV2680_PREVIEW_CLK;
1373
1374 OV2680_Set_Dummy(0, dummy_line); /* modify dummy_pixel must gen AE table again */
1375 return ERROR_NONE;
1376}
1377
1378
1379
1380/*************************************************************************
1381* FUNCTION
1382*OV2680Capture
1383*
1384* DESCRIPTION
1385* This function setup the CMOS sensor in capture MY_OUTPUT mode
1386*
1387* PARAMETERS
1388*
1389* RETURNS
1390* None
1391*
1392* GLOBALS AFFECTED
1393*
1394*************************************************************************/
1395UINT32 OV2680Capture(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
1396 MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
1397{
1398 kal_uint16 dummy_pixel = 0;
1399 kal_uint16 dummy_line = 0;
1400 kal_uint16 ret;
1401 int iLen;
1402#ifdef OV2680_DRIVER_TRACE
1403 SENSORDB("OV2680Capture start test1\n");
1404#endif
1405
1406 spin_lock(&OV2680_drv_lock);
1407 OV2680_sensor.video_mode = KAL_FALSE;
1408 //OV2680_sensor.is_autofliker = KAL_FALSE;
1409 OV2680_sensor.pv_mode = KAL_FALSE;
1410 spin_unlock(&OV2680_drv_lock);
1411
1412 dummy_line = 0;
1413 //OV2680_sensor.frame_height = OV2680_PV_PERIOD_LINE_NUMS;
1414 OV2680_sensor.dummy_pixels = 0;
1415 OV2680_sensor.dummy_lines = 0;
1416 OV2680_sensor.line_length = OV2680_PV_PERIOD_PIXEL_NUMS;
1417 OV2680_sensor.frame_height = OV2680_PV_PERIOD_LINE_NUMS + dummy_line;
1418 OV2680_sensor.pclk = OV2680_PREVIEW_CLK;
1419
1420 OV2680_Set_Dummy(0, dummy_line); /* modify dummy_pixel must gen AE table again */
1421
1422
1423 return ERROR_NONE;
1424} /* OV2680_Capture() */
1425
1426
1427UINT32 OV26803DPreview(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
1428 MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
1429{
1430 kal_uint16 dummy_line;
1431 kal_uint16 ret;
1432 int iLen;
1433#ifdef OV2680_DRIVER_TRACE
1434 SENSORDB("OV26803DPreview \n");
1435#endif
1436
1437 spin_lock(&OV2680_drv_lock);
1438 OV2680_sensor.pv_mode = KAL_TRUE;
1439 spin_unlock(&OV2680_drv_lock);
1440
1441 spin_lock(&OV2680_drv_lock);
1442 OV2680_sensor.video_mode = KAL_FALSE;
1443 spin_unlock(&OV2680_drv_lock);
1444
1445 return ERROR_NONE;
1446
1447}
1448
1449
1450UINT32 OV2680GetResolution(MSDK_SENSOR_RESOLUTION_INFO_STRUCT *pSensorResolution)
1451{
1452#ifdef OV2680_DRIVER_TRACE
1453 SENSORDB("OV2680GetResolution \n");
1454#endif
1455 pSensorResolution->SensorFullWidth=OV2680_IMAGE_SENSOR_FULL_WIDTH;
1456 pSensorResolution->SensorFullHeight=OV2680_IMAGE_SENSOR_FULL_HEIGHT;
1457 pSensorResolution->SensorPreviewWidth=OV2680_IMAGE_SENSOR_PV_WIDTH;
1458 pSensorResolution->SensorPreviewHeight=OV2680_IMAGE_SENSOR_PV_HEIGHT;
1459 pSensorResolution->SensorVideoWidth=OV2680_IMAGE_SENSOR_VIDEO_WIDTH;
1460 pSensorResolution->SensorVideoHeight=OV2680_IMAGE_SENSOR_VIDEO_HEIGHT;
1461 pSensorResolution->Sensor3DFullWidth=OV2680_IMAGE_SENSOR_3D_FULL_WIDTH;
1462 pSensorResolution->Sensor3DFullHeight=OV2680_IMAGE_SENSOR_3D_FULL_HEIGHT;
1463 pSensorResolution->Sensor3DPreviewWidth=OV2680_IMAGE_SENSOR_3D_PV_WIDTH;
1464 pSensorResolution->Sensor3DPreviewHeight=OV2680_IMAGE_SENSOR_3D_PV_HEIGHT;
1465 pSensorResolution->Sensor3DVideoWidth=OV2680_IMAGE_SENSOR_3D_VIDEO_WIDTH;
1466 pSensorResolution->Sensor3DVideoHeight=OV2680_IMAGE_SENSOR_3D_VIDEO_HEIGHT;
1467 return ERROR_NONE;
1468}/* OV2680GetResolution() */
1469
1470UINT32 OV2680GetInfo(MSDK_SCENARIO_ID_ENUM ScenarioId,
1471 MSDK_SENSOR_INFO_STRUCT *pSensorInfo,
1472 MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData)
1473{
1474#ifdef OV2680_DRIVER_TRACE
1475