[PATCH v2 1/2] media: i2c: ov8865: fix horizontal flip control polarity

Jakob Berg Jespersen <[email protected]>
Newsgroups org.kernel.vger.linux-media,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <[email protected]>
The sensor's native readout is horizontally mirrored and the FORMAT2
FLIP_HORZ bits (reg 0x3821) un-mirror it. The driver sets those bits for
V4L2_CID_HFLIP=1, so the control is inverted: HFLIP=1 yields the
un-mirrored image and HFLIP=0 the mirrored one, the opposite of what is
requested.

Invert the polarity so HFLIP=0 yields the unflipped image.

Found on the Surface Pro 7+ rear camera (180 degree mount), where
libcamera's HFLIP=1+VFLIP=1 correction otherwise produces a mirrored
image.

Fixes: 11c0d8fdccc5 ("media: i2c: Add support for the OV8865 image sensor")
Cc: [email protected]
Reviewed-by: Hans de Goede <[email protected]>
Signed-off-by: Jakob Berg Jespersen <[email protected]>
---
 drivers/media/i2c/ov8865.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
index c6d53c3d55ca..ccda33839246 100644
--- a/drivers/media/i2c/ov8865.c
+++ b/drivers/media/i2c/ov8865.c
@@ -2204,8 +2204,9 @@ static int ov8865_flip_horz_configure(struct ov8865_sensor *sensor, bool enable)
 	u8 bits = OV8865_FORMAT2_FLIP_HORZ_ISP_EN |
 		  OV8865_FORMAT2_FLIP_HORZ_SENSOR_EN;
 
+	/* HFLIP is inverted on this sensor: the FLIP_HORZ bits un-mirror the readout. */
 	return ov8865_update_bits(sensor, OV8865_FORMAT2_REG, bits,
-				  enable ? bits : 0);
+				  enable ? 0 : bits);
 }
 
 /* Test Pattern */

-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.