mt9p111: solve bug that 32 pixsel data are not captured every line.
authorlzg <lzg@rockchip.com.cn>
Fri, 27 May 2011 05:57:22 +0000 (22:57 -0700)
committerlzg <lzg@rockchip.com.cn>
Fri, 27 May 2011 05:57:22 +0000 (22:57 -0700)
mt9p111: solve bug that colour effect set fail
mt9p111: solve bug that video 720p set fail
mt9p111: solve bug that auto flash always open
mt9p111: change the way to cature image with other resolutions except 2592*1944

drivers/media/video/mt9p111.c
drivers/media/video/mt9p111.h

index 579004414ecfac1700569129ff9e930d0ccd7f48..36ec7ae1e268ddd8c7a8cbfdbe383f6b94fe8939 100755 (executable)
@@ -59,6 +59,9 @@ module_param(debug, int, S_IRUGO|S_IWUSR);
 #define SENSOR_INIT_HEIGHT  480
 #define SENSOR_INIT_WINSEQADR sensor_vga
 #define SENSOR_INIT_PIXFMT V4L2_PIX_FMT_UYVY
+#define YUV420_BUFFER_MAX_SIZE  7558272     /* 2592*1944*1.5*/ 
+
+
 
 #define CONFIG_SENSOR_WhiteBalance     1
 #define CONFIG_SENSOR_Brightness       0
@@ -112,13 +115,25 @@ module_param(debug, int, S_IRUGO|S_IWUSR);
 static struct reginfo sensor_init_data[] =
 {
 //[Step2-PLL_Timing]
-//for 24MHz input, VCO=MAX PCLK=76.8MHz
+//for 24MHz input, VCO=MAX=768mhz  
 { 0x0010, 0x0340, WORD_LEN, 0},
-{ 0x0012, 0x0090, WORD_LEN, 0},
+
+/*sovle problem that lack of pclk during one href*/
+#if  ADJUST_PCLK_FRE_FALG
+{ 0x0012, 0x0080, WORD_LEN, 0},     //PCLK=85MHz
+#else
+{ 0x0012, 0x0090, WORD_LEN, 0},     //PCLK=76MHz
+#endif
+
 { 0x0014, 0x2025, WORD_LEN, 0},
-{ 0x001E, 0x0565, WORD_LEN, 0},        // PAD_SLEW_PAD_CONFIG
-{ 0x0022, 0x0030, WORD_LEN, 0},   //0x01E0     // VDD_DIS_COUNTER
-{ 0x002A, 0x7F7E, WORD_LEN, 0},   //0x7F7F     // PLL_P4_P5_P6_DIVIDERS By Hwang 20101104
+{ 0x001E, 0x0565, WORD_LEN, 0},    // PAD_SLEW_PAD_CONFIG
+{ 0x0022, 0x0030, WORD_LEN, 0},   //0x01E0// VDD_DIS_COUNTER
+
+#if   ADJUST_PCLK_FRE_FALG
+{ 0x002A, 0x7FFF, WORD_LEN, 0},  
+#else
+{ 0x002A, 0x7F7E, WORD_LEN, 0},   //0x7F7F// PLL_P4_P5_P6_DIVIDERS By Hwang 20101104
+#endif
 { 0x002C, 0x0000, WORD_LEN, 0},        // PLL_P7_DIVIDER
 { 0x002E, 0x0000, WORD_LEN, 0},        // SENSOR_CLOCK_DIVIDER
 { 0x0018, 0x4008, WORD_LEN, 0},        // STANDBY_CONTROL_AND_STATUS
@@ -166,8 +181,10 @@ static struct reginfo sensor_init_data[] =
 { 0xC858, 0x0003, WORD_LEN, 0},        // CAM_CORE_A_COARSE_ITMIN
 { 0xC8B8, 0x0004, WORD_LEN, 0},        // CAM_OUTPUT_0_JPEG_CONTROL
 { 0xC8AE, 0x0001, WORD_LEN, 0},        // CAM_OUTPUT_0_OUTPUT_FORMAT
+
 { 0xC8AA, 0x0280, WORD_LEN, 0},        // CAM_OUTPUT_0_IMAGE_WIDTH
 { 0xC8AC, 0x01E0, WORD_LEN, 0},        // CAM_OUTPUT_0_IMAGE_HEIGHT
+
 { 0xC872, 0x0010, WORD_LEN, 0},        // CAM_CORE_B_Y_ADDR_START
 { 0xC874, 0x001C, WORD_LEN, 0},        // CAM_CORE_B_X_ADDR_START
 { 0xC876, 0x07AF, WORD_LEN, 0},        // CAM_CORE_B_Y_ADDR_END
@@ -1360,7 +1377,6 @@ static struct reginfo sensor_init_data[] =
 };
 
 /* 720p 15fps @ 1280x720 */
-
 static struct reginfo sensor_720p[]=
 {
        //{SEQUENCE_END, 0x00},
@@ -1393,39 +1409,92 @@ static struct reginfo sensor_720p[]=
 };
 
 /*     1080p, 0x15fps, 0xyuv @1920x1080 */
-
 static struct reginfo sensor_1080p[]=
 {
        {SEQUENCE_END, 0x00}
 };
 
 /* 2592X1944 QSXGA */
+#if  ADJUST_FOR_CAPTURE_FALG
+static struct reginfo sensor_qsxga[] =
+{
+    {0x098E, 0x48C0,WORD_LEN,0},    // LOGICAL_ADDRESS_ACCESS [CAM_OUTPUT_1_IMAGE_WIDTH]
+    {0xC8C0, 0x0A20,WORD_LEN,0},    // CAM_OUTPUT_1_IMAGE_WIDTH
+    {0xC8C2, 0x0798,WORD_LEN,0},    // CAM_OUTPUT_1_IMAGE_HEIGHT
+    {0x8404, 0x06 ,BYTE_LEN,0},      // SEQ_CMD
+    {SEQUENCE_WAIT_MS,100,WORD_LEN,0},
+       {SEQUENCE_END, 0x00}
+};
+#else
 static struct reginfo sensor_qsxga[] =
 {
        {SEQUENCE_PROPERTY,SEQUENCE_CAPTURE},
        {SEQUENCE_END, 0x00}
 };
+#endif
+
 /* 2048*1536 QXGA */
+#if ADJUST_FOR_CAPTURE_FALG
+// send extra two lines to forbid to be captured error
 static struct reginfo sensor_qxga[] =
 {
+    {0x098E, 0x48C0,WORD_LEN,0},    // LOGICAL_ADDRESS_ACCESS [CAM_OUTPUT_1_IMAGE_WIDTH]
+    {0xC8C0, 0x0800,WORD_LEN,0},    // CAM_OUTPUT_1_IMAGE_WIDTH
+    {0xC8C2, 0x0602,WORD_LEN,0},    // CAM_OUTPUT_1_IMAGE_HEIGHT
+    {0x8404, 0x06 ,BYTE_LEN,0},      // SEQ_CMD
+    {SEQUENCE_WAIT_MS,100,WORD_LEN,0},
        {SEQUENCE_END, 0x00}
 };
+#else
+static struct reginfo sensor_qxga[] =
+{
+       {SEQUENCE_END, 0x00}
+};
+#endif
 
 /* 1600X1200 UXGA */
+#if ADJUST_FOR_CAPTURE_FALG
+static struct reginfo sensor_uxga[] =
+{
+    {0x098E, 0x48C0,WORD_LEN,0},    // LOGICAL_ADDRESS_ACCESS [CAM_OUTPUT_1_IMAGE_WIDTH]
+    {0xC8C0, 0x0640,WORD_LEN,0},    // CAM_OUTPUT_1_IMAGE_WIDTH
+    {0xC8C2, 0x04b2,WORD_LEN,0},    // CAM_OUTPUT_1_IMAGE_HEIGHT
+    {0x8404, 0x06 ,BYTE_LEN,0},      // SEQ_CMD
+    {SEQUENCE_WAIT_MS,100,WORD_LEN,0},
+       {SEQUENCE_END, 0x00}
+};
+#else
 static struct reginfo sensor_uxga[] =
 {
        {SEQUENCE_END, 0x00}
 };
+
+#endif
+
 /* 1280X1024 SXGA */
 static struct reginfo sensor_sxga[] =
 {
        {SEQUENCE_END, 0x00}
 };
+
 /*  1024X768 XGA */
+#if ADJUST_FOR_CAPTURE_FALG
 static struct reginfo sensor_xga[] =
 {
+    {0x098E, 0x48C0,WORD_LEN,0},    // LOGICAL_ADDRESS_ACCESS [CAM_OUTPUT_1_IMAGE_WIDTH]
+    {0xC8C0, 0x0403,WORD_LEN,0},    // CAM_OUTPUT_1_IMAGE_WIDTH
+    {0xC8C2, 0x0302,WORD_LEN,0},    // CAM_OUTPUT_1_IMAGE_HEIGHT
+    {0x8404, 0x06 ,BYTE_LEN,0},      // SEQ_CMD
+    {SEQUENCE_WAIT_MS,100,WORD_LEN,0},
        {SEQUENCE_END, 0x00}
 };
+#else
+static struct reginfo sensor_xga[] =
+{
+       {SEQUENCE_END, 0x00}
+};
+#endif
+
 
 /* 800X600 SVGA*/
 static struct reginfo sensor_svga[] =
@@ -1445,7 +1514,7 @@ static struct reginfo sensor_vga[] =
     {0xC86A, 0x1194, WORD_LEN, 0},    // CAM_CORE_A_LINE_LENGTH_PCK
     {0xC86C, 0x0518, WORD_LEN, 0},    // CAM_CORE_A_OUTPUT_SIZE_WIDTH
     {0xC86E, 0x03D4, WORD_LEN, 0},    // CAM_CORE_A_OUTPUT_SIZE_HEIGHT
-    {0xC870, 0x0014, WORD_LEN, 0},  // CAM_CORE_A_RX_FIFO_TRIGGER_MARK
+    {0xC870, 0x0014, WORD_LEN, 0},    // CAM_CORE_A_RX_FIFO_TRIGGER_MARK
     {0xC858, 0x0003, WORD_LEN, 0},  // CAM_CORE_A_COARSE_ITMIN
     {0xC8A4, 0x0A28, WORD_LEN, 0},    // CAM_CORE_B_OUTPUT_SIZE_WIDTH
     {0xC8A6, 0x07A0, WORD_LEN, 0 },    // CAM_CORE_B_OUTPUT_SIZE_HEIGHT
@@ -1474,90 +1543,7 @@ static struct reginfo sensor_qcif[] =
 {
        {SEQUENCE_END, 0x00}
 };
-#if 0
-/* 160X120 QQVGA*/
-static struct reginfo ov2655_qqvga[] =
-{
-
-    {0x300E, 0x34},
-    {0x3011, 0x01},
-    {0x3012, 0x10},
-    {0x302a, 0x02},
-    {0x302b, 0xE6},
-    {0x306f, 0x14},
-    {0x3362, 0x90},
-
-    {0x3070, 0x5d},
-    {0x3072, 0x5d},
-    {0x301c, 0x07},
-    {0x301d, 0x07},
-
-    {0x3020, 0x01},
-    {0x3021, 0x18},
-    {0x3022, 0x00},
-    {0x3023, 0x06},
-    {0x3024, 0x06},
-    {0x3025, 0x58},
-    {0x3026, 0x02},
-    {0x3027, 0x61},
-    {0x3088, 0x00},
-    {0x3089, 0xa0},
-    {0x308a, 0x00},
-    {0x308b, 0x78},
-    {0x3316, 0x64},
-    {0x3317, 0x25},
-    {0x3318, 0x80},
-    {0x3319, 0x08},
-    {0x331a, 0x0a},
-    {0x331b, 0x07},
-    {0x331c, 0x80},
-    {0x331d, 0x38},
-    {0x3100, 0x00},
-    {0x3302, 0x11},
-
-    {0x0, 0x0},
-};
-
-
-
-static  struct reginfo ov2655_Sharpness_auto[] =
-{
-    {0x3306, 0x00},
-};
-
-static  struct reginfo ov2655_Sharpness1[] =
-{
-    {0x3306, 0x08},
-    {0x3371, 0x00},
-};
-
-static  struct reginfo ov2655_Sharpness2[][3] =
-{
-    //Sharpness 2
-    {0x3306, 0x08},
-    {0x3371, 0x01},
-};
-
-static  struct reginfo ov2655_Sharpness3[] =
-{
-    //default
-    {0x3306, 0x08},
-    {0x332d, 0x02},
-};
-static  struct reginfo ov2655_Sharpness4[]=
-{
-    //Sharpness 4
-    {0x3306, 0x08},
-    {0x332d, 0x03},
-};
 
-static  struct reginfo ov2655_Sharpness5[] =
-{
-    //Sharpness 5
-    {0x3306, 0x08},
-    {0x332d, 0x04},
-};
-#endif
 static  struct reginfo sensor_Preview2Capture[]=
 {
        //capture2preview
@@ -1903,6 +1889,7 @@ static  struct reginfo sensor_FlipOff[]=
 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
 
 #endif
+
 #if CONFIG_SENSOR_Scene
 static  struct reginfo sensor_SceneAuto[] =
 {
@@ -1916,6 +1903,7 @@ static  struct reginfo sensor_SceneNight[] =
 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
 
 #endif
+
 #if CONFIG_SENSOR_DigitalZoom
 static struct reginfo sensor_Zoom0[] =
 {
@@ -2904,13 +2892,12 @@ static struct reginfo* sensor_fmt_catch(int set_w, int set_h, int *ret_w, int *r
        } 
 
 #if  ADJUST_FOR_VGA_FALG    
-
-        if (((set_w >= 640) && (set_h >= 480)) && (sensor_vga[0].reg!=SEQUENCE_END)) {
+        // to forbid preview err         
+        if (((set_w >= 576) && (set_h >= 432)) && (sensor_vga[0].reg!=SEQUENCE_END)) {
             winseqe_set_addr = sensor_vga;
             *ret_w = 576;
             *ret_h = 432;
         } 
-
 #else
         if (((set_w >= 640) && (set_h >= 480)) && (sensor_vga[0].reg!=SEQUENCE_END)) {
             winseqe_set_addr = sensor_vga;
@@ -2919,74 +2906,42 @@ static struct reginfo* sensor_fmt_catch(int set_w, int set_h, int *ret_w, int *r
         } 
 
 #endif
-       
-        
+              
         if (((set_w >= 800) && (set_h >= 600)) && (sensor_svga[0].reg!=SEQUENCE_END)) {
             winseqe_set_addr = sensor_svga;
             *ret_w = 800;
             *ret_h = 600;
         } 
 
-#if ADJUST_FOR_CAPTURE_FALG
-        if (((set_w >= 1024) && (set_h >= 768)) && (sensor_qsxga[0].reg!=SEQUENCE_END)) {
-            winseqe_set_addr = sensor_qsxga;
-            *ret_w = 2560;
-            *ret_h = 1920;
-       } 
-#else
         if (((set_w >= 1024) && (set_h >= 768)) && (sensor_xga[0].reg!=SEQUENCE_END)) {
             winseqe_set_addr = sensor_xga;
             *ret_w = 1024;
             *ret_h = 768;
        } 
-#endif       
+      
         if (((set_w >= 1280) && (set_h >= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END)) {
             winseqe_set_addr = sensor_sxga;
             *ret_w = 1280;
             *ret_h = 1024;
-        } 
-        
-#if ADJUST_FOR_CAPTURE_FALG
-        if (((set_w >= 1600) && (set_h >= 1200)) && (sensor_qsxga[0].reg!=SEQUENCE_END)) {
-            winseqe_set_addr = sensor_qsxga;
-            *ret_w = 2560;
-            *ret_h = 1920;
-       } 
-#else
+        }         
+
         if (((set_w >= 1600) && (set_h >= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END)) {
             winseqe_set_addr = sensor_uxga;
             *ret_w = 1600;
             *ret_h = 1200;
        } 
-#endif
 
-#if ADJUST_FOR_CAPTURE_FALG
-        if (((set_w >= 2048) && (set_h >= 1536)) && (sensor_qsxga[0].reg!=SEQUENCE_END)) {
-            winseqe_set_addr = sensor_qsxga;
-            *ret_w = 2560;
-            *ret_h = 1920;
-        } 
-#else
         if (((set_w >= 2048) && (set_h >= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END)) {
             winseqe_set_addr = sensor_qxga;
             *ret_w = 2048;
             *ret_h = 1536;
         } 
-#endif
 
-#if  ADJUST_FOR_CAPTURE_FALG
-        if (((set_w >= 2560) && (set_h >= 1920)) && (sensor_qsxga[0].reg!=SEQUENCE_END)) {
-            winseqe_set_addr = sensor_qsxga;
-            *ret_w = 2560;
-            *ret_h = 1920;
-        }
-#else
         if (((set_w >= 2592) && (set_h >= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END)) {
             winseqe_set_addr = sensor_qsxga;
             *ret_w = 2592;
             *ret_h = 1944;
         }
-#endif
 
         if (winseqe_set_addr == NULL) {
             if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END)) {
@@ -3179,6 +3134,45 @@ static struct reginfo* sensor_fmt_catch(int set_w, int set_h, int *ret_w, int *r
        return winseqe_set_addr;
 }
 
+/*modify image with resolution 2592*1944;solve bug that the first 32 pixel data*/
+/*in the first line have misplace with the last 32 pixel data in the last line*/
+static int sensor_cb(struct videobuf_buffer  *vb)
+{
+  // struct videobuf_buffer *
+   struct videobuf_buffer *buffer = vb;
+   char *imagey_addr =NULL;
+   char *imageuv_addr = NULL;
+   char *tempaddr = NULL;
+   int  tempsize = 0;
+
+   if(buffer->width!=SENSOR_MAX_WIDTH||buffer->height!=SENSOR_MAX_HEIGHT||buffer==NULL)
+    return -1;
+   if (buffer->bsize< YUV420_BUFFER_MAX_SIZE)        //yuv420 format size
+    return -1;
+
+   imagey_addr = (char*)buffer->boff;         // y data  to be dealed with
+   imageuv_addr = imagey_addr+buffer->width*buffer->height;
+   SENSOR_DG("\n%s..%s..imagey_addr = 0x%x; imageuv_addr = 0x%x\n",__FUNCTION__,SENSOR_NAME_STRING(),imagey_addr,imageuv_addr);
+   SENSOR_DG("\n%s..%s..buffer->bsize=%d\n",__FUNCTION__,SENSOR_NAME_STRING());
+
+   tempaddr =  imageuv_addr - 32;  
+   memcpy(tempaddr,imagey_addr,32);
+
+   tempaddr = imagey_addr+32;
+   memcpy(imagey_addr,tempaddr,32);
+
+                                      //uv data to be dealed with
+   tempsize  = YUV420_BUFFER_MAX_SIZE-32;                              
+   tempaddr = imagey_addr+tempsize;
+   memcpy(tempaddr,imageuv_addr,32);
+
+   tempaddr = imageuv_addr+32;
+   memcpy(imageuv_addr,tempaddr,32);
+   return 0;
+}
+
+
 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
 {
     struct i2c_client *client = sd->priv;
@@ -3188,6 +3182,8 @@ static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
     struct reginfo *winseqe_set_addr=NULL;
     int ret = 0, set_w,set_h,cnt;
     u16 seq_state=0;
+    int time = 0;
+    u16 targetbrightness,realbrightness;
     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
 
        if (sensor->info_priv.pixfmt != pix->pixelformat) {
@@ -3221,14 +3217,30 @@ static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
 
        winseqe_set_addr = sensor_fmt_catch(set_w, set_h, &set_w, &set_h);
 
-    if ((winseqe_set_addr  != sensor->info_priv.winseqe_cur_addr) && winseqe_set_addr) {
-        ret |= sensor_write_array(client, winseqe_set_addr);
-        if (ret != 0) {
-            SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
-            goto sensor_s_fmt_end;
+    if ((winseqe_set_addr  != sensor->info_priv.winseqe_cur_addr) && winseqe_set_addr)
+    { 
+       /*solve bug that video set is ineffective */
+       /*set five times to make sure sensor_720p set go into effect*/
+        if(winseqe_set_addr==sensor_720p)
+        {
+          time = 5;
+        }else{
+          time = 1;
+        }
+        
+        while(time > 0)
+        {
+           time--;
+           ret |= sensor_write_array(client, winseqe_set_addr);
+           if (ret != 0) {
+                SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
+                goto sensor_s_fmt_end;
+           }
+           udelay(10);
         }
         sensor->info_priv.winseqe_cur_addr  = winseqe_set_addr;
-               if ((winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
+               if (winseqe_set_addr==sensor_qxga ||winseqe_set_addr==sensor_qsxga||winseqe_set_addr==sensor_uxga ||winseqe_set_addr==sensor_xga)
+        {
                SENSOR_DG("\n%s..%s..Capture icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
                } else {
                        SENSOR_DG("\n%s..%s..Video icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
@@ -3237,31 +3249,66 @@ static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
                }
     }
 
-       if (winseqe_set_addr && (winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
-               ret |= sensor_write_array(client, sensor_Preview2Capture);
+       if (winseqe_set_addr && (winseqe_set_addr==sensor_qxga ||winseqe_set_addr==sensor_qsxga||winseqe_set_addr==sensor_uxga ||winseqe_set_addr==sensor_xga)) 
+     {
+               ret |= sensor_write_array(client, sensor_Preview2Capture);      
                if (ret != 0) {
                SENSOR_TR("%s Preview 2 Capture failed\n", SENSOR_NAME_STRING());
                goto sensor_s_fmt_end;
        }
+
+      /*check state of register 0x8405 to make sure set is successful*/
+      /*set sensor_Preview2Capture more times to make sure set go into effect */
         cnt = 0;
-        do{                                //check state of register 0x8405 to make sure set is successful
+        time  =0;
+        do{                      
             ret =  0;
             msleep(50);   
             ret =sensor_read(client,0x8405, &seq_state);
             if (ret < 0)
               goto sensor_s_fmt_end;
             cnt++;
-            SENSOR_DG("mt9p111 Preview 2 Capture seq_state = 0x%x\n",seq_state);
-         } while((seq_state != 0x07) && (cnt < 20));
-        
-         SENSOR_TR("%s Preview 2 Capture failed\n", SENSOR_NAME_STRING());
-
-        #if CONFIG_SENSOR_Flash
-        if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
+            if(cnt > 9)
+            {
+                time++;
+                cnt = 0;
+                       ret |= sensor_write_array(client, sensor_Preview2Capture);      
+                       if (ret != 0||time >2) {
+                       SENSOR_TR("%s Preview 2 Capture failed\n", SENSOR_NAME_STRING());
+                       goto sensor_s_fmt_end;
+               }
+               // SENSOR_DG("mt9p111 Preview 2 Capture again\n",cnt,seq_state);
+            }
+           // SENSOR_DG("mt9p111 Preview 2 Capture count = %d;seq_state = 0x%x\n",cnt,seq_state);
+         } while((seq_state != 0x07) && (time < 3));
+
+      #if CONFIG_SENSOR_Flash
+       /*The 0xA409 is AE target register address.*/
+       /*The 0xB804 is currently total brightness Y value of sensor.*/
+       targetbrightness = 0;
+       realbrightness =0;
+       if((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2))
+       {
+          if(sensor->info_priv.flash == 1)
+          {
+            ret =sensor_read(client,0xA409, &targetbrightness);
+            if (ret < 0)
+              SENSOR_DG("%s ..%s..get targetbrightness fail\n", SENSOR_NAME_STRING(),__FUNCTION__);
+            
+            ret =sensor_read(client, 0xB804, &realbrightness);
+            if (ret < 0)
+              SENSOR_DG("%s ..%s..get realbrightness fail\n", SENSOR_NAME_STRING(),__FUNCTION__);
+          }
+         
+          if((realbrightness < targetbrightness)|| (sensor->info_priv.flash == 2))
+          {
             sensor_ioctrl(icd, Sensor_Flash, Flash_On);
-            SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
+            SENSOR_DG("%s flash on,realbrightness=%d,targetbrightness=%d\n", SENSOR_NAME_STRING(),realbrightness,targetbrightness);
+          }else{
+            SENSOR_DG("%s not need to flash in capture!\n", SENSOR_NAME_STRING());
+          }
         }
-        #endif        
+      #endif        
                sensor->info_priv.capture_w = set_w;
                sensor->info_priv.capture_h = set_h;
                sensor->info_priv.snap2preview = true;
@@ -3379,17 +3426,27 @@ static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l
 #if CONFIG_SENSOR_Effect
 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
 {
+    int time =5;
+    int ret =0 ;
     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
 
     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
     {
         if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
         {
-            if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
+           /*set five times to make sure the set go into effect*/
+           /*solve bug for setting invalidate during changing from preview to video*/
+            while(time >0)
             {
-                SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
-                return -EINVAL;
-            }
+                time--;
+                ret |=sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]);
+                if(ret != 0)
+                {  
+                    SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
+                    return -EINVAL;
+                }
+                msleep(50);   
+            }       
             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
             return 0;
         }
@@ -3797,6 +3854,7 @@ static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
     struct sensor *sensor = to_sensor(client);
     struct soc_camera_device *icd = client->dev.platform_data;
     const struct v4l2_queryctrl *qctrl;
+    
     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
 
 
@@ -3915,6 +3973,7 @@ static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_
     const struct v4l2_queryctrl *qctrl;
     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
     struct sensor *sensor = to_sensor(client);
+    
     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
 
     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
@@ -4242,11 +4301,6 @@ sensor_video_probe_err:
 
     return ret;
 }
-static int sensor_cb(struct videobuf_buffer *vb)
-{
-
-    return 0;
-}
 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
 {
        struct i2c_client *client = sd->priv;
@@ -4254,6 +4308,8 @@ static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
     struct sensor *sensor = to_sensor(client);
     int ret = 0;
     
+    rk29_camera_sensor_cb_s *icd_cb =NULL;
+    
        SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
        switch (cmd)
        {
@@ -4298,9 +4354,9 @@ static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
                }
         case RK29_CAM_SUBDEV_CB_REGISTER:
         {
-            icd_cb = (rk29_camera_sensor_cb_s*)arg;
-            icd_cb->sensor_cb = sensor_cb;
-            break;    
+           icd_cb = (rk29_camera_sensor_cb_s*)(arg);
+           //icd_cb->sensor_cb = sensor_cb;
+           break;    
         }
                default:
                {
index 536fabb3e62439d70378035d7b416ee92d51c4c2..0cd4b17968663f6ac962de061d2750fae1874ba1 100755 (executable)
@@ -40,4 +40,5 @@ struct reginfo
 #define ADJUST_FOR_720P_FALG      1
 #define ADJUST_FOR_VGA_FALG       1
 #define ADJUST_FOR_CAPTURE_FALG   1
+#define ADJUST_PCLK_FRE_FALG      1
 #endif