From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 257B3334C22 for ; Tue, 27 Jan 2026 14:40:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524804; cv=none; b=eduV1IZqfEuEtjRJO/IMoWPvBbRRvguCNl1MFXamuazOPt04Uv5lEfX5ff27NkKsoAWI/if9MztqyvtlznQWfMb+MitlAgdMnEU2KEbcMvJ0QBJS2DirJ78N3naCngc8PyHS/8Ug9GVXLOcky9BcrjY8MTleOqJkhoyWXYptSYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524804; c=relaxed/simple; bh=r1EM2vfsDGfqJ4zPMIJDZKpb3Eeh0H1vaHxfyMbNz3E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V2THDQ4M25NhZ1itImB19Vim2EQKlBZcC9DhnWTwnkmSyIWL8cVaRhZXFBzCnb8r5bUPHkl1cWiB31Cmhsg9n8ywvU8gpcsc1cMXpfLd8zLjxnk1rHfIAGnsRSpHyG1vNVlR1KJmUCtPSgK/JCU3RjZJQ70E2x9gCRj2T47s6EI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkEY-0007YT-N3; Tue, 27 Jan 2026 15:39:58 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:10 +0100 Subject: [PATCH v3 01/27] media: dt-bindings: media: rockchip-rga: add rockchip,rk3588-rga3 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: <20260127-spu-rga3-v3-1-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add a new compatible for the RGA3 (Raster Graphic Acceleration 3) peripheral found on the RK3588 SoC. Also specify an iommu property, as the RGA3 contains the generic rockchip iommu. The RGA2 also has an iommu, but it's specific to the RGA2. The existing binding refers to the RGA2 peripheral. The RK3588 contains one RGA2 core and two RGA3 cores. Both feature a similar functionality of scaling, cropping and rotating of up to two input images into one output image. Key differences of the RGA3 are: - supports 10bit YUV output formats - supports 8x8 tiles and FBCD as inputs and outputs - supports BT2020 color space conversion - max output resolution of (8192-64)x(8192-64) - MMU can map up to 32G DDR RAM - fully planar formats (3 planes) are not supported - max scale up/down factor of 8 (RGA2 allows up to 16) Signed-off-by: Sven P=C3=BCschel --- .../devicetree/bindings/media/rockchip-rga.yaml | 19 +++++++++++++++= +++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/media/rockchip-rga.yaml b/Do= cumentation/devicetree/bindings/media/rockchip-rga.yaml index ac17cda65191b..7735d8794c719 100644 --- a/Documentation/devicetree/bindings/media/rockchip-rga.yaml +++ b/Documentation/devicetree/bindings/media/rockchip-rga.yaml @@ -9,7 +9,9 @@ title: Rockchip 2D raster graphic acceleration controller (= RGA) description: RGA is a standalone 2D raster graphic acceleration unit. It accelerates = 2D graphics operations, such as point/line drawing, image scaling, rotation, - BitBLT, alpha blending and image blur/sharpness. + BitBLT, alpha blending and image blur/sharpness. There exist two variants + named RGA2 and RGA3 that differ in the supported inputs/output formats, + the attached IOMMU and the supported operations on the input. =20 maintainers: - Jacob Chen @@ -20,6 +22,7 @@ properties: oneOf: - const: rockchip,rk3288-rga - const: rockchip,rk3399-rga + - const: rockchip,rk3588-rga3 - items: - enum: - rockchip,rk3228-rga @@ -45,6 +48,9 @@ properties: power-domains: maxItems: 1 =20 + iommus: + maxItems: 1 + resets: maxItems: 3 =20 @@ -54,6 +60,17 @@ properties: - const: axi - const: ahb =20 +allOf: +- if: + properties: + compatible: + contains: + enum: + - rockchip,rk3588-rga3 + then: + required: + - iommus + required: - compatible - reg --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 2EB0435B642 for ; Tue, 27 Jan 2026 14:40:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524806; cv=none; b=sRFmQs/G9WpjVIc/mOWZMbTWtW+bIVuf+lSCDFUmmG7bVcxmw2hbBu2OaT9fGrKeR7ksgc409AqyUaekmGvOYBKpA8tgHLkWHKNF6qKExRroKT7BoBHebiWz5Lha8HDfS9M5Z3zhp3vXU5bAeWRNu4RqdcdL6fW3tXQsxoc/E50= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524806; c=relaxed/simple; bh=icoHQejuB1lcpJEjCkE7OSLt3mDLOGkfFIlSQq0Xr7I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X7fMvmy6CTLs2/MyS0GdgqkIzLJGz/SPF2CV8epiFh3FOenamr5kD4rrKAp9Hk/5yYo4li43hr1bR4GgtId81+6TG4aZDGNd9bmaK6a2Mm1oXcb2ENV4y4vTk1e5kcbREwQ36C9tQSvcwMWt0pzzG5z0kdWckTVXTFAPfuw8NAs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkEa-0007YT-3Q; Tue, 27 Jan 2026 15:40:00 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:11 +0100 Subject: [PATCH v3 02/27] media: v4l2-common: sort RGB formats in v4l2_format_info 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: <20260127-spu-rga3-v3-2-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sort the RGB formats in v4l2_format_info to match the format definitions in include/uapi/linux/videodev2.h . Also introduce the same sections to partition the list of formats and align the format info in each section. The alignment of the 1 or 2 bytes RGB formats contains an additional space in preparation of adding the missing formats to the list, as for V4L2_PIX_FMT_ARGB555X an additional space is necessary. Signed-off-by: Sven P=C3=BCschel --- drivers/media/v4l2-core/v4l2-common.c | 54 +++++++++++++++++++------------= ---- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-cor= e/v4l2-common.c index 554c591e11133..49c1ec08e2eb3 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -245,33 +245,39 @@ EXPORT_SYMBOL_GPL(v4l2_s_parm_cap); const struct v4l2_format_info *v4l2_format_info(u32 format) { static const struct v4l2_format_info formats[] =3D { - /* RGB formats */ - { .format =3D V4L2_PIX_FMT_BGR24, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 3, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_RGB24, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 3, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_HSV24, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 3, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_BGR32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_XBGR32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_BGRX32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_RGB32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_XRGB32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_RGBX32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_HSV32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_ARGB32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_RGBA32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_ABGR32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_BGRA32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_RGB565, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_RGB565X, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_RGB555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_BGR666, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_BGR48_12, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 6, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_BGR48, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .me= m_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 6, 0, 0, 0 }, .bpp_div =3D {= 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_RGB48, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .me= m_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 6, 0, 0, 0 }, .bpp_div =3D {= 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_ABGR64_12, .pixel_enc =3D V4L2_PIXEL_ENC_RGB,= .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 8, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_RGBA1010102, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + /* RGB formats (1 or 2 bytes per pixel) */ + { .format =3D V4L2_PIX_FMT_RGB555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGB565, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGB565X, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + + /* RGB formats (3 or 4 bytes per pixel) */ + { .format =3D V4L2_PIX_FMT_BGR666, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_BGR24, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 3, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGB24, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 3, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_BGR32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ABGR32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_XBGR32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_BGRA32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_BGRX32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGB32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGBA32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGBX32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ARGB32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_XRGB32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGBX1010102, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGBA1010102, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_ARGB2101010, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, =20 + /* RGB formats (6 or 8 bytes per pixel) */ + { .format =3D V4L2_PIX_FMT_BGR48_12, .pixel_enc =3D V4L2_PIXEL_ENC_RGB,= .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 6, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_BGR48, .pixel_enc =3D V4L2_PIXEL_ENC_RGB,= .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 6, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGB48, .pixel_enc =3D V4L2_PIXEL_ENC_RGB,= .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 6, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ABGR64_12, .pixel_enc =3D V4L2_PIXEL_ENC_RGB,= .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 8, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + + /* HSV formats */ + { .format =3D V4L2_PIX_FMT_HSV24, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .me= m_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 3, 0, 0, 0 }, .bpp_div =3D {= 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_HSV32, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .me= m_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div =3D {= 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + /* YUV packed formats */ { .format =3D V4L2_PIX_FMT_YUYV, .pixel_enc =3D V4L2_PIXEL_ENC_YUV, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 2, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_YVYU, .pixel_enc =3D V4L2_PIXEL_ENC_YUV, .= mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div =3D= { 1, 1, 1, 1 }, .hdiv =3D 2, .vdiv =3D 1 }, --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 337CD35CB6F for ; Tue, 27 Jan 2026 14:40:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524807; cv=none; b=JPEQ3HAqjZyAlI4LNSjPaYA8wxi/9jglSYg849AzuVZFwg+SWQEmzKZeuTJ0VoxVPxFFY3C7miD5ZUbE8Pi/a+Arinxxu7ZghO1evraKUmnVpSkSRFo+gfydG/6G/zN0loawRXWFLzfetuy7ULDNwfRv3xtju5yy2JOLGmBL/A4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524807; c=relaxed/simple; bh=AuYJlg6TgiMolrpUqEMycXz8m3t2Q058f1bJSmSeV24=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B5fPTn+Pv2KPYlGUmXmKO3pyeQ2C8BuMBnoxZ/mSw6slRTU0uc6Rw8nFB5PdPrsw/9ikFmdWAsplUjUps3oL9ir7xfXjy8h6Q73mLw3TA7N+ePFDE/2gOylQrfWcGkr/noIokbK5fUzQkWxp421LK8/JbX5FbcdwE0aVpdGl5/4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkEb-0007YT-Ea; Tue, 27 Jan 2026 15:40:01 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:12 +0100 Subject: [PATCH v3 03/27] media: v4l2-common: add missing 1 and 2 byte RGB formats to v4l2_format_info 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: <20260127-spu-rga3-v3-3-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add all missing one and two byte RGB formats to v4l2_format_info. This allows drivers to more consistently use v4l2_format_info, as it now covers all currently defined RGB formats. Signed-off-by: Sven P=C3=BCschel --- drivers/media/v4l2-core/v4l2-common.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-cor= e/v4l2-common.c index 49c1ec08e2eb3..58a4b372cf5be 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -246,8 +246,29 @@ const struct v4l2_format_info *v4l2_format_info(u32 fo= rmat) { static const struct v4l2_format_info formats[] =3D { /* RGB formats (1 or 2 bytes per pixel) */ + { .format =3D V4L2_PIX_FMT_RGB332, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 1, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGB444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ARGB444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_XRGB444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGBA444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGBX444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ABGR444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_XBGR444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_BGRA444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_BGRX444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGB555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ARGB555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_XRGB555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGBA555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGBX555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ABGR555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_XBGR555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_BGRA555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_BGRX555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGB565, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGB555X, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ARGB555X, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_XRGB555X, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGB565X, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, =20 /* RGB formats (3 or 4 bytes per pixel) */ --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 E069A35772C for ; Tue, 27 Jan 2026 14:40:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524807; cv=none; b=IFY95k1cuavdnMf/tqOLhTnXAiV19kZfUreeskmJsG5uDh/ViKKFA1aEaVIfsZKk5VQ+IeMQKWfE24yGJ6tXJp54KutgBnFmdzUSRafCkiLfkK1LNZKyvMP/BhSxO0SvEdhGlamVB4nTbdl4v2XnPAiWkhyPtm9YkpcPo3dIDLs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524807; c=relaxed/simple; bh=x0Yjf61ZNYh29Ukk3STDrpuFjkdsDfhkpobB1j4jhps=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qZrwqX30Z1u+evJxMs0Lo4pg9SdmKfjG8mG4vtykpkWS4k7AjVeB8QPiM/wEyDqaUlGP1DC3HmgwV+I6G+MECIWst3NgtgocKpA127eVSnn50uRiHEUFC/BRKJzv1uGet5i8NtuMRyepRZ+HvpWMuG+xiOPEzUwfbyC/vDX6c8E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkEc-0007YT-OE; Tue, 27 Jan 2026 15:40:02 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:13 +0100 Subject: [PATCH v3 04/27] media: v4l2-common: add has_alpha to v4l2_format_info 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: <20260127-spu-rga3-v3-4-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add a has_alpha value to the v4l2_format_info struct to indicate if the format contains an alpha component. This information can currently not be queried in a generic way, but might be useful for potential drivers to properly setup alpha blending to copy or set the alpha value. The implementation is based on the drm_format_info implementation. Signed-off-by: Sven P=C3=BCschel --- drivers/media/v4l2-core/v4l2-common.c | 32 ++++++++++++++++---------------- include/media/v4l2-common.h | 2 ++ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-cor= e/v4l2-common.c index 58a4b372cf5be..2b5ccedeb6841 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -248,26 +248,26 @@ const struct v4l2_format_info *v4l2_format_info(u32 f= ormat) /* RGB formats (1 or 2 bytes per pixel) */ { .format =3D V4L2_PIX_FMT_RGB332, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 1, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGB444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_ARGB444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ARGB444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, { .format =3D V4L2_PIX_FMT_XRGB444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_RGBA444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGBA444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, { .format =3D V4L2_PIX_FMT_RGBX444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_ABGR444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ABGR444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, { .format =3D V4L2_PIX_FMT_XBGR444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_BGRA444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_BGRA444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, { .format =3D V4L2_PIX_FMT_BGRX444, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGB555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_ARGB555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ARGB555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, { .format =3D V4L2_PIX_FMT_XRGB555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_RGBA555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGBA555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, { .format =3D V4L2_PIX_FMT_RGBX555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_ABGR555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ABGR555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, { .format =3D V4L2_PIX_FMT_XBGR555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_BGRA555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_BGRA555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, { .format =3D V4L2_PIX_FMT_BGRX555, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGB565, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGB555X, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_ARGB555X, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ARGB555X, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, { .format =3D V4L2_PIX_FMT_XRGB555X, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGB565X, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, = .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 2, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, =20 @@ -276,24 +276,24 @@ const struct v4l2_format_info *v4l2_format_info(u32 f= ormat) { .format =3D V4L2_PIX_FMT_BGR24, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 3, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGB24, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 3, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_BGR32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_ABGR32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ABGR32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, { .format =3D V4L2_PIX_FMT_XBGR32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_BGRA32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_BGRA32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, { .format =3D V4L2_PIX_FMT_BGRX32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGB32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_RGBA32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGBA32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, { .format =3D V4L2_PIX_FMT_RGBX32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_ARGB32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ARGB32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, { .format =3D V4L2_PIX_FMT_XRGB32, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGBX1010102, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_RGBA1010102, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_ARGB2101010, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_RGBA1010102, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, + { .format =3D V4L2_PIX_FMT_ARGB2101010, .pixel_enc =3D V4L2_PIXEL_ENC_RG= B, .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 4, 0, 0, 0 }, .bpp_div= =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, =20 /* RGB formats (6 or 8 bytes per pixel) */ { .format =3D V4L2_PIX_FMT_BGR48_12, .pixel_enc =3D V4L2_PIXEL_ENC_RGB,= .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 6, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_BGR48, .pixel_enc =3D V4L2_PIXEL_ENC_RGB,= .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 6, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, { .format =3D V4L2_PIX_FMT_RGB48, .pixel_enc =3D V4L2_PIXEL_ENC_RGB,= .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 6, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, - { .format =3D V4L2_PIX_FMT_ABGR64_12, .pixel_enc =3D V4L2_PIXEL_ENC_RGB,= .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 8, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, + { .format =3D V4L2_PIX_FMT_ABGR64_12, .pixel_enc =3D V4L2_PIXEL_ENC_RGB,= .mem_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 8, 0, 0, 0 }, .bpp_div = =3D { 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1, .has_alpha =3D true }, =20 /* HSV formats */ { .format =3D V4L2_PIX_FMT_HSV24, .pixel_enc =3D V4L2_PIXEL_ENC_RGB, .me= m_planes =3D 1, .comp_planes =3D 1, .bpp =3D { 3, 0, 0, 0 }, .bpp_div =3D {= 1, 1, 1, 1 }, .hdiv =3D 1, .vdiv =3D 1 }, diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h index f8b1faced79c8..401d8506c24b5 100644 --- a/include/media/v4l2-common.h +++ b/include/media/v4l2-common.h @@ -520,6 +520,7 @@ enum v4l2_pixel_encoding { * @vdiv: Vertical chroma subsampling factor * @block_w: Per-plane macroblock pixel width (optional) * @block_h: Per-plane macroblock pixel height (optional) + * @has_alpha: Does the format embeds an alpha component? */ struct v4l2_format_info { u32 format; @@ -532,6 +533,7 @@ struct v4l2_format_info { u8 vdiv; u8 block_w[4]; u8 block_h[4]; + bool has_alpha; }; =20 static inline bool v4l2_is_format_rgb(const struct v4l2_format_info *f) --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 3046F35CB6E for ; Tue, 27 Jan 2026 14:40:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524807; cv=none; b=NwTMY3HwXlsyM++PHnre9LZFI+tL7zy5pPKxMQLMhPrv+JJMgAuKtgmxoXoqf1hzQSzxhpdVkgwVxL4+INSmX0RbUaF++Im6xNi507SmAfRkX9H/hHaGH9p8No2TpBMNHYF1yK7dXKpfgqBgu2MNiQRw3Ho0oG3TgQD2eK8iPSs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524807; c=relaxed/simple; bh=FE0q+9IWB9cdSzVXcVcA+rfDcDAvz7Z0AHtTsxTB21s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=twIUd6lJLdLJ6o+XiFDwSId/A1cEU1XYGc4AGQRy0UXU/xXexYDkmjVpwsclpefsUVoEeSJRAoQyF0jBcNulgSyB2kEzzDeye7agi1ZcHWImy+H4RQKlBqahliwJ2daZ5TeYSxrlsXTFUT3WGXP4h6KPxMEySjpJOH+SoWoqNo4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkEe-0007YT-6Z; Tue, 27 Jan 2026 15:40:04 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:14 +0100 Subject: [PATCH v3 05/27] media: v4l2-common: add v4l2_fill_pixfmt_mp_aligned helper 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: <20260127-spu-rga3-v3-5-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add a v4l2_fill_pixfmt_mp_aligned helper which allows the user to specify a custom stride alignment in bytes. This is necessary for hardware like the Rockchip RGA3, which requires the stride value to be aligned to a 16 bytes boundary. Signed-off-by: Sven P=C3=BCschel --- drivers/media/v4l2-core/v4l2-common.c | 45 +++++++++++++++++++++++++------= ---- include/media/v4l2-common.h | 4 ++++ 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-cor= e/v4l2-common.c index 2b5ccedeb6841..e61506ead9150 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -431,14 +431,15 @@ static inline unsigned int v4l2_format_block_height(c= onst struct v4l2_format_inf } =20 static inline unsigned int v4l2_format_plane_stride(const struct v4l2_form= at_info *info, int plane, - unsigned int width) + unsigned int width, u8 byte_alignment) { unsigned int hdiv =3D plane ? info->hdiv : 1; unsigned int aligned_width =3D ALIGN(width, v4l2_format_block_width(info, plane)); =20 - return DIV_ROUND_UP(aligned_width, hdiv) * - info->bpp[plane] / info->bpp_div[plane]; + return ALIGN(DIV_ROUND_UP(aligned_width, hdiv) * info->bpp[plane] / + info->bpp_div[plane], + byte_alignment); } =20 static inline unsigned int v4l2_format_plane_height(const struct v4l2_form= at_info *info, int plane, @@ -452,9 +453,10 @@ static inline unsigned int v4l2_format_plane_height(co= nst struct v4l2_format_inf } =20 static inline unsigned int v4l2_format_plane_size(const struct v4l2_format= _info *info, int plane, - unsigned int width, unsigned int height) + unsigned int width, unsigned int height, + u8 stride_alignment) { - return v4l2_format_plane_stride(info, plane, width) * + return v4l2_format_plane_stride(info, plane, width, stride_alignment) * v4l2_format_plane_height(info, plane, height); } =20 @@ -475,8 +477,9 @@ void v4l2_apply_frmsize_constraints(u32 *width, u32 *he= ight, } EXPORT_SYMBOL_GPL(v4l2_apply_frmsize_constraints); =20 -int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, - u32 pixelformat, u32 width, u32 height) +int v4l2_fill_pixfmt_mp_aligned(struct v4l2_pix_format_mplane *pixfmt, + u32 pixelformat, u32 width, u32 height, + u8 stride_alignment) { const struct v4l2_format_info *info; struct v4l2_plane_pix_format *plane; @@ -493,23 +496,41 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane= *pixfmt, =20 if (info->mem_planes =3D=3D 1) { plane =3D &pixfmt->plane_fmt[0]; - plane->bytesperline =3D v4l2_format_plane_stride(info, 0, width); + /* + * In case of multiple planes the stride of the other planes + * is derived from the y stride. To avoid breaking the stride + * alignment for the non y plane, multiply it by 2. + */ + if (info->comp_planes > 1) + stride_alignment *=3D 2; + plane->bytesperline =3D v4l2_format_plane_stride(info, 0, width, + stride_alignment); plane->sizeimage =3D 0; =20 for (i =3D 0; i < info->comp_planes; i++) plane->sizeimage +=3D - v4l2_format_plane_size(info, i, width, height); + v4l2_format_plane_size(info, i, width, height, + stride_alignment); } else { for (i =3D 0; i < info->comp_planes; i++) { plane =3D &pixfmt->plane_fmt[i]; plane->bytesperline =3D - v4l2_format_plane_stride(info, i, width); + v4l2_format_plane_stride(info, i, width, + stride_alignment); plane->sizeimage =3D plane->bytesperline * v4l2_format_plane_height(info, i, height); } } return 0; } +EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt_mp_aligned); + +int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, + u32 pixelformat, u32 width, u32 height) +{ + return v4l2_fill_pixfmt_mp_aligned(pixfmt, pixelformat, + width, height, 1); +} EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt_mp); =20 int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, @@ -529,12 +550,12 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, = u32 pixelformat, pixfmt->width =3D width; pixfmt->height =3D height; pixfmt->pixelformat =3D pixelformat; - pixfmt->bytesperline =3D v4l2_format_plane_stride(info, 0, width); + pixfmt->bytesperline =3D v4l2_format_plane_stride(info, 0, width, 1); pixfmt->sizeimage =3D 0; =20 for (i =3D 0; i < info->comp_planes; i++) pixfmt->sizeimage +=3D - v4l2_format_plane_size(info, i, width, height); + v4l2_format_plane_size(info, i, width, height, 1); return 0; } EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt); diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h index 401d8506c24b5..edd416178c333 100644 --- a/include/media/v4l2-common.h +++ b/include/media/v4l2-common.h @@ -558,6 +558,10 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u= 32 pixelformat, u32 width, u32 height); int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, u32 pixelfo= rmat, u32 width, u32 height); +/* @stride_alignment is a power of 2 value in bytes */ +int v4l2_fill_pixfmt_mp_aligned(struct v4l2_pix_format_mplane *pixfmt, + u32 pixelformat, u32 width, u32 height, + u8 stride_alignment); =20 /** * v4l2_get_link_freq - Get link rate from transmitter --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 60BD8356A23 for ; Tue, 27 Jan 2026 14:40:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524809; cv=none; b=aE+V+La8aEg4W2qgfWQ4LvsHc7DRm2kICfE6VxSt+wVOeA3+zIGxrs5bUrlljfC96O4s0SO+FSl0WB7l4Tx9DVuoSmBSsWRQB7TjtUHQRisy/tIjPLkOBWQ8z9rKeSfSg+YCdMvHEftOVfKaak7y+WNMTv306PmHsMqWza+Xbzc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524809; c=relaxed/simple; bh=nPr/yFMr7sD7yVKE0J0oTZ5E/lqngZX18lzQlxnrkhA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=awkwxhD/TUN9YKDljK6HZnyR1VkcKHlUYY5jzW3it1PeuIncF1ITjZDxPcx+iOOg6l8LvYLQi26nzoQl6jj/IqycdSgQPwyM5XlRcZ7pDUSYCbbR1vlqG1QT4bscwZW5Uzxap70dfpnmCMzGJPCYZ4UGL9McgfNdmfuNdfA+0nE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkEg-0007YT-BX; Tue, 27 Jan 2026 15:40:06 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:15 +0100 Subject: [PATCH v3 06/27] media: rockchip: rga: use clk_bulk api 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: <20260127-spu-rga3-v3-6-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Use the clk_bulk API to avoid code duplication for each of the three clocks. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 65 ++++-----------------------= ---- drivers/media/platform/rockchip/rga/rga.h | 6 +-- 2 files changed, 11 insertions(+), 60 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 43f6a8d993811..338c7796490bc 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -698,48 +698,10 @@ static const struct video_device rga_videodev =3D { .device_caps =3D V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING, }; =20 -static int rga_enable_clocks(struct rockchip_rga *rga) -{ - int ret; - - ret =3D clk_prepare_enable(rga->sclk); - if (ret) { - dev_err(rga->dev, "Cannot enable rga sclk: %d\n", ret); - return ret; - } - - ret =3D clk_prepare_enable(rga->aclk); - if (ret) { - dev_err(rga->dev, "Cannot enable rga aclk: %d\n", ret); - goto err_disable_sclk; - } - - ret =3D clk_prepare_enable(rga->hclk); - if (ret) { - dev_err(rga->dev, "Cannot enable rga hclk: %d\n", ret); - goto err_disable_aclk; - } - - return 0; - -err_disable_aclk: - clk_disable_unprepare(rga->aclk); -err_disable_sclk: - clk_disable_unprepare(rga->sclk); - - return ret; -} - -static void rga_disable_clocks(struct rockchip_rga *rga) -{ - clk_disable_unprepare(rga->sclk); - clk_disable_unprepare(rga->hclk); - clk_disable_unprepare(rga->aclk); -} - static int rga_parse_dt(struct rockchip_rga *rga) { struct reset_control *core_rst, *axi_rst, *ahb_rst; + int ret; =20 core_rst =3D devm_reset_control_get(rga->dev, "core"); if (IS_ERR(core_rst)) { @@ -771,23 +733,12 @@ static int rga_parse_dt(struct rockchip_rga *rga) udelay(1); reset_control_deassert(ahb_rst); =20 - rga->sclk =3D devm_clk_get(rga->dev, "sclk"); - if (IS_ERR(rga->sclk)) { - dev_err(rga->dev, "failed to get sclk clock\n"); - return PTR_ERR(rga->sclk); - } - - rga->aclk =3D devm_clk_get(rga->dev, "aclk"); - if (IS_ERR(rga->aclk)) { - dev_err(rga->dev, "failed to get aclk clock\n"); - return PTR_ERR(rga->aclk); - } - - rga->hclk =3D devm_clk_get(rga->dev, "hclk"); - if (IS_ERR(rga->hclk)) { - dev_err(rga->dev, "failed to get hclk clock\n"); - return PTR_ERR(rga->hclk); + ret =3D devm_clk_bulk_get_all(rga->dev, &rga->clks); + if (ret < 0) { + dev_err(rga->dev, "failed to get clocks\n"); + return ret; } + rga->num_clks =3D ret; =20 return 0; } @@ -935,7 +886,7 @@ static int __maybe_unused rga_runtime_suspend(struct de= vice *dev) { struct rockchip_rga *rga =3D dev_get_drvdata(dev); =20 - rga_disable_clocks(rga); + clk_bulk_disable_unprepare(rga->num_clks, rga->clks); =20 return 0; } @@ -944,7 +895,7 @@ static int __maybe_unused rga_runtime_resume(struct dev= ice *dev) { struct rockchip_rga *rga =3D dev_get_drvdata(dev); =20 - return rga_enable_clocks(rga); + return clk_bulk_prepare_enable(rga->num_clks, rga->clks); } =20 static const struct dev_pm_ops rga_pm =3D { diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 72a28b120fabf..2db10acecb405 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -6,6 +6,7 @@ #ifndef __RGA_H__ #define __RGA_H__ =20 +#include #include #include #include @@ -81,9 +82,8 @@ struct rockchip_rga { struct device *dev; struct regmap *grf; void __iomem *regs; - struct clk *sclk; - struct clk *aclk; - struct clk *hclk; + struct clk_bulk_data *clks; + int num_clks; struct rockchip_rga_version version; =20 /* vfd lock */ --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 AB9DC35CB6F for ; Tue, 27 Jan 2026 14:40:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524812; cv=none; b=N5bNCJQRRE+vmTjZqO2wgTyvPdr8fMgrqTaHdF4p5EGQZMLgJx4044ctuNp0NWJWqaBZXsJfYiVrw+yJD9MG+VpHxRnE1cTOsT9yaYX81CIFTJWRE2JDdMX3zGyPnSjsvgb36xcCJron3wwjM5a87yrMqeGN6roTdep5DZMHJ58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524812; c=relaxed/simple; bh=JOwvDeJCyzrvK5jl/gxmF1CyRNmJLl778mr+and9tyU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qAmNNNwOOCzMFLnCCWMeDdcOPAbtUuWWOPCv5lOS1zfTxCrmZGLzb89Y8YtZdC3vCjJN3pHEDawi32uYDPfEfyj1IrVTpsUsl6r9LjsgLQNXmHUXMYsOqQT3YR41MC4ktMuljVOCDFxSt7Jy3tHIwdm44qlcl34uYwc9VHXGZH0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkEi-0007YT-FO; Tue, 27 Jan 2026 15:40:08 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:16 +0100 Subject: [PATCH v3 07/27] media: rockchip: rga: use stride for offset calculation 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: <20260127-spu-rga3-v3-7-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Use the stride instead of the width for the offset calculation. This ensures that the bytesperline value doesn't need to match the width value of the image. Furthermore this patch removes the dependency on the uv_factor property and instead reuses the v4l2_format_info to determine the correct division factor. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-buf.c | 14 +++++++++----- drivers/media/platform/rockchip/rga/rga.c | 16 ---------------- drivers/media/platform/rockchip/rga/rga.h | 1 - 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/= platform/rockchip/rga/rga-buf.c index bb575873f2b24..65fc0d5b4aa10 100644 --- a/drivers/media/platform/rockchip/rga/rga-buf.c +++ b/drivers/media/platform/rockchip/rga/rga-buf.c @@ -14,7 +14,6 @@ #include #include =20 -#include "rga-hw.h" #include "rga.h" =20 static ssize_t fill_descriptors(struct rga_dma_desc *desc, size_t max_desc, @@ -95,14 +94,19 @@ static int rga_buf_init(struct vb2_buffer *vb) return 0; } =20 -static int get_plane_offset(struct rga_frame *f, int plane) +static int get_plane_offset(struct rga_frame *f, + const struct v4l2_format_info *info, + int plane) { + u32 stride =3D f->pix.plane_fmt[0].bytesperline; + if (plane =3D=3D 0) return 0; if (plane =3D=3D 1) - return f->width * f->height; + return stride * f->height; if (plane =3D=3D 2) - return f->width * f->height + (f->width * f->height / f->fmt->uv_factor); + return stride * f->height + + (stride * f->height / info->hdiv / info->vdiv); =20 return -EINVAL; } @@ -148,7 +152,7 @@ static int rga_buf_prepare(struct vb2_buffer *vb) /* Fill the remaining planes */ info =3D v4l2_format_info(f->fmt->fourcc); for (i =3D info->mem_planes; i < info->comp_planes; i++) - offsets[i] =3D get_plane_offset(f, i); + offsets[i] =3D get_plane_offset(f, info, i); =20 rbuf->offset.y_off =3D offsets[0]; rbuf->offset.u_off =3D offsets[1]; diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 338c7796490bc..da4d5bec7a0a5 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -190,7 +190,6 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_ALPHA_SWAP, .hw_format =3D RGA_COLOR_FMT_ABGR8888, .depth =3D 32, - .uv_factor =3D 1, .y_div =3D 1, .x_div =3D 1, }, @@ -199,7 +198,6 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_ABGR8888, .depth =3D 32, - .uv_factor =3D 1, .y_div =3D 1, .x_div =3D 1, }, @@ -208,7 +206,6 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_XBGR8888, .depth =3D 32, - .uv_factor =3D 1, .y_div =3D 1, .x_div =3D 1, }, @@ -217,7 +214,6 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_RGB888, .depth =3D 24, - .uv_factor =3D 1, .y_div =3D 1, .x_div =3D 1, }, @@ -226,7 +222,6 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_RGB888, .depth =3D 24, - .uv_factor =3D 1, .y_div =3D 1, .x_div =3D 1, }, @@ -235,7 +230,6 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_ABGR4444, .depth =3D 16, - .uv_factor =3D 1, .y_div =3D 1, .x_div =3D 1, }, @@ -244,7 +238,6 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_ABGR1555, .depth =3D 16, - .uv_factor =3D 1, .y_div =3D 1, .x_div =3D 1, }, @@ -253,7 +246,6 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_BGR565, .depth =3D 16, - .uv_factor =3D 1, .y_div =3D 1, .x_div =3D 1, }, @@ -262,7 +254,6 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_UV_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV420SP, .depth =3D 12, - .uv_factor =3D 4, .y_div =3D 2, .x_div =3D 1, }, @@ -271,7 +262,6 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_UV_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV422SP, .depth =3D 16, - .uv_factor =3D 2, .y_div =3D 1, .x_div =3D 1, }, @@ -280,7 +270,6 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV420SP, .depth =3D 12, - .uv_factor =3D 4, .y_div =3D 2, .x_div =3D 1, }, @@ -289,7 +278,6 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV420SP, .depth =3D 12, - .uv_factor =3D 4, .y_div =3D 2, .x_div =3D 1, }, @@ -298,7 +286,6 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV422SP, .depth =3D 16, - .uv_factor =3D 2, .y_div =3D 1, .x_div =3D 1, }, @@ -307,7 +294,6 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV420P, .depth =3D 12, - .uv_factor =3D 4, .y_div =3D 2, .x_div =3D 2, }, @@ -316,7 +302,6 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV422P, .depth =3D 16, - .uv_factor =3D 2, .y_div =3D 1, .x_div =3D 2, }, @@ -325,7 +310,6 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_UV_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV420P, .depth =3D 12, - .uv_factor =3D 4, .y_div =3D 2, .x_div =3D 2, }, diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 2db10acecb405..477cf5b62bbb2 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -17,7 +17,6 @@ struct rga_fmt { u32 fourcc; int depth; - u8 uv_factor; u8 y_div; u8 x_div; u8 color_swap; --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 3B7DE35E55E for ; Tue, 27 Jan 2026 14:40:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524815; cv=none; b=GO5QP0CD33eyK/3rsssKO5oYxUXgAIiPOKwNTd3bSnODLs24gJlYQ4UgQ56y0iXMRuhefRvgPcHOB4PjzmGF7D5lyMy6OAo5qmZAap8nKXwCi5ADO0nyOlg0DmHWts/f5nkrBE7ym9ySagKKrvG2RUxHmol1fDt4/KkqOBkwgwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524815; c=relaxed/simple; bh=f8lrm6KTwShKMSYBAYA3sfrVYl4Lr0G0oKCR0bEiokg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EufeJJqmy+oKrl2RAe1pRNV8yDCDBbQiueOz8XO414rw7XTbR/g24IpNBvAED+8YupPCFhkiprHFYBQvt8XKStKen7YU2AruvYZcFomj4FhbsPjbBBIO+XopQMN5tB5vGOmnSGOOvlE2aWlt5THtzknWPsoSX88UC825npnEK+Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkEk-0007YT-Nh; Tue, 27 Jan 2026 15:40:10 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:17 +0100 Subject: [PATCH v3 08/27] media: rockchip: rga: remove redundant rga_frame variables 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: <20260127-spu-rga3-v3-8-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= , Nicolas Dufresne X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Remove the redundant rga_frame variables width, height and color space. The value of these variables is already contained in the pix member of rga_frame. The code also keeps these values in sync. Therefore drop them in favor of the existing pix member. Reviewed-by: Nicolas Dufresne Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-buf.c | 6 ++--- drivers/media/platform/rockchip/rga/rga-hw.c | 6 ++--- drivers/media/platform/rockchip/rga/rga.c | 32 ++++++++++-------------= ---- drivers/media/platform/rockchip/rga/rga.h | 5 ----- 4 files changed, 18 insertions(+), 31 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/= platform/rockchip/rga/rga-buf.c index 65fc0d5b4aa10..ffc6162b2e681 100644 --- a/drivers/media/platform/rockchip/rga/rga-buf.c +++ b/drivers/media/platform/rockchip/rga/rga-buf.c @@ -103,10 +103,10 @@ static int get_plane_offset(struct rga_frame *f, if (plane =3D=3D 0) return 0; if (plane =3D=3D 1) - return stride * f->height; + return stride * f->pix.height; if (plane =3D=3D 2) - return stride * f->height + - (stride * f->height / info->hdiv / info->vdiv); + return stride * f->pix.height + + (stride * f->pix.height / info->hdiv / info->vdiv); =20 return -EINVAL; } diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index 43ed742a16492..f1d5237472941 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -53,7 +53,7 @@ rga_get_addr_offset(struct rga_frame *frm, struct rga_add= r_offset *offset, x_div =3D frm->fmt->x_div; y_div =3D frm->fmt->y_div; uv_stride =3D frm->stride / x_div; - pixel_width =3D frm->stride / frm->width; + pixel_width =3D frm->stride / frm->pix.width; =20 lt->y_off =3D offset->y_off + y * frm->stride + x * pixel_width; lt->u_off =3D offset->u_off + (y / y_div) * uv_stride + x / x_div; @@ -191,7 +191,7 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx) =20 if (RGA_COLOR_FMT_IS_YUV(ctx->in.fmt->hw_format) && RGA_COLOR_FMT_IS_RGB(ctx->out.fmt->hw_format)) { - switch (ctx->in.colorspace) { + switch (ctx->in.pix.colorspace) { case V4L2_COLORSPACE_REC709: src_info.data.csc_mode =3D RGA_SRC_CSC_MODE_BT709_R0; break; @@ -203,7 +203,7 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx) =20 if (RGA_COLOR_FMT_IS_RGB(ctx->in.fmt->hw_format) && RGA_COLOR_FMT_IS_YUV(ctx->out.fmt->hw_format)) { - switch (ctx->out.colorspace) { + switch (ctx->out.pix.colorspace) { case V4L2_COLORSPACE_REC709: dst_info.data.csc_mode =3D RGA_SRC_CSC_MODE_BT709_R0; break; diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index da4d5bec7a0a5..20d1d9cb7625d 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -329,9 +329,6 @@ static struct rga_fmt *rga_fmt_find(u32 pixelformat) } =20 static struct rga_frame def_frame =3D { - .width =3D DEFAULT_WIDTH, - .height =3D DEFAULT_HEIGHT, - .colorspace =3D V4L2_COLORSPACE_DEFAULT, .crop.left =3D 0, .crop.top =3D 0, .crop.width =3D DEFAULT_WIDTH, @@ -363,9 +360,9 @@ static int rga_open(struct file *file) ctx->out =3D def_frame; =20 v4l2_fill_pixfmt_mp(&ctx->in.pix, - ctx->in.fmt->fourcc, ctx->out.width, ctx->out.height); + ctx->in.fmt->fourcc, DEFAULT_WIDTH, DEFAULT_HEIGHT); v4l2_fill_pixfmt_mp(&ctx->out.pix, - ctx->out.fmt->fourcc, ctx->out.width, ctx->out.height); + ctx->out.fmt->fourcc, DEFAULT_WIDTH, DEFAULT_HEIGHT); =20 if (mutex_lock_interruptible(&rga->mutex)) { kfree(ctx); @@ -453,10 +450,8 @@ static int vidioc_g_fmt(struct file *file, void *priv,= struct v4l2_format *f) if (IS_ERR(frm)) return PTR_ERR(frm); =20 - v4l2_fill_pixfmt_mp(pix_fmt, frm->fmt->fourcc, frm->width, frm->height); - + *pix_fmt =3D frm->pix; pix_fmt->field =3D V4L2_FIELD_NONE; - pix_fmt->colorspace =3D frm->colorspace; =20 return 0; } @@ -505,27 +500,24 @@ static int vidioc_s_fmt(struct file *file, void *priv= , struct v4l2_format *f) frm =3D rga_get_frame(ctx, f->type); if (IS_ERR(frm)) return PTR_ERR(frm); - frm->width =3D pix_fmt->width; - frm->height =3D pix_fmt->height; frm->size =3D 0; for (i =3D 0; i < pix_fmt->num_planes; i++) frm->size +=3D pix_fmt->plane_fmt[i].sizeimage; frm->fmt =3D rga_fmt_find(pix_fmt->pixelformat); frm->stride =3D pix_fmt->plane_fmt[0].bytesperline; - frm->colorspace =3D pix_fmt->colorspace; =20 /* Reset crop settings */ frm->crop.left =3D 0; frm->crop.top =3D 0; - frm->crop.width =3D frm->width; - frm->crop.height =3D frm->height; + frm->crop.width =3D pix_fmt->width; + frm->crop.height =3D pix_fmt->height; =20 frm->pix =3D *pix_fmt; =20 v4l2_dbg(debug, 1, &rga->v4l2_dev, "[%s] fmt - %p4cc %dx%d (stride %d, sizeimage %d)\n", V4L2_TYPE_IS_OUTPUT(f->type) ? "OUTPUT" : "CAPTURE", - &frm->fmt->fourcc, frm->width, frm->height, + &frm->fmt->fourcc, pix_fmt->width, pix_fmt->height, frm->stride, frm->size); =20 for (i =3D 0; i < pix_fmt->num_planes; i++) { @@ -579,8 +571,8 @@ static int vidioc_g_selection(struct file *file, void *= priv, } else { s->r.left =3D 0; s->r.top =3D 0; - s->r.width =3D f->width; - s->r.height =3D f->height; + s->r.width =3D f->pix.width; + s->r.height =3D f->pix.height; } =20 return 0; @@ -629,8 +621,8 @@ static int vidioc_s_selection(struct file *file, void *= priv, return -EINVAL; } =20 - if (s->r.left + s->r.width > f->width || - s->r.top + s->r.height > f->height || + if (s->r.left + s->r.width > f->pix.width || + s->r.top + s->r.height > f->pix.height || s->r.width < MIN_WIDTH || s->r.height < MIN_HEIGHT) { v4l2_dbg(debug, 1, &rga->v4l2_dev, "unsupported crop value.\n"); return -EINVAL; @@ -821,8 +813,8 @@ static int rga_probe(struct platform_device *pdev) goto rel_m2m; } =20 - def_frame.stride =3D (def_frame.width * def_frame.fmt->depth) >> 3; - def_frame.size =3D def_frame.stride * def_frame.height; + def_frame.stride =3D (DEFAULT_WIDTH * def_frame.fmt->depth) >> 3; + def_frame.size =3D def_frame.stride * DEFAULT_HEIGHT; =20 ret =3D video_register_device(vfd, VFL_TYPE_VIDEO, -1); if (ret) { diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 477cf5b62bbb2..c4a3905a48f0d 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -24,11 +24,6 @@ struct rga_fmt { }; =20 struct rga_frame { - /* Original dimensions */ - u32 width; - u32 height; - u32 colorspace; - /* Crop */ struct v4l2_rect crop; =20 --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 62CBF34D4F6 for ; Tue, 27 Jan 2026 14:40:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524817; cv=none; b=XXnyhav3VvYwineWOidRFh0n+uAqOM9PUct5U1nwaS8wPukOQP9wCRJGIbU+Fhhd5mbTVt5MFcvl/sGJRnLvOIdXMWeKIUMOPs9+6oFIWKj6y+48+Z0Way4i3Ki/b5pOSNJnnb/611USPo/nsnOrr8ZR8e5/QDiOo7f+6fNZJHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524817; c=relaxed/simple; bh=i76+ZhA7uUnOTpJ826FpHqCzbtSaPcBMDvf50EJMVwg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ahy5RgCc58kgRn8CI6YTgPakjbVj/8Vm4rvnuJECCOXM/P/Vqu4OF/bxRZV69jto55CeDXc86+gHLUSFq7nuGbxbnYAsjaw16YlGQCL2GW78JMpSWo29NU+xZr55Tvu1I5A1hkIWtIsa8cxLGM88T8XVmsnVlUyRGlydGRRblUA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkEn-0007YT-1K; Tue, 27 Jan 2026 15:40:13 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:18 +0100 Subject: [PATCH v3 09/27] media: rockchip: rga: announce and sync colorimetry 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: <20260127-spu-rga3-v3-9-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Announce the capability to adjust the quantization and ycbcr_enc on the capture side and check if the SET_CSC flag is set when the colorimetry is changed. Furthermore copy the colorimetry from the output to the capture side to fix the currently failing v4l2-compliance tests, which expect exactly this behavior. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 37 +++++++++++++++++++++++++++= ++++ 1 file changed, 37 insertions(+) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 20d1d9cb7625d..cf9d5702598fa 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -437,6 +437,15 @@ static int vidioc_enum_fmt(struct file *file, void *pr= iv, struct v4l2_fmtdesc *f fmt =3D &formats[f->index]; f->pixelformat =3D fmt->fourcc; =20 + if (f->type !=3D V4L2_BUF_TYPE_VIDEO_CAPTURE && + f->type !=3D V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) + return 0; + + /* allow changing the quantization and xfer func for YUV formats */ + if (v4l2_is_format_yuv(v4l2_format_info(f->pixelformat))) + f->flags |=3D V4L2_FMT_FLAG_CSC_QUANTIZATION | + V4L2_FMT_FLAG_CSC_YCBCR_ENC; + return 0; } =20 @@ -459,8 +468,25 @@ static int vidioc_g_fmt(struct file *file, void *priv,= struct v4l2_format *f) static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_forma= t *f) { struct v4l2_pix_format_mplane *pix_fmt =3D &f->fmt.pix_mp; + struct rga_ctx *ctx =3D file_to_rga_ctx(file); struct rga_fmt *fmt; =20 + if (V4L2_TYPE_IS_CAPTURE(f->type)) { + const struct rga_frame *frm; + + frm =3D rga_get_frame(ctx, f->type); + if (IS_ERR(frm)) + return PTR_ERR(frm); + + if (!(pix_fmt->flags & V4L2_PIX_FMT_FLAG_SET_CSC)) { + pix_fmt->quantization =3D frm->pix.quantization; + pix_fmt->ycbcr_enc =3D frm->pix.ycbcr_enc; + } + /* disallow values not announced in vidioc_enum_fmt */ + pix_fmt->colorspace =3D frm->pix.colorspace; + pix_fmt->xfer_func =3D frm->pix.xfer_func; + } + fmt =3D rga_fmt_find(pix_fmt->pixelformat); if (!fmt) fmt =3D &formats[0]; @@ -506,6 +532,17 @@ static int vidioc_s_fmt(struct file *file, void *priv,= struct v4l2_format *f) frm->fmt =3D rga_fmt_find(pix_fmt->pixelformat); frm->stride =3D pix_fmt->plane_fmt[0].bytesperline; =20 + /* + * Copy colorimetry from output to capture as required by the + * v4l2-compliance tests + */ + if (V4L2_TYPE_IS_OUTPUT(f->type)) { + ctx->out.pix.colorspace =3D pix_fmt->colorspace; + ctx->out.pix.ycbcr_enc =3D pix_fmt->ycbcr_enc; + ctx->out.pix.quantization =3D pix_fmt->quantization; + ctx->out.pix.xfer_func =3D pix_fmt->xfer_func; + } + /* Reset crop settings */ frm->crop.left =3D 0; frm->crop.top =3D 0; --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 B312435F8C5 for ; Tue, 27 Jan 2026 14:40:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524819; cv=none; b=Btas3o9xkAF3zBcScS4mRy8gX1ok5d6EZVfRyq+xNS2q6ZFL/JphXOWWre+0NX8VxZ4NhBM9RNjPhMWz5p+oyFf21pwlronQtdF7wjU+JM4iNA8782cAjQqP9fwCdocoCaxo8eEWVi8polnNOGEOrPGIhY8XiMkbVu6uSKI1I3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524819; c=relaxed/simple; bh=DyomiX0gnvea6msBK8tQG5M3tCc+c31/ZoGYJN66V30=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KCziBrRyk/CG2dphHPHOVu5hPQ+UaLilrnHspLcOWOEs7yr9bvtG7FX1qfEfRq59M5ZlcvezrfwXKKHC0mYWpH16kEpf3i3UtO4dupugAvrOuJMkrywn9JeKJ4l86O5iS+p2nsms5e661W8B49HxAoX+oKcpc30VMzisN152NH0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkEp-0007YT-9B; Tue, 27 Jan 2026 15:40:15 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:19 +0100 Subject: [PATCH v3 10/27] media: rockchip: rga: move hw specific parts to a dedicated struct 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: <20260127-spu-rga3-v3-10-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= , Nicolas Dufresne X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org In preparation for the RGA3 unit, move RGA2 specific parts from rga.c to rga-hw.c and create a struct to reference the RGA2 specific functions and formats. This also allows to remove the rga-hw.h reference from the include list of the rga driver. Also document the command finish interrupt with a dedicated define. Reviewed-by: Nicolas Dufresne Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 166 ++++++++++++++++++++- drivers/media/platform/rockchip/rga/rga-hw.h | 5 +- drivers/media/platform/rockchip/rga/rga.c | 211 +++++------------------= ---- drivers/media/platform/rockchip/rga/rga.h | 23 ++- 4 files changed, 227 insertions(+), 178 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index f1d5237472941..c0218a71fee04 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -437,8 +437,8 @@ static void rga_cmd_set(struct rga_ctx *ctx, PAGE_SIZE, DMA_BIDIRECTIONAL); } =20 -void rga_hw_start(struct rockchip_rga *rga, - struct rga_vb_buffer *src, struct rga_vb_buffer *dst) +static void rga_hw_start(struct rockchip_rga *rga, + struct rga_vb_buffer *src, struct rga_vb_buffer *dst) { struct rga_ctx *ctx =3D rga->curr; =20 @@ -452,3 +452,165 @@ void rga_hw_start(struct rockchip_rga *rga, =20 rga_write(rga, RGA_CMD_CTRL, 0x1); } + +static bool rga_handle_irq(struct rockchip_rga *rga) +{ + int intr; + + intr =3D rga_read(rga, RGA_INT) & 0xf; + + rga_mod(rga, RGA_INT, intr << 4, 0xf << 4); + + return intr & RGA_INT_COMMAND_FINISHED; +} + +static void rga_get_version(struct rockchip_rga *rga) +{ + rga->version.major =3D (rga_read(rga, RGA_VERSION_INFO) >> 24) & 0xFF; + rga->version.minor =3D (rga_read(rga, RGA_VERSION_INFO) >> 20) & 0x0F; +} + +static struct rga_fmt formats[] =3D { + { + .fourcc =3D V4L2_PIX_FMT_ARGB32, + .color_swap =3D RGA_COLOR_ALPHA_SWAP, + .hw_format =3D RGA_COLOR_FMT_ABGR8888, + .depth =3D 32, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_ABGR32, + .color_swap =3D RGA_COLOR_RB_SWAP, + .hw_format =3D RGA_COLOR_FMT_ABGR8888, + .depth =3D 32, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_XBGR32, + .color_swap =3D RGA_COLOR_RB_SWAP, + .hw_format =3D RGA_COLOR_FMT_XBGR8888, + .depth =3D 32, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_RGB24, + .color_swap =3D RGA_COLOR_NONE_SWAP, + .hw_format =3D RGA_COLOR_FMT_RGB888, + .depth =3D 24, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_BGR24, + .color_swap =3D RGA_COLOR_RB_SWAP, + .hw_format =3D RGA_COLOR_FMT_RGB888, + .depth =3D 24, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_ARGB444, + .color_swap =3D RGA_COLOR_RB_SWAP, + .hw_format =3D RGA_COLOR_FMT_ABGR4444, + .depth =3D 16, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_ARGB555, + .color_swap =3D RGA_COLOR_RB_SWAP, + .hw_format =3D RGA_COLOR_FMT_ABGR1555, + .depth =3D 16, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_RGB565, + .color_swap =3D RGA_COLOR_RB_SWAP, + .hw_format =3D RGA_COLOR_FMT_BGR565, + .depth =3D 16, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV21, + .color_swap =3D RGA_COLOR_UV_SWAP, + .hw_format =3D RGA_COLOR_FMT_YUV420SP, + .depth =3D 12, + .y_div =3D 2, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV61, + .color_swap =3D RGA_COLOR_UV_SWAP, + .hw_format =3D RGA_COLOR_FMT_YUV422SP, + .depth =3D 16, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV12, + .color_swap =3D RGA_COLOR_NONE_SWAP, + .hw_format =3D RGA_COLOR_FMT_YUV420SP, + .depth =3D 12, + .y_div =3D 2, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV12M, + .color_swap =3D RGA_COLOR_NONE_SWAP, + .hw_format =3D RGA_COLOR_FMT_YUV420SP, + .depth =3D 12, + .y_div =3D 2, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV16, + .color_swap =3D RGA_COLOR_NONE_SWAP, + .hw_format =3D RGA_COLOR_FMT_YUV422SP, + .depth =3D 16, + .y_div =3D 1, + .x_div =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_YUV420, + .color_swap =3D RGA_COLOR_NONE_SWAP, + .hw_format =3D RGA_COLOR_FMT_YUV420P, + .depth =3D 12, + .y_div =3D 2, + .x_div =3D 2, + }, + { + .fourcc =3D V4L2_PIX_FMT_YUV422P, + .color_swap =3D RGA_COLOR_NONE_SWAP, + .hw_format =3D RGA_COLOR_FMT_YUV422P, + .depth =3D 16, + .y_div =3D 1, + .x_div =3D 2, + }, + { + .fourcc =3D V4L2_PIX_FMT_YVU420, + .color_swap =3D RGA_COLOR_UV_SWAP, + .hw_format =3D RGA_COLOR_FMT_YUV420P, + .depth =3D 12, + .y_div =3D 2, + .x_div =3D 2, + }, +}; + +const struct rga_hw rga2_hw =3D { + .formats =3D formats, + .num_formats =3D ARRAY_SIZE(formats), + .cmdbuf_size =3D RGA_CMDBUF_SIZE, + .min_width =3D MIN_WIDTH, + .max_width =3D MAX_WIDTH, + .min_height =3D MIN_HEIGHT, + .max_height =3D MAX_HEIGHT, + + .start =3D rga_hw_start, + .handle_irq =3D rga_handle_irq, + .get_version =3D rga_get_version, +}; diff --git a/drivers/media/platform/rockchip/rga/rga-hw.h b/drivers/media/p= latform/rockchip/rga/rga-hw.h index cc6bd7f5b0300..f4752aa823051 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.h +++ b/drivers/media/platform/rockchip/rga/rga-hw.h @@ -15,9 +15,6 @@ #define MIN_WIDTH 34 #define MIN_HEIGHT 34 =20 -#define DEFAULT_WIDTH 100 -#define DEFAULT_HEIGHT 100 - #define RGA_TIMEOUT 500 =20 /* Registers address */ @@ -178,6 +175,8 @@ #define RGA_ALPHA_COLOR_NORMAL 0 #define RGA_ALPHA_COLOR_MULTIPLY_CAL 1 =20 +#define RGA_INT_COMMAND_FINISHED 4 + /* Registers union */ union rga_mode_ctrl { unsigned int val; diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index cf9d5702598fa..21a3c6cd38dbc 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -25,7 +25,6 @@ #include #include =20 -#include "rga-hw.h" #include "rga.h" =20 static int debug; @@ -47,7 +46,7 @@ static void device_run(void *prv) =20 dst =3D v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); =20 - rga_hw_start(rga, vb_to_rga(src), vb_to_rga(dst)); + rga->hw->start(rga, vb_to_rga(src), vb_to_rga(dst)); =20 spin_unlock_irqrestore(&rga->ctrl_lock, flags); } @@ -55,13 +54,8 @@ static void device_run(void *prv) static irqreturn_t rga_isr(int irq, void *prv) { struct rockchip_rga *rga =3D prv; - int intr; =20 - intr =3D rga_read(rga, RGA_INT) & 0xf; - - rga_mod(rga, RGA_INT, intr << 4, 0xf << 4); - - if (intr & 0x04) { + if (rga->hw->handle_irq(rga)) { struct vb2_v4l2_buffer *src, *dst; struct rga_ctx *ctx =3D rga->curr; =20 @@ -184,158 +178,17 @@ static int rga_setup_ctrls(struct rga_ctx *ctx) return 0; } =20 -static struct rga_fmt formats[] =3D { - { - .fourcc =3D V4L2_PIX_FMT_ARGB32, - .color_swap =3D RGA_COLOR_ALPHA_SWAP, - .hw_format =3D RGA_COLOR_FMT_ABGR8888, - .depth =3D 32, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_ABGR32, - .color_swap =3D RGA_COLOR_RB_SWAP, - .hw_format =3D RGA_COLOR_FMT_ABGR8888, - .depth =3D 32, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_XBGR32, - .color_swap =3D RGA_COLOR_RB_SWAP, - .hw_format =3D RGA_COLOR_FMT_XBGR8888, - .depth =3D 32, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_RGB24, - .color_swap =3D RGA_COLOR_NONE_SWAP, - .hw_format =3D RGA_COLOR_FMT_RGB888, - .depth =3D 24, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_BGR24, - .color_swap =3D RGA_COLOR_RB_SWAP, - .hw_format =3D RGA_COLOR_FMT_RGB888, - .depth =3D 24, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_ARGB444, - .color_swap =3D RGA_COLOR_RB_SWAP, - .hw_format =3D RGA_COLOR_FMT_ABGR4444, - .depth =3D 16, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_ARGB555, - .color_swap =3D RGA_COLOR_RB_SWAP, - .hw_format =3D RGA_COLOR_FMT_ABGR1555, - .depth =3D 16, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_RGB565, - .color_swap =3D RGA_COLOR_RB_SWAP, - .hw_format =3D RGA_COLOR_FMT_BGR565, - .depth =3D 16, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_NV21, - .color_swap =3D RGA_COLOR_UV_SWAP, - .hw_format =3D RGA_COLOR_FMT_YUV420SP, - .depth =3D 12, - .y_div =3D 2, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_NV61, - .color_swap =3D RGA_COLOR_UV_SWAP, - .hw_format =3D RGA_COLOR_FMT_YUV422SP, - .depth =3D 16, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_NV12, - .color_swap =3D RGA_COLOR_NONE_SWAP, - .hw_format =3D RGA_COLOR_FMT_YUV420SP, - .depth =3D 12, - .y_div =3D 2, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_NV12M, - .color_swap =3D RGA_COLOR_NONE_SWAP, - .hw_format =3D RGA_COLOR_FMT_YUV420SP, - .depth =3D 12, - .y_div =3D 2, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_NV16, - .color_swap =3D RGA_COLOR_NONE_SWAP, - .hw_format =3D RGA_COLOR_FMT_YUV422SP, - .depth =3D 16, - .y_div =3D 1, - .x_div =3D 1, - }, - { - .fourcc =3D V4L2_PIX_FMT_YUV420, - .color_swap =3D RGA_COLOR_NONE_SWAP, - .hw_format =3D RGA_COLOR_FMT_YUV420P, - .depth =3D 12, - .y_div =3D 2, - .x_div =3D 2, - }, - { - .fourcc =3D V4L2_PIX_FMT_YUV422P, - .color_swap =3D RGA_COLOR_NONE_SWAP, - .hw_format =3D RGA_COLOR_FMT_YUV422P, - .depth =3D 16, - .y_div =3D 1, - .x_div =3D 2, - }, - { - .fourcc =3D V4L2_PIX_FMT_YVU420, - .color_swap =3D RGA_COLOR_UV_SWAP, - .hw_format =3D RGA_COLOR_FMT_YUV420P, - .depth =3D 12, - .y_div =3D 2, - .x_div =3D 2, - }, -}; - -#define NUM_FORMATS ARRAY_SIZE(formats) - -static struct rga_fmt *rga_fmt_find(u32 pixelformat) +static struct rga_fmt *rga_fmt_find(struct rockchip_rga *rga, u32 pixelfor= mat) { unsigned int i; =20 - for (i =3D 0; i < NUM_FORMATS; i++) { - if (formats[i].fourcc =3D=3D pixelformat) - return &formats[i]; + for (i =3D 0; i < rga->hw->num_formats; i++) { + if (rga->hw->formats[i].fourcc =3D=3D pixelformat) + return &rga->hw->formats[i]; } return NULL; } =20 -static struct rga_frame def_frame =3D { - .crop.left =3D 0, - .crop.top =3D 0, - .crop.width =3D DEFAULT_WIDTH, - .crop.height =3D DEFAULT_HEIGHT, - .fmt =3D &formats[0], -}; - struct rga_frame *rga_get_frame(struct rga_ctx *ctx, enum v4l2_buf_type ty= pe) { if (V4L2_TYPE_IS_OUTPUT(type)) @@ -350,6 +203,18 @@ static int rga_open(struct file *file) struct rockchip_rga *rga =3D video_drvdata(file); struct rga_ctx *ctx =3D NULL; int ret =3D 0; + u32 def_width =3D clamp(DEFAULT_WIDTH, rga->hw->min_width, rga->hw->max_w= idth); + u32 def_height =3D clamp(DEFAULT_HEIGHT, rga->hw->min_height, rga->hw->ma= x_height); + struct rga_frame def_frame =3D { + .crop.left =3D 0, + .crop.top =3D 0, + .crop.width =3D def_width, + .crop.height =3D def_height, + .fmt =3D &rga->hw->formats[0], + }; + + def_frame.stride =3D (def_width * def_frame.fmt->depth) >> 3; + def_frame.size =3D def_frame.stride * def_height; =20 ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) @@ -360,9 +225,9 @@ static int rga_open(struct file *file) ctx->out =3D def_frame; =20 v4l2_fill_pixfmt_mp(&ctx->in.pix, - ctx->in.fmt->fourcc, DEFAULT_WIDTH, DEFAULT_HEIGHT); + ctx->in.fmt->fourcc, def_width, def_height); v4l2_fill_pixfmt_mp(&ctx->out.pix, - ctx->out.fmt->fourcc, DEFAULT_WIDTH, DEFAULT_HEIGHT); + ctx->out.fmt->fourcc, def_width, def_height); =20 if (mutex_lock_interruptible(&rga->mutex)) { kfree(ctx); @@ -429,12 +294,13 @@ vidioc_querycap(struct file *file, void *priv, struct= v4l2_capability *cap) =20 static int vidioc_enum_fmt(struct file *file, void *priv, struct v4l2_fmtd= esc *f) { + struct rockchip_rga *rga =3D video_drvdata(file); struct rga_fmt *fmt; =20 - if (f->index >=3D NUM_FORMATS) + if (f->index >=3D rga->hw->num_formats) return -EINVAL; =20 - fmt =3D &formats[f->index]; + fmt =3D &rga->hw->formats[f->index]; f->pixelformat =3D fmt->fourcc; =20 if (f->type !=3D V4L2_BUF_TYPE_VIDEO_CAPTURE && @@ -469,6 +335,7 @@ static int vidioc_try_fmt(struct file *file, void *priv= , struct v4l2_format *f) { struct v4l2_pix_format_mplane *pix_fmt =3D &f->fmt.pix_mp; struct rga_ctx *ctx =3D file_to_rga_ctx(file); + const struct rga_hw *hw =3D ctx->rga->hw; struct rga_fmt *fmt; =20 if (V4L2_TYPE_IS_CAPTURE(f->type)) { @@ -487,14 +354,14 @@ static int vidioc_try_fmt(struct file *file, void *pr= iv, struct v4l2_format *f) pix_fmt->xfer_func =3D frm->pix.xfer_func; } =20 - fmt =3D rga_fmt_find(pix_fmt->pixelformat); + fmt =3D rga_fmt_find(ctx->rga, pix_fmt->pixelformat); if (!fmt) - fmt =3D &formats[0]; + fmt =3D &hw->formats[0]; =20 pix_fmt->width =3D clamp(pix_fmt->width, - (u32)MIN_WIDTH, (u32)MAX_WIDTH); + hw->min_width, hw->max_width); pix_fmt->height =3D clamp(pix_fmt->height, - (u32)MIN_HEIGHT, (u32)MAX_HEIGHT); + hw->min_height, hw->max_height); =20 v4l2_fill_pixfmt_mp(pix_fmt, fmt->fourcc, pix_fmt->width, pix_fmt->height= ); pix_fmt->field =3D V4L2_FIELD_NONE; @@ -529,7 +396,7 @@ static int vidioc_s_fmt(struct file *file, void *priv, = struct v4l2_format *f) frm->size =3D 0; for (i =3D 0; i < pix_fmt->num_planes; i++) frm->size +=3D pix_fmt->plane_fmt[i].sizeimage; - frm->fmt =3D rga_fmt_find(pix_fmt->pixelformat); + frm->fmt =3D rga_fmt_find(rga, pix_fmt->pixelformat); frm->stride =3D pix_fmt->plane_fmt[0].bytesperline; =20 /* @@ -660,7 +527,7 @@ static int vidioc_s_selection(struct file *file, void *= priv, =20 if (s->r.left + s->r.width > f->pix.width || s->r.top + s->r.height > f->pix.height || - s->r.width < MIN_WIDTH || s->r.height < MIN_HEIGHT) { + s->r.width < rga->hw->min_width || s->r.height < rga->hw->min_height)= { v4l2_dbg(debug, 1, &rga->v4l2_dev, "unsupported crop value.\n"); return -EINVAL; } @@ -770,6 +637,10 @@ static int rga_probe(struct platform_device *pdev) if (!rga) return -ENOMEM; =20 + rga->hw =3D of_device_get_match_data(&pdev->dev); + if (!rga->hw) + return dev_err_probe(&pdev->dev, -ENODEV, "failed to get match data\n"); + rga->dev =3D &pdev->dev; spin_lock_init(&rga->ctrl_lock); mutex_init(&rga->mutex); @@ -833,8 +704,7 @@ static int rga_probe(struct platform_device *pdev) if (ret < 0) goto rel_m2m; =20 - rga->version.major =3D (rga_read(rga, RGA_VERSION_INFO) >> 24) & 0xFF; - rga->version.minor =3D (rga_read(rga, RGA_VERSION_INFO) >> 20) & 0x0F; + rga->hw->get_version(rga); =20 v4l2_info(&rga->v4l2_dev, "HW Version: 0x%02x.%02x\n", rga->version.major, rga->version.minor); @@ -842,7 +712,7 @@ static int rga_probe(struct platform_device *pdev) pm_runtime_put(rga->dev); =20 /* Create CMD buffer */ - rga->cmdbuf_virt =3D dma_alloc_attrs(rga->dev, RGA_CMDBUF_SIZE, + rga->cmdbuf_virt =3D dma_alloc_attrs(rga->dev, rga->hw->cmdbuf_size, &rga->cmdbuf_phy, GFP_KERNEL, DMA_ATTR_WRITE_COMBINE); if (!rga->cmdbuf_virt) { @@ -850,9 +720,6 @@ static int rga_probe(struct platform_device *pdev) goto rel_m2m; } =20 - def_frame.stride =3D (DEFAULT_WIDTH * def_frame.fmt->depth) >> 3; - def_frame.size =3D def_frame.stride * DEFAULT_HEIGHT; - ret =3D video_register_device(vfd, VFL_TYPE_VIDEO, -1); if (ret) { v4l2_err(&rga->v4l2_dev, "Failed to register video device\n"); @@ -865,7 +732,7 @@ static int rga_probe(struct platform_device *pdev) return 0; =20 free_dma: - dma_free_attrs(rga->dev, RGA_CMDBUF_SIZE, rga->cmdbuf_virt, + dma_free_attrs(rga->dev, rga->hw->cmdbuf_size, rga->cmdbuf_virt, rga->cmdbuf_phy, DMA_ATTR_WRITE_COMBINE); rel_m2m: v4l2_m2m_release(rga->m2m_dev); @@ -883,7 +750,7 @@ static void rga_remove(struct platform_device *pdev) { struct rockchip_rga *rga =3D platform_get_drvdata(pdev); =20 - dma_free_attrs(rga->dev, RGA_CMDBUF_SIZE, rga->cmdbuf_virt, + dma_free_attrs(rga->dev, rga->hw->cmdbuf_size, rga->cmdbuf_virt, rga->cmdbuf_phy, DMA_ATTR_WRITE_COMBINE); =20 v4l2_info(&rga->v4l2_dev, "Removing\n"); @@ -919,9 +786,11 @@ static const struct dev_pm_ops rga_pm =3D { static const struct of_device_id rockchip_rga_match[] =3D { { .compatible =3D "rockchip,rk3288-rga", + .data =3D &rga2_hw, }, { .compatible =3D "rockchip,rk3399-rga", + .data =3D &rga2_hw, }, {}, }; diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index c4a3905a48f0d..640e510285341 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -14,6 +14,9 @@ =20 #define RGA_NAME "rockchip-rga" =20 +#define DEFAULT_WIDTH 100 +#define DEFAULT_HEIGHT 100 + struct rga_fmt { u32 fourcc; int depth; @@ -68,6 +71,8 @@ static inline struct rga_ctx *file_to_rga_ctx(struct file= *filp) return container_of(file_to_v4l2_fh(filp), struct rga_ctx, fh); } =20 +struct rga_hw; + struct rockchip_rga { struct v4l2_device v4l2_dev; struct v4l2_m2m_dev *m2m_dev; @@ -88,6 +93,8 @@ struct rockchip_rga { struct rga_ctx *curr; dma_addr_t cmdbuf_phy; void *cmdbuf_virt; + + const struct rga_hw *hw; }; =20 struct rga_addr_offset { @@ -138,7 +145,19 @@ static inline void rga_mod(struct rockchip_rga *rga, u= 32 reg, u32 val, u32 mask) rga_write(rga, reg, temp); }; =20 -void rga_hw_start(struct rockchip_rga *rga, - struct rga_vb_buffer *src, struct rga_vb_buffer *dst); +struct rga_hw { + struct rga_fmt *formats; + u32 num_formats; + size_t cmdbuf_size; + u32 min_width, min_height; + u32 max_width, max_height; + + void (*start)(struct rockchip_rga *rga, + struct rga_vb_buffer *src, struct rga_vb_buffer *dst); + bool (*handle_irq)(struct rockchip_rga *rga); + void (*get_version)(struct rockchip_rga *rga); +}; + +extern const struct rga_hw rga2_hw; =20 #endif --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 7F7A335FF67 for ; Tue, 27 Jan 2026 14:40:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524821; cv=none; b=fCbfGSpnOyCAz3Xu5yGvvyJ8xrpvIfYsh3zzgLmPy7L/FEZJHDXYJP2pFY6gx9FK9cuQ0ia/nWv2kpiG70FDonO1IttBtN8w/xfn3ueW7ec4CA5iruuSaoLid9GkKTA28UofvVIXCC445C9fi/cQwpiajiwWSphza2IVLt++09w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524821; c=relaxed/simple; bh=sQRBR8hqsVnFilBb4IeM1DRR5keXwvKE0i990WgKU4w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sh5oLhY/QGOisGzE+CGkkTLnWWlopy4gjOH18z4C2pYec7iebMMkzFDGUKH192Yvh8BRA9EfofPpPan6xO/KmtbyubztvnwJmtu0ASMZTPX+tXvFPfpjal693nvbhyv6oC4FS/C+KmSfisPLmvL0c8LOLxb2ikyPIsOo92feXHQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkEr-0007YT-E5; Tue, 27 Jan 2026 15:40:17 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:20 +0100 Subject: [PATCH v3 11/27] media: rockchip: rga: avoid odd frame sizes for YUV formats 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: <20260127-spu-rga3-v3-11-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Avoid odd frame sizes for YUV formats, as they may cause undefined behavior. This is done in preparation for the RGA3, which hangs when the output format is set to 129x129 pixel YUV420 SP (NV12). This requirement is documented explicitly for the RGA3 in section 5.6.3 of the RK3588 TRM Part 2. For the RGA2 the RK3588 TRM Part 2 (section 6.1.2) and RK3568 TRM Part 2 (section 14.2) only mentions the x/y offsets and stride aligning requirements. But the vendor driver for the RGA2 also contains checks for the width and height to be aligned to 2 bytes. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 21a3c6cd38dbc..4fa6adb10b7ee 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -337,6 +337,19 @@ static int vidioc_try_fmt(struct file *file, void *pri= v, struct v4l2_format *f) struct rga_ctx *ctx =3D file_to_rga_ctx(file); const struct rga_hw *hw =3D ctx->rga->hw; struct rga_fmt *fmt; + struct v4l2_frmsize_stepwise frmsize =3D { + .min_width =3D hw->min_width, + .max_width =3D hw->max_width, + .min_height =3D hw->min_height, + .max_height =3D hw->max_height, + .step_width =3D 1, + .step_height =3D 1, + }; + + if (v4l2_is_format_yuv(v4l2_format_info(pix_fmt->pixelformat))) { + frmsize.step_width =3D 2; + frmsize.step_height =3D 2; + } =20 if (V4L2_TYPE_IS_CAPTURE(f->type)) { const struct rga_frame *frm; @@ -358,11 +371,7 @@ static int vidioc_try_fmt(struct file *file, void *pri= v, struct v4l2_format *f) if (!fmt) fmt =3D &hw->formats[0]; =20 - pix_fmt->width =3D clamp(pix_fmt->width, - hw->min_width, hw->max_width); - pix_fmt->height =3D clamp(pix_fmt->height, - hw->min_height, hw->max_height); - + v4l2_apply_frmsize_constraints(&pix_fmt->width, &pix_fmt->height, &frmsiz= e); v4l2_fill_pixfmt_mp(pix_fmt, fmt->fourcc, pix_fmt->width, pix_fmt->height= ); pix_fmt->field =3D V4L2_FIELD_NONE; =20 --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 6F47436073B for ; Tue, 27 Jan 2026 14:40:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524822; cv=none; b=oOHRF31NuyMObGohxSVNu5KtMHGf8w58/cvrOMHDLQ6Gk7OcUOsuih2OdK/0qi0FECDFwS9oCpftc+vlxA0XLxFI8qtRjk2+t4ZrKp1qolLabocnqruKNrd9Ds7awTDfQouiw62sgdVGzUYyneS/PNUxAzoEpqfDze8jnbDvfzk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524822; c=relaxed/simple; bh=BD49zYnjni/1LXL3mM8Ds27rZ141elFgjYeaJs61og0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=moKEwoyuFuI+P+ikdtdNDK5W5suP7c8v3c3UB+pdCsFwTPjKLMqtl/jV0ihb+zZT4yN4fxAyyotyiGo/wd8Dt3760SkM5xqYVZgcMKhVsETR7uWRr9kNrbeV5G7TrKjJ1DIeZ4nrc0GagjKFHBfRPLD8I7/fiUmyknugc++QxlM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkEt-0007YT-F1; Tue, 27 Jan 2026 15:40:19 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:21 +0100 Subject: [PATCH v3 12/27] media: rockchip: rga: calculate x_div/y_div using v4l2_format_info 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: <20260127-spu-rga3-v3-12-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Calculate the x_div and y_div variables with the information from v4l2_format_info instead of storing these in the rga_fmt struct. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 45 +++++++-----------------= ---- drivers/media/platform/rockchip/rga/rga.h | 2 -- 2 files changed, 11 insertions(+), 36 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index c0218a71fee04..7405355c334ad 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -42,6 +42,7 @@ rga_get_addr_offset(struct rga_frame *frm, struct rga_add= r_offset *offset, { struct rga_corners_addr_offset offsets; struct rga_addr_offset *lt, *lb, *rt, *rb; + const struct v4l2_format_info *format_info; unsigned int x_div =3D 0, y_div =3D 0, uv_stride =3D 0, pixel_width =3D 0; =20 @@ -50,8 +51,16 @@ rga_get_addr_offset(struct rga_frame *frm, struct rga_ad= dr_offset *offset, rt =3D &offsets.right_top; rb =3D &offsets.right_bottom; =20 - x_div =3D frm->fmt->x_div; - y_div =3D frm->fmt->y_div; + format_info =3D v4l2_format_info(frm->pix.pixelformat); + /* x_div is only used for the u/v planes. + * When the format doesn't have these, use 1 to avoid a division by zero. + */ + if (format_info->bpp[1]) + x_div =3D format_info->hdiv * format_info->bpp_div[1] / + format_info->bpp[1]; + else + x_div =3D 1; + y_div =3D format_info->vdiv; uv_stride =3D frm->stride / x_div; pixel_width =3D frm->stride / frm->pix.width; =20 @@ -476,128 +485,96 @@ static struct rga_fmt formats[] =3D { .color_swap =3D RGA_COLOR_ALPHA_SWAP, .hw_format =3D RGA_COLOR_FMT_ABGR8888, .depth =3D 32, - .y_div =3D 1, - .x_div =3D 1, }, { .fourcc =3D V4L2_PIX_FMT_ABGR32, .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_ABGR8888, .depth =3D 32, - .y_div =3D 1, - .x_div =3D 1, }, { .fourcc =3D V4L2_PIX_FMT_XBGR32, .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_XBGR8888, .depth =3D 32, - .y_div =3D 1, - .x_div =3D 1, }, { .fourcc =3D V4L2_PIX_FMT_RGB24, .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_RGB888, .depth =3D 24, - .y_div =3D 1, - .x_div =3D 1, }, { .fourcc =3D V4L2_PIX_FMT_BGR24, .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_RGB888, .depth =3D 24, - .y_div =3D 1, - .x_div =3D 1, }, { .fourcc =3D V4L2_PIX_FMT_ARGB444, .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_ABGR4444, .depth =3D 16, - .y_div =3D 1, - .x_div =3D 1, }, { .fourcc =3D V4L2_PIX_FMT_ARGB555, .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_ABGR1555, .depth =3D 16, - .y_div =3D 1, - .x_div =3D 1, }, { .fourcc =3D V4L2_PIX_FMT_RGB565, .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_BGR565, .depth =3D 16, - .y_div =3D 1, - .x_div =3D 1, }, { .fourcc =3D V4L2_PIX_FMT_NV21, .color_swap =3D RGA_COLOR_UV_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV420SP, .depth =3D 12, - .y_div =3D 2, - .x_div =3D 1, }, { .fourcc =3D V4L2_PIX_FMT_NV61, .color_swap =3D RGA_COLOR_UV_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV422SP, .depth =3D 16, - .y_div =3D 1, - .x_div =3D 1, }, { .fourcc =3D V4L2_PIX_FMT_NV12, .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV420SP, .depth =3D 12, - .y_div =3D 2, - .x_div =3D 1, }, { .fourcc =3D V4L2_PIX_FMT_NV12M, .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV420SP, .depth =3D 12, - .y_div =3D 2, - .x_div =3D 1, }, { .fourcc =3D V4L2_PIX_FMT_NV16, .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV422SP, .depth =3D 16, - .y_div =3D 1, - .x_div =3D 1, }, { .fourcc =3D V4L2_PIX_FMT_YUV420, .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV420P, .depth =3D 12, - .y_div =3D 2, - .x_div =3D 2, }, { .fourcc =3D V4L2_PIX_FMT_YUV422P, .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV422P, .depth =3D 16, - .y_div =3D 1, - .x_div =3D 2, }, { .fourcc =3D V4L2_PIX_FMT_YVU420, .color_swap =3D RGA_COLOR_UV_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV420P, .depth =3D 12, - .y_div =3D 2, - .x_div =3D 2, }, }; =20 diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 640e510285341..27b3c9b4f220c 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -20,8 +20,6 @@ struct rga_fmt { u32 fourcc; int depth; - u8 y_div; - u8 x_div; u8 color_swap; u8 hw_format; }; --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 C423335CBDD for ; Tue, 27 Jan 2026 14:40:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524825; cv=none; b=sM8TscI7EMoVd/QCE+t3qHehZfjFtLlUDsMcJr21WWCIFY4N/Uzj7jcVsBHdaZD9IOKQnj8+qncg17kly5J54JxhpPOBHPvQRmfP3i0vJ2A67V/nIEypp85CIqanB8qCWQVvtRoMV0Q7Sy0G6SKM+bgVbyHiMfff0U8ZZkZy+o0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524825; c=relaxed/simple; bh=GQr6gJ6RW3y3I5PfRuJXbEG83bn3Uw0rmyDi3r9F/r0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ppaHyC/ngqZ8ruTsrGViaTNWuOH0mzHEBm7+axvBJosDj+mNmHsbtNYjbwO41aN8LwJkXMQOxA4V0W2kqgbs2FHG9nTKDFrGT26Sm0efdifvD9Hr9fC2JxpmZpGogC9a9PfY4c8wKlaJMpM7Mpq3JiBNBMPuHpyhCfgq+CvuSZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkEv-0007YT-MF; Tue, 27 Jan 2026 15:40:21 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:22 +0100 Subject: [PATCH v3 13/27] media: rockchip: rga: move cmdbuf to rga_ctx 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: <20260127-spu-rga3-v3-13-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= , Nicolas Dufresne X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Move the command buffer to the rga_ctx struct in preparation to reuse an already prepared command buffer. This allows to split the command buffer setup in a further commit to setup a template for the command buffer at streamon and only update the buffer addresses in device_run and trigger the command stream. No sync point is added, as one command buffer should only be used for one conversion at a time. Reviewed-by: Nicolas Dufresne Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 28 +++++++--------- drivers/media/platform/rockchip/rga/rga.c | 48 ++++++++++++++++--------= ---- drivers/media/platform/rockchip/rga/rga.h | 5 +-- 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index 7405355c334ad..caf2424962351 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -122,8 +122,7 @@ static struct rga_addr_offset *rga_lookup_draw_pos(stru= ct =20 static void rga_cmd_set_src_addr(struct rga_ctx *ctx, dma_addr_t dma_addr) { - struct rockchip_rga *rga =3D ctx->rga; - u32 *dest =3D rga->cmdbuf_virt; + u32 *dest =3D ctx->cmdbuf_virt; unsigned int reg; =20 reg =3D RGA_MMU_SRC_BASE - RGA_MODE_BASE_REG; @@ -135,8 +134,7 @@ static void rga_cmd_set_src_addr(struct rga_ctx *ctx, d= ma_addr_t dma_addr) =20 static void rga_cmd_set_src1_addr(struct rga_ctx *ctx, dma_addr_t dma_addr) { - struct rockchip_rga *rga =3D ctx->rga; - u32 *dest =3D rga->cmdbuf_virt; + u32 *dest =3D ctx->cmdbuf_virt; unsigned int reg; =20 reg =3D RGA_MMU_SRC1_BASE - RGA_MODE_BASE_REG; @@ -148,8 +146,7 @@ static void rga_cmd_set_src1_addr(struct rga_ctx *ctx, = dma_addr_t dma_addr) =20 static void rga_cmd_set_dst_addr(struct rga_ctx *ctx, dma_addr_t dma_addr) { - struct rockchip_rga *rga =3D ctx->rga; - u32 *dest =3D rga->cmdbuf_virt; + u32 *dest =3D ctx->cmdbuf_virt; unsigned int reg; =20 reg =3D RGA_MMU_DST_BASE - RGA_MODE_BASE_REG; @@ -162,7 +159,7 @@ static void rga_cmd_set_dst_addr(struct rga_ctx *ctx, d= ma_addr_t dma_addr) static void rga_cmd_set_trans_info(struct rga_ctx *ctx) { struct rockchip_rga *rga =3D ctx->rga; - u32 *dest =3D rga->cmdbuf_virt; + u32 *dest =3D ctx->cmdbuf_virt; unsigned int scale_dst_w, scale_dst_h; unsigned int src_h, src_w, dst_h, dst_w; union rga_src_info src_info; @@ -322,8 +319,7 @@ static void rga_cmd_set_src_info(struct rga_ctx *ctx, struct rga_addr_offset *offset) { struct rga_corners_addr_offset src_offsets; - struct rockchip_rga *rga =3D ctx->rga; - u32 *dest =3D rga->cmdbuf_virt; + u32 *dest =3D ctx->cmdbuf_virt; unsigned int src_h, src_w, src_x, src_y; =20 src_h =3D ctx->in.crop.height; @@ -350,8 +346,7 @@ static void rga_cmd_set_dst_info(struct rga_ctx *ctx, { struct rga_addr_offset *dst_offset; struct rga_corners_addr_offset offsets; - struct rockchip_rga *rga =3D ctx->rga; - u32 *dest =3D rga->cmdbuf_virt; + u32 *dest =3D ctx->cmdbuf_virt; unsigned int dst_h, dst_w, dst_x, dst_y; unsigned int mir_mode =3D 0; unsigned int rot_mode =3D 0; @@ -397,8 +392,7 @@ static void rga_cmd_set_dst_info(struct rga_ctx *ctx, =20 static void rga_cmd_set_mode(struct rga_ctx *ctx) { - struct rockchip_rga *rga =3D ctx->rga; - u32 *dest =3D rga->cmdbuf_virt; + u32 *dest =3D ctx->cmdbuf_virt; union rga_mode_ctrl mode; union rga_alpha_ctrl0 alpha_ctrl0; union rga_alpha_ctrl1 alpha_ctrl1; @@ -423,7 +417,7 @@ static void rga_cmd_set(struct rga_ctx *ctx, { struct rockchip_rga *rga =3D ctx->rga; =20 - memset(rga->cmdbuf_virt, 0, RGA_CMDBUF_SIZE * 4); + memset(ctx->cmdbuf_virt, 0, RGA_CMDBUF_SIZE * 4); =20 rga_cmd_set_src_addr(ctx, src->dma_desc_pa); /* @@ -439,11 +433,11 @@ static void rga_cmd_set(struct rga_ctx *ctx, rga_cmd_set_dst_info(ctx, &dst->offset); rga_cmd_set_trans_info(ctx); =20 - rga_write(rga, RGA_CMD_BASE, rga->cmdbuf_phy); + rga_write(rga, RGA_CMD_BASE, ctx->cmdbuf_phy); =20 /* sync CMD buf for RGA */ - dma_sync_single_for_device(rga->dev, rga->cmdbuf_phy, - PAGE_SIZE, DMA_BIDIRECTIONAL); + dma_sync_single_for_device(rga->dev, ctx->cmdbuf_phy, + PAGE_SIZE, DMA_BIDIRECTIONAL); } =20 static void rga_hw_start(struct rockchip_rga *rga, diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 4fa6adb10b7ee..ac42e905a88cd 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -219,6 +219,16 @@ static int rga_open(struct file *file) ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) return -ENOMEM; + + /* Create CMD buffer */ + ctx->cmdbuf_virt =3D dma_alloc_attrs(rga->dev, rga->hw->cmdbuf_size, + &ctx->cmdbuf_phy, GFP_KERNEL, + DMA_ATTR_WRITE_COMBINE); + if (!ctx->cmdbuf_virt) { + ret =3D -ENOMEM; + goto rel_ctx; + } + ctx->rga =3D rga; /* Set default formats */ ctx->in =3D def_frame; @@ -230,15 +240,13 @@ static int rga_open(struct file *file) ctx->out.fmt->fourcc, def_width, def_height); =20 if (mutex_lock_interruptible(&rga->mutex)) { - kfree(ctx); - return -ERESTARTSYS; + ret =3D -ERESTARTSYS; + goto rel_cmdbuf; } ctx->fh.m2m_ctx =3D v4l2_m2m_ctx_init(rga->m2m_dev, ctx, &queue_init); if (IS_ERR(ctx->fh.m2m_ctx)) { ret =3D PTR_ERR(ctx->fh.m2m_ctx); - mutex_unlock(&rga->mutex); - kfree(ctx); - return ret; + goto unlock_mutex; } v4l2_fh_init(&ctx->fh, video_devdata(file)); v4l2_fh_add(&ctx->fh, file); @@ -252,6 +260,15 @@ static int rga_open(struct file *file) mutex_unlock(&rga->mutex); =20 return 0; + +unlock_mutex: + mutex_unlock(&rga->mutex); +rel_cmdbuf: + dma_free_attrs(rga->dev, rga->hw->cmdbuf_size, ctx->cmdbuf_virt, + ctx->cmdbuf_phy, DMA_ATTR_WRITE_COMBINE); +rel_ctx: + kfree(ctx); + return ret; } =20 static int rga_release(struct file *file) @@ -266,6 +283,10 @@ static int rga_release(struct file *file) v4l2_ctrl_handler_free(&ctx->ctrl_handler); v4l2_fh_del(&ctx->fh, file); v4l2_fh_exit(&ctx->fh); + + dma_free_attrs(rga->dev, rga->hw->cmdbuf_size, ctx->cmdbuf_virt, + ctx->cmdbuf_phy, DMA_ATTR_WRITE_COMBINE); + kfree(ctx); =20 mutex_unlock(&rga->mutex); @@ -720,19 +741,10 @@ static int rga_probe(struct platform_device *pdev) =20 pm_runtime_put(rga->dev); =20 - /* Create CMD buffer */ - rga->cmdbuf_virt =3D dma_alloc_attrs(rga->dev, rga->hw->cmdbuf_size, - &rga->cmdbuf_phy, GFP_KERNEL, - DMA_ATTR_WRITE_COMBINE); - if (!rga->cmdbuf_virt) { - ret =3D -ENOMEM; - goto rel_m2m; - } - ret =3D video_register_device(vfd, VFL_TYPE_VIDEO, -1); if (ret) { v4l2_err(&rga->v4l2_dev, "Failed to register video device\n"); - goto free_dma; + goto rel_m2m; } =20 v4l2_info(&rga->v4l2_dev, "Registered %s as /dev/%s\n", @@ -740,9 +752,6 @@ static int rga_probe(struct platform_device *pdev) =20 return 0; =20 -free_dma: - dma_free_attrs(rga->dev, rga->hw->cmdbuf_size, rga->cmdbuf_virt, - rga->cmdbuf_phy, DMA_ATTR_WRITE_COMBINE); rel_m2m: v4l2_m2m_release(rga->m2m_dev); rel_vdev: @@ -759,9 +768,6 @@ static void rga_remove(struct platform_device *pdev) { struct rockchip_rga *rga =3D platform_get_drvdata(pdev); =20 - dma_free_attrs(rga->dev, rga->hw->cmdbuf_size, rga->cmdbuf_virt, - rga->cmdbuf_phy, DMA_ATTR_WRITE_COMBINE); - v4l2_info(&rga->v4l2_dev, "Removing\n"); =20 v4l2_m2m_release(rga->m2m_dev); diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 27b3c9b4f220c..04aeb7b429523 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -53,6 +53,9 @@ struct rga_ctx { struct rga_frame out; struct v4l2_ctrl_handler ctrl_handler; =20 + void *cmdbuf_virt; + dma_addr_t cmdbuf_phy; + int osequence; int csequence; =20 @@ -89,8 +92,6 @@ struct rockchip_rga { spinlock_t ctrl_lock; =20 struct rga_ctx *curr; - dma_addr_t cmdbuf_phy; - void *cmdbuf_virt; =20 const struct rga_hw *hw; }; --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 74B5B35F8C5 for ; Tue, 27 Jan 2026 14:40:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524828; cv=none; b=OkWOKkyPfuQaUyqoXvvahkqHE1gM4qXpNLGgyd2SrAB+9ENv7vNKXg07tmrWq3amQBOJ4j6IBObeVmdBIAEqTuTUAj3BQrvpB5medNWvFS4krDrvPR/WUN+JK1VBjUYVi/KfgrzPTSmeo/5vkxgmItJYf7cGkDCBhHePr1npkqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524828; c=relaxed/simple; bh=/k7y+ulhazQXhid7mmqv3l/6j4W1vDnO4DejkulkWtk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FsD4TRBa3Zo11uEJLZzGOKkbCyR+qRNGkb6ymKjBJwCZYrD0YzV/DtFDQOstk6SdifR+awvpW9nBBwRYU6GFxWIfsfBx+E7vEHHzSD8H9tDNv7zQYJbVpAHgMyKeoFodGDGr3DZPY7Ckza3gY5qRcDUUw9HGYPmO7LzWra5PaZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkEx-0007YT-ME; Tue, 27 Jan 2026 15:40:23 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:23 +0100 Subject: [PATCH v3 14/27] media: rockchip: rga: align stride to 4 bytes 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: <20260127-spu-rga3-v3-14-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add an alignment setting to rga_hw to set the desired stride alignment. As the RGA2 register for the stride counts in word units, the code already divides the bytesperline value by 4 when writing it into the register. Therefore fix the alignment to a multiple of 4 to avoid potential off by one errors due from the division. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 1 + drivers/media/platform/rockchip/rga/rga.c | 11 ++++++----- drivers/media/platform/rockchip/rga/rga.h | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index caf2424962351..16380be598e4a 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -580,6 +580,7 @@ const struct rga_hw rga2_hw =3D { .max_width =3D MAX_WIDTH, .min_height =3D MIN_HEIGHT, .max_height =3D MAX_HEIGHT, + .stride_alignment =3D 4, =20 .start =3D rga_hw_start, .handle_irq =3D rga_handle_irq, diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index ac42e905a88cd..2920efe65082a 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -234,10 +234,10 @@ static int rga_open(struct file *file) ctx->in =3D def_frame; ctx->out =3D def_frame; =20 - v4l2_fill_pixfmt_mp(&ctx->in.pix, - ctx->in.fmt->fourcc, def_width, def_height); - v4l2_fill_pixfmt_mp(&ctx->out.pix, - ctx->out.fmt->fourcc, def_width, def_height); + v4l2_fill_pixfmt_mp_aligned(&ctx->in.pix, ctx->in.fmt->fourcc, + def_width, def_height, rga->hw->stride_alignment); + v4l2_fill_pixfmt_mp_aligned(&ctx->out.pix, ctx->out.fmt->fourcc, + def_width, def_height, rga->hw->stride_alignment); =20 if (mutex_lock_interruptible(&rga->mutex)) { ret =3D -ERESTARTSYS; @@ -393,7 +393,8 @@ static int vidioc_try_fmt(struct file *file, void *priv= , struct v4l2_format *f) fmt =3D &hw->formats[0]; =20 v4l2_apply_frmsize_constraints(&pix_fmt->width, &pix_fmt->height, &frmsiz= e); - v4l2_fill_pixfmt_mp(pix_fmt, fmt->fourcc, pix_fmt->width, pix_fmt->height= ); + v4l2_fill_pixfmt_mp_aligned(pix_fmt, pix_fmt->pixelformat, + pix_fmt->width, pix_fmt->height, hw->stride_alignment); pix_fmt->field =3D V4L2_FIELD_NONE; =20 return 0; diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 04aeb7b429523..38518146910a6 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -150,6 +150,7 @@ struct rga_hw { size_t cmdbuf_size; u32 min_width, min_height; u32 max_width, max_height; + u8 stride_alignment; =20 void (*start)(struct rockchip_rga *rga, struct rga_vb_buffer *src, struct rga_vb_buffer *dst); --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 7121335D5F8 for ; Tue, 27 Jan 2026 14:40:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524830; cv=none; b=S6Yo8FFO3LON0+LN2xkKi4dYxn0R6MMhk/L65IH96bGOD0fZNeZFq5oHvepLtE8rD6YtAuKhL0QOAQ9wfzegbxrdTAYWJ9d9dOXWpy8fMZUxj2qb6X0//tY+eV07ExxGu/x1oXBWRFwMid2bhfXhiTjqbWCGDjm/DCVnRWIJqkc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524830; c=relaxed/simple; bh=iDSo3xKVQDr0j+iq/VfyVGqXilMDTdQkkmmxSDyozRY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CjRJM3EmomGqJWYUVENg8QfcKPIu40lwPpZNJRibMvGleEvEzALfcab4wXd9e2ZlfuahW4Vs4udp5Xt9Dd1mjnnja6ui/qHO3hAGV1k5vSoPSr5SjD0pLMDgRdAFfyoi+BcLJbJ84X610hoJUBQ4lRduMmH8MfL57Uz/v1Ejscs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkF0-0007YT-38; Tue, 27 Jan 2026 15:40:26 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:24 +0100 Subject: [PATCH v3 15/27] media: rockchip: rga: prepare cmdbuf on streamon 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: <20260127-spu-rga3-v3-15-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= , Nicolas Dufresne X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Prepare the command buffer on streamon to reuse it's contents instead of completely writing it for every frame. Due to the stream settings being fixed after a streamon we only need to replace the source and destination addresses for each frame. This reduces the amount of CPU and memory operations done in each frame. Reviewed-by: Nicolas Dufresne Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 13 +++++++++---- drivers/media/platform/rockchip/rga/rga.c | 13 ++++++++++++- drivers/media/platform/rockchip/rga/rga.h | 1 + 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index 16380be598e4a..dcd540ed3fd5b 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -417,8 +417,6 @@ static void rga_cmd_set(struct rga_ctx *ctx, { struct rockchip_rga *rga =3D ctx->rga; =20 - memset(ctx->cmdbuf_virt, 0, RGA_CMDBUF_SIZE * 4); - rga_cmd_set_src_addr(ctx, src->dma_desc_pa); /* * Due to hardware bug, @@ -427,11 +425,9 @@ static void rga_cmd_set(struct rga_ctx *ctx, rga_cmd_set_src1_addr(ctx, dst->dma_desc_pa); =20 rga_cmd_set_dst_addr(ctx, dst->dma_desc_pa); - rga_cmd_set_mode(ctx); =20 rga_cmd_set_src_info(ctx, &src->offset); rga_cmd_set_dst_info(ctx, &dst->offset); - rga_cmd_set_trans_info(ctx); =20 rga_write(rga, RGA_CMD_BASE, ctx->cmdbuf_phy); =20 @@ -440,6 +436,14 @@ static void rga_cmd_set(struct rga_ctx *ctx, PAGE_SIZE, DMA_BIDIRECTIONAL); } =20 +static void rga_hw_setup_cmdbuf(struct rga_ctx *ctx) +{ + memset(ctx->cmdbuf_virt, 0, RGA_CMDBUF_SIZE * 4); + + rga_cmd_set_mode(ctx); + rga_cmd_set_trans_info(ctx); +} + static void rga_hw_start(struct rockchip_rga *rga, struct rga_vb_buffer *src, struct rga_vb_buffer *dst) { @@ -582,6 +586,7 @@ const struct rga_hw rga2_hw =3D { .max_height =3D MAX_HEIGHT, .stride_alignment =3D 4, =20 + .setup_cmdbuf =3D rga_hw_setup_cmdbuf, .start =3D rga_hw_start, .handle_irq =3D rga_handle_irq, .get_version =3D rga_get_version, diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 2920efe65082a..6947c472a8b01 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -568,6 +568,17 @@ static int vidioc_s_selection(struct file *file, void = *priv, return ret; } =20 +static int vidioc_streamon(struct file *file, void *priv, + enum v4l2_buf_type type) +{ + struct rga_ctx *ctx =3D file_to_rga_ctx(file); + const struct rga_hw *hw =3D ctx->rga->hw; + + hw->setup_cmdbuf(ctx); + + return v4l2_m2m_streamon(file, ctx->fh.m2m_ctx, type); +} + static const struct v4l2_ioctl_ops rga_ioctl_ops =3D { .vidioc_querycap =3D vidioc_querycap, =20 @@ -592,7 +603,7 @@ static const struct v4l2_ioctl_ops rga_ioctl_ops =3D { .vidioc_subscribe_event =3D v4l2_ctrl_subscribe_event, .vidioc_unsubscribe_event =3D v4l2_event_unsubscribe, =20 - .vidioc_streamon =3D v4l2_m2m_ioctl_streamon, + .vidioc_streamon =3D vidioc_streamon, .vidioc_streamoff =3D v4l2_m2m_ioctl_streamoff, =20 .vidioc_g_selection =3D vidioc_g_selection, diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 38518146910a6..c741213710b32 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -152,6 +152,7 @@ struct rga_hw { u32 max_width, max_height; u8 stride_alignment; =20 + void (*setup_cmdbuf)(struct rga_ctx *ctx); void (*start)(struct rockchip_rga *rga, struct rga_vb_buffer *src, struct rga_vb_buffer *dst); bool (*handle_irq)(struct rockchip_rga *rga); --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 E917735D615 for ; Tue, 27 Jan 2026 14:40:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524832; cv=none; b=n4iSjy7fgivtov+gtNyaBLrXoXIfUonXYPynjPsOi3/hTowG0BK5hof2LWk5kOEb2KvgHtqXFOb4AZaBShn38iIbsF8zyvaoploHVFmduhtiv10EElLGTC83Q/d5XLcr0hHC+C7voZyals/4dP51EeKbyrCy/6v+7KFa9qKzrME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524832; c=relaxed/simple; bh=J6XXFWpx2j/S2nJfW149OVH+tylhl3sW1jNNdXITzo8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=btV+jgVSxNowDp2uBH5db3ZPfrZnKW78/X0T5kyz8bqTJJNaXONxNb9wmptZpupzz62hYfNZTw9zNlkF8Z6NTSGQnQJmXjwzGeYNenK/Yc474FWq03vQ2qEp4t2XbXr425G/vwAA0rr4DzuENFYq6nehjKb72nrtr/vrBlKtcAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkF2-0007YT-N2; Tue, 27 Jan 2026 15:40:29 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:25 +0100 Subject: [PATCH v3 16/27] media: rockchip: rga: check scaling factor 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: <20260127-spu-rga3-v3-16-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Check the scaling factor to avoid potential problems. This is relevant for the upcoming RGA3 support, as it can hang when the scaling factor is exceeded. There are two relevant scenarios that have to be considered to protect against invalid scaling values: When the output or capture is already streaming, setting the format on the other side should consider the max scaling factor and clamp it accordingly. This is only done in the streaming case, as it otherwise may unintentionally clamp the value when the application sets the first format (due to a default format on the other side). When the format is set on both sides first, then the format won't be corrected by above means. Therefore the second streamon call has to check the scaling factor and fail otherwise. As try functions should only be state aware if specified, the scaling limitation is only done in s_fmt. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 1 + drivers/media/platform/rockchip/rga/rga-hw.h | 1 + drivers/media/platform/rockchip/rga/rga.c | 47 ++++++++++++++++++++++++= ++++ drivers/media/platform/rockchip/rga/rga.h | 1 + 4 files changed, 50 insertions(+) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index dcd540ed3fd5b..7a4070665fed7 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -584,6 +584,7 @@ const struct rga_hw rga2_hw =3D { .max_width =3D MAX_WIDTH, .min_height =3D MIN_HEIGHT, .max_height =3D MAX_HEIGHT, + .max_scaling_factor =3D MAX_SCALING_FACTOR, .stride_alignment =3D 4, =20 .setup_cmdbuf =3D rga_hw_setup_cmdbuf, diff --git a/drivers/media/platform/rockchip/rga/rga-hw.h b/drivers/media/p= latform/rockchip/rga/rga-hw.h index f4752aa823051..fffcab0131225 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.h +++ b/drivers/media/platform/rockchip/rga/rga-hw.h @@ -14,6 +14,7 @@ =20 #define MIN_WIDTH 34 #define MIN_HEIGHT 34 +#define MAX_SCALING_FACTOR 16 =20 #define RGA_TIMEOUT 500 =20 diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 6947c472a8b01..fad921ddd8348 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -405,10 +405,36 @@ static int vidioc_s_fmt(struct file *file, void *priv= , struct v4l2_format *f) struct v4l2_pix_format_mplane *pix_fmt =3D &f->fmt.pix_mp; struct rga_ctx *ctx =3D file_to_rga_ctx(file); struct rockchip_rga *rga =3D ctx->rga; + const struct rga_hw *hw =3D rga->hw; struct vb2_queue *vq; struct rga_frame *frm; int ret =3D 0; int i; + struct rga_frame *limit_frm =3D NULL; + + /* Limit before try_fmt to avoid recalculating the stride */ + if (V4L2_TYPE_IS_OUTPUT(f->type) && + v4l2_m2m_get_dst_vq(ctx->fh.m2m_ctx)->streaming) + limit_frm =3D &ctx->out; + if (V4L2_TYPE_IS_CAPTURE(f->type) && + v4l2_m2m_get_src_vq(ctx->fh.m2m_ctx)->streaming) + limit_frm =3D &ctx->in; + if (limit_frm) { + const struct v4l2_frmsize_stepwise frmsize =3D { + .min_width =3D DIV_ROUND_UP(limit_frm->pix.width, + hw->max_scaling_factor), + .max_width =3D + limit_frm->pix.width * hw->max_scaling_factor, + .min_height =3D DIV_ROUND_UP(limit_frm->pix.height, + hw->max_scaling_factor), + .max_height =3D + limit_frm->pix.height * hw->max_scaling_factor, + .step_width =3D 1, + .step_height =3D 1, + }; + v4l2_apply_frmsize_constraints(&pix_fmt->width, + &pix_fmt->height, &frmsize); + } =20 /* Adjust all values accordingly to the hardware capabilities * and chosen format. @@ -568,12 +594,33 @@ static int vidioc_s_selection(struct file *file, void= *priv, return ret; } =20 +static bool check_scaling(const struct rga_hw *hw, u32 src_size, u32 dst_s= ize) +{ + if (src_size < dst_size) + return src_size * hw->max_scaling_factor >=3D dst_size; + else + return dst_size * hw->max_scaling_factor >=3D src_size; +} + static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type type) { struct rga_ctx *ctx =3D file_to_rga_ctx(file); const struct rga_hw *hw =3D ctx->rga->hw; =20 + if ((V4L2_TYPE_IS_OUTPUT(type) && + v4l2_m2m_get_dst_vq(ctx->fh.m2m_ctx)->streaming) || + (V4L2_TYPE_IS_CAPTURE(type) && + v4l2_m2m_get_src_vq(ctx->fh.m2m_ctx)->streaming)) { + /* + * As the other side is already streaming, + * check that the max scaling factor isn't exceeded. + */ + if (!check_scaling(hw, ctx->in.pix.width, ctx->out.pix.width) || + !check_scaling(hw, ctx->in.pix.height, ctx->out.pix.height)) + return -EINVAL; + } + hw->setup_cmdbuf(ctx); =20 return v4l2_m2m_streamon(file, ctx->fh.m2m_ctx, type); diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index c741213710b32..454af283b1694 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -150,6 +150,7 @@ struct rga_hw { size_t cmdbuf_size; u32 min_width, min_height; u32 max_width, max_height; + u8 max_scaling_factor; u8 stride_alignment; =20 void (*setup_cmdbuf)(struct rga_ctx *ctx); --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 40B1E35DCEA for ; Tue, 27 Jan 2026 14:40:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524837; cv=none; b=bqvzZ1LL4/wPozd0X4v+WE7YqqtsuN5TGLGBVhMxVD2aB55g/UJk7DUzJ1prxts9lPZFcgP3sVbo8kHSp9ePMBbnKn74wXhM/FSmDqMnJse0f/cdUIZ3lhsDIaFhDB+/GEgGU1cAaWZ8p/8b26Oh2fazFLdtg2QPboNG0BDmPBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524837; c=relaxed/simple; bh=9oZlroJ9XuflE2o0RNcZUe31218/+DMxnepcIEcnrSo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LmO8VhgNXbNOaNZWbpphtpxTL294IdiGutCZLOUecChp2l8USpecIJflumRmMWmzE5ri5Jxkao0K3f+ZLx3XLTPqeRge1kfwRwp4VXA+y4xIZBMVCZTYwJwbf50oa0tnBmEQQjpjPDv+Ar092g+CMgqCSXEYhwsW3XQgaiBHzO8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkF7-0007YT-T0; Tue, 27 Jan 2026 15:40:34 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:26 +0100 Subject: [PATCH v3 17/27] media: rockchip: rga: use card type to specify rga type 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: <20260127-spu-rga3-v3-17-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= , Nicolas Dufresne X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org In preparation of the RGA3 support add a filed to the rga_hw struct to specify the desired card type value. This allows the user to differentiate the RGA2 and RGA3 video device nodes. Reviewed-by: Nicolas Dufresne Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 1 + drivers/media/platform/rockchip/rga/rga.c | 4 +++- drivers/media/platform/rockchip/rga/rga.h | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index 7a4070665fed7..f6070508b1475 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -577,6 +577,7 @@ static struct rga_fmt formats[] =3D { }; =20 const struct rga_hw rga2_hw =3D { + .card_type =3D "rga2", .formats =3D formats, .num_formats =3D ARRAY_SIZE(formats), .cmdbuf_size =3D RGA_CMDBUF_SIZE, diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index fad921ddd8348..f33e2288dab6f 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -306,8 +306,10 @@ static const struct v4l2_file_operations rga_fops =3D { static int vidioc_querycap(struct file *file, void *priv, struct v4l2_capability *cap) { + struct rockchip_rga *rga =3D video_drvdata(file); + strscpy(cap->driver, RGA_NAME, sizeof(cap->driver)); - strscpy(cap->card, "rockchip-rga", sizeof(cap->card)); + strscpy(cap->card, rga->hw->card_type, sizeof(cap->card)); strscpy(cap->bus_info, "platform:rga", sizeof(cap->bus_info)); =20 return 0; diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 454af283b1694..dc6f90b843c32 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -145,6 +145,7 @@ static inline void rga_mod(struct rockchip_rga *rga, u3= 2 reg, u32 val, u32 mask) }; =20 struct rga_hw { + const char *card_type; struct rga_fmt *formats; u32 num_formats; size_t cmdbuf_size; --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 4887535DD0B for ; Tue, 27 Jan 2026 14:40:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524841; cv=none; b=Wq4hUrdfNJkgwBIQjCguW+L0neyHPWqwjub87wD1T10X5nKVAG8wCg9MPmSjytypQov6WEpn3lnl1bts4Y1MCnq9A2EVLAFhtxqQSS2DLeEF+DVYBxerrFbu7nUiXn075iVUxuCJHDhKVTyWEdKCQbmjITMucr90CL0mgVbOqJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524841; c=relaxed/simple; bh=jbkNCKyDHiA5hXKkbFRRmePu1zRkSZhccvfTht3xWgQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=H/o/wGrBS1VPwuDX0Q9Bmg03HJgOnD9hI6PaDAaagF1jcm0vzkCrPPygQaFhLrLxN1yQj7aw/2pojJoxW6cakBwA/QJTIENbIc+C8vDB6UP/iBKU4kcnIj+I9HvAWbv/PrmjBP6ECdGZXBkBs2imIPfR2eVUDB/PS+xKTcL0R5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkFB-0007YT-2l; Tue, 27 Jan 2026 15:40:37 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:27 +0100 Subject: [PATCH v3 18/27] media: rockchip: rga: change offset to dma_addresses 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: <20260127-spu-rga3-v3-18-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= , Nicolas Dufresne X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Change the offset to dma_addresses, as the current naming is misleading. The offset naming comes from the fact that it references the offset in the mapped iommu address space. But from the hardware point of view this is an address, as also pointed out by the register naming (e.g. RGA_DST_Y_RGB_BASE_ADDR). Therefore also change the type to dma_addr_t, as with an external iommu driver this would also be the correct type. This change is a preparation for the RGA3 support, which uses an external iommu and therefore just gets an dma_addr_t for each buffer. The field renaming allows to reuse the existing fields of rga_vb_buffer to store these values. Reviewed-by: Nicolas Dufresne Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-buf.c | 12 +-- drivers/media/platform/rockchip/rga/rga-hw.c | 105 +++++++++++++---------= ---- drivers/media/platform/rockchip/rga/rga.h | 12 +-- 3 files changed, 64 insertions(+), 65 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/= platform/rockchip/rga/rga-buf.c index ffc6162b2e681..bc349d0a46365 100644 --- a/drivers/media/platform/rockchip/rga/rga-buf.c +++ b/drivers/media/platform/rockchip/rga/rga-buf.c @@ -121,7 +121,7 @@ static int rga_buf_prepare(struct vb2_buffer *vb) size_t curr_desc =3D 0; int i; const struct v4l2_format_info *info; - unsigned int offsets[VIDEO_MAX_PLANES]; + unsigned int dma_addrs[VIDEO_MAX_PLANES]; =20 if (IS_ERR(f)) return PTR_ERR(f); @@ -145,18 +145,18 @@ static int rga_buf_prepare(struct vb2_buffer *vb) "Failed to map video buffer to RGA\n"); return n_desc; } - offsets[i] =3D curr_desc << PAGE_SHIFT; + dma_addrs[i] =3D curr_desc << PAGE_SHIFT; curr_desc +=3D n_desc; } =20 /* Fill the remaining planes */ info =3D v4l2_format_info(f->fmt->fourcc); for (i =3D info->mem_planes; i < info->comp_planes; i++) - offsets[i] =3D get_plane_offset(f, info, i); + dma_addrs[i] =3D dma_addrs[0] + get_plane_offset(f, info, i); =20 - rbuf->offset.y_off =3D offsets[0]; - rbuf->offset.u_off =3D offsets[1]; - rbuf->offset.v_off =3D offsets[2]; + rbuf->dma_addrs.y_addr =3D dma_addrs[0]; + rbuf->dma_addrs.u_addr =3D dma_addrs[1]; + rbuf->dma_addrs.v_addr =3D dma_addrs[2]; =20 return 0; } diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index f6070508b1475..bf4a86a640ec5 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -16,11 +16,11 @@ enum e_rga_start_pos { RB =3D 3, }; =20 -struct rga_corners_addr_offset { - struct rga_addr_offset left_top; - struct rga_addr_offset right_top; - struct rga_addr_offset left_bottom; - struct rga_addr_offset right_bottom; +struct rga_corners_addrs { + struct rga_addrs left_top; + struct rga_addrs right_top; + struct rga_addrs left_bottom; + struct rga_addrs right_bottom; }; =20 static unsigned int rga_get_scaling(unsigned int src, unsigned int dst) @@ -36,20 +36,20 @@ static unsigned int rga_get_scaling(unsigned int src, u= nsigned int dst) return (src > dst) ? ((dst << 16) / src) : ((src << 16) / dst); } =20 -static struct rga_corners_addr_offset -rga_get_addr_offset(struct rga_frame *frm, struct rga_addr_offset *offset, - unsigned int x, unsigned int y, unsigned int w, unsigned int h) +static struct rga_corners_addrs +rga_get_corner_addrs(struct rga_frame *frm, struct rga_addrs *addrs, + unsigned int x, unsigned int y, unsigned int w, unsigned int h) { - struct rga_corners_addr_offset offsets; - struct rga_addr_offset *lt, *lb, *rt, *rb; + struct rga_corners_addrs corner_addrs; + struct rga_addrs *lt, *lb, *rt, *rb; const struct v4l2_format_info *format_info; unsigned int x_div =3D 0, y_div =3D 0, uv_stride =3D 0, pixel_width =3D 0; =20 - lt =3D &offsets.left_top; - lb =3D &offsets.left_bottom; - rt =3D &offsets.right_top; - rb =3D &offsets.right_bottom; + lt =3D &corner_addrs.left_top; + lb =3D &corner_addrs.left_bottom; + rt =3D &corner_addrs.right_top; + rb =3D &corner_addrs.right_bottom; =20 format_info =3D v4l2_format_info(frm->pix.pixelformat); /* x_div is only used for the u/v planes. @@ -64,29 +64,28 @@ rga_get_addr_offset(struct rga_frame *frm, struct rga_a= ddr_offset *offset, uv_stride =3D frm->stride / x_div; pixel_width =3D frm->stride / frm->pix.width; =20 - lt->y_off =3D offset->y_off + y * frm->stride + x * pixel_width; - lt->u_off =3D offset->u_off + (y / y_div) * uv_stride + x / x_div; - lt->v_off =3D offset->v_off + (y / y_div) * uv_stride + x / x_div; + lt->y_addr =3D addrs->y_addr + y * frm->stride + x * pixel_width; + lt->u_addr =3D addrs->u_addr + (y / y_div) * uv_stride + x / x_div; + lt->v_addr =3D addrs->v_addr + (y / y_div) * uv_stride + x / x_div; =20 - lb->y_off =3D lt->y_off + (h - 1) * frm->stride; - lb->u_off =3D lt->u_off + (h / y_div - 1) * uv_stride; - lb->v_off =3D lt->v_off + (h / y_div - 1) * uv_stride; + lb->y_addr =3D lt->y_addr + (h - 1) * frm->stride; + lb->u_addr =3D lt->u_addr + (h / y_div - 1) * uv_stride; + lb->v_addr =3D lt->v_addr + (h / y_div - 1) * uv_stride; =20 - rt->y_off =3D lt->y_off + (w - 1) * pixel_width; - rt->u_off =3D lt->u_off + w / x_div - 1; - rt->v_off =3D lt->v_off + w / x_div - 1; + rt->y_addr =3D lt->y_addr + (w - 1) * pixel_width; + rt->u_addr =3D lt->u_addr + w / x_div - 1; + rt->v_addr =3D lt->v_addr + w / x_div - 1; =20 - rb->y_off =3D lb->y_off + (w - 1) * pixel_width; - rb->u_off =3D lb->u_off + w / x_div - 1; - rb->v_off =3D lb->v_off + w / x_div - 1; + rb->y_addr =3D lb->y_addr + (w - 1) * pixel_width; + rb->u_addr =3D lb->u_addr + w / x_div - 1; + rb->v_addr =3D lb->v_addr + w / x_div - 1; =20 - return offsets; + return corner_addrs; } =20 -static struct rga_addr_offset *rga_lookup_draw_pos(struct - rga_corners_addr_offset - * offsets, u32 rotate_mode, - u32 mirr_mode) +static struct rga_addrs *rga_lookup_draw_pos(struct rga_corners_addrs *cor= ner_addrs, + u32 rotate_mode, + u32 mirr_mode) { static enum e_rga_start_pos rot_mir_point_matrix[4][4] =3D { { @@ -103,18 +102,18 @@ static struct rga_addr_offset *rga_lookup_draw_pos(st= ruct }, }; =20 - if (!offsets) + if (!corner_addrs) return NULL; =20 switch (rot_mir_point_matrix[rotate_mode][mirr_mode]) { case LT: - return &offsets->left_top; + return &corner_addrs->left_top; case LB: - return &offsets->left_bottom; + return &corner_addrs->left_bottom; case RT: - return &offsets->right_top; + return &corner_addrs->right_top; case RB: - return &offsets->right_bottom; + return &corner_addrs->right_bottom; } =20 return NULL; @@ -316,9 +315,9 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx) } =20 static void rga_cmd_set_src_info(struct rga_ctx *ctx, - struct rga_addr_offset *offset) + struct rga_addrs *addrs) { - struct rga_corners_addr_offset src_offsets; + struct rga_corners_addrs src_corner_addrs; u32 *dest =3D ctx->cmdbuf_virt; unsigned int src_h, src_w, src_x, src_y; =20 @@ -330,22 +329,22 @@ static void rga_cmd_set_src_info(struct rga_ctx *ctx, /* * Calculate the source framebuffer base address with offset pixel. */ - src_offsets =3D rga_get_addr_offset(&ctx->in, offset, - src_x, src_y, src_w, src_h); + src_corner_addrs =3D rga_get_corner_addrs(&ctx->in, addrs, + src_x, src_y, src_w, src_h); =20 dest[(RGA_SRC_Y_RGB_BASE_ADDR - RGA_MODE_BASE_REG) >> 2] =3D - src_offsets.left_top.y_off; + src_corner_addrs.left_top.y_addr; dest[(RGA_SRC_CB_BASE_ADDR - RGA_MODE_BASE_REG) >> 2] =3D - src_offsets.left_top.u_off; + src_corner_addrs.left_top.u_addr; dest[(RGA_SRC_CR_BASE_ADDR - RGA_MODE_BASE_REG) >> 2] =3D - src_offsets.left_top.v_off; + src_corner_addrs.left_top.v_addr; } =20 static void rga_cmd_set_dst_info(struct rga_ctx *ctx, - struct rga_addr_offset *offset) + struct rga_addrs *addrs) { - struct rga_addr_offset *dst_offset; - struct rga_corners_addr_offset offsets; + struct rga_addrs *dst_addrs; + struct rga_corners_addrs corner_addrs; u32 *dest =3D ctx->cmdbuf_virt; unsigned int dst_h, dst_w, dst_x, dst_y; unsigned int mir_mode =3D 0; @@ -379,15 +378,15 @@ static void rga_cmd_set_dst_info(struct rga_ctx *ctx, /* * Configure the dest framebuffer base address with pixel offset. */ - offsets =3D rga_get_addr_offset(&ctx->out, offset, dst_x, dst_y, dst_w, d= st_h); - dst_offset =3D rga_lookup_draw_pos(&offsets, rot_mode, mir_mode); + corner_addrs =3D rga_get_corner_addrs(&ctx->out, addrs, dst_x, dst_y, dst= _w, dst_h); + dst_addrs =3D rga_lookup_draw_pos(&corner_addrs, rot_mode, mir_mode); =20 dest[(RGA_DST_Y_RGB_BASE_ADDR - RGA_MODE_BASE_REG) >> 2] =3D - dst_offset->y_off; + dst_addrs->y_addr; dest[(RGA_DST_CB_BASE_ADDR - RGA_MODE_BASE_REG) >> 2] =3D - dst_offset->u_off; + dst_addrs->u_addr; dest[(RGA_DST_CR_BASE_ADDR - RGA_MODE_BASE_REG) >> 2] =3D - dst_offset->v_off; + dst_addrs->v_addr; } =20 static void rga_cmd_set_mode(struct rga_ctx *ctx) @@ -426,8 +425,8 @@ static void rga_cmd_set(struct rga_ctx *ctx, =20 rga_cmd_set_dst_addr(ctx, dst->dma_desc_pa); =20 - rga_cmd_set_src_info(ctx, &src->offset); - rga_cmd_set_dst_info(ctx, &dst->offset); + rga_cmd_set_src_info(ctx, &src->dma_addrs); + rga_cmd_set_dst_info(ctx, &dst->dma_addrs); =20 rga_write(rga, RGA_CMD_BASE, ctx->cmdbuf_phy); =20 diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index dc6f90b843c32..025b1df594e9a 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -96,10 +96,10 @@ struct rockchip_rga { const struct rga_hw *hw; }; =20 -struct rga_addr_offset { - unsigned int y_off; - unsigned int u_off; - unsigned int v_off; +struct rga_addrs { + dma_addr_t y_addr; + dma_addr_t u_addr; + dma_addr_t v_addr; }; =20 struct rga_vb_buffer { @@ -111,8 +111,8 @@ struct rga_vb_buffer { dma_addr_t dma_desc_pa; size_t n_desc; =20 - /* Plane offsets of this buffer into the mapping */ - struct rga_addr_offset offset; + /* Plane DMA addresses after the MMU mapping of the buffer */ + struct rga_addrs dma_addrs; }; =20 static inline struct rga_vb_buffer *vb_to_rga(struct vb2_v4l2_buffer *vb) --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 D6E9A363C5E for ; Tue, 27 Jan 2026 14:40:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524843; cv=none; b=WWsjnPGK2t56af17v0zBj/RVi9ZrjYSKHoZKM9GkeOd/UGM0ziylrxsFmkXBzoIZdz2OtZRWlFCcnzYBYaK3q+FtboAXZpU2YZUyDNOT2z8f8l9dZXNImPu/A9wflGsVFAHy9fapneKnUw6fFPnX+n66k0LPcf5a2tA/RJ2KPDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524843; c=relaxed/simple; bh=KgX6tpqLLzK+Zt9Of/VVerFFbzU7QT3NK9hBImIckYI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eihcpj+21Um91yWPQkoXFmoi9hBE7fvQA28S4EftlX+DeeESFHy0F3yIXVEaCi8ND2eDYQLiga5uYT058XM02dlyXUD7dQ1goaU/cuH64kyUy8hzT/HYU9R7avvusQuroHuCyynmkyngPzgt7L4KjavEPi2qpj0HxiIh5s9QY1g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkFD-0007YT-PW; Tue, 27 Jan 2026 15:40:40 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:28 +0100 Subject: [PATCH v3 19/27] media: rockchip: rga: support external iommus 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: <20260127-spu-rga3-v3-19-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org In preparation for the RGA3 add support for external iommus. This is a transition step to just disable the RGA2 specific mmu table setup code. Currently a simple rga_hw struct field is used to set the internal iommu. But to handle the case of more sophisticated detection mechanisms (e.g. check for an iommu property in the device tree), it is abstracted by an inline function. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-buf.c | 31 ++++++++++++++++++-----= ---- drivers/media/platform/rockchip/rga/rga-hw.c | 1 + drivers/media/platform/rockchip/rga/rga.c | 11 ++++++++-- drivers/media/platform/rockchip/rga/rga.h | 6 ++++++ 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/= platform/rockchip/rga/rga-buf.c index bc349d0a46365..4e82ca1a5e8d9 100644 --- a/drivers/media/platform/rockchip/rga/rga-buf.c +++ b/drivers/media/platform/rockchip/rga/rga-buf.c @@ -12,6 +12,7 @@ #include #include #include +#include #include =20 #include "rga.h" @@ -82,6 +83,9 @@ static int rga_buf_init(struct vb2_buffer *vb) if (IS_ERR(f)) return PTR_ERR(f); =20 + if (!rga_has_internal_iommu(rga)) + return 0; + n_desc =3D DIV_ROUND_UP(f->size, PAGE_SIZE); =20 rbuf->n_desc =3D n_desc; @@ -136,17 +140,21 @@ static int rga_buf_prepare(struct vb2_buffer *vb) for (i =3D 0; i < vb->num_planes; i++) { vb2_set_plane_payload(vb, i, f->pix.plane_fmt[i].sizeimage); =20 - /* Create local MMU table for RGA */ - n_desc =3D fill_descriptors(&rbuf->dma_desc[curr_desc], - rbuf->n_desc - curr_desc, - vb2_dma_sg_plane_desc(vb, i)); - if (n_desc < 0) { - v4l2_err(&ctx->rga->v4l2_dev, - "Failed to map video buffer to RGA\n"); - return n_desc; + if (rga_has_internal_iommu(ctx->rga)) { + /* Create local MMU table for RGA */ + n_desc =3D fill_descriptors(&rbuf->dma_desc[curr_desc], + rbuf->n_desc - curr_desc, + vb2_dma_sg_plane_desc(vb, i)); + if (n_desc < 0) { + v4l2_err(&ctx->rga->v4l2_dev, + "Failed to map video buffer to RGA\n"); + return n_desc; + } + dma_addrs[i] =3D curr_desc << PAGE_SHIFT; + curr_desc +=3D n_desc; + } else { + dma_addrs[i] =3D vb2_dma_contig_plane_dma_addr(vb, i); } - dma_addrs[i] =3D curr_desc << PAGE_SHIFT; - curr_desc +=3D n_desc; } =20 /* Fill the remaining planes */ @@ -176,6 +184,9 @@ static void rga_buf_cleanup(struct vb2_buffer *vb) struct rga_ctx *ctx =3D vb2_get_drv_priv(vb->vb2_queue); struct rockchip_rga *rga =3D ctx->rga; =20 + if (!rga_has_internal_iommu(rga)) + return; + dma_free_coherent(rga->dev, rbuf->n_desc * sizeof(*rbuf->dma_desc), rbuf->dma_desc, rbuf->dma_desc_pa); } diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index bf4a86a640ec5..2013b59701d12 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -577,6 +577,7 @@ static struct rga_fmt formats[] =3D { =20 const struct rga_hw rga2_hw =3D { .card_type =3D "rga2", + .has_internal_iommu =3D true, .formats =3D formats, .num_formats =3D ARRAY_SIZE(formats), .cmdbuf_size =3D RGA_CMDBUF_SIZE, diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index f33e2288dab6f..b13ff8d7c572c 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -23,6 +23,7 @@ #include #include #include +#include #include =20 #include "rga.h" @@ -95,7 +96,10 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct = vb2_queue *dst_vq) src_vq->io_modes =3D VB2_MMAP | VB2_DMABUF; src_vq->drv_priv =3D ctx; src_vq->ops =3D &rga_qops; - src_vq->mem_ops =3D &vb2_dma_sg_memops; + if (rga_has_internal_iommu(ctx->rga)) + src_vq->mem_ops =3D &vb2_dma_sg_memops; + else + src_vq->mem_ops =3D &vb2_dma_contig_memops; src_vq->gfp_flags =3D __GFP_DMA32; src_vq->buf_struct_size =3D sizeof(struct rga_vb_buffer); src_vq->timestamp_flags =3D V4L2_BUF_FLAG_TIMESTAMP_COPY; @@ -110,7 +114,10 @@ queue_init(void *priv, struct vb2_queue *src_vq, struc= t vb2_queue *dst_vq) dst_vq->io_modes =3D VB2_MMAP | VB2_DMABUF; dst_vq->drv_priv =3D ctx; dst_vq->ops =3D &rga_qops; - dst_vq->mem_ops =3D &vb2_dma_sg_memops; + if (rga_has_internal_iommu(ctx->rga)) + dst_vq->mem_ops =3D &vb2_dma_sg_memops; + else + dst_vq->mem_ops =3D &vb2_dma_contig_memops; dst_vq->gfp_flags =3D __GFP_DMA32; dst_vq->buf_struct_size =3D sizeof(struct rga_vb_buffer); dst_vq->timestamp_flags =3D V4L2_BUF_FLAG_TIMESTAMP_COPY; diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 025b1df594e9a..95fa7fd1c509a 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -146,6 +146,7 @@ static inline void rga_mod(struct rockchip_rga *rga, u3= 2 reg, u32 val, u32 mask) =20 struct rga_hw { const char *card_type; + bool has_internal_iommu; struct rga_fmt *formats; u32 num_formats; size_t cmdbuf_size; @@ -161,6 +162,11 @@ struct rga_hw { void (*get_version)(struct rockchip_rga *rga); }; =20 +static inline bool rga_has_internal_iommu(const struct rockchip_rga *rga) +{ + return rga->hw->has_internal_iommu; +} + extern const struct rga_hw rga2_hw; =20 #endif --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 676DA3644A3 for ; Tue, 27 Jan 2026 14:40:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524846; cv=none; b=b9L1La7wmK7DbLbI7vlBdRYueyJRaNN1gVeqfjs0Hr3av0W+VxmqIuL/izAtb3XleemE3pZYVXMOXJxaA6wVVp/c7Rk2+oWFTWemwdAX5QSyaahYEsUlM3oOPQSndADRXwhgs8iiROI0C8ffES7OnlqZDeCq4l/bkNVAcMMIMgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524846; c=relaxed/simple; bh=IlkjocgXxDhqK4HVHh5k/9rnXOdSgoc0MSweffvzge4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GptkqeW98suYQtlHfagymqpADx1TflxY1Jwm5epHTGvisVqd+wBFZR1x7D+aEyUKzXMBQEXEZ8SDLNvmU32aqEd7LZ3ulLF1gDA790mi5v1nJMg5Hcxu9ijxwahTG2COGjT7lt+AE6+dOgd9MRCTwGEH5L+tIc/kkC2VBzU2lf8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkFG-0007YT-D4; Tue, 27 Jan 2026 15:40:42 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:29 +0100 Subject: [PATCH v3 20/27] media: rockchip: rga: share the interrupt when an external iommu is used 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: <20260127-spu-rga3-v3-20-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= , Michael Olbrich , Nicolas Dufresne X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org From: Michael Olbrich The RGA3 and the corresponding iommu share the interrupt. So in that case, request a shared interrupt so that the iommu driver can request it as well. Signed-off-by: Michael Olbrich Reviewed-by: Nicolas Dufresne Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index b13ff8d7c572c..b2ee59235d1e3 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -761,7 +761,8 @@ static int rga_probe(struct platform_device *pdev) goto err_put_clk; } =20 - ret =3D devm_request_irq(rga->dev, irq, rga_isr, 0, + ret =3D devm_request_irq(rga->dev, irq, rga_isr, + rga_has_internal_iommu(rga) ? 0 : IRQF_SHARED, dev_name(rga->dev), rga); if (ret < 0) { dev_err(rga->dev, "failed to request irq\n"); --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 8DC6035E552 for ; Tue, 27 Jan 2026 14:40:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524848; cv=none; b=MhTZ8YLzo49vFjhW4OmE6s99P+3OjDcPGDDlqEJ75fZ2oNx9k4Ag++tRVe1pPgjSDgQ21y68oOtMhOu6VmKqteSmn4K6ea5rWRIMYpc8RcrJC8jdNDLP+tWRHFKv2GEaJ3y2InX1m2vpWhsVSKYiIb367fORwKqFyBZyMvLIg3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524848; c=relaxed/simple; bh=7dNDc9Ziln25yF+Cbc+nUGgZJbeEAX0pdbqLQFauSEI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o2cn60W+HkDKbORyOV1WLOrEI34iqWEdKW1/wuhmssmumNr4OoOHop06YVQnHSQZBT+F8IFYC6FE410CLCOCWBVo71EOsgg4WdjsnTAmJEjgbs+R2TmGRtl4rL4IZ7ByttZEhu7sNfBWXbsjtxWdr3mFf5fETbdwkg9ufwKeZ1E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkFI-0007YT-GJ; Tue, 27 Jan 2026 15:40:44 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:30 +0100 Subject: [PATCH v3 21/27] media: rockchip: rga: remove size from rga_frame 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: <20260127-spu-rga3-v3-21-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org The size member is only used for the mmu page table mapping. Therefore avoid storing the value and instead only calculate it in place. This also avoids the calculation entirely when an external iommu is used. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-buf.c | 6 +++++- drivers/media/platform/rockchip/rga/rga.c | 8 ++------ drivers/media/platform/rockchip/rga/rga.h | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/= platform/rockchip/rga/rga-buf.c index 4e82ca1a5e8d9..c0cc885ba58a8 100644 --- a/drivers/media/platform/rockchip/rga/rga-buf.c +++ b/drivers/media/platform/rockchip/rga/rga-buf.c @@ -79,6 +79,8 @@ static int rga_buf_init(struct vb2_buffer *vb) struct rockchip_rga *rga =3D ctx->rga; struct rga_frame *f =3D rga_get_frame(ctx, vb->vb2_queue->type); size_t n_desc =3D 0; + u32 size =3D 0; + u8 i; =20 if (IS_ERR(f)) return PTR_ERR(f); @@ -86,7 +88,9 @@ static int rga_buf_init(struct vb2_buffer *vb) if (!rga_has_internal_iommu(rga)) return 0; =20 - n_desc =3D DIV_ROUND_UP(f->size, PAGE_SIZE); + for (i =3D 0; i < f->pix.num_planes; i++) + size +=3D f->pix.plane_fmt[i].sizeimage; + n_desc =3D DIV_ROUND_UP(size, PAGE_SIZE); =20 rbuf->n_desc =3D n_desc; rbuf->dma_desc =3D dma_alloc_coherent(rga->dev, diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index b2ee59235d1e3..59463c7f26b6f 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -221,7 +221,6 @@ static int rga_open(struct file *file) }; =20 def_frame.stride =3D (def_width * def_frame.fmt->depth) >> 3; - def_frame.size =3D def_frame.stride * def_height; =20 ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) @@ -459,9 +458,6 @@ static int vidioc_s_fmt(struct file *file, void *priv, = struct v4l2_format *f) frm =3D rga_get_frame(ctx, f->type); if (IS_ERR(frm)) return PTR_ERR(frm); - frm->size =3D 0; - for (i =3D 0; i < pix_fmt->num_planes; i++) - frm->size +=3D pix_fmt->plane_fmt[i].sizeimage; frm->fmt =3D rga_fmt_find(rga, pix_fmt->pixelformat); frm->stride =3D pix_fmt->plane_fmt[0].bytesperline; =20 @@ -485,10 +481,10 @@ static int vidioc_s_fmt(struct file *file, void *priv= , struct v4l2_format *f) frm->pix =3D *pix_fmt; =20 v4l2_dbg(debug, 1, &rga->v4l2_dev, - "[%s] fmt - %p4cc %dx%d (stride %d, sizeimage %d)\n", + "[%s] fmt - %p4cc %dx%d (stride %d)\n", V4L2_TYPE_IS_OUTPUT(f->type) ? "OUTPUT" : "CAPTURE", &frm->fmt->fourcc, pix_fmt->width, pix_fmt->height, - frm->stride, frm->size); + frm->stride); =20 for (i =3D 0; i < pix_fmt->num_planes; i++) { v4l2_dbg(debug, 1, &rga->v4l2_dev, diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 95fa7fd1c509a..2838fc7785f72 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -34,7 +34,6 @@ struct rga_frame { =20 /* Variables that can calculated once and reused */ u32 stride; - u32 size; }; =20 struct rga_dma_desc { --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 D6FF5364EB2 for ; Tue, 27 Jan 2026 14:40:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524850; cv=none; b=GKnF2uxjZkuGXO7qlWYUiaIAoIkISWmnz5kRjyHdy+yJ4RX+hD/CDynq6K/HHk4MeXIkeh6TARvDpo32H2qxCsrcS52P8aC/Jy9NR6v7DHc2l8fA9R1wyQ0xu2toJ+C7jSVMUcHUQe7lLcvUWTwTSBgHpqMG7g6CBiWV4GQ68FU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524850; c=relaxed/simple; bh=82OxQEPMx3A5useUzoN54EOJjdkBs6evsd2RYUAhzq4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U6zitg/SGHn5IK/h3i/D09C0cXSgAXWSeMt5S4UwNLucA1uERU4xVR2/a45Z95mmCJUi5VFlqICf7V1AE48JqZdpicC7j9kdYgYKQCCDLaB9A7ipUa/y++rX2G5kBMF1Khi0pwY0pE21pmAV9Ds8L57WTxEWfsc9HnKKDAtgZkE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkFK-0007YT-Pu; Tue, 27 Jan 2026 15:40:47 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:31 +0100 Subject: [PATCH v3 22/27] media: rockchip: rga: remove stride from rga_frame 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: <20260127-spu-rga3-v3-22-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= , Nicolas Dufresne X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Remove the stride variable from rga_frame. Despite the comment it didn't involve any calculation and is just a copy of the plane_fmt[0].bytesperline value. Therefore avoid this struct member and use the bytesperline value directly in the places where it is required. Also drop the dependency on the depth format member, which was only used to calculate the stride of the default format. This is already done by the v4l2_fill_pixfmt_mp_aligned helper and used as stride in try_fmt. Therefore using it's value also for the default format stride is just more consistent. Reviewed-by: Nicolas Dufresne Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 36 ++++++++++--------------= ---- drivers/media/platform/rockchip/rga/rga.c | 5 +--- drivers/media/platform/rockchip/rga/rga.h | 4 ---- 3 files changed, 13 insertions(+), 32 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index 2013b59701d12..5d993cf69963d 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -44,7 +44,7 @@ rga_get_corner_addrs(struct rga_frame *frm, struct rga_ad= drs *addrs, struct rga_addrs *lt, *lb, *rt, *rb; const struct v4l2_format_info *format_info; unsigned int x_div =3D 0, - y_div =3D 0, uv_stride =3D 0, pixel_width =3D 0; + y_div =3D 0, y_stride =3D 0, uv_stride =3D 0, pixel_width =3D 0; =20 lt =3D &corner_addrs.left_top; lb =3D &corner_addrs.left_bottom; @@ -61,14 +61,15 @@ rga_get_corner_addrs(struct rga_frame *frm, struct rga_= addrs *addrs, else x_div =3D 1; y_div =3D format_info->vdiv; - uv_stride =3D frm->stride / x_div; - pixel_width =3D frm->stride / frm->pix.width; + y_stride =3D frm->pix.plane_fmt[0].bytesperline; + uv_stride =3D y_stride / x_div; + pixel_width =3D y_stride / frm->pix.width; =20 - lt->y_addr =3D addrs->y_addr + y * frm->stride + x * pixel_width; + lt->y_addr =3D addrs->y_addr + y * y_stride + x * pixel_width; lt->u_addr =3D addrs->u_addr + (y / y_div) * uv_stride + x / x_div; lt->v_addr =3D addrs->v_addr + (y / y_div) * uv_stride + x / x_div; =20 - lb->y_addr =3D lt->y_addr + (h - 1) * frm->stride; + lb->y_addr =3D lt->y_addr + (h - 1) * y_stride; lb->u_addr =3D lt->u_addr + (h / y_div - 1) * uv_stride; lb->v_addr =3D lt->v_addr + (h / y_div - 1) * uv_stride; =20 @@ -169,6 +170,7 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx) union rga_src_act_info src_act_info; union rga_dst_vir_info dst_vir_info; union rga_dst_act_info dst_act_info; + u32 in_stride, out_stride; =20 src_h =3D ctx->in.crop.height; src_w =3D ctx->in.crop.width; @@ -291,13 +293,15 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ct= x) * Calculate the framebuffer virtual strides and active size, * note that the step of vir_stride / vir_width is 4 byte words */ - src_vir_info.data.vir_stride =3D ctx->in.stride >> 2; - src_vir_info.data.vir_width =3D ctx->in.stride >> 2; + in_stride =3D ctx->in.pix.plane_fmt[0].bytesperline; + src_vir_info.data.vir_stride =3D in_stride >> 2; + src_vir_info.data.vir_width =3D in_stride >> 2; =20 src_act_info.data.act_height =3D src_h - 1; src_act_info.data.act_width =3D src_w - 1; =20 - dst_vir_info.data.vir_stride =3D ctx->out.stride >> 2; + out_stride =3D ctx->out.pix.plane_fmt[0].bytesperline; + dst_vir_info.data.vir_stride =3D out_stride >> 2; dst_act_info.data.act_height =3D dst_h - 1; dst_act_info.data.act_width =3D dst_w - 1; =20 @@ -481,97 +485,81 @@ static struct rga_fmt formats[] =3D { .fourcc =3D V4L2_PIX_FMT_ARGB32, .color_swap =3D RGA_COLOR_ALPHA_SWAP, .hw_format =3D RGA_COLOR_FMT_ABGR8888, - .depth =3D 32, }, { .fourcc =3D V4L2_PIX_FMT_ABGR32, .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_ABGR8888, - .depth =3D 32, }, { .fourcc =3D V4L2_PIX_FMT_XBGR32, .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_XBGR8888, - .depth =3D 32, }, { .fourcc =3D V4L2_PIX_FMT_RGB24, .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_RGB888, - .depth =3D 24, }, { .fourcc =3D V4L2_PIX_FMT_BGR24, .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_RGB888, - .depth =3D 24, }, { .fourcc =3D V4L2_PIX_FMT_ARGB444, .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_ABGR4444, - .depth =3D 16, }, { .fourcc =3D V4L2_PIX_FMT_ARGB555, .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_ABGR1555, - .depth =3D 16, }, { .fourcc =3D V4L2_PIX_FMT_RGB565, .color_swap =3D RGA_COLOR_RB_SWAP, .hw_format =3D RGA_COLOR_FMT_BGR565, - .depth =3D 16, }, { .fourcc =3D V4L2_PIX_FMT_NV21, .color_swap =3D RGA_COLOR_UV_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV420SP, - .depth =3D 12, }, { .fourcc =3D V4L2_PIX_FMT_NV61, .color_swap =3D RGA_COLOR_UV_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV422SP, - .depth =3D 16, }, { .fourcc =3D V4L2_PIX_FMT_NV12, .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV420SP, - .depth =3D 12, }, { .fourcc =3D V4L2_PIX_FMT_NV12M, .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV420SP, - .depth =3D 12, }, { .fourcc =3D V4L2_PIX_FMT_NV16, .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV422SP, - .depth =3D 16, }, { .fourcc =3D V4L2_PIX_FMT_YUV420, .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV420P, - .depth =3D 12, }, { .fourcc =3D V4L2_PIX_FMT_YUV422P, .color_swap =3D RGA_COLOR_NONE_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV422P, - .depth =3D 16, }, { .fourcc =3D V4L2_PIX_FMT_YVU420, .color_swap =3D RGA_COLOR_UV_SWAP, .hw_format =3D RGA_COLOR_FMT_YUV420P, - .depth =3D 12, }, }; =20 diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 59463c7f26b6f..30d09ec77afca 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -220,8 +220,6 @@ static int rga_open(struct file *file) .fmt =3D &rga->hw->formats[0], }; =20 - def_frame.stride =3D (def_width * def_frame.fmt->depth) >> 3; - ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) return -ENOMEM; @@ -459,7 +457,6 @@ static int vidioc_s_fmt(struct file *file, void *priv, = struct v4l2_format *f) if (IS_ERR(frm)) return PTR_ERR(frm); frm->fmt =3D rga_fmt_find(rga, pix_fmt->pixelformat); - frm->stride =3D pix_fmt->plane_fmt[0].bytesperline; =20 /* * Copy colorimetry from output to capture as required by the @@ -484,7 +481,7 @@ static int vidioc_s_fmt(struct file *file, void *priv, = struct v4l2_format *f) "[%s] fmt - %p4cc %dx%d (stride %d)\n", V4L2_TYPE_IS_OUTPUT(f->type) ? "OUTPUT" : "CAPTURE", &frm->fmt->fourcc, pix_fmt->width, pix_fmt->height, - frm->stride); + pix_fmt->plane_fmt[0].bytesperline); =20 for (i =3D 0; i < pix_fmt->num_planes; i++) { v4l2_dbg(debug, 1, &rga->v4l2_dev, diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 2838fc7785f72..d203b7dae2b03 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -19,7 +19,6 @@ =20 struct rga_fmt { u32 fourcc; - int depth; u8 color_swap; u8 hw_format; }; @@ -31,9 +30,6 @@ struct rga_frame { /* Image format */ struct rga_fmt *fmt; struct v4l2_pix_format_mplane pix; - - /* Variables that can calculated once and reused */ - u32 stride; }; =20 struct rga_dma_desc { --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 74F84364EB9 for ; Tue, 27 Jan 2026 14:40:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524853; cv=none; b=DzHOfyzlH3QtzLzqd7le9SfyDkJUmnXFAbiImc8H5261j5qK/pw/rfwD8RzkfBrnVlO8KWLETwIz0XOOpg3jLWe8hemWuha9k2FWtIHq3dN+RSvXCjiGvTRs9o+jZEs/MhIS/m3k30LDR24VlCZon1D+FR0mJhU1zGJaKEHPnak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524853; c=relaxed/simple; bh=jVCIMtQ5Oc39w6WM/yRgF86Yn2ql20o6yBm4CyY0j4k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XGF/J38dE2MPKgqT/swzu55xUmqCPZtX/VZ+LjQZFbFPKEBS0dpke2fjFwx51m78AQUzmhxaPFJLwaorYrmdHCjpYfLyftwnbNt76+hfdwVl5VOzVIMQuu2ss0Ps1VszJuwRp+SgVN34o2MR3i45iXmtWLj7tyMRBKUIEYrXjRM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkFN-0007YT-4l; Tue, 27 Jan 2026 15:40:49 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:32 +0100 Subject: [PATCH v3 23/27] media: rockchip: rga: move rga_fmt to rga-hw.h 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: <20260127-spu-rga3-v3-23-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= , Nicolas Dufresne X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Move rga_fmt to rga-hw in preparation of the RGA3 addition, as the struct contains many RGA2 specific values. They are used to write the correct register values quickly based on the chosen format. Therefore the pointer to the rga_fmt struct is kept but changed to an opaque void pointer outside of the rga-hw.h. To enumerate and set the correct formats, two helper functions need to be exposed in the rga_hw struct: enum_format just get's the vidioc_enum_fmt format and it's return value is also returned from vidioc_enum_fmt. This is a simple pass-through, as the implementation is very simple. adjust_and_map_format is a simple abstraction around the previous rga_find_format. But unlike rga_find_format, it always returns a valid format. Therefore the passed format value is also a pointer to update it in case the values are not supported by the hardware. Due to the RGA3 supporting different formats on the capture and output side, an additional parameter is_capture has been added to support this use-case. The additional ctx parameter is also added to allow the RGA3 to limit the colorimetry only if an RGB<->YCrCb transformation happens. Reviewed-by: Nicolas Dufresne Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-buf.c | 2 +- drivers/media/platform/rockchip/rga/rga-hw.c | 49 +++++++++++++++++++++--= ---- drivers/media/platform/rockchip/rga/rga-hw.h | 8 +++++ drivers/media/platform/rockchip/rga/rga.c | 39 +++++++-------------- drivers/media/platform/rockchip/rga/rga.h | 14 +++----- 5 files changed, 66 insertions(+), 46 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/= platform/rockchip/rga/rga-buf.c index c0cc885ba58a8..8632b18cd3fc6 100644 --- a/drivers/media/platform/rockchip/rga/rga-buf.c +++ b/drivers/media/platform/rockchip/rga/rga-buf.c @@ -162,7 +162,7 @@ static int rga_buf_prepare(struct vb2_buffer *vb) } =20 /* Fill the remaining planes */ - info =3D v4l2_format_info(f->fmt->fourcc); + info =3D v4l2_format_info(f->pix.pixelformat); for (i =3D info->mem_planes; i < info->comp_planes; i++) dma_addrs[i] =3D dma_addrs[0] + get_plane_offset(f, info, i); =20 diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index 5d993cf69963d..e76d1994b8684 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -171,6 +171,8 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx) union rga_dst_vir_info dst_vir_info; union rga_dst_act_info dst_act_info; u32 in_stride, out_stride; + struct rga_fmt *in_fmt =3D ctx->in.fmt; + struct rga_fmt *out_fmt =3D ctx->out.fmt; =20 src_h =3D ctx->in.crop.height; src_w =3D ctx->in.crop.width; @@ -186,18 +188,18 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ct= x) dst_vir_info.val =3D dest[(RGA_DST_VIR_INFO - RGA_MODE_BASE_REG) >> 2]; dst_act_info.val =3D dest[(RGA_DST_ACT_INFO - RGA_MODE_BASE_REG) >> 2]; =20 - src_info.data.format =3D ctx->in.fmt->hw_format; - src_info.data.swap =3D ctx->in.fmt->color_swap; - dst_info.data.format =3D ctx->out.fmt->hw_format; - dst_info.data.swap =3D ctx->out.fmt->color_swap; + src_info.data.format =3D in_fmt->hw_format; + src_info.data.swap =3D in_fmt->color_swap; + dst_info.data.format =3D out_fmt->hw_format; + dst_info.data.swap =3D out_fmt->color_swap; =20 /* * CSC mode must only be set when the colorspace families differ between * input and output. It must remain unset (zeroed) if both are the same. */ =20 - if (RGA_COLOR_FMT_IS_YUV(ctx->in.fmt->hw_format) && - RGA_COLOR_FMT_IS_RGB(ctx->out.fmt->hw_format)) { + if (RGA_COLOR_FMT_IS_YUV(in_fmt->hw_format) && + RGA_COLOR_FMT_IS_RGB(out_fmt->hw_format)) { switch (ctx->in.pix.colorspace) { case V4L2_COLORSPACE_REC709: src_info.data.csc_mode =3D RGA_SRC_CSC_MODE_BT709_R0; @@ -208,8 +210,8 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx) } } =20 - if (RGA_COLOR_FMT_IS_RGB(ctx->in.fmt->hw_format) && - RGA_COLOR_FMT_IS_YUV(ctx->out.fmt->hw_format)) { + if (RGA_COLOR_FMT_IS_RGB(in_fmt->hw_format) && + RGA_COLOR_FMT_IS_YUV(out_fmt->hw_format)) { switch (ctx->out.pix.colorspace) { case V4L2_COLORSPACE_REC709: dst_info.data.csc_mode =3D RGA_SRC_CSC_MODE_BT709_R0; @@ -563,11 +565,36 @@ static struct rga_fmt formats[] =3D { }, }; =20 +static void *rga_adjust_and_map_format(struct rga_ctx *ctx, + struct v4l2_pix_format_mplane *format, + bool is_output) +{ + unsigned int i; + + if (!format) + return &formats[0]; + + for (i =3D 0; i < ARRAY_SIZE(formats); i++) { + if (formats[i].fourcc =3D=3D format->pixelformat) + return &formats[i]; + } + + format->pixelformat =3D formats[0].fourcc; + return &formats[0]; +} + +static int rga_enum_format(struct v4l2_fmtdesc *f) +{ + if (f->index >=3D ARRAY_SIZE(formats)) + return -EINVAL; + + f->pixelformat =3D formats[f->index].fourcc; + return 0; +} + const struct rga_hw rga2_hw =3D { .card_type =3D "rga2", .has_internal_iommu =3D true, - .formats =3D formats, - .num_formats =3D ARRAY_SIZE(formats), .cmdbuf_size =3D RGA_CMDBUF_SIZE, .min_width =3D MIN_WIDTH, .max_width =3D MAX_WIDTH, @@ -580,4 +607,6 @@ const struct rga_hw rga2_hw =3D { .start =3D rga_hw_start, .handle_irq =3D rga_handle_irq, .get_version =3D rga_get_version, + .adjust_and_map_format =3D rga_adjust_and_map_format, + .enum_format =3D rga_enum_format, }; diff --git a/drivers/media/platform/rockchip/rga/rga-hw.h b/drivers/media/p= latform/rockchip/rga/rga-hw.h index fffcab0131225..039a3e868733e 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.h +++ b/drivers/media/platform/rockchip/rga/rga-hw.h @@ -6,6 +6,8 @@ #ifndef __RGA_HW_H__ #define __RGA_HW_H__ =20 +#include + #define RGA_CMDBUF_SIZE 0x20 =20 /* Hardware limits */ @@ -431,4 +433,10 @@ union rga_pat_con { } data; }; =20 +struct rga_fmt { + u32 fourcc; + u8 color_swap; + u8 hw_format; +}; + #endif diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 30d09ec77afca..c1371ad0b1ea1 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -185,17 +185,6 @@ static int rga_setup_ctrls(struct rga_ctx *ctx) return 0; } =20 -static struct rga_fmt *rga_fmt_find(struct rockchip_rga *rga, u32 pixelfor= mat) -{ - unsigned int i; - - for (i =3D 0; i < rga->hw->num_formats; i++) { - if (rga->hw->formats[i].fourcc =3D=3D pixelformat) - return &rga->hw->formats[i]; - } - return NULL; -} - struct rga_frame *rga_get_frame(struct rga_ctx *ctx, enum v4l2_buf_type ty= pe) { if (V4L2_TYPE_IS_OUTPUT(type)) @@ -217,7 +206,6 @@ static int rga_open(struct file *file) .crop.top =3D 0, .crop.width =3D def_width, .crop.height =3D def_height, - .fmt =3D &rga->hw->formats[0], }; =20 ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); @@ -238,9 +226,12 @@ static int rga_open(struct file *file) ctx->in =3D def_frame; ctx->out =3D def_frame; =20 - v4l2_fill_pixfmt_mp_aligned(&ctx->in.pix, ctx->in.fmt->fourcc, + ctx->in.fmt =3D rga->hw->adjust_and_map_format(ctx, &ctx->in.pix, true); + v4l2_fill_pixfmt_mp_aligned(&ctx->in.pix, ctx->in.pix.pixelformat, def_width, def_height, rga->hw->stride_alignment); - v4l2_fill_pixfmt_mp_aligned(&ctx->out.pix, ctx->out.fmt->fourcc, + ctx->out.fmt =3D + rga->hw->adjust_and_map_format(ctx, &ctx->out.pix, false); + v4l2_fill_pixfmt_mp_aligned(&ctx->out.pix, ctx->out.pix.pixelformat, def_width, def_height, rga->hw->stride_alignment); =20 if (mutex_lock_interruptible(&rga->mutex)) { @@ -322,13 +313,11 @@ vidioc_querycap(struct file *file, void *priv, struct= v4l2_capability *cap) static int vidioc_enum_fmt(struct file *file, void *priv, struct v4l2_fmtd= esc *f) { struct rockchip_rga *rga =3D video_drvdata(file); - struct rga_fmt *fmt; - - if (f->index >=3D rga->hw->num_formats) - return -EINVAL; + int ret; =20 - fmt =3D &rga->hw->formats[f->index]; - f->pixelformat =3D fmt->fourcc; + ret =3D rga->hw->enum_format(f); + if (ret !=3D 0) + return ret; =20 if (f->type !=3D V4L2_BUF_TYPE_VIDEO_CAPTURE && f->type !=3D V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) @@ -363,7 +352,6 @@ static int vidioc_try_fmt(struct file *file, void *priv= , struct v4l2_format *f) struct v4l2_pix_format_mplane *pix_fmt =3D &f->fmt.pix_mp; struct rga_ctx *ctx =3D file_to_rga_ctx(file); const struct rga_hw *hw =3D ctx->rga->hw; - struct rga_fmt *fmt; struct v4l2_frmsize_stepwise frmsize =3D { .min_width =3D hw->min_width, .max_width =3D hw->max_width, @@ -394,9 +382,7 @@ static int vidioc_try_fmt(struct file *file, void *priv= , struct v4l2_format *f) pix_fmt->xfer_func =3D frm->pix.xfer_func; } =20 - fmt =3D rga_fmt_find(ctx->rga, pix_fmt->pixelformat); - if (!fmt) - fmt =3D &hw->formats[0]; + hw->adjust_and_map_format(ctx, pix_fmt, V4L2_TYPE_IS_OUTPUT(f->type)); =20 v4l2_apply_frmsize_constraints(&pix_fmt->width, &pix_fmt->height, &frmsiz= e); v4l2_fill_pixfmt_mp_aligned(pix_fmt, pix_fmt->pixelformat, @@ -456,7 +442,8 @@ static int vidioc_s_fmt(struct file *file, void *priv, = struct v4l2_format *f) frm =3D rga_get_frame(ctx, f->type); if (IS_ERR(frm)) return PTR_ERR(frm); - frm->fmt =3D rga_fmt_find(rga, pix_fmt->pixelformat); + frm->fmt =3D rga->hw->adjust_and_map_format(ctx, pix_fmt, + V4L2_TYPE_IS_OUTPUT(f->type)); =20 /* * Copy colorimetry from output to capture as required by the @@ -480,7 +467,7 @@ static int vidioc_s_fmt(struct file *file, void *priv, = struct v4l2_format *f) v4l2_dbg(debug, 1, &rga->v4l2_dev, "[%s] fmt - %p4cc %dx%d (stride %d)\n", V4L2_TYPE_IS_OUTPUT(f->type) ? "OUTPUT" : "CAPTURE", - &frm->fmt->fourcc, pix_fmt->width, pix_fmt->height, + &pix_fmt->pixelformat, pix_fmt->width, pix_fmt->height, pix_fmt->plane_fmt[0].bytesperline); =20 for (i =3D 0; i < pix_fmt->num_planes; i++) { diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index d203b7dae2b03..d98e57c6d7b57 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -17,18 +17,12 @@ #define DEFAULT_WIDTH 100 #define DEFAULT_HEIGHT 100 =20 -struct rga_fmt { - u32 fourcc; - u8 color_swap; - u8 hw_format; -}; - struct rga_frame { /* Crop */ struct v4l2_rect crop; =20 /* Image format */ - struct rga_fmt *fmt; + void *fmt; struct v4l2_pix_format_mplane pix; }; =20 @@ -142,8 +136,6 @@ static inline void rga_mod(struct rockchip_rga *rga, u3= 2 reg, u32 val, u32 mask) struct rga_hw { const char *card_type; bool has_internal_iommu; - struct rga_fmt *formats; - u32 num_formats; size_t cmdbuf_size; u32 min_width, min_height; u32 max_width, max_height; @@ -155,6 +147,10 @@ struct rga_hw { struct rga_vb_buffer *src, struct rga_vb_buffer *dst); bool (*handle_irq)(struct rockchip_rga *rga); void (*get_version)(struct rockchip_rga *rga); + void *(*adjust_and_map_format)(struct rga_ctx *ctx, + struct v4l2_pix_format_mplane *format, + bool is_output); + int (*enum_format)(struct v4l2_fmtdesc *f); }; =20 static inline bool rga_has_internal_iommu(const struct rockchip_rga *rga) --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 383EC364EB2 for ; Tue, 27 Jan 2026 14:40:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524856; cv=none; b=sI5jXi82uWFWkoSS7LHY6HBbx2+uIoEmQxfE+cq7ZsjOozLUJOIIVSeVpGJllm698wUHhctEPuV9AHWGz1lZu6N61014P8ZrFADoFbhqqxqYx9wecPE8c5zD+0U8+BDUEH5sE3eYEKSyvROw9C8mpq2FLkuu8KRNeyHGmX1/KLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524856; c=relaxed/simple; bh=cj2M6d2sBy0PrgbNO/4zA3IRn6ezxXjj1ml42vJvcSg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WaBFNwUZupShOWya1iymedIUF/AGb2ttPVL7eF6yryci7Y21WIM1IPJkeo5AbwB0L9NZxmvn7efsofl2PveiG8TxAs9BgUtpSOBaV0eozmhJAPNno3RqnNi/5uOi7zk4AlXpwlt36iJhkS6tGixLBN/3df1dSMNSCyfUZvyG0YI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkFQ-0007YT-43; Tue, 27 Jan 2026 15:40:52 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:33 +0100 Subject: [PATCH v3 24/27] media: rockchip: rga: add feature flags 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: <20260127-spu-rga3-v3-24-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= , Nicolas Dufresne X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org In preparation to the RGA3 addition add feature flags, which can limit the exposed feature set of the video device, like rotating or selection support. This is necessary as the RGA3 doesn't initially implement the full feature set currently exposed by the driver. Reviewed-by: Nicolas Dufresne Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga-hw.c | 4 ++++ drivers/media/platform/rockchip/rga/rga.c | 23 +++++++++++++++-------- drivers/media/platform/rockchip/rga/rga.h | 7 +++++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c b/drivers/media/p= latform/rockchip/rga/rga-hw.c index e76d1994b8684..c7b68b27f89b2 100644 --- a/drivers/media/platform/rockchip/rga/rga-hw.c +++ b/drivers/media/platform/rockchip/rga/rga-hw.c @@ -602,6 +602,10 @@ const struct rga_hw rga2_hw =3D { .max_height =3D MAX_HEIGHT, .max_scaling_factor =3D MAX_SCALING_FACTOR, .stride_alignment =3D 4, + .features =3D RGA_FEATURE_FLIP + | RGA_FEATURE_ROTATE + | RGA_FEATURE_BG_COLOR + | RGA_FEATURE_SELECTION, =20 .setup_cmdbuf =3D rga_hw_setup_cmdbuf, .start =3D rga_hw_start, diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index c1371ad0b1ea1..43644995c152e 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -162,17 +162,21 @@ static int rga_setup_ctrls(struct rga_ctx *ctx) =20 v4l2_ctrl_handler_init(&ctx->ctrl_handler, 4); =20 - v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops, - V4L2_CID_HFLIP, 0, 1, 1, 0); + if (rga->hw->features & RGA_FEATURE_FLIP) { + v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops, + V4L2_CID_HFLIP, 0, 1, 1, 0); =20 - v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops, - V4L2_CID_VFLIP, 0, 1, 1, 0); + v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops, + V4L2_CID_VFLIP, 0, 1, 1, 0); + } =20 - v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops, - V4L2_CID_ROTATE, 0, 270, 90, 0); + if (rga->hw->features & RGA_FEATURE_ROTATE) + v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops, + V4L2_CID_ROTATE, 0, 270, 90, 0); =20 - v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops, - V4L2_CID_BG_COLOR, 0, 0xffffffff, 1, 0); + if (rga->hw->features & RGA_FEATURE_BG_COLOR) + v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops, + V4L2_CID_BG_COLOR, 0, 0xffffffff, 1, 0); =20 if (ctx->ctrl_handler.error) { int err =3D ctx->ctrl_handler.error; @@ -536,6 +540,9 @@ static int vidioc_s_selection(struct file *file, void *= priv, struct rga_frame *f; int ret =3D 0; =20 + if (!(rga->hw->features & RGA_FEATURE_SELECTION)) + return -EINVAL; + f =3D rga_get_frame(ctx, s->type); if (IS_ERR(f)) return PTR_ERR(f); diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index d98e57c6d7b57..849b96392b780 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -6,6 +6,7 @@ #ifndef __RGA_H__ #define __RGA_H__ =20 +#include #include #include #include @@ -133,6 +134,11 @@ static inline void rga_mod(struct rockchip_rga *rga, u= 32 reg, u32 val, u32 mask) rga_write(rga, reg, temp); }; =20 +#define RGA_FEATURE_FLIP BIT(0) +#define RGA_FEATURE_ROTATE BIT(1) +#define RGA_FEATURE_BG_COLOR BIT(2) +#define RGA_FEATURE_SELECTION BIT(3) + struct rga_hw { const char *card_type; bool has_internal_iommu; @@ -141,6 +147,7 @@ struct rga_hw { u32 max_width, max_height; u8 max_scaling_factor; u8 stride_alignment; + u8 features; =20 void (*setup_cmdbuf)(struct rga_ctx *ctx); void (*start)(struct rockchip_rga *rga, --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 22E24365A0D for ; Tue, 27 Jan 2026 14:40:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524860; cv=none; b=UnoVWXjyPkEw0YZpQ42zg8TM+0r7STEp2ksz27KMavQQI6p33RDKerdgt1s/GhYcCS1FJOeDqb/MaHPF0V2uBYCBUQALuzxRGjqZdL1iNTJqNHUiO0s1Td6ApOUJb23kD34hh1ThAXHeMsYwt3ZSm5dQG6fYhPvwCyiPvZw6acs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524860; c=relaxed/simple; bh=MywVxrn1inXy0jLeAB6sTXMhpkXU8JKjq05VAMNLxcY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cwg+Rc+3WsAYNTwN+FBfFOvQ4L+XGpe5yGE97Pxm3qO+4amNEyMV0LsStAKYJNTJgxyNDSG7+C3arLCIlE85RgrParvv9d5hagg4gBL+lP1Ox69vttVgGXfvwj5MWMo8v64qKww6HIcgop/hjBONj+R7uF7iXo8jBkIO8JLzcFo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkFS-0007YT-EG; Tue, 27 Jan 2026 15:40:54 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:34 +0100 Subject: [PATCH v3 25/27] media: rockchip: rga: disable multi-core support 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: <20260127-spu-rga3-v3-25-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Disable multi-core support in preparation of the RGA3 addition. The RK3588 SoC features two equal RGA3 cores. This allows scheduling of the work between both cores, which is not yet implemented. Until it is implemented avoid exposing both cores as independent video devices to prevent an ABI breakage when multi-core support is added. This patch is copied from the Hantro driver patch to disable multi core support by Sebastian Reichel. See commit ccdeb8d57f7f ("media: hantro: Disable multicore support") Link: https://lore.kernel.org/all/20240618183816.77597-4-sebastian.reichel@= collabora.com/ Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 47 +++++++++++++++++++++++++++= ++++ 1 file changed, 47 insertions(+) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index 43644995c152e..e45b9c853d659 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -708,6 +708,49 @@ static int rga_parse_dt(struct rockchip_rga *rga) return 0; } =20 +/* + * Some SoCs, like RK3588 have multiple identical RGA3 cores, but the + * kernel is currently missing support for multi-core handling. Exposing + * separate devices for each core to userspace is bad, since that does + * not allow scheduling tasks properly (and creates ABI). With this workar= ound + * the driver will only probe for the first core and early exit for the ot= her + * cores. Once the driver gains multi-core support, the same technique + * for detecting the main core can be used to cluster all cores together. + */ +static int rga_disable_multicore(struct device *dev) +{ + struct device_node *node =3D NULL; + const char *compatible; + bool is_main_core; + int ret; + + /* Intentionally ignores the fallback strings */ + ret =3D of_property_read_string(dev->of_node, "compatible", &compatible); + if (ret) + return ret; + + /* The first compatible and available node found is considered the main c= ore */ + do { + node =3D of_find_compatible_node(node, NULL, compatible); + if (of_device_is_available(node)) + break; + } while (node); + + if (!node) + return -EINVAL; + + is_main_core =3D (dev->of_node =3D=3D node); + + of_node_put(node); + + if (!is_main_core) { + dev_info(dev, "missing multi-core support, ignoring this instance\n"); + return -ENODEV; + } + + return 0; +} + static int rga_probe(struct platform_device *pdev) { struct rockchip_rga *rga; @@ -718,6 +761,10 @@ static int rga_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; =20 + ret =3D rga_disable_multicore(&pdev->dev); + if (ret) + return ret; + rga =3D devm_kzalloc(&pdev->dev, sizeof(*rga), GFP_KERNEL); if (!rga) return -ENOMEM; --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 E254A35CB7E for ; Tue, 27 Jan 2026 14:40:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524863; cv=none; b=dH59xW8ktRhEztYDuFCtj3iSc8iG0mYCNnX9vExW2bfkYj/ijVEv5HS3qRnyOvccnn++fR3Fd/G93h113oEqDLAu990KGZLQP5cH+/+sC/+Bd6QRShoEfbVP1JDc1uh+aPiR2BxdiWpvOm9KILYKig5PB8AUtYlNaORznSR/E/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524863; c=relaxed/simple; bh=IJ2ot6iFkxjAL3a6s0ThDP0NBp0uTIYFm9HxpxuIEVA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rvyRmI6hJwrX10CKHWu0BVw81155MX8yFuDsNA6QnPHuFZOMwQAn41FwyXLQmOCtWGfpbXh4R3FxCwZBC2jeKtHwqoKklhAfCq0VSVOUZ+lk/YJIVCmmq07Z94+K8eCMg/gOw2bK+7fNYgVhklibmW6iJxDIOS387i8uEf0KbMI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkFU-0007YT-NH; Tue, 27 Jan 2026 15:40:57 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:35 +0100 Subject: [PATCH v3 26/27] media: rockchip: rga: add rga3 support 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: <20260127-spu-rga3-v3-26-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add support for the RGA3 unit contained in the RK3588. Only a basic feature set consisting of scaling and color conversion is implemented. Currently unimplemented features include: - Advanced formats like 10bit YUV, FBCE mode and Tile8x8 mode - Background color (V4L2_CID_BG_COLOR) - Configurable alpha value (V4L2_CID_ALPHA_COMPONENT) - Image flipping (V4L2_CID_HFLIP and V4L2_CID_VFLIP) - Image rotation (V4L2_CID_ROTATE) - Image cropping/composing (VIDIOC_S_SELECTION) - Only very basic output cropping for 1088 -> 1080 cases is implemented The register address defines were copied from the vendor Rockchip kernel sources and slightly adjusted to not start at 0 again for the cmd registers. During testing it has been noted that the scaling of the hardware is slightly incorrect. A test conversion of 128x128 RGBA to 256x256 RGBA causes a slightly larger scaling. The scaling is suddle, as it seems that the image is scaled to a 2px larger version and then cropped to it's final size. Trying to use the RGA2 scaling factor calculation didn't work. As the calculation matches the vendor kernel driver, no further research has been utilized to check if there may be some kind of better scaling factor calculation. Furthermore comparing the RGA3 conversion with the GStreamer videoconvertscale element, the chroma-site is different. A quick testing didn't reveal a chroma-site that creates the same image with the GStreamer Element. Also when converting from YUV to RGB the RGB values differ by 1 or 2. This doesn't seem to be a colorspace conversion issue but rather a slightly different precision on the calculation. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/Makefile | 2 +- drivers/media/platform/rockchip/rga/rga.c | 4 + drivers/media/platform/rockchip/rga/rga.h | 1 + drivers/media/platform/rockchip/rga/rga3-hw.c | 507 ++++++++++++++++++++++= ++++ drivers/media/platform/rockchip/rga/rga3-hw.h | 192 ++++++++++ 5 files changed, 705 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/rockchip/rga/Makefile b/drivers/media/p= latform/rockchip/rga/Makefile index 1bbecdc3d8df2..7326a548f3dc7 100644 --- a/drivers/media/platform/rockchip/rga/Makefile +++ b/drivers/media/platform/rockchip/rga/Makefile @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only -rockchip-rga-objs :=3D rga.o rga-hw.o rga-buf.o +rockchip-rga-objs :=3D rga.o rga-hw.o rga3-hw.o rga-buf.o =20 obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) +=3D rockchip-rga.o diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index e45b9c853d659..dd08c3a70a735 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -910,6 +910,10 @@ static const struct of_device_id rockchip_rga_match[] = =3D { .compatible =3D "rockchip,rk3399-rga", .data =3D &rga2_hw, }, + { + .compatible =3D "rockchip,rk3588-rga3", + .data =3D &rga3_hw, + }, {}, }; =20 diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index 849b96392b780..bb225549db86e 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -166,5 +166,6 @@ static inline bool rga_has_internal_iommu(const struct = rockchip_rga *rga) } =20 extern const struct rga_hw rga2_hw; +extern const struct rga_hw rga3_hw; =20 #endif diff --git a/drivers/media/platform/rockchip/rga/rga3-hw.c b/drivers/media/= platform/rockchip/rga/rga3-hw.c new file mode 100644 index 0000000000000..213650edab962 --- /dev/null +++ b/drivers/media/platform/rockchip/rga/rga3-hw.c @@ -0,0 +1,507 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2025-2026 Pengutronix e.K. + * Author: Sven P=C3=BCschel + */ + +#include +#include +#include +#include + +#include + +#include "rga3-hw.h" +#include "rga.h" + +static unsigned int rga3_get_scaling(unsigned int src, unsigned int dst) +{ + /* + * RGA3 scaling factor calculation as described in chapter 5.4.7 Resize + * of the TRM Part 2. The resulting scaling factor is a 16-bit value + * and therefore normalized with 2^16. + * + * While the TRM also mentions (dst-1)/(src-1) for the up-scaling case, + * it didn't work as the value always exceeds 16 bit. Flipping the + * factors results in a correct up-scaling. This is possible as the + * RGA3 has the RGA3_WIN_SCALE_XXX_UP bit to determine if it does + * an up or downscale. + * + * The scaling factor can potentially cause a slightly larger scaling + * (e.g. 1/2px larger scale and then cropped to the destination size). + * This can be seen when scaling 128x128px RGBA to 256x256px RGBA. + * The RGA2 scaling factor calculation (without the various +/-1 + * doesn't work for the RGA3. It's assumed that this is an hardware + * accuracy limitation, as the vendor kernel driver uses the same + * scaling factor calculation. + * + * With a scaling factor of 1.0 the calculation technically also + * overflows 16 bit. This isn't relevant, as in this case the + * RGA3_WIN_SCALE_XXX_BYPASS bit completely skips the scaling operation. + */ + if (dst > src) { + if (((src - 1) << 16) % (dst - 1) =3D=3D 0) + return ((src - 1) << 16) / (dst - 1) - 1; + else + return ((src - 1) << 16) / (dst - 1); + } else { + return ((dst - 1) << 16) / (src - 1) + 1; + } +} + +/* + * Check if the given format can be captured, as the RGA3 doesn't support = all + * input formats also on it's output. + */ +static bool rga3_can_capture(const struct rga3_fmt *fmt) +{ + return fmt->hw_format <=3D RGA3_COLOR_FMT_LAST_OUTPUT; +} + +/* + * Map the transformations to the RGA3 command buffer. + * Currently this is just the scaling settings and a fixed alpha value. + */ +static void rga3_cmd_set_trans_info(struct rga_ctx *ctx) +{ + u32 *cmd =3D ctx->cmdbuf_virt; + unsigned int src_h, src_w, dst_h, dst_w; + unsigned int reg; + u16 hor_scl_fac, ver_scl_fac; + const struct rga3_fmt *in =3D ctx->in.fmt; + + /* Support basic input cropping to support 1088px inputs */ + src_h =3D ctx->in.crop.height; + src_w =3D ctx->in.crop.width; + dst_h =3D ctx->out.pix.height; + dst_w =3D ctx->out.pix.width; + + reg =3D RGA3_WIN0_RD_CTRL - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] |=3D FIELD_PREP(RGA3_WIN_SCALE_HOR_UP, dst_w > src_w) + | FIELD_PREP(RGA3_WIN_SCALE_HOR_BYPASS, dst_w =3D=3D src_w) + | FIELD_PREP(RGA3_WIN_SCALE_VER_UP, dst_h > src_h) + | FIELD_PREP(RGA3_WIN_SCALE_VER_BYPASS, dst_h =3D=3D src_h); + + hor_scl_fac =3D rga3_get_scaling(src_w, dst_w); + ver_scl_fac =3D rga3_get_scaling(src_h, dst_h); + reg =3D RGA3_WIN0_SCL_FAC - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_SCALE_HOR_FAC, hor_scl_fac) + | FIELD_PREP(RGA3_SCALE_VER_FAC, ver_scl_fac); + + if (v4l2_format_info(in->fourcc)->has_alpha) { + /* copy alpha from input */ + reg =3D RGA3_OVLP_TOP_ALPHA - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_ALPHA_SELECT_MODE, 1) + | FIELD_PREP(RGA3_ALPHA_BLEND_MODE, 1); + reg =3D RGA3_OVLP_BOT_ALPHA - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_ALPHA_SELECT_MODE, 1) + | FIELD_PREP(RGA3_ALPHA_BLEND_MODE, 1); + } else { + /* just use a 255 alpha value */ + reg =3D RGA3_OVLP_TOP_CTRL - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_OVLP_GLOBAL_ALPHA, 0xff) + | FIELD_PREP(RGA3_OVLP_COLOR_MODE, 1); + reg =3D RGA3_OVLP_BOT_CTRL - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_OVLP_GLOBAL_ALPHA, 0xff) + | FIELD_PREP(RGA3_OVLP_COLOR_MODE, 1); + } +} + +static void rga3_cmd_set_win0_addr(struct rga_ctx *ctx, + const struct rga_addrs *addrs) +{ + u32 *cmd =3D ctx->cmdbuf_virt; + unsigned int reg; + + reg =3D RGA3_WIN0_Y_BASE - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D addrs->y_addr; + reg =3D RGA3_WIN0_U_BASE - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D addrs->u_addr; +} + +static void rga3_cmd_set_wr_addr(struct rga_ctx *ctx, + const struct rga_addrs *addrs) +{ + u32 *cmd =3D ctx->cmdbuf_virt; + unsigned int reg; + + reg =3D RGA3_WR_Y_BASE - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D addrs->y_addr; + reg =3D RGA3_WR_U_BASE - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D addrs->u_addr; +} + +/* Map the input pixel format to win0 of the comamnd buffer. */ +static void rga3_cmd_set_win0_format(struct rga_ctx *ctx) +{ + u32 *cmd =3D ctx->cmdbuf_virt; + const struct rga3_fmt *in =3D ctx->in.fmt; + const struct rga3_fmt *out =3D ctx->out.fmt; + const struct v4l2_format_info *in_fmt, *out_fmt; + unsigned int act_h, act_w, src_h, src_w; + bool r2y, y2r; + u8 rd_format; + const struct v4l2_pix_format_mplane *csc_pix; + u8 csc_mode; + unsigned int reg; + + act_h =3D ctx->in.pix.height; + act_w =3D ctx->in.pix.width; + /* Support basic input cropping to support 1088px inputs */ + src_h =3D ctx->in.crop.height; + src_w =3D ctx->in.crop.width; + + in_fmt =3D v4l2_format_info(in->fourcc); + out_fmt =3D v4l2_format_info(out->fourcc); + r2y =3D v4l2_is_format_rgb(in_fmt) && v4l2_is_format_yuv(out_fmt); + y2r =3D v4l2_is_format_yuv(in_fmt) && v4l2_is_format_rgb(out_fmt); + + /* The Hardware only supports formats with 1/2 planes */ + if (in_fmt->comp_planes =3D=3D 2) + rd_format =3D RGA3_RDWR_FORMAT_SEMI_PLANAR; + else + rd_format =3D RGA3_RDWR_FORMAT_INTERLEAVED; + + /* set pixel format and CSC */ + csc_pix =3D r2y ? &ctx->out.pix : &ctx->in.pix; + switch (csc_pix->ycbcr_enc) { + case V4L2_YCBCR_ENC_BT2020: + csc_mode =3D RGA3_WIN_CSC_MODE_BT2020_L; + break; + case V4L2_YCBCR_ENC_709: + csc_mode =3D RGA3_WIN_CSC_MODE_BT709_L; + break; + default: /* should be fixed to BT601 in adjust_and_map_format */ + if (csc_pix->quantization =3D=3D V4L2_QUANTIZATION_LIM_RANGE) + csc_mode =3D RGA3_WIN_CSC_MODE_BT601_L; + else + csc_mode =3D RGA3_WIN_CSC_MODE_BT601_F; + break; + } + + reg =3D RGA3_WIN0_RD_CTRL - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] |=3D FIELD_PREP(RGA3_WIN_ENABLE, 1) + | FIELD_PREP(RGA3_WIN_PIC_FORMAT, in->hw_format) + | FIELD_PREP(RGA3_WIN_YC_SWAP, in->yc_swap) + | FIELD_PREP(RGA3_WIN_RBUV_SWAP, in->rbuv_swap) + | FIELD_PREP(RGA3_WIN_RD_FORMAT, rd_format) + | FIELD_PREP(RGA3_WIN_R2Y, r2y) + | FIELD_PREP(RGA3_WIN_Y2R, y2r) + | FIELD_PREP(RGA3_WIN_CSC_MODE, csc_mode); + + /* set stride */ + reg =3D RGA3_WIN0_VIR_STRIDE - RGA3_FIRST_CMD_REG; + /* stride needs to be in words */ + cmd[reg >> 2] =3D ctx->in.pix.plane_fmt[0].bytesperline >> 2; + reg =3D RGA3_WIN0_UV_VIR_STRIDE - RGA3_FIRST_CMD_REG; + /* The Hardware only supports formats with 1/2 planes */ + if (ctx->in.pix.num_planes =3D=3D 2) + cmd[reg >> 2] =3D ctx->in.pix.plane_fmt[1].bytesperline >> 2; + else + cmd[reg >> 2] =3D ctx->in.pix.plane_fmt[0].bytesperline >> 2; + + /* set size */ + reg =3D RGA3_WIN0_ACT_SIZE - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_WIDTH, act_w) + | FIELD_PREP(RGA3_HEIGHT, act_h); + reg =3D RGA3_WIN0_SRC_SIZE - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_WIDTH, src_w) + | FIELD_PREP(RGA3_HEIGHT, src_h); +} + +/* Map the output pixel format to the command buffer */ +static void rga3_cmd_set_wr_format(struct rga_ctx *ctx) +{ + u32 *cmd =3D ctx->cmdbuf_virt; + const struct rga3_fmt *out =3D ctx->out.fmt; + const struct v4l2_format_info *out_fmt; + unsigned int dst_h, dst_w; + u8 wr_format; + unsigned int reg; + + dst_h =3D ctx->out.pix.height; + dst_w =3D ctx->out.pix.width; + + out_fmt =3D v4l2_format_info(out->fourcc); + + /* The Hardware only supports formats with 1/2 planes */ + if (out_fmt->comp_planes =3D=3D 2) + wr_format =3D RGA3_RDWR_FORMAT_SEMI_PLANAR; + else + wr_format =3D RGA3_RDWR_FORMAT_INTERLEAVED; + + /* set pixel format */ + reg =3D RGA3_WR_CTRL - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_WR_PIC_FORMAT, out->hw_format) + | FIELD_PREP(RGA3_WR_YC_SWAP, out->yc_swap) + | FIELD_PREP(RGA3_WR_RBUV_SWAP, out->rbuv_swap) + | FIELD_PREP(RGA3_WR_FORMAT, wr_format) + /* Use the max value to avoid limiting the write speed */ + | FIELD_PREP(RGA3_WR_SW_OUTSTANDING_MAX, 63); + + /* set stride */ + reg =3D RGA3_WR_VIR_STRIDE - RGA3_FIRST_CMD_REG; + /* stride needs to be in words */ + cmd[reg >> 2] =3D ctx->out.pix.plane_fmt[0].bytesperline >> 2; + reg =3D RGA3_WR_PL_VIR_STRIDE - RGA3_FIRST_CMD_REG; + /* The Hardware only supports formats with 1/2 planes */ + if (ctx->out.pix.num_planes =3D=3D 2) + cmd[reg >> 2] =3D ctx->out.pix.plane_fmt[1].bytesperline >> 2; + else + cmd[reg >> 2] =3D ctx->out.pix.plane_fmt[0].bytesperline >> 2; + + /* Set size. + * As two inputs are not supported, we don't use win1. + * Therefore only set the size for win0. + */ + reg =3D RGA3_WIN0_DST_SIZE - RGA3_FIRST_CMD_REG; + cmd[reg >> 2] =3D FIELD_PREP(RGA3_WIDTH, dst_w) + | FIELD_PREP(RGA3_HEIGHT, dst_h); +} + +static void rga3_hw_setup_cmdbuf(struct rga_ctx *ctx) +{ + memset(ctx->cmdbuf_virt, 0, RGA3_CMDBUF_SIZE * 4); + + rga3_cmd_set_win0_format(ctx); + rga3_cmd_set_trans_info(ctx); + rga3_cmd_set_wr_format(ctx); +} + +static void rga3_hw_start(struct rockchip_rga *rga, + struct rga_vb_buffer *src, struct rga_vb_buffer *dst) +{ + struct rga_ctx *ctx =3D rga->curr; + + rga3_cmd_set_win0_addr(ctx, &src->dma_addrs); + rga3_cmd_set_wr_addr(ctx, &dst->dma_addrs); + + rga_write(rga, RGA3_CMD_ADDR, ctx->cmdbuf_phy); + + /* sync CMD buf for RGA */ + dma_sync_single_for_device(rga->dev, ctx->cmdbuf_phy, + PAGE_SIZE, DMA_BIDIRECTIONAL); + + /* set to master mode and start the conversion */ + rga_write(rga, RGA3_SYS_CTRL, + FIELD_PREP(RGA3_CMD_MODE, RGA3_CMD_MODE_MASTER)); + rga_write(rga, RGA3_INT_EN, FIELD_PREP(RGA3_INT_FRM_DONE, 1)); + rga_write(rga, RGA3_CMD_CTRL, + FIELD_PREP(RGA3_CMD_LINE_START_PULSE, 1)); +} + +static bool rga3_handle_irq(struct rockchip_rga *rga) +{ + u32 intr; + + intr =3D rga_read(rga, RGA3_INT_RAW); + /* clear all interrupts */ + rga_write(rga, RGA3_INT_CLR, intr); + + return FIELD_GET(RGA3_INT_FRM_DONE, intr); +} + +static void rga3_get_version(struct rockchip_rga *rga) +{ + u32 version =3D rga_read(rga, RGA3_VERSION_NUM); + + rga->version.major =3D FIELD_GET(RGA3_VERSION_NUM_MAJOR, version); + rga->version.minor =3D FIELD_GET(RGA3_VERSION_NUM_MINOR, version); +} + +static struct rga3_fmt rga3_formats[] =3D { + { + .fourcc =3D V4L2_PIX_FMT_RGB24, + .hw_format =3D RGA3_COLOR_FMT_BGR888, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_BGR24, + .hw_format =3D RGA3_COLOR_FMT_BGR888, + }, + { + .fourcc =3D V4L2_PIX_FMT_ABGR32, + .hw_format =3D RGA3_COLOR_FMT_BGRA8888, + }, + { + .fourcc =3D V4L2_PIX_FMT_RGBA32, + .hw_format =3D RGA3_COLOR_FMT_BGRA8888, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_XBGR32, + .hw_format =3D RGA3_COLOR_FMT_BGRA8888, + }, + { + .fourcc =3D V4L2_PIX_FMT_RGBX32, + .hw_format =3D RGA3_COLOR_FMT_BGRA8888, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_RGB565, + .hw_format =3D RGA3_COLOR_FMT_BGR565, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV12M, + .hw_format =3D RGA3_COLOR_FMT_YUV420, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV12, + .hw_format =3D RGA3_COLOR_FMT_YUV420, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV21M, + .hw_format =3D RGA3_COLOR_FMT_YUV420, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV21, + .hw_format =3D RGA3_COLOR_FMT_YUV420, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV16M, + .hw_format =3D RGA3_COLOR_FMT_YUV422, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV16, + .hw_format =3D RGA3_COLOR_FMT_YUV422, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV61M, + .hw_format =3D RGA3_COLOR_FMT_YUV422, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_NV61, + .hw_format =3D RGA3_COLOR_FMT_YUV422, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_YUYV, + .hw_format =3D RGA3_COLOR_FMT_YUV422, + .yc_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_YVYU, + .hw_format =3D RGA3_COLOR_FMT_YUV422, + .yc_swap =3D 1, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_UYVY, + .hw_format =3D RGA3_COLOR_FMT_YUV422, + }, + { + .fourcc =3D V4L2_PIX_FMT_VYUY, + .hw_format =3D RGA3_COLOR_FMT_YUV422, + .rbuv_swap =3D 1, + }, + /* Input only formats last to keep rga3_enum_format simple */ + { + .fourcc =3D V4L2_PIX_FMT_ARGB32, + .hw_format =3D RGA3_COLOR_FMT_ABGR8888, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_BGRA32, + .hw_format =3D RGA3_COLOR_FMT_ABGR8888, + }, + { + .fourcc =3D V4L2_PIX_FMT_XRGB32, + .hw_format =3D RGA3_COLOR_FMT_ABGR8888, + .rbuv_swap =3D 1, + }, + { + .fourcc =3D V4L2_PIX_FMT_BGRX32, + .hw_format =3D RGA3_COLOR_FMT_ABGR8888, + }, +}; + +static int rga3_enum_format(struct v4l2_fmtdesc *f) +{ + struct rga3_fmt *fmt; + + if (f->index >=3D ARRAY_SIZE(rga3_formats)) + return -EINVAL; + + fmt =3D &rga3_formats[f->index]; + if (V4L2_TYPE_IS_CAPTURE(f->type) && !rga3_can_capture(fmt)) + return -EINVAL; + + f->pixelformat =3D fmt->fourcc; + return 0; +} + +static void *rga3_adjust_and_map_format(struct rga_ctx *ctx, + struct v4l2_pix_format_mplane *format, + bool is_output) +{ + unsigned int i; + const struct v4l2_format_info *format_info; + const struct v4l2_pix_format_mplane *other_format; + const struct v4l2_format_info *other_format_info; + + if (!format) + return &rga3_formats[0]; + + format_info =3D v4l2_format_info(format->pixelformat); + other_format =3D is_output ? &ctx->in.pix : &ctx->out.pix; + other_format_info =3D v4l2_format_info(other_format->pixelformat); + + if ((v4l2_is_format_rgb(format_info) && + v4l2_is_format_yuv(other_format_info)) || + (v4l2_is_format_yuv(format_info) && + v4l2_is_format_rgb(other_format_info))) { + /* + * The RGA3 only supports BT601, BT709 and BT2020 RGB<->YUV conversions + * Additionally BT709 and BT2020 only support limited range YUV. + */ + switch (format->ycbcr_enc) { + case V4L2_YCBCR_ENC_601: + /* supports full and limited range */ + break; + case V4L2_YCBCR_ENC_709: + case V4L2_YCBCR_ENC_BT2020: + format->quantization =3D V4L2_QUANTIZATION_LIM_RANGE; + break; + default: + format->ycbcr_enc =3D V4L2_YCBCR_ENC_601; + format->quantization =3D V4L2_QUANTIZATION_FULL_RANGE; + break; + } + } + + for (i =3D 0; i < ARRAY_SIZE(rga3_formats); i++) { + if (!is_output && !rga3_can_capture(&rga3_formats[i])) + continue; + + if (rga3_formats[i].fourcc =3D=3D format->pixelformat) + return &rga3_formats[i]; + } + + format->pixelformat =3D rga3_formats[0].fourcc; + return &rga3_formats[0]; +} + +const struct rga_hw rga3_hw =3D { + .card_type =3D "rga3", + .has_internal_iommu =3D false, + .cmdbuf_size =3D RGA3_CMDBUF_SIZE, + .min_width =3D RGA3_MIN_WIDTH, + .min_height =3D RGA3_MIN_HEIGHT, + /* use output size, as it's a bit smaller than the input size */ + .max_width =3D RGA3_MAX_OUTPUT_WIDTH, + .max_height =3D RGA3_MAX_OUTPUT_HEIGHT, + .max_scaling_factor =3D RGA3_MAX_SCALING_FACTOR, + .stride_alignment =3D 16, + .features =3D 0, + + .setup_cmdbuf =3D rga3_hw_setup_cmdbuf, + .start =3D rga3_hw_start, + .handle_irq =3D rga3_handle_irq, + .get_version =3D rga3_get_version, + .enum_format =3D rga3_enum_format, + .adjust_and_map_format =3D rga3_adjust_and_map_format, +}; diff --git a/drivers/media/platform/rockchip/rga/rga3-hw.h b/drivers/media/= platform/rockchip/rga/rga3-hw.h new file mode 100644 index 0000000000000..cc87051492194 --- /dev/null +++ b/drivers/media/platform/rockchip/rga/rga3-hw.h @@ -0,0 +1,192 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) Pengutronix e.K. + * Author: Sven P=C3=BCschel + */ +#ifndef __RGA3_HW_H__ +#define __RGA3_HW_H__ + +#include +#include + +#define RGA3_CMDBUF_SIZE 0x2e + +#define RGA3_MIN_WIDTH 128 +#define RGA3_MIN_HEIGHT 128 +#define RGA3_MAX_INPUT_WIDTH (8192 - 16) +#define RGA3_MAX_INPUT_HEIGHT (8192 - 16) +#define RGA3_MAX_OUTPUT_WIDTH (8192 - 64) +#define RGA3_MAX_OUTPUT_HEIGHT (8192 - 64) +#define RGA3_MAX_SCALING_FACTOR 8 +#define RGA3_RESET_TIMEOUT 1000 + +/* Registers address */ +/* sys reg */ +#define RGA3_SYS_CTRL 0x000 +#define RGA3_CMD_CTRL 0x004 +#define RGA3_CMD_ADDR 0x008 +#define RGA3_MI_GROUP_CTRL 0x00c +#define RGA3_ARQOS_CTRL 0x010 +#define RGA3_VERSION_NUM 0x018 +#define RGA3_VERSION_TIM 0x01c +#define RGA3_INT_EN 0x020 +#define RGA3_INT_RAW 0x024 +#define RGA3_INT_MSK 0x028 +#define RGA3_INT_CLR 0x02c +#define RGA3_RO_SRST 0x030 +#define RGA3_STATUS0 0x034 +#define RGA3_SCAN_CNT 0x038 +#define RGA3_CMD_STATE 0x040 + +/* cmd reg */ +#define RGA3_WIN0_RD_CTRL 0x100 +#define RGA3_FIRST_CMD_REG RGA3_WIN0_RD_CTRL +#define RGA3_WIN0_Y_BASE 0x110 +#define RGA3_WIN0_U_BASE 0x114 +#define RGA3_WIN0_V_BASE 0x118 +#define RGA3_WIN0_VIR_STRIDE 0x11c +#define RGA3_WIN0_FBC_OFF 0x120 +#define RGA3_WIN0_SRC_SIZE 0x124 +#define RGA3_WIN0_ACT_OFF 0x128 +#define RGA3_WIN0_ACT_SIZE 0x12c +#define RGA3_WIN0_DST_SIZE 0x130 +#define RGA3_WIN0_SCL_FAC 0x134 +#define RGA3_WIN0_UV_VIR_STRIDE 0x138 +#define RGA3_WIN1_RD_CTRL 0x140 +#define RGA3_WIN1_Y_BASE 0x150 +#define RGA3_WIN1_U_BASE 0x154 +#define RGA3_WIN1_V_BASE 0x158 +#define RGA3_WIN1_VIR_STRIDE 0x15c +#define RGA3_WIN1_FBC_OFF 0x160 +#define RGA3_WIN1_SRC_SIZE 0x164 +#define RGA3_WIN1_ACT_OFF 0x168 +#define RGA3_WIN1_ACT_SIZE 0x16c +#define RGA3_WIN1_DST_SIZE 0x170 +#define RGA3_WIN1_SCL_FAC 0x174 +#define RGA3_WIN1_UV_VIR_STRIDE 0x178 +#define RGA3_OVLP_CTRL 0x180 +#define RGA3_OVLP_OFF 0x184 +#define RGA3_OVLP_TOP_KEY_MIN 0x188 +#define RGA3_OVLP_TOP_KEY_MAX 0x18c +#define RGA3_OVLP_TOP_CTRL 0x190 +#define RGA3_OVLP_BOT_CTRL 0x194 +#define RGA3_OVLP_TOP_ALPHA 0x198 +#define RGA3_OVLP_BOT_ALPHA 0x19c +#define RGA3_WR_CTRL 0x1a0 +#define RGA3_WR_FBCE_CTRL 0x1a4 +#define RGA3_WR_VIR_STRIDE 0x1a8 +#define RGA3_WR_PL_VIR_STRIDE 0x1ac +#define RGA3_WR_Y_BASE 0x1b0 +#define RGA3_WR_U_BASE 0x1b4 +#define RGA3_WR_V_BASE 0x1b8 + +/* Registers value */ +#define RGA3_COLOR_FMT_YUV420 0x0 +#define RGA3_COLOR_FMT_YUV422 0x1 +#define RGA3_COLOR_FMT_YUV420_10B 0x2 +#define RGA3_COLOR_FMT_YUV422_10B 0x3 +/* + * Use memory ordering names + * instead of the datasheet naming RGB formats in big endian order + */ +#define RGA3_COLOR_FMT_BGR565 0x4 +#define RGA3_COLOR_FMT_BGR888 0x5 +#define RGA3_COLOR_FMT_FIRST_HAS_ALPHA RGA3_COLOR_FMT_BGRA8888 +#define RGA3_COLOR_FMT_BGRA8888 0x6 +#define RGA3_COLOR_FMT_LAST_OUTPUT RGA3_COLOR_FMT_BGRA8888 +/* the following are only supported as inputs */ +#define RGA3_COLOR_FMT_ABGR8888 0x7 +/* + * the following seem to be unnecessary, + * as they can be achieved with RB swaps + */ +#define RGA3_COLOR_FMT_RGBA8888 0x8 +#define RGA3_COLOR_FMT_ARGB8888 0x9 + +#define RGA3_RDWR_FORMAT_SEMI_PLANAR 0x1 +#define RGA3_RDWR_FORMAT_INTERLEAVED 0x2 + +#define RGA3_CMD_MODE_MASTER 0x1 + +#define RGA3_WIN_CSC_MODE_BT601_L 0x0 +#define RGA3_WIN_CSC_MODE_BT709_L 0x1 +#define RGA3_WIN_CSC_MODE_BT601_F 0x2 +#define RGA3_WIN_CSC_MODE_BT2020_L 0x3 + +/* RGA masks */ +/* SYS_CTRL */ +#define RGA3_CCLK_SRESET BIT(4) +#define RGA3_ACLK_SRESET BIT(3) +#define RGA3_CMD_MODE BIT(1) + +/* CMD_CTRL */ +#define RGA3_CMD_LINE_START_PULSE BIT(0) + +/* VERSION_NUM */ +#define RGA3_VERSION_NUM_MAJOR GENMASK(31, 28) +#define RGA3_VERSION_NUM_MINOR GENMASK(27, 20) + +/* INT_* */ +#define RGA3_INT_FRM_DONE BIT(0) +#define RGA3_INT_DMA_READ_BUS_ERR BIT(2) +#define RGA3_INT_WIN0_FBC_DEC_ERR BIT(5) +#define RGA3_INT_WIN0_HOR_ERR BIT(6) +#define RGA3_INT_WIN0_VER_ERR BIT(7) +#define RGA3_INT_WR_VER_ERR BIT(13) +#define RGA3_INT_WR_HOR_ERR BIT(14) +#define RGA3_INT_WR_BUS_ERR BIT(15) +#define RGA3_INT_WIN0_IN_FIFO_WR_ERR BIT(16) +#define RGA3_INT_WIN0_IN_FIFO_RD_ERR BIT(17) +#define RGA3_INT_WIN0_HOR_FIFO_WR_ERR BIT(18) +#define RGA3_INT_WIN0_HOR_FIFO_RD_ERR BIT(19) +#define RGA3_INT_WIN0_VER_FIFO_WR_ERR BIT(20) +#define RGA3_INT_WIN0_VER_FIFO_RD_ERR BIT(21) + +/* RO_SRST */ +#define RGA3_RO_SRST_DONE GENMASK(5, 0) + +/* *_SIZE */ +#define RGA3_HEIGHT GENMASK(28, 16) +#define RGA3_WIDTH GENMASK(12, 0) + +/* SCL_FAC */ +#define RGA3_SCALE_VER_FAC GENMASK(31, 16) +#define RGA3_SCALE_HOR_FAC GENMASK(15, 0) + +/* WINx_CTRL */ +#define RGA3_WIN_CSC_MODE GENMASK(27, 26) +#define RGA3_WIN_R2Y BIT(25) +#define RGA3_WIN_Y2R BIT(24) +#define RGA3_WIN_SCALE_VER_UP BIT(23) +#define RGA3_WIN_SCALE_VER_BYPASS BIT(22) +#define RGA3_WIN_SCALE_HOR_UP BIT(21) +#define RGA3_WIN_SCALE_HOR_BYPASS BIT(20) +#define RGA3_WIN_YC_SWAP BIT(13) +#define RGA3_WIN_RBUV_SWAP BIT(12) +#define RGA3_WIN_RD_FORMAT GENMASK(9, 8) +#define RGA3_WIN_PIC_FORMAT GENMASK(7, 4) +#define RGA3_WIN_ENABLE BIT(0) + +/* COLOR_CTRL */ +#define RGA3_OVLP_GLOBAL_ALPHA GENMASK(23, 16) +#define RGA3_OVLP_COLOR_MODE BIT(0) + +/* ALPHA_CTRL */ +#define RGA3_ALPHA_SELECT_MODE BIT(4) +#define RGA3_ALPHA_BLEND_MODE GENMASK(3, 2) + +/* WR_CTRL */ +#define RGA3_WR_YC_SWAP BIT(20) +#define RGA3_WR_SW_OUTSTANDING_MAX GENMASK(18, 13) +#define RGA3_WR_RBUV_SWAP BIT(12) +#define RGA3_WR_FORMAT GENMASK(9, 8) +#define RGA3_WR_PIC_FORMAT GENMASK(7, 4) + +struct rga3_fmt { + u32 fourcc; + u8 hw_format; + bool rbuv_swap; + bool yc_swap; +}; + +#endif --=20 2.52.0 From nobody Mon Feb 9 01:35:10 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 A72ED35E533 for ; Tue, 27 Jan 2026 14:41:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524863; cv=none; b=D+/7ICjg7ZJ5QTMy9sBeG4ClcoJdtcshnYT0KiHYkvWzBXi2NT42qqObsnQ0PubCxjmye2n3ch5u3n2AXPi4PIyteZMS7tOZNTb9EGiRsk55Rbz6VislWkIZqgpL3KbroGP6OtyYzFvs3jCJTm/MDvwB3lO9Eik1mhhAL3B81tM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524863; c=relaxed/simple; bh=+VsWsEg0rEmpODVt6AZotBpo6jkuzOnObDO7E1FP1PU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L1PT8OZScTv+qBOC1RNWyGdKt3eq4cLKGjXtud/H3O+7eAn5H4pDVcbjzo4ZqjvETvOIKhEOtYsq7Ayp9Q5FRID1DO2IOh+fjrQXDL0HTr7T3xmz6cav2RTndT7JwLVcvBcNX1E9z+z8BorDuyrT2mPRT3L9TO84Li8opdhuMCI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1vkkFW-0007YT-TM; Tue, 27 Jan 2026 15:40:59 +0100 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 27 Jan 2026 15:39:36 +0100 Subject: [PATCH v3 27/27] arm64: dts: rockchip: add rga3 dt nodes 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: <20260127-spu-rga3-v3-27-77b273067beb@pengutronix.de> References: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> In-Reply-To: <20260127-spu-rga3-v3-0-77b273067beb@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.3 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add devicetree nodes for the RGA3 (Raster Graphics Acceleration 3) peripheral in the RK3588. The existing rga node refers to the RGA2 peripheral. The RK3588 contains one RGA2 core and two RGA3 cores. Both feature a similar functionality of scaling, cropping and rotating of up to two input images into one output image. Key differences of the RGA3 are: - supports 10bit YUV output formats - supports 8x8 tiles and FBCD as inputs and outputs - supports BT2020 color space conversion - max output resolution of (8192-64)x(8192-64) - MMU can map up to 32G DDR RAM - fully planar formats (3 planes) are not supported - max scale up/down factor of 8 (RGA2 allows up to 16) Signed-off-by: Sven P=C3=BCschel --- arch/arm64/boot/dts/rockchip/rk3588-base.dtsi | 44 +++++++++++++++++++++++= ++++ 1 file changed, 44 insertions(+) diff --git a/arch/arm64/boot/dts/rockchip/rk3588-base.dtsi b/arch/arm64/boo= t/dts/rockchip/rk3588-base.dtsi index 2a79217930206..d1d44cf948e92 100644 --- a/arch/arm64/boot/dts/rockchip/rk3588-base.dtsi +++ b/arch/arm64/boot/dts/rockchip/rk3588-base.dtsi @@ -1273,6 +1273,50 @@ rga: rga@fdb80000 { power-domains =3D <&power RK3588_PD_VDPU>; }; =20 + rga3_core0: rga@fdb60000 { + compatible =3D "rockchip,rk3588-rga3"; + reg =3D <0x0 0xfdb60000 0x0 0x200>; + interrupts =3D ; + clocks =3D <&cru ACLK_RGA3_0>, <&cru HCLK_RGA3_0>, <&cru CLK_RGA3_0_CORE= >; + clock-names =3D "aclk", "hclk", "sclk"; + resets =3D <&cru SRST_RGA3_0_CORE>, <&cru SRST_A_RGA3_0>, <&cru SRST_H_R= GA3_0>; + reset-names =3D "core", "axi", "ahb"; + power-domains =3D <&power RK3588_PD_RGA30>; + iommus =3D <&rga3_0_mmu>; + }; + + rga3_0_mmu: iommu@fdb60f00 { + compatible =3D "rockchip,rk3588-iommu", "rockchip,rk3568-iommu"; + reg =3D <0x0 0xfdb60f00 0x0 0x100>; + interrupts =3D ; + clocks =3D <&cru ACLK_RGA3_0>, <&cru HCLK_RGA3_0>; + clock-names =3D "aclk", "iface"; + #iommu-cells =3D <0>; + power-domains =3D <&power RK3588_PD_RGA30>; + }; + + rga3_core1: rga@fdb70000 { + compatible =3D "rockchip,rk3588-rga3"; + reg =3D <0x0 0xfdb70000 0x0 0x200>; + interrupts =3D ; + clocks =3D <&cru ACLK_RGA3_1>, <&cru HCLK_RGA3_1>, <&cru CLK_RGA3_1_CORE= >; + clock-names =3D "aclk", "hclk", "sclk"; + resets =3D <&cru SRST_RGA3_1_CORE>, <&cru SRST_A_RGA3_1>, <&cru SRST_H_R= GA3_1>; + reset-names =3D "core", "axi", "ahb"; + power-domains =3D <&power RK3588_PD_RGA31>; + iommus =3D <&rga3_1_mmu>; + }; + + rga3_1_mmu: iommu@fdb70f00 { + compatible =3D "rockchip,rk3588-iommu", "rockchip,rk3568-iommu"; + reg =3D <0x0 0xfdb70f00 0x0 0x100>; + interrupts =3D ; + clocks =3D <&cru ACLK_RGA3_1>, <&cru HCLK_RGA3_1>; + clock-names =3D "aclk", "iface"; + #iommu-cells =3D <0>; + power-domains =3D <&power RK3588_PD_RGA31>; + }; + vepu121_0: video-codec@fdba0000 { compatible =3D "rockchip,rk3588-vepu121"; reg =3D <0x0 0xfdba0000 0x0 0x800>; --=20 2.52.0