ARM64: DTS: Add rk3399-firefly uart4 device, node as /dev/ttyS1
[firefly-linux-kernel-4.4.55.git] / drivers / media / video / hi704.c
index 5cd8e844a2e7545ff0f1be194a8216c9d59060d1..d12c5eeec1b50bb5a78b47bc47a976a9f58d7a5c 100755 (executable)
@@ -19,7 +19,7 @@ o* Driver for MT9M001 CMOS Image Sensor from Micron
 #include <media/v4l2-common.h>
 #include <media/v4l2-chip-ident.h>
 #include <media/soc_camera.h>
-#include <mach/rk29_camera.h>
+#include <plat/rk_camera.h>
 
 static int debug;
 module_param(debug, int, S_IRUGO|S_IWUSR);
@@ -101,6 +101,19 @@ struct reginfo
     u8 val;
 };
 
+//flash off in fixed time to prevent from too hot , zyc
+struct  flash_timer{
+    struct soc_camera_device *icd;
+       struct hrtimer timer;
+};
+#if CONFIG_SENSOR_Flash
+static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
+#endif
+static struct  flash_timer flash_off_timer;
+//for user defined if user want to customize the series , zyc
+#ifdef CONFIG_HI704_USER_DEFINED_SERIES
+#include "hi704_user_series.c"
+#else
 /* init SVGA preview */
 static struct reginfo sensor_init_data[] =
 {
@@ -111,7 +124,7 @@ static struct reginfo sensor_init_data[] =
 {0x01, 0xf3},   //PWRCTL(0x01[P0])Bit[1]:Software Reset.
 {0x01, 0xf1},
 {0x10, 0x00},//vga mode
-{0x11, 0x91},   //For No Fixed Framerate Bit[2]
+{0x11, 0x90},   //For No Fixed Framerate Bit[2]
 {0x12, 0x04},
     
 {0x20, 0x00},
@@ -138,13 +151,13 @@ static struct reginfo sensor_init_data[] =
 {0x85, 0x4b},
 {0x89, 0x48},
     
-{0x90, 0x0b},
-{0x91, 0x0b},    
-{0x92, 0x48},
-{0x93, 0x48},
+{0x90, 0x0c},
+{0x91, 0x0c},    
+{0x92, 0x78},
+{0x93, 0x70},
 {0x98, 0x38},
 {0x99, 0x40},
-{0xa0, 0x00},
+{0xa0, 0x40},
 {0xa8, 0x40},
 
 //PAGE 2
@@ -228,7 +241,7 @@ static struct reginfo sensor_init_data[] =
 {0x11, 0x43},
 {0x12, 0x30},
     
-{0x40, 0x10},//brightness +1
+{0x40, 0x00},//brightness +1
 {0x41, 0x02},
 {0x48, 0x98},//contrast level +1
     
@@ -367,7 +380,7 @@ static struct reginfo sensor_init_data[] =
 {0x39,0xbd},
 {0x3a,0xc8},
 {0x3b,0xd9},
-{0x3c,0xe8},
+{0x3c,0xe5},
 {0x3d,0xf5},
 {0x3e,0xff},
  //0930
@@ -437,7 +450,7 @@ static struct reginfo sensor_init_data[] =
 {0x6A, 0x28},
 {0x6B, 0xc8},
 
-{0x70, 0x42},//Y Target 42
+{0x70, 0x38},//Y Target 42
 
 {0x76, 0x22}, //Unlock bnd1
 {0x77, 0x02}, //Unlock bnd2 02->a2 _10_04_06 hhzin
@@ -495,12 +508,12 @@ static struct reginfo sensor_init_data[] =
 {0x99, 0x23},
 
 {0x9c, 0x0b}, //4shared limit_10_04_06 hhzin
-{0x9d, 0x3b}, // 0x06d3 --> 0x0b3b
+{0x9d, 0xb8}, // 0x06d3 --> 0x0b3b
 {0x9e, 0x00}, //4shared Unit_10_04_06 hhzin
 {0x9f, 0xfa}, // 0x01f4 --> 0xfa
 
 {0xb1, 0x14},
-{0xb2, 0x50},
+{0xb2, 0x30},
 {0xb4, 0x14},
 {0xb5, 0x38},
 {0xb6, 0x26},
@@ -589,10 +602,10 @@ static struct reginfo sensor_vga[] =
 {0x20, 0x00},
 {0x21, 0x04},
 
-{0x40, 0x00},        //HBLANK: 0x70 = 112
-{0x41, 0x70},
+{0x40, 0x01},        //HBLANK: 0x70 = 112
+{0x41, 0x58},
 {0x42, 0x00},        //VBLANK: 0x04 = 4
-{0x43, 0x40},
+{0x43, 0x64},
 
 {0x03, 0x11},
 {0x10, 0x25},  
@@ -600,19 +613,19 @@ static struct reginfo sensor_vga[] =
 {0x03, 0x20},
 {0x83, 0x00},
 {0x84, 0xaf},
-{0x85, 0x80},
+{0x85, 0xc8},
 {0x86, 0x00},
-{0x87, 0xc0},
+{0x87, 0xf0},
 
 {0x8b, 0x3a},
-{0x8c, 0x80},
+{0x8c, 0x98},
 {0x8d, 0x30},
-{0x8e, 0xc0},
+{0x8e, 0xd4},
 
-{0x9c, 0x08},
-{0x9d, 0xa0},
+{0x9c, 0x0b},
+{0x9d, 0xb8},
 {0x9e, 0x00},
-{0x9f, 0xc0},
+{0x9f, 0xfa},
 {END_REG, END_REG},
 };
 
@@ -634,7 +647,7 @@ static  struct reginfo sensor_qvga[] =
 {0x40, 0x01},        //HBLANK:  0x0158 = 344
 {0x41, 0x58},
 {0x42, 0x00},        //VBLANK:  0x14 = 20
-{0x43, 0x14},
+{0x43, 0x64},
 
 {0x03, 0x11},        //QVGA Fixframerate
 {0x10, 0x21},  
@@ -653,7 +666,7 @@ static  struct reginfo sensor_qvga[] =
 {0x8e, 0xd4},
 
 {0x9c, 0x0b},
-{0x9d, 0x3b},
+{0x9d, 0xb8},
 {0x9e, 0x00},
 {0x9f, 0xfa},
 {END_REG, END_REG},
@@ -665,7 +678,7 @@ static struct reginfo sensor_qcif[] =
        {END_REG, END_REG},
 };
 
-
+#endif
 static  struct reginfo sensor_ClrFmt_YUYV[]=
 {
 
@@ -972,8 +985,8 @@ static  struct reginfo sensor_Saturation1[]=
 {
                //00 level
        {0x03, 0x10},
-       {0x62, 0x90},
-       {0x63, 0x90},
+       {0x62, 0x80},
+       {0x63, 0x80},
        {END_REG, END_REG},
 };
 
@@ -1017,7 +1030,7 @@ static  struct reginfo sensor_Contrast3[]=
 {
     //Contrast 0
     {0x03, 0x10},
-    {0x48, 0x84},
+    {0x48, 0x80},
        {END_REG, END_REG},
 };
 
@@ -1115,7 +1128,7 @@ static struct reginfo sensor_Zoom3[] =
 };
 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
 #endif
-static const struct v4l2_querymenu sensor_menus[] =
+static  struct v4l2_querymenu sensor_menus[] =
 {
        #if CONFIG_SENSOR_WhiteBalance
     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 0,  .name = "auto",  .reserved = 0, }, {  .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 1, .name = "incandescent",  .reserved = 0,},
@@ -1139,7 +1152,7 @@ static const struct v4l2_querymenu sensor_menus[] =
     #endif
 };
 
-static const struct v4l2_queryctrl sensor_controls[] =
+static  struct v4l2_queryctrl sensor_controls[] =
 {
        #if CONFIG_SENSOR_WhiteBalance
     {
@@ -1621,6 +1634,11 @@ static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd
 
                        if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
                                sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
+                if(on){
+                    //flash off after 2 secs
+                       hrtimer_cancel(&(flash_off_timer.timer));
+                       hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
+                    }
                        }
             break;
                }
@@ -1633,9 +1651,18 @@ static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd
 sensor_power_end:
        return ret;
 }
+#if CONFIG_SENSOR_Flash
+static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
+       struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
+    sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
+       SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
+    return 0;
+    
+}
+#endif
 static int sensor_init(struct v4l2_subdev *sd, u32 val)
 {
-    struct i2c_client *client = sd->priv;
+    struct i2c_client *client = v4l2_get_subdevdata(sd);
     struct soc_camera_device *icd = client->dev.platform_data;
     struct sensor *sensor = to_sensor(client);
        const struct v4l2_queryctrl *qctrl;
@@ -1742,6 +1769,8 @@ static int sensor_init(struct v4l2_subdev *sd, u32 val)
        qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
        if (qctrl)
         sensor->info_priv.flash = qctrl->default_value;
+    flash_off_timer.icd = icd;
+       flash_off_timer.timer.function = flash_off_func;
     #endif
 
     SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),((val == 0)?__FUNCTION__:"sensor_reinit"),icd->user_width,icd->user_height);
@@ -1833,7 +1862,7 @@ static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
 
 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
 {
-    struct i2c_client *client = sd->priv;
+    struct i2c_client *client = v4l2_get_subdevdata(sd);
     struct soc_camera_device *icd = client->dev.platform_data;
     struct sensor *sensor = to_sensor(client);
 
@@ -1882,7 +1911,7 @@ static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefm
 }
 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
 {
-    struct i2c_client *client = sd->priv;
+    struct i2c_client *client = v4l2_get_subdevdata(sd);
     struct sensor *sensor = to_sensor(client);
     const struct sensor_datafmt *fmt;
        const struct v4l2_queryctrl *qctrl;
@@ -2040,7 +2069,7 @@ sensor_s_fmt_end:
 
 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
 {
-    struct i2c_client *client = sd->priv;
+    struct i2c_client *client = v4l2_get_subdevdata(sd);
     struct sensor *sensor = to_sensor(client);
     const struct sensor_datafmt *fmt;
     int ret = 0;
@@ -2069,7 +2098,7 @@ static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
 
  static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
 {
-    struct i2c_client *client = sd->priv;
+    struct i2c_client *client = v4l2_get_subdevdata(sd);
 
     if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
         return -EINVAL;
@@ -2353,7 +2382,7 @@ static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_que
 
 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
 {
-    struct i2c_client *client = sd->priv;
+    struct i2c_client *client = v4l2_get_subdevdata(sd);
     struct sensor *sensor = to_sensor(client);
     const struct v4l2_queryctrl *qctrl;
 
@@ -2412,7 +2441,7 @@ static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
 
 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
 {
-    struct i2c_client *client = sd->priv;
+    struct i2c_client *client = v4l2_get_subdevdata(sd);
     struct sensor *sensor = to_sensor(client);
     struct soc_camera_device *icd = client->dev.platform_data;
     const struct v4l2_queryctrl *qctrl;
@@ -2702,7 +2731,7 @@ static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_c
 
 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
 {
-    struct i2c_client *client = sd->priv;
+    struct i2c_client *client = v4l2_get_subdevdata(sd);
     struct soc_camera_device *icd = client->dev.platform_data;
     int i, error_cnt=0, error_idx=-1;
 
@@ -2727,7 +2756,7 @@ static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_control
 
 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
 {
-    struct i2c_client *client = sd->priv;
+    struct i2c_client *client = v4l2_get_subdevdata(sd);
     struct soc_camera_device *icd = client->dev.platform_data;
     int i, error_cnt=0, error_idx=-1;
 
@@ -2805,7 +2834,7 @@ sensor_video_probe_err:
 }
 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
 {
-       struct i2c_client *client = sd->priv;
+       struct i2c_client *client = v4l2_get_subdevdata(sd);
     struct soc_camera_device *icd = client->dev.platform_data;
     struct sensor *sensor = to_sensor(client);
     int ret = 0;
@@ -2845,11 +2874,18 @@ static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
                 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
                     for (i = 0; i < icd->ops->num_controls; i++) {
                                if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
-                                       memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));                                       
+                                       //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));  
+                              sensor_controls[i].id=0xffff;                            
                                }
                     }
                     sensor->info_priv.flash = 0xff;
                     SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
+                }else{ //two cameras are the same,need to deal diffrently ,zyc
+                    for (i = 0; i < icd->ops->num_controls; i++) {
+                           if(0xffff == icd->ops->controls[i].id){
+                              sensor_controls[i].id=V4L2_CID_FLASH;
+                           }               
+                    }
                 }
                }
             #endif
@@ -2943,6 +2979,7 @@ static int sensor_probe(struct i2c_client *client,
         kfree(sensor);
                sensor = NULL;
     }
+       hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
     SENSOR_DG("\n%s..%s..%d  ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
     return ret;
 }