From: Viresh Kumar <viresh.kumar@linaro.org>
To: Viresh Kumar <vireshk@kernel.org>, Nishanth Menon <nm@ti.com>,
Stephen Boyd <sboyd@kernel.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>,
linux-pm@vger.kernel.org,
Vincent Guittot <vincent.guittot@linaro.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
Dmitry Osipenko <dmitry.osipenko@collabora.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH V2 09/13] OPP: Assert clk_count == 1 for single clk helpers
Date: Tue, 5 Jul 2022 12:30:12 +0530 [thread overview]
Message-ID: <f039572f213ee49125d3d1ea4e64a94b79778426.1657003420.git.viresh.kumar@linaro.org> (raw)
In-Reply-To: <cover.1657003420.git.viresh.kumar@linaro.org>
Many helpers can be safely called only for devices that have a single
clk associated with them. Assert the same for those routines.
Tested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/opp/core.c | 45 +++++++++++++++++++++++++++++++++++++++------
1 file changed, 39 insertions(+), 6 deletions(-)
diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index e1696cf63409..5b3542557f72 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -97,6 +97,18 @@ struct opp_table *_find_opp_table(struct device *dev)
return opp_table;
}
+/*
+ * Returns true if multiple clocks aren't there, else returns false with WARN.
+ *
+ * We don't force clk_count == 1 here as there are users who don't have a clock
+ * representation in the OPP table and manage the clock configuration themselves
+ * in an platform specific way.
+ */
+static bool assert_single_clk(struct opp_table *opp_table)
+{
+ return !WARN_ON(opp_table->clk_count > 1);
+}
+
/**
* dev_pm_opp_get_voltage() - Gets the voltage corresponding to an opp
* @opp: opp for which voltage has to be returned for
@@ -181,6 +193,9 @@ unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
return 0;
}
+ if (!assert_single_clk(opp->opp_table))
+ return 0;
+
return opp->rates[0];
}
EXPORT_SYMBOL_GPL(dev_pm_opp_get_freq);
@@ -601,7 +616,8 @@ static struct dev_pm_opp *_find_key_floor(struct device *dev,
struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
unsigned long freq, bool available)
{
- return _find_key_exact(dev, freq, 0, available, _read_freq, NULL);
+ return _find_key_exact(dev, freq, 0, available, _read_freq,
+ assert_single_clk);
}
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_exact);
@@ -609,7 +625,7 @@ static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table,
unsigned long *freq)
{
return _opp_table_find_key_ceil(opp_table, freq, 0, true, _read_freq,
- NULL);
+ assert_single_clk);
}
/**
@@ -633,7 +649,7 @@ static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table,
struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
unsigned long *freq)
{
- return _find_key_ceil(dev, freq, 0, true, _read_freq, NULL);
+ return _find_key_ceil(dev, freq, 0, true, _read_freq, assert_single_clk);
}
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil);
@@ -658,7 +674,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil);
struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
unsigned long *freq)
{
- return _find_key_floor(dev, freq, 0, true, _read_freq, NULL);
+ return _find_key_floor(dev, freq, 0, true, _read_freq, assert_single_clk);
}
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor);
@@ -1521,6 +1537,9 @@ void dev_pm_opp_remove(struct device *dev, unsigned long freq)
if (IS_ERR(opp_table))
return;
+ if (!assert_single_clk(opp_table))
+ goto put_table;
+
mutex_lock(&opp_table->lock);
list_for_each_entry(iter, &opp_table->opp_list, node) {
@@ -1542,6 +1561,7 @@ void dev_pm_opp_remove(struct device *dev, unsigned long freq)
__func__, freq);
}
+put_table:
/* Drop the reference taken by _find_opp_table() */
dev_pm_opp_put_opp_table(opp_table);
}
@@ -1868,6 +1888,9 @@ int _opp_add_v1(struct opp_table *opp_table, struct device *dev,
unsigned long tol;
int ret;
+ if (!assert_single_clk(opp_table))
+ return -EINVAL;
+
new_opp = _opp_allocate(opp_table);
if (!new_opp)
return -ENOMEM;
@@ -2721,6 +2744,11 @@ static int _opp_set_availability(struct device *dev, unsigned long freq,
return r;
}
+ if (!assert_single_clk(opp_table)) {
+ r = -EINVAL;
+ goto put_table;
+ }
+
mutex_lock(&opp_table->lock);
/* Do we have the frequency? */
@@ -2792,6 +2820,11 @@ int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
return r;
}
+ if (!assert_single_clk(opp_table)) {
+ r = -EINVAL;
+ goto put_table;
+ }
+
mutex_lock(&opp_table->lock);
/* Do we have the frequency? */
@@ -2823,11 +2856,11 @@ int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
opp);
dev_pm_opp_put(opp);
- goto adjust_put_table;
+ goto put_table;
adjust_unlock:
mutex_unlock(&opp_table->lock);
-adjust_put_table:
+put_table:
dev_pm_opp_put_opp_table(opp_table);
return r;
}
--
2.31.1.272.g89b43f80a514
next prev parent reply other threads:[~2022-07-05 7:01 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-05 7:00 [PATCH V2 00/13] OPP: Add support for multiple clocks* Viresh Kumar
2022-07-05 7:00 ` [PATCH V2 01/13] OPP: Use consistent names for OPP table instances Viresh Kumar
2022-07-05 7:00 ` [PATCH V2 02/13] OPP: Remove rate_not_available parameter to _opp_add() Viresh Kumar
2022-07-05 7:00 ` [PATCH V2 03/13] OPP: Reuse _opp_compare_key() in _opp_add_static_v2() Viresh Kumar
2022-07-05 7:00 ` [PATCH V2 04/13] OPP: Make dev_pm_opp_set_opp() independent of frequency Viresh Kumar
2022-07-05 7:00 ` [PATCH V2 05/13] dt-bindings: opp: accept array of frequencies Viresh Kumar
2022-07-05 7:00 ` [PATCH V2 06/13] OPP: Allow multiple clocks for a device Viresh Kumar
2022-07-05 7:00 ` [PATCH V2 07/13] OPP: Compare bandwidths for all paths in _opp_compare_key() Viresh Kumar
2022-07-05 7:00 ` [PATCH V2 08/13] OPP: Add key specific assert() method to key finding helpers Viresh Kumar
2022-07-05 7:00 ` Viresh Kumar [this message]
2022-07-05 17:21 ` [PATCH V2 09/13] OPP: Assert clk_count == 1 for single clk helpers Krzysztof Kozlowski
2022-07-06 6:39 ` Viresh Kumar
2022-07-05 7:00 ` [PATCH V2 10/13] OPP: Provide a simple implementation to configure multiple clocks Viresh Kumar
2022-07-05 7:00 ` [PATCH V2 11/13] OPP: Allow config_clks helper for single clk case Viresh Kumar
2022-07-05 7:00 ` [PATCH V2 12/13] PM / devfreq: tegra30: Register config_clks helper Viresh Kumar
2022-07-05 7:00 ` [PATCH V2 13/13] OPP: Remove dev{m}_pm_opp_of_add_table_noclk() Viresh Kumar
2022-07-07 19:43 ` [PATCH V2 00/13] OPP: Add support for multiple clocks* Dmitry Osipenko
2022-07-08 7:19 ` Viresh Kumar
2022-07-08 7:26 ` Dmitry Osipenko
2022-07-08 7:30 ` Dmitry Osipenko
2022-07-08 8:13 ` Viresh Kumar
2022-07-08 8:12 ` Viresh Kumar
2022-07-08 16:15 ` Dmitry Osipenko
2022-07-11 16:40 ` Johan Hovold
2022-07-12 7:52 ` Viresh Kumar
2022-07-12 12:25 ` Manivannan Sadhasivam
2022-07-12 14:29 ` Johan Hovold
2022-07-12 15:10 ` Viresh Kumar
2022-07-12 15:55 ` Johan Hovold
2022-07-13 6:55 ` 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=f039572f213ee49125d3d1ea4e64a94b79778426.1657003420.git.viresh.kumar@linaro.org \
--to=viresh.kumar@linaro.org \
--cc=dmitry.osipenko@collabora.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=nm@ti.com \
--cc=rafael@kernel.org \
--cc=sboyd@kernel.org \
--cc=vincent.guittot@linaro.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).