From: Lukasz Luba <lukasz.luba@arm.com>
To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
vireshk@kernel.org, robh+dt@kernel.org
Cc: sboyd@kernel.org, nm@ti.com, rafael@kernel.org,
sudeep.holla@arm.com, daniel.lezcano@linaro.org,
Dietmar.Eggemann@arm.com, lukasz.luba@arm.com
Subject: [PATCH 3/4] OPP: Add dev_pm_opp_set_sustainable_opp_freq()
Date: Wed, 28 Oct 2020 14:08:46 +0000 [thread overview]
Message-ID: <20201028140847.1018-4-lukasz.luba@arm.com> (raw)
In-Reply-To: <20201028140847.1018-1-lukasz.luba@arm.com>
Add a new function allowing to set sustainable OPP from the drivers code.
This is helpful when the device drivers populate the OPP table by
themself.
Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
---
drivers/opp/core.c | 49 ++++++++++++++++++++++++++++++++++++++++++
include/linux/pm_opp.h | 8 +++++++
2 files changed, 57 insertions(+)
diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index bb1e68b96d0e..753443f17327 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -325,6 +325,55 @@ unsigned long dev_pm_opp_get_sustainable_opp_freq(struct device *dev)
}
EXPORT_SYMBOL_GPL(dev_pm_opp_get_sustainable_opp_freq);
+/**
+ * dev_pm_opp_set_sustainable_opp_freq() - Find and set the OPP sustainable
+ * based on given frequency
+ * @dev: device for which we do this operation
+ * @freq: frequency which OPP is going to be marked
+ *
+ * Mark the OPP of a given frequency @freq as sustainable_opp. If there is
+ * already sustainable OPP, choose the highest frequency one and set.
+ *
+ * Return: This function return 0 when the new OPP is marked as sustainable
+ * or error return value, which can be:
+ * EINVAL: for bad pointer or no match found for frequency search
+ * EEXIST: if existing sustainable OPP has higher rate
+ */
+int dev_pm_opp_set_sustainable_opp_freq(struct device *dev, unsigned long freq)
+{
+ struct opp_table *opp_table;
+ struct dev_pm_opp *opp;
+ int ret = 0;
+
+ opp = dev_pm_opp_find_freq_exact(dev, freq, true);
+ if (IS_ERR_OR_NULL(opp))
+ return -EINVAL;
+
+ opp_table = _find_opp_table(dev);
+ if (IS_ERR(opp_table))
+ return -EINVAL;
+
+ if (opp_table->sustainable_opp) {
+ /* Pick the OPP with higher rate as sustainable OPP */
+ if (opp->rate > opp_table->sustainable_opp->rate) {
+ opp_table->sustainable_opp->sustainable = false;
+ opp->sustainable = true;
+ opp_table->sustainable_opp = opp;
+ } else {
+ ret = -EEXIST;
+ }
+ } else {
+ opp->sustainable = true;
+ opp_table->sustainable_opp = opp;
+ }
+
+ dev_pm_opp_put(opp);
+ dev_pm_opp_put_opp_table(opp_table);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(dev_pm_opp_set_sustainable_opp_freq);
+
int _get_opp_count(struct opp_table *opp_table)
{
struct dev_pm_opp *opp;
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index 363d5a2c1ef3..e634a6b00e65 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -107,6 +107,8 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
unsigned long dev_pm_opp_get_sustainable_opp_freq(struct device *dev);
+int dev_pm_opp_set_sustainable_opp_freq(struct device *dev,
+ unsigned long freq);
struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
unsigned long freq,
@@ -221,6 +223,12 @@ static inline unsigned long dev_pm_opp_get_sustainable_opp_freq(struct device *d
return 0;
}
+static inline int dev_pm_opp_set_sustainable_freq(struct device *dev,
+ unsigned long freq)
+{
+ return -EOPNOTSUPP;
+}
+
static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
unsigned long freq, bool available)
{
--
2.17.1
next prev parent reply other threads:[~2020-10-28 22:27 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-28 14:08 [PATCH 0/4] Add sustainable OPP concept Lukasz Luba
2020-10-28 14:08 ` [PATCH 1/4] dt-bindings: opp: Introduce opp-sustainable bindings Lukasz Luba
2020-10-28 21:47 ` Nishanth Menon
2020-10-29 10:04 ` Lukasz Luba
2020-10-29 12:59 ` Nishanth Menon
2020-10-29 13:33 ` Lukasz Luba
2020-10-29 13:49 ` Nishanth Menon
2020-10-29 14:20 ` Lukasz Luba
2020-10-30 19:34 ` Rob Herring
2020-11-02 8:40 ` Lukasz Luba
2020-10-28 14:08 ` [PATCH 2/4] OPP: Add support for parsing the 'opp-sustainable' property Lukasz Luba
2020-10-30 11:47 ` Quentin Perret
2020-10-30 12:53 ` Lukasz Luba
2020-10-28 14:08 ` Lukasz Luba [this message]
2020-10-28 14:08 ` [PATCH 4/4] firmware: arm_scmi/perf: Mark sustainable OPP Lukasz Luba
2020-10-29 7:40 ` [PATCH 0/4] Add sustainable OPP concept Viresh Kumar
2020-10-29 7:53 ` Viresh Kumar
2020-10-29 9:56 ` Lukasz Luba
2020-10-30 8:29 ` Viresh Kumar
2020-10-30 9:19 ` Lukasz Luba
2020-10-30 9:52 ` Viresh Kumar
2020-10-30 10:56 ` Lukasz Luba
2020-10-30 11:17 ` Viresh Kumar
2020-10-30 12:40 ` Lukasz Luba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201028140847.1018-4-lukasz.luba@arm.com \
--to=lukasz.luba@arm.com \
--cc=Dietmar.Eggemann@arm.com \
--cc=daniel.lezcano@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=nm@ti.com \
--cc=rafael@kernel.org \
--cc=robh+dt@kernel.org \
--cc=sboyd@kernel.org \
--cc=sudeep.holla@arm.com \
--cc=vireshk@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®