Set gain to range 32-255 -> 96-765

This commit is contained in:
dchvs 2021-04-04 19:09:26 -06:00
parent 712fc2f18b
commit bd9969166a
1 changed files with 4 additions and 27 deletions

View File

@ -397,50 +397,27 @@ static int mt9m021_set_gain(struct tegracam_device *tc_dev, s64 val)
struct camera_common_data *s_data = tc_dev->s_data;
struct device *dev = tc_dev->dev;
int err = 0;
u16 gain_mul;
u16 reg16 = 0;
u64 gain = 0;
dev_dbg(dev, "Setting Gain to: %lld", val);
if (val >= MT9M021_GAIN_8X_FIXED) {
gain_mul = MT9M021_GAIN_8X;
} else if (val >= MT9M021_GAIN_4X_FIXED) {
gain_mul = MT9M021_GAIN_4X;
} else if (val >= MT9M021_GAIN_2X_FIXED) {
gain_mul = MT9M021_GAIN_2X;
} else {
gain_mul = MT9M021_GAIN_1X;
}
/*
* Digital gain equation:
*
* RANGE: 1x, 7.97x
* STEPS: 1/32
*
* gain accepts mapping from range 32 - 255
*
* SCALE FACTOR = 3
*
* min_gain_val = 102
* max_gain_val = 160
* min_gain_val = 96
* max_gain_val = 765
* gain_factor = 3
*
* gain accepts mapping to range 32 - 53
*/
gain = val / 3;
/* Update analog gain multiplier */
err = mt9m021_read_reg16(s_data, MT9M021_DIGITAL_TEST, &reg16);
if (err)
goto exit;
reg16 =
(reg16 & ~MT9M021_ANALOG_GAIN_MASK) |
((gain_mul << MT9M021_ANALOG_GAIN_SHIFT) &
MT9M021_ANALOG_GAIN_MASK);
err = mt9m021_write_reg16(s_data, MT9M021_DIGITAL_TEST, reg16);
if (err)
goto exit;
/* Update global gain */
err = mt9m021_write_reg16(s_data, MT9M021_GLOBAL_GAIN, gain);
if (err)