import PULS_20180308
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / imgsensor / src / mt8127 / hi708_yuv / hi708yuv_Sensor.c
1
2 /* Copyright Statement:
3 *
4 * This software/firmware and related documentation ("MediaTek Software") are
5 * protected under relevant copyright laws. The information contained herein
6 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
7 * Without the prior written permission of MediaTek inc. and/or its licensors,
8 * any reproduction, modification, use or disclosure of MediaTek Software,
9 * and information contained herein, in whole or in part, shall be strictly prohibited.
10 */
11 /* MediaTek Inc. (C) 2010. All rights reserved.
12 *
13 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
14 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
15 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
16 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
19 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
20 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
21 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
22 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
23 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
24 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
25 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
26 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
27 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
28 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
29 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
30 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
31 *
32 * The following software/firmware and/or related documentation ("MediaTek Software")
33 * have been modified by MediaTek Inc. All revisions are subject to any receiver's
34 * applicable license agreements with MediaTek Inc.
35 */
36
37
38 /*****************************************************************************
39 * Copyright Statement:
40 * --------------------
41 * This software is protected by Copyright and the information contained
42 * herein is confidential. The software may not be copied and the information
43 * contained herein may not be used or disclosed except with the written
44 * permission of MediaTek Inc. (C) 2008
45 *
46 * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
47 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
48 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
49 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
50 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
51 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
52 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
53 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
54 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
55 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
56 * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
57 * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
58 *
59 * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
60 * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
61 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
62 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
63 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
64 *
65 * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
66 * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
67 * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
68 * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
69 * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
70 *
71 *****************************************************************************//*****************************************************************************
72 *
73 * Filename:
74 * ---------
75 * sensor.c
76 *
77 * Project:
78 * --------
79 * DUMA
80 *
81 * Description:
82 * ------------
83 * Source code of Sensor driver
84 *
85 *
86 * Author:
87 * -------
88 * PC Huang (MTK02204)
89 *
90 *============================================================================
91 * HISTORY
92 * Below this line, this part is controlled by CC/CQ. DO NOT MODIFY!!
93 *------------------------------------------------------------------------------
94 * $Revision:$
95 * $Modtime:$
96 * $Log:$
97 *
98 * 07 11 2011 jun.pei
99 * [ALPS00059464] hi708 sensor check in
100 * .
101 *
102 *
103 *------------------------------------------------------------------------------
104 * Upper this line, this part is controlled by CC/CQ. DO NOT MODIFY!!
105 *============================================================================
106 ****************************************************************************/
107 #include <linux/videodev2.h>
108 #include <linux/i2c.h>
109 #include <linux/platform_device.h>
110 #include <linux/delay.h>
111 #include <linux/cdev.h>
112 #include <linux/uaccess.h>
113 #include <linux/fs.h>
114 #include <asm/atomic.h>
115 //#include <mach/mt6516_pll.h>
116
117 #include "kd_camera_hw.h"
118 #include "kd_imgsensor.h"
119 #include "kd_imgsensor_define.h"
120 #include "kd_imgsensor_errcode.h"
121 #include "kd_camera_feature.h"
122
123 #include "hi708yuv_Sensor.h"
124 #include "hi708yuv_Camera_Sensor_para.h"
125 #include "hi708yuv_CameraCustomized.h"
126
127 #define HI708YUV_DEBUG
128 #ifdef HI708YUV_DEBUG
129 #define SENSORDB printk
130 #else
131
132 #define SENSORDB(x,...)
133 #endif
134
135 #if 0
136 extern int iReadReg(u16 a_u2Addr , u8 * a_puBuff , u16 i2cId);
137 extern int iWriteReg(u16 a_u2Addr , u32 a_u4Data , u32 a_u4Bytes , u16 i2cId);
138 static int sensor_id_fail = 0;
139 #define HI708_write_cmos_sensor(addr, para) iWriteReg((u16) addr , (u32) para ,1,HI708_WRITE_ID)
140 #define HI708_write_cmos_sensor_2(addr, para, bytes) iWriteReg((u16) addr , (u32) para ,bytes,HI708_WRITE_ID)
141 kal_uint16 HI708_read_cmos_sensor(kal_uint32 addr)
142 {
143 kal_uint16 get_byte=0;
144 iReadReg((u16) addr ,(u8*)&get_byte,HI708_WRITE_ID);
145 return get_byte;
146 }
147
148 #endif
149
150 #if defined(DTV_NMI5625) || defined(ATV_NMI168H)
151 extern bool g_bIsAtvStart;
152 #endif
153
154 static DEFINE_SPINLOCK(hi708_yuv_drv_lock);
155
156 extern int iReadRegI2C(u8 *a_pSendData , u16 a_sizeSendData, u8 * a_pRecvData, u16 a_sizeRecvData, u16 i2cId);
157 extern int iWriteRegI2C(u8 *a_pSendData , u16 a_sizeSendData, u16 i2cId);
158 kal_uint16 HI708_write_cmos_sensor(kal_uint8 addr, kal_uint8 para)
159 {
160 char puSendCmd[2] = {(char)(addr & 0xFF) , (char)(para & 0xFF)};
161 iWriteRegI2C(puSendCmd , 2,HI708_WRITE_ID);
162 return 0;
163 }
164 kal_uint16 HI708_read_cmos_sensor(kal_uint8 addr)
165 {
166 kal_uint16 get_byte=0;
167 char puSendCmd = { (char)(addr & 0xFF) };
168 iReadRegI2C(&puSendCmd , 1, (u8*)&get_byte,1,HI708_WRITE_ID);
169 return get_byte;
170 }
171
172 #define HI708_LOAD_FROM_T_FLASH
173 #ifdef HI708_LOAD_FROM_T_FLASH
174
175 static kal_uint8 fromsd = 0;
176 kal_uint16 HI708_write_cmos_sensor(kal_uint8 addr, kal_uint8 para);
177
178 #define HI708_OP_CODE_INI 0x00 /* Initial value. */
179 #define HI708_OP_CODE_REG 0x01 /* Register */
180 #define HI708_OP_CODE_DLY 0x02 /* Delay */
181 #define HI708_OP_CODE_END 0x03 /* End of initial setting. */
182
183 typedef struct
184 {
185 u16 init_reg;
186 u16 init_val; /* Save the register value and delay tick */
187 u8 op_code; /* 0 - Initial value, 1 - Register, 2 - Delay, 3 - End of setting. */
188 } HI708_initial_set_struct;
189
190 HI708_initial_set_struct HI708_Init_Reg[1000];
191
192 u32 strtol(const char *nptr, u8 base)
193 {
194 u8 ret;
195 if(!nptr || (base!=16 && base!=10 && base!=8))
196 {
197 printk("%s(): NULL pointer input\n", __FUNCTION__);
198 return -1;
199 }
200 for(ret=0; *nptr; nptr++)
201 {
202 if((base==16 && *nptr>='A' && *nptr<='F') ||
203 (base==16 && *nptr>='a' && *nptr<='f') ||
204 (base>=10 && *nptr>='0' && *nptr<='9') ||
205 (base>=8 && *nptr>='0' && *nptr<='7') )
206 {
207 ret *= base;
208 if(base==16 && *nptr>='A' && *nptr<='F')
209 ret += *nptr-'A'+10;
210 else if(base==16 && *nptr>='a' && *nptr<='f')
211 ret += *nptr-'a'+10;
212 else if(base>=10 && *nptr>='0' && *nptr<='9')
213 ret += *nptr-'0';
214 else if(base>=8 && *nptr>='0' && *nptr<='7')
215 ret += *nptr-'0';
216 }
217 else
218 return ret;
219 }
220 return ret;
221 }
222
223 u8 Hi708_Initialize_from_T_Flash()
224 {
225 //FS_HANDLE fp = -1; /* Default, no file opened. */
226 //u8 *data_buff = NULL;
227 u8 *curr_ptr = NULL;
228 u32 file_size = 0;
229 //u32 bytes_read = 0;
230 u32 i = 0, j = 0;
231 u8 func_ind[4] = {0}; /* REG or DLY */
232
233
234 struct file *fp;
235 mm_segment_t fs;
236 loff_t pos = 0;
237 static u8 data_buff[10*1024] ;
238
239 fp = filp_open("/storage/sdcard0/hi708_sd.dat", O_RDONLY , 0);
240 if (IS_ERR(fp)) {
241 printk("create file error\n");
242 return 2;//-1;
243 }
244 else
245 printk("Hi708_Initialize_from_T_Flash Open File Success\n");
246
247 fs = get_fs();
248 set_fs(KERNEL_DS);
249
250 file_size = vfs_llseek(fp, 0, SEEK_END);
251 vfs_read(fp, data_buff, file_size, &pos);
252 filp_close(fp, NULL);
253 set_fs(fs);
254
255 printk("1\n");
256
257 /* Start parse the setting witch read from t-flash. */
258 curr_ptr = data_buff;
259 while (curr_ptr < (data_buff + file_size))
260 {
261 while ((*curr_ptr == ' ') || (*curr_ptr == '\t'))/* Skip the Space & TAB */
262 curr_ptr++;
263
264 if (((*curr_ptr) == '/') && ((*(curr_ptr + 1)) == '*'))
265 {
266 while (!(((*curr_ptr) == '*') && ((*(curr_ptr + 1)) == '/')))
267 {
268 curr_ptr++; /* Skip block comment code. */
269 }
270
271 while (!((*curr_ptr == 0x0D) && (*(curr_ptr+1) == 0x0A)))
272 {
273 curr_ptr++;
274 }
275
276 curr_ptr += 2; /* Skip the enter line */
277
278 continue ;
279 }
280
281 if (((*curr_ptr) == '/') || ((*curr_ptr) == '{') || ((*curr_ptr) == '}')) /* Comment line, skip it. */
282 {
283 while (!((*curr_ptr == 0x0D) && (*(curr_ptr+1) == 0x0A)))
284 {
285 curr_ptr++;
286 }
287
288 curr_ptr += 2; /* Skip the enter line */
289
290 continue ;
291 }
292 /* This just content one enter line. */
293 if (((*curr_ptr) == 0x0D) && ((*(curr_ptr + 1)) == 0x0A))
294 {
295 curr_ptr += 2;
296 continue ;
297 }
298 //printk(" curr_ptr1 = %s\n",curr_ptr);
299 memcpy(func_ind, curr_ptr, 3);
300
301 if (strcmp((const char *)func_ind, "REG") == 0) /* REG */
302 {
303 curr_ptr += 6; /* Skip "REG(0x" or "DLY(" */
304 HI708_Init_Reg[i].op_code = HI708_OP_CODE_REG;
305
306 HI708_Init_Reg[i].init_reg = strtol((const char *)curr_ptr, 16);
307 curr_ptr += 5; /* Skip "00, 0x" */
308
309 HI708_Init_Reg[i].init_val = strtol((const char *)curr_ptr, 16);
310 curr_ptr += 4; /* Skip "00);" */
311 }
312 else /* DLY */
313 {
314 /* Need add delay for this setting. */
315 curr_ptr += 4;
316 HI708_Init_Reg[i].op_code = HI708_OP_CODE_DLY;
317
318 HI708_Init_Reg[i].init_reg = 0xFF;
319 HI708_Init_Reg[i].init_val = strtol((const char *)curr_ptr, 10); /* Get the delay ticks, the delay should less then 50 */
320 }
321 i++;
322
323 /* Skip to next line directly. */
324 while (!((*curr_ptr == 0x0D) && (*(curr_ptr+1) == 0x0A)))
325 {
326 curr_ptr++;
327 }
328 curr_ptr += 2;
329 }
330 printk("2\n");
331 /* (0xFFFF, 0xFFFF) means the end of initial setting. */
332 HI708_Init_Reg[i].op_code = HI708_OP_CODE_END;
333 HI708_Init_Reg[i].init_reg = 0xFF;
334 HI708_Init_Reg[i].init_val = 0xFF;
335 i++;
336 //for (j=0; j<i; j++)
337 //printk(" %x == %x\n",SP2528_Init_Reg[j].init_reg, SP2528_Init_Reg[j].init_val);
338
339 /* Start apply the initial setting to sensor. */
340 #if 1
341 for (j=0; j<i; j++)
342 {
343 if (HI708_Init_Reg[j].op_code == HI708_OP_CODE_END) /* End of the setting. */
344 {
345 break ;
346 }
347 else if (HI708_Init_Reg[j].op_code == HI708_OP_CODE_DLY)
348 {
349 msleep(HI708_Init_Reg[j].init_val); /* Delay */
350 }
351 else if (HI708_Init_Reg[j].op_code == HI708_OP_CODE_REG)
352 {
353 HI708_write_cmos_sensor((kal_uint8)HI708_Init_Reg[j].init_reg, (kal_uint8)HI708_Init_Reg[j].init_val);
354 }
355 else
356 {
357 printk("REG ERROR!\n");
358 }
359 }
360 #endif
361 printk("3\n");
362 return 1;
363 }
364
365 #endif
366
367 /*******************************************************************************
368 * // Adapter for Winmo typedef
369 ********************************************************************************/
370 #define WINMO_USE 0
371
372 #define Sleep(ms) mdelay(ms)
373 #define RETAILMSG(x,...)
374 #define TEXT
375
376
377 /*******************************************************************************
378 * follow is define by jun
379 ********************************************************************************/
380 MSDK_SENSOR_CONFIG_STRUCT HI708SensorConfigData;
381
382 static struct HI708_sensor_STRUCT HI708_sensor;
383 static kal_uint32 HI708_zoom_factor = 0;
384 static kal_bool HI708_night_flag = 0;
385 static int sensor_id_fail = 0;
386 const HI708_SENSOR_INIT_INFO HI708_Initial_Setting_Info[] =
387 {
388 {0x01,0xf1},
389 {0x01,0xf3},
390 {0x01,0xf1},
391
392 {0x11,0x93},//ForNoFixedFramerateBit[2]
393 {0x12,0x05},//PCLKINV
394
395 {0x20,0x00},
396 {0x21,0x04},
397 {0x22,0x00},
398 {0x23,0x04},
399
400 {0x24, 0x01},
401 {0x25, 0xe0},
402 {0x26, 0x02},
403 {0x27, 0x80},
404
405 {0x40, 0x01}, //HBLANK: 0x70 = 112
406 {0x41, 0x58},
407 {0x42, 0x00}, //VBLANK: 0x40 = 64
408 {0x43, 0x14}, //0x04 -> 0x40: For Max Framerate = 30fps
409 //BLC
410 {0x80,0x2e},
411 {0x81,0x7e},
412 {0x82,0x90},
413 {0x83,0x30},
414 {0x84,0x20},
415 {0x85,0x0b},
416 {0x89,0x48},//BLChold
417 {0x90,0x0e},
418 {0x91,0x0e},
419
420 {0x92,0x40},//AG_IN
421 {0x93,0x38},//AG_OUT
422 {0x98,0x20},
423 {0x99,0x43},//OutBLC
424 {0xa0,0x43},//DarkBLC
425 {0xa8,0x43},//NormalBLC
426
427 //Page2
428 {0x03,0x02},
429 {0x20,0x33},
430 {0x21,0x77},
431 {0x22,0xa7},
432 {0x23,0x30},
433 {0x52,0xa2},
434 {0x55,0x18},
435 {0x56,0x0c},
436 {0x60,0x11},
437 {0x61,0x1b},
438 {0x62,0x11},
439 {0x63,0x1a},
440 {0x64,0x11},
441 {0x65,0x1a},
442 {0x72,0x12},
443 {0x73,0x19},
444 {0x74,0x12},
445 {0x75,0x19},
446 {0x80,0x1d},
447 {0x81,0x6f},
448 {0x82,0x1e},
449 {0x83,0x2b},
450 {0x84,0x1e},
451 {0x85,0x2b},
452 {0x92,0x45},
453 {0x93,0x52},
454 {0x94,0x45},
455 {0x95,0x52},
456 {0xa0,0x1d},
457 {0xa1,0x6b},
458 {0xa4,0x6b},
459 {0xa5,0x1d},
460 {0xa8,0x2e},
461 {0xa9,0x42},
462 {0xaa,0x55},
463 {0xab,0x69},
464 {0xb8,0x10},
465 {0xb9,0x13},
466 {0xbc,0x1d},
467 {0xbd,0x1f},
468 {0xc0,0x04},
469 {0xc1,0x0d},
470 {0xc4,0x05},
471 {0xc5,0x0c},
472 {0xc8,0x06},
473 {0xc9,0x0b},
474 {0xcc,0x06},
475 {0xcd,0x0a},
476 {0xc2,0x04},
477 {0xc3,0x0d},
478 {0xc6,0x05},
479 {0xc7,0x0c},
480 {0xca,0x06},
481 {0xcb,0x0b},
482 {0xce,0x06},
483 {0xcf,0x0a},
484 {0xd0,0x03},
485 {0xd1,0x1c},
486 {0xd6,0x46},
487 {0xd7,0x48},
488
489 //Page10
490 {0x03,0x10},
491 {0x10,0x03},//03;//ISPCTL1;YUVORDER{FIX)
492 {0x11,0x43},
493 {0x12,0xF0},//Yoffet;dyoffseetenable
494 {0x40,0x8a}, //0x95
495 {0x41,0x00},//00DYOFS
496 {0x42,0x01},//Cb//3
497 {0x43,0x01},//Cr//4
498 {0x48,0x94},//Contrast //0xaa
499 {0x50,0x48},//AGBRT
500
501 {0x60,0x7f},
502 {0x61,0x00},//
503 {0x62,0x86},//SATB
504 {0x63,0x90},//SATR 0x8a
505 {0x64,0x48},//AGSAT
506 {0x67,0x3f},
507 {0x68,0x80},
508
509 //LPF
510 {0x03,0x11},
511 {0x10,0x25}, //LPF_CTL1//0x01
512 {0x11,0x07}, //TestSetting
513 {0x20,0x00}, //LPF_AUTO_CTL
514 {0x21,0x38}, //LPF_PGA_TH
515 {0x22,0x00}, //LPF_TIME_TH
516 {0x23,0x10}, //TestSetting
517 {0x60,0x10}, //ZARA_SIGMA_TH//40->10
518 {0x61,0x82},
519 {0x62,0x00}, //ZARA_HLVL_CTL
520 {0x63,0x00}, //ZARA_LLVL_CTL
521 {0x64,0x00}, //ZARA_DY_CTL
522
523 {0x67,0xA0}, //TestSetting
524 {0x68,0x40}, //TestSetting
525 {0x69,0x10}, //TestSetting
526
527 //2D
528 {0x03,0x12},
529 {0x40,0xeb}, //YC2D_LPF_CTL1
530 {0x41,0x10}, //YC2D_LPF_CTL2
531 {0x50,0x18}, //TestSetting
532 {0x51,0x24}, //TestSetting
533 {0x70,0x1f}, //GBGR_CTL1//0x1f
534 {0x71,0x00}, //TestSetting
535 {0x72,0x00}, //TestSetting
536 {0x73,0x00}, //TestSetting
537 {0x74,0x10}, //GBGR_G_UNIT_TH
538 {0x75,0x10}, //GBGR_RB_UNIT_TH
539 {0x76,0x20}, //GBGR_EDGE_TH
540 {0x77,0x80}, //GBGR_HLVL_TH
541 {0x78,0x88}, //GBGR_HLVL_COMP
542 {0x79,0x18}, //TestSetting
543 {0xb0,0x7d},//dpc
544
545 //Edge
546 {0x03,0x13},
547 {0x10,0x01},
548 {0x11,0x89},
549 {0x12,0x14},
550 {0x13,0x19},
551 {0x14,0x08}, //TestSetting
552 {0x20,0x06}, //SHARP_SLOPE
553 {0x21,0x05}, //SHARP_SLOPE_TH
554 {0x23,0x30}, //SHARP_DY_CTL
555 {0x24,0x33}, //40->33
556 {0x25,0x08}, //SHARP_PGA_TH
557 {0x26,0x18}, //TestSetting
558 {0x27,0x00}, //TestSetting
559 {0x28,0x08}, //TestSetting
560 {0x29,0x50}, //AG_TH
561 {0x2a,0xe0}, //regionratio
562 {0x2b,0x10}, //TestSetting
563 {0x2c,0x28}, //TestSetting
564 {0x2d,0x40}, //TestSetting
565 {0x2e,0x00}, //TestSetting
566 {0x2f,0x00}, //TestSetting
567 {0x30,0x11}, //TestSetting
568 {0x80,0x03}, //SHARP2D_CTL
569 {0x81,0x07}, //TestSetting
570 {0x90,0x06}, //SHARP2D_SLOPE
571 {0x91,0x05}, //SHARP2D_DIFF_CTL
572 {0x92,0x00}, //SHARP2D_HI_CLIP
573 {0x93,0x20}, //SHARP2D_DY_CTL
574 {0x94,0x42}, //TestSetting
575 {0x95,0x60}, //TestSetting
576
577 //Shading
578 {0x03,0x14},
579 {0x10,0x01},
580 {0x20,0x93},//XCEN
581 {0x21,0x80},//YCEN
582 {0x22,0x54},//76;34;2b
583 {0x23,0x50},//4b;15;0d
584 {0x24,0x44},//3b;10;0b
585
586 //Page15CMC
587 {0x03,0x15},
588 {0x10,0x03},
589
590 {0x14,0x3c},
591 {0x16,0x2c},
592 {0x17,0x2f},
593
594 {0x30,0xcb},
595 {0x31,0x61},
596 {0x32,0x16},
597 {0x33,0x23},
598 {0x34,0xce},
599 {0x35,0x2b},
600 {0x36,0x01},
601 {0x37,0x34},
602 {0x38,0x75},
603
604 {0x40,0x87},
605 {0x41,0x18},
606 {0x42,0x91},
607 {0x43,0x94},
608 {0x44,0x9f},
609 {0x45,0x33},
610 {0x46,0x00},
611 {0x47,0x94},
612 {0x48,0x14},
613
614 //PAGE16
615 //GammaCorrection
616 {0x03,0x16},
617
618 {0x30,0x00},
619 {0x31,0x0a},
620 {0x32,0x1b},
621 {0x33,0x2e},
622 {0x34,0x5c},
623 {0x35,0x79},
624 {0x36,0x95},
625 {0x37,0xa4},
626 {0x38,0xb1},
627 {0x39,0xbd},
628 {0x3a,0xc8},
629 {0x3b,0xd9},
630 {0x3c,0xe8},
631 {0x3d,0xf5},
632 {0x3e,0xff},
633
634 //PAGE17
635 //AutoFlickerCancellation
636 {0x03,0x17},
637 {0xc4,0x3c},
638 {0xc5,0x32},
639
640 //Page20AE
641 {0x03,0x20},
642 {0x10,0x0c},
643 {0x11,0x04},
644
645 {0x20,0x01},
646 {0x28,0x27},
647 {0x29,0xa1},
648
649 {0x2a,0xf0},
650 {0x2b,0x34},
651
652 {0x30, 0x78},
653
654 {0x39,0x22},
655 {0x3a,0xde},
656 {0x3b,0x22},
657 {0x3c,0xde},
658
659 {0x60,0x95},//d5;99
660 {0x68,0x3c},
661 {0x69,0x64},
662 {0x6A,0x28},
663 {0x6B,0xc8},
664
665 {0x70,0x48},//YTarget42
666
667 {0x76,0x22},//Unlockbnd1
668 {0x77,0x02},//Unlockbnd2
669
670 {0x78,0x12},//Yth1
671 {0x79,0x26},//Yth2
672 {0x7a,0x23},//Yth3
673
674 {0x7c,0x1c},
675 {0x7d,0x22},
676
677 {0x83, 0x01}, //EXP Normal 33.33 fps
678 {0x84, 0xbc},
679 {0x85, 0x56},
680 {0x86, 0x00}, //EXPMin 3250.00 fps
681 {0x87, 0xfa},
682 {0x88, 0x01}, //EXP Max 7.14 fps
683 {0x89, 0xbc},
684 {0x8a, 0x56},
685 {0x8B, 0x1f}, //EXP100
686 {0x8C, 0xbd},
687 {0x8D, 0x1a}, //EXP120
688 {0x8E, 0x5e},
689 {0x9c, 0x03}, //EXP Limit 812.50 fps
690 {0x9d, 0x6b},
691 {0x9e, 0x00}, //EXP Unit
692 {0x9f, 0xfa},
693 // {0xa4, 0x18},
694
695
696 {0x94, 0x01},
697 {0x95, 0xb7},
698 {0x96, 0x74},
699 {0x98, 0x8C},
700 {0x99, 0x23},
701
702 {0xb1, 0x14},
703 {0xb2, 0x48},
704 {0xb4, 0x14},
705 {0xb5, 0x38},
706 {0xb6, 0x26},
707 {0xb7, 0x20},
708 {0xb8, 0x1d},
709 {0xb9, 0x1b},
710 {0xba, 0x1a},
711 {0xbb, 0x19},
712 {0xbc, 0x19},
713 {0xbd, 0x18},
714
715 {0xc0, 0x1a}, //0x1a->0x16
716 {0xc3, 0x48},
717 {0xc4, 0x48},
718
719
720 //Page22AWB
721 {0x03,0x22},
722 {0x10,0xfb},
723 {0x11,0x26},
724 {0x30,0x80},
725 {0x31,0x80},
726 {0x38,0x12},
727 {0x39,0x33},
728 {0x3a,0x88},
729 {0x3b,0xc4},
730 {0x40,0xf0},
731 {0x41,0x33},
732 {0x42,0x33},
733 {0x43,0xf3},
734 {0x44,0x55},
735 {0x45,0x44},
736 {0x46,0x02},
737 {0x60,0x00},
738 {0x61,0x00},
739 {0x80,0x39},
740 {0x81,0x20},
741 {0x82,0x22},
742 {0x83,0x46},
743 {0x84,0x16},
744 {0x85,0x57},
745 {0x86,0x28},
746 {0x87,0x38},
747 {0x88,0x20},
748 {0x89,0x48},
749 {0x8a,0x38},
750 {0x8b,0x02},
751 {0x8d,0x22},
752 {0x8e,0x71},
753 {0x8f,0x63},
754 {0x90,0x60},
755 {0x91,0x5c},
756 {0x92,0x56},
757 {0x93,0x52},
758 {0x94,0x4c},
759 {0x95,0x36},
760 {0x96,0x31},
761 {0x97,0x2e},
762 {0x98,0x2a},
763 {0x99,0x29},
764 {0x9a,0x26},
765 {0x9b,0x09},
766 {0xb0,0x30},
767 {0xb1,0x48},
768 {0x03,0x22},
769 {0x10,0xfb},
770
771 {0x03,0x20},
772 {0x10,0x9c},
773
774 {0x01,0xf0},
775 {0x03,0x00},
776 {0x01,0xc0},
777
778 {0xff,0xff}//EndofInitialSetting
779 };
780
781 static void HI708_Set_VGA_mode(void)
782 {
783 HI708_write_cmos_sensor(0x01, HI708_read_cmos_sensor(0x01)|0x01); //Sleep: For Write Reg
784
785 HI708_write_cmos_sensor(0x03, 0x00);
786 HI708_write_cmos_sensor(0x10, 0x00); //VGA Size
787
788 HI708_write_cmos_sensor(0x20, 0x00);
789 HI708_write_cmos_sensor(0x21, 0x04);
790
791 HI708_write_cmos_sensor(0x40, 0x01); //HBLANK: 0x70 = 112
792 HI708_write_cmos_sensor(0x41, 0x58);
793 HI708_write_cmos_sensor(0x42, 0x00); //VBLANK: 0x04 = 4
794 HI708_write_cmos_sensor(0x43, 0x14);
795
796 // HI708_write_cmos_sensor(0x03, 0x11);
797 // HI708_write_cmos_sensor(0x10, 0x25);
798
799 HI708_write_cmos_sensor(0x03, 0x20);
800
801 HI708_write_cmos_sensor(0x10, HI708_read_cmos_sensor(0x10)&0x7f); //Close AE
802 HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)|0x08); //Reset AE
803
804 //HI708_write_cmos_sensor(0x83, 0x00);
805 // HI708_write_cmos_sensor(0x84, 0xbe);
806 //HI708_write_cmos_sensor(0x85, 0x6e);
807 HI708_write_cmos_sensor(0x86, 0x00);
808 HI708_write_cmos_sensor(0x87, 0xfa);
809
810 HI708_write_cmos_sensor(0x8b, 0x1f);
811 HI708_write_cmos_sensor(0x8c, 0xbd);
812 HI708_write_cmos_sensor(0x8d, 0x1a);
813 HI708_write_cmos_sensor(0x8e, 0x5e);
814
815 HI708_write_cmos_sensor(0x9c, 0x03);//0b
816 HI708_write_cmos_sensor(0x9d, 0x6b);//b8
817 HI708_write_cmos_sensor(0x9e, 0x00);
818 HI708_write_cmos_sensor(0x9f, 0xfa);
819
820 HI708_write_cmos_sensor(0x01, HI708_read_cmos_sensor(0x01)&0xfe); //Exit Sleep: For Write Reg
821
822 HI708_write_cmos_sensor(0x03, 0x20);
823 HI708_write_cmos_sensor(0x10, HI708_read_cmos_sensor(0x10)|0x80); //Open AE
824 HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)&0xf7); //Reset AE
825
826 }
827
828 static void HI708_Initial_Setting(void)
829 {
830 kal_uint32 iEcount;
831 for(iEcount=0;(!((0xff==(HI708_Initial_Setting_Info[iEcount].address))&&(0xff==(HI708_Initial_Setting_Info[iEcount].data))));iEcount++)
832 {
833 HI708_write_cmos_sensor(HI708_Initial_Setting_Info[iEcount].address, HI708_Initial_Setting_Info[iEcount].data);
834 }
835
836 HI708_Set_VGA_mode();
837 }
838
839 static void HI708_Init_Parameter(void)
840 {
841 spin_lock(&hi708_yuv_drv_lock);
842 HI708_sensor.first_init = KAL_TRUE;
843 HI708_sensor.pv_mode = KAL_TRUE;
844 HI708_sensor.night_mode = KAL_FALSE;
845 HI708_sensor.MPEG4_Video_mode = KAL_FALSE;
846
847 HI708_sensor.cp_pclk = HI708_sensor.pv_pclk;
848
849 HI708_sensor.pv_dummy_pixels = 0;
850 HI708_sensor.pv_dummy_lines = 0;
851 HI708_sensor.cp_dummy_pixels = 0;
852 HI708_sensor.cp_dummy_lines = 0;
853
854 HI708_sensor.wb = 0;
855 HI708_sensor.exposure = 0;
856 HI708_sensor.effect = 0;
857 HI708_sensor.banding = AE_FLICKER_MODE_50HZ;
858
859 HI708_sensor.pv_line_length = 640;
860 HI708_sensor.pv_frame_height = 480;
861 HI708_sensor.cp_line_length = 640;
862 HI708_sensor.cp_frame_height = 480;
863 spin_unlock(&hi708_yuv_drv_lock);
864 }
865
866 static kal_uint8 HI708_power_on(void)
867 {
868 kal_uint8 HI708_sensor_id = 0;
869 spin_lock(&hi708_yuv_drv_lock);
870 HI708_sensor.pv_pclk = 13000000;
871 spin_unlock(&hi708_yuv_drv_lock);
872 //Software Reset
873 HI708_write_cmos_sensor(0x01,0xf1);
874 HI708_write_cmos_sensor(0x01,0xf3);
875 HI708_write_cmos_sensor(0x01,0xf1);
876
877 /* Read Sensor ID */
878 HI708_sensor_id = HI708_read_cmos_sensor(0x04);
879 SENSORDB("[HI708YUV]:read Sensor ID:%x\n",HI708_sensor_id);
880 return HI708_sensor_id;
881 }
882
883
884 /*************************************************************************
885 * FUNCTION
886 * HI708Open
887 *
888 * DESCRIPTION
889 * This function initialize the registers of CMOS sensor
890 *
891 * PARAMETERS
892 * None
893 *
894 * RETURNS
895 * None
896 *
897 * GLOBALS AFFECTED
898 *
899 *************************************************************************/
900 UINT32 HI708Open(void)
901 {
902 spin_lock(&hi708_yuv_drv_lock);
903 sensor_id_fail = 0;
904 spin_unlock(&hi708_yuv_drv_lock);
905 SENSORDB("[Enter]:HI708 Open func:");
906
907
908 if (HI708_power_on() != HI708_SENSOR_ID)
909 {
910 SENSORDB("[HI708]Error:read sensor ID fail\n");
911 spin_lock(&hi708_yuv_drv_lock);
912 sensor_id_fail = 1;
913 spin_unlock(&hi708_yuv_drv_lock);
914 return ERROR_SENSOR_CONNECT_FAIL;
915 }
916
917 /* Apply sensor initail setting*/
918
919 #ifdef HI708_LOAD_FROM_T_FLASH
920
921 struct file *fp;
922 mm_segment_t fs;
923 loff_t pos = 0;
924 //static char buf[10*1024] ;
925
926 printk("HI708 Open File Start\n");
927 fp = filp_open("/storage/sdcard0/hi708_sd.dat", O_RDONLY , 0);
928 if (IS_ERR(fp))
929 {
930 fromsd = 0;
931 printk("open file error\n");
932 ////////return 0;
933 }
934 else
935 {
936 printk("open file success\n");
937 fromsd = 1;
938 //SP2528_Initialize_from_T_Flash();
939 filp_close(fp, NULL);
940 }
941 //set_fs(fs);
942 if(fromsd == 1)
943 Hi708_Initialize_from_T_Flash();
944 else
945 {
946 HI708_Initial_Setting();
947 }
948 HI708_Init_Parameter();
949 #else
950 /* Apply sensor initail setting*/
951 HI708_Initial_Setting();
952 HI708_Init_Parameter();
953 #endif
954
955
956
957 SENSORDB("[Exit]:HI708 Open func\n");
958 return ERROR_NONE;
959 } /* HI708Open() */
960
961 UINT32 HI708Init(void)
962 {
963 UINT32 open_ret = HI708Open();
964
965 if (ERROR_SENSOR_CONNECT_FAIL != open_ret)
966 {
967 HI708_write_cmos_sensor(0x03, 0x00);
968 HI708_write_cmos_sensor(0x08, 0x0f);
969 HI708_write_cmos_sensor(0x01, 0xf1); //sensor sleep mode
970 mDELAY(20);
971 }
972
973 return open_ret;
974 } /* HI708Init() */
975
976 /*************************************************************************
977 * FUNCTION
978 * HI708_GetSensorID
979 *
980 * DESCRIPTION
981 * This function get the sensor ID
982 *
983 * PARAMETERS
984 * None
985 *
986 * RETURNS
987 * None
988 *
989 * GLOBALS AFFECTED
990 *
991 *************************************************************************/
992 static kal_uint32 HI708_GetSensorID(kal_uint32 *sensorID)
993 {
994 SENSORDB("[Enter]:HI708 Open func ");
995 *sensorID = HI708_power_on() ;
996
997 if (*sensorID != HI708_SENSOR_ID)
998 {
999 SENSORDB("[HI708]Error:read sensor ID fail\n");
1000 spin_lock(&hi708_yuv_drv_lock);
1001 sensor_id_fail = 1;
1002 spin_unlock(&hi708_yuv_drv_lock);
1003 *sensorID = 0xFFFFFFFF;
1004 return ERROR_SENSOR_CONNECT_FAIL;
1005 }
1006
1007 return ERROR_NONE;
1008 } /* HI708Open */
1009
1010
1011 /*************************************************************************
1012 * FUNCTION
1013 * HI708Close
1014 *
1015 * DESCRIPTION
1016 * This function is to turn off sensor module power.
1017 *
1018 * PARAMETERS
1019 * None
1020 *
1021 * RETURNS
1022 * None
1023 *
1024 * GLOBALS AFFECTED
1025 *
1026 *************************************************************************/
1027 UINT32 HI708Close(void)
1028 {
1029
1030 return ERROR_NONE;
1031 } /* HI708Close() */
1032
1033
1034 static void HI708_Set_Mirror_Flip(kal_uint8 image_mirror)
1035 {
1036 /********************************************************
1037 * Page Mode 0: Reg 0x0011 bit[1:0] = [Y Flip : X Flip]
1038 * 0: Off; 1: On.
1039 *********************************************************/
1040 kal_uint8 temp_data;
1041 SENSORDB("[Enter]:HI708 set Mirror_flip func:image_mirror=%d\n",image_mirror);
1042 HI708_write_cmos_sensor(0x03,0x00); //Page 0
1043 temp_data = (HI708_read_cmos_sensor(0x11) & 0xfc);
1044 spin_lock(&hi708_yuv_drv_lock);
1045 //HI708_sensor.mirror = (HI708_read_cmos_sensor(0x11) & 0xfc);
1046 switch (image_mirror)
1047 {
1048 case IMAGE_NORMAL:
1049 //HI708_sensor.mirror |= 0x00;
1050 temp_data |= 0x00;
1051 break;
1052 case IMAGE_H_MIRROR:
1053 //HI708_sensor.mirror |= 0x01;
1054 temp_data |= 0x01;
1055 break;
1056 case IMAGE_V_MIRROR:
1057 //HI708_sensor.mirror |= 0x02;
1058 temp_data |= 0x02;
1059 break;
1060 case IMAGE_HV_MIRROR:
1061 //HI708_sensor.mirror |= 0x03;
1062 temp_data |= 0x03;
1063 break;
1064 default:
1065 //HI708_sensor.mirror |= 0x00;
1066 temp_data |= 0x00;
1067 }
1068 HI708_sensor.mirror = temp_data;
1069 spin_unlock(&hi708_yuv_drv_lock);
1070 HI708_write_cmos_sensor(0x11, HI708_sensor.mirror);
1071 SENSORDB("[Exit]:HI708 set Mirror_flip func\n");
1072 }
1073
1074 #if 0
1075 static void HI708_set_dummy(kal_uint16 dummy_pixels,kal_uint16 dummy_lines)
1076 {
1077 HI708_write_cmos_sensor(0x03, 0x00); //Page 0
1078 HI708_write_cmos_sensor(0x40,((dummy_pixels & 0x0F00))>>8); //HBLANK
1079 HI708_write_cmos_sensor(0x41,(dummy_pixels & 0xFF));
1080 HI708_write_cmos_sensor(0x42,((dummy_lines & 0xFF00)>>8)); //VBLANK ( Vsync Type 1)
1081 HI708_write_cmos_sensor(0x43,(dummy_lines & 0xFF));
1082 }
1083 #endif
1084
1085 // 640 * 480
1086
1087
1088 static void HI708_Cal_Min_Frame_Rate(kal_uint16 min_framerate)
1089 {
1090 kal_uint32 HI708_expmax = 0;
1091 kal_uint32 HI708_expbanding = 0;
1092 kal_uint32 temp_data;
1093
1094 SENSORDB("[HI708] HI708_Cal_Min_Frame_Rate:min_fps=%d\n",min_framerate);
1095
1096 //No Fixed Framerate
1097 HI708_write_cmos_sensor(0x01, HI708_read_cmos_sensor(0x01)|0x01); //Sleep: For Write Reg
1098 HI708_write_cmos_sensor(0x03, 0x00);
1099 HI708_write_cmos_sensor(0x11, HI708_read_cmos_sensor(0x11)&0xfb);
1100
1101 HI708_write_cmos_sensor(0x03, 0x20);
1102 HI708_write_cmos_sensor(0x10, HI708_read_cmos_sensor(0x10)&0x7f); //Close AE
1103 HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)|0x08); //Reset AE
1104 //HI708_write_cmos_sensor(0x11, 0x04);
1105 //HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)|0x08); //Reset AE
1106 //HI708_write_cmos_sensor(0x2a, 0xf0);
1107 //HI708_write_cmos_sensor(0x2b, 0x34);
1108
1109 HI708_write_cmos_sensor(0x03, 0x00);
1110 temp_data = ((HI708_read_cmos_sensor(0x40)<<8)|HI708_read_cmos_sensor(0x41));
1111 spin_lock(&hi708_yuv_drv_lock);
1112 HI708_sensor.pv_dummy_pixels = temp_data;
1113 HI708_sensor.pv_line_length = HI708_VGA_DEFAULT_PIXEL_NUMS+ HI708_sensor.pv_dummy_pixels ;
1114 spin_unlock(&hi708_yuv_drv_lock);
1115
1116 if(HI708_sensor.banding == AE_FLICKER_MODE_50HZ)
1117 {
1118 HI708_expbanding = (HI708_sensor.pv_pclk/HI708_sensor.pv_line_length/100)*HI708_sensor.pv_line_length/8;
1119 HI708_expmax = HI708_expbanding*10*(100/min_framerate) ;
1120 }
1121 else if(HI708_sensor.banding == AE_FLICKER_MODE_60HZ)
1122 {
1123 HI708_expbanding = (HI708_sensor.pv_pclk/HI708_sensor.pv_line_length/120)*HI708_sensor.pv_line_length/8;
1124 HI708_expmax = HI708_expbanding*10*(120/min_framerate) ;
1125 }
1126 else//default 5oHZ
1127 {
1128 SENSORDB("[HI708][Error] Wrong Banding Setting!!!...");
1129 }
1130
1131 HI708_write_cmos_sensor(0x03, 0x00);
1132 HI708_write_cmos_sensor(0x12, 0x05);
1133
1134 HI708_write_cmos_sensor(0x03, 0x20);
1135
1136 HI708_write_cmos_sensor(0x8b, 0x1f);
1137 HI708_write_cmos_sensor(0x8c, 0xbd);
1138 HI708_write_cmos_sensor(0x8d, 0x1a);
1139 HI708_write_cmos_sensor(0x8e, 0x5e);
1140
1141 HI708_write_cmos_sensor(0x9c, 0x03);//0b
1142 HI708_write_cmos_sensor(0x9d, 0x6b);//b8
1143 HI708_write_cmos_sensor(0x9e, 0x00);
1144 HI708_write_cmos_sensor(0x9f, 0xfa);
1145
1146
1147 if(HI708_sensor.night_mode)
1148 {
1149 HI708_write_cmos_sensor(0x03, 0x20);
1150 HI708_write_cmos_sensor(0x83, 0x02);//(HI708_expmax>>16)&0xff);//7fps
1151 HI708_write_cmos_sensor(0x84, 0x49);//(HI708_expmax>>8)&0xff);
1152 HI708_write_cmos_sensor(0x85, 0xf0);//(HI708_expmax>>0)&0xff);
1153 HI708_write_cmos_sensor(0x88, 0x02);//(HI708_expmax>>16)&0xff);//7fps
1154 HI708_write_cmos_sensor(0x89, 0x49);//(HI708_expmax>>8)&0xff);
1155 HI708_write_cmos_sensor(0x8a, 0xf0);//(HI708_expmax>>0)&0xff);
1156 HI708_night_flag = KAL_TRUE;
1157 }else
1158 {
1159 if(HI708_night_flag)
1160 {
1161 HI708_write_cmos_sensor(0x83, 0x02);//(HI708_expmax>>16)&0xff);//01 10fps
1162 HI708_write_cmos_sensor(0x84, 0x7a);//(HI708_expmax>>8)&0xff);//bc
1163 HI708_write_cmos_sensor(0x85, 0xc4);//(HI708_expmax>>0)&0xff);//56
1164 HI708_night_flag = KAL_FALSE;
1165 }
1166 HI708_write_cmos_sensor(0x88, 0x02);//(HI708_expmax>>16)&0xff);//01 10fps
1167 HI708_write_cmos_sensor(0x89, 0x7a);//(HI708_expmax>>8)&0xff);//bc
1168 HI708_write_cmos_sensor(0x8a, 0xc4);//(HI708_expmax>>0)&0xff);//56
1169 }
1170
1171 HI708_write_cmos_sensor(0x03, 0x20);
1172 HI708_write_cmos_sensor(0x10, HI708_read_cmos_sensor(0x10)|0x80); //Open AE
1173 HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)&0xf7); //Reset AE
1174 HI708_write_cmos_sensor(0x03, 0x00);
1175 HI708_write_cmos_sensor(0x01, HI708_read_cmos_sensor(0x01)&0xfe); //Exit Sleep: For Write Reg
1176
1177 }
1178
1179
1180 static void HI708_Fix_Video_Frame_Rate(kal_uint16 fix_framerate)
1181 {
1182 kal_uint32 HI708_expfix;
1183 kal_uint32 HI708_expfix_temp;
1184 kal_uint32 HI708_expmax = 0;
1185 kal_uint32 HI708_expbanding = 0;
1186 kal_uint32 temp_data1,temp_data2;
1187
1188 SENSORDB("[Enter]HI708 Fix_video_frame_rate func: fix_fps=%d\n",fix_framerate);
1189
1190 spin_lock(&hi708_yuv_drv_lock);
1191 HI708_sensor.video_current_frame_rate = fix_framerate;
1192 spin_unlock(&hi708_yuv_drv_lock);
1193 // Fixed Framerate
1194 HI708_write_cmos_sensor(0x01, HI708_read_cmos_sensor(0x01)|0x01); //Sleep: For Write Reg
1195
1196 HI708_write_cmos_sensor(0x03, 0x00);
1197 //HI708_write_cmos_sensor(0x11, HI708_read_cmos_sensor(0x11)|0x04);
1198
1199 //HI708_write_cmos_sensor(0x12,HI708_read_cmos_sensor(0x12)&0xfe);
1200
1201 HI708_write_cmos_sensor(0x03, 0x20);
1202 HI708_write_cmos_sensor(0x10, HI708_read_cmos_sensor(0x10)&0x7f); //Close AE
1203
1204 HI708_write_cmos_sensor(0x11, 0x00);
1205 HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)|0x08); //Reset AE
1206 //HI708_write_cmos_sensor(0x2a, 0x00);
1207 //HI708_write_cmos_sensor(0x2b, 0x35);
1208
1209 HI708_write_cmos_sensor(0x03, 0x00);
1210 temp_data1 = ((HI708_read_cmos_sensor(0x40)<<8)|HI708_read_cmos_sensor(0x41));
1211 temp_data2 = ((HI708_read_cmos_sensor(0x42)<<8)|HI708_read_cmos_sensor(0x43));
1212 spin_lock(&hi708_yuv_drv_lock);
1213 HI708_sensor.pv_dummy_pixels = temp_data1;
1214 HI708_sensor.pv_line_length = HI708_VGA_DEFAULT_PIXEL_NUMS + HI708_sensor.pv_dummy_pixels ;
1215 HI708_sensor.pv_dummy_lines = temp_data2;
1216 spin_unlock(&hi708_yuv_drv_lock);
1217
1218 HI708_expfix_temp = ((HI708_sensor.pv_pclk*10/fix_framerate)-(HI708_sensor.pv_line_length*HI708_sensor.pv_dummy_lines))/8;
1219 HI708_expfix = ((HI708_expfix_temp*8/HI708_sensor.pv_line_length)*HI708_sensor.pv_line_length)/8;
1220
1221 HI708_write_cmos_sensor(0x03, 0x20);
1222 //HI708_write_cmos_sensor(0x83, (HI708_expfix>>16)&0xff);
1223 //HI708_write_cmos_sensor(0x84, (HI708_expfix>>8)&0xff);
1224 //HI708_write_cmos_sensor(0x85, (HI708_expfix>>0)&0xff);
1225 HI708_write_cmos_sensor(0x8b, 0x1f);
1226 HI708_write_cmos_sensor(0x8c, 0xbd);
1227 HI708_write_cmos_sensor(0x8d, 0x1a);
1228 HI708_write_cmos_sensor(0x8e, 0x5e);
1229 /*
1230 if(HI708_sensor.night_mode)
1231 {
1232 HI708_write_cmos_sensor(0x83, 0x02);//(HI708_expfix>>16)&0xff);//10fps
1233 HI708_write_cmos_sensor(0x84, 0x7a);//(HI708_expfix>>8)&0xff);
1234 HI708_write_cmos_sensor(0x85, 0xc4);//(HI708_expfix>>0)&0xff);
1235 HI708_write_cmos_sensor(0x88, 0x02);//(HI708_expfix>>16)&0xff);//10fps
1236 HI708_write_cmos_sensor(0x89, 0x7a);//(HI708_expfix>>8)&0xff);
1237 HI708_write_cmos_sensor(0x8a, 0xc4);//(HI708_expfix>>0)&0xff);
1238 HI708_write_cmos_sensor(0x91, 0x02);//(HI708_expfix>>16)&0xff);//10fps
1239 HI708_write_cmos_sensor(0x92, 0x71);//(HI708_expfix>>8)&0xff);
1240 HI708_write_cmos_sensor(0x93, 0x00);//(HI708_expfix>>0)&0xff);
1241 }else*/
1242 //{
1243 HI708_write_cmos_sensor(0x83, 0x01);//(HI708_expfix>>16)&0xff);//11fps
1244 HI708_write_cmos_sensor(0x84, 0xbc);//(HI708_expfix>>8)&0xff);
1245 HI708_write_cmos_sensor(0x85, 0x56);//(HI708_expfix>>0)&0xff);
1246 HI708_write_cmos_sensor(0x88, 0x00);//(HI708_expfix>>16)&0xff);//11fps
1247 HI708_write_cmos_sensor(0x89, 0xde);//(HI708_expfix>>8)&0xff);
1248 HI708_write_cmos_sensor(0x8a, 0x2b);//(HI708_expfix>>0)&0xff);
1249 HI708_write_cmos_sensor(0x91, 0x01);//(HI708_expfix>>16)&0xff);//10fps
1250 HI708_write_cmos_sensor(0x92, 0xbb);//(HI708_expfix>>8)&0xff);
1251 HI708_write_cmos_sensor(0x93, 0x5c);//(HI708_expfix>>0)&0xff);
1252 //}
1253 if(HI708_sensor.banding == AE_FLICKER_MODE_50HZ)
1254 {
1255 HI708_expbanding = ((HI708_read_cmos_sensor(0x8b)<<8)|HI708_read_cmos_sensor(0x8c));
1256 }
1257 else if(HI708_sensor.banding == AE_FLICKER_MODE_60HZ)
1258 {
1259 HI708_expbanding = ((HI708_read_cmos_sensor(0x8d)<<8)|HI708_read_cmos_sensor(0x8e));
1260 }
1261 else
1262 {
1263 SENSORDB("[HI708]Wrong Banding Setting!!!...");
1264 }
1265 HI708_expmax = ((HI708_expfix_temp-HI708_expbanding)/HI708_expbanding)*HI708_expbanding;
1266
1267 HI708_write_cmos_sensor(0x03, 0x20);
1268 //HI708_write_cmos_sensor(0x88, (HI708_expmax>>16)&0xff);
1269 //HI708_write_cmos_sensor(0x89, (HI708_expmax>>8)&0xff);
1270 //HI708_write_cmos_sensor(0x8a, (HI708_expmax>>0)&0xff);
1271
1272 HI708_write_cmos_sensor(0x03, 0x20);
1273 HI708_write_cmos_sensor(0x10, HI708_read_cmos_sensor(0x10)|0x80); //Open AE
1274 HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)&0xf7); //Reset AE
1275
1276 HI708_write_cmos_sensor(0x01, HI708_read_cmos_sensor(0x01)&0xfe); //Exit Sleep: For Write Reg
1277 }
1278
1279 #if 0
1280 // 320 * 240
1281 static void HI708_Set_QVGA_mode(void)
1282 {
1283 HI708_write_cmos_sensor(0x01, HI708_read_cmos_sensor(0x01)|0x01); //Sleep: For Write Reg
1284
1285 HI708_write_cmos_sensor(0x03, 0x00);
1286 HI708_write_cmos_sensor(0x10, 0x01); //QVGA Size: 0x10 -> 0x01
1287
1288 HI708_write_cmos_sensor(0x20, 0x00);
1289 HI708_write_cmos_sensor(0x21, 0x02);
1290
1291 HI708_write_cmos_sensor(0x40, 0x01); //HBLANK: 0x0158 = 344
1292 HI708_write_cmos_sensor(0x41, 0x58);
1293 HI708_write_cmos_sensor(0x42, 0x00); //VBLANK: 0x14 = 20
1294 HI708_write_cmos_sensor(0x43, 0x14);
1295
1296 HI708_write_cmos_sensor(0x03, 0x11); //QVGA Fixframerate
1297 HI708_write_cmos_sensor(0x10, 0x21);
1298
1299 HI708_write_cmos_sensor(0x03, 0x20);
1300 HI708_write_cmos_sensor(0x10, HI708_read_cmos_sensor(0x10)&0x7f); //Close AE
1301 HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)|0x08); //Reset AE
1302
1303 HI708_write_cmos_sensor(0x83, 0x00);
1304 HI708_write_cmos_sensor(0x84, 0xaf);
1305 HI708_write_cmos_sensor(0x85, 0xc8);
1306 HI708_write_cmos_sensor(0x86, 0x00);
1307 HI708_write_cmos_sensor(0x87, 0xfa);
1308
1309 HI708_write_cmos_sensor(0x8b, 0x3a);
1310 HI708_write_cmos_sensor(0x8c, 0x98);
1311 HI708_write_cmos_sensor(0x8d, 0x30);
1312 HI708_write_cmos_sensor(0x8e, 0xd4);
1313
1314 HI708_write_cmos_sensor(0x9c, 0x0b);
1315 HI708_write_cmos_sensor(0x9d, 0x3b);
1316 HI708_write_cmos_sensor(0x9e, 0x00);
1317 HI708_write_cmos_sensor(0x9f, 0xfa);
1318
1319 HI708_write_cmos_sensor(0x01, HI708_read_cmos_sensor(0x01)&0xfe); //Exit Sleep: For Write Reg
1320
1321 HI708_write_cmos_sensor(0x03, 0x20);
1322 HI708_write_cmos_sensor(0x10, HI708_read_cmos_sensor(0x10)|0x80); //Open AE
1323 HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)&0xf7); //Reset AE
1324
1325 }
1326 #endif
1327 void HI708_night_mode(kal_bool enable)
1328 {
1329 SENSORDB("HHL[Enter]HI708 night mode func:enable = %d\n",enable);
1330 SENSORDB("HI708_sensor.video_mode = %d\n",HI708_sensor.MPEG4_Video_mode);
1331 SENSORDB("HI708_sensor.night_mode = %d\n",HI708_sensor.night_mode);
1332 spin_lock(&hi708_yuv_drv_lock);
1333 HI708_sensor.night_mode = enable;
1334 spin_unlock(&hi708_yuv_drv_lock);
1335
1336 if(HI708_sensor.MPEG4_Video_mode == KAL_TRUE)
1337 return;
1338
1339 if(enable)
1340
1341 {
1342 if (HI708_sensor.banding == AE_FLICKER_MODE_50HZ)
1343 {
1344
1345 SENSORDB("[HI708]HI708NightMode Disable AE_FLICKER_MODE_50HZ\n");
1346
1347 HI708_write_cmos_sensor(0x03, 0x20);
1348
1349 HI708_write_cmos_sensor(0x10, HI708_read_cmos_sensor(0x10)&0x7f); //Close AE
1350 HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)|0x08); //Reset AE
1351
1352 //BEGIN <> <20130922> <improve the camera experience that before to capture the next photo, the screen lighten instantly> panzaoyan
1353 HI708_write_cmos_sensor(0x83, 0x02);
1354 HI708_write_cmos_sensor(0x84, 0x7a);
1355 HI708_write_cmos_sensor(0x85, 0xc4);//15fps
1356 HI708_write_cmos_sensor(0x86, 0x00);
1357 HI708_write_cmos_sensor(0x87, 0xfa);
1358 //END <> <20130922> <improve the camera experience that before to capture the next photo, the screen lighten instantly> panzaoyan
1359 HI708_write_cmos_sensor(0x88, 0x02);
1360 HI708_write_cmos_sensor(0x89, 0x7a);
1361 HI708_write_cmos_sensor(0x8A, 0xc4);//7
1362
1363 HI708_write_cmos_sensor(0x8b, 0x1f);
1364 HI708_write_cmos_sensor(0x8c, 0xbd);
1365 HI708_write_cmos_sensor(0x8d, 0x1a);
1366 HI708_write_cmos_sensor(0x8e, 0x5e);
1367
1368 HI708_write_cmos_sensor(0x9c, 0x03);
1369 HI708_write_cmos_sensor(0x9d, 0x6b);
1370 HI708_write_cmos_sensor(0x9e, 0x00);
1371 HI708_write_cmos_sensor(0x9f, 0xfa);
1372
1373
1374 HI708_write_cmos_sensor(0x01, HI708_read_cmos_sensor(0x01)&0xfe); //Exit Sleep: For Write Reg
1375
1376 HI708_write_cmos_sensor(0x03, 0x20);
1377 HI708_write_cmos_sensor(0x10, HI708_read_cmos_sensor(0x10)|0x80); //Open AE
1378 HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)&0xf7); //Reset AE
1379
1380
1381
1382 }
1383 else
1384 {
1385 SENSORDB("[HI708]HI708NightMode Disable AE_FLICKER_MODE_60HZ\n");
1386 HI708_write_cmos_sensor(0x03, 0x20);
1387
1388 HI708_write_cmos_sensor(0x10, HI708_read_cmos_sensor(0x10)&0x7f); //Close AE
1389 HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)|0x08); //Reset AE
1390
1391 //BEGIN <> <20130922> <improve the camera experience that before to capture the next photo, the screen lighten instantly> panzaoyan
1392
1393 HI708_write_cmos_sensor(0x83, 0x02);
1394 HI708_write_cmos_sensor(0x84, 0x78);
1395 HI708_write_cmos_sensor(0x85, 0xd0);//15fps
1396 HI708_write_cmos_sensor(0x86, 0x00);
1397 HI708_write_cmos_sensor(0x87, 0xfa);
1398 //END <> <20130922> <improve the camera experience that before to capture the next photo, the screen lighten instantly> panzaoyan
1399 HI708_write_cmos_sensor(0x88, 0x02);
1400 HI708_write_cmos_sensor(0x89, 0x78);
1401 HI708_write_cmos_sensor(0x8A, 0xd0);//7
1402
1403 HI708_write_cmos_sensor(0x8b, 0x1f);
1404 HI708_write_cmos_sensor(0x8c, 0xbd);
1405 HI708_write_cmos_sensor(0x8d, 0x1a);
1406 HI708_write_cmos_sensor(0x8e, 0x5e);
1407
1408 HI708_write_cmos_sensor(0x9c, 0x03);
1409 HI708_write_cmos_sensor(0x9d, 0x6b);
1410 HI708_write_cmos_sensor(0x9e, 0x00);
1411 HI708_write_cmos_sensor(0x9f, 0xfa);
1412
1413
1414 HI708_write_cmos_sensor(0x01, HI708_read_cmos_sensor(0x01)&0xfe); //Exit Sleep: For Write Reg
1415
1416 HI708_write_cmos_sensor(0x03, 0x20);
1417 HI708_write_cmos_sensor(0x10, HI708_read_cmos_sensor(0x10)|0x80); //Open AE
1418 HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)&0xf7); //Reset AE
1419
1420
1421 }
1422
1423
1424 }
1425 else
1426 {
1427 if (HI708_sensor.banding == AE_FLICKER_MODE_50HZ)
1428 { SENSORDB("[HI708]HI708NightMode Enable AE_FLICKER_MODE_50HZ\n");
1429 HI708_write_cmos_sensor(0x03, 0x20);
1430
1431 HI708_write_cmos_sensor(0x10, HI708_read_cmos_sensor(0x10)&0x7f); //Close AE
1432 HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)|0x08); //Reset AE
1433 //BEGIN <> <20130922> <improve the camera experience that before to capture the next photo, the screen lighten instantly> panzaoyan
1434 HI708_write_cmos_sensor(0x83, 0x01);
1435 HI708_write_cmos_sensor(0x84, 0xbc);
1436 HI708_write_cmos_sensor(0x85, 0x56);//15fps
1437 HI708_write_cmos_sensor(0x86, 0x00);
1438 HI708_write_cmos_sensor(0x87, 0xfa);
1439 //END <> <20130922> <improve the camera experience that before to capture the next photo, the screen lighten instantly> panzaoyan
1440 HI708_write_cmos_sensor(0x88, 0x01);
1441 HI708_write_cmos_sensor(0x89, 0xbc);
1442 HI708_write_cmos_sensor(0x8A, 0x56);//7
1443
1444 HI708_write_cmos_sensor(0x8b, 0x1f);
1445 HI708_write_cmos_sensor(0x8c, 0xbd);
1446 HI708_write_cmos_sensor(0x8d, 0x1a);
1447 HI708_write_cmos_sensor(0x8e, 0x5e);
1448
1449 HI708_write_cmos_sensor(0x9c, 0x03);
1450 HI708_write_cmos_sensor(0x9d, 0x6b);
1451 HI708_write_cmos_sensor(0x9e, 0x00);
1452 HI708_write_cmos_sensor(0x9f, 0xfa);
1453
1454
1455 HI708_write_cmos_sensor(0x01, HI708_read_cmos_sensor(0x01)&0xfe); //Exit Sleep: For Write Reg
1456
1457 HI708_write_cmos_sensor(0x03, 0x20);
1458 HI708_write_cmos_sensor(0x10, HI708_read_cmos_sensor(0x10)|0x80); //Open AE
1459 HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)&0xf7); //Reset AE
1460
1461 }
1462 else
1463 { SENSORDB("[HI708]HI708NightMode Enable AE_FLICKER_MODE_60HZ\n");
1464
1465 HI708_write_cmos_sensor(0x03, 0x20);
1466
1467 HI708_write_cmos_sensor(0x10, HI708_read_cmos_sensor(0x10)&0x7f); //Close AE
1468 HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)|0x08); //Reset AE
1469 //BEGIN <> <20130922> <improve the camera experience that before to capture the next photo, the screen lighten instantly> panzaoyan
1470 HI708_write_cmos_sensor(0x83, 0x01);
1471 HI708_write_cmos_sensor(0x84, 0xc0);
1472 HI708_write_cmos_sensor(0x85, 0x3e);//15fps
1473 HI708_write_cmos_sensor(0x86, 0x00);
1474 HI708_write_cmos_sensor(0x87, 0xfa);
1475 //END<> <20130922> <improve the camera experience that before to capture the next photo, the screen lighten instantly> panzaoyan
1476 HI708_write_cmos_sensor(0x88, 0x01);
1477 HI708_write_cmos_sensor(0x89, 0xc0);
1478 HI708_write_cmos_sensor(0x8A, 0x3e);//7
1479
1480 HI708_write_cmos_sensor(0x8b, 0x1f);
1481 HI708_write_cmos_sensor(0x8c, 0xbd);
1482 HI708_write_cmos_sensor(0x8d, 0x1a);
1483 HI708_write_cmos_sensor(0x8e, 0x5e);
1484
1485 HI708_write_cmos_sensor(0x9c, 0x03);
1486 HI708_write_cmos_sensor(0x9d, 0x6b);
1487 HI708_write_cmos_sensor(0x9e, 0x00);
1488 HI708_write_cmos_sensor(0x9f, 0xfa);
1489
1490
1491 HI708_write_cmos_sensor(0x01, HI708_read_cmos_sensor(0x01)&0xfe); //Exit Sleep: For Write Reg
1492
1493 HI708_write_cmos_sensor(0x03, 0x20);
1494 HI708_write_cmos_sensor(0x10, HI708_read_cmos_sensor(0x10)|0x80); //Open AE
1495 HI708_write_cmos_sensor(0x18, HI708_read_cmos_sensor(0x18)&0xf7); //Reset AE
1496
1497 }
1498
1499
1500 }
1501 }
1502
1503 /*************************************************************************
1504 * FUNCTION
1505 * HI708Preview
1506 *
1507 * DESCRIPTION
1508 * This function start the sensor preview.
1509 *
1510 * PARAMETERS
1511 * *image_window : address pointer of pixel numbers in one period of HSYNC
1512 * *sensor_config_data : address pointer of line numbers in one period of VSYNC
1513 *
1514 * RETURNS
1515 * None
1516 *
1517 * GLOBALS AFFECTED
1518 *
1519 *************************************************************************/
1520 static UINT32 HI708Preview(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
1521 MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
1522 {
1523
1524 HI708_write_cmos_sensor(0x03, 0x22);
1525 HI708_write_cmos_sensor(0x10, 0xfb);
1526 spin_lock(&hi708_yuv_drv_lock);
1527 sensor_config_data->SensorImageMirror = IMAGE_HV_MIRROR;
1528 if(HI708_sensor.first_init == KAL_TRUE)
1529 {
1530 HI708_sensor.MPEG4_Video_mode = HI708_sensor.MPEG4_Video_mode;
1531 }
1532 else
1533 {
1534 HI708_sensor.MPEG4_Video_mode = KAL_FALSE;//!HI708_sensor.MPEG4_Video_mode;
1535 }
1536 spin_unlock(&hi708_yuv_drv_lock);
1537
1538 SENSORDB("HHL[Enter]:HI708 preview func:");
1539 SENSORDB("HI708_sensor.video_mode = %d\n",HI708_sensor.MPEG4_Video_mode);
1540
1541 spin_lock(&hi708_yuv_drv_lock);
1542 HI708_sensor.first_init = KAL_FALSE;
1543 HI708_sensor.pv_mode = KAL_TRUE;
1544 spin_unlock(&hi708_yuv_drv_lock);
1545
1546 // {
1547 // SENSORDB("[HI708]preview set_VGA_mode\n");
1548 //
1549 // }
1550
1551 //HI708_write_cmos_sensor(0x03, 0x10);
1552 //HI708_write_cmos_sensor(0x40, 0x03);
1553 //HI708_write_cmos_sensor(0x62, 0x83);
1554 //HI708_write_cmos_sensor(0x63, 0x9a);
1555
1556 // HI708_Set_Mirror_Flip(sensor_config_data->SensorImageMirror);
1557 // HI708_Set_Mirror_Flip(IMAGE_V_MIRROR);
1558
1559 SENSORDB("[Exit]:HI708 preview func\n");
1560
1561 HI708_night_mode(HI708_sensor.night_mode);
1562 return TRUE;
1563 } /* HI708_Preview */
1564
1565
1566 UINT32 HI708Capture(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
1567 MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
1568 {
1569 kal_uint32 CapShutter;
1570 SENSORDB("HHL[HI708][Enter]HI708_capture_func\n");
1571 spin_lock(&hi708_yuv_drv_lock);
1572 HI708_sensor.pv_mode = KAL_FALSE;
1573 spin_unlock(&hi708_yuv_drv_lock);
1574 #if 0
1575 HI708_write_cmos_sensor(0x03, 0x20);
1576 HI708_sensor.PvShutter = (HI708_read_cmos_sensor(0x80) << 16)|(HI708_read_cmos_sensor(0x81) << 8)|HI708_read_cmos_sensor(0x82);
1577 CapShutter = HI708_sensor.PvShutter;
1578 HI708_sensor.CapExposure=HI708_sensor.PvShutter*8*76923
1579
1580 HI708_write_cmos_sensor(0x03, 0x20);
1581 HI708_write_cmos_sensor(0x83, (CapShutter >> 16) & 0xFF);
1582 HI708_write_cmos_sensor(0x84, (CapShutter >> 8) & 0xFF);
1583 HI708_write_cmos_sensor(0x85, CapShutter & 0xFF);
1584 #endif
1585 return ERROR_NONE;
1586 } /* HM3451Capture() */
1587
1588
1589 UINT32 HI708GetResolution(MSDK_SENSOR_RESOLUTION_INFO_STRUCT *pSensorResolution)
1590 {
1591 SENSORDB("[Enter]:HI708 get Resolution func\n");
1592
1593 pSensorResolution->SensorFullWidth=HI708_IMAGE_SENSOR_FULL_WIDTH ;
1594 pSensorResolution->SensorFullHeight=HI708_IMAGE_SENSOR_FULL_HEIGHT ;
1595 pSensorResolution->SensorPreviewWidth=HI708_IMAGE_SENSOR_PV_WIDTH ;
1596 pSensorResolution->SensorPreviewHeight=HI708_IMAGE_SENSOR_PV_HEIGHT ;
1597 pSensorResolution->SensorVideoWidth=HI708_IMAGE_SENSOR_PV_WIDTH ;
1598 pSensorResolution->SensorVideoHeight=HI708_IMAGE_SENSOR_PV_HEIGHT ;
1599 pSensorResolution->Sensor3DFullWidth=HI708_IMAGE_SENSOR_FULL_WIDTH ;
1600 pSensorResolution->Sensor3DFullHeight=HI708_IMAGE_SENSOR_FULL_HEIGHT ;
1601 pSensorResolution->Sensor3DPreviewWidth=HI708_IMAGE_SENSOR_PV_WIDTH ;
1602 pSensorResolution->Sensor3DPreviewHeight=HI708_IMAGE_SENSOR_PV_HEIGHT ;
1603 pSensorResolution->Sensor3DVideoWidth=HI708_IMAGE_SENSOR_PV_WIDTH ;
1604 pSensorResolution->Sensor3DVideoHeight=HI708_IMAGE_SENSOR_PV_HEIGHT ;
1605
1606 SENSORDB("[Exit]:HI708 get Resolution func\n");
1607 return ERROR_NONE;
1608 } /* HI708GetResolution() */
1609
1610 UINT32 HI708GetInfo(MSDK_SCENARIO_ID_ENUM ScenarioId,
1611 MSDK_SENSOR_INFO_STRUCT *pSensorInfo,
1612 MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData)
1613 {
1614
1615 switch(ScenarioId)
1616 {
1617
1618 case MSDK_SCENARIO_ID_CAMERA_ZSD:
1619 pSensorInfo->SensorPreviewResolutionX=HI708_IMAGE_SENSOR_PV_WIDTH;
1620 pSensorInfo->SensorPreviewResolutionY=HI708_IMAGE_SENSOR_PV_HEIGHT;
1621 pSensorInfo->SensorFullResolutionX=HI708_IMAGE_SENSOR_FULL_WIDTH;
1622 pSensorInfo->SensorFullResolutionY=HI708_IMAGE_SENSOR_FULL_HEIGHT;
1623 pSensorInfo->SensorCameraPreviewFrameRate=15;
1624 break;
1625
1626 case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
1627 case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
1628 pSensorInfo->SensorPreviewResolutionX=HI708_IMAGE_SENSOR_PV_WIDTH;
1629 pSensorInfo->SensorPreviewResolutionY=HI708_IMAGE_SENSOR_PV_HEIGHT;
1630 pSensorInfo->SensorFullResolutionX=HI708_IMAGE_SENSOR_FULL_WIDTH;
1631 pSensorInfo->SensorFullResolutionY=HI708_IMAGE_SENSOR_FULL_HEIGHT;
1632 pSensorInfo->SensorCameraPreviewFrameRate=30;
1633 break;
1634 case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
1635 pSensorInfo->SensorPreviewResolutionX=HI708_IMAGE_SENSOR_PV_WIDTH;
1636 pSensorInfo->SensorPreviewResolutionY=HI708_IMAGE_SENSOR_PV_HEIGHT;
1637 pSensorInfo->SensorFullResolutionX=HI708_IMAGE_SENSOR_FULL_WIDTH;
1638 pSensorInfo->SensorFullResolutionY=HI708_IMAGE_SENSOR_FULL_HEIGHT;
1639 pSensorInfo->SensorCameraPreviewFrameRate=30;
1640 break;
1641 case MSDK_SCENARIO_ID_CAMERA_3D_PREVIEW: //added
1642 case MSDK_SCENARIO_ID_CAMERA_3D_VIDEO:
1643 case MSDK_SCENARIO_ID_CAMERA_3D_CAPTURE: //added
1644 pSensorInfo->SensorPreviewResolutionX=HI708_IMAGE_SENSOR_PV_WIDTH;
1645 pSensorInfo->SensorPreviewResolutionY=HI708_IMAGE_SENSOR_PV_HEIGHT;
1646 pSensorInfo->SensorFullResolutionX=HI708_IMAGE_SENSOR_FULL_WIDTH;
1647 pSensorInfo->SensorFullResolutionY=HI708_IMAGE_SENSOR_FULL_HEIGHT;
1648 pSensorInfo->SensorCameraPreviewFrameRate=30;
1649 break;
1650 default:
1651
1652 pSensorInfo->SensorPreviewResolutionX=HI708_IMAGE_SENSOR_PV_WIDTH;
1653 pSensorInfo->SensorPreviewResolutionY=HI708_IMAGE_SENSOR_PV_HEIGHT;
1654 pSensorInfo->SensorFullResolutionX=HI708_IMAGE_SENSOR_FULL_WIDTH;
1655 pSensorInfo->SensorFullResolutionY=HI708_IMAGE_SENSOR_FULL_HEIGHT;
1656 pSensorInfo->SensorCameraPreviewFrameRate=30;
1657 break;
1658
1659 }
1660
1661
1662
1663 SENSORDB("[Enter]:HI708 getInfo func:ScenarioId = %d\n",ScenarioId);
1664
1665 // pSensorInfo->SensorPreviewResolutionX=HI708_IMAGE_SENSOR_PV_WIDTH;
1666 // pSensorInfo->SensorPreviewResolutionY=HI708_IMAGE_SENSOR_PV_HEIGHT;
1667 // pSensorInfo->SensorFullResolutionX=HI708_IMAGE_SENSOR_FULL_WIDTH;
1668 // pSensorInfo->SensorFullResolutionY=HI708_IMAGE_SENSOR_FULL_HEIGHT;
1669
1670 pSensorInfo->SensorCameraPreviewFrameRate=30;
1671 pSensorInfo->SensorVideoFrameRate=30;
1672 pSensorInfo->SensorStillCaptureFrameRate=30;
1673 pSensorInfo->SensorWebCamCaptureFrameRate=15;
1674 pSensorInfo->SensorResetActiveHigh=FALSE;//low is to reset
1675 pSensorInfo->SensorResetDelayCount=4; //4ms
1676 pSensorInfo->SensorOutputDataFormat=SENSOR_OUTPUT_FORMAT_YUYV; //SENSOR_OUTPUT_FORMAT_YVYU;
1677 pSensorInfo->SensorClockPolarity=SENSOR_CLOCK_POLARITY_LOW;
1678 pSensorInfo->SensorClockFallingPolarity=SENSOR_CLOCK_POLARITY_LOW;
1679 pSensorInfo->SensorHsyncPolarity = SENSOR_CLOCK_POLARITY_LOW;
1680 pSensorInfo->SensorVsyncPolarity = SENSOR_CLOCK_POLARITY_LOW;
1681 pSensorInfo->SensorInterruptDelayLines = 1;
1682 pSensorInfo->SensroInterfaceType=SENSOR_INTERFACE_TYPE_PARALLEL;
1683
1684
1685 pSensorInfo->CaptureDelayFrame = 2;
1686 pSensorInfo->PreviewDelayFrame = 2;//10;
1687 pSensorInfo->VideoDelayFrame = 0;
1688 pSensorInfo->SensorMasterClockSwitch = 0;
1689 pSensorInfo->SensorDrivingCurrent = ISP_DRIVING_8MA;
1690
1691 switch (ScenarioId)
1692 {
1693 case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
1694 case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
1695 case MSDK_SCENARIO_ID_CAMERA_3D_PREVIEW:
1696 case MSDK_SCENARIO_ID_CAMERA_3D_VIDEO:
1697 pSensorInfo->SensorClockFreq=26;
1698 pSensorInfo->SensorClockDividCount= 3;
1699 pSensorInfo->SensorClockRisingCount= 0;
1700 pSensorInfo->SensorClockFallingCount= 2;
1701 pSensorInfo->SensorPixelClockCount= 3;
1702 pSensorInfo->SensorDataLatchCount= 2;
1703 pSensorInfo->SensorGrabStartX = 4;
1704 pSensorInfo->SensorGrabStartY = 2;
1705 break;
1706 case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
1707 case MSDK_SCENARIO_ID_CAMERA_3D_CAPTURE:
1708 pSensorInfo->SensorClockFreq=26;
1709 pSensorInfo->SensorClockDividCount= 3;
1710 pSensorInfo->SensorClockRisingCount= 0;
1711 pSensorInfo->SensorClockFallingCount= 2;
1712 pSensorInfo->SensorPixelClockCount= 3;
1713 pSensorInfo->SensorDataLatchCount= 2;
1714 pSensorInfo->SensorGrabStartX = 4;
1715 pSensorInfo->SensorGrabStartY = 2;//4;
1716 break;
1717 default:
1718 pSensorInfo->SensorClockFreq=26;
1719 pSensorInfo->SensorClockDividCount=3;
1720 pSensorInfo->SensorClockRisingCount=0;
1721 pSensorInfo->SensorClockFallingCount=2;
1722 pSensorInfo->SensorPixelClockCount=3;
1723 pSensorInfo->SensorDataLatchCount=2;
1724 pSensorInfo->SensorGrabStartX = 4;
1725 pSensorInfo->SensorGrabStartY = 2;//4;
1726 break;
1727 }
1728 // HI708_PixelClockDivider=pSensorInfo->SensorPixelClockCount;
1729 memcpy(pSensorConfigData, &HI708SensorConfigData, sizeof(MSDK_SENSOR_CONFIG_STRUCT));
1730
1731 SENSORDB("[Exit]:HI708 getInfo func\n");
1732 return ERROR_NONE;
1733 } /* HI708GetInfo() */
1734
1735
1736 UINT32 HI708Control(MSDK_SCENARIO_ID_ENUM ScenarioId, MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *pImageWindow,
1737 MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData)
1738 {
1739 SENSORDB("HHL [Enter]:HI708 Control func:ScenarioId = %d\n",ScenarioId);
1740
1741 switch (ScenarioId)
1742 {
1743 case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
1744 case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
1745 //case MSDK_SCENARIO_ID_CAMERA_3D_PREVIEW:
1746 //case MSDK_SCENARIO_ID_CAMERA_3D_VIDEO:
1747 HI708Preview(pImageWindow, pSensorConfigData);
1748 break;
1749 case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
1750 //case MSDK_SCENARIO_ID_CAMERA_3D_CAPTURE:
1751 HI708Capture(pImageWindow, pSensorConfigData);
1752 break;
1753 // case MSDK_SCENARIO_ID_CAMERA_3D_PREVIEW: //added
1754 // case MSDK_SCENARIO_ID_CAMERA_3D_VIDEO:
1755 // case MSDK_SCENARIO_ID_CAMERA_3D_CAPTURE: //added
1756 // HI708Preview(pImageWindow, pSensorConfigData);
1757 // break;
1758 // case MSDK_SCENARIO_ID_CAMERA_ZSD:
1759 // HI708Capture(pImageWindow, pSensorConfigData);
1760 // break;
1761 default:
1762 break;
1763 }
1764
1765 SENSORDB("[Exit]:HI708 Control func\n");
1766 return TRUE;
1767 } /* HI708Control() */
1768
1769
1770 /*************************************************************************
1771 * FUNCTION
1772 * HI708_set_param_wb
1773 *
1774 * DESCRIPTION
1775 * wb setting.
1776 *
1777 * PARAMETERS
1778 * none
1779 *
1780 * RETURNS
1781 * None
1782 *
1783 * GLOBALS AFFECTED
1784 *
1785 *************************************************************************/
1786 BOOL HI708_set_param_wb(UINT16 para)
1787 {
1788 //This sensor need more time to balance AWB,
1789 //we suggest higher fps or drop some frame to avoid garbage color when preview initial
1790 SENSORDB("[Enter]HI708 set_param_wb func:para = %d\n",para);
1791
1792 if(HI708_sensor.wb == para) return KAL_TRUE;
1793
1794 spin_lock(&hi708_yuv_drv_lock);
1795 HI708_sensor.wb = para;
1796 spin_unlock(&hi708_yuv_drv_lock);
1797
1798 switch (para)
1799 {
1800 case AWB_MODE_AUTO:
1801 {
1802 HI708_write_cmos_sensor(0x03, 0x22);
1803 HI708_write_cmos_sensor(0x11, 0x2e);
1804 HI708_write_cmos_sensor(0x80, 0x38);
1805 HI708_write_cmos_sensor(0x82, 0x30);
1806 HI708_write_cmos_sensor(0x83, 0x46);//56
1807 HI708_write_cmos_sensor(0x84, 0x16);
1808 HI708_write_cmos_sensor(0x85, 0x57);
1809 HI708_write_cmos_sensor(0x86, 0x28);
1810 }
1811 break;
1812 case AWB_MODE_CLOUDY_DAYLIGHT:
1813 {
1814 HI708_write_cmos_sensor(0x03, 0x22);
1815 HI708_write_cmos_sensor(0x11, 0x28);
1816 HI708_write_cmos_sensor(0x80, 0x52);
1817 HI708_write_cmos_sensor(0x81, 0x20);
1818 HI708_write_cmos_sensor(0x82, 0x2e);
1819 HI708_write_cmos_sensor(0x83, 0x5d);
1820 HI708_write_cmos_sensor(0x84, 0x55);
1821 HI708_write_cmos_sensor(0x85, 0x30);
1822 HI708_write_cmos_sensor(0x86, 0x25);
1823 }
1824 break;
1825 case AWB_MODE_DAYLIGHT:
1826 {
1827 HI708_write_cmos_sensor(0x03, 0x22);
1828 HI708_write_cmos_sensor(0x11, 0x28);
1829 HI708_write_cmos_sensor(0x80, 0x50);
1830 HI708_write_cmos_sensor(0x81, 0x20);
1831 HI708_write_cmos_sensor(0x82, 0x2d);
1832 HI708_write_cmos_sensor(0x83, 0x52);
1833 HI708_write_cmos_sensor(0x84, 0x40);
1834 HI708_write_cmos_sensor(0x85, 0x30);
1835 HI708_write_cmos_sensor(0x86, 0x1c);
1836 }
1837 break;
1838 case AWB_MODE_INCANDESCENT:
1839 {
1840 HI708_write_cmos_sensor(0x03, 0x22);
1841 HI708_write_cmos_sensor(0x11, 0x28);
1842 HI708_write_cmos_sensor(0x80, 0x29);
1843 HI708_write_cmos_sensor(0x82, 0x54);
1844 HI708_write_cmos_sensor(0x83, 0x2e);
1845 HI708_write_cmos_sensor(0x84, 0x23);
1846 HI708_write_cmos_sensor(0x85, 0x58);
1847 HI708_write_cmos_sensor(0x86, 0x4f);
1848 }
1849 break;
1850 case AWB_MODE_FLUORESCENT:
1851 {
1852 HI708_write_cmos_sensor(0x03, 0x22);
1853 HI708_write_cmos_sensor(0x11, 0x28);
1854 HI708_write_cmos_sensor(0x80, 0x40);
1855 HI708_write_cmos_sensor(0x81, 0x20);
1856 HI708_write_cmos_sensor(0x82, 0x4f);
1857 HI708_write_cmos_sensor(0x83, 0x44);
1858 HI708_write_cmos_sensor(0x84, 0x3a);
1859 HI708_write_cmos_sensor(0x85, 0x47);
1860 HI708_write_cmos_sensor(0x86, 0x3a);
1861 }
1862 break;
1863 case AWB_MODE_TUNGSTEN:
1864 {
1865 HI708_write_cmos_sensor(0x03, 0x22);
1866 HI708_write_cmos_sensor(0x80, 0x24);
1867 HI708_write_cmos_sensor(0x81, 0x20);
1868 HI708_write_cmos_sensor(0x82, 0x58);
1869 HI708_write_cmos_sensor(0x83, 0x27);
1870 HI708_write_cmos_sensor(0x84, 0x22);
1871 HI708_write_cmos_sensor(0x85, 0x58);
1872 HI708_write_cmos_sensor(0x86, 0x52);
1873 }
1874 break;
1875 case AWB_MODE_OFF:
1876 {
1877 SENSORDB("HI708 AWB OFF");
1878 HI708_write_cmos_sensor(0x03, 0x22);
1879 HI708_write_cmos_sensor(0x10, 0xe2);
1880 }
1881 break;
1882 default:
1883 return FALSE;
1884 }
1885
1886 return TRUE;
1887 } /* HI708_set_param_wb */
1888
1889 /*************************************************************************
1890 * FUNCTION
1891 * HI708_set_param_effect
1892 *
1893 * DESCRIPTION
1894 * effect setting.
1895 *
1896 * PARAMETERS
1897 * none
1898 *
1899 * RETURNS
1900 * None
1901 *
1902 * GLOBALS AFFECTED
1903 *
1904 *************************************************************************/
1905 BOOL HI708_set_param_effect(UINT16 para)
1906 {
1907 SENSORDB("[Enter]HI708 set_param_effect func:para = %d\n",para);
1908
1909 if(HI708_sensor.effect == para) return KAL_TRUE;
1910
1911 spin_lock(&hi708_yuv_drv_lock);
1912 HI708_sensor.effect = para;
1913 spin_unlock(&hi708_yuv_drv_lock);
1914
1915 switch (para)
1916 {
1917 case MEFFECT_OFF:
1918 {
1919 HI708_write_cmos_sensor(0x03, 0x10);
1920 HI708_write_cmos_sensor(0x11, 0x43);
1921 HI708_write_cmos_sensor(0x12, 0xF0);
1922 HI708_write_cmos_sensor(0x13, 0x03);
1923 HI708_write_cmos_sensor(0x44, 0x80);
1924 HI708_write_cmos_sensor(0x45, 0x80);
1925
1926 HI708_write_cmos_sensor(0x47, 0x7f);
1927 //HI708_write_cmos_sensor(0x03, 0x13);
1928 // HI708_write_cmos_sensor(0x20, 0x07);
1929 //HI708_write_cmos_sensor(0x21, 0x07);
1930
1931
1932 }
1933 break;
1934 case MEFFECT_SEPIA:
1935 {
1936 HI708_write_cmos_sensor(0x03, 0x10);
1937 HI708_write_cmos_sensor(0x11, 0x03);
1938 HI708_write_cmos_sensor(0x12, 0x23);
1939 HI708_write_cmos_sensor(0x13, 0x00);
1940 HI708_write_cmos_sensor(0x44, 0x6c);
1941 HI708_write_cmos_sensor(0x45, 0x9a);
1942
1943 HI708_write_cmos_sensor(0x47, 0x7f);
1944 // HI708_write_cmos_sensor(0x03, 0x13);
1945 // HI708_write_cmos_sensor(0x20, 0x07);
1946 //HI708_write_cmos_sensor(0x21, 0x07);
1947
1948
1949 }
1950 break;
1951 case MEFFECT_NEGATIVE:
1952 {
1953 HI708_write_cmos_sensor(0x03, 0x10);
1954 HI708_write_cmos_sensor(0x11, 0x03);
1955 HI708_write_cmos_sensor(0x12, 0x08);
1956 HI708_write_cmos_sensor(0x13, 0x00);
1957 HI708_write_cmos_sensor(0x14, 0x00);
1958 }
1959 break;
1960 case MEFFECT_SEPIAGREEN:
1961 {
1962 HI708_write_cmos_sensor(0x03, 0x10);
1963 HI708_write_cmos_sensor(0x11, 0x03);
1964 HI708_write_cmos_sensor(0x12, 0x03);
1965 //HI708_write_cmos_sensor(0x40, 0x00);
1966 HI708_write_cmos_sensor(0x13, 0x00);
1967 HI708_write_cmos_sensor(0x44, 0x30);
1968 HI708_write_cmos_sensor(0x45, 0x50);
1969 }
1970 break;
1971 case MEFFECT_SEPIABLUE:
1972 {
1973 HI708_write_cmos_sensor(0x03, 0x10);
1974 HI708_write_cmos_sensor(0x11, 0x03);
1975 HI708_write_cmos_sensor(0x12, 0x03);
1976 //HI708_write_cmos_sensor(0x40, 0x00);
1977 HI708_write_cmos_sensor(0x13, 0x00);
1978 HI708_write_cmos_sensor(0x44, 0xb0);
1979 HI708_write_cmos_sensor(0x45, 0x40);
1980 }
1981 break;
1982 case MEFFECT_MONO:
1983 {
1984 HI708_write_cmos_sensor(0x03, 0x10);
1985 HI708_write_cmos_sensor(0x11, 0x03);
1986 HI708_write_cmos_sensor(0x12, 0x03);
1987 //HI708_write_cmos_sensor(0x40, 0x00);
1988 HI708_write_cmos_sensor(0x44, 0x80);
1989 HI708_write_cmos_sensor(0x45, 0x80);
1990 }
1991 break;
1992 default:
1993 return KAL_FALSE;
1994 }
1995
1996 return KAL_TRUE;
1997 } /* HI708_set_param_effect */
1998
1999 /*************************************************************************
2000 * FUNCTION
2001 * HI708_set_param_banding
2002 *
2003 * DESCRIPTION
2004 * banding setting.
2005 *
2006 * PARAMETERS
2007 * none
2008 *
2009 * RETURNS
2010 * None
2011 *
2012 * GLOBALS AFFECTED
2013 *
2014 *************************************************************************/
2015 BOOL HI708_set_param_banding(UINT16 para)
2016 {
2017 SENSORDB("[Enter]HI708 set_param_banding func:para = %d\n",para);
2018
2019 if(HI708_sensor.banding == para) return KAL_TRUE;
2020
2021 spin_lock(&hi708_yuv_drv_lock);
2022 HI708_sensor.banding = para;
2023 spin_unlock(&hi708_yuv_drv_lock);
2024
2025 switch (para)
2026 {
2027 case AE_FLICKER_MODE_50HZ:
2028 {
2029 HI708_write_cmos_sensor(0x03,0x20);
2030 HI708_write_cmos_sensor(0x10,0x1c);
2031 HI708_write_cmos_sensor(0x18,0x38);
2032 //BEGIN <> <20130922> <improve the camera experience that before to capture the next photo, the screen lighten instantly> panzaoyan
2033 HI708_write_cmos_sensor(0x83, 0x01);
2034 HI708_write_cmos_sensor(0x84, 0xbc);
2035 HI708_write_cmos_sensor(0x85, 0x56);//15fps
2036 //END <> <20130922> <improve the camera experience that before to capture the next photo, the screen lighten instantly> panzaoyan
2037 HI708_write_cmos_sensor(0x88, 0x01);
2038 HI708_write_cmos_sensor(0x89, 0xbc);
2039 HI708_write_cmos_sensor(0x8A, 0x56);//50HZ
2040
2041 HI708_write_cmos_sensor(0x18, 0x30);
2042 HI708_write_cmos_sensor(0x10, 0x9c);
2043 }
2044 break;
2045 case AE_FLICKER_MODE_60HZ:
2046 {
2047 HI708_write_cmos_sensor(0x03,0x20);
2048 HI708_write_cmos_sensor(0x10,0x0c);
2049 HI708_write_cmos_sensor(0x18,0x38);
2050 //BEGIN <> <20130922> <improve the camera experience that before to capture the next photo, the screen lighten instantly> panzaoyan
2051 HI708_write_cmos_sensor(0x83, 0x01);
2052 HI708_write_cmos_sensor(0x84, 0xc0);
2053 HI708_write_cmos_sensor(0x85, 0x3e);//15fps
2054 HI708_write_cmos_sensor(0x86, 0x00);
2055 HI708_write_cmos_sensor(0x87, 0xfa);
2056 //END <> <20130922> <improve the camera experience that before to capture the next photo, the screen lighten instantly> panzaoyan
2057 HI708_write_cmos_sensor(0x88, 0x01);
2058 HI708_write_cmos_sensor(0x89, 0xc0);
2059 HI708_write_cmos_sensor(0x8A, 0x3e);//60HZ
2060
2061 HI708_write_cmos_sensor(0x18, 0x30);
2062 HI708_write_cmos_sensor(0x10, 0x8c);
2063 }
2064 break;
2065 default:
2066 {
2067 HI708_write_cmos_sensor(0x03,0x20);
2068 HI708_write_cmos_sensor(0x10,0x1c);
2069 HI708_write_cmos_sensor(0x18,0x38);
2070 //BEGIN <> <20130922> <improve the camera experience that before to capture the next photo, the screen lighten instantly> panzaoyan
2071 HI708_write_cmos_sensor(0x83, 0x01);
2072 HI708_write_cmos_sensor(0x84, 0xbc);
2073 HI708_write_cmos_sensor(0x85, 0x56);//15fps
2074 //END <> <20130922> <improve the camera experience that before to capture the next photo, the screen lighten instantly> panzaoyan
2075 HI708_write_cmos_sensor(0x88, 0x01);
2076 HI708_write_cmos_sensor(0x89, 0xbc);
2077 HI708_write_cmos_sensor(0x8A, 0x56);//50HZ
2078
2079 HI708_write_cmos_sensor(0x18, 0x30);
2080 HI708_write_cmos_sensor(0x10, 0x9c);
2081 }
2082 }
2083
2084 return KAL_TRUE;
2085 } /* HI708_set_param_banding */
2086
2087
2088
2089
2090 /*************************************************************************
2091 * FUNCTION
2092 * HI708_set_param_exposure
2093 *
2094 * DESCRIPTION
2095 * exposure setting.
2096 *
2097 * PARAMETERS
2098 * none
2099 *
2100 * RETURNS
2101 * None
2102 *
2103 * GLOBALS AFFECTED
2104 *
2105 *************************************************************************/
2106 BOOL HI708_set_param_exposure(UINT16 para)
2107 {
2108 SENSORDB("[Enter]HI708 set_param_exposure func:para = %d\n",para);
2109
2110 if(HI708_sensor.exposure == para) return KAL_TRUE;
2111
2112 spin_lock(&hi708_yuv_drv_lock);
2113 HI708_sensor.exposure = para;
2114 spin_unlock(&hi708_yuv_drv_lock);
2115
2116 HI708_write_cmos_sensor(0x03,0x10);
2117 HI708_write_cmos_sensor(0x12,HI708_read_cmos_sensor(0x12)|0x10);
2118 switch (para)
2119 {
2120 /*GIONEE: malp 20130625 add for CR00828155 start*/
2121 case AE_EV_COMP_20: //+2 EV
2122 HI708_write_cmos_sensor(0x40,0x30);
2123 break;
2124 /*GIONEE: malp 20130625 add for CR00828155 end*/
2125 case AE_EV_COMP_13: //+1.3 EV
2126 HI708_write_cmos_sensor(0x40,0x20);
2127 break;
2128 case AE_EV_COMP_10: //+1 EV
2129 HI708_write_cmos_sensor(0x40,0x15);
2130 break;
2131 case AE_EV_COMP_07: //+0.7 EV
2132 HI708_write_cmos_sensor(0x40,0x10);
2133 break;
2134 case AE_EV_COMP_03: // +0.3 EV
2135 HI708_write_cmos_sensor(0x40,0x05);
2136 break;
2137 case AE_EV_COMP_00: // +0 EV
2138 HI708_write_cmos_sensor(0x40,0x88);//90//96 wangc modified for reducing previewer brightness at 2012-10-24
2139
2140 break;
2141 case AE_EV_COMP_n03: // -0.3 EV
2142 HI708_write_cmos_sensor(0x40,0x95);//98//a3
2143
2144 break;
2145 case AE_EV_COMP_n07: // -0.7 EV
2146 HI708_write_cmos_sensor(0x40,0xa0);
2147 break;
2148 case AE_EV_COMP_n10: //-1 EV
2149 HI708_write_cmos_sensor(0x40,0xa5);
2150 break;
2151 case AE_EV_COMP_n13: // -1.3 EV
2152 HI708_write_cmos_sensor(0x40,0xb0);
2153 break;
2154 /*GIONEE: malp 20130625 add for CR00828155 start*/
2155 case AE_EV_COMP_n20: //-2 EV
2156 HI708_write_cmos_sensor(0x40,0xc0);
2157 break;
2158 /*GIONEE: malp 20130625 add for CR00828155 end*/
2159 default:
2160 return FALSE;
2161 }
2162
2163 return TRUE;
2164 } /* HI708_set_param_exposure */
2165
2166 void HI708_set_AE_mode(UINT32 iPara)
2167 {
2168 UINT8 temp_AE_reg = 0;
2169 SENSORDB("HI708_set_AE_mode = %d E \n",iPara);
2170 HI708_write_cmos_sensor(0x03,0x20);
2171 temp_AE_reg = HI708_read_cmos_sensor(0x10);
2172
2173 if (AE_MODE_OFF == iPara)
2174 {
2175 // turn off AEC/AGC
2176 HI708_write_cmos_sensor(0x10,temp_AE_reg &~ 0x10);
2177 }
2178 else
2179 {
2180 HI708_write_cmos_sensor(0x10,temp_AE_reg | 0x10);
2181 }
2182 }
2183 UINT32 HI708YUVSensorSetting(FEATURE_ID iCmd, UINT32 iPara)
2184 {
2185 SENSORDB("[Enter]HI708YUVSensorSetting func:cmd = %d\n",iCmd);
2186
2187 switch (iCmd)
2188 {
2189 case FID_SCENE_MODE: //auto mode or night mode
2190 if (iPara == SCENE_MODE_OFF)//auto mode
2191 {
2192 HI708_night_mode(FALSE);
2193 }
2194 else if (iPara == SCENE_MODE_NIGHTSCENE)//night mode
2195 {
2196 HI708_night_mode(TRUE);
2197 }
2198 break;
2199 case FID_AWB_MODE:
2200 HI708_set_param_wb(iPara);
2201 break;
2202 case FID_COLOR_EFFECT:
2203 HI708_set_param_effect(iPara);
2204 break;
2205 case FID_AE_EV:
2206 HI708_set_param_exposure(iPara);
2207 break;
2208 case FID_AE_FLICKER:
2209 HI708_set_param_banding(iPara);
2210 break;
2211 case FID_ZOOM_FACTOR:
2212 spin_lock(&hi708_yuv_drv_lock);
2213 HI708_zoom_factor = iPara;
2214 spin_unlock(&hi708_yuv_drv_lock);
2215 break;
2216 case FID_AE_SCENE_MODE:
2217 HI708_set_AE_mode(iPara);
2218 break;
2219 default:
2220 break;
2221 }
2222 return TRUE;
2223 } /* HI708YUVSensorSetting */
2224
2225 UINT32 HI708YUVSetVideoMode(UINT16 u2FrameRate)
2226 {
2227 /* spin_lock(&hi708_yuv_drv_lock);
2228 HI708_sensor.MPEG4_Video_mode = KAL_TRUE;
2229 spin_unlock(&hi708_yuv_drv_lock);
2230 SENSORDB("[Enter]HI708 Set Video Mode:FrameRate= %d\n",u2FrameRate);
2231 SENSORDB("HI708_sensor.video_mode = %d\n",HI708_sensor.MPEG4_Video_mode);
2232
2233 // if(u2FrameRate == 30) u2FrameRate = 20;
2234 //u2FrameRate = 12;
2235
2236 spin_lock(&hi708_yuv_drv_lock);
2237 HI708_sensor.fix_framerate = u2FrameRate * 10;
2238 spin_unlock(&hi708_yuv_drv_lock);
2239
2240 if(HI708_sensor.fix_framerate <= 300 )
2241 {
2242 HI708_Fix_Video_Frame_Rate(HI708_sensor.fix_framerate);
2243 }
2244 else
2245 {
2246 SENSORDB("Wrong Frame Rate");
2247 }
2248
2249 return TRUE;
2250 */
2251 }
2252
2253 void HI708GetAFMaxNumFocusAreas(UINT32 *pFeatureReturnPara32)
2254 {
2255 *pFeatureReturnPara32 = 0;
2256 SENSORDB("HI708GetAFMaxNumFocusAreas *pFeatureReturnPara32 = %d\n", *pFeatureReturnPara32);
2257 }
2258
2259 void HI708GetAEMaxNumMeteringAreas(UINT32 *pFeatureReturnPara32)
2260 {
2261 *pFeatureReturnPara32 = 0;
2262 SENSORDB("HI708GetAEMaxNumMeteringAreas *pFeatureReturnPara32 = %d\n", *pFeatureReturnPara32);
2263 }
2264
2265 void HI708GetExifInfo(UINT32 exifAddr)
2266 {
2267 SENSOR_EXIF_INFO_STRUCT* pExifInfo = (SENSOR_EXIF_INFO_STRUCT*)exifAddr;
2268 pExifInfo->FNumber = 28;
2269 pExifInfo->AEISOSpeed = AE_ISO_100;
2270 pExifInfo->AWBMode = HI708_sensor.wb;
2271 pExifInfo->CapExposureTime = 0;
2272 pExifInfo->FlashLightTimeus = 0;
2273 pExifInfo->RealISOValue = AE_ISO_100;
2274 }
2275
2276 /*****add by zero *********/
2277 UINT32 HI708SetTestPatternMode(kal_bool bEnable)
2278 {
2279 printk("zero %s\n ",__func__);
2280 HI708_Set_Mirror_Flip(IMAGE_NORMAL);
2281 }
2282 /*******end*************/
2283
2284 UINT32 HI708FeatureControl(MSDK_SENSOR_FEATURE_ENUM FeatureId,
2285 UINT8 *pFeaturePara,UINT32 *pFeatureParaLen)
2286 {
2287 //UINT16 u2Temp = 0;
2288 UINT16 *pFeatureReturnPara16=(UINT16 *) pFeaturePara;
2289 UINT16 *pFeatureData16=(UINT16 *) pFeaturePara;
2290 UINT32 *pFeatureReturnPara32=(UINT32 *) pFeaturePara;
2291 UINT32 *pFeatureData32=(UINT32 *) pFeaturePara;
2292 MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData=(MSDK_SENSOR_CONFIG_STRUCT *) pFeaturePara;
2293 MSDK_SENSOR_REG_INFO_STRUCT *pSensorRegData=(MSDK_SENSOR_REG_INFO_STRUCT *) pFeaturePara;
2294 SENSORDB("HHL [Enter]:HI708 Feature Control func:FeatureId = %d\n",FeatureId);
2295
2296 switch (FeatureId)
2297 {
2298 case SENSOR_FEATURE_GET_RESOLUTION:
2299 *pFeatureReturnPara16++=HI708_IMAGE_SENSOR_FULL_WIDTH;
2300 *pFeatureReturnPara16=HI708_IMAGE_SENSOR_FULL_HEIGHT;
2301 *pFeatureParaLen=4;
2302 break;
2303 case SENSOR_FEATURE_GET_PERIOD:
2304 *pFeatureReturnPara16++=HI708_IMAGE_SENSOR_PV_WIDTH;//+HI708_sensor.pv_dummy_pixels;
2305 *pFeatureReturnPara16=HI708_IMAGE_SENSOR_PV_HEIGHT;//+HI708_sensor.pv_dummy_lines;
2306 *pFeatureParaLen=4;
2307 break;
2308 case SENSOR_FEATURE_GET_PIXEL_CLOCK_FREQ:
2309 //*pFeatureReturnPara32 = HI708_sensor_pclk/10;
2310 *pFeatureParaLen=4;
2311 break;
2312 case SENSOR_FEATURE_SET_ESHUTTER:
2313
2314 break;
2315 case SENSOR_FEATURE_SET_NIGHTMODE:
2316 HI708_night_mode((BOOL) *pFeatureData16);
2317 break;
2318 case SENSOR_FEATURE_SET_GAIN:
2319 break;
2320 case SENSOR_FEATURE_SET_FLASHLIGHT:
2321 break;
2322 case SENSOR_FEATURE_SET_ISP_MASTER_CLOCK_FREQ:
2323 break;
2324 case SENSOR_FEATURE_SET_REGISTER:
2325 HI708_write_cmos_sensor(pSensorRegData->RegAddr, pSensorRegData->RegData);
2326 break;
2327 case SENSOR_FEATURE_GET_REGISTER:
2328 pSensorRegData->RegData = HI708_read_cmos_sensor(pSensorRegData->RegAddr);
2329 break;
2330 case SENSOR_FEATURE_GET_CONFIG_PARA:
2331 memcpy(pSensorConfigData, &HI708SensorConfigData, sizeof(MSDK_SENSOR_CONFIG_STRUCT));
2332 *pFeatureParaLen=sizeof(MSDK_SENSOR_CONFIG_STRUCT);
2333 break;
2334 case SENSOR_FEATURE_SET_CCT_REGISTER:
2335 case SENSOR_FEATURE_GET_CCT_REGISTER:
2336 case SENSOR_FEATURE_SET_ENG_REGISTER:
2337 case SENSOR_FEATURE_GET_ENG_REGISTER:
2338 case SENSOR_FEATURE_GET_REGISTER_DEFAULT:
2339 case SENSOR_FEATURE_CAMERA_PARA_TO_SENSOR:
2340 case SENSOR_FEATURE_SENSOR_TO_CAMERA_PARA:
2341 case SENSOR_FEATURE_GET_GROUP_INFO:
2342 case SENSOR_FEATURE_GET_ITEM_INFO:
2343 case SENSOR_FEATURE_SET_ITEM_INFO:
2344 case SENSOR_FEATURE_GET_ENG_INFO:
2345 break;
2346 case SENSOR_FEATURE_GET_GROUP_COUNT:
2347 // *pFeatureReturnPara32++=0;
2348 //*pFeatureParaLen=4;
2349 break;
2350
2351 case SENSOR_FEATURE_GET_LENS_DRIVER_ID:
2352 // get the lens driver ID from EEPROM or just return LENS_DRIVER_ID_DO_NOT_CARE
2353 // if EEPROM does not exist in camera module.
2354 *pFeatureReturnPara32=LENS_DRIVER_ID_DO_NOT_CARE;
2355 *pFeatureParaLen=4;
2356 break;
2357 case SENSOR_FEATURE_SET_YUV_CMD:
2358 HI708YUVSensorSetting((FEATURE_ID)*pFeatureData32, *(pFeatureData32+1));
2359 break;
2360 case SENSOR_FEATURE_SET_VIDEO_MODE:
2361 HI708YUVSetVideoMode(*pFeatureData16);
2362 break;
2363 case SENSOR_FEATURE_CHECK_SENSOR_ID:
2364 HI708_GetSensorID(pFeatureData32);
2365 break;
2366 case SENSOR_FEATURE_GET_AF_MAX_NUM_FOCUS_AREAS:
2367 HI708GetAFMaxNumFocusAreas(pFeatureReturnPara32);
2368 *pFeatureParaLen=4;
2369 break;
2370 case SENSOR_FEATURE_GET_AE_MAX_NUM_METERING_AREAS:
2371 HI708GetAEMaxNumMeteringAreas(pFeatureReturnPara32);
2372 *pFeatureParaLen=4;
2373 break;
2374 case SENSOR_FEATURE_GET_EXIF_INFO:
2375 SENSORDB("SENSOR_FEATURE_GET_EXIF_INFO\n");
2376 SENSORDB("EXIF addr = 0x%x\n",*pFeatureData32);
2377 HI708GetExifInfo(*pFeatureData32);
2378 break;
2379 case SENSOR_FEATURE_SET_TEST_PATTERN:
2380 HI708SetTestPatternMode((BOOL)*pFeatureData16); //add by zero
2381 break;
2382 default:
2383 break;
2384 }
2385 return ERROR_NONE;
2386 } /* HI708FeatureControl() */
2387
2388
2389 SENSOR_FUNCTION_STRUCT SensorFuncHI708=
2390 {
2391 HI708Open,
2392 HI708GetInfo,
2393 HI708GetResolution,
2394 HI708FeatureControl,
2395 HI708Control,
2396 HI708Close
2397 };
2398
2399 UINT32 HI708_YUV_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc)
2400 {
2401
2402 /* To Do : Check Sensor status here */
2403 if (pfFunc!=NULL)
2404 *pfFunc=&SensorFuncHI708;
2405
2406 return ERROR_NONE;
2407 } /* SensorInit() */
2408
2409