History log of /linux-master/drivers/base/power/clock_ops.c
Revision Date Author Comments
# db2292b0 19-Dec-2023 Greg Kroah-Hartman <gregkh@linuxfoundation.org>

PM: clk: make pm_clk_add_notifier() take a const pointer

The driver core wants to work with const struct bus_type, so there's no
reason that pm_clk_add_notifier() should not also do the same thing,
considering that it just passes the pointer off to the driver core which
is expecting a const *.

Cc: Rafael J. Wysocki <rafael@kernel.org>
Link: https://lore.kernel.org/r/2023121922-triumph-exploit-f545@gregkh
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# a649136b 31-Jul-2021 Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

PM: runtime: add devm_pm_clk_create helper

A typical code pattern for pm_clk_create() call is to call it in the
_probe function and to call pm_clk_destroy() both from _probe error path
and from _remove function. For some drivers the whole remove function
would consist of the call to pm_remove_disable().

Add helper function to replace this bolierplate piece of code. Calling
devm_pm_clk_create() removes the need for calling pm_clk_destroy() both
in the probe()'s error path and in the remove() function.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://lore.kernel.org/r/20210731195034.979084-3-dmitry.baryshkov@linaro.org
Acked-by: Rafael J. Wysocki <rafael@kernel.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>


# 33b688e3 31-Mar-2021 Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>

PM: clk: remove kernel-doc warning

Remove make W=1 warning:

drivers/base/power/clock_ops.c:148: warning: expecting prototype for
pm_clk_enable(). Prototype was for __pm_clk_enable() instead

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 0bfa0820 25-Jan-2021 Nicolas Pitre <npitre@baylibre.com>

PM: clk: make PM clock layer compatible with clocks that must sleep

The clock API splits its interface into sleepable ant atomic contexts:

- clk_prepare/clk_unprepare for stuff that might sleep

- clk_enable_clk_disable for anything that may be done in atomic context

The code handling runtime PM for clocks only calls clk_disable() on
suspend requests, and clk_enable on resume requests. This means that
runtime PM with clock providers that only have the prepare/unprepare
methods implemented is basically useless.

Many clock implementations can't accommodate atomic contexts. This is
often the case when communication with the clock happens through another
subsystem like I2C or SCMI.

Let's make the clock PM code useful with such clocks by safely invoking
clk_prepare/clk_unprepare upon resume/suspend requests. Of course, when
such clocks are registered with the PM layer then pm_runtime_irq_safe()
can't be used, and neither pm_runtime_suspend() nor pm_runtime_resume()
may be invoked in atomic context.

For clocks that do implement the enable and disable methods then
everything just works as before.

A note on sparse:
According to https://lwn.net/Articles/109066/ there are things
that sparse can't cope with. In particular, pm_clk_op_lock() and
pm_clk_op_unlock() may or may not lock/unlock psd->lock depending on
some runtime condition. To work around that we tell it the lock is
always untaken for the purpose of static analisys.

Thanks to Naresh Kamboju for reporting issues with the initial patch.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Tested-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 338c993f 27-May-2019 Geert Uytterhoeven <geert+renesas@glider.be>

PM / clk: Remove error message on out-of-memory condition

There is no need to print an error message if kstrdup() fails, as the
memory allocation core already takes care of that.

Note that commit 59d84ca8c46a93ad ("PM / OPP / clk: Remove unnecessary
OOM message") already removed similar error messages, but this one was
forgotten.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 7e186d9d 27-May-2019 Kefeng Wang <wangkefeng.wang@huawei.com>

drivers: base: power: clock_ops: Use of_clk_get_parent_count()

Use of_clk_get_parent_count() instead of open coding.

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 5de363b6 02-Apr-2019 Greg Kroah-Hartman <gregkh@linuxfoundation.org>

drivers: base: power: add proper SPDX identifiers on files that did not have them.

There were a few files in the driver core power code that did not have
SPDX identifiers on them, so fix that up. At the same time, remove the
"free form" text that specified the license of the file, as that is
impossible for any tool to properly parse.

Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 40619f7d 05-Jan-2019 Aditya Pakki <pakki001@umn.edu>

PM: clock_ops: fix missing clk_prepare() return value check

clk_prepare() can fail, so check its status and if it fails,
issue an error message and change the clock_entry_status to
PCE_STATUS_ERROR.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
[ rjw: Subject ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 5e2e2f9f 23-Aug-2018 Dan Carpenter <dan.carpenter@oracle.com>

PM / clk: signedness bug in of_pm_clk_add_clks()

"count" needs to be signed for the error handling to work. I made "i"
signed as well so they match.

Fixes: 02113ba93ea4 (PM / clk: Add support for obtaining clocks from device-tree)
Cc: 4.6+ <stable@vger.kernel.org> # 4.6+
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 498b5fdd 21-Jun-2016 Jon Hunter <jonathanh@nvidia.com>

PM / clk: Add support for adding a specific clock from device-tree

Some drivers using the PM clocks framework need to add specific clocks
from device-tree using a name by calling the functions
of_clk_get_by_name() and then pm_clk_add_clk(). Rather than having
drivers call both functions, add a helper function of_pm_clk_add_clk()
that will call these functions so drivers can call a single function
to add a specific clock from device-tree.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 29b968b2 05-Jun-2016 Paul Gortmaker <paul.gortmaker@windriver.com>

PM / clk: export symbols for existing pm_clk_<...> API fcns

While trying to convert a DMA driver from bool to tristate, we
encountered the following:

ERROR: "pm_clk_add_clk" [drivers/dma/tegra210-adma.ko] undefined!
ERROR: "pm_clk_create" [drivers/dma/tegra210-adma.ko] undefined!
ERROR: "pm_clk_destroy" [drivers/dma/tegra210-adma.ko] undefined!
ERROR: "pm_clk_suspend" [drivers/dma/tegra210-adma.ko] undefined!
ERROR: "pm_clk_resume" [drivers/dma/tegra210-adma.ko] undefined!

Since in principle there is nothing preventing these functions
from being used in modular code as well as builtin, we add the
export of them. We expand the scope to also include:

pm_clk_add
of_pm_clk_add_clks
pm_clk_remove
pm_clk_remove_clk
pm_clk_init
pm_clk_runtime_suspend
pm_clk_runtime_resume
pm_clk_add_notifier

...since these functions are also non-static and presumably form
part of the existing API used by other drivers that may become
modular in the future.

Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 0b26985a 16-Apr-2016 Colin Ian King <colin.king@canonical.com>

PM / clk: ensure we don't allocate a -ve size of count clks

It is entirely possible for of_count_phandle_wit_args to
return a -ve error return value so we need to check for this
otherwise we end up allocating a negative number of clk objects.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 02113ba9 15-Mar-2016 Jon Hunter <jonathanh@nvidia.com>

PM / clk: Add support for obtaining clocks from device-tree

The PM clocks framework requires clients to pass either a con-id or a
valid clk pointer in order to add a clock to a device. Add a new
function of_pm_clk_add_clks() to allows device clocks to be retrieved
from device-tree and populated for a given device. Note that it is
not necessary to make the compilation of this new function dependent
upon CONFIG_OF because there are stubs functions for the device-tree
APIs used.

In order to handle errors encountered when adding clocks from
device-tree, add a function pm_clk_remove_clk() to remove any clocks
(using a pointer to the clk structure) that have been added
successfully before the error occurred.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Acked-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 989561de 07-Jan-2016 Tomeu Vizoso <tomeu.vizoso@collabora.com>

PM / Domains: add setter for dev.pm_domain

Adds a function that sets the pointer to dev_pm_domain in struct device
and that warns if the device has already finished probing. The reason
why we want to enforce that is because in the general case that can
cause problems and also that we can simplify code quite a bit if we can
always assume that.

This patch also changes all current code that directly sets the
dev.pm_domain pointer.

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# d35818a9 06-Jan-2016 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

PM / clk: don't leave clocks enabled when driver not bound

There is a new notification BUS_NOTIFY_DRIVER_NOT_BOUND that is issued when
driver fails during binding. In such case pm_clk_notify(), when PM_CLK=n,
leaves clocks enabled. Undo operations that have been done in
BUS_NOTIFY_BIND_DRIVER case.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# a6175616 19-Oct-2015 Geert Uytterhoeven <geert@linux-m68k.org>

PM / clk: Fix broken build due to non-matching code and header #ifdefs

If an architecture's main Kconfig file doesn't include
kernel/power/Kconfig, but CONFIG_PM=y and HAVE_CLK=y (e.g. m68knommu
allmodconfig):

drivers/base/power/clock_ops.c: In function ‘__pm_clk_add’:
drivers/base/power/clock_ops.c:106: error: ‘struct pm_subsys_data’ has no member named ‘clock_list’
drivers/base/power/clock_ops.c: At top level:
drivers/base/power/clock_ops.c:120: error: redefinition of ‘pm_clk_add’
include/linux/pm_clock.h:64: error: previous definition of ‘pm_clk_add’ was here
drivers/base/power/clock_ops.c:135: error: redefinition of ‘pm_clk_add_clk’
include/linux/pm_clock.h:69: error: previous definition of ‘pm_clk_add_clk’ was here
drivers/base/power/clock_ops.c:171: error: redefinition of ‘pm_clk_remove’
include/linux/pm_clock.h:73: error: previous definition of ‘pm_clk_remove’ was here
drivers/base/power/clock_ops.c: In function ‘pm_clk_remove’:
drivers/base/power/clock_ops.c:180: error: ‘struct pm_subsys_data’ has no member named ‘clock_list’
drivers/base/power/clock_ops.c:180: error: ‘struct pm_subsys_data’ has no member named ‘clock_list’
drivers/base/power/clock_ops.c: At top level:
drivers/base/power/clock_ops.c:207: error: redefinition of ‘pm_clk_init’
include/linux/pm_clock.h:54: error: previous definition of ‘pm_clk_init’ was here
drivers/base/power/clock_ops.c: In function ‘pm_clk_init’:
drivers/base/power/clock_ops.c:210: error: ‘struct pm_subsys_data’ has no member named ‘clock_list’
drivers/base/power/clock_ops.c: At top level:
drivers/base/power/clock_ops.c:221: error: redefinition of ‘pm_clk_create’
include/linux/pm_clock.h:57: error: previous definition of ‘pm_clk_create’ was here
drivers/base/power/clock_ops.c:234: error: redefinition of ‘pm_clk_destroy’
include/linux/pm_clock.h:61: error: previous definition of ‘pm_clk_destroy’ was here
drivers/base/power/clock_ops.c: In function ‘pm_clk_destroy’:
drivers/base/power/clock_ops.c:246: error: ‘struct pm_subsys_data’ has no member named ‘clock_list’
drivers/base/power/clock_ops.c:246: error: ‘struct pm_subsys_data’ has no member named ‘clock_list’
drivers/base/power/clock_ops.c: At top level:
drivers/base/power/clock_ops.c:263: error: expected identifier or ‘(’ before ‘void’
drivers/base/power/clock_ops.c:263: error: expected ‘)’ before numeric constant
drivers/base/power/clock_ops.c:293: error: expected identifier or ‘(’ before ‘void’
drivers/base/power/clock_ops.c:293: error: expected ‘)’ before numeric constant
drivers/base/power/clock_ops.c: In function ‘pm_clk_runtime_suspend’:
drivers/base/power/clock_ops.c:384: error: called object ‘0u’ is not a function
drivers/base/power/clock_ops.c: In function ‘pm_clk_runtime_resume’:
drivers/base/power/clock_ops.c:400: error: called object ‘0u’ is not a function

This happens because:
- drivers/base/power/clock_ops.c depends on CONFIG_HAVE_CLK,
- the failing code inside clock_ops.c additionally depends on
CONFIG_PM,
- the forward declarations and other definitions in <linux/pm_clock.h>
depend on CONFIG_PM_CLK,
- CONFIG_PM_CLK is defined as PM && HAVE_CLK in kernel/power/Kconfig,
but it is not included on all architectures.

Fix this by protecting the failing code inside clock_ops.c by
CONFIG_PM_CLK instead of CONFIG_PM, so it matches <linux/pm_clock.h>.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 772b0508 01-Oct-2015 Stephen Boyd <sboyd@codeaurora.org>

PM / clk: Do not __clk_get passed in clock-references

Clock references are on a per-user basis now, so they are not supposed
to be refcounted by itself anymore. Therefore multiple cascaded get and
put calls will fail.

When a clock reference gets passed into pm_clk_add_clk we can assume
that the pm clock handling will take control of the clock reference,
so after this functions returns the caller should've given up control
of that handle.

So remove the additional call to __clk_get() in __pm_clk_add().

The only current user of pm_clk_add_clk is drivers/clk/shmobile/clk-mstp.c
which already follows this paradigm by only getting the clock but not
puting it after passing the reference into pm_clk_add_clk.

In the error case the caller is expected to clean up the clock, as it
may very well try to do something different if pm_clk_add_clk() fails.

Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
[add commit-message]
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# f4745a92 29-Jun-2015 Colin Ian King <colin.king@canonical.com>

PM / clk: don't return int on __pm_clk_enable()

Static analysis by cppcheck found an issue that was recently introduced by
commit 471f7707b6f0b1 ("PM / clock_ops: make __pm_clk_enable more generic")
where a return status in ret was not being initialised and garbage
being returned when ce->status >= PCE_STATUS_ERROR.

The fact that ret is not being checked by the caller and that
ret is only used internally __pm_clk_enable() to check if clk_enable()
was OK means we can ignore returning it instead turn
__pm_clk_enable() into function with a void return.

Fixes: 471f7707b6f0b1 ("PM / clock_ops: make __pm_clk_enable more generic")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# f17f4adf 29-May-2015 Geert Uytterhoeven <geert+renesas@glider.be>

PM / clk: Print acquired clock name in addition to con_id

Currently the con_id of the acquired clock is printed for debugging
purposes. But in several cases, the con_id is NULL, which doesn't
provide much debugging information when printed. These cases are:
- When explicitly passing a NULL con_id (which means the first clock
tied to the device, if available),
- When not using pm_clk_add(), but pm_clk_add_clk() (which takes a
"struct clk *" directly).

Hence print the actual clock name in addition to (and not instead of;
thanks Grygorii Strashko!) the con_id.

Note that the clock name is not available with legacy clock frameworks,
and the hex pointer address will be printed instead.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Grygorii Strashko <grygorii.strashko@linaro.org>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 3fc3a0be 08-May-2015 Geert Uytterhoeven <geert+renesas@glider.be>

PM / clk: Fix clock error check in __pm_clk_add()

In the final iteration of commit 245bd6f6af8a62a2 ("PM / clock_ops: Add
pm_clk_add_clk()"), a refcount increment was added by Grygorii Strashko.
However, the accompanying IS_ERR() check operates on the wrong clock
pointer, which is always zero at this point, i.e. not an error.
This may lead to a NULL pointer dereference later, when __clk_get()
tries to dereference an error pointer.

Check the passed clock pointer instead to fix this.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Fixes: 245bd6f6af8a62a2 ("PM / clock_ops: Add pm_clk_add_clk()")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 75f50400 23-Apr-2015 Rajendra Nayak <rnayak@codeaurora.org>

PM / clock_ops: Provide default runtime ops to users

Most users of PM clocks do the extact same things in the runtime
suspend/resume callbacks. Provide them USE_PM_CLK_RUNTIME_OPS so
as to avoid/remove boilerplate code.

Signed-off-by: Rajendra Nayak <rnayak@codeaurora.org>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
Acked-by: Santosh Shilimkar <ssantosh@kernel.org>
Acked-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 59d84ca8 09-Feb-2015 Quentin Lambert <lambert.quentin@gmail.com>

PM / OPP / clk: Remove unnecessary OOM message

This patch reduces the kernel size by removing error messages that duplicate
the normal OOM message.

A simplified version of the semantic patch that finds this problem is as
follows: (http://coccinelle.lip6.fr)

@@
identifier f,print,l;
expression e;
constant char[] c;
@@

e = \(kzalloc\|kmalloc\|devm_kzalloc\|devm_kmalloc\)(...);
if (e == NULL) {
<+...
- print(...,c,...);
... when any
(
goto l;
|
return ...;
)
...+> }

Signed-off-by: Quentin Lambert <lambert.quentin@gmail.com>
Acked-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# d30d819d 27-Nov-2014 Rafael J. Wysocki <rafael.j.wysocki@intel.com>

PM: Drop CONFIG_PM_RUNTIME from the driver core

After commit b2b49ccbdd54 (PM: Kconfig: Set PM_RUNTIME if PM_SLEEP is
selected) PM_RUNTIME is always set if PM is set, so quite a few
depend on CONFIG_PM or even may be dropped entirely in some cases.

Replace CONFIG_PM_RUNTIME with CONFIG_PM in the PM core code.

Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Acked-by: Kevin Hilman <khilman@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 471f7707 06-Nov-2014 Strashko, Grygorii <grygorii.strashko@ti.com>

PM / clock_ops: make __pm_clk_enable more generic

Now there are two places in code which do the same things,
so allow __pm_clk_enable() to accept pointer on pm_clock_entry
structure as second parameter instead of pointer on clock and
remove duplicated code.

Also, updated function intended to be used by following patch.

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 245bd6f6 06-Nov-2014 Geert Uytterhoeven <geert+renesas@glider.be>

PM / clock_ops: Add pm_clk_add_clk()

The existing pm_clk_add() allows to pass a clock by con_id. However,
when referring to a specific clock from DT, no con_id is available.

Add pm_clk_add_clk(), which allows to specify the struct clk * directly.
The will will increment refcount on clock pointer, so the caller has
to use clk_put() on clock pointer when done.

Reviewed-by: Santosh Shilimkar <santosh.shilimkar@ti.com>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# a968bed7 01-Oct-2014 Geert Uytterhoeven <geert+renesas@glider.be>

PM / clk: Fix crash in clocks management code if !CONFIG_PM_RUNTIME

Unlike the clocks management code for runtime PM, the code used for
system suspend does not check the pm_clock_entry.status field.
If pm_clk_acquire() failed, ce->status will be PCE_STATUS_ERROR, and
ce->clk will be a negative error code (e.g. 0xfffffffe = -2 = -ENOENT).

Depending on the clock implementation, suspend or resume may crash with:

Unable to handle kernel NULL pointer dereference at virtual address 00000026

(CCF clk_disable() has an IS_ERR_OR_NULL() check, while CCF clk_enable()
only has a NULL check; pre-CCF implementations may behave differently)

While just checking for PCE_STATUS_ERROR would be sufficient, it doesn't
hurt to use the same state machine as is done for runtime PM, as this
makes the two versions more similar, and eligible for a future
consolidation.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 4272b961 21-Jan-2014 Paul Gortmaker <paul.gortmaker@windriver.com>

drivers/base: delete non-required instances of include <linux/init.h>

None of these files are actually using any __init type directives
and hence don't need to include <linux/init.h>. Most are just a
left over from __devinit and __cpuinit removal, or simply due to
code getting copied from one driver to the next.

Cc: Len Brown <len.brown@intel.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Pavel Machek <pavel@ucw.cz>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Mark Brown <broonie@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 5cda3fbb 13-Jan-2014 Ben Dooks <ben.dooks@codethink.co.uk>

PM / clock_ops: report clock errors from clk_enable()

If clk_enable() fails, then print a message so that the user can see
what is happening instead of silently failing to enable the clock.

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
Reviewed-by: Ian Molton <ian.molton@codethink.co.uk>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# afdd3ab3 13-Jan-2014 Ben Dooks <ben.dooks@codethink.co.uk>

PM / clock_ops: check return of clk_enable() in pm_clk_resume()

The clk_enable() call in the pm_clk_resume() call returns an error
that is not being checked. If clk_enable() fails then we should
not set the state of the clock to PCE_STATUS_ENABLED.

Note, the issue of warning the user if this fails has not been
addressed in this patch as this is not the only place the driver
calls clk_enable().

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
Reviewed-by: Ian Molton <ian.molton@codethink.co.uk>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 8a6720ec 13-Jan-2014 Ben Dooks <ben.dooks@codethink.co.uk>

PM / clock_ops: fix up clk prepare/unprepare count

The drivers/base/power/clock_ops.c file is causing warnings from
the clock driver (as shown below) due to failing to do a clk_prepare()
call before enabling a clock. It also fails to check the balance of
prepare/unprepare as __pm_clk_remove() do clk_disable_unprepare() call.

This bug has probably been in since commit b2476490e ("clk: introduce
the common clock framework") as the warning was part of the original
commit. It is strange that it has not been noticed (although this has
also been coupled with a failure for certain SH builds to not build the
necessary glue to use this method of controlling the clocks).

In summary, this is probably needed in several stable branches but need
advice on which ones.

On the Renesas Lager board, this causes numerous warnings of the following
and even worse the clock system will not enable clocks, causing drivers
that are in development to fail to work:

WARNING: CPU: 0 PID: 1 at drivers/clk/clk.c:883 __clk_enable+0x2c/0xa0()

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
Reviewed-by: Ian Molton <ian.molton@codethink.co.uk>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# c122f27e 22-Oct-2012 Murali Karicheri <m-karicheri2@ti.com>

base: power - use clk_prepare_enable and clk_prepare_disable

When PM runtime is enabled in DaVinci and the machine migrates to
common clk framework, the clk_enable() gets called without
clk_prepare(). This patch is to fix this issue so that PM run
time can inter work with common clk framework.

Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 77254950 07-Aug-2012 Rafael J. Wysocki <rjw@rjwysocki.net>

PM: Make dev_pm_get_subsys_data() always return 0 on success

Commits 1d5fcfec22 (PM / Domains: Add device domain data reference
counter) and 62d4490294 (PM / Domains: Allow device callbacks to be
added at any time) added checks for the return value of
dev_pm_get_subsys_data(), but those checks were incorrect, because
that function returned 1 on success in some cases.

Since all of the existing users of dev_pm_get_subsys_data() don't use
the positive value returned by it on success, change its definition
so that it always returns 0 when successful.

Reported-by: Heiko Stübner <heiko@sntech.de>
Reported-by: Tushar Behera <tushar.behera@linaro.org>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>


# 51990e82 22-Jan-2012 Paul Gortmaker <paul.gortmaker@windriver.com>

device.h: cleanup users outside of linux/include (C files)

For files that are actively using linux/device.h, make sure
that they call it out. This will allow us to clean up some
of the implicit uses of linux/device.h within include/*
without introducing build regressions.

Yes, this was created by "cheating" -- i.e. the headers were
cleaned up, and then the fallout was found and fixed, and then
the two commits were reordered. This ensures we don't introduce
build regressions into the git history.

Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>


# 24050956 09-Nov-2011 Magnus Damm <damm@opensource.se>

PM / Clocks: Only disable enabled clocks in pm_clk_suspend()

Refrain from running clk_disable() on clocks that
have not been enabled. A typical case when this can
happen is during Suspend-to-RAM for devices that have
no driver associated with them. In such case the clock
may be in default ACQUIRED state.

Without this patch the sh7372 Mackerel board crashes
in __clk_disable() during Suspend-to-RAM with:
"Trying to disable clock 0xdeadbeef with 0 usecount"
This happens for the CEU device which is added during
boot. The test case has no CEU driver included in the
kernel configuration. Needed for v3.2-rc1.

Signed-off-by: Magnus Damm <damm@opensource.se>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>


# 0ab1e79b 21-Oct-2011 Jonghwan Choi <jhbird.choi@samsung.com>

PM / Clocks: Remove redundant NULL checks before kfree()

Since kfree() checks it its argument is not NULL, it is not necessary
to duplicate this check in __pm_clk_remove().

[rjw: Added the changelog.]

Signed-off-by: Jonghwan Choi <jhbird.choi@samsung.com>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>


# e8b364b8 26-Sep-2011 Rafael J. Wysocki <rjw@rjwysocki.net>

PM / Clocks: Do not acquire a mutex under a spinlock

Commit b7ab83e (PM: Use spinlock instead of mutex in clock
management functions) introduced a regression causing clocks_mutex
to be acquired under a spinlock. This happens because
pm_clk_suspend() and pm_clk_resume() call pm_clk_acquire() under
pcd->lock, but pm_clk_acquire() executes clk_get() which causes
clocks_mutex to be acquired. Similarly, __pm_clk_remove(),
executed under pcd->lock, calls clk_put(), which also causes
clocks_mutex to be acquired.

To fix those problems make pm_clk_add() call pm_clk_acquire(), so
that pm_clk_suspend() and pm_clk_resume() don't have to do that.
Change pm_clk_remove() and pm_clk_destroy() to separate
modifications of the pcd->clock_list list from the actual removal of
PM clock entry objects done by __pm_clk_remove().

Reported-and-tested-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Russell King <rmk+kernel@arm.linux.org.uk>


# b5e8d269 25-Aug-2011 Rafael J. Wysocki <rjw@rjwysocki.net>

PM: Move clock-related definitions and headers to separate file

Since the PM clock management code in drivers/base/power/clock_ops.c
is used for both runtime PM and system suspend/hibernation, the
definitions of data structures and headers related to it should not
be located in include/linux/pm_rumtime.h. Move them to a separate
header file.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>


# ef27bed1 25-Aug-2011 Rafael J. Wysocki <rjw@rjwysocki.net>

PM: Reference counting of power.subsys_data

Since the power.subsys_data device field will be used by multiple
filesystems, introduce a reference counting mechanism for it to avoid
freeing it prematurely or changing its value at a wrong time.

Make the PM clocks management code that currently is the only user of
power.subsys_data use the new reference counting.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>


# 5c095a0e 25-Aug-2011 Rafael J. Wysocki <rjw@rjwysocki.net>

PM: Introduce struct pm_subsys_data

Introduce struct pm_subsys_data that may be subclassed by subsystems
to store subsystem-specific information related to the device. Move
the clock management fields accessed through the power.subsys_data
pointer in struct device to the new strucutre.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>


# b7ab83ed 24-Aug-2011 Rafael J. Wysocki <rjw@rjwysocki.net>

PM: Use spinlock instead of mutex in clock management functions

The lock member of struct pm_clk_data is of type struct mutex,
which is a problem, because the suspend and resume routines
defined in drivers/base/power/clock_ops.c cannot be executed
with interrupts disabled for this reason. Modify
struct pm_clk_data so that its lock member is a spinlock.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Magnus Damm <damm@opensource.se>


# 3d5c3036 01-Jul-2011 Rafael J. Wysocki <rjw@rjwysocki.net>

PM: Rename clock management functions

The common PM clock management functions may be used for system
suspend/resume as well as for runtime PM, so rename them
accordingly. Modify kerneldoc comments describing these functions
and kernel messages printed by them, so that they refer to power
management in general rather that to runtime PM.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Reviewed-by: Kevin Hilman <khilman@ti.com>


# b7b95920 01-Jul-2011 Rafael J. Wysocki <rjw@rjwysocki.net>

PM: Allow the clocks management code to be used during system suspend

The common clocks management code in drivers/base/power/clock_ops.c
is going to be used during system-wide power transitions as well as
for runtime PM, so it shouldn't depend on CONFIG_PM_RUNTIME.
However, the suspend/resume functions provided by it for
CONFIG_PM_RUNTIME unset, to be used during system-wide power
transitions, should not behave in the same way as their counterparts
defined for CONFIG_PM_RUNTIME set, because in that case the clocks
are managed differently at run time.

The names of the functions still contain the word "runtime" after
this change, but that is going to be modified by a separate patch
later.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Reviewed-by: Kevin Hilman <khilman@ti.com>


# 564b905a 22-Jun-2011 Rafael J. Wysocki <rjw@rjwysocki.net>

PM / Domains: Rename struct dev_power_domain to struct dev_pm_domain

The naming convention used by commit 7538e3db6e015e890825fbd9f86599b
(PM: Add support for device power domains), which introduced the
struct dev_power_domain type for representing device power domains,
evidently confuses some developers who tend to think that objects
of this type must correspond to "power domains" as defined by
hardware, which is not the case. Namely, at the kernel level, a
struct dev_power_domain object can represent arbitrary set of devices
that are mutually dependent power management-wise and need not belong
to one hardware power domain. To avoid that confusion, rename struct
dev_power_domain to struct dev_pm_domain and rename the related
pointers in struct device and struct pm_clk_notifier_block from
pwr_domain to pm_domain.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Kevin Hilman <khilman@ti.com>


# 4d1518f5 21-Jun-2011 Rafael J. Wysocki <rjw@rjwysocki.net>

PM / Runtime: Handle clocks correctly if CONFIG_PM_RUNTIME is unset

Commit 85eb8c8d0b0900c073b0e6f89979ac9c439ade1a (PM / Runtime:
Generic clock manipulation rountines for runtime PM (v6)) converted
the shmobile platform to using generic code for runtime PM clock
management, but it changed the behavior for CONFIG_PM_RUNTIME unset
incorrectly.

Specifically, for CONFIG_PM_RUNTIME unset pm_runtime_clk_notify()
should enable clocks for action equal to BUS_NOTIFY_BIND_DRIVER and
it should disable them for action equal to BUS_NOTIFY_UNBOUND_DRIVER
(instead of BUS_NOTIFY_ADD_DEVICE and BUS_NOTIFY_DEL_DEVICE,
respectively). Make this function behave as appropriate.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Magnus Damm <damm@opensource.se>


# 3b3eca31 07-Jun-2011 Rafael J. Wysocki <rjw@rjwysocki.net>

PM / Runtime: Fix loops in pm_runtime_clk_notify()

The loops over connection ID strings in pm_runtime_clk_notify()
should actually iterate over the strings and not over the elements
of the first of them, so make them behave as appropriate.

This fixes a regression introduced by commit 600b776eb39a13a28b090
(OMAP1 / PM: Use generic clock manipulation routines for runtime PM).

Reported-and-tested-by: Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>


# 72874daa 03-May-2011 Rafael J. Wysocki <rjw@rjwysocki.net>

PM: Fix build issue in clock_ops.c for CONFIG_PM_RUNTIME unset

Fix a build issue in drivers/base/power/clock_ops.c occuring when
CONFIG_PM_RUNTIME is not set.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>


# 85eb8c8d 29-Apr-2011 Rafael J. Wysocki <rjw@rjwysocki.net>

PM / Runtime: Generic clock manipulation rountines for runtime PM (v6)

Many different platforms and subsystems may want to disable device
clocks during suspend and enable them during resume which is going to
be done in a very similar way in all those cases. For this reason,
provide generic routines for the manipulation of device clocks during
suspend and resume.

Convert the ARM shmobile platform to using the new routines.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>