1 From f1a8ae8064a65846489386fe95790900fb150242 Mon Sep 17 00:00:00 2001
2 From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
3 Date: Fri, 12 Jun 2020 15:53:51 +0200
4 Subject: [PATCH] media: i2c: imx290: Add support for test pattern
7 Commit a58df1f9e4885eaf3d0663574a217e513821a9f0 upstream.
9 Add support for generating following test patterns by IMX290:
12 * Horizontal Color-bar Chart
13 * Vertical Color-bar Chart
17 * 000/555h Toggle Pattern
19 Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
20 Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
21 Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
22 Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
24 drivers/media/i2c/imx290.c | 41 +++++++++++++++++++++++++++++++++++++-
25 1 file changed, 40 insertions(+), 1 deletion(-)
27 --- a/drivers/media/i2c/imx290.c
28 +++ b/drivers/media/i2c/imx290.c
30 #define IMX290_REGHOLD 0x3001
31 #define IMX290_XMSTA 0x3002
32 #define IMX290_FR_FDG_SEL 0x3009
33 +#define IMX290_BLKLEVEL_LOW 0x300a
34 +#define IMX290_BLKLEVEL_HIGH 0x300b
35 #define IMX290_GAIN 0x3014
36 #define IMX290_HMAX_LOW 0x301c
37 #define IMX290_HMAX_HIGH 0x301d
38 +#define IMX290_PGCTRL 0x308c
39 #define IMX290_PHY_LANE_NUM 0x3407
40 #define IMX290_CSI_LANE_MODE 0x3443
42 +#define IMX290_PGCTRL_REGEN BIT(0)
43 +#define IMX290_PGCTRL_THRU BIT(1)
44 +#define IMX290_PGCTRL_MODE(n) ((n) << 4)
46 static const char * const imx290_supply_name[] = {
49 @@ -91,6 +98,17 @@ static const struct regmap_config imx290
50 .cache_type = REGCACHE_RBTREE,
53 +static const char * const imx290_test_pattern_menu[] = {
55 + "Sequence Pattern 1",
56 + "Horizontal Color-bar Chart",
57 + "Vertical Color-bar Chart",
58 + "Sequence Pattern 2",
59 + "Gradation Pattern 1",
60 + "Gradation Pattern 2",
61 + "000/555h Toggle Pattern",
64 static const struct imx290_regval imx290_global_init_settings[] = {
67 @@ -448,6 +466,22 @@ static int imx290_set_ctrl(struct v4l2_c
69 ret = imx290_set_gain(imx290, ctrl->val);
71 + case V4L2_CID_TEST_PATTERN:
73 + imx290_write_reg(imx290, IMX290_BLKLEVEL_LOW, 0x00);
74 + imx290_write_reg(imx290, IMX290_BLKLEVEL_HIGH, 0x00);
76 + imx290_write_reg(imx290, IMX290_PGCTRL,
77 + (u8)(IMX290_PGCTRL_REGEN |
78 + IMX290_PGCTRL_THRU |
79 + IMX290_PGCTRL_MODE(ctrl->val)));
81 + imx290_write_reg(imx290, IMX290_PGCTRL, 0x00);
83 + imx290_write_reg(imx290, IMX290_BLKLEVEL_LOW, 0x3c);
84 + imx290_write_reg(imx290, IMX290_BLKLEVEL_HIGH, 0x00);
90 @@ -959,7 +993,7 @@ static int imx290_probe(struct i2c_clien
92 imx290_entity_init_cfg(&imx290->sd, NULL);
94 - v4l2_ctrl_handler_init(&imx290->ctrls, 3);
95 + v4l2_ctrl_handler_init(&imx290->ctrls, 4);
97 v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
98 V4L2_CID_GAIN, 0, 72, 1, 0);
99 @@ -977,6 +1011,11 @@ static int imx290_probe(struct i2c_clien
101 imx290_calc_pixel_rate(imx290));
103 + v4l2_ctrl_new_std_menu_items(&imx290->ctrls, &imx290_ctrl_ops,
104 + V4L2_CID_TEST_PATTERN,
105 + ARRAY_SIZE(imx290_test_pattern_menu) - 1,
106 + 0, 0, imx290_test_pattern_menu);
108 imx290->sd.ctrl_handler = &imx290->ctrls;
110 if (imx290->ctrls.error) {