Fix gain equation on Driver

This commit is contained in:
dchvs 2021-03-04 00:36:20 -06:00
parent fef47412d5
commit 7f1843d73d
1 changed files with 52 additions and 47 deletions

View File

@ -135,8 +135,8 @@
#define MT9M021_ANALOG_GAIN_SHIFT 4
#define MT9M021_ANALOG_GAIN_MASK 0x0030
#define MT9M021_GLOBAL_GAIN_MIN 4
#define MT9M021_GLOBAL_GAIN_MAX 6476
#define MT9M021_GLOBAL_GAIN_MIN 100
#define MT9M021_GLOBAL_GAIN_MAX 797
#define MT9M021_GLOBAL_GAIN_DEF 100
#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;
u16 gain_mul;
u16 reg16 = 0;
u8 integer, fraction;
u64 gain = 0;
dev_dbg(dev, "Setting Gain to: %lld", val);
if (val >= MT9M021_GAIN_8X_FIXED) {
integer = val / MT9M021_GAIN_8X_FIXED;
fraction = ((val / 8) % 100) * 32 / 100;
gain_mul = MT9M021_GAIN_8X;
} else if (val >= MT9M021_GAIN_4X_FIXED) {
integer = val / MT9M021_GAIN_4X_FIXED;
fraction = ((val / 4) % 100) * 32 / 100;
gain_mul = MT9M021_GAIN_4X;
} else if (val >= MT9M021_GAIN_2X_FIXED) {
integer = val / MT9M021_GAIN_2X_FIXED;
fraction = ((val / 2) % 100) * 32 / 100;
gain_mul = MT9M021_GAIN_2X;
} else {
integer = val / MT9M021_GAIN_1X_FIXED;
fraction = (val % 100) * 32 / 100;
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 */
err = mt9m021_read_reg16(s_data, MT9M021_DIGITAL_TEST, &reg16);
if (err)
@ -436,14 +443,12 @@ static int mt9m021_set_gain(struct tegracam_device *tc_dev, s64 val)
/* Update global gain */
err =
mt9m021_write_reg16(s_data, MT9M021_GLOBAL_GAIN,
(integer << 5) | fraction);
mt9m021_write_reg16(s_data, MT9M021_GLOBAL_GAIN, gain);
msleep(10);
if (err)
goto exit;
err =
mt9m021_write_reg16(s_data, MT9M021_GLOBAL_GAIN_CB,
(integer << 5) | fraction);
mt9m021_write_reg16(s_data, MT9M021_GLOBAL_GAIN_CB, gain);
if (err)
goto exit;
@ -528,11 +533,11 @@ static int mt9m021_set_exposure(struct tegracam_device *tc_dev, s64 val)
u64 coarse_time;
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 = mode->signal_properties.pixel_clock.val *
val / mode->image_properties.line_length /
coarse_time =
val * mode->signal_properties.pixel_clock.val /
mode->image_properties.line_length /
mode->control_properties.exposure_factor;
err = mt9m021_set_coarse_time(priv, coarse_time);