2019-06-04 01:11:33 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2009-09-03 10:14:05 -07:00
|
|
|
/*
|
|
|
|
* omap_device implementation
|
|
|
|
*
|
2010-07-26 15:34:33 -07:00
|
|
|
* Copyright (C) 2009-2010 Nokia Corporation
|
2010-05-18 19:24:05 -07:00
|
|
|
* Paul Walmsley, Kevin Hilman
|
2009-09-03 10:14:05 -07:00
|
|
|
*
|
|
|
|
* Developed in collaboration with (alphabetical order): Benoit
|
2010-05-18 19:24:05 -07:00
|
|
|
* Cousson, Thara Gopinath, Tony Lindgren, Rajendra Nayak, Vikram
|
2009-09-03 10:14:05 -07:00
|
|
|
* Pandita, Sakari Poussa, Anand Sawant, Santosh Shilimkar, Richard
|
|
|
|
* Woodruff
|
|
|
|
*
|
|
|
|
* This code provides a consistent interface for OMAP device drivers
|
|
|
|
* to control power management and interconnect properties of their
|
|
|
|
* devices.
|
|
|
|
*
|
2013-01-26 00:48:53 -07:00
|
|
|
* In the medium- to long-term, this code should be implemented as a
|
|
|
|
* proper omap_bus/omap_device in Linux, no more platform_data func
|
|
|
|
* pointers
|
2009-09-03 10:14:05 -07:00
|
|
|
*/
|
|
|
|
#undef DEBUG
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/platform_device.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 01:04:11 -07:00
|
|
|
#include <linux/slab.h>
|
2009-09-03 10:14:05 -07:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/io.h>
|
2010-09-21 10:23:04 -07:00
|
|
|
#include <linux/clk.h>
|
2011-02-25 15:40:21 -07:00
|
|
|
#include <linux/clkdev.h>
|
2016-01-07 08:46:13 -07:00
|
|
|
#include <linux/pm_domain.h>
|
2011-05-31 16:08:09 -07:00
|
|
|
#include <linux/pm_runtime.h>
|
2011-08-10 04:32:08 -07:00
|
|
|
#include <linux/of.h>
|
2017-10-10 14:23:35 -07:00
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/of_irq.h>
|
2011-08-10 04:32:08 -07:00
|
|
|
#include <linux/notifier.h>
|
2009-09-03 10:14:05 -07:00
|
|
|
|
2013-12-06 11:52:58 -07:00
|
|
|
#include "common.h"
|
2013-01-11 12:24:18 -07:00
|
|
|
#include "soc.h"
|
2012-10-02 17:25:48 -07:00
|
|
|
#include "omap_device.h"
|
2012-10-02 17:41:35 -07:00
|
|
|
#include "omap_hwmod.h"
|
2009-09-03 10:14:05 -07:00
|
|
|
|
|
|
|
/* Private functions */
|
|
|
|
|
2011-07-10 04:54:12 -07:00
|
|
|
static void _add_clkdev(struct omap_device *od, const char *clk_alias,
|
|
|
|
const char *clk_name)
|
|
|
|
{
|
|
|
|
struct clk *r;
|
2015-03-02 08:46:03 -07:00
|
|
|
int rc;
|
2011-07-10 04:54:12 -07:00
|
|
|
|
|
|
|
if (!clk_alias || !clk_name)
|
|
|
|
return;
|
|
|
|
|
2011-07-21 13:58:51 -07:00
|
|
|
dev_dbg(&od->pdev->dev, "Creating %s -> %s\n", clk_alias, clk_name);
|
2011-07-10 04:54:12 -07:00
|
|
|
|
2011-07-21 13:58:51 -07:00
|
|
|
r = clk_get_sys(dev_name(&od->pdev->dev), clk_alias);
|
2011-07-10 04:54:12 -07:00
|
|
|
if (!IS_ERR(r)) {
|
2014-08-25 16:15:34 -07:00
|
|
|
dev_dbg(&od->pdev->dev,
|
2011-07-21 09:58:36 -07:00
|
|
|
"alias %s already exists\n", clk_alias);
|
2011-07-10 04:54:12 -07:00
|
|
|
clk_put(r);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-30 06:14:59 -07:00
|
|
|
r = clk_get_sys(NULL, clk_name);
|
|
|
|
|
2017-05-31 15:51:37 -07:00
|
|
|
if (IS_ERR(r)) {
|
2016-06-30 06:14:59 -07:00
|
|
|
struct of_phandle_args clkspec;
|
|
|
|
|
|
|
|
clkspec.np = of_find_node_by_name(NULL, clk_name);
|
|
|
|
|
|
|
|
r = of_clk_get_from_provider(&clkspec);
|
|
|
|
|
|
|
|
rc = clk_register_clkdev(r, clk_alias,
|
|
|
|
dev_name(&od->pdev->dev));
|
|
|
|
} else {
|
|
|
|
rc = clk_add_alias(clk_alias, dev_name(&od->pdev->dev),
|
|
|
|
clk_name, NULL);
|
|
|
|
}
|
|
|
|
|
2015-03-02 08:46:03 -07:00
|
|
|
if (rc) {
|
|
|
|
if (rc == -ENODEV || rc == -ENOMEM)
|
|
|
|
dev_err(&od->pdev->dev,
|
|
|
|
"clkdev_alloc for %s failed\n", clk_alias);
|
|
|
|
else
|
|
|
|
dev_err(&od->pdev->dev,
|
|
|
|
"clk_get for %s failed\n", clk_name);
|
2011-07-10 04:54:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-21 10:23:04 -07:00
|
|
|
/**
|
2011-07-10 04:54:12 -07:00
|
|
|
* _add_hwmod_clocks_clkdev - Add clkdev entry for hwmod optional clocks
|
|
|
|
* and main clock
|
2010-09-21 10:23:04 -07:00
|
|
|
* @od: struct omap_device *od
|
2011-07-10 04:54:12 -07:00
|
|
|
* @oh: struct omap_hwmod *oh
|
2010-09-21 10:23:04 -07:00
|
|
|
*
|
2011-07-10 04:54:12 -07:00
|
|
|
* For the main clock and every optional clock present per hwmod per
|
|
|
|
* omap_device, this function adds an entry in the clkdev table of the
|
|
|
|
* form <dev-id=dev_name, con-id=role> if it does not exist already.
|
2010-09-21 10:23:04 -07:00
|
|
|
*
|
|
|
|
* The function is called from inside omap_device_build_ss(), after
|
|
|
|
* omap_device_register.
|
|
|
|
*
|
|
|
|
* This allows drivers to get a pointer to its optional clocks based on its role
|
|
|
|
* by calling clk_get(<dev*>, <role>).
|
2011-07-10 04:54:12 -07:00
|
|
|
* In the case of the main clock, a "fck" alias is used.
|
2010-09-21 10:23:04 -07:00
|
|
|
*
|
|
|
|
* No return value.
|
|
|
|
*/
|
2011-07-10 04:54:12 -07:00
|
|
|
static void _add_hwmod_clocks_clkdev(struct omap_device *od,
|
|
|
|
struct omap_hwmod *oh)
|
2010-09-21 10:23:04 -07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2011-07-10 04:54:12 -07:00
|
|
|
_add_clkdev(od, "fck", oh->main_clk);
|
2011-02-25 15:40:21 -07:00
|
|
|
|
2011-07-10 04:54:12 -07:00
|
|
|
for (i = 0; i < oh->opt_clks_cnt; i++)
|
|
|
|
_add_clkdev(od, oh->opt_clks[i].role, oh->opt_clks[i].clk);
|
2010-09-21 10:23:04 -07:00
|
|
|
}
|
|
|
|
|
2009-09-03 10:14:05 -07:00
|
|
|
|
2011-08-10 04:32:08 -07:00
|
|
|
/**
|
|
|
|
* omap_device_build_from_dt - build an omap_device with multiple hwmods
|
2019-11-06 04:59:45 -07:00
|
|
|
* @pdev: The platform device to update.
|
2011-08-10 04:32:08 -07:00
|
|
|
*
|
|
|
|
* Function for building an omap_device already registered from device-tree
|
|
|
|
*
|
|
|
|
* Returns 0 or PTR_ERR() on error.
|
|
|
|
*/
|
|
|
|
static int omap_device_build_from_dt(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct omap_hwmod **hwmods;
|
|
|
|
struct omap_device *od;
|
|
|
|
struct omap_hwmod *oh;
|
|
|
|
struct device_node *node = pdev->dev.of_node;
|
2018-02-22 15:05:31 -07:00
|
|
|
struct resource res;
|
2011-08-10 04:32:08 -07:00
|
|
|
const char *oh_name;
|
|
|
|
int oh_cnt, i, ret = 0;
|
2018-04-16 10:24:14 -07:00
|
|
|
bool device_active = false, skip_pm_domain = false;
|
2011-08-10 04:32:08 -07:00
|
|
|
|
|
|
|
oh_cnt = of_property_count_strings(node, "ti,hwmods");
|
ARM: OMAP: use consistent error checking
Consistently check errors using the usual method used in the kernel
for much of its history. For instance:
int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t)
{
int div;
div = gpmc_calc_divider(t->sync_clk);
if (div < 0)
return div;
static int gpmc_set_async_mode(int cs, struct gpmc_timings *t)
{
...
return gpmc_cs_set_timings(cs, t);
.....
ret = gpmc_set_async_mode(gpmc_onenand_data->cs, &t);
if (IS_ERR_VALUE(ret))
return ret;
So, gpmc_cs_set_timings() thinks any negative return value is an error,
but where we check that in higher levels, only a limited range are
errors...
There is only _one_ use of IS_ERR_VALUE() in arch/arm which is really
appropriate, and that is in arch/arm/include/asm/syscall.h:
static inline long syscall_get_error(struct task_struct *task,
struct pt_regs *regs)
{
unsigned long error = regs->ARM_r0;
return IS_ERR_VALUE(error) ? error : 0;
}
because this function really does have to differentiate between error
return values and addresses which look like negative numbers (eg, from
mmap()).
So, here's a patch to remove them from OMAP, except for the above.
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2013-03-13 13:44:21 -07:00
|
|
|
if (oh_cnt <= 0) {
|
2012-01-20 10:14:00 -07:00
|
|
|
dev_dbg(&pdev->dev, "No 'hwmods' to build omap_device\n");
|
2011-08-10 04:32:08 -07:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2018-04-16 10:24:14 -07:00
|
|
|
/* SDMA still needs special handling for omap_device_build() */
|
|
|
|
ret = of_property_read_string_index(node, "ti,hwmods", 0, &oh_name);
|
|
|
|
if (!ret && (!strncmp("dma_system", oh_name, 10) ||
|
|
|
|
!strncmp("dma", oh_name, 3)))
|
|
|
|
skip_pm_domain = true;
|
|
|
|
|
2018-02-22 15:05:31 -07:00
|
|
|
/* Use ti-sysc driver instead of omap_device? */
|
2018-04-16 10:24:14 -07:00
|
|
|
if (!skip_pm_domain &&
|
|
|
|
!omap_hwmod_parse_module_range(NULL, node, &res))
|
2018-02-22 15:05:31 -07:00
|
|
|
return -ENODEV;
|
|
|
|
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 14:03:40 -07:00
|
|
|
hwmods = kcalloc(oh_cnt, sizeof(struct omap_hwmod *), GFP_KERNEL);
|
2011-08-10 04:32:08 -07:00
|
|
|
if (!hwmods) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto odbfd_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < oh_cnt; i++) {
|
|
|
|
of_property_read_string_index(node, "ti,hwmods", i, &oh_name);
|
|
|
|
oh = omap_hwmod_lookup(oh_name);
|
|
|
|
if (!oh) {
|
|
|
|
dev_err(&pdev->dev, "Cannot lookup hwmod '%s'\n",
|
|
|
|
oh_name);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto odbfd_exit1;
|
|
|
|
}
|
|
|
|
hwmods[i] = oh;
|
2013-07-28 22:01:51 -07:00
|
|
|
if (oh->flags & HWMOD_INIT_NO_IDLE)
|
|
|
|
device_active = true;
|
2011-08-10 04:32:08 -07:00
|
|
|
}
|
|
|
|
|
2013-01-26 00:48:53 -07:00
|
|
|
od = omap_device_alloc(pdev, hwmods, oh_cnt);
|
2013-09-18 12:01:58 -07:00
|
|
|
if (IS_ERR(od)) {
|
2011-08-10 04:32:08 -07:00
|
|
|
dev_err(&pdev->dev, "Cannot allocate omap_device for :%s\n",
|
|
|
|
oh_name);
|
|
|
|
ret = PTR_ERR(od);
|
|
|
|
goto odbfd_exit1;
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:54:09 -07:00
|
|
|
/* Fix up missing resource names */
|
|
|
|
for (i = 0; i < pdev->num_resources; i++) {
|
|
|
|
struct resource *r = &pdev->resource[i];
|
|
|
|
|
|
|
|
if (r->name == NULL)
|
|
|
|
r->name = dev_name(&pdev->dev);
|
|
|
|
}
|
|
|
|
|
2018-04-16 10:24:14 -07:00
|
|
|
if (!skip_pm_domain) {
|
|
|
|
dev_pm_domain_set(&pdev->dev, &omap_device_pm_domain);
|
|
|
|
if (device_active) {
|
|
|
|
omap_device_enable(pdev);
|
|
|
|
pm_runtime_set_active(&pdev->dev);
|
|
|
|
}
|
2013-07-28 22:01:51 -07:00
|
|
|
}
|
|
|
|
|
2011-08-10 04:32:08 -07:00
|
|
|
odbfd_exit1:
|
|
|
|
kfree(hwmods);
|
|
|
|
odbfd_exit:
|
ARM: OMAP2+: omap_device: add fail hook for runtime_pm when bad data is detected
Due to the cross dependencies between hwmod for automanaged device
information for OMAP and dts node definitions, we can run into scenarios
where the dts node is defined, however it's hwmod entry is yet to be
added. In these cases:
a) omap_device does not register a pm_domain (since it cannot find
hwmod entry).
b) driver does not know about (a), does a pm_runtime_get_sync which
never fails
c) It then tries to do some operation on the device (such as read the
revision register (as part of probe) without clock or adequate OMAP
generic PM operation performed for enabling the module.
This causes a crash such as that reported in:
https://bugzilla.kernel.org/show_bug.cgi?id=66441
When 'ti,hwmod' is provided in dt node, it is expected that the device
will not function without the OMAP's power automanagement. Hence, when
we hit a fail condition (due to hwmod entries not present or other
similar scenario), fail at pm_domain level due to lack of data, provide
enough information for it to be fixed, however, it allows for the driver
to take appropriate measures to prevent crash.
Reported-by: Tobias Jakobi <tjakobi@math.uni-bielefeld.de>
Signed-off-by: Nishanth Menon <nm@ti.com>
Acked-by: Kevin Hilman <khilman@linaro.org>
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Kevin Hilman <khilman@linaro.org>
2013-12-03 18:39:13 -07:00
|
|
|
/* if data/we are at fault.. load up a fail handler */
|
|
|
|
if (ret)
|
2016-01-07 08:46:13 -07:00
|
|
|
dev_pm_domain_set(&pdev->dev, &omap_device_fail_pm_domain);
|
ARM: OMAP2+: omap_device: add fail hook for runtime_pm when bad data is detected
Due to the cross dependencies between hwmod for automanaged device
information for OMAP and dts node definitions, we can run into scenarios
where the dts node is defined, however it's hwmod entry is yet to be
added. In these cases:
a) omap_device does not register a pm_domain (since it cannot find
hwmod entry).
b) driver does not know about (a), does a pm_runtime_get_sync which
never fails
c) It then tries to do some operation on the device (such as read the
revision register (as part of probe) without clock or adequate OMAP
generic PM operation performed for enabling the module.
This causes a crash such as that reported in:
https://bugzilla.kernel.org/show_bug.cgi?id=66441
When 'ti,hwmod' is provided in dt node, it is expected that the device
will not function without the OMAP's power automanagement. Hence, when
we hit a fail condition (due to hwmod entries not present or other
similar scenario), fail at pm_domain level due to lack of data, provide
enough information for it to be fixed, however, it allows for the driver
to take appropriate measures to prevent crash.
Reported-by: Tobias Jakobi <tjakobi@math.uni-bielefeld.de>
Signed-off-by: Nishanth Menon <nm@ti.com>
Acked-by: Kevin Hilman <khilman@linaro.org>
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Kevin Hilman <khilman@linaro.org>
2013-12-03 18:39:13 -07:00
|
|
|
|
2011-08-10 04:32:08 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _omap_device_notifier_call(struct notifier_block *nb,
|
|
|
|
unsigned long event, void *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
2012-07-10 11:13:16 -07:00
|
|
|
struct omap_device *od;
|
2016-02-12 09:56:52 -07:00
|
|
|
int err;
|
2011-08-10 04:32:08 -07:00
|
|
|
|
|
|
|
switch (event) {
|
2016-07-28 10:50:37 -07:00
|
|
|
case BUS_NOTIFY_REMOVED_DEVICE:
|
2011-08-10 04:32:08 -07:00
|
|
|
if (pdev->archdata.od)
|
|
|
|
omap_device_delete(pdev->archdata.od);
|
|
|
|
break;
|
2016-02-12 09:56:52 -07:00
|
|
|
case BUS_NOTIFY_UNBOUND_DRIVER:
|
|
|
|
od = to_omap_device(pdev);
|
|
|
|
if (od && (od->_state == OMAP_DEVICE_STATE_ENABLED)) {
|
|
|
|
dev_info(dev, "enabled after unload, idling\n");
|
|
|
|
err = omap_device_idle(pdev);
|
|
|
|
if (err)
|
|
|
|
dev_err(dev, "failed to idle\n");
|
|
|
|
}
|
|
|
|
break;
|
2017-03-30 12:58:18 -07:00
|
|
|
case BUS_NOTIFY_BIND_DRIVER:
|
|
|
|
od = to_omap_device(pdev);
|
|
|
|
if (od && (od->_state == OMAP_DEVICE_STATE_ENABLED) &&
|
|
|
|
pm_runtime_status_suspended(dev)) {
|
|
|
|
od->_driver_status = BUS_NOTIFY_BIND_DRIVER;
|
|
|
|
pm_runtime_set_active(dev);
|
|
|
|
}
|
|
|
|
break;
|
2012-07-10 11:13:16 -07:00
|
|
|
case BUS_NOTIFY_ADD_DEVICE:
|
|
|
|
if (pdev->dev.of_node)
|
|
|
|
omap_device_build_from_dt(pdev);
|
2013-12-06 11:52:58 -07:00
|
|
|
omap_auxdata_legacy_init(dev);
|
2012-07-10 11:13:16 -07:00
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
od = to_omap_device(pdev);
|
|
|
|
if (od)
|
|
|
|
od->_driver_status = event;
|
2011-08-10 04:32:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
2013-01-26 00:48:53 -07:00
|
|
|
/**
|
|
|
|
* _omap_device_enable_hwmods - call omap_hwmod_enable() on all hwmods
|
|
|
|
* @od: struct omap_device *od
|
|
|
|
*
|
|
|
|
* Enable all underlying hwmods. Returns 0.
|
|
|
|
*/
|
|
|
|
static int _omap_device_enable_hwmods(struct omap_device *od)
|
|
|
|
{
|
2015-02-26 06:49:51 -07:00
|
|
|
int ret = 0;
|
2013-01-26 00:48:53 -07:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < od->hwmods_cnt; i++)
|
2015-02-26 06:49:51 -07:00
|
|
|
ret |= omap_hwmod_enable(od->hwmods[i]);
|
2013-01-26 00:48:53 -07:00
|
|
|
|
2015-02-26 06:49:51 -07:00
|
|
|
return ret;
|
2013-01-26 00:48:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _omap_device_idle_hwmods - call omap_hwmod_idle() on all hwmods
|
|
|
|
* @od: struct omap_device *od
|
|
|
|
*
|
|
|
|
* Idle all underlying hwmods. Returns 0.
|
|
|
|
*/
|
|
|
|
static int _omap_device_idle_hwmods(struct omap_device *od)
|
|
|
|
{
|
2015-02-26 06:49:51 -07:00
|
|
|
int ret = 0;
|
2013-01-26 00:48:53 -07:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < od->hwmods_cnt; i++)
|
2015-02-26 06:49:51 -07:00
|
|
|
ret |= omap_hwmod_idle(od->hwmods[i]);
|
2013-01-26 00:48:53 -07:00
|
|
|
|
2015-02-26 06:49:51 -07:00
|
|
|
return ret;
|
2013-01-26 00:48:53 -07:00
|
|
|
}
|
2011-08-10 04:32:08 -07:00
|
|
|
|
2009-09-03 10:14:05 -07:00
|
|
|
/* Public functions for use by core code */
|
|
|
|
|
2010-12-21 21:31:55 -07:00
|
|
|
/**
|
|
|
|
* omap_device_get_context_loss_count - get lost context count
|
2019-11-06 04:59:45 -07:00
|
|
|
* @pdev: The platform device to update.
|
2010-12-21 21:31:55 -07:00
|
|
|
*
|
|
|
|
* Using the primary hwmod, query the context loss count for this
|
|
|
|
* device.
|
|
|
|
*
|
|
|
|
* Callers should consider context for this device lost any time this
|
|
|
|
* function returns a value different than the value the caller got
|
|
|
|
* the last time it called this function.
|
|
|
|
*
|
2016-05-21 04:50:25 -07:00
|
|
|
* If any hwmods exist for the omap_device associated with @pdev,
|
2010-12-21 21:31:55 -07:00
|
|
|
* return the context loss counter for that hwmod, otherwise return
|
|
|
|
* zero.
|
|
|
|
*/
|
2011-06-09 06:56:23 -07:00
|
|
|
int omap_device_get_context_loss_count(struct platform_device *pdev)
|
2010-12-21 21:31:55 -07:00
|
|
|
{
|
|
|
|
struct omap_device *od;
|
|
|
|
u32 ret = 0;
|
|
|
|
|
2011-07-09 18:15:20 -07:00
|
|
|
od = to_omap_device(pdev);
|
2010-12-21 21:31:55 -07:00
|
|
|
|
|
|
|
if (od->hwmods_cnt)
|
|
|
|
ret = omap_hwmod_get_context_loss_count(od->hwmods[0]);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-08-09 07:47:01 -07:00
|
|
|
/**
|
|
|
|
* omap_device_alloc - allocate an omap_device
|
|
|
|
* @pdev: platform_device that will be included in this omap_device
|
2019-11-06 04:59:45 -07:00
|
|
|
* @ohs: ptr to the omap_hwmod for this omap_device
|
|
|
|
* @oh_cnt: the size of the ohs list
|
2011-08-09 07:47:01 -07:00
|
|
|
*
|
|
|
|
* Convenience function for allocating an omap_device structure and filling
|
2013-01-26 00:48:53 -07:00
|
|
|
* hwmods, and resources.
|
2011-08-09 07:47:01 -07:00
|
|
|
*
|
|
|
|
* Returns an struct omap_device pointer or ERR_PTR() on error;
|
|
|
|
*/
|
ARM: OMAP: omap_device: Expose omap_device_{alloc, delete, register}
Expose omap_device_{alloc, delete, register} so we can use them outside
of omap_device.c.
This approach allows users, which need to manipulate an archdata member
of a device before it is registered, to do so. This is also useful
for users who have their devices created very early so they can be used
at ->reserve() time to reserve CMA memory.
The immediate use case for this is to set the private iommu archdata
member, which binds a device to its associated iommu controller.
This way, generic code will be able to attach omap devices to their
iommus, without calling any omap-specific API.
With this in hand, we can further clean the existing mainline OMAP iommu
driver and its mainline users, and focus on generic IOMMU approaches
for future users (rpmsg/remoteproc and the upcoming generic DMA API).
This patch is still considered an interim solution until DT fully materializes
for omap; at that point, this functionality will be removed as DT will
take care of creating the devices and configuring them correctly.
Tested on OMAP4 with a generic rpmsg/remoteproc that doesn't use any
omap-specific IOMMU API anymore.
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
Signed-off-by: Kevin Hilman <khilman@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
2012-02-20 10:43:29 -07:00
|
|
|
struct omap_device *omap_device_alloc(struct platform_device *pdev,
|
2013-01-26 00:48:53 -07:00
|
|
|
struct omap_hwmod **ohs, int oh_cnt)
|
2011-08-09 07:47:01 -07:00
|
|
|
{
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
struct omap_device *od;
|
2017-10-10 14:27:26 -07:00
|
|
|
int i;
|
2011-08-09 07:47:01 -07:00
|
|
|
struct omap_hwmod **hwmods;
|
|
|
|
|
|
|
|
od = kzalloc(sizeof(struct omap_device), GFP_KERNEL);
|
|
|
|
if (!od) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto oda_exit1;
|
|
|
|
}
|
|
|
|
od->hwmods_cnt = oh_cnt;
|
|
|
|
|
|
|
|
hwmods = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
|
|
|
|
if (!hwmods)
|
|
|
|
goto oda_exit2;
|
|
|
|
|
|
|
|
od->hwmods = hwmods;
|
|
|
|
od->pdev = pdev;
|
|
|
|
pdev->archdata.od = od;
|
|
|
|
|
|
|
|
for (i = 0; i < oh_cnt; i++) {
|
|
|
|
hwmods[i]->od = od;
|
|
|
|
_add_hwmod_clocks_clkdev(od, hwmods[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return od;
|
|
|
|
|
|
|
|
oda_exit2:
|
|
|
|
kfree(od);
|
|
|
|
oda_exit1:
|
|
|
|
dev_err(&pdev->dev, "omap_device: build failed (%d)\n", ret);
|
|
|
|
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
ARM: OMAP: omap_device: Expose omap_device_{alloc, delete, register}
Expose omap_device_{alloc, delete, register} so we can use them outside
of omap_device.c.
This approach allows users, which need to manipulate an archdata member
of a device before it is registered, to do so. This is also useful
for users who have their devices created very early so they can be used
at ->reserve() time to reserve CMA memory.
The immediate use case for this is to set the private iommu archdata
member, which binds a device to its associated iommu controller.
This way, generic code will be able to attach omap devices to their
iommus, without calling any omap-specific API.
With this in hand, we can further clean the existing mainline OMAP iommu
driver and its mainline users, and focus on generic IOMMU approaches
for future users (rpmsg/remoteproc and the upcoming generic DMA API).
This patch is still considered an interim solution until DT fully materializes
for omap; at that point, this functionality will be removed as DT will
take care of creating the devices and configuring them correctly.
Tested on OMAP4 with a generic rpmsg/remoteproc that doesn't use any
omap-specific IOMMU API anymore.
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
Signed-off-by: Kevin Hilman <khilman@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
2012-02-20 10:43:29 -07:00
|
|
|
void omap_device_delete(struct omap_device *od)
|
2011-08-09 07:47:01 -07:00
|
|
|
{
|
2011-08-10 04:32:08 -07:00
|
|
|
if (!od)
|
|
|
|
return;
|
|
|
|
|
2011-08-09 07:47:01 -07:00
|
|
|
od->pdev->archdata.od = NULL;
|
|
|
|
kfree(od->hwmods);
|
|
|
|
kfree(od);
|
|
|
|
}
|
|
|
|
|
2014-12-12 16:42:49 -07:00
|
|
|
#ifdef CONFIG_PM
|
2011-04-28 15:36:42 -07:00
|
|
|
static int _od_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
2011-05-31 16:08:09 -07:00
|
|
|
int ret;
|
2011-04-28 15:36:42 -07:00
|
|
|
|
2011-05-31 16:08:09 -07:00
|
|
|
ret = pm_generic_runtime_suspend(dev);
|
2015-02-26 06:49:51 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-05-31 16:08:09 -07:00
|
|
|
|
2015-02-26 06:49:51 -07:00
|
|
|
return omap_device_idle(pdev);
|
2011-05-31 16:08:09 -07:00
|
|
|
}
|
|
|
|
|
2011-04-28 15:36:42 -07:00
|
|
|
static int _od_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
2015-02-26 06:49:51 -07:00
|
|
|
int ret;
|
2011-04-28 15:36:42 -07:00
|
|
|
|
2015-02-26 06:49:51 -07:00
|
|
|
ret = omap_device_enable(pdev);
|
2016-02-12 09:56:52 -07:00
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "use pm_runtime_put_sync_suspend() in driver?\n");
|
2015-02-26 06:49:51 -07:00
|
|
|
return ret;
|
2016-02-12 09:56:52 -07:00
|
|
|
}
|
2011-05-31 16:08:09 -07:00
|
|
|
|
|
|
|
return pm_generic_runtime_resume(dev);
|
2011-04-28 15:36:42 -07:00
|
|
|
}
|
ARM: OMAP2+: omap_device: add fail hook for runtime_pm when bad data is detected
Due to the cross dependencies between hwmod for automanaged device
information for OMAP and dts node definitions, we can run into scenarios
where the dts node is defined, however it's hwmod entry is yet to be
added. In these cases:
a) omap_device does not register a pm_domain (since it cannot find
hwmod entry).
b) driver does not know about (a), does a pm_runtime_get_sync which
never fails
c) It then tries to do some operation on the device (such as read the
revision register (as part of probe) without clock or adequate OMAP
generic PM operation performed for enabling the module.
This causes a crash such as that reported in:
https://bugzilla.kernel.org/show_bug.cgi?id=66441
When 'ti,hwmod' is provided in dt node, it is expected that the device
will not function without the OMAP's power automanagement. Hence, when
we hit a fail condition (due to hwmod entries not present or other
similar scenario), fail at pm_domain level due to lack of data, provide
enough information for it to be fixed, however, it allows for the driver
to take appropriate measures to prevent crash.
Reported-by: Tobias Jakobi <tjakobi@math.uni-bielefeld.de>
Signed-off-by: Nishanth Menon <nm@ti.com>
Acked-by: Kevin Hilman <khilman@linaro.org>
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Kevin Hilman <khilman@linaro.org>
2013-12-03 18:39:13 -07:00
|
|
|
|
|
|
|
static int _od_fail_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
dev_warn(dev, "%s: FIXME: missing hwmod/omap_dev info\n", __func__);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _od_fail_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
dev_warn(dev, "%s: FIXME: missing hwmod/omap_dev info\n", __func__);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2011-07-12 13:48:03 -07:00
|
|
|
#endif
|
2011-04-28 15:36:42 -07:00
|
|
|
|
2011-07-12 13:48:19 -07:00
|
|
|
#ifdef CONFIG_SUSPEND
|
|
|
|
static int _od_suspend_noirq(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct omap_device *od = to_omap_device(pdev);
|
|
|
|
int ret;
|
|
|
|
|
2012-07-10 15:29:04 -07:00
|
|
|
/* Don't attempt late suspend on a driver that is not bound */
|
|
|
|
if (od->_driver_status != BUS_NOTIFY_BOUND_DRIVER)
|
|
|
|
return 0;
|
|
|
|
|
2011-07-12 13:48:19 -07:00
|
|
|
ret = pm_generic_suspend_noirq(dev);
|
|
|
|
|
|
|
|
if (!ret && !pm_runtime_status_suspended(dev)) {
|
|
|
|
if (pm_generic_runtime_suspend(dev) == 0) {
|
2013-04-26 13:25:34 -07:00
|
|
|
omap_device_idle(pdev);
|
2011-07-12 13:48:19 -07:00
|
|
|
od->flags |= OMAP_DEVICE_SUSPENDED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _od_resume_noirq(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct omap_device *od = to_omap_device(pdev);
|
|
|
|
|
ARM: OMAP2+: omap_device: maintain sane runtime pm status around suspend/resume
OMAP device hooks around suspend|resume_noirq ensures that hwmod
devices are forced to idle using omap_device_idle/enable as part of
the last stage of suspend activity.
For a device such as i2c who uses autosuspend, it is possible to enter
the suspend path with dev->power.runtime_status = RPM_ACTIVE.
As part of the suspend flow, the generic runtime logic would increment
it's dev->power.disable_depth to 1. This should prevent further
pm_runtime_get_sync from succeeding once the runtime_status has been
set to RPM_SUSPENDED.
Now, as part of the suspend_noirq handler in omap_device, we force the
following: if the device status is !suspended, we force the device
to idle using omap_device_idle (clocks are cut etc..). This ensures
that from a hardware perspective, the device is "suspended". However,
runtime_status is left to be active.
*if* an operation is attempted after this point to
pm_runtime_get_sync, runtime framework depends on runtime_status to
indicate accurately the device status, and since it sees it to be
ACTIVE, it assumes the module is functional and returns a non-error
value. As a result the user will see pm_runtime_get succeed, however a
register access will crash due to the lack of clocks.
To prevent this from happening, we should ensure that runtime_status
exactly indicates the device status. As a result of this change
any further calls to pm_runtime_get* would return -EACCES (since
disable_depth is 1). On resume, we restore the clocks and runtime
status exactly as we suspended with. These operations are not expected
to fail as we update the states after the core runtime framework has
suspended itself and restore before the core runtime framework has
resumed.
Cc: stable@vger.kernel.org # v3.4+
Reported-by: J Keerthy <j-keerthy@ti.com>
Signed-off-by: Nishanth Menon <nm@ti.com>
Acked-by: Rajendra Nayak <rnayak@ti.com>
Acked-by: Kevin Hilman <khilman@linaro.org>
Reviewed-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
2013-11-14 10:05:16 -07:00
|
|
|
if (od->flags & OMAP_DEVICE_SUSPENDED) {
|
2011-07-12 13:48:19 -07:00
|
|
|
od->flags &= ~OMAP_DEVICE_SUSPENDED;
|
2013-04-26 13:25:34 -07:00
|
|
|
omap_device_enable(pdev);
|
2011-07-12 13:48:19 -07:00
|
|
|
pm_generic_runtime_resume(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pm_generic_resume_noirq(dev);
|
|
|
|
}
|
2011-09-01 10:59:36 -07:00
|
|
|
#else
|
|
|
|
#define _od_suspend_noirq NULL
|
|
|
|
#define _od_resume_noirq NULL
|
2011-07-12 13:48:19 -07:00
|
|
|
#endif
|
|
|
|
|
ARM: OMAP2+: omap_device: add fail hook for runtime_pm when bad data is detected
Due to the cross dependencies between hwmod for automanaged device
information for OMAP and dts node definitions, we can run into scenarios
where the dts node is defined, however it's hwmod entry is yet to be
added. In these cases:
a) omap_device does not register a pm_domain (since it cannot find
hwmod entry).
b) driver does not know about (a), does a pm_runtime_get_sync which
never fails
c) It then tries to do some operation on the device (such as read the
revision register (as part of probe) without clock or adequate OMAP
generic PM operation performed for enabling the module.
This causes a crash such as that reported in:
https://bugzilla.kernel.org/show_bug.cgi?id=66441
When 'ti,hwmod' is provided in dt node, it is expected that the device
will not function without the OMAP's power automanagement. Hence, when
we hit a fail condition (due to hwmod entries not present or other
similar scenario), fail at pm_domain level due to lack of data, provide
enough information for it to be fixed, however, it allows for the driver
to take appropriate measures to prevent crash.
Reported-by: Tobias Jakobi <tjakobi@math.uni-bielefeld.de>
Signed-off-by: Nishanth Menon <nm@ti.com>
Acked-by: Kevin Hilman <khilman@linaro.org>
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Kevin Hilman <khilman@linaro.org>
2013-12-03 18:39:13 -07:00
|
|
|
struct dev_pm_domain omap_device_fail_pm_domain = {
|
|
|
|
.ops = {
|
|
|
|
SET_RUNTIME_PM_OPS(_od_fail_runtime_suspend,
|
|
|
|
_od_fail_runtime_resume, NULL)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-15 12:47:45 -07:00
|
|
|
struct dev_pm_domain omap_device_pm_domain = {
|
2011-04-28 15:36:42 -07:00
|
|
|
.ops = {
|
2011-07-12 13:48:03 -07:00
|
|
|
SET_RUNTIME_PM_OPS(_od_runtime_suspend, _od_runtime_resume,
|
PM / Runtime: Rework the "runtime idle" helper routine
The "runtime idle" helper routine, rpm_idle(), currently ignores
return values from .runtime_idle() callbacks executed by it.
However, it turns out that many subsystems use
pm_generic_runtime_idle() which checks the return value of the
driver's callback and executes pm_runtime_suspend() for the device
unless that value is not 0. If that logic is moved to rpm_idle()
instead, pm_generic_runtime_idle() can be dropped and its users
will not need any .runtime_idle() callbacks any more.
Moreover, the PCI, SCSI, and SATA subsystems' .runtime_idle()
routines, pci_pm_runtime_idle(), scsi_runtime_idle(), and
ata_port_runtime_idle(), respectively, as well as a few drivers'
ones may be simplified if rpm_idle() calls rpm_suspend() after 0 has
been returned by the .runtime_idle() callback executed by it.
To reduce overall code bloat, make the changes described above.
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Tested-by: Kevin Hilman <khilman@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Kevin Hilman <khilman@linaro.org>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
2013-06-03 12:49:52 -07:00
|
|
|
NULL)
|
2011-04-28 15:36:42 -07:00
|
|
|
USE_PLATFORM_PM_SLEEP_OPS
|
2015-04-27 11:24:32 -07:00
|
|
|
SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(_od_suspend_noirq,
|
|
|
|
_od_resume_noirq)
|
2011-04-28 15:36:42 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-09-03 10:14:05 -07:00
|
|
|
/**
|
|
|
|
* omap_device_register - register an omap_device with one omap_hwmod
|
2019-11-06 04:59:45 -07:00
|
|
|
* @pdev: the platform device (omap_device) to register.
|
2009-09-03 10:14:05 -07:00
|
|
|
*
|
|
|
|
* Register the omap_device structure. This currently just calls
|
|
|
|
* platform_device_register() on the underlying platform_device.
|
|
|
|
* Returns the return value of platform_device_register().
|
|
|
|
*/
|
ARM: OMAP: omap_device: Expose omap_device_{alloc, delete, register}
Expose omap_device_{alloc, delete, register} so we can use them outside
of omap_device.c.
This approach allows users, which need to manipulate an archdata member
of a device before it is registered, to do so. This is also useful
for users who have their devices created very early so they can be used
at ->reserve() time to reserve CMA memory.
The immediate use case for this is to set the private iommu archdata
member, which binds a device to its associated iommu controller.
This way, generic code will be able to attach omap devices to their
iommus, without calling any omap-specific API.
With this in hand, we can further clean the existing mainline OMAP iommu
driver and its mainline users, and focus on generic IOMMU approaches
for future users (rpmsg/remoteproc and the upcoming generic DMA API).
This patch is still considered an interim solution until DT fully materializes
for omap; at that point, this functionality will be removed as DT will
take care of creating the devices and configuring them correctly.
Tested on OMAP4 with a generic rpmsg/remoteproc that doesn't use any
omap-specific IOMMU API anymore.
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
Signed-off-by: Kevin Hilman <khilman@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
2012-02-20 10:43:29 -07:00
|
|
|
int omap_device_register(struct platform_device *pdev)
|
2009-09-03 10:14:05 -07:00
|
|
|
{
|
2011-07-21 14:47:53 -07:00
|
|
|
pr_debug("omap_device: %s: registering\n", pdev->name);
|
2009-09-03 10:14:05 -07:00
|
|
|
|
2016-01-07 08:46:13 -07:00
|
|
|
dev_pm_domain_set(&pdev->dev, &omap_device_pm_domain);
|
2011-07-21 13:58:51 -07:00
|
|
|
return platform_device_add(pdev);
|
2009-09-03 10:14:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Public functions for use by device drivers through struct platform_data */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_device_enable - fully activate an omap_device
|
2019-11-06 04:59:45 -07:00
|
|
|
* @pdev: the platform device to activate
|
2009-09-03 10:14:05 -07:00
|
|
|
*
|
|
|
|
* Do whatever is necessary for the hwmods underlying omap_device @od
|
|
|
|
* to be accessible and ready to operate. This generally involves
|
|
|
|
* enabling clocks, setting SYSCONFIG registers; and in the future may
|
|
|
|
* involve remuxing pins. Device drivers should call this function
|
2013-01-26 00:48:53 -07:00
|
|
|
* indirectly via pm_runtime_get*(). Returns -EINVAL if called when
|
|
|
|
* the omap_device is already enabled, or passes along the return
|
|
|
|
* value of _omap_device_enable_hwmods().
|
2009-09-03 10:14:05 -07:00
|
|
|
*/
|
|
|
|
int omap_device_enable(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct omap_device *od;
|
|
|
|
|
2011-07-09 18:15:20 -07:00
|
|
|
od = to_omap_device(pdev);
|
2009-09-03 10:14:05 -07:00
|
|
|
|
|
|
|
if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
|
2011-07-21 09:58:36 -07:00
|
|
|
dev_warn(&pdev->dev,
|
|
|
|
"omap_device: %s() called from invalid state %d\n",
|
|
|
|
__func__, od->_state);
|
2009-09-03 10:14:05 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-01-26 00:48:53 -07:00
|
|
|
ret = _omap_device_enable_hwmods(od);
|
2009-09-03 10:14:05 -07:00
|
|
|
|
2015-02-26 06:49:51 -07:00
|
|
|
if (ret == 0)
|
|
|
|
od->_state = OMAP_DEVICE_STATE_ENABLED;
|
2009-09-03 10:14:05 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_device_idle - idle an omap_device
|
2019-11-06 04:59:45 -07:00
|
|
|
* @pdev: The platform_device (omap_device) to idle
|
2009-09-03 10:14:05 -07:00
|
|
|
*
|
2013-01-26 00:48:53 -07:00
|
|
|
* Idle omap_device @od. Device drivers call this function indirectly
|
|
|
|
* via pm_runtime_put*(). Returns -EINVAL if the omap_device is not
|
2009-09-03 10:14:05 -07:00
|
|
|
* currently enabled, or passes along the return value of
|
2013-01-26 00:48:53 -07:00
|
|
|
* _omap_device_idle_hwmods().
|
2009-09-03 10:14:05 -07:00
|
|
|
*/
|
|
|
|
int omap_device_idle(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct omap_device *od;
|
|
|
|
|
2011-07-09 18:15:20 -07:00
|
|
|
od = to_omap_device(pdev);
|
2009-09-03 10:14:05 -07:00
|
|
|
|
|
|
|
if (od->_state != OMAP_DEVICE_STATE_ENABLED) {
|
2011-07-21 09:58:36 -07:00
|
|
|
dev_warn(&pdev->dev,
|
|
|
|
"omap_device: %s() called from invalid state %d\n",
|
|
|
|
__func__, od->_state);
|
2009-09-03 10:14:05 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-01-26 00:48:53 -07:00
|
|
|
ret = _omap_device_idle_hwmods(od);
|
2009-09-03 10:14:05 -07:00
|
|
|
|
2015-02-26 06:49:51 -07:00
|
|
|
if (ret == 0)
|
|
|
|
od->_state = OMAP_DEVICE_STATE_IDLE;
|
2009-09-03 10:14:05 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-23 16:28:18 -07:00
|
|
|
/**
|
|
|
|
* omap_device_assert_hardreset - set a device's hardreset line
|
|
|
|
* @pdev: struct platform_device * to reset
|
|
|
|
* @name: const char * name of the reset line
|
|
|
|
*
|
|
|
|
* Set the hardreset line identified by @name on the IP blocks
|
|
|
|
* associated with the hwmods backing the platform_device @pdev. All
|
|
|
|
* of the hwmods associated with @pdev must have the same hardreset
|
|
|
|
* line linked to them for this to work. Passes along the return value
|
|
|
|
* of omap_hwmod_assert_hardreset() in the event of any failure, or
|
|
|
|
* returns 0 upon success.
|
|
|
|
*/
|
|
|
|
int omap_device_assert_hardreset(struct platform_device *pdev, const char *name)
|
|
|
|
{
|
|
|
|
struct omap_device *od = to_omap_device(pdev);
|
|
|
|
int ret = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < od->hwmods_cnt; i++) {
|
|
|
|
ret = omap_hwmod_assert_hardreset(od->hwmods[i], name);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_device_deassert_hardreset - release a device's hardreset line
|
|
|
|
* @pdev: struct platform_device * to reset
|
|
|
|
* @name: const char * name of the reset line
|
|
|
|
*
|
|
|
|
* Release the hardreset line identified by @name on the IP blocks
|
|
|
|
* associated with the hwmods backing the platform_device @pdev. All
|
|
|
|
* of the hwmods associated with @pdev must have the same hardreset
|
|
|
|
* line linked to them for this to work. Passes along the return
|
|
|
|
* value of omap_hwmod_deassert_hardreset() in the event of any
|
|
|
|
* failure, or returns 0 upon success.
|
|
|
|
*/
|
|
|
|
int omap_device_deassert_hardreset(struct platform_device *pdev,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct omap_device *od = to_omap_device(pdev);
|
|
|
|
int ret = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < od->hwmods_cnt; i++) {
|
|
|
|
ret = omap_hwmod_deassert_hardreset(od->hwmods[i], name);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-27 13:02:32 -07:00
|
|
|
/**
|
|
|
|
* omap_device_get_by_hwmod_name() - convert a hwmod name to
|
|
|
|
* device pointer.
|
|
|
|
* @oh_name: name of the hwmod device
|
|
|
|
*
|
|
|
|
* Returns back a struct device * pointer associated with a hwmod
|
|
|
|
* device represented by a hwmod_name
|
|
|
|
*/
|
|
|
|
struct device *omap_device_get_by_hwmod_name(const char *oh_name)
|
|
|
|
{
|
|
|
|
struct omap_hwmod *oh;
|
|
|
|
|
|
|
|
if (!oh_name) {
|
|
|
|
WARN(1, "%s: no hwmod name!\n", __func__);
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
oh = omap_hwmod_lookup(oh_name);
|
2013-02-24 03:56:59 -07:00
|
|
|
if (!oh) {
|
2011-07-27 13:02:32 -07:00
|
|
|
WARN(1, "%s: no hwmod for %s\n", __func__,
|
|
|
|
oh_name);
|
2013-02-24 03:56:59 -07:00
|
|
|
return ERR_PTR(-ENODEV);
|
2011-07-27 13:02:32 -07:00
|
|
|
}
|
2013-02-24 03:56:59 -07:00
|
|
|
if (!oh->od) {
|
2011-07-27 13:02:32 -07:00
|
|
|
WARN(1, "%s: no omap_device for %s\n", __func__,
|
|
|
|
oh_name);
|
2013-02-24 03:56:59 -07:00
|
|
|
return ERR_PTR(-ENODEV);
|
2011-07-27 13:02:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return &oh->od->pdev->dev;
|
|
|
|
}
|
2010-08-23 08:10:55 -07:00
|
|
|
|
2011-08-10 04:32:08 -07:00
|
|
|
static struct notifier_block platform_nb = {
|
|
|
|
.notifier_call = _omap_device_notifier_call,
|
|
|
|
};
|
|
|
|
|
2010-08-23 08:10:55 -07:00
|
|
|
static int __init omap_device_init(void)
|
|
|
|
{
|
2011-08-10 04:32:08 -07:00
|
|
|
bus_register_notifier(&platform_bus_type, &platform_nb);
|
2012-02-15 12:47:45 -07:00
|
|
|
return 0;
|
2010-08-23 08:10:55 -07:00
|
|
|
}
|
2015-12-03 12:38:09 -07:00
|
|
|
omap_postcore_initcall(omap_device_init);
|
2012-07-10 15:06:11 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_device_late_idle - idle devices without drivers
|
|
|
|
* @dev: struct device * associated with omap_device
|
|
|
|
* @data: unused
|
|
|
|
*
|
|
|
|
* Check the driver bound status of this device, and idle it
|
|
|
|
* if there is no driver attached.
|
|
|
|
*/
|
|
|
|
static int __init omap_device_late_idle(struct device *dev, void *data)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct omap_device *od = to_omap_device(pdev);
|
2013-07-28 22:01:50 -07:00
|
|
|
int i;
|
2012-07-10 15:06:11 -07:00
|
|
|
|
|
|
|
if (!od)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If omap_device state is enabled, but has no driver bound,
|
|
|
|
* idle it.
|
|
|
|
*/
|
2013-07-28 22:01:50 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Some devices (like memory controllers) are always kept
|
|
|
|
* enabled, and should not be idled even with no drivers.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < od->hwmods_cnt; i++)
|
|
|
|
if (od->hwmods[i]->flags & HWMOD_INIT_NO_IDLE)
|
|
|
|
return 0;
|
|
|
|
|
2015-09-01 13:59:24 -07:00
|
|
|
if (od->_driver_status != BUS_NOTIFY_BOUND_DRIVER &&
|
|
|
|
od->_driver_status != BUS_NOTIFY_BIND_DRIVER) {
|
2012-07-10 15:06:11 -07:00
|
|
|
if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
|
|
|
|
dev_warn(dev, "%s: enabled but no driver. Idling\n",
|
|
|
|
__func__);
|
|
|
|
omap_device_idle(pdev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init omap_device_late_init(void)
|
|
|
|
{
|
|
|
|
bus_for_each_dev(&platform_bus_type, NULL, NULL, omap_device_late_idle);
|
2014-10-27 13:05:54 -07:00
|
|
|
|
2012-07-10 15:06:11 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2013-05-08 16:48:01 -07:00
|
|
|
omap_late_initcall_sync(omap_device_late_init);
|