Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2709221rdb; Tue, 12 Sep 2023 09:42:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH8bee+U4K3xWnZ3Nw5xBZ55MUsn+pOUQPKP/iJ+ALT4yxrYW10v/Wq/gvRa12BEmaPW9o7 X-Received: by 2002:a05:6808:bd3:b0:3a8:8b74:fd59 with SMTP id o19-20020a0568080bd300b003a88b74fd59mr380357oik.0.1694536947835; Tue, 12 Sep 2023 09:42:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694536947; cv=none; d=google.com; s=arc-20160816; b=CFs8TJG7erGAOEfoadhfYq5e0fdY4QeL3UX/V49Iuf/nARph0pNaTT2fztm6AXKtkv aOs2IwYvBAj9gBE01GK0iVjnDb4d5abILOf9CnB3WJPsxTRJtVmbNtejSVTthjwyGkWf eDTsQuJT+cmgEUEfsnqX87gjT4882jSsulNm2Dgh9zLNkXFchNj8Y9dCMQlylEq3kg+c M+J6za9bualI2adjzL7xXJGfxO10SxPu0GpX1DiuNZQbHhQHO5ZkJUP/ba+Q0pVKh8mq gDtRc80h33++cbaGlI2P5ZTHNv6MjhGUpTUW4O3m9XhkeCR01X7OBwYtfGpOVhjwiGCd cifw== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=/zHxmluN0BQ4g4B+jy/KGPGzVWApZW42f3eyU5l2gLA=; fh=wmn2BpfHg0f3rTW9sWDPts713saA9Ez48EV0r98IfAg=; b=uH+tA4f+IXS4HBDDOY6oaT2o3hxIFX+LqFDS+k4mXm1CVscWXiWcv6gz9MoPasMo3A S44pj0HtexDmHVr2giWRz6fGz1xkXp4+wCRafX6PTCEt/mCKLwKxSTcHyQNaASUsthc+ oz4GhfcmrMZGU6oTlKy5eOWGPMYevlbAYqDD2Dsptzxxa4CR85JERs9iR8bJn6Rf/eEM I5o/0+p2IBorHkzyfsO1r5LuYcJ59wg1pv8hO7FQik+dM5fjvWdyR9hzQgOPD47teCw7 tSO+HUbVaG2zp5VsmbMNUdxmqd7UY55gQuIY208MwyD+jt2u5pZxu4LkKvVq/eSo1LhS 4E2g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id o9-20020a634e49000000b00565f01b9403si8140992pgl.883.2023.09.12.09.42.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 09:42:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 331BB852683B; Mon, 11 Sep 2023 23:44:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230123AbjILGoW (ORCPT + 99 others); Tue, 12 Sep 2023 02:44:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbjILGoW (ORCPT ); Tue, 12 Sep 2023 02:44:22 -0400 Received: from soltyk.jannau.net (soltyk.jannau.net [144.76.91.90]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBF0CAF for ; Mon, 11 Sep 2023 23:44:17 -0700 (PDT) Received: by soltyk.jannau.net (Postfix, from userid 1000) id D9EEF270487; Tue, 12 Sep 2023 08:44:15 +0200 (CEST) Date: Tue, 12 Sep 2023 08:44:15 +0200 From: Janne Grunau To: Christophe JAILLET Cc: Thomas Zimmermann , Javier Martinez Canillas , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.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> <0b6ad379-049a-5152-12e5-77c62ffc4541@wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0b6ad379-049a-5152-12e5-77c62ffc4541@wanadoo.fr> 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 (howler.vger.email [0.0.0.0]); Mon, 11 Sep 2023 23:44:21 -0700 (PDT) On 2023-09-10 22:16:05 +0200, Christophe JAILLET wrote: > Le 10/09/2023 ? 18:39, Janne Grunau via B4 Relay a ?crit?: > > 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 (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); > > + } > > + > > sdev->pwr_dom_devs[i] can be an ERR_PTR here. > Maybe a break or a continue missing after drm_err() above? yes, a continue is missing, added, locally for v2. thanks Janne