aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-omap2/omap_device.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-omap2/omap_device.c')
-rw-r--r--arch/arm/mach-omap2/omap_device.c537
1 files changed, 59 insertions, 478 deletions
diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
index e065daa537c0..6ee3ad3dd95a 100644
--- a/arch/arm/mach-omap2/omap_device.c
+++ b/arch/arm/mach-omap2/omap_device.c
@@ -17,68 +17,15 @@
17 * to control power management and interconnect properties of their 17 * to control power management and interconnect properties of their
18 * devices. 18 * devices.
19 * 19 *
20 * In the medium- to long-term, this code should either be 20 * In the medium- to long-term, this code should be implemented as a
21 * a) implemented via arch-specific pointers in platform_data 21 * proper omap_bus/omap_device in Linux, no more platform_data func
22 * or 22 * pointers
23 * b) implemented as a proper omap_bus/omap_device in Linux, no more
24 * platform_data func pointers
25 * 23 *
26 * 24 *
27 * Guidelines for usage by driver authors:
28 *
29 * 1. These functions are intended to be used by device drivers via
30 * function pointers in struct platform_data. As an example,
31 * omap_device_enable() should be passed to the driver as
32 *
33 * struct foo_driver_platform_data {
34 * ...
35 * int (*device_enable)(struct platform_device *pdev);
36 * ...
37 * }
38 *
39 * Note that the generic "device_enable" name is used, rather than
40 * "omap_device_enable". This is so other architectures can pass in their
41 * own enable/disable functions here.
42 *
43 * This should be populated during device setup:
44 *
45 * ...
46 * pdata->device_enable = omap_device_enable;
47 * ...
48 *
49 * 2. Drivers should first check to ensure the function pointer is not null
50 * before calling it, as in:
51 *
52 * if (pdata->device_enable)
53 * pdata->device_enable(pdev);
54 *
55 * This allows other architectures that don't use similar device_enable()/
56 * device_shutdown() functions to execute normally.
57 *
58 * ...
59 *
60 * Suggested usage by device drivers:
61 *
62 * During device initialization:
63 * device_enable()
64 *
65 * During device idle:
66 * (save remaining device context if necessary)
67 * device_idle();
68 *
69 * During device resume:
70 * device_enable();
71 * (restore context if necessary)
72 *
73 * During device shutdown:
74 * device_shutdown()
75 * (device must be reinitialized at this point to use it again)
76 *
77 */ 25 */
78#undef DEBUG 26#undef DEBUG
79 27
80#include <linux/kernel.h> 28#include <linux/kernel.h>
81#include <linux/export.h>
82#include <linux/platform_device.h> 29#include <linux/platform_device.h>
83#include <linux/slab.h> 30#include <linux/slab.h>
84#include <linux/err.h> 31#include <linux/err.h>
@@ -92,155 +39,8 @@
92#include "omap_device.h" 39#include "omap_device.h"
93#include "omap_hwmod.h" 40#include "omap_hwmod.h"
94 41
95/* These parameters are passed to _omap_device_{de,}activate() */
96#define USE_WAKEUP_LAT 0
97#define IGNORE_WAKEUP_LAT 1
98
99static int omap_early_device_register(struct platform_device *pdev);
100
101static struct omap_device_pm_latency omap_default_latency[] = {
102 {
103 .deactivate_func = omap_device_idle_hwmods,
104 .activate_func = omap_device_enable_hwmods,
105 .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
106 }
107};
108
109/* Private functions */ 42/* Private functions */
110 43
111/**
112 * _omap_device_activate - increase device readiness
113 * @od: struct omap_device *
114 * @ignore_lat: increase to latency target (0) or full readiness (1)?
115 *
116 * Increase readiness of omap_device @od (thus decreasing device
117 * wakeup latency, but consuming more power). If @ignore_lat is
118 * IGNORE_WAKEUP_LAT, make the omap_device fully active. Otherwise,
119 * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup
120 * latency is greater than the requested maximum wakeup latency, step
121 * backwards in the omap_device_pm_latency table to ensure the
122 * device's maximum wakeup latency is less than or equal to the
123 * requested maximum wakeup latency. Returns 0.
124 */
125static int _omap_device_activate(struct omap_device *od, u8 ignore_lat)
126{
127 struct timespec a, b, c;
128
129 dev_dbg(&od->pdev->dev, "omap_device: activating\n");
130
131 while (od->pm_lat_level > 0) {
132 struct omap_device_pm_latency *odpl;
133 unsigned long long act_lat = 0;
134
135 od->pm_lat_level--;
136
137 odpl = od->pm_lats + od->pm_lat_level;
138
139 if (!ignore_lat &&
140 (od->dev_wakeup_lat <= od->_dev_wakeup_lat_limit))
141 break;
142
143 read_persistent_clock(&a);
144
145 /* XXX check return code */
146 odpl->activate_func(od);
147
148 read_persistent_clock(&b);
149
150 c = timespec_sub(b, a);
151 act_lat = timespec_to_ns(&c);
152
153 dev_dbg(&od->pdev->dev,
154 "omap_device: pm_lat %d: activate: elapsed time %llu nsec\n",
155 od->pm_lat_level, act_lat);
156
157 if (act_lat > odpl->activate_lat) {
158 odpl->activate_lat_worst = act_lat;
159 if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
160 odpl->activate_lat = act_lat;
161 dev_dbg(&od->pdev->dev,
162 "new worst case activate latency %d: %llu\n",
163 od->pm_lat_level, act_lat);
164 } else
165 dev_warn(&od->pdev->dev,
166 "activate latency %d higher than expected. (%llu > %d)\n",
167 od->pm_lat_level, act_lat,
168 odpl->activate_lat);
169 }
170
171 od->dev_wakeup_lat -= odpl->activate_lat;
172 }
173
174 return 0;
175}
176
177/**
178 * _omap_device_deactivate - decrease device readiness
179 * @od: struct omap_device *
180 * @ignore_lat: decrease to latency target (0) or full inactivity (1)?
181 *
182 * Decrease readiness of omap_device @od (thus increasing device
183 * wakeup latency, but conserving power). If @ignore_lat is
184 * IGNORE_WAKEUP_LAT, make the omap_device fully inactive. Otherwise,
185 * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup
186 * latency is less than the requested maximum wakeup latency, step
187 * forwards in the omap_device_pm_latency table to ensure the device's
188 * maximum wakeup latency is less than or equal to the requested
189 * maximum wakeup latency. Returns 0.
190 */
191static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat)
192{
193 struct timespec a, b, c;
194
195 dev_dbg(&od->pdev->dev, "omap_device: deactivating\n");
196
197 while (od->pm_lat_level < od->pm_lats_cnt) {
198 struct omap_device_pm_latency *odpl;
199 unsigned long long deact_lat = 0;
200
201 odpl = od->pm_lats + od->pm_lat_level;
202
203 if (!ignore_lat &&
204 ((od->dev_wakeup_lat + odpl->activate_lat) >
205 od->_dev_wakeup_lat_limit))
206 break;
207
208 read_persistent_clock(&a);
209
210 /* XXX check return code */
211 odpl->deactivate_func(od);
212
213 read_persistent_clock(&b);
214
215 c = timespec_sub(b, a);
216 deact_lat = timespec_to_ns(&c);
217
218 dev_dbg(&od->pdev->dev,
219 "omap_device: pm_lat %d: deactivate: elapsed time %llu nsec\n",
220 od->pm_lat_level, deact_lat);
221
222 if (deact_lat > odpl->deactivate_lat) {
223 odpl->deactivate_lat_worst = deact_lat;
224 if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
225 odpl->deactivate_lat = deact_lat;
226 dev_dbg(&od->pdev->dev,
227 "new worst case deactivate latency %d: %llu\n",
228 od->pm_lat_level, deact_lat);
229 } else
230 dev_warn(&od->pdev->dev,
231 "deactivate latency %d higher than expected. (%llu > %d)\n",
232 od->pm_lat_level, deact_lat,
233 odpl->deactivate_lat);
234 }
235
236 od->dev_wakeup_lat += odpl->activate_lat;
237
238 od->pm_lat_level++;
239 }
240
241 return 0;
242}
243
244static void _add_clkdev(struct omap_device *od, const char *clk_alias, 44static void _add_clkdev(struct omap_device *od, const char *clk_alias,
245 const char *clk_name) 45 const char *clk_name)
246{ 46{
@@ -315,9 +115,6 @@ static void _add_hwmod_clocks_clkdev(struct omap_device *od,
315 * @oh: ptr to the single omap_hwmod that backs this omap_device 115 * @oh: ptr to the single omap_hwmod that backs this omap_device
316 * @pdata: platform_data ptr to associate with the platform_device 116 * @pdata: platform_data ptr to associate with the platform_device
317 * @pdata_len: amount of memory pointed to by @pdata 117 * @pdata_len: amount of memory pointed to by @pdata
318 * @pm_lats: pointer to a omap_device_pm_latency array for this device
319 * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
320 * @is_early_device: should the device be registered as an early device or not
321 * 118 *
322 * Function for building an omap_device already registered from device-tree 119 * Function for building an omap_device already registered from device-tree
323 * 120 *
@@ -356,7 +153,7 @@ static int omap_device_build_from_dt(struct platform_device *pdev)
356 hwmods[i] = oh; 153 hwmods[i] = oh;
357 } 154 }
358 155
359 od = omap_device_alloc(pdev, hwmods, oh_cnt, NULL, 0); 156 od = omap_device_alloc(pdev, hwmods, oh_cnt);
360 if (!od) { 157 if (!od) {
361 dev_err(&pdev->dev, "Cannot allocate omap_device for :%s\n", 158 dev_err(&pdev->dev, "Cannot allocate omap_device for :%s\n",
362 oh_name); 159 oh_name);
@@ -407,6 +204,39 @@ static int _omap_device_notifier_call(struct notifier_block *nb,
407 return NOTIFY_DONE; 204 return NOTIFY_DONE;
408} 205}
409 206
207/**
208 * _omap_device_enable_hwmods - call omap_hwmod_enable() on all hwmods
209 * @od: struct omap_device *od
210 *
211 * Enable all underlying hwmods. Returns 0.
212 */
213static int _omap_device_enable_hwmods(struct omap_device *od)
214{
215 int i;
216
217 for (i = 0; i < od->hwmods_cnt; i++)
218 omap_hwmod_enable(od->hwmods[i]);
219
220 /* XXX pass along return value here? */
221 return 0;
222}
223
224/**
225 * _omap_device_idle_hwmods - call omap_hwmod_idle() on all hwmods
226 * @od: struct omap_device *od
227 *
228 * Idle all underlying hwmods. Returns 0.
229 */
230static int _omap_device_idle_hwmods(struct omap_device *od)
231{
232 int i;
233
234 for (i = 0; i < od->hwmods_cnt; i++)
235 omap_hwmod_idle(od->hwmods[i]);
236
237 /* XXX pass along return value here? */
238 return 0;
239}
410 240
411/* Public functions for use by core code */ 241/* Public functions for use by core code */
412 242
@@ -526,18 +356,14 @@ static int _od_fill_dma_resources(struct omap_device *od,
526 * @oh: ptr to the single omap_hwmod that backs this omap_device 356 * @oh: ptr to the single omap_hwmod that backs this omap_device
527 * @pdata: platform_data ptr to associate with the platform_device 357 * @pdata: platform_data ptr to associate with the platform_device
528 * @pdata_len: amount of memory pointed to by @pdata 358 * @pdata_len: amount of memory pointed to by @pdata
529 * @pm_lats: pointer to a omap_device_pm_latency array for this device
530 * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
531 * 359 *
532 * Convenience function for allocating an omap_device structure and filling 360 * Convenience function for allocating an omap_device structure and filling
533 * hwmods, resources and pm_latency attributes. 361 * hwmods, and resources.
534 * 362 *
535 * Returns an struct omap_device pointer or ERR_PTR() on error; 363 * Returns an struct omap_device pointer or ERR_PTR() on error;
536 */ 364 */
537struct omap_device *omap_device_alloc(struct platform_device *pdev, 365struct omap_device *omap_device_alloc(struct platform_device *pdev,
538 struct omap_hwmod **ohs, int oh_cnt, 366 struct omap_hwmod **ohs, int oh_cnt)
539 struct omap_device_pm_latency *pm_lats,
540 int pm_lats_cnt)
541{ 367{
542 int ret = -ENOMEM; 368 int ret = -ENOMEM;
543 struct omap_device *od; 369 struct omap_device *od;
@@ -626,18 +452,6 @@ struct omap_device *omap_device_alloc(struct platform_device *pdev,
626 goto oda_exit3; 452 goto oda_exit3;
627 453
628have_everything: 454have_everything:
629 if (!pm_lats) {
630 pm_lats = omap_default_latency;
631 pm_lats_cnt = ARRAY_SIZE(omap_default_latency);
632 }
633
634 od->pm_lats_cnt = pm_lats_cnt;
635 od->pm_lats = kmemdup(pm_lats,
636 sizeof(struct omap_device_pm_latency) * pm_lats_cnt,
637 GFP_KERNEL);
638 if (!od->pm_lats)
639 goto oda_exit3;
640
641 pdev->archdata.od = od; 455 pdev->archdata.od = od;
642 456
643 for (i = 0; i < oh_cnt; i++) { 457 for (i = 0; i < oh_cnt; i++) {
@@ -663,7 +477,6 @@ void omap_device_delete(struct omap_device *od)
663 return; 477 return;
664 478
665 od->pdev->archdata.od = NULL; 479 od->pdev->archdata.od = NULL;
666 kfree(od->pm_lats);
667 kfree(od->hwmods); 480 kfree(od->hwmods);
668 kfree(od); 481 kfree(od);
669} 482}
@@ -675,9 +488,6 @@ void omap_device_delete(struct omap_device *od)
675 * @oh: ptr to the single omap_hwmod that backs this omap_device 488 * @oh: ptr to the single omap_hwmod that backs this omap_device
676 * @pdata: platform_data ptr to associate with the platform_device 489 * @pdata: platform_data ptr to associate with the platform_device
677 * @pdata_len: amount of memory pointed to by @pdata 490 * @pdata_len: amount of memory pointed to by @pdata
678 * @pm_lats: pointer to a omap_device_pm_latency array for this device
679 * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
680 * @is_early_device: should the device be registered as an early device or not
681 * 491 *
682 * Convenience function for building and registering a single 492 * Convenience function for building and registering a single
683 * omap_device record, which in turn builds and registers a 493 * omap_device record, which in turn builds and registers a
@@ -685,11 +495,10 @@ void omap_device_delete(struct omap_device *od)
685 * information. Returns ERR_PTR(-EINVAL) if @oh is NULL; otherwise, 495 * information. Returns ERR_PTR(-EINVAL) if @oh is NULL; otherwise,
686 * passes along the return value of omap_device_build_ss(). 496 * passes along the return value of omap_device_build_ss().
687 */ 497 */
688struct platform_device __init *omap_device_build(const char *pdev_name, int pdev_id, 498struct platform_device __init *omap_device_build(const char *pdev_name,
689 struct omap_hwmod *oh, void *pdata, 499 int pdev_id,
690 int pdata_len, 500 struct omap_hwmod *oh,
691 struct omap_device_pm_latency *pm_lats, 501 void *pdata, int pdata_len)
692 int pm_lats_cnt, int is_early_device)
693{ 502{
694 struct omap_hwmod *ohs[] = { oh }; 503 struct omap_hwmod *ohs[] = { oh };
695 504
@@ -697,8 +506,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name, int pdev
697 return ERR_PTR(-EINVAL); 506 return ERR_PTR(-EINVAL);
698 507
699 return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata, 508 return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata,
700 pdata_len, pm_lats, pm_lats_cnt, 509 pdata_len);
701 is_early_device);
702} 510}
703 511
704/** 512/**
@@ -708,9 +516,6 @@ struct platform_device __init *omap_device_build(const char *pdev_name, int pdev
708 * @oh: ptr to the single omap_hwmod that backs this omap_device 516 * @oh: ptr to the single omap_hwmod that backs this omap_device
709 * @pdata: platform_data ptr to associate with the platform_device 517 * @pdata: platform_data ptr to associate with the platform_device
710 * @pdata_len: amount of memory pointed to by @pdata 518 * @pdata_len: amount of memory pointed to by @pdata
711 * @pm_lats: pointer to a omap_device_pm_latency array for this device
712 * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
713 * @is_early_device: should the device be registered as an early device or not
714 * 519 *
715 * Convenience function for building and registering an omap_device 520 * Convenience function for building and registering an omap_device
716 * subsystem record. Subsystem records consist of multiple 521 * subsystem record. Subsystem records consist of multiple
@@ -718,11 +523,11 @@ struct platform_device __init *omap_device_build(const char *pdev_name, int pdev
718 * platform_device record. Returns an ERR_PTR() on error, or passes 523 * platform_device record. Returns an ERR_PTR() on error, or passes
719 * along the return value of omap_device_register(). 524 * along the return value of omap_device_register().
720 */ 525 */
721struct platform_device __init *omap_device_build_ss(const char *pdev_name, int pdev_id, 526struct platform_device __init *omap_device_build_ss(const char *pdev_name,
722 struct omap_hwmod **ohs, int oh_cnt, 527 int pdev_id,
723 void *pdata, int pdata_len, 528 struct omap_hwmod **ohs,
724 struct omap_device_pm_latency *pm_lats, 529 int oh_cnt, void *pdata,
725 int pm_lats_cnt, int is_early_device) 530 int pdata_len)
726{ 531{
727 int ret = -ENOMEM; 532 int ret = -ENOMEM;
728 struct platform_device *pdev; 533 struct platform_device *pdev;
@@ -746,7 +551,7 @@ struct platform_device __init *omap_device_build_ss(const char *pdev_name, int p
746 else 551 else
747 dev_set_name(&pdev->dev, "%s", pdev->name); 552 dev_set_name(&pdev->dev, "%s", pdev->name);
748 553
749 od = omap_device_alloc(pdev, ohs, oh_cnt, pm_lats, pm_lats_cnt); 554 od = omap_device_alloc(pdev, ohs, oh_cnt);
750 if (IS_ERR(od)) 555 if (IS_ERR(od))
751 goto odbs_exit1; 556 goto odbs_exit1;
752 557
@@ -754,10 +559,7 @@ struct platform_device __init *omap_device_build_ss(const char *pdev_name, int p
754 if (ret) 559 if (ret)
755 goto odbs_exit2; 560 goto odbs_exit2;
756 561
757 if (is_early_device) 562 ret = omap_device_register(pdev);
758 ret = omap_early_device_register(pdev);
759 else
760 ret = omap_device_register(pdev);
761 if (ret) 563 if (ret)
762 goto odbs_exit2; 564 goto odbs_exit2;
763 565
@@ -774,24 +576,6 @@ odbs_exit:
774 return ERR_PTR(ret); 576 return ERR_PTR(ret);
775} 577}
776 578
777/**
778 * omap_early_device_register - register an omap_device as an early platform
779 * device.
780 * @od: struct omap_device * to register
781 *
782 * Register the omap_device structure. This currently just calls
783 * platform_early_add_device() on the underlying platform_device.
784 * Returns 0 by default.
785 */
786static int __init omap_early_device_register(struct platform_device *pdev)
787{
788 struct platform_device *devices[1];
789
790 devices[0] = pdev;
791 early_platform_add_devices(devices, 1);
792 return 0;
793}
794
795#ifdef CONFIG_PM_RUNTIME 579#ifdef CONFIG_PM_RUNTIME
796static int _od_runtime_suspend(struct device *dev) 580static int _od_runtime_suspend(struct device *dev)
797{ 581{
@@ -902,10 +686,9 @@ int omap_device_register(struct platform_device *pdev)
902 * to be accessible and ready to operate. This generally involves 686 * to be accessible and ready to operate. This generally involves
903 * enabling clocks, setting SYSCONFIG registers; and in the future may 687 * enabling clocks, setting SYSCONFIG registers; and in the future may
904 * involve remuxing pins. Device drivers should call this function 688 * involve remuxing pins. Device drivers should call this function
905 * (through platform_data function pointers) where they would normally 689 * indirectly via pm_runtime_get*(). Returns -EINVAL if called when
906 * enable clocks, etc. Returns -EINVAL if called when the omap_device 690 * the omap_device is already enabled, or passes along the return
907 * is already enabled, or passes along the return value of 691 * value of _omap_device_enable_hwmods().
908 * _omap_device_activate().
909 */ 692 */
910int omap_device_enable(struct platform_device *pdev) 693int omap_device_enable(struct platform_device *pdev)
911{ 694{
@@ -921,14 +704,8 @@ int omap_device_enable(struct platform_device *pdev)
921 return -EINVAL; 704 return -EINVAL;
922 } 705 }
923 706
924 /* Enable everything if we're enabling this device from scratch */ 707 ret = _omap_device_enable_hwmods(od);
925 if (od->_state == OMAP_DEVICE_STATE_UNKNOWN)
926 od->pm_lat_level = od->pm_lats_cnt;
927
928 ret = _omap_device_activate(od, IGNORE_WAKEUP_LAT);
929 708
930 od->dev_wakeup_lat = 0;
931 od->_dev_wakeup_lat_limit = UINT_MAX;
932 od->_state = OMAP_DEVICE_STATE_ENABLED; 709 od->_state = OMAP_DEVICE_STATE_ENABLED;
933 710
934 return ret; 711 return ret;
@@ -938,14 +715,10 @@ int omap_device_enable(struct platform_device *pdev)
938 * omap_device_idle - idle an omap_device 715 * omap_device_idle - idle an omap_device
939 * @od: struct omap_device * to idle 716 * @od: struct omap_device * to idle
940 * 717 *
941 * Idle omap_device @od by calling as many .deactivate_func() entries 718 * Idle omap_device @od. Device drivers call this function indirectly
942 * in the omap_device's pm_lats table as is possible without exceeding 719 * via pm_runtime_put*(). Returns -EINVAL if the omap_device is not
943 * the device's maximum wakeup latency limit, pm_lat_limit. Device
944 * drivers should call this function (through platform_data function
945 * pointers) where they would normally disable clocks after operations
946 * complete, etc.. Returns -EINVAL if the omap_device is not
947 * currently enabled, or passes along the return value of 720 * currently enabled, or passes along the return value of
948 * _omap_device_deactivate(). 721 * _omap_device_idle_hwmods().
949 */ 722 */
950int omap_device_idle(struct platform_device *pdev) 723int omap_device_idle(struct platform_device *pdev)
951{ 724{
@@ -961,7 +734,7 @@ int omap_device_idle(struct platform_device *pdev)
961 return -EINVAL; 734 return -EINVAL;
962 } 735 }
963 736
964 ret = _omap_device_deactivate(od, USE_WAKEUP_LAT); 737 ret = _omap_device_idle_hwmods(od);
965 738
966 od->_state = OMAP_DEVICE_STATE_IDLE; 739 od->_state = OMAP_DEVICE_STATE_IDLE;
967 740
@@ -969,42 +742,6 @@ int omap_device_idle(struct platform_device *pdev)
969} 742}
970 743
971/** 744/**
972 * omap_device_shutdown - shut down an omap_device
973 * @od: struct omap_device * to shut down
974 *
975 * Shut down omap_device @od by calling all .deactivate_func() entries
976 * in the omap_device's pm_lats table and then shutting down all of
977 * the underlying omap_hwmods. Used when a device is being "removed"
978 * or a device driver is being unloaded. Returns -EINVAL if the
979 * omap_device is not currently enabled or idle, or passes along the
980 * return value of _omap_device_deactivate().
981 */
982int omap_device_shutdown(struct platform_device *pdev)
983{
984 int ret, i;
985 struct omap_device *od;
986
987 od = to_omap_device(pdev);
988
989 if (od->_state != OMAP_DEVICE_STATE_ENABLED &&
990 od->_state != OMAP_DEVICE_STATE_IDLE) {
991 dev_warn(&pdev->dev,
992 "omap_device: %s() called from invalid state %d\n",
993 __func__, od->_state);
994 return -EINVAL;
995 }
996
997 ret = _omap_device_deactivate(od, IGNORE_WAKEUP_LAT);
998
999 for (i = 0; i < od->hwmods_cnt; i++)
1000 omap_hwmod_shutdown(od->hwmods[i]);
1001
1002 od->_state = OMAP_DEVICE_STATE_SHUTDOWN;
1003
1004 return ret;
1005}
1006
1007/**
1008 * omap_device_assert_hardreset - set a device's hardreset line 745 * omap_device_assert_hardreset - set a device's hardreset line
1009 * @pdev: struct platform_device * to reset 746 * @pdev: struct platform_device * to reset
1010 * @name: const char * name of the reset line 747 * @name: const char * name of the reset line
@@ -1060,86 +797,6 @@ int omap_device_deassert_hardreset(struct platform_device *pdev,
1060} 797}
1061 798
1062/** 799/**
1063 * omap_device_align_pm_lat - activate/deactivate device to match wakeup lat lim
1064 * @od: struct omap_device *
1065 *
1066 * When a device's maximum wakeup latency limit changes, call some of
1067 * the .activate_func or .deactivate_func function pointers in the
1068 * omap_device's pm_lats array to ensure that the device's maximum
1069 * wakeup latency is less than or equal to the new latency limit.
1070 * Intended to be called by OMAP PM code whenever a device's maximum
1071 * wakeup latency limit changes (e.g., via
1072 * omap_pm_set_dev_wakeup_lat()). Returns 0 if nothing needs to be
1073 * done (e.g., if the omap_device is not currently idle, or if the
1074 * wakeup latency is already current with the new limit) or passes
1075 * along the return value of _omap_device_deactivate() or
1076 * _omap_device_activate().
1077 */
1078int omap_device_align_pm_lat(struct platform_device *pdev,
1079 u32 new_wakeup_lat_limit)
1080{
1081 int ret = -EINVAL;
1082 struct omap_device *od;
1083
1084 od = to_omap_device(pdev);
1085
1086 if (new_wakeup_lat_limit == od->dev_wakeup_lat)
1087 return 0;
1088
1089 od->_dev_wakeup_lat_limit = new_wakeup_lat_limit;
1090
1091 if (od->_state != OMAP_DEVICE_STATE_IDLE)
1092 return 0;
1093 else if (new_wakeup_lat_limit > od->dev_wakeup_lat)
1094 ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
1095 else if (new_wakeup_lat_limit < od->dev_wakeup_lat)
1096 ret = _omap_device_activate(od, USE_WAKEUP_LAT);
1097
1098 return ret;
1099}
1100
1101/**
1102 * omap_device_get_pwrdm - return the powerdomain * associated with @od
1103 * @od: struct omap_device *
1104 *
1105 * Return the powerdomain associated with the first underlying
1106 * omap_hwmod for this omap_device. Intended for use by core OMAP PM
1107 * code. Returns NULL on error or a struct powerdomain * upon
1108 * success.
1109 */
1110struct powerdomain *omap_device_get_pwrdm(struct omap_device *od)
1111{
1112 /*
1113 * XXX Assumes that all omap_hwmod powerdomains are identical.
1114 * This may not necessarily be true. There should be a sanity
1115 * check in here to WARN() if any difference appears.
1116 */
1117 if (!od->hwmods_cnt)
1118 return NULL;
1119
1120 return omap_hwmod_get_pwrdm(od->hwmods[0]);
1121}
1122
1123/**
1124 * omap_device_get_mpu_rt_va - return the MPU's virtual addr for the hwmod base
1125 * @od: struct omap_device *
1126 *
1127 * Return the MPU's virtual address for the base of the hwmod, from
1128 * the ioremap() that the hwmod code does. Only valid if there is one
1129 * hwmod associated with this device. Returns NULL if there are zero
1130 * or more than one hwmods associated with this omap_device;
1131 * otherwise, passes along the return value from
1132 * omap_hwmod_get_mpu_rt_va().
1133 */
1134void __iomem *omap_device_get_rt_va(struct omap_device *od)
1135{
1136 if (od->hwmods_cnt != 1)
1137 return NULL;
1138
1139 return omap_hwmod_get_mpu_rt_va(od->hwmods[0]);
1140}
1141
1142/**
1143 * omap_device_get_by_hwmod_name() - convert a hwmod name to 800 * omap_device_get_by_hwmod_name() - convert a hwmod name to
1144 * device pointer. 801 * device pointer.
1145 * @oh_name: name of the hwmod device 802 * @oh_name: name of the hwmod device
@@ -1173,82 +830,6 @@ struct device *omap_device_get_by_hwmod_name(const char *oh_name)
1173 830
1174 return &oh->od->pdev->dev; 831 return &oh->od->pdev->dev;
1175} 832}
1176EXPORT_SYMBOL(omap_device_get_by_hwmod_name);
1177
1178/*
1179 * Public functions intended for use in omap_device_pm_latency
1180 * .activate_func and .deactivate_func function pointers
1181 */
1182
1183/**
1184 * omap_device_enable_hwmods - call omap_hwmod_enable() on all hwmods
1185 * @od: struct omap_device *od
1186 *
1187 * Enable all underlying hwmods. Returns 0.
1188 */
1189int omap_device_enable_hwmods(struct omap_device *od)
1190{
1191 int i;
1192
1193 for (i = 0; i < od->hwmods_cnt; i++)
1194 omap_hwmod_enable(od->hwmods[i]);
1195
1196 /* XXX pass along return value here? */
1197 return 0;
1198}
1199
1200/**
1201 * omap_device_idle_hwmods - call omap_hwmod_idle() on all hwmods
1202 * @od: struct omap_device *od
1203 *
1204 * Idle all underlying hwmods. Returns 0.
1205 */
1206int omap_device_idle_hwmods(struct omap_device *od)
1207{
1208 int i;
1209
1210 for (i = 0; i < od->hwmods_cnt; i++)
1211 omap_hwmod_idle(od->hwmods[i]);
1212
1213 /* XXX pass along return value here? */
1214 return 0;
1215}
1216
1217/**
1218 * omap_device_disable_clocks - disable all main and interface clocks
1219 * @od: struct omap_device *od
1220 *
1221 * Disable the main functional clock and interface clock for all of the
1222 * omap_hwmods associated with the omap_device. Returns 0.
1223 */
1224int omap_device_disable_clocks(struct omap_device *od)
1225{
1226 int i;
1227
1228 for (i = 0; i < od->hwmods_cnt; i++)
1229 omap_hwmod_disable_clocks(od->hwmods[i]);
1230
1231 /* XXX pass along return value here? */
1232 return 0;
1233}
1234
1235/**
1236 * omap_device_enable_clocks - enable all main and interface clocks
1237 * @od: struct omap_device *od
1238 *
1239 * Enable the main functional clock and interface clock for all of the
1240 * omap_hwmods associated with the omap_device. Returns 0.
1241 */
1242int omap_device_enable_clocks(struct omap_device *od)
1243{
1244 int i;
1245
1246 for (i = 0; i < od->hwmods_cnt; i++)
1247 omap_hwmod_enable_clocks(od->hwmods[i]);
1248
1249 /* XXX pass along return value here? */
1250 return 0;
1251}
1252 833
1253static struct notifier_block platform_nb = { 834static struct notifier_block platform_nb = {
1254 .notifier_call = _omap_device_notifier_call, 835 .notifier_call = _omap_device_notifier_call,