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