1 From d0f282c0afb570a286d6b8438ec0041ca2d2d6db Mon Sep 17 00:00:00 2001
2 From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
3 Date: Mon, 16 Jan 2023 15:44:44 +0100
4 Subject: [PATCH] media: i2c: imx290: Factor out black level setting to
7 Upstream commit ee4ce8936693
9 The black level programmed in the BLKLEVEL register depends on the
10 output format. The black level value computation is currently performed
11 in imx290_set_ctrl(), in addition to having different black level values
12 in the output-specific register value tables. Move it to a separate
13 function to simplify the imx290_set_ctrl() code.
15 Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
16 Reviewed-by: Alexander Stein <alexander.stein@ew.tq-group.com>
17 Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
18 Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
19 Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 drivers/media/i2c/imx290.c | 50 ++++++++++++++++++++------------------
22 1 file changed, 26 insertions(+), 24 deletions(-)
24 --- a/drivers/media/i2c/imx290.c
25 +++ b/drivers/media/i2c/imx290.c
27 #define IMX290_PIXEL_ARRAY_RECORDING_WIDTH 1920
28 #define IMX290_PIXEL_ARRAY_RECORDING_HEIGHT 1080
30 +/* Equivalent value for 16bpp */
31 +#define IMX290_BLACK_LEVEL_DEFAULT 3840
33 #define IMX290_NUM_SUPPLIES 3
35 struct imx290_regval {
36 @@ -315,7 +318,6 @@ static const struct imx290_regval imx290
37 { IMX290_ADBIT2, IMX290_ADBIT2_10BIT },
38 { IMX290_ADBIT3, IMX290_ADBIT3_10BIT },
39 { IMX290_CSI_DT_FMT, IMX290_CSI_DT_FMT_RAW10 },
40 - { IMX290_BLKLEVEL, 60 },
43 static const struct imx290_regval imx290_12bit_settings[] = {
44 @@ -325,7 +327,6 @@ static const struct imx290_regval imx290
45 { IMX290_ADBIT2, IMX290_ADBIT2_12BIT },
46 { IMX290_ADBIT3, IMX290_ADBIT3_12BIT },
47 { IMX290_CSI_DT_FMT, IMX290_CSI_DT_FMT_RAW12 },
48 - { IMX290_BLKLEVEL, 240 },
51 /* supported link frequencies */
52 @@ -516,35 +517,40 @@ static int imx290_set_data_lanes(struct
56 +static int imx290_set_black_level(struct imx290 *imx290,
57 + unsigned int black_level, int *err)
59 + return imx290_write(imx290, IMX290_BLKLEVEL,
60 + black_level >> (16 - imx290->bpp), err);
63 static int imx290_write_current_format(struct imx290 *imx290)
65 + const struct imx290_regval *regs;
66 + unsigned int num_regs;
69 switch (imx290->current_format.code) {
70 case MEDIA_BUS_FMT_SRGGB10_1X10:
71 - ret = imx290_set_register_array(imx290, imx290_10bit_settings,
73 - imx290_10bit_settings));
75 - dev_err(imx290->dev, "Could not set format registers\n");
78 + regs = imx290_10bit_settings;
79 + num_regs = ARRAY_SIZE(imx290_10bit_settings);
81 case MEDIA_BUS_FMT_SRGGB12_1X12:
82 - ret = imx290_set_register_array(imx290, imx290_12bit_settings,
84 - imx290_12bit_settings));
86 - dev_err(imx290->dev, "Could not set format registers\n");
89 + regs = imx290_12bit_settings;
90 + num_regs = ARRAY_SIZE(imx290_12bit_settings);
93 dev_err(imx290->dev, "Unknown pixel format\n");
98 + ret = imx290_set_register_array(imx290, regs, num_regs);
100 + dev_err(imx290->dev, "Could not set format registers\n");
104 + return imx290_set_black_level(imx290, IMX290_BLACK_LEVEL_DEFAULT, &ret);
107 /* ----------------------------------------------------------------------------
108 @@ -573,7 +579,7 @@ static int imx290_set_ctrl(struct v4l2_c
110 case V4L2_CID_TEST_PATTERN:
112 - imx290_write(imx290, IMX290_BLKLEVEL, 0, &ret);
113 + imx290_set_black_level(imx290, 0, &ret);
114 usleep_range(10000, 11000);
115 imx290_write(imx290, IMX290_PGCTRL,
116 (u8)(IMX290_PGCTRL_REGEN |
117 @@ -582,12 +588,8 @@ static int imx290_set_ctrl(struct v4l2_c
119 imx290_write(imx290, IMX290_PGCTRL, 0x00, &ret);
120 usleep_range(10000, 11000);
121 - if (imx290->bpp == 10)
122 - imx290_write(imx290, IMX290_BLKLEVEL, 0x3c,
124 - else /* 12 bits per pixel */
125 - imx290_write(imx290, IMX290_BLKLEVEL, 0xf0,
127 + imx290_set_black_level(imx290, IMX290_BLACK_LEVEL_DEFAULT,