From nobody Sat Jul 25 02:12:52 2026 Received: from mail-43172.protonmail.ch (mail-43172.protonmail.ch [185.70.43.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1E5342B736 for ; Mon, 20 Jul 2026 14:29:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784557768; cv=none; b=TsKuYMlJvItr10E7VNof4N6cxKr6tvMhewBvBl/fFTKlDtGafz7dFn6oQxfmmuSIDjQhCcYdsiKTeYecpkk7UFMseTFuQAvklODdL+iD5H9p/XERymmFW3jBbMhWg8AyAgx6i3eK+K58NPgrLYuXnFBVn9Xi2dPvuXDJ/AGN1Eo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784557768; c=relaxed/simple; bh=/xxjhTeTYlPskVvcuW8vsxe5iugEc5NZC/WrGRNyeqc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ToME/sqgkEmtJrau+8qt40t3EoqapJpDrzqNALFTbQVceCY/ubnIgKk1tziZQntr+I1sgCm+v08XMJaubGc1cRf8Bc/0ZJGfAvT1ioztvKgV4TT3p/p5G6c8sWH9anx4bDPi9xJw7Pbht7lSLxY+IKgNasbxFg3XEekXahym79M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=berg.pm; spf=pass smtp.mailfrom=berg.pm; dkim=pass (2048-bit key) header.d=berg.pm header.i=@berg.pm header.b=lYGFnjyx; arc=none smtp.client-ip=185.70.43.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=berg.pm Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=berg.pm Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=berg.pm header.i=@berg.pm header.b="lYGFnjyx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=berg.pm; s=protonmail; t=1784557755; x=1784816955; bh=qMxNineG/nldiihWlEY9FdiQ6QC7kxpKIqji2f+Qolk=; h=From:Date:Subject:Message-Id:References:In-Reply-To:To:Cc:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=lYGFnjyx5IXHHPJCdH9BGlOhLSHTPCHJcyJNDTKFif2v34KMCqZdyBKUx+bxiw+8L /iT6lVfEhCjUo0YE/kGX4BK8vnulcLOmA2rfSUscbWaSEyAwyvInwzXoylVa4XJQOP MfzthV7+l4T9bx+xRvfDuH6VxB2KkPDBA8/lF/btYBYw7pt9S7XgQO3++hAC7PhP3m 4oUsaFrtBRuS96oVTrfnOm4G6W3+Dlb26hxe5pZt21dS9K2x/Ni6CPSIPCK+KG/OtW BiWbaijjdKRynvQ6nGEAM+ykM2UwamNRMxkLPg/DWmQ/minW30jC0K1lEK3GQdNRFy OIHABk+mI1yug== X-Pm-Submission-Id: 4h3jZJ3V3fz1DDLl From: Jakob Berg Jespersen Date: Mon, 20 Jul 2026 16:28:40 +0200 Subject: [PATCH RFC 1/2] media: i2c: ov8865: fix horizontal flip control polarity Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260720-sp7plus-ov-flips-v1-1-5f345b0673de@berg.pm> References: <20260720-sp7plus-ov-flips-v1-0-5f345b0673de@berg.pm> In-Reply-To: <20260720-sp7plus-ov-flips-v1-0-5f345b0673de@berg.pm> To: Sakari Ailus , Mauro Carvalho Chehab , Daniel Scally Cc: Hans de Goede , Fernando Rimoli , Tooraj Taraz , "Joseph V. Lavigne" , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Jakob Berg Jespersen X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784557750; l=2010; i=dev@berg.pm; s=20260719; h=from:subject:message-id; bh=/xxjhTeTYlPskVvcuW8vsxe5iugEc5NZC/WrGRNyeqc=; b=t+gXxG2gCVslmYEuL0qk4Q4FnaUBzKDZbDNV8toBc5ZSTvi9QJYjoeAzyLJCM+AoLcKmNJObd 5IXZzYShbrCDt/T1wEfvgybWUDqRnFWeb4cQrC8FjnfxYO9LlQLxfY+ X-Developer-Key: i=dev@berg.pm; a=ed25519; pk=b1r+eoJThwSQ/r5DjO7jrcosyrIsyhlOuKk9CBdvBxs= The ov8865's native readout is horizontally mirrored and the FORMAT2 FLIP_HORZ bits (reg 0x3821) un-mirror it: with the bits cleared the image is mirrored, with them set it is not. The driver maps V4L2_CID_HFLIP=3D1 to setting the bits, so requesting a flip produces an unflipped image and vice versa. This is user-visible on the Surface Pro 7+ rear camera (mounted with a 180 degree rotation, SSDB degree=3D180): libcamera requests HFLIP=3D1+VFLIP= =3D1 to undo the mount rotation and gets a horizontally flipped image. Verified by a live 4-state flip/image matrix on the streaming sensor: hflip=3D0 vflip=3D0 -> 180 degree rotation (both flips) hflip=3D1 vflip=3D0 -> vertical flip only hflip=3D0 vflip=3D1 -> correct image hflip=3D1 vflip=3D1 -> horizontal flip only (vertical flip =3D reflection over a horizontal mirror line, as on water; horizontal flip =3D reflection over a vertical mirror line, as in a mirror) which is only consistent with an inverted HFLIP and a correct VFLIP. Invert the polarity so HFLIP=3D0 yields the unflipped image. Signed-off-by: Jakob Berg Jespersen --- drivers/media/i2c/ov8865.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c index c6d53c3d55ca..901ea7c16395 100644 --- a/drivers/media/i2c/ov8865.c +++ b/drivers/media/i2c/ov8865.c @@ -2204,8 +2204,14 @@ static int ov8865_flip_horz_configure(struct ov8865_= sensor *sensor, bool enable) u8 bits =3D OV8865_FORMAT2_FLIP_HORZ_ISP_EN | OV8865_FORMAT2_FLIP_HORZ_SENSOR_EN; =20 + /* + * The sensor's native readout is horizontally mirrored; the + * FLIP_HORZ bits un-mirror it. Map the control so that HFLIP=3D0 + * yields an unmirrored image (verified on Surface Pro 7+ rear + * camera by a live flip-control/image matrix test). + */ return ov8865_update_bits(sensor, OV8865_FORMAT2_REG, bits, - enable ? bits : 0); + enable ? 0 : bits); } =20 /* Test Pattern */ --=20 2.55.0 From nobody Sat Jul 25 02:12:52 2026 Received: from mail-106111.protonmail.ch (mail-106111.protonmail.ch [79.135.106.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A784442A7B8 for ; Mon, 20 Jul 2026 14:29:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.135.106.111 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784557770; cv=none; b=Mja5/wp1/5yWa7F1Wi5HxMVPsqu8wXT1q/uKFXagZWmFOElTIsTTEkuaS0hrp3cbsShrx0+RADtc9ednM4eJIfdsSi1IJ8ctWoufJTRDNLRwf+EDP50qmopy+MYQFNycZR5/iNAI/SpwMRxnoydHdNOH/FSp5UgquC57QmWi874= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784557770; c=relaxed/simple; bh=1eY9tAkEvPPuQJSxLFf9+C++D+iIDA3Q9citWB/XFqA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AP0/eSOuc7KCt81JnMd7rGFbPA1g8D+W9UvhRa+08qeln/TtafoIccRu6bt3OCfdUWR0X6zzjbGmYGtUEHWRDgLcHn8++U1xMQfDgFoygn4gsQBtQWgkvVeuCXPDLlvNz2/Q8/LMXTLGGHkjHwU+Zb6Ao/3RMRbQQamN1sXdOhU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=berg.pm; spf=pass smtp.mailfrom=berg.pm; dkim=pass (2048-bit key) header.d=berg.pm header.i=@berg.pm header.b=eZC/Y0mo; arc=none smtp.client-ip=79.135.106.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=berg.pm Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=berg.pm Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=berg.pm header.i=@berg.pm header.b="eZC/Y0mo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=berg.pm; s=protonmail; t=1784557757; x=1784816957; bh=j+LVHoTpL8nxBUUAk+O7qsyoV75A13acO9XcZV3Od00=; h=From:Date:Subject:Message-Id:References:In-Reply-To:To:Cc:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=eZC/Y0moEajO8WQw0aYceJqJIyJNxu/aciegaXa2nO1SPJyuufyvFuZgBtNjY/HC7 sQMg+vc+EoscTjQSVcj1LxGh5swkYeo0FRL7g/GVs/M8LvTZsF0AiMwi4/0sjwyD40 ztfwBmLGbLAuxnSPCsv0sjTSQ84rtOAfpLX+VWLDQ9O3PzjbrFYpVuriqq6+oMwY4c okqvHlCeNSnMHW1qSuez+bWghG9VkGCWZpQDQwCICZCYWBlBV+8Khxief2cXB1u3xj I8BgeyNvqt8mSe2oVfdbDJJrT6Gz06Kknfqds9DRog8tWy94+TLYKRZHpUre0uzA41 ezzOAI4MGZidw== X-Pm-Submission-Id: 4h3jZM1ktTz1DDp6 From: Jakob Berg Jespersen Date: Mon, 20 Jul 2026 16:28:41 +0200 Subject: [PATCH RFC 2/2] media: i2c: ov5693: fix horizontal flip polarity and Bayer phase Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260720-sp7plus-ov-flips-v1-2-5f345b0673de@berg.pm> References: <20260720-sp7plus-ov-flips-v1-0-5f345b0673de@berg.pm> In-Reply-To: <20260720-sp7plus-ov-flips-v1-0-5f345b0673de@berg.pm> To: Sakari Ailus , Mauro Carvalho Chehab , Daniel Scally Cc: Hans de Goede , Fernando Rimoli , Tooraj Taraz , "Joseph V. Lavigne" , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Jakob Berg Jespersen X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784557750; l=2974; i=dev@berg.pm; s=20260719; h=from:subject:message-id; bh=1eY9tAkEvPPuQJSxLFf9+C++D+iIDA3Q9citWB/XFqA=; b=0ECAa2GAtrMIzstlkChlbyDn7OfaIT+ak7+8PK/2PZIBzT9TjQmwwuQEcUbAmesdaTAPI69ym 5iHscq6aCFTCIy2+5ncGisD51eUH+EpsAscQZ/+9XhA/c0UU9Yu0S48 X-Developer-Key: i=dev@berg.pm; a=ed25519; pk=b1r+eoJThwSQ/r5DjO7jrcosyrIsyhlOuKk9CBdvBxs= Like the ov8865 (see previous patch), the ov5693's native readout is horizontally mirrored and the FORMAT2 FLIP_HORZ bits (reg 0x3821) un-mirror it: with the bits cleared the image is mirrored, with them set it is not. The vendor init table sets the bits by default (0x3821 =3D 0x1e). The driver maps V4L2_CID_HFLIP=3D1 to setting the bits, so requesting a flip produces an unflipped image and vice versa. This is user-visible on the Surface Pro 7+ front camera (mounted with a 180 degree rotation, SSDB degree=3D180): libcamera requests HFLIP=3D1+VFLIP= =3D1 to undo the mount rotation and gets a horizontally flipped image. Verified the same way as the ov8865, with a live 4-state flip/image matrix on the streaming sensor giving the same result: an inverted HFLIP with a correct VFLIP. Invert the polarity so HFLIP=3D0 yields the unflipped image (bits set) and HFLIP=3D1 the flipped one (bits cleared). Clearing the bits also shifts the Bayer sampling by one column: the fixed SBGGR10 mbus code the driver reports is only correct for the bits-set orientation, so the HFLIP=3D1 state has the wrong colors. Compensate by shifting the ISP output window (reg 0x3810) one column in that state only: OFFSET_START_X =3D 1 when HFLIP=3D1, 0 otherwise. There is a spare column to shift into because the crop end is programmed inclusively (crop end =3D crop start + width). Validated on the SP7+: correct geometry and colors in both flip states. Signed-off-by: Jakob Berg Jespersen Tested-by: Fernando Rimoli --- drivers/media/i2c/ov5693.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c index 4cc796bbee92..95dc6af45125 100644 --- a/drivers/media/i2c/ov5693.c +++ b/drivers/media/i2c/ov5693.c @@ -375,8 +375,28 @@ static int ov5693_flip_horz_configure(struct ov5693_de= vice *ov5693, OV5693_FORMAT2_FLIP_HORZ_SENSOR_EN; int ret; =20 + /* + * The sensor's native readout is horizontally mirrored; the + * FLIP_HORZ bits un-mirror it. Map the control so that HFLIP=3D0 + * yields an unmirrored image (verified on Surface Pro 7+ front + * camera by a live flip-control/image matrix test, matching the + * same behaviour found on the ov8865). + */ ret =3D cci_update_bits(ov5693->regmap, OV5693_FORMAT2_REG, bits, - enable ? bits : 0, NULL); + enable ? 0 : bits, NULL); + if (ret) + return ret; + + /* + * Clearing the FLIP_HORZ bits shifts the Bayer sampling by one + * column relative to the orientation the init table (0x3821 =3D 0x1e) + * and the reported SBGGR10 mbus code assume, which corrupts colors. + * Offset the ISP output window by one column in that state to keep + * the BGGR phase; the crop window always has one spare column + * (crop end =3D start + width, inclusive). + */ + ret =3D cci_write(ov5693->regmap, OV5693_OFFSET_START_X_REG, + enable ? 1 : 0, NULL); if (ret) return ret; =20 --=20 2.55.0