2009-09-03 17:14:05 +00:00
|
|
|
/*
|
|
|
|
* omap_device implementation
|
|
|
|
*
|
2010-07-26 22:34:33 +00:00
|
|
|
* Copyright (C) 2009-2010 Nokia Corporation
|
2010-05-19 02:24:05 +00:00
|
|
|
* Paul Walmsley, Kevin Hilman
|
2009-09-03 17:14:05 +00:00
|
|
|
*
|
|
|
|
* Developed in collaboration with (alphabetical order): Benoit
|
2010-05-19 02:24:05 +00:00
|
|
|
* Cousson, Thara Gopinath, Tony Lindgren, Rajendra Nayak, Vikram
|
2009-09-03 17:14:05 +00: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.
|
|
|
|
*
|
|
|
|
* In the medium- to long-term, this code should either be
|
|
|
|
* a) implemented via arch-specific pointers in platform_data
|
|
|
|
* or
|
|
|
|
* b) implemented as a proper omap_bus/omap_device in Linux, no more
|
|
|
|
* platform_data func pointers
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Guidelines for usage by driver authors:
|
|
|
|
*
|
|
|
|
* 1. These functions are intended to be used by device drivers via
|
|
|
|
* function pointers in struct platform_data. As an example,
|
|
|
|
* omap_device_enable() should be passed to the driver as
|
|
|
|
*
|
|
|
|
* struct foo_driver_platform_data {
|
|
|
|
* ...
|
|
|
|
* int (*device_enable)(struct platform_device *pdev);
|
|
|
|
* ...
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* Note that the generic "device_enable" name is used, rather than
|
|
|
|
* "omap_device_enable". This is so other architectures can pass in their
|
|
|
|
* own enable/disable functions here.
|
|
|
|
*
|
|
|
|
* This should be populated during device setup:
|
|
|
|
*
|
|
|
|
* ...
|
|
|
|
* pdata->device_enable = omap_device_enable;
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* 2. Drivers should first check to ensure the function pointer is not null
|
|
|
|
* before calling it, as in:
|
|
|
|
*
|
|
|
|
* if (pdata->device_enable)
|
|
|
|
* pdata->device_enable(pdev);
|
|
|
|
*
|
|
|
|
* This allows other architectures that don't use similar device_enable()/
|
|
|
|
* device_shutdown() functions to execute normally.
|
|
|
|
*
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* Suggested usage by device drivers:
|
|
|
|
*
|
|
|
|
* During device initialization:
|
|
|
|
* device_enable()
|
|
|
|
*
|
|
|
|
* During device idle:
|
|
|
|
* (save remaining device context if necessary)
|
|
|
|
* device_idle();
|
|
|
|
*
|
|
|
|
* During device resume:
|
|
|
|
* device_enable();
|
|
|
|
* (restore context if necessary)
|
|
|
|
*
|
|
|
|
* During device shutdown:
|
|
|
|
* device_shutdown()
|
|
|
|
* (device must be reinitialized at this point to use it again)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#undef DEBUG
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
2011-11-07 20:27:10 +00:00
|
|
|
#include <linux/export.h>
|
2009-09-03 17:14:05 +00:00
|
|
|
#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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2009-09-03 17:14:05 +00:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/io.h>
|
2010-09-21 17:23:04 +00:00
|
|
|
#include <linux/clk.h>
|
2011-02-25 22:40:21 +00:00
|
|
|
#include <linux/clkdev.h>
|
2011-05-31 23:08:09 +00:00
|
|
|
#include <linux/pm_runtime.h>
|
2011-08-10 11:32:08 +00:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/notifier.h>
|
2009-09-03 17:14:05 +00:00
|
|
|
|
2009-10-20 16:40:47 +00:00
|
|
|
#include <plat/omap_device.h>
|
|
|
|
#include <plat/omap_hwmod.h>
|
2011-02-25 22:40:21 +00:00
|
|
|
#include <plat/clock.h>
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
/* These parameters are passed to _omap_device_{de,}activate() */
|
|
|
|
#define USE_WAKEUP_LAT 0
|
|
|
|
#define IGNORE_WAKEUP_LAT 1
|
|
|
|
|
2011-07-21 21:47:53 +00:00
|
|
|
static int omap_device_register(struct platform_device *pdev);
|
|
|
|
static int omap_early_device_register(struct platform_device *pdev);
|
2011-08-09 14:47:01 +00:00
|
|
|
static struct omap_device *omap_device_alloc(struct platform_device *pdev,
|
|
|
|
struct omap_hwmod **ohs, int oh_cnt,
|
|
|
|
struct omap_device_pm_latency *pm_lats,
|
|
|
|
int pm_lats_cnt);
|
2011-08-10 11:32:08 +00:00
|
|
|
static void omap_device_delete(struct omap_device *od);
|
2011-08-09 14:47:01 +00:00
|
|
|
|
2011-07-21 21:14:35 +00:00
|
|
|
|
2011-08-09 14:54:19 +00:00
|
|
|
static struct omap_device_pm_latency omap_default_latency[] = {
|
|
|
|
{
|
|
|
|
.deactivate_func = omap_device_idle_hwmods,
|
|
|
|
.activate_func = omap_device_enable_hwmods,
|
|
|
|
.flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-09-03 17:14:05 +00:00
|
|
|
/* Private functions */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _omap_device_activate - increase device readiness
|
|
|
|
* @od: struct omap_device *
|
|
|
|
* @ignore_lat: increase to latency target (0) or full readiness (1)?
|
|
|
|
*
|
|
|
|
* Increase readiness of omap_device @od (thus decreasing device
|
|
|
|
* wakeup latency, but consuming more power). If @ignore_lat is
|
|
|
|
* IGNORE_WAKEUP_LAT, make the omap_device fully active. Otherwise,
|
|
|
|
* if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup
|
|
|
|
* latency is greater than the requested maximum wakeup latency, step
|
|
|
|
* backwards in the omap_device_pm_latency table to ensure the
|
|
|
|
* device's maximum wakeup latency is less than or equal to the
|
|
|
|
* requested maximum wakeup latency. Returns 0.
|
|
|
|
*/
|
|
|
|
static int _omap_device_activate(struct omap_device *od, u8 ignore_lat)
|
|
|
|
{
|
2009-10-19 22:25:24 +00:00
|
|
|
struct timespec a, b, c;
|
2009-09-03 17:14:05 +00:00
|
|
|
|
2011-07-21 20:58:51 +00:00
|
|
|
dev_dbg(&od->pdev->dev, "omap_device: activating\n");
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
while (od->pm_lat_level > 0) {
|
|
|
|
struct omap_device_pm_latency *odpl;
|
2009-10-19 22:25:24 +00:00
|
|
|
unsigned long long act_lat = 0;
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
od->pm_lat_level--;
|
|
|
|
|
|
|
|
odpl = od->pm_lats + od->pm_lat_level;
|
|
|
|
|
|
|
|
if (!ignore_lat &&
|
|
|
|
(od->dev_wakeup_lat <= od->_dev_wakeup_lat_limit))
|
|
|
|
break;
|
|
|
|
|
2009-12-08 23:34:23 +00:00
|
|
|
read_persistent_clock(&a);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
/* XXX check return code */
|
|
|
|
odpl->activate_func(od);
|
|
|
|
|
2009-12-08 23:34:23 +00:00
|
|
|
read_persistent_clock(&b);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
2009-10-19 22:25:24 +00:00
|
|
|
c = timespec_sub(b, a);
|
2009-12-08 23:34:26 +00:00
|
|
|
act_lat = timespec_to_ns(&c);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
2011-07-21 20:58:51 +00:00
|
|
|
dev_dbg(&od->pdev->dev,
|
2011-07-21 16:58:36 +00:00
|
|
|
"omap_device: pm_lat %d: activate: elapsed time "
|
|
|
|
"%llu nsec\n", od->pm_lat_level, act_lat);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
2010-01-27 03:13:02 +00:00
|
|
|
if (act_lat > odpl->activate_lat) {
|
|
|
|
odpl->activate_lat_worst = act_lat;
|
|
|
|
if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
|
|
|
|
odpl->activate_lat = act_lat;
|
2011-07-21 20:58:51 +00:00
|
|
|
dev_dbg(&od->pdev->dev,
|
2011-07-25 13:18:24 +00:00
|
|
|
"new worst case activate latency "
|
|
|
|
"%d: %llu\n",
|
|
|
|
od->pm_lat_level, act_lat);
|
2010-01-27 03:13:02 +00:00
|
|
|
} else
|
2011-07-21 20:58:51 +00:00
|
|
|
dev_warn(&od->pdev->dev,
|
2011-07-21 16:58:36 +00:00
|
|
|
"activate latency %d "
|
|
|
|
"higher than exptected. (%llu > %d)\n",
|
|
|
|
od->pm_lat_level, act_lat,
|
|
|
|
odpl->activate_lat);
|
2010-01-27 03:13:02 +00:00
|
|
|
}
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
od->dev_wakeup_lat -= odpl->activate_lat;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _omap_device_deactivate - decrease device readiness
|
|
|
|
* @od: struct omap_device *
|
|
|
|
* @ignore_lat: decrease to latency target (0) or full inactivity (1)?
|
|
|
|
*
|
|
|
|
* Decrease readiness of omap_device @od (thus increasing device
|
|
|
|
* wakeup latency, but conserving power). If @ignore_lat is
|
|
|
|
* IGNORE_WAKEUP_LAT, make the omap_device fully inactive. Otherwise,
|
|
|
|
* if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup
|
|
|
|
* latency is less than the requested maximum wakeup latency, step
|
|
|
|
* forwards in the omap_device_pm_latency table to ensure the device's
|
|
|
|
* maximum wakeup latency is less than or equal to the requested
|
|
|
|
* maximum wakeup latency. Returns 0.
|
|
|
|
*/
|
|
|
|
static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat)
|
|
|
|
{
|
2009-10-19 22:25:24 +00:00
|
|
|
struct timespec a, b, c;
|
2009-09-03 17:14:05 +00:00
|
|
|
|
2011-07-21 20:58:51 +00:00
|
|
|
dev_dbg(&od->pdev->dev, "omap_device: deactivating\n");
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
while (od->pm_lat_level < od->pm_lats_cnt) {
|
|
|
|
struct omap_device_pm_latency *odpl;
|
2009-10-19 22:25:24 +00:00
|
|
|
unsigned long long deact_lat = 0;
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
odpl = od->pm_lats + od->pm_lat_level;
|
|
|
|
|
|
|
|
if (!ignore_lat &&
|
|
|
|
((od->dev_wakeup_lat + odpl->activate_lat) >
|
|
|
|
od->_dev_wakeup_lat_limit))
|
|
|
|
break;
|
|
|
|
|
2009-12-08 23:34:23 +00:00
|
|
|
read_persistent_clock(&a);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
/* XXX check return code */
|
|
|
|
odpl->deactivate_func(od);
|
|
|
|
|
2009-12-08 23:34:23 +00:00
|
|
|
read_persistent_clock(&b);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
2009-10-19 22:25:24 +00:00
|
|
|
c = timespec_sub(b, a);
|
2009-12-08 23:34:26 +00:00
|
|
|
deact_lat = timespec_to_ns(&c);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
2011-07-21 20:58:51 +00:00
|
|
|
dev_dbg(&od->pdev->dev,
|
2011-07-21 16:58:36 +00:00
|
|
|
"omap_device: pm_lat %d: deactivate: elapsed time "
|
|
|
|
"%llu nsec\n", od->pm_lat_level, deact_lat);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
2010-01-27 03:13:02 +00:00
|
|
|
if (deact_lat > odpl->deactivate_lat) {
|
|
|
|
odpl->deactivate_lat_worst = deact_lat;
|
|
|
|
if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
|
|
|
|
odpl->deactivate_lat = deact_lat;
|
2011-07-21 20:58:51 +00:00
|
|
|
dev_dbg(&od->pdev->dev,
|
2011-07-25 13:18:24 +00:00
|
|
|
"new worst case deactivate latency "
|
|
|
|
"%d: %llu\n",
|
|
|
|
od->pm_lat_level, deact_lat);
|
2010-01-27 03:13:02 +00:00
|
|
|
} else
|
2011-07-21 20:58:51 +00:00
|
|
|
dev_warn(&od->pdev->dev,
|
2011-07-21 16:58:36 +00:00
|
|
|
"deactivate latency %d "
|
|
|
|
"higher than exptected. (%llu > %d)\n",
|
|
|
|
od->pm_lat_level, deact_lat,
|
|
|
|
odpl->deactivate_lat);
|
2010-01-27 03:13:02 +00:00
|
|
|
}
|
|
|
|
|
2009-09-03 17:14:05 +00:00
|
|
|
od->dev_wakeup_lat += odpl->activate_lat;
|
|
|
|
|
|
|
|
od->pm_lat_level++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-10 11:54:12 +00: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-21 20:58:51 +00:00
|
|
|
dev_dbg(&od->pdev->dev, "Creating %s -> %s\n", clk_alias, clk_name);
|
2011-07-10 11:54:12 +00:00
|
|
|
|
2011-07-21 20:58:51 +00:00
|
|
|
r = clk_get_sys(dev_name(&od->pdev->dev), clk_alias);
|
2011-07-10 11:54:12 +00:00
|
|
|
if (!IS_ERR(r)) {
|
2011-07-21 20:58:51 +00:00
|
|
|
dev_warn(&od->pdev->dev,
|
2011-07-21 16:58:36 +00:00
|
|
|
"alias %s already exists\n", clk_alias);
|
2011-07-10 11:54:12 +00:00
|
|
|
clk_put(r);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = omap_clk_get_by_name(clk_name);
|
|
|
|
if (IS_ERR(r)) {
|
2011-07-21 20:58:51 +00:00
|
|
|
dev_err(&od->pdev->dev,
|
2011-07-21 16:58:36 +00:00
|
|
|
"omap_clk_get_by_name for %s failed\n", clk_name);
|
2011-07-10 11:54:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-21 20:58:51 +00:00
|
|
|
l = clkdev_alloc(r, clk_alias, dev_name(&od->pdev->dev));
|
2011-07-10 11:54:12 +00:00
|
|
|
if (!l) {
|
2011-07-21 20:58:51 +00:00
|
|
|
dev_err(&od->pdev->dev,
|
2011-07-21 16:58:36 +00:00
|
|
|
"clkdev_alloc for %s failed\n", clk_alias);
|
2011-07-10 11:54:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
clkdev_add(l);
|
|
|
|
}
|
|
|
|
|
2010-09-21 17:23:04 +00:00
|
|
|
/**
|
2011-07-10 11:54:12 +00:00
|
|
|
* _add_hwmod_clocks_clkdev - Add clkdev entry for hwmod optional clocks
|
|
|
|
* and main clock
|
2010-09-21 17:23:04 +00:00
|
|
|
* @od: struct omap_device *od
|
2011-07-10 11:54:12 +00:00
|
|
|
* @oh: struct omap_hwmod *oh
|
2010-09-21 17:23:04 +00:00
|
|
|
*
|
2011-07-10 11:54:12 +00: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 17:23:04 +00: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 11:54:12 +00:00
|
|
|
* In the case of the main clock, a "fck" alias is used.
|
2010-09-21 17:23:04 +00:00
|
|
|
*
|
|
|
|
* No return value.
|
|
|
|
*/
|
2011-07-10 11:54:12 +00:00
|
|
|
static void _add_hwmod_clocks_clkdev(struct omap_device *od,
|
|
|
|
struct omap_hwmod *oh)
|
2010-09-21 17:23:04 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2011-07-10 11:54:12 +00:00
|
|
|
_add_clkdev(od, "fck", oh->main_clk);
|
2011-02-25 22:40:21 +00:00
|
|
|
|
2011-07-10 11:54:12 +00: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 17:23:04 +00:00
|
|
|
}
|
|
|
|
|
2009-09-03 17:14:05 +00:00
|
|
|
|
2011-08-10 11:32:08 +00:00
|
|
|
static struct dev_pm_domain omap_device_pm_domain;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* @pm_lats: pointer to a omap_device_pm_latency array for this device
|
|
|
|
* @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
|
|
|
|
* @is_early_device: should the device be registered as an early device or not
|
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
oh_cnt = of_property_count_strings(node, "ti,hwmods");
|
|
|
|
if (!oh_cnt || IS_ERR_VALUE(oh_cnt)) {
|
|
|
|
dev_warn(&pdev->dev, "No 'hwmods' to build omap_device\n");
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
od = omap_device_alloc(pdev, hwmods, oh_cnt, NULL, 0);
|
|
|
|
if (!od) {
|
|
|
|
dev_err(&pdev->dev, "Cannot allocate omap_device for :%s\n",
|
|
|
|
oh_name);
|
|
|
|
ret = PTR_ERR(od);
|
|
|
|
goto odbfd_exit1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (of_get_property(node, "ti,no_idle_on_suspend", NULL))
|
|
|
|
omap_device_disable_idle_on_suspend(pdev);
|
|
|
|
|
|
|
|
pdev->dev.pm_domain = &omap_device_pm_domain;
|
|
|
|
|
|
|
|
odbfd_exit1:
|
|
|
|
kfree(hwmods);
|
|
|
|
odbfd_exit:
|
|
|
|
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);
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case BUS_NOTIFY_ADD_DEVICE:
|
|
|
|
if (pdev->dev.of_node)
|
|
|
|
omap_device_build_from_dt(pdev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUS_NOTIFY_DEL_DEVICE:
|
|
|
|
if (pdev->archdata.od)
|
|
|
|
omap_device_delete(pdev->archdata.od);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-03 17:14:05 +00:00
|
|
|
/* Public functions for use by core code */
|
|
|
|
|
2010-12-22 04:31:55 +00: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 13:56:23 +00:00
|
|
|
int omap_device_get_context_loss_count(struct platform_device *pdev)
|
2010-12-22 04:31:55 +00:00
|
|
|
{
|
|
|
|
struct omap_device *od;
|
|
|
|
u32 ret = 0;
|
|
|
|
|
2011-07-10 01:15:20 +00:00
|
|
|
od = to_omap_device(pdev);
|
2010-12-22 04:31:55 +00:00
|
|
|
|
|
|
|
if (od->hwmods_cnt)
|
|
|
|
ret = omap_hwmod_get_context_loss_count(od->hwmods[0]);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-09-03 17:14:05 +00:00
|
|
|
/**
|
|
|
|
* omap_device_count_resources - count number of struct resource entries needed
|
|
|
|
* @od: struct omap_device *
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-07-21 21:14:35 +00:00
|
|
|
static int omap_device_count_resources(struct omap_device *od)
|
2009-09-03 17:14:05 +00:00
|
|
|
{
|
|
|
|
int c = 0;
|
|
|
|
int i;
|
|
|
|
|
2010-09-24 16:23:18 +00:00
|
|
|
for (i = 0; i < od->hwmods_cnt; i++)
|
|
|
|
c += omap_hwmod_count_resources(od->hwmods[i]);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
pr_debug("omap_device: %s: counted %d total resources across %d "
|
2011-07-21 20:58:51 +00:00
|
|
|
"hwmods\n", od->pdev->name, c, od->hwmods_cnt);
|
2009-09-03 17:14:05 +00: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-21 21:14:35 +00:00
|
|
|
static int omap_device_fill_resources(struct omap_device *od,
|
|
|
|
struct resource *res)
|
2009-09-03 17:14:05 +00:00
|
|
|
{
|
|
|
|
int c = 0;
|
|
|
|
int i, r;
|
|
|
|
|
2010-09-24 16:23:18 +00:00
|
|
|
for (i = 0; i < od->hwmods_cnt; i++) {
|
|
|
|
r = omap_hwmod_fill_resources(od->hwmods[i], res);
|
2009-09-03 17:14:05 +00:00
|
|
|
res += r;
|
|
|
|
c += r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-09 14:47:01 +00: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
|
|
|
|
* @pm_lats: pointer to a omap_device_pm_latency array for this device
|
|
|
|
* @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
|
|
|
|
*
|
|
|
|
* Convenience function for allocating an omap_device structure and filling
|
|
|
|
* hwmods, resources and pm_latency attributes.
|
|
|
|
*
|
|
|
|
* Returns an struct omap_device pointer or ERR_PTR() on error;
|
|
|
|
*/
|
|
|
|
static struct omap_device *omap_device_alloc(struct platform_device *pdev,
|
|
|
|
struct omap_hwmod **ohs, int oh_cnt,
|
|
|
|
struct omap_device_pm_latency *pm_lats,
|
|
|
|
int pm_lats_cnt)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HACK: Ideally the resources from DT should match, and hwmod
|
|
|
|
* should just add the missing ones. Since the name is not
|
|
|
|
* properly populated by DT, stick to hwmod resources only.
|
|
|
|
*/
|
|
|
|
if (pdev->num_resources && pdev->resource)
|
|
|
|
dev_warn(&pdev->dev, "%s(): resources already allocated %d\n",
|
|
|
|
__func__, pdev->num_resources);
|
|
|
|
|
|
|
|
res_count = omap_device_count_resources(od);
|
|
|
|
if (res_count > 0) {
|
|
|
|
dev_dbg(&pdev->dev, "%s(): resources allocated from hwmod %d\n",
|
|
|
|
__func__, res_count);
|
|
|
|
res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
|
|
|
|
if (!res)
|
|
|
|
goto oda_exit3;
|
|
|
|
|
|
|
|
omap_device_fill_resources(od, res);
|
|
|
|
|
|
|
|
ret = platform_device_add_resources(pdev, res, res_count);
|
|
|
|
kfree(res);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
goto oda_exit3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pm_lats) {
|
|
|
|
pm_lats = omap_default_latency;
|
|
|
|
pm_lats_cnt = ARRAY_SIZE(omap_default_latency);
|
|
|
|
}
|
|
|
|
|
|
|
|
od->pm_lats_cnt = pm_lats_cnt;
|
|
|
|
od->pm_lats = kmemdup(pm_lats,
|
|
|
|
sizeof(struct omap_device_pm_latency) * pm_lats_cnt,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!od->pm_lats)
|
|
|
|
goto oda_exit3;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void omap_device_delete(struct omap_device *od)
|
|
|
|
{
|
2011-08-10 11:32:08 +00:00
|
|
|
if (!od)
|
|
|
|
return;
|
|
|
|
|
2011-08-09 14:47:01 +00:00
|
|
|
od->pdev->archdata.od = NULL;
|
|
|
|
kfree(od->pm_lats);
|
|
|
|
kfree(od->hwmods);
|
|
|
|
kfree(od);
|
|
|
|
}
|
|
|
|
|
2009-09-03 17:14:05 +00: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
|
|
|
|
* @pm_lats: pointer to a omap_device_pm_latency array for this device
|
|
|
|
* @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
|
2010-02-24 19:05:58 +00:00
|
|
|
* @is_early_device: should the device be registered as an early device or not
|
2009-09-03 17:14:05 +00:00
|
|
|
*
|
|
|
|
* 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().
|
|
|
|
*/
|
2011-07-21 20:48:45 +00:00
|
|
|
struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
|
2009-09-03 17:14:05 +00:00
|
|
|
struct omap_hwmod *oh, void *pdata,
|
|
|
|
int pdata_len,
|
|
|
|
struct omap_device_pm_latency *pm_lats,
|
2010-02-24 19:05:58 +00:00
|
|
|
int pm_lats_cnt, int is_early_device)
|
2009-09-03 17:14:05 +00:00
|
|
|
{
|
|
|
|
struct omap_hwmod *ohs[] = { oh };
|
|
|
|
|
|
|
|
if (!oh)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata,
|
2010-02-24 19:05:58 +00:00
|
|
|
pdata_len, pm_lats, pm_lats_cnt,
|
|
|
|
is_early_device);
|
2009-09-03 17:14:05 +00: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
|
|
|
|
* @pm_lats: pointer to a omap_device_pm_latency array for this device
|
|
|
|
* @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
|
2010-02-24 19:05:58 +00:00
|
|
|
* @is_early_device: should the device be registered as an early device or not
|
2009-09-03 17:14:05 +00:00
|
|
|
*
|
|
|
|
* 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().
|
|
|
|
*/
|
2011-07-21 20:48:45 +00:00
|
|
|
struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
|
2009-09-03 17:14:05 +00:00
|
|
|
struct omap_hwmod **ohs, int oh_cnt,
|
|
|
|
void *pdata, int pdata_len,
|
|
|
|
struct omap_device_pm_latency *pm_lats,
|
2010-02-24 19:05:58 +00:00
|
|
|
int pm_lats_cnt, int is_early_device)
|
2009-09-03 17:14:05 +00:00
|
|
|
{
|
|
|
|
int ret = -ENOMEM;
|
2011-07-21 20:58:51 +00:00
|
|
|
struct platform_device *pdev;
|
2009-09-03 17:14:05 +00: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-21 20:58:51 +00:00
|
|
|
pdev = platform_device_alloc(pdev_name, pdev_id);
|
|
|
|
if (!pdev) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto odbs_exit;
|
|
|
|
}
|
|
|
|
|
2011-08-09 14:47:01 +00: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-03 17:14:05 +00:00
|
|
|
|
2011-08-09 14:47:01 +00:00
|
|
|
od = omap_device_alloc(pdev, ohs, oh_cnt, pm_lats, pm_lats_cnt);
|
|
|
|
if (!od)
|
2011-07-21 20:58:51 +00:00
|
|
|
goto odbs_exit1;
|
|
|
|
|
|
|
|
ret = platform_device_add_data(pdev, pdata, pdata_len);
|
2010-07-12 13:38:07 +00:00
|
|
|
if (ret)
|
2011-08-09 14:47:01 +00:00
|
|
|
goto odbs_exit2;
|
2009-09-03 17:14:05 +00:00
|
|
|
|
2010-02-24 19:05:58 +00:00
|
|
|
if (is_early_device)
|
2011-07-21 20:58:51 +00:00
|
|
|
ret = omap_early_device_register(pdev);
|
2010-02-24 19:05:58 +00:00
|
|
|
else
|
2011-07-21 20:58:51 +00:00
|
|
|
ret = omap_device_register(pdev);
|
|
|
|
if (ret)
|
2011-08-09 14:47:01 +00:00
|
|
|
goto odbs_exit2;
|
2010-07-26 22:34:30 +00:00
|
|
|
|
2011-07-21 20:58:51 +00:00
|
|
|
return pdev;
|
2009-09-03 17:14:05 +00:00
|
|
|
|
2011-07-21 20:58:51 +00:00
|
|
|
odbs_exit2:
|
2011-08-09 14:47:01 +00:00
|
|
|
omap_device_delete(od);
|
2011-07-21 20:58:51 +00:00
|
|
|
odbs_exit1:
|
|
|
|
platform_device_put(pdev);
|
|
|
|
odbs_exit:
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret);
|
|
|
|
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
2010-02-24 19:05:58 +00:00
|
|
|
/**
|
|
|
|
* omap_early_device_register - register an omap_device as an early platform
|
|
|
|
* device.
|
|
|
|
* @od: struct omap_device * to register
|
|
|
|
*
|
|
|
|
* Register the omap_device structure. This currently just calls
|
|
|
|
* platform_early_add_device() on the underlying platform_device.
|
|
|
|
* Returns 0 by default.
|
|
|
|
*/
|
2011-07-21 21:47:53 +00:00
|
|
|
static int omap_early_device_register(struct platform_device *pdev)
|
2010-02-24 19:05:58 +00:00
|
|
|
{
|
|
|
|
struct platform_device *devices[1];
|
|
|
|
|
2011-07-21 21:47:53 +00:00
|
|
|
devices[0] = pdev;
|
2010-02-24 19:05:58 +00:00
|
|
|
early_platform_add_devices(devices, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-12 20:48:03 +00:00
|
|
|
#ifdef CONFIG_PM_RUNTIME
|
2011-04-28 22:36:42 +00:00
|
|
|
static int _od_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
2011-05-31 23:08:09 +00:00
|
|
|
int ret;
|
2011-04-28 22:36:42 +00:00
|
|
|
|
2011-05-31 23:08:09 +00:00
|
|
|
ret = pm_generic_runtime_suspend(dev);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
omap_device_idle(pdev);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _od_runtime_idle(struct device *dev)
|
|
|
|
{
|
|
|
|
return pm_generic_runtime_idle(dev);
|
2011-04-28 22:36:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int _od_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
|
2011-05-31 23:08:09 +00:00
|
|
|
omap_device_enable(pdev);
|
|
|
|
|
|
|
|
return pm_generic_runtime_resume(dev);
|
2011-04-28 22:36:42 +00:00
|
|
|
}
|
2011-07-12 20:48:03 +00:00
|
|
|
#endif
|
2011-04-28 22:36:42 +00:00
|
|
|
|
2011-07-12 20:48:19 +00: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;
|
|
|
|
|
2011-07-12 20:48:29 +00:00
|
|
|
if (od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND)
|
|
|
|
return pm_generic_suspend_noirq(dev);
|
|
|
|
|
2011-07-12 20:48:19 +00:00
|
|
|
ret = pm_generic_suspend_noirq(dev);
|
|
|
|
|
|
|
|
if (!ret && !pm_runtime_status_suspended(dev)) {
|
|
|
|
if (pm_generic_runtime_suspend(dev) == 0) {
|
|
|
|
omap_device_idle(pdev);
|
|
|
|
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);
|
|
|
|
|
2011-07-12 20:48:29 +00:00
|
|
|
if (od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND)
|
|
|
|
return pm_generic_resume_noirq(dev);
|
|
|
|
|
2011-07-12 20:48:19 +00:00
|
|
|
if ((od->flags & OMAP_DEVICE_SUSPENDED) &&
|
|
|
|
!pm_runtime_status_suspended(dev)) {
|
|
|
|
od->flags &= ~OMAP_DEVICE_SUSPENDED;
|
|
|
|
omap_device_enable(pdev);
|
|
|
|
pm_generic_runtime_resume(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pm_generic_resume_noirq(dev);
|
|
|
|
}
|
2011-09-01 17:59:36 +00:00
|
|
|
#else
|
|
|
|
#define _od_suspend_noirq NULL
|
|
|
|
#define _od_resume_noirq NULL
|
2011-07-12 20:48:19 +00:00
|
|
|
#endif
|
|
|
|
|
2011-06-22 23:52:55 +00:00
|
|
|
static struct dev_pm_domain omap_device_pm_domain = {
|
2011-04-28 22:36:42 +00:00
|
|
|
.ops = {
|
2011-07-12 20:48:03 +00:00
|
|
|
SET_RUNTIME_PM_OPS(_od_runtime_suspend, _od_runtime_resume,
|
|
|
|
_od_runtime_idle)
|
2011-04-28 22:36:42 +00:00
|
|
|
USE_PLATFORM_PM_SLEEP_OPS
|
2011-08-25 13:31:14 +00:00
|
|
|
.suspend_noirq = _od_suspend_noirq,
|
|
|
|
.resume_noirq = _od_resume_noirq,
|
2011-04-28 22:36:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-09-03 17:14:05 +00: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().
|
|
|
|
*/
|
2011-07-21 21:47:53 +00:00
|
|
|
static int omap_device_register(struct platform_device *pdev)
|
2009-09-03 17:14:05 +00:00
|
|
|
{
|
2011-07-21 21:47:53 +00:00
|
|
|
pr_debug("omap_device: %s: registering\n", pdev->name);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
2011-07-21 21:47:53 +00:00
|
|
|
pdev->dev.parent = &omap_device_parent;
|
|
|
|
pdev->dev.pm_domain = &omap_device_pm_domain;
|
2011-07-21 20:58:51 +00:00
|
|
|
return platform_device_add(pdev);
|
2009-09-03 17:14:05 +00: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
|
|
|
|
* (through platform_data function pointers) where they would normally
|
|
|
|
* enable clocks, etc. Returns -EINVAL if called when the omap_device
|
|
|
|
* is already enabled, or passes along the return value of
|
|
|
|
* _omap_device_activate().
|
|
|
|
*/
|
|
|
|
int omap_device_enable(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct omap_device *od;
|
|
|
|
|
2011-07-10 01:15:20 +00:00
|
|
|
od = to_omap_device(pdev);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
|
2011-07-21 16:58:36 +00:00
|
|
|
dev_warn(&pdev->dev,
|
|
|
|
"omap_device: %s() called from invalid state %d\n",
|
|
|
|
__func__, od->_state);
|
2009-09-03 17:14:05 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable everything if we're enabling this device from scratch */
|
|
|
|
if (od->_state == OMAP_DEVICE_STATE_UNKNOWN)
|
|
|
|
od->pm_lat_level = od->pm_lats_cnt;
|
|
|
|
|
|
|
|
ret = _omap_device_activate(od, IGNORE_WAKEUP_LAT);
|
|
|
|
|
|
|
|
od->dev_wakeup_lat = 0;
|
2009-12-08 23:34:22 +00:00
|
|
|
od->_dev_wakeup_lat_limit = UINT_MAX;
|
2009-09-03 17:14:05 +00:00
|
|
|
od->_state = OMAP_DEVICE_STATE_ENABLED;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_device_idle - idle an omap_device
|
|
|
|
* @od: struct omap_device * to idle
|
|
|
|
*
|
|
|
|
* Idle omap_device @od by calling as many .deactivate_func() entries
|
|
|
|
* in the omap_device's pm_lats table as is possible without exceeding
|
|
|
|
* the device's maximum wakeup latency limit, pm_lat_limit. Device
|
|
|
|
* drivers should call this function (through platform_data function
|
|
|
|
* pointers) where they would normally disable clocks after operations
|
|
|
|
* complete, etc.. Returns -EINVAL if the omap_device is not
|
|
|
|
* currently enabled, or passes along the return value of
|
|
|
|
* _omap_device_deactivate().
|
|
|
|
*/
|
|
|
|
int omap_device_idle(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct omap_device *od;
|
|
|
|
|
2011-07-10 01:15:20 +00:00
|
|
|
od = to_omap_device(pdev);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
if (od->_state != OMAP_DEVICE_STATE_ENABLED) {
|
2011-07-21 16:58:36 +00:00
|
|
|
dev_warn(&pdev->dev,
|
|
|
|
"omap_device: %s() called from invalid state %d\n",
|
|
|
|
__func__, od->_state);
|
2009-09-03 17:14:05 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
|
|
|
|
|
|
|
|
od->_state = OMAP_DEVICE_STATE_IDLE;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_device_shutdown - shut down an omap_device
|
|
|
|
* @od: struct omap_device * to shut down
|
|
|
|
*
|
|
|
|
* Shut down omap_device @od by calling all .deactivate_func() entries
|
|
|
|
* in the omap_device's pm_lats table and then shutting down all of
|
|
|
|
* the underlying omap_hwmods. Used when a device is being "removed"
|
|
|
|
* or a device driver is being unloaded. Returns -EINVAL if the
|
|
|
|
* omap_device is not currently enabled or idle, or passes along the
|
|
|
|
* return value of _omap_device_deactivate().
|
|
|
|
*/
|
|
|
|
int omap_device_shutdown(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
int ret, i;
|
|
|
|
struct omap_device *od;
|
|
|
|
|
2011-07-10 01:15:20 +00:00
|
|
|
od = to_omap_device(pdev);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
if (od->_state != OMAP_DEVICE_STATE_ENABLED &&
|
|
|
|
od->_state != OMAP_DEVICE_STATE_IDLE) {
|
2011-07-21 16:58:36 +00:00
|
|
|
dev_warn(&pdev->dev,
|
|
|
|
"omap_device: %s() called from invalid state %d\n",
|
|
|
|
__func__, od->_state);
|
2009-09-03 17:14:05 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = _omap_device_deactivate(od, IGNORE_WAKEUP_LAT);
|
|
|
|
|
2010-09-24 16:23:18 +00:00
|
|
|
for (i = 0; i < od->hwmods_cnt; i++)
|
|
|
|
omap_hwmod_shutdown(od->hwmods[i]);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
od->_state = OMAP_DEVICE_STATE_SHUTDOWN;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_device_align_pm_lat - activate/deactivate device to match wakeup lat lim
|
|
|
|
* @od: struct omap_device *
|
|
|
|
*
|
|
|
|
* When a device's maximum wakeup latency limit changes, call some of
|
|
|
|
* the .activate_func or .deactivate_func function pointers in the
|
|
|
|
* omap_device's pm_lats array to ensure that the device's maximum
|
|
|
|
* wakeup latency is less than or equal to the new latency limit.
|
|
|
|
* Intended to be called by OMAP PM code whenever a device's maximum
|
|
|
|
* wakeup latency limit changes (e.g., via
|
|
|
|
* omap_pm_set_dev_wakeup_lat()). Returns 0 if nothing needs to be
|
|
|
|
* done (e.g., if the omap_device is not currently idle, or if the
|
|
|
|
* wakeup latency is already current with the new limit) or passes
|
|
|
|
* along the return value of _omap_device_deactivate() or
|
|
|
|
* _omap_device_activate().
|
|
|
|
*/
|
|
|
|
int omap_device_align_pm_lat(struct platform_device *pdev,
|
|
|
|
u32 new_wakeup_lat_limit)
|
|
|
|
{
|
|
|
|
int ret = -EINVAL;
|
|
|
|
struct omap_device *od;
|
|
|
|
|
2011-07-10 01:15:20 +00:00
|
|
|
od = to_omap_device(pdev);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
if (new_wakeup_lat_limit == od->dev_wakeup_lat)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
od->_dev_wakeup_lat_limit = new_wakeup_lat_limit;
|
|
|
|
|
|
|
|
if (od->_state != OMAP_DEVICE_STATE_IDLE)
|
|
|
|
return 0;
|
|
|
|
else if (new_wakeup_lat_limit > od->dev_wakeup_lat)
|
|
|
|
ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
|
|
|
|
else if (new_wakeup_lat_limit < od->dev_wakeup_lat)
|
|
|
|
ret = _omap_device_activate(od, USE_WAKEUP_LAT);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_device_get_pwrdm - return the powerdomain * associated with @od
|
|
|
|
* @od: struct omap_device *
|
|
|
|
*
|
|
|
|
* Return the powerdomain associated with the first underlying
|
|
|
|
* omap_hwmod for this omap_device. Intended for use by core OMAP PM
|
|
|
|
* code. Returns NULL on error or a struct powerdomain * upon
|
|
|
|
* success.
|
|
|
|
*/
|
|
|
|
struct powerdomain *omap_device_get_pwrdm(struct omap_device *od)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* XXX Assumes that all omap_hwmod powerdomains are identical.
|
|
|
|
* This may not necessarily be true. There should be a sanity
|
|
|
|
* check in here to WARN() if any difference appears.
|
|
|
|
*/
|
|
|
|
if (!od->hwmods_cnt)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return omap_hwmod_get_pwrdm(od->hwmods[0]);
|
|
|
|
}
|
|
|
|
|
2010-07-26 22:34:33 +00:00
|
|
|
/**
|
|
|
|
* omap_device_get_mpu_rt_va - return the MPU's virtual addr for the hwmod base
|
|
|
|
* @od: struct omap_device *
|
|
|
|
*
|
|
|
|
* Return the MPU's virtual address for the base of the hwmod, from
|
|
|
|
* the ioremap() that the hwmod code does. Only valid if there is one
|
|
|
|
* hwmod associated with this device. Returns NULL if there are zero
|
|
|
|
* or more than one hwmods associated with this omap_device;
|
|
|
|
* otherwise, passes along the return value from
|
|
|
|
* omap_hwmod_get_mpu_rt_va().
|
|
|
|
*/
|
|
|
|
void __iomem *omap_device_get_rt_va(struct omap_device *od)
|
|
|
|
{
|
|
|
|
if (od->hwmods_cnt != 1)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return omap_hwmod_get_mpu_rt_va(od->hwmods[0]);
|
|
|
|
}
|
|
|
|
|
2011-07-27 20:02:32 +00: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);
|
|
|
|
if (IS_ERR_OR_NULL(oh)) {
|
|
|
|
WARN(1, "%s: no hwmod for %s\n", __func__,
|
|
|
|
oh_name);
|
|
|
|
return ERR_PTR(oh ? PTR_ERR(oh) : -ENODEV);
|
|
|
|
}
|
|
|
|
if (IS_ERR_OR_NULL(oh->od)) {
|
|
|
|
WARN(1, "%s: no omap_device for %s\n", __func__,
|
|
|
|
oh_name);
|
|
|
|
return ERR_PTR(oh->od ? PTR_ERR(oh->od) : -ENODEV);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ERR_OR_NULL(oh->od->pdev))
|
|
|
|
return ERR_PTR(oh->od->pdev ? PTR_ERR(oh->od->pdev) : -ENODEV);
|
|
|
|
|
|
|
|
return &oh->od->pdev->dev;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(omap_device_get_by_hwmod_name);
|
|
|
|
|
2009-09-03 17:14:05 +00:00
|
|
|
/*
|
|
|
|
* Public functions intended for use in omap_device_pm_latency
|
|
|
|
* .activate_func and .deactivate_func function pointers
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_device_enable_hwmods - call omap_hwmod_enable() on all hwmods
|
|
|
|
* @od: struct omap_device *od
|
|
|
|
*
|
|
|
|
* Enable all underlying hwmods. Returns 0.
|
|
|
|
*/
|
|
|
|
int omap_device_enable_hwmods(struct omap_device *od)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-09-24 16:23:18 +00:00
|
|
|
for (i = 0; i < od->hwmods_cnt; i++)
|
|
|
|
omap_hwmod_enable(od->hwmods[i]);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
int omap_device_idle_hwmods(struct omap_device *od)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-09-24 16:23:18 +00:00
|
|
|
for (i = 0; i < od->hwmods_cnt; i++)
|
|
|
|
omap_hwmod_idle(od->hwmods[i]);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
/* XXX pass along return value here? */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_device_disable_clocks - disable all main and interface clocks
|
|
|
|
* @od: struct omap_device *od
|
|
|
|
*
|
|
|
|
* Disable the main functional clock and interface clock for all of the
|
|
|
|
* omap_hwmods associated with the omap_device. Returns 0.
|
|
|
|
*/
|
|
|
|
int omap_device_disable_clocks(struct omap_device *od)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-09-24 16:23:18 +00:00
|
|
|
for (i = 0; i < od->hwmods_cnt; i++)
|
|
|
|
omap_hwmod_disable_clocks(od->hwmods[i]);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
/* XXX pass along return value here? */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_device_enable_clocks - enable all main and interface clocks
|
|
|
|
* @od: struct omap_device *od
|
|
|
|
*
|
|
|
|
* Enable the main functional clock and interface clock for all of the
|
|
|
|
* omap_hwmods associated with the omap_device. Returns 0.
|
|
|
|
*/
|
|
|
|
int omap_device_enable_clocks(struct omap_device *od)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-09-24 16:23:18 +00:00
|
|
|
for (i = 0; i < od->hwmods_cnt; i++)
|
|
|
|
omap_hwmod_enable_clocks(od->hwmods[i]);
|
2009-09-03 17:14:05 +00:00
|
|
|
|
|
|
|
/* XXX pass along return value here? */
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-23 15:10:55 +00:00
|
|
|
|
|
|
|
struct device omap_device_parent = {
|
|
|
|
.init_name = "omap",
|
|
|
|
.parent = &platform_bus,
|
|
|
|
};
|
|
|
|
|
2011-08-10 11:32:08 +00:00
|
|
|
static struct notifier_block platform_nb = {
|
|
|
|
.notifier_call = _omap_device_notifier_call,
|
|
|
|
};
|
|
|
|
|
2010-08-23 15:10:55 +00:00
|
|
|
static int __init omap_device_init(void)
|
|
|
|
{
|
2011-08-10 11:32:08 +00:00
|
|
|
bus_register_notifier(&platform_bus_type, &platform_nb);
|
2010-08-23 15:10:55 +00:00
|
|
|
return device_register(&omap_device_parent);
|
|
|
|
}
|
|
|
|
core_initcall(omap_device_init);
|