Commit graph

17 commits

Author SHA1 Message Date
Viresh Kumar cdd6ed90cd OPP: Use a single mechanism to free the OPP table
Currently there are two separate ways to free the OPP table based on how
it is created in the first place.

We call _dev_pm_opp_remove_table() to free the static and/or dynamic
OPP, OPP list devices, etc. This is done for the case where the OPP
table is added while initializing the OPPs, like via the path
dev_pm_opp_of_add_table().

We also call dev_pm_opp_put_opp_table() in some cases which eventually
frees the OPP table structure once the reference count reaches 0. This
is used by the first case as well as other cases like
dev_pm_opp_set_regulators() where the OPPs aren't necessarily
initialized at this point.

This whole thing is a bit unclear and messy and obstruct any further
cleanup/fixup of OPP core.

This patch tries to streamline this by keeping a single path for OPP
table destruction, i.e. dev_pm_opp_put_opp_table().

All the cleanup happens in _opp_table_kref_release() now after the
reference count reaches 0. _dev_pm_opp_remove_table() is removed as it
isn't required anymore.

We don't drop the reference to the OPP table after creating it from
_of_add_opp_table_v{1|2}() anymore and the same is dropped only when we
try to remove them.

Tested-by: Niklas Cassel <niklas.cassel@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2018-09-19 14:56:46 -07:00
Viresh Kumar 2a4eb7358a OPP: Don't remove dynamic OPPs from _dev_pm_opp_remove_table()
Only one platform was depending on this feature and it is already
updated now. Stop removing dynamic OPPs from _dev_pm_opp_remove_table().
This simplifies lot of paths and removes unnecessary parameters.

Tested-by: Niklas Cassel <niklas.cassel@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2018-09-19 14:56:45 -07:00
Viresh Kumar d0e8ae6c26 OPP: Create separate kref for static OPPs list
The static OPPs don't always get freed with the OPP table, it can happen
before that as well. For example, if the OPP table is first created
using helpers like dev_pm_opp_set_supported_hw() and the OPPs are
created at a later point. Now when the OPPs are removed, the OPP table
stays until the time dev_pm_opp_put_supported_hw() is called.

Later patches will streamline the freeing of OPP table and that requires
the static OPPs to get freed with help of a separate kernel reference.
This patch prepares for that by creating a separate kref for static OPPs
list.

Tested-by: Niklas Cassel <niklas.cassel@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2018-09-19 14:56:43 -07:00
Viresh Kumar f06ed90e70 OPP: Parse OPP table's DT properties from _of_init_opp_table()
Parse the DT properties present in the OPP table from
_of_init_opp_table(), which is a dedicated routine for DT parsing.

Minor relocation of helpers is required for this.

It is possible now for _managed_opp() to return a partially initialized
OPP table if the OPP table is created via the helpers like
dev_pm_opp_set_supported_hw() and we need another flag to indicate if
the static OPP are already parsed or not to make sure we don't
incorrectly skip initializing the static OPPs.

Tested-by: Niklas Cassel <niklas.cassel@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2018-09-19 14:56:42 -07:00
Viresh Kumar eb7c8743d6 OPP: Pass index to _of_init_opp_table()
This is a preparatory patch required for the next commit which will
start using OPP table's node pointer in _of_init_opp_table(), which
requires the index in order to read the OPP table's phandle.

This commit adds the index argument in the call chains in order to get
it delivered to _of_init_opp_table().

Tested-by: Niklas Cassel <niklas.cassel@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2018-09-19 14:56:41 -07:00
Viresh Kumar 404b1369ea OPP: Don't try to remove all OPP tables on failure
dev_pm_opp_of_cpumask_add_table() creates the OPP table for all CPUs
present in the cpumask and on errors it should revert all changes it has
done.

It actually is doing a bit more than that. On errors, it tries to free
all the OPP tables, even the one it hasn't created yet. This may also
end up freeing the OPP tables which were created from separate path,
like dev_pm_opp_set_supported_hw().

Reported-and-tested-by: Niklas Cassel <niklas.cassel@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2018-09-19 14:56:40 -07:00
Viresh Kumar 2fbb8670b4 OPP: Free OPP table properly on performance state irregularities
The OPP table was freed, but not the individual OPPs which is done from
_dev_pm_opp_remove_table(). Fix it by calling _dev_pm_opp_remove_table()
as well.

Cc: 4.18 <stable@vger.kernel.org> # v4.18
Fixes: 3ba98324e8 ("PM / OPP: Get performance state using genpd helper")
Tested-by: Niklas Cassel <niklas.cassel@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2018-09-19 14:56:39 -07:00
Viresh Kumar 8a352fd878 OPP: Allow same OPP table to be used for multiple genpd
The OPP binding says:

	Property: operating-points-v2

	...

	This can contain more than one phandle for power domain
	providers that provide multiple power domains. That is, one
	phandle for each power domain. If only one phandle is available,
	then the same OPP table will be used for all power domains
	provided by the power domain provider.

But the OPP core isn't allowing the same OPP table to be used for
multiple domains. Update dev_pm_opp_of_add_table_indexed() to allow
that.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
2018-05-30 15:38:21 +05:30
Dan Carpenter 6a89e012aa PM / OPP: silence an uninitialized variable warning
Smatch complains that it's possible we print "rate" in the debug output
when it hasn't been initialized.  It should be zero on that path.

Fixes: a1e8c13600 ("PM / OPP: "opp-hz" is optional for power domains")
[ Viresh: Added the Fixes tag ]
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2018-05-16 15:25:44 +05:30
Viresh Kumar 3ba98324e8 PM / OPP: Get performance state using genpd helper
The genpd core provides an API now to retrieve the performance state
from DT, use that instead of the ->get_pstate() callback.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
2018-05-09 10:15:20 +05:30
Viresh Kumar e2f4b5f8dc PM / OPP: Implement dev_pm_opp_get_of_node()
This adds a new helper to let the power domain drivers to access
opp->np, so that they can read platform specific properties from the
node.

Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
2018-05-09 10:15:19 +05:30
Viresh Kumar a88bd2a51e PM / OPP: Implement of_dev_pm_opp_find_required_opp()
A device's DT node or its OPP nodes can contain a phandle to other
device's OPP node, in the "required-opps" property.

This patch implements a routine to find that required OPP from the node
that contains the "required-opps" property.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
2018-05-09 10:15:19 +05:30
Viresh Kumar fa9b274f8a PM / OPP: Implement dev_pm_opp_of_add_table_indexed()
The "operating-points-v2" property can contain a list of phandles now,
specifically for the power domain providers that provide multiple
domains.

Add support to parse that.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
2018-05-09 10:15:18 +05:30
Viresh Kumar a1e8c13600 PM / OPP: "opp-hz" is optional for power domains
"opp-hz" property is optional for power domains now and we shouldn't
error out if it is missing for power domains.

This patch creates two new routines, _get_opp_count() and
_opp_is_duplicate(), by separating existing code from their parent
functions. Also skip duplicate OPP check for power domain OPPs as they
may not have any the "opp-hz" field, but a platform specific performance
state binding to uniquely identify OPP nodes.

By default the debugfs OPP nodes are named using the "rate" value, but
that isn't possible for the power domain OPP nodes and hence they use
the index of the OPP node in the OPP node list instead.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
2018-05-09 10:15:18 +05:30
Sudeep Holla 9867999f3a PM / OPP: add missing of_node_put() for of_get_cpu_node()
Commit 762792913f (PM / OPP: Fix get sharing CPUs when hotplug
is used) moved away from using cpu_dev->of_node because of some
limitations.

However, commit 7467c9d959 (of: return of_get_cpu_node from
of_cpu_device_node_get if CPUs are not registered) added support to
fall back to of_get_cpu_node() if called if CPUs are not registered
yet.

Add the missing of_node_put() for the CPU device nodes. Also go back
to using of_cpu_device_node_get() in dev_pm_opp_of_get_sharing_cpus()
to avoid scanning the device tree again.

Acked-by: Viresh Kumar <vireshk@kernel.org>
Fixes: 762792913f (PM / OPP: Fix get sharing CPUs when hotplug is used)
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Reviewed-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2017-10-14 00:49:41 +02:00
Tobias Jordan 7978db3447 PM / OPP: Add missing of_node_put(np)
The for_each_available_child_of_node() loop in _of_add_opp_table_v2()
doesn't drop the reference to "np" on errors. Fix that.

Fixes: 274659029c (PM / OPP: Add support to parse "operating-points-v2" bindings)
Cc: 4.3+ <stable@vger.kernel.org> # 4.3+
Signed-off-by: Tobias Jordan <Tobias.Jordan@elektrobit.com>
[ VK: Improved commit log. ]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2017-10-11 01:53:22 +02:00
Viresh Kumar 7813dd6fc7 PM / OPP: Move the OPP directory out of power/
The drivers/base/power/ directory is special and contains code related
to power management core like system suspend/resume, hibernation, etc.
It was fine to keep the OPP code inside it when we had just one file for
it, but it is growing now and already has a directory for itself.

Lets move it directly under drivers/ directory, just like cpufreq and
cpuidle.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2017-10-03 02:45:12 +02:00
Renamed from drivers/base/power/opp/of.c (Browse further)