From nobody Thu Jun 25 10:45:25 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 4802CC433F5 for ; Tue, 22 Feb 2022 14:09:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232725AbiBVOJW (ORCPT ); Tue, 22 Feb 2022 09:09:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232698AbiBVOJT (ORCPT ); Tue, 22 Feb 2022 09:09:19 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 36B2215F09A; Tue, 22 Feb 2022 06:08:54 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 033D4106F; Tue, 22 Feb 2022 06:08:54 -0800 (PST) Received: from e123648.arm.com (unknown [10.57.9.152]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B91C93F5A1; Tue, 22 Feb 2022 06:08:51 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, viresh.kumar@linaro.org, rafael@kernel.org, daniel.lezcano@linaro.org, nm@ti.com, sboyd@kernel.org, mka@chromium.org, dianders@chromium.org, robh+dt@kernel.org, devicetree@vger.kernel.org, linux-pm@vger.kernel.org Subject: [[PATCH v2 1/2] dt-bindings: opp: Add 'opp-microwatt' entry in the OPP Date: Tue, 22 Feb 2022 14:07:45 +0000 Message-Id: <20220222140746.12293-2-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220222140746.12293-1-lukasz.luba@arm.com> References: <20220222140746.12293-1-lukasz.luba@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add new entry for the OPP which provides information about power expressed in micro-Watts. It is useful for the Energy Model framework. Signed-off-by: Lukasz Luba --- Documentation/devicetree/bindings/opp/opp-v2-base.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/devicetree/bindings/opp/opp-v2-base.yaml b/Docum= entation/devicetree/bindings/opp/opp-v2-base.yaml index 15a76bcd6d42..3f07a279ed2a 100644 --- a/Documentation/devicetree/bindings/opp/opp-v2-base.yaml +++ b/Documentation/devicetree/bindings/opp/opp-v2-base.yaml @@ -93,6 +93,13 @@ patternProperties: minItems: 1 maxItems: 8 # Should be enough regulators =20 + opp-microwatt: + description: + Power for the OPP + + A value representing power for the OPP in micro-Watts. + $ref: /schemas/types.yaml#/definitions/uint32 + opp-level: description: A value representing the performance level of the device. --=20 2.17.1 From nobody Thu Jun 25 10:45:25 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 00461C433FE for ; Tue, 22 Feb 2022 14:09:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232742AbiBVOJ2 (ORCPT ); Tue, 22 Feb 2022 09:09:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232720AbiBVOJW (ORCPT ); Tue, 22 Feb 2022 09:09:22 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B1CA515F620; Tue, 22 Feb 2022 06:08:56 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8075A139F; Tue, 22 Feb 2022 06:08:56 -0800 (PST) Received: from e123648.arm.com (unknown [10.57.9.152]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4A4D23F5A1; Tue, 22 Feb 2022 06:08:54 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, viresh.kumar@linaro.org, rafael@kernel.org, daniel.lezcano@linaro.org, nm@ti.com, sboyd@kernel.org, mka@chromium.org, dianders@chromium.org, robh+dt@kernel.org, devicetree@vger.kernel.org, linux-pm@vger.kernel.org Subject: [[PATCH v2 2/2] OPP: Add 'opp-microwatt' parsing for advanced EM registration Date: Tue, 22 Feb 2022 14:07:46 +0000 Message-Id: <20220222140746.12293-3-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220222140746.12293-1-lukasz.luba@arm.com> References: <20220222140746.12293-1-lukasz.luba@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The Energy Model (EM) can be created based on DT entry: 'dynamic-power-coefficient'. It's a 'simple' EM which is limited to the dynamic power. It has to fit into the math formula which requires also information about voltage. Some of the platforms don't expose voltage information, thus it's not possible to use EM registration using DT. This patch aims to fix it. It introduces new implementation of the EM registration callback. The new mechanism parses OPP node in DT which contains the power expressed in micro-Watts. It also allows to register 'advanced' EM, which models total power (static + dynamic), so better reflects real HW. Signed-off-by: Lukasz Luba --- drivers/opp/of.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 2f40afa4e65c..94059408fa39 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -1395,6 +1395,40 @@ struct device_node *dev_pm_opp_get_of_node(struct de= v_pm_opp *opp) } EXPORT_SYMBOL_GPL(dev_pm_opp_get_of_node); =20 +/* + * Callback function provided to the Energy Model framework upon registrat= ion. + * It provides the power based on DT by @dev at @kHz if it is the frequency + * of an existing OPP, or at the frequency of the first OPP above @kHz oth= erwise + * (see dev_pm_opp_find_freq_ceil()). This function updates @kHz to the ce= iled + * frequency and @mW to the associated power. + * + * Returns 0 on success or a proper -EINVAL value in case of error. + */ +static int __maybe_unused +_get_dt_power(unsigned long *mW, unsigned long *kHz, struct device *dev) +{ + struct dev_pm_opp *opp; + unsigned long opp_freq; + u32 opp_power; + int ret; + + /* Find the right frequency and related OPP */ + opp_freq =3D *kHz * 1000; + opp =3D dev_pm_opp_find_freq_ceil(dev, &opp_freq); + if (IS_ERR(opp)) + return -EINVAL; + + ret =3D of_property_read_u32(opp->np, "opp-microwatt", &opp_power); + dev_pm_opp_put(opp); + if (ret) + return -EINVAL; + + *kHz =3D opp_freq / 1000; + *mW =3D opp_power / 1000; + + return 0; +} + /* * Callback function provided to the Energy Model framework upon registrat= ion. * This computes the power estimated by @dev at @kHz if it is the frequency @@ -1445,6 +1479,33 @@ static int __maybe_unused _get_power(unsigned long *= mW, unsigned long *kHz, return 0; } =20 +static int _of_find_opp_microwatt_property(struct device *dev) +{ + unsigned long freq =3D 0; + struct dev_pm_opp *opp; + struct device_node *np; + struct property *prop; + + /* We only support "operating-points-v2" */ + np =3D dev_pm_opp_of_get_opp_desc_node(dev); + if (!np) + return -EINVAL; + + of_node_put(np); + + /* Check if an OPP has needed property */ + opp =3D dev_pm_opp_find_freq_ceil(dev, &freq); + if (IS_ERR(opp)) + return -EINVAL; + + prop =3D of_find_property(opp->np, "opp-microwatt", NULL); + dev_pm_opp_put(opp); + if (!prop) + return -EINVAL; + + return 0; +} + /** * dev_pm_opp_of_register_em() - Attempt to register an Energy Model * @dev : Device for which an Energy Model has to be registered @@ -1474,6 +1535,15 @@ int dev_pm_opp_of_register_em(struct device *dev, st= ruct cpumask *cpus) goto failed; } =20 + /* First, try to find more precised Energy Model in DT */ + if (!_of_find_opp_microwatt_property(dev)) { + struct em_data_callback em_dt_cb =3D EM_DATA_CB(_get_dt_power); + + ret =3D em_dev_register_perf_domain(dev, nr_opp, &em_dt_cb, + cpus, true); + return ret; + } + np =3D of_node_get(dev->of_node); if (!np) { ret =3D -EINVAL; --=20 2.17.1