From nobody Sun Apr 19 09:06:42 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 EE54FCCA479 for ; Mon, 4 Jul 2022 12:08:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233944AbiGDMIV (ORCPT ); Mon, 4 Jul 2022 08:08:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233896AbiGDMIO (ORCPT ); Mon, 4 Jul 2022 08:08:14 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD91B1183F for ; Mon, 4 Jul 2022 05:08:13 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id x18-20020a17090a8a9200b001ef83b332f5so3222849pjn.0 for ; Mon, 04 Jul 2022 05:08:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WfE4CypbYijTDGyXwa2amCPLxG9OKV5lx3ftdIcweMc=; b=VOQJJ0Xj/keiRsNE95xbWVq38yfDGgT0CJdYARDTyHrjtV95Uc7sIddF49E+uHQB8W DKqF1YdxyG2JQ2Y/2iig0KDAG2jVxWnLUhjs98cQbu5TmUNfqmVRwp4IeB3lhaZNphN6 V9n71n5QAbcZDGZNZT5Aa7pVyqw3H5bbVxINxocWdRcT3RtNX/mKpHVLVzxFZKOdSgIt mZZduUrAHuSRleXG5LxEHs+yi+6Iva1IuOZIkcorwseVgaJXkkPHoFmFVy0iZXgFD76j 3U3Ex1JLKEVxe4LPtOSbwFKBU+99HnItBt/Zrum/Ad7gIPy6HIduiDWG9OcSXGjKYPl6 zibA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WfE4CypbYijTDGyXwa2amCPLxG9OKV5lx3ftdIcweMc=; b=Lub+1EY0iXcQECF0bOb6JjsSQLuzXyiBr11jqKhn11l4j4LdX3PE9IefqgoCrCAzci V00bso8RqhkWmhFvz5KZQpGd5wuqT9aq3Kdvu/plZjN5++iN3ntOUdnyhHpe03tv6wnk C8VLh5Y3Rj5YHseupnsya4YnmLILZMgyilMrf3E4QcCga5Pc1r3eHeuu3N2fKu0Mmqnz L383wctyrRw961LR2CMs+mjF1Wwrw9o18VLr9WU0Vr7gYil/Q0weD7/eT0lLnN0vSXfx Wj2KPU+fVMutX2BM7bCm8GI/ARFdhM1OudigiYYwAlr/tcMMdjwulnoTnpxb9yGwA2lx XayA== X-Gm-Message-State: AJIora8K0+SDv2T0ABcU7IdqqdfNNw0FA8IfvHWSXnQ8hYP4zgRt/w5z ngUJcPzCV9eT8sUR1KrNBb2Wwg== X-Google-Smtp-Source: AGRyM1sEiZGHuKgCdtlWDDXh3Q8VSVWbopUUJNuMEHLrtBilE/TOPNcCiyxk+knqz76QgtmPzTy/qQ== X-Received: by 2002:a17:902:934c:b0:167:80c6:aedd with SMTP id g12-20020a170902934c00b0016780c6aeddmr36946238plp.97.1656936492939; Mon, 04 Jul 2022 05:08:12 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id bc12-20020a170902930c00b0015e8d4eb1d5sm20991256plb.31.2022.07.04.05.08.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:12 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org Subject: [PATCH V3 01/20] OPP: Track if clock name is configured by platform Date: Mon, 4 Jul 2022 17:37:39 +0530 Message-Id: <0a43452bb6b1f499b695b123e9fedf4b1a9bbf64.1656935522.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" Track if the clock name is configured by the platform or not. This is a preparatory change and will be used by later commits. This also makes the behavior of the clkname API similar to other ones, which allow repeated calls to the same API for each CPU. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 7 +++++++ drivers/opp/opp.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index b2715950e76d..e166bfe5fc90 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -2277,6 +2277,10 @@ struct opp_table *dev_pm_opp_set_clkname(struct devi= ce *dev, const char *name) goto err; } =20 + /* Another CPU that shares the OPP table has set the clkname ? */ + if (opp_table->clk_configured) + return opp_table; + /* clk shouldn't be initialized at this point */ if (WARN_ON(opp_table->clk)) { ret =3D -EBUSY; @@ -2291,6 +2295,8 @@ struct opp_table *dev_pm_opp_set_clkname(struct devic= e *dev, const char *name) goto err; } =20 + opp_table->clk_configured =3D true; + return opp_table; =20 err: @@ -2311,6 +2317,7 @@ void dev_pm_opp_put_clkname(struct opp_table *opp_tab= le) =20 clk_put(opp_table->clk); opp_table->clk =3D ERR_PTR(-EINVAL); + opp_table->clk_configured =3D false; =20 dev_pm_opp_put_opp_table(opp_table); } diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 45e3a55239a1..9e1cfcb0ea98 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -149,6 +149,7 @@ enum opp_table_access { * @supported_hw: Array of version number to support. * @supported_hw_count: Number of elements in supported_hw array. * @prop_name: A name to postfix to many DT properties, while parsing them. + * @clk_configured: Clock name is configured by the platform. * @clk: Device's clock handle * @regulators: Supply regulators * @regulator_count: Number of power supply regulators. Its value can be -1 @@ -200,6 +201,7 @@ struct opp_table { unsigned int *supported_hw; unsigned int supported_hw_count; const char *prop_name; + bool clk_configured; struct clk *clk; struct regulator **regulators; int regulator_count; --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 EA323CCA479 for ; Mon, 4 Jul 2022 12:08:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233983AbiGDMI0 (ORCPT ); Mon, 4 Jul 2022 08:08:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233926AbiGDMIS (ORCPT ); Mon, 4 Jul 2022 08:08:18 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04C5411456 for ; Mon, 4 Jul 2022 05:08:17 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id a15so2420694pjs.0 for ; Mon, 04 Jul 2022 05:08:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JrOGtxkFmB6UH0d1rGpCly52Gseq2BReDDh7CSQ+HAQ=; b=qEcnTAIjcN2FhHiBHkMFY4f7YGO5q4FlBkrys/AbzPQC6gyy/PoQmTIQHzPNYy6smq upYJ9fz1S2hIU0zCWOvCx+NBN3GwOwVTxeDdILqAN+ZBJWgOL3aaVpHUyIEQf3W9y4GB oVL403zkb82N14XsG1SDHWSjz0ZiPEs46zuIfVSHfJrWNaUL7fXukYEFO95bvmNySRpt 2WjI0oVb7xcGbbjmi36Z9R6Znz1wCfpQRyNdOkQif0fIJC1HhAztjQCT/hrCRztijbZF NnFiHfq9aQuFW+0mlewI5A6zzCCj0hQQ1NQOdt9t0Vq/akqTODbLRtc4dXQmEtKgQF2I 4l5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JrOGtxkFmB6UH0d1rGpCly52Gseq2BReDDh7CSQ+HAQ=; b=3dohhNAhO/5Fg/bCruT/Fa93qTIt8TUk7Kp5f1grXQtKp4d4wQ4xrjsaJcWK6GTwX2 jBZPwGTw2XvRvXnLZXJDV9dlqHBFsXZOJo/CJUZy5DM+tAkF6rpBm+4TaW8sT5jywTl+ r452vHBLURzINCMDyOq/5T06F5Oypk4+G/GZNvCpByRmcLSEQpCYBjgUh05Feb/K3pdv 5SXKco1nyRbeOCaMl03uK2X+G3Gcdb5ru2zMbKFejmfqzqlOeJjrCIfwb7KlRoZjmaDQ +1wjoZHlcX0h0oU70ZZ0b0H5hXMh8oqbSTZw9i71v9G3QCh2qAm8CSVaUA0cQtH10Wak lf4w== X-Gm-Message-State: AJIora/zljAGHjovAMzbKTqsSxFCMI5LOnyXDFCDrOi+w3VZRnFlSUVK zAQ1X0GCrxZ53rekMnjj+qHkog== X-Google-Smtp-Source: AGRyM1vYOAL9m3AYRPKBdHWJfJ6+0roTu5XHMn0UOmQO2dYfab5ob4tUcBZNNswchA1997RbCNrTzw== X-Received: by 2002:a17:90b:1e06:b0:1ec:b513:4523 with SMTP id pg6-20020a17090b1e0600b001ecb5134523mr36905015pjb.58.1656936496430; Mon, 04 Jul 2022 05:08:16 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id u10-20020a056a00098a00b0051bc721b838sm21068389pfg.188.2022.07.04.05.08.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:16 -0700 (PDT) From: Viresh Kumar To: "Rafael J. Wysocki" , Viresh Kumar , Chanwoo Choi , MyungJoo Ham , Kyungmin Park , Krzysztof Kozlowski , Alim Akhtar , Qiang Yu , Rob Herring , Tomeu Vizoso , Steven Price , Alyssa Rosenzweig , Nishanth Menon , Stephen Boyd , Thierry Reding , Jonathan Hunter Cc: linux-pm@vger.kernel.org, Vincent Guittot , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org, lima@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH V3 02/20] OPP: Make dev_pm_opp_set_regulators() accept NULL terminated list Date: Mon, 4 Jul 2022 17:37:40 +0530 Message-Id: <9730e011004b7526e79c6f409f5147fb235b414a.1656935522.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" Make dev_pm_opp_set_regulators() accept a NULL terminated list of names instead of making the callers keep the two parameters in sync, which creates an opportunity for bugs to get in. Suggested-by: Greg Kroah-Hartman Signed-off-by: Viresh Kumar Reviewed-by: Chanwoo Choi --- drivers/cpufreq/cpufreq-dt.c | 9 ++++----- drivers/cpufreq/ti-cpufreq.c | 7 +++---- drivers/devfreq/exynos-bus.c | 4 ++-- drivers/gpu/drm/lima/lima_devfreq.c | 3 ++- drivers/gpu/drm/panfrost/panfrost_devfreq.c | 4 ++-- drivers/opp/core.c | 18 ++++++++++++------ drivers/soc/tegra/pmc.c | 4 ++-- include/linux/pm_opp.h | 9 ++++----- 8 files changed, 31 insertions(+), 27 deletions(-) diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c index 8fcaba541539..be0c19b3ffa5 100644 --- a/drivers/cpufreq/cpufreq-dt.c +++ b/drivers/cpufreq/cpufreq-dt.c @@ -193,7 +193,7 @@ static int dt_cpufreq_early_init(struct device *dev, in= t cpu) struct private_data *priv; struct device *cpu_dev; bool fallback =3D false; - const char *reg_name; + const char *reg_name[] =3D { NULL, NULL }; int ret; =20 /* Check if this CPU is already covered by some other policy */ @@ -218,10 +218,9 @@ static int dt_cpufreq_early_init(struct device *dev, i= nt cpu) * OPP layer will be taking care of regulators now, but it needs to know * the name of the regulator first. */ - reg_name =3D find_supply_name(cpu_dev); - if (reg_name) { - priv->opp_table =3D dev_pm_opp_set_regulators(cpu_dev, ®_name, - 1); + reg_name[0] =3D find_supply_name(cpu_dev); + if (reg_name[0]) { + priv->opp_table =3D dev_pm_opp_set_regulators(cpu_dev, reg_name); if (IS_ERR(priv->opp_table)) { ret =3D PTR_ERR(priv->opp_table); if (ret !=3D -EPROBE_DEFER) diff --git a/drivers/cpufreq/ti-cpufreq.c b/drivers/cpufreq/ti-cpufreq.c index 8f9fdd864391..560d67a6bef1 100644 --- a/drivers/cpufreq/ti-cpufreq.c +++ b/drivers/cpufreq/ti-cpufreq.c @@ -173,7 +173,7 @@ static struct ti_cpufreq_soc_data omap34xx_soc_data =3D= { * seems to always read as 0). */ =20 -static const char * const omap3_reg_names[] =3D {"cpu0", "vbb"}; +static const char * const omap3_reg_names[] =3D {"cpu0", "vbb", NULL}; =20 static struct ti_cpufreq_soc_data omap36xx_soc_data =3D { .reg_names =3D omap3_reg_names, @@ -326,7 +326,7 @@ static int ti_cpufreq_probe(struct platform_device *pde= v) const struct of_device_id *match; struct opp_table *ti_opp_table; struct ti_cpufreq_data *opp_data; - const char * const default_reg_names[] =3D {"vdd", "vbb"}; + const char * const default_reg_names[] =3D {"vdd", "vbb", NULL}; int ret; =20 match =3D dev_get_platdata(&pdev->dev); @@ -387,8 +387,7 @@ static int ti_cpufreq_probe(struct platform_device *pde= v) if (opp_data->soc_data->reg_names) reg_names =3D opp_data->soc_data->reg_names; ti_opp_table =3D dev_pm_opp_set_regulators(opp_data->cpu_dev, - reg_names, - ARRAY_SIZE(default_reg_names)); + reg_names); if (IS_ERR(ti_opp_table)) { dev_pm_opp_put_supported_hw(opp_data->opp_table); ret =3D PTR_ERR(ti_opp_table); diff --git a/drivers/devfreq/exynos-bus.c b/drivers/devfreq/exynos-bus.c index e689101abc93..541baff93ee8 100644 --- a/drivers/devfreq/exynos-bus.c +++ b/drivers/devfreq/exynos-bus.c @@ -180,10 +180,10 @@ static int exynos_bus_parent_parse_of(struct device_n= ode *np, { struct device *dev =3D bus->dev; struct opp_table *opp_table; - const char *vdd =3D "vdd"; + const char *supplies[] =3D { "vdd", NULL }; int i, ret, count, size; =20 - opp_table =3D dev_pm_opp_set_regulators(dev, &vdd, 1); + opp_table =3D dev_pm_opp_set_regulators(dev, supplies); if (IS_ERR(opp_table)) { ret =3D PTR_ERR(opp_table); dev_err(dev, "failed to set regulators %d\n", ret); diff --git a/drivers/gpu/drm/lima/lima_devfreq.c b/drivers/gpu/drm/lima/lim= a_devfreq.c index 8989e215dfc9..dc83c5421125 100644 --- a/drivers/gpu/drm/lima/lima_devfreq.c +++ b/drivers/gpu/drm/lima/lima_devfreq.c @@ -111,6 +111,7 @@ int lima_devfreq_init(struct lima_device *ldev) struct dev_pm_opp *opp; unsigned long cur_freq; int ret; + const char *regulator_names[] =3D { "mali", NULL }; =20 if (!device_property_present(dev, "operating-points-v2")) /* Optional, continue without devfreq */ @@ -122,7 +123,7 @@ int lima_devfreq_init(struct lima_device *ldev) if (ret) return ret; =20 - ret =3D devm_pm_opp_set_regulators(dev, (const char *[]){ "mali" }, 1); + ret =3D devm_pm_opp_set_regulators(dev, regulator_names); if (ret) { /* Continue if the optional regulator is missing */ if (ret !=3D -ENODEV) diff --git a/drivers/gpu/drm/panfrost/panfrost_devfreq.c b/drivers/gpu/drm/= panfrost/panfrost_devfreq.c index 194af7f607a6..12784f349550 100644 --- a/drivers/gpu/drm/panfrost/panfrost_devfreq.c +++ b/drivers/gpu/drm/panfrost/panfrost_devfreq.c @@ -91,6 +91,7 @@ int panfrost_devfreq_init(struct panfrost_device *pfdev) struct devfreq *devfreq; struct thermal_cooling_device *cooling; struct panfrost_devfreq *pfdevfreq =3D &pfdev->pfdevfreq; + const char *supplies[] =3D { pfdev->comp->supply_names[0], NULL }; =20 if (pfdev->comp->num_supplies > 1) { /* @@ -101,8 +102,7 @@ int panfrost_devfreq_init(struct panfrost_device *pfdev) return 0; } =20 - ret =3D devm_pm_opp_set_regulators(dev, pfdev->comp->supply_names, - pfdev->comp->num_supplies); + ret =3D devm_pm_opp_set_regulators(dev, supplies); if (ret) { /* Continue if the optional regulator is missing */ if (ret !=3D -ENODEV) { diff --git a/drivers/opp/core.c b/drivers/opp/core.c index e166bfe5fc90..4e4593957ec5 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -2105,13 +2105,20 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_put_prop_name); * This must be called before any OPPs are initialized for the device. */ struct opp_table *dev_pm_opp_set_regulators(struct device *dev, - const char * const names[], - unsigned int count) + const char * const names[]) { struct dev_pm_opp_supply *supplies; + const char * const *temp =3D names; struct opp_table *opp_table; struct regulator *reg; - int ret, i; + int count =3D 0, ret, i; + + /* Count number of regulators */ + while (*temp++) + count++; + + if (!count) + return ERR_PTR(-EINVAL); =20 opp_table =3D _add_opp_table(dev, false); if (IS_ERR(opp_table)) @@ -2236,12 +2243,11 @@ static void devm_pm_opp_regulators_release(void *da= ta) * Return: 0 on success and errorno otherwise. */ int devm_pm_opp_set_regulators(struct device *dev, - const char * const names[], - unsigned int count) + const char * const names[]) { struct opp_table *opp_table; =20 - opp_table =3D dev_pm_opp_set_regulators(dev, names, count); + opp_table =3D dev_pm_opp_set_regulators(dev, names); if (IS_ERR(opp_table)) return PTR_ERR(opp_table); =20 diff --git a/drivers/soc/tegra/pmc.c b/drivers/soc/tegra/pmc.c index 5611d14d3ba2..6a4b8f7e7948 100644 --- a/drivers/soc/tegra/pmc.c +++ b/drivers/soc/tegra/pmc.c @@ -1384,7 +1384,7 @@ tegra_pmc_core_pd_opp_to_performance_state(struct gen= eric_pm_domain *genpd, static int tegra_pmc_core_pd_add(struct tegra_pmc *pmc, struct device_node= *np) { struct generic_pm_domain *genpd; - const char *rname =3D "core"; + const char *rname[] =3D { "core", NULL}; int err; =20 genpd =3D devm_kzalloc(pmc->dev, sizeof(*genpd), GFP_KERNEL); @@ -1395,7 +1395,7 @@ static int tegra_pmc_core_pd_add(struct tegra_pmc *pm= c, struct device_node *np) genpd->set_performance_state =3D tegra_pmc_core_pd_set_performance_state; genpd->opp_to_performance_state =3D tegra_pmc_core_pd_opp_to_performance_= state; =20 - err =3D devm_pm_opp_set_regulators(pmc->dev, &rname, 1); + err =3D devm_pm_opp_set_regulators(pmc->dev, rname); if (err) return dev_err_probe(pmc->dev, err, "failed to set core OPP regulator\n"); diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 6708b4ec244d..4c490865d574 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -159,9 +159,9 @@ void dev_pm_opp_put_supported_hw(struct opp_table *opp_= table); int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, = unsigned int count); struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char = *name); void dev_pm_opp_put_prop_name(struct opp_table *opp_table); -struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char= * const names[], unsigned int count); +struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char= * const names[]); void dev_pm_opp_put_regulators(struct opp_table *opp_table); -int devm_pm_opp_set_regulators(struct device *dev, const char * const name= s[], unsigned int count); +int devm_pm_opp_set_regulators(struct device *dev, const char * const name= s[]); struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *n= ame); void dev_pm_opp_put_clkname(struct opp_table *opp_table); int devm_pm_opp_set_clkname(struct device *dev, const char *name); @@ -379,7 +379,7 @@ static inline struct opp_table *dev_pm_opp_set_prop_nam= e(struct device *dev, con =20 static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {} =20 -static inline struct opp_table *dev_pm_opp_set_regulators(struct device *d= ev, const char * const names[], unsigned int count) +static inline struct opp_table *dev_pm_opp_set_regulators(struct device *d= ev, const char * const names[]) { return ERR_PTR(-EOPNOTSUPP); } @@ -387,8 +387,7 @@ static inline struct opp_table *dev_pm_opp_set_regulato= rs(struct device *dev, co static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) = {} =20 static inline int devm_pm_opp_set_regulators(struct device *dev, - const char * const names[], - unsigned int count) + const char * const names[]) { return -EOPNOTSUPP; } --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 C52EEC433EF for ; Mon, 4 Jul 2022 12:08:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233953AbiGDMIg (ORCPT ); Mon, 4 Jul 2022 08:08:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233963AbiGDMIW (ORCPT ); Mon, 4 Jul 2022 08:08:22 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27EB6B64 for ; Mon, 4 Jul 2022 05:08:20 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id b2so8784059pfb.8 for ; Mon, 04 Jul 2022 05:08:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UR9S24AVhdiyO3FjKQelsAHWRldKQJFRITpPgI47fvs=; b=t/ORs6pHsddG83J8MiSSWlq8NntooA+4f9BfjedD+VNOrTo4Otsbh9ILrb/jygXlxw ZSrkLuIdG+0OuZqV3t0wEJ1mr4p+i0s3wNi90qcGe1g/819ozfKOEDUidTIMO8MXn12L VwRp8XZBEAjbbBbSsX7roq0p8RJx8tyhazLGAyA/oe261Apknf+N3II4+Wr4yNPLQaNV W+XVnYoQX7COmQN/ykxMu7jvMjjh/vJ+9IebEdw743xuJXrNEn1fgtxAaWWSqxPCjVhx xvSbXsG2Jll8a3gNyKH1ZY6s4tJMtKLzBZ+fJeEaZwIFF7UPrch7p5kmt8CkKeMGT8H3 ZX2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UR9S24AVhdiyO3FjKQelsAHWRldKQJFRITpPgI47fvs=; b=CKuL1u7QQtfKSGdRacQGJ+I04GqVCiO8uyEk663ze3f1WZBppJbTR6gKE++WcsXbt1 uHkVa2brCYg7SZlKFlg8OMTHU11NutrphoSamen1wAMuFajkNaeVY0JLfxrw8TRBl7CV 6nRPr1x4/i7R5jd/m3xwOEPjK2QYuWjR8IkYx5Z6WsPIk3QagwkHEmQ3NtPX4aRjOwZv 3I87BPjLvcew0Dn2nrP760EBXFm5SlB0YdQzhfhWIZTqayIH5NqeCKgbLKbmQRU23nvj 4m1gTje8LpgWM7LhyRhkM12h98HUOxv4om8wXEAMqiEGfCmMRHljH8TaixIn90ELyhQ8 Ki/g== X-Gm-Message-State: AJIora+QE5U9X0wfpTaWR/bx6Uqy6WziqUPBnG3SUY6/C8CSPrzBjPOM uUdvB6KnfS59gUOHZRAj9HwZRw== X-Google-Smtp-Source: AGRyM1uIQyxW408bOWtO51tAuKYwlZSV8iuEau8+/wE43ynjPeBq5axSKY7Vu1B87/joAioI/ajspQ== X-Received: by 2002:a05:6a00:32c5:b0:525:933e:252f with SMTP id cl5-20020a056a0032c500b00525933e252fmr34642402pfb.26.1656936499455; Mon, 04 Jul 2022 05:08:19 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id d10-20020a170903230a00b0016be0417409sm2620209plh.254.2022.07.04.05.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:19 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Dmitry Osipenko , linux-kernel@vger.kernel.org Subject: [PATCH V3 03/20] OPP: Add dev_pm_opp_set_config() and friends Date: Mon, 4 Jul 2022 17:37:41 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" The OPP core already have few configuration specific APIs and it is getting complex or messy for both the OPP core and its users. Lets introduce a new set of API which will be used for all kind of different configurations, and shall eventually be used by all the existing ones. The new API, returns a unique token instead of a pointer to the OPP table, which allows the OPP core to drop the resources selectively later on. Tested-by: Dmitry Osipenko Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 229 ++++++++++++++++++++++++++++++++++++++++- drivers/opp/opp.h | 21 ++++ include/linux/pm_opp.h | 42 ++++++++ 3 files changed, 291 insertions(+), 1 deletion(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 4e4593957ec5..7ab20c3b91ed 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -13,11 +13,12 @@ #include #include #include -#include #include #include #include #include +#include +#include =20 #include "opp.h" =20 @@ -36,6 +37,9 @@ DEFINE_MUTEX(opp_table_lock); /* Flag indicating that opp_tables list is being updated at the moment */ static bool opp_tables_busy; =20 +/* OPP ID allocator */ +static DEFINE_XARRAY_ALLOC1(opp_configs); + static bool _find_opp_dev(const struct device *dev, struct opp_table *opp_= table) { struct opp_device *opp_dev; @@ -2624,6 +2628,229 @@ int devm_pm_opp_attach_genpd(struct device *dev, co= nst char * const *names, } EXPORT_SYMBOL_GPL(devm_pm_opp_attach_genpd); =20 +static void _opp_clear_config(struct opp_config_data *data) +{ + if (data->flags & OPP_CONFIG_GENPD) + dev_pm_opp_detach_genpd(data->opp_table); + if (data->flags & OPP_CONFIG_REGULATOR) + dev_pm_opp_put_regulators(data->opp_table); + if (data->flags & OPP_CONFIG_SUPPORTED_HW) + dev_pm_opp_put_supported_hw(data->opp_table); + if (data->flags & OPP_CONFIG_REGULATOR_HELPER) + dev_pm_opp_unregister_set_opp_helper(data->opp_table); + if (data->flags & OPP_CONFIG_PROP_NAME) + dev_pm_opp_put_prop_name(data->opp_table); + if (data->flags & OPP_CONFIG_CLK) + dev_pm_opp_put_clkname(data->opp_table); + + dev_pm_opp_put_opp_table(data->opp_table); + kfree(data); +} + +/** + * dev_pm_opp_set_config() - Set OPP configuration for the device. + * @dev: Device for which configuration is being set. + * @config: OPP configuration. + * + * This allows all device OPP configurations to be performed at once. + * + * This must be called before any OPPs are initialized for the device. Thi= s may + * be called multiple times for the same OPP table, for example once for e= ach + * CPU that share the same table. This must be balanced by the same number= of + * calls to dev_pm_opp_clear_config() in order to free the OPP table prope= rly. + * + * This returns a token to the caller, which must be passed to + * dev_pm_opp_clear_config() to free the resources later. The value of the + * returned token will be >=3D 1 for success and negative for errors. The = minimum + * value of 1 is chosen here to make it easy for callers to manage the res= ource. + */ +int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *co= nfig) +{ + struct opp_table *opp_table, *err; + struct opp_config_data *data; + unsigned int id; + int ret; + + data =3D kmalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + opp_table =3D _add_opp_table(dev, false); + if (IS_ERR(opp_table)) { + kfree(data); + return PTR_ERR(opp_table); + } + + data->opp_table =3D opp_table; + data->flags =3D 0; + + /* This should be called before OPPs are initialized */ + if (WARN_ON(!list_empty(&opp_table->opp_list))) { + ret =3D -EBUSY; + goto err; + } + + /* Configure clocks */ + if (config->clk_names) { + const char * const *temp =3D config->clk_names; + int count =3D 0; + + /* Count number of clks */ + while (*temp++) + count++; + + /* + * This is a special case where we have a single clock, whose + * connection id name is NULL, i.e. first two entries are NULL + * in the array. + */ + if (!count && !config->clk_names[1]) + count =3D 1; + + /* We support only one clock name for now */ + if (count !=3D 1) { + ret =3D -EINVAL; + goto err; + } + + err =3D dev_pm_opp_set_clkname(dev, config->clk_names[0]); + if (IS_ERR(err)) { + ret =3D PTR_ERR(err); + goto err; + } + + data->flags |=3D OPP_CONFIG_CLK; + } + + /* Configure property names */ + if (config->prop_name) { + err =3D dev_pm_opp_set_prop_name(dev, config->prop_name); + if (IS_ERR(err)) { + ret =3D PTR_ERR(err); + goto err; + } + + data->flags |=3D OPP_CONFIG_PROP_NAME; + } + + /* Configure opp helper */ + if (config->set_opp) { + err =3D dev_pm_opp_register_set_opp_helper(dev, config->set_opp); + if (IS_ERR(err)) { + ret =3D PTR_ERR(err); + goto err; + } + + data->flags |=3D OPP_CONFIG_REGULATOR_HELPER; + } + + /* Configure supported hardware */ + if (config->supported_hw) { + err =3D dev_pm_opp_set_supported_hw(dev, config->supported_hw, + config->supported_hw_count); + if (IS_ERR(err)) { + ret =3D PTR_ERR(err); + goto err; + } + + data->flags |=3D OPP_CONFIG_SUPPORTED_HW; + } + + /* Configure supplies */ + if (config->regulator_names) { + err =3D dev_pm_opp_set_regulators(dev, config->regulator_names); + if (IS_ERR(err)) { + ret =3D PTR_ERR(err); + goto err; + } + + data->flags |=3D OPP_CONFIG_REGULATOR; + } + + /* Attach genpds */ + if (config->genpd_names) { + err =3D dev_pm_opp_attach_genpd(dev, config->genpd_names, + config->virt_devs); + if (IS_ERR(err)) { + ret =3D PTR_ERR(err); + goto err; + } + + data->flags |=3D OPP_CONFIG_GENPD; + } + + ret =3D xa_alloc(&opp_configs, &id, data, XA_LIMIT(1, INT_MAX), + GFP_KERNEL); + if (ret) + goto err; + + return id; + +err: + _opp_clear_config(data); + return ret; +} +EXPORT_SYMBOL_GPL(dev_pm_opp_set_config); + +/** + * dev_pm_opp_clear_config() - Releases resources blocked for OPP configur= ation. + * @opp_table: OPP table returned from dev_pm_opp_set_config(). + * + * This allows all device OPP configurations to be cleared at once. This m= ust be + * called once for each call made to dev_pm_opp_set_config(), in order to = free + * the OPPs properly. + * + * Currently the first call itself ends up freeing all the OPP configurati= ons, + * while the later ones only drop the OPP table reference. This works well= for + * now as we would never want to use an half initialized OPP table and wan= t to + * remove the configurations together. + */ +void dev_pm_opp_clear_config(int token) +{ + struct opp_config_data *data; + + /* + * This lets the callers call this unconditionally and keep their code + * simple. + */ + if (unlikely(token <=3D 0)) + return; + + data =3D xa_erase(&opp_configs, token); + if (WARN_ON(!data)) + return; + + _opp_clear_config(data); +} +EXPORT_SYMBOL_GPL(dev_pm_opp_clear_config); + +static void devm_pm_opp_config_release(void *token) +{ + dev_pm_opp_clear_config((unsigned long)token); +} + +/** + * devm_pm_opp_set_config() - Set OPP configuration for the device. + * @dev: Device for which configuration is being set. + * @config: OPP configuration. + * + * This allows all device OPP configurations to be performed at once. + * This is a resource-managed variant of dev_pm_opp_set_config(). + * + * Return: 0 on success and errorno otherwise. + */ +int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *c= onfig) +{ + int token =3D dev_pm_opp_set_config(dev, config); + + if (token < 0) + return token; + + return devm_add_action_or_reset(dev, devm_pm_opp_config_release, + (void *) ((unsigned long) token)); +} +EXPORT_SYMBOL_GPL(devm_pm_opp_set_config); + /** * dev_pm_opp_xlate_required_opp() - Find required OPP for @src_table OPP. * @src_table: OPP table which has @dst_table as one of its required OPP t= able. diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 9e1cfcb0ea98..d652f0cc84f1 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -28,6 +28,27 @@ extern struct mutex opp_table_lock; =20 extern struct list_head opp_tables, lazy_opp_tables; =20 +/* OPP Config flags */ +#define OPP_CONFIG_CLK BIT(0) +#define OPP_CONFIG_REGULATOR BIT(1) +#define OPP_CONFIG_REGULATOR_HELPER BIT(2) +#define OPP_CONFIG_PROP_NAME BIT(3) +#define OPP_CONFIG_SUPPORTED_HW BIT(4) +#define OPP_CONFIG_GENPD BIT(5) + +/** + * struct opp_config_data - data for set config operations + * @opp_table: OPP table + * @flags: OPP config flags + * + * This structure stores the OPP config information for each OPP table + * configuration by the callers. + */ +struct opp_config_data { + struct opp_table *opp_table; + unsigned int flags; +}; + /* * Internal data structure organization with the OPP layer library is as * follows: diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 4c490865d574..a08f9481efb3 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -90,6 +90,32 @@ struct dev_pm_set_opp_data { struct device *dev; }; =20 +/** + * struct dev_pm_opp_config - Device OPP configuration values + * @clk_names: Clk names, NULL terminated array, max 1 clock for now. + * @prop_name: Name to postfix to properties. + * @set_opp: Custom set OPP helper. + * @supported_hw: Array of hierarchy of versions to match. + * @supported_hw_count: Number of elements in the array. + * @regulator_names: Array of pointers to the names of the regulator, NULL= terminated. + * @genpd_names: Null terminated array of pointers containing names of gen= pd to + * attach. + * @virt_devs: Pointer to return the array of virtual devices. + * + * This structure contains platform specific OPP configurations for the de= vice. + */ +struct dev_pm_opp_config { + /* NULL terminated */ + const char * const *clk_names; + const char *prop_name; + int (*set_opp)(struct dev_pm_set_opp_data *data); + const unsigned int *supported_hw; + unsigned int supported_hw_count; + const char * const *regulator_names; + const char * const *genpd_names; + struct device ***virt_devs; +}; + #if defined(CONFIG_PM_OPP) =20 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev); @@ -154,6 +180,10 @@ int dev_pm_opp_disable(struct device *dev, unsigned lo= ng freq); int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block= *nb); int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_blo= ck *nb); =20 +int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *co= nfig); +int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *c= onfig); +void dev_pm_opp_clear_config(int token); + struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u3= 2 *versions, unsigned int count); void dev_pm_opp_put_supported_hw(struct opp_table *opp_table); int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, = unsigned int count); @@ -418,6 +448,18 @@ static inline int devm_pm_opp_attach_genpd(struct devi= ce *dev, return -EOPNOTSUPP; } =20 +static inline int dev_pm_opp_set_config(struct device *dev, struct dev_pm_= opp_config *config) +{ + return -EOPNOTSUPP; +} + +static inline int devm_pm_opp_set_config(struct device *dev, struct dev_pm= _opp_config *config) +{ + return -EOPNOTSUPP; +} + +static inline void dev_pm_opp_clear_config(int token) {} + static inline struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_= table *src_table, struct opp_table *dst_table, struct dev_pm_opp *src_opp) { --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 37954C433EF for ; Mon, 4 Jul 2022 12:08:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234034AbiGDMIm (ORCPT ); Mon, 4 Jul 2022 08:08:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234005AbiGDMIe (ORCPT ); Mon, 4 Jul 2022 08:08:34 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6EFE10DD for ; Mon, 4 Jul 2022 05:08:22 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id k14so8412995plh.4 for ; Mon, 04 Jul 2022 05:08:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xl1HN34mhSotDnvkt8tXbixjNJQAdLGe7tUjPgb4h/M=; b=hejDPxc4/RjWZjryn7VcZq2nFLoqh3D59bqolGEGxKaoAO4HZ9dhFD1ae9+7+eHVo3 HdDau2hnwokSRTjXgR6W4AJgKGXuJLqrEcYvNRpbSjFgO/FOeUg4NWbl+EeaJLR/CXL2 kVoWTBkwswESs/0Z/TC8GJWauLe1k4y78Hux8yuLm1yIaWN99UxzpFrofpE31qFi9sSM ia6hU9BjtJioEODs+PZ0sLGB8yqjfJrZEC/1+bYVGT39nfAXJmE/oGxJfckjTZX4i512 JwzzQImON4dckvSgJi8X99FS90ojLTtXcsetHnqyRX56R3pWpUHfmoRjQxDxZbeWJJaI c3DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xl1HN34mhSotDnvkt8tXbixjNJQAdLGe7tUjPgb4h/M=; b=DfOQ6Zm26GoIllQ6Ph6z5DM8BWgq8+thTdALGbMNncpTgFGS4qLx4utKUls3p4rznt 3B+N8F6ki0trCaWS6c491ZvdgmDN523I4mxeafcpf29sFB62m/jH+dWG6vbyLtN/atZ/ byEKp6jKjKv1FdSI+DB5mSdTaoeka8v8iBWacHfd917CNlEXv+0d0ieRtppMsT9saw02 5FfsfMu2Rp8/KyGYVxIRPLudY2d/1xp+oViFLfpRJNTh+mZbMxtgu9YBQal0TNZk2xQh qEM0BhnvHdhAFLAgnUvZbljnyOEtfzvRzqe3R22BSEteju4NmLu113n8zediAVNCH4ik ReoA== X-Gm-Message-State: AJIora8BSKODrvF6Pcevasy1iImrsWWpAncRWdfWeMij/wm0FUiQiG5v 3Uhji5/KnjWrSF+w1R56MhuqGw== X-Google-Smtp-Source: AGRyM1vSrGUtt8sLadqWT6ivitaXEtkpIrx4RhuIhulQC2xIcP13GoJJAeiT2ojX22gwqUQrgqnIlA== X-Received: by 2002:a17:90b:3d0f:b0:1ed:3dd0:900d with SMTP id pt15-20020a17090b3d0f00b001ed3dd0900dmr35349600pjb.191.1656936502167; Mon, 04 Jul 2022 05:08:22 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id s23-20020a170902a51700b001690d283f52sm20713693plq.158.2022.07.04.05.08.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:21 -0700 (PDT) From: Viresh Kumar To: Andy Gross , Bjorn Andersson , Ilia Lin , "Rafael J. Wysocki" , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , Stephen Boyd , Nishanth Menon , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 04/20] cpufreq: qcom-nvmem: Migrate to dev_pm_opp_set_config() Date: Mon, 4 Jul 2022 17:37:42 +0530 Message-Id: <4623510dc596f65502c44f2879c9cc5dd650dbd3.1656935522.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" The OPP core now provides a unified API for setting all configuration types, i.e. dev_pm_opp_set_config(). Lets start using it. Signed-off-by: Viresh Kumar --- drivers/cpufreq/qcom-cpufreq-nvmem.c | 109 +++++++-------------------- 1 file changed, 28 insertions(+), 81 deletions(-) diff --git a/drivers/cpufreq/qcom-cpufreq-nvmem.c b/drivers/cpufreq/qcom-cp= ufreq-nvmem.c index 6dfa86971a75..863548f59c3e 100644 --- a/drivers/cpufreq/qcom-cpufreq-nvmem.c +++ b/drivers/cpufreq/qcom-cpufreq-nvmem.c @@ -55,9 +55,7 @@ struct qcom_cpufreq_match_data { }; =20 struct qcom_cpufreq_drv { - struct opp_table **names_opp_tables; - struct opp_table **hw_opp_tables; - struct opp_table **genpd_opp_tables; + int *opp_tokens; u32 versions; const struct qcom_cpufreq_match_data *data; }; @@ -315,72 +313,43 @@ static int qcom_cpufreq_probe(struct platform_device = *pdev) } of_node_put(np); =20 - drv->names_opp_tables =3D kcalloc(num_possible_cpus(), - sizeof(*drv->names_opp_tables), + drv->opp_tokens =3D kcalloc(num_possible_cpus(), sizeof(*drv->opp_tokens), GFP_KERNEL); - if (!drv->names_opp_tables) { + if (!drv->opp_tokens) { ret =3D -ENOMEM; goto free_drv; } - drv->hw_opp_tables =3D kcalloc(num_possible_cpus(), - sizeof(*drv->hw_opp_tables), - GFP_KERNEL); - if (!drv->hw_opp_tables) { - ret =3D -ENOMEM; - goto free_opp_names; - } - - drv->genpd_opp_tables =3D kcalloc(num_possible_cpus(), - sizeof(*drv->genpd_opp_tables), - GFP_KERNEL); - if (!drv->genpd_opp_tables) { - ret =3D -ENOMEM; - goto free_opp; - } =20 for_each_possible_cpu(cpu) { + struct dev_pm_opp_config config =3D { + .supported_hw =3D NULL, + }; + cpu_dev =3D get_cpu_device(cpu); if (NULL =3D=3D cpu_dev) { ret =3D -ENODEV; - goto free_genpd_opp; + goto free_opp; } =20 if (drv->data->get_version) { + config.supported_hw =3D &drv->versions; + config.supported_hw_count =3D 1; =20 - if (pvs_name) { - drv->names_opp_tables[cpu] =3D dev_pm_opp_set_prop_name( - cpu_dev, - pvs_name); - if (IS_ERR(drv->names_opp_tables[cpu])) { - ret =3D PTR_ERR(drv->names_opp_tables[cpu]); - dev_err(cpu_dev, "Failed to add OPP name %s\n", - pvs_name); - goto free_opp; - } - } - - drv->hw_opp_tables[cpu] =3D dev_pm_opp_set_supported_hw( - cpu_dev, &drv->versions, 1); - if (IS_ERR(drv->hw_opp_tables[cpu])) { - ret =3D PTR_ERR(drv->hw_opp_tables[cpu]); - dev_err(cpu_dev, - "Failed to set supported hardware\n"); - goto free_genpd_opp; - } + if (pvs_name) + config.prop_name =3D pvs_name; } =20 if (drv->data->genpd_names) { - drv->genpd_opp_tables[cpu] =3D - dev_pm_opp_attach_genpd(cpu_dev, - drv->data->genpd_names, - NULL); - if (IS_ERR(drv->genpd_opp_tables[cpu])) { - ret =3D PTR_ERR(drv->genpd_opp_tables[cpu]); - if (ret !=3D -EPROBE_DEFER) - dev_err(cpu_dev, - "Could not attach to pm_domain: %d\n", - ret); - goto free_genpd_opp; + config.genpd_names =3D drv->data->genpd_names; + config.virt_devs =3D NULL; + } + + if (config.supported_hw || config.genpd_names) { + drv->opp_tokens[cpu] =3D dev_pm_opp_set_config(cpu_dev, &config); + if (drv->opp_tokens[cpu] < 0) { + ret =3D drv->opp_tokens[cpu]; + dev_err(cpu_dev, "Failed to set OPP config\n"); + goto free_opp; } } } @@ -395,27 +364,10 @@ static int qcom_cpufreq_probe(struct platform_device = *pdev) ret =3D PTR_ERR(cpufreq_dt_pdev); dev_err(cpu_dev, "Failed to register platform device\n"); =20 -free_genpd_opp: - for_each_possible_cpu(cpu) { - if (IS_ERR(drv->genpd_opp_tables[cpu])) - break; - dev_pm_opp_detach_genpd(drv->genpd_opp_tables[cpu]); - } - kfree(drv->genpd_opp_tables); free_opp: - for_each_possible_cpu(cpu) { - if (IS_ERR(drv->names_opp_tables[cpu])) - break; - dev_pm_opp_put_prop_name(drv->names_opp_tables[cpu]); - } - for_each_possible_cpu(cpu) { - if (IS_ERR(drv->hw_opp_tables[cpu])) - break; - dev_pm_opp_put_supported_hw(drv->hw_opp_tables[cpu]); - } - kfree(drv->hw_opp_tables); -free_opp_names: - kfree(drv->names_opp_tables); + for_each_possible_cpu(cpu) + dev_pm_opp_clear_config(drv->opp_tokens[cpu]); + kfree(drv->opp_tokens); free_drv: kfree(drv); =20 @@ -429,15 +381,10 @@ static int qcom_cpufreq_remove(struct platform_device= *pdev) =20 platform_device_unregister(cpufreq_dt_pdev); =20 - for_each_possible_cpu(cpu) { - dev_pm_opp_put_supported_hw(drv->names_opp_tables[cpu]); - dev_pm_opp_put_supported_hw(drv->hw_opp_tables[cpu]); - dev_pm_opp_detach_genpd(drv->genpd_opp_tables[cpu]); - } + for_each_possible_cpu(cpu) + dev_pm_opp_clear_config(drv->opp_tokens[cpu]); =20 - kfree(drv->names_opp_tables); - kfree(drv->hw_opp_tables); - kfree(drv->genpd_opp_tables); + kfree(drv->opp_tokens); kfree(drv); =20 return 0; --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 21166C43334 for ; Mon, 4 Jul 2022 12:08:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234221AbiGDMIy (ORCPT ); Mon, 4 Jul 2022 08:08:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233989AbiGDMIg (ORCPT ); Mon, 4 Jul 2022 08:08:36 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1202F11A09 for ; Mon, 4 Jul 2022 05:08:25 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id j1-20020a17090aeb0100b001ef777a7befso3021795pjz.0 for ; Mon, 04 Jul 2022 05:08:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KxgLelNuWT5l4LKZo/aKRP7N8N8MOwnW7uf8T3lO5YM=; b=M5sqMky7dul93mwO1cpzt2UVIUkgqSJnlBiS4jQzhp3uCqpkv9Uj8sBRIzNWCp/4/r /WuapDAVKxR/Ztt/xdo0cWzoAPLRjOuMcOYbjsm+CJus296d/NjdWB6UP+Fq0h3fy1xy ZBTFTkZ1f+H3upB9gQXHVAEnI2yUvawtGn582FfX30yWYdBVBOugD+lhDP9+2OnUq+Km 6V+ZPLUHLDur44Ah00QHHUYeLqfuzelPXsML0KTZdq04Sq9vFIjdTYNogZkyuraPfzUM hJnvWsj3c6AE5YReSV5gjYbmWjn/XqAU9xBxHUMTlsj5Hy4CrUyHm+PhsvAuHuR/DSz7 ldpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KxgLelNuWT5l4LKZo/aKRP7N8N8MOwnW7uf8T3lO5YM=; b=0cKHrB0fBkrqlvv7UvtmEWI4Lu95uxlt1rxLKOxGsT6/rOw6T1l1dkgJTfXggoYKpX JHKMlVx0Cs0TmiQvzcbyum49ux7CHRsJfoYLAOj5mjPUN15rIq3iOCFLnvY9GBrUsD2p eTjxrM9wka1sf76lq7A63o/6EISB97BICa0iME5zUk4iQhNtGPzS+I2FggIeOVNNVGBQ nds0LWatokeWlhTGQsqPOpL5wf00nwUp8uUjJIQnqmMekXKQfrwmWDk859+gXwcu1T/0 htw8/8PPo9ze+pnpIcFHrY70mv/mUZC6lmIFtxDvbrRDfwxYW0+Uhu5CWgFNNcxXAowx BH7Q== X-Gm-Message-State: AJIora+vj9V5J8GAQ1daazvIe+c3Zb0XzteqQMEowH+hVHTeau7bNtrK weCxGC6Wvd5s69GMxzHWfgHGoQ== X-Google-Smtp-Source: AGRyM1toKei5gUmcV+0t+PABYig/AwZPmv/yv+3Ilq4Kot+Y4MOsLO3uFqP/qQMxIcknTkRKzRuqQA== X-Received: by 2002:a17:90b:2285:b0:1ec:aa3f:8dc1 with SMTP id kx5-20020a17090b228500b001ecaa3f8dc1mr36415858pjb.145.1656936505024; Mon, 04 Jul 2022 05:08:25 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id s7-20020a17090302c700b00168e83eda56sm21060261plk.3.2022.07.04.05.08.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:24 -0700 (PDT) From: Viresh Kumar To: Patrice Chotard , "Rafael J. Wysocki" , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , Stephen Boyd , Nishanth Menon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 05/20] cpufreq: sti: Migrate to dev_pm_opp_set_config() Date: Mon, 4 Jul 2022 17:37:43 +0530 Message-Id: <0b24496df4a70225c777726ffe2540cf83a3c079.1656935522.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" The OPP core now provides a unified API for setting all configuration types, i.e. dev_pm_opp_set_config(). Lets start using it. Signed-off-by: Viresh Kumar --- drivers/cpufreq/sti-cpufreq.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/drivers/cpufreq/sti-cpufreq.c b/drivers/cpufreq/sti-cpufreq.c index fdb0a722d881..a67df90848c2 100644 --- a/drivers/cpufreq/sti-cpufreq.c +++ b/drivers/cpufreq/sti-cpufreq.c @@ -156,9 +156,13 @@ static int sti_cpufreq_set_opp_info(void) unsigned int hw_info_offset; unsigned int version[VERSION_ELEMENTS]; int pcode, substrate, major, minor; - int ret; + int opp_token, ret; char name[MAX_PCODE_NAME_LEN]; - struct opp_table *opp_table; + struct dev_pm_opp_config config =3D { + .supported_hw =3D version, + .supported_hw_count =3D ARRAY_SIZE(version), + .prop_name =3D name, + }; =20 reg_fields =3D sti_cpufreq_match(); if (!reg_fields) { @@ -210,21 +214,14 @@ static int sti_cpufreq_set_opp_info(void) =20 snprintf(name, MAX_PCODE_NAME_LEN, "pcode%d", pcode); =20 - opp_table =3D dev_pm_opp_set_prop_name(dev, name); - if (IS_ERR(opp_table)) { - dev_err(dev, "Failed to set prop name\n"); - return PTR_ERR(opp_table); - } - version[0] =3D BIT(major); version[1] =3D BIT(minor); version[2] =3D BIT(substrate); =20 - opp_table =3D dev_pm_opp_set_supported_hw(dev, version, VERSION_ELEMENTS); - if (IS_ERR(opp_table)) { - dev_err(dev, "Failed to set supported hardware\n"); - ret =3D PTR_ERR(opp_table); - goto err_put_prop_name; + opp_token =3D dev_pm_opp_set_config(dev, &config); + if (opp_token < 0) { + dev_err(dev, "Failed to set OPP config\n"); + return opp_token; } =20 dev_dbg(dev, "pcode: %d major: %d minor: %d substrate: %d\n", @@ -233,10 +230,6 @@ static int sti_cpufreq_set_opp_info(void) version[0], version[1], version[2]); =20 return 0; - -err_put_prop_name: - dev_pm_opp_put_prop_name(opp_table); - return ret; } =20 static int sti_cpufreq_fetch_syscon_registers(void) --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 6B1E2C433EF for ; Mon, 4 Jul 2022 12:09:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234251AbiGDMI7 (ORCPT ); Mon, 4 Jul 2022 08:08:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234124AbiGDMIj (ORCPT ); Mon, 4 Jul 2022 08:08:39 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B11111C1A for ; Mon, 4 Jul 2022 05:08:28 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id o18so7600790pgu.9 for ; Mon, 04 Jul 2022 05:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WkT4cfQDKDgQriqwWc+6j8mdVE37fQDQyfwgbCdj5XM=; b=etMNCuvt0uzioN7MJq081SPdRL8NX4YOILS2GtQ2QRBruN3Xd/MDhjYqVwL7/BuZcl PF9IJMtla+CRBQLhFbVLFBErdBZZreCs+k7cD348iRIFe/hXPphLjrC25UTRHmJbsEBQ Y5ZJ+5QSa3+ox9X+oyLyAGJuIxGhhCULJRg2T8wY7q2lCVVNGo7rG1QAuFgbNk0iW+F2 zZdpEGOnmW3oD0mfkmMWaMXkjjn4uhiCkgPE3rCUOrKi4FjYeyCXlmuSz9sTTZ6Ti8l8 Fwg/RCN465DERe3QJoOX5ul/Yxty+z2Cm6bWM6aPyOLJxX91o2mgsIpLn3pFV3Zkirat 5uCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WkT4cfQDKDgQriqwWc+6j8mdVE37fQDQyfwgbCdj5XM=; b=Qtbj0HCRMYLR1xOHq6n9/SnunNSiBtX7cNGvSkk3xrSSYSMmqv+gWrwkCn9HuwaoJy 3thZ/LRJVSpZ6+Z614ppWPZerlO48CCmPHi5jJTahdVz0e8qH/VfgkLglY9rH8OaNeiQ VSw57C1pF1ps121Yx5AD865QcsnkAvBBhNgPcxEQYU/Tx0hG3E7V1AD9rdp2buXEinMe uNHuZm7RgxsCTLU8XfO0OG6cU7M4i2fJpJfv1an6SKhMrU9QoEq9LIdeJiv+gcYAk0z3 Uu4NPIfFPOl2o4MWBFeD1h7DfDU83jWaO4pwSIEhyc7eIr+/38BRtNL3ZaFHe6Yjj4kX QEEw== X-Gm-Message-State: AJIora+pqjhDrH0gp9ulDml4B1vemE7UYHO/s2BUpvo8TGATIOviAIfW pd7eAgoK7sX5W2KoZhs/3+bCEA== X-Google-Smtp-Source: AGRyM1tXweBB4oshG2eCoAeOGjJLdt48rXejLcqNLC2hz6NERwcmVLQ/A4E9kstzW9zBhGDocNwDzA== X-Received: by 2002:a63:8849:0:b0:40d:e25:9fb2 with SMTP id l70-20020a638849000000b0040d0e259fb2mr25519396pgd.592.1656936507697; Mon, 04 Jul 2022 05:08:27 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id n4-20020a6546c4000000b0040c9df2b060sm20448482pgr.30.2022.07.04.05.08.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:27 -0700 (PDT) From: Viresh Kumar To: "Rafael J. Wysocki" , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , Stephen Boyd , Nishanth Menon , linux-kernel@vger.kernel.org Subject: [PATCH V3 06/20] cpufreq: ti: Migrate to dev_pm_opp_set_config() Date: Mon, 4 Jul 2022 17:37:44 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" The OPP core now provides a unified API for setting all configuration types, i.e. dev_pm_opp_set_config(). Lets start using it. Signed-off-by: Viresh Kumar --- drivers/cpufreq/ti-cpufreq.c | 37 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/drivers/cpufreq/ti-cpufreq.c b/drivers/cpufreq/ti-cpufreq.c index 560d67a6bef1..df85a77d476b 100644 --- a/drivers/cpufreq/ti-cpufreq.c +++ b/drivers/cpufreq/ti-cpufreq.c @@ -60,7 +60,6 @@ struct ti_cpufreq_data { struct device_node *opp_node; struct regmap *syscon; const struct ti_cpufreq_soc_data *soc_data; - struct opp_table *opp_table; }; =20 static unsigned long amx3_efuse_xlate(struct ti_cpufreq_data *opp_data, @@ -324,10 +323,13 @@ static int ti_cpufreq_probe(struct platform_device *p= dev) { u32 version[VERSION_COUNT]; const struct of_device_id *match; - struct opp_table *ti_opp_table; struct ti_cpufreq_data *opp_data; const char * const default_reg_names[] =3D {"vdd", "vbb", NULL}; int ret; + struct dev_pm_opp_config config =3D { + .supported_hw =3D version, + .supported_hw_count =3D ARRAY_SIZE(version), + }; =20 match =3D dev_get_platdata(&pdev->dev); if (!match) @@ -370,32 +372,21 @@ static int ti_cpufreq_probe(struct platform_device *p= dev) if (ret) goto fail_put_node; =20 - ti_opp_table =3D dev_pm_opp_set_supported_hw(opp_data->cpu_dev, - version, VERSION_COUNT); - if (IS_ERR(ti_opp_table)) { - dev_err(opp_data->cpu_dev, - "Failed to set supported hardware\n"); - ret =3D PTR_ERR(ti_opp_table); - goto fail_put_node; - } - - opp_data->opp_table =3D ti_opp_table; - if (opp_data->soc_data->multi_regulator) { - const char * const *reg_names =3D default_reg_names; - if (opp_data->soc_data->reg_names) - reg_names =3D opp_data->soc_data->reg_names; - ti_opp_table =3D dev_pm_opp_set_regulators(opp_data->cpu_dev, - reg_names); - if (IS_ERR(ti_opp_table)) { - dev_pm_opp_put_supported_hw(opp_data->opp_table); - ret =3D PTR_ERR(ti_opp_table); - goto fail_put_node; - } + config.regulator_names =3D opp_data->soc_data->reg_names; + else + config.regulator_names =3D default_reg_names; + } + + ret =3D dev_pm_opp_set_config(opp_data->cpu_dev, &config); + if (ret < 0) { + dev_err(opp_data->cpu_dev, "Failed to set OPP config\n"); + goto fail_put_node; } =20 of_node_put(opp_data->opp_node); + register_cpufreq_dt: platform_device_register_simple("cpufreq-dt", -1, NULL, 0); =20 --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 6D54DCCA479 for ; Mon, 4 Jul 2022 12:09:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234279AbiGDMJG (ORCPT ); Mon, 4 Jul 2022 08:09:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233970AbiGDMIl (ORCPT ); Mon, 4 Jul 2022 08:08:41 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3DC512089 for ; Mon, 4 Jul 2022 05:08:30 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id b2so8784482pfb.8 for ; Mon, 04 Jul 2022 05:08:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zM6k7wksuNvGlGq6D8pYCpU91RIfKXfSwe1O1batFpM=; b=Pk79kImAgR1NPXrXBciuZ0mSuzaxskitVfe4NlJ2XlyTl0xMFuwItkbbi0cprHg6PF O/koDJOxvLb0hVLFIl0DvA3UYks4ajZlwD4ysoMPfq7cLIuLD03ucdgN2W1XiBgARkHG 7XXdd4ID1CI9ykMAZaCXoaLOjf8pE4W2kR2G4bfMprveeyUOPvS4zKR2JCZdXUWp0n3M BvXSI4iI1+i9VJvp9SqVajDbKSPxAT9OjTUmp8X3DENT2hpcktHKFwRZLJaPWxNA4+VR L9qNGc7D7VVgeW0RoD4RKMKciIRAyKpnz//IV2y8FJuiSwgmInto+4iwU4jgt+Nejrp6 wPFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zM6k7wksuNvGlGq6D8pYCpU91RIfKXfSwe1O1batFpM=; b=hv8MdfPAwrLk/NeuZTDTTHTMzM8k1iF4lzmLCHtPuLRtoiTZjGANSHPqkhkFZhCTFh o6UeCg2UoCN2VwPKxhtMFtqBjj6btdz4KCoexSPEZ5R87hrPyHvoRkKtSYB3QFFuYAsi 6PXeRMt69xEPR3nLDJ5YT4ACcTLV1/XkVmKUgB2oQIedQl77LdCYkTr/3IAmtr+dRyDZ P0zKTGnKZkdCcOlswvv4tVcnlwlz6wbnNTWG1qMEH0sXJ46OOH+cNgs06FqY7jU9JeTD xr3BPjyBbZEfJW9LWetQHAx9OroJuy5V7EY9W1UF1SE/3Us8GlpZYxvjiIKxUvuZ6LRV nJOw== X-Gm-Message-State: AJIora9EA3XbR44fgPmnNGp+JEjFRlfNfP7GSD/jRAdzjCnKcxv1kq/t buzkIkD3sY0ewhT1F+87q70Pwg== X-Google-Smtp-Source: AGRyM1uqmJynJNrbJeDxw4sHqdMSf2eDgcVImaSFfyVb2XrpmBPc3tF3N1I5pjtaPgA1Xtm+BTaJ5Q== X-Received: by 2002:a65:6054:0:b0:411:5e12:21b2 with SMTP id a20-20020a656054000000b004115e1221b2mr24544781pgp.222.1656936510437; Mon, 04 Jul 2022 05:08:30 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id u2-20020a170902714200b0016a522915e5sm21089580plm.83.2022.07.04.05.08.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:30 -0700 (PDT) From: Viresh Kumar To: Qiang Yu Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Stephen Boyd , Nishanth Menon , dri-devel@lists.freedesktop.org, lima@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 07/20] drm/lima: Migrate to dev_pm_opp_set_config() Date: Mon, 4 Jul 2022 17:37:45 +0530 Message-Id: <734af371b2523219c719111be72d932dc3fd7eb9.1656935522.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" The OPP core now provides a unified API for setting all configuration types, i.e. dev_pm_opp_set_config(). Lets start using it. Signed-off-by: Viresh Kumar --- drivers/gpu/drm/lima/lima_devfreq.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/lima/lima_devfreq.c b/drivers/gpu/drm/lima/lim= a_devfreq.c index dc83c5421125..011be7ff51e1 100644 --- a/drivers/gpu/drm/lima/lima_devfreq.c +++ b/drivers/gpu/drm/lima/lima_devfreq.c @@ -112,6 +112,11 @@ int lima_devfreq_init(struct lima_device *ldev) unsigned long cur_freq; int ret; const char *regulator_names[] =3D { "mali", NULL }; + const char *clk_names[] =3D { "core", NULL }; + struct dev_pm_opp_config config =3D { + .regulator_names =3D regulator_names, + .clk_names =3D clk_names, + }; =20 if (!device_property_present(dev, "operating-points-v2")) /* Optional, continue without devfreq */ @@ -119,11 +124,7 @@ int lima_devfreq_init(struct lima_device *ldev) =20 spin_lock_init(&ldevfreq->lock); =20 - ret =3D devm_pm_opp_set_clkname(dev, "core"); - if (ret) - return ret; - - ret =3D devm_pm_opp_set_regulators(dev, regulator_names); + ret =3D devm_pm_opp_set_config(dev, &config); if (ret) { /* Continue if the optional regulator is missing */ if (ret !=3D -ENODEV) --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 7DA55C43334 for ; Mon, 4 Jul 2022 12:09:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234170AbiGDMJI (ORCPT ); Mon, 4 Jul 2022 08:09:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234026AbiGDMIn (ORCPT ); Mon, 4 Jul 2022 08:08:43 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D233120A0 for ; Mon, 4 Jul 2022 05:08:33 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id j1-20020a17090aeb0100b001ef777a7befso3022014pjz.0 for ; Mon, 04 Jul 2022 05:08:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MkV+K20z+SrLBFTmdhzZDzVO0y1dFuzDvpTTKeDqBqE=; b=i67LpLjm+RKEUcX9+AseN1xHAQF8gguDnDeVc16EdRZV3zXrM/xuJY3hhlgtLsx0ok T9jmkGkhFH/kfvg9VVtKDik3j4TEigCWm1J04DznjoQqilFMlH2CLx/D1otcfI23fNZl 6Hb5WzKGYHFNTs56dwxX0HlcVuEjUw8o2fiMf13exT+gHNf4Pp5wbyVZV5uCkrr2RK2n D2S1r9SEC+mObAnXYmZsKRpZ0qUYrOCqXt2gwl0mLWfNIiJNPFRa09F8+GvDYBirW9O2 sWJVYtrePJfMMCyUTCaaltaUK3NpNWLdEPdHNpiFXYDZk1HNFjRbabdRWkg/lbssqSnc 0fqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MkV+K20z+SrLBFTmdhzZDzVO0y1dFuzDvpTTKeDqBqE=; b=6/lQD2psuR2m2giOrpC4NNOcmLXFzaDxYttPMaGUf6ZdL5f2dL4HNWRtNzv1SGiybb 5aGrpzGBDws0lMoXQ5prU7WVbnzG3ct8xD4cyi4GzwKOOeEaVDBZv0ngBnTLuK5XQ/kS 91ZbOh72+PScMwNBG0lIOAXt69/MBWOAv8Fc3ZRT7GBzqK11VNUcpXljHFXDRJly74X2 3SxFyT5Lgnq+7IHWuacApzNfTw0PJQqSa1/meqqMZrCzvEp5bBdoWwIzOqyzFLsEVWcO AieyBkHGybzTjDgOqL2GfzY27N8nMC1cWiVBLY3soX1Rh3aYMsCW7nMyD0U+/WXL0NYl 0siA== X-Gm-Message-State: AJIora+pUM+3uIPVxJRLnwGiIMAA1M1uZUpxN/v+vGJBOAUJ3OPgY3D9 baK7KHEL8/r/yszUwVm7bCRIXw== X-Google-Smtp-Source: AGRyM1uSBj2VWwaqLWtNB6ZoVvhK4MFRceFAZjuhKW7adcehXBDxa0PbgVVv7V2mcOW2hlDSqUbQrA== X-Received: by 2002:a17:90b:1807:b0:1ef:8aa5:1158 with SMTP id lw7-20020a17090b180700b001ef8aa51158mr4472242pjb.163.1656936513213; Mon, 04 Jul 2022 05:08:33 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id s22-20020a17090aba1600b001ec71be4145sm12468028pjr.2.2022.07.04.05.08.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:32 -0700 (PDT) From: Viresh Kumar To: Thierry Reding , Jonathan Hunter Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Stephen Boyd , Nishanth Menon , Dmitry Osipenko , linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 08/20] soc/tegra: Add comment over devm_pm_opp_set_clkname() Date: Mon, 4 Jul 2022 17:37:46 +0530 Message-Id: <2f93b66f785b91c720aacd3cdb152fbf1e375141.1656935522.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" Explain why special handling was required here, it isn't obvious at all. Tested-by: Dmitry Osipenko Signed-off-by: Viresh Kumar --- drivers/soc/tegra/common.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/soc/tegra/common.c b/drivers/soc/tegra/common.c index 32c346b72635..9f3fdeb1a11c 100644 --- a/drivers/soc/tegra/common.c +++ b/drivers/soc/tegra/common.c @@ -108,6 +108,13 @@ int devm_tegra_core_dev_init_opp_table(struct device *= dev, u32 hw_version; int err; =20 + /* + * For some devices we don't have any OPP table in the DT, and in order + * to use the same code path for all the devices, we create a dummy OPP + * table for them via this call. The dummy OPP table is only capable of + * doing clk_set_rate() on invocation of dev_pm_opp_set_rate() and + * doesn't provide any other functionality. + */ err =3D devm_pm_opp_set_clkname(dev, NULL); if (err) { dev_err(dev, "failed to set OPP clk: %d\n", err); --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 A592DC43334 for ; Mon, 4 Jul 2022 12:09:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234227AbiGDMJX (ORCPT ); Mon, 4 Jul 2022 08:09:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234086AbiGDMIx (ORCPT ); Mon, 4 Jul 2022 08:08:53 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99AD2120AC for ; Mon, 4 Jul 2022 05:08:36 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id c13so4659334pla.6 for ; Mon, 04 Jul 2022 05:08:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hg/cFplgKXasJmWL+OFLUAPfuBDqHR87rTqNltqJyMU=; b=ElYiOdMFeX2LZAKxIHfhmm1VperaY/9hCjNtv0uXfVRA0MR/4Z1dW/TIwohfrdw3zC 5yfNElWqi+ZQlyMt+gGiAvZhYKw/Qjl+f5o1xzJhRefBDuQvvdic6QE1KRHBtfZDrYq+ kfUyRZc4DUd3bZkNdymAucZQfbpm0h1ACBK2Z5S8AhKsxqbd5eFk1viVsmsVnDlDx5eH 4J6owN15WJFuyS3PC/E8cdgenGdfMDjDrhwo1QhKvN2Kh0IfS0hV1Q3kGYlfXl25rmpT tlpSI2LOACnib5AbqMi39qPjHs14KXoEln8otF+FZc4hWZTDlAWv01YhvO2Wv6wlp9wt zloA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hg/cFplgKXasJmWL+OFLUAPfuBDqHR87rTqNltqJyMU=; b=FCdVIg53RFYn+AGNRaC/eQuvCeRc02SnPrvoHf1qmQy1+B9D8C0UwdpqlqgQ19Olnv g2SeR8F1bIjIjv6AFrNNWk4nCGmV8e+vg5XeL0Rtor0qNNes9VHg04pu2YI4HGO/RUZF w+V8gp4n/gG7PVjhwt+rzFHsKOCUEGKkDj8bIwQXqodVuA14/n5Sb0W6+FpYP6utt1jj RdzfgViL3WIeI6UY5Hqzbk2YFGZAR84VQKexRApWIDO2AKrPZjnY4FmPFZcEy2Rt/EUv 0ueF2Mq2SLbmrGG/IYfdWiPZ5etv0De+zdeVC+Eh2oVInmXK6Mm8xEPjmldrGK1MaDZk lUoA== X-Gm-Message-State: AJIora8AmaP7uhHFaD2X+PcH4KDKQn2qCcknys8HxzJbhDhW0AYnrRed S3JuErWSSFc/FCNpxp0saEHA4w== X-Google-Smtp-Source: AGRyM1tmSfyZts2TP1rVRGtt0oK5UlDreVoEDBr/wzXwSWigCPZMlz1k0k1jEryIK+AZtd70GDM/Rg== X-Received: by 2002:a17:90b:1488:b0:1ef:82bb:5f08 with SMTP id js8-20020a17090b148800b001ef82bb5f08mr8737098pjb.214.1656936516144; Mon, 04 Jul 2022 05:08:36 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id g189-20020a6252c6000000b0052833322760sm6584054pfb.187.2022.07.04.05.08.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:35 -0700 (PDT) From: Viresh Kumar To: Thierry Reding , Jonathan Hunter Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Stephen Boyd , Nishanth Menon , Dmitry Osipenko , linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 09/20] soc/tegra: Migrate to dev_pm_opp_set_config() Date: Mon, 4 Jul 2022 17:37:47 +0530 Message-Id: <640201fa0191b27902f92db1cbbda1c74c7befb8.1656935522.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" The OPP core now provides a unified API for setting all configuration types, i.e. dev_pm_opp_set_config(). Lets start using it. Tested-by: Dmitry Osipenko Signed-off-by: Viresh Kumar --- drivers/soc/tegra/common.c | 52 +++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/drivers/soc/tegra/common.c b/drivers/soc/tegra/common.c index 9f3fdeb1a11c..dff6d5ef4e46 100644 --- a/drivers/soc/tegra/common.c +++ b/drivers/soc/tegra/common.c @@ -107,36 +107,46 @@ int devm_tegra_core_dev_init_opp_table(struct device = *dev, { u32 hw_version; int err; - /* - * For some devices we don't have any OPP table in the DT, and in order - * to use the same code path for all the devices, we create a dummy OPP - * table for them via this call. The dummy OPP table is only capable of - * doing clk_set_rate() on invocation of dev_pm_opp_set_rate() and - * doesn't provide any other functionality. + * The clk's connection id to set is NULL and this is a NULL terminated + * array, hence two NULL entries. */ - err =3D devm_pm_opp_set_clkname(dev, NULL); - if (err) { - dev_err(dev, "failed to set OPP clk: %d\n", err); - return err; - } - - /* Tegra114+ doesn't support OPP yet */ - if (!of_machine_is_compatible("nvidia,tegra20") && - !of_machine_is_compatible("nvidia,tegra30")) - return -ENODEV; - - if (of_machine_is_compatible("nvidia,tegra20")) + const char *clk_names[] =3D { NULL, NULL }; + struct dev_pm_opp_config config =3D { + /* + * For some devices we don't have any OPP table in the DT, and + * in order to use the same code path for all the devices, we + * create a dummy OPP table for them via this. The dummy OPP + * table is only capable of doing clk_set_rate() on invocation + * of dev_pm_opp_set_rate() and doesn't provide any other + * functionality. + */ + .clk_names =3D clk_names, + }; + + if (of_machine_is_compatible("nvidia,tegra20")) { hw_version =3D BIT(tegra_sku_info.soc_process_id); - else + config.supported_hw =3D &hw_version; + config.supported_hw_count =3D 1; + } else if (of_machine_is_compatible("nvidia,tegra30")) { hw_version =3D BIT(tegra_sku_info.soc_speedo_id); + config.supported_hw =3D &hw_version; + config.supported_hw_count =3D 1; + } =20 - err =3D devm_pm_opp_set_supported_hw(dev, &hw_version, 1); + err =3D devm_pm_opp_set_config(dev, &config); if (err) { - dev_err(dev, "failed to set OPP supported HW: %d\n", err); + dev_err(dev, "failed to set OPP config: %d\n", err); return err; } =20 + /* + * Tegra114+ doesn't support OPP yet, return early for non tegra20/30 + * case. + */ + if (!config.supported_hw) + return -ENODEV; + /* * Older device-trees have an empty OPP table, we will get * -ENODEV from devm_pm_opp_of_add_table() in this case. --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 C8191CCA47C for ; Mon, 4 Jul 2022 12:09:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234336AbiGDMJ0 (ORCPT ); Mon, 4 Jul 2022 08:09:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234239AbiGDMI4 (ORCPT ); Mon, 4 Jul 2022 08:08:56 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3790218A for ; Mon, 4 Jul 2022 05:08:39 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id c13so4659441pla.6 for ; Mon, 04 Jul 2022 05:08:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gC67fAeym71rEkFE9k+oqzY1p3FNiw9zFdZR8va6dpY=; b=Pml5WBPxzc1XEVvLTl/1ecRTpGQ07MA7iG8JyddspRVnPUQwLWFmlJQftSxz63Yxza K/GZWSVVmo2hxQsLGAap3J5G/2M4hNoblfZzpKMNGBodMzTorddM7t170hRgv1w4lmtg S2jdLbuWRGg/F5wsQMSdJM24vBhopvX9UNO40jOdGxaYYPSDEJJ5U/myb/5tbHsidLX9 e7+vnKrVOLwGubQi+FJLwBxPtvWwoEv2MMT0SRw3NRtnPitqQ5rFabe3y+qSVe/lCf/G lUjN5UKK5YebywPhB9hnEYQWwHqeuChDYfkYR0Yc56F3Yw3rGbqdjBhh0mGyzY+orwut HFkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gC67fAeym71rEkFE9k+oqzY1p3FNiw9zFdZR8va6dpY=; b=endBQmxj0fFYMjCnsFKV1AWMMJTBrAZ41r0v26ntpq3b77JHh6CfSO27ncPcyfPFSz u+oQjHh+0I/SmvySHjMgu1+PakY45OsY4R2fDmSewYMqCO0ty0295RkqzlC50sgYQepy JKvlMyA8uVQogtg9p5GfMLiNtPQ2G/XC8i0p31gixEDxjxKiricEak86uzpdiftcl6tF 1mE392Ae1dHenc5U3GpkVdPsgRYKuui9Y9qXY4sphjMHCvrrMXnCZzW//ZaKisrukJqX FAFUflUrgHnhCo5nxpvrBFqtJVeRDaZIcnmIarKfSL95oKDCUI6B9f+rz7y8JNkOmHwY 8ylA== X-Gm-Message-State: AJIora/Vo3B7Z6T2LerhEBigxfgFd3PnzfALeF8/OisMWYJ24B59kxbZ 3BHfGMNM9YZObwve1+Bqequ4Qw== X-Google-Smtp-Source: AGRyM1s+vQ3aYmJZ6251w1IjsHZYQ2vqP9sfRwH11QyT+Pb7osqxW45+tzLdW7RxYOIhMU62h93xoA== X-Received: by 2002:a17:90b:17cb:b0:1ec:9d52:46f7 with SMTP id me11-20020a17090b17cb00b001ec9d5246f7mr34220040pjb.221.1656936519213; Mon, 04 Jul 2022 05:08:39 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id m11-20020a170902768b00b001637997d0d4sm20922989pll.206.2022.07.04.05.08.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:38 -0700 (PDT) From: Viresh Kumar To: "Rafael J. Wysocki" , Viresh Kumar , Chanwoo Choi , MyungJoo Ham , Kyungmin Park , Krzysztof Kozlowski , Alim Akhtar , Nishanth Menon , Stephen Boyd Cc: linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH V3 10/20] OPP: Migrate set-regulators API to use set-config helpers Date: Mon, 4 Jul 2022 17:37:48 +0530 Message-Id: <57b3f53e71550be92e28f4e2fa619f93bb5f3d78.1656935522.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" Now that we have a central API to handle all OPP table configurations, migrate the set-regulators family of helpers to use the new infrastructure. The return type and parameter to the APIs change a bit due to this, update the current users as well in the same commit in order to avoid breaking builds. Signed-off-by: Viresh Kumar Reviewed-by: Chanwoo Choi --- drivers/cpufreq/cpufreq-dt.c | 12 ++--- drivers/devfreq/exynos-bus.c | 19 +++----- drivers/opp/core.c | 91 ++++++++---------------------------- include/linux/pm_opp.h | 44 ++++++++++------- 4 files changed, 60 insertions(+), 106 deletions(-) diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c index be0c19b3ffa5..d69d13a26414 100644 --- a/drivers/cpufreq/cpufreq-dt.c +++ b/drivers/cpufreq/cpufreq-dt.c @@ -29,9 +29,9 @@ struct private_data { =20 cpumask_var_t cpus; struct device *cpu_dev; - struct opp_table *opp_table; struct cpufreq_frequency_table *freq_table; bool have_static_opps; + int opp_token; }; =20 static LIST_HEAD(priv_list); @@ -220,9 +220,9 @@ static int dt_cpufreq_early_init(struct device *dev, in= t cpu) */ reg_name[0] =3D find_supply_name(cpu_dev); if (reg_name[0]) { - priv->opp_table =3D dev_pm_opp_set_regulators(cpu_dev, reg_name); - if (IS_ERR(priv->opp_table)) { - ret =3D PTR_ERR(priv->opp_table); + priv->opp_token =3D dev_pm_opp_set_regulators(cpu_dev, reg_name); + if (priv->opp_token < 0) { + ret =3D priv->opp_token; if (ret !=3D -EPROBE_DEFER) dev_err(cpu_dev, "failed to set regulators: %d\n", ret); @@ -294,7 +294,7 @@ static int dt_cpufreq_early_init(struct device *dev, in= t cpu) out: if (priv->have_static_opps) dev_pm_opp_of_cpumask_remove_table(priv->cpus); - dev_pm_opp_put_regulators(priv->opp_table); + dev_pm_opp_put_regulators(priv->opp_token); free_cpumask: free_cpumask_var(priv->cpus); return ret; @@ -308,7 +308,7 @@ static void dt_cpufreq_release(void) dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &priv->freq_table); if (priv->have_static_opps) dev_pm_opp_of_cpumask_remove_table(priv->cpus); - dev_pm_opp_put_regulators(priv->opp_table); + dev_pm_opp_put_regulators(priv->opp_token); free_cpumask_var(priv->cpus); list_del(&priv->node); } diff --git a/drivers/devfreq/exynos-bus.c b/drivers/devfreq/exynos-bus.c index 541baff93ee8..d1235242367f 100644 --- a/drivers/devfreq/exynos-bus.c +++ b/drivers/devfreq/exynos-bus.c @@ -33,7 +33,7 @@ struct exynos_bus { =20 unsigned long curr_freq; =20 - struct opp_table *opp_table; + int opp_token; struct clk *clk; unsigned int ratio; }; @@ -161,8 +161,7 @@ static void exynos_bus_exit(struct device *dev) =20 dev_pm_opp_of_remove_table(dev); clk_disable_unprepare(bus->clk); - dev_pm_opp_put_regulators(bus->opp_table); - bus->opp_table =3D NULL; + dev_pm_opp_put_regulators(bus->opp_token); } =20 static void exynos_bus_passive_exit(struct device *dev) @@ -179,18 +178,16 @@ static int exynos_bus_parent_parse_of(struct device_n= ode *np, struct exynos_bus *bus) { struct device *dev =3D bus->dev; - struct opp_table *opp_table; const char *supplies[] =3D { "vdd", NULL }; int i, ret, count, size; =20 - opp_table =3D dev_pm_opp_set_regulators(dev, supplies); - if (IS_ERR(opp_table)) { - ret =3D PTR_ERR(opp_table); + ret =3D dev_pm_opp_set_regulators(dev, supplies); + if (ret < 0) { dev_err(dev, "failed to set regulators %d\n", ret); return ret; } =20 - bus->opp_table =3D opp_table; + bus->opp_token =3D ret; =20 /* * Get the devfreq-event devices to get the current utilization of @@ -236,8 +233,7 @@ static int exynos_bus_parent_parse_of(struct device_nod= e *np, return 0; =20 err_regulator: - dev_pm_opp_put_regulators(bus->opp_table); - bus->opp_table =3D NULL; + dev_pm_opp_put_regulators(bus->opp_token); =20 return ret; } @@ -459,8 +455,7 @@ static int exynos_bus_probe(struct platform_device *pde= v) dev_pm_opp_of_remove_table(dev); clk_disable_unprepare(bus->clk); err_reg: - dev_pm_opp_put_regulators(bus->opp_table); - bus->opp_table =3D NULL; + dev_pm_opp_put_regulators(bus->opp_token); =20 return ret; } diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 7ab20c3b91ed..6ff9b5b69d07 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -991,8 +991,8 @@ static int _set_opp_custom(const struct opp_table *opp_= table, int size; =20 /* - * We support this only if dev_pm_opp_set_regulators() was called - * earlier. + * We support this only if dev_pm_opp_set_config() was called + * earlier to set regulators. */ if (opp_table->sod_supplies) { size =3D sizeof(*old_opp->supplies) * opp_table->regulator_count; @@ -2097,7 +2097,7 @@ void dev_pm_opp_put_prop_name(struct opp_table *opp_t= able) EXPORT_SYMBOL_GPL(dev_pm_opp_put_prop_name); =20 /** - * dev_pm_opp_set_regulators() - Set regulator names for the device + * _opp_set_regulators() - Set regulator names for the device * @dev: Device for which regulator name is being set. * @names: Array of pointers to the names of the regulator. * @count: Number of regulators. @@ -2108,12 +2108,11 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_put_prop_name); * * This must be called before any OPPs are initialized for the device. */ -struct opp_table *dev_pm_opp_set_regulators(struct device *dev, - const char * const names[]) +static int _opp_set_regulators(struct opp_table *opp_table, struct device = *dev, + const char * const names[]) { struct dev_pm_opp_supply *supplies; const char * const *temp =3D names; - struct opp_table *opp_table; struct regulator *reg; int count =3D 0, ret, i; =20 @@ -2122,29 +2121,17 @@ struct opp_table *dev_pm_opp_set_regulators(struct = device *dev, count++; =20 if (!count) - return ERR_PTR(-EINVAL); - - opp_table =3D _add_opp_table(dev, false); - if (IS_ERR(opp_table)) - return opp_table; - - /* This should be called before OPPs are initialized */ - if (WARN_ON(!list_empty(&opp_table->opp_list))) { - ret =3D -EBUSY; - goto err; - } + return -EINVAL; =20 /* Another CPU that shares the OPP table has set the regulators ? */ if (opp_table->regulators) - return opp_table; + return 0; =20 opp_table->regulators =3D kmalloc_array(count, sizeof(*opp_table->regulators), GFP_KERNEL); - if (!opp_table->regulators) { - ret =3D -ENOMEM; - goto err; - } + if (!opp_table->regulators) + return -ENOMEM; =20 for (i =3D 0; i < count; i++) { reg =3D regulator_get_optional(dev, names[i]); @@ -2174,7 +2161,7 @@ struct opp_table *dev_pm_opp_set_regulators(struct de= vice *dev, } mutex_unlock(&opp_table->lock); =20 - return opp_table; + return 0; =20 free_regulators: while (i !=3D 0) @@ -2183,26 +2170,20 @@ struct opp_table *dev_pm_opp_set_regulators(struct = device *dev, kfree(opp_table->regulators); opp_table->regulators =3D NULL; opp_table->regulator_count =3D -1; -err: - dev_pm_opp_put_opp_table(opp_table); =20 - return ERR_PTR(ret); + return ret; } -EXPORT_SYMBOL_GPL(dev_pm_opp_set_regulators); =20 /** - * dev_pm_opp_put_regulators() - Releases resources blocked for regulator - * @opp_table: OPP table returned from dev_pm_opp_set_regulators(). + * _opp_put_regulators() - Releases resources blocked for regulator + * @opp_table: OPP table returned from _opp_set_regulators(). */ -void dev_pm_opp_put_regulators(struct opp_table *opp_table) +static void _opp_put_regulators(struct opp_table *opp_table) { int i; =20 - if (unlikely(!opp_table)) - return; - if (!opp_table->regulators) - goto put_opp_table; + return; =20 if (opp_table->enabled) { for (i =3D opp_table->regulator_count - 1; i >=3D 0; i--) @@ -2225,40 +2206,7 @@ void dev_pm_opp_put_regulators(struct opp_table *opp= _table) kfree(opp_table->regulators); opp_table->regulators =3D NULL; opp_table->regulator_count =3D -1; - -put_opp_table: - dev_pm_opp_put_opp_table(opp_table); -} -EXPORT_SYMBOL_GPL(dev_pm_opp_put_regulators); - -static void devm_pm_opp_regulators_release(void *data) -{ - dev_pm_opp_put_regulators(data); -} - -/** - * devm_pm_opp_set_regulators() - Set regulator names for the device - * @dev: Device for which regulator name is being set. - * @names: Array of pointers to the names of the regulator. - * @count: Number of regulators. - * - * This is a resource-managed variant of dev_pm_opp_set_regulators(). - * - * Return: 0 on success and errorno otherwise. - */ -int devm_pm_opp_set_regulators(struct device *dev, - const char * const names[]) -{ - struct opp_table *opp_table; - - opp_table =3D dev_pm_opp_set_regulators(dev, names); - if (IS_ERR(opp_table)) - return PTR_ERR(opp_table); - - return devm_add_action_or_reset(dev, devm_pm_opp_regulators_release, - opp_table); } -EXPORT_SYMBOL_GPL(devm_pm_opp_set_regulators); =20 /** * dev_pm_opp_set_clkname() - Set clk name for the device @@ -2633,7 +2581,7 @@ static void _opp_clear_config(struct opp_config_data = *data) if (data->flags & OPP_CONFIG_GENPD) dev_pm_opp_detach_genpd(data->opp_table); if (data->flags & OPP_CONFIG_REGULATOR) - dev_pm_opp_put_regulators(data->opp_table); + _opp_put_regulators(data->opp_table); if (data->flags & OPP_CONFIG_SUPPORTED_HW) dev_pm_opp_put_supported_hw(data->opp_table); if (data->flags & OPP_CONFIG_REGULATOR_HELPER) @@ -2758,11 +2706,10 @@ int dev_pm_opp_set_config(struct device *dev, struc= t dev_pm_opp_config *config) =20 /* Configure supplies */ if (config->regulator_names) { - err =3D dev_pm_opp_set_regulators(dev, config->regulator_names); - if (IS_ERR(err)) { - ret =3D PTR_ERR(err); + ret =3D _opp_set_regulators(opp_table, dev, + config->regulator_names); + if (ret) goto err; - } =20 data->flags |=3D OPP_CONFIG_REGULATOR; } diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index a08f9481efb3..f014bd172c99 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -189,9 +189,6 @@ void dev_pm_opp_put_supported_hw(struct opp_table *opp_= table); int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, = unsigned int count); struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char = *name); void dev_pm_opp_put_prop_name(struct opp_table *opp_table); -struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char= * const names[]); -void dev_pm_opp_put_regulators(struct opp_table *opp_table); -int devm_pm_opp_set_regulators(struct device *dev, const char * const name= s[]); struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *n= ame); void dev_pm_opp_put_clkname(struct opp_table *opp_table); int devm_pm_opp_set_clkname(struct device *dev, const char *name); @@ -409,19 +406,6 @@ static inline struct opp_table *dev_pm_opp_set_prop_na= me(struct device *dev, con =20 static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {} =20 -static inline struct opp_table *dev_pm_opp_set_regulators(struct device *d= ev, const char * const names[]) -{ - return ERR_PTR(-EOPNOTSUPP); -} - -static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) = {} - -static inline int devm_pm_opp_set_regulators(struct device *dev, - const char * const names[]) -{ - return -EOPNOTSUPP; -} - static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev,= const char *name) { return ERR_PTR(-EOPNOTSUPP); @@ -606,4 +590,32 @@ static inline int dev_pm_opp_of_find_icc_paths(struct = device *dev, struct opp_ta } #endif =20 +/* OPP Configuration helpers */ + +/* Regulators helpers */ +static inline int dev_pm_opp_set_regulators(struct device *dev, + const char * const names[]) +{ + struct dev_pm_opp_config config =3D { + .regulator_names =3D names, + }; + + return dev_pm_opp_set_config(dev, &config); +} + +static inline void dev_pm_opp_put_regulators(int token) +{ + dev_pm_opp_clear_config(token); +} + +static inline int devm_pm_opp_set_regulators(struct device *dev, + const char * const names[]) +{ + struct dev_pm_opp_config config =3D { + .regulator_names =3D names, + }; + + return devm_pm_opp_set_config(dev, &config); +} + #endif /* __LINUX_OPP_H__ */ --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 30AC6C43334 for ; Mon, 4 Jul 2022 12:09:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234349AbiGDMJk (ORCPT ); Mon, 4 Jul 2022 08:09:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234020AbiGDMJA (ORCPT ); Mon, 4 Jul 2022 08:09:00 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14CB912603 for ; Mon, 4 Jul 2022 05:08:42 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id o31-20020a17090a0a2200b001ef7bd037bbso4075780pjo.0 for ; Mon, 04 Jul 2022 05:08:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5/9TsfHubVBv9DY1BppOPOwd/HnEouHrujq83/2ruNg=; b=xmkenxa4Ac/ERNHJnlrShcfIHGlT6j3H0Agxofs36a8AA62Q5HdxwpAu+uPQDyweLN fXfG/3pO26jJbcbpI9UARobDLLQAhXzG9scFa6V10+JWHo3vnnnB8PbCDWRx3J4DhoUB i+LUJrFjicOca45jAvMueSVh/d5jydDxvGnPbmAF31GNQKQjIijfvRfiEeQl1OKpyYeL ixJgjc/fujsGZr9npzSQPLyNYM8ZecgEtkkrHuSRmgPTg7KSOqbLPKuKD1s5uPU6BAol aDee493mfYAPCPZGrdbjc/rm54KfmZ5ewxg3yFCU5DvhuO5o0+bYjM0hZAj3M7kXuxvS 3+yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5/9TsfHubVBv9DY1BppOPOwd/HnEouHrujq83/2ruNg=; b=BlehLd/gmhuHydBV+5QcxA9ggPtHZsoZ310Bnj6pQW6efk3Ml+3jyMvyQMDqkHx46D wr2jXfM7w0yqYw2aRd/CA4ZHu3qJ1dEFpjfnzG4nB4XKac0i+/oBhApCyiYvZh2XzMpZ z/Bii+WFs3VMu2tlfLcoAe81NVDQDNM32R43iHkAW7WtzC+dpVuL8Ejsn13JFaWwZtRX 20ZtvudrMCb94GcuAMsSLlRVKySOibN8VO9n/JdDqRoJZiQMhQqSvcNU7oNcZ42nKLtP idlM7gXlstMKDldfH5Q+KRqCocQ4xOX0Hbb9CtJCYqCmYAtKz2YwgLiOGuiwywgnJYPU 41MQ== X-Gm-Message-State: AJIora/vQMwEIcaXmP+TntIXIh8e6UIopf2gp5gBI8xfYXeP4elyR0U4 Zj+ohwqVMisbLX/rlfmcCXi7VQ== X-Google-Smtp-Source: AGRyM1tzoP2BrzAF0O9+mDmKNI6HEzcfmUZRSOi26/yUuVYzHS04jmRMOv3hDjlx8wp27beJnNXtPw== X-Received: by 2002:a17:902:e844:b0:16a:32d9:722c with SMTP id t4-20020a170902e84400b0016a32d9722cmr35010927plg.40.1656936522271; Mon, 04 Jul 2022 05:08:42 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b0016a38fa3f95sm20997613plk.118.2022.07.04.05.08.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:42 -0700 (PDT) From: Viresh Kumar To: "Rafael J. Wysocki" , Viresh Kumar , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Thierry Reding , Jonathan Hunter , Krzysztof Kozlowski , Nishanth Menon , Stephen Boyd Cc: linux-pm@vger.kernel.org, Vincent Guittot , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH V3 11/20] OPP: Migrate set-supported-hw API to use set-config helpers Date: Mon, 4 Jul 2022 17:37:49 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" Now that we have a central API to handle all OPP table configurations, migrate the set-supported-hw family of helpers to use the new infrastructure. The return type and parameter to the APIs change a bit due to this, update the current users as well in the same commit in order to avoid breaking builds. Signed-off-by: Viresh Kumar --- drivers/cpufreq/imx-cpufreq-dt.c | 12 ++-- drivers/cpufreq/tegra20-cpufreq.c | 12 ++-- drivers/memory/tegra/tegra124-emc.c | 11 ++-- drivers/opp/core.c | 87 +++++++---------------------- include/linux/pm_opp.h | 49 +++++++++------- 5 files changed, 66 insertions(+), 105 deletions(-) diff --git a/drivers/cpufreq/imx-cpufreq-dt.c b/drivers/cpufreq/imx-cpufreq= -dt.c index 3fe9125156b4..76e553af2071 100644 --- a/drivers/cpufreq/imx-cpufreq-dt.c +++ b/drivers/cpufreq/imx-cpufreq-dt.c @@ -31,8 +31,8 @@ =20 /* cpufreq-dt device registered by imx-cpufreq-dt */ static struct platform_device *cpufreq_dt_pdev; -static struct opp_table *cpufreq_opp_table; static struct device *cpu_dev; +static int cpufreq_opp_token; =20 enum IMX7ULP_CPUFREQ_CLKS { ARM, @@ -153,9 +153,9 @@ static int imx_cpufreq_dt_probe(struct platform_device = *pdev) dev_info(&pdev->dev, "cpu speed grade %d mkt segment %d supported-hw %#x = %#x\n", speed_grade, mkt_segment, supported_hw[0], supported_hw[1]); =20 - cpufreq_opp_table =3D dev_pm_opp_set_supported_hw(cpu_dev, supported_hw, = 2); - if (IS_ERR(cpufreq_opp_table)) { - ret =3D PTR_ERR(cpufreq_opp_table); + cpufreq_opp_token =3D dev_pm_opp_set_supported_hw(cpu_dev, supported_hw, = 2); + if (cpufreq_opp_token < 0) { + ret =3D cpufreq_opp_token; dev_err(&pdev->dev, "Failed to set supported opp: %d\n", ret); return ret; } @@ -163,7 +163,7 @@ static int imx_cpufreq_dt_probe(struct platform_device = *pdev) cpufreq_dt_pdev =3D platform_device_register_data( &pdev->dev, "cpufreq-dt", -1, NULL, 0); if (IS_ERR(cpufreq_dt_pdev)) { - dev_pm_opp_put_supported_hw(cpufreq_opp_table); + dev_pm_opp_put_supported_hw(cpufreq_opp_token); ret =3D PTR_ERR(cpufreq_dt_pdev); dev_err(&pdev->dev, "Failed to register cpufreq-dt: %d\n", ret); return ret; @@ -176,7 +176,7 @@ static int imx_cpufreq_dt_remove(struct platform_device= *pdev) { platform_device_unregister(cpufreq_dt_pdev); if (!of_machine_is_compatible("fsl,imx7ulp")) - dev_pm_opp_put_supported_hw(cpufreq_opp_table); + dev_pm_opp_put_supported_hw(cpufreq_opp_token); else clk_bulk_put(ARRAY_SIZE(imx7ulp_clks), imx7ulp_clks); =20 diff --git a/drivers/cpufreq/tegra20-cpufreq.c b/drivers/cpufreq/tegra20-cp= ufreq.c index e8db3d75be25..ab7ac7df9e62 100644 --- a/drivers/cpufreq/tegra20-cpufreq.c +++ b/drivers/cpufreq/tegra20-cpufreq.c @@ -32,9 +32,9 @@ static bool cpu0_node_has_opp_v2_prop(void) return ret; } =20 -static void tegra20_cpufreq_put_supported_hw(void *opp_table) +static void tegra20_cpufreq_put_supported_hw(void *opp_token) { - dev_pm_opp_put_supported_hw(opp_table); + dev_pm_opp_put_supported_hw((unsigned long) opp_token); } =20 static void tegra20_cpufreq_dt_unregister(void *cpufreq_dt) @@ -45,7 +45,6 @@ static void tegra20_cpufreq_dt_unregister(void *cpufreq_d= t) static int tegra20_cpufreq_probe(struct platform_device *pdev) { struct platform_device *cpufreq_dt; - struct opp_table *opp_table; struct device *cpu_dev; u32 versions[2]; int err; @@ -71,16 +70,15 @@ static int tegra20_cpufreq_probe(struct platform_device= *pdev) if (WARN_ON(!cpu_dev)) return -ENODEV; =20 - opp_table =3D dev_pm_opp_set_supported_hw(cpu_dev, versions, 2); - err =3D PTR_ERR_OR_ZERO(opp_table); - if (err) { + err =3D dev_pm_opp_set_supported_hw(cpu_dev, versions, 2); + if (err < 0) { dev_err(&pdev->dev, "failed to set supported hw: %d\n", err); return err; } =20 err =3D devm_add_action_or_reset(&pdev->dev, tegra20_cpufreq_put_supported_hw, - opp_table); + (void *)((unsigned long) err)); if (err) return err; =20 diff --git a/drivers/memory/tegra/tegra124-emc.c b/drivers/memory/tegra/teg= ra124-emc.c index 908f8d5392b2..85bc936c02f9 100644 --- a/drivers/memory/tegra/tegra124-emc.c +++ b/drivers/memory/tegra/tegra124-emc.c @@ -1395,15 +1395,14 @@ static int tegra_emc_interconnect_init(struct tegra= _emc *emc) static int tegra_emc_opp_table_init(struct tegra_emc *emc) { u32 hw_version =3D BIT(tegra_sku_info.soc_speedo_id); - struct opp_table *hw_opp_table; - int err; + int opp_token, err; =20 - hw_opp_table =3D dev_pm_opp_set_supported_hw(emc->dev, &hw_version, 1); - err =3D PTR_ERR_OR_ZERO(hw_opp_table); - if (err) { + err =3D dev_pm_opp_set_supported_hw(emc->dev, &hw_version, 1); + if (err < 0) { dev_err(emc->dev, "failed to set OPP supported HW: %d\n", err); return err; } + opp_token =3D err; =20 err =3D dev_pm_opp_of_add_table(emc->dev); if (err) { @@ -1430,7 +1429,7 @@ static int tegra_emc_opp_table_init(struct tegra_emc = *emc) remove_table: dev_pm_opp_of_remove_table(emc->dev); put_hw_table: - dev_pm_opp_put_supported_hw(hw_opp_table); + dev_pm_opp_put_supported_hw(opp_token); =20 return err; } diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 6ff9b5b69d07..8dbdfff38973 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1952,7 +1952,7 @@ int _opp_add_v1(struct opp_table *opp_table, struct d= evice *dev, } =20 /** - * dev_pm_opp_set_supported_hw() - Set supported platforms + * _opp_set_supported_hw() - Set supported platforms * @dev: Device for which supported-hw has to be set. * @versions: Array of hierarchy of versions to match. * @count: Number of elements in the array. @@ -1962,84 +1962,39 @@ int _opp_add_v1(struct opp_table *opp_table, struct= device *dev, * OPPs, which are available for those versions, based on its 'opp-support= ed-hw' * property. */ -struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, - const u32 *versions, unsigned int count) +static int _opp_set_supported_hw(struct opp_table *opp_table, + const u32 *versions, unsigned int count) { - struct opp_table *opp_table; - - opp_table =3D _add_opp_table(dev, false); - if (IS_ERR(opp_table)) - return opp_table; - - /* Make sure there are no concurrent readers while updating opp_table */ - WARN_ON(!list_empty(&opp_table->opp_list)); - /* Another CPU that shares the OPP table has set the property ? */ if (opp_table->supported_hw) - return opp_table; + return 0; =20 opp_table->supported_hw =3D kmemdup(versions, count * sizeof(*versions), GFP_KERNEL); - if (!opp_table->supported_hw) { - dev_pm_opp_put_opp_table(opp_table); - return ERR_PTR(-ENOMEM); - } + if (!opp_table->supported_hw) + return -ENOMEM; =20 opp_table->supported_hw_count =3D count; =20 - return opp_table; + return 0; } -EXPORT_SYMBOL_GPL(dev_pm_opp_set_supported_hw); =20 /** - * dev_pm_opp_put_supported_hw() - Releases resources blocked for supporte= d hw - * @opp_table: OPP table returned by dev_pm_opp_set_supported_hw(). + * _opp_put_supported_hw() - Releases resources blocked for supported hw + * @opp_table: OPP table returned by _opp_set_supported_hw(). * * This is required only for the V2 bindings, and is called for a matching - * dev_pm_opp_set_supported_hw(). Until this is called, the opp_table stru= cture + * _opp_set_supported_hw(). Until this is called, the opp_table structure * will not be freed. */ -void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) +static void _opp_put_supported_hw(struct opp_table *opp_table) { - if (unlikely(!opp_table)) - return; - - kfree(opp_table->supported_hw); - opp_table->supported_hw =3D NULL; - opp_table->supported_hw_count =3D 0; - - dev_pm_opp_put_opp_table(opp_table); -} -EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw); - -static void devm_pm_opp_supported_hw_release(void *data) -{ - dev_pm_opp_put_supported_hw(data); -} - -/** - * devm_pm_opp_set_supported_hw() - Set supported platforms - * @dev: Device for which supported-hw has to be set. - * @versions: Array of hierarchy of versions to match. - * @count: Number of elements in the array. - * - * This is a resource-managed variant of dev_pm_opp_set_supported_hw(). - * - * Return: 0 on success and errorno otherwise. - */ -int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, - unsigned int count) -{ - struct opp_table *opp_table; - - opp_table =3D dev_pm_opp_set_supported_hw(dev, versions, count); - if (IS_ERR(opp_table)) - return PTR_ERR(opp_table); - - return devm_add_action_or_reset(dev, devm_pm_opp_supported_hw_release, - opp_table); + if (opp_table->supported_hw) { + kfree(opp_table->supported_hw); + opp_table->supported_hw =3D NULL; + opp_table->supported_hw_count =3D 0; + } } -EXPORT_SYMBOL_GPL(devm_pm_opp_set_supported_hw); =20 /** * dev_pm_opp_set_prop_name() - Set prop-extn name @@ -2583,7 +2538,7 @@ static void _opp_clear_config(struct opp_config_data = *data) if (data->flags & OPP_CONFIG_REGULATOR) _opp_put_regulators(data->opp_table); if (data->flags & OPP_CONFIG_SUPPORTED_HW) - dev_pm_opp_put_supported_hw(data->opp_table); + _opp_put_supported_hw(data->opp_table); if (data->flags & OPP_CONFIG_REGULATOR_HELPER) dev_pm_opp_unregister_set_opp_helper(data->opp_table); if (data->flags & OPP_CONFIG_PROP_NAME) @@ -2694,12 +2649,10 @@ int dev_pm_opp_set_config(struct device *dev, struc= t dev_pm_opp_config *config) =20 /* Configure supported hardware */ if (config->supported_hw) { - err =3D dev_pm_opp_set_supported_hw(dev, config->supported_hw, - config->supported_hw_count); - if (IS_ERR(err)) { - ret =3D PTR_ERR(err); + ret =3D _opp_set_supported_hw(opp_table, config->supported_hw, + config->supported_hw_count); + if (ret) goto err; - } =20 data->flags |=3D OPP_CONFIG_SUPPORTED_HW; } diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index f014bd172c99..94d0101c254c 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -184,9 +184,6 @@ int dev_pm_opp_set_config(struct device *dev, struct de= v_pm_opp_config *config); int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *c= onfig); void dev_pm_opp_clear_config(int token); =20 -struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u3= 2 *versions, unsigned int count); -void dev_pm_opp_put_supported_hw(struct opp_table *opp_table); -int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, = unsigned int count); struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char = *name); void dev_pm_opp_put_prop_name(struct opp_table *opp_table); struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *n= ame); @@ -369,22 +366,6 @@ static inline int dev_pm_opp_unregister_notifier(struc= t device *dev, struct noti return -EOPNOTSUPP; } =20 -static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device = *dev, - const u32 *versions, - unsigned int count) -{ - return ERR_PTR(-EOPNOTSUPP); -} - -static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table= ) {} - -static inline int devm_pm_opp_set_supported_hw(struct device *dev, - const u32 *versions, - unsigned int count) -{ - return -EOPNOTSUPP; -} - static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct = device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data)) { @@ -618,4 +599,34 @@ static inline int devm_pm_opp_set_regulators(struct de= vice *dev, return devm_pm_opp_set_config(dev, &config); } =20 +/* Supported-hw helpers */ +static inline int dev_pm_opp_set_supported_hw(struct device *dev, + const u32 *versions, + unsigned int count) +{ + struct dev_pm_opp_config config =3D { + .supported_hw =3D versions, + .supported_hw_count =3D count, + }; + + return dev_pm_opp_set_config(dev, &config); +} + +static inline void dev_pm_opp_put_supported_hw(int token) +{ + dev_pm_opp_clear_config(token); +} + +static inline int devm_pm_opp_set_supported_hw(struct device *dev, + const u32 *versions, + unsigned int count) +{ + struct dev_pm_opp_config config =3D { + .supported_hw =3D versions, + .supported_hw_count =3D count, + }; + + return devm_pm_opp_set_config(dev, &config); +} + #endif /* __LINUX_OPP_H__ */ --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 DFFB4C43334 for ; Mon, 4 Jul 2022 12:09:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234219AbiGDMJq (ORCPT ); Mon, 4 Jul 2022 08:09:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234041AbiGDMJH (ORCPT ); Mon, 4 Jul 2022 08:09:07 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E18612616 for ; Mon, 4 Jul 2022 05:08:45 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id j1-20020a17090aeb0100b001ef777a7befso3022302pjz.0 for ; Mon, 04 Jul 2022 05:08:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9IrdxzxTTKLEFqWex8kwhKDZi3CUweIZT4I4RMPAg9Q=; b=NBpMXihmPxXh0ldVsTqVnPHisV7QIaooloK5TLqgGR4Eq3tI/aoCpTiZCJfQzmwL34 9UnrXXdwlLclxaXJNmZATFo9aOrlQICa7zZg7HtD1fUkXe9OipYlSrRc9unK4MI+Wi2z PKRXzpGxAP6WdgJVqCZVKZxeYw7R5/gJjBIr2NDQFRYggSkqNwouUgYq4DdXKHNHNn5K WWFkx14/em0EHU8Wwbidh+Vb4Po+82bT/L8L3cOiTZ8PnKwryRHRklvR1A9pvpluZj2B nqKs/l+WCLAoQAdm+8TQM5f5aTvI9zZvzBxt0Jap+o7thYEsPRFX2o8eWEh1P7GFa/Yz nuSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9IrdxzxTTKLEFqWex8kwhKDZi3CUweIZT4I4RMPAg9Q=; b=1Tzb75MzQKxsuwNPWzG/alksP9sGZ1FkKLb5Qms7uJ3UdCOuEM0Yn0+vNuBMxfg7Nk OjLh2YylB+NGLsWq57B0x6LugMP7PIQE0AWtgSo+ogZGLNcJqkjHlISVChxtlw+J7ghm sv5uRMZKW0gzywVXu4QHmMXG/1+zov7NERwdgvbs/tKTz2hv2JuhQN2EmC3MQGhB0fwy Se4UjGidcidEB5whhd3hT5CNOsmzTE6GSGUqtPuEitGSfpeeRnwJ6ZnIdVd4qk1AL2B2 LLPM0xBIThecXpaaCxerbdEGypI7L1fZdkY8Qn35jY6ArdnwsIxu6vQ9LYhUvtxA0RDx FYIQ== X-Gm-Message-State: AJIora/FuM2ueqFCTmr9f0qguJgFFPHwusUDyjpZ1ZzE0dUE6TpJ9qf7 cG0VgDUYnAg3nb5bQTL6oBL3AQ== X-Google-Smtp-Source: AGRyM1uRSy4NzHoOWjBM1hcipF+dubrs0xwkLuyFRx39LNV4lYZ/tb0MHIx/gIFSTMcG1V4pq7jRgA== X-Received: by 2002:a17:90b:f86:b0:1ef:90f2:884c with SMTP id ft6-20020a17090b0f8600b001ef90f2884cmr1086310pjb.91.1656936525252; Mon, 04 Jul 2022 05:08:45 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id d3-20020a17090ac24300b001ef8ab65052sm1690189pjx.11.2022.07.04.05.08.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:44 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH V3 12/20] OPP: Migrate set-clk-name API to use set-config helpers Date: Mon, 4 Jul 2022 17:37:50 +0530 Message-Id: <0ae7b982b4c87940a01d78200295f7bc66cb67f7.1656935522.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" Now that we have a central API to handle all OPP table configurations, migrate the set-clk-name family of helpers to use the new infrastructure. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 142 +++++++++++++---------------------------- include/linux/pm_opp.h | 41 +++++++----- 2 files changed, 69 insertions(+), 114 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 8dbdfff38973..0a82ca7ae453 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -2164,104 +2164,71 @@ static void _opp_put_regulators(struct opp_table *= opp_table) } =20 /** - * dev_pm_opp_set_clkname() - Set clk name for the device - * @dev: Device for which clk name is being set. - * @name: Clk name. - * - * In order to support OPP switching, OPP layer needs to get pointer to the - * clock for the device. Simple cases work fine without using this routine= (i.e. - * by passing connection-id as NULL), but for a device with multiple clocks - * available, the OPP core needs to know the exact name of the clk to use. + * _opp_set_clknames() - Set clk names for the device + * @dev: Device for which clk names is being set. + * @names: Clk names. + * + * In order to support OPP switching, OPP layer needs to get pointers to t= he + * clocks for the device. Simple cases work fine without using this routine + * (i.e. by passing connection-id as NULL), but for a device with multiple + * clocks available, the OPP core needs to know the exact names of the clk= s to + * use. * * This must be called before any OPPs are initialized for the device. */ -struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *n= ame) +static int _opp_set_clknames(struct opp_table *opp_table, struct device *d= ev, + const char * const names[]) { - struct opp_table *opp_table; - int ret; + const char * const *temp =3D names; + int count =3D 0; =20 - opp_table =3D _add_opp_table(dev, false); - if (IS_ERR(opp_table)) - return opp_table; + /* Count number of clks */ + while (*temp++) + count++; =20 - /* This should be called before OPPs are initialized */ - if (WARN_ON(!list_empty(&opp_table->opp_list))) { - ret =3D -EBUSY; - goto err; - } + /* + * This is a special case where we have a single clock, whose connection + * id name is NULL, i.e. first two entries are NULL in the array. + */ + if (!count && !names[1]) + count =3D 1; + + /* We support only one clock name for now */ + if (count !=3D 1) + return -EINVAL; =20 /* Another CPU that shares the OPP table has set the clkname ? */ if (opp_table->clk_configured) - return opp_table; + return 0; =20 /* clk shouldn't be initialized at this point */ - if (WARN_ON(opp_table->clk)) { - ret =3D -EBUSY; - goto err; - } + if (WARN_ON(opp_table->clk)) + return -EBUSY; =20 /* Find clk for the device */ - opp_table->clk =3D clk_get(dev, name); + opp_table->clk =3D clk_get(dev, names[0]); if (IS_ERR(opp_table->clk)) { - ret =3D dev_err_probe(dev, PTR_ERR(opp_table->clk), + return dev_err_probe(dev, PTR_ERR(opp_table->clk), "%s: Couldn't find clock\n", __func__); - goto err; } =20 opp_table->clk_configured =3D true; =20 - return opp_table; - -err: - dev_pm_opp_put_opp_table(opp_table); - - return ERR_PTR(ret); -} -EXPORT_SYMBOL_GPL(dev_pm_opp_set_clkname); - -/** - * dev_pm_opp_put_clkname() - Releases resources blocked for clk. - * @opp_table: OPP table returned from dev_pm_opp_set_clkname(). - */ -void dev_pm_opp_put_clkname(struct opp_table *opp_table) -{ - if (unlikely(!opp_table)) - return; - - clk_put(opp_table->clk); - opp_table->clk =3D ERR_PTR(-EINVAL); - opp_table->clk_configured =3D false; - - dev_pm_opp_put_opp_table(opp_table); -} -EXPORT_SYMBOL_GPL(dev_pm_opp_put_clkname); - -static void devm_pm_opp_clkname_release(void *data) -{ - dev_pm_opp_put_clkname(data); + return 0; } =20 /** - * devm_pm_opp_set_clkname() - Set clk name for the device - * @dev: Device for which clk name is being set. - * @name: Clk name. - * - * This is a resource-managed variant of dev_pm_opp_set_clkname(). - * - * Return: 0 on success and errorno otherwise. + * _opp_put_clknames() - Releases resources blocked for clks. + * @opp_table: OPP table returned from _opp_set_clknames(). */ -int devm_pm_opp_set_clkname(struct device *dev, const char *name) +static void _opp_put_clknames(struct opp_table *opp_table) { - struct opp_table *opp_table; - - opp_table =3D dev_pm_opp_set_clkname(dev, name); - if (IS_ERR(opp_table)) - return PTR_ERR(opp_table); - - return devm_add_action_or_reset(dev, devm_pm_opp_clkname_release, - opp_table); + if (opp_table->clk_configured) { + clk_put(opp_table->clk); + opp_table->clk =3D ERR_PTR(-EINVAL); + opp_table->clk_configured =3D false; + } } -EXPORT_SYMBOL_GPL(devm_pm_opp_set_clkname); =20 /** * dev_pm_opp_register_set_opp_helper() - Register custom set OPP helper @@ -2544,7 +2511,7 @@ static void _opp_clear_config(struct opp_config_data = *data) if (data->flags & OPP_CONFIG_PROP_NAME) dev_pm_opp_put_prop_name(data->opp_table); if (data->flags & OPP_CONFIG_CLK) - dev_pm_opp_put_clkname(data->opp_table); + _opp_put_clknames(data->opp_table); =20 dev_pm_opp_put_opp_table(data->opp_table); kfree(data); @@ -2595,32 +2562,9 @@ int dev_pm_opp_set_config(struct device *dev, struct= dev_pm_opp_config *config) =20 /* Configure clocks */ if (config->clk_names) { - const char * const *temp =3D config->clk_names; - int count =3D 0; - - /* Count number of clks */ - while (*temp++) - count++; - - /* - * This is a special case where we have a single clock, whose - * connection id name is NULL, i.e. first two entries are NULL - * in the array. - */ - if (!count && !config->clk_names[1]) - count =3D 1; - - /* We support only one clock name for now */ - if (count !=3D 1) { - ret =3D -EINVAL; - goto err; - } - - err =3D dev_pm_opp_set_clkname(dev, config->clk_names[0]); - if (IS_ERR(err)) { - ret =3D PTR_ERR(err); + ret =3D _opp_set_clknames(opp_table, dev, config->clk_names); + if (ret) goto err; - } =20 data->flags |=3D OPP_CONFIG_CLK; } diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 94d0101c254c..ed1906bbe8bb 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -186,9 +186,6 @@ void dev_pm_opp_clear_config(int token); =20 struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char = *name); void dev_pm_opp_put_prop_name(struct opp_table *opp_table); -struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *n= ame); -void dev_pm_opp_put_clkname(struct opp_table *opp_table); -int devm_pm_opp_set_clkname(struct device *dev, const char *name); struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, i= nt (*set_opp)(struct dev_pm_set_opp_data *data)); void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table); int devm_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)= (struct dev_pm_set_opp_data *data)); @@ -387,18 +384,6 @@ static inline struct opp_table *dev_pm_opp_set_prop_na= me(struct device *dev, con =20 static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {} =20 -static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev,= const char *name) -{ - return ERR_PTR(-EOPNOTSUPP); -} - -static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {} - -static inline int devm_pm_opp_set_clkname(struct device *dev, const char *= name) -{ - return -EOPNOTSUPP; -} - static inline struct opp_table *dev_pm_opp_attach_genpd(struct device *dev= , const char * const *names, struct device ***virt_devs) { return ERR_PTR(-EOPNOTSUPP); @@ -629,4 +614,30 @@ static inline int devm_pm_opp_set_supported_hw(struct = device *dev, return devm_pm_opp_set_config(dev, &config); } =20 +/* clkname helpers */ +static inline int dev_pm_opp_set_clkname(struct device *dev, const char *n= ame) +{ + const char *names[] =3D { name, NULL }; + struct dev_pm_opp_config config =3D { + .clk_names =3D names, + }; + + return dev_pm_opp_set_config(dev, &config); +} + +static inline void dev_pm_opp_put_clkname(int token) +{ + dev_pm_opp_clear_config(token); +} + +static inline int devm_pm_opp_set_clkname(struct device *dev, const char *= name) +{ + const char *names[] =3D { name, NULL }; + struct dev_pm_opp_config config =3D { + .clk_names =3D names, + }; + + return devm_pm_opp_set_config(dev, &config); +} + #endif /* __LINUX_OPP_H__ */ --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 69EE3CCA479 for ; Mon, 4 Jul 2022 12:09:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233999AbiGDMJx (ORCPT ); Mon, 4 Jul 2022 08:09:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233493AbiGDMJM (ORCPT ); Mon, 4 Jul 2022 08:09:12 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B7BD12627 for ; Mon, 4 Jul 2022 05:08:48 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id o31-20020a17090a0a2200b001ef7bd037bbso4075998pjo.0 for ; Mon, 04 Jul 2022 05:08:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8xhiD9amdZ6J7ogRI+kKZI/KO8vtgIY0dvS9gGM+qI8=; b=qkjX0dVwiicUWd3IVn3k5ZhFosaWDSgUjoZYwP2bSD2KQhZqxJcI4tHkkYFU/FeBRW BHoaUa6qQcjmlfxvRx93i9qKVFkWa8ZHXKl4NauFD9sS95i1C/vHdciswWtQsZjSYz1k VHrxnwB5FqQsLIjwhU+kwW+BnOpaE5u12g1ZBYSOnl40lDdUL3n0I4ar+aXYviR0xguv LAzfHBvayaiqioepZEy2kPswJRwxu/z+1l0D1oRrZQX+/zrg//yb1emo4734VbtzFRf1 FIxxeAVtZu2zt6KaEVZQwofCGii19RO3v7X4LuOjZBkwUMfPjw0cHKP4WTovhBEeDrmI oQhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8xhiD9amdZ6J7ogRI+kKZI/KO8vtgIY0dvS9gGM+qI8=; b=wruSv8sboxtx0a5KDjrCd00emi8b0aL69YFBt0E/nTejNykb9f/nC7wBzIz8MIEkR2 jxyds3BzkXzWiv/nD0ZAbjLdxe+luF+0TUc6qEcneHt/jOMf7misW5meEBf86ZJQ4sj4 l0vCfQRo2GQrVaTc1ituxizlMDK+uxBIzvSD026wmXfQXTXP9j4cezw/VGGVFflCfkYO HFDA4bpc2Oqof1wj43qfbhhQ6hsXYVOqOgrufWZhZWsiJFGnRU9cTfjHxF/Te3t7BnxX A1DoGWa0DupgFGk3jXA9YShApWmEZP8BqkZzzcks+eB4N0jPJPY59MEg+1vlN6dYTaiP t4cg== X-Gm-Message-State: AJIora/wpsobVkeYjhBHPKkb3IMCycF5bvJHj6WeHZ5mMyAJGTie4vyV X1Bj4hOd1LDX/bzA/G3vKuVHHQ== X-Google-Smtp-Source: AGRyM1tBz/4s/3409KodSTMaww+Cy4Z/YO6/yZnOkRIVzLkC7L8iDGtr3uoenKxm+mtquKSoJW1PZA== X-Received: by 2002:a17:90b:4a0c:b0:1ec:d90c:601d with SMTP id kk12-20020a17090b4a0c00b001ecd90c601dmr35151468pjb.154.1656936528249; Mon, 04 Jul 2022 05:08:48 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id v8-20020a17090a00c800b001ef869aa755sm2459835pjd.15.2022.07.04.05.08.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:47 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH V3 13/20] OPP: Migrate set-opp-helper API to use set-config helpers Date: Mon, 4 Jul 2022 17:37:51 +0530 Message-Id: <7274b73c609073e40461467a6d6cc211ef772bb0.1656935522.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" Now that we have a central API to handle all OPP table configurations, migrate the set-opp-helper family of helpers to use the new infrastructure. The return type and parameter to the APIs change a bit due to this, update the current users as well in the same commit in order to avoid breaking builds. Remove devm_pm_opp_register_set_opp_helper() as it has no users currently. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 89 +++++++++---------------------------- drivers/opp/ti-opp-supply.c | 6 +-- include/linux/pm_opp.h | 33 +++++++------- 3 files changed, 39 insertions(+), 89 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 0a82ca7ae453..9da7dcf62cab 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -2231,7 +2231,7 @@ static void _opp_put_clknames(struct opp_table *opp_t= able) } =20 /** - * dev_pm_opp_register_set_opp_helper() - Register custom set OPP helper + * _opp_register_set_opp_helper() - Register custom set OPP helper * @dev: Device for which the helper is getting registered. * @set_opp: Custom set OPP helper. * @@ -2240,32 +2240,18 @@ static void _opp_put_clknames(struct opp_table *opp= _table) * * This must be called before any OPPs are initialized for the device. */ -struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, - int (*set_opp)(struct dev_pm_set_opp_data *data)) +static int _opp_register_set_opp_helper(struct opp_table *opp_table, + struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data)) { struct dev_pm_set_opp_data *data; - struct opp_table *opp_table; - - if (!set_opp) - return ERR_PTR(-EINVAL); - - opp_table =3D _add_opp_table(dev, false); - if (IS_ERR(opp_table)) - return opp_table; - - /* This should be called before OPPs are initialized */ - if (WARN_ON(!list_empty(&opp_table->opp_list))) { - dev_pm_opp_put_opp_table(opp_table); - return ERR_PTR(-EBUSY); - } =20 /* Another CPU that shares the OPP table has set the helper ? */ if (opp_table->set_opp) - return opp_table; + return 0; =20 data =3D kzalloc(sizeof(*data), GFP_KERNEL); if (!data) - return ERR_PTR(-ENOMEM); + return -ENOMEM; =20 mutex_lock(&opp_table->lock); opp_table->set_opp_data =3D data; @@ -2278,60 +2264,26 @@ struct opp_table *dev_pm_opp_register_set_opp_helpe= r(struct device *dev, =20 opp_table->set_opp =3D set_opp; =20 - return opp_table; + return 0; } -EXPORT_SYMBOL_GPL(dev_pm_opp_register_set_opp_helper); =20 /** - * dev_pm_opp_unregister_set_opp_helper() - Releases resources blocked for - * set_opp helper - * @opp_table: OPP table returned from dev_pm_opp_register_set_opp_helper(= ). + * _opp_unregister_set_opp_helper() - Releases resources blocked for set_o= pp helper + * @opp_table: OPP table returned from _opp_register_set_opp_helper(). * * Release resources blocked for platform specific set_opp helper. */ -void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) +static void _opp_unregister_set_opp_helper(struct opp_table *opp_table) { - if (unlikely(!opp_table)) - return; - - opp_table->set_opp =3D NULL; - - mutex_lock(&opp_table->lock); - kfree(opp_table->set_opp_data); - opp_table->set_opp_data =3D NULL; - mutex_unlock(&opp_table->lock); - - dev_pm_opp_put_opp_table(opp_table); -} -EXPORT_SYMBOL_GPL(dev_pm_opp_unregister_set_opp_helper); - -static void devm_pm_opp_unregister_set_opp_helper(void *data) -{ - dev_pm_opp_unregister_set_opp_helper(data); -} - -/** - * devm_pm_opp_register_set_opp_helper() - Register custom set OPP helper - * @dev: Device for which the helper is getting registered. - * @set_opp: Custom set OPP helper. - * - * This is a resource-managed version of dev_pm_opp_register_set_opp_helpe= r(). - * - * Return: 0 on success and errorno otherwise. - */ -int devm_pm_opp_register_set_opp_helper(struct device *dev, - int (*set_opp)(struct dev_pm_set_opp_data *data)) -{ - struct opp_table *opp_table; - - opp_table =3D dev_pm_opp_register_set_opp_helper(dev, set_opp); - if (IS_ERR(opp_table)) - return PTR_ERR(opp_table); + if (opp_table->set_opp) { + opp_table->set_opp =3D NULL; =20 - return devm_add_action_or_reset(dev, devm_pm_opp_unregister_set_opp_helpe= r, - opp_table); + mutex_lock(&opp_table->lock); + kfree(opp_table->set_opp_data); + opp_table->set_opp_data =3D NULL; + mutex_unlock(&opp_table->lock); + } } -EXPORT_SYMBOL_GPL(devm_pm_opp_register_set_opp_helper); =20 static void _opp_detach_genpd(struct opp_table *opp_table) { @@ -2507,7 +2459,7 @@ static void _opp_clear_config(struct opp_config_data = *data) if (data->flags & OPP_CONFIG_SUPPORTED_HW) _opp_put_supported_hw(data->opp_table); if (data->flags & OPP_CONFIG_REGULATOR_HELPER) - dev_pm_opp_unregister_set_opp_helper(data->opp_table); + _opp_unregister_set_opp_helper(data->opp_table); if (data->flags & OPP_CONFIG_PROP_NAME) dev_pm_opp_put_prop_name(data->opp_table); if (data->flags & OPP_CONFIG_CLK) @@ -2582,11 +2534,10 @@ int dev_pm_opp_set_config(struct device *dev, struc= t dev_pm_opp_config *config) =20 /* Configure opp helper */ if (config->set_opp) { - err =3D dev_pm_opp_register_set_opp_helper(dev, config->set_opp); - if (IS_ERR(err)) { - ret =3D PTR_ERR(err); + ret =3D _opp_register_set_opp_helper(opp_table, dev, + config->set_opp); + if (ret) goto err; - } =20 data->flags |=3D OPP_CONFIG_REGULATOR_HELPER; } diff --git a/drivers/opp/ti-opp-supply.c b/drivers/opp/ti-opp-supply.c index bd4771f388ab..40ebc9ac82dd 100644 --- a/drivers/opp/ti-opp-supply.c +++ b/drivers/opp/ti-opp-supply.c @@ -405,9 +405,9 @@ static int ti_opp_supply_probe(struct platform_device *= pdev) return ret; } =20 - ret =3D PTR_ERR_OR_ZERO(dev_pm_opp_register_set_opp_helper(cpu_dev, - ti_opp_supply_set_opp)); - if (ret) + ret =3D dev_pm_opp_register_set_opp_helper(cpu_dev, + ti_opp_supply_set_opp); + if (ret < 0) _free_optimized_voltages(dev, &opp_data); =20 return ret; diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index ed1906bbe8bb..85a4b7353979 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -186,9 +186,6 @@ void dev_pm_opp_clear_config(int token); =20 struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char = *name); void dev_pm_opp_put_prop_name(struct opp_table *opp_table); -struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, i= nt (*set_opp)(struct dev_pm_set_opp_data *data)); -void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table); -int devm_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)= (struct dev_pm_set_opp_data *data)); struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char *= const *names, struct device ***virt_devs); void dev_pm_opp_detach_genpd(struct opp_table *opp_table); int devm_pm_opp_attach_genpd(struct device *dev, const char * const *names= , struct device ***virt_devs); @@ -363,20 +360,6 @@ static inline int dev_pm_opp_unregister_notifier(struc= t device *dev, struct noti return -EOPNOTSUPP; } =20 -static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct = device *dev, - int (*set_opp)(struct dev_pm_set_opp_data *data)) -{ - return ERR_PTR(-EOPNOTSUPP); -} - -static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *= opp_table) {} - -static inline int devm_pm_opp_register_set_opp_helper(struct device *dev, - int (*set_opp)(struct dev_pm_set_opp_data *data)) -{ - return -EOPNOTSUPP; -} - static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *de= v, const char *name) { return ERR_PTR(-EOPNOTSUPP); @@ -640,4 +623,20 @@ static inline int devm_pm_opp_set_clkname(struct devic= e *dev, const char *name) return devm_pm_opp_set_config(dev, &config); } =20 +/* set-opp helpers */ +static inline int dev_pm_opp_register_set_opp_helper(struct device *dev, + int (*set_opp)(struct dev_pm_set_opp_data *data)) +{ + struct dev_pm_opp_config config =3D { + .set_opp =3D set_opp, + }; + + return dev_pm_opp_set_config(dev, &config); +} + +static inline void dev_pm_opp_unregister_set_opp_helper(int token) +{ + dev_pm_opp_clear_config(token); +} + #endif /* __LINUX_OPP_H__ */ --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 F077ECCA47C for ; Mon, 4 Jul 2022 12:09:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232279AbiGDMJ5 (ORCPT ); Mon, 4 Jul 2022 08:09:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234317AbiGDMJW (ORCPT ); Mon, 4 Jul 2022 08:09:22 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9AD912613 for ; Mon, 4 Jul 2022 05:08:51 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id y141so8787534pfb.7 for ; Mon, 04 Jul 2022 05:08:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EVwwsLgblRII0czn7jaGcIQ0lMjiB5lW3Rzfz9bgHNA=; b=rpR3CZu8opaXuJUwHDy4f7GFgdLnkIR+SOHvjjmy4HU7iprbXBo0ORpawDhL4k5o+y EYLC4i7Ql6GJkkZePrPYrXwaxSumynWMJqjpPI0Ubtq6ZH1mmFJu64y6r4gYvLHSRn4c fHfxoulWAtF1uyW8V+8nvmlH3a0XeueJ7eMJOdQ0TMi0a9+ri41DlHcHDFsKR3DI6F6k Yk7iS7LBp3QdlmWTc1qqYvef7TUlfyV/bCqX5ktwiv54WAHemMgL0hGCbaoLuM3hY4iv pA1c+XWMOVGal61DAF77CvWvdfhsV34zGthHbenJ3UppKgEeQgbqJqqTPirvMPkvLT6P 9W4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EVwwsLgblRII0czn7jaGcIQ0lMjiB5lW3Rzfz9bgHNA=; b=twRmCWjdg886U61ParppQ7vHhkrpe5MuzhlSfl9jq435TNTg4GV6qJ9Z+em3Bg0iuv ldyGGPoc8dqx1d8+6SrHHUEG5qDTw65GzLB1dGsuTb77uTaOjWgUBcrcqttAylhaU6WG 2m4AhN9QRW/X+bXgnnbwP+GMygJzhuCMPxruvc2Z8DOU1CcJhYiVQJjJ9z9zBGuy4vhi Lh+EV4rtI9AK0Y3TXtDKd8u0aP2mOXwb+NekzyA1spD7m9u5y71MzuNnGCrjAtkzo8qQ 9OM0fQyIG4f8o960HC4zxYgzdZicNXUExtbyq67Wz5XCHvR7rRdD0nqgI1PX+KrdNTSw 2MMg== X-Gm-Message-State: AJIora8zhhBWjmEGa6FTaoHQkwjdBeGGew+jYRRileaiQ7ouVN79YI0z SOf3cFU002qKaEqLSl8yAJP7Pg== X-Google-Smtp-Source: AGRyM1tEGWdGdhPMOgJAEhZ+sfknlv72HahQgSA+crudG5Z82VdZWqpx/T5Q1fDVW+U5oi9RP3unRA== X-Received: by 2002:a05:6a00:2292:b0:525:6c57:8dd5 with SMTP id f18-20020a056a00229200b005256c578dd5mr35612660pfe.17.1656936531161; Mon, 04 Jul 2022 05:08:51 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id x10-20020a1709027c0a00b0016a6caacaefsm20465980pll.103.2022.07.04.05.08.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:50 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH V3 14/20] OPP: Migrate attach-genpd API to use set-config helpers Date: Mon, 4 Jul 2022 17:37:52 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" Now that we have a central API to handle all OPP table configurations, migrate the attach-genpd family of helpers to use the new infrastructure. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 85 +++++++++--------------------------------- include/linux/pm_opp.h | 48 +++++++++++++++--------- 2 files changed, 49 insertions(+), 84 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 9da7dcf62cab..458584994c2b 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -2285,7 +2285,7 @@ static void _opp_unregister_set_opp_helper(struct opp= _table *opp_table) } } =20 -static void _opp_detach_genpd(struct opp_table *opp_table) +static void _detach_genpd(struct opp_table *opp_table) { int index; =20 @@ -2305,7 +2305,7 @@ static void _opp_detach_genpd(struct opp_table *opp_t= able) } =20 /** - * dev_pm_opp_attach_genpd - Attach genpd(s) for the device and save virtu= al device pointer + * _opp_attach_genpd - Attach genpd(s) for the device and save virtual dev= ice pointer * @dev: Consumer device for which the genpd is getting attached. * @names: Null terminated array of pointers containing names of genpd to = attach. * @virt_devs: Pointer to return the array of virtual devices. @@ -2326,30 +2326,23 @@ static void _opp_detach_genpd(struct opp_table *opp= _table) * The order of entries in the names array must match the order in which * "required-opps" are added in DT. */ -struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, - const char * const *names, struct device ***virt_devs) +static int _opp_attach_genpd(struct opp_table *opp_table, struct device *d= ev, + const char * const *names, struct device ***virt_devs) { - struct opp_table *opp_table; struct device *virt_dev; int index =3D 0, ret =3D -EINVAL; const char * const *name =3D names; =20 - opp_table =3D _add_opp_table(dev, false); - if (IS_ERR(opp_table)) - return opp_table; - if (opp_table->genpd_virt_devs) - return opp_table; + return 0; =20 /* * If the genpd's OPP table isn't already initialized, parsing of the * required-opps fail for dev. We should retry this after genpd's OPP * table is added. */ - if (!opp_table->required_opp_count) { - ret =3D -EPROBE_DEFER; - goto put_table; - } + if (!opp_table->required_opp_count) + return -EPROBE_DEFER; =20 mutex_lock(&opp_table->genpd_virt_dev_lock); =20 @@ -2382,78 +2375,38 @@ struct opp_table *dev_pm_opp_attach_genpd(struct de= vice *dev, *virt_devs =3D opp_table->genpd_virt_devs; mutex_unlock(&opp_table->genpd_virt_dev_lock); =20 - return opp_table; + return 0; =20 err: - _opp_detach_genpd(opp_table); + _detach_genpd(opp_table); unlock: mutex_unlock(&opp_table->genpd_virt_dev_lock); + return ret; =20 -put_table: - dev_pm_opp_put_opp_table(opp_table); - - return ERR_PTR(ret); } -EXPORT_SYMBOL_GPL(dev_pm_opp_attach_genpd); =20 /** - * dev_pm_opp_detach_genpd() - Detach genpd(s) from the device. - * @opp_table: OPP table returned by dev_pm_opp_attach_genpd(). + * _opp_detach_genpd() - Detach genpd(s) from the device. + * @opp_table: OPP table returned by _opp_attach_genpd(). * * This detaches the genpd(s), resets the virtual device pointers, and put= s the * OPP table. */ -void dev_pm_opp_detach_genpd(struct opp_table *opp_table) +static void _opp_detach_genpd(struct opp_table *opp_table) { - if (unlikely(!opp_table)) - return; - /* * Acquire genpd_virt_dev_lock to make sure virt_dev isn't getting * used in parallel. */ mutex_lock(&opp_table->genpd_virt_dev_lock); - _opp_detach_genpd(opp_table); + _detach_genpd(opp_table); mutex_unlock(&opp_table->genpd_virt_dev_lock); - - dev_pm_opp_put_opp_table(opp_table); } -EXPORT_SYMBOL_GPL(dev_pm_opp_detach_genpd); - -static void devm_pm_opp_detach_genpd(void *data) -{ - dev_pm_opp_detach_genpd(data); -} - -/** - * devm_pm_opp_attach_genpd - Attach genpd(s) for the device and save virt= ual - * device pointer - * @dev: Consumer device for which the genpd is getting attached. - * @names: Null terminated array of pointers containing names of genpd to = attach. - * @virt_devs: Pointer to return the array of virtual devices. - * - * This is a resource-managed version of dev_pm_opp_attach_genpd(). - * - * Return: 0 on success and errorno otherwise. - */ -int devm_pm_opp_attach_genpd(struct device *dev, const char * const *names, - struct device ***virt_devs) -{ - struct opp_table *opp_table; - - opp_table =3D dev_pm_opp_attach_genpd(dev, names, virt_devs); - if (IS_ERR(opp_table)) - return PTR_ERR(opp_table); - - return devm_add_action_or_reset(dev, devm_pm_opp_detach_genpd, - opp_table); -} -EXPORT_SYMBOL_GPL(devm_pm_opp_attach_genpd); =20 static void _opp_clear_config(struct opp_config_data *data) { if (data->flags & OPP_CONFIG_GENPD) - dev_pm_opp_detach_genpd(data->opp_table); + _opp_detach_genpd(data->opp_table); if (data->flags & OPP_CONFIG_REGULATOR) _opp_put_regulators(data->opp_table); if (data->flags & OPP_CONFIG_SUPPORTED_HW) @@ -2564,12 +2517,10 @@ int dev_pm_opp_set_config(struct device *dev, struc= t dev_pm_opp_config *config) =20 /* Attach genpds */ if (config->genpd_names) { - err =3D dev_pm_opp_attach_genpd(dev, config->genpd_names, - config->virt_devs); - if (IS_ERR(err)) { - ret =3D PTR_ERR(err); + ret =3D _opp_attach_genpd(opp_table, dev, config->genpd_names, + config->virt_devs); + if (ret) goto err; - } =20 data->flags |=3D OPP_CONFIG_GENPD; } diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 85a4b7353979..20e1e5060a8a 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -186,9 +186,6 @@ void dev_pm_opp_clear_config(int token); =20 struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char = *name); void dev_pm_opp_put_prop_name(struct opp_table *opp_table); -struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char *= const *names, struct device ***virt_devs); -void dev_pm_opp_detach_genpd(struct opp_table *opp_table); -int devm_pm_opp_attach_genpd(struct device *dev, const char * const *names= , struct device ***virt_devs); struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_tab= le, struct opp_table *dst_table, struct dev_pm_opp *src_opp); int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct= opp_table *dst_table, unsigned int pstate); int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq); @@ -367,20 +364,6 @@ static inline struct opp_table *dev_pm_opp_set_prop_na= me(struct device *dev, con =20 static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {} =20 -static inline struct opp_table *dev_pm_opp_attach_genpd(struct device *dev= , const char * const *names, struct device ***virt_devs) -{ - return ERR_PTR(-EOPNOTSUPP); -} - -static inline void dev_pm_opp_detach_genpd(struct opp_table *opp_table) {} - -static inline int devm_pm_opp_attach_genpd(struct device *dev, - const char * const *names, - struct device ***virt_devs) -{ - return -EOPNOTSUPP; -} - static inline int dev_pm_opp_set_config(struct device *dev, struct dev_pm_= opp_config *config) { return -EOPNOTSUPP; @@ -639,4 +622,35 @@ static inline void dev_pm_opp_unregister_set_opp_helpe= r(int token) dev_pm_opp_clear_config(token); } =20 +/* genpd helpers */ +static inline int dev_pm_opp_attach_genpd(struct device *dev, + const char * const *names, + struct device ***virt_devs) +{ + struct dev_pm_opp_config config =3D { + .genpd_names =3D names, + .virt_devs =3D virt_devs, + }; + + return dev_pm_opp_set_config(dev, &config); +} + +static inline void dev_pm_opp_detach_genpd(int token) +{ + dev_pm_opp_clear_config(token); +} + +static inline int devm_pm_opp_attach_genpd(struct device *dev, + const char * const *names, + struct device ***virt_devs) +{ + struct dev_pm_opp_config config =3D { + .genpd_names =3D names, + .virt_devs =3D virt_devs, + }; + + return devm_pm_opp_set_config(dev, &config); +} + + #endif /* __LINUX_OPP_H__ */ --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 A66ECC433EF for ; Mon, 4 Jul 2022 12:10:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230319AbiGDMKF (ORCPT ); Mon, 4 Jul 2022 08:10:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234328AbiGDMJW (ORCPT ); Mon, 4 Jul 2022 08:09:22 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6FB411A0C for ; Mon, 4 Jul 2022 05:08:54 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id r22so1883132pgr.2 for ; Mon, 04 Jul 2022 05:08:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kl68/Ge329JOBN8CDqlysFsOT5joX99Z+i70CGu+msw=; b=EAPUEFzYTGuwd7KwfeWIWHABSqOZA8SlZNOKkdvDAGNYKPrscnkHRezVxW6I5aU9ZE kb99aFv5etogNHOd2Zwp8kUS8EaI/8XrWsJnPKcUJaCFV5S6VXiI0nYSeM0+JEqnTasx CJlMwU/51ZCD8caQIU5SoFnuJgMDKcTiFuVBtxSTwVOzrCICJd51IzmZB5zTl3+mjtEX MNukj7W3NiuKs5eWUcPLg2I7DNtbmaINAg687PtwC+z8eKqUrkx/a9YSia7PuB3dT0NL CGTp17o5Chf/5/Z64eVeYSJWDpLT6l6RlctpUHzifEvD2IJhOcX20fTzcSuBbMiOoR/c bapQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kl68/Ge329JOBN8CDqlysFsOT5joX99Z+i70CGu+msw=; b=2qFeYMeICeGuHp0Yd/0IsQR+HiPg8HI/cLqNrJVSYACNjbRb6o3PZ15AYJir0FdiJO Fpf/lJuNbhIeP2eLUufaO/dx74sTvWC5sZFqg2SCChU5Gv5sA709xBqmu24lnbGh4/R5 D09utt70DXeC93fSyNB9cdmIw+QehctxdPyXTViuIP6jBjxl8lgm9CAwvXtyK9PwrGK4 Y8J+Dq+fd2Iifiav6pZNEAHoJEK5BU6O0q4MgGj4NY3AYqjyAWJX0GZMMvvvOH92GGsB +Q3qAxbXjvk7agMjSf8BLK2E53Jt5fCKIt9xD7Lju+j+hj3cJecfNr05yq1kSJ+OEAey AI2A== X-Gm-Message-State: AJIora9dXpBX2zj8B2qyPnvsNaqW/xuORz+/6r1dVJBmG+Dg6RyAmNFI IOntlEichBuL5+uMS5ERUbO9Sg== X-Google-Smtp-Source: AGRyM1saClCpHqIjdDI+VytCcyi2ILPZ57ZBHaO9dBX+pNGS/RIp1zb8Fj/hebHIstDpQXjporCXxQ== X-Received: by 2002:a63:de10:0:b0:411:9f90:b91f with SMTP id f16-20020a63de10000000b004119f90b91fmr21147329pgg.412.1656936534130; Mon, 04 Jul 2022 05:08:54 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id z15-20020a1709027e8f00b0015e8d4eb273sm4544753pla.189.2022.07.04.05.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:53 -0700 (PDT) From: Viresh Kumar To: Yangtao Li , "Rafael J. Wysocki" , Viresh Kumar , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Nishanth Menon , Stephen Boyd Cc: linux-pm@vger.kernel.org, Vincent Guittot , linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH V3 15/20] OPP: Migrate set-prop-name helper API to use set-config helpers Date: Mon, 4 Jul 2022 17:37:53 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" Now that we have a central API to handle all OPP table configurations, migrate the set-prop-name family of helpers to use the new infrastructure. The return type and parameter to the APIs change a bit due to this, update the current users as well in the same commit in order to avoid breaking builds. Signed-off-by: Viresh Kumar Acked-by: Samuel Holland --- drivers/cpufreq/sun50i-cpufreq-nvmem.c | 31 +++++++-------- drivers/opp/core.c | 55 +++++++++----------------- include/linux/pm_opp.h | 23 ++++++----- 3 files changed, 46 insertions(+), 63 deletions(-) diff --git a/drivers/cpufreq/sun50i-cpufreq-nvmem.c b/drivers/cpufreq/sun50= i-cpufreq-nvmem.c index 75e1bf3a08f7..a4922580ce06 100644 --- a/drivers/cpufreq/sun50i-cpufreq-nvmem.c +++ b/drivers/cpufreq/sun50i-cpufreq-nvmem.c @@ -86,20 +86,20 @@ static int sun50i_cpufreq_get_efuse(u32 *versions) =20 static int sun50i_cpufreq_nvmem_probe(struct platform_device *pdev) { - struct opp_table **opp_tables; + int *opp_tokens; char name[MAX_NAME_LEN]; unsigned int cpu; u32 speed =3D 0; int ret; =20 - opp_tables =3D kcalloc(num_possible_cpus(), sizeof(*opp_tables), + opp_tokens =3D kcalloc(num_possible_cpus(), sizeof(*opp_tokens), GFP_KERNEL); - if (!opp_tables) + if (!opp_tokens) return -ENOMEM; =20 ret =3D sun50i_cpufreq_get_efuse(&speed); if (ret) { - kfree(opp_tables); + kfree(opp_tokens); return ret; } =20 @@ -113,9 +113,9 @@ static int sun50i_cpufreq_nvmem_probe(struct platform_d= evice *pdev) goto free_opp; } =20 - opp_tables[cpu] =3D dev_pm_opp_set_prop_name(cpu_dev, name); - if (IS_ERR(opp_tables[cpu])) { - ret =3D PTR_ERR(opp_tables[cpu]); + opp_tokens[cpu] =3D dev_pm_opp_set_prop_name(cpu_dev, name); + if (opp_tokens[cpu] < 0) { + ret =3D opp_tokens[cpu]; pr_err("Failed to set prop name\n"); goto free_opp; } @@ -124,7 +124,7 @@ static int sun50i_cpufreq_nvmem_probe(struct platform_d= evice *pdev) cpufreq_dt_pdev =3D platform_device_register_simple("cpufreq-dt", -1, NULL, 0); if (!IS_ERR(cpufreq_dt_pdev)) { - platform_set_drvdata(pdev, opp_tables); + platform_set_drvdata(pdev, opp_tokens); return 0; } =20 @@ -132,27 +132,24 @@ static int sun50i_cpufreq_nvmem_probe(struct platform= _device *pdev) pr_err("Failed to register platform device\n"); =20 free_opp: - for_each_possible_cpu(cpu) { - if (IS_ERR_OR_NULL(opp_tables[cpu])) - break; - dev_pm_opp_put_prop_name(opp_tables[cpu]); - } - kfree(opp_tables); + for_each_possible_cpu(cpu) + dev_pm_opp_put_prop_name(opp_tokens[cpu]); + kfree(opp_tokens); =20 return ret; } =20 static int sun50i_cpufreq_nvmem_remove(struct platform_device *pdev) { - struct opp_table **opp_tables =3D platform_get_drvdata(pdev); + int *opp_tokens =3D platform_get_drvdata(pdev); unsigned int cpu; =20 platform_device_unregister(cpufreq_dt_pdev); =20 for_each_possible_cpu(cpu) - dev_pm_opp_put_prop_name(opp_tables[cpu]); + dev_pm_opp_put_prop_name(opp_tokens[cpu]); =20 - kfree(opp_tables); + kfree(opp_tokens); =20 return 0; } diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 458584994c2b..1745e25c1eaf 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1997,7 +1997,7 @@ static void _opp_put_supported_hw(struct opp_table *o= pp_table) } =20 /** - * dev_pm_opp_set_prop_name() - Set prop-extn name + * _opp_set_prop_name() - Set prop-extn name * @dev: Device for which the prop-name has to be set. * @name: name to postfix to properties. * @@ -2006,50 +2006,33 @@ static void _opp_put_supported_hw(struct opp_table = *opp_table) * which the extension will apply are opp-microvolt and opp-microamp. OPP = core * should postfix the property name with - while looking for them. */ -struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char = *name) +static int _opp_set_prop_name(struct opp_table *opp_table, const char *nam= e) { - struct opp_table *opp_table; - - opp_table =3D _add_opp_table(dev, false); - if (IS_ERR(opp_table)) - return opp_table; - - /* Make sure there are no concurrent readers while updating opp_table */ - WARN_ON(!list_empty(&opp_table->opp_list)); - /* Another CPU that shares the OPP table has set the property ? */ - if (opp_table->prop_name) - return opp_table; - - opp_table->prop_name =3D kstrdup(name, GFP_KERNEL); if (!opp_table->prop_name) { - dev_pm_opp_put_opp_table(opp_table); - return ERR_PTR(-ENOMEM); + opp_table->prop_name =3D kstrdup(name, GFP_KERNEL); + if (!opp_table->prop_name) + return -ENOMEM; } =20 - return opp_table; + return 0; } -EXPORT_SYMBOL_GPL(dev_pm_opp_set_prop_name); =20 /** - * dev_pm_opp_put_prop_name() - Releases resources blocked for prop-name - * @opp_table: OPP table returned by dev_pm_opp_set_prop_name(). + * _opp_put_prop_name() - Releases resources blocked for prop-name + * @opp_table: OPP table returned by _opp_set_prop_name(). * * This is required only for the V2 bindings, and is called for a matching - * dev_pm_opp_set_prop_name(). Until this is called, the opp_table structu= re + * _opp_set_prop_name(). Until this is called, the opp_table structure * will not be freed. */ -void dev_pm_opp_put_prop_name(struct opp_table *opp_table) +static void _opp_put_prop_name(struct opp_table *opp_table) { - if (unlikely(!opp_table)) - return; - - kfree(opp_table->prop_name); - opp_table->prop_name =3D NULL; - - dev_pm_opp_put_opp_table(opp_table); + if (opp_table->prop_name) { + kfree(opp_table->prop_name); + opp_table->prop_name =3D NULL; + } } -EXPORT_SYMBOL_GPL(dev_pm_opp_put_prop_name); =20 /** * _opp_set_regulators() - Set regulator names for the device @@ -2414,7 +2397,7 @@ static void _opp_clear_config(struct opp_config_data = *data) if (data->flags & OPP_CONFIG_REGULATOR_HELPER) _opp_unregister_set_opp_helper(data->opp_table); if (data->flags & OPP_CONFIG_PROP_NAME) - dev_pm_opp_put_prop_name(data->opp_table); + _opp_put_prop_name(data->opp_table); if (data->flags & OPP_CONFIG_CLK) _opp_put_clknames(data->opp_table); =20 @@ -2441,7 +2424,7 @@ static void _opp_clear_config(struct opp_config_data = *data) */ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *co= nfig) { - struct opp_table *opp_table, *err; + struct opp_table *opp_table; struct opp_config_data *data; unsigned int id; int ret; @@ -2476,11 +2459,9 @@ int dev_pm_opp_set_config(struct device *dev, struct= dev_pm_opp_config *config) =20 /* Configure property names */ if (config->prop_name) { - err =3D dev_pm_opp_set_prop_name(dev, config->prop_name); - if (IS_ERR(err)) { - ret =3D PTR_ERR(err); + ret =3D _opp_set_prop_name(opp_table, config->prop_name); + if (ret) goto err; - } =20 data->flags |=3D OPP_CONFIG_PROP_NAME; } diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 20e1e5060a8a..f995ca1406e8 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -184,8 +184,6 @@ int dev_pm_opp_set_config(struct device *dev, struct de= v_pm_opp_config *config); int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *c= onfig); void dev_pm_opp_clear_config(int token); =20 -struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char = *name); -void dev_pm_opp_put_prop_name(struct opp_table *opp_table); struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_tab= le, struct opp_table *dst_table, struct dev_pm_opp *src_opp); int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct= opp_table *dst_table, unsigned int pstate); int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq); @@ -357,13 +355,6 @@ static inline int dev_pm_opp_unregister_notifier(struc= t device *dev, struct noti return -EOPNOTSUPP; } =20 -static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *de= v, const char *name) -{ - return ERR_PTR(-EOPNOTSUPP); -} - -static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {} - static inline int dev_pm_opp_set_config(struct device *dev, struct dev_pm_= opp_config *config) { return -EOPNOTSUPP; @@ -652,5 +643,19 @@ static inline int devm_pm_opp_attach_genpd(struct devi= ce *dev, return devm_pm_opp_set_config(dev, &config); } =20 +/* prop-name helpers */ +static inline int dev_pm_opp_set_prop_name(struct device *dev, const char = *name) +{ + struct dev_pm_opp_config config =3D { + .prop_name =3D name, + }; + + return dev_pm_opp_set_config(dev, &config); +} + +static inline void dev_pm_opp_put_prop_name(int token) +{ + dev_pm_opp_clear_config(token); +} =20 #endif /* __LINUX_OPP_H__ */ --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 CED01C433EF for ; Mon, 4 Jul 2022 12:10:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233305AbiGDMKO (ORCPT ); Mon, 4 Jul 2022 08:10:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234338AbiGDMJ0 (ORCPT ); Mon, 4 Jul 2022 08:09:26 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B3331263F for ; Mon, 4 Jul 2022 05:08:57 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id x18-20020a17090a8a9200b001ef83b332f5so3224985pjn.0 for ; Mon, 04 Jul 2022 05:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/rxGDvIN/4skEVodhcHfGZ0EFBLSAZBvRwIgIUIkzN8=; b=dajE6R5ZvcmdwhTwjyhmbfXqCxtCtUxYWDvgZrz5BZ2oJj18rtQ1NIG7zb4kobbnPt kbSXYg3CRG+iNiIzam6mU3onh8IwVocUjTdXyZwzHWA5ytxIvnvcy6GwBUiohq5awZwi ATqxJ/wv3LNzbDwa2USaubJ2FCnuE3qsOhKxIccwuRX3307VuDxz9zNZZoKMJtL+MArH F/cqOZ+7vTR2Z+GSIOk3N8NxFkt5ROb+NofQKPQpLvexIQygm3YL2oafKdZKfoHdQxTB 30drebrwuOmkHWpKaXUyypffGLWsEV3NmG7Yri1fwqBY1wDhnuzc8bKFoy0RQYm95il0 PkEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/rxGDvIN/4skEVodhcHfGZ0EFBLSAZBvRwIgIUIkzN8=; b=5y7UFaysQ0mB+J0ryX2qjXMUUi8OszccFRzTN/XyQSUYlEW/z2iPWkxsqvogWVNXay pZdvoqNeo2Ug+rocxWmMiiNru9Y4UYO4kz5WpPbNolOrp2wVp4bMDfGpP1qxWF2HWeCj kOGsYW5VboQgmALeZNZ0/XkXeP3q85uI64Oqcn6P98xPsfs+WiX+9tqYsaFSZt32IiJV ztJ11VC5UFvYVez3PXMl9062CJgrV8p7hfyWsE6e6B/ZXWb4SON1Em9No0fb3gPe2cML tZA7ARvY5GsRkDRP/t7o5pENADYvAR8t10FenPORwzyBkSujVpbPtvrA7ZfUlKNSJnaU ewpQ== X-Gm-Message-State: AJIora/yMDdQfZXl5OUx3zMHWT5P2Zv1DDXm8TBNqhNlWaSq8FV55eCl N0ZGo5pyVPCIhasPewq5z2mBvQ== X-Google-Smtp-Source: AGRyM1sKdDqykdrQ/uHLjZGUdN+DL5XGqX0jMh66dHcOscKth++9OzF8v4i5N3HR1wcwBqvWwdR7mQ== X-Received: by 2002:a17:903:1250:b0:16b:9866:c2f0 with SMTP id u16-20020a170903125000b0016b9866c2f0mr33050412plh.68.1656936537087; Mon, 04 Jul 2022 05:08:57 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id y11-20020a170902d64b00b0016782c55790sm20963906plh.232.2022.07.04.05.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:56 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Dmitry Osipenko , linux-kernel@vger.kernel.org Subject: [PATCH V3 16/20] OPP: Add support for config_regulators() helper Date: Mon, 4 Jul 2022 17:37:54 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" Extend the dev_pm_opp_set_config() interface to allow adding config_regulators() helpers. This helper will be called to set the voltages of the regulators from the regular path in _set_opp(), while we are trying to change the OPP. This will eventually replace the custom set_opp() helper. Tested-by: Dmitry Osipenko Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 68 +++++++++++++++++++++++++++++++++++++++++- drivers/opp/opp.h | 2 ++ include/linux/pm_opp.h | 22 ++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 1745e25c1eaf..12bae79564f1 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1185,6 +1185,17 @@ static int _set_opp(struct device *dev, struct opp_t= able *opp_table, dev_err(dev, "Failed to set bw: %d\n", ret); return ret; } + + if (opp_table->config_regulators) { + ret =3D opp_table->config_regulators(dev, old_opp, opp, + opp_table->regulators, + opp_table->regulator_count); + if (ret) { + dev_err(dev, "Failed to set regulator voltages: %d\n", + ret); + return ret; + } + } } =20 if (opp_table->set_opp) { @@ -1202,6 +1213,17 @@ static int _set_opp(struct device *dev, struct opp_t= able *opp_table, =20 /* Scaling down? Configure required OPPs after frequency */ if (scaling_down) { + if (opp_table->config_regulators) { + ret =3D opp_table->config_regulators(dev, old_opp, opp, + opp_table->regulators, + opp_table->regulator_count); + if (ret) { + dev_err(dev, "Failed to set regulator voltages: %d\n", + ret); + return ret; + } + } + ret =3D _set_opp_bw(opp_table, opp, dev); if (ret) { dev_err(dev, "Failed to set bw: %d\n", ret); @@ -2268,6 +2290,38 @@ static void _opp_unregister_set_opp_helper(struct op= p_table *opp_table) } } =20 +/** + * _opp_set_config_regulators_helper() - Register custom set regulator hel= per. + * @dev: Device for which the helper is getting registered. + * @config_regulators: Custom set regulator helper. + * + * This is useful to support platforms with multiple regulators per device. + * + * This must be called before any OPPs are initialized for the device. + */ +static int _opp_set_config_regulators_helper(struct opp_table *opp_table, + struct device *dev, config_regulators_t config_regulators) +{ + /* Another CPU that shares the OPP table has set the helper ? */ + if (!opp_table->config_regulators) + opp_table->config_regulators =3D config_regulators; + + return 0; +} + +/** + * _opp_put_config_regulators_helper() - Releases resources blocked for + * config_regulators helper. + * @opp_table: OPP table returned from _opp_set_config_regulators_helper(). + * + * Release resources blocked for platform specific config_regulators helpe= r. + */ +static void _opp_put_config_regulators_helper(struct opp_table *opp_table) +{ + if (opp_table->config_regulators) + opp_table->config_regulators =3D NULL; +} + static void _detach_genpd(struct opp_table *opp_table) { int index; @@ -2394,8 +2448,10 @@ static void _opp_clear_config(struct opp_config_data= *data) _opp_put_regulators(data->opp_table); if (data->flags & OPP_CONFIG_SUPPORTED_HW) _opp_put_supported_hw(data->opp_table); - if (data->flags & OPP_CONFIG_REGULATOR_HELPER) + if (data->flags & OPP_CONFIG_REGULATOR_HELPER) { + _opp_put_config_regulators_helper(data->opp_table); _opp_unregister_set_opp_helper(data->opp_table); + } if (data->flags & OPP_CONFIG_PROP_NAME) _opp_put_prop_name(data->opp_table); if (data->flags & OPP_CONFIG_CLK) @@ -2476,6 +2532,16 @@ int dev_pm_opp_set_config(struct device *dev, struct= dev_pm_opp_config *config) data->flags |=3D OPP_CONFIG_REGULATOR_HELPER; } =20 + /* Configure config_regulators helper */ + if (config->config_regulators) { + ret =3D _opp_set_config_regulators_helper(opp_table, dev, + config->config_regulators); + if (ret) + goto err; + + data->flags |=3D OPP_CONFIG_REGULATOR_HELPER; + } + /* Configure supported hardware */ if (config->supported_hw) { ret =3D _opp_set_supported_hw(opp_table, config->supported_hw, diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index d652f0cc84f1..45fd40737159 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -172,6 +172,7 @@ enum opp_table_access { * @prop_name: A name to postfix to many DT properties, while parsing them. * @clk_configured: Clock name is configured by the platform. * @clk: Device's clock handle + * @config_regulators: Platform specific config_regulators() callback. * @regulators: Supply regulators * @regulator_count: Number of power supply regulators. Its value can be -1 * (uninitialized), 0 (no opp-microvolt property) or > 0 (has opp-microvolt @@ -224,6 +225,7 @@ struct opp_table { const char *prop_name; bool clk_configured; struct clk *clk; + config_regulators_t config_regulators; struct regulator **regulators; int regulator_count; struct icc_path **paths; diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index f995ca1406e8..9f2f9a792a19 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -90,11 +90,16 @@ struct dev_pm_set_opp_data { struct device *dev; }; =20 +typedef int (*config_regulators_t)(struct device *dev, + struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp, + struct regulator **regulators, unsigned int count); + /** * struct dev_pm_opp_config - Device OPP configuration values * @clk_names: Clk names, NULL terminated array, max 1 clock for now. * @prop_name: Name to postfix to properties. * @set_opp: Custom set OPP helper. + * @config_regulators: Custom set regulator helper. * @supported_hw: Array of hierarchy of versions to match. * @supported_hw_count: Number of elements in the array. * @regulator_names: Array of pointers to the names of the regulator, NULL= terminated. @@ -109,6 +114,7 @@ struct dev_pm_opp_config { const char * const *clk_names; const char *prop_name; int (*set_opp)(struct dev_pm_set_opp_data *data); + config_regulators_t config_regulators; const unsigned int *supported_hw; unsigned int supported_hw_count; const char * const *regulator_names; @@ -613,6 +619,22 @@ static inline void dev_pm_opp_unregister_set_opp_helpe= r(int token) dev_pm_opp_clear_config(token); } =20 +/* config-regulators helpers */ +static inline int dev_pm_opp_set_config_regulators(struct device *dev, + config_regulators_t helper) +{ + struct dev_pm_opp_config config =3D { + .config_regulators =3D helper, + }; + + return dev_pm_opp_set_config(dev, &config); +} + +static inline void dev_pm_opp_put_config_regulators(int token) +{ + dev_pm_opp_clear_config(token); +} + /* genpd helpers */ static inline int dev_pm_opp_attach_genpd(struct device *dev, const char * const *names, --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 37813CCA479 for ; Mon, 4 Jul 2022 12:10:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233776AbiGDMKX (ORCPT ); Mon, 4 Jul 2022 08:10:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234140AbiGDMJj (ORCPT ); Mon, 4 Jul 2022 08:09:39 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F088612083 for ; Mon, 4 Jul 2022 05:09:00 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id o15so4667634pjh.1 for ; Mon, 04 Jul 2022 05:09:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6OTH+s35Nt1rHwpbqRf4JhwqpF3oRIrQNAJMgMK39Yw=; b=zK04P3GaT+VUUatklviMx3RQPZ5FH4TAUHEC4agKXqi44pxINk1fo5Jz3fI4kka5wP FVZ8LEHy2jmA8cI3F8F+DDM+bIzgfMq2cumMWrieLIQP1VzdBp3WLiPbweQhTDpnYnOY fJuNzYwYkE0zxtQLYbh/hHHdJ94RNnYbi0S5lSwzhpli60Rwg7LuEXW2SbLGnCgw+mD1 XhqR8v9gAm2hbx1QMSYujHzvpcfyQTQs5XGj1UVAJoacNonaIj4k3mgdqzFGreidzuNO CLqkkyVdzko/02shRWuLvLcgY2BsDIrb0DCxmf1UurwWgUlmAvH6SvQslFxVioLCi4ux e4QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6OTH+s35Nt1rHwpbqRf4JhwqpF3oRIrQNAJMgMK39Yw=; b=0+sXZ3qvZXT7eGI1hWRo0/TjXEXWfIrQVVtx0cGNWbc4KjeiMJrQaKuLWQr0h1LJmJ NOa0C2Ik3XMzZTyi7pvmp2XTny8Yq5DJnztihk1aBU2/nRLR1AgZcy6BxM6tCWoyuZrY 5cGEzJGQkEET58USbEGgHflawFq+0b7lUffVz/cdR2cl3VCDIDIxD2qdAY3Vfxe9RXuW nXY6yz9/K6KtH2Ri30bE20T+VuvN7oz6F5oZu6wkRaxVs7Hvxtl6CPOOxAuCJ2phw4yc J3dHbc1zLNXKqeXc+hOGdcz+FeAEGkNJsvOskP6DjJeCoCOUCm28TLFdYmkzct2QlQpj VAWA== X-Gm-Message-State: AJIora8fjagIygbNKpiKq/lMcHvtFjRq3RDabAlLElII1Ehdp+3rvN6C GHbzqml1/PrK4Z2UOLcxjxs4WA== X-Google-Smtp-Source: AGRyM1uQhX7ZSS88GaMyGgQj5OKjal1s7Chv2oZ0wsNkkPyfPZUdJGO+kmKzgoWtdsXc2I/AeAYgXQ== X-Received: by 2002:a17:90a:fa01:b0:1ef:6e6a:4ff0 with SMTP id cm1-20020a17090afa0100b001ef6e6a4ff0mr15376041pjb.35.1656936539792; Mon, 04 Jul 2022 05:08:59 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id z2-20020a17090a66c200b001ece55b938asm10020809pjl.32.2022.07.04.05.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:59 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Dmitry Osipenko , linux-kernel@vger.kernel.org Subject: [PATCH V3 17/20] OPP: Make _generic_set_opp_regulator() a config_regulators() interface Date: Mon, 4 Jul 2022 17:37:55 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" In order to reuse the same code path, i.e. clk_set_rate() from _set_opp(), migrate _generic_set_opp_regulator() to implement a config_regulators() interface. It is renamed to _opp_config_regulator_single() and is set as the preferred config_regulators() interface whenever we have a single regulator available. Note that this also drops code responsible for restoring the voltage/freq in case of errors. We aren't handling that properly currently, restoring only some of the resources while leaving others out (like bandwidth and required OPPs). It is better to drop all of it instead of partial restoration. Tested-by: Dmitry Osipenko Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 51 +++++++++++----------------------------------- 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 12bae79564f1..5ecf077b6b17 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -896,62 +896,34 @@ static inline int _generic_set_opp_clk_only(struct de= vice *dev, struct clk *clk, return ret; } =20 -static int _generic_set_opp_regulator(struct opp_table *opp_table, - struct device *dev, - struct dev_pm_opp *opp, - unsigned long freq, - int scaling_down) +static int _opp_config_regulator_single(struct device *dev, + struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp, + struct regulator **regulators, unsigned int count) { - struct regulator *reg =3D opp_table->regulators[0]; - struct dev_pm_opp *old_opp =3D opp_table->current_opp; + struct regulator *reg =3D regulators[0]; int ret; =20 /* This function only supports single regulator per device */ - if (WARN_ON(opp_table->regulator_count > 1)) { + if (WARN_ON(count > 1)) { dev_err(dev, "multiple regulators are not supported\n"); return -EINVAL; } =20 - /* Scaling up? Scale voltage before frequency */ - if (!scaling_down) { - ret =3D _set_opp_voltage(dev, reg, opp->supplies); - if (ret) - goto restore_voltage; - } - - /* Change frequency */ - ret =3D _generic_set_opp_clk_only(dev, opp_table->clk, freq); + ret =3D _set_opp_voltage(dev, reg, new_opp->supplies); if (ret) - goto restore_voltage; - - /* Scaling down? Scale voltage after frequency */ - if (scaling_down) { - ret =3D _set_opp_voltage(dev, reg, opp->supplies); - if (ret) - goto restore_freq; - } + return ret; =20 /* * Enable the regulator after setting its voltages, otherwise it breaks * some boot-enabled regulators. */ - if (unlikely(!opp_table->enabled)) { + if (unlikely(!new_opp->opp_table->enabled)) { ret =3D regulator_enable(reg); if (ret < 0) dev_warn(dev, "Failed to enable regulator: %d", ret); } =20 return 0; - -restore_freq: - if (_generic_set_opp_clk_only(dev, opp_table->clk, old_opp->rate)) - dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n", - __func__, old_opp->rate); -restore_voltage: - /* This shouldn't harm even if the voltages weren't updated earlier */ - _set_opp_voltage(dev, reg, old_opp->supplies); - - return ret; } =20 static int _set_opp_bw(const struct opp_table *opp_table, @@ -1200,9 +1172,6 @@ static int _set_opp(struct device *dev, struct opp_ta= ble *opp_table, =20 if (opp_table->set_opp) { ret =3D _set_opp_custom(opp_table, dev, opp, freq); - } else if (opp_table->regulators) { - ret =3D _generic_set_opp_regulator(opp_table, dev, opp, freq, - scaling_down); } else { /* Only frequency scaling */ ret =3D _generic_set_opp_clk_only(dev, opp_table->clk, freq); @@ -2121,6 +2090,10 @@ static int _opp_set_regulators(struct opp_table *opp= _table, struct device *dev, } mutex_unlock(&opp_table->lock); =20 + /* Set generic config_regulators() for single regulators here */ + if (count =3D=3D 1) + opp_table->config_regulators =3D _opp_config_regulator_single; + return 0; =20 free_regulators: --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 C36E6C43334 for ; Mon, 4 Jul 2022 12:10:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233997AbiGDMKf (ORCPT ); Mon, 4 Jul 2022 08:10:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234168AbiGDMJw (ORCPT ); Mon, 4 Jul 2022 08:09:52 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4063E12776 for ; Mon, 4 Jul 2022 05:09:03 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id o5-20020a17090a3d4500b001ef76490983so4873774pjf.2 for ; Mon, 04 Jul 2022 05:09:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vAMHigCn1QN+1TDwn/mbxMoFc35nWEMDHAOhKmW0B9s=; b=Dd74ljO2SM7wVwhMJ+AQbkj7z/UCcDzXnMaoWlVaB/RQVugQB89DGMynP03Shx/C74 lKsR7mRnR7DZVUIknex094Qetz3tlJLcavKGxYuAAwKvLRypLonVVQw7Kq+bfn41T8Mr RZlk2gd8SFWG9xBBlYcyFDnV1aJ2h4L6hv6wyZFv0ICkvnmRB9LMoiLmu2L2ovCzjYUS RGFKFvEu4vISb6mLQnPAwJabrF7DoskMoSYHX62YhxKEcPLR81Vu7Ewk9E08HKHR6Rwh xiMQdA6jSdf6YZpOGTc3NVohfRY6aty60DRKmnRDTxGkZGJMCHxrnJ/TFHmqy5zOP8xG 4ZHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vAMHigCn1QN+1TDwn/mbxMoFc35nWEMDHAOhKmW0B9s=; b=m0yJFfFiGi9kcbtN1S9pwlQq/dxRB3F5Vd23kBmD5+bt+Eb42Ojw+o/5QXfVxJtSm/ j1qlDylQQnkBi3NFf6yjGJrCLjUGa/FVBukbsB0BhqcVNoC0LrImVOpCAUXX+EFOQvLr JpsUYcbfUpZzaC8l+pBRxo6IDEcU7BwGsTlc2a7wJ8D3nhvq63SnMDAjq1ILU7sq3q+M JI1Apr/N9irPDLvvZNO+saqEeG5E1IjrvSgzOAD2PXrcGYgUsm2a3VMCpjk2jHZcxhVE Xfc2QARnsmBKlWEeLdGAlUKYE904g0qXjYelLU3lg6A+XemO2VXNPdwO60ABZG/8OjDq epOQ== X-Gm-Message-State: AJIora/ydXSdOxUhCTTx3ZAO0BuCewDjHWvEm5i6AGSnHVFV3E7IJGqY XdhaH/WN0HC3kujwPO6pU80RsQ== X-Google-Smtp-Source: AGRyM1uAZ6e8I45NEVqS4vNNYKyJGPhM9CDuyTbc3Y4NHbng16Pg8T/NithFAf85w+tNz6V3FUsD4A== X-Received: by 2002:a17:90b:4b51:b0:1ec:f991:baaf with SMTP id mi17-20020a17090b4b5100b001ecf991baafmr35371632pjb.186.1656936542647; Mon, 04 Jul 2022 05:09:02 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id n19-20020a635913000000b0040df0c9a1aasm15335278pgb.14.2022.07.04.05.09.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:09:02 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Dmitry Osipenko , linux-kernel@vger.kernel.org Subject: [PATCH V3 18/20] OPP: Add dev_pm_opp_get_supplies() Date: Mon, 4 Jul 2022 17:37:56 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" We already have an API for getting voltage information for a single regulator, dev_pm_opp_get_voltage(), but there is nothing available for multiple regulator case. This patch adds a new API, dev_pm_opp_get_supplies(), to get all information related to the supplies for an OPP. Tested-by: Dmitry Osipenko Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 25 +++++++++++++++++++++++++ include/linux/pm_opp.h | 7 +++++++ 2 files changed, 32 insertions(+) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 5ecf077b6b17..3a794bff2ba1 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -117,6 +117,31 @@ unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp= *opp) } EXPORT_SYMBOL_GPL(dev_pm_opp_get_voltage); =20 +/** + * dev_pm_opp_get_supplies() - Gets the supply information corresponding t= o an opp + * @opp: opp for which voltage has to be returned for + * @supplies: Placeholder for copying the supply information. + * + * Return: negative error number on failure, 0 otherwise on success after + * setting @supplies. + * + * This can be used for devices with any number of power supplies. The cal= ler + * must ensure the @supplies array must contain space for each regulator. + */ +int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, + struct dev_pm_opp_supply *supplies) +{ + if (IS_ERR_OR_NULL(opp) || !supplies) { + pr_err("%s: Invalid parameters\n", __func__); + return -EINVAL; + } + + memcpy(supplies, opp->supplies, + sizeof(*supplies) * opp->opp_table->regulator_count); + return 0; +} +EXPORT_SYMBOL_GPL(dev_pm_opp_get_supplies); + /** * dev_pm_opp_get_power() - Gets the power corresponding to an opp * @opp: opp for which power has to be returned for diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 9f2f9a792a19..1e2b33d79ba6 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -129,6 +129,8 @@ void dev_pm_opp_put_opp_table(struct opp_table *opp_tab= le); =20 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp); =20 +int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supp= ly *supplies); + unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp); =20 unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp); @@ -217,6 +219,11 @@ static inline unsigned long dev_pm_opp_get_voltage(str= uct dev_pm_opp *opp) return 0; } =20 +static inline int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct d= ev_pm_opp_supply *supplies) +{ + return -EOPNOTSUPP; +} + static inline unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp) { return 0; --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 6F375C43334 for ; Mon, 4 Jul 2022 12:10:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234308AbiGDMKi (ORCPT ); Mon, 4 Jul 2022 08:10:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233725AbiGDMJz (ORCPT ); Mon, 4 Jul 2022 08:09:55 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E0E3120A0 for ; Mon, 4 Jul 2022 05:09:06 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id z12-20020a17090a7b8c00b001ef84000b8bso3179329pjc.1 for ; Mon, 04 Jul 2022 05:09:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VY7WoCXtSxpDy49aZW3k9T/g6ZT/rb96KiKQJSdQeqs=; b=Qou5WpDZpxl7rh70fpR5vaceWx1f44DRsmgNblwCkLosOCUFC5rJdXyWRnD7mCEkqo rwQ+Xm469DOA0nENgIUYLdYJWpwtNXudatw4pVA6PmR7+zUDbrhZhEoFa1hms+9I2agy EuEspsyljgBkSm4DprgxS3QKY9il+4iupz/IqVu32cf83bQNd+Ewe1b+sNdMWIkPNTdg dCBpy0WCdAYDBGiMtuGvQ4DyHgIA33DHPg2HRtcp8VfT3wcc9z5QONG8b76CwGAkcrsG Ah4vnrVLcKP8J+xSZR3Ged1Kv+yZnX3DfaS+XaHJrKTsKhnHnYTsPgIswtj0VkQlczRc E3bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VY7WoCXtSxpDy49aZW3k9T/g6ZT/rb96KiKQJSdQeqs=; b=gmg4jcQ2Pl3FIo2Q5R+m72MM2Ij3dgN+yEzqRZ2otosJGEU5xiG63ortcTLPQvUIeI cbHH6wc25GDLvgWNaCgPrMLBJeeqqeVh125803sRIJnWyyfwge/YijKt4fCYSlsaKDFS IyzAOlfpZq4682c7yZvpcyEanKZ6PhgPKTyZjHFevjvQVH50dLJzAaR7qySQ1yB6vguu DXMFNpLw/K4XTqKuVdJts6yl7LEOkfATkMtpfC1RlkgKyJ1GSHPyMZ9ruO/oq3SWcbVh Wwz23AJzSoSUPAJTxVKQNLekg3doQRY4/d7yUU36Z3+7imNV44xkRHm5YK3cyASzWHxq 0oJg== X-Gm-Message-State: AJIora/vNfGnjonKU14BWwJXV1Rdnofzdb2N8M7XE7+RxRIIW4gTpoBT qto8EizUIiuVY4zNr38lbZWWfw== X-Google-Smtp-Source: AGRyM1tbKd+RU3HYy4fxirhcWCGYNcGovRRk2UPexyrZl0y0paEeuQR1A7LgjSyBs66/c/0OjDGsCw== X-Received: by 2002:a17:90a:e7c1:b0:1ed:3b8c:7ced with SMTP id kb1-20020a17090ae7c100b001ed3b8c7cedmr37572078pjb.77.1656936545444; Mon, 04 Jul 2022 05:09:05 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id d17-20020a656b91000000b003c25dfd7372sm19941570pgw.26.2022.07.04.05.09.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:09:05 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org Subject: [PATCH V3 19/20] OPP: ti: Migrate to dev_pm_opp_set_config_regulators() Date: Mon, 4 Jul 2022 17:37:57 +0530 Message-Id: <9f7e72d6329095dcd2561a12e91b91b1851f5b7d.1656935522.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" The OPP core now provides dev_pm_opp_set_config_regulators() interface, which needs the platforms to just set the OPP voltages instead of both clk and voltage. The clock is set by the OPP core instead and hence reduces code redundancy. Migrate the only user of the custom set_opp() to dev_pm_opp_set_config_regulators(). Signed-off-by: Viresh Kumar --- drivers/opp/ti-opp-supply.c | 75 +++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 41 deletions(-) diff --git a/drivers/opp/ti-opp-supply.c b/drivers/opp/ti-opp-supply.c index 40ebc9ac82dd..8f3f13fbbb25 100644 --- a/drivers/opp/ti-opp-supply.c +++ b/drivers/opp/ti-opp-supply.c @@ -36,11 +36,15 @@ struct ti_opp_supply_optimum_voltage_table { * @vdd_table: Optimized voltage mapping table * @num_vdd_table: number of entries in vdd_table * @vdd_absolute_max_voltage_uv: absolute maximum voltage in UV for the su= pply + * @old_supplies: Placeholder for supplies information for old OPP. + * @new_supplies: Placeholder for supplies information for new OPP. */ struct ti_opp_supply_data { struct ti_opp_supply_optimum_voltage_table *vdd_table; u32 num_vdd_table; u32 vdd_absolute_max_voltage_uv; + struct dev_pm_opp_supply old_supplies[2]; + struct dev_pm_opp_supply new_supplies[2]; }; =20 static struct ti_opp_supply_data opp_data; @@ -266,27 +270,32 @@ static int _opp_set_voltage(struct device *dev, return 0; } =20 -/** - * ti_opp_supply_set_opp() - do the opp supply transition - * @data: information on regulators and new and old opps provided by - * opp core to use in transition - * - * Return: If successful, 0, else appropriate error value. - */ -static int ti_opp_supply_set_opp(struct dev_pm_set_opp_data *data) +/* Do the opp supply transition */ +static int ti_opp_config_regulators(struct device *dev, + struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp, + struct regulator **regulators, unsigned int count) { - struct dev_pm_opp_supply *old_supply_vdd =3D &data->old_opp.supplies[0]; - struct dev_pm_opp_supply *old_supply_vbb =3D &data->old_opp.supplies[1]; - struct dev_pm_opp_supply *new_supply_vdd =3D &data->new_opp.supplies[0]; - struct dev_pm_opp_supply *new_supply_vbb =3D &data->new_opp.supplies[1]; - struct device *dev =3D data->dev; - unsigned long old_freq =3D data->old_opp.rate, freq =3D data->new_opp.rat= e; - struct clk *clk =3D data->clk; - struct regulator *vdd_reg =3D data->regulators[0]; - struct regulator *vbb_reg =3D data->regulators[1]; + struct dev_pm_opp_supply *old_supply_vdd =3D &opp_data.old_supplies[0]; + struct dev_pm_opp_supply *old_supply_vbb =3D &opp_data.old_supplies[1]; + struct dev_pm_opp_supply *new_supply_vdd =3D &opp_data.new_supplies[0]; + struct dev_pm_opp_supply *new_supply_vbb =3D &opp_data.new_supplies[1]; + struct regulator *vdd_reg =3D regulators[0]; + struct regulator *vbb_reg =3D regulators[1]; + unsigned long old_freq, freq; int vdd_uv; int ret; =20 + /* We must have two regulators here */ + WARN_ON(count !=3D 2); + + /* Fetch supplies and freq information from OPP core */ + ret =3D dev_pm_opp_get_supplies(new_opp, opp_data.new_supplies); + WARN_ON(ret); + + old_freq =3D dev_pm_opp_get_freq(old_opp); + freq =3D dev_pm_opp_get_freq(new_opp); + WARN_ON(!old_freq || !freq); + vdd_uv =3D _get_optimal_vdd_voltage(dev, &opp_data, new_supply_vdd->u_volt); =20 @@ -303,39 +312,24 @@ static int ti_opp_supply_set_opp(struct dev_pm_set_op= p_data *data) ret =3D _opp_set_voltage(dev, new_supply_vbb, 0, vbb_reg, "vbb"); if (ret) goto restore_voltage; - } - - /* Change frequency */ - dev_dbg(dev, "%s: switching OPP: %lu Hz --> %lu Hz\n", - __func__, old_freq, freq); - - ret =3D clk_set_rate(clk, freq); - if (ret) { - dev_err(dev, "%s: failed to set clock rate: %d\n", __func__, - ret); - goto restore_voltage; - } - - /* Scaling down? Scale voltage after frequency */ - if (freq < old_freq) { + } else { ret =3D _opp_set_voltage(dev, new_supply_vbb, 0, vbb_reg, "vbb"); if (ret) - goto restore_freq; + goto restore_voltage; =20 ret =3D _opp_set_voltage(dev, new_supply_vdd, vdd_uv, vdd_reg, "vdd"); if (ret) - goto restore_freq; + goto restore_voltage; } =20 return 0; =20 -restore_freq: - ret =3D clk_set_rate(clk, old_freq); - if (ret) - dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n", - __func__, old_freq); restore_voltage: + /* Fetch old supplies information only if required */ + ret =3D dev_pm_opp_get_supplies(old_opp, opp_data.old_supplies); + WARN_ON(ret); + /* This shouldn't harm even if the voltages weren't updated earlier */ if (old_supply_vdd->u_volt) { ret =3D _opp_set_voltage(dev, old_supply_vbb, 0, vbb_reg, "vbb"); @@ -405,8 +399,7 @@ static int ti_opp_supply_probe(struct platform_device *= pdev) return ret; } =20 - ret =3D dev_pm_opp_register_set_opp_helper(cpu_dev, - ti_opp_supply_set_opp); + ret =3D dev_pm_opp_set_config_regulators(cpu_dev, ti_opp_config_regulator= s); if (ret < 0) _free_optimized_voltages(dev, &opp_data); =20 --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 09:06:42 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 37AC4C43334 for ; Mon, 4 Jul 2022 12:10:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233235AbiGDMKs (ORCPT ); Mon, 4 Jul 2022 08:10:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234218AbiGDMJ6 (ORCPT ); Mon, 4 Jul 2022 08:09:58 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE6C0120A2 for ; Mon, 4 Jul 2022 05:09:08 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id o3-20020a17090a744300b001ef8f7f3dddso918592pjk.3 for ; Mon, 04 Jul 2022 05:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CCXeMMqXv2ueskwr9AiX3zDSgl5Tmazujbdu2hn28cI=; b=B+l9aaVyvBZnrM9C9jn6t6+Xa3Gq5L62J6XNlXqVyPZshh7SYbeaVOpFsaYbxUnJKs 1FvyXvkj+TeaGSgLeu1VB/xYGWor4OKdGmqBlCH2vMnr4cXmBljHeZ3C/njOmMHqlNkA 4+uYjavLNkQMFvyBTDs8jDP3yscbFADJDelNDXFVCBVL/jPXogZdfIcl83KpVwx43sY0 61/JmCXpe6Io3OMoijI65ZDrbVcNTahSK938BtxrQHD+g/4w0mNTvNeOUpq05bkpQhB+ hILq0U0ZpW7Hr+evVtsggnlbDR4zBZ86SrolWfUK90SOk6JCtA35z12G/wS9b7mDMDLF w+Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CCXeMMqXv2ueskwr9AiX3zDSgl5Tmazujbdu2hn28cI=; b=3X3KMwryaigIVGJ7SE0VLtkw0NCtXdk2YRwIO0THHk4dCJq0EhPyUz4/YCtz6f2mav kUzfWr4UcyHe4GC5ZGQVzIhTUSKIFM6c43SPmIe4VFAM2PfFozEUZRYCaqc8i4y1Z2T0 MPLmREx4D7TAFvc4LTnzZwRhCrgd4fSo02oX+IQMzSqCaWrnh4/vK9a63TgXl25EvQ/c DEbr8PNUFu5bwEzXQD/nSqOmyo4kPIYe2WZjo1OXC038kYUbqaJRl8ihMCqVEAWSuQ16 uocAwwrSfa60o7HqykrDc4h9e5sV+msNqbSV09jB5Cvve08NpLt0JzktqrfZAeFu0okz XjYg== X-Gm-Message-State: AJIora8CUZgB+MPg8T4q/8ta/04+4mJz8ezoARNwLTzxsqdxg+LLxjhm n7ez7oWya59AuOOqATaH51hVPw== X-Google-Smtp-Source: AGRyM1v5EESwQRbGNtRH4Q4jVClkROes1qYVWShiDigZ+gU8Gck/CycG/K54DvsEYjsuOqlgTkm44A== X-Received: by 2002:a17:902:c40c:b0:16a:1a72:56c8 with SMTP id k12-20020a170902c40c00b0016a1a7256c8mr35413578plk.107.1656936548425; Mon, 04 Jul 2022 05:09:08 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id l124-20020a622582000000b00518285976cdsm20998717pfl.9.2022.07.04.05.09.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:09:08 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Dmitry Osipenko , linux-kernel@vger.kernel.org Subject: [PATCH V3 20/20] OPP: Remove custom OPP helper support Date: Mon, 4 Jul 2022 17:37:58 +0530 Message-Id: <20faa4894af53aa1a5dd8371236a978e3965862e.1656935522.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" The only user of the custom helper is migrated to use dev_pm_opp_set_config_regulators() interface. Remove the now unused custom OPP helper support. This cleans up _set_opp() and leaves a single code path to be used by all users. Tested-by: Dmitry Osipenko Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 132 +---------------------------------------- drivers/opp/opp.h | 7 --- include/linux/pm_opp.h | 51 ---------------- 3 files changed, 2 insertions(+), 188 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 3a794bff2ba1..e74bdc134c5a 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -979,36 +979,6 @@ static int _set_opp_bw(const struct opp_table *opp_tab= le, return 0; } =20 -static int _set_opp_custom(const struct opp_table *opp_table, - struct device *dev, struct dev_pm_opp *opp, - unsigned long freq) -{ - struct dev_pm_set_opp_data *data =3D opp_table->set_opp_data; - struct dev_pm_opp *old_opp =3D opp_table->current_opp; - int size; - - /* - * We support this only if dev_pm_opp_set_config() was called - * earlier to set regulators. - */ - if (opp_table->sod_supplies) { - size =3D sizeof(*old_opp->supplies) * opp_table->regulator_count; - memcpy(data->old_opp.supplies, old_opp->supplies, size); - memcpy(data->new_opp.supplies, opp->supplies, size); - data->regulator_count =3D opp_table->regulator_count; - } else { - data->regulator_count =3D 0; - } - - data->regulators =3D opp_table->regulators; - data->clk =3D opp_table->clk; - data->dev =3D dev; - data->old_opp.rate =3D old_opp->rate; - data->new_opp.rate =3D freq; - - return opp_table->set_opp(data); -} - static int _set_required_opp(struct device *dev, struct device *pd_dev, struct dev_pm_opp *opp, int i) { @@ -1195,13 +1165,7 @@ static int _set_opp(struct device *dev, struct opp_t= able *opp_table, } } =20 - if (opp_table->set_opp) { - ret =3D _set_opp_custom(opp_table, dev, opp, freq); - } else { - /* Only frequency scaling */ - ret =3D _generic_set_opp_clk_only(dev, opp_table->clk, freq); - } - + ret =3D _generic_set_opp_clk_only(dev, opp_table->clk, freq); if (ret) return ret; =20 @@ -2065,7 +2029,6 @@ static void _opp_put_prop_name(struct opp_table *opp_= table) static int _opp_set_regulators(struct opp_table *opp_table, struct device = *dev, const char * const names[]) { - struct dev_pm_opp_supply *supplies; const char * const *temp =3D names; struct regulator *reg; int count =3D 0, ret, i; @@ -2101,20 +2064,6 @@ static int _opp_set_regulators(struct opp_table *opp= _table, struct device *dev, =20 opp_table->regulator_count =3D count; =20 - supplies =3D kmalloc_array(count * 2, sizeof(*supplies), GFP_KERNEL); - if (!supplies) { - ret =3D -ENOMEM; - goto free_regulators; - } - - mutex_lock(&opp_table->lock); - opp_table->sod_supplies =3D supplies; - if (opp_table->set_opp_data) { - opp_table->set_opp_data->old_opp.supplies =3D supplies; - opp_table->set_opp_data->new_opp.supplies =3D supplies + count; - } - mutex_unlock(&opp_table->lock); - /* Set generic config_regulators() for single regulators here */ if (count =3D=3D 1) opp_table->config_regulators =3D _opp_config_regulator_single; @@ -2151,16 +2100,6 @@ static void _opp_put_regulators(struct opp_table *op= p_table) for (i =3D opp_table->regulator_count - 1; i >=3D 0; i--) regulator_put(opp_table->regulators[i]); =20 - mutex_lock(&opp_table->lock); - if (opp_table->set_opp_data) { - opp_table->set_opp_data->old_opp.supplies =3D NULL; - opp_table->set_opp_data->new_opp.supplies =3D NULL; - } - - kfree(opp_table->sod_supplies); - opp_table->sod_supplies =3D NULL; - mutex_unlock(&opp_table->lock); - kfree(opp_table->regulators); opp_table->regulators =3D NULL; opp_table->regulator_count =3D -1; @@ -2233,61 +2172,6 @@ static void _opp_put_clknames(struct opp_table *opp_= table) } } =20 -/** - * _opp_register_set_opp_helper() - Register custom set OPP helper - * @dev: Device for which the helper is getting registered. - * @set_opp: Custom set OPP helper. - * - * This is useful to support complex platforms (like platforms with multip= le - * regulators per device), instead of the generic OPP set rate helper. - * - * This must be called before any OPPs are initialized for the device. - */ -static int _opp_register_set_opp_helper(struct opp_table *opp_table, - struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data)) -{ - struct dev_pm_set_opp_data *data; - - /* Another CPU that shares the OPP table has set the helper ? */ - if (opp_table->set_opp) - return 0; - - data =3D kzalloc(sizeof(*data), GFP_KERNEL); - if (!data) - return -ENOMEM; - - mutex_lock(&opp_table->lock); - opp_table->set_opp_data =3D data; - if (opp_table->sod_supplies) { - data->old_opp.supplies =3D opp_table->sod_supplies; - data->new_opp.supplies =3D opp_table->sod_supplies + - opp_table->regulator_count; - } - mutex_unlock(&opp_table->lock); - - opp_table->set_opp =3D set_opp; - - return 0; -} - -/** - * _opp_unregister_set_opp_helper() - Releases resources blocked for set_o= pp helper - * @opp_table: OPP table returned from _opp_register_set_opp_helper(). - * - * Release resources blocked for platform specific set_opp helper. - */ -static void _opp_unregister_set_opp_helper(struct opp_table *opp_table) -{ - if (opp_table->set_opp) { - opp_table->set_opp =3D NULL; - - mutex_lock(&opp_table->lock); - kfree(opp_table->set_opp_data); - opp_table->set_opp_data =3D NULL; - mutex_unlock(&opp_table->lock); - } -} - /** * _opp_set_config_regulators_helper() - Register custom set regulator hel= per. * @dev: Device for which the helper is getting registered. @@ -2446,10 +2330,8 @@ static void _opp_clear_config(struct opp_config_data= *data) _opp_put_regulators(data->opp_table); if (data->flags & OPP_CONFIG_SUPPORTED_HW) _opp_put_supported_hw(data->opp_table); - if (data->flags & OPP_CONFIG_REGULATOR_HELPER) { + if (data->flags & OPP_CONFIG_REGULATOR_HELPER) _opp_put_config_regulators_helper(data->opp_table); - _opp_unregister_set_opp_helper(data->opp_table); - } if (data->flags & OPP_CONFIG_PROP_NAME) _opp_put_prop_name(data->opp_table); if (data->flags & OPP_CONFIG_CLK) @@ -2520,16 +2402,6 @@ int dev_pm_opp_set_config(struct device *dev, struct= dev_pm_opp_config *config) data->flags |=3D OPP_CONFIG_PROP_NAME; } =20 - /* Configure opp helper */ - if (config->set_opp) { - ret =3D _opp_register_set_opp_helper(opp_table, dev, - config->set_opp); - if (ret) - goto err; - - data->flags |=3D OPP_CONFIG_REGULATOR_HELPER; - } - /* Configure config_regulators helper */ if (config->config_regulators) { ret =3D _opp_set_config_regulators_helper(opp_table, dev, diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 45fd40737159..13abe991e811 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -182,9 +182,6 @@ enum opp_table_access { * @enabled: Set to true if the device's resources are enabled/configured. * @genpd_performance_state: Device's power domain support performance sta= te. * @is_genpd: Marks if the OPP table belongs to a genpd. - * @set_opp: Platform specific set_opp callback - * @sod_supplies: Set opp data supplies - * @set_opp_data: Data to be passed to set_opp callback * @dentry: debugfs dentry pointer of the real device directory (not links= ). * @dentry_name: Name of the real dentry. * @@ -234,10 +231,6 @@ struct opp_table { bool genpd_performance_state; bool is_genpd; =20 - int (*set_opp)(struct dev_pm_set_opp_data *data); - struct dev_pm_opp_supply *sod_supplies; - struct dev_pm_set_opp_data *set_opp_data; - #ifdef CONFIG_DEBUG_FS struct dentry *dentry; char dentry_name[NAME_MAX]; diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 1e2b33d79ba6..9d59aedc2be3 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -57,39 +57,6 @@ struct dev_pm_opp_icc_bw { u32 peak; }; =20 -/** - * struct dev_pm_opp_info - OPP freq/voltage/current values - * @rate: Target clk rate in hz - * @supplies: Array of voltage/current values for all power supplies - * - * This structure stores the freq/voltage/current values for a single OPP. - */ -struct dev_pm_opp_info { - unsigned long rate; - struct dev_pm_opp_supply *supplies; -}; - -/** - * struct dev_pm_set_opp_data - Set OPP data - * @old_opp: Old OPP info - * @new_opp: New OPP info - * @regulators: Array of regulator pointers - * @regulator_count: Number of regulators - * @clk: Pointer to clk - * @dev: Pointer to the struct device - * - * This structure contains all information required for setting an OPP. - */ -struct dev_pm_set_opp_data { - struct dev_pm_opp_info old_opp; - struct dev_pm_opp_info new_opp; - - struct regulator **regulators; - unsigned int regulator_count; - struct clk *clk; - struct device *dev; -}; - typedef int (*config_regulators_t)(struct device *dev, struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp, struct regulator **regulators, unsigned int count); @@ -98,7 +65,6 @@ typedef int (*config_regulators_t)(struct device *dev, * struct dev_pm_opp_config - Device OPP configuration values * @clk_names: Clk names, NULL terminated array, max 1 clock for now. * @prop_name: Name to postfix to properties. - * @set_opp: Custom set OPP helper. * @config_regulators: Custom set regulator helper. * @supported_hw: Array of hierarchy of versions to match. * @supported_hw_count: Number of elements in the array. @@ -113,7 +79,6 @@ struct dev_pm_opp_config { /* NULL terminated */ const char * const *clk_names; const char *prop_name; - int (*set_opp)(struct dev_pm_set_opp_data *data); config_regulators_t config_regulators; const unsigned int *supported_hw; unsigned int supported_hw_count; @@ -610,22 +575,6 @@ static inline int devm_pm_opp_set_clkname(struct devic= e *dev, const char *name) return devm_pm_opp_set_config(dev, &config); } =20 -/* set-opp helpers */ -static inline int dev_pm_opp_register_set_opp_helper(struct device *dev, - int (*set_opp)(struct dev_pm_set_opp_data *data)) -{ - struct dev_pm_opp_config config =3D { - .set_opp =3D set_opp, - }; - - return dev_pm_opp_set_config(dev, &config); -} - -static inline void dev_pm_opp_unregister_set_opp_helper(int token) -{ - dev_pm_opp_clear_config(token); -} - /* config-regulators helpers */ static inline int dev_pm_opp_set_config_regulators(struct device *dev, config_regulators_t helper) --=20 2.31.1.272.g89b43f80a514