Fix gain equation on Driver
This commit is contained in:
parent
fef47412d5
commit
7f1843d73d
|
@ -135,8 +135,8 @@
|
||||||
#define MT9M021_ANALOG_GAIN_SHIFT 4
|
#define MT9M021_ANALOG_GAIN_SHIFT 4
|
||||||
#define MT9M021_ANALOG_GAIN_MASK 0x0030
|
#define MT9M021_ANALOG_GAIN_MASK 0x0030
|
||||||
|
|
||||||
#define MT9M021_GLOBAL_GAIN_MIN 4
|
#define MT9M021_GLOBAL_GAIN_MIN 100
|
||||||
#define MT9M021_GLOBAL_GAIN_MAX 6476
|
#define MT9M021_GLOBAL_GAIN_MAX 797
|
||||||
#define MT9M021_GLOBAL_GAIN_DEF 100
|
#define MT9M021_GLOBAL_GAIN_DEF 100
|
||||||
|
|
||||||
#define MT9M021_COARSE_INT_TIME_MIN 0x0001
|
#define MT9M021_COARSE_INT_TIME_MIN 0x0001
|
||||||
|
@ -399,28 +399,35 @@ static int mt9m021_set_gain(struct tegracam_device *tc_dev, s64 val)
|
||||||
int err = 0;
|
int err = 0;
|
||||||
u16 gain_mul;
|
u16 gain_mul;
|
||||||
u16 reg16 = 0;
|
u16 reg16 = 0;
|
||||||
u8 integer, fraction;
|
u64 gain = 0;
|
||||||
|
|
||||||
dev_dbg(dev, "Setting Gain to: %lld", val);
|
dev_dbg(dev, "Setting Gain to: %lld", val);
|
||||||
|
|
||||||
if (val >= MT9M021_GAIN_8X_FIXED) {
|
if (val >= MT9M021_GAIN_8X_FIXED) {
|
||||||
integer = val / MT9M021_GAIN_8X_FIXED;
|
|
||||||
fraction = ((val / 8) % 100) * 32 / 100;
|
|
||||||
gain_mul = MT9M021_GAIN_8X;
|
gain_mul = MT9M021_GAIN_8X;
|
||||||
} else if (val >= MT9M021_GAIN_4X_FIXED) {
|
} else if (val >= MT9M021_GAIN_4X_FIXED) {
|
||||||
integer = val / MT9M021_GAIN_4X_FIXED;
|
|
||||||
fraction = ((val / 4) % 100) * 32 / 100;
|
|
||||||
gain_mul = MT9M021_GAIN_4X;
|
gain_mul = MT9M021_GAIN_4X;
|
||||||
} else if (val >= MT9M021_GAIN_2X_FIXED) {
|
} else if (val >= MT9M021_GAIN_2X_FIXED) {
|
||||||
integer = val / MT9M021_GAIN_2X_FIXED;
|
|
||||||
fraction = ((val / 2) % 100) * 32 / 100;
|
|
||||||
gain_mul = MT9M021_GAIN_2X;
|
gain_mul = MT9M021_GAIN_2X;
|
||||||
} else {
|
} else {
|
||||||
integer = val / MT9M021_GAIN_1X_FIXED;
|
|
||||||
fraction = (val % 100) * 32 / 100;
|
|
||||||
gain_mul = MT9M021_GAIN_1X;
|
gain_mul = MT9M021_GAIN_1X;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Digital gain equation:
|
||||||
|
*
|
||||||
|
* RANGE: 1x, 7.97x
|
||||||
|
* GAIN: VAL / STEPS;
|
||||||
|
* STEPS: 1/32
|
||||||
|
*
|
||||||
|
* SCALE FACTOR = 100.000
|
||||||
|
*
|
||||||
|
* min_gain_val = 100.000
|
||||||
|
* max_gain_val = 797.000
|
||||||
|
* step_gain_val = 3125
|
||||||
|
*/
|
||||||
|
gain = val / 3125;
|
||||||
|
|
||||||
/* Update analog gain multiplier */
|
/* Update analog gain multiplier */
|
||||||
err = mt9m021_read_reg16(s_data, MT9M021_DIGITAL_TEST, ®16);
|
err = mt9m021_read_reg16(s_data, MT9M021_DIGITAL_TEST, ®16);
|
||||||
if (err)
|
if (err)
|
||||||
|
@ -436,14 +443,12 @@ static int mt9m021_set_gain(struct tegracam_device *tc_dev, s64 val)
|
||||||
|
|
||||||
/* Update global gain */
|
/* Update global gain */
|
||||||
err =
|
err =
|
||||||
mt9m021_write_reg16(s_data, MT9M021_GLOBAL_GAIN,
|
mt9m021_write_reg16(s_data, MT9M021_GLOBAL_GAIN, gain);
|
||||||
(integer << 5) | fraction);
|
|
||||||
msleep(10);
|
msleep(10);
|
||||||
if (err)
|
if (err)
|
||||||
goto exit;
|
goto exit;
|
||||||
err =
|
err =
|
||||||
mt9m021_write_reg16(s_data, MT9M021_GLOBAL_GAIN_CB,
|
mt9m021_write_reg16(s_data, MT9M021_GLOBAL_GAIN_CB, gain);
|
||||||
(integer << 5) | fraction);
|
|
||||||
if (err)
|
if (err)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
|
@ -528,11 +533,11 @@ static int mt9m021_set_exposure(struct tegracam_device *tc_dev, s64 val)
|
||||||
u64 coarse_time;
|
u64 coarse_time;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
dev_dbg(dev, "Setting Exposure Time to: %lld", val);
|
dev_dbg(dev, "Setting Exposure Time to : %lld", val);
|
||||||
|
|
||||||
/* Calculate coarse-time */
|
coarse_time =
|
||||||
coarse_time = mode->signal_properties.pixel_clock.val *
|
val * mode->signal_properties.pixel_clock.val /
|
||||||
val / mode->image_properties.line_length /
|
mode->image_properties.line_length /
|
||||||
mode->control_properties.exposure_factor;
|
mode->control_properties.exposure_factor;
|
||||||
|
|
||||||
err = mt9m021_set_coarse_time(priv, coarse_time);
|
err = mt9m021_set_coarse_time(priv, coarse_time);
|
||||||
|
|
Loading…
Reference in New Issue