ARM: OMAP: remove plat/clock.h
[deliverable/linux.git] / arch / arm / mach-omap2 / 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>
55581415 81#include <linux/export.h>
b04b65ab 82#include <linux/platform_device.h>
5a0e3ad6 83#include <linux/slab.h>
b04b65ab
PW
84#include <linux/err.h>
85#include <linux/io.h>
4ef7aca8 86#include <linux/clk.h>
da0653fe 87#include <linux/clkdev.h>
345f79b3 88#include <linux/pm_runtime.h>
dc2d07eb
BC
89#include <linux/of.h>
90#include <linux/notifier.h>
b04b65ab 91
25c7d49e 92#include "omap_device.h"
2a296c8f 93#include "omap_hwmod.h"
b04b65ab
PW
94
95/* These parameters are passed to _omap_device_{de,}activate() */
96#define USE_WAKEUP_LAT 0
97#define IGNORE_WAKEUP_LAT 1
98
bfae4f8f 99static int omap_early_device_register(struct platform_device *pdev);
a2a28ad9 100
b7b5bc91
BC
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
b04b65ab
PW
109/* Private functions */
110
b04b65ab
PW
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{
f059429e 127 struct timespec a, b, c;
b04b65ab 128
d66b3fe4 129 dev_dbg(&od->pdev->dev, "omap_device: activating\n");
b04b65ab
PW
130
131 while (od->pm_lat_level > 0) {
132 struct omap_device_pm_latency *odpl;
f059429e 133 unsigned long long act_lat = 0;
b04b65ab
PW
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
d2292667 143 read_persistent_clock(&a);
b04b65ab
PW
144
145 /* XXX check return code */
146 odpl->activate_func(od);
147
d2292667 148 read_persistent_clock(&b);
b04b65ab 149
f059429e 150 c = timespec_sub(b, a);
0d93d8bb 151 act_lat = timespec_to_ns(&c);
b04b65ab 152
d66b3fe4 153 dev_dbg(&od->pdev->dev,
7852ec05
PW
154 "omap_device: pm_lat %d: activate: elapsed time %llu nsec\n",
155 od->pm_lat_level, act_lat);
b04b65ab 156
9799aca2
KH
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;
d66b3fe4 161 dev_dbg(&od->pdev->dev,
7852ec05 162 "new worst case activate latency %d: %llu\n",
47c3e5d8 163 od->pm_lat_level, act_lat);
9799aca2 164 } else
d66b3fe4 165 dev_warn(&od->pdev->dev,
7852ec05 166 "activate latency %d higher than expected. (%llu > %d)\n",
49882c99
KH
167 od->pm_lat_level, act_lat,
168 odpl->activate_lat);
9799aca2 169 }
b04b65ab
PW
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{
f059429e 193 struct timespec a, b, c;
b04b65ab 194
d66b3fe4 195 dev_dbg(&od->pdev->dev, "omap_device: deactivating\n");
b04b65ab
PW
196
197 while (od->pm_lat_level < od->pm_lats_cnt) {
198 struct omap_device_pm_latency *odpl;
f059429e 199 unsigned long long deact_lat = 0;
b04b65ab
PW
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
d2292667 208 read_persistent_clock(&a);
b04b65ab
PW
209
210 /* XXX check return code */
211 odpl->deactivate_func(od);
212
d2292667 213 read_persistent_clock(&b);
b04b65ab 214
f059429e 215 c = timespec_sub(b, a);
0d93d8bb 216 deact_lat = timespec_to_ns(&c);
b04b65ab 217
d66b3fe4 218 dev_dbg(&od->pdev->dev,
7852ec05
PW
219 "omap_device: pm_lat %d: deactivate: elapsed time %llu nsec\n",
220 od->pm_lat_level, deact_lat);
b04b65ab 221
9799aca2
KH
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;
d66b3fe4 226 dev_dbg(&od->pdev->dev,
7852ec05 227 "new worst case deactivate latency %d: %llu\n",
47c3e5d8 228 od->pm_lat_level, deact_lat);
9799aca2 229 } else
d66b3fe4 230 dev_warn(&od->pdev->dev,
7852ec05 231 "deactivate latency %d higher than expected. (%llu > %d)\n",
49882c99
KH
232 od->pm_lat_level, deact_lat,
233 odpl->deactivate_lat);
9799aca2
KH
234 }
235
b04b65ab
PW
236 od->dev_wakeup_lat += odpl->activate_lat;
237
238 od->pm_lat_level++;
239 }
240
241 return 0;
242}
243
bf1e0776
BC
244static void _add_clkdev(struct omap_device *od, const char *clk_alias,
245 const char *clk_name)
246{
247 struct clk *r;
248 struct clk_lookup *l;
249
250 if (!clk_alias || !clk_name)
251 return;
252
d66b3fe4 253 dev_dbg(&od->pdev->dev, "Creating %s -> %s\n", clk_alias, clk_name);
bf1e0776 254
d66b3fe4 255 r = clk_get_sys(dev_name(&od->pdev->dev), clk_alias);
bf1e0776 256 if (!IS_ERR(r)) {
d66b3fe4 257 dev_warn(&od->pdev->dev,
49882c99 258 "alias %s already exists\n", clk_alias);
bf1e0776
BC
259 clk_put(r);
260 return;
261 }
262
6ea74cb9 263 r = clk_get(NULL, clk_name);
bf1e0776 264 if (IS_ERR(r)) {
d66b3fe4 265 dev_err(&od->pdev->dev,
6ea74cb9 266 "clk_get for %s failed\n", clk_name);
bf1e0776
BC
267 return;
268 }
269
d66b3fe4 270 l = clkdev_alloc(r, clk_alias, dev_name(&od->pdev->dev));
bf1e0776 271 if (!l) {
d66b3fe4 272 dev_err(&od->pdev->dev,
49882c99 273 "clkdev_alloc for %s failed\n", clk_alias);
bf1e0776
BC
274 return;
275 }
276
277 clkdev_add(l);
278}
279
4ef7aca8 280/**
bf1e0776
BC
281 * _add_hwmod_clocks_clkdev - Add clkdev entry for hwmod optional clocks
282 * and main clock
4ef7aca8 283 * @od: struct omap_device *od
bf1e0776 284 * @oh: struct omap_hwmod *oh
4ef7aca8 285 *
bf1e0776
BC
286 * For the main clock and every optional clock present per hwmod per
287 * omap_device, this function adds an entry in the clkdev table of the
288 * form <dev-id=dev_name, con-id=role> if it does not exist already.
4ef7aca8
PB
289 *
290 * The function is called from inside omap_device_build_ss(), after
291 * omap_device_register.
292 *
293 * This allows drivers to get a pointer to its optional clocks based on its role
294 * by calling clk_get(<dev*>, <role>).
bf1e0776 295 * In the case of the main clock, a "fck" alias is used.
4ef7aca8
PB
296 *
297 * No return value.
298 */
bf1e0776
BC
299static void _add_hwmod_clocks_clkdev(struct omap_device *od,
300 struct omap_hwmod *oh)
4ef7aca8
PB
301{
302 int i;
303
bf1e0776 304 _add_clkdev(od, "fck", oh->main_clk);
da0653fe 305
bf1e0776
BC
306 for (i = 0; i < oh->opt_clks_cnt; i++)
307 _add_clkdev(od, oh->opt_clks[i].role, oh->opt_clks[i].clk);
4ef7aca8
PB
308}
309
b04b65ab 310
dc2d07eb
BC
311/**
312 * omap_device_build_from_dt - build an omap_device with multiple hwmods
313 * @pdev_name: name of the platform_device driver to use
314 * @pdev_id: this platform_device's connection ID
315 * @oh: ptr to the single omap_hwmod that backs this omap_device
316 * @pdata: platform_data ptr to associate with the platform_device
317 * @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 *
322 * Function for building an omap_device already registered from device-tree
323 *
324 * Returns 0 or PTR_ERR() on error.
325 */
326static int omap_device_build_from_dt(struct platform_device *pdev)
327{
328 struct omap_hwmod **hwmods;
329 struct omap_device *od;
330 struct omap_hwmod *oh;
331 struct device_node *node = pdev->dev.of_node;
332 const char *oh_name;
333 int oh_cnt, i, ret = 0;
334
335 oh_cnt = of_property_count_strings(node, "ti,hwmods");
336 if (!oh_cnt || IS_ERR_VALUE(oh_cnt)) {
5dc06b7e 337 dev_dbg(&pdev->dev, "No 'hwmods' to build omap_device\n");
dc2d07eb
BC
338 return -ENODEV;
339 }
340
341 hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
342 if (!hwmods) {
343 ret = -ENOMEM;
344 goto odbfd_exit;
345 }
346
347 for (i = 0; i < oh_cnt; i++) {
348 of_property_read_string_index(node, "ti,hwmods", i, &oh_name);
349 oh = omap_hwmod_lookup(oh_name);
350 if (!oh) {
351 dev_err(&pdev->dev, "Cannot lookup hwmod '%s'\n",
352 oh_name);
353 ret = -EINVAL;
354 goto odbfd_exit1;
355 }
356 hwmods[i] = oh;
357 }
358
359 od = omap_device_alloc(pdev, hwmods, oh_cnt, NULL, 0);
360 if (!od) {
361 dev_err(&pdev->dev, "Cannot allocate omap_device for :%s\n",
362 oh_name);
363 ret = PTR_ERR(od);
364 goto odbfd_exit1;
365 }
366
3956a1a0
PU
367 /* Fix up missing resource names */
368 for (i = 0; i < pdev->num_resources; i++) {
369 struct resource *r = &pdev->resource[i];
370
371 if (r->name == NULL)
372 r->name = dev_name(&pdev->dev);
373 }
374
dc2d07eb
BC
375 if (of_get_property(node, "ti,no_idle_on_suspend", NULL))
376 omap_device_disable_idle_on_suspend(pdev);
377
378 pdev->dev.pm_domain = &omap_device_pm_domain;
379
380odbfd_exit1:
381 kfree(hwmods);
382odbfd_exit:
383 return ret;
384}
385
386static int _omap_device_notifier_call(struct notifier_block *nb,
387 unsigned long event, void *dev)
388{
389 struct platform_device *pdev = to_platform_device(dev);
e753345b 390 struct omap_device *od;
dc2d07eb
BC
391
392 switch (event) {
dc2d07eb
BC
393 case BUS_NOTIFY_DEL_DEVICE:
394 if (pdev->archdata.od)
395 omap_device_delete(pdev->archdata.od);
396 break;
e753345b
KH
397 case BUS_NOTIFY_ADD_DEVICE:
398 if (pdev->dev.of_node)
399 omap_device_build_from_dt(pdev);
400 /* fall through */
401 default:
402 od = to_omap_device(pdev);
403 if (od)
404 od->_driver_status = event;
dc2d07eb
BC
405 }
406
407 return NOTIFY_DONE;
408}
409
410
b04b65ab
PW
411/* Public functions for use by core code */
412
c80705aa
KH
413/**
414 * omap_device_get_context_loss_count - get lost context count
415 * @od: struct omap_device *
416 *
417 * Using the primary hwmod, query the context loss count for this
418 * device.
419 *
420 * Callers should consider context for this device lost any time this
421 * function returns a value different than the value the caller got
422 * the last time it called this function.
423 *
424 * If any hwmods exist for the omap_device assoiated with @pdev,
425 * return the context loss counter for that hwmod, otherwise return
426 * zero.
427 */
fc013873 428int omap_device_get_context_loss_count(struct platform_device *pdev)
c80705aa
KH
429{
430 struct omap_device *od;
431 u32 ret = 0;
432
8f0d69de 433 od = to_omap_device(pdev);
c80705aa
KH
434
435 if (od->hwmods_cnt)
436 ret = omap_hwmod_get_context_loss_count(od->hwmods[0]);
437
438 return ret;
439}
440
b04b65ab
PW
441/**
442 * omap_device_count_resources - count number of struct resource entries needed
443 * @od: struct omap_device *
444 *
445 * Count the number of struct resource entries needed for this
446 * omap_device @od. Used by omap_device_build_ss() to determine how
447 * much memory to allocate before calling
448 * omap_device_fill_resources(). Returns the count.
449 */
a2a28ad9 450static int omap_device_count_resources(struct omap_device *od)
b04b65ab 451{
b04b65ab
PW
452 int c = 0;
453 int i;
454
f39f4898
KVA
455 for (i = 0; i < od->hwmods_cnt; i++)
456 c += omap_hwmod_count_resources(od->hwmods[i]);
b04b65ab 457
7852ec05
PW
458 pr_debug("omap_device: %s: counted %d total resources across %d hwmods\n",
459 od->pdev->name, c, od->hwmods_cnt);
b04b65ab
PW
460
461 return c;
462}
463
464/**
465 * omap_device_fill_resources - fill in array of struct resource
466 * @od: struct omap_device *
467 * @res: pointer to an array of struct resource to be filled in
468 *
469 * Populate one or more empty struct resource pointed to by @res with
470 * the resource data for this omap_device @od. Used by
471 * omap_device_build_ss() after calling omap_device_count_resources().
472 * Ideally this function would not be needed at all. If omap_device
473 * replaces platform_device, then we can specify our own
474 * get_resource()/ get_irq()/etc functions that use the underlying
475 * omap_hwmod information. Or if platform_device is extended to use
476 * subarchitecture-specific function pointers, the various
477 * platform_device functions can simply call omap_device internal
478 * functions to get device resources. Hacking around the existing
479 * platform_device code wastes memory. Returns 0.
480 */
a2a28ad9
KH
481static int omap_device_fill_resources(struct omap_device *od,
482 struct resource *res)
b04b65ab 483{
b04b65ab
PW
484 int i, r;
485
f39f4898
KVA
486 for (i = 0; i < od->hwmods_cnt; i++) {
487 r = omap_hwmod_fill_resources(od->hwmods[i], res);
b04b65ab 488 res += r;
b04b65ab
PW
489 }
490
491 return 0;
492}
493
b82b04e8
VH
494/**
495 * _od_fill_dma_resources - fill in array of struct resource with dma resources
496 * @od: struct omap_device *
497 * @res: pointer to an array of struct resource to be filled in
498 *
499 * Populate one or more empty struct resource pointed to by @res with
500 * the dma resource data for this omap_device @od. Used by
501 * omap_device_alloc() after calling omap_device_count_resources().
502 *
503 * Ideally this function would not be needed at all. If we have
504 * mechanism to get dma resources from DT.
505 *
506 * Returns 0.
507 */
508static int _od_fill_dma_resources(struct omap_device *od,
509 struct resource *res)
510{
511 int i, r;
512
513 for (i = 0; i < od->hwmods_cnt; i++) {
514 r = omap_hwmod_fill_dma_resources(od->hwmods[i], res);
515 res += r;
516 }
517
518 return 0;
519}
520
a4f6cdb0
BC
521/**
522 * omap_device_alloc - allocate an omap_device
523 * @pdev: platform_device that will be included in this omap_device
524 * @oh: ptr to the single omap_hwmod that backs this omap_device
525 * @pdata: platform_data ptr to associate with the platform_device
526 * @pdata_len: amount of memory pointed to by @pdata
527 * @pm_lats: pointer to a omap_device_pm_latency array for this device
528 * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
529 *
530 * Convenience function for allocating an omap_device structure and filling
531 * hwmods, resources and pm_latency attributes.
532 *
533 * Returns an struct omap_device pointer or ERR_PTR() on error;
534 */
993e4fbd 535struct omap_device *omap_device_alloc(struct platform_device *pdev,
a4f6cdb0
BC
536 struct omap_hwmod **ohs, int oh_cnt,
537 struct omap_device_pm_latency *pm_lats,
538 int pm_lats_cnt)
539{
540 int ret = -ENOMEM;
541 struct omap_device *od;
542 struct resource *res = NULL;
543 int i, res_count;
544 struct omap_hwmod **hwmods;
545
546 od = kzalloc(sizeof(struct omap_device), GFP_KERNEL);
547 if (!od) {
548 ret = -ENOMEM;
549 goto oda_exit1;
550 }
551 od->hwmods_cnt = oh_cnt;
552
553 hwmods = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
554 if (!hwmods)
555 goto oda_exit2;
556
557 od->hwmods = hwmods;
558 od->pdev = pdev;
559
b82b04e8 560 res_count = omap_device_count_resources(od);
a4f6cdb0 561 /*
b82b04e8
VH
562 * DT Boot:
563 * OF framework will construct the resource structure (currently
564 * does for MEM & IRQ resource) and we should respect/use these
565 * resources, killing hwmod dependency.
566 * If pdev->num_resources > 0, we assume that MEM & IRQ resources
567 * have been allocated by OF layer already (through DTB).
568 *
569 * Non-DT Boot:
570 * Here, pdev->num_resources = 0, and we should get all the
571 * resources from hwmod.
572 *
573 * TODO: Once DMA resource is available from OF layer, we should
574 * kill filling any resources from hwmod.
a4f6cdb0 575 */
b82b04e8
VH
576 if (res_count > pdev->num_resources) {
577 /* Allocate resources memory to account for new resources */
a4f6cdb0
BC
578 res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
579 if (!res)
580 goto oda_exit3;
581
b82b04e8
VH
582 /*
583 * If pdev->num_resources > 0, then assume that,
584 * MEM and IRQ resources will only come from DT and only
585 * fill DMA resource from hwmod layer.
586 */
587 if (pdev->num_resources && pdev->resource) {
588 dev_dbg(&pdev->dev, "%s(): resources already allocated %d\n",
589 __func__, res_count);
590 memcpy(res, pdev->resource,
591 sizeof(struct resource) * pdev->num_resources);
592 _od_fill_dma_resources(od, &res[pdev->num_resources]);
593 } else {
594 dev_dbg(&pdev->dev, "%s(): using resources from hwmod %d\n",
595 __func__, res_count);
596 omap_device_fill_resources(od, res);
597 }
a4f6cdb0
BC
598
599 ret = platform_device_add_resources(pdev, res, res_count);
600 kfree(res);
601
602 if (ret)
603 goto oda_exit3;
604 }
605
606 if (!pm_lats) {
607 pm_lats = omap_default_latency;
608 pm_lats_cnt = ARRAY_SIZE(omap_default_latency);
609 }
610
611 od->pm_lats_cnt = pm_lats_cnt;
612 od->pm_lats = kmemdup(pm_lats,
613 sizeof(struct omap_device_pm_latency) * pm_lats_cnt,
614 GFP_KERNEL);
615 if (!od->pm_lats)
616 goto oda_exit3;
617
618 pdev->archdata.od = od;
619
620 for (i = 0; i < oh_cnt; i++) {
621 hwmods[i]->od = od;
622 _add_hwmod_clocks_clkdev(od, hwmods[i]);
623 }
624
625 return od;
626
627oda_exit3:
628 kfree(hwmods);
629oda_exit2:
630 kfree(od);
631oda_exit1:
632 dev_err(&pdev->dev, "omap_device: build failed (%d)\n", ret);
633
634 return ERR_PTR(ret);
635}
636
993e4fbd 637void omap_device_delete(struct omap_device *od)
a4f6cdb0 638{
dc2d07eb
BC
639 if (!od)
640 return;
641
a4f6cdb0
BC
642 od->pdev->archdata.od = NULL;
643 kfree(od->pm_lats);
644 kfree(od->hwmods);
645 kfree(od);
646}
647
b04b65ab
PW
648/**
649 * omap_device_build - build and register an omap_device with one omap_hwmod
650 * @pdev_name: name of the platform_device driver to use
651 * @pdev_id: this platform_device's connection ID
652 * @oh: ptr to the single omap_hwmod that backs this omap_device
653 * @pdata: platform_data ptr to associate with the platform_device
654 * @pdata_len: amount of memory pointed to by @pdata
655 * @pm_lats: pointer to a omap_device_pm_latency array for this device
656 * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
c23a97d3 657 * @is_early_device: should the device be registered as an early device or not
b04b65ab
PW
658 *
659 * Convenience function for building and registering a single
660 * omap_device record, which in turn builds and registers a
661 * platform_device record. See omap_device_build_ss() for more
662 * information. Returns ERR_PTR(-EINVAL) if @oh is NULL; otherwise,
663 * passes along the return value of omap_device_build_ss().
664 */
9cf793f9 665struct platform_device __init *omap_device_build(const char *pdev_name, int pdev_id,
b04b65ab
PW
666 struct omap_hwmod *oh, void *pdata,
667 int pdata_len,
668 struct omap_device_pm_latency *pm_lats,
c23a97d3 669 int pm_lats_cnt, int is_early_device)
b04b65ab
PW
670{
671 struct omap_hwmod *ohs[] = { oh };
672
673 if (!oh)
674 return ERR_PTR(-EINVAL);
675
676 return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata,
c23a97d3
TG
677 pdata_len, pm_lats, pm_lats_cnt,
678 is_early_device);
b04b65ab
PW
679}
680
681/**
682 * omap_device_build_ss - build and register an omap_device with multiple hwmods
683 * @pdev_name: name of the platform_device driver to use
684 * @pdev_id: this platform_device's connection ID
685 * @oh: ptr to the single omap_hwmod that backs this omap_device
686 * @pdata: platform_data ptr to associate with the platform_device
687 * @pdata_len: amount of memory pointed to by @pdata
688 * @pm_lats: pointer to a omap_device_pm_latency array for this device
689 * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
c23a97d3 690 * @is_early_device: should the device be registered as an early device or not
b04b65ab
PW
691 *
692 * Convenience function for building and registering an omap_device
693 * subsystem record. Subsystem records consist of multiple
694 * omap_hwmods. This function in turn builds and registers a
695 * platform_device record. Returns an ERR_PTR() on error, or passes
696 * along the return value of omap_device_register().
697 */
9cf793f9 698struct platform_device __init *omap_device_build_ss(const char *pdev_name, int pdev_id,
b04b65ab
PW
699 struct omap_hwmod **ohs, int oh_cnt,
700 void *pdata, int pdata_len,
701 struct omap_device_pm_latency *pm_lats,
c23a97d3 702 int pm_lats_cnt, int is_early_device)
b04b65ab
PW
703{
704 int ret = -ENOMEM;
d66b3fe4 705 struct platform_device *pdev;
b04b65ab 706 struct omap_device *od;
b04b65ab
PW
707
708 if (!ohs || oh_cnt == 0 || !pdev_name)
709 return ERR_PTR(-EINVAL);
710
711 if (!pdata && pdata_len > 0)
712 return ERR_PTR(-EINVAL);
713
d66b3fe4
KH
714 pdev = platform_device_alloc(pdev_name, pdev_id);
715 if (!pdev) {
716 ret = -ENOMEM;
717 goto odbs_exit;
718 }
719
a4f6cdb0
BC
720 /* Set the dev_name early to allow dev_xxx in omap_device_alloc */
721 if (pdev->id != -1)
722 dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
723 else
724 dev_set_name(&pdev->dev, "%s", pdev->name);
b04b65ab 725
a4f6cdb0 726 od = omap_device_alloc(pdev, ohs, oh_cnt, pm_lats, pm_lats_cnt);
a87e6628 727 if (IS_ERR(od))
d66b3fe4 728 goto odbs_exit1;
d66b3fe4
KH
729
730 ret = platform_device_add_data(pdev, pdata, pdata_len);
49b368a6 731 if (ret)
a4f6cdb0 732 goto odbs_exit2;
b04b65ab 733
c23a97d3 734 if (is_early_device)
d66b3fe4 735 ret = omap_early_device_register(pdev);
c23a97d3 736 else
d66b3fe4
KH
737 ret = omap_device_register(pdev);
738 if (ret)
a4f6cdb0 739 goto odbs_exit2;
06563581 740
d66b3fe4 741 return pdev;
b04b65ab 742
d66b3fe4 743odbs_exit2:
a4f6cdb0 744 omap_device_delete(od);
d66b3fe4
KH
745odbs_exit1:
746 platform_device_put(pdev);
747odbs_exit:
b04b65ab
PW
748
749 pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret);
750
751 return ERR_PTR(ret);
752}
753
c23a97d3
TG
754/**
755 * omap_early_device_register - register an omap_device as an early platform
756 * device.
757 * @od: struct omap_device * to register
758 *
759 * Register the omap_device structure. This currently just calls
760 * platform_early_add_device() on the underlying platform_device.
761 * Returns 0 by default.
762 */
9cf793f9 763static int __init omap_early_device_register(struct platform_device *pdev)
c23a97d3
TG
764{
765 struct platform_device *devices[1];
766
bfae4f8f 767 devices[0] = pdev;
c23a97d3
TG
768 early_platform_add_devices(devices, 1);
769 return 0;
770}
771
256a5435 772#ifdef CONFIG_PM_RUNTIME
638080c3
KH
773static int _od_runtime_suspend(struct device *dev)
774{
775 struct platform_device *pdev = to_platform_device(dev);
345f79b3 776 int ret;
638080c3 777
345f79b3
KH
778 ret = pm_generic_runtime_suspend(dev);
779
780 if (!ret)
781 omap_device_idle(pdev);
782
783 return ret;
784}
785
786static int _od_runtime_idle(struct device *dev)
787{
788 return pm_generic_runtime_idle(dev);
638080c3
KH
789}
790
791static int _od_runtime_resume(struct device *dev)
792{
793 struct platform_device *pdev = to_platform_device(dev);
794
345f79b3
KH
795 omap_device_enable(pdev);
796
797 return pm_generic_runtime_resume(dev);
638080c3 798}
256a5435 799#endif
638080c3 800
c03f007a
KH
801#ifdef CONFIG_SUSPEND
802static int _od_suspend_noirq(struct device *dev)
803{
804 struct platform_device *pdev = to_platform_device(dev);
805 struct omap_device *od = to_omap_device(pdev);
806 int ret;
807
72bb6f9b
KH
808 /* Don't attempt late suspend on a driver that is not bound */
809 if (od->_driver_status != BUS_NOTIFY_BOUND_DRIVER)
810 return 0;
811
c03f007a
KH
812 ret = pm_generic_suspend_noirq(dev);
813
814 if (!ret && !pm_runtime_status_suspended(dev)) {
815 if (pm_generic_runtime_suspend(dev) == 0) {
b7c39a3f
PW
816 if (!(od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND))
817 omap_device_idle(pdev);
c03f007a
KH
818 od->flags |= OMAP_DEVICE_SUSPENDED;
819 }
820 }
821
822 return ret;
823}
824
825static int _od_resume_noirq(struct device *dev)
826{
827 struct platform_device *pdev = to_platform_device(dev);
828 struct omap_device *od = to_omap_device(pdev);
829
830 if ((od->flags & OMAP_DEVICE_SUSPENDED) &&
831 !pm_runtime_status_suspended(dev)) {
832 od->flags &= ~OMAP_DEVICE_SUSPENDED;
b7c39a3f
PW
833 if (!(od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND))
834 omap_device_enable(pdev);
c03f007a
KH
835 pm_generic_runtime_resume(dev);
836 }
837
838 return pm_generic_resume_noirq(dev);
839}
126caf13
KH
840#else
841#define _od_suspend_noirq NULL
842#define _od_resume_noirq NULL
c03f007a
KH
843#endif
844
3ec2decb 845struct dev_pm_domain omap_device_pm_domain = {
638080c3 846 .ops = {
256a5435
KH
847 SET_RUNTIME_PM_OPS(_od_runtime_suspend, _od_runtime_resume,
848 _od_runtime_idle)
638080c3 849 USE_PLATFORM_PM_SLEEP_OPS
ff35336d
KH
850 .suspend_noirq = _od_suspend_noirq,
851 .resume_noirq = _od_resume_noirq,
638080c3
KH
852 }
853};
854
b04b65ab
PW
855/**
856 * omap_device_register - register an omap_device with one omap_hwmod
857 * @od: struct omap_device * to register
858 *
859 * Register the omap_device structure. This currently just calls
860 * platform_device_register() on the underlying platform_device.
861 * Returns the return value of platform_device_register().
862 */
993e4fbd 863int omap_device_register(struct platform_device *pdev)
b04b65ab 864{
bfae4f8f 865 pr_debug("omap_device: %s: registering\n", pdev->name);
b04b65ab 866
bfae4f8f 867 pdev->dev.pm_domain = &omap_device_pm_domain;
d66b3fe4 868 return platform_device_add(pdev);
b04b65ab
PW
869}
870
871
872/* Public functions for use by device drivers through struct platform_data */
873
874/**
875 * omap_device_enable - fully activate an omap_device
876 * @od: struct omap_device * to activate
877 *
878 * Do whatever is necessary for the hwmods underlying omap_device @od
879 * to be accessible and ready to operate. This generally involves
880 * enabling clocks, setting SYSCONFIG registers; and in the future may
881 * involve remuxing pins. Device drivers should call this function
882 * (through platform_data function pointers) where they would normally
883 * enable clocks, etc. Returns -EINVAL if called when the omap_device
884 * is already enabled, or passes along the return value of
885 * _omap_device_activate().
886 */
887int omap_device_enable(struct platform_device *pdev)
888{
889 int ret;
890 struct omap_device *od;
891
8f0d69de 892 od = to_omap_device(pdev);
b04b65ab
PW
893
894 if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
49882c99
KH
895 dev_warn(&pdev->dev,
896 "omap_device: %s() called from invalid state %d\n",
897 __func__, od->_state);
b04b65ab
PW
898 return -EINVAL;
899 }
900
901 /* Enable everything if we're enabling this device from scratch */
902 if (od->_state == OMAP_DEVICE_STATE_UNKNOWN)
903 od->pm_lat_level = od->pm_lats_cnt;
904
905 ret = _omap_device_activate(od, IGNORE_WAKEUP_LAT);
906
907 od->dev_wakeup_lat = 0;
5f1b6ef7 908 od->_dev_wakeup_lat_limit = UINT_MAX;
b04b65ab
PW
909 od->_state = OMAP_DEVICE_STATE_ENABLED;
910
911 return ret;
912}
913
914/**
915 * omap_device_idle - idle an omap_device
916 * @od: struct omap_device * to idle
917 *
918 * Idle omap_device @od by calling as many .deactivate_func() entries
919 * in the omap_device's pm_lats table as is possible without exceeding
920 * the device's maximum wakeup latency limit, pm_lat_limit. Device
921 * drivers should call this function (through platform_data function
922 * pointers) where they would normally disable clocks after operations
923 * complete, etc.. Returns -EINVAL if the omap_device is not
924 * currently enabled, or passes along the return value of
925 * _omap_device_deactivate().
926 */
927int omap_device_idle(struct platform_device *pdev)
928{
929 int ret;
930 struct omap_device *od;
931
8f0d69de 932 od = to_omap_device(pdev);
b04b65ab
PW
933
934 if (od->_state != OMAP_DEVICE_STATE_ENABLED) {
49882c99
KH
935 dev_warn(&pdev->dev,
936 "omap_device: %s() called from invalid state %d\n",
937 __func__, od->_state);
b04b65ab
PW
938 return -EINVAL;
939 }
940
941 ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
942
943 od->_state = OMAP_DEVICE_STATE_IDLE;
944
945 return ret;
946}
947
948/**
949 * omap_device_shutdown - shut down an omap_device
950 * @od: struct omap_device * to shut down
951 *
952 * Shut down omap_device @od by calling all .deactivate_func() entries
953 * in the omap_device's pm_lats table and then shutting down all of
954 * the underlying omap_hwmods. Used when a device is being "removed"
955 * or a device driver is being unloaded. Returns -EINVAL if the
956 * omap_device is not currently enabled or idle, or passes along the
957 * return value of _omap_device_deactivate().
958 */
959int omap_device_shutdown(struct platform_device *pdev)
960{
961 int ret, i;
962 struct omap_device *od;
b04b65ab 963
8f0d69de 964 od = to_omap_device(pdev);
b04b65ab
PW
965
966 if (od->_state != OMAP_DEVICE_STATE_ENABLED &&
967 od->_state != OMAP_DEVICE_STATE_IDLE) {
49882c99
KH
968 dev_warn(&pdev->dev,
969 "omap_device: %s() called from invalid state %d\n",
970 __func__, od->_state);
b04b65ab
PW
971 return -EINVAL;
972 }
973
974 ret = _omap_device_deactivate(od, IGNORE_WAKEUP_LAT);
975
f39f4898
KVA
976 for (i = 0; i < od->hwmods_cnt; i++)
977 omap_hwmod_shutdown(od->hwmods[i]);
b04b65ab
PW
978
979 od->_state = OMAP_DEVICE_STATE_SHUTDOWN;
980
981 return ret;
982}
983
8bb9fde2
ORL
984/**
985 * omap_device_assert_hardreset - set a device's hardreset line
986 * @pdev: struct platform_device * to reset
987 * @name: const char * name of the reset line
988 *
989 * Set the hardreset line identified by @name on the IP blocks
990 * associated with the hwmods backing the platform_device @pdev. All
991 * of the hwmods associated with @pdev must have the same hardreset
992 * line linked to them for this to work. Passes along the return value
993 * of omap_hwmod_assert_hardreset() in the event of any failure, or
994 * returns 0 upon success.
995 */
996int omap_device_assert_hardreset(struct platform_device *pdev, const char *name)
997{
998 struct omap_device *od = to_omap_device(pdev);
999 int ret = 0;
1000 int i;
1001
1002 for (i = 0; i < od->hwmods_cnt; i++) {
1003 ret = omap_hwmod_assert_hardreset(od->hwmods[i], name);
1004 if (ret)
1005 break;
1006 }
1007
1008 return ret;
1009}
1010
1011/**
1012 * omap_device_deassert_hardreset - release a device's hardreset line
1013 * @pdev: struct platform_device * to reset
1014 * @name: const char * name of the reset line
1015 *
1016 * Release the hardreset line identified by @name on the IP blocks
1017 * associated with the hwmods backing the platform_device @pdev. All
1018 * of the hwmods associated with @pdev must have the same hardreset
1019 * line linked to them for this to work. Passes along the return
1020 * value of omap_hwmod_deassert_hardreset() in the event of any
1021 * failure, or returns 0 upon success.
1022 */
1023int omap_device_deassert_hardreset(struct platform_device *pdev,
1024 const char *name)
1025{
1026 struct omap_device *od = to_omap_device(pdev);
1027 int ret = 0;
1028 int i;
1029
1030 for (i = 0; i < od->hwmods_cnt; i++) {
1031 ret = omap_hwmod_deassert_hardreset(od->hwmods[i], name);
1032 if (ret)
1033 break;
1034 }
1035
1036 return ret;
1037}
1038
b04b65ab
PW
1039/**
1040 * omap_device_align_pm_lat - activate/deactivate device to match wakeup lat lim
1041 * @od: struct omap_device *
1042 *
1043 * When a device's maximum wakeup latency limit changes, call some of
1044 * the .activate_func or .deactivate_func function pointers in the
1045 * omap_device's pm_lats array to ensure that the device's maximum
1046 * wakeup latency is less than or equal to the new latency limit.
1047 * Intended to be called by OMAP PM code whenever a device's maximum
1048 * wakeup latency limit changes (e.g., via
1049 * omap_pm_set_dev_wakeup_lat()). Returns 0 if nothing needs to be
1050 * done (e.g., if the omap_device is not currently idle, or if the
1051 * wakeup latency is already current with the new limit) or passes
1052 * along the return value of _omap_device_deactivate() or
1053 * _omap_device_activate().
1054 */
1055int omap_device_align_pm_lat(struct platform_device *pdev,
1056 u32 new_wakeup_lat_limit)
1057{
1058 int ret = -EINVAL;
1059 struct omap_device *od;
1060
8f0d69de 1061 od = to_omap_device(pdev);
b04b65ab
PW
1062
1063 if (new_wakeup_lat_limit == od->dev_wakeup_lat)
1064 return 0;
1065
1066 od->_dev_wakeup_lat_limit = new_wakeup_lat_limit;
1067
1068 if (od->_state != OMAP_DEVICE_STATE_IDLE)
1069 return 0;
1070 else if (new_wakeup_lat_limit > od->dev_wakeup_lat)
1071 ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
1072 else if (new_wakeup_lat_limit < od->dev_wakeup_lat)
1073 ret = _omap_device_activate(od, USE_WAKEUP_LAT);
1074
1075 return ret;
1076}
1077
1078/**
1079 * omap_device_get_pwrdm - return the powerdomain * associated with @od
1080 * @od: struct omap_device *
1081 *
1082 * Return the powerdomain associated with the first underlying
1083 * omap_hwmod for this omap_device. Intended for use by core OMAP PM
1084 * code. Returns NULL on error or a struct powerdomain * upon
1085 * success.
1086 */
1087struct powerdomain *omap_device_get_pwrdm(struct omap_device *od)
1088{
1089 /*
1090 * XXX Assumes that all omap_hwmod powerdomains are identical.
1091 * This may not necessarily be true. There should be a sanity
1092 * check in here to WARN() if any difference appears.
1093 */
1094 if (!od->hwmods_cnt)
1095 return NULL;
1096
1097 return omap_hwmod_get_pwrdm(od->hwmods[0]);
1098}
1099
db2a60bf
PW
1100/**
1101 * omap_device_get_mpu_rt_va - return the MPU's virtual addr for the hwmod base
1102 * @od: struct omap_device *
1103 *
1104 * Return the MPU's virtual address for the base of the hwmod, from
1105 * the ioremap() that the hwmod code does. Only valid if there is one
1106 * hwmod associated with this device. Returns NULL if there are zero
1107 * or more than one hwmods associated with this omap_device;
1108 * otherwise, passes along the return value from
1109 * omap_hwmod_get_mpu_rt_va().
1110 */
1111void __iomem *omap_device_get_rt_va(struct omap_device *od)
1112{
1113 if (od->hwmods_cnt != 1)
1114 return NULL;
1115
1116 return omap_hwmod_get_mpu_rt_va(od->hwmods[0]);
1117}
1118
1f8a7d52
NM
1119/**
1120 * omap_device_get_by_hwmod_name() - convert a hwmod name to
1121 * device pointer.
1122 * @oh_name: name of the hwmod device
1123 *
1124 * Returns back a struct device * pointer associated with a hwmod
1125 * device represented by a hwmod_name
1126 */
1127struct device *omap_device_get_by_hwmod_name(const char *oh_name)
1128{
1129 struct omap_hwmod *oh;
1130
1131 if (!oh_name) {
1132 WARN(1, "%s: no hwmod name!\n", __func__);
1133 return ERR_PTR(-EINVAL);
1134 }
1135
1136 oh = omap_hwmod_lookup(oh_name);
1137 if (IS_ERR_OR_NULL(oh)) {
1138 WARN(1, "%s: no hwmod for %s\n", __func__,
1139 oh_name);
1140 return ERR_PTR(oh ? PTR_ERR(oh) : -ENODEV);
1141 }
1142 if (IS_ERR_OR_NULL(oh->od)) {
1143 WARN(1, "%s: no omap_device for %s\n", __func__,
1144 oh_name);
1145 return ERR_PTR(oh->od ? PTR_ERR(oh->od) : -ENODEV);
1146 }
1147
1148 if (IS_ERR_OR_NULL(oh->od->pdev))
1149 return ERR_PTR(oh->od->pdev ? PTR_ERR(oh->od->pdev) : -ENODEV);
1150
1151 return &oh->od->pdev->dev;
1152}
1153EXPORT_SYMBOL(omap_device_get_by_hwmod_name);
1154
b04b65ab
PW
1155/*
1156 * Public functions intended for use in omap_device_pm_latency
1157 * .activate_func and .deactivate_func function pointers
1158 */
1159
1160/**
1161 * omap_device_enable_hwmods - call omap_hwmod_enable() on all hwmods
1162 * @od: struct omap_device *od
1163 *
1164 * Enable all underlying hwmods. Returns 0.
1165 */
1166int omap_device_enable_hwmods(struct omap_device *od)
1167{
b04b65ab
PW
1168 int i;
1169
f39f4898
KVA
1170 for (i = 0; i < od->hwmods_cnt; i++)
1171 omap_hwmod_enable(od->hwmods[i]);
b04b65ab
PW
1172
1173 /* XXX pass along return value here? */
1174 return 0;
1175}
1176
1177/**
1178 * omap_device_idle_hwmods - call omap_hwmod_idle() on all hwmods
1179 * @od: struct omap_device *od
1180 *
1181 * Idle all underlying hwmods. Returns 0.
1182 */
1183int omap_device_idle_hwmods(struct omap_device *od)
1184{
b04b65ab
PW
1185 int i;
1186
f39f4898
KVA
1187 for (i = 0; i < od->hwmods_cnt; i++)
1188 omap_hwmod_idle(od->hwmods[i]);
b04b65ab
PW
1189
1190 /* XXX pass along return value here? */
1191 return 0;
1192}
1193
1194/**
1195 * omap_device_disable_clocks - disable all main and interface clocks
1196 * @od: struct omap_device *od
1197 *
1198 * Disable the main functional clock and interface clock for all of the
1199 * omap_hwmods associated with the omap_device. Returns 0.
1200 */
1201int omap_device_disable_clocks(struct omap_device *od)
1202{
b04b65ab
PW
1203 int i;
1204
f39f4898
KVA
1205 for (i = 0; i < od->hwmods_cnt; i++)
1206 omap_hwmod_disable_clocks(od->hwmods[i]);
b04b65ab
PW
1207
1208 /* XXX pass along return value here? */
1209 return 0;
1210}
1211
1212/**
1213 * omap_device_enable_clocks - enable all main and interface clocks
1214 * @od: struct omap_device *od
1215 *
1216 * Enable the main functional clock and interface clock for all of the
1217 * omap_hwmods associated with the omap_device. Returns 0.
1218 */
1219int omap_device_enable_clocks(struct omap_device *od)
1220{
b04b65ab
PW
1221 int i;
1222
f39f4898
KVA
1223 for (i = 0; i < od->hwmods_cnt; i++)
1224 omap_hwmod_enable_clocks(od->hwmods[i]);
b04b65ab
PW
1225
1226 /* XXX pass along return value here? */
1227 return 0;
1228}
0d5e8252 1229
dc2d07eb
BC
1230static struct notifier_block platform_nb = {
1231 .notifier_call = _omap_device_notifier_call,
1232};
1233
0d5e8252
KH
1234static int __init omap_device_init(void)
1235{
dc2d07eb 1236 bus_register_notifier(&platform_bus_type, &platform_nb);
3ec2decb 1237 return 0;
0d5e8252
KH
1238}
1239core_initcall(omap_device_init);
9634c8dd
KH
1240
1241/**
1242 * omap_device_late_idle - idle devices without drivers
1243 * @dev: struct device * associated with omap_device
1244 * @data: unused
1245 *
1246 * Check the driver bound status of this device, and idle it
1247 * if there is no driver attached.
1248 */
1249static int __init omap_device_late_idle(struct device *dev, void *data)
1250{
1251 struct platform_device *pdev = to_platform_device(dev);
1252 struct omap_device *od = to_omap_device(pdev);
1253
1254 if (!od)
1255 return 0;
1256
1257 /*
1258 * If omap_device state is enabled, but has no driver bound,
1259 * idle it.
1260 */
1261 if (od->_driver_status != BUS_NOTIFY_BOUND_DRIVER) {
1262 if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
1263 dev_warn(dev, "%s: enabled but no driver. Idling\n",
1264 __func__);
1265 omap_device_idle(pdev);
1266 }
1267 }
1268
1269 return 0;
1270}
1271
1272static int __init omap_device_late_init(void)
1273{
1274 bus_for_each_dev(&platform_bus_type, NULL, NULL, omap_device_late_idle);
1275 return 0;
1276}
1277late_initcall(omap_device_late_init);
This page took 0.265875 seconds and 5 git commands to generate.