mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maxime Ripard <mripard@kernel.org>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
	 Mats Randgaard <matrandg@cisco.com>,
	 Alain Volmat <alain.volmat@foss.st.com>,
	 Sakari Ailus <sakari.ailus@linux.intel.com>,
	 Hans Verkuil <hverkuil@kernel.org>,
	 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Hans Verkuil <hans.verkuil@cisco.com>,
	 Dave Stevenson <dave.stevenson@raspberrypi.com>,
	 Maxime Ripard <mripard@kernel.org>
Subject: [PATCH v4 4/4] media: gc2145: Fix the RGB MBUS format
Date: Mon, 13 Oct 2025 13:01:36 +0200	[thread overview]
Message-ID: <20251013-csi-bgr-rgb-v4-4-55eab2caa69f@kernel.org> (raw)
In-Reply-To: <20251013-csi-bgr-rgb-v4-0-55eab2caa69f@kernel.org>

The GalaxyCore GC2145 is an MIPI-CSI2 sensor. Among others, it support
the MIPI-CSI2 RGB565 format, listed in the driver as
MEDIA_BUS_FMT_RGB565_1X16.

Most CSI2 receiver drivers then map MEDIA_BUS_FMT_RGB565_1X16 to
V4L2_PIX_FMT_RGB565.

However, V4L2_PIX_FMT_RGB565 is defined as having its color components
in the R, G and B order, from left to right. MIPI-CSI2 however defines
the RGB565 format with blue first.

This essentially means that the R and B will be swapped compared to what
V4L2_PIX_FMT_RGB565 defines.

The proper MBUS format would be BGR565, so let's use that.

Fixes: 03cc7fefbb09 ("media: i2c: gc2145: Galaxy Core GC2145 sensor support")
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
 drivers/media/i2c/gc2145.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/gc2145.c b/drivers/media/i2c/gc2145.c
index b215963a2648b7423fc0ca42b300b6c586d2b994..3c179ccf19cd7ed016699d4de4eb81271c1e11ab 100644
--- a/drivers/media/i2c/gc2145.c
+++ b/drivers/media/i2c/gc2145.c
@@ -579,11 +579,11 @@ static const struct gc2145_format supported_formats[] = {
 		.colorspace	= V4L2_COLORSPACE_SRGB,
 		.datatype	= MIPI_CSI2_DT_YUV422_8B,
 		.output_fmt	= 0x03,
 	},
 	{
-		.code		= MEDIA_BUS_FMT_RGB565_1X16,
+		.code		= MEDIA_BUS_FMT_BGR565_1X16,
 		.colorspace	= V4L2_COLORSPACE_SRGB,
 		.datatype	= MIPI_CSI2_DT_RGB565,
 		.output_fmt	= 0x06,
 		.switch_bit	= true,
 	},
@@ -613,10 +613,25 @@ static const struct gc2145_format supported_formats[] = {
 		.colorspace     = V4L2_COLORSPACE_RAW,
 		.datatype       = MIPI_CSI2_DT_RAW8,
 		.output_fmt     = 0x17,
 		.row_col_switch = GC2145_SYNC_MODE_ROW_SWITCH,
 	},
+	{
+	/*
+	 * The driver was initially introduced with RGB565 support, but
+	 * CSI really means BGR.
+	 *
+	 * Since we might have applications that would have hard-coded
+	 * the RGB565, let's support both, with RGB being last to make
+	 * sure it's only a last resort.
+	 */
+		.code		= MEDIA_BUS_FMT_RGB565_1X16,
+		.colorspace	= V4L2_COLORSPACE_SRGB,
+		.datatype	= MIPI_CSI2_DT_RGB565,
+		.output_fmt	= 0x06,
+		.switch_bit	= true,
+	},
 };
 
 struct gc2145_ctrls {
 	struct v4l2_ctrl_handler handler;
 	struct v4l2_ctrl *pixel_rate;
@@ -658,12 +673,17 @@ static inline struct v4l2_subdev *gc2145_ctrl_to_sd(struct v4l2_ctrl *ctrl)
 }
 
 static const struct gc2145_format *
 gc2145_get_format_code(struct gc2145 *gc2145, u32 code)
 {
+	struct i2c_client *client = v4l2_get_subdevdata(&gc2145->sd);
 	unsigned int i;
 
+	if (code == MEDIA_BUS_FMT_RGB565_1X16)
+		dev_warn_once(&client->dev,
+			      "RGB format isn't actually supported by the hardware. The application should be fixed to use BGR.");
+
 	for (i = 0; i < ARRAY_SIZE(supported_formats); i++) {
 		if (supported_formats[i].code == code)
 			break;
 	}
 
@@ -696,11 +716,11 @@ static int gc2145_init_state(struct v4l2_subdev *sd,
 	struct v4l2_rect *crop;
 
 	/* Initialize pad format */
 	format = v4l2_subdev_state_get_format(state, 0);
 	gc2145_update_pad_format(gc2145, &supported_modes[0], format,
-				 MEDIA_BUS_FMT_RGB565_1X16,
+				 MEDIA_BUS_FMT_BGR565_1X16,
 				 V4L2_COLORSPACE_SRGB);
 
 	/* Initialize crop rectangle. */
 	crop = v4l2_subdev_state_get_crop(state, 0);
 	*crop = supported_modes[0].crop;

-- 
2.51.0


      parent reply	other threads:[~2025-10-13 11:01 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-13 11:01 [PATCH v4 0/4] media: Fix CSI2 RGB vs BGR pixel order Maxime Ripard
2025-10-13 11:01 ` [PATCH v4 1/4] media: uapi: Clarify MBUS color component order for serial buses Maxime Ripard
2025-10-26 23:12   ` Laurent Pinchart
2025-10-13 11:01 ` [PATCH v4 2/4] media: uapi: Introduce MEDIA_BUS_FMT_BGR565_1X16 Maxime Ripard
2025-10-26 23:15   ` Laurent Pinchart
2025-10-26 23:33     ` Laurent Pinchart
2025-12-08 15:32       ` Maxime Ripard
2026-01-23 15:34         ` Laurent Pinchart
2026-01-28 12:32           ` Maxime Ripard
2026-01-28 13:19             ` Laurent Pinchart
2026-02-02  7:23               ` Jai Luthra
2026-02-02  9:31                 ` Laurent Pinchart
2026-02-02 10:51                   ` Jai Luthra
2026-02-03 23:43                     ` Laurent Pinchart
2026-02-04  0:52                       ` Jai Luthra
2026-02-03  8:52               ` Maxime Ripard
2026-02-03 23:40                 ` Laurent Pinchart
2026-02-04  9:31                   ` Maxime Ripard
2026-02-04 19:41                     ` Laurent Pinchart
2025-10-13 11:01 ` [PATCH v4 3/4] media: tc358743: Fix the RGB MBUS format Maxime Ripard
2025-10-13 17:15   ` Dave Stevenson
2025-10-13 11:01 ` Maxime Ripard [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251013-csi-bgr-rgb-v4-4-55eab2caa69f@kernel.org \
    --to=mripard@kernel.org \
    --cc=alain.volmat@foss.st.com \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=hans.verkuil@cisco.com \
    --cc=hverkuil@kernel.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=matrandg@cisco.com \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®