From nobody Thu Oct 2 20:42:56 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 17AC42E9730; Thu, 11 Sep 2025 09:15:41 +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=1757582142; cv=none; b=AsD8LrOUXPOMHXraiHKw/5l+I5DniNKcQ99+4nF6ai+AJ0+Wfe7BkOYiWhECcbhTZdCAMwsHCW/v6fhfNu6X7JlFYAXOvZUABZ8YvK+hzG0FxuAyrfkVA1n7cjj5/IOIlMKLbIkpU/l9kCP67L+Qmz9tPNcM/ufhgMVYxt04qKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757582142; c=relaxed/simple; bh=LIYL+FyEHAnJV8IzqdIcs1l232AGKZKm8aHRWU2Mccg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZKhRJsjLVhSjXoOU55No7HxZ2U6VsYpnNM5pSyM6QL1JtanpGTAz70c6x6s3llfBPLYWb/ZbxNQ6HJG2cl/nmo53/k+HJXrUxYWotdFTQl2zfVG+X9A76hW7WtGlLHZHnVxsmX72ne0btuRGmTNYdRuxXnrjYn9Wav3hJl+d0CE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tPKOM0XE; 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="tPKOM0XE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43AACC4CEF0; Thu, 11 Sep 2025 09:15:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757582141; bh=LIYL+FyEHAnJV8IzqdIcs1l232AGKZKm8aHRWU2Mccg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=tPKOM0XEZRe8teTyy2AS1RYyeZmorBJK9iyG9C6wj0N96AUun9kKHISMRfTlbqvUI FLWy4Y4m+pzi27eWZACMKsv7Eg0nBsv/goIVNCnineDbudk6x+7iYhpJARYsGxOthh G4GqXGsoJo20YS4K0KTQLZMVuUWJEPjZ2UjNJK7GJNBpXNQAUjUBiXeOrlrDfUdg/L LLIcJmjpl/EXq4oelJH3Hp85kJCtiM+XkuKVxO6hw/Uj9smZKAZQtFJz3ChfPr+DgL Ccjjg9FCOS8BGwTWDAnaHNtT4PzrR65sPApLZPPYt6wRjpnOha3atXTbppj1ogitIr p7d7vnVZ5xlAg== From: Maxime Ripard Date: Thu, 11 Sep 2025 11:15:32 +0200 Subject: [PATCH v2 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: <20250911-csi-bgr-rgb-v2-1-e6c6b10c1040@kernel.org> References: <20250911-csi-bgr-rgb-v2-0-e6c6b10c1040@kernel.org> In-Reply-To: <20250911-csi-bgr-rgb-v2-0-e6c6b10c1040@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=owGbwMvMwCmsHn9OcpHtvjLG02pJDBmHJpu9Pa2vt2il8hPT8+VsJva7N0w110yIUZdaG82wa /WTmNDNHVNZGIQ5GWTFFFmeyISdXt6+uMrBfuUPmDmsTCBDGLg4BWAiG2cx1qm/K2DN4Uur/uxy /4eudfSBbpuuHMm2U39nHln3/vj1V2KVexttVlvvFnMXqks8cUe0i7HhJ49GRX7Cn6NFQkt8L+1 yjnxs8PXuY0NNt9X73pkGNxWasbAXLwqq0nlnO9dv3ZmXDukA 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 20:42:56 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 CFD1B2E92BB; Thu, 11 Sep 2025 09:15:44 +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=1757582144; cv=none; b=nyGlkSGDOqBJ5UX8CQTbMxmaJ0ZREFjpKfQCD4wFUZHSSyVWJOfMlp8WBcyzvOlAVBSSDrYq1QTw7+WdnTehb7B+bcQ3M4OfuMyWnRYjbu89KucHHWgCF6MI9WMlXAZowp58X+qUwhFjFh8BepoECMn8bf8vACu7NWvMpqk4fOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757582144; c=relaxed/simple; bh=vtTI7iW2ovg2Lmmj3juW68JND8KyxijKZTrPOxRQSL8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nKzkLS7lk+KKhJdW+sYZ8Cr1jV+OiJ2fgbuSxZgWgHkOp/i5SegfY3DOxtS6r9stWEXRbzkCyZk0/e3COz/75NJxLKST/l3LsI0CQbFioSKj2bn3blhvXODeukU45VobXxnlWJQwkdNrIakFQO0XoF6icgcij0ZuRrOkd0YS58M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X6JxS+vE; 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="X6JxS+vE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E6F2C4CEF1; Thu, 11 Sep 2025 09:15:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757582144; bh=vtTI7iW2ovg2Lmmj3juW68JND8KyxijKZTrPOxRQSL8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=X6JxS+vErz5m+mvx0whoo52Reu2gmATCag73v5ZDXHtMl4mqjIctcz7ubZXpyo2bJ nX2+IYgmu9ZsuvgUPnk0eTP/mwB7eM/nSknImNYZ6W5cM+hml7mURIDWpcKQDVEAd+ KCx+ZM/+GRaE2usrFeRZtN4+7su9PUSVyIhRoH+rMv2wQ/vXY53MPNeyVPNKf4k6gR Kq0j8g+QCU9WrIQRY1qXgCPdQIp2dqTYaVI1/Fluanc79mywf/Vi8izKg/mmNjVvQ4 oelDrZtIe1goDnB17Klmgi885d3PPRnFiy0BW8ghGKtpTiD4NMjOM/ZMfIJw5B4oRA hXiyKTzEhtGRQ== From: Maxime Ripard Date: Thu, 11 Sep 2025 11:15:33 +0200 Subject: [PATCH v2 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: <20250911-csi-bgr-rgb-v2-2-e6c6b10c1040@kernel.org> References: <20250911-csi-bgr-rgb-v2-0-e6c6b10c1040@kernel.org> In-Reply-To: <20250911-csi-bgr-rgb-v2-0-e6c6b10c1040@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=vtTI7iW2ovg2Lmmj3juW68JND8KyxijKZTrPOxRQSL8=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDBmHJps9P6wadfKQivladl2/lv211zsuvG61Mfn6ff7hS 3tDTRr+d0xlYRDmZJAVU2R5IhN2enn74ioH+5U/YOawMoEMYeDiFICJ8Ekw1tkvU2HJSHH8+rha 6uFrs97kd07Toz/uvnyjuHtXX5XnX251VcY7z/adOvpBfpFN3MNlHxnr9HkTdk6/XvLDh6t5t+3 qbqaoO6yn24+Ya1uqzVx+Le0Fa4C089bvOVPeVu/i23lSe30xAA== 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 RGB656 media bus code. That's a mistake, but since we don't have a BGR656 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 20:42:56 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 B1E6E2EA48B; Thu, 11 Sep 2025 09:15:47 +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=1757582148; cv=none; b=l65KG7JvWmsOIl1xf9l2rDMX6SjEBkxGvupXn+DruE4m0XPO9BQCygK6tAP6RCos/hcXRmmDuj1RlbyGieStQhJfsiTP+lrDren32FsSqAz3NSUoKzyuDKd2GogVhXJZkE8M0AjaoUnSD06hQQQrzTeCCG0jFdzcDjsCgWuOYKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757582148; c=relaxed/simple; bh=Yki5P3B26fSbEWVtA0gYNtsSH8/osnb1L1uGLNPqoR0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HAe7xEF6t+zS2kwcNB6LpCNkZHepDabCJQZ1uTja5LuIICXxWFlaEgg2Dq2o4d+Iw3QC0KNO4xOZ9TVo34X0DSZz7WKIRxJkyZB9vh3xKaSd83lExIsszXQqwQHtOyZqTOw9cv9sN+dzRvDmRtg2OMxHeVbgzr4rZJEBpZVKb2M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hx2hwlZK; 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="hx2hwlZK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA4A3C4CEF8; Thu, 11 Sep 2025 09:15:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757582147; bh=Yki5P3B26fSbEWVtA0gYNtsSH8/osnb1L1uGLNPqoR0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hx2hwlZKDC9txopcaNgcHodrC5R3IZkNggpwGJjnOF244/baGRXiVp0GfBrghV6H5 c8PGz6ET9LoDTegw4Xw5OepLt6rc8VZY8BskZ5BvznSn47RIJzI6FdtjdTE4nkh9Bc J0t8gnQ4QZuQo+WtEtwN02rRX9bAssx6V0k962jcB8GYe2lfKzDM/UA/HfmTtI3RRK frLixVWwEHVJC37PUrXAxdQKeJ38KLcIqd5fDxuVALk2EowgBqFMOObyc8qoMbfIVP h6xo7j9Tj8EfLc1sqr7qS+m8DL5RzH0ghFaONIafCjr1yfFceQOo9Yr3aBhJyOqlqJ Y5Toj4yN1oTUA== From: Maxime Ripard Date: Thu, 11 Sep 2025 11:15:34 +0200 Subject: [PATCH v2 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: <20250911-csi-bgr-rgb-v2-3-e6c6b10c1040@kernel.org> References: <20250911-csi-bgr-rgb-v2-0-e6c6b10c1040@kernel.org> In-Reply-To: <20250911-csi-bgr-rgb-v2-0-e6c6b10c1040@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=5256; i=mripard@kernel.org; h=from:subject:message-id; bh=Yki5P3B26fSbEWVtA0gYNtsSH8/osnb1L1uGLNPqoR0=; b=kA0DAAkTJ1/OGaI9vnYByyZiAGjCkzehPYw8TOBiJXU+kQmoUMauJtxh1SYU9EAfBhT2FCwxi oiVBAATCQAdFiEE5BxWy6eHo3pAP6n4J1/OGaI9vnYFAmjCkzcACgkQJ1/OGaI9vnZCjAGA8Xk/ p0NR1nsgH5KVwnwzZq3MEauJSerPfYe8xlWnHc1fn5uPEKA9jAfOmCc4HAIrAX4zH5IeoSq7oEZ fc0dtOP8vekw7B41IqZXnrvzth7Kfn56FsSAqK6QM+/pRVylmjtg= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D The tc358743 is an HDMI to MIPI-CSI2 bridge. It supports two of the three HDMI 1.4 video formats: RGB 4:4:4 and YCbCr 422. 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 | 51 ++++++++++++++++++++++++++++++++++++----= ---- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c index 1cc7636e446d77d7c6266ca86517496261d2b039..a3054cd823da4cf3db24c6b2bfb= f0fcaa43f2814 100644 --- a/drivers/media/i2c/tc358743.c +++ b/drivers/media/i2c/tc358743.c @@ -693,11 +693,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. + */ + v4l2_warn(sd, "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 +1364,28 @@ 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. + */ + fallthrough; + 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; + } =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 +1718,33 @@ 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: + fallthrough; case MEDIA_BUS_FMT_RGB888_1X24: return V4L2_COLORSPACE_SRGB; case MEDIA_BUS_FMT_UYVY8_1X16: return V4L2_COLORSPACE_SMPTE170M; default: @@ -1746,11 +1778,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 +2199,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 20:42:56 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 69A752EA485; Thu, 11 Sep 2025 09:15:50 +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=1757582150; cv=none; b=Z3PRPD2zNSij8kgppPBWMmzu7IiCWD9x23NjRSR39+Z2eOXjN0vNBFgOM5WmuLYMYLnVNrE5bs/CbKpcO/TyRJQGMbXZkYwOAskNyx/ubFSlwqSup+9mQzAenoa6UGoMVV2GQzpFOn14E9s9X7KAt0d5qOsgAy+xLwfei6h/Vbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757582150; c=relaxed/simple; bh=7kN8g8jWps+OAHrQ5Wj8PfMisBek8dcqdJrCMUM3QpY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DLYOoglO60J0C8Di12nWf8hwY3VvbOsKq9hkFqu/mSD75Xnkuxf0n0/dJsXgmSblT4I7tATSlobt6AmzHzuxtOMonyIR808IHnaofu6chXSPGp/DsaThFRk+fODNpa2pmZuSmW/9QUjJ8duxmsW5X521zeYq6kHI9SiHx3YqaB0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N9Uo4UU/; 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="N9Uo4UU/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94572C4CEFC; Thu, 11 Sep 2025 09:15:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757582149; bh=7kN8g8jWps+OAHrQ5Wj8PfMisBek8dcqdJrCMUM3QpY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=N9Uo4UU/N9uv+cQ+Cb+rSNCnWJJKX2SLbHpzkP2T2as7Mx/5mXBa8DDjCwWh69muI o+/E6kEDpYaobLs5PHIPDe4439adeDWoXwVekMNzF16du48zaLXOSZGMUqavSJDNqR sgCTqId0d2519pF6ChA8VI39v6EBjAtY2+kReR6LHdYxj2cGiyZjhbGKN8YakRZ7th cuvKcrLP0XnOIoYs5ZH9FOisgTrLocD43vdVJujhDgHKUJvaAS1T1gEqIn/aXy7GDK dgMnh+rDI7TCBg0aUE6FvQkAXzbAd7d9vRLimYL+zfL+wOntKzYVIhb5GEM/Iobosr zzNqwQD0Dlh9g== From: Maxime Ripard Date: Thu, 11 Sep 2025 11:15:35 +0200 Subject: [PATCH v2 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: <20250911-csi-bgr-rgb-v2-4-e6c6b10c1040@kernel.org> References: <20250911-csi-bgr-rgb-v2-0-e6c6b10c1040@kernel.org> In-Reply-To: <20250911-csi-bgr-rgb-v2-0-e6c6b10c1040@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=3305; i=mripard@kernel.org; h=from:subject:message-id; bh=7kN8g8jWps+OAHrQ5Wj8PfMisBek8dcqdJrCMUM3QpY=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDBmHJptfa3F4KzXplMkP17hmBt6Xu14u8JnNs3Jz6Nmln vu4/ulP75jKwiDMySArpsjyRCbs9PL2xVUO9it/wMxhZQIZwsDFKQATmfOPsWHOzuf3VkbsvGPT 1t+Tlac171xzWrsi4yrZ4Jj7M1qm6SmF799r4cq8NNHqgXoIWzTDVsb6ENbVO3z37Fa1u/5QJ/D udDHT87khbktYfHe1BS1SU/g2Keto/and377JXWSem3Zx4ssaAA== 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 | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/gc2145.c b/drivers/media/i2c/gc2145.c index 559a851669aaf57cfba4d8834d04de9a3e3d91e0..59a0e51c70c84fe1045701d246d= 02bb1cf97388c 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; @@ -660,10 +675,14 @@ static inline struct v4l2_subdev *gc2145_ctrl_to_sd(s= truct v4l2_ctrl *ctrl) static const struct gc2145_format * gc2145_get_format_code(struct gc2145 *gc2145, u32 code) { unsigned int i; =20 + if (code =3D=3D MEDIA_BUS_FMT_RGB565_1X16) + v4l2_warn(&gc2145->sd, + "RGB format isn't actually supported by the hardware. The application= 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 +715,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