Skip to content

Commit

Permalink
media: imx290: Add module parameter to automatically switch to HCG mode
Browse files Browse the repository at this point in the history
The sensor has Low Conversion Gain (HCG) and High Conversion Gain (HCG)
modes, with the supposedly the HCG mode having better noise performance
at high gains.

Based on other devices based on the same sensor, automatically switch
between LCG and HCG at a defined analog gain register threshold.
The threshold can be defined via a module parameter, and defaults to
80, representing 24dB of gain, matching other devices using this module.

Signed-off-by: Dave Stevenson <[email protected]>
  • Loading branch information
6by9 committed May 15, 2024
1 parent 886f86f commit 394e219
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion drivers/media/i2c/imx290.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/of.h>
#include <linux/pm_runtime.h>
#include <linux/regmap.h>
Expand Down Expand Up @@ -41,6 +42,8 @@
#define IMX290_WINMODE_720P (1 << 4)
#define IMX290_WINMODE_CROP (4 << 4)
#define IMX290_FR_FDG_SEL CCI_REG8(0x3009)
#define IMX290_FDG_HCG BIT(4)
#define IMX290_FDG_LCG 0
#define IMX290_BLKLEVEL CCI_REG16_LE(0x300a)
#define IMX290_GAIN CCI_REG8(0x3014)
#define IMX290_VMAX CCI_REG24_LE(0x3018)
Expand Down Expand Up @@ -162,6 +165,10 @@

#define IMX290_NUM_SUPPLIES 3

static int hgc_threshold = 80;
module_param(hgc_threshold, int, 0664);
MODULE_PARM_DESC(hgc_threshold, "Analog gain threshold to enable HCG mode");

enum imx290_colour_variant {
IMX290_VARIANT_COLOUR,
IMX290_VARIANT_MONO,
Expand Down Expand Up @@ -649,7 +656,6 @@ static int imx290_set_data_lanes(struct imx290 *imx290)
&ret);
cci_write(imx290->regmap, IMX290_CSI_LANE_MODE, imx290->nlanes - 1,
&ret);
cci_write(imx290->regmap, IMX290_FR_FDG_SEL, 0x01, &ret);

return ret;
}
Expand Down Expand Up @@ -763,6 +769,10 @@ static int imx290_set_ctrl(struct v4l2_ctrl *ctrl)
switch (ctrl->id) {
case V4L2_CID_ANALOGUE_GAIN:
ret = cci_write(imx290->regmap, IMX290_GAIN, ctrl->val, NULL);

cci_write(imx290->regmap, IMX290_FR_FDG_SEL,
0x01 | (ctrl->val >= hgc_threshold) ?
IMX290_FDG_HCG : IMX290_FDG_LCG, &ret);
break;

case V4L2_CID_VBLANK:
Expand Down

0 comments on commit 394e219

Please sign in to comment.