From: Dmitry Osipenko <digetx@gmail.com>
To: Thierry Reding <thierry.reding@gmail.com>,
MyungJoo Ham <myungjoo.ham@samsung.com>,
Kyungmin Park <kyungmin.park@samsung.com>,
Chanwoo Choi <cw00.choi@samsung.com>,
Jonathan Hunter <jonathanh@nvidia.com>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>
Cc: linux-clk@vger.kernel.org, linux-pm@vger.kernel.org,
linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v1 2/5] clk: Introduce clk_round_rate_unboundly()
Date: Tue, 31 Mar 2020 02:16:14 +0300 [thread overview]
Message-ID: <20200330231617.17079-3-digetx@gmail.com> (raw)
In-Reply-To: <20200330231617.17079-1-digetx@gmail.com>
In same cases it may be desired to round clock's rate without taking into
account current min/max requests made by the clock's users. One example is
building up OPP table based on a possible clock rates.
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
drivers/clk/clk.c | 49 +++++++++++++++++++++++++++++++++++----------
include/linux/clk.h | 18 +++++++++++++++++
2 files changed, 56 insertions(+), 11 deletions(-)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 39c59f063aa0..28c2e1699619 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1412,16 +1412,7 @@ unsigned long clk_hw_round_rate(struct clk_hw *hw, unsigned long rate)
}
EXPORT_SYMBOL_GPL(clk_hw_round_rate);
-/**
- * clk_round_rate - round the given rate for a clk
- * @clk: the clk for which we are rounding a rate
- * @rate: the rate which is to be rounded
- *
- * Takes in a rate as input and rounds it to a rate that the clk can actually
- * use which is then returned. If clk doesn't support round_rate operation
- * then the parent rate is returned.
- */
-long clk_round_rate(struct clk *clk, unsigned long rate)
+static long __clk_round_rate(struct clk *clk, unsigned long rate, bool bound)
{
struct clk_rate_request req;
int ret;
@@ -1434,7 +1425,13 @@ long clk_round_rate(struct clk *clk, unsigned long rate)
if (clk->exclusive_count)
clk_core_rate_unprotect(clk->core);
- clk_core_get_boundaries(clk->core, &req.min_rate, &req.max_rate);
+ if (bound) {
+ clk_core_get_boundaries(clk->core, &req.min_rate,
+ &req.max_rate);
+ } else {
+ req.min_rate = 0;
+ req.max_rate = ULONG_MAX;
+ }
req.rate = rate;
ret = clk_core_round_rate_nolock(clk->core, &req);
@@ -1449,8 +1446,38 @@ long clk_round_rate(struct clk *clk, unsigned long rate)
return req.rate;
}
+
+/**
+ * clk_round_rate - round the given rate for a clk
+ * @clk: the clk for which we are rounding a rate
+ * @rate: the rate which is to be rounded
+ *
+ * Takes in a rate as input and rounds it to a rate that the clk can actually
+ * use which is then returned. If clk doesn't support round_rate operation
+ * then the parent rate is returned.
+ */
+long clk_round_rate(struct clk *clk, unsigned long rate)
+{
+ return __clk_round_rate(clk, rate, true);
+}
EXPORT_SYMBOL_GPL(clk_round_rate);
+/**
+ * clk_round_rate_unboundly - unboundly round the given rate for a clk
+ * @clk: the clk for which we are rounding a rate
+ * @rate: the rate which is to be rounded
+ *
+ * Takes in a rate as input and rounds it to a rate that the clk can use
+ * which is then returned. The given rate isn't bounded by clk users min-max
+ * rates, unlike in a case of clk_round_rate(). If clk doesn't support
+ * round_rate operation then the parent rate is returned.
+ */
+long clk_round_rate_unboundly(struct clk *clk, unsigned long rate)
+{
+ return __clk_round_rate(clk, rate, false);
+}
+EXPORT_SYMBOL_GPL(clk_round_rate_unboundly);
+
/**
* __clk_notify - call clk notifier chain
* @core: clk that is changing rate
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 7fd6a1febcf4..b534643015f5 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -622,6 +622,19 @@ void devm_clk_put(struct device *dev, struct clk *clk);
*/
long clk_round_rate(struct clk *clk, unsigned long rate);
+/**
+ * clk_round_rate_unboundly - adjust a rate to the rate a clock can provide
+ * @clk: clock source
+ * @rate: desired clock rate in Hz
+ *
+ * This helper function rounds the given rate to a value that hardware
+ * could actually accept, without taking into account current min/max
+ * requests. Useful for cases like OPP table buildup.
+ *
+ * Returns rounded clock rate in Hz, or negative errno.
+ */
+long clk_round_rate_unboundly(struct clk *clk, unsigned long rate);
+
/**
* clk_set_rate - set the clock rate for a clock source
* @clk: clock source
@@ -857,6 +870,11 @@ static inline long clk_round_rate(struct clk *clk, unsigned long rate)
return 0;
}
+static inline long clk_round_rate_unboundly(struct clk *clk, unsigned long rate)
+{
+ return 0;
+}
+
static inline bool clk_has_parent(struct clk *clk, struct clk *parent)
{
return true;
--
2.25.1
next prev parent reply other threads:[~2020-03-30 23:20 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-30 23:16 [PATCH v1 0/5] NVIDIA Tegra devfreq drivers improvements Dmitry Osipenko
2020-03-30 23:16 ` [PATCH v1 1/5] PM / devfreq: tegra: Add Dmitry as a maintainer Dmitry Osipenko
2020-03-31 23:13 ` Chanwoo Choi
2020-04-01 18:52 ` Dmitry Osipenko
2020-03-30 23:16 ` Dmitry Osipenko [this message]
2020-04-02 0:33 ` [PATCH v1 2/5] clk: Introduce clk_round_rate_unboundly() Michał Mirosław
2020-04-02 14:21 ` Dmitry Osipenko
2020-05-27 5:55 ` Stephen Boyd
2020-05-27 17:57 ` Dmitry Osipenko
2020-05-28 0:38 ` Stephen Boyd
2020-05-27 5:57 ` Stephen Boyd
2020-03-30 23:16 ` [PATCH v1 3/5] PM / devfreq: tegra20: Use clk_round_rate_unboundly() Dmitry Osipenko
2020-03-31 23:22 ` Chanwoo Choi
2020-03-31 23:23 ` Chanwoo Choi
2020-03-30 23:16 ` [PATCH v1 4/5] PM / devfreq: tegra30: " Dmitry Osipenko
2020-03-31 23:22 ` Chanwoo Choi
2020-03-31 23:23 ` Chanwoo Choi
2020-03-30 23:16 ` [PATCH v1 5/5] PM / devfreq: tegra30: Make CPUFreq notifier to take into account boosting Dmitry Osipenko
2020-03-31 23:29 ` Chanwoo Choi
2020-04-01 18:53 ` Dmitry Osipenko
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=20200330231617.17079-3-digetx@gmail.com \
--to=digetx@gmail.com \
--cc=cw00.choi@samsung.com \
--cc=jonathanh@nvidia.com \
--cc=kyungmin.park@samsung.com \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=myungjoo.ham@samsung.com \
--cc=sboyd@kernel.org \
--cc=thierry.reding@gmail.com \
/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).