80 #include <linux/kernel.h>
81 #include <linux/export.h>
83 #include <linux/slab.h>
94 #include <plat/clock.h>
97 #define USE_WAKEUP_LAT 0
98 #define IGNORE_WAKEUP_LAT 1
126 static int _omap_device_activate(
struct omap_device *od,
u8 ignore_lat)
130 dev_dbg(&od->
pdev->dev,
"omap_device: activating\n");
134 unsigned long long act_lat = 0;
151 c = timespec_sub(
b,
a);
152 act_lat = timespec_to_ns(&
c);
155 "omap_device: pm_lat %d: activate: elapsed time %llu nsec\n",
163 "new worst case activate latency %d: %llu\n",
167 "activate latency %d higher than expected. (%llu > %d)\n",
192 static int _omap_device_deactivate(
struct omap_device *od,
u8 ignore_lat)
196 dev_dbg(&od->
pdev->dev,
"omap_device: deactivating\n");
200 unsigned long long deact_lat = 0;
216 c = timespec_sub(
b,
a);
217 deact_lat = timespec_to_ns(&
c);
220 "omap_device: pm_lat %d: deactivate: elapsed time %llu nsec\n",
228 "new worst case deactivate latency %d: %llu\n",
232 "deactivate latency %d higher than expected. (%llu > %d)\n",
245 static void _add_clkdev(
struct omap_device *od,
const char *clk_alias,
246 const char *clk_name)
251 if (!clk_alias || !clk_name)
254 dev_dbg(&od->
pdev->dev,
"Creating %s -> %s\n", clk_alias, clk_name);
259 "alias %s already exists\n", clk_alias);
267 "clk_get for %s failed\n", clk_name);
274 "clkdev_alloc for %s failed\n", clk_alias);
300 static void _add_hwmod_clocks_clkdev(
struct omap_device *od,
305 _add_clkdev(od,
"fck", oh->
main_clk);
334 int oh_cnt,
i,
ret = 0;
338 dev_dbg(&pdev->
dev,
"No 'hwmods' to build omap_device\n");
348 for (i = 0; i < oh_cnt; i++) {
352 dev_err(&pdev->
dev,
"Cannot lookup hwmod '%s'\n",
362 dev_err(&pdev->
dev,
"Cannot allocate omap_device for :%s\n",
373 r->
name = dev_name(&pdev->
dev);
377 omap_device_disable_idle_on_suspend(pdev);
399 if (pdev->
dev.of_node)
400 omap_device_build_from_dt(pdev);
403 od = to_omap_device(pdev);
434 od = to_omap_device(pdev);
451 static int omap_device_count_resources(
struct omap_device *od)
459 pr_debug(
"omap_device: %s: counted %d total resources across %d hwmods\n",
482 static int omap_device_fill_resources(
struct omap_device *od,
509 static int _od_fill_dma_resources(
struct omap_device *od,
561 res_count = omap_device_count_resources(od);
589 dev_dbg(&pdev->
dev,
"%s(): resources already allocated %d\n",
590 __func__, res_count);
595 dev_dbg(&pdev->
dev,
"%s(): using resources from hwmod %d\n",
596 __func__, res_count);
597 omap_device_fill_resources(od, res);
608 pm_lats = omap_default_latency;
609 pm_lats_cnt =
ARRAY_SIZE(omap_default_latency);
621 for (i = 0; i < oh_cnt; i++) {
623 _add_hwmod_clocks_clkdev(od, hwmods[i]);
633 dev_err(&pdev->
dev,
"omap_device: build failed (%d)\n", ret);
670 int pm_lats_cnt,
int is_early_device)
678 pdata_len, pm_lats, pm_lats_cnt,
701 void *
pdata,
int pdata_len,
703 int pm_lats_cnt,
int is_early_device)
709 if (!ohs || oh_cnt == 0 || !pdev_name)
712 if (!pdata && pdata_len > 0)
736 ret = omap_early_device_register(pdev);
750 pr_err(
"omap_device: %s: build failed (%d)\n", pdev_name, ret);
773 #ifdef CONFIG_PM_RUNTIME
774 static int _od_runtime_suspend(
struct device *dev)
779 ret = pm_generic_runtime_suspend(dev);
787 static int _od_runtime_idle(
struct device *dev)
789 return pm_generic_runtime_idle(dev);
792 static int _od_runtime_resume(
struct device *dev)
798 return pm_generic_runtime_resume(dev);
802 #ifdef CONFIG_SUSPEND
813 ret = pm_generic_suspend_noirq(dev);
815 if (!ret && !pm_runtime_status_suspended(dev)) {
816 if (pm_generic_runtime_suspend(dev) == 0) {
832 !pm_runtime_status_suspended(dev)) {
836 pm_generic_runtime_resume(dev);
839 return pm_generic_resume_noirq(dev);
842 #define _od_suspend_noirq NULL
843 #define _od_resume_noirq NULL
893 od = to_omap_device(pdev);
897 "omap_device: %s() called from invalid state %d\n",
933 od = to_omap_device(pdev);
937 "omap_device: %s() called from invalid state %d\n",
965 od = to_omap_device(pdev);
970 "omap_device: %s() called from invalid state %d\n",
1057 u32 new_wakeup_lat_limit)
1062 od = to_omap_device(pdev);
1133 WARN(1,
"%s: no hwmod name!\n", __func__);
1138 if (IS_ERR_OR_NULL(oh)) {
1139 WARN(1,
"%s: no hwmod for %s\n", __func__,
1141 return ERR_PTR(oh ? PTR_ERR(oh) : -
ENODEV);
1143 if (IS_ERR_OR_NULL(oh->
od)) {
1144 WARN(1,
"%s: no omap_device for %s\n", __func__,
1146 return ERR_PTR(oh->
od ? PTR_ERR(oh->
od) : -
ENODEV);
1149 if (IS_ERR_OR_NULL(oh->
od->pdev))
1150 return ERR_PTR(oh->
od->pdev ? PTR_ERR(oh->
od->pdev) : -
ENODEV);
1152 return &oh->
od->pdev->dev;
1232 .notifier_call = _omap_device_notifier_call,
1235 static int __init omap_device_init(
void)
1264 dev_warn(dev,
"%s: enabled but no driver. Idling\n",
1273 static int __init omap_device_late_init(
void)