Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2396291rdb; Mon, 11 Sep 2023 23:48:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQhBx9R0FtmKXDrc5GU690njSDQPqaF9PBJXZnWvxyDhhHua7FeK5iK9K6QjSUy4jI5nay X-Received: by 2002:a17:90a:5892:b0:26b:494f:ae5d with SMTP id j18-20020a17090a589200b0026b494fae5dmr2285903pji.1.1694501285969; Mon, 11 Sep 2023 23:48:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694501285; cv=none; d=google.com; s=arc-20160816; b=hCkuFnzYulTcCCfCC4JS7nWWqQtNQihQOeTpHknH525/om3E+J9QUCTVIL0SW01ksd cqdmSdp8MEdZWacL4g5chiQNVTlY1DcBd0aTvqXVFcye/mjL6jGVNYtDvrGWzS1YvTtk NOwdGoeaqo5UeGFLnBlTFMyGI3DMkdERBKRCivNGpl0MhXsKQLRxn8ncIwi1xbdQrkFp 3yjJlNwQ6WczzIBjntnKEV+YzjYqh05T7i/wDv3R8PxtGV3YkljLBgfxuAd4AsEuCbsR suYdJQeozVqCmd3pcvC1XPPbLFJmX36QBw91matCBxLFZKb35/HBwbQklECTtyPQhyZV k88A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=wpdO6w68X+9OaaGqE9Z6H+bkZkwfyqwYRdifB5OrQ68=; fh=awx1KO+/OOdlQzap7qesdDFClpqYtvzt4n20klBB50o=; b=T1KosyVB3wRH/onGBBe+87F9ma48XG26nVJN7HeBZqusCFPeRfOC+a3MVrvgGmF7Nl f6TwAjOR9nfx5nybs4PZisnDjI1ptZYLeRHVzRF3XVBjfoGf6W/5FwKgy9phibeZDHk3 PPV/LxtVwZWh7rbMZB/FJl5/iCDBFf3avN8wi6dp3uL6MdWpNOOHXZlguGSj6PY4as3x f4EQkozJ9DUxaeGu058Akcvi7JMNduaD09Od6MbhdDtTVzSwc2mxrZwfv8OAUNmH427f trA2TexmYhM3dA87Rxe30P+HK4i2atf16Yg+fGhuSzboxrmyH304EcH9amgYwZx0ixK0 Wwug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id ca12-20020a056a02068c00b00565354f7f7fsi7748748pgb.346.2023.09.11.23.48.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 23:48:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 11E628087273; Mon, 11 Sep 2023 23:48:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230294AbjILGrp (ORCPT + 99 others); Tue, 12 Sep 2023 02:47:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230327AbjILGrn (ORCPT ); Tue, 12 Sep 2023 02:47:43 -0400 Received: from soltyk.jannau.net (soltyk.jannau.net [144.76.91.90]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CCEA10C0 for ; Mon, 11 Sep 2023 23:47:39 -0700 (PDT) Received: by soltyk.jannau.net (Postfix, from userid 1000) id 39E73270487; Tue, 12 Sep 2023 08:47:38 +0200 (CEST) Date: Tue, 12 Sep 2023 08:47:38 +0200 From: Janne Grunau To: Thomas Zimmermann Cc: Javier Martinez Canillas , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, asahi@lists.linux.dev Subject: Re: [PATCH] drm/simpledrm: Add support for multiple "power-domains" Message-ID: References: <20230910-simpledrm-multiple-power-domains-v1-1-f8718aefc685@jannau.net> <3efb0304-df1a-4038-a716-a910b53c1445@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3efb0304-df1a-4038-a716-a910b53c1445@suse.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 11 Sep 2023 23:48:03 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email On 2023-09-11 14:26:10 +0200, Thomas Zimmermann wrote: > Hi > > Am 10.09.23 um 18:39 schrieb Janne Grunau via B4 Relay: > > From: Janne Grunau > > > > Multiple power domains need to be handled explicitly in each driver. The > > driver core can not handle it automatically since it is not aware of > > power sequencing requirements the hardware might have. This is not a > > problem for simpledrm since everything is expected to be powered on by > > the bootloader. simpledrm has just ensure it remains powered on during > > its lifetime. > > This is required on Apple silicon M2 and M2 Pro/Max/Ultra desktop > > systems. The HDMI output initialized by the bootloader requires keeping > > the display controller and a DP phy power domain on. > > > > Signed-off-by: Janne Grunau > > --- > > drivers/gpu/drm/tiny/simpledrm.c | 106 +++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 106 insertions(+) > > > > diff --git a/drivers/gpu/drm/tiny/simpledrm.c b/drivers/gpu/drm/tiny/simpledrm.c > > index ff86ba1ae1b8..efedede57d42 100644 > > --- a/drivers/gpu/drm/tiny/simpledrm.c > > +++ b/drivers/gpu/drm/tiny/simpledrm.c > > @@ -6,6 +6,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > @@ -227,6 +228,12 @@ struct simpledrm_device { > > unsigned int regulator_count; > > struct regulator **regulators; > > #endif > > + /* power-domains */ > > +#if defined CONFIG_OF && defined CONFIG_PM_GENERIC_DOMAINS > > + int pwr_dom_count; > > + struct device **pwr_dom_devs; > > + struct device_link **pwr_dom_links; > > +#endif > > /* simplefb settings */ > > struct drm_display_mode mode; > > @@ -468,6 +475,102 @@ static int simpledrm_device_init_regulators(struct simpledrm_device *sdev) > > } > > #endif > > +#if defined CONFIG_OF && defined CONFIG_PM_GENERIC_DOMAINS > > +/* > > + * Generic power domain handling code. > > + * > > + * Here we handle the power-domains properties of our "simple-framebuffer" > > + * dt node. This is only necessary if there is more than one power-domain. > > + * A single power-domains is handled automatically by the driver core. Multiple > > + * power-domains have to be handled by drivers since the driver core can't know > > + * the correct power sequencing. Power sequencing is not an issue for simpledrm > > + * since the bootloader has put the power domains already in the correct state. > > + * simpledrm has only to ensure they remain active for its lifetime. > > + * > > + * When the driver unloads, we detach from the power-domains. > > + * > > + * We only complain about errors here, no action is taken as the most likely > > + * error can only happen due to a mismatch between the bootloader which set > > + * up the "simple-framebuffer" dt node, and the PM domain providers in the > > + * device tree. Chances are that there are no adverse effects, and if there are, > > + * a clean teardown of the fb probe will not help us much either. So just > > + * complain and carry on, and hope that the user actually gets a working fb at > > + * the end of things. > > + */ > > +static void simpledrm_device_detach_genpd(void *res) > > +{ > > + int i; > > + struct simpledrm_device *sdev = /*(struct simpledrm_device *)*/res; > > + > > + > > + drm_err(&sdev->dev, "% power-domains count:%d\n", __func__, sdev->pwr_dom_count); > > If anything, drm_dbg() see my own reply, was never supposed to be there, removed locally > > > + if (sdev->pwr_dom_count <= 1) > > + return; > > + > > + for (i = sdev->pwr_dom_count - 1; i >= 0; i--) { > > + if (!sdev->pwr_dom_links[i]) > > + device_link_del(sdev->pwr_dom_links[i]); > > + if (!IS_ERR_OR_NULL(sdev->pwr_dom_devs[i])) > > + dev_pm_domain_detach(sdev->pwr_dom_devs[i], true); > > + } > > +} > > + > > +static int simpledrm_device_attach_genpd(struct simpledrm_device *sdev) > > +{ > > + struct device *dev = sdev->dev.dev; > > + int i; > > + > > + sdev->pwr_dom_count = of_count_phandle_with_args(dev->of_node, "power-domains", > > + "#power-domain-cells"); > > + /* > > + * Single power-domain devices are handled by driver core nothing to do > > + * here. The same for device nodes without "power-domains" property. > > + */ > > + if (sdev->pwr_dom_count <= 1) > > + return 0; > > + > > + sdev->pwr_dom_devs = devm_kcalloc(dev, sdev->pwr_dom_count, > > + sizeof(*sdev->pwr_dom_devs), > > + GFP_KERNEL); > > + if (!sdev->pwr_dom_devs) > > + return -ENOMEM; > > + > > + sdev->pwr_dom_links = devm_kcalloc(dev, sdev->pwr_dom_count, > > + sizeof(*sdev->pwr_dom_links), > > + GFP_KERNEL); > > + if (!sdev->pwr_dom_links) > > + return -ENOMEM; > > + > > + for (i = 0; i < sdev->pwr_dom_count; i++) { > > + sdev->pwr_dom_devs[i] = dev_pm_domain_attach_by_id(dev, i); > > + if (IS_ERR(sdev->pwr_dom_devs[i])) { > > + int ret = PTR_ERR(sdev->pwr_dom_devs[i]); > > + if (ret == -EPROBE_DEFER) { > > + simpledrm_device_detach_genpd(sdev); > > + return PTR_ERR(sdev->pwr_dom_devs[i]); > > + } > > + drm_err(&sdev->dev, > > + "pm_domain_attach_by_id(%u) failed: %d\n", i, ret); > > The driver's not really failing to initialize AFAICT. CAlling drm_warn() > might be more appropriate. copied from simpledrm_device_init_regulators() but I agree that drm_warn() is more appropiate. change locally for v2. > > + } > > + > > + sdev->pwr_dom_links[i] = device_link_add(dev, > > + sdev->pwr_dom_devs[i], > > + DL_FLAG_STATELESS | > > + DL_FLAG_PM_RUNTIME | > > + DL_FLAG_RPM_ACTIVE); > > + if (!sdev->pwr_dom_links[i]) > > + drm_err(&sdev->dev, "failed to link power-domain %u\n", i); > > Also drm_warn() ? changed Thanks, Janne