From patchwork Wed Oct 2 12:22:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 13819759 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7058CCF31B4 for ; Wed, 2 Oct 2024 12:31:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gFH9tv3EyMbkQCesSF+Pisa4vxI80qkPcngq9hSO9D0=; b=iEavdC+JPMlPthTk+GcUy8NZ8T TC6mHPTj+95dzFkDUAzLaVNDqp46qX07lwg0gqvPyN2/o+A06ub1yqIKEYgFzbYrJ41rZJkMpCANq xoRSXG9xEfhHxTq4g/a2UrGECMEfQTwfmrJkRSFOf8sKExqtxe1zSQbpHPgwJRzpcAy5on1Cpv+ca BaIMQoTD8IzBwj64dlICJfPvEBojoBYOnXNNmB431QQE4L7WhLQnzPamCPL4bWiIKelSb70WrXkur EJ2sdXR3nRKDJ7CtRq/ljAXm8v2XB/8Het9v2NzaGVtnFDtFGLIxmbG6K2H/cBjl3exuLZ9bExMAQ qj5lufsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1svyW0-00000005ta6-07ZT; Wed, 02 Oct 2024 12:31:36 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1svyNa-00000005qXi-1wQW for linux-arm-kernel@lists.infradead.org; Wed, 02 Oct 2024 12:22:55 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-5398939d29eso6012544e87.0 for ; Wed, 02 Oct 2024 05:22:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727871773; x=1728476573; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gFH9tv3EyMbkQCesSF+Pisa4vxI80qkPcngq9hSO9D0=; b=mLIzQOrW/qnYyTnRRDC7yNX/i7cGdYQAs5gbSiDdLSbO53LhjUutwKBmZFlpjGVDY9 0c5P4eooZQGOHj0hkSicBHooncWTD8qvHZg0ZBFIz+yTteURY2T6JCBAWPbP57xu2Skk YuPAPaOyhI/DMBxFXKnD3lPFDfXTgWCOvgAdQIhC4UP0sIysvqJMNRu/rsbsotX0CGHz YJVP4PPB2hVBpgZRezCmdi23VhDawpVFrJkPv1sTY9P11LNyiAeaEg1r5dkz8+9fLMW2 QsA4Yx9Hf3hTVRrwFQBsMb5jDKkrPixCgvC8ZDswrDdNMFNK/I5oMPRzlNnrWWsTSnJm O0JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727871773; x=1728476573; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gFH9tv3EyMbkQCesSF+Pisa4vxI80qkPcngq9hSO9D0=; b=crUymAksE5YfU537yprEhHwLyXm1taHCOgDedxsbaOQXU6Ou65Wb1LqLRiH1bqIC8H BGV+Y9st0ygYvpfCWbIUncaQYQjKGMRNTraht/nK1vCqPf9PPOlcUpq68d8CSTGCDPuJ 4QMB6cDwqVm8l6YR1BRuoLpEhPjfTB4GkbQq1Z0ZhD4Fz+ADECJ3OO6BjgQnrXEteoMM 8GiZMVutkoxAvsJSwM+HH3VKbdYrEhr6aYNK9nxHDEoR6qMsEptboH/sjllrzROnygGR 3gsyo3dY+2fq9VoKyT64ao7QsJZvRpt4EQFfHZ5G5tXTEEpKI4EGe4AcDTOwM+491I20 ebdg== X-Forwarded-Encrypted: i=1; AJvYcCX8jvi9kseWztjTZjsCRhdd4lQuHQhWofO0XNfWF+jyXn4A+DStGK/Alid1HMAvDaRkYzSYGBYbII/2LOzxWit4@lists.infradead.org X-Gm-Message-State: AOJu0YwswjKEvbujb0WR5xXzQPt040g9T/SneuII5bkw5sHRYT3VUigi 01vFhQ9X03a3fr5snD2kvBzFN6YbP2MHmOZEJ7VDzvZ43blXTR4ZNXvr9LqrVTc= X-Google-Smtp-Source: AGHT+IHEjNv7ZCxNOSC2V6obj2+dWZVZVLatN/UEyPBuKnoG56fp85/7vBdsw6KDnsPAalW5KMVKog== X-Received: by 2002:a05:6512:124d:b0:539:8f4d:a7dd with SMTP id 2adb3069b0e04-539a0795b71mr1720419e87.42.1727871772538; Wed, 02 Oct 2024 05:22:52 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-538a043204fsm1912659e87.165.2024.10.02.05.22.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 05:22:52 -0700 (PDT) From: Ulf Hansson To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: "Rafael J . Wysocki" , Dikshita Agarwal , Vedang Nagar , Bjorn Andersson , Konrad Dybcio , Nikunj Kela , Bryan O'Donoghue , Thierry Reding , Mikko Perttunen , Jonathan Hunter , Stephan Gerhold , Ilia Lin , Stanimir Varbanov , Vikash Garodia , Ulf Hansson , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 06/11] pmdomain: core: Set the required dev for a required OPP during genpd attach Date: Wed, 2 Oct 2024 14:22:27 +0200 Message-Id: <20241002122232.194245-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241002122232.194245-1-ulf.hansson@linaro.org> References: <20241002122232.194245-1-ulf.hansson@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241002_052254_531741_846B6C34 X-CRM114-Status: GOOD ( 23.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In the single PM domain case there is no need for platform code to specify the index of the corresponding required OPP in DT, as the index must be zero. This allows us to assign a required dev for the required OPP from genpd, while attaching a device to its PM domain. In this way, we can remove some of the genpd specific code in the OPP core for the single PM domain case. Although, this cleanup is made from a subsequent change. Signed-off-by: Ulf Hansson --- Changes in v4: - Limit the assignment of the required_dev to the single PM domain case. - Use dev_pm_opp_set_config() rather than the resource managed version. --- drivers/pmdomain/core.c | 42 ++++++++++++++++++++++++++++++++++++--- include/linux/pm_domain.h | 1 + 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c index 259abd338f4c..76490f0bf1e2 100644 --- a/drivers/pmdomain/core.c +++ b/drivers/pmdomain/core.c @@ -1722,6 +1722,7 @@ static void genpd_free_dev_data(struct device *dev, spin_unlock_irq(&dev->power.lock); + dev_pm_opp_clear_config(gpd_data->opp_token); kfree(gpd_data->td); kfree(gpd_data); dev_pm_put_subsys_data(dev); @@ -2884,6 +2885,29 @@ static void genpd_dev_pm_sync(struct device *dev) genpd_queue_power_off_work(pd); } +static int genpd_set_required_opp_dev(struct device *dev, + struct device *base_dev) +{ + struct dev_pm_opp_config config = { + .required_dev = dev, + }; + int ret; + + /* Limit support to non-providers for now. */ + if (of_property_present(base_dev->of_node, "#power-domain-cells")) + return 0; + + if (!dev_pm_opp_of_has_required_opp(base_dev)) + return 0; + + ret = dev_pm_opp_set_config(base_dev, &config); + if (ret < 0) + return ret; + + dev_gpd_data(dev)->opp_token = ret; + return 0; +} + static int genpd_set_required_opp(struct device *dev, unsigned int index) { int ret, pstate; @@ -2908,7 +2932,8 @@ static int genpd_set_required_opp(struct device *dev, unsigned int index) } static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev, - unsigned int index, bool power_on) + unsigned int index, unsigned int num_domains, + bool power_on) { struct of_phandle_args pd_args; struct generic_pm_domain *pd; @@ -2940,6 +2965,17 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev, dev->pm_domain->detach = genpd_dev_pm_detach; dev->pm_domain->sync = genpd_dev_pm_sync; + /* + * For a single PM domain the index of the required OPP must be zero, so + * let's try to assign a required dev in that case. In the multiple PM + * domains case, we need platform code to specify the index. + */ + if (num_domains == 1) { + ret = genpd_set_required_opp_dev(dev, base_dev); + if (ret) + goto err; + } + ret = genpd_set_required_opp(dev, index); if (ret) goto err; @@ -2994,7 +3030,7 @@ int genpd_dev_pm_attach(struct device *dev) "#power-domain-cells") != 1) return 0; - return __genpd_dev_pm_attach(dev, dev, 0, true); + return __genpd_dev_pm_attach(dev, dev, 0, 1, true); } EXPORT_SYMBOL_GPL(genpd_dev_pm_attach); @@ -3047,7 +3083,7 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev, } /* Try to attach the device to the PM domain at the specified index. */ - ret = __genpd_dev_pm_attach(virt_dev, dev, index, false); + ret = __genpd_dev_pm_attach(virt_dev, dev, index, num_domains, false); if (ret < 1) { device_unregister(virt_dev); return ret ? ERR_PTR(ret) : NULL; diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 92f9d56f623d..76775ab38898 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -252,6 +252,7 @@ struct generic_pm_domain_data { unsigned int performance_state; unsigned int default_pstate; unsigned int rpm_pstate; + unsigned int opp_token; bool hw_mode; void *data; };