Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp331981pxv; Thu, 22 Jul 2021 00:51:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfTkeWNdMD2fo/J3sJbUpayC/e5GBnX7dmn+ZIy/uWFl30VH5H6swdtLsMiZ8MhSUU8Uwo X-Received: by 2002:a50:ff0a:: with SMTP id a10mr53177095edu.273.1626940294327; Thu, 22 Jul 2021 00:51:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626940294; cv=none; d=google.com; s=arc-20160816; b=Fh4F3bTwdXnRPwA5nuLrhjh/jGYYcQZf3tiuwxrq/RfhxPQ8N2rpnH1j2oRjsf2am7 CwvmJTbMpucMKrlBxNQDx64ZjfkvdG4W7QrhvrPmaPGksRSckThGQHCCr7CS/mGDaUue G4MLS6eqT9i2Bs/kqdKZxeSNAxXUvAk/AOD+r2sXnaEgfaK/ZNszDOz8tVGvw7p4Vj6A ebrrQWdlZSakz50SpiWwNtNllWtP2CcUXsoSfBXsQc/cVAQo3Dj4G4hUyHLAzB7AUWpp rg7bx9Be4KMS4cVPjnYK40Gwe+pZSs0h55whP8uD4+9GvwFn6PRPWtX0LGg9Z9doDGbZ pRVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KPQFSQf3nlrjEsJEPlZkN2daacpxsZVC+klKaSukPf8=; b=Ico+6+opdri8Ng/izOCUQncvF5B85dszi6I7RiWgppJyUsNbL/kl0X0a/Qo1kIm7yX 0ZWLiW4IWM/wPW3l/qDXExYli8NCfmd+XeHI3UY2R5Z5KtlBuACajc3NjZUOmITANnpA VWWbXQhXr0juVzEbN+hTOkk4Df9CE70l78NtNzNdnSc7CPdyG7MZM58meToyUyhkwyX3 QA9zwEpbar1TT1WeJk7e+NzM+D6NRIGtmT1/tbD2eS1wHDk5xtModgRVjGsKYRaJB1Hd AW7PlwokzP80wc8GwhlMMvMAreeY9jyo6eNxXPQTcL3+YZ5XFyBu+RbLfryvqaDhip79 SJEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="WF/xA/hh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a23si8600663edx.263.2021.07.22.00.51.10; Thu, 22 Jul 2021 00:51:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="WF/xA/hh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229642AbhGVHJL (ORCPT + 99 others); Thu, 22 Jul 2021 03:09:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230170AbhGVHJK (ORCPT ); Thu, 22 Jul 2021 03:09:10 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D80AEC061575 for ; Thu, 22 Jul 2021 00:49:44 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id l1so5602588edr.11 for ; Thu, 22 Jul 2021 00:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KPQFSQf3nlrjEsJEPlZkN2daacpxsZVC+klKaSukPf8=; b=WF/xA/hhluJ+pU9zw+7lBXxAB6tCYov6J3krRERm2arX0Nd7/KmM6oISsZYv6NV9J3 nRUM4If+T6AAOJ4LgS41DGdGb48ES0ToVKq17VaLwgF1EuOB/Zksl8uWM2+eQ2MtkY2h nvjR9R1HBUtJKhfcf4D4tIYz3I+Cl5QUYD2dY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KPQFSQf3nlrjEsJEPlZkN2daacpxsZVC+klKaSukPf8=; b=R0mPxF6BtRtRovUGkoV5GQhG+7RNqDxU+IqbRoDxTSHiPUAAWZS3auLbcmW9+MnAU4 kZqz6aobo/oS9o2GQjxrZWigXHYR/46DUy3JkBRPPuVLF0T+gpt5L+ZrSNKngJBAx9aB jbuEDYZBubgkd8YZRlyGVdvp4tPXoqNciO1dbOw7MZJ5rzcvwuYxIWEkfJEADcv1WJ2r BPenfkSx4T6yPckbdfeQ5CydSlqHrLua+9GjWIk21kveEexkev23cmBqNT+7NADhXNga kYxAVklpG8Ojt30uP4si+j7H/MyHKxhvPR6YufgpkF0Ns7WR4tpnC046QX5u1/XkiGmO +5CQ== X-Gm-Message-State: AOAM531nH5Ln/VojLoo87I7V64zG1bLgpM2L1kjKfIsy3OY+YJDnLhH7 6Agv9QR+YvHsG9x6oPbQHaqFY0+l/RZ62op6fA9Ebw== X-Received: by 2002:a05:6402:51c7:: with SMTP id r7mr54673740edd.150.1626940183480; Thu, 22 Jul 2021 00:49:43 -0700 (PDT) MIME-Version: 1.0 References: <20210720134525.563936-1-maxime@cerno.tech> <20210720134525.563936-3-maxime@cerno.tech> In-Reply-To: <20210720134525.563936-3-maxime@cerno.tech> From: Jagan Teki Date: Thu, 22 Jul 2021 13:19:32 +0530 Message-ID: Subject: Re: [PATCH 02/10] drm/bridge: Add a function to abstract away panels To: Maxime Ripard Cc: Robert Foss , Andrzej Hajda , Daniel Vetter , David Airlie , Sam Ravnborg , Maarten Lankhorst , Thomas Zimmermann , Neil Armstrong , Jonas Karlman , Jernej Skrabec , Thierry Reding , Laurent Pinchart , linux-kernel , dri-devel Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Maxime, On Tue, Jul 20, 2021 at 7:15 PM Maxime Ripard wrote: > > Display drivers so far need to have a lot of boilerplate to first > retrieve either the panel or bridge that they are connected to using > drm_of_find_panel_or_bridge(), and then either deal with each with ad-hoc > functions or create a drm panel bridge through drm_panel_bridge_add. Correct, but drm_of_find_panel_or_bridge is still required in some DSI drivers where the panel pointer required separately. > > In order to reduce the boilerplate and hopefully create a path of least > resistance towards using the DRM panel bridge layer, let's create the > function devm_drm_of_get_next to reduce that boilerplate. > > Signed-off-by: Maxime Ripard > --- > drivers/gpu/drm/drm_bridge.c | 62 +++++++++++++++++++++++++++++++++--- > drivers/gpu/drm/drm_of.c | 3 ++ > include/drm/drm_bridge.h | 2 ++ > 3 files changed, 63 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c > index 044acd07c153..aef8c9f4fb9f 100644 > --- a/drivers/gpu/drm/drm_bridge.c > +++ b/drivers/gpu/drm/drm_bridge.c > @@ -24,10 +24,12 @@ > #include > #include > #include > +#include > > #include > #include > #include > +#include > > #include "drm_crtc_internal.h" > > @@ -50,10 +52,8 @@ > * > * Display drivers are responsible for linking encoders with the first bridge > * in the chains. This is done by acquiring the appropriate bridge with > - * of_drm_find_bridge() or drm_of_find_panel_or_bridge(), or creating it for a > - * panel with drm_panel_bridge_add_typed() (or the managed version > - * devm_drm_panel_bridge_add_typed()). Once acquired, the bridge shall be > - * attached to the encoder with a call to drm_bridge_attach(). > + * drm_of_get_next(). Once acquired, the bridge shall be attached to the > + * encoder with a call to drm_bridge_attach(). > * > * Bridges are responsible for linking themselves with the next bridge in the > * chain, if any. This is done the same way as for encoders, with the call to > @@ -1223,6 +1223,60 @@ struct drm_bridge *of_drm_find_bridge(struct device_node *np) > return NULL; > } > EXPORT_SYMBOL(of_drm_find_bridge); > + > +/** > + * devm_drm_of_get_next - Return next bridge in the chain > + * @dev: device to tie the bridge lifetime to > + * @np: device tree node containing encoder output ports > + * @port: port in the device tree node > + * @endpoint: endpoint in the device tree node > + * > + * Given a DT node's port and endpoint number, finds the connected node > + * and returns the associated bridge if any, or creates and returns a > + * drm panel bridge instance if a panel is connected. > + * > + * Returns a pointer to the bridge if successful, or an error pointer > + * otherwise. > + */ > +struct drm_bridge *devm_drm_of_get_next(struct device *dev, > + struct device_node *np, > + unsigned int port, > + unsigned int endpoint) > +{ > + struct device_node *remote; > + struct drm_bridge *bridge; > + struct drm_panel *panel; > + > + /* > + * of_graph_get_remote_node() produces a noisy error message if port > + * node isn't found and the absence of the port is a legit case here, > + * so at first we silently check whether graph presents in the > + * device-tree node. > + */ > + if (!of_graph_is_present(np)) > + return ERR_PTR(-ENODEV); > + > + remote = of_graph_get_remote_node(np, port, endpoint); > + if (!remote) > + return ERR_PTR(-ENODEV); > + > + bridge = of_drm_find_bridge(remote); > + if (bridge) { > + of_node_put(remote); > + return bridge; > + } > + > + panel = of_drm_find_panel(remote); > + if (IS_ERR(panel)) { > + of_node_put(remote); > + return ERR_CAST(panel); > + } > + > + of_node_put(remote); > + > + return devm_drm_panel_bridge_add(dev, panel); > +} This is ideally similar to drm_of_find_panel_or_bridge followed by panel_bridge_add. Can we reuse drm_of_find_panel_or_bridge for now till it deprecated? Thanks, Jagan.