]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
media: hi556: correct the test pattern configuration
authorBingbu Cao <bingbu.cao@intel.com>
Mon, 30 Jun 2025 09:04:20 +0000 (17:04 +0800)
committerHans Verkuil <hverkuil@xs4all.nl>
Thu, 10 Jul 2025 09:32:25 +0000 (11:32 +0200)
Hynix hi556 support 8 test pattern modes:
hi556_test_pattern_menu[] = {
{
"Disabled",
"Solid Colour",
"100% Colour Bars",
"Fade To Grey Colour Bars",
"PN9",
"Gradient Horizontal",
"Gradient Vertical",
"Check Board",
"Slant Pattern",
}

The test pattern is set by a 8-bit register according to the
specification.
+--------+-------------------------------+
| BIT[0] |  Solid color                  |
+--------+-------------------------------+
| BIT[1] |  Color bar                    |
+--------+-------------------------------+
| BIT[2] |  Fade to grey color bar       |
+--------+-------------------------------+
| BIT[3] |  PN9                          |
+--------+-------------------------------+
| BIT[4] |  Gradient horizontal          |
+--------+-------------------------------+
| BIT[5] |  Gradient vertical            |
+--------+-------------------------------+
| BIT[6] |  Check board                  |
+--------+-------------------------------+
| BIT[7] |  Slant pattern                |
+--------+-------------------------------+
Based on function above, current test pattern programming is wrong.
This patch fixes it by 'BIT(pattern - 1)'. If pattern is 0, driver
will disable the test pattern generation and set the pattern to 0.

Fixes: e62138403a84 ("media: hi556: Add support for Hi-556 sensor")
Cc: stable@vger.kernel.org
Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
drivers/media/i2c/hi556.c

index 110dd00c51aede8a310082fe4ac779f70ba8bd40..076c19fcf99cb9804d3280fb28e5557a4c1dc776 100644 (file)
@@ -762,21 +762,23 @@ static int hi556_test_pattern(struct hi556 *hi556, u32 pattern)
        int ret;
        u32 val;
 
-       if (pattern) {
-               ret = hi556_read_reg(hi556, HI556_REG_ISP,
-                                    HI556_REG_VALUE_08BIT, &val);
-               if (ret)
-                       return ret;
+       ret = hi556_read_reg(hi556, HI556_REG_ISP,
+                            HI556_REG_VALUE_08BIT, &val);
+       if (ret)
+               return ret;
 
-               ret = hi556_write_reg(hi556, HI556_REG_ISP,
-                                     HI556_REG_VALUE_08BIT,
-                                     val | HI556_REG_ISP_TPG_EN);
-               if (ret)
-                       return ret;
-       }
+       val = pattern ? (val | HI556_REG_ISP_TPG_EN) :
+               (val & ~HI556_REG_ISP_TPG_EN);
+
+       ret = hi556_write_reg(hi556, HI556_REG_ISP,
+                             HI556_REG_VALUE_08BIT, val);
+       if (ret)
+               return ret;
+
+       val = pattern ? BIT(pattern - 1) : 0;
 
        return hi556_write_reg(hi556, HI556_REG_TEST_PATTERN,
-                              HI556_REG_VALUE_08BIT, pattern);
+                              HI556_REG_VALUE_08BIT, val);
 }
 
 static int hi556_set_ctrl(struct v4l2_ctrl *ctrl)