[PORT FROM R2] atomisp: make delay in focus_status function variable
authorRobert Jong-A-Lock <robert.jong-a-lock@intel.com>
Tue, 1 Nov 2011 13:58:43 +0000 (14:58 +0100)
committerbuildbot <buildbot@intel.com>
Mon, 19 Dec 2011 13:27:42 +0000 (05:27 -0800)
BZ: 17272

this change assumes that one step needs 1ms of delay.The ammount
of steps changed times 1ms, maximised to 40ms, is then used to
wait before the focus_status function returns
ATOMISP_FOCUS_HP_COMPLETE again. This way the delay is no longer
fixed to 60ms after each call to t_focus.

Change-Id: Ie8ce0ecffff8933d1b91341741f6ff7e934a2a1d
Orig-Change-Id: Ia0419de7d14418dc63da8b1ab61988e36edaffa2
Reviewed-on: http://android.intel.com:8080/22864
Reviewed-by: Jong-a-lock, Robert <robert.jong-a-lock@intel.com>
Reviewed-by: Koski, Anttu <anttu.koski@intel.com>
Tested-by: Koski, Anttu <anttu.koski@intel.com>
Reviewed-by: Wang, Wen W <wen.w.wang@intel.com>
Reviewed-by: Samurov, Vitali <vitali.samurov@intel.com>
Reviewed-by: Cohen, David A <david.a.cohen@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
Reviewed-on: http://android.intel.com:8080/27991
Reviewed-by: Tuominen, TeemuX <teemux.tuominen@intel.com>
drivers/media/video/mt9e013.c
drivers/media/video/mt9e013.h

index e9c4a06..3d8cf29 100644 (file)
@@ -523,7 +523,6 @@ static int mt9e013_write_reg_array(struct i2c_client *client,
        return __mt9e013_flush_reg_array(client, &ctrl);
 }
 
-
 static int mt9e013_t_focus_abs(struct v4l2_subdev *sd, s32 value)
 {
        struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -535,75 +534,62 @@ static int mt9e013_t_focus_abs(struct v4l2_subdev *sd, s32 value)
        ret = mt9e013_write_reg(client, MT9E013_16BIT, MT9E013_VCM_CODE,
                                MT9E013_MAX_FOCUS_POS - value);
        if (ret == 0) {
+               dev->number_of_steps = value - dev->focus;
                dev->focus = value;
-               do_gettimeofday(&(dev->timestamp_t_focus_abs));
+               getnstimeofday(&(dev->timestamp_t_focus_abs));
        }
        return ret;
 }
 
-static int mt9e013_q_focus_abs(struct v4l2_subdev *sd, s32 *value)
-{
-       struct i2c_client *client = v4l2_get_subdevdata(sd);
-       int ret;
-       u16 val;
-
-
-
-       ret = mt9e013_read_reg(client, MT9E013_16BIT,
-                              MT9E013_VCM_CODE, &val);
-       *value = MT9E013_MAX_FOCUS_POS - val;
-
-       return ret;
-}
-
 static int mt9e013_t_focus_rel(struct v4l2_subdev *sd, s32 value)
 {
        struct mt9e013_device *dev = to_mt9e013_sensor(sd);
        return mt9e013_t_focus_abs(sd, dev->focus + value);
 }
 
-#define WAIT_FOR_VCM_MOTOR     60000
+#define DELAY_PER_STEP_NS      1000000
+#define DELAY_MAX_PER_STEP_NS  (1000000*40)
 static int mt9e013_q_focus_status(struct v4l2_subdev *sd, s32 *value)
 {
        u32 status = 0;
        struct mt9e013_device *dev = to_mt9e013_sensor(sd);
-       struct timeval current_time;
-       bool stillmoving = false;
-       struct i2c_client *client = v4l2_get_subdevdata(sd);
+       struct timespec temptime;
+       const struct timespec timedelay = {
+               0,
+               min((u32)abs(dev->number_of_steps)*DELAY_PER_STEP_NS,
+                       (u32)DELAY_MAX_PER_STEP_NS),
+       };
 
+       getnstimeofday(&temptime);
 
-       do_gettimeofday(&current_time);
-       if (current_time.tv_sec == (dev->timestamp_t_focus_abs).tv_sec) {
-               if (current_time.tv_usec < ((dev->timestamp_t_focus_abs).tv_usec+WAIT_FOR_VCM_MOTOR)) {
-                       stillmoving = true;
-               }
-       } else {
-               if ((current_time.tv_usec+1000000) < ((dev->timestamp_t_focus_abs).tv_usec+WAIT_FOR_VCM_MOTOR)) {
-                       /* assuming the delay betwee calls does not take more than a second. */
-                       stillmoving = true;
-               }
-       }
+       temptime = timespec_sub(temptime, (dev->timestamp_t_focus_abs));
 
-       if (stillmoving) {
+       if (timespec_compare(&temptime, &timedelay) <= 0) {
                status |= ATOMISP_FOCUS_STATUS_MOVING;
                status |= ATOMISP_FOCUS_HP_IN_PROGRESS;
        } else {
-               status |= ATOMISP_FOCUS_HP_COMPLETE;
                status |= ATOMISP_FOCUS_STATUS_ACCEPTS_NEW_MOVE;
+               status |= ATOMISP_FOCUS_HP_COMPLETE;
        }
        *value = status;
        return 0;
 }
 
-/*
-static int mt9e013_vcm_enable(struct v4l2_subdev *sd)
+static int mt9e013_q_focus_abs(struct v4l2_subdev *sd, s32 *value)
 {
-       struct i2c_client *client = v4l2_get_subdevdata(sd);
+       struct mt9e013_device *dev = to_mt9e013_sensor(sd);
+       s32 val;
 
-       return mt9e013_rmw_reg(client, MT9E013_16BIT, MT9E013_VCM_SLEW_STEP,
-                               MT9E013_VCM_ENABLE, 0x1);
+       mt9e013_q_focus_status(sd, &val);
+
+       if (val & ATOMISP_FOCUS_STATUS_MOVING)
+               *value  = dev->focus - dev->number_of_steps;
+       else
+               *value  = dev->focus ;
+
+       return 0;
 }
-*/
+
 static long mt9e013_set_exposure(struct v4l2_subdev *sd, u16 coarse_itg,
                                 u16 fine_itg, u16 gain)
 
@@ -1564,7 +1550,6 @@ static int mt9e013_s_stream(struct v4l2_subdev *sd, int enable)
        int ret;
        struct i2c_client *client = v4l2_get_subdevdata(sd);
        struct mt9e013_device *dev = to_mt9e013_sensor(sd);
-       u16 temp;
 
        if (enable) {
                if (dev->sensor_revision <= 0x0) {
@@ -1574,7 +1559,7 @@ static int mt9e013_s_stream(struct v4l2_subdev *sd, int enable)
                                {MT9E013_16BIT, {0x30F2}, 0x0000}, /* VCM_NEW_CODE */
                                INIT_VCM_CONTROL,
                                {MT9E013_16BIT, {0x30F2}, 0x0000}, /* VCM_NEW_CODE */
-                               {MT9E013_TOK_DELAY, {0}, 100},
+                               {MT9E013_TOK_DELAY, {0}, 60},
                                {MT9E013_TOK_TERM, {0}, 0}
                        };
 
index c1c2bb5..6016e72 100644 (file)
@@ -378,7 +378,8 @@ struct mt9e013_device {
        u16 lines_per_frame;
        u8 fps;
        int run_mode;
-       struct timeval timestamp_t_focus_abs;
+       struct timespec timestamp_t_focus_abs;
+       s16 number_of_steps;
 
 };