aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/plat-omap/omap_device.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/plat-omap/omap_device.c')
-rw-r--r--arch/arm/plat-omap/omap_device.c450
1 files changed, 336 insertions, 114 deletions
diff --git a/arch/arm/plat-omap/omap_device.c b/arch/arm/plat-omap/omap_device.c
index 02609eee0562..cd90bedd9306 100644
--- a/arch/arm/plat-omap/omap_device.c
+++ b/arch/arm/plat-omap/omap_device.c
@@ -85,6 +85,8 @@
85#include <linux/clk.h> 85#include <linux/clk.h>
86#include <linux/clkdev.h> 86#include <linux/clkdev.h>
87#include <linux/pm_runtime.h> 87#include <linux/pm_runtime.h>
88#include <linux/of.h>
89#include <linux/notifier.h>
88 90
89#include <plat/omap_device.h> 91#include <plat/omap_device.h>
90#include <plat/omap_hwmod.h> 92#include <plat/omap_hwmod.h>
@@ -94,6 +96,23 @@
94#define USE_WAKEUP_LAT 0 96#define USE_WAKEUP_LAT 0
95#define IGNORE_WAKEUP_LAT 1 97#define IGNORE_WAKEUP_LAT 1
96 98
99static int omap_device_register(struct platform_device *pdev);
100static int omap_early_device_register(struct platform_device *pdev);
101static struct omap_device *omap_device_alloc(struct platform_device *pdev,
102 struct omap_hwmod **ohs, int oh_cnt,
103 struct omap_device_pm_latency *pm_lats,
104 int pm_lats_cnt);
105static void omap_device_delete(struct omap_device *od);
106
107
108static struct omap_device_pm_latency omap_default_latency[] = {
109 {
110 .deactivate_func = omap_device_idle_hwmods,
111 .activate_func = omap_device_enable_hwmods,
112 .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
113 }
114};
115
97/* Private functions */ 116/* Private functions */
98 117
99/** 118/**
@@ -114,7 +133,7 @@ static int _omap_device_activate(struct omap_device *od, u8 ignore_lat)
114{ 133{
115 struct timespec a, b, c; 134 struct timespec a, b, c;
116 135
117 pr_debug("omap_device: %s: activating\n", od->pdev.name); 136 dev_dbg(&od->pdev->dev, "omap_device: activating\n");
118 137
119 while (od->pm_lat_level > 0) { 138 while (od->pm_lat_level > 0) {
120 struct omap_device_pm_latency *odpl; 139 struct omap_device_pm_latency *odpl;
@@ -138,25 +157,24 @@ static int _omap_device_activate(struct omap_device *od, u8 ignore_lat)
138 c = timespec_sub(b, a); 157 c = timespec_sub(b, a);
139 act_lat = timespec_to_ns(&c); 158 act_lat = timespec_to_ns(&c);
140 159
141 pr_debug("omap_device: %s: pm_lat %d: activate: elapsed time " 160 dev_dbg(&od->pdev->dev,
142 "%llu nsec\n", od->pdev.name, od->pm_lat_level, 161 "omap_device: pm_lat %d: activate: elapsed time "
143 act_lat); 162 "%llu nsec\n", od->pm_lat_level, act_lat);
144 163
145 if (act_lat > odpl->activate_lat) { 164 if (act_lat > odpl->activate_lat) {
146 odpl->activate_lat_worst = act_lat; 165 odpl->activate_lat_worst = act_lat;
147 if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) { 166 if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
148 odpl->activate_lat = act_lat; 167 odpl->activate_lat = act_lat;
149 pr_warning("omap_device: %s.%d: new worst case " 168 dev_dbg(&od->pdev->dev,
150 "activate latency %d: %llu\n", 169 "new worst case activate latency "
151 od->pdev.name, od->pdev.id, 170 "%d: %llu\n",
152 od->pm_lat_level, act_lat); 171 od->pm_lat_level, act_lat);
153 } else 172 } else
154 pr_warning("omap_device: %s.%d: activate " 173 dev_warn(&od->pdev->dev,
155 "latency %d higher than exptected. " 174 "activate latency %d "
156 "(%llu > %d)\n", 175 "higher than exptected. (%llu > %d)\n",
157 od->pdev.name, od->pdev.id, 176 od->pm_lat_level, act_lat,
158 od->pm_lat_level, act_lat, 177 odpl->activate_lat);
159 odpl->activate_lat);
160 } 178 }
161 179
162 od->dev_wakeup_lat -= odpl->activate_lat; 180 od->dev_wakeup_lat -= odpl->activate_lat;
@@ -183,7 +201,7 @@ static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat)
183{ 201{
184 struct timespec a, b, c; 202 struct timespec a, b, c;
185 203
186 pr_debug("omap_device: %s: deactivating\n", od->pdev.name); 204 dev_dbg(&od->pdev->dev, "omap_device: deactivating\n");
187 205
188 while (od->pm_lat_level < od->pm_lats_cnt) { 206 while (od->pm_lat_level < od->pm_lats_cnt) {
189 struct omap_device_pm_latency *odpl; 207 struct omap_device_pm_latency *odpl;
@@ -206,28 +224,26 @@ static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat)
206 c = timespec_sub(b, a); 224 c = timespec_sub(b, a);
207 deact_lat = timespec_to_ns(&c); 225 deact_lat = timespec_to_ns(&c);
208 226
209 pr_debug("omap_device: %s: pm_lat %d: deactivate: elapsed time " 227 dev_dbg(&od->pdev->dev,
210 "%llu nsec\n", od->pdev.name, od->pm_lat_level, 228 "omap_device: pm_lat %d: deactivate: elapsed time "
211 deact_lat); 229 "%llu nsec\n", od->pm_lat_level, deact_lat);
212 230
213 if (deact_lat > odpl->deactivate_lat) { 231 if (deact_lat > odpl->deactivate_lat) {
214 odpl->deactivate_lat_worst = deact_lat; 232 odpl->deactivate_lat_worst = deact_lat;
215 if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) { 233 if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
216 odpl->deactivate_lat = deact_lat; 234 odpl->deactivate_lat = deact_lat;
217 pr_warning("omap_device: %s.%d: new worst case " 235 dev_dbg(&od->pdev->dev,
218 "deactivate latency %d: %llu\n", 236 "new worst case deactivate latency "
219 od->pdev.name, od->pdev.id, 237 "%d: %llu\n",
220 od->pm_lat_level, deact_lat); 238 od->pm_lat_level, deact_lat);
221 } else 239 } else
222 pr_warning("omap_device: %s.%d: deactivate " 240 dev_warn(&od->pdev->dev,
223 "latency %d higher than exptected. " 241 "deactivate latency %d "
224 "(%llu > %d)\n", 242 "higher than exptected. (%llu > %d)\n",
225 od->pdev.name, od->pdev.id, 243 od->pm_lat_level, deact_lat,
226 od->pm_lat_level, deact_lat, 244 odpl->deactivate_lat);
227 odpl->deactivate_lat);
228 } 245 }
229 246
230
231 od->dev_wakeup_lat += odpl->activate_lat; 247 od->dev_wakeup_lat += odpl->activate_lat;
232 248
233 od->pm_lat_level++; 249 od->pm_lat_level++;
@@ -245,28 +261,27 @@ static void _add_clkdev(struct omap_device *od, const char *clk_alias,
245 if (!clk_alias || !clk_name) 261 if (!clk_alias || !clk_name)
246 return; 262 return;
247 263
248 pr_debug("omap_device: %s: Creating %s -> %s\n", 264 dev_dbg(&od->pdev->dev, "Creating %s -> %s\n", clk_alias, clk_name);
249 dev_name(&od->pdev.dev), clk_alias, clk_name);
250 265
251 r = clk_get_sys(dev_name(&od->pdev.dev), clk_alias); 266 r = clk_get_sys(dev_name(&od->pdev->dev), clk_alias);
252 if (!IS_ERR(r)) { 267 if (!IS_ERR(r)) {
253 pr_warning("omap_device: %s: alias %s already exists\n", 268 dev_warn(&od->pdev->dev,
254 dev_name(&od->pdev.dev), clk_alias); 269 "alias %s already exists\n", clk_alias);
255 clk_put(r); 270 clk_put(r);
256 return; 271 return;
257 } 272 }
258 273
259 r = omap_clk_get_by_name(clk_name); 274 r = omap_clk_get_by_name(clk_name);
260 if (IS_ERR(r)) { 275 if (IS_ERR(r)) {
261 pr_err("omap_device: %s: omap_clk_get_by_name for %s failed\n", 276 dev_err(&od->pdev->dev,
262 dev_name(&od->pdev.dev), clk_name); 277 "omap_clk_get_by_name for %s failed\n", clk_name);
263 return; 278 return;
264 } 279 }
265 280
266 l = clkdev_alloc(r, clk_alias, dev_name(&od->pdev.dev)); 281 l = clkdev_alloc(r, clk_alias, dev_name(&od->pdev->dev));
267 if (!l) { 282 if (!l) {
268 pr_err("omap_device: %s: clkdev_alloc for %s failed\n", 283 dev_err(&od->pdev->dev,
269 dev_name(&od->pdev.dev), clk_alias); 284 "clkdev_alloc for %s failed\n", clk_alias);
270 return; 285 return;
271 } 286 }
272 287
@@ -304,6 +319,96 @@ static void _add_hwmod_clocks_clkdev(struct omap_device *od,
304} 319}
305 320
306 321
322static struct dev_pm_domain omap_device_pm_domain;
323
324/**
325 * omap_device_build_from_dt - build an omap_device with multiple hwmods
326 * @pdev_name: name of the platform_device driver to use
327 * @pdev_id: this platform_device's connection ID
328 * @oh: ptr to the single omap_hwmod that backs this omap_device
329 * @pdata: platform_data ptr to associate with the platform_device
330 * @pdata_len: amount of memory pointed to by @pdata
331 * @pm_lats: pointer to a omap_device_pm_latency array for this device
332 * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
333 * @is_early_device: should the device be registered as an early device or not
334 *
335 * Function for building an omap_device already registered from device-tree
336 *
337 * Returns 0 or PTR_ERR() on error.
338 */
339static int omap_device_build_from_dt(struct platform_device *pdev)
340{
341 struct omap_hwmod **hwmods;
342 struct omap_device *od;
343 struct omap_hwmod *oh;
344 struct device_node *node = pdev->dev.of_node;
345 const char *oh_name;
346 int oh_cnt, i, ret = 0;
347
348 oh_cnt = of_property_count_strings(node, "ti,hwmods");
349 if (!oh_cnt || IS_ERR_VALUE(oh_cnt)) {
350 dev_warn(&pdev->dev, "No 'hwmods' to build omap_device\n");
351 return -ENODEV;
352 }
353
354 hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
355 if (!hwmods) {
356 ret = -ENOMEM;
357 goto odbfd_exit;
358 }
359
360 for (i = 0; i < oh_cnt; i++) {
361 of_property_read_string_index(node, "ti,hwmods", i, &oh_name);
362 oh = omap_hwmod_lookup(oh_name);
363 if (!oh) {
364 dev_err(&pdev->dev, "Cannot lookup hwmod '%s'\n",
365 oh_name);
366 ret = -EINVAL;
367 goto odbfd_exit1;
368 }
369 hwmods[i] = oh;
370 }
371
372 od = omap_device_alloc(pdev, hwmods, oh_cnt, NULL, 0);
373 if (!od) {
374 dev_err(&pdev->dev, "Cannot allocate omap_device for :%s\n",
375 oh_name);
376 ret = PTR_ERR(od);
377 goto odbfd_exit1;
378 }
379
380 if (of_get_property(node, "ti,no_idle_on_suspend", NULL))
381 omap_device_disable_idle_on_suspend(pdev);
382
383 pdev->dev.pm_domain = &omap_device_pm_domain;
384
385odbfd_exit1:
386 kfree(hwmods);
387odbfd_exit:
388 return ret;
389}
390
391static int _omap_device_notifier_call(struct notifier_block *nb,
392 unsigned long event, void *dev)
393{
394 struct platform_device *pdev = to_platform_device(dev);
395
396 switch (event) {
397 case BUS_NOTIFY_ADD_DEVICE:
398 if (pdev->dev.of_node)
399 omap_device_build_from_dt(pdev);
400 break;
401
402 case BUS_NOTIFY_DEL_DEVICE:
403 if (pdev->archdata.od)
404 omap_device_delete(pdev->archdata.od);
405 break;
406 }
407
408 return NOTIFY_DONE;
409}
410
411
307/* Public functions for use by core code */ 412/* Public functions for use by core code */
308 413
309/** 414/**
@@ -343,7 +448,7 @@ u32 omap_device_get_context_loss_count(struct platform_device *pdev)
343 * much memory to allocate before calling 448 * much memory to allocate before calling
344 * omap_device_fill_resources(). Returns the count. 449 * omap_device_fill_resources(). Returns the count.
345 */ 450 */
346int omap_device_count_resources(struct omap_device *od) 451static int omap_device_count_resources(struct omap_device *od)
347{ 452{
348 int c = 0; 453 int c = 0;
349 int i; 454 int i;
@@ -352,7 +457,7 @@ int omap_device_count_resources(struct omap_device *od)
352 c += omap_hwmod_count_resources(od->hwmods[i]); 457 c += omap_hwmod_count_resources(od->hwmods[i]);
353 458
354 pr_debug("omap_device: %s: counted %d total resources across %d " 459 pr_debug("omap_device: %s: counted %d total resources across %d "
355 "hwmods\n", od->pdev.name, c, od->hwmods_cnt); 460 "hwmods\n", od->pdev->name, c, od->hwmods_cnt);
356 461
357 return c; 462 return c;
358} 463}
@@ -374,7 +479,8 @@ int omap_device_count_resources(struct omap_device *od)
374 * functions to get device resources. Hacking around the existing 479 * functions to get device resources. Hacking around the existing
375 * platform_device code wastes memory. Returns 0. 480 * platform_device code wastes memory. Returns 0.
376 */ 481 */
377int omap_device_fill_resources(struct omap_device *od, struct resource *res) 482static int omap_device_fill_resources(struct omap_device *od,
483 struct resource *res)
378{ 484{
379 int c = 0; 485 int c = 0;
380 int i, r; 486 int i, r;
@@ -389,6 +495,113 @@ int omap_device_fill_resources(struct omap_device *od, struct resource *res)
389} 495}
390 496
391/** 497/**
498 * omap_device_alloc - allocate an omap_device
499 * @pdev: platform_device that will be included in this omap_device
500 * @oh: ptr to the single omap_hwmod that backs this omap_device
501 * @pdata: platform_data ptr to associate with the platform_device
502 * @pdata_len: amount of memory pointed to by @pdata
503 * @pm_lats: pointer to a omap_device_pm_latency array for this device
504 * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
505 *
506 * Convenience function for allocating an omap_device structure and filling
507 * hwmods, resources and pm_latency attributes.
508 *
509 * Returns an struct omap_device pointer or ERR_PTR() on error;
510 */
511static struct omap_device *omap_device_alloc(struct platform_device *pdev,
512 struct omap_hwmod **ohs, int oh_cnt,
513 struct omap_device_pm_latency *pm_lats,
514 int pm_lats_cnt)
515{
516 int ret = -ENOMEM;
517 struct omap_device *od;
518 struct resource *res = NULL;
519 int i, res_count;
520 struct omap_hwmod **hwmods;
521
522 od = kzalloc(sizeof(struct omap_device), GFP_KERNEL);
523 if (!od) {
524 ret = -ENOMEM;
525 goto oda_exit1;
526 }
527 od->hwmods_cnt = oh_cnt;
528
529 hwmods = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
530 if (!hwmods)
531 goto oda_exit2;
532
533 od->hwmods = hwmods;
534 od->pdev = pdev;
535
536 /*
537 * HACK: Ideally the resources from DT should match, and hwmod
538 * should just add the missing ones. Since the name is not
539 * properly populated by DT, stick to hwmod resources only.
540 */
541 if (pdev->num_resources && pdev->resource)
542 dev_warn(&pdev->dev, "%s(): resources already allocated %d\n",
543 __func__, pdev->num_resources);
544
545 res_count = omap_device_count_resources(od);
546 if (res_count > 0) {
547 dev_dbg(&pdev->dev, "%s(): resources allocated from hwmod %d\n",
548 __func__, res_count);
549 res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
550 if (!res)
551 goto oda_exit3;
552
553 omap_device_fill_resources(od, res);
554
555 ret = platform_device_add_resources(pdev, res, res_count);
556 kfree(res);
557
558 if (ret)
559 goto oda_exit3;
560 }
561
562 if (!pm_lats) {
563 pm_lats = omap_default_latency;
564 pm_lats_cnt = ARRAY_SIZE(omap_default_latency);
565 }
566
567 od->pm_lats_cnt = pm_lats_cnt;
568 od->pm_lats = kmemdup(pm_lats,
569 sizeof(struct omap_device_pm_latency) * pm_lats_cnt,
570 GFP_KERNEL);
571 if (!od->pm_lats)
572 goto oda_exit3;
573
574 pdev->archdata.od = od;
575
576 for (i = 0; i < oh_cnt; i++) {
577 hwmods[i]->od = od;
578 _add_hwmod_clocks_clkdev(od, hwmods[i]);
579 }
580
581 return od;
582
583oda_exit3:
584 kfree(hwmods);
585oda_exit2:
586 kfree(od);
587oda_exit1:
588 dev_err(&pdev->dev, "omap_device: build failed (%d)\n", ret);
589
590 return ERR_PTR(ret);
591}
592
593static void omap_device_delete(struct omap_device *od)
594{
595 if (!od)
596 return;
597
598 od->pdev->archdata.od = NULL;
599 kfree(od->pm_lats);
600 kfree(od->hwmods);
601 kfree(od);
602}
603
604/**
392 * omap_device_build - build and register an omap_device with one omap_hwmod 605 * omap_device_build - build and register an omap_device with one omap_hwmod
393 * @pdev_name: name of the platform_device driver to use 606 * @pdev_name: name of the platform_device driver to use
394 * @pdev_id: this platform_device's connection ID 607 * @pdev_id: this platform_device's connection ID
@@ -405,7 +618,7 @@ int omap_device_fill_resources(struct omap_device *od, struct resource *res)
405 * information. Returns ERR_PTR(-EINVAL) if @oh is NULL; otherwise, 618 * information. Returns ERR_PTR(-EINVAL) if @oh is NULL; otherwise,
406 * passes along the return value of omap_device_build_ss(). 619 * passes along the return value of omap_device_build_ss().
407 */ 620 */
408struct omap_device *omap_device_build(const char *pdev_name, int pdev_id, 621struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
409 struct omap_hwmod *oh, void *pdata, 622 struct omap_hwmod *oh, void *pdata,
410 int pdata_len, 623 int pdata_len,
411 struct omap_device_pm_latency *pm_lats, 624 struct omap_device_pm_latency *pm_lats,
@@ -438,18 +651,15 @@ struct omap_device *omap_device_build(const char *pdev_name, int pdev_id,
438 * platform_device record. Returns an ERR_PTR() on error, or passes 651 * platform_device record. Returns an ERR_PTR() on error, or passes
439 * along the return value of omap_device_register(). 652 * along the return value of omap_device_register().
440 */ 653 */
441struct omap_device *omap_device_build_ss(const char *pdev_name, int pdev_id, 654struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
442 struct omap_hwmod **ohs, int oh_cnt, 655 struct omap_hwmod **ohs, int oh_cnt,
443 void *pdata, int pdata_len, 656 void *pdata, int pdata_len,
444 struct omap_device_pm_latency *pm_lats, 657 struct omap_device_pm_latency *pm_lats,
445 int pm_lats_cnt, int is_early_device) 658 int pm_lats_cnt, int is_early_device)
446{ 659{
447 int ret = -ENOMEM; 660 int ret = -ENOMEM;
661 struct platform_device *pdev;
448 struct omap_device *od; 662 struct omap_device *od;
449 char *pdev_name2;
450 struct resource *res = NULL;
451 int i, res_count;
452 struct omap_hwmod **hwmods;
453 663
454 if (!ohs || oh_cnt == 0 || !pdev_name) 664 if (!ohs || oh_cnt == 0 || !pdev_name)
455 return ERR_PTR(-EINVAL); 665 return ERR_PTR(-EINVAL);
@@ -457,72 +667,40 @@ struct omap_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
457 if (!pdata && pdata_len > 0) 667 if (!pdata && pdata_len > 0)
458 return ERR_PTR(-EINVAL); 668 return ERR_PTR(-EINVAL);
459 669
460 pr_debug("omap_device: %s: building with %d hwmods\n", pdev_name, 670 pdev = platform_device_alloc(pdev_name, pdev_id);
461 oh_cnt); 671 if (!pdev) {
462 672 ret = -ENOMEM;
463 od = kzalloc(sizeof(struct omap_device), GFP_KERNEL); 673 goto odbs_exit;
464 if (!od) 674 }
465 return ERR_PTR(-ENOMEM);
466 675
467 od->hwmods_cnt = oh_cnt; 676 /* Set the dev_name early to allow dev_xxx in omap_device_alloc */
677 if (pdev->id != -1)
678 dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
679 else
680 dev_set_name(&pdev->dev, "%s", pdev->name);
468 681
469 hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt, 682 od = omap_device_alloc(pdev, ohs, oh_cnt, pm_lats, pm_lats_cnt);
470 GFP_KERNEL); 683 if (!od)
471 if (!hwmods)
472 goto odbs_exit1; 684 goto odbs_exit1;
473 685
474 memcpy(hwmods, ohs, sizeof(struct omap_hwmod *) * oh_cnt); 686 ret = platform_device_add_data(pdev, pdata, pdata_len);
475 od->hwmods = hwmods;
476
477 pdev_name2 = kzalloc(strlen(pdev_name) + 1, GFP_KERNEL);
478 if (!pdev_name2)
479 goto odbs_exit2;
480 strcpy(pdev_name2, pdev_name);
481
482 od->pdev.name = pdev_name2;
483 od->pdev.id = pdev_id;
484
485 res_count = omap_device_count_resources(od);
486 if (res_count > 0) {
487 res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
488 if (!res)
489 goto odbs_exit3;
490 }
491 omap_device_fill_resources(od, res);
492
493 od->pdev.num_resources = res_count;
494 od->pdev.resource = res;
495
496 ret = platform_device_add_data(&od->pdev, pdata, pdata_len);
497 if (ret) 687 if (ret)
498 goto odbs_exit4; 688 goto odbs_exit2;
499
500 od->pm_lats = pm_lats;
501 od->pm_lats_cnt = pm_lats_cnt;
502 689
503 if (is_early_device) 690 if (is_early_device)
504 ret = omap_early_device_register(od); 691 ret = omap_early_device_register(pdev);
505 else 692 else
506 ret = omap_device_register(od); 693 ret = omap_device_register(pdev);
507
508 for (i = 0; i < oh_cnt; i++) {
509 hwmods[i]->od = od;
510 _add_hwmod_clocks_clkdev(od, hwmods[i]);
511 }
512
513 if (ret) 694 if (ret)
514 goto odbs_exit4; 695 goto odbs_exit2;
515 696
516 return od; 697 return pdev;
517 698
518odbs_exit4:
519 kfree(res);
520odbs_exit3:
521 kfree(pdev_name2);
522odbs_exit2: 699odbs_exit2:
523 kfree(hwmods); 700 omap_device_delete(od);
524odbs_exit1: 701odbs_exit1:
525 kfree(od); 702 platform_device_put(pdev);
703odbs_exit:
526 704
527 pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret); 705 pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret);
528 706
@@ -538,11 +716,11 @@ odbs_exit1:
538 * platform_early_add_device() on the underlying platform_device. 716 * platform_early_add_device() on the underlying platform_device.
539 * Returns 0 by default. 717 * Returns 0 by default.
540 */ 718 */
541int omap_early_device_register(struct omap_device *od) 719static int omap_early_device_register(struct platform_device *pdev)
542{ 720{
543 struct platform_device *devices[1]; 721 struct platform_device *devices[1];
544 722
545 devices[0] = &(od->pdev); 723 devices[0] = pdev;
546 early_platform_add_devices(devices, 1); 724 early_platform_add_devices(devices, 1);
547 return 0; 725 return 0;
548} 726}
@@ -638,13 +816,13 @@ static struct dev_pm_domain omap_device_pm_domain = {
638 * platform_device_register() on the underlying platform_device. 816 * platform_device_register() on the underlying platform_device.
639 * Returns the return value of platform_device_register(). 817 * Returns the return value of platform_device_register().
640 */ 818 */
641int omap_device_register(struct omap_device *od) 819static int omap_device_register(struct platform_device *pdev)
642{ 820{
643 pr_debug("omap_device: %s: registering\n", od->pdev.name); 821 pr_debug("omap_device: %s: registering\n", pdev->name);
644 822
645 od->pdev.dev.parent = &omap_device_parent; 823 pdev->dev.parent = &omap_device_parent;
646 od->pdev.dev.pm_domain = &omap_device_pm_domain; 824 pdev->dev.pm_domain = &omap_device_pm_domain;
647 return platform_device_register(&od->pdev); 825 return platform_device_add(pdev);
648} 826}
649 827
650 828
@@ -671,8 +849,9 @@ int omap_device_enable(struct platform_device *pdev)
671 od = to_omap_device(pdev); 849 od = to_omap_device(pdev);
672 850
673 if (od->_state == OMAP_DEVICE_STATE_ENABLED) { 851 if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
674 WARN(1, "omap_device: %s.%d: %s() called from invalid state %d\n", 852 dev_warn(&pdev->dev,
675 od->pdev.name, od->pdev.id, __func__, od->_state); 853 "omap_device: %s() called from invalid state %d\n",
854 __func__, od->_state);
676 return -EINVAL; 855 return -EINVAL;
677 } 856 }
678 857
@@ -710,8 +889,9 @@ int omap_device_idle(struct platform_device *pdev)
710 od = to_omap_device(pdev); 889 od = to_omap_device(pdev);
711 890
712 if (od->_state != OMAP_DEVICE_STATE_ENABLED) { 891 if (od->_state != OMAP_DEVICE_STATE_ENABLED) {
713 WARN(1, "omap_device: %s.%d: %s() called from invalid state %d\n", 892 dev_warn(&pdev->dev,
714 od->pdev.name, od->pdev.id, __func__, od->_state); 893 "omap_device: %s() called from invalid state %d\n",
894 __func__, od->_state);
715 return -EINVAL; 895 return -EINVAL;
716 } 896 }
717 897
@@ -742,8 +922,9 @@ int omap_device_shutdown(struct platform_device *pdev)
742 922
743 if (od->_state != OMAP_DEVICE_STATE_ENABLED && 923 if (od->_state != OMAP_DEVICE_STATE_ENABLED &&
744 od->_state != OMAP_DEVICE_STATE_IDLE) { 924 od->_state != OMAP_DEVICE_STATE_IDLE) {
745 WARN(1, "omap_device: %s.%d: %s() called from invalid state %d\n", 925 dev_warn(&pdev->dev,
746 od->pdev.name, od->pdev.id, __func__, od->_state); 926 "omap_device: %s() called from invalid state %d\n",
927 __func__, od->_state);
747 return -EINVAL; 928 return -EINVAL;
748 } 929 }
749 930
@@ -837,6 +1018,42 @@ void __iomem *omap_device_get_rt_va(struct omap_device *od)
837 return omap_hwmod_get_mpu_rt_va(od->hwmods[0]); 1018 return omap_hwmod_get_mpu_rt_va(od->hwmods[0]);
838} 1019}
839 1020
1021/**
1022 * omap_device_get_by_hwmod_name() - convert a hwmod name to
1023 * device pointer.
1024 * @oh_name: name of the hwmod device
1025 *
1026 * Returns back a struct device * pointer associated with a hwmod
1027 * device represented by a hwmod_name
1028 */
1029struct device *omap_device_get_by_hwmod_name(const char *oh_name)
1030{
1031 struct omap_hwmod *oh;
1032
1033 if (!oh_name) {
1034 WARN(1, "%s: no hwmod name!\n", __func__);
1035 return ERR_PTR(-EINVAL);
1036 }
1037
1038 oh = omap_hwmod_lookup(oh_name);
1039 if (IS_ERR_OR_NULL(oh)) {
1040 WARN(1, "%s: no hwmod for %s\n", __func__,
1041 oh_name);
1042 return ERR_PTR(oh ? PTR_ERR(oh) : -ENODEV);
1043 }
1044 if (IS_ERR_OR_NULL(oh->od)) {
1045 WARN(1, "%s: no omap_device for %s\n", __func__,
1046 oh_name);
1047 return ERR_PTR(oh->od ? PTR_ERR(oh->od) : -ENODEV);
1048 }
1049
1050 if (IS_ERR_OR_NULL(oh->od->pdev))
1051 return ERR_PTR(oh->od->pdev ? PTR_ERR(oh->od->pdev) : -ENODEV);
1052
1053 return &oh->od->pdev->dev;
1054}
1055EXPORT_SYMBOL(omap_device_get_by_hwmod_name);
1056
840/* 1057/*
841 * Public functions intended for use in omap_device_pm_latency 1058 * Public functions intended for use in omap_device_pm_latency
842 * .activate_func and .deactivate_func function pointers 1059 * .activate_func and .deactivate_func function pointers
@@ -917,8 +1134,13 @@ struct device omap_device_parent = {
917 .parent = &platform_bus, 1134 .parent = &platform_bus,
918}; 1135};
919 1136
1137static struct notifier_block platform_nb = {
1138 .notifier_call = _omap_device_notifier_call,
1139};
1140
920static int __init omap_device_init(void) 1141static int __init omap_device_init(void)
921{ 1142{
1143 bus_register_notifier(&platform_bus_type, &platform_nb);
922 return device_register(&omap_device_parent); 1144 return device_register(&omap_device_parent);
923} 1145}
924core_initcall(omap_device_init); 1146core_initcall(omap_device_init);