From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78E67C77B75 for ; Tue, 11 Apr 2023 11:42:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229913AbjDKLm6 (ORCPT ); Tue, 11 Apr 2023 07:42:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229911AbjDKLmx (ORCPT ); Tue, 11 Apr 2023 07:42:53 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 981673A87; Tue, 11 Apr 2023 04:42:48 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="155597296" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 11 Apr 2023 20:42:47 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 67CC8400195D; Tue, 11 Apr 2023 20:42:43 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 01/17] drm: rcar-du: Add encoder lib support Date: Tue, 11 Apr 2023 12:42:19 +0100 Message-Id: <20230411114235.366042-2-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add RCar DU encoder lib support by moving rcar_du_encoder_count_ports() and rcar_du_encoder_funcs to the lib file and added rcar_du_lib_encoder_ini= t() to share the common code between RCar and RZ/G2L DU encoder drivers. Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v5->v6: * Updated rcar_du_encoder_init() to take care of DSI outputs. v2->v5: * No change v1->v2: * Rebased on drm-misc-next and DU-next. * Fixed the warning reported by bot. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/Kconfig | 5 + drivers/gpu/drm/rcar-du/Makefile | 2 + drivers/gpu/drm/rcar-du/rcar_du_encoder.c | 117 +-------------- drivers/gpu/drm/rcar-du/rcar_du_encoder.h | 14 +- drivers/gpu/drm/rcar-du/rcar_du_encoder_lib.c | 138 ++++++++++++++++++ drivers/gpu/drm/rcar-du/rcar_du_encoder_lib.h | 30 ++++ 6 files changed, 180 insertions(+), 126 deletions(-) create mode 100644 drivers/gpu/drm/rcar-du/rcar_du_encoder_lib.c create mode 100644 drivers/gpu/drm/rcar-du/rcar_du_encoder_lib.h diff --git a/drivers/gpu/drm/rcar-du/Kconfig b/drivers/gpu/drm/rcar-du/Kcon= fig index 53c356aed5d5..07a922cc3504 100644 --- a/drivers/gpu/drm/rcar-du/Kconfig +++ b/drivers/gpu/drm/rcar-du/Kconfig @@ -80,3 +80,8 @@ config DRM_RCAR_WRITEBACK bool default y if ARM64 depends on DRM_RCAR_DU + +config DRM_RCAR_LIB + bool + default y + depends on DRM_RCAR_DU diff --git a/drivers/gpu/drm/rcar-du/Makefile b/drivers/gpu/drm/rcar-du/Mak= efile index b8f2c82651d9..479c8eebba5a 100644 --- a/drivers/gpu/drm/rcar-du/Makefile +++ b/drivers/gpu/drm/rcar-du/Makefile @@ -6,6 +6,8 @@ rcar-du-drm-y :=3D rcar_du_crtc.o \ rcar_du_kms.o \ rcar_du_plane.o \ =20 +rcar-du-drm-$(CONFIG_DRM_RCAR_LIB) +=3D rcar_du_encoder_lib.o + rcar-du-drm-$(CONFIG_DRM_RCAR_VSP) +=3D rcar_du_vsp.o rcar-du-drm-$(CONFIG_DRM_RCAR_WRITEBACK) +=3D rcar_du_writeback.o =20 diff --git a/drivers/gpu/drm/rcar-du/rcar_du_encoder.c b/drivers/gpu/drm/rc= ar-du/rcar_du_encoder.c index 7ecec7b04a8d..b9b5a31c3cb5 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_encoder.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_encoder.c @@ -2,7 +2,7 @@ /* * R-Car Display Unit Encoder * - * Copyright (C) 2013-2014 Renesas Electronics Corporation + * Copyright (C) 2013-2023 Renesas Electronics Corporation * * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) */ @@ -10,128 +10,17 @@ #include #include =20 -#include -#include -#include - #include "rcar_du_drv.h" #include "rcar_du_encoder.h" -#include "rcar_lvds.h" =20 /* -----------------------------------------------------------------------= ------ * Encoder */ =20 -static unsigned int rcar_du_encoder_count_ports(struct device_node *node) -{ - struct device_node *ports; - struct device_node *port; - unsigned int num_ports =3D 0; - - ports =3D of_get_child_by_name(node, "ports"); - if (!ports) - ports =3D of_node_get(node); - - for_each_child_of_node(ports, port) { - if (of_node_name_eq(port, "port")) - num_ports++; - } - - of_node_put(ports); - - return num_ports; -} - -static const struct drm_encoder_funcs rcar_du_encoder_funcs =3D { -}; - int rcar_du_encoder_init(struct rcar_du_device *rcdu, enum rcar_du_output output, struct device_node *enc_node) { - struct rcar_du_encoder *renc; - struct drm_connector *connector; - struct drm_bridge *bridge; - int ret; - - /* - * Locate the DRM bridge from the DT node. For the DPAD outputs, if the - * DT node has a single port, assume that it describes a panel and - * create a panel bridge. - */ - if ((output =3D=3D RCAR_DU_OUTPUT_DPAD0 || - output =3D=3D RCAR_DU_OUTPUT_DPAD1) && - rcar_du_encoder_count_ports(enc_node) =3D=3D 1) { - struct drm_panel *panel =3D of_drm_find_panel(enc_node); - - if (IS_ERR(panel)) - return PTR_ERR(panel); - - bridge =3D devm_drm_panel_bridge_add_typed(rcdu->dev, panel, - DRM_MODE_CONNECTOR_DPI); - if (IS_ERR(bridge)) - return PTR_ERR(bridge); - } else { - bridge =3D of_drm_find_bridge(enc_node); - if (!bridge) - return -EPROBE_DEFER; - - if (output =3D=3D RCAR_DU_OUTPUT_LVDS0 || - output =3D=3D RCAR_DU_OUTPUT_LVDS1) - rcdu->lvds[output - RCAR_DU_OUTPUT_LVDS0] =3D bridge; - - if (output =3D=3D RCAR_DU_OUTPUT_DSI0 || - output =3D=3D RCAR_DU_OUTPUT_DSI1) - rcdu->dsi[output - RCAR_DU_OUTPUT_DSI0] =3D bridge; - } - - /* - * Create and initialize the encoder. On Gen3, skip the LVDS1 output if - * the LVDS1 encoder is used as a companion for LVDS0 in dual-link - * mode, or any LVDS output if it isn't connected. The latter may happen - * on D3 or E3 as the LVDS encoders are needed to provide the pixel - * clock to the DU, even when the LVDS outputs are not used. - */ - if (rcdu->info->gen >=3D 3) { - if (output =3D=3D RCAR_DU_OUTPUT_LVDS1 && - rcar_lvds_dual_link(bridge)) - return -ENOLINK; - - if ((output =3D=3D RCAR_DU_OUTPUT_LVDS0 || - output =3D=3D RCAR_DU_OUTPUT_LVDS1) && - !rcar_lvds_is_connected(bridge)) - return -ENOLINK; - } - - dev_dbg(rcdu->dev, "initializing encoder %pOF for output %s\n", - enc_node, rcar_du_output_name(output)); - - renc =3D drmm_encoder_alloc(&rcdu->ddev, struct rcar_du_encoder, base, - &rcar_du_encoder_funcs, DRM_MODE_ENCODER_NONE, - NULL); - if (IS_ERR(renc)) - return PTR_ERR(renc); - - renc->output =3D output; - - /* Attach the bridge to the encoder. */ - ret =3D drm_bridge_attach(&renc->base, bridge, NULL, - DRM_BRIDGE_ATTACH_NO_CONNECTOR); - if (ret) { - dev_err(rcdu->dev, - "failed to attach bridge %pOF for output %s (%d)\n", - bridge->of_node, rcar_du_output_name(output), ret); - return ret; - } - - /* Create the connector for the chain of bridges. */ - connector =3D drm_bridge_connector_init(&rcdu->ddev, &renc->base); - if (IS_ERR(connector)) { - dev_err(rcdu->dev, - "failed to created connector for output %s (%ld)\n", - rcar_du_output_name(output), PTR_ERR(connector)); - return PTR_ERR(connector); - } - - return drm_connector_attach_encoder(connector, &renc->base); + return rcar_du_lib_encoder_init(rcdu, output, enc_node, + rcar_du_output_name(output)); } diff --git a/drivers/gpu/drm/rcar-du/rcar_du_encoder.h b/drivers/gpu/drm/rc= ar-du/rcar_du_encoder.h index e5ec8fbb3979..d33b684fe93f 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_encoder.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_encoder.h @@ -2,7 +2,7 @@ /* * R-Car Display Unit Encoder * - * Copyright (C) 2013-2014 Renesas Electronics Corporation + * Copyright (C) 2013-2022 Renesas Electronics Corporation * * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) */ @@ -10,17 +10,7 @@ #ifndef __RCAR_DU_ENCODER_H__ #define __RCAR_DU_ENCODER_H__ =20 -#include - -struct rcar_du_device; - -struct rcar_du_encoder { - struct drm_encoder base; - enum rcar_du_output output; -}; - -#define to_rcar_encoder(e) \ - container_of(e, struct rcar_du_encoder, base) +#include "rcar_du_encoder_lib.h" =20 int rcar_du_encoder_init(struct rcar_du_device *rcdu, enum rcar_du_output output, diff --git a/drivers/gpu/drm/rcar-du/rcar_du_encoder_lib.c b/drivers/gpu/dr= m/rcar-du/rcar_du_encoder_lib.c new file mode 100644 index 000000000000..6c47cdd06538 --- /dev/null +++ b/drivers/gpu/drm/rcar-du/rcar_du_encoder_lib.c @@ -0,0 +1,138 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * R-Car Display Unit Encoder Lib + * + * Copyright (C) 2013-2023 Renesas Electronics Corporation + * + * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) + */ + +#include +#include + +#include +#include +#include + +#include "rcar_du_drv.h" +#include "rcar_du_encoder.h" +#include "rcar_lvds.h" + +/* -----------------------------------------------------------------------= ------ + * Encoder + */ + +static unsigned int rcar_du_encoder_count_ports(struct device_node *node) +{ + struct device_node *ports; + struct device_node *port; + unsigned int num_ports =3D 0; + + ports =3D of_get_child_by_name(node, "ports"); + if (!ports) + ports =3D of_node_get(node); + + for_each_child_of_node(ports, port) { + if (of_node_name_eq(port, "port")) + num_ports++; + } + + of_node_put(ports); + + return num_ports; +} + +static const struct drm_encoder_funcs rcar_du_encoder_funcs =3D { +}; + +int rcar_du_lib_encoder_init(struct rcar_du_device *rcdu, + enum rcar_du_output output, + struct device_node *enc_node, + const char *output_name) +{ + struct rcar_du_encoder *renc; + struct drm_connector *connector; + struct drm_bridge *bridge; + int ret; + + /* + * Locate the DRM bridge from the DT node. For the DPAD outputs, if the + * DT node has a single port, assume that it describes a panel and + * create a panel bridge. + */ + if ((output =3D=3D RCAR_DU_OUTPUT_DPAD0 || + output =3D=3D RCAR_DU_OUTPUT_DPAD1) && + rcar_du_encoder_count_ports(enc_node) =3D=3D 1) { + struct drm_panel *panel =3D of_drm_find_panel(enc_node); + + if (IS_ERR(panel)) + return PTR_ERR(panel); + + bridge =3D devm_drm_panel_bridge_add_typed(rcdu->dev, panel, + DRM_MODE_CONNECTOR_DPI); + if (IS_ERR(bridge)) + return PTR_ERR(bridge); + } else { + bridge =3D of_drm_find_bridge(enc_node); + if (!bridge) + return -EPROBE_DEFER; + + if (output =3D=3D RCAR_DU_OUTPUT_LVDS0 || + output =3D=3D RCAR_DU_OUTPUT_LVDS1) + rcdu->lvds[output - RCAR_DU_OUTPUT_LVDS0] =3D bridge; + + if (output =3D=3D RCAR_DU_OUTPUT_DSI0 || + output =3D=3D RCAR_DU_OUTPUT_DSI1) + rcdu->dsi[output - RCAR_DU_OUTPUT_DSI0] =3D bridge; + } + + /* + * Create and initialize the encoder. On Gen3, skip the LVDS1 output if + * the LVDS1 encoder is used as a companion for LVDS0 in dual-link + * mode, or any LVDS output if it isn't connected. The latter may happen + * on D3 or E3 as the LVDS encoders are needed to provide the pixel + * clock to the DU, even when the LVDS outputs are not used. + */ + if (rcdu->info->gen >=3D 3) { + if (output =3D=3D RCAR_DU_OUTPUT_LVDS1 && + rcar_lvds_dual_link(bridge)) + return -ENOLINK; + + if ((output =3D=3D RCAR_DU_OUTPUT_LVDS0 || + output =3D=3D RCAR_DU_OUTPUT_LVDS1) && + !rcar_lvds_is_connected(bridge)) + return -ENOLINK; + } + + dev_dbg(rcdu->dev, "initializing encoder %pOF for output %s\n", + enc_node, rcar_du_output_name(output)); + + renc =3D drmm_encoder_alloc(&rcdu->ddev, struct rcar_du_encoder, base, + &rcar_du_encoder_funcs, DRM_MODE_ENCODER_NONE, + NULL); + if (IS_ERR(renc)) + return PTR_ERR(renc); + + renc->output =3D output; + + /* Attach the bridge to the encoder. */ + ret =3D drm_bridge_attach(&renc->base, bridge, NULL, + DRM_BRIDGE_ATTACH_NO_CONNECTOR); + if (ret) { + dev_err(rcdu->dev, + "failed to attach bridge %pOF for output %s (%d)\n", + bridge->of_node, output_name, ret); + return ret; + } + + /* Create the connector for the chain of bridges. */ + connector =3D drm_bridge_connector_init(&rcdu->ddev, &renc->base); + if (IS_ERR(connector)) { + dev_err(rcdu->dev, + "failed to created connector for output %s (%ld)\n", + output_name, PTR_ERR(connector)); + return PTR_ERR(connector); + } + + return drm_connector_attach_encoder(connector, &renc->base); +} diff --git a/drivers/gpu/drm/rcar-du/rcar_du_encoder_lib.h b/drivers/gpu/dr= m/rcar-du/rcar_du_encoder_lib.h new file mode 100644 index 000000000000..1f6ba6250305 --- /dev/null +++ b/drivers/gpu/drm/rcar-du/rcar_du_encoder_lib.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * R-Car Display Unit Encoder Lib + * + * Copyright (C) 2013-2023 Renesas Electronics Corporation + * + * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) + */ + +#ifndef __RCAR_DU_ENCODER_LIB_H__ +#define __RCAR_DU_ENCODER_LIB_H__ + +#include + +struct rcar_du_device; + +struct rcar_du_encoder { + struct drm_encoder base; + enum rcar_du_output output; +}; + +#define to_rcar_encoder(e) \ + container_of(e, struct rcar_du_encoder, base) + +int rcar_du_lib_encoder_init(struct rcar_du_device *rcdu, + enum rcar_du_output output, + struct device_node *enc_node, + const char *output_name); + +#endif /* __RCAR_DU_ENCODER_LIB_H__ */ --=20 2.25.1 From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1FE4C76196 for ; Tue, 11 Apr 2023 11:43:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229553AbjDKLnI (ORCPT ); Tue, 11 Apr 2023 07:43:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229688AbjDKLm7 (ORCPT ); Tue, 11 Apr 2023 07:42:59 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 200533C25; Tue, 11 Apr 2023 04:42:53 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="155597302" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 11 Apr 2023 20:42:52 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 6A0C7400195D; Tue, 11 Apr 2023 20:42:48 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 02/17] drm: rcar-du: Add kms lib support Date: Tue, 11 Apr 2023 12:42:20 +0100 Message-Id: <20230411114235.366042-3-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add RCar DU kms lib support for sharing the common code between RCar and RZ/G2L DU KMS drivers by moving rcar_du_format_infos table and rcar_du_format_infos() to the lib file. Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v1->v6: * Rebased on drm-misc-next and DU-next. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/Makefile | 3 +- drivers/gpu/drm/rcar-du/rcar_du_kms.c | 320 --------------------- drivers/gpu/drm/rcar-du/rcar_du_kms.h | 16 +- drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c | 335 ++++++++++++++++++++++ drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h | 27 ++ 5 files changed, 366 insertions(+), 335 deletions(-) create mode 100644 drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c create mode 100644 drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h diff --git a/drivers/gpu/drm/rcar-du/Makefile b/drivers/gpu/drm/rcar-du/Mak= efile index 479c8eebba5a..3ce410300334 100644 --- a/drivers/gpu/drm/rcar-du/Makefile +++ b/drivers/gpu/drm/rcar-du/Makefile @@ -6,7 +6,8 @@ rcar-du-drm-y :=3D rcar_du_crtc.o \ rcar_du_kms.o \ rcar_du_plane.o \ =20 -rcar-du-drm-$(CONFIG_DRM_RCAR_LIB) +=3D rcar_du_encoder_lib.o +rcar-du-drm-$(CONFIG_DRM_RCAR_LIB) +=3D rcar_du_encoder_lib.o \ + rcar_du_kms_lib.o =20 rcar-du-drm-$(CONFIG_DRM_RCAR_VSP) +=3D rcar_du_vsp.o rcar-du-drm-$(CONFIG_DRM_RCAR_WRITEBACK) +=3D rcar_du_writeback.o diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.c b/drivers/gpu/drm/rcar-d= u/rcar_du_kms.c index adfb36b0e815..3141d447e979 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.c @@ -32,326 +32,6 @@ #include "rcar_du_vsp.h" #include "rcar_du_writeback.h" =20 -/* -----------------------------------------------------------------------= ------ - * Format helpers - */ - -static const struct rcar_du_format_info rcar_du_format_infos[] =3D { - { - .fourcc =3D DRM_FORMAT_RGB565, - .v4l2 =3D V4L2_PIX_FMT_RGB565, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 1, - .pnmr =3D PnMR_SPIM_TP | PnMR_DDDF_16BPP, - .edf =3D PnDDCR4_EDF_NONE, - }, { - .fourcc =3D DRM_FORMAT_ARGB1555, - .v4l2 =3D V4L2_PIX_FMT_ARGB555, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 1, - .pnmr =3D PnMR_SPIM_ALP | PnMR_DDDF_ARGB, - .edf =3D PnDDCR4_EDF_NONE, - }, { - .fourcc =3D DRM_FORMAT_XRGB1555, - .v4l2 =3D V4L2_PIX_FMT_XRGB555, - .bpp =3D 16, - .planes =3D 1, - .pnmr =3D PnMR_SPIM_ALP | PnMR_DDDF_ARGB, - .edf =3D PnDDCR4_EDF_NONE, - }, { - .fourcc =3D DRM_FORMAT_XRGB8888, - .v4l2 =3D V4L2_PIX_FMT_XBGR32, - .bpp =3D 32, - .planes =3D 1, - .hsub =3D 1, - .pnmr =3D PnMR_SPIM_TP | PnMR_DDDF_16BPP, - .edf =3D PnDDCR4_EDF_RGB888, - }, { - .fourcc =3D DRM_FORMAT_ARGB8888, - .v4l2 =3D V4L2_PIX_FMT_ABGR32, - .bpp =3D 32, - .planes =3D 1, - .hsub =3D 1, - .pnmr =3D PnMR_SPIM_ALP | PnMR_DDDF_16BPP, - .edf =3D PnDDCR4_EDF_ARGB8888, - }, { - .fourcc =3D DRM_FORMAT_UYVY, - .v4l2 =3D V4L2_PIX_FMT_UYVY, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 2, - .pnmr =3D PnMR_SPIM_TP_OFF | PnMR_DDDF_YC, - .edf =3D PnDDCR4_EDF_NONE, - }, { - .fourcc =3D DRM_FORMAT_YUYV, - .v4l2 =3D V4L2_PIX_FMT_YUYV, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 2, - .pnmr =3D PnMR_SPIM_TP_OFF | PnMR_DDDF_YC, - .edf =3D PnDDCR4_EDF_NONE, - }, { - .fourcc =3D DRM_FORMAT_NV12, - .v4l2 =3D V4L2_PIX_FMT_NV12M, - .bpp =3D 12, - .planes =3D 2, - .hsub =3D 2, - .pnmr =3D PnMR_SPIM_TP_OFF | PnMR_DDDF_YC, - .edf =3D PnDDCR4_EDF_NONE, - }, { - .fourcc =3D DRM_FORMAT_NV21, - .v4l2 =3D V4L2_PIX_FMT_NV21M, - .bpp =3D 12, - .planes =3D 2, - .hsub =3D 2, - .pnmr =3D PnMR_SPIM_TP_OFF | PnMR_DDDF_YC, - .edf =3D PnDDCR4_EDF_NONE, - }, { - .fourcc =3D DRM_FORMAT_NV16, - .v4l2 =3D V4L2_PIX_FMT_NV16M, - .bpp =3D 16, - .planes =3D 2, - .hsub =3D 2, - .pnmr =3D PnMR_SPIM_TP_OFF | PnMR_DDDF_YC, - .edf =3D PnDDCR4_EDF_NONE, - }, - /* - * The following formats are not supported on Gen2 and thus have no - * associated .pnmr or .edf settings. - */ - { - .fourcc =3D DRM_FORMAT_RGB332, - .v4l2 =3D V4L2_PIX_FMT_RGB332, - .bpp =3D 8, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_ARGB4444, - .v4l2 =3D V4L2_PIX_FMT_ARGB444, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_XRGB4444, - .v4l2 =3D V4L2_PIX_FMT_XRGB444, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_RGBA4444, - .v4l2 =3D V4L2_PIX_FMT_RGBA444, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_RGBX4444, - .v4l2 =3D V4L2_PIX_FMT_RGBX444, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_ABGR4444, - .v4l2 =3D V4L2_PIX_FMT_ABGR444, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_XBGR4444, - .v4l2 =3D V4L2_PIX_FMT_XBGR444, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_BGRA4444, - .v4l2 =3D V4L2_PIX_FMT_BGRA444, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_BGRX4444, - .v4l2 =3D V4L2_PIX_FMT_BGRX444, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_RGBA5551, - .v4l2 =3D V4L2_PIX_FMT_RGBA555, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_RGBX5551, - .v4l2 =3D V4L2_PIX_FMT_RGBX555, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_ABGR1555, - .v4l2 =3D V4L2_PIX_FMT_ABGR555, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_XBGR1555, - .v4l2 =3D V4L2_PIX_FMT_XBGR555, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_BGRA5551, - .v4l2 =3D V4L2_PIX_FMT_BGRA555, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_BGRX5551, - .v4l2 =3D V4L2_PIX_FMT_BGRX555, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_BGR888, - .v4l2 =3D V4L2_PIX_FMT_RGB24, - .bpp =3D 24, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_RGB888, - .v4l2 =3D V4L2_PIX_FMT_BGR24, - .bpp =3D 24, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_RGBA8888, - .v4l2 =3D V4L2_PIX_FMT_BGRA32, - .bpp =3D 32, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_RGBX8888, - .v4l2 =3D V4L2_PIX_FMT_BGRX32, - .bpp =3D 32, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_ABGR8888, - .v4l2 =3D V4L2_PIX_FMT_RGBA32, - .bpp =3D 32, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_XBGR8888, - .v4l2 =3D V4L2_PIX_FMT_RGBX32, - .bpp =3D 32, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_BGRA8888, - .v4l2 =3D V4L2_PIX_FMT_ARGB32, - .bpp =3D 32, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_BGRX8888, - .v4l2 =3D V4L2_PIX_FMT_XRGB32, - .bpp =3D 32, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_RGBX1010102, - .v4l2 =3D V4L2_PIX_FMT_RGBX1010102, - .bpp =3D 32, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_RGBA1010102, - .v4l2 =3D V4L2_PIX_FMT_RGBA1010102, - .bpp =3D 32, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_ARGB2101010, - .v4l2 =3D V4L2_PIX_FMT_ARGB2101010, - .bpp =3D 32, - .planes =3D 1, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_YVYU, - .v4l2 =3D V4L2_PIX_FMT_YVYU, - .bpp =3D 16, - .planes =3D 1, - .hsub =3D 2, - }, { - .fourcc =3D DRM_FORMAT_NV61, - .v4l2 =3D V4L2_PIX_FMT_NV61M, - .bpp =3D 16, - .planes =3D 2, - .hsub =3D 2, - }, { - .fourcc =3D DRM_FORMAT_YUV420, - .v4l2 =3D V4L2_PIX_FMT_YUV420M, - .bpp =3D 12, - .planes =3D 3, - .hsub =3D 2, - }, { - .fourcc =3D DRM_FORMAT_YVU420, - .v4l2 =3D V4L2_PIX_FMT_YVU420M, - .bpp =3D 12, - .planes =3D 3, - .hsub =3D 2, - }, { - .fourcc =3D DRM_FORMAT_YUV422, - .v4l2 =3D V4L2_PIX_FMT_YUV422M, - .bpp =3D 16, - .planes =3D 3, - .hsub =3D 2, - }, { - .fourcc =3D DRM_FORMAT_YVU422, - .v4l2 =3D V4L2_PIX_FMT_YVU422M, - .bpp =3D 16, - .planes =3D 3, - .hsub =3D 2, - }, { - .fourcc =3D DRM_FORMAT_YUV444, - .v4l2 =3D V4L2_PIX_FMT_YUV444M, - .bpp =3D 24, - .planes =3D 3, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_YVU444, - .v4l2 =3D V4L2_PIX_FMT_YVU444M, - .bpp =3D 24, - .planes =3D 3, - .hsub =3D 1, - }, { - .fourcc =3D DRM_FORMAT_Y210, - .v4l2 =3D V4L2_PIX_FMT_Y210, - .bpp =3D 32, - .planes =3D 1, - .hsub =3D 2, - }, { - .fourcc =3D DRM_FORMAT_Y212, - .v4l2 =3D V4L2_PIX_FMT_Y212, - .bpp =3D 32, - .planes =3D 1, - .hsub =3D 2, - }, -}; - -const struct rcar_du_format_info *rcar_du_format_info(u32 fourcc) -{ - unsigned int i; - - for (i =3D 0; i < ARRAY_SIZE(rcar_du_format_infos); ++i) { - if (rcar_du_format_infos[i].fourcc =3D=3D fourcc) - return &rcar_du_format_infos[i]; - } - - return NULL; -} - /* -----------------------------------------------------------------------= ------ * Frame buffer */ diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.h b/drivers/gpu/drm/rcar-d= u/rcar_du_kms.h index f31afeeee05a..d2d4f34fe557 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.h @@ -2,7 +2,7 @@ /* * R-Car Display Unit Mode Setting * - * Copyright (C) 2013-2014 Renesas Electronics Corporation + * Copyright (C) 2013-2023 Renesas Electronics Corporation * * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) */ @@ -10,7 +10,7 @@ #ifndef __RCAR_DU_KMS_H__ #define __RCAR_DU_KMS_H__ =20 -#include +#include "rcar_du_kms_lib.h" =20 struct dma_buf_attachment; struct drm_file; @@ -20,18 +20,6 @@ struct drm_mode_create_dumb; struct rcar_du_device; struct sg_table; =20 -struct rcar_du_format_info { - u32 fourcc; - u32 v4l2; - unsigned int bpp; - unsigned int planes; - unsigned int hsub; - unsigned int pnmr; - unsigned int edf; -}; - -const struct rcar_du_format_info *rcar_du_format_info(u32 fourcc); - int rcar_du_modeset_init(struct rcar_du_device *rcdu); =20 int rcar_du_dumb_create(struct drm_file *file, struct drm_device *dev, diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c b/drivers/gpu/drm/rc= ar-du/rcar_du_kms_lib.c new file mode 100644 index 000000000000..5921040586fc --- /dev/null +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c @@ -0,0 +1,335 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * R-Car Display Unit Mode Setting Lib + * + * Copyright (C) 2013-2023 Renesas Electronics Corporation + * + * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) + */ + +#include + +#include + +#include "rcar_du_kms.h" +#include "rcar_du_regs.h" + +/* -----------------------------------------------------------------------= ------ + * Format helpers + */ + +static const struct rcar_du_format_info rcar_du_format_infos[] =3D { + { + .fourcc =3D DRM_FORMAT_RGB565, + .v4l2 =3D V4L2_PIX_FMT_RGB565, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 1, + .pnmr =3D PnMR_SPIM_TP | PnMR_DDDF_16BPP, + .edf =3D PnDDCR4_EDF_NONE, + }, { + .fourcc =3D DRM_FORMAT_ARGB1555, + .v4l2 =3D V4L2_PIX_FMT_ARGB555, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 1, + .pnmr =3D PnMR_SPIM_ALP | PnMR_DDDF_ARGB, + .edf =3D PnDDCR4_EDF_NONE, + }, { + .fourcc =3D DRM_FORMAT_XRGB1555, + .v4l2 =3D V4L2_PIX_FMT_XRGB555, + .bpp =3D 16, + .planes =3D 1, + .pnmr =3D PnMR_SPIM_ALP | PnMR_DDDF_ARGB, + .edf =3D PnDDCR4_EDF_NONE, + }, { + .fourcc =3D DRM_FORMAT_XRGB8888, + .v4l2 =3D V4L2_PIX_FMT_XBGR32, + .bpp =3D 32, + .planes =3D 1, + .hsub =3D 1, + .pnmr =3D PnMR_SPIM_TP | PnMR_DDDF_16BPP, + .edf =3D PnDDCR4_EDF_RGB888, + }, { + .fourcc =3D DRM_FORMAT_ARGB8888, + .v4l2 =3D V4L2_PIX_FMT_ABGR32, + .bpp =3D 32, + .planes =3D 1, + .hsub =3D 1, + .pnmr =3D PnMR_SPIM_ALP | PnMR_DDDF_16BPP, + .edf =3D PnDDCR4_EDF_ARGB8888, + }, { + .fourcc =3D DRM_FORMAT_UYVY, + .v4l2 =3D V4L2_PIX_FMT_UYVY, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 2, + .pnmr =3D PnMR_SPIM_TP_OFF | PnMR_DDDF_YC, + .edf =3D PnDDCR4_EDF_NONE, + }, { + .fourcc =3D DRM_FORMAT_YUYV, + .v4l2 =3D V4L2_PIX_FMT_YUYV, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 2, + .pnmr =3D PnMR_SPIM_TP_OFF | PnMR_DDDF_YC, + .edf =3D PnDDCR4_EDF_NONE, + }, { + .fourcc =3D DRM_FORMAT_NV12, + .v4l2 =3D V4L2_PIX_FMT_NV12M, + .bpp =3D 12, + .planes =3D 2, + .hsub =3D 2, + .pnmr =3D PnMR_SPIM_TP_OFF | PnMR_DDDF_YC, + .edf =3D PnDDCR4_EDF_NONE, + }, { + .fourcc =3D DRM_FORMAT_NV21, + .v4l2 =3D V4L2_PIX_FMT_NV21M, + .bpp =3D 12, + .planes =3D 2, + .hsub =3D 2, + .pnmr =3D PnMR_SPIM_TP_OFF | PnMR_DDDF_YC, + .edf =3D PnDDCR4_EDF_NONE, + }, { + .fourcc =3D DRM_FORMAT_NV16, + .v4l2 =3D V4L2_PIX_FMT_NV16M, + .bpp =3D 16, + .planes =3D 2, + .hsub =3D 2, + .pnmr =3D PnMR_SPIM_TP_OFF | PnMR_DDDF_YC, + .edf =3D PnDDCR4_EDF_NONE, + }, + /* + * The following formats are not supported on Gen2 and thus have no + * associated .pnmr or .edf settings. + */ + { + .fourcc =3D DRM_FORMAT_RGB332, + .v4l2 =3D V4L2_PIX_FMT_RGB332, + .bpp =3D 8, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_ARGB4444, + .v4l2 =3D V4L2_PIX_FMT_ARGB444, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_XRGB4444, + .v4l2 =3D V4L2_PIX_FMT_XRGB444, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_RGBA4444, + .v4l2 =3D V4L2_PIX_FMT_RGBA444, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_RGBX4444, + .v4l2 =3D V4L2_PIX_FMT_RGBX444, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_ABGR4444, + .v4l2 =3D V4L2_PIX_FMT_ABGR444, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_XBGR4444, + .v4l2 =3D V4L2_PIX_FMT_XBGR444, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_BGRA4444, + .v4l2 =3D V4L2_PIX_FMT_BGRA444, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_BGRX4444, + .v4l2 =3D V4L2_PIX_FMT_BGRX444, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_RGBA5551, + .v4l2 =3D V4L2_PIX_FMT_RGBA555, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_RGBX5551, + .v4l2 =3D V4L2_PIX_FMT_RGBX555, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_ABGR1555, + .v4l2 =3D V4L2_PIX_FMT_ABGR555, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_XBGR1555, + .v4l2 =3D V4L2_PIX_FMT_XBGR555, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_BGRA5551, + .v4l2 =3D V4L2_PIX_FMT_BGRA555, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_BGRX5551, + .v4l2 =3D V4L2_PIX_FMT_BGRX555, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_BGR888, + .v4l2 =3D V4L2_PIX_FMT_RGB24, + .bpp =3D 24, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_RGB888, + .v4l2 =3D V4L2_PIX_FMT_BGR24, + .bpp =3D 24, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_RGBA8888, + .v4l2 =3D V4L2_PIX_FMT_BGRA32, + .bpp =3D 32, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_RGBX8888, + .v4l2 =3D V4L2_PIX_FMT_BGRX32, + .bpp =3D 32, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_ABGR8888, + .v4l2 =3D V4L2_PIX_FMT_RGBA32, + .bpp =3D 32, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_XBGR8888, + .v4l2 =3D V4L2_PIX_FMT_RGBX32, + .bpp =3D 32, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_BGRA8888, + .v4l2 =3D V4L2_PIX_FMT_ARGB32, + .bpp =3D 32, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_BGRX8888, + .v4l2 =3D V4L2_PIX_FMT_XRGB32, + .bpp =3D 32, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_RGBX1010102, + .v4l2 =3D V4L2_PIX_FMT_RGBX1010102, + .bpp =3D 32, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_RGBA1010102, + .v4l2 =3D V4L2_PIX_FMT_RGBA1010102, + .bpp =3D 32, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_ARGB2101010, + .v4l2 =3D V4L2_PIX_FMT_ARGB2101010, + .bpp =3D 32, + .planes =3D 1, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_YVYU, + .v4l2 =3D V4L2_PIX_FMT_YVYU, + .bpp =3D 16, + .planes =3D 1, + .hsub =3D 2, + }, { + .fourcc =3D DRM_FORMAT_NV61, + .v4l2 =3D V4L2_PIX_FMT_NV61M, + .bpp =3D 16, + .planes =3D 2, + .hsub =3D 2, + }, { + .fourcc =3D DRM_FORMAT_YUV420, + .v4l2 =3D V4L2_PIX_FMT_YUV420M, + .bpp =3D 12, + .planes =3D 3, + .hsub =3D 2, + }, { + .fourcc =3D DRM_FORMAT_YVU420, + .v4l2 =3D V4L2_PIX_FMT_YVU420M, + .bpp =3D 12, + .planes =3D 3, + .hsub =3D 2, + }, { + .fourcc =3D DRM_FORMAT_YUV422, + .v4l2 =3D V4L2_PIX_FMT_YUV422M, + .bpp =3D 16, + .planes =3D 3, + .hsub =3D 2, + }, { + .fourcc =3D DRM_FORMAT_YVU422, + .v4l2 =3D V4L2_PIX_FMT_YVU422M, + .bpp =3D 16, + .planes =3D 3, + .hsub =3D 2, + }, { + .fourcc =3D DRM_FORMAT_YUV444, + .v4l2 =3D V4L2_PIX_FMT_YUV444M, + .bpp =3D 24, + .planes =3D 3, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_YVU444, + .v4l2 =3D V4L2_PIX_FMT_YVU444M, + .bpp =3D 24, + .planes =3D 3, + .hsub =3D 1, + }, { + .fourcc =3D DRM_FORMAT_Y210, + .v4l2 =3D V4L2_PIX_FMT_Y210, + .bpp =3D 32, + .planes =3D 1, + .hsub =3D 2, + }, { + .fourcc =3D DRM_FORMAT_Y212, + .v4l2 =3D V4L2_PIX_FMT_Y212, + .bpp =3D 32, + .planes =3D 1, + .hsub =3D 2, + }, +}; + +const struct rcar_du_format_info *rcar_du_format_info(u32 fourcc) +{ + unsigned int i; + + for (i =3D 0; i < ARRAY_SIZE(rcar_du_format_infos); ++i) { + if (rcar_du_format_infos[i].fourcc =3D=3D fourcc) + return &rcar_du_format_infos[i]; + } + + return NULL; +} diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h b/drivers/gpu/drm/rc= ar-du/rcar_du_kms_lib.h new file mode 100644 index 000000000000..d72069436cac --- /dev/null +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * R-Car Display Unit Mode Setting Lib + * + * Copyright (C) 2013-2023 Renesas Electronics Corporation + * + * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) + */ + +#ifndef __RCAR_DU_KMS_LIB_H__ +#define __RCAR_DU_KMS_LIB_H__ + +#include + +struct rcar_du_format_info { + u32 fourcc; + u32 v4l2; + unsigned int bpp; + unsigned int planes; + unsigned int hsub; + unsigned int pnmr; + unsigned int edf; +}; + +const struct rcar_du_format_info *rcar_du_format_info(u32 fourcc); + +#endif /* __RCAR_DU_KMS_LIB_H__ */ --=20 2.25.1 From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61533C76196 for ; Tue, 11 Apr 2023 11:43:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230017AbjDKLnP (ORCPT ); Tue, 11 Apr 2023 07:43:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229985AbjDKLnG (ORCPT ); Tue, 11 Apr 2023 07:43:06 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6DAA440EA; Tue, 11 Apr 2023 04:42:58 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="155597311" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 11 Apr 2023 20:42:57 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 6A451400564A; Tue, 11 Apr 2023 20:42:53 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 03/17] drm: rcar-du: Add vsp lib support Date: Tue, 11 Apr 2023 12:42:21 +0100 Message-Id: <20230411114235.366042-4-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add RCar DU vsp lib support by moving rcar_du_vsp_disable() to the lib file so that same function can be used by both RCar and RZ/G2L DU VSP drivers. Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v1->v6: * Rebased on drm-misc-next and DU-next. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/Kconfig | 5 +++++ drivers/gpu/drm/rcar-du/Makefile | 1 + drivers/gpu/drm/rcar-du/rcar_du_vsp.c | 5 ----- drivers/gpu/drm/rcar-du/rcar_du_vsp.h | 4 ++-- drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c | 17 +++++++++++++++++ drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h | 19 +++++++++++++++++++ 6 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c create mode 100644 drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h diff --git a/drivers/gpu/drm/rcar-du/Kconfig b/drivers/gpu/drm/rcar-du/Kcon= fig index 07a922cc3504..373568a23655 100644 --- a/drivers/gpu/drm/rcar-du/Kconfig +++ b/drivers/gpu/drm/rcar-du/Kconfig @@ -85,3 +85,8 @@ config DRM_RCAR_LIB bool default y depends on DRM_RCAR_DU + +config DRM_RCAR_VSP_LIB + bool + default y + depends on DRM_RCAR_VSP diff --git a/drivers/gpu/drm/rcar-du/Makefile b/drivers/gpu/drm/rcar-du/Mak= efile index 3ce410300334..8fc924cf37a7 100644 --- a/drivers/gpu/drm/rcar-du/Makefile +++ b/drivers/gpu/drm/rcar-du/Makefile @@ -10,6 +10,7 @@ rcar-du-drm-$(CONFIG_DRM_RCAR_LIB) +=3D rcar_du_encoder_l= ib.o \ rcar_du_kms_lib.o =20 rcar-du-drm-$(CONFIG_DRM_RCAR_VSP) +=3D rcar_du_vsp.o +rcar-du-drm-$(CONFIG_DRM_RCAR_VSP_LIB) +=3D rcar_du_vsp_lib.o rcar-du-drm-$(CONFIG_DRM_RCAR_WRITEBACK) +=3D rcar_du_writeback.o =20 obj-$(CONFIG_DRM_RCAR_CMM) +=3D rcar_cmm.o diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c b/drivers/gpu/drm/rcar-d= u/rcar_du_vsp.c index 45c05d0ffc70..3dab5fc822cf 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp.c @@ -88,11 +88,6 @@ void rcar_du_vsp_enable(struct rcar_du_crtc *crtc) vsp1_du_setup_lif(crtc->vsp->vsp, crtc->vsp_pipe, &cfg); } =20 -void rcar_du_vsp_disable(struct rcar_du_crtc *crtc) -{ - vsp1_du_setup_lif(crtc->vsp->vsp, crtc->vsp_pipe, NULL); -} - void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc) { vsp1_du_atomic_begin(crtc->vsp->vsp, crtc->vsp_pipe); diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp.h b/drivers/gpu/drm/rcar-d= u/rcar_du_vsp.h index 67630f0b6599..8fbfa86c93e0 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp.h @@ -12,6 +12,8 @@ =20 #include =20 +#include "rcar_du_vsp_lib.h" + struct drm_framebuffer; struct rcar_du_format_info; struct rcar_du_vsp; @@ -59,7 +61,6 @@ to_rcar_vsp_plane_state(struct drm_plane_state *state) int rcar_du_vsp_init(struct rcar_du_vsp *vsp, struct device_node *np, unsigned int crtcs); void rcar_du_vsp_enable(struct rcar_du_crtc *crtc); -void rcar_du_vsp_disable(struct rcar_du_crtc *crtc); void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc); void rcar_du_vsp_atomic_flush(struct rcar_du_crtc *crtc); int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb, @@ -74,7 +75,6 @@ static inline int rcar_du_vsp_init(struct rcar_du_vsp *vs= p, return -ENXIO; } static inline void rcar_du_vsp_enable(struct rcar_du_crtc *crtc) { }; -static inline void rcar_du_vsp_disable(struct rcar_du_crtc *crtc) { }; static inline void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc) { }; static inline void rcar_du_vsp_atomic_flush(struct rcar_du_crtc *crtc) { }; static inline int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c b/drivers/gpu/drm/rc= ar-du/rcar_du_vsp_lib.c new file mode 100644 index 000000000000..374707b9cc12 --- /dev/null +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * R-Car Display Unit VSP-Based Compositor Lib + * + * Copyright (C) 2015-2023 Renesas Electronics Corporation + * + * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) + */ + +#include + +#include "rcar_du_drv.h" + +void rcar_du_vsp_disable(struct rcar_du_crtc *crtc) +{ + vsp1_du_setup_lif(crtc->vsp->vsp, crtc->vsp_pipe, NULL); +} diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h b/drivers/gpu/drm/rc= ar-du/rcar_du_vsp_lib.h new file mode 100644 index 000000000000..55b026f20c46 --- /dev/null +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * R-Car Display Unit VSP-Based Compositor Lib + * + * Copyright (C) 2015-2023 Renesas Electronics Corporation + * + * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) + */ + +#ifndef __RCAR_DU_VSP_LIB_H__ +#define __RCAR_DU_VSP_LIB_H__ + +#ifdef CONFIG_DRM_RCAR_VSP +void rcar_du_vsp_disable(struct rcar_du_crtc *crtc); +#else +static inline void rcar_du_vsp_disable(struct rcar_du_crtc *crtc) { }; +#endif + +#endif /* __RCAR_DU_VSP_LIB_H__ */ --=20 2.25.1 From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8CDFC77B6F for ; Tue, 11 Apr 2023 11:43:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229785AbjDKLn2 (ORCPT ); Tue, 11 Apr 2023 07:43:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230008AbjDKLnN (ORCPT ); Tue, 11 Apr 2023 07:43:13 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B7AD035B1; Tue, 11 Apr 2023 04:43:03 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="155597319" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 11 Apr 2023 20:43:02 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 6D4014000A93; Tue, 11 Apr 2023 20:42:58 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 04/17] drm: rcar-du: Move rcar_du_vsp_atomic_begin() Date: Tue, 11 Apr 2023 12:42:22 +0100 Message-Id: <20230411114235.366042-5-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move rcar_du_vsp_atomic_begin() to RCar DU VSP lib. Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v1->v6: * Rebased on drm-misc-next and DU-next. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/rcar_du_vsp.c | 5 ----- drivers/gpu/drm/rcar-du/rcar_du_vsp.h | 2 -- drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c | 5 +++++ drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h | 2 ++ 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c b/drivers/gpu/drm/rcar-d= u/rcar_du_vsp.c index 3dab5fc822cf..66ada10fccd4 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp.c @@ -88,11 +88,6 @@ void rcar_du_vsp_enable(struct rcar_du_crtc *crtc) vsp1_du_setup_lif(crtc->vsp->vsp, crtc->vsp_pipe, &cfg); } =20 -void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc) -{ - vsp1_du_atomic_begin(crtc->vsp->vsp, crtc->vsp_pipe); -} - void rcar_du_vsp_atomic_flush(struct rcar_du_crtc *crtc) { struct vsp1_du_atomic_pipe_config cfg =3D { { 0, } }; diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp.h b/drivers/gpu/drm/rcar-d= u/rcar_du_vsp.h index 8fbfa86c93e0..83a2f3e85860 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp.h @@ -61,7 +61,6 @@ to_rcar_vsp_plane_state(struct drm_plane_state *state) int rcar_du_vsp_init(struct rcar_du_vsp *vsp, struct device_node *np, unsigned int crtcs); void rcar_du_vsp_enable(struct rcar_du_crtc *crtc); -void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc); void rcar_du_vsp_atomic_flush(struct rcar_du_crtc *crtc); int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb, struct sg_table sg_tables[3]); @@ -75,7 +74,6 @@ static inline int rcar_du_vsp_init(struct rcar_du_vsp *vs= p, return -ENXIO; } static inline void rcar_du_vsp_enable(struct rcar_du_crtc *crtc) { }; -static inline void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc) { }; static inline void rcar_du_vsp_atomic_flush(struct rcar_du_crtc *crtc) { }; static inline int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb, diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c b/drivers/gpu/drm/rc= ar-du/rcar_du_vsp_lib.c index 374707b9cc12..a69e0842c98c 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c @@ -15,3 +15,8 @@ void rcar_du_vsp_disable(struct rcar_du_crtc *crtc) { vsp1_du_setup_lif(crtc->vsp->vsp, crtc->vsp_pipe, NULL); } + +void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc) +{ + vsp1_du_atomic_begin(crtc->vsp->vsp, crtc->vsp_pipe); +} diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h b/drivers/gpu/drm/rc= ar-du/rcar_du_vsp_lib.h index 55b026f20c46..e0077e832d01 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h @@ -12,8 +12,10 @@ =20 #ifdef CONFIG_DRM_RCAR_VSP void rcar_du_vsp_disable(struct rcar_du_crtc *crtc); +void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc); #else static inline void rcar_du_vsp_disable(struct rcar_du_crtc *crtc) { }; +static inline void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc) { }; #endif =20 #endif /* __RCAR_DU_VSP_LIB_H__ */ --=20 2.25.1 From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3446C77B6F for ; Tue, 11 Apr 2023 11:43:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229789AbjDKLni (ORCPT ); Tue, 11 Apr 2023 07:43:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230006AbjDKLnZ (ORCPT ); Tue, 11 Apr 2023 07:43:25 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D0B2240CD; Tue, 11 Apr 2023 04:43:08 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="159045191" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 11 Apr 2023 20:43:07 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 70FA94008C6C; Tue, 11 Apr 2023 20:43:03 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 05/17] drm: rcar-du: Move rcar_du_vsp_atomic_flush() Date: Tue, 11 Apr 2023 12:42:23 +0100 Message-Id: <20230411114235.366042-6-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move rcar_du_vsp_atomic_flush() to RCar DU vsp lib. Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v1->v6: * Rebased on drm-misc-next and DU-next. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/rcar_du_vsp.c | 13 ------------- drivers/gpu/drm/rcar-du/rcar_du_vsp.h | 2 -- drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c | 14 ++++++++++++++ drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h | 2 ++ 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c b/drivers/gpu/drm/rcar-d= u/rcar_du_vsp.c index 66ada10fccd4..55557d9a3bc8 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp.c @@ -88,19 +88,6 @@ void rcar_du_vsp_enable(struct rcar_du_crtc *crtc) vsp1_du_setup_lif(crtc->vsp->vsp, crtc->vsp_pipe, &cfg); } =20 -void rcar_du_vsp_atomic_flush(struct rcar_du_crtc *crtc) -{ - struct vsp1_du_atomic_pipe_config cfg =3D { { 0, } }; - struct rcar_du_crtc_state *state; - - state =3D to_rcar_crtc_state(crtc->crtc.state); - cfg.crc =3D state->crc; - - rcar_du_writeback_setup(crtc, &cfg.writeback); - - vsp1_du_atomic_flush(crtc->vsp->vsp, crtc->vsp_pipe, &cfg); -} - static const u32 rcar_du_vsp_formats[] =3D { DRM_FORMAT_RGB332, DRM_FORMAT_ARGB4444, diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp.h b/drivers/gpu/drm/rcar-d= u/rcar_du_vsp.h index 83a2f3e85860..b610e6b40304 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp.h @@ -61,7 +61,6 @@ to_rcar_vsp_plane_state(struct drm_plane_state *state) int rcar_du_vsp_init(struct rcar_du_vsp *vsp, struct device_node *np, unsigned int crtcs); void rcar_du_vsp_enable(struct rcar_du_crtc *crtc); -void rcar_du_vsp_atomic_flush(struct rcar_du_crtc *crtc); int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb, struct sg_table sg_tables[3]); void rcar_du_vsp_unmap_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer = *fb, @@ -74,7 +73,6 @@ static inline int rcar_du_vsp_init(struct rcar_du_vsp *vs= p, return -ENXIO; } static inline void rcar_du_vsp_enable(struct rcar_du_crtc *crtc) { }; -static inline void rcar_du_vsp_atomic_flush(struct rcar_du_crtc *crtc) { }; static inline int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb, struct sg_table sg_tables[3]) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c b/drivers/gpu/drm/rc= ar-du/rcar_du_vsp_lib.c index a69e0842c98c..ecf0801202b7 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c @@ -10,6 +10,7 @@ #include =20 #include "rcar_du_drv.h" +#include "rcar_du_writeback.h" =20 void rcar_du_vsp_disable(struct rcar_du_crtc *crtc) { @@ -20,3 +21,16 @@ void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc) { vsp1_du_atomic_begin(crtc->vsp->vsp, crtc->vsp_pipe); } + +void rcar_du_vsp_atomic_flush(struct rcar_du_crtc *crtc) +{ + struct vsp1_du_atomic_pipe_config cfg =3D { { 0, } }; + struct rcar_du_crtc_state *state; + + state =3D to_rcar_crtc_state(crtc->crtc.state); + cfg.crc =3D state->crc; + + rcar_du_writeback_setup(crtc, &cfg.writeback); + + vsp1_du_atomic_flush(crtc->vsp->vsp, crtc->vsp_pipe, &cfg); +} diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h b/drivers/gpu/drm/rc= ar-du/rcar_du_vsp_lib.h index e0077e832d01..1506e739f714 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h @@ -13,9 +13,11 @@ #ifdef CONFIG_DRM_RCAR_VSP void rcar_du_vsp_disable(struct rcar_du_crtc *crtc); void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc); +void rcar_du_vsp_atomic_flush(struct rcar_du_crtc *crtc); #else static inline void rcar_du_vsp_disable(struct rcar_du_crtc *crtc) { }; static inline void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc) { }; +static inline void rcar_du_vsp_atomic_flush(struct rcar_du_crtc *crtc) { }; #endif =20 #endif /* __RCAR_DU_VSP_LIB_H__ */ --=20 2.25.1 From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F735C77B6F for ; Tue, 11 Apr 2023 11:43:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229977AbjDKLn4 (ORCPT ); Tue, 11 Apr 2023 07:43:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229840AbjDKLnq (ORCPT ); Tue, 11 Apr 2023 07:43:46 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9A16D40E5; Tue, 11 Apr 2023 04:43:24 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="159045199" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 11 Apr 2023 20:43:12 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 73536400195D; Tue, 11 Apr 2023 20:43:08 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 06/17] drm: rcar-du: Move rcar_du_vsp_{map,unmap}_fb() Date: Tue, 11 Apr 2023 12:42:24 +0100 Message-Id: <20230411114235.366042-7-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move rcar_du_vsp_{map,unmap}_fb() to RCar DU VSP lib. Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v1->v6: * Rebased on drm-misc-next and DU-next. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/rcar_du_vsp.c | 78 --------------------- drivers/gpu/drm/rcar-du/rcar_du_vsp.h | 18 ----- drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c | 84 +++++++++++++++++++++++ drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h | 20 ++++++ 4 files changed, 104 insertions(+), 96 deletions(-) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c b/drivers/gpu/drm/rcar-d= u/rcar_du_vsp.c index 55557d9a3bc8..d461043c7828 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp.c @@ -11,11 +11,8 @@ #include #include #include -#include -#include #include #include -#include #include #include =20 @@ -208,68 +205,6 @@ static void rcar_du_vsp_plane_setup(struct rcar_du_vsp= _plane *plane) plane->index, &cfg); } =20 -int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb, - struct sg_table sg_tables[3]) -{ - struct rcar_du_device *rcdu =3D vsp->dev; - unsigned int i, j; - int ret; - - for (i =3D 0; i < fb->format->num_planes; ++i) { - struct drm_gem_dma_object *gem =3D drm_fb_dma_get_gem_obj(fb, i); - struct sg_table *sgt =3D &sg_tables[i]; - - if (gem->sgt) { - struct scatterlist *src; - struct scatterlist *dst; - - /* - * If the GEM buffer has a scatter gather table, it has - * been imported from a dma-buf and has no physical - * address as it might not be physically contiguous. - * Copy the original scatter gather table to map it to - * the VSP. - */ - ret =3D sg_alloc_table(sgt, gem->sgt->orig_nents, - GFP_KERNEL); - if (ret) - goto fail; - - src =3D gem->sgt->sgl; - dst =3D sgt->sgl; - for (j =3D 0; j < gem->sgt->orig_nents; ++j) { - sg_set_page(dst, sg_page(src), src->length, - src->offset); - src =3D sg_next(src); - dst =3D sg_next(dst); - } - } else { - ret =3D dma_get_sgtable(rcdu->dev, sgt, gem->vaddr, - gem->dma_addr, gem->base.size); - if (ret) - goto fail; - } - - ret =3D vsp1_du_map_sg(vsp->vsp, sgt); - if (ret) { - sg_free_table(sgt); - goto fail; - } - } - - return 0; - -fail: - while (i--) { - struct sg_table *sgt =3D &sg_tables[i]; - - vsp1_du_unmap_sg(vsp->vsp, sgt); - sg_free_table(sgt); - } - - return ret; -} - static int rcar_du_vsp_plane_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state) { @@ -291,19 +226,6 @@ static int rcar_du_vsp_plane_prepare_fb(struct drm_pla= ne *plane, return drm_gem_plane_helper_prepare_fb(plane, state); } =20 -void rcar_du_vsp_unmap_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer = *fb, - struct sg_table sg_tables[3]) -{ - unsigned int i; - - for (i =3D 0; i < fb->format->num_planes; ++i) { - struct sg_table *sgt =3D &sg_tables[i]; - - vsp1_du_unmap_sg(vsp->vsp, sgt); - sg_free_table(sgt); - } -} - static void rcar_du_vsp_plane_cleanup_fb(struct drm_plane *plane, struct drm_plane_state *state) { diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp.h b/drivers/gpu/drm/rcar-d= u/rcar_du_vsp.h index b610e6b40304..4022ed014353 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp.h @@ -14,10 +14,7 @@ =20 #include "rcar_du_vsp_lib.h" =20 -struct drm_framebuffer; struct rcar_du_format_info; -struct rcar_du_vsp; -struct sg_table; =20 struct rcar_du_vsp_plane { struct drm_plane plane; @@ -61,10 +58,6 @@ to_rcar_vsp_plane_state(struct drm_plane_state *state) int rcar_du_vsp_init(struct rcar_du_vsp *vsp, struct device_node *np, unsigned int crtcs); void rcar_du_vsp_enable(struct rcar_du_crtc *crtc); -int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb, - struct sg_table sg_tables[3]); -void rcar_du_vsp_unmap_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer = *fb, - struct sg_table sg_tables[3]); #else static inline int rcar_du_vsp_init(struct rcar_du_vsp *vsp, struct device_node *np, @@ -73,17 +66,6 @@ static inline int rcar_du_vsp_init(struct rcar_du_vsp *v= sp, return -ENXIO; } static inline void rcar_du_vsp_enable(struct rcar_du_crtc *crtc) { }; -static inline int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, - struct drm_framebuffer *fb, - struct sg_table sg_tables[3]) -{ - return -ENXIO; -} -static inline void rcar_du_vsp_unmap_fb(struct rcar_du_vsp *vsp, - struct drm_framebuffer *fb, - struct sg_table sg_tables[3]) -{ -} #endif =20 #endif /* __RCAR_DU_VSP_H__ */ diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c b/drivers/gpu/drm/rc= ar-du/rcar_du_vsp_lib.c index ecf0801202b7..92ae3b0cf995 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c @@ -7,6 +7,15 @@ * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) */ =20 +#include +#include +#include +#include +#include + +#include +#include + #include =20 #include "rcar_du_drv.h" @@ -34,3 +43,78 @@ void rcar_du_vsp_atomic_flush(struct rcar_du_crtc *crtc) =20 vsp1_du_atomic_flush(crtc->vsp->vsp, crtc->vsp_pipe, &cfg); } + +int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb, + struct sg_table sg_tables[3]) +{ + struct rcar_du_device *rcdu =3D vsp->dev; + unsigned int i, j; + int ret; + + for (i =3D 0; i < fb->format->num_planes; ++i) { + struct drm_gem_dma_object *gem =3D drm_fb_dma_get_gem_obj(fb, i); + struct sg_table *sgt =3D &sg_tables[i]; + + if (gem->sgt) { + struct scatterlist *src; + struct scatterlist *dst; + + /* + * If the GEM buffer has a scatter gather table, it has + * been imported from a dma-buf and has no physical + * address as it might not be physically contiguous. + * Copy the original scatter gather table to map it to + * the VSP. + */ + ret =3D sg_alloc_table(sgt, gem->sgt->orig_nents, + GFP_KERNEL); + if (ret) + goto fail; + + src =3D gem->sgt->sgl; + dst =3D sgt->sgl; + for (j =3D 0; j < gem->sgt->orig_nents; ++j) { + sg_set_page(dst, sg_page(src), src->length, + src->offset); + src =3D sg_next(src); + dst =3D sg_next(dst); + } + } else { + ret =3D dma_get_sgtable(rcdu->dev, sgt, gem->vaddr, + gem->dma_addr, gem->base.size); + if (ret) + goto fail; + } + + ret =3D vsp1_du_map_sg(vsp->vsp, sgt); + if (ret) { + sg_free_table(sgt); + goto fail; + } + } + + return 0; + +fail: + while (i--) { + struct sg_table *sgt =3D &sg_tables[i]; + + vsp1_du_unmap_sg(vsp->vsp, sgt); + sg_free_table(sgt); + } + + return ret; +} + +void rcar_du_vsp_unmap_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer = *fb, + struct sg_table sg_tables[3]) +{ + unsigned int i; + + for (i =3D 0; i < fb->format->num_planes; ++i) { + struct sg_table *sgt =3D &sg_tables[i]; + + vsp1_du_unmap_sg(vsp->vsp, sgt); + sg_free_table(sgt); + } +} diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h b/drivers/gpu/drm/rc= ar-du/rcar_du_vsp_lib.h index 1506e739f714..d59182b2630f 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h @@ -10,14 +10,34 @@ #ifndef __RCAR_DU_VSP_LIB_H__ #define __RCAR_DU_VSP_LIB_H__ =20 +struct drm_framebuffer; +struct rcar_du_vsp; +struct sg_table; + #ifdef CONFIG_DRM_RCAR_VSP void rcar_du_vsp_disable(struct rcar_du_crtc *crtc); void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc); void rcar_du_vsp_atomic_flush(struct rcar_du_crtc *crtc); +int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb, + struct sg_table sg_tables[3]); +void rcar_du_vsp_unmap_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer = *fb, + struct sg_table sg_tables[3]); #else static inline void rcar_du_vsp_disable(struct rcar_du_crtc *crtc) { }; static inline void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc) { }; static inline void rcar_du_vsp_atomic_flush(struct rcar_du_crtc *crtc) { }; +static inline int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, + struct drm_framebuffer *fb, + struct sg_table sg_tables[3]) +{ + return -ENXIO; +} + +static inline void rcar_du_vsp_unmap_fb(struct rcar_du_vsp *vsp, + struct drm_framebuffer *fb, + struct sg_table sg_tables[3]) +{ +} #endif =20 #endif /* __RCAR_DU_VSP_LIB_H__ */ --=20 2.25.1 From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A697C76196 for ; Tue, 11 Apr 2023 11:43:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229621AbjDKLnw (ORCPT ); Tue, 11 Apr 2023 07:43:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229575AbjDKLnm (ORCPT ); Tue, 11 Apr 2023 07:43:42 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3CEC749C5; Tue, 11 Apr 2023 04:43:18 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="155597350" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 11 Apr 2023 20:43:17 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 78145400564A; Tue, 11 Apr 2023 20:43:13 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 07/17] drm: rcar-du: Move rcar_du_dumb_create() Date: Tue, 11 Apr 2023 12:42:25 +0100 Message-Id: <20230411114235.366042-8-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move rcar_du_dumb_create() to RCar DU KMS lib. Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v1->v6: * Rebased on drm-misc-next and DU-next. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/rcar_du_kms.c | 21 ----------------- drivers/gpu/drm/rcar-du/rcar_du_kms.h | 5 ---- drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c | 28 +++++++++++++++++++++++ drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h | 7 ++++++ 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.c b/drivers/gpu/drm/rcar-d= u/rcar_du_kms.c index 3141d447e979..4b5511a20313 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.c @@ -81,27 +81,6 @@ struct drm_gem_object *rcar_du_gem_prime_import_sg_table= (struct drm_device *dev, return gem_obj; } =20 -int rcar_du_dumb_create(struct drm_file *file, struct drm_device *dev, - struct drm_mode_create_dumb *args) -{ - struct rcar_du_device *rcdu =3D to_rcar_du_device(dev); - unsigned int min_pitch =3D DIV_ROUND_UP(args->width * args->bpp, 8); - unsigned int align; - - /* - * The R8A7779 DU requires a 16 pixels pitch alignment as documented, - * but the R8A7790 DU seems to require a 128 bytes pitch alignment. - */ - if (rcar_du_needs(rcdu, RCAR_DU_QUIRK_ALIGN_128B)) - align =3D 128; - else - align =3D 16 * args->bpp / 8; - - args->pitch =3D roundup(min_pitch, align); - - return drm_gem_dma_dumb_create_internal(file, dev, args); -} - static struct drm_framebuffer * rcar_du_fb_create(struct drm_device *dev, struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.h b/drivers/gpu/drm/rcar-d= u/rcar_du_kms.h index d2d4f34fe557..5490c99947fd 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.h @@ -13,18 +13,13 @@ #include "rcar_du_kms_lib.h" =20 struct dma_buf_attachment; -struct drm_file; struct drm_device; struct drm_gem_object; -struct drm_mode_create_dumb; struct rcar_du_device; struct sg_table; =20 int rcar_du_modeset_init(struct rcar_du_device *rcdu); =20 -int rcar_du_dumb_create(struct drm_file *file, struct drm_device *dev, - struct drm_mode_create_dumb *args); - struct drm_gem_object *rcar_du_gem_prime_import_sg_table(struct drm_device= *dev, struct dma_buf_attachment *attach, struct sg_table *sgt); diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c b/drivers/gpu/drm/rc= ar-du/rcar_du_kms_lib.c index 5921040586fc..e88f753704cd 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c @@ -7,10 +7,13 @@ * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) */ =20 +#include #include +#include =20 #include =20 +#include "rcar_du_drv.h" #include "rcar_du_kms.h" #include "rcar_du_regs.h" =20 @@ -333,3 +336,28 @@ const struct rcar_du_format_info *rcar_du_format_info(= u32 fourcc) =20 return NULL; } + +/* -----------------------------------------------------------------------= ------ + * Frame buffer + */ + +int rcar_du_dumb_create(struct drm_file *file, struct drm_device *dev, + struct drm_mode_create_dumb *args) +{ + struct rcar_du_device *rcdu =3D to_rcar_du_device(dev); + unsigned int min_pitch =3D DIV_ROUND_UP(args->width * args->bpp, 8); + unsigned int align; + + /* + * The R8A7779 DU requires a 16 pixels pitch alignment as documented, + * but the R8A7790 DU seems to require a 128 bytes pitch alignment. + */ + if (rcar_du_needs(rcdu, RCAR_DU_QUIRK_ALIGN_128B)) + align =3D 128; + else + align =3D 16 * args->bpp / 8; + + args->pitch =3D roundup(min_pitch, align); + + return drm_gem_dma_dumb_create_internal(file, dev, args); +} diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h b/drivers/gpu/drm/rc= ar-du/rcar_du_kms_lib.h index d72069436cac..6e4cfe2ef867 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h @@ -12,6 +12,10 @@ =20 #include =20 +struct drm_device; +struct drm_file; +struct drm_mode_create_dumb; + struct rcar_du_format_info { u32 fourcc; u32 v4l2; @@ -24,4 +28,7 @@ struct rcar_du_format_info { =20 const struct rcar_du_format_info *rcar_du_format_info(u32 fourcc); =20 +int rcar_du_dumb_create(struct drm_file *file, struct drm_device *dev, + struct drm_mode_create_dumb *args); + #endif /* __RCAR_DU_KMS_LIB_H__ */ --=20 2.25.1 From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 428B3C76196 for ; Tue, 11 Apr 2023 11:44:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229909AbjDKLoA (ORCPT ); Tue, 11 Apr 2023 07:44:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbjDKLnq (ORCPT ); Tue, 11 Apr 2023 07:43:46 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 761A335B1; Tue, 11 Apr 2023 04:43:25 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="155597359" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 11 Apr 2023 20:43:23 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 831FA4000A93; Tue, 11 Apr 2023 20:43:18 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 08/17] drm: rcar-du: Move rcar_du_gem_prime_import_sg_table() Date: Tue, 11 Apr 2023 12:42:26 +0100 Message-Id: <20230411114235.366042-9-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move rcar_du_gem_prime_import_sg_table() to RCar DU KMS lib. Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v1->v6: * Rebased on drm-misc-next and DU-next. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/rcar_du_kms.c | 47 ----------------------- drivers/gpu/drm/rcar-du/rcar_du_kms.h | 8 ---- drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c | 46 ++++++++++++++++++++++ drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h | 7 ++++ 4 files changed, 53 insertions(+), 55 deletions(-) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.c b/drivers/gpu/drm/rcar-d= u/rcar_du_kms.c index 4b5511a20313..ae969f640bb6 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.c @@ -11,8 +11,6 @@ #include #include #include -#include -#include #include #include #include @@ -36,51 +34,6 @@ * Frame buffer */ =20 -static const struct drm_gem_object_funcs rcar_du_gem_funcs =3D { - .free =3D drm_gem_dma_object_free, - .print_info =3D drm_gem_dma_object_print_info, - .get_sg_table =3D drm_gem_dma_object_get_sg_table, - .vmap =3D drm_gem_dma_object_vmap, - .mmap =3D drm_gem_dma_object_mmap, - .vm_ops =3D &drm_gem_dma_vm_ops, -}; - -struct drm_gem_object *rcar_du_gem_prime_import_sg_table(struct drm_device= *dev, - struct dma_buf_attachment *attach, - struct sg_table *sgt) -{ - struct rcar_du_device *rcdu =3D to_rcar_du_device(dev); - struct drm_gem_dma_object *dma_obj; - struct drm_gem_object *gem_obj; - int ret; - - if (!rcar_du_has(rcdu, RCAR_DU_FEATURE_VSP1_SOURCE)) - return drm_gem_dma_prime_import_sg_table(dev, attach, sgt); - - /* Create a DMA GEM buffer. */ - dma_obj =3D kzalloc(sizeof(*dma_obj), GFP_KERNEL); - if (!dma_obj) - return ERR_PTR(-ENOMEM); - - gem_obj =3D &dma_obj->base; - gem_obj->funcs =3D &rcar_du_gem_funcs; - - drm_gem_private_object_init(dev, gem_obj, attach->dmabuf->size); - dma_obj->map_noncoherent =3D false; - - ret =3D drm_gem_create_mmap_offset(gem_obj); - if (ret) { - drm_gem_object_release(gem_obj); - kfree(dma_obj); - return ERR_PTR(ret); - } - - dma_obj->dma_addr =3D 0; - dma_obj->sgt =3D sgt; - - return gem_obj; -} - static struct drm_framebuffer * rcar_du_fb_create(struct drm_device *dev, struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.h b/drivers/gpu/drm/rcar-d= u/rcar_du_kms.h index 5490c99947fd..02ba7c1c7a70 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.h @@ -12,16 +12,8 @@ =20 #include "rcar_du_kms_lib.h" =20 -struct dma_buf_attachment; -struct drm_device; -struct drm_gem_object; struct rcar_du_device; -struct sg_table; =20 int rcar_du_modeset_init(struct rcar_du_device *rcdu); =20 -struct drm_gem_object *rcar_du_gem_prime_import_sg_table(struct drm_device= *dev, - struct dma_buf_attachment *attach, - struct sg_table *sgt); - #endif /* __RCAR_DU_KMS_H__ */ diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c b/drivers/gpu/drm/rc= ar-du/rcar_du_kms_lib.c index e88f753704cd..37809d06df89 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c @@ -10,6 +10,7 @@ #include #include #include +#include =20 #include =20 @@ -341,6 +342,51 @@ const struct rcar_du_format_info *rcar_du_format_info(= u32 fourcc) * Frame buffer */ =20 +static const struct drm_gem_object_funcs rcar_du_gem_funcs =3D { + .free =3D drm_gem_dma_object_free, + .print_info =3D drm_gem_dma_object_print_info, + .get_sg_table =3D drm_gem_dma_object_get_sg_table, + .vmap =3D drm_gem_dma_object_vmap, + .mmap =3D drm_gem_dma_object_mmap, + .vm_ops =3D &drm_gem_dma_vm_ops, +}; + +struct drm_gem_object *rcar_du_gem_prime_import_sg_table(struct drm_device= *dev, + struct dma_buf_attachment *attach, + struct sg_table *sgt) +{ + struct rcar_du_device *rcdu =3D to_rcar_du_device(dev); + struct drm_gem_dma_object *dma_obj; + struct drm_gem_object *gem_obj; + int ret; + + if (!rcar_du_has(rcdu, RCAR_DU_FEATURE_VSP1_SOURCE)) + return drm_gem_dma_prime_import_sg_table(dev, attach, sgt); + + /* Create a DMA GEM buffer. */ + dma_obj =3D kzalloc(sizeof(*dma_obj), GFP_KERNEL); + if (!dma_obj) + return ERR_PTR(-ENOMEM); + + gem_obj =3D &dma_obj->base; + gem_obj->funcs =3D &rcar_du_gem_funcs; + + drm_gem_private_object_init(dev, gem_obj, attach->dmabuf->size); + dma_obj->map_noncoherent =3D false; + + ret =3D drm_gem_create_mmap_offset(gem_obj); + if (ret) { + drm_gem_object_release(gem_obj); + kfree(dma_obj); + return ERR_PTR(ret); + } + + dma_obj->dma_addr =3D 0; + dma_obj->sgt =3D sgt; + + return gem_obj; +} + int rcar_du_dumb_create(struct drm_file *file, struct drm_device *dev, struct drm_mode_create_dumb *args) { diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h b/drivers/gpu/drm/rc= ar-du/rcar_du_kms_lib.h index 6e4cfe2ef867..2556966024f8 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h @@ -12,9 +12,12 @@ =20 #include =20 +struct dma_buf_attachment; struct drm_device; struct drm_file; +struct drm_gem_object; struct drm_mode_create_dumb; +struct sg_table; =20 struct rcar_du_format_info { u32 fourcc; @@ -31,4 +34,8 @@ const struct rcar_du_format_info *rcar_du_format_info(u32= fourcc); int rcar_du_dumb_create(struct drm_file *file, struct drm_device *dev, struct drm_mode_create_dumb *args); =20 +struct drm_gem_object *rcar_du_gem_prime_import_sg_table(struct drm_device= *dev, + struct dma_buf_attachment *attach, + struct sg_table *sgt); + #endif /* __RCAR_DU_KMS_LIB_H__ */ --=20 2.25.1 From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECB0DC77B74 for ; Tue, 11 Apr 2023 11:44:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229982AbjDKLoQ (ORCPT ); Tue, 11 Apr 2023 07:44:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229696AbjDKLoN (ORCPT ); Tue, 11 Apr 2023 07:44:13 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 88D3CE45; Tue, 11 Apr 2023 04:43:46 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="159045220" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 11 Apr 2023 20:43:27 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 82CAE400564A; Tue, 11 Apr 2023 20:43:23 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 09/17] drm: rcar-du: Add rcar_du_lib_vsp_init() Date: Tue, 11 Apr 2023 12:42:27 +0100 Message-Id: <20230411114235.366042-10-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" RZ/G2L does not have plane registers as well as it uses different CRTC. The below functions are SoC specific * rcar_du_crtc_finish_page_flip() * __rcar_du_plane_setup * __rcar_du_plane_atomic_check All other function can be handled in common code. This patch introduces rcar_du_lib_vsp_init() to share common_init, vsp_formats and vsp_plane_func= s(). Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v1->v6: * Rebased on drm-misc-next and DU-next. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/rcar_du_vsp.c | 203 +-------------------- drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c | 212 ++++++++++++++++++++++ drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h | 11 ++ 3 files changed, 225 insertions(+), 201 deletions(-) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c b/drivers/gpu/drm/rcar-d= u/rcar_du_vsp.c index d461043c7828..e54a605a1bdf 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp.c @@ -13,7 +13,6 @@ #include #include #include -#include #include =20 #include @@ -85,71 +84,6 @@ void rcar_du_vsp_enable(struct rcar_du_crtc *crtc) vsp1_du_setup_lif(crtc->vsp->vsp, crtc->vsp_pipe, &cfg); } =20 -static const u32 rcar_du_vsp_formats[] =3D { - DRM_FORMAT_RGB332, - DRM_FORMAT_ARGB4444, - DRM_FORMAT_XRGB4444, - DRM_FORMAT_ARGB1555, - DRM_FORMAT_XRGB1555, - DRM_FORMAT_RGB565, - DRM_FORMAT_BGR888, - DRM_FORMAT_RGB888, - DRM_FORMAT_BGRA8888, - DRM_FORMAT_BGRX8888, - DRM_FORMAT_ARGB8888, - DRM_FORMAT_XRGB8888, - DRM_FORMAT_UYVY, - DRM_FORMAT_YUYV, - DRM_FORMAT_YVYU, - DRM_FORMAT_NV12, - DRM_FORMAT_NV21, - DRM_FORMAT_NV16, - DRM_FORMAT_NV61, - DRM_FORMAT_YUV420, - DRM_FORMAT_YVU420, - DRM_FORMAT_YUV422, - DRM_FORMAT_YVU422, - DRM_FORMAT_YUV444, - DRM_FORMAT_YVU444, -}; - -/* - * Gen4 supports the same formats as above, and additionally 2-10-10-10 RGB - * formats and Y210 & Y212 formats. - */ -static const u32 rcar_du_vsp_formats_gen4[] =3D { - DRM_FORMAT_RGB332, - DRM_FORMAT_ARGB4444, - DRM_FORMAT_XRGB4444, - DRM_FORMAT_ARGB1555, - DRM_FORMAT_XRGB1555, - DRM_FORMAT_RGB565, - DRM_FORMAT_BGR888, - DRM_FORMAT_RGB888, - DRM_FORMAT_BGRA8888, - DRM_FORMAT_BGRX8888, - DRM_FORMAT_ARGB8888, - DRM_FORMAT_XRGB8888, - DRM_FORMAT_RGBX1010102, - DRM_FORMAT_RGBA1010102, - DRM_FORMAT_ARGB2101010, - DRM_FORMAT_UYVY, - DRM_FORMAT_YUYV, - DRM_FORMAT_YVYU, - DRM_FORMAT_NV12, - DRM_FORMAT_NV21, - DRM_FORMAT_NV16, - DRM_FORMAT_NV61, - DRM_FORMAT_YUV420, - DRM_FORMAT_YVU420, - DRM_FORMAT_YUV422, - DRM_FORMAT_YVU422, - DRM_FORMAT_YUV444, - DRM_FORMAT_YVU444, - DRM_FORMAT_Y210, - DRM_FORMAT_Y212, -}; - static void rcar_du_vsp_plane_setup(struct rcar_du_vsp_plane *plane) { struct rcar_du_vsp_plane_state *state =3D @@ -271,142 +205,9 @@ static const struct drm_plane_helper_funcs rcar_du_vs= p_plane_helper_funcs =3D { .atomic_update =3D rcar_du_vsp_plane_atomic_update, }; =20 -static struct drm_plane_state * -rcar_du_vsp_plane_atomic_duplicate_state(struct drm_plane *plane) -{ - struct rcar_du_vsp_plane_state *copy; - - if (WARN_ON(!plane->state)) - return NULL; - - copy =3D kzalloc(sizeof(*copy), GFP_KERNEL); - if (copy =3D=3D NULL) - return NULL; - - __drm_atomic_helper_plane_duplicate_state(plane, ©->state); - - return ©->state; -} - -static void rcar_du_vsp_plane_atomic_destroy_state(struct drm_plane *plane, - struct drm_plane_state *state) -{ - __drm_atomic_helper_plane_destroy_state(state); - kfree(to_rcar_vsp_plane_state(state)); -} - -static void rcar_du_vsp_plane_reset(struct drm_plane *plane) -{ - struct rcar_du_vsp_plane_state *state; - - if (plane->state) { - rcar_du_vsp_plane_atomic_destroy_state(plane, plane->state); - plane->state =3D NULL; - } - - state =3D kzalloc(sizeof(*state), GFP_KERNEL); - if (state =3D=3D NULL) - return; - - __drm_atomic_helper_plane_reset(plane, &state->state); -} - -static const struct drm_plane_funcs rcar_du_vsp_plane_funcs =3D { - .update_plane =3D drm_atomic_helper_update_plane, - .disable_plane =3D drm_atomic_helper_disable_plane, - .reset =3D rcar_du_vsp_plane_reset, - .destroy =3D drm_plane_cleanup, - .atomic_duplicate_state =3D rcar_du_vsp_plane_atomic_duplicate_state, - .atomic_destroy_state =3D rcar_du_vsp_plane_atomic_destroy_state, -}; - -static void rcar_du_vsp_cleanup(struct drm_device *dev, void *res) -{ - struct rcar_du_vsp *vsp =3D res; - unsigned int i; - - for (i =3D 0; i < vsp->num_planes; ++i) { - struct rcar_du_vsp_plane *plane =3D &vsp->planes[i]; - - drm_plane_cleanup(&plane->plane); - } - - kfree(vsp->planes); - - put_device(vsp->vsp); -} - int rcar_du_vsp_init(struct rcar_du_vsp *vsp, struct device_node *np, unsigned int crtcs) { - struct rcar_du_device *rcdu =3D vsp->dev; - struct platform_device *pdev; - unsigned int num_crtcs =3D hweight32(crtcs); - unsigned int num_planes; - unsigned int i; - int ret; - - /* Find the VSP device and initialize it. */ - pdev =3D of_find_device_by_node(np); - if (!pdev) - return -ENXIO; - - vsp->vsp =3D &pdev->dev; - - ret =3D drmm_add_action_or_reset(&rcdu->ddev, rcar_du_vsp_cleanup, vsp); - if (ret < 0) - return ret; - - ret =3D vsp1_du_init(vsp->vsp); - if (ret < 0) - return ret; - - num_planes =3D rcdu->info->num_rpf; - - vsp->planes =3D kcalloc(num_planes, sizeof(*vsp->planes), GFP_KERNEL); - if (!vsp->planes) - return -ENOMEM; - - for (i =3D 0; i < num_planes; ++i) { - enum drm_plane_type type =3D i < num_crtcs - ? DRM_PLANE_TYPE_PRIMARY - : DRM_PLANE_TYPE_OVERLAY; - struct rcar_du_vsp_plane *plane =3D &vsp->planes[i]; - unsigned int num_formats; - const u32 *formats; - - if (rcdu->info->gen < 4) { - num_formats =3D ARRAY_SIZE(rcar_du_vsp_formats); - formats =3D rcar_du_vsp_formats; - } else { - num_formats =3D ARRAY_SIZE(rcar_du_vsp_formats_gen4); - formats =3D rcar_du_vsp_formats_gen4; - } - - plane->vsp =3D vsp; - plane->index =3D i; - - ret =3D drm_universal_plane_init(&rcdu->ddev, &plane->plane, - crtcs, &rcar_du_vsp_plane_funcs, - formats, num_formats, - NULL, type, NULL); - if (ret < 0) - return ret; - - drm_plane_helper_add(&plane->plane, - &rcar_du_vsp_plane_helper_funcs); - - drm_plane_create_alpha_property(&plane->plane); - drm_plane_create_zpos_property(&plane->plane, i, 0, - num_planes - 1); - - drm_plane_create_blend_mode_property(&plane->plane, - BIT(DRM_MODE_BLEND_PIXEL_NONE) | - BIT(DRM_MODE_BLEND_PREMULTI) | - BIT(DRM_MODE_BLEND_COVERAGE)); - - vsp->num_planes++; - } - - return 0; + return rcar_du_lib_vsp_init(vsp, np, crtcs, + &rcar_du_vsp_plane_helper_funcs); } diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c b/drivers/gpu/drm/rc= ar-du/rcar_du_vsp_lib.c index 92ae3b0cf995..f2d55695f6c1 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c @@ -7,13 +7,19 @@ * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) */ =20 +#include +#include +#include +#include #include #include #include #include #include +#include =20 #include +#include #include =20 #include @@ -44,6 +50,71 @@ void rcar_du_vsp_atomic_flush(struct rcar_du_crtc *crtc) vsp1_du_atomic_flush(crtc->vsp->vsp, crtc->vsp_pipe, &cfg); } =20 +static const u32 rcar_du_vsp_formats[] =3D { + DRM_FORMAT_RGB332, + DRM_FORMAT_ARGB4444, + DRM_FORMAT_XRGB4444, + DRM_FORMAT_ARGB1555, + DRM_FORMAT_XRGB1555, + DRM_FORMAT_RGB565, + DRM_FORMAT_BGR888, + DRM_FORMAT_RGB888, + DRM_FORMAT_BGRA8888, + DRM_FORMAT_BGRX8888, + DRM_FORMAT_ARGB8888, + DRM_FORMAT_XRGB8888, + DRM_FORMAT_UYVY, + DRM_FORMAT_YUYV, + DRM_FORMAT_YVYU, + DRM_FORMAT_NV12, + DRM_FORMAT_NV21, + DRM_FORMAT_NV16, + DRM_FORMAT_NV61, + DRM_FORMAT_YUV420, + DRM_FORMAT_YVU420, + DRM_FORMAT_YUV422, + DRM_FORMAT_YVU422, + DRM_FORMAT_YUV444, + DRM_FORMAT_YVU444, +}; + +/* + * Gen4 supports the same formats as above, and additionally 2-10-10-10 RGB + * formats and Y210 & Y212 formats. + */ +static const u32 rcar_du_vsp_formats_gen4[] =3D { + DRM_FORMAT_RGB332, + DRM_FORMAT_ARGB4444, + DRM_FORMAT_XRGB4444, + DRM_FORMAT_ARGB1555, + DRM_FORMAT_XRGB1555, + DRM_FORMAT_RGB565, + DRM_FORMAT_BGR888, + DRM_FORMAT_RGB888, + DRM_FORMAT_BGRA8888, + DRM_FORMAT_BGRX8888, + DRM_FORMAT_ARGB8888, + DRM_FORMAT_XRGB8888, + DRM_FORMAT_RGBX1010102, + DRM_FORMAT_RGBA1010102, + DRM_FORMAT_ARGB2101010, + DRM_FORMAT_UYVY, + DRM_FORMAT_YUYV, + DRM_FORMAT_YVYU, + DRM_FORMAT_NV12, + DRM_FORMAT_NV21, + DRM_FORMAT_NV16, + DRM_FORMAT_NV61, + DRM_FORMAT_YUV420, + DRM_FORMAT_YVU420, + DRM_FORMAT_YUV422, + DRM_FORMAT_YVU422, + DRM_FORMAT_YUV444, + DRM_FORMAT_YVU444, + DRM_FORMAT_Y210, + DRM_FORMAT_Y212, +}; + int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb, struct sg_table sg_tables[3]) { @@ -118,3 +189,144 @@ void rcar_du_vsp_unmap_fb(struct rcar_du_vsp *vsp, st= ruct drm_framebuffer *fb, sg_free_table(sgt); } } + +static struct drm_plane_state * +rcar_du_vsp_plane_atomic_duplicate_state(struct drm_plane *plane) +{ + struct rcar_du_vsp_plane_state *copy; + + if (WARN_ON(!plane->state)) + return NULL; + + copy =3D kzalloc(sizeof(*copy), GFP_KERNEL); + if (copy =3D=3D NULL) + return NULL; + + __drm_atomic_helper_plane_duplicate_state(plane, ©->state); + + return ©->state; +} + +static void rcar_du_vsp_plane_atomic_destroy_state(struct drm_plane *plane, + struct drm_plane_state *state) +{ + __drm_atomic_helper_plane_destroy_state(state); + kfree(to_rcar_vsp_plane_state(state)); +} + +static void rcar_du_vsp_plane_reset(struct drm_plane *plane) +{ + struct rcar_du_vsp_plane_state *state; + + if (plane->state) { + rcar_du_vsp_plane_atomic_destroy_state(plane, plane->state); + plane->state =3D NULL; + } + + state =3D kzalloc(sizeof(*state), GFP_KERNEL); + if (state =3D=3D NULL) + return; + + __drm_atomic_helper_plane_reset(plane, &state->state); +} + +static const struct drm_plane_funcs rcar_du_vsp_plane_funcs =3D { + .update_plane =3D drm_atomic_helper_update_plane, + .disable_plane =3D drm_atomic_helper_disable_plane, + .reset =3D rcar_du_vsp_plane_reset, + .destroy =3D drm_plane_cleanup, + .atomic_duplicate_state =3D rcar_du_vsp_plane_atomic_duplicate_state, + .atomic_destroy_state =3D rcar_du_vsp_plane_atomic_destroy_state, +}; + +static void rcar_du_vsp_cleanup(struct drm_device *dev, void *res) +{ + struct rcar_du_vsp *vsp =3D res; + unsigned int i; + + for (i =3D 0; i < vsp->num_planes; ++i) { + struct rcar_du_vsp_plane *plane =3D &vsp->planes[i]; + + drm_plane_cleanup(&plane->plane); + } + + kfree(vsp->planes); + + put_device(vsp->vsp); +} + +int rcar_du_lib_vsp_init(struct rcar_du_vsp *vsp, struct device_node *np, + unsigned int crtcs, + const struct drm_plane_helper_funcs *rcar_du_vsp_plane_helper_funcs) +{ + struct rcar_du_device *rcdu =3D vsp->dev; + struct platform_device *pdev; + unsigned int num_crtcs =3D hweight32(crtcs); + unsigned int num_planes; + unsigned int i; + int ret; + + /* Find the VSP device and initialize it. */ + pdev =3D of_find_device_by_node(np); + if (!pdev) + return -ENXIO; + + vsp->vsp =3D &pdev->dev; + + ret =3D drmm_add_action_or_reset(&rcdu->ddev, rcar_du_vsp_cleanup, vsp); + if (ret < 0) + return ret; + + ret =3D vsp1_du_init(vsp->vsp); + if (ret < 0) + return ret; + + num_planes =3D rcdu->info->num_rpf; + + vsp->planes =3D kcalloc(num_planes, sizeof(*vsp->planes), GFP_KERNEL); + if (!vsp->planes) + return -ENOMEM; + + for (i =3D 0; i < num_planes; ++i) { + enum drm_plane_type type =3D i < num_crtcs + ? DRM_PLANE_TYPE_PRIMARY + : DRM_PLANE_TYPE_OVERLAY; + struct rcar_du_vsp_plane *plane =3D &vsp->planes[i]; + unsigned int num_formats; + const u32 *formats; + + if (rcdu->info->gen < 4) { + num_formats =3D ARRAY_SIZE(rcar_du_vsp_formats); + formats =3D rcar_du_vsp_formats; + } else { + num_formats =3D ARRAY_SIZE(rcar_du_vsp_formats_gen4); + formats =3D rcar_du_vsp_formats_gen4; + } + + plane->vsp =3D vsp; + plane->index =3D i; + + ret =3D drm_universal_plane_init(&rcdu->ddev, &plane->plane, + crtcs, &rcar_du_vsp_plane_funcs, + formats, num_formats, + NULL, type, NULL); + if (ret < 0) + return ret; + + drm_plane_helper_add(&plane->plane, + rcar_du_vsp_plane_helper_funcs); + + drm_plane_create_alpha_property(&plane->plane); + drm_plane_create_zpos_property(&plane->plane, i, 0, + num_planes - 1); + + drm_plane_create_blend_mode_property(&plane->plane, + BIT(DRM_MODE_BLEND_PIXEL_NONE) | + BIT(DRM_MODE_BLEND_PREMULTI) | + BIT(DRM_MODE_BLEND_COVERAGE)); + + vsp->num_planes++; + } + + return 0; +} diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h b/drivers/gpu/drm/rc= ar-du/rcar_du_vsp_lib.h index d59182b2630f..2ced23132db2 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h @@ -22,6 +22,9 @@ int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct dr= m_framebuffer *fb, struct sg_table sg_tables[3]); void rcar_du_vsp_unmap_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer = *fb, struct sg_table sg_tables[3]); +int rcar_du_lib_vsp_init(struct rcar_du_vsp *vsp, struct device_node *np, + unsigned int crtcs, + const struct drm_plane_helper_funcs *rcar_du_vsp_plane_helper_funcs); #else static inline void rcar_du_vsp_disable(struct rcar_du_crtc *crtc) { }; static inline void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc) { }; @@ -38,6 +41,14 @@ static inline void rcar_du_vsp_unmap_fb(struct rcar_du_v= sp *vsp, struct sg_table sg_tables[3]) { } + +static inline int +rcar_du_lib_vsp_init(struct rcar_du_vsp *vsp, struct device_node *np, + unsigned int crtcs, + const struct drm_plane_helper_funcs *rcar_du_vsp_plane_helper_funcs) +{ + return -ENXIO; +} #endif =20 #endif /* __RCAR_DU_VSP_LIB_H__ */ --=20 2.25.1 From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CDC8C77B70 for ; Tue, 11 Apr 2023 11:44:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230038AbjDKLoT (ORCPT ); Tue, 11 Apr 2023 07:44:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229716AbjDKLoN (ORCPT ); Tue, 11 Apr 2023 07:44:13 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 31D7A46B9; Tue, 11 Apr 2023 04:43:47 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="159045224" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 11 Apr 2023 20:43:32 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 8262A4000A93; Tue, 11 Apr 2023 20:43:28 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 10/17] drm: rcar-du: Move rcar_du_vsp_plane_prepare_fb() Date: Tue, 11 Apr 2023 12:42:28 +0100 Message-Id: <20230411114235.366042-11-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move rcar_du_vsp_plane_prepare_fb() to RCar DU vsp lib so that both RCar and RZ/G2L DU vsp drivers can share this function. Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v1->v6: * Rebased on drm-misc-next and DU-next. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/rcar_du_vsp.c | 21 --------------------- drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c | 21 +++++++++++++++++++++ drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h | 8 ++++++++ 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c b/drivers/gpu/drm/rcar-d= u/rcar_du_vsp.c index e54a605a1bdf..3abc5031112e 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp.c @@ -139,27 +139,6 @@ static void rcar_du_vsp_plane_setup(struct rcar_du_vsp= _plane *plane) plane->index, &cfg); } =20 -static int rcar_du_vsp_plane_prepare_fb(struct drm_plane *plane, - struct drm_plane_state *state) -{ - struct rcar_du_vsp_plane_state *rstate =3D to_rcar_vsp_plane_state(state); - struct rcar_du_vsp *vsp =3D to_rcar_vsp_plane(plane)->vsp; - int ret; - - /* - * There's no need to prepare (and unprepare) the framebuffer when the - * plane is not visible, as it will not be displayed. - */ - if (!state->visible) - return 0; - - ret =3D rcar_du_vsp_map_fb(vsp, state->fb, rstate->sg_tables); - if (ret < 0) - return ret; - - return drm_gem_plane_helper_prepare_fb(plane, state); -} - static void rcar_du_vsp_plane_cleanup_fb(struct drm_plane *plane, struct drm_plane_state *state) { diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c b/drivers/gpu/drm/rc= ar-du/rcar_du_vsp_lib.c index f2d55695f6c1..91259d44efe9 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c @@ -177,6 +177,27 @@ int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct= drm_framebuffer *fb, return ret; } =20 +int rcar_du_vsp_plane_prepare_fb(struct drm_plane *plane, + struct drm_plane_state *state) +{ + struct rcar_du_vsp_plane_state *rstate =3D to_rcar_vsp_plane_state(state); + struct rcar_du_vsp *vsp =3D to_rcar_vsp_plane(plane)->vsp; + int ret; + + /* + * There's no need to prepare (and unprepare) the framebuffer when the + * plane is not visible, as it will not be displayed. + */ + if (!state->visible) + return 0; + + ret =3D rcar_du_vsp_map_fb(vsp, state->fb, rstate->sg_tables); + if (ret < 0) + return ret; + + return drm_gem_plane_helper_prepare_fb(plane, state); +} + void rcar_du_vsp_unmap_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer = *fb, struct sg_table sg_tables[3]) { diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h b/drivers/gpu/drm/rc= ar-du/rcar_du_vsp_lib.h index 2ced23132db2..3d3a7735facd 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h @@ -25,6 +25,8 @@ void rcar_du_vsp_unmap_fb(struct rcar_du_vsp *vsp, struct= drm_framebuffer *fb, int rcar_du_lib_vsp_init(struct rcar_du_vsp *vsp, struct device_node *np, unsigned int crtcs, const struct drm_plane_helper_funcs *rcar_du_vsp_plane_helper_funcs); +int rcar_du_vsp_plane_prepare_fb(struct drm_plane *plane, + struct drm_plane_state *state); #else static inline void rcar_du_vsp_disable(struct rcar_du_crtc *crtc) { }; static inline void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc) { }; @@ -49,6 +51,12 @@ rcar_du_lib_vsp_init(struct rcar_du_vsp *vsp, struct dev= ice_node *np, { return -ENXIO; } + +static inline int rcar_du_vsp_plane_prepare_fb(struct drm_plane *plane, + struct drm_plane_state *state) +{ + return -ENXIO; +} #endif =20 #endif /* __RCAR_DU_VSP_LIB_H__ */ --=20 2.25.1 From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DDACC77B74 for ; Tue, 11 Apr 2023 11:44:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230086AbjDKLoi (ORCPT ); Tue, 11 Apr 2023 07:44:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230087AbjDKLoc (ORCPT ); Tue, 11 Apr 2023 07:44:32 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EA35749FA; Tue, 11 Apr 2023 04:44:03 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="159045229" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 11 Apr 2023 20:43:37 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 7D697400195D; Tue, 11 Apr 2023 20:43:33 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 11/17] drm: rcar-du: Move rcar_du_vsp_plane_cleanup_fb() Date: Tue, 11 Apr 2023 12:42:29 +0100 Message-Id: <20230411114235.366042-12-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move rcar_du_vsp_plane_cleanup_fb() to RCar DU vsp lib so that it can be shared by both RCar and RZ/G2L DU vsp drivers. Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v1->v6: * Rebased on drm-misc-next and DU-next. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/rcar_du_vsp.c | 12 ------------ drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c | 12 ++++++++++++ drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h | 7 +++++++ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c b/drivers/gpu/drm/rcar-d= u/rcar_du_vsp.c index 3abc5031112e..d785654e4aa3 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp.c @@ -139,18 +139,6 @@ static void rcar_du_vsp_plane_setup(struct rcar_du_vsp= _plane *plane) plane->index, &cfg); } =20 -static void rcar_du_vsp_plane_cleanup_fb(struct drm_plane *plane, - struct drm_plane_state *state) -{ - struct rcar_du_vsp_plane_state *rstate =3D to_rcar_vsp_plane_state(state); - struct rcar_du_vsp *vsp =3D to_rcar_vsp_plane(plane)->vsp; - - if (!state->visible) - return; - - rcar_du_vsp_unmap_fb(vsp, state->fb, rstate->sg_tables); -} - static int rcar_du_vsp_plane_atomic_check(struct drm_plane *plane, struct drm_atomic_state *state) { diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c b/drivers/gpu/drm/rc= ar-du/rcar_du_vsp_lib.c index 91259d44efe9..9240c56ec40f 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c @@ -211,6 +211,18 @@ void rcar_du_vsp_unmap_fb(struct rcar_du_vsp *vsp, str= uct drm_framebuffer *fb, } } =20 +void rcar_du_vsp_plane_cleanup_fb(struct drm_plane *plane, + struct drm_plane_state *state) +{ + struct rcar_du_vsp_plane_state *rstate =3D to_rcar_vsp_plane_state(state); + struct rcar_du_vsp *vsp =3D to_rcar_vsp_plane(plane)->vsp; + + if (!state->visible) + return; + + rcar_du_vsp_unmap_fb(vsp, state->fb, rstate->sg_tables); +} + static struct drm_plane_state * rcar_du_vsp_plane_atomic_duplicate_state(struct drm_plane *plane) { diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h b/drivers/gpu/drm/rc= ar-du/rcar_du_vsp_lib.h index 3d3a7735facd..efd2bb36c88b 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h @@ -27,6 +27,8 @@ int rcar_du_lib_vsp_init(struct rcar_du_vsp *vsp, struct = device_node *np, const struct drm_plane_helper_funcs *rcar_du_vsp_plane_helper_funcs); int rcar_du_vsp_plane_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state); +void rcar_du_vsp_plane_cleanup_fb(struct drm_plane *plane, + struct drm_plane_state *state); #else static inline void rcar_du_vsp_disable(struct rcar_du_crtc *crtc) { }; static inline void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc) { }; @@ -57,6 +59,11 @@ static inline int rcar_du_vsp_plane_prepare_fb(struct dr= m_plane *plane, { return -ENXIO; } + +static inline void rcar_du_vsp_plane_cleanup_fb(struct drm_plane *plane, + struct drm_plane_state *state) +{ +} #endif =20 #endif /* __RCAR_DU_VSP_LIB_H__ */ --=20 2.25.1 From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38A09C77B6F for ; Tue, 11 Apr 2023 11:44:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230097AbjDKLom (ORCPT ); Tue, 11 Apr 2023 07:44:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230079AbjDKLog (ORCPT ); Tue, 11 Apr 2023 07:44:36 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B16BF422D; Tue, 11 Apr 2023 04:44:13 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="159045238" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 11 Apr 2023 20:43:42 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 7FC15400195D; Tue, 11 Apr 2023 20:43:38 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 12/17] drm: rcar-du: Move rcar_du_vsp_plane_atomic_update() Date: Tue, 11 Apr 2023 12:42:30 +0100 Message-Id: <20230411114235.366042-13-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move rcar_du_vsp_plane_atomic_update() to RCar DU vsp lib so that both RCar and RZ/G2L DU vsp drivers can share this function. Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v1->v6: * Rebased on drm-misc-next and DU-next. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/rcar_du_vsp.c | 70 ---------------------- drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c | 71 +++++++++++++++++++++++ drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h | 7 +++ 3 files changed, 78 insertions(+), 70 deletions(-) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c b/drivers/gpu/drm/rcar-d= u/rcar_du_vsp.c index d785654e4aa3..4d14de408de1 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp.c @@ -84,61 +84,6 @@ void rcar_du_vsp_enable(struct rcar_du_crtc *crtc) vsp1_du_setup_lif(crtc->vsp->vsp, crtc->vsp_pipe, &cfg); } =20 -static void rcar_du_vsp_plane_setup(struct rcar_du_vsp_plane *plane) -{ - struct rcar_du_vsp_plane_state *state =3D - to_rcar_vsp_plane_state(plane->plane.state); - struct rcar_du_crtc *crtc =3D to_rcar_crtc(state->state.crtc); - struct drm_framebuffer *fb =3D plane->plane.state->fb; - const struct rcar_du_format_info *format; - struct vsp1_du_atomic_config cfg =3D { - .pixelformat =3D 0, - .pitch =3D fb->pitches[0], - .alpha =3D state->state.alpha >> 8, - .zpos =3D state->state.zpos, - }; - u32 fourcc =3D state->format->fourcc; - unsigned int i; - - cfg.src.left =3D state->state.src.x1 >> 16; - cfg.src.top =3D state->state.src.y1 >> 16; - cfg.src.width =3D drm_rect_width(&state->state.src) >> 16; - cfg.src.height =3D drm_rect_height(&state->state.src) >> 16; - - cfg.dst.left =3D state->state.dst.x1; - cfg.dst.top =3D state->state.dst.y1; - cfg.dst.width =3D drm_rect_width(&state->state.dst); - cfg.dst.height =3D drm_rect_height(&state->state.dst); - - for (i =3D 0; i < state->format->planes; ++i) - cfg.mem[i] =3D sg_dma_address(state->sg_tables[i].sgl) - + fb->offsets[i]; - - if (state->state.pixel_blend_mode =3D=3D DRM_MODE_BLEND_PIXEL_NONE) { - switch (fourcc) { - case DRM_FORMAT_ARGB1555: - fourcc =3D DRM_FORMAT_XRGB1555; - break; - - case DRM_FORMAT_ARGB4444: - fourcc =3D DRM_FORMAT_XRGB4444; - break; - - case DRM_FORMAT_ARGB8888: - fourcc =3D DRM_FORMAT_XRGB8888; - break; - } - } - - format =3D rcar_du_format_info(fourcc); - cfg.pixelformat =3D format->v4l2; - - cfg.premult =3D state->state.pixel_blend_mode =3D=3D DRM_MODE_BLEND_PREMU= LTI; - - vsp1_du_atomic_update(plane->vsp->vsp, crtc->vsp_pipe, - plane->index, &cfg); -} - static int rcar_du_vsp_plane_atomic_check(struct drm_plane *plane, struct drm_atomic_state *state) { @@ -150,21 +95,6 @@ static int rcar_du_vsp_plane_atomic_check(struct drm_pl= ane *plane, &rstate->format); } =20 -static void rcar_du_vsp_plane_atomic_update(struct drm_plane *plane, - struct drm_atomic_state *state) -{ - struct drm_plane_state *old_state =3D drm_atomic_get_old_plane_state(stat= e, plane); - struct drm_plane_state *new_state =3D drm_atomic_get_new_plane_state(stat= e, plane); - struct rcar_du_vsp_plane *rplane =3D to_rcar_vsp_plane(plane); - struct rcar_du_crtc *crtc =3D to_rcar_crtc(old_state->crtc); - - if (new_state->visible) - rcar_du_vsp_plane_setup(rplane); - else if (old_state->crtc) - vsp1_du_atomic_update(rplane->vsp->vsp, crtc->vsp_pipe, - rplane->index, NULL); -} - static const struct drm_plane_helper_funcs rcar_du_vsp_plane_helper_funcs = =3D { .prepare_fb =3D rcar_du_vsp_plane_prepare_fb, .cleanup_fb =3D rcar_du_vsp_plane_cleanup_fb, diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c b/drivers/gpu/drm/rc= ar-du/rcar_du_vsp_lib.c index 9240c56ec40f..a8ddf06686cd 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.c @@ -25,6 +25,7 @@ #include =20 #include "rcar_du_drv.h" +#include "rcar_du_kms.h" #include "rcar_du_writeback.h" =20 void rcar_du_vsp_disable(struct rcar_du_crtc *crtc) @@ -115,6 +116,61 @@ static const u32 rcar_du_vsp_formats_gen4[] =3D { DRM_FORMAT_Y212, }; =20 +static void rcar_du_vsp_plane_setup(struct rcar_du_vsp_plane *plane) +{ + struct rcar_du_vsp_plane_state *state =3D + to_rcar_vsp_plane_state(plane->plane.state); + struct rcar_du_crtc *crtc =3D to_rcar_crtc(state->state.crtc); + struct drm_framebuffer *fb =3D plane->plane.state->fb; + const struct rcar_du_format_info *format; + struct vsp1_du_atomic_config cfg =3D { + .pixelformat =3D 0, + .pitch =3D fb->pitches[0], + .alpha =3D state->state.alpha >> 8, + .zpos =3D state->state.zpos, + }; + u32 fourcc =3D state->format->fourcc; + unsigned int i; + + cfg.src.left =3D state->state.src.x1 >> 16; + cfg.src.top =3D state->state.src.y1 >> 16; + cfg.src.width =3D drm_rect_width(&state->state.src) >> 16; + cfg.src.height =3D drm_rect_height(&state->state.src) >> 16; + + cfg.dst.left =3D state->state.dst.x1; + cfg.dst.top =3D state->state.dst.y1; + cfg.dst.width =3D drm_rect_width(&state->state.dst); + cfg.dst.height =3D drm_rect_height(&state->state.dst); + + for (i =3D 0; i < state->format->planes; ++i) + cfg.mem[i] =3D sg_dma_address(state->sg_tables[i].sgl) + + fb->offsets[i]; + + if (state->state.pixel_blend_mode =3D=3D DRM_MODE_BLEND_PIXEL_NONE) { + switch (fourcc) { + case DRM_FORMAT_ARGB1555: + fourcc =3D DRM_FORMAT_XRGB1555; + break; + + case DRM_FORMAT_ARGB4444: + fourcc =3D DRM_FORMAT_XRGB4444; + break; + + case DRM_FORMAT_ARGB8888: + fourcc =3D DRM_FORMAT_XRGB8888; + break; + } + } + + format =3D rcar_du_format_info(fourcc); + cfg.pixelformat =3D format->v4l2; + + cfg.premult =3D state->state.pixel_blend_mode =3D=3D DRM_MODE_BLEND_PREMU= LTI; + + vsp1_du_atomic_update(plane->vsp->vsp, crtc->vsp_pipe, + plane->index, &cfg); +} + int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb, struct sg_table sg_tables[3]) { @@ -223,6 +279,21 @@ void rcar_du_vsp_plane_cleanup_fb(struct drm_plane *pl= ane, rcar_du_vsp_unmap_fb(vsp, state->fb, rstate->sg_tables); } =20 +void rcar_du_vsp_plane_atomic_update(struct drm_plane *plane, + struct drm_atomic_state *state) +{ + struct drm_plane_state *old_state =3D drm_atomic_get_old_plane_state(stat= e, plane); + struct drm_plane_state *new_state =3D drm_atomic_get_new_plane_state(stat= e, plane); + struct rcar_du_vsp_plane *rplane =3D to_rcar_vsp_plane(plane); + struct rcar_du_crtc *crtc =3D to_rcar_crtc(old_state->crtc); + + if (new_state->visible) + rcar_du_vsp_plane_setup(rplane); + else if (old_state->crtc) + vsp1_du_atomic_update(rplane->vsp->vsp, crtc->vsp_pipe, + rplane->index, NULL); +} + static struct drm_plane_state * rcar_du_vsp_plane_atomic_duplicate_state(struct drm_plane *plane) { diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h b/drivers/gpu/drm/rc= ar-du/rcar_du_vsp_lib.h index efd2bb36c88b..4e1421e3c00f 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp_lib.h @@ -29,6 +29,8 @@ int rcar_du_vsp_plane_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state); void rcar_du_vsp_plane_cleanup_fb(struct drm_plane *plane, struct drm_plane_state *state); +void rcar_du_vsp_plane_atomic_update(struct drm_plane *plane, + struct drm_atomic_state *state); #else static inline void rcar_du_vsp_disable(struct rcar_du_crtc *crtc) { }; static inline void rcar_du_vsp_atomic_begin(struct rcar_du_crtc *crtc) { }; @@ -64,6 +66,11 @@ static inline void rcar_du_vsp_plane_cleanup_fb(struct d= rm_plane *plane, struct drm_plane_state *state) { } + +static inline void rcar_du_vsp_plane_atomic_update(struct drm_plane *plane, + struct drm_atomic_state *state) +{ +} #endif =20 #endif /* __RCAR_DU_VSP_LIB_H__ */ --=20 2.25.1 From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACF38C76196 for ; Tue, 11 Apr 2023 11:44:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229454AbjDKLoY (ORCPT ); Tue, 11 Apr 2023 07:44:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229696AbjDKLoR (ORCPT ); Tue, 11 Apr 2023 07:44:17 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8FA9840F9; Tue, 11 Apr 2023 04:43:50 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="155597382" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 11 Apr 2023 20:43:48 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 81244400195D; Tue, 11 Apr 2023 20:43:43 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 13/17] drm: rcar-du: Add rcar_du_lib_fb_create() Date: Tue, 11 Apr 2023 12:42:31 +0100 Message-Id: <20230411114235.366042-14-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move the common code from rcar_du_fb_create->rcar_du_lib_fb_create, so that rzg2l_du_fb_create() can reuse the common code. Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v1->v6: * Rebased on drm-misc-next and DU-next. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/rcar_du_kms.c | 64 +-------------------- drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c | 69 +++++++++++++++++++++++ drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h | 4 ++ 3 files changed, 74 insertions(+), 63 deletions(-) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.c b/drivers/gpu/drm/rcar-d= u/rcar_du_kms.c index ae969f640bb6..74845d8bad9d 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.c @@ -38,69 +38,7 @@ static struct drm_framebuffer * rcar_du_fb_create(struct drm_device *dev, struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd) { - struct rcar_du_device *rcdu =3D to_rcar_du_device(dev); - const struct rcar_du_format_info *format; - unsigned int chroma_pitch; - unsigned int max_pitch; - unsigned int align; - unsigned int i; - - format =3D rcar_du_format_info(mode_cmd->pixel_format); - if (format =3D=3D NULL) { - dev_dbg(dev->dev, "unsupported pixel format %p4cc\n", - &mode_cmd->pixel_format); - return ERR_PTR(-EINVAL); - } - - if (rcdu->info->gen < 3) { - /* - * On Gen2 the DU limits the pitch to 4095 pixels and requires - * buffers to be aligned to a 16 pixels boundary (or 128 bytes - * on some platforms). - */ - unsigned int bpp =3D format->planes =3D=3D 1 ? format->bpp / 8 : 1; - - max_pitch =3D 4095 * bpp; - - if (rcar_du_needs(rcdu, RCAR_DU_QUIRK_ALIGN_128B)) - align =3D 128; - else - align =3D 16 * bpp; - } else { - /* - * On Gen3 the memory interface is handled by the VSP that - * limits the pitch to 65535 bytes and has no alignment - * constraint. - */ - max_pitch =3D 65535; - align =3D 1; - } - - if (mode_cmd->pitches[0] & (align - 1) || - mode_cmd->pitches[0] > max_pitch) { - dev_dbg(dev->dev, "invalid pitch value %u\n", - mode_cmd->pitches[0]); - return ERR_PTR(-EINVAL); - } - - /* - * Calculate the chroma plane(s) pitch using the horizontal subsampling - * factor. For semi-planar formats, the U and V planes are combined, the - * pitch must thus be doubled. - */ - chroma_pitch =3D mode_cmd->pitches[0] / format->hsub; - if (format->planes =3D=3D 2) - chroma_pitch *=3D 2; - - for (i =3D 1; i < format->planes; ++i) { - if (mode_cmd->pitches[i] !=3D chroma_pitch) { - dev_dbg(dev->dev, - "luma and chroma pitches are not compatible\n"); - return ERR_PTR(-EINVAL); - } - } - - return drm_gem_fb_create(dev, file_priv, mode_cmd); + return rcar_du_lib_fb_create(dev, file_priv, mode_cmd); } =20 /* -----------------------------------------------------------------------= ------ diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c b/drivers/gpu/drm/rc= ar-du/rcar_du_kms_lib.c index 37809d06df89..f092d8e4aa16 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c @@ -407,3 +407,72 @@ int rcar_du_dumb_create(struct drm_file *file, struct = drm_device *dev, =20 return drm_gem_dma_dumb_create_internal(file, dev, args); } + +struct drm_framebuffer * +rcar_du_lib_fb_create(struct drm_device *dev, struct drm_file *file_priv, + const struct drm_mode_fb_cmd2 *mode_cmd) +{ + struct rcar_du_device *rcdu =3D to_rcar_du_device(dev); + const struct rcar_du_format_info *format; + unsigned int chroma_pitch; + unsigned int max_pitch; + unsigned int align; + unsigned int i; + + format =3D rcar_du_format_info(mode_cmd->pixel_format); + if (format =3D=3D NULL) { + dev_dbg(dev->dev, "unsupported pixel format %p4cc\n", + &mode_cmd->pixel_format); + return ERR_PTR(-EINVAL); + } + + if (rcdu->info->gen < 3) { + /* + * On Gen2 the DU limits the pitch to 4095 pixels and requires + * buffers to be aligned to a 16 pixels boundary (or 128 bytes + * on some platforms). + */ + unsigned int bpp =3D format->planes =3D=3D 1 ? format->bpp / 8 : 1; + + max_pitch =3D 4095 * bpp; + + if (rcar_du_needs(rcdu, RCAR_DU_QUIRK_ALIGN_128B)) + align =3D 128; + else + align =3D 16 * bpp; + } else { + /* + * On Gen3 the memory interface is handled by the VSP that + * limits the pitch to 65535 bytes and has no alignment + * constraint. + */ + max_pitch =3D 65535; + align =3D 1; + } + + if (mode_cmd->pitches[0] & (align - 1) || + mode_cmd->pitches[0] > max_pitch) { + dev_dbg(dev->dev, "invalid pitch value %u\n", + mode_cmd->pitches[0]); + return ERR_PTR(-EINVAL); + } + + /* + * Calculate the chroma plane(s) pitch using the horizontal subsampling + * factor. For semi-planar formats, the U and V planes are combined, the + * pitch must thus be doubled. + */ + chroma_pitch =3D mode_cmd->pitches[0] / format->hsub; + if (format->planes =3D=3D 2) + chroma_pitch *=3D 2; + + for (i =3D 1; i < format->planes; ++i) { + if (mode_cmd->pitches[i] !=3D chroma_pitch) { + dev_dbg(dev->dev, + "luma and chroma pitches are not compatible\n"); + return ERR_PTR(-EINVAL); + } + } + + return drm_gem_fb_create(dev, file_priv, mode_cmd); +} diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h b/drivers/gpu/drm/rc= ar-du/rcar_du_kms_lib.h index 2556966024f8..f264e0415d53 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h @@ -38,4 +38,8 @@ struct drm_gem_object *rcar_du_gem_prime_import_sg_table(= struct drm_device *dev, struct dma_buf_attachment *attach, struct sg_table *sgt); =20 +struct drm_framebuffer * +rcar_du_lib_fb_create(struct drm_device *dev, struct drm_file *file_priv, + const struct drm_mode_fb_cmd2 *mode_cmd); + #endif /* __RCAR_DU_KMS_LIB_H__ */ --=20 2.25.1 From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DE9FC76196 for ; Tue, 11 Apr 2023 11:45:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230129AbjDKLpB (ORCPT ); Tue, 11 Apr 2023 07:45:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230107AbjDKLo4 (ORCPT ); Tue, 11 Apr 2023 07:44:56 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 89BF549CF; Tue, 11 Apr 2023 04:44:35 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="159045249" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 11 Apr 2023 20:43:53 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 936CA4000A93; Tue, 11 Apr 2023 20:43:48 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 14/17] drm: rcar-du: Add rcar_du_lib_mode_cfg_helper_get() Date: Tue, 11 Apr 2023 12:42:32 +0100 Message-Id: <20230411114235.366042-15-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add rcar_du_lib_mode_cfg_helper_get() in RCar DU kms lib to get the pointer to rcar_du_mode_config_helper, so that both rcar_du_atomic_ commit_tail() and rcar_du_mode_config_helper can be reused by rcar_du_modeset_init() and rzg2l_du_modeset_init(). Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v1->v6: * Rebased on drm-misc-next and DU-next. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/rcar_du_kms.c | 46 +----------------- drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c | 59 +++++++++++++++++++++++ drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h | 3 ++ 3 files changed, 63 insertions(+), 45 deletions(-) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.c b/drivers/gpu/drm/rcar-d= u/rcar_du_kms.c index 74845d8bad9d..b0b40b1cc37d 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.c @@ -7,9 +7,7 @@ * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) */ =20 -#include #include -#include #include #include #include @@ -61,52 +59,10 @@ static int rcar_du_atomic_check(struct drm_device *dev, return rcar_du_atomic_check_planes(dev, state); } =20 -static void rcar_du_atomic_commit_tail(struct drm_atomic_state *old_state) -{ - struct drm_device *dev =3D old_state->dev; - struct rcar_du_device *rcdu =3D to_rcar_du_device(dev); - struct drm_crtc_state *crtc_state; - struct drm_crtc *crtc; - unsigned int i; - - /* - * Store RGB routing to DPAD0 and DPAD1, the hardware will be configured - * when starting the CRTCs. - */ - rcdu->dpad1_source =3D -1; - - for_each_new_crtc_in_state(old_state, crtc, crtc_state, i) { - struct rcar_du_crtc_state *rcrtc_state =3D - to_rcar_crtc_state(crtc_state); - struct rcar_du_crtc *rcrtc =3D to_rcar_crtc(crtc); - - if (rcrtc_state->outputs & BIT(RCAR_DU_OUTPUT_DPAD0)) - rcdu->dpad0_source =3D rcrtc->index; - - if (rcrtc_state->outputs & BIT(RCAR_DU_OUTPUT_DPAD1)) - rcdu->dpad1_source =3D rcrtc->index; - } - - /* Apply the atomic update. */ - drm_atomic_helper_commit_modeset_disables(dev, old_state); - drm_atomic_helper_commit_planes(dev, old_state, - DRM_PLANE_COMMIT_ACTIVE_ONLY); - drm_atomic_helper_commit_modeset_enables(dev, old_state); - - drm_atomic_helper_commit_hw_done(old_state); - drm_atomic_helper_wait_for_flip_done(dev, old_state); - - drm_atomic_helper_cleanup_planes(dev, old_state); -} - /* -----------------------------------------------------------------------= ------ * Initialization */ =20 -static const struct drm_mode_config_helper_funcs rcar_du_mode_config_helpe= r =3D { - .atomic_commit_tail =3D rcar_du_atomic_commit_tail, -}; - static const struct drm_mode_config_funcs rcar_du_mode_config_funcs =3D { .fb_create =3D rcar_du_fb_create, .atomic_check =3D rcar_du_atomic_check, @@ -412,7 +368,7 @@ int rcar_du_modeset_init(struct rcar_du_device *rcdu) dev->mode_config.min_height =3D 0; dev->mode_config.normalize_zpos =3D true; dev->mode_config.funcs =3D &rcar_du_mode_config_funcs; - dev->mode_config.helper_private =3D &rcar_du_mode_config_helper; + dev->mode_config.helper_private =3D rcar_du_lib_mode_cfg_helper_get(); =20 if (rcdu->info->gen < 3) { dev->mode_config.max_width =3D 4095; diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c b/drivers/gpu/drm/rc= ar-du/rcar_du_kms_lib.c index f092d8e4aa16..13d033009c9f 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c @@ -7,6 +7,9 @@ * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) */ =20 +#include +#include +#include #include #include #include @@ -476,3 +479,59 @@ rcar_du_lib_fb_create(struct drm_device *dev, struct d= rm_file *file_priv, =20 return drm_gem_fb_create(dev, file_priv, mode_cmd); } + +/* -----------------------------------------------------------------------= ------ + * Atomic Check and Update + */ + +static void rcar_du_atomic_commit_tail(struct drm_atomic_state *old_state) +{ + struct drm_device *dev =3D old_state->dev; + struct rcar_du_device *rcdu =3D to_rcar_du_device(dev); + struct drm_crtc_state *crtc_state; + struct drm_crtc *crtc; + unsigned int i; + + /* + * Store RGB routing to DPAD0 and DPAD1, the hardware will be configured + * when starting the CRTCs. + */ + rcdu->dpad1_source =3D -1; + + for_each_new_crtc_in_state(old_state, crtc, crtc_state, i) { + struct rcar_du_crtc_state *rcrtc_state =3D + to_rcar_crtc_state(crtc_state); + struct rcar_du_crtc *rcrtc =3D to_rcar_crtc(crtc); + + if (rcrtc_state->outputs & BIT(RCAR_DU_OUTPUT_DPAD0)) + rcdu->dpad0_source =3D rcrtc->index; + + if (rcrtc_state->outputs & BIT(RCAR_DU_OUTPUT_DPAD1)) + rcdu->dpad1_source =3D rcrtc->index; + } + + /* Apply the atomic update. */ + drm_atomic_helper_commit_modeset_disables(dev, old_state); + drm_atomic_helper_commit_planes(dev, old_state, + DRM_PLANE_COMMIT_ACTIVE_ONLY); + drm_atomic_helper_commit_modeset_enables(dev, old_state); + + drm_atomic_helper_commit_hw_done(old_state); + drm_atomic_helper_wait_for_flip_done(dev, old_state); + + drm_atomic_helper_cleanup_planes(dev, old_state); +} + +/* -----------------------------------------------------------------------= ------ + * Initialization + */ + +static const struct drm_mode_config_helper_funcs rcar_du_mode_config_helpe= r =3D { + .atomic_commit_tail =3D rcar_du_atomic_commit_tail, +}; + +const struct drm_mode_config_helper_funcs * +rcar_du_lib_mode_cfg_helper_get(void) +{ + return &rcar_du_mode_config_helper; +} diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h b/drivers/gpu/drm/rc= ar-du/rcar_du_kms_lib.h index f264e0415d53..be36b98b2d5d 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h @@ -42,4 +42,7 @@ struct drm_framebuffer * rcar_du_lib_fb_create(struct drm_device *dev, struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd); =20 +const struct drm_mode_config_helper_funcs * +rcar_du_lib_mode_cfg_helper_get(void); + #endif /* __RCAR_DU_KMS_LIB_H__ */ --=20 2.25.1 From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A910DC76196 for ; Tue, 11 Apr 2023 11:44:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230099AbjDKLop (ORCPT ); Tue, 11 Apr 2023 07:44:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229676AbjDKLoj (ORCPT ); Tue, 11 Apr 2023 07:44:39 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 46E9B421E; Tue, 11 Apr 2023 04:44:17 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="155597402" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 11 Apr 2023 20:43:58 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id CDE394000A93; Tue, 11 Apr 2023 20:43:53 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 15/17] drm: rcar-du: Move rcar_du_encoders_init() Date: Tue, 11 Apr 2023 12:42:33 +0100 Message-Id: <20230411114235.366042-16-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" RZ/G2L supports only DSI and DPI. Add rcar_du_encoders_init() to handle the pointer to du_output_name(), so that we can share du_encoders_init() between RCar and RZ/G2L kms drivers. Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v1->v6: * Rebased on drm-misc-next and DU-next. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/rcar_du_kms.c | 92 +------------------ drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c | 102 ++++++++++++++++++++++ drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h | 6 ++ 3 files changed, 110 insertions(+), 90 deletions(-) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.c b/drivers/gpu/drm/rcar-d= u/rcar_du_kms.c index b0b40b1cc37d..94f1602ea707 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.c @@ -69,95 +69,6 @@ static const struct drm_mode_config_funcs rcar_du_mode_c= onfig_funcs =3D { .atomic_commit =3D drm_atomic_helper_commit, }; =20 -static int rcar_du_encoders_init_one(struct rcar_du_device *rcdu, - enum rcar_du_output output, - struct of_endpoint *ep) -{ - struct device_node *entity; - int ret; - - /* Locate the connected entity and initialize the encoder. */ - entity =3D of_graph_get_remote_port_parent(ep->local_node); - if (!entity) { - dev_dbg(rcdu->dev, "unconnected endpoint %pOF, skipping\n", - ep->local_node); - return -ENODEV; - } - - if (!of_device_is_available(entity)) { - dev_dbg(rcdu->dev, - "connected entity %pOF is disabled, skipping\n", - entity); - of_node_put(entity); - return -ENODEV; - } - - ret =3D rcar_du_encoder_init(rcdu, output, entity); - if (ret && ret !=3D -EPROBE_DEFER && ret !=3D -ENOLINK) - dev_warn(rcdu->dev, - "failed to initialize encoder %pOF on output %s (%d), skipping\n", - entity, rcar_du_output_name(output), ret); - - of_node_put(entity); - - return ret; -} - -static int rcar_du_encoders_init(struct rcar_du_device *rcdu) -{ - struct device_node *np =3D rcdu->dev->of_node; - struct device_node *ep_node; - unsigned int num_encoders =3D 0; - - /* - * Iterate over the endpoints and create one encoder for each output - * pipeline. - */ - for_each_endpoint_of_node(np, ep_node) { - enum rcar_du_output output; - struct of_endpoint ep; - unsigned int i; - int ret; - - ret =3D of_graph_parse_endpoint(ep_node, &ep); - if (ret < 0) { - of_node_put(ep_node); - return ret; - } - - /* Find the output route corresponding to the port number. */ - for (i =3D 0; i < RCAR_DU_OUTPUT_MAX; ++i) { - if (rcdu->info->routes[i].possible_crtcs && - rcdu->info->routes[i].port =3D=3D ep.port) { - output =3D i; - break; - } - } - - if (i =3D=3D RCAR_DU_OUTPUT_MAX) { - dev_warn(rcdu->dev, - "port %u references unexisting output, skipping\n", - ep.port); - continue; - } - - /* Process the output pipeline. */ - ret =3D rcar_du_encoders_init_one(rcdu, output, &ep); - if (ret < 0) { - if (ret =3D=3D -EPROBE_DEFER) { - of_node_put(ep_node); - return ret; - } - - continue; - } - - num_encoders++; - } - - return num_encoders; -} - static int rcar_du_properties_init(struct rcar_du_device *rcdu) { /* @@ -457,7 +368,8 @@ int rcar_du_modeset_init(struct rcar_du_device *rcdu) } =20 /* Initialize the encoders. */ - ret =3D rcar_du_encoders_init(rcdu); + ret =3D rcar_du_encoders_init(rcdu, rcar_du_output_name, + rcar_du_encoder_init); if (ret < 0) return ret; =20 diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c b/drivers/gpu/drm/rc= ar-du/rcar_du_kms_lib.c index 13d033009c9f..781e666a45a8 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c @@ -15,6 +15,8 @@ #include #include =20 +#include +#include #include =20 #include "rcar_du_drv.h" @@ -535,3 +537,103 @@ rcar_du_lib_mode_cfg_helper_get(void) { return &rcar_du_mode_config_helper; } + +static int +rcar_du_encoders_init_one(struct rcar_du_device *rcdu, + enum rcar_du_output output, + struct of_endpoint *ep, + const char *output_name, + int (*rcar_du_encoder_init_fn)(struct rcar_du_device *r, + enum rcar_du_output op, + struct device_node *d)) +{ + struct device_node *entity; + int ret; + + /* Locate the connected entity and initialize the encoder. */ + entity =3D of_graph_get_remote_port_parent(ep->local_node); + if (!entity) { + dev_dbg(rcdu->dev, "unconnected endpoint %pOF, skipping\n", + ep->local_node); + return -ENODEV; + } + + if (!of_device_is_available(entity)) { + dev_dbg(rcdu->dev, + "connected entity %pOF is disabled, skipping\n", + entity); + of_node_put(entity); + return -ENODEV; + } + + ret =3D rcar_du_encoder_init_fn(rcdu, output, entity); + if (ret && ret !=3D -EPROBE_DEFER && ret !=3D -ENOLINK) + dev_warn(rcdu->dev, + "failed to initialize encoder %pOF on output %s (%d), skipping\n", + entity, output_name, ret); + + of_node_put(entity); + + return ret; +} + +int rcar_du_encoders_init(struct rcar_du_device *rcdu, + const char* (*out_name)(enum rcar_du_output output), + int (*encoder_init_fn)(struct rcar_du_device *rcdu, + enum rcar_du_output output, + struct device_node *enc_node)) +{ + struct device_node *np =3D rcdu->dev->of_node; + struct device_node *ep_node; + unsigned int num_encoders =3D 0; + + /* + * Iterate over the endpoints and create one encoder for each output + * pipeline. + */ + for_each_endpoint_of_node(np, ep_node) { + enum rcar_du_output output; + struct of_endpoint ep; + unsigned int i; + int ret; + + ret =3D of_graph_parse_endpoint(ep_node, &ep); + if (ret < 0) { + of_node_put(ep_node); + return ret; + } + + /* Find the output route corresponding to the port number. */ + for (i =3D 0; i < RCAR_DU_OUTPUT_MAX; ++i) { + if (rcdu->info->routes[i].possible_crtcs && + rcdu->info->routes[i].port =3D=3D ep.port) { + output =3D i; + break; + } + } + + if (i =3D=3D RCAR_DU_OUTPUT_MAX) { + dev_warn(rcdu->dev, + "port %u references unexisting output, skipping\n", + ep.port); + continue; + } + + /* Process the output pipeline. */ + ret =3D rcar_du_encoders_init_one(rcdu, output, &ep, + out_name(output), + encoder_init_fn); + if (ret < 0) { + if (ret =3D=3D -EPROBE_DEFER) { + of_node_put(ep_node); + return ret; + } + + continue; + } + + num_encoders++; + } + + return num_encoders; +} diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h b/drivers/gpu/drm/rc= ar-du/rcar_du_kms_lib.h index be36b98b2d5d..ace973b80fe6 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h @@ -45,4 +45,10 @@ rcar_du_lib_fb_create(struct drm_device *dev, struct drm= _file *file_priv, const struct drm_mode_config_helper_funcs * rcar_du_lib_mode_cfg_helper_get(void); =20 +int rcar_du_encoders_init(struct rcar_du_device *rcdu, + const char* (*out_name)(enum rcar_du_output output), + int (*encoder_init_fn)(struct rcar_du_device *rcdu, + enum rcar_du_output output, + struct device_node *enc_node)); + #endif /* __RCAR_DU_KMS_LIB_H__ */ --=20 2.25.1 From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58BE0C77B6F for ; Tue, 11 Apr 2023 11:45:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229893AbjDKLpF (ORCPT ); Tue, 11 Apr 2023 07:45:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230123AbjDKLpB (ORCPT ); Tue, 11 Apr 2023 07:45:01 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 46E3146AB; Tue, 11 Apr 2023 04:44:39 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="155597425" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 11 Apr 2023 20:44:03 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id D7C51400195D; Tue, 11 Apr 2023 20:43:58 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 16/17] drm: rcar-du: Move rcar_du_properties_init() Date: Tue, 11 Apr 2023 12:42:34 +0100 Message-Id: <20230411114235.366042-17-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move rcar_du_properties_init() to RCar DU kms lib, so that it can be shared by both RCar and RZ/G2L kms drivers. Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v1->v6: * Rebased on drm-misc-next and DU-next. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/rcar_du_kms.c | 16 ---------------- drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c | 16 ++++++++++++++++ drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h | 2 ++ 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.c b/drivers/gpu/drm/rcar-d= u/rcar_du_kms.c index 94f1602ea707..01ffe36f9d44 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.c @@ -69,22 +69,6 @@ static const struct drm_mode_config_funcs rcar_du_mode_c= onfig_funcs =3D { .atomic_commit =3D drm_atomic_helper_commit, }; =20 -static int rcar_du_properties_init(struct rcar_du_device *rcdu) -{ - /* - * The color key is expressed as an RGB888 triplet stored in a 32-bit - * integer in XRGB8888 format. Bit 24 is used as a flag to disable (0) - * or enable source color keying (1). - */ - rcdu->props.colorkey =3D - drm_property_create_range(&rcdu->ddev, 0, "colorkey", - 0, 0x01ffffff); - if (rcdu->props.colorkey =3D=3D NULL) - return -ENOMEM; - - return 0; -} - static int rcar_du_vsps_init(struct rcar_du_device *rcdu) { const struct device_node *np =3D rcdu->dev->of_node; diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c b/drivers/gpu/drm/rc= ar-du/rcar_du_kms_lib.c index 781e666a45a8..438a56c550f2 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c @@ -637,3 +637,19 @@ int rcar_du_encoders_init(struct rcar_du_device *rcdu, =20 return num_encoders; } + +int rcar_du_properties_init(struct rcar_du_device *rcdu) +{ + /* + * The color key is expressed as an RGB888 triplet stored in a 32-bit + * integer in XRGB8888 format. Bit 24 is used as a flag to disable (0) + * or enable source color keying (1). + */ + rcdu->props.colorkey =3D + drm_property_create_range(&rcdu->ddev, 0, "colorkey", + 0, 0x01ffffff); + if (rcdu->props.colorkey =3D=3D NULL) + return -ENOMEM; + + return 0; +} diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h b/drivers/gpu/drm/rc= ar-du/rcar_du_kms_lib.h index ace973b80fe6..50e92a19d98c 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h @@ -51,4 +51,6 @@ int rcar_du_encoders_init(struct rcar_du_device *rcdu, enum rcar_du_output output, struct device_node *enc_node)); =20 +int rcar_du_properties_init(struct rcar_du_device *rcdu); + #endif /* __RCAR_DU_KMS_LIB_H__ */ --=20 2.25.1 From nobody Wed Feb 11 20:05:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA1CEC76196 for ; Tue, 11 Apr 2023 11:45:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230063AbjDKLpd (ORCPT ); Tue, 11 Apr 2023 07:45:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230123AbjDKLp2 (ORCPT ); Tue, 11 Apr 2023 07:45:28 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2D14546B1; Tue, 11 Apr 2023 04:45:04 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,336,1673881200"; d="scan'208";a="155597457" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 11 Apr 2023 20:44:08 +0900 Received: from localhost.localdomain (unknown [10.226.93.123]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id D27234008C6C; Tue, 11 Apr 2023 20:44:03 +0900 (JST) From: Biju Das To: David Airlie , Daniel Vetter , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski Cc: Biju Das , Laurent Pinchart , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 17/17] drm: rcar-du: Add rcar_du_lib_vsps_init() Date: Tue, 11 Apr 2023 12:42:35 +0100 Message-Id: <20230411114235.366042-18-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> References: <20230411114235.366042-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add rcar_du_lib_vsps_init() to RCar DU kms lib to handle both rcar_du_vsp_init() and rzg2l_du_vsp_init(). Signed-off-by: Biju Das --- v6->v7: * Rebased to drm-tip. v1->v6: * Rebased on drm-misc-next and DU-next. v1: * Created the lib suggested by Laurent. Ref: https://patchwork.kernel.org/project/linux-renesas-soc/patch/2022031613110= 0.30685-6-biju.das.jz@bp.renesas.com/ --- drivers/gpu/drm/rcar-du/rcar_du_kms.c | 88 +--------------------- drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c | 89 +++++++++++++++++++++++ drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h | 5 ++ 3 files changed, 95 insertions(+), 87 deletions(-) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.c b/drivers/gpu/drm/rcar-d= u/rcar_du_kms.c index 01ffe36f9d44..6f3352a6a264 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.c @@ -69,92 +69,6 @@ static const struct drm_mode_config_funcs rcar_du_mode_c= onfig_funcs =3D { .atomic_commit =3D drm_atomic_helper_commit, }; =20 -static int rcar_du_vsps_init(struct rcar_du_device *rcdu) -{ - const struct device_node *np =3D rcdu->dev->of_node; - const char *vsps_prop_name =3D "renesas,vsps"; - struct of_phandle_args args; - struct { - struct device_node *np; - unsigned int crtcs_mask; - } vsps[RCAR_DU_MAX_VSPS] =3D { { NULL, }, }; - unsigned int vsps_count =3D 0; - unsigned int cells; - unsigned int i; - int ret; - - /* - * First parse the DT vsps property to populate the list of VSPs. Each - * entry contains a pointer to the VSP DT node and a bitmask of the - * connected DU CRTCs. - */ - ret =3D of_property_count_u32_elems(np, vsps_prop_name); - if (ret < 0) { - /* Backward compatibility with old DTBs. */ - vsps_prop_name =3D "vsps"; - ret =3D of_property_count_u32_elems(np, vsps_prop_name); - } - cells =3D ret / rcdu->num_crtcs - 1; - if (cells > 1) - return -EINVAL; - - for (i =3D 0; i < rcdu->num_crtcs; ++i) { - unsigned int j; - - ret =3D of_parse_phandle_with_fixed_args(np, vsps_prop_name, - cells, i, &args); - if (ret < 0) - goto error; - - /* - * Add the VSP to the list or update the corresponding existing - * entry if the VSP has already been added. - */ - for (j =3D 0; j < vsps_count; ++j) { - if (vsps[j].np =3D=3D args.np) - break; - } - - if (j < vsps_count) - of_node_put(args.np); - else - vsps[vsps_count++].np =3D args.np; - - vsps[j].crtcs_mask |=3D BIT(i); - - /* - * Store the VSP pointer and pipe index in the CRTC. If the - * second cell of the 'renesas,vsps' specifier isn't present, - * default to 0 to remain compatible with older DT bindings. - */ - rcdu->crtcs[i].vsp =3D &rcdu->vsps[j]; - rcdu->crtcs[i].vsp_pipe =3D cells >=3D 1 ? args.args[0] : 0; - } - - /* - * Then initialize all the VSPs from the node pointers and CRTCs bitmask - * computed previously. - */ - for (i =3D 0; i < vsps_count; ++i) { - struct rcar_du_vsp *vsp =3D &rcdu->vsps[i]; - - vsp->index =3D i; - vsp->dev =3D rcdu; - - ret =3D rcar_du_vsp_init(vsp, vsps[i].np, vsps[i].crtcs_mask); - if (ret < 0) - goto error; - } - - return 0; - -error: - for (i =3D 0; i < ARRAY_SIZE(vsps); ++i) - of_node_put(vsps[i].np); - - return ret; -} - static int rcar_du_cmm_init(struct rcar_du_device *rcdu) { const struct device_node *np =3D rcdu->dev->of_node; @@ -326,7 +240,7 @@ int rcar_du_modeset_init(struct rcar_du_device *rcdu) =20 /* Initialize the compositors. */ if (rcar_du_has(rcdu, RCAR_DU_FEATURE_VSP1_SOURCE)) { - ret =3D rcar_du_vsps_init(rcdu); + ret =3D rcar_du_lib_vsps_init(rcdu, rcar_du_vsp_init); if (ret < 0) return ret; } diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c b/drivers/gpu/drm/rc= ar-du/rcar_du_kms_lib.c index 438a56c550f2..b9949dbd3c33 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c @@ -653,3 +653,92 @@ int rcar_du_properties_init(struct rcar_du_device *rcd= u) =20 return 0; } + +int rcar_du_lib_vsps_init(struct rcar_du_device *rcdu, + int (*rcar_du_vsp_init_fn)(struct rcar_du_vsp *vsp, + struct device_node *np, + unsigned int crtcs)) +{ + const struct device_node *np =3D rcdu->dev->of_node; + const char *vsps_prop_name =3D "renesas,vsps"; + struct of_phandle_args args; + struct { + struct device_node *np; + unsigned int crtcs_mask; + } vsps[RCAR_DU_MAX_VSPS] =3D { { NULL, }, }; + unsigned int vsps_count =3D 0; + unsigned int cells; + unsigned int i; + int ret; + + /* + * First parse the DT vsps property to populate the list of VSPs. Each + * entry contains a pointer to the VSP DT node and a bitmask of the + * connected DU CRTCs. + */ + ret =3D of_property_count_u32_elems(np, vsps_prop_name); + if (ret < 0) { + /* Backward compatibility with old DTBs. */ + vsps_prop_name =3D "vsps"; + ret =3D of_property_count_u32_elems(np, vsps_prop_name); + } + cells =3D ret / rcdu->num_crtcs - 1; + if (cells > 1) + return -EINVAL; + + for (i =3D 0; i < rcdu->num_crtcs; ++i) { + unsigned int j; + + ret =3D of_parse_phandle_with_fixed_args(np, vsps_prop_name, + cells, i, &args); + if (ret < 0) + goto error; + + /* + * Add the VSP to the list or update the corresponding existing + * entry if the VSP has already been added. + */ + for (j =3D 0; j < vsps_count; ++j) { + if (vsps[j].np =3D=3D args.np) + break; + } + + if (j < vsps_count) + of_node_put(args.np); + else + vsps[vsps_count++].np =3D args.np; + + vsps[j].crtcs_mask |=3D BIT(i); + + /* + * Store the VSP pointer and pipe index in the CRTC. If the + * second cell of the 'renesas,vsps' specifier isn't present, + * default to 0 to remain compatible with older DT bindings. + */ + rcdu->crtcs[i].vsp =3D &rcdu->vsps[j]; + rcdu->crtcs[i].vsp_pipe =3D cells >=3D 1 ? args.args[0] : 0; + } + + /* + * Then initialize all the VSPs from the node pointers and CRTCs bitmask + * computed previously. + */ + for (i =3D 0; i < vsps_count; ++i) { + struct rcar_du_vsp *vsp =3D &rcdu->vsps[i]; + + vsp->index =3D i; + vsp->dev =3D rcdu; + + ret =3D rcar_du_vsp_init_fn(vsp, vsps[i].np, vsps[i].crtcs_mask); + if (ret < 0) + goto error; + } + + return 0; + +error: + for (i =3D 0; i < ARRAY_SIZE(vsps); ++i) + of_node_put(vsps[i].np); + + return ret; +} diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h b/drivers/gpu/drm/rc= ar-du/rcar_du_kms_lib.h index 50e92a19d98c..81bb38eadbe0 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h @@ -53,4 +53,9 @@ int rcar_du_encoders_init(struct rcar_du_device *rcdu, =20 int rcar_du_properties_init(struct rcar_du_device *rcdu); =20 +int rcar_du_lib_vsps_init(struct rcar_du_device *rcdu, + int (*rcar_du_vsp_init_fn)(struct rcar_du_vsp *vsp, + struct device_node *np, + unsigned int crtcs)); + #endif /* __RCAR_DU_KMS_LIB_H__ */ --=20 2.25.1