diff options
author | Justin Madru <jdm64@gawab.com> | 2009-12-18 15:52:53 -0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-03-03 16:42:33 -0800 |
commit | 8c172dde41db666f7a5f3bb62205da017e23c0ec (patch) | |
tree | ee8f478264aa66e738df8b92cccedecb309816af /drivers/staging/dream | |
parent | 096417e087a391dc78780cc1843369a521635522 (diff) | |
download | blackbird-obmc-linux-8c172dde41db666f7a5f3bb62205da017e23c0ec.tar.gz blackbird-obmc-linux-8c172dde41db666f7a5f3bb62205da017e23c0ec.zip |
Staging: s5k3e2fx.c: simplify complexity by factoring
the code was looping, setting s_move[i] to the following calculations
if (actual_step>= 0)
s_move[i] = ((((i + 1) * gain + 0x200) - (i * gain + 0x200)) / 0x400);
else
s_move[i] = ((((i + 1) * gain - 0x200) - (i * gain - 0x200)) / 0x400);
but, this code reduces to the expression
s_move[i] = gain>> 10;
The reason for the complexity was to generate a step function with
integer division and rounding to land on specific values. But these calculations
can be simplified to the following code:
gain = ((actual_step<< 10) / 5)>> 10;
for (i = 0; i<= 4; i++)
s_move[i] = gain;
Signed-off-by: Justin Madru<jdm64@gawab.com>
Reviewed-by: Ray Lee<ray-lk@madrabbit.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/dream')
-rw-r--r-- | drivers/staging/dream/camera/s5k3e2fx.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/drivers/staging/dream/camera/s5k3e2fx.c b/drivers/staging/dream/camera/s5k3e2fx.c index edba19889b0f..66582af5a586 100644 --- a/drivers/staging/dream/camera/s5k3e2fx.c +++ b/drivers/staging/dream/camera/s5k3e2fx.c @@ -1093,14 +1093,10 @@ static int32_t s5k3e2fx_move_focus(int direction, int32_t num_steps) actual_step = step_direction * (int16_t)num_steps; pos_offset = init_code + s5k3e2fx_ctrl->curr_lens_pos; - gain = actual_step * 0x400 / 5; + gain = ((actual_step << 10) / 5) >> 10; - for (i = 0; i <= 4; i++) { - if (actual_step >= 0) - s_move[i] = ((((i+1)*gain+0x200) - (i*gain+0x200))/0x400); - else - s_move[i] = ((((i+1)*gain-0x200) - (i*gain-0x200))/0x400); - } + for (i = 0; i <= 4; i++) + s_move[i] = gain; /* Ring Damping Code */ for (i = 0; i <= 4; i++) { |