From nobody Thu Oct 2 11:49:16 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B109F2F0688; Wed, 17 Sep 2025 11:16:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758107788; cv=none; b=jqczHOf8ff9GjFgoEAVNSzRN3pnbxDQZ7iOLm+mWk/2htzK0G158yqTEVaAnCho4iUeE1JQ9NrK311FrH4FSFHas1aAxn+7JELTyFZEJzNsxx9NZoNO5ij493/Z0mJ228/tI/yOzKS7qC+QtraX43xvyB1OlZM71MufIiXc/Ne4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758107788; c=relaxed/simple; bh=LIYL+FyEHAnJV8IzqdIcs1l232AGKZKm8aHRWU2Mccg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Axm0QJB7vwdIG3Nf3D/RmP1KqFP8oohXK9KNuh8R/kG66Dwx0Fdckpw6wmLipeMDbBxp/YyIf35WLOXS3k+969vvJBylwUPjVnXq96JEwxle365RAS4a1gRP8ll8a9uWJXYAIuoNgBySwnJb7pODxrMEYoTx8AObJNGoWxPLIeY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W8U64rT4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W8U64rT4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05C23C4CEF0; Wed, 17 Sep 2025 11:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758107788; bh=LIYL+FyEHAnJV8IzqdIcs1l232AGKZKm8aHRWU2Mccg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=W8U64rT4kdE90K4lLI+/2PIC4J2Yia3ItrPqt0GsO/jEDqHoXNXntjXJTaSDaThSn obaPBmbVS6riDTQLSHV55bte8j274F3lPY4ZanqeUKmU9P91lcopwOS0KSwFE+MK1e NcaBFbfGNrCh5E1EgXR6pnO+DMUm6gKZWlmbWkBPL0nhDcU8hvza2LSfHYYnotOw1d sS64a0xKo+EjY9QcLi4ZL4VKtY/f97lBjcNRSMu2+WmxuiOHxBDWvCBf9I0Bj5ebyo HC7mOeADEo4B1nO5X2f2KOzbEFt7jbwhGZqCE8C0aNliJDDqk0KREskWjdUMc7XpgU FPX75UpmJKIDQ== From: Maxime Ripard Date: Wed, 17 Sep 2025 13:16:11 +0200 Subject: [PATCH v3 1/4] media: uapi: Clarify MBUS color component order for serial buses 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: <20250917-csi-bgr-rgb-v3-1-0145571b3aa4@kernel.org> References: <20250917-csi-bgr-rgb-v3-0-0145571b3aa4@kernel.org> In-Reply-To: <20250917-csi-bgr-rgb-v3-0-0145571b3aa4@kernel.org> To: Mauro Carvalho Chehab , Mats Randgaard , Alain Volmat , Sakari Ailus , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Hans Verkuil , Dave Stevenson , Maxime Ripard X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2324; i=mripard@kernel.org; h=from:subject:message-id; bh=LIYL+FyEHAnJV8IzqdIcs1l232AGKZKm8aHRWU2Mccg=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDBmnZrTULvEU2s9UWZYwPalXVcP6dmFT1iGDKn0p04rU2 KWaC/M7prIwCHMyyIopsjyRCTu9vH1xlYP9yh8wc1iZQIYwcHEKwESOdzLW1/+X/J5icDRTS8vf aELn2zjfBRJPJola1hheS3bapLrP0HnOlOpXeo8XaaZ9fDxrg95qxhqu43ffS3tdfiMRkNS9Jc/ rxs7Y6QZM72btquBVX5rtXpE+hyliR6uUWdnezYkWIrZLvAE= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D The subdev format documentation has a subsection describing how to use the media bus pixel codes for serial buses. While it describes the sampling part well, it doesn't really describe the current convention used for the components order. Let's improve that. Signed-off-by: Maxime Ripard --- Documentation/userspace-api/media/v4l/subdev-formats.rst | 14 ++++++++----= -- 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Documentation/userspace-api/media/v4l/subdev-formats.rst b/Doc= umentation/userspace-api/media/v4l/subdev-formats.rst index 2a94371448dc07e5c7097421bd82f42dcd7e21aa..8e92f784abd8123f9ea950f954a= 60af56ee76dbe 100644 --- a/Documentation/userspace-api/media/v4l/subdev-formats.rst +++ b/Documentation/userspace-api/media/v4l/subdev-formats.rst @@ -158,16 +158,18 @@ formats in memory (a raw Bayer image won't be magical= ly converted to JPEG just by storing it to memory), there is no one-to-one correspondence between them. =20 The media bus pixel codes document parallel formats. Should the pixel data= be transported over a serial bus, the media bus pixel code that describes a -parallel format that transfers a sample on a single clock cycle is used. F= or -instance, both MEDIA_BUS_FMT_BGR888_1X24 and MEDIA_BUS_FMT_BGR888_3X8 are = used -on parallel busses for transferring an 8 bits per sample BGR data, whereas= on -serial busses the data in this format is only referred to using -MEDIA_BUS_FMT_BGR888_1X24. This is because there is effectively only a sin= gle -way to transport that format on the serial busses. +parallel format that transfers a sample on a single clock cycle is used. T= he +color component order used is the same used on the serial bus. For instanc= e, +both MEDIA_BUS_FMT_BGR888_1X24 and MEDIA_BUS_FMT_BGR888_3X8 are used on pa= rallel +busses for transferring an 8 bits per sample BGR data, whereas on serial b= usses +the data in this format is only referred to using MEDIA_BUS_FMT_BGR888_1X2= 4, +with BGR meaning that the blue component is transmitted first, then green,= then +red. This is because there is effectively only a single way to transport t= hat +format on the serial busses. =20 Packed RGB Formats ^^^^^^^^^^^^^^^^^^ =20 Those formats transfer pixel data as red, green and blue components. The --=20 2.50.1 From nobody Thu Oct 2 11:49:16 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 4DCE027B341; Wed, 17 Sep 2025 11:16:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758107792; cv=none; b=JF/zR/22kTvR43WQ5V/NcpctzAp0DBbeaan/VmcxDrZtEWmAExmD4MCUJLB8QS+4uirI3gw93Qh0H0+JN/v2XitEkRbyNxYwxvkYZtBEnKo0GiCIlU6RNXeQcI0U6JUxUGU7MhWafZNIjfKBd002j6fxmCnbheVoMrULSmMZkJg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758107792; c=relaxed/simple; bh=iMHuHlG6q411YG0e3jmZQFv19cMjrMhM2NPTCdKopC8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hQlnRGvIx88xHdoThIXSv/JmbpVMk5tE1X1Ig4+0mjf2BbNEKSiIp3/9E2LaxTBueAQIk2w5C9v/FGXOHJGisYMMbgaR2EEXUwH/QKgh8oO8cIXH3K9KR813XYUBKYa+/4fxg/Pa6wdzivgrEGLzjK5qcIPkNQ8cK3HRaoYRqUY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MO9J3wOd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MO9J3wOd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D505FC4CEF0; Wed, 17 Sep 2025 11:16:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758107791; bh=iMHuHlG6q411YG0e3jmZQFv19cMjrMhM2NPTCdKopC8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=MO9J3wOd4tc+T5RVk15uV68rKx4Ze6zI8qLKXZAYleQIS7W2HxfyaUvKlMw2RuUDD r43+GTTkHG5iycbGMMtDtXqqF5/dxqjtD3VUuwUPyHLs/tpO1EpnPFeAt0zEtYY6ll 9jaFPS49BzdGLzwNIWAqaoywDYDp9JJsrd/pBM0cwjcShDRs6I13xPHCXIH3dBYVOW K+KFdXdMbzAjkC2o/IFW3Ol8zXwGxtEVLltobYn/TBP6fKtfGzKLSsX5EE2jOuJ/cd yXBrBe4BkCX9sWbxKm48NpinUyF/NEzZ80CaPEZwo+Fy6UcOlDWtu34x7aCOTCN33x 27c8uLAJ/qc5A== From: Maxime Ripard Date: Wed, 17 Sep 2025 13:16:12 +0200 Subject: [PATCH v3 2/4] media: uapi: Introduce MEDIA_BUS_FMT_BGR565_1X16 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: <20250917-csi-bgr-rgb-v3-2-0145571b3aa4@kernel.org> References: <20250917-csi-bgr-rgb-v3-0-0145571b3aa4@kernel.org> In-Reply-To: <20250917-csi-bgr-rgb-v3-0-0145571b3aa4@kernel.org> To: Mauro Carvalho Chehab , Mats Randgaard , Alain Volmat , Sakari Ailus , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Hans Verkuil , Dave Stevenson , Maxime Ripard X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3098; i=mripard@kernel.org; h=from:subject:message-id; bh=iMHuHlG6q411YG0e3jmZQFv19cMjrMhM2NPTCdKopC8=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDBmnZrQeiwnw8dsyKfmBse3E6dyXcsWevfsx46u4iOehW faueySiO6ayMAhzMsiKKbI8kQk7vbx9cZWD/cofMHNYmUCGMHBxCsBEeIQZ64wl1k66rMv8y2P/ ZO/4T5HfnrQ6bGXWPO468/NenjefxRaKfnh0ZrHFmsLvyzVlCycYizLWZ08+y+PswjDrcVDe+7V yv9tPHp+0otPi8VNDBQ/bi3Xyx12TJ+q+aJ7Nc+vgweAlwhPcAA== X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D MIPI-CSI2 sends its RGB format on the wire with the blue component first, then green, then red. MIPI calls that format "RGB", but by v4l2 conventions it would be BGR. MIPI-CSI2 supports three RGB variants: 444, 555, 565, 666 and 888. We already have BGR666 and BGR888 media bus formats, we don't have any CSI transceivers using the 444 and 555 variants, but some transceivers use the CSI RGB565 format, while using the RGB565 media bus code. That's a mistake, but since we don't have a BGR565 media bus code we need to introduce one before fixing it. Signed-off-by: Maxime Ripard --- .../userspace-api/media/v4l/subdev-formats.rst | 37 ++++++++++++++++++= ++++ include/uapi/linux/media-bus-format.h | 3 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Documentation/userspace-api/media/v4l/subdev-formats.rst b/Doc= umentation/userspace-api/media/v4l/subdev-formats.rst index 8e92f784abd8123f9ea950f954a60af56ee76dbe..def0d24ef6cdb1a2ec9395af146= 8f56adf31a8de 100644 --- a/Documentation/userspace-api/media/v4l/subdev-formats.rst +++ b/Documentation/userspace-api/media/v4l/subdev-formats.rst @@ -625,10 +625,47 @@ The following tables list existing packed RGB formats. - b\ :sub:`4` - b\ :sub:`3` - b\ :sub:`2` - b\ :sub:`1` - b\ :sub:`0` + * .. _MEDIA-BUS-FMT-BGR565-1X16: + + - MEDIA_BUS_FMT_BGR565_1X16 + - 0x1028 + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - b\ :sub:`4` + - b\ :sub:`3` + - b\ :sub:`2` + - b\ :sub:`1` + - b\ :sub:`0` + - g\ :sub:`5` + - g\ :sub:`4` + - g\ :sub:`3` + - g\ :sub:`2` + - g\ :sub:`1` + - g\ :sub:`0` + - r\ :sub:`4` + - r\ :sub:`3` + - r\ :sub:`2` + - r\ :sub:`1` + - r\ :sub:`0` * .. _MEDIA-BUS-FMT-BGR565-2X8-BE: =20 - MEDIA_BUS_FMT_BGR565_2X8_BE - 0x1005 - diff --git a/include/uapi/linux/media-bus-format.h b/include/uapi/linux/med= ia-bus-format.h index ff62056feed5b6588bfcfdff178f5b68eecd3a26..a73d91876d31844bf8c2da91dde= a541181840bd2 100644 --- a/include/uapi/linux/media-bus-format.h +++ b/include/uapi/linux/media-bus-format.h @@ -32,17 +32,18 @@ * new pixel codes. */ =20 #define MEDIA_BUS_FMT_FIXED 0x0001 =20 -/* RGB - next is 0x1028 */ +/* RGB - next is 0x1029 */ #define MEDIA_BUS_FMT_RGB444_1X12 0x1016 #define MEDIA_BUS_FMT_RGB444_2X8_PADHI_BE 0x1001 #define MEDIA_BUS_FMT_RGB444_2X8_PADHI_LE 0x1002 #define MEDIA_BUS_FMT_RGB555_2X8_PADHI_BE 0x1003 #define MEDIA_BUS_FMT_RGB555_2X8_PADHI_LE 0x1004 #define MEDIA_BUS_FMT_RGB565_1X16 0x1017 +#define MEDIA_BUS_FMT_BGR565_1X16 0x1028 #define MEDIA_BUS_FMT_BGR565_2X8_BE 0x1005 #define MEDIA_BUS_FMT_BGR565_2X8_LE 0x1006 #define MEDIA_BUS_FMT_RGB565_2X8_BE 0x1007 #define MEDIA_BUS_FMT_RGB565_2X8_LE 0x1008 #define MEDIA_BUS_FMT_RGB666_1X18 0x1009 --=20 2.50.1 From nobody Thu Oct 2 11:49:16 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D574332B4A8; Wed, 17 Sep 2025 11:16:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758107794; cv=none; b=GJJvIs3gBp1CB+odmVbPPqWd07H4tl+t111MChogxkNKPAv88Bj/tldfvo0j4PM8oD62ADJTS97KVUpyxDuwmcfSkHx4D5868qQJ2EFV7kI7EAscoi67Ex6bPVfnZM1kfsR6k3CEYidUr9ZWK2mh+eySDN1+6cchcFpjfQamn5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758107794; c=relaxed/simple; bh=7eslHwnb16alN9CgVcqEeExdF+Ais9BO+1nMjxLyk5o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uIewMldFcIf6EQAeP5KDW55wmPZym4Vy0Isnq3AQJFw3qZ0F8FQ+e0e37b+yiY2ifyNjm1795dv12WadKSX0AKYCaVXZJzv2aZ2uG8ZAZlkM35FVQLpYu3sG0dY2CSrbav2wzr9LZKFj9MjFFfDkExtrmo0nOyPSc09yvZngMpg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=azrzV3d0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="azrzV3d0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA47AC4CEF7; Wed, 17 Sep 2025 11:16:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758107794; bh=7eslHwnb16alN9CgVcqEeExdF+Ais9BO+1nMjxLyk5o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=azrzV3d0J4Wl1UK9gAQcxyIKS3hN2/rtBT6X2sMHVr+u+bndkIX672HUKN5zEbxqr XMn49Glp2046mwpGzhXXZkNZlZgFdvZ31V/hFLAMngrqmKkL9rRS/ZUebAKoK1Yame l7tcx38Nl2v3BlWuRTZKjQ9mB2Nhycfpls/hul6EuG+cGUgiM0D7u47UpllvLUeaUr HNTK2hFYZnQvPTtozi6Pf692Jmfpjrz/csHzgkLRIQA9TW9Yr2xXrRdXMq4a//zZJA KhVb63FzoIXrpPxrLpSwIXaoYegnAy2GtQ/6x7ttMx77Yav3cRmq/uLq56oxFt7mt3 oka8N2h03EMHw== From: Maxime Ripard Date: Wed, 17 Sep 2025 13:16:13 +0200 Subject: [PATCH v3 3/4] media: tc358743: Fix the RGB MBUS format 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: <20250917-csi-bgr-rgb-v3-3-0145571b3aa4@kernel.org> References: <20250917-csi-bgr-rgb-v3-0-0145571b3aa4@kernel.org> In-Reply-To: <20250917-csi-bgr-rgb-v3-0-0145571b3aa4@kernel.org> To: Mauro Carvalho Chehab , Mats Randgaard , Alain Volmat , Sakari Ailus , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Hans Verkuil , Dave Stevenson , Maxime Ripard X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5735; i=mripard@kernel.org; h=from:subject:message-id; bh=7eslHwnb16alN9CgVcqEeExdF+Ais9BO+1nMjxLyk5o=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDBmnZrR+9Zi6Tkh8j/63U0tn3ix++3KmtkH+/y+vT0x+t NqP5dKZ5R1TWRiEORlkxRRZnsiEnV7evrjKwX7lD5g5rEwgQxi4OAVgIlW/GBs2L556vlbATWWR Dw/Hgo/fXKbesz6TtqRJ4fuCM7Zvpnjs3Sxnmv/7vkFgAs/lvKaeghbGhm3rQptdsro9WrekHQ5 pffrigEPxr4B123LYtujz1lqp8Xqb6wQKeFVN5us98e7YvbdJAA== X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D The tc358743 is an HDMI to MIPI-CSI2 bridge. It can output all three HDMI 1.4 video formats: RGB 4:4:4, YCbCr 4:2:2, and YCbCr 4:4:4. RGB 4:4:4 is converted to the MIPI-CSI2 RGB888 video format, and listed in the driver as MEDIA_BUS_FMT_RGB888_1X24. Most CSI2 receiver drivers then map MEDIA_BUS_FMT_RGB888_1X24 to V4L2_PIX_FMT_RGB24. However, V4L2_PIX_FMT_RGB24 is defined as having its color components in the R, G and B order, from left to right. MIPI-CSI2 however defines the RGB888 format with blue first. This essentially means that the R and B will be swapped compared to what V4L2_PIX_FMT_RGB24 defines. The proper MBUS format would be BGR888, so let's use that. Fixes: d32d98642de6 ("[media] Driver for Toshiba TC358743 HDMI to CSI-2 bri= dge") Signed-off-by: Maxime Ripard --- drivers/media/i2c/tc358743.c | 53 ++++++++++++++++++++++++++++++++++++----= ---- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c index 1cc7636e446d77d7c6266ca86517496261d2b039..897bc2d5317963c6987a1b2cd19= 807d6981d0fa9 100644 --- a/drivers/media/i2c/tc358743.c +++ b/drivers/media/i2c/tc358743.c @@ -678,10 +678,11 @@ static void tc358743_set_ref_clk(struct v4l2_subdev *= sd) } =20 static void tc358743_set_csi_color_space(struct v4l2_subdev *sd) { struct tc358743_state *state =3D to_state(sd); + struct device *dev =3D &state->i2c_client->dev; =20 switch (state->mbus_fmt_code) { case MEDIA_BUS_FMT_UYVY8_1X16: v4l2_dbg(2, debug, sd, "%s: YCbCr 422 16-bit\n", __func__); i2c_wr8_and_or(sd, VOUT_SET2, @@ -693,11 +694,21 @@ static void tc358743_set_csi_color_space(struct v4l2_= subdev *sd) i2c_wr16_and_or(sd, CONFCTL, ~MASK_YCBCRFMT, MASK_YCBCRFMT_422_8_BIT); mutex_unlock(&state->confctl_mutex); break; case MEDIA_BUS_FMT_RGB888_1X24: - v4l2_dbg(2, debug, sd, "%s: RGB 888 24-bit\n", __func__); + /* + * The driver was initially introduced with RGB888 + * support, but CSI really means BGR. + * + * Since we might have applications that would have + * hard-coded the RGB888, let's support both. + */ + dev_warn_once(dev, "RGB format isn't actually supported by the hardware.= The application should be fixed to use BGR."); + fallthrough; + case MEDIA_BUS_FMT_BGR888_1X24: + v4l2_dbg(2, debug, sd, "%s: BGR 888 24-bit\n", __func__); i2c_wr8_and_or(sd, VOUT_SET2, ~(MASK_SEL422 | MASK_VOUT_422FIL_100) & 0xff, 0x00); i2c_wr8_and_or(sd, VI_REP, ~MASK_VOUT_COLOR_SEL & 0xff, MASK_VOUT_COLOR_RGB_FULL); @@ -1354,15 +1365,30 @@ static int tc358743_log_status(struct v4l2_subdev *= sd) (i2c_rd16(sd, CSI_STATUS) & MASK_S_RXACT) ? "yes" : "no"); v4l2_info(sd, "Stopped: %s\n", (i2c_rd16(sd, CSI_STATUS) & MASK_S_HLT) ? "yes" : "no"); - v4l2_info(sd, "Color space: %s\n", - state->mbus_fmt_code =3D=3D MEDIA_BUS_FMT_UYVY8_1X16 ? - "YCbCr 422 16-bit" : - state->mbus_fmt_code =3D=3D MEDIA_BUS_FMT_RGB888_1X24 ? - "RGB 888 24-bit" : "Unsupported"); + + switch (state->mbus_fmt_code) { + case MEDIA_BUS_FMT_BGR888_1X24: + /* + * The driver was initially introduced with RGB888 + * support, but CSI really means BGR. + * + * Since we might have applications that would have + * hard-coded the RGB888, let's support both. + */ + case MEDIA_BUS_FMT_RGB888_1X24: + v4l2_info(sd, "Color space: BGR 888 24-bit\n"); + break; + case MEDIA_BUS_FMT_UYVY8_1X16: + v4l2_info(sd, "Color space: YCbCr 422 16-bit\n"); + break; + default: + v4l2_info(sd, "Color space: Unsupported\n"); + break; + } =20 v4l2_info(sd, "-----%s status-----\n", is_hdmi(sd) ? "HDMI" : "DVI-D"); v4l2_info(sd, "HDCP encrypted content: %s\n", hdmi_sys_status & MASK_S_HDCP ? "yes" : "no"); v4l2_info(sd, "Input color space: %s %s range\n", @@ -1695,24 +1721,32 @@ static int tc358743_enum_mbus_code(struct v4l2_subd= ev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) { switch (code->index) { case 0: - code->code =3D MEDIA_BUS_FMT_RGB888_1X24; + code->code =3D MEDIA_BUS_FMT_BGR888_1X24; break; case 1: code->code =3D MEDIA_BUS_FMT_UYVY8_1X16; break; + case 2: + /* + * We need to keep RGB888 for backward compatibility, + * but we should list it last for userspace to pick BGR. + */ + code->code =3D MEDIA_BUS_FMT_RGB888_1X24; + break; default: return -EINVAL; } return 0; } =20 static u32 tc358743_g_colorspace(u32 code) { switch (code) { + case MEDIA_BUS_FMT_BGR888_1X24: case MEDIA_BUS_FMT_RGB888_1X24: return V4L2_COLORSPACE_SRGB; case MEDIA_BUS_FMT_UYVY8_1X16: return V4L2_COLORSPACE_SMPTE170M; default: @@ -1746,11 +1780,12 @@ static int tc358743_set_fmt(struct v4l2_subdev *sd, struct tc358743_state *state =3D to_state(sd); =20 u32 code =3D format->format.code; /* is overwritten by get_fmt */ int ret =3D tc358743_get_fmt(sd, sd_state, format); =20 - if (code =3D=3D MEDIA_BUS_FMT_RGB888_1X24 || + if (code =3D=3D MEDIA_BUS_FMT_BGR888_1X24 || + code =3D=3D MEDIA_BUS_FMT_RGB888_1X24 || code =3D=3D MEDIA_BUS_FMT_UYVY8_1X16) format->format.code =3D code; format->format.colorspace =3D tc358743_g_colorspace(format->format.code); =20 if (ret) @@ -2166,11 +2201,11 @@ static int tc358743_probe(struct i2c_client *client) sd->entity.function =3D MEDIA_ENT_F_VID_IF_BRIDGE; err =3D media_entity_pads_init(&sd->entity, 1, &state->pad); if (err < 0) goto err_hdl; =20 - state->mbus_fmt_code =3D MEDIA_BUS_FMT_RGB888_1X24; + state->mbus_fmt_code =3D MEDIA_BUS_FMT_BGR888_1X24; =20 sd->dev =3D &client->dev; =20 mutex_init(&state->confctl_mutex); =20 --=20 2.50.1 From nobody Thu Oct 2 11:49:16 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B8E812EC0B9; Wed, 17 Sep 2025 11:16:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758107797; cv=none; b=lfiiQc6TJfLk/OimSsPDeNvXKW5rkyZNIHK3DdbwpCAq8zMsQvvpNPX65yTH+YsPZLFhEc9rMNVy46k4otRKKhui3LwbLhhTCOa1l05hDkGdXdGrsK5Bj+3UcN51yPhEa6cJG1A2EkAzsb+QmvwcX/6Pt8W0Us8S23mb71iLeoc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758107797; c=relaxed/simple; bh=Y+3nIrnvAgbnHI5g9PJ6WJ/KzCKFqJfuSMVVefbpSho=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O7X0m/WsqfxRHBm7oTpfAU+EZoEpOU3cQ9scpIrFuXiN3FOFfg+7B6y3sMzh9ueM4dLq+XUB69pmFShdLtABcfALM8HbSiighd2OJJ1Qz9xBxHpMdVK6YTgkX6JwBcfYYkCTFVtgQp4cAPgBeLwQGeM8gvsjekhwwwMK4rq4tHc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eosiQvRq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eosiQvRq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DAEEEC4CEF5; Wed, 17 Sep 2025 11:16:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758107797; bh=Y+3nIrnvAgbnHI5g9PJ6WJ/KzCKFqJfuSMVVefbpSho=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=eosiQvRq93/I0qbVOx7KCYCNCQ24Pki1pJ4jPP9OFmkQDG1PrlHw+X7sZBhSJ6v8u HuXXU09bgoqrDwUr59yAoWiPsI1lNRwSVWT7YaoO8t8SbmUmsWo692bmHlWt9XxKMf iuKYGrHly3HmcyZqBklZC//2sH3cn4GQyF0K8W7oZAZ1Xf9a+6TVZVQtNFLOVK6TAN zMbftgn3Tl2vt6GI3PL34iMY5uO8eps/6NisIWO1nugRexye6P3+tCTbC2YHfVFbuo wQJZSYEfYjXPF+Muf//8EgiTO6ZIGKqeTWNecoAU+neR7q4gaGddH8gzzXCd2kdzDs oNcqyc+vwLSuQ== From: Maxime Ripard Date: Wed, 17 Sep 2025 13:16:14 +0200 Subject: [PATCH v3 4/4] media: gc2145: Fix the RGB MBUS format 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: <20250917-csi-bgr-rgb-v3-4-0145571b3aa4@kernel.org> References: <20250917-csi-bgr-rgb-v3-0-0145571b3aa4@kernel.org> In-Reply-To: <20250917-csi-bgr-rgb-v3-0-0145571b3aa4@kernel.org> To: Mauro Carvalho Chehab , Mats Randgaard , Alain Volmat , Sakari Ailus , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Hans Verkuil , Dave Stevenson , Maxime Ripard X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3387; i=mripard@kernel.org; h=from:subject:message-id; bh=Y+3nIrnvAgbnHI5g9PJ6WJ/KzCKFqJfuSMVVefbpSho=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDBmnZrR96y7SUXrs5tVudyVCzyVv87ppRXEJCgv/r6ovK +TYkbqoYyoLgzAng6yYIssTmbDTy9sXVznYr/wBM4eVCWQIAxenAExEtI+xhjOkklV0qtyEbh7h 7k0GD8oe8Jbb/Hiu2XLyy1PnNFmer4luosz1z17uelnauMzurv0kxoZVXBeU8ip3HVpiE85caJg 2LWO1vGi9+KepNi3HeJn5+NJ3uPAJ9y5RN8qSz1R0u5EgDwA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D 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 --- 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 559a851669aaf57cfba4d8834d04de9a3e3d91e0..88c3d92accb71108d23fa305d2c= cf5bca2dd1079 100644 --- a/drivers/media/i2c/gc2145.c +++ b/drivers/media/i2c/gc2145.c @@ -579,11 +579,11 @@ static const struct gc2145_format supported_formats[]= =3D { .colorspace =3D V4L2_COLORSPACE_SRGB, .datatype =3D MIPI_CSI2_DT_YUV422_8B, .output_fmt =3D 0x03, }, { - .code =3D MEDIA_BUS_FMT_RGB565_1X16, + .code =3D MEDIA_BUS_FMT_BGR565_1X16, .colorspace =3D V4L2_COLORSPACE_SRGB, .datatype =3D MIPI_CSI2_DT_RGB565, .output_fmt =3D 0x06, .switch_bit =3D true, }, @@ -613,10 +613,25 @@ static const struct gc2145_format supported_formats[]= =3D { .colorspace =3D V4L2_COLORSPACE_RAW, .datatype =3D MIPI_CSI2_DT_RAW8, .output_fmt =3D 0x17, .row_col_switch =3D 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 =3D MEDIA_BUS_FMT_RGB565_1X16, + .colorspace =3D V4L2_COLORSPACE_SRGB, + .datatype =3D MIPI_CSI2_DT_RGB565, + .output_fmt =3D 0x06, + .switch_bit =3D true, + }, }; =20 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(s= truct v4l2_ctrl *ctrl) } =20 static const struct gc2145_format * gc2145_get_format_code(struct gc2145 *gc2145, u32 code) { + struct i2c_client *client =3D v4l2_get_subdevdata(&gc2145->sd); unsigned int i; =20 + if (code =3D=3D MEDIA_BUS_FMT_RGB565_1X16) + dev_warn_once(&client->dev, + "RGB format isn't actually supported by the hardware. The applica= tion should be fixed to use BGR."); + for (i =3D 0; i < ARRAY_SIZE(supported_formats); i++) { if (supported_formats[i].code =3D=3D code) break; } =20 @@ -696,11 +716,11 @@ static int gc2145_init_state(struct v4l2_subdev *sd, struct v4l2_rect *crop; =20 /* Initialize pad format */ format =3D 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); =20 /* Initialize crop rectangle. */ crop =3D v4l2_subdev_state_get_crop(state, 0); *crop =3D supported_modes[0].crop; --=20 2.50.1