| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 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 |
| 5 | generation |
| 6 | |
| 7 | Commit a58df1f9e4885eaf3d0663574a217e513821a9f0 upstream. |
| 8 | |
| 9 | Add support for generating following test patterns by IMX290: |
| 10 | |
| 11 | * Sequence Pattern 1 |
| 12 | * Horizontal Color-bar Chart |
| 13 | * Vertical Color-bar Chart |
| 14 | * Sequence Pattern 2 |
| 15 | * Gradation Pattern 1 |
| 16 | * Gradation Pattern 2 |
| 17 | * 000/555h Toggle Pattern |
| 18 | |
| 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> |
| 23 | --- |
| 24 | drivers/media/i2c/imx290.c | 41 +++++++++++++++++++++++++++++++++++++- |
| 25 | 1 file changed, 40 insertions(+), 1 deletion(-) |
| 26 | |
| 27 | --- a/drivers/media/i2c/imx290.c |
| 28 | +++ b/drivers/media/i2c/imx290.c |
| 29 | @@ -26,12 +26,19 @@ |
| 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 |
| 41 | |
| 42 | +#define IMX290_PGCTRL_REGEN BIT(0) |
| 43 | +#define IMX290_PGCTRL_THRU BIT(1) |
| 44 | +#define IMX290_PGCTRL_MODE(n) ((n) << 4) |
| 45 | + |
| 46 | static const char * const imx290_supply_name[] = { |
| 47 | "vdda", |
| 48 | "vddd", |
| 49 | @@ -91,6 +98,17 @@ static const struct regmap_config imx290 |
| 50 | .cache_type = REGCACHE_RBTREE, |
| 51 | }; |
| 52 | |
| 53 | +static const char * const imx290_test_pattern_menu[] = { |
| 54 | + "Disabled", |
| 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", |
| 62 | +}; |
| 63 | + |
| 64 | static const struct imx290_regval imx290_global_init_settings[] = { |
| 65 | { 0x3007, 0x00 }, |
| 66 | { 0x3018, 0x65 }, |
| 67 | @@ -448,6 +466,22 @@ static int imx290_set_ctrl(struct v4l2_c |
| 68 | case V4L2_CID_GAIN: |
| 69 | ret = imx290_set_gain(imx290, ctrl->val); |
| 70 | break; |
| 71 | + case V4L2_CID_TEST_PATTERN: |
| 72 | + if (ctrl->val) { |
| 73 | + imx290_write_reg(imx290, IMX290_BLKLEVEL_LOW, 0x00); |
| 74 | + imx290_write_reg(imx290, IMX290_BLKLEVEL_HIGH, 0x00); |
| 75 | + msleep(10); |
| 76 | + imx290_write_reg(imx290, IMX290_PGCTRL, |
| 77 | + (u8)(IMX290_PGCTRL_REGEN | |
| 78 | + IMX290_PGCTRL_THRU | |
| 79 | + IMX290_PGCTRL_MODE(ctrl->val))); |
| 80 | + } else { |
| 81 | + imx290_write_reg(imx290, IMX290_PGCTRL, 0x00); |
| 82 | + msleep(10); |
| 83 | + imx290_write_reg(imx290, IMX290_BLKLEVEL_LOW, 0x3c); |
| 84 | + imx290_write_reg(imx290, IMX290_BLKLEVEL_HIGH, 0x00); |
| 85 | + } |
| 86 | + break; |
| 87 | default: |
| 88 | ret = -EINVAL; |
| 89 | break; |
| 90 | @@ -959,7 +993,7 @@ static int imx290_probe(struct i2c_clien |
| 91 | */ |
| 92 | imx290_entity_init_cfg(&imx290->sd, NULL); |
| 93 | |
| 94 | - v4l2_ctrl_handler_init(&imx290->ctrls, 3); |
| 95 | + v4l2_ctrl_handler_init(&imx290->ctrls, 4); |
| 96 | |
| 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 |
| 100 | 1, INT_MAX, 1, |
| 101 | imx290_calc_pixel_rate(imx290)); |
| 102 | |
| 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); |
| 107 | + |
| 108 | imx290->sd.ctrl_handler = &imx290->ctrls; |
| 109 | |
| 110 | if (imx290->ctrls.error) { |