dda5eba989e6484830cb693219150fa9a805a9fe
[openwrt/staging/blocktrron.git] /
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
5 a function
6
7 Upstream commit ee4ce8936693
8
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.
14
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>
20 ---
21 drivers/media/i2c/imx290.c | 50 ++++++++++++++++++++------------------
22 1 file changed, 26 insertions(+), 24 deletions(-)
23
24 --- a/drivers/media/i2c/imx290.c
25 +++ b/drivers/media/i2c/imx290.c
26 @@ -152,6 +152,9 @@
27 #define IMX290_PIXEL_ARRAY_RECORDING_WIDTH 1920
28 #define IMX290_PIXEL_ARRAY_RECORDING_HEIGHT 1080
29
30 +/* Equivalent value for 16bpp */
31 +#define IMX290_BLACK_LEVEL_DEFAULT 3840
32 +
33 #define IMX290_NUM_SUPPLIES 3
34
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 },
41 };
42
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 },
49 };
50
51 /* supported link frequencies */
52 @@ -516,35 +517,40 @@ static int imx290_set_data_lanes(struct
53 return ret;
54 }
55
56 +static int imx290_set_black_level(struct imx290 *imx290,
57 + unsigned int black_level, int *err)
58 +{
59 + return imx290_write(imx290, IMX290_BLKLEVEL,
60 + black_level >> (16 - imx290->bpp), err);
61 +}
62 +
63 static int imx290_write_current_format(struct imx290 *imx290)
64 {
65 + const struct imx290_regval *regs;
66 + unsigned int num_regs;
67 int ret;
68
69 switch (imx290->current_format.code) {
70 case MEDIA_BUS_FMT_SRGGB10_1X10:
71 - ret = imx290_set_register_array(imx290, imx290_10bit_settings,
72 - ARRAY_SIZE(
73 - imx290_10bit_settings));
74 - if (ret < 0) {
75 - dev_err(imx290->dev, "Could not set format registers\n");
76 - return ret;
77 - }
78 + regs = imx290_10bit_settings;
79 + num_regs = ARRAY_SIZE(imx290_10bit_settings);
80 break;
81 case MEDIA_BUS_FMT_SRGGB12_1X12:
82 - ret = imx290_set_register_array(imx290, imx290_12bit_settings,
83 - ARRAY_SIZE(
84 - imx290_12bit_settings));
85 - if (ret < 0) {
86 - dev_err(imx290->dev, "Could not set format registers\n");
87 - return ret;
88 - }
89 + regs = imx290_12bit_settings;
90 + num_regs = ARRAY_SIZE(imx290_12bit_settings);
91 break;
92 default:
93 dev_err(imx290->dev, "Unknown pixel format\n");
94 return -EINVAL;
95 }
96
97 - return 0;
98 + ret = imx290_set_register_array(imx290, regs, num_regs);
99 + if (ret < 0) {
100 + dev_err(imx290->dev, "Could not set format registers\n");
101 + return ret;
102 + }
103 +
104 + return imx290_set_black_level(imx290, IMX290_BLACK_LEVEL_DEFAULT, &ret);
105 }
106
107 /* ----------------------------------------------------------------------------
108 @@ -573,7 +579,7 @@ static int imx290_set_ctrl(struct v4l2_c
109
110 case V4L2_CID_TEST_PATTERN:
111 if (ctrl->val) {
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
118 } else {
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,
123 - &ret);
124 - else /* 12 bits per pixel */
125 - imx290_write(imx290, IMX290_BLKLEVEL, 0xf0,
126 - &ret);
127 + imx290_set_black_level(imx290, IMX290_BLACK_LEVEL_DEFAULT,
128 + &ret);
129 }
130 break;
131 default: