2009-09-04 00:14:05 +07:00
|
|
|
/*
|
|
|
|
* omap_device implementation
|
|
|
|
*
|
2010-07-27 05:34:33 +07:00
|
|
|
* Copyright (C) 2009-2010 Nokia Corporation
|
2010-05-19 09:24:05 +07:00
|
|
|
* Paul Walmsley, Kevin Hilman
|
2009-09-04 00:14:05 +07:00
|
|
|
*
|
|
|
|
* Developed in collaboration with (alphabetical order): Benoit
|
2010-05-19 09:24:05 +07:00
|
|
|
* Cousson, Thara Gopinath, Tony Lindgren, Rajendra Nayak, Vikram
|
2009-09-04 00:14:05 +07:00
|
|
|
* Pandita, Sakari Poussa, Anand Sawant, Santosh Shilimkar, Richard
|
|
|
|
* Woodruff
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code provides a consistent interface for OMAP device drivers
|
|
|
|
* to control power management and interconnect properties of their
|
|
|
|
* devices.
|
|
|
|
*
|
2013-01-26 14: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-04 00: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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2009-09-04 00:14:05 +07:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/io.h>
|
2010-09-22 00:23:04 +07:00
|
|
|
#include <linux/clk.h>
|
2011-02-26 05:40:21 +07:00
|
|
|
#include <linux/clkdev.h>
|
2011-06-01 06:08:09 +07:00
|
|
|
#include <linux/pm_runtime.h>
|
2011-08-10 18:32:08 +07:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/notifier.h>
|
2009-09-04 00:14:05 +07:00
|
|
|
|
2013-12-07 01:52:58 +07:00
|
|
|
#include "common.h"
|
2013-01-12 02:24:18 +07:00
|
|
|
#include "soc.h"
|
2012-10-03 07:25:48 +07:00
|
|
|
#include "omap_device.h"
|
2012-10-03 07:41:35 +07:00
|
|
|
#include "omap_hwmod.h"
|
2009-09-04 00:14:05 +07:00
|
|
|
|
|
|
|
/* Private functions */
|
|
|
|
|
2011-07-10 18:54:12 +07:00
|
|
|
static void _add_clkdev(struct omap_device *od, const char *clk_alias,
|
|
|
|
const char *clk_name)
|
|
|
|
{
|
|
|
|
struct clk *r;
|
|
|
|
struct clk_lookup *l;
|
|
|
|
|
|
|
|
if (!clk_alias || !clk_name)
|
|
|
|
return;
|
|
|
|
|
2011-07-22 03:58:51 +07:00
|
|
|
dev_dbg(&od->pdev->dev, "Creating %s -> %s\n", clk_alias, clk_name);
|
2011-07-10 18:54:12 +07:00
|
|
|
|
2011-07-22 03:58:51 +07:00
|
|
|
r = clk_get_sys(dev_name(&od->pdev->dev), clk_alias);
|
2011-07-10 18:54:12 +07:00
|
|
|
if (!IS_ERR(r)) {
|
2014-08-26 06:15:34 +07:00
|
|
|
dev_dbg(&od->pdev->dev,
|
2011-07-21 23:58:36 +07:00
|
|
|
"alias %s already exists\n", clk_alias);
|
2011-07-10 18:54:12 +07:00
|
|
|
clk_put(r);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-22 15:24:16 +07:00
|
|
|
r = clk_get(NULL, clk_name);
|
2011-07-10 18:54:12 +07:00
|
|
|
if (IS_ERR(r)) {
|
2011-07-22 03:58:51 +07:00
|
|
|
dev_err(&od->pdev->dev,
|
2012-09-22 15:24:16 +07:00
|
|
|
"clk_get for %s failed\n", clk_name);
|
2011-07-10 18:54:12 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-22 03:58:51 +07:00
|
|
|
l = clkdev_alloc(r, clk_alias, dev_name(&od->pdev->dev));
|
2011-07-10 18:54:12 +07:00
|
|
|
if (!l) {
|
2011-07-22 03:58:51 +07:00
|
|
|
dev_err(&od->pdev->dev,
|
2011-07-21 23:58:36 +07:00
|
|
|
"clkdev_alloc for %s failed\n", clk_alias);
|
2011-07-10 18:54:12 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
clkdev_add(l);
|
|
|
|
}
|
|
|
|
|
2010-09-22 00:23:04 +07:00
|
|
|
/**
|
2011-07-10 18:54:12 +07:00
|
|
|
* _add_hwmod_clocks_clkdev - Add clkdev entry for hwmod optional clocks
|
|
|
|
* and main clock
|
2010-09-22 00:23:04 +07:00
|
|
|
* @od: struct omap_device *od
|
2011-07-10 18:54:12 +07:00
|
|
|
* @oh: struct omap_hwmod *oh
|
2010-09-22 00:23:04 +07:00
|
|
|
*
|
2011-07-10 18: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-22 00: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 18:54:12 +07:00
|
|
|
* In the case of the main clock, a "fck" alias is used.
|
2010-09-22 00:23:04 +07:00
|
|
|
*
|
|
|
|
* No return value.
|
|
|
|
*/
|
2011-07-10 18:54:12 +07:00
|
|
|
static void _add_hwmod_clocks_clkdev(struct omap_device *od,
|
|
|
|
struct omap_hwmod *oh)
|
2010-09-22 00:23:04 +07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2011-07-10 18:54:12 +07:00
|
|
|
_add_clkdev(od, "fck", oh->main_clk);
|
2011-02-26 05:40:21 +07:00
|
|
|
|
2011-07-10 18: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-22 00:23:04 +07:00
|
|
|
}
|
|
|
|
|
2009-09-04 00:14:05 +07:00
|
|
|
|
2011-08-10 18:32:08 +07:00
|
|
|
/**
|
|
|
|
* omap_device_build_from_dt - build an omap_device with multiple hwmods
|
|
|
|
* @pdev_name: name of the platform_device driver to use
|
|
|
|
* @pdev_id: this platform_device's connection ID
|
|
|
|
* @oh: ptr to the single omap_hwmod that backs this omap_device
|
|
|
|
* @pdata: platform_data ptr to associate with the platform_device
|
|
|
|
* @pdata_len: amount of memory pointed to by @pdata
|
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
const char *oh_name;
|
|
|
|
int oh_cnt, i, ret = 0;
|
2013-07-29 12:01:51 +07:00
|
|
|
bool device_active = false;
|
2011-08-10 18: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-14 03:44:21 +07:00
|
|
|
if (oh_cnt <= 0) {
|
2012-01-21 00:14:00 +07:00
|
|
|
dev_dbg(&pdev->dev, "No 'hwmods' to build omap_device\n");
|
2011-08-10 18:32:08 +07:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
|
|
|
|
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-29 12:01:51 +07:00
|
|
|
if (oh->flags & HWMOD_INIT_NO_IDLE)
|
|
|
|
device_active = true;
|
2011-08-10 18:32:08 +07:00
|
|
|
}
|
|
|
|
|
2013-01-26 14:48:53 +07:00
|
|
|
od = omap_device_alloc(pdev, hwmods, oh_cnt);
|
2013-09-19 02:01:58 +07:00
|
|
|
if (IS_ERR(od)) {
|
2011-08-10 18: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 20: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);
|
|
|
|
}
|
|
|
|
|
2011-08-10 18:32:08 +07:00
|
|
|
pdev->dev.pm_domain = &omap_device_pm_domain;
|
|
|
|
|
2013-07-29 12:01:51 +07:00
|
|
|
if (device_active) {
|
|
|
|
omap_device_enable(pdev);
|
|
|
|
pm_runtime_set_active(&pdev->dev);
|
|
|
|
}
|
|
|
|
|
2011-08-10 18: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-04 08:39:13 +07:00
|
|
|
/* if data/we are at fault.. load up a fail handler */
|
|
|
|
if (ret)
|
|
|
|
pdev->dev.pm_domain = &omap_device_fail_pm_domain;
|
|
|
|
|
2011-08-10 18: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-11 01:13:16 +07:00
|
|
|
struct omap_device *od;
|
2011-08-10 18:32:08 +07:00
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case BUS_NOTIFY_DEL_DEVICE:
|
|
|
|
if (pdev->archdata.od)
|
|
|
|
omap_device_delete(pdev->archdata.od);
|
|
|
|
break;
|
2012-07-11 01:13:16 +07:00
|
|
|
case BUS_NOTIFY_ADD_DEVICE:
|
|
|
|
if (pdev->dev.of_node)
|
|
|
|
omap_device_build_from_dt(pdev);
|
2013-12-07 01:52:58 +07:00
|
|
|
omap_auxdata_legacy_init(dev);
|
2012-07-11 01:13:16 +07:00
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
od = to_omap_device(pdev);
|
|
|
|
if (od)
|
|
|
|
od->_driver_status = event;
|
2011-08-10 18:32:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
2013-01-26 14: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)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < od->hwmods_cnt; i++)
|
|
|
|
omap_hwmod_enable(od->hwmods[i]);
|
|
|
|
|
|
|
|
/* XXX pass along return value here? */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _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)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < od->hwmods_cnt; i++)
|
|
|
|
omap_hwmod_idle(od->hwmods[i]);
|
|
|
|
|
|
|
|
/* XXX pass along return value here? */
|
|
|
|
return 0;
|
|
|
|
}
|
2011-08-10 18:32:08 +07:00
|
|
|
|
2009-09-04 00:14:05 +07:00
|
|
|
/* Public functions for use by core code */
|
|
|
|
|
2010-12-22 11:31:55 +07:00
|
|
|
/**
|
|
|
|
* omap_device_get_context_loss_count - get lost context count
|
|
|
|
* @od: struct omap_device *
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* If any hwmods exist for the omap_device assoiated with @pdev,
|
|
|
|
* return the context loss counter for that hwmod, otherwise return
|
|
|
|
* zero.
|
|
|
|
*/
|
2011-06-09 20:56:23 +07:00
|
|
|
int omap_device_get_context_loss_count(struct platform_device *pdev)
|
2010-12-22 11:31:55 +07:00
|
|
|
{
|
|
|
|
struct omap_device *od;
|
|
|
|
u32 ret = 0;
|
|
|
|
|
2011-07-10 08:15:20 +07:00
|
|
|
od = to_omap_device(pdev);
|
2010-12-22 11:31:55 +07:00
|
|
|
|
|
|
|
if (od->hwmods_cnt)
|
|
|
|
ret = omap_hwmod_get_context_loss_count(od->hwmods[0]);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-09-04 00:14:05 +07:00
|
|
|
/**
|
|
|
|
* omap_device_count_resources - count number of struct resource entries needed
|
|
|
|
* @od: struct omap_device *
|
2012-11-22 06:15:17 +07:00
|
|
|
* @flags: Type of resources to include when counting (IRQ/DMA/MEM)
|
2009-09-04 00:14:05 +07:00
|
|
|
*
|
|
|
|
* Count the number of struct resource entries needed for this
|
|
|
|
* omap_device @od. Used by omap_device_build_ss() to determine how
|
|
|
|
* much memory to allocate before calling
|
|
|
|
* omap_device_fill_resources(). Returns the count.
|
|
|
|
*/
|
2012-11-22 06:15:17 +07:00
|
|
|
static int omap_device_count_resources(struct omap_device *od,
|
|
|
|
unsigned long flags)
|
2009-09-04 00:14:05 +07:00
|
|
|
{
|
|
|
|
int c = 0;
|
|
|
|
int i;
|
|
|
|
|
2010-09-24 23:23:18 +07:00
|
|
|
for (i = 0; i < od->hwmods_cnt; i++)
|
2012-11-22 06:15:17 +07:00
|
|
|
c += omap_hwmod_count_resources(od->hwmods[i], flags);
|
2009-09-04 00:14:05 +07:00
|
|
|
|
2012-07-26 13:54:26 +07:00
|
|
|
pr_debug("omap_device: %s: counted %d total resources across %d hwmods\n",
|
|
|
|
od->pdev->name, c, od->hwmods_cnt);
|
2009-09-04 00:14:05 +07:00
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_device_fill_resources - fill in array of struct resource
|
|
|
|
* @od: struct omap_device *
|
|
|
|
* @res: pointer to an array of struct resource to be filled in
|
|
|
|
*
|
|
|
|
* Populate one or more empty struct resource pointed to by @res with
|
|
|
|
* the resource data for this omap_device @od. Used by
|
|
|
|
* omap_device_build_ss() after calling omap_device_count_resources().
|
|
|
|
* Ideally this function would not be needed at all. If omap_device
|
|
|
|
* replaces platform_device, then we can specify our own
|
|
|
|
* get_resource()/ get_irq()/etc functions that use the underlying
|
|
|
|
* omap_hwmod information. Or if platform_device is extended to use
|
|
|
|
* subarchitecture-specific function pointers, the various
|
|
|
|
* platform_device functions can simply call omap_device internal
|
|
|
|
* functions to get device resources. Hacking around the existing
|
|
|
|
* platform_device code wastes memory. Returns 0.
|
|
|
|
*/
|
2011-07-22 04:14:35 +07:00
|
|
|
static int omap_device_fill_resources(struct omap_device *od,
|
|
|
|
struct resource *res)
|
2009-09-04 00:14:05 +07:00
|
|
|
{
|
|
|
|
int i, r;
|
|
|
|
|
2010-09-24 23:23:18 +07:00
|
|
|
for (i = 0; i < od->hwmods_cnt; i++) {
|
|
|
|
r = omap_hwmod_fill_resources(od->hwmods[i], res);
|
2009-09-04 00:14:05 +07:00
|
|
|
res += r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-29 16:48:11 +07:00
|
|
|
/**
|
|
|
|
* _od_fill_dma_resources - fill in array of struct resource with dma resources
|
|
|
|
* @od: struct omap_device *
|
|
|
|
* @res: pointer to an array of struct resource to be filled in
|
|
|
|
*
|
|
|
|
* Populate one or more empty struct resource pointed to by @res with
|
|
|
|
* the dma resource data for this omap_device @od. Used by
|
|
|
|
* omap_device_alloc() after calling omap_device_count_resources().
|
|
|
|
*
|
|
|
|
* Ideally this function would not be needed at all. If we have
|
|
|
|
* mechanism to get dma resources from DT.
|
|
|
|
*
|
|
|
|
* Returns 0.
|
|
|
|
*/
|
|
|
|
static int _od_fill_dma_resources(struct omap_device *od,
|
|
|
|
struct resource *res)
|
|
|
|
{
|
|
|
|
int i, r;
|
|
|
|
|
|
|
|
for (i = 0; i < od->hwmods_cnt; i++) {
|
|
|
|
r = omap_hwmod_fill_dma_resources(od->hwmods[i], res);
|
|
|
|
res += r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-09 21:47:01 +07:00
|
|
|
/**
|
|
|
|
* omap_device_alloc - allocate an omap_device
|
|
|
|
* @pdev: platform_device that will be included in this omap_device
|
|
|
|
* @oh: ptr to the single omap_hwmod that backs this omap_device
|
|
|
|
* @pdata: platform_data ptr to associate with the platform_device
|
|
|
|
* @pdata_len: amount of memory pointed to by @pdata
|
|
|
|
*
|
|
|
|
* Convenience function for allocating an omap_device structure and filling
|
2013-01-26 14:48:53 +07:00
|
|
|
* hwmods, and resources.
|
2011-08-09 21: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-21 00:43:29 +07:00
|
|
|
struct omap_device *omap_device_alloc(struct platform_device *pdev,
|
2013-01-26 14:48:53 +07:00
|
|
|
struct omap_hwmod **ohs, int oh_cnt)
|
2011-08-09 21:47:01 +07:00
|
|
|
{
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
struct omap_device *od;
|
|
|
|
struct resource *res = NULL;
|
|
|
|
int i, res_count;
|
|
|
|
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;
|
|
|
|
|
|
|
|
/*
|
2012-11-22 06:15:18 +07:00
|
|
|
* Non-DT Boot:
|
|
|
|
* Here, pdev->num_resources = 0, and we should get all the
|
|
|
|
* resources from hwmod.
|
|
|
|
*
|
2012-08-29 16:48:11 +07:00
|
|
|
* DT Boot:
|
|
|
|
* OF framework will construct the resource structure (currently
|
|
|
|
* does for MEM & IRQ resource) and we should respect/use these
|
|
|
|
* resources, killing hwmod dependency.
|
|
|
|
* If pdev->num_resources > 0, we assume that MEM & IRQ resources
|
|
|
|
* have been allocated by OF layer already (through DTB).
|
2012-11-22 06:15:18 +07:00
|
|
|
* As preparation for the future we examine the OF provided resources
|
|
|
|
* to see if we have DMA resources provided already. In this case
|
|
|
|
* there is no need to update the resources for the device, we use the
|
|
|
|
* OF provided ones.
|
2012-08-29 16:48:11 +07:00
|
|
|
*
|
|
|
|
* TODO: Once DMA resource is available from OF layer, we should
|
|
|
|
* kill filling any resources from hwmod.
|
2011-08-09 21:47:01 +07:00
|
|
|
*/
|
2012-11-22 06:15:18 +07:00
|
|
|
if (!pdev->num_resources) {
|
|
|
|
/* Count all resources for the device */
|
|
|
|
res_count = omap_device_count_resources(od, IORESOURCE_IRQ |
|
|
|
|
IORESOURCE_DMA |
|
|
|
|
IORESOURCE_MEM);
|
|
|
|
} else {
|
|
|
|
/* Take a look if we already have DMA resource via DT */
|
|
|
|
for (i = 0; i < pdev->num_resources; i++) {
|
|
|
|
struct resource *r = &pdev->resource[i];
|
|
|
|
|
|
|
|
/* We have it, no need to touch the resources */
|
|
|
|
if (r->flags == IORESOURCE_DMA)
|
|
|
|
goto have_everything;
|
2012-08-29 16:48:11 +07:00
|
|
|
}
|
2012-11-22 06:15:18 +07:00
|
|
|
/* Count only DMA resources for the device */
|
|
|
|
res_count = omap_device_count_resources(od, IORESOURCE_DMA);
|
|
|
|
/* The device has no DMA resource, no need for update */
|
|
|
|
if (!res_count)
|
|
|
|
goto have_everything;
|
2011-08-09 21:47:01 +07:00
|
|
|
|
2012-11-22 06:15:18 +07:00
|
|
|
res_count += pdev->num_resources;
|
|
|
|
}
|
2011-08-09 21:47:01 +07:00
|
|
|
|
2012-11-22 06:15:18 +07:00
|
|
|
/* Allocate resources memory to account for new resources */
|
|
|
|
res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
|
|
|
|
if (!res)
|
|
|
|
goto oda_exit3;
|
|
|
|
|
|
|
|
if (!pdev->num_resources) {
|
|
|
|
dev_dbg(&pdev->dev, "%s: using %d resources from hwmod\n",
|
|
|
|
__func__, res_count);
|
|
|
|
omap_device_fill_resources(od, res);
|
|
|
|
} else {
|
|
|
|
dev_dbg(&pdev->dev,
|
|
|
|
"%s: appending %d DMA resources from hwmod\n",
|
|
|
|
__func__, res_count - pdev->num_resources);
|
|
|
|
memcpy(res, pdev->resource,
|
|
|
|
sizeof(struct resource) * pdev->num_resources);
|
|
|
|
_od_fill_dma_resources(od, &res[pdev->num_resources]);
|
2011-08-09 21:47:01 +07:00
|
|
|
}
|
|
|
|
|
2012-11-22 06:15:18 +07:00
|
|
|
ret = platform_device_add_resources(pdev, res, res_count);
|
|
|
|
kfree(res);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
goto oda_exit3;
|
|
|
|
|
|
|
|
have_everything:
|
2011-08-09 21:47:01 +07:00
|
|
|
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_exit3:
|
|
|
|
kfree(hwmods);
|
|
|
|
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-21 00:43:29 +07:00
|
|
|
void omap_device_delete(struct omap_device *od)
|
2011-08-09 21:47:01 +07:00
|
|
|
{
|
2011-08-10 18:32:08 +07:00
|
|
|
if (!od)
|
|
|
|
return;
|
|
|
|
|
2011-08-09 21:47:01 +07:00
|
|
|
od->pdev->archdata.od = NULL;
|
|
|
|
kfree(od->hwmods);
|
|
|
|
kfree(od);
|
|
|
|
}
|
|
|
|
|
2009-09-04 00:14:05 +07:00
|
|
|
/**
|
|
|
|
* omap_device_build - build and register an omap_device with one omap_hwmod
|
|
|
|
* @pdev_name: name of the platform_device driver to use
|
|
|
|
* @pdev_id: this platform_device's connection ID
|
|
|
|
* @oh: ptr to the single omap_hwmod that backs this omap_device
|
|
|
|
* @pdata: platform_data ptr to associate with the platform_device
|
|
|
|
* @pdata_len: amount of memory pointed to by @pdata
|
|
|
|
*
|
|
|
|
* Convenience function for building and registering a single
|
|
|
|
* omap_device record, which in turn builds and registers a
|
|
|
|
* platform_device record. See omap_device_build_ss() for more
|
|
|
|
* information. Returns ERR_PTR(-EINVAL) if @oh is NULL; otherwise,
|
|
|
|
* passes along the return value of omap_device_build_ss().
|
|
|
|
*/
|
2013-01-26 14:48:53 +07:00
|
|
|
struct platform_device __init *omap_device_build(const char *pdev_name,
|
|
|
|
int pdev_id,
|
|
|
|
struct omap_hwmod *oh,
|
|
|
|
void *pdata, int pdata_len)
|
2009-09-04 00:14:05 +07:00
|
|
|
{
|
|
|
|
struct omap_hwmod *ohs[] = { oh };
|
|
|
|
|
|
|
|
if (!oh)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata,
|
2013-01-26 14:48:53 +07:00
|
|
|
pdata_len);
|
2009-09-04 00:14:05 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_device_build_ss - build and register an omap_device with multiple hwmods
|
|
|
|
* @pdev_name: name of the platform_device driver to use
|
|
|
|
* @pdev_id: this platform_device's connection ID
|
|
|
|
* @oh: ptr to the single omap_hwmod that backs this omap_device
|
|
|
|
* @pdata: platform_data ptr to associate with the platform_device
|
|
|
|
* @pdata_len: amount of memory pointed to by @pdata
|
|
|
|
*
|
|
|
|
* Convenience function for building and registering an omap_device
|
|
|
|
* subsystem record. Subsystem records consist of multiple
|
|
|
|
* omap_hwmods. This function in turn builds and registers a
|
|
|
|
* platform_device record. Returns an ERR_PTR() on error, or passes
|
|
|
|
* along the return value of omap_device_register().
|
|
|
|
*/
|
2013-01-26 14:48:53 +07:00
|
|
|
struct platform_device __init *omap_device_build_ss(const char *pdev_name,
|
|
|
|
int pdev_id,
|
|
|
|
struct omap_hwmod **ohs,
|
|
|
|
int oh_cnt, void *pdata,
|
|
|
|
int pdata_len)
|
2009-09-04 00:14:05 +07:00
|
|
|
{
|
|
|
|
int ret = -ENOMEM;
|
2011-07-22 03:58:51 +07:00
|
|
|
struct platform_device *pdev;
|
2009-09-04 00:14:05 +07:00
|
|
|
struct omap_device *od;
|
|
|
|
|
|
|
|
if (!ohs || oh_cnt == 0 || !pdev_name)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
if (!pdata && pdata_len > 0)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
2011-07-22 03:58:51 +07:00
|
|
|
pdev = platform_device_alloc(pdev_name, pdev_id);
|
|
|
|
if (!pdev) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto odbs_exit;
|
|
|
|
}
|
|
|
|
|
2011-08-09 21:47:01 +07:00
|
|
|
/* Set the dev_name early to allow dev_xxx in omap_device_alloc */
|
|
|
|
if (pdev->id != -1)
|
|
|
|
dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
|
|
|
|
else
|
|
|
|
dev_set_name(&pdev->dev, "%s", pdev->name);
|
2009-09-04 00:14:05 +07:00
|
|
|
|
2013-01-26 14:48:53 +07:00
|
|
|
od = omap_device_alloc(pdev, ohs, oh_cnt);
|
2012-09-21 13:32:04 +07:00
|
|
|
if (IS_ERR(od))
|
2011-07-22 03:58:51 +07:00
|
|
|
goto odbs_exit1;
|
|
|
|
|
|
|
|
ret = platform_device_add_data(pdev, pdata, pdata_len);
|
2010-07-12 20:38:07 +07:00
|
|
|
if (ret)
|
2011-08-09 21:47:01 +07:00
|
|
|
goto odbs_exit2;
|
2009-09-04 00:14:05 +07:00
|
|
|
|
2013-01-26 14:48:53 +07:00
|
|
|
ret = omap_device_register(pdev);
|
2011-07-22 03:58:51 +07:00
|
|
|
if (ret)
|
2011-08-09 21:47:01 +07:00
|
|
|
goto odbs_exit2;
|
2010-07-27 05:34:30 +07:00
|
|
|
|
2011-07-22 03:58:51 +07:00
|
|
|
return pdev;
|
2009-09-04 00:14:05 +07:00
|
|
|
|
2011-07-22 03:58:51 +07:00
|
|
|
odbs_exit2:
|
2011-08-09 21:47:01 +07:00
|
|
|
omap_device_delete(od);
|
2011-07-22 03:58:51 +07:00
|
|
|
odbs_exit1:
|
|
|
|
platform_device_put(pdev);
|
|
|
|
odbs_exit:
|
2009-09-04 00:14:05 +07:00
|
|
|
|
|
|
|
pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret);
|
|
|
|
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
2014-12-13 06:42:49 +07:00
|
|
|
#ifdef CONFIG_PM
|
2011-04-29 05:36:42 +07:00
|
|
|
static int _od_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
2011-06-01 06:08:09 +07:00
|
|
|
int ret;
|
2011-04-29 05:36:42 +07:00
|
|
|
|
2011-06-01 06:08:09 +07:00
|
|
|
ret = pm_generic_runtime_suspend(dev);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
omap_device_idle(pdev);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-29 05:36:42 +07:00
|
|
|
static int _od_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
|
2011-06-01 06:08:09 +07:00
|
|
|
omap_device_enable(pdev);
|
|
|
|
|
|
|
|
return pm_generic_runtime_resume(dev);
|
2011-04-29 05: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-04 08: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-13 03:48:03 +07:00
|
|
|
#endif
|
2011-04-29 05:36:42 +07:00
|
|
|
|
2011-07-13 03: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-11 05: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-13 03:48:19 +07:00
|
|
|
ret = pm_generic_suspend_noirq(dev);
|
|
|
|
|
|
|
|
if (!ret && !pm_runtime_status_suspended(dev)) {
|
|
|
|
if (pm_generic_runtime_suspend(dev) == 0) {
|
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-15 00:05:16 +07:00
|
|
|
pm_runtime_set_suspended(dev);
|
2013-04-27 03:25:34 +07:00
|
|
|
omap_device_idle(pdev);
|
2011-07-13 03: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-15 00:05:16 +07:00
|
|
|
if (od->flags & OMAP_DEVICE_SUSPENDED) {
|
2011-07-13 03:48:19 +07:00
|
|
|
od->flags &= ~OMAP_DEVICE_SUSPENDED;
|
2013-04-27 03:25:34 +07:00
|
|
|
omap_device_enable(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-15 00:05:16 +07:00
|
|
|
/*
|
|
|
|
* XXX: we run before core runtime pm has resumed itself. At
|
|
|
|
* this point in time, we just restore the runtime pm state and
|
|
|
|
* considering symmetric operations in resume, we donot expect
|
|
|
|
* to fail. If we failed, something changed in core runtime_pm
|
|
|
|
* framework OR some device driver messed things up, hence, WARN
|
|
|
|
*/
|
|
|
|
WARN(pm_runtime_set_active(dev),
|
|
|
|
"Could not set %s runtime state active\n", dev_name(dev));
|
2011-07-13 03:48:19 +07:00
|
|
|
pm_generic_runtime_resume(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pm_generic_resume_noirq(dev);
|
|
|
|
}
|
2011-09-02 00:59:36 +07:00
|
|
|
#else
|
|
|
|
#define _od_suspend_noirq NULL
|
|
|
|
#define _od_resume_noirq NULL
|
2011-07-13 03: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-04 08: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-16 02:47:45 +07:00
|
|
|
struct dev_pm_domain omap_device_pm_domain = {
|
2011-04-29 05:36:42 +07:00
|
|
|
.ops = {
|
2011-07-13 03: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-04 02:49:52 +07:00
|
|
|
NULL)
|
2011-04-29 05:36:42 +07:00
|
|
|
USE_PLATFORM_PM_SLEEP_OPS
|
2011-08-25 20:31:14 +07:00
|
|
|
.suspend_noirq = _od_suspend_noirq,
|
|
|
|
.resume_noirq = _od_resume_noirq,
|
2011-04-29 05:36:42 +07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-09-04 00:14:05 +07:00
|
|
|
/**
|
|
|
|
* omap_device_register - register an omap_device with one omap_hwmod
|
|
|
|
* @od: struct omap_device * to register
|
|
|
|
*
|
|
|
|
* 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-21 00:43:29 +07:00
|
|
|
int omap_device_register(struct platform_device *pdev)
|
2009-09-04 00:14:05 +07:00
|
|
|
{
|
2011-07-22 04:47:53 +07:00
|
|
|
pr_debug("omap_device: %s: registering\n", pdev->name);
|
2009-09-04 00:14:05 +07:00
|
|
|
|
2011-07-22 04:47:53 +07:00
|
|
|
pdev->dev.pm_domain = &omap_device_pm_domain;
|
2011-07-22 03:58:51 +07:00
|
|
|
return platform_device_add(pdev);
|
2009-09-04 00:14:05 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Public functions for use by device drivers through struct platform_data */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_device_enable - fully activate an omap_device
|
|
|
|
* @od: struct omap_device * to activate
|
|
|
|
*
|
|
|
|
* 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 14: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-04 00:14:05 +07:00
|
|
|
*/
|
|
|
|
int omap_device_enable(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct omap_device *od;
|
|
|
|
|
2011-07-10 08:15:20 +07:00
|
|
|
od = to_omap_device(pdev);
|
2009-09-04 00:14:05 +07:00
|
|
|
|
|
|
|
if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
|
2011-07-21 23:58:36 +07:00
|
|
|
dev_warn(&pdev->dev,
|
|
|
|
"omap_device: %s() called from invalid state %d\n",
|
|
|
|
__func__, od->_state);
|
2009-09-04 00:14:05 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-01-26 14:48:53 +07:00
|
|
|
ret = _omap_device_enable_hwmods(od);
|
2009-09-04 00:14:05 +07:00
|
|
|
|
|
|
|
od->_state = OMAP_DEVICE_STATE_ENABLED;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_device_idle - idle an omap_device
|
|
|
|
* @od: struct omap_device * to idle
|
|
|
|
*
|
2013-01-26 14: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-04 00:14:05 +07:00
|
|
|
* currently enabled, or passes along the return value of
|
2013-01-26 14:48:53 +07:00
|
|
|
* _omap_device_idle_hwmods().
|
2009-09-04 00:14:05 +07:00
|
|
|
*/
|
|
|
|
int omap_device_idle(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct omap_device *od;
|
|
|
|
|
2011-07-10 08:15:20 +07:00
|
|
|
od = to_omap_device(pdev);
|
2009-09-04 00:14:05 +07:00
|
|
|
|
|
|
|
if (od->_state != OMAP_DEVICE_STATE_ENABLED) {
|
2011-07-21 23:58:36 +07:00
|
|
|
dev_warn(&pdev->dev,
|
|
|
|
"omap_device: %s() called from invalid state %d\n",
|
|
|
|
__func__, od->_state);
|
2009-09-04 00:14:05 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-01-26 14:48:53 +07:00
|
|
|
ret = _omap_device_idle_hwmods(od);
|
2009-09-04 00:14:05 +07:00
|
|
|
|
|
|
|
od->_state = OMAP_DEVICE_STATE_IDLE;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-24 06: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-28 03: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 17:56:59 +07:00
|
|
|
if (!oh) {
|
2011-07-28 03:02:32 +07:00
|
|
|
WARN(1, "%s: no hwmod for %s\n", __func__,
|
|
|
|
oh_name);
|
2013-02-24 17:56:59 +07:00
|
|
|
return ERR_PTR(-ENODEV);
|
2011-07-28 03:02:32 +07:00
|
|
|
}
|
2013-02-24 17:56:59 +07:00
|
|
|
if (!oh->od) {
|
2011-07-28 03:02:32 +07:00
|
|
|
WARN(1, "%s: no omap_device for %s\n", __func__,
|
|
|
|
oh_name);
|
2013-02-24 17:56:59 +07:00
|
|
|
return ERR_PTR(-ENODEV);
|
2011-07-28 03:02:32 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return &oh->od->pdev->dev;
|
|
|
|
}
|
2010-08-23 22:10:55 +07:00
|
|
|
|
2011-08-10 18:32:08 +07:00
|
|
|
static struct notifier_block platform_nb = {
|
|
|
|
.notifier_call = _omap_device_notifier_call,
|
|
|
|
};
|
|
|
|
|
2010-08-23 22:10:55 +07:00
|
|
|
static int __init omap_device_init(void)
|
|
|
|
{
|
2011-08-10 18:32:08 +07:00
|
|
|
bus_register_notifier(&platform_bus_type, &platform_nb);
|
2012-02-16 02:47:45 +07:00
|
|
|
return 0;
|
2010-08-23 22:10:55 +07:00
|
|
|
}
|
2013-01-12 02:24:18 +07:00
|
|
|
omap_core_initcall(omap_device_init);
|
2012-07-11 05: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-29 12:01:50 +07:00
|
|
|
int i;
|
2012-07-11 05:06:11 +07:00
|
|
|
|
|
|
|
if (!od)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If omap_device state is enabled, but has no driver bound,
|
|
|
|
* idle it.
|
|
|
|
*/
|
2013-07-29 12: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;
|
|
|
|
|
2012-07-11 05:06:11 +07:00
|
|
|
if (od->_driver_status != BUS_NOTIFY_BOUND_DRIVER) {
|
|
|
|
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-28 03:05:54 +07:00
|
|
|
|
|
|
|
WARN(!of_have_populated_dt(),
|
|
|
|
"legacy booting deprecated, please update to boot with .dts\n");
|
|
|
|
|
2012-07-11 05:06:11 +07:00
|
|
|
return 0;
|
|
|
|
}
|
2013-05-09 06:48:01 +07:00
|
|
|
omap_late_initcall_sync(omap_device_late_init);
|