blob: d8c75c8f78d75268eca6330f353a8b9007f6904a [file] [log] [blame]
Paul Walmsleyb04b65a2009-09-03 20:14:05 +03001/*
2 * omap_device implementation
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Paul Walmsley
6 *
7 * Developed in collaboration with (alphabetical order): Benoit
8 * Cousson, Kevin Hilman, 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/err.h>
83#include <linux/io.h>
84
Tony Lindgrence491cf2009-10-20 09:40:47 -070085#include <plat/omap_device.h>
86#include <plat/omap_hwmod.h>
Paul Walmsleyb04b65a2009-09-03 20:14:05 +030087
88/* These parameters are passed to _omap_device_{de,}activate() */
89#define USE_WAKEUP_LAT 0
90#define IGNORE_WAKEUP_LAT 1
91
92/* XXX this should be moved into a separate file */
93#if defined(CONFIG_ARCH_OMAP2420)
94# define OMAP_32KSYNCT_BASE 0x48004000
95#elif defined(CONFIG_ARCH_OMAP2430)
96# define OMAP_32KSYNCT_BASE 0x49020000
97#elif defined(CONFIG_ARCH_OMAP3430)
98# define OMAP_32KSYNCT_BASE 0x48320000
99#else
100# error Unknown OMAP device
101#endif
102
103/* Private functions */
104
105/**
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300106 * _omap_device_activate - increase device readiness
107 * @od: struct omap_device *
108 * @ignore_lat: increase to latency target (0) or full readiness (1)?
109 *
110 * Increase readiness of omap_device @od (thus decreasing device
111 * wakeup latency, but consuming more power). If @ignore_lat is
112 * IGNORE_WAKEUP_LAT, make the omap_device fully active. Otherwise,
113 * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup
114 * latency is greater than the requested maximum wakeup latency, step
115 * backwards in the omap_device_pm_latency table to ensure the
116 * device's maximum wakeup latency is less than or equal to the
117 * requested maximum wakeup latency. Returns 0.
118 */
119static int _omap_device_activate(struct omap_device *od, u8 ignore_lat)
120{
Tony Lindgrenf059429e2009-10-19 15:25:24 -0700121 struct timespec a, b, c;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300122
123 pr_debug("omap_device: %s: activating\n", od->pdev.name);
124
125 while (od->pm_lat_level > 0) {
126 struct omap_device_pm_latency *odpl;
Tony Lindgrenf059429e2009-10-19 15:25:24 -0700127 unsigned long long act_lat = 0;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300128
129 od->pm_lat_level--;
130
131 odpl = od->pm_lats + od->pm_lat_level;
132
133 if (!ignore_lat &&
134 (od->dev_wakeup_lat <= od->_dev_wakeup_lat_limit))
135 break;
136
Kevin Hilmand2292662009-12-08 16:34:23 -0700137 read_persistent_clock(&a);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300138
139 /* XXX check return code */
140 odpl->activate_func(od);
141
Kevin Hilmand2292662009-12-08 16:34:23 -0700142 read_persistent_clock(&b);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300143
Tony Lindgrenf059429e2009-10-19 15:25:24 -0700144 c = timespec_sub(b, a);
Kevin Hilman0d93d8b2009-12-08 16:34:26 -0700145 act_lat = timespec_to_ns(&c);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300146
147 pr_debug("omap_device: %s: pm_lat %d: activate: elapsed time "
Kevin Hilman0d93d8b2009-12-08 16:34:26 -0700148 "%llu nsec\n", od->pdev.name, od->pm_lat_level,
Tony Lindgrenf059429e2009-10-19 15:25:24 -0700149 act_lat);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300150
Kevin Hilman9799aca2010-01-26 20:13:02 -0700151 if (act_lat > odpl->activate_lat) {
152 odpl->activate_lat_worst = act_lat;
153 if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
154 odpl->activate_lat = act_lat;
155 pr_warning("omap_device: %s.%d: new worst case "
156 "activate latency %d: %llu\n",
157 od->pdev.name, od->pdev.id,
158 od->pm_lat_level, act_lat);
159 } else
160 pr_warning("omap_device: %s.%d: activate "
161 "latency %d higher than exptected. "
162 "(%llu > %d)\n",
163 od->pdev.name, od->pdev.id,
164 od->pm_lat_level, act_lat,
165 odpl->activate_lat);
166 }
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300167
168 od->dev_wakeup_lat -= odpl->activate_lat;
169 }
170
171 return 0;
172}
173
174/**
175 * _omap_device_deactivate - decrease device readiness
176 * @od: struct omap_device *
177 * @ignore_lat: decrease to latency target (0) or full inactivity (1)?
178 *
179 * Decrease readiness of omap_device @od (thus increasing device
180 * wakeup latency, but conserving power). If @ignore_lat is
181 * IGNORE_WAKEUP_LAT, make the omap_device fully inactive. Otherwise,
182 * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup
183 * latency is less than the requested maximum wakeup latency, step
184 * forwards in the omap_device_pm_latency table to ensure the device's
185 * maximum wakeup latency is less than or equal to the requested
186 * maximum wakeup latency. Returns 0.
187 */
188static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat)
189{
Tony Lindgrenf059429e2009-10-19 15:25:24 -0700190 struct timespec a, b, c;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300191
192 pr_debug("omap_device: %s: deactivating\n", od->pdev.name);
193
194 while (od->pm_lat_level < od->pm_lats_cnt) {
195 struct omap_device_pm_latency *odpl;
Tony Lindgrenf059429e2009-10-19 15:25:24 -0700196 unsigned long long deact_lat = 0;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300197
198 odpl = od->pm_lats + od->pm_lat_level;
199
200 if (!ignore_lat &&
201 ((od->dev_wakeup_lat + odpl->activate_lat) >
202 od->_dev_wakeup_lat_limit))
203 break;
204
Kevin Hilmand2292662009-12-08 16:34:23 -0700205 read_persistent_clock(&a);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300206
207 /* XXX check return code */
208 odpl->deactivate_func(od);
209
Kevin Hilmand2292662009-12-08 16:34:23 -0700210 read_persistent_clock(&b);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300211
Tony Lindgrenf059429e2009-10-19 15:25:24 -0700212 c = timespec_sub(b, a);
Kevin Hilman0d93d8b2009-12-08 16:34:26 -0700213 deact_lat = timespec_to_ns(&c);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300214
215 pr_debug("omap_device: %s: pm_lat %d: deactivate: elapsed time "
Kevin Hilman0d93d8b2009-12-08 16:34:26 -0700216 "%llu nsec\n", od->pdev.name, od->pm_lat_level,
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300217 deact_lat);
218
Kevin Hilman9799aca2010-01-26 20:13:02 -0700219 if (deact_lat > odpl->deactivate_lat) {
220 odpl->deactivate_lat_worst = deact_lat;
221 if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
222 odpl->deactivate_lat = deact_lat;
223 pr_warning("omap_device: %s.%d: new worst case "
224 "deactivate latency %d: %llu\n",
225 od->pdev.name, od->pdev.id,
226 od->pm_lat_level, deact_lat);
227 } else
228 pr_warning("omap_device: %s.%d: deactivate "
229 "latency %d higher than exptected. "
230 "(%llu > %d)\n",
231 od->pdev.name, od->pdev.id,
232 od->pm_lat_level, deact_lat,
233 odpl->deactivate_lat);
234 }
235
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300236
237 od->dev_wakeup_lat += odpl->activate_lat;
238
239 od->pm_lat_level++;
240 }
241
242 return 0;
243}
244
245static inline struct omap_device *_find_by_pdev(struct platform_device *pdev)
246{
247 return container_of(pdev, struct omap_device, pdev);
248}
249
250
251/* Public functions for use by core code */
252
253/**
254 * omap_device_count_resources - count number of struct resource entries needed
255 * @od: struct omap_device *
256 *
257 * Count the number of struct resource entries needed for this
258 * omap_device @od. Used by omap_device_build_ss() to determine how
259 * much memory to allocate before calling
260 * omap_device_fill_resources(). Returns the count.
261 */
262int omap_device_count_resources(struct omap_device *od)
263{
264 struct omap_hwmod *oh;
265 int c = 0;
266 int i;
267
268 for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
269 c += omap_hwmod_count_resources(oh);
270
271 pr_debug("omap_device: %s: counted %d total resources across %d "
272 "hwmods\n", od->pdev.name, c, od->hwmods_cnt);
273
274 return c;
275}
276
277/**
278 * omap_device_fill_resources - fill in array of struct resource
279 * @od: struct omap_device *
280 * @res: pointer to an array of struct resource to be filled in
281 *
282 * Populate one or more empty struct resource pointed to by @res with
283 * the resource data for this omap_device @od. Used by
284 * omap_device_build_ss() after calling omap_device_count_resources().
285 * Ideally this function would not be needed at all. If omap_device
286 * replaces platform_device, then we can specify our own
287 * get_resource()/ get_irq()/etc functions that use the underlying
288 * omap_hwmod information. Or if platform_device is extended to use
289 * subarchitecture-specific function pointers, the various
290 * platform_device functions can simply call omap_device internal
291 * functions to get device resources. Hacking around the existing
292 * platform_device code wastes memory. Returns 0.
293 */
294int omap_device_fill_resources(struct omap_device *od, struct resource *res)
295{
296 struct omap_hwmod *oh;
297 int c = 0;
298 int i, r;
299
300 for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++) {
301 r = omap_hwmod_fill_resources(oh, res);
302 res += r;
303 c += r;
304 }
305
306 return 0;
307}
308
309/**
310 * omap_device_build - build and register an omap_device with one omap_hwmod
311 * @pdev_name: name of the platform_device driver to use
312 * @pdev_id: this platform_device's connection ID
313 * @oh: ptr to the single omap_hwmod that backs this omap_device
314 * @pdata: platform_data ptr to associate with the platform_device
315 * @pdata_len: amount of memory pointed to by @pdata
316 * @pm_lats: pointer to a omap_device_pm_latency array for this device
317 * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
318 *
319 * Convenience function for building and registering a single
320 * omap_device record, which in turn builds and registers a
321 * platform_device record. See omap_device_build_ss() for more
322 * information. Returns ERR_PTR(-EINVAL) if @oh is NULL; otherwise,
323 * passes along the return value of omap_device_build_ss().
324 */
325struct omap_device *omap_device_build(const char *pdev_name, int pdev_id,
326 struct omap_hwmod *oh, void *pdata,
327 int pdata_len,
328 struct omap_device_pm_latency *pm_lats,
329 int pm_lats_cnt)
330{
331 struct omap_hwmod *ohs[] = { oh };
332
333 if (!oh)
334 return ERR_PTR(-EINVAL);
335
336 return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata,
337 pdata_len, pm_lats, pm_lats_cnt);
338}
339
340/**
341 * omap_device_build_ss - build and register an omap_device with multiple hwmods
342 * @pdev_name: name of the platform_device driver to use
343 * @pdev_id: this platform_device's connection ID
344 * @oh: ptr to the single omap_hwmod that backs this omap_device
345 * @pdata: platform_data ptr to associate with the platform_device
346 * @pdata_len: amount of memory pointed to by @pdata
347 * @pm_lats: pointer to a omap_device_pm_latency array for this device
348 * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
349 *
350 * Convenience function for building and registering an omap_device
351 * subsystem record. Subsystem records consist of multiple
352 * omap_hwmods. This function in turn builds and registers a
353 * platform_device record. Returns an ERR_PTR() on error, or passes
354 * along the return value of omap_device_register().
355 */
356struct omap_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
357 struct omap_hwmod **ohs, int oh_cnt,
358 void *pdata, int pdata_len,
359 struct omap_device_pm_latency *pm_lats,
360 int pm_lats_cnt)
361{
362 int ret = -ENOMEM;
363 struct omap_device *od;
364 char *pdev_name2;
365 struct resource *res = NULL;
366 int res_count;
367 struct omap_hwmod **hwmods;
368
369 if (!ohs || oh_cnt == 0 || !pdev_name)
370 return ERR_PTR(-EINVAL);
371
372 if (!pdata && pdata_len > 0)
373 return ERR_PTR(-EINVAL);
374
375 pr_debug("omap_device: %s: building with %d hwmods\n", pdev_name,
376 oh_cnt);
377
378 od = kzalloc(sizeof(struct omap_device), GFP_KERNEL);
379 if (!od)
380 return ERR_PTR(-ENOMEM);
381
382 od->hwmods_cnt = oh_cnt;
383
384 hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt,
385 GFP_KERNEL);
386 if (!hwmods)
387 goto odbs_exit1;
388
389 memcpy(hwmods, ohs, sizeof(struct omap_hwmod *) * oh_cnt);
390 od->hwmods = hwmods;
391
392 pdev_name2 = kzalloc(strlen(pdev_name) + 1, GFP_KERNEL);
393 if (!pdev_name2)
394 goto odbs_exit2;
395 strcpy(pdev_name2, pdev_name);
396
397 od->pdev.name = pdev_name2;
398 od->pdev.id = pdev_id;
399
400 res_count = omap_device_count_resources(od);
401 if (res_count > 0) {
402 res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
403 if (!res)
404 goto odbs_exit3;
405 }
406 omap_device_fill_resources(od, res);
407
408 od->pdev.num_resources = res_count;
409 od->pdev.resource = res;
410
411 platform_device_add_data(&od->pdev, pdata, pdata_len);
412
413 od->pm_lats = pm_lats;
414 od->pm_lats_cnt = pm_lats_cnt;
415
416 ret = omap_device_register(od);
417 if (ret)
418 goto odbs_exit4;
419
420 return od;
421
422odbs_exit4:
423 kfree(res);
424odbs_exit3:
425 kfree(pdev_name2);
426odbs_exit2:
427 kfree(hwmods);
428odbs_exit1:
429 kfree(od);
430
431 pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret);
432
433 return ERR_PTR(ret);
434}
435
436/**
437 * omap_device_register - register an omap_device with one omap_hwmod
438 * @od: struct omap_device * to register
439 *
440 * Register the omap_device structure. This currently just calls
441 * platform_device_register() on the underlying platform_device.
442 * Returns the return value of platform_device_register().
443 */
444int omap_device_register(struct omap_device *od)
445{
446 pr_debug("omap_device: %s: registering\n", od->pdev.name);
447
448 return platform_device_register(&od->pdev);
449}
450
451
452/* Public functions for use by device drivers through struct platform_data */
453
454/**
455 * omap_device_enable - fully activate an omap_device
456 * @od: struct omap_device * to activate
457 *
458 * Do whatever is necessary for the hwmods underlying omap_device @od
459 * to be accessible and ready to operate. This generally involves
460 * enabling clocks, setting SYSCONFIG registers; and in the future may
461 * involve remuxing pins. Device drivers should call this function
462 * (through platform_data function pointers) where they would normally
463 * enable clocks, etc. Returns -EINVAL if called when the omap_device
464 * is already enabled, or passes along the return value of
465 * _omap_device_activate().
466 */
467int omap_device_enable(struct platform_device *pdev)
468{
469 int ret;
470 struct omap_device *od;
471
472 od = _find_by_pdev(pdev);
473
474 if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
475 WARN(1, "omap_device: %s.%d: omap_device_enable() called from "
476 "invalid state\n", od->pdev.name, od->pdev.id);
477 return -EINVAL;
478 }
479
480 /* Enable everything if we're enabling this device from scratch */
481 if (od->_state == OMAP_DEVICE_STATE_UNKNOWN)
482 od->pm_lat_level = od->pm_lats_cnt;
483
484 ret = _omap_device_activate(od, IGNORE_WAKEUP_LAT);
485
486 od->dev_wakeup_lat = 0;
Kevin Hilman5f1b6ef2009-12-08 16:34:22 -0700487 od->_dev_wakeup_lat_limit = UINT_MAX;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300488 od->_state = OMAP_DEVICE_STATE_ENABLED;
489
490 return ret;
491}
492
493/**
494 * omap_device_idle - idle an omap_device
495 * @od: struct omap_device * to idle
496 *
497 * Idle omap_device @od by calling as many .deactivate_func() entries
498 * in the omap_device's pm_lats table as is possible without exceeding
499 * the device's maximum wakeup latency limit, pm_lat_limit. Device
500 * drivers should call this function (through platform_data function
501 * pointers) where they would normally disable clocks after operations
502 * complete, etc.. Returns -EINVAL if the omap_device is not
503 * currently enabled, or passes along the return value of
504 * _omap_device_deactivate().
505 */
506int omap_device_idle(struct platform_device *pdev)
507{
508 int ret;
509 struct omap_device *od;
510
511 od = _find_by_pdev(pdev);
512
513 if (od->_state != OMAP_DEVICE_STATE_ENABLED) {
514 WARN(1, "omap_device: %s.%d: omap_device_idle() called from "
515 "invalid state\n", od->pdev.name, od->pdev.id);
516 return -EINVAL;
517 }
518
519 ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
520
521 od->_state = OMAP_DEVICE_STATE_IDLE;
522
523 return ret;
524}
525
526/**
527 * omap_device_shutdown - shut down an omap_device
528 * @od: struct omap_device * to shut down
529 *
530 * Shut down omap_device @od by calling all .deactivate_func() entries
531 * in the omap_device's pm_lats table and then shutting down all of
532 * the underlying omap_hwmods. Used when a device is being "removed"
533 * or a device driver is being unloaded. Returns -EINVAL if the
534 * omap_device is not currently enabled or idle, or passes along the
535 * return value of _omap_device_deactivate().
536 */
537int omap_device_shutdown(struct platform_device *pdev)
538{
539 int ret, i;
540 struct omap_device *od;
541 struct omap_hwmod *oh;
542
543 od = _find_by_pdev(pdev);
544
545 if (od->_state != OMAP_DEVICE_STATE_ENABLED &&
546 od->_state != OMAP_DEVICE_STATE_IDLE) {
547 WARN(1, "omap_device: %s.%d: omap_device_shutdown() called "
548 "from invalid state\n", od->pdev.name, od->pdev.id);
549 return -EINVAL;
550 }
551
552 ret = _omap_device_deactivate(od, IGNORE_WAKEUP_LAT);
553
554 for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
555 omap_hwmod_shutdown(oh);
556
557 od->_state = OMAP_DEVICE_STATE_SHUTDOWN;
558
559 return ret;
560}
561
562/**
563 * omap_device_align_pm_lat - activate/deactivate device to match wakeup lat lim
564 * @od: struct omap_device *
565 *
566 * When a device's maximum wakeup latency limit changes, call some of
567 * the .activate_func or .deactivate_func function pointers in the
568 * omap_device's pm_lats array to ensure that the device's maximum
569 * wakeup latency is less than or equal to the new latency limit.
570 * Intended to be called by OMAP PM code whenever a device's maximum
571 * wakeup latency limit changes (e.g., via
572 * omap_pm_set_dev_wakeup_lat()). Returns 0 if nothing needs to be
573 * done (e.g., if the omap_device is not currently idle, or if the
574 * wakeup latency is already current with the new limit) or passes
575 * along the return value of _omap_device_deactivate() or
576 * _omap_device_activate().
577 */
578int omap_device_align_pm_lat(struct platform_device *pdev,
579 u32 new_wakeup_lat_limit)
580{
581 int ret = -EINVAL;
582 struct omap_device *od;
583
584 od = _find_by_pdev(pdev);
585
586 if (new_wakeup_lat_limit == od->dev_wakeup_lat)
587 return 0;
588
589 od->_dev_wakeup_lat_limit = new_wakeup_lat_limit;
590
591 if (od->_state != OMAP_DEVICE_STATE_IDLE)
592 return 0;
593 else if (new_wakeup_lat_limit > od->dev_wakeup_lat)
594 ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
595 else if (new_wakeup_lat_limit < od->dev_wakeup_lat)
596 ret = _omap_device_activate(od, USE_WAKEUP_LAT);
597
598 return ret;
599}
600
601/**
602 * omap_device_get_pwrdm - return the powerdomain * associated with @od
603 * @od: struct omap_device *
604 *
605 * Return the powerdomain associated with the first underlying
606 * omap_hwmod for this omap_device. Intended for use by core OMAP PM
607 * code. Returns NULL on error or a struct powerdomain * upon
608 * success.
609 */
610struct powerdomain *omap_device_get_pwrdm(struct omap_device *od)
611{
612 /*
613 * XXX Assumes that all omap_hwmod powerdomains are identical.
614 * This may not necessarily be true. There should be a sanity
615 * check in here to WARN() if any difference appears.
616 */
617 if (!od->hwmods_cnt)
618 return NULL;
619
620 return omap_hwmod_get_pwrdm(od->hwmods[0]);
621}
622
623/*
624 * Public functions intended for use in omap_device_pm_latency
625 * .activate_func and .deactivate_func function pointers
626 */
627
628/**
629 * omap_device_enable_hwmods - call omap_hwmod_enable() on all hwmods
630 * @od: struct omap_device *od
631 *
632 * Enable all underlying hwmods. Returns 0.
633 */
634int omap_device_enable_hwmods(struct omap_device *od)
635{
636 struct omap_hwmod *oh;
637 int i;
638
639 for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
640 omap_hwmod_enable(oh);
641
642 /* XXX pass along return value here? */
643 return 0;
644}
645
646/**
647 * omap_device_idle_hwmods - call omap_hwmod_idle() on all hwmods
648 * @od: struct omap_device *od
649 *
650 * Idle all underlying hwmods. Returns 0.
651 */
652int omap_device_idle_hwmods(struct omap_device *od)
653{
654 struct omap_hwmod *oh;
655 int i;
656
657 for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
658 omap_hwmod_idle(oh);
659
660 /* XXX pass along return value here? */
661 return 0;
662}
663
664/**
665 * omap_device_disable_clocks - disable all main and interface clocks
666 * @od: struct omap_device *od
667 *
668 * Disable the main functional clock and interface clock for all of the
669 * omap_hwmods associated with the omap_device. Returns 0.
670 */
671int omap_device_disable_clocks(struct omap_device *od)
672{
673 struct omap_hwmod *oh;
674 int i;
675
676 for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
677 omap_hwmod_disable_clocks(oh);
678
679 /* XXX pass along return value here? */
680 return 0;
681}
682
683/**
684 * omap_device_enable_clocks - enable all main and interface clocks
685 * @od: struct omap_device *od
686 *
687 * Enable the main functional clock and interface clock for all of the
688 * omap_hwmods associated with the omap_device. Returns 0.
689 */
690int omap_device_enable_clocks(struct omap_device *od)
691{
692 struct omap_hwmod *oh;
693 int i;
694
695 for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
696 omap_hwmod_enable_clocks(oh);
697
698 /* XXX pass along return value here? */
699 return 0;
700}