]> git.karo-electronics.de Git - mv-sheeva.git/blob - arch/arm/plat-omap/omap_device.c
Merge branch 'omap_for_2.6.37' of git://dev.omapzoom.org/pub/scm/santosh/kernel-omap4...
[mv-sheeva.git] / arch / arm / plat-omap / omap_device.c
1 /*
2  * omap_device implementation
3  *
4  * Copyright (C) 2009-2010 Nokia Corporation
5  * Paul Walmsley, Kevin Hilman
6  *
7  * Developed in collaboration with (alphabetical order): Benoit
8  * Cousson, Thara Gopinath, Tony Lindgren, Rajendra Nayak, Vikram
9  * Pandita, Sakari Poussa, Anand Sawant, Santosh Shilimkar, Richard
10  * Woodruff
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License version 2 as
14  * published by the Free Software Foundation.
15  *
16  * This code provides a consistent interface for OMAP device drivers
17  * to control power management and interconnect properties of their
18  * devices.
19  *
20  * In the medium- to long-term, this code should either be
21  * a) implemented via arch-specific pointers in platform_data
22  * or
23  * b) implemented as a proper omap_bus/omap_device in Linux, no more
24  *    platform_data func pointers
25  *
26  *
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  */
78 #undef DEBUG
79
80 #include <linux/kernel.h>
81 #include <linux/platform_device.h>
82 #include <linux/slab.h>
83 #include <linux/err.h>
84 #include <linux/io.h>
85 #include <linux/clk.h>
86
87 #include <plat/omap_device.h>
88 #include <plat/omap_hwmod.h>
89
90 /* These parameters are passed to _omap_device_{de,}activate() */
91 #define USE_WAKEUP_LAT                  0
92 #define IGNORE_WAKEUP_LAT               1
93
94 /* Private functions */
95
96 /**
97  * _omap_device_activate - increase device readiness
98  * @od: struct omap_device *
99  * @ignore_lat: increase to latency target (0) or full readiness (1)?
100  *
101  * Increase readiness of omap_device @od (thus decreasing device
102  * wakeup latency, but consuming more power).  If @ignore_lat is
103  * IGNORE_WAKEUP_LAT, make the omap_device fully active.  Otherwise,
104  * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup
105  * latency is greater than the requested maximum wakeup latency, step
106  * backwards in the omap_device_pm_latency table to ensure the
107  * device's maximum wakeup latency is less than or equal to the
108  * requested maximum wakeup latency.  Returns 0.
109  */
110 static int _omap_device_activate(struct omap_device *od, u8 ignore_lat)
111 {
112         struct timespec a, b, c;
113
114         pr_debug("omap_device: %s: activating\n", od->pdev.name);
115
116         while (od->pm_lat_level > 0) {
117                 struct omap_device_pm_latency *odpl;
118                 unsigned long long act_lat = 0;
119
120                 od->pm_lat_level--;
121
122                 odpl = od->pm_lats + od->pm_lat_level;
123
124                 if (!ignore_lat &&
125                     (od->dev_wakeup_lat <= od->_dev_wakeup_lat_limit))
126                         break;
127
128                 read_persistent_clock(&a);
129
130                 /* XXX check return code */
131                 odpl->activate_func(od);
132
133                 read_persistent_clock(&b);
134
135                 c = timespec_sub(b, a);
136                 act_lat = timespec_to_ns(&c);
137
138                 pr_debug("omap_device: %s: pm_lat %d: activate: elapsed time "
139                          "%llu nsec\n", od->pdev.name, od->pm_lat_level,
140                          act_lat);
141
142                 if (act_lat > odpl->activate_lat) {
143                         odpl->activate_lat_worst = act_lat;
144                         if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
145                                 odpl->activate_lat = act_lat;
146                                 pr_warning("omap_device: %s.%d: new worst case "
147                                            "activate latency %d: %llu\n",
148                                            od->pdev.name, od->pdev.id,
149                                            od->pm_lat_level, act_lat);
150                         } else
151                                 pr_warning("omap_device: %s.%d: activate "
152                                            "latency %d higher than exptected. "
153                                            "(%llu > %d)\n",
154                                            od->pdev.name, od->pdev.id,
155                                            od->pm_lat_level, act_lat,
156                                            odpl->activate_lat);
157                 }
158
159                 od->dev_wakeup_lat -= odpl->activate_lat;
160         }
161
162         return 0;
163 }
164
165 /**
166  * _omap_device_deactivate - decrease device readiness
167  * @od: struct omap_device *
168  * @ignore_lat: decrease to latency target (0) or full inactivity (1)?
169  *
170  * Decrease readiness of omap_device @od (thus increasing device
171  * wakeup latency, but conserving power).  If @ignore_lat is
172  * IGNORE_WAKEUP_LAT, make the omap_device fully inactive.  Otherwise,
173  * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup
174  * latency is less than the requested maximum wakeup latency, step
175  * forwards in the omap_device_pm_latency table to ensure the device's
176  * maximum wakeup latency is less than or equal to the requested
177  * maximum wakeup latency.  Returns 0.
178  */
179 static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat)
180 {
181         struct timespec a, b, c;
182
183         pr_debug("omap_device: %s: deactivating\n", od->pdev.name);
184
185         while (od->pm_lat_level < od->pm_lats_cnt) {
186                 struct omap_device_pm_latency *odpl;
187                 unsigned long long deact_lat = 0;
188
189                 odpl = od->pm_lats + od->pm_lat_level;
190
191                 if (!ignore_lat &&
192                     ((od->dev_wakeup_lat + odpl->activate_lat) >
193                      od->_dev_wakeup_lat_limit))
194                         break;
195
196                 read_persistent_clock(&a);
197
198                 /* XXX check return code */
199                 odpl->deactivate_func(od);
200
201                 read_persistent_clock(&b);
202
203                 c = timespec_sub(b, a);
204                 deact_lat = timespec_to_ns(&c);
205
206                 pr_debug("omap_device: %s: pm_lat %d: deactivate: elapsed time "
207                          "%llu nsec\n", od->pdev.name, od->pm_lat_level,
208                          deact_lat);
209
210                 if (deact_lat > odpl->deactivate_lat) {
211                         odpl->deactivate_lat_worst = deact_lat;
212                         if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
213                                 odpl->deactivate_lat = deact_lat;
214                                 pr_warning("omap_device: %s.%d: new worst case "
215                                            "deactivate latency %d: %llu\n",
216                                            od->pdev.name, od->pdev.id,
217                                            od->pm_lat_level, deact_lat);
218                         } else
219                                 pr_warning("omap_device: %s.%d: deactivate "
220                                            "latency %d higher than exptected. "
221                                            "(%llu > %d)\n",
222                                            od->pdev.name, od->pdev.id,
223                                            od->pm_lat_level, deact_lat,
224                                            odpl->deactivate_lat);
225                 }
226
227
228                 od->dev_wakeup_lat += odpl->activate_lat;
229
230                 od->pm_lat_level++;
231         }
232
233         return 0;
234 }
235
236 static inline struct omap_device *_find_by_pdev(struct platform_device *pdev)
237 {
238         return container_of(pdev, struct omap_device, pdev);
239 }
240
241 /**
242  * _add_optional_clock_alias - Add clock alias for hwmod optional clocks
243  * @od: struct omap_device *od
244  *
245  * For every optional clock present per hwmod per omap_device, this function
246  * adds an entry in the clocks list of the form <dev-id=dev_name, con-id=role>
247  * if an entry is already present in it with the form <dev-id=NULL, con-id=role>
248  *
249  * The function is called from inside omap_device_build_ss(), after
250  * omap_device_register.
251  *
252  * This allows drivers to get a pointer to its optional clocks based on its role
253  * by calling clk_get(<dev*>, <role>).
254  *
255  * No return value.
256  */
257 static void _add_optional_clock_alias(struct omap_device *od,
258                                       struct omap_hwmod *oh)
259 {
260         int i;
261
262         for (i = 0; i < oh->opt_clks_cnt; i++) {
263                 struct omap_hwmod_opt_clk *oc;
264                 int r;
265
266                 oc = &oh->opt_clks[i];
267
268                 if (!oc->_clk)
269                         continue;
270
271                 r = clk_add_alias(oc->role, dev_name(&od->pdev.dev),
272                                   (char *)oc->clk, &od->pdev.dev);
273                 if (r)
274                         pr_err("omap_device: %s: clk_add_alias for %s failed\n",
275                                dev_name(&od->pdev.dev), oc->role);
276         }
277 }
278
279
280 /* Public functions for use by core code */
281
282 /**
283  * omap_device_count_resources - count number of struct resource entries needed
284  * @od: struct omap_device *
285  *
286  * Count the number of struct resource entries needed for this
287  * omap_device @od.  Used by omap_device_build_ss() to determine how
288  * much memory to allocate before calling
289  * omap_device_fill_resources().  Returns the count.
290  */
291 int omap_device_count_resources(struct omap_device *od)
292 {
293         struct omap_hwmod *oh;
294         int c = 0;
295         int i;
296
297         for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
298                 c += omap_hwmod_count_resources(oh);
299
300         pr_debug("omap_device: %s: counted %d total resources across %d "
301                  "hwmods\n", od->pdev.name, c, od->hwmods_cnt);
302
303         return c;
304 }
305
306 /**
307  * omap_device_fill_resources - fill in array of struct resource
308  * @od: struct omap_device *
309  * @res: pointer to an array of struct resource to be filled in
310  *
311  * Populate one or more empty struct resource pointed to by @res with
312  * the resource data for this omap_device @od.  Used by
313  * omap_device_build_ss() after calling omap_device_count_resources().
314  * Ideally this function would not be needed at all.  If omap_device
315  * replaces platform_device, then we can specify our own
316  * get_resource()/ get_irq()/etc functions that use the underlying
317  * omap_hwmod information.  Or if platform_device is extended to use
318  * subarchitecture-specific function pointers, the various
319  * platform_device functions can simply call omap_device internal
320  * functions to get device resources.  Hacking around the existing
321  * platform_device code wastes memory.  Returns 0.
322  */
323 int omap_device_fill_resources(struct omap_device *od, struct resource *res)
324 {
325         struct omap_hwmod *oh;
326         int c = 0;
327         int i, r;
328
329         for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++) {
330                 r = omap_hwmod_fill_resources(oh, res);
331                 res += r;
332                 c += r;
333         }
334
335         return 0;
336 }
337
338 /**
339  * omap_device_build - build and register an omap_device with one omap_hwmod
340  * @pdev_name: name of the platform_device driver to use
341  * @pdev_id: this platform_device's connection ID
342  * @oh: ptr to the single omap_hwmod that backs this omap_device
343  * @pdata: platform_data ptr to associate with the platform_device
344  * @pdata_len: amount of memory pointed to by @pdata
345  * @pm_lats: pointer to a omap_device_pm_latency array for this device
346  * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
347  * @is_early_device: should the device be registered as an early device or not
348  *
349  * Convenience function for building and registering a single
350  * omap_device record, which in turn builds and registers a
351  * platform_device record.  See omap_device_build_ss() for more
352  * information.  Returns ERR_PTR(-EINVAL) if @oh is NULL; otherwise,
353  * passes along the return value of omap_device_build_ss().
354  */
355 struct omap_device *omap_device_build(const char *pdev_name, int pdev_id,
356                                       struct omap_hwmod *oh, void *pdata,
357                                       int pdata_len,
358                                       struct omap_device_pm_latency *pm_lats,
359                                       int pm_lats_cnt, int is_early_device)
360 {
361         struct omap_hwmod *ohs[] = { oh };
362
363         if (!oh)
364                 return ERR_PTR(-EINVAL);
365
366         return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata,
367                                     pdata_len, pm_lats, pm_lats_cnt,
368                                     is_early_device);
369 }
370
371 /**
372  * omap_device_build_ss - build and register an omap_device with multiple hwmods
373  * @pdev_name: name of the platform_device driver to use
374  * @pdev_id: this platform_device's connection ID
375  * @oh: ptr to the single omap_hwmod that backs this omap_device
376  * @pdata: platform_data ptr to associate with the platform_device
377  * @pdata_len: amount of memory pointed to by @pdata
378  * @pm_lats: pointer to a omap_device_pm_latency array for this device
379  * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
380  * @is_early_device: should the device be registered as an early device or not
381  *
382  * Convenience function for building and registering an omap_device
383  * subsystem record.  Subsystem records consist of multiple
384  * omap_hwmods.  This function in turn builds and registers a
385  * platform_device record.  Returns an ERR_PTR() on error, or passes
386  * along the return value of omap_device_register().
387  */
388 struct omap_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
389                                          struct omap_hwmod **ohs, int oh_cnt,
390                                          void *pdata, int pdata_len,
391                                          struct omap_device_pm_latency *pm_lats,
392                                          int pm_lats_cnt, int is_early_device)
393 {
394         int ret = -ENOMEM;
395         struct omap_device *od;
396         char *pdev_name2;
397         struct resource *res = NULL;
398         int i, res_count;
399         struct omap_hwmod **hwmods;
400
401         if (!ohs || oh_cnt == 0 || !pdev_name)
402                 return ERR_PTR(-EINVAL);
403
404         if (!pdata && pdata_len > 0)
405                 return ERR_PTR(-EINVAL);
406
407         pr_debug("omap_device: %s: building with %d hwmods\n", pdev_name,
408                  oh_cnt);
409
410         od = kzalloc(sizeof(struct omap_device), GFP_KERNEL);
411         if (!od)
412                 return ERR_PTR(-ENOMEM);
413
414         od->hwmods_cnt = oh_cnt;
415
416         hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt,
417                          GFP_KERNEL);
418         if (!hwmods)
419                 goto odbs_exit1;
420
421         memcpy(hwmods, ohs, sizeof(struct omap_hwmod *) * oh_cnt);
422         od->hwmods = hwmods;
423
424         pdev_name2 = kzalloc(strlen(pdev_name) + 1, GFP_KERNEL);
425         if (!pdev_name2)
426                 goto odbs_exit2;
427         strcpy(pdev_name2, pdev_name);
428
429         od->pdev.name = pdev_name2;
430         od->pdev.id = pdev_id;
431
432         res_count = omap_device_count_resources(od);
433         if (res_count > 0) {
434                 res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
435                 if (!res)
436                         goto odbs_exit3;
437         }
438         omap_device_fill_resources(od, res);
439
440         od->pdev.num_resources = res_count;
441         od->pdev.resource = res;
442
443         ret = platform_device_add_data(&od->pdev, pdata, pdata_len);
444         if (ret)
445                 goto odbs_exit4;
446
447         od->pm_lats = pm_lats;
448         od->pm_lats_cnt = pm_lats_cnt;
449
450         if (is_early_device)
451                 ret = omap_early_device_register(od);
452         else
453                 ret = omap_device_register(od);
454
455         for (i = 0; i < oh_cnt; i++) {
456                 hwmods[i]->od = od;
457                 _add_optional_clock_alias(od, hwmods[i]);
458         }
459
460         if (ret)
461                 goto odbs_exit4;
462
463         return od;
464
465 odbs_exit4:
466         kfree(res);
467 odbs_exit3:
468         kfree(pdev_name2);
469 odbs_exit2:
470         kfree(hwmods);
471 odbs_exit1:
472         kfree(od);
473
474         pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret);
475
476         return ERR_PTR(ret);
477 }
478
479 /**
480  * omap_early_device_register - register an omap_device as an early platform
481  * device.
482  * @od: struct omap_device * to register
483  *
484  * Register the omap_device structure.  This currently just calls
485  * platform_early_add_device() on the underlying platform_device.
486  * Returns 0 by default.
487  */
488 int omap_early_device_register(struct omap_device *od)
489 {
490         struct platform_device *devices[1];
491
492         devices[0] = &(od->pdev);
493         early_platform_add_devices(devices, 1);
494         return 0;
495 }
496
497 /**
498  * omap_device_register - register an omap_device with one omap_hwmod
499  * @od: struct omap_device * to register
500  *
501  * Register the omap_device structure.  This currently just calls
502  * platform_device_register() on the underlying platform_device.
503  * Returns the return value of platform_device_register().
504  */
505 int omap_device_register(struct omap_device *od)
506 {
507         pr_debug("omap_device: %s: registering\n", od->pdev.name);
508
509         od->pdev.dev.parent = &omap_device_parent;
510         return platform_device_register(&od->pdev);
511 }
512
513
514 /* Public functions for use by device drivers through struct platform_data */
515
516 /**
517  * omap_device_enable - fully activate an omap_device
518  * @od: struct omap_device * to activate
519  *
520  * Do whatever is necessary for the hwmods underlying omap_device @od
521  * to be accessible and ready to operate.  This generally involves
522  * enabling clocks, setting SYSCONFIG registers; and in the future may
523  * involve remuxing pins.  Device drivers should call this function
524  * (through platform_data function pointers) where they would normally
525  * enable clocks, etc.  Returns -EINVAL if called when the omap_device
526  * is already enabled, or passes along the return value of
527  * _omap_device_activate().
528  */
529 int omap_device_enable(struct platform_device *pdev)
530 {
531         int ret;
532         struct omap_device *od;
533
534         od = _find_by_pdev(pdev);
535
536         if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
537                 WARN(1, "omap_device: %s.%d: %s() called from invalid state %d\n",
538                      od->pdev.name, od->pdev.id, __func__, od->_state);
539                 return -EINVAL;
540         }
541
542         /* Enable everything if we're enabling this device from scratch */
543         if (od->_state == OMAP_DEVICE_STATE_UNKNOWN)
544                 od->pm_lat_level = od->pm_lats_cnt;
545
546         ret = _omap_device_activate(od, IGNORE_WAKEUP_LAT);
547
548         od->dev_wakeup_lat = 0;
549         od->_dev_wakeup_lat_limit = UINT_MAX;
550         od->_state = OMAP_DEVICE_STATE_ENABLED;
551
552         return ret;
553 }
554
555 /**
556  * omap_device_idle - idle an omap_device
557  * @od: struct omap_device * to idle
558  *
559  * Idle omap_device @od by calling as many .deactivate_func() entries
560  * in the omap_device's pm_lats table as is possible without exceeding
561  * the device's maximum wakeup latency limit, pm_lat_limit.  Device
562  * drivers should call this function (through platform_data function
563  * pointers) where they would normally disable clocks after operations
564  * complete, etc..  Returns -EINVAL if the omap_device is not
565  * currently enabled, or passes along the return value of
566  * _omap_device_deactivate().
567  */
568 int omap_device_idle(struct platform_device *pdev)
569 {
570         int ret;
571         struct omap_device *od;
572
573         od = _find_by_pdev(pdev);
574
575         if (od->_state != OMAP_DEVICE_STATE_ENABLED) {
576                 WARN(1, "omap_device: %s.%d: %s() called from invalid state %d\n",
577                      od->pdev.name, od->pdev.id, __func__, od->_state);
578                 return -EINVAL;
579         }
580
581         ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
582
583         od->_state = OMAP_DEVICE_STATE_IDLE;
584
585         return ret;
586 }
587
588 /**
589  * omap_device_shutdown - shut down an omap_device
590  * @od: struct omap_device * to shut down
591  *
592  * Shut down omap_device @od by calling all .deactivate_func() entries
593  * in the omap_device's pm_lats table and then shutting down all of
594  * the underlying omap_hwmods.  Used when a device is being "removed"
595  * or a device driver is being unloaded.  Returns -EINVAL if the
596  * omap_device is not currently enabled or idle, or passes along the
597  * return value of _omap_device_deactivate().
598  */
599 int omap_device_shutdown(struct platform_device *pdev)
600 {
601         int ret, i;
602         struct omap_device *od;
603         struct omap_hwmod *oh;
604
605         od = _find_by_pdev(pdev);
606
607         if (od->_state != OMAP_DEVICE_STATE_ENABLED &&
608             od->_state != OMAP_DEVICE_STATE_IDLE) {
609                 WARN(1, "omap_device: %s.%d: %s() called from invalid state %d\n",
610                      od->pdev.name, od->pdev.id, __func__, od->_state);
611                 return -EINVAL;
612         }
613
614         ret = _omap_device_deactivate(od, IGNORE_WAKEUP_LAT);
615
616         for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
617                 omap_hwmod_shutdown(oh);
618
619         od->_state = OMAP_DEVICE_STATE_SHUTDOWN;
620
621         return ret;
622 }
623
624 /**
625  * omap_device_align_pm_lat - activate/deactivate device to match wakeup lat lim
626  * @od: struct omap_device *
627  *
628  * When a device's maximum wakeup latency limit changes, call some of
629  * the .activate_func or .deactivate_func function pointers in the
630  * omap_device's pm_lats array to ensure that the device's maximum
631  * wakeup latency is less than or equal to the new latency limit.
632  * Intended to be called by OMAP PM code whenever a device's maximum
633  * wakeup latency limit changes (e.g., via
634  * omap_pm_set_dev_wakeup_lat()).  Returns 0 if nothing needs to be
635  * done (e.g., if the omap_device is not currently idle, or if the
636  * wakeup latency is already current with the new limit) or passes
637  * along the return value of _omap_device_deactivate() or
638  * _omap_device_activate().
639  */
640 int omap_device_align_pm_lat(struct platform_device *pdev,
641                              u32 new_wakeup_lat_limit)
642 {
643         int ret = -EINVAL;
644         struct omap_device *od;
645
646         od = _find_by_pdev(pdev);
647
648         if (new_wakeup_lat_limit == od->dev_wakeup_lat)
649                 return 0;
650
651         od->_dev_wakeup_lat_limit = new_wakeup_lat_limit;
652
653         if (od->_state != OMAP_DEVICE_STATE_IDLE)
654                 return 0;
655         else if (new_wakeup_lat_limit > od->dev_wakeup_lat)
656                 ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
657         else if (new_wakeup_lat_limit < od->dev_wakeup_lat)
658                 ret = _omap_device_activate(od, USE_WAKEUP_LAT);
659
660         return ret;
661 }
662
663 /**
664  * omap_device_get_pwrdm - return the powerdomain * associated with @od
665  * @od: struct omap_device *
666  *
667  * Return the powerdomain associated with the first underlying
668  * omap_hwmod for this omap_device.  Intended for use by core OMAP PM
669  * code.  Returns NULL on error or a struct powerdomain * upon
670  * success.
671  */
672 struct powerdomain *omap_device_get_pwrdm(struct omap_device *od)
673 {
674         /*
675          * XXX Assumes that all omap_hwmod powerdomains are identical.
676          * This may not necessarily be true.  There should be a sanity
677          * check in here to WARN() if any difference appears.
678          */
679         if (!od->hwmods_cnt)
680                 return NULL;
681
682         return omap_hwmod_get_pwrdm(od->hwmods[0]);
683 }
684
685 /**
686  * omap_device_get_mpu_rt_va - return the MPU's virtual addr for the hwmod base
687  * @od: struct omap_device *
688  *
689  * Return the MPU's virtual address for the base of the hwmod, from
690  * the ioremap() that the hwmod code does.  Only valid if there is one
691  * hwmod associated with this device.  Returns NULL if there are zero
692  * or more than one hwmods associated with this omap_device;
693  * otherwise, passes along the return value from
694  * omap_hwmod_get_mpu_rt_va().
695  */
696 void __iomem *omap_device_get_rt_va(struct omap_device *od)
697 {
698         if (od->hwmods_cnt != 1)
699                 return NULL;
700
701         return omap_hwmod_get_mpu_rt_va(od->hwmods[0]);
702 }
703
704 /*
705  * Public functions intended for use in omap_device_pm_latency
706  * .activate_func and .deactivate_func function pointers
707  */
708
709 /**
710  * omap_device_enable_hwmods - call omap_hwmod_enable() on all hwmods
711  * @od: struct omap_device *od
712  *
713  * Enable all underlying hwmods.  Returns 0.
714  */
715 int omap_device_enable_hwmods(struct omap_device *od)
716 {
717         struct omap_hwmod *oh;
718         int i;
719
720         for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
721                 omap_hwmod_enable(oh);
722
723         /* XXX pass along return value here? */
724         return 0;
725 }
726
727 /**
728  * omap_device_idle_hwmods - call omap_hwmod_idle() on all hwmods
729  * @od: struct omap_device *od
730  *
731  * Idle all underlying hwmods.  Returns 0.
732  */
733 int omap_device_idle_hwmods(struct omap_device *od)
734 {
735         struct omap_hwmod *oh;
736         int i;
737
738         for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
739                 omap_hwmod_idle(oh);
740
741         /* XXX pass along return value here? */
742         return 0;
743 }
744
745 /**
746  * omap_device_disable_clocks - disable all main and interface clocks
747  * @od: struct omap_device *od
748  *
749  * Disable the main functional clock and interface clock for all of the
750  * omap_hwmods associated with the omap_device.  Returns 0.
751  */
752 int omap_device_disable_clocks(struct omap_device *od)
753 {
754         struct omap_hwmod *oh;
755         int i;
756
757         for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
758                 omap_hwmod_disable_clocks(oh);
759
760         /* XXX pass along return value here? */
761         return 0;
762 }
763
764 /**
765  * omap_device_enable_clocks - enable all main and interface clocks
766  * @od: struct omap_device *od
767  *
768  * Enable the main functional clock and interface clock for all of the
769  * omap_hwmods associated with the omap_device.  Returns 0.
770  */
771 int omap_device_enable_clocks(struct omap_device *od)
772 {
773         struct omap_hwmod *oh;
774         int i;
775
776         for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
777                 omap_hwmod_enable_clocks(oh);
778
779         /* XXX pass along return value here? */
780         return 0;
781 }
782
783 struct device omap_device_parent = {
784         .init_name      = "omap",
785         .parent         = &platform_bus,
786 };
787
788 static int __init omap_device_init(void)
789 {
790         return device_register(&omap_device_parent);
791 }
792 core_initcall(omap_device_init);