From: Dong Aisheng <aisheng.dong@nxp.com>
To: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, sboyd@codeaurora.org,
vireshk@kernel.org, nm@ti.com, rjw@rjwysocki.net,
shawnguo@kernel.org, Anson.Huang@nxp.com, ping.bai@nxp.com,
Dong Aisheng <aisheng.dong@nxp.com>
Subject: [PATCH 4/7] PM / OPP: use OPP node clock to set CPU frequency
Date: Thu, 24 Aug 2017 00:10:07 +0800 [thread overview]
Message-ID: <1503504610-12880-5-git-send-email-aisheng.dong@nxp.com> (raw)
In-Reply-To: <1503504610-12880-1-git-send-email-aisheng.dong@nxp.com>
If OPP node has a valid clock, we use this corresponding OPP clock to
set the device clock frequency instead of the default opp_table->clk which
is shared by all OPPs.
Cc: Viresh Kumar <vireshk@kernel.org>
Cc: Nishanth Menon <nm@ti.com>
Cc: Stephen Boyd <sboyd@codeaurora.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
---
drivers/base/power/opp/core.c | 10 +++++++++-
drivers/base/power/opp/of.c | 8 ++++++++
drivers/base/power/opp/opp.h | 3 +++
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c
index 2579401..d4656cc 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -600,7 +600,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
struct opp_table *opp_table;
unsigned long freq, old_freq;
struct dev_pm_opp *old_opp, *opp;
- struct clk *clk;
+ struct clk *clk, *old_clk = NULL;
int ret, size;
if (unlikely(!target_freq)) {
@@ -651,6 +651,11 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
goto put_old_opp;
}
+ if (!IS_ERR_OR_NULL(opp->clk)) {
+ old_clk = opp_table->cur_clk;
+ opp_table->cur_clk = opp->clk;
+ }
+
dev_dbg(dev, "%s: switching OPP: %lu Hz --> %lu Hz\n", __func__,
old_freq, freq);
@@ -683,6 +688,9 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
ret = opp_table->set_opp(data);
}
+ if (ret && !IS_ERR_OR_NULL(opp->clk))
+ opp_table->cur_clk = old_clk;
+
dev_pm_opp_put(opp);
put_old_opp:
if (!IS_ERR(old_opp))
diff --git a/drivers/base/power/opp/of.c b/drivers/base/power/opp/of.c
index 57eec1c..64909e7 100644
--- a/drivers/base/power/opp/of.c
+++ b/drivers/base/power/opp/of.c
@@ -13,6 +13,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#include <linux/clk.h>
#include <linux/cpu.h>
#include <linux/errno.h>
#include <linux/device.h>
@@ -314,6 +315,13 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev,
new_opp->dynamic = false;
new_opp->available = true;
+ new_opp->clk = of_clk_get(np, 0);
+ if (IS_ERR(new_opp->clk)) {
+ ret = PTR_ERR(new_opp->clk);
+ if (ret == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+ }
+
if (!of_property_read_u32(np, "clock-latency-ns", &val))
new_opp->clock_latency_ns = val;
diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h
index 30a637c..dbe8ec6 100644
--- a/drivers/base/power/opp/opp.h
+++ b/drivers/base/power/opp/opp.h
@@ -60,6 +60,7 @@ extern struct list_head opp_tables;
* @suspend: true if suspend OPP
* @rate: Frequency in hertz
* @supplies: Power supplies voltage/current values
+ * @clk: Clock used for this OPP
* @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's
* frequency from any other OPP's frequency.
* @opp_table: points back to the opp_table struct this opp belongs to
@@ -80,6 +81,8 @@ struct dev_pm_opp {
struct dev_pm_opp_supply *supplies;
+ struct clk *clk;
+
unsigned long clock_latency_ns;
struct opp_table *opp_table;
--
2.7.4
next prev parent reply other threads:[~2017-08-23 16:10 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-23 16:10 [PATCH 0/7] PM / OPP: per OPP node clock support and imx7ulp cpufreq driver Dong Aisheng
2017-08-23 16:10 ` [PATCH 1/7] PM / OPP: Add platform specific set_clk function Dong Aisheng
2017-09-19 22:58 ` Viresh Kumar
2017-09-20 7:03 ` Dong Aisheng
2017-09-20 20:30 ` Viresh Kumar
2017-09-21 2:17 ` A.s. Dong
2017-08-23 16:10 ` [PATCH 2/7] dt-bindings: PM / OPP: add clocks per OPP node support Dong Aisheng
2017-08-31 17:39 ` Rob Herring
2017-09-01 13:01 ` Dong Aisheng
2017-08-23 16:10 ` [PATCH 3/7] PM / OPP: rename opp_table->clk to opp_table->cur_clk Dong Aisheng
2017-08-23 16:10 ` Dong Aisheng [this message]
2017-08-23 16:10 ` [PATCH 5/7] PM / OPP: Add dev_pm_opp_get_cur_clk() Dong Aisheng
2017-08-23 16:10 ` [PATCH 6/7] cpufreq: make cpufreq_generic_init transition_latency default to CPUFREQ_ETERNAL Dong Aisheng
2017-09-19 23:10 ` Viresh Kumar
2017-09-20 7:04 ` Dong Aisheng
2017-09-20 14:45 ` Viresh Kumar
2017-08-23 16:10 ` [PATCH 7/7] cpufreq: add imx7ulp cpufreq driver Dong Aisheng
2017-09-11 7:28 ` [PATCH 0/7] PM / OPP: per OPP node clock support and " Dong Aisheng
2017-09-19 22:54 ` Viresh Kumar
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=1503504610-12880-5-git-send-email-aisheng.dong@nxp.com \
--to=aisheng.dong@nxp.com \
--cc=Anson.Huang@nxp.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=nm@ti.com \
--cc=ping.bai@nxp.com \
--cc=rjw@rjwysocki.net \
--cc=sboyd@codeaurora.org \
--cc=shawnguo@kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).